From 96af4b94a158a88237c15f858d937cbf37fe895e Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Thu, 9 Feb 2023 16:57:01 +1100 Subject: [PATCH] minor gpu improvements --- src/processor/gpu.rs | 15 ++++++++------- src/processor/gpu/types.rs | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/processor/gpu.rs b/src/processor/gpu.rs index af711fe..75cef70 100644 --- a/src/processor/gpu.rs +++ b/src/processor/gpu.rs @@ -169,7 +169,7 @@ impl CPU { let mode_1_vblank_enabled = get_bit(stat, 4); let mode_0_hblank_enabled = get_bit(stat, 3); - let lyc_eq_ly = self.memory.get(0xFF44) == self.memory.get(0xFF45); + let lyc_eq_ly = self.gpu.scanline == self.memory.get(0xFF45); let mode_2 = self.gpu.mode == DrawMode::Mode2; let mode_1_vblank = self.gpu.mode == DrawMode::VBlank; let mode_0_hblank = self.gpu.mode == DrawMode::HBlank; @@ -232,18 +232,16 @@ impl CPU { fn render_scanline_window(&mut self, scanline: u8, lcdc: &LCDC, palette: Palette) { let pos_y = self.memory.get(0xFF4A); // subtracting 7 to get the Real Number... - let pos_x = self.memory.get(0xFF4B).wrapping_sub(7); - if pos_y < 143 && pos_x < 166 { + let pos_x = self.memory.get(0xFF4B); self.render_tiles( scanline, &lcdc.window_tilemap, &lcdc.tile_area, palette, - pos_x, + pos_x.wrapping_sub(7), pos_y, false, - ) - } + ); } fn render_scanline_obj(&mut self, scanline: u8, lcdc: &LCDC, bg_palette: Palette) { @@ -304,6 +302,9 @@ impl CPU { let lsb = get_bit(lsbs, x_addr); let msb = get_bit(msbs, x_addr); let colour = bits_to_mapped_colour(lsb, msb, object.flags.palette); + if colour == object.flags.palette.zero { + continue; + } let x_coord_uncorrected = (object.x as usize) + (px_x as usize); if x_coord_uncorrected < 8 { continue; @@ -331,7 +332,7 @@ impl CPU { wrap: bool, ) { let tile_line_y = scanline.wrapping_add(offset_y); - if (scanline as usize + offset_y as usize) % 0xFF > 0 && !wrap { + if ((scanline as usize + offset_y as usize) / 0xFF) > 0 && !wrap { return; } let tilemap_row = tile_line_y / 8; diff --git a/src/processor/gpu/types.rs b/src/processor/gpu/types.rs index 3b37887..575f9bc 100644 --- a/src/processor/gpu/types.rs +++ b/src/processor/gpu/types.rs @@ -65,7 +65,7 @@ pub(super) struct LCDC { pub(super) bg_window_enable: bool, } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq)] pub(super) enum Colour { White, LightGray,