chore(cpu): move RST behaviour to a method

This commit is contained in:
2021-04-07 23:05:03 -05:00
parent 0eb40a8109
commit cf3b79f0dc
2 changed files with 13 additions and 6 deletions

View File

@@ -1092,10 +1092,10 @@ impl Instruction {
}
Instruction::RST(n) => {
// RST n | Push current address onto the stack, jump to 0x0000 + n
let addr = cpu.register_pair(RegisterPair::PC);
Self::push(cpu, addr);
cpu.set_register_pair(RegisterPair::PC, n as u16);
Cycle::new(16)
// The same behaviour will occur when handling an interrupt so this code
// is relegated to a method
Self::reset(cpu, n)
}
Instruction::RLC(reg) => {
// RLC r[z] | Rotate register r[z] left
@@ -1614,6 +1614,13 @@ impl Instruction {
(lower << 4) | upper
}
pub fn reset(cpu: &mut Cpu, vector: u8) -> Cycle {
let addr = cpu.register_pair(RegisterPair::PC);
Self::push(cpu, addr);
cpu.set_register_pair(RegisterPair::PC, vector as u16);
Cycle::new(16)
}
}
impl Instruction {