better zero checking

This commit is contained in:
Alex Janka 2023-02-26 16:18:22 +11:00
parent 78bb6fc65f
commit 0536d19242
3 changed files with 10 additions and 19 deletions

View file

@ -276,18 +276,12 @@ impl Gpu {
let x_addr = if object.flags.x_flip { px_x } else { 7 - px_x }; let x_addr = if object.flags.x_flip { px_x } else { 7 - px_x };
let lsb = get_bit(lsbs, x_addr); let lsb = get_bit(lsbs, x_addr);
let msb = get_bit(msbs, x_addr); let msb = get_bit(msbs, x_addr);
let colour = match object.flags.palette { let (colour, is_zero) = match object.flags.palette {
ObjPalette::Zero => self.obj_palette_0, ObjPalette::Zero => self.obj_palette_0,
ObjPalette::One => self.obj_palette_1, ObjPalette::One => self.obj_palette_1,
} }
.map_bits(lsb, msb); .map_bits(lsb, msb);
if colour if is_zero {
== match object.flags.palette {
ObjPalette::Zero => self.obj_palette_0,
ObjPalette::One => self.obj_palette_1,
}
.zero
{
continue; continue;
} }
let x_coord_uncorrected = (object.x as usize) + (px_x as usize); let x_coord_uncorrected = (object.x as usize) + (px_x as usize);
@ -341,11 +335,8 @@ impl Gpu {
let msbs = self.vram.get(tile_addr + 1); let msbs = self.vram.get(tile_addr + 1);
let lsb = get_bit(lsbs, 7 - tile_px_x); let lsb = get_bit(lsbs, 7 - tile_px_x);
let msb = get_bit(msbs, 7 - tile_px_x); let msb = get_bit(msbs, 7 - tile_px_x);
let colour = self.bg_palette.map_bits(lsb, msb); let (colour, is_zero) = self.bg_palette.map_bits(lsb, msb);
self.is_bg_zero[x] = is_zero;
if lsb || msb {
self.is_bg_zero[x] = false;
}
self.buffer[(scanline as usize * WIDTH) + x] = colour.as_rgb(); self.buffer[(scanline as usize * WIDTH) + x] = colour.as_rgb();
} }

View file

@ -66,7 +66,7 @@ impl TileWindow {
let colour = palette.map_bits(lsb, msb); let colour = palette.map_bits(lsb, msb);
self.sprite_buffer[real_px_x + (real_px_y * TILE_WINDOW_WIDTH)] = self.sprite_buffer[real_px_x + (real_px_y * TILE_WINDOW_WIDTH)] =
colour.as_rgb(); colour.0.as_rgb();
} }
} }
} }

View file

@ -150,12 +150,12 @@ impl Palette {
| (self.three.as_bits() << 6) | (self.three.as_bits() << 6)
} }
pub(super) fn map_bits(&self, lsb: bool, msb: bool) -> Colour { pub(super) fn map_bits(&self, lsb: bool, msb: bool) -> (Colour, bool) {
match (lsb, msb) { match (lsb, msb) {
(true, true) => self.three, (true, true) => (self.three, false),
(true, false) => self.one, (true, false) => (self.one, false),
(false, true) => self.two, (false, true) => (self.two, false),
(false, false) => self.zero, (false, false) => (self.zero, true),
} }
} }
} }