Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!usc!pollux.usc.edu!papa From: papa@pollux.usc.edu (Marco Papa) Newsgroups: comp.sys.amiga Subject: Re: Timer Device Message-ID: <18420@usc.edu> Date: 12 Jul 89 04:34:44 GMT References: <764@orbit.UUCP> Sender: news@usc.edu Reply-To: papa@pollux.usc.edu (Marco Papa) Organization: Felsina Software, Los Angeles, CA Lines: 76 In article <764@orbit.UUCP> glamdrng@pnet51.cts.com (Rocky Lhotka) writes: >Does anyone have a nice, simple (but working) example of how to use the >timer.device to perform the function of the AmigaDOS Delay() function? >I have entered a couple example programs from books which do not work at all, >as they never return on the Wait() call... I really would appreciate any >help anyone can give me, as this seems like such a SIMPLE thing to do, but is >apparently not so... Thanks in advance!! The following code is from the XPR distribution. I don't know if Willy wrote it himself. The nice thing is that unlike Delay() it can be used in libraries and such. /** timeout.c * * Roll-yer-own Delay() function. * **/ #include #include #include #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; } -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= uucp:...!pollux!papa BIX:papa ARPAnet:pollux!papa@oberon.usc.edu "There's Alpha, Beta, Gamma, Diga and Caligari!" -- Rick Unland -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=