NDS update
authorSam Lantinga <slouken@libsdl.org>
Sat, 26 Mar 2011 21:26:05 -0700
changeset 5515 0fcf231a6e74
parent 5514 6bd701987ba9
child 5516 89ad52a52876
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).
Makefile.ds
README.ds
src/render/nds/SDL_ndsrender.c
src/timer/nds/SDL_systimer.c
src/video/SDL_surface.c
src/video/nds/SDL_ndsevents.c
src/video/nds/SDL_ndsvideo.c
--- a/Makefile.ds	Fri Mar 25 14:45:04 2011 -0700
+++ b/Makefile.ds	Sat Mar 26 21:26:05 2011 -0700
@@ -17,7 +17,7 @@
 #---------------------------------------------------------------------------------
 TARGET		:=	$(shell basename $(CURDIR))
 BUILD		:=	src
-SOURCES		:=	source
+SOURCES		:=	src
 DATA		:=	data
 INCLUDES	:=	include
 
@@ -53,7 +53,7 @@
 # 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 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 @@
 	@$(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 @@
 clean:
 	@echo clean ...
 	@cd src; rm -fr $(OFILES) $(OFILES:.o=.d) lib
+	@rm -f $(OUTPUT)
+	@make -C test/nds-test-progs -s clean
 
 #---------------------------------------------------------------------------------
 else
--- a/README.ds	Fri Mar 25 14:45:04 2011 -0700
+++ b/README.ds	Sat Mar 26 21:26:05 2011 -0700
@@ -17,9 +17,9 @@
 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-
@@ -27,7 +27,7 @@
 * 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 @@
 * 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.
--- a/src/render/nds/SDL_ndsrender.c	Fri Mar 25 14:45:04 2011 -0700
+++ b/src/render/nds/SDL_ndsrender.c	Sat Mar 26 21:26:05 2011 -0700
@@ -131,7 +131,7 @@
     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 @@
 {
     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,
@@ -185,7 +183,24 @@
 
 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 @@
 	}
 
 	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 @@
         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 @@
 	renderer->RenderDrawLines = NDS_RenderDrawLines;
 	renderer->RenderFillRects = NDS_RenderFillRects;
 
+	renderer->driverdata = data;
+
     return renderer;
 }
 
@@ -353,7 +348,7 @@
     .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,
 		},
--- a/src/timer/nds/SDL_systimer.c	Fri Mar 25 14:45:04 2011 -0700
+++ b/src/timer/nds/SDL_systimer.c	Sat Mar 26 21:26:05 2011 -0700
@@ -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
--- a/src/video/SDL_surface.c	Fri Mar 25 14:45:04 2011 -0700
+++ b/src/video/SDL_surface.c	Sat Mar 26 21:26:05 2011 -0700
@@ -866,7 +866,7 @@
                          Uint32 flags)
 {
     SDL_PixelFormat *fmt;
-    SDL_Surface *convert;
+    SDL_Surface *convert = NULL;
 
     fmt = SDL_AllocFormat(pixel_format);
     if (fmt) {
--- a/src/video/nds/SDL_ndsevents.c	Fri Mar 25 14:45:04 2011 -0700
+++ b/src/video/nds/SDL_ndsevents.c	Sat Mar 26 21:26:05 2011 -0700
@@ -44,7 +44,9 @@
         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);
     }
 }
--- a/src/video/nds/SDL_ndsvideo.c	Fri Mar 25 14:45:04 2011 -0700
+++ b/src/video/nds/SDL_ndsvideo.c	Sat Mar 26 21:26:05 2011 -0700
@@ -249,6 +249,8 @@
 {
 	display->driverdata = mode->driverdata;
 
+    powerOn(POWER_ALL_2D);
+
 #ifdef USE_HW_RENDERER
 
 	videoSetMode(MODE_5_3D);
@@ -256,17 +258,13 @@
 
 	/* 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 @@
 	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 @@
 
 	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 @@
     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 @@
     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: */