' error_codes.pb — Error code constants and handling
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL errCode AS LONG
    LOCAL errModule AS LONG
    LOCAL errSeverity AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL totalErrors AS LONG
    LOCAL fatalCount AS LONG
    LOCAL warnCount AS LONG
    LOCAL infoCount AS LONG
    LOCAL errStr AS STRING
    LOCAL moduleStr AS STRING
    LOCAL severityStr AS STRING
    LOCAL numTests AS LONG
    LOCAL iter AS LONG
    LOCAL codeVal AS LONG

    PRINT "=== Error Codes System ==="
    PRINT "Format: 0xMMSSVV (Module, Severity, Code)"

    FOR numTests = 1 TO 12
        IF numTests = 1 THEN codeVal = 16777216
        IF numTests = 2 THEN codeVal = 33554432
        IF numTests = 3 THEN codeVal = 50331648
        IF numTests = 4 THEN codeVal = 66846720
        IF numTests = 5 THEN codeVal = 83886080
        IF numTests = 6 THEN codeVal = 100663296
        IF numTests = 7 THEN codeVal = 117440512
        IF numTests = 8 THEN codeVal = 134217728
        IF numTests = 9 THEN codeVal = 150994944
        IF numTests = 10 THEN codeVal = 167772160
        IF numTests = 11 THEN codeVal = 184549376
        IF numTests = 12 THEN codeVal = 201326592

        errModule = codeVal / 16777216
        errSeverity = codeVal / 65536 - errModule * 256
        errCode = codeVal - errModule * 16777216 - errSeverity * 65536

        IF errModule = 1 THEN moduleStr = "KERNEL"
        IF errModule = 2 THEN moduleStr = "MEMORY"
        IF errModule = 3 THEN moduleStr = "NETWORK"
        IF errModule = 4 THEN moduleStr = "FILESYS"
        IF errModule = 5 THEN moduleStr = "GRAPHICS"
        IF errModule = 6 THEN moduleStr = "DATABASE"
        IF errModule = 7 THEN moduleStr = "SECURITY"
        IF errModule = 8 THEN moduleStr = "INPUT"
        IF errModule = 9 THEN moduleStr = "OUTPUT"
        IF errModule = 10 THEN moduleStr = "CONFIG"
        IF errModule = 11 THEN moduleStr = "PLUGIN"
        IF errModule = 12 THEN moduleStr = "RUNTIME"

        IF errSeverity = 0 THEN severityStr = "INFO"
        IF errSeverity = 1 THEN severityStr = "WARN"
        IF errSeverity = 2 THEN severityStr = "ERROR"
        IF errSeverity = 3 THEN severityStr = "FATAL"

        IF errSeverity = 0 THEN infoCount = infoCount + 1
        IF errSeverity = 1 THEN warnCount = warnCount + 1
        IF errSeverity = 2 THEN warnCount = warnCount + 1
        IF errSeverity = 3 THEN fatalCount = fatalCount + 1

        errStr = "  [" + severityStr + "] " + moduleStr + " #" + STR$(errCode)
        PRINT errStr
        totalErrors = totalErrors + 1
    NEXT numTests

    PRINT "--- Error Summary ---"
    PRINT "Total: " + STR$(totalErrors)
    PRINT "Fatal: " + STR$(fatalCount) + " Warnings: " + STR$(warnCount) + " Info: " + STR$(infoCount)

    PRINT "=== End Error Codes ==="
    FUNCTION = 0
END FUNCTION
