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