define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / timer / timervblank.c
blob65ad61ececfc03076ac3b2fcdf759ba741c3209f
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: VBlank server for the timer.device/timer.hidd
6 Lang: english
7 */
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"
15 #undef SysBase
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) {\
25 (d)->tv_secs++;\
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)
36 AROS_USERFUNC_INIT
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);
71 tr = next;
73 else
76 The first request hasn't finished, as all requests are in
77 order, we don't bother searching through the remaining
79 tr = NULL;
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);
102 tr = next;
104 else
107 The first request hasn't finished, as all requests are in
108 order, we don't bother searching through the remaining
110 tr = NULL;
114 return 0;
115 AROS_USERFUNC_EXIT