Final merge of Google Summer of Code 2008 work...
authorSam Lantinga <slouken@libsdl.org>
Wed, 27 Aug 2008 15:10:03 +0000
changeset 2735204be4fc2726
parent 2734 dd25eabe441c
child 2736 ae653575d4af
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
include/SDL_config.h.default
include/SDL_config.h.in
include/SDL_config_nintendods.h
include/SDL_pixels.h
include/SDL_platform.h
include/SDL_stdinc.h
src/SDL_compat.c
src/SDL_error.c
src/audio/SDL_audio.c
src/audio/SDL_wave.c
src/audio/alsa/SDL_alsa_audio.c
src/audio/bsd/SDL_bsdaudio.c
src/audio/dart/SDL_dart.c
src/audio/dma/SDL_dmaaudio.c
src/audio/esd/SDL_esdaudio.c
src/audio/nds/SDL_ndsaudio.c
src/audio/nds/SDL_ndsaudio.h
src/audio/nto/SDL_nto_audio.c
src/audio/paudio/SDL_paudio.c
src/audio/ums/SDL_umsaudio.c
src/audio/windib/SDL_dibaudio.c
src/audio/windx5/SDL_dx5audio.c
src/cdrom/SDL_cdrom.c
src/cdrom/aix/SDL_syscdrom.c
src/cdrom/beos/SDL_syscdrom.cc
src/cdrom/bsdi/SDL_syscdrom.c
src/cdrom/freebsd/SDL_syscdrom.c
src/cdrom/linux/SDL_syscdrom.c
src/cdrom/macosx/AudioFilePlayer.c
src/cdrom/macosx/AudioFileReaderThread.c
src/cdrom/macosx/CDPlayer.c
src/cdrom/openbsd/SDL_syscdrom.c
src/cdrom/osf/SDL_syscdrom.c
src/cdrom/qnx/SDL_syscdrom.c
src/events/SDL_events.c
src/events/default_cursor.h
src/file/SDL_rwops.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick.c
src/joystick/nds/SDL_sysjoystick.c
src/loadso/macosx/SDL_dlcompat.c
src/main/beos/SDL_BeApp.cc
src/stdlib/SDL_stdlib.c
src/thread/SDL_thread_c.h
src/thread/irix/SDL_syssem.c
src/thread/nds/SDL_syscond.c
src/thread/nds/SDL_syscond_c.h
src/thread/nds/SDL_sysmutex.c
src/thread/nds/SDL_sysmutex_c.h
src/thread/nds/SDL_syssem.c
src/thread/nds/SDL_syssem_c.h
src/thread/nds/SDL_systhread.c
src/thread/nds/SDL_systhread_c.h
src/thread/pthread/SDL_syssem.c
src/thread/riscos/SDL_syssem.c
src/timer/nds/SDL_systimer.c
src/timer/riscos/SDL_systimer.c
src/timer/unix/SDL_systimer.c
src/video/SDL_RLEaccel.c
src/video/SDL_blit_0.c
src/video/SDL_blit_1.c
src/video/SDL_blit_A.c
src/video/SDL_blit_N.c
src/video/SDL_gamma.c
src/video/SDL_pixels.c
src/video/SDL_renderer_sw.c
src/video/SDL_surface.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/ataricommon/SDL_atarigl.c
src/video/bwindow/SDL_sysvideo.cc
src/video/dc/SDL_dcevents.c
src/video/dc/SDL_dcvideo.c
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_mouse.c
src/video/directfb/SDL_DirectFB_video.c
src/video/fbcon/SDL_fb3dfx.c
src/video/fbcon/SDL_fbelo.c
src/video/fbcon/SDL_fbevents.c
src/video/fbcon/SDL_fbmatrox.c
src/video/fbcon/SDL_fbriva.c
src/video/fbcon/SDL_fbvideo.c
src/video/gapi/SDL_gapivideo.c
src/video/ipod/SDL_ipodvideo.c
src/video/nds/SDL_ndsevents.c
src/video/nds/SDL_ndsevents_c.h
src/video/nds/SDL_ndsrender.c
src/video/nds/SDL_ndsrender_c.h
src/video/nds/SDL_ndsvideo.c
src/video/nds/SDL_ndsvideo.h
src/video/os2fslib/SDL_os2fslib.c
src/video/photon/SDL_ph_gl.c
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_phyuv.c
src/video/ps2gs/SDL_gsevents.c
src/video/ps2gs/SDL_gsvideo.c
src/video/riscos/SDL_riscosvideo.c
src/video/svga/SDL_svgaevents.c
src/video/svga/SDL_svgavideo.c
src/video/vgl/SDL_vglevents.c
src/video/vgl/SDL_vglvideo.c
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_gdirender.c
src/video/win32/SDL_win32keyboard.c
src/video/win32/SDL_win32opengl.c
src/video/wscons/SDL_wsconsevents.c
src/video/wscons/SDL_wsconsvideo.c
src/video/x11/SDL_x11opengl.c
src/video/xbios/SDL_xbiosmodes.c
test/nds-test-progs/general/Makefile
test/nds-test-progs/general/source/main.c
test/nds-test-progs/sprite/Makefile
test/nds-test-progs/sprite/source/common.c
test/nds-test-progs/sprite/source/common.h
test/nds-test-progs/sprite/source/testsprite.c
test/nds-test-progs/sprite2/Makefile
test/nds-test-progs/sprite2/source/common.c
test/nds-test-progs/sprite2/source/common.h
test/nds-test-progs/sprite2/source/testsprite2.c
test/testblitspeed.c
test/testdyngl.c
test/testpalette.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile.ds	Wed Aug 27 15:10:03 2008 +0000
     1.3 @@ -0,0 +1,129 @@
     1.4 +
     1.5 +#LibSDL 1.3 porting and enhancements by Darren Alton (lifning)
     1.6 +#LibSDL 1.2.9 DS porting by Troy Davis(GPF)
     1.7 +
     1.8 +ifeq ($(strip $(DEVKITPRO)),)
     1.9 +$(error "Please set DEVKITPRO in your environment (available from http://www.devkitpro.org). export DEVKITPRO=<path to>devkitPro")
    1.10 +endif
    1.11 +ifeq ($(strip $(DEVKITARM)),)
    1.12 +DEVKITARM = $(DEVKITPRO)/devkitARM
    1.13 +endif
    1.14 +PATH := $(PATH):$(DEVKITARM)/bin
    1.15 +
    1.16 +CC = arm-eabi-gcc
    1.17 +AR = arm-eabi-ar
    1.18 +RANLIB = arm-eabi-ranlib
    1.19 +
    1.20 +#ifdef GL
    1.21 +#DEFS += -DSDL_VIDEO_OPENGL=1
    1.22 +#TARGET = libSDL_gl.a
    1.23 +#else
    1.24 +TARGET = libSDL.a
    1.25 +#endif
    1.26 +
    1.27 +#CFLAGS=$(DEFS) -Iinclude
    1.28 +CFLAGS	=	-mthumb -mthumb-interwork \
    1.29 +		-march=armv5te -mtune=arm946e-s \
    1.30 +		-O2 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
    1.31 +		-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 \
    1.32 +		-Iinclude -Isrc -Isrc/audio -Isrc/cdrom -Isrc/endian -Isrc/events -Isrc/joystick -Isrc/thread/nds -Isrc/thread -Isrc/timer -Isrc/video
    1.33 +
    1.34 +#src/audio/disk/SDL_diskaudio.c \
    1.35 +#src/audio/dummy/SDL_dummyaudio.c \
    1.36 +
    1.37 +SRCS = \
    1.38 +src/SDL.c \
    1.39 +src/SDL_compat.c \
    1.40 +src/SDL_error.c \
    1.41 +src/SDL_fatal.c \
    1.42 +src/audio/nds/SDL_ndsaudio.c \
    1.43 +src/audio/SDL_audio.c \
    1.44 +src/audio/SDL_audiocvt.c \
    1.45 +src/audio/SDL_audiodev.c \
    1.46 +src/audio/SDL_audiotypecvt.c \
    1.47 +src/audio/SDL_mixer.c \
    1.48 +src/audio/SDL_mixer_m68k.c \
    1.49 +src/audio/SDL_mixer_MMX.c \
    1.50 +src/audio/SDL_mixer_MMX_VC.c \
    1.51 +src/audio/SDL_wave.c \
    1.52 +src/cdrom/dummy/SDL_syscdrom.c \
    1.53 +src/cdrom/SDL_cdrom.c \
    1.54 +src/cpuinfo/SDL_cpuinfo.c \
    1.55 +src/events/SDL_events.c \
    1.56 +src/events/SDL_keyboard.c \
    1.57 +src/events/SDL_mouse.c \
    1.58 +src/events/SDL_quit.c \
    1.59 +src/events/SDL_windowevents.c \
    1.60 +src/file/SDL_rwops.c \
    1.61 +src/joystick/nds/SDL_sysjoystick.c \
    1.62 +src/joystick/SDL_joystick.c \
    1.63 +src/stdlib/SDL_getenv.c \
    1.64 +src/stdlib/SDL_iconv.c \
    1.65 +src/stdlib/SDL_malloc.c \
    1.66 +src/stdlib/SDL_qsort.c \
    1.67 +src/stdlib/SDL_stdlib.c \
    1.68 +src/stdlib/SDL_string.c \
    1.69 +src/thread/SDL_thread.c \
    1.70 +src/thread/nds/SDL_syscond.c \
    1.71 +src/thread/nds/SDL_sysmutex.c \
    1.72 +src/thread/nds/SDL_syssem.c \
    1.73 +src/thread/nds/SDL_systhread.c \
    1.74 +src/timer/nds/SDL_systimer.c \
    1.75 +src/timer/SDL_timer.c \
    1.76 +src/video/nds/SDL_ndsevents.c \
    1.77 +src/video/nds/SDL_ndsrender.c \
    1.78 +src/video/nds/SDL_ndsvideo.c \
    1.79 +src/video/dummy/SDL_nullevents.c \
    1.80 +src/video/dummy/SDL_nullrender.c \
    1.81 +src/video/dummy/SDL_nullvideo.c \
    1.82 +src/video/SDL_blit_0.c \
    1.83 +src/video/SDL_blit_1.c \
    1.84 +src/video/SDL_blit_A.c \
    1.85 +src/video/SDL_blit_auto.c \
    1.86 +src/video/SDL_blit.c \
    1.87 +src/video/SDL_blit_copy.c \
    1.88 +src/video/SDL_blit_N.c \
    1.89 +src/video/SDL_blit_slow.c \
    1.90 +src/video/SDL_bmp.c \
    1.91 +src/video/SDL_fill.c \
    1.92 +src/video/SDL_gamma.c \
    1.93 +src/video/SDL_pixels.c \
    1.94 +src/video/SDL_rect.c \
    1.95 +src/video/SDL_renderer_gl.c \
    1.96 +src/video/SDL_renderer_sw.c \
    1.97 +src/video/SDL_RLEaccel.c \
    1.98 +src/video/SDL_stretch.c \
    1.99 +src/video/SDL_surface.c \
   1.100 +src/video/SDL_video.c \
   1.101 +src/video/SDL_yuv_mmx.c \
   1.102 +src/video/SDL_yuv_sw.c \
   1.103 +
   1.104 +OBJS = $(SRCS:.c=.o)
   1.105 +
   1.106 +TEST = \
   1.107 +test/nds-test-progs/general/general.nds \
   1.108 +test/nds-test-progs/sprite/sprite.nds \
   1.109 +test/nds-test-progs/sprite2/sprite2.nds \
   1.110 +
   1.111 +
   1.112 +all: $(TARGET)
   1.113 +
   1.114 +$(TARGET): copy_config \
   1.115 +	$(OBJS)
   1.116 +	$(AR) rc $(TARGET) $(OBJS)
   1.117 +	-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
   1.118 +
   1.119 +install: $(TARGET)
   1.120 +	@cp libSDL.a $(DEVKITPRO)/libnds/lib/
   1.121 +	@mkdir -p $(DEVKITPRO)/libnds/include/SDL/
   1.122 +	@cp include/*.h $(DEVKITPRO)/libnds/include/SDL/
   1.123 +
   1.124 +nds_test:
   1.125 +	$(MAKE) -C test/nds-test-progs
   1.126 +
   1.127 +copy_config:
   1.128 +	@cp include/SDL_config.h.default include/SDL_config.h
   1.129 +
   1.130 +clean:
   1.131 +	rm -f include/SDL_config.h $(OBJS)
   1.132 +
     2.1 --- a/include/SDL_config.h.default	Wed Aug 27 13:37:19 2008 +0000
     2.2 +++ b/include/SDL_config.h.default	Wed Aug 27 15:10:03 2008 +0000
     2.3 @@ -26,7 +26,9 @@
     2.4  #include "SDL_platform.h"
     2.5  
     2.6  /* Add any platform that doesn't build using the configure system */
     2.7 -#if defined(__DREAMCAST__)
     2.8 +#if defined(__NINTENDODS__)
     2.9 +#include "SDL_config_nintendods.h"
    2.10 +#elif defined(__DREAMCAST__)
    2.11  #include "SDL_config_dreamcast.h"
    2.12  #elif defined(__MACOSX__)
    2.13  #include "SDL_config_macosx.h"
     3.1 --- a/include/SDL_config.h.in	Wed Aug 27 13:37:19 2008 +0000
     3.2 +++ b/include/SDL_config.h.in	Wed Aug 27 15:10:03 2008 +0000
     3.3 @@ -177,6 +177,7 @@
     3.4  #undef SDL_AUDIO_DRIVER_MMEAUDIO
     3.5  #undef SDL_AUDIO_DRIVER_NAS
     3.6  #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC
     3.7 +#undef SDL_AUDIO_DRIVER_NDS
     3.8  #undef SDL_AUDIO_DRIVER_OSS
     3.9  #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
    3.10  #undef SDL_AUDIO_DRIVER_PAUDIO
    3.11 @@ -211,6 +212,7 @@
    3.12  #undef SDL_JOYSTICK_IOKIT
    3.13  #undef SDL_JOYSTICK_LINUX
    3.14  #undef SDL_JOYSTICK_MINT
    3.15 +#undef SDL_JOYSTICK_NDS
    3.16  #undef SDL_JOYSTICK_OS2
    3.17  #undef SDL_JOYSTICK_RISCOS
    3.18  #undef SDL_JOYSTICK_WINMM
    3.19 @@ -233,6 +235,7 @@
    3.20  /* Enable various threading systems */
    3.21  #undef SDL_THREAD_BEOS
    3.22  #undef SDL_THREAD_DC
    3.23 +#undef SDL_THREAD_NDS
    3.24  #undef SDL_THREAD_OS2
    3.25  #undef SDL_THREAD_PTH
    3.26  #undef SDL_THREAD_PTHREAD
    3.27 @@ -246,6 +249,7 @@
    3.28  #undef SDL_TIMER_DC
    3.29  #undef SDL_TIMER_DUMMY
    3.30  #undef SDL_TIMER_MINT
    3.31 +#undef SDL_TIMER_NDS
    3.32  #undef SDL_TIMER_OS2
    3.33  #undef SDL_TIMER_RISCOS
    3.34  #undef SDL_TIMER_UNIX
    3.35 @@ -263,6 +267,7 @@
    3.36  #undef SDL_VIDEO_DRIVER_GEM
    3.37  #undef SDL_VIDEO_DRIVER_IPOD
    3.38  #undef SDL_VIDEO_DRIVER_NANOX
    3.39 +#undef SDL_VIDEO_DRIVER_NDS
    3.40  #undef SDL_VIDEO_DRIVER_OS2FS
    3.41  #undef SDL_VIDEO_DRIVER_PHOTON
    3.42  #undef SDL_VIDEO_DRIVER_PS2GS
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/include/SDL_config_nintendods.h	Wed Aug 27 15:10:03 2008 +0000
     4.3 @@ -0,0 +1,119 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2006 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +
    4.26 +#ifndef _SDL_config_nintendods_h
    4.27 +#define _SDL_config_nintendods_h
    4.28 +
    4.29 +#include "SDL_platform.h"
    4.30 +
    4.31 +/* This is a set of defines to configure the SDL features */
    4.32 +
    4.33 +typedef signed char int8_t;
    4.34 +typedef unsigned char uint8_t;
    4.35 +typedef signed short int16_t;
    4.36 +typedef unsigned short uint16_t;
    4.37 +typedef signed int int32_t;
    4.38 +typedef unsigned int uint32_t;
    4.39 +typedef signed long long int64_t;
    4.40 +typedef unsigned long long uint64_t;
    4.41 +
    4.42 +/* LiF: __PTRDIFF_TYPE__ was causing errors of conflicting typedefs with the
    4.43 +   <stdint.h> shipping with devkitARM.  copied a similar ifdef from it. */
    4.44 +#ifndef __PTRDIFF_TYPE__
    4.45 +typedef unsigned long uintptr_t;
    4.46 +#else
    4.47 +typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
    4.48 +#endif
    4.49 +
    4.50 +
    4.51 +#define SDL_HAS_64BIT_TYPE	1
    4.52 +
    4.53 +/* Useful headers */
    4.54 +#define HAVE_SYS_TYPES_H	1
    4.55 +#define HAVE_STDIO_H	1
    4.56 +#define STDC_HEADERS	1
    4.57 +#define HAVE_STRING_H	1
    4.58 +#define HAVE_CTYPE_H	1
    4.59 +
    4.60 +/* C library functions */
    4.61 +#define HAVE_MALLOC	1
    4.62 +#define HAVE_CALLOC	1
    4.63 +#define HAVE_REALLOC	1
    4.64 +#define HAVE_FREE	1
    4.65 +#define HAVE_ALLOCA	1
    4.66 +#define HAVE_GETENV	1
    4.67 +#define HAVE_PUTENV	1
    4.68 +#define HAVE_QSORT	1
    4.69 +#define HAVE_ABS	1
    4.70 +#define HAVE_BCOPY	1
    4.71 +#define HAVE_MEMSET	1
    4.72 +#define HAVE_MEMCPY	1
    4.73 +#define HAVE_MEMMOVE	1
    4.74 +#define HAVE_MEMCMP	1
    4.75 +#define HAVE_STRLEN	1
    4.76 +#define HAVE_STRDUP	1
    4.77 +#define HAVE_INDEX	1
    4.78 +#define HAVE_RINDEX	1
    4.79 +#define HAVE_STRCHR	1
    4.80 +#define HAVE_STRRCHR	1
    4.81 +#define HAVE_STRSTR	1
    4.82 +#define HAVE_STRTOL	1
    4.83 +#define HAVE_STRTOD	1
    4.84 +#define HAVE_ATOI	1
    4.85 +#define HAVE_ATOF	1
    4.86 +#define HAVE_STRCMP	1
    4.87 +#define HAVE_STRNCMP	1
    4.88 +#define HAVE_STRICMP	1
    4.89 +#define HAVE_STRCASECMP	1
    4.90 +#define HAVE_SSCANF	1
    4.91 +#define HAVE_SNPRINTF	1
    4.92 +#define HAVE_VSNPRINTF	1
    4.93 +
    4.94 +/* DS isn't that sophisticated */
    4.95 +#define LACKS_SYS_MMAN_H 1
    4.96 +
    4.97 +/* Enable various audio drivers */
    4.98 +#define SDL_AUDIO_DRIVER_NDS	1
    4.99 +/*#define SDL_AUDIO_DRIVER_DUMMY	1 TODO: uncomment this later*/
   4.100 +
   4.101 +/* DS doesn't have optical media */
   4.102 +#define SDL_CDROM_DISABLED	1
   4.103 +
   4.104 +/* Enable various input drivers */
   4.105 +#define SDL_JOYSTICK_NDS	1
   4.106 +/*#define SDL_JOYSTICK_DUMMY	1 TODO: uncomment this later*/
   4.107 +
   4.108 +/* DS has no dynamic linking afaik */
   4.109 +#define SDL_LOADSO_DISABLED	1
   4.110 +
   4.111 +/* Enable various threading systems */
   4.112 +/*#define SDL_THREAD_NDS	1*/
   4.113 +#define SDL_THREADS_DISABLED	1
   4.114 +
   4.115 +/* Enable various timer systems */
   4.116 +#define SDL_TIMER_NDS	1
   4.117 +
   4.118 +/* Enable various video drivers */
   4.119 +#define SDL_VIDEO_DRIVER_NDS	1
   4.120 +/*#define SDL_VIDEO_DRIVER_DUMMY	1 TODO: uncomment this later*/
   4.121 +
   4.122 +#endif /* _SDL_config_nintendods_h */
     5.1 --- a/include/SDL_pixels.h	Wed Aug 27 13:37:19 2008 +0000
     5.2 +++ b/include/SDL_pixels.h	Wed Aug 27 15:10:03 2008 +0000
     5.3 @@ -146,12 +146,18 @@
     5.4      SDL_PIXELFORMAT_RGB555 =
     5.5          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
     5.6                                 SDL_PACKEDLAYOUT_1555, 15, 2),
     5.7 +    SDL_PIXELFORMAT_BGR555 =
     5.8 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
     5.9 +                               SDL_PACKEDLAYOUT_1555, 15, 2),
    5.10      SDL_PIXELFORMAT_ARGB4444 =
    5.11          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
    5.12                                 SDL_PACKEDLAYOUT_4444, 16, 2),
    5.13      SDL_PIXELFORMAT_ARGB1555 =
    5.14          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
    5.15                                 SDL_PACKEDLAYOUT_1555, 16, 2),
    5.16 +    SDL_PIXELFORMAT_ABGR1555 =
    5.17 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
    5.18 +                               SDL_PACKEDLAYOUT_1555, 16, 2),
    5.19      SDL_PIXELFORMAT_RGB565 =
    5.20          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
    5.21                                 SDL_PACKEDLAYOUT_565, 16, 2),
     6.1 --- a/include/SDL_platform.h	Wed Aug 27 13:37:19 2008 +0000
     6.2 +++ b/include/SDL_platform.h	Wed Aug 27 15:10:03 2008 +0000
     6.3 @@ -97,4 +97,9 @@
     6.4  #define __WIN32__	1
     6.5  #endif
     6.6  
     6.7 +#if defined(__NDS__)
     6.8 +#undef __NINTENDODS__
     6.9 +#define __NINTENDODS__	1
    6.10 +#endif
    6.11 +
    6.12  #endif /* _SDL_platform_h */
     7.1 --- a/include/SDL_stdinc.h	Wed Aug 27 13:37:19 2008 +0000
     7.2 +++ b/include/SDL_stdinc.h	Wed Aug 27 15:10:03 2008 +0000
     7.3 @@ -147,8 +147,12 @@
     7.4  SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
     7.5  SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
     7.6  SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
     7.7 +#ifndef __NINTENDODS__          /* TODO: figure out why the following happens:
     7.8 +                                   include/SDL_stdinc.h:150: error: size of array 'SDL_dummy_uint64' is negative
     7.9 +                                   include/SDL_stdinc.h:151: error: size of array 'SDL_dummy_sint64' is negative */
    7.10  SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
    7.11  SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
    7.12 +#endif
    7.13  #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
    7.14  
    7.15  /* Check to make sure enums are the size of ints, for structure packing.
    7.16 @@ -162,12 +166,14 @@
    7.17  #endif
    7.18  
    7.19  #ifndef DOXYGEN_SHOULD_IGNORE_THIS
    7.20 +#ifndef __NINTENDODS__          /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
    7.21  typedef enum
    7.22  {
    7.23      DUMMY_ENUM_VALUE
    7.24  } SDL_DUMMY_ENUM;
    7.25  
    7.26  SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
    7.27 +#endif
    7.28  #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
    7.29  
    7.30  #include "begin_code.h"
    7.31 @@ -425,6 +431,9 @@
    7.32  #ifdef HAVE_WCSLEN
    7.33  #define SDL_wcslen      wcslen
    7.34  #else
    7.35 +#if !defined(wchar_t) && defined(__NINTENDODS__)
    7.36 +#define wchar_t short           /* TODO: figure out why libnds doesn't have this */
    7.37 +#endif
    7.38  extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
    7.39  #endif
    7.40  
     8.1 --- a/src/SDL_compat.c	Wed Aug 27 13:37:19 2008 +0000
     8.2 +++ b/src/SDL_compat.c	Wed Aug 27 15:10:03 2008 +0000
     8.3 @@ -693,6 +693,7 @@
     8.4          SDL_UpdateRects(screen, 1, &rect);
     8.5      }
     8.6  }
     8.7 +
     8.8  void
     8.9  SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
    8.10  {
     9.1 --- a/src/SDL_error.c	Wed Aug 27 13:37:19 2008 +0000
     9.2 +++ b/src/SDL_error.c	Wed Aug 27 15:10:03 2008 +0000
     9.3 @@ -180,8 +180,8 @@
     9.4                  case 's':
     9.5                      len =
     9.6                          SDL_snprintf(msg, maxlen, tmp,
     9.7 -                                     SDL_LookupString(error->
     9.8 -                                                      args[argi++].buf));
     9.9 +                                     SDL_LookupString(error->args[argi++].
    9.10 +                                                      buf));
    9.11                      msg += len;
    9.12                      maxlen -= len;
    9.13                      break;
    10.1 --- a/src/audio/SDL_audio.c	Wed Aug 27 13:37:19 2008 +0000
    10.2 +++ b/src/audio/SDL_audio.c	Wed Aug 27 15:10:03 2008 +0000
    10.3 @@ -70,6 +70,7 @@
    10.4  extern AudioBootStrap DCAUD_bootstrap;
    10.5  extern AudioBootStrap MMEAUDIO_bootstrap;
    10.6  extern AudioBootStrap DART_bootstrap;
    10.7 +extern AudioBootStrap NDSAUD_bootstrap;
    10.8  
    10.9  
   10.10  /* Available audio drivers */
   10.11 @@ -145,6 +146,9 @@
   10.12  #if SDL_AUDIO_DRIVER_DART
   10.13      &DART_bootstrap,
   10.14  #endif
   10.15 +#if SDL_AUDIO_DRIVER_NDS
   10.16 +    &NDSAUD_bootstrap,
   10.17 +#endif
   10.18      NULL
   10.19  };
   10.20  
   10.21 @@ -167,31 +171,38 @@
   10.22  {
   10.23      return -1;
   10.24  }
   10.25 +
   10.26  static void
   10.27  SDL_AudioThreadInit_Default(_THIS)
   10.28  {                               /* no-op. */
   10.29  }
   10.30 +
   10.31  static void
   10.32  SDL_AudioWaitDevice_Default(_THIS)
   10.33  {                               /* no-op. */
   10.34  }
   10.35 +
   10.36  static void
   10.37  SDL_AudioPlayDevice_Default(_THIS)
   10.38  {                               /* no-op. */
   10.39  }
   10.40 +
   10.41  static Uint8 *
   10.42  SDL_AudioGetDeviceBuf_Default(_THIS)
   10.43  {
   10.44      return NULL;
   10.45  }
   10.46 +
   10.47  static void
   10.48  SDL_AudioWaitDone_Default(_THIS)
   10.49  {                               /* no-op. */
   10.50  }
   10.51 +
   10.52  static void
   10.53  SDL_AudioCloseDevice_Default(_THIS)
   10.54  {                               /* no-op. */
   10.55  }
   10.56 +
   10.57  static void
   10.58  SDL_AudioDeinitialize_Default(void)
   10.59  {                               /* no-op. */
    11.1 --- a/src/audio/SDL_wave.c	Wed Aug 27 13:37:19 2008 +0000
    11.2 +++ b/src/audio/SDL_wave.c	Wed Aug 27 15:10:03 2008 +0000
    11.3 @@ -462,8 +462,7 @@
    11.4          }
    11.5          /* 2 Uint32's for chunk header+len, plus the lenread */
    11.6          headerDiff += lenread + 2 * sizeof(Uint32);
    11.7 -    }
    11.8 -    while ((chunk.magic == FACT) || (chunk.magic == LIST));
    11.9 +    } while ((chunk.magic == FACT) || (chunk.magic == LIST));
   11.10  
   11.11      /* Decode the audio data format */
   11.12      format = (WaveFMT *) chunk.data;
   11.13 @@ -564,8 +563,7 @@
   11.14          *audio_buf = chunk.data;
   11.15          if (chunk.magic != DATA)
   11.16              headerDiff += lenread + 2 * sizeof(Uint32);
   11.17 -    }
   11.18 -    while (chunk.magic != DATA);
   11.19 +    } while (chunk.magic != DATA);
   11.20      headerDiff += 2 * sizeof(Uint32);   /* for the data chunk and len */
   11.21  
   11.22      if (MS_ADPCM_encoded) {
    12.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Wed Aug 27 13:37:19 2008 +0000
    12.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Wed Aug 27 15:10:03 2008 +0000
    12.3 @@ -259,16 +259,19 @@
    12.4  {
    12.5      SWIZ6(Uint64);
    12.6  }
    12.7 +
    12.8  static __inline__ void
    12.9  swizzle_alsa_channels_6_32bit(_THIS)
   12.10  {
   12.11      SWIZ6(Uint32);
   12.12  }
   12.13 +
   12.14  static __inline__ void
   12.15  swizzle_alsa_channels_6_16bit(_THIS)
   12.16  {
   12.17      SWIZ6(Uint16);
   12.18  }
   12.19 +
   12.20  static __inline__ void
   12.21  swizzle_alsa_channels_6_8bit(_THIS)
   12.22  {
    13.1 --- a/src/audio/bsd/SDL_bsdaudio.c	Wed Aug 27 13:37:19 2008 +0000
    13.2 +++ b/src/audio/bsd/SDL_bsdaudio.c	Wed Aug 27 15:10:03 2008 +0000
    13.3 @@ -270,8 +270,7 @@
    13.4              || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
    13.5              SDL_Delay(1);       /* Let a little CPU time go by */
    13.6          }
    13.7 -    }
    13.8 -    while (p < written);
    13.9 +    } while (p < written);
   13.10  
   13.11      /* If timer synchronization is enabled, set the next write frame */
   13.12      if (this->hidden->frame_ticks) {
    14.1 --- a/src/audio/dart/SDL_dart.c	Wed Aug 27 13:37:19 2008 +0000
    14.2 +++ b/src/audio/dart/SDL_dart.c	Wed Aug 27 15:10:03 2008 +0000
    14.3 @@ -62,8 +62,8 @@
    14.4                  pBufDesc->iBufferUsage = BUFFER_EMPTY;
    14.5                  // And notify DART feeder thread that it will have to work a bit.
    14.6                  if (pSDLAudioDevice)
    14.7 -                    DosPostEventSem(pSDLAudioDevice->hidden->
    14.8 -                                    hevAudioBufferPlayed);
    14.9 +                    DosPostEventSem(pSDLAudioDevice->
   14.10 +                                    hidden->hevAudioBufferPlayed);
   14.11              }
   14.12          }
   14.13      }
   14.14 @@ -312,10 +312,11 @@
   14.15          (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
   14.16      pBufDesc->iBufferUsage = BUFFER_USED;
   14.17      // Send it to DART to be queued
   14.18 -    _this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.
   14.19 -                                           ulMixHandle,
   14.20 -                                           &(_this->hidden->
   14.21 -                                             pMixBuffers[iFreeBuf]), 1);
   14.22 +    _this->hidden->MixSetupParms.pmixWrite(_this->hidden->
   14.23 +                                           MixSetupParms.ulMixHandle,
   14.24 +                                           &(_this->
   14.25 +                                             hidden->pMixBuffers[iFreeBuf]),
   14.26 +                                           1);
   14.27  
   14.28      _this->hidden->iLastPlayedBuf = iFreeBuf;
   14.29      iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs;
   14.30 @@ -333,8 +334,8 @@
   14.31          if (_this->hidden) {
   14.32              iFreeBuf = _this->hidden->iNextFreeBuffer;
   14.33              pBufDesc =
   14.34 -                (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].
   14.35 -                ulUserParm;
   14.36 +                (pMixBufferDesc) _this->hidden->
   14.37 +                pMixBuffers[iFreeBuf].ulUserParm;
   14.38  
   14.39              if (pBufDesc) {
   14.40                  if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {
    15.1 --- a/src/audio/dma/SDL_dmaaudio.c	Wed Aug 27 13:37:19 2008 +0000
    15.2 +++ b/src/audio/dma/SDL_dmaaudio.c	Wed Aug 27 15:10:03 2008 +0000
    15.3 @@ -498,8 +498,7 @@
    15.4              this->enabled = 0;
    15.5              return (NULL);
    15.6          }
    15.7 -    }
    15.8 -    while (frame_ticks && (info.blocks < 1));
    15.9 +    } while (frame_ticks && (info.blocks < 1));
   15.10  #ifdef DEBUG_AUDIO
   15.11      if (info.blocks > 1) {
   15.12          printf("Warning: audio underflow (%d frags)\n", info.blocks - 1);
    16.1 --- a/src/audio/esd/SDL_esdaudio.c	Wed Aug 27 13:37:19 2008 +0000
    16.2 +++ b/src/audio/esd/SDL_esdaudio.c	Wed Aug 27 15:10:03 2008 +0000
    16.3 @@ -154,9 +154,8 @@
    16.4          if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
    16.5              SDL_Delay(1);       /* Let a little CPU time go by */
    16.6          }
    16.7 -    }
    16.8 -    while ((written < 0) &&
    16.9 -           ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
   16.10 +    } while ((written < 0) &&
   16.11 +             ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
   16.12  
   16.13      /* Set the next write frame */
   16.14      this->hidden->next_frame += this->hidden->frame_ticks;
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/audio/nds/SDL_ndsaudio.c	Wed Aug 27 15:10:03 2008 +0000
    17.3 @@ -0,0 +1,130 @@
    17.4 +/*
    17.5 +    SDL - Simple DirectMedia Layer
    17.6 +    Copyright (C) 1997-2006 Sam Lantinga
    17.7 +
    17.8 +    This library is free software; you can redistribute it and/or
    17.9 +    modify it under the terms of the GNU Lesser General Public
   17.10 +    License as published by the Free Software Foundation; either
   17.11 +    version 2.1 of the License, or (at your option) any later version.
   17.12 +
   17.13 +    This library is distributed in the hope that it will be useful,
   17.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17.16 +    Lesser General Public License for more details.
   17.17 +
   17.18 +    You should have received a copy of the GNU Lesser General Public
   17.19 +    License along with this library; if not, write to the Free Software
   17.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   17.21 +
   17.22 +    Sam Lantinga
   17.23 +    slouken@libsdl.org
   17.24 +
   17.25 +    This file written by Ryan C. Gordon (icculus@icculus.org)
   17.26 +*/
   17.27 +#include "SDL_config.h"
   17.28 +
   17.29 +/* Output audio to NDS */
   17.30 +
   17.31 +#include <nds.h>
   17.32 +
   17.33 +#include "SDL_audio.h"
   17.34 +#include "../SDL_audio_c.h"
   17.35 +#include "SDL_ndsaudio.h"
   17.36 +
   17.37 +static int
   17.38 +NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture)
   17.39 +{
   17.40 +    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
   17.41 +    int valid_datatype = 0;
   17.42 +
   17.43 +    this->hidden = SDL_malloc(sizeof(*(this->hidden)));
   17.44 +    if (!this->hidden) {
   17.45 +        SDL_OutOfMemory();
   17.46 +        return 0;
   17.47 +    }
   17.48 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   17.49 +
   17.50 +    while ((!valid_datatype) && (test_format)) {
   17.51 +        this->spec.format = test_format;
   17.52 +        switch (test_format) {
   17.53 +        case AUDIO_S8:
   17.54 +            /*case AUDIO_S16LSB: */
   17.55 +            valid_datatype = 1;
   17.56 +            break;
   17.57 +        default:
   17.58 +            test_format = SDL_NextAudioFormat();
   17.59 +            break;
   17.60 +        }
   17.61 +    }
   17.62 +
   17.63 +    /* set the generic sound parameters */
   17.64 +    setGenericSound(22050,      /* sample rate */
   17.65 +                    127,        /* volume */
   17.66 +                    64,         /* panning/balance */
   17.67 +                    0);         /* sound format */
   17.68 +
   17.69 +    return 1;
   17.70 +}
   17.71 +
   17.72 +static void
   17.73 +NDSAUD_PlayDevice(_THIS)
   17.74 +{
   17.75 +    TransferSoundData *sound = SDL_malloc(sizeof(TransferSoundData));
   17.76 +    if (!sound) {
   17.77 +        SDL_OutOfMemory();
   17.78 +    }
   17.79 +
   17.80 +    playGenericSound(this->hidden->mixbuf, this->hidden->mixlen);
   17.81 +#if 0
   17.82 +//    sound->data = this->hidden->mixbuf;/* pointer to raw audio data */
   17.83 +//    sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
   17.84 +//    sound->rate = 22050; /* sample rate = 22050Hz */
   17.85 +//    sound->vol = 127;    /* volume [0..127] for [min..max] */
   17.86 +//    sound->pan = 64;     /* balance [0..127] for [left..right] */
   17.87 +//    sound->format = 0;   /* 0 for 16-bit, 1 for 8-bit */
   17.88 +//    playSound(sound);
   17.89 +#endif
   17.90 +}
   17.91 +
   17.92 +
   17.93 +static Uint8 *
   17.94 +NDSAUD_GetDeviceBuf(_THIS)
   17.95 +{
   17.96 +    return this->hidden->mixbuf;        /* is this right? */
   17.97 +}
   17.98 +
   17.99 +static void
  17.100 +NDSAUD_WaitDevice(_THIS)
  17.101 +{
  17.102 +    /* stub */
  17.103 +}
  17.104 +
  17.105 +static void
  17.106 +NDSAUD_CloseDevice(_THIS)
  17.107 +{
  17.108 +    /* stub */
  17.109 +}
  17.110 +
  17.111 +static int
  17.112 +NDSAUD_Init(SDL_AudioDriverImpl * impl)
  17.113 +{
  17.114 +    /* Set the function pointers */
  17.115 +    impl->OpenDevice = NDSAUD_OpenDevice;
  17.116 +    impl->PlayDevice = NDSAUD_PlayDevice;
  17.117 +    impl->WaitDevice = NDSAUD_WaitDevice;
  17.118 +    impl->GetDeviceBuf = NDSAUD_GetDeviceBuf;
  17.119 +    impl->CloseDevice = NDSAUD_CloseDevice;
  17.120 +
  17.121 +    /* and the capabilities */
  17.122 +    impl->HasCaptureSupport = 1;
  17.123 +    impl->OnlyHasDefaultOutputDevice = 1;
  17.124 +    impl->OnlyHasDefaultInputDevice = 1;
  17.125 +
  17.126 +    return 1;
  17.127 +}
  17.128 +
  17.129 +AudioBootStrap NDSAUD_bootstrap = {
  17.130 +    "nds", "SDL NDS audio driver", NDSAUD_Init, 0       /*1? */
  17.131 +};
  17.132 +
  17.133 +/* vi: set ts=4 sw=4 expandtab: */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/audio/nds/SDL_ndsaudio.h	Wed Aug 27 15:10:03 2008 +0000
    18.3 @@ -0,0 +1,44 @@
    18.4 +/*
    18.5 +    SDL - Simple DirectMedia Layer
    18.6 +    Copyright (C) 1997-2006 Sam Lantinga
    18.7 +
    18.8 +    This library is free software; you can redistribute it and/or
    18.9 +    modify it under the terms of the GNU Lesser General Public
   18.10 +    License as published by the Free Software Foundation; either
   18.11 +    version 2.1 of the License, or (at your option) any later version.
   18.12 +
   18.13 +    This library is distributed in the hope that it will be useful,
   18.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18.16 +    Lesser General Public License for more details.
   18.17 +
   18.18 +    You should have received a copy of the GNU Lesser General Public
   18.19 +    License along with this library; if not, write to the Free Software
   18.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   18.21 +
   18.22 +    Sam Lantinga
   18.23 +    slouken@libsdl.org
   18.24 +*/
   18.25 +#include "SDL_config.h"
   18.26 +
   18.27 +#ifndef _SDL_ndsaudio_h
   18.28 +#define _SDL_ndsaudio_h
   18.29 +
   18.30 +#include "../SDL_sysaudio.h"
   18.31 +#include <nds/arm9/sound.h>
   18.32 +
   18.33 +/* Hidden "this" pointer for the audio functions */
   18.34 +#define _THIS	SDL_AudioDevice *this
   18.35 +
   18.36 +struct SDL_PrivateAudioData
   18.37 +{
   18.38 +    TransferSoundData *sound;
   18.39 +    /* The file descriptor for the audio device */
   18.40 +    Uint8 *mixbuf;
   18.41 +    Uint32 mixlen;
   18.42 +    Uint32 write_delay;
   18.43 +    Uint32 initial_calls;
   18.44 +};
   18.45 +
   18.46 +#endif /* _SDL_ndsaudio_h */
   18.47 +/* vi: set ts=4 sw=4 expandtab: */
    19.1 --- a/src/audio/nto/SDL_nto_audio.c	Wed Aug 27 13:37:19 2008 +0000
    19.2 +++ b/src/audio/nto/SDL_nto_audio.c	Wed Aug 27 15:10:03 2008 +0000
    19.3 @@ -154,8 +154,7 @@
    19.4              }
    19.5              break;
    19.6          }
    19.7 -    }
    19.8 -    while (1);
    19.9 +    } while (1);
   19.10  }
   19.11  
   19.12  static void
   19.13 @@ -213,8 +212,7 @@
   19.14              towrite -= written;
   19.15              pcmbuffer += written * this->spec.channels;
   19.16          }
   19.17 -    }
   19.18 -    while ((towrite > 0) && (this->enabled));
   19.19 +    } while ((towrite > 0) && (this->enabled));
   19.20  
   19.21      /* If we couldn't write, assume fatal error for now */
   19.22      if (towrite != 0) {
    20.1 --- a/src/audio/paudio/SDL_paudio.c	Wed Aug 27 13:37:19 2008 +0000
    20.2 +++ b/src/audio/paudio/SDL_paudio.c	Wed Aug 27 15:10:03 2008 +0000
    20.3 @@ -208,9 +208,8 @@
    20.4          if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
    20.5              SDL_Delay(1);       /* Let a little CPU time go by */
    20.6          }
    20.7 -    }
    20.8 -    while ((written < 0) &&
    20.9 -           ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
   20.10 +    } while ((written < 0) &&
   20.11 +             ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
   20.12  
   20.13      /* If timer synchronization is enabled, set the next write frame */
   20.14      if (this->hidden->frame_ticks) {
    21.1 --- a/src/audio/ums/SDL_umsaudio.c	Wed Aug 27 13:37:19 2008 +0000
    21.2 +++ b/src/audio/ums/SDL_umsaudio.c	Wed Aug 27 15:10:03 2008 +0000
    21.3 @@ -218,8 +218,7 @@
    21.4  #endif
    21.5              return;
    21.6          }
    21.7 -    }
    21.8 -    while (samplesToWrite > 0);
    21.9 +    } while (samplesToWrite > 0);
   21.10  
   21.11      SDL_LockAudio();
   21.12      SDL_memcpy(&swpbuf, &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer));
   21.13 @@ -326,8 +325,7 @@
   21.14          if (!success) {
   21.15              test_format = SDL_NextAudioFormat();
   21.16          }
   21.17 -    }
   21.18 -    while (!success && test_format);
   21.19 +    } while (!success && test_format);
   21.20  
   21.21      if (success == 0) {
   21.22          SDL_SetError("Couldn't find any hardware audio formats");
    22.1 --- a/src/audio/windib/SDL_dibaudio.c	Wed Aug 27 13:37:19 2008 +0000
    22.2 +++ b/src/audio/windib/SDL_dibaudio.c	Wed Aug 27 15:10:03 2008 +0000
    22.3 @@ -107,8 +107,8 @@
    22.4  Uint8 *
    22.5  WINWAVEOUT_GetDeviceBuf(_THIS)
    22.6  {
    22.7 -    return (Uint8 *) (this->hidden->wavebuf[this->hidden->next_buffer].
    22.8 -                      lpData);
    22.9 +    return (Uint8 *) (this->hidden->
   22.10 +                      wavebuf[this->hidden->next_buffer].lpData);
   22.11  }
   22.12  
   22.13  void
   22.14 @@ -136,8 +136,7 @@
   22.15          if (left > 0) {
   22.16              SDL_Delay(100);
   22.17          }
   22.18 -    }
   22.19 -    while (left > 0);
   22.20 +    } while (left > 0);
   22.21  }
   22.22  
   22.23  void
    23.1 --- a/src/audio/windx5/SDL_dx5audio.c	Wed Aug 27 13:37:19 2008 +0000
    23.2 +++ b/src/audio/windx5/SDL_dx5audio.c	Wed Aug 27 15:10:03 2008 +0000
    23.3 @@ -278,8 +278,9 @@
    23.4          IDirectSoundBuffer_Restore(this->hidden->mixbuf);
    23.5          result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
    23.6                                           this->hidden->mixlen,
    23.7 -                                         (LPVOID *) & this->hidden->
    23.8 -                                         locked_buf, &rawlen, NULL, &junk, 0);
    23.9 +                                         (LPVOID *) & this->
   23.10 +                                         hidden->locked_buf, &rawlen, NULL,
   23.11 +                                         &junk, 0);
   23.12      }
   23.13      if (result != DS_OK) {
   23.14          SetDSerror("DirectSound Lock", result);
    24.1 --- a/src/cdrom/SDL_cdrom.c	Wed Aug 27 13:37:19 2008 +0000
    24.2 +++ b/src/cdrom/SDL_cdrom.c	Wed Aug 27 15:10:03 2008 +0000
    24.3 @@ -44,6 +44,7 @@
    24.4      NULL,                       /* Eject */
    24.5      NULL,                       /* Close */
    24.6  };
    24.7 +
    24.8  int SDL_numcds;
    24.9  
   24.10  int
    25.1 --- a/src/cdrom/aix/SDL_syscdrom.c	Wed Aug 27 13:37:19 2008 +0000
    25.2 +++ b/src/cdrom/aix/SDL_syscdrom.c	Wed Aug 27 15:10:03 2008 +0000
    25.3 @@ -181,8 +181,7 @@
    25.4  #endif
    25.5              return;
    25.6          }
    25.7 -    }
    25.8 -    while (ret == 0);
    25.9 +    } while (ret == 0);
   25.10  
   25.11  #ifdef DEBUG_CDROM
   25.12      fprintf(stderr, "Read %d vmount structures\n", ret);
   25.13 @@ -211,8 +210,7 @@
   25.14          }
   25.15          ptr = (struct vmount *) ((char *) ptr + ptr->vmt_length);
   25.16          ret--;
   25.17 -    }
   25.18 -    while (ret > 0);
   25.19 +    } while (ret > 0);
   25.20  
   25.21      free(buffer);
   25.22  }
   25.23 @@ -247,8 +245,7 @@
   25.24                  }
   25.25              }
   25.26          }
   25.27 -    }
   25.28 -    while (ret == 0);
   25.29 +    } while (ret == 0);
   25.30      ret = endfsent_r(&fsFile);
   25.31      if (ret != 0)
   25.32          return -1;
   25.33 @@ -275,8 +272,7 @@
   25.34                  }
   25.35              }
   25.36          }
   25.37 -    }
   25.38 -    while (entry != NULL);
   25.39 +    } while (entry != NULL);
   25.40      endfsent();
   25.41  #endif
   25.42  }
   25.43 @@ -326,8 +322,7 @@
   25.44                  } else {
   25.45                      SDLcdrom = NULL;
   25.46                  }
   25.47 -            }
   25.48 -            while (SDLcdrom);
   25.49 +            } while (SDLcdrom);
   25.50              SDL_stack_free(cdpath);
   25.51          }
   25.52  
    26.1 --- a/src/cdrom/beos/SDL_syscdrom.cc	Wed Aug 27 13:37:19 2008 +0000
    26.2 +++ b/src/cdrom/beos/SDL_syscdrom.cc	Wed Aug 27 15:10:03 2008 +0000
    26.3 @@ -193,8 +193,7 @@
    26.4                  } else {
    26.5                      SDLcdrom = NULL;
    26.6                  }
    26.7 -            }
    26.8 -            while (SDLcdrom);
    26.9 +            } while (SDLcdrom);
   26.10              SDL_stack_free(cdpath);
   26.11          }
   26.12  
    27.1 --- a/src/cdrom/bsdi/SDL_syscdrom.c	Wed Aug 27 13:37:19 2008 +0000
    27.2 +++ b/src/cdrom/bsdi/SDL_syscdrom.c	Wed Aug 27 15:10:03 2008 +0000
    27.3 @@ -286,8 +286,7 @@
    27.4                  } else {
    27.5                      SDLcdrom = NULL;
    27.6                  }
    27.7 -            }
    27.8 -            while (SDLcdrom);
    27.9 +            } while (SDLcdrom);
   27.10              SDL_stack_free(cdpath);
   27.11          }
   27.12  
    28.1 --- a/src/cdrom/freebsd/SDL_syscdrom.c	Wed Aug 27 13:37:19 2008 +0000
    28.2 +++ b/src/cdrom/freebsd/SDL_syscdrom.c	Wed Aug 27 15:10:03 2008 +0000
    28.3 @@ -176,8 +176,7 @@
    28.4                  } else {
    28.5                      SDLcdrom = NULL;
    28.6                  }
    28.7 -            }
    28.8 -            while (SDLcdrom);
    28.9 +            } while (SDLcdrom);
   28.10              SDL_stack_free(cdpath);
   28.11          }
   28.12  
    29.1 --- a/src/cdrom/linux/SDL_syscdrom.c	Wed Aug 27 13:37:19 2008 +0000
    29.2 +++ b/src/cdrom/linux/SDL_syscdrom.c	Wed Aug 27 15:10:03 2008 +0000
    29.3 @@ -312,8 +312,7 @@
    29.4                  } else {
    29.5                      SDLcdrom = NULL;
    29.6                  }
    29.7 -            }
    29.8 -            while (SDLcdrom);
    29.9 +            } while (SDLcdrom);
   29.10              SDL_stack_free(cdpath);
   29.11          }
   29.12  
    30.1 --- a/src/cdrom/macosx/AudioFilePlayer.c	Wed Aug 27 13:37:19 2008 +0000
    30.2 +++ b/src/cdrom/macosx/AudioFilePlayer.c	Wed Aug 27 15:10:03 2008 +0000
    30.3 @@ -311,8 +311,7 @@
    30.4  
    30.5          /* Skip the chunk data */
    30.6          offset = chunk.ckSize;
    30.7 -    }
    30.8 -    while (chunk.ckID != 'SSND');
    30.9 +    } while (chunk.ckID != 'SSND');
   30.10  
   30.11      /* Read the header of the SSND chunk. After this, we are positioned right
   30.12         at the start of the audio data. */
    31.1 --- a/src/cdrom/macosx/AudioFileReaderThread.c	Wed Aug 27 13:37:19 2008 +0000
    31.2 +++ b/src/cdrom/macosx/AudioFileReaderThread.c	Wed Aug 27 15:10:03 2008 +0000
    31.3 @@ -335,9 +335,8 @@
    31.4          }
    31.5          /* construct pointer */
    31.6          char *writePtr = (char *) (theItem->GetFileBuffer(theItem) +
    31.7 -                                   (theItem->
    31.8 -                                    mWriteToFirstBuffer ? 0 : theItem->
    31.9 -                                    mChunkSize));
   31.10 +                                   (theItem->mWriteToFirstBuffer ? 0 :
   31.11 +                                    theItem->mChunkSize));
   31.12  
   31.13          /* read data */
   31.14          result = theItem->Read(theItem, writePtr, &dataChunkSize);
   31.15 @@ -486,8 +485,7 @@
   31.16      } else {
   31.17          *inOutDataSize = afm->mChunkSize;
   31.18          *inOutData =
   31.19 -            afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->
   31.20 -                                                            mFileBuffer +
   31.21 +            afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer +
   31.22                                                              afm->mChunkSize);
   31.23      }
   31.24  
    32.1 --- a/src/cdrom/macosx/CDPlayer.c	Wed Aug 27 13:37:19 2008 +0000
    32.2 +++ b/src/cdrom/macosx/CDPlayer.c	Wed Aug 27 15:10:03 2008 +0000
    32.3 @@ -400,8 +400,7 @@
    32.4                  }
    32.5                  CFRelease(name);
    32.6              }
    32.7 -        }
    32.8 -        while (noErr == result);
    32.9 +        } while (noErr == result);
   32.10          FSCloseIterator(iterator);
   32.11      }
   32.12  
    33.1 --- a/src/cdrom/openbsd/SDL_syscdrom.c	Wed Aug 27 13:37:19 2008 +0000
    33.2 +++ b/src/cdrom/openbsd/SDL_syscdrom.c	Wed Aug 27 15:10:03 2008 +0000
    33.3 @@ -184,8 +184,7 @@
    33.4                  } else {
    33.5                      SDLcdrom = NULL;
    33.6                  }
    33.7 -            }
    33.8 -            while (SDLcdrom);
    33.9 +            } while (SDLcdrom);
   33.10              SDL_stack_free(cdpath);
   33.11          }
   33.12  
    34.1 --- a/src/cdrom/osf/SDL_syscdrom.c	Wed Aug 27 13:37:19 2008 +0000
    34.2 +++ b/src/cdrom/osf/SDL_syscdrom.c	Wed Aug 27 15:10:03 2008 +0000
    34.3 @@ -199,8 +199,7 @@
    34.4                  } else {
    34.5                      SDLcdrom = NULL;
    34.6                  }
    34.7 -            }
    34.8 -            while (SDLcdrom);
    34.9 +            } while (SDLcdrom);
   34.10              SDL_stack_free(cdpath);
   34.11          }
   34.12  
    35.1 --- a/src/cdrom/qnx/SDL_syscdrom.c	Wed Aug 27 13:37:19 2008 +0000
    35.2 +++ b/src/cdrom/qnx/SDL_syscdrom.c	Wed Aug 27 15:10:03 2008 +0000
    35.3 @@ -184,8 +184,7 @@
    35.4                  } else {
    35.5                      SDLcdrom = NULL;
    35.6                  }
    35.7 -            }
    35.8 -            while (SDLcdrom);
    35.9 +            } while (SDLcdrom);
   35.10              SDL_stack_free(cdpath);
   35.11          }
   35.12  
   35.13 @@ -357,8 +356,7 @@
   35.14              devctlret = ENXIO;
   35.15              break;
   35.16          }
   35.17 -    }
   35.18 -    while ((devctlret == EAGAIN) || (devctlret == ESTALE));
   35.19 +    } while ((devctlret == EAGAIN) || (devctlret == ESTALE));
   35.20  
   35.21      if (devctlret != 0) {
   35.22          if (devctlret == ENXIO) {
    36.1 --- a/src/events/SDL_events.c	Wed Aug 27 13:37:19 2008 +0000
    36.2 +++ b/src/events/SDL_events.c	Wed Aug 27 15:10:03 2008 +0000
    36.3 @@ -73,6 +73,7 @@
    36.4          }
    36.5      }
    36.6  }
    36.7 +
    36.8  void
    36.9  SDL_Unlock_EventThread(void)
   36.10  {
    37.1 --- a/src/events/default_cursor.h	Wed Aug 27 13:37:19 2008 +0000
    37.2 +++ b/src/events/default_cursor.h	Wed Aug 27 15:10:03 2008 +0000
    37.3 @@ -51,6 +51,7 @@
    37.4      0x03, 0x00,
    37.5      0x00, 0x00
    37.6  };
    37.7 +
    37.8  static unsigned char default_cmask[] = {
    37.9      0xC0, 0x00,
   37.10      0xE0, 0x00,
   37.11 @@ -90,6 +91,7 @@
   37.12      0x03, 0x00,
   37.13      0x00, 0x00
   37.14  };
   37.15 +
   37.16  static unsigned char default_cmask[] = {
   37.17      0x40, 0x00,
   37.18      0xE0, 0x00,
    38.1 --- a/src/file/SDL_rwops.c	Wed Aug 27 13:37:19 2008 +0000
    38.2 +++ b/src/file/SDL_rwops.c	Wed Aug 27 15:10:03 2008 +0000
    38.3 @@ -28,6 +28,10 @@
    38.4  #include "SDL_endian.h"
    38.5  #include "SDL_rwops.h"
    38.6  
    38.7 +#ifdef __NDS__
    38.8 +/* include libfat headers for fatInitDefault(). */
    38.9 +#include <fat.h>
   38.10 +#endif /* __NDS__ */
   38.11  
   38.12  #ifdef __WIN32__
   38.13  
   38.14 @@ -132,6 +136,7 @@
   38.15  
   38.16      return 0;                   /* ok */
   38.17  }
   38.18 +
   38.19  static long SDLCALL
   38.20  win32_file_seek(SDL_RWops * context, long offset, int whence)
   38.21  {
   38.22 @@ -173,6 +178,7 @@
   38.23      SDL_Error(SDL_EFSEEK);
   38.24      return -1;                  /* error */
   38.25  }
   38.26 +
   38.27  static size_t SDLCALL
   38.28  win32_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
   38.29  {
   38.30 @@ -226,6 +232,7 @@
   38.31      }
   38.32      return (total_read / size);
   38.33  }
   38.34 +
   38.35  static size_t SDLCALL
   38.36  win32_file_write(SDL_RWops * context, const void *ptr, size_t size,
   38.37                   size_t num)
   38.38 @@ -265,6 +272,7 @@
   38.39      nwritten = byte_written / size;
   38.40      return nwritten;
   38.41  }
   38.42 +
   38.43  static int SDLCALL
   38.44  win32_file_close(SDL_RWops * context)
   38.45  {
   38.46 @@ -298,6 +306,7 @@
   38.47          return (-1);
   38.48      }
   38.49  }
   38.50 +
   38.51  static size_t SDLCALL
   38.52  stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
   38.53  {
   38.54 @@ -309,6 +318,7 @@
   38.55      }
   38.56      return (nread);
   38.57  }
   38.58 +
   38.59  static size_t SDLCALL
   38.60  stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
   38.61  {
   38.62 @@ -320,6 +330,7 @@
   38.63      }
   38.64      return (nwrote);
   38.65  }
   38.66 +
   38.67  static int SDLCALL
   38.68  stdio_close(SDL_RWops * context)
   38.69  {
   38.70 @@ -368,6 +379,7 @@
   38.71      context->hidden.mem.here = newpos;
   38.72      return (context->hidden.mem.here - context->hidden.mem.base);
   38.73  }
   38.74 +
   38.75  static size_t SDLCALL
   38.76  mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
   38.77  {
   38.78 @@ -390,6 +402,7 @@
   38.79  
   38.80      return (total_bytes / size);
   38.81  }
   38.82 +
   38.83  static size_t SDLCALL
   38.84  mem_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
   38.85  {
   38.86 @@ -400,12 +413,14 @@
   38.87      context->hidden.mem.here += num * size;
   38.88      return (num);
   38.89  }
   38.90 +
   38.91  static size_t SDLCALL
   38.92  mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
   38.93  {
   38.94      SDL_SetError("Can't write to read-only memory");
   38.95      return (-1);
   38.96  }
   38.97 +
   38.98  static int SDLCALL
   38.99  mem_close(SDL_RWops * context)
  38.100  {
  38.101 @@ -463,6 +478,13 @@
  38.102  {
  38.103      SDL_RWops *rwops = NULL;
  38.104  
  38.105 +#if 0
  38.106 +/*#ifdef __NDS__*/
  38.107 +    /* set it up so we can use stdio file function */
  38.108 +    fatInitDefault();
  38.109 +    printf("called fatInitDefault()");
  38.110 +#endif /* __NDS__ */
  38.111 +
  38.112      rwops = SDL_AllocRW();
  38.113      if (rwops != NULL) {
  38.114          rwops->seek = stdio_seek;
    39.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Wed Aug 27 13:37:19 2008 +0000
    39.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Wed Aug 27 15:10:03 2008 +0000
    39.3 @@ -149,8 +149,8 @@
    39.4                  (*ppPlugInInterface)->QueryInterface(ppPlugInInterface,
    39.5                                                       CFUUIDGetUUIDBytes
    39.6                                                       (kIOHIDDeviceInterfaceID),
    39.7 -                                                     (void *) &(pDevice->
    39.8 -                                                                interface));
    39.9 +                                                     (void *)
   39.10 +                                                     &(pDevice->interface));
   39.11              if (S_OK != plugInResult)
   39.12                  HIDReportErrorNum
   39.13                      ("CouldnŐt query HID class device interface from plugInInterface",
    40.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Wed Aug 27 13:37:19 2008 +0000
    40.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Wed Aug 27 15:10:03 2008 +0000
    40.3 @@ -89,6 +89,7 @@
    40.4  static struct joystick_logical_mapping mp88xx_1_logical_axismap[] = {
    40.5      {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}
    40.6  };
    40.7 +
    40.8  static struct joystick_logical_mapping mp88xx_1_logical_buttonmap[] = {
    40.9      {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8},
   40.10      {0, 9}, {0, 10}, {0, 11}
   40.11 @@ -98,6 +99,7 @@
   40.12      {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {0, 3},
   40.13      {1, 2}, {1, 3}, {0, 4}, {0, 5}, {1, 4}, {1, 5}
   40.14  };
   40.15 +
   40.16  static struct joystick_logical_mapping mp88xx_2_logical_buttonmap[] = {
   40.17      {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8},
   40.18      {0, 9}, {0, 10}, {0, 11},
   40.19 @@ -110,6 +112,7 @@
   40.20      {1, 2}, {1, 3}, {2, 0}, {2, 1}, {2, 2}, {2, 3},
   40.21      {0, 4}, {0, 5}, {1, 4}, {1, 5}, {2, 4}, {2, 5}
   40.22  };
   40.23 +
   40.24  static struct joystick_logical_mapping mp88xx_3_logical_buttonmap[] = {
   40.25      {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8},
   40.26      {0, 9}, {0, 10}, {0, 11},
   40.27 @@ -125,6 +128,7 @@
   40.28      {3, 0}, {3, 1}, {3, 2}, {3, 3}, {0, 4}, {0, 5},
   40.29      {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5}
   40.30  };
   40.31 +
   40.32  static struct joystick_logical_mapping mp88xx_4_logical_buttonmap[] = {
   40.33      {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8},
   40.34      {0, 9}, {0, 10}, {0, 11},
   40.35 @@ -147,15 +151,18 @@
   40.36  static struct joystick_logical_layout mp88xx_1_logical_layout[] = {
   40.37      {6, 0, 0, 12}
   40.38  };
   40.39 +
   40.40  static struct joystick_logical_layout mp88xx_2_logical_layout[] = {
   40.41      {6, 0, 0, 12},
   40.42      {6, 0, 0, 12}
   40.43  };
   40.44 +
   40.45  static struct joystick_logical_layout mp88xx_3_logical_layout[] = {
   40.46      {6, 0, 0, 12},
   40.47      {6, 0, 0, 12},
   40.48      {6, 0, 0, 12}
   40.49  };
   40.50 +
   40.51  static struct joystick_logical_layout mp88xx_4_logical_layout[] = {
   40.52      {6, 0, 0, 12},
   40.53      {6, 0, 0, 12},
   40.54 @@ -953,8 +960,8 @@
   40.55  #endif /* USE_LOGICAL_JOYSTICKS */
   40.56  
   40.57          SDL_PrivateJoystickHat(stick, hat,
   40.58 -                               position_map[the_hat->axis[1]][the_hat->
   40.59 -                                                              axis[0]]);
   40.60 +                               position_map[the_hat->
   40.61 +                                            axis[1]][the_hat->axis[0]]);
   40.62      }
   40.63  }
   40.64  
   40.65 @@ -1085,13 +1092,13 @@
   40.66                      code -= BTN_MISC;
   40.67  #ifndef NO_LOGICAL_JOYSTICKS
   40.68                      if (!LogicalJoystickButton(joystick,
   40.69 -                                               joystick->hwdata->
   40.70 -                                               key_map[code],
   40.71 +                                               joystick->
   40.72 +                                               hwdata->key_map[code],
   40.73                                                 events[i].value))
   40.74  #endif
   40.75                          SDL_PrivateJoystickButton(joystick,
   40.76 -                                                  joystick->hwdata->
   40.77 -                                                  key_map[code],
   40.78 +                                                  joystick->
   40.79 +                                                  hwdata->key_map[code],
   40.80                                                    events[i].value);
   40.81                  }
   40.82                  break;
   40.83 @@ -1113,12 +1120,12 @@
   40.84                          EV_AxisCorrect(joystick, code, events[i].value);
   40.85  #ifndef NO_LOGICAL_JOYSTICKS
   40.86                      if (!LogicalJoystickAxis(joystick,
   40.87 -                                             joystick->hwdata->
   40.88 -                                             abs_map[code], events[i].value))
   40.89 +                                             joystick->hwdata->abs_map[code],
   40.90 +                                             events[i].value))
   40.91  #endif
   40.92                          SDL_PrivateJoystickAxis(joystick,
   40.93 -                                                joystick->hwdata->
   40.94 -                                                abs_map[code],
   40.95 +                                                joystick->
   40.96 +                                                hwdata->abs_map[code],
   40.97                                                  events[i].value);
   40.98                      break;
   40.99                  }
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Wed Aug 27 15:10:03 2008 +0000
    41.3 @@ -0,0 +1,172 @@
    41.4 +/*
    41.5 +    SDL - Simple DirectMedia Layer
    41.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    41.7 +
    41.8 +    This library is free software; you can redistribute it and/or
    41.9 +    modify it under the terms of the GNU Library General Public
   41.10 +    License as published by the Free Software Foundation; either
   41.11 +    version 2 of the License, or (at your option) any later version.
   41.12 +
   41.13 +    This library is distributed in the hope that it will be useful,
   41.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   41.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   41.16 +    Library General Public License for more details.
   41.17 +
   41.18 +    You should have received a copy of the GNU Library General Public
   41.19 +    License along with this library; if not, write to the Free
   41.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   41.21 +
   41.22 +    Sam Lantinga
   41.23 +    slouken@devolution.com
   41.24 +*/
   41.25 +
   41.26 +#include "SDL_config.h"
   41.27 +
   41.28 +#ifdef SDL_JOYSTICK_NDS
   41.29 +
   41.30 +/* This is the system specific header for the SDL joystick API */
   41.31 +#include <nds.h>
   41.32 +#include <stdio.h>              /* For the definition of NULL */
   41.33 +
   41.34 +#include "SDL_error.h"
   41.35 +#include "SDL_events.h"
   41.36 +#include "SDL_joystick.h"
   41.37 +#include "SDL_sysjoystick.h"
   41.38 +#include "SDL_joystick_c.h"
   41.39 +
   41.40 +#include "../../video/nds/SDL_ndsevents_c.h"
   41.41 +
   41.42 +/* Function to scan the system for joysticks.
   41.43 + * This function should set SDL_numjoysticks to the number of available
   41.44 + * joysticks.  Joystick 0 should be the system default joystick.
   41.45 + * It should return 0, or -1 on an unrecoverable fatal error.
   41.46 + */
   41.47 +int
   41.48 +SDL_SYS_JoystickInit(void)
   41.49 +{
   41.50 +    SDL_numjoysticks = 1;
   41.51 +    
   41.52 return (1);
   41.53 +}
   41.54 +
   41.55 +/* Function to get the device-dependent name of a joystick */
   41.56 +const char *
   41.57 +SDL_SYS_JoystickName(int index)
   41.58 +{
   41.59 +    if (!index)
   41.60 +        return "NDS builtin joypad";
   41.61 +    SDL_SetError("No joystick available with that index");
   41.62 +    return (NULL);
   41.63 +}
   41.64 +
   41.65 +/* Function to open a joystick for use.
   41.66 +   The joystick to open is specified by the index field of the joystick.
   41.67 +   This should fill the nbuttons and naxes fields of the joystick structure.
   41.68 +   It returns 0, or -1 if there is an error.
   41.69 + */
   41.70 +int
   41.71 +SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
   41.72 +{
   41.73 +    joystick->nbuttons = 8;
   41.74 +    joystick->nhats = 0;
   41.75 +    joystick->nballs = 0;
   41.76 +    joystick->naxes = 2;
   41.77 +    return 0;
   41.78 +}
   41.79 +
   41.80 +
   41.81 +/* Function to update the state of a joystick - called as a device poll.
   41.82 + * This function shouldn't update the joystick structure directly,
   41.83 + * but instead should call SDL_PrivateJoystick*() to deliver events
   41.84 + * and update joystick device state.
   41.85 + */
   41.86 +    void
   41.87 +SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   41.88 +{
   41.89 +    u32 keysd, keysu;
   41.90 +    int magnitude = 16384;
   41.91 +    
   41.92 +        /*scanKeys(); */ 
   41.93 +        keysd = keysDown();
   41.94 +    keysu = keysUp();
   41.95 +
   41.96 +    if ((keysd & KEY_UP)) {
   41.97 +        SDL_PrivateJoystickAxis(joystick, 1, -magnitude);
   41.98 +    }
   41.99 +    if ((keysd & KEY_DOWN)) {
  41.100 +        SDL_PrivateJoystickAxis(joystick, 1, magnitude);
  41.101 +    }
  41.102 +    if ((keysd & KEY_LEFT)) {
  41.103 +        SDL_PrivateJoystickAxis(joystick, 0, -magnitude);
  41.104 +    }
  41.105 +    if ((keysd & KEY_RIGHT)) {
  41.106 +        SDL_PrivateJoystickAxis(joystick, 0, magnitude);
  41.107 +    }
  41.108 +    
  41.109 if ((keysu & (KEY_UP | KEY_DOWN))) {
  41.110 +        SDL_PrivateJoystickAxis(joystick, 1, 0);
  41.111 +    }
  41.112 +    
  41.113 if ((keysu & (KEY_LEFT | KEY_RIGHT))) {
  41.114 +        SDL_PrivateJoystickAxis(joystick, 0, 0);
  41.115 +    }
  41.116 +    
  41.117 if ((keysd & KEY_A)) {
  41.118 +        SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
  41.119 +    }
  41.120 +    
  41.121 if ((keysd & KEY_B)) {
  41.122 +        SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
  41.123 +    }
  41.124 +    
  41.125 if ((keysd & KEY_X)) {
  41.126 +        SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
  41.127 +    }
  41.128 +    
  41.129 if ((keysd & KEY_Y)) {
  41.130 +        SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
  41.131 +    }
  41.132 +    
  41.133 if ((keysd & KEY_L)) {
  41.134 +        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
  41.135 +    }
  41.136 +    
  41.137 if ((keysd & KEY_R)) {
  41.138 +        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
  41.139 +    }
  41.140 +    
  41.141 if ((keysd & KEY_SELECT)) {
  41.142 +        SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
  41.143 +    }
  41.144 +    
  41.145 if ((keysd & KEY_START)) {
  41.146 +        SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
  41.147 +    }
  41.148 +    
  41.149 if ((keysu & KEY_A)) {
  41.150 +        SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
  41.151 +    }
  41.152 +    
  41.153 if ((keysu & KEY_B)) {
  41.154 +        SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
  41.155 +    }
  41.156 +    
  41.157 if ((keysu & KEY_X)) {
  41.158 +        SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
  41.159 +    }
  41.160 +    
  41.161 if ((keysu & KEY_Y)) {
  41.162 +        SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
  41.163 +    }
  41.164 +    
  41.165 if ((keysu & KEY_L)) {
  41.166 +        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
  41.167 +    }
  41.168 +    
  41.169 if ((keysu & KEY_R)) {
  41.170 +        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
  41.171 +    }
  41.172 +    
  41.173 if ((keysu & KEY_SELECT)) {
  41.174 +        SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
  41.175 +    }
  41.176 +    
  41.177 if ((keysu & KEY_START)) {
  41.178 +        SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
  41.179 +    }
  41.180 +
  41.181 }
  41.182 +
  41.183 +/* Function to close a joystick after use */
  41.184 +void
  41.185 +SDL_SYS_JoystickClose(SDL_Joystick * joystick)
  41.186 +{
  41.187 +}
  41.188 +
  41.189 +/* Function to perform any system-specific joystick related cleanup */
  41.190 +void
  41.191 +SDL_SYS_JoystickQuit(void)
  41.192 +{
  41.193 +}
  41.194 +
  41.195 +#endif /* SDL_JOYSTICK_NDS */
    42.1 --- a/src/loadso/macosx/SDL_dlcompat.c	Wed Aug 27 13:37:19 2008 +0000
    42.2 +++ b/src/loadso/macosx/SDL_dlcompat.c	Wed Aug 27 15:10:03 2008 +0000
    42.3 @@ -616,8 +616,8 @@
    42.4                  || (LC_LOAD_WEAK_DYLIB == lc->cmd)) {
    42.5                  if ((wh = (struct mach_header *)
    42.6                       my_find_image((char
    42.7 -                                    *) (((struct dylib_command *) lc)->
    42.8 -                                        dylib.name.offset + (char *) lc)))) {
    42.9 +                                    *) (((struct dylib_command *) lc)->dylib.
   42.10 +                                        name.offset + (char *) lc)))) {
   42.11                      if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol)) {
   42.12                          nssym = dyld_NSLookupSymbolInImage(wh,
   42.13                                                             symbol,
   42.14 @@ -1067,6 +1067,7 @@
   42.15      return answer;
   42.16  
   42.17  }
   42.18 +
   42.19  static void *
   42.20  dlsym_auto_underscore_intern(void *handle, const char *symbol)
   42.21  {
    43.1 --- a/src/main/beos/SDL_BeApp.cc	Wed Aug 27 13:37:19 2008 +0000
    43.2 +++ b/src/main/beos/SDL_BeApp.cc	Wed Aug 27 15:10:03 2008 +0000
    43.3 @@ -78,8 +78,7 @@
    43.4  
    43.5          do {
    43.6              SDL_Delay(10);
    43.7 -        }
    43.8 -        while ((be_app == NULL) || be_app->IsLaunching());
    43.9 +        } while ((be_app == NULL) || be_app->IsLaunching());
   43.10  
   43.11          /* Mark the application active */
   43.12          SDL_BeAppActive = 0;
    44.1 --- a/src/stdlib/SDL_stdlib.c	Wed Aug 27 13:37:19 2008 +0000
    44.2 +++ b/src/stdlib/SDL_stdlib.c	Wed Aug 27 15:10:03 2008 +0000
    44.3 @@ -135,6 +135,7 @@
    44.4      }
    44.5      /* *INDENT-ON* */
    44.6  }
    44.7 +
    44.8  void
    44.9  __declspec(naked)
   44.10  _alldiv()
   44.11 @@ -222,6 +223,7 @@
   44.12      }
   44.13      /* *INDENT-ON* */
   44.14  }
   44.15 +
   44.16  void
   44.17  __declspec(naked)
   44.18  _aulldiv()
   44.19 @@ -279,6 +281,7 @@
   44.20      }
   44.21      /* *INDENT-ON* */
   44.22  }
   44.23 +
   44.24  void
   44.25  __declspec(naked)
   44.26  _allrem()
   44.27 @@ -365,6 +368,7 @@
   44.28      }
   44.29      /* *INDENT-ON* */
   44.30  }
   44.31 +
   44.32  void
   44.33  __declspec(naked)
   44.34  _aullrem()
   44.35 @@ -423,6 +427,7 @@
   44.36      }
   44.37      /* *INDENT-ON* */
   44.38  }
   44.39 +
   44.40  void
   44.41  __declspec(naked)
   44.42  _alldvrm()
   44.43 @@ -532,6 +537,7 @@
   44.44      }
   44.45      /* *INDENT-ON* */
   44.46  }
   44.47 +
   44.48  void
   44.49  __declspec(naked)
   44.50  _aulldvrm()
   44.51 @@ -604,6 +610,7 @@
   44.52      }
   44.53      /* *INDENT-ON* */
   44.54  }
   44.55 +
   44.56  void
   44.57  __declspec(naked)
   44.58  _allshl()
   44.59 @@ -630,6 +637,7 @@
   44.60      }
   44.61      /* *INDENT-ON* */
   44.62  }
   44.63 +
   44.64  void
   44.65  __declspec(naked)
   44.66  _aullshr()
    45.1 --- a/src/thread/SDL_thread_c.h	Wed Aug 27 13:37:19 2008 +0000
    45.2 +++ b/src/thread/SDL_thread_c.h	Wed Aug 27 15:10:03 2008 +0000
    45.3 @@ -43,6 +43,8 @@
    45.4  #include "irix/SDL_systhread_c.h"
    45.5  #elif SDL_THREAD_WIN32
    45.6  #include "win32/SDL_systhread_c.h"
    45.7 +#elif SDL_THREAD_NDS
    45.8 +#include "nds/SDL_systhread_c.h"
    45.9  #else
   45.10  #error Need thread implementation for this platform
   45.11  #include "generic/SDL_systhread_c.h"
    46.1 --- a/src/thread/irix/SDL_syssem.c	Wed Aug 27 13:37:19 2008 +0000
    46.2 +++ b/src/thread/irix/SDL_syssem.c	Wed Aug 27 15:10:03 2008 +0000
    46.3 @@ -55,9 +55,11 @@
    46.4  static struct sembuf op_trywait[2] = {
    46.5      {0, -1, (IPC_NOWAIT | SEM_UNDO)}    /* Decrement semaphore, no block */
    46.6  };
    46.7 +
    46.8  static struct sembuf op_wait[2] = {
    46.9      {0, -1, SEM_UNDO}           /* Decrement semaphore */
   46.10  };
   46.11 +
   46.12  static struct sembuf op_post[1] = {
   46.13      {0, 1, (IPC_NOWAIT | SEM_UNDO)}     /* Increment semaphore */
   46.14  };
   46.15 @@ -170,8 +172,7 @@
   46.16              break;
   46.17          }
   46.18          SDL_Delay(1);
   46.19 -    }
   46.20 -    while (SDL_GetTicks() < timeout);
   46.21 +    } while (SDL_GetTicks() < timeout);
   46.22  
   46.23      return retval;
   46.24  }
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/src/thread/nds/SDL_syscond.c	Wed Aug 27 15:10:03 2008 +0000
    47.3 @@ -0,0 +1,229 @@
    47.4 +/*
    47.5 +    SDL - Simple DirectMedia Layer
    47.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    47.7 +
    47.8 +    This library is free software; you can redistribute it and/or
    47.9 +    modify it under the terms of the GNU Library General Public
   47.10 +    License as published by the Free Software Foundation; either
   47.11 +    version 2 of the License, or (at your option) any later version.
   47.12 +
   47.13 +    This library is distributed in the hope that it will be useful,
   47.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   47.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   47.16 +    Library General Public License for more details.
   47.17 +
   47.18 +    You should have received a copy of the GNU Library General Public
   47.19 +    License along with this library; if not, write to the Free
   47.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   47.21 +
   47.22 +    Sam Lantinga
   47.23 +    slouken@devolution.com
   47.24 +*/
   47.25 +
   47.26 +#ifdef SAVE_RCSID
   47.27 +static char rcsid =
   47.28 +    "@(#) $Id: SDL_syscond.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   47.29 +#endif
   47.30 +
   47.31 +/* An implementation of condition variables using semaphores and mutexes */
   47.32 +/*
   47.33 +   This implementation borrows heavily from the BeOS condition variable
   47.34 +   implementation, written by Christopher Tate and Owen Smith.  Thanks!
   47.35 + */
   47.36 +
   47.37 +#include <stdio.h>
   47.38 +#include <stdlib.h>
   47.39 +
   47.40 +#include "SDL_error.h"
   47.41 +#include "SDL_thread.h"
   47.42 +
   47.43 +struct SDL_cond
   47.44 +{
   47.45 +    SDL_mutex *lock;
   47.46 +    int waiting;
   47.47 +    int signals;
   47.48 +    SDL_sem *wait_sem;
   47.49 +    SDL_sem *wait_done;
   47.50 +};
   47.51 +
   47.52 +/* Create a condition variable */
   47.53 +SDL_cond *
   47.54 +SDL_CreateCond(void)
   47.55 +{
   47.56 +    SDL_cond *cond;
   47.57 +
   47.58 +    cond = (SDL_cond *) malloc(sizeof(SDL_cond));
   47.59 +    if (cond) {
   47.60 +        cond->lock = SDL_CreateMutex();
   47.61 +        cond->wait_sem = SDL_CreateSemaphore(0);
   47.62 +        cond->wait_done = SDL_CreateSemaphore(0);
   47.63 +        cond->waiting = cond->signals = 0;
   47.64 +        if (!cond->lock || !cond->wait_sem || !cond->wait_done) {
   47.65 +            SDL_DestroyCond(cond);
   47.66 +            cond = NULL;
   47.67 +        }
   47.68 +    } else {
   47.69 +        SDL_OutOfMemory();
   47.70 +    }
   47.71 +    return (cond);
   47.72 +}
   47.73 +
   47.74 +/* Destroy a condition variable */
   47.75 +void
   47.76 +SDL_DestroyCond(SDL_cond * cond)
   47.77 +{
   47.78 +    if (cond) {
   47.79 +        if (cond->wait_sem) {
   47.80 +            SDL_DestroySemaphore(cond->wait_sem);
   47.81 +        }
   47.82 +        if (cond->wait_done) {
   47.83 +            SDL_DestroySemaphore(cond->wait_done);
   47.84 +        }
   47.85 +        if (cond->lock) {
   47.86 +            SDL_DestroyMutex(cond->lock);
   47.87 +        }
   47.88 +        free(cond);
   47.89 +    }
   47.90 +}
   47.91 +
   47.92 +/* Restart one of the threads that are waiting on the condition variable */
   47.93 +int
   47.94 +SDL_CondSignal(SDL_cond * cond)
   47.95 +{
   47.96 +    if (!cond) {
   47.97 +        SDL_SetError("Passed a NULL condition variable");
   47.98 +        return -1;
   47.99 +    }
  47.100 +
  47.101 +    /* If there are waiting threads not already signalled, then
  47.102 +       signal the condition and wait for the thread to respond.
  47.103 +     */
  47.104 +    SDL_LockMutex(cond->lock);
  47.105 +    if (cond->waiting > cond->signals) {
  47.106 +        ++cond->signals;
  47.107 +        SDL_SemPost(cond->wait_sem);
  47.108 +        SDL_UnlockMutex(cond->lock);
  47.109 +        SDL_SemWait(cond->wait_done);
  47.110 +    } else {
  47.111 +        SDL_UnlockMutex(cond->lock);
  47.112 +    }
  47.113 +
  47.114 +    return 0;
  47.115 +}
  47.116 +
  47.117 +/* Restart all threads that are waiting on the condition variable */
  47.118 +int
  47.119 +SDL_CondBroadcast(SDL_cond * cond)
  47.120 +{
  47.121 +    if (!cond) {
  47.122 +        SDL_SetError("Passed a NULL condition variable");
  47.123 +        return -1;
  47.124 +    }
  47.125 +
  47.126 +    /* If there are waiting threads not already signalled, then
  47.127 +       signal the condition and wait for the thread to respond.
  47.128 +     */
  47.129 +    SDL_LockMutex(cond->lock);
  47.130 +    if (cond->waiting > cond->signals) {
  47.131 +        int i, num_waiting;
  47.132 +
  47.133 +        num_waiting = (cond->waiting - cond->signals);
  47.134 +        cond->signals = cond->waiting;
  47.135 +        for (i = 0; i < num_waiting; ++i) {
  47.136 +            SDL_SemPost(cond->wait_sem);
  47.137 +        }
  47.138 +        /* Now all released threads are blocked here, waiting for us.
  47.139 +           Collect them all (and win fabulous prizes!) :-)
  47.140 +         */
  47.141 +        SDL_UnlockMutex(cond->lock);
  47.142 +        for (i = 0; i < num_waiting; ++i) {
  47.143 +            SDL_SemWait(cond->wait_done);
  47.144 +        }
  47.145 +    } else {
  47.146 +        SDL_UnlockMutex(cond->lock);
  47.147 +    }
  47.148 +
  47.149 +    return 0;
  47.150 +}
  47.151 +
  47.152 +/* Wait on the condition variable for at most 'ms' milliseconds.
  47.153 +   The mutex must be locked before entering this function!
  47.154 +   The mutex is unlocked during the wait, and locked again after the wait.
  47.155 +
  47.156 +Typical use:
  47.157 +
  47.158 +Thread A:
  47.159 +	SDL_LockMutex(lock);
  47.160 +	while ( ! condition ) {
  47.161 +		SDL_CondWait(cond);
  47.162 +	}
  47.163 +	SDL_UnlockMutex(lock);
  47.164 +
  47.165 +Thread B:
  47.166 +	SDL_LockMutex(lock);
  47.167 +	...
  47.168 +	condition = true;
  47.169 +	...
  47.170 +	SDL_UnlockMutex(lock);
  47.171 + */
  47.172 +int
  47.173 +SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
  47.174 +{
  47.175 +    int retval;
  47.176 +
  47.177 +    if (!cond) {
  47.178 +        SDL_SetError("Passed a NULL condition variable");
  47.179 +        return -1;
  47.180 +    }
  47.181 +
  47.182 +    /* Obtain the protection mutex, and increment the number of waiters.
  47.183 +       This allows the signal mechanism to only perform a signal if there
  47.184 +       are waiting threads.
  47.185 +     */
  47.186 +    SDL_LockMutex(cond->lock);
  47.187 +    ++cond->waiting;
  47.188 +    SDL_UnlockMutex(cond->lock);
  47.189 +
  47.190 +    /* Unlock the mutex, as is required by condition variable semantics */
  47.191 +    SDL_UnlockMutex(mutex);
  47.192 +
  47.193 +    /* Wait for a signal */
  47.194 +    if (ms == SDL_MUTEX_MAXWAIT) {
  47.195 +        retval = SDL_SemWait(cond->wait_sem);
  47.196 +    } else {
  47.197 +        retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
  47.198 +    }
  47.199 +
  47.200 +    /* Let the signaler know we have completed the wait, otherwise
  47.201 +       the signaler can race ahead and get the condition semaphore
  47.202 +       if we are stopped between the mutex unlock and semaphore wait,
  47.203 +       giving a deadlock.  See the following URL for details:
  47.204 +       http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
  47.205 +     */
  47.206 +    SDL_LockMutex(cond->lock);
  47.207 +    if (cond->signals > 0) {
  47.208 +        /* If we timed out, we need to eat a condition signal */
  47.209 +        if (retval > 0) {
  47.210 +            SDL_SemWait(cond->wait_sem);
  47.211 +        }
  47.212 +        /* We always notify the signal thread that we are done */
  47.213 +        SDL_SemPost(cond->wait_done);
  47.214 +
  47.215 +        /* Signal handshake complete */
  47.216 +        --cond->signals;
  47.217 +    }
  47.218 +    --cond->waiting;
  47.219 +    SDL_UnlockMutex(cond->lock);
  47.220 +
  47.221 +    /* Lock the mutex, as is required by condition variable semantics */
  47.222 +    SDL_LockMutex(mutex);
  47.223 +
  47.224 +    return retval;
  47.225 +}
  47.226 +
  47.227 +/* Wait on the condition variable forever */
  47.228 +int
  47.229 +SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
  47.230 +{
  47.231 +    return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
  47.232 +}
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/src/thread/nds/SDL_syscond_c.h	Wed Aug 27 15:10:03 2008 +0000
    48.3 @@ -0,0 +1,26 @@
    48.4 +/*
    48.5 +    SDL - Simple DirectMedia Layer
    48.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    48.7 +
    48.8 +    This library is free software; you can redistribute it and/or
    48.9 +    modify it under the terms of the GNU Library General Public
   48.10 +    License as published by the Free Software Foundation; either
   48.11 +    version 2 of the License, or (at your option) any later version.
   48.12 +
   48.13 +    This library is distributed in the hope that it will be useful,
   48.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   48.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   48.16 +    Library General Public License for more details.
   48.17 +
   48.18 +    You should have received a copy of the GNU Library General Public
   48.19 +    License along with this library; if not, write to the Free
   48.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   48.21 +
   48.22 +    Sam Lantinga
   48.23 +    slouken@devolution.com
   48.24 +*/
   48.25 +
   48.26 +#ifdef SAVE_RCSID
   48.27 +static char rcsid =
   48.28 +    "@(#) $Id: SDL_syscond_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   48.29 +#endif
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/src/thread/nds/SDL_sysmutex.c	Wed Aug 27 15:10:03 2008 +0000
    49.3 @@ -0,0 +1,142 @@
    49.4 +/*
    49.5 +    SDL - Simple DirectMedia Layer
    49.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    49.7 +
    49.8 +    This library is free software; you can redistribute it and/or
    49.9 +    modify it under the terms of the GNU Library General Public
   49.10 +    License as published by the Free Software Foundation; either
   49.11 +    version 2 of the License, or (at your option) any later version.
   49.12 +
   49.13 +    This library is distributed in the hope that it will be useful,
   49.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   49.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   49.16 +    Library General Public License for more details.
   49.17 +
   49.18 +    You should have received a copy of the GNU Library General Public
   49.19 +    License along with this library; if not, write to the Free
   49.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   49.21 +
   49.22 +    Sam Lantinga
   49.23 +    slouken@devolution.com
   49.24 +*/
   49.25 +
   49.26 +#ifdef SAVE_RCSID
   49.27 +static char rcsid =
   49.28 +    "@(#) $Id: SDL_sysmutex.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   49.29 +#endif
   49.30 +
   49.31 +/* An implementation of mutexes using semaphores */
   49.32 +
   49.33 +#include <stdio.h>
   49.34 +#include <stdlib.h>
   49.35 +
   49.36 +#include "SDL_error.h"
   49.37 +#include "SDL_thread.h"
   49.38 +#include "SDL_systhread_c.h"
   49.39 +
   49.40 +
   49.41 +struct SDL_mutex
   49.42 +{
   49.43 +    int recursive;
   49.44 +    Uint32 owner;
   49.45 +    SDL_sem *sem;
   49.46 +};
   49.47 +
   49.48 +/* Create a mutex */
   49.49 +SDL_mutex *
   49.50 +SDL_CreateMutex(void)
   49.51 +{
   49.52 +    SDL_mutex *mutex;
   49.53 +
   49.54 +    /* Allocate mutex memory */
   49.55 +    mutex = (SDL_mutex *) malloc(sizeof(*mutex));
   49.56 +    if (mutex) {
   49.57 +        /* Create the mutex semaphore, with initial value 1 */
   49.58 +        mutex->sem = SDL_CreateSemaphore(1);
   49.59 +        mutex->recursive = 0;
   49.60 +        mutex->owner = 0;
   49.61 +        if (!mutex->sem) {
   49.62 +            free(mutex);
   49.63 +            mutex = NULL;
   49.64 +        }
   49.65 +    } else {
   49.66 +        SDL_OutOfMemory();
   49.67 +    }
   49.68 +    return mutex;
   49.69 +}
   49.70 +
   49.71 +/* Free the mutex */
   49.72 +void
   49.73 +SDL_DestroyMutex(SDL_mutex * mutex)
   49.74 +{
   49.75 +    if (mutex) {
   49.76 +        if (mutex->sem) {
   49.77 +            SDL_DestroySemaphore(mutex->sem);
   49.78 +        }
   49.79 +        free(mutex);
   49.80 +    }
   49.81 +}
   49.82 +
   49.83 +/* Lock the semaphore */
   49.84 +int
   49.85 +SDL_mutexP(SDL_mutex * mutex)
   49.86 +{
   49.87 +#ifdef DISABLE_THREADS
   49.88 +    return 0;
   49.89 +#else
   49.90 +    Uint32 this_thread;
   49.91 +
   49.92 +    if (mutex == NULL) {
   49.93 +        SDL_SetError("Passed a NULL mutex");
   49.94 +        return -1;
   49.95 +    }
   49.96 +
   49.97 +    this_thread = SDL_ThreadID();
   49.98 +    if (mutex->owner == this_thread) {
   49.99 +        ++mutex->recursive;
  49.100 +    } else {
  49.101 +        /* The order of operations is important.
  49.102 +           We set the locking thread id after we obtain the lock
  49.103 +           so unlocks from other threads will fail.
  49.104 +         */
  49.105 +        SDL_SemWait(mutex->sem);
  49.106 +        mutex->owner = this_thread;
  49.107 +        mutex->recursive = 0;
  49.108 +    }
  49.109 +
  49.110 +    return 0;
  49.111 +#endif /* DISABLE_THREADS */
  49.112 +}
  49.113 +
  49.114 +/* Unlock the mutex */
  49.115 +int
  49.116 +SDL_mutexV(SDL_mutex * mutex)
  49.117 +{
  49.118 +#ifdef DISABLE_THREADS
  49.119 +    return 0;
  49.120 +#else
  49.121 +    if (mutex == NULL) {
  49.122 +        SDL_SetError("Passed a NULL mutex");
  49.123 +        return -1;
  49.124 +    }
  49.125 +
  49.126 +    /* If we don't own the mutex, we can't unlock it */
  49.127 +    if (SDL_ThreadID() != mutex->owner) {
  49.128 +        SDL_SetError("mutex not owned by this thread");
  49.129 +        return -1;
  49.130 +    }
  49.131 +
  49.132 +    if (mutex->recursive) {
  49.133 +        --mutex->recursive;
  49.134 +    } else {
  49.135 +        /* The order of operations is important.
  49.136 +           First reset the owner so another thread doesn't lock
  49.137 +           the mutex and set the ownership before we reset it,
  49.138 +           then release the lock semaphore.
  49.139 +         */
  49.140 +        mutex->owner = 0;
  49.141 +        SDL_SemPost(mutex->sem);
  49.142 +    }
  49.143 +    return 0;
  49.144 +#endif /* DISABLE_THREADS */
  49.145 +}
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/src/thread/nds/SDL_sysmutex_c.h	Wed Aug 27 15:10:03 2008 +0000
    50.3 @@ -0,0 +1,26 @@
    50.4 +/*
    50.5 +    SDL - Simple DirectMedia Layer
    50.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    50.7 +
    50.8 +    This library is free software; you can redistribute it and/or
    50.9 +    modify it under the terms of the GNU Library General Public
   50.10 +    License as published by the Free Software Foundation; either
   50.11 +    version 2 of the License, or (at your option) any later version.
   50.12 +
   50.13 +    This library is distributed in the hope that it will be useful,
   50.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   50.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   50.16 +    Library General Public License for more details.
   50.17 +
   50.18 +    You should have received a copy of the GNU Library General Public
   50.19 +    License along with this library; if not, write to the Free
   50.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   50.21 +
   50.22 +    Sam Lantinga
   50.23 +    slouken@devolution.com
   50.24 +*/
   50.25 +
   50.26 +#ifdef SAVE_RCSID
   50.27 +static char rcsid =
   50.28 +    "@(#) $Id: SDL_sysmutex_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   50.29 +#endif
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/src/thread/nds/SDL_syssem.c	Wed Aug 27 15:10:03 2008 +0000
    51.3 @@ -0,0 +1,228 @@
    51.4 +/*
    51.5 +    SDL - Simple DirectMedia Layer
    51.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    51.7 +
    51.8 +    This library is free software; you can redistribute it and/or
    51.9 +    modify it under the terms of the GNU Library General Public
   51.10 +    License as published by the Free Software Foundation; either
   51.11 +    version 2 of the License, or (at your option) any later version.
   51.12 +
   51.13 +    This library is distributed in the hope that it will be useful,
   51.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   51.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   51.16 +    Library General Public License for more details.
   51.17 +
   51.18 +    You should have received a copy of the GNU Library General Public
   51.19 +    License along with this library; if not, write to the Free
   51.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   51.21 +
   51.22 +    Sam Lantinga
   51.23 +    slouken@devolution.com
   51.24 +*/
   51.25 +
   51.26 +#ifdef SAVE_RCSID
   51.27 +static char rcsid =
   51.28 +    "@(#) $Id: SDL_syssem.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   51.29 +#endif
   51.30 +
   51.31 +/* An implementation of semaphores using mutexes and condition variables */
   51.32 +
   51.33 +#include <stdlib.h>
   51.34 +
   51.35 +#include "SDL_error.h"
   51.36 +#include "SDL_timer.h"
   51.37 +#include "SDL_thread.h"
   51.38 +#include "SDL_systhread_c.h"
   51.39 +
   51.40 +
   51.41 +#ifdef DISABLE_THREADS
   51.42 +
   51.43 +SDL_sem *
   51.44 +SDL_CreateSemaphore(Uint32 initial_value)
   51.45 +{
   51.46 +    SDL_SetError("SDL not configured with thread support");
   51.47 +    return (SDL_sem *) 0;
   51.48 +}
   51.49 +
   51.50 +void
   51.51 +SDL_DestroySemaphore(SDL_sem * sem)
   51.52 +{
   51.53 +    return;
   51.54 +}
   51.55 +
   51.56 +int
   51.57 +SDL_SemTryWait(SDL_sem * sem)
   51.58 +{
   51.59 +    SDL_SetError("SDL not configured with thread support");
   51.60 +    return -1;
   51.61 +}
   51.62 +
   51.63 +int
   51.64 +SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
   51.65 +{
   51.66 +    SDL_SetError("SDL not configured with thread support");
   51.67 +    return -1;
   51.68 +}
   51.69 +
   51.70 +int
   51.71 +SDL_SemWait(SDL_sem * sem)
   51.72 +{
   51.73 +    SDL_SetError("SDL not configured with thread support");
   51.74 +    return -1;
   51.75 +}
   51.76 +
   51.77 +Uint32
   51.78 +SDL_SemValue(SDL_sem * sem)
   51.79 +{
   51.80 +    return 0;
   51.81 +}
   51.82 +
   51.83 +int
   51.84 +SDL_SemPost(SDL_sem * sem)
   51.85 +{
   51.86 +    SDL_SetError("SDL not configured with thread support");
   51.87 +    return -1;
   51.88 +}
   51.89 +
   51.90 +#else
   51.91 +
   51.92 +struct SDL_semaphore
   51.93 +{
   51.94 +    Uint32 count;
   51.95 +    Uint32 waiters_count;
   51.96 +    SDL_mutex *count_lock;
   51.97 +    SDL_cond *count_nonzero;
   51.98 +};
   51.99 +
  51.100 +SDL_sem *
  51.101 +SDL_CreateSemaphore(Uint32 initial_value)
  51.102 +{
  51.103 +    SDL_sem *sem;
  51.104 +
  51.105 +    sem = (SDL_sem *) malloc(sizeof(*sem));
  51.106 +    if (!sem) {
  51.107 +        SDL_OutOfMemory();
  51.108 +        return (0);
  51.109 +    }
  51.110 +    sem->count = initial_value;
  51.111 +    sem->waiters_count = 0;
  51.112 +
  51.113 +    sem->count_lock = SDL_CreateMutex();
  51.114 +    sem->count_nonzero = SDL_CreateCond();
  51.115 +    if (!sem->count_lock || !sem->count_nonzero) {
  51.116 +        SDL_DestroySemaphore(sem);
  51.117 +        return (0);
  51.118 +    }
  51.119 +
  51.120 +    return (sem);
  51.121 +}
  51.122 +
  51.123 +/* WARNING:
  51.124 +   You cannot call this function when another thread is using the semaphore.
  51.125 +*/
  51.126 +void
  51.127 +SDL_DestroySemaphore(SDL_sem * sem)
  51.128 +{
  51.129 +    if (sem) {
  51.130 +        sem->count = 0xFFFFFFFF;
  51.131 +        while (sem->waiters_count > 0) {
  51.132 +            SDL_CondSignal(sem->count_nonzero);
  51.133 +            SDL_Delay(10);
  51.134 +        }
  51.135 +        SDL_DestroyCond(sem->count_nonzero);
  51.136 +        SDL_mutexP(sem->count_lock);
  51.137 +        SDL_mutexV(sem->count_lock);
  51.138 +        SDL_DestroyMutex(sem->count_lock);
  51.139 +        free(sem);
  51.140 +    }
  51.141 +}
  51.142 +
  51.143 +int
  51.144 +SDL_SemTryWait(SDL_sem * sem)
  51.145 +{
  51.146 +    int retval;
  51.147 +
  51.148 +    if (!sem) {
  51.149 +        SDL_SetError("Passed a NULL semaphore");
  51.150 +        return -1;
  51.151 +    }
  51.152 +
  51.153 +    retval = SDL_MUTEX_TIMEDOUT;
  51.154 +    SDL_LockMutex(sem->count_lock);
  51.155 +    if (sem->count > 0) {
  51.156 +        --sem->count;
  51.157 +        retval = 0;
  51.158 +    }
  51.159 +    SDL_UnlockMutex(sem->count_lock);
  51.160 +
  51.161 +    return retval;
  51.162 +}
  51.163 +
  51.164 +int
  51.165 +SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
  51.166 +{
  51.167 +    int retval;
  51.168 +
  51.169 +    if (!sem) {
  51.170 +        SDL_SetError("Passed a NULL semaphore");
  51.171 +        return -1;
  51.172 +    }
  51.173 +
  51.174 +    /* A timeout of 0 is an easy case */
  51.175 +    if (timeout == 0) {
  51.176 +        return SDL_SemTryWait(sem);
  51.177 +    }
  51.178 +
  51.179 +    SDL_LockMutex(sem->count_lock);
  51.180 +    ++sem->waiters_count;
  51.181 +    retval = 0;
  51.182 +    while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) {
  51.183 +        retval = SDL_CondWaitTimeout(sem->count_nonzero,
  51.184 +                                     sem->count_lock, timeout);
  51.185 +    }
  51.186 +    --sem->waiters_count;
  51.187 +    --sem->count;
  51.188 +    SDL_UnlockMutex(sem->count_lock);
  51.189 +
  51.190 +    return retval;
  51.191 +}
  51.192 +
  51.193 +int
  51.194 +SDL_SemWait(SDL_sem * sem)
  51.195 +{
  51.196 +    return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
  51.197 +}
  51.198 +
  51.199 +Uint32
  51.200 +SDL_SemValue(SDL_sem * sem)
  51.201 +{
  51.202 +    Uint32 value;
  51.203 +
  51.204 +    value = 0;
  51.205 +    if (sem) {
  51.206 +        SDL_LockMutex(sem->count_lock);
  51.207 +        value = sem->count;
  51.208 +        SDL_UnlockMutex(sem->count_lock);
  51.209 +    }
  51.210 +    return value;
  51.211 +}
  51.212 +
  51.213 +int
  51.214 +SDL_SemPost(SDL_sem * sem)
  51.215 +{
  51.216 +    if (!sem) {
  51.217 +        SDL_SetError("Passed a NULL semaphore");
  51.218 +        return -1;
  51.219 +    }
  51.220 +
  51.221 +    SDL_LockMutex(sem->count_lock);
  51.222 +    if (sem->waiters_count > 0) {
  51.223 +        SDL_CondSignal(sem->count_nonzero);
  51.224 +    }
  51.225 +    ++sem->count;
  51.226 +    SDL_UnlockMutex(sem->count_lock);
  51.227 +
  51.228 +    return 0;
  51.229 +}
  51.230 +
  51.231 +#endif /* DISABLE_THREADS */
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/src/thread/nds/SDL_syssem_c.h	Wed Aug 27 15:10:03 2008 +0000
    52.3 @@ -0,0 +1,26 @@
    52.4 +/*
    52.5 +    SDL - Simple DirectMedia Layer
    52.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    52.7 +
    52.8 +    This library is free software; you can redistribute it and/or
    52.9 +    modify it under the terms of the GNU Library General Public
   52.10 +    License as published by the Free Software Foundation; either
   52.11 +    version 2 of the License, or (at your option) any later version.
   52.12 +
   52.13 +    This library is distributed in the hope that it will be useful,
   52.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   52.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   52.16 +    Library General Public License for more details.
   52.17 +
   52.18 +    You should have received a copy of the GNU Library General Public
   52.19 +    License along with this library; if not, write to the Free
   52.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   52.21 +
   52.22 +    Sam Lantinga
   52.23 +    slouken@devolution.com
   52.24 +*/
   52.25 +
   52.26 +#ifdef SAVE_RCSID
   52.27 +static char rcsid =
   52.28 +    "@(#) $Id: SDL_syssem_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   52.29 +#endif
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/src/thread/nds/SDL_systhread.c	Wed Aug 27 15:10:03 2008 +0000
    53.3 @@ -0,0 +1,63 @@
    53.4 +/*
    53.5 +    SDL - Simple DirectMedia Layer
    53.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    53.7 +
    53.8 +    This library is free software; you can redistribute it and/or
    53.9 +    modify it under the terms of the GNU Library General Public
   53.10 +    License as published by the Free Software Foundation; either
   53.11 +    version 2 of the License, or (at your option) any later version.
   53.12 +
   53.13 +    This library is distributed in the hope that it will be useful,
   53.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   53.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   53.16 +    Library General Public License for more details.
   53.17 +
   53.18 +    You should have received a copy of the GNU Library General Public
   53.19 +    License along with this library; if not, write to the Free
   53.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   53.21 +
   53.22 +    Sam Lantinga
   53.23 +    slouken@devolution.com
   53.24 +*/
   53.25 +
   53.26 +#ifdef SAVE_RCSID
   53.27 +static char rcsid =
   53.28 +    "@(#) $Id: SDL_systhread.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   53.29 +#endif
   53.30 +
   53.31 +/* Thread management routines for SDL */
   53.32 +
   53.33 +#include "SDL_error.h"
   53.34 +#include "SDL_thread.h"
   53.35 +#include "SDL_systhread.h"
   53.36 +
   53.37 +int
   53.38 +SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
   53.39 +{
   53.40 +    SDL_SetError("Threads are not supported on this platform");
   53.41 +    return (-1);
   53.42 +}
   53.43 +
   53.44 +void
   53.45 +SDL_SYS_SetupThread(void)
   53.46 +{
   53.47 +    return;
   53.48 +}
   53.49 +
   53.50 +Uint32
   53.51 +SDL_ThreadID(void)
   53.52 +{
   53.53 +    return (0);
   53.54 +}
   53.55 +
   53.56 +void
   53.57 +SDL_SYS_WaitThread(SDL_Thread * thread)
   53.58 +{
   53.59 +    return;
   53.60 +}
   53.61 +
   53.62 +void
   53.63 +SDL_SYS_KillThread(SDL_Thread * thread)
   53.64 +{
   53.65 +    return;
   53.66 +}
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/src/thread/nds/SDL_systhread_c.h	Wed Aug 27 15:10:03 2008 +0000
    54.3 @@ -0,0 +1,28 @@
    54.4 +/*
    54.5 +    SDL - Simple DirectMedia Layer
    54.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    54.7 +
    54.8 +    This library is free software; you can redistribute it and/or
    54.9 +    modify it under the terms of the GNU Library General Public
   54.10 +    License as published by the Free Software Foundation; either
   54.11 +    version 2 of the License, or (at your option) any later version.
   54.12 +
   54.13 +    This library is distributed in the hope that it will be useful,
   54.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   54.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   54.16 +    Library General Public License for more details.
   54.17 +
   54.18 +    You should have received a copy of the GNU Library General Public
   54.19 +    License along with this library; if not, write to the Free
   54.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   54.21 +
   54.22 +    Sam Lantinga
   54.23 +    slouken@devolution.com
   54.24 +*/
   54.25 +
   54.26 +/* Stub until we implement threads on this platform */
   54.27 +typedef int SYS_ThreadHandle;
   54.28 +
   54.29 +#ifndef DISABLE_THREADS
   54.30 +#define DISABLE_THREADS
   54.31 +#endif
    55.1 --- a/src/thread/pthread/SDL_syssem.c	Wed Aug 27 13:37:19 2008 +0000
    55.2 +++ b/src/thread/pthread/SDL_syssem.c	Wed Aug 27 15:10:03 2008 +0000
    55.3 @@ -125,8 +125,7 @@
    55.4              break;
    55.5          }
    55.6          SDL_Delay(1);
    55.7 -    }
    55.8 -    while (SDL_GetTicks() < timeout);
    55.9 +    } while (SDL_GetTicks() < timeout);
   55.10  
   55.11      return retval;
   55.12  }
    56.1 --- a/src/thread/riscos/SDL_syssem.c	Wed Aug 27 13:37:19 2008 +0000
    56.2 +++ b/src/thread/riscos/SDL_syssem.c	Wed Aug 27 15:10:03 2008 +0000
    56.3 @@ -177,8 +177,7 @@
    56.4              break;
    56.5          }
    56.6          SDL_Delay(1);
    56.7 -    }
    56.8 -    while (SDL_GetTicks() < timeout);
    56.9 +    } while (SDL_GetTicks() < timeout);
   56.10  
   56.11      return retval;
   56.12  }
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/src/timer/nds/SDL_systimer.c	Wed Aug 27 15:10:03 2008 +0000
    57.3 @@ -0,0 +1,120 @@
    57.4 +/*
    57.5 +    SDL - Simple DirectMedia Layer
    57.6 +    Copyright (C) 1997-2006 Sam Lantinga
    57.7 +
    57.8 +    This library is free software; you can redistribute it and/or
    57.9 +    modify it under the terms of the GNU Lesser General Public
   57.10 +    License as published by the Free Software Foundation; either
   57.11 +    version 2.1 of the License, or (at your option) any later version.
   57.12 +
   57.13 +    This library is distributed in the hope that it will be useful,
   57.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   57.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   57.16 +    Lesser General Public License for more details.
   57.17 +
   57.18 +    You should have received a copy of the GNU Lesser General Public
   57.19 +    License along with this library; if not, write to the Free Software
   57.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   57.21 +
   57.22 +    Sam Lantinga
   57.23 +    slouken@libsdl.org
   57.24 +*/
   57.25 +#include "SDL_config.h"
   57.26 +
   57.27 +#ifdef SDL_TIMER_NDS
   57.28 +
   57.29 +#include <nds.h>
   57.30 +#include <nds/timers.h>
   57.31 +
   57.32 +#include "SDL_timer.h"
   57.33 +#include "../SDL_timer_c.h"
   57.34 +#include "../SDL_systimer.h"
   57.35 +
   57.36 +/* Data to handle a single periodic alarm */
   57.37 +static int timer_alive = 0;
   57.38 +static Uint32 timer_ticks;
   57.39 +
   57.40 +void
   57.41 +SDL_StartTicks(void)
   57.42 +{
   57.43 +    if (!timer_alive) {
   57.44 +        SDL_SYS_TimerInit();
   57.45 +        SDL_SYS_StartTimer();
   57.46 +    }
   57.47 +
   57.48 +    timer_ticks = 0;
   57.49 +}
   57.50 +
   57.51 +Uint32
   57.52 +SDL_GetTicks(void)
   57.53 +{
   57.54 +    return timer_ticks;
   57.55 +}
   57.56 +
   57.57 +void
   57.58 +SDL_Delay(Uint32 ms)
   57.59 +{
   57.60 +    Uint32 start = SDL_GetTicks();
   57.61 +    while (timer_alive) {
   57.62 +        if ((SDL_GetTicks() - start) >= ms)
   57.63 +            break;
   57.64 +    }
   57.65 +}
   57.66 +
   57.67 +static int
   57.68 +RunTimer(void *unused)
   57.69 +{
   57.70 +    while (timer_alive) {
   57.71 +        if (SDL_timer_running) {
   57.72 +        }
   57.73 +        SDL_Delay(1);
   57.74 +    }
   57.75 +    return (0);
   57.76 +}
   57.77 +
   57.78 +void
   57.79 +NDS_TimerInterrupt(void)
   57.80 +{
   57.81 +    timer_ticks++;
   57.82 +}
   57.83 +
   57.84 +/* This is only called if the event thread is not running */
   57.85 +int
   57.86 +SDL_SYS_TimerInit(void)
   57.87 +{
   57.88 +    timer_alive = 1;
   57.89 +    timer_ticks = 0;
   57.90 +    TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
   57.91 +    TIMER_DATA(3) = TIMER_FREQ_1024(1000);
   57.92 +    irqSet(IRQ_TIMER3, NDS_TimerInterrupt);
   57.93 +    irqEnable(IRQ_TIMER3);
   57.94 +    return 0;
   57.95 +}
   57.96 +
   57.97 +void
   57.98 +SDL_SYS_TimerQuit(void)
   57.99 +{
  57.100 +    if (timer_alive) {
  57.101 +        TIMER_CR(3) = 0;
  57.102 +    }
  57.103 +    timer_alive = 0;
  57.104 +    irqDisable(IRQ_TIMER3);
  57.105 +}
  57.106 +
  57.107 +int
  57.108 +SDL_SYS_StartTimer(void)
  57.109 +{
  57.110 +    TIMER_CR(3) |= TIMER_ENABLE;
  57.111 +    return 0;
  57.112 +}
  57.113 +
  57.114 +void
  57.115 +SDL_SYS_StopTimer(void)
  57.116 +{
  57.117 +    TIMER_CR(3) &= ~TIMER_ENABLE;
  57.118 +    return;
  57.119 +}
  57.120 +
  57.121 +
  57.122 +#endif /* SDL_TIMER_NDS */
  57.123 +/* vi: set ts=4 sw=4 expandtab: */
    58.1 --- a/src/timer/riscos/SDL_systimer.c	Wed Aug 27 13:37:19 2008 +0000
    58.2 +++ b/src/timer/riscos/SDL_systimer.c	Wed Aug 27 15:10:03 2008 +0000
    58.3 @@ -130,8 +130,7 @@
    58.4              pthread_yield();
    58.5  #endif
    58.6  
    58.7 -    }
    58.8 -    while (1);
    58.9 +    } while (1);
   58.10  }
   58.11  
   58.12  #if SDL_THREADS_DISABLED
    59.1 --- a/src/timer/unix/SDL_systimer.c	Wed Aug 27 13:37:19 2008 +0000
    59.2 +++ b/src/timer/unix/SDL_systimer.c	Wed Aug 27 15:10:03 2008 +0000
    59.3 @@ -137,8 +137,7 @@
    59.4  
    59.5          was_error = select(0, NULL, NULL, NULL, &tv);
    59.6  #endif /* HAVE_NANOSLEEP */
    59.7 -    }
    59.8 -    while (was_error && (errno == EINTR));
    59.9 +    } while (was_error && (errno == EINTR));
   59.10  #endif /* SDL_THREAD_PTH */
   59.11  }
   59.12  
    60.1 --- a/src/video/SDL_RLEaccel.c	Wed Aug 27 13:37:19 2008 +0000
    60.2 +++ b/src/video/SDL_RLEaccel.c	Wed Aug 27 15:10:03 2008 +0000
    60.3 @@ -1154,8 +1154,7 @@
    60.4                              ofs += run;
    60.5                          } else if (!ofs)
    60.6                              goto done;
    60.7 -                    }
    60.8 -                    while (ofs < w);
    60.9 +                    } while (ofs < w);
   60.10  
   60.11                      /* skip padding */
   60.12                      srcbuf += (uintptr_t) srcbuf & 2;
   60.13 @@ -1168,10 +1167,8 @@
   60.14                          run = ((Uint16 *) srcbuf)[1];
   60.15                          srcbuf += 4 * (run + 1);
   60.16                          ofs += run;
   60.17 -                    }
   60.18 -                    while (ofs < w);
   60.19 -                }
   60.20 -                while (--vskip);
   60.21 +                    } while (ofs < w);
   60.22 +                } while (--vskip);
   60.23              } else {
   60.24                  /* the 32/32 interleaved format */
   60.25                  vskip <<= 1;    /* opaque and translucent have same format */
   60.26 @@ -1187,10 +1184,8 @@
   60.27                              ofs += run;
   60.28                          } else if (!ofs)
   60.29                              goto done;
   60.30 -                    }
   60.31 -                    while (ofs < w);
   60.32 -                }
   60.33 -                while (--vskip);
   60.34 +                    } while (ofs < w);
   60.35 +                } while (--vskip);
   60.36              }
   60.37          }
   60.38      }
   60.39 @@ -1567,8 +1562,7 @@
   60.40                      runstart += len;
   60.41                      run -= len;
   60.42                  }
   60.43 -            }
   60.44 -            while (x < w);
   60.45 +            } while (x < w);
   60.46  
   60.47              /* Make sure the next output address is 32-bit aligned */
   60.48              dst += (uintptr_t) dst & 2;
   60.49 @@ -1604,8 +1598,7 @@
   60.50                  }
   60.51                  if (!blankline)
   60.52                      lastline = dst;
   60.53 -            }
   60.54 -            while (x < w);
   60.55 +            } while (x < w);
   60.56  
   60.57              src += surface->pitch >> 2;
   60.58          }
   60.59 @@ -1771,8 +1764,7 @@
   60.60              }
   60.61              if (!blankline)
   60.62                  lastline = dst;
   60.63 -        }
   60.64 -        while (x < w);
   60.65 +        } while (x < w);
   60.66  
   60.67          srcbuf += surface->pitch;
   60.68      }
   60.69 @@ -1911,8 +1903,7 @@
   60.70                  ofs += run;
   60.71              } else if (!ofs)
   60.72                  return (SDL_TRUE);
   60.73 -        }
   60.74 -        while (ofs < w);
   60.75 +        } while (ofs < w);
   60.76  
   60.77          /* skip padding if needed */
   60.78          if (bpp == 2)
   60.79 @@ -1929,8 +1920,7 @@
   60.80                  srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
   60.81                  ofs += run;
   60.82              }
   60.83 -        }
   60.84 -        while (ofs < w);
   60.85 +        } while (ofs < w);
   60.86          dst += surface->pitch >> 2;
   60.87      }
   60.88      /* Make the compiler happy */
    61.1 --- a/src/video/SDL_blit_0.c	Wed Aug 27 13:37:19 2008 +0000
    61.2 +++ b/src/video/SDL_blit_0.c	Wed Aug 27 15:10:03 2008 +0000
    61.3 @@ -80,6 +80,7 @@
    61.4          }
    61.5      }
    61.6  }
    61.7 +
    61.8  static void
    61.9  BlitBto2(SDL_BlitInfo * info)
   61.10  {
   61.11 @@ -116,6 +117,7 @@
   61.12          dst += dstskip;
   61.13      }
   61.14  }
   61.15 +
   61.16  static void
   61.17  BlitBto3(SDL_BlitInfo * info)
   61.18  {
   61.19 @@ -154,6 +156,7 @@
   61.20          dst += dstskip;
   61.21      }
   61.22  }
   61.23 +
   61.24  static void
   61.25  BlitBto4(SDL_BlitInfo * info)
   61.26  {
    62.1 --- a/src/video/SDL_blit_1.c	Wed Aug 27 13:37:19 2008 +0000
    62.2 +++ b/src/video/SDL_blit_1.c	Wed Aug 27 15:10:03 2008 +0000
    62.3 @@ -184,6 +184,7 @@
    62.4      }
    62.5  #endif /* USE_DUFFS_LOOP */
    62.6  }
    62.7 +
    62.8  static void
    62.9  Blit1to3(SDL_BlitInfo * info)
   62.10  {
   62.11 @@ -232,6 +233,7 @@
   62.12          dst += dstskip;
   62.13      }
   62.14  }
   62.15 +
   62.16  static void
   62.17  Blit1to4(SDL_BlitInfo * info)
   62.18  {
    63.1 --- a/src/video/SDL_blit_A.c	Wed Aug 27 13:37:19 2008 +0000
    63.2 +++ b/src/video/SDL_blit_A.c	Wed Aug 27 15:10:03 2008 +0000
    63.3 @@ -283,8 +283,8 @@
    63.4          amult = alpha | (alpha << 8);
    63.5          amult = amult | (amult << 16);
    63.6          chanmask =
    63.7 -            (0xff << df->Rshift) | (0xff << df->Gshift) | (0xff << df->
    63.8 -                                                           Bshift);
    63.9 +            (0xff << df->Rshift) | (0xff << df->
   63.10 +                                    Gshift) | (0xff << df->Bshift);
   63.11          mm_alpha = _mm_set_pi32(0, amult & chanmask);   /* 0000AAAA -> mm_alpha, minus 1 chan */
   63.12          mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */
   63.13          /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */
   63.14 @@ -526,8 +526,8 @@
   63.15      /* Use zero for alpha if either surface doesn't have alpha */
   63.16      if (dstfmt->Amask) {
   63.17          amask =
   63.18 -            ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->
   63.19 -                                                                   Ashift);
   63.20 +            ((srcfmt->Amask) ? RESHIFT(srcfmt->
   63.21 +                                       Ashift) : 0x10) << (dstfmt->Ashift);
   63.22      } else {
   63.23          amask =
   63.24              0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
    64.1 --- a/src/video/SDL_blit_N.c	Wed Aug 27 13:37:19 2008 +0000
    64.2 +++ b/src/video/SDL_blit_N.c	Wed Aug 27 15:10:03 2008 +0000
    64.3 @@ -141,8 +141,8 @@
    64.4      /* Use zero for alpha if either surface doesn't have alpha */
    64.5      if (dstfmt->Amask) {
    64.6          amask =
    64.7 -            ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->
    64.8 -                                                                   Ashift);
    64.9 +            ((srcfmt->Amask) ? RESHIFT(srcfmt->
   64.10 +                                       Ashift) : 0x10) << (dstfmt->Ashift);
   64.11      } else {
   64.12          amask =
   64.13              0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
   64.14 @@ -1435,6 +1435,7 @@
   64.15      0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100,
   64.16      0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200
   64.17  };
   64.18 +
   64.19  static void
   64.20  Blit_RGB565_ARGB8888(SDL_BlitInfo * info)
   64.21  {
   64.22 @@ -1572,6 +1573,7 @@
   64.23      0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff,
   64.24      0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff
   64.25  };
   64.26 +
   64.27  static void
   64.28  Blit_RGB565_ABGR8888(SDL_BlitInfo * info)
   64.29  {
   64.30 @@ -1709,6 +1711,7 @@
   64.31      0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000,
   64.32      0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000,
   64.33  };
   64.34 +
   64.35  static void
   64.36  Blit_RGB565_RGBA8888(SDL_BlitInfo * info)
   64.37  {
   64.38 @@ -1846,6 +1849,7 @@
   64.39      0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff,
   64.40      0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff
   64.41  };
   64.42 +
   64.43  static void
   64.44  Blit_RGB565_BGRA8888(SDL_BlitInfo * info)
   64.45  {
   64.46 @@ -1930,6 +1934,7 @@
   64.47      }
   64.48  #endif /* USE_DUFFS_LOOP */
   64.49  }
   64.50 +
   64.51  static void
   64.52  BlitNto1(SDL_BlitInfo * info)
   64.53  {
   64.54 @@ -2340,6 +2345,7 @@
   64.55      /* Default for 8-bit RGB source, an invalid combination */
   64.56      {0, 0, 0, 0, 0, 0, 0, 0, NULL},
   64.57  };
   64.58 +
   64.59  static const struct blit_table normal_blit_2[] = {
   64.60  #if SDL_ALTIVEC_BLITTERS
   64.61      /* has-altivec */
   64.62 @@ -2366,10 +2372,12 @@
   64.63      /* Default for 16-bit RGB source, used if no other blitter matches */
   64.64      {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   64.65  };
   64.66 +
   64.67  static const struct blit_table normal_blit_3[] = {
   64.68      /* Default for 24-bit RGB source, never optimized */
   64.69      {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   64.70  };
   64.71 +
   64.72  static const struct blit_table normal_blit_4[] = {
   64.73  #if SDL_ALTIVEC_BLITTERS
   64.74      /* has-altivec | dont-use-prefetch */
   64.75 @@ -2396,6 +2404,7 @@
   64.76      /* Default for 32-bit RGB source, used if no other blitter matches */
   64.77      {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   64.78  };
   64.79 +
   64.80  static const struct blit_table *normal_blit[] = {
   64.81      normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
   64.82  };
    65.1 --- a/src/video/SDL_gamma.c	Wed Aug 27 13:37:19 2008 +0000
    65.2 +++ b/src/video/SDL_gamma.c	Wed Aug 27 15:10:03 2008 +0000
    65.3 @@ -70,6 +70,7 @@
    65.4          }
    65.5      }
    65.6  }
    65.7 +
    65.8  static void
    65.9  CalculateGammaFromRamp(float *gamma, Uint16 * ramp)
   65.10  {
    66.1 --- a/src/video/SDL_pixels.c	Wed Aug 27 13:37:19 2008 +0000
    66.2 +++ b/src/video/SDL_pixels.c	Wed Aug 27 15:10:03 2008 +0000
    66.3 @@ -168,12 +168,16 @@
    66.4          break;
    66.5      case 15:
    66.6          switch (Rmask) {
    66.7 +        case 0x001F:
    66.8 +            return SDL_PIXELFORMAT_BGR555;
    66.9          case 0x7C00:
   66.10              return SDL_PIXELFORMAT_RGB555;
   66.11          }
   66.12          break;
   66.13      case 16:
   66.14          switch (Rmask) {
   66.15 +        case 0x001F:
   66.16 +            return SDL_PIXELFORMAT_ABGR1555;
   66.17          case 0x0F00:
   66.18              return SDL_PIXELFORMAT_ARGB4444;
   66.19          case 0x7C00:
   66.20 @@ -748,6 +752,7 @@
   66.21          map->info.table = NULL;
   66.22      }
   66.23  }
   66.24 +
   66.25  int
   66.26  SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
   66.27  {
    67.1 --- a/src/video/SDL_renderer_sw.c	Wed Aug 27 13:37:19 2008 +0000
    67.2 +++ b/src/video/SDL_renderer_sw.c	Wed Aug 27 15:10:03 2008 +0000
    67.3 @@ -388,8 +388,9 @@
    67.4                        void **pixels, int *pitch)
    67.5  {
    67.6      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
    67.7 -        return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture->
    67.8 -                                            driverdata, pixels, pitch);
    67.9 +        return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *)
   67.10 +                                            texture->driverdata, pixels,
   67.11 +                                            pitch);
   67.12      } else {
   67.13          SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   67.14  
   67.15 @@ -464,8 +465,9 @@
   67.16                   const SDL_Rect * rect, const void *pixels, int pitch)
   67.17  {
   67.18      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   67.19 -        return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture->
   67.20 -                                       driverdata, rect, pixels, pitch);
   67.21 +        return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *)
   67.22 +                                       texture->driverdata, rect, pixels,
   67.23 +                                       pitch);
   67.24      } else {
   67.25          SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   67.26          Uint8 *src, *dst;
   67.27 @@ -492,9 +494,9 @@
   67.28                 int *pitch)
   67.29  {
   67.30      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   67.31 -        return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) texture->
   67.32 -                                     driverdata, rect, markDirty, pixels,
   67.33 -                                     pitch);
   67.34 +        return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *)
   67.35 +                                     texture->driverdata, rect, markDirty,
   67.36 +                                     pixels, pitch);
   67.37      } else {
   67.38          SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   67.39  
   67.40 @@ -535,10 +537,10 @@
   67.41  
   67.42      color = SDL_MapRGBA(data->surface.format, r, g, b, a);
   67.43  
   67.44 -    if (data->renderer->
   67.45 -        LockTexture(data->renderer, data->texture[data->current_texture],
   67.46 -                    rect, 1, &data->surface.pixels,
   67.47 -                    &data->surface.pitch) < 0) {
   67.48 +    if (data->renderer->LockTexture(data->renderer,
   67.49 +                                    data->texture[data->current_texture],
   67.50 +                                    rect, 1, &data->surface.pixels,
   67.51 +                                    &data->surface.pitch) < 0) {
   67.52          return -1;
   67.53      }
   67.54      data->surface.w = rect->w;
   67.55 @@ -566,10 +568,10 @@
   67.56          SDL_AddDirtyRect(&data->dirty, dstrect);
   67.57      }
   67.58  
   67.59 -    if (data->renderer->
   67.60 -        LockTexture(data->renderer, data->texture[data->current_texture],
   67.61 -                    dstrect, 1, &data->surface.pixels,
   67.62 -                    &data->surface.pitch) < 0) {
   67.63 +    if (data->renderer->LockTexture(data->renderer,
   67.64 +                                    data->texture[data->current_texture],
   67.65 +                                    dstrect, 1, &data->surface.pixels,
   67.66 +                                    &data->surface.pitch) < 0) {
   67.67          return -1;
   67.68      }
   67.69  
    68.1 --- a/src/video/SDL_surface.c	Wed Aug 27 13:37:19 2008 +0000
    68.2 +++ b/src/video/SDL_surface.c	Wed Aug 27 15:10:03 2008 +0000
    68.3 @@ -409,9 +409,9 @@
    68.4          return 0;
    68.5      }
    68.6  
    68.7 -    switch (surface->map->info.
    68.8 -            flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD |
    68.9 -                     SDL_COPY_MOD)) {
   68.10 +    switch (surface->map->
   68.11 +            info.flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD |
   68.12 +                          SDL_COPY_MOD)) {
   68.13      case SDL_COPY_MASK:
   68.14          *blendMode = SDL_TEXTUREBLENDMODE_MASK;
   68.15          break;
    69.1 --- a/src/video/SDL_sysvideo.h	Wed Aug 27 13:37:19 2008 +0000
    69.2 +++ b/src/video/SDL_sysvideo.h	Wed Aug 27 15:10:03 2008 +0000
    69.3 @@ -369,6 +369,9 @@
    69.4  #if SDL_VIDEO_DRIVER_DUMMY
    69.5  extern VideoBootStrap DUMMY_bootstrap;
    69.6  #endif
    69.7 +#if SDL_VIDEO_DRIVER_NDS
    69.8 +extern VideoBootStrap NDS_bootstrap;
    69.9 +#endif
   69.10  
   69.11  #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   69.12  
    70.1 --- a/src/video/SDL_video.c	Wed Aug 27 13:37:19 2008 +0000
    70.2 +++ b/src/video/SDL_video.c	Wed Aug 27 15:10:03 2008 +0000
    70.3 @@ -103,6 +103,9 @@
    70.4  #if SDL_VIDEO_DRIVER_OS2FS
    70.5      &OS2FSLib_bootstrap,
    70.6  #endif
    70.7 +#if SDL_VIDEO_DRIVER_NDS
    70.8 +    &NDS_bootstrap,
    70.9 +#endif
   70.10  #if SDL_VIDEO_DRIVER_DUMMY
   70.11      &DUMMY_bootstrap,
   70.12  #endif
    71.1 --- a/src/video/ataricommon/SDL_atarigl.c	Wed Aug 27 13:37:19 2008 +0000
    71.2 +++ b/src/video/ataricommon/SDL_atarigl.c	Wed Aug 27 15:10:03 2008 +0000
    71.3 @@ -349,9 +349,9 @@
    71.4      }
    71.5  
    71.6      if (!
    71.7 -        (_this->gl_data->
    71.8 -         OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w,
    71.9 -                           surface->h))) {
   71.10 +        (_this->
   71.11 +         gl_data->OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w,
   71.12 +                                    surface->h))) {
   71.13          SDL_SetError("Can not make OpenGL context current");
   71.14          return -1;
   71.15      }
   71.16 @@ -512,10 +512,10 @@
   71.17  
   71.18          gl_ctx =
   71.19              _this->gl_data->OSMesaCreateContextExt(osmesa_format,
   71.20 -                                                   _this->gl_config.
   71.21 -                                                   depth_size,
   71.22 -                                                   _this->gl_config.
   71.23 -                                                   stencil_size,
   71.24 +                                                   _this->
   71.25 +                                                   gl_config.depth_size,
   71.26 +                                                   _this->
   71.27 +                                                   gl_config.stencil_size,
   71.28                                                     newaccumsize, NULL);
   71.29  
   71.30          if (gl_ctx) {
    72.1 --- a/src/video/bwindow/SDL_sysvideo.cc	Wed Aug 27 13:37:19 2008 +0000
    72.2 +++ b/src/video/bwindow/SDL_sysvideo.cc	Wed Aug 27 15:10:03 2008 +0000
    72.3 @@ -670,8 +670,8 @@
    72.4                          _this->gl_config.driver_loaded = 1;
    72.5                          SDL_strlcpy(_this->gl_config.driver_path,
    72.6                                      "libGL.so",
    72.7 -                                    SDL_arraysize(_this->gl_config.
    72.8 -                                                  driver_path));
    72.9 +                                    SDL_arraysize(_this->
   72.10 +                                                  gl_config.driver_path));
   72.11                      }
   72.12                  }
   72.13              }
    73.1 --- a/src/video/dc/SDL_dcevents.c	Wed Aug 27 13:37:19 2008 +0000
    73.2 +++ b/src/video/dc/SDL_dcevents.c	Wed Aug 27 15:10:03 2008 +0000
    73.3 @@ -135,8 +135,7 @@
    73.4      for (i = 0; i < sizeof(sdl_shift); i++) {
    73.5          if ((shiftkeys >> i) & 1) {
    73.6              keysym.sym = sdl_shift[i];
    73.7 -            SDL_PrivateKeyboard(((state->
    73.8 -                                  shift_keys >> i) & 1) ? SDL_PRESSED :
    73.9 +            SDL_PrivateKeyboard(((state->shift_keys >> i) & 1) ? SDL_PRESSED :
   73.10                                  SDL_RELEASED, &keysym);
   73.11          }
   73.12      }
   73.13 @@ -146,8 +145,7 @@
   73.14              int key = sdl_key[i];
   73.15              if (key) {
   73.16                  keysym.sym = key;
   73.17 -                SDL_PrivateKeyboard(state->
   73.18 -                                    matrix[i] ? SDL_PRESSED :
   73.19 +                SDL_PrivateKeyboard(state->matrix[i] ? SDL_PRESSED :
   73.20                                      SDL_RELEASED, &keysym);
   73.21              }
   73.22          }
    74.1 --- a/src/video/dc/SDL_dcvideo.c	Wed Aug 27 13:37:19 2008 +0000
    74.2 +++ b/src/video/dc/SDL_dcvideo.c	Wed Aug 27 15:10:03 2008 +0000
    74.3 @@ -158,6 +158,7 @@
    74.4  const static SDL_Rect RECT_800x600 = { 0, 0, 800, 600 }, RECT_640x480 = {
    74.5  0, 0, 640, 480}, RECT_320x240 = {
    74.6  0, 0, 320, 240};
    74.7 +
    74.8  const static SDL_Rect *vid_modes[] = {
    74.9      &RECT_800x600,
   74.10      &RECT_640x480,
   74.11 @@ -296,6 +297,7 @@
   74.12  {
   74.13      return (-1);
   74.14  }
   74.15 +
   74.16  static void
   74.17  DC_FreeHWSurface(_THIS, SDL_Surface * surface)
   74.18  {
    75.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Wed Aug 27 13:37:19 2008 +0000
    75.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Wed Aug 27 15:10:03 2008 +0000
    75.3 @@ -383,33 +383,25 @@
    75.4              switch (evt.type) {
    75.5              case DIET_BUTTONPRESS:
    75.6                  posted += SDL_PrivateMouseButton(SDL_PRESSED,
    75.7 -                                                 DirectFB_TranslateButton(evt.
    75.8 -                                                                          button),
    75.9 -                                                 0, 0);
   75.10 +                                                 DirectFB_TranslateButton
   75.11 +                                                 (evt.button), 0, 0);
   75.12                  break;
   75.13              case DIET_BUTTONRELEASE:
   75.14                  posted += SDL_PrivateMouseButton(SDL_RELEASED,
   75.15 -                                                 DirectFB_TranslateButton(evt.
   75.16 -                                                                          button),
   75.17 -                                                 0, 0);
   75.18 +                                                 DirectFB_TranslateButton
   75.19 +                                                 (evt.button), 0, 0);
   75.20                  break;
   75.21              case DIET_KEYPRESS:
   75.22                  posted += SDL_PrivateKeyboard(SDL_PRESSED,
   75.23 -                                              DirectFB_TranslateKey(evt.
   75.24 -                                                                    key_id,
   75.25 -                                                                    evt.
   75.26 -                                                                    key_symbol,
   75.27 -                                                                    mod,
   75.28 -                                                                    &keysym));
   75.29 +                                              DirectFB_TranslateKey
   75.30 +                                              (evt.key_id, evt.key_symbol,
   75.31 +                                               mod, &keysym));
   75.32                  break;
   75.33              case DIET_KEYRELEASE:
   75.34                  posted += SDL_PrivateKeyboard(SDL_RELEASED,
   75.35 -                                              DirectFB_TranslateKey(evt.
   75.36 -                                                                    key_id,
   75.37 -                                                                    evt.
   75.38 -                                                                    key_symbol,
   75.39 -                                                                    mod,
   75.40 -                                                                    &keysym));
   75.41 +                                              DirectFB_TranslateKey
   75.42 +                                              (evt.key_id, evt.key_symbol,
   75.43 +                                               mod, &keysym));
   75.44                  break;
   75.45              case DIET_AXISMOTION:
   75.46                  if (evt.flags & DIEF_AXISREL) {
    76.1 --- a/src/video/directfb/SDL_DirectFB_mouse.c	Wed Aug 27 13:37:19 2008 +0000
    76.2 +++ b/src/video/directfb/SDL_DirectFB_mouse.c	Wed Aug 27 15:10:03 2008 +0000
    76.3 @@ -85,14 +85,15 @@
    76.4      dsc.height = surface->h;
    76.5      dsc.pixelformat = DSPF_ARGB;
    76.6  
    76.7 -    SDL_DFB_CHECKERR(devdata->dfb->
    76.8 -                     CreateSurface(devdata->dfb, &dsc, &curdata->surf));
    76.9 +    SDL_DFB_CHECKERR(devdata->
   76.10 +                     dfb->CreateSurface(devdata->dfb, &dsc, &curdata->surf));
   76.11      curdata->hotx = hot_x;
   76.12      curdata->hoty = hot_y;
   76.13      cursor->driverdata = curdata;
   76.14  
   76.15 -    SDL_DFB_CHECKERR(curdata->surf->
   76.16 -                     Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch));
   76.17 +    SDL_DFB_CHECKERR(curdata->
   76.18 +                     surf->Lock(curdata->surf, DSLF_WRITE, (void *) &dest,
   76.19 +                                &pitch));
   76.20  
   76.21      //FIXME: Implies a lot of things, e.g. rgba format for SDL_SURFACE ....
   76.22      p = surface->pixels;
   76.23 @@ -131,18 +132,18 @@
   76.24          DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
   76.25  
   76.26          if (cursor)
   76.27 -            SDL_DFB_CHECKERR(windata->window->
   76.28 -                             SetCursorShape(windata->window, curdata->surf,
   76.29 -                                            curdata->hotx, curdata->hoty));
   76.30 +            SDL_DFB_CHECKERR(windata->window->SetCursorShape(windata->window,
   76.31 +                                                             curdata->surf,
   76.32 +                                                             curdata->hotx,
   76.33 +                                                             curdata->hoty));
   76.34          //TODO: Check administrative 
   76.35 -        SDL_DFB_CHECKERR(dispdata->layer->
   76.36 -                         SetCooperativeLevel(dispdata->layer,
   76.37 -                                             DLSCL_ADMINISTRATIVE));
   76.38 -        SDL_DFB_CHECKERR(dispdata->layer->
   76.39 -                         SetCursorOpacity(dispdata->layer,
   76.40 -                                          cursor ? 0xC0 : 0x00));
   76.41 -        SDL_DFB_CHECKERR(dispdata->layer->
   76.42 -                         SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
   76.43 +        SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
   76.44 +                                                              DLSCL_ADMINISTRATIVE));
   76.45 +        SDL_DFB_CHECKERR(dispdata->layer->SetCursorOpacity(dispdata->layer,
   76.46 +                                                           cursor ? 0xC0 :
   76.47 +                                                           0x00));
   76.48 +        SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
   76.49 +                                                              DLSCL_SHARED));
   76.50      }
   76.51  
   76.52      return 0;
   76.53 @@ -181,8 +182,8 @@
   76.54      int cx, cy;
   76.55  
   76.56      SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy));
   76.57 -    SDL_DFB_CHECKERR(dispdata->layer->
   76.58 -                     WarpCursor(dispdata->layer, cx + x, cy + y));
   76.59 +    SDL_DFB_CHECKERR(dispdata->
   76.60 +                     layer->WarpCursor(dispdata->layer, cx + x, cy + y));
   76.61  
   76.62    error:
   76.63      return;
    77.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Wed Aug 27 13:37:19 2008 +0000
    77.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Wed Aug 27 15:10:03 2008 +0000
    77.3 @@ -314,8 +314,8 @@
    77.4          SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen));
    77.5  
    77.6          devdata->aux = i;
    77.7 -        SDL_DFB_CHECKERR(screen->
    77.8 -                         EnumDisplayLayers(screen, &cbLayers, devdata));
    77.9 +        SDL_DFB_CHECKERR(screen->EnumDisplayLayers
   77.10 +                         (screen, &cbLayers, devdata));
   77.11  #if (DIRECTFB_MAJOR_VERSION >= 1)
   77.12          screen->GetSize(screen, &tcw[i], &tch[i]);
   77.13  #else
   77.14 @@ -338,12 +338,12 @@
   77.15  
   77.16      for (i = 0; i < devdata->numscreens; i++) {
   77.17          //SDL_DFB_CHECKERR( dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer) );
   77.18 -        SDL_DFB_CHECKERR(dfb->
   77.19 -                         GetDisplayLayer(dfb, devdata->gralayer[i], &layer));
   77.20 +        SDL_DFB_CHECKERR(dfb->GetDisplayLayer
   77.21 +                         (dfb, devdata->gralayer[i], &layer));
   77.22          //SDL_DFB_CHECKERR( dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events) );
   77.23  
   77.24 -        SDL_DFB_CHECKERR(layer->
   77.25 -                         SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE));
   77.26 +        SDL_DFB_CHECKERR(layer->SetCooperativeLevel
   77.27 +                         (layer, DLSCL_ADMINISTRATIVE));
   77.28          layer->EnableCursor(layer, 1);
   77.29          SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
   77.30          SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
   77.31 @@ -379,8 +379,8 @@
   77.32          /* Enumerate the available fullscreen modes */
   77.33          SDL_DFB_CALLOC(dispdata->modelist, DFB_MAX_MODES,
   77.34                         sizeof(SDL_DisplayMode));
   77.35 -        SDL_DFB_CHECKERR(dfb->
   77.36 -                         EnumVideoModes(dfb, EnumModesCallback, &display));
   77.37 +        SDL_DFB_CHECKERR(dfb->EnumVideoModes
   77.38 +                         (dfb, EnumModesCallback, &display));
   77.39  
   77.40          SDL_AddVideoDisplay(&display);
   77.41      }
   77.42 @@ -433,13 +433,14 @@
   77.43          DFB_DisplayData *dispdata =
   77.44              (DFB_DisplayData *) _this->displays[i].driverdata;
   77.45          if (dispdata->layer) {
   77.46 -            SDL_DFB_CHECK(dispdata->layer->
   77.47 -                          SetCooperativeLevel(dispdata->layer,
   77.48 -                                              DLSCL_ADMINISTRATIVE));
   77.49 -            SDL_DFB_CHECK(dispdata->layer->
   77.50 -                          SetCursorOpacity(dispdata->layer, 0x00));
   77.51 -            SDL_DFB_CHECK(dispdata->layer->
   77.52 -                          SetCooperativeLevel(dispdata->layer, DLSCL_SHARED));
   77.53 +            SDL_DFB_CHECK(dispdata->
   77.54 +                          layer->SetCooperativeLevel(dispdata->layer,
   77.55 +                                                     DLSCL_ADMINISTRATIVE));
   77.56 +            SDL_DFB_CHECK(dispdata->
   77.57 +                          layer->SetCursorOpacity(dispdata->layer, 0x00));
   77.58 +            SDL_DFB_CHECK(dispdata->
   77.59 +                          layer->SetCooperativeLevel(dispdata->layer,
   77.60 +                                                     DLSCL_SHARED));
   77.61          }
   77.62          SDL_DFB_RELEASE(dispdata->layer);
   77.63  
   77.64 @@ -578,8 +579,8 @@
   77.65      DFBResult ret;
   77.66      DFB_WindowData *win;
   77.67  
   77.68 -    SDL_DFB_CHECKERR(data->layer->
   77.69 -                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
   77.70 +    SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
   77.71 +                                                      DLSCL_ADMINISTRATIVE));
   77.72  
   77.73      SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
   77.74      config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;        // | DLCONF_BUFFERMODE;
   77.75 @@ -604,8 +605,8 @@
   77.76      SDL_DFB_DEBUG("Trace\n");
   77.77      config.flags &= ~fail;
   77.78      SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
   77.79 -    SDL_DFB_CHECKERR(data->layer->
   77.80 -                     SetCooperativeLevel(data->layer, DLSCL_ADMINISTRATIVE));
   77.81 +    SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
   77.82 +                                                      DLSCL_ADMINISTRATIVE));
   77.83  
   77.84      /* Double check */
   77.85      SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
   77.86 @@ -674,11 +675,11 @@
   77.87      SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
   77.88      windata = (DFB_WindowData *) window->driverdata;
   77.89  
   77.90 -    SDL_DFB_CHECKERR(devdata->dfb->
   77.91 -                     SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
   77.92 -    SDL_DFB_CHECKERR(dispdata->layer->
   77.93 -                     SetCooperativeLevel(dispdata->layer,
   77.94 -                                         DLSCL_ADMINISTRATIVE));
   77.95 +    SDL_DFB_CHECKERR(devdata->
   77.96 +                     dfb->SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
   77.97 +    SDL_DFB_CHECKERR(dispdata->
   77.98 +                     layer->SetCooperativeLevel(dispdata->layer,
   77.99 +                                                DLSCL_ADMINISTRATIVE));
  77.100  
  77.101      /* Fill the window description. */
  77.102      if (window->x == SDL_WINDOWPOS_CENTERED) {
  77.103 @@ -725,8 +726,8 @@
  77.104      desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE / DSCAPS_PREMULTIPLIED;
  77.105  
  77.106      /* Create the window. */
  77.107 -    SDL_DFB_CHECKERR(dispdata->layer->
  77.108 -                     CreateWindow(dispdata->layer, &desc, &windata->window));
  77.109 +    SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
  77.110 +                                                   &windata->window));
  77.111  
  77.112      windata->window->GetOptions(windata->window, &wopts);
  77.113  #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
  77.114 @@ -744,12 +745,13 @@
  77.115  
  77.116      windata->window->SetOptions(windata->window, wopts);
  77.117      /* Get the window's surface. */
  77.118 -    SDL_DFB_CHECKERR(windata->window->
  77.119 -                     GetSurface(windata->window, &windata->surface));
  77.120 +    SDL_DFB_CHECKERR(windata->
  77.121 +                     window->GetSurface(windata->window, &windata->surface));
  77.122      windata->window->SetOpacity(windata->window, 0xFF);
  77.123 -    SDL_DFB_CHECKERR(windata->window->
  77.124 -                     CreateEventBuffer(windata->window,
  77.125 -                                       &(windata->eventbuffer)));
  77.126 +    SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
  77.127 +                                                        &
  77.128 +                                                        (windata->
  77.129 +                                                         eventbuffer)));
  77.130      SDL_DFB_CHECKERR(windata->window->
  77.131                       EnableEvents(windata->window,
  77.132                                    DWET_POSITION | DWET_SIZE | DWET_CLOSE |
  77.133 @@ -812,6 +814,7 @@
  77.134      //return -1;
  77.135  
  77.136  }
  77.137 +
  77.138  static void
  77.139  DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
  77.140  {
  77.141 @@ -886,6 +889,7 @@
  77.142      windata->window->SetOpacity(windata->window, 0);
  77.143  
  77.144  }
  77.145 +
  77.146  static void
  77.147  DirectFB_RaiseWindow(_THIS, SDL_Window * window)
  77.148  {
  77.149 @@ -907,6 +911,7 @@
  77.150      SDL_Unsupported();
  77.151  
  77.152  }
  77.153 +
  77.154  static void
  77.155  DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
  77.156  {
  77.157 @@ -928,6 +933,7 @@
  77.158      SDL_Unsupported();
  77.159  
  77.160  }
  77.161 +
  77.162  static void
  77.163  DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
  77.164  {
  77.165 @@ -1156,8 +1162,8 @@
  77.166          devdata->glFlush();
  77.167  
  77.168      SDL_DFB_CHECKERR(windata->gl_context->Unlock(windata->gl_context));
  77.169 -    SDL_DFB_CHECKERR(windata->surface->
  77.170 -                     Flip(windata->surface, &region, DSFLIP_ONSYNC));
  77.171 +    SDL_DFB_CHECKERR(windata->
  77.172 +                     surface->Flip(windata->surface, &region, DSFLIP_ONSYNC));
  77.173      SDL_DFB_CHECKERR(windata->gl_context->Lock(windata->gl_context));
  77.174  
  77.175      return;
    78.1 --- a/src/video/fbcon/SDL_fb3dfx.c	Wed Aug 27 13:37:19 2008 +0000
    78.2 +++ b/src/video/fbcon/SDL_fb3dfx.c	Wed Aug 27 15:10:03 2008 +0000
    78.3 @@ -37,6 +37,7 @@
    78.4      /* wait until we're past the start */
    78.5      while ((tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0);
    78.6  }
    78.7 +
    78.8  static void
    78.9  WaitIdle(_THIS)
   78.10  {
    79.1 --- a/src/video/fbcon/SDL_fbelo.c	Wed Aug 27 13:37:19 2008 +0000
    79.2 +++ b/src/video/fbcon/SDL_fbelo.c	Wed Aug 27 15:10:03 2008 +0000
    79.3 @@ -268,8 +268,7 @@
    79.4          if (result == 0) {
    79.5              i--;
    79.6          }
    79.7 -    }
    79.8 -    while (!ok && (i > 0));
    79.9 +    } while (!ok && (i > 0));
   79.10  
   79.11      return ok;
   79.12  }
    80.1 --- a/src/video/fbcon/SDL_fbevents.c	Wed Aug 27 13:37:19 2008 +0000
    80.2 +++ b/src/video/fbcon/SDL_fbevents.c	Wed Aug 27 15:10:03 2008 +0000
    80.3 @@ -545,9 +545,8 @@
    80.4                  if (select(fd + 1, &fdset, 0, 0, &tv) < 1) {
    80.5                      break;
    80.6                  }
    80.7 -            }
    80.8 -            while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) &&
    80.9 -                   ((ch == 0xFA) || (ch == 0xAA)));
   80.10 +            } while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) &&
   80.11 +                     ((ch == 0xFA) || (ch == 0xAA)));
   80.12  
   80.13              /* Experimental values (Logitech wheelmouse) */
   80.14  #ifdef DEBUG_MOUSE
   80.15 @@ -970,6 +969,7 @@
   80.16      ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
   80.17      ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
   80.18  }
   80.19 +
   80.20  static void
   80.21  switch_vt_done(_THIS)
   80.22  {
   80.23 @@ -995,6 +995,7 @@
   80.24                           (SDL_APPACTIVE | SDL_APPINPUTFOCUS |
   80.25                            SDL_APPMOUSEFOCUS));
   80.26  }
   80.27 +
   80.28  static void
   80.29  switch_vt(_THIS, unsigned short which)
   80.30  {
   80.31 @@ -1113,8 +1114,7 @@
   80.32                  }
   80.33              }
   80.34          }
   80.35 -    }
   80.36 -    while (posted);
   80.37 +    } while (posted);
   80.38  }
   80.39  
   80.40  void
    81.1 --- a/src/video/fbcon/SDL_fbmatrox.c	Wed Aug 27 13:37:19 2008 +0000
    81.2 +++ b/src/video/fbcon/SDL_fbmatrox.c	Wed Aug 27 15:10:03 2008 +0000
    81.3 @@ -41,6 +41,7 @@
    81.4      count = mga_in32(0x1E20) + 2;
    81.5      while (mga_in32(0x1E20) < count);
    81.6  }
    81.7 +
    81.8  static void
    81.9  WaitIdle(_THIS)
   81.10  {
    82.1 --- a/src/video/fbcon/SDL_fbriva.c	Wed Aug 27 13:37:19 2008 +0000
    82.2 +++ b/src/video/fbcon/SDL_fbriva.c	Wed Aug 27 15:10:03 2008 +0000
    82.3 @@ -40,6 +40,7 @@
    82.4      while ((*port & 0x08));
    82.5      while (!(*port & 0x08));
    82.6  }
    82.7 +
    82.8  static void
    82.9  NV3WaitIdle(_THIS)
   82.10  {
   82.11 @@ -47,6 +48,7 @@
   82.12      while ((Rop->FifoFree < FifoEmptyCount) ||
   82.13             (*(mapped_io + PGRAPH_OFFSET + 0x000006B0) & 0x01));
   82.14  }
   82.15 +
   82.16  static void
   82.17  NV4WaitIdle(_THIS)
   82.18  {
    83.1 --- a/src/video/fbcon/SDL_fbvideo.c	Wed Aug 27 13:37:19 2008 +0000
    83.2 +++ b/src/video/fbcon/SDL_fbvideo.c	Wed Aug 27 15:10:03 2008 +0000
    83.3 @@ -82,6 +82,7 @@
    83.4      {0, 0, 320, 240},
    83.5      {0, 0, 320, 200}
    83.6  };
    83.7 +
    83.8  static const struct
    83.9  {
   83.10      int xres;
   83.11 @@ -323,15 +324,13 @@
   83.12              blank = 1;
   83.13          else
   83.14              blank = 0;
   83.15 -    }
   83.16 -    while (blank);
   83.17 +    } while (blank);
   83.18      /* remove whitespace at the begining of the string */
   83.19      i = 0;
   83.20      do {
   83.21          line[i] = c[i];
   83.22          i++;
   83.23 -    }
   83.24 -    while (c[i] != 0);
   83.25 +    } while (c[i] != 0);
   83.26      return 1;
   83.27  }
   83.28  
   83.29 @@ -347,8 +346,7 @@
   83.30              return 0;
   83.31          if (SDL_strncmp(line, "geometry", 8) == 0)
   83.32              break;
   83.33 -    }
   83.34 -    while (1);
   83.35 +    } while (1);
   83.36  
   83.37      SDL_sscanf(line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres,
   83.38                 &vinfo->xres_virtual, &vinfo->yres_virtual,
   83.39 @@ -394,8 +392,7 @@
   83.40              if (SDL_strncmp(option, "true", 4) == 0)
   83.41                  vinfo->vmode |= FB_VMODE_DOUBLE;
   83.42          }
   83.43 -    }
   83.44 -    while (SDL_strncmp(line, "endmode", 7) != 0);
   83.45 +    } while (SDL_strncmp(line, "endmode", 7) != 0);
   83.46  
   83.47      return 1;
   83.48  }
   83.49 @@ -826,6 +823,7 @@
   83.50      fprintf(stderr, "\talpha: %d/%d\n", vinfo->transp.length,
   83.51              vinfo->transp.offset);
   83.52  }
   83.53 +
   83.54  static void
   83.55  print_finfo(struct fb_fix_screeninfo *finfo)
   83.56  {
   83.57 @@ -1193,6 +1191,7 @@
   83.58      screen->hwdata = (struct private_hwdata *) &surfaces;
   83.59      return (0);
   83.60  }
   83.61 +
   83.62  static void
   83.63  FB_FreeHWSurfaces(_THIS)
   83.64  {
   83.65 @@ -1283,6 +1282,7 @@
   83.66      surface->hwdata = (struct private_hwdata *) bucket;
   83.67      return (0);
   83.68  }
   83.69 +
   83.70  static void
   83.71  FB_FreeHWSurface(_THIS, SDL_Surface * surface)
   83.72  {
   83.73 @@ -1352,6 +1352,7 @@
   83.74      }
   83.75      return (0);
   83.76  }
   83.77 +
   83.78  static void
   83.79  FB_UnlockHWSurface(_THIS, SDL_Surface * surface)
   83.80  {
    84.1 --- a/src/video/gapi/SDL_gapivideo.c	Wed Aug 27 13:37:19 2008 +0000
    84.2 +++ b/src/video/gapi/SDL_gapivideo.c	Wed Aug 27 15:10:03 2008 +0000
    84.3 @@ -340,8 +340,7 @@
    84.4                                                              gx.GXSuspend,
    84.5                                                              "?GXSuspend@@YAHXZ")
    84.6          LINK(GXResume, gx.GXResume, "?GXResume@@YAHXZ") LINK(GXSetViewport,
    84.7 -                                                             gx.
    84.8 -                                                             GXSetViewport,
    84.9 +                                                             gx.GXSetViewport,
   84.10                                                               "?GXSetViewport@@YAHKKKK@Z")
   84.11          LINK(GXIsDisplayDRAMBuffer, gx.GXIsDisplayDRAMBuffer,
   84.12               "?GXIsDisplayDRAMBuffer@@YAHXZ")
   84.13 @@ -807,6 +806,7 @@
   84.14  {
   84.15      return (-1);
   84.16  }
   84.17 +
   84.18  static void
   84.19  GAPI_FreeHWSurface(_THIS, SDL_Surface * surface)
   84.20  {
    85.1 --- a/src/video/ipod/SDL_ipodvideo.c	Wed Aug 27 13:37:19 2008 +0000
    85.2 +++ b/src/video/ipod/SDL_ipodvideo.c	Wed Aug 27 15:10:03 2008 +0000
    85.3 @@ -526,8 +526,7 @@
    85.4          }
    85.5          if (dbgout)
    85.6              fprintf(dbgout, "\n");
    85.7 -    }
    85.8 -    while (posted);
    85.9 +    } while (posted);
   85.10  }
   85.11  
   85.12  // enough space for 160x128x2
   85.13 @@ -570,8 +569,7 @@
   85.14          do {
   85.15              if ((inl(lcd_base) & (unsigned int) 0x8000) == 0)
   85.16                  break;
   85.17 -        }
   85.18 -        while (M_timer_check(start, 1000) == 0);
   85.19 +        } while (M_timer_check(start, 1000) == 0);
   85.20      }
   85.21  }
   85.22  
   85.23 @@ -681,10 +679,10 @@
   85.24          do {
   85.25              if ((inl(0x70008A0C) & 0x80000000) == 0)
   85.26                  break;
   85.27 -        }
   85.28 -        while (C_timer_check(start, 1000) == 0);
   85.29 +        } while (C_timer_check(start, 1000) == 0);
   85.30      }
   85.31  }
   85.32 +
   85.33  static void
   85.34  C_lcd_cmd_data(int cmd, int data)
   85.35  {
   85.36 @@ -780,10 +778,12 @@
   85.37                      ipod_scr[y * (lcd_width / 4) + x / 4] |=
   85.38                          (((Uint8 *) (SDL_VideoSurface->pixels))[y *
   85.39                                                                  SDL_VideoSurface->
   85.40 -                                                                pitch
   85.41 -                                                                +
   85.42 -                                                                x] &
   85.43 -                         3) << (2 * (x % 4));
   85.44 +                                                                pitch +
   85.45 +                                                                x] & 3) << (2
   85.46 +                                                                            *
   85.47 +                                                                            (x
   85.48 +                                                                             %
   85.49 +                                                                             4));
   85.50                  }
   85.51              }
   85.52          }
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/src/video/nds/SDL_ndsevents.c	Wed Aug 27 15:10:03 2008 +0000
    86.3 @@ -0,0 +1,54 @@
    86.4 +/*
    86.5 +    SDL - Simple DirectMedia Layer
    86.6 +    Copyright (C) 1997-2006 Sam Lantinga
    86.7 +
    86.8 +    This library is free software; you can redistribute it and/or
    86.9 +    modify it under the terms of the GNU Lesser General Public
   86.10 +    License as published by the Free Software Foundation; either
   86.11 +    version 2.1 of the License, or (at your option) any later version.
   86.12 +
   86.13 +    This library is distributed in the hope that it will be useful,
   86.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   86.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   86.16 +    Lesser General Public License for more details.
   86.17 +
   86.18 +    You should have received a copy of the GNU Lesser General Public
   86.19 +    License along with this library; if not, write to the Free Software
   86.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   86.21 +
   86.22 +    Sam Lantinga
   86.23 +    slouken@libsdl.org
   86.24 +*/
   86.25 +#include "SDL_config.h"
   86.26 +
   86.27 +/* Being a null driver, there's no event stream. We just define stubs for
   86.28 +   most of the API. */
   86.29 +
   86.30 +#include <stdio.h>
   86.31 +#include <stdlib.h>
   86.32 +#include <nds.h>
   86.33 +
   86.34 +#include "SDL.h"
   86.35 +#include "../../events/SDL_sysevents.h"
   86.36 +#include "../../events/SDL_events_c.h"
   86.37 +
   86.38 +#include "SDL_ndsvideo.h"
   86.39 +#include "SDL_ndsevents_c.h"
   86.40 +
   86.41 +void
   86.42 +NDS_PumpEvents(_THIS)
   86.43 +{
   86.44 +    scanKeys();
   86.45 +    /* TODO: defer click-age */
   86.46 +    if (keysDown() & KEY_TOUCH) {
   86.47 +        SDL_SendMouseButton(0, SDL_PRESSED, 0);
   86.48 +    } else if (keysUp() & KEY_TOUCH) {
   86.49 +        SDL_SendMouseButton(0, SDL_RELEASED, 0);
   86.50 +    }
   86.51 +    if (keysHeld() & KEY_TOUCH) {
   86.52 +        touchPosition t = touchReadXY();
   86.53 +        SDL_SendMouseMotion(0, 0, t.px, t.py);
   86.54 +    }
   86.55 +}
   86.56 +
   86.57 +/* vi: set ts=4 sw=4 expandtab: */
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/src/video/nds/SDL_ndsevents_c.h	Wed Aug 27 15:10:03 2008 +0000
    87.3 @@ -0,0 +1,28 @@
    87.4 +/*
    87.5 +    SDL - Simple DirectMedia Layer
    87.6 +    Copyright (C) 1997-2006 Sam Lantinga
    87.7 +
    87.8 +    This library is free software; you can redistribute it and/or
    87.9 +    modify it under the terms of the GNU Lesser General Public
   87.10 +    License as published by the Free Software Foundation; either
   87.11 +    version 2.1 of the License, or (at your option) any later version.
   87.12 +
   87.13 +    This library is distributed in the hope that it will be useful,
   87.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   87.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   87.16 +    Lesser General Public License for more details.
   87.17 +
   87.18 +    You should have received a copy of the GNU Lesser General Public
   87.19 +    License along with this library; if not, write to the Free Software
   87.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   87.21 +
   87.22 +    Sam Lantinga
   87.23 +    slouken@libsdl.org
   87.24 +*/
   87.25 +#include "SDL_config.h"
   87.26 +
   87.27 +#include "SDL_ndsvideo.h"
   87.28 +
   87.29 +extern void NDS_PumpEvents(_THIS);
   87.30 +
   87.31 +/* vi: set ts=4 sw=4 expandtab: */
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/src/video/nds/SDL_ndsrender.c	Wed Aug 27 15:10:03 2008 +0000
    88.3 @@ -0,0 +1,660 @@
    88.4 +/*
    88.5 +    SDL - Simple DirectMedia Layer
    88.6 +    Copyright (C) 1997-2006 Sam Lantinga
    88.7 +
    88.8 +    This library is free software; you can redistribute it and/or
    88.9 +    modify it under the terms of the GNU Lesser General Public
   88.10 +    License as published by the Free Software Foundation; either
   88.11 +    version 2.1 of the License, or (at your option) any later version.
   88.12 +
   88.13 +    This library is distributed in the hope that it will be useful,
   88.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   88.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   88.16 +    Lesser General Public License for more details.
   88.17 +
   88.18 +    You should have received a copy of the GNU Lesser General Public
   88.19 +    License along with this library; if not, write to the Free Software
   88.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   88.21 +
   88.22 +    Sam Lantinga
   88.23 +    slouken@libsdl.org
   88.24 +*/
   88.25 +
   88.26 +#include <stdio.h>
   88.27 +#include <stdlib.h>
   88.28 +#include <nds.h>
   88.29 +#include <nds/arm9/video.h>
   88.30 +#include <nds/arm9/sprite.h>
   88.31 +#include <nds/arm9/trig_lut.h>
   88.32 +
   88.33 +#include "SDL_config.h"
   88.34 +
   88.35 +#include "SDL_video.h"
   88.36 +#include "../SDL_sysvideo.h"
   88.37 +#include "../SDL_yuv_sw_c.h"
   88.38 +#include "../SDL_renderer_sw.h"
   88.39 +
   88.40 +/* NDS sprite-related functions */
   88.41 +#define SPRITE_DMA_CHANNEL 3
   88.42 +#define SPRITE_ANGLE_MASK 0x01FF
   88.43 +
   88.44 +void
   88.45 +NDS_OAM_Update(tOAM * oam, int sub)
   88.46 +{
   88.47 +    DC_FlushAll();
   88.48 +    dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer,
   88.49 +                     sub ? OAM_SUB : OAM, SPRITE_COUNT * sizeof(SpriteEntry));
   88.50 +}
   88.51 +
   88.52 +void
   88.53 +NDS_OAM_RotateSprite(SpriteRotation * spriteRotation, u16 angle)
   88.54 +{
   88.55 +    s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4;
   88.56 +    s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4;
   88.57 +
   88.58 +    spriteRotation->hdx = c;
   88.59 +    spriteRotation->hdy = s;
   88.60 +    spriteRotation->vdx = -s;
   88.61 +    spriteRotation->vdy = c;
   88.62 +}
   88.63 +
   88.64 +void
   88.65 +NDS_OAM_Init(tOAM * oam, int sub)
   88.66 +{
   88.67 +    int i;
   88.68 +    for (i = 0; i < SPRITE_COUNT; i++) {
   88.69 +        oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED;
   88.70 +        oam->spriteBuffer[i].attribute[1] = 0;
   88.71 +        oam->spriteBuffer[i].attribute[2] = 0;
   88.72 +    }
   88.73 +    for (i = 0; i < MATRIX_COUNT; i++) {
   88.74 +        NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0);
   88.75 +    }
   88.76 +    swiWaitForVBlank();
   88.77 +    NDS_OAM_Update(oam, sub);
   88.78 +}
   88.79 +
   88.80 +void
   88.81 +NDS_OAM_HideSprite(SpriteEntry * spriteEntry)
   88.82 +{
   88.83 +    spriteEntry->isRotoscale = 0;
   88.84 +    spriteEntry->isHidden = 1;
   88.85 +}
   88.86 +
   88.87 +void
   88.88 +NDS_OAM_ShowSprite(SpriteEntry * spriteEntry, int affine, int double_bound)
   88.89 +{
   88.90 +    if (affine) {
   88.91 +        spriteEntry->isRotoscale = 1;
   88.92 +        spriteEntry->rsDouble = double_bound;
   88.93 +    } else {
   88.94 +        spriteEntry->isHidden = 0;
   88.95 +    }
   88.96 +}
   88.97 +
   88.98 +
   88.99 +/* SDL NDS renderer implementation */
  88.100 +
  88.101 +static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags);
  88.102 +static int NDS_ActivateRenderer(SDL_Renderer * renderer);
  88.103 +static int NDS_DisplayModeChanged(SDL_Renderer * renderer);
  88.104 +static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
  88.105 +static int NDS_QueryTexturePixels(SDL_Renderer * renderer,
  88.106 +                                  SDL_Texture * texture, void **pixels,
  88.107 +                                  int *pitch);
  88.108 +static int NDS_SetTexturePalette(SDL_Renderer * renderer,
  88.109 +                                 SDL_Texture * texture,
  88.110 +                                 const SDL_Color * colors, int firstcolor,
  88.111 +                                 int ncolors);
  88.112 +static int NDS_GetTexturePalette(SDL_Renderer * renderer,
  88.113 +                                 SDL_Texture * texture, SDL_Color * colors,
  88.114 +                                 int firstcolor, int ncolors);
  88.115 +static int NDS_SetTextureColorMod(SDL_Renderer * renderer,
  88.116 +                                  SDL_Texture * texture);
  88.117 +static int NDS_SetTextureAlphaMod(SDL_Renderer * renderer,
  88.118 +                                  SDL_Texture * texture);
  88.119 +static int NDS_SetTextureBlendMode(SDL_Renderer * renderer,
  88.120 +                                   SDL_Texture * texture);
  88.121 +static int NDS_SetTextureScaleMode(SDL_Renderer * renderer,
  88.122 +                                   SDL_Texture * texture);
  88.123 +static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  88.124 +                             const SDL_Rect * rect, const void *pixels,
  88.125 +                             int pitch);
  88.126 +static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  88.127 +                           const SDL_Rect * rect, int markDirty,
  88.128 +                           void **pixels, int *pitch);
  88.129 +static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
  88.130 +static void NDS_DirtyTexture(SDL_Renderer * renderer,
  88.131 +                             SDL_Texture * texture, int numrects,
  88.132 +                             const SDL_Rect * rects);
  88.133 +static int NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
  88.134 +                          Uint8 b, Uint8 a, const SDL_Rect * rect);
  88.135 +static int NDS_RenderCopy(SDL_Renderer * renderer,
  88.136 +                          SDL_Texture * texture,
  88.137 +                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
  88.138 +static void NDS_RenderPresent(SDL_Renderer * renderer);
  88.139 +static void NDS_DestroyTexture(SDL_Renderer * renderer,
  88.140 +                               SDL_Texture * texture);
  88.141 +static void NDS_DestroyRenderer(SDL_Renderer * renderer);
  88.142 +
  88.143 +
  88.144 +SDL_RenderDriver NDS_RenderDriver = {
  88.145 +    NDS_CreateRenderer,
  88.146 +    {"nds",                     /* char* name */
  88.147 +     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC),  /* u32 flags */
  88.148 +     (SDL_TEXTUREMODULATE_NONE),        /* u32 mod_modes */
  88.149 +     (SDL_TEXTUREBLENDMODE_MASK),       /* u32 blend_modes */
  88.150 +     (SDL_TEXTURESCALEMODE_FAST),       /* u32 scale_modes */
  88.151 +     3,                         /* u32 num_texture_formats */
  88.152 +     {
  88.153 +      SDL_PIXELFORMAT_INDEX8,
  88.154 +      SDL_PIXELFORMAT_ABGR1555,
  88.155 +      SDL_PIXELFORMAT_BGR555,
  88.156 +      },                        /* u32 texture_formats[20] */
  88.157 +     (256),                     /* int max_texture_width */
  88.158 +     (256),                     /* int max_texture_height */
  88.159 +     }
  88.160 +};
  88.161 +
  88.162 +typedef struct
  88.163 +{
  88.164 +    bg_attribute *bg;           /* backgrounds */
  88.165 +    tOAM oam_copy;              /* sprites */
  88.166 +    u8 bg_taken[4];
  88.167 +    int sub;
  88.168 +} NDS_RenderData;
  88.169 +
  88.170 +typedef struct
  88.171 +{
  88.172 +    enum
  88.173 +    { NDSTX_BG, NDSTX_SPR } type;       /* represented in a bg or sprite. */
  88.174 +    int hw_index;               /* sprite: index in the OAM. /  bg: 2 or 3. */
  88.175 +    struct
  88.176 +    {
  88.177 +        int hdx, hdy, vdx, vdy; /* affine transformation, used for scaling. */
  88.178 +        int pitch, bpp;         /* some useful info */
  88.179 +    } dim;
  88.180 +    u16 *vram_pixels;           /* where the pixel data is stored (a pointer into VRAM) */
  88.181 +    u16 *vram_palette;          /* where the palette data is stored if it's indexed. */
  88.182 +    /*int size; */
  88.183 +} NDS_TextureData;
  88.184 +
  88.185 +
  88.186 +
  88.187 +SDL_Renderer *
  88.188 +NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
  88.189 +{
  88.190 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
  88.191 +    SDL_DisplayMode *displayMode = &display->current_mode;
  88.192 +    SDL_Renderer *renderer;
  88.193 +    NDS_RenderData *data;
  88.194 +    int i, n;
  88.195 +    int bpp;
  88.196 +    Uint32 Rmask, Gmask, Bmask, Amask;
  88.197 +
  88.198 +    if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp,
  88.199 +                                    &Rmask, &Gmask, &Bmask, &Amask)) {
  88.200 +        SDL_SetError("Unknown display format");
  88.201 +        return NULL;
  88.202 +    }
  88.203 +    switch (displayMode->format) {
  88.204 +    case SDL_PIXELFORMAT_INDEX8:
  88.205 +    case SDL_PIXELFORMAT_ABGR1555:
  88.206 +    case SDL_PIXELFORMAT_BGR555:
  88.207 +        /* okay */
  88.208 +        break;
  88.209 +    case SDL_PIXELFORMAT_RGB555:
  88.210 +    case SDL_PIXELFORMAT_RGB565:
  88.211 +    case SDL_PIXELFORMAT_ARGB1555:
  88.212 +        /* we'll take these too for now */
  88.213 +        break;
  88.214 +    default:
  88.215 +        SDL_SetError("Warning: wrong display format for NDS!\n");
  88.216 +        break;
  88.217 +    }
  88.218 +
  88.219 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
  88.220 +    if (!renderer) {
  88.221 +        SDL_OutOfMemory();
  88.222 +        return NULL;
  88.223 +    }
  88.224 +
  88.225 +    data = (NDS_RenderData *) SDL_malloc(sizeof(*data));
  88.226 +    if (!data) {
  88.227 +        NDS_DestroyRenderer(renderer);
  88.228 +        SDL_OutOfMemory();
  88.229 +        return NULL;
  88.230 +    }
  88.231 +    SDL_zerop(data);
  88.232 +
  88.233 +    renderer->RenderFill = NDS_RenderFill;
  88.234 +    renderer->RenderCopy = NDS_RenderCopy;
  88.235 +    renderer->RenderPresent = NDS_RenderPresent;
  88.236 +    renderer->DestroyRenderer = NDS_DestroyRenderer;
  88.237 +    renderer->info.name = NDS_RenderDriver.info.name;
  88.238 +    renderer->info.flags = 0;
  88.239 +    renderer->window = window->id;
  88.240 +    renderer->driverdata = data;
  88.241 +    renderer->CreateTexture = NDS_CreateTexture;
  88.242 +    renderer->QueryTexturePixels = NDS_QueryTexturePixels;
  88.243 +    renderer->SetTexturePalette = NDS_SetTexturePalette;
  88.244 +    renderer->GetTexturePalette = NDS_GetTexturePalette;
  88.245 +    renderer->SetTextureColorMod = NDS_SetTextureColorMod;
  88.246 +    renderer->SetTextureAlphaMod = NDS_SetTextureAlphaMod;
  88.247 +    renderer->SetTextureBlendMode = NDS_SetTextureBlendMode;
  88.248 +    renderer->SetTextureScaleMode = NDS_SetTextureScaleMode;
  88.249 +    renderer->UpdateTexture = NDS_UpdateTexture;
  88.250 +    renderer->LockTexture = NDS_LockTexture;
  88.251 +    renderer->UnlockTexture = NDS_UnlockTexture;
  88.252 +    renderer->DirtyTexture = NDS_DirtyTexture;
  88.253 +    renderer->DestroyTexture = NDS_DestroyTexture;
  88.254 +
  88.255 +    renderer->info.mod_modes = NDS_RenderDriver.info.mod_modes;
  88.256 +    renderer->info.blend_modes = NDS_RenderDriver.info.blend_modes;
  88.257 +    renderer->info.scale_modes = NDS_RenderDriver.info.scale_modes;
  88.258 +    renderer->info.num_texture_formats =
  88.259 +        NDS_RenderDriver.info.num_texture_formats;
  88.260 +    SDL_memcpy(renderer->info.texture_formats,
  88.261 +               NDS_RenderDriver.info.texture_formats,
  88.262 +               sizeof(renderer->info.texture_formats));
  88.263 +    renderer->info.max_texture_width =
  88.264 +        NDS_RenderDriver.info.max_texture_width;
  88.265 +    renderer->info.max_texture_height =
  88.266 +        NDS_RenderDriver.info.max_texture_height;
  88.267 +
  88.268 +    data->sub = 0;              /* TODO: this is hard-coded to the "main" screen.
  88.269 +                                   figure out how to detect whether to set it to
  88.270 +                                   "sub" screen.  window->id, perhaps? */
  88.271 +    if (!data->sub) {
  88.272 +        data->bg = &BACKGROUND;
  88.273 +    } else {
  88.274 +        data->bg = &BACKGROUND_SUB;
  88.275 +    }
  88.276 +    data->bg_taken[2] = data->bg_taken[3] = 0;
  88.277 +
  88.278 +    NDS_OAM_Init(&(data->oam_copy), data->sub); /* init sprites. */
  88.279 +
  88.280 +    return renderer;
  88.281 +}
  88.282 +
  88.283 +static int
  88.284 +NDS_ActivateRenderer(SDL_Renderer * renderer)
  88.285 +{
  88.286 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  88.287 +
  88.288 +    return 0;
  88.289 +}
  88.290 +
  88.291 +static int
  88.292 +NDS_DisplayModeChanged(SDL_Renderer * renderer)
  88.293 +{
  88.294 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  88.295 +
  88.296 +    return 0;
  88.297 +}
  88.298 +
  88.299 +static int
  88.300 +NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  88.301 +{
  88.302 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  88.303 +    NDS_TextureData *txdat = NULL;
  88.304 +    int i;
  88.305 +    int bpp;
  88.306 +    Uint32 Rmask, Gmask, Bmask, Amask;
  88.307 +
  88.308 +    if (!SDL_PixelFormatEnumToMasks
  88.309 +        (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
  88.310 +        SDL_SetError("Unknown texture format");
  88.311 +        return -1;
  88.312 +    }
  88.313 +
  88.314 +    /* conditional statements on w/h to place it as bg/sprite
  88.315 +       depending on which one it fits. */
  88.316 +    if (texture->w <= 64 && texture->h <= 64) {
  88.317 +        int whichspr = -1;
  88.318 +        printf("Tried to make a sprite.\n");
  88.319 +        txdat->type = NDSTX_SPR;
  88.320 +        for (i = 0; i < SPRITE_COUNT; ++i) {
  88.321 +            if (data->oam_copy.spriteBuffer[i].attribute[0] & ATTR0_DISABLED) {
  88.322 +                whichspr = i;
  88.323 +                break;
  88.324 +            }
  88.325 +        }
  88.326 +        if (whichspr >= 0) {
  88.327 +            SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]);
  88.328 +            int maxside = texture->w > texture->h ? texture->w : texture->h;
  88.329 +            int pitch;
  88.330 +
  88.331 +            texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
  88.332 +            txdat = (NDS_TextureData *) texture->driverdata;
  88.333 +            if (!txdat) {
  88.334 +                SDL_OutOfMemory();
  88.335 +                return -1;
  88.336 +            }
  88.337 +
  88.338 +            sprent->objMode = OBJMODE_BITMAP;
  88.339 +            sprent->posX = 0;
  88.340 +            sprent->posY = 0;
  88.341 +            sprent->colMode = OBJCOLOR_16;      /* OBJCOLOR_256 for INDEX8 */
  88.342 +
  88.343 +            /* the first 32 sprites get transformation matrices.
  88.344 +               first come, first served */
  88.345 +            if (whichspr < MATRIX_COUNT) {
  88.346 +                sprent->isRotoscale = 1;
  88.347 +                sprent->rsMatrixIdx = whichspr;
  88.348 +            }
  88.349 +
  88.350 +            /* containing shape (square or 2:1 rectangles) */
  88.351 +            sprent->objShape = OBJSHAPE_SQUARE;
  88.352 +            if (texture->w / 2 >= texture->h) {
  88.353 +                sprent->objShape = OBJSHAPE_WIDE;
  88.354 +            } else if (texture->h / 2 >= texture->w) {
  88.355 +                sprent->objShape = OBJSHAPE_TALL;
  88.356 +            }
  88.357 +
  88.358 +            /* size in pixels */
  88.359 +            /* FIXME: "pitch" is hardcoded for 2bytes per pixel. */
  88.360 +            sprent->objSize = OBJSIZE_64;
  88.361 +            pitch = 128;
  88.362 +            if (maxside <= 8) {
  88.363 +                sprent->objSize = OBJSIZE_8;
  88.364 +                pitch = 16;
  88.365 +            } else if (maxside <= 16) {
  88.366 +                sprent->objSize = OBJSIZE_16;
  88.367 +                pitch = 32;
  88.368 +            } else if (maxside <= 32) {
  88.369 +                sprent->objSize = OBJSIZE_32;
  88.370 +                pitch = 64;
  88.371 +            }
  88.372 +
  88.373 +            /* FIXME: this is hard-coded and will obviously only work for one
  88.374 +               sprite-texture.  tells it to look at the beginning of SPRITE_GFX
  88.375 +               for its pixels. */
  88.376 +            sprent->tileIdx = 0;
  88.377 +
  88.378 +            /* now for the texture data */
  88.379 +            txdat->type = NDSTX_SPR;
  88.380 +            txdat->hw_index = whichspr;
  88.381 +            txdat->dim.hdx = 0x100;
  88.382 +            txdat->dim.hdy = 0;
  88.383 +            txdat->dim.vdx = 0;
  88.384 +            txdat->dim.vdy = 0x100;
  88.385 +            txdat->dim.pitch = pitch;
  88.386 +            txdat->dim.bpp = bpp;
  88.387 +            txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);     /* FIXME: use tileIdx*boundary
  88.388 +                                                                                           to point to proper location */
  88.389 +        } else {
  88.390 +            SDL_SetError("Out of NDS sprites.");
  88.391 +        }
  88.392 +    } else if (texture->w <= 256 && texture->h <= 256) {
  88.393 +        int whichbg = -1, base = 0;
  88.394 +        if (!data->bg_taken[2]) {
  88.395 +            whichbg = 2;
  88.396 +        } else if (!data->bg_taken[3]) {
  88.397 +            whichbg = 3;
  88.398 +            base = 4;
  88.399 +        }
  88.400 +        if (whichbg >= 0) {
  88.401 +            texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
  88.402 +            txdat = (NDS_TextureData *) texture->driverdata;
  88.403 +            if (!txdat) {
  88.404 +                SDL_OutOfMemory();
  88.405 +                return -1;
  88.406 +            }
  88.407 +
  88.408 +            /* this is hard-coded to being 256x256 ABGR1555 for now. */
  88.409 +            data->bg->control[whichbg] = (bpp == 8) ?
  88.410 +                BG_BMP8_256x256 : BG_BMP16_256x256;
  88.411 +
  88.412 +            data->bg->control[whichbg] |= BG_BMP_BASE(base);
  88.413 +
  88.414 +            data->bg->scroll[whichbg].x = 0;
  88.415 +            data->bg->scroll[whichbg].y = 0;
  88.416 +
  88.417 +            txdat->type = NDSTX_BG;
  88.418 +            txdat->hw_index = whichbg;
  88.419 +            txdat->dim.hdx = 0x100;
  88.420 +            txdat->dim.hdy = 0;
  88.421 +            txdat->dim.vdx = 0;
  88.422 +            txdat->dim.vdy = 0x100;
  88.423 +            txdat->dim.pitch = 512;
  88.424 +            txdat->dim.bpp = bpp;
  88.425 +            txdat->vram_pixels = (u16 *) (data->sub ?
  88.426 +                                          BG_BMP_RAM_SUB(base) :
  88.427 +                                          BG_BMP_RAM(base));
  88.428 +
  88.429 +            /*txdat->size = txdat->dim.pitch * texture->h; */
  88.430 +        } else {
  88.431 +            SDL_SetError("Out of NDS backgrounds.");
  88.432 +        }
  88.433 +    } else {
  88.434 +        SDL_SetError("Texture too big for NDS hardware.");
  88.435 +    }
  88.436 +
  88.437 +    if (!texture->driverdata) {
  88.438 +        return -1;
  88.439 +    }
  88.440 +
  88.441 +    return 0;
  88.442 +}
  88.443 +
  88.444 +static int
  88.445 +NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  88.446 +                       void **pixels, int *pitch)
  88.447 +{
  88.448 +    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  88.449 +    *pixels = txdat->vram_pixels;
  88.450 +    *pitch = txdat->dim.pitch;
  88.451 +    return 0;
  88.452 +}
  88.453 +
  88.454 +static int
  88.455 +NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  88.456 +                  const SDL_Rect * rect, const void *pixels, int pitch)
  88.457 +{
  88.458 +    NDS_TextureData *txdat;
  88.459 +    Uint8 *src, *dst;
  88.460 +    int row;
  88.461 +    size_t length;
  88.462 +
  88.463 +    txdat = (NDS_TextureData *) texture->driverdata;
  88.464 +
  88.465 +    src = (Uint8 *) pixels;
  88.466 +    dst =
  88.467 +        (Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch +
  88.468 +        rect->x * ((txdat->dim.bpp + 1) / 8);
  88.469 +    length = rect->w * ((txdat->dim.bpp + 1) / 8);
  88.470 +
  88.471 +    if (rect->w == texture->w) {
  88.472 +        dmaCopy(src, dst, length * rect->h);
  88.473 +    } else {
  88.474 +        for (row = 0; row < rect->h; ++row) {
  88.475 +            dmaCopy(src, dst, length);
  88.476 +            src += pitch;
  88.477 +            dst += txdat->dim.pitch;
  88.478 +        }
  88.479 +    }
  88.480 +
  88.481 +    return 0;
  88.482 +}
  88.483 +
  88.484 +static int
  88.485 +NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  88.486 +                const SDL_Rect * rect, int markDirty, void **pixels,
  88.487 +                int *pitch)
  88.488 +{
  88.489 +    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  88.490 +
  88.491 +    *pixels = (void *) ((u8 *) txdat->vram_pixels + rect->y
  88.492 +                        * txdat->dim.pitch +
  88.493 +                        rect->x * ((txdat->dim.bpp + 1) / 8));
  88.494 +    *pitch = txdat->dim.pitch;
  88.495 +
  88.496 +    return 0;
  88.497 +}
  88.498 +
  88.499 +static void
  88.500 +NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  88.501 +{
  88.502 +    /* stub! */
  88.503 +}
  88.504 +
  88.505 +static void
  88.506 +NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  88.507 +                 int numrects, const SDL_Rect * rects)
  88.508 +{
  88.509 +    /* stub! */
  88.510 +}
  88.511 +
  88.512 +static int
  88.513 +NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
  88.514 +               Uint8 a, const SDL_Rect * rect)
  88.515 +{
  88.516 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  88.517 +    SDL_Rect real_rect = *rect;
  88.518 +    u16 color;
  88.519 +    int i, j;
  88.520 +
  88.521 +    color = RGB8(r, g, b);      /* <-- macro in libnds that makes an ARGB1555 pixel */
  88.522 +    /* TODO: make a single-color sprite and stretch it.
  88.523 +       calculate the "HDX" width modifier of the sprite by:
  88.524 +       let S be the actual sprite's width (like, 32 pixels for example)
  88.525 +       let R be the rectangle's width (maybe 50 pixels)
  88.526 +       HDX = (R<<8) / S;
  88.527 +       (it's fixed point, hence the bit shift.  same goes for vertical.
  88.528 +       be sure to use 32-bit int's for the bit shift before the division!)
  88.529 +     */
  88.530 +
  88.531 +    return 0;
  88.532 +}
  88.533 +
  88.534 +static int
  88.535 +NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  88.536 +               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  88.537 +{
  88.538 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  88.539 +    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  88.540 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
  88.541 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
  88.542 +    int i;
  88.543 +    int bpp = SDL_BYTESPERPIXEL(texture->format);
  88.544 +    int pitch = txdat->dim.pitch;
  88.545 +
  88.546 +    if (txdat->type == NDSTX_BG) {
  88.547 +        bg_rotation *bgrot = (txdat->hw_index == 2) ?
  88.548 +            &(data->bg->bg2_rotation) : &(data->bg->bg3_rotation);
  88.549 +        bgrot->xdx = txdat->dim.hdx;
  88.550 +        bgrot->xdy = txdat->dim.hdy;
  88.551 +        bgrot->ydx = txdat->dim.vdx;
  88.552 +        bgrot->ydy = txdat->dim.vdy;
  88.553 +        bgrot->centerX = 0;
  88.554 +        bgrot->centerY = 0;
  88.555 +
  88.556 +        data->bg->scroll[txdat->hw_index].x = dstrect->x;
  88.557 +        data->bg->scroll[txdat->hw_index].y = dstrect->y;
  88.558 +    } else {
  88.559 +        /* sprites not fully implemented yet */
  88.560 +        SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
  88.561 +        spr->posX = dstrect->x;
  88.562 +        spr->posY = dstrect->y;
  88.563 +        if (txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) {
  88.564 +            SpriteRotation *sprot =
  88.565 +                &(data->oam_copy.matrixBuffer[txdat->hw_index]);
  88.566 +            sprot->hdx = txdat->dim.hdx;
  88.567 +            sprot->hdy = txdat->dim.hdy;
  88.568 +            sprot->vdx = txdat->dim.vdx;
  88.569 +            sprot->vdy = txdat->dim.vdy;
  88.570 +        }
  88.571 +    }
  88.572 +
  88.573 +    return 0;
  88.574 +}
  88.575 +
  88.576 +
  88.577 +static void
  88.578 +NDS_RenderPresent(SDL_Renderer * renderer)
  88.579 +{
  88.580 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  88.581 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
  88.582 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
  88.583 +
  88.584 +    /* update sprites */
  88.585 +    NDS_OAM_Update(&(data->oam_copy), data->sub);
  88.586 +    /* vsync for NDS */
  88.587 +    if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
  88.588 +        swiWaitForVBlank();
  88.589 +    }
  88.590 +}
  88.591 +
  88.592 +static void
  88.593 +NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  88.594 +{
  88.595 +    NDS_TextureData *txdat = texture->driverdata;
  88.596 +    /* free anything else allocated for texture */
  88.597 +    SDL_free(txdat);
  88.598 +}
  88.599 +
  88.600 +static void
  88.601 +NDS_DestroyRenderer(SDL_Renderer * renderer)
  88.602 +{
  88.603 +    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
  88.604 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
  88.605 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
  88.606 +    int i;
  88.607 +
  88.608 +    if (data) {
  88.609 +        /* free anything else relevant if anything else is allocated. */
  88.610 +        SDL_free(data);
  88.611 +    }
  88.612 +    SDL_free(renderer);
  88.613 +}
  88.614 +
  88.615 +static int
  88.616 +NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
  88.617 +                      const SDL_Color * colors, int firstcolor, int ncolors)
  88.618 +{
  88.619 +    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  88.620 +    /* set 8-bit modes in the background control registers
  88.621 +       for backgrounds, BGn_CR |= BG_256_COLOR */
  88.622 +
  88.623 +    return 0;
  88.624 +}
  88.625 +
  88.626 +static int
  88.627 +NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
  88.628 +                      SDL_Color * colors, int firstcolor, int ncolors)
  88.629 +{
  88.630 +    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
  88.631 +    /* stub! */
  88.632 +    return 0;
  88.633 +}
  88.634 +
  88.635 +static int
  88.636 +NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
  88.637 +{
  88.638 +    /* stub! */
  88.639 +    return 0;
  88.640 +}
  88.641 +
  88.642 +static int
  88.643 +NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
  88.644 +{
  88.645 +    /* stub! */
  88.646 +    return 0;
  88.647 +}
  88.648 +
  88.649 +static int
  88.650 +NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
  88.651 +{
  88.652 +    /* stub! */
  88.653 +    return 0;
  88.654 +}
  88.655 +
  88.656 +static int
  88.657 +NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
  88.658 +{
  88.659 +    /* stub! (note: NDS hardware scaling is nearest neighbor.) */
  88.660 +    return 0;
  88.661 +}
  88.662 +
  88.663 +/* vi: set ts=4 sw=4 expandtab: */
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/src/video/nds/SDL_ndsrender_c.h	Wed Aug 27 15:10:03 2008 +0000
    89.3 @@ -0,0 +1,28 @@
    89.4 +/*
    89.5 +    SDL - Simple DirectMedia Layer
    89.6 +    Copyright (C) 1997-2006 Sam Lantinga
    89.7 +
    89.8 +    This library is free software; you can redistribute it and/or
    89.9 +    modify it under the terms of the GNU Lesser General Public
   89.10 +    License as published by the Free Software Foundation; either
   89.11 +    version 2.1 of the License, or (at your option) any later version.
   89.12 +
   89.13 +    This library is distributed in the hope that it will be useful,
   89.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   89.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   89.16 +    Lesser General Public License for more details.
   89.17 +
   89.18 +    You should have received a copy of the GNU Lesser General Public
   89.19 +    License along with this library; if not, write to the Free Software
   89.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   89.21 +
   89.22 +    Sam Lantinga
   89.23 +    slouken@libsdl.org
   89.24 +*/
   89.25 +#include "SDL_config.h"
   89.26 +
   89.27 +/* SDL surface based renderer implementation */
   89.28 +
   89.29 +extern SDL_RenderDriver NDS_RenderDriver;
   89.30 +
   89.31 +/* vi: set ts=4 sw=4 expandtab: */
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/src/video/nds/SDL_ndsvideo.c	Wed Aug 27 15:10:03 2008 +0000
    90.3 @@ -0,0 +1,168 @@
    90.4 +/*
    90.5 +    SDL - Simple DirectMedia Layer
    90.6 +    Copyright (C) 1997-2006 Sam Lantinga
    90.7 +
    90.8 +    This library is free software; you can redistribute it and/or
    90.9 +    modify it under the terms of the GNU Lesser General Public
   90.10 +    License as published by the Free Software Foundation; either
   90.11 +    version 2.1 of the License, or (at your option) any later version.
   90.12 +
   90.13 +    This library is distributed in the hope that it will be useful,
   90.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   90.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   90.16 +    Lesser General Public License for more details.
   90.17 +
   90.18 +    You should have received a copy of the GNU Lesser General Public
   90.19 +    License along with this library; if not, write to the Free Software
   90.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   90.21 +
   90.22 +    Sam Lantinga
   90.23 +    slouken@libsdl.org
   90.24 +*/
   90.25 +#include "SDL_config.h"
   90.26 +
   90.27 +/* SDL Nintendo DS video driver implementation
   90.28 + * based on dummy driver:
   90.29 + *  Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
   90.30 + *  of this was cut-and-pasted from Stephane Peter's work in the AAlib
   90.31 + *  SDL video driver.  Renamed to "DUMMY" by Sam Lantinga.
   90.32 + */
   90.33 +
   90.34 +#include <stdio.h>
   90.35 +#include <stdlib.h>
   90.36 +#include <nds.h>
   90.37 +#include <nds/arm9/video.h>
   90.38 +
   90.39 +#include "SDL_video.h"
   90.40 +#include "SDL_mouse.h"
   90.41 +#include "../SDL_sysvideo.h"
   90.42 +#include "../SDL_pixels_c.h"
   90.43 +#include "../../events/SDL_events_c.h"
   90.44 +
   90.45 +#include "SDL_ndsvideo.h"
   90.46 +#include "SDL_ndsevents_c.h"
   90.47 +#include "SDL_ndsrender_c.h"
   90.48 +
   90.49 +#define NDSVID_DRIVER_NAME "nds"
   90.50 +
   90.51 +/* Initialization/Query functions */
   90.52 +static int NDS_VideoInit(_THIS);
   90.53 +static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
   90.54 +static void NDS_VideoQuit(_THIS);
   90.55 +
   90.56 +
   90.57 +/* SDL NDS driver bootstrap functions */
   90.58 +static int
   90.59 +NDS_Available(void)
   90.60 +{
   90.61 +    return (1);                 /* always here */
   90.62 +}
   90.63 +
   90.64 +static void
   90.65 +NDS_DeleteDevice(SDL_VideoDevice * device)
   90.66 +{
   90.67 +    SDL_free(device);
   90.68 +}
   90.69 +
   90.70 +static SDL_VideoDevice *
   90.71 +NDS_CreateDevice(int devindex)
   90.72 +{
   90.73 +    SDL_VideoDevice *device;
   90.74 +
   90.75 +    /* Initialize all variables that we clean on shutdown */
   90.76 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   90.77 +    if (!device) {
   90.78 +        SDL_OutOfMemory();
   90.79 +        if (device) {
   90.80 +            SDL_free(device);
   90.81 +        }
   90.82 +        return (0);
   90.83 +    }
   90.84 +
   90.85 +    /* Set the function pointers */
   90.86 +    device->VideoInit = NDS_VideoInit;
   90.87 +    device->VideoQuit = NDS_VideoQuit;
   90.88 +    device->SetDisplayMode = NDS_SetDisplayMode;
   90.89 +    device->PumpEvents = NDS_PumpEvents;
   90.90 +
   90.91 +    device->num_displays = 2;   /* DS = dual screens */
   90.92 +
   90.93 +    device->free = NDS_DeleteDevice;
   90.94 +
   90.95 +    return device;
   90.96 +}
   90.97 +
   90.98 +VideoBootStrap NDS_bootstrap = {
   90.99 +    NDSVID_DRIVER_NAME, "SDL NDS video driver",
  90.100 +    NDS_Available, NDS_CreateDevice
  90.101 +};
  90.102 +
  90.103 +int
  90.104 +NDS_VideoInit(_THIS)
  90.105 +{
  90.106 +    SDL_DisplayMode mode;
  90.107 +    int i;
  90.108 +
  90.109 +    /* simple 256x192x16x60 for now */
  90.110 +    mode.w = 256;
  90.111 +    mode.h = 192;
  90.112 +    mode.format = SDL_PIXELFORMAT_ABGR1555;
  90.113 +    mode.refresh_rate = 60;
  90.114 +    mode.driverdata = NULL;
  90.115 +
  90.116 +    SDL_AddBasicVideoDisplay(&mode);
  90.117 +    SDL_AddRenderDriver(0, &NDS_RenderDriver);
  90.118 +
  90.119 +    SDL_zero(mode);
  90.120 +    SDL_AddDisplayMode(0, &mode);
  90.121 +
  90.122 +    powerON(POWER_ALL_2D);
  90.123 +    irqInit();
  90.124 +    irqEnable(IRQ_VBLANK);
  90.125 +    NDS_SetDisplayMode(_this, &mode);
  90.126 +
  90.127 +    return 0;
  90.128 +}
  90.129 +
  90.130 +static int
  90.131 +NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
  90.132 +{
  90.133 +    /* right now this function is just hard-coded for 256x192 ABGR1555 */
  90.134 +    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.) */
  90.135 +                 DISPLAY_SPR_ACTIVE | DISPLAY_SPR_EXT_PALETTE); /* display on main core
  90.136 +                                                                   with lots of flags set for
  90.137 +                                                                   flexibility/capacity to render */
  90.138 +
  90.139 +    /* hopefully these cover all the various things we might need to do */
  90.140 +    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
  90.141 +    vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
  90.142 +    vramSetBankC(VRAM_C_SUB_BG_0x06200000);
  90.143 +    vramSetBankD(VRAM_D_MAIN_BG_0x06040000);    /* not a typo. vram d can't sub */
  90.144 +    vramSetBankE(VRAM_E_MAIN_SPRITE);
  90.145 +    vramSetBankF(VRAM_F_OBJ_EXT_PALETTE);
  90.146 +    vramSetBankG(VRAM_G_BG_EXT_PALETTE);
  90.147 +    vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
  90.148 +    vramSetBankI(VRAM_I_SUB_SPRITE);
  90.149 +
  90.150 +    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub
  90.151 +                                                           TODO: this will change
  90.152 +                                                           when multi-head is
  90.153 +                                                           introduced in render */
  90.154 +
  90.155 +    return 0;
  90.156 +}
  90.157 +
  90.158 +void
  90.159 +NDS_VideoQuit(_THIS)
  90.160 +{
  90.161 +    videoSetMode(DISPLAY_SCREEN_OFF);
  90.162 +    videoSetModeSub(DISPLAY_SCREEN_OFF);
  90.163 +    vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
  90.164 +    vramSetBankE(VRAM_E_LCD);
  90.165 +    vramSetBankF(VRAM_F_LCD);
  90.166 +    vramSetBankG(VRAM_G_LCD);
  90.167 +    vramSetBankH(VRAM_H_LCD);
  90.168 +    vramSetBankI(VRAM_I_LCD);
  90.169 +}
  90.170 +
  90.171 +/* vi: set ts=4 sw=4 expandtab: */
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/src/video/nds/SDL_ndsvideo.h	Wed Aug 27 15:10:03 2008 +0000
    91.3 @@ -0,0 +1,31 @@
    91.4 +/*
    91.5 +    SDL - Simple DirectMedia Layer
    91.6 +    Copyright (C) 1997-2006 Sam Lantinga
    91.7 +
    91.8 +    This library is free software; you can redistribute it and/or
    91.9 +    modify it under the terms of the GNU Lesser General Public
   91.10 +    License as published by the Free Software Foundation; either
   91.11 +    version 2.1 of the License, or (at your option) any later version.
   91.12 +
   91.13 +    This library is distributed in the hope that it will be useful,
   91.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   91.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   91.16 +    Lesser General Public License for more details.
   91.17 +
   91.18 +    You should have received a copy of the GNU Lesser General Public
   91.19 +    License along with this library; if not, write to the Free Software
   91.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   91.21 +
   91.22 +    Sam Lantinga
   91.23 +    slouken@libsdl.org
   91.24 +*/
   91.25 +#include "SDL_config.h"
   91.26 +
   91.27 +#ifndef _SDL_ndsvideo_h
   91.28 +#define _SDL_ndsvideo_h
   91.29 +
   91.30 +#include "../SDL_sysvideo.h"
   91.31 +
   91.32 +#endif /* _SDL_ndsvideo_h */
   91.33 +
   91.34 +/* vi: set ts=4 sw=4 expandtab: */
    92.1 --- a/src/video/os2fslib/SDL_os2fslib.c	Wed Aug 27 13:37:19 2008 +0000
    92.2 +++ b/src/video/os2fslib/SDL_os2fslib.c	Wed Aug 27 15:10:03 2008 +0000
    92.3 @@ -440,8 +440,8 @@
    92.4                      if ((!pVideo->hidden->pSDLSurface) ||
    92.5                          ((pVideo->hidden->pSDLSurface)
    92.6                           &&
    92.7 -                         ((pVideo->hidden->pSDLSurface->
    92.8 -                           flags & SDL_RESIZABLE) == 0)))
    92.9 +                         ((pVideo->hidden->
   92.10 +                           pSDLSurface->flags & SDL_RESIZABLE) == 0)))
   92.11                          FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd));
   92.12  #ifdef DEBUG_BUILD
   92.13                      else
   92.14 @@ -552,11 +552,11 @@
   92.15                      {
   92.16  
   92.17                          iXScaleError =
   92.18 -                            (pVideo->hidden->SrcBufferDesc.
   92.19 -                             uiXResolution - 1) / swp.cx;
   92.20 +                            (pVideo->hidden->SrcBufferDesc.uiXResolution -
   92.21 +                             1) / swp.cx;
   92.22                          iYScaleError =
   92.23 -                            (pVideo->hidden->SrcBufferDesc.
   92.24 -                             uiYResolution - 1) / swp.cy;
   92.25 +                            (pVideo->hidden->SrcBufferDesc.uiYResolution -
   92.26 +                             1) / swp.cy;
   92.27                          if (iXScaleError < 0)
   92.28                              iXScaleError = 0;
   92.29                          if (iYScaleError < 0)
   92.30 @@ -577,24 +577,22 @@
   92.31                          iTop =
   92.32                              (swp.cy -
   92.33                               rcl.yTop) *
   92.34 -                            pVideo->hidden->SrcBufferDesc.
   92.35 -                            uiYResolution / swp.cy - iYScaleError;
   92.36 +                            pVideo->hidden->SrcBufferDesc.uiYResolution /
   92.37 +                            swp.cy - iYScaleError;
   92.38                          iLeft =
   92.39                              rcl.xLeft *
   92.40 -                            pVideo->hidden->SrcBufferDesc.
   92.41 -                            uiXResolution / swp.cx - iXScaleError;
   92.42 +                            pVideo->hidden->SrcBufferDesc.uiXResolution /
   92.43 +                            swp.cx - iXScaleError;
   92.44                          iWidth =
   92.45                              ((rcl.xRight -
   92.46                                rcl.xLeft) *
   92.47 -                             pVideo->hidden->SrcBufferDesc.
   92.48 -                             uiXResolution + swp.cx - 1) / swp.cx +
   92.49 -                            2 * iXScaleError;
   92.50 +                             pVideo->hidden->SrcBufferDesc.uiXResolution +
   92.51 +                             swp.cx - 1) / swp.cx + 2 * iXScaleError;
   92.52                          iHeight =
   92.53                              ((rcl.yTop -
   92.54                                rcl.yBottom) *
   92.55 -                             pVideo->hidden->SrcBufferDesc.
   92.56 -                             uiYResolution + swp.cy - 1) / swp.cy +
   92.57 -                            2 * iYScaleError;
   92.58 +                             pVideo->hidden->SrcBufferDesc.uiYResolution +
   92.59 +                             swp.cy - 1) / swp.cy + 2 * iYScaleError;
   92.60  
   92.61                          iWidth += iXScaleError2;
   92.62                          iHeight += iYScaleError2;
   92.63 @@ -606,20 +604,19 @@
   92.64                          if (iTop + iHeight >
   92.65                              pVideo->hidden->SrcBufferDesc.uiYResolution)
   92.66                              iHeight =
   92.67 -                                pVideo->hidden->SrcBufferDesc.
   92.68 -                                uiYResolution - iTop;
   92.69 +                                pVideo->hidden->SrcBufferDesc.uiYResolution -
   92.70 +                                iTop;
   92.71                          if (iLeft + iWidth >
   92.72                              pVideo->hidden->SrcBufferDesc.uiXResolution)
   92.73                              iWidth =
   92.74 -                                pVideo->hidden->SrcBufferDesc.
   92.75 -                                uiXResolution - iLeft;
   92.76 +                                pVideo->hidden->SrcBufferDesc.uiXResolution -
   92.77 +                                iLeft;
   92.78  
   92.79  #ifdef DEBUG_BUILD
   92.80                          printf
   92.81                              ("WM_PAINT : BitBlt: %d %d -> %d %d (Buf %d x %d)\n",
   92.82                               iTop, iLeft, iWidth, iHeight,
   92.83 -                             pVideo->hidden->SrcBufferDesc.
   92.84 -                             uiXResolution,
   92.85 +                             pVideo->hidden->SrcBufferDesc.uiXResolution,
   92.86                               pVideo->hidden->SrcBufferDesc.uiYResolution);
   92.87                          fflush(stdout);
   92.88  #endif
   92.89 @@ -693,15 +690,15 @@
   92.90                              WinQueryWindowPos(hwnd, &swp);
   92.91                              if ((!pVideo->hidden->pSDLSurface) ||
   92.92                                  ((pVideo->hidden->pSDLSurface) &&
   92.93 -                                 (pVideo->hidden->pSDLSurface->
   92.94 -                                  flags & SDL_RESIZABLE)
   92.95 +                                 (pVideo->hidden->
   92.96 +                                  pSDLSurface->flags & SDL_RESIZABLE)
   92.97                                   &&
   92.98                                   ((swp.cx !=
   92.99 -                                   pVideo->hidden->SrcBufferDesc.
  92.100 -                                   uiXResolution)
  92.101 +                                   pVideo->hidden->
  92.102 +                                   SrcBufferDesc.uiXResolution)
  92.103                                    || (swp.cy !=
  92.104 -                                      pVideo->hidden->
  92.105 -                                      SrcBufferDesc.uiYResolution))
  92.106 +                                      pVideo->hidden->SrcBufferDesc.
  92.107 +                                      uiYResolution))
  92.108                                   && (!FSLib_QueryFSMode(hwnd)))) {
  92.109                                  // Resizable surface and in resizing!
  92.110                                  // So, don't blit now!
  92.111 @@ -718,14 +715,12 @@
  92.112                                  fflush(stdout);
  92.113  #endif
  92.114                                  FSLIB_BITBLT(hwnd,
  92.115 -                                             pVideo->hidden->
  92.116 -                                             pchSrcBuffer, 0,
  92.117 +                                             pVideo->hidden->pchSrcBuffer, 0,
  92.118                                               0,
  92.119                                               pVideo->hidden->
  92.120 -                                             SrcBufferDesc.
  92.121 -                                             uiXResolution,
  92.122 -                                             pVideo->hidden->
  92.123 -                                             SrcBufferDesc.uiYResolution);
  92.124 +                                             SrcBufferDesc.uiXResolution,
  92.125 +                                             pVideo->hidden->SrcBufferDesc.
  92.126 +                                             uiYResolution);
  92.127                              }
  92.128                          }
  92.129  #ifdef DEBUG_BUILD
  92.130 @@ -773,8 +768,8 @@
  92.131                                            &swpClient);
  92.132                          ptl.x = 0;
  92.133                          ptl.y = 0;
  92.134 -                        WinMapWindowPoints(pVideo->hidden->
  92.135 -                                           hwndClient, HWND_DESKTOP, &ptl, 1);
  92.136 +                        WinMapWindowPoints(pVideo->hidden->hwndClient,
  92.137 +                                           HWND_DESKTOP, &ptl, 1);
  92.138                          pVideo->hidden->iSkipWMMOUSEMOVE++;     /* Don't take next WM_MOUSEMOVE into account!  */
  92.139                          WinSetPointerPos(HWND_DESKTOP,
  92.140                                           ptl.x + swpClient.cx / 2,
  92.141 @@ -825,8 +820,8 @@
  92.142                                            &swpClient);
  92.143                          ptl.x = 0;
  92.144                          ptl.y = 0;
  92.145 -                        WinMapWindowPoints(pVideo->hidden->
  92.146 -                                           hwndClient, HWND_DESKTOP, &ptl, 1);
  92.147 +                        WinMapWindowPoints(pVideo->hidden->hwndClient,
  92.148 +                                           HWND_DESKTOP, &ptl, 1);
  92.149                          pVideo->hidden->iSkipWMMOUSEMOVE++;     /* Don't take next WM_MOUSEMOVE into account!  */
  92.150                          WinSetPointerPos(HWND_DESKTOP,
  92.151                                           ptl.x + swpClient.cx / 2,
  92.152 @@ -867,8 +862,8 @@
  92.153                                            &swpClient);
  92.154                          ptl.x = 0;
  92.155                          ptl.y = 0;
  92.156 -                        WinMapWindowPoints(pVideo->hidden->
  92.157 -                                           hwndClient, HWND_DESKTOP, &ptl, 1);
  92.158 +                        WinMapWindowPoints(pVideo->hidden->hwndClient,
  92.159 +                                           HWND_DESKTOP, &ptl, 1);
  92.160                          pVideo->hidden->iSkipWMMOUSEMOVE++;     /* Don't take next WM_MOUSEMOVE into account!  */
  92.161                          WinSetPointerPos(HWND_DESKTOP,
  92.162                                           ptl.x + swpClient.cx / 2,
  92.163 @@ -910,8 +905,8 @@
  92.164                                            &swpClient);
  92.165                          ptl.x = 0;
  92.166                          ptl.y = 0;
  92.167 -                        WinMapWindowPoints(pVideo->hidden->
  92.168 -                                           hwndClient, HWND_DESKTOP, &ptl, 1);
  92.169 +                        WinMapWindowPoints(pVideo->hidden->hwndClient,
  92.170 +                                           HWND_DESKTOP, &ptl, 1);
  92.171                          pVideo->hidden->iSkipWMMOUSEMOVE++;     /* Don't take next WM_MOUSEMOVE into account!  */
  92.172                          WinSetPointerPos(HWND_DESKTOP,
  92.173                                           ptl.x + swpClient.cx / 2,
  92.174 @@ -1378,6 +1373,7 @@
  92.175      while (len-- > 0)
  92.176          *dst++ = ~*src++;
  92.177  }
  92.178 +
  92.179  static void
  92.180  memxor(Uint8 * dst, Uint8 * src1, Uint8 * src2, int len)
  92.181  {
  92.182 @@ -1635,6 +1631,7 @@
  92.183  {
  92.184      return (-1);
  92.185  }
  92.186 +
  92.187  static void
  92.188  os2fslib_FreeHWSurface(_THIS, SDL_Surface * surface)
  92.189  {
  92.190 @@ -2505,23 +2502,27 @@
  92.191          pResult = SDL_CreateRGBSurface(SDL_SWSURFACE,
  92.192                                         pModeInfoFound->uiXResolution,
  92.193                                         pModeInfoFound->uiYResolution,
  92.194 -                                       pModeInfoFound->uiBPP,
  92.195 -                                       ((unsigned int) pModeInfoFound->
  92.196 -                                        PixelFormat.
  92.197 -                                        ucRedMask) << pModeInfoFound->
  92.198 -                                       PixelFormat.ucRedPosition,
  92.199 -                                       ((unsigned int) pModeInfoFound->
  92.200 -                                        PixelFormat.
  92.201 -                                        ucGreenMask) << pModeInfoFound->
  92.202 -                                       PixelFormat.ucGreenPosition,
  92.203 -                                       ((unsigned int) pModeInfoFound->
  92.204 -                                        PixelFormat.
  92.205 -                                        ucBlueMask) << pModeInfoFound->
  92.206 -                                       PixelFormat.ucBluePosition,
  92.207 -                                       ((unsigned int) pModeInfoFound->
  92.208 -                                        PixelFormat.
  92.209 -                                        ucAlphaMask) << pModeInfoFound->
  92.210 -                                       PixelFormat.ucAlphaPosition);
  92.211 +                                       pModeInfoFound->uiBPP, ((unsigned int)
  92.212 +                                                               pModeInfoFound->
  92.213 +                                                               PixelFormat.
  92.214 +                                                               ucRedMask)
  92.215 +                                       << pModeInfoFound->PixelFormat.
  92.216 +                                       ucRedPosition, ((unsigned int)
  92.217 +                                                       pModeInfoFound->
  92.218 +                                                       PixelFormat.
  92.219 +                                                       ucGreenMask)
  92.220 +                                       << pModeInfoFound->PixelFormat.
  92.221 +                                       ucGreenPosition, ((unsigned int)
  92.222 +                                                         pModeInfoFound->
  92.223 +                                                         PixelFormat.
  92.224 +                                                         ucBlueMask)
  92.225 +                                       << pModeInfoFound->PixelFormat.
  92.226 +                                       ucBluePosition, ((unsigned int)
  92.227 +                                                        pModeInfoFound->
  92.228 +                                                        PixelFormat.
  92.229 +                                                        ucAlphaMask)
  92.230 +                                       << pModeInfoFound->PixelFormat.
  92.231 +                                       ucAlphaPosition);
  92.232  
  92.233          if (pResult == NULL) {
  92.234              DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer);
  92.235 @@ -2535,23 +2536,27 @@
  92.236  
  92.237          // Adjust pixel format mask!
  92.238          pResult->format->Rmask =
  92.239 -            ((unsigned int) pModeInfoFound->PixelFormat.
  92.240 -             ucRedMask) << pModeInfoFound->PixelFormat.ucRedPosition;
  92.241 +            ((unsigned int) pModeInfoFound->
  92.242 +             PixelFormat.ucRedMask) << pModeInfoFound->PixelFormat.
  92.243 +            ucRedPosition;
  92.244          pResult->format->Rshift = pModeInfoFound->PixelFormat.ucRedPosition;
  92.245          pResult->format->Rloss = pModeInfoFound->PixelFormat.ucRedAdjust;
  92.246          pResult->format->Gmask =
  92.247 -            ((unsigned int) pModeInfoFound->PixelFormat.
  92.248 -             ucGreenMask) << pModeInfoFound->PixelFormat.ucGreenPosition;
  92.249 +            ((unsigned int) pModeInfoFound->
  92.250 +             PixelFormat.ucGreenMask) << pModeInfoFound->PixelFormat.
  92.251 +            ucGreenPosition;
  92.252          pResult->format->Gshift = pModeInfoFound->PixelFormat.ucGreenPosition;
  92.253          pResult->format->Gloss = pModeInfoFound->PixelFormat.ucGreenAdjust;
  92.254          pResult->format->Bmask =
  92.255 -            ((unsigned int) pModeInfoFound->PixelFormat.
  92.256 -             ucBlueMask) << pModeInfoFound->PixelFormat.ucBluePosition;
  92.257 +            ((unsigned int) pModeInfoFound->
  92.258 +             PixelFormat.ucBlueMask) << pModeInfoFound->PixelFormat.
  92.259 +            ucBluePosition;
  92.260          pResult->format->Bshift = pModeInfoFound->PixelFormat.ucBluePosition;
  92.261          pResult->format->Bloss = pModeInfoFound->PixelFormat.ucBlueAdjust;
  92.262          pResult->format->Amask =
  92.263 -            ((unsigned int) pModeInfoFound->PixelFormat.
  92.264 -             ucAlphaMask) << pModeInfoFound->PixelFormat.ucAlphaPosition;
  92.265 +            ((unsigned int) pModeInfoFound->
  92.266 +             PixelFormat.ucAlphaMask) << pModeInfoFound->PixelFormat.
  92.267 +            ucAlphaPosition;
  92.268          pResult->format->Ashift = pModeInfoFound->PixelFormat.ucAlphaPosition;
  92.269          pResult->format->Aloss = pModeInfoFound->PixelFormat.ucAlphaAdjust;
  92.270  
  92.271 @@ -2738,10 +2743,8 @@
  92.272                          for (i = 0; _this->hidden->pListModesResult[i]; i++) {
  92.273                              iNumOfSlots++;
  92.274                              if (iPlace == -1) {
  92.275 -                                if ((_this->hidden->
  92.276 -                                     pListModesResult[i]->w *
  92.277 -                                     _this->hidden->
  92.278 -                                     pListModesResult[i]->h) <
  92.279 +                                if ((_this->hidden->pListModesResult[i]->w *
  92.280 +                                     _this->hidden->pListModesResult[i]->h) <
  92.281                                      (pRect->w * pRect->h)) {
  92.282                                      iPlace = i;
  92.283                                  }
  92.284 @@ -2754,14 +2757,10 @@
  92.285  //            printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace);
  92.286  #endif
  92.287  
  92.288 -                        pNewList =
  92.289 -                            (SDL_Rect **) SDL_realloc(_this->
  92.290 -                                                      hidden->
  92.291 -                                                      pListModesResult,
  92.292 -                                                      (iNumOfSlots
  92.293 -                                                       +
  92.294 -                                                       1) *
  92.295 -                                                      sizeof(SDL_Rect *));
  92.296 +                        pNewList = (SDL_Rect **)
  92.297 +                            SDL_realloc(_this->hidden->pListModesResult,
  92.298 +                                        (iNumOfSlots +
  92.299 +                                         1) * sizeof(SDL_Rect *));
  92.300                          if (pNewList) {
  92.301                              for (i = iNumOfSlots; i > iPlace; i--)
  92.302                                  pNewList[i] = pNewList[i - 1];
  92.303 @@ -2816,23 +2815,25 @@
  92.304      vformat->BytesPerPixel = (vformat->BitsPerPixel + 7) / 8;
  92.305  
  92.306      vformat->Rmask =
  92.307 -        ((unsigned int) pDesktopMode->PixelFormat.ucRedMask) << pDesktopMode->
  92.308 -        PixelFormat.ucRedPosition;
  92.309 +        ((unsigned int) pDesktopMode->PixelFormat.
  92.310 +         ucRedMask) << pDesktopMode->PixelFormat.ucRedPosition;
  92.311      vformat->Rshift = pDesktopMode->PixelFormat.ucRedPosition;
  92.312      vformat->Rloss = pDesktopMode->PixelFormat.ucRedAdjust;
  92.313      vformat->Gmask =
  92.314 -        ((unsigned int) pDesktopMode->PixelFormat.
  92.315 -         ucGreenMask) << pDesktopMode->PixelFormat.ucGreenPosition;
  92.316 +        ((unsigned int) pDesktopMode->
  92.317 +         PixelFormat.ucGreenMask) << pDesktopMode->PixelFormat.
  92.318 +        ucGreenPosition;
  92.319      vformat->Gshift = pDesktopMode->PixelFormat.ucGreenPosition;
  92.320      vformat->Gloss = pDesktopMode->PixelFormat.ucGreenAdjust;
  92.321      vformat->Bmask =
  92.322 -        ((unsigned int) pDesktopMode->PixelFormat.
  92.323 -         ucBlueMask) << pDesktopMode->PixelFormat.ucBluePosition;
  92.324 +        ((unsigned int) pDesktopMode->
  92.325 +         PixelFormat.ucBlueMask) << pDesktopMode->PixelFormat.ucBluePosition;
  92.326      vformat->Bshift = pDesktopMode->PixelFormat.ucBluePosition;
  92.327      vformat->Bloss = pDesktopMode->PixelFormat.ucBlueAdjust;
  92.328      vformat->Amask =
  92.329 -        ((unsigned int) pDesktopMode->PixelFormat.
  92.330 -         ucAlphaMask) << pDesktopMode->PixelFormat.ucAlphaPosition;
  92.331 +        ((unsigned int) pDesktopMode->
  92.332 +         PixelFormat.ucAlphaMask) << pDesktopMode->PixelFormat.
  92.333 +        ucAlphaPosition;
  92.334      vformat->Ashift = pDesktopMode->PixelFormat.ucAlphaPosition;
  92.335      vformat->Aloss = pDesktopMode->PixelFormat.ucAlphaAdjust;
  92.336  
  92.337 @@ -2937,10 +2938,10 @@
  92.338                 sizeof(_this->hidden->SrcBufferDesc));
  92.339      // Allocate new video buffer!
  92.340      _this->hidden->pchSrcBuffer =
  92.341 -        (char *) SDL_malloc(_this->hidden->pAvailableFSLibVideoModes->
  92.342 -                            uiScanLineSize *
  92.343 -                            _this->hidden->pAvailableFSLibVideoModes->
  92.344 -                            uiYResolution);
  92.345 +        (char *) SDL_malloc(_this->hidden->
  92.346 +                            pAvailableFSLibVideoModes->uiScanLineSize *
  92.347 +                            _this->hidden->
  92.348 +                            pAvailableFSLibVideoModes->uiYResolution);
  92.349      if (!_this->hidden->pchSrcBuffer) {
  92.350  #ifdef DEBUG_BUILD
  92.351          printf
    93.1 --- a/src/video/photon/SDL_ph_gl.c	Wed Aug 27 13:37:19 2008 +0000
    93.2 +++ b/src/video/photon/SDL_ph_gl.c	Wed Aug 27 15:10:03 2008 +0000
    93.3 @@ -315,11 +315,14 @@
    93.4          && (this->gl_config.accum_blue_size != 0)
    93.5          && (this->gl_config.accum_green_size != 0)) {
    93.6          qnxgl_attribs_slide = qnxgl_attrib_set_accum(qnxgl_attribs_slide,
    93.7 -                                                     this->gl_config.
    93.8 -                                                     accum_red_size +
    93.9 -                                                     this->gl_config.
   93.10 -                                                     accum_blue_size +
   93.11 -                                                     this->gl_config.
   93.12 +                                                     this->
   93.13 +                                                     gl_config.accum_red_size
   93.14 +                                                     +
   93.15 +                                                     this->
   93.16 +                                                     gl_config.accum_blue_size
   93.17 +                                                     +
   93.18 +                                                     this->
   93.19 +                                                     gl_config.
   93.20                                                       accum_green_size +
   93.21                                                       this->gl_config.
   93.22                                                       accum_alpha_size);
    94.1 --- a/src/video/photon/SDL_ph_image.c	Wed Aug 27 13:37:19 2008 +0000
    94.2 +++ b/src/video/photon/SDL_ph_image.c	Wed Aug 27 15:10:03 2008 +0000
    94.3 @@ -244,9 +244,8 @@
    94.4      }
    94.5  
    94.6      if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    94.7 -        OCImage.FrameData1 =
    94.8 -            (unsigned char *) PdGetOffscreenContextPtr(OCImage.
    94.9 -                                                       offscreen_backcontext);
   94.10 +        OCImage.FrameData1 = (unsigned char *)
   94.11 +            PdGetOffscreenContextPtr(OCImage.offscreen_backcontext);
   94.12          if (OCImage.FrameData1 == NULL) {
   94.13              SDL_SetError
   94.14                  ("ph_SetupFullScreenImage(back): PdGetOffscreenContextPtr() function failed !\n");
    95.1 --- a/src/video/photon/SDL_phyuv.c	Wed Aug 27 13:37:19 2008 +0000
    95.2 +++ b/src/video/photon/SDL_phyuv.c	Wed Aug 27 15:10:03 2008 +0000
    95.3 @@ -149,8 +149,8 @@
    95.4                                      &overlay->hwdata->caps);
    95.5          if (rtncode == 0) {
    95.6              if (overlay->hwdata->caps.format == format) {
    95.7 -                if ((overlay->hwdata->caps.
    95.8 -                     flags & Pg_SCALER_CAP_DST_CHROMA_KEY) ==
    95.9 +                if ((overlay->hwdata->
   95.10 +                     caps.flags & Pg_SCALER_CAP_DST_CHROMA_KEY) ==
   95.11                      Pg_SCALER_CAP_DST_CHROMA_KEY) {
   95.12                      overlay->hwdata->ischromakey = 1;
   95.13                  }
   95.14 @@ -161,8 +161,7 @@
   95.15              break;
   95.16          }
   95.17          i++;
   95.18 -    }
   95.19 -    while (1);
   95.20 +    } while (1);
   95.21  
   95.22  
   95.23      if (vidport == -1) {
    96.1 --- a/src/video/ps2gs/SDL_gsevents.c	Wed Aug 27 13:37:19 2008 +0000
    96.2 +++ b/src/video/ps2gs/SDL_gsevents.c	Wed Aug 27 15:10:03 2008 +0000
    96.3 @@ -479,9 +479,8 @@
    96.4                  if (select(fd + 1, &fdset, 0, 0, &tv) < 1) {
    96.5                      break;
    96.6                  }
    96.7 -            }
    96.8 -            while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) &&
    96.9 -                   ((ch == 0xFA) || (ch == 0xAA)));
   96.10 +            } while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) &&
   96.11 +                     ((ch == 0xFA) || (ch == 0xAA)));
   96.12  
   96.13              /* Experimental values (Logitech wheelmouse) */
   96.14  #ifdef DEBUG_MOUSE
   96.15 @@ -833,8 +832,7 @@
   96.16                  }
   96.17              }
   96.18          }
   96.19 -    }
   96.20 -    while (posted);
   96.21 +    } while (posted);
   96.22  }
   96.23  
   96.24  void
    97.1 --- a/src/video/ps2gs/SDL_gsvideo.c	Wed Aug 27 13:37:19 2008 +0000
    97.2 +++ b/src/video/ps2gs/SDL_gsvideo.c	Wed Aug 27 15:10:03 2008 +0000
    97.3 @@ -232,6 +232,7 @@
    97.4          0x0e,                   /* A+D */
    97.5          0,                      /* 2 */
    97.6  PS2_GS_TEX0_1, (1 << 5) + (1 << 6), PS2_GS_TEX1_1, 0, PS2_GS_TEXFLUSH};
    97.7 +
    97.8  static unsigned long long scale_tags[] __attribute__ ((aligned(16))) = {
    97.9      5 | (1LL << 60),            /* GIFtag */
   97.10          0x0e,                   /* A+D */
   97.11 @@ -573,11 +574,13 @@
   97.12  {
   97.13      return (-1);
   97.14  }
   97.15 +
   97.16  static void
   97.17  GS_FreeHWSurface(_THIS, SDL_Surface * surface)
   97.18  {
   97.19      return;
   97.20  }
   97.21 +
   97.22  static int
   97.23  GS_LockHWSurface(_THIS, SDL_Surface * surface)
   97.24  {
   97.25 @@ -606,6 +609,7 @@
   97.26      }
   97.27      return (0);
   97.28  }
   97.29 +
   97.30  static void
   97.31  GS_UnlockHWSurface(_THIS, SDL_Surface * surface)
   97.32  {
    98.1 --- a/src/video/riscos/SDL_riscosvideo.c	Wed Aug 27 13:37:19 2008 +0000
    98.2 +++ b/src/video/riscos/SDL_riscosvideo.c	Wed Aug 27 15:10:03 2008 +0000
    98.3 @@ -286,6 +286,7 @@
    98.4  {
    98.5      return (-1);
    98.6  }
    98.7 +
    98.8  static void
    98.9  RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface)
   98.10  {
    99.1 --- a/src/video/svga/SDL_svgaevents.c	Wed Aug 27 13:37:19 2008 +0000
    99.2 +++ b/src/video/svga/SDL_svgaevents.c	Wed Aug 27 15:10:03 2008 +0000
    99.3 @@ -207,8 +207,7 @@
    99.4          posted = 0;
    99.5          mouse_update();
    99.6          keyboard_update();
    99.7 -    }
    99.8 -    while (posted);
    99.9 +    } while (posted);
   99.10  }
   99.11  
   99.12  void
   100.1 --- a/src/video/svga/SDL_svgavideo.c	Wed Aug 27 13:37:19 2008 +0000
   100.2 +++ b/src/video/svga/SDL_svgavideo.c	Wed Aug 27 15:10:03 2008 +0000
   100.3 @@ -467,6 +467,7 @@
   100.4  {
   100.5      return (-1);
   100.6  }
   100.7 +
   100.8  static void
   100.9  SVGA_FreeHWSurface(_THIS, SDL_Surface * surface)
  100.10  {
  100.11 @@ -480,6 +481,7 @@
  100.12      /* The waiting is done in SVGA_FlipHWSurface() */
  100.13      return (0);
  100.14  }
  100.15 +
  100.16  static void
  100.17  SVGA_UnlockHWSurface(_THIS, SDL_Surface * surface)
  100.18  {
   101.1 --- a/src/video/vgl/SDL_vglevents.c	Wed Aug 27 13:37:19 2008 +0000
   101.2 +++ b/src/video/vgl/SDL_vglevents.c	Wed Aug 27 15:10:03 2008 +0000
   101.3 @@ -141,8 +141,7 @@
   101.4          posted = 0;
   101.5          handle_keyboard(this);
   101.6          handle_mouse(this);
   101.7 -    }
   101.8 -    while (posted != 0);
   101.9 +    } while (posted != 0);
  101.10  }
  101.11  
  101.12  void
   102.1 --- a/src/video/vgl/SDL_vglvideo.c	Wed Aug 27 13:37:19 2008 +0000
   102.2 +++ b/src/video/vgl/SDL_vglvideo.c	Wed Aug 27 15:10:03 2008 +0000
   102.3 @@ -409,6 +409,7 @@
   102.4  {
   102.5      return -1;
   102.6  }
   102.7 +
   102.8  static void
   102.9  VGL_FreeHWSurface(_THIS, SDL_Surface * surface)
  102.10  {
  102.11 @@ -424,6 +425,7 @@
  102.12      }
  102.13      return 0;
  102.14  }
  102.15 +
  102.16  static void
  102.17  VGL_UnlockHWSurface(_THIS, SDL_Surface * surface)
  102.18  {
   103.1 --- a/src/video/win32/SDL_d3drender.c	Wed Aug 27 13:37:19 2008 +0000
   103.2 +++ b/src/video/win32/SDL_d3drender.c	Wed Aug 27 15:10:03 2008 +0000
   103.3 @@ -596,8 +596,8 @@
   103.4      result =
   103.5          IDirect3DDevice9_UpdateTexture(renderdata->device,
   103.6                                         (IDirect3DBaseTexture9 *) temp,
   103.7 -                                       (IDirect3DBaseTexture9 *) data->
   103.8 -                                       texture);
   103.9 +                                       (IDirect3DBaseTexture9 *)
  103.10 +                                       data->texture);
  103.11      IDirect3DTexture9_Release(temp);
  103.12      if (FAILED(result)) {
  103.13          D3D_SetError("UpdateTexture()", result);
  103.14 @@ -805,9 +805,8 @@
  103.15      }
  103.16  
  103.17      result =
  103.18 -        IDirect3DDevice9_SetTexture(data->device, 0,
  103.19 -                                    (IDirect3DBaseTexture9 *) texturedata->
  103.20 -                                    texture);
  103.21 +        IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
  103.22 +                                    texturedata->texture);
  103.23      if (FAILED(result)) {
  103.24          D3D_SetError("SetTexture()", result);
  103.25          return -1;
   104.1 --- a/src/video/win32/SDL_gdirender.c	Wed Aug 27 13:37:19 2008 +0000
   104.2 +++ b/src/video/win32/SDL_gdirender.c	Wed Aug 27 15:10:03 2008 +0000
   104.3 @@ -620,9 +620,8 @@
   104.4          SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
   104.5          RealizePalette(data->memory_hdc);
   104.6      }
   104.7 -    if (texture->
   104.8 -        blendMode & (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND))
   104.9 -    {
  104.10 +    if (texture->blendMode &
  104.11 +        (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND)) {
  104.12          BLENDFUNCTION blendFunc = {
  104.13              AC_SRC_OVER,
  104.14              0,
   105.1 --- a/src/video/win32/SDL_win32keyboard.c	Wed Aug 27 13:37:19 2008 +0000
   105.2 +++ b/src/video/win32/SDL_win32keyboard.c	Wed Aug 27 15:10:03 2008 +0000
   105.3 @@ -41,6 +41,7 @@
   105.4      30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
   105.5      25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
   105.6  };
   105.7 +
   105.8  BYTE keypad_scancodes[10] = {
   105.9      82, 79, 80, 81, 75, 76, 77, 71, 72, 73
  105.10  };
   106.1 --- a/src/video/win32/SDL_win32opengl.c	Wed Aug 27 13:37:19 2008 +0000
   106.2 +++ b/src/video/win32/SDL_win32opengl.c	Wed Aug 27 15:10:03 2008 +0000
   106.3 @@ -500,8 +500,7 @@
   106.4      if (_this->gl_config.accelerated >= 0) {
   106.5          *iAttr++ = WGL_ACCELERATION_ARB;
   106.6          *iAttr++ =
   106.7 -            (_this->gl_config.
   106.8 -             accelerated ? WGL_GENERIC_ACCELERATION_ARB :
   106.9 +            (_this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB :
  106.10               WGL_NO_ACCELERATION_ARB);
  106.11      }
  106.12  
   107.1 --- a/src/video/wscons/SDL_wsconsevents.c	Wed Aug 27 13:37:19 2008 +0000
   107.2 +++ b/src/video/wscons/SDL_wsconsevents.c	Wed Aug 27 15:10:03 2008 +0000
   107.3 @@ -145,8 +145,7 @@
   107.4          posted = 0;
   107.5          updateMouse();
   107.6          updateKeyboard(this);
   107.7 -    }
   107.8 -    while (posted);
   107.9 +    } while (posted);
  107.10  }
  107.11  
  107.12  void
   108.1 --- a/src/video/wscons/SDL_wsconsvideo.c	Wed Aug 27 13:37:19 2008 +0000
   108.2 +++ b/src/video/wscons/SDL_wsconsvideo.c	Wed Aug 27 15:10:03 2008 +0000
   108.3 @@ -399,6 +399,7 @@
   108.4  {
   108.5      return -1;
   108.6  }
   108.7 +
   108.8  static void
   108.9  WSCONS_FreeHWSurface(_THIS, SDL_Surface * surface)
  108.10  {
   109.1 --- a/src/video/x11/SDL_x11opengl.c	Wed Aug 27 13:37:19 2008 +0000
   109.2 +++ b/src/video/x11/SDL_x11opengl.c	Wed Aug 27 15:10:03 2008 +0000
   109.3 @@ -417,8 +417,8 @@
   109.4      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   109.5      Display *display = data->videodata->display;
   109.6      int screen =
   109.7 -        ((SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata)->
   109.8 -        screen;
   109.9 +        ((SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->
  109.10 +         driverdata)->screen;
  109.11      XWindowAttributes xattr;
  109.12      XVisualInfo v, *vinfo;
  109.13      int n;
   110.1 --- a/src/video/xbios/SDL_xbiosmodes.c	Wed Aug 27 13:37:19 2008 +0000
   110.2 +++ b/src/video/xbios/SDL_xbiosmodes.c	Wed Aug 27 15:10:03 2008 +0000
   110.3 @@ -277,8 +277,8 @@
   110.4                      SDL_XBIOS_AddMode(_this, falcon_rgb_modes[i].width,
   110.5                                        falcon_rgb_modes[i].height,
   110.6                                        falcon_rgb_modes[i].bpp,
   110.7 -                                      falcon_rgb_modes[i].
   110.8 -                                      modecode & modecodemask, SDL_FALSE);
   110.9 +                                      falcon_rgb_modes[i].modecode &
  110.10 +                                      modecodemask, SDL_FALSE);
  110.11                  }
  110.12                  break;
  110.13              case MONITOR_VGA:
  110.14 @@ -288,8 +288,8 @@
  110.15                      SDL_XBIOS_AddMode(_this, falcon_vga_modes[i].width,
  110.16                                        falcon_vga_modes[i].height,
  110.17                                        falcon_vga_modes[i].bpp,
  110.18 -                                      falcon_vga_modes[i].
  110.19 -                                      modecode & modecodemask, SDL_FALSE);
  110.20 +                                      falcon_vga_modes[i].modecode &
  110.21 +                                      modecodemask, SDL_FALSE);
  110.22                  }
  110.23                  break;
  110.24              }
   111.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   111.2 +++ b/test/nds-test-progs/general/Makefile	Wed Aug 27 15:10:03 2008 +0000
   111.3 @@ -0,0 +1,132 @@
   111.4 +#---------------------------------------------------------------------------------
   111.5 +.SUFFIXES:
   111.6 +#---------------------------------------------------------------------------------
   111.7 +
   111.8 +ifeq ($(strip $(DEVKITARM)),)
   111.9 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
  111.10 +endif
  111.11 +
  111.12 +include $(DEVKITARM)/ds_rules
  111.13 +
  111.14 +#---------------------------------------------------------------------------------
  111.15 +# TARGET is the name of the output
  111.16 +# BUILD is the directory where object files & intermediate files will be placed
  111.17 +# SOURCES is a list of directories containing source code
  111.18 +# INCLUDES is a list of directories containing extra header files
  111.19 +#---------------------------------------------------------------------------------
  111.20 +TARGET		:=	$(shell basename $(CURDIR))
  111.21 +BUILD		:=	build
  111.22 +SOURCES		:=	source
  111.23 +DATA		:=	data  
  111.24 +INCLUDES	:=	include
  111.25 +
  111.26 +#---------------------------------------------------------------------------------
  111.27 +# options for code generation
  111.28 +#---------------------------------------------------------------------------------
  111.29 +ARCH	:=	-mthumb -mthumb-interwork
  111.30 +
  111.31 +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
  111.32 +# *insists* it has a FPU or VFP, and it won't take no for an answer!
  111.33 +CFLAGS	:=	-save-temps -g -Wall -O0\
  111.34 + 			-mcpu=arm9tdmi -mtune=arm9tdmi \
  111.35 +			$(ARCH)
  111.36 +
  111.37 +CFLAGS	+=	$(INCLUDE) -DARM9 -D__NDS__
  111.38 +CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti
  111.39 +
  111.40 +ASFLAGS	:=	-g $(ARCH)
  111.41 +LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
  111.42 +
  111.43 +#---------------------------------------------------------------------------------
  111.44 +# any extra libraries we wish to link with the project
  111.45 +#---------------------------------------------------------------------------------
  111.46 +LIBS	:= -lSDL -lfat -lnds9
  111.47 + 
  111.48 + 
  111.49 +#---------------------------------------------------------------------------------
  111.50 +# list of directories containing libraries, this must be the top level containing
  111.51 +# include and lib
  111.52 +#---------------------------------------------------------------------------------
  111.53 +LIBDIRS	:=	$(LIBNDS)
  111.54 + 
  111.55 +#---------------------------------------------------------------------------------
  111.56 +# no real need to edit anything past this point unless you need to add additional
  111.57 +# rules for different file extensions
  111.58 +#---------------------------------------------------------------------------------
  111.59 +ifneq ($(BUILD),$(notdir $(CURDIR)))
  111.60 +#---------------------------------------------------------------------------------
  111.61 + 
  111.62 +export OUTPUT	:=	$(CURDIR)/$(TARGET)
  111.63 + 
  111.64 +export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  111.65 +					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
  111.66 +
  111.67 +export DEPSDIR	:=	$(CURDIR)/$(BUILD)
  111.68 +
  111.69 +CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  111.70 +CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  111.71 +SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  111.72 +BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  111.73 + 
  111.74 +#---------------------------------------------------------------------------------
  111.75 +# use CXX for linking C++ projects, CC for standard C
  111.76 +#---------------------------------------------------------------------------------
  111.77 +ifeq ($(strip $(CPPFILES)),)
  111.78 +#---------------------------------------------------------------------------------
  111.79 +	export LD	:=	$(CC)
  111.80 +#---------------------------------------------------------------------------------
  111.81 +else
  111.82 +#---------------------------------------------------------------------------------
  111.83 +	export LD	:=	$(CXX)
  111.84 +#---------------------------------------------------------------------------------
  111.85 +endif
  111.86 +#---------------------------------------------------------------------------------
  111.87 +
  111.88 +export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
  111.89 +					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  111.90 + 
  111.91 +export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  111.92 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  111.93 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  111.94 +					-I$(CURDIR)/$(BUILD)
  111.95 + 
  111.96 +export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  111.97 + 
  111.98 +.PHONY: $(BUILD) clean
  111.99 + 
 111.100 +#---------------------------------------------------------------------------------
 111.101 +$(BUILD):
 111.102 +	@[ -d $@ ] || mkdir -p $@
 111.103 +	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
 111.104 + 
 111.105 +#---------------------------------------------------------------------------------
 111.106 +clean:
 111.107 +	@echo clean ...
 111.108 +	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba 
 111.109 + 
 111.110 + 
 111.111 +#---------------------------------------------------------------------------------
 111.112 +else
 111.113 + 
 111.114 +DEPENDS	:=	$(OFILES:.o=.d)
 111.115 + 
 111.116 +#---------------------------------------------------------------------------------
 111.117 +# main targets
 111.118 +#---------------------------------------------------------------------------------
 111.119 +$(OUTPUT).ds.gba	: 	$(OUTPUT).nds
 111.120 +$(OUTPUT).nds	: 	$(OUTPUT).arm9
 111.121 +$(OUTPUT).arm9	:	$(OUTPUT).elf
 111.122 +$(OUTPUT).elf	:	$(OFILES)
 111.123 + 
 111.124 +#---------------------------------------------------------------------------------
 111.125 +%.pcx.o	:	%.pcx
 111.126 +#---------------------------------------------------------------------------------
 111.127 +	@echo $(notdir $<)
 111.128 +	@$(bin2o)
 111.129 + 
 111.130 + 
 111.131 +-include $(DEPENDS)
 111.132 + 
 111.133 +#---------------------------------------------------------------------------------------
 111.134 +endif
 111.135 +#---------------------------------------------------------------------------------------
   112.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   112.2 +++ b/test/nds-test-progs/general/source/main.c	Wed Aug 27 15:10:03 2008 +0000
   112.3 @@ -0,0 +1,96 @@
   112.4 +
   112.5 +#include <SDL/SDL.h>
   112.6 +#if defined(NDS) || defined(__NDS__) || defined (__NDS)
   112.7 +#include <nds.h>
   112.8 +#include <fat.h>
   112.9 +#else
  112.10 +#define swiWaitForVBlank()
  112.11 +#define consoleDemoInit()
  112.12 +#define fatInitDefault()
  112.13 +#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
  112.14 +#endif
  112.15 +    void
  112.16 +splash(SDL_Surface * screen, int s)
  112.17 +{
  112.18 +    SDL_Surface *logo;
  112.19 +    SDL_Rect area = { 0, 0, 256, 192 };
  112.20 +
  112.21 +    logo = SDL_LoadBMP("sdl.bmp");
  112.22 +    if (!logo) {
  112.23 +        printf("Couldn't splash.\n");
  112.24 +        return;
  112.25 +    }
  112.26 +    /*logo->flags &= ~SDL_PREALLOC; */
  112.27 +    SDL_BlitSurface(logo, NULL, screen, &area);
  112.28 +    SDL_Flip(screen);
  112.29 +    while (s-- > 0) {
  112.30 +        int i = 60;
  112.31 +        while (--i)
  112.32 +            swiWaitForVBlank();
  112.33 +    }
  112.34 +}
  112.35 +
  112.36 +
  112.37 int
  112.38 +main(void)
  112.39 +{
  112.40 +    SDL_Surface *screen;
  112.41 +    SDL_Joystick *stick;
  112.42 +    SDL_Event event;
  112.43 +    SDL_Rect rect = { 0, 0, 256, 192 };
  112.44 +    int i;
  112.45 +
  112.46 +    consoleDemoInit();
  112.47 +    puts("Hello world!  Initializing FAT...");
  112.48 +    fatInitDefault();
  112.49 +    
  112.50 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
  112.51 +        puts("# error initializing SDL");
  112.52 +        puts(SDL_GetError());
  112.53 +        return 1;
  112.54 +    }
  112.55 +    puts("* initialized SDL");
  112.56 +    screen = SDL_SetVideoMode(256, 192, 15, SDL_SWSURFACE);
  112.57 +    if (!screen) {
  112.58 +        puts("# error setting video mode");
  112.59 +        puts(SDL_GetError());
  112.60 +        return 2;
  112.61 +    }
  112.62 +    screen->flags &= ~SDL_PREALLOC;
  112.63 +    puts("* set video mode");
  112.64 +    stick = SDL_JoystickOpen(0);
  112.65 +    if (stick == NULL) {
  112.66 +        puts("# error opening joystick");
  112.67 +        puts(SDL_GetError());
  112.68 +//              return 3;
  112.69 +    }
  112.70 +    puts("* opened joystick");
  112.71 +
  112.72 +    /*splash(screen, 3); */
  112.73 +
  112.74 +    SDL_FillRect(screen, &rect, RGB15(0, 0, 31) | 0x8000);
  112.75 +    SDL_Flip(screen);
  112.76 +
  112.77 +    while (1)
  112.78 +        while (SDL_PollEvent(&event))
  112.79 +            switch (event.type) {
  112.80 +            case SDL_JOYBUTTONDOWN:
  112.81 +                SDL_FillRect(screen, &rect, (u16) rand() | 0x8000);
  112.82 +                SDL_Flip(screen);
  112.83 +                if (rect.w > 8) {
  112.84 +                    rect.x += 4;
  112.85 +                    rect.y += 3;
  112.86 +                    rect.w -= 8;
  112.87 +                    rect.h -= 6;
  112.88 +                }
  112.89 +                printf("button %d pressed at %d ticks\n",
  112.90 +                       event.jbutton.which, SDL_GetTicks());
  112.91 +                break;
  112.92 +            case SDL_QUIT:
  112.93 +                SDL_Quit();
  112.94 +                return 0;
  112.95 +            default:
  112.96 +                break;
  112.97 +            }
  112.98 +    
  112.99 return 0;
 112.100 +
 112.101 }
 112.102 +
 112.103 +
   113.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   113.2 +++ b/test/nds-test-progs/sprite/Makefile	Wed Aug 27 15:10:03 2008 +0000
   113.3 @@ -0,0 +1,132 @@
   113.4 +#---------------------------------------------------------------------------------
   113.5 +.SUFFIXES:
   113.6 +#---------------------------------------------------------------------------------
   113.7 +
   113.8 +ifeq ($(strip $(DEVKITARM)),)
   113.9 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
  113.10 +endif
  113.11 +
  113.12 +include $(DEVKITARM)/ds_rules
  113.13 +
  113.14 +#---------------------------------------------------------------------------------
  113.15 +# TARGET is the name of the output
  113.16 +# BUILD is the directory where object files & intermediate files will be placed
  113.17 +# SOURCES is a list of directories containing source code
  113.18 +# INCLUDES is a list of directories containing extra header files
  113.19 +#---------------------------------------------------------------------------------
  113.20 +TARGET		:=	$(shell basename $(CURDIR))
  113.21 +BUILD		:=	build
  113.22 +SOURCES		:=	source
  113.23 +DATA		:=	data  
  113.24 +INCLUDES	:=	include
  113.25 +
  113.26 +#---------------------------------------------------------------------------------
  113.27 +# options for code generation
  113.28 +#---------------------------------------------------------------------------------
  113.29 +ARCH	:=	-mthumb -mthumb-interwork
  113.30 +
  113.31 +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
  113.32 +# *insists* it has a FPU or VFP, and it won't take no for an answer!
  113.33 +CFLAGS	:=	-save-temps -g -Wall -O0\
  113.34 + 			-mcpu=arm9tdmi -mtune=arm9tdmi \
  113.35 +			$(ARCH)
  113.36 +
  113.37 +CFLAGS	+=	$(INCLUDE) -DARM9 -D__NDS__
  113.38 +CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti
  113.39 +
  113.40 +ASFLAGS	:=	-g $(ARCH)
  113.41 +LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
  113.42 +
  113.43 +#---------------------------------------------------------------------------------
  113.44 +# any extra libraries we wish to link with the project
  113.45 +#---------------------------------------------------------------------------------
  113.46 +LIBS	:= -lSDL -lfat -lnds9
  113.47 + 
  113.48 + 
  113.49 +#---------------------------------------------------------------------------------
  113.50 +# list of directories containing libraries, this must be the top level containing
  113.51 +# include and lib
  113.52 +#---------------------------------------------------------------------------------
  113.53 +LIBDIRS	:=	$(LIBNDS)
  113.54 + 
  113.55 +#---------------------------------------------------------------------------------
  113.56 +# no real need to edit anything past this point unless you need to add additional
  113.57 +# rules for different file extensions
  113.58 +#---------------------------------------------------------------------------------
  113.59 +ifneq ($(BUILD),$(notdir $(CURDIR)))
  113.60 +#---------------------------------------------------------------------------------
  113.61 + 
  113.62 +export OUTPUT	:=	$(CURDIR)/$(TARGET)
  113.63 + 
  113.64 +export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  113.65 +					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
  113.66 +
  113.67 +export DEPSDIR	:=	$(CURDIR)/$(BUILD)
  113.68 +
  113.69 +CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  113.70 +CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  113.71 +SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  113.72 +BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  113.73 + 
  113.74 +#---------------------------------------------------------------------------------
  113.75 +# use CXX for linking C++ projects, CC for standard C
  113.76 +#---------------------------------------------------------------------------------
  113.77 +ifeq ($(strip $(CPPFILES)),)
  113.78 +#---------------------------------------------------------------------------------
  113.79 +	export LD	:=	$(CC)
  113.80 +#---------------------------------------------------------------------------------
  113.81 +else
  113.82 +#---------------------------------------------------------------------------------
  113.83 +	export LD	:=	$(CXX)
  113.84 +#---------------------------------------------------------------------------------
  113.85 +endif
  113.86 +#---------------------------------------------------------------------------------
  113.87 +
  113.88 +export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
  113.89 +					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  113.90 + 
  113.91 +export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  113.92 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  113.93 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  113.94 +					-I$(CURDIR)/$(BUILD)
  113.95 + 
  113.96 +export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  113.97 + 
  113.98 +.PHONY: $(BUILD) clean
  113.99 + 
 113.100 +#---------------------------------------------------------------------------------
 113.101 +$(BUILD):
 113.102 +	@[ -d $@ ] || mkdir -p $@
 113.103 +	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
 113.104 + 
 113.105 +#---------------------------------------------------------------------------------
 113.106 +clean:
 113.107 +	@echo clean ...
 113.108 +	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba 
 113.109 + 
 113.110 + 
 113.111 +#---------------------------------------------------------------------------------
 113.112 +else
 113.113 + 
 113.114 +DEPENDS	:=	$(OFILES:.o=.d)
 113.115 + 
 113.116 +#---------------------------------------------------------------------------------
 113.117 +# main targets
 113.118 +#---------------------------------------------------------------------------------
 113.119 +$(OUTPUT).ds.gba	: 	$(OUTPUT).nds
 113.120 +$(OUTPUT).nds	: 	$(OUTPUT).arm9
 113.121 +$(OUTPUT).arm9	:	$(OUTPUT).elf
 113.122 +$(OUTPUT).elf	:	$(OFILES)
 113.123 + 
 113.124 +#---------------------------------------------------------------------------------
 113.125 +%.pcx.o	:	%.pcx
 113.126 +#---------------------------------------------------------------------------------
 113.127 +	@echo $(notdir $<)
 113.128 +	@$(bin2o)
 113.129 + 
 113.130 + 
 113.131 +-include $(DEPENDS)
 113.132 + 
 113.133 +#---------------------------------------------------------------------------------------
 113.134 +endif
 113.135 +#---------------------------------------------------------------------------------------
   114.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   114.2 +++ b/test/nds-test-progs/sprite/source/common.c	Wed Aug 27 15:10:03 2008 +0000
   114.3 @@ -0,0 +1,965 @@
   114.4 +
   114.5 +/* A simple test program framework */
   114.6 +
   114.7 +#include <stdio.h>
   114.8 +
   114.9 +#include "common.h"
  114.10 +
  114.11 +#define VIDEO_USAGE \
  114.12 +"[--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]"
  114.13 +
  114.14 +#define AUDIO_USAGE \
  114.15 +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
  114.16 +
  114.17 +CommonState *
  114.18 +CommonCreateState(char **argv, Uint32 flags)
  114.19 +{
  114.20 +    CommonState *state = SDL_calloc(1, sizeof(*state));
  114.21 +    if (!state) {
  114.22 +        SDL_OutOfMemory();
  114.23 +        return NULL;
  114.24 +    }
  114.25 +
  114.26 +    /* Initialize some defaults */
  114.27 +    state->argv = argv;
  114.28 +    state->flags = flags;
  114.29 +    state->window_title = argv[0];
  114.30 +    state->window_flags = SDL_WINDOW_SHOWN;
  114.31 +    state->window_x = SDL_WINDOWPOS_UNDEFINED;
  114.32 +    state->window_y = SDL_WINDOWPOS_UNDEFINED;
  114.33 +    state->window_w = 256;
  114.34 +    state->window_h = 192;
  114.35 +    state->num_windows = 1;
  114.36 +    state->audiospec.freq = 22050;
  114.37 +    state->audiospec.format = AUDIO_S16;
  114.38 +    state->audiospec.channels = 2;
  114.39 +    state->audiospec.samples = 2048;
  114.40 +    return state;
  114.41 +}
  114.42 +
  114.43 +int
  114.44 +CommonArg(CommonState * state, int index)
  114.45 +{
  114.46 +    char **argv = state->argv;
  114.47 +
  114.48 +    if (SDL_strcasecmp(argv[index], "--video") == 0) {
  114.49 +        ++index;
  114.50 +        if (!argv[index]) {
  114.51 +            return -1;
  114.52 +        }
  114.53 +        state->videodriver = argv[index];
  114.54 +        return 2;
  114.55 +    }
  114.56 +    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
  114.57 +        ++index;
  114.58 +        if (!argv[index]) {
  114.59 +            return -1;
  114.60 +        }
  114.61 +        state->renderdriver = argv[index];
  114.62 +        return 2;
  114.63 +    }
  114.64 +    if (SDL_strcasecmp(argv[index], "--info") == 0) {
  114.65 +        ++index;
  114.66 +        if (!argv[index]) {
  114.67 +            return -1;
  114.68 +        }
  114.69 +        if (SDL_strcasecmp(argv[index], "all") == 0) {
  114.70 +            state->verbose |=
  114.71 +                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
  114.72 +                 VERBOSE_EVENT);
  114.73 +            return 2;
  114.74 +        }
  114.75 +        if (SDL_strcasecmp(argv[index], "video") == 0) {
  114.76 +            state->verbose |= VERBOSE_VIDEO;
  114.77 +            return 2;
  114.78 +        }
  114.79 +        if (SDL_strcasecmp(argv[index], "modes") == 0) {
  114.80 +            state->verbose |= VERBOSE_MODES;
  114.81 +            return 2;
  114.82 +        }
  114.83 +        if (SDL_strcasecmp(argv[index], "render") == 0) {
  114.84 +            state->verbose |= VERBOSE_RENDER;
  114.85 +            return 2;
  114.86 +        }
  114.87 +        if (SDL_strcasecmp(argv[index], "event") == 0) {
  114.88 +            state->verbose |= VERBOSE_EVENT;
  114.89 +            return 2;
  114.90 +        }
  114.91 +        return -1;
  114.92 +    }
  114.93 +    if (SDL_strcasecmp(argv[index], "--display") == 0) {
  114.94 +        ++index;
  114.95 +        if (!argv[index]) {
  114.96 +            return -1;
  114.97 +        }
  114.98 +        state->display = SDL_atoi(argv[index]);
  114.99 +        return 2;
 114.100 +    }
 114.101 +    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
 114.102 +        state->window_flags |= SDL_WINDOW_FULLSCREEN;
 114.103 +        state->num_windows = 1;
 114.104 +        return 1;
 114.105 +    }
 114.106 +    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
 114.107 +        ++index;
 114.108 +        if (!argv[index] || !SDL_isdigit(*argv[index])) {
 114.109 +            return -1;
 114.110 +        }
 114.111 +        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
 114.112 +            state->num_windows = SDL_atoi(argv[index]);
 114.113 +        }
 114.114 +        return 2;
 114.115 +    }
 114.116 +    if (SDL_strcasecmp(argv[index], "--title") == 0) {
 114.117 +        ++index;
 114.118 +        if (!argv[index]) {
 114.119 +            return -1;
 114.120 +        }
 114.121 +        state->window_title = argv[index];
 114.122 +        return 2;
 114.123 +    }
 114.124 +    if (SDL_strcasecmp(argv[index], "--center") == 0) {
 114.125 +        state->window_x = SDL_WINDOWPOS_CENTERED;
 114.126 +        state->window_y = SDL_WINDOWPOS_CENTERED;
 114.127 +        return 1;
 114.128 +    }
 114.129 +    if (SDL_strcasecmp(argv[index], "--position") == 0) {
 114.130 +        char *x, *y;
 114.131 +        ++index;
 114.132 +        if (!argv[index]) {
 114.133 +            return -1;
 114.134 +        }
 114.135 +        x = argv[index];
 114.136 +        y = argv[index];
 114.137 +        while (*y && *y != ',') {
 114.138 +            ++y;
 114.139 +        }
 114.140 +        if (!*y) {
 114.141 +            return -1;
 114.142 +        }
 114.143 +        *y++ = '\0';
 114.144 +        state->window_x = SDL_atoi(x);
 114.145 +        state->window_y = SDL_atoi(y);
 114.146 +        return 2;
 114.147 +    }
 114.148 +    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
 114.149 +        char *w, *h;
 114.150 +        ++index;
 114.151 +        if (!argv[index]) {
 114.152 +            return -1;
 114.153 +        }
 114.154 +        w = argv[index];
 114.155 +        h = argv[index];
 114.156 +        while (*h && *h != 'x') {
 114.157 +            ++h;
 114.158 +        }
 114.159 +        if (!*h) {
 114.160 +            return -1;
 114.161 +        }
 114.162 +        *h++ = '\0';
 114.163 +        state->window_w = SDL_atoi(w);
 114.164 +        state->window_h = SDL_atoi(h);
 114.165 +        return 2;
 114.166 +    }
 114.167 +    if (SDL_strcasecmp(argv[index], "--depth") == 0) {
 114.168 +        ++index;
 114.169 +        if (!argv[index]) {
 114.170 +            return -1;
 114.171 +        }
 114.172 +        state->depth = SDL_atoi(argv[index]);
 114.173 +        return 2;
 114.174 +    }
 114.175 +    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
 114.176 +        ++index;
 114.177 +        if (!argv[index]) {
 114.178 +            return -1;
 114.179 +        }
 114.180 +        state->refresh_rate = SDL_atoi(argv[index]);
 114.181 +        return 2;
 114.182 +    }
 114.183 +    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
 114.184 +        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
 114.185 +        return 1;
 114.186 +    }
 114.187 +    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
 114.188 +        state->window_flags |= SDL_WINDOW_BORDERLESS;
 114.189 +        return 1;
 114.190 +    }
 114.191 +    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
 114.192 +        state->window_flags |= SDL_WINDOW_RESIZABLE;
 114.193 +        return 1;
 114.194 +    }
 114.195 +    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
 114.196 +        state->window_flags |= SDL_WINDOW_MINIMIZED;
 114.197 +        return 1;
 114.198 +    }
 114.199 +    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
 114.200 +        state->window_flags |= SDL_WINDOW_MAXIMIZED;
 114.201 +        return 1;
 114.202 +    }
 114.203 +    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
 114.204 +        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
 114.205 +        return 1;
 114.206 +    }
 114.207 +    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
 114.208 +        ++index;
 114.209 +        if (!argv[index]) {
 114.210 +            return -1;
 114.211 +        }
 114.212 +        state->audiospec.freq = SDL_atoi(argv[index]);
 114.213 +        return 2;
 114.214 +    }
 114.215 +    if (SDL_strcasecmp(argv[index], "--format") == 0) {
 114.216 +        ++index;
 114.217 +        if (!argv[index]) {
 114.218 +            return -1;
 114.219 +        }
 114.220 +        if (SDL_strcasecmp(argv[index], "U8") == 0) {
 114.221 +            state->audiospec.format = AUDIO_U8;
 114.222 +            return 2;
 114.223 +        }
 114.224 +        if (SDL_strcasecmp(argv[index], "S8") == 0) {
 114.225 +            state->audiospec.format = AUDIO_S8;
 114.226 +            return 2;
 114.227 +        }
 114.228 +        if (SDL_strcasecmp(argv[index], "U16") == 0) {
 114.229 +            state->audiospec.format = AUDIO_U16;
 114.230 +            return 2;
 114.231 +        }
 114.232 +        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
 114.233 +            state->audiospec.format = AUDIO_U16LSB;
 114.234 +            return 2;
 114.235 +        }
 114.236 +        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
 114.237 +            state->audiospec.format = AUDIO_U16MSB;
 114.238 +            return 2;
 114.239 +        }
 114.240 +        if (SDL_strcasecmp(argv[index], "S16") == 0) {
 114.241 +            state->audiospec.format = AUDIO_S16;
 114.242 +            return 2;
 114.243 +        }
 114.244 +        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
 114.245 +            state->audiospec.format = AUDIO_S16LSB;
 114.246 +            return 2;
 114.247 +        }
 114.248 +        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
 114.249 +            state->audiospec.format = AUDIO_S16MSB;
 114.250 +            return 2;
 114.251 +        }
 114.252 +        return -1;
 114.253 +    }
 114.254 +    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
 114.255 +        ++index;
 114.256 +        if (!argv[index]) {
 114.257 +            return -1;
 114.258 +        }
 114.259 +        state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
 114.260 +        return 2;
 114.261 +    }
 114.262 +    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
 114.263 +        ++index;
 114.264 +        if (!argv[index]) {
 114.265 +            return -1;
 114.266 +        }
 114.267 +        state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
 114.268 +        return 2;
 114.269 +    }
 114.270 +    if ((SDL_strcasecmp(argv[index], "-h") == 0)
 114.271 +        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
 114.272 +        /* Print the usage message */
 114.273 +        return -1;
 114.274 +    }
 114.275 +    return 0;
 114.276 +}
 114.277 +
 114.278 +const char *
 114.279 +CommonUsage(CommonState * state)
 114.280 +{
 114.281 +    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
 114.282 +    case SDL_INIT_VIDEO:
 114.283 +        return VIDEO_USAGE;
 114.284 +    case SDL_INIT_AUDIO:
 114.285 +        return AUDIO_USAGE;
 114.286 +    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
 114.287 +        return VIDEO_USAGE " " AUDIO_USAGE;
 114.288 +    default:
 114.289 +        return "";
 114.290 +    }
 114.291 +}
 114.292 +
 114.293 +static void
 114.294 +PrintRendererFlag(Uint32 flag)
 114.295 +{
 114.296 +    switch (flag) {
 114.297 +    case SDL_RENDERER_SINGLEBUFFER:
 114.298 +        fprintf(stderr, "SingleBuffer");
 114.299 +        break;
 114.300 +    case SDL_RENDERER_PRESENTCOPY:
 114.301 +        fprintf(stderr, "PresentCopy");
 114.302 +        break;
 114.303 +    case SDL_RENDERER_PRESENTFLIP2:
 114.304 +        fprintf(stderr, "PresentFlip2");
 114.305 +        break;
 114.306 +    case SDL_RENDERER_PRESENTFLIP3:
 114.307 +        fprintf(stderr, "PresentFlip3");
 114.308 +        break;
 114.309 +    case SDL_RENDERER_PRESENTDISCARD:
 114.310 +        fprintf(stderr, "PresentDiscard");
 114.311 +        break;
 114.312 +    case SDL_RENDERER_PRESENTVSYNC:
 114.313 +        fprintf(stderr, "PresentVSync");
 114.314 +        break;
 114.315 +    case SDL_RENDERER_ACCELERATED:
 114.316 +        fprintf(stderr, "Accelerated");
 114.317 +        break;
 114.318 +    default:
 114.319 +        fprintf(stderr, "0x%8.8x", flag);
 114.320 +        break;
 114.321 +    }
 114.322 +}
 114.323 +
 114.324 +static void
 114.325 +PrintBlendMode(Uint32 flag)
 114.326 +{
 114.327 +    switch (flag) {
 114.328 +    case SDL_TEXTUREBLENDMODE_NONE:
 114.329 +        fprintf(stderr, "None");
 114.330 +        break;
 114.331 +    case SDL_TEXTUREBLENDMODE_MASK:
 114.332 +        fprintf(stderr, "Mask");
 114.333 +        break;
 114.334 +    case SDL_TEXTUREBLENDMODE_BLEND:
 114.335 +        fprintf(stderr, "Blend");
 114.336 +        break;
 114.337 +    case SDL_TEXTUREBLENDMODE_ADD:
 114.338 +        fprintf(stderr, "Add");
 114.339 +        break;
 114.340 +    case SDL_TEXTUREBLENDMODE_MOD:
 114.341 +        fprintf(stderr, "Mod");
 114.342 +        break;
 114.343 +    default:
 114.344 +        fprintf(stderr, "0x%8.8x", flag);
 114.345 +        break;
 114.346 +    }
 114.347 +}
 114.348 +
 114.349 +static void
 114.350 +PrintScaleMode(Uint32 flag)
 114.351 +{
 114.352 +    switch (flag) {
 114.353 +    case SDL_TEXTURESCALEMODE_NONE:
 114.354 +        fprintf(stderr, "None");
 114.355 +        break;
 114.356 +    case SDL_TEXTURESCALEMODE_FAST:
 114.357 +        fprintf(stderr, "Fast");
 114.358 +        break;
 114.359 +    case SDL_TEXTURESCALEMODE_SLOW:
 114.360 +        fprintf(stderr, "Slow");
 114.361 +        break;
 114.362 +    case SDL_TEXTURESCALEMODE_BEST:
 114.363 +        fprintf(stderr, "Best");
 114.364 +        break;
 114.365 +    default:
 114.366 +        fprintf(stderr, "0x%8.8x", flag);
 114.367 +        break;
 114.368 +    }
 114.369 +}
 114.370 +
 114.371 +static void
 114.372 +PrintPixelFormat(Uint32 format)
 114.373 +{
 114.374 +    switch (format) {
 114.375 +    case SDL_PIXELFORMAT_UNKNOWN:
 114.376 +        fprintf(stderr, "Unknwon");
 114.377 +        break;
 114.378 +    case SDL_PIXELFORMAT_INDEX1LSB:
 114.379 +        fprintf(stderr, "Index1LSB");
 114.380 +        break;
 114.381 +    case SDL_PIXELFORMAT_INDEX1MSB:
 114.382 +        fprintf(stderr, "Index1MSB");
 114.383 +        break;
 114.384 +    case SDL_PIXELFORMAT_INDEX4LSB:
 114.385 +        fprintf(stderr, "Index4LSB");
 114.386 +        break;
 114.387 +    case SDL_PIXELFORMAT_INDEX4MSB:
 114.388 +        fprintf(stderr, "Index4MSB");
 114.389 +        break;
 114.390 +    case SDL_PIXELFORMAT_INDEX8:
 114.391 +        fprintf(stderr, "Index8");
 114.392 +        break;
 114.393 +    case SDL_PIXELFORMAT_RGB332:
 114.394 +        fprintf(stderr, "RGB332");
 114.395 +        break;
 114.396 +    case SDL_PIXELFORMAT_RGB444:
 114.397 +        fprintf(stderr, "RGB444");
 114.398 +        break;
 114.399 +    case SDL_PIXELFORMAT_RGB555:
 114.400 +        fprintf(stderr, "RGB555");
 114.401 +        break;
 114.402 +    case SDL_PIXELFORMAT_ARGB4444:
 114.403 +        fprintf(stderr, "ARGB4444");
 114.404 +        break;
 114.405 +    case SDL_PIXELFORMAT_ARGB1555:
 114.406 +        fprintf(stderr, "ARGB1555");
 114.407 +        break;
 114.408 +    case SDL_PIXELFORMAT_RGB565:
 114.409 +        fprintf(stderr, "RGB565");
 114.410 +        break;
 114.411 +    case SDL_PIXELFORMAT_RGB24:
 114.412 +        fprintf(stderr, "RGB24");
 114.413 +        break;
 114.414 +    case SDL_PIXELFORMAT_BGR24:
 114.415 +        fprintf(stderr, "BGR24");
 114.416 +        break;
 114.417 +    case SDL_PIXELFORMAT_RGB888:
 114.418 +        fprintf(stderr, "RGB888");
 114.419 +        break;
 114.420 +    case SDL_PIXELFORMAT_BGR888:
 114.421 +        fprintf(stderr, "BGR888");
 114.422 +        break;
 114.423 +    case SDL_PIXELFORMAT_ARGB8888:
 114.424 +        fprintf(stderr, "ARGB8888");
 114.425 +        break;
 114.426 +    case SDL_PIXELFORMAT_RGBA8888:
 114.427 +        fprintf(stderr, "RGBA8888");
 114.428 +        break;
 114.429 +    case SDL_PIXELFORMAT_ABGR8888:
 114.430 +        fprintf(stderr, "ABGR8888");
 114.431 +        break;
 114.432 +    case SDL_PIXELFORMAT_BGRA8888:
 114.433 +        fprintf(stderr, "BGRA8888");
 114.434 +        break;
 114.435 +    case SDL_PIXELFORMAT_ARGB2101010:
 114.436 +        fprintf(stderr, "ARGB2101010");
 114.437 +        break;
 114.438 +    case SDL_PIXELFORMAT_YV12:
 114.439 +        fprintf(stderr, "YV12");
 114.440 +        break;
 114.441 +    case SDL_PIXELFORMAT_IYUV:
 114.442 +        fprintf(stderr, "IYUV");
 114.443 +        break;
 114.444 +    case SDL_PIXELFORMAT_YUY2:
 114.445 +        fprintf(stderr, "YUY2");
 114.446 +        break;
 114.447 +    case SDL_PIXELFORMAT_UYVY:
 114.448 +        fprintf(stderr, "UYVY");
 114.449 +        break;
 114.450 +    case SDL_PIXELFORMAT_YVYU:
 114.451 +        fprintf(stderr, "YVYU");
 114.452 +        break;
 114.453 +    case SDL_PIXELFORMAT_ABGR1555:
 114.454 +        fprintf(stderr, "ABGR1555");
 114.455 +        break;
 114.456 +    case SDL_PIXELFORMAT_BGR555:
 114.457 +        fprintf(stderr, "BGR555");
 114.458 +        break;
 114.459 +    default:
 114.460 +        fprintf(stderr, "0x%8.8x", format);
 114.461 +        break;
 114.462 +    }
 114.463 +}
 114.464 +
 114.465 +static void
 114.466 +PrintRenderer(SDL_RendererInfo * info)
 114.467 +{
 114.468 +    int i, count;
 114.469 +
 114.470 +    fprintf(stderr, "  Renderer %s:\n", info->name);
 114.471 +
 114.472 +    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
 114.473 +    fprintf(stderr, " (");
 114.474 +    count = 0;
 114.475 +    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
 114.476 +        Uint32 flag = (1 << i);
 114.477 +        if (info->flags & flag) {
 114.478 +            if (count > 0) {
 114.479 +                fprintf(stderr, " | ");
 114.480 +            }
 114.481 +            PrintRendererFlag(flag);
 114.482 +            ++count;
 114.483 +        }
 114.484 +    }
 114.485 +    fprintf(stderr, ")\n");
 114.486 +
 114.487 +    fprintf(stderr, "    Blend: 0x%8.8X", info->blend_modes);
 114.488 +    fprintf(stderr, " (");
 114.489 +    count = 0;
 114.490 +    for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) {
 114.491 +        Uint32 flag = (1 << i);
 114.492 +        if (info->blend_modes & flag) {
 114.493 +            if (count > 0) {
 114.494 +                fprintf(stderr, " | ");
 114.495 +            }
 114.496 +            PrintBlendMode(flag);
 114.497 +            ++count;
 114.498 +        }
 114.499 +    }
 114.500 +    fprintf(stderr, ")\n");
 114.501 +
 114.502 +    fprintf(stderr, "    Scale: 0x%8.8X", info->scale_modes);
 114.503 +    fprintf(stderr, " (");
 114.504 +    count = 0;
 114.505 +    for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) {
 114.506 +        Uint32 flag = (1 << i);
 114.507 +        if (info->scale_modes & flag) {
 114.508 +            if (count > 0) {
 114.509 +                fprintf(stderr, " | ");
 114.510 +            }
 114.511 +            PrintScaleMode(flag);
 114.512 +            ++count;
 114.513 +        }
 114.514 +    }
 114.515 +    fprintf(stderr, ")\n");
 114.516 +
 114.517 +    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
 114.518 +    for (i = 0; i < (int) info->num_texture_formats; ++i) {
 114.519 +        if (i > 0) {
 114.520 +            fprintf(stderr, ", ");
 114.521 +        }
 114.522 +        PrintPixelFormat(info->texture_formats[i]);
 114.523 +    }
 114.524 +    fprintf(stderr, "\n");
 114.525 +
 114.526 +    if (info->max_texture_width || info->max_texture_height) {
 114.527 +        fprintf(stderr, "    Max Texture Size: %dx%d\n",
 114.528 +                info->max_texture_width, info->max_texture_height);
 114.529 +    }
 114.530 +}
 114.531 +
 114.532 +SDL_bool
 114.533 +CommonInit(CommonState * state)
 114.534 +{
 114.535 +    int i, j, m, n;
 114.536 +    SDL_DisplayMode fullscreen_mode;
 114.537 +
 114.538 +    if (state->flags & SDL_INIT_VIDEO) {
 114.539 +        if (state->verbose & VERBOSE_VIDEO) {
 114.540 +            n = SDL_GetNumVideoDrivers();
 114.541 +            if (n == 0) {
 114.542 +                fprintf(stderr, "No built-in video drivers\n");
 114.543 +            } else {
 114.544 +                fprintf(stderr, "Built-in video drivers:");
 114.545 +                for (i = 0; i < n; ++i) {
 114.546 +                    if (i > 0) {
 114.547 +                        fprintf(stderr, ",");
 114.548 +                    }
 114.549 +                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
 114.550 +                }
 114.551 +                fprintf(stderr, "\n");
 114.552 +            }
 114.553 +        }
 114.554 +        if (SDL_VideoInit(state->videodriver, 0) < 0) {
 114.555 +            fprintf(stderr, "Couldn't initialize video driver: %s\n",
 114.556 +                    SDL_GetError());
 114.557 +            return SDL_FALSE;
 114.558 +        }
 114.559 +        if (state->verbose & VERBOSE_VIDEO) {
 114.560 +            fprintf(stderr, "Video driver: %s\n",
 114.561 +                    SDL_GetCurrentVideoDriver());
 114.562 +        }
 114.563 +
 114.564 +        if (state->verbose & VERBOSE_MODES) {
 114.565 +            SDL_DisplayMode mode;
 114.566 +            int bpp;
 114.567 +            Uint32 Rmask, Gmask, Bmask, Amask;
 114.568 +
 114.569 +            n = SDL_GetNumVideoDisplays();
 114.570 +            fprintf(stderr, "Number of displays: %d\n", n);
 114.571 +            for (i = 0; i < n; ++i) {
 114.572 +                fprintf(stderr, "Display %d:\n", i);
 114.573 +                SDL_SelectVideoDisplay(i);
 114.574 +
 114.575 +                SDL_GetDesktopDisplayMode(&mode);
 114.576 +                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
 114.577 +                                           &Bmask, &Amask);
 114.578 +                fprintf(stderr,
 114.579 +                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel\n",
 114.580 +                        mode.w, mode.h, mode.refresh_rate, bpp);
 114.581 +                if (Rmask || Gmask || Bmask) {
 114.582 +                    fprintf(stderr, "      Red Mask = 0x%.8x\n", Rmask);
 114.583 +                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
 114.584 +                    fprintf(stderr, "      Blue Mask = 0x%.8x\n", Bmask);
 114.585 +                    if (Amask)
 114.586 +                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
 114.587 +                }
 114.588 +
 114.589 +                /* Print available fullscreen video modes */
 114.590 +                m = SDL_GetNumDisplayModes();
 114.591 +                if (m == 0) {
 114.592 +                    fprintf(stderr, "No available fullscreen video modes\n");
 114.593 +                } else {
 114.594 +                    fprintf(stderr, "  Fullscreen video modes:\n");
 114.595 +                    for (j = 0; j < m; ++j) {
 114.596 +                        SDL_GetDisplayMode(j, &mode);
 114.597 +                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
 114.598 +                                                   &Gmask, &Bmask, &Amask);
 114.599 +                        fprintf(stderr,
 114.600 +                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n",
 114.601 +                                j, mode.w, mode.h, mode.refresh_rate, bpp);
 114.602 +                        if (Rmask || Gmask || Bmask) {
 114.603 +                            fprintf(stderr, "        Red Mask = 0x%.8x\n",
 114.604 +                                    Rmask);
 114.605 +                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
 114.606 +                                    Gmask);
 114.607 +                            fprintf(stderr, "        Blue Mask = 0x%.8x\n",
 114.608 +                                    Bmask);
 114.609 +                            if (Amask)
 114.610 +                                fprintf(stderr,
 114.611 +                                        "        Alpha Mask = 0x%.8x\n",
 114.612 +                                        Amask);
 114.613 +                        }
 114.614 +                    }
 114.615 +                }
 114.616 +            }
 114.617 +        }
 114.618 +
 114.619 +        SDL_SelectVideoDisplay(state->display);
 114.620 +        if (state->verbose & VERBOSE_RENDER) {
 114.621 +            SDL_RendererInfo info;
 114.622 +
 114.623 +            n = SDL_GetNumRenderDrivers();
 114.624 +            if (n == 0) {
 114.625 +                fprintf(stderr, "No built-in render drivers\n");
 114.626 +            } else {
 114.627 +                fprintf(stderr, "Built-in render drivers:\n");
 114.628 +                for (i = 0; i < n; ++i) {
 114.629 +                    SDL_GetRenderDriverInfo(i, &info);
 114.630 +                    PrintRenderer(&info);
 114.631 +                }
 114.632 +            }
 114.633 +        }
 114.634 +
 114.635 +        switch (state->depth) {
 114.636 +        case 8:
 114.637 +            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
 114.638 +            break;
 114.639 +        case 15:
 114.640 +            fullscreen_mode.format = SDL_PIXELFORMAT_BGR555;
 114.641 +            break;
 114.642 +        case 16:
 114.643 +        default:
 114.644 +            fullscreen_mode.format = SDL_PIXELFORMAT_ABGR1555;
 114.645 +            break;
 114.646 +/* NDS       default:
 114.647 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
 114.648 +            break;*/
 114.649 +        }
 114.650 +        fullscreen_mode.w = state->window_w;
 114.651 +        fullscreen_mode.h = state->window_h;
 114.652 +        fullscreen_mode.refresh_rate = state->refresh_rate;
 114.653 +        SDL_SetFullscreenDisplayMode(&fullscreen_mode);
 114.654 +
 114.655 +        state->windows =
 114.656 +            (SDL_WindowID *) SDL_malloc(state->num_windows *
 114.657 +                                        sizeof(*state->windows));
 114.658 +        if (!state->windows) {
 114.659 +            fprintf(stderr, "Out of memory!\n");
 114.660 +            return SDL_FALSE;
 114.661 +        }
 114.662 +        for (i = 0; i < state->num_windows; ++i) {
 114.663 +            char title[1024];
 114.664 +
 114.665 +            if (state->num_windows > 1) {
 114.666 +                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
 114.667 +                             state->window_title, i + 1);
 114.668 +            } else {
 114.669 +                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
 114.670 +            }
 114.671 +            state->windows[i] =
 114.672 +                SDL_CreateWindow(title, state->window_x, state->window_y,
 114.673 +                                 state->window_w, state->window_h,
 114.674 +                                 state->window_flags);
 114.675 +            if (!state->windows[i]) {
 114.676 +                fprintf(stderr, "Couldn't create window: %s\n",
 114.677 +                        SDL_GetError());
 114.678 +                return SDL_FALSE;
 114.679 +            }
 114.680 +
 114.681 +            if (!state->skip_renderer
 114.682 +                && (state->renderdriver
 114.683 +                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
 114.684 +                m = -1;
 114.685 +                if (state->renderdriver) {
 114.686 +                    SDL_RendererInfo info;
 114.687 +                    n = SDL_GetNumRenderDrivers();
 114.688 +                    for (j = 0; j < n; ++j) {
 114.689 +                        SDL_GetRenderDriverInfo(j, &info);
 114.690 +                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
 114.691 +                            0) {
 114.692 +                            m = j;
 114.693 +                            break;
 114.694 +                        }
 114.695 +                    }
 114.696 +                    if (m == n) {
 114.697 +                        fprintf(stderr,
 114.698 +                                "Couldn't find render driver named %s",
 114.699 +                                state->renderdriver);
 114.700 +                        return SDL_FALSE;
 114.701 +                    }
 114.702 +                }
 114.703 +                if (SDL_CreateRenderer
 114.704 +                    (state->windows[i], m, state->render_flags) < 0) {
 114.705 +                    fprintf(stderr, "Couldn't create renderer: %s\n",
 114.706 +                            SDL_GetError());
 114.707 +                    return SDL_FALSE;
 114.708 +                }
 114.709 +                if (state->verbose & VERBOSE_RENDER) {
 114.710 +                    SDL_RendererInfo info;
 114.711 +
 114.712 +                    fprintf(stderr, "Current renderer:\n");
 114.713 +                    SDL_GetRendererInfo(&info);
 114.714 +                    PrintRenderer(&info);
 114.715 +                }
 114.716 +            }
 114.717 +        }
 114.718 +        SDL_SelectRenderer(state->windows[0]);
 114.719 +    }
 114.720 +
 114.721 +    if (state->flags & SDL_INIT_AUDIO) {
 114.722 +        if (state->verbose & VERBOSE_AUDIO) {
 114.723 +            n = SDL_GetNumAudioDrivers();
 114.724 +            if (n == 0) {
 114.725 +                fprintf(stderr, "No built-in audio drivers\n");
 114.726 +            } else {
 114.727 +                fprintf(stderr, "Built-in audio drivers:");
 114.728 +                for (i = 0; i < n; ++i) {
 114.729 +                    if (i > 0) {
 114.730 +                        fprintf(stderr, ",");
 114.731 +                    }
 114.732 +                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
 114.733 +                }
 114.734 +                fprintf(stderr, "\n");
 114.735 +            }
 114.736 +        }
 114.737 +        if (SDL_AudioInit(state->audiodriver) < 0) {
 114.738 +            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
 114.739 +                    SDL_GetError());
 114.740 +            return SDL_FALSE;
 114.741 +        }
 114.742 +        if (state->verbose & VERBOSE_VIDEO) {
 114.743 +            fprintf(stderr, "Audio driver: %s\n",
 114.744 +                    SDL_GetCurrentAudioDriver());
 114.745 +        }
 114.746 +
 114.747 +        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
 114.748 +            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
 114.749 +            return SDL_FALSE;
 114.750 +        }
 114.751 +    }
 114.752 +
 114.753 +    return SDL_TRUE;
 114.754 +}
 114.755 +
 114.756 +static void
 114.757 +PrintEvent(SDL_Event * event)
 114.758 +{
 114.759 +    fprintf(stderr, "SDL EVENT: ");
 114.760 +    switch (event->type) {
 114.761 +    case SDL_WINDOWEVENT:
 114.762 +        switch (event->window.event) {
 114.763 +        case SDL_WINDOWEVENT_SHOWN:
 114.764 +            fprintf(stderr, "Window %d shown", event->window.windowID);
 114.765 +            break;
 114.766 +        case SDL_WINDOWEVENT_HIDDEN:
 114.767 +            fprintf(stderr, "Window %d hidden", event->window.windowID);
 114.768 +            break;
 114.769 +        case SDL_WINDOWEVENT_EXPOSED:
 114.770 +            fprintf(stderr, "Window %d exposed", event->window.windowID);
 114.771 +            break;
 114.772 +        case SDL_WINDOWEVENT_MOVED:
 114.773 +            fprintf(stderr, "Window %d moved to %d,%d",
 114.774 +                    event->window.windowID, event->window.data1,
 114.775 +                    event->window.data2);
 114.776 +            break;
 114.777 +        case SDL_WINDOWEVENT_RESIZED:
 114.778 +            fprintf(stderr, "Window %d resized to %dx%d",
 114.779 +                    event->window.windowID, event->window.data1,
 114.780 +                    event->window.data2);
 114.781 +            break;
 114.782 +        case SDL_WINDOWEVENT_MINIMIZED:
 114.783 +            fprintf(stderr, "Window %d minimized", event->window.windowID);
 114.784 +            break;
 114.785 +        case SDL_WINDOWEVENT_MAXIMIZED:
 114.786 +            fprintf(stderr, "Window %d maximized", event->window.windowID);
 114.787 +            break;
 114.788 +        case SDL_WINDOWEVENT_RESTORED:
 114.789 +            fprintf(stderr, "Window %d restored", event->window.windowID);
 114.790 +            break;
 114.791 +        case SDL_WINDOWEVENT_ENTER:
 114.792 +            fprintf(stderr, "Mouse entered window %d",
 114.793 +                    event->window.windowID);
 114.794 +            break;
 114.795 +        case SDL_WINDOWEVENT_LEAVE:
 114.796 +            fprintf(stderr, "Mouse left window %d", event->window.windowID);
 114.797 +            break;
 114.798 +        case SDL_WINDOWEVENT_FOCUS_GAINED:
 114.799 +            fprintf(stderr, "Window %d gained keyboard focus",
 114.800 +                    event->window.windowID);
 114.801 +            break;
 114.802 +        case SDL_WINDOWEVENT_FOCUS_LOST:
 114.803 +            fprintf(stderr, "Window %d lost keyboard focus",
 114.804 +                    event->window.windowID);
 114.805 +            break;
 114.806 +        case SDL_WINDOWEVENT_CLOSE:
 114.807 +            fprintf(stderr, "Window %d closed", event->window.windowID);
 114.808 +            break;
 114.809 +        default:
 114.810 +            fprintf(stderr, "Window %d got unknown event %d",
 114.811 +                    event->window.windowID, event->window.event);
 114.812 +            break;
 114.813 +        }
 114.814 +        break;
 114.815 +    case SDL_KEYDOWN:
 114.816 +        fprintf(stderr,
 114.817 +                "Keyboard %d: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
 114.818 +                event->key.which, event->key.windowID,
 114.819 +                event->key.keysym.scancode,
 114.820 +                SDL_GetScancodeName(event->key.keysym.scancode),
 114.821 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
 114.822 +        break;
 114.823 +    case SDL_KEYUP:
 114.824 +        fprintf(stderr,
 114.825 +                "Keyboard %d: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
 114.826 +                event->key.which, event->key.windowID,
 114.827 +                event->key.keysym.scancode,
 114.828 +                SDL_GetScancodeName(event->key.keysym.scancode),
 114.829 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
 114.830 +        break;
 114.831 +    case SDL_TEXTINPUT:
 114.832 +        fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d",
 114.833 +                event->text.which, event->text.text, event->text.windowID);
 114.834 +        break;
 114.835 +    case SDL_MOUSEMOTION:
 114.836 +        fprintf(stderr, "Mouse %d: moved to %d,%d (%d,%d) in window %d",
 114.837 +                event->motion.which, event->motion.x, event->motion.y,
 114.838 +                event->motion.xrel, event->motion.yrel,
 114.839 +                event->motion.windowID);
 114.840 +        break;
 114.841 +    case SDL_MOUSEBUTTONDOWN:
 114.842 +        fprintf(stderr, "Mouse %d: button %d pressed at %d,%d in window %d",
 114.843 +                event->button.which, event->button.button, event->button.x,
 114.844 +                event->button.y, event->button.windowID);
 114.845 +        break;
 114.846 +    case SDL_MOUSEBUTTONUP:
 114.847 +        fprintf(stderr, "Mouse %d: button %d released at %d,%d in window %d",
 114.848 +                event->button.which, event->button.button, event->button.x,
 114.849 +                event->button.y, event->button.windowID);
 114.850 +        break;
 114.851 +    case SDL_MOUSEWHEEL:
 114.852 +        fprintf(stderr,
 114.853 +                "Mouse %d: wheel scrolled %d in x and %d in y in window %d",
 114.854 +                event->wheel.which, event->wheel.x, event->wheel.y,
 114.855 +                event->wheel.windowID);
 114.856 +        break;
 114.857 +    case SDL_JOYBALLMOTION:
 114.858 +        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
 114.859 +                event->jball.which, event->jball.ball, event->jball.xrel,
 114.860 +                event->jball.yrel);
 114.861 +        break;
 114.862 +    case SDL_JOYHATMOTION:
 114.863 +        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
 114.864 +                event->jhat.hat);
 114.865 +        switch (event->jhat.value) {
 114.866 +        case SDL_HAT_CENTERED:
 114.867 +            fprintf(stderr, "CENTER");
 114.868 +            break;
 114.869 +        case SDL_HAT_UP:
 114.870 +            fprintf(stderr, "UP");
 114.871 +            break;
 114.872 +        case SDL_HAT_RIGHTUP:
 114.873 +            fprintf(stderr, "RIGHTUP");
 114.874 +            break;
 114.875 +        case SDL_HAT_RIGHT:
 114.876 +            fprintf(stderr, "RIGHT");
 114.877 +            break;
 114.878 +        case SDL_HAT_RIGHTDOWN:
 114.879 +            fprintf(stderr, "RIGHTDOWN");
 114.880 +            break;
 114.881 +        case SDL_HAT_DOWN:
 114.882 +            fprintf(stderr, "DOWN");
 114.883 +            break;
 114.884 +        case SDL_HAT_LEFTDOWN:
 114.885 +            fprintf(stderr, "LEFTDOWN");
 114.886 +            break;
 114.887 +        case SDL_HAT_LEFT:
 114.888 +            fprintf(stderr, "LEFT");
 114.889 +            break;
 114.890 +        case SDL_HAT_LEFTUP:
 114.891 +            fprintf(stderr, "LEFTUP");
 114.892 +            break;
 114.893 +        default:
 114.894 +            fprintf(stderr, "UNKNOWN");
 114.895 +            break;
 114.896 +        }
 114.897 +        break;
 114.898 +    case SDL_JOYBUTTONDOWN:
 114.899 +        fprintf(stderr, "Joystick %d: button %d pressed",
 114.900 +                event->jbutton.which, event->jbutton.button);
 114.901 +        break;
 114.902 +    case SDL_JOYBUTTONUP:
 114.903 +        fprintf(stderr, "Joystick %d: button %d released",
 114.904 +                event->jbutton.which, event->jbutton.button);
 114.905 +        break;
 114.906 +    case SDL_QUIT:
 114.907 +        fprintf(stderr, "Quit requested");
 114.908 +        break;
 114.909 +    case SDL_USEREVENT:
 114.910 +        fprintf(stderr, "User event %d", event->user.code);
 114.911 +        break;
 114.912 +    default:
 114.913 +        fprintf(stderr, "Unknown event %d", event->type);
 114.914 +        break;
 114.915 +    }
 114.916 +    fprintf(stderr, "\n");
 114.917 +}
 114.918 +
 114.919 +void
 114.920 +CommonEvent(CommonState * state, SDL_Event * event, int *done)
 114.921 +{
 114.922 +    if (state->verbose & VERBOSE_EVENT) {
 114.923 +        PrintEvent(event);
 114.924 +    }
 114.925 +
 114.926 +    switch (event->type) {
 114.927 +    case SDL_WINDOWEVENT:
 114.928 +        switch (event->window.event) {
 114.929 +        case SDL_WINDOWEVENT_CLOSE:
 114.930 +            *done = 1;
 114.931 +            break;
 114.932 +        }
 114.933 +        break;
 114.934 +    case SDL_KEYDOWN:
 114.935 +        switch (event->key.keysym.sym) {
 114.936 +            /* Add hotkeys here */
 114.937 +        case SDLK_g:
 114.938 +            if (event->key.keysym.mod & KMOD_CTRL) {
 114.939 +                /* Ctrl-G toggle grab */
 114.940 +            }
 114.941 +            break;
 114.942 +        case SDLK_ESCAPE:
 114.943 +            *done = 1;
 114.944 +            break;
 114.945 +        default:
 114.946 +            break;
 114.947 +        }
 114.948 +        break;
 114.949 +    case SDL_QUIT:
 114.950 +        *done = 1;
 114.951 +        break;
 114.952 +    }
 114.953 +}
 114.954 +
 114.955 +void
 114.956 +CommonQuit(CommonState * state)
 114.957 +{
 114.958 +    if (state->flags & SDL_INIT_VIDEO) {
 114.959 +        SDL_VideoQuit();
 114.960 +    }
 114.961 +    if (state->flags & SDL_INIT_AUDIO) {
 114.962 +        SDL_AudioQuit();
 114.963 +    }
 114.964 +    if (state->windows) {
 114.965 +        SDL_free(state->windows);
 114.966 +    }
 114.967 +    SDL_free(state);
 114.968 +}
   115.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   115.2 +++ b/test/nds-test-progs/sprite/source/common.h	Wed Aug 27 15:10:03 2008 +0000
   115.3 @@ -0,0 +1,48 @@
   115.4 +
   115.5 +/* A simple test program framework */
   115.6 +
   115.7 +#include <SDL/SDL.h>
   115.8 +
   115.9 +#define VERBOSE_VIDEO   0x00000001
  115.10 +#define VERBOSE_MODES   0x00000002
  115.11 +#define VERBOSE_RENDER  0x00000004
  115.12 +#define VERBOSE_EVENT   0x00000008
  115.13 +#define VERBOSE_AUDIO   0x00000010
  115.14 +
  115.15 +typedef struct
  115.16 +{
  115.17 +    /* SDL init flags */
  115.18 +    char **argv;
  115.19 +    Uint32 flags;
  115.20 +    Uint32 verbose;
  115.21 +
  115.22 +    /* Video info */
  115.23 +    const char *videodriver;
  115.24 +    int display;
  115.25 +    const char *window_title;
  115.26 +    Uint32 window_flags;
  115.27 +    int window_x;
  115.28 +    int window_y;
  115.29 +    int window_w;
  115.30 +    int window_h;
  115.31 +    int depth;
  115.32 +    int refresh_rate;
  115.33 +    int num_windows;
  115.34 +    SDL_WindowID *windows;
  115.35 +
  115.36 +    /* Renderer info */
  115.37 +    const char *renderdriver;
  115.38 +    Uint32 render_flags;
  115.39 +    SDL_bool skip_renderer;
  115.40 +
  115.41 +    /* Audio info */
  115.42 +    const char *audiodriver;
  115.43 +    SDL_AudioSpec audiospec;
  115.44 +} CommonState;
  115.45 +
  115.46 +extern CommonState *CommonCreateState(char **argv, Uint32 flags);
  115.47 +extern int CommonArg(CommonState * state, int index);
  115.48 +extern const char *CommonUsage(CommonState * state);
  115.49 +extern SDL_bool CommonInit(CommonState * state);
  115.50 +extern void CommonEvent(CommonState * state, SDL_Event * event, int *done);
  115.51 +extern void CommonQuit(CommonState * state);
   116.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   116.2 +++ b/test/nds-test-progs/sprite/source/testsprite.c	Wed Aug 27 15:10:03 2008 +0000
   116.3 @@ -0,0 +1,316 @@
   116.4 +/* Simple program:  Move N sprites around on the screen as fast as possible */
   116.5 +
   116.6 +#include <stdlib.h>
   116.7 +#include <stdio.h>
   116.8 +#include <time.h>
   116.9 +#include <math.h>
  116.10 +#include <fat.h>
  116.11 +#include <SDL/SDL.h>
  116.12 +
  116.13 +#define NUM_SPRITES	10
  116.14 +#define MAX_SPEED 	1
  116.15 +
  116.16 +SDL_Surface *sprite;
  116.17 +int numsprites;
  116.18 +SDL_Rect *sprite_rects;
  116.19 +SDL_Rect *positions;
  116.20 +SDL_Rect *velocities;
  116.21 +int sprites_visible;
  116.22 +int debug_flip;
  116.23 +Uint16 sprite_w, sprite_h;
  116.24 +
  116.25 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
  116.26 +static void
  116.27 +quit(int rc)
  116.28 +{
  116.29 +    SDL_Quit();
  116.30 +    exit(rc);
  116.31 +}
  116.32 +
  116.33 +int
  116.34 +LoadSprite(char *file)
  116.35 +{
  116.36 +    SDL_Surface *temp;
  116.37 +
  116.38 +    /* Load the sprite image */
  116.39 +    sprite = SDL_LoadBMP(file);
  116.40 +    if (sprite == NULL) {
  116.41 +        fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
  116.42 +        return (-1);
  116.43 +    }
  116.44 +
  116.45 +    /* Set transparent pixel as the pixel at (0,0) */
  116.46 +    if (sprite->format->palette) {
  116.47 +        SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
  116.48 +                        *(Uint8 *) sprite->pixels);
  116.49 +    }
  116.50 +
  116.51 +    /* Convert sprite to video format */
  116.52 +    temp = SDL_DisplayFormat(sprite);
  116.53 +    SDL_FreeSurface(sprite);
  116.54 +    if (temp == NULL) {
  116.55 +        fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError());
  116.56 +        return (-1);
  116.57 +    }
  116.58 +    sprite = temp;
  116.59 +
  116.60 +    /* We're ready to roll. :) */
  116.61 +    return (0);
  116.62 +}
  116.63 +
  116.64 +void
  116.65 +MoveSprites(SDL_Surface * screen, Uint32 background)
  116.66 +{
  116.67 +    int i, nupdates;
  116.68 +    SDL_Rect area, *position, *velocity;
  116.69 +
  116.70 +    nupdates = 0;
  116.71 +    /* Erase all the sprites if necessary */
  116.72 +    if (sprites_visible) {
  116.73 +        SDL_FillRect(screen, NULL, background);
  116.74 +    }
  116.75 +
  116.76 +    /* Move the sprite, bounce at the wall, and draw */
  116.77 +    for (i = 0; i < numsprites; ++i) {
  116.78 +        position = &positions[i];
  116.79 +        velocity = &velocities[i];
  116.80 +        position->x += velocity->x;
  116.81 +        if ((position->x < 0) || (position->x >= (screen->w - sprite_w))) {
  116.82 +            velocity->x = -velocity->x;
  116.83 +            position->x += velocity->x;
  116.84 +        }
  116.85 +        position->y += velocity->y;
  116.86 +        if ((position->y < 0) || (position->y >= (screen->h - sprite_w))) {
  116.87 +            velocity->y = -velocity->y;
  116.88 +            position->y += velocity->y;
  116.89 +        }
  116.90 +
  116.91 +        /* Blit the sprite onto the screen */
  116.92 +        area = *position;
  116.93 +        SDL_BlitSurface(sprite, NULL, screen, &area);
  116.94 +        sprite_rects[nupdates++] = area;
  116.95 +    }
  116.96 +
  116.97 +    if (debug_flip) {
  116.98 +        if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
  116.99 +            static int t = 0;
 116.100 +
 116.101 +            Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0);
 116.102 +            SDL_Rect r;
 116.103 +            r.x = t;
 116.104 +/* (sin((float) t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w - 20); */
 116.105 +            r.y = 0;
 116.106 +            r.w = 20;
 116.107 +            r.h = screen->h;
 116.108 +
 116.109 +            SDL_FillRect(screen, &r, color);
 116.110 +            t += 2;
 116.111 +        }
 116.112 +    }
 116.113 +
 116.114 +    /* Update the screen! */
 116.115 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 116.116 +        SDL_Flip(screen);
 116.117 +    } else {
 116.118 +        SDL_UpdateRects(screen, nupdates, sprite_rects);
 116.119 +    }
 116.120 +    sprites_visible = 1;
 116.121 +}
 116.122 +
 116.123 +/* This is a way of telling whether or not to use hardware surfaces */
 116.124 +Uint32
 116.125 +FastestFlags(Uint32 flags, int width, int height, int bpp)
 116.126 +{
 116.127 +    const SDL_VideoInfo *info;
 116.128 +
 116.129 +    /* Hardware acceleration is only used in fullscreen mode */
 116.130 +    flags |= SDL_FULLSCREEN;
 116.131 +
 116.132 +    /* Check for various video capabilities */
 116.133 +    info = SDL_GetVideoInfo();
 116.134 +    if (info->blit_hw_CC && info->blit_fill) {
 116.135 +        /* We use accelerated colorkeying and color filling */
 116.136 +        flags |= SDL_HWSURFACE;
 116.137 +    }
 116.138 +    /* If we have enough video memory, and will use accelerated
 116.139 +       blits directly to it, then use page flipping.
 116.140 +     */
 116.141 +    if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
 116.142 +        /* Direct hardware blitting without double-buffering
 116.143 +           causes really bad flickering.
 116.144 +         */
 116.145 +        if (info->video_mem * 1024 > (height * width * bpp / 8)) {
 116.146 +            flags |= SDL_DOUBLEBUF;
 116.147 +        } else {
 116.148 +            flags &= ~SDL_HWSURFACE;
 116.149 +        }
 116.150 +    }
 116.151 +
 116.152 +    /* Return the flags */
 116.153 +    return (flags);
 116.154 +}
 116.155 +
 116.156 +int
 116.157 +main(int argc, char *argv[])
 116.158 +{
 116.159 +    SDL_Surface *screen;
 116.160 +    Uint8 *mem;
 116.161 +    int width, height;
 116.162 +    Uint8 video_bpp;
 116.163 +    Uint32 videoflags;
 116.164 +    Uint32 background;
 116.165 +    int i, done;
 116.166 +    SDL_Event event;
 116.167 +    Uint32 then, now, frames;
 116.168 +
 116.169 +    consoleDemoInit();
 116.170 +    puts("Hello world!  Initializing FAT...");
 116.171 +    fatInitDefault();
 116.172 +    /* Initialize SDL */
 116.173 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
 116.174 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
 116.175 +        return (1);
 116.176 +    }
 116.177 +    puts("* initialized SDL");
 116.178 +
 116.179 +    numsprites = NUM_SPRITES;
 116.180 +    videoflags = SDL_SWSURFACE /*| SDL_ANYFORMAT */ ;
 116.181 +    width = 256;
 116.182 +    height = 192;
 116.183 +    video_bpp = 15;
 116.184 +    debug_flip = 0;
 116.185 +    while (argc > 1) {
 116.186 +        --argc;
 116.187 +        if (strcmp(argv[argc - 1], "-width") == 0) {
 116.188 +            width = atoi(argv[argc]);
 116.189 +            --argc;
 116.190 +        } else if (strcmp(argv[argc - 1], "-height") == 0) {
 116.191 +            height = atoi(argv[argc]);
 116.192 +            --argc;
 116.193 +        } else if (strcmp(argv[argc - 1], "-bpp") == 0) {
 116.194 +            video_bpp = atoi(argv[argc]);
 116.195 +            videoflags &= ~SDL_ANYFORMAT;
 116.196 +            --argc;
 116.197 +        } else if (strcmp(argv[argc], "-fast") == 0) {
 116.198 +            videoflags = FastestFlags(videoflags, width, height, video_bpp);
 116.199 +        } else if (strcmp(argv[argc], "-hw") == 0) {
 116.200 +            videoflags ^= SDL_HWSURFACE;
 116.201 +        } else if (strcmp(argv[argc], "-flip") == 0) {
 116.202 +            videoflags ^= SDL_DOUBLEBUF;
 116.203 +        } else if (strcmp(argv[argc], "-debugflip") == 0) {
 116.204 +            debug_flip ^= 1;
 116.205 +        } else if (strcmp(argv[argc], "-fullscreen") == 0) {
 116.206 +            videoflags ^= SDL_FULLSCREEN;
 116.207 +        } else if (isdigit(argv[argc][0])) {
 116.208 +            numsprites = atoi(argv[argc]);
 116.209 +        } else {
 116.210 +            fprintf(stderr,
 116.211 +                    "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n",
 116.212 +                    argv[0]);
 116.213 +            quit(1);
 116.214 +        }
 116.215 +    }
 116.216 +
 116.217 +    /* Set video mode */
 116.218 +    screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
 116.219 +    if (!screen) {
 116.220 +        fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
 116.221 +                width, height, SDL_GetError());
 116.222 +        quit(2);
 116.223 +    }
 116.224 +    screen->flags &= ~SDL_PREALLOC;
 116.225 +    puts("* set video mode");
 116.226 +
 116.227 +    /* Load the sprite */
 116.228 +    if (LoadSprite("icon.bmp") < 0) {
 116.229 +        quit(1);
 116.230 +    }
 116.231 +    puts("* loaded sprite");
 116.232 +
 116.233 +    /* Allocate memory for the sprite info */
 116.234 +    mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites);
 116.235 +    if (mem == NULL) {
 116.236 +        SDL_FreeSurface(sprite);
 116.237 +        fprintf(stderr, "Out of memory!\n");
 116.238 +        quit(2);
 116.239 +    }
 116.240 +    sprite_rects = (SDL_Rect *) mem;
 116.241 +    positions = sprite_rects;
 116.242 +    sprite_rects += numsprites;
 116.243 +    velocities = sprite_rects;
 116.244 +    sprite_rects += numsprites;
 116.245 +    sprite_w = sprite->w;
 116.246 +    sprite_h = sprite->h;
 116.247 +    srand(time(NULL));
 116.248 +    for (i = 0; i < numsprites; ++i) {
 116.249 +        positions[i].x = rand() % (screen->w - sprite_w);
 116.250 +        positions[i].y = rand() % (screen->h - sprite_h);
 116.251 +        positions[i].w = sprite->w;
 116.252 +        positions[i].h = sprite->h;
 116.253 +        velocities[i].x = 0;
 116.254 +        velocities[i].y = 0;
 116.255 +        while (!velocities[i].x && !velocities[i].y) {
 116.256 +            velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
 116.257 +            velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
 116.258 +        }
 116.259 +    }
 116.260 +    background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
 116.261 +
 116.262 +    /* Print out information about our surfaces */
 116.263 +    printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel);
 116.264 +    if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
 116.265 +        printf("Screen is in video memory\n");
 116.266 +    } else {
 116.267 +        printf("Screen is in system memory\n");
 116.268 +    }
 116.269 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
 116.270 +        printf("Screen has double-buffering enabled\n");
 116.271 +    }
 116.272 +    if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
 116.273 +        printf("Sprite is in video memory\n");
 116.274 +    } else {
 116.275 +        printf("Sprite is in system memory\n");
 116.276 +    }
 116.277 +    /* Run a sample blit to trigger blit acceleration */
 116.278 +    {
 116.279 +        SDL_Rect dst;
 116.280 +        dst.x = 0;
 116.281 +        dst.y = 0;
 116.282 +        dst.w = sprite->w;
 116.283 +        dst.h = sprite->h;
 116.284 +        SDL_BlitSurface(sprite, NULL, screen, &dst);
 116.285 +        SDL_FillRect(screen, &dst, background);
 116.286 +    }
 116.287 +    if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) {
 116.288 +        printf("Sprite blit uses hardware acceleration\n");
 116.289 +    }
 116.290 +    if ((sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
 116.291 +        printf("Sprite blit uses RLE acceleration\n");
 116.292 +    }
 116.293 +
 116.294 +    /* Loop, blitting sprites and waiting for a keystroke */
 116.295 +    frames = 0;
 116.296 +    then = SDL_GetTicks();
 116.297 +    done = 0;
 116.298 +    sprites_visible = 0;
 116.299 +    puts("hello!");
 116.300 +    while (!done) {
 116.301 +        /* Check for events */
 116.302 +        ++frames;
 116.303 +        printf(".");
 116.304 +        swiWaitForVBlank();
 116.305 +        MoveSprites(screen, background);
 116.306 +    }
 116.307 +    puts("goodbye!");
 116.308 +    SDL_FreeSurface(sprite);
 116.309 +    free(mem);
 116.310 +
 116.311 +    /* Print out some timing information */
 116.312 +    now = SDL_GetTicks();
 116.313 +    if (now > then) {
 116.314 +        printf("%2.2f frames per second\n",
 116.315 +               ((double) frames * 1000) / (now - then));
 116.316 +    }
 116.317 +    SDL_Quit();
 116.318 +    return (0);
 116.319 +}
   117.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   117.2 +++ b/test/nds-test-progs/sprite2/Makefile	Wed Aug 27 15:10:03 2008 +0000
   117.3 @@ -0,0 +1,132 @@
   117.4 +#---------------------------------------------------------------------------------
   117.5 +.SUFFIXES:
   117.6 +#---------------------------------------------------------------------------------
   117.7 +
   117.8 +ifeq ($(strip $(DEVKITARM)),)
   117.9 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
  117.10 +endif
  117.11 +
  117.12 +include $(DEVKITARM)/ds_rules
  117.13 +
  117.14 +#---------------------------------------------------------------------------------
  117.15 +# TARGET is the name of the output
  117.16 +# BUILD is the directory where object files & intermediate files will be placed
  117.17 +# SOURCES is a list of directories containing source code
  117.18 +# INCLUDES is a list of directories containing extra header files
  117.19 +#---------------------------------------------------------------------------------
  117.20 +TARGET		:=	$(shell basename $(CURDIR))
  117.21 +BUILD		:=	build
  117.22 +SOURCES		:=	source
  117.23 +DATA		:=	data  
  117.24 +INCLUDES	:=	include
  117.25 +
  117.26 +#---------------------------------------------------------------------------------
  117.27 +# options for code generation
  117.28 +#---------------------------------------------------------------------------------
  117.29 +ARCH	:=	-mthumb -mthumb-interwork
  117.30 +
  117.31 +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
  117.32 +# *insists* it has a FPU or VFP, and it won't take no for an answer!
  117.33 +CFLAGS	:=	-save-temps -g -Wall -O0\
  117.34 + 			-mcpu=arm9tdmi -mtune=arm9tdmi \
  117.35 +			$(ARCH)
  117.36 +
  117.37 +CFLAGS	+=	$(INCLUDE) -DARM9 -D__NDS__
  117.38 +CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti
  117.39 +
  117.40 +ASFLAGS	:=	-g $(ARCH)
  117.41 +LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
  117.42 +
  117.43 +#---------------------------------------------------------------------------------
  117.44 +# any extra libraries we wish to link with the project
  117.45 +#---------------------------------------------------------------------------------
  117.46 +LIBS	:= -lSDL -lfat -lnds9
  117.47 + 
  117.48 + 
  117.49 +#---------------------------------------------------------------------------------
  117.50 +# list of directories containing libraries, this must be the top level containing
  117.51 +# include and lib
  117.52 +#---------------------------------------------------------------------------------
  117.53 +LIBDIRS	:=	$(LIBNDS)
  117.54 + 
  117.55 +#---------------------------------------------------------------------------------
  117.56 +# no real need to edit anything past this point unless you need to add additional
  117.57 +# rules for different file extensions
  117.58 +#---------------------------------------------------------------------------------
  117.59 +ifneq ($(BUILD),$(notdir $(CURDIR)))
  117.60 +#---------------------------------------------------------------------------------
  117.61 + 
  117.62 +export OUTPUT	:=	$(CURDIR)/$(TARGET)
  117.63 + 
  117.64 +export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  117.65 +					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
  117.66 +
  117.67 +export DEPSDIR	:=	$(CURDIR)/$(BUILD)
  117.68 +
  117.69 +CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  117.70 +CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  117.71 +SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  117.72 +BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  117.73 + 
  117.74 +#---------------------------------------------------------------------------------
  117.75 +# use CXX for linking C++ projects, CC for standard C
  117.76 +#---------------------------------------------------------------------------------
  117.77 +ifeq ($(strip $(CPPFILES)),)
  117.78 +#---------------------------------------------------------------------------------
  117.79 +	export LD	:=	$(CC)
  117.80 +#---------------------------------------------------------------------------------
  117.81 +else
  117.82 +#---------------------------------------------------------------------------------
  117.83 +	export LD	:=	$(CXX)
  117.84 +#---------------------------------------------------------------------------------
  117.85 +endif
  117.86 +#---------------------------------------------------------------------------------
  117.87 +
  117.88 +export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
  117.89 +					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  117.90 + 
  117.91 +export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  117.92 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  117.93 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  117.94 +					-I$(CURDIR)/$(BUILD)
  117.95 + 
  117.96 +export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  117.97 + 
  117.98 +.PHONY: $(BUILD) clean
  117.99 + 
 117.100 +#---------------------------------------------------------------------------------
 117.101 +$(BUILD):
 117.102 +	@[ -d $@ ] || mkdir -p $@
 117.103 +	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
 117.104 + 
 117.105 +#---------------------------------------------------------------------------------
 117.106 +clean:
 117.107 +	@echo clean ...
 117.108 +	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba 
 117.109 + 
 117.110 + 
 117.111 +#---------------------------------------------------------------------------------
 117.112 +else
 117.113 + 
 117.114 +DEPENDS	:=	$(OFILES:.o=.d)
 117.115 + 
 117.116 +#---------------------------------------------------------------------------------
 117.117 +# main targets
 117.118 +#---------------------------------------------------------------------------------
 117.119 +$(OUTPUT).ds.gba	: 	$(OUTPUT).nds
 117.120 +$(OUTPUT).nds	: 	$(OUTPUT).arm9
 117.121 +$(OUTPUT).arm9	:	$(OUTPUT).elf
 117.122 +$(OUTPUT).elf	:	$(OFILES)
 117.123 + 
 117.124 +#---------------------------------------------------------------------------------
 117.125 +%.bin.o	:	%.bin
 117.126 +#---------------------------------------------------------------------------------
 117.127 +	@echo $(notdir $<)
 117.128 +	@$(bin2o)
 117.129 + 
 117.130 + 
 117.131 +-include $(DEPENDS)
 117.132 + 
 117.133 +#---------------------------------------------------------------------------------------
 117.134 +endif
 117.135 +#---------------------------------------------------------------------------------------
   118.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   118.2 +++ b/test/nds-test-progs/sprite2/source/common.c	Wed Aug 27 15:10:03 2008 +0000
   118.3 @@ -0,0 +1,965 @@
   118.4 +
   118.5 +/* A simple test program framework */
   118.6 +
   118.7 +#include <stdio.h>
   118.8 +
   118.9 +#include "common.h"
  118.10 +
  118.11 +#define VIDEO_USAGE \
  118.12 +"[--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]"
  118.13 +
  118.14 +#define AUDIO_USAGE \
  118.15 +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
  118.16 +
  118.17 +CommonState *
  118.18 +CommonCreateState(char **argv, Uint32 flags)
  118.19 +{
  118.20 +    CommonState *state = SDL_calloc(1, sizeof(*state));
  118.21 +    if (!state) {
  118.22 +        SDL_OutOfMemory();
  118.23 +        return NULL;
  118.24 +    }
  118.25 +
  118.26 +    /* Initialize some defaults */
  118.27 +    state->argv = argv;
  118.28 +    state->flags = flags;
  118.29 +    state->window_title = argv[0];
  118.30 +    state->window_flags = SDL_WINDOW_SHOWN;
  118.31 +    state->window_x = SDL_WINDOWPOS_UNDEFINED;
  118.32 +    state->window_y = SDL_WINDOWPOS_UNDEFINED;
  118.33 +    state->window_w = 256;
  118.34 +    state->window_h = 192;
  118.35 +    state->num_windows = 1;
  118.36 +    state->audiospec.freq = 22050;
  118.37 +    state->audiospec.format = AUDIO_S16;
  118.38 +    state->audiospec.channels = 2;
  118.39 +    state->audiospec.samples = 2048;
  118.40 +    return state;
  118.41 +}
  118.42 +
  118.43 +int
  118.44 +CommonArg(CommonState * state, int index)
  118.45 +{
  118.46 +    char **argv = state->argv;
  118.47 +
  118.48 +    if (SDL_strcasecmp(argv[index], "--video") == 0) {
  118.49 +        ++index;
  118.50 +        if (!argv[index]) {
  118.51 +            return -1;
  118.52 +        }
  118.53 +        state->videodriver = argv[index];
  118.54 +        return 2;
  118.55 +    }
  118.56 +    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
  118.57 +        ++index;
  118.58 +        if (!argv[index]) {
  118.59 +            return -1;
  118.60 +        }
  118.61 +        state->renderdriver = argv[index];
  118.62 +        return 2;
  118.63 +    }
  118.64 +    if (SDL_strcasecmp(argv[index], "--info") == 0) {
  118.65 +        ++index;
  118.66 +        if (!argv[index]) {
  118.67 +            return -1;
  118.68 +        }
  118.69 +        if (SDL_strcasecmp(argv[index], "all") == 0) {
  118.70 +            state->verbose |=
  118.71 +                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
  118.72 +                 VERBOSE_EVENT);
  118.73 +            return 2;
  118.74 +        }
  118.75 +        if (SDL_strcasecmp(argv[index], "video") == 0) {
  118.76 +            state->verbose |= VERBOSE_VIDEO;
  118.77 +            return 2;
  118.78 +        }
  118.79 +        if (SDL_strcasecmp(argv[index], "modes") == 0) {
  118.80 +            state->verbose |= VERBOSE_MODES;
  118.81 +            return 2;
  118.82 +        }
  118.83 +        if (SDL_strcasecmp(argv[index], "render") == 0) {
  118.84 +            state->verbose |= VERBOSE_RENDER;
  118.85 +            return 2;
  118.86 +        }
  118.87 +        if (SDL_strcasecmp(argv[index], "event") == 0) {
  118.88 +            state->verbose |= VERBOSE_EVENT;
  118.89 +            return 2;
  118.90 +        }
  118.91 +        return -1;
  118.92 +    }
  118.93 +    if (SDL_strcasecmp(argv[index], "--display") == 0) {
  118.94 +        ++index;
  118.95 +        if (!argv[index]) {
  118.96 +            return -1;
  118.97 +        }
  118.98 +        state->display = SDL_atoi(argv[index]);
  118.99 +        return 2;
 118.100 +    }
 118.101 +    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
 118.102 +        state->window_flags |= SDL_WINDOW_FULLSCREEN;
 118.103 +        state->num_windows = 1;
 118.104 +        return 1;
 118.105 +    }
 118.106 +    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
 118.107 +        ++index;
 118.108 +        if (!argv[index] || !SDL_isdigit(*argv[index])) {
 118.109 +            return -1;
 118.110 +        }
 118.111 +        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
 118.112 +            state->num_windows = SDL_atoi(argv[index]);
 118.113 +        }
 118.114 +        return 2;
 118.115 +    }
 118.116 +    if (SDL_strcasecmp(argv[index], "--title") == 0) {
 118.117 +        ++index;
 118.118 +        if (!argv[index]) {
 118.119 +            return -1;
 118.120 +        }
 118.121 +        state->window_title = argv[index];
 118.122 +        return 2;
 118.123 +    }
 118.124 +    if (SDL_strcasecmp(argv[index], "--center") == 0) {
 118.125 +        state->window_x = SDL_WINDOWPOS_CENTERED;
 118.126 +        state->window_y = SDL_WINDOWPOS_CENTERED;
 118.127 +        return 1;
 118.128 +    }
 118.129 +    if (SDL_strcasecmp(argv[index], "--position") == 0) {
 118.130 +        char *x, *y;
 118.131 +        ++index;
 118.132 +        if (!argv[index]) {
 118.133 +            return -1;
 118.134 +        }
 118.135 +        x = argv[index];
 118.136 +        y = argv[index];
 118.137 +        while (*y && *y != ',') {
 118.138 +            ++y;
 118.139 +        }
 118.140 +        if (!*y) {
 118.141 +            return -1;
 118.142 +        }
 118.143 +        *y++ = '\0';
 118.144 +        state->window_x = SDL_atoi(x);
 118.145 +        state->window_y = SDL_atoi(y);
 118.146 +        return 2;
 118.147 +    }
 118.148 +    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
 118.149 +        char *w, *h;
 118.150 +        ++index;
 118.151 +        if (!argv[index]) {
 118.152 +            return -1;
 118.153 +        }
 118.154 +        w = argv[index];
 118.155 +        h = argv[index];
 118.156 +        while (*h && *h != 'x') {
 118.157 +            ++h;
 118.158 +        }
 118.159 +        if (!*h) {
 118.160 +            return -1;
 118.161 +        }
 118.162 +        *h++ = '\0';
 118.163 +        state->window_w = SDL_atoi(w);
 118.164 +        state->window_h = SDL_atoi(h);
 118.165 +        return 2;
 118.166 +    }
 118.167 +    if (SDL_strcasecmp(argv[index], "--depth") == 0) {
 118.168 +        ++index;
 118.169 +        if (!argv[index]) {
 118.170 +            return -1;
 118.171 +        }
 118.172 +        state->depth = SDL_atoi(argv[index]);
 118.173 +        return 2;
 118.174 +    }
 118.175 +    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
 118.176 +        ++index;
 118.177 +        if (!argv[index]) {
 118.178 +            return -1;
 118.179 +        }
 118.180 +        state->refresh_rate = SDL_atoi(argv[index]);
 118.181 +        return 2;
 118.182 +    }
 118.183 +    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
 118.184 +        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
 118.185 +        return 1;
 118.186 +    }
 118.187 +    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
 118.188 +        state->window_flags |= SDL_WINDOW_BORDERLESS;
 118.189 +        return 1;
 118.190 +    }
 118.191 +    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
 118.192 +        state->window_flags |= SDL_WINDOW_RESIZABLE;
 118.193 +        return 1;
 118.194 +    }
 118.195 +    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
 118.196 +        state->window_flags |= SDL_WINDOW_MINIMIZED;
 118.197 +        return 1;
 118.198 +    }
 118.199 +    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
 118.200 +        state->window_flags |= SDL_WINDOW_MAXIMIZED;
 118.201 +        return 1;
 118.202 +    }
 118.203 +    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
 118.204 +        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
 118.205 +        return 1;
 118.206 +    }
 118.207 +    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
 118.208 +        ++index;
 118.209 +        if (!argv[index]) {
 118.210 +            return -1;
 118.211 +        }
 118.212 +        state->audiospec.freq = SDL_atoi(argv[index]);
 118.213 +        return 2;
 118.214 +    }
 118.215 +    if (SDL_strcasecmp(argv[index], "--format") == 0) {
 118.216 +        ++index;
 118.217 +        if (!argv[index]) {
 118.218 +            return -1;
 118.219 +        }
 118.220 +        if (SDL_strcasecmp(argv[index], "U8") == 0) {
 118.221 +            state->audiospec.format = AUDIO_U8;
 118.222 +            return 2;
 118.223 +        }
 118.224 +        if (SDL_strcasecmp(argv[index], "S8") == 0) {
 118.225 +            state->audiospec.format = AUDIO_S8;
 118.226 +            return 2;
 118.227 +        }
 118.228 +        if (SDL_strcasecmp(argv[index], "U16") == 0) {
 118.229 +            state->audiospec.format = AUDIO_U16;
 118.230 +            return 2;
 118.231 +        }
 118.232 +        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
 118.233 +            state->audiospec.format = AUDIO_U16LSB;
 118.234 +            return 2;
 118.235 +        }
 118.236 +        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
 118.237 +            state->audiospec.format = AUDIO_U16MSB;
 118.238 +            return 2;
 118.239 +        }
 118.240 +        if (SDL_strcasecmp(argv[index], "S16") == 0) {
 118.241 +            state->audiospec.format = AUDIO_S16;
 118.242 +            return 2;
 118.243 +        }
 118.244 +        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
 118.245 +            state->audiospec.format = AUDIO_S16LSB;
 118.246 +            return 2;
 118.247 +        }
 118.248 +        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
 118.249 +            state->audiospec.format = AUDIO_S16MSB;
 118.250 +            return 2;
 118.251 +        }
 118.252 +        return -1;
 118.253 +    }
 118.254 +    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
 118.255 +        ++index;
 118.256 +        if (!argv[index]) {
 118.257 +            return -1;
 118.258 +        }
 118.259 +        state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
 118.260 +        return 2;
 118.261 +    }
 118.262 +    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
 118.263 +        ++index;
 118.264 +        if (!argv[index]) {
 118.265 +            return -1;
 118.266 +        }
 118.267 +        state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
 118.268 +        return 2;
 118.269 +    }
 118.270 +    if ((SDL_strcasecmp(argv[index], "-h") == 0)
 118.271 +        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
 118.272 +        /* Print the usage message */
 118.273 +        return -1;
 118.274 +    }
 118.275 +    return 0;
 118.276 +}
 118.277 +
 118.278 +const char *
 118.279 +CommonUsage(CommonState * state)
 118.280 +{
 118.281 +    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
 118.282 +    case SDL_INIT_VIDEO:
 118.283 +        return VIDEO_USAGE;
 118.284 +    case SDL_INIT_AUDIO:
 118.285 +        return AUDIO_USAGE;
 118.286 +    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
 118.287 +        return VIDEO_USAGE " " AUDIO_USAGE;
 118.288 +    default:
 118.289 +        return "";
 118.290 +    }
 118.291 +}
 118.292 +
 118.293 +static void
 118.294 +PrintRendererFlag(Uint32 flag)
 118.295 +{
 118.296 +    switch (flag) {
 118.297 +    case SDL_RENDERER_SINGLEBUFFER:
 118.298 +        fprintf(stderr, "SingleBuffer");
 118.299 +        break;
 118.300 +    case SDL_RENDERER_PRESENTCOPY:
 118.301 +        fprintf(stderr, "PresentCopy");
 118.302 +        break;
 118.303 +    case SDL_RENDERER_PRESENTFLIP2:
 118.304 +        fprintf(stderr, "PresentFlip2");
 118.305 +        break;
 118.306 +    case SDL_RENDERER_PRESENTFLIP3:
 118.307 +        fprintf(stderr, "PresentFlip3");
 118.308 +        break;
 118.309 +    case SDL_RENDERER_PRESENTDISCARD:
 118.310 +        fprintf(stderr, "PresentDiscard");
 118.311 +        break;
 118.312 +    case SDL_RENDERER_PRESENTVSYNC:
 118.313 +        fprintf(stderr, "PresentVSync");
 118.314 +        break;
 118.315 +    case SDL_RENDERER_ACCELERATED:
 118.316 +        fprintf(stderr, "Accelerated");
 118.317 +        break;
 118.318 +    default:
 118.319 +        fprintf(stderr, "0x%8.8x", flag);
 118.320 +        break;
 118.321 +    }
 118.322 +}
 118.323 +
 118.324 +static void
 118.325 +PrintBlendMode(Uint32 flag)
 118.326 +{
 118.327 +    switch (flag) {
 118.328 +    case SDL_TEXTUREBLENDMODE_NONE:
 118.329 +        fprintf(stderr, "None");
 118.330 +        break;
 118.331 +    case SDL_TEXTUREBLENDMODE_MASK:
 118.332 +        fprintf(stderr, "Mask");
 118.333 +        break;
 118.334 +    case SDL_TEXTUREBLENDMODE_BLEND:
 118.335 +        fprintf(stderr, "Blend");
 118.336 +        break;
 118.337 +    case SDL_TEXTUREBLENDMODE_ADD:
 118.338 +        fprintf(stderr, "Add");
 118.339 +        break;
 118.340 +    case SDL_TEXTUREBLENDMODE_MOD:
 118.341 +        fprintf(stderr, "Mod");
 118.342 +        break;
 118.343 +    default:
 118.344 +        fprintf(stderr, "0x%8.8x", flag);
 118.345 +        break;
 118.346 +    }
 118.347 +}
 118.348 +
 118.349 +static void
 118.350 +PrintScaleMode(Uint32 flag)
 118.351 +{
 118.352 +    switch (flag) {
 118.353 +    case SDL_TEXTURESCALEMODE_NONE:
 118.354 +        fprintf(stderr, "None");
 118.355 +        break;
 118.356 +    case SDL_TEXTURESCALEMODE_FAST:
 118.357 +        fprintf(stderr, "Fast");
 118.358 +        break;
 118.359 +    case SDL_TEXTURESCALEMODE_SLOW:
 118.360 +        fprintf(stderr, "Slow");
 118.361 +        break;
 118.362 +    case SDL_TEXTURESCALEMODE_BEST:
 118.363 +        fprintf(stderr, "Best");
 118.364 +        break;
 118.365 +    default:
 118.366 +        fprintf(stderr, "0x%8.8x", flag);
 118.367 +        break;
 118.368 +    }
 118.369 +}
 118.370 +
 118.371 +static void
 118.372 +PrintPixelFormat(Uint32 format)
 118.373 +{
 118.374 +    switch (format) {
 118.375 +    case SDL_PIXELFORMAT_UNKNOWN:
 118.376 +        fprintf(stderr, "Unknwon");
 118.377 +        break;
 118.378 +    case SDL_PIXELFORMAT_INDEX1LSB:
 118.379 +        fprintf(stderr, "Index1LSB");
 118.380 +        break;
 118.381 +    case SDL_PIXELFORMAT_INDEX1MSB:
 118.382 +        fprintf(stderr, "Index1MSB");
 118.383 +        break;
 118.384 +    case SDL_PIXELFORMAT_INDEX4LSB:
 118.385 +        fprintf(stderr, "Index4LSB");
 118.386 +        break;
 118.387 +    case SDL_PIXELFORMAT_INDEX4MSB:
 118.388 +        fprintf(stderr, "Index4MSB");
 118.389 +        break;
 118.390 +    case SDL_PIXELFORMAT_INDEX8:
 118.391 +        fprintf(stderr, "Index8");
 118.392 +        break;
 118.393 +    case SDL_PIXELFORMAT_RGB332:
 118.394 +        fprintf(stderr, "RGB332");
 118.395 +        break;
 118.396 +    case SDL_PIXELFORMAT_RGB444:
 118.397 +        fprintf(stderr, "RGB444");
 118.398 +        break;
 118.399 +    case SDL_PIXELFORMAT_RGB555:
 118.400 +        fprintf(stderr, "RGB555");
 118.401 +        break;
 118.402 +    case SDL_PIXELFORMAT_ARGB4444:
 118.403 +        fprintf(stderr, "ARGB4444");
 118.404 +        break;
 118.405 +    case SDL_PIXELFORMAT_ARGB1555:
 118.406 +        fprintf(stderr, "ARGB1555");
 118.407 +        break;
 118.408 +    case SDL_PIXELFORMAT_RGB565:
 118.409 +        fprintf(stderr, "RGB565");
 118.410 +        break;
 118.411 +    case SDL_PIXELFORMAT_RGB24:
 118.412 +        fprintf(stderr, "RGB24");
 118.413 +        break;
 118.414 +    case SDL_PIXELFORMAT_BGR24:
 118.415 +        fprintf(stderr, "BGR24");
 118.416 +        break;
 118.417 +    case SDL_PIXELFORMAT_RGB888:
 118.418 +        fprintf(stderr, "RGB888");
 118.419 +        break;
 118.420 +    case SDL_PIXELFORMAT_BGR888:
 118.421 +        fprintf(stderr, "BGR888");
 118.422 +        break;
 118.423 +    case SDL_PIXELFORMAT_ARGB8888:
 118.424 +        fprintf(stderr, "ARGB8888");
 118.425 +        break;
 118.426 +    case SDL_PIXELFORMAT_RGBA8888:
 118.427 +        fprintf(stderr, "RGBA8888");
 118.428 +        break;
 118.429 +    case SDL_PIXELFORMAT_ABGR8888:
 118.430 +        fprintf(stderr, "ABGR8888");
 118.431 +        break;
 118.432 +    case SDL_PIXELFORMAT_BGRA8888:
 118.433 +        fprintf(stderr, "BGRA8888");
 118.434 +        break;
 118.435 +    case SDL_PIXELFORMAT_ARGB2101010:
 118.436 +        fprintf(stderr, "ARGB2101010");
 118.437 +        break;
 118.438 +    case SDL_PIXELFORMAT_YV12:
 118.439 +        fprintf(stderr, "YV12");
 118.440 +        break;
 118.441 +    case SDL_PIXELFORMAT_IYUV:
 118.442 +        fprintf(stderr, "IYUV");
 118.443 +        break;
 118.444 +    case SDL_PIXELFORMAT_YUY2:
 118.445 +        fprintf(stderr, "YUY2");
 118.446 +        break;
 118.447 +    case SDL_PIXELFORMAT_UYVY:
 118.448 +        fprintf(stderr, "UYVY");
 118.449 +        break;
 118.450 +    case SDL_PIXELFORMAT_YVYU:
 118.451 +        fprintf(stderr, "YVYU");
 118.452 +        break;
 118.453 +    case SDL_PIXELFORMAT_ABGR1555:
 118.454 +        fprintf(stderr, "ABGR1555");
 118.455 +        break;
 118.456 +    case SDL_PIXELFORMAT_BGR555:
 118.457 +        fprintf(stderr, "BGR555");
 118.458 +        break;
 118.459 +    default:
 118.460 +        fprintf(stderr, "0x%8.8x", format);
 118.461 +        break;
 118.462 +    }
 118.463 +}
 118.464 +
 118.465 +static void
 118.466 +PrintRenderer(SDL_RendererInfo * info)
 118.467 +{
 118.468 +    int i, count;
 118.469 +
 118.470 +    fprintf(stderr, "  Renderer %s:\n", info->name);
 118.471 +
 118.472 +    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
 118.473 +    fprintf(stderr, " (");
 118.474 +    count = 0;
 118.475 +    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
 118.476 +        Uint32 flag = (1 << i);
 118.477 +        if (info->flags & flag) {
 118.478 +            if (count > 0) {
 118.479 +                fprintf(stderr, " | ");
 118.480 +            }
 118.481 +            PrintRendererFlag(flag);
 118.482 +            ++count;
 118.483 +        }
 118.484 +    }
 118.485 +    fprintf(stderr, ")\n");
 118.486 +
 118.487 +    fprintf(stderr, "    Blend: 0x%8.8X", info->blend_modes);
 118.488 +    fprintf(stderr, " (");
 118.489 +    count = 0;
 118.490 +    for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) {
 118.491 +        Uint32 flag = (1 << i);
 118.492 +        if (info->blend_modes & flag) {
 118.493 +            if (count > 0) {
 118.494 +                fprintf(stderr, " | ");
 118.495 +            }
 118.496 +            PrintBlendMode(flag);
 118.497 +            ++count;
 118.498 +        }
 118.499 +    }
 118.500 +    fprintf(stderr, ")\n");
 118.501 +
 118.502 +    fprintf(stderr, "    Scale: 0x%8.8X", info->scale_modes);
 118.503 +    fprintf(stderr, " (");
 118.504 +    count = 0;
 118.505 +    for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) {
 118.506 +        Uint32 flag = (1 << i);
 118.507 +        if (info->scale_modes & flag) {
 118.508 +            if (count > 0) {
 118.509 +                fprintf(stderr, " | ");
 118.510 +            }
 118.511 +            PrintScaleMode(flag);
 118.512 +            ++count;
 118.513 +        }
 118.514 +    }
 118.515 +    fprintf(stderr, ")\n");
 118.516 +
 118.517 +    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
 118.518 +    for (i = 0; i < (int) info->num_texture_formats; ++i) {
 118.519 +        if (i > 0) {
 118.520 +            fprintf(stderr, ", ");
 118.521 +        }
 118.522 +        PrintPixelFormat(info->texture_formats[i]);
 118.523 +    }
 118.524 +    fprintf(stderr, "\n");
 118.525 +
 118.526 +    if (info->max_texture_width || info->max_texture_height) {
 118.527 +        fprintf(stderr, "    Max Texture Size: %dx%d\n",
 118.528 +                info->max_texture_width, info->max_texture_height);
 118.529 +    }
 118.530 +}
 118.531 +
 118.532 +SDL_bool
 118.533 +CommonInit(CommonState * state)
 118.534 +{
 118.535 +    int i, j, m, n;
 118.536 +    SDL_DisplayMode fullscreen_mode;
 118.537 +
 118.538 +    if (state->flags & SDL_INIT_VIDEO) {
 118.539 +        if (state->verbose & VERBOSE_VIDEO) {
 118.540 +            n = SDL_GetNumVideoDrivers();
 118.541 +            if (n == 0) {
 118.542 +                fprintf(stderr, "No built-in video drivers\n");
 118.543 +            } else {
 118.544 +                fprintf(stderr, "Built-in video drivers:");
 118.545 +                for (i = 0; i < n; ++i) {
 118.546 +                    if (i > 0) {
 118.547 +                        fprintf(stderr, ",");
 118.548 +                    }
 118.549 +                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
 118.550 +                }
 118.551 +                fprintf(stderr, "\n");
 118.552 +            }
 118.553 +        }
 118.554 +        if (SDL_VideoInit(state->videodriver, 0) < 0) {
 118.555 +            fprintf(stderr, "Couldn't initialize video driver: %s\n",
 118.556 +                    SDL_GetError());
 118.557 +            return SDL_FALSE;
 118.558 +        }
 118.559 +        if (state->verbose & VERBOSE_VIDEO) {
 118.560 +            fprintf(stderr, "Video driver: %s\n",
 118.561 +                    SDL_GetCurrentVideoDriver());
 118.562 +        }
 118.563 +
 118.564 +        if (state->verbose & VERBOSE_MODES) {
 118.565 +            SDL_DisplayMode mode;
 118.566 +            int bpp;
 118.567 +            Uint32 Rmask, Gmask, Bmask, Amask;
 118.568 +
 118.569 +            n = SDL_GetNumVideoDisplays();
 118.570 +            fprintf(stderr, "Number of displays: %d\n", n);
 118.571 +            for (i = 0; i < n; ++i) {
 118.572 +                fprintf(stderr, "Display %d:\n", i);
 118.573 +                SDL_SelectVideoDisplay(i);
 118.574 +
 118.575 +                SDL_GetDesktopDisplayMode(&mode);
 118.576 +                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
 118.577 +                                           &Bmask, &Amask);
 118.578 +                fprintf(stderr,
 118.579 +                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel\n",
 118.580 +                        mode.w, mode.h, mode.refresh_rate, bpp);
 118.581 +                if (Rmask || Gmask || Bmask) {
 118.582 +                    fprintf(stderr, "      Red Mask = 0x%.8x\n", Rmask);
 118.583 +                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
 118.584 +                    fprintf(stderr, "      Blue Mask = 0x%.8x\n", Bmask);
 118.585 +                    if (Amask)
 118.586 +                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
 118.587 +                }
 118.588 +
 118.589 +                /* Print available fullscreen video modes */
 118.590 +                m = SDL_GetNumDisplayModes();
 118.591 +                if (m == 0) {
 118.592 +                    fprintf(stderr, "No available fullscreen video modes\n");
 118.593 +                } else {
 118.594 +                    fprintf(stderr, "  Fullscreen video modes:\n");
 118.595 +                    for (j = 0; j < m; ++j) {
 118.596 +                        SDL_GetDisplayMode(j, &mode);
 118.597 +                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
 118.598 +                                                   &Gmask, &Bmask, &Amask);
 118.599 +                        fprintf(stderr,
 118.600 +                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n",
 118.601 +                                j, mode.w, mode.h, mode.refresh_rate, bpp);
 118.602 +                        if (Rmask || Gmask || Bmask) {
 118.603 +                            fprintf(stderr, "        Red Mask = 0x%.8x\n",
 118.604 +                                    Rmask);
 118.605 +                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
 118.606 +                                    Gmask);
 118.607 +                            fprintf(stderr, "        Blue Mask = 0x%.8x\n",
 118.608 +                                    Bmask);
 118.609 +                            if (Amask)
 118.610 +                                fprintf(stderr,
 118.611 +                                        "        Alpha Mask = 0x%.8x\n",
 118.612 +                                        Amask);
 118.613 +                        }
 118.614 +                    }
 118.615 +                }
 118.616 +            }
 118.617 +        }
 118.618 +
 118.619 +        SDL_SelectVideoDisplay(state->display);
 118.620 +        if (state->verbose & VERBOSE_RENDER) {
 118.621 +            SDL_RendererInfo info;
 118.622 +
 118.623 +            n = SDL_GetNumRenderDrivers();
 118.624 +            if (n == 0) {
 118.625 +                fprintf(stderr, "No built-in render drivers\n");
 118.626 +            } else {
 118.627 +                fprintf(stderr, "Built-in render drivers:\n");
 118.628 +                for (i = 0; i < n; ++i) {
 118.629 +                    SDL_GetRenderDriverInfo(i, &info);
 118.630 +                    PrintRenderer(&info);
 118.631 +                }
 118.632 +            }
 118.633 +        }
 118.634 +
 118.635 +        switch (state->depth) {
 118.636 +        case 8:
 118.637 +            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
 118.638 +            break;
 118.639 +        case 15:
 118.640 +            fullscreen_mode.format = SDL_PIXELFORMAT_BGR555;
 118.641 +            break;
 118.642 +        case 16:
 118.643 +        default:
 118.644 +            fullscreen_mode.format = SDL_PIXELFORMAT_ABGR1555;
 118.645 +            break;
 118.646 +/* NDS       default:
 118.647 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
 118.648 +            break;*/
 118.649 +        }
 118.650 +        fullscreen_mode.w = state->window_w;
 118.651 +        fullscreen_mode.h = state->window_h;
 118.652 +        fullscreen_mode.refresh_rate = state->refresh_rate;
 118.653 +        SDL_SetFullscreenDisplayMode(&fullscreen_mode);
 118.654 +
 118.655 +        state->windows =
 118.656 +            (SDL_WindowID *) SDL_malloc(state->num_windows *
 118.657 +                                        sizeof(*state->windows));
 118.658 +        if (!state->windows) {
 118.659 +            fprintf(stderr, "Out of memory!\n");
 118.660 +            return SDL_FALSE;
 118.661 +        }
 118.662 +        for (i = 0; i < state->num_windows; ++i) {
 118.663 +            char title[1024];
 118.664 +
 118.665 +            if (state->num_windows > 1) {
 118.666 +                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
 118.667 +                             state->window_title, i + 1);
 118.668 +            } else {
 118.669 +                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
 118.670 +            }
 118.671 +            state->windows[i] =
 118.672 +                SDL_CreateWindow(title, state->window_x, state->window_y,
 118.673 +                                 state->window_w, state->window_h,
 118.674 +                                 state->window_flags);
 118.675 +            if (!state->windows[i]) {
 118.676 +                fprintf(stderr, "Couldn't create window: %s\n",
 118.677 +                        SDL_GetError());
 118.678 +                return SDL_FALSE;
 118.679 +            }
 118.680 +
 118.681 +            if (!state->skip_renderer