diff --git a/src/cpu.rs b/src/cpu.rs index b45b0aa..ae6e4e2 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -32,7 +32,6 @@ pub struct CPU { ime_flag: bool, /// 0 if nothing to do, 2 if ime needs to be set after next instruction, 1 if ime needs to be set after this instruction enable_ime: i32, - low_power_mode: bool, last_execution_time: std::time::Instant, cycles: u64, } @@ -48,7 +47,6 @@ impl CPU { last_step_result: InstructionResult::default(), enable_ime: 0, ime_flag: false, - low_power_mode: false, last_execution_time: std::time::Instant::now(), cycles: 0, } diff --git a/src/cpu/instructions/misc.rs b/src/cpu/instructions/misc.rs index ad1db1a..975b175 100644 --- a/src/cpu/instructions/misc.rs +++ b/src/cpu/instructions/misc.rs @@ -157,21 +157,38 @@ impl CPU { } pub fn halt(&mut self) -> InstructionResult { - self.low_power_mode = true; - - // Halt bug implementieren oder nicht? - if self.ime_flag {} - //bug einfügen - if self.interrupt_pentding() {} - InstructionResult { - cycles: 0, - bytes: 1, - condition_codes: ConditionCodes { - zero: FlagState::NotAffected, - subtract: FlagState::NotAffected, - half_carry: FlagState::NotAffected, - carry: FlagState::NotAffected, - }, + // Halt bug ist noch nicht implementiert. Bug tritt nicht und wird auch nicht behoben. + if self.ime_flag { + if self.check_and_handle_interrupts(){ + InstructionResult{ + bytes: 1, + cycles: 0, + condition_codes: ConditionCodes{ + carry: FlagState::NotAffected, + half_carry: FlagState::NotAffected, + subtract: FlagState::NotAffected, + zero: FlagState::NotAffected, + } + } + } + else{ + InstructionResult::default() + } + } + else if self.interrupt_pentding(){ + InstructionResult{ + bytes: 1, + cycles: 0, + condition_codes: ConditionCodes{ + carry: FlagState::NotAffected, + half_carry: FlagState::NotAffected, + subtract: FlagState::NotAffected, + zero: FlagState::NotAffected, + } + } + } + else{ + InstructionResult::default() } } }