
 1000  *SAVE S.UNIDISK RWTS
 1010  *--------------------------------
 1020  UNIDISK.SLOT        .EQ 5
 1030   
 1040  MY.COMMAND          .EQ $26
 1050  MY.BUFFER.POINTER   .EQ $3C
 1060  IOB.BUFFER.POINTER  .EQ $3E
 1070  IOB.PTR             .EQ $48
 1080   
 1090  MY.BUFFER           .EQ $BB00
 1100   
 1110  PATCH.POINT         .EQ $BD12
 1120  PATCH.RETURN        .EQ $BD15
 1130   
 1140  PC.DISPATCH         .EQ UNIDISK.SLOT*$100+$C000
 1150   
 1160  PRBYTE              .EQ $FDDA
 1170  COUT                .EQ $FDED
 1180  *--------------------------------
 1190         .OR $803
 1200         .TF RWTS 3.5
 1210   
 1220  INSTALL
 1230         LDX #6            make sure we have a
 1240  .1     LDA ID.TABLE,X    protocol converter
 1250         CMP UNIDISK.SLOT*$100+$C001,X
 1260         BNE NO.PC
 1270         DEX
 1280         DEX
 1290         BPL .1
 1300   
 1310         LDA #$4C          patch in the JMP
 1320         STA PATCH.POINT   to our code
 1330         LDA #MY.RWTS
 1340         STA PATCH.POINT+1
 1350         LDA /MY.RWTS
 1360         STA PATCH.POINT+2
 1370         LDA #$60
 1380         STA $A54F         disable INIT
 1390   
 1400  MOVE   LDY #IMAGE.SIZE+1 install our code
 1410  .1     LDA IMAGE-1,Y
 1420         STA MY.RWTS-1,Y
 1430         DEY
 1440         BNE .1
 1450   
 1460         CLC
 1470         LDA UNIDISK.SLOT*$100+$C0FF
 1480         ADC #3            find protocol
 1490         STA READ.CALL     converter entry
 1500         STA WRITE.CALL
 1510         BNE DONE          ...always
 1520   
 1530  NO.PC  LDX #0
 1540  .1     LDA MESSAGES,X    print an error message
 1550         BEQ DONE
 1560         JSR COUT
 1570         INX
 1580         BNE .1
 1590  DONE   JMP $3D0
 1600  *--------------------------------
 1610  MESSAGES
 1620         .HS 8D
 1630         .AS -/No PC in slot /
 1640         .DA #$B0+UNIDISK.SLOT
 1650         .HS 878D00
 1660  *--------------------------------
 1670  ID.TABLE .HS 20.FF.00.FF.03.FF.00
 1680  *            ^     ^     ^     ^
 1690  *        Protocol Converter ID Bytes
 1700  *--------------------------------
 1710  IMAGE  .EQ *
 1720         .PH $BEAF
 1730  MY.RWTS
 1740         CMP #UNIDISK.SLOT*$10
 1750         BEQ MINE          my call!
 1760         TAX               not mine, so do
 1770         LDY #$F           patched-over code
 1780         JMP PATCH.RETURN  and go back
 1790  *--------------------------------
 1800  MINE
 1810         LDY #$F
 1820         CMP (IOB.PTR),Y   check previous slot
 1830         BEQ SET.BLOCK     same, so go on
 1840         STA (IOB.PTR),Y   set previous slot
 1850         LDA #$FF
 1860         STA LAST.BLOCK    trash LAST.BLOCK
 1870   
 1880  SET.BLOCK
 1890         LDA #0
 1900         STA BLOCK+1
 1910         LDY #4
 1920         LDA (IOB.PTR),Y   get track
 1930  .1     ASL
 1940         ROL BLOCK+1       *16
 1950         DEY
 1960         BNE .1
 1970         STA BLOCK
 1980         LDY #5
 1990         LDA (IOB.PTR),Y   get sector
 2000         LSR               /2, odd/even into carry
 2010         ORA BLOCK
 2020         STA BLOCK
 2030   
 2040  SET.POINTERS
 2050         LDA #MY.BUFFER
 2060         STA MY.BUFFER.POINTER
 2070         LDA /MY.BUFFER
 2080         ADC #0       carry sets hi/lo half of buffer
 2090         STA MY.BUFFER.POINTER+1
 2100         LDY #8
 2110         LDA (IOB.PTR),Y   get IOB buffer
 2120         STA IOB.BUFFER.POINTER
 2130         INY
 2140         LDA (IOB.PTR),Y
 2150         STA IOB.BUFFER.POINTER+1
 2160   
 2170  SET.DRIVE
 2180         LDY #2
 2190         LDA (IOB.PTR),Y   get drive
 2200         LDY #$10
 2210         STA (IOB.PTR),Y   set previous drive
 2220         DEY
 2230         DEY
 2240         STA (IOB.PTR),Y   set previous volume
 2250         LSR
 2260         BCS SET.COMMAND   .CS. if D1
 2270         LDA BLOCK         add 800 to BLOCK if D2
 2280         ADC #800
 2290         STA BLOCK
 2300         LDA BLOCK+1
 2310         ADC /800
 2320         STA BLOCK+1
 2330   
 2340  SET.COMMAND
 2350         LDY #$C
 2360         LDA (IOB.PTR),Y   get command
 2370         BEQ GOOD.EXIT
 2380         CMP #3            exit if not READ or WRITE
 2390         BCS GOOD.EXIT
 2400         STA MY.COMMAND    save command
 2410   
 2420  CHECK.FOR.RE.READ
 2430         LDX #0            zero the flag
 2440         LDY #1            check two bytes
 2450  .1     LDA BLOCK,Y
 2460         CMP LAST.BLOCK,Y  compare
 2470         BEQ .2            same, so go on
 2480         INX               different, so flag it
 2490         STA LAST.BLOCK,Y  and store new value
 2500  .2     DEY
 2510         BPL .1            now do low bytes
 2520         TXA               check the flag
 2530         BNE READ          if different, go read
 2540   
 2550  CHECK.FOR.VTOC
 2560         LDY #5
 2570         LDA (IOB.PTR),Y   get sector
 2580         BNE SKIP.READ     non-zero isn't VTOC
 2590         DEY
 2600         LDA (IOB.PTR),Y   get track
 2610         CMP #$11
 2620         BNE SKIP.READ     not $11 isn't VTOC
 2630   
 2640  READ   JSR PC.DISPATCH
 2650  READ.CALL .EQ *-2
 2660         .DA #1            READ
 2670         .DA PARMLIST
 2680         BCS ERROR.EXIT
 2690   
 2700  SKIP.READ
 2710         LDA MY.COMMAND    check command
 2720         CMP #2
 2730         BEQ WRITE.MOVE.BUFFER
 2740   
 2750  READ.MOVE.BUFFER
 2760         LDY #0
 2770  .1     LDA (MY.BUFFER.POINTER),Y
 2780         STA (IOB.BUFFER.POINTER),Y
 2790         INY
 2800         BNE .1
 2810         BEQ GOOD.EXIT     ...always
 2820   
 2830  WRITE.MOVE.BUFFER
 2840         LDY #0
 2850  .1     LDA (IOB.BUFFER.POINTER),Y
 2860         STA (MY.BUFFER.POINTER),Y 
 2870         INY
 2880         BNE .1
 2890   
 2900  WRITE  JSR PC.DISPATCH
 2910  WRITE.CALL .EQ *-2
 2920         .DA #2            WRITE
 2930         .DA PARMLIST
 2940         BCS ERROR.EXIT
 2950   
 2960  GOOD.EXIT
 2970         CLC
 2980         LDA #0
 2990         BEQ EXIT          ...always
 3000   
 3010  ERROR.EXIT
 3020         CMP #$2B     write protect?
 3030         BEQ .1
 3040         LDA #$40     make everything else DRIVE ERROR
 3050         .HS 2C
 3060  .1     LDA #$10
 3070         SEC
 3080   
 3090  EXIT   LDY #$D
 3100         STA (IOB.PTR),Y   save return code
 3110         RTS
 3120  *--------------------------------
 3130  PARMLIST
 3140         .DA #3        3 parameters
 3150         .DA #1        unit number
 3160         .DA MY.BUFFER buffer address 
 3170  BLOCK  .BS 3         block number
 3180   
 3190  LAST.BLOCK .HS FFFF
 3200  *--------------------------------
 3210         .BS $BF97-*
 3220         .EP
 3230  IMAGE.END .EQ *-1
 3240  IMAGE.SIZE .EQ IMAGE.END-IMAGE
 3250         .LIF

