10
20
30
40 IFPAGE>=&8000THENPRINT"6502 Machines only!":END
50 ?&284=&FF:$&404=STRING$(26*4-1,CHR$0):@%=&90A:Z%=0
60 DEFFNlo(A%)=A%AND&FF
70 DEFFNhi(A%)=(A%AND&FF00)DIV&100
80 DEFFNhex(X%,Y%)=RIGHT$("0000000"+STR$~X%,Y%)
90
100 FORP%=&B00TO&CFCSTEP4:!P%=&E5E5E5E5:NEXT:FORQ%=0TO2STEP2:P%=&B00:[OPTQ%
110 EQUS"(C)JR":.gcfs%SEC:JMP&FFC5:.code%CLD:LDA#1:LDX#&A8:LDY#0:JSR&FFDA:STY&AB:LDA&A8:STA&F2:LDA&A9:STA&F3
120 LDX#&FF:SEC:JSR&FFC2:JSR gcfs%:BCS cde1%:EOR#&30:CMP#4:EQUW&490:EOR#&30:BCS cde0%+5:TAX:JSR gcfs%:BCS cde1%:CMP#&20:BNE err0%
130 .cde0%JSR gcfs%:BCS cde1%:AND#&DF:CMP#&50:EQUW&3D0:ASLA:EQUW&4D0:CMP#&53:BNE err0%:BIT&AB:BNE err0%:ORA&AB:STA&AB:BNE cde0%
140 .cde1%STX osbk%:ASL&AB:BCC cde2%:LDX#FNlo(&FF-err0%+chms%):LDA chms%-FNlo(&FF-err0%+chms%),X:JSR&FFEE:INX:BNE cde1%+9:JSR&FFE0:PHP:JSR&FFE7:PLP:BCC cde2%:LDA#&7D:JMP&FFF4
150 .chms%EQUS"Change disc and press a key":.err0%EQUW&DC00:EQUS"Syntax: SWAP (<drive>) (P)(S)"
160 .err1%EQUW&B400:EQUS"Dir not empty":.err2%EQUW&FF00:EQUS"Bad SWAP disc":BRK
170 .cde2%JSR rdsc%-6
180 .cde3%STA&70:STX&71:STY&72:PHP:PLA:STA&73:RTS
190 .mkct%LDX#0:LDA cat0%-&F0,Y:STA&908,X:LDA cat1%-&F0,Y:STA&A08,X:INX:INY:BNE mkct%+2:STX&A05:RTS
200 .swsc%LDY#&21:JSR rdsc%-2:INX:EOR#2:JSR rdsc%:JSR swsc%+15:DEX:EOR#2:BPL wtsc%
210 LDY#&22:LDX#9:.wtsc%PHA:LDA#&4B:BNE rdsc%+3:LDA#0:LDY#&22:LDX#9:.rdsc%PHA:LDA#&53:STA osbk%+6:PLA
220 .oswd%STA osbk%+8:STX osbk%+2:STY osbk%+9:LDA#&7F:LDX#FNlo(osbk%):LDY#FNhi(osbk%):JSR&FFF1
230 LDY osbk%+9:LDX osbk%+2:LDA osbk%+10:EQUW&4D0:LDA osbk%+8:RTS:EQUW&C700:EQUS"Disc error":BRK:.osbk%BRK:EQUD&FFFF0900:EQUD3:BRK
240 .cat1%EQUW&900:EQUW code%:EQUD&4CC0200:EQUD0:EQUD&2000000:.cat0%EQUD&50415753:EQUD&A4202020:EQUD&212121A1:EQUD&A1212121
250 ]:NEXT:PRINT"Ended @:";~P%:IF&D00<P%THENPRINT"Code too long!":END
260 OSCLI"SAVE :1.SWAP FFFF0900+400 "+STR$~code%+" FFFF0900"
270 PRINT"Double cat system saved"
280 *SWAP 3