From c57db9433f638d00e86860c3bc718a254e46d977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Thu, 30 Jun 2022 13:37:46 +0100 Subject: [PATCH] feat: support for the hblank and vblank --- src/ppu.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/ppu.rs b/src/ppu.rs index e8292591..48ede09f 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -92,8 +92,37 @@ impl Ppu { self.mode = PpuMode::Hblank; } } - PpuMode::Hblank => todo!(), - PpuMode::VBlank => todo!(), + PpuMode::Hblank => { + if self.mode_clock >= 204 { + self.line += 1; + + // in case we've reached the end of the + // screen we're now entering the v-blank + if self.line == 143 { + self.mode = PpuMode::VBlank; + // self.drawData @todo implement this one + } else { + self.mode = PpuMode::OamRead; + } + + self.mode_clock = 0; + } + } + PpuMode::VBlank => { + if self.mode_clock >= 456 { + self.line += 1; + + // in case the end of v-blank has been reached then + // we must jump again to the OAM read mode and reset + // the scan line counter to the zero value + if self.line == 153 { + self.mode = PpuMode::OamRead; + self.line = 0; + } + + self.mode_clock = 0; + } + } } } -- GitLab