From ecb3f0745952819d7b0351821496be508180c07c Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 6 Nov 2014 19:30:05 -0500 Subject: [PATCH 1/3] Add branch_if_carry_clear_test(). --- src/machine.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index e95411d..6175778 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -860,6 +860,19 @@ fn jump_test() { assert_eq!(machine.registers.program_counter, addr); } +#[test] +fn branch_if_carry_clear_test() { + let mut machine = Machine::new(); + + machine.execute_instruction((instruction::SEC, instruction::UseImplied)); + machine.branch_if_carry_clear(Address(0xABCD)); + assert_eq!(machine.registers.program_counter, Address(0)); + + machine.execute_instruction((instruction::CLC, instruction::UseImplied)); + machine.branch_if_carry_clear(Address(0xABCD)); + assert_eq!(machine.registers.program_counter, Address(0xABCD)); +} + #[test] fn branch_if_minus_test() { { From be7539d6c92f7d9a2d1b62e8bc9f2bd9687656c9 Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 6 Nov 2014 19:32:15 -0500 Subject: [PATCH 2/3] Add branch_if_carry_clear(). --- src/machine.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index 6175778..73f5596 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -541,6 +541,12 @@ impl Machine { self.registers.program_counter = addr; } + fn branch_if_carry_clear(&mut self, addr: Address) { + if !self.registers.status.contains(PS_CARRY) { + self.registers.program_counter = addr; + } + } + fn branch_if_minus(&mut self, addr: Address) { if self.registers.status.contains(PS_NEGATIVE) { self.registers.program_counter = addr; From 7a4515b375e7dfdbd96684e5d65499d62d954879 Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 6 Nov 2014 19:35:07 -0500 Subject: [PATCH 3/3] Add BCC to execute_instruction. --- src/machine.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index 73f5596..357b01b 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -110,6 +110,13 @@ impl Machine { &mut self.registers.status); } + (instruction::BCC, instruction::UseRelative(rel)) => { + let addr = self.registers.program_counter + + AddressDiff(rel as i32); + self.branch_if_carry_clear(addr); + } + + (instruction::BIT, instruction::UseAddress(addr)) => { let a: u8 = self.registers.accumulator as u8; let m: u8 = self.memory.get_byte(addr);