Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Final merge of Google Summer of Code 2008 work...
Browse files Browse the repository at this point in the history
Port SDL 1.3 to the Nintendo DS
by Darren Alton, mentored by Sam Lantinga
  • Loading branch information
slouken committed Aug 27, 2008
1 parent ba7155a commit d012661
Show file tree
Hide file tree
Showing 123 changed files with 6,082 additions and 388 deletions.
129 changes: 129 additions & 0 deletions Makefile.ds
@@ -0,0 +1,129 @@

#LibSDL 1.3 porting and enhancements by Darren Alton (lifning)
#LibSDL 1.2.9 DS porting by Troy Davis(GPF)

ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment (available from http://www.devkitpro.org). export DEVKITPRO=<path to>devkitPro")
endif
ifeq ($(strip $(DEVKITARM)),)
DEVKITARM = $(DEVKITPRO)/devkitARM
endif
PATH := $(PATH):$(DEVKITARM)/bin

CC = arm-eabi-gcc
AR = arm-eabi-ar
RANLIB = arm-eabi-ranlib

#ifdef GL
#DEFS += -DSDL_VIDEO_OPENGL=1
#TARGET = libSDL_gl.a
#else
TARGET = libSDL.a
#endif

#CFLAGS=$(DEFS) -Iinclude
CFLAGS = -mthumb -mthumb-interwork \
-march=armv5te -mtune=arm946e-s \
-O2 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
-DARM9 -D__NDS__ -I$(DEVKITPRO)/libnds/include -DENABLE_NDS -DNO_SIGNAL_H -DDISABLE_THREADS -DPACKAGE=\"SDL\" -DVERSION=\"1.3\" -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 \
-Iinclude -Isrc -Isrc/audio -Isrc/cdrom -Isrc/endian -Isrc/events -Isrc/joystick -Isrc/thread/nds -Isrc/thread -Isrc/timer -Isrc/video

#src/audio/disk/SDL_diskaudio.c \
#src/audio/dummy/SDL_dummyaudio.c \

SRCS = \
src/SDL.c \
src/SDL_compat.c \
src/SDL_error.c \
src/SDL_fatal.c \
src/audio/nds/SDL_ndsaudio.c \
src/audio/SDL_audio.c \
src/audio/SDL_audiocvt.c \
src/audio/SDL_audiodev.c \
src/audio/SDL_audiotypecvt.c \
src/audio/SDL_mixer.c \
src/audio/SDL_mixer_m68k.c \
src/audio/SDL_mixer_MMX.c \
src/audio/SDL_mixer_MMX_VC.c \
src/audio/SDL_wave.c \
src/cdrom/dummy/SDL_syscdrom.c \
src/cdrom/SDL_cdrom.c \
src/cpuinfo/SDL_cpuinfo.c \
src/events/SDL_events.c \
src/events/SDL_keyboard.c \
src/events/SDL_mouse.c \
src/events/SDL_quit.c \
src/events/SDL_windowevents.c \
src/file/SDL_rwops.c \
src/joystick/nds/SDL_sysjoystick.c \
src/joystick/SDL_joystick.c \
src/stdlib/SDL_getenv.c \
src/stdlib/SDL_iconv.c \
src/stdlib/SDL_malloc.c \
src/stdlib/SDL_qsort.c \
src/stdlib/SDL_stdlib.c \
src/stdlib/SDL_string.c \
src/thread/SDL_thread.c \
src/thread/nds/SDL_syscond.c \
src/thread/nds/SDL_sysmutex.c \
src/thread/nds/SDL_syssem.c \
src/thread/nds/SDL_systhread.c \
src/timer/nds/SDL_systimer.c \
src/timer/SDL_timer.c \
src/video/nds/SDL_ndsevents.c \
src/video/nds/SDL_ndsrender.c \
src/video/nds/SDL_ndsvideo.c \
src/video/dummy/SDL_nullevents.c \
src/video/dummy/SDL_nullrender.c \
src/video/dummy/SDL_nullvideo.c \
src/video/SDL_blit_0.c \
src/video/SDL_blit_1.c \
src/video/SDL_blit_A.c \
src/video/SDL_blit_auto.c \
src/video/SDL_blit.c \
src/video/SDL_blit_copy.c \
src/video/SDL_blit_N.c \
src/video/SDL_blit_slow.c \
src/video/SDL_bmp.c \
src/video/SDL_fill.c \
src/video/SDL_gamma.c \
src/video/SDL_pixels.c \
src/video/SDL_rect.c \
src/video/SDL_renderer_gl.c \
src/video/SDL_renderer_sw.c \
src/video/SDL_RLEaccel.c \
src/video/SDL_stretch.c \
src/video/SDL_surface.c \
src/video/SDL_video.c \
src/video/SDL_yuv_mmx.c \
src/video/SDL_yuv_sw.c \

OBJS = $(SRCS:.c=.o)

TEST = \
test/nds-test-progs/general/general.nds \
test/nds-test-progs/sprite/sprite.nds \
test/nds-test-progs/sprite2/sprite2.nds \


all: $(TARGET)

$(TARGET): copy_config \
$(OBJS)
$(AR) rc $(TARGET) $(OBJS)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1

install: $(TARGET)
@cp libSDL.a $(DEVKITPRO)/libnds/lib/
@mkdir -p $(DEVKITPRO)/libnds/include/SDL/
@cp include/*.h $(DEVKITPRO)/libnds/include/SDL/

nds_test:
$(MAKE) -C test/nds-test-progs

copy_config:
@cp include/SDL_config.h.default include/SDL_config.h

clean:
rm -f include/SDL_config.h $(OBJS)

4 changes: 3 additions & 1 deletion include/SDL_config.h.default
Expand Up @@ -26,7 +26,9 @@
#include "SDL_platform.h"

/* Add any platform that doesn't build using the configure system */
#if defined(__DREAMCAST__)
#if defined(__NINTENDODS__)
#include "SDL_config_nintendods.h"
#elif defined(__DREAMCAST__)
#include "SDL_config_dreamcast.h"
#elif defined(__MACOSX__)
#include "SDL_config_macosx.h"
Expand Down
5 changes: 5 additions & 0 deletions include/SDL_config.h.in
Expand Up @@ -177,6 +177,7 @@
#undef SDL_AUDIO_DRIVER_MMEAUDIO
#undef SDL_AUDIO_DRIVER_NAS
#undef SDL_AUDIO_DRIVER_NAS_DYNAMIC
#undef SDL_AUDIO_DRIVER_NDS
#undef SDL_AUDIO_DRIVER_OSS
#undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
#undef SDL_AUDIO_DRIVER_PAUDIO
Expand Down Expand Up @@ -211,6 +212,7 @@
#undef SDL_JOYSTICK_IOKIT
#undef SDL_JOYSTICK_LINUX
#undef SDL_JOYSTICK_MINT
#undef SDL_JOYSTICK_NDS
#undef SDL_JOYSTICK_OS2
#undef SDL_JOYSTICK_RISCOS
#undef SDL_JOYSTICK_WINMM
Expand All @@ -233,6 +235,7 @@
/* Enable various threading systems */
#undef SDL_THREAD_BEOS
#undef SDL_THREAD_DC
#undef SDL_THREAD_NDS
#undef SDL_THREAD_OS2
#undef SDL_THREAD_PTH
#undef SDL_THREAD_PTHREAD
Expand All @@ -246,6 +249,7 @@
#undef SDL_TIMER_DC
#undef SDL_TIMER_DUMMY
#undef SDL_TIMER_MINT
#undef SDL_TIMER_NDS
#undef SDL_TIMER_OS2
#undef SDL_TIMER_RISCOS
#undef SDL_TIMER_UNIX
Expand All @@ -263,6 +267,7 @@
#undef SDL_VIDEO_DRIVER_GEM
#undef SDL_VIDEO_DRIVER_IPOD
#undef SDL_VIDEO_DRIVER_NANOX
#undef SDL_VIDEO_DRIVER_NDS
#undef SDL_VIDEO_DRIVER_OS2FS
#undef SDL_VIDEO_DRIVER_PHOTON
#undef SDL_VIDEO_DRIVER_PS2GS
Expand Down
119 changes: 119 additions & 0 deletions include/SDL_config_nintendods.h
@@ -0,0 +1,119 @@
/*
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_nintendods_h
#define _SDL_config_nintendods_h

#include "SDL_platform.h"

/* This is a set of defines to configure the SDL features */

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

/* LiF: __PTRDIFF_TYPE__ was causing errors of conflicting typedefs with the
<stdint.h> shipping with devkitARM. copied a similar ifdef from it. */
#ifndef __PTRDIFF_TYPE__
typedef unsigned long uintptr_t;
#else
typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
#endif


#define SDL_HAS_64BIT_TYPE 1

/* Useful headers */
#define HAVE_SYS_TYPES_H 1
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
#define HAVE_STRING_H 1
#define HAVE_CTYPE_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_QSORT 1
#define HAVE_ABS 1
#define HAVE_BCOPY 1
#define HAVE_MEMSET 1
#define HAVE_MEMCPY 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMCMP 1
#define HAVE_STRLEN 1
#define HAVE_STRDUP 1
#define HAVE_INDEX 1
#define HAVE_RINDEX 1
#define HAVE_STRCHR 1
#define HAVE_STRRCHR 1
#define HAVE_STRSTR 1
#define HAVE_STRTOL 1
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
#define HAVE_STRCMP 1
#define HAVE_STRNCMP 1
#define HAVE_STRICMP 1
#define HAVE_STRCASECMP 1
#define HAVE_SSCANF 1
#define HAVE_SNPRINTF 1
#define HAVE_VSNPRINTF 1

/* DS isn't that sophisticated */
#define LACKS_SYS_MMAN_H 1

/* Enable various audio drivers */
#define SDL_AUDIO_DRIVER_NDS 1
/*#define SDL_AUDIO_DRIVER_DUMMY 1 TODO: uncomment this later*/

/* DS doesn't have optical media */
#define SDL_CDROM_DISABLED 1

/* Enable various input drivers */
#define SDL_JOYSTICK_NDS 1
/*#define SDL_JOYSTICK_DUMMY 1 TODO: uncomment this later*/

/* DS has no dynamic linking afaik */
#define SDL_LOADSO_DISABLED 1

/* Enable various threading systems */
/*#define SDL_THREAD_NDS 1*/
#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 TODO: uncomment this later*/

#endif /* _SDL_config_nintendods_h */
6 changes: 6 additions & 0 deletions include/SDL_pixels.h
Expand Up @@ -146,12 +146,18 @@ enum
SDL_PIXELFORMAT_RGB555 =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
SDL_PACKEDLAYOUT_1555, 15, 2),
SDL_PIXELFORMAT_BGR555 =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
SDL_PACKEDLAYOUT_1555, 15, 2),
SDL_PIXELFORMAT_ARGB4444 =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
SDL_PACKEDLAYOUT_4444, 16, 2),
SDL_PIXELFORMAT_ARGB1555 =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
SDL_PACKEDLAYOUT_1555, 16, 2),
SDL_PIXELFORMAT_ABGR1555 =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
SDL_PACKEDLAYOUT_1555, 16, 2),
SDL_PIXELFORMAT_RGB565 =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
SDL_PACKEDLAYOUT_565, 16, 2),
Expand Down
5 changes: 5 additions & 0 deletions include/SDL_platform.h
Expand Up @@ -97,4 +97,9 @@
#define __WIN32__ 1
#endif

#if defined(__NDS__)
#undef __NINTENDODS__
#define __NINTENDODS__ 1
#endif

#endif /* _SDL_platform_h */
9 changes: 9 additions & 0 deletions include/SDL_stdinc.h
Expand Up @@ -147,8 +147,12 @@ SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
#ifndef __NINTENDODS__ /* TODO: figure out why the following happens:
include/SDL_stdinc.h:150: error: size of array 'SDL_dummy_uint64' is negative
include/SDL_stdinc.h:151: error: size of array 'SDL_dummy_sint64' is negative */
SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
#endif
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */

/* Check to make sure enums are the size of ints, for structure packing.
Expand All @@ -162,12 +166,14 @@ SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
#endif

#ifndef DOXYGEN_SHOULD_IGNORE_THIS
#ifndef __NINTENDODS__ /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
typedef enum
{
DUMMY_ENUM_VALUE
} SDL_DUMMY_ENUM;

SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
#endif
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */

#include "begin_code.h"
Expand Down Expand Up @@ -425,6 +431,9 @@ extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
#ifdef HAVE_WCSLEN
#define SDL_wcslen wcslen
#else
#if !defined(wchar_t) && defined(__NINTENDODS__)
#define wchar_t short /* TODO: figure out why libnds doesn't have this */
#endif
extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
#endif

Expand Down
1 change: 1 addition & 0 deletions src/SDL_compat.c
Expand Up @@ -693,6 +693,7 @@ SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
SDL_UpdateRects(screen, 1, &rect);
}
}

void
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
{
Expand Down
4 changes: 2 additions & 2 deletions src/SDL_error.c
Expand Up @@ -180,8 +180,8 @@ SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
case 's':
len =
SDL_snprintf(msg, maxlen, tmp,
SDL_LookupString(error->
args[argi++].buf));
SDL_LookupString(error->args[argi++].
buf));
msg += len;
maxlen -= len;
break;
Expand Down

0 comments on commit d012661

Please sign in to comment.