home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / xprzmodem_459.lzh / XprZmodem / timeout.c < prev    next >
C/C++ Source or Header  |  1991-02-18  |  1KB  |  61 lines

  1. /** timeout.c
  2. *
  3. *   Roll-yer-own Delay() function.
  4. *
  5. **/
  6. #include <proto/all.h>
  7. #include <exec/types.h>
  8. #include <exec/exec.h>
  9. #include <exec/memory.h>
  10. #include <devices/timer.h>
  11.  
  12. #define TRSIZE ((long) sizeof(struct timerequest))
  13.  
  14. void TimeOut(long ticks) {
  15.    long secs, micros;
  16.    struct timerequest *Timereq = NULL;
  17.    struct MsgPort *Timerport;
  18.  
  19.    if (ticks == 0L) return;
  20.  
  21.    Timerport = CreatePort(0L, 0L);
  22.    if (Timerport == NULL) goto cleanup;
  23.  
  24.    Timereq = (struct timerequest *) AllocMem(TRSIZE, MEMF_PUBLIC | MEMF_CLEAR);
  25.    if (Timereq == NULL) goto cleanup;
  26.  
  27.    if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)Timereq, 0L) != NULL) goto cleanup;
  28. /*
  29. *  Set up timer request.
  30. */
  31.    secs = ticks / 50L;
  32.    micros = (ticks % 50L) * 20000L;
  33.  
  34.    Timereq->tr_node.io_Message.mn_ReplyPort = Timerport;
  35.    Timereq->tr_node.io_Command = TR_ADDREQUEST;
  36.    Timereq->tr_node.io_Flags = 0;
  37.    Timereq->tr_node.io_Error = 0;
  38.    Timereq->tr_time.tv_secs = secs;
  39.    Timereq->tr_time.tv_micro = micros;
  40. /*
  41. *   Time out
  42. */
  43.    SendIO((struct IORequest *)Timereq);
  44.    Wait(1L << Timerport->mp_SigBit);
  45. /*
  46. *  Handle timer events.
  47. */
  48.    GetMsg(Timerport);
  49. /*
  50. *   Clean up
  51. */
  52. cleanup:
  53.    if (Timereq) {
  54.       if (Timereq->tr_node.io_Message.mn_ReplyPort) CloseDevice((struct IORequest *)Timereq);
  55.       FreeMem(Timereq, TRSIZE);
  56.    }
  57.    if (Timerport) DeletePort(Timerport);
  58.  
  59.    return;
  60. }
  61.