From 0d9edf04a86c15c0b2a3a04c8431b49aa2ceaca0 Mon Sep 17 00:00:00 2001 From: Darren Alton Date: Mon, 18 Aug 2008 07:29:52 +0000 Subject: [PATCH] Timers work now. --- Makefile.ds | 2 +- include/SDL_config_nintendods.h | 2 +- src/timer/nds/SDL_systimer.c | 25 +++++++++++---------- src/video/nds/SDL_ndsrender.c | 3 +-- test/nds-test-progs/general/source/main.c | 27 ++++++++--------------- 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Makefile.ds b/Makefile.ds index 39d5734e0..573f007f6 100644 --- a/Makefile.ds +++ b/Makefile.ds @@ -67,7 +67,7 @@ src/thread/nds/SDL_syscond.c \ src/thread/nds/SDL_sysmutex.c \ src/thread/nds/SDL_syssem.c \ src/thread/nds/SDL_systhread.c \ -src/timer/dummy/SDL_systimer.c \ +src/timer/nds/SDL_systimer.c \ src/timer/SDL_timer.c \ src/video/nds/SDL_ndsevents.c \ src/video/nds/SDL_ndsrender.c \ diff --git a/include/SDL_config_nintendods.h b/include/SDL_config_nintendods.h index 8db44ea3d..a57f999ff 100644 --- a/include/SDL_config_nintendods.h +++ b/include/SDL_config_nintendods.h @@ -110,7 +110,7 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t; #define SDL_THREADS_DISABLED 1 /* Enable various timer systems */ -#define SDL_TIMERS_DISABLED 1 +#define SDL_TIMER_NDS 1 /* Enable various video drivers */ #define SDL_VIDEO_DRIVER_NDS 1 diff --git a/src/timer/nds/SDL_systimer.c b/src/timer/nds/SDL_systimer.c index 41ca82d89..23775c5a0 100644 --- a/src/timer/nds/SDL_systimer.c +++ b/src/timer/nds/SDL_systimer.c @@ -28,7 +28,10 @@ #include "SDL_timer.h" #include "../SDL_timer_c.h" +#include "../SDL_systimer.h" +/* Data to handle a single periodic alarm */ +static int timer_alive = 0; static Uint32 timer_ticks; void @@ -57,10 +60,6 @@ SDL_Delay(Uint32 ms) } } -/* Data to handle a single periodic alarm */ -static int timer_alive = 0; -static int timer_ticks = 0; - static int RunTimer(void *unused) { @@ -72,8 +71,8 @@ RunTimer(void *unused) return (0); } -void NDS_TimerInterrupt() { - printf("timer irq\n"); +void NDS_TimerInterrupt(void) { + timer_ticks++; } /* This is only called if the event thread is not running */ @@ -82,9 +81,10 @@ SDL_SYS_TimerInit(void) { timer_alive = 1; timer_ticks = 0; - TIMER_CR(0) = TIMER_DIV_1024 | TIMER_IRQ_REQ; - TIMER_DATA(0) = TIMER_FREQ_1024(1000); - irqSet(IRQ_TIMER1, NDS_TimerInterrupt); + TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ; + TIMER_DATA(3) = TIMER_FREQ_1024(1000); + irqSet(IRQ_TIMER3, NDS_TimerInterrupt); + irqEnable(IRQ_TIMER3); return 0; } @@ -92,22 +92,23 @@ void SDL_SYS_TimerQuit(void) { if (timer_alive) { - TIMER_CR(0) = 0; + TIMER_CR(3) = 0; } timer_alive = 0; + irqDisable(IRQ_TIMER3); } int SDL_SYS_StartTimer(void) { - TIMER_CR(0) |= TIMER_ENABLE; + TIMER_CR(3) |= TIMER_ENABLE; return 0; } void SDL_SYS_StopTimer(void) { - TIMER_CR(0) &= ~TIMER_ENABLE; + TIMER_CR(3) &= ~TIMER_ENABLE; return; } diff --git a/src/video/nds/SDL_ndsrender.c b/src/video/nds/SDL_ndsrender.c index aa3a6b999..e35ac204c 100644 --- a/src/video/nds/SDL_ndsrender.c +++ b/src/video/nds/SDL_ndsrender.c @@ -656,8 +656,7 @@ NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Color * colors, int firstcolor, int ncolors) { NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; - TRACE("+NDS_GetTexturePalette\n"); - TRACE("-NDS_GetTexturePalette\n"); + TRACE("!NDS_GetTexturePalette\n"); return 0; } diff --git a/test/nds-test-progs/general/source/main.c b/test/nds-test-progs/general/source/main.c index 6a46897ca..4f02b8872 100755 --- a/test/nds-test-progs/general/source/main.c +++ b/test/nds-test-progs/general/source/main.c @@ -32,7 +32,7 @@ int main(void) { SDL_Surface *screen; SDL_Joystick *stick; SDL_Event event; - SDL_Rect rect = {8,8,240,176}; + SDL_Rect rect = {0,0,256,192}; int i; consoleDemoInit(); puts("Hello world! Initializing FAT..."); @@ -68,23 +68,14 @@ int main(void) { while(SDL_PollEvent(&event)) switch(event.type) { case SDL_JOYBUTTONDOWN: - switch(event.jbutton.which) { - case 0: - SDL_FillRect(screen, &rect, RGB15(31,0,0)|0x8000); - break; - case 1: - SDL_FillRect(screen, &rect, RGB15(0,31,0)|0x8000); - break; - case 2: - SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000); - break; - case 3: - SDL_FillRect(screen, &rect, RGB15(0,0,0)|0x8000); - break; - default: break; - } - printf("joy_%d, at %d\n", event.jbutton.which, SDL_GetTicks()); - SDL_Flip(screen); + SDL_FillRect(screen, &rect, (u16)rand()|0x8000); + SDL_Flip(screen); + if(rect.w > 8) { + rect.x += 4; rect.y += 3; + rect.w -= 8; rect.h -= 6; + } + printf("button %d pressed at %d ticks\n", + event.jbutton.which, SDL_GetTicks()); break; case SDL_QUIT: SDL_Quit(); return 0; default: break;