From fab7ff5cf0e90f44b7cb3f96c08cfb61abd2a1be Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Sun, 16 Nov 2014 21:11:22 -0500 Subject: [PATCH 1/3] Add exclusive_or_test(). --- src/machine.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index e85837e..159206f 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1194,4 +1194,34 @@ fn compare_with_y_register_test() { }, instruction::LDY ); +} + +#[test] +fn exclusive_or_test() { + let mut machine = Machine::new(); + + for a_before in range(0u8, 255u8) { + for val in range(0u8, 255u8) { + machine.execute_instruction( + (instruction::LDA, instruction::UseImmediate(a_before)) + ); + + machine.exclusive_or(val); + + let a_after = a_before ^ val; + assert_eq!(machine.registers.accumulator, a_after as i8); + + if a_after == 0 { + assert!(machine.registers.status.contains(PS_ZERO)); + } else { + assert!(!machine.registers.status.contains(PS_ZERO)); + } + + if (a_after as i8) < 0 { + assert!(machine.registers.status.contains(PS_NEGATIVE)); + } else { + assert!(!machine.registers.status.contains(PS_NEGATIVE)); + } + } + } } \ No newline at end of file From e4acd0575d6d9f01be6b174d0967aeea7b6be783 Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Sun, 16 Nov 2014 21:14:23 -0500 Subject: [PATCH 2/3] Add EOR to execute_instruction(). --- src/machine.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index 159206f..8b23bbf 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -220,6 +220,14 @@ impl Machine { self.dec_x(); } + (instruction::EOR, instruction::UseImmediate(val)) => { + self.exclusive_or(val); + } + (instruction::EOR, instruction::UseAddress(addr)) => { + let val = self.memory.get_byte(addr); + self.exclusive_or(val); + } + (instruction::INC, instruction::UseAddress(addr)) => { let m = self.memory.get_byte(addr); let m = m + 1; From b7cc5cd2348748c277fdbd732cdb38ba37291755 Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Sun, 16 Nov 2014 21:20:42 -0500 Subject: [PATCH 3/3] Add exclusive_or(). --- src/machine.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index 8b23bbf..94d2c24 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -696,6 +696,11 @@ impl Machine { self.compare(y, val); } + fn exclusive_or(&mut self, val: u8) { + let a_after = self.registers.accumulator ^ (val as i8); + self.load_accumulator(a_after); + } + fn push_on_stack(&mut self, val: u8) { let addr = self.registers.stack_pointer.to_address(); self.memory.set_byte(addr, val);