
 1000  *      .LIST OFF
 1010  *---------------------------------
 1020  *      DOS 3.2.1 DISASSEMBLY $BEA0-BFFF
 1030  *      BOB SANDER-CEDERLOF      3-26-81
 1040  *---------------------------------
 1050  CURRENT.TRACK       .EQ $478
 1060  *---------------------------------
 1070  PHASE.OFF           .EQ $C080
 1080  PHASE.ON            .EQ $C081
 1090  MOTOR.OFF           .EQ $C088
 1100  MOTOR.ON            .EQ $C089
 1110  ENABLE.DRIVE.1      .EQ $C08A
 1120  ENABLE.DRIVE.2      .EQ $C08B
 1130  Q6L                 .EQ $C08C
 1140  Q6H                 .EQ $C08D
 1150  Q7L                 .EQ $C08E
 1160  Q7H                 .EQ $C08F
 1170  *---------------------------------
 1180  SECTOR     .EQ $2D
 1190  VOLUME     .EQ $2F
 1200  TRACK.CNTR .EQ $41
 1210  DATA.CNTR  .EQ $46
 1220  SYNC.CNT   .EQ $47
 1230  CONST.AA   .EQ $4A
 1240  FILL.CNTR  .EQ $4B
 1250  FMT.SECTOR .EQ $4B
 1260  *---------------------------------
 1270  READ.ADDRESS        .EQ $B965
 1280  SEEK.TRACK.ABSOLUTE .EQ $BA1E
 1290  RWTS.EXIT           .EQ $BE37
 1300  ERROR.HANDLER       .EQ $BE39
 1310  *---------------------------------
 1320  ERR.BAD.DRIVE       .EQ $40
 1330  *---------------------------------
 1340         .OR $BEA0
 1350         .TA $800
 1360  *---------------------------------
 1370  FORMAT LDA #128     SET CURRENT TRACK REAL HIGH
 1380         STA CURRENT.TRACK   SO DRIVE WILL HOME
 1390         LDA #0              TO TRACK 0
 1400         STA TRACK.CNTR  INIT COUNTER FOR INIT ROUTINE
 1410         JSR SEEK.TRACK.ABSOLUTE
 1420  *---------------------------------
 1430         LDA #$AA     SAVE $AA IN PAGE ZERO FOR TIMING
 1440         STA CONST.AA
 1450  *---------------------------------
 1460  *      FILL ENTIRE TRACK WITH SYNC BYTES
 1470  *---------------------------------
 1480         LDY #80      START WITH 80 SYNC-BYTES
 1490  FILL.TRACK.WITH.SYNC
 1500         STY SYNC.CNT  # OF SYNC BYTES BETWEEN SECTORS
 1510         LDA #39      WRITE SYNC'S OVER ENTIRE TRACK
 1520         STA FILL.CNTR
 1530         LDA Q6H,X    GET READY TO WRITE
 1540         LDA Q7L,X
 1550         LDA #$FF     WRITE $FF EVERYWHERE
 1560         STA Q7H,X    ALL SET TO WRITE....
 1570         CMP Q6L,X
 1580         BIT $00      DELAY 3 CYCLES
 1590  .1     DEY
 1600         BEQ .3
 1610         PHA
 1620         PLA          THESE ARE JUST FOR TIMING
 1630         NOP          NEED 27 CYCLES BTWN WRITES
 1640  .2     PHA
 1650         PLA
 1660         NOP
 1670         NOP
 1680         STA Q6H,X    WRITE SYNC BYTE
 1690         CMP Q6L,X
 1700         BCS .1       ...ALWAYS
 1710  .3     DEC FILL.CNTR  TRACK FULL YET?
 1720         BNE .2       NO
 1730  *---------------------------------
 1740  *      WRITE 13-SECTOR HEADERS ON TRACK
 1750  *
 1760  *          EACH SECTOR CONSISTS OF AN ADDRESS BLOCK
 1770  *          AND A DATA BLOCK.
 1780  *          ADDRESS:  D5 AA B5 V1 V2 T1 T2
 1790  *                    S1 S2 C1 C2 DE AA EB
 1800  *          DATA:     FORMATTED TO ALL SYNC BYTES
 1810  *---------------------------------
 1820  FORMAT.TRACK
 1830         LDY SYNC.CNT  # SYNC BYTES BTWN SECTORS
 1840         NOP
 1850         NOP
 1860  .1     BNE .4       ...ALWAYS
 1870  *---------------------------------
 1880  .2     PHA          WRITE SYNC BYTES BEFORE SECTOR
 1890         PLA
 1900         PHA
 1910         PLA
 1920         CMP ($00,X)  DELAY 6 CYCLES
 1930  .4     NOP
 1940  .5     STA Q6H,X    WRITE NEXT SYNC BYTE
 1950         CMP Q6L,X
 1960         DEY
 1970         BNE .2
 1980  *---------------------------------
 1990         LDA #$D5     WRITE D5 AA B5
 2000         JSR WRITE.BYTE.2
 2010         LDA #$AA
 2020         JSR WRITE.BYTE.3
 2030         LDA #$B5
 2040         JSR WRITE.BYTE.3
 2050         LDA VOLUME   WRITE VOLUME, TRACK, AND SECTOR
 2060         JSR WRITE.BYTE.1
 2070         LDA TRACK.CNTR
 2080         JSR WRITE.BYTE.1
 2090         LDA FMT.SECTOR
 2100         JSR WRITE.BYTE.1
 2110         LDA VOLUME   COMPUTE CHECKSUM
 2120         EOR TRACK.CNTR
 2130         EOR FMT.SECTOR
 2140         PHA          WRITE CHECKSUM
 2150         LSR
 2160         ORA CONST.AA   #$AA, FOR TIMING
 2170         STA Q6H,X
 2180         CMP Q6L,X
 2190         PLA
 2200         ORA #$AA
 2210         JSR WRITE.BYTE.2
 2220         LDA #$DE     WRITE DE AA EB
 2230         JSR WRITE.BYTE.3
 2240         LDA #$AA
 2250         JSR WRITE.BYTE.3
 2260         LDA #$EB
 2270         JSR WRITE.BYTE.3
 2280         LDA #$FF     WRITE MORE SYNC BYTES
 2290         JSR WRITE.BYTE.3
 2300         LDY #2       FILL WHOLE DATA BLOCK WITH $FF
 2310         STY DATA.CNTR
 2320         LDY #173
 2330         BNE .7       ...ALWAYS
 2340  .6     DEY          FINISHED?
 2350         BEQ .8       YES, AT LEAST THIS GROUP
 2360         PHA          23 CYCLES PER BYTE
 2370         PLA
 2380         NOP
 2390  .7     PHA
 2400         PLA
 2410         STA Q6H,X
 2420         CMP Q6L,X
 2430         BCS .6       ...ALWAYS
 2440  .8     DEC DATA.CNTR  FINISHED?
 2450         BNE .7       NOT YET, DO SECOND GROUP
 2460  *---------------------------------
 2470         LDY SYNC.CNT
 2480         CLC
 2490         BIT $00      DELAY
 2500         STA Q6H,X
 2510         LDA Q6L,X
 2520         LDA FMT.SECTOR   COMPUTE NEXT SECTOR #
 2530         ADC #10      SKEW FACTOR = 10
 2540         STA FMT.SECTOR
 2550         SBC #12
 2560         BEQ CHECK.TRACK
 2570         BCS .9       STORE VALUE MODULO 13
 2580         .HS 2C       'BIT' OPCODE TO SKIP NEXT TWO BYTES
 2590  .9     STA FMT.SECTOR
 2600         LDA #$FF
 2610         JMP .5       DO NEXT SECTOR
 2620  *---------------------------------
 2630  *      CHECK WHETHER TRACK OVERLAPPED
 2640  *---------------------------------
 2650  CHECK.TRACK
 2660         PHA          TIME DELAY
 2670         PLA
 2680         LDY SYNC.CNT
 2690         LDA Q6H,X    SET UP TO READ
 2700         LDA Q7L,X    SENSE WRITE PROTECT
 2710         BMI .4       DRIVE ERROR
 2720         DEY
 2730  .1     PHA          DELAY LOOP
 2740         PLA
 2750         PHA
 2760         PLA
 2770         PHA
 2780         PLA
 2790         DEY          FINISHED WITH DELAY YET?
 2800         BNE .1       NO
 2810         JSR READ.ADDRESS
 2820         BCS .2       BAD READ
 2830         LDA SECTOR   SHOULD BE SECTOR 0
 2840         BEQ .3       YES!
 2850  .2     LDY SYNC.CNT  DIMINISH SYNC COUNT
 2860         DEY          AND TRY AGAIN
 2870         CPY #16      UNLESS NOT ENOUGH LEFT
 2880         BCC .4       DRIVE ERROR
 2890         JMP FILL.TRACK.WITH.SYNC
 2900  *---------------------------------
 2910  .3     INC TRACK.CNTR  NEXT TRACK
 2920         LDA TRACK.CNTR
 2930         CMP #35      FINISHED?
 2940         BCS .5       YES
 2950         ASL          DOUBLE FOR TRACK SEEK ROUTINE
 2960         JSR SEEK.TRACK.ABSOLUTE
 2970         LDY SYNC.CNT  BUMP SYNC.CNT BEFORE TRYING
 2980         INY           NEXT TRACK
 2990         INY
 3000         STY SYNC.CNT
 3010         JMP FILL.TRACK.WITH.SYNC
 3020  *---------------------------------
 3030  .4     LDA #ERR.BAD.DRIVE
 3040         JMP ERROR.HANDLER
 3050  *---------------------------------
 3060  .5     JMP RWTS.EXIT
 3070  *---------------------------------
 3080  *      SUBROUTINES TO WRITE BYTE ON DISK
 3090  *---------------------------------
 3100  WRITE.BYTE.1
 3110         PHA          ADDRESS BLOCK FORMAT
 3120         LSR
 3130         ORA CONST.AA
 3140         STA Q6H,X
 3150         CMP Q6L,X
 3160         PLA
 3170         CMP ($00,X)  DELAY 6 CYCLES
 3180         ORA #$AA
 3190  WRITE.BYTE.2
 3200         NOP
 3210  WRITE.BYTE.3
 3220         PHA
 3230         PLA
 3240         NOP
 3250         STA Q6H,X
 3260         CMP Q6L,X
 3270         RTS
 3280  *---------------------------------
 3290  *      VARIOUS ODDS AND ENDS
 3300  *---------------------------------
 3310         .HS 0160     LEFT OVER
 3320  PATCH1 JMP $A5DD
 3330  PATCH2 STA $AA63
 3340         STA $AA70
 3350         STA $AA71
 3360         RTS
 3370  PATCH3 JSR $A75B
 3380         STY $AAB7
 3390         RTS
 3400  PATCH4 JSR $AE7E    FROM $B377
 3410         LDX $B39B
 3420         TXS
 3430         JSR $A316
 3440         TSX
 3450         STX $B39B
 3460         LDA #9       "DISK FULL" ERROR
 3470         JMP $B385

