src/video/nds/SDL_ndsrender.c
branchgsoc2008_nds
changeset 2673 24a6b3588eac
parent 2672 74ac057679d5
child 2677 6386764eb222
     1.1 --- a/src/video/nds/SDL_ndsrender.c	Tue Jun 17 08:26:36 2008 +0000
     1.2 +++ b/src/video/nds/SDL_ndsrender.c	Thu Jun 19 07:11:35 2008 +0000
     1.3 @@ -68,8 +68,9 @@
     1.4   */
     1.5  
     1.6  u16
     1.7 -sdlds_rgb2bgr(u16 c) {
     1.8 -/* hack to get the colors right until I actually add BGR555 to the headers */
     1.9 +sdlds_rgb2bgr(u16 c)
    1.10 +{
    1.11 +/* hack to get the proper colors until I actually get BGR555 to work right */
    1.12      u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b;
    1.13      r = (c & Rmask) >> 10;
    1.14      b = (c & Bmask) << 10;
    1.15 @@ -79,27 +80,29 @@
    1.16  void
    1.17  sdlds_surf2vram(SDL_Surface * s)
    1.18  {
    1.19 -
    1.20 -    int i;
    1.21 -	/*for (i = 0; i < 30; ++i) swiWaitForVBlank();*/
    1.22 -    for (i = 0; i < 256 * 192; ++i) {
    1.23 -        ((u16 *) VRAM_A)[i] = sdlds_rgb2bgr(((u16 *) (s->pixels))[i+160]);
    1.24 +    if (s->w == 256) {
    1.25 +        dmaCopy((u8 *) (s->pixels) + 156 * sizeof(u16),
    1.26 +                VRAM_A, 256 * 192 * sizeof(u16));
    1.27      }
    1.28  }
    1.29  
    1.30  void
    1.31 -sdlds_print_pixfmt_info(SDL_PixelFormat *f) {
    1.32 -	if(!f) return;
    1.33 -	printf("bpp: %d\nRGBA: %x %x %x %x\n",
    1.34 -	       f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
    1.35 +sdlds_print_pixfmt_info(SDL_PixelFormat * f)
    1.36 +{
    1.37 +    if (!f)
    1.38 +        return;
    1.39 +    printf("bpp: %d\nRGBA: %x %x %x %x\n",
    1.40 +           f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
    1.41  }
    1.42  
    1.43  void
    1.44 -sdlds_print_surface_info(SDL_Surface *s) {
    1.45 -	if(!s) return;
    1.46 -	printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
    1.47 -	       s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
    1.48 -	sdlds_print_pixfmt_info(s->format);
    1.49 +sdlds_print_surface_info(SDL_Surface * s)
    1.50 +{
    1.51 +    if (!s)
    1.52 +        return;
    1.53 +    printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
    1.54 +           s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
    1.55 +    sdlds_print_pixfmt_info(s->format);
    1.56  }
    1.57  
    1.58  
    1.59 @@ -113,11 +116,10 @@
    1.60      SDL_NDS_RenderData *data;
    1.61      int i, n;
    1.62      int bpp = 15;
    1.63 -/*/
    1.64 -    Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
    1.65 -/*/
    1.66 +    Uint32 Rmask, Gmask, Bmask, Amask;
    1.67 +/*  Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
    1.68      Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
    1.69 -//*/
    1.70 +*/
    1.71  
    1.72  #if 0
    1.73      printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
    1.74 @@ -125,12 +127,12 @@
    1.75             window->x, window->y, window->w, window->h);
    1.76  #endif
    1.77  
    1.78 -    /* hard coded this to ARGB1555 for now
    1.79 -       if (!SDL_PixelFormatEnumToMasks
    1.80 -       (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
    1.81 -       SDL_SetError("Unknown display format");
    1.82 -       return NULL;
    1.83 -       } */
    1.84 +    /* hard coded this to BGR555 for now */
    1.85 +    if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
    1.86 +                                    &Rmask, &Gmask, &Bmask, &Amask)) {
    1.87 +        SDL_SetError("Unknown display format");
    1.88 +        return NULL;
    1.89 +    }
    1.90  
    1.91      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
    1.92      if (!renderer) {
    1.93 @@ -168,12 +170,14 @@
    1.94      }
    1.95      for (i = 0; i < n; ++i) {
    1.96          data->screens[i] =
    1.97 -            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask);
    1.98 +            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
    1.99 +                                 Amask);
   1.100          if (!data->screens[i]) {
   1.101              SDL_NDS_DestroyRenderer(renderer);
   1.102              return NULL;
   1.103          }
   1.104          SDL_SetSurfacePalette(data->screens[i], display->palette);
   1.105 +        sdlds_print_surface_info(data->screens[i]);
   1.106      }
   1.107  
   1.108      data->current_screen = 0;
   1.109 @@ -227,7 +231,7 @@
   1.110          SDL_Rect real_srcrect = *srcrect;
   1.111          SDL_Rect real_dstrect = *dstrect;
   1.112          /*sdlds_print_surface_info(surface);
   1.113 -        sdlds_print_surface_info(target);*/
   1.114 +           sdlds_print_surface_info(target); */
   1.115          sdlds_surf2vram(surface);
   1.116          return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
   1.117      }
   1.118 @@ -240,7 +244,8 @@
   1.119      for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
   1.120          for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
   1.121              VRAM_A[(dj + dy) * 256 + di + dx] =
   1.122 -              ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si + sx];
   1.123 +                ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
   1.124 +                                             sx];
   1.125          }
   1.126      }
   1.127      return 0;
   1.128 @@ -252,13 +257,17 @@
   1.129  SDL_NDS_RenderPresent(SDL_Renderer * renderer)
   1.130  {
   1.131      SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
   1.132 +    int i;
   1.133  #if 0
   1.134      printf("SDL_NDS_RenderPresent(renderer)\n");
   1.135      printf(" renderer: %s\n", renderer->info.name);
   1.136  #endif
   1.137      /* Send the data to the display */
   1.138 -    /*sdlds_surf2vram(data->screens[data->current_screen]);*/
   1.139  
   1.140 +    /* hack to fix the pixel format until I figure out why BGR doesn't work */
   1.141 +    for (i = 0; i < 256 * 192; ++i) {
   1.142 +        VRAM_A[i] = sdlds_rgb2bgr(VRAM_A[i]);
   1.143 +    }
   1.144      /* Update the flipping chain, if any */
   1.145      if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   1.146          data->current_screen = (data->current_screen + 1) % 2;