Mercurial > sdl-ios-xcode
annotate src/timer/nds/SDL_systimer.c @ 2698:e1da92da346c gsoc2008_nds
Clean up.
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Wed, 27 Aug 2008 04:23:38 +0000 |
parents | 0b395a60deff |
children |
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" |
2696 | 31 #include "../SDL_systimer.h" |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
32 |
2696 | 33 /* Data to handle a single periodic alarm */ |
34 static int timer_alive = 0; | |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
35 static Uint32 timer_ticks; |
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 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
38 SDL_StartTicks(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
39 { |
2698 | 40 if (!timer_alive) { |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
41 SDL_SYS_TimerInit(); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
42 SDL_SYS_StartTimer(); |
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 timer_ticks = 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
46 } |
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 Uint32 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
49 SDL_GetTicks(void) |
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 return timer_ticks; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
52 } |
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 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
55 SDL_Delay(Uint32 ms) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
56 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
57 Uint32 start = SDL_GetTicks(); |
2698 | 58 while (timer_alive) { |
59 if ((SDL_GetTicks() - start) >= ms) | |
60 break; | |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
61 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
62 } |
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 |
2698 | 75 void |
76 NDS_TimerInterrupt(void) | |
77 { | |
78 timer_ticks++; | |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
79 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
80 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
81 /* 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
|
82 int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
83 SDL_SYS_TimerInit(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
84 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
85 timer_alive = 1; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
86 timer_ticks = 0; |
2696 | 87 TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ; |
88 TIMER_DATA(3) = TIMER_FREQ_1024(1000); | |
89 irqSet(IRQ_TIMER3, NDS_TimerInterrupt); | |
90 irqEnable(IRQ_TIMER3); | |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
91 return 0; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
92 } |
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 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
95 SDL_SYS_TimerQuit(void) |
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 if (timer_alive) { |
2696 | 98 TIMER_CR(3) = 0; |
2683
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 timer_alive = 0; |
2696 | 101 irqDisable(IRQ_TIMER3); |
2683
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 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
104 int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
105 SDL_SYS_StartTimer(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
106 { |
2696 | 107 TIMER_CR(3) |= TIMER_ENABLE; |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
108 return 0; |
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 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
111 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
112 SDL_SYS_StopTimer(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
113 { |
2696 | 114 TIMER_CR(3) &= ~TIMER_ENABLE; |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
115 return; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
116 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
117 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
118 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
119 #endif /* SDL_TIMER_NDS */ |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
120 /* vi: set ts=4 sw=4 expandtab: */ |