changeset 2673:24a6b3588eac gsoc2008_nds

Cleaned up and added joypad support from 1.2.9 NDS port. Also some minor video driver bugfixes.
author Darren Alton <dalton@stevens.edu>
date Thu, 19 Jun 2008 07:11:35 +0000
parents 74ac057679d5
children f1d07ba2e275
files 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
diffstat 8 files changed, 116 insertions(+), 174 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.ds	Tue Jun 17 08:26:36 2008 +0000
+++ b/Makefile.ds	Thu Jun 19 07:11:35 2008 +0000
@@ -49,7 +49,7 @@
 src/events/SDL_quit.c \
 src/events/SDL_windowevents.c \
 src/file/SDL_rwops.c \
-src/joystick/dummy/SDL_sysjoystick.c \
+src/joystick/nds/SDL_sysjoystick.c \
 src/joystick/SDL_joystick.c \
 src/stdlib/SDL_getenv.c \
 src/stdlib/SDL_iconv.c \
@@ -64,9 +64,6 @@
 src/thread/nds/SDL_systhread.c \
 src/timer/dummy/SDL_systimer.c \
 src/timer/SDL_timer.c \
-src/video/dummy/SDL_nullevents.c \
-src/video/dummy/SDL_nullrender.c \
-src/video/dummy/SDL_nullvideo.c \
 src/video/nds/SDL_ndsevents.c \
 src/video/nds/SDL_ndsrender.c \
 src/video/nds/SDL_ndsvideo.c \
@@ -130,6 +127,8 @@
 
 install: $(TARGET)
 	@cp libSDL.a $(DEVKITPRO)/libnds/lib/
+	@mkdir -p $(DEVKITPRO)/libnds/include/SDL/
+	@cp include/*.h $(DEVKITPRO)/libnds/include/SDL/
 
 copy_config:
 	@cp include/SDL_config.h.default include/SDL_config.h
--- a/include/SDL_config_nintendods.h	Tue Jun 17 08:26:36 2008 +0000
+++ b/include/SDL_config_nintendods.h	Thu Jun 19 07:11:35 2008 +0000
@@ -98,7 +98,7 @@
 #define SDL_CDROM_DISABLED	1
 
 /* Enable various input drivers */
-#define SDL_JOYSTICK_DISABLED	1
+#define SDL_JOYSTICK_NDS	1
 
 /* DS has no dynamic linking afaik */
 #define SDL_LOADSO_DISABLED	1
--- a/include/SDL_pixels.h	Tue Jun 17 08:26:36 2008 +0000
+++ b/include/SDL_pixels.h	Thu Jun 19 07:11:35 2008 +0000
@@ -146,12 +146,18 @@
     SDL_PIXELFORMAT_RGB555 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
                                SDL_PACKEDLAYOUT_1555, 15, 2),
+    SDL_PIXELFORMAT_BGR555 =
+        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
+                               SDL_PACKEDLAYOUT_1555, 15, 2),
     SDL_PIXELFORMAT_ARGB4444 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
                                SDL_PACKEDLAYOUT_4444, 16, 2),
     SDL_PIXELFORMAT_ARGB1555 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
                                SDL_PACKEDLAYOUT_1555, 16, 2),
+    SDL_PIXELFORMAT_ABGR1555 =
+        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
+                               SDL_PACKEDLAYOUT_1555, 16, 2),
     SDL_PIXELFORMAT_RGB565 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
                                SDL_PACKEDLAYOUT_565, 16, 2),
--- a/src/joystick/nds/SDL_sysjoystick.c	Tue Jun 17 08:26:36 2008 +0000
+++ b/src/joystick/nds/SDL_sysjoystick.c	Thu Jun 19 07:11:35 2008 +0000
@@ -25,12 +25,17 @@
     "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $";
 #endif
 
+#include "SDL_config.h"
+
+#ifdef SDL_JOYSTICK_NDS
+
 /* This is the system specific header for the SDL joystick API */
 #include <nds.h>
 //#include <nds/registers_alt.h>
 #include <stdio.h>              /* For the definition of NULL */
 
 #include "SDL_error.h"
+#include "SDL_events.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
 #include "SDL_joystick_c.h"
@@ -46,9 +51,8 @@
 SDL_SYS_JoystickInit(void)
 {
     SDL_numjoysticks = 1;
-    
-        //keysInit();
-        return (1);
+    /* keysInit();*/
+    return (1);
 }
 
 /* Function to get the device-dependent name of a joystick */
@@ -82,150 +86,71 @@
  * but instead should call SDL_PrivateJoystick*() to deliver events
  * and update joystick device state.
  */
-int prevbutton = 0;
-int prevkey = 0;
-
-int dc = NULL;
-int ldc = 0;
-u32 keysd, keysu = NULL;
 void
 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
 {
-    
-        //dc=keysd;
-        //if (dc != NULL)
-        //{
-        //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); 
-        //swiWaitForVBlank();
-        //scanKeys();
-        //keysd = keysDown(); 
-        //keysu = keysUp();
-        //ldc=keysd;
-        
-        //}
-        /*if (prevkey !=NULL && prevbutton !=NULL)
-           {
-           scanKeys();
-           }
-         */ 
-        
-        //scanKeys();
-        keysd = keysDown();
-    
keysu = keysUp();
-    

short ax = 0, v = 0, h = 0;
+    u32 keysd, keysu;
+    int magnitude = 16384;
+    scanKeys();
+    keysd = keysDown();
+    keysu = keysUp();
+
     if ((keysd & KEY_UP)) {
-        ax = 1;
-        v = -10;
-        SDL_PrivateJoystickAxis(joystick, ax, v);
-        prevkey = KEY_UP;
-    }                           //fprintf(stderr,"KEY_UP\n");}
+        SDL_PrivateJoystickAxis(joystick, 1, -magnitude);
+    }
     if ((keysd & KEY_DOWN)) {
-        ax = 1;
-        v = 10;
-        SDL_PrivateJoystickAxis(joystick, ax, v);
-        prevkey = KEY_DOWN;
-    }                           //fprintf(stderr,"KEY_DOWN\n");}
+        SDL_PrivateJoystickAxis(joystick, 1, magnitude);
+    }
     if ((keysd & KEY_LEFT)) {
-        ax = 0;
-        h = -10;
-        SDL_PrivateJoystickAxis(joystick, ax, h);
-        prevkey = KEY_LEFT;
-    }                           //fprintf(stderr,"KEY_LEFT\n");}
+        SDL_PrivateJoystickAxis(joystick, 0, -magnitude);
+    }
     if ((keysd & KEY_RIGHT)) {
-        ax = 0;
-        h = 10;
-        SDL_PrivateJoystickAxis(joystick, ax, h);
-        prevkey = KEY_RIGHT;
-    }                           //fprintf(stderr,"KEY_RIGHT\n");}
-    
if ((keysu & KEY_UP)) {
-        ax = 1;
-        v = 0;
-        SDL_PrivateJoystickAxis(joystick, ax, v);
-        prevkey = NULL;
-    }                           //fprintf(stderr,"KEY_UP\n");}
-    if ((keysu & KEY_DOWN)) {
-        ax = 1;
-        v = 0;
-        SDL_PrivateJoystickAxis(joystick, ax, v);
-        prevkey = NULL;
-    }                           //fprintf(stderr,"KEY_DOWN\n");}
-    if ((keysu & KEY_LEFT)) {
-        ax = 0;
-        h = 0;
-        SDL_PrivateJoystickAxis(joystick, ax, h);
-        prevkey = NULL;
-    }                           //fprintf(stderr,"KEY_LEFT\n");}
-    if ((keysu & KEY_RIGHT)) {
-        ax = 0;
-        h = 0;
-        SDL_PrivateJoystickAxis(joystick, ax, h);
-        prevkey = NULL;
-    }                           //fprintf(stderr,"KEY_RIGHT\n");}
-    
if ((keysd & KEY_A)) {
+        SDL_PrivateJoystickAxis(joystick, 0, magnitude);
+    }
+
    if ((keysu & (KEY_UP|KEY_DOWN))) {
+        SDL_PrivateJoystickAxis(joystick, 1, 0);
+    }
+    if ((keysu & (KEY_LEFT|KEY_RIGHT))) {
+        SDL_PrivateJoystickAxis(joystick, 0, 0);
+    }
+
    if ((keysd & KEY_A)) {
         SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
-        prevbutton = KEY_A;
-    }
-    
if ((keysd & KEY_B)) {
+    }
    if ((keysd & KEY_B)) {
         SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
-        prevbutton = KEY_B;
-    }
-    
if ((keysd & KEY_X)) {
+    }
    if ((keysd & KEY_X)) {
         SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
-        prevbutton = KEY_X;
-    }
-    
if ((keysd & KEY_Y)) {
+    }
    if ((keysd & KEY_Y)) {
         SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
-        prevbutton = KEY_Y;
     }
-    
if ((keysd & KEY_SELECT)) {
+
    if ((keysd & KEY_L)) {
+        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
+    }
    if ((keysd & KEY_R)) {
+        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
+    }
+
    if ((keysd & KEY_SELECT)) {
         SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
-        prevbutton = KEY_SELECT;
-    }
-    
if ((keysd & KEY_START)) {
+    }
    if ((keysd & KEY_START)) {
         SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
-        prevbutton = KEY_START;
-    }
-    
if ((keysd & KEY_L)) {
-        SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
-        prevbutton = KEY_L;
     }
-    
if ((keysd & KEY_R)) {
-        SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
-        prevbutton = KEY_R;
-    }
-    

if ((keysu & KEY_A)) {
+
    if ((keysu & KEY_A)) {
         SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
-        prevbutton = NULL;
-    }
-    
if ((keysu & KEY_B)) {
+    }
    if ((keysu & KEY_B)) {
         SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
-        prevbutton = NULL;
-    }
-    
if ((keysu & KEY_X)) {
+    }
    if ((keysu & KEY_X)) {
         SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
-        prevbutton = NULL;
-    }
-    
if ((keysu & KEY_Y)) {
+    }
    if ((keysu & KEY_Y)) {
         SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
-        prevbutton = NULL;
     }
-    
if ((keysu & KEY_SELECT)) {
+
    if ((keysu & KEY_L)) {
+        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
+    }
    if ((keysu & KEY_R)) {
+        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
+    }
+
    if ((keysu & KEY_SELECT)) {
         SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
-        prevbutton = NULL;
-    }
-    
if ((keysu & KEY_START)) {
+    }
    if ((keysu & KEY_START)) {
         SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
-        prevbutton = NULL;
-    }
-    
if ((keysu & KEY_L)) {
-        SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
-        prevbutton = NULL;
-    }
-    
if ((keysu & KEY_R)) {
-        SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
-        prevbutton = NULL;
-    }
-

}
+    }
}
 
 /* Function to close a joystick after use */
 void
@@ -238,3 +163,5 @@
 SDL_SYS_JoystickQuit(void)
 {
 }
+#endif /* SDL_JOYSTICK_NDS */
+
--- a/src/video/SDL_pixels.c	Tue Jun 17 08:26:36 2008 +0000
+++ b/src/video/SDL_pixels.c	Thu Jun 19 07:11:35 2008 +0000
@@ -168,12 +168,16 @@
         break;
     case 15:
         switch (Rmask) {
+        case 0x001F:
+            return SDL_PIXELFORMAT_BGR555;
         case 0x7C00:
             return SDL_PIXELFORMAT_RGB555;
         }
         break;
     case 16:
         switch (Rmask) {
+        case 0x001F:
+            return SDL_PIXELFORMAT_ABGR1555;
         case 0x0F00:
             return SDL_PIXELFORMAT_ARGB4444;
         case 0x7C00:
--- a/src/video/dummy/SDL_nullrender.c	Tue Jun 17 08:26:36 2008 +0000
+++ b/src/video/dummy/SDL_nullrender.c	Thu Jun 19 07:11:35 2008 +0000
@@ -181,11 +181,11 @@
         SDL_SaveBMP(data->screens[data->current_screen], file);
     }
     /*{
-        int i;
-        for (i = 0; i < 256 * 192; ++i)
-            ((Uint16 *)0x6800000)[i]
-                = ((Uint16 *)(data->screens[data->current_screen]->pixels))[i];
-    }*/
+       int i;
+       for (i = 0; i < 256 * 192; ++i)
+       ((Uint16 *)0x6800000)[i]
+       = ((Uint16 *)(data->screens[data->current_screen]->pixels))[i];
+       } */
 
     /* Update the flipping chain, if any */
     if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
--- a/src/video/nds/SDL_ndsrender.c	Tue Jun 17 08:26:36 2008 +0000
+++ b/src/video/nds/SDL_ndsrender.c	Thu Jun 19 07:11:35 2008 +0000
@@ -68,8 +68,9 @@
  */
 
 u16
-sdlds_rgb2bgr(u16 c) {
-/* hack to get the colors right until I actually add BGR555 to the headers */
+sdlds_rgb2bgr(u16 c)
+{
+/* hack to get the proper colors until I actually get BGR555 to work right */
     u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b;
     r = (c & Rmask) >> 10;
     b = (c & Bmask) << 10;
@@ -79,27 +80,29 @@
 void
 sdlds_surf2vram(SDL_Surface * s)
 {
-
-    int i;
-	/*for (i = 0; i < 30; ++i) swiWaitForVBlank();*/
-    for (i = 0; i < 256 * 192; ++i) {
-        ((u16 *) VRAM_A)[i] = sdlds_rgb2bgr(((u16 *) (s->pixels))[i+160]);
+    if (s->w == 256) {
+        dmaCopy((u8 *) (s->pixels) + 156 * sizeof(u16),
+                VRAM_A, 256 * 192 * sizeof(u16));
     }
 }
 
 void
-sdlds_print_pixfmt_info(SDL_PixelFormat *f) {
-	if(!f) return;
-	printf("bpp: %d\nRGBA: %x %x %x %x\n",
-	       f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
+sdlds_print_pixfmt_info(SDL_PixelFormat * f)
+{
+    if (!f)
+        return;
+    printf("bpp: %d\nRGBA: %x %x %x %x\n",
+           f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
 }
 
 void
-sdlds_print_surface_info(SDL_Surface *s) {
-	if(!s) return;
-	printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
-	       s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
-	sdlds_print_pixfmt_info(s->format);
+sdlds_print_surface_info(SDL_Surface * s)
+{
+    if (!s)
+        return;
+    printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
+           s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
+    sdlds_print_pixfmt_info(s->format);
 }
 
 
@@ -113,11 +116,10 @@
     SDL_NDS_RenderData *data;
     int i, n;
     int bpp = 15;
-/*/
-    Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
-/*/
+    Uint32 Rmask, Gmask, Bmask, Amask;
+/*  Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
     Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
-//*/
+*/
 
 #if 0
     printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
@@ -125,12 +127,12 @@
            window->x, window->y, window->w, window->h);
 #endif
 
-    /* hard coded this to ARGB1555 for now
-       if (!SDL_PixelFormatEnumToMasks
-       (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
-       SDL_SetError("Unknown display format");
-       return NULL;
-       } */
+    /* hard coded this to BGR555 for now */
+    if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
+                                    &Rmask, &Gmask, &Bmask, &Amask)) {
+        SDL_SetError("Unknown display format");
+        return NULL;
+    }
 
     renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
     if (!renderer) {
@@ -168,12 +170,14 @@
     }
     for (i = 0; i < n; ++i) {
         data->screens[i] =
-            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask);
+            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
+                                 Amask);
         if (!data->screens[i]) {
             SDL_NDS_DestroyRenderer(renderer);
             return NULL;
         }
         SDL_SetSurfacePalette(data->screens[i], display->palette);
+        sdlds_print_surface_info(data->screens[i]);
     }
 
     data->current_screen = 0;
@@ -227,7 +231,7 @@
         SDL_Rect real_srcrect = *srcrect;
         SDL_Rect real_dstrect = *dstrect;
         /*sdlds_print_surface_info(surface);
-        sdlds_print_surface_info(target);*/
+           sdlds_print_surface_info(target); */
         sdlds_surf2vram(surface);
         return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
     }
@@ -240,7 +244,8 @@
     for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
         for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
             VRAM_A[(dj + dy) * 256 + di + dx] =
-              ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si + sx];
+                ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
+                                             sx];
         }
     }
     return 0;
@@ -252,13 +257,17 @@
 SDL_NDS_RenderPresent(SDL_Renderer * renderer)
 {
     SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
+    int i;
 #if 0
     printf("SDL_NDS_RenderPresent(renderer)\n");
     printf(" renderer: %s\n", renderer->info.name);
 #endif
     /* Send the data to the display */
-    /*sdlds_surf2vram(data->screens[data->current_screen]);*/
 
+    /* hack to fix the pixel format until I figure out why BGR doesn't work */
+    for (i = 0; i < 256 * 192; ++i) {
+        VRAM_A[i] = sdlds_rgb2bgr(VRAM_A[i]);
+    }
     /* Update the flipping chain, if any */
     if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
         data->current_screen = (data->current_screen + 1) % 2;
--- a/src/video/nds/SDL_ndsvideo.c	Tue Jun 17 08:26:36 2008 +0000
+++ b/src/video/nds/SDL_ndsvideo.c	Thu Jun 19 07:11:35 2008 +0000
@@ -63,7 +63,7 @@
 NDS_Available(void)
 {
     const char *envr = SDL_getenv("SDL_VIDEODRIVER");
-    /*printf("NDS_Available()\n");*/
+    /*printf("NDS_Available()\n"); */
     return (1);
 }
 
@@ -77,7 +77,7 @@
 NDS_CreateDevice(int devindex)
 {
     SDL_VideoDevice *device;
-    /*printf("NDS_CreateDevice(%d)\n", devindex);*/
+    /*printf("NDS_CreateDevice(%d)\n", devindex); */
 
     /* Initialize all variables that we clean on shutdown */
     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
@@ -113,10 +113,10 @@
     SDL_DisplayMode mode;
     int i;
 
-    /* simple 256x192x16x60 for now */
+    /* simple 256x192x15x60 for now */
     mode.w = 256;
     mode.h = 192;
-    mode.format = SDL_PIXELFORMAT_RGB555;
+    mode.format = SDL_PIXELFORMAT_BGR555;
     mode.refresh_rate = 60;
     mode.driverdata = NULL;
 
@@ -139,10 +139,7 @@
     BG_PALETTE_SUB[255] = RGB15(31, 31, 31);
     consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31),
                        (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);
-    for (i = 0; i < 256 * 192; ++i) {
-        ((u16 *) VRAM_A)[i] = i;
-    }
-    
+
     /*NDS_SetDisplayMode(_this, &mode); */
     return 0;
 }
@@ -150,7 +147,7 @@
 static int
 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
 {
-    /* right now this function is just hard-coded for 256x192 ARGB1555 */
+    /* right now this function is just hard-coded for 256x192 ABGR1555 */
 #if 0
     videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);       /* display on main core */
     videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */