XBA instruction

This commit is contained in:
2022-12-05 17:44:26 -05:00
parent 2440723263
commit 296500cc8e
2 changed files with 26 additions and 0 deletions
+4
View File
@@ -380,6 +380,10 @@ impl CPU {
pub fn increment_cycles_transfer(&mut self) { pub fn increment_cycles_transfer(&mut self) {
self.registers.increment_pc(1); self.cycles += 2; self.registers.increment_pc(1); self.cycles += 2;
} }
pub fn increment_cycles_xba(&mut self) {
self.registers.increment_pc(1); self.cycles += 3;
}
} }
#[cfg(test)] #[cfg(test)]
+22
View File
@@ -1002,6 +1002,13 @@ impl CPU {
self.increment_cycles_transfer(); self.increment_cycles_transfer();
} }
fn xba(&mut self) {
self.registers.a = (self.registers.a << 8) | (self.registers.a >> 8);
self.registers.set_negative_flag(((self.registers.a as u8) >> 7) == 1);
self.registers.set_zero_flag((self.registers.a as u8) == 0);
self.increment_cycles_xba();
}
pub fn execute_opcode(&mut self, opcode: u8, bus: &mut Bus) { pub fn execute_opcode(&mut self, opcode: u8, bus: &mut Bus) {
type A = AddressingMode; type A = AddressingMode;
type I = IndexRegister; type I = IndexRegister;
@@ -1345,6 +1352,10 @@ impl CPU {
0xCB => unimplemented!("WAI instruction not implemented yet"), 0xCB => unimplemented!("WAI instruction not implemented yet"),
// WDM // WDM
0x42 => unimplemented!("WDM instruction not implemented yet"), 0x42 => unimplemented!("WDM instruction not implemented yet"),
// XBA
0xEB => self.xba(),
// XCE
0xFB => unimplemented!("XCE instruction not implemented yet"),
_ => println!("Invalid opcode: {:02X}", opcode), _ => println!("Invalid opcode: {:02X}", opcode),
} }
} }
@@ -2765,4 +2776,15 @@ mod cpu_instructions_tests {
assert_eq!(cpu.registers.pc, 0x0001); assert_eq!(cpu.registers.pc, 0x0001);
assert_eq!(cpu.cycles, 2); assert_eq!(cpu.cycles, 2);
} }
#[test]
fn test_xba() {
let mut cpu = CPU::new();
cpu.registers.pc = 0x0000;
cpu.registers.a = 0x11FF;
cpu.xba();
assert_eq!(cpu.registers.a, 0xFF11);
assert_eq!(cpu.registers.pc, 0x0001);
assert_eq!(cpu.cycles, 3);
}
} }