Add initial register values to Processor::default

old-bit-manip
Nick Krichevsky 2023-11-21 15:22:53 -05:00
parent 206f364421
commit f5b0ba2a2f
1 changed files with 18 additions and 10 deletions

View File

@ -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,
}
}