reset vblank flag lol

This commit is contained in:
Alex Janka 2023-02-05 18:50:07 +11:00
parent 976ee24d6a
commit 839429029d

View file

@ -1,6 +1,6 @@
use crate::{HEIGHT, WIDTH}; 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)] #[derive(PartialEq)]
enum DrawMode { enum DrawMode {
@ -51,8 +51,7 @@ impl CPU {
self.gpu.mode_clock = 0; self.gpu.mode_clock = 0;
self.gpu.scanline += 1; self.gpu.scanline += 1;
if self.gpu.scanline == 153 { if self.gpu.scanline == 153 {
self.gpu.mode = DrawMode::Mode2; self.exit_vblank();
self.gpu.scanline = 0;
} }
} }
} }
@ -86,6 +85,13 @@ impl CPU {
self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 0)); 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) { fn set_lcd_status(&mut self) {
let mut stat = self.memory.get(0xFF41); let mut stat = self.memory.get(0xFF41);
stat = set_or_clear_bit(stat, 2, self.memory.get(0xFF44) == self.memory.get(0xFF45)); stat = set_or_clear_bit(stat, 2, self.memory.get(0xFF44) == self.memory.get(0xFF45));