Mercurial > sdl-ios-xcode
changeset 3976:8582c6a5ca16 SDL-1.2
Added initial support for Nintendo DS, based on the work by Troy Davis (GPF)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 25 Jun 2007 00:50:20 +0000 |
parents | e85e65aec22f |
children | 722db1bd733c |
files | 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 |
diffstat | 25 files changed, 1744 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile.ds Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,63 @@ +#LibSDL 1.2.12 +#DS porting by Troy Davis(GPF) + + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro) +endif +ifeq ($(strip $(DEVKITARM)),) +DEVKITARM := $(DEVKITPRO)/devkitARM +endif + + +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) + +OBJS = $(SRCS:.c=.o) + + +SUBDIRS= + +CC=arm-eabi-gcc +CXX=arm-eabi-g++ +LDSHARED=$(CXX) +AR=arm-eabi-ar rc +RANLIB=arm-eabi-ranlib + +CFLAGS = -mthumb -mthumb-interwork \ + -march=armv5te -mtune=arm946e-s \ + -O2 -Wall -Wwrite-strings -Wpointer-arith \ + -DARM9 -D__NDS__ -I$(DEVKITPRO)/libnds/include -Iinclude + +CXXFLAGS += $(CFLAGS) + +all: $(DEVKITPRO)/libnds/lib/libSDL.a + + +$(DEVKITPRO)/libnds/lib/libSDL.a: $(OBJS) + $(AR) $@ $(OBJS) + -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 + +clean: + find . -name "*.o" |xargs rm -f + find . -name "*.d" |xargs rm -f + -rm -f *.elf + -rm -f *.nds + -rm -f *.gba + -rm -f *.arm9 + -rm -f *.map + -rm -f *.img + -rm -Rf *.d + + +subdirs: $(patsubst %, _dir_%, $(SUBDIRS)) + +$(patsubst %, _dir_%, $(SUBDIRS)): + $(MAKE) -C $(patsubst _dir_%, %, $@) + +clean_subdirs: $(patsubst %, _clean_dir_%, $(SUBDIRS)) + +$(patsubst %, _clean_dir_%, $(SUBDIRS)): + $(MAKE) -C $(patsubst _clean_dir_%, %, $@) clean + +#include $(DEVKITARM)/ds_rules +
--- a/README Sun Jun 24 18:26:35 2007 +0000 +++ b/README Mon Jun 25 00:50:20 2007 +0000 @@ -12,10 +12,11 @@ level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D framebuffer across multiple platforms. -The current version supports Linux, Windows, Windows CE, BeOS, MacOS, -Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. -The code contains support for Dreamcast, Atari, AIX, OSF/Tru64, -RISC OS, SymbianOS, and OS/2, but these are not officially supported. +The current version supports Linux, Windows CE/95/98/ME/XP/Vista, BeOS, +MacOS Classic, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, +and QNX. The code contains support for Dreamcast, Atari, AIX, OSF/Tru64, +RISC OS, SymbianOS, Nintendo DS, and OS/2, but these are not officially +supported. SDL is written in C, but works with C++ natively, and has bindings to several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.NDS Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,22 @@ +The SDL port to the Nintendo DS + +This port uses the devKitPro toolchain, available from: +http://www.devkitpro.org + +Precompiled tools for cross-compiling on Linux are available from: +http://www.libsdl.org/extras/nds/devkitPro-20070503-linux.tar.gz + +todo: +add ds console specific features/optimizations +mouse/keyboard support +dual screen support + +build with: +cp include/SDL_config_nds.h include/SDL_config.h +make -f Makefile.ds + +included is an arm9/arm7 template to allow for sound streaming support. + +Enjoy, fix the source and share :) +Troy Davis(GPF) +http://gpf.dcemu.co.uk/
--- a/docs.html Sun Jun 24 18:26:35 2007 +0000 +++ b/docs.html Mon Jun 25 00:50:20 2007 +0000 @@ -49,6 +49,9 @@ <P> Unofficial support for the S60/SymbianOS platform has been added. </P> +<P> + Unofficial support for the Nintendo DS platform has been added. +</P> </BLOCKQUOTE> <H3> Unix Notes </H3>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/SDL_config_nds.h Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,115 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +#ifndef _SDL_config_nds_h +#define _SDL_config_nds_h + +#include "SDL_platform.h" + +/* This is a set of defines to configure the SDL features */ + +/* General platform specific identifiers */ +#include "SDL_platform.h" + +/* C datatypes */ +#define SDL_HAS_64BIT_TYPE 1 + +/* Endianness */ +#define SDL_BYTEORDER 1234 + +/* Useful headers */ +#define HAVE_ALLOCA_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_STDIO_H 1 +#define STDC_HEADERS 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STDARG_H 1 +#define HAVE_MALLOC_H 1 +#define HAVE_STRING_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_ICONV_H 1 +#define HAVE_SIGNAL_H 1 + +/* C library functions */ +#define HAVE_MALLOC 1 +#define HAVE_CALLOC 1 +#define HAVE_REALLOC 1 +#define HAVE_FREE 1 +#define HAVE_ALLOCA 1 +#define HAVE_GETENV 1 +#define HAVE_PUTENV 1 +#define HAVE_UNSETENV 1 +#define HAVE_QSORT 1 +#define HAVE_ABS 1 +#define HAVE_BCOPY 1 +#define HAVE_MEMSET 1 +#define HAVE_MEMCPY 1 +#define HAVE_MEMMOVE 1 +#define HAVE_STRLEN 1 +#define HAVE_STRLCPY 1 +#define HAVE_STRLCAT 1 +#define HAVE_STRDUP 1 +#define HAVE_STRCHR 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRSTR 1 +#define HAVE_STRTOL 1 +#define HAVE_STRTOUL 1 +#define HAVE_STRTOLL 1 +#define HAVE_STRTOULL 1 +#define HAVE_ATOI 1 +#define HAVE_ATOF 1 +#define HAVE_STRCMP 1 +#define HAVE_STRNCMP 1 +#define HAVE_STRCASECMP 1 +#define HAVE_STRNCASECMP 1 +#define HAVE_SSCANF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 +#define HAVE_SETJMP 1 + +/* Enable various audio drivers */ +#define SDL_AUDIO_DRIVER_NDS 1 +#define SDL_AUDIO_DRIVER_DUMMY 1 + +/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */ +#define SDL_CDROM_DISABLED 1 + +/* Enable various input drivers */ +#define SDL_JOYSTICK_NDS 1 + +/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */ +#define SDL_LOADSO_DISABLED 1 + +/* Enable the stub thread support (src/thread/generic/\*.c) */ +#define SDL_THREADS_DISABLED 1 + +/* Enable various timer systems */ +#define SDL_TIMER_NDS 1 + +/* Enable various video drivers */ +#define SDL_VIDEO_DRIVER_NDS 1 +#define SDL_VIDEO_DRIVER_DUMMY 1 + +#endif /* _SDL_config_nds_h */
--- a/include/SDL_stdinc.h Sun Jun 24 18:26:35 2007 +0000 +++ b/include/SDL_stdinc.h Mon Jun 25 00:50:20 2007 +0000 @@ -129,7 +129,9 @@ DUMMY_ENUM_VALUE } SDL_DUMMY_ENUM; +#ifndef __NDS__ SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int)); +#endif #include "begin_code.h"
--- a/src/SDL.c Sun Jun 24 18:26:35 2007 +0000 +++ b/src/SDL.c Mon Jun 25 00:50:20 2007 +0000 @@ -54,7 +54,9 @@ /* The initialized subsystems */ static Uint32 SDL_initialized = 0; +#if !SDL_TIMERS_DISABLED static Uint32 ticks_started = 0; +#endif #ifdef CHECK_LEAKS int surfaces_allocated = 0;
--- a/src/audio/SDL_audio.c Sun Jun 24 18:26:35 2007 +0000 +++ b/src/audio/SDL_audio.c Mon Jun 25 00:50:20 2007 +0000 @@ -101,6 +101,9 @@ #if SDL_AUDIO_DRIVER_DC &DCAUD_bootstrap, #endif +#if SDL_AUDIO_DRIVER_NDS + &NDSAUD_bootstrap, +#endif #if SDL_AUDIO_DRIVER_MMEAUDIO &MMEAUDIO_bootstrap, #endif @@ -470,10 +473,7 @@ return(-1); } -#if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED) - /* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */ -#else -#if defined(__MINT__) && SDL_THREADS_DISABLED +#if SDL_THREADS_DISABLED /* Uses interrupt driven audio, without thread */ #else /* Create a semaphore for locking the sound buffers */ @@ -483,8 +483,7 @@ SDL_CloseAudio(); return(-1); } -#endif /* __MINT__ */ -#endif /* __MACOS__ */ +#endif /* SDL_THREADS_DISABLED */ /* Calculate the silence and size of the audio specification */ SDL_CalculateAudioSpec(desired);
--- a/src/audio/SDL_sysaudio.h Sun Jun 24 18:26:35 2007 +0000 +++ b/src/audio/SDL_sysaudio.h Mon Jun 25 00:50:20 2007 +0000 @@ -165,6 +165,9 @@ #if SDL_AUDIO_DRIVER_DC extern AudioBootStrap DCAUD_bootstrap; #endif +#if SDL_AUDIO_DRIVER_NDS +extern AudioBootStrap NDSAUD_bootstrap; +#endif #if SDL_AUDIO_DRIVER_MMEAUDIO extern AudioBootStrap MMEAUDIO_bootstrap; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audio/nds/SDL_ndsaudio.c Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,335 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Allow access to a raw mixing buffer */ +#include <nds.h> +#include "SDL.h" +#include "SDL_endian.h" +#include "SDL_timer.h" +#include "SDL_audio.h" +#include "../SDL_audiomem.h" +#include "../SDL_audio_c.h" +#include "SDL_ndsaudio.h" +#include "soundcommon.h" + + +/* Audio driver functions */ +static int NDS_OpenAudio(_THIS, SDL_AudioSpec *spec); +static void NDS_WaitAudio(_THIS); +static void NDS_PlayAudio(_THIS); +static Uint8 *NDS_GetAudioBuf(_THIS); +static void NDS_CloseAudio(_THIS); + +/* Audio driver bootstrap functions */ + +u32 framecounter = 0,soundoffset = 0; +static SDL_AudioDevice *sdl_nds_audiodevice; + +//void SoundMixCallback(void *stream,u32 size) +//{ +// //printf("SoundMixCallback\n"); +// +// Uint8 *buffer; +// +// buffer = sdl_nds_audiodevice->hidden->mixbuf; +// memset(buffer, sdl_nds_audiodevice->spec.silence, size); +// +// if (!sdl_nds_audiodevice->paused){ +// +// +// //if (sdl_nds_audiodevice->convert.needed) { +// // int silence; +// +// // if (sdl_nds_audiodevice->convert.src_format == AUDIO_U8 ) { +// // silence = 0x80; +// // } else { +// // silence = 0; +// // } +// // memset(sdl_nds_audiodevice->convert.buf, silence, sdl_nds_audiodevice->convert.len); +// // sdl_nds_audiodevice->spec.callback(sdl_nds_audiodevice->spec.userdata, +// // (Uint8 *)sdl_nds_audiodevice->convert.buf,sdl_nds_audiodevice->convert.len); +// // SDL_ConvertAudio(&sdl_nds_audiodevice->convert); +// // memcpy(buffer, sdl_nds_audiodevice->convert.buf, sdl_nds_audiodevice->convert.len_cvt); +// //} else +// { +// sdl_nds_audiodevice->spec.callback(sdl_nds_audiodevice->spec.userdata, buffer, size); +// //memcpy((Sint16 *)stream,buffer, size); +// } +// +// } +// +// if(soundsystem->format == 8) +// { +// int i; +// s32 *buffer32 = (s32 *)buffer; +// s32 *stream32 = (s32 *)stream; +// for(i=0;i<size/4;i++){ *stream32++ = buffer32[i] ^ 0x80808080;} +// //for(i = 0; i < size; i++) +// // ((s8*)stream)[i]=(buffer[i]^0x80); +// } +// else +// { +// int i; +// for(i = 0; i < size; i++){ +// //((short*)stream)[i] =(short)buffer[i] << 8; // sound 8bit ---> buffer 16bit +// //if (buffer[i] &0x80) +// //((Sint16*)stream)[i] = 0xff00 | buffer[i]; +// ((Sint16*)stream)[i] = (buffer[i] - 128) << 8; +// +// //else +// // ((Sint16*)stream)[i] = buffer[i]; +// } +// //register signed char *pSrc =buffer; +// //register short *pDest =stream; +// //int x; +// // for (x=size; x>0; x--) +// // { +// // register short temp = (((short)*pSrc)-128)<<8; +// // pSrc++; +// // *pDest++ = temp; +// // } +// +// //memcpy((Sint16 *)stream,buffer, size); +// } +//} + +void SoundMixCallback(void *stream,u32 len) +{ + SDL_AudioDevice *audio = (SDL_AudioDevice *)sdl_nds_audiodevice; + + /* Silence the buffer, since it's ours */ + SDL_memset(stream, audio->spec.silence, len); + + /* Only do soemthing if audio is enabled */ + if ( ! audio->enabled ) + return; + + if ( ! audio->paused ) { + if ( audio->convert.needed ) { + //fprintf(stderr,"converting audio\n"); + SDL_mutexP(audio->mixer_lock); + (*audio->spec.callback)(audio->spec.userdata, + (Uint8 *)audio->convert.buf,audio->convert.len); + SDL_mutexV(audio->mixer_lock); + SDL_ConvertAudio(&audio->convert); + SDL_memcpy(stream,audio->convert.buf,audio->convert.len_cvt); + } else { + SDL_mutexP(audio->mixer_lock); + (*audio->spec.callback)(audio->spec.userdata, + (Uint8 *)stream, len); + SDL_mutexV(audio->mixer_lock); + } + } + return; +} +void MixSound(void) +{ + int remain; + + if(soundsystem->format == 8) + { + if((soundsystem->soundcursor + soundsystem->numsamples) > soundsystem->buffersize) + { + SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor],soundsystem->buffersize - soundsystem->soundcursor); + remain = soundsystem->numsamples - (soundsystem->buffersize - soundsystem->soundcursor); + SoundMixCallback(soundsystem->mixbuffer,remain); + } + else + { + SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor],soundsystem->numsamples); + } + } + else + { + if((soundsystem->soundcursor + soundsystem->numsamples) > (soundsystem->buffersize >> 1)) + { + SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor << 1],(soundsystem->buffersize >> 1) - soundsystem->soundcursor); + remain = soundsystem->numsamples - ((soundsystem->buffersize >> 1) - soundsystem->soundcursor); + SoundMixCallback(soundsystem->mixbuffer,remain); + } + else + { + SoundMixCallback(&soundsystem->mixbuffer[soundsystem->soundcursor << 1],soundsystem->numsamples); + } + } +} + +void InterruptHandler(void) +{ + framecounter++; +} +void FiFoHandler(void) +{ + u32 command; + while ( !(REG_IPC_FIFO_CR & (IPC_FIFO_RECV_EMPTY)) ) + { + command = REG_IPC_FIFO_RX; + + switch(command) + { + case FIFO_NONE: + break; + case UPDATEON_ARM9: + REG_IME = 0; + MixSound(); + REG_IME = 1; + SendCommandToArm7(MIXCOMPLETE_ONARM9); + break; + } + } +} + + + + + +static int Audio_Available(void) +{ + return(1); +} + +static void Audio_DeleteDevice(SDL_AudioDevice *device) +{ +} + +static SDL_AudioDevice *Audio_CreateDevice(int devindex) +{ + + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); + if ( this ) { + SDL_memset(this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc((sizeof *this->hidden)); + } + if ( (this == NULL) || (this->hidden == NULL) ) { + SDL_OutOfMemory(); + if ( this ) { + SDL_free(this); + } + return(0); + } + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = NDS_OpenAudio; + this->WaitAudio = NDS_WaitAudio; + this->PlayAudio = NDS_PlayAudio; + this->GetAudioBuf = NDS_GetAudioBuf; + this->CloseAudio = NDS_CloseAudio; + + this->free = Audio_DeleteDevice; +//fprintf(stderr,"Audio_CreateDevice\n"); + return this; +} + +AudioBootStrap NDSAUD_bootstrap = { + "nds", "NDS audio", + Audio_Available, Audio_CreateDevice +}; + + +void static NDS_WaitAudio(_THIS) +{ + //printf("NDS_WaitAudio\n"); +} + +static void NDS_PlayAudio(_THIS) +{ + //printf("playing audio\n"); + if (this->paused) + return; + +} + +static Uint8 *NDS_GetAudioBuf(_THIS) +{ + return NULL;//(this->hidden->mixbuf); +} + +static void NDS_CloseAudio(_THIS) +{ +/* if ( this->hidden->mixbuf != NULL ) { + SDL_FreeAudioMem(this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + }*/ +} + +static int NDS_OpenAudio(_THIS, SDL_AudioSpec *spec) +{ + //printf("NDS_OpenAudio\n"); + int format = 0; + //switch(spec->format&0xff) { + //case 8: spec->format = AUDIO_S8;format=8; break; + //case 16: spec->format = AUDIO_S16LSB;format=16; break; + //default: + // SDL_SetError("Unsupported audio format"); + // return(-1); + //} + switch (spec->format&~0x1000) { + case AUDIO_S8: + /* Signed 8-bit audio supported */ + format=8; + break; + case AUDIO_U8: + spec->format ^= 0x80;format=8; + break; + case AUDIO_U16: + /* Unsigned 16-bit audio unsupported, convert to S16 */ + spec->format ^=0x8000;format=16; + case AUDIO_S16: + /* Signed 16-bit audio supported */ + format=16; + break; + } + /* Update the fragment size as size in bytes */ + SDL_CalculateAudioSpec(spec); + + /* Allocate mixing buffer */ + //this->hidden->mixlen = spec->size; + //this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); + //if ( this->hidden->mixbuf == NULL ) { + // SDL_SetError("Out of Memory"); + // return(-1); + //} + + SDL_NDSAudio_mutex = 0; + sdl_nds_audiodevice=this; + + irqInit(); + irqSet(IRQ_VBLANK,&InterruptHandler); + irqSet(IRQ_FIFO_NOT_EMPTY,&FiFoHandler); + irqEnable(IRQ_FIFO_NOT_EMPTY); + + REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ; + + + + SoundSystemInit(spec->freq,spec->size,0,format); + SoundStartMixer(); + + + return(1); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audio/nds/SDL_ndsaudio.h Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,40 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_lowaudio_h +#define _SDL_lowaudio_h + +#include "../SDL_sysaudio.h" + +/* Hidden "this" pointer for the audio functions */ +#define _THIS SDL_AudioDevice *this + +struct SDL_PrivateAudioData { + /* The file descriptor for the audio device */ + //Uint8 *mixbuf; + //Uint32 mixlen; +}; +unsigned short SDL_NDSAudio_mutex=0; + + +#endif /* _SDL_lowaudio_h */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audio/nds/sound9.c Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,61 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" +#include "SDL_stdinc.h" + +#include "soundcommon.h" + +void SoundSystemInit(u32 rate,u32 buffersize,u8 channel,u8 format) +{ + soundsystem->rate = rate; + + if(format == 8) + soundsystem->buffersize = buffersize; + else if(format == 16) + soundsystem->buffersize = buffersize * sizeof(short); + + soundsystem->mixbuffer = (s8*)SDL_malloc(soundsystem->buffersize); + //soundsystem->soundbuffer = soundsystem->mixbuffer; + soundsystem->format = format; + soundsystem->channel = channel; + soundsystem->prevtimer = 0; + soundsystem->soundcursor = 0; + soundsystem->numsamples = 0; + soundsystem->period = 0x1000000 / rate; + soundsystem->cmd = INIT; +} + +void SoundStartMixer(void) +{ + soundsystem->cmd |= MIX; +} + +void SendCommandToArm7(u32 command) +{ + while (REG_IPC_FIFO_CR & IPC_FIFO_SEND_FULL); + if (REG_IPC_FIFO_CR & IPC_FIFO_ERROR) + { + REG_IPC_FIFO_CR |= IPC_FIFO_SEND_CLEAR; + } + + REG_IPC_FIFO_TX = command; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audio/nds/soundcommon.h Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,80 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef __SOUNDCOMMON_H +#define __SOUNDCOMMON_H + +#include <nds.h> + +#define CLOCK (1 << 25) + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + NONE = 0, + INIT = 1, + MIX = 2, + MIXING = 4, + STOP = 8 +}CommandType; + +typedef enum +{ + FIFO_NONE = 0, + UPDATEON_ARM9 = 1, + MIXCOMPLETE_ONARM9 = 2, +}FifoType; + +typedef struct +{ + s8 *mixbuffer;//,*soundbuffer; + u32 rate; + u32 buffersize; + u32 cmd; + u8 channel,format; + u32 soundcursor,numsamples; + s32 prevtimer; + s16 period; +}S_SoundSystem; + +#define soundsystem ((S_SoundSystem*)((u32)(IPC)+sizeof(TransferRegion))) + +#ifdef ARM9 +extern void SoundSystemInit(u32 rate,u32 buffersize,u8 channel,u8 format); +extern void SoundStartMixer(void); +extern void SendCommandToArm7(u32 command); +#else +extern void SoundVBlankIrq(void); +extern void SoundSwapAndMix(void); +extern void SoundSetTimer(int period); +extern void SoundFifoHandler(void); +extern void SendCommandToArm9(u32 command); +#endif + +#ifdef __cplusplus +} +#endif +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/joystick/nds/SDL_sysjoystick.c Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,150 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* This is the system specific header for the SDL joystick API */ +#include <nds.h> +//#include <nds/registers_alt.h> + +#include "SDL_error.h" +#include "SDL_events.h" +#include "SDL_joystick.h" +#include "../SDL_sysjoystick.h" +#include "../SDL_joystick_c.h" + +#include "../../video/nds/SDL_ndsevents_c.h" + +/* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return 0, or -1 on an unrecoverable fatal error. + */ +int SDL_SYS_JoystickInit(void) +{ + SDL_numjoysticks = 1; + //keysInit(); + + return(1); +} + +/* Function to get the device-dependent name of a joystick */ +const char *SDL_SYS_JoystickName(int index) +{ + if(!index) + return "NDS builtin joypad"; + SDL_SetError("No joystick available with that index"); + return (NULL); +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +{ + joystick->nbuttons=8; + joystick->nhats=0; + joystick->nballs=0; + joystick->naxes=2; + return 0; +} + + +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ + +int prevbutton=0; +int prevkey=0; + +int dc=0;int ldc=0; +u32 keysd,keysu=0; +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +{ + //dc=keysd; + //if (dc) + //{ + //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); + //swiWaitForVBlank(); + //scanKeys(); + //keysd = keysDown(); + //keysu = keysUp(); + //ldc=keysd; + + //} + /*if (prevkey && prevbutton) + { + scanKeys(); + } + */ + + //scanKeys(); + keysd = keysDown(); + keysu = keysUp(); + + + short ax=0,v=0,h=0; + if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");} + if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");} + if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");} + if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");} + + if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_UP\n");} + if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=0;}//fprintf(stderr,"KEY_DOWN\n");} + if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_LEFT\n");} + if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=0;}//fprintf(stderr,"KEY_RIGHT\n");} + + if((keysd&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;} + if((keysd&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;} + if((keysd&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;} + if((keysd&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;} + if((keysd&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;} + if((keysd&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;} + if((keysd&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;} + if((keysd&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;} + + if((keysu&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=0;} + if((keysu&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=0;} + if((keysu&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=0;} + if((keysu&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=0;} + if((keysu&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=0;} + if((keysu&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=0;} + if((keysu&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=0;} + if((keysu&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=0;} + + + +} + +/* Function to close a joystick after use */ +void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +{ +} + +/* Function to perform any system-specific joystick related cleanup */ +void SDL_SYS_JoystickQuit(void) +{ +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/timer/nds/SDL_systimer.c Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,73 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_thread.h" +#include "SDL_timer.h" +#include "SDL_error.h" +#include "../SDL_timer_c.h" + +#include <nds.h> + +#define timers2ms(tlow,thigh)(tlow | (thigh<<16)) >> 5 + + +void SDL_StartTicks(void) +{ + TIMER0_DATA=0; + TIMER1_DATA=0; + TIMER0_CR=TIMER_ENABLE|TIMER_DIV_1024; + TIMER1_CR=TIMER_ENABLE|TIMER_CASCADE; +} + +Uint32 SDL_GetTicks(void) +{ + return timers2ms(TIMER0_DATA, TIMER1_DATA); +} + +void SDL_Delay(Uint32 ms) +{ + Uint32 now; + now=timers2ms(TIMER0_DATA, TIMER1_DATA); + while((Uint32)timers2ms(TIMER0_DATA, TIMER1_DATA)<now+ms); + +} + +/* This is only called if the event thread is not running */ +int SDL_SYS_TimerInit(void) +{ + return 0; +} + +void SDL_SYS_TimerQuit(void) +{ +} + +int SDL_SYS_StartTimer(void) +{ + SDL_SetError("Timers not implemented on NDS"); + return -1; +} + +void SDL_SYS_StopTimer(void) +{ +}
--- a/src/video/SDL_blit.h Sun Jun 24 18:26:35 2007 +0000 +++ b/src/video/SDL_blit.h Mon Jun 25 00:50:20 2007 +0000 @@ -166,12 +166,21 @@ } while(0) /* Assemble R-G-B values into a specified pixel format and store them */ +#ifdef __NDS__ // FIXME +#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \ +{ \ + Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ + ((g>>fmt->Gloss)<<fmt->Gshift)| \ + ((b>>fmt->Bloss)<<fmt->Bshift) | (1<<15); \ +} +#else #define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \ { \ Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ ((g>>fmt->Gloss)<<fmt->Gshift)| \ ((b>>fmt->Bloss)<<fmt->Bshift); \ } +#endif // __NDS__ FIXME #define RGB565_FROM_RGB(Pixel, r, g, b) \ { \ Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \ @@ -321,6 +330,15 @@ } while(0) /* FIXME: this isn't correct, especially for Alpha (maximum != 255) */ +#ifdef __NDS__ // FIXME +#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \ +{ \ + Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ + ((g>>fmt->Gloss)<<fmt->Gshift)| \ + ((b>>fmt->Bloss)<<fmt->Bshift)| \ + ((a>>fmt->Aloss)<<fmt->Ashift) | (1<<15); \ +} +#else #define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \ { \ Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \ @@ -328,6 +346,7 @@ ((b>>fmt->Bloss)<<fmt->Bshift)| \ ((a>>fmt->Aloss)<<fmt->Ashift); \ } +#endif // __NDS__ FIXME #define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \ { \ switch (bpp) { \
--- a/src/video/SDL_sysvideo.h Sun Jun 24 18:26:35 2007 +0000 +++ b/src/video/SDL_sysvideo.h Mon Jun 25 00:50:20 2007 +0000 @@ -392,6 +392,9 @@ #if SDL_VIDEO_DRIVER_DC extern VideoBootStrap DC_bootstrap; #endif +#if SDL_VIDEO_DRIVER_NDS +extern VideoBootStrap NDS_bootstrap; +#endif #if SDL_VIDEO_DRIVER_RISCOS extern VideoBootStrap RISCOS_bootstrap; #endif
--- a/src/video/SDL_video.c Sun Jun 24 18:26:35 2007 +0000 +++ b/src/video/SDL_video.c Mon Jun 25 00:50:20 2007 +0000 @@ -108,6 +108,9 @@ #if SDL_VIDEO_DRIVER_DC &DC_bootstrap, #endif +#if SDL_VIDEO_DRIVER_NDS + &NDS_bootstrap, +#endif #if SDL_VIDEO_DRIVER_RISCOS &RISCOS_bootstrap, #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsevents.c Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,83 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Being a nds driver, there's no event stream. We just define stubs for + most of the API. */ +#include <nds.h> +#include "SDL.h" +#include "../../events/SDL_sysevents.h" +#include "../../events/SDL_events_c.h" +#include "SDL_ndsvideo.h" +#include "SDL_ndsevents_c.h" + +static SDLKey keymap[NDS_NUMKEYS]; +char keymem[NDS_NUMKEYS]; /* memorize states of buttons */ + +void NDS_PumpEvents(_THIS) +{ + scanKeys(); + int i; + SDL_keysym keysym; + keysym.mod=KMOD_NONE; + for(i=0;i<NDS_NUMKEYS;i++) + { + keysym.scancode=i; + keysym.sym=keymap[i]; + if(keysHeld()&(1<<i) && !keymem[i]) + { + keymem[i]=1; + //printf("key released %d\n",i); + SDL_PrivateKeyboard(SDL_RELEASED, &keysym); + } + if(!(keysHeld()&(1<<i)) && keymem[i]) + { + keymem[i]=0; + //printf("key pressed %d\n",i); + SDL_PrivateKeyboard(SDL_PRESSED, &keysym); + } + } + //touchPosition touch; + //touch=touchReadXY(); + //if (touch.px!=0 || touch.py!=0) + // SDL_PrivateMouseMotion(SDL_PRESSED, 0, touch.px, touch.py); +} + +void NDS_InitOSKeymap(_THIS) +{ + SDL_memset(keymem,1,NDS_NUMKEYS); + keymap[KEY_A]=SDLK_a; + keymap[KEY_B]=SDLK_s; + keymap[KEY_X]=SDLK_w; + keymap[KEY_Y]=SDLK_d; + keymap[KEY_L]=SDLK_q; + keymap[KEY_R]=SDLK_e; + keymap[KEY_UP]=SDLK_UP; + keymap[KEY_DOWN]=SDLK_DOWN; + keymap[KEY_LEFT]=SDLK_LEFT; + keymap[KEY_RIGHT]=SDLK_RIGHT; + keymap[KEY_SELECT]=SDLK_SPACE; + keymap[KEY_START]=SDLK_RETURN; +} + +/* end of SDL_gbaevents.c ... */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsevents_c.h Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,51 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_ndsvideo.h" + +/* Variables and functions exported by SDL_sysevents.c to other parts + of the native video subsystem (SDL_sysvideo.c) +*/ +extern void NDS_InitOSKeymap(_THIS); +extern void NDS_PumpEvents(_THIS); + +#define NDS_NUMKEYS 12 + +/* +#define NDS_JOYPADREG 0x4000130 +#define NDS_JOYPAD (*(volatile Uint16*)NDS_JOYPADREG) + +#define NDS_NUMKEYS 10 +#define NDS_KEYA (0) +#define NDS_KEYB (1) +#define NDS_KEYSEL (2) +#define NDS_KEYSTART (3) +#define NDS_KEYRIGHT (4) +#define NDS_KEYLEFT (5) +#define NDS_KEYUP (6) +#define NDS_KEYDOWN (7) +#define NDS_KEYR (8) +#define NDS_KEYL (9) +*/ +/* end of SDL_NDSevents_c.h ... */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsmouse.c Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,34 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_error.h" +#include "SDL_mouse.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_ndsmouse_c.h" + + +/* The implementation dependent data for the window manager cursor */ +struct WMcursor { + int unused; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsmouse_c.h Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,26 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_ndsvideo.h" + +/* Functions to be exported */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsvideo.c Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,500 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include <nds.h> +#include <nds/registers_alt.h> +#include "SDL.h" +#include "SDL_error.h" +#include "SDL_video.h" +#include "SDL_mouse.h" +#include "../SDL_sysvideo.h" +#include "../SDL_pixels_c.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_ndsvideo.h" +#include "SDL_ndsevents_c.h" +#include "SDL_ndsmouse_c.h" + +#define NDSVID_DRIVER_NAME "nds" + +/* Initialization/Query functions */ +static int NDS_VideoInit(_THIS, SDL_PixelFormat *vformat); +static SDL_Rect **NDS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); +static SDL_Surface *NDS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); +static int NDS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); +static void NDS_VideoQuit(_THIS); + +/* Hardware surface functions */ +static int NDS_AllocHWSurface(_THIS, SDL_Surface *surface); +static int NDS_LockHWSurface(_THIS, SDL_Surface *surface); +static int NDS_FlipHWSurface(_THIS, SDL_Surface *surface); +static void NDS_UnlockHWSurface(_THIS, SDL_Surface *surface); +static void NDS_FreeHWSurface(_THIS, SDL_Surface *surface); + +/* etc. */ +static void NDS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); + +/* NDS driver bootstrap functions */ + +static int NDS_Available(void) +{ + return(1); +} + +static void NDS_DeleteDevice(SDL_VideoDevice *device) +{ + SDL_free(device->hidden); + SDL_free(device); +} + +void on_irq_vblank() +{ + // Disable interrupts + //REG_IME = 0; + scanKeys(); + + // VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK; + // REG_IF |= IRQ_VBLANK; + //REG_IF = REG_IF; + + // Enable interrupts + //REG_IME = 1; +} + +static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, + SDL_Surface *dst, SDL_Rect *dstrect) + { + return 0; + } + +static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) +{ + if (src->flags & SDL_SRCALPHA) return false; + if (src->flags & SDL_SRCCOLORKEY) return false; + if (src->flags & SDL_HWPALETTE ) return false; + if (dst->flags & SDL_SRCALPHA) return false; + if (dst->flags & SDL_SRCCOLORKEY) return false; + if (dst->flags & SDL_HWPALETTE ) return false; + + if (src->format->BitsPerPixel != dst->format->BitsPerPixel) return false; + if (src->format->BytesPerPixel != dst->format->BytesPerPixel) return false; + + src->map->hw_blit = HWAccelBlit; + return true; +} + +static SDL_VideoDevice *NDS_CreateDevice(int devindex) +{ + SDL_VideoDevice *device=0; + + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); + if ( device ) { + SDL_memset(device, 0, (sizeof *device)); + device->hidden = (struct SDL_PrivateVideoData *) + SDL_malloc((sizeof *device->hidden)); + } + if ( (device == NULL) || (device->hidden == NULL) ) { + SDL_OutOfMemory(); + if ( device ) { + SDL_free(device); + } + return(0); + } + SDL_memset(device->hidden, 0, (sizeof *device->hidden)); + + /* Set the function pointers */ + device->VideoInit = NDS_VideoInit; + device->ListModes = NDS_ListModes; + device->SetVideoMode = NDS_SetVideoMode; + device->CreateYUVOverlay = NULL; + device->SetColors = NDS_SetColors; + device->UpdateRects = NDS_UpdateRects; + device->VideoQuit = NDS_VideoQuit; + device->AllocHWSurface = NDS_AllocHWSurface; + device->CheckHWBlit = CheckHWBlit; + device->FillHWRect = NULL; + device->SetHWColorKey = NULL; + device->SetHWAlpha = NULL; + device->LockHWSurface = NDS_LockHWSurface; + device->UnlockHWSurface = NDS_UnlockHWSurface; + device->FlipHWSurface = NDS_FlipHWSurface; + device->FreeHWSurface = NDS_FreeHWSurface; + device->SetCaption = NULL; + device->SetIcon = NULL; + device->IconifyWindow = NULL; + device->GrabInput = NULL; + device->GetWMInfo = NULL; + device->InitOSKeymap = NDS_InitOSKeymap; + device->PumpEvents = NDS_PumpEvents; + device->info.blit_hw=1; + + device->free = NDS_DeleteDevice; + return device; +} + +VideoBootStrap NDS_bootstrap = { + NDSVID_DRIVER_NAME, "SDL NDS video driver", + NDS_Available, NDS_CreateDevice +}; + + u16* frontBuffer;// = (u16*)(0x06000000); + u16* backBuffer;// = (u16*)(0x06000000 + 256 * 256 * 2); +int NDS_VideoInit(_THIS, SDL_PixelFormat *vformat) +{ + //printf("WARNING: You are using the SDL NDS video driver!\n"); + + /* Determine the screen depth (use default 8-bit depth) */ + /* we change this during the SDL_SetVideoMode implementation... */ + vformat->BitsPerPixel = 16; // mode 3 + vformat->BytesPerPixel = 2; + vformat->Rmask = 0x0000f800; + vformat->Gmask = 0x000007e0; + vformat->Bmask = 0x0000001f; + powerON(POWER_ALL); + irqInit(); + irqSet(IRQ_VBLANK, on_irq_vblank); + irqEnable(IRQ_VBLANK); + + //set the mode for 2 text layers and two extended background layers + //videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); + videoSetMode(MODE_6_2D| DISPLAY_BG2_ACTIVE); + + //set the sub background up for text display (we could just print to one + //of the main display text backgrounds just as easily + videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text + + //set the first two banks as background memory and the third as sub background memory + //D is not used..if you need a bigger background then you will need to map + //more vram banks consecutivly (VRAM A-D are all 0x20000 bytes in size) + //vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_BG_0x6020000,VRAM_C_SUB_BG , VRAM_D_LCD); + vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_BG,VRAM_C_MAIN_BG,VRAM_D_MAIN_BG); + //vramSetBankA(VRAM_A_MAIN_BG); + //vramSetBankB(VRAM_B_MAIN_BG); + //vramSetBankC(VRAM_C_MAIN_BG); + //vramSetBankD(VRAM_D_MAIN_BG); + //vramSetBankE(VRAM_E_MAIN_BG); + //vramSetBankF(VRAM_F_MAIN_BG); + //vramSetBankG(VRAM_G_MAIN_BG); + vramSetBankH(VRAM_H_SUB_BG); + vramSetBankI(VRAM_I_LCD); + + ////////////////set up text background for text///////////////////// + SUB_BG0_CR = BG_MAP_BASE(8); + + BG_PALETTE_SUB[255] = RGB15(31,31,31);//by default font will be rendered with color 255 + ///////////////set up our bitmap background/////////////////////// + + //BG3_CR = BG_BMP16_512x512; + + //these are rotation backgrounds so you must set the rotation attributes: + //these are fixed point numbers with the low 8 bits the fractional part + //this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap + /* BG3_XDX = 1<<8; + BG3_XDY = 0; + BG3_YDX = 0; + BG3_YDY = 1<<8; + //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2 + BG3_CX = 0; + BG3_CY = 0; + */ + //consoleInit() is a lot more flexible but this gets you up and running quick + consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(8), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); + + + frontBuffer =(u16*)(0x06000000); + //backBuffer =(u16*)(0x06000000 + 1024 * 512*2); + + //lcdSwap(); + /* We're done! */ + return(0); +} + +SDL_Rect **NDS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) +{ + return (SDL_Rect **) -1; +} + +SDL_Surface *NDS_SetVideoMode(_THIS, SDL_Surface *current, + int width, int height, int bpp, Uint32 flags) +{ + Uint32 Rmask, Gmask, Bmask, Amask; + + //if(width > 1024 || height > 512 || bpp > 16) + // return(NULL); + + if(bpp >8) { + bpp=16; + Rmask = 0x0000001F; + Gmask = 0x000003E0; + Bmask = 0x00007C00; + Amask = 0x00008000; + + videoSetMode(MODE_5_2D| DISPLAY_BG2_ACTIVE); + + vramSetMainBanks(VRAM_A_MAIN_BG,VRAM_B_MAIN_BG,VRAM_C_MAIN_BG,VRAM_D_MAIN_BG); + + BG2_CR = BG_BMP16_512x512; + BG2_XDX = ((width / 256) << 8) | (width % 256) ; + BG2_XDY = 0; + BG2_YDX = 0; + BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ; + BG2_CX = 0; + BG2_CY = 0; +// for (i=0;i<256*192;i++) +// frontBuffer[i] = RGB15(31,0,0)|BIT(15); + } + else + if(bpp <= 8) { + bpp=8; + Rmask = 0x00000000; + Gmask = 0x00000000; + Bmask = 0x00000000; + BG2_CR = BG_BMP8_1024x512; + BG2_XDX = ((width / 256) << 8) | (width % 256) ; + BG2_XDY = 0; + BG2_YDX = 0; + BG2_YDY = ((height / 192) << 8) | ((height % 192) + (height % 192) / 3) ; + + } + else + if(bpp < 15) bpp=15; + if(width<=256) width=256; + else + if(width<256) width=256; + if(height<=192) height=192; + else + if(height<192) height=192; + + if(bpp==8) + { + if(width<256) width=256; + if(height<192) height=192; + this->hidden->ndsmode=4; + } + + if(bpp==15) + { + if(width<256) this->hidden->ndsmode=5; + else this->hidden->ndsmode=3; + } + + this->hidden->buffer= frontBuffer;//NDS_VRAM_BASE; + + //NDS_DISPCNT = NDS_DISP_MODE(this->hidden->ndsmode)|NDS_DISP_BG2; + + //fprintf(stderr,"Setting mode %dx%d (ndsmode %d)\n", width, height,this->hidden->ndsmode); + + // FIXME: How do I tell that 15 bits mode is 555? + + SDL_memset(this->hidden->buffer, 0, 1024 * 512* ((this->hidden->ndsmode==4 || this->hidden->ndsmode==5) ? 2 : 1 ) * ((bpp+7) / 8)); + + /* Allocate the new pixel format for the screen */ + if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, Amask) ) { + this->hidden->buffer = NULL; + SDL_SetError("Couldn't allocate new pixel format for requested mode"); + return(NULL); + } + + /* Set up the new mode framebuffer */ + current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | (this->hidden->ndsmode > 0 ? SDL_DOUBLEBUF : 0); + this->hidden->w = current->w = width; + this->hidden->h = current->h = height; + current->pixels = frontBuffer; + + if (flags & SDL_DOUBLEBUF) { + this->hidden->secondbufferallocd=1; + backBuffer=(u16*)SDL_malloc(1024*512*2); + current->pixels = backBuffer; + } + if(bpp==8) + current->pitch =1024; + else + current->pitch =1024*2; + + /* We're done */ + return(current); +} + +static int NDS_AllocHWSurface(_THIS, SDL_Surface *surface) +{ + if(this->hidden->secondbufferallocd) { + //printf("double double buffer alloc\n"); + return -1; + } + //if(this->hidden->ndsmode==3) + //{ + // printf("no 2nd buffer in mode3\n"); + // return -1; + //} + //printf("second buffer\n"); + //this->hidden->secondbufferallocd=1; + //backBuffer=(u16*)malloc(1024*512*2); + //surface->pixels = backBuffer; + + return(0); +} +static void NDS_FreeHWSurface(_THIS, SDL_Surface *surface) +{ + //free(backBuffer); + this->hidden->secondbufferallocd=0; +} +int z=0; +/* We need to wait for vertical retrace on page flipped displays */ +static int NDS_LockHWSurface(_THIS, SDL_Surface *surface) +{ +/* + uint8* a = surface->pixels; + int i,j; + a += 5 * SCREEN_WIDTH + 5; + for( i = 0; i < 195; ++i) { + uint16* line = a + (SCREEN_WIDTH * i); + for( j = 0; j < 158; ++j) { + *line++ = RGB15(155,155,25); + } + } +*/ + //if (z <256) + // BG_PALETTE[z++]=RGB15(255-z,z,255-z); + + + return(0); +} + +static void NDS_UnlockHWSurface(_THIS, SDL_Surface *surface) +{ + return; +} + +static int NDS_FlipHWSurface(_THIS, SDL_Surface *surface) +{ + if(this->hidden->secondbufferallocd){ + while(DISP_Y!=192); + while(DISP_Y==192); + //printf("flip"); + + dmaCopyAsynch(backBuffer,frontBuffer,1024*512); + } + //printf("flip\n"); + //u16* temp = surface->pixels; + //surface->pixels = frontBuffer; + //frontBuffer = temp; + /* u8* vram=BG_GFX; + int x,y; + for(y = 0; y < 512; y++) + dmaCopy(&frontBuffer[y*rects->w], &vram[y*512],512); + //unsigned char buf; + + //printf("NDS_FlipHWSurface\n"); + //printf("ptr now: 0x%x\n",surface->pixels); + + while(DISP_Y!=192); + while(DISP_Y==192); + //swap + u16* temp = frontBuffer; + frontBuffer = backBuffer; + backBuffer = temp; + + //flip + //base is 16KB and screen size is 256x256x2 (128KB) + BG2_CR ^= BG_BMP_BASE( 512 / 16 ); */ +/* + if(surface->pixels == frontBuffer)//NDS_VRAM_BASE) + { + while(DISP_Y!=192); + while(DISP_Y==192); + //swap + u16* temp = backBuffer; + backBuffer = frontBuffer; + frontBuffer = temp; + + //flip + //base is 16KB and screen size is 256x256x2 (128KB) + BG3_CR ^= BG_BMP_BASE( 128 / 16 ); + } + else + { + + while(DISP_Y!=192); + while(DISP_Y==192); + //swap + u16* temp = frontBuffer; + frontBuffer = backBuffer; + backBuffer = temp; + + //flip + //base is 16KB and screen size is 256x256x2 (128KB) + BG3_CR ^= BG_BMP_BASE( 128 / 16 ); + + } + */ + //printf("ptr then: 0x%x\n",surface->pixels); + + //printf("setting dispcnt to 0x%x\n",NDS_DISPCNT = NDS_DISP_MODE(this->hidden->ndsmode)|NDS_DISP_BG2| buf); + return(0); +} + +static void NDS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) +{ + //fprintf(stderr,"update\n"); + /* do nothing. */ + //dmaCopy(frontBuffer,BG_GFX,512*512); + /* + u8* vram=(u8*)BG_GFX; + int x,y; + for(y = 0; y < 512; y++) + dmaCopy(&frontBuffer[y*rects->w], &vram[y*512],512); + */ + +} + +int NDS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) +{ + //printf("SetColors\n"); + short r,g,b; + + if(this->hidden->ndsmode != 4) + { + printf("This is not a palettized mode\n"); + return -1; + } + + int i,j=firstcolor+ncolors; + for(i=firstcolor;i<j;i++) + { + r=colors[i].r>>3; + g=colors[i].g>>3; + b=colors[i].b>>3; + BG_PALETTE[i]=RGB15(r, g, b); + } + + return(0); +} + +/* Note: If we are terminated, this could be called in the middle of + another SDL video routine -- notably UpdateRects. +*/ +void NDS_VideoQuit(_THIS) +{ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/nds/SDL_ndsvideo.h Mon Jun 25 00:50:20 2007 +0000 @@ -0,0 +1,61 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_ndsvideo_h +#define _SDL_ndsvideo_h + +#include "SDL_mouse.h" +#include "../SDL_sysvideo.h" + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_VideoDevice *this + + +/* Private display data */ + +struct SDL_PrivateVideoData { + int w, h; + void *buffer; + short ndsmode; + short secondbufferallocd; +}; + +/* +#define NDS_VIDC_BASE 0x4000000 +#define NDS_DISPCNT (*(volatile Uint32*)(NDS_VIDC_BASE)) +#define NDS_VIDC_SCANLINE (NDS_VIDC_BASE+6) +#define NDS_SCANLINE (*(volatile Uint8*)(NDS_VIDC_SCANLINE)) + +#define NDS_DISP_MODE(n) (n&7) +#define NDS_DISP_BG2 0x400 +#define NDS_DISP_FB 0x10 + +#define NDS_PAL_BASE 0x5000000 +#define NDS_BGPAL ((volatile Uint16*)(NDS_PAL_BASE)) +#define NDS_OBJPAL ((volatile Uint16*)(NDS_PAL_BASE+0x200)) + +#define NDS_VRAM_BASE 0x6000000 +#define NDS_VRAM_2NDBUF 0x600a000 +#define NDS_VRAM = ((volatile Uint16* )NDS_VRAM_BASE) +*/ +#endif /* _SDL_ndsvideo_h */
--- a/src/video/windib/SDL_dibvideo.c Sun Jun 24 18:26:35 2007 +0000 +++ b/src/video/windib/SDL_dibvideo.c Mon Jun 25 00:50:20 2007 +0000 @@ -751,6 +751,11 @@ /* Set video surface flags */ if ( bpp <= 8 ) { + if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { + hdc = GetDC(SDL_Window); + SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC); + ReleaseDC(SDL_Window, hdc); + } /* BitBlt() maps colors for us */ video->flags |= SDL_HWPALETTE; }