home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol1 / Trackdisk / LowLevelDisk < prev    next >
Encoding:
Text File  |  1999-10-27  |  8.1 KB  |  230 lines

  1. (c)  Copyright 1989-1999 Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice, and 
  3. is provided "as is" without warranty of any kind, either expressed or implied.  
  4. The entire risk as to the use of this information is assumed by the user.
  5.  
  6.  
  7.  
  8.  
  9.                    Amiga Low-Level Disk Access
  10.  
  11.                         by Bryce Nesbitt
  12.  
  13.  
  14.  
  15. Some high-performance games for the Amiga have been released recently which
  16. ignore the operating system and take over the machine.  While this practice 
  17. is discouraged, it is allowable.  However, some of these games make direct
  18. use of the floppy disk hardware in an incorrect manner.  Such misuse is NOT 
  19. acceptable.
  20.  
  21. Similarly, certain books by major publishers have described direct access
  22. techniques for the Amiga's disk hardware which will NOT work with all
  23. Amigas.  Commodore uses floppy disk drives manufactured by several different 
  24. vendors.  These vendors often upgrade or modernize their disk drive lines, 
  25. usually making the older drive models unavailable.  For this reason, it is 
  26. impossible for a developer to test with all possible drive types.  In order 
  27. to work across this broad spectrum of drives, certain rules must be 
  28. followed.
  29.  
  30. The routines presented here will allow you to get low-level access to the
  31. Amiga's floppy disk hardware without sacrificing compatability.  Three 
  32. functions are provided to correctly implement the three most critical drive 
  33. operations, namely, motor on, motor off and step.  Also included is a simple
  34. test module which shows how to use the routines in your application.
  35.  
  36.  
  37.  
  38.  
  39.        Disk Routine      Purpose
  40.        ------------      -------------   
  41.  
  42.        MOTORON           Turn the motor on, and properly wait for the
  43.                          drive to reach full speed.
  44.  
  45.        MOTOROFF          Turn off and deselect all drives
  46.  
  47.        STEPHEAD          Step the head, and properly wait for the 3.0
  48.                          millisecond step delay on any speed CPU.
  49.  
  50.        TEST              Test program showing use of above functions.
  51.  
  52.  
  53.  
  54. By using these routines you can avoid the hardware dependencies that make
  55. your software unloadable on some Amigas and the customer support headaches
  56. that go along with it.
  57.  
  58.  
  59.  
  60.  
  61.  
  62. *  opt l+,c+,w-
  63. ;
  64. ; Low-level "take over the machine" disk drive functions.
  65. ;
  66. ; *** FOR USE ONLY WHEN YOU HAVE TAKEN OVER THE MACHINE ***
  67. ;
  68. ; Written by Bryce Nesbitt, Commodore-Amiga, Inc.
  69. ;
  70. ;****** Externally visible functions
  71.  
  72.         XDEF    MOTORON     ;Turn drive 0 motor ON & wait for READY.
  73.         XDEF    MOTOROFF    ;Turn off all drive motors.
  74.         XDEF    STEPHEADS   ;Step the drive head & wait properly.
  75.  
  76.  
  77. ;****** Hard-coded I/O register locations
  78. ;
  79. CIAA_PRA        EQU $BFE001 ;Port "A" on CIA "A".
  80. CIAB_PRB        EQU $BFD100 ;Port "B" on CIA "B".
  81. CIAA_TALO       EQU $BFE401 ;Timer A low
  82. CIAA_TAHI       EQU $BFE501 ;Timer A high
  83. CIAA_ICR        EQU $BFED01 ;Interrupt control register
  84. CIAA_CRA        EQU $BFEE01 ;Timer A control
  85.  
  86.  
  87. ;;;;;;; MOTORON ;;;;;;;
  88. ;
  89. ; Turn off the motors of drives 1-3, then turn on drive 0.
  90. ; This function returns when drive 0 is ON and spinning at full speed.
  91. ; If drive 0 is already spinning, this function returns very quickly.
  92. ;
  93. ; The direction and side lines are untouched.
  94. ;
  95. MOTORON:
  96.                 or.b    #$F9,CIAB_PRB   ;Set motor line to off, deselect
  97.                                          ;all drives, and unset STEP line.
  98.                 and.b   #$8F,CIAB_PRB   ;Select drives 1-3 so they see the
  99.                                          ;motor off setting
  100.                 or.b    #$70,CIAB_PRB   ;Deselect drives 1-3
  101.  
  102.                 and.b   #$7F,CIAB_PRB   ;Set motor ON.  This must be done
  103.                                          ;*BEFORE* selecting drives!
  104.                 and.b   #$F7,CIAB_PRB   ;Select drive zero.  The drive will
  105.                                          ;"remember" the motor setting
  106.                                          ;if the motor was already on,
  107.                                          ;nothing happens
  108.  
  109. motor_wait      btst.b  #5,CIAA_PRA     ;Check READY line
  110.                 bne.s   motor_wait      ;Busy-wait until drive is ready
  111.                 rts
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. ;;;;;;; MOTOROFF ;;;;;;;
  119. ;
  120. ; Turn OFF all drive motors.
  121. ;
  122. MOTOROFF:
  123.                 or.b    #$F8,CIAB_PRB   ;Deselect all drives and set motor
  124.                                          ;line to OFF
  125.                 and.b   #$87,CIAB_PRB   ;Select all drives so they see the
  126.                                          ;new motor setting.
  127.                 or.b    #$F8,CIAB_PRB   ;Deselect all drives
  128.                 rts
  129.  
  130.  
  131. ;;;;;;; STEPHEADS ;;;;;;;
  132. ;
  133. ; D0 must contain zero to step the heads inward, and -1 to step the
  134. ; heads toward the outside of the disk.
  135. ;
  136. ; The heads will step in the direction indicated.  After stepping this
  137. ; function will do a processor-independant wait for the required
  138. ; 3.0 millisecond step delay.  Note that some disk drives do not
  139. ; require a full 3.0 milliseconds, but others do.  It is not safe
  140. ; to release a commercial product with a shorter step delay.
  141. ;
  142. ; Note that the STEP line must always start out high, be pulsed
  143. ; low, then return high.
  144. ;
  145. ; Using this timer chip method and interrupts, it is easy to create
  146. ; a loader that keeps on loading while your title music plays.
  147. ;
  148. STEPHEADS:
  149.                 and.b   #2,d0           ;Remove garbage bits
  150.                 or.b    d0,CIAB_PRB     ;Set direction register FIRST
  151.  
  152.                 ;(Try to be a little bit slow about pulsing the step line)
  153.                 bclr.b  #0,CIAB_PRB     ;Pulse STEP line low
  154.                 bset.b  #0,CIAB_PRB     ;Return STEP high
  155. ;
  156. ; Use the timer chip to waste 3.0 milliseconds
  157. ;
  158. ; The base Amiga crytal frequecies are:
  159. ;           NTSC    28.63636 Mhz
  160. ;           PAL     28.37516  Mhz
  161. ; The two 16 bit timers on the 8520 chips each count down at 1/10
  162. ; the CPU clock, or .715909 Mhz.  That works out to 1.3968255
  163. ; microseconds per count.  Under PAL the countdown is a hair
  164. ; slower, .709379 Mhz.
  165. ;
  166. ; To wait 1/100 second would require waiting 10,000 microseconds.
  167. ; The timer register would be set to (10,000 / 1.3968255 = 7159).
  168. ;
  169. ; To wait 3 milliseconds would require waiting 3000 microsecsonds.
  170. ; The register would be set to (3000 / 1.3968255 = 2148).
  171. ;
  172. ; See the hardware manual for more information on the 8520 chips.
  173. ;
  174.  
  175. ;----Setup (really only needs to be done once)
  176.                 move.w  #$7fff,$dff09a      ;Kill all custom chip interrupts
  177. ;----This sets timer A to one-shot mode.
  178.                 move.b  CIAA_CRA,d0         ;Set control register A
  179.                 and.b   #%11000000,d0       ;Don't trash the 60/50Hz flag
  180.                 or.b    #%00001000,d0       ;or serial direction bits
  181.                 move.b  d0,CIAA_CRA
  182.                 move.b  #%01111111,CIAA_ICR ;Clear all 8520 interrupts
  183. ;----end setup
  184.  
  185. ;----Set time (low byte THEN high byte)
  186.                 move.b  #(2148&255),CIAA_TALO  ;Mask off low part
  187.                 move.b  #(2148>>8),CIAA_TAHI  ;Shift high part 8 bits
  188.  
  189. ;----Wait for the timer to count down
  190. busy_wait:      btst.b  #0,CIAA_ICR         ;Wait for timer expired flag
  191.                 beq.s   busy_wait
  192.                 rts
  193.  
  194.  
  195. ;;;;;;; TEST ;;;;;;;
  196. ;
  197. ; Quick, nasty test program
  198. ;
  199. *               INCDIR  "inc:"
  200.                 INCLUDE "exec/types.i"
  201.                 INCLUDE "exec/ables.i"
  202.  
  203.                 XREF    _LVODisable
  204.  
  205.  
  206. TEST:           move.l  4,a6
  207.                 jsr     _LVODisable(a6)
  208.                 bsr     MOTORON
  209.  
  210.                 moveq   #10,d3          ;Ten full seeks before end
  211. fullseek:
  212.                 bset.b  #1,CIAB_PRB     ;Set direction to OUTWARD
  213.                 moveq   #80-1,d2        ;80 tracks
  214. test4           bsr     STEPHEADS
  215.                 btst.b  #4,CIAA_PRA     ;Check track 00 sensor
  216.                 dbeq    d2,test4        ;Decrement and branch until
  217.                                         ;EQual or count exceeded
  218.                 moveq   #80-1,d2
  219.                 bclr.b  #1,CIAB_PRB     ;Set direction to INWARD
  220. test3           bsr     STEPHEADS
  221.                 dbra    d2,test3
  222.  
  223.                 dbra    d3,fullseek
  224.  
  225.                 bsr     MOTOROFF
  226. fish            bra.s   fish
  227. ;
  228. ; We have killed the operating system, so this tester never exits
  229. ;
  230.