10 REM > RTCTest
  100 REM Read & Write M128 CMOS Chip Directly
  150 REM (C) Ian Wolstenholme 2022
  200 REM Except Assembler RTC Clock access code
  250 REM adapted from New AUG (C)Dickens&Holmes 1986
  300 REM Version 1.3 21/i/23
  320 REM New option 8 - show all CMOS registers and bytes
  350 REM Use strings for colour changes; restore cursor on error; speed up
  360 REM Option 7 keypress processing
  400 REM To do: 1. Test for 23:59:59 bug
  420 REM        2. Interpret other CMOS contents (bytes 19-49)
  430 REM        3. Figure out meaning of Telecoms CMOS byte
  500 DIMcode 240
  550 DIMbaud$(7):FORB%=0TO7:READbaud$(B%):NEXT
  600 DIMprinter$(4):FORB%=0TO4:READprinter$(B%):NEXT
  650 DIMregs$(9):FORB%=0TO9:READregs$(B%):NEXT
  700 Y$=" 20":REM For century
  710 I$=CHR$17+CHR$129+CHR$17+CHR$0:REM Inverse video
  720 N$=CHR$17+CHR$128+CHR$17+CHR$1:REM Normal video
  730 R$="Press a key to return to menu"
  750 PROCassemble
  800 M%=128
  850 ONERRORM%=M%+1
  900 MODE M%
  950 ONERRORREPORT:PRINT" at ";ERL;N$:VDU23,1,3;0;0;0;0;:OSCLI"FX4,0":END
 1000 REPEAT
 1050   CLS:VDU23,1;0;0;0;0;
 1100   PRINTI$"Master CMOS/RTC Chip Settings v1.3"N$'
 1150   PRINT"1. Show all CMOS settings"
 1200   PRINT"2. Show time/date"
 1250   PRINT"3. Test CMOS chip"
 1300   PRINT"4. Show all time registers"
 1350   PRINT"5. Test BST function"
 1400   PRINT"6. Set Econet station number"
 1450   PRINT"7. Show Registers A to D"
 1460   PRINT"8. Show all CMOS registers and bytes"
 1500   PRINT'"0. Exit"
 1550   REPEATK%=GET:UNTILK%>47ANDK%<57
 1600   IFK%=49PROCdisplaycmos
 1650   IFK%=50PROCdisplaytime
 1700   IFK%=51PROCtestchip
 1750   IFK%=52PROCdisplayregs
 1800   IFK%=53PROCbsttest
 1850   IFK%=54PROCsetstation
 1900   IFK%=55PROCshowregisters
 1920   IFK%=56PROCshoweverything
 1950 UNTILK%=48
 2000 VDU23,1,3;0;0;0;0;
 2050 END
 2100 DATA75,150,300,1200,2400,4800,9600,19200
 2150 DATANo printer,Parallel,Serial,User,Econet
 2200 DATASeconds,Seconds Alarm,Minutes,Minutes Alarm,Hours,Hours Alarm,Day of Week,Day of Month,Month,Year
 2250 DEFPROCassemble
 2300 FORB%=0TO2STEP2
 2350   P%=code
 2400   oswrch=&FFEE
 2450   slowbus=&FE4F:REM System VIA port A output
 2500   regb=&FE40   :REM System VIA port B control
 2550   ddra=&FE43   :REM System VIA port A direction
 2600   [OPTB%
 2650   .read JSRaddress
 2700   LDA#&49 \select read
 2750   STAregb
 2800   LDA#0:STAddra \ WasSTZ ddra, make 6502 compatible
 2850   LDA#&4A \set DS active
 2900   STAregb
 2950   LDYslowbus \value to be read in Y register
 3000   JMPfinish
 3050   .write  JSR address
 3100   LDA#&41 \select WR on addressable latch
 3150   STAregb
 3200   LDA#&4A \take DS active
 3250   STAregb
 3300   STYslowbus
 3350   JMPfinish \ Was BRA, make 6502 compatible
 3400   .address LDA #2\enter with X=selected address
 3450   STAregb \Write CE & DS inactive to system via
 3500   LDA#&82 \AS active
 3550   STAregb
 3600   LDA#&FF \slow databus as output
 3650   STAddra
 3700   STXslowbus \write register address
 3750   LDA#&C2 \Take CE active
 3800   STAregb
 3850   LDA#&42 \strobe AS low to latch data
 3900   STAregb
 3950   RTS
 4000   .finish LDA#&42 \deactivate DS
 4050   STAregb
 4100   LDA#&02 \deactivate CE
 4150   STAregb
 4200   RTS
 4250   .readregister
 4300   LDXreg:LDY#0:JSRread:STYcmos:RTS
 4350   .writeregister
 4400   LDXreg:LDYcmos:JSRwrite:RTS
 4450   .readall
 4500   LDX#0
 4550   .readloop
 4600   LDY#0
 4650   JSRread
 4700   TYA
 4750   STAcmos,X
 4800   INX
 4850   CPX#65
 4900   BNEreadloop
 4950   RTS
 5000   .printromtitle
 5050   LDA#&80:STA&F7
 5100   LDA#9:STA&F6 \ Rom title at &8009
 5150   .romloop
 5200   LDYreg \ Re-use register number byte - must be within loop to work on BBCB
 5250   JSR&FFB9 \ OSRDRM
 5300   CMP#31
 5350   BMIskipprint
 5400   JSR&FFE3 \ Print if sensible char
 5450   .skipprint
 5500   CMP#0
 5550   BEQromfinish
 5600   INC&F6
 5650   LDA&F6
 5700   CMP#9+16 \ 16 chars printed only (in case rubbish)
 5750   BNEromloop
 5800   .romfinish
 5850   RTS
 5900   .reg EQUB0
 5950   .cmos EQUS STRING$(14,CHR$0)
 6000   .cmosram EQUS STRING$(50,CHR$0)
 6050   ]
 6100 NEXT
 6150 ENDPROC
 6200 DEFFNreadreg(R%)
 6250 REMStore register number in .reg
 6300 ?reg=R%
 6350 REM Call read code, result in Y register
 6400 CALLreadregister:=?cmos
 6450 DEFPROCwritereg(R%,V%)
 6500 REM Store register number in .reg
 6550 ?reg=R%
 6600 ?cmos=V%:REMStore value to write in .write
 6650 CALLwriteregister
 6700 ENDPROC
 6750 DEFFNtime
 6800 T%=TIME:REPEATUNTIL(FNreadreg(&A)AND128)=0ORTIME>T%+20:REM Wait till no update in progress
 6850 =FNh(FNreadreg(4))+":"+FNh(FNreadreg(2))+":"+FNh(FNreadreg(0))
 6900 DEFFNdate
 6950 T%=TIME:REPEATUNTIL(FNreadreg(&A)AND128)=0ORTIME>T%+20:REM Wait till no update in progress
 7000 =MID$("SunMonTueWedThuFriSat",FNreadreg(6)*3-2,3)+","+FNh(FNreadreg(7))+" "+MID$("JanFebMarAprMayJunJulAugSepOctNovDec",FNreadreg(8)*3-2,3)+Y$+FNh(FNreadreg(9))
 7050 DEFFNtimestring
 7100 =FNdate+"."+FNtime
 7150 DEFFNtestcmos
 7200 REM Read byte 26 of CMOS (keyboard delay setting) to check 6818 presence
 7250 R%=FNreadreg(26):W%=255:IFR%=255 W%=128
 7300 PROCwritereg(26,W%)
 7350 N%=FNreadreg(26)
 7400 PROCwritereg(26,R%):REM restore old value if possible
 7450 IFN%=W% =TRUE ELSE =FALSE
 7500 DEFFNreaddse
 7550 =(FNreadreg(&B)AND1)=1
 7600 DEFPROCwritedse
 7650 PROCwritereg(&B,(FNreadreg(&B)OR1))
 7700 ENDPROC
 7750 DEFFNtestbst
 7800 PROCwritedse
 7850 T%=TIME:REPEATCALLreadall:UNTIL?cmos<&54 ORTIME>T%+600:REM do all this within the current minute
 7900 REPEATUNTILFNreadreg(0)<>FNreadreg(0):REM wait till second ticks
 7950 PRINT"Current time: "TAB(20);FNtimestring
 8000 FORB%=0TO9:?(cmos+B%+20)=?(cmos+B%):NEXT:REM Store old time
 8050 PROCwritereg(&B,(FNreadreg(&B)OR128)):REM stop the clock
 8100 U%=TIME:REM Record time elapsed during routine
 8150 PROCwritereg(8,&4):PROCwritereg(7,&30):PROCwritereg(6,1):PROCwritereg(4,&1):PROCwritereg(2,&59):PROCwritereg(0,&58):REM set time to Sun,30/4 1:59:58
 8200 PRINT"Setting time to:"TAB(20);FNtimestring
 8250 PROCwritereg(&B,(FNreadreg(&B)MOD128)):REM start the clock
 8300 PRINT"Waiting 2 seconds till 3am..."
 8350 T%=TIME:REPEATUNTILTIME>T%+200:REM Wait 2 seconds
 8400 B%=(FNreadreg(4)=&3):REM hours should be 3 if BST active
 8450 PRINT"Reading time..."TAB(20);FNtimestring
 8500 PROCwritereg(&B,(FNreadreg(&B)OR128)):REM stop the clock
 8550 FORC%=1TO9:PROCwritereg(C%,?(cmos+C%+20)):NEXT:REM Restore prev time exc.s
 8600 REPEATUNTILTIME>U%+300:Q%=EVAL(STR$~cmos?20):Q%=Q%+(TIME-U%)/100:Q%=EVAL("&"+STR$Q%):PROCwritereg(0,Q%):REM Need round no of seconds
 8650 PROCwritereg(&B,(FNreadreg(&B)MOD128)):REM start the clock
 8700 PRINT"Restoring time to:"TAB(20);FNtimestring
 8750 =B%
 8800 DEFPROCshowcmos
 8850 CLS
 8900 PRINTI$"CMOS RAM Settings:"N$
 8950 CALLreadall
 9000 PRINT"Econet Station Number"TAB(23);?cmosram
 9050 PRINT"Econet Servers"TAB(23)"File server: ";cmosram?2;".";cmosram?1;", Printer Server: ";cmosram?4;".";cmosram?3
 9100 PRINT"Default filing system"TAB(23);cmosram?5 MOD16;" (";:?reg=cmosram?5 MOD16:CALLprintromtitle:PRINT")"
 9150 PRINT"Default language"TAB(23);cmosram?5 DIV16;" (";:?reg=cmosram?5 DIV16:CALLprintromtitle:PRINT")"
 9200 IFM% MOD128=3 PROCshortplug ELSEPROClongplug
 9250 PRINT"EDIT settings"TAB(23);"Mode: ";:IF(cmosram?8 AND7)=2PRINT"K";ELSEIF(cmosram?8 AND7)=5PRINT"D";ELSEPRINT;(cmosram?8 AND7);
 9300 PRINT", TAB to ";:IFcmosram?8 ANDPRINT"Words";ELSEPRINT"Columns";
 9350 PRINT", ";:IFcmosram?8 AND16 PRINT"Insert";ELSEPRINT"Overwrite";
 9400 PRINT", ";:IFcmosram?8 AND32 PRINT"Show";ELSEPRINT"Hide";
 9450 PRINT" Returns"
 9500 PRINT"Telecoms settings"TAB(23);cmosram?9
 9550 PRINT"Screen settings"TAB(23);"Mode: ";128*((cmosram?10 AND8)/8)+(cmosram?10 AND7);", TV ";
 9600 T%=(cmosram?10 AND 128)/128*4+(cmosram?10 AND 64)/64*2+(cmosram?10 AND 32)/32*1:IFT%>3 T%=T%+248
 9650 PRINT;T%;",";(cmosram?10 AND16)/16;" (";:IFcmosram?10 AND16 PRINT"Interlace on)";ELSEPRINT"Interlace off)";
 9700 PRINT", ";:IFcmosram?16 AND 8 PRINT"No scroll";ELSEPRINT"Scroll";
 9710 IFcmos?16 AND 1:PRINT", Shadow"ELSEPRINT", No shadow"
 9750 PRINT"Floppy drive timings"TAB(23);cmosram?11 AND7
 9800 PRINT"ADFS Defaults"TAB(23);:IFcmosram?11 AND64 PRINT"No d";ELSEPRINT"D";
 9850 PRINT"irectory, ";:IFcmosram?11 AND128 PRINT"Floppy"ELSEPRINT"Winchester"
 9900 PRINT"Keyboard settings"TAB(23);"Repeat Delay: ";cmosram?12;", Repeat Rate: ";cmosram?13;", ";
 9950 IFcmosram?11 AND8PRINT"SHIFT-CAPS ";
10000 IFcmosram?11 AND16PRINT"No CAPS ";
10050 IFcmosram?11 AND32PRINT"CAPS Lock ";
10100 PRINT'"Second processor"TAB(23);:IFcmosram?16 ANDPRINT"External ";ELSEPRINT"Internal ";
10150 IFcmosram?15 ANDPRINT"(Enabled) "ELSEPRINT"(Disabled)"
10200 PRINT"Serial settings"TAB(23);"Baud rate: ";1+(cmosram?15 AND 16)/16*4+(cmosram?15 AND 8)/8*2+(cmosram?15 AND 4)/4*1;" (";baud$((cmosram?15 AND 16)/16*4+(cmosram?15 AND 8)/8*2+(cmosram?15 AND 4)/4*1);"), Data format: ";
10250 PRINT;(cmosram?16 AND 128)/128*4+(cmosram?16 AND 64)/64*2+(cmosram?16 AND 32)/32*1
10300 S%=(cmosram?15 AND 128)/128*4+(cmosram?15 AND 64)/64*2+(cmosram?15 AND 32)/32*1:PRINT"Printer settings"TAB(23);"Type: ";S%;" (";:IFS%<5 PRINTprinter$(S%); ELSEPRINT"Unknown";
10350 PRINT"), Ignore character: ";cmosram?14;" (";:IFcmosram?15 ANDPRINT"Not i";ELSEPRINT"I";
10400 PRINT"n use)"
10450 PRINT"Beep"TAB(23);:IFcmosram?16 AND 2 PRINT"Loud"ELSEPRINT"Quiet"
10500 PRINT"Autoboot"TAB(23);:IFcmosram?16 AND16 PRINT"Boot" ELSE PRINT"No boot"
10550 PRINT"ANFS Settings"TAB(23);:IFcmosram?17 AND 1 PRINT"Space";ELSEPRINT"No space";
10600 PRINT", FindLib ";:IFcmosram?17 ANDPRINT"on";ELSEPRINT"off";
10650 PRINT", Workspace ";:IFcmosram?17 ANDPRINT"&E/F";ELSEPRINT"&B/C";
10700 PRINT", Protection ";:IFcmosram?17 AND64PRINT"on";ELSEPRINT"off";
10750 PRINTTAB(23)"Display versions ";:IFcmosram?17 AND 128 PRINT"on"ELSEPRINT"off"
10800 PRINT"Joystick Settings"TAB(23)"Speed: ";cmosram?18 AND7;", ";:IFcmosram?18 AND 32 PRINT"Switched";ELSEPRINT"Proportional";
10810 PRINT", Century: ";19+(cmosram?18 DIV 64)
10820 PRINT"Country"TAB(23);cmosram?19
10830 PRINT"ROM bytes"TAB(23);:FOR A%=30 TO 45:PRINTFNh(cmos?A%);" ";:NEXT:PRINT
10850 ENDPROC
10900 DEFFNromtitle(?reg)
10950 CALLprintromtitle
11000 =TRUE:REM Doesn't need to be FN, could be PROc
11050 DEFPROCdisplaycmos
11100 PROCshowcmos:PRINT'R$
11150 REPEATPRINTTAB(50,0)"Time: ";FNtimestring:UNTILINKEY(10)<>-1
11200 ENDPROC
11250 DEFPROCdisplaytime
11300 CLS:PRINTI$"Display RTC Time and Date"N$''''R$
11350 REPEATPRINTTAB(0,2)FNtimestring:UNTILINKEY(10)<>-1
11400 ENDPROC
11450 DEFPROCtestchip
11500 CLS:PRINTI$"Test Presence of CMOS Chip"'N$
11550 IFFNtestcmos PRINT"6818 chip present"ELSEPRINT"No 6818 chip"
11600 PRINT'R$
11650 REPEATUNTILGET
11700 ENDPROC
11750 DEFPROCdisplayregs
11800 CLS:PRINTI$"Show Time Registers"N$
11850 *FX225,128
11900 REPEAT
11950   CALLreadall
12000   bcd=(cmos?&B AND4)=0
12050   PRINTTAB(0,2);
12100   FORB%=0TO13
12150     PRINT;B%;" - ";:IFB%<10 PRINTregs$(B%); ELSE PRINT"Register ";~B%;
12200     PRINTTAB(23);:IFB%<10 ANDbcd PRINT~cmos?B%  ELSE PRINTcmos?B%
12250   NEXT
12300   PRINT'"Register B Settings (toggle with f0-f3):"
12350   PRINT"Daylight saving"TAB(23);:IFFNreaddse PRINT"Enabled "ELSEPRINT"Disabled"
12400   PRINT"12/24 Hour Clock"TAB(23);:IFcmos?&B ANDPRINT"24-hour clock"ELSEPRINT"12-hour clock"
12450   PRINT"Data mode"TAB(23);:IFbcd PRINT"Binary coded decimal"ELSEPRINT"Decimal             "
12500   PRINT"Clock set"TAB(23);:IFcmos?&B AND 128 PRINT"Clock halted "ELSEPRINT"Clock running"
12550   PRINT'"Press "I$"f0-f3"N$" or any other"RIGHT$(R$,22)
12600   PRINTTAB(50,0)"Time: ";FNtimestring
12650   K%=INKEY(10)
12700   IFK%=128 PROCwritereg(&B,FNreadreg(&B) EOR1):K%=-1
12750   IFK%=129 PROCwritereg(&B,FNreadreg(&B)EOR2):K%=-1
12800   IFK%=130 PROCwritereg(&B,FNreadreg(&B)EOR4):K%=-1
12850   IFK%=131 PROCwritereg(&B,FNreadreg(&B)EOR128):K%=-1
12900 UNTILK%<>-1
12950 K%=0
13000 *FX225,1
13050 ENDPROC
13100 DEFPROClongplug
13150 FORB%=0TO7
13200   PRINT"ROM ";B%;" ";:IFcmosram?6 AND2^B% PRINT"Inserted"ELSEPRINT"Unplugged";
13250   PRINTTAB(23)"ROM ";B%+8;" ";:IFcmosram?7 AND2^B% PRINT"Inserted" ELSEPRINT"Unplugged"
13300 NEXT
13350 ENDPROC
13400 DEFPROCshortplug
13450 PRINT"ROMs Unplugged"TAB(23);
13500 FORC%=6TO7
13550   FORB%=0TO7
13600     IFcmosram?C% AND2^B% ELSE PRINT;B%+(C%-6)*8;" ";
13650 NEXT:NEXT
13700 PRINT'"ROMS Inserted"TAB(23);
13750 FORC%=6TO7
13800   FORB%=0TO7
13850     IFcmosram?C% AND2^B% PRINT;B%+(C%-6)*8;" ";
13900 NEXT:NEXT
13950 PRINT
14000 ENDPROC
14050 DEFPROCbsttest
14100 CLS:PRINTI$"Testing BST function of 6818 chip...."'N$
14150 IFNOTFNtestcmos PRINT"No 6818 chip":GOTO14250
14200 IFFNtestbst PRINT'"BST function present"ELSEPRINT'"No BST Function"
14250 PRINT''R$
14300 REPEATUNTILGET
14350 ENDPROC
14400 DEFPROCsetstation
14450 VDU23,1,3;0;0;0;0;
14500 CLS:PRINTI$"Set Econet station number"'N$
14550 PRINT"Current station number:   ";FNreadreg(14)
14600 REPEAT
14650   PRINT"Input new station number: ";:INPUT""S%
14700   IFS%<0 OR S%>254 PRINT"Bad station number"
14750 UNTILS%>=0 AND S%<255
14800 IFS%=0 PRINT"Unchanged"ELSEPRINT"Setting station number to ";S%:PROCwritereg(14,S%)
14850 PRINT'R$;
14900 REPEATUNTILGET
14950 ENDPROC
15000 DEFPROCshowregisters
15050 regsel=65:bitsel=7
15100 *FX4,1
15110 *FX219,9
15150 CLS
15200 PRINTI$"Show Registers A-D"N$
15250 PRINTTAB(0,28)I$"Arrow keys"N$" to change highlighted selection"I$'"RETURN"N$" to toggle bit"I$'"TAB"N$RIGHT$(R$,18)
15300 PRINTTAB(0,13)I$"Register A (R/W except bit 7)"N$'"Update in progress (7)"'"Divider bits (6-4)"'"Rate selection bits (3-0)"
15350 PRINTTAB(40,13)I$"Register B (R/W)"N$'TAB(40,14)"Set (Halt RTC)"TAB(40,15)"Periodic Interrupt Enable"TAB(40,16)"Alarm Interrupt Enable"TAB(40,17)"Update-Ended Interrupt Enable"
15400 PRINTTAB(40,18)"Square Wave Enable"TAB(40,19)"Data Mode"TAB(40,20)"24/12 Hr Clock"TAB(40,21)"Daylight Saving Enable"
15450 PRINTTAB(0,18)I$"Register C (R/O bits 7-4)"N$'"Interrupt Request Flag"'"Periodic Interrupt Flag"'"Alarm Interrupt Flag"'"Update-Ended Interrupt Flag"
15500 PRINTTAB(0,24)I$"Register D (R/O bit 7)"N$'"Valid RAM and Time - Power sense pin"
15520 PRINTTAB(0,1)"Bit     7       6      5      4      3      2      1      0"
15550 PRINTTAB(0,2)"Value   128     64     32     16     8      4      2      1       Total"
15560 FORB%=65TO68:PRINTTAB(0,-126+(B%*2))CHR$B%;:NEXT
15600 REPEAT
15650   PRINTTAB(50,0)"Time: ";FNtimestring
15700   FORB%=65TO68
15720     currentreg=FNreadreg(B%-55):REM Read once per pass to speed up
15750     REMPRINTTAB(0,-126+(B%*2))CHR$B%;  Moved earlier to speed up
15850     FORC%=7TO0STEP-1
15900       IFregsel=B% AND bitsel=C% PRINTI$; ELSEPRINTN$
15950       PRINTTAB(ABS(-55+(C%*7)),-126+(B%*2));"   ";:IFcurrentreg AND2^C% PRINT"1";ELSEPRINT"0";:REM wasFNreadreg(B%-55)AND2^C%
16000       PRINT"   ";
16050     NEXT
16100     PRINTTAB(66,-126+(B%*2));N$;currentreg;"  ";
16150   NEXT
16180   currentreg=FNreadreg(&A)
16200   IFcurrentreg AND128PRINTTAB(28,14)"Set  "ELSEPRINTTAB(28,14)"Clear"
16250   PRINTTAB(28,15);((currentreg AND112)/16);" "
16300   PRINTTAB(28,16);currentreg AND15;"  "
16320   currentreg=FNreadreg(&B)
16350   FORB%=7TO3STEP-1:IFcurrentreg AND2^B% PRINTTAB(70,ABS(-21+B%))"Set  "ELSEPRINTTAB(70,ABS(-21+B%))"Clear"
16400   NEXT
16450   PRINTTAB(70,19);:IFcurrentreg AND2^2 PRINT"Decimal"ELSEPRINT"BCD    "
16500   PRINTTAB(70,20);:IFcurrentreg AND2^1 PRINT"24-hr"ELSEPRINT"12-hr"
16550   PRINTTAB(70,21);:IFcurrentreg AND2^0 PRINT"Enabled "ELSEPRINT"Disabled"
16560   currentreg=FNreadreg(&C)
16600   FORB%=7TO4STEP-1:IFcurrentreg AND2^B% PRINTTAB(28,ABS(-26+B%))"Set  "ELSEPRINTTAB(28,ABS(-26+B%))"Clear"
16650   NEXT
16700   IFFNreadreg(&D)AND2^7 PRINTTAB(37,25)"High"ELSEPRINTTAB(37,25)"Low "
16720   K%=INKEY(0):IFK%=-1 OR K%=9  ELSEPROCdokeypress
16750 UNTILK%=9
16800 *FX4,0
16850 ENDPROC
16900 DEFPROCdokeypress
16950 IFK%=139 regsel=regsel-1:IFregsel<65 regsel=68
17000 IFK%=136 bitsel=bitsel+1:IFbitsel>7 bitsel=0
17050 IFK%=137 bitsel=bitsel-1:IFbitsel<0 bitsel=7
17100 IFK%=138 regsel=regsel+1:IFregsel>68 regsel=65
17150 IFK%=13 PROCwritereg(regsel-55,(FNreadreg(regsel-55)EOR2^bitsel))
17200 *FX15,1
17250 ENDPROC
18000 DEFPROCshoweverything
18020 CLS:PRINTI$"Show All CMOS Registers and Bytes"N$
18030 REPEAT
18040   CALLreadall
18045   PRINTTAB(0,2);
18050   FORB%=0TO13
18055     IFB%>6 PRINTTAB(40,B%-5);
18060     PRINT"Register ";B%;TAB(16);cmos?B%;TAB(20);"(&";FNh(cmos?B%);")"
18080   NEXT
18100   PRINT
18140   FORB%=0TO49
18160     PRINTTAB(20*(B% DIV13),10+(B% MOD13))"Byte ";B%;SPC(3-LENSTR$B%);SPC(3-LENSTR$(cmosram?B%));cmosram?B%;" (&";FNh(cmosram?B%);")"
18180   NEXT
18900   PRINTTAB(0,26)R$
18950 UNTILNOTINKEY(0)
18990 ENDPROC
19000 DEFFNh(A%)=RIGHT$("0"+STR$~A%,2)