home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 138.lha / Cycle / time.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  1KB  |  56 lines

  1. /* "time.c"
  2.  * Fuctions relatingto the timer device: Timer_Open(), Timer_Close(), and
  3.  * Timer_Post(). Timer_Post() requests the timer device to send a message
  4.  * after the given number of seconds and microseconds.
  5.  */
  6. #include <exec/types.h>
  7. #include <exec/ports.h>
  8. #include <devices/timer.h>
  9.  
  10. #include "cycles.h"
  11.  
  12. TIMEREQ *Timer_Open(unit,tp)
  13. ULONG unit;
  14. PORT *tp;
  15. {
  16.   long error;
  17.   TIMEREQ *tr;
  18.  
  19.   if (!tp) tp = CreatePort(0,0);
  20.   if (!tp) return(0);
  21.  
  22.   tr = (TIMEREQ *)CreateExtIO(tp,sizeof(TIMEREQ));
  23.   if(!tr) {
  24.     printf("Can't create timer request\n");
  25.     return(0);
  26.   }
  27.   error = OpenDevice("timer.device",unit,tr,0L);
  28.   if (error) {
  29.     Timer_Close(tr);
  30.     return(0);
  31.   }
  32.   return(tr);
  33. }
  34. /* close the timer device down */
  35. void Timer_Close(tr)
  36. TIMEREQ *tr;
  37. {
  38.   PORT *tp;
  39.  
  40.   if (tr) {
  41.     tp = tr->tr_node.io_Message.mn_ReplyPort;
  42.     if (tp) DeletePort(tp);
  43.     CloseDevice(tr);
  44.     DeleteExtIO(tr,sizeof(TIMEREQ));
  45.   }
  46. }
  47. /* ask the timer to reply to our message after a certain time */
  48. void Timer_Post(tr,secs,micro)
  49. TIMEREQ *tr;
  50. {
  51.   tr->tr_node.io_Command = TR_ADDREQUEST;
  52.   tr->tr_time.tv_secs    = secs;
  53.   tr->tr_time.tv_micro   = micro;
  54.   SendIO(tr);
  55. }
  56.