mirror of
https://github.com/mre/mos6502.git
synced 2025-01-03 15:30:32 +00:00
commit
d42922a788
@ -116,6 +116,11 @@ impl Machine {
|
||||
self.branch_if_carry_clear(addr);
|
||||
}
|
||||
|
||||
(instruction::BCS, instruction::UseRelative(rel)) => {
|
||||
let addr = self.registers.program_counter
|
||||
+ AddressDiff(rel as i32);
|
||||
self.branch_if_carry_set(addr);
|
||||
}
|
||||
|
||||
(instruction::BIT, instruction::UseAddress(addr)) => {
|
||||
let a: u8 = self.registers.accumulator as u8;
|
||||
@ -554,6 +559,12 @@ impl Machine {
|
||||
}
|
||||
}
|
||||
|
||||
fn branch_if_carry_set(&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;
|
||||
@ -886,6 +897,19 @@ fn branch_if_carry_clear_test() {
|
||||
assert_eq!(machine.registers.program_counter, Address(0xABCD));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn branch_if_carry_set_test() {
|
||||
let mut machine = Machine::new();
|
||||
|
||||
machine.execute_instruction((instruction::CLC, instruction::UseImplied));
|
||||
machine.branch_if_carry_set(Address(0xABCD));
|
||||
assert_eq!(machine.registers.program_counter, Address(0));
|
||||
|
||||
machine.execute_instruction((instruction::SEC, instruction::UseImplied));
|
||||
machine.branch_if_carry_set(Address(0xABCD));
|
||||
assert_eq!(machine.registers.program_counter, Address(0xABCD));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn branch_if_minus_test() {
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user