CPU constructor overhaul
This commit is contained in:
parent
358dfb832a
commit
184054349f
63
src/cpu.rs
63
src/cpu.rs
@ -81,14 +81,61 @@ impl CPU {
|
||||
///
|
||||
/// [CPU Registers]: https://gbdev.io/pandocs/Power_Up_Sequence.html#cpu-registers
|
||||
pub fn new() -> Self {
|
||||
let mut out = Self::default();
|
||||
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;
|
||||
out.hl.wide_mut().0 = 0x000d;
|
||||
out.pc.0 = 0x0100;
|
||||
out.sp.0 = 0xfffe;
|
||||
out
|
||||
Self::new_mgb()
|
||||
}
|
||||
|
||||
pub fn new_dmg() -> Self {
|
||||
Self::default()
|
||||
.with_af(0x0100 | 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_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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user