10 REM >Y2KFixS 20 REM by Steven Flintham 30 REM 40 REM Version 0.01 50 REM 60 REM Friday 25th July 1997 70 REM Thursday 21st August 1997 80 : 90 REM This is a bit of a bodge, but should suffice. The Master Reference 100 REM Manual implies that the RTC itself contains a century number and 110 REM correctly handles the 21st century. Whether or not this is actually 120 REM the case, I don't want to get involved in talking directly to the 130 REM RTC - I'd probably have to disassemble the OS to find out how to 140 REM do it and there's always a slight risk of doing something nasty to 150 REM the chip. 160 REM 170 REM All I do is provide a "front end" to the OSWORD calls, changing the 180 REM "19" in the date string to "20" for years from 0 to 69 inclusive - 190 REM this adjusts the range of years which is displayed correctly to 200 REM 1970-2069. This works because the RTC doesn't know 1900 wasn't a 210 REM leap year. The OSWORD call to read the CMOS clock in BCD format is 220 REM unmodified as it doesn't return a year; anything using it for 230 REM display purposes probably assumes a 19XX year, but there's nothing 240 REM I can do about that. 250 REM 260 REM There's no need to do anything about setting the RTC; the OS treats 270 REM a 20XX year as a 19XX year for this purpose, which is just what's 280 REM wanted with this fix. 290 : 300 PROCinit 310 PROCassemble 320 OSCLI "Save Y2KFix "+STR$~code%+" "+STR$~(save_to_here-dest%+code%)+" "+STR$~redirect_wordv+" "+STR$~dest% 330 END 340 : 350 DEF PROCinit 360 DIM code% 1024 370 dest%=&A80 380 : 390 wordv=&20C 400 osword=&FFF1 410 : 420 REM I can't see why I shouldn't use these locations for this purpose 430 REM although in theory it might cause problems. 440 osword_x=&F0 450 osword_y=&F1 460 ENDPROC 470 : 480 DEF PROCassemble 490 FOR opt%=4 TO 7 STEP 3 500 P%=dest%:O%=code% 510 [OPT opt% 520 \ This isn't needed once it's been executed the first time, so it can 530 \ be overwritten after loading. Depending on where the fix code is 540 \ placed in memory, it might be more useful to have this once-only 550 \ code at the end instead of the beginning. (It would then be necessary 560 \ to save the uninitialised data though.) 570 .redirect_wordv 580 LDA wordv:CMP #my_osword MOD 256:BNE redirect_vector_do_it 590 LDA wordv+1:CMP #my_osword DIV 256:BEQ rts \ Already redirected 600 .redirect_vector_do_it \ Actually redirect the vector 610 LDA wordv:STA old_vector 620 LDA wordv+1:STA old_vector+1 630 LDA #my_osword MOD 256:STA wordv 640 LDA #my_osword DIV 256:STA wordv+1 650 .rts 660 RTS 670 : 680 \ TODO?; I don't preserve the processor flags at all; is this a flaw? 690 .my_osword 700 CMP #14:BNE pass_on \ Only process calls to read the clock 710 STX osword_x:STY osword_y 720 LDY #0:LDA (osword_x),Y 730 CMP #1:BEQ restore_pass_on \ nothing to change for BCD read 740 \ Handle the string operations by letting the OS deal with it, then 750 \ modifying the century in the string if appropriate 760 TXA:PHA:LDA osword_y:PHA 770 TAY:LDA #14:JSR old_osword \ X hasn't been modified 780 PLA:STA osword_y:PLA:STA osword_x 790 \ Year within century is at offsets 13 and 14 800 LDY #13:LDA (osword_x),Y 810 SEC:SBC #ASC"0" 820 ASL A:STA year_within_century 830 ASL A:ASL A 840 \ The carry should be clear anyway, but it seems silly to risk problems. 850 CLC:ADC year_within_century:STA year_within_century 860 \ year_within_century now contains C*10, where the year is ABCD 870 INY:LDA (osword_x),Y:SEC:SBC #ASC"0" 880 CLC:ADC year_within_century 890 \ A now contains CD, where the year is ABCD 900 CMP #70:BCS claim \ If CD>=70, do nothing 910 LDY #11:LDA #ASC"2":STA (osword_x),Y 920 INY:LDA #ASC"0":STA (osword_x),Y 930 .claim 940 \ Y has been corrupted, but OS 3.2 (at least) doesn't preserve either 950 \ X or Y (it will have corrupted X itself on the earlier OSWORD call 960 \ but this code hasn't corrupted it). It does preserve A, however. 970 LDA #14 980 RTS 990 .restore_pass_on 1000 LDA #14:LDY osword_y \ X hasn't been modified 1010 .old_osword 1020 .pass_on 1030 JMP (old_vector) 1040 : 1050 .save_to_here 1060 \ Uninitialised data 1070 .old_vector EQUW 0 1080 .year_within_century EQUB 0 1090 ] 1100 NEXT 1110 ENDPROC