implement HALT
This commit is contained in:
parent
89370fd077
commit
122bfee8df
|
@ -29,6 +29,7 @@ pub struct CPU {
|
|||
pub last_instruction_addr: u16,
|
||||
pub window: Window,
|
||||
pub gpu: GPU,
|
||||
halted: bool,
|
||||
}
|
||||
|
||||
// Hz
|
||||
|
@ -45,10 +46,19 @@ impl CPU {
|
|||
last_instruction_addr: 0x0,
|
||||
window,
|
||||
gpu: GPU::default(),
|
||||
halted: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exec_next(&mut self) {
|
||||
let interrupt_cycles = self.handle_interrupts();
|
||||
self.increment_timers(interrupt_cycles);
|
||||
|
||||
if self.halted {
|
||||
self.increment_timers(1);
|
||||
return;
|
||||
}
|
||||
|
||||
self.last_instruction_addr = self.reg.pc;
|
||||
let opcode = self.next_opcode();
|
||||
self.last_instruction = opcode;
|
||||
|
@ -69,9 +79,6 @@ impl CPU {
|
|||
let cycles = self.run_opcode(opcode);
|
||||
self.memory.user_mode = false;
|
||||
self.increment_timers(cycles);
|
||||
|
||||
let interrupt_cycles = self.handle_interrupts();
|
||||
self.increment_timers(interrupt_cycles);
|
||||
}
|
||||
|
||||
fn increment_timers(&mut self, cycles: u8) {
|
||||
|
@ -149,6 +156,7 @@ impl CPU {
|
|||
}
|
||||
|
||||
fn service_interrupt(&mut self, addr: u16) {
|
||||
self.halted = false;
|
||||
self.push(self.reg.pc);
|
||||
self.reg.pc = addr;
|
||||
self.memory.ime = false;
|
||||
|
|
|
@ -552,7 +552,8 @@ impl CPU {
|
|||
2
|
||||
}
|
||||
0x76 => {
|
||||
panic!("halt")
|
||||
self.halted = true;
|
||||
1
|
||||
}
|
||||
0x77 => {
|
||||
self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A));
|
||||
|
|
Loading…
Reference in a new issue