2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: VBlank server for the timer.device/timer.hidd
8 #include <exec/types.h>
9 #include <exec/execbase.h>
10 #include <hardware/intbits.h>
11 #include <proto/exec.h>
12 #include <proto/timer.h>
13 #include <aros/debug.h>
19 This is a slightly faster version of AddTime() that we use here. It
20 also saves the function call overhead...
22 #define FastAddTime(d, s)\
23 (d)->tv_micro += (s)->tv_micro;\
24 (d)->tv_secs += (s)->tv_secs;\
25 if((d)->tv_micro > 999999) {\
27 (d)->tv_micro -= 1000000;\
30 BOOL
timer_addToWaitList(struct TimerBase
*, struct MinList
*, struct timerequest
*);
32 AROS_UFH4(ULONG
, VBlankInt
,
33 AROS_UFHA(ULONG
, dummy
, A0
),
34 AROS_UFHA(struct TimerBase
*, TimerBase
, A1
),
35 AROS_UFHA(ULONG
, dummy2
, A5
),
36 AROS_UFHA(struct ExecBase
*, SysBase
, A6
)
41 struct timerequest
*tr
, *next
;
43 EClockUpdate(TimerBase
);
46 Go through the "wait for x seconds" list and return requests
47 that have completed. A completed request is one whose time
48 is less than that of the elapsed time.
50 ForeachNodeSafe(&TimerBase
->tb_Lists
[TL_VBLANK
], tr
, next
)
52 if(CmpTime(&TimerBase
->tb_Elapsed
, &tr
->tr_time
) <= 0)
54 if (tr
== &TimerBase
->tb_vblank_timerequest
)
56 struct IntVector
*iv
= &SysBase
->IntVects
[INTB_VERTB
];
62 AROS_UFC5(void, iv
->iv_Code
,
63 AROS_UFCA(ULONG
, 0, D1
),
64 AROS_UFCA(ULONG
, 0, A0
),
65 AROS_UFCA(APTR
, iv
->iv_Data
, A1
),
66 AROS_UFCA(APTR
, iv
->iv_Code
, A5
),
67 AROS_UFCA(struct ExecBase
*, SysBase
, A6
)
71 /* Automatically requeue/reactivate request */
73 Remove((struct Node
*)tr
);
74 tr
->tr_node
.io_Command
= TR_ADDREQUEST
;
75 tr
->tr_time
.tv_secs
= 0;
76 tr
->tr_time
.tv_micro
= 1000000 / SysBase
->VBlankFrequency
;
77 AddTime(&tr
->tr_time
, &TimerBase
->tb_Elapsed
);
79 timer_addToWaitList(TimerBase
, &TimerBase
->tb_Lists
[TL_VBLANK
], tr
);
81 if (--SysBase
->Elapsed
== 0)
83 SysBase
->SysFlags
|= 0x2000;
84 SysBase
->AttnResched
|= 0x80;
90 /* This request has finished */
91 Remove((struct Node
*)tr
);
92 tr
->tr_time
.tv_secs
= tr
->tr_time
.tv_micro
= 0;
93 tr
->tr_node
.io_Error
= 0;
94 ReplyMsg((struct Message
*)tr
);
100 The first request hasn't finished, as all requests are in
101 order, we don't bother searching through the remaining
108 The other this is the "wait until a specified time". Here a request
109 is complete if the time we are waiting for is before the current time.
111 ForeachNodeSafe(&TimerBase
->tb_Lists
[TL_WAITVBL
], tr
, next
)
113 if(CmpTime(&TimerBase
->tb_CurrentTime
, &tr
->tr_time
) <= 0)
115 /* This request has finished */
116 Remove((struct Node
*)tr
);
117 tr
->tr_time
.tv_secs
= tr
->tr_time
.tv_micro
= 0;
118 tr
->tr_node
.io_Error
= 0;
119 ReplyMsg((struct Message
*)tr
);
124 The first request hasn't finished, as all requests are in
125 order, we don't bother searching through the remaining
131 Timer0Setup(TimerBase
);