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 <proto/exec.h>
11 #include <proto/timer.h>
12 #include <aros/debug.h>
14 #include "timer_intern.h"
18 This is a slightly faster version of AddTime() that we use here. It
19 also saves the function call overhead...
21 #define FastAddTime(d, s)\
22 (d)->tv_micro += (s)->tv_micro;\
23 (d)->tv_secs += (s)->tv_secs;\
24 if((d)->tv_micro > 999999) {\
26 (d)->tv_micro -= 1000000;\
29 AROS_UFH4(ULONG
, VBlankInt
,
30 AROS_UFHA(ULONG
, dummy
, A0
),
31 AROS_UFHA(struct TimerBase
*, TimerBase
, A1
),
32 AROS_UFHA(ULONG
, dummy2
, A5
),
33 AROS_UFHA(struct ExecBase
*, SysBase
, A6
)
38 struct timerequest
*tr
, *next
;
41 Firstly increment the current time. No need to Disable() here as
42 there are no other interrupts that are allowed to interrupt us
43 that can do anything with this.
45 FastAddTime(&TimerBase
->tb_CurrentTime
, &TimerBase
->tb_VBlankTime
);
46 FastAddTime(&TimerBase
->tb_Elapsed
, &TimerBase
->tb_VBlankTime
);
48 TimerBase
->tb_ticks_total
++;
51 Go through the "wait for x seconds" list and return requests
52 that have completed. A completed request is one whose time
53 is less than that of the elapsed time.
55 tr
= (struct timerequest
*)TimerBase
->tb_Lists
[TL_VBLANK
].mlh_Head
;
57 while(tr
&& ((struct Node
*)tr
)->ln_Succ
!= NULL
)
59 if( (tr
->tr_time
.tv_secs
< TimerBase
->tb_Elapsed
.tv_secs
)
60 || ( (tr
->tr_time
.tv_secs
<= TimerBase
->tb_Elapsed
.tv_secs
)
61 && (tr
->tr_time
.tv_micro
< TimerBase
->tb_Elapsed
.tv_micro
))
64 /* This request has finished */
65 next
= (struct timerequest
*)tr
->tr_node
.io_Message
.mn_Node
.ln_Succ
;
66 Remove((struct Node
*)tr
);
67 tr
->tr_time
.tv_secs
= tr
->tr_time
.tv_micro
= 0;
68 tr
->tr_node
.io_Error
= 0;
69 ReplyMsg((struct Message
*)tr
);
76 The first request hasn't finished, as all requests are in
77 order, we don't bother searching through the remaining
84 The other this is the "wait until a specified time". Here a request
85 is complete if the time we are waiting for is before the current time.
87 tr
= (struct timerequest
*)TimerBase
->tb_Lists
[TL_WAITVBL
].mlh_Head
;
89 while(tr
&& ((struct Node
*)tr
)->ln_Succ
!= NULL
)
91 if( (tr
->tr_time
.tv_secs
<= TimerBase
->tb_CurrentTime
.tv_secs
)
92 && (tr
->tr_time
.tv_micro
< TimerBase
->tb_CurrentTime
.tv_micro
)
95 /* This request has finished */
96 next
= (struct timerequest
*)tr
->tr_node
.io_Message
.mn_Node
.ln_Succ
;
97 Remove((struct Node
*)tr
);
98 tr
->tr_time
.tv_secs
= tr
->tr_time
.tv_micro
= 0;
99 tr
->tr_node
.io_Error
= 0;
100 ReplyMsg((struct Message
*)tr
);
107 The first request hasn't finished, as all requests are in
108 order, we don't bother searching through the remaining