CPU constructor overhaul

This commit is contained in:
John 2024-07-09 00:59:33 -05:00
parent 358dfb832a
commit 184054349f

View File

@ -81,14 +81,61 @@ impl CPU {
/// ///
/// [CPU Registers]: https://gbdev.io/pandocs/Power_Up_Sequence.html#cpu-registers /// [CPU Registers]: https://gbdev.io/pandocs/Power_Up_Sequence.html#cpu-registers
pub fn new() -> Self { pub fn new() -> Self {
let mut out = Self::default(); Self::new_mgb()
out.af.wide_mut().0 = 0x1100 | Flags::new().with_z(true).into_bits() as u16; }
out.bc.wide_mut().0 = 0x0100;
out.de.wide_mut().0 = 0xff56; pub fn new_dmg() -> Self {
out.hl.wide_mut().0 = 0x000d; Self::default()
out.pc.0 = 0x0100; .with_af(0x0100 | Flags::new().with_z(true).into_bits() as u16)
out.sp.0 = 0xfffe; .with_bc(0x0013)
out .with_de(0x00d8)
.with_hl(0x014d)
.with_pc(0x0100)
.with_sp(0xfffe)
}
pub fn new_mgb() -> Self {
Self::default()
.with_af(0xff00 | Flags::new().with_z(true).into_bits() as u16)
.with_bc(0x0013)
.with_de(0x00d8)
.with_hl(0x014d)
.with_pc(0x0100)
.with_sp(0xfffe)
}
pub fn new_cgb() -> Self {
Self::default()
.with_af(0x1100 | Flags::new().with_z(true).into_bits() as u16)
.with_bc(0x0100)
.with_de(0xff56)
.with_hl(0x000d)
.with_pc(0x0100)
.with_sp(0xfffe)
}
pub fn with_pc(self, value: u16) -> Self {
Self { pc: Wrapping(value), ..self }
}
pub fn with_sp(self, value: u16) -> Self {
Self { sp: Wrapping(value), ..self }
}
pub fn with_af(self, value: u16) -> Self {
Self { af: SplitRegister::from(value), ..self }
}
pub fn with_bc(self, value: u16) -> Self {
Self { bc: SplitRegister::from(value), ..self }
}
pub fn with_de(self, value: u16) -> Self {
Self { de: SplitRegister::from(value), ..self }
}
pub fn with_hl(self, value: u16) -> Self {
Self { hl: SplitRegister::from(value), ..self }
} }
} }