Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Timers work now.
  • Loading branch information
Darren Alton committed Aug 18, 2008
1 parent 9f8db75 commit 0d9edf0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Makefile.ds
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion include/SDL_config_nintendods.h
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions src/timer/nds/SDL_systimer.c
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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 */
Expand All @@ -82,32 +81,34 @@ 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;
}

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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/video/nds/SDL_ndsrender.c
Expand Up @@ -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;
}

Expand Down
27 changes: 9 additions & 18 deletions test/nds-test-progs/general/source/main.c
Expand Up @@ -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...");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0d9edf0

Please sign in to comment.