diff --git a/MC6809/inc/mc6809.h b/MC6809/inc/mc6809.h index 197143a..969920a 100644 --- a/MC6809/inc/mc6809.h +++ b/MC6809/inc/mc6809.h @@ -183,6 +183,7 @@ namespace EightBit { uint8_t clr(); void cmp(uint8_t operand, uint8_t data); void cmp(register16_t operand, register16_t data); + uint8_t com(uint8_t operand); uint8_t neg(uint8_t operand); register16_t m_d; diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index f107494..5a61141 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -148,6 +148,13 @@ int EightBit::mc6809::executeUnprefixed(uint8_t opcode) { case 0x60: addCycles(6); BUS().write(neg(AM_indexed_byte())); break; // NEG (indexed) case 0x70: addCycles(7); BUS().write(neg(AM_extended_byte())); break; // NEG (extended) + // COM + case 0x03: addCycles(6); BUS().write(com(AM_direct_byte())); break; // COM (COM direct) + case 0x43: addCycles(2); A() = com(A()); break; // COM (COMA inherent) + case 0x53: addCycles(2); B() = com(B()); break; // COM (COMB inherent) + case 0x63: addCycles(6); BUS().write(com(AM_indexed_byte())); break; // COM (COM indexed) + case 0x73: addCycles(7); BUS().write(com(AM_extended_byte())); break; // COM (COM extended) + default: UNREACHABLE; } @@ -434,3 +441,11 @@ void EightBit::mc6809::cmp(register16_t operand, register16_t data) { const uint32_t difference = operand.word - data.word; adjustSubtraction(operand.word, data.word, difference); } + +uint8_t EightBit::mc6809::com(uint8_t operand) { + const uint8_t result = ~operand; + adjustNZ(result); + clearFlag(CC(), VF); + setFlag(CC(), CF); + return result; +}