From b5824122317031bbb7cfe1b90a88b450a31a42d7 Mon Sep 17 00:00:00 2001 From: Adrian Conlon <98398945+AdrianConlon@users.noreply.github.com> Date: Thu, 7 Mar 2024 08:31:28 +0000 Subject: [PATCH] RMW simplification --- M6502/inc/mos6502.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index bf7b506..c9acecc 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -176,20 +176,21 @@ namespace EightBit { #define FIXUP_RMW(ADDRESSING, OPERATION) \ { \ fixup(ADDRESSING()); \ - const auto result = OPERATION(memoryRead()); \ - memoryModifyWrite(result); \ + _RMW(OPERATION); \ } #define RMW(ADDRESSING, OPERATION) \ { \ - const auto result = OPERATION(memoryRead(ADDRESSING())); \ - memoryModifyWrite(result); \ + BUS().ADDRESS() = ADDRESSING(); \ + _RMW(OPERATION); \ } - void memoryModifyWrite(const uint8_t data) noexcept { - // The read will have already taken place... - memoryWrite(); - memoryWrite(data); +#define _RMW(OPERATION) \ + { \ + const auto data = memoryRead(); \ + const auto result = OPERATION(data); \ + memoryWrite(); \ + memoryWrite(result); \ } void maybe_fixup(register16_t address, uint8_t unfixed_page, bool always_fixup = false) noexcept {