From d01266126f752e0d0216665d26b4ed9490238a20 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 27 Aug 2008 15:10:03 +0000 Subject: [PATCH] Final merge of Google Summer of Code 2008 work... Port SDL 1.3 to the Nintendo DS by Darren Alton, mentored by Sam Lantinga --- Makefile.ds | 129 +++ include/SDL_config.h.default | 4 +- include/SDL_config.h.in | 5 + include/SDL_config_nintendods.h | 119 +++ include/SDL_pixels.h | 6 + include/SDL_platform.h | 5 + include/SDL_stdinc.h | 9 + src/SDL_compat.c | 1 + src/SDL_error.c | 4 +- src/audio/SDL_audio.c | 11 + src/audio/SDL_wave.c | 6 +- src/audio/alsa/SDL_alsa_audio.c | 3 + src/audio/bsd/SDL_bsdaudio.c | 3 +- src/audio/dart/SDL_dart.c | 17 +- src/audio/dma/SDL_dmaaudio.c | 3 +- src/audio/esd/SDL_esdaudio.c | 5 +- src/audio/nds/SDL_ndsaudio.c | 130 +++ src/audio/nds/SDL_ndsaudio.h | 44 + src/audio/nto/SDL_nto_audio.c | 6 +- src/audio/paudio/SDL_paudio.c | 5 +- src/audio/ums/SDL_umsaudio.c | 6 +- src/audio/windib/SDL_dibaudio.c | 7 +- src/audio/windx5/SDL_dx5audio.c | 5 +- src/cdrom/SDL_cdrom.c | 1 + src/cdrom/aix/SDL_syscdrom.c | 15 +- src/cdrom/beos/SDL_syscdrom.cc | 3 +- src/cdrom/bsdi/SDL_syscdrom.c | 3 +- src/cdrom/freebsd/SDL_syscdrom.c | 3 +- src/cdrom/linux/SDL_syscdrom.c | 3 +- src/cdrom/macosx/AudioFilePlayer.c | 3 +- src/cdrom/macosx/AudioFileReaderThread.c | 8 +- src/cdrom/macosx/CDPlayer.c | 3 +- src/cdrom/openbsd/SDL_syscdrom.c | 3 +- src/cdrom/osf/SDL_syscdrom.c | 3 +- src/cdrom/qnx/SDL_syscdrom.c | 6 +- src/events/SDL_events.c | 1 + src/events/default_cursor.h | 2 + src/file/SDL_rwops.c | 22 + src/joystick/darwin/SDL_sysjoystick.c | 4 +- src/joystick/linux/SDL_sysjoystick.c | 27 +- src/joystick/nds/SDL_sysjoystick.c | 172 ++++ src/loadso/macosx/SDL_dlcompat.c | 5 +- src/main/beos/SDL_BeApp.cc | 3 +- src/stdlib/SDL_stdlib.c | 8 + src/thread/SDL_thread_c.h | 2 + src/thread/irix/SDL_syssem.c | 5 +- src/thread/nds/SDL_syscond.c | 229 +++++ src/thread/nds/SDL_syscond_c.h | 26 + src/thread/nds/SDL_sysmutex.c | 142 +++ src/thread/nds/SDL_sysmutex_c.h | 26 + src/thread/nds/SDL_syssem.c | 228 +++++ src/thread/nds/SDL_syssem_c.h | 26 + src/thread/nds/SDL_systhread.c | 63 ++ src/thread/nds/SDL_systhread_c.h | 28 + src/thread/pthread/SDL_syssem.c | 3 +- src/thread/riscos/SDL_syssem.c | 3 +- src/timer/nds/SDL_systimer.c | 120 +++ src/timer/riscos/SDL_systimer.c | 3 +- src/timer/unix/SDL_systimer.c | 3 +- src/video/SDL_RLEaccel.c | 30 +- src/video/SDL_blit_0.c | 3 + src/video/SDL_blit_1.c | 2 + src/video/SDL_blit_A.c | 8 +- src/video/SDL_blit_N.c | 13 +- src/video/SDL_gamma.c | 1 + src/video/SDL_pixels.c | 5 + src/video/SDL_renderer_sw.c | 32 +- src/video/SDL_surface.c | 6 +- src/video/SDL_sysvideo.h | 3 + src/video/SDL_video.c | 3 + src/video/ataricommon/SDL_atarigl.c | 14 +- src/video/bwindow/SDL_sysvideo.cc | 4 +- src/video/dc/SDL_dcevents.c | 6 +- src/video/dc/SDL_dcvideo.c | 2 + src/video/directfb/SDL_DirectFB_events.c | 28 +- src/video/directfb/SDL_DirectFB_mouse.c | 35 +- src/video/directfb/SDL_DirectFB_video.c | 72 +- src/video/fbcon/SDL_fb3dfx.c | 1 + src/video/fbcon/SDL_fbelo.c | 3 +- src/video/fbcon/SDL_fbevents.c | 10 +- src/video/fbcon/SDL_fbmatrox.c | 1 + src/video/fbcon/SDL_fbriva.c | 2 + src/video/fbcon/SDL_fbvideo.c | 17 +- src/video/gapi/SDL_gapivideo.c | 4 +- src/video/ipod/SDL_ipodvideo.c | 20 +- src/video/nds/SDL_ndsevents.c | 54 + src/video/nds/SDL_ndsevents_c.h | 28 + src/video/nds/SDL_ndsrender.c | 660 ++++++++++++ src/video/nds/SDL_ndsrender_c.h | 28 + src/video/nds/SDL_ndsvideo.c | 168 +++ src/video/nds/SDL_ndsvideo.h | 31 + src/video/os2fslib/SDL_os2fslib.c | 183 ++-- src/video/photon/SDL_ph_gl.c | 13 +- src/video/photon/SDL_ph_image.c | 5 +- src/video/photon/SDL_phyuv.c | 7 +- src/video/ps2gs/SDL_gsevents.c | 8 +- src/video/ps2gs/SDL_gsvideo.c | 4 + src/video/riscos/SDL_riscosvideo.c | 1 + src/video/svga/SDL_svgaevents.c | 3 +- src/video/svga/SDL_svgavideo.c | 2 + src/video/vgl/SDL_vglevents.c | 3 +- src/video/vgl/SDL_vglvideo.c | 2 + src/video/win32/SDL_d3drender.c | 9 +- src/video/win32/SDL_gdirender.c | 5 +- src/video/win32/SDL_win32keyboard.c | 1 + src/video/win32/SDL_win32opengl.c | 3 +- src/video/wscons/SDL_wsconsevents.c | 3 +- src/video/wscons/SDL_wsconsvideo.c | 1 + src/video/x11/SDL_x11opengl.c | 4 +- src/video/xbios/SDL_xbiosmodes.c | 8 +- test/nds-test-progs/general/Makefile | 132 +++ test/nds-test-progs/general/source/main.c | 96 ++ test/nds-test-progs/sprite/Makefile | 132 +++ test/nds-test-progs/sprite/source/common.c | 965 ++++++++++++++++++ test/nds-test-progs/sprite/source/common.h | 48 + .../nds-test-progs/sprite/source/testsprite.c | 316 ++++++ test/nds-test-progs/sprite2/Makefile | 132 +++ test/nds-test-progs/sprite2/source/common.c | 965 ++++++++++++++++++ test/nds-test-progs/sprite2/source/common.h | 48 + .../sprite2/source/testsprite2.c | 330 ++++++ test/testblitspeed.c | 3 +- test/testdyngl.c | 3 +- test/testpalette.c | 3 +- 123 files changed, 6082 insertions(+), 388 deletions(-) create mode 100644 Makefile.ds create mode 100644 include/SDL_config_nintendods.h create mode 100644 src/audio/nds/SDL_ndsaudio.c create mode 100644 src/audio/nds/SDL_ndsaudio.h create mode 100644 src/joystick/nds/SDL_sysjoystick.c create mode 100644 src/thread/nds/SDL_syscond.c create mode 100644 src/thread/nds/SDL_syscond_c.h create mode 100644 src/thread/nds/SDL_sysmutex.c create mode 100644 src/thread/nds/SDL_sysmutex_c.h create mode 100644 src/thread/nds/SDL_syssem.c create mode 100644 src/thread/nds/SDL_syssem_c.h create mode 100644 src/thread/nds/SDL_systhread.c create mode 100644 src/thread/nds/SDL_systhread_c.h create mode 100644 src/timer/nds/SDL_systimer.c create mode 100644 src/video/nds/SDL_ndsevents.c create mode 100644 src/video/nds/SDL_ndsevents_c.h create mode 100644 src/video/nds/SDL_ndsrender.c create mode 100644 src/video/nds/SDL_ndsrender_c.h create mode 100644 src/video/nds/SDL_ndsvideo.c create mode 100644 src/video/nds/SDL_ndsvideo.h create mode 100755 test/nds-test-progs/general/Makefile create mode 100755 test/nds-test-progs/general/source/main.c create mode 100755 test/nds-test-progs/sprite/Makefile create mode 100755 test/nds-test-progs/sprite/source/common.c create mode 100755 test/nds-test-progs/sprite/source/common.h create mode 100755 test/nds-test-progs/sprite/source/testsprite.c create mode 100755 test/nds-test-progs/sprite2/Makefile create mode 100755 test/nds-test-progs/sprite2/source/common.c create mode 100755 test/nds-test-progs/sprite2/source/common.h create mode 100755 test/nds-test-progs/sprite2/source/testsprite2.c diff --git a/Makefile.ds b/Makefile.ds new file mode 100644 index 000000000..64e84d7ef --- /dev/null +++ b/Makefile.ds @@ -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=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) + diff --git a/include/SDL_config.h.default b/include/SDL_config.h.default index c7b1693b0..06027a2a7 100644 --- a/include/SDL_config.h.default +++ b/include/SDL_config.h.default @@ -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" diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 648c9a7dc..415de51e8 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -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 diff --git a/include/SDL_config_nintendods.h b/include/SDL_config_nintendods.h new file mode 100644 index 000000000..a57f999ff --- /dev/null +++ b/include/SDL_config_nintendods.h @@ -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 + 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 */ diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h index 0c528474c..db484d182 100644 --- a/include/SDL_pixels.h +++ b/include/SDL_pixels.h @@ -146,12 +146,18 @@ enum 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), diff --git a/include/SDL_platform.h b/include/SDL_platform.h index 1bfee29ec..e7f1c9e38 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -97,4 +97,9 @@ #define __WIN32__ 1 #endif +#if defined(__NDS__) +#undef __NINTENDODS__ +#define __NINTENDODS__ 1 +#endif + #endif /* _SDL_platform_h */ diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 3df9e2a22..194454ff1 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -147,8 +147,12 @@ SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2); 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 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8); #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 @@ extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string); #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 diff --git a/src/SDL_compat.c b/src/SDL_compat.c index 1c1572a69..a8b310ba6 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -693,6 +693,7 @@ SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) SDL_UpdateRects(screen, 1, &rect); } } + void SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects) { diff --git a/src/SDL_error.c b/src/SDL_error.c index a447a125d..372763817 100644 --- a/src/SDL_error.c +++ b/src/SDL_error.c @@ -180,8 +180,8 @@ SDL_GetErrorMsg(char *errstr, unsigned int maxlen) 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; diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 3038ff907..6d5f432cd 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -70,6 +70,7 @@ extern AudioBootStrap DUMMYAUD_bootstrap; extern AudioBootStrap DCAUD_bootstrap; extern AudioBootStrap MMEAUDIO_bootstrap; extern AudioBootStrap DART_bootstrap; +extern AudioBootStrap NDSAUD_bootstrap; /* Available audio drivers */ @@ -144,6 +145,9 @@ static AudioBootStrap *bootstrap[] = { #endif #if SDL_AUDIO_DRIVER_DART &DART_bootstrap, +#endif +#if SDL_AUDIO_DRIVER_NDS + &NDSAUD_bootstrap, #endif NULL }; @@ -167,31 +171,38 @@ SDL_AudioDetectDevices_Default(int iscapture) { 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. */ diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c index 630209ee6..c5eee2c42 100644 --- a/src/audio/SDL_wave.c +++ b/src/audio/SDL_wave.c @@ -462,8 +462,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc, } /* 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 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc, *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) { diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index d774c4f18..473b2e14f 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -259,16 +259,19 @@ swizzle_alsa_channels_6_64bit(_THIS) { 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) { diff --git a/src/audio/bsd/SDL_bsdaudio.c b/src/audio/bsd/SDL_bsdaudio.c index b7f01f15b..a5ada0b8b 100644 --- a/src/audio/bsd/SDL_bsdaudio.c +++ b/src/audio/bsd/SDL_bsdaudio.c @@ -270,8 +270,7 @@ BSDAUDIO_PlayDevice(_THIS) || ((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) { diff --git a/src/audio/dart/SDL_dart.c b/src/audio/dart/SDL_dart.c index d0549fffe..56ba77e65 100644 --- a/src/audio/dart/SDL_dart.c +++ b/src/audio/dart/SDL_dart.c @@ -62,8 +62,8 @@ DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags) 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 @@ DART_PlayDevice(_THIS) (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 @@ DART_GetDeviceBuf(_THIS) 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) { diff --git a/src/audio/dma/SDL_dmaaudio.c b/src/audio/dma/SDL_dmaaudio.c index ab5d9c85a..c7d071292 100644 --- a/src/audio/dma/SDL_dmaaudio.c +++ b/src/audio/dma/SDL_dmaaudio.c @@ -498,8 +498,7 @@ DMA_GetDeviceBuf(_THIS) 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); diff --git a/src/audio/esd/SDL_esdaudio.c b/src/audio/esd/SDL_esdaudio.c index 8c4b1b491..e52f546d9 100644 --- a/src/audio/esd/SDL_esdaudio.c +++ b/src/audio/esd/SDL_esdaudio.c @@ -154,9 +154,8 @@ ESD_PlayDevice(_THIS) 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; diff --git a/src/audio/nds/SDL_ndsaudio.c b/src/audio/nds/SDL_ndsaudio.c new file mode 100644 index 000000000..13ba2584f --- /dev/null +++ b/src/audio/nds/SDL_ndsaudio.c @@ -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 + +#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: */ diff --git a/src/audio/nds/SDL_ndsaudio.h b/src/audio/nds/SDL_ndsaudio.h new file mode 100644 index 000000000..0109a3c55 --- /dev/null +++ b/src/audio/nds/SDL_ndsaudio.h @@ -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 + +/* 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: */ diff --git a/src/audio/nto/SDL_nto_audio.c b/src/audio/nto/SDL_nto_audio.c index 4459d196c..8b3bbcf42 100644 --- a/src/audio/nto/SDL_nto_audio.c +++ b/src/audio/nto/SDL_nto_audio.c @@ -154,8 +154,7 @@ NTO_WaitDevice(_THIS) } break; } - } - while (1); + } while (1); } static void @@ -213,8 +212,7 @@ NTO_PlayDevice(_THIS) 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) { diff --git a/src/audio/paudio/SDL_paudio.c b/src/audio/paudio/SDL_paudio.c index 89d385831..2b04fcca4 100644 --- a/src/audio/paudio/SDL_paudio.c +++ b/src/audio/paudio/SDL_paudio.c @@ -208,9 +208,8 @@ PAUDIO_PlayDevice(_THIS) 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) { diff --git a/src/audio/ums/SDL_umsaudio.c b/src/audio/ums/SDL_umsaudio.c index 3bdb414b5..eee2c3cbb 100644 --- a/src/audio/ums/SDL_umsaudio.c +++ b/src/audio/ums/SDL_umsaudio.c @@ -218,8 +218,7 @@ UMS_PlayAudio(_THIS) #endif return; } - } - while (samplesToWrite > 0); + } while (samplesToWrite > 0); SDL_LockAudio(); SDL_memcpy(&swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer)); @@ -326,8 +325,7 @@ UMS_OpenAudio(_THIS, SDL_AudioSpec * spec) 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"); diff --git a/src/audio/windib/SDL_dibaudio.c b/src/audio/windib/SDL_dibaudio.c index 7edf563fa..e48fced54 100644 --- a/src/audio/windib/SDL_dibaudio.c +++ b/src/audio/windib/SDL_dibaudio.c @@ -107,8 +107,8 @@ WINWAVEOUT_WaitDevice(_THIS) 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 @@ WINWAVEOUT_WaitDone(_THIS) if (left > 0) { SDL_Delay(100); } - } - while (left > 0); + } while (left > 0); } void diff --git a/src/audio/windx5/SDL_dx5audio.c b/src/audio/windx5/SDL_dx5audio.c index 1edaef1e7..4cac5bad4 100644 --- a/src/audio/windx5/SDL_dx5audio.c +++ b/src/audio/windx5/SDL_dx5audio.c @@ -278,8 +278,9 @@ DSOUND_GetDeviceBuf(_THIS) 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); diff --git a/src/cdrom/SDL_cdrom.c b/src/cdrom/SDL_cdrom.c index afb75c9e3..5ff5bf3ee 100644 --- a/src/cdrom/SDL_cdrom.c +++ b/src/cdrom/SDL_cdrom.c @@ -44,6 +44,7 @@ struct CDcaps SDL_CDcaps = { NULL, /* Eject */ NULL, /* Close */ }; + int SDL_numcds; int diff --git a/src/cdrom/aix/SDL_syscdrom.c b/src/cdrom/aix/SDL_syscdrom.c index 95994adfd..31c4422da 100644 --- a/src/cdrom/aix/SDL_syscdrom.c +++ b/src/cdrom/aix/SDL_syscdrom.c @@ -181,8 +181,7 @@ CheckMounts() #endif return; } - } - while (ret == 0); + } while (ret == 0); #ifdef DEBUG_CDROM fprintf(stderr, "Read %d vmount structures\n", ret); @@ -211,8 +210,7 @@ CheckMounts() } ptr = (struct vmount *) ((char *) ptr + ptr->vmt_length); ret--; - } - while (ret > 0); + } while (ret > 0); free(buffer); } @@ -247,8 +245,7 @@ CheckNonmounts() } } } - } - while (ret == 0); + } while (ret == 0); ret = endfsent_r(&fsFile); if (ret != 0) return -1; @@ -275,8 +272,7 @@ CheckNonmounts() } } } - } - while (entry != NULL); + } while (entry != NULL); endfsent(); #endif } @@ -326,8 +322,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } diff --git a/src/cdrom/beos/SDL_syscdrom.cc b/src/cdrom/beos/SDL_syscdrom.cc index 3bca020b6..cecba2170 100644 --- a/src/cdrom/beos/SDL_syscdrom.cc +++ b/src/cdrom/beos/SDL_syscdrom.cc @@ -193,8 +193,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } diff --git a/src/cdrom/bsdi/SDL_syscdrom.c b/src/cdrom/bsdi/SDL_syscdrom.c index 719c12d5e..4426a195a 100644 --- a/src/cdrom/bsdi/SDL_syscdrom.c +++ b/src/cdrom/bsdi/SDL_syscdrom.c @@ -286,8 +286,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } diff --git a/src/cdrom/freebsd/SDL_syscdrom.c b/src/cdrom/freebsd/SDL_syscdrom.c index 21e239209..b01a95fd7 100644 --- a/src/cdrom/freebsd/SDL_syscdrom.c +++ b/src/cdrom/freebsd/SDL_syscdrom.c @@ -176,8 +176,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } diff --git a/src/cdrom/linux/SDL_syscdrom.c b/src/cdrom/linux/SDL_syscdrom.c index 324a16141..f54117ee0 100644 --- a/src/cdrom/linux/SDL_syscdrom.c +++ b/src/cdrom/linux/SDL_syscdrom.c @@ -312,8 +312,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } diff --git a/src/cdrom/macosx/AudioFilePlayer.c b/src/cdrom/macosx/AudioFilePlayer.c index 569baf4ea..1817ad3b4 100644 --- a/src/cdrom/macosx/AudioFilePlayer.c +++ b/src/cdrom/macosx/AudioFilePlayer.c @@ -311,8 +311,7 @@ AudioFilePlayer_OpenFile(AudioFilePlayer * afp, const FSRef * inRef, /* 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. */ diff --git a/src/cdrom/macosx/AudioFileReaderThread.c b/src/cdrom/macosx/AudioFileReaderThread.c index fb9f45b58..272a78616 100644 --- a/src/cdrom/macosx/AudioFileReaderThread.c +++ b/src/cdrom/macosx/AudioFileReaderThread.c @@ -335,9 +335,8 @@ FileReaderThread_ReadNextChunk(FileReaderThread * frt) } /* 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 @@ AudioFileManager_GetFileData(AudioFileManager * afm, void **inOutData, } else { *inOutDataSize = afm->mChunkSize; *inOutData = - afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm-> - mFileBuffer + + afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer + afm->mChunkSize); } diff --git a/src/cdrom/macosx/CDPlayer.c b/src/cdrom/macosx/CDPlayer.c index 25d086238..df206d379 100644 --- a/src/cdrom/macosx/CDPlayer.c +++ b/src/cdrom/macosx/CDPlayer.c @@ -400,8 +400,7 @@ ListTrackFiles(FSVolumeRefNum theVolume, FSRef * trackFiles, int numTracks) } CFRelease(name); } - } - while (noErr == result); + } while (noErr == result); FSCloseIterator(iterator); } diff --git a/src/cdrom/openbsd/SDL_syscdrom.c b/src/cdrom/openbsd/SDL_syscdrom.c index ce0deb0be..620a89283 100644 --- a/src/cdrom/openbsd/SDL_syscdrom.c +++ b/src/cdrom/openbsd/SDL_syscdrom.c @@ -184,8 +184,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } diff --git a/src/cdrom/osf/SDL_syscdrom.c b/src/cdrom/osf/SDL_syscdrom.c index 5ee6e202e..47e8b4847 100644 --- a/src/cdrom/osf/SDL_syscdrom.c +++ b/src/cdrom/osf/SDL_syscdrom.c @@ -199,8 +199,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } diff --git a/src/cdrom/qnx/SDL_syscdrom.c b/src/cdrom/qnx/SDL_syscdrom.c index e9e7f3adc..d0127b0f3 100644 --- a/src/cdrom/qnx/SDL_syscdrom.c +++ b/src/cdrom/qnx/SDL_syscdrom.c @@ -184,8 +184,7 @@ SDL_SYS_CDInit(void) } else { SDLcdrom = NULL; } - } - while (SDLcdrom); + } while (SDLcdrom); SDL_stack_free(cdpath); } @@ -357,8 +356,7 @@ SDL_SYS_CDStatus(SDL_CD * cdrom, int *position) devctlret = ENXIO; break; } - } - while ((devctlret == EAGAIN) || (devctlret == ESTALE)); + } while ((devctlret == EAGAIN) || (devctlret == ESTALE)); if (devctlret != 0) { if (devctlret == ENXIO) { diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 364182eb3..d9d80ecb1 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -73,6 +73,7 @@ SDL_Lock_EventThread(void) } } } + void SDL_Unlock_EventThread(void) { diff --git a/src/events/default_cursor.h b/src/events/default_cursor.h index 1fcc19e09..b61dc6549 100644 --- a/src/events/default_cursor.h +++ b/src/events/default_cursor.h @@ -51,6 +51,7 @@ static unsigned char default_cdata[] = { 0x03, 0x00, 0x00, 0x00 }; + static unsigned char default_cmask[] = { 0xC0, 0x00, 0xE0, 0x00, @@ -90,6 +91,7 @@ static unsigned char default_cdata[] = { 0x03, 0x00, 0x00, 0x00 }; + static unsigned char default_cmask[] = { 0x40, 0x00, 0xE0, 0x00, diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 22879cdba..c9a56fdab 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -28,6 +28,10 @@ #include "SDL_endian.h" #include "SDL_rwops.h" +#ifdef __NDS__ +/* include libfat headers for fatInitDefault(). */ +#include +#endif /* __NDS__ */ #ifdef __WIN32__ @@ -132,6 +136,7 @@ win32_file_open(SDL_RWops * context, const char *filename, const char *mode) return 0; /* ok */ } + static long SDLCALL win32_file_seek(SDL_RWops * context, long offset, int whence) { @@ -173,6 +178,7 @@ win32_file_seek(SDL_RWops * context, long offset, int whence) 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 @@ win32_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) } 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 @@ win32_file_write(SDL_RWops * context, const void *ptr, size_t size, nwritten = byte_written / size; return nwritten; } + static int SDLCALL win32_file_close(SDL_RWops * context) { @@ -298,6 +306,7 @@ stdio_seek(SDL_RWops * context, long offset, int whence) return (-1); } } + static size_t SDLCALL stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) { @@ -309,6 +318,7 @@ stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) } return (nread); } + static size_t SDLCALL stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) { @@ -320,6 +330,7 @@ stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) } return (nwrote); } + static int SDLCALL stdio_close(SDL_RWops * context) { @@ -368,6 +379,7 @@ mem_seek(SDL_RWops * context, long offset, int whence) 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 @@ mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum) 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 @@ mem_write(SDL_RWops * context, const void *ptr, size_t size, size_t num) 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_RWFromFP(FILE * fp, SDL_bool autoclose) { 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; diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index 8bb21fe05..5ead47779 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -149,8 +149,8 @@ HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice) (*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", diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index c31dace49..78456e9e3 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -89,6 +89,7 @@ struct joystick_logical_mapping 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 @@ static struct joystick_logical_mapping mp88xx_2_logical_axismap[] = { {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 @@ static struct joystick_logical_mapping mp88xx_3_logical_axismap[] = { {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 @@ static struct joystick_logical_mapping mp88xx_4_logical_axismap[] = { {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 @@ struct joystick_logical_layout 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 @@ HandleHat(SDL_Joystick * stick, Uint8 hat, int axis, int value) #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 @@ EV_HandleEvents(SDL_Joystick * joystick) 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_HandleEvents(SDL_Joystick * joystick) 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; } diff --git a/src/joystick/nds/SDL_sysjoystick.c b/src/joystick/nds/SDL_sysjoystick.c new file mode 100644 index 000000000..498edae8a --- /dev/null +++ b/src/joystick/nds/SDL_sysjoystick.c @@ -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 +#include /* 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 */ diff --git a/src/loadso/macosx/SDL_dlcompat.c b/src/loadso/macosx/SDL_dlcompat.c index 980c08af3..951061ab3 100644 --- a/src/loadso/macosx/SDL_dlcompat.c +++ b/src/loadso/macosx/SDL_dlcompat.c @@ -616,8 +616,8 @@ search_linked_libs(const struct mach_header *mh, const char *symbol) || (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 @@ dlsym_auto_underscore(void *handle, const char *symbol) return answer; } + static void * dlsym_auto_underscore_intern(void *handle, const char *symbol) { diff --git a/src/main/beos/SDL_BeApp.cc b/src/main/beos/SDL_BeApp.cc index 02df93e7b..005c91d2a 100644 --- a/src/main/beos/SDL_BeApp.cc +++ b/src/main/beos/SDL_BeApp.cc @@ -78,8 +78,7 @@ SDL_InitBeApp(void) 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; diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index de17663af..7aacad88d 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -135,6 +135,7 @@ _allmul() } /* *INDENT-ON* */ } + void __declspec(naked) _alldiv() @@ -222,6 +223,7 @@ _alldiv() } /* *INDENT-ON* */ } + void __declspec(naked) _aulldiv() @@ -279,6 +281,7 @@ _aulldiv() } /* *INDENT-ON* */ } + void __declspec(naked) _allrem() @@ -365,6 +368,7 @@ _allrem() } /* *INDENT-ON* */ } + void __declspec(naked) _aullrem() @@ -423,6 +427,7 @@ _aullrem() } /* *INDENT-ON* */ } + void __declspec(naked) _alldvrm() @@ -532,6 +537,7 @@ _alldvrm() } /* *INDENT-ON* */ } + void __declspec(naked) _aulldvrm() @@ -604,6 +610,7 @@ _aulldvrm() } /* *INDENT-ON* */ } + void __declspec(naked) _allshl() @@ -630,6 +637,7 @@ _allshl() } /* *INDENT-ON* */ } + void __declspec(naked) _aullshr() diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index 1276e9263..0e27c2fce 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -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" diff --git a/src/thread/irix/SDL_syssem.c b/src/thread/irix/SDL_syssem.c index 00ed025a7..82f9ae7a7 100644 --- a/src/thread/irix/SDL_syssem.c +++ b/src/thread/irix/SDL_syssem.c @@ -55,9 +55,11 @@ union semun { 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 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) break; } SDL_Delay(1); - } - while (SDL_GetTicks() < timeout); + } while (SDL_GetTicks() < timeout); return retval; } diff --git a/src/thread/nds/SDL_syscond.c b/src/thread/nds/SDL_syscond.c new file mode 100644 index 000000000..ac1504958 --- /dev/null +++ b/src/thread/nds/SDL_syscond.c @@ -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 +#include + +#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); +} diff --git a/src/thread/nds/SDL_syscond_c.h b/src/thread/nds/SDL_syscond_c.h new file mode 100644 index 000000000..178498d8c --- /dev/null +++ b/src/thread/nds/SDL_syscond_c.h @@ -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 diff --git a/src/thread/nds/SDL_sysmutex.c b/src/thread/nds/SDL_sysmutex.c new file mode 100644 index 000000000..161884ef1 --- /dev/null +++ b/src/thread/nds/SDL_sysmutex.c @@ -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 +#include + +#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 */ +} diff --git a/src/thread/nds/SDL_sysmutex_c.h b/src/thread/nds/SDL_sysmutex_c.h new file mode 100644 index 000000000..9abe18746 --- /dev/null +++ b/src/thread/nds/SDL_sysmutex_c.h @@ -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 diff --git a/src/thread/nds/SDL_syssem.c b/src/thread/nds/SDL_syssem.c new file mode 100644 index 000000000..442256d83 --- /dev/null +++ b/src/thread/nds/SDL_syssem.c @@ -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 + +#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 */ diff --git a/src/thread/nds/SDL_syssem_c.h b/src/thread/nds/SDL_syssem_c.h new file mode 100644 index 000000000..430788d57 --- /dev/null +++ b/src/thread/nds/SDL_syssem_c.h @@ -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 diff --git a/src/thread/nds/SDL_systhread.c b/src/thread/nds/SDL_systhread.c new file mode 100644 index 000000000..4090a62c6 --- /dev/null +++ b/src/thread/nds/SDL_systhread.c @@ -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; +} diff --git a/src/thread/nds/SDL_systhread_c.h b/src/thread/nds/SDL_systhread_c.h new file mode 100644 index 000000000..c6fe446a6 --- /dev/null +++ b/src/thread/nds/SDL_systhread_c.h @@ -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 diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index ba335e3f7..b97411cfd 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -125,8 +125,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) break; } SDL_Delay(1); - } - while (SDL_GetTicks() < timeout); + } while (SDL_GetTicks() < timeout); return retval; } diff --git a/src/thread/riscos/SDL_syssem.c b/src/thread/riscos/SDL_syssem.c index 23e8fb562..e8954b0c0 100644 --- a/src/thread/riscos/SDL_syssem.c +++ b/src/thread/riscos/SDL_syssem.c @@ -177,8 +177,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) break; } SDL_Delay(1); - } - while (SDL_GetTicks() < timeout); + } while (SDL_GetTicks() < timeout); return retval; } diff --git a/src/timer/nds/SDL_systimer.c b/src/timer/nds/SDL_systimer.c new file mode 100644 index 000000000..54cd173f3 --- /dev/null +++ b/src/timer/nds/SDL_systimer.c @@ -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 +#include + +#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: */ diff --git a/src/timer/riscos/SDL_systimer.c b/src/timer/riscos/SDL_systimer.c index 003f616a4..ff8eee197 100644 --- a/src/timer/riscos/SDL_systimer.c +++ b/src/timer/riscos/SDL_systimer.c @@ -130,8 +130,7 @@ SDL_Delay(Uint32 ms) pthread_yield(); #endif - } - while (1); + } while (1); } #if SDL_THREADS_DISABLED diff --git a/src/timer/unix/SDL_systimer.c b/src/timer/unix/SDL_systimer.c index 89b415739..5fffe1354 100644 --- a/src/timer/unix/SDL_systimer.c +++ b/src/timer/unix/SDL_systimer.c @@ -137,8 +137,7 @@ SDL_Delay(Uint32 ms) 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 */ } diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 0998d3f93..6b55ce87f 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -1154,8 +1154,7 @@ SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect, ofs += run; } else if (!ofs) goto done; - } - while (ofs < w); + } while (ofs < w); /* skip padding */ srcbuf += (uintptr_t) srcbuf & 2; @@ -1168,10 +1167,8 @@ SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect, 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 @@ SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect, ofs += run; } else if (!ofs) goto done; - } - while (ofs < w); - } - while (--vskip); + } while (ofs < w); + } while (--vskip); } } } @@ -1567,8 +1562,7 @@ RLEAlphaSurface(SDL_Surface * surface) 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 @@ RLEAlphaSurface(SDL_Surface * surface) } if (!blankline) lastline = dst; - } - while (x < w); + } while (x < w); src += surface->pitch >> 2; } @@ -1771,8 +1764,7 @@ RLEColorkeySurface(SDL_Surface * surface) } if (!blankline) lastline = dst; - } - while (x < w); + } while (x < w); srcbuf += surface->pitch; } @@ -1911,8 +1903,7 @@ UnRLEAlpha(SDL_Surface * surface) 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 @@ UnRLEAlpha(SDL_Surface * surface) 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 */ diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index 0b04ee4b2..6c82ccfe9 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -80,6 +80,7 @@ BlitBto1(SDL_BlitInfo * info) } } } + static void BlitBto2(SDL_BlitInfo * info) { @@ -116,6 +117,7 @@ BlitBto2(SDL_BlitInfo * info) dst += dstskip; } } + static void BlitBto3(SDL_BlitInfo * info) { @@ -154,6 +156,7 @@ BlitBto3(SDL_BlitInfo * info) dst += dstskip; } } + static void BlitBto4(SDL_BlitInfo * info) { diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index 7319850ab..617693502 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -184,6 +184,7 @@ Blit1to2(SDL_BlitInfo * info) } #endif /* USE_DUFFS_LOOP */ } + static void Blit1to3(SDL_BlitInfo * info) { @@ -232,6 +233,7 @@ Blit1to3(SDL_BlitInfo * info) dst += dstskip; } } + static void Blit1to4(SDL_BlitInfo * info) { diff --git a/src/video/SDL_blit_A.c b/src/video/SDL_blit_A.c index e8d8c7155..1bba55d5b 100644 --- a/src/video/SDL_blit_A.c +++ b/src/video/SDL_blit_A.c @@ -283,8 +283,8 @@ BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info) 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 @@ calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt) /* 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) ^ diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index 38fba803e..8d21085af 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -141,8 +141,8 @@ calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt) /* 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 @@ static const Uint32 RGB565_ARGB8888_LUT[512] = { 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100, 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200 }; + static void Blit_RGB565_ARGB8888(SDL_BlitInfo * info) { @@ -1572,6 +1573,7 @@ static const Uint32 RGB565_ABGR8888_LUT[512] = { 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff, 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff }; + static void Blit_RGB565_ABGR8888(SDL_BlitInfo * info) { @@ -1709,6 +1711,7 @@ static const Uint32 RGB565_RGBA8888_LUT[512] = { 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000, 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000, }; + static void Blit_RGB565_RGBA8888(SDL_BlitInfo * info) { @@ -1846,6 +1849,7 @@ static const Uint32 RGB565_BGRA8888_LUT[512] = { 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff, 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff }; + static void Blit_RGB565_BGRA8888(SDL_BlitInfo * info) { @@ -1930,6 +1934,7 @@ Blit_RGB888_index8_map(SDL_BlitInfo * info) } #endif /* USE_DUFFS_LOOP */ } + static void BlitNto1(SDL_BlitInfo * info) { @@ -2340,6 +2345,7 @@ static const struct blit_table normal_blit_1[] = { /* 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 @@ static const struct blit_table normal_blit_2[] = { /* 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 @@ static const struct blit_table normal_blit_4[] = { /* 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 }; diff --git a/src/video/SDL_gamma.c b/src/video/SDL_gamma.c index cd1dd1bc2..92bc5d2f7 100644 --- a/src/video/SDL_gamma.c +++ b/src/video/SDL_gamma.c @@ -70,6 +70,7 @@ CalculateGammaRamp(float gamma, Uint16 * ramp) } } } + static void CalculateGammaFromRamp(float *gamma, Uint16 * ramp) { diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 1d15f7bce..550eddc17 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -168,12 +168,16 @@ SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, 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 @@ SDL_InvalidateMap(SDL_BlitMap * map) map->info.table = NULL; } } + int SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) { diff --git a/src/video/SDL_renderer_sw.c b/src/video/SDL_renderer_sw.c index 2c4133078..a0aef99bf 100644 --- a/src/video/SDL_renderer_sw.c +++ b/src/video/SDL_renderer_sw.c @@ -388,8 +388,9 @@ SW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ SW_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, 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 @@ SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 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; } diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 3d7a68c70..6102ce680 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -409,9 +409,9 @@ SDL_GetSurfaceBlendMode(SDL_Surface * surface, int *blendMode) 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; diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index fbc9408db..e97ee375d 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -369,6 +369,9 @@ extern VideoBootStrap OS2FSLib_bootstrap; #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]) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index a5354c224..42ddf3085 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -103,6 +103,9 @@ static VideoBootStrap *bootstrap[] = { #if SDL_VIDEO_DRIVER_OS2FS &OS2FSLib_bootstrap, #endif +#if SDL_VIDEO_DRIVER_NDS + &NDS_bootstrap, +#endif #if SDL_VIDEO_DRIVER_DUMMY &DUMMY_bootstrap, #endif diff --git a/src/video/ataricommon/SDL_atarigl.c b/src/video/ataricommon/SDL_atarigl.c index 03df3755b..2c4fd9482 100644 --- a/src/video/ataricommon/SDL_atarigl.c +++ b/src/video/ataricommon/SDL_atarigl.c @@ -349,9 +349,9 @@ SDL_AtariGL_MakeCurrent(_THIS) } 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 @@ InitNew(_THIS, SDL_Surface * current) 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) { diff --git a/src/video/bwindow/SDL_sysvideo.cc b/src/video/bwindow/SDL_sysvideo.cc index 77970afbc..752d59883 100644 --- a/src/video/bwindow/SDL_sysvideo.cc +++ b/src/video/bwindow/SDL_sysvideo.cc @@ -670,8 +670,8 @@ extern "C" _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)); } } } diff --git a/src/video/dc/SDL_dcevents.c b/src/video/dc/SDL_dcevents.c index e39b538e5..20855fdf7 100644 --- a/src/video/dc/SDL_dcevents.c +++ b/src/video/dc/SDL_dcevents.c @@ -135,8 +135,7 @@ keyboard_update(void) 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 @@ keyboard_update(void) 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); } } diff --git a/src/video/dc/SDL_dcvideo.c b/src/video/dc/SDL_dcvideo.c index 7a4d4d993..bceb009af 100644 --- a/src/video/dc/SDL_dcvideo.c +++ b/src/video/dc/SDL_dcvideo.c @@ -158,6 +158,7 @@ DC_VideoInit(_THIS, SDL_PixelFormat * vformat) 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 @@ DC_AllocHWSurface(_THIS, SDL_Surface * surface) { return (-1); } + static void DC_FreeHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c index 1e783bdf9..901e3bee0 100644 --- a/src/video/directfb/SDL_DirectFB_events.c +++ b/src/video/directfb/SDL_DirectFB_events.c @@ -383,33 +383,25 @@ DirectFB_PumpEvents(_THIS) 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) { diff --git a/src/video/directfb/SDL_DirectFB_mouse.c b/src/video/directfb/SDL_DirectFB_mouse.c index 3447d5770..1395e593b 100644 --- a/src/video/directfb/SDL_DirectFB_mouse.c +++ b/src/video/directfb/SDL_DirectFB_mouse.c @@ -85,14 +85,15 @@ DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) 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 @@ DirectFB_ShowCursor(SDL_Cursor * cursor) 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 @@ DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y) 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; diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c index 9090b4cfa..57f94f4ef 100644 --- a/src/video/directfb/SDL_DirectFB_video.c +++ b/src/video/directfb/SDL_DirectFB_video.c @@ -314,8 +314,8 @@ DirectFB_VideoInit(_THIS) 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 @@ DirectFB_VideoInit(_THIS) 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 @@ DirectFB_VideoInit(_THIS) /* 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 @@ DirectFB_VideoQuit(_THIS) 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 @@ DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode) 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 @@ DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode) 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 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) 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 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) 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 @@ DirectFB_CreateWindow(_THIS, SDL_Window * window) 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 @@ DirectFB_SetWindowTitle(_THIS, SDL_Window * window) //return -1; } + static void DirectFB_SetWindowPosition(_THIS, SDL_Window * window) { @@ -886,6 +889,7 @@ DirectFB_HideWindow(_THIS, SDL_Window * window) windata->window->SetOpacity(windata->window, 0); } + static void DirectFB_RaiseWindow(_THIS, SDL_Window * window) { @@ -907,6 +911,7 @@ DirectFB_MaximizeWindow(_THIS, SDL_Window * window) SDL_Unsupported(); } + static void DirectFB_MinimizeWindow(_THIS, SDL_Window * window) { @@ -928,6 +933,7 @@ DirectFB_RestoreWindow(_THIS, SDL_Window * window) SDL_Unsupported(); } + static void DirectFB_SetWindowGrab(_THIS, SDL_Window * window) { @@ -1156,8 +1162,8 @@ DirectFB_GL_SwapWindow(_THIS, SDL_Window * window) 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; diff --git a/src/video/fbcon/SDL_fb3dfx.c b/src/video/fbcon/SDL_fb3dfx.c index a40cf2534..7a927050a 100644 --- a/src/video/fbcon/SDL_fb3dfx.c +++ b/src/video/fbcon/SDL_fb3dfx.c @@ -37,6 +37,7 @@ WaitVBL(_THIS) /* wait until we're past the start */ while ((tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0); } + static void WaitIdle(_THIS) { diff --git a/src/video/fbcon/SDL_fbelo.c b/src/video/fbcon/SDL_fbelo.c index d85aebdb6..9f9f56110 100644 --- a/src/video/fbcon/SDL_fbelo.c +++ b/src/video/fbcon/SDL_fbelo.c @@ -268,8 +268,7 @@ eloWaitReply(unsigned char type, unsigned char *reply, int fd) if (result == 0) { i--; } - } - while (!ok && (i > 0)); + } while (!ok && (i > 0)); return ok; } diff --git a/src/video/fbcon/SDL_fbevents.c b/src/video/fbcon/SDL_fbevents.c index 2bf6ad452..4e5551786 100644 --- a/src/video/fbcon/SDL_fbevents.c +++ b/src/video/fbcon/SDL_fbevents.c @@ -545,9 +545,8 @@ detect_imps2(int fd) 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 @@ switch_vt_prep(_THIS) ioctl(keyboard_fd, KDSETMODE, KD_TEXT); ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); } + static void switch_vt_done(_THIS) { @@ -995,6 +995,7 @@ switch_vt_done(_THIS) (SDL_APPACTIVE | SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS)); } + static void switch_vt(_THIS, unsigned short which) { @@ -1113,8 +1114,7 @@ FB_PumpEvents(_THIS) } } } - } - while (posted); + } while (posted); } void diff --git a/src/video/fbcon/SDL_fbmatrox.c b/src/video/fbcon/SDL_fbmatrox.c index bcf774602..22cde3827 100644 --- a/src/video/fbcon/SDL_fbmatrox.c +++ b/src/video/fbcon/SDL_fbmatrox.c @@ -41,6 +41,7 @@ WaitVBL(_THIS) count = mga_in32(0x1E20) + 2; while (mga_in32(0x1E20) < count); } + static void WaitIdle(_THIS) { diff --git a/src/video/fbcon/SDL_fbriva.c b/src/video/fbcon/SDL_fbriva.c index 6c1044832..a1bcc0806 100644 --- a/src/video/fbcon/SDL_fbriva.c +++ b/src/video/fbcon/SDL_fbriva.c @@ -40,6 +40,7 @@ WaitVBL(_THIS) while ((*port & 0x08)); while (!(*port & 0x08)); } + static void NV3WaitIdle(_THIS) { @@ -47,6 +48,7 @@ NV3WaitIdle(_THIS) while ((Rop->FifoFree < FifoEmptyCount) || (*(mapped_io + PGRAPH_OFFSET + 0x000006B0) & 0x01)); } + static void NV4WaitIdle(_THIS) { diff --git a/src/video/fbcon/SDL_fbvideo.c b/src/video/fbcon/SDL_fbvideo.c index 50b85762d..738ced323 100644 --- a/src/video/fbcon/SDL_fbvideo.c +++ b/src/video/fbcon/SDL_fbvideo.c @@ -82,6 +82,7 @@ static const SDL_Rect checkres[] = { {0, 0, 320, 240}, {0, 0, 320, 200} }; + static const struct { int xres; @@ -323,15 +324,13 @@ read_fbmodes_line(FILE * f, char *line, int length) 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 @@ read_fbmodes_mode(FILE * f, struct fb_var_screeninfo *vinfo) 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 @@ read_fbmodes_mode(FILE * f, struct fb_var_screeninfo *vinfo) 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 @@ print_vinfo(struct fb_var_screeninfo *vinfo) 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 @@ FB_InitHWSurfaces(_THIS, SDL_Surface * screen, char *base, int size) screen->hwdata = (struct private_hwdata *) &surfaces; return (0); } + static void FB_FreeHWSurfaces(_THIS) { @@ -1283,6 +1282,7 @@ FB_AllocHWSurface(_THIS, SDL_Surface * surface) surface->hwdata = (struct private_hwdata *) bucket; return (0); } + static void FB_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -1352,6 +1352,7 @@ FB_LockHWSurface(_THIS, SDL_Surface * surface) } return (0); } + static void FB_UnlockHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/gapi/SDL_gapivideo.c b/src/video/gapi/SDL_gapivideo.c index 40da2afef..58cf807fd 100644 --- a/src/video/gapi/SDL_gapivideo.c +++ b/src/video/gapi/SDL_gapivideo.c @@ -340,8 +340,7 @@ GAPI_CreateDevice(int devindex) 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 @@ GAPI_AllocHWSurface(_THIS, SDL_Surface * surface) { return (-1); } + static void GAPI_FreeHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/ipod/SDL_ipodvideo.c b/src/video/ipod/SDL_ipodvideo.c index b338e6fc0..1ccaac44b 100644 --- a/src/video/ipod/SDL_ipodvideo.c +++ b/src/video/ipod/SDL_ipodvideo.c @@ -526,8 +526,7 @@ iPod_PumpEvents(_THIS) } if (dbgout) fprintf(dbgout, "\n"); - } - while (posted); + } while (posted); } // enough space for 160x128x2 @@ -570,8 +569,7 @@ M_lcd_wait_write(void) 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 @@ C_lcd_wait_write(void) 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_UpdateRects(_THIS, int nrects, SDL_Rect * rects) 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)); } } } diff --git a/src/video/nds/SDL_ndsevents.c b/src/video/nds/SDL_ndsevents.c new file mode 100644 index 000000000..99ebf11c3 --- /dev/null +++ b/src/video/nds/SDL_ndsevents.c @@ -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 +#include +#include + +#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: */ diff --git a/src/video/nds/SDL_ndsevents_c.h b/src/video/nds/SDL_ndsevents_c.h new file mode 100644 index 000000000..03ff73518 --- /dev/null +++ b/src/video/nds/SDL_ndsevents_c.h @@ -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: */ diff --git a/src/video/nds/SDL_ndsrender.c b/src/video/nds/SDL_ndsrender.c new file mode 100644 index 000000000..9e5e2ba90 --- /dev/null +++ b/src/video/nds/SDL_ndsrender.c @@ -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 +#include +#include +#include +#include +#include + +#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: */ diff --git a/src/video/nds/SDL_ndsrender_c.h b/src/video/nds/SDL_ndsrender_c.h new file mode 100644 index 000000000..cbc581c0a --- /dev/null +++ b/src/video/nds/SDL_ndsrender_c.h @@ -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: */ diff --git a/src/video/nds/SDL_ndsvideo.c b/src/video/nds/SDL_ndsvideo.c new file mode 100644 index 000000000..a09267a95 --- /dev/null +++ b/src/video/nds/SDL_ndsvideo.c @@ -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 +#include +#include +#include + +#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: */ diff --git a/src/video/nds/SDL_ndsvideo.h b/src/video/nds/SDL_ndsvideo.h new file mode 100644 index 000000000..bbd32228f --- /dev/null +++ b/src/video/nds/SDL_ndsvideo.h @@ -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: */ diff --git a/src/video/os2fslib/SDL_os2fslib.c b/src/video/os2fslib/SDL_os2fslib.c index ab5d3d58b..e7174594f 100644 --- a/src/video/os2fslib/SDL_os2fslib.c +++ b/src/video/os2fslib/SDL_os2fslib.c @@ -440,8 +440,8 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { 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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) &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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) &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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) &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 @@ WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) &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 @@ memnot(Uint8 * dst, Uint8 * src, int len) while (len-- > 0) *dst++ = ~*src++; } + static void memxor(Uint8 * dst, Uint8 * src1, Uint8 * src2, int len) { @@ -1635,6 +1631,7 @@ os2fslib_AllocHWSurface(_THIS, SDL_Surface * surface) { return (-1); } + static void os2fslib_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -2505,23 +2502,27 @@ os2fslib_SetVideoMode(_THIS, SDL_Surface * current, 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 @@ os2fslib_SetVideoMode(_THIS, SDL_Surface * current, // 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 @@ os2fslib_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) 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 @@ os2fslib_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) // 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 @@ os2fslib_VideoInit(_THIS, SDL_PixelFormat * vformat) 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 @@ os2fslib_VideoInit(_THIS, SDL_PixelFormat * vformat) 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 diff --git a/src/video/photon/SDL_ph_gl.c b/src/video/photon/SDL_ph_gl.c index 09c0495c1..43ca58d2f 100644 --- a/src/video/photon/SDL_ph_gl.c +++ b/src/video/photon/SDL_ph_gl.c @@ -315,11 +315,14 @@ ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) && (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); diff --git a/src/video/photon/SDL_ph_image.c b/src/video/photon/SDL_ph_image.c index 12bcc2a1c..211170d21 100644 --- a/src/video/photon/SDL_ph_image.c +++ b/src/video/photon/SDL_ph_image.c @@ -244,9 +244,8 @@ ph_SetupFullScreenImage(_THIS, SDL_Surface * screen) } 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"); diff --git a/src/video/photon/SDL_phyuv.c b/src/video/photon/SDL_phyuv.c index a2b9962c4..609a70cf1 100644 --- a/src/video/photon/SDL_phyuv.c +++ b/src/video/photon/SDL_phyuv.c @@ -149,8 +149,8 @@ ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, &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 @@ ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, break; } i++; - } - while (1); + } while (1); if (vidport == -1) { diff --git a/src/video/ps2gs/SDL_gsevents.c b/src/video/ps2gs/SDL_gsevents.c index c41274977..3156163f9 100644 --- a/src/video/ps2gs/SDL_gsevents.c +++ b/src/video/ps2gs/SDL_gsevents.c @@ -479,9 +479,8 @@ detect_imps2(int fd) 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 @@ GS_PumpEvents(_THIS) } } } - } - while (posted); + } while (posted); } void diff --git a/src/video/ps2gs/SDL_gsvideo.c b/src/video/ps2gs/SDL_gsvideo.c index cef67b120..12bd8c5d5 100644 --- a/src/video/ps2gs/SDL_gsvideo.c +++ b/src/video/ps2gs/SDL_gsvideo.c @@ -232,6 +232,7 @@ static unsigned long long tex_tags[] __attribute__ ((aligned(16))) = { 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 @@ GS_AllocHWSurface(_THIS, SDL_Surface * surface) { return (-1); } + static void GS_FreeHWSurface(_THIS, SDL_Surface * surface) { return; } + static int GS_LockHWSurface(_THIS, SDL_Surface * surface) { @@ -606,6 +609,7 @@ GS_LockHWSurface(_THIS, SDL_Surface * surface) } return (0); } + static void GS_UnlockHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c index cda29f07c..06d092e97 100644 --- a/src/video/riscos/SDL_riscosvideo.c +++ b/src/video/riscos/SDL_riscosvideo.c @@ -286,6 +286,7 @@ RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface) { return (-1); } + static void RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/svga/SDL_svgaevents.c b/src/video/svga/SDL_svgaevents.c index 84e8d7017..5d5c88856 100644 --- a/src/video/svga/SDL_svgaevents.c +++ b/src/video/svga/SDL_svgaevents.c @@ -207,8 +207,7 @@ SVGA_PumpEvents(_THIS) posted = 0; mouse_update(); keyboard_update(); - } - while (posted); + } while (posted); } void diff --git a/src/video/svga/SDL_svgavideo.c b/src/video/svga/SDL_svgavideo.c index 93d664c6e..cb05b2d08 100644 --- a/src/video/svga/SDL_svgavideo.c +++ b/src/video/svga/SDL_svgavideo.c @@ -467,6 +467,7 @@ SVGA_AllocHWSurface(_THIS, SDL_Surface * surface) { return (-1); } + static void SVGA_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -480,6 +481,7 @@ SVGA_LockHWSurface(_THIS, SDL_Surface * surface) /* The waiting is done in SVGA_FlipHWSurface() */ return (0); } + static void SVGA_UnlockHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/vgl/SDL_vglevents.c b/src/video/vgl/SDL_vglevents.c index 4520c4620..8f7a7f43b 100644 --- a/src/video/vgl/SDL_vglevents.c +++ b/src/video/vgl/SDL_vglevents.c @@ -141,8 +141,7 @@ VGL_PumpEvents(_THIS) posted = 0; handle_keyboard(this); handle_mouse(this); - } - while (posted != 0); + } while (posted != 0); } void diff --git a/src/video/vgl/SDL_vglvideo.c b/src/video/vgl/SDL_vglvideo.c index 3dee9f12e..1c3f81aac 100644 --- a/src/video/vgl/SDL_vglvideo.c +++ b/src/video/vgl/SDL_vglvideo.c @@ -409,6 +409,7 @@ VGL_AllocHWSurface(_THIS, SDL_Surface * surface) { return -1; } + static void VGL_FreeHWSurface(_THIS, SDL_Surface * surface) { @@ -424,6 +425,7 @@ VGL_LockHWSurface(_THIS, SDL_Surface * surface) } return 0; } + static void VGL_UnlockHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/win32/SDL_d3drender.c b/src/video/win32/SDL_d3drender.c index b17ad2542..503c80acb 100644 --- a/src/video/win32/SDL_d3drender.c +++ b/src/video/win32/SDL_d3drender.c @@ -596,8 +596,8 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, } 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; diff --git a/src/video/win32/SDL_gdirender.c b/src/video/win32/SDL_gdirender.c index 90e5c5776..b32a90e48 100644 --- a/src/video/win32/SDL_gdirender.c +++ b/src/video/win32/SDL_gdirender.c @@ -620,9 +620,8 @@ GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 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, diff --git a/src/video/win32/SDL_win32keyboard.c b/src/video/win32/SDL_win32keyboard.c index 7cba3bb95..cce6a6a09 100644 --- a/src/video/win32/SDL_win32keyboard.c +++ b/src/video/win32/SDL_win32keyboard.c @@ -41,6 +41,7 @@ BYTE alpha_scancodes[26] = { 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 }; diff --git a/src/video/win32/SDL_win32opengl.c b/src/video/win32/SDL_win32opengl.c index 66184e2ec..550316ad4 100644 --- a/src/video/win32/SDL_win32opengl.c +++ b/src/video/win32/SDL_win32opengl.c @@ -500,8 +500,7 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window) 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); } diff --git a/src/video/wscons/SDL_wsconsevents.c b/src/video/wscons/SDL_wsconsevents.c index b68608ba8..ac1d34395 100644 --- a/src/video/wscons/SDL_wsconsevents.c +++ b/src/video/wscons/SDL_wsconsevents.c @@ -145,8 +145,7 @@ WSCONS_PumpEvents(_THIS) posted = 0; updateMouse(); updateKeyboard(this); - } - while (posted); + } while (posted); } void diff --git a/src/video/wscons/SDL_wsconsvideo.c b/src/video/wscons/SDL_wsconsvideo.c index 3ca86e5ee..126ec6bbc 100644 --- a/src/video/wscons/SDL_wsconsvideo.c +++ b/src/video/wscons/SDL_wsconsvideo.c @@ -399,6 +399,7 @@ WSCONS_AllocHWSurface(_THIS, SDL_Surface * surface) { return -1; } + static void WSCONS_FreeHWSurface(_THIS, SDL_Surface * surface) { diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 48323877e..69a4f3305 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -417,8 +417,8 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) 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; diff --git a/src/video/xbios/SDL_xbiosmodes.c b/src/video/xbios/SDL_xbiosmodes.c index a2736d3d5..9fd491a14 100644 --- a/src/video/xbios/SDL_xbiosmodes.c +++ b/src/video/xbios/SDL_xbiosmodes.c @@ -277,8 +277,8 @@ SDL_XBIOS_InitModes(_THIS) 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_InitModes(_THIS) 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; } diff --git a/test/nds-test-progs/general/Makefile b/test/nds-test-progs/general/Makefile new file mode 100755 index 000000000..0f59a0e76 --- /dev/null +++ b/test/nds-test-progs/general/Makefile @@ -0,0 +1,132 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=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 +#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/general/source/main.c b/test/nds-test-progs/general/source/main.c new file mode 100755 index 000000000..2bc5e3102 --- /dev/null +++ b/test/nds-test-progs/general/source/main.c @@ -0,0 +1,96 @@ + +#include +#if defined(NDS) || defined(__NDS__) || defined (__NDS) +#include +#include +#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; + } + + diff --git a/test/nds-test-progs/sprite/Makefile b/test/nds-test-progs/sprite/Makefile new file mode 100755 index 000000000..0f59a0e76 --- /dev/null +++ b/test/nds-test-progs/sprite/Makefile @@ -0,0 +1,132 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=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 +#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/sprite/source/common.c b/test/nds-test-progs/sprite/source/common.c new file mode 100755 index 000000000..364b8460a --- /dev/null +++ b/test/nds-test-progs/sprite/source/common.c @@ -0,0 +1,965 @@ + +/* A simple test program framework */ + +#include + +#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); +} diff --git a/test/nds-test-progs/sprite/source/common.h b/test/nds-test-progs/sprite/source/common.h new file mode 100755 index 000000000..0e0393198 --- /dev/null +++ b/test/nds-test-progs/sprite/source/common.h @@ -0,0 +1,48 @@ + +/* A simple test program framework */ + +#include + +#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); diff --git a/test/nds-test-progs/sprite/source/testsprite.c b/test/nds-test-progs/sprite/source/testsprite.c new file mode 100755 index 000000000..4134de581 --- /dev/null +++ b/test/nds-test-progs/sprite/source/testsprite.c @@ -0,0 +1,316 @@ +/* Simple program: Move N sprites around on the screen as fast as possible */ + +#include +#include +#include +#include +#include +#include + +#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); +} diff --git a/test/nds-test-progs/sprite2/Makefile b/test/nds-test-progs/sprite2/Makefile new file mode 100755 index 000000000..2612f5a7e --- /dev/null +++ b/test/nds-test-progs/sprite2/Makefile @@ -0,0 +1,132 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=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 +#--------------------------------------------------------------------------------------- diff --git a/test/nds-test-progs/sprite2/source/common.c b/test/nds-test-progs/sprite2/source/common.c new file mode 100755 index 000000000..364b8460a --- /dev/null +++ b/test/nds-test-progs/sprite2/source/common.c @@ -0,0 +1,965 @@ + +/* A simple test program framework */ + +#include + +#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); +} diff --git a/test/nds-test-progs/sprite2/source/common.h b/test/nds-test-progs/sprite2/source/common.h new file mode 100755 index 000000000..0e0393198 --- /dev/null +++ b/test/nds-test-progs/sprite2/source/common.h @@ -0,0 +1,48 @@ + +/* A simple test program framework */ + +#include + +#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); diff --git a/test/nds-test-progs/sprite2/source/testsprite2.c b/test/nds-test-progs/sprite2/source/testsprite2.c new file mode 100755 index 000000000..1db283c78 --- /dev/null +++ b/test/nds-test-progs/sprite2/source/testsprite2.c @@ -0,0 +1,330 @@ +/* Simple program: Move N sprites around on the screen as fast as possible */ + +#include +#include +#include +#include +#include +#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: */ diff --git a/test/testblitspeed.c b/test/testblitspeed.c index f3f023e20..e365f3aba 100644 --- a/test/testblitspeed.c +++ b/test/testblitspeed.c @@ -397,8 +397,7 @@ test_blit_speed(void) } 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)); diff --git a/test/testdyngl.c b/test/testdyngl.c index e98ae4107..5e4275e33 100644 --- a/test/testdyngl.c +++ b/test/testdyngl.c @@ -185,8 +185,7 @@ main(int argc, char *argv[]) } SDL_Delay(20); - } - while (!done); + } while (!done); SDL_Quit(); return 0; diff --git a/test/testpalette.c b/test/testpalette.c index 921e6c46f..8fd84be03 100644 --- a/test/testpalette.c +++ b/test/testpalette.c @@ -338,8 +338,7 @@ main(int argc, char **argv) /* 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));