From c00e170285ba74ca3972ef0268367de69e52bade Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 13 Nov 2014 18:49:43 -0500 Subject: [PATCH 1/3] Add branch_if_overflow_set_test(). --- src/machine.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index f1d907c..d386478 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1006,3 +1006,15 @@ fn branch_if_overflow_clear_test() { machine.branch_if_overflow_clear(Address(0xABCD)); assert_eq!(machine.registers.program_counter, Address(0xABCD)); } + +#[test] +fn branch_if_overflow_set_test() { + let mut machine = Machine::new(); + + machine.branch_if_overflow_set(Address(0xABCD)); + assert_eq!(machine.registers.program_counter, Address(0)); + + machine.registers.status.insert(PS_OVERFLOW); + machine.branch_if_overflow_set(Address(0xABCD)); + assert_eq!(machine.registers.program_counter, Address(0xABCD)); +} From 7e0a086a1dcedf1a22b4e9a8002314728484e21b Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 13 Nov 2014 18:50:55 -0500 Subject: [PATCH 2/3] Add branch_if_overflow_set(). --- src/machine.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index d386478..cc12882 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -607,6 +607,12 @@ impl Machine { } } + fn branch_if_overflow_set(&mut self, addr: Address) { + if self.registers.status.contains(PS_OVERFLOW) { + self.registers.program_counter = addr; + } + } + fn push_on_stack(&mut self, val: u8) { let addr = self.registers.stack_pointer.to_address(); self.memory.set_byte(addr, val); From 448fc3f0610ca21eb82182da463e3e451a34a66a Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 13 Nov 2014 18:52:14 -0500 Subject: [PATCH 3/3] Add BVC to execute_instruction(). --- src/machine.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index cc12882..e36093c 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -169,6 +169,12 @@ impl Machine { self.branch_if_overflow_clear(addr); } + (instruction::BVS, instruction::UseRelative(rel)) => { + let addr = self.registers.program_counter + + AddressDiff(rel as i32); + self.branch_if_overflow_set(addr); + } + (instruction::CLC, instruction::UseImplied) => { self.registers.status.and(!PS_CARRY); }