Added initial support for Nintendo DS, based on the work by Troy Davis (GPF) SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 25 Jun 2007 00:50:20 +0000
branchSDL-1.2
changeset 39768582c6a5ca16
parent 3975 e85e65aec22f
child 3977 722db1bd733c
Added initial support for Nintendo DS, based on the work by Troy Davis (GPF)
Makefile.ds
README
README.NDS
docs.html
include/SDL_config_nds.h
include/SDL_stdinc.h
src/SDL.c
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/nds/SDL_ndsaudio.c
src/audio/nds/SDL_ndsaudio.h
src/audio/nds/sound9.c
src/audio/nds/soundcommon.h
src/joystick/nds/SDL_sysjoystick.c
src/timer/nds/SDL_systimer.c
src/video/SDL_blit.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/nds/SDL_ndsevents.c
src/video/nds/SDL_ndsevents_c.h
src/video/nds/SDL_ndsmouse.c
src/video/nds/SDL_ndsmouse_c.h
src/video/nds/SDL_ndsvideo.c
src/video/nds/SDL_ndsvideo.h
src/video/windib/SDL_dibvideo.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile.ds	Mon Jun 25 00:50:20 2007 +0000
     1.3 @@ -0,0 +1,63 @@
     1.4 +#LibSDL 1.2.12
     1.5 +#DS porting by Troy Davis(GPF)
     1.6 +
     1.7 +
     1.8 +ifeq ($(strip $(DEVKITPRO)),)
     1.9 +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro)
    1.10 +endif
    1.11 +ifeq ($(strip $(DEVKITARM)),)
    1.12 +DEVKITARM := $(DEVKITPRO)/devkitARM
    1.13 +endif
    1.14 +
    1.15 +
    1.16 +SRCS = $(shell echo ./src/*.c ./src/audio/*.c ./src/cdrom/*.c ./src/cpuinfo/*.c ./src/events/*.c ./src/file/*.c ./src/stdlib/*.c ./src/thread/*.c ./src/timer/*.c ./src/video/*.c ./src/joystick/*.c ./src/joystick/nds/*.c ./src/cdrom/dummy/*.c ./src/thread/generic/*.c ./src/timer/nds/*.c ./src/loadso/dummy/*.c ./src/audio/dummy/*.c ./src/audio/nds/*.c ./src/video/dummy/*.c ./src/video/nds/*.c)
    1.17 +
    1.18 +OBJS = $(SRCS:.c=.o) 
    1.19 +	
    1.20 +
    1.21 +SUBDIRS=
    1.22 +
    1.23 +CC=arm-eabi-gcc
    1.24 +CXX=arm-eabi-g++ 
    1.25 +LDSHARED=$(CXX)
    1.26 +AR=arm-eabi-ar rc
    1.27 +RANLIB=arm-eabi-ranlib 
    1.28 +
    1.29 +CFLAGS	=	-mthumb -mthumb-interwork \
    1.30 +		-march=armv5te -mtune=arm946e-s \
    1.31 +		-O2 -Wall -Wwrite-strings -Wpointer-arith \
    1.32 +		-DARM9 -D__NDS__ -I$(DEVKITPRO)/libnds/include -Iinclude
    1.33 +
    1.34 +CXXFLAGS += $(CFLAGS)
    1.35 +
    1.36 +all: $(DEVKITPRO)/libnds/lib/libSDL.a       
    1.37 +
    1.38 +
    1.39 +$(DEVKITPRO)/libnds/lib/libSDL.a:		$(OBJS)
    1.40 +	$(AR) $@ $(OBJS)
    1.41 +	-@ ($(RANLIB) $@ || true) >/dev/null 2>&1 	
    1.42 +
    1.43 +clean: 
    1.44 +	find . -name "*.o" |xargs rm -f
    1.45 +	find . -name "*.d" |xargs rm -f
    1.46 +	-rm -f *.elf
    1.47 +	-rm -f *.nds
    1.48 +	-rm -f *.gba
    1.49 +	-rm -f *.arm9
    1.50 +	-rm -f *.map
    1.51 +	-rm -f *.img
    1.52 +	-rm -Rf *.d
    1.53 +
    1.54 +
    1.55 +subdirs: $(patsubst %, _dir_%, $(SUBDIRS))
    1.56 +
    1.57 +$(patsubst %, _dir_%, $(SUBDIRS)):
    1.58 +	$(MAKE) -C $(patsubst _dir_%, %, $@)
    1.59 +
    1.60 +clean_subdirs: $(patsubst %, _clean_dir_%, $(SUBDIRS))
    1.61 +
    1.62 +$(patsubst %, _clean_dir_%, $(SUBDIRS)):
    1.63 +	$(MAKE) -C $(patsubst _clean_dir_%, %, $@) clean
    1.64 +
    1.65 +#include $(DEVKITARM)/ds_rules
    1.66 +
     2.1 --- a/README	Sun Jun 24 18:26:35 2007 +0000
     2.2 +++ b/README	Mon Jun 25 00:50:20 2007 +0000
     2.3 @@ -12,10 +12,11 @@
     2.4  level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
     2.5  and 2D framebuffer across multiple platforms.
     2.6  
     2.7 -The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
     2.8 -Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
     2.9 -The code contains support for Dreamcast, Atari, AIX, OSF/Tru64,
    2.10 -RISC OS, SymbianOS, and OS/2, but these are not officially supported.
    2.11 +The current version supports Linux, Windows CE/95/98/ME/XP/Vista, BeOS,
    2.12 +MacOS Classic, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX,
    2.13 +and QNX.  The code contains support for Dreamcast, Atari, AIX, OSF/Tru64,
    2.14 +RISC OS, SymbianOS, Nintendo DS, and OS/2, but these are not officially
    2.15 +supported.
    2.16  
    2.17  SDL is written in C, but works with C++ natively, and has bindings to
    2.18  several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/README.NDS	Mon Jun 25 00:50:20 2007 +0000
     3.3 @@ -0,0 +1,22 @@
     3.4 +The SDL port to the Nintendo DS
     3.5 +
     3.6 +This port uses the devKitPro toolchain, available from:
     3.7 +http://www.devkitpro.org
     3.8 +
     3.9 +Precompiled tools for cross-compiling on Linux are available from:
    3.10 +http://www.libsdl.org/extras/nds/devkitPro-20070503-linux.tar.gz
    3.11 +
    3.12 +todo:
    3.13 +add ds console specific features/optimizations
    3.14 +mouse/keyboard support
    3.15 +dual screen support
    3.16 +
    3.17 +build with:
    3.18 +cp include/SDL_config_nds.h include/SDL_config.h
    3.19 +make -f Makefile.ds
    3.20 +
    3.21 +included is an arm9/arm7 template to allow for sound streaming support.
    3.22 +
    3.23 +Enjoy, fix the source and share :)
    3.24 +Troy Davis(GPF)
    3.25 +http://gpf.dcemu.co.uk/
     4.1 --- a/docs.html	Sun Jun 24 18:26:35 2007 +0000
     4.2 +++ b/docs.html	Mon Jun 25 00:50:20 2007 +0000
     4.3 @@ -49,6 +49,9 @@
     4.4  <P>
     4.5  	Unofficial support for the S60/SymbianOS platform has been added.
     4.6  </P>
     4.7 +<P>
     4.8 +	Unofficial support for the Nintendo DS platform has been added.
     4.9 +</P>
    4.10  </BLOCKQUOTE>
    4.11  
    4.12  <H3> Unix Notes </H3>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/include/SDL_config_nds.h	Mon Jun 25 00:50:20 2007 +0000
     5.3 @@ -0,0 +1,115 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 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 Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 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 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +
    5.26 +#ifndef _SDL_config_nds_h
    5.27 +#define _SDL_config_nds_h
    5.28 +
    5.29 +#include "SDL_platform.h"
    5.30 +
    5.31 +/* This is a set of defines to configure the SDL features */
    5.32 +
    5.33 +/* General platform specific identifiers */
    5.34 +#include "SDL_platform.h"
    5.35 +
    5.36 +/* C datatypes */
    5.37 +#define SDL_HAS_64BIT_TYPE 1
    5.38 +
    5.39 +/* Endianness */
    5.40 +#define SDL_BYTEORDER 1234
    5.41 +
    5.42 +/* Useful headers */
    5.43 +#define HAVE_ALLOCA_H 1
    5.44 +#define HAVE_SYS_TYPES_H 1
    5.45 +#define HAVE_STDIO_H 1
    5.46 +#define STDC_HEADERS 1
    5.47 +#define HAVE_STDLIB_H 1
    5.48 +#define HAVE_STDARG_H 1
    5.49 +#define HAVE_MALLOC_H 1
    5.50 +#define HAVE_STRING_H 1
    5.51 +#define HAVE_INTTYPES_H 1
    5.52 +#define HAVE_STDINT_H 1
    5.53 +#define HAVE_CTYPE_H 1
    5.54 +#define HAVE_MATH_H 1
    5.55 +#define HAVE_ICONV_H 1
    5.56 +#define HAVE_SIGNAL_H 1
    5.57 +
    5.58 +/* C library functions */
    5.59 +#define HAVE_MALLOC 1
    5.60 +#define HAVE_CALLOC 1
    5.61 +#define HAVE_REALLOC 1
    5.62 +#define HAVE_FREE 1
    5.63 +#define HAVE_ALLOCA 1
    5.64 +#define HAVE_GETENV 1
    5.65 +#define HAVE_PUTENV 1
    5.66 +#define HAVE_UNSETENV 1
    5.67 +#define HAVE_QSORT 1
    5.68 +#define HAVE_ABS 1
    5.69 +#define HAVE_BCOPY 1
    5.70 +#define HAVE_MEMSET 1
    5.71 +#define HAVE_MEMCPY 1
    5.72 +#define HAVE_MEMMOVE 1
    5.73 +#define HAVE_STRLEN 1
    5.74 +#define HAVE_STRLCPY 1
    5.75 +#define HAVE_STRLCAT 1
    5.76 +#define HAVE_STRDUP 1
    5.77 +#define HAVE_STRCHR 1
    5.78 +#define HAVE_STRRCHR 1
    5.79 +#define HAVE_STRSTR 1
    5.80 +#define HAVE_STRTOL 1
    5.81 +#define HAVE_STRTOUL 1
    5.82 +#define HAVE_STRTOLL 1
    5.83 +#define HAVE_STRTOULL 1
    5.84 +#define HAVE_ATOI 1
    5.85 +#define HAVE_ATOF 1
    5.86 +#define HAVE_STRCMP 1
    5.87 +#define HAVE_STRNCMP 1
    5.88 +#define HAVE_STRCASECMP 1
    5.89 +#define HAVE_STRNCASECMP 1
    5.90 +#define HAVE_SSCANF 1
    5.91 +#define HAVE_SNPRINTF 1
    5.92 +#define HAVE_VSNPRINTF 1
    5.93 +#define HAVE_SETJMP 1
    5.94 +
    5.95 +/* Enable various audio drivers */
    5.96 +#define SDL_AUDIO_DRIVER_NDS	1
    5.97 +#define SDL_AUDIO_DRIVER_DUMMY	1
    5.98 +
    5.99 +/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
   5.100 +#define SDL_CDROM_DISABLED	1
   5.101 +
   5.102 +/* Enable various input drivers */
   5.103 +#define SDL_JOYSTICK_NDS	1
   5.104 +
   5.105 +/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
   5.106 +#define SDL_LOADSO_DISABLED	1
   5.107 +
   5.108 +/* Enable the stub thread support (src/thread/generic/\*.c) */
   5.109 +#define SDL_THREADS_DISABLED	1
   5.110 +
   5.111 +/* Enable various timer systems */
   5.112 +#define SDL_TIMER_NDS	1
   5.113 +
   5.114 +/* Enable various video drivers */
   5.115 +#define SDL_VIDEO_DRIVER_NDS	1
   5.116 +#define SDL_VIDEO_DRIVER_DUMMY	1
   5.117 +
   5.118 +#endif /* _SDL_config_nds_h */
     6.1 --- a/include/SDL_stdinc.h	Sun Jun 24 18:26:35 2007 +0000
     6.2 +++ b/include/SDL_stdinc.h	Mon Jun 25 00:50:20 2007 +0000
     6.3 @@ -129,7 +129,9 @@
     6.4  	DUMMY_ENUM_VALUE
     6.5  } SDL_DUMMY_ENUM;
     6.6  
     6.7 +#ifndef __NDS__
     6.8  SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
     6.9 +#endif
    6.10  
    6.11  
    6.12  #include "begin_code.h"
     7.1 --- a/src/SDL.c	Sun Jun 24 18:26:35 2007 +0000
     7.2 +++ b/src/SDL.c	Mon Jun 25 00:50:20 2007 +0000
     7.3 @@ -54,7 +54,9 @@
     7.4  
     7.5  /* The initialized subsystems */
     7.6  static Uint32 SDL_initialized = 0;
     7.7 +#if !SDL_TIMERS_DISABLED
     7.8  static Uint32 ticks_started = 0;
     7.9 +#endif
    7.10  
    7.11  #ifdef CHECK_LEAKS
    7.12  int surfaces_allocated = 0;
     8.1 --- a/src/audio/SDL_audio.c	Sun Jun 24 18:26:35 2007 +0000
     8.2 +++ b/src/audio/SDL_audio.c	Mon Jun 25 00:50:20 2007 +0000
     8.3 @@ -101,6 +101,9 @@
     8.4  #if SDL_AUDIO_DRIVER_DC
     8.5  	&DCAUD_bootstrap,
     8.6  #endif
     8.7 +#if SDL_AUDIO_DRIVER_NDS
     8.8 +	&NDSAUD_bootstrap,
     8.9 +#endif
    8.10  #if SDL_AUDIO_DRIVER_MMEAUDIO
    8.11  	&MMEAUDIO_bootstrap,
    8.12  #endif
    8.13 @@ -470,10 +473,7 @@
    8.14  		return(-1);
    8.15  	}
    8.16  
    8.17 -#if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED)
    8.18 -	/* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */
    8.19 -#else
    8.20 -#if defined(__MINT__) && SDL_THREADS_DISABLED
    8.21 +#if SDL_THREADS_DISABLED
    8.22  	/* Uses interrupt driven audio, without thread */
    8.23  #else
    8.24  	/* Create a semaphore for locking the sound buffers */
    8.25 @@ -483,8 +483,7 @@
    8.26  		SDL_CloseAudio();
    8.27  		return(-1);
    8.28  	}
    8.29 -#endif /* __MINT__ */
    8.30 -#endif /* __MACOS__ */
    8.31 +#endif /* SDL_THREADS_DISABLED */
    8.32  
    8.33  	/* Calculate the silence and size of the audio specification */
    8.34  	SDL_CalculateAudioSpec(desired);
     9.1 --- a/src/audio/SDL_sysaudio.h	Sun Jun 24 18:26:35 2007 +0000
     9.2 +++ b/src/audio/SDL_sysaudio.h	Mon Jun 25 00:50:20 2007 +0000
     9.3 @@ -165,6 +165,9 @@
     9.4  #if SDL_AUDIO_DRIVER_DC
     9.5  extern AudioBootStrap DCAUD_bootstrap;
     9.6  #endif
     9.7 +#if SDL_AUDIO_DRIVER_NDS
     9.8 +extern AudioBootStrap NDSAUD_bootstrap;
     9.9 +#endif
    9.10  #if SDL_AUDIO_DRIVER_MMEAUDIO
    9.11  extern AudioBootStrap MMEAUDIO_bootstrap;
    9.12  #endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/audio/nds/SDL_ndsaudio.c	Mon Jun 25 00:50:20 2007 +0000
    10.3 @@ -0,0 +1,335 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997-2006 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 Lesser General Public
   10.10 +    License as published by the Free Software Foundation; either
   10.11 +    version 2.1 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 +    Lesser General Public License for more details.
   10.17 +
   10.18 +    You should have received a copy of the GNU Lesser General Public
   10.19 +    License along with this library; if not, write to the Free Software
   10.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   10.21 +
   10.22 +    Sam Lantinga
   10.23 +    slouken@libsdl.org
   10.24 +*/
   10.25 +#include "SDL_config.h"
   10.26 +
   10.27 +/* Allow access to a raw mixing buffer */
   10.28 +#include <nds.h>
   10.29 +#include "SDL.h"
   10.30 +#include "SDL_endian.h"
   10.31 +#include "SDL_timer.h"
   10.32 +#include "SDL_audio.h"
   10.33 +#include "../SDL_audiomem.h"
   10.34 +#include "../SDL_audio_c.h"
   10.35 +#include "SDL_ndsaudio.h"
   10.36 +#include "soundcommon.h"
   10.37 +
   10.38 +
   10.39 +/* Audio driver functions */
   10.40 +static int NDS_OpenAudio(_THIS, SDL_AudioSpec *spec);
   10.41 +static void NDS_WaitAudio(_THIS);
   10.42 +static void NDS_PlayAudio(_THIS);
   10.43 +static Uint8 *NDS_GetAudioBuf(_THIS);
   10.44 +static void NDS_CloseAudio(_THIS);
   10.45 +
   10.46 +/* Audio driver bootstrap functions */
   10.47 +
   10.48 +u32 framecounter = 0,soundoffset = 0;
   10.49 +static SDL_AudioDevice *sdl_nds_audiodevice; 
   10.50 +
   10.51 +//void SoundMixCallback(void *stream,u32 size)
   10.52 +//{
   10.53 +//	//printf("SoundMixCallback\n");
   10.54 +//	
   10.55 +//	Uint8 *buffer;
   10.56 +//	 
   10.57 +// 	buffer = sdl_nds_audiodevice->hidden->mixbuf;
   10.58 +//	memset(buffer, sdl_nds_audiodevice->spec.silence, size);
   10.59 +//	
   10.60 +//	if (!sdl_nds_audiodevice->paused){ 
   10.61 +//		 
   10.62 +//
   10.63 +//	//if (sdl_nds_audiodevice->convert.needed) {
   10.64 +//	//	int silence;
   10.65 +//
   10.66 +//	//	if (sdl_nds_audiodevice->convert.src_format == AUDIO_U8 ) { 
   10.67 +//	//		silence = 0x80;
   10.68 +//	//	} else {
   10.69 +//	//		silence =  0; 
   10.70 +//	//	}
   10.71 +//	//	memset(sdl_nds_audiodevice->convert.buf, silence, sdl_nds_audiodevice->convert.len);
   10.72 +//	//	sdl_nds_audiodevice->spec.callback(sdl_nds_audiodevice->spec.userdata,
   10.73 +//	//		(Uint8 *)sdl_nds_audiodevice->convert.buf,sdl_nds_audiodevice->convert.len);
   10.74 +//	//	SDL_ConvertAudio(&sdl_nds_audiodevice->convert);
   10.75 +//	//	memcpy(buffer, sdl_nds_audiodevice->convert.buf, sdl_nds_audiodevice->convert.len_cvt);
   10.76 +//	//} else 
   10.77 +//	{
   10.78 +//		sdl_nds_audiodevice->spec.callback(sdl_nds_audiodevice->spec.userdata, buffer, size);
   10.79 +//		//memcpy((Sint16 *)stream,buffer, size);
   10.80 +//	}
   10.81 +//
   10.82 +//	}
   10.83 +//
   10.84 +//	if(soundsystem->format == 8)
   10.85 +//	{
   10.86 +//		int i;
   10.87 +//		s32 *buffer32 = (s32 *)buffer; 
   10.88 +//		s32 *stream32 = (s32 *)stream;
   10.89 +//		for(i=0;i<size/4;i++){ *stream32++ = buffer32[i] ^ 0x80808080;}
   10.90 +//		//for(i = 0; i < size; i++)
   10.91 +//		//	((s8*)stream)[i]=(buffer[i]^0x80);
   10.92 +//	}
   10.93 +//	else
   10.94 +//	{
   10.95 +//		int i;
   10.96 +//		for(i = 0; i < size; i++){
   10.97 +//			//((short*)stream)[i] =(short)buffer[i] << 8;				// sound 8bit ---> buffer 16bit
   10.98 +//			//if (buffer[i] &0x80)
   10.99 +//				//((Sint16*)stream)[i] = 0xff00 | buffer[i];
  10.100 +//			((Sint16*)stream)[i] = (buffer[i] - 128) << 8;
  10.101 +//
  10.102 +//			//else
  10.103 +//			//	((Sint16*)stream)[i] = buffer[i];
  10.104 +//		}
  10.105 +//		//register signed char *pSrc =buffer;
  10.106 +//		//register short *pDest =stream;
  10.107 +//		//int x;
  10.108 +//		//			for (x=size; x>0; x--)
  10.109 +//		//			{
  10.110 +//		//				register short temp = (((short)*pSrc)-128)<<8;
  10.111 +//		//				pSrc++;
  10.112 +//		//				*pDest++ = temp;
  10.113 +//		//			}
  10.114 +//
  10.115 +//		//memcpy((Sint16 *)stream,buffer, size);
  10.116 +//	}
  10.117 +//}
  10.118 +
  10.119 +void SoundMixCallback(void *stream,u32 len)
  10.120 +{
  10.121 +	SDL_AudioDevice *audio = (SDL_AudioDevice *)sdl_nds_audiodevice;
  10.122 +
  10.123 +	/* Silence the buffer, since it's ours */
  10.124 +	SDL_memset(stream, audio->spec.silence, len);
  10.125 +
  10.126 +	/* Only do soemthing if audio is enabled */
  10.127 +	if ( ! audio->enabled )
  10.128 +		return;
  10.129 +
  10.130 +	if ( ! audio->paused ) {
  10.131 +		if ( audio->convert.needed ) {
  10.132 +			//fprintf(stderr,"converting audio\n");
  10.133 +			SDL_mutexP(audio->mixer_lock);
  10.134 +			(*audio->spec.callback)(audio->spec.userdata,
  10.135 +				(Uint8 *)audio->convert.buf,audio->convert.len);
  10.136 +			SDL_mutexV(audio->mixer_lock);
  10.137 +			SDL_ConvertAudio(&audio->convert);
  10.138 +			SDL_memcpy(stream,audio->convert.buf,audio->convert.len_cvt);
  10.139 +		} else {
  10.140 +			SDL_mutexP(audio->mixer_lock);
  10.141 +			(*audio->spec.callback)(audio->spec.userdata,
  10.142 +						(Uint8 *)stream, len);
  10.143 +			SDL_mutexV(audio->mixer_lock);
  10.144 +		}
  10.145 +	}
  10.146 +	return;
  10.147 +}
  10.148 +void MixSound(void)
  10.149 +{
  10.150 +	int remain;
  10.151 +
  10.152 +	if(soundsystem->format == 8)
  10.153 +	{
  10.154 +		if((soundsystem->soundcursor + soundsystem->numsamples) > soundsystem->buffersize)
  10.155 +		{
  10.156 +			SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor],soundsystem->buffersize - soundsystem->soundcursor);
  10.157 +			remain = soundsystem->numsamples - (soundsystem->buffersize - soundsystem->soundcursor);
  10.158 +			SoundMixCallback(soundsystem->mixbuffer,remain);
  10.159 +		}
  10.160 +		else
  10.161 +		{
  10.162 +			SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor],soundsystem->numsamples);
  10.163 +		}
  10.164 +	}
  10.165 +	else
  10.166 +	{
  10.167 +		if((soundsystem->soundcursor + soundsystem->numsamples) > (soundsystem->buffersize >> 1))
  10.168 +		{
  10.169 +			SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor << 1],(soundsystem->buffersize >> 1) - soundsystem->soundcursor);
  10.170 +			remain = soundsystem->numsamples - ((soundsystem->buffersize >> 1) - soundsystem->soundcursor);
  10.171 +			SoundMixCallback(soundsystem->mixbuffer,remain);
  10.172 +		}
  10.173 +		else
  10.174 +		{
  10.175 +			SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor << 1],soundsystem->numsamples);
  10.176 +		}
  10.177 +	}
  10.178 +}
  10.179 +
  10.180 +void InterruptHandler(void)
  10.181 +{
  10.182 +	framecounter++;
  10.183 +}
  10.184 +void FiFoHandler(void)
  10.185 +{
  10.186 +	u32 command;
  10.187 +	while ( !(REG_IPC_FIFO_CR & (IPC_FIFO_RECV_EMPTY)) ) 
  10.188 +	{
  10.189 +		command = REG_IPC_FIFO_RX;
  10.190 +
  10.191 +		switch(command)
  10.192 +		{
  10.193 +		case FIFO_NONE:
  10.194 +			break;
  10.195 +		case UPDATEON_ARM9:
  10.196 +			REG_IME = 0;
  10.197 +			MixSound();
  10.198 +			REG_IME = 1;
  10.199 +			SendCommandToArm7(MIXCOMPLETE_ONARM9);
  10.200 +			break;
  10.201 +		}
  10.202 +	}
  10.203 +}
  10.204 +
  10.205 +
  10.206 +
  10.207 +
  10.208 +
  10.209 +static int Audio_Available(void)
  10.210 +{
  10.211 +	return(1);
  10.212 +}
  10.213 +
  10.214 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
  10.215 +{
  10.216 +}
  10.217 +
  10.218 +static SDL_AudioDevice *Audio_CreateDevice(int devindex)
  10.219 +{
  10.220 +	
  10.221 +	SDL_AudioDevice *this;
  10.222 +
  10.223 +	/* Initialize all variables that we clean on shutdown */
  10.224 +	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
  10.225 +	if ( this ) {
  10.226 +		SDL_memset(this, 0, (sizeof *this));
  10.227 +		this->hidden = (struct SDL_PrivateAudioData *)
  10.228 +				SDL_malloc((sizeof *this->hidden));
  10.229 +	}
  10.230 +	if ( (this == NULL) || (this->hidden == NULL) ) {
  10.231 +		SDL_OutOfMemory();
  10.232 +		if ( this ) {
  10.233 +			SDL_free(this);
  10.234 +		}
  10.235 +		return(0);
  10.236 +	}
  10.237 +	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
  10.238 +
  10.239 +	/* Set the function pointers */
  10.240 +	this->OpenAudio = NDS_OpenAudio;
  10.241 +	this->WaitAudio = NDS_WaitAudio;
  10.242 +	this->PlayAudio = NDS_PlayAudio;
  10.243 +	this->GetAudioBuf = NDS_GetAudioBuf;
  10.244 +	this->CloseAudio = NDS_CloseAudio;
  10.245 +
  10.246 +	this->free = Audio_DeleteDevice;
  10.247 +//fprintf(stderr,"Audio_CreateDevice\n");
  10.248 +	return this;
  10.249 +}
  10.250 +
  10.251 +AudioBootStrap NDSAUD_bootstrap = {
  10.252 +	"nds", "NDS audio",
  10.253 +	Audio_Available, Audio_CreateDevice
  10.254 +};
  10.255 +
  10.256 +
  10.257 +void static NDS_WaitAudio(_THIS)
  10.258 +{
  10.259 +	//printf("NDS_WaitAudio\n");
  10.260 +}
  10.261 +
  10.262 +static void NDS_PlayAudio(_THIS)
  10.263 +{
  10.264 +	//printf("playing audio\n");
  10.265 +	if (this->paused)
  10.266 +		return;
  10.267 +	
  10.268 +}
  10.269 +
  10.270 +static Uint8 *NDS_GetAudioBuf(_THIS)
  10.271 +{
  10.272 +	return NULL;//(this->hidden->mixbuf); 
  10.273 +}
  10.274 +
  10.275 +static void NDS_CloseAudio(_THIS)
  10.276 +{
  10.277 +/*	if ( this->hidden->mixbuf != NULL ) {
  10.278 +		SDL_FreeAudioMem(this->hidden->mixbuf);
  10.279 +		this->hidden->mixbuf = NULL;
  10.280 +	}*/ 
  10.281 +}
  10.282 +
  10.283 +static int NDS_OpenAudio(_THIS, SDL_AudioSpec *spec)
  10.284 +{
  10.285 +	//printf("NDS_OpenAudio\n");
  10.286 +	int format = 0;
  10.287 +	//switch(spec->format&0xff) {
  10.288 +	//case  8: spec->format = AUDIO_S8;format=8; break;
  10.289 +	//case 16: spec->format = AUDIO_S16LSB;format=16; break;
  10.290 +	//default:
  10.291 +	//	SDL_SetError("Unsupported audio format");
  10.292 +	//	return(-1);
  10.293 +	//}
  10.294 +	switch (spec->format&~0x1000) {
  10.295 +		case AUDIO_S8:
  10.296 +			/* Signed 8-bit audio supported */
  10.297 +			format=8;
  10.298 +			break;
  10.299 +		case AUDIO_U8:
  10.300 +			spec->format ^= 0x80;format=8;
  10.301 +			break;
  10.302 +		case AUDIO_U16:
  10.303 +			/* Unsigned 16-bit audio unsupported, convert to S16 */
  10.304 +			spec->format ^=0x8000;format=16;
  10.305 +		case AUDIO_S16:
  10.306 +			/* Signed 16-bit audio supported */
  10.307 +			format=16;
  10.308 +			break;
  10.309 +	}
  10.310 +	/* Update the fragment size as size in bytes */
  10.311 +	SDL_CalculateAudioSpec(spec);
  10.312 +
  10.313 +	/* Allocate mixing buffer */
  10.314 +	//this->hidden->mixlen = spec->size;
  10.315 +	//this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
  10.316 +	//if ( this->hidden->mixbuf == NULL ) {
  10.317 +	//	SDL_SetError("Out of Memory");
  10.318 +	//	return(-1);
  10.319 +	//} 
  10.320 +
  10.321 +	SDL_NDSAudio_mutex = 0; 
  10.322 +	sdl_nds_audiodevice=this;
  10.323 +	
  10.324 +	irqInit();
  10.325 +	irqSet(IRQ_VBLANK,&InterruptHandler);
  10.326 +	irqSet(IRQ_FIFO_NOT_EMPTY,&FiFoHandler);
  10.327 +	irqEnable(IRQ_FIFO_NOT_EMPTY);
  10.328 +	
  10.329 +	REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ;
  10.330 +
  10.331 +
  10.332 +
  10.333 +	SoundSystemInit(spec->freq,spec->size,0,format);
  10.334 +	SoundStartMixer();
  10.335 +
  10.336 +	
  10.337 +	return(1);
  10.338 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/audio/nds/SDL_ndsaudio.h	Mon Jun 25 00:50:20 2007 +0000
    11.3 @@ -0,0 +1,40 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997-2006 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 Lesser General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2.1 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 +    Lesser General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Lesser General Public
   11.19 +    License along with this library; if not, write to the Free Software
   11.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@libsdl.org
   11.24 +*/
   11.25 +#include "SDL_config.h"
   11.26 +
   11.27 +#ifndef _SDL_lowaudio_h
   11.28 +#define _SDL_lowaudio_h
   11.29 +
   11.30 +#include "../SDL_sysaudio.h"
   11.31 +
   11.32 +/* Hidden "this" pointer for the audio functions */
   11.33 +#define _THIS	SDL_AudioDevice *this
   11.34 +
   11.35 +struct SDL_PrivateAudioData {
   11.36 +	/* The file descriptor for the audio device */
   11.37 +	//Uint8 *mixbuf;
   11.38 +	//Uint32 mixlen;
   11.39 +}; 
   11.40 +unsigned short SDL_NDSAudio_mutex=0; 
   11.41 + 
   11.42 +
   11.43 +#endif /* _SDL_lowaudio_h */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/audio/nds/sound9.c	Mon Jun 25 00:50:20 2007 +0000
    12.3 @@ -0,0 +1,61 @@
    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 +#include "SDL_stdinc.h"
   12.27 +
   12.28 +#include "soundcommon.h"
   12.29 +
   12.30 +void SoundSystemInit(u32 rate,u32 buffersize,u8 channel,u8 format)
   12.31 +{
   12.32 +	soundsystem->rate = rate;
   12.33 +	
   12.34 +	if(format == 8) 
   12.35 +		soundsystem->buffersize = buffersize;
   12.36 +	else if(format == 16)
   12.37 +		soundsystem->buffersize = buffersize * sizeof(short);
   12.38 +
   12.39 +	soundsystem->mixbuffer = (s8*)SDL_malloc(soundsystem->buffersize);
   12.40 +	//soundsystem->soundbuffer = soundsystem->mixbuffer;
   12.41 +	soundsystem->format = format;
   12.42 +	soundsystem->channel = channel;
   12.43 +	soundsystem->prevtimer = 0;
   12.44 +	soundsystem->soundcursor = 0;
   12.45 +	soundsystem->numsamples = 0;
   12.46 +	soundsystem->period = 0x1000000 / rate;
   12.47 +	soundsystem->cmd = INIT;
   12.48 +}
   12.49 +
   12.50 +void SoundStartMixer(void)
   12.51 +{
   12.52 +	soundsystem->cmd |= MIX;
   12.53 +}
   12.54 +
   12.55 +void SendCommandToArm7(u32 command)
   12.56 +{
   12.57 +    while (REG_IPC_FIFO_CR & IPC_FIFO_SEND_FULL);
   12.58 +    if (REG_IPC_FIFO_CR & IPC_FIFO_ERROR)
   12.59 +    {
   12.60 +        REG_IPC_FIFO_CR |= IPC_FIFO_SEND_CLEAR;
   12.61 +    } 
   12.62 +    
   12.63 +    REG_IPC_FIFO_TX = command;
   12.64 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/audio/nds/soundcommon.h	Mon Jun 25 00:50:20 2007 +0000
    13.3 @@ -0,0 +1,80 @@
    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 +#ifndef __SOUNDCOMMON_H
   13.28 +#define __SOUNDCOMMON_H
   13.29 +
   13.30 +#include <nds.h>
   13.31 +
   13.32 +#define CLOCK (1 << 25)
   13.33 +
   13.34 +#ifdef __cplusplus
   13.35 +extern "C" {
   13.36 +#endif
   13.37 +
   13.38 +typedef enum
   13.39 +{
   13.40 +	NONE = 0,
   13.41 +	INIT = 1,
   13.42 +	MIX = 2,
   13.43 +	MIXING = 4,
   13.44 +	STOP = 8
   13.45 +}CommandType;
   13.46 +
   13.47 +typedef enum
   13.48 +{
   13.49 +	FIFO_NONE = 0,
   13.50 +	UPDATEON_ARM9 = 1,
   13.51 +	MIXCOMPLETE_ONARM9 = 2,
   13.52 +}FifoType; 
   13.53 +
   13.54 +typedef struct
   13.55 +{
   13.56 +	s8 *mixbuffer;//,*soundbuffer;
   13.57 +	u32 rate;
   13.58 +	u32 buffersize;
   13.59 +	u32 cmd;
   13.60 +	u8 channel,format;
   13.61 +	u32 soundcursor,numsamples;
   13.62 +	s32 prevtimer;
   13.63 +	s16 period;
   13.64 +}S_SoundSystem;
   13.65 +
   13.66 +#define soundsystem ((S_SoundSystem*)((u32)(IPC)+sizeof(TransferRegion)))
   13.67 +
   13.68 +#ifdef ARM9
   13.69 +extern void SoundSystemInit(u32 rate,u32 buffersize,u8 channel,u8 format);
   13.70 +extern void SoundStartMixer(void);
   13.71 +extern void SendCommandToArm7(u32 command);
   13.72 +#else
   13.73 +extern void SoundVBlankIrq(void);
   13.74 +extern void SoundSwapAndMix(void);
   13.75 +extern void SoundSetTimer(int period);
   13.76 +extern void SoundFifoHandler(void);
   13.77 +extern void SendCommandToArm9(u32 command);
   13.78 +#endif
   13.79 +
   13.80 +#ifdef __cplusplus
   13.81 +}
   13.82 +#endif
   13.83 +#endif
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Mon Jun 25 00:50:20 2007 +0000
    14.3 @@ -0,0 +1,150 @@
    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 +#include "SDL_config.h"
   14.26 +
   14.27 +/* This is the system specific header for the SDL joystick API */
   14.28 +#include <nds.h>
   14.29 +//#include <nds/registers_alt.h>
   14.30 +
   14.31 +#include "SDL_error.h"
   14.32 +#include "SDL_events.h"
   14.33 +#include "SDL_joystick.h"
   14.34 +#include "../SDL_sysjoystick.h"
   14.35 +#include "../SDL_joystick_c.h"
   14.36 +
   14.37 +#include "../../video/nds/SDL_ndsevents_c.h"
   14.38 +
   14.39 +/* Function to scan the system for joysticks.
   14.40 + * This function should set SDL_numjoysticks to the number of available
   14.41 + * joysticks.  Joystick 0 should be the system default joystick.
   14.42 + * It should return 0, or -1 on an unrecoverable fatal error.
   14.43 + */
   14.44 +int SDL_SYS_JoystickInit(void)
   14.45 +{
   14.46 +	SDL_numjoysticks = 1;
   14.47 +    //keysInit();
   14.48 +
   14.49 +	return(1);
   14.50 +}
   14.51 +
   14.52 +/* Function to get the device-dependent name of a joystick */
   14.53 +const char *SDL_SYS_JoystickName(int index)
   14.54 +{
   14.55 +	if(!index)
   14.56 +		return "NDS builtin joypad";
   14.57 +	SDL_SetError("No joystick available with that index");
   14.58 +	return (NULL);
   14.59 +}
   14.60 +
   14.61 +/* Function to open a joystick for use.
   14.62 +   The joystick to open is specified by the index field of the joystick.
   14.63 +   This should fill the nbuttons and naxes fields of the joystick structure.
   14.64 +   It returns 0, or -1 if there is an error.
   14.65 + */
   14.66 +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
   14.67 +{
   14.68 +	joystick->nbuttons=8;
   14.69 +	joystick->nhats=0;
   14.70 +	joystick->nballs=0;
   14.71 +	joystick->naxes=2;
   14.72 +	return 0;
   14.73 +}
   14.74 +
   14.75 +
   14.76 +/* Function to update the state of a joystick - called as a device poll.
   14.77 + * This function shouldn't update the joystick structure directly,
   14.78 + * but instead should call SDL_PrivateJoystick*() to deliver events
   14.79 + * and update joystick device state.
   14.80 + */
   14.81 +
   14.82 +int prevbutton=0;
   14.83 +int prevkey=0;
   14.84 +
   14.85 +int dc=0;int ldc=0;
   14.86 +u32 keysd,keysu=0;
   14.87 +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
   14.88 +{
   14.89 +    //dc=keysd;
   14.90 +	//if (dc)
   14.91 +	//{
   14.92 +		//fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
   14.93 +		//swiWaitForVBlank();
   14.94 +		//scanKeys();
   14.95 +		//keysd = keysDown(); 
   14.96 +		//keysu = keysUp();
   14.97 +		//ldc=keysd;
   14.98 +		 
   14.99 +	//}
  14.100 +	/*if (prevkey && prevbutton)
  14.101 +	{
  14.102 +		scanKeys();
  14.103 +	}
  14.104 +	*/
  14.105 +	
  14.106 +	//scanKeys();
  14.107 +		keysd = keysDown(); 
  14.108 +		keysu = keysUp();
  14.109 +		
  14.110 +	
  14.111 +	short ax=0,v=0,h=0;
  14.112 +	if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");}
  14.113 +	if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");}
  14.114 +	if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");}
  14.115 +	if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");}
  14.116 +
  14.117 +	if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_UP\n");}
  14.118 +	if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_DOWN\n");}
  14.119 +	if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_LEFT\n");}
  14.120 +	if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_RIGHT\n");}
  14.121 +
  14.122 +	if((keysd&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;}
  14.123 +	if((keysd&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;}
  14.124 +	if((keysd&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;}
  14.125 +	if((keysd&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;}
  14.126 +	if((keysd&KEY_SELECT))	{SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;}
  14.127 +	if((keysd&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;}
  14.128 +	if((keysd&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;}
  14.129 +	if((keysd&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;}
  14.130 +
  14.131 +	if((keysu&KEY_A))		{SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=0;}
  14.132 +	if((keysu&KEY_B))		{SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=0;}
  14.133 +	if((keysu&KEY_X))		{SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=0;}
  14.134 +	if((keysu&KEY_Y))		{SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=0;}
  14.135 +	if((keysu&KEY_SELECT))  {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=0;}
  14.136 +	if((keysu&KEY_START))	{SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=0;}
  14.137 +	if((keysu&KEY_L))		{SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=0;}
  14.138 +	if((keysu&KEY_R))		{SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=0;}
  14.139 +
  14.140 +
  14.141 +
  14.142 +}
  14.143 +
  14.144 +/* Function to close a joystick after use */
  14.145 +void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
  14.146 +{
  14.147 +}
  14.148 +
  14.149 +/* Function to perform any system-specific joystick related cleanup */
  14.150 +void SDL_SYS_JoystickQuit(void)
  14.151 +{
  14.152 +}
  14.153 +
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/timer/nds/SDL_systimer.c	Mon Jun 25 00:50:20 2007 +0000
    15.3 @@ -0,0 +1,73 @@
    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 +#include "SDL_thread.h"
   15.28 +#include "SDL_timer.h"
   15.29 +#include "SDL_error.h"
   15.30 +#include "../SDL_timer_c.h"
   15.31 +
   15.32 +#include <nds.h>
   15.33 +
   15.34 +#define timers2ms(tlow,thigh)(tlow | (thigh<<16)) >> 5
   15.35 +
   15.36 +
   15.37 +void SDL_StartTicks(void)
   15.38 +{
   15.39 +   TIMER0_DATA=0; 
   15.40 +   TIMER1_DATA=0; 
   15.41 +   TIMER0_CR=TIMER_ENABLE|TIMER_DIV_1024; 
   15.42 +   TIMER1_CR=TIMER_ENABLE|TIMER_CASCADE;
   15.43 +}
   15.44 +
   15.45 +Uint32 SDL_GetTicks(void)
   15.46 +{
   15.47 +	return timers2ms(TIMER0_DATA, TIMER1_DATA);
   15.48 +}
   15.49 +
   15.50 +void SDL_Delay(Uint32 ms)
   15.51 +{
   15.52 +   Uint32 now; 
   15.53 +   now=timers2ms(TIMER0_DATA, TIMER1_DATA); 
   15.54 +   while((Uint32)timers2ms(TIMER0_DATA, TIMER1_DATA)<now+ms); 
   15.55 +
   15.56 +}
   15.57 +
   15.58 +/* This is only called if the event thread is not running */
   15.59 +int SDL_SYS_TimerInit(void)
   15.60 +{
   15.61 +	return 0;
   15.62 +}
   15.63 +
   15.64 +void SDL_SYS_TimerQuit(void)
   15.65 +{
   15.66 +}
   15.67 +
   15.68 +int SDL_SYS_StartTimer(void)
   15.69 +{
   15.70 +	SDL_SetError("Timers not implemented on NDS");
   15.71 +	return -1;
   15.72 +}
   15.73 +
   15.74 +void SDL_SYS_StopTimer(void)
   15.75 +{
   15.76 +}
    16.1 --- a/src/video/SDL_blit.h	Sun Jun 24 18:26:35 2007 +0000
    16.2 +++ b/src/video/SDL_blit.h	Mon Jun 25 00:50:20 2007 +0000
    16.3 @@ -166,12 +166,21 @@
    16.4  } while(0)
    16.5  
    16.6  /* Assemble R-G-B values into a specified pixel format and store them */
    16.7 +#ifdef __NDS__ // FIXME
    16.8 +#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)				\
    16.9 +{									\
   16.10 +	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   16.11 +		((g>>fmt->Gloss)<<fmt->Gshift)|				\
   16.12 +		((b>>fmt->Bloss)<<fmt->Bshift) | (1<<15);				\
   16.13 +}
   16.14 +#else
   16.15  #define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)				\
   16.16  {									\
   16.17  	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   16.18  		((g>>fmt->Gloss)<<fmt->Gshift)|				\
   16.19  		((b>>fmt->Bloss)<<fmt->Bshift);				\
   16.20  }
   16.21 +#endif // __NDS__ FIXME
   16.22  #define RGB565_FROM_RGB(Pixel, r, g, b)					\
   16.23  {									\
   16.24  	Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3);			\
   16.25 @@ -321,6 +330,15 @@
   16.26  } while(0)
   16.27  
   16.28  /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
   16.29 +#ifdef __NDS__ // FIXME
   16.30 +#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)				\
   16.31 +{									\
   16.32 +	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   16.33 +		((g>>fmt->Gloss)<<fmt->Gshift)|				\
   16.34 +		((b>>fmt->Bloss)<<fmt->Bshift)|				\
   16.35 +		((a>>fmt->Aloss)<<fmt->Ashift) | (1<<15);				\
   16.36 +}
   16.37 +#else
   16.38  #define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)				\
   16.39  {									\
   16.40  	Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|				\
   16.41 @@ -328,6 +346,7 @@
   16.42  		((b>>fmt->Bloss)<<fmt->Bshift)|				\
   16.43  		((a>>fmt->Aloss)<<fmt->Ashift);				\
   16.44  }
   16.45 +#endif // __NDS__ FIXME
   16.46  #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)			\
   16.47  {									\
   16.48  	switch (bpp) {							\
    17.1 --- a/src/video/SDL_sysvideo.h	Sun Jun 24 18:26:35 2007 +0000
    17.2 +++ b/src/video/SDL_sysvideo.h	Mon Jun 25 00:50:20 2007 +0000
    17.3 @@ -392,6 +392,9 @@
    17.4  #if SDL_VIDEO_DRIVER_DC
    17.5  extern VideoBootStrap DC_bootstrap;
    17.6  #endif
    17.7 +#if SDL_VIDEO_DRIVER_NDS
    17.8 +extern VideoBootStrap NDS_bootstrap;
    17.9 +#endif
   17.10  #if SDL_VIDEO_DRIVER_RISCOS
   17.11  extern VideoBootStrap RISCOS_bootstrap;
   17.12  #endif
    18.1 --- a/src/video/SDL_video.c	Sun Jun 24 18:26:35 2007 +0000
    18.2 +++ b/src/video/SDL_video.c	Mon Jun 25 00:50:20 2007 +0000
    18.3 @@ -108,6 +108,9 @@
    18.4  #if SDL_VIDEO_DRIVER_DC
    18.5  	&DC_bootstrap,
    18.6  #endif
    18.7 +#if SDL_VIDEO_DRIVER_NDS
    18.8 +	&NDS_bootstrap,
    18.9 +#endif
   18.10  #if SDL_VIDEO_DRIVER_RISCOS
   18.11  	&RISCOS_bootstrap,
   18.12  #endif
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/video/nds/SDL_ndsevents.c	Mon Jun 25 00:50:20 2007 +0000
    19.3 @@ -0,0 +1,83 @@
    19.4 +/*
    19.5 +    SDL - Simple DirectMedia Layer
    19.6 +    Copyright (C) 1997-2006 Sam Lantinga
    19.7 +
    19.8 +    This library is free software; you can redistribute it and/or
    19.9 +    modify it under the terms of the GNU Lesser General Public
   19.10 +    License as published by the Free Software Foundation; either
   19.11 +    version 2.1 of the License, or (at your option) any later version.
   19.12 +
   19.13 +    This library is distributed in the hope that it will be useful,
   19.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19.16 +    Lesser General Public License for more details.
   19.17 +
   19.18 +    You should have received a copy of the GNU Lesser General Public
   19.19 +    License along with this library; if not, write to the Free Software
   19.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19.21 +
   19.22 +    Sam Lantinga
   19.23 +    slouken@libsdl.org
   19.24 +*/
   19.25 +#include "SDL_config.h"
   19.26 +
   19.27 +/* Being a nds driver, there's no event stream. We just define stubs for
   19.28 +   most of the API. */
   19.29 +#include <nds.h>
   19.30 +#include "SDL.h"
   19.31 +#include "../../events/SDL_sysevents.h"
   19.32 +#include "../../events/SDL_events_c.h"
   19.33 +#include "SDL_ndsvideo.h"
   19.34 +#include "SDL_ndsevents_c.h"
   19.35 +
   19.36 +static SDLKey keymap[NDS_NUMKEYS];
   19.37 +char keymem[NDS_NUMKEYS];	/* memorize states of buttons */
   19.38 +
   19.39 +void NDS_PumpEvents(_THIS)
   19.40 +{
   19.41 +	scanKeys();
   19.42 +	int i;
   19.43 +	SDL_keysym keysym;
   19.44 +	keysym.mod=KMOD_NONE;
   19.45 +	for(i=0;i<NDS_NUMKEYS;i++)
   19.46 +	{
   19.47 +		keysym.scancode=i;
   19.48 +		keysym.sym=keymap[i];
   19.49 +		if(keysHeld()&(1<<i) && !keymem[i])
   19.50 +		{
   19.51 +			keymem[i]=1;
   19.52 +			//printf("key released %d\n",i);
   19.53 +			SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   19.54 +		}
   19.55 +		if(!(keysHeld()&(1<<i)) && keymem[i])
   19.56 +		{
   19.57 +			keymem[i]=0;
   19.58 +			//printf("key pressed %d\n",i);
   19.59 +			SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   19.60 +		}
   19.61 +	}
   19.62 +	//touchPosition touch;
   19.63 +	//touch=touchReadXY();
   19.64 +	//if (touch.px!=0 || touch.py!=0)
   19.65 +	//	SDL_PrivateMouseMotion(SDL_PRESSED, 0, touch.px, touch.py);
   19.66 +}
   19.67 +
   19.68 +void NDS_InitOSKeymap(_THIS)
   19.69 +{
   19.70 +	SDL_memset(keymem,1,NDS_NUMKEYS);
   19.71 +	keymap[KEY_A]=SDLK_a;
   19.72 +	keymap[KEY_B]=SDLK_s;
   19.73 +	keymap[KEY_X]=SDLK_w;
   19.74 +	keymap[KEY_Y]=SDLK_d;
   19.75 +	keymap[KEY_L]=SDLK_q;
   19.76 +	keymap[KEY_R]=SDLK_e;
   19.77 +	keymap[KEY_UP]=SDLK_UP;
   19.78 +	keymap[KEY_DOWN]=SDLK_DOWN;
   19.79 +	keymap[KEY_LEFT]=SDLK_LEFT;
   19.80 +	keymap[KEY_RIGHT]=SDLK_RIGHT;
   19.81 +	keymap[KEY_SELECT]=SDLK_SPACE;
   19.82 +	keymap[KEY_START]=SDLK_RETURN;
   19.83 +}
   19.84 +
   19.85 +/* end of SDL_gbaevents.c ... */
   19.86 +
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/nds/SDL_ndsevents_c.h	Mon Jun 25 00:50:20 2007 +0000
    20.3 @@ -0,0 +1,51 @@
    20.4 +/*
    20.5 +    SDL - Simple DirectMedia Layer
    20.6 +    Copyright (C) 1997-2006 Sam Lantinga
    20.7 +
    20.8 +    This library is free software; you can redistribute it and/or
    20.9 +    modify it under the terms of the GNU Lesser General Public
   20.10 +    License as published by the Free Software Foundation; either
   20.11 +    version 2.1 of the License, or (at your option) any later version.
   20.12 +
   20.13 +    This library is distributed in the hope that it will be useful,
   20.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.16 +    Lesser General Public License for more details.
   20.17 +
   20.18 +    You should have received a copy of the GNU Lesser General Public
   20.19 +    License along with this library; if not, write to the Free Software
   20.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   20.21 +
   20.22 +    Sam Lantinga
   20.23 +    slouken@libsdl.org
   20.24 +*/
   20.25 +#include "SDL_config.h"
   20.26 +
   20.27 +#include "SDL_ndsvideo.h"
   20.28 +
   20.29 +/* Variables and functions exported by SDL_sysevents.c to other parts 
   20.30 +   of the native video subsystem (SDL_sysvideo.c)
   20.31 +*/
   20.32 +extern void NDS_InitOSKeymap(_THIS);
   20.33 +extern void NDS_PumpEvents(_THIS);
   20.34 +
   20.35 +#define NDS_NUMKEYS 12
   20.36 +
   20.37 +/*
   20.38 +#define NDS_JOYPADREG 0x4000130
   20.39 +#define NDS_JOYPAD (*(volatile Uint16*)NDS_JOYPADREG)
   20.40 +
   20.41 +#define NDS_NUMKEYS 10
   20.42 +#define NDS_KEYA (0)
   20.43 +#define NDS_KEYB (1)
   20.44 +#define NDS_KEYSEL (2)
   20.45 +#define NDS_KEYSTART (3)
   20.46 +#define NDS_KEYRIGHT (4)
   20.47 +#define NDS_KEYLEFT (5)
   20.48 +#define NDS_KEYUP (6)
   20.49 +#define NDS_KEYDOWN (7)
   20.50 +#define NDS_KEYR (8)
   20.51 +#define NDS_KEYL (9)
   20.52 +*/
   20.53 +/* end of SDL_NDSevents_c.h ... */
   20.54 +
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/video/nds/SDL_ndsmouse.c	Mon Jun 25 00:50:20 2007 +0000
    21.3 @@ -0,0 +1,34 @@
    21.4 +/*
    21.5 +    SDL - Simple DirectMedia Layer
    21.6 +    Copyright (C) 1997-2006 Sam Lantinga
    21.7 +
    21.8 +    This library is free software; you can redistribute it and/or
    21.9 +    modify it under the terms of the GNU Lesser General Public
   21.10 +    License as published by the Free Software Foundation; either
   21.11 +    version 2.1 of the License, or (at your option) any later version.
   21.12 +
   21.13 +    This library is distributed in the hope that it will be useful,
   21.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   21.16 +    Lesser General Public License for more details.
   21.17 +
   21.18 +    You should have received a copy of the GNU Lesser General Public
   21.19 +    License along with this library; if not, write to the Free Software
   21.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   21.21 +
   21.22 +    Sam Lantinga
   21.23 +    slouken@libsdl.org
   21.24 +*/
   21.25 +#include "SDL_config.h"
   21.26 +
   21.27 +#include "SDL_error.h"
   21.28 +#include "SDL_mouse.h"
   21.29 +#include "../../events/SDL_events_c.h"
   21.30 +
   21.31 +#include "SDL_ndsmouse_c.h"
   21.32 +
   21.33 +
   21.34 +/* The implementation dependent data for the window manager cursor */
   21.35 +struct WMcursor {
   21.36 +	int unused;
   21.37 +};
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/video/nds/SDL_ndsmouse_c.h	Mon Jun 25 00:50:20 2007 +0000
    22.3 @@ -0,0 +1,26 @@
    22.4 +/*
    22.5 +    SDL - Simple DirectMedia Layer
    22.6 +    Copyright (C) 1997-2006 Sam Lantinga
    22.7 +
    22.8 +    This library is free software; you can redistribute it and/or
    22.9 +    modify it under the terms of the GNU Lesser General Public
   22.10 +    License as published by the Free Software Foundation; either
   22.11 +    version 2.1 of the License, or (at your option) any later version.
   22.12 +
   22.13 +    This library is distributed in the hope that it will be useful,
   22.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   22.16 +    Lesser General Public License for more details.
   22.17 +
   22.18 +    You should have received a copy of the GNU Lesser General Public
   22.19 +    License along with this library; if not, write to the Free Software
   22.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   22.21 +
   22.22 +    Sam Lantinga
   22.23 +    slouken@libsdl.org
   22.24 +*/
   22.25 +#include "SDL_config.h"
   22.26 +
   22.27 +#include "SDL_ndsvideo.h"
   22.28 +
   22.29 +/* Functions to be exported */
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/video/nds/SDL_ndsvideo.c	Mon Jun 25 00:50:20 2007 +0000
    23.3 @@ -0,0 +1,500 @@
    23.4 +/*
    23.5 +    SDL - Simple DirectMedia Layer
    23.6 +    Copyright (C) 1997-2006 Sam Lantinga
    23.7 +
    23.8 +    This library is free software; you can redistribute it and/or
    23.9 +    modify it under the terms of the GNU Lesser General Public
   23.10 +    License as published by the Free Software Foundation; either
   23.11 +    version 2.1 of the License, or (at your option) any later version.
   23.12 +
   23.13 +    This library is distributed in the hope that it will be useful,
   23.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   23.16 +    Lesser General Public License for more details.
   23.17 +
   23.18 +    You should have received a copy of the GNU Lesser General Public
   23.19 +    License along with this library; if not, write to the Free Software
   23.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   23.21 +
   23.22 +    Sam Lantinga
   23.23 +    slouken@libsdl.org
   23.24 +*/
   23.25 +#include "SDL_config.h"
   23.26 +
   23.27 +#include <nds.h>
   23.28 +#include <nds/registers_alt.h>
   23.29 +#include "SDL.h"
   23.30 +#include "SDL_error.h"
   23.31 +#include "SDL_video.h"
   23.32 +#include "SDL_mouse.h"
   23.33 +#include "../SDL_sysvideo.h"
   23.34 +#include "../SDL_pixels_c.h"
   23.35 +#include "../../events/SDL_events_c.h"
   23.36 +
   23.37 +#include "SDL_ndsvideo.h"
   23.38 +#include "SDL_ndsevents_c.h"
   23.39 +#include "SDL_ndsmouse_c.h"
   23.40 +
   23.41 +#define NDSVID_DRIVER_NAME "nds"
   23.42 +
   23.43 +/* Initialization/Query functions */
   23.44 +static int NDS_VideoInit(_THIS, SDL_PixelFormat *vformat);
   23.45 +static SDL_Rect **NDS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   23.46 +static SDL_Surface *NDS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   23.47 +static int NDS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
   23.48 +static void NDS_VideoQuit(_THIS);
   23.49 +
   23.50 +/* Hardware surface functions */
   23.51 +static int NDS_AllocHWSurface(_THIS, SDL_Surface *surface);
   23.52 +static int NDS_LockHWSurface(_THIS, SDL_Surface *surface);
   23.53 +static int NDS_FlipHWSurface(_THIS, SDL_Surface *surface);
   23.54 +static void NDS_UnlockHWSurface(_THIS, SDL_Surface *surface);
   23.55 +static void NDS_FreeHWSurface(_THIS, SDL_Surface *surface);
   23.56 +
   23.57 +/* etc. */
   23.58 +static void NDS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
   23.59 +
   23.60 +/* NDS driver bootstrap functions */
   23.61 +
   23.62 +static int NDS_Available(void)
   23.63 +{
   23.64 +	return(1);
   23.65 +}
   23.66 +
   23.67 +static void NDS_DeleteDevice(SDL_VideoDevice *device)
   23.68 +{
   23.69 +	SDL_free(device->hidden);
   23.70 +	SDL_free(device);
   23.71 +}
   23.72 +
   23.73 +void on_irq_vblank() 
   23.74 +{	
   23.75 +  // Disable interrupts
   23.76 +  //REG_IME = 0;
   23.77 +  scanKeys();
   23.78 +
   23.79 +  //  VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK; 
   23.80 +  //  REG_IF |= IRQ_VBLANK; 
   23.81 +  //REG_IF = REG_IF;
   23.82 +
   23.83 +  // Enable interrupts
   23.84 +  //REG_IME = 1;
   23.85 +}
   23.86 +
   23.87 +static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
   23.88 +                        SDL_Surface *dst, SDL_Rect *dstrect)
   23.89 + {
   23.90 +	return 0;
   23.91 + }
   23.92 + 
   23.93 +static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
   23.94 +{
   23.95 + 	if (src->flags & SDL_SRCALPHA) return false;
   23.96 + 	if (src->flags & SDL_SRCCOLORKEY) return false;
   23.97 + 	if (src->flags & SDL_HWPALETTE ) return false;
   23.98 + 	if (dst->flags & SDL_SRCALPHA) return false;
   23.99 + 	if (dst->flags & SDL_SRCCOLORKEY) return false;
  23.100 + 	if (dst->flags & SDL_HWPALETTE ) return false;
  23.101 +
  23.102 + 	if (src->format->BitsPerPixel != dst->format->BitsPerPixel) return false;
  23.103 + 	if (src->format->BytesPerPixel != dst->format->BytesPerPixel) return false;
  23.104 + 		
  23.105 +        src->map->hw_blit = HWAccelBlit;
  23.106 +        return true;
  23.107 +}
  23.108 +
  23.109 +static SDL_VideoDevice *NDS_CreateDevice(int devindex)
  23.110 +{
  23.111 +	SDL_VideoDevice *device=0;
  23.112 +
  23.113 +
  23.114 +	/* Initialize all variables that we clean on shutdown */
  23.115 +	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
  23.116 +	if ( device ) {
  23.117 +		SDL_memset(device, 0, (sizeof *device));
  23.118 +		device->hidden = (struct SDL_PrivateVideoData *)
  23.119 +				SDL_malloc((sizeof *device->hidden));
  23.120 +	}
  23.121 +	if ( (device == NULL) || (device->hidden == NULL) ) {
  23.122 +		SDL_OutOfMemory();
  23.123 +		if ( device ) {
  23.124 +			SDL_free(device);
  23.125 +		}
  23.126 +		return(0);
  23.127 +	} 
  23.128 +	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
  23.129 +
  23.130 +	/* Set the function pointers */
  23.131 +	device->VideoInit = NDS_VideoInit;
  23.132 +	device->ListModes = NDS_ListModes;
  23.133 +	device->SetVideoMode = NDS_SetVideoMode;
  23.134 +	device->CreateYUVOverlay = NULL;
  23.135 +	device->SetColors = NDS_SetColors;
  23.136 +	device->UpdateRects = NDS_UpdateRects;
  23.137 +	device->VideoQuit = NDS_VideoQuit;
  23.138 +	device->AllocHWSurface = NDS_AllocHWSurface;
  23.139 +	device->CheckHWBlit = CheckHWBlit;
  23.140 +	device->FillHWRect = NULL;
  23.141 +	device->SetHWColorKey = NULL;
  23.142 +	device->SetHWAlpha = NULL;
  23.143 +	device->LockHWSurface = NDS_LockHWSurface;
  23.144 +	device->UnlockHWSurface = NDS_UnlockHWSurface;
  23.145 +	device->FlipHWSurface = NDS_FlipHWSurface;
  23.146 +	device->FreeHWSurface = NDS_FreeHWSurface;
  23.147 +	device->SetCaption = NULL;
  23.148 +	device->SetIcon = NULL;
  23.149 +	device->IconifyWindow = NULL;
  23.150 +	device->GrabInput = NULL;
  23.151 +	device->GetWMInfo = NULL;
  23.152 +	device->InitOSKeymap = NDS_InitOSKeymap;
  23.153 +	device->PumpEvents = NDS_PumpEvents;
  23.154 +	device->info.blit_hw=1;
  23.155 +
  23.156 +	device->free = NDS_DeleteDevice;
  23.157 +	return device;
  23.158 +}
  23.159 +
  23.160 +VideoBootStrap NDS_bootstrap = {
  23.161 +	NDSVID_DRIVER_NAME, "SDL NDS video driver",
  23.162 +	NDS_Available, NDS_CreateDevice
  23.163 +};
  23.164 +
  23.165 +	u16* frontBuffer;// = (u16*)(0x06000000);
  23.166 +	u16* backBuffer;// =  (u16*)(0x06000000 + 256 * 256 * 2); 
  23.167 +int NDS_VideoInit(_THIS, SDL_PixelFormat *vformat)
  23.168 +{
  23.169 +	//printf("WARNING: You are using the SDL NDS video driver!\n");
  23.170 +
  23.171 +	/* Determine the screen depth (use default 8-bit depth) */
  23.172 +	/* we change this during the SDL_SetVideoMode implementation... */
  23.173 +	vformat->BitsPerPixel = 16;	// mode 3
  23.174 +	vformat->BytesPerPixel = 2;
  23.175 +	vformat->Rmask = 0x0000f800;
  23.176 +	vformat->Gmask = 0x000007e0;
  23.177 +	vformat->Bmask = 0x0000001f; 
  23.178 +    powerON(POWER_ALL);
  23.179 +	irqInit();
  23.180 +	irqSet(IRQ_VBLANK, on_irq_vblank); 
  23.181 +	irqEnable(IRQ_VBLANK);
  23.182 +
  23.183 +    //set the mode for 2 text layers and two extended background layers
  23.184 +	//videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); 
  23.185 +	videoSetMode(MODE_6_2D| DISPLAY_BG2_ACTIVE); 
  23.186 +	
  23.187 +	//set the sub background up for text display (we could just print to one
  23.188 +	//of the main display text backgrounds just as easily
  23.189 +	videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text
  23.190 +	
  23.191 +    //set the first two banks as background memory and the third as sub background memory
  23.192 +    //D is not used..if you need a bigger background then you will need to map
  23.193 +    //more vram banks consecutivly (VRAM A-D are all 0x20000 bytes in size)
  23.194 +    //vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_BG_0x6020000,VRAM_C_SUB_BG , VRAM_D_LCD); 
  23.195 +	vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_BG,VRAM_C_MAIN_BG,VRAM_D_MAIN_BG);
  23.196 +	//vramSetBankA(VRAM_A_MAIN_BG);
  23.197 +	//vramSetBankB(VRAM_B_MAIN_BG);
  23.198 +	//vramSetBankC(VRAM_C_MAIN_BG);
  23.199 +	//vramSetBankD(VRAM_D_MAIN_BG);
  23.200 +	//vramSetBankE(VRAM_E_MAIN_BG);
  23.201 +	//vramSetBankF(VRAM_F_MAIN_BG);
  23.202 +	//vramSetBankG(VRAM_G_MAIN_BG);
  23.203 +	vramSetBankH(VRAM_H_SUB_BG);
  23.204 +	vramSetBankI(VRAM_I_LCD);
  23.205 +    
  23.206 +	////////////////set up text background for text/////////////////////
  23.207 +    SUB_BG0_CR = BG_MAP_BASE(8);
  23.208 +	
  23.209 +	BG_PALETTE_SUB[255] = RGB15(31,31,31);//by default font will be rendered with color 255
  23.210 +	///////////////set up our bitmap background///////////////////////
  23.211 +
  23.212 +	//BG3_CR = BG_BMP16_512x512;
  23.213 +	
  23.214 +	//these are rotation backgrounds so you must set the rotation attributes:
  23.215 +    //these are fixed point numbers with the low 8 bits the fractional part
  23.216 +    //this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
  23.217 +      /*  BG3_XDX = 1<<8;
  23.218 +        BG3_XDY = 0; 
  23.219 +        BG3_YDX = 0;
  23.220 +        BG3_YDY = 1<<8;
  23.221 +    //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2 
  23.222 +        BG3_CX = 0;
  23.223 +        BG3_CY = 0; 	
  23.224 +		*/
  23.225 +	//consoleInit() is a lot more flexible but this gets you up and running quick
  23.226 +	consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(8), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); 
  23.227 +	
  23.228 +
  23.229 +	frontBuffer =(u16*)(0x06000000);
  23.230 +	//backBuffer  =(u16*)(0x06000000 + 1024 * 512*2); 
  23.231 +
  23.232 +	//lcdSwap();
  23.233 +	/* We're done! */
  23.234 +	return(0); 
  23.235 +}
  23.236 +
  23.237 +SDL_Rect **NDS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  23.238 +{
  23.239 +	return (SDL_Rect **) -1;
  23.240 +}
  23.241 +
  23.242 +SDL_Surface *NDS_SetVideoMode(_THIS, SDL_Surface *current,
  23.243 +				int width, int height, int bpp, Uint32 flags)
  23.244 +{
  23.245 +	Uint32 Rmask, Gmask, Bmask, Amask; 
  23.246 +
  23.247 +	//if(width > 1024 || height > 512 || bpp > 16)
  23.248 +	//	return(NULL);
  23.249 +
  23.250 +	if(bpp >8) {
  23.251 +		bpp=16;
  23.252 + 		Rmask = 0x0000001F;
  23.253 +		Gmask = 0x000003E0;
  23.254 +		Bmask = 0x00007C00;
  23.255 +		Amask = 0x00008000;
  23.256 +
  23.257 +		videoSetMode(MODE_5_2D| DISPLAY_BG2_ACTIVE); 
  23.258 +
  23.259 +		vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_BG,VRAM_C_MAIN_BG,VRAM_D_MAIN_BG);
  23.260 +
  23.261 +		BG2_CR = BG_BMP16_512x512;
  23.262 +	    BG2_XDX = ((width / 256) << 8) | (width % 256) ; 
  23.263 +        BG2_XDY = 0; 
  23.264 +        BG2_YDX = 0;	
  23.265 +        BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ;
  23.266 +        BG2_CX = 0;
  23.267 +        BG2_CY = 0; 
  23.268 +//        for (i=0;i<256*192;i++)
  23.269 +//	        frontBuffer[i] = RGB15(31,0,0)|BIT(15);
  23.270 +	}
  23.271 +	else
  23.272 +	if(bpp <= 8) {
  23.273 +		bpp=8;
  23.274 +		Rmask = 0x00000000;
  23.275 +		Gmask = 0x00000000; 
  23.276 +		Bmask = 0x00000000;
  23.277 +		BG2_CR = BG_BMP8_1024x512;
  23.278 +        BG2_XDX = ((width / 256) << 8) | (width % 256) ;
  23.279 +        BG2_XDY = 0; 
  23.280 +        BG2_YDX = 0;
  23.281 +        BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ;
  23.282 +
  23.283 +	}
  23.284 +	else
  23.285 +		if(bpp < 15) bpp=15;
  23.286 +	if(width<=256) width=256;
  23.287 +	else
  23.288 +		if(width<256) width=256;
  23.289 +	if(height<=192) height=192;
  23.290 +	else
  23.291 +		if(height<192) height=192;
  23.292 +	
  23.293 +	if(bpp==8)
  23.294 +	{
  23.295 +		if(width<256) width=256;
  23.296 +		if(height<192) height=192;
  23.297 +		this->hidden->ndsmode=4;
  23.298 +	}
  23.299 +	
  23.300 +	if(bpp==15)
  23.301 +	{
  23.302 +		if(width<256) this->hidden->ndsmode=5;
  23.303 +		else this->hidden->ndsmode=3; 
  23.304 +	}
  23.305 +
  23.306 +	this->hidden->buffer= frontBuffer;//NDS_VRAM_BASE;
  23.307 +	
  23.308 +	//NDS_DISPCNT = NDS_DISP_MODE(this->hidden->ndsmode)|NDS_DISP_BG2;
  23.309 +	
  23.310 + 	//fprintf(stderr,"Setting mode %dx%d (ndsmode %d)\n", width, height,this->hidden->ndsmode);
  23.311 +
  23.312 +	// FIXME: How do I tell that 15 bits mode is 555?
  23.313 +
  23.314 +	SDL_memset(this->hidden->buffer, 0, 1024 * 512* ((this->hidden->ndsmode==4 || this->hidden->ndsmode==5) ? 2 : 1 ) * ((bpp+7) / 8));
  23.315 +
  23.316 +	/* Allocate the new pixel format for the screen */
  23.317 +	if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, Amask) ) {
  23.318 +		this->hidden->buffer = NULL;
  23.319 +		SDL_SetError("Couldn't allocate new pixel format for requested mode");
  23.320 +		return(NULL);
  23.321 +	}
  23.322 +
  23.323 +	/* Set up the new mode framebuffer */
  23.324 +	current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | (this->hidden->ndsmode > 0 ? SDL_DOUBLEBUF : 0);
  23.325 +	this->hidden->w = current->w = width;
  23.326 +	this->hidden->h = current->h = height;
  23.327 +	current->pixels = frontBuffer;
  23.328 +
  23.329 +	if (flags & SDL_DOUBLEBUF) { 
  23.330 +		this->hidden->secondbufferallocd=1;
  23.331 +		backBuffer=(u16*)SDL_malloc(1024*512*2);
  23.332 +		current->pixels = backBuffer; 
  23.333 +	}
  23.334 +	if(bpp==8)
  23.335 +		current->pitch =1024;
  23.336 +	else
  23.337 +		current->pitch =1024*2;
  23.338 +
  23.339 +	/* We're done */
  23.340 +	return(current);
  23.341 +}
  23.342 +
  23.343 +static int NDS_AllocHWSurface(_THIS, SDL_Surface *surface)
  23.344 +{
  23.345 +	if(this->hidden->secondbufferallocd) {
  23.346 +		//printf("double double buffer alloc\n");
  23.347 +		return -1;
  23.348 +	}
  23.349 +	//if(this->hidden->ndsmode==3)
  23.350 +	//{
  23.351 +	//	printf("no 2nd buffer in mode3\n");
  23.352 +	//	return -1;
  23.353 +	//}
  23.354 +	//printf("second buffer\n");
  23.355 +	//this->hidden->secondbufferallocd=1;
  23.356 +	//backBuffer=(u16*)malloc(1024*512*2);
  23.357 +	//surface->pixels = backBuffer; 
  23.358 +
  23.359 +	return(0);
  23.360 +}
  23.361 +static void NDS_FreeHWSurface(_THIS, SDL_Surface *surface)
  23.362 +{
  23.363 +	//free(backBuffer);
  23.364 +	this->hidden->secondbufferallocd=0;
  23.365 +}
  23.366 +int z=0;
  23.367 +/* We need to wait for vertical retrace on page flipped displays */
  23.368 +static int NDS_LockHWSurface(_THIS, SDL_Surface *surface)
  23.369 +{
  23.370 +/*
  23.371 +	uint8* a = surface->pixels;
  23.372 +  int i,j;
  23.373 +  a += 5 * SCREEN_WIDTH + 5;
  23.374 +  for( i = 0; i < 195; ++i) {
  23.375 +    uint16* line = a + (SCREEN_WIDTH * i);
  23.376 +    for( j = 0; j < 158; ++j) {
  23.377 +      *line++ = RGB15(155,155,25);
  23.378 +    }
  23.379 +  }
  23.380 +*/
  23.381 +	//if (z <256)
  23.382 +	// BG_PALETTE[z++]=RGB15(255-z,z,255-z);
  23.383 +
  23.384 + 
  23.385 +	return(0);
  23.386 +}
  23.387 +
  23.388 +static void NDS_UnlockHWSurface(_THIS, SDL_Surface *surface)
  23.389 +{
  23.390 +	return;
  23.391 +}
  23.392 +
  23.393 +static int NDS_FlipHWSurface(_THIS, SDL_Surface *surface)
  23.394 +{
  23.395 +	if(this->hidden->secondbufferallocd){
  23.396 +		while(DISP_Y!=192);
  23.397 +	    while(DISP_Y==192); 
  23.398 +		//printf("flip");
  23.399 +
  23.400 +		dmaCopyAsynch(backBuffer,frontBuffer,1024*512);
  23.401 +	}
  23.402 +		//printf("flip\n");
  23.403 +        //u16* temp = surface->pixels;
  23.404 +        //surface->pixels = frontBuffer;
  23.405 +        //frontBuffer = temp;
  23.406 +	/*	u8* vram=BG_GFX;
  23.407 +	int x,y;
  23.408 +	for(y = 0; y < 512; y++)
  23.409 +		dmaCopy(&frontBuffer[y*rects->w], &vram[y*512],512);
  23.410 +	//unsigned char buf;
  23.411 +	
  23.412 +	//printf("NDS_FlipHWSurface\n");
  23.413 +	//printf("ptr now: 0x%x\n",surface->pixels);
  23.414 +
  23.415 +	    while(DISP_Y!=192);
  23.416 +	    while(DISP_Y==192); 
  23.417 +        //swap
  23.418 +        u16* temp = frontBuffer;
  23.419 +        frontBuffer = backBuffer;
  23.420 +        backBuffer = temp;
  23.421 +        
  23.422 +        //flip 
  23.423 +        //base is 16KB and screen size is 256x256x2 (128KB)
  23.424 +        BG2_CR ^= BG_BMP_BASE( 512 / 16 ); */
  23.425 +/*
  23.426 +	if(surface->pixels == frontBuffer)//NDS_VRAM_BASE)
  23.427 +	{
  23.428 +			while(DISP_Y!=192);
  23.429 +	while(DISP_Y==192); 
  23.430 +        //swap
  23.431 +        u16* temp = backBuffer;
  23.432 +        backBuffer = frontBuffer;
  23.433 +        frontBuffer = temp;
  23.434 +        
  23.435 +        //flip 
  23.436 +        //base is 16KB and screen size is 256x256x2 (128KB)
  23.437 +        BG3_CR ^= BG_BMP_BASE( 128 / 16 ); 
  23.438 +	}
  23.439 +	else
  23.440 +	{
  23.441 +
  23.442 +		while(DISP_Y!=192);
  23.443 +	while(DISP_Y==192); 
  23.444 +        //swap
  23.445 +        u16* temp = frontBuffer;
  23.446 +        frontBuffer = backBuffer;
  23.447 +        backBuffer = temp;
  23.448 +        
  23.449 +        //flip 
  23.450 +        //base is 16KB and screen size is 256x256x2 (128KB)
  23.451 +        BG3_CR ^= BG_BMP_BASE( 128 / 16 ); 
  23.452 +		
  23.453 +	}
  23.454 +	*/
  23.455 +	//printf("ptr then: 0x%x\n",surface->pixels);
  23.456 +
  23.457 +	//printf("setting dispcnt to 0x%x\n",NDS_DISPCNT = NDS_DISP_MODE(this->hidden->ndsmode)|NDS_DISP_BG2| buf);
  23.458 +	return(0);
  23.459 +}
  23.460 +
  23.461 +static void NDS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
  23.462 +{
  23.463 +	//fprintf(stderr,"update\n");
  23.464 +	/* do nothing. */
  23.465 +	//dmaCopy(frontBuffer,BG_GFX,512*512);
  23.466 +	 /*
  23.467 +	u8* vram=(u8*)BG_GFX;
  23.468 +	int x,y;
  23.469 +	for(y = 0; y < 512; y++)
  23.470 +		dmaCopy(&frontBuffer[y*rects->w], &vram[y*512],512);
  23.471 +	 */
  23.472 +
  23.473 +}
  23.474 +
  23.475 +int NDS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  23.476 +{
  23.477 +	//printf("SetColors\n");
  23.478 +	short r,g,b;
  23.479 +	
  23.480 +	if(this->hidden->ndsmode != 4)
  23.481 +	{
  23.482 +		printf("This is not a palettized mode\n");
  23.483 +		return -1;
  23.484 +	}
  23.485 +
  23.486 +	int i,j=firstcolor+ncolors;
  23.487 +	for(i=firstcolor;i<j;i++)
  23.488 +	{
  23.489 +		r=colors[i].r>>3;
  23.490 +		g=colors[i].g>>3;
  23.491 +		b=colors[i].b>>3;
  23.492 +		BG_PALETTE[i]=RGB15(r, g, b);
  23.493 +	} 
  23.494 +
  23.495 +	return(0);
  23.496 +}
  23.497 +
  23.498 +/* Note:  If we are terminated, this could be called in the middle of
  23.499 +   another SDL video routine -- notably UpdateRects.
  23.500 +*/
  23.501 +void NDS_VideoQuit(_THIS)
  23.502 +{
  23.503 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/video/nds/SDL_ndsvideo.h	Mon Jun 25 00:50:20 2007 +0000
    24.3 @@ -0,0 +1,61 @@
    24.4 +/*
    24.5 +    SDL - Simple DirectMedia Layer
    24.6 +    Copyright (C) 1997-2006 Sam Lantinga
    24.7 +
    24.8 +    This library is free software; you can redistribute it and/or
    24.9 +    modify it under the terms of the GNU Lesser General Public
   24.10 +    License as published by the Free Software Foundation; either
   24.11 +    version 2.1 of the License, or (at your option) any later version.
   24.12 +
   24.13 +    This library is distributed in the hope that it will be useful,
   24.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   24.16 +    Lesser General Public License for more details.
   24.17 +
   24.18 +    You should have received a copy of the GNU Lesser General Public
   24.19 +    License along with this library; if not, write to the Free Software
   24.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   24.21 +
   24.22 +    Sam Lantinga
   24.23 +    slouken@libsdl.org
   24.24 +*/
   24.25 +#include "SDL_config.h"
   24.26 +
   24.27 +#ifndef _SDL_ndsvideo_h
   24.28 +#define _SDL_ndsvideo_h
   24.29 +
   24.30 +#include "SDL_mouse.h"
   24.31 +#include "../SDL_sysvideo.h"
   24.32 +
   24.33 +/* Hidden "this" pointer for the video functions */
   24.34 +#define _THIS	SDL_VideoDevice *this
   24.35 +
   24.36 +
   24.37 +/* Private display data */
   24.38 +
   24.39 +struct SDL_PrivateVideoData {
   24.40 +    int w, h;
   24.41 +    void *buffer;
   24.42 +    short ndsmode;
   24.43 +    short secondbufferallocd;
   24.44 +};
   24.45 +
   24.46 +/*
   24.47 +#define NDS_VIDC_BASE 0x4000000
   24.48 +#define NDS_DISPCNT (*(volatile Uint32*)(NDS_VIDC_BASE))
   24.49 +#define NDS_VIDC_SCANLINE (NDS_VIDC_BASE+6)
   24.50 +#define NDS_SCANLINE (*(volatile Uint8*)(NDS_VIDC_SCANLINE))
   24.51 +
   24.52 +#define NDS_DISP_MODE(n) (n&7)
   24.53 +#define NDS_DISP_BG2 0x400
   24.54 +#define NDS_DISP_FB 0x10
   24.55 +
   24.56 +#define NDS_PAL_BASE 0x5000000
   24.57 +#define NDS_BGPAL ((volatile Uint16*)(NDS_PAL_BASE))
   24.58 +#define NDS_OBJPAL ((volatile Uint16*)(NDS_PAL_BASE+0x200))
   24.59 +
   24.60 +#define NDS_VRAM_BASE 0x6000000
   24.61 +#define NDS_VRAM_2NDBUF 0x600a000
   24.62 +#define NDS_VRAM = ((volatile Uint16* )NDS_VRAM_BASE)
   24.63 +*/
   24.64 +#endif /* _SDL_ndsvideo_h */
    25.1 --- a/src/video/windib/SDL_dibvideo.c	Sun Jun 24 18:26:35 2007 +0000
    25.2 +++ b/src/video/windib/SDL_dibvideo.c	Mon Jun 25 00:50:20 2007 +0000
    25.3 @@ -751,6 +751,11 @@
    25.4  
    25.5  		/* Set video surface flags */
    25.6  		if ( bpp <= 8 ) {
    25.7 +			if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
    25.8 +				hdc = GetDC(SDL_Window);
    25.9 +				SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC);
   25.10 +				ReleaseDC(SDL_Window, hdc);
   25.11 +			}
   25.12  			/* BitBlt() maps colors for us */
   25.13  			video->flags |= SDL_HWPALETTE;
   25.14  		}