mirror of
https://github.com/mre/mos6502.git
synced 2024-09-27 19:56:34 +00:00
add/implement BRA instruction for CMOS
This commit is contained in:
parent
189cbde060
commit
ff5cf019fd
@ -322,6 +322,11 @@ impl<M: Bus, V: Variant> CPU<M, V> {
|
|||||||
self.branch_if_positive(addr);
|
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) => {
|
(Instruction::BRK, OpInput::UseImplied) => {
|
||||||
for b in self.registers.program_counter.wrapping_sub(1).to_be_bytes() {
|
for b in self.registers.program_counter.wrapping_sub(1).to_be_bytes() {
|
||||||
self.push_on_stack(b);
|
self.push_on_stack(b);
|
||||||
@ -1011,6 +1016,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) {
|
fn branch_if_positive(&mut self, addr: u16) {
|
||||||
if !self.registers.status.contains(Status::PS_NEGATIVE) {
|
if !self.registers.status.contains(Status::PS_NEGATIVE) {
|
||||||
self.registers.program_counter = addr;
|
self.registers.program_counter = addr;
|
||||||
|
@ -55,6 +55,7 @@ pub enum Instruction {
|
|||||||
BMI, // Branch if Minus............... | .. ..... PC = N
|
BMI, // Branch if Minus............... | .. ..... PC = N
|
||||||
BNE, // Branch if Not Equal........... | .. ..... PC = !Z
|
BNE, // Branch if Not Equal........... | .. ..... PC = !Z
|
||||||
BPL, // Branch if Positive............ | .. ..... PC = Z
|
BPL, // Branch if Positive............ | .. ..... PC = Z
|
||||||
|
BRA, // Unconditional BRAnch.......... | .. B.... S PC =
|
||||||
BRK, // BReaK......................... | .. B.... S PC =
|
BRK, // BReaK......................... | .. B.... S PC =
|
||||||
BVC, // Branch if oVerflow Clear...... | .. ..... PC = !V
|
BVC, // Branch if oVerflow Clear...... | .. ..... PC = !V
|
||||||
BVS, // Branch if oVerflow Set........ | .. ..... PC = V
|
BVS, // Branch if oVerflow Set........ | .. ..... PC = V
|
||||||
@ -495,6 +496,7 @@ impl crate::Variant for Cmos6502 {
|
|||||||
// TODO: We obviously need to add the other CMOS instructions here.
|
// TODO: We obviously need to add the other CMOS instructions here.
|
||||||
match opcode {
|
match opcode {
|
||||||
0x6c => Some((Instruction::JMP, AddressingMode::Indirect)),
|
0x6c => Some((Instruction::JMP, AddressingMode::Indirect)),
|
||||||
|
0x80 => Some((Instruction::BRA, AddressingMode::Relative)),
|
||||||
_ => Nmos6502::decode(opcode),
|
_ => Nmos6502::decode(opcode),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user