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

