comparison src/video/nds/SDL_ndsrender.c @ 2691:87cfb5fde5db gsoc2008_nds

Rendering now partially works! (Some BIZARRE bug that I inadvertently fixed.)
author Darren Alton <dalton@stevens.edu>
date Sat, 16 Aug 2008 11:05:50 +0000
parents ca01c20274c0
children cd8978f47849
comparison
equal deleted inserted replaced
2690:ca01c20274c0 2691:87cfb5fde5db
119 static int NDS_SetTextureBlendMode(SDL_Renderer * renderer, 119 static int NDS_SetTextureBlendMode(SDL_Renderer * renderer,
120 SDL_Texture * texture); 120 SDL_Texture * texture);
121 static int NDS_SetTextureScaleMode(SDL_Renderer * renderer, 121 static int NDS_SetTextureScaleMode(SDL_Renderer * renderer,
122 SDL_Texture * texture); 122 SDL_Texture * texture);
123 static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 123 static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
124 const SDL_Rect * rect, const void *pixels, 124 const SDL_Rect * rect, const void *pixels,
125 int pitch); 125 int pitch);
126 static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 126 static int NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
127 const SDL_Rect * rect, int markDirty, void **pixels, 127 const SDL_Rect * rect, int markDirty, void **pixels,
128 int *pitch); 128 int *pitch);
129 static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 129 static void NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
130 static void NDS_DirtyTexture(SDL_Renderer * renderer, 130 static void NDS_DirtyTexture(SDL_Renderer * renderer,
142 142
143 143
144 SDL_RenderDriver NDS_RenderDriver = { 144 SDL_RenderDriver NDS_RenderDriver = {
145 NDS_CreateRenderer, 145 NDS_CreateRenderer,
146 { "nds", /* char* name */ 146 { "nds", /* char* name */
147 (SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED), /* u32 flags */ 147 (SDL_RENDERER_SINGLEBUFFER |
148 SDL_RENDERER_ACCELERATED |
149 SDL_RENDERER_PRESENTDISCARD |
150 SDL_RENDERER_PRESENTVSYNC), /* u32 flags */
148 (SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */ 151 (SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */
149 (SDL_TEXTUREBLENDMODE_MASK), /* u32 blend_modes */ 152 (SDL_TEXTUREBLENDMODE_MASK), /* u32 blend_modes */
150 (SDL_TEXTURESCALEMODE_FAST), /* u32 scale_modes */ 153 (SDL_TEXTURESCALEMODE_FAST), /* u32 scale_modes */
151 3, /* u32 num_texture_formats */ 154 3, /* u32 num_texture_formats */
152 { 155 {
179 u16 *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */ 182 u16 *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */
180 u16 *vram_palette; /* where the palette data is stored if it's indexed.*/ 183 u16 *vram_palette; /* where the palette data is stored if it's indexed.*/
181 /*int size;*/ 184 /*int size;*/
182 } NDS_TextureData; 185 } NDS_TextureData;
183 186
184
185
186 void sdlds_splash() {
187 int i;
188 printf("splash!\n");
189 BG3_CR = BG_BMP16_256x256|BG_BMP_BASE(0);
190 BG3_XDX = 1 << 8; BG3_XDY = 0 << 8;
191 BG3_YDX = 0 << 8; BG3_YDY = 1 << 8;
192 BG3_CX = 0 << 8; BG3_CY = 0 << 8;
193 for(i = 0; i < 256*192; ++i) {
194 ((u16*)BG_BMP_RAM(0))[i] = i|0x8000;
195 }
196 printf("one... two...\n");
197 for(i = 0; i < 120; ++i) {
198 swiWaitForVBlank();
199 }
200 for(i = 0; i < 256*192; ++i) {
201 ((u16*)BG_BMP_RAM(0))[i] = 0;
202 }
203 BG3_CR = 0;
204 printf("done splash!\n");
205 }
206 187
207 188
208 SDL_Renderer * 189 SDL_Renderer *
209 NDS_CreateRenderer(SDL_Window * window, Uint32 flags) 190 NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
210 { 191 {
291 data->bg = &BACKGROUND_SUB; 272 data->bg = &BACKGROUND_SUB;
292 } 273 }
293 data->bg_taken[2] = data->bg_taken[3] = 0; 274 data->bg_taken[2] = data->bg_taken[3] = 0;
294 NDS_OAM_Init(&(data->oam_copy)); /* init sprites. */ 275 NDS_OAM_Init(&(data->oam_copy)); /* init sprites. */
295 276
296 sdlds_splash();
297
298 TRACE("-NDS_CreateRenderer\n"); 277 TRACE("-NDS_CreateRenderer\n");
278 printf("renderer is %x\n", (u32)(renderer->UpdateTexture));
299 return renderer; 279 return renderer;
300 } 280 }
301 281
302 static int 282 static int
303 NDS_ActivateRenderer(SDL_Renderer * renderer) 283 NDS_ActivateRenderer(SDL_Renderer * renderer)
342 txdat->type = NDSTX_SPR; 322 txdat->type = NDSTX_SPR;
343 } else if(texture->w <= 256 && texture->h <= 256) { 323 } else if(texture->w <= 256 && texture->h <= 256) {
344 int whichbg = -1, base = 0; 324 int whichbg = -1, base = 0;
345 if(!data->bg_taken[2]) { 325 if(!data->bg_taken[2]) {
346 whichbg = 2; 326 whichbg = 2;
327 data->bg->bg2_rotation.xdx = 0x100;
328 data->bg->bg2_rotation.xdy = 0;
329 data->bg->bg2_rotation.ydx = 0;
330 data->bg->bg2_rotation.ydy = 0x100;
331 data->bg->bg2_rotation.centerX = 0;
332 data->bg->bg2_rotation.centerY = 0;
347 } else if(!data->bg_taken[3]) { 333 } else if(!data->bg_taken[3]) {
348 whichbg = 3; 334 whichbg = 3;
335 data->bg->bg3_rotation.xdx = 0x100;
336 data->bg->bg3_rotation.xdy = 0;
337 data->bg->bg3_rotation.ydx = 0;
338 data->bg->bg3_rotation.ydy = 0x100;
339 data->bg->bg3_rotation.centerX = 0;
340 data->bg->bg3_rotation.centerY = 0;
349 base = 4; 341 base = 4;
350 } 342 }
351 if(whichbg >= 0) { 343 if(whichbg >= 0) {
352 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); 344 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
353 txdat = (NDS_TextureData*)texture->driverdata; 345 txdat = (NDS_TextureData*)texture->driverdata;
369 361
370 txdat->type = NDSTX_BG; 362 txdat->type = NDSTX_BG;
371 txdat->hw_index = whichbg; 363 txdat->hw_index = whichbg;
372 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0; 364 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0;
373 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; 365 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100;
374 txdat->dim.pitch = 256 * (bpp/8); 366 txdat->dim.pitch = 256 * ((bpp+1)/8);
375 txdat->dim.bpp = bpp; 367 txdat->dim.bpp = bpp;
376 txdat->vram_pixels = (u16*)(data->sub ? 368 txdat->vram_pixels = (u16*)(data->sub ?
377 BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base)); 369 BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base));
370
371 /* TESTING PURPOSES ONLY!!!
372 shows that the texture is set up properly on the screen. */
373 for(i = 0; i < 256*192; ++i) {
374 txdat->vram_pixels[i] = RGB15(31,31,0)|0x8000;
375 }
376 printf("--one... two...\n");
377 for(i = 0; i < 120; ++i) {
378 swiWaitForVBlank();
379 }
380 for(i = 0; i < 256*192; ++i) {
381 txdat->vram_pixels[i] = 0;
382 }
378 /*txdat->size = txdat->dim.pitch * texture->h;*/ 383 /*txdat->size = txdat->dim.pitch * texture->h;*/
379 } else { 384 } else {
380 SDL_SetError("Out of NDS backgrounds."); 385 SDL_SetError("Out of NDS backgrounds.");
381 printf("ran out.\n"); 386 printf("ran out.\n");
382 } 387 }
407 412
408 static int 413 static int
409 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 414 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
410 const SDL_Rect * rect, const void *pixels, int pitch) 415 const SDL_Rect * rect, const void *pixels, int pitch)
411 { 416 {
412 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; 417 NDS_TextureData *txdat;
413 Uint8 *src, *dst; 418 Uint8 *src, *dst;
414 int row; size_t length; 419 int row; size_t length;
415 TRACE("+NDS_UpdateTexture\n"); 420 TRACE("+NDS_UpdateTexture\n");
421 if(!texture) { printf("OH BOY!!!\n"); return -1; }
422 txdat = (NDS_TextureData *) texture->driverdata;
416 423
417 src = (Uint8 *) pixels; 424 src = (Uint8 *) pixels;
418 dst = 425 dst =
419 (Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch + 426 (Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch +
420 rect->x * (txdat->dim.bpp/8); 427 rect->x * ((txdat->dim.bpp+1)/8);
421 length = rect->w * (txdat->dim.bpp/8); 428 length = rect->w * ((txdat->dim.bpp+1)/8);
422 for (row = 0; row < rect->h; ++row) { 429 for (row = 0; row < rect->h; ++row) {
423 SDL_memcpy(dst, src, length); 430 SDL_memcpy(dst, src, length);
424 src += pitch; 431 src += pitch;
425 dst += txdat->dim.pitch; 432 dst += txdat->dim.pitch;
426 } 433 }
442 /* TODO: figure out how to handle this! */ 449 /* TODO: figure out how to handle this! */
443 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/ 450 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/
444 } 451 }
445 452
446 *pixels = (void *) ((u8 *)txdat->vram_pixels + rect->y 453 *pixels = (void *) ((u8 *)txdat->vram_pixels + rect->y
447 * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8)); 454 * txdat->dim.pitch + rect->x * ((txdat->dim.bpp+1)/8));
448 *pitch = txdat->dim.pitch; 455 *pitch = txdat->dim.pitch;
449 printf(" pixels = %08x\n", (u32)*pixels);
450 printf(" vram = %08x\n", (u32)(txdat->vram_pixels));
451 TRACE("-NDS_LockTexture\n"); 456 TRACE("-NDS_LockTexture\n");
452 return 0; 457 return 0;
453 } 458 }
454 459
455 static void 460 static void
515 tmpbg->ydy = txdat->dim.vdy; 520 tmpbg->ydy = txdat->dim.vdy;
516 tmpbg->centerX = 0; 521 tmpbg->centerX = 0;
517 tmpbg->centerY = 0; 522 tmpbg->centerY = 0;
518 } else { 523 } else {
519 /* sprites not implemented yet */ 524 /* sprites not implemented yet */
520 } 525 printf("tried to RenderCopy a sprite.\n");
521 printf(" txdat->hw_index = %d\n", txdat->hw_index); 526 }
522 TRACE("-NDS_RenderCopy\n"); 527 TRACE("-NDS_RenderCopy\n");
523 528
524 return 0; 529 return 0;
525 } 530 }
526 531