Fix for the previous commit: actually 'svn add'ed some files. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Tue, 10 Jun 2008 06:57:57 +0000
branchgsoc2008_nds
changeset 26706e4669f4db49
parent 2669 e27bdcc80744
child 2671 c3e7c0698cbb
Fix for the previous commit: actually 'svn add'ed some files.
Makefile.ds
include/SDL_config_nintendods.h
src/joystick/nds/SDL_sysjoystick.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/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
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile.ds	Tue Jun 10 06:57:57 2008 +0000
     1.3 @@ -0,0 +1,139 @@
     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 $(DEVKITARM)),)
     1.9 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
    1.10 +endif
    1.11 +
    1.12 +CC = arm-eabi-gcc
    1.13 +AR = arm-eabi-ar
    1.14 +RANLIB = arm-eabi-ranlib
    1.15 +
    1.16 +#ifdef GL
    1.17 +#DEFS += -DSDL_VIDEO_OPENGL=1
    1.18 +#TARGET = libSDL_gl.a
    1.19 +#else
    1.20 +TARGET = libSDL.a
    1.21 +#endif
    1.22 +
    1.23 +#CFLAGS=$(DEFS) -Iinclude
    1.24 +CFLAGS	=	-mthumb -mthumb-interwork \
    1.25 +		-march=armv5te -mtune=arm946e-s \
    1.26 +		-O2 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
    1.27 +		-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.28 +		-Iinclude -Isrc -Isrc/audio -Isrc/cdrom -Isrc/endian -Isrc/events -Isrc/joystick -Isrc/thread/nds -Isrc/thread -Isrc/timer -Isrc/video
    1.29 +
    1.30 +SRCS = \
    1.31 +src/SDL.c \
    1.32 +src/SDL_compat.c \
    1.33 +src/SDL_error.c \
    1.34 +src/SDL_fatal.c \
    1.35 +src/audio/disk/SDL_diskaudio.c \
    1.36 +src/audio/dummy/SDL_dummyaudio.c \
    1.37 +src/audio/SDL_audio.c \
    1.38 +src/audio/SDL_audiocvt.c \
    1.39 +src/audio/SDL_audiodev.c \
    1.40 +src/audio/SDL_audiotypecvt.c \
    1.41 +src/audio/SDL_mixer.c \
    1.42 +src/audio/SDL_mixer_m68k.c \
    1.43 +src/audio/SDL_mixer_MMX.c \
    1.44 +src/audio/SDL_mixer_MMX_VC.c \
    1.45 +src/audio/SDL_wave.c \
    1.46 +src/cdrom/dummy/SDL_syscdrom.c \
    1.47 +src/cdrom/SDL_cdrom.c \
    1.48 +src/cpuinfo/SDL_cpuinfo.c \
    1.49 +src/events/SDL_events.c \
    1.50 +src/events/SDL_keyboard.c \
    1.51 +src/events/SDL_mouse.c \
    1.52 +src/events/SDL_quit.c \
    1.53 +src/events/SDL_windowevents.c \
    1.54 +src/file/SDL_rwops.c \
    1.55 +src/joystick/dummy/SDL_sysjoystick.c \
    1.56 +src/joystick/SDL_joystick.c \
    1.57 +src/stdlib/SDL_getenv.c \
    1.58 +src/stdlib/SDL_iconv.c \
    1.59 +src/stdlib/SDL_malloc.c \
    1.60 +src/stdlib/SDL_qsort.c \
    1.61 +src/stdlib/SDL_stdlib.c \
    1.62 +src/stdlib/SDL_string.c \
    1.63 +src/thread/SDL_thread.c \
    1.64 +src/thread/nds/SDL_syscond.c \
    1.65 +src/thread/nds/SDL_sysmutex.c \
    1.66 +src/thread/nds/SDL_syssem.c \
    1.67 +src/thread/nds/SDL_systhread.c \
    1.68 +src/timer/dummy/SDL_systimer.c \
    1.69 +src/timer/SDL_timer.c \
    1.70 +src/video/dummy/SDL_nullevents.c \
    1.71 +src/video/dummy/SDL_nullrender.c \
    1.72 +src/video/dummy/SDL_nullvideo.c \
    1.73 +src/video/nds/SDL_ndsevents.c \
    1.74 +src/video/nds/SDL_ndsrender.c \
    1.75 +src/video/nds/SDL_ndsvideo.c \
    1.76 +src/video/SDL_blit_0.c \
    1.77 +src/video/SDL_blit_1.c \
    1.78 +src/video/SDL_blit_A.c \
    1.79 +src/video/SDL_blit_auto.c \
    1.80 +src/video/SDL_blit.c \
    1.81 +src/video/SDL_blit_copy.c \
    1.82 +src/video/SDL_blit_N.c \
    1.83 +src/video/SDL_blit_slow.c \
    1.84 +src/video/SDL_bmp.c \
    1.85 +src/video/SDL_fill.c \
    1.86 +src/video/SDL_gamma.c \
    1.87 +src/video/SDL_pixels.c \
    1.88 +src/video/SDL_rect.c \
    1.89 +src/video/SDL_renderer_gl.c \
    1.90 +src/video/SDL_renderer_sw.c \
    1.91 +src/video/SDL_RLEaccel.c \
    1.92 +src/video/SDL_stretch.c \
    1.93 +src/video/SDL_surface.c \
    1.94 +src/video/SDL_video.c \
    1.95 +src/video/SDL_yuv_mmx.c \
    1.96 +src/video/SDL_yuv_sw.c \
    1.97 +
    1.98 +OBJS = $(SRCS:.c=.o)
    1.99 +
   1.100 +TEST = \
   1.101 +	test/checkkeys.c \
   1.102 +	test/graywin.c \
   1.103 +	test/loopwave.c \
   1.104 +	test/testalpha.c \
   1.105 +	test/testbitmap.c \
   1.106 +	test/testcdrom.c \
   1.107 +	test/testerror.c \
   1.108 +	test/testgamma.c \
   1.109 +	test/testgl.c \
   1.110 +	test/testhread.c \
   1.111 +	test/testjoystick.c \
   1.112 +	test/testkeys.c \
   1.113 +	test/testlock.c \
   1.114 +	test/testoverlay.c \
   1.115 +	test/testpalette.c \
   1.116 +	test/testsem.c \
   1.117 +	test/testsprite.c \
   1.118 +	test/testtimer.c \
   1.119 +	test/testtypes.c \
   1.120 +	test/testver.c \
   1.121 +	test/testvidinfo.c \
   1.122 +	test/testwin.c \
   1.123 +	test/testwm.c \
   1.124 +	test/threadwin.c \
   1.125 +	test/torturethread.c \
   1.126 +
   1.127 +all: $(TARGET)
   1.128 +
   1.129 +$(TARGET): copy_config \
   1.130 +	$(OBJS)
   1.131 +	$(AR) rc $(TARGET) $(OBJS)
   1.132 +	-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
   1.133 +
   1.134 +install: $(TARGET)
   1.135 +	@cp libSDL.a $(DEVKITPRO)/libnds/lib/
   1.136 +
   1.137 +copy_config:
   1.138 +	@cp include/SDL_config.h.default include/SDL_config.h
   1.139 +
   1.140 +clean:
   1.141 +	rm -f include/SDL_config.h $(OBJS)
   1.142 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/include/SDL_config_nintendods.h	Tue Jun 10 06:57:57 2008 +0000
     2.3 @@ -0,0 +1,117 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2006 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +
    2.26 +#ifndef _SDL_config_nintendods_h
    2.27 +#define _SDL_config_nintendods_h
    2.28 +
    2.29 +#include "SDL_platform.h"
    2.30 +
    2.31 +/* This is a set of defines to configure the SDL features */
    2.32 +
    2.33 +typedef signed char int8_t;
    2.34 +typedef unsigned char uint8_t;
    2.35 +typedef signed short int16_t;
    2.36 +typedef unsigned short uint16_t;
    2.37 +typedef signed int int32_t;
    2.38 +typedef unsigned int uint32_t;
    2.39 +typedef signed long long int64_t;
    2.40 +typedef unsigned long long uint64_t;
    2.41 +
    2.42 +/* LiF: __PTRDIFF_TYPE__ was causing errors of conflicting typedefs with the
    2.43 +   <stdint.h> shipping with devkitARM.  copied a similar ifdef from it. */
    2.44 +#ifndef __PTRDIFF_TYPE__
    2.45 +typedef unsigned long uintptr_t;
    2.46 +#else
    2.47 +typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
    2.48 +#endif
    2.49 +
    2.50 +
    2.51 +#define SDL_HAS_64BIT_TYPE	1
    2.52 +
    2.53 +/* Useful headers */
    2.54 +#define HAVE_SYS_TYPES_H	1
    2.55 +#define HAVE_STDIO_H	1
    2.56 +#define STDC_HEADERS	1
    2.57 +#define HAVE_STRING_H	1
    2.58 +#define HAVE_CTYPE_H	1
    2.59 +
    2.60 +/* C library functions */
    2.61 +#define HAVE_MALLOC	1
    2.62 +#define HAVE_CALLOC	1
    2.63 +#define HAVE_REALLOC	1
    2.64 +#define HAVE_FREE	1
    2.65 +#define HAVE_ALLOCA	1
    2.66 +#define HAVE_GETENV	1
    2.67 +#define HAVE_PUTENV	1
    2.68 +#define HAVE_QSORT	1
    2.69 +#define HAVE_ABS	1
    2.70 +#define HAVE_BCOPY	1
    2.71 +#define HAVE_MEMSET	1
    2.72 +#define HAVE_MEMCPY	1
    2.73 +#define HAVE_MEMMOVE	1
    2.74 +#define HAVE_MEMCMP	1
    2.75 +#define HAVE_STRLEN	1
    2.76 +#define HAVE_STRDUP	1
    2.77 +#define HAVE_INDEX	1
    2.78 +#define HAVE_RINDEX	1
    2.79 +#define HAVE_STRCHR	1
    2.80 +#define HAVE_STRRCHR	1
    2.81 +#define HAVE_STRSTR	1
    2.82 +#define HAVE_STRTOL	1
    2.83 +#define HAVE_STRTOD	1
    2.84 +#define HAVE_ATOI	1
    2.85 +#define HAVE_ATOF	1
    2.86 +#define HAVE_STRCMP	1
    2.87 +#define HAVE_STRNCMP	1
    2.88 +#define HAVE_STRICMP	1
    2.89 +#define HAVE_STRCASECMP	1
    2.90 +#define HAVE_SSCANF	1
    2.91 +#define HAVE_SNPRINTF	1
    2.92 +#define HAVE_VSNPRINTF	1
    2.93 +
    2.94 +/* DS isn't that sophisticated */
    2.95 +#define LACKS_SYS_MMAN_H 1
    2.96 +
    2.97 +/* Enable various audio drivers */
    2.98 +#define SDL_AUDIO_DRIVER_DUMMY	1
    2.99 +
   2.100 +/* DS doesn't have optical media */
   2.101 +#define SDL_CDROM_DISABLED	1
   2.102 +
   2.103 +/* Enable various input drivers */
   2.104 +#define SDL_JOYSTICK_DISABLED	1
   2.105 +
   2.106 +/* DS has no dynamic linking afaik */
   2.107 +#define SDL_LOADSO_DISABLED	1
   2.108 +
   2.109 +/* Enable various threading systems */
   2.110 +/*#define SDL_THREAD_NDS	1*/
   2.111 +#define SDL_THREADS_DISABLED	1
   2.112 +
   2.113 +/* Enable various timer systems */
   2.114 +#define SDL_TIMERS_DISABLED	1
   2.115 +
   2.116 +/* Enable various video drivers */
   2.117 +#define SDL_VIDEO_DRIVER_NDS	1
   2.118 +
   2.119 +#endif /* _SDL_config_nintendods_h */
   2.120 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Tue Jun 10 06:57:57 2008 +0000
     3.3 @@ -0,0 +1,154 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Library General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Library General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Library General Public
    3.19 +    License along with this library; if not, write to the Free
    3.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@devolution.com
    3.24 +*/
    3.25 +
    3.26 +#ifdef SAVE_RCSID
    3.27 +static char rcsid =
    3.28 + "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
    3.29 +#endif
    3.30 +
    3.31 +/* This is the system specific header for the SDL joystick API */
    3.32 +#include <nds.h>
    3.33 +//#include <nds/registers_alt.h>
    3.34 +#include <stdio.h>		/* For the definition of NULL */
    3.35 +
    3.36 +#include "SDL_error.h"
    3.37 +#include "SDL_joystick.h"
    3.38 +#include "SDL_sysjoystick.h"
    3.39 +#include "SDL_joystick_c.h"
    3.40 +
    3.41 +#include "../../video/nds/SDL_ndsevents_c.h"
    3.42 +
    3.43 +/* Function to scan the system for joysticks.
    3.44 + * This function should set SDL_numjoysticks to the number of available
    3.45 + * joysticks.  Joystick 0 should be the system default joystick.
    3.46 + * It should return 0, or -1 on an unrecoverable fatal error.
    3.47 + */
    3.48 +int SDL_SYS_JoystickInit(void)
    3.49 +{
    3.50 +	SDL_numjoysticks = 1;
    3.51 +    //keysInit();
    3.52 +
    3.53 +	return(1);
    3.54 +}
    3.55 +
    3.56 +/* Function to get the device-dependent name of a joystick */
    3.57 +const char *SDL_SYS_JoystickName(int index)
    3.58 +{
    3.59 +	if(!index)
    3.60 +		return "NDS builtin joypad";
    3.61 +	SDL_SetError("No joystick available with that index");
    3.62 +	return (NULL);
    3.63 +}
    3.64 +
    3.65 +/* Function to open a joystick for use.
    3.66 +   The joystick to open is specified by the index field of the joystick.
    3.67 +   This should fill the nbuttons and naxes fields of the joystick structure.
    3.68 +   It returns 0, or -1 if there is an error.
    3.69 + */
    3.70 +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
    3.71 +{
    3.72 +	joystick->nbuttons=8;
    3.73 +	joystick->nhats=0;
    3.74 +	joystick->nballs=0;
    3.75 +	joystick->naxes=2;
    3.76 +	return 0;
    3.77 +}
    3.78 +
    3.79 +
    3.80 +/* Function to update the state of a joystick - called as a device poll.
    3.81 + * This function shouldn't update the joystick structure directly,
    3.82 + * but instead should call SDL_PrivateJoystick*() to deliver events
    3.83 + * and update joystick device state.
    3.84 + */
    3.85 +
    3.86 +int prevbutton=0;
    3.87 +int prevkey=0;
    3.88 +
    3.89 +int dc=NULL;int ldc=0;
    3.90 +u32 keysd,keysu=NULL;
    3.91 +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
    3.92 +{
    3.93 +    //dc=keysd;
    3.94 +	//if (dc != NULL)
    3.95 +	//{
    3.96 +		//fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
    3.97 +		//swiWaitForVBlank();
    3.98 +		//scanKeys();
    3.99 +		//keysd = keysDown(); 
   3.100 +		//keysu = keysUp();
   3.101 +		//ldc=keysd;
   3.102 +		 
   3.103 +	//}
   3.104 +	/*if (prevkey !=NULL && prevbutton !=NULL)
   3.105 +	{
   3.106 +		scanKeys();
   3.107 +	}
   3.108 +	*/
   3.109 +	
   3.110 +	//scanKeys();
   3.111 +		keysd = keysDown(); 
   3.112 +		keysu = keysUp();
   3.113 +		
   3.114 +	
   3.115 +	short ax=0,v=0,h=0;
   3.116 +	if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");}
   3.117 +	if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");}
   3.118 +	if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");}
   3.119 +	if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");}
   3.120 +
   3.121 +	if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_UP\n");}
   3.122 +	if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_DOWN\n");}
   3.123 +	if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_LEFT\n");}
   3.124 +	if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_RIGHT\n");}
   3.125 +
   3.126 +	if((keysd&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;}
   3.127 +	if((keysd&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;}
   3.128 +	if((keysd&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;}
   3.129 +	if((keysd&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;}
   3.130 +	if((keysd&KEY_SELECT))	{SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;}
   3.131 +	if((keysd&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;}
   3.132 +	if((keysd&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;}
   3.133 +	if((keysd&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;}
   3.134 +
   3.135 +	if((keysu&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=NULL;}
   3.136 +	if((keysu&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=NULL;}
   3.137 +	if((keysu&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=NULL;}
   3.138 +	if((keysu&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=NULL;}
   3.139 +	if((keysu&KEY_SELECT))  {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=NULL;}
   3.140 +	if((keysu&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=NULL;}
   3.141 +	if((keysu&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=NULL;}
   3.142 +	if((keysu&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=NULL;}
   3.143 +
   3.144 +
   3.145 +
   3.146 +}
   3.147 +
   3.148 +/* Function to close a joystick after use */
   3.149 +void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
   3.150 +{
   3.151 +}
   3.152 +
   3.153 +/* Function to perform any system-specific joystick related cleanup */
   3.154 +void SDL_SYS_JoystickQuit(void)
   3.155 +{
   3.156 +}
   3.157 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/thread/nds/SDL_syscond.c	Tue Jun 10 06:57:57 2008 +0000
     4.3 @@ -0,0 +1,223 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  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 Library General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2 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 +    Library General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Library General Public
    4.19 +    License along with this library; if not, write to the Free
    4.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@devolution.com
    4.24 +*/
    4.25 +
    4.26 +#ifdef SAVE_RCSID
    4.27 +static char rcsid =
    4.28 + "@(#) $Id: SDL_syscond.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    4.29 +#endif
    4.30 +
    4.31 +/* An implementation of condition variables using semaphores and mutexes */
    4.32 +/*
    4.33 +   This implementation borrows heavily from the BeOS condition variable
    4.34 +   implementation, written by Christopher Tate and Owen Smith.  Thanks!
    4.35 + */
    4.36 +
    4.37 +#include <stdio.h>
    4.38 +#include <stdlib.h>
    4.39 +
    4.40 +#include "SDL_error.h"
    4.41 +#include "SDL_thread.h"
    4.42 +
    4.43 +struct SDL_cond
    4.44 +{
    4.45 +	SDL_mutex *lock;
    4.46 +	int waiting;
    4.47 +	int signals;
    4.48 +	SDL_sem *wait_sem;
    4.49 +	SDL_sem *wait_done;
    4.50 +};
    4.51 +
    4.52 +/* Create a condition variable */
    4.53 +SDL_cond * SDL_CreateCond(void)
    4.54 +{
    4.55 +	SDL_cond *cond;
    4.56 +
    4.57 +	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
    4.58 +	if ( cond ) {
    4.59 +		cond->lock = SDL_CreateMutex();
    4.60 +		cond->wait_sem = SDL_CreateSemaphore(0);
    4.61 +		cond->wait_done = SDL_CreateSemaphore(0);
    4.62 +		cond->waiting = cond->signals = 0;
    4.63 +		if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) {
    4.64 +			SDL_DestroyCond(cond);
    4.65 +			cond = NULL;
    4.66 +		}
    4.67 +	} else {
    4.68 +		SDL_OutOfMemory();
    4.69 +	}
    4.70 +	return(cond);
    4.71 +}
    4.72 +
    4.73 +/* Destroy a condition variable */
    4.74 +void SDL_DestroyCond(SDL_cond *cond)
    4.75 +{
    4.76 +	if ( cond ) {
    4.77 +		if ( cond->wait_sem ) {
    4.78 +			SDL_DestroySemaphore(cond->wait_sem);
    4.79 +		}
    4.80 +		if ( cond->wait_done ) {
    4.81 +			SDL_DestroySemaphore(cond->wait_done);
    4.82 +		}
    4.83 +		if ( cond->lock ) {
    4.84 +			SDL_DestroyMutex(cond->lock);
    4.85 +		}
    4.86 +		free(cond);
    4.87 +	}
    4.88 +}
    4.89 +
    4.90 +/* Restart one of the threads that are waiting on the condition variable */
    4.91 +int SDL_CondSignal(SDL_cond *cond)
    4.92 +{
    4.93 +	if ( ! cond ) {
    4.94 +		SDL_SetError("Passed a NULL condition variable");
    4.95 +		return -1;
    4.96 +	}
    4.97 +
    4.98 +	/* If there are waiting threads not already signalled, then
    4.99 +	   signal the condition and wait for the thread to respond.
   4.100 +	*/
   4.101 +	SDL_LockMutex(cond->lock);
   4.102 +	if ( cond->waiting > cond->signals ) {
   4.103 +		++cond->signals;
   4.104 +		SDL_SemPost(cond->wait_sem);
   4.105 +		SDL_UnlockMutex(cond->lock);
   4.106 +		SDL_SemWait(cond->wait_done);
   4.107 +	} else {
   4.108 +		SDL_UnlockMutex(cond->lock);
   4.109 +	}
   4.110 +
   4.111 +	return 0;
   4.112 +}
   4.113 +
   4.114 +/* Restart all threads that are waiting on the condition variable */
   4.115 +int SDL_CondBroadcast(SDL_cond *cond)
   4.116 +{
   4.117 +	if ( ! cond ) {
   4.118 +		SDL_SetError("Passed a NULL condition variable");
   4.119 +		return -1;
   4.120 +	}
   4.121 +
   4.122 +	/* If there are waiting threads not already signalled, then
   4.123 +	   signal the condition and wait for the thread to respond.
   4.124 +	*/
   4.125 +	SDL_LockMutex(cond->lock);
   4.126 +	if ( cond->waiting > cond->signals ) {
   4.127 +		int i, num_waiting;
   4.128 +
   4.129 +		num_waiting = (cond->waiting - cond->signals);
   4.130 +		cond->signals = cond->waiting;
   4.131 +		for ( i=0; i<num_waiting; ++i ) {
   4.132 +			SDL_SemPost(cond->wait_sem);
   4.133 +		}
   4.134 +		/* Now all released threads are blocked here, waiting for us.
   4.135 +		   Collect them all (and win fabulous prizes!) :-)
   4.136 +		 */
   4.137 +		SDL_UnlockMutex(cond->lock);
   4.138 +		for ( i=0; i<num_waiting; ++i ) {
   4.139 +			SDL_SemWait(cond->wait_done);
   4.140 +		}
   4.141 +	} else {
   4.142 +		SDL_UnlockMutex(cond->lock);
   4.143 +	}
   4.144 +
   4.145 +	return 0;
   4.146 +}
   4.147 +
   4.148 +/* Wait on the condition variable for at most 'ms' milliseconds.
   4.149 +   The mutex must be locked before entering this function!
   4.150 +   The mutex is unlocked during the wait, and locked again after the wait.
   4.151 +
   4.152 +Typical use:
   4.153 +
   4.154 +Thread A:
   4.155 +	SDL_LockMutex(lock);
   4.156 +	while ( ! condition ) {
   4.157 +		SDL_CondWait(cond);
   4.158 +	}
   4.159 +	SDL_UnlockMutex(lock);
   4.160 +
   4.161 +Thread B:
   4.162 +	SDL_LockMutex(lock);
   4.163 +	...
   4.164 +	condition = true;
   4.165 +	...
   4.166 +	SDL_UnlockMutex(lock);
   4.167 + */
   4.168 +int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
   4.169 +{
   4.170 +	int retval;
   4.171 +
   4.172 +	if ( ! cond ) {
   4.173 +		SDL_SetError("Passed a NULL condition variable");
   4.174 +		return -1;
   4.175 +	}
   4.176 +
   4.177 +	/* Obtain the protection mutex, and increment the number of waiters.
   4.178 +	   This allows the signal mechanism to only perform a signal if there
   4.179 +	   are waiting threads.
   4.180 +	 */
   4.181 +	SDL_LockMutex(cond->lock);
   4.182 +	++cond->waiting;
   4.183 +	SDL_UnlockMutex(cond->lock);
   4.184 +
   4.185 +	/* Unlock the mutex, as is required by condition variable semantics */
   4.186 +	SDL_UnlockMutex(mutex);
   4.187 +
   4.188 +	/* Wait for a signal */
   4.189 +	if ( ms == SDL_MUTEX_MAXWAIT ) {
   4.190 +		retval = SDL_SemWait(cond->wait_sem);
   4.191 +	} else {
   4.192 +		retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
   4.193 +	}
   4.194 +
   4.195 +	/* Let the signaler know we have completed the wait, otherwise
   4.196 +           the signaler can race ahead and get the condition semaphore
   4.197 +           if we are stopped between the mutex unlock and semaphore wait,
   4.198 +           giving a deadlock.  See the following URL for details:
   4.199 +        http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
   4.200 +	*/
   4.201 +	SDL_LockMutex(cond->lock);
   4.202 +	if ( cond->signals > 0 ) {
   4.203 +		/* If we timed out, we need to eat a condition signal */
   4.204 +		if ( retval > 0 ) {
   4.205 +			SDL_SemWait(cond->wait_sem);
   4.206 +		}
   4.207 +		/* We always notify the signal thread that we are done */
   4.208 +		SDL_SemPost(cond->wait_done);
   4.209 +
   4.210 +		/* Signal handshake complete */
   4.211 +		--cond->signals;
   4.212 +	}
   4.213 +	--cond->waiting;
   4.214 +	SDL_UnlockMutex(cond->lock);
   4.215 +
   4.216 +	/* Lock the mutex, as is required by condition variable semantics */
   4.217 +	SDL_LockMutex(mutex);
   4.218 +
   4.219 +	return retval;
   4.220 +}
   4.221 +
   4.222 +/* Wait on the condition variable forever */
   4.223 +int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
   4.224 +{
   4.225 +	return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
   4.226 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/thread/nds/SDL_syscond_c.h	Tue Jun 10 06:57:57 2008 +0000
     5.3 @@ -0,0 +1,27 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Library General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Library General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Library General Public
    5.19 +    License along with this library; if not, write to the Free
    5.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@devolution.com
    5.24 +*/
    5.25 +
    5.26 +#ifdef SAVE_RCSID
    5.27 +static char rcsid =
    5.28 + "@(#) $Id: SDL_syscond_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    5.29 +#endif
    5.30 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/thread/nds/SDL_sysmutex.c	Tue Jun 10 06:57:57 2008 +0000
     6.3 @@ -0,0 +1,137 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Library General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Library General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Library General Public
    6.19 +    License along with this library; if not, write to the Free
    6.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    slouken@devolution.com
    6.24 +*/
    6.25 +
    6.26 +#ifdef SAVE_RCSID
    6.27 +static char rcsid =
    6.28 + "@(#) $Id: SDL_sysmutex.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    6.29 +#endif
    6.30 +
    6.31 +/* An implementation of mutexes using semaphores */
    6.32 +
    6.33 +#include <stdio.h>
    6.34 +#include <stdlib.h>
    6.35 +
    6.36 +#include "SDL_error.h"
    6.37 +#include "SDL_thread.h"
    6.38 +#include "SDL_systhread_c.h"
    6.39 +
    6.40 +
    6.41 +struct SDL_mutex {
    6.42 +	int recursive;
    6.43 +	Uint32 owner;
    6.44 +	SDL_sem *sem;
    6.45 +};
    6.46 +
    6.47 +/* Create a mutex */
    6.48 +SDL_mutex *SDL_CreateMutex(void)
    6.49 +{
    6.50 +	SDL_mutex *mutex;
    6.51 +
    6.52 +	/* Allocate mutex memory */
    6.53 +	mutex = (SDL_mutex *)malloc(sizeof(*mutex));
    6.54 +	if ( mutex ) {
    6.55 +		/* Create the mutex semaphore, with initial value 1 */
    6.56 +		mutex->sem = SDL_CreateSemaphore(1);
    6.57 +		mutex->recursive = 0;
    6.58 +		mutex->owner = 0;
    6.59 +		if ( ! mutex->sem ) {
    6.60 +			free(mutex);
    6.61 +			mutex = NULL;
    6.62 +		}
    6.63 +	} else {
    6.64 +		SDL_OutOfMemory();
    6.65 +	}
    6.66 +	return mutex;
    6.67 +}
    6.68 +
    6.69 +/* Free the mutex */
    6.70 +void SDL_DestroyMutex(SDL_mutex *mutex)
    6.71 +{
    6.72 +	if ( mutex ) {
    6.73 +		if ( mutex->sem ) {
    6.74 +			SDL_DestroySemaphore(mutex->sem);
    6.75 +		}
    6.76 +		free(mutex);
    6.77 +	}
    6.78 +}
    6.79 +
    6.80 +/* Lock the semaphore */
    6.81 +int SDL_mutexP(SDL_mutex *mutex)
    6.82 +{
    6.83 +#ifdef DISABLE_THREADS
    6.84 +	return 0;
    6.85 +#else
    6.86 +	Uint32 this_thread;
    6.87 +
    6.88 +	if ( mutex == NULL ) {
    6.89 +		SDL_SetError("Passed a NULL mutex");
    6.90 +		return -1;
    6.91 +	}
    6.92 +
    6.93 +	this_thread = SDL_ThreadID();
    6.94 +	if ( mutex->owner == this_thread ) {
    6.95 +		++mutex->recursive;
    6.96 +	} else {
    6.97 +		/* The order of operations is important.
    6.98 +		   We set the locking thread id after we obtain the lock
    6.99 +		   so unlocks from other threads will fail.
   6.100 +		*/
   6.101 +		SDL_SemWait(mutex->sem);
   6.102 +		mutex->owner = this_thread;
   6.103 +		mutex->recursive = 0;
   6.104 +	}
   6.105 +
   6.106 +	return 0;
   6.107 +#endif /* DISABLE_THREADS */
   6.108 +}
   6.109 +
   6.110 +/* Unlock the mutex */
   6.111 +int SDL_mutexV(SDL_mutex *mutex)
   6.112 +{
   6.113 +#ifdef DISABLE_THREADS
   6.114 +	return 0;
   6.115 +#else
   6.116 +	if ( mutex == NULL ) {
   6.117 +		SDL_SetError("Passed a NULL mutex");
   6.118 +		return -1;
   6.119 +	}
   6.120 +
   6.121 +	/* If we don't own the mutex, we can't unlock it */
   6.122 +	if ( SDL_ThreadID() != mutex->owner ) {
   6.123 +		SDL_SetError("mutex not owned by this thread");
   6.124 +		return -1;
   6.125 +	}
   6.126 +
   6.127 +	if ( mutex->recursive ) {
   6.128 +		--mutex->recursive;
   6.129 +	} else {
   6.130 +		/* The order of operations is important.
   6.131 +		   First reset the owner so another thread doesn't lock
   6.132 +		   the mutex and set the ownership before we reset it,
   6.133 +		   then release the lock semaphore.
   6.134 +		 */
   6.135 +		mutex->owner = 0;
   6.136 +		SDL_SemPost(mutex->sem);
   6.137 +	}
   6.138 +	return 0;
   6.139 +#endif /* DISABLE_THREADS */
   6.140 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/thread/nds/SDL_sysmutex_c.h	Tue Jun 10 06:57:57 2008 +0000
     7.3 @@ -0,0 +1,27 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Library General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Library General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Library General Public
    7.19 +    License along with this library; if not, write to the Free
    7.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@devolution.com
    7.24 +*/
    7.25 +
    7.26 +#ifdef SAVE_RCSID
    7.27 +static char rcsid =
    7.28 + "@(#) $Id: SDL_sysmutex_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    7.29 +#endif
    7.30 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/thread/nds/SDL_syssem.c	Tue Jun 10 06:57:57 2008 +0000
     8.3 @@ -0,0 +1,214 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Library General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Library General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Library General Public
    8.19 +    License along with this library; if not, write to the Free
    8.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@devolution.com
    8.24 +*/
    8.25 +
    8.26 +#ifdef SAVE_RCSID
    8.27 +static char rcsid =
    8.28 + "@(#) $Id: SDL_syssem.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    8.29 +#endif
    8.30 +
    8.31 +/* An implementation of semaphores using mutexes and condition variables */
    8.32 +
    8.33 +#include <stdlib.h>
    8.34 +
    8.35 +#include "SDL_error.h"
    8.36 +#include "SDL_timer.h"
    8.37 +#include "SDL_thread.h"
    8.38 +#include "SDL_systhread_c.h"
    8.39 +
    8.40 +
    8.41 +#ifdef DISABLE_THREADS
    8.42 +
    8.43 +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
    8.44 +{
    8.45 +	SDL_SetError("SDL not configured with thread support");
    8.46 +	return (SDL_sem *)0;
    8.47 +}
    8.48 +
    8.49 +void SDL_DestroySemaphore(SDL_sem *sem)
    8.50 +{
    8.51 +	return;
    8.52 +}
    8.53 +
    8.54 +int SDL_SemTryWait(SDL_sem *sem)
    8.55 +{
    8.56 +	SDL_SetError("SDL not configured with thread support");
    8.57 +	return -1;
    8.58 +}
    8.59 +
    8.60 +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
    8.61 +{
    8.62 +	SDL_SetError("SDL not configured with thread support");
    8.63 +	return -1;
    8.64 +}
    8.65 +
    8.66 +int SDL_SemWait(SDL_sem *sem)
    8.67 +{
    8.68 +	SDL_SetError("SDL not configured with thread support");
    8.69 +	return -1;
    8.70 +}
    8.71 +
    8.72 +Uint32 SDL_SemValue(SDL_sem *sem)
    8.73 +{
    8.74 +	return 0;
    8.75 +}
    8.76 +
    8.77 +int SDL_SemPost(SDL_sem *sem)
    8.78 +{
    8.79 +	SDL_SetError("SDL not configured with thread support");
    8.80 +	return -1;
    8.81 +}
    8.82 +
    8.83 +#else
    8.84 +
    8.85 +struct SDL_semaphore
    8.86 +{
    8.87 +	Uint32 count;
    8.88 +	Uint32 waiters_count;
    8.89 +	SDL_mutex *count_lock;
    8.90 +	SDL_cond *count_nonzero;
    8.91 +};
    8.92 +
    8.93 +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
    8.94 +{
    8.95 +	SDL_sem *sem;
    8.96 +
    8.97 +	sem = (SDL_sem *)malloc(sizeof(*sem));
    8.98 +	if ( ! sem ) {
    8.99 +		SDL_OutOfMemory();
   8.100 +		return(0);
   8.101 +	}
   8.102 +	sem->count = initial_value;
   8.103 +	sem->waiters_count = 0;
   8.104 +
   8.105 +	sem->count_lock = SDL_CreateMutex();
   8.106 +	sem->count_nonzero = SDL_CreateCond();
   8.107 +	if ( ! sem->count_lock || ! sem->count_nonzero ) {
   8.108 +		SDL_DestroySemaphore(sem);
   8.109 +		return(0);
   8.110 +	}
   8.111 +
   8.112 +	return(sem);
   8.113 +}
   8.114 +
   8.115 +/* WARNING:
   8.116 +   You cannot call this function when another thread is using the semaphore.
   8.117 +*/
   8.118 +void SDL_DestroySemaphore(SDL_sem *sem)
   8.119 +{
   8.120 +	if ( sem ) {
   8.121 +		sem->count = 0xFFFFFFFF;
   8.122 +		while ( sem->waiters_count > 0) {
   8.123 +			SDL_CondSignal(sem->count_nonzero);
   8.124 +			SDL_Delay(10);
   8.125 +		}
   8.126 +		SDL_DestroyCond(sem->count_nonzero);
   8.127 +		SDL_mutexP(sem->count_lock);
   8.128 +		SDL_mutexV(sem->count_lock);
   8.129 +		SDL_DestroyMutex(sem->count_lock);
   8.130 +		free(sem);
   8.131 +	}
   8.132 +}
   8.133 +
   8.134 +int SDL_SemTryWait(SDL_sem *sem)
   8.135 +{
   8.136 +	int retval;
   8.137 +
   8.138 +	if ( ! sem ) {
   8.139 +		SDL_SetError("Passed a NULL semaphore");
   8.140 +		return -1;
   8.141 +	}
   8.142 +
   8.143 +	retval = SDL_MUTEX_TIMEDOUT;
   8.144 +	SDL_LockMutex(sem->count_lock);
   8.145 +	if ( sem->count > 0 ) {
   8.146 +		--sem->count;
   8.147 +		retval = 0;
   8.148 +	}
   8.149 +	SDL_UnlockMutex(sem->count_lock);
   8.150 +
   8.151 +	return retval;
   8.152 +}
   8.153 +
   8.154 +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
   8.155 +{
   8.156 +	int retval;
   8.157 +
   8.158 +	if ( ! sem ) {
   8.159 +		SDL_SetError("Passed a NULL semaphore");
   8.160 +		return -1;
   8.161 +	}
   8.162 +
   8.163 +	/* A timeout of 0 is an easy case */
   8.164 +	if ( timeout == 0 ) {
   8.165 +		return SDL_SemTryWait(sem);
   8.166 +	}
   8.167 +
   8.168 +	SDL_LockMutex(sem->count_lock);
   8.169 +	++sem->waiters_count;
   8.170 +	retval = 0;
   8.171 +	while ( (sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT) ) {
   8.172 +		retval = SDL_CondWaitTimeout(sem->count_nonzero,
   8.173 +		                             sem->count_lock, timeout);
   8.174 +	}
   8.175 +	--sem->waiters_count;
   8.176 +	--sem->count;
   8.177 +	SDL_UnlockMutex(sem->count_lock);
   8.178 +
   8.179 +	return retval;
   8.180 +}
   8.181 +
   8.182 +int SDL_SemWait(SDL_sem *sem)
   8.183 +{
   8.184 +	return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
   8.185 +}
   8.186 +
   8.187 +Uint32 SDL_SemValue(SDL_sem *sem)
   8.188 +{
   8.189 +	Uint32 value;
   8.190 +	
   8.191 +	value = 0;
   8.192 +	if ( sem ) {
   8.193 +		SDL_LockMutex(sem->count_lock);
   8.194 +		value = sem->count;
   8.195 +		SDL_UnlockMutex(sem->count_lock);
   8.196 +	}
   8.197 +	return value;
   8.198 +}
   8.199 +
   8.200 +int SDL_SemPost(SDL_sem *sem)
   8.201 +{
   8.202 +	if ( ! sem ) {
   8.203 +		SDL_SetError("Passed a NULL semaphore");
   8.204 +		return -1;
   8.205 +	}
   8.206 +
   8.207 +	SDL_LockMutex(sem->count_lock);
   8.208 +	if ( sem->waiters_count > 0 ) {
   8.209 +		SDL_CondSignal(sem->count_nonzero);
   8.210 +	}
   8.211 +	++sem->count;
   8.212 +	SDL_UnlockMutex(sem->count_lock);
   8.213 +
   8.214 +	return 0;
   8.215 +}
   8.216 +
   8.217 +#endif /* DISABLE_THREADS */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/thread/nds/SDL_syssem_c.h	Tue Jun 10 06:57:57 2008 +0000
     9.3 @@ -0,0 +1,27 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Library General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Library General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Library General Public
    9.19 +    License along with this library; if not, write to the Free
    9.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@devolution.com
    9.24 +*/
    9.25 +
    9.26 +#ifdef SAVE_RCSID
    9.27 +static char rcsid =
    9.28 + "@(#) $Id: SDL_syssem_c.h,v 1.2 2001/04/26 16:50:18 hercules Exp $";
    9.29 +#endif
    9.30 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/thread/nds/SDL_systhread.c	Tue Jun 10 06:57:57 2008 +0000
    10.3 @@ -0,0 +1,59 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    10.7 +
    10.8 +    This library is free software; you can redistribute it and/or
    10.9 +    modify it under the terms of the GNU Library General Public
   10.10 +    License as published by the Free Software Foundation; either
   10.11 +    version 2 of the License, or (at your option) any later version.
   10.12 +
   10.13 +    This library is distributed in the hope that it will be useful,
   10.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 +    Library General Public License for more details.
   10.17 +
   10.18 +    You should have received a copy of the GNU Library General Public
   10.19 +    License along with this library; if not, write to the Free
   10.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.21 +
   10.22 +    Sam Lantinga
   10.23 +    slouken@devolution.com
   10.24 +*/
   10.25 +
   10.26 +#ifdef SAVE_RCSID
   10.27 +static char rcsid =
   10.28 + "@(#) $Id: SDL_systhread.c,v 1.2 2001/04/26 16:50:18 hercules Exp $";
   10.29 +#endif
   10.30 +
   10.31 +/* Thread management routines for SDL */
   10.32 +
   10.33 +#include "SDL_error.h"
   10.34 +#include "SDL_thread.h"
   10.35 +#include "SDL_systhread.h"
   10.36 +
   10.37 +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
   10.38 +{
   10.39 +	SDL_SetError("Threads are not supported on this platform");
   10.40 +	return(-1);
   10.41 +}
   10.42 +
   10.43 +void SDL_SYS_SetupThread(void)
   10.44 +{
   10.45 +	return;
   10.46 +}
   10.47 +
   10.48 +Uint32 SDL_ThreadID(void)
   10.49 +{
   10.50 +	return(0);
   10.51 +}
   10.52 +
   10.53 +void SDL_SYS_WaitThread(SDL_Thread *thread)
   10.54 +{
   10.55 +	return;
   10.56 +}
   10.57 +
   10.58 +void SDL_SYS_KillThread(SDL_Thread *thread)
   10.59 +{
   10.60 +	return;
   10.61 +}
   10.62 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/thread/nds/SDL_systhread_c.h	Tue Jun 10 06:57:57 2008 +0000
    11.3 @@ -0,0 +1,28 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    11.7 +
    11.8 +    This library is free software; you can redistribute it and/or
    11.9 +    modify it under the terms of the GNU Library General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2 of the License, or (at your option) any later version.
   11.12 +
   11.13 +    This library is distributed in the hope that it will be useful,
   11.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +    Library General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Library General Public
   11.19 +    License along with this library; if not, write to the Free
   11.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@devolution.com
   11.24 +*/
   11.25 +
   11.26 +/* Stub until we implement threads on this platform */
   11.27 +typedef int SYS_ThreadHandle;
   11.28 +
   11.29 +#ifndef DISABLE_THREADS
   11.30 +#define DISABLE_THREADS
   11.31 +#endif
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/nds/SDL_ndsevents.c	Tue Jun 10 06:57:57 2008 +0000
    12.3 @@ -0,0 +1,44 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997-2006 Sam Lantinga
    12.7 +
    12.8 +    This library is free software; you can redistribute it and/or
    12.9 +    modify it under the terms of the GNU Lesser General Public
   12.10 +    License as published by the Free Software Foundation; either
   12.11 +    version 2.1 of the License, or (at your option) any later version.
   12.12 +
   12.13 +    This library is distributed in the hope that it will be useful,
   12.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 +    Lesser General Public License for more details.
   12.17 +
   12.18 +    You should have received a copy of the GNU Lesser General Public
   12.19 +    License along with this library; if not, write to the Free Software
   12.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.21 +
   12.22 +    Sam Lantinga
   12.23 +    slouken@libsdl.org
   12.24 +*/
   12.25 +#include "SDL_config.h"
   12.26 +
   12.27 +/* Being a null driver, there's no event stream. We just define stubs for
   12.28 +   most of the API. */
   12.29 +
   12.30 +#include <stdio.h>
   12.31 +#include <stdlib.h>
   12.32 +#include <nds.h>
   12.33 +
   12.34 +#include "SDL.h"
   12.35 +#include "../../events/SDL_sysevents.h"
   12.36 +#include "../../events/SDL_events_c.h"
   12.37 +
   12.38 +#include "SDL_ndsvideo.h"
   12.39 +#include "SDL_ndsevents_c.h"
   12.40 +
   12.41 +void
   12.42 +NDS_PumpEvents(_THIS)
   12.43 +{
   12.44 +    /* do nothing. */
   12.45 +}
   12.46 +
   12.47 +/* vi: set ts=4 sw=4 expandtab: */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/video/nds/SDL_ndsevents_c.h	Tue Jun 10 06:57:57 2008 +0000
    13.3 @@ -0,0 +1,28 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997-2006 Sam Lantinga
    13.7 +
    13.8 +    This library is free software; you can redistribute it and/or
    13.9 +    modify it under the terms of the GNU Lesser General Public
   13.10 +    License as published by the Free Software Foundation; either
   13.11 +    version 2.1 of the License, or (at your option) any later version.
   13.12 +
   13.13 +    This library is distributed in the hope that it will be useful,
   13.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 +    Lesser General Public License for more details.
   13.17 +
   13.18 +    You should have received a copy of the GNU Lesser General Public
   13.19 +    License along with this library; if not, write to the Free Software
   13.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   13.21 +
   13.22 +    Sam Lantinga
   13.23 +    slouken@libsdl.org
   13.24 +*/
   13.25 +#include "SDL_config.h"
   13.26 +
   13.27 +#include "SDL_ndsvideo.h"
   13.28 +
   13.29 +extern void NDS_PumpEvents(_THIS);
   13.30 +
   13.31 +/* vi: set ts=4 sw=4 expandtab: */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/video/nds/SDL_ndsrender.c	Tue Jun 10 06:57:57 2008 +0000
    14.3 @@ -0,0 +1,285 @@
    14.4 +/*
    14.5 +    SDL - Simple DirectMedia Layer
    14.6 +    Copyright (C) 1997-2006 Sam Lantinga
    14.7 +
    14.8 +    This library is free software; you can redistribute it and/or
    14.9 +    modify it under the terms of the GNU Lesser General Public
   14.10 +    License as published by the Free Software Foundation; either
   14.11 +    version 2.1 of the License, or (at your option) any later version.
   14.12 +
   14.13 +    This library is distributed in the hope that it will be useful,
   14.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14.16 +    Lesser General Public License for more details.
   14.17 +
   14.18 +    You should have received a copy of the GNU Lesser General Public
   14.19 +    License along with this library; if not, write to the Free Software
   14.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   14.21 +
   14.22 +    Sam Lantinga
   14.23 +    slouken@libsdl.org
   14.24 +*/
   14.25 +
   14.26 +#include <stdio.h>
   14.27 +#include <stdlib.h>
   14.28 +#include <nds.h>
   14.29 +
   14.30 +#include "SDL_config.h"
   14.31 +
   14.32 +#include "SDL_video.h"
   14.33 +#include "../SDL_sysvideo.h"
   14.34 +#include "../SDL_yuv_sw_c.h"
   14.35 +#include "../SDL_renderer_sw.h"
   14.36 +
   14.37 +
   14.38 +/* SDL surface based renderer implementation */
   14.39 +
   14.40 +static SDL_Renderer *SDL_NDS_CreateRenderer(SDL_Window * window,
   14.41 +                                              Uint32 flags);
   14.42 +static int SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
   14.43 +                                Uint8 b, Uint8 a, const SDL_Rect * rect);
   14.44 +static int SDL_NDS_RenderCopy(SDL_Renderer * renderer,
   14.45 +                                SDL_Texture * texture,
   14.46 +                                const SDL_Rect * srcrect,
   14.47 +                                const SDL_Rect * dstrect);
   14.48 +static void SDL_NDS_RenderPresent(SDL_Renderer * renderer);
   14.49 +static void SDL_NDS_DestroyRenderer(SDL_Renderer * renderer);
   14.50 +
   14.51 +
   14.52 +SDL_RenderDriver SDL_NDS_RenderDriver = {
   14.53 +    SDL_NDS_CreateRenderer,
   14.54 +    { "nds",  SDL_RENDERER_PRESENTCOPY }
   14.55 +/*   (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
   14.56 +      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
   14.57 +      SDL_RENDERER_PRESENTDISCARD),*/
   14.58 +};
   14.59 +
   14.60 +typedef struct
   14.61 +{
   14.62 +    int current_screen;
   14.63 +    SDL_Surface *screens[3];
   14.64 +    int ultimate_answer;
   14.65 +} SDL_NDS_RenderData;
   14.66 +
   14.67 +SDL_Renderer *
   14.68 +SDL_NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
   14.69 +{
   14.70 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   14.71 +    SDL_DisplayMode *displayMode = &display->current_mode;
   14.72 +    SDL_Renderer *renderer;
   14.73 +    SDL_NDS_RenderData *data;
   14.74 +    int i, n;
   14.75 +    int bpp = 16;
   14.76 +    Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
   14.77 +
   14.78 +    printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
   14.79 +    printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w, window->h);
   14.80 +
   14.81 +    /* hard coded this to ARGB1555 for now
   14.82 +    if (!SDL_PixelFormatEnumToMasks
   14.83 +        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   14.84 +        SDL_SetError("Unknown display format");
   14.85 +        return NULL;
   14.86 +    }*/
   14.87 +
   14.88 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   14.89 +    if (!renderer) {
   14.90 +        SDL_OutOfMemory();
   14.91 +        return NULL;
   14.92 +    }
   14.93 +
   14.94 +    data = (SDL_NDS_RenderData *) SDL_malloc(sizeof(*data));
   14.95 +    if (!data) {
   14.96 +        SDL_NDS_DestroyRenderer(renderer);
   14.97 +        SDL_OutOfMemory();
   14.98 +        return NULL;
   14.99 +    }
  14.100 +    SDL_zerop(data);
  14.101 +
  14.102 +    renderer->RenderFill = SDL_NDS_RenderFill;
  14.103 +    renderer->RenderCopy = SDL_NDS_RenderCopy;
  14.104 +    renderer->RenderPresent = SDL_NDS_RenderPresent;
  14.105 +    renderer->DestroyRenderer = SDL_NDS_DestroyRenderer;
  14.106 +    renderer->info.name = SDL_NDS_RenderDriver.info.name;
  14.107 +    renderer->info.flags = 0;
  14.108 +    renderer->window = window->id;
  14.109 +    renderer->driverdata = data;
  14.110 +    Setup_SoftwareRenderer(renderer);
  14.111 +
  14.112 +    if (flags & SDL_RENDERER_PRESENTFLIP2) {
  14.113 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
  14.114 +        n = 2;
  14.115 +    } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
  14.116 +        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
  14.117 +        n = 3;
  14.118 +    } else {
  14.119 +        renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
  14.120 +        n = 1;
  14.121 +    }
  14.122 +    for (i = 0; i < n; ++i) {
  14.123 +        data->screens[i] =
  14.124 +            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask);
  14.125 +        if (!data->screens[i]) {
  14.126 +            SDL_NDS_DestroyRenderer(renderer);
  14.127 +            return NULL;
  14.128 +        }
  14.129 +        SDL_SetSurfacePalette(data->screens[i], display->palette);
  14.130 +    }
  14.131 +
  14.132 +    data->current_screen = 0;
  14.133 +    data->ultimate_answer = 42;
  14.134 +#if 0
  14.135 +#define blarg (data->screens[0])
  14.136 +    printf("hello?\n");
  14.137 +    if(!data || !(data->screens) || !blarg) {
  14.138 +        printf("they're null.\n");
  14.139 +    } else {
  14.140 +        printf("not null.\n");
  14.141 +        printf("%d\n%d\n%d\n%d\n%x\n%x\n%x\n%x\n",
  14.142 +        blarg->w, blarg->h, blarg->pitch,
  14.143 +        blarg->format->BitsPerPixel,
  14.144 +        blarg->format->Rmask,
  14.145 +        blarg->format->Gmask,
  14.146 +        blarg->format->Bmask,
  14.147 +        (u32)(blarg->pixels)); /* ARGH WHY DOESN'T THIS PRINT AT ALL? */
  14.148 +        printf("hurr\n");
  14.149 +    }
  14.150 +#undef blarg
  14.151 +#endif
  14.152 +    return renderer;
  14.153 +}
  14.154 +
  14.155 +static int
  14.156 +SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
  14.157 +                     Uint8 a, const SDL_Rect * rect)
  14.158 +{
  14.159 +    SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
  14.160 +    SDL_Surface *target = data->screens[data->current_screen];
  14.161 +    Uint32 color;
  14.162 +    SDL_Rect real_rect = *rect;
  14.163 +
  14.164 +    color = SDL_MapRGBA(target->format, r, g, b, a);
  14.165 +
  14.166 +    return SDL_FillRect(target, &real_rect, color);
  14.167 +}
  14.168 +
  14.169 +/* this is mainly for testing stuff to put a surface where I can see it */
  14.170 +void sdlds_surf2vram(SDL_Surface *s) {
  14.171 +    int i;
  14.172 +    for(i = 0; i < 256*192; ++i) {
  14.173 +        ((u16*)VRAM_A)[i] = ((u16*)(s->pixels))[i];
  14.174 +    }
  14.175 +}
  14.176 +
  14.177 +static int
  14.178 +SDL_NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  14.179 +                     const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  14.180 +{
  14.181 +    SDL_NDS_RenderData *data =
  14.182 +        (SDL_NDS_RenderData *) renderer->driverdata;
  14.183 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
  14.184 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
  14.185 +    printf("SDL_NDS_RenderCopy(renderer, texture, srcrect, dstrect)\n");
  14.186 +    printf(" renderer: %s\n", renderer->info.name);
  14.187 +    printf(" texture: %dx%d\n", texture->w, texture->h);
  14.188 +    printf(" srcrect: (%d,%d), %dx%d\n", srcrect->x, srcrect->y, srcrect->w, srcrect->h);
  14.189 +    printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w, dstrect->h);
  14.190 +
  14.191 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  14.192 +        SDL_Surface *target = data->screens[data->current_screen];
  14.193 +        void *pixels =
  14.194 +            (Uint8 *) target->pixels + dstrect->y * target->pitch +
  14.195 +            dstrect->x * target->format->BytesPerPixel;
  14.196 +        return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
  14.197 +                                   srcrect, display->current_mode.format,
  14.198 +                                   dstrect->w, dstrect->h, pixels,
  14.199 +                                   target->pitch);
  14.200 +    } else {
  14.201 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  14.202 +        SDL_Surface *target = data->screens[data->current_screen];
  14.203 +        SDL_Rect real_srcrect = *srcrect;
  14.204 +        SDL_Rect real_dstrect = *dstrect;
  14.205 +        printf("Rmask %x Gmask %x Bmask %x Amask %x\n"
  14.206 +               "width %d, height %d, pitch %d\nbpp %d, pixels %x\n",
  14.207 +            surface->format->Rmask, surface->format->Gmask,
  14.208 +            surface->format->Bmask, surface->format->Amask,
  14.209 +            surface->w, surface->h, surface->pitch,
  14.210 +            surface->format->BitsPerPixel, (u32)(surface->pixels));
  14.211 +        sdlds_surf2vram(surface);
  14.212 +        return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
  14.213 +    }
  14.214 +#if 0
  14.215 +/* previous attempt to copy it directly to vram */
  14.216 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  14.217 +        int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h;
  14.218 +        int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
  14.219 +        int si,sj, di,dj;
  14.220 +        /*printf("DEBUG: still alive!\n");*/
  14.221 +        for(sj=0, dj=0; sj<sh && dj<dh; ++sj, ++dj) {
  14.222 +            for(si=0, di=0; si<sw && di<dw; ++si, ++di) {
  14.223 +                ((uint16*)VRAM_A)[(dj+dy)*256 + di+dx]
  14.224 +                 = ((Uint16*)surface->pixels)[(sj+sy)*(surface->w) + si+sx];
  14.225 +            }
  14.226 +        }
  14.227 +        /*printf("DEBUG: still alive!\n");*/
  14.228 +    }
  14.229 +    return 0;
  14.230 +#endif
  14.231 +}
  14.232 +
  14.233 +static void
  14.234 +SDL_NDS_RenderPresent(SDL_Renderer * renderer)
  14.235 +{
  14.236 +    SDL_NDS_RenderData *data =
  14.237 +        (SDL_NDS_RenderData *) renderer->driverdata;
  14.238 +
  14.239 +    printf("SDL_NDS_RenderPresent(renderer)\n");
  14.240 +    printf(" renderer: %s\n", renderer->info.name);
  14.241 +    /* Send the data to the display */
  14.242 +
  14.243 +#if 0
  14.244 +/*testing to see if rectangles drawn get copied right*/
  14.245 +    {
  14.246 +    SDL_Rect ra;
  14.247 +  	ra.x=0; ra.y=0; ra.w=256; ra.h=192;
  14.248 +	SDL_FillRect(data->screens[data->current_screen], &ra, 0x250);
  14.249 +	ra.x=32; ra.y=32; ra.w=192; ra.h=128;
  14.250 +	SDL_FillRect(data->screens[data->current_screen], &ra,
  14.251 +	    SDL_MapRGBA(data->screens[data->current_screen]->format,
  14.252 +	    255,255,255,255));
  14.253 +	}
  14.254 +/*okay so this works but why not when I do it in the main()?
  14.255 +  for some reason the screen I get from screen=SDL_SetVideoMode(...)
  14.256 +  doesn't get copied to renderer->driverdata? */
  14.257 +    for(i = 0; i < 30; ++i) swiWaitForVBlank(); /* delay for debug purpose */
  14.258 +#endif
  14.259 +    sdlds_surf2vram(data->screens[data->current_screen]);
  14.260 +
  14.261 +    /* Update the flipping chain, if any */
  14.262 +    if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
  14.263 +        data->current_screen = (data->current_screen + 1) % 2;
  14.264 +    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
  14.265 +        data->current_screen = (data->current_screen + 1) % 3;
  14.266 +    }
  14.267 +}
  14.268 +
  14.269 +static void
  14.270 +SDL_NDS_DestroyRenderer(SDL_Renderer * renderer)
  14.271 +{
  14.272 +    SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
  14.273 +    int i;
  14.274 +
  14.275 +    printf("SDL_NDS_DestroyRenderer(renderer)\n");
  14.276 +    printf(" renderer: %s\n", renderer->info.name);
  14.277 +    if (data) {
  14.278 +        for (i = 0; i < SDL_arraysize(data->screens); ++i) {
  14.279 +            if (data->screens[i]) {
  14.280 +                SDL_FreeSurface(data->screens[i]);
  14.281 +            }
  14.282 +        }
  14.283 +        SDL_free(data);
  14.284 +    }
  14.285 +    SDL_free(renderer);
  14.286 +}
  14.287 +
  14.288 +/* vi: set ts=4 sw=4 expandtab: */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/video/nds/SDL_ndsrender_c.h	Tue Jun 10 06:57:57 2008 +0000
    15.3 @@ -0,0 +1,28 @@
    15.4 +/*
    15.5 +    SDL - Simple DirectMedia Layer
    15.6 +    Copyright (C) 1997-2006 Sam Lantinga
    15.7 +
    15.8 +    This library is free software; you can redistribute it and/or
    15.9 +    modify it under the terms of the GNU Lesser General Public
   15.10 +    License as published by the Free Software Foundation; either
   15.11 +    version 2.1 of the License, or (at your option) any later version.
   15.12 +
   15.13 +    This library is distributed in the hope that it will be useful,
   15.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.16 +    Lesser General Public License for more details.
   15.17 +
   15.18 +    You should have received a copy of the GNU Lesser General Public
   15.19 +    License along with this library; if not, write to the Free Software
   15.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   15.21 +
   15.22 +    Sam Lantinga
   15.23 +    slouken@libsdl.org
   15.24 +*/
   15.25 +#include "SDL_config.h"
   15.26 +
   15.27 +/* SDL surface based renderer implementation */
   15.28 +
   15.29 +extern SDL_RenderDriver SDL_NDS_RenderDriver;
   15.30 +
   15.31 +/* vi: set ts=4 sw=4 expandtab: */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/video/nds/SDL_ndsvideo.c	Tue Jun 10 06:57:57 2008 +0000
    16.3 @@ -0,0 +1,174 @@
    16.4 +/*
    16.5 +    SDL - Simple DirectMedia Layer
    16.6 +    Copyright (C) 1997-2006 Sam Lantinga
    16.7 +
    16.8 +    This library is free software; you can redistribute it and/or
    16.9 +    modify it under the terms of the GNU Lesser General Public
   16.10 +    License as published by the Free Software Foundation; either
   16.11 +    version 2.1 of the License, or (at your option) any later version.
   16.12 +
   16.13 +    This library is distributed in the hope that it will be useful,
   16.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   16.16 +    Lesser General Public License for more details.
   16.17 +
   16.18 +    You should have received a copy of the GNU Lesser General Public
   16.19 +    License along with this library; if not, write to the Free Software
   16.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   16.21 +
   16.22 +    Sam Lantinga
   16.23 +    slouken@libsdl.org
   16.24 +*/
   16.25 +#include "SDL_config.h"
   16.26 +
   16.27 +/* Dummy SDL video driver implementation; this is just enough to make an
   16.28 + *  SDL-based application THINK it's got a working video driver, for
   16.29 + *  applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
   16.30 + *  and also for use as a collection of stubs when porting SDL to a new
   16.31 + *  platform for which you haven't yet written a valid video driver.
   16.32 + *
   16.33 + * This is also a great way to determine bottlenecks: if you think that SDL
   16.34 + *  is a performance problem for a given platform, enable this driver, and
   16.35 + *  then see if your application runs faster without video overhead.
   16.36 + *
   16.37 + * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
   16.38 + *  of this was cut-and-pasted from Stephane Peter's work in the AAlib
   16.39 + *  SDL video driver.  Renamed to "DUMMY" by Sam Lantinga.
   16.40 + */
   16.41 +
   16.42 +#include <stdio.h>
   16.43 +#include <stdlib.h>
   16.44 +#include <nds.h>
   16.45 +
   16.46 +#include "SDL_video.h"
   16.47 +#include "SDL_mouse.h"
   16.48 +#include "../SDL_sysvideo.h"
   16.49 +#include "../SDL_pixels_c.h"
   16.50 +#include "../../events/SDL_events_c.h"
   16.51 +
   16.52 +#include "SDL_ndsvideo.h"
   16.53 +#include "SDL_ndsevents_c.h"
   16.54 +#include "SDL_ndsrender_c.h"
   16.55 +
   16.56 +#define NDSVID_DRIVER_NAME "nds"
   16.57 +
   16.58 +/* Initialization/Query functions */
   16.59 +static int NDS_VideoInit(_THIS);
   16.60 +static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
   16.61 +static void NDS_VideoQuit(_THIS);
   16.62 +
   16.63 +/* DUMMY driver bootstrap functions */
   16.64 +
   16.65 +static int
   16.66 +NDS_Available(void)
   16.67 +{
   16.68 +    const char *envr = SDL_getenv("SDL_VIDEODRIVER");
   16.69 +	printf("NDS_Available()\n");
   16.70 +    return (1);
   16.71 +}
   16.72 +
   16.73 +static void
   16.74 +NDS_DeleteDevice(SDL_VideoDevice * device)
   16.75 +{
   16.76 +    SDL_free(device);
   16.77 +}
   16.78 +
   16.79 +static SDL_VideoDevice *
   16.80 +NDS_CreateDevice(int devindex)
   16.81 +{
   16.82 +    SDL_VideoDevice *device;
   16.83 +	printf("NDS_CreateDevice(%d)\n", devindex);
   16.84 +
   16.85 +    /* Initialize all variables that we clean on shutdown */
   16.86 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   16.87 +    if (!device) {
   16.88 +        SDL_OutOfMemory();
   16.89 +        if (device) {
   16.90 +            SDL_free(device);
   16.91 +        }
   16.92 +        return (0);
   16.93 +    }
   16.94 +
   16.95 +    /* Set the function pointers */
   16.96 +    device->VideoInit = NDS_VideoInit;
   16.97 +    device->VideoQuit = NDS_VideoQuit;
   16.98 +    device->SetDisplayMode = NDS_SetDisplayMode;
   16.99 +    device->PumpEvents = NDS_PumpEvents;
  16.100 +
  16.101 +    device->num_displays = 2; /* DS = dual screens */
  16.102 +
  16.103 +    device->free = NDS_DeleteDevice;
  16.104 +
  16.105 +    return device;
  16.106 +}
  16.107 +
  16.108 +VideoBootStrap NDS_bootstrap = {
  16.109 +    NDSVID_DRIVER_NAME, "SDL NDS video driver",
  16.110 +    NDS_Available, NDS_CreateDevice
  16.111 +};
  16.112 +
  16.113 +int
  16.114 +NDS_VideoInit(_THIS)
  16.115 +{
  16.116 +    SDL_DisplayMode mode;
  16.117 +    int i;
  16.118 +
  16.119 +    /* simple 256x192x16x60 for now */
  16.120 +    mode.w = 256;  mode.h = 192;
  16.121 +    mode.format = SDL_PIXELFORMAT_ARGB1555;
  16.122 +    mode.refresh_rate = 60;
  16.123 +    mode.driverdata = NULL;
  16.124 +
  16.125 +    SDL_AddBasicVideoDisplay(&mode);
  16.126 +    SDL_AddRenderDriver(0, &SDL_NDS_RenderDriver);
  16.127 +
  16.128 +    SDL_zero(mode);
  16.129 +    SDL_AddDisplayMode(0, &mode);
  16.130 +
  16.131 +	/* hackish stuff to get things up and running for now, and for a console */
  16.132 +	powerON(POWER_ALL);
  16.133 +	videoSetMode(MODE_FB0);
  16.134 +	videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
  16.135 +	vramSetBankA(VRAM_A_LCD);
  16.136 +	vramSetBankC(VRAM_C_SUB_BG);
  16.137 +	irqInit();
  16.138 +	irqEnable(IRQ_VBLANK);
  16.139 +    /* set up console for debug text 'n stuff */
  16.140 +    SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31,31,31);
  16.141 +	consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31),
  16.142 +	                   (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
  16.143 +    for(i = 0; i < 256*192; ++i) {
  16.144 +		((u16*)VRAM_A)[i] = i;
  16.145 +	}
  16.146 +	for(i = 0; i < 60; ++i) swiWaitForVBlank();
  16.147 +    /*NDS_SetDisplayMode(_this, &mode);*/
  16.148 +    return 0;
  16.149 +}
  16.150 +
  16.151 +static int
  16.152 +NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
  16.153 +{
  16.154 +	/* right now this function is just hard-coded for 256x192 ARGB1555 */
  16.155 +#if 0
  16.156 +	videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); /* display on main core */
  16.157 +    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */
  16.158 +    vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_LCD,
  16.159 +                     VRAM_C_SUB_BG, VRAM_D_LCD);
  16.160 +
  16.161 +    /* maps well to the 256x192 screen anyway.  note: need VRAM_B for bigger */
  16.162 +    BG3_CR = BG_BMP16_256x256;
  16.163 +    /* affine transformation matrix.  nothing too fancy here */
  16.164 +	BG3_XDX = 0x100;    BG3_XDY = 0;
  16.165 +	BG3_YDX = 0;        BG3_YDY = 0x100;
  16.166 +	/* x/y position */
  16.167 +	BG3_CX = 0;         BG3_CY = 0;
  16.168 +#endif
  16.169 +    return 0;
  16.170 +}
  16.171 +
  16.172 +void
  16.173 +NDS_VideoQuit(_THIS)
  16.174 +{
  16.175 +}
  16.176 +
  16.177 +/* vi: set ts=4 sw=4 expandtab: */
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/video/nds/SDL_ndsvideo.h	Tue Jun 10 06:57:57 2008 +0000
    17.3 @@ -0,0 +1,31 @@
    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 +#include "SDL_config.h"
   17.26 +
   17.27 +#ifndef _SDL_ndsvideo_h
   17.28 +#define _SDL_ndsvideo_h
   17.29 +
   17.30 +#include "../SDL_sysvideo.h"
   17.31 +
   17.32 +#endif /* _SDL_ndsvideo_h */
   17.33 +
   17.34 +/* vi: set ts=4 sw=4 expandtab: */