1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-25 02:33:26 +00:00

Merge pull request #28 from amw-zero/ark-bvc

Implement BVC instruction
This commit is contained in:
Andrew Keeton 2014-11-13 18:45:05 -05:00
commit 5e0d4c68cc

View File

@ -163,6 +163,12 @@ impl Machine {
self.branch_if_positive(addr);
}
(instruction::BVC, instruction::UseRelative(rel)) => {
let addr = self.registers.program_counter
+ AddressDiff(rel as i32);
self.branch_if_overflow_clear(addr);
}
(instruction::CLC, instruction::UseImplied) => {
self.registers.status.and(!PS_CARRY);
}
@ -595,6 +601,12 @@ impl Machine {
}
}
fn branch_if_overflow_clear(&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);
@ -981,3 +993,16 @@ fn branch_if_positive_test() {
machine.branch_if_positive(Address(0xABCD));
assert_eq!(machine.registers.program_counter, Address(0xABCD));
}
#[test]
fn branch_if_overflow_clear_test() {
let mut machine = Machine::new();
machine.registers.status.insert(PS_OVERFLOW);
machine.branch_if_overflow_clear(Address(0xABCD));
assert_eq!(machine.registers.program_counter, Address(0));
machine.registers.status.remove(PS_OVERFLOW);
machine.branch_if_overflow_clear(Address(0xABCD));
assert_eq!(machine.registers.program_counter, Address(0xABCD));
}