10 REM > 6502.ProgTips.DofWeek
   20 REM Calculate day of week for 8-bit year range
   30 REM Works for any date from 1900-01-01 to 2155-12-31.
   40 :
   50 DIM mc% 59
   60 FOR P=0 TO 1
   70   P%=mc%:O%=P%
   80   [OPT P*2+4
   90   \ On entry  A=day, 1..31
  100   \           X=month, 1..12
  110   \           Y=year-1900, 0..255
  120   \ On exit   A=day of week 0..6 for Sun..Sat, Carry will be Set
  130   \           Needs incrementing with ADC #0 after calling to
  140   \           become standard 1..7 range
  150   \ Size      56 bytes + 1 byte workspace (50 bytes if year 1900 test removed)
  160   \
  170   .DayOfWeek
  180   CPX #3:BCS dow_march       :\ Year starts in March to bypass leap year problem
  190   CPY #0:BNE dow_1901:LDY #6 :\ Include this line to adjust for 1900
  200   .dow_1901
  210   DEY                        :\ If Jan or Feb, decrement year
  220   .dow_march
  230   EOR #&7F                   :\ Invert A so carry works right
  240   CPY #2100-1900             :\ Carry will be 1 if 22nd century
  250   ADC dow_months-1,X         :\ A=day+month_offset
  260   STA dow_tmp
  270   TYA:JSR dow_mod7           :\ Get the year MOD 7 to prevent overflow
  280   SBC dow_tmp:STA dow_tmp    :\ A=day+month_offset+year using SEC from dow_mod7
  290   TYA:LSR A:LSR A            :\ Get the year DIV 4
  300   CLC:ADC dow_tmp            :\ A=day+month_offset+year+year/4, fall through to MOD 7
  310   .dow_mod7
  320   ADC #7:BCC dow_mod7        :\ Reduce A to A MOD 7, returns SEC
  330   \ADC #0                    :\ Include to return 1-7, also swaps CC so JSR dow_mod7 works
  340   RTS
  350   .dow_months
  360   EQUB 1:EQUB 5:EQUB 6:EQUB 3  :\ Month offsets
  370   EQUB 1:EQUB 5:EQUB 3:EQUB 0
  380   EQUB 4:EQUB 2:EQUB 6:EQUB 4
  390   .dow_tmp
  400   EQUB 0                  :\ Temporary storage
  410   \
  420 ]NEXT
  430 DEFFNday(A%):=MID$("SunMonTueWedThuFriSat",A%*3-2,3)
  440 FOR X%=1 TO 12
  450   FOR A%=1 TO 31
  460     PRINT A%;"/";X%;"/";1900+Y%;" - ";FNday(1+((USR DayOfWeek) AND 255))
  470     IF A%=30:IF X%=4 OR X%=6 OR X%=9 OR X%=11:A%=32
  480     IF A%=28:IF X%=2:IF (Y% MOD 4) OR ((Y%+1900) MOD 400):A%=32
  490     IF A%=29:IF X%=2:A%=32
  500   NEXT
  510 NEXT