\ Calculating the day of the week for a given date \ ================================================ \ mdfs.net/Info/Comp/Z80/ProgTips/Date/DayOfWeek - J.G.Harston \ \ Based on code at http://6502.org/source/misc/dow.htm by Paul Guertin. \ \ This routine works for any date from 1900-01-01 to 2155-12-31. \ No range checking is done, so validate input before calling. \ \ It uses the formula \ Weekday = (day + offset[month] + year + year/4 + fudge) mod 7 \ offset[month] adjusts the day count so 1st of a month is effectively \ the (lastday+1)-th of the previous month. \ fudge is -1 when after 2099 as 2100 is not a leap year. \ \ On entry B =day, 1..31 \ C =month, 1..12 \ E =year-1900, 0..255 \ On exit A=day of week 0..6 for Sun..Sat, Carry will be Set \ Needs incrementing with INC A after calling to \ become standard 1..7 range \ Size 51 bytes \ .DayOfWeek LD A,C:CP 3 :\ Is month March or later? LD A,E :\ A=year for later JR NC,dow_march :\ Start year in March make leap years easier AND A:JR NZ,dow_1901:LD A,6 :\ Adjust for 1900 - include this for Jan/Feb 1900 .dow_1901 DEC A:LD E,A :\ If Jan or Feb, decrement year .dow_march CP 2100-1900:CCF:SBC A,0 :\ Adjust for 2100 not a leap year CALL dow_mod7 :\ Get year MOD 7 to prevent overflow ADD A,B :\ A=day + year SRL E:SRL E:ADD A,E :\ A=day + year + year/4 LD HL,dow_months-1 :\ HL=>month table LD B,0:ADD HL,BC :\ HL=>month offset ADD A,(HL) :\ A=day + offset[m] + year + year/4 .dow_mod7 ADD A,7:JR NC,dow_mod7 RET .dow_months DEFB 2:DEFB 5:DEFB 4:DEFB 0 :\ Month offsets DEFB 2:DEFB 5:DEFB 0:DEFB 3 DEFB 6:DEFB 1:DEFB 4:DEFB 6 \