-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrk.rs
35 lines (31 loc) · 1.01 KB
/
brk.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{ins::Instruction, mem::Addr};
use crate::cpu::CPU;
/// The BRK instruction forces the generation of an interrupt request. The program counter
/// and processor status are pushed on the stack then the IRQ interrupt vector at $FFFE/F
/// is loaded into the PC and the break flag in the status set to one.
pub struct BRK(pub Addr);
impl BRK {
fn set_flags(cpu: &mut CPU) {
// Set break command flag
cpu.flags.b = true;
}
}
impl Instruction for BRK {
fn execute(&self, cpu: &mut CPU) {
match self {
BRK(Addr::Implicit) => {
// TODO push the pc and processor status onto the stack. Check if the
// following is correct.
cpu.pc = 0xFFFE;
Self::set_flags(cpu);
},
_ => panic!("Addressing method not supported")
}
}
fn code(&self) -> crate::Byte {
match self {
BRK(Addr::Implicit) => 0x00,
_ => panic!("Operation not supported")
}
}
}