This commit is contained in:
Sam M W 2024-04-27 14:04:54 +01:00
parent 2a2ab1eadd
commit 453735ba5e
2 changed files with 42 additions and 0 deletions

View File

@ -653,6 +653,38 @@ impl<M: Bus, V: Variant> CPU<M, V> {
let val = self.registers.accumulator;
self.load_y_register(val);
}
(Instruction::TRB, OpInput::UseAddress(addr)) => {
let val = self.memory.get_byte(addr);
// The zero flag is set based on the result of the 'and'.
self.registers.status.set_with_mask(
Status::PS_ZERO,
Status::new(StatusArgs {
zero: 0 == (self.registers.accumulator & val),
..StatusArgs::none()
}),
);
// The 1's in the accumulator set the corresponding bits in the operand
let res = self.registers.accumulator | val;
self.memory.set_byte(addr, res);
}
(Instruction::TSB, OpInput::UseAddress(addr)) => {
let val = self.memory.get_byte(addr);
// The zero flag is set based on the result of the 'and'.
self.registers.status.set_with_mask(
Status::PS_ZERO,
Status::new(StatusArgs {
zero: 0 == (self.registers.accumulator & val),
..StatusArgs::none()
}),
);
// The 1's in the accumulator clear the corresponding bits in the operand
let res = (self.registers.accumulator ^ 0xff) & val;
self.memory.set_byte(addr, res);
}
(Instruction::TSX, OpInput::UseImplied) => {
let StackPointer(val) = self.registers.stack_pointer;
self.load_x_register(val);

View File

@ -210,6 +210,12 @@ pub enum Instruction {
// Transfer Accumulator to Y
TAY,
// Test and Reset Bits
TRB,
// Test and Set Bits
TSB,
// Transfer Stack pointer to X
TSX,
@ -623,6 +629,10 @@ impl crate::Variant for Cmos6502 {
0xfa => Some((Instruction::PLX, AddressingMode::Implied)),
0x5a => Some((Instruction::PHY, AddressingMode::Implied)),
0xda => Some((Instruction::PHX, AddressingMode::Implied)),
0x04 => Some((Instruction::TSB, AddressingMode::ZeroPage)),
0x14 => Some((Instruction::TRB, AddressingMode::ZeroPage)),
0x0c => Some((Instruction::TSB, AddressingMode::Absolute)),
0x1c => Some((Instruction::TRB, AddressingMode::Absolute)),
_ => Nmos6502::decode(opcode),
}
}