Cleaned up and added joypad support from 1.2.9 NDS port. Also some minor video driver bugfixes. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Thu, 19 Jun 2008 07:11:35 +0000
branchgsoc2008_nds
changeset 267324a6b3588eac
parent 2672 74ac057679d5
child 2674 f1d07ba2e275
Cleaned up and added joypad support from 1.2.9 NDS port. Also some minor video driver bugfixes.
Makefile.ds
include/SDL_config_nintendods.h
include/SDL_pixels.h
src/joystick/nds/SDL_sysjoystick.c
src/video/SDL_pixels.c
src/video/dummy/SDL_nullrender.c
src/video/nds/SDL_ndsrender.c
src/video/nds/SDL_ndsvideo.c
     1.1 --- a/Makefile.ds	Tue Jun 17 08:26:36 2008 +0000
     1.2 +++ b/Makefile.ds	Thu Jun 19 07:11:35 2008 +0000
     1.3 @@ -49,7 +49,7 @@
     1.4  src/events/SDL_quit.c \
     1.5  src/events/SDL_windowevents.c \
     1.6  src/file/SDL_rwops.c \
     1.7 -src/joystick/dummy/SDL_sysjoystick.c \
     1.8 +src/joystick/nds/SDL_sysjoystick.c \
     1.9  src/joystick/SDL_joystick.c \
    1.10  src/stdlib/SDL_getenv.c \
    1.11  src/stdlib/SDL_iconv.c \
    1.12 @@ -64,9 +64,6 @@
    1.13  src/thread/nds/SDL_systhread.c \
    1.14  src/timer/dummy/SDL_systimer.c \
    1.15  src/timer/SDL_timer.c \
    1.16 -src/video/dummy/SDL_nullevents.c \
    1.17 -src/video/dummy/SDL_nullrender.c \
    1.18 -src/video/dummy/SDL_nullvideo.c \
    1.19  src/video/nds/SDL_ndsevents.c \
    1.20  src/video/nds/SDL_ndsrender.c \
    1.21  src/video/nds/SDL_ndsvideo.c \
    1.22 @@ -130,6 +127,8 @@
    1.23  
    1.24  install: $(TARGET)
    1.25  	@cp libSDL.a $(DEVKITPRO)/libnds/lib/
    1.26 +	@mkdir -p $(DEVKITPRO)/libnds/include/SDL/
    1.27 +	@cp include/*.h $(DEVKITPRO)/libnds/include/SDL/
    1.28  
    1.29  copy_config:
    1.30  	@cp include/SDL_config.h.default include/SDL_config.h
     2.1 --- a/include/SDL_config_nintendods.h	Tue Jun 17 08:26:36 2008 +0000
     2.2 +++ b/include/SDL_config_nintendods.h	Thu Jun 19 07:11:35 2008 +0000
     2.3 @@ -98,7 +98,7 @@
     2.4  #define SDL_CDROM_DISABLED	1
     2.5  
     2.6  /* Enable various input drivers */
     2.7 -#define SDL_JOYSTICK_DISABLED	1
     2.8 +#define SDL_JOYSTICK_NDS	1
     2.9  
    2.10  /* DS has no dynamic linking afaik */
    2.11  #define SDL_LOADSO_DISABLED	1
     3.1 --- a/include/SDL_pixels.h	Tue Jun 17 08:26:36 2008 +0000
     3.2 +++ b/include/SDL_pixels.h	Thu Jun 19 07:11:35 2008 +0000
     3.3 @@ -146,12 +146,18 @@
     3.4      SDL_PIXELFORMAT_RGB555 =
     3.5          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
     3.6                                 SDL_PACKEDLAYOUT_1555, 15, 2),
     3.7 +    SDL_PIXELFORMAT_BGR555 =
     3.8 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
     3.9 +                               SDL_PACKEDLAYOUT_1555, 15, 2),
    3.10      SDL_PIXELFORMAT_ARGB4444 =
    3.11          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
    3.12                                 SDL_PACKEDLAYOUT_4444, 16, 2),
    3.13      SDL_PIXELFORMAT_ARGB1555 =
    3.14          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
    3.15                                 SDL_PACKEDLAYOUT_1555, 16, 2),
    3.16 +    SDL_PIXELFORMAT_ABGR1555 =
    3.17 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
    3.18 +                               SDL_PACKEDLAYOUT_1555, 16, 2),
    3.19      SDL_PIXELFORMAT_RGB565 =
    3.20          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
    3.21                                 SDL_PACKEDLAYOUT_565, 16, 2),
     4.1 --- a/src/joystick/nds/SDL_sysjoystick.c	Tue Jun 17 08:26:36 2008 +0000
     4.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Thu Jun 19 07:11:35 2008 +0000
     4.3 @@ -25,12 +25,17 @@
     4.4      "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
     4.5  #endif
     4.6  
     4.7 +#include "SDL_config.h"
     4.8 +
     4.9 +#ifdef SDL_JOYSTICK_NDS
    4.10 +
    4.11  /* This is the system specific header for the SDL joystick API */
    4.12  #include <nds.h>
    4.13  //#include <nds/registers_alt.h>
    4.14  #include <stdio.h>              /* For the definition of NULL */
    4.15  
    4.16  #include "SDL_error.h"
    4.17 +#include "SDL_events.h"
    4.18  #include "SDL_joystick.h"
    4.19  #include "SDL_sysjoystick.h"
    4.20  #include "SDL_joystick_c.h"
    4.21 @@ -46,9 +51,8 @@
    4.22  SDL_SYS_JoystickInit(void)
    4.23  {
    4.24      SDL_numjoysticks = 1;
    4.25 -    
    4.26 -        //keysInit();
    4.27 -        return (1);
    4.28 +    /* keysInit();*/
    4.29 +    return (1);
    4.30  }
    4.31  
    4.32  /* Function to get the device-dependent name of a joystick */
    4.33 @@ -82,150 +86,71 @@
    4.34   * but instead should call SDL_PrivateJoystick*() to deliver events
    4.35   * and update joystick device state.
    4.36   */
    4.37 -int prevbutton = 0;
    4.38 -int prevkey = 0;
    4.39 -
    4.40 -int dc = NULL;
    4.41 -int ldc = 0;
    4.42 -u32 keysd, keysu = NULL;
    4.43  void
    4.44  SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
    4.45  {
    4.46 -    
    4.47 -        //dc=keysd;
    4.48 -        //if (dc != NULL)
    4.49 -        //{
    4.50 -        //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
    4.51 -        //swiWaitForVBlank();
    4.52 -        //scanKeys();
    4.53 -        //keysd = keysDown(); 
    4.54 -        //keysu = keysUp();
    4.55 -        //ldc=keysd;
    4.56 -        
    4.57 -        //}
    4.58 -        /*if (prevkey !=NULL && prevbutton !=NULL)
    4.59 -           {
    4.60 -           scanKeys();
    4.61 -           }
    4.62 -         */ 
    4.63 -        
    4.64 -        //scanKeys();
    4.65 -        keysd = keysDown();
    4.66 -    
    4.67 keysu = keysUp();
    4.68 -    
    4.69 
    4.70 short ax = 0, v = 0, h = 0;
    4.71 +    u32 keysd, keysu;
    4.72 +    int magnitude = 16384;
    4.73 +    scanKeys();
    4.74 +    keysd = keysDown();
    4.75 +    keysu = keysUp();
    4.76 +
    4.77      if ((keysd & KEY_UP)) {
    4.78 -        ax = 1;
    4.79 -        v = -10;
    4.80 -        SDL_PrivateJoystickAxis(joystick, ax, v);
    4.81 -        prevkey = KEY_UP;
    4.82 -    }                           //fprintf(stderr,"KEY_UP\n");}
    4.83 +        SDL_PrivateJoystickAxis(joystick, 1, -magnitude);
    4.84 +    }
    4.85      if ((keysd & KEY_DOWN)) {
    4.86 -        ax = 1;
    4.87 -        v = 10;
    4.88 -        SDL_PrivateJoystickAxis(joystick, ax, v);
    4.89 -        prevkey = KEY_DOWN;
    4.90 -    }                           //fprintf(stderr,"KEY_DOWN\n");}
    4.91 +        SDL_PrivateJoystickAxis(joystick, 1, magnitude);
    4.92 +    }
    4.93      if ((keysd & KEY_LEFT)) {
    4.94 -        ax = 0;
    4.95 -        h = -10;
    4.96 -        SDL_PrivateJoystickAxis(joystick, ax, h);
    4.97 -        prevkey = KEY_LEFT;
    4.98 -    }                           //fprintf(stderr,"KEY_LEFT\n");}
    4.99 +        SDL_PrivateJoystickAxis(joystick, 0, -magnitude);
   4.100 +    }
   4.101      if ((keysd & KEY_RIGHT)) {
   4.102 -        ax = 0;
   4.103 -        h = 10;
   4.104 -        SDL_PrivateJoystickAxis(joystick, ax, h);
   4.105 -        prevkey = KEY_RIGHT;
   4.106 -    }                           //fprintf(stderr,"KEY_RIGHT\n");}
   4.107 -    
   4.108 if ((keysu & KEY_UP)) {
   4.109 -        ax = 1;
   4.110 -        v = 0;
   4.111 -        SDL_PrivateJoystickAxis(joystick, ax, v);
   4.112 -        prevkey = NULL;
   4.113 -    }                           //fprintf(stderr,"KEY_UP\n");}
   4.114 -    if ((keysu & KEY_DOWN)) {
   4.115 -        ax = 1;
   4.116 -        v = 0;
   4.117 -        SDL_PrivateJoystickAxis(joystick, ax, v);
   4.118 -        prevkey = NULL;
   4.119 -    }                           //fprintf(stderr,"KEY_DOWN\n");}
   4.120 -    if ((keysu & KEY_LEFT)) {
   4.121 -        ax = 0;
   4.122 -        h = 0;
   4.123 -        SDL_PrivateJoystickAxis(joystick, ax, h);
   4.124 -        prevkey = NULL;
   4.125 -    }                           //fprintf(stderr,"KEY_LEFT\n");}
   4.126 -    if ((keysu & KEY_RIGHT)) {
   4.127 -        ax = 0;
   4.128 -        h = 0;
   4.129 -        SDL_PrivateJoystickAxis(joystick, ax, h);
   4.130 -        prevkey = NULL;
   4.131 -    }                           //fprintf(stderr,"KEY_RIGHT\n");}
   4.132 -    
   4.133 if ((keysd & KEY_A)) {
   4.134 +        SDL_PrivateJoystickAxis(joystick, 0, magnitude);
   4.135 +    }
   4.136 +
   4.137     if ((keysu & (KEY_UP|KEY_DOWN))) {
   4.138 +        SDL_PrivateJoystickAxis(joystick, 1, 0);
   4.139 +    }
   4.140 +    if ((keysu & (KEY_LEFT|KEY_RIGHT))) {
   4.141 +        SDL_PrivateJoystickAxis(joystick, 0, 0);
   4.142 +    }
   4.143 +
   4.144     if ((keysd & KEY_A)) {
   4.145          SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
   4.146 -        prevbutton = KEY_A;
   4.147 +    }
   4.148     if ((keysd & KEY_B)) {
   4.149 +        SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
   4.150 +    }
   4.151     if ((keysd & KEY_X)) {
   4.152 +        SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
   4.153 +    }
   4.154     if ((keysd & KEY_Y)) {
   4.155 +        SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
   4.156      }
   4.157 -    
   4.158 if ((keysd & KEY_B)) {
   4.159 -        SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
   4.160 -        prevbutton = KEY_B;
   4.161 +
   4.162     if ((keysd & KEY_L)) {
   4.163 +        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
   4.164 +    }
   4.165     if ((keysd & KEY_R)) {
   4.166 +        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
   4.167      }
   4.168 -    
   4.169 if ((keysd & KEY_X)) {
   4.170 -        SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
   4.171 -        prevbutton = KEY_X;
   4.172 +
   4.173     if ((keysd & KEY_SELECT)) {
   4.174 +        SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
   4.175 +    }
   4.176     if ((keysd & KEY_START)) {
   4.177 +        SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
   4.178      }
   4.179 -    
   4.180 if ((keysd & KEY_Y)) {
   4.181 -        SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
   4.182 -        prevbutton = KEY_Y;
   4.183 +
   4.184     if ((keysu & KEY_A)) {
   4.185 +        SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
   4.186 +    }
   4.187     if ((keysu & KEY_B)) {
   4.188 +        SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
   4.189 +    }
   4.190     if ((keysu & KEY_X)) {
   4.191 +        SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
   4.192 +    }
   4.193     if ((keysu & KEY_Y)) {
   4.194 +        SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
   4.195      }
   4.196 -    
   4.197 if ((keysd & KEY_SELECT)) {
   4.198 -        SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
   4.199 -        prevbutton = KEY_SELECT;
   4.200 +
   4.201     if ((keysu & KEY_L)) {
   4.202 +        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
   4.203 +    }
   4.204     if ((keysu & KEY_R)) {
   4.205 +        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
   4.206      }
   4.207 -    
   4.208 if ((keysd & KEY_START)) {
   4.209 -        SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
   4.210 -        prevbutton = KEY_START;
   4.211 -    }
   4.212 -    
   4.213 if ((keysd & KEY_L)) {
   4.214 -        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
   4.215 -        prevbutton = KEY_L;
   4.216 -    }
   4.217 -    
   4.218 if ((keysd & KEY_R)) {
   4.219 -        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
   4.220 -        prevbutton = KEY_R;
   4.221 -    }
   4.222 -    
   4.223 
   4.224 if ((keysu & KEY_A)) {
   4.225 -        SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
   4.226 -        prevbutton = NULL;
   4.227 -    }
   4.228 -    
   4.229 if ((keysu & KEY_B)) {
   4.230 -        SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
   4.231 -        prevbutton = NULL;
   4.232 -    }
   4.233 -    
   4.234 if ((keysu & KEY_X)) {
   4.235 -        SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
   4.236 -        prevbutton = NULL;
   4.237 -    }
   4.238 -    
   4.239 if ((keysu & KEY_Y)) {
   4.240 -        SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
   4.241 -        prevbutton = NULL;
   4.242 -    }
   4.243 -    
   4.244 if ((keysu & KEY_SELECT)) {
   4.245 +
   4.246     if ((keysu & KEY_SELECT)) {
   4.247          SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
   4.248 -        prevbutton = NULL;
   4.249 -    }
   4.250 -    
   4.251 if ((keysu & KEY_START)) {
   4.252 +    }
   4.253     if ((keysu & KEY_START)) {
   4.254          SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
   4.255 -        prevbutton = NULL;
   4.256 -    }
   4.257 -    
   4.258 if ((keysu & KEY_L)) {
   4.259 -        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
   4.260 -        prevbutton = NULL;
   4.261 -    }
   4.262 -    
   4.263 if ((keysu & KEY_R)) {
   4.264 -        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
   4.265 -        prevbutton = NULL;
   4.266 -    }
   4.267 -
   4.268 
   4.269 }
   4.270 +    }
   4.271 }
   4.272  
   4.273  /* Function to close a joystick after use */
   4.274  void
   4.275 @@ -238,3 +163,5 @@
   4.276  SDL_SYS_JoystickQuit(void)
   4.277  {
   4.278  }
   4.279 +#endif /* SDL_JOYSTICK_NDS */
   4.280 +
     5.1 --- a/src/video/SDL_pixels.c	Tue Jun 17 08:26:36 2008 +0000
     5.2 +++ b/src/video/SDL_pixels.c	Thu Jun 19 07:11:35 2008 +0000
     5.3 @@ -168,12 +168,16 @@
     5.4          break;
     5.5      case 15:
     5.6          switch (Rmask) {
     5.7 +        case 0x001F:
     5.8 +            return SDL_PIXELFORMAT_BGR555;
     5.9          case 0x7C00:
    5.10              return SDL_PIXELFORMAT_RGB555;
    5.11          }
    5.12          break;
    5.13      case 16:
    5.14          switch (Rmask) {
    5.15 +        case 0x001F:
    5.16 +            return SDL_PIXELFORMAT_ABGR1555;
    5.17          case 0x0F00:
    5.18              return SDL_PIXELFORMAT_ARGB4444;
    5.19          case 0x7C00:
     6.1 --- a/src/video/dummy/SDL_nullrender.c	Tue Jun 17 08:26:36 2008 +0000
     6.2 +++ b/src/video/dummy/SDL_nullrender.c	Thu Jun 19 07:11:35 2008 +0000
     6.3 @@ -181,11 +181,11 @@
     6.4          SDL_SaveBMP(data->screens[data->current_screen], file);
     6.5      }
     6.6      /*{
     6.7 -        int i;
     6.8 -        for (i = 0; i < 256 * 192; ++i)
     6.9 -            ((Uint16 *)0x6800000)[i]
    6.10 -                = ((Uint16 *)(data->screens[data->current_screen]->pixels))[i];
    6.11 -    }*/
    6.12 +       int i;
    6.13 +       for (i = 0; i < 256 * 192; ++i)
    6.14 +       ((Uint16 *)0x6800000)[i]
    6.15 +       = ((Uint16 *)(data->screens[data->current_screen]->pixels))[i];
    6.16 +       } */
    6.17  
    6.18      /* Update the flipping chain, if any */
    6.19      if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
     7.1 --- a/src/video/nds/SDL_ndsrender.c	Tue Jun 17 08:26:36 2008 +0000
     7.2 +++ b/src/video/nds/SDL_ndsrender.c	Thu Jun 19 07:11:35 2008 +0000
     7.3 @@ -68,8 +68,9 @@
     7.4   */
     7.5  
     7.6  u16
     7.7 -sdlds_rgb2bgr(u16 c) {
     7.8 -/* hack to get the colors right until I actually add BGR555 to the headers */
     7.9 +sdlds_rgb2bgr(u16 c)
    7.10 +{
    7.11 +/* hack to get the proper colors until I actually get BGR555 to work right */
    7.12      u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b;
    7.13      r = (c & Rmask) >> 10;
    7.14      b = (c & Bmask) << 10;
    7.15 @@ -79,27 +80,29 @@
    7.16  void
    7.17  sdlds_surf2vram(SDL_Surface * s)
    7.18  {
    7.19 -
    7.20 -    int i;
    7.21 -	/*for (i = 0; i < 30; ++i) swiWaitForVBlank();*/
    7.22 -    for (i = 0; i < 256 * 192; ++i) {
    7.23 -        ((u16 *) VRAM_A)[i] = sdlds_rgb2bgr(((u16 *) (s->pixels))[i+160]);
    7.24 +    if (s->w == 256) {
    7.25 +        dmaCopy((u8 *) (s->pixels) + 156 * sizeof(u16),
    7.26 +                VRAM_A, 256 * 192 * sizeof(u16));
    7.27      }
    7.28  }
    7.29  
    7.30  void
    7.31 -sdlds_print_pixfmt_info(SDL_PixelFormat *f) {
    7.32 -	if(!f) return;
    7.33 -	printf("bpp: %d\nRGBA: %x %x %x %x\n",
    7.34 -	       f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
    7.35 +sdlds_print_pixfmt_info(SDL_PixelFormat * f)
    7.36 +{
    7.37 +    if (!f)
    7.38 +        return;
    7.39 +    printf("bpp: %d\nRGBA: %x %x %x %x\n",
    7.40 +           f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
    7.41  }
    7.42  
    7.43  void
    7.44 -sdlds_print_surface_info(SDL_Surface *s) {
    7.45 -	if(!s) return;
    7.46 -	printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
    7.47 -	       s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
    7.48 -	sdlds_print_pixfmt_info(s->format);
    7.49 +sdlds_print_surface_info(SDL_Surface * s)
    7.50 +{
    7.51 +    if (!s)
    7.52 +        return;
    7.53 +    printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
    7.54 +           s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
    7.55 +    sdlds_print_pixfmt_info(s->format);
    7.56  }
    7.57  
    7.58  
    7.59 @@ -113,11 +116,10 @@
    7.60      SDL_NDS_RenderData *data;
    7.61      int i, n;
    7.62      int bpp = 15;
    7.63 -/*/
    7.64 -    Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
    7.65 -/*/
    7.66 +    Uint32 Rmask, Gmask, Bmask, Amask;
    7.67 +/*  Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
    7.68      Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
    7.69 -//*/
    7.70 +*/
    7.71  
    7.72  #if 0
    7.73      printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
    7.74 @@ -125,12 +127,12 @@
    7.75             window->x, window->y, window->w, window->h);
    7.76  #endif
    7.77  
    7.78 -    /* hard coded this to ARGB1555 for now
    7.79 -       if (!SDL_PixelFormatEnumToMasks
    7.80 -       (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
    7.81 -       SDL_SetError("Unknown display format");
    7.82 -       return NULL;
    7.83 -       } */
    7.84 +    /* hard coded this to BGR555 for now */
    7.85 +    if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
    7.86 +                                    &Rmask, &Gmask, &Bmask, &Amask)) {
    7.87 +        SDL_SetError("Unknown display format");
    7.88 +        return NULL;
    7.89 +    }
    7.90  
    7.91      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
    7.92      if (!renderer) {
    7.93 @@ -168,12 +170,14 @@
    7.94      }
    7.95      for (i = 0; i < n; ++i) {
    7.96          data->screens[i] =
    7.97 -            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask);
    7.98 +            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
    7.99 +                                 Amask);
   7.100          if (!data->screens[i]) {
   7.101              SDL_NDS_DestroyRenderer(renderer);
   7.102              return NULL;
   7.103          }
   7.104          SDL_SetSurfacePalette(data->screens[i], display->palette);
   7.105 +        sdlds_print_surface_info(data->screens[i]);
   7.106      }
   7.107  
   7.108      data->current_screen = 0;
   7.109 @@ -227,7 +231,7 @@
   7.110          SDL_Rect real_srcrect = *srcrect;
   7.111          SDL_Rect real_dstrect = *dstrect;
   7.112          /*sdlds_print_surface_info(surface);
   7.113 -        sdlds_print_surface_info(target);*/
   7.114 +           sdlds_print_surface_info(target); */
   7.115          sdlds_surf2vram(surface);
   7.116          return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
   7.117      }
   7.118 @@ -240,7 +244,8 @@
   7.119      for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
   7.120          for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
   7.121              VRAM_A[(dj + dy) * 256 + di + dx] =
   7.122 -              ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si + sx];
   7.123 +                ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
   7.124 +                                             sx];
   7.125          }
   7.126      }
   7.127      return 0;
   7.128 @@ -252,13 +257,17 @@
   7.129  SDL_NDS_RenderPresent(SDL_Renderer * renderer)
   7.130  {
   7.131      SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
   7.132 +    int i;
   7.133  #if 0
   7.134      printf("SDL_NDS_RenderPresent(renderer)\n");
   7.135      printf(" renderer: %s\n", renderer->info.name);
   7.136  #endif
   7.137      /* Send the data to the display */
   7.138 -    /*sdlds_surf2vram(data->screens[data->current_screen]);*/
   7.139  
   7.140 +    /* hack to fix the pixel format until I figure out why BGR doesn't work */
   7.141 +    for (i = 0; i < 256 * 192; ++i) {
   7.142 +        VRAM_A[i] = sdlds_rgb2bgr(VRAM_A[i]);
   7.143 +    }
   7.144      /* Update the flipping chain, if any */
   7.145      if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   7.146          data->current_screen = (data->current_screen + 1) % 2;
     8.1 --- a/src/video/nds/SDL_ndsvideo.c	Tue Jun 17 08:26:36 2008 +0000
     8.2 +++ b/src/video/nds/SDL_ndsvideo.c	Thu Jun 19 07:11:35 2008 +0000
     8.3 @@ -63,7 +63,7 @@
     8.4  NDS_Available(void)
     8.5  {
     8.6      const char *envr = SDL_getenv("SDL_VIDEODRIVER");
     8.7 -    /*printf("NDS_Available()\n");*/
     8.8 +    /*printf("NDS_Available()\n"); */
     8.9      return (1);
    8.10  }
    8.11  
    8.12 @@ -77,7 +77,7 @@
    8.13  NDS_CreateDevice(int devindex)
    8.14  {
    8.15      SDL_VideoDevice *device;
    8.16 -    /*printf("NDS_CreateDevice(%d)\n", devindex);*/
    8.17 +    /*printf("NDS_CreateDevice(%d)\n", devindex); */
    8.18  
    8.19      /* Initialize all variables that we clean on shutdown */
    8.20      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    8.21 @@ -113,10 +113,10 @@
    8.22      SDL_DisplayMode mode;
    8.23      int i;
    8.24  
    8.25 -    /* simple 256x192x16x60 for now */
    8.26 +    /* simple 256x192x15x60 for now */
    8.27      mode.w = 256;
    8.28      mode.h = 192;
    8.29 -    mode.format = SDL_PIXELFORMAT_RGB555;
    8.30 +    mode.format = SDL_PIXELFORMAT_BGR555;
    8.31      mode.refresh_rate = 60;
    8.32      mode.driverdata = NULL;
    8.33  
    8.34 @@ -139,10 +139,7 @@
    8.35      BG_PALETTE_SUB[255] = RGB15(31, 31, 31);
    8.36      consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31),
    8.37                         (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);
    8.38 -    for (i = 0; i < 256 * 192; ++i) {
    8.39 -        ((u16 *) VRAM_A)[i] = i;
    8.40 -    }
    8.41 -    
    8.42 +
    8.43      /*NDS_SetDisplayMode(_this, &mode); */
    8.44      return 0;
    8.45  }
    8.46 @@ -150,7 +147,7 @@
    8.47  static int
    8.48  NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
    8.49  {
    8.50 -    /* right now this function is just hard-coded for 256x192 ARGB1555 */
    8.51 +    /* right now this function is just hard-coded for 256x192 ABGR1555 */
    8.52  #if 0
    8.53      videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);       /* display on main core */
    8.54      videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */