From 49012a21c8570ac882c658595c37a96bda557959 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 9 Oct 2024 21:50:03 -0400 Subject: [PATCH] Convert `index` macro. --- InstructionSets/M50740/Executor.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/InstructionSets/M50740/Executor.cpp b/InstructionSets/M50740/Executor.cpp index 2f006c1b1..ee3bbff33 100644 --- a/InstructionSets/M50740/Executor.cpp +++ b/InstructionSets/M50740/Executor.cpp @@ -553,6 +553,16 @@ template void Executor::perform(uint8_t *operand [[maybe_u carry_flag_ = (~temp16 >> 8)&1; }; + const auto index = [&](auto op) { + if(index_mode_) { + uint8_t t = read(x_); + op(t); + write(x_, t); + } else { + op(a_); + } + }; + switch(operation) { case Operation::LDA: if(index_mode_) { @@ -684,36 +694,25 @@ template void Executor::perform(uint8_t *operand [[maybe_u Operations affected by the index mode flag: ADC, AND, CMP, EOR, LDA, ORA, and SBC. */ -#define index(op) \ - if(index_mode_) { \ - uint8_t t = read(x_); \ - op(t); \ - write(x_, t); \ - } else { \ - op(a_); \ - } - case Operation::ORA: { - const auto op_ora = [&](uint8_t x) { + const auto op_ora = [&](uint8_t &x) { set_nz(x |= *operand); }; index(op_ora); } break; case Operation::AND: { - const auto op_and = [&](uint8_t x) { + const auto op_and = [&](uint8_t &x) { set_nz(x &= *operand); }; index(op_and); } break; case Operation::EOR: { - const auto op_eor = [&](uint8_t x) { + const auto op_eor = [&](uint8_t &x) { set_nz(x ^= *operand); }; index(op_eor); } break; -#undef index - case Operation::CMP: if(index_mode_) { op_cmp(read(x_));