diff --git a/Core/Cpu.Instructions.cpp b/Core/Cpu.Instructions.cpp index 0be6b51..86d866e 100644 --- a/Core/Cpu.Instructions.cpp +++ b/Core/Cpu.Instructions.cpp @@ -799,9 +799,9 @@ void Cpu::STZ() /******************* Bit test operations ********************/ -template void Cpu::TestBits(T value) +template void Cpu::TestBits(T value, bool alterZeroFlagOnly) { - if(_instAddrMode <= AddrMode::ImmM) { + if(alterZeroFlagOnly) { //"Immediate addressing only affects the z flag (with the result of the bitwise And), but does not affect the n and v flags." if(((T)_state.A & value) == 0) { SetFlags(ProcFlags::Zero); @@ -827,20 +827,44 @@ template void Cpu::TestBits(T value) void Cpu::BIT() { if(CheckFlag(ProcFlags::MemoryMode8)) { - TestBits(GetByteValue()); + TestBits(GetByteValue(), _instAddrMode <= AddrMode::ImmM); } else { - TestBits(GetWordValue()); + TestBits(GetWordValue(), _instAddrMode <= AddrMode::ImmM); } } void Cpu::TRB() { - //TODO + if(CheckFlag(ProcFlags::MemoryMode8)) { + TestBits(GetByteValue(), true); + + uint8_t value = ReadData(_operand); + value &= ~_state.A; + Write(_operand, value); + } else { + TestBits(GetWordValue(), true); + + uint16_t value = ReadDataWord(_operand); + value &= ~_state.A; + WriteWord(_operand, value); + } } void Cpu::TSB() { - //TODO + if(CheckFlag(ProcFlags::MemoryMode8)) { + TestBits(GetByteValue(), true); + + uint8_t value = ReadData(_operand); + value |= _state.A; + Write(_operand, value); + } else { + TestBits(GetWordValue(), true); + + uint16_t value = ReadDataWord(_operand); + value |= _state.A; + WriteWord(_operand, value); + } } /****************** diff --git a/Core/Cpu.h b/Core/Cpu.h index 5ebcfbf..387d7f9 100644 --- a/Core/Cpu.h +++ b/Core/Cpu.h @@ -205,7 +205,7 @@ private: void STZ(); //Test bits - template void TestBits(T value); + template void TestBits(T value, bool alterZeroFlagOnly); void BIT(); void TRB();