Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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).
  • Loading branch information
slouken committed Mar 27, 2011
1 parent 01cb78a commit 8ded3e61463c5faf6807a2e8baeb281b52518b7f
Showing with 84 additions and 61 deletions.
  1. +11 −8 Makefile.ds
  2. +24 −4 README.ds
  3. +24 −29 src/render/nds/SDL_ndsrender.c
  4. +1 −1 src/timer/nds/SDL_systimer.c
  5. +1 −1 src/video/SDL_surface.c
  6. +3 −1 src/video/nds/SDL_ndsevents.c
  7. +20 −17 src/video/nds/SDL_ndsvideo.c
@@ -17,7 +17,7 @@ include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := src
SOURCES := source
SOURCES := src
DATA := data
INCLUDES := include

@@ -53,7 +53,7 @@ endif
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
LIBDIRS := $(LIBNDS) $(PORTLIBS)

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
@@ -171,7 +171,8 @@ export OFILES := $(addsuffix .o,$(BINFILES)) \

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
-I$(CURDIR)/$(BUILD) \
-I$(PORTLIBS)/include/SDL

.PHONY: $(BUILD) clean all

@@ -186,15 +187,15 @@ $(BUILD): lib
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.ds -s

install: $(BUILD)
@cp $(OUTPUT) $(DEVKITPRO)/libnds/lib/
@mkdir -p $(DEVKITPRO)/libnds/include/SDL/
@cp include/*.h $(DEVKITPRO)/libnds/include/SDL/
@mkdir -p $(PORTLIBS)/include/SDL/
@rsync -a $(OUTPUT) $(PORTLIBS)/lib/
@rsync -a include/*.h $(PORTLIBS)/include/SDL/

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

tags:
etags $(SRCS)
cd $(SOURCES); etags $(CFILES)

# This file must be compiled with the ARM instruction set, not
# thumb. Use devkitpro way of doing things.
@@ -206,6 +207,8 @@ src/atomic/SDL_spinlock.arm.c: src/atomic/SDL_spinlock.c
clean:
@echo clean ...
@cd src; rm -fr $(OFILES) $(OFILES:.o=.d) lib
@rm -f $(OUTPUT)
@make -C test/nds-test-progs -s clean

#---------------------------------------------------------------------------------
else
@@ -17,17 +17,17 @@ Simple DirectMedia Layer for Nintendo DS
After setting the devkitpro environment, cd into your SDL directory and type:
make -f Makefile.ds

This will compile and install the library and headers into the proper libnds
directories. Additionnaly it will compile several tests that you can run
either on the DS or with desmume. For instance:
This will compile and install the library and headers into the
devkitpro's portlibs directory. Additionnaly it will compile several
tests that you can run either on the DS or with desmume. For instance:
desmume test/nds-test-progs/general/general.nds

-Notes-
* The renderer code is based on the gl like engine. It's not using the sprite engine.
* The port is very basic and incomplete:
- SDL currently has to be compiled for either framebuffer mode or render mode.
See USE_HW_RENDERER in Makefile.ds.
- some optionnal renderer functions are not implemented.
- some optional renderer functions are not implemented.

-Limitations-
* 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:
* 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.

-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)
SDL_free(txdat);
}

/* size is no more than 1024. */
/* size is no more than 512. */
static int get_gltexture_size(unsigned int size)
{
if (size > 256)
@@ -155,12 +155,10 @@ static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
{
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;

SDL_Log("enter %s\n", __func__);

glLoadTileSet(txdat->image,
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->h),
TEXGEN_OFF, 0, NULL,
@@ -184,8 +182,25 @@ static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
}

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;
static int frame =0;

glEnd2D();

glFlush(0);

swiWaitForVBlank();

/* wait for capture unit to be ready */
while(REG_DISPCAPCNT & DCAP_ENABLE);
@@ -205,22 +220,6 @@ static int NDS_RenderClear(SDL_Renderer *renderer)
}

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,
@@ -323,14 +322,8 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
return NULL;
}

renderer->info.name = NDS_RenderDriver.info.name;
renderer->info.flags = 0;
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->info = NDS_RenderDriver.info;
renderer->info.flags = SDL_RENDERER_ACCELERATED;

renderer->UpdateViewport = NDS_UpdateViewport;
renderer->CreateTexture = NDS_CreateTexture;
@@ -345,6 +338,8 @@ NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->RenderDrawLines = NDS_RenderDrawLines;
renderer->RenderFillRects = NDS_RenderFillRects;

renderer->driverdata = data;

return renderer;
}

@@ -353,7 +348,7 @@ SDL_RenderDriver NDS_RenderDriver = {
.info = {
.name = "nds",
.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC,
.num_texture_formats = 1,
.num_texture_formats = 2,
.texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555,
[1] = SDL_PIXELFORMAT_BGR555,
},
@@ -28,7 +28,7 @@

#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 void
@@ -866,7 +866,7 @@ SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format,
Uint32 flags)
{
SDL_PixelFormat *fmt;
SDL_Surface *convert;
SDL_Surface *convert = NULL;

fmt = SDL_AllocFormat(pixel_format);
if (fmt) {
@@ -44,7 +44,9 @@ NDS_PumpEvents(_THIS)
SDL_SendMouseButton(0, SDL_RELEASED, 0);
}
if (keysHeld() & KEY_TOUCH) {
touchPosition t = touchReadXY();
touchPosition t;

touchRead(&t);
SDL_SendMouseMotion(0, 0, t.px, t.py);
}
}
@@ -249,24 +249,22 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode
{
display->driverdata = mode->driverdata;

powerOn(POWER_ALL_2D);

#ifdef USE_HW_RENDERER

videoSetMode(MODE_5_3D);
videoSetModeSub(MODE_5_2D);

/* initialize gl2d */
glScreen2D();
glBegin2D();

vramSetBankA(VRAM_A_TEXTURE);
vramSetBankA(VRAM_A_TEXTURE);
vramSetBankB(VRAM_B_TEXTURE );
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankE(VRAM_E_TEX_PALETTE);

powerOn(POWER_ALL_2D);

irqInit();
irqEnable(IRQ_VBLANK);

// sub sprites hold the bottom image when 3D directed to top
initSubSprites();

@@ -279,16 +277,11 @@ static int NDS_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode
videoSetMode(MODE_5_2D);
videoSetModeSub(MODE_5_2D);

vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_TEXTURE );
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankE(VRAM_E_TEX_PALETTE);

powerOn(POWER_ALL_2D);

irqInit();
irqEnable(IRQ_VBLANK);

#endif

return 0;
@@ -311,7 +304,7 @@ static int NDS_VideoInit(_THIS)

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.h = 2*SCREEN_HEIGHT+SCREEN_GAP;
mode.refresh_rate = 60;
@@ -379,8 +372,8 @@ static SDL_VideoDevice *NDS_CreateDevice(int devindex)
device->PumpEvents = NDS_PumpEvents;
device->free = NDS_DeleteDevice;

/* Set the debug output. Use only for under an emulator. Will crash the DS. */
#if 1
/* Set the debug output. Use only under an emulator. Will crash the DS. */
#if 0
SDL_LogSetOutputFunction(NDS_DebugOutput, NULL);
#endif

@@ -392,4 +385,14 @@ VideoBootStrap NDS_bootstrap = {
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: */

0 comments on commit 8ded3e6

Please sign in to comment.