
 1000  *      .LIF
 1010  *---------------------------------
 1020  *      DOS 3.2.1 $B800 - $BCFF
 1030  *---------------------------------
 1040         .OR $B800
 1050         .TA $0800
 1060  *---------------------------------
 1070  BUF.PNTR   .EQ $3E,3F
 1080  CURRENT.TRACK       .EQ $0478
 1090  *---------------------------------
 1100  *      DISK CONTROLLER ADDRESSES
 1110  *---------------------------------
 1120  PHOFF  .EQ $C080    PHASE-OFF
 1130  PHON   .EQ $C081    PHASE-ON
 1140  MTROFF .EQ $C088    MOTOR OFF
 1150  MTRON  .EQ $C089    MOTOR ON
 1160  DRV0EN .EQ $C08A    DRIVE 0 ENABLE
 1170  DRV1EN .EQ $C08B    DRIVE 1 ENABLE
 1180  Q6L    .EQ $C08C    SET Q6 LOW
 1190  Q6H    .EQ $C08D    SET Q6 HIGH
 1200  Q7L    .EQ $C08E    SET Q7 LOW
 1210  Q7H    .EQ $C08F    SET Q7 HIGH
 1220  *
 1230  *      Q6    Q7     USE OF Q6 AND Q7 LINES
 1240  *     ----  ----    ----------------------
 1250  *     LOW   LOW     READ (DISK TO SHIFT REGISTER)
 1260  *     LOW   HIGH    WRITE (SHIFT REGISTER TO DISK)
 1270  *     HIGH  LOW     SENSE WRITE PROTECT
 1280  *     HIGH  HIGH    LOAD SHIFT REGISTER FROM DATA BUS
 1290         .PG
 1300  *---------------------------------
 1310  *      CONVERT 256 BYTES TO 410 5-BIT NYBBLES
 1320  *---------------------------------
 1330  PRE.NYBBLE
 1340         LDX #50      51 BYTES PER SECTION
 1350         LDY #0       INDEX INTO 256-BYTE BUFFER
 1360  *---BUFFER PART 1, SECTION 1-----
 1370  .1     LDA (BUF.PNTR),Y  GET BYTE FROM BUFFER
 1380         STA $26      SAVE HERE FOR LOWER 3 BITS
 1390         LSR          USE TOP 5 BITS
 1400         LSR
 1410         LSR
 1420         STA RWTS.BUFFER.1.1,X
 1430  *---BUFFER PART 1, SECTION 2-----
 1440         INY          NEXT REAL BYTE
 1450         LDA (BUF.PNTR),Y  GET BYTE FROM BUFFER
 1460         STA $27      SAVE HERE FOR LOWER 3 BITS
 1470         LSR          USE TOP 5 BITS
 1480         LSR
 1490         LSR
 1500         STA RWTS.BUFFER.1.2,X
 1510  *---BUFFER PART 1, SECTION 3-----
 1520         INY          NEXT REAL BYTE
 1530         LDA (BUF.PNTR),Y  GET BYTE FROM BUFFER
 1540         STA $2A      SAVE FOR LOWER 3 BITS
 1550         LSR
 1560         LSR          USE TOP 5 BITS
 1570         LSR
 1580         STA RWTS.BUFFER.1.3,X
 1590  *---BUFFER PART 1, SECTION 4-----
 1600         INY          NEXT REAL BYTE
 1610         LDA (BUF.PNTR),Y  GET BYTE FROM BUFFER
 1620         LSR          USE TOP 5 BITS
 1630         ROL $2A      BIT 0 INTO $2A
 1640         LSR
 1650         ROL $27      BIT 1 INTO $27
 1660         LSR
 1670         ROL $26      BIT 2 INTO $26
 1680         STA RWTS.BUFFER.1.4,X
 1690  *---BUFFER PART 1, SECTION 5-----
 1700         INY          NEXT REAL BYTE
 1710         LDA (BUF.PNTR),Y  GET BYTE FROM BUFFER
 1720         LSR          USE TOP 5 BITS
 1730         ROL $2A      BIT 0 INTO $2A
 1740         LSR
 1750         ROL $27      BIT 1 INTO $27
 1760         LSR          HOLD BIT 2 IN CARRY-BIT
 1770         STA RWTS.BUFFER.1.5,X
 1780  *---BUFFER PART 2, SECTION 0-----
 1790         LDA $26      APPEND BIT 2 TO $26
 1800         ROL
 1810         AND #$1F     5-BIT MASK
 1820         STA RWTS.BUFFER.2.1,X
 1830  *---BUFFER PART 2, SECTION 1-----
 1840         LDA $27
 1850         AND #$1F
 1860         STA RWTS.BUFFER.2.2,X
 1870  *---BUFFER PART 2, SECTION 2-----
 1880         LDA $2A
 1890         AND #$1F
 1900         STA RWTS.BUFFER.2.3,X
 1910  *---------------------------------
 1920         INY          NEXT REAL BYTE
 1930         DEX          NEXT BYTE IN EACH SECTION
 1940         BPL .1       LOOP UNTIL EACH SECTION FULL
 1950  *---------------------------------
 1960         LDA (BUF.PNTR),Y  GET LAST REAL BYTE
 1970         TAX
 1980         AND #7       USE LOWER 3 BITS
 1990         STA RWTS.BUFFER.2.4
 2000         TXA          NOW GET 5 UPPER BITS
 2010         LSR
 2020         LSR
 2030         LSR
 2040         STA RWTS.BUFFER.1.6
 2050         RTS
 2060   .PG
 2070  *---------------------------------
 2080  *      WRITE A SECTOR ON THE DISK FROM RWTS.BUFFER
 2090  *---------------------------------
 2100  WRITE.SECTOR
 2110         SEC          SET IN CASE OF ERROR RETURN
 2120         LDA Q6H,X    Q6 HIGH, Q7 LOW,
 2130         LDA Q7L,X    TO READ WRITE PROTECT STATUS
 2140         BMI .5       DISK IS WRITE PROTECTED
 2150         STX $27      SAVE SLOT #
 2160         STX $0678    HERE, TOO
 2170         LDA RWTS.BUFFER.2.1  FIRST NYBBLE OF DATA
 2180         STA $26      SAVE IT
 2190         LDA #$FF     SYNC BYTE
 2200         STA Q7H,X    Q6H,Q7H: (A) TO SHIFT REGISTER
 2210         ORA Q6L,X    Q6L,Q7H: WRITE ON DISK
 2220         PHA          TIME DELAYS
 2230         PLA
 2240         NOP
 2250         LDY #10      WRITE TEN MORE SYNC BYTES
 2260  .1     ORA $26      WASTE TIME
 2270         JSR WRT2     WRITE (A) ON DISK
 2280         DEY
 2290         BNE .1       UNTIL 10 OF THEM
 2300         LDA #$D5     WRITE DATA HEADER
 2310         JSR WRT1
 2320         LDA #$AA
 2330         JSR WRT1
 2340         LDA #$AD
 2350         JSR WRT1
 2360         TYA          A=0
 2370         LDY #154     WRITE 154 NYBBLES
 2380         BNE .3       ...ALWAYS
 2390  .2     LDA RWTS.BUFFER.2.1,Y  GET CURRENT NYBBLE AND
 2400  .3     EOR RWTS.BUFFER.2.1-1,Y  EOR WITH PREVIOUS NYBBLE
 2410         TAX          USE AS OFFSET INTO TABLE
 2420         LDA NYBBLE.TABLE,X  MAP 5-BITS TO 8-BITS
 2430         LDX $27      GET SLOT AGAIN
 2440         STA Q6H,X    Q6H,Q7H: (A) TO SHIFT REGISTER
 2450         LDA Q6L,X    Q6L,Q7H: WRITE ON DISK
 2460         DEY
 2470         BNE .2       UNTIL ALL BYTES FROM THIS BLOCK DONE
 2480         LDA $26      GET FIRST NYBBLE
 2490         NOP
 2500  .4     EOR RWTS.BUFFER.1.1,Y  EOR WITH CURRENT NYBBLE
 2510         TAX          INDEX INTO TABLE
 2520         LDA NYBBLE.TABLE,X  MAP TO 8-BIT VALUE
 2530         LDX $0678    SLOT # AGAIN
 2540         STA Q6H,X    Q6H,Q7L: (A) TO SHIFT REGISTER
 2550         LDA Q6L,X    Q6L,Q7H: WRITE ON DISK
 2560         LDA RWTS.BUFFER.1.1,Y  GET NYBBLE
 2570         INY
 2580         BNE .4       MORE TO DO
 2590         TAX          LAST NYBBLE
 2600         LDA NYBBLE.TABLE,X  MAP TO 8 BITS
 2610         LDX $27      SLOT # AGAIN
 2620         JSR WRT3     WRITE CHECK SUM ON DISK
 2630         LDA #$DE     WRITE TRAILER
 2640         JSR WRT1
 2650         LDA #$AA
 2660         JSR WRT1
 2670         LDA #$EB
 2680         JSR WRT1
 2690         LDA Q7L,X    Q7L
 2700  .5     LDA Q6L,X    Q6L
 2710         RTS
 2720  *---------------------------------
 2730  WRT1   CLC          WAIT 2 CYCLES
 2740  WRT2   PHA          WAIT 3 CYCLES
 2750         PLA          WAIT 4 CYCLES
 2760  WRT3   STA Q6H,X    Q6H,Q7H: (A) TO SHIFT REGISTER
 2770         ORA Q6L,X    Q6L,Q7H: WRITE ON DISK
 2780         RTS
 2790   .PG
 2800  *---------------------------------
 2810  *      READ SECTOR INTO RWTS.BUFFER
 2820  *---------------------------------
 2830  READ.SECTOR
 2840         LDY #32      MUST FIND $D5 WITHIN 32 BYTES
 2850  .1     DEY
 2860         BEQ ERROR.RETURN
 2870  .2     LDA Q6L,X    READ SHIFT REGISTER
 2880         BPL .2       WAIT FOR FULL BYTE
 2890  .3     EOR #$D5     SEE IF FOUND $D5
 2900         BNE .1       NOT YET
 2910         NOP          DELAY BEFORE NEXT READ
 2920  .4     LDA Q6L,X    READ SHIFT REGISTER
 2930         BPL .4       WAIT FOR FULL BYTE
 2940         CMP #$AA     SEE IF $AA
 2950         BNE .3       NO
 2960         LDY #154     BYTE COUNT FOR LATER
 2970  .5     LDA Q6L,X    READ SHIFT REGISTER
 2980         BPL .5       WAIT FOR FULL BYTE
 2990         CMP #$AD     IS IT $AD?
 3000         BNE .3       NO
 3010  *---------------------------------
 3020         LDA #0       BEGIN CHECKSUM
 3030  .6     DEY
 3040         STY $26
 3050  .7     LDY Q6L,X    READ SHIFT REGISTER
 3060         BPL .7       WAIT FOR FULL BYTE
 3070         EOR BYTE.TABLE,Y  CONVERT TO NYBBLE
 3080         LDY $26      BUFFER INDEX
 3090         STA RWTS.BUFFER.2.1,Y
 3100         BNE .6
 3110  .8     STY $26
 3120  .9     LDY Q6L,X    READ SHIFT REGISTER
 3130         BPL .9       WAIT FOR FULL BYTE
 3140         EOR BYTE.TABLE,Y  CONVERT TO NYBBLE
 3150         LDY $26
 3160         STA RWTS.BUFFER.1.1,Y
 3170         INY
 3180         BNE .8
 3190  .10    LDY Q6L,X    READ CHECKSUM
 3200         BPL .10
 3210         CMP BYTE.TABLE,Y
 3220         BNE ERROR.RETURN
 3230  .11    LDA Q6L,X    READ TRAILER
 3240         BPL .11
 3250         CMP #$DE
 3260         BNE ERROR.RETURN
 3270         NOP
 3280  .12    LDA Q6L,X
 3290         BPL .12
 3300         CMP #$AA
 3310         BEQ GOOD.RETURN
 3320  ERROR.RETURN
 3330         SEC
 3340         RTS
 3350   .PG
 3360  *---------------------------------
 3370  *      READ ADDRESS
 3380  *---------------------------------
 3390  READ.ADDRESS
 3400         LDY #$F8     TRY 1800 TIMES (FROM $F8F8 TO $10000)
 3410         STY $26
 3420  .1     INY
 3430         BNE .2
 3440         INC $26
 3450         BEQ ERROR.RETURN
 3460  .2     LDA Q6L,X    READ SHIFT REGISTER
 3470         BPL .2       WAIT FOR FULL BYTE
 3480  .3     CMP #$D5     SEE IF $D5
 3490         BNE .1       NO
 3500         NOP          DELAY
 3510  .4     LDA Q6L,X    READ SHIFT REGISTER
 3520         BPL .4       WAIT FOR FULL BYTE
 3530         CMP #$AA     SEE IF $AA
 3540         BNE .3       NO
 3550         LDY #3       READ 3 BYTES LATER
 3560  .5     LDA Q6L,X    READ SHIFT REGISTER
 3570         BPL .5
 3580         CMP #$B5     SEE IF $B5
 3590         BNE .3       NO
 3600         LDA #0       START CHECK SUM
 3610  .6     STA $27
 3620  .7     LDA Q6L,X    READ REGISTER
 3630         BPL .7
 3640         ROL
 3650         STA $26
 3660  .8     LDA Q6L,X    READ REGISTER
 3670         BPL .8       WAIT FOR FULL BYTE
 3680         AND $26      MERGE THE NYBBLES
 3690         STA $2C,Y    $2C -- CHECK SUM
 3700         EOR $27      $2D -- SECTOR
 3710         DEY          $2E -- TRACK
 3720         BPL .6       $2F -- VOLUME
 3730         TAY          TEST CHECK SUM
 3740         BNE ERROR.RETURN
 3750  .9     LDA Q6L,X    READ REGISTER
 3760         BPL .9       WAIT FOR FULL BYTE
 3770         CMP #$DE     TEST FOR VALID TRAILER
 3780         BNE ERROR.RETURN
 3790         NOP
 3800  .10    LDA Q6L,X    READ REGISTER
 3810         BPL .10
 3820         CMP #$AA
 3830         BNE ERROR.RETURN
 3840  GOOD.RETURN
 3850         CLC
 3860         RTS
 3870         .PG
 3880  *---------------------------------
 3890  *      CONVERT 410 5-BIT NYBBLES TO 256 BYTES
 3900  *      (THEY ARE NOW LEFT-JUSTIFIED IN RWTS.BUFFER)
 3910  *---------------------------------
 3920  POST.NYBBLE
 3930         LDX #50      51 BYTES PER SECTION
 3940         LDY #0
 3950  *---BUFFER PART 1, SECTION 1-----
 3960  .1     LDA RWTS.BUFFER.2.1,X
 3970         LSR
 3980         LSR          RIGHT-JUSTIFY THE NYBBLE
 3990         LSR
 4000         STA $27      SAVE BIT 0
 4010         LSR
 4020         STA $26      SAVE BIT 1
 4030         LSR          BITS 2-4
 4040         ORA RWTS.BUFFER.1.1,X
 4050         STA (BUF.PNTR),Y  STORE IN BUFFER
 4060  *---BUFFER PART 1, SECTION 2-----
 4070         INY          NEXT BYTE
 4080         LDA RWTS.BUFFER.2.2,X
 4090         LSR          RIGHT-JUSTIFY THE NYBBLE
 4100         LSR
 4110         LSR
 4120         LSR          BIT 0 INTO CARRY
 4130         ROL $27      AND SAVE HERE
 4140         LSR          BIT 1 INTO CARRY
 4150         ROL $26      AND SAVE HERE
 4160         ORA RWTS.BUFFER.1.2,X
 4170         STA (BUF.PNTR),Y  STORE THE BYTE
 4180  *---BUFFER PART 1, SECTION 3-----
 4190         INY          NEXT BYTE
 4200         LDA RWTS.BUFFER.2.3,X
 4210         LSR          RIGHT-JUSTIFY THE NYBBLE
 4220         LSR
 4230         LSR
 4240         LSR          BIT 0 INTO CARRY
 4250         ROL $27      AND SAVE HERE
 4260         LSR          BIT 1 INTO CARRY
 4270         ROL $26      AND SAVE HERE
 4280         ORA RWTS.BUFFER.1.3,X
 4290         STA (BUF.PNTR),Y  STORE THE BYTE
 4300  *---BUFFER PART1, SECTION 4-----
 4310         INY          NEXT BYTE
 4320         LDA $26      USE THE 3 BITS SAVED HERE
 4330         AND #7       MAKE SURE ONLY 3 BITS
 4340         ORA RWTS.BUFFER.1.4,X
 4350         STA (BUF.PNTR),Y  STORE THE BYTE
 4360  *---BUFFER PART1, SECTION 5-----
 4370         INY          NEXT BYTE
 4380         LDA $27      USE THE 3 BITS SAVED HERE
 4390         AND #7       MAKE SURE ONLY 3 BITS
 4400         ORA RWTS.BUFFER.1.5,X
 4410         STA (BUF.PNTR),Y  STORE THE BYTE
 4420  *---------------------------------
 4430         INY          NEXT BYTE
 4440         DEX
 4450         BPL .1
 4460  *---------------------------------
 4470         LDA RWTS.BUFFER.2.4  GET THE LAST BYTE
 4480         LSR          RIGHT JUSTIFY
 4490         LSR
 4500         LSR
 4510         ORA RWTS.BUFFER.1.6
 4520         STA (BUF.PNTR),Y  STORE THE LAST BYTE
 4530         RTS
 4540   .PG
 4550  *---------------------------------
 4560  *      TRACK SEEK
 4570  *---------------------------------
 4580  SEEK.TRACK.ABSOLUTE
 4590         STX $2B      CURRENT SLOT*16
 4600         STA $2A      SAVE TRACK #
 4610         CMP CURRENT.TRACK  COMPARE TO CURRENT TRACK
 4620         BEQ .9       ALREADY THERE
 4630         LDA #0
 4640         STA $26      # OF STEPS SO FAR
 4650  .1     LDA CURRENT.TRACK  CURRENT TRACK NUMBER
 4660         STA $27
 4670         SEC
 4680         SBC $2A      DESIRED TRACK
 4690         BEQ .6       WE HAVE ARRIVED
 4700         BCS .2       CURRENT > DESIRED
 4710         EOR #$FF     CURRENT < DESIRED
 4720         INC CURRENT.TRACK  INCREMENT CURRENT
 4730         BCC .3       ...ALWAYS
 4740  .2     ADC #$FE     CARRY SET, SO A=A-1
 4750         DEC CURRENT.TRACK  DECREMENT CURRENT TRACK
 4760  .3     CMP $26      GET MINIMUM OF:
 4770         BCC .4          1. # OF TRACKS TO MOVE LESS 1
 4780         LDA $26         2. # OF ITERATIONS SO FAR
 4790  .4     CMP #12         3. ELEVEN
 4800         BCS .5
 4810         TAY
 4820  .5     SEC          TURN PHASE ON
 4830         JSR .7
 4840         LDA ONTBL,Y  GET DELAY TIME
 4850         JSR DLY100   DELAY 100*A MICROSECONDS
 4860         LDA $27      TRACK NUMBER
 4870         CLC          TURN PHASE OFF
 4880         JSR .8
 4890         LDA OFFTBL,Y
 4900         JSR DLY100
 4910         INC $26      # OF STEPS SO FAR
 4920         BNE .1       ...ALWAYS
 4930  *---------------------------------
 4940  .6     JSR DLY100
 4950         CLC          TURN PHASE OFF
 4960  .7     LDA CURRENT.TRACK
 4970  .8     AND #3       ONLY KEEP LOW-ORDER 2 BITS
 4980         ROL          (0000 0XX0)
 4990         ORA $2B      (0SSS 0XX0) MERGE SLOT
 5000         TAX          USE AS INDEX FOR PHASE-OFF
 5010         LDA PHOFF,X  PHASE-OFF
 5020         LDX $2B
 5030  .9     RTS
 5040  *---------------------------------
 5050  *      SHORT DELAY SUBROUTINE
 5060  *---------------------------------
 5070  DLY100 LDX #17      100*A MICROSECONDS
 5080  .1     DEX
 5090         BNE .1
 5100         INC $46
 5110         BNE .2
 5120         INC $47
 5130  .2     SEC
 5140         SBC #1
 5150         BNE DLY100
 5160         RTS
 5170  *---------------------------------
 5180  *      DELAY TIMES FOR STEPPING MOTOR
 5190  *---------------------------------
 5200  ONTBL  .HS 01302824201E1D1C1C1C1C1C
 5210  OFFTBL .HS 702C26221F1E1D1C1C1C1C1C
 5220         .HS 1C1C1C1C
 5230         .PG
 5240  *---------------------------------
 5250  *      BYTE TABLE
 5260  *---------------------------------
 5270  BYTE.TABLE .EQ *-$A8
 5280         .HS 00000000010810180203040506202830
 5290         .HS 070938400A4850580B0C0D0E0F111213
 5300         .HS 14151617191A1B1C1D1E212223246068
 5310         .HS 2526707827808890292A2B2C2D2E2F31
 5320         .HS 323398A034A8B0B8353637393AC0C8D0
 5330         .HS 3B3CD8E03EE8F0F8
 5340  *---------------------------------
 5350  *      410-BYTE BUFFER FOR NYBBLES
 5360  *---------------------------------
 5370  RWTS.BUFFER.1.1 .BS 51  $BB00 - BB32
 5380  RWTS.BUFFER.1.2 .BS 51  $BB33 - BB65
 5390  RWTS.BUFFER.1.3 .BS 51  $BB66 - BB98
 5400  RWTS.BUFFER.1.4 .BS 51  $BB99 - BBCB
 5410  RWTS.BUFFER.1.5 .BS 51  $BBCC - BBFE
 5420  RWTS.BUFFER.1.6 .BS 1   $BBFF
 5430  RWTS.BUFFER.2.1 .BS 51  $BC00 - BC32
 5440  RWTS.BUFFER.2.2 .BS 51  $BC33 - BC65
 5450  RWTS.BUFFER.2.3 .BS 51  $BC66 -BC98
 5460  RWTS.BUFFER.2.4 .BS 1   $BC99
 5470  *---------------------------------
 5480  *      NYBBLE TABLE
 5490  *---------------------------------
 5500  NYBBLE.TABLE
 5510         .HS ABADAEAFB5B6B7BABBBDBEBF
 5520         .HS D6D7DADBDDDEDFEAEBEDEEEF
 5530         .HS F5F6F7FAFBFDFEFF
 5540  *---------------------------------
 5550  *      $BCBA THRU $BCFF IS NOT USED BY DOS 3.2.1
 5560  *---------------------------------
 5570         .PG

