NDS video driver is now functional, using software rendering and framebuffer. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Tue, 17 Jun 2008 08:26:36 +0000
branchgsoc2008_nds
changeset 267274ac057679d5
parent 2671 c3e7c0698cbb
child 2673 24a6b3588eac
NDS video driver is now functional, using software rendering and framebuffer.
include/SDL_config_nintendods.h
src/video/nds/SDL_ndsrender.c
src/video/nds/SDL_ndsvideo.c
     1.1 --- a/include/SDL_config_nintendods.h	Thu Jun 12 02:38:49 2008 +0000
     1.2 +++ b/include/SDL_config_nintendods.h	Tue Jun 17 08:26:36 2008 +0000
     1.3 @@ -111,6 +111,6 @@
     1.4  #define SDL_TIMERS_DISABLED	1
     1.5  
     1.6  /* Enable various video drivers */
     1.7 -#define SDL_VIDEO_DRIVER_DUMMY	1
     1.8 +#define SDL_VIDEO_DRIVER_NDS	1
     1.9  
    1.10  #endif /* _SDL_config_nintendods_h */
     2.1 --- a/src/video/nds/SDL_ndsrender.c	Thu Jun 12 02:38:49 2008 +0000
     2.2 +++ b/src/video/nds/SDL_ndsrender.c	Tue Jun 17 08:26:36 2008 +0000
     2.3 @@ -61,6 +61,49 @@
     2.4      int ultimate_answer;
     2.5  } SDL_NDS_RenderData;
     2.6  
     2.7 +
     2.8 +
     2.9 +/* this is mainly hackish testing/debugging stuff to get cleaned up soon
    2.10 +   anything named sdlds_blah shouldn't make it into the stable version
    2.11 + */
    2.12 +
    2.13 +u16
    2.14 +sdlds_rgb2bgr(u16 c) {
    2.15 +/* hack to get the colors right until I actually add BGR555 to the headers */
    2.16 +    u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b;
    2.17 +    r = (c & Rmask) >> 10;
    2.18 +    b = (c & Bmask) << 10;
    2.19 +    return (c & GAmask) | r | b;
    2.20 +}
    2.21 +
    2.22 +void
    2.23 +sdlds_surf2vram(SDL_Surface * s)
    2.24 +{
    2.25 +
    2.26 +    int i;
    2.27 +	/*for (i = 0; i < 30; ++i) swiWaitForVBlank();*/
    2.28 +    for (i = 0; i < 256 * 192; ++i) {
    2.29 +        ((u16 *) VRAM_A)[i] = sdlds_rgb2bgr(((u16 *) (s->pixels))[i+160]);
    2.30 +    }
    2.31 +}
    2.32 +
    2.33 +void
    2.34 +sdlds_print_pixfmt_info(SDL_PixelFormat *f) {
    2.35 +	if(!f) return;
    2.36 +	printf("bpp: %d\nRGBA: %x %x %x %x\n",
    2.37 +	       f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
    2.38 +}
    2.39 +
    2.40 +void
    2.41 +sdlds_print_surface_info(SDL_Surface *s) {
    2.42 +	if(!s) return;
    2.43 +	printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
    2.44 +	       s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
    2.45 +	sdlds_print_pixfmt_info(s->format);
    2.46 +}
    2.47 +
    2.48 +
    2.49 +
    2.50  SDL_Renderer *
    2.51  SDL_NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
    2.52  {
    2.53 @@ -69,12 +112,18 @@
    2.54      SDL_Renderer *renderer;
    2.55      SDL_NDS_RenderData *data;
    2.56      int i, n;
    2.57 -    int bpp = 16;
    2.58 +    int bpp = 15;
    2.59 +/*/
    2.60      Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
    2.61 +/*/
    2.62 +    Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
    2.63 +//*/
    2.64  
    2.65 +#if 0
    2.66      printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
    2.67 -    printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w,
    2.68 -           window->h);
    2.69 +    printf(" window: (%d,%d), %dx%d\n",
    2.70 +           window->x, window->y, window->w, window->h);
    2.71 +#endif
    2.72  
    2.73      /* hard coded this to ARGB1555 for now
    2.74         if (!SDL_PixelFormatEnumToMasks
    2.75 @@ -119,8 +168,7 @@
    2.76      }
    2.77      for (i = 0; i < n; ++i) {
    2.78          data->screens[i] =
    2.79 -            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
    2.80 -                                 Amask);
    2.81 +            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask);
    2.82          if (!data->screens[i]) {
    2.83              SDL_NDS_DestroyRenderer(renderer);
    2.84              return NULL;
    2.85 @@ -130,18 +178,7 @@
    2.86  
    2.87      data->current_screen = 0;
    2.88      data->ultimate_answer = 42;
    2.89 -#if 0
    2.90 -#define blarg (data->screens[0])
    2.91 -    printf("hello?\n");
    2.92 -    if (!data || !(data->screens) || !blarg) {
    2.93 -        printf("they're null.\n");
    2.94 -    } else {
    2.95 -        printf("not null.\n");
    2.96 -        printf("%d\n%d\n%d\n%d\n%x\n%x\n%x\n%x\n", blarg->w, blarg->h, blarg->pitch, blarg->format->BitsPerPixel, blarg->format->Rmask, blarg->format->Gmask, blarg->format->Bmask, (u32) (blarg->pixels));     /* ARGH WHY DOESN'T THIS PRINT AT ALL? */
    2.97 -        printf("hurr\n");
    2.98 -    }
    2.99 -#undef blarg
   2.100 -#endif
   2.101 +
   2.102      return renderer;
   2.103  }
   2.104  
   2.105 @@ -159,16 +196,6 @@
   2.106      return SDL_FillRect(target, &real_rect, color);
   2.107  }
   2.108  
   2.109 -/* this is mainly for testing stuff to put a surface where I can see it */
   2.110 -void
   2.111 -sdlds_surf2vram(SDL_Surface * s)
   2.112 -{
   2.113 -    int i;
   2.114 -    for (i = 0; i < 256 * 192; ++i) {
   2.115 -        ((u16 *) VRAM_A)[i] = ((u16 *) (s->pixels))[i];
   2.116 -    }
   2.117 -}
   2.118 -
   2.119  static int
   2.120  SDL_NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   2.121                     const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   2.122 @@ -176,6 +203,7 @@
   2.123      SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
   2.124      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   2.125      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   2.126 +#if 0
   2.127      printf("SDL_NDS_RenderCopy(renderer, texture, srcrect, dstrect)\n");
   2.128      printf(" renderer: %s\n", renderer->info.name);
   2.129      printf(" texture: %dx%d\n", texture->w, texture->h);
   2.130 @@ -183,7 +211,7 @@
   2.131             srcrect->h);
   2.132      printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w,
   2.133             dstrect->h);
   2.134 -
   2.135 +#endif
   2.136      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   2.137          SDL_Surface *target = data->screens[data->current_screen];
   2.138          void *pixels =
   2.139 @@ -198,69 +226,38 @@
   2.140          SDL_Surface *target = data->screens[data->current_screen];
   2.141          SDL_Rect real_srcrect = *srcrect;
   2.142          SDL_Rect real_dstrect = *dstrect;
   2.143 -        printf("Rmask %x Gmask %x Bmask %x Amask %x\n"
   2.144 -               "width %d, height %d, pitch %d\nbpp %d, pixels %x\n",
   2.145 -               surface->format->Rmask, surface->format->Gmask,
   2.146 -               surface->format->Bmask, surface->format->Amask,
   2.147 -               surface->w, surface->h, surface->pitch,
   2.148 -               surface->format->BitsPerPixel, (u32) (surface->pixels));
   2.149 +        /*sdlds_print_surface_info(surface);
   2.150 +        sdlds_print_surface_info(target);*/
   2.151          sdlds_surf2vram(surface);
   2.152          return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
   2.153      }
   2.154  #if 0
   2.155 -/* previous attempt to copy it directly to vram */
   2.156 +    /* copy it directly to vram */
   2.157      SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   2.158      int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h;
   2.159      int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
   2.160      int si, sj, di, dj;
   2.161 -    /*printf("DEBUG: still alive!\n"); */
   2.162      for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
   2.163          for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
   2.164 -            ((uint16 *) VRAM_A)[(dj + dy) * 256 + di + dx]
   2.165 -                = ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
   2.166 -                                               sx];
   2.167 +            VRAM_A[(dj + dy) * 256 + di + dx] =
   2.168 +              ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si + sx];
   2.169          }
   2.170      }
   2.171 -    /*printf("DEBUG: still alive!\n"); */
   2.172 +    return 0;
   2.173 +#endif
   2.174  }
   2.175  
   2.176 -return 0;
   2.177 -#endif
   2.178 -}
   2.179  
   2.180  static void
   2.181  SDL_NDS_RenderPresent(SDL_Renderer * renderer)
   2.182  {
   2.183      SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
   2.184 -
   2.185 +#if 0
   2.186      printf("SDL_NDS_RenderPresent(renderer)\n");
   2.187      printf(" renderer: %s\n", renderer->info.name);
   2.188 +#endif
   2.189      /* Send the data to the display */
   2.190 -
   2.191 -#if 0
   2.192 -/*testing to see if rectangles drawn get copied right*/
   2.193 -    {
   2.194 -        SDL_Rect ra;
   2.195 -        ra.x = 0;
   2.196 -        ra.y = 0;
   2.197 -        ra.w = 256;
   2.198 -        ra.h = 192;
   2.199 -        
   2.200 SDL_FillRect(data->screens[data->current_screen], &ra, 0x250);
   2.201 -        ra.x = 32;
   2.202 -        ra.y = 32;
   2.203 -        ra.w = 192;
   2.204 -        ra.h = 128;
   2.205 -        
   2.206 SDL_FillRect(data->screens[data->current_screen], &ra,
   2.207 -                      SDL_MapRGBA(data->screens[data->current_screen]->format,
   2.208 -                                  255, 255, 255, 255));
   2.209 -    }
   2.210 -/*okay so this works but why not when I do it in the main()?
   2.211 -  for some reason the screen I get from screen=SDL_SetVideoMode(...)
   2.212 -  doesn't get copied to renderer->driverdata? */
   2.213 -    for (i = 0; i < 30; ++i)
   2.214 -        swiWaitForVBlank();     /* delay for debug purpose */
   2.215 -#endif
   2.216 -    sdlds_surf2vram(data->screens[data->current_screen]);
   2.217 +    /*sdlds_surf2vram(data->screens[data->current_screen]);*/
   2.218  
   2.219      /* Update the flipping chain, if any */
   2.220      if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
     3.1 --- a/src/video/nds/SDL_ndsvideo.c	Thu Jun 12 02:38:49 2008 +0000
     3.2 +++ b/src/video/nds/SDL_ndsvideo.c	Tue Jun 17 08:26:36 2008 +0000
     3.3 @@ -63,7 +63,7 @@
     3.4  NDS_Available(void)
     3.5  {
     3.6      const char *envr = SDL_getenv("SDL_VIDEODRIVER");
     3.7 -    printf("NDS_Available()\n");
     3.8 +    /*printf("NDS_Available()\n");*/
     3.9      return (1);
    3.10  }
    3.11  
    3.12 @@ -77,7 +77,7 @@
    3.13  NDS_CreateDevice(int devindex)
    3.14  {
    3.15      SDL_VideoDevice *device;
    3.16 -    printf("NDS_CreateDevice(%d)\n", devindex);
    3.17 +    /*printf("NDS_CreateDevice(%d)\n", devindex);*/
    3.18  
    3.19      /* Initialize all variables that we clean on shutdown */
    3.20      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    3.21 @@ -116,7 +116,7 @@
    3.22      /* simple 256x192x16x60 for now */
    3.23      mode.w = 256;
    3.24      mode.h = 192;
    3.25 -    mode.format = SDL_PIXELFORMAT_ARGB1555;
    3.26 +    mode.format = SDL_PIXELFORMAT_RGB555;
    3.27      mode.refresh_rate = 60;
    3.28      mode.driverdata = NULL;
    3.29  
    3.30 @@ -142,8 +142,6 @@
    3.31      for (i = 0; i < 256 * 192; ++i) {
    3.32          ((u16 *) VRAM_A)[i] = i;
    3.33      }
    3.34 -    for (i = 0; i < 60; ++i)
    3.35 -        swiWaitForVBlank();
    3.36      
    3.37      /*NDS_SetDisplayMode(_this, &mode); */
    3.38      return 0;