home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
272.lha
/
xprquickb
/
timeout.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-05
|
1KB
|
61 lines
/** timeout.c
*
* Roll-yer-own Delay() function.
*
**/
#include <exec/exec.h>
#include <devices/timer.h>
#include <functions.h>
#define TRSIZE ((long) sizeof(struct timerequest))
TimeOut(ticks)
long ticks;
{
long secs, micros;
struct timerequest *Timereq = NULL;
struct MsgPort *Timerport = 0L;
if (ticks == 0L) return;
Timerport = CreatePort(0L, 0L);
if (Timerport == NULL) goto cleanup;
Timereq = (struct timerequest *) AllocMem(TRSIZE, MEMF_PUBLIC | MEMF_CLEAR);
if (Timereq == NULL) goto cleanup;
if (OpenDevice(TIMERNAME, UNIT_VBLANK, Timereq, 0L) != NULL) goto cleanup;
/*
* Set up timer request.
*/
secs = ticks / 50L;
micros = (ticks % 50L) * 20000L;
Timereq->tr_node.io_Message.mn_ReplyPort = Timerport;
Timereq->tr_node.io_Command = TR_ADDREQUEST;
Timereq->tr_node.io_Flags = 0;
Timereq->tr_node.io_Error = 0;
Timereq->tr_time.tv_secs = secs;
Timereq->tr_time.tv_micro = micros;
/*
* Time out
*/
SendIO(Timereq);
Wait(1L << Timerport->mp_SigBit);
/*
* Handle timer events.
*/
GetMsg(Timerport);
/*
* Clean up
*/
cleanup:
if (Timereq) {
if (Timereq->tr_node.io_Message.mn_ReplyPort) CloseDevice(Timereq);
FreeMem(Timereq, TRSIZE);
}
if (Timerport) DeletePort(Timerport);
return;
}