diff --git a/src/processor/gpu.rs b/src/processor/gpu.rs index 9438b7b..13ee71f 100644 --- a/src/processor/gpu.rs +++ b/src/processor/gpu.rs @@ -1,6 +1,6 @@ use crate::{HEIGHT, WIDTH}; -use super::{set_bit, set_or_clear_bit, CPU}; +use super::{clear_bit, set_bit, set_or_clear_bit, CPU}; #[derive(PartialEq)] enum DrawMode { @@ -51,8 +51,7 @@ impl CPU { self.gpu.mode_clock = 0; self.gpu.scanline += 1; if self.gpu.scanline == 153 { - self.gpu.mode = DrawMode::Mode2; - self.gpu.scanline = 0; + self.exit_vblank(); } } } @@ -86,6 +85,13 @@ impl CPU { self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 0)); } + fn exit_vblank(&mut self) { + self.gpu.mode = DrawMode::Mode2; + self.gpu.scanline = 0; + self.memory + .set(0xFF0F, clear_bit(self.memory.get(0xFF0F), 0)); + } + fn set_lcd_status(&mut self) { let mut stat = self.memory.get(0xFF41); stat = set_or_clear_bit(stat, 2, self.memory.get(0xFF44) == self.memory.get(0xFF45));