add/implement BRA instruction for CMOS

This commit is contained in:
Sam M W 2024-04-24 12:16:27 +01:00
parent 309ad50374
commit df51b077e7
2 changed files with 11 additions and 0 deletions

View File

@ -310,6 +310,11 @@ impl<M: Bus, V: Variant> CPU<M, V> {
self.branch_if_positive(addr);
}
(Instruction::BRA, OpInput::UseRelative(rel)) => {
let addr = self.registers.program_counter.wrapping_add(rel);
self.branch(addr);
}
(Instruction::BRK, OpInput::UseImplied) => {
for b in self.registers.program_counter.wrapping_sub(1).to_be_bytes() {
self.push_on_stack(b);
@ -1007,6 +1012,10 @@ impl<M: Bus, V: Variant> CPU<M, V> {
}
}
fn branch(&mut self, addr: u16) {
self.registers.program_counter = addr;
}
fn branch_if_positive(&mut self, addr: u16) {
if !self.registers.status.contains(Status::PS_NEGATIVE) {
self.registers.program_counter = addr;

View File

@ -55,6 +55,7 @@ pub enum Instruction {
BMI, // Branch if Minus............... | .. ..... PC = N
BNE, // Branch if Not Equal........... | .. ..... PC = !Z
BPL, // Branch if Positive............ | .. ..... PC = Z
BRA, // Unconditional BRAnch.......... | .. B.... S PC =
BRK, // BReaK......................... | .. B.... S PC =
BVC, // Branch if oVerflow Clear...... | .. ..... PC = !V
BVS, // Branch if oVerflow Set........ | .. ..... PC = V
@ -490,6 +491,7 @@ impl crate::Variant for Cmos6502 {
// TODO: We obviously need to add the other CMOS instructions here.
match opcode {
0x6c => Some((Instruction::JMP, AddressingMode::Indirect)),
0x80 => Some((Instruction::BRA, AddressingMode::Relative)),
_ => Nmos6502::decode(opcode),
}
}