-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtxa.rs
More file actions
36 lines (32 loc) · 976 Bytes
/
txa.rs
File metadata and controls
36 lines (32 loc) · 976 Bytes
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
36
use crate::{cpu::CPU, ins::Instruction, mem::Addr};
use crate::Byte;
/// Transfer X to Accumulator - Copies the current contents of the X register into the
/// accumulator and sets the zero and negative flags as appropriate.
pub struct TXA(pub Addr);
impl TXA {
fn set_flags(cpu: &mut CPU) {
// Set zero flag if A = 0
cpu.flags.z = cpu.reg.acc == 0;
// Set negative flag if bit 7 of A is set
cpu.flags.n = (cpu.reg.acc & 0b10000000) > 0;
}
}
impl Instruction for TXA {
fn execute(&self, cpu: &mut CPU) {
match self {
// 1B, 2C
TXA(Addr::Implicit) => {
cpu.reg.acc = cpu.reg.x;
cpu.pc += 1;
},
_ => panic!("Operation not supported!")
}
Self::set_flags(cpu);
}
fn code(&self) -> Byte {
match self {
TXA(Addr::Implicit) => 0x8A,
_ => panic!("Operation not supported!")
}
}
}