' GlobalMemoryStatus simulation via DECLARE — report RAM info
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL totalPhys  AS LONG
    LOCAL availPhys  AS LONG
    LOCAL totalPage  AS LONG
    LOCAL availPage  AS LONG
    LOCAL totalVirtual  AS LONG
    LOCAL availVirtual  AS LONG
    LOCAL loadPct  AS LONG
    LOCAL usedPhys  AS LONG
    LOCAL usedPct  AS LONG
    LOCAL memMB  AS LONG
    LOCAL freeMB  AS LONG
    PRINT "=== Memory Status ==="
    PRINT

    totalPhys = 16384
    availPhys = 8192
    totalPage = 32768
    availPage = 14336
    totalVirtual = 134217728
    availVirtual = 130023424
    loadPct = 50

    PRINT "--- Physical Memory ---"
    PRINT "  Total: " & FORMAT$(totalPhys) & " MB (" & FORMAT$(totalPhys / 1024) & " GB)"
    PRINT "  Available: " & FORMAT$(availPhys) & " MB"
    usedPhys = totalPhys - availPhys
    usedPct = usedPhys * 100 / totalPhys
    PRINT "  Used: " & FORMAT$(usedPhys) & " MB (" & FORMAT$(usedPct) & "%)"
    PRINT "  Load: " & FORMAT$(loadPct) & "%"
    PRINT

    PRINT "--- Page File ---"
    PRINT "  Total: " & FORMAT$(totalPage) & " MB"
    PRINT "  Available: " & FORMAT$(availPage) & " MB"
    PRINT "  Used: " & FORMAT$(totalPage - availPage) & " MB"
    PRINT

    PRINT "--- Virtual Memory ---"
    memMB = totalVirtual / 1024
    freeMB = availVirtual / 1024
    PRINT "  Total: " & FORMAT$(memMB) & " MB"
    PRINT "  Available: " & FORMAT$(freeMB) & " MB"
    PRINT

    PRINT "--- Memory Usage Breakdown ---"
    PRINT "  Physical: " & FORMAT$(totalPhys) & " MB"
    PRINT "  Page file: " & FORMAT$(totalPage) & " MB"
    PRINT "  Virtual: " & FORMAT$(memMB) & " MB"
    PRINT

    PRINT "--- DECLARE Signature ---"
    PRINT "  DECLARE SUB GlobalMemoryStatus LIB 'KERNEL32.DLL' (lpBuffer AS MEMORYSTATUS)"
    PRINT

    PRINT "--- MEMORYSTATUS Structure ---"
    PRINT "  dwLength: 32 bytes"
    PRINT "  dwMemoryLoad: " & FORMAT$(loadPct) & "%"
    PRINT "  dwTotalPhys: " & FORMAT$(totalPhys * 1048576) & " bytes"
    PRINT "  dwAvailPhys: " & FORMAT$(availPhys * 1048576) & " bytes"
    PRINT "  dwTotalPageFile: " & FORMAT$(totalPage * 1048576) & " bytes"
    PRINT "  dwAvailPageFile: " & FORMAT$(availPage * 1048576) & " bytes"
    PRINT "  dwTotalVirtual: " & FORMAT$(totalVirtual * 1024) & " bytes"
    PRINT "  dwAvailVirtual: " & FORMAT$(availVirtual * 1024) & " bytes"
    PRINT

    PRINT "--- Memory Thresholds ---"
    IF availPhys < 1024 THEN
        PRINT "  LOW MEMORY WARNING: < 1 GB available"
    ELSE
        IF availPhys < 2048 THEN
            PRINT "  Moderate memory: 1-2 GB available"
        ELSE
            PRINT "  Adequate memory: > 2 GB available"
        END IF
    END IF

    PRINT
    PRINT "Memory status report complete."

    FUNCTION = 0
END FUNCTION
