Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!tandem!zorch!amiga0!mykes From: mykes@amiga0.SF-Bay.ORG (Mike Schwartz) Newsgroups: comp.sys.amiga.programmer Subject: Re: Direct hardware drive access Message-ID: Date: 31 Mar 91 04:32:34 GMT References: <2147@pdxgate.UUCP> Organization: Amiga makes it possible Lines: 133 In article <2147@pdxgate.UUCP> bairds@eecs.cs.pdx.edu (Shawn L. Baird) writes: >With the recent flamage/discussion I've revitalized some of my interest >in trying my hand at direct disk reading. I've included a small snippet >of code and will say that I can't even get the drive light to come on. >The code enters with Disable() having been called and all DMA turned >off (I'm not using any disk DMA for stepping out to track 0, so this >shouldn't be a problem should it?). The goal is to step the disk out to >track 0. > > ; step to the outside of the disk in drive 0 (I wish) > and.b #$7f,ciaaprb ; select motor > and.b #$f7,ciaaprb ; select drive 0 >diskready: btst.b #5,ciaapra ; check DSKRDY > beq.s diskready > or.b #$02,ciaaprb ; set step direction >checktrack0: move.l #3000,d0 > jsr wait > btst.b #4,ciaapra ; check DSKTRACK0 > bne.s disktrack0 > and.b #$fe,ciaaprb ; step out > or.b #$01,ciaaprb > bra.s checktrack0 >disktrack0: or.b #$88,ciaaprb ; unselect drive 0 > >The subroutine wait uses the cia timer to wait d0 microseconds and works >as far as I can tell. Didn't someone around here claim to have worked on, >or developed entirely, the trackdisk.device for 1.3 and 2.0? If so, help! > >--- > Shawn L. Baird, bairds@eecs.ee.pdx.edu, Wraith on DikuMUD > The above message is not licensed by AT&T, or at least, not yet. Try the following routines, instead. Notice that 'structured' programming techniques are just as doable in assembler as they are in 'C'. Note that when coding in assembler, your code is pretty optimal. In particular, notice that rather than saying: bsr StepDelay rts You can use bra StepDelay Which saves 34 clock cycles and 2 bytes. tdError dc.l 0 ; result of last operation tdDrive dc.b 0 ; selected drive tdDriveBits dc.b 0 ; bits for CIA for selected drive EVEN SetDrive0 clr.b tdDrive move.b #%00110000,tdDriveBits rts SetDrive1 move.b #1,tdDrive move.b #%00101000,tdDriveBits rts SetDrive2 move.b #2,tdDrive move.b #%00011000,tdDriveBits rts ; Turn Amiga drive motor on: MotorOn clr.l tdError lea CIAB,a0 move.b #%11111111,(a0) move.b #%01111111,(a0) move.b #%01000111,d0 or.b tdDriveBits,d0 move.b d0,(a0) ; wait for disk to come up to speed move.l d4,-(sp) move.w #750/3,d4 .wait bsr StepDelay dbra d4,.wait move.l (sp)+,d4 move.l tdError,d0 rts ; Turn Amiga drive motor off: MotorOff move.l #CIAB,a0 move.b #%11111111,(a0) move.b #%10000111,(a0) move.b #%11111111,(a0) rts ; Use CIA A, Timer A, to delay at least 3Ms. StepDelay move.l d0,-(sp) move.b CRAA,d0 and.b #%11000000,d0 or.b #%00001000,d0 move.b d0,CRAA move.b #%01111111,ICRA move.b #(2148&255),TALOA move.b #(2148>>8),TAHIA .wait btst #0,ICRA beq.s .wait move.l (sp)+,d0 rts ; Step toward track 80: StepRight move.l #CIAB,a0 move.b #%01000111,d0 or.b tdDriveBits,d0 move.b d0,(a0) move.b #%01000100,d0 or.b tdDriveBits,d0 move.b d0,(a0) move.b #%01000101,d0 or.b tdDriveBits,d0 move.b d0,(a0) move.b #%01000111,d0 or.b tdDriveBits,d0 move.b d0,(a0) bra StepDelay ; Step toward track 00 (outermost physical track) StepLeft move.l #CIAB,a0 move.b #%01000111,d0 or.b tdDriveBits,d0 move.b d0,(a0) move.b #%01000110,d0 or.b tdDriveBits,d0 move.b d0,(a0) move.b #%01000111,d0 or.b tdDriveBits,d0 move.b d0,(a0) bra StepDelay -- ******************************************************** * Appendix A of the Amiga Hardware Manual tells you * * everything you need to know to take full advantage * * of the power of the Amiga. And it is only 10 pages! * ********************************************************