-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpla.rs
31 lines (28 loc) · 940 Bytes
/
pla.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
use crate::{cpu::CPU, ins::Instruction, mem::Addr};
use crate::Byte;
/// Pull Accumulator - Pops the topmost byte from the stack and stores it in the
/// accumulator.
pub struct PLA(pub Addr);
impl Instruction for PLA {
fn execute(&self, cpu: &mut CPU) {
match self {
// 1B, 4C
PLA(Addr::Implicit) => {
// TODO handle overflow case (when stack is empty)
// Read the value at the top of the stack
cpu.reg.acc = cpu.read_byte(CPU::stack_address(cpu.sp + 1));
// Increment stack pointer (POP)
cpu.sp += 1;
// Increment program counter
cpu.pc += 1;
},
_ => panic!("Operation not supported!")
}
}
fn code(&self) -> Byte {
match self {
PLA(Addr::Implicit) => 0x68,
_ => panic!("Operation not supported!")
}
}
}