src/video/nds/SDL_ndsrender.c
branchgsoc2008_nds
changeset 2671 c3e7c0698cbb
parent 2670 6e4669f4db49
child 2672 74ac057679d5
     1.1 --- a/src/video/nds/SDL_ndsrender.c	Tue Jun 10 06:57:57 2008 +0000
     1.2 +++ b/src/video/nds/SDL_ndsrender.c	Thu Jun 12 02:38:49 2008 +0000
     1.3 @@ -35,20 +35,20 @@
     1.4  /* SDL surface based renderer implementation */
     1.5  
     1.6  static SDL_Renderer *SDL_NDS_CreateRenderer(SDL_Window * window,
     1.7 -                                              Uint32 flags);
     1.8 +                                            Uint32 flags);
     1.9  static int SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
    1.10 -                                Uint8 b, Uint8 a, const SDL_Rect * rect);
    1.11 +                              Uint8 b, Uint8 a, const SDL_Rect * rect);
    1.12  static int SDL_NDS_RenderCopy(SDL_Renderer * renderer,
    1.13 -                                SDL_Texture * texture,
    1.14 -                                const SDL_Rect * srcrect,
    1.15 -                                const SDL_Rect * dstrect);
    1.16 +                              SDL_Texture * texture,
    1.17 +                              const SDL_Rect * srcrect,
    1.18 +                              const SDL_Rect * dstrect);
    1.19  static void SDL_NDS_RenderPresent(SDL_Renderer * renderer);
    1.20  static void SDL_NDS_DestroyRenderer(SDL_Renderer * renderer);
    1.21  
    1.22  
    1.23  SDL_RenderDriver SDL_NDS_RenderDriver = {
    1.24      SDL_NDS_CreateRenderer,
    1.25 -    { "nds",  SDL_RENDERER_PRESENTCOPY }
    1.26 +    {"nds", SDL_RENDERER_PRESENTCOPY}
    1.27  /*   (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
    1.28        SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
    1.29        SDL_RENDERER_PRESENTDISCARD),*/
    1.30 @@ -73,14 +73,15 @@
    1.31      Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
    1.32  
    1.33      printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
    1.34 -    printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w, window->h);
    1.35 +    printf(" window: (%d,%d), %dx%d\n", window->x, window->y, window->w,
    1.36 +           window->h);
    1.37  
    1.38      /* hard coded this to ARGB1555 for now
    1.39 -    if (!SDL_PixelFormatEnumToMasks
    1.40 -        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
    1.41 -        SDL_SetError("Unknown display format");
    1.42 -        return NULL;
    1.43 -    }*/
    1.44 +       if (!SDL_PixelFormatEnumToMasks
    1.45 +       (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
    1.46 +       SDL_SetError("Unknown display format");
    1.47 +       return NULL;
    1.48 +       } */
    1.49  
    1.50      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
    1.51      if (!renderer) {
    1.52 @@ -118,7 +119,8 @@
    1.53      }
    1.54      for (i = 0; i < n; ++i) {
    1.55          data->screens[i] =
    1.56 -            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask);
    1.57 +            SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
    1.58 +                                 Amask);
    1.59          if (!data->screens[i]) {
    1.60              SDL_NDS_DestroyRenderer(renderer);
    1.61              return NULL;
    1.62 @@ -131,17 +133,11 @@
    1.63  #if 0
    1.64  #define blarg (data->screens[0])
    1.65      printf("hello?\n");
    1.66 -    if(!data || !(data->screens) || !blarg) {
    1.67 +    if (!data || !(data->screens) || !blarg) {
    1.68          printf("they're null.\n");
    1.69      } else {
    1.70          printf("not null.\n");
    1.71 -        printf("%d\n%d\n%d\n%d\n%x\n%x\n%x\n%x\n",
    1.72 -        blarg->w, blarg->h, blarg->pitch,
    1.73 -        blarg->format->BitsPerPixel,
    1.74 -        blarg->format->Rmask,
    1.75 -        blarg->format->Gmask,
    1.76 -        blarg->format->Bmask,
    1.77 -        (u32)(blarg->pixels)); /* ARGH WHY DOESN'T THIS PRINT AT ALL? */
    1.78 +        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? */
    1.79          printf("hurr\n");
    1.80      }
    1.81  #undef blarg
    1.82 @@ -151,7 +147,7 @@
    1.83  
    1.84  static int
    1.85  SDL_NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    1.86 -                     Uint8 a, const SDL_Rect * rect)
    1.87 +                   Uint8 a, const SDL_Rect * rect)
    1.88  {
    1.89      SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
    1.90      SDL_Surface *target = data->screens[data->current_screen];
    1.91 @@ -164,26 +160,29 @@
    1.92  }
    1.93  
    1.94  /* this is mainly for testing stuff to put a surface where I can see it */
    1.95 -void sdlds_surf2vram(SDL_Surface *s) {
    1.96 +void
    1.97 +sdlds_surf2vram(SDL_Surface * s)
    1.98 +{
    1.99      int i;
   1.100 -    for(i = 0; i < 256*192; ++i) {
   1.101 -        ((u16*)VRAM_A)[i] = ((u16*)(s->pixels))[i];
   1.102 +    for (i = 0; i < 256 * 192; ++i) {
   1.103 +        ((u16 *) VRAM_A)[i] = ((u16 *) (s->pixels))[i];
   1.104      }
   1.105  }
   1.106  
   1.107  static int
   1.108  SDL_NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   1.109 -                     const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   1.110 +                   const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   1.111  {
   1.112 -    SDL_NDS_RenderData *data =
   1.113 -        (SDL_NDS_RenderData *) renderer->driverdata;
   1.114 +    SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
   1.115      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.116      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.117      printf("SDL_NDS_RenderCopy(renderer, texture, srcrect, dstrect)\n");
   1.118      printf(" renderer: %s\n", renderer->info.name);
   1.119      printf(" texture: %dx%d\n", texture->w, texture->h);
   1.120 -    printf(" srcrect: (%d,%d), %dx%d\n", srcrect->x, srcrect->y, srcrect->w, srcrect->h);
   1.121 -    printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w, dstrect->h);
   1.122 +    printf(" srcrect: (%d,%d), %dx%d\n", srcrect->x, srcrect->y, srcrect->w,
   1.123 +           srcrect->h);
   1.124 +    printf(" dstrect: (%d,%d), %dx%d\n", dstrect->x, dstrect->y, dstrect->w,
   1.125 +           dstrect->h);
   1.126  
   1.127      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   1.128          SDL_Surface *target = data->screens[data->current_screen];
   1.129 @@ -201,37 +200,38 @@
   1.130          SDL_Rect real_dstrect = *dstrect;
   1.131          printf("Rmask %x Gmask %x Bmask %x Amask %x\n"
   1.132                 "width %d, height %d, pitch %d\nbpp %d, pixels %x\n",
   1.133 -            surface->format->Rmask, surface->format->Gmask,
   1.134 -            surface->format->Bmask, surface->format->Amask,
   1.135 -            surface->w, surface->h, surface->pitch,
   1.136 -            surface->format->BitsPerPixel, (u32)(surface->pixels));
   1.137 +               surface->format->Rmask, surface->format->Gmask,
   1.138 +               surface->format->Bmask, surface->format->Amask,
   1.139 +               surface->w, surface->h, surface->pitch,
   1.140 +               surface->format->BitsPerPixel, (u32) (surface->pixels));
   1.141          sdlds_surf2vram(surface);
   1.142          return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
   1.143      }
   1.144  #if 0
   1.145  /* previous attempt to copy it directly to vram */
   1.146 -        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   1.147 -        int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h;
   1.148 -        int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
   1.149 -        int si,sj, di,dj;
   1.150 -        /*printf("DEBUG: still alive!\n");*/
   1.151 -        for(sj=0, dj=0; sj<sh && dj<dh; ++sj, ++dj) {
   1.152 -            for(si=0, di=0; si<sw && di<dw; ++si, ++di) {
   1.153 -                ((uint16*)VRAM_A)[(dj+dy)*256 + di+dx]
   1.154 -                 = ((Uint16*)surface->pixels)[(sj+sy)*(surface->w) + si+sx];
   1.155 -            }
   1.156 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   1.157 +    int sx = srcrect->x, sy = srcrect->y, sw = srcrect->w, sh = srcrect->h;
   1.158 +    int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
   1.159 +    int si, sj, di, dj;
   1.160 +    /*printf("DEBUG: still alive!\n"); */
   1.161 +    for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
   1.162 +        for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
   1.163 +            ((uint16 *) VRAM_A)[(dj + dy) * 256 + di + dx]
   1.164 +                = ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
   1.165 +                                               sx];
   1.166          }
   1.167 -        /*printf("DEBUG: still alive!\n");*/
   1.168      }
   1.169 -    return 0;
   1.170 +    /*printf("DEBUG: still alive!\n"); */
   1.171 +}
   1.172 +
   1.173 +return 0;
   1.174  #endif
   1.175  }
   1.176  
   1.177  static void
   1.178  SDL_NDS_RenderPresent(SDL_Renderer * renderer)
   1.179  {
   1.180 -    SDL_NDS_RenderData *data =
   1.181 -        (SDL_NDS_RenderData *) renderer->driverdata;
   1.182 +    SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
   1.183  
   1.184      printf("SDL_NDS_RenderPresent(renderer)\n");
   1.185      printf(" renderer: %s\n", renderer->info.name);
   1.186 @@ -240,18 +240,25 @@
   1.187  #if 0
   1.188  /*testing to see if rectangles drawn get copied right*/
   1.189      {
   1.190 -    SDL_Rect ra;
   1.191 -  	ra.x=0; ra.y=0; ra.w=256; ra.h=192;
   1.192 -	SDL_FillRect(data->screens[data->current_screen], &ra, 0x250);
   1.193 -	ra.x=32; ra.y=32; ra.w=192; ra.h=128;
   1.194 -	SDL_FillRect(data->screens[data->current_screen], &ra,
   1.195 -	    SDL_MapRGBA(data->screens[data->current_screen]->format,
   1.196 -	    255,255,255,255));
   1.197 -	}
   1.198 +        SDL_Rect ra;
   1.199 +        ra.x = 0;
   1.200 +        ra.y = 0;
   1.201 +        ra.w = 256;
   1.202 +        ra.h = 192;
   1.203 +        
   1.204 SDL_FillRect(data->screens[data->current_screen], &ra, 0x250);
   1.205 +        ra.x = 32;
   1.206 +        ra.y = 32;
   1.207 +        ra.w = 192;
   1.208 +        ra.h = 128;
   1.209 +        
   1.210 SDL_FillRect(data->screens[data->current_screen], &ra,
   1.211 +                      SDL_MapRGBA(data->screens[data->current_screen]->format,
   1.212 +                                  255, 255, 255, 255));
   1.213 +    }
   1.214  /*okay so this works but why not when I do it in the main()?
   1.215    for some reason the screen I get from screen=SDL_SetVideoMode(...)
   1.216    doesn't get copied to renderer->driverdata? */
   1.217 -    for(i = 0; i < 30; ++i) swiWaitForVBlank(); /* delay for debug purpose */
   1.218 +    for (i = 0; i < 30; ++i)
   1.219 +        swiWaitForVBlank();     /* delay for debug purpose */
   1.220  #endif
   1.221      sdlds_surf2vram(data->screens[data->current_screen]);
   1.222