home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff236.lzh / XprZmodem / timeout.c < prev    next >
C/C++ Source or Header  |  1989-08-09  |  1KB  |  61 lines

  1. /** timeout.c
  2. *
  3. *   Roll-yer-own Delay() function.
  4. *
  5. **/
  6. #include <exec/exec.h>
  7. #include <devices/timer.h>
  8. #include <functions.h>
  9.  
  10. #define TRSIZE ((long) sizeof(struct timerequest))
  11.  
  12. TimeOut(ticks)
  13. long ticks;
  14. {
  15.    long secs, micros;
  16.    struct timerequest *Timereq = NULL;
  17.    struct MsgPort *Timerport = 0L;
  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, 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(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(Timereq);
  55.       FreeMem(Timereq, TRSIZE);
  56.    }
  57.    if (Timerport) DeletePort(Timerport);
  58.  
  59.    return;
  60. }
  61.