Mercurial > sdl-ios-xcode
annotate src/timer/nds/SDL_systimer.c @ 2683:e858ac8868b6 gsoc2008_nds
Ongoing video render work; initial work on NDS Timers.
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Fri, 08 Aug 2008 08:22:08 +0000 |
parents | |
children | 0b395a60deff |
rev | line source |
---|---|
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
1 /* |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
4 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
9 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
14 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
18 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
19 Sam Lantinga |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
20 slouken@libsdl.org |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
21 */ |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
23 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
24 #ifdef SDL_TIMER_NDS |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
25 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
26 #include <nds.h> |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
27 #include <nds/timers.h> |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
28 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
29 #include "SDL_timer.h" |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
30 #include "../SDL_timer_c.h" |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
31 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
32 static Uint32 timer_ticks; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
33 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
34 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
35 SDL_StartTicks(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
36 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
37 if(!timer_alive) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
38 SDL_SYS_TimerInit(); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
39 SDL_SYS_StartTimer(); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
40 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
41 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
42 timer_ticks = 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
43 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
44 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
45 Uint32 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
46 SDL_GetTicks(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
47 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
48 return timer_ticks; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
49 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
50 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
51 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
52 SDL_Delay(Uint32 ms) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
53 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
54 Uint32 start = SDL_GetTicks(); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
55 while(timer_alive) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
56 if((SDL_GetTicks() - start) >= ms) break; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
57 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
58 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
59 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
60 /* Data to handle a single periodic alarm */ |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
61 static int timer_alive = 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
62 static int timer_ticks = 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
63 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
64 static int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
65 RunTimer(void *unused) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
66 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
67 while (timer_alive) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
68 if (SDL_timer_running) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
69 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
70 SDL_Delay(1); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
71 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
72 return (0); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
73 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
74 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
75 void NDS_TimerInterrupt() { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
76 printf("timer irq\n"); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
77 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
78 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
79 /* This is only called if the event thread is not running */ |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
80 int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
81 SDL_SYS_TimerInit(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
82 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
83 timer_alive = 1; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
84 timer_ticks = 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
85 TIMER_CR(0) = TIMER_DIV_1024 | TIMER_IRQ_REQ; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
86 TIMER_DATA(0) = TIMER_FREQ_1024(1000); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
87 irqSet(IRQ_TIMER1, NDS_TimerInterrupt); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
88 return 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
89 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
90 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
91 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
92 SDL_SYS_TimerQuit(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
93 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
94 if (timer_alive) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
95 TIMER_CR(0) = 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
96 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
97 timer_alive = 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
98 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
99 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
100 int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
101 SDL_SYS_StartTimer(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
102 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
103 TIMER_CR(0) |= TIMER_ENABLE; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
104 return 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
105 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
106 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
107 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
108 SDL_SYS_StopTimer(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
109 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
110 TIMER_CR(0) &= ~TIMER_ENABLE; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
111 return; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
112 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
113 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
114 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
115 #endif /* SDL_TIMER_NDS */ |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
116 /* vi: set ts=4 sw=4 expandtab: */ |