> RTCTest d* Read & Write M128 CMOS Chip Directly  (C) Ian Wolstenholme 2022 , Except Assembler RTC Clock access code 1 adapted from New AUG (C)Dickens&Holmes 1986 , Version 1.3 21/i/23 @6 New option 8 - show all CMOS registers and bytes ^G Use strings for colour changes; restore cursor on error; speed up h" Option 7 keypress processing % To do: 1. Test for 23:59:59 bug ; 2. Interpret other CMOS contents (bytes 19-49) 8 3. Figure out meaning of Telecoms CMOS byte  code 240 &"baud$(7):B%=07:baud$(B%): X(printer$(4):B%=04:printer$(B%): "regs$(9):B%=09:regs$(B%): Y$=" 20": For century &I$=17+129+17+0: Inverse video %N$=17+128+17+1: Normal video &R$="Press a key to return to menu"  assemble  M%=128 R M%=M%+1  M% 0:" at ";;N$:23,1,3;0;0;0;0;:"FX4,0":  :23,1;0;0;0;0; L.I$"Master CMOS/RTC Chip Settings v1.3"N$' ~ "1. Show all CMOS settings" "2. Show time/date" "3. Test CMOS chip" !"4. Show all time registers" F"5. Test BST function" x#"6. Set Econet station number" "7. Show Registers A to D" +"8. Show all CMOS registers and bytes" '"0. Exit" K%=:K%>47K%<57 @K%=49displaycmos rK%=50displaytime K%=51testchip K%=52displayregs K%=53bsttest :K%=54setstation lK%=55showregisters K%=56showeverything  K%=48 23,1,3;0;0;0;0;  4)75,150,300,1200,2400,4800,9600,19200 f+No printer,Parallel,Serial,User,Econet fSeconds,Seconds Alarm,Minutes,Minutes Alarm,Hours,Hours Alarm,Day of Week,Day of Month,Month,Year assemble  B%=022 . P%=code `oswrch=&FFEE ,slowbus=&FE4F: System VIA port A output -regb=&FE40 : System VIA port B control /ddra=&FE43 : System VIA port A direction ( [OPTB% Z.read JSRaddress LDA#&49 \select read STAregb 5LDA#0:STAddra \ WasSTZ ddra, make 6502 compatible "LDA#&4A \set DS active T STAregb .LDYslowbus \value to be read in Y register JMPfinish .write JSR address +LDA#&41 \select WR on addressable latch N STAregb LDA#&4A \take DS active STAregb STYslowbus -JMPfinish \ Was BRA, make 6502 compatible H1.address LDA #2\enter with X=selected address z1STAregb \Write CE & DS inactive to system via LDA#&82 \AS active STAregb #LDA#&FF \slow databus as output B STAddra t&STXslowbus \write register address LDA#&C2 \Take CE active  STAregb  (LDA#&42 \strobe AS low to latch data < STAregb nRTS ".finish LDA#&42 \deactivate DS  STAregb LDA#&02 \deactivate CE 6 STAregb hRTS .readregister $LDXreg:LDY#0:JSRread:STYcmos:RTS .writeregister 0LDXreg:LDYcmos:JSRwrite:RTS b .readall  LDX#0  .readloop  LDY#0 * JSRread \TYA  STAcmos,X INX  CPX#65 $BNEreadloop VRTS .printromtitle LDA#&80:STA&F7 %LDA#9:STA&F6 \ Rom title at &8009  .romloop PNLDYreg \ Re-use register number byte - must be within loop to work on BBCB JSR&FFB9 \ OSRDRM  CMP#31 BMIskipprint %JSR&FFE3 \ Print if sensible char J.skipprint | CMP#0 BEQromfinish  INC&F6  LDA&F6 D6CMP#9+16 \ 16 chars printed only (in case rubbish) vBNEromloop .romfinish RTS  .reg EQUB0 >.cmos EQUS 14,0) p.cmosram EQUS 50,0) ]   8ݤreadreg(R%) j"Store register number in .reg  ?reg=R% * Call read code, result in Y register readregister:=?cmos 2writereg(R%,V%) d# Store register number in .reg  ?reg=R% ,?cmos=V%:Store value to write in .write writeregister , ^ ݤtime IT%=:(readreg(&A)128)=0>T%+20: Wait till no update in progress <=h(readreg(4))+":"+h(readreg(2))+":"+h(readreg(0))  ݤdate &IT%=:(readreg(&A)128)=0>T%+20: Wait till no update in progress X="SunMonTueWedThuFriSat",readreg(6)*3-2,3)+","+h(readreg(7))+" "+"JanFebMarAprMayJunJulAugSepOctNovDec",readreg(8)*3-2,3)+Y$+h(readreg(9)) ݤtimestring =date+"."+time ݤtestcmos  J Read byte 26 of CMOS (keyboard delay setting) to check 6818 presence R)R%=readreg(26):W%=255:R%=255 W%=128 writereg(26,W%) N%=readreg(26) 4writereg(26,R%): restore old value if possible N%=W% = = L ݤreaddse ~=(readreg(&B)1)=1 writedse "writereg(&B,(readreg(&B)1))  F ݤtestbst x writedse OT%=:readall:?cmos<&54 >T%+600: do all this within the current minute 7readreg(0)<>readreg(0): wait till second ticks %"Current time: "20);timestring @7B%=09:?(cmos+B%+20)=?(cmos+B%):: Store old time r5writereg(&B,(readreg(&B)128)): stop the clock -U%=: Record time elapsed during routine քwritereg(8,&4):writereg(7,&30):writereg(6,1):writereg(4,&1):writereg(2,&59):writereg(0,&58): set time to Sun,30/4 1:59:58 '"Setting time to:"20);timestring :6writereg(&B,(readreg(&B)128)): start the clock l$"Waiting 2 seconds till 3am..." $T%=:>T%+200: Wait 2 seconds 9B%=(readreg(4)=&3): hours should be 3 if BST active !&"Reading time..."20);timestring !45writereg(&B,(readreg(&B)128)): stop the clock !fCC%=19:writereg(C%,?(cmos+C%+20)):: Restore prev time exc.s !h>U%+300:Q%=(~cmos?20):Q%=Q%+(-U%)/100:Q%=("&"+Q%):writereg(0,Q%): Need round no of seconds !6writereg(&B,(readreg(&B)128)): start the clock !)"Restoring time to:"20);timestring ".=B% "`showcmos " "I$"CMOS RAM Settings:"N$ " readall #()"Econet Station Number"23);?cmosram #Zm"Econet Servers"23)"File server: ";cmosram?2;".";cmosram?1;", Printer Server: ";cmosram?4;".";cmosram?3 #["Default filing system"23);cmosram?5 16;" (";:?reg=cmosram?5 16:printromtitle:")" #V"Default language"23);cmosram?5 16;" (";:?reg=cmosram?5 16:printromtitle:")" #$M% 128=3 shortplug longplug $"a"EDIT settings"23);"MODE ";:(cmosram?8 7)=2"K";(cmosram?8 7)=5"D";;(cmosram?8 7); $T5", TAB to ";:cmosram?8 8 "Words";"Columns"; $2", ";:cmosram?8 16 "Insert";"Overwrite"; $+", ";:cmosram?8 32 "Show";"Hide"; $" Returns" %&"Telecoms settings"23);cmosram?9 %NS"Screen settings"23);"MODE ";128*((cmosram?10 8)/8)+(cmosram?10 7);", TV "; %]T%=(cmosram?10 128)/128*4+(cmosram?10 64)/64*2+(cmosram?10 32)/32*1:T%>3 T%=T%+248 %[;T%;",";(cmosram?10 16)/16;" (";:cmosram?10 16 "Interlace on)";"Interlace off)"; %3", ";:cmosram?16 8 "No scroll";"Scroll"; %+cmos?16 1:", Shadow"", No shadow" &-"Floppy drive timings"23);cmosram?11 7 &H8"ADFS Defaults"23);:cmosram?11 64 "No d";"D"; &z;"irectory, ";:cmosram?11 128 "Floppy""Hard Drive" &["Keyboard settings"23);"Repeat Delay: ";cmosram?12;", Repeat Rate: ";cmosram?13;", "; &!cmosram?11 8"SHIFT-CAPS "; 'cmosram?11 16"No CAPS "; 'B!cmosram?11 32"CAPS Lock "; 'tH'"Second processor"23);:cmosram?16 4 "External ";"Internal "; '.cmosram?15 1 "(Enabled) ""(Disabled)" '"Serial settings"23);"Baud rate: ";1+(cmosram?15 16)/16*4+(cmosram?15 8)/8*2+(cmosram?15 4)/4*1;" (";baud$((cmosram?15 16)/16*4+(cmosram?15 8)/8*2+(cmosram?15 4)/4*1);"), Data format: "; ( L;(cmosram?16 128)/128*4+(cmosram?16 64)/64*2+(cmosram?16 32)/32*1 (-1 + +displaytime ,$,:I$"Display RTC Time and Date"N$''''R$ ,V!0,2)timestring:(10)<>-1 , ,testchip ,(:I$"Test Presence of CMOS Chip"'N$ -3testcmos "6818 chip present""No 6818 chip" -P'R$ - - -displayregs . :I$"Show Time Registers"N$ .J*FX225,128 .| . readall .bcd=(cmos?&B 4)=0 / 0,2); /D B%=013 /v6;B%;" - ";:B%<10 regs$(B%); "Register ";~B%; /,23);:B%<10 bcd ~cmos?B% cmos?B% / 0 0'"Register B Settings (toggle with f0-f3):" 0>="Daylight saving"23);:readdse "Enabled ""Disabled" 0pJ"12/24 Hour Clock"23);:cmos?&B 2 "24-hour clock""12-hour clock" 0J"Data mode"23);:bcd "Binary coded decimal""Decimal " 0F"Clock set"23);:cmos?&B 128 "Clock halted ""Clock running" 1/'"Press "I$"f0-f3"N$" or any other"R$,22) 1850,0)"Time: ";timestring 1j K%=(10) 1/K%=128 writereg(&B,readreg(&B) 1):K%=-1 1.K%=129 writereg(&B,readreg(&B)2):K%=-1 2.K%=130 writereg(&B,readreg(&B)4):K%=-1 220K%=131 writereg(&B,readreg(&B)128):K%=-1 2d K%<>-1 2K%=0 2 *FX225,1 2 3,longplug 3^ B%=07 3?"ROM ";B%;" ";:cmosram?6 2^B% "Inserted";"Unplugged"; 3O23)"ROM ";" ",B%<2);B%+8;" ";:cmosram?7 2^B% "Inserted" "Unplugged" 3 4& 4Xshortplug 4"ROMs Unplugged"23); 4 C%=67 4 B%=07 5 *cmosram?C% 2^B% ;B%+(C%-6)*8;" "; 5R: 5'"ROMS Inserted"23); 5 C%=67 5 B%=07 6(cmosram?C% 2^B% ;B%+(C%-6)*8;" "; 6L: 6~ 6 6 bsttest 73:I$"Testing BST function of 6818 chip...."'N$ 7F%笤testcmos "No 6818 chip":tjw 7x:testbst '"BST function present"'"No BST Function" 7 ''R$ 7 8 8@setstation 8r23,1,3;0;0;0;0; 8':I$"Set Econet station number"'N$ 8."Current station number: ";readreg(14) 9 9:("Input new station number: ";:""S% 9l(S%<0 S%>254 "Bad station number" 9S%>=0 S%<255 9HS%=0 "Unchanged""Setting station number to ";S%:writereg(14,S%) : 'R$; :4 :f :showregisters :regsel=65:bitsel=7 : *FX4,1 ; *FX219,9 ;. ;`I$"Show Registers A-D"N$ ;k0,28)I$"Arrow keys"N$" to change highlighted selection"I$'"RETURN"N$" to toggle bit"I$'"TAB"N$R$,18) ;x0,13)I$"Register A (R/W except bit 7)"N$'"Update in progress (7)"'"Divider bits (6-4)"'"Rate selection bits (3-0)" ;40,13)I$"Register B (R/W)"N$'40,14)"Set (Halt RTC)"40,15)"Periodic Interrupt Enable"40,16)"Alarm Interrupt Enable"40,17)"Update-Ended Interrupt Enable" <(h40,18)"Square Wave Enable"40,19)"Data Mode"40,20)"24/12 Hr Clock"40,21)"Daylight Saving Enable" PRINTTAB(0,-126+(B%*2))CHR$B%; Moved earlier to speed up =C%=70-1 >$regsel=B% bitsel=C% I$; N$ >Nb(-55+(C%*7)),-126+(B%*2));" ";:currentreg 2^C% "1";"0";: wasFNreadreg(B%-55)AND2^C% > " "; > >)66,-126+(B%*2));N$;currentreg;" "; ? ?4currentreg=readreg(&A) ?H3currentreg 12828,14)"Set "28,14)"Clear" ?z'28,15);((currentreg 112)/16);" " ? 28,16);currentreg 15;" " ?currentreg=readreg(&B) ?NB%=73-1:currentreg 2^B% 70,(-21+B%))"Set "70,(-21+B%))"Clear" @ @B470,19);:currentreg 2^2 "Decimal""BCD " @t070,20);:currentreg 2^1 "24-hr""12-hr" @670,21);:currentreg 2^0 "Enabled ""Disabled" @currentreg=readreg(&C) @NB%=74-1:currentreg 2^B% 28,(-26+B%))"Set "28,(-26+B%))"Clear" A  A<3readreg(&D)2^7 37,25)"High"37,25)"Low " AP'K%=(0):K%=-1 K%=9 dokeypress An K%=9 A *FX4,0 A Bdokeypress B60K%=139 regsel=regsel-1:regsel<65 regsel=68 Bh.K%=136 bitsel=bitsel+1:bitsel>7 bitsel=0 B.K%=137 bitsel=bitsel-1:bitsel<0 bitsel=7 B0K%=138 regsel=regsel+1:regsel>68 regsel=65 B>K%=13 writereg(regsel-55,(readreg(regsel-55)2^bitsel)) C0 *FX15,1 Cb FPshoweverything Fd.:I$"Show All CMOS Registers and Bytes"N$ Fn Fx readall F} 0,2); F B%=013 FB%>6 40,B%-5); F:"Register ";B%;16);cmos?B%;20);"(&";h(cmos?B%);")" F F F B%=049 Fj20*(B% 13),10+(B% 13))"Byte ";B%;(3-B%);(3-(cmosram?B%));cmosram?B%;" (&";h(cmosram?B%);")" G I 0,26)R$ J (0) J. J8ݤh(A%)="0"+~A%,2)