From d0c376ba901d0d6f39ded6a6cad1beafec8f95ee Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 20 Nov 2014 18:34:07 -0500 Subject: [PATCH 1/4] Add inclusive_or_test(). --- src/machine.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index a9f3e01..130bbae 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1239,3 +1239,33 @@ fn exclusive_or_test() { } } } + +#[test] +fn inclusive_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.inclusive_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)); + } + } + } +} From 9c95ade3a3991b3efad1716a5ee3661fa4c700de Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 20 Nov 2014 18:45:52 -0500 Subject: [PATCH 2/4] Fix inclusive_or_test(). --- src/machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.rs b/src/machine.rs index 130bbae..ca21462 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1247,7 +1247,7 @@ fn inclusive_or_test() { for a_before in range(0u8, 255u8) { for val in range(0u8, 255u8) { machine.execute_instruction( - (instruction::LDA, instruction::UseImmediate(a_before)) + (Instruction::LDA, OpInput::UseImmediate(a_before)) ); machine.inclusive_or(val); From 8698dc17f963b8dc4ec95164c350f681254fb707 Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 20 Nov 2014 18:47:32 -0500 Subject: [PATCH 3/4] Add ORA to execute_instruction(). --- src/machine.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index ca21462..2780ecd 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -291,6 +291,14 @@ impl Machine { &mut self.registers.status); } + (Instruction::ORA, OpInput::UseImmediate(val)) => { + self.inclusive_or(val); + } + (Instruction::ORA, OpInput::UseAddress(addr)) => { + let val = self.memory.get_byte(addr); + self.inclusive_or(val); + } + (Instruction::PHA, OpInput::UseImplied) => { // Push accumulator let val = self.registers.accumulator as u8; From 4e75f50afd4343323d95f6749fec19e3128894e5 Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 20 Nov 2014 18:48:42 -0500 Subject: [PATCH 4/4] Add inclusive_or(). --- src/machine.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index 2780ecd..0462268 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -709,6 +709,11 @@ impl Machine { self.load_accumulator(a_after); } + fn inclusive_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);