home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / Devcon_Extras / Tech_Articles / Game_Vendors < prev    next >
Encoding:
Text File  |  1992-08-27  |  7.5 KB  |  216 lines

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