From f5b0ba2a2fba3fd18a2eaf61b8891e7d4cdf4d99 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Tue, 21 Nov 2023 15:22:53 -0500 Subject: [PATCH] Add initial register values to Processor::default --- src/register.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/register.rs b/src/register.rs index 3fc644b..956e275 100644 --- a/src/register.rs +++ b/src/register.rs @@ -10,6 +10,14 @@ pub enum Error { } const INITIAL_PROGRAM_COUNTER_VALUE: u16 = 0x100; +const INITIAL_STACK_POINTER_VALUE: u16 = 0xFFFE; +const INITIAL_A_REGISTER_VALUE: u8 = 0x01; +const INITIAL_B_REGISTER_VALUE: u8 = 0xFF; +const INITIAL_C_REGISTER_VALUE: u8 = 0x13; +const INITIAL_D_REGISTER_VALUE: u8 = 0x00; +const INITIAL_E_REGISTER_VALUE: u8 = 0xC1; +const INITIAL_H_REGISTER_VALUE: u8 = 0x84; +const INITIAL_L_REGISTER_VALUE: u8 = 0x03; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Flag { @@ -90,19 +98,19 @@ impl Registers { impl Default for Registers { fn default() -> Self { - // TODO: verify that these 0 values are correct. I feel like they must - // be, but I haven't read enough of the manual Registers { - a: 0, - b: 0, - c: 0, - d: 0, - e: 0, - h: 0, - l: 0, + a: INITIAL_A_REGISTER_VALUE, + b: INITIAL_B_REGISTER_VALUE, + c: INITIAL_C_REGISTER_VALUE, + d: INITIAL_D_REGISTER_VALUE, + e: INITIAL_E_REGISTER_VALUE, + h: INITIAL_H_REGISTER_VALUE, + l: INITIAL_L_REGISTER_VALUE, interrupts_enabled: false, - stack_pointer: 0, + stack_pointer: INITIAL_STACK_POINTER_VALUE, program_counter: INITIAL_PROGRAM_COUNTER_VALUE, + // TODO: this is correct on the "early" DMG0 but the more widely available DMG does have some nuance + // https://gbdev.io/pandocs/Power_Up_Sequence.html?highlight=FFFE#dmg_c flags: 0, } }