diff --git a/lib/src/processor/memory/mmio/gpu.rs b/lib/src/processor/memory/mmio/gpu.rs index b9eb38b..9327f90 100644 --- a/lib/src/processor/memory/mmio/gpu.rs +++ b/lib/src/processor/memory/mmio/gpu.rs @@ -117,10 +117,11 @@ where match self.stat.mode { DrawMode::HBlank => { // mode 0: hblank - if self.mode_clock >= 204 { - self.mode_clock = 0; + const HBLANK_MODE_CLOCK: usize = 204; + if self.mode_clock >= HBLANK_MODE_CLOCK { + self.mode_clock -= HBLANK_MODE_CLOCK; self.scanline += 1; - if self.scanline == 143 { + if self.scanline == 144 { self.enter_vblank(output); interrupts.vblank = true; } else { @@ -130,8 +131,9 @@ where } DrawMode::VBlank => { // mode 1: vblank - if self.mode_clock >= 456 { - self.mode_clock = 0; + const VBLANK_MODE_CLOCK: usize = 456; + if self.mode_clock >= VBLANK_MODE_CLOCK { + self.mode_clock -= VBLANK_MODE_CLOCK; self.scanline += 1; if self.scanline == 153 { self.exit_vblank(output); @@ -139,17 +141,19 @@ where } } DrawMode::Mode2 => { + const MODE2_MODE_CLOCK: usize = 80; // search oam for sprites on this line // we dont really have to emulate this - if self.mode_clock >= 80 { - self.mode_clock = 0; + if self.mode_clock >= MODE2_MODE_CLOCK { + self.mode_clock -= MODE2_MODE_CLOCK; self.stat.mode = DrawMode::Mode3; } } DrawMode::Mode3 => { + const MODE3_MODE_CLOCK: usize = 172; // generate scanline - if self.mode_clock >= 172 { - self.mode_clock = 0; + if self.mode_clock >= MODE3_MODE_CLOCK { + self.mode_clock -= MODE3_MODE_CLOCK; self.enter_hblank(output); } }