From a5534ac375c171d86e0170ad777a11b8a6b8859d Mon Sep 17 00:00:00 2001 From: Johannes Muenzel Date: Sat, 25 Oct 2014 19:04:52 -0400 Subject: [PATCH] Implement transfer instructions. --- src/machine.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/machine.rs b/src/machine.rs index d63d494..7229413 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -31,7 +31,7 @@ use address::{Address, AddressDiff}; use instruction; use instruction::{DecodedInstr}; use memory::Memory; -use registers::{ Registers, Status, StatusArgs }; +use registers::{ Registers, StackPointer, Status, StatusArgs }; use registers::{ PS_NEGATIVE, PS_OVERFLOW, PS_ZERO, PS_CARRY }; pub struct Machine { @@ -146,6 +146,35 @@ impl Machine { self.memory.set_byte(addr, self.registers.index_y as u8); }, + (instruction::TAX, instruction::UseImplied) => { + let val = self.registers.accumulator; + self.load_x_register(val); + }, + (instruction::TAY, instruction::UseImplied) => { + let val = self.registers.accumulator; + self.load_y_register(val); + }, + (instruction::TSX, instruction::UseImplied) => { + let StackPointer(val) = self.registers.stack_pointer; + let val = val as i8; + self.load_x_register(val); + }, + (instruction::TXA, instruction::UseImplied) => { + let val = self.registers.index_x; + self.load_accumulator(val); + }, + (instruction::TXS, instruction::UseImplied) => { + // Note that this is the only 'transfer' instruction that does + // NOT set the zero and negative flags. (Because the target + // is the stack pointer) + let val = self.registers.index_x; + self.registers.stack_pointer = StackPointer(val as u8); + }, + (instruction::TYA, instruction::UseImplied) => { + let val = self.registers.index_y; + self.load_accumulator(val); + }, + (instruction::NOP, _) => { debug!("nop instr"); },