
 1000  *---------------------------------
 1010  *      DOS 3.3 DISASSEMBLY   $BD00-BEAE
 1020  *      BOB SANDER-CEDERLOF       3-3-81
 1030  *---------------------------------
 1040  CURRENT.TRACK       .EQ $478
 1050  DRIVE.1.TRACK       .EQ $478 THRU 47F (INDEX BY SLOT)
 1060  DRIVE.2.TRACK       .EQ $4F8 THRU 4FF (INDEX BY SLOT)
 1070  SEARCH.COUNT        .EQ $4F8
 1080  RETRY.COUNT         .EQ $578
 1090  SLOT                .EQ $5F8
 1100  SEEK.COUNT          .EQ $6F8
 1110  *---------------------------------
 1120  PHASE.OFF           .EQ $C080
 1130  PHASE.ON            .EQ $C081
 1140  MOTOR.OFF           .EQ $C088
 1150  MOTOR.ON            .EQ $C089
 1160  ENABLE.DRIVE.1      .EQ $C08A
 1170  ENABLE.DRIVE.2      .EQ $C08B
 1180  Q6L                 .EQ $C08C
 1190  Q6H                 .EQ $C08D
 1200  Q7L                 .EQ $C08E
 1210  Q7H                 .EQ $C08F
 1220  *---------------------------------
 1230  SECTOR     .EQ $2D
 1240  TRACK      .EQ $2A
 1250  VOLUME     .EQ $2F
 1260  DRIVE.NO   .EQ $35
 1270  DCT.PNTR   .EQ $3C,3D
 1280  BUF.PNTR   .EQ $3E,3F
 1290  MOTOR.TIME .EQ $46,47
 1300  IOB.PNTR   .EQ $48,49
 1310  *---------------------------------
 1320  PRE.NYBBLE          .EQ $B800
 1330  WRITE.SECTOR        .EQ $B82A
 1340  READ.SECTOR         .EQ $B8DC
 1350  READ.ADDRESS        .EQ $B944
 1360  POST.NYBBLE         .EQ $B8C2
 1370  SEEK.TRACK.ABSOLUTE .EQ $B9A0
 1380  DELAY.LOOP          .EQ $BA00
 1390  *---------------------------------
 1400  ERR.WRITE.PROTECT   .EQ $10
 1410  ERR.WRONG.VOLUME    .EQ $20
 1420  ERR.BAD.DRIVE       .EQ $40
 1430  *---------------------------------
 1440         .OR $BD00
 1450         .TA $800
 1460  *---------------------------------
 1470  RWTS   STY IOB.PNTR SAVE ADDRESS OF IOB
 1480         STA IOB.PNTR+1
 1490         LDY #2
 1500         STY SEEK.COUNT  UP TO 2 RE-CALIBRATIONS
 1510         LDY #4
 1520         STY SEARCH.COUNT
 1530         LDY #1       POINT AT SLOT# IN IOB
 1540         LDA (IOB.PNTR),Y  SLOT# FOR THIS OPERATION
 1550         TAX
 1560         LDY #15      POINT AT PREVIOUS SLOT#
 1570         CMP (IOB.PNTR),Y  SAME SLOT?
 1580         BEQ .3       YES
 1590         TXA          SAVE NEW SLOT ON STACK
 1600         PHA
 1610         LDA (IOB.PNTR),Y  GET OLD SLOT#
 1620         TAX
 1630         PLA          STORE NEW SLOT #
 1640         PHA          INTO OLD SLOT# SPOT
 1650         STA (IOB.PNTR),Y
 1660  *---------------------------------
 1670  *      SEE IF OLD MOTOR STILL SPINNING
 1680  *---------------------------------
 1690         LDA Q7L,X    GO INTO READ MODE
 1700  .1     LDY #8       IF DATA DOES NOT CHANGE
 1710         LDA Q6L,X       FOR 96 MICROSECONDS,
 1720  .2     CMP Q6L,X       THEN THE DRIVE IS STOPPED
 1730         BNE .1       WOOPS! IT CHANGED!
 1740         DEY          TIME UP YET?
 1750         BNE .2       NO, KEEP CHECKING
 1760         PLA          GET NEW SLOT # AGAIN
 1770         TAX
 1780  *---------------------------------
 1790  .3     LDA Q7L,X    SET UP TO READ
 1800         LDA Q6L,X
 1810         LDY #8
 1820  .31    LDA Q6L,X    GET CURRENT DATA
 1830         PHA          7 CYCLE DELAY
 1840         PLA
 1850         PHA          7 CYCLE DELAY
 1860         PLA
 1870         STX SLOT
 1880         CMP Q6L,X    SEE IF DATA CHANGED
 1890         BNE .32      YES, IT CHANGED
 1900         DEY
 1910         BNE .31      KEEP WAITING
 1920  .32    PHP          SAVE ANSWER ON STACK
 1930         LDA MOTOR.ON,X   TURN ON MOTOR
 1940         LDY #6       COPY POINTERS INTO PAGE ZERO
 1950  .4     LDA (IOB.PNTR),Y
 1960         STA DCT.PNTR-6,Y
 1970         INY          DCT.PNTR .EQ $3C,3D
 1980         CPY #10      BUF.PNTR .EQ $3E,3F
 1990         BNE .4
 2000         LDY #3       GET MOTOR ON TIME FROM DCT
 2010         LDA (DCT.PNTR),Y
 2020         STA MOTOR.TIME+1  HIGH BYTE ONLY
 2030         LDY #2       GET DRIVE #
 2040         LDA (IOB.PNTR),Y
 2050         LDY #16      SEE IF SAME AS OLD DRIVE#
 2060         CMP (IOB.PNTR),Y
 2070         BEQ .5       YES
 2080         STA (IOB.PNTR),Y  UPDATE OLD DRIVE #
 2090         PLP          SET Z STATUS
 2100         LDY #0       TO FLAG MOTOR OFF
 2110         PHP
 2120  .5     ROR          CHECK LSB OF DRIVE #
 2130         BCC .6       DRIVE 2
 2140         LDA ENABLE.DRIVE.1,X
 2150         BCS .7       ...ALWAYS
 2160  .6     LDA ENABLE.DRIVE.2,X
 2170  .7     ROR DRIVE.NO SET SIGN BIT IF DRIVE 1
 2180         PLP          WAS MOTOR PROBABLY OFF?
 2190         PHP
 2200         BNE .9       NO, DEFINITELY ON
 2210  *---------------------------------
 2220  *      DELAY FROM 150 TO 180 MILLISECONDS,
 2230  *      DEPENDING ON WHAT GARBAGE IS IN A-REG
 2240  *---------------------------------
 2250         LDY #7       YES, WAIT A WHILE
 2260  .8     JSR DELAY.LOOP
 2270         DEY          BUT IT WORKS ANYWAY....
 2280         BNE .8
 2290         LDX SLOT     RESTORE SLOT#
 2300  *---------------------------------
 2310  .9     LDY #4       GET TRACK #
 2320         LDA (IOB.PNTR),Y
 2330         JSR SEEK.TRACK
 2340         PLP          WAS MOTOR DEFINITELY ON?
 2350         BNE PROCESS.COMMAND  YES, MOTOR ON
 2360         LDY MOTOR.TIME+1   SEE IF NEED TO WAIT
 2370         BPL PROCESS.COMMAND   NO
 2380  *---------------------------------
 2390  *      MOTOR WAS OFF, SO WAIT REST OF MOTOR ON TIME
 2400  *      FOR APPLE DISK II, MOTOR ON TIME IS 1 SECOND.
 2410  *      PART OF THIS TIME IS COUNTED DOWN WHILE SEEKING
 2420  *      FOR THE TRACK.
 2430  *---------------------------------
 2440  .10    LDY #18      ABOUT 100 MICROSECONDS PER TRIP
 2450  .11    DEY
 2460         BNE .11
 2470         INC MOTOR.TIME
 2480         BNE .10
 2490         INC MOTOR.TIME+1
 2500         BNE .10
 2510  *---------------------------------
 2520  *      MOTOR ON AND UP TO SPEED, SO LET'S
 2530  *      FIND OUT WHAT THE COMMAND IS AND DO IT!
 2540  *---------------------------------
 2550  PROCESS.COMMAND
 2560         LDY #12      GET COMMAND
 2570         LDA (IOB.PNTR),Y
 2580         BEQ .8       NULL COMMAND, LET'S LEAVE
 2590         CMP #4       FORMAT?
 2600         BEQ .9       YES
 2610         ROR          SET CARRY=1 IF READ, =0 IF WRITE
 2620         PHP          SAVE ON STACK
 2630         BCS .1       READ
 2640         JSR PRE.NYBBLE  WRITE
 2650  .1     LDY #48      UP TO 48 RETRIES
 2660         STY RETRY.COUNT
 2670  .2     LDX SLOT     GET SLOT NUMBER AGAIN
 2680         JSR READ.ADDRESS
 2690         BCC .5       GOOD ADDRESS READ
 2700  .21    DEC RETRY.COUNT
 2710         BPL .2       KEEP TRYING
 2720  .3     LDA CURRENT.TRACK  GET TRACK WE WANTED
 2730         PHA          SAVE IT
 2740         LDA #96      PRETEND TO BE ON TRACK 96
 2750         JSR SETUP.TRACK
 2760         DEC SEEK.COUNT
 2770         BEQ .6       NO MORE RE-CALIBRATES
 2780         LDA #4
 2790         STA SEARCH.COUNT
 2800         LDA #0       LOOK FOR TRACK 0
 2810         JSR SEEK.TRACK
 2820         PLA          GET TRACK WE REALLY WANT
 2830  .4     JSR SEEK.TRACK
 2840         JMP .1
 2850  *---------------------------------
 2860  .5     LDY $2E      TRACK# IN ADDRESS HEADER
 2870         CPY CURRENT.TRACK
 2880         BEQ .10      FOUND RIGHT TRACK
 2890         LDA CURRENT.TRACK
 2900         PHA          SAVE TRACK WE REALLY WANT
 2910         TYA          SET UP TRACK WE ACTUALLY FOUNG
 2920         JSR SETUP.TRACK
 2930         PLA          TRACK WE WANT
 2940         DEC SEARCH.COUNT
 2950         BNE .4       TRY AGAIN
 2960         BEQ .3       TRY TO RE-CALIBRATE AGAIN
 2970  *---------------------------------
 2980  *      DRIVE ERROR, CANNOT FIND TRACK
 2990  *---------------------------------
 3000  .6     PLA          REMOVE CURRENT.TRACK
 3010         LDA #ERR.BAD.DRIVE
 3020  .7     PLP
 3030         JMP ERROR.HANDLER
 3040  *---------------------------------
 3050  *      NULL COMMAND, ON THE WAY OUT....
 3060  *---------------------------------
 3070  .8     BEQ RWTS.EXIT
 3080  *---------------------------------
 3090  *      FORMAT COMMAND
 3100  *---------------------------------
 3110  .9     JMP FORMAT
 3120  *---------------------------------
 3130  *      READ OR WRITE COMMAND
 3140  *---------------------------------
 3150  .10    LDY #3       GET VOLUME# WANTED
 3160         LDA (IOB.PNTR),Y
 3170         PHA          SAVE DESIRED VOLUME# ON STACK
 3180         LDA VOLUME
 3190         LDY #14      STORE ACTUAL VOLUME NUMBER FOUND
 3200         STA (IOB.PNTR),Y
 3210         PLA          GET DESIRED VOLUME# AGAIN
 3220         BEQ .11      IF =0, DON'T CARE
 3230         CMP VOLUME   SEE IF RIGHT VOLUME
 3240         BEQ .11      YES
 3250         LDA #ERR.WRONG.VOLUME
 3260         BNE .7       UH OH!
 3270  *---------------------------------
 3280  .11    LDY #5       GET SECTOR# WANTED
 3290         LDA (IOB.PNTR),Y   (LOGICAL SECTOR NUMBER)
 3300         TAY          INDEX INTO PHYSICAL SECTOR VECTOR
 3310         LDA PHYSICAL.SECTOR.VECTOR,Y
 3320         CMP SECTOR
 3330         BNE .21      NOT THE RIGHT SECTOR
 3340         PLP          GET COMMAND FLAG AGAIN
 3350         BCC WRITE
 3360         JSR READ.SECTOR
 3370         PHP          SAVE RESULT; IF BAD, WILL BE COMMAND
 3380         BCS .21      BAD READ
 3390         PLP          THROW AWAY
 3400         LDX #0
 3410         STX $26
 3420         JSR POST.NYBBLE
 3430         LDX SLOT
 3440  RWTS.EXIT
 3450         CLC
 3460         .HS 24       "BIT" TO SKIP NEXT INSTRUCTION
 3470  *---------------------------------
 3480  ERROR.HANDLER
 3490         SEC          INDICATE AN ERROR
 3500         LDY #13      STORE ERROR CODE
 3510         STA (IOB.PNTR),Y
 3520         LDA MOTOR.OFF,X
 3530         RTS
 3540  *---------------------------------
 3550  WRITE  JSR WRITE.SECTOR
 3560         BCC RWTS.EXIT
 3570         LDA #ERR.WRITE.PROTECT
 3580         BCS ERROR.HANDLER   ...ALWAYS
 3590  *---------------------------------
 3600  *      SEEK TRACK SUBROUTINE
 3610  *      (A) = TRACK# TO SEEK
 3620  *      (DRIVE.NO) IS NEGATIVE IF DRIVE 1
 3630  *                AND POSITIVE IF DRIVE 2
 3640  *---------------------------------
 3650  SEEK.TRACK
 3660         PHA          SAVE TRACK#
 3670         LDY #1       CHECK DEVICE CHARACTERISTICS TABLE
 3680         LDA (DCT.PNTR),Y   FOR TYPE OF DISK
 3690         ROR          SET CARRY IF TWO PHASES PER TRACK
 3700         PLA          GET TRACK# AGAIN
 3710         BCC .1       ONE PHASE PER TRACK
 3720         ASL          TWO PHASES PER TRACK, SO DOUBLE IT
 3730         JSR .1       FIND THE TRACK
 3740         LSR CURRENT.TRACK  DIVIDE IT BACK DOWN
 3750         RTS
 3760  *---------------------------------
 3770  .1     STA TRACK
 3780         JSR GET.SLOT.IN.Y
 3790         LDA DRIVE.1.TRACK,Y
 3800         BIT DRIVE.NO   WHICH DRIVE?
 3810         BMI .2       DRIVE 1
 3820         LDA DRIVE.2.TRACK,Y
 3830  .2     STA CURRENT.TRACK   WHERE WE ARE RIGHT NOW
 3840         LDA TRACK    WHERE WE WANT TO BE
 3850         BIT DRIVE.NO WHICH DRIVE?
 3860         BMI .3       DRIVE 1
 3870         STA DRIVE.2.TRACK,Y   DRIVE 2
 3880         BPL .4       ...ALWAYS
 3890  .3     STA DRIVE.1.TRACK,Y
 3900  .4     JMP SEEK.TRACK.ABSOLUTE
 3910  *---------------------------------
 3920  *      CONVERT SLOT*16 TO SLOT IN Y-REG
 3930  *---------------------------------
 3940  GET.SLOT.IN.Y
 3950         TXA          SLOT*16 FROM X-REG
 3960         LSR
 3970         LSR
 3980         LSR
 3990         LSR
 4000         TAY          SLOT INTO Y
 4010         RTS
 4020  *---------------------------------
 4030  *      SET UP CURRENT TRACK LOCATION
 4040  *      IN DRIVE.1.TRACK OR DRIVE.2.TRACK VECTORS,
 4050  *      INDEXED BY SLOT NUMBER.
 4060  *
 4070  *      (A) = TRACK# TO BE SET UP
 4080  *---------------------------------
 4090  SETUP.TRACK
 4100         PHA          SAVE TRACK # WE WANT TO SET UP
 4110         LDY #2       GET DRIVE NUMBER FROM IOB
 4120         LDA (IOB.PNTR),Y
 4130         ROR          SET CARRY IF DRIVE 1, CLEAR IF 2
 4140         ROR DRIVE.NO MAKE NEGATIVE IF 1, POSITIVE IF 2
 4150         JSR GET.SLOT.IN.Y
 4160         PLA          GET TRACK #
 4170         ASL          DOUBLE IT
 4180         BIT DRIVE.NO  WHICH DRIVE?
 4190         BMI .1       DRIVE 1
 4200         STA DRIVE.2.TRACK,Y
 4210         BPL .2       ...ALWAYS
 4220  .1     STA DRIVE.1.TRACK,Y
 4230  .2     RTS
 4240  *---------------------------------
 4250  FORMAT
 4260  *---------------------------------
 4270         .BS $BFB8-*
 4280  PHYSICAL.SECTOR.VECTOR
 4290         .HS 000D0B09070503010E0C0A080604020F

