Rendering now partially works! (Some BIZARRE bug that I inadvertently fixed.) gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Sat, 16 Aug 2008 11:05:50 +0000
branchgsoc2008_nds
changeset 269187cfb5fde5db
parent 2690 ca01c20274c0
child 2692 cd8978f47849
Rendering now partially works! (Some BIZARRE bug that I inadvertently fixed.)
src/video/nds/SDL_ndsrender.c
test/nds-test-progs/general/source/main.c
     1.1 --- a/src/video/nds/SDL_ndsrender.c	Sat Aug 16 07:44:35 2008 +0000
     1.2 +++ b/src/video/nds/SDL_ndsrender.c	Sat Aug 16 11:05:50 2008 +0000
     1.3 @@ -121,8 +121,8 @@
     1.4  static int NDS_SetTextureScaleMode(SDL_Renderer * renderer,
     1.5                                    SDL_Texture * texture);
     1.6  static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
     1.7 -                            const SDL_Rect * rect, const void *pixels,
     1.8 -                            int pitch);
     1.9 +                          const SDL_Rect * rect, const void *pixels,
    1.10 +                          int pitch);
    1.11  static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.12                            const SDL_Rect * rect, int markDirty, void **pixels,
    1.13                            int *pitch);
    1.14 @@ -144,7 +144,10 @@
    1.15  SDL_RenderDriver NDS_RenderDriver = {
    1.16      NDS_CreateRenderer,
    1.17      {   "nds", /* char* name */
    1.18 -        (SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED), /* u32 flags */
    1.19 +        (SDL_RENDERER_SINGLEBUFFER |
    1.20 +         SDL_RENDERER_ACCELERATED |
    1.21 +         SDL_RENDERER_PRESENTDISCARD |
    1.22 +         SDL_RENDERER_PRESENTVSYNC), /* u32 flags */
    1.23          (SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */
    1.24          (SDL_TEXTUREBLENDMODE_MASK), /* u32 blend_modes */
    1.25          (SDL_TEXTURESCALEMODE_FAST), /* u32 scale_modes */
    1.26 @@ -183,28 +186,6 @@
    1.27  
    1.28  
    1.29  
    1.30 -void sdlds_splash() {
    1.31 -    int i;
    1.32 -    printf("splash!\n");
    1.33 -	BG3_CR = BG_BMP16_256x256|BG_BMP_BASE(0);
    1.34 -    BG3_XDX = 1 << 8; BG3_XDY = 0 << 8;
    1.35 -    BG3_YDX = 0 << 8; BG3_YDY = 1 << 8;
    1.36 -    BG3_CX = 0 << 8;  BG3_CY = 0 << 8;
    1.37 -    for(i = 0; i < 256*192; ++i) {
    1.38 -        ((u16*)BG_BMP_RAM(0))[i] = i|0x8000;
    1.39 -    }
    1.40 -    printf("one... two...\n");
    1.41 -    for(i = 0; i < 120; ++i) {
    1.42 -        swiWaitForVBlank();
    1.43 -    }
    1.44 -    for(i = 0; i < 256*192; ++i) {
    1.45 -        ((u16*)BG_BMP_RAM(0))[i] = 0;
    1.46 -    }
    1.47 -    BG3_CR = 0;
    1.48 -    printf("done splash!\n");
    1.49 -}
    1.50 -
    1.51 -
    1.52  SDL_Renderer *
    1.53  NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
    1.54  {
    1.55 @@ -293,9 +274,8 @@
    1.56      data->bg_taken[2] = data->bg_taken[3] = 0;
    1.57      NDS_OAM_Init(&(data->oam_copy)); /* init sprites. */
    1.58  
    1.59 -    sdlds_splash();
    1.60 -
    1.61      TRACE("-NDS_CreateRenderer\n");
    1.62 +    printf("renderer is %x\n", (u32)(renderer->UpdateTexture));
    1.63      return renderer;
    1.64  }
    1.65  
    1.66 @@ -344,8 +324,20 @@
    1.67          int whichbg = -1, base = 0;
    1.68          if(!data->bg_taken[2]) {
    1.69              whichbg = 2;
    1.70 +            data->bg->bg2_rotation.xdx = 0x100;
    1.71 +            data->bg->bg2_rotation.xdy = 0;
    1.72 +            data->bg->bg2_rotation.ydx = 0;
    1.73 +            data->bg->bg2_rotation.ydy = 0x100;
    1.74 +            data->bg->bg2_rotation.centerX = 0;
    1.75 +            data->bg->bg2_rotation.centerY = 0;
    1.76          } else if(!data->bg_taken[3]) {
    1.77              whichbg = 3;
    1.78 +            data->bg->bg3_rotation.xdx = 0x100;
    1.79 +            data->bg->bg3_rotation.xdy = 0;
    1.80 +            data->bg->bg3_rotation.ydx = 0;
    1.81 +            data->bg->bg3_rotation.ydy = 0x100;
    1.82 +            data->bg->bg3_rotation.centerX = 0;
    1.83 +            data->bg->bg3_rotation.centerY = 0;
    1.84              base = 4;
    1.85          }
    1.86          if(whichbg >= 0) {
    1.87 @@ -371,10 +363,23 @@
    1.88              txdat->hw_index = whichbg;
    1.89              txdat->dim.hdx = 0x100; txdat->dim.hdy = 0;
    1.90              txdat->dim.vdx = 0;     txdat->dim.vdy = 0x100;
    1.91 -            txdat->dim.pitch = 256 * (bpp/8);
    1.92 +            txdat->dim.pitch = 256 * ((bpp+1)/8);
    1.93              txdat->dim.bpp = bpp;
    1.94              txdat->vram_pixels = (u16*)(data->sub ?
    1.95                  BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base));
    1.96 +
    1.97 +            /* TESTING PURPOSES ONLY!!!
    1.98 +               shows that the texture is set up properly on the screen. */
    1.99 +            for(i = 0; i < 256*192; ++i) {
   1.100 +                txdat->vram_pixels[i] = RGB15(31,31,0)|0x8000;
   1.101 +            }
   1.102 +            printf("--one... two...\n");
   1.103 +            for(i = 0; i < 120; ++i) {
   1.104 +                swiWaitForVBlank();
   1.105 +            }
   1.106 +            for(i = 0; i < 256*192; ++i) {
   1.107 +                txdat->vram_pixels[i] = 0;
   1.108 +            }
   1.109              /*txdat->size = txdat->dim.pitch * texture->h;*/
   1.110          } else {
   1.111              SDL_SetError("Out of NDS backgrounds.");
   1.112 @@ -409,16 +414,18 @@
   1.113  NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.114                   const SDL_Rect * rect, const void *pixels, int pitch)
   1.115  {
   1.116 -    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   1.117 +    NDS_TextureData *txdat;
   1.118      Uint8 *src, *dst;
   1.119      int row; size_t length;
   1.120      TRACE("+NDS_UpdateTexture\n");
   1.121 +    if(!texture) { printf("OH BOY!!!\n"); return -1; }
   1.122 +    txdat = (NDS_TextureData *) texture->driverdata;
   1.123  
   1.124      src = (Uint8 *) pixels;
   1.125      dst =
   1.126          (Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch +
   1.127 -        rect->x * (txdat->dim.bpp/8);
   1.128 -    length = rect->w * (txdat->dim.bpp/8);
   1.129 +        rect->x * ((txdat->dim.bpp+1)/8);
   1.130 +    length = rect->w * ((txdat->dim.bpp+1)/8);
   1.131      for (row = 0; row < rect->h; ++row) {
   1.132          SDL_memcpy(dst, src, length);
   1.133          src += pitch;
   1.134 @@ -444,10 +451,8 @@
   1.135      }
   1.136  
   1.137      *pixels = (void *) ((u8 *)txdat->vram_pixels + rect->y
   1.138 -                        * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8));
   1.139 +                        * txdat->dim.pitch + rect->x * ((txdat->dim.bpp+1)/8));
   1.140      *pitch = txdat->dim.pitch;
   1.141 -    printf("  pixels = %08x\n", (u32)*pixels);
   1.142 -    printf("  vram = %08x\n", (u32)(txdat->vram_pixels));
   1.143      TRACE("-NDS_LockTexture\n");
   1.144      return 0;
   1.145  }
   1.146 @@ -517,8 +522,8 @@
   1.147          tmpbg->centerY = 0;
   1.148      } else {
   1.149          /* sprites not implemented yet */
   1.150 +        printf("tried to RenderCopy a sprite.\n");
   1.151      }
   1.152 -    printf("  txdat->hw_index = %d\n", txdat->hw_index);
   1.153      TRACE("-NDS_RenderCopy\n");
   1.154  
   1.155      return 0;
     2.1 --- a/test/nds-test-progs/general/source/main.c	Sat Aug 16 07:44:35 2008 +0000
     2.2 +++ b/test/nds-test-progs/general/source/main.c	Sat Aug 16 11:05:50 2008 +0000
     2.3 @@ -20,6 +20,7 @@
     2.4  	SDL_Joystick *stick;
     2.5  	SDL_Event event;
     2.6  	SDL_Rect rect = {8,8,240,176};
     2.7 +	int i;
     2.8  
     2.9  	consoleDemoInit();
    2.10  	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) {
    2.11 @@ -27,23 +28,22 @@
    2.12  		puts(SDL_GetError());
    2.13  		return 1;
    2.14  	}
    2.15 -	puts("* initialized SDL\n"); delay(1);
    2.16 -
    2.17 -	screen = SDL_SetVideoMode(256, 192, 16, SDL_SWSURFACE);
    2.18 +	puts("* initialized SDL\n");
    2.19 +	screen = SDL_SetVideoMode(256, 192, 15, SDL_SWSURFACE);
    2.20  	if(!screen) {
    2.21  		puts("# error setting video mode");
    2.22  		puts(SDL_GetError());
    2.23  		return 2;
    2.24  	}
    2.25 -	puts("* set video mode\n"); delay(1);
    2.26 -
    2.27 +	screen->flags &= ~SDL_PREALLOC;
    2.28 +	puts("* set video mode\n");
    2.29  	stick = SDL_JoystickOpen(0);
    2.30  	if(stick == NULL) {
    2.31  		puts("# error opening joystick");
    2.32  		puts(SDL_GetError());
    2.33  //		return 3;
    2.34  	}
    2.35 -	puts("* opened joystick"); delay(1);
    2.36 +	puts("* opened joystick");
    2.37  	SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000);
    2.38  	SDL_Flip(screen);
    2.39