From 0536d1924237d3a7bb28b74b10578552d19e99dc Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 26 Feb 2023 16:18:22 +1100 Subject: [PATCH] better zero checking --- src/processor/memory/mmio/gpu.rs | 17 ++++------------- src/processor/memory/mmio/gpu/tile_window.rs | 2 +- src/processor/memory/mmio/gpu/types.rs | 10 +++++----- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/processor/memory/mmio/gpu.rs b/src/processor/memory/mmio/gpu.rs index 15ab2a6..e1dc251 100644 --- a/src/processor/memory/mmio/gpu.rs +++ b/src/processor/memory/mmio/gpu.rs @@ -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(); } diff --git a/src/processor/memory/mmio/gpu/tile_window.rs b/src/processor/memory/mmio/gpu/tile_window.rs index 4150cda..0699ddc 100644 --- a/src/processor/memory/mmio/gpu/tile_window.rs +++ b/src/processor/memory/mmio/gpu/tile_window.rs @@ -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(); } } } diff --git a/src/processor/memory/mmio/gpu/types.rs b/src/processor/memory/mmio/gpu/types.rs index a76de9f..abf829e 100644 --- a/src/processor/memory/mmio/gpu/types.rs +++ b/src/processor/memory/mmio/gpu/types.rs @@ -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), } } }