Mercurial > sdl-ios-xcode
comparison src/video/nds/SDL_ndsrender.c @ 2685:2190b873ff00 gsoc2008_nds
Making room for test prog's
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Wed, 13 Aug 2008 00:45:35 +0000 |
parents | e858ac8868b6 |
children | 5166b19b6808 |
comparison
equal
deleted
inserted
replaced
2684:a4f143d187dd | 2685:2190b873ff00 |
---|---|
30 #include "../SDL_sysvideo.h" | 30 #include "../SDL_sysvideo.h" |
31 #include "../SDL_yuv_sw_c.h" | 31 #include "../SDL_yuv_sw_c.h" |
32 #include "../SDL_renderer_sw.h" | 32 #include "../SDL_renderer_sw.h" |
33 | 33 |
34 | 34 |
35 /* SDL surface based renderer implementation */ | 35 /* SDL NDS renderer implementation */ |
36 | 36 |
37 static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags); | 37 static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags); |
38 static int NDS_ActivateRenderer(SDL_Renderer * renderer); | 38 static int NDS_ActivateRenderer(SDL_Renderer * renderer); |
39 static int NDS_DisplayModeChanged(SDL_Renderer * renderer); | 39 static int NDS_DisplayModeChanged(SDL_Renderer * renderer); |
40 static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 40 static int NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
97 | 97 |
98 typedef struct | 98 typedef struct |
99 { | 99 { |
100 bg_attribute *bg; | 100 bg_attribute *bg; |
101 u8 bg_taken[4]; | 101 u8 bg_taken[4]; |
102 /* todo for sprites: pSpriteRotation and pSpriteEntry. pointers to OAM */ | |
102 int sub; | 103 int sub; |
103 } NDS_RenderData; | 104 } NDS_RenderData; |
104 | 105 |
105 typedef struct | 106 typedef struct |
106 { | 107 { |
107 enum { NDSTX_BG, NDSTX_SPR } type; | 108 enum { NDSTX_BG, NDSTX_SPR } type; |
108 int hw_index; | 109 int hw_index; |
109 struct { int w, h, pitch, bpp; } dim; | 110 struct { int hdx, hdy, vdx, vdy, pitch, bpp; } dim; |
110 u16 *vram; | 111 u16 *vram; |
111 } NDS_TextureData; | 112 } NDS_TextureData; |
112 | 113 |
113 | 114 |
114 /* this is mainly hackish testing/debugging stuff to get cleaned up soon | 115 /* this is mainly hackish testing/debugging stuff to get cleaned up soon |
121 /* hack to get the proper colors until I actually get BGR555 to work right */ | 122 /* hack to get the proper colors until I actually get BGR555 to work right */ |
122 u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b; | 123 u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b; |
123 r = (c & Rmask) >> 10; | 124 r = (c & Rmask) >> 10; |
124 b = (c & Bmask) << 10; | 125 b = (c & Bmask) << 10; |
125 return (c & GAmask) | r | b; | 126 return (c & GAmask) | r | b; |
126 } | |
127 | |
128 void | |
129 sdlds_print_pixfmt_info(SDL_PixelFormat * f) | |
130 { | |
131 if (!f) | |
132 return; | |
133 printf("bpp: %d\nRGBA: %x %x %x %x\n", | |
134 f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask); | |
135 } | |
136 | |
137 void | |
138 sdlds_print_surface_info(SDL_Surface * s) | |
139 { | |
140 if (!s) | |
141 return; | |
142 printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n", | |
143 s->flags, s->w, s->h, s->pitch, s->locked, s->refcount); | |
144 sdlds_print_pixfmt_info(s->format); | |
145 } | 127 } |
146 | 128 |
147 /* again the above shouldn't make it into the stable version */ | 129 /* again the above shouldn't make it into the stable version */ |
148 | 130 |
149 SDL_Renderer * | 131 SDL_Renderer * |
267 sprites not implemented yet. elegant, I know. | 249 sprites not implemented yet. elegant, I know. |
268 } else*/ if(texture->w <= 256 && texture->h <= 256) { | 250 } else*/ if(texture->w <= 256 && texture->h <= 256) { |
269 int whichbg = -1; | 251 int whichbg = -1; |
270 if(!data->bg_taken[2]) { | 252 if(!data->bg_taken[2]) { |
271 whichbg = 2; | 253 whichbg = 2; |
272 data->bg->bg2_rotation.xdx = 0x100; | |
273 data->bg->bg2_rotation.xdy = 0; | |
274 data->bg->bg2_rotation.ydx = 0; | |
275 data->bg->bg2_rotation.ydy = 0x100; | |
276 data->bg->bg2_rotation.centerX = 0; | |
277 data->bg->bg2_rotation.centerY = 0; | |
278 } else if(!data->bg_taken[3]) { | 254 } else if(!data->bg_taken[3]) { |
279 whichbg = 3; | 255 whichbg = 3; |
280 data->bg->bg3_rotation.xdx = 0x100; | |
281 data->bg->bg3_rotation.xdy = 0; | |
282 data->bg->bg3_rotation.ydx = 0; | |
283 data->bg->bg3_rotation.ydy = 0x100; | |
284 data->bg->bg3_rotation.centerX = 0; | |
285 data->bg->bg3_rotation.centerY = 0; | |
286 } | 256 } |
287 if(whichbg >= 0) { | 257 if(whichbg >= 0) { |
288 data->bg->control[whichbg] = (bpp == 8) ? | 258 data->bg->control[whichbg] = (bpp == 8) ? |
289 BG_BMP8_256x256 : BG_BMP16_256x256; | 259 BG_BMP8_256x256 : BG_BMP16_256x256; |
290 data->bg->scroll[whichbg].x = 0; | 260 data->bg->scroll[whichbg].x = 0; |
291 data->bg->scroll[whichbg].y = 0; | 261 data->bg->scroll[whichbg].y = 0; |
292 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); | 262 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); |
293 txdat = (NDS_TextureData*)texture->driverdata; | 263 txdat = (NDS_TextureData*)texture->driverdata; |
294 txdat->type = NDSTX_BG; | 264 txdat->type = NDSTX_BG; |
295 txdat->hw_index = whichbg; | 265 txdat->hw_index = whichbg; |
296 txdat->dim.w = texture->w; | 266 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0; |
297 txdat->dim.h = texture->h; | 267 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; |
298 txdat->dim.pitch = 256 * (bpp/8); | 268 txdat->dim.pitch = 256 * (bpp/8); |
299 txdat->dim.bpp = bpp; | 269 txdat->dim.bpp = bpp; |
300 txdat->vram = (u16*)(data->sub ? | 270 txdat->vram = (u16*)(data->sub ? |
301 BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg)); | 271 BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg)); |
302 for(i = 0; i < 256*256; ++i) { | |
303 txdat->vram[i] = 0x8000|RGB15(0,31,31); | |
304 } | |
305 for(i = 0; i < 60; ++i) swiWaitForVBlank(); | 272 for(i = 0; i < 60; ++i) swiWaitForVBlank(); |
306 } else { | 273 } else { |
307 SDL_SetError("Out of NDS backgrounds."); | 274 SDL_SetError("Out of NDS backgrounds."); |
275 printf("ran out.\n"); | |
308 } | 276 } |
309 } else { | 277 } else { |
310 SDL_SetError("Texture too big for NDS hardware."); | 278 SDL_SetError("Texture too big for NDS hardware."); |
311 } | 279 } |
312 } | 280 } |
332 *pixels = txdat->vram; | 300 *pixels = txdat->vram; |
333 *pitch = txdat->dim.pitch; | 301 *pitch = txdat->dim.pitch; |
334 printf("-NDS_QueryTexturePixels\n"); | 302 printf("-NDS_QueryTexturePixels\n"); |
335 return 0; | 303 return 0; |
336 } | 304 } |
337 } | |
338 | |
339 static int | |
340 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | |
341 const SDL_Color * colors, int firstcolor, int ncolors) | |
342 { | |
343 printf("+NDS_SetTexturePalette\n"); | |
344 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
345 SDL_SetError("YUV textures don't have a palette"); | |
346 return -1; | |
347 } else { | |
348 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
349 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ | |
350 printf("-NDS_SetTexturePalette\n"); | |
351 return 0; | |
352 } | |
353 } | |
354 | |
355 static int | |
356 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | |
357 SDL_Color * colors, int firstcolor, int ncolors) | |
358 { | |
359 printf("+NDS_GetTexturePalette\n"); | |
360 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
361 SDL_SetError("YUV textures don't have a palette"); | |
362 return -1; | |
363 } else { | |
364 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
365 printf("-NDS_GetTexturePalette\n"); | |
366 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ | |
367 return 0; | |
368 } | |
369 } | |
370 | |
371 static int | |
372 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
373 { | |
374 printf("!NDS_SetTextureColorMod\n"); | |
375 /* stub. TODO: figure out what needs to be done, if anything */ | |
376 return 0; | |
377 } | |
378 | |
379 static int | |
380 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
381 { | |
382 printf("!NDS_SetTextureAlphaMod\n"); | |
383 /* stub. TODO: figure out what needs to be done, if anything */ | |
384 return 0; | |
385 } | |
386 | |
387 static int | |
388 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
389 { | |
390 printf("!NDS_SetTextureBlendMode\n"); | |
391 /* stub. TODO: figure out what needs to be done, if anything */ | |
392 return 0; | |
393 } | |
394 | |
395 static int | |
396 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
397 { | |
398 printf("!NDS_SetTextureScaleMode\n"); | |
399 /* stub. TODO: figure out what needs to be done. | |
400 (NDS hardware scaling is nearest neighbor.) */ | |
401 return 0; | |
402 } | 305 } |
403 | 306 |
404 static int | 307 static int |
405 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 308 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
406 const SDL_Rect * rect, const void *pixels, int pitch) | 309 const SDL_Rect * rect, const void *pixels, int pitch) |
441 return -1; | 344 return -1; |
442 } else { | 345 } else { |
443 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | 346 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
444 | 347 |
445 if (markDirty) { | 348 if (markDirty) { |
349 printf("wanted to mark dirty\n"); | |
446 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/ | 350 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/ |
447 } | 351 } |
448 | 352 |
449 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch | 353 *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch |
450 + rect->x * (txdat->dim.bpp/8)); | 354 + rect->x * (txdat->dim.bpp/8)); |
451 *pitch = txdat->dim.pitch; | 355 *pitch = txdat->dim.pitch; |
356 printf(" pixels = %08x\n", (u32)*pixels); | |
452 printf("-NDS_LockTexture\n"); | 357 printf("-NDS_LockTexture\n"); |
453 return 0; | 358 return 0; |
454 } | 359 } |
455 } | 360 } |
456 | 361 |
499 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 404 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
500 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | 405 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
501 // SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 406 // SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
502 // SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 407 // SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
503 int i; | 408 int i; |
409 int bpp = SDL_BYTESPERPIXEL(texture->format); | |
410 int pitch = txdat->dim.pitch; | |
504 printf("+NDS_RenderCopy\n"); | 411 printf("+NDS_RenderCopy\n"); |
505 /*for(i = 0; i <= 0xFFFF; ++i) { | 412 if(txdat->type == NDSTX_BG) { |
506 txdat->vram[i] = 0x8000|i; | 413 bg_rotation *tmpbg = (txdat->hw_index == 2) ? |
507 }*/ | 414 &(data->bg->bg2_rotation) : &(data->bg->bg3_rotation); |
508 printf("/txdat->hw_index = %d\n", txdat->hw_index); | 415 tmpbg->xdx = txdat->dim.hdx; |
509 #if 0 | 416 tmpbg->xdy = txdat->dim.hdy; |
510 if (txdat->dirty.list) { | 417 tmpbg->ydx = txdat->dim.vdx; |
511 SDL_DirtyRect *dirty; | 418 tmpbg->ydy = txdat->dim.vdy; |
512 void *pixels; | 419 tmpbg->centerX = 0; |
513 int bpp = SDL_BYTESPERPIXEL(texture->format); | 420 tmpbg->centerY = 0; |
514 int pitch = txdat->pitch; | 421 } else { |
515 /* below was borrowed from SDL_renderer_gl.c. doesn't work, obv. | 422 /* sprites not implemented yet */ |
516 figure out how to get the graphics data into VRAM. */ | 423 } |
517 | 424 printf(" txdat->hw_index = %d\n", txdat->hw_index); |
518 for (dirty = txdat->dirty.list; dirty; dirty = dirty->next) { | |
519 SDL_Rect *rect = &dirty->rect; | |
520 /*pixels = | |
521 (void *) ((Uint8 *) txdat->vram + rect->y * pitch + | |
522 rect->x * bpp); | |
523 data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y, | |
524 rect->w, rect->h, texturedata->format, | |
525 texturedata->formattype, pixels);*/ | |
526 } | |
527 SDL_ClearDirtyRects(&txdat->dirty); | |
528 } | |
529 #endif | |
530 printf("-NDS_RenderCopy\n"); | 425 printf("-NDS_RenderCopy\n"); |
531 return 0; | 426 return 0; |
532 } | 427 } |
533 | 428 |
534 | 429 |
535 static void | 430 static void |
536 NDS_RenderPresent(SDL_Renderer * renderer) | 431 NDS_RenderPresent(SDL_Renderer * renderer) |
537 { | 432 { |
538 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 433 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
539 /* Send the data to the display TODO */ | 434 /* Send the data to the display TODO */ |
540 | 435 /* shouldn't it already be there at this point? |
436 I guess set the BG's and sprites "visible" flags here. */ | |
541 printf("+NDS_RenderPresent\n"); | 437 printf("+NDS_RenderPresent\n"); |
542 /* Update the flipping chain, if any */ | 438 |
439 /* vsync for NDS */ | |
543 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { | 440 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { |
544 swiWaitForVBlank(); | 441 swiWaitForVBlank(); |
545 } | 442 } |
546 printf("-NDS_RenderPresent\n"); | 443 printf("-NDS_RenderPresent\n"); |
547 } | 444 } |
590 } | 487 } |
591 SDL_free(renderer); | 488 SDL_free(renderer); |
592 printf("-NDS_DestroyRenderer\n"); | 489 printf("-NDS_DestroyRenderer\n"); |
593 } | 490 } |
594 | 491 |
492 static int | |
493 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | |
494 const SDL_Color * colors, int firstcolor, int ncolors) | |
495 { | |
496 printf("+NDS_SetTexturePalette\n"); | |
497 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
498 SDL_SetError("YUV textures don't have a palette"); | |
499 return -1; | |
500 } else { | |
501 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
502 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ | |
503 printf("-NDS_SetTexturePalette\n"); | |
504 return 0; | |
505 } | |
506 } | |
507 | |
508 static int | |
509 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | |
510 SDL_Color * colors, int firstcolor, int ncolors) | |
511 { | |
512 printf("+NDS_GetTexturePalette\n"); | |
513 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
514 SDL_SetError("YUV textures don't have a palette"); | |
515 return -1; | |
516 } else { | |
517 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | |
518 printf("-NDS_GetTexturePalette\n"); | |
519 /* TODO: mess with 8-bit modes and/or 16-color palette modes */ | |
520 return 0; | |
521 } | |
522 } | |
523 | |
524 static int | |
525 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
526 { | |
527 printf("!NDS_SetTextureColorMod\n"); | |
528 /* stub. TODO: figure out what needs to be done, if anything */ | |
529 return 0; | |
530 } | |
531 | |
532 static int | |
533 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
534 { | |
535 printf("!NDS_SetTextureAlphaMod\n"); | |
536 /* stub. TODO: figure out what needs to be done, if anything */ | |
537 return 0; | |
538 } | |
539 | |
540 static int | |
541 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
542 { | |
543 printf("!NDS_SetTextureBlendMode\n"); | |
544 /* stub. TODO: figure out what needs to be done, if anything */ | |
545 return 0; | |
546 } | |
547 | |
548 static int | |
549 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
550 { | |
551 printf("!NDS_SetTextureScaleMode\n"); | |
552 /* stub. TODO: figure out what needs to be done. | |
553 (NDS hardware scaling is nearest neighbor.) */ | |
554 return 0; | |
555 } | |
556 | |
595 /* vi: set ts=4 sw=4 expandtab: */ | 557 /* vi: set ts=4 sw=4 expandtab: */ |