comparison 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
comparison
equal deleted inserted replaced
2682:f7594fc66bda 2683:e858ac8868b6
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
32 static Uint32 timer_ticks;
33
34 void
35 SDL_StartTicks(void)
36 {
37 if(!timer_alive) {
38 SDL_SYS_TimerInit();
39 SDL_SYS_StartTimer();
40 }
41
42 timer_ticks = 0;
43 }
44
45 Uint32
46 SDL_GetTicks(void)
47 {
48 return timer_ticks;
49 }
50
51 void
52 SDL_Delay(Uint32 ms)
53 {
54 Uint32 start = SDL_GetTicks();
55 while(timer_alive) {
56 if((SDL_GetTicks() - start) >= ms) break;
57 }
58 }
59
60 /* Data to handle a single periodic alarm */
61 static int timer_alive = 0;
62 static int timer_ticks = 0;
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 NDS_TimerInterrupt() {
76 printf("timer irq\n");
77 }
78
79 /* This is only called if the event thread is not running */
80 int
81 SDL_SYS_TimerInit(void)
82 {
83 timer_alive = 1;
84 timer_ticks = 0;
85 TIMER_CR(0) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
86 TIMER_DATA(0) = TIMER_FREQ_1024(1000);
87 irqSet(IRQ_TIMER1, NDS_TimerInterrupt);
88 return 0;
89 }
90
91 void
92 SDL_SYS_TimerQuit(void)
93 {
94 if (timer_alive) {
95 TIMER_CR(0) = 0;
96 }
97 timer_alive = 0;
98 }
99
100 int
101 SDL_SYS_StartTimer(void)
102 {
103 TIMER_CR(0) |= TIMER_ENABLE;
104 return 0;
105 }
106
107 void
108 SDL_SYS_StopTimer(void)
109 {
110 TIMER_CR(0) &= ~TIMER_ENABLE;
111 return;
112 }
113
114
115 #endif /* SDL_TIMER_NDS */
116 /* vi: set ts=4 sw=4 expandtab: */