Path: utzoo!attcan!uunet!ogicse!orstcs!usenet!jacobs.CS.ORST.EDU!parkern From: parkern@jacobs.CS.ORST.EDU (Neil Parker) Newsgroups: comp.sys.apple2 Subject: Re: Disk // register listing Summary: Improved details on accessing the Disk II (LONG!) Message-ID: <1990Nov08.105414.22053@scion.CS.ORST.EDU> Date: 8 Nov 90 10:54:14 GMT References: <9011030453.AA02428@apple.com> Sender: @scion.CS.ORST.EDU Reply-To: parkern@jacobs.cs.orst.edu (Neil Parker) Organization: The Universal Society for the Prevention of Reality Lines: 232 Nntp-Posting-Host: jacobs.cs.orst.edu In article <9011030453.AA02428@apple.com> MQUINN%UTCVM@PUCC.PRINCETON.EDU writes: >On Fri, 2 Nov 90 17:12:29 GMT Charles William Swiger said: >>Anybody have a detailed description of the $C0Ex range of addresses? >>(Which are the registers that control a 5.25" drive at the lowest level >>possible.) >> >>I've disassembled DOS 3.3 RWTS, the $C600 boot code, parts of ProDOS, >>etc and the function of some locations are obvious, but others aren't. >>Thanks. >> >> >> >>-- Charles William Swiger >> cs4w+@andrew.cmu.edu > >ADDRESS LABEL DESCRIPTION >----------------------------------------------------------------- >$C080 PHASEOFF Stepper motor phase 0 off. >$C081 PHASEON STEPPER MOTOR PHASE 0 ON. >$C082 PHASE1OFF STEPPER MOTOR PHASE 1 OFF. >$C083 PHASE1ON STEPPER MOTOR PHASE 1 ON. >$C084 PHASE2OFF { } >$C085 PHASE2ON { YOU CAN FIGURE } >$C086 PHASE3OFF { OUT THESE } >$C087 PHASE3ON { } >$C088 MOTOROFF TURN OFF MOTOR. >$C089 MOTORON TURN MOTOR ON. >$C08A DRVOEN ENGAGE DRIVE 1 >$C08B DRV1EN ENGANE DRIVE 2 >$C08C Q6L STROBE DATA LATCH FOR I/O >$C08D Q6H LOAD DATA LATCH. >$C08E Q7L PREPARE LATCH FOR INPUT. >$C08F Q7H PREPARE LATCH FOR OUTPUT. > > Q7L WITH Q6L = READ > Q7L W/ Q6H = SENSE WRITE PROTECT > Q7H W/ Q6L = WRITE > Q7H W/ Q6H = LOAD WRITE LATCH So far, so good. The explanation which followed, however, might be a bit misleading. The following is taken from "Beneath Apple DOS" and "Beneath Apple ProDOS", which I have sitting in front of me as I type. I am also using "Use of the Disk II Interface Card Through Your Own Software" by John Uhley, from the April 1983 issue of "Apple Orchard" (which goes into considerably more detail about stepping tracks than "Beneath Apple *DOS"). Basically, each track (and half-track) may be considered to be "under" one of the four phases of the stepper motor. Track Phase ---- ----- 0 0 0.5 1 1 2 1.5 3 2 0 2.5 1 3 2 3.5 3 etc.. To figure the phase for a given (half-)track, multiply the track number by 2, and keep only the two low-order bits. Stepping from one track to another is simply a matter of stepping one track at a time from the original track to the destination track. Thus, to step inward from track A to track B, first step to (half-)track A+0.5, then to (half-)track A+1, and so on, until you arrive at track B. Likewise, to step outward from track B to track A, first step to (half-)track B-0.5, then to B-1, and so on until you arrive at track A. An individual step (which must from the original half-track to one if its immediatly neighboring half-tracks) is accomplished by turning on the appropriate phase, waiting, and turning off the phase. An appropriate wait may be obtained by loading the accumulator with #$56 and doing a JSR to the Monitor's WAIT routine ($FCA8). (DOS and ProDOS are able to obtain improved speed by taking into account the fact that once the head is moving, it takes less time to make subsequent steps.) Note that this scheme requires DOS to keep track of which track it's on--there's no way to ask the drive where the head is. If the current track number is unknown, the head must be "recalibrated" by assuming that we're currently at track 35 (or beyond), and then seeking to track 0 (this is what causes that awful GRRRRRINDing sound when you boot a 5.25" disk). Assuming that the disk motor is on, the following code (lifted from the Apple Orchard article) will step from CURTRK to DESTRK on the disk drive whose slot number (*16) is stored in SLOT: MAINLOOP LDA CURTRK CMP DESTRK BEQ ALLDONE BCC MOVEUP BCS MOVEDOWN ; ; MOVE DOWN TO LAST PHASE ; MOVEDOWN DEC CURTRK JMP DOWORK ; ; MOVE UP TO NEXT PHASE ; MOVEUP INC CURTRK ; ; COMPUTE PHASE NUMBER ; FROM THE "NEW" CURTRK ; DOWORK LDA CURTRK AND #$03 ASL ; ; GET INDEXING FOR CUR SLOT# ; ORA SLOT TAY ; ; TURN ON PHASE TO MOVE & ; WAIT FOR PHYSICAL ACTION ; LDA $C081,Y LDA #$56 JSR $FCA8 ; ; TURN OFF PHASE (ALWAYS) % ; LOOP BACK TO CHECK ON NEW ; CURTRK-DESTRK RELATIONSHIP ; LDA $C080,Y JMP MAINLOOP ; ; ALL DONE... QUIT ; ALLDONE (Your code continues here) Most other drive operations are simpler than stepping. Turning on the drive: LDX SLOT LDA $C089,X Once the drive is on, you have to wait for the motor to come up to speed. The Apple Orchard article uses the following code for the delay: LDA #$EF STA WAIT LDA #$D8 STA WAIT+1 MWAITA LDY #$12 MWAITB DEY BNE MWAITB INC WAIT BNE MWAITA INC WAIT+1 BNE MWAITA where WAIT is a location on zero-page. Again, DOS is able to decrease the delay by some clever timing. Selecting drive 1: LDX SLOT LDA $C08A,X Selecting drive 2: LDX SLOT LDA $C08B,X Sensing write-protect: LDX SLOT LDA $C08D,X LDA $C08E,X BMI PROTECTED Setting READ mode (necessary for reading): LDX SLOT LDA $C08E,X Reading a byte (after selecting READ mode): LDX SLOT READLP LDA $C08C,X BPL READLP Writing data: First, sense the write-protect status. Then, LDX SLOT LDA DATA1 STA $C08F,X ORA $C08C,X (wait) LDA DATA2 STA $C08D,X ORA $C08C,X (wait) LDA DATA3 STA $C08D,X ORA $C08C,X (etc...) The wait time must be such that the accesses to $C08C come EXACTLY 32 machine cycles apart. Note also that the first data byte is written differently than subsequent bytes--the access to $C08F in necessary to set WRITE mode. After all data is written, you should access $C08E to select READ mode, in order to prevent data from being erased. At one point (in the disk formatting code), DOS 3.3 uses code like this to write data at 32-cycle intervals: LDA #$D5 (2 cycles) JSR WRITE9 (6) LDA #$AA (2) JSR WRITE9 (6) . . . WRITE9 CLC (2) WRITE7 PHA (3) PLA (4) WRITE STA $C08D,X (5) ORA $C08C,X (4) RTS (6) There is a LOT more to know about disk formatting than what is covered in this post. If you can find a copy of "Beneath Apple DOS", buy it--it will tell you just about everything there is to know about the format of a 5.25" disk. "Beneath Apple ProDOS" has a similar, but somewhat abbreviated discussion. >| | | >| This is your brain... | BITNET-- mquinn@utcvm | >| This is your brain on drugs... | pro-line: | >| This is your brain on frog licking.| mquinn@pro-gsplus.cts.com | >|____________________________________|_______________________________| - Neil Parker -- Neil Parker No cute ASCII art...no cute quote...no cute parkern@jacobs.cs.orst.edu disclaimer...no deposit, no return... parker@corona.uoregon.edu (This space intentionally left blank: )