mirror of
https://github.com/mre/mos6502.git
synced 2024-11-25 02:33:26 +00:00
commit
8c0e4949a9
@ -110,6 +110,13 @@ impl Machine {
|
|||||||
&mut self.registers.status);
|
&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)) => {
|
(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);
|
||||||
@ -541,6 +548,12 @@ impl Machine {
|
|||||||
self.registers.program_counter = addr;
|
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) {
|
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;
|
||||||
@ -860,6 +873,19 @@ fn jump_test() {
|
|||||||
assert_eq!(machine.registers.program_counter, addr);
|
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]
|
#[test]
|
||||||
fn branch_if_minus_test() {
|
fn branch_if_minus_test() {
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user