diff --git a/src/bus.rs b/src/bus.rs index 241b9ad..ca4d23c 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -36,6 +36,7 @@ pub struct Bus { pub timer: Timer, pub sound: Sound, pub interrupts: Interrupts, + pub cgb_mode: bool, } impl Bus { @@ -67,6 +68,7 @@ impl Bus { timer: Timer::new(), sound: Sound::new(), interrupts: Interrupts::new(), + cgb_mode, }; // Hardware registers after the bootrom diff --git a/src/cpu.rs b/src/cpu.rs index 8eb594f..2db01a6 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -87,6 +87,21 @@ impl Registers { } } + pub fn new_cgb() -> Self { + Self { + a: 0x11, + f: 0x00, + b: 0x00, + c: 0x00, + d: 0xFF, + e: 0x56, + h: 0x00, + l: 0x0D, + sp: 0xFFFE, + pc: 0x0100, + } + } + pub fn get(&self, register: Register) -> u16 { match register { Register::A => self.a as u16, @@ -818,9 +833,12 @@ pub struct CPU { } impl CPU { - pub fn new() -> Self { + pub fn new(cgb_mode: bool) -> Self { Self { - registers: Registers::new(), + registers: match cgb_mode { + true => Registers::new_cgb(), + false => Registers::new(), + }, cycles: Cycles(0), last_op_cycles: Cycles(0), exec_calls_count: 0, diff --git a/src/emulator.rs b/src/emulator.rs index 53f328c..d272e7f 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -16,9 +16,11 @@ pub struct Emulator { impl Emulator { pub fn new() -> Self { + let bus = Bus::new(); + let cgb_mode = bus.cgb_mode; Self { - bus: Bus::new(), - cpu: CPU::new(), + bus, + cpu: CPU::new(cgb_mode), } }