NDS update
authorSam Lantinga <slouken@libsdl.org>
Sat, 26 Mar 2011 21:26:05 -0700
changeset 55150fcf231a6e74
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
     1.1 --- a/Makefile.ds	Fri Mar 25 14:45:04 2011 -0700
     1.2 +++ b/Makefile.ds	Sat Mar 26 21:26:05 2011 -0700
     1.3 @@ -17,7 +17,7 @@
     1.4  #---------------------------------------------------------------------------------
     1.5  TARGET		:=	$(shell basename $(CURDIR))
     1.6  BUILD		:=	src
     1.7 -SOURCES		:=	source
     1.8 +SOURCES		:=	src
     1.9  DATA		:=	data
    1.10  INCLUDES	:=	include
    1.11  
    1.12 @@ -53,7 +53,7 @@
    1.13  # list of directories containing libraries, this must be the top level containing
    1.14  # include and lib
    1.15  #---------------------------------------------------------------------------------
    1.16 -LIBDIRS	:=	$(LIBNDS)
    1.17 +LIBDIRS	:=	$(LIBNDS) $(PORTLIBS)
    1.18  
    1.19  #---------------------------------------------------------------------------------
    1.20  # no real need to edit anything past this point unless you need to add additional
    1.21 @@ -171,7 +171,8 @@
    1.22  
    1.23  export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
    1.24  			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
    1.25 -			-I$(CURDIR)/$(BUILD)
    1.26 +			-I$(CURDIR)/$(BUILD) \
    1.27 +			-I$(PORTLIBS)/include/SDL
    1.28  
    1.29  .PHONY: $(BUILD) clean all
    1.30  
    1.31 @@ -186,15 +187,15 @@
    1.32  	@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.ds -s
    1.33  
    1.34  install: $(BUILD)
    1.35 -	@cp $(OUTPUT) $(DEVKITPRO)/libnds/lib/
    1.36 -	@mkdir -p $(DEVKITPRO)/libnds/include/SDL/
    1.37 -	@cp include/*.h $(DEVKITPRO)/libnds/include/SDL/
    1.38 +	@mkdir -p $(PORTLIBS)/include/SDL/
    1.39 +	@rsync -a $(OUTPUT) $(PORTLIBS)/lib/
    1.40 +	@rsync -a include/*.h $(PORTLIBS)/include/SDL/
    1.41  
    1.42  nds_test:
    1.43 -	$(MAKE) -C test/nds-test-progs
    1.44 +	$(MAKE) -C test/nds-test-progs -s
    1.45  
    1.46  tags:
    1.47 -	etags $(SRCS)
    1.48 +	cd $(SOURCES); etags $(CFILES)
    1.49  
    1.50  # This file must be compiled with the ARM instruction set, not
    1.51  # thumb. Use devkitpro way of doing things.
    1.52 @@ -206,6 +207,8 @@
    1.53  clean:
    1.54  	@echo clean ...
    1.55  	@cd src; rm -fr $(OFILES) $(OFILES:.o=.d) lib
    1.56 +	@rm -f $(OUTPUT)
    1.57 +	@make -C test/nds-test-progs -s clean
    1.58  
    1.59  #---------------------------------------------------------------------------------
    1.60  else
     2.1 --- a/README.ds	Fri Mar 25 14:45:04 2011 -0700
     2.2 +++ b/README.ds	Sat Mar 26 21:26:05 2011 -0700
     2.3 @@ -17,9 +17,9 @@
     2.4  After setting the devkitpro environment, cd into your SDL directory and type:
     2.5    make -f Makefile.ds
     2.6  
     2.7 -This will compile and install the library and headers into the proper libnds
     2.8 -directories. Additionnaly it will compile several tests that you can run
     2.9 -either on the DS or with desmume. For instance:
    2.10 +This will compile and install the library and headers into the
    2.11 +devkitpro's portlibs directory. Additionnaly it will compile several
    2.12 +tests that you can run either on the DS or with desmume. For instance:
    2.13    desmume test/nds-test-progs/general/general.nds
    2.14  
    2.15  -Notes-
    2.16 @@ -27,7 +27,7 @@
    2.17  * The port is very basic and incomplete:
    2.18    - SDL currently has to be compiled for either framebuffer mode or render mode.
    2.19       See USE_HW_RENDERER in Makefile.ds.
    2.20 -  - some optionnal renderer functions are not implemented.
    2.21 +  - some optional renderer functions are not implemented.
    2.22  
    2.23  -Limitations-
    2.24  * in hardware renderer mode, don't load too many textures. The internal format is
    2.25 @@ -36,4 +36,24 @@
    2.26  * the screen size is 256 x 384. Anything else won't work.
    2.27  * there is no 8 bits/pixel mode because SDL 1.3 doesn't support palettes.
    2.28  
    2.29 +-Joystick mapping-
    2.30 +The Joystick presented to SDL has 2 axes and 8 buttons
    2.31  
    2.32 + KEY      | Code
    2.33 +  A       |   0
    2.34 +  B       |   1
    2.35 +  X       |   2
    2.36 +  Y       |   3
    2.37 +  L       |   4
    2.38 +  R       |   5
    2.39 +  select  |   6
    2.40 +  start   |   7
    2.41 +
    2.42 + Left-right is axe 0.
    2.43 + Up-down is axe 1.
    2.44 +
    2.45 +-Mouse mapping-
    2.46 +todo
    2.47 +
    2.48 +-Examples-
    2.49 +Due to memory limitations, to be able to successfully run the testscale example, sample.bmp must be resized to 256x105.
     3.1 --- a/src/render/nds/SDL_ndsrender.c	Fri Mar 25 14:45:04 2011 -0700
     3.2 +++ b/src/render/nds/SDL_ndsrender.c	Sat Mar 26 21:26:05 2011 -0700
     3.3 @@ -131,7 +131,7 @@
     3.4      SDL_free(txdat);
     3.5  }
     3.6  
     3.7 -/* size is no more than 1024. */
     3.8 +/* size is no more than 512. */
     3.9  static int get_gltexture_size(unsigned int size)
    3.10  {
    3.11  	if (size > 256)
    3.12 @@ -155,12 +155,10 @@
    3.13  {
    3.14      NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
    3.15  
    3.16 -	SDL_Log("enter %s\n", __func__);
    3.17 -
    3.18  	glLoadTileSet(txdat->image,
    3.19  				  rect->w, rect->h,
    3.20  				  rect->w, rect->h,
    3.21 -				  GL_RGBA,
    3.22 +				  texture->format == SDL_PIXELFORMAT_ABGR1555 ? GL_RGBA : GL_RGB,
    3.23  				  get_gltexture_size(rect->w),
    3.24  				  get_gltexture_size(rect->h),
    3.25  				  TEXGEN_OFF, 0, NULL,
    3.26 @@ -185,7 +183,24 @@
    3.27  
    3.28  static int NDS_RenderClear(SDL_Renderer *renderer)
    3.29  {
    3.30 +    glClearColor(renderer->r >> 3,
    3.31 +                 renderer->g >> 3,
    3.32 +                 renderer->b >> 3,
    3.33 +                 renderer->a >> 3);
    3.34 +
    3.35 +	return 0;
    3.36 +}
    3.37 +
    3.38 +static void NDS_RenderPresent(SDL_Renderer * renderer)
    3.39 +{
    3.40      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
    3.41 +	static int frame =0;
    3.42 +
    3.43 +	glEnd2D();
    3.44 +		
    3.45 +	glFlush(0);
    3.46 +
    3.47 +	swiWaitForVBlank();
    3.48  
    3.49  	/* wait for capture unit to be ready */
    3.50  	while(REG_DISPCAPCNT & DCAP_ENABLE);
    3.51 @@ -205,22 +220,6 @@
    3.52  	}
    3.53  
    3.54  	glBegin2D();
    3.55 -
    3.56 -    glClearColor(renderer->r >> 3,
    3.57 -                 renderer->g >> 3,
    3.58 -                 renderer->b >> 3,
    3.59 -                 renderer->a >> 3);
    3.60 -
    3.61 -	return 0;
    3.62 -}
    3.63 -
    3.64 -static void NDS_RenderPresent(SDL_Renderer * renderer)
    3.65 -{
    3.66 -//	SDL_Log("enter %s\n", __func__);
    3.67 -
    3.68 -	glEnd2D();
    3.69 -		
    3.70 -	glFlush( 0 );
    3.71  }
    3.72  
    3.73  static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points,
    3.74 @@ -323,14 +322,8 @@
    3.75          return NULL;
    3.76      }
    3.77  
    3.78 -    renderer->info.name = NDS_RenderDriver.info.name;
    3.79 -    renderer->info.flags = 0;
    3.80 -    renderer->info.num_texture_formats = NDS_RenderDriver.info.num_texture_formats;
    3.81 -    SDL_memcpy(renderer->info.texture_formats,
    3.82 -			   NDS_RenderDriver.info.texture_formats,
    3.83 -               sizeof(renderer->info.texture_formats));
    3.84 -    renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width;
    3.85 -    renderer->info.max_texture_height = NDS_RenderDriver.info.max_texture_height;
    3.86 +    renderer->info = NDS_RenderDriver.info;
    3.87 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
    3.88  
    3.89  	renderer->UpdateViewport = NDS_UpdateViewport;
    3.90      renderer->CreateTexture = NDS_CreateTexture;
    3.91 @@ -345,6 +338,8 @@
    3.92  	renderer->RenderDrawLines = NDS_RenderDrawLines;
    3.93  	renderer->RenderFillRects = NDS_RenderFillRects;
    3.94  
    3.95 +	renderer->driverdata = data;
    3.96 +
    3.97      return renderer;
    3.98  }
    3.99  
   3.100 @@ -353,7 +348,7 @@
   3.101      .info = {
   3.102  		.name = "nds",
   3.103  		.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC,
   3.104 -		.num_texture_formats = 1,
   3.105 +		.num_texture_formats = 2,
   3.106  		.texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555,
   3.107  							 [1] = SDL_PIXELFORMAT_BGR555,
   3.108  		},
     4.1 --- a/src/timer/nds/SDL_systimer.c	Fri Mar 25 14:45:04 2011 -0700
     4.2 +++ b/src/timer/nds/SDL_systimer.c	Sat Mar 26 21:26:05 2011 -0700
     4.3 @@ -28,7 +28,7 @@
     4.4  
     4.5  #include "SDL_timer.h"
     4.6  
     4.7 -/* Will wrap afetr 49 days. Shouldn't be an issue. */
     4.8 +/* Will wrap after 49 days. Shouldn't be an issue. */
     4.9  static volatile Uint32 timer_ticks;
    4.10  
    4.11  static void
     5.1 --- a/src/video/SDL_surface.c	Fri Mar 25 14:45:04 2011 -0700
     5.2 +++ b/src/video/SDL_surface.c	Sat Mar 26 21:26:05 2011 -0700
     5.3 @@ -866,7 +866,7 @@
     5.4                           Uint32 flags)
     5.5  {
     5.6      SDL_PixelFormat *fmt;
     5.7 -    SDL_Surface *convert;
     5.8 +    SDL_Surface *convert = NULL;
     5.9  
    5.10      fmt = SDL_AllocFormat(pixel_format);
    5.11      if (fmt) {
     6.1 --- a/src/video/nds/SDL_ndsevents.c	Fri Mar 25 14:45:04 2011 -0700
     6.2 +++ b/src/video/nds/SDL_ndsevents.c	Sat Mar 26 21:26:05 2011 -0700
     6.3 @@ -44,7 +44,9 @@
     6.4          SDL_SendMouseButton(0, SDL_RELEASED, 0);
     6.5      }
     6.6      if (keysHeld() & KEY_TOUCH) {
     6.7 -        touchPosition t = touchReadXY();
     6.8 +		touchPosition t;
     6.9 +
    6.10 +		touchRead(&t);
    6.11          SDL_SendMouseMotion(0, 0, t.px, t.py);
    6.12      }
    6.13  }
     7.1 --- a/src/video/nds/SDL_ndsvideo.c	Fri Mar 25 14:45:04 2011 -0700
     7.2 +++ b/src/video/nds/SDL_ndsvideo.c	Sat Mar 26 21:26:05 2011 -0700
     7.3 @@ -249,6 +249,8 @@
     7.4  {
     7.5  	display->driverdata = mode->driverdata;
     7.6  
     7.7 +    powerOn(POWER_ALL_2D);
     7.8 +
     7.9  #ifdef USE_HW_RENDERER
    7.10  
    7.11  	videoSetMode(MODE_5_3D);
    7.12 @@ -256,17 +258,13 @@
    7.13  
    7.14  	/* initialize gl2d */
    7.15  	glScreen2D();
    7.16 +	glBegin2D();
    7.17  	
    7.18 -    vramSetBankA(VRAM_A_TEXTURE);
    7.19 +	vramSetBankA(VRAM_A_TEXTURE);
    7.20  	vramSetBankB(VRAM_B_TEXTURE );
    7.21 -    vramSetBankC(VRAM_C_SUB_BG_0x06200000);
    7.22 +	vramSetBankC(VRAM_C_SUB_BG_0x06200000);
    7.23  	vramSetBankE(VRAM_E_TEX_PALETTE);
    7.24  
    7.25 -    powerOn(POWER_ALL_2D);
    7.26 -
    7.27 -    irqInit();
    7.28 -    irqEnable(IRQ_VBLANK);
    7.29 -
    7.30      // sub sprites hold the bottom image when 3D directed to top
    7.31      initSubSprites();
    7.32   
    7.33 @@ -279,16 +277,11 @@
    7.34  	videoSetMode(MODE_5_2D);
    7.35  	videoSetModeSub(MODE_5_2D);
    7.36  
    7.37 -    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
    7.38 +	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
    7.39  	vramSetBankB(VRAM_B_TEXTURE );
    7.40 -    vramSetBankC(VRAM_C_SUB_BG_0x06200000);
    7.41 +	vramSetBankC(VRAM_C_SUB_BG_0x06200000);
    7.42  	vramSetBankE(VRAM_E_TEX_PALETTE);
    7.43  
    7.44 -    powerOn(POWER_ALL_2D);
    7.45 -
    7.46 -    irqInit();
    7.47 -    irqEnable(IRQ_VBLANK);
    7.48 -
    7.49  #endif
    7.50  
    7.51      return 0;
    7.52 @@ -311,7 +304,7 @@
    7.53  
    7.54  	SDL_zero(mode);
    7.55  
    7.56 -    mode.format = SDL_PIXELFORMAT_UNKNOWN; // shoud be SDL_PIXELFORMAT_ABGR1555;
    7.57 +    mode.format = SDL_PIXELFORMAT_UNKNOWN; // should be SDL_PIXELFORMAT_ABGR1555;
    7.58      mode.w = SCREEN_WIDTH;
    7.59      mode.h = 2*SCREEN_HEIGHT+SCREEN_GAP;
    7.60      mode.refresh_rate = 60;
    7.61 @@ -379,8 +372,8 @@
    7.62      device->PumpEvents = NDS_PumpEvents;
    7.63      device->free = NDS_DeleteDevice;
    7.64  
    7.65 -	/* Set the debug output. Use only for under an emulator. Will crash the DS. */
    7.66 -#if 1
    7.67 +	/* Set the debug output. Use only under an emulator. Will crash the DS. */
    7.68 +#if 0
    7.69  	SDL_LogSetOutputFunction(NDS_DebugOutput, NULL);
    7.70  #endif
    7.71  
    7.72 @@ -392,4 +385,14 @@
    7.73      NDS_Available, NDS_CreateDevice
    7.74  };
    7.75  
    7.76 +double SDLCALL SDL_pow(double x, double y)
    7.77 +{
    7.78 +	static int once = 1;
    7.79 +	if (once) {
    7.80 +		SDL_Log("SDL_pow called but not supported on this platform");
    7.81 +		once = 0;
    7.82 +	}
    7.83 +	return 0;
    7.84 +}
    7.85 +
    7.86  /* vi: set ts=4 sw=4 expandtab: */