home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d109 / uupc.lha / UUpc / Source / LOCAL / Timer.c < prev    next >
C/C++ Source or Header  |  1987-10-28  |  3KB  |  124 lines

  1. /*  
  2.  *  Timer.c: Functions to invoke the Amiga timer:
  3.  *  
  4.  *  External Functions:
  5.  *
  6.  *  OpenTimer, CloseTimer, StartTimer, TimerExpired, GetTimerSigBit
  7.  * 
  8.  *  Maintenance Notes:
  9.  *   05Jul86  - Created by Jeff Lydiatt, Vancouver, Canada.
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/nodes.h>
  14. #include <exec/lists.h>
  15. #include <exec/ports.h>
  16. #include <exec/tasks.h>
  17. #include <exec/io.h>
  18. #include <devices/timer.h>
  19. #include <functions.h>
  20.  
  21. static struct timerequest TimerIO;
  22. static struct MsgPort    *TimerPort = NULL;
  23. static BOOL timerON;
  24. static BOOL timerExpired;
  25.  
  26. /*-------------------------------------------------------------*/
  27. /*    OpenTimer: return TRUE if timer opened OK           */
  28. /*-------------------------------------------------------------*/
  29.  
  30. BOOL OpenTimer()
  31. {
  32.    register struct timerequest *t = &TimerIO;
  33.    register struct MsgPort *port;
  34.  
  35.    timerON = FALSE;
  36.    timerExpired = TRUE;
  37.    if ( TimerPort != NULL )
  38.       return TRUE;
  39.  
  40.    if ( (port = CreatePort("Timer Port", 0L)) == NULL )
  41.       return FALSE;
  42.    else
  43.       TimerPort = port;
  44.  
  45.    if (OpenDevice(TIMERNAME, UNIT_VBLANK, t, 0L) != 0)
  46.      {
  47.     DeletePort( port );
  48.     TimerPort = NULL;
  49.     return FALSE;
  50.      }
  51.  
  52.    return TRUE;
  53. }
  54.  
  55. /*-------------------------------------------------------------*/
  56. /*    CloseTimer: All Done with the timer.               */
  57. /*-------------------------------------------------------------*/
  58.  
  59. void CloseTimer()
  60. {
  61.    register struct timerequest *t = &TimerIO;
  62.  
  63.    if ( timerON )
  64.       AbortIO( t );
  65.  
  66.    CloseDevice( t );
  67.    DeletePort( TimerPort );
  68.    TimerPort = NULL;
  69. }
  70.  
  71. /*-------------------------------------------------------------*/
  72. /*    GetTimerSigBit: return Timer signal bit               */
  73. /*-------------------------------------------------------------*/
  74.  
  75. int GetTimerSigBit()
  76. {
  77.    return TimerPort->mp_SigBit;
  78. }
  79.  
  80. /*-------------------------------------------------------------*/
  81. /*    StartTimer: launch the timer.                   */
  82. /*-------------------------------------------------------------*/
  83.  
  84. void StartTimer(seconds, micros)
  85. ULONG seconds, micros;
  86. {
  87.    register struct timerequest *t = &TimerIO;
  88.  
  89.    if ( timerON )
  90.      {
  91.     AbortIO( t );
  92.     (void) GetMsg( TimerPort );
  93.     timerON = FALSE;
  94.         timerExpired = TRUE;
  95.      }
  96.  
  97.    t->tr_time.tv_secs = seconds;
  98.    t->tr_time.tv_micro = micros;
  99.    t->tr_node.io_Command = TR_ADDREQUEST;
  100.    t->tr_node.io_Flags = IOF_QUICK;
  101.    t->tr_node.io_Error = 0;
  102.    t->tr_node.io_Message.mn_ReplyPort = TimerPort;
  103.    SendIO( t );
  104.    timerExpired = FALSE;
  105.    timerON = TRUE;
  106. }
  107.  
  108. /*-------------------------------------------------------------*/
  109. /*    TimerExpired: returns TRUE if timer expired.           */
  110. /*-------------------------------------------------------------*/
  111.  
  112. BOOL TimerExpired()
  113. {
  114.    if ( timerON && ( CheckIO( &TimerIO.tr_node ) == NULL) )
  115.       return FALSE;
  116.  
  117.    (void)GetMsg( TimerPort );
  118.    timerExpired = TRUE;
  119.    timerON = FALSE;
  120.  
  121.    return timerExpired;
  122. }
  123.  
  124.