Refactor cpu constructor and fix tests

This commit is contained in:
Franco Colmenarez 2022-02-07 19:11:23 -05:00
parent 2ca1813939
commit ba4051bc14
2 changed files with 20 additions and 7 deletions

View File

@ -833,12 +833,22 @@ pub struct CPU {
}
impl CPU {
pub fn new(cgb_mode: bool) -> Self {
pub fn new() -> Self {
Self {
registers: match cgb_mode {
true => Registers::new_cgb(),
false => Registers::new(),
},
registers: Registers::new(),
cycles: Cycles(0),
last_op_cycles: Cycles(0),
exec_calls_count: 0,
is_halted: false,
ei_delay: false,
ime: true,
enable_logs: !env::var("CPU_LOG").is_err() || !env::var("CPU_LOGS").is_err(),
}
}
pub fn new_cgb() -> Self {
Self {
registers: Registers::new_cgb(),
cycles: Cycles(0),
last_op_cycles: Cycles(0),
exec_calls_count: 0,

View File

@ -17,10 +17,13 @@ pub struct Emulator {
impl Emulator {
pub fn new() -> Self {
let bus = Bus::new();
let cgb_mode = bus.cgb_mode;
let cpu = match bus.cgb_mode {
true => CPU::new_cgb(),
false => CPU::new(),
};
Self {
bus,
cpu: CPU::new(cgb_mode),
cpu,
}
}