Commit 9d68aabe authored by Sam Lantinga's avatar Sam Lantinga

Added initial support for Nintendo DS, based on the work by Troy Davis (GPF)

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402376
parent 10ab421d
#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
......@@ -12,10 +12,11 @@ This is the Simple DirectMedia Layer, a general API that provides low
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,
......
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/
......@@ -49,6 +49,9 @@ SDL 1.2.12 is a minor bug fix release.
<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>
......
/*
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 */
......@@ -129,7 +129,9 @@ typedef enum {
DUMMY_ENUM_VALUE
} SDL_DUMMY_ENUM;
#ifndef __NDS__
SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
#endif
#include "begin_code.h"
......
......@@ -54,7 +54,9 @@ static SDL_version version =
/* 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;
......
......@@ -101,6 +101,9 @@ static AudioBootStrap *bootstrap[] = {
#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 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
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 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
SDL_CloseAudio();
return(-1);
}
#endif /* __MINT__ */
#endif /* __MACOS__ */
#endif /* SDL_THREADS_DISABLED */
/* Calculate the silence and size of the audio specification */
SDL_CalculateAudioSpec(desired);
......
......@@ -165,6 +165,9 @@ extern AudioBootStrap DUMMYAUD_bootstrap;
#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
......
/*
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);
}
/*
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 */
/*
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;
}
/*
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
/*
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)
{
}
/*
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)
{
}
......@@ -166,12 +166,21 @@ do { \
} 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 @@ do { \
} 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 @@ do { \
((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) { \
......
......@@ -392,6 +392,9 @@ extern VideoBootStrap PG_bootstrap;
#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
......
......@@ -108,6 +108,9 @@ static VideoBootStrap *bootstrap[] = {
#if SDL_VIDEO_DRIVER_DC
&DC_bootstrap,
#endif
#if SDL_VIDEO_DRIVER_NDS
&NDS_bootstrap,
#endif
#if SDL_VIDEO_DRIVER_RISCOS
&RISCOS_bootstrap,
#endif
......
/*
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 ... */
/*
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 ... */
/*
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;
};
/*
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 */
This diff is collapsed.
/*
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 */
......@@ -751,6 +751,11 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current,
/* 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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment