src/mame/machine/snes.c
| r7648 | r7649 | |
| 411 | 411 | case WBGLOG: |
| 412 | 412 | return snes_ppu.ppu1_open_bus; |
| 413 | 413 | |
| 414 | | // According to BSNES, these should return snes_open_bus_r! |
| 415 | | // case OAMADDL: |
| 416 | | // case OAMADDH: |
| 417 | | // case VMADDH: |
| 418 | | // case CGADD: |
| 419 | | // case CGDATA: |
| 420 | | // return snes_ram[offset]; |
| 421 | 414 | case MPYL: /* Multiplication result (low) */ |
| 422 | 415 | { |
| 423 | 416 | /* Perform 16bit * 8bit multiply */ |
| 424 | | UINT32 c = snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8); |
| 417 | UINT32 c = (INT16)snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8); |
| 425 | 418 | snes_ppu.ppu1_open_bus = c & 0xff; |
| 426 | 419 | return snes_ppu.ppu1_open_bus; |
| 427 | 420 | } |
| 428 | 421 | case MPYM: /* Multiplication result (mid) */ |
| 429 | 422 | { |
| 430 | 423 | /* Perform 16bit * 8bit multiply */ |
| 431 | | UINT32 c = snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8); |
| 424 | UINT32 c = (INT16)snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8); |
| 432 | 425 | snes_ppu.ppu1_open_bus = (c >> 8) & 0xff; |
| 433 | 426 | return snes_ppu.ppu1_open_bus; |
| 434 | 427 | } |
| 435 | 428 | case MPYH: /* Multiplication result (high) */ |
| 436 | 429 | { |
| 437 | 430 | /* Perform 16bit * 8bit multiply */ |
| 438 | | UINT32 c = snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8); |
| 431 | UINT32 c = (INT16)snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8); |
| 439 | 432 | snes_ppu.ppu1_open_bus = (c >> 16) & 0xff; |
| 440 | 433 | return snes_ppu.ppu1_open_bus; |
| 441 | 434 | } |
| 442 | 435 | case SLHV: /* Software latch for H/V counter */ |
| 443 | 436 | snes_latch_counters(space->machine); |
| 444 | | return snes_open_bus_r(space,0); /* Return value is meaningless */ |
| 437 | return snes_open_bus_r(space, 0); /* Return value is meaningless */ |
| 445 | 438 | case ROAMDATA: /* Read data from OAM (DR) */ |
| 446 | 439 | { |
| 447 | 440 | int oam_addr = snes_ppu.oam.address; |
| r7648 | r7649 | |
| 489 | 482 | snes_ram[VMADDL] = addr & 0xff; |
| 490 | 483 | snes_ram[VMADDH] = (addr >> 8) & 0xff; |
| 491 | 484 | } |
| 485 | |
| 486 | return snes_ppu.ppu1_open_bus; |
| 492 | 487 | } |
| 493 | | return snes_ppu.ppu1_open_bus; |
| 494 | 488 | case RVMDATAH: /* Read data from VRAM (high) */ |
| 495 | 489 | { |
| 496 | 490 | UINT32 addr = (snes_ram[VMADDH] << 8) | snes_ram[VMADDL]; |
| r7648 | r7649 | |
| 515 | 509 | snes_ram[VMADDL] = addr & 0xff; |
| 516 | 510 | snes_ram[VMADDH] = (addr >> 8) & 0xff; |
| 517 | 511 | } |
| 512 | |
| 513 | return snes_ppu.ppu1_open_bus; |
| 518 | 514 | } |
| 519 | | return snes_ppu.ppu1_open_bus; |
| 520 | 515 | case RCGDATA: /* Read data from CGRAM */ |
| 521 | 516 | if (!(state->cgram_address & 0x01)) |
| 522 | 517 | { |
| r7648 | r7649 | |
| 570 | 565 | state->read_ophct = 0; |
| 571 | 566 | state->read_opvct = 0; |
| 572 | 567 | value = snes_ram[offset]; |
| 573 | | value |= (snes_ppu.ppu1_open_bus & 0x20); |
| 568 | value |= (snes_ppu.ppu2_open_bus & 0x20); |
| 574 | 569 | value |= (snes_ppu.ppu2_version & 0x0f); |
| 575 | 570 | snes_ram[offset] = value; // not sure if this is needed... |
| 576 | 571 | snes_ppu.ppu2_open_bus = value; |
| r7648 | r7649 | |
| 618 | 613 | case VTIMEH: |
| 619 | 614 | return snes_ram[offset]; |
| 620 | 615 | case RDNMI: /* NMI flag by v-blank and version number */ |
| 621 | | value = (snes_ram[offset] & 0x8f) | (snes_open_bus_r(space,0) & 0x70); |
| 616 | value = (snes_ram[offset] & 0x8f) | (snes_open_bus_r(space, 0) & 0x70); |
| 622 | 617 | snes_ram[offset] &= 0x7f; /* NMI flag is reset on read */ |
| 623 | 618 | return value; |
| 624 | 619 | case TIMEUP: /* IRQ flag by H/V count timer */ |
| 625 | | value = (snes_open_bus_r(space,0) & 0x7f) | (snes_ram[TIMEUP] & 0x80); |
| 620 | value = (snes_open_bus_r(space, 0) & 0x7f) | (snes_ram[TIMEUP] & 0x80); |
| 626 | 621 | cpu_set_input_line(state->maincpu, G65816_LINE_IRQ, CLEAR_LINE ); |
| 627 | 622 | snes_ram[TIMEUP] = 0; |
| 628 | 623 | return value; |
| r7648 | r7649 | |
| 630 | 625 | // electronics test says hcounter 272 is start of hblank, which is beampos 363 |
| 631 | 626 | // if (video_screen_get_hpos(space->machine->primary_screen) >= 363) snes_ram[offset] |= 0x40; |
| 632 | 627 | // else snes_ram[offset] &= ~0x40; |
| 633 | | return (snes_ram[offset] & 0xc1) | (snes_open_bus_r(space,0) & 0x3e); |
| 628 | return (snes_ram[offset] & 0xc1) | (snes_open_bus_r(space, 0) & 0x3e); |
| 634 | 629 | case RDIO: /* Programmable I/O port - echos back what's written to WRIO */ |
| 635 | 630 | return snes_ram[WRIO]; |
| 636 | 631 | case RDDIVL: /* Quotient of divide result (low) */ |
| r7648 | r7649 | |
| 654 | 649 | return state->joy4l; |
| 655 | 650 | case JOY4H: /* Joypad 4 status register (high) */ |
| 656 | 651 | return state->joy4h; |
| 657 | | case DMAP0: |
| 658 | | case DMAP1: |
| 659 | | case DMAP2: |
| 660 | | case DMAP3: |
| 661 | | case DMAP4: |
| 662 | | case DMAP5: |
| 663 | | case DMAP6: |
| 664 | | case DMAP7: |
| 665 | | // return (snes_ram[offset] & 0xdf) | (snes_open_bus_r(space,0) & 0x20); |
| 666 | | case BBAD0: case A1T0L: case A1T0H: case A1B0: case DAS0L: |
| 667 | | case DAS0H: case DSAB0: case A2A0L: case A2A0H: case NTRL0: |
| 668 | | case BBAD1: case A1T1L: case A1T1H: case A1B1: case DAS1L: |
| 669 | | case DAS1H: case DSAB1: case A2A1L: case A2A1H: case NTRL1: |
| 670 | | case BBAD2: case A1T2L: case A1T2H: case A1B2: case DAS2L: |
| 671 | | case DAS2H: case DSAB2: case A2A2L: case A2A2H: case NTRL2: |
| 672 | | case BBAD3: case A1T3L: case A1T3H: case A1B3: case DAS3L: |
| 673 | | case DAS3H: case DSAB3: case A2A3L: case A2A3H: case NTRL3: |
| 674 | | case BBAD4: case A1T4L: case A1T4H: case A1B4: case DAS4L: |
| 675 | | case DAS4H: case DSAB4: case A2A4L: case A2A4H: case NTRL4: |
| 676 | | case BBAD5: case A1T5L: case A1T5H: case A1B5: case DAS5L: |
| 677 | | case DAS5H: case DSAB5: case A2A5L: case A2A5H: case NTRL5: |
| 678 | | case BBAD6: case A1T6L: case A1T6H: case A1B6: case DAS6L: |
| 679 | | case DAS6H: case DSAB6: case A2A6L: case A2A6H: case NTRL6: |
| 680 | | case BBAD7: case A1T7L: case A1T7H: case A1B7: case DAS7L: |
| 681 | | case DAS7H: case DSAB7: case A2A7L: case A2A7H: case NTRL7: |
| 652 | case DMAP0: case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/ |
| 653 | case DMAP4: case DMAP5: case DMAP6: case DMAP7: |
| 654 | case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/ |
| 655 | case BBAD4: case BBAD5: case BBAD6: case BBAD7: |
| 656 | case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/ |
| 657 | case A1T4L: case A1T5L: case A1T6L: case A1T7L: |
| 658 | case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/ |
| 659 | case A1T4H: case A1T5H: case A1T6H: case A1T7H: |
| 660 | case A1B0: case A1B1: case A1B2: case A1B3: /*0x43n4*/ |
| 661 | case A1B4: case A1B5: case A1B6: case A1B7: |
| 662 | case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/ |
| 663 | case DAS4L: case DAS5L: case DAS6L: case DAS7L: |
| 664 | case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/ |
| 665 | case DAS4H: case DAS5H: case DAS6H: case DAS7H: |
| 666 | case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/ |
| 667 | case DSAB4: case DSAB5: case DSAB6: case DSAB7: |
| 668 | case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/ |
| 669 | case A2A4L: case A2A5L: case A2A6L: case A2A7L: |
| 670 | case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/ |
| 671 | case A2A4H: case A2A5H: case A2A6H: case A2A7H: |
| 672 | case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/ |
| 673 | case NTRL4: case NTRL5: case NTRL6: case NTRL7: |
| 674 | case 0x430b: case 0x431b: case 0x432b: case 0x433b: /* according to bsnes, this does not return open_bus (even if its precise effect is unknown) */ |
| 675 | case 0x434b: case 0x435b: case 0x436b: case 0x437b: |
| 682 | 676 | return snes_ram[offset]; |
| 683 | 677 | |
| 684 | 678 | #ifndef MESS |
| r7648 | r7649 | |
| 696 | 690 | //printf("unsupported read: offset == %08x\n", offset); |
| 697 | 691 | |
| 698 | 692 | /* Unsupported reads returns open bus */ |
| 699 | | // printf("%02x %02x\n",offset,snes_open_bus_r(space,0)); |
| 693 | // printf("%02x %02x\n",offset,snes_open_bus_r(space, 0)); |
| 700 | 694 | return snes_open_bus_r(space, 0); |
| 701 | 695 | } |
| 702 | 696 | |
| r7648 | r7649 | |
| 840 | 834 | snes_ppu.update_offsets = 1; |
| 841 | 835 | break; |
| 842 | 836 | case MOSAIC: /* Size and screen designation for mosaic */ |
| 843 | | /* FIXME: We support horizontal mosaic only partially */ |
| 844 | 837 | snes_ppu.mosaic_size = (data & 0xf0) >> 4; |
| 845 | 838 | snes_ppu.layer[SNES_BG1].mosaic_enabled = BIT(data, 0); |
| 846 | 839 | snes_ppu.layer[SNES_BG2].mosaic_enabled = BIT(data, 1); |
| r7648 | r7649 | |
| 1299 | 1292 | case TIMEUP: |
| 1300 | 1293 | snes_ram[TIMEUP] = data &~0x7f; |
| 1301 | 1294 | return; |
| 1302 | | /* Following are read-only */ |
| 1295 | /* Following are read-only */ |
| 1303 | 1296 | case HVBJOY: /* H/V blank and joypad enable */ |
| 1304 | 1297 | case MPYL: /* Multiplication result (low) */ |
| 1305 | 1298 | case MPYM: /* Multiplication result (mid) */ |
| r7648 | r7649 | |
| 1321 | 1314 | logerror( "Write to read-only register: %X value: %X", offset, data ); |
| 1322 | 1315 | #endif /* MAME_DEBUG */ |
| 1323 | 1316 | return; |
| 1324 | | /* Below is all DMA related */ |
| 1325 | | case DMAP0: case BBAD0: case A1T0L: case A1T0H: case A1B0: case DAS0L: |
| 1326 | | case DAS0H: case DSAB0: case A2A0L: case A2A0H: case NTRL0: |
| 1327 | | case DMAP1: case BBAD1: case A1T1L: case A1T1H: case A1B1: case DAS1L: |
| 1328 | | case DAS1H: case DSAB1: case A2A1L: case A2A1H: case NTRL1: |
| 1329 | | case DMAP2: case BBAD2: case A1T2L: case A1T2H: case A1B2: case DAS2L: |
| 1330 | | case DAS2H: case DSAB2: case A2A2L: case A2A2H: case NTRL2: |
| 1331 | | case DMAP3: case BBAD3: case A1T3L: case A1T3H: case A1B3: case DAS3L: |
| 1332 | | case DAS3H: case DSAB3: case A2A3L: case A2A3H: case NTRL3: |
| 1333 | | case DMAP4: case BBAD4: case A1T4L: case A1T4H: case A1B4: case DAS4L: |
| 1334 | | case DAS4H: case DSAB4: case A2A4L: case A2A4H: case NTRL4: |
| 1335 | | case DMAP5: case BBAD5: case A1T5L: case A1T5H: case A1B5: case DAS5L: |
| 1336 | | case DAS5H: case DSAB5: case A2A5L: case A2A5H: case NTRL5: |
| 1337 | | case DMAP6: case BBAD6: case A1T6L: case A1T6H: case A1B6: case DAS6L: |
| 1338 | | case DAS6H: case DSAB6: case A2A6L: case A2A6H: case NTRL6: |
| 1339 | | case DMAP7: case BBAD7: case A1T7L: case A1T7H: case A1B7: case DAS7L: |
| 1340 | | case DAS7H: case DSAB7: case A2A7L: case A2A7H: case NTRL7: |
| 1317 | /* Below is all DMA related */ |
| 1318 | case DMAP0: case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/ |
| 1319 | case DMAP4: case DMAP5: case DMAP6: case DMAP7: |
| 1320 | case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/ |
| 1321 | case BBAD4: case BBAD5: case BBAD6: case BBAD7: |
| 1322 | case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/ |
| 1323 | case A1T4L: case A1T5L: case A1T6L: case A1T7L: |
| 1324 | case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/ |
| 1325 | case A1T4H: case A1T5H: case A1T6H: case A1T7H: |
| 1326 | case A1B0: case A1B1: case A1B2: case A1B3: /*0x43n4*/ |
| 1327 | case A1B4: case A1B5: case A1B6: case A1B7: |
| 1328 | case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/ |
| 1329 | case DAS4L: case DAS5L: case DAS6L: case DAS7L: |
| 1330 | case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/ |
| 1331 | case DAS4H: case DAS5H: case DAS6H: case DAS7H: |
| 1332 | case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/ |
| 1333 | case DSAB4: case DSAB5: case DSAB6: case DSAB7: |
| 1334 | case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/ |
| 1335 | case A2A4L: case A2A5L: case A2A6L: case A2A7L: |
| 1336 | case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/ |
| 1337 | case A2A4H: case A2A5H: case A2A6H: case A2A7H: |
| 1338 | case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/ |
| 1339 | case NTRL4: case NTRL5: case NTRL6: case NTRL7: |
| 1340 | case 0x430b: case 0x431b: case 0x432b: case 0x433b: |
| 1341 | case 0x434b: case 0x435b: case 0x436b: case 0x437b: |
| 1341 | 1342 | break; |
| 1342 | 1343 | } |
| 1343 | 1344 | |
src/mame/video/snes.c
| r7648 | r7649 | |
| 84 | 84 | #ifdef SNES_LAYER_DEBUG |
| 85 | 85 | struct DEBUGOPTS |
| 86 | 86 | { |
| 87 | | UINT8 input_count; |
| 88 | 87 | UINT8 bg_disabled[5]; |
| 89 | 88 | UINT8 mode_disabled[8]; |
| 90 | 89 | UINT8 draw_subscreen; |
| r7648 | r7649 | |
| 97 | 96 | static struct DEBUGOPTS debug_options; |
| 98 | 97 | /* red green blue purple yellow cyan grey white */ |
| 99 | 98 | static const UINT16 dbg_mode_colours[8] = { 0x1f, 0x3e0, 0x7c00, 0x7c1f, 0x3ff, 0x7fe0, 0x4210, 0x7fff }; |
| 100 | | static UINT8 snes_dbg_video(running_machine *machine, bitmap_t *bitmap, UINT16 curline); |
| 99 | static UINT8 snes_dbg_video(running_machine *machine, UINT16 curline); |
| 101 | 100 | #endif /* SNES_LAYER_DEBUG */ |
| 102 | 101 | |
| 103 | 102 | static const UINT16 table_obj_offset[8][8] = |
| r7648 | r7649 | |
| 132 | 131 | SNES_COLOR_DEPTH_8BPP |
| 133 | 132 | }; |
| 134 | 133 | |
| 135 | | /********************************************************************************** |
| 136 | | * TODO: the draw_tile routines below should be merged/reworked to reduce everything |
| 137 | | * to a single routine with the additional parameters: OAM/BG (to decide if checking |
| 138 | | * against priority or not) and tile length (16 for hires BG, 8 otherwise) |
| 139 | | **********************************************************************************/ |
| 140 | | |
| 141 | 134 | /***************************************** |
| 142 | | * snes_draw_tile() |
| 135 | * snes_get_bgcolor() |
| 143 | 136 | * |
| 144 | | * Draw BG tiles with variable bit planes |
| 137 | * Get the proper color (direct or from cgram) |
| 145 | 138 | *****************************************/ |
| 146 | 139 | |
| 147 | | INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ) |
| 140 | INLINE UINT16 snes_get_bgcolor( UINT8 direct_colors, UINT16 palette, UINT8 color ) |
| 148 | 141 | { |
| 149 | | UINT8 mask, plane[8]; |
| 150 | | UINT16 c; |
| 151 | | INT16 ii, jj; |
| 142 | UINT16 c = 0; |
| 152 | 143 | |
| 153 | | for (ii = 0; ii < planes / 2; ii++) |
| 144 | if (direct_colors) |
| 154 | 145 | { |
| 155 | | plane[2 * ii] = snes_vram[tileaddr + 16 * ii]; |
| 156 | | plane[2 * ii + 1] = snes_vram[tileaddr + 16 * ii + 1]; |
| 146 | /* format is 0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */ |
| 147 | c = ((color & 0x07) << 2) | ((color & 0x38) << 4) | ((color & 0xc0) << 7); |
| 148 | c |= ((palette & 0x04) >> 1) | ((palette & 0x08) << 3) | ((palette & 0x10) << 8); |
| 157 | 149 | } |
| 158 | | |
| 159 | | if (flip) |
| 160 | | mask = 0x1; |
| 161 | 150 | else |
| 162 | | mask = 0x80; |
| 151 | c = snes_cgram[(palette + color) % FIXED_COLOUR]; |
| 163 | 152 | |
| 164 | | for (ii = x; ii < (x + 8); ii++) |
| 165 | | { |
| 166 | | UINT8 colour = 0; |
| 167 | | if (flip) |
| 168 | | { |
| 169 | | for (jj = 0; jj < planes; jj++) |
| 170 | | colour |= plane[jj] & mask ? (1 << jj) : 0; |
| 153 | return c; |
| 154 | } |
| 171 | 155 | |
| 172 | | mask <<= 1; |
| 173 | | } |
| 174 | | else |
| 175 | | { |
| 176 | | for (jj = 0; jj < planes; jj++) |
| 177 | | colour |= plane[jj] & mask ? (1 << jj) : 0; |
| 156 | /***************************************** |
| 157 | * snes_set_scanline_pixel() |
| 158 | * |
| 159 | * Store pixel color, priority, layer and |
| 160 | * color math exception (for OAM) in the |
| 161 | * proper scanline |
| 162 | *****************************************/ |
| 178 | 163 | |
| 179 | | mask >>= 1; |
| 180 | | } |
| 164 | INLINE void snes_set_scanline_pixel( int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend ) |
| 165 | { |
| 166 | scanlines[screen].buffer[x] = color; |
| 167 | scanlines[screen].priority[x] = priority; |
| 168 | scanlines[screen].layer[x] = layer; |
| 169 | scanlines[screen].blend_exception[x] = blend; |
| 170 | } |
| 181 | 171 | |
| 172 | /************************************************************************************************* |
| 173 | * SNES tiles |
| 174 | * |
| 175 | * The way vram is accessed to draw tiles is basically the same for both BG and OAM tiles. Main |
| 176 | * differences are bit planes (variable for BG and fixed for OAM) and a few details of the scanline |
| 177 | * output (since OAM has neither mosaic, nor hires, nor direct colors). |
| 178 | * Hence, we use a common function to take data from VRAM and then we call specific routines for |
| 179 | * OAM vs BG vs Hi-Res BG tiles. |
| 180 | *************************************************************************************************/ |
| 182 | 181 | |
| 183 | | if (!hires) |
| 184 | | { |
| 185 | | if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && scanlines[SNES_MAINSCREEN].enable) |
| 186 | | { |
| 187 | | if (scanlines[SNES_MAINSCREEN].priority[ii] <= priority) |
| 188 | | { |
| 189 | | UINT8 clr = colour; |
| 190 | | UINT8 clipmask = snes_ppu.clipmasks[layer][ii]; |
| 191 | | UINT8 mosaic = snes_ppu.layer[SNES_MAINSCREEN].mosaic_enabled; |
| 182 | /***************************************** |
| 183 | * snes_draw_bgtile_lores() |
| 184 | * snes_draw_bgtile_hires() |
| 185 | * snes_draw_oamtile_() |
| 186 | * |
| 187 | * Check if a pixel is clipped or not, and |
| 188 | * copy it to the scanline buffer when |
| 189 | * appropriate. The actual way to perform |
| 190 | * such operations depends on the source |
| 191 | * (BG or OAM) and on the resolution (hires |
| 192 | * or lores) |
| 193 | *****************************************/ |
| 192 | 194 | |
| 193 | | #ifdef SNES_LAYER_DEBUG |
| 194 | | if (debug_options.windows_disabled) |
| 195 | | clipmask = 0xff; |
| 196 | | if (debug_options.mosaic_disabled) |
| 197 | | mosaic = 0; |
| 198 | | #endif /* SNES_LAYER_DEBUG */ |
| 195 | INLINE void snes_draw_bgtile_lores( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ) |
| 196 | { |
| 197 | int screen; |
| 198 | UINT16 c; |
| 199 | 199 | |
| 200 | | /* Clip to windows */ |
| 201 | | if (scanlines[SNES_MAINSCREEN].clip) |
| 202 | | clr &= clipmask; |
| 203 | | |
| 204 | | /* Only draw if we have a colour (0 == transparent) */ |
| 205 | | if (clr) |
| 206 | | { |
| 207 | | if (direct_colors) |
| 208 | | { |
| 209 | | /* format is 0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */ |
| 210 | | c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7); |
| 211 | | c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8); |
| 212 | | } |
| 213 | | else |
| 214 | | c = snes_cgram[(pal + clr) % FIXED_COLOUR]; |
| 215 | | |
| 216 | | if (mosaic) // handle horizontal mosaic |
| 217 | | { |
| 218 | | int x_mos; |
| 219 | | |
| 220 | | //TODO: 512 modes has the h values doubled. |
| 221 | | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++) |
| 222 | | { |
| 223 | | scanlines[SNES_MAINSCREEN].buffer[ii + x_mos] = c; |
| 224 | | scanlines[SNES_MAINSCREEN].priority[ii + x_mos] = priority; |
| 225 | | scanlines[SNES_MAINSCREEN].layer[ii + x_mos] = layer; |
| 226 | | scanlines[SNES_MAINSCREEN].blend_exception[ii + x_mos] = 0; |
| 227 | | } |
| 228 | | |
| 229 | | ii += x_mos - 1; |
| 230 | | } |
| 231 | | else |
| 232 | | { |
| 233 | | scanlines[SNES_MAINSCREEN].buffer[ii] = c; |
| 234 | | scanlines[SNES_MAINSCREEN].priority[ii] = priority; |
| 235 | | scanlines[SNES_MAINSCREEN].layer[ii] = layer; |
| 236 | | scanlines[SNES_MAINSCREEN].blend_exception[ii] = 0; |
| 237 | | } |
| 238 | | } |
| 239 | | } |
| 240 | | } |
| 241 | | |
| 242 | | if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && scanlines[SNES_SUBSCREEN].enable) |
| 200 | for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++) |
| 201 | { |
| 202 | if (ii >= 0 && ii < SNES_SCR_WIDTH && scanlines[screen].enable) |
| 203 | { |
| 204 | if (scanlines[screen].priority[ii] <= priority) |
| 243 | 205 | { |
| 244 | | if (scanlines[SNES_SUBSCREEN].priority[ii] <= priority) |
| 245 | | { |
| 246 | | UINT8 clr = colour; |
| 247 | | UINT8 clipmask = snes_ppu.clipmasks[layer][ii]; |
| 248 | | UINT8 mosaic = snes_ppu.layer[SNES_SUBSCREEN].mosaic_enabled; |
| 206 | UINT8 clr = colour; |
| 207 | UINT8 clipmask = snes_ppu.clipmasks[layer][ii]; |
| 249 | 208 | |
| 250 | 209 | #ifdef SNES_LAYER_DEBUG |
| 251 | | if (debug_options.windows_disabled) |
| 252 | | clipmask = 0xff; |
| 253 | | if (debug_options.mosaic_disabled) |
| 254 | | mosaic = 0; |
| 210 | if (debug_options.windows_disabled) |
| 211 | clipmask = 0xff; |
| 255 | 212 | #endif /* SNES_LAYER_DEBUG */ |
| 256 | 213 | |
| 257 | | /* Clip to windows */ |
| 258 | | if (scanlines[SNES_SUBSCREEN].clip) |
| 259 | | clr &= clipmask; |
| 214 | /* Clip to windows */ |
| 215 | if (scanlines[screen].clip) |
| 216 | clr &= clipmask; |
| 260 | 217 | |
| 261 | | /* Only draw if we have a colour (0 == transparent) */ |
| 262 | | if (clr) |
| 263 | | { |
| 264 | | if (direct_colors) |
| 265 | | { |
| 266 | | /* format is 0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */ |
| 267 | | c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7); |
| 268 | | c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8); |
| 269 | | } |
| 270 | | else |
| 271 | | c = snes_cgram[(pal + clr) % FIXED_COLOUR]; |
| 272 | | |
| 273 | | if (mosaic) // handle horizontal mosaic |
| 274 | | { |
| 275 | | int x_mos; |
| 276 | | |
| 277 | | //TODO: 512 modes has the h values doubled. |
| 278 | | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++) |
| 279 | | { |
| 280 | | scanlines[SNES_SUBSCREEN].buffer[ii + x_mos] = c; |
| 281 | | scanlines[SNES_SUBSCREEN].priority[ii + x_mos] = priority; |
| 282 | | scanlines[SNES_SUBSCREEN].layer[ii + x_mos] = layer; |
| 283 | | scanlines[SNES_SUBSCREEN].blend_exception[ii + x_mos] = 0; |
| 284 | | } |
| 285 | | |
| 286 | | ii += x_mos - 1; |
| 287 | | } |
| 288 | | else |
| 289 | | { |
| 290 | | scanlines[SNES_SUBSCREEN].buffer[ii] = c; |
| 291 | | scanlines[SNES_SUBSCREEN].priority[ii] = priority; |
| 292 | | scanlines[SNES_SUBSCREEN].layer[ii] = layer; |
| 293 | | scanlines[SNES_SUBSCREEN].blend_exception[ii] = 0; |
| 294 | | } |
| 295 | | } |
| 218 | /* Only draw if we have a colour (0 == transparent) */ |
| 219 | if (clr) |
| 220 | { |
| 221 | c = snes_get_bgcolor(direct_colors, pal, clr); |
| 222 | snes_set_scanline_pixel(screen, ii, c, priority, layer, 0); |
| 296 | 223 | } |
| 297 | 224 | } |
| 298 | 225 | } |
| 299 | | else /* hires */ |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | INLINE void snes_draw_bgtile_hires( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ) |
| 230 | { |
| 231 | int screen; |
| 232 | UINT16 c; |
| 233 | |
| 234 | for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++) |
| 235 | { |
| 236 | // odd pixels to main screen, even pixels to sub screen |
| 237 | if (ii >= 0 && ii < (SNES_SCR_WIDTH << 1) && ((ii & 1) ^ screen) && scanlines[screen].enable) |
| 300 | 238 | { |
| 301 | | if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && (ii & 1) && scanlines[SNES_MAINSCREEN].enable) |
| 239 | if (scanlines[screen].priority[ii >> 1] <= priority) |
| 302 | 240 | { |
| 303 | | if (scanlines[SNES_MAINSCREEN].priority[ii >> 1] <= priority) |
| 304 | | { |
| 305 | | UINT8 clr = colour; |
| 306 | | UINT8 clipmask = snes_ppu.clipmasks[layer][ii]; |
| 307 | | UINT8 mosaic = snes_ppu.layer[SNES_MAINSCREEN].mosaic_enabled; |
| 241 | UINT8 clr = colour; |
| 242 | UINT8 clipmask = snes_ppu.clipmasks[layer][ii]; |
| 308 | 243 | |
| 309 | 244 | #ifdef SNES_LAYER_DEBUG |
| 310 | | if (debug_options.windows_disabled) |
| 311 | | clipmask = 0xff; |
| 312 | | if (debug_options.mosaic_disabled) |
| 313 | | mosaic = 0; |
| 245 | if (debug_options.windows_disabled) |
| 246 | clipmask = 0xff; |
| 314 | 247 | #endif /* SNES_LAYER_DEBUG */ |
| 315 | 248 | |
| 316 | | /* Clip to windows */ |
| 317 | | if (scanlines[SNES_MAINSCREEN].clip) |
| 318 | | clr &= clipmask; |
| 249 | /* Clip to windows */ |
| 250 | if (scanlines[screen].clip) |
| 251 | clr &= clipmask; |
| 319 | 252 | |
| 320 | | /* Only draw if we have a colour (0 == transparent) */ |
| 321 | | if (clr) |
| 322 | | { |
| 323 | | if (direct_colors) |
| 324 | | { |
| 325 | | /* format is 0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */ |
| 326 | | c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7); |
| 327 | | c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8); |
| 328 | | } |
| 329 | | else |
| 330 | | c = snes_cgram[(pal + clr) % FIXED_COLOUR]; |
| 331 | | |
| 332 | | if (mosaic) // handle horizontal mosaic |
| 333 | | { |
| 334 | | int x_mos; |
| 335 | | |
| 336 | | //TODO: 512 modes has the h values doubled. |
| 337 | | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++) |
| 338 | | { |
| 339 | | scanlines[SNES_MAINSCREEN].buffer[(ii + x_mos) >> 1] = c; |
| 340 | | scanlines[SNES_MAINSCREEN].priority[(ii + x_mos) >> 1] = priority; |
| 341 | | scanlines[SNES_MAINSCREEN].layer[(ii + x_mos) >> 1] = layer; |
| 342 | | scanlines[SNES_MAINSCREEN].blend_exception[(ii + x_mos) >> 1] = 0; |
| 343 | | } |
| 344 | | ii += x_mos - 1; |
| 345 | | } |
| 346 | | else |
| 347 | | { |
| 348 | | scanlines[SNES_MAINSCREEN].buffer[ii >> 1] = c; |
| 349 | | scanlines[SNES_MAINSCREEN].priority[ii >> 1] = priority; |
| 350 | | scanlines[SNES_MAINSCREEN].layer[ii >> 1] = layer; |
| 351 | | scanlines[SNES_MAINSCREEN].blend_exception[ii >> 1] = 0; |
| 352 | | } |
| 353 | | } |
| 253 | /* Only draw if we have a colour (0 == transparent) */ |
| 254 | if (clr) |
| 255 | { |
| 256 | c = snes_get_bgcolor(direct_colors, pal, clr); |
| 257 | snes_set_scanline_pixel(screen, ii >> 1, c, priority, layer, 0); |
| 354 | 258 | } |
| 355 | 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 356 | 263 | |
| 357 | | if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && !(ii & 1) && scanlines[SNES_SUBSCREEN].enable) |
| 358 | | { |
| 359 | | if (scanlines[SNES_SUBSCREEN].priority[ii >> 1] <= priority) |
| 360 | | { |
| 361 | | UINT8 clr = colour; |
| 362 | | UINT8 clipmask = snes_ppu.clipmasks[layer][ii]; |
| 363 | | UINT8 mosaic = snes_ppu.layer[SNES_SUBSCREEN].mosaic_enabled; |
| 264 | INLINE void snes_draw_oamtile( INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority ) |
| 265 | { |
| 266 | int screen; |
| 267 | int blend; |
| 268 | UINT16 c; |
| 269 | INT16 pos = ii & 0x1ff; |
| 364 | 270 | |
| 271 | for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++) |
| 272 | { |
| 273 | if (pos >= 0 && pos < SNES_SCR_WIDTH && scanlines[screen].enable) |
| 274 | { |
| 275 | UINT8 clr = colour; |
| 276 | UINT8 clipmask = snes_ppu.clipmasks[SNES_OAM][pos]; |
| 277 | |
| 365 | 278 | #ifdef SNES_LAYER_DEBUG |
| 366 | | if (debug_options.windows_disabled) |
| 367 | | clipmask = 0xff; |
| 368 | | if (debug_options.mosaic_disabled) |
| 369 | | mosaic = 0; |
| 279 | if (debug_options.windows_disabled) |
| 280 | clipmask = 0xff; |
| 370 | 281 | #endif /* SNES_LAYER_DEBUG */ |
| 371 | 282 | |
| 372 | | /* Clip to windows */ |
| 373 | | if (scanlines[SNES_SUBSCREEN].clip) |
| 374 | | clr &= clipmask; |
| 283 | /* Clip to windows */ |
| 284 | if (scanlines[screen].clip) |
| 285 | clr &= clipmask; |
| 375 | 286 | |
| 376 | | /* Only draw if we have a colour (0 == transparent) */ |
| 377 | | if (clr) |
| 378 | | { |
| 379 | | if (direct_colors) |
| 380 | | { |
| 381 | | /* format is 0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */ |
| 382 | | c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7); |
| 383 | | c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8); |
| 384 | | } |
| 385 | | else |
| 386 | | c = snes_cgram[(pal + clr) % FIXED_COLOUR]; |
| 387 | | |
| 388 | | if (mosaic) // handle horizontal mosaic |
| 389 | | { |
| 390 | | int x_mos; |
| 391 | | |
| 392 | | //TODO: 512 modes has the h values doubled. |
| 393 | | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++) |
| 394 | | { |
| 395 | | scanlines[SNES_SUBSCREEN].buffer[(ii + x_mos) >> 1] = c; |
| 396 | | scanlines[SNES_SUBSCREEN].priority[(ii + x_mos) >> 1] = priority; |
| 397 | | scanlines[SNES_SUBSCREEN].layer[(ii + x_mos) >> 1] = layer; |
| 398 | | scanlines[SNES_SUBSCREEN].blend_exception[(ii + x_mos) >> 1] = 0; |
| 399 | | } |
| 400 | | ii += x_mos - 1; |
| 401 | | } |
| 402 | | else |
| 403 | | { |
| 404 | | scanlines[SNES_SUBSCREEN].buffer[ii >> 1] = c; |
| 405 | | scanlines[SNES_SUBSCREEN].priority[ii >> 1] = priority; |
| 406 | | scanlines[SNES_SUBSCREEN].layer[ii >> 1] = layer; |
| 407 | | scanlines[SNES_SUBSCREEN].blend_exception[ii >> 1] = 0; |
| 408 | | } |
| 409 | | } |
| 410 | | } |
| 287 | /* Only draw if we have a colour (0 == transparent) */ |
| 288 | if (clr) |
| 289 | { |
| 290 | c = snes_cgram[(pal + clr) % FIXED_COLOUR]; |
| 291 | blend = (pal + clr < 192) ? 1 : 0; |
| 292 | snes_set_scanline_pixel(screen, pos, c, priority, SNES_OAM, blend); |
| 411 | 293 | } |
| 412 | 294 | } |
| 413 | 295 | } |
| 414 | 296 | } |
| 415 | 297 | |
| 416 | 298 | /***************************************** |
| 417 | | * snes_draw_tile_x2() |
| 299 | * snes_draw_tile() |
| 418 | 300 | * |
| 419 | | * Draw 2 tiles with variable bit planes |
| 301 | * Get pixel color with variable bit planes |
| 302 | * from snes_vram and draw the tiles by |
| 303 | * calling the appropriate routine |
| 420 | 304 | *****************************************/ |
| 421 | 305 | |
| 422 | | INLINE void snes_draw_tile_x2( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ) |
| 306 | INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, int tile_size, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ) |
| 423 | 307 | { |
| 424 | | if (flip) |
| 425 | | { |
| 426 | | snes_draw_tile(planes, layer, tileaddr + (8 * planes), x, priority, flip, direct_colors, pal, hires); |
| 427 | | snes_draw_tile(planes, layer, tileaddr, x + 8, priority, flip, direct_colors, pal, hires); |
| 428 | | } |
| 429 | | else |
| 430 | | { |
| 431 | | snes_draw_tile(planes, layer, tileaddr, x, priority, flip, direct_colors, pal, hires); |
| 432 | | snes_draw_tile(planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, direct_colors, pal, hires); |
| 433 | | } |
| 434 | | } |
| 308 | UINT8 plane[8]; |
| 309 | INT16 ii, jj, start_pixel; |
| 310 | int tile, x_mos; |
| 435 | 311 | |
| 436 | | /***************************************** |
| 437 | | * snes_draw_tile_object() |
| 438 | | * |
| 439 | | * Draw OAM tiles with 4 bit planes(16 colors) |
| 440 | | *****************************************/ |
| 312 | start_pixel = x; |
| 441 | 313 | |
| 442 | | INLINE void snes_draw_tile_object( UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal ) |
| 443 | | { |
| 444 | | UINT8 mask, plane[4]; |
| 445 | | UINT16 c; |
| 446 | | int blend; |
| 447 | | INT16 ii, jj; |
| 448 | | |
| 449 | | plane[0] = snes_vram[tileaddr]; |
| 450 | | plane[1] = snes_vram[tileaddr + 1]; |
| 451 | | plane[2] = snes_vram[tileaddr + 16]; |
| 452 | | plane[3] = snes_vram[tileaddr + 17]; |
| 453 | | |
| 454 | | if (flip) |
| 455 | | mask = 0x01; |
| 456 | | else |
| 457 | | mask = 0x80; |
| 458 | | |
| 459 | | for (ii = x; ii < (x + 8); ii++) |
| 314 | /* if 8x8 tile we draw once; if 16x16 we draw twice */ |
| 315 | for (tile = 0; tile < (1 << tile_size); tile++) |
| 460 | 316 | { |
| 461 | | UINT8 colour = 0; |
| 462 | | if (flip) |
| 317 | for (ii = 0; ii < planes / 2; ii++) |
| 463 | 318 | { |
| 464 | | for (jj = 0; jj < 4; jj++) |
| 465 | | colour |= plane[jj] & mask ? (1 << jj) : 0; |
| 466 | | |
| 467 | | mask <<= 1; |
| 319 | plane[2 * ii] = snes_vram[tileaddr + 16 * ii]; |
| 320 | plane[2 * ii + 1] = snes_vram[tileaddr + 16 * ii + 1]; |
| 468 | 321 | } |
| 469 | | else |
| 470 | | { |
| 471 | | for (jj = 0; jj < 4; jj++) |
| 472 | | colour |= plane[jj] & mask ? (1 << jj) : 0; |
| 473 | 322 | |
| 474 | | mask >>= 1; |
| 475 | | } |
| 476 | | |
| 477 | | INT16 pos = ii & 0x1ff; |
| 478 | | |
| 479 | | if (pos >= 0 && pos < SNES_SCR_WIDTH && scanlines[SNES_MAINSCREEN].enable) |
| 323 | for (ii = x; ii < (x + 8); ii++) |
| 480 | 324 | { |
| 481 | | { |
| 482 | | UINT8 clr = colour; |
| 483 | | UINT8 clipmask = snes_ppu.clipmasks[SNES_OAM][pos]; |
| 325 | UINT8 colour = 0; |
| 326 | UINT8 mosaic = snes_ppu.layer[layer].mosaic_enabled; |
| 484 | 327 | |
| 485 | 328 | #ifdef SNES_LAYER_DEBUG |
| 486 | | if (debug_options.windows_disabled) |
| 487 | | clipmask = 0xff; |
| 329 | if (debug_options.mosaic_disabled) |
| 330 | mosaic = 0; |
| 488 | 331 | #endif /* SNES_LAYER_DEBUG */ |
| 489 | 332 | |
| 490 | | /* Clip to windows */ |
| 491 | | if (scanlines[SNES_MAINSCREEN].clip) |
| 492 | | clr &= clipmask; |
| 333 | if (flip) |
| 334 | { |
| 335 | for (jj = 0; jj < planes; jj++) |
| 336 | colour |= BIT(plane[jj], ii - x) ? (1 << jj) : 0; |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | for (jj = 0; jj < planes; jj++) |
| 341 | colour |= BIT(plane[jj], 7 - (ii - x)) ? (1 << jj) : 0; |
| 342 | } |
| 493 | 343 | |
| 494 | | /* Only draw if we have a colour (0 == transparent) */ |
| 495 | | if (clr) |
| 344 | if (layer == SNES_OAM) |
| 345 | snes_draw_oamtile(ii, colour, pal, priority); |
| 346 | else if (!hires) |
| 347 | { |
| 348 | if (mosaic) |
| 496 | 349 | { |
| 497 | | c = snes_cgram[(pal + clr) % FIXED_COLOUR]; |
| 498 | | blend = (pal + clr < 192) ? 1 : 0; |
| 499 | | |
| 500 | | scanlines[SNES_MAINSCREEN].buffer[pos] = c; |
| 501 | | scanlines[SNES_MAINSCREEN].priority[pos] = priority; |
| 502 | | scanlines[SNES_MAINSCREEN].layer[pos] = SNES_OAM; |
| 503 | | scanlines[SNES_MAINSCREEN].blend_exception[pos] = blend; |
| 350 | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++) |
| 351 | snes_draw_bgtile_lores(layer, ii + x_mos, colour, pal, direct_colors, priority); |
| 352 | ii += x_mos - 1; |
| 504 | 353 | } |
| 354 | else |
| 355 | snes_draw_bgtile_lores(layer, ii, colour, pal, direct_colors, priority); |
| 505 | 356 | } |
| 506 | | } |
| 507 | | |
| 508 | | if (pos >= 0 && pos < SNES_SCR_WIDTH && scanlines[SNES_SUBSCREEN].enable) |
| 509 | | { |
| 357 | else /* hires */ |
| 510 | 358 | { |
| 511 | | UINT8 clr = colour; |
| 512 | | UINT8 clipmask = snes_ppu.clipmasks[SNES_OAM][pos]; |
| 513 | | |
| 514 | | #ifdef SNES_LAYER_DEBUG |
| 515 | | if (debug_options.windows_disabled) |
| 516 | | clipmask = 0xff; |
| 517 | | #endif /* SNES_LAYER_DEBUG */ |
| 518 | | |
| 519 | | /* Clip to windows */ |
| 520 | | if (scanlines[SNES_SUBSCREEN].clip) |
| 521 | | clr &= clipmask; |
| 522 | | |
| 523 | | /* Only draw if we have a colour (0 == transparent) */ |
| 524 | | if (clr) |
| 359 | if (mosaic) |
| 525 | 360 | { |
| 526 | | c = snes_cgram[(pal + clr) % FIXED_COLOUR]; |
| 527 | | blend = (pal + clr < 192) ? 1 : 0; |
| 528 | | |
| 529 | | scanlines[SNES_SUBSCREEN].buffer[pos] = c; |
| 530 | | scanlines[SNES_SUBSCREEN].priority[pos] = priority; |
| 531 | | scanlines[SNES_SUBSCREEN].layer[pos] = SNES_OAM; |
| 532 | | scanlines[SNES_SUBSCREEN].blend_exception[pos] = blend; |
| 361 | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++) |
| 362 | snes_draw_bgtile_hires(layer, ii + x_mos, colour, pal, direct_colors, priority); |
| 363 | ii += x_mos - 1; |
| 533 | 364 | } |
| 365 | else |
| 366 | snes_draw_bgtile_hires(layer, ii, colour, pal, direct_colors, priority); |
| 534 | 367 | } |
| 535 | 368 | } |
| 369 | |
| 370 | /* adjust tileaddr & x in case we have to draw again (for 16x16 tiles) */ |
| 371 | if (!flip) |
| 372 | tileaddr += (8 * planes); |
| 373 | else |
| 374 | tileaddr -= (8 * planes); |
| 375 | |
| 376 | x += 8; |
| 536 | 377 | } |
| 537 | 378 | } |
| 538 | 379 | |
| r7648 | r7649 | |
| 596 | 437 | UINT16 opt_bit = (layer == SNES_BG1) ? 13 : (layer == SNES_BG2) ? 14 : 0; |
| 597 | 438 | UINT8 tile_size; |
| 598 | 439 | /* variables depending on color_depth */ |
| 599 | | UINT8 tile_divider = (color_depth == SNES_COLOR_DEPTH_8BPP) ? 4 : 2; |
| 600 | 440 | UINT8 color_planes = 2 << color_depth; |
| 601 | 441 | /* below we cheat to simplify the code: 8BPP should have 0 pal offset, not 0x100 (but we take care of this by later using pal % FIXED_COLOUR) */ |
| 602 | 442 | UINT8 color_shift = 2 << color_depth; |
| r7648 | r7649 | |
| 703 | 543 | } |
| 704 | 544 | |
| 705 | 545 | #ifdef SNES_LAYER_DEBUG |
| 706 | | /* if we want to draw only one of the priorities of this layer */ |
| 707 | | if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) || |
| 708 | | ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b))) |
| 709 | | { |
| 710 | | if (!hires && tile_size) |
| 711 | | ii += 16; |
| 712 | | else |
| 713 | | ii += 8; |
| 714 | | continue; |
| 715 | | } |
| 546 | /* if we want to draw only one of the priorities of this layer */ |
| 547 | if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) || |
| 548 | ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b))) |
| 549 | { |
| 550 | if (!hires && tile_size) |
| 551 | ii += 16; |
| 552 | else |
| 553 | ii += 8; |
| 554 | continue; |
| 555 | } |
| 716 | 556 | #endif /* SNES_LAYER_DEBUG */ |
| 717 | 557 | |
| 718 | | |
| 719 | 558 | /* figure out which line to draw */ |
| 720 | 559 | yscroll = ypos & ((8 << tile_size) - 1); |
| 721 | 560 | |
| 722 | | if (yscroll > ((8 << tile_size) - 1)) /* scrolled into the next tile */ |
| 723 | | yscroll -= (8 << tile_size); |
| 561 | if (tile_size) |
| 562 | if ((yscroll & 8) != vflip) |
| 563 | tile += 16; |
| 724 | 564 | |
| 565 | if (yscroll > 7) |
| 566 | yscroll &= 7; |
| 567 | |
| 725 | 568 | if (vflip) |
| 726 | | { |
| 727 | | if (tile_size) |
| 728 | | { |
| 729 | | if (yscroll > 7) |
| 730 | | { |
| 731 | | yscroll -= 8; |
| 732 | | } |
| 733 | | else |
| 734 | | { |
| 735 | | tile += 32 / tile_divider; |
| 736 | | } |
| 737 | | } |
| 738 | 569 | yscroll = -yscroll + 7; |
| 739 | | } |
| 740 | | else |
| 741 | | { |
| 742 | | if (yscroll > 7) |
| 743 | | { |
| 744 | | tile += 32 / tile_divider; |
| 745 | | yscroll -= 8; |
| 746 | | } |
| 747 | | } |
| 570 | |
| 748 | 571 | yscroll <<= 1; |
| 749 | 572 | |
| 750 | | /* below, only color_planes depends on color_depth */ |
| 751 | | if (hires) /* Hi-Res: 2bpp & 4bpp */ |
| 573 | if (hires) |
| 752 | 574 | { |
| 753 | | snes_draw_tile_x2(color_planes, layer, charaddr + (tile * 8 * color_planes) + yscroll, (ii - xscroll) * 2, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 575 | /* adjust tile for horizontal flip */ |
| 576 | if (hflip) |
| 577 | tile += 1; |
| 578 | |
| 579 | /* draw 16 pixels (the routine will automatically send half of them to the mainscreen scanline and half to the subscreen one) */ |
| 580 | snes_draw_tile(color_planes, layer, charaddr + (tile * 8 * color_planes) + yscroll, (ii - xscroll) * 2, 1, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 754 | 581 | ii += 8; |
| 755 | 582 | } |
| 756 | | else /* tile_size = 0 */ |
| 583 | else |
| 757 | 584 | { |
| 758 | | if (tile_size) |
| 759 | | { |
| 760 | | snes_draw_tile_x2(color_planes, layer, charaddr + (tile * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 761 | | ii += 16; |
| 762 | | } |
| 763 | | else /* No Hi-Res: 2bpp, 4bpp & 8bpp */ |
| 764 | | { |
| 765 | | snes_draw_tile(color_planes, layer, charaddr + (tile * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 766 | | ii += 8; |
| 767 | | } |
| 585 | /* adjust tile for horizontal flip */ |
| 586 | if (tile_size && hflip) |
| 587 | tile += 1; |
| 588 | |
| 589 | snes_draw_tile(color_planes, layer, charaddr + (tile * 8 * color_planes) + yscroll, ii - xscroll, tile_size, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 590 | ii += (8 << tile_size); |
| 768 | 591 | } |
| 769 | 592 | } |
| 770 | 593 | } |
| r7648 | r7649 | |
| 787 | 610 | UINT8 colour = 0; |
| 788 | 611 | UINT16 *mosaic_x, *mosaic_y; |
| 789 | 612 | UINT16 c; |
| 613 | int screen; |
| 790 | 614 | |
| 791 | 615 | #ifdef SNES_LAYER_DEBUG |
| 792 | 616 | if (debug_options.bg_disabled[layer]) |
| r7648 | r7649 | |
| 903 | 727 | colour &= 0x7f; |
| 904 | 728 | |
| 905 | 729 | #ifdef SNES_LAYER_DEBUG |
| 906 | | /* if we want to draw only one of the priorities of this layer */ |
| 907 | | if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) || |
| 908 | | ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b))) |
| 909 | | continue; |
| 730 | /* if we want to draw only one of the priorities of this layer */ |
| 731 | if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) || |
| 732 | ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b))) |
| 733 | continue; |
| 910 | 734 | #endif /* SNES_LAYER_DEBUG */ |
| 911 | 735 | } |
| 912 | 736 | |
| 913 | | if (scanlines[SNES_MAINSCREEN].enable) |
| 737 | for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++) |
| 914 | 738 | { |
| 915 | | UINT8 clr = colour; |
| 916 | | UINT8 clipmask = snes_ppu.clipmasks[layer][xpos]; |
| 917 | | |
| 918 | | #ifdef SNES_LAYER_DEBUG |
| 919 | | if (debug_options.windows_disabled) |
| 920 | | clipmask = 0xff; |
| 921 | | #endif /* SNES_LAYER_DEBUG */ |
| 922 | | |
| 923 | | /* Clip to windows */ |
| 924 | | if (scanlines[SNES_MAINSCREEN].clip) |
| 925 | | clr &= clipmask; |
| 926 | | |
| 927 | | /* Draw pixel if appropriate */ |
| 928 | | if (scanlines[SNES_MAINSCREEN].priority[xpos] <= priority && clr > 0) |
| 739 | if (scanlines[screen].enable) |
| 929 | 740 | { |
| 930 | | /* Direct select, but only outside EXTBG! */ |
| 931 | | if (snes_ppu.direct_color && layer == SNES_BG1) |
| 932 | | { |
| 933 | | /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */ |
| 934 | | c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7); |
| 935 | | } |
| 936 | | else |
| 937 | | c = snes_cgram[clr]; |
| 741 | UINT8 clr = colour; |
| 742 | UINT8 clipmask = snes_ppu.clipmasks[layer][xpos]; |
| 938 | 743 | |
| 939 | | scanlines[SNES_MAINSCREEN].buffer[xpos] = c; |
| 940 | | scanlines[SNES_MAINSCREEN].priority[xpos] = priority; |
| 941 | | scanlines[SNES_MAINSCREEN].layer[xpos] = layer; |
| 942 | | } |
| 943 | | } |
| 944 | | |
| 945 | | if (scanlines[SNES_SUBSCREEN].enable) |
| 946 | | { |
| 947 | | UINT8 clr = colour; |
| 948 | | UINT8 clipmask = snes_ppu.clipmasks[layer][xpos]; |
| 949 | | |
| 950 | 744 | #ifdef SNES_LAYER_DEBUG |
| 951 | | if (debug_options.windows_disabled) |
| 952 | | clipmask = 0xff; |
| 745 | if (debug_options.windows_disabled) |
| 746 | clipmask = 0xff; |
| 953 | 747 | #endif /* SNES_LAYER_DEBUG */ |
| 954 | 748 | |
| 955 | | /* Clip to windows */ |
| 956 | | if (scanlines[SNES_SUBSCREEN].clip) |
| 957 | | clr &= clipmask; |
| 749 | /* Clip to windows */ |
| 750 | if (scanlines[screen].clip) |
| 751 | clr &= clipmask; |
| 958 | 752 | |
| 959 | | /* Draw pixel if appropriate */ |
| 960 | | if (scanlines[SNES_SUBSCREEN].priority[xpos] <= priority && clr > 0) |
| 961 | | { |
| 962 | | /* Direct select, but only outside EXTBG! */ |
| 963 | | if (snes_ppu.direct_color && layer == SNES_BG1) |
| 753 | /* Draw pixel if appropriate */ |
| 754 | if (scanlines[screen].priority[xpos] <= priority && clr > 0) |
| 964 | 755 | { |
| 965 | | /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */ |
| 966 | | c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7); |
| 756 | /* Direct select, but only outside EXTBG! */ |
| 757 | // Direct color format is: 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. |
| 758 | // In other words, like normal direct color, with pal = 0 |
| 759 | c = snes_get_bgcolor(snes_ppu.direct_color && layer == SNES_BG1, 0, clr); |
| 760 | snes_set_scanline_pixel(screen, xpos, c, priority, layer, 0); |
| 967 | 761 | } |
| 968 | | else |
| 969 | | c = snes_cgram[clr]; |
| 970 | | |
| 971 | | scanlines[SNES_SUBSCREEN].buffer[xpos] = c; |
| 972 | | scanlines[SNES_SUBSCREEN].priority[xpos] = priority; |
| 973 | | scanlines[SNES_SUBSCREEN].layer[xpos] = layer; |
| 974 | 762 | } |
| 975 | 763 | } |
| 976 | 764 | } |
| r7648 | r7649 | |
| 1327 | 1115 | } |
| 1328 | 1116 | #endif /* SNES_LAYER_DEBUG */ |
| 1329 | 1117 | |
| 1330 | | snes_draw_tile_object(charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, pri, oam_tilelist[tile].hflip, oam_tilelist[tile].pal); |
| 1118 | /* OAM tiles have fixed planes (4), fixed tile_size (8x8), no direct color and no hires, but otherwise work the same as BG ones */ |
| 1119 | snes_draw_tile(4, SNES_OAM, charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, 0, pri, oam_tilelist[tile].hflip, 0, oam_tilelist[tile].pal, 0); |
| 1331 | 1120 | } |
| 1332 | 1121 | } |
| 1333 | 1122 | |
| r7648 | r7649 | |
| 1763 | 1552 | snes_update_obsel(); |
| 1764 | 1553 | |
| 1765 | 1554 | #ifdef SNES_LAYER_DEBUG |
| 1766 | | if (snes_dbg_video(machine, bitmap, curline)) |
| 1555 | if (snes_dbg_video(machine, curline)) |
| 1767 | 1556 | { |
| 1768 | 1557 | profiler_mark_end(); |
| 1769 | 1558 | return; |
| r7648 | r7649 | |
| 1870 | 1659 | { |
| 1871 | 1660 | #ifdef SNES_LAYER_DEBUG |
| 1872 | 1661 | memset(&debug_options, 0, sizeof(debug_options)); |
| 1873 | | debug_options.input_count = 5; |
| 1874 | 1662 | #endif |
| 1875 | 1663 | } |
| 1876 | 1664 | |
| r7648 | r7649 | |
| 1891 | 1679 | |
| 1892 | 1680 | #ifdef SNES_LAYER_DEBUG |
| 1893 | 1681 | |
| 1894 | | static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16 curline ) |
| 1895 | | { |
| 1896 | | /* Check if the user has enabled or disabled stuff */ |
| 1897 | | if (curline == 1) |
| 1898 | | { |
| 1899 | | if (!debug_options.input_count--) |
| 1900 | | { |
| 1901 | | int i; |
| 1902 | | UINT8 toggles = input_port_read_safe(machine, "DEBUG1", 0); |
| 1903 | | debug_options.select_pri[SNES_BG1] = (toggles & 0x03); |
| 1904 | | debug_options.select_pri[SNES_BG2] = (toggles & 0x0c) >> 2; |
| 1905 | | debug_options.select_pri[SNES_BG3] = (toggles & 0x30) >> 4; |
| 1906 | | debug_options.select_pri[SNES_BG4] = (toggles & 0xc0) >> 6; |
| 1682 | #define DEBUG_TOGGLE(bit, debug_settings, MSG1, MSG2) \ |
| 1683 | if (BIT(toggles, bit) && !debug_settings) \ |
| 1684 | { \ |
| 1685 | debug_settings = 1; \ |
| 1686 | popmessage MSG1; \ |
| 1687 | } \ |
| 1688 | else if (!BIT(toggles, bit) && debug_settings) \ |
| 1689 | { \ |
| 1690 | debug_settings = 0; \ |
| 1691 | popmessage MSG2; \ |
| 1692 | } \ |
| 1907 | 1693 | |
| 1908 | | toggles = input_port_read_safe(machine, "DEBUG2", 0); |
| 1909 | | for (i = 0; i < 4; i++) |
| 1910 | | { |
| 1911 | | if (BIT(toggles, i)) |
| 1912 | | { |
| 1913 | | debug_options.bg_disabled[i] = !debug_options.bg_disabled[i]; |
| 1914 | | popmessage("Debug: %s BG%d.\n", debug_options.bg_disabled[i] ? "Disabled" : "Enabled", i + 1); |
| 1915 | | } |
| 1916 | | } |
| 1917 | | if (BIT(toggles, 4)) |
| 1918 | | { |
| 1919 | | debug_options.bg_disabled[SNES_OAM] = !debug_options.bg_disabled[SNES_OAM]; |
| 1920 | | popmessage("Debug: %s OAM.\n", debug_options.bg_disabled[SNES_OAM] ? "Disabled" : "Enabled"); |
| 1921 | | } |
| 1922 | | if (BIT(toggles, 5)) |
| 1923 | | { |
| 1924 | | debug_options.draw_subscreen = !debug_options.draw_subscreen; |
| 1925 | | popmessage("Debug: Switched screens.\n"); |
| 1926 | | } |
| 1927 | | if (BIT(toggles, 6)) |
| 1928 | | { |
| 1929 | | debug_options.colormath_disabled = !debug_options.colormath_disabled; |
| 1930 | | popmessage("Debug: %s Color Math.\n", debug_options.colormath_disabled ? "Disabled" : "Enabled"); |
| 1931 | | } |
| 1932 | | if (BIT(toggles, 7)) |
| 1933 | | { |
| 1934 | | debug_options.windows_disabled = !debug_options.windows_disabled; |
| 1935 | | popmessage("Debug: %s Window Masks.\n", debug_options.windows_disabled ? "Disabled" : "Enabled"); |
| 1936 | | } |
| 1937 | 1694 | |
| 1938 | | toggles = input_port_read_safe(machine, "DEBUG4", 0); |
| 1939 | | for (i = 0; i < 8; i++) |
| 1940 | | { |
| 1941 | | if (BIT(toggles, i)) |
| 1942 | | { |
| 1943 | | debug_options.mode_disabled[i] = !debug_options.mode_disabled[i]; |
| 1944 | | popmessage("Debug: %s Mode %d drawing.\n", debug_options.mode_disabled[i] ? "Disabled" : "Enabled", i); |
| 1945 | | } |
| 1946 | | } |
| 1695 | static UINT8 snes_dbg_video( running_machine *machine, UINT16 curline ) |
| 1696 | { |
| 1697 | int i; |
| 1698 | UINT8 toggles = input_port_read_safe(machine, "DEBUG1", 0); |
| 1699 | debug_options.select_pri[SNES_BG1] = (toggles & 0x03); |
| 1700 | debug_options.select_pri[SNES_BG2] = (toggles & 0x0c) >> 2; |
| 1701 | debug_options.select_pri[SNES_BG3] = (toggles & 0x30) >> 4; |
| 1702 | debug_options.select_pri[SNES_BG4] = (toggles & 0xc0) >> 6; |
| 1947 | 1703 | |
| 1948 | | toggles = input_port_read_safe(machine, "DEBUG3", 0); |
| 1949 | | if (toggles & 0x4) |
| 1950 | | { |
| 1951 | | debug_options.mosaic_disabled = !debug_options.mosaic_disabled; |
| 1952 | | popmessage("Debug: %s Mosaic.\n", debug_options.mosaic_disabled ? "Disabled" : "Enabled"); |
| 1953 | | } |
| 1954 | | debug_options.sprite_reversed = BIT(toggles, 7); |
| 1955 | | debug_options.select_pri[SNES_OAM] = (toggles & 0x70) >> 4; |
| 1704 | toggles = input_port_read_safe(machine, "DEBUG2", 0); |
| 1705 | for (i = 0; i < 4; i++) |
| 1706 | DEBUG_TOGGLE(i, debug_options.bg_disabled[i], ("Debug: Disabled BG%d.\n", i + 1), ("Debug: Enabled BG%d.\n", i + 1)) |
| 1707 | DEBUG_TOGGLE(4, debug_options.bg_disabled[SNES_OAM], ("Debug: Disabled OAM.\n"), ("Debug: Enabled OAM.\n")) |
| 1708 | DEBUG_TOGGLE(5, debug_options.draw_subscreen, ("Debug: Switched screens.\n"), ("Debug: Switched screens.\n")) |
| 1709 | DEBUG_TOGGLE(6, debug_options.colormath_disabled, ("Debug: Disabled Color Math.\n"), ("Debug: Enabled Color Math.\n")) |
| 1710 | DEBUG_TOGGLE(7, debug_options.windows_disabled, ("Debug: Disabled Window Masks.\n"), ("Debug: Enabled Window Masks.\n")) |
| 1956 | 1711 | |
| 1957 | | debug_options.input_count = 5; |
| 1958 | | } |
| 1712 | toggles = input_port_read_safe(machine, "DEBUG4", 0); |
| 1713 | for (i = 0; i < 8; i++) |
| 1714 | DEBUG_TOGGLE(i, debug_options.mode_disabled[i], ("Debug: Disabled Mode %d drawing.\n", i), ("Debug: Enabled Mode %d drawing.\n", i)) |
| 1959 | 1715 | |
| 1716 | toggles = input_port_read_safe(machine, "DEBUG3", 0); |
| 1717 | DEBUG_TOGGLE(2, debug_options.mosaic_disabled, ("Debug: Disabled Mosaic.\n"), ("Debug: Enabled Mosaic.\n")) |
| 1718 | debug_options.sprite_reversed = BIT(toggles, 7); |
| 1719 | debug_options.select_pri[SNES_OAM] = (toggles & 0x70) >> 4; |
| 1720 | |
| 1960 | 1721 | #ifdef MAME_DEBUG |
| 1722 | /* Once per frame, log video properties */ |
| 1723 | if (curline == 1) |
| 1724 | { |
| 1961 | 1725 | static const char WINLOGIC[4] = { '|', '&', '^', '!' }; |
| 1962 | 1726 | |
| 1963 | 1727 | logerror("%s", debug_options.windows_disabled?" ":"W"); |
| r7648 | r7649 | |
| 2046 | 1810 | logerror("Mode7: A %5d B %5d", snes_ppu.mode7.matrix_a, snes_ppu.mode7.matrix_b ); |
| 2047 | 1811 | 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 ); |
| 2048 | 1812 | logerror(" X %5d Y %5d", snes_ppu.mode7.origin_x, snes_ppu.mode7.origin_y ); |
| 2049 | | #endif |
| 2050 | 1813 | } |
| 1814 | #endif |
| 2051 | 1815 | |
| 2052 | 1816 | return 0; |
| 2053 | 1817 | } |