From 95c526d957a8a5f5d7f48159e4ce83e1d5964a83 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 30 Nov 2022 16:21:35 -0500 Subject: [PATCH] Start arrangements for full extension words. --- .../Implementation/ExecutorImplementation.hpp | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index 1d129a354..a6aa656a4 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -201,14 +201,31 @@ template IntT Executor::State::read_pc() { template uint32_t Executor::State::index_8bitdisplacement() { - // TODO: if not a 68000, check bit 8 for whether this should be a full extension word; - // also include the scale field even if not. + // Get the brief extension word. const auto extension = read_pc(); + + // The 68000, 68080 and 68010 do not support the scale field, and are limited + // to brief extension words. + const int scale = model <= Model::M68010 ? 0 : (extension >> 9) & 3; + + // Decode brief instruction word fields. const auto offset = int8_t(extension); const int register_index = (extension >> 12) & 15; - const uint32_t displacement = registers[register_index].l; - const uint32_t sized_displacement = (extension & 0x800) ? displacement : int16_t(displacement); - return offset + sized_displacement; + + // The 68000, 68080 and 68010 support only brief extension words. + if(model <= Model::M68010 || !(extension & 0x100)) { + const uint32_t displacement = registers[register_index].l << scale; + const uint32_t sized_displacement = (extension & 0x800) ? displacement : int16_t(displacement); + return offset + sized_displacement; + } + + // Determine a long extension. + // + // Cf. https://edwardhalferty.com/2020/12/16/decoding-the-extended-addressing-modes-of-the-68000/ +// const bool has_base = extension & 0x80; +// const bool has_index = extension & 0x40; + + return 0; } template