diff --git a/Makefile.ds b/Makefile.ds index eccc78326..180178e63 100644 --- a/Makefile.ds +++ b/Makefile.ds @@ -22,46 +22,58 @@ TARGET = libSDL.a #endif #CFLAGS=$(DEFS) -Iinclude -CFLAGS = -mthumb -mthumb-interwork \ - -march=armv5te -mtune=arm946e-s \ - -O2 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ - -DARM9 -D__NDS__ -I$(DEVKITPRO)/libnds/include -DENABLE_NDS -DNO_SIGNAL_H -DDISABLE_THREADS -DPACKAGE=\"SDL\" -DVERSION=\"1.3\" -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 \ - -Iinclude -Isrc -Isrc/audio -Isrc/cdrom -Isrc/endian -Isrc/events -Isrc/joystick -Isrc/thread/nds -Isrc/thread -Isrc/timer -Isrc/video +CFLAGS = -mthumb -mthumb-interwork \ + -march=armv5te -mtune=arm946e-s \ + -O2 -Wall -Wwrite-strings -Wpointer-arith \ + -DARM9 -D__NDS__ -I$(DEVKITPRO)/libnds/include -DENABLE_NDS -DNO_SIGNAL_H -DDISABLE_THREADS -DPACKAGE=\"SDL\" -DVERSION=\"1.3\" -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 \ + -Iinclude -Isrc -Isrc/audio -Isrc/cdrom -Isrc/endian -Isrc/events -Isrc/joystick -Isrc/thread/nds -Isrc/thread -Isrc/timer -Isrc/video #src/audio/disk/SDL_diskaudio.c \ #src/audio/dummy/SDL_dummyaudio.c \ SRCS = \ src/SDL.c \ +src/SDL_assert.c \ src/SDL_compat.c \ src/SDL_error.c \ src/SDL_fatal.c \ -src/SDL_assert.c \ -src/audio/nds/SDL_ndsaudio.c \ +src/SDL_hints.c \ +src/SDL_log.c \ +src/atomic/nds/SDL_atomic.c \ +src/atomic/SDL_atomic.c \ src/audio/SDL_audio.c \ src/audio/SDL_audiocvt.c \ src/audio/SDL_audiodev.c \ src/audio/SDL_audiotypecvt.c \ src/audio/SDL_mixer.c \ -src/audio/SDL_mixer_m68k.c \ src/audio/SDL_mixer_MMX.c \ src/audio/SDL_mixer_MMX_VC.c \ +src/audio/SDL_mixer_m68k.c \ src/audio/SDL_wave.c \ -src/cdrom/dummy/SDL_syscdrom.c \ -src/cdrom/SDL_cdrom.c \ +src/audio/nds/SDL_ndsaudio.c \ src/cpuinfo/SDL_cpuinfo.c \ src/events/SDL_events.c \ src/events/SDL_keyboard.c \ src/events/SDL_mouse.c \ src/events/SDL_quit.c \ +src/events/SDL_touch.c \ src/events/SDL_windowevents.c \ +src/events/nds/SDL_ndsgesture.c \ src/file/SDL_rwops.c \ -src/power/SDL_power.c \ -src/power/nds/SDL_syspower.c \ src/haptic/SDL_haptic.c \ src/haptic/nds/SDL_syshaptic.c \ -src/joystick/nds/SDL_sysjoystick.c \ src/joystick/SDL_joystick.c \ +src/joystick/nds/SDL_sysjoystick.c \ +src/power/SDL_power.c \ +src/power/nds/SDL_syspower.c \ +src/render/SDL_render.c \ +src/render/SDL_yuv_sw.c \ +src/render/software/SDL_render_sw.c \ +src/render/software/SDL_blendpoint.c \ +src/render/software/SDL_drawline.c \ +src/render/software/SDL_blendline.c \ +src/render/software/SDL_blendfillrect.c \ +src/render/software/SDL_drawpoint.c \ src/stdlib/SDL_getenv.c \ src/stdlib/SDL_iconv.c \ src/stdlib/SDL_malloc.c \ @@ -73,37 +85,29 @@ 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/nds/SDL_systimer.c \ src/timer/SDL_timer.c \ -src/video/nds/SDL_ndsevents.c \ -src/video/nds/SDL_ndsrender.c \ -src/video/nds/SDL_ndsvideo.c \ -src/video/dummy/SDL_nullevents.c \ -src/video/dummy/SDL_nullrender.c \ -src/video/dummy/SDL_nullvideo.c \ +src/timer/nds/SDL_systimer.c \ +src/video/SDL_RLEaccel.c \ +src/video/SDL_blit.c \ src/video/SDL_blit_0.c \ src/video/SDL_blit_1.c \ src/video/SDL_blit_A.c \ -src/video/SDL_blit_auto.c \ -src/video/SDL_blit.c \ -src/video/SDL_blit_copy.c \ src/video/SDL_blit_N.c \ +src/video/SDL_blit_auto.c \ +src/video/SDL_blit_copy.c \ src/video/SDL_blit_slow.c \ src/video/SDL_bmp.c \ -src/video/SDL_drawline.c \ -src/video/SDL_drawpoint.c \ src/video/SDL_fillrect.c \ -src/video/SDL_gamma.c \ src/video/SDL_pixels.c \ src/video/SDL_rect.c \ -src/video/SDL_renderer_gl.c \ -src/video/SDL_renderer_sw.c \ -src/video/SDL_RLEaccel.c \ src/video/SDL_stretch.c \ src/video/SDL_surface.c \ src/video/SDL_video.c \ -src/video/SDL_yuv_mmx.c \ -src/video/SDL_yuv_sw.c \ +src/video/dummy/SDL_nullevents.c \ +src/video/dummy/SDL_nullvideo.c \ +src/video/nds/SDL_ndsevents.c \ +src/video/nds/SDL_ndsrender.c \ +src/video/nds/SDL_ndsvideo.c \ OBJS = $(SRCS:.c=.o) @@ -113,7 +117,7 @@ test/nds-test-progs/sprite/sprite.nds \ test/nds-test-progs/sprite2/sprite2.nds \ -all: $(TARGET) +all: $(TARGET) install nds_test $(TARGET): copy_config \ $(OBJS) @@ -126,7 +130,9 @@ install: $(TARGET) @cp include/*.h $(DEVKITPRO)/libnds/include/SDL/ nds_test: - $(MAKE) -C test/nds-test-progs + $(MAKE) -C test/nds-test-progs/general +# $(MAKE) -C test/nds-test-progs/sprite +# $(MAKE) -C test/nds-test-progs/sprite2 copy_config: @cp include/SDL_config.h.default include/SDL_config.h diff --git a/include/SDL_config_nintendods.h b/include/SDL_config_nintendods.h index 84ca592e3..77845f146 100644 --- a/include/SDL_config_nintendods.h +++ b/include/SDL_config_nintendods.h @@ -46,6 +46,8 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t; #endif #endif /* !_STDINT_H_ && !HAVE_STDINT_H */ +#define SIZEOF_VOIDP 4 + #define SDL_HAS_64BIT_TYPE 1 /* Useful headers */ @@ -113,9 +115,12 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t; /* Enable various video drivers */ #define SDL_VIDEO_DRIVER_NDS 1 -/*#define SDL_VIDEO_DRIVER_DUMMY 1 TODO: uncomment this later*/ +#define SDL_VIDEO_RENDER_NDS 1 /* Enable system power support */ #define SDL_POWER_NINTENDODS 1 +/* Enable haptic support */ +#define SDL_HAPTIC_NDS 1 + #endif /* _SDL_config_nintendods_h */ diff --git a/src/SDL.c b/src/SDL.c index 51bdf5f53..6c4f7b0b0 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -266,6 +266,8 @@ SDL_GetPlatform() return "Mac OS X"; #elif __NETBSD__ return "NetBSD"; +#elif __NDS__ + return "Nintendo DS"; #elif __OPENBSD__ return "OpenBSD"; #elif __OS2__ diff --git a/src/atomic/nds/SDL_atomic.c b/src/atomic/nds/SDL_atomic.c new file mode 100644 index 000000000..c4ee7701b --- /dev/null +++ b/src/atomic/nds/SDL_atomic.c @@ -0,0 +1,469 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org + + Contributed by Bob Pendleton, bob@pendleton.com +*/ + +#include "SDL_stdinc.h" +#include "SDL_atomic.h" + +#include "SDL_error.h" + +/* + This file provides 32, and 64 bit atomic operations. If the + operations are provided by the native hardware and operating system + they are used. If they are not then the operations are emulated + using the SDL spin lock operations. If spin lock can not be + implemented then these functions must fail. +*/ + +/* + DUMMY VERSION. + + This version of the code assumes there is no support for atomic + operations. Therefore, every function sets the SDL error + message. Oddly enough, if you only have one thread then this + version actuallys works. +*/ + +/* + Native spinlock routines. Because this is the dummy implementation + these will always call SDL_SetError() and do nothing. +*/ + +void +SDL_AtomicLock(SDL_SpinLock *lock) +{ + SDL_SetError("SDL_atomic.c: is not implemented on this platform"); +} + +void +SDL_AtomicUnlock(SDL_SpinLock *lock) +{ + SDL_SetError("SDL_atomic.c: is not implemented on this platform"); +} + +/* + Note that platform specific versions can be built from this version + by changing the #undefs to #defines and adding platform specific + code. +*/ + +#undef nativeTestThenSet32 +#undef nativeClear32 +#undef nativeFetchThenIncrement32 +#undef nativeFetchThenDecrement32 +#undef nativeFetchThenAdd32 +#undef nativeFetchThenSubtract32 +#undef nativeIncrementThenFetch32 +#undef nativeDecrementThenFetch32 +#undef nativeAddThenFetch32 +#undef nativeSubtractThenFetch32 + +#undef nativeTestThenSet64 +#undef nativeClear64 +#undef nativeFetchThenIncrement64 +#undef nativeFetchThenDecrement64 +#undef nativeFetchThenAdd64 +#undef nativeFetchThenSubtract64 +#undef nativeIncrementThenFetch64 +#undef nativeDecrementThenFetch64 +#undef nativeAddThenFetch64 +#undef nativeSubtractThenFetch64 + +/* + If any of the operations are not provided then we must emulate some + of them. That means we need a nice implementation of spin locks + that avoids the "one big lock" problem. We use a vector of spin + locks and pick which one to use based on the address of the operand + of the function. + + To generate the index of the lock we first shift by 3 bits to get + rid on the zero bits that result from 32 and 64 bit allignment of + data. We then mask off all but 5 bits and use those 5 bits as an + index into the table. + + Picking the lock this way insures that accesses to the same data at + the same time will go to the same lock. OTOH, accesses to different + data have only a 1/32 chance of hitting the same lock. That should + pretty much eliminate the chances of several atomic operations on + different data from waiting on the same "big lock". If it isn't + then the table of locks can be expanded to a new size so long as + the new size is a power of two. +*/ + +static SDL_SpinLock locks[32] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, +}; + +static __inline__ void +privateWaitLock(volatile void *ptr) +{ +#if SIZEOF_VOIDP == 4 + Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f); +#elif SIZEOF_VOIDP == 8 + Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f); +#endif + + SDL_AtomicLock(&locks[index]); +} + +static __inline__ void +privateUnlock(volatile void *ptr) +{ +#if SIZEOF_VOIDP == 4 + Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f); +#elif SIZEOF_VOIDP == 8 + Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f); +#endif + + SDL_AtomicUnlock(&locks[index]); +} + +/* 32 bit atomic operations */ + +SDL_bool +SDL_AtomicTestThenSet32(volatile Uint32 * ptr) +{ +#ifdef nativeTestThenSet32 +#else + SDL_bool result = SDL_FALSE; + + privateWaitLock(ptr); + result = (*ptr == 0); + if (result) + { + *ptr = 1; + } + privateUnlock(ptr); + + return result; +#endif +} + +void +SDL_AtomicClear32(volatile Uint32 * ptr) +{ +#ifdef nativeClear32 +#else + privateWaitLock(ptr); + *ptr = 0; + privateUnlock(ptr); + + return; +#endif +} + +Uint32 +SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr) +{ +#ifdef nativeFetchThenIncrement32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr)+= 1; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint32 +SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr) +{ +#ifdef nativeFetchThenDecrement32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr) -= 1; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint32 +SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value) +{ +#ifdef nativeFetchThenAdd32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr)+= value; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint32 +SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value) +{ +#ifdef nativeFetchThenSubtract32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr)-= value; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint32 +SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr) +{ +#ifdef nativeIncrementThenFetch32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + (*ptr)+= 1; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint32 +SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr) +{ +#ifdef nativeDecrementThenFetch32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + (*ptr)-= 1; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint32 +SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value) +{ +#ifdef nativeAddThenFetch32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + (*ptr)+= value; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint32 +SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value) +{ +#ifdef nativeSubtractThenFetch32 +#else + Uint32 tmp = 0; + + privateWaitLock(ptr); + (*ptr)-= value; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} + +/* 64 bit atomic operations */ +#ifdef SDL_HAS_64BIT_TYPE + +SDL_bool +SDL_AtomicTestThenSet64(volatile Uint64 * ptr) +{ +#ifdef nativeTestThenSet64 +#else + SDL_bool result = SDL_FALSE; + + privateWaitLock(ptr); + result = (*ptr == 0); + if (result) + { + *ptr = 1; + } + privateUnlock(ptr); + + return result; +#endif +} + +void +SDL_AtomicClear64(volatile Uint64 * ptr) +{ +#ifdef nativeClear64 +#else + privateWaitLock(ptr); + *ptr = 0; + privateUnlock(ptr); + + return; +#endif +} + +Uint64 +SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr) +{ +#ifdef nativeFetchThenIncrement64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr)+= 1; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint64 +SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr) +{ +#ifdef nativeFetchThenDecrement64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr) -= 1; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint64 +SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value) +{ +#ifdef nativeFetchThenAdd64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr)+= value; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint64 +SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value) +{ +#ifdef nativeFetchThenSubtract64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + tmp = *ptr; + (*ptr)-= value; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint64 +SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr) +{ +#ifdef nativeIncrementThenFetch64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + (*ptr)+= 1; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint64 +SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr) +{ +#ifdef nativeDecrementThenFetch64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + (*ptr)-= 1; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint64 +SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value) +{ +#ifdef nativeAddThenFetch64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + (*ptr)+= value; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} + +Uint64 +SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value) +{ +#ifdef nativeSubtractThenFetch64 +#else + Uint64 tmp = 0; + + privateWaitLock(ptr); + (*ptr)-= value; + tmp = *ptr; + privateUnlock(ptr); + + return tmp; +#endif +} +#endif + diff --git a/src/audio/nds/SDL_ndsaudio.c b/src/audio/nds/SDL_ndsaudio.c index ba7ddd06f..3bb258b52 100644 --- a/src/audio/nds/SDL_ndsaudio.c +++ b/src/audio/nds/SDL_ndsaudio.c @@ -57,11 +57,13 @@ NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture) } } +#if 0 /* set the generic sound parameters */ setGenericSound(22050, /* sample rate */ 127, /* volume */ 64, /* panning/balance */ 0); /* sound format */ +#endif return 1; } @@ -69,13 +71,9 @@ NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture) static void NDSAUD_PlayDevice(_THIS) { - TransferSoundData *sound = SDL_malloc(sizeof(TransferSoundData)); - if (!sound) { - SDL_OutOfMemory(); - } - - playGenericSound(this->hidden->mixbuf, this->hidden->mixlen); #if 0 + playGenericSound(this->hidden->mixbuf, this->hidden->mixlen); + // sound->data = this->hidden->mixbuf;/* pointer to raw audio data */ // sound->len = this->hidden->mixlen; /* size of raw data pointed to above */ // sound->rate = 22050; /* sample rate = 22050Hz */ diff --git a/src/audio/nds/SDL_ndsaudio.h b/src/audio/nds/SDL_ndsaudio.h index 35c8c6c65..81d2412c4 100644 --- a/src/audio/nds/SDL_ndsaudio.h +++ b/src/audio/nds/SDL_ndsaudio.h @@ -32,7 +32,6 @@ struct SDL_PrivateAudioData { - TransferSoundData *sound; /* The file descriptor for the audio device */ Uint8 *mixbuf; Uint32 mixlen; diff --git a/src/events/nds/SDL_ndsgesture.c b/src/events/nds/SDL_ndsgesture.c new file mode 100644 index 000000000..b2b4d71e9 --- /dev/null +++ b/src/events/nds/SDL_ndsgesture.c @@ -0,0 +1,41 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software Founation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#include "SDL_config.h" + +/* No supported under the NDS because of math operations. */ + +#include "SDL_events.h" +#include "SDL_events_c.h" +#include "SDL_gesture_c.h" + +int SDL_GestureAddTouch(SDL_Touch* touch) +{ + return 0; +} + +void SDL_GestureProcessEvent(SDL_Event* event) +{ + return; +} + +/* vi: set ts=4 sw=4 expandtab: */ + diff --git a/src/haptic/nds/SDL_syshaptic.c b/src/haptic/nds/SDL_syshaptic.c index e903c3edb..a464fc9ba 100644 --- a/src/haptic/nds/SDL_syshaptic.c +++ b/src/haptic/nds/SDL_syshaptic.c @@ -26,21 +26,21 @@ #include "SDL_haptic.h" #include "../SDL_syshaptic.h" #include "SDL_joystick.h" -#include #include +#include #define MAX_HAPTICS 1 /* right now only the ezf3in1 (and maybe official rumble pak) are supported and there can only be one of those in at a time (in GBA slot.) */ -SDL_Haptic *nds_haptic = NULL; +static SDL_Haptic *nds_haptic = NULL; -typedef struct +struct haptic_hwdata { enum { NONE, OFFICIAL, EZF3IN1 } type; int pos; -} NDS_HapticData; +}; void @@ -165,7 +165,7 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic) return -1; } - haptic->hwdata = SDL_malloc(sizeof(NDS_HapticData)); + haptic->hwdata = SDL_malloc(sizeof(struct haptic_hwdata)); if (!haptic->hwdata) { SDL_OutOfMemory(); return -1; diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index ef4e9568c..cfb4c23c0 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -60,6 +60,9 @@ static const SDL_RenderDriver *render_drivers[] = { #endif #if SDL_VIDEO_RENDER_DIRECTFB &DirectFB_RenderDriver, +#endif +#if SDL_VIDEO_RENDER_NDS + &NDS_RenderDriver, #endif &SW_RenderDriver #endif /* !SDL_RENDER_DISABLED */ diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index ec4da2eb7..86b955368 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -136,6 +136,9 @@ extern SDL_RenderDriver GLES_RenderDriver; #if SDL_VIDEO_RENDER_DIRECTFB extern SDL_RenderDriver DirectFB_RenderDriver; #endif +#ifdef SDL_VIDEO_RENDER_NDS +extern SDL_RenderDriver NDS_RenderDriver; +#endif extern SDL_RenderDriver SW_RenderDriver; #endif /* !SDL_RENDER_DISABLED */ diff --git a/src/timer/nds/SDL_systimer.c b/src/timer/nds/SDL_systimer.c index 8e72ef621..8eb453ba9 100644 --- a/src/timer/nds/SDL_systimer.c +++ b/src/timer/nds/SDL_systimer.c @@ -28,7 +28,7 @@ #include "SDL_timer.h" - +/* Will wrap afetr 49 days. Shouldn't be an issue. */ static volatile Uint32 timer_ticks; static void @@ -42,10 +42,8 @@ SDL_StartTicks(void) { timer_ticks = 0; - TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ; - TIMER_DATA(3) = TIMER_FREQ_1024(1000); - irqSet(IRQ_TIMER3, NDS_TimerInterrupt); - irqEnable(IRQ_TIMER3); + /* Set timer 2 to fire every ms. */ + timerStart(2, ClockDivider_1024, TIMER_FREQ_1024(1000), NDS_TimerInterrupt); } Uint32 @@ -58,7 +56,7 @@ void SDL_Delay(Uint32 ms) { Uint32 start = SDL_GetTicks(); - while (timer_alive) { + while (1) { if ((SDL_GetTicks() - start) >= ms) break; } diff --git a/src/video/nds/SDL_ndsevents.c b/src/video/nds/SDL_ndsevents.c index b1576a532..850456a38 100644 --- a/src/video/nds/SDL_ndsevents.c +++ b/src/video/nds/SDL_ndsevents.c @@ -45,8 +45,7 @@ NDS_PumpEvents(_THIS) } if (keysHeld() & KEY_TOUCH) { touchPosition t = touchReadXY(); - SDL_SendMouseMotion(0, 0, t.px, t.py, 1); /* last arg is pressure, - hardcoded 1 for now */ + SDL_SendMouseMotion(0, 0, t.px, t.py); } } diff --git a/src/video/nds/SDL_ndsrender.c b/src/video/nds/SDL_ndsrender.c index 5e06494ad..7e3b43fff 100644 --- a/src/video/nds/SDL_ndsrender.c +++ b/src/video/nds/SDL_ndsrender.c @@ -31,8 +31,8 @@ #include "SDL_video.h" #include "../SDL_sysvideo.h" -#include "../SDL_yuv_sw_c.h" -#include "../SDL_renderer_sw.h" +#include "SDL_render.h" +#include "../../render/SDL_sysrender.h" /* SDL NDS renderer implementation */ @@ -40,9 +40,11 @@ static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags); static int NDS_ActivateRenderer(SDL_Renderer * renderer); static int NDS_DisplayModeChanged(SDL_Renderer * renderer); static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); +#if 0 static int NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, void **pixels, int *pitch); +#endif static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch); @@ -50,8 +52,8 @@ static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, int markDirty, void **pixels, int *pitch); static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, - Uint8 b, Uint8 a, const SDL_Rect * rect); +static int NDS_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); static int NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); @@ -149,7 +151,7 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags) } SDL_zerop(data); - renderer->RenderFill = NDS_RenderFill; + renderer->RenderFillRects = NDS_RenderFillRects; renderer->RenderCopy = NDS_RenderCopy; renderer->RenderPresent = NDS_RenderPresent; renderer->DestroyRenderer = NDS_DestroyRenderer; @@ -158,7 +160,7 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->window = window; renderer->driverdata = data; renderer->CreateTexture = NDS_CreateTexture; - renderer->QueryTexturePixels = NDS_QueryTexturePixels; +// renderer->QueryTexturePixels = NDS_QueryTexturePixels; renderer->UpdateTexture = NDS_UpdateTexture; renderer->LockTexture = NDS_LockTexture; renderer->UnlockTexture = NDS_UnlockTexture; @@ -341,7 +343,7 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) bgUpdate(bg3); */ txdat->type = NDSTX_BG; - txdat->pitch = (texture->w) * (bpp / 8); + txdat->pitch = (texture->w) * ((bpp+1) / 8); txdat->bpp = bpp; txdat->rotate = 0; txdat->scale.x = 0x100; @@ -354,7 +356,7 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x, txdat->scale.y); bgSetScroll(txdat->hw_index, txdat->scroll.x, txdat->scroll.y); - bgUpdate(txdat->hw_index); + bgUpdate(); data->bg_taken[whichbg] = 1; /*txdat->size = txdat->dim.pitch * texture->h; */ @@ -372,6 +374,7 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) return 0; } +#if 0 static int NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, void **pixels, int *pitch) @@ -381,6 +384,7 @@ NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, *pitch = txdat->pitch; return 0; } +#endif static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, @@ -433,16 +437,13 @@ NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) } static int -NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, - Uint8 a, const SDL_Rect * rect) +NDS_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count) { NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; - SDL_Rect real_rect = *rect; - u16 color; - int i, j; printf("NDS_RenderFill: stub\n"); - color = RGB8(r, g, b); /* macro in libnds that makes an ARGB1555 pixel */ + /* TODO: make a single-color sprite and stretch it. calculate the "HDX" width modifier of the sprite by: let S be the actual sprite's width (like, 32 pixels for example) diff --git a/src/video/nds/SDL_ndsvideo.c b/src/video/nds/SDL_ndsvideo.c index 0428b0e33..9eaca2111 100644 --- a/src/video/nds/SDL_ndsvideo.c +++ b/src/video/nds/SDL_ndsvideo.c @@ -38,6 +38,8 @@ #include "../SDL_sysvideo.h" #include "../SDL_pixels_c.h" #include "../../events/SDL_events_c.h" +#include "SDL_render.h" +#include "../../render/SDL_sysrender.h" #include "SDL_ndsvideo.h" #include "SDL_ndsevents_c.h" @@ -47,7 +49,8 @@ /* Initialization/Query functions */ static int NDS_VideoInit(_THIS); -static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); +static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, + SDL_DisplayMode *mode); static void NDS_VideoQuit(_THIS); @@ -73,10 +76,7 @@ NDS_CreateDevice(int devindex) device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { SDL_OutOfMemory(); - if (device) { - SDL_free(device); - } - return (0); + return NULL; } /* Set the function pointers */ @@ -101,7 +101,6 @@ int NDS_VideoInit(_THIS) { SDL_DisplayMode mode; - int i; /* simple 256x192x16x60 for now */ mode.w = 256; @@ -113,21 +112,19 @@ NDS_VideoInit(_THIS) if (SDL_AddBasicVideoDisplay(&mode) < 0) { return -1; } - SDL_AddRenderDriver(&_this->displays[0], &NDS_RenderDriver); SDL_zero(mode); - SDL_AddDisplayMode(0, &mode); + SDL_AddDisplayMode(&_this->displays[0], &mode); - powerON(POWER_ALL_2D); - irqInit(); + powerOn(POWER_ALL_2D); irqEnable(IRQ_VBLANK); - NDS_SetDisplayMode(_this, &mode); + NDS_SetDisplayMode(_this, &_this->displays[0], &mode); return 0; } static int -NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) +NDS_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) { /* right now this function is just hard-coded for 256x192 ABGR1555 */ videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_BG_EXT_PALETTE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_1D_BMP | DISPLAY_SPR_1D_BMP_SIZE_256 | /* (try 128 if 256 is trouble.) */ @@ -141,7 +138,7 @@ NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankD(VRAM_D_MAIN_BG_0x06040000); /* not a typo. vram d can't sub */ vramSetBankE(VRAM_E_MAIN_SPRITE); - vramSetBankF(VRAM_F_OBJ_EXT_PALETTE); + vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE); vramSetBankG(VRAM_G_BG_EXT_PALETTE); vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); vramSetBankI(VRAM_I_SUB_SPRITE); diff --git a/test/nds-test-progs/general/source/main.c b/test/nds-test-progs/general/source/main.c index 2bc5e3102..b9c74c0ec 100755 --- a/test/nds-test-progs/general/source/main.c +++ b/test/nds-test-progs/general/source/main.c @@ -82,7 +82,7 @@ main(void) rect.h -= 6; } printf("button %d pressed at %d ticks\n", - event.jbutton.which, SDL_GetTicks()); + event.jbutton.button, SDL_GetTicks()); break; case SDL_QUIT: SDL_Quit();