10
20 :
30
40
50 ESCFLG =&FF :
60 FAULT =&FD :
70 SCANHEX =&FFA1 :
80 PRHEX =&FFAA :
90 PR2HEX =&FFAD :
100 PRTEXT =&FFB3 :
110 OSQUIT =&FFB9 :
120 OSERROR =&FFBC :
130 OSINIT =&FFBF :
140 PRSTRING=&FFC5 :
150 OSFIND =&FFCE :
160 OSGBPB =&FFD1 :
170 OSBPUT =&FFD4 :
180 OSBGET =&FFD7 :
190 OSARGS =&FFDA :
200 OSFILE =&FFDD :
210 OSRDCH =&FFE0 :
220 OSASCI =&FFE3 :
230 OSNEWL =&FFE7 :
240 OSWRCR =&FFEC :
250 OSWRCH =&FFEE :
260 OSWORD =&FFF1 :
270 OSBYTE =&FFF4 :
280 OS_CLI =&FFF7 :
290 BRKV =&0202 :
300 EVENTV =&0220 :
310 :
320 CODELOAD=&4000:DIM mcode% &400
330 FOR P=0 TO 1:opt%=P*3+4
340 P%=CODELOAD:O%=mcode%
350 [OPT opt%
360 \ CODE HEADER
370 \ -----------
380 .CODESTART
390 JMP CODEENTRY
400 BRK:BRK:BRK
410 EQUB &42
420 EQUB COPYMSG-CODESTART
430 EQUB 0
440 .TITLE
450 EQUS "65x02 Tube test program"
460 .COPYMSG
470 EQUB 0:EQUS "(C)2014 J.G.Harston"
480 EQUB 0
490 EQUD CODELOAD
500 :
510 .CODEENTRY
520 PHP:PHA:TYA:PHA:TXA:PHA:TSX
530 LDA &FFFB:BMI CHECK2
540 BRK:EQUB 255:EQUS "Not running on Tube":BRK
550 :
560 .CHECK2
570 LDA PRTEXT:CMP #&4C:BEQ DOTESTS
580 LDA &107,X:STA &EE:STA &F2
590 LDA &108,X:STA &EF:STA &F3
600 JSR MEMSWAP
610 JSR PRTEXT:EQUS "Old MOS ":BRK
620 :
630 .DOTESTS
640 LDX #TITLE AND 255:LDY #TITLE DIV 256
650 JSR PRSTRING:JSR OSNEWL
660 JSR PRTEXT:EQUS "A=&":EQUB 0
670 LDA &103,X:JSR PRHEX
680 JSR PRTEXT:EQUS " X=&":EQUB 0
690 LDA &101,X:JSR PRHEX
700 JSR PRTEXT:EQUS " Y=&":EQUB 0
710 LDA &102,X:JSR PRHEX
720 JSR PRTEXT:EQUS " S=&01":EQUB 0
730 TXA:CLC:ADC #4:JSR PRHEX
740 JSR PRTEXT:EQUS " P=&":EQUB 0
750 LDA &104,X:JSR PRHEX
760 :
770 JSR PRTEXT:EQUB 13:EQUS "MEMBOT=&":EQUB 0
780 LDA #&83:JSR OSBYTE:JSR PR2HEX
790 JSR PRTEXT:EQUS " MEMTOP=&":EQUB 0
800 LDA #&84:JSR OSBYTE:JSR PR2HEX
810 \JSR PRTEXT:\EQUB 13:\EQUS "CMD=> ":\EQUB 0
820 JSR OSNEWL:JSR OSNEWL
830 :
840 LDA PRTSAVE+6:BEQ DOTESTS2:JMP EXIT
850 .DOTESTS2
860 JSR PRTEXT:EQUS "TUBE MOS entries:":EQUB 13
870 EQUS "PRHEX: ":EQUB 0
880 LDX #0
890 .HEX1LP
900 TXA:JSR PRHEX:INX:CPX #14:BNE HEX1LP
910 JSR PRTEXT:EQUB 13:EQUS "PR2HEX: ":EQUB 0
920 LDX #0:LDY #0
930 .HEX2LP
940 JSR PR2HEX:JSR PRSPACE
950 INX:INX:INY:INY:INY:CPY #14:BCC HEX2LP
960 JSR PRTEXT:EQUB 13:EQUS "PRTEXT: This is using PRTEXT":EQUB 0
970 JSR PRTEXT:EQUB 13:EQUS "PRSTRING: ":EQUB 0
980 LDX #TEST3 AND 255:LDY #TEST3 DIV 256:JSR PRSTRING
990 .SKIP1
1000 JSR PRTEXT:EQUS "ERRJMP: save BRKV":EQUB 0
1010 LDA BRKV+0:STA BRKSAVE+0
1020 LDA BRKV+1:STA BRKSAVE+1
1030 JSR PRTEXT:EQUS ", claim BRKV":EQUB 0
1040 LDA #MYERR AND 255:STA BRKV+0
1050 LDA #MYERR DIV 256:STA BRKV+1
1060 JSR PRTEXT:EQUS ", generate error":EQUB 0
1070 BRK:EQUB 255:EQUS "Test error message":BRK
1080 .MYERR
1090 JSR PRTEXT:EQUB 13:EQUS "ERRJMP: caught error: ":EQUB 0
1100 LDY #0:LDA (FAULT),Y:JSR PRHEX:JSR PRSPACE
1110 LDX FAULT+0:LDY FAULT+1
1120 INX:BNE P%+3:INY:JSR PRSTRING
1130 JSR PRTEXT:EQUB 13:EQUS "ERRJMP: restore BRKV":EQUB 0
1140 LDA BRKSAVE+0:STA BRKV+0
1150 LDA BRKSAVE+1:STA BRKV+1
1160 JSR PRKEY
1170 JSR PRTEXT:EQUS"OS_CLI: *help":EQUB 13:EQUB 0
1180 LDX #CMDHELP AND 255:LDY #CMDHELP DIV 256:JSR OS_CLI
1190 JSR PRTEXT:EQUS "OSQUIT":EQUB 13:EQUB 0
1200 JMP OSQUIT
1210 :
1220 .EXIT
1230 PLA:PLA:PLA:PLA
1240 .MEMSWAP
1250 LDX #11
1260 .MEMLP1
1270 LDA PRHEX,X:LDY PRTSAVE,X
1280 STA PRTSAVE,X:TYA:STA PRHEX,X
1290 DEX:BPL MEMLP1:LDX #2
1300 .MEMLP2
1310 LDA PRSTRING,X:LDY PRSSAVE,X
1320 STA PRSSAVE,X:TYA:STA PRSTRING,X
1330 DEX:BPL MEMLP2:RTS
1340 :
1350 .PTEXT
1360 PLA:STA &FA:PLA:STA &FB
1370 JSR PSTR3:JMP (&00FA)
1380 .PSTR
1390 STX &FA:STY &FB
1400 .PSTR2
1410 LDY #0:LDA (&FA),Y
1420 BEQ PSTR3:JSR OSASCI
1430 .PSTR3
1440 INC &FA:BNE PSTR4:INC &FB
1450 .PSTR4
1460 TAY:BNE PSTR2:RTS
1470 :
1480 .P2HEX
1490 TYA:JSR PHEX:TXA
1500 .PHEX
1510 PHA:LSR A:LSR A:LSR A:LSR A
1520 JSR PNYB:PLA
1530 .PNYB
1540 AND #15:CMP #10:BCC PDIG:ADC #6
1550 .PDIG
1560 ADC #ASC"0":JMP OSWRCH
1570 :
1580 .PRSPACE:LDA #32:JMP OSWRCH
1590 .PRKEY
1600 JSR PRTEXT:EQUB 13:EQUB 13:EQUS "Press a key...":EQUB 0
1610 JSR OSRDCH:JMP OSWRCR
1620 :
1630 .TEST3:EQUS "This is using PRSTRING":EQUB 13:EQUB 0
1640 .CMDHELP:EQUS "help":EQUB 13
1650 .BRKSAVE:EQUW 0
1660 .PRTSAVE:JMP PHEX:JMP P2HEX:BRK:BRK:BRK:JMP PTEXT
1670 .PRSSAVE:JMP PSTR
1680 :
1690 ]NEXT
1700 PRINT"*SAVE TEST65 ";~mcode%;" ";~O%;" "~CODELOAD;" "~CODELOAD