Mercurial > sdl-ios-xcode
changeset 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
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile.ds Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,129 @@ + +#LibSDL 1.3 porting and enhancements by Darren Alton (lifning) +#LibSDL 1.2.9 DS porting by Troy Davis(GPF) + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment (available from http://www.devkitpro.org). export DEVKITPRO=<path to>devkitPro") +endif +ifeq ($(strip $(DEVKITARM)),) +DEVKITARM = $(DEVKITPRO)/devkitARM +endif +PATH := $(PATH):$(DEVKITARM)/bin + +CC = arm-eabi-gcc +AR = arm-eabi-ar +RANLIB = arm-eabi-ranlib + +#ifdef GL +#DEFS += -DSDL_VIDEO_OPENGL=1 +#TARGET = libSDL_gl.a +#else +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 + +#src/audio/disk/SDL_diskaudio.c \ +#src/audio/dummy/SDL_dummyaudio.c \ + +SRCS = \ +src/SDL.c \ +src/SDL_compat.c \ +src/SDL_error.c \ +src/SDL_fatal.c \ +src/audio/nds/SDL_ndsaudio.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_wave.c \ +src/cdrom/dummy/SDL_syscdrom.c \ +src/cdrom/SDL_cdrom.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_windowevents.c \ +src/file/SDL_rwops.c \ +src/joystick/nds/SDL_sysjoystick.c \ +src/joystick/SDL_joystick.c \ +src/stdlib/SDL_getenv.c \ +src/stdlib/SDL_iconv.c \ +src/stdlib/SDL_malloc.c \ +src/stdlib/SDL_qsort.c \ +src/stdlib/SDL_stdlib.c \ +src/stdlib/SDL_string.c \ +src/thread/SDL_thread.c \ +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/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_slow.c \ +src/video/SDL_bmp.c \ +src/video/SDL_fill.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 \ + +OBJS = $(SRCS:.c=.o) + +TEST = \ +test/nds-test-progs/general/general.nds \ +test/nds-test-progs/sprite/sprite.nds \ +test/nds-test-progs/sprite2/sprite2.nds \ + + +all: $(TARGET) + +$(TARGET): copy_config \ + $(OBJS) + $(AR) rc $(TARGET) $(OBJS) + -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 + +install: $(TARGET) + @cp libSDL.a $(DEVKITPRO)/libnds/lib/ + @mkdir -p $(DEVKITPRO)/libnds/include/SDL/ + @cp include/*.h $(DEVKITPRO)/libnds/include/SDL/ + +nds_test: + $(MAKE) -C test/nds-test-progs + +copy_config: + @cp include/SDL_config.h.default include/SDL_config.h + +clean: + rm -f include/SDL_config.h $(OBJS) +
--- a/include/SDL_config.h.default Wed Aug 27 13:37:19 2008 +0000 +++ b/include/SDL_config.h.default Wed Aug 27 15:10:03 2008 +0000 @@ -26,7 +26,9 @@ #include "SDL_platform.h" /* Add any platform that doesn't build using the configure system */ -#if defined(__DREAMCAST__) +#if defined(__NINTENDODS__) +#include "SDL_config_nintendods.h" +#elif defined(__DREAMCAST__) #include "SDL_config_dreamcast.h" #elif defined(__MACOSX__) #include "SDL_config_macosx.h"
--- a/include/SDL_config.h.in Wed Aug 27 13:37:19 2008 +0000 +++ b/include/SDL_config.h.in Wed Aug 27 15:10:03 2008 +0000 @@ -177,6 +177,7 @@ #undef SDL_AUDIO_DRIVER_MMEAUDIO #undef SDL_AUDIO_DRIVER_NAS #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC +#undef SDL_AUDIO_DRIVER_NDS #undef SDL_AUDIO_DRIVER_OSS #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H #undef SDL_AUDIO_DRIVER_PAUDIO @@ -211,6 +212,7 @@ #undef SDL_JOYSTICK_IOKIT #undef SDL_JOYSTICK_LINUX #undef SDL_JOYSTICK_MINT +#undef SDL_JOYSTICK_NDS #undef SDL_JOYSTICK_OS2 #undef SDL_JOYSTICK_RISCOS #undef SDL_JOYSTICK_WINMM @@ -233,6 +235,7 @@ /* Enable various threading systems */ #undef SDL_THREAD_BEOS #undef SDL_THREAD_DC +#undef SDL_THREAD_NDS #undef SDL_THREAD_OS2 #undef SDL_THREAD_PTH #undef SDL_THREAD_PTHREAD @@ -246,6 +249,7 @@ #undef SDL_TIMER_DC #undef SDL_TIMER_DUMMY #undef SDL_TIMER_MINT +#undef SDL_TIMER_NDS #undef SDL_TIMER_OS2 #undef SDL_TIMER_RISCOS #undef SDL_TIMER_UNIX @@ -263,6 +267,7 @@ #undef SDL_VIDEO_DRIVER_GEM #undef SDL_VIDEO_DRIVER_IPOD #undef SDL_VIDEO_DRIVER_NANOX +#undef SDL_VIDEO_DRIVER_NDS #undef SDL_VIDEO_DRIVER_OS2FS #undef SDL_VIDEO_DRIVER_PHOTON #undef SDL_VIDEO_DRIVER_PS2GS
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/SDL_config_nintendods.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,119 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ + +#ifndef _SDL_config_nintendods_h +#define _SDL_config_nintendods_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long long int64_t; +typedef unsigned long long uint64_t; + +/* LiF: __PTRDIFF_TYPE__ was causing errors of conflicting typedefs with the + <stdint.h> shipping with devkitARM. copied a similar ifdef from it. */ +#ifndef __PTRDIFF_TYPE__ +typedef unsigned long uintptr_t; +#else +typedef unsigned __PTRDIFF_TYPE__ uintptr_t; +#endif + + +#define SDL_HAS_64BIT_TYPE 1 + +/* Useful headers */ +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STRING_H 1 +#define HAVE_CTYPE_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCMP 1 +#define HAVE_STRLEN 1 +#define HAVE_STRDUP 1 +#define HAVE_INDEX 1 +#define HAVE_RINDEX 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOD 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_STRICMP 1 +#define HAVE_STRCASECMP 1 +#define HAVE_SSCANF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 + +/* DS isn't that sophisticated */ +#define LACKS_SYS_MMAN_H 1 + +/* Enable various audio drivers */ +#define SDL_AUDIO_DRIVER_NDS 1 +/*#define SDL_AUDIO_DRIVER_DUMMY 1 TODO: uncomment this later*/ + +/* DS doesn't have optical media */ +#define SDL_CDROM_DISABLED 1 + +/* Enable various input drivers */ +#define SDL_JOYSTICK_NDS 1 +/*#define SDL_JOYSTICK_DUMMY 1 TODO: uncomment this later*/ + +/* DS has no dynamic linking afaik */ +#define SDL_LOADSO_DISABLED 1 + +/* Enable various threading systems */ +/*#define SDL_THREAD_NDS 1*/ +#define SDL_THREADS_DISABLED 1 + +/* Enable various timer systems */ +#define SDL_TIMER_NDS 1 + +/* Enable various video drivers */ +#define SDL_VIDEO_DRIVER_NDS 1 +/*#define SDL_VIDEO_DRIVER_DUMMY 1 TODO: uncomment this later*/ + +#endif /* _SDL_config_nintendods_h */
--- a/include/SDL_pixels.h Wed Aug 27 13:37:19 2008 +0000 +++ b/include/SDL_pixels.h Wed Aug 27 15:10:03 2008 +0000 @@ -146,12 +146,18 @@ SDL_PIXELFORMAT_RGB555 = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_1555, 15, 2), + SDL_PIXELFORMAT_BGR555 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, + SDL_PACKEDLAYOUT_1555, 15, 2), SDL_PIXELFORMAT_ARGB4444 = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_4444, 16, 2), SDL_PIXELFORMAT_ARGB1555 = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_1555, 16, 2), + SDL_PIXELFORMAT_ABGR1555 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR, + SDL_PACKEDLAYOUT_1555, 16, 2), SDL_PIXELFORMAT_RGB565 = SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_565, 16, 2),
--- a/include/SDL_platform.h Wed Aug 27 13:37:19 2008 +0000 +++ b/include/SDL_platform.h Wed Aug 27 15:10:03 2008 +0000 @@ -97,4 +97,9 @@ #define __WIN32__ 1 #endif +#if defined(__NDS__) +#undef __NINTENDODS__ +#define __NINTENDODS__ 1 +#endif + #endif /* _SDL_platform_h */
--- a/include/SDL_stdinc.h Wed Aug 27 13:37:19 2008 +0000 +++ b/include/SDL_stdinc.h Wed Aug 27 15:10:03 2008 +0000 @@ -147,8 +147,12 @@ SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2); SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4); SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4); +#ifndef __NINTENDODS__ /* TODO: figure out why the following happens: + include/SDL_stdinc.h:150: error: size of array 'SDL_dummy_uint64' is negative + include/SDL_stdinc.h:151: error: size of array 'SDL_dummy_sint64' is negative */ SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8); SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); +#endif #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ /* Check to make sure enums are the size of ints, for structure packing. @@ -162,12 +166,14 @@ #endif #ifndef DOXYGEN_SHOULD_IGNORE_THIS +#ifndef __NINTENDODS__ /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */ typedef enum { DUMMY_ENUM_VALUE } SDL_DUMMY_ENUM; SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); +#endif #endif /* DOXYGEN_SHOULD_IGNORE_THIS */ #include "begin_code.h" @@ -425,6 +431,9 @@ #ifdef HAVE_WCSLEN #define SDL_wcslen wcslen #else +#if !defined(wchar_t) && defined(__NINTENDODS__) +#define wchar_t short /* TODO: figure out why libnds doesn't have this */ +#endif extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string); #endif
--- a/src/SDL_compat.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/SDL_compat.c Wed Aug 27 15:10:03 2008 +0000 @@ -693,6 +693,7 @@ SDL_UpdateRects(screen, 1, &rect); } } + void SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects) {
--- a/src/SDL_error.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/SDL_error.c Wed Aug 27 15:10:03 2008 +0000 @@ -180,8 +180,8 @@ case 's': len = SDL_snprintf(msg, maxlen, tmp, - SDL_LookupString(error-> - args[argi++].buf)); + SDL_LookupString(error->args[argi++]. + buf)); msg += len; maxlen -= len; break;
--- a/src/audio/SDL_audio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/SDL_audio.c Wed Aug 27 15:10:03 2008 +0000 @@ -70,6 +70,7 @@ extern AudioBootStrap DCAUD_bootstrap; extern AudioBootStrap MMEAUDIO_bootstrap; extern AudioBootStrap DART_bootstrap; +extern AudioBootStrap NDSAUD_bootstrap; /* Available audio drivers */ @@ -145,6 +146,9 @@ #if SDL_AUDIO_DRIVER_DART &DART_bootstrap, #endif +#if SDL_AUDIO_DRIVER_NDS + &NDSAUD_bootstrap, +#endif NULL }; @@ -167,31 +171,38 @@ { return -1; } + static void SDL_AudioThreadInit_Default(_THIS) { /* no-op. */ } + static void SDL_AudioWaitDevice_Default(_THIS) { /* no-op. */ } + static void SDL_AudioPlayDevice_Default(_THIS) { /* no-op. */ } + static Uint8 * SDL_AudioGetDeviceBuf_Default(_THIS) { return NULL; } + static void SDL_AudioWaitDone_Default(_THIS) { /* no-op. */ } + static void SDL_AudioCloseDevice_Default(_THIS) { /* no-op. */ } + static void SDL_AudioDeinitialize_Default(void) { /* no-op. */
--- a/src/audio/SDL_wave.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/SDL_wave.c Wed Aug 27 15:10:03 2008 +0000 @@ -462,8 +462,7 @@ } /* 2 Uint32's for chunk header+len, plus the lenread */ headerDiff += lenread + 2 * sizeof(Uint32); - } - while ((chunk.magic == FACT) || (chunk.magic == LIST)); + } while ((chunk.magic == FACT) || (chunk.magic == LIST)); /* Decode the audio data format */ format = (WaveFMT *) chunk.data; @@ -564,8 +563,7 @@ *audio_buf = chunk.data; if (chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32); - } - while (chunk.magic != DATA); + } while (chunk.magic != DATA); headerDiff += 2 * sizeof(Uint32); /* for the data chunk and len */ if (MS_ADPCM_encoded) {
--- a/src/audio/alsa/SDL_alsa_audio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/alsa/SDL_alsa_audio.c Wed Aug 27 15:10:03 2008 +0000 @@ -259,16 +259,19 @@ { SWIZ6(Uint64); } + static __inline__ void swizzle_alsa_channels_6_32bit(_THIS) { SWIZ6(Uint32); } + static __inline__ void swizzle_alsa_channels_6_16bit(_THIS) { SWIZ6(Uint16); } + static __inline__ void swizzle_alsa_channels_6_8bit(_THIS) {
--- a/src/audio/bsd/SDL_bsdaudio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/bsd/SDL_bsdaudio.c Wed Aug 27 15:10:03 2008 +0000 @@ -270,8 +270,7 @@ || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) { SDL_Delay(1); /* Let a little CPU time go by */ } - } - while (p < written); + } while (p < written); /* If timer synchronization is enabled, set the next write frame */ if (this->hidden->frame_ticks) {
--- a/src/audio/dart/SDL_dart.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/dart/SDL_dart.c Wed Aug 27 15:10:03 2008 +0000 @@ -62,8 +62,8 @@ pBufDesc->iBufferUsage = BUFFER_EMPTY; // And notify DART feeder thread that it will have to work a bit. if (pSDLAudioDevice) - DosPostEventSem(pSDLAudioDevice->hidden-> - hevAudioBufferPlayed); + DosPostEventSem(pSDLAudioDevice-> + hidden->hevAudioBufferPlayed); } } } @@ -312,10 +312,11 @@ (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm; pBufDesc->iBufferUsage = BUFFER_USED; // Send it to DART to be queued - _this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms. - ulMixHandle, - &(_this->hidden-> - pMixBuffers[iFreeBuf]), 1); + _this->hidden->MixSetupParms.pmixWrite(_this->hidden-> + MixSetupParms.ulMixHandle, + &(_this-> + hidden->pMixBuffers[iFreeBuf]), + 1); _this->hidden->iLastPlayedBuf = iFreeBuf; iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs; @@ -333,8 +334,8 @@ if (_this->hidden) { iFreeBuf = _this->hidden->iNextFreeBuffer; pBufDesc = - (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf]. - ulUserParm; + (pMixBufferDesc) _this->hidden-> + pMixBuffers[iFreeBuf].ulUserParm; if (pBufDesc) { if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {
--- a/src/audio/dma/SDL_dmaaudio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/dma/SDL_dmaaudio.c Wed Aug 27 15:10:03 2008 +0000 @@ -498,8 +498,7 @@ this->enabled = 0; return (NULL); } - } - while (frame_ticks && (info.blocks < 1)); + } while (frame_ticks && (info.blocks < 1)); #ifdef DEBUG_AUDIO if (info.blocks > 1) { printf("Warning: audio underflow (%d frags)\n", info.blocks - 1);
--- a/src/audio/esd/SDL_esdaudio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/esd/SDL_esdaudio.c Wed Aug 27 15:10:03 2008 +0000 @@ -154,9 +154,8 @@ if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) { SDL_Delay(1); /* Let a little CPU time go by */ } - } - while ((written < 0) && - ((errno == 0) || (errno == EAGAIN) || (errno == EINTR))); + } while ((written < 0) && + ((errno == 0) || (errno == EAGAIN) || (errno == EINTR))); /* Set the next write frame */ this->hidden->next_frame += this->hidden->frame_ticks;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audio/nds/SDL_ndsaudio.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,130 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 + + This file written by Ryan C. Gordon (icculus@icculus.org) +*/ +#include "SDL_config.h" + +/* Output audio to NDS */ + +#include <nds.h> + +#include "SDL_audio.h" +#include "../SDL_audio_c.h" +#include "SDL_ndsaudio.h" + +static int +NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture) +{ + SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); + int valid_datatype = 0; + + this->hidden = SDL_malloc(sizeof(*(this->hidden))); + if (!this->hidden) { + SDL_OutOfMemory(); + return 0; + } + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + + while ((!valid_datatype) && (test_format)) { + this->spec.format = test_format; + switch (test_format) { + case AUDIO_S8: + /*case AUDIO_S16LSB: */ + valid_datatype = 1; + break; + default: + test_format = SDL_NextAudioFormat(); + break; + } + } + + /* set the generic sound parameters */ + setGenericSound(22050, /* sample rate */ + 127, /* volume */ + 64, /* panning/balance */ + 0); /* sound format */ + + return 1; +} + +static void +NDSAUD_PlayDevice(_THIS) +{ + TransferSoundData *sound = SDL_malloc(sizeof(TransferSoundData)); + if (!sound) { + SDL_OutOfMemory(); + } + + playGenericSound(this->hidden->mixbuf, this->hidden->mixlen); +#if 0 +// 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 */ +// sound->vol = 127; /* volume [0..127] for [min..max] */ +// sound->pan = 64; /* balance [0..127] for [left..right] */ +// sound->format = 0; /* 0 for 16-bit, 1 for 8-bit */ +// playSound(sound); +#endif +} + + +static Uint8 * +NDSAUD_GetDeviceBuf(_THIS) +{ + return this->hidden->mixbuf; /* is this right? */ +} + +static void +NDSAUD_WaitDevice(_THIS) +{ + /* stub */ +} + +static void +NDSAUD_CloseDevice(_THIS) +{ + /* stub */ +} + +static int +NDSAUD_Init(SDL_AudioDriverImpl * impl) +{ + /* Set the function pointers */ + impl->OpenDevice = NDSAUD_OpenDevice; + impl->PlayDevice = NDSAUD_PlayDevice; + impl->WaitDevice = NDSAUD_WaitDevice; + impl->GetDeviceBuf = NDSAUD_GetDeviceBuf; + impl->CloseDevice = NDSAUD_CloseDevice; + + /* and the capabilities */ + impl->HasCaptureSupport = 1; + impl->OnlyHasDefaultOutputDevice = 1; + impl->OnlyHasDefaultInputDevice = 1; + + return 1; +} + +AudioBootStrap NDSAUD_bootstrap = { + "nds", "SDL NDS audio driver", NDSAUD_Init, 0 /*1? */ +}; + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audio/nds/SDL_ndsaudio.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,44 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ +#include "SDL_config.h" + +#ifndef _SDL_ndsaudio_h +#define _SDL_ndsaudio_h + +#include "../SDL_sysaudio.h" +#include <nds/arm9/sound.h> + +/* Hidden "this" pointer for the audio functions */ +#define _THIS SDL_AudioDevice *this + +struct SDL_PrivateAudioData +{ + TransferSoundData *sound; + /* The file descriptor for the audio device */ + Uint8 *mixbuf; + Uint32 mixlen; + Uint32 write_delay; + Uint32 initial_calls; +}; + +#endif /* _SDL_ndsaudio_h */ +/* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/nto/SDL_nto_audio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/nto/SDL_nto_audio.c Wed Aug 27 15:10:03 2008 +0000 @@ -154,8 +154,7 @@ } break; } - } - while (1); + } while (1); } static void @@ -213,8 +212,7 @@ towrite -= written; pcmbuffer += written * this->spec.channels; } - } - while ((towrite > 0) && (this->enabled)); + } while ((towrite > 0) && (this->enabled)); /* If we couldn't write, assume fatal error for now */ if (towrite != 0) {
--- a/src/audio/paudio/SDL_paudio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/paudio/SDL_paudio.c Wed Aug 27 15:10:03 2008 +0000 @@ -208,9 +208,8 @@ if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) { SDL_Delay(1); /* Let a little CPU time go by */ } - } - while ((written < 0) && - ((errno == 0) || (errno == EAGAIN) || (errno == EINTR))); + } while ((written < 0) && + ((errno == 0) || (errno == EAGAIN) || (errno == EINTR))); /* If timer synchronization is enabled, set the next write frame */ if (this->hidden->frame_ticks) {
--- a/src/audio/ums/SDL_umsaudio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/ums/SDL_umsaudio.c Wed Aug 27 15:10:03 2008 +0000 @@ -218,8 +218,7 @@ #endif return; } - } - while (samplesToWrite > 0); + } while (samplesToWrite > 0); SDL_LockAudio(); SDL_memcpy(&swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer)); @@ -326,8 +325,7 @@ if (!success) { test_format = SDL_NextAudioFormat(); } - } - while (!success && test_format); + } while (!success && test_format); if (success == 0) { SDL_SetError("Couldn't find any hardware audio formats");
--- a/src/audio/windib/SDL_dibaudio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/windib/SDL_dibaudio.c Wed Aug 27 15:10:03 2008 +0000 @@ -107,8 +107,8 @@ Uint8 * WINWAVEOUT_GetDeviceBuf(_THIS) { - return (Uint8 *) (this->hidden->wavebuf[this->hidden->next_buffer]. - lpData); + return (Uint8 *) (this->hidden-> + wavebuf[this->hidden->next_buffer].lpData); } void @@ -136,8 +136,7 @@ if (left > 0) { SDL_Delay(100); } - } - while (left > 0); + } while (left > 0); } void
--- a/src/audio/windx5/SDL_dx5audio.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/audio/windx5/SDL_dx5audio.c Wed Aug 27 15:10:03 2008 +0000 @@ -278,8 +278,9 @@ IDirectSoundBuffer_Restore(this->hidden->mixbuf); result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor, this->hidden->mixlen, - (LPVOID *) & this->hidden-> - locked_buf, &rawlen, NULL, &junk, 0); + (LPVOID *) & this-> + hidden->locked_buf, &rawlen, NULL, + &junk, 0); } if (result != DS_OK) { SetDSerror("DirectSound Lock", result);
--- a/src/cdrom/SDL_cdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/SDL_cdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -44,6 +44,7 @@ NULL, /* Eject */ NULL, /* Close */ }; + int SDL_numcds; int
--- a/src/cdrom/aix/SDL_syscdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/aix/SDL_syscdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -181,8 +181,7 @@ #endif return; } - } - while (ret == 0); + } while (ret == 0); #ifdef DEBUG_CDROM fprintf(stderr, "Read %d vmount structures\n", ret); @@ -211,8 +210,7 @@ } ptr = (struct vmount *) ((char *) ptr + ptr->vmt_length); ret--; - } - while (ret > 0); + } while (ret > 0); free(buffer); } @@ -247,8 +245,7 @@ } } } - } - while (ret == 0); + } while (ret == 0); ret = endfsent_r(&fsFile); if (ret != 0) return -1; @@ -275,8 +272,7 @@ } } } - } - while (entry != NULL); + } while (entry != NULL); endfsent(); #endif } @@ -326,8 +322,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); }
--- a/src/cdrom/beos/SDL_syscdrom.cc Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/beos/SDL_syscdrom.cc Wed Aug 27 15:10:03 2008 +0000 @@ -193,8 +193,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); }
--- a/src/cdrom/bsdi/SDL_syscdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/bsdi/SDL_syscdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -286,8 +286,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); }
--- a/src/cdrom/freebsd/SDL_syscdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/freebsd/SDL_syscdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -176,8 +176,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); }
--- a/src/cdrom/linux/SDL_syscdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/linux/SDL_syscdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -312,8 +312,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); }
--- a/src/cdrom/macosx/AudioFilePlayer.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/macosx/AudioFilePlayer.c Wed Aug 27 15:10:03 2008 +0000 @@ -311,8 +311,7 @@ /* Skip the chunk data */ offset = chunk.ckSize; - } - while (chunk.ckID != 'SSND'); + } while (chunk.ckID != 'SSND'); /* Read the header of the SSND chunk. After this, we are positioned right at the start of the audio data. */
--- a/src/cdrom/macosx/AudioFileReaderThread.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/macosx/AudioFileReaderThread.c Wed Aug 27 15:10:03 2008 +0000 @@ -335,9 +335,8 @@ } /* construct pointer */ char *writePtr = (char *) (theItem->GetFileBuffer(theItem) + - (theItem-> - mWriteToFirstBuffer ? 0 : theItem-> - mChunkSize)); + (theItem->mWriteToFirstBuffer ? 0 : + theItem->mChunkSize)); /* read data */ result = theItem->Read(theItem, writePtr, &dataChunkSize); @@ -486,8 +485,7 @@ } else { *inOutDataSize = afm->mChunkSize; *inOutData = - afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm-> - mFileBuffer + + afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer + afm->mChunkSize); }
--- a/src/cdrom/macosx/CDPlayer.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/macosx/CDPlayer.c Wed Aug 27 15:10:03 2008 +0000 @@ -400,8 +400,7 @@ } CFRelease(name); } - } - while (noErr == result); + } while (noErr == result); FSCloseIterator(iterator); }
--- a/src/cdrom/openbsd/SDL_syscdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/openbsd/SDL_syscdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -184,8 +184,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); }
--- a/src/cdrom/osf/SDL_syscdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/osf/SDL_syscdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -199,8 +199,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); }
--- a/src/cdrom/qnx/SDL_syscdrom.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/cdrom/qnx/SDL_syscdrom.c Wed Aug 27 15:10:03 2008 +0000 @@ -184,8 +184,7 @@ } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } @@ -357,8 +356,7 @@ devctlret = ENXIO; break; } - } - while ((devctlret == EAGAIN) || (devctlret == ESTALE)); + } while ((devctlret == EAGAIN) || (devctlret == ESTALE)); if (devctlret != 0) { if (devctlret == ENXIO) {
--- a/src/events/SDL_events.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/events/SDL_events.c Wed Aug 27 15:10:03 2008 +0000 @@ -73,6 +73,7 @@ } } } + void SDL_Unlock_EventThread(void) {
--- a/src/events/default_cursor.h Wed Aug 27 13:37:19 2008 +0000 +++ b/src/events/default_cursor.h Wed Aug 27 15:10:03 2008 +0000 @@ -51,6 +51,7 @@ 0x03, 0x00, 0x00, 0x00 }; + static unsigned char default_cmask[] = { 0xC0, 0x00, 0xE0, 0x00, @@ -90,6 +91,7 @@ 0x03, 0x00, 0x00, 0x00 }; + static unsigned char default_cmask[] = { 0x40, 0x00, 0xE0, 0x00,
--- a/src/file/SDL_rwops.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/file/SDL_rwops.c Wed Aug 27 15:10:03 2008 +0000 @@ -28,6 +28,10 @@ #include "SDL_endian.h" #include "SDL_rwops.h" +#ifdef __NDS__ +/* include libfat headers for fatInitDefault(). */ +#include <fat.h> +#endif /* __NDS__ */ #ifdef __WIN32__ @@ -132,6 +136,7 @@ return 0; /* ok */ } + static long SDLCALL win32_file_seek(SDL_RWops * context, long offset, int whence) { @@ -173,6 +178,7 @@ SDL_Error(SDL_EFSEEK); return -1; /* error */ } + static size_t SDLCALL win32_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) { @@ -226,6 +232,7 @@ } return (total_read / size); } + static size_t SDLCALL win32_file_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) @@ -265,6 +272,7 @@ nwritten = byte_written / size; return nwritten; } + static int SDLCALL win32_file_close(SDL_RWops * context) { @@ -298,6 +306,7 @@ return (-1); } } + static size_t SDLCALL stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) { @@ -309,6 +318,7 @@ } return (nread); } + static size_t SDLCALL stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) { @@ -320,6 +330,7 @@ } return (nwrote); } + static int SDLCALL stdio_close(SDL_RWops * context) { @@ -368,6 +379,7 @@ context->hidden.mem.here = newpos; return (context->hidden.mem.here - context->hidden.mem.base); } + static size_t SDLCALL mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) { @@ -390,6 +402,7 @@ return (total_bytes / size); } + static size_t SDLCALL mem_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) { @@ -400,12 +413,14 @@ context->hidden.mem.here += num * size; return (num); } + static size_t SDLCALL mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num) { SDL_SetError("Can't write to read-only memory"); return (-1); } + static int SDLCALL mem_close(SDL_RWops * context) { @@ -463,6 +478,13 @@ { SDL_RWops *rwops = NULL; +#if 0 +/*#ifdef __NDS__*/ + /* set it up so we can use stdio file function */ + fatInitDefault(); + printf("called fatInitDefault()"); +#endif /* __NDS__ */ + rwops = SDL_AllocRW(); if (rwops != NULL) { rwops->seek = stdio_seek;
--- a/src/joystick/darwin/SDL_sysjoystick.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/joystick/darwin/SDL_sysjoystick.c Wed Aug 27 15:10:03 2008 +0000 @@ -149,8 +149,8 @@ (*ppPlugInInterface)->QueryInterface(ppPlugInInterface, CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), - (void *) &(pDevice-> - interface)); + (void *) + &(pDevice->interface)); if (S_OK != plugInResult) HIDReportErrorNum ("CouldnÕt query HID class device interface from plugInInterface",
--- a/src/joystick/linux/SDL_sysjoystick.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/joystick/linux/SDL_sysjoystick.c Wed Aug 27 15:10:03 2008 +0000 @@ -89,6 +89,7 @@ static struct joystick_logical_mapping mp88xx_1_logical_axismap[] = { {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5} }; + static struct joystick_logical_mapping mp88xx_1_logical_buttonmap[] = { {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11} @@ -98,6 +99,7 @@ {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {0, 3}, {1, 2}, {1, 3}, {0, 4}, {0, 5}, {1, 4}, {1, 5} }; + static struct joystick_logical_mapping mp88xx_2_logical_buttonmap[] = { {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11}, @@ -110,6 +112,7 @@ {1, 2}, {1, 3}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {0, 4}, {0, 5}, {1, 4}, {1, 5}, {2, 4}, {2, 5} }; + static struct joystick_logical_mapping mp88xx_3_logical_buttonmap[] = { {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11}, @@ -125,6 +128,7 @@ {3, 0}, {3, 1}, {3, 2}, {3, 3}, {0, 4}, {0, 5}, {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} }; + static struct joystick_logical_mapping mp88xx_4_logical_buttonmap[] = { {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11}, @@ -147,15 +151,18 @@ static struct joystick_logical_layout mp88xx_1_logical_layout[] = { {6, 0, 0, 12} }; + static struct joystick_logical_layout mp88xx_2_logical_layout[] = { {6, 0, 0, 12}, {6, 0, 0, 12} }; + static struct joystick_logical_layout mp88xx_3_logical_layout[] = { {6, 0, 0, 12}, {6, 0, 0, 12}, {6, 0, 0, 12} }; + static struct joystick_logical_layout mp88xx_4_logical_layout[] = { {6, 0, 0, 12}, {6, 0, 0, 12}, @@ -953,8 +960,8 @@ #endif /* USE_LOGICAL_JOYSTICKS */ SDL_PrivateJoystickHat(stick, hat, - position_map[the_hat->axis[1]][the_hat-> - axis[0]]); + position_map[the_hat-> + axis[1]][the_hat->axis[0]]); } } @@ -1085,13 +1092,13 @@ code -= BTN_MISC; #ifndef NO_LOGICAL_JOYSTICKS if (!LogicalJoystickButton(joystick, - joystick->hwdata-> - key_map[code], + joystick-> + hwdata->key_map[code], events[i].value)) #endif SDL_PrivateJoystickButton(joystick, - joystick->hwdata-> - key_map[code], + joystick-> + hwdata->key_map[code], events[i].value); } break; @@ -1113,12 +1120,12 @@ EV_AxisCorrect(joystick, code, events[i].value); #ifndef NO_LOGICAL_JOYSTICKS if (!LogicalJoystickAxis(joystick, - joystick->hwdata-> - abs_map[code], events[i].value)) + joystick->hwdata->abs_map[code], + events[i].value)) #endif SDL_PrivateJoystickAxis(joystick, - joystick->hwdata-> - abs_map[code], + joystick-> + hwdata->abs_map[code], events[i].value); break; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/joystick/nds/SDL_sysjoystick.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,172 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#include "SDL_config.h" + +#ifdef SDL_JOYSTICK_NDS + +/* This is the system specific header for the SDL joystick API */ +#include <nds.h> +#include <stdio.h> /* For the definition of NULL */ + +#include "SDL_error.h" +#include "SDL_events.h" +#include "SDL_joystick.h" +#include "SDL_sysjoystick.h" +#include "SDL_joystick_c.h" + +#include "../../video/nds/SDL_ndsevents_c.h" + +/* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return 0, or -1 on an unrecoverable fatal error. + */ +int +SDL_SYS_JoystickInit(void) +{ + SDL_numjoysticks = 1; + return (1); +} + +/* Function to get the device-dependent name of a joystick */ +const char * +SDL_SYS_JoystickName(int index) +{ + if (!index) + return "NDS builtin joypad"; + SDL_SetError("No joystick available with that index"); + return (NULL); +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int +SDL_SYS_JoystickOpen(SDL_Joystick * joystick) +{ + joystick->nbuttons = 8; + joystick->nhats = 0; + joystick->nballs = 0; + joystick->naxes = 2; + return 0; +} + + +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ + void +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) +{ + u32 keysd, keysu; + int magnitude = 16384; + + /*scanKeys(); */ + keysd = keysDown(); + keysu = keysUp(); + + if ((keysd & KEY_UP)) { + SDL_PrivateJoystickAxis(joystick, 1, -magnitude); + } + if ((keysd & KEY_DOWN)) { + SDL_PrivateJoystickAxis(joystick, 1, magnitude); + } + if ((keysd & KEY_LEFT)) { + SDL_PrivateJoystickAxis(joystick, 0, -magnitude); + } + if ((keysd & KEY_RIGHT)) { + SDL_PrivateJoystickAxis(joystick, 0, magnitude); + } + if ((keysu & (KEY_UP | KEY_DOWN))) { + SDL_PrivateJoystickAxis(joystick, 1, 0); + } + if ((keysu & (KEY_LEFT | KEY_RIGHT))) { + SDL_PrivateJoystickAxis(joystick, 0, 0); + } + if ((keysd & KEY_A)) { + SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); + } + if ((keysd & KEY_B)) { + SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED); + } + if ((keysd & KEY_X)) { + SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED); + } + if ((keysd & KEY_Y)) { + SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED); + } + if ((keysd & KEY_L)) { + SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED); + } + if ((keysd & KEY_R)) { + SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED); + } + if ((keysd & KEY_SELECT)) { + SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED); + } + if ((keysd & KEY_START)) { + SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED); + } + if ((keysu & KEY_A)) { + SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); + } + if ((keysu & KEY_B)) { + SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED); + } + if ((keysu & KEY_X)) { + SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED); + } + if ((keysu & KEY_Y)) { + SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED); + } + if ((keysu & KEY_L)) { + SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED); + } + if ((keysu & KEY_R)) { + SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED); + } + if ((keysu & KEY_SELECT)) { + SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED); + } + if ((keysu & KEY_START)) { + SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED); + } + } + +/* Function to close a joystick after use */ +void +SDL_SYS_JoystickClose(SDL_Joystick * joystick) +{ +} + +/* Function to perform any system-specific joystick related cleanup */ +void +SDL_SYS_JoystickQuit(void) +{ +} + +#endif /* SDL_JOYSTICK_NDS */
--- a/src/loadso/macosx/SDL_dlcompat.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/loadso/macosx/SDL_dlcompat.c Wed Aug 27 15:10:03 2008 +0000 @@ -616,8 +616,8 @@ || (LC_LOAD_WEAK_DYLIB == lc->cmd)) { if ((wh = (struct mach_header *) my_find_image((char - *) (((struct dylib_command *) lc)-> - dylib.name.offset + (char *) lc)))) { + *) (((struct dylib_command *) lc)->dylib. + name.offset + (char *) lc)))) { if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol)) { nssym = dyld_NSLookupSymbolInImage(wh, symbol, @@ -1067,6 +1067,7 @@ return answer; } + static void * dlsym_auto_underscore_intern(void *handle, const char *symbol) {
--- a/src/main/beos/SDL_BeApp.cc Wed Aug 27 13:37:19 2008 +0000 +++ b/src/main/beos/SDL_BeApp.cc Wed Aug 27 15:10:03 2008 +0000 @@ -78,8 +78,7 @@ do { SDL_Delay(10); - } - while ((be_app == NULL) || be_app->IsLaunching()); + } while ((be_app == NULL) || be_app->IsLaunching()); /* Mark the application active */ SDL_BeAppActive = 0;
--- a/src/stdlib/SDL_stdlib.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/stdlib/SDL_stdlib.c Wed Aug 27 15:10:03 2008 +0000 @@ -135,6 +135,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _alldiv() @@ -222,6 +223,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _aulldiv() @@ -279,6 +281,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _allrem() @@ -365,6 +368,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _aullrem() @@ -423,6 +427,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _alldvrm() @@ -532,6 +537,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _aulldvrm() @@ -604,6 +610,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _allshl() @@ -630,6 +637,7 @@ } /* *INDENT-ON* */ } + void __declspec(naked) _aullshr()
--- a/src/thread/SDL_thread_c.h Wed Aug 27 13:37:19 2008 +0000 +++ b/src/thread/SDL_thread_c.h Wed Aug 27 15:10:03 2008 +0000 @@ -43,6 +43,8 @@ #include "irix/SDL_systhread_c.h" #elif SDL_THREAD_WIN32 #include "win32/SDL_systhread_c.h" +#elif SDL_THREAD_NDS +#include "nds/SDL_systhread_c.h" #else #error Need thread implementation for this platform #include "generic/SDL_systhread_c.h"
--- a/src/thread/irix/SDL_syssem.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/thread/irix/SDL_syssem.c Wed Aug 27 15:10:03 2008 +0000 @@ -55,9 +55,11 @@ static struct sembuf op_trywait[2] = { {0, -1, (IPC_NOWAIT | SEM_UNDO)} /* Decrement semaphore, no block */ }; + static struct sembuf op_wait[2] = { {0, -1, SEM_UNDO} /* Decrement semaphore */ }; + static struct sembuf op_post[1] = { {0, 1, (IPC_NOWAIT | SEM_UNDO)} /* Increment semaphore */ }; @@ -170,8 +172,7 @@ break; } SDL_Delay(1); - } - while (SDL_GetTicks() < timeout); + } while (SDL_GetTicks() < timeout); return retval; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_syscond.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,229 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_syscond.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; +#endif + +/* An implementation of condition variables using semaphores and mutexes */ +/* + This implementation borrows heavily from the BeOS condition variable + implementation, written by Christopher Tate and Owen Smith. Thanks! + */ + +#include <stdio.h> +#include <stdlib.h> + +#include "SDL_error.h" +#include "SDL_thread.h" + +struct SDL_cond +{ + SDL_mutex *lock; + int waiting; + int signals; + SDL_sem *wait_sem; + SDL_sem *wait_done; +}; + +/* Create a condition variable */ +SDL_cond * +SDL_CreateCond(void) +{ + SDL_cond *cond; + + cond = (SDL_cond *) malloc(sizeof(SDL_cond)); + if (cond) { + cond->lock = SDL_CreateMutex(); + cond->wait_sem = SDL_CreateSemaphore(0); + cond->wait_done = SDL_CreateSemaphore(0); + cond->waiting = cond->signals = 0; + if (!cond->lock || !cond->wait_sem || !cond->wait_done) { + SDL_DestroyCond(cond); + cond = NULL; + } + } else { + SDL_OutOfMemory(); + } + return (cond); +} + +/* Destroy a condition variable */ +void +SDL_DestroyCond(SDL_cond * cond) +{ + if (cond) { + if (cond->wait_sem) { + SDL_DestroySemaphore(cond->wait_sem); + } + if (cond->wait_done) { + SDL_DestroySemaphore(cond->wait_done); + } + if (cond->lock) { + SDL_DestroyMutex(cond->lock); + } + free(cond); + } +} + +/* Restart one of the threads that are waiting on the condition variable */ +int +SDL_CondSignal(SDL_cond * cond) +{ + if (!cond) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex(cond->lock); + if (cond->waiting > cond->signals) { + ++cond->signals; + SDL_SemPost(cond->wait_sem); + SDL_UnlockMutex(cond->lock); + SDL_SemWait(cond->wait_done); + } else { + SDL_UnlockMutex(cond->lock); + } + + return 0; +} + +/* Restart all threads that are waiting on the condition variable */ +int +SDL_CondBroadcast(SDL_cond * cond) +{ + if (!cond) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* If there are waiting threads not already signalled, then + signal the condition and wait for the thread to respond. + */ + SDL_LockMutex(cond->lock); + if (cond->waiting > cond->signals) { + int i, num_waiting; + + num_waiting = (cond->waiting - cond->signals); + cond->signals = cond->waiting; + for (i = 0; i < num_waiting; ++i) { + SDL_SemPost(cond->wait_sem); + } + /* Now all released threads are blocked here, waiting for us. + Collect them all (and win fabulous prizes!) :-) + */ + SDL_UnlockMutex(cond->lock); + for (i = 0; i < num_waiting; ++i) { + SDL_SemWait(cond->wait_done); + } + } else { + SDL_UnlockMutex(cond->lock); + } + + return 0; +} + +/* Wait on the condition variable for at most 'ms' milliseconds. + The mutex must be locked before entering this function! + The mutex is unlocked during the wait, and locked again after the wait. + +Typical use: + +Thread A: + SDL_LockMutex(lock); + while ( ! condition ) { + SDL_CondWait(cond); + } + SDL_UnlockMutex(lock); + +Thread B: + SDL_LockMutex(lock); + ... + condition = true; + ... + SDL_UnlockMutex(lock); + */ +int +SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) +{ + int retval; + + if (!cond) { + SDL_SetError("Passed a NULL condition variable"); + return -1; + } + + /* Obtain the protection mutex, and increment the number of waiters. + This allows the signal mechanism to only perform a signal if there + are waiting threads. + */ + SDL_LockMutex(cond->lock); + ++cond->waiting; + SDL_UnlockMutex(cond->lock); + + /* Unlock the mutex, as is required by condition variable semantics */ + SDL_UnlockMutex(mutex); + + /* Wait for a signal */ + if (ms == SDL_MUTEX_MAXWAIT) { + retval = SDL_SemWait(cond->wait_sem); + } else { + retval = SDL_SemWaitTimeout(cond->wait_sem, ms); + } + + /* Let the signaler know we have completed the wait, otherwise + the signaler can race ahead and get the condition semaphore + if we are stopped between the mutex unlock and semaphore wait, + giving a deadlock. See the following URL for details: + http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html + */ + SDL_LockMutex(cond->lock); + if (cond->signals > 0) { + /* If we timed out, we need to eat a condition signal */ + if (retval > 0) { + SDL_SemWait(cond->wait_sem); + } + /* We always notify the signal thread that we are done */ + SDL_SemPost(cond->wait_done); + + /* Signal handshake complete */ + --cond->signals; + } + --cond->waiting; + SDL_UnlockMutex(cond->lock); + + /* Lock the mutex, as is required by condition variable semantics */ + SDL_LockMutex(mutex); + + return retval; +} + +/* Wait on the condition variable forever */ +int +SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex) +{ + return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_syscond_c.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,26 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_syscond_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_sysmutex.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,142 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_sysmutex.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; +#endif + +/* An implementation of mutexes using semaphores */ + +#include <stdio.h> +#include <stdlib.h> + +#include "SDL_error.h" +#include "SDL_thread.h" +#include "SDL_systhread_c.h" + + +struct SDL_mutex +{ + int recursive; + Uint32 owner; + SDL_sem *sem; +}; + +/* Create a mutex */ +SDL_mutex * +SDL_CreateMutex(void) +{ + SDL_mutex *mutex; + + /* Allocate mutex memory */ + mutex = (SDL_mutex *) malloc(sizeof(*mutex)); + if (mutex) { + /* Create the mutex semaphore, with initial value 1 */ + mutex->sem = SDL_CreateSemaphore(1); + mutex->recursive = 0; + mutex->owner = 0; + if (!mutex->sem) { + free(mutex); + mutex = NULL; + } + } else { + SDL_OutOfMemory(); + } + return mutex; +} + +/* Free the mutex */ +void +SDL_DestroyMutex(SDL_mutex * mutex) +{ + if (mutex) { + if (mutex->sem) { + SDL_DestroySemaphore(mutex->sem); + } + free(mutex); + } +} + +/* Lock the semaphore */ +int +SDL_mutexP(SDL_mutex * mutex) +{ +#ifdef DISABLE_THREADS + return 0; +#else + Uint32 this_thread; + + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + this_thread = SDL_ThreadID(); + if (mutex->owner == this_thread) { + ++mutex->recursive; + } else { + /* The order of operations is important. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. + */ + SDL_SemWait(mutex->sem); + mutex->owner = this_thread; + mutex->recursive = 0; + } + + return 0; +#endif /* DISABLE_THREADS */ +} + +/* Unlock the mutex */ +int +SDL_mutexV(SDL_mutex * mutex) +{ +#ifdef DISABLE_THREADS + return 0; +#else + if (mutex == NULL) { + SDL_SetError("Passed a NULL mutex"); + return -1; + } + + /* If we don't own the mutex, we can't unlock it */ + if (SDL_ThreadID() != mutex->owner) { + SDL_SetError("mutex not owned by this thread"); + return -1; + } + + if (mutex->recursive) { + --mutex->recursive; + } else { + /* The order of operations is important. + First reset the owner so another thread doesn't lock + the mutex and set the ownership before we reset it, + then release the lock semaphore. + */ + mutex->owner = 0; + SDL_SemPost(mutex->sem); + } + return 0; +#endif /* DISABLE_THREADS */ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_sysmutex_c.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,26 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_sysmutex_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_syssem.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,228 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_syssem.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; +#endif + +/* An implementation of semaphores using mutexes and condition variables */ + +#include <stdlib.h> + +#include "SDL_error.h" +#include "SDL_timer.h" +#include "SDL_thread.h" +#include "SDL_systhread_c.h" + + +#ifdef DISABLE_THREADS + +SDL_sem * +SDL_CreateSemaphore(Uint32 initial_value) +{ + SDL_SetError("SDL not configured with thread support"); + return (SDL_sem *) 0; +} + +void +SDL_DestroySemaphore(SDL_sem * sem) +{ + return; +} + +int +SDL_SemTryWait(SDL_sem * sem) +{ + SDL_SetError("SDL not configured with thread support"); + return -1; +} + +int +SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) +{ + SDL_SetError("SDL not configured with thread support"); + return -1; +} + +int +SDL_SemWait(SDL_sem * sem) +{ + SDL_SetError("SDL not configured with thread support"); + return -1; +} + +Uint32 +SDL_SemValue(SDL_sem * sem) +{ + return 0; +} + +int +SDL_SemPost(SDL_sem * sem) +{ + SDL_SetError("SDL not configured with thread support"); + return -1; +} + +#else + +struct SDL_semaphore +{ + Uint32 count; + Uint32 waiters_count; + SDL_mutex *count_lock; + SDL_cond *count_nonzero; +}; + +SDL_sem * +SDL_CreateSemaphore(Uint32 initial_value) +{ + SDL_sem *sem; + + sem = (SDL_sem *) malloc(sizeof(*sem)); + if (!sem) { + SDL_OutOfMemory(); + return (0); + } + sem->count = initial_value; + sem->waiters_count = 0; + + sem->count_lock = SDL_CreateMutex(); + sem->count_nonzero = SDL_CreateCond(); + if (!sem->count_lock || !sem->count_nonzero) { + SDL_DestroySemaphore(sem); + return (0); + } + + return (sem); +} + +/* WARNING: + You cannot call this function when another thread is using the semaphore. +*/ +void +SDL_DestroySemaphore(SDL_sem * sem) +{ + if (sem) { + sem->count = 0xFFFFFFFF; + while (sem->waiters_count > 0) { + SDL_CondSignal(sem->count_nonzero); + SDL_Delay(10); + } + SDL_DestroyCond(sem->count_nonzero); + SDL_mutexP(sem->count_lock); + SDL_mutexV(sem->count_lock); + SDL_DestroyMutex(sem->count_lock); + free(sem); + } +} + +int +SDL_SemTryWait(SDL_sem * sem) +{ + int retval; + + if (!sem) { + SDL_SetError("Passed a NULL semaphore"); + return -1; + } + + retval = SDL_MUTEX_TIMEDOUT; + SDL_LockMutex(sem->count_lock); + if (sem->count > 0) { + --sem->count; + retval = 0; + } + SDL_UnlockMutex(sem->count_lock); + + return retval; +} + +int +SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) +{ + int retval; + + if (!sem) { + SDL_SetError("Passed a NULL semaphore"); + return -1; + } + + /* A timeout of 0 is an easy case */ + if (timeout == 0) { + return SDL_SemTryWait(sem); + } + + SDL_LockMutex(sem->count_lock); + ++sem->waiters_count; + retval = 0; + while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { + retval = SDL_CondWaitTimeout(sem->count_nonzero, + sem->count_lock, timeout); + } + --sem->waiters_count; + --sem->count; + SDL_UnlockMutex(sem->count_lock); + + return retval; +} + +int +SDL_SemWait(SDL_sem * sem) +{ + return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); +} + +Uint32 +SDL_SemValue(SDL_sem * sem) +{ + Uint32 value; + + value = 0; + if (sem) { + SDL_LockMutex(sem->count_lock); + value = sem->count; + SDL_UnlockMutex(sem->count_lock); + } + return value; +} + +int +SDL_SemPost(SDL_sem * sem) +{ + if (!sem) { + SDL_SetError("Passed a NULL semaphore"); + return -1; + } + + SDL_LockMutex(sem->count_lock); + if (sem->waiters_count > 0) { + SDL_CondSignal(sem->count_nonzero); + } + ++sem->count; + SDL_UnlockMutex(sem->count_lock); + + return 0; +} + +#endif /* DISABLE_THREADS */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_syssem_c.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,26 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_syssem_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_systhread.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,63 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_systhread.c,v 1.2 2001/04/26 16:50:18 hercules Exp $"; +#endif + +/* Thread management routines for SDL */ + +#include "SDL_error.h" +#include "SDL_thread.h" +#include "SDL_systhread.h" + +int +SDL_SYS_CreateThread(SDL_Thread * thread, void *args) +{ + SDL_SetError("Threads are not supported on this platform"); + return (-1); +} + +void +SDL_SYS_SetupThread(void) +{ + return; +} + +Uint32 +SDL_ThreadID(void) +{ + return (0); +} + +void +SDL_SYS_WaitThread(SDL_Thread * thread) +{ + return; +} + +void +SDL_SYS_KillThread(SDL_Thread * thread) +{ + return; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/nds/SDL_systhread_c.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +/* Stub until we implement threads on this platform */ +typedef int SYS_ThreadHandle; + +#ifndef DISABLE_THREADS +#define DISABLE_THREADS +#endif
--- a/src/thread/pthread/SDL_syssem.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/thread/pthread/SDL_syssem.c Wed Aug 27 15:10:03 2008 +0000 @@ -125,8 +125,7 @@ break; } SDL_Delay(1); - } - while (SDL_GetTicks() < timeout); + } while (SDL_GetTicks() < timeout); return retval; }
--- a/src/thread/riscos/SDL_syssem.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/thread/riscos/SDL_syssem.c Wed Aug 27 15:10:03 2008 +0000 @@ -177,8 +177,7 @@ break; } SDL_Delay(1); - } - while (SDL_GetTicks() < timeout); + } while (SDL_GetTicks() < timeout); return retval; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/timer/nds/SDL_systimer.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,120 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ +#include "SDL_config.h" + +#ifdef SDL_TIMER_NDS + +#include <nds.h> +#include <nds/timers.h> + +#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 +SDL_StartTicks(void) +{ + if (!timer_alive) { + SDL_SYS_TimerInit(); + SDL_SYS_StartTimer(); + } + + timer_ticks = 0; +} + +Uint32 +SDL_GetTicks(void) +{ + return timer_ticks; +} + +void +SDL_Delay(Uint32 ms) +{ + Uint32 start = SDL_GetTicks(); + while (timer_alive) { + if ((SDL_GetTicks() - start) >= ms) + break; + } +} + +static int +RunTimer(void *unused) +{ + while (timer_alive) { + if (SDL_timer_running) { + } + SDL_Delay(1); + } + return (0); +} + +void +NDS_TimerInterrupt(void) +{ + timer_ticks++; +} + +/* This is only called if the event thread is not running */ +int +SDL_SYS_TimerInit(void) +{ + timer_alive = 1; + 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); + return 0; +} + +void +SDL_SYS_TimerQuit(void) +{ + if (timer_alive) { + TIMER_CR(3) = 0; + } + timer_alive = 0; + irqDisable(IRQ_TIMER3); +} + +int +SDL_SYS_StartTimer(void) +{ + TIMER_CR(3) |= TIMER_ENABLE; + return 0; +} + +void +SDL_SYS_StopTimer(void) +{ + TIMER_CR(3) &= ~TIMER_ENABLE; + return; +} + + +#endif /* SDL_TIMER_NDS */ +/* vi: set ts=4 sw=4 expandtab: */
--- a/src/timer/riscos/SDL_systimer.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/timer/riscos/SDL_systimer.c Wed Aug 27 15:10:03 2008 +0000 @@ -130,8 +130,7 @@ pthread_yield(); #endif - } - while (1); + } while (1); } #if SDL_THREADS_DISABLED
--- a/src/timer/unix/SDL_systimer.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/timer/unix/SDL_systimer.c Wed Aug 27 15:10:03 2008 +0000 @@ -137,8 +137,7 @@ was_error = select(0, NULL, NULL, NULL, &tv); #endif /* HAVE_NANOSLEEP */ - } - while (was_error && (errno == EINTR)); + } while (was_error && (errno == EINTR)); #endif /* SDL_THREAD_PTH */ }
--- a/src/video/SDL_RLEaccel.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_RLEaccel.c Wed Aug 27 15:10:03 2008 +0000 @@ -1154,8 +1154,7 @@ ofs += run; } else if (!ofs) goto done; - } - while (ofs < w); + } while (ofs < w); /* skip padding */ srcbuf += (uintptr_t) srcbuf & 2; @@ -1168,10 +1167,8 @@ run = ((Uint16 *) srcbuf)[1]; srcbuf += 4 * (run + 1); ofs += run; - } - while (ofs < w); - } - while (--vskip); + } while (ofs < w); + } while (--vskip); } else { /* the 32/32 interleaved format */ vskip <<= 1; /* opaque and translucent have same format */ @@ -1187,10 +1184,8 @@ ofs += run; } else if (!ofs) goto done; - } - while (ofs < w); - } - while (--vskip); + } while (ofs < w); + } while (--vskip); } } } @@ -1567,8 +1562,7 @@ runstart += len; run -= len; } - } - while (x < w); + } while (x < w); /* Make sure the next output address is 32-bit aligned */ dst += (uintptr_t) dst & 2; @@ -1604,8 +1598,7 @@ } if (!blankline) lastline = dst; - } - while (x < w); + } while (x < w); src += surface->pitch >> 2; } @@ -1771,8 +1764,7 @@ } if (!blankline) lastline = dst; - } - while (x < w); + } while (x < w); srcbuf += surface->pitch; } @@ -1911,8 +1903,7 @@ ofs += run; } else if (!ofs) return (SDL_TRUE); - } - while (ofs < w); + } while (ofs < w); /* skip padding if needed */ if (bpp == 2) @@ -1929,8 +1920,7 @@ srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf); ofs += run; } - } - while (ofs < w); + } while (ofs < w); dst += surface->pitch >> 2; } /* Make the compiler happy */
--- a/src/video/SDL_blit_0.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_blit_0.c Wed Aug 27 15:10:03 2008 +0000 @@ -80,6 +80,7 @@ } } } + static void BlitBto2(SDL_BlitInfo * info) { @@ -116,6 +117,7 @@ dst += dstskip; } } + static void BlitBto3(SDL_BlitInfo * info) { @@ -154,6 +156,7 @@ dst += dstskip; } } + static void BlitBto4(SDL_BlitInfo * info) {
--- a/src/video/SDL_blit_1.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_blit_1.c Wed Aug 27 15:10:03 2008 +0000 @@ -184,6 +184,7 @@ } #endif /* USE_DUFFS_LOOP */ } + static void Blit1to3(SDL_BlitInfo * info) { @@ -232,6 +233,7 @@ dst += dstskip; } } + static void Blit1to4(SDL_BlitInfo * info) {
--- a/src/video/SDL_blit_A.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_blit_A.c Wed Aug 27 15:10:03 2008 +0000 @@ -283,8 +283,8 @@ amult = alpha | (alpha << 8); amult = amult | (amult << 16); chanmask = - (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df-> - Bshift); + (0xff << df->Rshift) | (0xff << df-> + Gshift) | (0xff << df->Bshift); mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */ mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */ /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */ @@ -526,8 +526,8 @@ /* Use zero for alpha if either surface doesn't have alpha */ if (dstfmt->Amask) { amask = - ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt-> - Ashift); + ((srcfmt->Amask) ? RESHIFT(srcfmt-> + Ashift) : 0x10) << (dstfmt->Ashift); } else { amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
--- a/src/video/SDL_blit_N.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_blit_N.c Wed Aug 27 15:10:03 2008 +0000 @@ -141,8 +141,8 @@ /* Use zero for alpha if either surface doesn't have alpha */ if (dstfmt->Amask) { amask = - ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt-> - Ashift); + ((srcfmt->Amask) ? RESHIFT(srcfmt-> + Ashift) : 0x10) << (dstfmt->Ashift); } else { amask = 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^ @@ -1435,6 +1435,7 @@ 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100, 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200 }; + static void Blit_RGB565_ARGB8888(SDL_BlitInfo * info) { @@ -1572,6 +1573,7 @@ 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff, 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff }; + static void Blit_RGB565_ABGR8888(SDL_BlitInfo * info) { @@ -1709,6 +1711,7 @@ 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000, 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000, }; + static void Blit_RGB565_RGBA8888(SDL_BlitInfo * info) { @@ -1846,6 +1849,7 @@ 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff, 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff }; + static void Blit_RGB565_BGRA8888(SDL_BlitInfo * info) { @@ -1930,6 +1934,7 @@ } #endif /* USE_DUFFS_LOOP */ } + static void BlitNto1(SDL_BlitInfo * info) { @@ -2340,6 +2345,7 @@ /* Default for 8-bit RGB source, an invalid combination */ {0, 0, 0, 0, 0, 0, 0, 0, NULL}, }; + static const struct blit_table normal_blit_2[] = { #if SDL_ALTIVEC_BLITTERS /* has-altivec */ @@ -2366,10 +2372,12 @@ /* Default for 16-bit RGB source, used if no other blitter matches */ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} }; + static const struct blit_table normal_blit_3[] = { /* Default for 24-bit RGB source, never optimized */ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} }; + static const struct blit_table normal_blit_4[] = { #if SDL_ALTIVEC_BLITTERS /* has-altivec | dont-use-prefetch */ @@ -2396,6 +2404,7 @@ /* Default for 32-bit RGB source, used if no other blitter matches */ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0} }; + static const struct blit_table *normal_blit[] = { normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4 };
--- a/src/video/SDL_gamma.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_gamma.c Wed Aug 27 15:10:03 2008 +0000 @@ -70,6 +70,7 @@ } } } + static void CalculateGammaFromRamp(float *gamma, Uint16 * ramp) {
--- a/src/video/SDL_pixels.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_pixels.c Wed Aug 27 15:10:03 2008 +0000 @@ -168,12 +168,16 @@ break; case 15: switch (Rmask) { + case 0x001F: + return SDL_PIXELFORMAT_BGR555; case 0x7C00: return SDL_PIXELFORMAT_RGB555; } break; case 16: switch (Rmask) { + case 0x001F: + return SDL_PIXELFORMAT_ABGR1555; case 0x0F00: return SDL_PIXELFORMAT_ARGB4444; case 0x7C00: @@ -748,6 +752,7 @@ map->info.table = NULL; } } + int SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) {
--- a/src/video/SDL_renderer_sw.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_renderer_sw.c Wed Aug 27 15:10:03 2008 +0000 @@ -388,8 +388,9 @@ void **pixels, int *pitch) { if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture-> - driverdata, pixels, pitch); + return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) + texture->driverdata, pixels, + pitch); } else { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; @@ -464,8 +465,9 @@ const SDL_Rect * rect, const void *pixels, int pitch) { if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture-> - driverdata, rect, pixels, pitch); + return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) + texture->driverdata, rect, pixels, + pitch); } else { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; Uint8 *src, *dst; @@ -492,9 +494,9 @@ int *pitch) { if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) texture-> - driverdata, rect, markDirty, pixels, - pitch); + return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) + texture->driverdata, rect, markDirty, + pixels, pitch); } else { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; @@ -535,10 +537,10 @@ color = SDL_MapRGBA(data->surface.format, r, g, b, a); - if (data->renderer-> - LockTexture(data->renderer, data->texture[data->current_texture], - rect, 1, &data->surface.pixels, - &data->surface.pitch) < 0) { + if (data->renderer->LockTexture(data->renderer, + data->texture[data->current_texture], + rect, 1, &data->surface.pixels, + &data->surface.pitch) < 0) { return -1; } data->surface.w = rect->w; @@ -566,10 +568,10 @@ SDL_AddDirtyRect(&data->dirty, dstrect); } - if (data->renderer-> - LockTexture(data->renderer, data->texture[data->current_texture], - dstrect, 1, &data->surface.pixels, - &data->surface.pitch) < 0) { + if (data->renderer->LockTexture(data->renderer, + data->texture[data->current_texture], + dstrect, 1, &data->surface.pixels, + &data->surface.pitch) < 0) { return -1; }
--- a/src/video/SDL_surface.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_surface.c Wed Aug 27 15:10:03 2008 +0000 @@ -409,9 +409,9 @@ return 0; } - switch (surface->map->info. - flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | - SDL_COPY_MOD)) { + switch (surface->map-> + info.flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | + SDL_COPY_MOD)) { case SDL_COPY_MASK: *blendMode = SDL_TEXTUREBLENDMODE_MASK; break;
--- a/src/video/SDL_sysvideo.h Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_sysvideo.h Wed Aug 27 15:10:03 2008 +0000 @@ -369,6 +369,9 @@ #if SDL_VIDEO_DRIVER_DUMMY extern VideoBootStrap DUMMY_bootstrap; #endif +#if SDL_VIDEO_DRIVER_NDS +extern VideoBootStrap NDS_bootstrap; +#endif #define SDL_CurrentDisplay (_this->displays[_this->current_display])
--- a/src/video/SDL_video.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/SDL_video.c Wed Aug 27 15:10:03 2008 +0000 @@ -103,6 +103,9 @@ #if SDL_VIDEO_DRIVER_OS2FS &OS2FSLib_bootstrap, #endif +#if SDL_VIDEO_DRIVER_NDS + &NDS_bootstrap, +#endif #if SDL_VIDEO_DRIVER_DUMMY &DUMMY_bootstrap, #endif
--- a/src/video/ataricommon/SDL_atarigl.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/ataricommon/SDL_atarigl.c Wed Aug 27 15:10:03 2008 +0000 @@ -349,9 +349,9 @@ } if (! - (_this->gl_data-> - OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, - surface->h))) { + (_this-> + gl_data->OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, + surface->h))) { SDL_SetError("Can not make OpenGL context current"); return -1; } @@ -512,10 +512,10 @@ gl_ctx = _this->gl_data->OSMesaCreateContextExt(osmesa_format, - _this->gl_config. - depth_size, - _this->gl_config. - stencil_size, + _this-> + gl_config.depth_size, + _this-> + gl_config.stencil_size, newaccumsize, NULL); if (gl_ctx) {
--- a/src/video/bwindow/SDL_sysvideo.cc Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/bwindow/SDL_sysvideo.cc Wed Aug 27 15:10:03 2008 +0000 @@ -670,8 +670,8 @@ _this->gl_config.driver_loaded = 1; SDL_strlcpy(_this->gl_config.driver_path, "libGL.so", - SDL_arraysize(_this->gl_config. - driver_path)); + SDL_arraysize(_this-> + gl_config.driver_path)); } } }
--- a/src/video/dc/SDL_dcevents.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/dc/SDL_dcevents.c Wed Aug 27 15:10:03 2008 +0000 @@ -135,8 +135,7 @@ for (i = 0; i < sizeof(sdl_shift); i++) { if ((shiftkeys >> i) & 1) { keysym.sym = sdl_shift[i]; - SDL_PrivateKeyboard(((state-> - shift_keys >> i) & 1) ? SDL_PRESSED : + SDL_PrivateKeyboard(((state->shift_keys >> i) & 1) ? SDL_PRESSED : SDL_RELEASED, &keysym); } } @@ -146,8 +145,7 @@ int key = sdl_key[i]; if (key) { keysym.sym = key; - SDL_PrivateKeyboard(state-> - matrix[i] ? SDL_PRESSED : + SDL_PrivateKeyboard(state->matrix[i] ? SDL_PRESSED : SDL_RELEASED, &keysym); } }
--- a/src/video/dc/SDL_dcvideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/dc/SDL_dcvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -158,6 +158,7 @@ const static SDL_Rect RECT_800x600 = { 0, 0, 800, 600 }, RECT_640x480 = { 0, 0, 640, 480}, RECT_320x240 = { 0, 0, 320, 240}; + const static SDL_Rect *vid_modes[] = { &RECT_800x600, &RECT_640x480, @@ -296,6 +297,7 @@ { return (-1); } + static void DC_FreeHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/directfb/SDL_DirectFB_events.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/directfb/SDL_DirectFB_events.c Wed Aug 27 15:10:03 2008 +0000 @@ -383,33 +383,25 @@ switch (evt.type) { case DIET_BUTTONPRESS: posted += SDL_PrivateMouseButton(SDL_PRESSED, - DirectFB_TranslateButton(evt. - button), - 0, 0); + DirectFB_TranslateButton + (evt.button), 0, 0); break; case DIET_BUTTONRELEASE: posted += SDL_PrivateMouseButton(SDL_RELEASED, - DirectFB_TranslateButton(evt. - button), - 0, 0); + DirectFB_TranslateButton + (evt.button), 0, 0); break; case DIET_KEYPRESS: posted += SDL_PrivateKeyboard(SDL_PRESSED, - DirectFB_TranslateKey(evt. - key_id, - evt. - key_symbol, - mod, - &keysym)); + DirectFB_TranslateKey + (evt.key_id, evt.key_symbol, + mod, &keysym)); break; case DIET_KEYRELEASE: posted += SDL_PrivateKeyboard(SDL_RELEASED, - DirectFB_TranslateKey(evt. - key_id, - evt. - key_symbol, - mod, - &keysym)); + DirectFB_TranslateKey + (evt.key_id, evt.key_symbol, + mod, &keysym)); break; case DIET_AXISMOTION: if (evt.flags & DIEF_AXISREL) {
--- a/src/video/directfb/SDL_DirectFB_mouse.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/directfb/SDL_DirectFB_mouse.c Wed Aug 27 15:10:03 2008 +0000 @@ -85,14 +85,15 @@ dsc.height = surface->h; dsc.pixelformat = DSPF_ARGB; - SDL_DFB_CHECKERR(devdata->dfb-> - CreateSurface(devdata->dfb, &dsc, &curdata->surf)); + SDL_DFB_CHECKERR(devdata-> + dfb->CreateSurface(devdata->dfb, &dsc, &curdata->surf)); curdata->hotx = hot_x; curdata->hoty = hot_y; cursor->driverdata = curdata; - SDL_DFB_CHECKERR(curdata->surf-> - Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch)); + SDL_DFB_CHECKERR(curdata-> + surf->Lock(curdata->surf, DSLF_WRITE, (void *) &dest, + &pitch)); //FIXME: Implies a lot of things, e.g. rgba format for SDL_SURFACE .... p = surface->pixels; @@ -131,18 +132,18 @@ DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; if (cursor) - SDL_DFB_CHECKERR(windata->window-> - SetCursorShape(windata->window, curdata->surf, - curdata->hotx, curdata->hoty)); + SDL_DFB_CHECKERR(windata->window->SetCursorShape(windata->window, + curdata->surf, + curdata->hotx, + curdata->hoty)); //TODO: Check administrative - SDL_DFB_CHECKERR(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, - DLSCL_ADMINISTRATIVE)); - SDL_DFB_CHECKERR(dispdata->layer-> - SetCursorOpacity(dispdata->layer, - cursor ? 0xC0 : 0x00)); - SDL_DFB_CHECKERR(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, DLSCL_SHARED)); + SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer, + DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(dispdata->layer->SetCursorOpacity(dispdata->layer, + cursor ? 0xC0 : + 0x00)); + SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer, + DLSCL_SHARED)); } return 0; @@ -181,8 +182,8 @@ int cx, cy; SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy)); - SDL_DFB_CHECKERR(dispdata->layer-> - WarpCursor(dispdata->layer, cx + x, cy + y)); + SDL_DFB_CHECKERR(dispdata-> + layer->WarpCursor(dispdata->layer, cx + x, cy + y)); error: return;
--- a/src/video/directfb/SDL_DirectFB_video.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/directfb/SDL_DirectFB_video.c Wed Aug 27 15:10:03 2008 +0000 @@ -314,8 +314,8 @@ SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen)); devdata->aux = i; - SDL_DFB_CHECKERR(screen-> - EnumDisplayLayers(screen, &cbLayers, devdata)); + SDL_DFB_CHECKERR(screen->EnumDisplayLayers + (screen, &cbLayers, devdata)); #if (DIRECTFB_MAJOR_VERSION >= 1) screen->GetSize(screen, &tcw[i], &tch[i]); #else @@ -338,12 +338,12 @@ for (i = 0; i < devdata->numscreens; i++) { //SDL_DFB_CHECKERR( dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer) ); - SDL_DFB_CHECKERR(dfb-> - GetDisplayLayer(dfb, devdata->gralayer[i], &layer)); + SDL_DFB_CHECKERR(dfb->GetDisplayLayer + (dfb, devdata->gralayer[i], &layer)); //SDL_DFB_CHECKERR( dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events) ); - SDL_DFB_CHECKERR(layer-> - SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(layer->SetCooperativeLevel + (layer, DLSCL_ADMINISTRATIVE)); layer->EnableCursor(layer, 1); SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0)); SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED)); @@ -379,8 +379,8 @@ /* Enumerate the available fullscreen modes */ SDL_DFB_CALLOC(dispdata->modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode)); - SDL_DFB_CHECKERR(dfb-> - EnumVideoModes(dfb, EnumModesCallback, &display)); + SDL_DFB_CHECKERR(dfb->EnumVideoModes + (dfb, EnumModesCallback, &display)); SDL_AddVideoDisplay(&display); } @@ -433,13 +433,14 @@ DFB_DisplayData *dispdata = (DFB_DisplayData *) _this->displays[i].driverdata; if (dispdata->layer) { - SDL_DFB_CHECK(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, - DLSCL_ADMINISTRATIVE)); - SDL_DFB_CHECK(dispdata->layer-> - SetCursorOpacity(dispdata->layer, 0x00)); - SDL_DFB_CHECK(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, DLSCL_SHARED)); + SDL_DFB_CHECK(dispdata-> + layer->SetCooperativeLevel(dispdata->layer, + DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECK(dispdata-> + layer->SetCursorOpacity(dispdata->layer, 0x00)); + SDL_DFB_CHECK(dispdata-> + layer->SetCooperativeLevel(dispdata->layer, + DLSCL_SHARED)); } SDL_DFB_RELEASE(dispdata->layer); @@ -578,8 +579,8 @@ DFBResult ret; DFB_WindowData *win; - SDL_DFB_CHECKERR(data->layer-> - SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, + DLSCL_ADMINISTRATIVE)); SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config)); config.flags = DLCONF_WIDTH | DLCONF_HEIGHT; // | DLCONF_BUFFERMODE; @@ -604,8 +605,8 @@ SDL_DFB_DEBUG("Trace\n"); config.flags &= ~fail; SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config)); - SDL_DFB_CHECKERR(data->layer-> - SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, + DLSCL_ADMINISTRATIVE)); /* Double check */ SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig)); @@ -674,11 +675,11 @@ SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData)); windata = (DFB_WindowData *) window->driverdata; - SDL_DFB_CHECKERR(devdata->dfb-> - SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL)); - SDL_DFB_CHECKERR(dispdata->layer-> - SetCooperativeLevel(dispdata->layer, - DLSCL_ADMINISTRATIVE)); + SDL_DFB_CHECKERR(devdata-> + dfb->SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL)); + SDL_DFB_CHECKERR(dispdata-> + layer->SetCooperativeLevel(dispdata->layer, + DLSCL_ADMINISTRATIVE)); /* Fill the window description. */ if (window->x == SDL_WINDOWPOS_CENTERED) { @@ -725,8 +726,8 @@ desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE / DSCAPS_PREMULTIPLIED; /* Create the window. */ - SDL_DFB_CHECKERR(dispdata->layer-> - CreateWindow(dispdata->layer, &desc, &windata->window)); + SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc, + &windata->window)); windata->window->GetOptions(windata->window, &wopts); #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0) @@ -744,12 +745,13 @@ windata->window->SetOptions(windata->window, wopts); /* Get the window's surface. */ - SDL_DFB_CHECKERR(windata->window-> - GetSurface(windata->window, &windata->surface)); + SDL_DFB_CHECKERR(windata-> + window->GetSurface(windata->window, &windata->surface)); windata->window->SetOpacity(windata->window, 0xFF); - SDL_DFB_CHECKERR(windata->window-> - CreateEventBuffer(windata->window, - &(windata->eventbuffer))); + SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window, + & + (windata-> + eventbuffer))); SDL_DFB_CHECKERR(windata->window-> EnableEvents(windata->window, DWET_POSITION | DWET_SIZE | DWET_CLOSE | @@ -812,6 +814,7 @@ //return -1; } + static void DirectFB_SetWindowPosition(_THIS, SDL_Window * window) { @@ -886,6 +889,7 @@ windata->window->SetOpacity(windata->window, 0); } + static void DirectFB_RaiseWindow(_THIS, SDL_Window * window) { @@ -907,6 +911,7 @@ SDL_Unsupported(); } + static void DirectFB_MinimizeWindow(_THIS, SDL_Window * window) { @@ -928,6 +933,7 @@ SDL_Unsupported(); } + static void DirectFB_SetWindowGrab(_THIS, SDL_Window * window) { @@ -1156,8 +1162,8 @@ devdata->glFlush(); SDL_DFB_CHECKERR(windata->gl_context->Unlock(windata->gl_context)); - SDL_DFB_CHECKERR(windata->surface-> - Flip(windata->surface, ®ion, DSFLIP_ONSYNC)); + SDL_DFB_CHECKERR(windata-> + surface->Flip(windata->surface, ®ion, DSFLIP_ONSYNC)); SDL_DFB_CHECKERR(windata->gl_context->Lock(windata->gl_context)); return;
--- a/src/video/fbcon/SDL_fb3dfx.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/fbcon/SDL_fb3dfx.c Wed Aug 27 15:10:03 2008 +0000 @@ -37,6 +37,7 @@ /* wait until we're past the start */ while ((tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0); } + static void WaitIdle(_THIS) {
--- a/src/video/fbcon/SDL_fbelo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/fbcon/SDL_fbelo.c Wed Aug 27 15:10:03 2008 +0000 @@ -268,8 +268,7 @@ if (result == 0) { i--; } - } - while (!ok && (i > 0)); + } while (!ok && (i > 0)); return ok; }
--- a/src/video/fbcon/SDL_fbevents.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/fbcon/SDL_fbevents.c Wed Aug 27 15:10:03 2008 +0000 @@ -545,9 +545,8 @@ if (select(fd + 1, &fdset, 0, 0, &tv) < 1) { break; } - } - while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && - ((ch == 0xFA) || (ch == 0xAA))); + } while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && + ((ch == 0xFA) || (ch == 0xAA))); /* Experimental values (Logitech wheelmouse) */ #ifdef DEBUG_MOUSE @@ -970,6 +969,7 @@ ioctl(keyboard_fd, KDSETMODE, KD_TEXT); ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); } + static void switch_vt_done(_THIS) { @@ -995,6 +995,7 @@ (SDL_APPACTIVE | SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS)); } + static void switch_vt(_THIS, unsigned short which) { @@ -1113,8 +1114,7 @@ } } } - } - while (posted); + } while (posted); } void
--- a/src/video/fbcon/SDL_fbmatrox.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/fbcon/SDL_fbmatrox.c Wed Aug 27 15:10:03 2008 +0000 @@ -41,6 +41,7 @@ count = mga_in32(0x1E20) + 2; while (mga_in32(0x1E20) < count); } + static void WaitIdle(_THIS) {
--- a/src/video/fbcon/SDL_fbriva.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/fbcon/SDL_fbriva.c Wed Aug 27 15:10:03 2008 +0000 @@ -40,6 +40,7 @@ while ((*port & 0x08)); while (!(*port & 0x08)); } + static void NV3WaitIdle(_THIS) { @@ -47,6 +48,7 @@ while ((Rop->FifoFree < FifoEmptyCount) || (*(mapped_io + PGRAPH_OFFSET + 0x000006B0) & 0x01)); } + static void NV4WaitIdle(_THIS) {
--- a/src/video/fbcon/SDL_fbvideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/fbcon/SDL_fbvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -82,6 +82,7 @@ {0, 0, 320, 240}, {0, 0, 320, 200} }; + static const struct { int xres; @@ -323,15 +324,13 @@ blank = 1; else blank = 0; - } - while (blank); + } while (blank); /* remove whitespace at the begining of the string */ i = 0; do { line[i] = c[i]; i++; - } - while (c[i] != 0); + } while (c[i] != 0); return 1; } @@ -347,8 +346,7 @@ return 0; if (SDL_strncmp(line, "geometry", 8) == 0) break; - } - while (1); + } while (1); SDL_sscanf(line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres, &vinfo->xres_virtual, &vinfo->yres_virtual, @@ -394,8 +392,7 @@ if (SDL_strncmp(option, "true", 4) == 0) vinfo->vmode |= FB_VMODE_DOUBLE; } - } - while (SDL_strncmp(line, "endmode", 7) != 0); + } while (SDL_strncmp(line, "endmode", 7) != 0); return 1; } @@ -826,6 +823,7 @@ fprintf(stderr, "\talpha: %d/%d\n", vinfo->transp.length, vinfo->transp.offset); } + static void print_finfo(struct fb_fix_screeninfo *finfo) { @@ -1193,6 +1191,7 @@ screen->hwdata = (struct private_hwdata *) &surfaces; return (0); } + static void FB_FreeHWSurfaces(_THIS) { @@ -1283,6 +1282,7 @@ surface->hwdata = (struct private_hwdata *) bucket; return (0); } + static void FB_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -1352,6 +1352,7 @@ } return (0); } + static void FB_UnlockHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/gapi/SDL_gapivideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/gapi/SDL_gapivideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -340,8 +340,7 @@ gx.GXSuspend, "?GXSuspend@@YAHXZ") LINK(GXResume, gx.GXResume, "?GXResume@@YAHXZ") LINK(GXSetViewport, - gx. - GXSetViewport, + gx.GXSetViewport, "?GXSetViewport@@YAHKKKK@Z") LINK(GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer, "?GXIsDisplayDRAMBuffer@@YAHXZ") @@ -807,6 +806,7 @@ { return (-1); } + static void GAPI_FreeHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/ipod/SDL_ipodvideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/ipod/SDL_ipodvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -526,8 +526,7 @@ } if (dbgout) fprintf(dbgout, "\n"); - } - while (posted); + } while (posted); } // enough space for 160x128x2 @@ -570,8 +569,7 @@ do { if ((inl(lcd_base) & (unsigned int) 0x8000) == 0) break; - } - while (M_timer_check(start, 1000) == 0); + } while (M_timer_check(start, 1000) == 0); } } @@ -681,10 +679,10 @@ do { if ((inl(0x70008A0C) & 0x80000000) == 0) break; - } - while (C_timer_check(start, 1000) == 0); + } while (C_timer_check(start, 1000) == 0); } } + static void C_lcd_cmd_data(int cmd, int data) { @@ -780,10 +778,12 @@ ipod_scr[y * (lcd_width / 4) + x / 4] |= (((Uint8 *) (SDL_VideoSurface->pixels))[y * SDL_VideoSurface-> - pitch - + - x] & - 3) << (2 * (x % 4)); + pitch + + x] & 3) << (2 + * + (x + % + 4)); } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsevents.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,54 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ +#include "SDL_config.h" + +/* Being a null driver, there's no event stream. We just define stubs for + most of the API. */ + +#include <stdio.h> +#include <stdlib.h> +#include <nds.h> + +#include "SDL.h" +#include "../../events/SDL_sysevents.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_ndsvideo.h" +#include "SDL_ndsevents_c.h" + +void +NDS_PumpEvents(_THIS) +{ + scanKeys(); + /* TODO: defer click-age */ + if (keysDown() & KEY_TOUCH) { + SDL_SendMouseButton(0, SDL_PRESSED, 0); + } else if (keysUp() & KEY_TOUCH) { + SDL_SendMouseButton(0, SDL_RELEASED, 0); + } + if (keysHeld() & KEY_TOUCH) { + touchPosition t = touchReadXY(); + SDL_SendMouseMotion(0, 0, t.px, t.py); + } +} + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsevents_c.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ +#include "SDL_config.h" + +#include "SDL_ndsvideo.h" + +extern void NDS_PumpEvents(_THIS); + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsrender.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,660 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <nds.h> +#include <nds/arm9/video.h> +#include <nds/arm9/sprite.h> +#include <nds/arm9/trig_lut.h> + +#include "SDL_config.h" + +#include "SDL_video.h" +#include "../SDL_sysvideo.h" +#include "../SDL_yuv_sw_c.h" +#include "../SDL_renderer_sw.h" + +/* NDS sprite-related functions */ +#define SPRITE_DMA_CHANNEL 3 +#define SPRITE_ANGLE_MASK 0x01FF + +void +NDS_OAM_Update(tOAM * oam, int sub) +{ + DC_FlushAll(); + dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer, + sub ? OAM_SUB : OAM, SPRITE_COUNT * sizeof(SpriteEntry)); +} + +void +NDS_OAM_RotateSprite(SpriteRotation * spriteRotation, u16 angle) +{ + s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4; + s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4; + + spriteRotation->hdx = c; + spriteRotation->hdy = s; + spriteRotation->vdx = -s; + spriteRotation->vdy = c; +} + +void +NDS_OAM_Init(tOAM * oam, int sub) +{ + int i; + for (i = 0; i < SPRITE_COUNT; i++) { + oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED; + oam->spriteBuffer[i].attribute[1] = 0; + oam->spriteBuffer[i].attribute[2] = 0; + } + for (i = 0; i < MATRIX_COUNT; i++) { + NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0); + } + swiWaitForVBlank(); + NDS_OAM_Update(oam, sub); +} + +void +NDS_OAM_HideSprite(SpriteEntry * spriteEntry) +{ + spriteEntry->isRotoscale = 0; + spriteEntry->isHidden = 1; +} + +void +NDS_OAM_ShowSprite(SpriteEntry * spriteEntry, int affine, int double_bound) +{ + if (affine) { + spriteEntry->isRotoscale = 1; + spriteEntry->rsDouble = double_bound; + } else { + spriteEntry->isHidden = 0; + } +} + + +/* SDL NDS renderer implementation */ + +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); +static int NDS_QueryTexturePixels(SDL_Renderer * renderer, + SDL_Texture * texture, void **pixels, + int *pitch); +static int NDS_SetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors); +static int NDS_GetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, SDL_Color * colors, + int firstcolor, int ncolors); +static int NDS_SetTextureColorMod(SDL_Renderer * renderer, + SDL_Texture * texture); +static int NDS_SetTextureAlphaMod(SDL_Renderer * renderer, + SDL_Texture * texture); +static int NDS_SetTextureBlendMode(SDL_Renderer * renderer, + SDL_Texture * texture); +static int NDS_SetTextureScaleMode(SDL_Renderer * renderer, + SDL_Texture * texture); +static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, + int pitch); +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 void NDS_DirtyTexture(SDL_Renderer * renderer, + SDL_Texture * texture, int numrects, + const SDL_Rect * rects); +static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, + Uint8 b, Uint8 a, const SDL_Rect * rect); +static int NDS_RenderCopy(SDL_Renderer * renderer, + SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_Rect * dstrect); +static void NDS_RenderPresent(SDL_Renderer * renderer); +static void NDS_DestroyTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void NDS_DestroyRenderer(SDL_Renderer * renderer); + + +SDL_RenderDriver NDS_RenderDriver = { + NDS_CreateRenderer, + {"nds", /* char* name */ + (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC), /* u32 flags */ + (SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */ + (SDL_TEXTUREBLENDMODE_MASK), /* u32 blend_modes */ + (SDL_TEXTURESCALEMODE_FAST), /* u32 scale_modes */ + 3, /* u32 num_texture_formats */ + { + SDL_PIXELFORMAT_INDEX8, + SDL_PIXELFORMAT_ABGR1555, + SDL_PIXELFORMAT_BGR555, + }, /* u32 texture_formats[20] */ + (256), /* int max_texture_width */ + (256), /* int max_texture_height */ + } +}; + +typedef struct +{ + bg_attribute *bg; /* backgrounds */ + tOAM oam_copy; /* sprites */ + u8 bg_taken[4]; + int sub; +} NDS_RenderData; + +typedef struct +{ + enum + { NDSTX_BG, NDSTX_SPR } type; /* represented in a bg or sprite. */ + int hw_index; /* sprite: index in the OAM. / bg: 2 or 3. */ + struct + { + int hdx, hdy, vdx, vdy; /* affine transformation, used for scaling. */ + int pitch, bpp; /* some useful info */ + } dim; + u16 *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */ + u16 *vram_palette; /* where the palette data is stored if it's indexed. */ + /*int size; */ +} NDS_TextureData; + + + +SDL_Renderer * +NDS_CreateRenderer(SDL_Window * window, Uint32 flags) +{ + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + SDL_DisplayMode *displayMode = &display->current_mode; + SDL_Renderer *renderer; + NDS_RenderData *data; + int i, n; + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, + &Rmask, &Gmask, &Bmask, &Amask)) { + SDL_SetError("Unknown display format"); + return NULL; + } + switch (displayMode->format) { + case SDL_PIXELFORMAT_INDEX8: + case SDL_PIXELFORMAT_ABGR1555: + case SDL_PIXELFORMAT_BGR555: + /* okay */ + break; + case SDL_PIXELFORMAT_RGB555: + case SDL_PIXELFORMAT_RGB565: + case SDL_PIXELFORMAT_ARGB1555: + /* we'll take these too for now */ + break; + default: + SDL_SetError("Warning: wrong display format for NDS!\n"); + break; + } + + renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); + if (!renderer) { + SDL_OutOfMemory(); + return NULL; + } + + data = (NDS_RenderData *) SDL_malloc(sizeof(*data)); + if (!data) { + NDS_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + SDL_zerop(data); + + renderer->RenderFill = NDS_RenderFill; + renderer->RenderCopy = NDS_RenderCopy; + renderer->RenderPresent = NDS_RenderPresent; + renderer->DestroyRenderer = NDS_DestroyRenderer; + renderer->info.name = NDS_RenderDriver.info.name; + renderer->info.flags = 0; + renderer->window = window->id; + renderer->driverdata = data; + renderer->CreateTexture = NDS_CreateTexture; + renderer->QueryTexturePixels = NDS_QueryTexturePixels; + renderer->SetTexturePalette = NDS_SetTexturePalette; + renderer->GetTexturePalette = NDS_GetTexturePalette; + renderer->SetTextureColorMod = NDS_SetTextureColorMod; + renderer->SetTextureAlphaMod = NDS_SetTextureAlphaMod; + renderer->SetTextureBlendMode = NDS_SetTextureBlendMode; + renderer->SetTextureScaleMode = NDS_SetTextureScaleMode; + renderer->UpdateTexture = NDS_UpdateTexture; + renderer->LockTexture = NDS_LockTexture; + renderer->UnlockTexture = NDS_UnlockTexture; + renderer->DirtyTexture = NDS_DirtyTexture; + renderer->DestroyTexture = NDS_DestroyTexture; + + renderer->info.mod_modes = NDS_RenderDriver.info.mod_modes; + renderer->info.blend_modes = NDS_RenderDriver.info.blend_modes; + renderer->info.scale_modes = NDS_RenderDriver.info.scale_modes; + renderer->info.num_texture_formats = + NDS_RenderDriver.info.num_texture_formats; + SDL_memcpy(renderer->info.texture_formats, + NDS_RenderDriver.info.texture_formats, + sizeof(renderer->info.texture_formats)); + renderer->info.max_texture_width = + NDS_RenderDriver.info.max_texture_width; + renderer->info.max_texture_height = + NDS_RenderDriver.info.max_texture_height; + + data->sub = 0; /* TODO: this is hard-coded to the "main" screen. + figure out how to detect whether to set it to + "sub" screen. window->id, perhaps? */ + if (!data->sub) { + data->bg = &BACKGROUND; + } else { + data->bg = &BACKGROUND_SUB; + } + data->bg_taken[2] = data->bg_taken[3] = 0; + + NDS_OAM_Init(&(data->oam_copy), data->sub); /* init sprites. */ + + return renderer; +} + +static int +NDS_ActivateRenderer(SDL_Renderer * renderer) +{ + NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; + + return 0; +} + +static int +NDS_DisplayModeChanged(SDL_Renderer * renderer) +{ + NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; + + return 0; +} + +static int +NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; + NDS_TextureData *txdat = NULL; + int i; + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + if (!SDL_PixelFormatEnumToMasks + (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { + SDL_SetError("Unknown texture format"); + return -1; + } + + /* conditional statements on w/h to place it as bg/sprite + depending on which one it fits. */ + if (texture->w <= 64 && texture->h <= 64) { + int whichspr = -1; + printf("Tried to make a sprite.\n"); + txdat->type = NDSTX_SPR; + for (i = 0; i < SPRITE_COUNT; ++i) { + if (data->oam_copy.spriteBuffer[i].attribute[0] & ATTR0_DISABLED) { + whichspr = i; + break; + } + } + if (whichspr >= 0) { + SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]); + int maxside = texture->w > texture->h ? texture->w : texture->h; + int pitch; + + texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); + txdat = (NDS_TextureData *) texture->driverdata; + if (!txdat) { + SDL_OutOfMemory(); + return -1; + } + + sprent->objMode = OBJMODE_BITMAP; + sprent->posX = 0; + sprent->posY = 0; + sprent->colMode = OBJCOLOR_16; /* OBJCOLOR_256 for INDEX8 */ + + /* the first 32 sprites get transformation matrices. + first come, first served */ + if (whichspr < MATRIX_COUNT) { + sprent->isRotoscale = 1; + sprent->rsMatrixIdx = whichspr; + } + + /* containing shape (square or 2:1 rectangles) */ + sprent->objShape = OBJSHAPE_SQUARE; + if (texture->w / 2 >= texture->h) { + sprent->objShape = OBJSHAPE_WIDE; + } else if (texture->h / 2 >= texture->w) { + sprent->objShape = OBJSHAPE_TALL; + } + + /* size in pixels */ + /* FIXME: "pitch" is hardcoded for 2bytes per pixel. */ + sprent->objSize = OBJSIZE_64; + pitch = 128; + if (maxside <= 8) { + sprent->objSize = OBJSIZE_8; + pitch = 16; + } else if (maxside <= 16) { + sprent->objSize = OBJSIZE_16; + pitch = 32; + } else if (maxside <= 32) { + sprent->objSize = OBJSIZE_32; + pitch = 64; + } + + /* FIXME: this is hard-coded and will obviously only work for one + sprite-texture. tells it to look at the beginning of SPRITE_GFX + for its pixels. */ + sprent->tileIdx = 0; + + /* now for the texture data */ + txdat->type = NDSTX_SPR; + txdat->hw_index = whichspr; + txdat->dim.hdx = 0x100; + txdat->dim.hdy = 0; + txdat->dim.vdx = 0; + txdat->dim.vdy = 0x100; + txdat->dim.pitch = pitch; + txdat->dim.bpp = bpp; + txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX); /* FIXME: use tileIdx*boundary + to point to proper location */ + } else { + SDL_SetError("Out of NDS sprites."); + } + } else if (texture->w <= 256 && texture->h <= 256) { + int whichbg = -1, base = 0; + if (!data->bg_taken[2]) { + whichbg = 2; + } else if (!data->bg_taken[3]) { + whichbg = 3; + base = 4; + } + if (whichbg >= 0) { + texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); + txdat = (NDS_TextureData *) texture->driverdata; + if (!txdat) { + SDL_OutOfMemory(); + return -1; + } + + /* this is hard-coded to being 256x256 ABGR1555 for now. */ + data->bg->control[whichbg] = (bpp == 8) ? + BG_BMP8_256x256 : BG_BMP16_256x256; + + data->bg->control[whichbg] |= BG_BMP_BASE(base); + + data->bg->scroll[whichbg].x = 0; + data->bg->scroll[whichbg].y = 0; + + txdat->type = NDSTX_BG; + txdat->hw_index = whichbg; + txdat->dim.hdx = 0x100; + txdat->dim.hdy = 0; + txdat->dim.vdx = 0; + txdat->dim.vdy = 0x100; + txdat->dim.pitch = 512; + txdat->dim.bpp = bpp; + txdat->vram_pixels = (u16 *) (data->sub ? + BG_BMP_RAM_SUB(base) : + BG_BMP_RAM(base)); + + /*txdat->size = txdat->dim.pitch * texture->h; */ + } else { + SDL_SetError("Out of NDS backgrounds."); + } + } else { + SDL_SetError("Texture too big for NDS hardware."); + } + + if (!texture->driverdata) { + return -1; + } + + return 0; +} + +static int +NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, + void **pixels, int *pitch) +{ + NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; + *pixels = txdat->vram_pixels; + *pitch = txdat->dim.pitch; + return 0; +} + +static int +NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, int pitch) +{ + NDS_TextureData *txdat; + Uint8 *src, *dst; + int row; + size_t length; + + txdat = (NDS_TextureData *) texture->driverdata; + + src = (Uint8 *) pixels; + dst = + (Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch + + rect->x * ((txdat->dim.bpp + 1) / 8); + length = rect->w * ((txdat->dim.bpp + 1) / 8); + + if (rect->w == texture->w) { + dmaCopy(src, dst, length * rect->h); + } else { + for (row = 0; row < rect->h; ++row) { + dmaCopy(src, dst, length); + src += pitch; + dst += txdat->dim.pitch; + } + } + + return 0; +} + +static int +NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, void **pixels, + int *pitch) +{ + NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; + + *pixels = (void *) ((u8 *) txdat->vram_pixels + rect->y + * txdat->dim.pitch + + rect->x * ((txdat->dim.bpp + 1) / 8)); + *pitch = txdat->dim.pitch; + + return 0; +} + +static void +NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + /* stub! */ +} + +static void +NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, + int numrects, const SDL_Rect * rects) +{ + /* stub! */ +} + +static int +NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, + Uint8 a, const SDL_Rect * rect) +{ + NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; + SDL_Rect real_rect = *rect; + u16 color; + int i, j; + + 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) + let R be the rectangle's width (maybe 50 pixels) + HDX = (R<<8) / S; + (it's fixed point, hence the bit shift. same goes for vertical. + be sure to use 32-bit int's for the bit shift before the division!) + */ + + return 0; +} + +static int +NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_Rect * dstrect) +{ + NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; + NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + int i; + int bpp = SDL_BYTESPERPIXEL(texture->format); + int pitch = txdat->dim.pitch; + + if (txdat->type == NDSTX_BG) { + bg_rotation *bgrot = (txdat->hw_index == 2) ? + &(data->bg->bg2_rotation) : &(data->bg->bg3_rotation); + bgrot->xdx = txdat->dim.hdx; + bgrot->xdy = txdat->dim.hdy; + bgrot->ydx = txdat->dim.vdx; + bgrot->ydy = txdat->dim.vdy; + bgrot->centerX = 0; + bgrot->centerY = 0; + + data->bg->scroll[txdat->hw_index].x = dstrect->x; + data->bg->scroll[txdat->hw_index].y = dstrect->y; + } else { + /* sprites not fully implemented yet */ + SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]); + spr->posX = dstrect->x; + spr->posY = dstrect->y; + if (txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) { + SpriteRotation *sprot = + &(data->oam_copy.matrixBuffer[txdat->hw_index]); + sprot->hdx = txdat->dim.hdx; + sprot->hdy = txdat->dim.hdy; + sprot->vdx = txdat->dim.vdx; + sprot->vdy = txdat->dim.vdy; + } + } + + return 0; +} + + +static void +NDS_RenderPresent(SDL_Renderer * renderer) +{ + NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + + /* update sprites */ + NDS_OAM_Update(&(data->oam_copy), data->sub); + /* vsync for NDS */ + if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { + swiWaitForVBlank(); + } +} + +static void +NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + NDS_TextureData *txdat = texture->driverdata; + /* free anything else allocated for texture */ + SDL_free(txdat); +} + +static void +NDS_DestroyRenderer(SDL_Renderer * renderer) +{ + NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); + int i; + + if (data) { + /* free anything else relevant if anything else is allocated. */ + SDL_free(data); + } + SDL_free(renderer); +} + +static int +NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, int ncolors) +{ + NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; + /* set 8-bit modes in the background control registers + for backgrounds, BGn_CR |= BG_256_COLOR */ + + return 0; +} + +static int +NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + SDL_Color * colors, int firstcolor, int ncolors) +{ + NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; + /* stub! */ + return 0; +} + +static int +NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) +{ + /* stub! */ + return 0; +} + +static int +NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) +{ + /* stub! */ + return 0; +} + +static int +NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) +{ + /* stub! */ + return 0; +} + +static int +NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) +{ + /* stub! (note: NDS hardware scaling is nearest neighbor.) */ + return 0; +} + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsrender_c.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ +#include "SDL_config.h" + +/* SDL surface based renderer implementation */ + +extern SDL_RenderDriver NDS_RenderDriver; + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,168 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ +#include "SDL_config.h" + +/* SDL Nintendo DS video driver implementation + * based on dummy driver: + * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion + * of this was cut-and-pasted from Stephane Peter's work in the AAlib + * SDL video driver. Renamed to "DUMMY" by Sam Lantinga. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <nds.h> +#include <nds/arm9/video.h> + +#include "SDL_video.h" +#include "SDL_mouse.h" +#include "../SDL_sysvideo.h" +#include "../SDL_pixels_c.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_ndsvideo.h" +#include "SDL_ndsevents_c.h" +#include "SDL_ndsrender_c.h" + +#define NDSVID_DRIVER_NAME "nds" + +/* Initialization/Query functions */ +static int NDS_VideoInit(_THIS); +static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); +static void NDS_VideoQuit(_THIS); + + +/* SDL NDS driver bootstrap functions */ +static int +NDS_Available(void) +{ + return (1); /* always here */ +} + +static void +NDS_DeleteDevice(SDL_VideoDevice * device) +{ + SDL_free(device); +} + +static SDL_VideoDevice * +NDS_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (!device) { + SDL_OutOfMemory(); + if (device) { + SDL_free(device); + } + return (0); + } + + /* Set the function pointers */ + device->VideoInit = NDS_VideoInit; + device->VideoQuit = NDS_VideoQuit; + device->SetDisplayMode = NDS_SetDisplayMode; + device->PumpEvents = NDS_PumpEvents; + + device->num_displays = 2; /* DS = dual screens */ + + device->free = NDS_DeleteDevice; + + return device; +} + +VideoBootStrap NDS_bootstrap = { + NDSVID_DRIVER_NAME, "SDL NDS video driver", + NDS_Available, NDS_CreateDevice +}; + +int +NDS_VideoInit(_THIS) +{ + SDL_DisplayMode mode; + int i; + + /* simple 256x192x16x60 for now */ + mode.w = 256; + mode.h = 192; + mode.format = SDL_PIXELFORMAT_ABGR1555; + mode.refresh_rate = 60; + mode.driverdata = NULL; + + SDL_AddBasicVideoDisplay(&mode); + SDL_AddRenderDriver(0, &NDS_RenderDriver); + + SDL_zero(mode); + SDL_AddDisplayMode(0, &mode); + + powerON(POWER_ALL_2D); + irqInit(); + irqEnable(IRQ_VBLANK); + NDS_SetDisplayMode(_this, &mode); + + return 0; +} + +static int +NDS_SetDisplayMode(_THIS, 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.) */ + DISPLAY_SPR_ACTIVE | DISPLAY_SPR_EXT_PALETTE); /* display on main core + with lots of flags set for + flexibility/capacity to render */ + + /* hopefully these cover all the various things we might need to do */ + vramSetBankA(VRAM_A_MAIN_BG_0x06000000); + vramSetBankB(VRAM_B_MAIN_BG_0x06020000); + 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); + vramSetBankG(VRAM_G_BG_EXT_PALETTE); + vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); + vramSetBankI(VRAM_I_SUB_SPRITE); + + videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub + TODO: this will change + when multi-head is + introduced in render */ + + return 0; +} + +void +NDS_VideoQuit(_THIS) +{ + videoSetMode(DISPLAY_SCREEN_OFF); + videoSetModeSub(DISPLAY_SCREEN_OFF); + vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); + vramSetBankE(VRAM_E_LCD); + vramSetBankF(VRAM_F_LCD); + vramSetBankG(VRAM_G_LCD); + vramSetBankH(VRAM_H_LCD); + vramSetBankI(VRAM_I_LCD); +} + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsvideo.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,31 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 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 +*/ +#include "SDL_config.h" + +#ifndef _SDL_ndsvideo_h +#define _SDL_ndsvideo_h + +#include "../SDL_sysvideo.h" + +#endif /* _SDL_ndsvideo_h */ + +/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/os2fslib/SDL_os2fslib.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/os2fslib/SDL_os2fslib.c Wed Aug 27 15:10:03 2008 +0000 @@ -440,8 +440,8 @@ if ((!pVideo->hidden->pSDLSurface) || ((pVideo->hidden->pSDLSurface) && - ((pVideo->hidden->pSDLSurface-> - flags & SDL_RESIZABLE) == 0))) + ((pVideo->hidden-> + pSDLSurface->flags & SDL_RESIZABLE) == 0))) FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd)); #ifdef DEBUG_BUILD else @@ -552,11 +552,11 @@ { iXScaleError = - (pVideo->hidden->SrcBufferDesc. - uiXResolution - 1) / swp.cx; + (pVideo->hidden->SrcBufferDesc.uiXResolution - + 1) / swp.cx; iYScaleError = - (pVideo->hidden->SrcBufferDesc. - uiYResolution - 1) / swp.cy; + (pVideo->hidden->SrcBufferDesc.uiYResolution - + 1) / swp.cy; if (iXScaleError < 0) iXScaleError = 0; if (iYScaleError < 0) @@ -577,24 +577,22 @@ iTop = (swp.cy - rcl.yTop) * - pVideo->hidden->SrcBufferDesc. - uiYResolution / swp.cy - iYScaleError; + pVideo->hidden->SrcBufferDesc.uiYResolution / + swp.cy - iYScaleError; iLeft = rcl.xLeft * - pVideo->hidden->SrcBufferDesc. - uiXResolution / swp.cx - iXScaleError; + pVideo->hidden->SrcBufferDesc.uiXResolution / + swp.cx - iXScaleError; iWidth = ((rcl.xRight - rcl.xLeft) * - pVideo->hidden->SrcBufferDesc. - uiXResolution + swp.cx - 1) / swp.cx + - 2 * iXScaleError; + pVideo->hidden->SrcBufferDesc.uiXResolution + + swp.cx - 1) / swp.cx + 2 * iXScaleError; iHeight = ((rcl.yTop - rcl.yBottom) * - pVideo->hidden->SrcBufferDesc. - uiYResolution + swp.cy - 1) / swp.cy + - 2 * iYScaleError; + pVideo->hidden->SrcBufferDesc.uiYResolution + + swp.cy - 1) / swp.cy + 2 * iYScaleError; iWidth += iXScaleError2; iHeight += iYScaleError2; @@ -606,20 +604,19 @@ if (iTop + iHeight > pVideo->hidden->SrcBufferDesc.uiYResolution) iHeight = - pVideo->hidden->SrcBufferDesc. - uiYResolution - iTop; + pVideo->hidden->SrcBufferDesc.uiYResolution - + iTop; if (iLeft + iWidth > pVideo->hidden->SrcBufferDesc.uiXResolution) iWidth = - pVideo->hidden->SrcBufferDesc. - uiXResolution - iLeft; + pVideo->hidden->SrcBufferDesc.uiXResolution - + iLeft; #ifdef DEBUG_BUILD printf ("WM_PAINT : BitBlt: %d %d -> %d %d (Buf %d x %d)\n", iTop, iLeft, iWidth, iHeight, - pVideo->hidden->SrcBufferDesc. - uiXResolution, + pVideo->hidden->SrcBufferDesc.uiXResolution, pVideo->hidden->SrcBufferDesc.uiYResolution); fflush(stdout); #endif @@ -693,15 +690,15 @@ WinQueryWindowPos(hwnd, &swp); if ((!pVideo->hidden->pSDLSurface) || ((pVideo->hidden->pSDLSurface) && - (pVideo->hidden->pSDLSurface-> - flags & SDL_RESIZABLE) + (pVideo->hidden-> + pSDLSurface->flags & SDL_RESIZABLE) && ((swp.cx != - pVideo->hidden->SrcBufferDesc. - uiXResolution) + pVideo->hidden-> + SrcBufferDesc.uiXResolution) || (swp.cy != - pVideo->hidden-> - SrcBufferDesc.uiYResolution)) + pVideo->hidden->SrcBufferDesc. + uiYResolution)) && (!FSLib_QueryFSMode(hwnd)))) { // Resizable surface and in resizing! // So, don't blit now! @@ -718,14 +715,12 @@ fflush(stdout); #endif FSLIB_BITBLT(hwnd, - pVideo->hidden-> - pchSrcBuffer, 0, + pVideo->hidden->pchSrcBuffer, 0, 0, pVideo->hidden-> - SrcBufferDesc. - uiXResolution, - pVideo->hidden-> - SrcBufferDesc.uiYResolution); + SrcBufferDesc.uiXResolution, + pVideo->hidden->SrcBufferDesc. + uiYResolution); } } #ifdef DEBUG_BUILD @@ -773,8 +768,8 @@ &swpClient); ptl.x = 0; ptl.y = 0; - WinMapWindowPoints(pVideo->hidden-> - hwndClient, HWND_DESKTOP, &ptl, 1); + WinMapWindowPoints(pVideo->hidden->hwndClient, + HWND_DESKTOP, &ptl, 1); pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ WinSetPointerPos(HWND_DESKTOP, ptl.x + swpClient.cx / 2, @@ -825,8 +820,8 @@ &swpClient); ptl.x = 0; ptl.y = 0; - WinMapWindowPoints(pVideo->hidden-> - hwndClient, HWND_DESKTOP, &ptl, 1); + WinMapWindowPoints(pVideo->hidden->hwndClient, + HWND_DESKTOP, &ptl, 1); pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ WinSetPointerPos(HWND_DESKTOP, ptl.x + swpClient.cx / 2, @@ -867,8 +862,8 @@ &swpClient); ptl.x = 0; ptl.y = 0; - WinMapWindowPoints(pVideo->hidden-> - hwndClient, HWND_DESKTOP, &ptl, 1); + WinMapWindowPoints(pVideo->hidden->hwndClient, + HWND_DESKTOP, &ptl, 1); pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ WinSetPointerPos(HWND_DESKTOP, ptl.x + swpClient.cx / 2, @@ -910,8 +905,8 @@ &swpClient); ptl.x = 0; ptl.y = 0; - WinMapWindowPoints(pVideo->hidden-> - hwndClient, HWND_DESKTOP, &ptl, 1); + WinMapWindowPoints(pVideo->hidden->hwndClient, + HWND_DESKTOP, &ptl, 1); pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ WinSetPointerPos(HWND_DESKTOP, ptl.x + swpClient.cx / 2, @@ -1378,6 +1373,7 @@ while (len-- > 0) *dst++ = ~*src++; } + static void memxor(Uint8 * dst, Uint8 * src1, Uint8 * src2, int len) { @@ -1635,6 +1631,7 @@ { return (-1); } + static void os2fslib_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -2505,23 +2502,27 @@ pResult = SDL_CreateRGBSurface(SDL_SWSURFACE, pModeInfoFound->uiXResolution, pModeInfoFound->uiYResolution, - pModeInfoFound->uiBPP, - ((unsigned int) pModeInfoFound-> - PixelFormat. - ucRedMask) << pModeInfoFound-> - PixelFormat.ucRedPosition, - ((unsigned int) pModeInfoFound-> - PixelFormat. - ucGreenMask) << pModeInfoFound-> - PixelFormat.ucGreenPosition, - ((unsigned int) pModeInfoFound-> - PixelFormat. - ucBlueMask) << pModeInfoFound-> - PixelFormat.ucBluePosition, - ((unsigned int) pModeInfoFound-> - PixelFormat. - ucAlphaMask) << pModeInfoFound-> - PixelFormat.ucAlphaPosition); + pModeInfoFound->uiBPP, ((unsigned int) + pModeInfoFound-> + PixelFormat. + ucRedMask) + << pModeInfoFound->PixelFormat. + ucRedPosition, ((unsigned int) + pModeInfoFound-> + PixelFormat. + ucGreenMask) + << pModeInfoFound->PixelFormat. + ucGreenPosition, ((unsigned int) + pModeInfoFound-> + PixelFormat. + ucBlueMask) + << pModeInfoFound->PixelFormat. + ucBluePosition, ((unsigned int) + pModeInfoFound-> + PixelFormat. + ucAlphaMask) + << pModeInfoFound->PixelFormat. + ucAlphaPosition); if (pResult == NULL) { DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer); @@ -2535,23 +2536,27 @@ // Adjust pixel format mask! pResult->format->Rmask = - ((unsigned int) pModeInfoFound->PixelFormat. - ucRedMask) << pModeInfoFound->PixelFormat.ucRedPosition; + ((unsigned int) pModeInfoFound-> + PixelFormat.ucRedMask) << pModeInfoFound->PixelFormat. + ucRedPosition; pResult->format->Rshift = pModeInfoFound->PixelFormat.ucRedPosition; pResult->format->Rloss = pModeInfoFound->PixelFormat.ucRedAdjust; pResult->format->Gmask = - ((unsigned int) pModeInfoFound->PixelFormat. - ucGreenMask) << pModeInfoFound->PixelFormat.ucGreenPosition; + ((unsigned int) pModeInfoFound-> + PixelFormat.ucGreenMask) << pModeInfoFound->PixelFormat. + ucGreenPosition; pResult->format->Gshift = pModeInfoFound->PixelFormat.ucGreenPosition; pResult->format->Gloss = pModeInfoFound->PixelFormat.ucGreenAdjust; pResult->format->Bmask = - ((unsigned int) pModeInfoFound->PixelFormat. - ucBlueMask) << pModeInfoFound->PixelFormat.ucBluePosition; + ((unsigned int) pModeInfoFound-> + PixelFormat.ucBlueMask) << pModeInfoFound->PixelFormat. + ucBluePosition; pResult->format->Bshift = pModeInfoFound->PixelFormat.ucBluePosition; pResult->format->Bloss = pModeInfoFound->PixelFormat.ucBlueAdjust; pResult->format->Amask = - ((unsigned int) pModeInfoFound->PixelFormat. - ucAlphaMask) << pModeInfoFound->PixelFormat.ucAlphaPosition; + ((unsigned int) pModeInfoFound-> + PixelFormat.ucAlphaMask) << pModeInfoFound->PixelFormat. + ucAlphaPosition; pResult->format->Ashift = pModeInfoFound->PixelFormat.ucAlphaPosition; pResult->format->Aloss = pModeInfoFound->PixelFormat.ucAlphaAdjust; @@ -2738,10 +2743,8 @@ for (i = 0; _this->hidden->pListModesResult[i]; i++) { iNumOfSlots++; if (iPlace == -1) { - if ((_this->hidden-> - pListModesResult[i]->w * - _this->hidden-> - pListModesResult[i]->h) < + if ((_this->hidden->pListModesResult[i]->w * + _this->hidden->pListModesResult[i]->h) < (pRect->w * pRect->h)) { iPlace = i; } @@ -2754,14 +2757,10 @@ // printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace); #endif - pNewList = - (SDL_Rect **) SDL_realloc(_this-> - hidden-> - pListModesResult, - (iNumOfSlots - + - 1) * - sizeof(SDL_Rect *)); + pNewList = (SDL_Rect **) + SDL_realloc(_this->hidden->pListModesResult, + (iNumOfSlots + + 1) * sizeof(SDL_Rect *)); if (pNewList) { for (i = iNumOfSlots; i > iPlace; i--) pNewList[i] = pNewList[i - 1]; @@ -2816,23 +2815,25 @@ vformat->BytesPerPixel = (vformat->BitsPerPixel + 7) / 8; vformat->Rmask = - ((unsigned int) pDesktopMode->PixelFormat.ucRedMask) << pDesktopMode-> - PixelFormat.ucRedPosition; + ((unsigned int) pDesktopMode->PixelFormat. + ucRedMask) << pDesktopMode->PixelFormat.ucRedPosition; vformat->Rshift = pDesktopMode->PixelFormat.ucRedPosition; vformat->Rloss = pDesktopMode->PixelFormat.ucRedAdjust; vformat->Gmask = - ((unsigned int) pDesktopMode->PixelFormat. - ucGreenMask) << pDesktopMode->PixelFormat.ucGreenPosition; + ((unsigned int) pDesktopMode-> + PixelFormat.ucGreenMask) << pDesktopMode->PixelFormat. + ucGreenPosition; vformat->Gshift = pDesktopMode->PixelFormat.ucGreenPosition; vformat->Gloss = pDesktopMode->PixelFormat.ucGreenAdjust; vformat->Bmask = - ((unsigned int) pDesktopMode->PixelFormat. - ucBlueMask) << pDesktopMode->PixelFormat.ucBluePosition; + ((unsigned int) pDesktopMode-> + PixelFormat.ucBlueMask) << pDesktopMode->PixelFormat.ucBluePosition; vformat->Bshift = pDesktopMode->PixelFormat.ucBluePosition; vformat->Bloss = pDesktopMode->PixelFormat.ucBlueAdjust; vformat->Amask = - ((unsigned int) pDesktopMode->PixelFormat. - ucAlphaMask) << pDesktopMode->PixelFormat.ucAlphaPosition; + ((unsigned int) pDesktopMode-> + PixelFormat.ucAlphaMask) << pDesktopMode->PixelFormat. + ucAlphaPosition; vformat->Ashift = pDesktopMode->PixelFormat.ucAlphaPosition; vformat->Aloss = pDesktopMode->PixelFormat.ucAlphaAdjust; @@ -2937,10 +2938,10 @@ sizeof(_this->hidden->SrcBufferDesc)); // Allocate new video buffer! _this->hidden->pchSrcBuffer = - (char *) SDL_malloc(_this->hidden->pAvailableFSLibVideoModes-> - uiScanLineSize * - _this->hidden->pAvailableFSLibVideoModes-> - uiYResolution); + (char *) SDL_malloc(_this->hidden-> + pAvailableFSLibVideoModes->uiScanLineSize * + _this->hidden-> + pAvailableFSLibVideoModes->uiYResolution); if (!_this->hidden->pchSrcBuffer) { #ifdef DEBUG_BUILD printf
--- a/src/video/photon/SDL_ph_gl.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/photon/SDL_ph_gl.c Wed Aug 27 15:10:03 2008 +0000 @@ -315,11 +315,14 @@ && (this->gl_config.accum_blue_size != 0) && (this->gl_config.accum_green_size != 0)) { qnxgl_attribs_slide = qnxgl_attrib_set_accum(qnxgl_attribs_slide, - this->gl_config. - accum_red_size + - this->gl_config. - accum_blue_size + - this->gl_config. + this-> + gl_config.accum_red_size + + + this-> + gl_config.accum_blue_size + + + this-> + gl_config. accum_green_size + this->gl_config. accum_alpha_size);
--- a/src/video/photon/SDL_ph_image.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/photon/SDL_ph_image.c Wed Aug 27 15:10:03 2008 +0000 @@ -244,9 +244,8 @@ } if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { - OCImage.FrameData1 = - (unsigned char *) PdGetOffscreenContextPtr(OCImage. - offscreen_backcontext); + OCImage.FrameData1 = (unsigned char *) + PdGetOffscreenContextPtr(OCImage.offscreen_backcontext); if (OCImage.FrameData1 == NULL) { SDL_SetError ("ph_SetupFullScreenImage(back): PdGetOffscreenContextPtr() function failed !\n");
--- a/src/video/photon/SDL_phyuv.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/photon/SDL_phyuv.c Wed Aug 27 15:10:03 2008 +0000 @@ -149,8 +149,8 @@ &overlay->hwdata->caps); if (rtncode == 0) { if (overlay->hwdata->caps.format == format) { - if ((overlay->hwdata->caps. - flags & Pg_SCALER_CAP_DST_CHROMA_KEY) == + if ((overlay->hwdata-> + caps.flags & Pg_SCALER_CAP_DST_CHROMA_KEY) == Pg_SCALER_CAP_DST_CHROMA_KEY) { overlay->hwdata->ischromakey = 1; } @@ -161,8 +161,7 @@ break; } i++; - } - while (1); + } while (1); if (vidport == -1) {
--- a/src/video/ps2gs/SDL_gsevents.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/ps2gs/SDL_gsevents.c Wed Aug 27 15:10:03 2008 +0000 @@ -479,9 +479,8 @@ if (select(fd + 1, &fdset, 0, 0, &tv) < 1) { break; } - } - while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && - ((ch == 0xFA) || (ch == 0xAA))); + } while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && + ((ch == 0xFA) || (ch == 0xAA))); /* Experimental values (Logitech wheelmouse) */ #ifdef DEBUG_MOUSE @@ -833,8 +832,7 @@ } } } - } - while (posted); + } while (posted); } void
--- a/src/video/ps2gs/SDL_gsvideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/ps2gs/SDL_gsvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -232,6 +232,7 @@ 0x0e, /* A+D */ 0, /* 2 */ PS2_GS_TEX0_1, (1 << 5) + (1 << 6), PS2_GS_TEX1_1, 0, PS2_GS_TEXFLUSH}; + static unsigned long long scale_tags[] __attribute__ ((aligned(16))) = { 5 | (1LL << 60), /* GIFtag */ 0x0e, /* A+D */ @@ -573,11 +574,13 @@ { return (-1); } + static void GS_FreeHWSurface(_THIS, SDL_Surface * surface) { return; } + static int GS_LockHWSurface(_THIS, SDL_Surface * surface) { @@ -606,6 +609,7 @@ } return (0); } + static void GS_UnlockHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/riscos/SDL_riscosvideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/riscos/SDL_riscosvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -286,6 +286,7 @@ { return (-1); } + static void RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/svga/SDL_svgaevents.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/svga/SDL_svgaevents.c Wed Aug 27 15:10:03 2008 +0000 @@ -207,8 +207,7 @@ posted = 0; mouse_update(); keyboard_update(); - } - while (posted); + } while (posted); } void
--- a/src/video/svga/SDL_svgavideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/svga/SDL_svgavideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -467,6 +467,7 @@ { return (-1); } + static void SVGA_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -480,6 +481,7 @@ /* The waiting is done in SVGA_FlipHWSurface() */ return (0); } + static void SVGA_UnlockHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/vgl/SDL_vglevents.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/vgl/SDL_vglevents.c Wed Aug 27 15:10:03 2008 +0000 @@ -141,8 +141,7 @@ posted = 0; handle_keyboard(this); handle_mouse(this); - } - while (posted != 0); + } while (posted != 0); } void
--- a/src/video/vgl/SDL_vglvideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/vgl/SDL_vglvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -409,6 +409,7 @@ { return -1; } + static void VGL_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -424,6 +425,7 @@ } return 0; } + static void VGL_UnlockHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/win32/SDL_d3drender.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/win32/SDL_d3drender.c Wed Aug 27 15:10:03 2008 +0000 @@ -596,8 +596,8 @@ result = IDirect3DDevice9_UpdateTexture(renderdata->device, (IDirect3DBaseTexture9 *) temp, - (IDirect3DBaseTexture9 *) data-> - texture); + (IDirect3DBaseTexture9 *) + data->texture); IDirect3DTexture9_Release(temp); if (FAILED(result)) { D3D_SetError("UpdateTexture()", result); @@ -805,9 +805,8 @@ } result = - IDirect3DDevice9_SetTexture(data->device, 0, - (IDirect3DBaseTexture9 *) texturedata-> - texture); + IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) + texturedata->texture); if (FAILED(result)) { D3D_SetError("SetTexture()", result); return -1;
--- a/src/video/win32/SDL_gdirender.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/win32/SDL_gdirender.c Wed Aug 27 15:10:03 2008 +0000 @@ -620,9 +620,8 @@ SelectPalette(data->memory_hdc, texturedata->hpal, TRUE); RealizePalette(data->memory_hdc); } - if (texture-> - blendMode & (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND)) - { + if (texture->blendMode & + (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND)) { BLENDFUNCTION blendFunc = { AC_SRC_OVER, 0,
--- a/src/video/win32/SDL_win32keyboard.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/win32/SDL_win32keyboard.c Wed Aug 27 15:10:03 2008 +0000 @@ -41,6 +41,7 @@ 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44 }; + BYTE keypad_scancodes[10] = { 82, 79, 80, 81, 75, 76, 77, 71, 72, 73 };
--- a/src/video/win32/SDL_win32opengl.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/win32/SDL_win32opengl.c Wed Aug 27 15:10:03 2008 +0000 @@ -500,8 +500,7 @@ if (_this->gl_config.accelerated >= 0) { *iAttr++ = WGL_ACCELERATION_ARB; *iAttr++ = - (_this->gl_config. - accelerated ? WGL_GENERIC_ACCELERATION_ARB : + (_this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB : WGL_NO_ACCELERATION_ARB); }
--- a/src/video/wscons/SDL_wsconsevents.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/wscons/SDL_wsconsevents.c Wed Aug 27 15:10:03 2008 +0000 @@ -145,8 +145,7 @@ posted = 0; updateMouse(); updateKeyboard(this); - } - while (posted); + } while (posted); } void
--- a/src/video/wscons/SDL_wsconsvideo.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/wscons/SDL_wsconsvideo.c Wed Aug 27 15:10:03 2008 +0000 @@ -399,6 +399,7 @@ { return -1; } + static void WSCONS_FreeHWSurface(_THIS, SDL_Surface * surface) {
--- a/src/video/x11/SDL_x11opengl.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/x11/SDL_x11opengl.c Wed Aug 27 15:10:03 2008 +0000 @@ -417,8 +417,8 @@ SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; int screen = - ((SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata)-> - screen; + ((SDL_DisplayData *) SDL_GetDisplayFromWindow(window)-> + driverdata)->screen; XWindowAttributes xattr; XVisualInfo v, *vinfo; int n;
--- a/src/video/xbios/SDL_xbiosmodes.c Wed Aug 27 13:37:19 2008 +0000 +++ b/src/video/xbios/SDL_xbiosmodes.c Wed Aug 27 15:10:03 2008 +0000 @@ -277,8 +277,8 @@ SDL_XBIOS_AddMode(_this, falcon_rgb_modes[i].width, falcon_rgb_modes[i].height, falcon_rgb_modes[i].bpp, - falcon_rgb_modes[i]. - modecode & modecodemask, SDL_FALSE); + falcon_rgb_modes[i].modecode & + modecodemask, SDL_FALSE); } break; case MONITOR_VGA: @@ -288,8 +288,8 @@ SDL_XBIOS_AddMode(_this, falcon_vga_modes[i].width, falcon_vga_modes[i].height, falcon_vga_modes[i].bpp, - falcon_vga_modes[i]. - modecode & modecodemask, SDL_FALSE); + falcon_vga_modes[i].modecode & + modecodemask, SDL_FALSE); } break; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/general/Makefile Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,132 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") +endif + +include $(DEVKITARM)/ds_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := $(shell basename $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -mthumb-interwork + +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD +# *insists* it has a FPU or VFP, and it won't take no for an answer! +CFLAGS := -save-temps -g -Wall -O0\ + -mcpu=arm9tdmi -mtune=arm9tdmi \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map) + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lSDL -lfat -lnds9 + + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBNDS) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).ds.gba : $(OUTPUT).nds +$(OUTPUT).nds : $(OUTPUT).arm9 +$(OUTPUT).arm9 : $(OUTPUT).elf +$(OUTPUT).elf : $(OFILES) + +#--------------------------------------------------------------------------------- +%.pcx.o : %.pcx +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#---------------------------------------------------------------------------------------
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/general/source/main.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,96 @@ + +#include <SDL/SDL.h> +#if defined(NDS) || defined(__NDS__) || defined (__NDS) +#include <nds.h> +#include <fat.h> +#else +#define swiWaitForVBlank() +#define consoleDemoInit() +#define fatInitDefault() +#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3)) +#endif + void +splash(SDL_Surface * screen, int s) +{ + SDL_Surface *logo; + SDL_Rect area = { 0, 0, 256, 192 }; + + logo = SDL_LoadBMP("sdl.bmp"); + if (!logo) { + printf("Couldn't splash.\n"); + return; + } + /*logo->flags &= ~SDL_PREALLOC; */ + SDL_BlitSurface(logo, NULL, screen, &area); + SDL_Flip(screen); + while (s-- > 0) { + int i = 60; + while (--i) + swiWaitForVBlank(); + } +} + + int +main(void) +{ + SDL_Surface *screen; + SDL_Joystick *stick; + SDL_Event event; + SDL_Rect rect = { 0, 0, 256, 192 }; + int i; + + consoleDemoInit(); + puts("Hello world! Initializing FAT..."); + fatInitDefault(); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { + puts("# error initializing SDL"); + puts(SDL_GetError()); + return 1; + } + puts("* initialized SDL"); + screen = SDL_SetVideoMode(256, 192, 15, SDL_SWSURFACE); + if (!screen) { + puts("# error setting video mode"); + puts(SDL_GetError()); + return 2; + } + screen->flags &= ~SDL_PREALLOC; + puts("* set video mode"); + stick = SDL_JoystickOpen(0); + if (stick == NULL) { + puts("# error opening joystick"); + puts(SDL_GetError()); +// return 3; + } + puts("* opened joystick"); + + /*splash(screen, 3); */ + + SDL_FillRect(screen, &rect, RGB15(0, 0, 31) | 0x8000); + SDL_Flip(screen); + + while (1) + while (SDL_PollEvent(&event)) + switch (event.type) { + case SDL_JOYBUTTONDOWN: + 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; + } + return 0; + } + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite/Makefile Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,132 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") +endif + +include $(DEVKITARM)/ds_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := $(shell basename $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -mthumb-interwork + +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD +# *insists* it has a FPU or VFP, and it won't take no for an answer! +CFLAGS := -save-temps -g -Wall -O0\ + -mcpu=arm9tdmi -mtune=arm9tdmi \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map) + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lSDL -lfat -lnds9 + + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBNDS) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).ds.gba : $(OUTPUT).nds +$(OUTPUT).nds : $(OUTPUT).arm9 +$(OUTPUT).arm9 : $(OUTPUT).elf +$(OUTPUT).elf : $(OFILES) + +#--------------------------------------------------------------------------------- +%.pcx.o : %.pcx +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#---------------------------------------------------------------------------------------
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite/source/common.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,965 @@ + +/* A simple test program framework */ + +#include <stdio.h> + +#include "common.h" + +#define VIDEO_USAGE \ +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]" + +#define AUDIO_USAGE \ +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" + +CommonState * +CommonCreateState(char **argv, Uint32 flags) +{ + CommonState *state = SDL_calloc(1, sizeof(*state)); + if (!state) { + SDL_OutOfMemory(); + return NULL; + } + + /* Initialize some defaults */ + state->argv = argv; + state->flags = flags; + state->window_title = argv[0]; + state->window_flags = SDL_WINDOW_SHOWN; + state->window_x = SDL_WINDOWPOS_UNDEFINED; + state->window_y = SDL_WINDOWPOS_UNDEFINED; + state->window_w = 256; + state->window_h = 192; + state->num_windows = 1; + state->audiospec.freq = 22050; + state->audiospec.format = AUDIO_S16; + state->audiospec.channels = 2; + state->audiospec.samples = 2048; + return state; +} + +int +CommonArg(CommonState * state, int index) +{ + char **argv = state->argv; + + if (SDL_strcasecmp(argv[index], "--video") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->videodriver = argv[index]; + return 2; + } + if (SDL_strcasecmp(argv[index], "--renderer") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->renderdriver = argv[index]; + return 2; + } + if (SDL_strcasecmp(argv[index], "--info") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + if (SDL_strcasecmp(argv[index], "all") == 0) { + state->verbose |= + (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER | + VERBOSE_EVENT); + return 2; + } + if (SDL_strcasecmp(argv[index], "video") == 0) { + state->verbose |= VERBOSE_VIDEO; + return 2; + } + if (SDL_strcasecmp(argv[index], "modes") == 0) { + state->verbose |= VERBOSE_MODES; + return 2; + } + if (SDL_strcasecmp(argv[index], "render") == 0) { + state->verbose |= VERBOSE_RENDER; + return 2; + } + if (SDL_strcasecmp(argv[index], "event") == 0) { + state->verbose |= VERBOSE_EVENT; + return 2; + } + return -1; + } + if (SDL_strcasecmp(argv[index], "--display") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->display = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) { + state->window_flags |= SDL_WINDOW_FULLSCREEN; + state->num_windows = 1; + return 1; + } + if (SDL_strcasecmp(argv[index], "--windows") == 0) { + ++index; + if (!argv[index] || !SDL_isdigit(*argv[index])) { + return -1; + } + if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) { + state->num_windows = SDL_atoi(argv[index]); + } + return 2; + } + if (SDL_strcasecmp(argv[index], "--title") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->window_title = argv[index]; + return 2; + } + if (SDL_strcasecmp(argv[index], "--center") == 0) { + state->window_x = SDL_WINDOWPOS_CENTERED; + state->window_y = SDL_WINDOWPOS_CENTERED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--position") == 0) { + char *x, *y; + ++index; + if (!argv[index]) { + return -1; + } + x = argv[index]; + y = argv[index]; + while (*y && *y != ',') { + ++y; + } + if (!*y) { + return -1; + } + *y++ = '\0'; + state->window_x = SDL_atoi(x); + state->window_y = SDL_atoi(y); + return 2; + } + if (SDL_strcasecmp(argv[index], "--geometry") == 0) { + char *w, *h; + ++index; + if (!argv[index]) { + return -1; + } + w = argv[index]; + h = argv[index]; + while (*h && *h != 'x') { + ++h; + } + if (!*h) { + return -1; + } + *h++ = '\0'; + state->window_w = SDL_atoi(w); + state->window_h = SDL_atoi(h); + return 2; + } + if (SDL_strcasecmp(argv[index], "--depth") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->depth = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--refresh") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->refresh_rate = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--vsync") == 0) { + state->render_flags |= SDL_RENDERER_PRESENTVSYNC; + return 1; + } + if (SDL_strcasecmp(argv[index], "--noframe") == 0) { + state->window_flags |= SDL_WINDOW_BORDERLESS; + return 1; + } + if (SDL_strcasecmp(argv[index], "--resize") == 0) { + state->window_flags |= SDL_WINDOW_RESIZABLE; + return 1; + } + if (SDL_strcasecmp(argv[index], "--minimize") == 0) { + state->window_flags |= SDL_WINDOW_MINIMIZED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--maximize") == 0) { + state->window_flags |= SDL_WINDOW_MAXIMIZED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--grab") == 0) { + state->window_flags |= SDL_WINDOW_INPUT_GRABBED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--rate") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->audiospec.freq = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--format") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + if (SDL_strcasecmp(argv[index], "U8") == 0) { + state->audiospec.format = AUDIO_U8; + return 2; + } + if (SDL_strcasecmp(argv[index], "S8") == 0) { + state->audiospec.format = AUDIO_S8; + return 2; + } + if (SDL_strcasecmp(argv[index], "U16") == 0) { + state->audiospec.format = AUDIO_U16; + return 2; + } + if (SDL_strcasecmp(argv[index], "U16LE") == 0) { + state->audiospec.format = AUDIO_U16LSB; + return 2; + } + if (SDL_strcasecmp(argv[index], "U16BE") == 0) { + state->audiospec.format = AUDIO_U16MSB; + return 2; + } + if (SDL_strcasecmp(argv[index], "S16") == 0) { + state->audiospec.format = AUDIO_S16; + return 2; + } + if (SDL_strcasecmp(argv[index], "S16LE") == 0) { + state->audiospec.format = AUDIO_S16LSB; + return 2; + } + if (SDL_strcasecmp(argv[index], "S16BE") == 0) { + state->audiospec.format = AUDIO_S16MSB; + return 2; + } + return -1; + } + if (SDL_strcasecmp(argv[index], "--channels") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->audiospec.channels = (Uint8) SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--samples") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->audiospec.samples = (Uint16) SDL_atoi(argv[index]); + return 2; + } + if ((SDL_strcasecmp(argv[index], "-h") == 0) + || (SDL_strcasecmp(argv[index], "--help") == 0)) { + /* Print the usage message */ + return -1; + } + return 0; +} + +const char * +CommonUsage(CommonState * state) +{ + switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { + case SDL_INIT_VIDEO: + return VIDEO_USAGE; + case SDL_INIT_AUDIO: + return AUDIO_USAGE; + case (SDL_INIT_VIDEO | SDL_INIT_AUDIO): + return VIDEO_USAGE " " AUDIO_USAGE; + default: + return ""; + } +} + +static void +PrintRendererFlag(Uint32 flag) +{ + switch (flag) { + case SDL_RENDERER_SINGLEBUFFER: + fprintf(stderr, "SingleBuffer"); + break; + case SDL_RENDERER_PRESENTCOPY: + fprintf(stderr, "PresentCopy"); + break; + case SDL_RENDERER_PRESENTFLIP2: + fprintf(stderr, "PresentFlip2"); + break; + case SDL_RENDERER_PRESENTFLIP3: + fprintf(stderr, "PresentFlip3"); + break; + case SDL_RENDERER_PRESENTDISCARD: + fprintf(stderr, "PresentDiscard"); + break; + case SDL_RENDERER_PRESENTVSYNC: + fprintf(stderr, "PresentVSync"); + break; + case SDL_RENDERER_ACCELERATED: + fprintf(stderr, "Accelerated"); + break; + default: + fprintf(stderr, "0x%8.8x", flag); + break; + } +} + +static void +PrintBlendMode(Uint32 flag) +{ + switch (flag) { + case SDL_TEXTUREBLENDMODE_NONE: + fprintf(stderr, "None"); + break; + case SDL_TEXTUREBLENDMODE_MASK: + fprintf(stderr, "Mask"); + break; + case SDL_TEXTUREBLENDMODE_BLEND: + fprintf(stderr, "Blend"); + break; + case SDL_TEXTUREBLENDMODE_ADD: + fprintf(stderr, "Add"); + break; + case SDL_TEXTUREBLENDMODE_MOD: + fprintf(stderr, "Mod"); + break; + default: + fprintf(stderr, "0x%8.8x", flag); + break; + } +} + +static void +PrintScaleMode(Uint32 flag) +{ + switch (flag) { + case SDL_TEXTURESCALEMODE_NONE: + fprintf(stderr, "None"); + break; + case SDL_TEXTURESCALEMODE_FAST: + fprintf(stderr, "Fast"); + break; + case SDL_TEXTURESCALEMODE_SLOW: + fprintf(stderr, "Slow"); + break; + case SDL_TEXTURESCALEMODE_BEST: + fprintf(stderr, "Best"); + break; + default: + fprintf(stderr, "0x%8.8x", flag); + break; + } +} + +static void +PrintPixelFormat(Uint32 format) +{ + switch (format) { + case SDL_PIXELFORMAT_UNKNOWN: + fprintf(stderr, "Unknwon"); + break; + case SDL_PIXELFORMAT_INDEX1LSB: + fprintf(stderr, "Index1LSB"); + break; + case SDL_PIXELFORMAT_INDEX1MSB: + fprintf(stderr, "Index1MSB"); + break; + case SDL_PIXELFORMAT_INDEX4LSB: + fprintf(stderr, "Index4LSB"); + break; + case SDL_PIXELFORMAT_INDEX4MSB: + fprintf(stderr, "Index4MSB"); + break; + case SDL_PIXELFORMAT_INDEX8: + fprintf(stderr, "Index8"); + break; + case SDL_PIXELFORMAT_RGB332: + fprintf(stderr, "RGB332"); + break; + case SDL_PIXELFORMAT_RGB444: + fprintf(stderr, "RGB444"); + break; + case SDL_PIXELFORMAT_RGB555: + fprintf(stderr, "RGB555"); + break; + case SDL_PIXELFORMAT_ARGB4444: + fprintf(stderr, "ARGB4444"); + break; + case SDL_PIXELFORMAT_ARGB1555: + fprintf(stderr, "ARGB1555"); + break; + case SDL_PIXELFORMAT_RGB565: + fprintf(stderr, "RGB565"); + break; + case SDL_PIXELFORMAT_RGB24: + fprintf(stderr, "RGB24"); + break; + case SDL_PIXELFORMAT_BGR24: + fprintf(stderr, "BGR24"); + break; + case SDL_PIXELFORMAT_RGB888: + fprintf(stderr, "RGB888"); + break; + case SDL_PIXELFORMAT_BGR888: + fprintf(stderr, "BGR888"); + break; + case SDL_PIXELFORMAT_ARGB8888: + fprintf(stderr, "ARGB8888"); + break; + case SDL_PIXELFORMAT_RGBA8888: + fprintf(stderr, "RGBA8888"); + break; + case SDL_PIXELFORMAT_ABGR8888: + fprintf(stderr, "ABGR8888"); + break; + case SDL_PIXELFORMAT_BGRA8888: + fprintf(stderr, "BGRA8888"); + break; + case SDL_PIXELFORMAT_ARGB2101010: + fprintf(stderr, "ARGB2101010"); + break; + case SDL_PIXELFORMAT_YV12: + fprintf(stderr, "YV12"); + break; + case SDL_PIXELFORMAT_IYUV: + fprintf(stderr, "IYUV"); + break; + case SDL_PIXELFORMAT_YUY2: + fprintf(stderr, "YUY2"); + break; + case SDL_PIXELFORMAT_UYVY: + fprintf(stderr, "UYVY"); + break; + case SDL_PIXELFORMAT_YVYU: + fprintf(stderr, "YVYU"); + break; + case SDL_PIXELFORMAT_ABGR1555: + fprintf(stderr, "ABGR1555"); + break; + case SDL_PIXELFORMAT_BGR555: + fprintf(stderr, "BGR555"); + break; + default: + fprintf(stderr, "0x%8.8x", format); + break; + } +} + +static void +PrintRenderer(SDL_RendererInfo * info) +{ + int i, count; + + fprintf(stderr, " Renderer %s:\n", info->name); + + fprintf(stderr, " Flags: 0x%8.8X", info->flags); + fprintf(stderr, " ("); + count = 0; + for (i = 0; i < sizeof(info->flags) * 8; ++i) { + Uint32 flag = (1 << i); + if (info->flags & flag) { + if (count > 0) { + fprintf(stderr, " | "); + } + PrintRendererFlag(flag); + ++count; + } + } + fprintf(stderr, ")\n"); + + fprintf(stderr, " Blend: 0x%8.8X", info->blend_modes); + fprintf(stderr, " ("); + count = 0; + for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) { + Uint32 flag = (1 << i); + if (info->blend_modes & flag) { + if (count > 0) { + fprintf(stderr, " | "); + } + PrintBlendMode(flag); + ++count; + } + } + fprintf(stderr, ")\n"); + + fprintf(stderr, " Scale: 0x%8.8X", info->scale_modes); + fprintf(stderr, " ("); + count = 0; + for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) { + Uint32 flag = (1 << i); + if (info->scale_modes & flag) { + if (count > 0) { + fprintf(stderr, " | "); + } + PrintScaleMode(flag); + ++count; + } + } + fprintf(stderr, ")\n"); + + fprintf(stderr, " Texture formats (%d): ", info->num_texture_formats); + for (i = 0; i < (int) info->num_texture_formats; ++i) { + if (i > 0) { + fprintf(stderr, ", "); + } + PrintPixelFormat(info->texture_formats[i]); + } + fprintf(stderr, "\n"); + + if (info->max_texture_width || info->max_texture_height) { + fprintf(stderr, " Max Texture Size: %dx%d\n", + info->max_texture_width, info->max_texture_height); + } +} + +SDL_bool +CommonInit(CommonState * state) +{ + int i, j, m, n; + SDL_DisplayMode fullscreen_mode; + + if (state->flags & SDL_INIT_VIDEO) { + if (state->verbose & VERBOSE_VIDEO) { + n = SDL_GetNumVideoDrivers(); + if (n == 0) { + fprintf(stderr, "No built-in video drivers\n"); + } else { + fprintf(stderr, "Built-in video drivers:"); + for (i = 0; i < n; ++i) { + if (i > 0) { + fprintf(stderr, ","); + } + fprintf(stderr, " %s", SDL_GetVideoDriver(i)); + } + fprintf(stderr, "\n"); + } + } + if (SDL_VideoInit(state->videodriver, 0) < 0) { + fprintf(stderr, "Couldn't initialize video driver: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + if (state->verbose & VERBOSE_VIDEO) { + fprintf(stderr, "Video driver: %s\n", + SDL_GetCurrentVideoDriver()); + } + + if (state->verbose & VERBOSE_MODES) { + SDL_DisplayMode mode; + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + n = SDL_GetNumVideoDisplays(); + fprintf(stderr, "Number of displays: %d\n", n); + for (i = 0; i < n; ++i) { + fprintf(stderr, "Display %d:\n", i); + SDL_SelectVideoDisplay(i); + + SDL_GetDesktopDisplayMode(&mode); + SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, + &Bmask, &Amask); + fprintf(stderr, + " Current mode: %dx%d@%dHz, %d bits-per-pixel\n", + mode.w, mode.h, mode.refresh_rate, bpp); + if (Rmask || Gmask || Bmask) { + fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); + fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); + fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); + if (Amask) + fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); + } + + /* Print available fullscreen video modes */ + m = SDL_GetNumDisplayModes(); + if (m == 0) { + fprintf(stderr, "No available fullscreen video modes\n"); + } else { + fprintf(stderr, " Fullscreen video modes:\n"); + for (j = 0; j < m; ++j) { + SDL_GetDisplayMode(j, &mode); + SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, + &Gmask, &Bmask, &Amask); + fprintf(stderr, + " Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", + j, mode.w, mode.h, mode.refresh_rate, bpp); + if (Rmask || Gmask || Bmask) { + fprintf(stderr, " Red Mask = 0x%.8x\n", + Rmask); + fprintf(stderr, " Green Mask = 0x%.8x\n", + Gmask); + fprintf(stderr, " Blue Mask = 0x%.8x\n", + Bmask); + if (Amask) + fprintf(stderr, + " Alpha Mask = 0x%.8x\n", + Amask); + } + } + } + } + } + + SDL_SelectVideoDisplay(state->display); + if (state->verbose & VERBOSE_RENDER) { + SDL_RendererInfo info; + + n = SDL_GetNumRenderDrivers(); + if (n == 0) { + fprintf(stderr, "No built-in render drivers\n"); + } else { + fprintf(stderr, "Built-in render drivers:\n"); + for (i = 0; i < n; ++i) { + SDL_GetRenderDriverInfo(i, &info); + PrintRenderer(&info); + } + } + } + + switch (state->depth) { + case 8: + fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8; + break; + case 15: + fullscreen_mode.format = SDL_PIXELFORMAT_BGR555; + break; + case 16: + default: + fullscreen_mode.format = SDL_PIXELFORMAT_ABGR1555; + break; +/* NDS default: + fullscreen_mode.format = SDL_PIXELFORMAT_RGB888; + break;*/ + } + fullscreen_mode.w = state->window_w; + fullscreen_mode.h = state->window_h; + fullscreen_mode.refresh_rate = state->refresh_rate; + SDL_SetFullscreenDisplayMode(&fullscreen_mode); + + state->windows = + (SDL_WindowID *) SDL_malloc(state->num_windows * + sizeof(*state->windows)); + if (!state->windows) { + fprintf(stderr, "Out of memory!\n"); + return SDL_FALSE; + } + for (i = 0; i < state->num_windows; ++i) { + char title[1024]; + + if (state->num_windows > 1) { + SDL_snprintf(title, SDL_arraysize(title), "%s %d", + state->window_title, i + 1); + } else { + SDL_strlcpy(title, state->window_title, SDL_arraysize(title)); + } + state->windows[i] = + SDL_CreateWindow(title, state->window_x, state->window_y, + state->window_w, state->window_h, + state->window_flags); + if (!state->windows[i]) { + fprintf(stderr, "Couldn't create window: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + + if (!state->skip_renderer + && (state->renderdriver + || !(state->window_flags & SDL_WINDOW_OPENGL))) { + m = -1; + if (state->renderdriver) { + SDL_RendererInfo info; + n = SDL_GetNumRenderDrivers(); + for (j = 0; j < n; ++j) { + SDL_GetRenderDriverInfo(j, &info); + if (SDL_strcasecmp(info.name, state->renderdriver) == + 0) { + m = j; + break; + } + } + if (m == n) { + fprintf(stderr, + "Couldn't find render driver named %s", + state->renderdriver); + return SDL_FALSE; + } + } + if (SDL_CreateRenderer + (state->windows[i], m, state->render_flags) < 0) { + fprintf(stderr, "Couldn't create renderer: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + if (state->verbose & VERBOSE_RENDER) { + SDL_RendererInfo info; + + fprintf(stderr, "Current renderer:\n"); + SDL_GetRendererInfo(&info); + PrintRenderer(&info); + } + } + } + SDL_SelectRenderer(state->windows[0]); + } + + if (state->flags & SDL_INIT_AUDIO) { + if (state->verbose & VERBOSE_AUDIO) { + n = SDL_GetNumAudioDrivers(); + if (n == 0) { + fprintf(stderr, "No built-in audio drivers\n"); + } else { + fprintf(stderr, "Built-in audio drivers:"); + for (i = 0; i < n; ++i) { + if (i > 0) { + fprintf(stderr, ","); + } + fprintf(stderr, " %s", SDL_GetAudioDriver(i)); + } + fprintf(stderr, "\n"); + } + } + if (SDL_AudioInit(state->audiodriver) < 0) { + fprintf(stderr, "Couldn't initialize audio driver: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + if (state->verbose & VERBOSE_VIDEO) { + fprintf(stderr, "Audio driver: %s\n", + SDL_GetCurrentAudioDriver()); + } + + if (SDL_OpenAudio(&state->audiospec, NULL) < 0) { + fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); + return SDL_FALSE; + } + } + + return SDL_TRUE; +} + +static void +PrintEvent(SDL_Event * event) +{ + fprintf(stderr, "SDL EVENT: "); + switch (event->type) { + case SDL_WINDOWEVENT: + switch (event->window.event) { + case SDL_WINDOWEVENT_SHOWN: + fprintf(stderr, "Window %d shown", event->window.windowID); + break; + case SDL_WINDOWEVENT_HIDDEN: + fprintf(stderr, "Window %d hidden", event->window.windowID); + break; + case SDL_WINDOWEVENT_EXPOSED: + fprintf(stderr, "Window %d exposed", event->window.windowID); + break; + case SDL_WINDOWEVENT_MOVED: + fprintf(stderr, "Window %d moved to %d,%d", + event->window.windowID, event->window.data1, + event->window.data2); + break; + case SDL_WINDOWEVENT_RESIZED: + fprintf(stderr, "Window %d resized to %dx%d", + event->window.windowID, event->window.data1, + event->window.data2); + break; + case SDL_WINDOWEVENT_MINIMIZED: + fprintf(stderr, "Window %d minimized", event->window.windowID); + break; + case SDL_WINDOWEVENT_MAXIMIZED: + fprintf(stderr, "Window %d maximized", event->window.windowID); + break; + case SDL_WINDOWEVENT_RESTORED: + fprintf(stderr, "Window %d restored", event->window.windowID); + break; + case SDL_WINDOWEVENT_ENTER: + fprintf(stderr, "Mouse entered window %d", + event->window.windowID); + break; + case SDL_WINDOWEVENT_LEAVE: + fprintf(stderr, "Mouse left window %d", event->window.windowID); + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + fprintf(stderr, "Window %d gained keyboard focus", + event->window.windowID); + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + fprintf(stderr, "Window %d lost keyboard focus", + event->window.windowID); + break; + case SDL_WINDOWEVENT_CLOSE: + fprintf(stderr, "Window %d closed", event->window.windowID); + break; + default: + fprintf(stderr, "Window %d got unknown event %d", + event->window.windowID, event->window.event); + break; + } + break; + case SDL_KEYDOWN: + fprintf(stderr, + "Keyboard %d: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s", + event->key.which, event->key.windowID, + event->key.keysym.scancode, + SDL_GetScancodeName(event->key.keysym.scancode), + event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); + break; + case SDL_KEYUP: + fprintf(stderr, + "Keyboard %d: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s", + event->key.which, event->key.windowID, + event->key.keysym.scancode, + SDL_GetScancodeName(event->key.keysym.scancode), + event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); + break; + case SDL_TEXTINPUT: + fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d", + event->text.which, event->text.text, event->text.windowID); + break; + case SDL_MOUSEMOTION: + fprintf(stderr, "Mouse %d: moved to %d,%d (%d,%d) in window %d", + event->motion.which, event->motion.x, event->motion.y, + event->motion.xrel, event->motion.yrel, + event->motion.windowID); + break; + case SDL_MOUSEBUTTONDOWN: + fprintf(stderr, "Mouse %d: button %d pressed at %d,%d in window %d", + event->button.which, event->button.button, event->button.x, + event->button.y, event->button.windowID); + break; + case SDL_MOUSEBUTTONUP: + fprintf(stderr, "Mouse %d: button %d released at %d,%d in window %d", + event->button.which, event->button.button, event->button.x, + event->button.y, event->button.windowID); + break; + case SDL_MOUSEWHEEL: + fprintf(stderr, + "Mouse %d: wheel scrolled %d in x and %d in y in window %d", + event->wheel.which, event->wheel.x, event->wheel.y, + event->wheel.windowID); + break; + case SDL_JOYBALLMOTION: + fprintf(stderr, "Joystick %d: ball %d moved by %d,%d", + event->jball.which, event->jball.ball, event->jball.xrel, + event->jball.yrel); + break; + case SDL_JOYHATMOTION: + fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which, + event->jhat.hat); + switch (event->jhat.value) { + case SDL_HAT_CENTERED: + fprintf(stderr, "CENTER"); + break; + case SDL_HAT_UP: + fprintf(stderr, "UP"); + break; + case SDL_HAT_RIGHTUP: + fprintf(stderr, "RIGHTUP"); + break; + case SDL_HAT_RIGHT: + fprintf(stderr, "RIGHT"); + break; + case SDL_HAT_RIGHTDOWN: + fprintf(stderr, "RIGHTDOWN"); + break; + case SDL_HAT_DOWN: + fprintf(stderr, "DOWN"); + break; + case SDL_HAT_LEFTDOWN: + fprintf(stderr, "LEFTDOWN"); + break; + case SDL_HAT_LEFT: + fprintf(stderr, "LEFT"); + break; + case SDL_HAT_LEFTUP: + fprintf(stderr, "LEFTUP"); + break; + default: + fprintf(stderr, "UNKNOWN"); + break; + } + break; + case SDL_JOYBUTTONDOWN: + fprintf(stderr, "Joystick %d: button %d pressed", + event->jbutton.which, event->jbutton.button); + break; + case SDL_JOYBUTTONUP: + fprintf(stderr, "Joystick %d: button %d released", + event->jbutton.which, event->jbutton.button); + break; + case SDL_QUIT: + fprintf(stderr, "Quit requested"); + break; + case SDL_USEREVENT: + fprintf(stderr, "User event %d", event->user.code); + break; + default: + fprintf(stderr, "Unknown event %d", event->type); + break; + } + fprintf(stderr, "\n"); +} + +void +CommonEvent(CommonState * state, SDL_Event * event, int *done) +{ + if (state->verbose & VERBOSE_EVENT) { + PrintEvent(event); + } + + switch (event->type) { + case SDL_WINDOWEVENT: + switch (event->window.event) { + case SDL_WINDOWEVENT_CLOSE: + *done = 1; + break; + } + break; + case SDL_KEYDOWN: + switch (event->key.keysym.sym) { + /* Add hotkeys here */ + case SDLK_g: + if (event->key.keysym.mod & KMOD_CTRL) { + /* Ctrl-G toggle grab */ + } + break; + case SDLK_ESCAPE: + *done = 1; + break; + default: + break; + } + break; + case SDL_QUIT: + *done = 1; + break; + } +} + +void +CommonQuit(CommonState * state) +{ + if (state->flags & SDL_INIT_VIDEO) { + SDL_VideoQuit(); + } + if (state->flags & SDL_INIT_AUDIO) { + SDL_AudioQuit(); + } + if (state->windows) { + SDL_free(state->windows); + } + SDL_free(state); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite/source/common.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,48 @@ + +/* A simple test program framework */ + +#include <SDL/SDL.h> + +#define VERBOSE_VIDEO 0x00000001 +#define VERBOSE_MODES 0x00000002 +#define VERBOSE_RENDER 0x00000004 +#define VERBOSE_EVENT 0x00000008 +#define VERBOSE_AUDIO 0x00000010 + +typedef struct +{ + /* SDL init flags */ + char **argv; + Uint32 flags; + Uint32 verbose; + + /* Video info */ + const char *videodriver; + int display; + const char *window_title; + Uint32 window_flags; + int window_x; + int window_y; + int window_w; + int window_h; + int depth; + int refresh_rate; + int num_windows; + SDL_WindowID *windows; + + /* Renderer info */ + const char *renderdriver; + Uint32 render_flags; + SDL_bool skip_renderer; + + /* Audio info */ + const char *audiodriver; + SDL_AudioSpec audiospec; +} CommonState; + +extern CommonState *CommonCreateState(char **argv, Uint32 flags); +extern int CommonArg(CommonState * state, int index); +extern const char *CommonUsage(CommonState * state); +extern SDL_bool CommonInit(CommonState * state); +extern void CommonEvent(CommonState * state, SDL_Event * event, int *done); +extern void CommonQuit(CommonState * state);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite/source/testsprite.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,316 @@ +/* Simple program: Move N sprites around on the screen as fast as possible */ + +#include <stdlib.h> +#include <stdio.h> +#include <time.h> +#include <math.h> +#include <fat.h> +#include <SDL/SDL.h> + +#define NUM_SPRITES 10 +#define MAX_SPEED 1 + +SDL_Surface *sprite; +int numsprites; +SDL_Rect *sprite_rects; +SDL_Rect *positions; +SDL_Rect *velocities; +int sprites_visible; +int debug_flip; +Uint16 sprite_w, sprite_h; + +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ +static void +quit(int rc) +{ + SDL_Quit(); + exit(rc); +} + +int +LoadSprite(char *file) +{ + SDL_Surface *temp; + + /* Load the sprite image */ + sprite = SDL_LoadBMP(file); + if (sprite == NULL) { + fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); + return (-1); + } + + /* Set transparent pixel as the pixel at (0,0) */ + if (sprite->format->palette) { + SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL), + *(Uint8 *) sprite->pixels); + } + + /* Convert sprite to video format */ + temp = SDL_DisplayFormat(sprite); + SDL_FreeSurface(sprite); + if (temp == NULL) { + fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError()); + return (-1); + } + sprite = temp; + + /* We're ready to roll. :) */ + return (0); +} + +void +MoveSprites(SDL_Surface * screen, Uint32 background) +{ + int i, nupdates; + SDL_Rect area, *position, *velocity; + + nupdates = 0; + /* Erase all the sprites if necessary */ + if (sprites_visible) { + SDL_FillRect(screen, NULL, background); + } + + /* Move the sprite, bounce at the wall, and draw */ + for (i = 0; i < numsprites; ++i) { + position = &positions[i]; + velocity = &velocities[i]; + position->x += velocity->x; + if ((position->x < 0) || (position->x >= (screen->w - sprite_w))) { + velocity->x = -velocity->x; + position->x += velocity->x; + } + position->y += velocity->y; + if ((position->y < 0) || (position->y >= (screen->h - sprite_w))) { + velocity->y = -velocity->y; + position->y += velocity->y; + } + + /* Blit the sprite onto the screen */ + area = *position; + SDL_BlitSurface(sprite, NULL, screen, &area); + sprite_rects[nupdates++] = area; + } + + if (debug_flip) { + if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { + static int t = 0; + + Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0); + SDL_Rect r; + r.x = t; +/* (sin((float) t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w - 20); */ + r.y = 0; + r.w = 20; + r.h = screen->h; + + SDL_FillRect(screen, &r, color); + t += 2; + } + } + + /* Update the screen! */ + if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { + SDL_Flip(screen); + } else { + SDL_UpdateRects(screen, nupdates, sprite_rects); + } + sprites_visible = 1; +} + +/* This is a way of telling whether or not to use hardware surfaces */ +Uint32 +FastestFlags(Uint32 flags, int width, int height, int bpp) +{ + const SDL_VideoInfo *info; + + /* Hardware acceleration is only used in fullscreen mode */ + flags |= SDL_FULLSCREEN; + + /* Check for various video capabilities */ + info = SDL_GetVideoInfo(); + if (info->blit_hw_CC && info->blit_fill) { + /* We use accelerated colorkeying and color filling */ + flags |= SDL_HWSURFACE; + } + /* If we have enough video memory, and will use accelerated + blits directly to it, then use page flipping. + */ + if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) { + /* Direct hardware blitting without double-buffering + causes really bad flickering. + */ + if (info->video_mem * 1024 > (height * width * bpp / 8)) { + flags |= SDL_DOUBLEBUF; + } else { + flags &= ~SDL_HWSURFACE; + } + } + + /* Return the flags */ + return (flags); +} + +int +main(int argc, char *argv[]) +{ + SDL_Surface *screen; + Uint8 *mem; + int width, height; + Uint8 video_bpp; + Uint32 videoflags; + Uint32 background; + int i, done; + SDL_Event event; + Uint32 then, now, frames; + + consoleDemoInit(); + puts("Hello world! Initializing FAT..."); + fatInitDefault(); + /* Initialize SDL */ + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + return (1); + } + puts("* initialized SDL"); + + numsprites = NUM_SPRITES; + videoflags = SDL_SWSURFACE /*| SDL_ANYFORMAT */ ; + width = 256; + height = 192; + video_bpp = 15; + debug_flip = 0; + while (argc > 1) { + --argc; + if (strcmp(argv[argc - 1], "-width") == 0) { + width = atoi(argv[argc]); + --argc; + } else if (strcmp(argv[argc - 1], "-height") == 0) { + height = atoi(argv[argc]); + --argc; + } else if (strcmp(argv[argc - 1], "-bpp") == 0) { + video_bpp = atoi(argv[argc]); + videoflags &= ~SDL_ANYFORMAT; + --argc; + } else if (strcmp(argv[argc], "-fast") == 0) { + videoflags = FastestFlags(videoflags, width, height, video_bpp); + } else if (strcmp(argv[argc], "-hw") == 0) { + videoflags ^= SDL_HWSURFACE; + } else if (strcmp(argv[argc], "-flip") == 0) { + videoflags ^= SDL_DOUBLEBUF; + } else if (strcmp(argv[argc], "-debugflip") == 0) { + debug_flip ^= 1; + } else if (strcmp(argv[argc], "-fullscreen") == 0) { + videoflags ^= SDL_FULLSCREEN; + } else if (isdigit(argv[argc][0])) { + numsprites = atoi(argv[argc]); + } else { + fprintf(stderr, + "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n", + argv[0]); + quit(1); + } + } + + /* Set video mode */ + screen = SDL_SetVideoMode(width, height, video_bpp, videoflags); + if (!screen) { + fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", + width, height, SDL_GetError()); + quit(2); + } + screen->flags &= ~SDL_PREALLOC; + puts("* set video mode"); + + /* Load the sprite */ + if (LoadSprite("icon.bmp") < 0) { + quit(1); + } + puts("* loaded sprite"); + + /* Allocate memory for the sprite info */ + mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites); + if (mem == NULL) { + SDL_FreeSurface(sprite); + fprintf(stderr, "Out of memory!\n"); + quit(2); + } + sprite_rects = (SDL_Rect *) mem; + positions = sprite_rects; + sprite_rects += numsprites; + velocities = sprite_rects; + sprite_rects += numsprites; + sprite_w = sprite->w; + sprite_h = sprite->h; + srand(time(NULL)); + for (i = 0; i < numsprites; ++i) { + positions[i].x = rand() % (screen->w - sprite_w); + positions[i].y = rand() % (screen->h - sprite_h); + positions[i].w = sprite->w; + positions[i].h = sprite->h; + velocities[i].x = 0; + velocities[i].y = 0; + while (!velocities[i].x && !velocities[i].y) { + velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; + velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; + } + } + background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); + + /* Print out information about our surfaces */ + printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel); + if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { + printf("Screen is in video memory\n"); + } else { + printf("Screen is in system memory\n"); + } + if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { + printf("Screen has double-buffering enabled\n"); + } + if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { + printf("Sprite is in video memory\n"); + } else { + printf("Sprite is in system memory\n"); + } + /* Run a sample blit to trigger blit acceleration */ + { + SDL_Rect dst; + dst.x = 0; + dst.y = 0; + dst.w = sprite->w; + dst.h = sprite->h; + SDL_BlitSurface(sprite, NULL, screen, &dst); + SDL_FillRect(screen, &dst, background); + } + if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) { + printf("Sprite blit uses hardware acceleration\n"); + } + if ((sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + printf("Sprite blit uses RLE acceleration\n"); + } + + /* Loop, blitting sprites and waiting for a keystroke */ + frames = 0; + then = SDL_GetTicks(); + done = 0; + sprites_visible = 0; + puts("hello!"); + while (!done) { + /* Check for events */ + ++frames; + printf("."); + swiWaitForVBlank(); + MoveSprites(screen, background); + } + puts("goodbye!"); + SDL_FreeSurface(sprite); + free(mem); + + /* Print out some timing information */ + now = SDL_GetTicks(); + if (now > then) { + printf("%2.2f frames per second\n", + ((double) frames * 1000) / (now - then)); + } + SDL_Quit(); + return (0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite2/Makefile Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,132 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") +endif + +include $(DEVKITARM)/ds_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := $(shell basename $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -mthumb-interwork + +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD +# *insists* it has a FPU or VFP, and it won't take no for an answer! +CFLAGS := -save-temps -g -Wall -O0\ + -mcpu=arm9tdmi -mtune=arm9tdmi \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DARM9 -D__NDS__ +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map) + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lSDL -lfat -lnds9 + + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBNDS) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).ds.gba : $(OUTPUT).nds +$(OUTPUT).nds : $(OUTPUT).arm9 +$(OUTPUT).arm9 : $(OUTPUT).elf +$(OUTPUT).elf : $(OFILES) + +#--------------------------------------------------------------------------------- +%.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#---------------------------------------------------------------------------------------
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite2/source/common.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,965 @@ + +/* A simple test program framework */ + +#include <stdio.h> + +#include "common.h" + +#define VIDEO_USAGE \ +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]" + +#define AUDIO_USAGE \ +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" + +CommonState * +CommonCreateState(char **argv, Uint32 flags) +{ + CommonState *state = SDL_calloc(1, sizeof(*state)); + if (!state) { + SDL_OutOfMemory(); + return NULL; + } + + /* Initialize some defaults */ + state->argv = argv; + state->flags = flags; + state->window_title = argv[0]; + state->window_flags = SDL_WINDOW_SHOWN; + state->window_x = SDL_WINDOWPOS_UNDEFINED; + state->window_y = SDL_WINDOWPOS_UNDEFINED; + state->window_w = 256; + state->window_h = 192; + state->num_windows = 1; + state->audiospec.freq = 22050; + state->audiospec.format = AUDIO_S16; + state->audiospec.channels = 2; + state->audiospec.samples = 2048; + return state; +} + +int +CommonArg(CommonState * state, int index) +{ + char **argv = state->argv; + + if (SDL_strcasecmp(argv[index], "--video") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->videodriver = argv[index]; + return 2; + } + if (SDL_strcasecmp(argv[index], "--renderer") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->renderdriver = argv[index]; + return 2; + } + if (SDL_strcasecmp(argv[index], "--info") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + if (SDL_strcasecmp(argv[index], "all") == 0) { + state->verbose |= + (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER | + VERBOSE_EVENT); + return 2; + } + if (SDL_strcasecmp(argv[index], "video") == 0) { + state->verbose |= VERBOSE_VIDEO; + return 2; + } + if (SDL_strcasecmp(argv[index], "modes") == 0) { + state->verbose |= VERBOSE_MODES; + return 2; + } + if (SDL_strcasecmp(argv[index], "render") == 0) { + state->verbose |= VERBOSE_RENDER; + return 2; + } + if (SDL_strcasecmp(argv[index], "event") == 0) { + state->verbose |= VERBOSE_EVENT; + return 2; + } + return -1; + } + if (SDL_strcasecmp(argv[index], "--display") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->display = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) { + state->window_flags |= SDL_WINDOW_FULLSCREEN; + state->num_windows = 1; + return 1; + } + if (SDL_strcasecmp(argv[index], "--windows") == 0) { + ++index; + if (!argv[index] || !SDL_isdigit(*argv[index])) { + return -1; + } + if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) { + state->num_windows = SDL_atoi(argv[index]); + } + return 2; + } + if (SDL_strcasecmp(argv[index], "--title") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->window_title = argv[index]; + return 2; + } + if (SDL_strcasecmp(argv[index], "--center") == 0) { + state->window_x = SDL_WINDOWPOS_CENTERED; + state->window_y = SDL_WINDOWPOS_CENTERED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--position") == 0) { + char *x, *y; + ++index; + if (!argv[index]) { + return -1; + } + x = argv[index]; + y = argv[index]; + while (*y && *y != ',') { + ++y; + } + if (!*y) { + return -1; + } + *y++ = '\0'; + state->window_x = SDL_atoi(x); + state->window_y = SDL_atoi(y); + return 2; + } + if (SDL_strcasecmp(argv[index], "--geometry") == 0) { + char *w, *h; + ++index; + if (!argv[index]) { + return -1; + } + w = argv[index]; + h = argv[index]; + while (*h && *h != 'x') { + ++h; + } + if (!*h) { + return -1; + } + *h++ = '\0'; + state->window_w = SDL_atoi(w); + state->window_h = SDL_atoi(h); + return 2; + } + if (SDL_strcasecmp(argv[index], "--depth") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->depth = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--refresh") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->refresh_rate = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--vsync") == 0) { + state->render_flags |= SDL_RENDERER_PRESENTVSYNC; + return 1; + } + if (SDL_strcasecmp(argv[index], "--noframe") == 0) { + state->window_flags |= SDL_WINDOW_BORDERLESS; + return 1; + } + if (SDL_strcasecmp(argv[index], "--resize") == 0) { + state->window_flags |= SDL_WINDOW_RESIZABLE; + return 1; + } + if (SDL_strcasecmp(argv[index], "--minimize") == 0) { + state->window_flags |= SDL_WINDOW_MINIMIZED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--maximize") == 0) { + state->window_flags |= SDL_WINDOW_MAXIMIZED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--grab") == 0) { + state->window_flags |= SDL_WINDOW_INPUT_GRABBED; + return 1; + } + if (SDL_strcasecmp(argv[index], "--rate") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->audiospec.freq = SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--format") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + if (SDL_strcasecmp(argv[index], "U8") == 0) { + state->audiospec.format = AUDIO_U8; + return 2; + } + if (SDL_strcasecmp(argv[index], "S8") == 0) { + state->audiospec.format = AUDIO_S8; + return 2; + } + if (SDL_strcasecmp(argv[index], "U16") == 0) { + state->audiospec.format = AUDIO_U16; + return 2; + } + if (SDL_strcasecmp(argv[index], "U16LE") == 0) { + state->audiospec.format = AUDIO_U16LSB; + return 2; + } + if (SDL_strcasecmp(argv[index], "U16BE") == 0) { + state->audiospec.format = AUDIO_U16MSB; + return 2; + } + if (SDL_strcasecmp(argv[index], "S16") == 0) { + state->audiospec.format = AUDIO_S16; + return 2; + } + if (SDL_strcasecmp(argv[index], "S16LE") == 0) { + state->audiospec.format = AUDIO_S16LSB; + return 2; + } + if (SDL_strcasecmp(argv[index], "S16BE") == 0) { + state->audiospec.format = AUDIO_S16MSB; + return 2; + } + return -1; + } + if (SDL_strcasecmp(argv[index], "--channels") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->audiospec.channels = (Uint8) SDL_atoi(argv[index]); + return 2; + } + if (SDL_strcasecmp(argv[index], "--samples") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->audiospec.samples = (Uint16) SDL_atoi(argv[index]); + return 2; + } + if ((SDL_strcasecmp(argv[index], "-h") == 0) + || (SDL_strcasecmp(argv[index], "--help") == 0)) { + /* Print the usage message */ + return -1; + } + return 0; +} + +const char * +CommonUsage(CommonState * state) +{ + switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { + case SDL_INIT_VIDEO: + return VIDEO_USAGE; + case SDL_INIT_AUDIO: + return AUDIO_USAGE; + case (SDL_INIT_VIDEO | SDL_INIT_AUDIO): + return VIDEO_USAGE " " AUDIO_USAGE; + default: + return ""; + } +} + +static void +PrintRendererFlag(Uint32 flag) +{ + switch (flag) { + case SDL_RENDERER_SINGLEBUFFER: + fprintf(stderr, "SingleBuffer"); + break; + case SDL_RENDERER_PRESENTCOPY: + fprintf(stderr, "PresentCopy"); + break; + case SDL_RENDERER_PRESENTFLIP2: + fprintf(stderr, "PresentFlip2"); + break; + case SDL_RENDERER_PRESENTFLIP3: + fprintf(stderr, "PresentFlip3"); + break; + case SDL_RENDERER_PRESENTDISCARD: + fprintf(stderr, "PresentDiscard"); + break; + case SDL_RENDERER_PRESENTVSYNC: + fprintf(stderr, "PresentVSync"); + break; + case SDL_RENDERER_ACCELERATED: + fprintf(stderr, "Accelerated"); + break; + default: + fprintf(stderr, "0x%8.8x", flag); + break; + } +} + +static void +PrintBlendMode(Uint32 flag) +{ + switch (flag) { + case SDL_TEXTUREBLENDMODE_NONE: + fprintf(stderr, "None"); + break; + case SDL_TEXTUREBLENDMODE_MASK: + fprintf(stderr, "Mask"); + break; + case SDL_TEXTUREBLENDMODE_BLEND: + fprintf(stderr, "Blend"); + break; + case SDL_TEXTUREBLENDMODE_ADD: + fprintf(stderr, "Add"); + break; + case SDL_TEXTUREBLENDMODE_MOD: + fprintf(stderr, "Mod"); + break; + default: + fprintf(stderr, "0x%8.8x", flag); + break; + } +} + +static void +PrintScaleMode(Uint32 flag) +{ + switch (flag) { + case SDL_TEXTURESCALEMODE_NONE: + fprintf(stderr, "None"); + break; + case SDL_TEXTURESCALEMODE_FAST: + fprintf(stderr, "Fast"); + break; + case SDL_TEXTURESCALEMODE_SLOW: + fprintf(stderr, "Slow"); + break; + case SDL_TEXTURESCALEMODE_BEST: + fprintf(stderr, "Best"); + break; + default: + fprintf(stderr, "0x%8.8x", flag); + break; + } +} + +static void +PrintPixelFormat(Uint32 format) +{ + switch (format) { + case SDL_PIXELFORMAT_UNKNOWN: + fprintf(stderr, "Unknwon"); + break; + case SDL_PIXELFORMAT_INDEX1LSB: + fprintf(stderr, "Index1LSB"); + break; + case SDL_PIXELFORMAT_INDEX1MSB: + fprintf(stderr, "Index1MSB"); + break; + case SDL_PIXELFORMAT_INDEX4LSB: + fprintf(stderr, "Index4LSB"); + break; + case SDL_PIXELFORMAT_INDEX4MSB: + fprintf(stderr, "Index4MSB"); + break; + case SDL_PIXELFORMAT_INDEX8: + fprintf(stderr, "Index8"); + break; + case SDL_PIXELFORMAT_RGB332: + fprintf(stderr, "RGB332"); + break; + case SDL_PIXELFORMAT_RGB444: + fprintf(stderr, "RGB444"); + break; + case SDL_PIXELFORMAT_RGB555: + fprintf(stderr, "RGB555"); + break; + case SDL_PIXELFORMAT_ARGB4444: + fprintf(stderr, "ARGB4444"); + break; + case SDL_PIXELFORMAT_ARGB1555: + fprintf(stderr, "ARGB1555"); + break; + case SDL_PIXELFORMAT_RGB565: + fprintf(stderr, "RGB565"); + break; + case SDL_PIXELFORMAT_RGB24: + fprintf(stderr, "RGB24"); + break; + case SDL_PIXELFORMAT_BGR24: + fprintf(stderr, "BGR24"); + break; + case SDL_PIXELFORMAT_RGB888: + fprintf(stderr, "RGB888"); + break; + case SDL_PIXELFORMAT_BGR888: + fprintf(stderr, "BGR888"); + break; + case SDL_PIXELFORMAT_ARGB8888: + fprintf(stderr, "ARGB8888"); + break; + case SDL_PIXELFORMAT_RGBA8888: + fprintf(stderr, "RGBA8888"); + break; + case SDL_PIXELFORMAT_ABGR8888: + fprintf(stderr, "ABGR8888"); + break; + case SDL_PIXELFORMAT_BGRA8888: + fprintf(stderr, "BGRA8888"); + break; + case SDL_PIXELFORMAT_ARGB2101010: + fprintf(stderr, "ARGB2101010"); + break; + case SDL_PIXELFORMAT_YV12: + fprintf(stderr, "YV12"); + break; + case SDL_PIXELFORMAT_IYUV: + fprintf(stderr, "IYUV"); + break; + case SDL_PIXELFORMAT_YUY2: + fprintf(stderr, "YUY2"); + break; + case SDL_PIXELFORMAT_UYVY: + fprintf(stderr, "UYVY"); + break; + case SDL_PIXELFORMAT_YVYU: + fprintf(stderr, "YVYU"); + break; + case SDL_PIXELFORMAT_ABGR1555: + fprintf(stderr, "ABGR1555"); + break; + case SDL_PIXELFORMAT_BGR555: + fprintf(stderr, "BGR555"); + break; + default: + fprintf(stderr, "0x%8.8x", format); + break; + } +} + +static void +PrintRenderer(SDL_RendererInfo * info) +{ + int i, count; + + fprintf(stderr, " Renderer %s:\n", info->name); + + fprintf(stderr, " Flags: 0x%8.8X", info->flags); + fprintf(stderr, " ("); + count = 0; + for (i = 0; i < sizeof(info->flags) * 8; ++i) { + Uint32 flag = (1 << i); + if (info->flags & flag) { + if (count > 0) { + fprintf(stderr, " | "); + } + PrintRendererFlag(flag); + ++count; + } + } + fprintf(stderr, ")\n"); + + fprintf(stderr, " Blend: 0x%8.8X", info->blend_modes); + fprintf(stderr, " ("); + count = 0; + for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) { + Uint32 flag = (1 << i); + if (info->blend_modes & flag) { + if (count > 0) { + fprintf(stderr, " | "); + } + PrintBlendMode(flag); + ++count; + } + } + fprintf(stderr, ")\n"); + + fprintf(stderr, " Scale: 0x%8.8X", info->scale_modes); + fprintf(stderr, " ("); + count = 0; + for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) { + Uint32 flag = (1 << i); + if (info->scale_modes & flag) { + if (count > 0) { + fprintf(stderr, " | "); + } + PrintScaleMode(flag); + ++count; + } + } + fprintf(stderr, ")\n"); + + fprintf(stderr, " Texture formats (%d): ", info->num_texture_formats); + for (i = 0; i < (int) info->num_texture_formats; ++i) { + if (i > 0) { + fprintf(stderr, ", "); + } + PrintPixelFormat(info->texture_formats[i]); + } + fprintf(stderr, "\n"); + + if (info->max_texture_width || info->max_texture_height) { + fprintf(stderr, " Max Texture Size: %dx%d\n", + info->max_texture_width, info->max_texture_height); + } +} + +SDL_bool +CommonInit(CommonState * state) +{ + int i, j, m, n; + SDL_DisplayMode fullscreen_mode; + + if (state->flags & SDL_INIT_VIDEO) { + if (state->verbose & VERBOSE_VIDEO) { + n = SDL_GetNumVideoDrivers(); + if (n == 0) { + fprintf(stderr, "No built-in video drivers\n"); + } else { + fprintf(stderr, "Built-in video drivers:"); + for (i = 0; i < n; ++i) { + if (i > 0) { + fprintf(stderr, ","); + } + fprintf(stderr, " %s", SDL_GetVideoDriver(i)); + } + fprintf(stderr, "\n"); + } + } + if (SDL_VideoInit(state->videodriver, 0) < 0) { + fprintf(stderr, "Couldn't initialize video driver: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + if (state->verbose & VERBOSE_VIDEO) { + fprintf(stderr, "Video driver: %s\n", + SDL_GetCurrentVideoDriver()); + } + + if (state->verbose & VERBOSE_MODES) { + SDL_DisplayMode mode; + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + n = SDL_GetNumVideoDisplays(); + fprintf(stderr, "Number of displays: %d\n", n); + for (i = 0; i < n; ++i) { + fprintf(stderr, "Display %d:\n", i); + SDL_SelectVideoDisplay(i); + + SDL_GetDesktopDisplayMode(&mode); + SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, + &Bmask, &Amask); + fprintf(stderr, + " Current mode: %dx%d@%dHz, %d bits-per-pixel\n", + mode.w, mode.h, mode.refresh_rate, bpp); + if (Rmask || Gmask || Bmask) { + fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); + fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); + fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); + if (Amask) + fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); + } + + /* Print available fullscreen video modes */ + m = SDL_GetNumDisplayModes(); + if (m == 0) { + fprintf(stderr, "No available fullscreen video modes\n"); + } else { + fprintf(stderr, " Fullscreen video modes:\n"); + for (j = 0; j < m; ++j) { + SDL_GetDisplayMode(j, &mode); + SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, + &Gmask, &Bmask, &Amask); + fprintf(stderr, + " Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", + j, mode.w, mode.h, mode.refresh_rate, bpp); + if (Rmask || Gmask || Bmask) { + fprintf(stderr, " Red Mask = 0x%.8x\n", + Rmask); + fprintf(stderr, " Green Mask = 0x%.8x\n", + Gmask); + fprintf(stderr, " Blue Mask = 0x%.8x\n", + Bmask); + if (Amask) + fprintf(stderr, + " Alpha Mask = 0x%.8x\n", + Amask); + } + } + } + } + } + + SDL_SelectVideoDisplay(state->display); + if (state->verbose & VERBOSE_RENDER) { + SDL_RendererInfo info; + + n = SDL_GetNumRenderDrivers(); + if (n == 0) { + fprintf(stderr, "No built-in render drivers\n"); + } else { + fprintf(stderr, "Built-in render drivers:\n"); + for (i = 0; i < n; ++i) { + SDL_GetRenderDriverInfo(i, &info); + PrintRenderer(&info); + } + } + } + + switch (state->depth) { + case 8: + fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8; + break; + case 15: + fullscreen_mode.format = SDL_PIXELFORMAT_BGR555; + break; + case 16: + default: + fullscreen_mode.format = SDL_PIXELFORMAT_ABGR1555; + break; +/* NDS default: + fullscreen_mode.format = SDL_PIXELFORMAT_RGB888; + break;*/ + } + fullscreen_mode.w = state->window_w; + fullscreen_mode.h = state->window_h; + fullscreen_mode.refresh_rate = state->refresh_rate; + SDL_SetFullscreenDisplayMode(&fullscreen_mode); + + state->windows = + (SDL_WindowID *) SDL_malloc(state->num_windows * + sizeof(*state->windows)); + if (!state->windows) { + fprintf(stderr, "Out of memory!\n"); + return SDL_FALSE; + } + for (i = 0; i < state->num_windows; ++i) { + char title[1024]; + + if (state->num_windows > 1) { + SDL_snprintf(title, SDL_arraysize(title), "%s %d", + state->window_title, i + 1); + } else { + SDL_strlcpy(title, state->window_title, SDL_arraysize(title)); + } + state->windows[i] = + SDL_CreateWindow(title, state->window_x, state->window_y, + state->window_w, state->window_h, + state->window_flags); + if (!state->windows[i]) { + fprintf(stderr, "Couldn't create window: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + + if (!state->skip_renderer + && (state->renderdriver + || !(state->window_flags & SDL_WINDOW_OPENGL))) { + m = -1; + if (state->renderdriver) { + SDL_RendererInfo info; + n = SDL_GetNumRenderDrivers(); + for (j = 0; j < n; ++j) { + SDL_GetRenderDriverInfo(j, &info); + if (SDL_strcasecmp(info.name, state->renderdriver) == + 0) { + m = j; + break; + } + } + if (m == n) { + fprintf(stderr, + "Couldn't find render driver named %s", + state->renderdriver); + return SDL_FALSE; + } + } + if (SDL_CreateRenderer + (state->windows[i], m, state->render_flags) < 0) { + fprintf(stderr, "Couldn't create renderer: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + if (state->verbose & VERBOSE_RENDER) { + SDL_RendererInfo info; + + fprintf(stderr, "Current renderer:\n"); + SDL_GetRendererInfo(&info); + PrintRenderer(&info); + } + } + } + SDL_SelectRenderer(state->windows[0]); + } + + if (state->flags & SDL_INIT_AUDIO) { + if (state->verbose & VERBOSE_AUDIO) { + n = SDL_GetNumAudioDrivers(); + if (n == 0) { + fprintf(stderr, "No built-in audio drivers\n"); + } else { + fprintf(stderr, "Built-in audio drivers:"); + for (i = 0; i < n; ++i) { + if (i > 0) { + fprintf(stderr, ","); + } + fprintf(stderr, " %s", SDL_GetAudioDriver(i)); + } + fprintf(stderr, "\n"); + } + } + if (SDL_AudioInit(state->audiodriver) < 0) { + fprintf(stderr, "Couldn't initialize audio driver: %s\n", + SDL_GetError()); + return SDL_FALSE; + } + if (state->verbose & VERBOSE_VIDEO) { + fprintf(stderr, "Audio driver: %s\n", + SDL_GetCurrentAudioDriver()); + } + + if (SDL_OpenAudio(&state->audiospec, NULL) < 0) { + fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); + return SDL_FALSE; + } + } + + return SDL_TRUE; +} + +static void +PrintEvent(SDL_Event * event) +{ + fprintf(stderr, "SDL EVENT: "); + switch (event->type) { + case SDL_WINDOWEVENT: + switch (event->window.event) { + case SDL_WINDOWEVENT_SHOWN: + fprintf(stderr, "Window %d shown", event->window.windowID); + break; + case SDL_WINDOWEVENT_HIDDEN: + fprintf(stderr, "Window %d hidden", event->window.windowID); + break; + case SDL_WINDOWEVENT_EXPOSED: + fprintf(stderr, "Window %d exposed", event->window.windowID); + break; + case SDL_WINDOWEVENT_MOVED: + fprintf(stderr, "Window %d moved to %d,%d", + event->window.windowID, event->window.data1, + event->window.data2); + break; + case SDL_WINDOWEVENT_RESIZED: + fprintf(stderr, "Window %d resized to %dx%d", + event->window.windowID, event->window.data1, + event->window.data2); + break; + case SDL_WINDOWEVENT_MINIMIZED: + fprintf(stderr, "Window %d minimized", event->window.windowID); + break; + case SDL_WINDOWEVENT_MAXIMIZED: + fprintf(stderr, "Window %d maximized", event->window.windowID); + break; + case SDL_WINDOWEVENT_RESTORED: + fprintf(stderr, "Window %d restored", event->window.windowID); + break; + case SDL_WINDOWEVENT_ENTER: + fprintf(stderr, "Mouse entered window %d", + event->window.windowID); + break; + case SDL_WINDOWEVENT_LEAVE: + fprintf(stderr, "Mouse left window %d", event->window.windowID); + break; + case SDL_WINDOWEVENT_FOCUS_GAINED: + fprintf(stderr, "Window %d gained keyboard focus", + event->window.windowID); + break; + case SDL_WINDOWEVENT_FOCUS_LOST: + fprintf(stderr, "Window %d lost keyboard focus", + event->window.windowID); + break; + case SDL_WINDOWEVENT_CLOSE: + fprintf(stderr, "Window %d closed", event->window.windowID); + break; + default: + fprintf(stderr, "Window %d got unknown event %d", + event->window.windowID, event->window.event); + break; + } + break; + case SDL_KEYDOWN: + fprintf(stderr, + "Keyboard %d: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s", + event->key.which, event->key.windowID, + event->key.keysym.scancode, + SDL_GetScancodeName(event->key.keysym.scancode), + event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); + break; + case SDL_KEYUP: + fprintf(stderr, + "Keyboard %d: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s", + event->key.which, event->key.windowID, + event->key.keysym.scancode, + SDL_GetScancodeName(event->key.keysym.scancode), + event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); + break; + case SDL_TEXTINPUT: + fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d", + event->text.which, event->text.text, event->text.windowID); + break; + case SDL_MOUSEMOTION: + fprintf(stderr, "Mouse %d: moved to %d,%d (%d,%d) in window %d", + event->motion.which, event->motion.x, event->motion.y, + event->motion.xrel, event->motion.yrel, + event->motion.windowID); + break; + case SDL_MOUSEBUTTONDOWN: + fprintf(stderr, "Mouse %d: button %d pressed at %d,%d in window %d", + event->button.which, event->button.button, event->button.x, + event->button.y, event->button.windowID); + break; + case SDL_MOUSEBUTTONUP: + fprintf(stderr, "Mouse %d: button %d released at %d,%d in window %d", + event->button.which, event->button.button, event->button.x, + event->button.y, event->button.windowID); + break; + case SDL_MOUSEWHEEL: + fprintf(stderr, + "Mouse %d: wheel scrolled %d in x and %d in y in window %d", + event->wheel.which, event->wheel.x, event->wheel.y, + event->wheel.windowID); + break; + case SDL_JOYBALLMOTION: + fprintf(stderr, "Joystick %d: ball %d moved by %d,%d", + event->jball.which, event->jball.ball, event->jball.xrel, + event->jball.yrel); + break; + case SDL_JOYHATMOTION: + fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which, + event->jhat.hat); + switch (event->jhat.value) { + case SDL_HAT_CENTERED: + fprintf(stderr, "CENTER"); + break; + case SDL_HAT_UP: + fprintf(stderr, "UP"); + break; + case SDL_HAT_RIGHTUP: + fprintf(stderr, "RIGHTUP"); + break; + case SDL_HAT_RIGHT: + fprintf(stderr, "RIGHT"); + break; + case SDL_HAT_RIGHTDOWN: + fprintf(stderr, "RIGHTDOWN"); + break; + case SDL_HAT_DOWN: + fprintf(stderr, "DOWN"); + break; + case SDL_HAT_LEFTDOWN: + fprintf(stderr, "LEFTDOWN"); + break; + case SDL_HAT_LEFT: + fprintf(stderr, "LEFT"); + break; + case SDL_HAT_LEFTUP: + fprintf(stderr, "LEFTUP"); + break; + default: + fprintf(stderr, "UNKNOWN"); + break; + } + break; + case SDL_JOYBUTTONDOWN: + fprintf(stderr, "Joystick %d: button %d pressed", + event->jbutton.which, event->jbutton.button); + break; + case SDL_JOYBUTTONUP: + fprintf(stderr, "Joystick %d: button %d released", + event->jbutton.which, event->jbutton.button); + break; + case SDL_QUIT: + fprintf(stderr, "Quit requested"); + break; + case SDL_USEREVENT: + fprintf(stderr, "User event %d", event->user.code); + break; + default: + fprintf(stderr, "Unknown event %d", event->type); + break; + } + fprintf(stderr, "\n"); +} + +void +CommonEvent(CommonState * state, SDL_Event * event, int *done) +{ + if (state->verbose & VERBOSE_EVENT) { + PrintEvent(event); + } + + switch (event->type) { + case SDL_WINDOWEVENT: + switch (event->window.event) { + case SDL_WINDOWEVENT_CLOSE: + *done = 1; + break; + } + break; + case SDL_KEYDOWN: + switch (event->key.keysym.sym) { + /* Add hotkeys here */ + case SDLK_g: + if (event->key.keysym.mod & KMOD_CTRL) { + /* Ctrl-G toggle grab */ + } + break; + case SDLK_ESCAPE: + *done = 1; + break; + default: + break; + } + break; + case SDL_QUIT: + *done = 1; + break; + } +} + +void +CommonQuit(CommonState * state) +{ + if (state->flags & SDL_INIT_VIDEO) { + SDL_VideoQuit(); + } + if (state->flags & SDL_INIT_AUDIO) { + SDL_AudioQuit(); + } + if (state->windows) { + SDL_free(state->windows); + } + SDL_free(state); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite2/source/common.h Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,48 @@ + +/* A simple test program framework */ + +#include <SDL/SDL.h> + +#define VERBOSE_VIDEO 0x00000001 +#define VERBOSE_MODES 0x00000002 +#define VERBOSE_RENDER 0x00000004 +#define VERBOSE_EVENT 0x00000008 +#define VERBOSE_AUDIO 0x00000010 + +typedef struct +{ + /* SDL init flags */ + char **argv; + Uint32 flags; + Uint32 verbose; + + /* Video info */ + const char *videodriver; + int display; + const char *window_title; + Uint32 window_flags; + int window_x; + int window_y; + int window_w; + int window_h; + int depth; + int refresh_rate; + int num_windows; + SDL_WindowID *windows; + + /* Renderer info */ + const char *renderdriver; + Uint32 render_flags; + SDL_bool skip_renderer; + + /* Audio info */ + const char *audiodriver; + SDL_AudioSpec audiospec; +} CommonState; + +extern CommonState *CommonCreateState(char **argv, Uint32 flags); +extern int CommonArg(CommonState * state, int index); +extern const char *CommonUsage(CommonState * state); +extern SDL_bool CommonInit(CommonState * state); +extern void CommonEvent(CommonState * state, SDL_Event * event, int *done); +extern void CommonQuit(CommonState * state);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nds-test-progs/sprite2/source/testsprite2.c Wed Aug 27 15:10:03 2008 +0000 @@ -0,0 +1,330 @@ +/* Simple program: Move N sprites around on the screen as fast as possible */ + +#include <stdlib.h> +#include <stdio.h> +#include <time.h> +#include <nds.h> +#include <fat.h> +#include "common.h" + +#include "icon_bmp_bin.h" + +#define NUM_SPRITES 10 +#define MAX_SPEED 1 + +static CommonState *state; +static int num_sprites; +static SDL_TextureID *sprites; +static SDL_bool cycle_color; +static SDL_bool cycle_alpha; +static int cycle_direction = 1; +static int current_alpha = 0; +static int current_color = 0; +static SDL_Rect *positions; +static SDL_Rect *velocities; +static int sprite_w, sprite_h; +static SDL_TextureBlendMode blendMode = SDL_TEXTUREBLENDMODE_MASK; +static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE; + +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ +static void +quit(int rc) +{ + if (sprites) { + SDL_free(sprites); + } + if (positions) { + SDL_free(positions); + } + if (velocities) { + SDL_free(velocities); + } + CommonQuit(state); + exit(rc); +} + +int +LoadSprite(char *file) +{ + int i; + SDL_Surface *temp; + + /* Load the sprite image */ + temp = SDL_LoadBMP(file); + if (temp == NULL) { + fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); + return (-1); + } + sprite_w = temp->w; + sprite_h = temp->h; + + /* Set transparent pixel as the pixel at (0,0) */ + if (temp->format->palette) { + SDL_SetColorKey(temp, SDL_SRCCOLORKEY, *(Uint8 *) temp->pixels); + } + + /* Create textures from the image */ + for (i = 0; i < state->num_windows; ++i) { + SDL_SelectRenderer(state->windows[i]); + sprites[i] = SDL_CreateTextureFromSurface(0, temp); + if (!sprites[i]) { + fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + SDL_FreeSurface(temp); + return (-1); + } + SDL_SetTextureBlendMode(sprites[i], blendMode); + SDL_SetTextureScaleMode(sprites[i], scaleMode); + } + SDL_FreeSurface(temp); + + /* We're ready to roll. :) */ + return (0); +} + +int +LoadSprite2(const u8 * ptr, int size) +{ + int i; + SDL_Rect r = { 0, 0, 32, 32 }; + for (i = 0; i < state->num_windows; ++i) { + SDL_SelectRenderer(state->windows[i]); + sprites[i] = SDL_CreateTexture(SDL_PIXELFORMAT_ABGR1555, + SDL_TEXTUREACCESS_STATIC, r.w, r.h); + if (!sprites[i]) { + fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); + return -1; + } + SDL_UpdateTexture(sprites[i], &r, ptr, r.w * 2); + SDL_SetTextureBlendMode(sprites[i], blendMode); + SDL_SetTextureScaleMode(sprites[i], scaleMode); + } + return 0; +} + +void +MoveSprites(SDL_WindowID window, SDL_TextureID sprite) +{ + int i, n; + int window_w, window_h; + SDL_Rect area, *position, *velocity; + + SDL_SelectRenderer(window); + + /* Query the sizes */ + SDL_GetWindowSize(window, &window_w, &window_h); + + /* Cycle the color and alpha, if desired */ + if (cycle_color) { + current_color += cycle_direction; + if (current_color < 0) { + current_color = 0; + cycle_direction = -cycle_direction; + } + if (current_color > 255) { + current_color = 255; + cycle_direction = -cycle_direction; + } + SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color, + (Uint8) current_color); + } + if (cycle_alpha) { + current_alpha += cycle_direction; + if (current_alpha < 0) { + current_alpha = 0; + cycle_direction = -cycle_direction; + } + if (current_alpha > 255) { + current_alpha = 255; + cycle_direction = -cycle_direction; + } + SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha); + } + + /* Move the sprite, bounce at the wall, and draw */ + n = 0; + SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL); + for (i = 0; i < num_sprites; ++i) { + position = &positions[i]; + velocity = &velocities[i]; + position->x += velocity->x; + if ((position->x < 0) || (position->x >= (window_w - sprite_w))) { + velocity->x = -velocity->x; + position->x += velocity->x; + } + position->y += velocity->y; + if ((position->y < 0) || (position->y >= (window_h - sprite_w))) { + velocity->y = -velocity->y; + position->y += velocity->y; + } + + /* Blit the sprite onto the screen */ + SDL_RenderCopy(sprite, NULL, position); + } + + /* Update the screen! */ + SDL_RenderPresent(); +} + +int +main(int argc, char *argv[]) +{ + int i, done; + SDL_Event event; + Uint32 then, now, frames; + + consoleDemoInit(); + puts("Hello world! Initializing FAT..."); + fatInitDefault(); + + /* Initialize parameters */ + num_sprites = NUM_SPRITES; + + /* Initialize test framework */ + state = CommonCreateState(argv, SDL_INIT_VIDEO); + if (!state) { + return 1; + } + for (i = 1; i < argc;) { + int consumed; + + consumed = CommonArg(state, i); + if (consumed == 0) { + consumed = -1; + if (SDL_strcasecmp(argv[i], "--blend") == 0) { + if (argv[i + 1]) { + if (SDL_strcasecmp(argv[i + 1], "none") == 0) { + blendMode = SDL_TEXTUREBLENDMODE_NONE; + consumed = 2; + } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) { + blendMode = SDL_TEXTUREBLENDMODE_MASK; + consumed = 2; + } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { + blendMode = SDL_TEXTUREBLENDMODE_BLEND; + consumed = 2; + } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { + blendMode = SDL_TEXTUREBLENDMODE_ADD; + consumed = 2; + } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { + blendMode = SDL_TEXTUREBLENDMODE_MOD; + consumed = 2; + } + } + } else if (SDL_strcasecmp(argv[i], "--scale") == 0) { + if (argv[i + 1]) { + if (SDL_strcasecmp(argv[i + 1], "none") == 0) { + scaleMode = SDL_TEXTURESCALEMODE_NONE; + consumed = 2; + } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) { + scaleMode = SDL_TEXTURESCALEMODE_FAST; + consumed = 2; + } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) { + scaleMode = SDL_TEXTURESCALEMODE_SLOW; + consumed = 2; + } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) { + scaleMode = SDL_TEXTURESCALEMODE_BEST; + consumed = 2; + } + } + } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { + cycle_color = SDL_TRUE; + consumed = 1; + } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { + cycle_alpha = SDL_TRUE; + consumed = 1; + } else if (SDL_isdigit(*argv[i])) { + num_sprites = SDL_atoi(argv[i]); + consumed = 1; + } + } + if (consumed < 0) { + fprintf(stderr, + "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n", + argv[0], CommonUsage(state)); + quit(1); + } + i += consumed; + } + if (!CommonInit(state)) { + quit(2); + } + + /* Create the windows, initialize the renderers, and load the textures */ + sprites = + (SDL_TextureID *) SDL_malloc(state->num_windows * sizeof(*sprites)); + if (!sprites) { + fprintf(stderr, "Out of memory!\n"); + quit(2); + } + for (i = 0; i < state->num_windows; ++i) { + SDL_SelectRenderer(state->windows[i]); + SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL); + } + if (LoadSprite2(icon_bmp_bin, icon_bmp_bin_size) < 0) { + printf("errored.\n"); + quit(2); + } + + /* Allocate memory for the sprite info */ + positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); + velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); + if (!positions || !velocities) { + fprintf(stderr, "Out of memory!\n"); + quit(2); + } + srand(time(NULL)); + if (scaleMode != SDL_TEXTURESCALEMODE_NONE) { + sprite_w += sprite_w / 2; + sprite_h += sprite_h / 2; + } + for (i = 0; i < num_sprites; ++i) { + positions[i].x = rand() % (state->window_w - sprite_w); + positions[i].y = rand() % (state->window_h - sprite_h); + positions[i].w = sprite_w; + positions[i].h = sprite_h; + velocities[i].x = 0; + velocities[i].y = 0; + while (!velocities[i].x && !velocities[i].y) { + velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; + velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED; + } + } + + /* Main render loop */ + frames = 0; + then = SDL_GetTicks(); + done = 0; + while (!done) { + /* Check for events */ + ++frames; + while (SDL_PollEvent(&event)) { + CommonEvent(state, &event, &done); + switch (event.type) { + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_EXPOSED: + SDL_SelectRenderer(event.window.windowID); + SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL); + break; + } + break; + default: + break; + } + } + for (i = 0; i < state->num_windows; ++i) { + MoveSprites(state->windows[i], sprites[i]); + } + } + + /* Print out some timing information */ + now = SDL_GetTicks(); + if (now > then) { + printf("%2.2f frames per second\n", + ((double) frames * 1000) / (now - then)); + } + + quit(0); + return 0; +} + +/* vi: set ts=4 sw=4 expandtab: */
--- a/test/testblitspeed.c Wed Aug 27 13:37:19 2008 +0000 +++ b/test/testblitspeed.c Wed Aug 27 15:10:03 2008 +0000 @@ -397,8 +397,7 @@ } now = SDL_GetTicks(); - } - while (now < end); + } while (now < end); printf("Non-blitting crap accounted for %d percent of this run.\n", percent(testms - elasped, testms));
--- a/test/testdyngl.c Wed Aug 27 13:37:19 2008 +0000 +++ b/test/testdyngl.c Wed Aug 27 15:10:03 2008 +0000 @@ -185,8 +185,7 @@ } SDL_Delay(20); - } - while (!done); + } while (!done); SDL_Quit(); return 0;
--- a/test/testpalette.c Wed Aug 27 13:37:19 2008 +0000 +++ b/test/testpalette.c Wed Aug 27 15:10:03 2008 +0000 @@ -338,8 +338,7 @@ /* update changed areas of the screen */ SDL_UpdateRects(screen, NBOATS, updates); frames++; - } - while (fade_level > 0); + } while (fade_level > 0); printf("%d frames, %.2f fps\n", frames, 1000.0 * frames / (SDL_GetTicks() - start));