
#define  TIMER 1
#include "globals.h"

extern struct Task *FindTask(), *MakeTask();

int Open_Timer()    /* Open the timer device */
{
   int error;

   TimerMsgPort.mp_SigBit = NULL;

   if ((error = OpenDevice(TIMERNAME, (long)UNIT_VBLANK, &TimerIO, 0L)) != 0)
      return(error);

   /* Set up the message port in the I/O request */

   TimerMsgPort.mp_Node.ln_Type = NT_MSGPORT;
   TimerMsgPort.mp_Node.ln_Name = "comm-timer";
   TimerMsgPort.mp_Flags        = 0;
   TimerMsgPort.mp_SigBit       = AllocSignal(-1L);
   TimerMsgPort.mp_SigTask      = FindTask(0L);

   AddPort(&TimerMsgPort);

   TimerIO.tr_node.io_Message.mn_ReplyPort = &TimerMsgPort;
   return(0);
}

Close_Timer()
{
   CloseDevice(&TimerIO);
   RemPort(&TimerMsgPort);
}

StartTimer(seconds, micros)
ULONG seconds, micros;
{
   TimerIO.tr_node.io_Command = TR_ADDREQUEST;
   TimerIO.tr_node.io_Flags   = IOF_QUICK;
   TimerIO.tr_time.tv_secs    = seconds;
   TimerIO.tr_time.tv_micro   = micros;
   SendIO(&TimerIO);
}

