From 96aa63661a943df5b4ac1dafc8fb40dd6ab977d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Fri, 1 Jul 2022 12:35:49 +0100
Subject: [PATCH] feat: better clokc management

---
 examples/sdl/src/main.rs | 10 +++-------
 src/gb.rs                |  6 ++++++
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs
index 8f0ef696..c241329b 100644
--- a/examples/sdl/src/main.rs
+++ b/examples/sdl/src/main.rs
@@ -5,13 +5,9 @@ fn main() {
     game_boy.load_boot_default();
 
     for i in 0..37000 {
-        // runs the CPU clock and determines the number of
-        // cycles that have advanced for that clock tick
-        let cycles = game_boy.clock();
-
-        // calls the clock in the PPU to update its own
-        // execution lifecycle by one set of ticks
-        game_boy.ppu_clock(cycles);
+        // runs the Game Boy clock, this operations should
+        // include the advance of both the CPU and the PPU
+        game_boy.clock();
 
         if game_boy.cpu().pc() >= 0x6032 {
             println!("{}", i);
diff --git a/src/gb.rs b/src/gb.rs
index 463d8191..182ec36f 100644
--- a/src/gb.rs
+++ b/src/gb.rs
@@ -13,6 +13,12 @@ impl GameBoy {
     }
 
     pub fn clock(&mut self) -> u8 {
+        let cycles = self.cpu_clock();
+        self.ppu_clock(cycles);
+        cycles
+    }
+
+    pub fn cpu_clock(&mut self) -> u8 {
         self.cpu.clock()
     }
 
-- 
GitLab