' xprint_calendar.pb — Calendar page generator simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL year AS LONG
    LOCAL month AS LONG
    LOCAL daysInMonth AS LONG
    LOCAL startDay AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL dayNum AS LONG
    LOCAL row AS LONG
    LOCAL col AS LONG
    LOCAL totalDays AS LONG
    LOCAL isLeap AS LONG
    LOCAL dayOffset AS LONG
    LOCAL calRows AS LONG
    LOCAL cellW AS LONG
    LOCAL margin AS LONG
    LOCAL pageWidth AS LONG
    LOCAL lineLength AS LONG
    LOCAL headerStr AS STRING
    LOCAL weekStr AS STRING

    year = 2026
    month = 6

    PRINT "=== Calendar Print ==="

    IF year / 4 * 4 = year THEN
        isLeap = 1
    ELSE
        isLeap = 0
    END IF

    IF month = 1 THEN daysInMonth = 31
    IF month = 2 THEN daysInMonth = 28
    IF month = 3 THEN daysInMonth = 31
    IF month = 4 THEN daysInMonth = 30
    IF month = 5 THEN daysInMonth = 31
    IF month = 6 THEN daysInMonth = 30
    IF month = 7 THEN daysInMonth = 31
    IF month = 8 THEN daysInMonth = 31
    IF month = 9 THEN daysInMonth = 30
    IF month = 10 THEN daysInMonth = 31
    IF month = 11 THEN daysInMonth = 30
    IF month = 12 THEN daysInMonth = 31
    IF month = 2 AND isLeap = 1 THEN daysInMonth = 29

    totalDays = 0
    FOR i = 1 TO month - 1
        IF i = 1 THEN totalDays = totalDays + 31
        IF i = 2 THEN totalDays = totalDays + 28
        IF i = 3 THEN totalDays = totalDays + 31
        IF i = 4 THEN totalDays = totalDays + 30
        IF i = 5 THEN totalDays = totalDays + 31
        IF i = 6 THEN totalDays = totalDays + 30
        IF i = 7 THEN totalDays = totalDays + 31
        IF i = 8 THEN totalDays = totalDays + 31
        IF i = 9 THEN totalDays = totalDays + 30
        IF i = 10 THEN totalDays = totalDays + 31
        IF i = 11 THEN totalDays = totalDays + 30
    NEXT i
    startDay = (totalDays + 1) MOD 7

    PRINT "Printing calendar for " + STR$(month) + "/" + STR$(year)
    PRINT "Days: " + STR$(daysInMonth) + " Start: " + STR$(startDay)
    PRINT " Sun Mon Tue Wed Thu Fri Sat"

    dayNum = 1
    FOR row = 0 TO 5
        weekStr = ""
        FOR col = 0 TO 6
            IF row = 0 AND col < startDay THEN
                weekStr = weekStr + "    "
            ELSE
                IF dayNum <= daysInMonth THEN
                    IF dayNum < 10 THEN
                        weekStr = weekStr + "   " + STR$(dayNum)
                    ELSE
                        weekStr = weekStr + "  " + STR$(dayNum)
                    END IF
                    dayNum = dayNum + 1
                ELSE
                    weekStr = weekStr + "    "
                END IF
            END IF
        NEXT col
        PRINT weekStr
        IF dayNum > daysInMonth THEN
            row = 5
        END IF
    NEXT row

    IF month = 12 THEN
        year = year + 1
    END IF

    PRINT "=== End Calendar ==="
    FUNCTION = 0
END FUNCTION
