Add initial register values to Processor::default

This commit is contained in:
Nick Krichevsky 2023-11-21 15:22:53 -05:00
parent 206f364421
commit f5b0ba2a2f

View file

@ -10,6 +10,14 @@ pub enum Error {
} }
const INITIAL_PROGRAM_COUNTER_VALUE: u16 = 0x100; 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)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Flag { pub enum Flag {
@ -90,19 +98,19 @@ impl Registers {
impl Default for Registers { impl Default for Registers {
fn default() -> Self { 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 { Registers {
a: 0, a: INITIAL_A_REGISTER_VALUE,
b: 0, b: INITIAL_B_REGISTER_VALUE,
c: 0, c: INITIAL_C_REGISTER_VALUE,
d: 0, d: INITIAL_D_REGISTER_VALUE,
e: 0, e: INITIAL_E_REGISTER_VALUE,
h: 0, h: INITIAL_H_REGISTER_VALUE,
l: 0, l: INITIAL_L_REGISTER_VALUE,
interrupts_enabled: false, interrupts_enabled: false,
stack_pointer: 0, stack_pointer: INITIAL_STACK_POINTER_VALUE,
program_counter: INITIAL_PROGRAM_COUNTER_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, flags: 0,
} }
} }