home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / misc / imagefx_sdk / sas / scanlib / timer.asm < prev    next >
Encoding:
Assembly Source File  |  1992-02-05  |  6.6 KB  |  186 lines

  1. ;--------------------------- TIMER FUNCTIONS -----------------------------
  2.  
  3.                 far
  4.  
  5.                 include 'exec/types.i'
  6.                 include 'exec/io.i'
  7.                 include 'devices/timer.i'
  8.  
  9. MANX            EQU     1
  10.  
  11.                 include 'macros.i'
  12.  
  13.                 xref    CreatePort,DeletePort
  14.                 xref    CreateExtIO,DeleteIO
  15.  
  16. SUCCESS         equ     1
  17. FAIL            equ     0
  18.  
  19. ; Create a timer.device request block.  Returns the request block in d0 if
  20. ; successful, otherwise returns NULL (condition codes are also set).
  21. ;
  22. ; req = CreateTimer (unit)
  23. ; d0                 d0.l
  24. ;
  25.  
  26.                 xdef    _CreateTimer
  27. _CreateTimer
  28.                 move.l  4(sp),d0
  29.  
  30.                 xdef    CreateTimer
  31. CreateTimer
  32.                 push    d2/a2/a6
  33.                 move.l  d0,d2                   ; Save unit number.
  34.                 suba.l  a0,a0                   ; Port name = NULL
  35.                 moveq   #0,d0                   ; Port priority = 0
  36.                 bsr     CreatePort              ; Create a message port.
  37.                 beq     9$                      ; Oops - couldn't make it.
  38.                 move.l  d0,a0                   ; Port address.
  39.                 move.l  #IOTV_SIZE,d0           ; Size of timer request block.
  40.                 bsr     CreateExtIO             ; Make a request block.
  41.                 beq     9$                      ; Oops - didn't open.
  42.                 move.l  d0,a2                   ; Save it for a moment.
  43.                 lea     timer_name,a0           ; Point to timer device name.
  44.                 move.l  d2,d0                   ; Get back unit number.
  45.                 move.l  a2,a1                   ; Get IO request block.
  46.                 moveq   #0,d1                   ; Flags = 0.
  47.                 exec    OpenDevice              ; Open the device.
  48.                 tst.l   d0                      ; Did it open?
  49.                 bne     9$                      ; Oops - nope.
  50.                 move.l  a2,d0                   ; It worked!  Tell about the
  51. 91$             pop     d2/a2/a6                ;    request, and exit.
  52.                 tst.l   d0                      ; Set condition codes.
  53.                 rts                             ; Return.
  54. 9$              moveq   #0,d0                   ; Something went awry - say so.
  55.                 bra     91$
  56.  
  57.  
  58. ; Delete a timer.device that was opened with CreateTimer() above.
  59. ;
  60. ; DeleteTimer (req)
  61. ;              a1
  62. ;
  63.  
  64.                 xdef    _DeleteTimer
  65. _DeleteTimer
  66.                 move.l  4(sp),a1
  67.  
  68.                 xdef    DeleteTimer
  69. DeleteTimer
  70.                 push    a2/a6
  71.                 move.l  a1,a2
  72.                 exec    CloseDevice             ; Close the timer.device.
  73.                 move.l  MN_REPLYPORT(a2),a1     ; Get address of reply port.
  74.                 bsr     DeletePort              ; Delete the reply port.
  75.                 move.l  a2,a1                   ; Get address of request block.
  76.                 bsr     DeleteIO                ; Delete the request block.
  77.                 pop     a2/a6                   ; All done.
  78.                 rts
  79.  
  80.  
  81. ; WaitTimer() - Waits for a certain amount of seconds/micros.  This sleeps
  82. ;               until the time elapsed is up.  This function is better
  83. ;               to call than Delay(), because this a) is more accurate and
  84. ;               b) can be called from a task.  'Success' indicates whether
  85. ;               or not the delay was for the full time requested.
  86. ;
  87. ; success = WaitTimer (secs, micros)
  88. ; d0                   d0    d1
  89. ;
  90.  
  91.                 xdef    _WaitTimer
  92. _WaitTimer
  93.                 move.l  4(sp),d0
  94.                 move.l  8(sp),d1
  95.  
  96.                 xdef    WaitTimer
  97. WaitTimer
  98.                 push    a2/a6
  99.                 push    d0                      ; Save seconds.
  100.                 bsr     CreateTimer             ; Create a timer request.
  101.                 beq     9$                      ; Oops - it failed.
  102.                 move.l  d0,a2                   ; Save request.
  103.                 move.w  #TR_ADDREQUEST,IO_COMMAND(a2)
  104.                 move.l  (sp)+,IOTV_TIME+0(a2)   ; Set seconds.
  105.                 move.l  d1,IOTV_TIME+4(a2)      ; Set microseconds.
  106.                 move.l  a2,a1
  107.                 exec    DoIO                    ; Sleep until time is up.
  108.                 move.l  a2,a1
  109.                 bsr     DeleteTimer             ; Free timer request.
  110.                 moveq   #SUCCESS,d0
  111. 91$             pop     a2/a6
  112.                 tst.l   d0
  113.                 rts
  114. 9$              moveq   #FAIL,d0
  115.                 bra     91$
  116.  
  117. ; QueueTimer() - Queue a timer to go off in a given number of seconds/micros.
  118. ;                This is asynchronous, as opposed to WaitTimer(), which is
  119. ;                synchronous.  The returned value is a pointer to the
  120. ;                timer request block.  It returns NULL if there is an error
  121. ;                of some kind.  When finished with the request, call
  122. ;                DeleteTimer() above to free the request block.
  123. ;
  124. ; req = QueueTimer (timereq, seconds, micros);
  125. ; d0                a0       d0       d1
  126. ;
  127.  
  128.                 xdef    _QueueTimer
  129. _QueueTimer
  130.                 move.l  4(sp),a0
  131.                 move.l  8(sp),d0
  132.                 move.l  12(sp),d1
  133.  
  134.                 xdef    QueueTimer
  135. QueueTimer
  136.                 push    a2/a6
  137.                 push    d0                      ; Save seconds.
  138.                 move.l  a0,a2                   ; Save request block pointer.
  139.                 move.w  #TR_ADDREQUEST,IO_COMMAND(a2)
  140.                 move.l  (sp)+,IOTV_TIME+0(a2)
  141.                 move.l  d1,IOTV_TIME+4(a2)
  142.                 move.l  a2,a1
  143.                 exec    SendIO                  ; Send it asynchronously.
  144.                 move.l  a2,d0
  145. 91$             pop     a2/a6
  146.                 tst.l   d0
  147.                 rts
  148. 9$              moveq   #0,d0
  149.                 bra     91$
  150.  
  151.  
  152. ; AbortTimer() - This is used to abort a timer request in progress (via.
  153. ;                the QueueTimer() function above).  It aborts the IO
  154. ;                request and frees the timer with DeleteTimer().
  155. ;
  156. ; AbortTimer (req)
  157. ;             a0
  158. ;
  159.  
  160.                 xdef    _AbortTimer
  161. _AbortTimer
  162.                 move.l  4(sp),a0
  163.  
  164.                 xdef    AbortTimer
  165. AbortTimer
  166.                 push    a2/a6
  167.                 move.l  a0,a2
  168.                 move.l  a2,a1
  169.                 exec    CheckIO
  170.                 tst.l   d0
  171.                 bne.s   9$
  172.                 move.l  a2,a1
  173.                 exec    AbortIO                 ; Abort the request.
  174.                 move.l  a2,a1
  175.                 call    WaitIO                  ; Wait for it to complete.
  176. 9$              pop     a2/a6
  177.                 rts
  178.  
  179.  
  180. timer_name      TIMERNAME
  181.                 cnop    0,2
  182.  
  183.  
  184.                 END
  185.  
  186.