src/mame/video/snes.c
| r7517 | r7518 | |
| 136 | 136 | * between the main and sub screens. |
| 137 | 137 | *****************************************/ |
| 138 | 138 | |
| 139 | | INLINE void snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip ) |
| 139 | INLINE void snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip, int switch_screens ) |
| 140 | 140 | { |
| 141 | /* when color math is applied to subscreen pixels, the blending depends on the blending used by the previous mainscreen |
| 142 | pixel, except for subscreen pixel 0 which has no previous mainscreen pixel, see comments in snes_refresh_scanline */ |
| 143 | if (switch_screens && offset > 0) |
| 144 | offset -= 1; |
| 145 | |
| 141 | 146 | if ((black_pen_clip == SNES_CLIP_ALL2) || |
| 142 | 147 | (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) || |
| 143 | 148 | (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset])) |
| r7517 | r7518 | |
| 154 | 159 | (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset])) |
| 155 | 160 | { |
| 156 | 161 | UINT16 r, g, b; |
| 162 | struct SCANLINE *subscreen; |
| 157 | 163 | int clip_max = 0; // if add then clip to 0x1f, if sub then clip to 0 |
| 158 | 164 | |
| 165 | #ifdef SNES_LAYER_DEBUG |
| 166 | /* Toggle drawing of SNES_SUBSCREEN or SNES_MAINSCREEN */ |
| 167 | if (debug_options.draw_subscreen) |
| 168 | { |
| 169 | subscreen = switch_screens ? &scanlines[SNES_SUBSCREEN] : &scanlines[SNES_MAINSCREEN]; |
| 170 | } |
| 171 | else |
| 172 | #endif /* SNES_LAYER_DEBUG */ |
| 173 | { |
| 174 | subscreen = switch_screens ? &scanlines[SNES_MAINSCREEN] : &scanlines[SNES_SUBSCREEN]; |
| 175 | } |
| 176 | |
| 159 | 177 | if (snes_ppu.sub_add_mode) /* SNES_SUBSCREEN*/ |
| 160 | 178 | { |
| 161 | 179 | if (!BIT(snes_ppu.color_modes, 7)) |
| 162 | 180 | { |
| 163 | 181 | /* 0x00 add */ |
| 164 | | r = (*colour & 0x1f) + (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f); |
| 165 | | g = ((*colour & 0x3e0) >> 5) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5); |
| 166 | | b = ((*colour & 0x7c00) >> 10) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10); |
| 182 | r = (*colour & 0x1f) + (subscreen->buffer[offset] & 0x1f); |
| 183 | g = ((*colour & 0x3e0) >> 5) + ((subscreen->buffer[offset] & 0x3e0) >> 5); |
| 184 | b = ((*colour & 0x7c00) >> 10) + ((subscreen->buffer[offset] & 0x7c00) >> 10); |
| 167 | 185 | clip_max = 1; |
| 168 | 186 | } |
| 169 | 187 | else |
| 170 | 188 | { |
| 171 | 189 | /* 0x80 sub */ |
| 172 | | r = (*colour & 0x1f) - (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f); |
| 173 | | g = ((*colour & 0x3e0) >> 5) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5); |
| 174 | | b = ((*colour & 0x7c00) >> 10) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10); |
| 190 | r = (*colour & 0x1f) - (subscreen->buffer[offset] & 0x1f); |
| 191 | g = ((*colour & 0x3e0) >> 5) - ((subscreen->buffer[offset] & 0x3e0) >> 5); |
| 192 | b = ((*colour & 0x7c00) >> 10) - ((subscreen->buffer[offset] & 0x7c00) >> 10); |
| 175 | 193 | if (r > 0x1f) r = 0; |
| 176 | 194 | if (g > 0x1f) g = 0; |
| 177 | 195 | if (b > 0x1f) b = 0; |
| 178 | 196 | } |
| 179 | 197 | /* only halve if the color is not the back colour */ |
| 180 | | if (BIT(snes_ppu.color_modes, 6) && (scanlines[SNES_SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR])) |
| 198 | if (BIT(snes_ppu.color_modes, 6) && (subscreen->buffer[offset] != snes_cgram[FIXED_COLOUR])) |
| 181 | 199 | { |
| 182 | 200 | r >>= 1; |
| 183 | 201 | g >>= 1; |
| r7517 | r7518 | |
| 1368 | 1386 | UINT16 ii; |
| 1369 | 1387 | int x; |
| 1370 | 1388 | int fade; |
| 1371 | | struct SCANLINE *scanline; |
| 1389 | struct SCANLINE *scanline1, *scanline2; |
| 1372 | 1390 | UINT16 c; |
| 1373 | 1391 | |
| 1374 | 1392 | profiler_mark_start(PROFILER_VIDEO); |
| r7517 | r7518 | |
| 1420 | 1438 | |
| 1421 | 1439 | /* Toggle drawing of SNES_SUBSCREEN or SNES_MAINSCREEN */ |
| 1422 | 1440 | if (debug_options.draw_subscreen) |
| 1423 | | scanline = &scanlines[SNES_SUBSCREEN]; |
| 1441 | { |
| 1442 | scanline1 = &scanlines[SNES_SUBSCREEN]; |
| 1443 | scanline2 = &scanlines[SNES_MAINSCREEN]; |
| 1444 | } |
| 1424 | 1445 | else |
| 1425 | 1446 | #endif /* SNES_LAYER_DEBUG */ |
| 1426 | | scanline = &scanlines[SNES_MAINSCREEN]; |
| 1447 | { |
| 1448 | scanline1 = &scanlines[SNES_MAINSCREEN]; |
| 1449 | scanline2 = &scanlines[SNES_SUBSCREEN]; |
| 1450 | } |
| 1427 | 1451 | |
| 1428 | 1452 | /* Phew! Draw the line to screen */ |
| 1429 | 1453 | fade = snes_ppu.screen_brightness; |
| r7517 | r7518 | |
| 1431 | 1455 | for (x = 0; x < SNES_SCR_WIDTH; x++) |
| 1432 | 1456 | { |
| 1433 | 1457 | int r, g, b, hires; |
| 1434 | | UINT16 temp_col; |
| 1435 | 1458 | hires = (snes_ppu.mode != 5 && snes_ppu.mode != 6) ? 0 : 1; |
| 1436 | | c = scanline->buffer[x]; |
| 1437 | | temp_col = scanline->buffer[x]; |
| 1459 | c = scanline1->buffer[x]; |
| 1438 | 1460 | |
| 1439 | 1461 | /* perform color math if the layer wants it (except if it's an object > 192) */ |
| 1440 | | if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math) |
| 1441 | | snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1462 | if (!scanline1->blend_exception[x] && snes_ppu.layer[scanline1->layer[x]].color_math) |
| 1463 | snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask, 0); |
| 1442 | 1464 | |
| 1443 | 1465 | r = ((c & 0x1f) * fade) >> 4; |
| 1444 | 1466 | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1445 | 1467 | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1446 | 1468 | |
| 1447 | | *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1469 | *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1448 | 1470 | |
| 1471 | /* in hires, the first pixel (of 512) is subscreen pixel, then the first mainscreen pixel follows, and so on... */ |
| 1449 | 1472 | if (!hires) |
| 1450 | | *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1473 | *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1451 | 1474 | else |
| 1452 | 1475 | { |
| 1453 | | c = scanlines[SNES_SUBSCREEN].buffer[x]; |
| 1454 | | scanlines[SNES_SUBSCREEN].buffer[x] = temp_col; |
| 1476 | c = scanline2->buffer[x]; |
| 1455 | 1477 | |
| 1456 | | if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math) |
| 1457 | | snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1478 | /* in hires, subscreen pixels are blended as well: for each subscreen pixel, color math is applied if |
| 1479 | it had been applied to the previous mainscreen pixel. What happens at subscreen pixel 0 (which has no |
| 1480 | previous mainscreen pixel) is undocumented. Until more info are discovered, we (arbitrarily) apply to it |
| 1481 | the same color math as the *next* mainscreen pixel (i.e. mainscreen pixel 0) */ |
| 1458 | 1482 | |
| 1483 | if (x == 0 && !scanline1->blend_exception[0] && snes_ppu.layer[scanline1->layer[0]].color_math) |
| 1484 | snes_draw_blend(0, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask, 1); |
| 1485 | else if (x > 0 && !scanline1->blend_exception[x - 1] && snes_ppu.layer[scanline1->layer[x - 1]].color_math) |
| 1486 | snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask, 1); |
| 1487 | |
| 1488 | |
| 1459 | 1489 | r = ((c & 0x1f) * fade) >> 4; |
| 1460 | 1490 | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1461 | 1491 | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1462 | 1492 | |
| 1463 | | *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1493 | *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1464 | 1494 | } |
| 1465 | 1495 | } |
| 1466 | 1496 | } |