aboutsummaryrefslogtreecommitdiff
path: root/TIMER.C
blob: ecfc6c9153bb81f09090f9dbec7193bc3d07ccb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/****************************************************************************/
/* timer.c  -- implements timer 	 	                           */
/*                                                                          */
/*                                                                          */
/****************************************************************************/
#include <system.h>
#include <librarie\dos.h>

#define NO 0
#define YES 1

/****************************************************************************/
/* InitTimer()                                                              */
/*                                                                          */
/* Initialize the timer device                                              */
/*                                                                          */
/****************************************************************************/

BOOL InitTimer(timermsg) struct timerequest *timermsg; {
    LONG error;
    struct MsgPort *timerport = NULL;    
    /* --- Create the timer message and port --- */
    timerport = (struct MsgPort *)CreatePort(0,0);
    if (timerport == NULL) return(NO);
    timermsg->tr_node.io_Message.mn_ReplyPort = timerport;
    error = OpenDevice(TIMERNAME,UNIT_VBLANK,timermsg,0);
    return ((BOOL)(error==0));
    }

/****************************************************************************/
/* SetTimer()                                                               */
/*                                                                          */
/* Set the timer so we will be awakened later on                            */
/*                                                                          */
/****************************************************************************/
SetTimer(timermsg,sec,micro) 
    struct timerequest *timermsg;ULONG sec,micro;   
    {
    timermsg->tr_node.io_Command=TR_ADDREQUEST;
    timermsg->tr_time.tv_secs=sec;
    timermsg->tr_time.tv_micro=micro;
    SendIO(timermsg);
    }

/****************************************************************************/
/* KillTimer()                                                              */
/*                                                                          */
/* Free storage from timerport				                   */
/*                                                                          */
/****************************************************************************/
KillTimer(timermsg) struct timerequest *timermsg; {
    struct MsgPort *timerport = timermsg->tr_node.io_Message.mn_ReplyPort;
    if (timerport!=NULL) DeletePort(timerport);
    timermsg->tr_node.io_Message.mn_ReplyPort = NULL;
    }

TimerSigBit(timermsg) struct timerequest *timermsg; {
    return(1 << timermsg->tr_node.io_Message.mn_ReplyPort->mp_SigBit);
    }

struct IntuiMessage *GetTimerMsg(timermsg) struct timerequest *timermsg; {
    return((struct IntuiMessage *)GetMsg(timermsg->tr_node.io_Message.mn_ReplyPort));
    }