diff --git a/src/processor/memory/mmio/gpu.rs b/src/processor/memory/mmio/gpu.rs index def20b5..15ab2a6 100644 --- a/src/processor/memory/mmio/gpu.rs +++ b/src/processor/memory/mmio/gpu.rs @@ -24,6 +24,7 @@ pub struct Gpu { pub vram: Vram, pub oam: Oam, pub window: Box, + is_bg_zero: Vec, lcdc: Lcdc, stat: Stat, mode_clock: usize, @@ -55,6 +56,7 @@ impl Gpu { vram: Vram::default(), oam: Oam::default(), window, + is_bg_zero: vec![true; WIDTH], lcdc: Lcdc::default(), stat: Stat::default(), mode_clock: 0, @@ -153,6 +155,9 @@ impl Gpu { } fn render_scanline(&mut self, scanline: u8) { + for e in &mut self.is_bg_zero { + *e = true; + } for x in 0..WIDTH { self.buffer[(scanline as usize * WIDTH) + x] = Colour::from_u8_rgb(255, 0, 255); } @@ -292,9 +297,7 @@ impl Gpu { let x_coord = x_coord_uncorrected - 8; if x_coord < WIDTH { let buffer_index = (scanline as usize * WIDTH) + x_coord; - if !object.flags.behind_bg_and_window - || self.buffer[buffer_index] == self.bg_palette.zero.as_rgb() - { + if !object.flags.behind_bg_and_window || self.is_bg_zero[x_coord] { self.buffer[buffer_index] = colour.as_rgb(); } } @@ -340,6 +343,10 @@ impl Gpu { 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; + } + self.buffer[(scanline as usize * WIDTH) + x] = colour.as_rgb(); } } diff --git a/src/processor/memory/mmio/gpu/types.rs b/src/processor/memory/mmio/gpu/types.rs index b8ad570..a76de9f 100644 --- a/src/processor/memory/mmio/gpu/types.rs +++ b/src/processor/memory/mmio/gpu/types.rs @@ -125,7 +125,7 @@ impl Colour { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub(super) struct Palette { pub(super) zero: Colour, pub(super) one: Colour,