Mercurial > sdl-ios-xcode
comparison src/video/nds/SDL_ndsrender.c @ 2690:ca01c20274c0 gsoc2008_nds
More work and some bugfixes on the graphics driver.
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Sat, 16 Aug 2008 07:44:35 +0000 |
parents | 71c56e900f8b |
children | 87cfb5fde5db |
comparison
equal
deleted
inserted
replaced
2689:e065c9f6a393 | 2690:ca01c20274c0 |
---|---|
32 #include "SDL_video.h" | 32 #include "SDL_video.h" |
33 #include "../SDL_sysvideo.h" | 33 #include "../SDL_sysvideo.h" |
34 #include "../SDL_yuv_sw_c.h" | 34 #include "../SDL_yuv_sw_c.h" |
35 #include "../SDL_renderer_sw.h" | 35 #include "../SDL_renderer_sw.h" |
36 | 36 |
37 | 37 #define TRACE |
38 //#define TRACE printf | |
38 | 39 |
39 /* NDS sprite-related functions */ | 40 /* NDS sprite-related functions */ |
40 #define SPRITE_DMA_CHANNEL 3 | 41 #define SPRITE_DMA_CHANNEL 3 |
41 #define SPRITE_ANGLE_MASK 0x01FF | 42 #define SPRITE_ANGLE_MASK 0x01FF |
42 | 43 |
143 SDL_RenderDriver NDS_RenderDriver = { | 144 SDL_RenderDriver NDS_RenderDriver = { |
144 NDS_CreateRenderer, | 145 NDS_CreateRenderer, |
145 { "nds", /* char* name */ | 146 { "nds", /* char* name */ |
146 (SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED), /* u32 flags */ | 147 (SDL_RENDERER_SINGLEBUFFER|SDL_RENDERER_ACCELERATED), /* u32 flags */ |
147 (SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */ | 148 (SDL_TEXTUREMODULATE_NONE), /* u32 mod_modes */ |
148 (SDL_TEXTUREBLENDMODE_NONE), /* u32 blend_modes */ | 149 (SDL_TEXTUREBLENDMODE_MASK), /* u32 blend_modes */ |
149 (SDL_TEXTURESCALEMODE_NONE), /* u32 scale_modes */ | 150 (SDL_TEXTURESCALEMODE_FAST), /* u32 scale_modes */ |
150 3, /* u32 num_texture_formats */ | 151 3, /* u32 num_texture_formats */ |
151 { | 152 { |
152 SDL_PIXELFORMAT_INDEX8, | 153 SDL_PIXELFORMAT_INDEX8, |
153 SDL_PIXELFORMAT_ABGR1555, | 154 SDL_PIXELFORMAT_ABGR1555, |
154 SDL_PIXELFORMAT_BGR555, | 155 SDL_PIXELFORMAT_BGR555, |
166 int sub; | 167 int sub; |
167 } NDS_RenderData; | 168 } NDS_RenderData; |
168 | 169 |
169 typedef struct | 170 typedef struct |
170 { | 171 { |
171 enum { NDSTX_BG, NDSTX_SPR } type; | 172 enum { NDSTX_BG, NDSTX_SPR } type; /* represented in a bg or sprite. */ |
172 int hw_index; | 173 int hw_index; /* sprite: index in the OAM. bg: 2 or 3. */ |
173 struct { int hdx, hdy, vdx, vdy, pitch, bpp; } dim; | 174 struct |
174 u16 *vram; | 175 { |
175 u16 *system_ram_copy; | 176 int hdx, hdy, vdx, vdy; /* affine transformation, used for scaling. */ |
176 int size; | 177 int pitch, bpp; /* some useful info */ |
178 } dim; | |
179 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.*/ | |
181 /*int size;*/ | |
177 } NDS_TextureData; | 182 } NDS_TextureData; |
178 | 183 |
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 } | |
179 | 206 |
180 | 207 |
181 SDL_Renderer * | 208 SDL_Renderer * |
182 NDS_CreateRenderer(SDL_Window * window, Uint32 flags) | 209 NDS_CreateRenderer(SDL_Window * window, Uint32 flags) |
183 { | 210 { |
187 NDS_RenderData *data; | 214 NDS_RenderData *data; |
188 int i, n; | 215 int i, n; |
189 int bpp; | 216 int bpp; |
190 Uint32 Rmask, Gmask, Bmask, Amask; | 217 Uint32 Rmask, Gmask, Bmask, Amask; |
191 | 218 |
192 printf("+NDS_CreateRenderer\n"); | 219 TRACE("+NDS_CreateRenderer\n"); |
193 if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, | 220 if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp, |
194 &Rmask, &Gmask, &Bmask, &Amask)) { | 221 &Rmask, &Gmask, &Bmask, &Amask)) { |
195 SDL_SetError("Unknown display format"); | 222 SDL_SetError("Unknown display format"); |
196 return NULL; | 223 return NULL; |
197 } | 224 } |
247 renderer->info.scale_modes = NDS_RenderDriver.info.scale_modes; | 274 renderer->info.scale_modes = NDS_RenderDriver.info.scale_modes; |
248 renderer->info.num_texture_formats = | 275 renderer->info.num_texture_formats = |
249 NDS_RenderDriver.info.num_texture_formats; | 276 NDS_RenderDriver.info.num_texture_formats; |
250 SDL_memcpy(renderer->info.texture_formats, | 277 SDL_memcpy(renderer->info.texture_formats, |
251 NDS_RenderDriver.info.texture_formats, | 278 NDS_RenderDriver.info.texture_formats, |
252 sizeof(renderer->info.texture_formats));; | 279 sizeof(renderer->info.texture_formats)); |
253 renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width; | 280 renderer->info.max_texture_width = |
281 NDS_RenderDriver.info.max_texture_width; | |
254 renderer->info.max_texture_height = | 282 renderer->info.max_texture_height = |
255 NDS_RenderDriver.info.max_texture_height; | 283 NDS_RenderDriver.info.max_texture_height; |
256 | |
257 data->bg = &BACKGROUND; /* BACKGROUND_SUB for second screen. */ | |
258 data->bg_taken[2] = data->bg_taken[3] = 0; | |
259 NDS_OAM_Init(&(data->oam_copy)); /* init sprites. */ | |
260 | 284 |
261 data->sub = 0; /* TODO: this is hard-coded to the "main" screen. | 285 data->sub = 0; /* TODO: this is hard-coded to the "main" screen. |
262 figure out how to detect whether to set it to | 286 figure out how to detect whether to set it to |
263 "sub" screen. window->id, perhaps? */ | 287 "sub" screen. window->id, perhaps? */ |
264 | 288 if(!data->sub) { |
265 printf("-NDS_CreateRenderer\n"); | 289 data->bg = &BACKGROUND; |
290 } else { | |
291 data->bg = &BACKGROUND_SUB; | |
292 } | |
293 data->bg_taken[2] = data->bg_taken[3] = 0; | |
294 NDS_OAM_Init(&(data->oam_copy)); /* init sprites. */ | |
295 | |
296 sdlds_splash(); | |
297 | |
298 TRACE("-NDS_CreateRenderer\n"); | |
266 return renderer; | 299 return renderer; |
267 } | 300 } |
268 | 301 |
269 static int | 302 static int |
270 NDS_ActivateRenderer(SDL_Renderer * renderer) | 303 NDS_ActivateRenderer(SDL_Renderer * renderer) |
271 { | 304 { |
272 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 305 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
273 printf("!NDS_ActivateRenderer\n"); | 306 TRACE("!NDS_ActivateRenderer\n"); |
274 return 0; | 307 return 0; |
275 } | 308 } |
276 | 309 |
277 static int | 310 static int |
278 NDS_DisplayModeChanged(SDL_Renderer * renderer) | 311 NDS_DisplayModeChanged(SDL_Renderer * renderer) |
279 { | 312 { |
280 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 313 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
281 printf("!NDS_DisplayModeChanged\n"); | 314 TRACE("!NDS_DisplayModeChanged\n"); |
282 return 0; | 315 return 0; |
283 } | 316 } |
284 | 317 |
285 static int | 318 static int |
286 NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 319 NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
289 NDS_TextureData *txdat = NULL; | 322 NDS_TextureData *txdat = NULL; |
290 int i; | 323 int i; |
291 int bpp; | 324 int bpp; |
292 Uint32 Rmask, Gmask, Bmask, Amask; | 325 Uint32 Rmask, Gmask, Bmask, Amask; |
293 | 326 |
294 printf("+NDS_CreateTexture\n"); | 327 TRACE("+NDS_CreateTexture\n"); |
295 if (!SDL_PixelFormatEnumToMasks | 328 if (!SDL_PixelFormatEnumToMasks |
296 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | 329 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
297 SDL_SetError("Unknown texture format"); | 330 SDL_SetError("Unknown texture format"); |
298 return -1; | 331 return -1; |
299 } | 332 } |
304 /* TODO: implement sprites similar to how BG's are. | 337 /* TODO: implement sprites similar to how BG's are. |
305 they have a similar affine transformation matrix | 338 they have a similar affine transformation matrix |
306 (hdx,hdy,vdx,vdy) as the backgrounds, so it should | 339 (hdx,hdy,vdx,vdy) as the backgrounds, so it should |
307 be similar enough to handle with the same driverdata. */ | 340 be similar enough to handle with the same driverdata. */ |
308 printf("Tried to make a sprite.\n"); | 341 printf("Tried to make a sprite.\n"); |
342 txdat->type = NDSTX_SPR; | |
309 } else if(texture->w <= 256 && texture->h <= 256) { | 343 } else if(texture->w <= 256 && texture->h <= 256) { |
310 int whichbg = -1; | 344 int whichbg = -1, base = 0; |
311 if(!data->bg_taken[2]) { | 345 if(!data->bg_taken[2]) { |
312 whichbg = 2; | 346 whichbg = 2; |
313 } else if(!data->bg_taken[3]) { | 347 } else if(!data->bg_taken[3]) { |
314 whichbg = 3; | 348 whichbg = 3; |
349 base = 4; | |
315 } | 350 } |
316 if(whichbg >= 0) { | 351 if(whichbg >= 0) { |
352 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); | |
353 txdat = (NDS_TextureData*)texture->driverdata; | |
354 if(!txdat) { | |
355 SDL_OutOfMemory(); | |
356 return -1; | |
357 } | |
358 | |
317 /* TODO: maybe this should be in RenderPresent or RenderCopy | 359 /* TODO: maybe this should be in RenderPresent or RenderCopy |
318 instead, copying from a malloc'd system RAM pixel buffer. */ | 360 instead, copying from a malloc'd system RAM pixel buffer. */ |
361 /* this is hard-coded to being 256x256 for now. */ | |
319 data->bg->control[whichbg] = (bpp == 8) ? | 362 data->bg->control[whichbg] = (bpp == 8) ? |
320 BG_BMP8_256x256 : BG_BMP16_256x256; | 363 BG_BMP8_256x256 : BG_BMP16_256x256; |
364 | |
365 data->bg->control[whichbg] |= BG_BMP_BASE(base); | |
366 | |
321 data->bg->scroll[whichbg].x = 0; | 367 data->bg->scroll[whichbg].x = 0; |
322 data->bg->scroll[whichbg].y = 0; | 368 data->bg->scroll[whichbg].y = 0; |
323 texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData)); | 369 |
324 txdat = (NDS_TextureData*)texture->driverdata; | |
325 txdat->type = NDSTX_BG; | 370 txdat->type = NDSTX_BG; |
326 txdat->hw_index = whichbg; | 371 txdat->hw_index = whichbg; |
327 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0; | 372 txdat->dim.hdx = 0x100; txdat->dim.hdy = 0; |
328 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; | 373 txdat->dim.vdx = 0; txdat->dim.vdy = 0x100; |
329 txdat->dim.pitch = 256 * (bpp/8); | 374 txdat->dim.pitch = 256 * (bpp/8); |
330 txdat->dim.bpp = bpp; | 375 txdat->dim.bpp = bpp; |
331 txdat->vram = (u16*)(data->sub ? | 376 txdat->vram_pixels = (u16*)(data->sub ? |
332 BG_BMP_RAM_SUB(whichbg) : BG_BMP_RAM(whichbg)); | 377 BG_BMP_RAM_SUB(base) : BG_BMP_RAM(base)); |
333 txdat->size = txdat->dim.pitch * texture->h; | 378 /*txdat->size = txdat->dim.pitch * texture->h;*/ |
334 } else { | 379 } else { |
335 SDL_SetError("Out of NDS backgrounds."); | 380 SDL_SetError("Out of NDS backgrounds."); |
336 printf("ran out.\n"); | 381 printf("ran out.\n"); |
337 } | 382 } |
338 } else { | 383 } else { |
339 SDL_SetError("Texture too big for NDS hardware."); | 384 SDL_SetError("Texture too big for NDS hardware."); |
340 } | 385 } |
341 | 386 |
342 printf("-NDS_CreateTexture\n"); | 387 TRACE("-NDS_CreateTexture\n"); |
343 if (!texture->driverdata) { | 388 if (!texture->driverdata) { |
344 SDL_SetError("Couldn't create NDS render driver data."); | 389 SDL_SetError("Couldn't create NDS render driver data."); |
345 return -1; | 390 return -1; |
346 } | 391 } |
347 | 392 |
351 static int | 396 static int |
352 NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, | 397 NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, |
353 void **pixels, int *pitch) | 398 void **pixels, int *pitch) |
354 { | 399 { |
355 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | 400 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
356 printf("+NDS_QueryTexturePixels\n"); | 401 TRACE("+NDS_QueryTexturePixels\n"); |
357 *pixels = txdat->vram; | 402 *pixels = txdat->vram_pixels; |
358 *pitch = txdat->dim.pitch; | 403 *pitch = txdat->dim.pitch; |
359 printf("-NDS_QueryTexturePixels\n"); | 404 TRACE("-NDS_QueryTexturePixels\n"); |
360 return 0; | 405 return 0; |
361 } | 406 } |
362 | 407 |
363 static int | 408 static int |
364 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 409 NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
365 const SDL_Rect * rect, const void *pixels, int pitch) | 410 const SDL_Rect * rect, const void *pixels, int pitch) |
366 { | 411 { |
367 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | 412 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
368 Uint8 *src, *dst; | 413 Uint8 *src, *dst; |
369 int row; size_t length; | 414 int row; size_t length; |
370 printf("+NDS_UpdateTexture\n"); | 415 TRACE("+NDS_UpdateTexture\n"); |
371 | 416 |
372 src = (Uint8 *) pixels; | 417 src = (Uint8 *) pixels; |
373 dst = | 418 dst = |
374 (Uint8 *) txdat->system_ram_copy + rect->y * txdat->dim.pitch + | 419 (Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch + |
375 rect->x * (txdat->dim.bpp/8); | 420 rect->x * (txdat->dim.bpp/8); |
376 length = rect->w * (txdat->dim.bpp/8); | 421 length = rect->w * (txdat->dim.bpp/8); |
377 for (row = 0; row < rect->h; ++row) { | 422 for (row = 0; row < rect->h; ++row) { |
378 SDL_memcpy(dst, src, length); | 423 SDL_memcpy(dst, src, length); |
379 src += pitch; | 424 src += pitch; |
380 dst += txdat->dim.pitch; | 425 dst += txdat->dim.pitch; |
381 } | 426 } |
382 | 427 |
383 printf("-NDS_UpdateTexture\n"); | 428 TRACE("-NDS_UpdateTexture\n"); |
384 return 0; | 429 return 0; |
385 } | 430 } |
386 | 431 |
387 static int | 432 static int |
388 NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 433 NDS_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
389 const SDL_Rect * rect, int markDirty, void **pixels, | 434 const SDL_Rect * rect, int markDirty, void **pixels, |
390 int *pitch) | 435 int *pitch) |
391 { | 436 { |
392 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | 437 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
393 int i; | 438 int i; |
394 printf("+NDS_LockTexture\n"); | 439 TRACE("+NDS_LockTexture\n"); |
395 if (markDirty) { | 440 if (markDirty) { |
396 printf("wanted to mark dirty\n"); | 441 printf("wanted to mark dirty\n"); |
397 /* TODO: figure out how to handle this! */ | 442 /* TODO: figure out how to handle this! */ |
398 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/ | 443 /*SDL_AddDirtyRect(&txdat->dirty, rect);*/ |
399 } | 444 } |
400 | 445 |
401 *pixels = (void *) ((u8 *)txdat->vram + rect->y | 446 *pixels = (void *) ((u8 *)txdat->vram_pixels + rect->y |
402 * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8)); | 447 * txdat->dim.pitch + rect->x * (txdat->dim.bpp/8)); |
403 *pitch = txdat->dim.pitch; | 448 *pitch = txdat->dim.pitch; |
404 printf(" pixels = %08x\n", (u32)*pixels); | 449 printf(" pixels = %08x\n", (u32)*pixels); |
405 printf(" vram = %08x\n", (u32)(txdat->vram)); | 450 printf(" vram = %08x\n", (u32)(txdat->vram_pixels)); |
406 printf("-NDS_LockTexture\n"); | 451 TRACE("-NDS_LockTexture\n"); |
407 return 0; | 452 return 0; |
408 } | 453 } |
409 | 454 |
410 static void | 455 static void |
411 NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 456 NDS_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
412 { | 457 { |
413 printf("+NDS_UnlockTexture\n"); | 458 TRACE("+NDS_UnlockTexture\n"); |
414 /* TODO: should I be doing something here, somehow, now that the pixels | 459 /* TODO: should I be doing something here, somehow, now that the pixels |
415 should have been "written" between LockTexture and this? */ | 460 should have been "written" between LockTexture and this? */ |
416 printf("-NDS_UnlockTexture\n"); | 461 TRACE("-NDS_UnlockTexture\n"); |
417 } | 462 } |
418 | 463 |
419 static void | 464 static void |
420 NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 465 NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
421 int numrects, const SDL_Rect * rects) | 466 int numrects, const SDL_Rect * rects) |
422 { | 467 { |
423 /* stub */ | 468 /* stub */ |
424 printf("!NDS_DirtyTexture\n"); | 469 TRACE("!NDS_DirtyTexture\n"); |
425 } | 470 } |
426 | 471 |
427 static int | 472 static int |
428 NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, | 473 NDS_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, |
429 Uint8 a, const SDL_Rect * rect) | 474 Uint8 a, const SDL_Rect * rect) |
431 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 476 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
432 SDL_Rect real_rect = *rect; | 477 SDL_Rect real_rect = *rect; |
433 u16 color; | 478 u16 color; |
434 int i, j; | 479 int i, j; |
435 | 480 |
436 printf("+NDS_RenderFill\n"); | 481 TRACE("+NDS_RenderFill\n"); |
437 color = RGB8(r,g,b); /* <-- macro in libnds that makes an ARGB1555 pixel */ | 482 color = RGB8(r,g,b); /* <-- macro in libnds that makes an ARGB1555 pixel */ |
438 /* TODO: make a single-color sprite and stretch it. | 483 /* TODO: make a single-color sprite and stretch it. |
439 calculate the "HDX" width modifier of the sprite by: | 484 calculate the "HDX" width modifier of the sprite by: |
440 let S be the actual sprite's width (like, 32 pixels for example) | 485 let S be the actual sprite's width (like, 32 pixels for example) |
441 let R be the rectangle's width (maybe 50 pixels) | 486 let R be the rectangle's width (maybe 50 pixels) |
442 HDX = (R<<8) / S; | 487 HDX = (R<<8) / S; |
443 (it's fixed point, hence the bit shift. same goes for vertical. | 488 (it's fixed point, hence the bit shift. same goes for vertical. |
444 be sure to use 32-bit int's for the bit shift before the division!) | 489 be sure to use 32-bit int's for the bit shift before the division!) |
445 */ | 490 */ |
446 | 491 |
447 printf("-NDS_RenderFill\n"); | 492 TRACE("-NDS_RenderFill\n"); |
448 return 0; | 493 return 0; |
449 } | 494 } |
450 | 495 |
451 static int | 496 static int |
452 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 497 NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
457 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 502 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
458 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 503 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
459 int i; | 504 int i; |
460 int bpp = SDL_BYTESPERPIXEL(texture->format); | 505 int bpp = SDL_BYTESPERPIXEL(texture->format); |
461 int pitch = txdat->dim.pitch; | 506 int pitch = txdat->dim.pitch; |
462 printf("+NDS_RenderCopy\n"); | 507 |
508 TRACE("+NDS_RenderCopy\n"); | |
463 if(txdat->type == NDSTX_BG) { | 509 if(txdat->type == NDSTX_BG) { |
464 bg_rotation *tmpbg = (txdat->hw_index == 2) ? | 510 bg_rotation *tmpbg = (txdat->hw_index == 2) ? |
465 &(data->bg->bg2_rotation) : &(data->bg->bg3_rotation); | 511 &(data->bg->bg2_rotation) : &(data->bg->bg3_rotation); |
466 tmpbg->xdx = txdat->dim.hdx; | 512 tmpbg->xdx = txdat->dim.hdx; |
467 tmpbg->xdy = txdat->dim.hdy; | 513 tmpbg->xdy = txdat->dim.hdy; |
471 tmpbg->centerY = 0; | 517 tmpbg->centerY = 0; |
472 } else { | 518 } else { |
473 /* sprites not implemented yet */ | 519 /* sprites not implemented yet */ |
474 } | 520 } |
475 printf(" txdat->hw_index = %d\n", txdat->hw_index); | 521 printf(" txdat->hw_index = %d\n", txdat->hw_index); |
476 printf("-NDS_RenderCopy\n"); | 522 TRACE("-NDS_RenderCopy\n"); |
523 | |
477 return 0; | 524 return 0; |
478 } | 525 } |
479 | 526 |
480 | 527 |
481 static void | 528 static void |
483 { | 530 { |
484 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 531 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
485 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 532 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
486 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 533 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
487 int i; | 534 int i; |
488 printf("+NDS_RenderPresent\n"); | 535 TRACE("+NDS_RenderPresent\n"); |
489 | 536 |
490 { | 537 { |
491 SDL_Texture * tx = display->textures[i]; | 538 SDL_Texture * tx = display->textures[i]; |
492 NDS_TextureData * txdat = (NDS_TextureData*)tx->driverdata; | 539 NDS_TextureData * txdat = (NDS_TextureData*)tx->driverdata; |
493 /* Send the data to the display TODO : | 540 /* Send the data to the display TODO : |
499 | 546 |
500 /* vsync for NDS */ | 547 /* vsync for NDS */ |
501 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { | 548 if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) { |
502 swiWaitForVBlank(); | 549 swiWaitForVBlank(); |
503 } | 550 } |
504 printf("-NDS_RenderPresent\n"); | 551 TRACE("-NDS_RenderPresent\n"); |
505 } | 552 } |
506 | 553 |
507 static void | 554 static void |
508 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 555 NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
509 { | 556 { |
510 printf("+NDS_DestroyTexture\n"); | 557 TRACE("+NDS_DestroyTexture\n"); |
511 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | 558 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { |
512 SDL_SetError("Unsupported texture format"); | 559 SDL_SetError("Unsupported texture format"); |
513 } else { | 560 } else { |
514 /* free anything else allocated for texture */ | 561 /* free anything else allocated for texture */ |
515 NDS_TextureData *txdat = texture->driverdata; | 562 NDS_TextureData *txdat = texture->driverdata; |
516 /*SDL_FreeDirtyRects(&txdat->dirty);*/ | 563 /*SDL_FreeDirtyRects(&txdat->dirty);*/ |
517 SDL_free(txdat->system_ram_copy); | |
518 SDL_free(txdat); | 564 SDL_free(txdat); |
519 } | 565 } |
520 printf("-NDS_DestroyTexture\n"); | 566 TRACE("-NDS_DestroyTexture\n"); |
521 } | 567 } |
522 | 568 |
523 static void | 569 static void |
524 NDS_DestroyRenderer(SDL_Renderer * renderer) | 570 NDS_DestroyRenderer(SDL_Renderer * renderer) |
525 { | 571 { |
526 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; | 572 NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata; |
527 /*SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 573 /*SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
528 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/ | 574 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/ |
529 int i; | 575 int i; |
530 | 576 |
531 printf("+NDS_DestroyRenderer\n"); | 577 TRACE("+NDS_DestroyRenderer\n"); |
532 if (data) { | 578 if (data) { |
533 /* TODO: free anything else relevant. */ | 579 /* TODO: free anything else relevant. */ |
534 /*for (i = 0; i < SDL_arraysize(data->texture); ++i) { | 580 /*for (i = 0; i < SDL_arraysize(data->texture); ++i) { |
535 if (data->texture[i]) { | 581 if (data->texture[i]) { |
536 DestroyTexture(data->renderer, data->texture[i]); | 582 DestroyTexture(data->renderer, data->texture[i]); |
546 } | 592 } |
547 SDL_FreeDirtyRects(&data->dirty);*/ | 593 SDL_FreeDirtyRects(&data->dirty);*/ |
548 SDL_free(data); | 594 SDL_free(data); |
549 } | 595 } |
550 SDL_free(renderer); | 596 SDL_free(renderer); |
551 printf("-NDS_DestroyRenderer\n"); | 597 TRACE("-NDS_DestroyRenderer\n"); |
552 } | 598 } |
553 | 599 |
554 static int | 600 static int |
555 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | 601 NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
556 const SDL_Color * colors, int firstcolor, int ncolors) | 602 const SDL_Color * colors, int firstcolor, int ncolors) |
557 { | 603 { |
558 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | 604 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
559 printf("+NDS_SetTexturePalette\n"); | 605 TRACE("+NDS_SetTexturePalette\n"); |
560 /* set 8-bit modes in the background control registers | 606 /* set 8-bit modes in the background control registers |
561 for backgrounds, BGn_CR |= BG_256_COLOR */ | 607 for backgrounds, BGn_CR |= BG_256_COLOR */ |
562 printf("-NDS_SetTexturePalette\n"); | 608 TRACE("-NDS_SetTexturePalette\n"); |
563 return 0; | 609 return 0; |
564 } | 610 } |
565 | 611 |
566 static int | 612 static int |
567 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | 613 NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
568 SDL_Color * colors, int firstcolor, int ncolors) | 614 SDL_Color * colors, int firstcolor, int ncolors) |
569 { | 615 { |
570 printf("+NDS_GetTexturePalette\n"); | 616 TRACE("+NDS_GetTexturePalette\n"); |
571 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; | 617 NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; |
572 printf("-NDS_GetTexturePalette\n"); | 618 TRACE("-NDS_GetTexturePalette\n"); |
573 return 0; | 619 return 0; |
574 } | 620 } |
575 | 621 |
576 static int | 622 static int |
577 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | 623 NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) |
578 { | 624 { |
579 printf("!NDS_SetTextureColorMod\n"); | 625 TRACE("!NDS_SetTextureColorMod\n"); |
580 /* stub! */ | 626 /* stub! */ |
581 return 0; | 627 return 0; |
582 } | 628 } |
583 | 629 |
584 static int | 630 static int |
585 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | 631 NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) |
586 { | 632 { |
587 printf("!NDS_SetTextureAlphaMod\n"); | 633 TRACE("!NDS_SetTextureAlphaMod\n"); |
588 /* stub! */ | 634 /* stub! */ |
589 return 0; | 635 return 0; |
590 } | 636 } |
591 | 637 |
592 static int | 638 static int |
593 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | 639 NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) |
594 { | 640 { |
595 printf("!NDS_SetTextureBlendMode\n"); | 641 TRACE("!NDS_SetTextureBlendMode\n"); |
596 /* stub! */ | 642 /* stub! */ |
597 return 0; | 643 return 0; |
598 } | 644 } |
599 | 645 |
600 static int | 646 static int |
601 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | 647 NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) |
602 { | 648 { |
603 printf("!NDS_SetTextureScaleMode\n"); | 649 TRACE("!NDS_SetTextureScaleMode\n"); |
604 /* stub! (note: NDS hardware scaling is nearest neighbor.) */ | 650 /* stub! (note: NDS hardware scaling is nearest neighbor.) */ |
605 return 0; | 651 return 0; |
606 } | 652 } |
607 | 653 |
608 /* vi: set ts=4 sw=4 expandtab: */ | 654 /* vi: set ts=4 sw=4 expandtab: */ |