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: 1 Apr 91 01:37:56 GMT References: <2147@pdxgate.UUCP> <20215@cbmvax.commodore.com> Organization: Amiga makes it possible Lines: 151 In article <20215@cbmvax.commodore.com> jesup@cbmvax.commodore.com (Randell Jesup) writes: >In article mykes@amiga0.SF-Bay.ORG (Mike Schwartz) writes: >> bsr StepDelay >> rts >>You can use >> bra StepDelay >>Which saves 34 clock cycles and 2 bytes. > > One of the oldest optimizations known to mankind (and compilers with >tail-recursion/etc optimizations will do this too - even a simple peephole >optimizer can catch this). > Some people who've never seen assembler language don't know about this. They *have* to rely upon their compilers to be good enough to do this for them. I'd be interested to know exactly *what* compilers for the Amiga do this optimization? I'd also point out that sometimes debugging can be easier if you do the bsr followed by RTS. You lose the clock cycles and bytes, but you gain the ability to "step over" the subroutine instead of having to manually put a breakpoint at its 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 > > First, the persons code you replied to was far better than this. >You're waiting .75 seconds (750 ms) on every motor-on. We spec that floppy >drives on the Amiga MUST be up to speed in .5 seconds. Also, the disk hardware >as a ready signal, to tell you when it's up to speed. Many drives come up to >speed far faster than .5 seconds, or may have just been turned off and are >still close to speed, etc, or may have been on already, etc. The person who >you responded to looped checking dskrdy. The best way to to wait .5 seconds, >checking dskrdy every so often (2.0 trackdisk checks it every .1 seconds). > I check DSKRDY before reading/writing to the disk. I waited a little extra time deliberatly to help ensure that drives that are up to 50% out of spec work. Better safe than sorry. And to help other developers who use AmigaMail: The article titled "Low Level Disk Access" by Bryce Nesbitt on page VIII-10/11 shows the following routine: motor_wait btst.b #5,CIAA_PRA ; check READY line bne.s motor_wait ; busy wait until drive is ready rts When I tried this on an A500 at EA, it didn't work at ALL. >> 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) > ^^^^^^^^^^^^^^^^^^^^ not needed, doesn't hurt >BTW, you could have coded that routine 2 bytes shorter and 12 cycles shorter, >if you care so much about space/speed. > >> rts >... >>; Step toward track 80: >>StepRight move.l #CIAB,a0 >> move.b #%01000111,d0 > ^ Interesting, that's DSKSEL3 > Ever test this code with 4 drives? My mistake. One of us (you, Bryce, and myself) should have caught this one. You saw these sources before we shipped. I had cut these routines from a set of MS-DOS/Atari ST format drivers someone else had written. > ^ Interesting, that's outwards (toward 0) Difference in terminology here, but Randall's usage is more correct. It should be IN instead of RIGHT, and OUT instead of LEFT. > This stuff of CIAB is not needed. > (though a different one is) >> or.b tdDriveBits,d0 >> move.b d0,(a0) >> move.b #%01000100,d0 > ^ Interesting, that's DSKSEL3 > ^ Interesting, that's inwards (toward 80) >The hardware manual says DSKDIREC MUST be set correctly BEFORE step is set to >0. You must be lucky not to have hit a drive that actually requires it yet. > PEOPLE NOTE THIS! There might not be a drive that requires it yet, but there might be in the future. EA has had ZERO returns or reports of any problems with these routines, but it is always a good idea to do it right. >> or.b tdDriveBits,d0 >> move.b d0,(a0) >> move.b #%01000101,d0 > ^ Interesting, that's DSKSEL3 >> or.b tdDriveBits,d0 >> move.b d0,(a0) >> move.b #%01000111,d0 > ^ Interesting, that's DSKSEL3 > ^ Interesting, that's outwards again > This stuff of CIAB is not needed. Kinda picky about the lower 3 bits... is it WRONG? >> or.b tdDriveBits,d0 >> move.b d0,(a0) >> bra StepDelay > > And where is your settle routine? (I suspect you merely didn't >include it - you need 15ms settle after finishing seeking (on top of the >step delay!) > There is a routine called StepToTrack that calls these routines. When it has stepped to the desired track, it waits 15ms. The original poster asked how to step the heads, not how to read/write to the disk. Another word of advice. Do not use the book "Amiga Disk Drives: Inside and Out" by Abacus. I was told by Commodore when I was writing my routines that the book is full of misinformation and was likely to cause people to have disk driver problems. >-- >Randell Jesup, Keeper of AmigaDos, Commodore Engineering. >{uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.commodore.com BIX: rjesup >Thus spake the Master Ninjei: "To program a million-line operating system >is easy, to change a man's temperament is more difficult." >(From "The Zen of Programming") ;-) -- ******************************************************** * 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! * ********************************************************