10 ; SAVE#D:DISK2.M65
20 ;
30 SNUMS .WORD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
40 ;
50 TYPED .BYTE 125,155,155,"[Type drv # and RETURN for directory]",0
60 TYPED2 .BYTE 155,155,"Please enter Source Filename:",155,155,0
70 NOTHERE .BYTE 125,155,155,"[ESC to exit, [1-8] for directories]",155,155
80       .BYTE " Please insert disk containing the",155
90       .BYTE "    below file, and hit RETURN.",155,155,"File: ",0
0100 LSTPS .BYTE 155,"This is the LAST pass!",155,0
0110 FMTDS .BYTE 155,"Format Destination disk?",0
0120 FMTSK .BYTE 155,"Use UltraSpeed sector skew?",0
0130 BDFMT .BYTE 125,155,155,"Error: Disk will not format!!!",155,0
0140 BADBY .BYTE 125,155,155,"There are Bad Bytes in this file!!!",155
0150     .BYTE 155,"Please download this file again or",155
0160     .BYTE "try FILEFIX2 on it!  Press RETURN",0
0170 WRTAG .BYTE 125,155,155,"Error while writing to Disk!",155,0
0180 WRTAG1 .BYTE 155,"Correct problem, and hit RETURN",0
0190 SELB JSR BELL
0200     LDX #TYPED&255
0210     LDY #TYPED/256
0220     JSR PRINT
0230 FIX2 LDX #TYPED2&255
0240     LDY #TYPED2/256
0250     JSR PRINT
0260     LDA #1
0270     STA PASTYP
0280     LDA #0
0290     STA OFSET
0300     STA OFSET+1
0310     STA XEUSED
0320     STA LASTFLG
0330     STA PASS
0340     STA EOFFLG
0350     JSR INITRAM
0360     LDA SOURCE
0370     STA DRIVE
0380     JSR ENTF
0390     BCC FIX3
0400     LDA #2
0410     STA 85
0420     LDA #11
0430     STA 84
0440     JMP FIX2
0450 FIX3 JSR MOVTF
0460     JMP SB8A
0470 SB8 LDX SOURCE
0480     CPX DEST
0490     BNE SELB2
0500 SB8A LDX #INSRTSRC&255
0510     LDY #INSRTSRC/256
0520     JSR PRINT
0530     JSR WSTART
0540 SELB2 JSR NCLOSE
0550     LDA FNAME+1
0560     CMP #':
0570     BNE SELB2A
0580     LDA #'1
0590 SELB2A SEC 
0600     SBC #'0
0610     STA SOURCE
0620     STA DRIVE
0630     TAX 
0640     JSR READ1DEN
0650     STA SRCDEN
0660     JSR SRCDNS
0670     LDA DEST
0680     STA DRIVE
0690     LDY #3
0700     STY $0352
0710     LDA #FNAME&255
0720     STA $0354
0730     LDA #FNAME/256
0740     STA $0355
0750     STA $0359
0760     INY 
0770     STY $035A
0780     LDX #$10
0790     JSR $E456
0800     BPL SELB3
0810 SELB00 STY YTEMP
0820     JSR NCLOSE
0830     LDY YTEMP
0840     JSR READERR
0850     LDA YTEMP
0860     CMP #170
0870     BNE SELB0
0880     LDA PASTYP
0890     BEQ SELB4
0900 SELB0 JMP MAIN
0910 SELB4 LDX #NOTHERE&255
0920     LDY #NOTHERE/256
0930     JSR PRINT
0940     LDA #0
0950     STA YTEMP
0960 SELB4A LDY YTEMP
0970     LDA FNAME,Y
0980     JSR OUTCHR
0990     CMP #$9B
1000     BEQ SELB4B
1010     INC YTEMP
1020     BNE SELB4A
1030 SELB4B JSR KGETCH
1040     CMP #$1B
1050     BEQ SELB0
1060     CMP #$9B
1070     BEQ SELB2
1080     JSR UPPER
1090     CMP #$41
1100     BCS SELB4B
1110     CMP #$20
1120     BCC SELB4B
1130     JSR SELDIR
1140     JMP SELB4
1150 SELB3 JSR DGETCHR
1160     CMP #249
1170     BEQ SELB3A
1180     CMP #250
1190     BEQ SELB3A
1200     CMP #$FF
1210     BEQ SELB3B
1220     CMP #0
1230     BEQ SELB3C
1240     LDY #0
1250     .BYTE $2C
1260 SELB3B LDY #29
1270     .BYTE $2C
1280 SELB3C LDY #57
1290     LDX #0
1300 SELB3D LDA NOTDM,Y
1310     STA STATUSL1+10,X
1320     INY 
1330     INX 
1340     CPX #29
1350     BCC SELB3D
1360     JSR NCLOSE
1370     JSR BELL
1380     JMP MAIN
1390 SELB3A SEC 
1400     SBC #249
1410     STA PASTYP
1420     JMP SELB3E
1430 DGETCHR LDX #$10
1440     LDA #7
1450     STA $0342,X
1460     LDA #0
1470     STA $0348,X
1480     STA $0349,X
1490     JMP $E456
1500 RDFIL LDY #28
1510 RDFIL1 LDA RDFILE,Y
1520     STA STATUSL1+10,Y
1530     DEY 
1540     BPL RDFIL1
1550     LDY #0
1560 RDFIL2 LDA FNAME,Y
1570     CMP #$9B
1580     BEQ RDFIL3
1590     CLC 
1600     ADC #$60
1610     STA STATUSL1+18,Y
1620     INY 
1630     CPY #20
1640     BCC RDFIL2
1650 RDFIL3 RTS 
1660 RDFILE .SBYTE "Reading                      "
1670 WRDISK .SBYTE "Writing to Destination Disk  "
1680 BADFL .SBYTE "Bad Bytes in the File!!!     "
1690 NOTDM .SBYTE " Not a DISKCOMM File!!!      Binary or Shrink file!!!     BASIC or Scrunch file!!!     "
1700 SELB3E LDA PASTYP
1710     BNE SELB3F
1720     LDA PASS
1730     BNE SELB3F
1740     JSR ENTF05
1750 SELB3F JSR RDFIL
1760     LDA #$80
1770     STA TLEN
1780     LDA #0
1790     STA TLEN+1
1800     JSR DGETCHR
1810     STA PASS
1820 SB7 AND #$60
1830     LSR A
1840     LSR A
1850     LSR A
1860     LSR A
1870     LSR A
1880     CLC 
1890     ADC #1
1900     STA DRIVDEN
1910     STA DSTDEN
1920     CMP #2
1930     BNE SELB3F1
1940     LDY #0
1950     STY TLEN
1960     INY 
1970     STY TLEN+1
1980 SELB3F1 LDX DEST
1990     LDA DSTDEN
2000     JSR DESTDNS
2010     JSR DSPPASS
2020     STA STATUSL4+24
2030 RLD1 LDA #7
2040     STA $0352
2050     LDA #BUFFER&255
2060     CLC 
2070     ADC OFSET
2080     STA $0354
2090     LDA #BUFFER/256
2100     ADC OFSET+1
2110     STA $0355
2120     LDA #BUFLEN&255
2130     SEC 
2140     SBC OFSET
2150     STA $0358
2160     LDA #BUFLEN/256
2170     SBC OFSET+1
2180     STA $0359
2190     LDX #$10
2200     JSR $E456
2210     CLC 
2220     LDA OFSET
2230     ADC $0358
2240     STA BLEN
2250     LDA OFSET+1
2260     ADC $0359
2270     STA BLEN+1
2280     CPY #127
2290     BCC SELB3G
2300     CPY #136
2310     BEQ SELB3H
2320 SELB3I JMP SELB00
2330 SELB3G LDA #1
2340     STA PASTYP  ;SET TO 1 IF OVERFLOWED BUFFER
2350     LDA XERAM
2360     BEQ SELB3H
2370     JSR RDFIL
2380     JSR RAMLOAD
2390     CPY #128
2400     BCS SELB3I
2410     LDY #1
2420     STY XEUSED
2430     STY CURBNK
2440     DEY 
2450     STY CURLOC
2460     LDA #$40
2470     STA CURLOC+1
2480 SELB3H LDA PASS
2490     BPL SELB5
2500     LDX #LSTPS&255
2510     LDY #LSTPS/256
2520     JSR PRINT
2530     JSR BELL
2540 SELB5 LDX DEST
2550     LDA DSTDEN
2560     JSR SETDNS
2570     CPX SOURCE
2580     BNE SELB5C
2590     JSR PINSDEST
2600     JSR WSTART
2610 SELB5C LDA PASS
2620     AND #$1F
2630     CMP #1
2640     BNE SELB5A
2650     LDX #FMTDS&255
2660     LDY #FMTDS/256
2670     JSR PRINT
2680     LDA #$FF
2690     STA 764
2700     JSR BELL
2710 SELB5B JSR KGETCH
2720     CMP #$1B
2730     BEQ SELB5E
2740     JSR UPPER
2750     CMP #'Y
2760     BEQ SELB9Z
2770     CMP #'N
2780     BEQ SELB9Z
2790     CMP #$1B    ;A RETURN
2800     BNE SELB5B
2810     LDA #'N
2820 SELB9Z PHA 
2830     JSR OUTCHR
2840     LDA #$9B
2850     JSR OUTCHR
2860     PLA 
2870     CMP #'Y
2880     BEQ SELB5D
2890     JMP SELB5A
2900 SELB5E JMP MAIN
2910 FMT1A STY YTEMP
2920     LDX #BDFMT&255
2930     LDY #BDFMT/256
2940     JSR PRINT
2950     LDY YTEMP
2960     JSR WRITERR
2970 FMT2Y LDX #WRTAG1&255
2980     LDY #WRTAG1/256
2990     JSR PRINT
3000     JSR WSTART
3010     JSR SELB5
3020 SELB5D LDA DRIVDEN
3030     JSR FMTDNS
3040     CPY #128
3050     BCS FMT1A
3060     LDA 20
3070     ADC #70
3080 SELB5F CMP 20
3090     BNE SELB5F
3100 SELB5A
3110     LDA #BUFFER&255
3120     STA BCUR
3130     LDA #BUFFER/256
3140     STA BCUR+1
3150 SELB6 LDA #TRKBUF&255
3160     STA SLOC
3170     LDA #TRKBUF/256
3180     STA SLOC+1
3190     LDA #0
3200     STA NUMSECS
3210     JSR WRTDEST
3220     JSR CLRWIND
3230 SELB6A JSR UNCOMP
3240     CPY #1
3250     BNE SELB6B
3260     JMP SELB6F
3270 SELB6B CPY #$80
3280     BNE SELB6C
3290     LDX #BADBY&255
3300     LDY #BADBY/256
3310     JSR PRINT
3320     LDY #28
3330 SELB6B1 LDA BADFL,Y
3340     STA STATUSL1+10,Y
3350     DEY 
3360     BPL SELB6B1
3370     JSR BELL
3380     JSR WSTART
3390     JMP MAIN
3400 SELB6C LDA NUMSECS
3410     ASL A
3420     TAX 
3430     LDA CSECTOR
3440     STA SNUMS,X
3450     LDA CSECTOR+1
3460     STA SNUMS+1,X
3470     LDY #0
3480 SELB6D LDA PREVSEC,Y
3490     STA (SLOC),Y
3500     INY 
3510     CPY TLEN
3520     BNE SELB6D
3530     CLC 
3540     LDA SLOC
3550     ADC TLEN
3560     STA SLOC
3570     LDA SLOC+1
3580     ADC TLEN+1
3590     STA SLOC+1
3600     INC NUMSECS
3610     LDA TLEN+1
3620     BEQ SELB6E
3630     INC NUMSECS
3640 SELB6E LDA NUMSECS
3650     CMP #18
3660     BCS SELB6F
3670     JMP SELB6A
3680 SELB6F LDA NUMSECS
3690     BNE SELB6G
3700     JMP SELB6L
3710 SELB6G LDA #0
3720     STA DATA
3730     LDA #TRKBUF&255
3740     STA $0304
3750     LDA #TRKBUF/256
3760     STA $0305
3770     LDA VERIFY
3780     STA COMMAND
3790 SELB6H LDA DATA
3800     ASL A
3810     TAX 
3820     LDA SNUMS,X
3830     STA SECTOR
3840     LDA SNUMS+1,X
3850     STA SECTOR+1
3860     TAX 
3870     LDA SECTOR
3880     LDY #17
3890     JSR DECPRT
3900     LDA $0304
3910     STA MWIND
3920     LDA $0305
3930     STA MWIND+1
3940     JSR DISKIO
3950     CPY #1
3960     BEQ SELB6I
3970     STY YTEMP
3980     JSR WRITERR
3990     LDA YTEMP
4000     CMP #144
4010     BNE SELB6Z
4020     LDX #WRTAG&255
4030     LDY #WRTAG/256
4040     JSR PRINT
4050     JMP FMT2Y
4060 SELB6Z JMP MAIN
4070 SELB6I CLC 
4080     LDA $0304
4090     ADC TLEN
4100     STA $0304
4110     LDA $0305
4120     ADC TLEN+1
4130     STA $0305
4140     INC DATA
4150     LDA TLEN+1
4160     BEQ SELB6J
4170     INC DATA
4180 SELB6J LDA DATA
4190     CMP NUMSECS
4200     BCS SELB6K
4210     JMP SELB6H
4220 SELB6K CMP #18
4230     BNE SELB6L
4240     JMP SELB6
4250 SELB6L LDA PASS
4260     BPL SELB6M
4270 SELB6Y LDY #28
4280 SELB6N LDA FILDSK,Y
4290     STA STATUSL1+10,Y
4300     DEY 
4310     BPL SELB6N
4320     JMP MAIN
4330 FILDSK .SBYTE "File(s) turned into Disk!!!  "
4340 SELB6M JSR NEWCLR
4350     SEC 
4360     LDA BCUR
4370     SBC #[BUFFER-2]&255
4380     STA EXTMP
4390     LDA BCUR+1
4400     SBC #[BUFFER-2]/256
4410     STA EXTMP+1 ;EXTMP=HOW MUCH
4420     SEC         ;BUFFER WAS USED
4430     LDA BLEN    ;+ 0 BYTES FOR
4440     SBC EXTMP   ;END, + 2 BYTES
4450     STA YTEMP   ;FOR NEXT HDR
4460     LDA BLEN+1
4470     SBC EXTMP+1
4480     ORA YTEMP
4490     BEQ SB9
4500     BCS SB0
4510 SB9 LDA PASTYP
4520     BNE SELB6Y
4530     LDX INCCHR
4540     INC FNAME,X
4550     JSR CLRWIND
4560     JMP SB8
4570 SB0 LDA BLEN
4580     SBC EXTMP
4590     STA OFSET
4600     STA OFFSET
4610     LDA BLEN+1
4620     SBC EXTMP+1
4630     STA OFSET+1
4640     STA OFFSET+1
4650     LDA #BUFFER&255
4660     STA SLOC
4670     LDA #BUFFER/256
4680     STA SLOC+1
4690     LDY #1
4700     LDA (BCUR),Y
4710     CMP #'E     ;FIXED 3.0 BUG
4720     BNE SB0A
4730     DEY 
4740     CMP (BCUR),Y
4750     BNE SB0A
4760     INC BCUR
4770     BNE SB0B
4780     INC BCUR+1
4790 SB0B LDY #1
4800     SEC 
4810     LDA OFSET
4820     SBC #1
4830     STA OFSET
4840     LDA OFSET+1
4850     SBC #0
4860     STA OFSET+1
4870     LDA (BCUR),Y
4880 SB0A STA PASS
4890     CLC 
4900     LDA BCUR
4910     ADC #2
4920     STA BCUR
4930     LDA BCUR+1
4940     ADC #0
4950     LDY #0
4960     STA BCUR+1
4970 SB1 LDA (BCUR),Y ;MOVE REST
4980     STA (SLOC),Y ;OF BUFFER
4990     INC BCUR    ;TO BEGINNING,
5000     BNE SB2     ;SET OFSET
5010     INC BCUR+1  ;ACCORDINGLY
5020 SB2 INC SLOC
5030     BNE SB3
5040     INC SLOC+1
5050 SB3 SEC 
5060     LDA OFFSET
5070     SBC #1
5080     STA OFFSET
5090     LDA OFFSET+1
5100     SBC #0
5110     STA OFFSET+1
5120     ORA OFFSET
5130     BNE SB1
5140     JSR CLRWIND
5150     LDA XEUSED
5160     BNE SB4
5170     LDA EOFFLG
5180     BNE SB42
5190     JSR RDFIL
5200 SB41 JSR BACKSRC
5210     LDA PASS
5220     JMP SB7
5230 SB4 JSR RAMMOVE
5240     BCC SB42
5250     LDA EOFFLG
5260     BNE SB42
5270     JMP SB41
5280 SB42 JSR DSPPASS
5290     LDA PASS
5300     BPL SB43
5310     LDX #LSTPS&255
5320     LDY #LSTPS/256
5330     JSR PRINT
5340     JSR BELL
5350 SB43 JMP SELB5A
5360 ;
5370 BACKSRC LDX SOURCE
5380     LDA SRCDEN
5390     JSR SETDNS
5400     CPX DEST
5410     BNE BKS1
5420     LDX #INSRTSRC&255
5430     LDY #INSRTSRC/256
5440     JSR PRINT
5450     JSR WSTART
5460 BKS1 RTS 
5470 ;
5480 ;
5490 UNCOMP LDY #0
5500     LDA LASTFLG
5510     BPL UC1
5520     INC CSECTOR
5530     BNE UC2
5540     INC CSECTOR+1
5550 UC2 JMP UC3
5560 UC1 LDA (BCUR),Y
5570     STA CSECTOR
5580     INY 
5590     LDA (BCUR),Y
5600     STA CSECTOR+1
5610     INY 
5620 UC3 LDA (BCUR),Y
5630     PHA 
5640     AND #$80
5650     STA LASTFLG
5660     PLA 
5670     AND #$7F
5680     LDX #0
5690     INY 
5700     CMP #'E
5710     BNE UNC1
5720     TYA 
5730     JSR UNADD
5740     LDY #1
5750     RTS         ;GOOD RETURN
5760 UNC1 CMP #'G
5770     BNE UNC2
5780     TYA 
5790     JSR UNADD
5800     LDY #0
5810 UNC1A LDA (BCUR),Y
5820     STA PREVSEC,Y
5830     INY 
5840     CPY TLEN
5850     BNE UNC1A
5860     LDA #128
5870     JSR UNADD
5880     LDA TLEN+1
5890     BEQ UNC1B
5900     LDA #128
5910 UNADD2 JSR UNADD
5920 UNC1B LDY #0
5930     RTS 
5940 UNC2 CMP #'B
5950     BNE UNC3
5960 UNC2A LDA (BCUR),Y
5970     STA PREVSEC+120,Y
5980     INY 
5990     CPY #8
6000     BCC UNC2A
6010     LDY #123
6020     LDA PREVSEC,Y
6030 UNC2B STA PREVSEC,Y
6040     DEY 
6050     BPL UNC2B
6060     LDA #8
6070     JMP UNADD2
6080 UNC3 CMP #'C
6090     BNE UNC4
6100 UNC3A LDA (BCUR),Y
6110     STA OFFSET
6120     INY 
6130     TYA 
6140     JSR UNADD
6150     LDY #0
6160 UNC3B CPX OFFSET
6170     BEQ UNC3C
6180     LDA (BCUR),Y
6190     STA PREVSEC,X
6200     INY 
6210     INX 
6220     CPX TLEN
6230     BNE UNC3B
6240 UNC3B2 TYA 
6250     CMP #0
6260     BEQ UNC3B1
6270     JMP UNADD2
6280 UNC3B1 LDA #$80
6290     JSR UNADD
6300     LDA #$80
6310     JMP UNADD2
6320 UNC3C LDA (BCUR),Y
6330     STA UNTIL
6340     INY 
6350     LDA (BCUR),Y
6360 UNC3D STA PREVSEC,X
6370     INX 
6380     CPX TLEN
6390     BEQ UNC3E
6400     CPX UNTIL
6410     BNE UNC3D
6420     INY 
6430     JMP UNC3A
6440 UNC3E INY 
6450     JMP UNC3B2
6460 UNADD CLC 
6470     ADC BCUR
6480     STA BCUR
6490     LDA BCUR+1
6500     ADC #0
6510     STA BCUR+1
6520     RTS 
6530 UNC4 CMP #'F
6540     BNE UNC5
6550     TYA 
6560     JMP UNADD2
6570 UNC5 CMP #'A
6580     BNE UNC6
6590     LDA (BCUR),Y
6600     TAX 
6610 UNC5A INY 
6620     LDA (BCUR),Y
6630     STA PREVSEC,X
6640     DEX 
6650     CPX #$FF
6660     BNE UNC5A
6670     INY 
6680     TYA 
6690     JMP UNADD2
6700 UNC6 CMP #'D
6710     BNE UNC7
6720     LDA (BCUR),Y
6730     TAX 
6740 UNC6A INY 
6750     LDA (BCUR),Y
6760     STA PREVSEC,X
6770     INX 
6780     CPX TLEN
6790     BNE UNC6A
6800     INY 
6810     TYA 
6820     JMP UNADD2
6830 UNC7 LDY #$80
6840     RTS         ;BAD BYTES
6850 ;
6860 ;
6870 WRTDEST LDY #28
6880 WRTDS1 LDA WRDISK,Y
6890     STA STATUSL1+10,Y
6900     DEY 
6910     BPL WRTDS1
6920     RTS 
6930 ;
6940 ENHCMP
6950     LDA #0
6960     STA NUMSECS
6970     LDA #TRKBUF&255
6980     STA SLOC
6990     LDA #TRKBUF/256
7000     STA SLOC+1
7010     LDA TLEN+1
7020     CLC 
7030     ADC #1
7040     STA YTEMP
7050     LDA #0
7060     STA OFFSET
7070     STA BUFDUP+18
7080 EHC1 LDY #0
7090 EHC2 LDA (SLOC),Y
7100     BNE EHC3
7110     INY 
7120     CPY TLEN
7130     BNE EHC2
7140     LDA #0
7150     JMP EHC3A
7160 EHC3 LDA OFFSET
7170 ;   CMP #0
7180     BEQ EHC3B
7190     LDA #$81
7200     .BYTE $2C
7210 EHC3B LDA #$80
7220 EHC3A LDX NUMSECS
7230     STA BUFDUP,X
7240     STA OFFSET
7250     CLC 
7260     LDA SLOC
7270     ADC TLEN
7280     STA SLOC
7290     LDA SLOC+1
7300     ADC TLEN+1
7310     STA SLOC+1
7320     LDA NUMSECS
7330     CLC 
7340     ADC YTEMP
7350     STA NUMSECS
7360 EHC4 CMP #18
7370     BCC EHC1
7380     LDY #0
7390     LDX YTEMP
7400 EHC6 LDA BUFDUP,Y
7410     BEQ EHC7
7420     AND #1
7430     STA OFFSET
7440     LDA BUFDUP,X
7450     BPL EHC6A
7460     JMP EHC7
7470 EHC6A LDA #2
7480     SEC 
7490     SBC OFFSET
7500     STA BUFDUP,Y
7510 EHC7 TXA 
7520     CLC 
7530     ADC YTEMP
7540     TAX 
7550     TYA 
7560     CLC 
7570     ADC YTEMP
7580     TAY 
7590     CPY #18
7600     BCC EHC6
7610     RTS 
7620 ;
7630 ;THE CUSTOM SIO:
7640 ;
7650 DRVTAB .BYTE " BEQ SIV2
7730     LDY $0301
7740     LDA DRVTAB-1,Y
7750     BEQ STST
7760     CMP #$28
7770     BEQ SIOV2
7780     JMP SHSP
7790 SIOV2 JSR $E459
7800     CPY #138
7810     BNE SIV1
7820     LDX $0301
7830     LDA #0
7840     STA DRVTAB-1,X
7850 SIV1 TYA 
7860     RTS 
7870     STA $F6
7880 SIV2 LDX $0301
7890     LDA #$28
7900     STA DRVTAB-1,X
7910     JMP $E459
7920 STST LDY #9
7930 SIV3 LDA $0302,Y ;STORE SIOB
7940     STA $E0,Y
7950     DEY 
7960     BPL SIV3
7970     LDA #'?
7980     STA $0302
7990     LDA #$40    ;SEND THE ? CMD
8000     STA $0303
8010     LDA #0
8020     STA $0304
8030     STA $0305
8040     STA $0309
8050     STA $030B
8060     LDA #1
8070     STA $0308
8080     STA $0306
8090     LDA #$20
8100     STA $030A
8110     LDY #$28    ;19.2K BAUD
8120     LDX #6      ;8 RETRIES
8130     LDA #$A0    ;QUIET I/O
8140     JSR HISIO
8150     BPL SIV4A
8160     LDA #'H
8170     STA $0302
8180     LDA #0
8190     STA $0303
8200     LDY #$28
8210     LDX #4
8220     LDA #$A0
8230     JSR HISIO
8240     BPL SIV4B
8250     LDA #$D3    ;INVERSE S
8260     STA $0302
8270     LDA #$40
8280     STA $0303
8290     LDX #4
8300     STX $0308
8310     LDA #$EA
8320     STA $0304
8330     LDA #2
8340     STA $0305
8350     LDA #$A0
8360     LDY #ATASIO
8370     JSR HISIO
8380     BPL SIV4C
8390     LDA #$28    ;19.2K
8400     .BYTE $2C
8410 SIV4A LDA 0     ;US DOUBLER
8420     .BYTE $2C
8430 SIV4B LDA #16   ;810 HAPPY
8440     .BYTE $2C
8450 SIV4C LDA #ATASIO ;ATARI
8460     LDY $0301
8470     STA DRVTAB-1,Y
8480     LDY #9
8490 SIV5 LDA $E0,Y
8500     STA $0302,Y ;PUT EVERYTHING
8510     DEY         ;BACK...
8520     BPL SIV5
8530     JMP SIOV
8540 ;
8550 SHSP TAY 
8560     CMP #16     ;HAPPY 810?
8570     BEQ SHSP5
8580     LDA $0302
8590     CMP #$21
8600     BEQ SIOF0
8610     CMP #$22
8620     BEQ SIOF0
8630     LDY $0301
8640     LDA DRVTAB-1,Y
8650     CMP #ATASIO
8660     BEQ SHSP2
8670 SHSP1 LDY $0301
8680     LDA DRVTAB-1,Y
8690     TAY 
8700 SHSP5 LDX #33   ;20 RETRIES
8710     LDA $0303
8720     STA TEMP303
8730     LDA #$A8
8740     JSR HISIO
8750     CPY #138
8760     BNE SHSP4
8770     LDA TEMP303
8780     STA $0303
8790     JMP SIV2
8800 SHSP4 TYA 
8810     RTS 
8820 SHSP2 LDA $0302
8830     CMP #$23
8840     BCC SHSP0
8850     ORA #$80
8860     STA $0302
8870     JMP SHSP1
8880 SHSP9 LDA $0302
8890     ORA #$80
8900     STA $0302
8910 SHSP0 JMP $E459
8920 ;
8930 SIOF0 CPY #0
8940     BEQ SHSP0
8950     LDX #FMTSK&255
8960     LDY #FMTSK/256
8970     JSR PRINT
8980 SIOF9 JSR KGETCH
8990     JSR UPPER
9000     CMP #'Y
9010     BEQ SIOF8
9020     LDA #'N
9030 SIOF8 PHA 
9040     JSR OUTCHR
9050     LDA #$9B
9060     JSR OUTCHR
9070     PLA 
9080     CMP #'Y
9090     BEQ SIOF8A
9100     LDX #13     ;DO NORM FMT
9110     LDY #$28
9120     LDA #$A8
9130     JMP HISIO
9140 SIOF8A LDY $0301
9150     LDA DRVTAB-1,Y
9160     CMP #ATASIO
9170     BEQ SHSP9
9180     LDA $0302
9190     CMP #$21
9200     BEQ SIOF1
9210     LDX #ENHTAB&255
9220     LDY #ENHTAB/256
9230     JMP SIOF3
9240 SIOF1 LDA $0309
9250     BEQ SIOF4
9260     LDX #DBLTAB&255
9270     LDY #DBLTAB/256
9280     JMP SIOF3
9290 SIOF4 LDX #SNGTAB&255
9300     LDY #SNGTAB/256
9310 SIOF3 STX $0304
9320     STY $0305
9330     LDA #'f
9340     STA $0302
9350     LDA #$80
9360     STA $0303
9370     STA $0308
9380     LDA #0
9390     STA $0309
9400     JMP SHSP1
9410 ;
9420 HISIO STX $0319
9430     STA $FF     ;QUIET I/O FLG
9440     STY $FE
9450     TSX 
9460     STX $FC
9470     SEI 
9480     LDA #2
9490     STA $F7
9500 SIO10 LDA $0319
9510     STA $F6
9520 SIO11 JSR SIO39
9530     LDA #$34
9540     STA $D303   ;SET CMD LINE
9550     JSR SIO21
9560     JSR SIO43
9570     BIT $0303   ;WHICH DIR?
9580     BPL SIO15
9590     JSR SIO21
9600 SIO15 DEC $F5
9610     JSR SIO27
9620     BIT $0303
9630     BVC SIO17
9640     LDA #0
9650     STA $F1
9660     LDY #24
9670     JSR SIO31
9680     LDY #0
9690 SIO16 JSR SIO34
9700     STA ($F2),Y
9710     CLC 
9720     ADC $F1
9730     ADC #0
9740     STA $F1
9750     INY 
9760     CPY $F4
9770     BNE SIO16
9780     JSR SIO34
9790     CMP $F1
9800     BNE SIO25   ;BAD CHECKSUM
9810 SIO17 LDA #$A0
9820     STA $D207
9830     LDA $10
9840     STA $D20E
9850     JSR SIO30
9860     LDY $F0
9870     BEQ SIO18
9880     DEC $F7
9890     BEQ SIO19
9900     JMP SIO10
9910 SIO18 INY 
9920 SIO19 CLI 
9930     STY $0303
9940     TYA 
9950     RTS 
9960 SIO21 LDX #$FF
9970 SIO22 DEX 
9980     BNE SIO22
9990     JSR SIO37
010000   LDY #0
010010   LDA ($F2),Y
010020   STA $F1
010030   STA $D20D
010040 SIO23 INY 
010050   CPY $F4
010060   BEQ SIO24
010070   LDA ($F2),Y
010080   JSR SIO35
010090   CLC 
010100   ADC $F1
010110   ADC #0
010120   STA $F1
010130   JMP SIO23
010140 SIO24 LDA $F1
010150   JSR SIO35
010160 SIO20 LDA $D20E
010170   AND #8
010180   BNE SIO20
010190   LDY #2
010200   JSR SIO31
010210   LDA #$C0
010220   STA $D20E
010230   JMP SIO28
010240 SIO25 LDA #$8A
010250 SIO26 STA $F0
010260   LDX $FC
010270   TXS 
010280   BIT $F5
010290   BMI SIO17
010300   DEC $F6
010310   BEQ SIO17
010320   JMP SIO11
010330 SIO27 LDA $0306
010340   ROR A
010350   ROR A
010360   TAY 
010370   AND #$3F
010380   TAX 
010390   TYA 
010400   ROR A
010410   AND #$C0
010420   TAY 
010430   JSR SIO32
010440 SIO28 JSR SIO38
010450   LDA #$3C
010460   STA $D303
010470   JSR SIO34
010480   CMP #'A
010490   BEQ SIO30
010500   CMP #'C
010510   BEQ SIO30
010520   CMP #'E
010530   BEQ SIO29
010540   LDA #$8B
010550   JMP SIO26
010560 SIO29 LDA #$90
010570   STA $F0
010580   RTS         ;ADDED
010590 SIO30 LDY #0
010600 SIO31 LDX #0
010610 SIO32 LDA #SIO25&255
010620   STA $0226
010630   LDA #SIO25/256
010640   STA $0227
010650   LDA #1
010660   JMP $E45C
010670 SIO34 LDA #$20
010680   BIT $D20E
010690   BPL SIO50
010700   BNE SIO34
010710   LDA #$DF
010720   STA $D20E
010730   LDA #$F8
010740   STA $D20E
010750   LDA $D20F
010760   STA $D20A
010770   BPL SIO51
010780   AND #$20
010790   BEQ SIO52
010800   LDA $D20D
010810   RTS 
010820 SIO50 LDA #$5F
010830   STA $D20E
010840   LDA #$F8
010850   STA $D20E
010860   LDA #1
010870   STA $F7
010880   DEC $F5
010890   LDA #$80
010900   .BYTE $2C
010910 SIO52 LDA #$8E
010920   .BYTE $2C
010930 SIO51 LDA #$8C
010940   JMP SIO26
010950 SIO35 PHA 
010960 SIO36 LDA $D20E
010970   AND #$10
010980   BNE SIO36
010990   LDA #$EF
011000   STA $D20E
011010   LDA #$F8
011020   STA $D20E
011030   PLA 
011040   STA $D20D
011050   RTS 
011060 SIO37 LDA #$23
011070   .BYTE $2C
011080 SIO38 LDA #$13
011090   STA $D20F
011100   STA $D20A
011110   LDA #$28
011120   STA $D208
011130   LDA $FF
011140   STA $D207
011150   LDA #$F8
011160   STA $D20E
011170   RTS 
011180 SIO39 LDA $0301
011190   ORA #$30
011200   STA $F8
011210   LDA $030A
011220   STA $FA
011230   LDA $030B
011240   STA $FB
011250   LDA $0302
011260   STA $F9
011270   BPL SIO39A
011280   JMP SIO42A
011290 SIO39A LDA $FE
011300   CMP #16
011310   BNE SIO40
011320   LDA $0302
011330   CMP #'R
011340   BEQ SIO42
011350   CMP #'P
011360   BEQ SIO42
011370   CMP #'W
011380   BEQ SIO42
011390   PLA 
011400   PLA 
011410   CLI 
011420   JMP $E459
011430 SIO42 ORA #$20
011440   STA $F9
011450 SIO42A LDA #40 ;NORM SPEED HDR
011460 SIO40 STA $D204
011470   LDA #0
011480   STA $D206
011490   STA $F0
011500   STA $F3
011510   STA $F5
011520   LDA #$F8
011530   STA $F2
011540   LDA #4
011550   STA $F4
011560   RTS 
011570 SIO43 LDA $0304
011580   STA $F2
011590   LDA $0305
011600   STA $F3
011610   LDA $0308
011620   STA $F4
011630   LDA $FE
011640   STA $D204
011650   RTS 
011660 SNGTAB .BYTE $28,1,0,$12,0,0,0,$80,$FF,0,0,0
011670   .BYTE 4,8,$0C,$10,1,5,9,$0D,$11,2,6,$0A,$0E,$12,3,7,$0B,$0F
011680 DBLTAB .BYTE $28,1,0,$12,0,4,1,0,$FF,0,0,0
011690   .BYTE 1,$0A,8,$11,6,$0F,4,$0D,2,$0B,9,$12,7,$10,5,$0E,3,$0C
011700 ENHTAB .BYTE $28,1,0,$1A,0,4,0,$80,$FF,0,0,0
011710   .BYTE 4,8,$0C,$10,$14,$18,1,5,9,$0D,$11,$15
011720   .BYTE $19,2,6,$0A,$0E,$12,$16,$1A,3,7,$0B,$0F,$13,$17
011730 ;
011740 NEWCLR LDA #1
011750   STA 752
011760   LDA #155
011770   JSR OUTCHR
011780   LDA #125
011790   JSR OUTCHR
011800   LDA #0
011810   STA 752
011820   RTS 
011830   .OPT LIST
011840   BRK 
011850   .OPT NO LIST
