1.1 --- a/src/video/nds/SDL_ndsrender.c Wed Aug 13 00:49:03 2008 +0000
1.2 +++ b/src/video/nds/SDL_ndsrender.c Thu Aug 14 04:33:55 2008 +0000
1.3 @@ -109,6 +109,8 @@
1.4 int hw_index;
1.5 struct { int hdx, hdy, vdx, vdy, pitch, bpp; } dim;
1.6 u16 *vram;
1.7 + u16 *system_ram_copy;
1.8 + int size;
1.9 } NDS_TextureData;
1.10
1.11
1.12 @@ -269,7 +271,8 @@
1.13 txdat->dim.bpp = bpp;
1.14 txdat->vram = (u16*)(data->sub ?
1.15 BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg));
1.16 - for(i = 0; i < 60; ++i) swiWaitForVBlank();
1.17 + txdat->size = txdat->dim.pitch * texture->h;
1.18 + txdat->system_ram_copy = SDL_malloc(txdat->size);
1.19 } else {
1.20 SDL_SetError("Out of NDS backgrounds.");
1.21 printf("ran out.\n");
1.22 @@ -320,7 +323,7 @@
1.23 /* IMPORTANT! copy the new pixels into the sprite or bg. */
1.24 src = (Uint8 *) pixels;
1.25 dst =
1.26 - (Uint8 *) txdat->vram + rect->y * txdat->dim.pitch +
1.27 + (Uint8 *) txdat->system_ram_copy + rect->y * txdat->dim.pitch +
1.28 rect->x * (txdat->dim.bpp/8);
1.29 length = rect->w * (txdat->dim.bpp/8);
1.30 for (row = 0; row < rect->h; ++row) {
1.31 @@ -350,8 +353,8 @@
1.32 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/
1.33 }
1.34
1.35 - *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
1.36 - + rect->x * (txdat->dim.bpp/8));
1.37 + *pixels = (void *) ((u8 *)txdat->system_ram_copy + rect->y
1.38 + * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8));
1.39 *pitch = txdat->dim.pitch;
1.40 printf(" pixels = %08x\n", (u32)*pixels);
1.41 printf("-NDS_LockTexture\n");
1.42 @@ -403,8 +406,8 @@
1.43 {
1.44 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
1.45 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
1.46 -// SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1.47 -// SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1.48 + SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1.49 + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1.50 int i;
1.51 int bpp = SDL_BYTESPERPIXEL(texture->format);
1.52 int pitch = txdat->dim.pitch;
1.53 @@ -431,11 +434,20 @@
1.54 NDS_RenderPresent(SDL_Renderer * renderer)
1.55 {
1.56 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
1.57 - /* Send the data to the display TODO */
1.58 - /* shouldn't it already be there at this point?
1.59 + SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1.60 + SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
1.61 + int i;
1.62 + /* Send the data to the display TODO :
1.63 + shouldn't it already be there at this point?
1.64 I guess set the BG's and sprites "visible" flags here. */
1.65 printf("+NDS_RenderPresent\n");
1.66
1.67 + for(i = 0; i < 64; ++i) {
1.68 + SDL_Texture * tx = display->textures[i];
1.69 + NDS_TextureData * txdat = (NDS_TextureData*)tx->driverdata;
1.70 + SDL_memcpy(txdat->vram, txdat->system_ram_copy, txdat->size);
1.71 + }
1.72 +
1.73 /* vsync for NDS */
1.74 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
1.75 swiWaitForVBlank();
1.76 @@ -453,6 +465,7 @@
1.77 /* free anything else allocated for texture */
1.78 NDS_TextureData *txdat = texture->driverdata;
1.79 /*SDL_FreeDirtyRects(&txdat->dirty);*/
1.80 + SDL_free(txdat->system_ram_copy);
1.81 SDL_free(txdat);
1.82 }
1.83 printf("-NDS_DestroyTexture\n");