\ Incrementing a date at the end of a month \ ========================================= \ Optimised version of code in SoftRTC. J.G.Harston. \ \ This routine works for any date from 1900-01-01 to 2155-12-31. \ No range checking is done, so validate input before calling. \ Invalid dates will be incremented to the next logical correct date. \ \ On entry A=day, 1..31 \ X=month, 1..12 \ Y=year-1900, 0..255 (year=1900..2155) \ On exit A=day, 1..31 \ X=month, 1..12 \ Y=year-1900, 0..255 (year=1900..2155) \ NE=date did not overflow \ EQ=date overflowed, A=0,X=0,Y=0 \ Size 57 to 64 bytes \ .DateIncrement \ Optional month range check: DEX:CPX #12:BCS DateUpdate2a:INX :\ Month out of range, skip to next year \ CMP DateLength-1,X:BCC DateUpdate4 :\ Not end of month, skip to increment day CPX #2:BNE DateUpdate2 :\ Not February, skip leap year check \ \ February, check for leap years CPY #2100-1900:BEQ DateUpdate2 :\ Non-leap year 2100, step to March CMP #29 :\ CC=28th February TYA:BEQ DateUpdate2 :\ Non-leap year 1900, step to March AND #3:BNE DateUpdate2 :\ Non-leap (year AND 3)<>0, step to March LDA #29:BCC DateUpdate5 :\ Leap year, jump to return 29th Feb \ \ Last day of month, increment to first day of next month .DateUpdate2 LDA #0 :\ Set day=0, will be incremented later CPX #12:BCC DateUpdate3 :\ Not December, don't increment year \ \ Last month of year, increment to first month of next year .DateUpdate2a LDX #0 :\ Set month=0, will be incremented later INY:BEQ DateUpdate5 :\ Increment year, exit if overflowed \ .DateUpdate3 INX :\ Increment to next month .DateUpdate4 CLC:ADC #1 :\ Increment day .DateUpdate5 RTS \ .DateLength EQUB 31:EQUB 28:EQUB 31:EQUB 30 :\ Month lengths EQUB 31:EQUB 30:EQUB 31:EQUB 31 EQUB 30:EQUB 31:EQUB 30:EQUB 31 EQUB 31:EQUB 31:EQUB 31 :\ Include these to allow months 13-15