src/mame/video/snes.c
| r5355 | r5356 | |
| 88 | 88 | #define SNES_CLIP_OUT 2 |
| 89 | 89 | #define SNES_CLIP_ALL2 3 |
| 90 | 90 | |
| 91 | | #ifdef SNES_DBG_video |
| 91 | #ifdef MAME_DEBUG |
| 92 | 92 | struct DEBUGOPTS |
| 93 | 93 | { |
| 94 | 94 | UINT8 input_count; |
| r5355 | r5356 | |
| 100 | 100 | static struct DEBUGOPTS debug_options = {5, {0,0,0,0,0,0}, 0, 0, 0}; |
| 101 | 101 | /* red green blue purple yellow cyan grey white */ |
| 102 | 102 | static const UINT16 dbg_mode_colours[8] = { 0x1f, 0x3e0, 0x7c00, 0x7c1f, 0x3ff, 0x7fe0, 0x4210, 0x7fff }; |
| 103 | | static UINT8 snes_dbg_video(bitmap_t *bitmap, UINT16 curline); |
| 104 | | #endif /* SNES_DBG_video */ |
| 103 | static UINT8 snes_dbg_video(running_machine *machine, bitmap_t *bitmap, UINT16 curline); |
| 104 | #endif /* MAME_DEBUG */ |
| 105 | 105 | |
| 106 | 106 | /* Forward declarations */ |
| 107 | 107 | static void snes_update_line_2(UINT8 screen, UINT8 layer, UINT16 curline ); |
| r5355 | r5356 | |
| 112 | 112 | static void snes_update_line_mode7(UINT8 screen, UINT8 layer, UINT16 curline ); |
| 113 | 113 | |
| 114 | 114 | /* Lookup tables */ |
| 115 | | static const UINT8 table_bgd_pty[2][4][2] = { { {7,10}, {6,9}, {1,4}, {0,3} }, { {3,10}, {1,7}, {0,0}, {0,0} } }; |
| 116 | | static const UINT8 table_obj_pty[4] = { 2, 5, 8, 11 }; |
| 115 | static const UINT8 table_bgd_pty[10][4][2] = {{ {7,10}, {6,9}, {1,4}, {0,3} }, // mode 0 |
| 116 | { {5,8}, {4,7}, {0,2}, {0,0} }, // mode 1 |
| 117 | { {2,6}, {0,4}, {0,0}, {0,0} }, // mode 2 |
| 118 | { {2,6}, {0,4}, {0,0}, {0,0} }, // mode 3 |
| 119 | { {2,6}, {0,4}, {0,0}, {0,0} }, // mode 4 |
| 120 | { {2,6}, {0,4}, {0,0}, {0,0} }, // mode 5 |
| 121 | { {1,4}, {0,0}, {0,0}, {0,0} }, // mode 6 |
| 122 | { {3,6}, {1,4}, {0,0}, {0,0} }, // mode 7 - this was used earlier... correct one: {1,1},{0,0}; or {2,2},{0,4} when EXTBG=1! |
| 123 | { {4,7}, {3,6}, {0,9}, {0,0} } // mode 1 + BG3 priority bit (current code does not use this!) |
| 124 | }; |
| 125 | static const UINT8 table_obj_pty[10][4] = { {2, 5, 8, 11}, // mode 0 |
| 126 | {1, 3, 6, 9}, // mode 1 |
| 127 | {1, 3, 5, 7}, // mode 2 |
| 128 | {1, 3, 5, 7}, // mode 3 |
| 129 | {1, 3, 5, 7}, // mode 4 |
| 130 | {1, 3, 5, 7}, // mode 5 |
| 131 | {0, 2, 3, 5}, // mode 6 |
| 132 | {2, 5, 8, 11}, // mode 7 - this was used earlier... correct one: {0,2,3,4}; or {1,3,5,6} when EXTBG=1! |
| 133 | {1, 2, 5, 8} // mode 1 + BG3 priority bit (current code does not use this!) |
| 134 | }; |
| 117 | 135 | static const UINT16 table_obj_offset[8][8] = |
| 118 | 136 | { |
| 119 | 137 | { (0*32), (0*32)+32, (0*32)+64, (0*32)+96, (0*32)+128, (0*32)+160, (0*32)+192, (0*32)+224 }, |
| r5355 | r5356 | |
| 156 | 174 | |
| 157 | 175 | extern UINT16 snes_htmult; |
| 158 | 176 | |
| 177 | enum |
| 178 | { |
| 179 | SNES_COLOR_DEPTH_2BPP = 0, |
| 180 | SNES_COLOR_DEPTH_4BPP, |
| 181 | SNES_COLOR_DEPTH_8BPP |
| 182 | }; |
| 183 | |
| 159 | 184 | /***************************************** |
| 160 | 185 | * snes_draw_blend() |
| 161 | 186 | * |
| r5355 | r5356 | |
| 167 | 192 | if( clip == SNES_CLIP_ALL2) // blending mode 3 == always OFF |
| 168 | 193 | return; |
| 169 | 194 | |
| 170 | | #ifdef SNES_DBG_video |
| 195 | #ifdef MAME_DEBUG |
| 171 | 196 | if( !debug_options.transparency_disabled ) |
| 172 | | #endif /* SNES_DBG_video */ |
| 197 | #endif /* MAME_DEBUG */ |
| 173 | 198 | if( (clip == SNES_CLIP_ALL) || |
| 174 | 199 | (clip == SNES_CLIP_IN && snes_ppu.clipmasks[5][offset]) || |
| 175 | 200 | (clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[5][offset]) ) |
| r5355 | r5356 | |
| 243 | 268 | } |
| 244 | 269 | } |
| 245 | 270 | |
| 271 | |
| 246 | 272 | /***************************************** |
| 247 | | * snes_draw_tile_2() |
| 273 | * snes_draw_tile_common() |
| 248 | 274 | * |
| 249 | | * Draw tiles with 2 bit planes(4 colors) |
| 275 | * Draw tiles with variable bit planes |
| 250 | 276 | *****************************************/ |
| 251 | | INLINE void snes_draw_tile_2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal ) |
| 277 | INLINE void snes_draw_tile_common(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal ) |
| 252 | 278 | { |
| 253 | | UINT8 mask, plane[2]; |
| 279 | UINT8 mask, plane[planes]; |
| 254 | 280 | UINT16 c; |
| 255 | | INT16 ii; |
| 281 | INT16 ii, jj; |
| 256 | 282 | |
| 257 | | plane[0] = snes_vram[tileaddr]; |
| 258 | | plane[1] = snes_vram[tileaddr + 1]; |
| 283 | for (ii = 0; ii < planes / 2; ii++) |
| 284 | { |
| 285 | plane[2 * ii] = snes_vram[tileaddr + 16 * ii]; |
| 286 | plane[2 * ii + 1] = snes_vram[tileaddr + 16 * ii + 1]; |
| 287 | } |
| 259 | 288 | |
| 260 | | if( flip ) |
| 289 | if (flip) |
| 261 | 290 | mask = 0x1; |
| 262 | 291 | else |
| 263 | 292 | mask = 0x80; |
| 264 | 293 | |
| 265 | | for( ii = x; ii < (x + 8); ii++ ) |
| 294 | for (ii = x; ii < (x + 8); ii++) |
| 266 | 295 | { |
| 267 | | UINT8 colour; |
| 268 | | if( flip ) |
| 296 | UINT8 colour = 0; |
| 297 | if (flip) |
| 269 | 298 | { |
| 270 | | colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0); |
| 299 | for (jj = 0; jj < planes; jj++) |
| 300 | colour |= plane[jj] & mask ? (1 << jj) : 0; |
| 301 | |
| 271 | 302 | mask <<= 1; |
| 272 | 303 | } |
| 273 | 304 | else |
| 274 | 305 | { |
| 275 | | colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0); |
| 306 | for (jj = 0; jj < planes; jj++) |
| 307 | colour |= plane[jj] & mask ? (1 << jj) : 0; |
| 308 | |
| 276 | 309 | mask >>= 1; |
| 277 | 310 | } |
| 278 | 311 | |
| 279 | | #ifdef SNES_DBG_video |
| 280 | | if( !debug_options.windows_disabled ) |
| 281 | | #endif /* SNES_DBG_video */ |
| 312 | #ifdef MAME_DEBUG |
| 313 | if(!debug_options.windows_disabled) |
| 314 | #endif /* MAME_DEBUG */ |
| 282 | 315 | /* Clip to windows */ |
| 283 | | if( (screen == MAINSCREEN && (snes_ram[TMW] & (0x1 << layer))) || (screen == SUBSCREEN && (snes_ram[TSW] & (0x1 << layer)))) |
| 316 | if ((screen == MAINSCREEN && (snes_ram[TMW] & (0x1 << layer))) || (screen == SUBSCREEN && (snes_ram[TSW] & (0x1 << layer)))) |
| 284 | 317 | colour &= snes_ppu.clipmasks[layer][ii]; |
| 285 | 318 | |
| 286 | 319 | /* Only draw if we have a colour (0 == transparent) */ |
| 287 | | if( colour ) |
| 320 | if (colour) |
| 288 | 321 | { |
| 289 | | if( (scanlines[screen].zbuf[ii] <= priority) && (ii >= 0) ) |
| 322 | if ((scanlines[screen].zbuf[ii] <= priority) && (ii >= 0)) |
| 290 | 323 | { |
| 291 | 324 | c = snes_cgram[pal + colour]; |
| 292 | | if( screen == MAINSCREEN ) /* Only blend main screens */ |
| 293 | | snes_draw_blend(ii, &c, snes_ppu.layer[layer].blend, (snes_ram[CGWSEL] & 0x30) >> 4 ); |
| 294 | | if( snes_ram[MOSAIC] & (1 << layer) ) // handle horizontal mosaic |
| 325 | if (screen == MAINSCREEN) /* Only blend main screens */ |
| 326 | snes_draw_blend(ii, &c, snes_ppu.layer[layer].blend, (snes_ram[CGWSEL] & 0x30) >> 4); |
| 327 | if (snes_ram[MOSAIC] & (1 << layer)) // handle horizontal mosaic |
| 295 | 328 | { |
| 296 | 329 | int x_mos; |
| 297 | 330 | |
| 298 | 331 | //TODO: 512 modes has the h values doubled. |
| 299 | | for(x_mos = 0;x_mos < (((snes_ram[MOSAIC] & 0xf0)>>4)+1) ; x_mos++) |
| 332 | for (x_mos = 0; x_mos < (((snes_ram[MOSAIC] & 0xf0) >> 4) + 1) ; x_mos++) |
| 300 | 333 | { |
| 301 | 334 | scanlines[screen].buffer[ii + x_mos] = c; |
| 302 | 335 | scanlines[screen].zbuf[ii + x_mos] = priority; |
| r5355 | r5356 | |
| 314 | 347 | } |
| 315 | 348 | |
| 316 | 349 | /***************************************** |
| 350 | * snes_draw_tile_2() |
| 351 | * |
| 352 | * Draw tiles with 2 bit planes(4 colors) |
| 353 | *****************************************/ |
| 354 | INLINE void snes_draw_tile_2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal ) |
| 355 | { |
| 356 | snes_draw_tile_common(screen, 2, layer, tileaddr, x, priority, flip, pal); |
| 357 | } |
| 358 | |
| 359 | /***************************************** |
| 317 | 360 | * snes_draw_tile_2x2() |
| 318 | 361 | * |
| 319 | 362 | * Draw 2 tiles with 2 bit planes(4 colors) |
| r5355 | r5356 | |
| 322 | 365 | { |
| 323 | 366 | if( flip ) |
| 324 | 367 | { |
| 325 | | snes_draw_tile_2(screen, layer, tileaddr + 16, x, priority, flip, pal ); |
| 326 | | snes_draw_tile_2(screen, layer, tileaddr, x + 8, priority, flip, pal ); |
| 368 | snes_draw_tile_2(screen, layer, tileaddr + 16, x, priority, flip, pal); |
| 369 | snes_draw_tile_2(screen, layer, tileaddr, x + 8, priority, flip, pal); |
| 327 | 370 | } |
| 328 | 371 | else |
| 329 | 372 | { |
| 330 | | snes_draw_tile_2(screen, layer, tileaddr, x, priority, flip, pal ); |
| 331 | | snes_draw_tile_2(screen, layer, tileaddr + 16, x + 8, priority, flip, pal ); |
| 373 | snes_draw_tile_2(screen, layer, tileaddr, x, priority, flip, pal); |
| 374 | snes_draw_tile_2(screen, layer, tileaddr + 16, x + 8, priority, flip, pal); |
| 332 | 375 | } |
| 333 | 376 | } |
| 334 | 377 | |
| r5355 | r5356 | |
| 339 | 382 | *****************************************/ |
| 340 | 383 | INLINE void snes_draw_tile_4(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal ) |
| 341 | 384 | { |
| 342 | | UINT8 mask, plane[4]; |
| 343 | | UINT16 c; |
| 344 | | INT16 ii; |
| 345 | | |
| 346 | | plane[0] = snes_vram[tileaddr]; |
| 347 | | plane[1] = snes_vram[tileaddr + 1]; |
| 348 | | plane[2] = snes_vram[tileaddr + 16]; |
| 349 | | plane[3] = snes_vram[tileaddr + 17]; |
| 350 | | |
| 351 | | if( flip ) |
| 352 | | mask = 0x1; |
| 353 | | else |
| 354 | | mask = 0x80; |
| 355 | | |
| 356 | | for( ii = x; ii < (x + 8); ii++ ) |
| 357 | | { |
| 358 | | UINT8 colour; |
| 359 | | if( flip ) |
| 360 | | { |
| 361 | | colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) | |
| 362 | | (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0); |
| 363 | | mask <<= 1; |
| 364 | | } |
| 365 | | else |
| 366 | | { |
| 367 | | colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) | |
| 368 | | (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0); |
| 369 | | mask >>= 1; |
| 370 | | } |
| 371 | | |
| 372 | | #ifdef SNES_DBG_video |
| 373 | | if( !debug_options.windows_disabled ) |
| 374 | | #endif /* SNES_DBG_video */ |
| 375 | | /* Clip to windows */ |
| 376 | | if( (screen == MAINSCREEN && (snes_ram[TMW] & (0x1 << layer))) || (screen == SUBSCREEN && (snes_ram[TSW] & (0x1 << layer)))) |
| 377 | | colour &= snes_ppu.clipmasks[layer][ii]; |
| 378 | | |
| 379 | | /* Only draw if we have a colour (0 == transparent) */ |
| 380 | | if( colour ) |
| 381 | | { |
| 382 | | if( (scanlines[screen].zbuf[ii] <= priority) && (ii >= 0) ) |
| 383 | | { |
| 384 | | c = snes_cgram[pal + colour]; |
| 385 | | if( screen == MAINSCREEN ) /* Only blend main screens */ |
| 386 | | snes_draw_blend(ii, &c, snes_ppu.layer[layer].blend, (snes_ram[CGWSEL] & 0x30) >> 4 ); |
| 387 | | if( snes_ram[MOSAIC] & (1 << layer) ) // handle horizontal mosaic |
| 388 | | { |
| 389 | | int x_mos; |
| 390 | | |
| 391 | | //TODO: 512 modes has the h values doubled. |
| 392 | | for(x_mos = 0;x_mos < (((snes_ram[MOSAIC] & 0xf0)>>4)+1) ; x_mos++) |
| 393 | | { |
| 394 | | scanlines[screen].buffer[ii + x_mos] = c; |
| 395 | | scanlines[screen].zbuf[ii + x_mos] = priority; |
| 396 | | } |
| 397 | | ii += x_mos - 1; |
| 398 | | } |
| 399 | | else |
| 400 | | { |
| 401 | | scanlines[screen].buffer[ii] = c; |
| 402 | | scanlines[screen].zbuf[ii] = priority; |
| 403 | | } |
| 404 | | } |
| 405 | | } |
| 406 | | } |
| 385 | snes_draw_tile_common(screen, 4, layer, tileaddr, x, priority, flip, pal); |
| 407 | 386 | } |
| 408 | 387 | |
| 409 | 388 | /***************************************** |
| r5355 | r5356 | |
| 415 | 394 | { |
| 416 | 395 | if( flip ) |
| 417 | 396 | { |
| 418 | | snes_draw_tile_4(screen, layer, tileaddr + 32, x, priority, flip, pal ); |
| 419 | | snes_draw_tile_4(screen, layer, tileaddr, x + 8, priority, flip, pal ); |
| 397 | snes_draw_tile_4(screen, layer, tileaddr + 32, x, priority, flip, pal); |
| 398 | snes_draw_tile_4(screen, layer, tileaddr, x + 8, priority, flip, pal); |
| 420 | 399 | } |
| 421 | 400 | else |
| 422 | 401 | { |
| 423 | | snes_draw_tile_4(screen, layer, tileaddr, x, priority, flip, pal ); |
| 424 | | snes_draw_tile_4(screen, layer, tileaddr + 32, x + 8, priority, flip, pal ); |
| 402 | snes_draw_tile_4(screen, layer, tileaddr, x, priority, flip, pal); |
| 403 | snes_draw_tile_4(screen, layer, tileaddr + 32, x + 8, priority, flip, pal); |
| 425 | 404 | } |
| 426 | 405 | } |
| 427 | 406 | |
| r5355 | r5356 | |
| 432 | 411 | *****************************************/ |
| 433 | 412 | INLINE void snes_draw_tile_8(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip ) |
| 434 | 413 | { |
| 435 | | UINT8 mask, plane[8]; |
| 436 | | UINT16 c; |
| 437 | | INT16 ii; |
| 438 | | |
| 439 | | plane[0] = snes_vram[tileaddr]; |
| 440 | | plane[1] = snes_vram[tileaddr + 1]; |
| 441 | | plane[2] = snes_vram[tileaddr + 16]; |
| 442 | | plane[3] = snes_vram[tileaddr + 17]; |
| 443 | | plane[4] = snes_vram[tileaddr + 32]; |
| 444 | | plane[5] = snes_vram[tileaddr + 33]; |
| 445 | | plane[6] = snes_vram[tileaddr + 48]; |
| 446 | | plane[7] = snes_vram[tileaddr + 49]; |
| 447 | | |
| 448 | | if( flip ) |
| 449 | | mask = 0x1; |
| 450 | | else |
| 451 | | mask = 0x80; |
| 452 | | |
| 453 | | for( ii = x; ii < (x + 8); ii++ ) |
| 454 | | { |
| 455 | | UINT8 colour; |
| 456 | | if( flip ) |
| 457 | | { |
| 458 | | colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) | |
| 459 | | (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0) | |
| 460 | | (plane[4] & mask ? 16 : 0) | (plane[5] & mask ? 32 : 0) | |
| 461 | | (plane[6] & mask ? 64 : 0) | (plane[7] & mask ? 128 : 0); |
| 462 | | mask <<= 1; |
| 463 | | } |
| 464 | | else |
| 465 | | { |
| 466 | | colour = (plane[0] & mask ? 1 : 0) | (plane[1] & mask ? 2 : 0) | |
| 467 | | (plane[2] & mask ? 4 : 0) | (plane[3] & mask ? 8 : 0) | |
| 468 | | (plane[4] & mask ? 16 : 0) | (plane[5] & mask ? 32 : 0) | |
| 469 | | (plane[6] & mask ? 64 : 0) | (plane[7] & mask ? 128 : 0); |
| 470 | | mask >>= 1; |
| 471 | | } |
| 472 | | |
| 473 | | #ifdef SNES_DBG_video |
| 474 | | if( !debug_options.windows_disabled ) |
| 475 | | #endif /* SNES_DBG_video */ |
| 476 | | /* Clip to windows */ |
| 477 | | if( (screen == MAINSCREEN && (snes_ram[TMW] & (0x1 << layer))) || (screen == SUBSCREEN && (snes_ram[TSW] & (0x1 << layer)))) |
| 478 | | colour &= snes_ppu.clipmasks[layer][ii]; |
| 479 | | |
| 480 | | /* Only draw if we have a colour (0 == transparent) */ |
| 481 | | if( colour ) |
| 482 | | { |
| 483 | | if( (scanlines[screen].zbuf[ii] <= priority) && (ii >= 0) ) |
| 484 | | { |
| 485 | | c = snes_cgram[colour]; |
| 486 | | if( screen == MAINSCREEN ) /* Only blend main screens */ |
| 487 | | snes_draw_blend(ii, &c, snes_ppu.layer[layer].blend, (snes_ram[CGWSEL] & 0x30) >> 4 ); |
| 488 | | if( snes_ram[MOSAIC] & (1 << layer) ) // handle horizontal mosaic |
| 489 | | { |
| 490 | | int x_mos; |
| 491 | | |
| 492 | | //TODO: 512 modes has the h values doubled. |
| 493 | | for(x_mos = 0;x_mos < (((snes_ram[MOSAIC] & 0xf0)>>4)+1) ; x_mos++) |
| 494 | | { |
| 495 | | scanlines[screen].buffer[ii + x_mos] = c; |
| 496 | | scanlines[screen].zbuf[ii + x_mos] = priority; |
| 497 | | } |
| 498 | | ii += x_mos - 1; |
| 499 | | } |
| 500 | | else |
| 501 | | { |
| 502 | | scanlines[screen].buffer[ii] = c; |
| 503 | | scanlines[screen].zbuf[ii] = priority; |
| 504 | | } |
| 505 | | } |
| 506 | | } |
| 507 | | } |
| 414 | snes_draw_tile_common(screen, 8, layer, tileaddr, x, priority, flip, 0); |
| 508 | 415 | } |
| 509 | 416 | |
| 510 | 417 | /***************************************** |
| r5355 | r5356 | |
| 516 | 423 | { |
| 517 | 424 | if( flip ) |
| 518 | 425 | { |
| 519 | | snes_draw_tile_8(screen, layer, tileaddr + 64, x, priority, flip ); |
| 520 | | snes_draw_tile_8(screen, layer, tileaddr, x + 8, priority, flip ); |
| 426 | snes_draw_tile_8(screen, layer, tileaddr + 64, x, priority, flip); |
| 427 | snes_draw_tile_8(screen, layer, tileaddr, x + 8, priority, flip); |
| 521 | 428 | } |
| 522 | 429 | else |
| 523 | 430 | { |
| 524 | | snes_draw_tile_8(screen, layer, tileaddr, x, priority, flip ); |
| 525 | | snes_draw_tile_8(screen, layer, tileaddr + 64, x + 8, priority, flip ); |
| 431 | snes_draw_tile_8(screen, layer, tileaddr, x, priority, flip); |
| 432 | snes_draw_tile_8(screen, layer, tileaddr + 64, x + 8, priority, flip); |
| 526 | 433 | } |
| 527 | 434 | } |
| 528 | 435 | |
| r5355 | r5356 | |
| 565 | 472 | mask >>= 1; |
| 566 | 473 | } |
| 567 | 474 | |
| 568 | | #ifdef SNES_DBG_video |
| 475 | #ifdef MAME_DEBUG |
| 569 | 476 | if( !debug_options.windows_disabled ) |
| 570 | | #endif /* SNES_DBG_video */ |
| 477 | #endif /* MAME_DEBUG */ |
| 571 | 478 | /* Clip to windows */ |
| 572 | 479 | if( (screen == MAINSCREEN && (snes_ram[TMW] & 0x10)) || (screen == SUBSCREEN && (snes_ram[TSW] & 0x10))) |
| 573 | 480 | colour &= snes_ppu.clipmasks[4][ii]; |
| r5355 | r5356 | |
| 629 | 536 | mask >>= 1; |
| 630 | 537 | } |
| 631 | 538 | |
| 632 | | #ifdef SNES_DBG_video |
| 539 | #ifdef MAME_DEBUG |
| 633 | 540 | if( !debug_options.windows_disabled ) |
| 634 | | #endif /* SNES_DBG_video */ |
| 541 | #endif /* MAME_DEBUG */ |
| 635 | 542 | /* Clip to windows */ |
| 636 | 543 | if( (screen == MAINSCREEN && (snes_ram[TMW] & 0x10)) || (screen == SUBSCREEN && (snes_ram[TSW] & 0x10))) |
| 637 | 544 | colour &= snes_ppu.clipmasks[4][ii]; |
| r5355 | r5356 | |
| 655 | 562 | } |
| 656 | 563 | |
| 657 | 564 | /********************************************* |
| 658 | | * snes_update_line_2() |
| 565 | * snes_update_line_common() |
| 659 | 566 | * |
| 660 | | * Update an entire line of 2 bit plane tiles. |
| 567 | * Update an entire line of tiles. |
| 661 | 568 | *********************************************/ |
| 662 | | static void snes_update_line_2(UINT8 screen, UINT8 layer, UINT16 curline ) |
| 569 | INLINE void snes_update_line_common( UINT8 screen, UINT8 color_depth, UINT8 hires, UINT8 layer, UINT16 curline ) |
| 663 | 570 | { |
| 664 | 571 | UINT32 tmap, tile; |
| 665 | 572 | UINT16 ii, vflip, hflip, pal; |
| r5355 | r5356 | |
| 670 | 577 | UINT16 vscroll, hscroll, vtilescroll; |
| 671 | 578 | UINT8 vshift, hshift, tile_size; |
| 672 | 579 | UINT8 bg3_pty = 0; |
| 580 | UINT8 color_shift = 0; |
| 581 | UINT8 divider = 1; |
| 673 | 582 | |
| 674 | | #ifdef SNES_DBG_video |
| 675 | | if( debug_options.bg_disabled[layer] ) |
| 583 | #ifdef MAME_DEBUG |
| 584 | if (debug_options.bg_disabled[layer]) |
| 676 | 585 | return; |
| 677 | | #endif /* SNES_DBG_video */ |
| 586 | #endif /* MAME_DEBUG */ |
| 678 | 587 | |
| 679 | 588 | /* set special priority bit */ |
| 680 | | if( snes_ppu.mode == 1 && snes_ram[BGMODE] & 0x8 ) |
| 589 | if (color_depth == SNES_COLOR_DEPTH_2BPP && snes_ppu.mode == 1 && snes_ram[BGMODE] & 0x8) |
| 681 | 590 | bg3_pty = 1; |
| 682 | 591 | |
| 683 | 592 | /* Handle Mosaic effects */ |
| 684 | | if( snes_ram[MOSAIC] & (1 << layer) ) |
| 593 | if (snes_ram[MOSAIC] & (1 << layer)) |
| 685 | 594 | curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1)); |
| 686 | 595 | |
| 687 | 596 | /* Find the size of the tiles (8x8 or 16x16) */ |
| r5355 | r5356 | |
| 696 | 605 | vtilescroll = vscroll + (curline >> (3 + tile_size)); |
| 697 | 606 | /* figure out which line to draw */ |
| 698 | 607 | line = (curline % (8 << tile_size)) + vshift; |
| 699 | | if( line > ((8 << tile_size) - 1) ) /* scrolled into the next tile */ |
| 608 | if (line > ((8 << tile_size) - 1)) /* scrolled into the next tile */ |
| 700 | 609 | { |
| 701 | 610 | vtilescroll++; /* pretend we scrolled by 1 tile line */ |
| 702 | 611 | line -= (8 << tile_size); |
| r5355 | r5356 | |
| 717 | 626 | /* Scroll horizontally */ |
| 718 | 627 | tmap += (hscroll & 0x1f) << 1; |
| 719 | 628 | |
| 720 | | for( ii = 0; ii < (66 >> tile_size); ii += 2 ) |
| 629 | /* set a couple of variables depending on color_dept */ |
| 630 | switch (color_depth) |
| 721 | 631 | { |
| 632 | case SNES_COLOR_DEPTH_2BPP: |
| 633 | divider = 2; |
| 634 | color_shift = 0; |
| 635 | break; |
| 636 | case SNES_COLOR_DEPTH_4BPP: |
| 637 | divider = 2; |
| 638 | color_shift = 2; |
| 639 | break; |
| 640 | case SNES_COLOR_DEPTH_8BPP: |
| 641 | divider = 4; |
| 642 | color_shift = 6; // 2009-08 FP: this should be 6 or 8, if I'm following correctly the drawing code |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | for (ii = 0; ii < (66 >> tile_size); ii += 2) |
| 647 | { |
| 722 | 648 | /* Have we scrolled into the next map? */ |
| 723 | | if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) ) |
| 649 | if (hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f))) |
| 724 | 650 | { |
| 725 | 651 | tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3]; |
| 726 | 652 | tmap -= ii; |
| 727 | 653 | hscroll = 0; /* Make sure we don't do this again */ |
| 728 | 654 | } |
| 729 | | if (tmap > 0x10000) tmap %= 0x10000; |
| 730 | | vflip = (snes_vram[tmap + ii + 1] & 0x80); |
| 655 | if (tmap > 0x10000) |
| 656 | tmap %= 0x10000; |
| 657 | |
| 658 | vflip = snes_vram[tmap + ii + 1] & 0x80; |
| 731 | 659 | hflip = snes_vram[tmap + ii + 1] & 0x40; |
| 732 | | priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5]; |
| 733 | | pal = (snes_vram[tmap + ii + 1] & 0x1c); /* 8 palettes of 4 colours */ |
| 660 | priority = table_bgd_pty[snes_ppu.mode + (/*bg3_pty ? 8 :*/ 0)][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5]; // if bg3_pty=1 we would need to also change the object, but currently we cannot (see comment below) |
| 661 | pal = (snes_vram[tmap + ii + 1] & 0x1c) << color_shift; /* 8 palettes of (4 * color_shift) colours */ |
| 734 | 662 | tile = (snes_vram[tmap + ii + 1] & 0x3) << 8; |
| 735 | | tile |= (snes_vram[tmap + ii] & 0xff); |
| 663 | tile |= snes_vram[tmap + ii] & 0xff; |
| 736 | 664 | |
| 737 | 665 | /* Mode 0 palettes are layer specific */ |
| 738 | | if( snes_ppu.mode == 0 ) |
| 666 | if (snes_ppu.mode == 0) |
| 739 | 667 | { |
| 740 | 668 | pal += (layer << 5); |
| 741 | 669 | } |
| 742 | 670 | |
| 671 | |
| 743 | 672 | tile_line = line; |
| 744 | | if( vflip ) |
| 673 | if (vflip) |
| 745 | 674 | { |
| 746 | | if( tile_size ) |
| 675 | if (tile_size) |
| 747 | 676 | { |
| 748 | | if( line > 7 ) |
| 677 | if (line > 7) |
| 749 | 678 | { |
| 750 | 679 | tile_line -= 8; |
| 751 | 680 | } |
| 752 | 681 | else |
| 753 | 682 | { |
| 754 | | tile += 16; |
| 683 | tile += 32 / divider; |
| 755 | 684 | } |
| 756 | 685 | } |
| 757 | 686 | tile_line = -tile_line + 7; |
| 758 | 687 | } |
| 759 | 688 | else |
| 760 | 689 | { |
| 761 | | if( line > 7 ) |
| 690 | if (line > 7) |
| 762 | 691 | { |
| 763 | | tile += 16; |
| 692 | tile += 32 / divider; |
| 764 | 693 | tile_line -= 8; |
| 765 | 694 | } |
| 766 | 695 | } |
| 767 | 696 | tile_line <<= 1; |
| 768 | 697 | |
| 769 | | /* Special case for bg3 */ |
| 770 | | if( layer == 2 && bg3_pty && (snes_vram[tmap + ii + 1] & 0x20) ) |
| 771 | | priority = table_obj_pty[3] + 1; /* We want to have the highest priority here */ |
| 698 | /* Special case for bg3 (we should use the proper priority table, but draw object does not have access to this priority bit) */ |
| 699 | if (layer == 2 && bg3_pty && (snes_vram[tmap + ii + 1] & 0x20)) |
| 700 | priority = table_obj_pty[snes_ppu.mode][3] + 1; /* We want to have the highest priority here */ |
| 772 | 701 | |
| 773 | | if( tile_size ) |
| 702 | /* The code below can probably simplified even more, by directly calling snes_draw_tile_common... */ |
| 703 | if (tile_size) |
| 774 | 704 | { |
| 775 | | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 776 | | } |
| 777 | | else |
| 778 | | { |
| 779 | | snes_draw_tile_2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 780 | | } |
| 781 | | } |
| 782 | | } |
| 783 | | |
| 784 | | /********************************************* |
| 785 | | * snes_update_line_2_hi() |
| 786 | | * |
| 787 | | * Update an entire line of 2 bit plane tiles. |
| 788 | | * This is the hires version. |
| 789 | | *********************************************/ |
| 790 | | static void snes_update_line_2_hi(UINT8 screen, UINT8 layer, UINT16 curline ) |
| 791 | | { |
| 792 | | UINT32 tmap, tile; |
| 793 | | UINT16 ii, vflip, hflip, pal; |
| 794 | | INT8 line, tile_line; |
| 795 | | UINT8 priority; |
| 796 | | /* scrolling */ |
| 797 | | UINT32 basevmap; |
| 798 | | UINT16 vscroll, hscroll, vtilescroll; |
| 799 | | UINT8 vshift, hshift, tile_size; |
| 800 | | UINT8 bg3_pty = 0; |
| 801 | | |
| 802 | | #ifdef SNES_DBG_video |
| 803 | | if( debug_options.bg_disabled[layer] ) |
| 804 | | return; |
| 805 | | #endif /* SNES_DBG_video */ |
| 806 | | |
| 807 | | /* set special priority bit */ |
| 808 | | if( snes_ppu.mode == 1 && snes_ram[BGMODE] & 0x8 ) |
| 809 | | bg3_pty = 1; |
| 810 | | |
| 811 | | /* Handle Mosaic effects */ |
| 812 | | if( snes_ram[MOSAIC] & (1 << layer) ) |
| 813 | | curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1)); |
| 814 | | |
| 815 | | /* Find the size of the tiles (8x8 or 16x16) */ |
| 816 | | tile_size = snes_ppu.layer[layer].tile_size; |
| 817 | | /* Find scroll info */ |
| 818 | | vscroll = snes_ppu.layer[layer].offset.tile_vert; |
| 819 | | vshift = snes_ppu.layer[layer].offset.shift_vert; |
| 820 | | hscroll = snes_ppu.layer[layer].offset.tile_horz; |
| 821 | | hshift = snes_ppu.layer[layer].offset.shift_horz; |
| 822 | | |
| 823 | | /* Find vertical scroll amount */ |
| 824 | | vtilescroll = vscroll + (curline >> (3 + tile_size)); |
| 825 | | /* figure out which line to draw */ |
| 826 | | line = (curline % (8 << tile_size)) + vshift; |
| 827 | | if( line > ((8 << tile_size) - 1) ) /* scrolled into the next tile */ |
| 828 | | { |
| 829 | | vtilescroll++; /* pretend we scrolled by 1 tile line */ |
| 830 | | line -= (8 << tile_size); |
| 831 | | } |
| 832 | | if( vtilescroll >= 128 ) |
| 833 | | vtilescroll -= 128; |
| 834 | | |
| 835 | | /* Jump to base map address */ |
| 836 | | tmap = snes_ppu.layer[layer].map; |
| 837 | | /* Offset vertically */ |
| 838 | | tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5]; |
| 839 | | /* Scroll vertically */ |
| 840 | | tmap += (vtilescroll & 0x1f) << 6; |
| 841 | | /* Remember this position */ |
| 842 | | basevmap = tmap; |
| 843 | | /* Offset horizontally */ |
| 844 | | tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3]; |
| 845 | | /* Scroll horizontally */ |
| 846 | | tmap += (hscroll & 0x1f) << 1; |
| 847 | | |
| 848 | | for( ii = 0; ii < (66 >> tile_size); ii += 2 ) |
| 849 | | { |
| 850 | | /* Have we scrolled into the next map? */ |
| 851 | | if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) ) |
| 852 | | { |
| 853 | | tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3]; |
| 854 | | tmap -= ii; |
| 855 | | hscroll = 0; /* Make sure we don't do this again */ |
| 856 | | } |
| 857 | | if (tmap > 0x10000) tmap %= 0x10000; |
| 858 | | vflip = (snes_vram[tmap + ii + 1] & 0x80); |
| 859 | | hflip = snes_vram[tmap + ii + 1] & 0x40; |
| 860 | | priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5]; |
| 861 | | pal = (snes_vram[tmap + ii + 1] & 0x1c); /* 8 palettes of 4 colours */ |
| 862 | | tile = (snes_vram[tmap + ii + 1] & 0x3) << 8; |
| 863 | | tile |= snes_vram[tmap + ii]; |
| 864 | | |
| 865 | | /* Mode 0 palettes are layer specific */ |
| 866 | | if( snes_ppu.mode == 0 ) |
| 867 | | { |
| 868 | | pal += (layer << 5); |
| 869 | | } |
| 870 | | |
| 871 | | tile_line = line; |
| 872 | | if( vflip ) |
| 873 | | { |
| 874 | | if( tile_size ) |
| 705 | if (hires) /* Hi-Res: 2bpp & 4bpp */ |
| 875 | 706 | { |
| 876 | | if( line > 7 ) |
| 707 | if (hflip) |
| 877 | 708 | { |
| 878 | | tile_line -= 8; |
| 709 | switch (color_depth) |
| 710 | { |
| 711 | case SNES_COLOR_DEPTH_2BPP: |
| 712 | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 713 | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 714 | break; |
| 715 | case SNES_COLOR_DEPTH_4BPP: |
| 716 | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 717 | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 718 | break; |
| 719 | } |
| 879 | 720 | } |
| 880 | 721 | else |
| 881 | 722 | { |
| 882 | | tile += 16; |
| 723 | switch (color_depth) |
| 724 | { |
| 725 | case SNES_COLOR_DEPTH_2BPP: |
| 726 | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 727 | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 728 | break; |
| 729 | |
| 730 | case SNES_COLOR_DEPTH_4BPP: |
| 731 | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 732 | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 733 | break; |
| 734 | } |
| 883 | 735 | } |
| 884 | 736 | } |
| 885 | | tile_line = -tile_line + 7; |
| 886 | | } |
| 887 | | else |
| 888 | | { |
| 889 | | if( line > 7 ) |
| 737 | else /* No Hi-Res: 2bpp, 4bpp & 8bpp */ |
| 890 | 738 | { |
| 891 | | tile += 16; |
| 892 | | tile_line -= 8; |
| 893 | | } |
| 894 | | } |
| 895 | | tile_line <<= 1; |
| 739 | switch (color_depth) |
| 740 | { |
| 741 | case SNES_COLOR_DEPTH_2BPP: |
| 742 | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 743 | break; |
| 896 | 744 | |
| 897 | | /* Special case for bg3 */ |
| 898 | | if( layer == 2 && bg3_pty && (snes_vram[tmap + ii + 1] & 0x20) ) |
| 899 | | priority = table_obj_pty[3] + 1; /* We want to have the highest priority here */ |
| 745 | case SNES_COLOR_DEPTH_4BPP: |
| 746 | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 747 | break; |
| 900 | 748 | |
| 901 | | if( tile_size ) |
| 749 | case SNES_COLOR_DEPTH_8BPP: |
| 750 | snes_draw_tile_8x2(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip ); |
| 751 | break; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | else /* tile_size = 0 */ |
| 902 | 756 | { |
| 903 | | if( hflip ) |
| 757 | if (hires) /* Hi-Res: 2bpp & 4bpp */ |
| 904 | 758 | { |
| 905 | | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 906 | | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 759 | switch (color_depth) |
| 760 | { |
| 761 | case SNES_COLOR_DEPTH_2BPP: |
| 762 | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 763 | break; |
| 764 | |
| 765 | case SNES_COLOR_DEPTH_4BPP: |
| 766 | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 767 | break; |
| 768 | } |
| 907 | 769 | } |
| 908 | | else |
| 770 | else /* No Hi-Res: 2bpp, 4bpp & 8bpp */ |
| 909 | 771 | { |
| 910 | | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 911 | | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 772 | switch (color_depth) |
| 773 | { |
| 774 | case SNES_COLOR_DEPTH_2BPP: |
| 775 | snes_draw_tile_2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 776 | break; |
| 777 | |
| 778 | case SNES_COLOR_DEPTH_4BPP: |
| 779 | snes_draw_tile_4(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 780 | break; |
| 781 | |
| 782 | case SNES_COLOR_DEPTH_8BPP: |
| 783 | snes_draw_tile_8(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip ); |
| 784 | break; |
| 785 | } |
| 912 | 786 | } |
| 913 | 787 | } |
| 914 | | else |
| 915 | | { |
| 916 | | snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 917 | | } |
| 918 | 788 | } |
| 919 | 789 | } |
| 920 | 790 | |
| 921 | 791 | /********************************************* |
| 792 | * snes_update_line_2() |
| 793 | * |
| 794 | * Update an entire line of 2 bit plane tiles. |
| 795 | *********************************************/ |
| 796 | static void snes_update_line_2(UINT8 screen, UINT8 layer, UINT16 curline ) |
| 797 | { |
| 798 | snes_update_line_common(screen, SNES_COLOR_DEPTH_2BPP, 0, layer, curline); |
| 799 | } |
| 800 | |
| 801 | /********************************************* |
| 802 | * snes_update_line_2_hi() |
| 803 | * |
| 804 | * Update an entire line of 2 bit plane tiles. |
| 805 | * This is the hires version. |
| 806 | *********************************************/ |
| 807 | static void snes_update_line_2_hi(UINT8 screen, UINT8 layer, UINT16 curline ) |
| 808 | { |
| 809 | snes_update_line_common(screen, SNES_COLOR_DEPTH_2BPP, 1, layer, curline); |
| 810 | } |
| 811 | |
| 812 | /********************************************* |
| 922 | 813 | * snes_update_line_4() |
| 923 | 814 | * |
| 924 | 815 | * Update an entire line of 4 bit plane tiles. |
| 925 | 816 | *********************************************/ |
| 926 | 817 | static void snes_update_line_4(UINT8 screen, UINT8 layer, UINT16 curline ) |
| 927 | 818 | { |
| 928 | | UINT32 tmap, tile; |
| 929 | | UINT16 ii, vflip, hflip, pal; |
| 930 | | INT8 line, tile_line; |
| 931 | | UINT8 priority; |
| 932 | | /* scrolling */ |
| 933 | | UINT32 basevmap; |
| 934 | | UINT16 vscroll, hscroll, vtilescroll; |
| 935 | | UINT8 vshift, hshift, tile_size; |
| 936 | | |
| 937 | | #ifdef SNES_DBG_video |
| 938 | | if( debug_options.bg_disabled[layer] ) |
| 939 | | return; |
| 940 | | #endif /* SNES_DBG_video */ |
| 941 | | |
| 942 | | /* Handle Mosaic effects */ |
| 943 | | if( snes_ram[MOSAIC] & (1 << layer) ) |
| 944 | | curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1)); |
| 945 | | |
| 946 | | /* Find the size of the tiles (8x8 or 16x16) */ |
| 947 | | tile_size = snes_ppu.layer[layer].tile_size; |
| 948 | | /* Find scroll info */ |
| 949 | | vscroll = snes_ppu.layer[layer].offset.tile_vert; |
| 950 | | vshift = snes_ppu.layer[layer].offset.shift_vert; |
| 951 | | hscroll = snes_ppu.layer[layer].offset.tile_horz; |
| 952 | | hshift = snes_ppu.layer[layer].offset.shift_horz; |
| 953 | | |
| 954 | | /* Jump to base map address */ |
| 955 | | tmap = snes_ppu.layer[layer].map; |
| 956 | | |
| 957 | | /* Find vertical scroll amount */ |
| 958 | | vtilescroll = vscroll + (curline >> (3 + tile_size)); |
| 959 | | /* figure out which line to draw */ |
| 960 | | line = (curline % (8 << tile_size)) + vshift; |
| 961 | | if( line > ((8 << tile_size) - 1) ) /* scrolled into the next tile */ |
| 962 | | { |
| 963 | | vtilescroll++; /* pretend we scrolled by 1 tile line */ |
| 964 | | line -= (8 << tile_size); |
| 965 | | } |
| 966 | | if( vtilescroll >= 128 ) |
| 967 | | vtilescroll -= 128; |
| 968 | | |
| 969 | | /* Offset vertically */ |
| 970 | | tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5]; |
| 971 | | /* Scroll vertically */ |
| 972 | | tmap += (vtilescroll & 0x1f) << 6; |
| 973 | | /* Remember this position */ |
| 974 | | basevmap = tmap; |
| 975 | | /* Offset horizontally */ |
| 976 | | tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3]; |
| 977 | | /* Scroll horizontally */ |
| 978 | | tmap += (hscroll & 0x1f) << 1; |
| 979 | | |
| 980 | | for( ii = 0; ii < (66 >> tile_size); ii += 2 ) |
| 981 | | { |
| 982 | | /* Have we scrolled into the next map? */ |
| 983 | | if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) ) |
| 984 | | { |
| 985 | | tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3]; |
| 986 | | tmap -= ii; |
| 987 | | hscroll = 0; /* Make sure we don't do this again */ |
| 988 | | } |
| 989 | | if (tmap > 0x10000) tmap %= 0x10000; |
| 990 | | vflip = snes_vram[tmap + ii + 1] & 0x80; |
| 991 | | hflip = snes_vram[tmap + ii + 1] & 0x40; |
| 992 | | priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5]; /* is this even right??? */ |
| 993 | | pal = (snes_vram[tmap + ii + 1] & 0x1c) << 2; /* 8 palettes of 16 colours */ |
| 994 | | tile = (snes_vram[tmap + ii + 1] & 0x3) << 8; |
| 995 | | tile |= snes_vram[tmap + ii]; |
| 996 | | |
| 997 | | tile_line = line; |
| 998 | | if( vflip ) |
| 999 | | { |
| 1000 | | if( tile_size ) |
| 1001 | | { |
| 1002 | | if( line > 7 ) |
| 1003 | | { |
| 1004 | | tile_line -= 8; |
| 1005 | | } |
| 1006 | | else |
| 1007 | | { |
| 1008 | | tile += 16; |
| 1009 | | } |
| 1010 | | } |
| 1011 | | tile_line = -tile_line + 7; |
| 1012 | | } |
| 1013 | | else |
| 1014 | | { |
| 1015 | | if( line > 7 ) |
| 1016 | | { |
| 1017 | | tile += 16; |
| 1018 | | tile_line -= 8; |
| 1019 | | } |
| 1020 | | } |
| 1021 | | tile_line <<= 1; |
| 1022 | | |
| 1023 | | if( tile_size ) |
| 1024 | | { |
| 1025 | | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 1026 | | } |
| 1027 | | else |
| 1028 | | { |
| 1029 | | snes_draw_tile_4(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal ); |
| 1030 | | } |
| 1031 | | } |
| 819 | snes_update_line_common(screen, SNES_COLOR_DEPTH_4BPP, 0, layer, curline); |
| 1032 | 820 | } |
| 1033 | 821 | |
| 1034 | 822 | /********************************************* |
| r5355 | r5356 | |
| 1039 | 827 | *********************************************/ |
| 1040 | 828 | static void snes_update_line_4_hi(UINT8 screen, UINT8 layer, UINT16 curline ) |
| 1041 | 829 | { |
| 1042 | | UINT32 tmap, tile; |
| 1043 | | UINT16 ii, vflip, hflip, pal; |
| 1044 | | INT8 line, tile_line; |
| 1045 | | UINT8 priority; |
| 1046 | | /* scrolling */ |
| 1047 | | UINT32 basevmap; |
| 1048 | | UINT16 vscroll, hscroll, vtilescroll; |
| 1049 | | UINT8 vshift, hshift, tile_size; |
| 1050 | | |
| 1051 | | #ifdef SNES_DBG_video |
| 1052 | | if( debug_options.bg_disabled[layer] ) |
| 1053 | | return; |
| 1054 | | #endif /* SNES_DBG_video */ |
| 1055 | | |
| 1056 | | /* Handle Mosaic effects */ |
| 1057 | | if( snes_ram[MOSAIC] & (1 << layer) ) |
| 1058 | | curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1)); |
| 1059 | | |
| 1060 | | /* Find the size of the tiles (8x8 or 16x16) */ |
| 1061 | | tile_size = snes_ppu.layer[layer].tile_size; |
| 1062 | | /* Find scroll info */ |
| 1063 | | vscroll = snes_ppu.layer[layer].offset.tile_vert; |
| 1064 | | vshift = snes_ppu.layer[layer].offset.shift_vert; |
| 1065 | | hscroll = snes_ppu.layer[layer].offset.tile_horz; |
| 1066 | | hshift = snes_ppu.layer[layer].offset.shift_horz; |
| 1067 | | |
| 1068 | | /* Find vertical scroll amount */ |
| 1069 | | vtilescroll = vscroll + (curline >> (3 + tile_size)); |
| 1070 | | /* figure out which line to draw */ |
| 1071 | | line = (curline % (8 << tile_size)) + vshift; |
| 1072 | | if( line > ((8 << tile_size) - 1) ) /* scrolled into the next tile */ |
| 1073 | | { |
| 1074 | | vtilescroll++; /* pretend we scrolled by 1 tile line */ |
| 1075 | | line -= (8 << tile_size); |
| 1076 | | } |
| 1077 | | if( vtilescroll >= 128 ) |
| 1078 | | vtilescroll -= 128; |
| 1079 | | |
| 1080 | | /* Jump to base map address */ |
| 1081 | | tmap = snes_ppu.layer[layer].map; |
| 1082 | | /* Offset vertically */ |
| 1083 | | tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5]; |
| 1084 | | /* Scroll vertically */ |
| 1085 | | tmap += (vtilescroll & 0x1f) << 6; |
| 1086 | | /* Remember this position */ |
| 1087 | | basevmap = tmap; |
| 1088 | | /* Offset horizontally */ |
| 1089 | | tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3]; |
| 1090 | | /* Scroll horizontally */ |
| 1091 | | tmap += (hscroll & 0x1f) << 1; |
| 1092 | | |
| 1093 | | for( ii = 0; ii < (66 >> tile_size); ii += 2 ) |
| 1094 | | { |
| 1095 | | /* Have we scrolled into the next map? */ |
| 1096 | | if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) ) |
| 1097 | | { |
| 1098 | | tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3]; |
| 1099 | | tmap -= ii; |
| 1100 | | hscroll = 0; /* Make sure we don't do this again */ |
| 1101 | | } |
| 1102 | | if (tmap > 0x10000) tmap %= 0x10000; |
| 1103 | | |
| 1104 | | vflip = snes_vram[tmap + ii + 1] & 0x80; |
| 1105 | | hflip = snes_vram[tmap + ii + 1] & 0x40; |
| 1106 | | priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5]; /* is this even right??? */ |
| 1107 | | pal = (snes_vram[tmap + ii + 1] & 0x1c) << 2; /* 8 palettes of 16 colours */ |
| 1108 | | tile = (snes_vram[tmap + ii + 1] & 0x3) << 8; |
| 1109 | | tile |= snes_vram[tmap + ii]; |
| 1110 | | |
| 1111 | | tile_line = line; |
| 1112 | | if( vflip ) |
| 1113 | | { |
| 1114 | | if( tile_size ) |
| 1115 | | { |
| 1116 | | if( line > 7 ) |
| 1117 | | { |
| 1118 | | tile_line -= 8; |
| 1119 | | } |
| 1120 | | else |
| 1121 | | { |
| 1122 | | tile += 16; |
| 1123 | | } |
| 1124 | | } |
| 1125 | | tile_line = -tile_line + 7; |
| 1126 | | } |
| 1127 | | else |
| 1128 | | { |
| 1129 | | if( line > 7 ) |
| 1130 | | { |
| 1131 | | tile += 16; |
| 1132 | | tile_line -= 8; |
| 1133 | | } |
| 1134 | | } |
| 1135 | | tile_line <<= 1; |
| 1136 | | |
| 1137 | | /* Does hi-res support the tile-size option? */ |
| 1138 | | if( tile_size ) |
| 1139 | | { |
| 1140 | | if( hflip ) |
| 1141 | | { |
| 1142 | | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 1143 | | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 1144 | | } |
| 1145 | | else |
| 1146 | | { |
| 1147 | | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 1148 | | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal ); |
| 1149 | | } |
| 1150 | | } |
| 1151 | | else |
| 1152 | | { |
| 1153 | | snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal ); |
| 1154 | | } |
| 1155 | | } |
| 830 | /* Does hi-res support the tile-size option? */ |
| 831 | snes_update_line_common(screen, SNES_COLOR_DEPTH_4BPP, 1, layer, curline); |
| 1156 | 832 | } |
| 1157 | 833 | |
| 1158 | 834 | /********************************************* |
| r5355 | r5356 | |
| 1162 | 838 | *********************************************/ |
| 1163 | 839 | static void snes_update_line_8(UINT8 screen, UINT8 layer, UINT16 curline ) |
| 1164 | 840 | { |
| 1165 | | UINT32 tmap, tile; |
| 1166 | | UINT16 ii, vflip, hflip, pal; |
| 1167 | | INT8 line, tile_line; |
| 1168 | | UINT8 priority; |
| 1169 | | /* scrolling */ |
| 1170 | | UINT32 basevmap; |
| 1171 | | UINT16 vscroll, hscroll, vtilescroll; |
| 1172 | | UINT8 vshift, hshift, tile_size; |
| 1173 | | |
| 1174 | | #ifdef SNES_DBG_video |
| 1175 | | if( debug_options.bg_disabled[layer] ) |
| 1176 | | return; |
| 1177 | | #endif /* SNES_DBG_video */ |
| 1178 | | |
| 1179 | | /* Handle Mosaic effects */ |
| 1180 | | if( snes_ram[MOSAIC] & (1 << layer) ) |
| 1181 | | curline -= (curline % ((snes_ram[MOSAIC] >> 4) + 1)); |
| 1182 | | |
| 1183 | | /* Find the size of the tiles (8x8 or 16x16) */ |
| 1184 | | tile_size = snes_ppu.layer[layer].tile_size; |
| 1185 | | /* Find scroll info */ |
| 1186 | | vscroll = snes_ppu.layer[layer].offset.tile_vert; |
| 1187 | | vshift = snes_ppu.layer[layer].offset.shift_vert; |
| 1188 | | hscroll = snes_ppu.layer[layer].offset.tile_horz; |
| 1189 | | hshift = snes_ppu.layer[layer].offset.shift_horz; |
| 1190 | | |
| 1191 | | /* Find vertical scroll amount */ |
| 1192 | | vtilescroll = vscroll + (curline >> (3 + tile_size)); |
| 1193 | | /* figure out which line to draw */ |
| 1194 | | line = (curline % (8 << tile_size)) + vshift; |
| 1195 | | if( line > ((8 << tile_size) - 1) ) /* scrolled into the next tile */ |
| 1196 | | { |
| 1197 | | vtilescroll++; /* pretend we scrolled by 1 tile line */ |
| 1198 | | line -= (8 << tile_size); |
| 1199 | | } |
| 1200 | | if( vtilescroll >= 128 ) |
| 1201 | | vtilescroll -= 128; |
| 1202 | | |
| 1203 | | /* Jump to base map address */ |
| 1204 | | tmap = snes_ppu.layer[layer].map; |
| 1205 | | /* Offset vertically */ |
| 1206 | | tmap += table_vscroll[snes_ppu.layer[layer].map_size][vtilescroll >> 5]; |
| 1207 | | /* Scroll vertically */ |
| 1208 | | tmap += (vtilescroll & 0x1f) << 6; |
| 1209 | | /* Remember this position */ |
| 1210 | | basevmap = tmap; |
| 1211 | | /* Offset horizontally */ |
| 1212 | | tmap += table_hscroll[snes_ppu.layer[layer].map_size & 3][(hscroll >> 5) & 3]; |
| 1213 | | /* Scroll horizontally */ |
| 1214 | | tmap += (hscroll & 0x1f) << 1; |
| 1215 | | |
| 1216 | | for( ii = 0; ii < (66 >> tile_size); ii += 2 ) |
| 1217 | | { |
| 1218 | | /* Have we scrolled into the next map? */ |
| 1219 | | if( hscroll && ((ii >> 1) >= 32 - (hscroll & 0x1f)) ) |
| 1220 | | { |
| 1221 | | tmap = basevmap + table_hscroll[snes_ppu.layer[layer].map_size & 3][((hscroll >> 5) + 1) & 3]; |
| 1222 | | tmap -= ii; |
| 1223 | | hscroll = 0; /* Make sure we don't do this again */ |
| 1224 | | } |
| 1225 | | if (tmap > 0x10000) tmap %= 0x10000; |
| 1226 | | vflip = (snes_vram[tmap + ii + 1] & 0x80); |
| 1227 | | hflip = snes_vram[tmap + ii + 1] & 0x40; |
| 1228 | | priority = table_bgd_pty[snes_ppu.mode > 1][layer][(snes_vram[tmap + ii + 1] & 0x20) >> 5]; |
| 1229 | | pal = (snes_vram[tmap + ii + 1] & 0x1c); /* what does this do for 8 bit screen? */ |
| 1230 | | tile = (snes_vram[tmap + ii + 1] & 0x3) << 8; |
| 1231 | | tile |= snes_vram[tmap + ii]; |
| 1232 | | |
| 1233 | | tile_line = line; |
| 1234 | | if( vflip ) |
| 1235 | | { |
| 1236 | | if( tile_size ) |
| 1237 | | { |
| 1238 | | if( line > 7 ) |
| 1239 | | { |
| 1240 | | tile_line -= 8; |
| 1241 | | } |
| 1242 | | else |
| 1243 | | { |
| 1244 | | tile += 8; |
| 1245 | | } |
| 1246 | | } |
| 1247 | | tile_line = -tile_line + 7; |
| 1248 | | } |
| 1249 | | else |
| 1250 | | { |
| 1251 | | if( line > 7 ) |
| 1252 | | { |
| 1253 | | tile += 8; |
| 1254 | | tile_line -= 8; |
| 1255 | | } |
| 1256 | | } |
| 1257 | | tile_line <<= 1; |
| 1258 | | |
| 1259 | | if( tile_size ) |
| 1260 | | { |
| 1261 | | snes_draw_tile_8x2(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip ); |
| 1262 | | } |
| 1263 | | else |
| 1264 | | { |
| 1265 | | snes_draw_tile_8(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip ); |
| 1266 | | } |
| 1267 | | } |
| 841 | snes_update_line_common(screen, SNES_COLOR_DEPTH_8BPP, 0, layer, curline); |
| 1268 | 842 | } |
| 1269 | 843 | |
| 1270 | 844 | /********************************************* |
| r5355 | r5356 | |
| 1280 | 854 | UINT8 priority = 0; |
| 1281 | 855 | UINT8 colour = 0; |
| 1282 | 856 | |
| 1283 | | #ifdef SNES_DBG_video |
| 857 | #ifdef MAME_DEBUG |
| 1284 | 858 | if( debug_options.bg_disabled[0] ) |
| 1285 | 859 | return; |
| 1286 | | #endif /* SNES_DBG_video */ |
| 860 | #endif /* MAME_DEBUG */ |
| 1287 | 861 | |
| 1288 | 862 | ma = snes_ppu.mode7.matrix_a; |
| 1289 | 863 | mb = snes_ppu.mode7.matrix_b; |
| r5355 | r5356 | |
| 1369 | 943 | colour &= snes_ppu.clipmasks[0][xpos]; |
| 1370 | 944 | |
| 1371 | 945 | /* Draw pixel if appropriate */ |
| 1372 | | if( scanlines[screen].zbuf[xpos] < table_bgd_pty[1][0][priority] && colour > 0 ) |
| 946 | if( scanlines[screen].zbuf[xpos] < table_bgd_pty[7][0][priority] && colour > 0 ) |
| 1373 | 947 | { |
| 1374 | 948 | UINT16 clr; |
| 1375 | 949 | /* Direct select */ |
| r5355 | r5356 | |
| 1382 | 956 | snes_draw_blend(xpos, &clr, snes_ppu.layer[0].blend, (snes_ram[CGWSEL] & 0x30) >> 4 ); /* FIXME: Need to support clip mode */ |
| 1383 | 957 | |
| 1384 | 958 | scanlines[screen].buffer[xpos] = clr; |
| 1385 | | scanlines[screen].zbuf[xpos] = table_bgd_pty[1][0][priority]; |
| 959 | scanlines[screen].zbuf[xpos] = table_bgd_pty[7][0][priority]; |
| 1386 | 960 | } |
| 1387 | 961 | } |
| 1388 | 962 | } |
| r5355 | r5356 | |
| 1406 | 980 | UINT8 *oamram = (UINT8 *)snes_oam; |
| 1407 | 981 | UINT32 name_sel = 0; |
| 1408 | 982 | |
| 1409 | | #ifdef SNES_DBG_video |
| 983 | #ifdef MAME_DEBUG |
| 1410 | 984 | if( debug_options.bg_disabled[4] ) |
| 1411 | 985 | return; |
| 1412 | | #endif /* SNES_DBG_video */ |
| 986 | #endif /* MAME_DEBUG */ |
| 1413 | 987 | |
| 1414 | 988 | if( snes_ppu.mode == 5 || snes_ppu.mode == 6 ) |
| 1415 | 989 | widemode = 1; |
| r5355 | r5356 | |
| 1424 | 998 | |
| 1425 | 999 | vflip = (oamram[oam] & 0x80) >> 7; |
| 1426 | 1000 | hflip = (oamram[oam] & 0x40) >> 6; |
| 1427 | | priority = table_obj_pty[(oamram[oam] & 0x30) >> 4]; |
| 1001 | priority = table_obj_pty[snes_ppu.mode][(oamram[oam] & 0x30) >> 4]; |
| 1428 | 1002 | pal = 128 + ((oamram[oam] & 0xE) << 3); |
| 1429 | 1003 | tile = (oamram[oam--] & 0x1) << 8; |
| 1430 | 1004 | tile |= oamram[oam--]; |
| r5355 | r5356 | |
| 1833 | 1407 | * |
| 1834 | 1408 | * Redraw the current line. |
| 1835 | 1409 | *********************************************/ |
| 1836 | | static void snes_refresh_scanline(bitmap_t *bitmap, UINT16 curline ) |
| 1410 | static void snes_refresh_scanline( running_machine *machine, bitmap_t *bitmap, UINT16 curline ) |
| 1837 | 1411 | { |
| 1838 | 1412 | UINT16 ii; |
| 1839 | 1413 | int x; |
| r5355 | r5356 | |
| 1877 | 1451 | snes_modedefs[snes_ppu.mode].drawLayer[ii](SUBSCREEN, ii, curline ); |
| 1878 | 1452 | } |
| 1879 | 1453 | /* Draw the back plane */ |
| 1880 | | #ifdef SNES_DBG_video |
| 1454 | #ifdef MAME_DEBUG |
| 1881 | 1455 | if( !debug_options.bg_disabled[5] ) |
| 1882 | | #endif /* SNES_DBG_video */ |
| 1456 | #endif /* MAME_DEBUG */ |
| 1883 | 1457 | if( snes_ram[CGADSUB] & 0x20 ) |
| 1884 | 1458 | { |
| 1885 | 1459 | for( ii = 0; ii < SNES_SCR_WIDTH * snes_htmult; ii++ ) |
| r5355 | r5356 | |
| 1896 | 1470 | snes_modedefs[snes_ppu.mode].drawLayer[ii](MAINSCREEN, ii, curline ); |
| 1897 | 1471 | } |
| 1898 | 1472 | |
| 1899 | | #ifdef SNES_DBG_video |
| 1900 | | if( snes_dbg_video(bitmap, curline ) ) |
| 1473 | #ifdef MAME_DEBUG |
| 1474 | if( snes_dbg_video(machine, bitmap, curline) ) |
| 1901 | 1475 | { |
| 1902 | 1476 | profiler_mark(PROFILER_END); |
| 1903 | 1477 | return; |
| r5355 | r5356 | |
| 1907 | 1481 | if( debug_options.draw_subscreen ) |
| 1908 | 1482 | scanline = &scanlines[SUBSCREEN]; |
| 1909 | 1483 | else |
| 1910 | | #endif /* SNES_DBG_video */ |
| 1484 | #endif /* MAME_DEBUG */ |
| 1911 | 1485 | scanline = &scanlines[MAINSCREEN]; |
| 1912 | 1486 | |
| 1913 | 1487 | /* Phew! Draw the line to screen */ |
| r5355 | r5356 | |
| 1930 | 1504 | int y; |
| 1931 | 1505 | |
| 1932 | 1506 | for (y = cliprect->min_y; y <= cliprect->max_y; y++) |
| 1933 | | snes_refresh_scanline(bitmap, y); |
| 1507 | snes_refresh_scanline(screen->machine, bitmap, y); |
| 1934 | 1508 | return 0; |
| 1935 | 1509 | } |
| 1936 | 1510 | |
| 1937 | 1511 | |
| 1938 | 1512 | /***** Debug Functions *****/ |
| 1939 | 1513 | |
| 1940 | | #ifdef SNES_DBG_video |
| 1514 | #ifdef MAME_DEBUG |
| 1941 | 1515 | |
| 1942 | | static void snes_dbg_draw_maps(bitmap_t *bitmap, UINT32 tmap, UINT8 bpl, UINT16 curline, UINT8 layer ) |
| 1516 | static void snes_dbg_draw_maps( bitmap_t *bitmap, UINT32 tmap, UINT8 bpl, UINT16 curline, UINT8 layer ) |
| 1943 | 1517 | { |
| 1944 | 1518 | UINT32 tile, addr = tmap; |
| 1945 | 1519 | UINT16 ii, vflip, hflip, pal; |
| 1946 | 1520 | INT8 line; |
| 1947 | | char str[50]; |
| 1948 | 1521 | |
| 1949 | 1522 | tmap += (curline >> 3) * 64; |
| 1950 | 1523 | for( ii = 0; ii < 64; ii += 2 ) |
| r5355 | r5356 | |
| 1976 | 1549 | } |
| 1977 | 1550 | } |
| 1978 | 1551 | |
| 1979 | | sprintf( str, "%d : %8X ", layer, addr ); |
| 1552 | logerror("%d : %8X ", layer, addr ); |
| 1980 | 1553 | //ui_draw_text( str, 0, 227 ); |
| 1981 | 1554 | } |
| 1982 | 1555 | |
| 1983 | | static void snes_dbg_draw_all_tiles(bitmap_t *bitmap, UINT32 tileaddr, UINT8 bpl, UINT16 pal ) |
| 1556 | static void snes_dbg_draw_all_tiles( running_machine *machine, bitmap_t *bitmap, UINT32 tileaddr, UINT8 bpl, UINT16 pal ) |
| 1984 | 1557 | { |
| 1985 | 1558 | UINT16 ii, jj, kk; |
| 1986 | 1559 | UINT32 addr = tileaddr; |
| 1987 | | char str[50]; |
| 1988 | 1560 | |
| 1989 | 1561 | for( jj = 0; jj < 32; jj++ ) |
| 1990 | 1562 | { |
| r5355 | r5356 | |
| 2022 | 1594 | } |
| 2023 | 1595 | } |
| 2024 | 1596 | |
| 2025 | | sprintf( str, " %8X ", tileaddr ); |
| 1597 | logerror(" %8X ", tileaddr ); |
| 2026 | 1598 | //ui_draw_text( str, 0, 227 ); |
| 2027 | 1599 | } |
| 2028 | 1600 | |
| 2029 | | static UINT8 snes_dbg_video(bitmap_t *bitmap, UINT16 curline ) |
| 1601 | static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16 curline ) |
| 2030 | 1602 | { |
| 2031 | 1603 | UINT16 ii; |
| 2032 | 1604 | |
| r5355 | r5356 | |
| 2036 | 1608 | if( curline == 0 ) |
| 2037 | 1609 | { |
| 2038 | 1610 | //UINT16 y = 1; |
| 2039 | | char t[100]; |
| 2040 | 1611 | static const char WINLOGIC[4] = { '|', '&', '^', '!' }; |
| 2041 | 1612 | |
| 2042 | 1613 | if( !debug_options.input_count-- ) |
| r5355 | r5356 | |
| 2064 | 1635 | debug_options.input_count = 5; |
| 2065 | 1636 | } |
| 2066 | 1637 | /* Display some debug info on the screen */ |
| 2067 | | sprintf( t, "%s%s", debug_options.windows_disabled?" ":"W", debug_options.transparency_disabled?" ":"T" ); |
| 1638 | logerror("%s%s", debug_options.windows_disabled?" ":"W", debug_options.transparency_disabled?" ":"T" ); |
| 2068 | 1639 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2069 | | sprintf( t, "%s1 %s%s%s%s%s%c%s%s%d%s %d %4X %4X", |
| 1640 | logerror("%s1 %s%s%s%s%s%c%s%s%d%s %d %4X %4X", |
| 2070 | 1641 | debug_options.bg_disabled[0]?" ":"*", |
| 2071 | 1642 | (snes_ram[TM] & 0x1)?"M":" ", |
| 2072 | 1643 | (snes_ram[TS] & 0x1)?"S":" ", |
| r5355 | r5356 | |
| 2082 | 1653 | (snes_ram[BG1SC] & 0xfc) << 9, |
| 2083 | 1654 | snes_ppu.layer[0].data ); |
| 2084 | 1655 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2085 | | sprintf( t, "%s2 %s%s%s%s%s%c%s%s%d%s %d %4X %4X", |
| 1656 | logerror("%s2 %s%s%s%s%s%c%s%s%d%s %d %4X %4X", |
| 2086 | 1657 | debug_options.bg_disabled[1]?" ":"*", |
| 2087 | 1658 | (snes_ram[TM] & 0x2)?"M":" ", |
| 2088 | 1659 | (snes_ram[TS] & 0x2)?"S":" ", |
| r5355 | r5356 | |
| 2098 | 1669 | (snes_ram[BG2SC] & 0xfc) << 9, |
| 2099 | 1670 | snes_ppu.layer[1].data ); |
| 2100 | 1671 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2101 | | sprintf( t, "%s3 %s%s%s%s%s%c%s%s%d%s%s%d %4X %4X", |
| 1672 | logerror("%s3 %s%s%s%s%s%c%s%s%d%s%s%d %4X %4X", |
| 2102 | 1673 | debug_options.bg_disabled[2]?" ":"*", |
| 2103 | 1674 | (snes_ram[TM] & 0x4)?"M":" ", |
| 2104 | 1675 | (snes_ram[TS] & 0x4)?"S":" ", |
| r5355 | r5356 | |
| 2115 | 1686 | (snes_ram[BG3SC] & 0xfc) << 9, |
| 2116 | 1687 | snes_ppu.layer[2].data ); |
| 2117 | 1688 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2118 | | sprintf( t, "%s4 %s%s%s%s%s%c%s%s%d%s %d %4X %4X", |
| 1689 | logerror("%s4 %s%s%s%s%s%c%s%s%d%s %d %4X %4X", |
| 2119 | 1690 | debug_options.bg_disabled[3]?" ":"*", |
| 2120 | 1691 | (snes_ram[TM] & 0x8)?"M":" ", |
| 2121 | 1692 | (snes_ram[TS] & 0x8)?"S":" ", |
| r5355 | r5356 | |
| 2131 | 1702 | (snes_ram[BG4SC] & 0xfc) << 9, |
| 2132 | 1703 | snes_ppu.layer[3].data ); |
| 2133 | 1704 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2134 | | sprintf( t, "%sO %s%s%s%s%s%c%s%s%d%d %4X", |
| 1705 | logerror("%sO %s%s%s%s%s%c%s%s%d%d %4X", |
| 2135 | 1706 | debug_options.bg_disabled[4]?" ":"*", |
| 2136 | 1707 | (snes_ram[TM] & 0x10)?"M":" ", |
| 2137 | 1708 | (snes_ram[TS] & 0x10)?"S":" ", |
| r5355 | r5356 | |
| 2144 | 1715 | snes_ppu.oam.size[0], snes_ppu.oam.size[1], |
| 2145 | 1716 | snes_ppu.layer[4].data ); |
| 2146 | 1717 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2147 | | sprintf( t, "%sB %s %c%s%s", |
| 1718 | logerror("%sB %s %c%s%s", |
| 2148 | 1719 | debug_options.bg_disabled[5]?" ":"*", |
| 2149 | 1720 | (snes_ram[CGADSUB] & 0x20)?"B":" ", |
| 2150 | 1721 | WINLOGIC[(snes_ram[WOBJLOG] & 0xc)>>2], |
| 2151 | 1722 | (snes_ram[WOBJSEL] & 0x20)?((snes_ram[WOBJSEL] & 0x10)?"o":"i"):" ", |
| 2152 | 1723 | (snes_ram[WOBJSEL] & 0x80)?((snes_ram[WOBJSEL] & 0x40)?"o":"i"):" " ); |
| 2153 | 1724 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2154 | | sprintf( t, "1) %3d %3d 2) %3d %3d", (snes_ppu.bgd_offset.horizontal[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[1] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[1] & 0x3ff) >> 3 ); |
| 1725 | logerror("1) %3d %3d 2) %3d %3d", (snes_ppu.bgd_offset.horizontal[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[0] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[1] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[1] & 0x3ff) >> 3 ); |
| 2155 | 1726 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2156 | | sprintf( t, "3) %3d %3d 4) %3d %3d", (snes_ppu.bgd_offset.horizontal[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[3] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[3] & 0x3ff) >> 3 ); |
| 1727 | logerror("3) %3d %3d 4) %3d %3d", (snes_ppu.bgd_offset.horizontal[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[2] & 0x3ff) >> 3, (snes_ppu.bgd_offset.horizontal[3] & 0x3ff) >> 3, (snes_ppu.bgd_offset.vertical[3] & 0x3ff) >> 3 ); |
| 2157 | 1728 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2158 | | sprintf( t, "Flags: %s%s%s %s %2d", (snes_ram[CGWSEL] & 0x2)?"S":"F", (snes_ram[CGADSUB] & 0x80)?"-":"+", (snes_ram[CGADSUB] & 0x40)?" 50%":"100%",(snes_ram[CGWSEL] & 0x1)?"D":"P", (snes_ram[MOSAIC] & 0xf0) >> 4 ); |
| 1729 | logerror("Flags: %s%s%s %s %2d", (snes_ram[CGWSEL] & 0x2)?"S":"F", (snes_ram[CGADSUB] & 0x80)?"-":"+", (snes_ram[CGADSUB] & 0x40)?" 50%":"100%",(snes_ram[CGWSEL] & 0x1)?"D":"P", (snes_ram[MOSAIC] & 0xf0) >> 4 ); |
| 2159 | 1730 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2160 | | sprintf( t, "SetINI: %s %s %s %s %s %s", (snes_ram[SETINI] & 0x1)?" I":"NI", (snes_ram[SETINI] & 0x2)?"P":"R", (snes_ram[SETINI] & 0x4)?"240":"225",(snes_ram[SETINI] & 0x8)?"512":"256",(snes_ram[SETINI] & 0x40)?"E":"N",(snes_ram[SETINI] & 0x80)?"ES":"NS" ); |
| 1731 | logerror("SetINI: %s %s %s %s %s %s", (snes_ram[SETINI] & 0x1)?" I":"NI", (snes_ram[SETINI] & 0x2)?"P":"R", (snes_ram[SETINI] & 0x4)?"240":"225",(snes_ram[SETINI] & 0x8)?"512":"256",(snes_ram[SETINI] & 0x40)?"E":"N",(snes_ram[SETINI] & 0x80)?"ES":"NS" ); |
| 2161 | 1732 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2162 | | sprintf( t, "Mode7: A %5d B %5d", snes_ppu.mode7.matrix_a, snes_ppu.mode7.matrix_b ); |
| 1733 | logerror("Mode7: A %5d B %5d", snes_ppu.mode7.matrix_a, snes_ppu.mode7.matrix_b ); |
| 2163 | 1734 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2164 | | sprintf( t, " %s%s%s C %5d D %5d", (snes_ram[M7SEL] & 0xc0)?((snes_ram[M7SEL] & 0x40)?"0":"C"):"R", (snes_ram[M7SEL] & 0x1)?"H":" ", (snes_ram[M7SEL] & 0x2)?"V":" ", snes_ppu.mode7.matrix_c, snes_ppu.mode7.matrix_d ); |
| 1735 | logerror(" %s%s%s C %5d D %5d", (snes_ram[M7SEL] & 0xc0)?((snes_ram[M7SEL] & 0x40)?"0":"C"):"R", (snes_ram[M7SEL] & 0x1)?"H":" ", (snes_ram[M7SEL] & 0x2)?"V":" ", snes_ppu.mode7.matrix_c, snes_ppu.mode7.matrix_d ); |
| 2165 | 1736 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2166 | | sprintf( t, " X %5d Y %5d", snes_ppu.mode7.origin_x, snes_ppu.mode7.origin_y ); |
| 1737 | logerror(" X %5d Y %5d", snes_ppu.mode7.origin_x, snes_ppu.mode7.origin_y ); |
| 2167 | 1738 | //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 ); |
| 2168 | 1739 | } |
| 2169 | 1740 | /* Just for testing, draw as many tiles as possible */ |
| r5355 | r5356 | |
| 2191 | 1762 | { |
| 2192 | 1763 | scanlines[MAINSCREEN].buffer[ii] = 0; |
| 2193 | 1764 | } |
| 2194 | | snes_dbg_draw_all_tiles(bitmap, addr, dt, pal * 16 ); |
| 1765 | snes_dbg_draw_all_tiles(machine, bitmap, addr, dt, pal * 16 ); |
| 2195 | 1766 | } |
| 2196 | 1767 | return 1; |
| 2197 | 1768 | } |
| r5355 | r5356 | |
| 2226 | 1797 | return 1; |
| 2227 | 1798 | } |
| 2228 | 1799 | } |
| 2229 | | |
| 1800 | #if 0 // 2009-08 FP: what was the purpose of these lines? |
| 2230 | 1801 | /* Draw some useful information about the back/fixed colours and current bg mode etc. */ |
| 2231 | 1802 | *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 26) = machine->pens[dbg_mode_colours[(snes_ram[CGWSEL] & 0xc0) >> 6]]; |
| 2232 | 1803 | *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 24) = machine->pens[dbg_mode_colours[(snes_ram[CGWSEL] & 0x30) >> 4]]; |
| r5355 | r5356 | |
| 2243 | 1814 | scanlines[MAINSCREEN].buffer[snes_ram[WH1]] = machine->pens[dbg_mode_colours[0]]; |
| 2244 | 1815 | scanlines[MAINSCREEN].buffer[snes_ram[WH2]] = machine->pens[dbg_mode_colours[2]]; |
| 2245 | 1816 | scanlines[MAINSCREEN].buffer[snes_ram[WH3]] = machine->pens[dbg_mode_colours[2]]; |
| 2246 | | |
| 1817 | #endif |
| 2247 | 1818 | return 0; |
| 2248 | 1819 | } |
| 2249 | 1820 | |
| 2250 | | #endif /* SNES_DBG_video */ |
| 1821 | #endif /* MAME_DEBUG */ |