From da30ead571b5243b777244b6407fe911fab8359f Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 19 Apr 2023 18:56:00 +0200 Subject: Fix some more ppu bugs --- src/ppu.c | 52 ++++++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) (limited to 'src/ppu.c') diff --git a/src/ppu.c b/src/ppu.c index afde963..3b159af 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -457,14 +457,10 @@ ppu_1bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y) { if ((y + v) >= SCREEN_HEIGHT) break; u8 ch1 = sprite[v]; u32 color= lut[ch1]; - u32 mask = ~color; + u32 mask = color * 0xF; color *= clr & 3; - if (start_col == 0) { - dst[0] = (dst[0] & ~mask) | color; - } else { - dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left); - dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right); - } + dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left); + dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right); if ((start_row + v) == 7) dst += (32 - 1) * 8; } } else { @@ -472,14 +468,10 @@ ppu_1bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y) { if ((y + v) >= SCREEN_HEIGHT) break; u8 ch1 = sprite[(7 - v)]; u32 color= lut[ch1]; - u32 mask = ~color; + u32 mask = color * 0xF; color *= clr & 3; - if (start_col == 0) { - dst[0] = (dst[0] & ~mask) | color; - } else { - dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left); - dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right); - } + dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left); + dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right); if ((start_row + v) == 7) dst += (32 - 1) * 8; } } @@ -631,12 +623,8 @@ ppu_2bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y) { u8 ch1 = sprite[v]; u8 ch2 = sprite[v | 8]; u32 color = lut[ch1] | (lut[ch2] << 1); - if (start_col == 0) { - dst[0] = (dst[0] & mask) | color; - } else { - dst[0] = (dst[0] & (mask << shift_left)) | color; - dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); - } + dst[0] = (dst[0] & (mask << shift_left)) | color; + dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); if ((start_row + v) == 7) dst += (32 - 1) * 8; } } else { @@ -645,12 +633,8 @@ ppu_2bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y) { u8 ch1 = sprite[(7 - v)]; u8 ch2 = sprite[(7 - v) | 8]; u32 color = lut[ch1] | (lut[ch2] << 1); - if (start_col == 0) { - dst[0] = (dst[0] & mask) | color; - } else { - dst[0] = (dst[0] & (mask << shift_left)) | color; - dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); - } + dst[0] = (dst[0] & (mask << shift_left)) | color; + dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); if ((start_row + v) == 7) dst += (32 - 1) * 8; } } @@ -723,12 +707,8 @@ ppu_2bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y) { color = (clr1 * col1mask) | (clr2 * col2mask) | (clr3 * col3mask); - if (start_col == 0) { - dst[0] = (dst[0] & mask) | color; - } else { - dst[0] = (dst[0] & (mask << shift_left)) | color; - dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); - } + dst[0] = (dst[0] & (mask << shift_left)) | color; + dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); if ((start_row + v) == 7) dst += (32 - 1) * 8; } } else { @@ -747,12 +727,8 @@ ppu_2bpp(u32 *layer, u16 x, u16 y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y) { color = (clr1 * col1mask) | (clr2 * col2mask) | (clr3 * col3mask); - if (start_col == 0) { - dst[0] = (dst[0] & mask) | color; - } else { - dst[0] = (dst[0] & (mask << shift_left)) | color; - dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); - } + dst[0] = (dst[0] & (mask << shift_left)) | color; + dst[8] = (dst[8] & (mask >> shift_right)) | (color >> shift_right); if ((start_row + v) == 7) dst += (32 - 1) * 8; } } -- cgit v1.2.1