From 67462c2f92c80bf366fc1d3529eabd7ddff5082b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 5 May 2022 12:27:36 -0400 Subject: [PATCH] Rewire MOVEP. --- InstructionSets/M68k/Executor.hpp | 3 +- .../Implementation/ExecutorImplementation.hpp | 62 ++++++++++--------- .../Implementation/PerformImplementation.hpp | 12 +--- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/InstructionSets/M68k/Executor.hpp b/InstructionSets/M68k/Executor.hpp index 2b122e135..60ce8e9a5 100644 --- a/InstructionSets/M68k/Executor.hpp +++ b/InstructionSets/M68k/Executor.hpp @@ -50,8 +50,7 @@ template class Executor { void jsr(uint32_t offset); void link(uint32_t &address, uint32_t offset); void unlink(uint32_t &address); - template void movep_fromR(uint32_t reg, uint32_t address); - template void movep_toR(uint32_t ®, uint32_t address); + template void movep(Preinstruction instruction, uint32_t source, uint32_t dest); // TODO: ownership of this shouldn't be here. struct Registers { diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index 49d34d6b5..71eeb68ad 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -395,38 +395,44 @@ void Executor::unlink(uint32_t &address) { template template -void Executor::movep_fromR(uint32_t reg, uint32_t address) { - if constexpr (sizeof(IntT) == 4) { - bus_handler_.template write(address, uint8_t(reg >> 24)); +void Executor::movep(Preinstruction instruction, uint32_t source, uint32_t dest) { + if(instruction.mode<0>() == AddressingMode::DataRegisterDirect) { + const uint32_t reg = source; + uint32_t address = dest; + + // Move register to memory. + if constexpr (sizeof(IntT) == 4) { + bus_handler_.template write(address, uint8_t(reg >> 24)); + address += 2; + + bus_handler_.template write(address, uint8_t(reg >> 16)); + address += 2; + } + + bus_handler_.template write(address, uint8_t(reg >> 8)); address += 2; - bus_handler_.template write(address, uint8_t(reg >> 16)); - address += 2; - } - - bus_handler_.template write(address, uint8_t(reg >> 8)); - address += 2; - - bus_handler_.template write(address, uint8_t(reg)); -} - -template -template -void Executor::movep_toR(uint32_t ®, uint32_t address) { - if constexpr (sizeof(IntT) == 4) { - reg = bus_handler_.template read(address) << 24; - address += 2; - - reg |= bus_handler_.template read(address) << 26; - address += 2; + bus_handler_.template write(address, uint8_t(reg)); } else { - reg &= 0xffff0000; + // Move memory to register. + uint32_t ® = data_[instruction.reg<1>()].l; + uint32_t address = source; + + if constexpr (sizeof(IntT) == 4) { + reg = bus_handler_.template read(address) << 24; + address += 2; + + reg |= bus_handler_.template read(address) << 26; + address += 2; + } else { + reg &= 0xffff0000; + } + + reg |= bus_handler_.template read(address) << 8; + address += 2; + + reg |= bus_handler_.template read(address); } - - reg |= bus_handler_.template read(address) << 8; - address += 2; - - reg |= bus_handler_.template read(address); } } diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index f151393c2..b4a435469 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -1177,19 +1177,11 @@ template < #undef set_neg_zero case Operation::MOVEPl: - if(instruction.mode<0>() == AddressingMode::DataRegisterDirect) { - flow_controller.template movep_fromR(src.l, dest.l); - } else { - flow_controller.template movep_toR(src.l, dest.l); - } + flow_controller.template movep(instruction, src.l, dest.l); break; case Operation::MOVEPw: - if(instruction.mode<0>() == AddressingMode::DataRegisterDirect) { - flow_controller.template movep_fromR(src.l, dest.l); - } else { - flow_controller.template movep_toR(src.l, dest.l); - } + flow_controller.template movep(instruction, src.l, dest.l); break; /*