From cc4d044f2827e10a58c15002a95d1e78dc819fa3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Mon, 14 Nov 2022 23:59:17 +0000
Subject: [PATCH] feat: more generic boot loading

---
 src/gb.rs  |  6 +++++-
 src/mmu.rs | 11 ++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/gb.rs b/src/gb.rs
index 1dcc81e3..70234c9c 100644
--- a/src/gb.rs
+++ b/src/gb.rs
@@ -124,7 +124,11 @@ impl GameBoy {
     }
 
     pub fn load_boot_default(&mut self) {
-        self.load_boot_static(BootRom::DmgBootix);
+        self.load_boot_dmg();
+    }
+
+    pub fn load_boot_dmg(&mut self) {
+        self.load_boot_static(BootRom::Cgb);
     }
 
     pub fn load_boot_cgb(&mut self) {
diff --git a/src/mmu.rs b/src/mmu.rs
index abe5aa46..be0c48b6 100644
--- a/src/mmu.rs
+++ b/src/mmu.rs
@@ -1,6 +1,6 @@
 use crate::{debugln, pad::Pad, ppu::Ppu, rom::Cartridge, timer::Timer};
 
-pub const BOOT_SIZE: usize = 256;
+pub const BOOT_SIZE: usize = 2304;
 pub const RAM_SIZE: usize = 8192;
 
 pub struct Mmu {
@@ -30,7 +30,16 @@ pub struct Mmu {
     /// the boot sequence has been finished.
     boot_active: bool,
 
+    /// Buffer to be used to store the boot ROM, this is the code
+    /// that is going to be executed at the beginning of the Game
+    /// Boy execution. The buffer effectively used is of 256 bytes
+    /// for the "normal" Game Boy (MGB) and 2308 bytes for the
+    /// Game Boy Color (CGB). Note that in the case of the CGB
+    /// the bios which is 2308 bytes long is in fact only 2048 bytes
+    /// as the 256 bytes in range 0x100-0x1FF are meant to be
+    /// overwritten byte the cartridge header.
     boot: [u8; BOOT_SIZE],
+
     ram: [u8; RAM_SIZE],
 }
 
-- 
GitLab