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

Merge pull request #27 from amw-zero/ark-bpl

Implement BPL instruction
This commit is contained in:
Andrew Keeton 2014-11-06 20:05:40 -05:00
commit b57a946f6a

View File

@ -157,6 +157,12 @@ impl Machine {
self.branch_if_minus(addr);
}
(instruction::BPL, instruction::UseRelative(rel)) => {
let addr = self.registers.program_counter
+ AddressDiff(rel as i32);
self.branch_if_positive(addr);
}
(instruction::CLC, instruction::UseImplied) => {
self.registers.status.and(!PS_CARRY);
}
@ -583,6 +589,12 @@ impl Machine {
}
}
fn branch_if_positive(&mut self, addr: Address) {
if !self.registers.status.contains(PS_NEGATIVE) {
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);
@ -956,3 +968,16 @@ fn branch_if_minus_test() {
assert_eq!(machine.registers.program_counter, Address(0xABCD));
}
}
#[test]
fn branch_if_positive_test() {
let mut machine = Machine::new();
machine.registers.status.insert(PS_NEGATIVE);
machine.branch_if_positive(Address(0xABCD));
assert_eq!(machine.registers.program_counter, Address(0));
machine.registers.status.remove(PS_NEGATIVE);
machine.branch_if_positive(Address(0xABCD));
assert_eq!(machine.registers.program_counter, Address(0xABCD));
}