Mercurial > sdl-ios-xcode
annotate src/timer/nds/SDL_systimer.c @ 2697:c9121b04cffa gsoc2008_nds
Some more work on the audio driver.
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Thu, 21 Aug 2008 12:38:21 +0000 |
parents | 0b395a60deff |
children | e1da92da346c |
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 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
40 if(!timer_alive) { |
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(); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
58 while(timer_alive) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
59 if((SDL_GetTicks() - start) >= ms) break; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
60 } |
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 static int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
64 RunTimer(void *unused) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
65 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
66 while (timer_alive) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
67 if (SDL_timer_running) { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
68 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
69 SDL_Delay(1); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
70 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
71 return (0); |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
72 } |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
73 |
2696 | 74 void NDS_TimerInterrupt(void) { |
75 timer_ticks++; | |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
76 } |
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 /* 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
|
79 int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
80 SDL_SYS_TimerInit(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
81 { |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
82 timer_alive = 1; |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
83 timer_ticks = 0; |
2696 | 84 TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ; |
85 TIMER_DATA(3) = TIMER_FREQ_1024(1000); | |
86 irqSet(IRQ_TIMER3, NDS_TimerInterrupt); | |
87 irqEnable(IRQ_TIMER3); | |
2683
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) { |
2696 | 95 TIMER_CR(3) = 0; |
2683
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; |
2696 | 98 irqDisable(IRQ_TIMER3); |
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 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
101 int |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
102 SDL_SYS_StartTimer(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
103 { |
2696 | 104 TIMER_CR(3) |= TIMER_ENABLE; |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
105 return 0; |
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 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
108 void |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
109 SDL_SYS_StopTimer(void) |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
110 { |
2696 | 111 TIMER_CR(3) &= ~TIMER_ENABLE; |
2683
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
112 return; |
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 |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
116 #endif /* SDL_TIMER_NDS */ |
e858ac8868b6
Ongoing video render work; initial work on NDS Timers.
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
117 /* vi: set ts=4 sw=4 expandtab: */ |