home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff222.lzh / MemGauge / TimerDevice.c < prev   
C/C++ Source or Header  |  1989-06-19  |  2KB  |  83 lines

  1. /* TimerDevice.c ************************************************************
  2. *
  3. *    TimerDevice - Timer control routines, very useful.
  4. *
  5. *    Author...     Olaf 'Olsen' Barthel (ED Electronic Design Hannover)
  6. *                  Brabeckstrasse 35
  7. *                  D-3000 Hannover 71
  8. *
  9. ****************************************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <devices/timer.h>
  13. #include <exec/memory.h>
  14.  
  15. struct timerequest    *tr_TimerRequest= NULL,*AllocMem();
  16. struct MsgPort        *tr_TimerPort    = NULL,*CreatePort();
  17.  
  18.     /* CloseTimerDevice() :
  19.      *
  20.      *    Closes the timer.device.
  21.      */
  22.  
  23. void
  24. CloseTimerDevice()
  25. {
  26.     if(tr_TimerRequest)
  27.     {
  28.         CloseDevice(tr_TimerRequest);
  29.         FreeMem(tr_TimerRequest,sizeof(struct timerequest));
  30.     }
  31.  
  32.     if(tr_TimerPort)
  33.         DeletePort(tr_TimerPort);
  34. }
  35.  
  36.     /* OpenTimerDevice() :
  37.      *
  38.      *    Opens the precision timer.
  39.      */
  40.  
  41.  
  42. BOOL
  43. OpenTimerDevice()
  44. {
  45.     if(!(tr_TimerPort = (struct MsgPort *)CreatePort(NULL,0)))
  46.         return(FALSE);
  47.  
  48.     if(!(tr_TimerRequest = (struct timerequest *)AllocMem(sizeof(struct timerequest),MEMF_PUBLIC | MEMF_CLEAR)))
  49.     {
  50.         DeletePort(tr_TimerPort);
  51.         return(FALSE);
  52.     }
  53.  
  54.     if(OpenDevice(TIMERNAME,UNIT_VBLANK,tr_TimerRequest,0))
  55.     {
  56.         FreeMem(tr_TimerRequest,sizeof(struct timerequest));
  57.         DeletePort(tr_TimerPort);
  58.         return(FALSE);
  59.     }
  60.  
  61.     tr_TimerRequest -> tr_node . io_Message . mn_ReplyPort    = tr_TimerPort;
  62.     tr_TimerRequest -> tr_node . io_Command            = TR_ADDREQUEST;
  63.     tr_TimerRequest -> tr_node . io_Flags            = 0;
  64.     tr_TimerRequest -> tr_node . io_Error            = 0;
  65.  
  66.     return(TRUE);
  67. }
  68.  
  69.     /* WaitTime(Seconds,Micros) :
  70.      *
  71.      *    Waits a couple of seconds/microseconds.
  72.      */
  73.  
  74. void
  75. WaitTime(Seconds,Micros)
  76. register ULONG Seconds,Micros;
  77. {
  78.     tr_TimerRequest -> tr_time . tv_secs    = Seconds;
  79.     tr_TimerRequest -> tr_time . tv_micro    = Micros;
  80.  
  81.     DoIO(tr_TimerRequest);
  82. }
  83.