BRK on CMOS clears the decimal flag

This commit is contained in:
Sam M W 2024-04-27 11:42:37 +01:00
parent cfb956f6a2
commit ecf222f80b
2 changed files with 14 additions and 0 deletions

View File

@ -326,6 +326,18 @@ impl<M: Bus, V: Variant> CPU<M, V> {
self.registers.status.or(Status::PS_DISABLE_INTERRUPTS);
}
(Instruction::BRKcld, OpInput::UseImplied) => {
for b in self.registers.program_counter.wrapping_sub(1).to_be_bytes() {
self.push_on_stack(b);
}
self.push_on_stack(self.registers.status.bits());
let pcl = self.memory.get_byte(0xfffe);
let pch = self.memory.get_byte(0xffff);
self.jump(((pch as u16) << 8) | pcl as u16);
self.registers.status.or(Status::PS_DISABLE_INTERRUPTS);
self.registers.status.and(!Status::PS_DECIMAL_MODE);
}
(Instruction::BVC, OpInput::UseRelative(rel)) => {
let addr = self.registers.program_counter.wrapping_add(rel);
self.branch_if_overflow_clear(addr);

View File

@ -57,6 +57,7 @@ pub enum Instruction {
BPL, // Branch if Positive............ | .. ..... PC = Z
BRA, // Unconditional BRAnch.......... | .. B.... S PC =
BRK, // BReaK......................... | .. B.... S PC =
BRKcld,// BReaK, clearing decimal flag.. | .. BD... S PC =
BVC, // Branch if oVerflow Clear...... | .. ..... PC = !V
BVS, // Branch if oVerflow Set........ | .. ..... PC = V
CLC, // CLear Carry flag.............. | .. ....C = 0
@ -495,6 +496,7 @@ impl crate::Variant for Cmos6502 {
fn decode(opcode: u8) -> Option<(Instruction, AddressingMode)> {
// TODO: We obviously need to add the other CMOS instructions here.
match opcode {
0x00 => Some((Instruction::BRKcld, AddressingMode::Implied)),
0x1a => Some((Instruction::INC, AddressingMode::Accumulator)),
0x3a => Some((Instruction::DEC, AddressingMode::Accumulator)),
0x6c => Some((Instruction::JMP, AddressingMode::Indirect)),