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 lsb = get_bit(lsbs, 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::One => self.obj_palette_1,
}
.map_bits(lsb, msb);
if colour
== match object.flags.palette {
ObjPalette::Zero => self.obj_palette_0,
ObjPalette::One => self.obj_palette_1,
}
.zero
{
if is_zero {
continue;
}
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 lsb = get_bit(lsbs, 7 - tile_px_x);
let msb = get_bit(msbs, 7 - tile_px_x);
let colour = self.bg_palette.map_bits(lsb, msb);
if lsb || msb {
self.is_bg_zero[x] = false;
}
let (colour, is_zero) = self.bg_palette.map_bits(lsb, msb);
self.is_bg_zero[x] = is_zero;
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);
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)
}
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) {
(true, true) => self.three,
(true, false) => self.one,
(false, true) => self.two,
(false, false) => self.zero,
(true, true) => (self.three, false),
(true, false) => (self.one, false),
(false, true) => (self.two, false),
(false, false) => (self.zero, true),
}
}
}