Commit 3b72fdef authored by Sam Lantinga's avatar Sam Lantinga

NDS update

Frank Zago to SDL

I've cleaned up a few bugs in the nds code. A few more tests now pass.
There's still a few things to do, but overall I think it's starting to be in a
good shape.

The patch also includes a bug fix for SDL_ConvertSurfaceFormat() (gcc warning).
parent 85ad17e7
...@@ -17,7 +17,7 @@ include $(DEVKITARM)/ds_rules ...@@ -17,7 +17,7 @@ include $(DEVKITARM)/ds_rules
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR)) TARGET := $(shell basename $(CURDIR))
BUILD := src BUILD := src
SOURCES := source SOURCES := src
DATA := data DATA := data
INCLUDES := include INCLUDES := include
...@@ -53,7 +53,7 @@ endif ...@@ -53,7 +53,7 @@ endif
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing
# include and lib # include and lib
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) LIBDIRS := $(LIBNDS) $(PORTLIBS)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional # no real need to edit anything past this point unless you need to add additional
...@@ -171,7 +171,8 @@ export OFILES := $(addsuffix .o,$(BINFILES)) \ ...@@ -171,7 +171,8 @@ export OFILES := $(addsuffix .o,$(BINFILES)) \
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) -I$(CURDIR)/$(BUILD) \
-I$(PORTLIBS)/include/SDL
.PHONY: $(BUILD) clean all .PHONY: $(BUILD) clean all
...@@ -186,15 +187,15 @@ $(BUILD): lib ...@@ -186,15 +187,15 @@ $(BUILD): lib
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.ds -s @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.ds -s
install: $(BUILD) install: $(BUILD)
@cp $(OUTPUT) $(DEVKITPRO)/libnds/lib/ @mkdir -p $(PORTLIBS)/include/SDL/
@mkdir -p $(DEVKITPRO)/libnds/include/SDL/ @rsync -a $(OUTPUT) $(PORTLIBS)/lib/
@cp include/*.h $(DEVKITPRO)/libnds/include/SDL/ @rsync -a include/*.h $(PORTLIBS)/include/SDL/
nds_test: nds_test:
$(MAKE) -C test/nds-test-progs $(MAKE) -C test/nds-test-progs -s
tags: tags:
etags $(SRCS) cd $(SOURCES); etags $(CFILES)
# This file must be compiled with the ARM instruction set, not # This file must be compiled with the ARM instruction set, not
# thumb. Use devkitpro way of doing things. # thumb. Use devkitpro way of doing things.
...@@ -206,6 +207,8 @@ src/atomic/SDL_spinlock.arm.c: src/atomic/SDL_spinlock.c ...@@ -206,6 +207,8 @@ src/atomic/SDL_spinlock.arm.c: src/atomic/SDL_spinlock.c
clean: clean:
@echo clean ... @echo clean ...
@cd src; rm -fr $(OFILES) $(OFILES:.o=.d) lib @cd src; rm -fr $(OFILES) $(OFILES:.o=.d) lib
@rm -f $(OUTPUT)
@make -C test/nds-test-progs -s clean
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
else else
......
...@@ -17,9 +17,9 @@ Simple DirectMedia Layer for Nintendo DS ...@@ -17,9 +17,9 @@ Simple DirectMedia Layer for Nintendo DS
After setting the devkitpro environment, cd into your SDL directory and type: After setting the devkitpro environment, cd into your SDL directory and type:
make -f Makefile.ds make -f Makefile.ds
This will compile and install the library and headers into the proper libnds This will compile and install the library and headers into the
directories. Additionnaly it will compile several tests that you can run devkitpro's portlibs directory. Additionnaly it will compile several
either on the DS or with desmume. For instance: tests that you can run either on the DS or with desmume. For instance:
desmume test/nds-test-progs/general/general.nds desmume test/nds-test-progs/general/general.nds
-Notes- -Notes-
...@@ -27,7 +27,7 @@ either on the DS or with desmume. For instance: ...@@ -27,7 +27,7 @@ either on the DS or with desmume. For instance:
* The port is very basic and incomplete: * The port is very basic and incomplete:
- SDL currently has to be compiled for either framebuffer mode or render mode. - SDL currently has to be compiled for either framebuffer mode or render mode.
See USE_HW_RENDERER in Makefile.ds. See USE_HW_RENDERER in Makefile.ds.
- some optionnal renderer functions are not implemented. - some optional renderer functions are not implemented.
-Limitations- -Limitations-
* in hardware renderer mode, don't load too many textures. The internal format is * in hardware renderer mode, don't load too many textures. The internal format is
...@@ -36,4 +36,24 @@ either on the DS or with desmume. For instance: ...@@ -36,4 +36,24 @@ either on the DS or with desmume. For instance:
* the screen size is 256 x 384. Anything else won't work. * the screen size is 256 x 384. Anything else won't work.
* there is no 8 bits/pixel mode because SDL 1.3 doesn't support palettes. * there is no 8 bits/pixel mode because SDL 1.3 doesn't support palettes.
-Joystick mapping-
The Joystick presented to SDL has 2 axes and 8 buttons
KEY | Code
A | 0
B | 1
X | 2
Y | 3
L | 4
R | 5
select | 6
start | 7
Left-right is axe 0.
Up-down is axe 1.
-Mouse mapping-
todo
-Examples-
Due to memory limitations, to be able to successfully run the testscale example, sample.bmp must be resized to 256x105.
...@@ -131,7 +131,7 @@ NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -131,7 +131,7 @@ NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
SDL_free(txdat); SDL_free(txdat);
} }
/* size is no more than 1024. */ /* size is no more than 512. */
static int get_gltexture_size(unsigned int size) static int get_gltexture_size(unsigned int size)
{ {
if (size > 256) if (size > 256)
...@@ -155,12 +155,10 @@ static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -155,12 +155,10 @@ static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
{ {
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
SDL_Log("enter %s\n", __func__);
glLoadTileSet(txdat->image, glLoadTileSet(txdat->image,
rect->w, rect->h, rect->w, rect->h,
rect->w, rect->h, rect->w, rect->h,
GL_RGBA, texture->format == SDL_PIXELFORMAT_ABGR1555 ? GL_RGBA : GL_RGB,
get_gltexture_size(rect->w), get_gltexture_size(rect->w),
get_gltexture_size(rect->h), get_gltexture_size(rect->h),
TEXGEN_OFF, 0, NULL, TEXGEN_OFF, 0, NULL,
...@@ -184,8 +182,25 @@ static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) ...@@ -184,8 +182,25 @@ static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
} }
static int NDS_RenderClear(SDL_Renderer *renderer) static int NDS_RenderClear(SDL_Renderer *renderer)
{
glClearColor(renderer->r >> 3,
renderer->g >> 3,
renderer->b >> 3,
renderer->a >> 3);
return 0;
}
static void NDS_RenderPresent(SDL_Renderer * renderer)
{ {
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
static int frame =0;
glEnd2D();
glFlush(0);
swiWaitForVBlank();
/* wait for capture unit to be ready */ /* wait for capture unit to be ready */
while(REG_DISPCAPCNT & DCAP_ENABLE); while(REG_DISPCAPCNT & DCAP_ENABLE);
...@@ -205,22 +220,6 @@ static int NDS_RenderClear(SDL_Renderer *renderer) ...@@ -205,22 +220,6 @@ static int NDS_RenderClear(SDL_Renderer *renderer)
} }
glBegin2D(); glBegin2D();
glClearColor(renderer->r >> 3,
renderer->g >> 3,
renderer->b >> 3,
renderer->a >> 3);
return 0;
}
static void NDS_RenderPresent(SDL_Renderer * renderer)
{
// SDL_Log("enter %s\n", __func__);
glEnd2D();
glFlush( 0 );
} }
static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points,
...@@ -323,14 +322,8 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -323,14 +322,8 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
return NULL; return NULL;
} }
renderer->info.name = NDS_RenderDriver.info.name; renderer->info = NDS_RenderDriver.info;
renderer->info.flags = 0; renderer->info.flags = SDL_RENDERER_ACCELERATED;
renderer->info.num_texture_formats = NDS_RenderDriver.info.num_texture_formats;
SDL_memcpy(renderer->info.texture_formats,
NDS_RenderDriver.info.texture_formats,
sizeof(renderer->info.texture_formats));
renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width;
renderer->info.max_texture_height = NDS_RenderDriver.info.max_texture_height;
renderer->UpdateViewport = NDS_UpdateViewport; renderer->UpdateViewport = NDS_UpdateViewport;
renderer->CreateTexture = NDS_CreateTexture; renderer->CreateTexture = NDS_CreateTexture;
...@@ -345,6 +338,8 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -345,6 +338,8 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->RenderDrawLines = NDS_RenderDrawLines; renderer->RenderDrawLines = NDS_RenderDrawLines;
renderer->RenderFillRects = NDS_RenderFillRects; renderer->RenderFillRects = NDS_RenderFillRects;
renderer->driverdata = data;
return renderer; return renderer;
} }
...@@ -353,7 +348,7 @@ SDL_RenderDriver NDS_RenderDriver = { ...@@ -353,7 +348,7 @@ SDL_RenderDriver NDS_RenderDriver = {
.info = { .info = {
.name = "nds", .name = "nds",
.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC, .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC,
.num_texture_formats = 1, .num_texture_formats = 2,
.texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555, .texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555,
[1] = SDL_PIXELFORMAT_BGR555, [1] = SDL_PIXELFORMAT_BGR555,
}, },
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "SDL_timer.h" #include "SDL_timer.h"
/* Will wrap afetr 49 days. Shouldn't be an issue. */ /* Will wrap after 49 days. Shouldn't be an issue. */
static volatile Uint32 timer_ticks; static volatile Uint32 timer_ticks;
static void static void
......
...@@ -866,7 +866,7 @@ SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format, ...@@ -866,7 +866,7 @@ SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format,
Uint32 flags) Uint32 flags)
{ {
SDL_PixelFormat *fmt; SDL_PixelFormat *fmt;
SDL_Surface *convert; SDL_Surface *convert = NULL;
fmt = SDL_AllocFormat(pixel_format); fmt = SDL_AllocFormat(pixel_format);
if (fmt) { if (fmt) {
......
...@@ -44,7 +44,9 @@ NDS_PumpEvents(_THIS) ...@@ -44,7 +44,9 @@ NDS_PumpEvents(_THIS)
SDL_SendMouseButton(0, SDL_RELEASED, 0); SDL_SendMouseButton(0, SDL_RELEASED, 0);
} }
if (keysHeld() & KEY_TOUCH) { if (keysHeld() & KEY_TOUCH) {
touchPosition t = touchReadXY(); touchPosition t;
touchRead(&t);
SDL_SendMouseMotion(0, 0, t.px, t.py); SDL_SendMouseMotion(0, 0, t.px, t.py);
} }
} }
......
...@@ -249,6 +249,8 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode ...@@ -249,6 +249,8 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode
{ {
display->driverdata = mode->driverdata; display->driverdata = mode->driverdata;
powerOn(POWER_ALL_2D);
#ifdef USE_HW_RENDERER #ifdef USE_HW_RENDERER
videoSetMode(MODE_5_3D); videoSetMode(MODE_5_3D);
...@@ -256,17 +258,13 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode ...@@ -256,17 +258,13 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode
/* initialize gl2d */ /* initialize gl2d */
glScreen2D(); glScreen2D();
glBegin2D();
vramSetBankA(VRAM_A_TEXTURE); vramSetBankA(VRAM_A_TEXTURE);
vramSetBankB(VRAM_B_TEXTURE ); vramSetBankB(VRAM_B_TEXTURE );
vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankE(VRAM_E_TEX_PALETTE); vramSetBankE(VRAM_E_TEX_PALETTE);
powerOn(POWER_ALL_2D);
irqInit();
irqEnable(IRQ_VBLANK);
// sub sprites hold the bottom image when 3D directed to top // sub sprites hold the bottom image when 3D directed to top
initSubSprites(); initSubSprites();
...@@ -279,16 +277,11 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode ...@@ -279,16 +277,11 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode
videoSetMode(MODE_5_2D); videoSetMode(MODE_5_2D);
videoSetModeSub(MODE_5_2D); videoSetModeSub(MODE_5_2D);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_TEXTURE ); vramSetBankB(VRAM_B_TEXTURE );
vramSetBankC(VRAM_C_SUB_BG_0x06200000); vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankE(VRAM_E_TEX_PALETTE); vramSetBankE(VRAM_E_TEX_PALETTE);
powerOn(POWER_ALL_2D);
irqInit();
irqEnable(IRQ_VBLANK);
#endif #endif
return 0; return 0;
...@@ -311,7 +304,7 @@ static int NDS_VideoInit(_THIS) ...@@ -311,7 +304,7 @@ static int NDS_VideoInit(_THIS)
SDL_zero(mode); SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_UNKNOWN; // shoud be SDL_PIXELFORMAT_ABGR1555; mode.format = SDL_PIXELFORMAT_UNKNOWN; // should be SDL_PIXELFORMAT_ABGR1555;
mode.w = SCREEN_WIDTH; mode.w = SCREEN_WIDTH;
mode.h = 2*SCREEN_HEIGHT+SCREEN_GAP; mode.h = 2*SCREEN_HEIGHT+SCREEN_GAP;
mode.refresh_rate = 60; mode.refresh_rate = 60;
...@@ -379,8 +372,8 @@ static SDL_VideoDevice *NDS_CreateDevice(int devindex) ...@@ -379,8 +372,8 @@ static SDL_VideoDevice *NDS_CreateDevice(int devindex)
device->PumpEvents = NDS_PumpEvents; device->PumpEvents = NDS_PumpEvents;
device->free = NDS_DeleteDevice; device->free = NDS_DeleteDevice;
/* Set the debug output. Use only for under an emulator. Will crash the DS. */ /* Set the debug output. Use only under an emulator. Will crash the DS. */
#if 1 #if 0
SDL_LogSetOutputFunction(NDS_DebugOutput, NULL); SDL_LogSetOutputFunction(NDS_DebugOutput, NULL);
#endif #endif
...@@ -392,4 +385,14 @@ VideoBootStrap NDS_bootstrap = { ...@@ -392,4 +385,14 @@ VideoBootStrap NDS_bootstrap = {
NDS_Available, NDS_CreateDevice NDS_Available, NDS_CreateDevice
}; };
double SDLCALL SDL_pow(double x, double y)
{
static int once = 1;
if (once) {
SDL_Log("SDL_pow called but not supported on this platform");
once = 0;
}
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
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