home *** CD-ROM | disk | FTP | other *** search
- ;--------------------------- TIMER FUNCTIONS -----------------------------
-
- far
-
- include 'exec/types.i'
- include 'exec/io.i'
- include 'devices/timer.i'
-
- MANX EQU 1
-
- include 'macros.i'
-
- xref CreatePort,DeletePort
- xref CreateExtIO,DeleteIO
-
- SUCCESS equ 1
- FAIL equ 0
-
- ; Create a timer.device request block. Returns the request block in d0 if
- ; successful, otherwise returns NULL (condition codes are also set).
- ;
- ; req = CreateTimer (unit)
- ; d0 d0.l
- ;
-
- xdef _CreateTimer
- _CreateTimer
- move.l 4(sp),d0
-
- xdef CreateTimer
- CreateTimer
- push d2/a2/a6
- move.l d0,d2 ; Save unit number.
- suba.l a0,a0 ; Port name = NULL
- moveq #0,d0 ; Port priority = 0
- bsr CreatePort ; Create a message port.
- beq 9$ ; Oops - couldn't make it.
- move.l d0,a0 ; Port address.
- move.l #IOTV_SIZE,d0 ; Size of timer request block.
- bsr CreateExtIO ; Make a request block.
- beq 9$ ; Oops - didn't open.
- move.l d0,a2 ; Save it for a moment.
- lea timer_name,a0 ; Point to timer device name.
- move.l d2,d0 ; Get back unit number.
- move.l a2,a1 ; Get IO request block.
- moveq #0,d1 ; Flags = 0.
- exec OpenDevice ; Open the device.
- tst.l d0 ; Did it open?
- bne 9$ ; Oops - nope.
- move.l a2,d0 ; It worked! Tell about the
- 91$ pop d2/a2/a6 ; request, and exit.
- tst.l d0 ; Set condition codes.
- rts ; Return.
- 9$ moveq #0,d0 ; Something went awry - say so.
- bra 91$
-
-
- ; Delete a timer.device that was opened with CreateTimer() above.
- ;
- ; DeleteTimer (req)
- ; a1
- ;
-
- xdef _DeleteTimer
- _DeleteTimer
- move.l 4(sp),a1
-
- xdef DeleteTimer
- DeleteTimer
- push a2/a6
- move.l a1,a2
- exec CloseDevice ; Close the timer.device.
- move.l MN_REPLYPORT(a2),a1 ; Get address of reply port.
- bsr DeletePort ; Delete the reply port.
- move.l a2,a1 ; Get address of request block.
- bsr DeleteIO ; Delete the request block.
- pop a2/a6 ; All done.
- rts
-
-
- ; WaitTimer() - Waits for a certain amount of seconds/micros. This sleeps
- ; until the time elapsed is up. This function is better
- ; to call than Delay(), because this a) is more accurate and
- ; b) can be called from a task. 'Success' indicates whether
- ; or not the delay was for the full time requested.
- ;
- ; success = WaitTimer (secs, micros)
- ; d0 d0 d1
- ;
-
- xdef _WaitTimer
- _WaitTimer
- move.l 4(sp),d0
- move.l 8(sp),d1
-
- xdef WaitTimer
- WaitTimer
- push a2/a6
- push d0 ; Save seconds.
- bsr CreateTimer ; Create a timer request.
- beq 9$ ; Oops - it failed.
- move.l d0,a2 ; Save request.
- move.w #TR_ADDREQUEST,IO_COMMAND(a2)
- move.l (sp)+,IOTV_TIME+0(a2) ; Set seconds.
- move.l d1,IOTV_TIME+4(a2) ; Set microseconds.
- move.l a2,a1
- exec DoIO ; Sleep until time is up.
- move.l a2,a1
- bsr DeleteTimer ; Free timer request.
- moveq #SUCCESS,d0
- 91$ pop a2/a6
- tst.l d0
- rts
- 9$ moveq #FAIL,d0
- bra 91$
-
- ; QueueTimer() - Queue a timer to go off in a given number of seconds/micros.
- ; This is asynchronous, as opposed to WaitTimer(), which is
- ; synchronous. The returned value is a pointer to the
- ; timer request block. It returns NULL if there is an error
- ; of some kind. When finished with the request, call
- ; DeleteTimer() above to free the request block.
- ;
- ; req = QueueTimer (timereq, seconds, micros);
- ; d0 a0 d0 d1
- ;
-
- xdef _QueueTimer
- _QueueTimer
- move.l 4(sp),a0
- move.l 8(sp),d0
- move.l 12(sp),d1
-
- xdef QueueTimer
- QueueTimer
- push a2/a6
- push d0 ; Save seconds.
- move.l a0,a2 ; Save request block pointer.
- move.w #TR_ADDREQUEST,IO_COMMAND(a2)
- move.l (sp)+,IOTV_TIME+0(a2)
- move.l d1,IOTV_TIME+4(a2)
- move.l a2,a1
- exec SendIO ; Send it asynchronously.
- move.l a2,d0
- 91$ pop a2/a6
- tst.l d0
- rts
- 9$ moveq #0,d0
- bra 91$
-
-
- ; AbortTimer() - This is used to abort a timer request in progress (via.
- ; the QueueTimer() function above). It aborts the IO
- ; request and frees the timer with DeleteTimer().
- ;
- ; AbortTimer (req)
- ; a0
- ;
-
- xdef _AbortTimer
- _AbortTimer
- move.l 4(sp),a0
-
- xdef AbortTimer
- AbortTimer
- push a2/a6
- move.l a0,a2
- move.l a2,a1
- exec CheckIO
- tst.l d0
- bne.s 9$
- move.l a2,a1
- exec AbortIO ; Abort the request.
- move.l a2,a1
- call WaitIO ; Wait for it to complete.
- 9$ pop a2/a6
- rts
-
-
- timer_name TIMERNAME
- cnop 0,2
-
-
- END
-
-