1
0
mirror of https://github.com/mre/mos6502.git synced 2024-12-22 12:29:31 +00:00

Merge pull request #26 from amw-zero/ark-beq

Implement BEQ instruction
This commit is contained in:
Andrew Keeton 2014-11-06 19:51:54 -05:00
commit a80c98b000

View File

@ -122,6 +122,12 @@ impl Machine {
self.branch_if_carry_set(addr); self.branch_if_carry_set(addr);
} }
(instruction::BEQ, instruction::UseRelative(rel)) => {
let addr = self.registers.program_counter
+ AddressDiff(rel as i32);
self.branch_if_equal(addr);
}
(instruction::BIT, instruction::UseAddress(addr)) => { (instruction::BIT, instruction::UseAddress(addr)) => {
let a: u8 = self.registers.accumulator as u8; let a: u8 = self.registers.accumulator as u8;
let m: u8 = self.memory.get_byte(addr); let m: u8 = self.memory.get_byte(addr);
@ -565,6 +571,12 @@ impl Machine {
} }
} }
fn branch_if_equal(&mut self, addr: Address) {
if self.registers.status.contains(PS_ZERO) {
self.registers.program_counter = addr;
}
}
fn branch_if_minus(&mut self, addr: Address) { fn branch_if_minus(&mut self, addr: Address) {
if self.registers.status.contains(PS_NEGATIVE) { if self.registers.status.contains(PS_NEGATIVE) {
self.registers.program_counter = addr; self.registers.program_counter = addr;
@ -910,6 +922,18 @@ fn branch_if_carry_set_test() {
assert_eq!(machine.registers.program_counter, Address(0xABCD)); assert_eq!(machine.registers.program_counter, Address(0xABCD));
} }
#[test]
fn branch_if_equal_test() {
let mut machine = Machine::new();
machine.branch_if_equal(Address(0xABCD));
assert_eq!(machine.registers.program_counter, Address(0));
machine.registers.status.or(PS_ZERO);
machine.branch_if_equal(Address(0xABCD));
assert_eq!(machine.registers.program_counter, Address(0xABCD));
}
#[test] #[test]
fn branch_if_minus_test() { fn branch_if_minus_test() {
{ {