home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff330.lzh
/
XprKermit
/
timeout.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-02
|
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;
}