From f14b13398792cf1b511dacd3e01ded0d50a13cdd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Sun, 25 Feb 2024 12:12:48 +0000
Subject: [PATCH] chore: better load boot state structure

Clarifies the boot state handling.
---
 frontends/sdl/src/main.rs |  3 +++
 src/gb.rs                 | 14 +++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs
index 3343e38b..f64569e1 100644
--- a/frontends/sdl/src/main.rs
+++ b/frontends/sdl/src/main.rs
@@ -971,6 +971,9 @@ fn main() {
     game_boy.set_timer_enabled(!args.no_timer);
     game_boy.attach_serial(device);
     game_boy.load(!args.no_boot && args.boot_rom_path.is_empty());
+    if args.no_boot {
+        game_boy.load_boot_state();
+    }
     if !args.boot_rom_path.is_empty() {
         game_boy.load_boot_path(&args.boot_rom_path).unwrap();
     }
diff --git a/src/gb.rs b/src/gb.rs
index fc55f9ae..f3058852 100644
--- a/src/gb.rs
+++ b/src/gb.rs
@@ -578,8 +578,11 @@ impl GameBoy {
         self.ppu().frame_index()
     }
 
+    /// Direct boot method that immediately jumps the machine
+    /// to the post boot state, this will effectively skip the
+    /// boot sequence and jump to the cartridge execution.
     pub fn boot(&mut self) {
-        self.cpu.boot();
+        self.load_boot_state();
     }
 
     pub fn load(&mut self, boot: bool) {
@@ -631,6 +634,15 @@ impl GameBoy {
         self.load_boot_static(BootRom::Cgb);
     }
 
+    /// Loads the boot machine state and sets the Program Counter
+    /// (PC) to the post boot address.
+    ///
+    /// Should allow the machine to jump to the cartridge execution
+    /// skipping the boot sequence.
+    pub fn load_boot_state(&mut self) {
+        self.cpu.boot();
+    }
+
     pub fn vram_eager(&mut self) -> Vec<u8> {
         self.ppu().vram().to_vec()
     }
-- 
GitLab