equal
deleted
inserted
replaced
107 { |
107 { |
108 enum { NDSTX_BG, NDSTX_SPR } type; |
108 enum { NDSTX_BG, NDSTX_SPR } type; |
109 int hw_index; |
109 int hw_index; |
110 struct { int hdx, hdy, vdx, vdy, pitch, bpp; } dim; |
110 struct { int hdx, hdy, vdx, vdy, pitch, bpp; } dim; |
111 u16 *vram; |
111 u16 *vram; |
|
112 u16 *system_ram_copy; |
|
113 int size; |
112 } NDS_TextureData; |
114 } NDS_TextureData; |
113 |
115 |
114 |
116 |
115 /* this is mainly hackish testing/debugging stuff to get cleaned up soon |
117 /* this is mainly hackish testing/debugging stuff to get cleaned up soon |
116 anything named sdlds_blah shouldn't make it into the stable version |
118 anything named sdlds_blah shouldn't make it into the stable version |
267 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; |
269 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; |
268 txdat->dim.pitch = 256 * (bpp/8); |
270 txdat->dim.pitch = 256 * (bpp/8); |
269 txdat->dim.bpp = bpp; |
271 txdat->dim.bpp = bpp; |
270 txdat->vram = (u16*)(data->sub ? |
272 txdat->vram = (u16*)(data->sub ? |
271 BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg)); |
273 BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg)); |
272 for(i = 0; i < 60; ++i) swiWaitForVBlank(); |
274 txdat->size = txdat->dim.pitch * texture->h; |
|
275 txdat->system_ram_copy = SDL_malloc(txdat->size); |
273 } else { |
276 } else { |
274 SDL_SetError("Out of NDS backgrounds."); |
277 SDL_SetError("Out of NDS backgrounds."); |
275 printf("ran out.\n"); |
278 printf("ran out.\n"); |
276 } |
279 } |
277 } else { |
280 } else { |
318 int row; |
321 int row; |
319 size_t length; |
322 size_t length; |
320 /* IMPORTANT! copy the new pixels into the sprite or bg. */ |
323 /* IMPORTANT! copy the new pixels into the sprite or bg. */ |
321 src = (Uint8 *) pixels; |
324 src = (Uint8 *) pixels; |
322 dst = |
325 dst = |
323 (Uint8 *) txdat->vram + rect->y * txdat->dim.pitch + |
326 (Uint8 *) txdat->system_ram_copy + rect->y * txdat->dim.pitch + |
324 rect->x * (txdat->dim.bpp/8); |
327 rect->x * (txdat->dim.bpp/8); |
325 length = rect->w * (txdat->dim.bpp/8); |
328 length = rect->w * (txdat->dim.bpp/8); |
326 for (row = 0; row < rect->h; ++row) { |
329 for (row = 0; row < rect->h; ++row) { |
327 SDL_memcpy(dst, src, length); |
330 SDL_memcpy(dst, src, length); |
328 src += pitch; |
331 src += pitch; |
348 if (markDirty) { |
351 if (markDirty) { |
349 printf("wanted to mark dirty\n"); |
352 printf("wanted to mark dirty\n"); |
350 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/ |
353 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/ |
351 } |
354 } |
352 |
355 |
353 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch |
356 *pixels = (void *) ((u8 *)txdat->system_ram_copy + rect->y |
354 + rect->x * (txdat->dim.bpp/8)); |
357 * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8)); |
355 *pitch = txdat->dim.pitch; |
358 *pitch = txdat->dim.pitch; |
356 printf(" pixels = %08x\n", (u32)*pixels); |
359 printf(" pixels = %08x\n", (u32)*pixels); |
357 printf("-NDS_LockTexture\n"); |
360 printf("-NDS_LockTexture\n"); |
358 return 0; |
361 return 0; |
359 } |
362 } |
401 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
404 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
402 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
405 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
403 { |
406 { |
404 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
407 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
405 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
408 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
406 // SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
409 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
407 // SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
410 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
408 int i; |
411 int i; |
409 int bpp = SDL_BYTESPERPIXEL(texture->format); |
412 int bpp = SDL_BYTESPERPIXEL(texture->format); |
410 int pitch = txdat->dim.pitch; |
413 int pitch = txdat->dim.pitch; |
411 printf("+NDS_RenderCopy\n"); |
414 printf("+NDS_RenderCopy\n"); |
412 if(txdat->type == NDSTX_BG) { |
415 if(txdat->type == NDSTX_BG) { |
429 |
432 |
430 static void |
433 static void |
431 NDS_RenderPresent(SDL_Renderer * renderer) |
434 NDS_RenderPresent(SDL_Renderer * renderer) |
432 { |
435 { |
433 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
436 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
434 /* Send the data to the display TODO */ |
437 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
435 /* shouldn't it already be there at this point? |
438 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
|
439 int i; |
|
440 /* Send the data to the display TODO : |
|
441 shouldn't it already be there at this point? |
436 I guess set the BG's and sprites "visible" flags here. */ |
442 I guess set the BG's and sprites "visible" flags here. */ |
437 printf("+NDS_RenderPresent\n"); |
443 printf("+NDS_RenderPresent\n"); |
|
444 |
|
445 for(i = 0; i < 64; ++i) { |
|
446 SDL_Texture * tx = display->textures[i]; |
|
447 NDS_TextureData * txdat = (NDS_TextureData*)tx->driverdata; |
|
448 SDL_memcpy(txdat->vram, txdat->system_ram_copy, txdat->size); |
|
449 } |
438 |
450 |
439 /* vsync for NDS */ |
451 /* vsync for NDS */ |
440 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { |
452 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { |
441 swiWaitForVBlank(); |
453 swiWaitForVBlank(); |
442 } |
454 } |
451 SDL_SetError("Unsupported texture format"); |
463 SDL_SetError("Unsupported texture format"); |
452 } else { |
464 } else { |
453 /* free anything else allocated for texture */ |
465 /* free anything else allocated for texture */ |
454 NDS_TextureData *txdat = texture->driverdata; |
466 NDS_TextureData *txdat = texture->driverdata; |
455 /*SDL_FreeDirtyRects(&txdat->dirty);*/ |
467 /*SDL_FreeDirtyRects(&txdat->dirty);*/ |
|
468 SDL_free(txdat->system_ram_copy); |
456 SDL_free(txdat); |
469 SDL_free(txdat); |
457 } |
470 } |
458 printf("-NDS_DestroyTexture\n"); |
471 printf("-NDS_DestroyTexture\n"); |
459 } |
472 } |
460 |
473 |