1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-15 05:31:30 +00:00

Reduce repetition.

This commit is contained in:
Thomas Harte 2023-10-09 11:49:38 -04:00
parent 5a77f0c93c
commit 769aed10ea

View File

@ -34,31 +34,23 @@ uint32_t address(
MemoryT &memory MemoryT &memory
) { ) {
// TODO: non-word indexes and bases. // TODO: non-word indexes and bases.
uint32_t address; if constexpr (source == Source::DirectAddress) {
switch(source) { return instruction.offset();
default: return 0;
case Source::Indirect: {
uint16_t zero = 0;
address = *resolve<model, uint16_t>(instruction, pointer.index(), pointer, registers, memory, &zero);
if constexpr (is_32bit(model)) {
address <<= pointer.scale();
} }
address += instruction.offset() + *resolve<model, uint16_t>(instruction, pointer.base(), pointer, registers, memory);
} break;
case Source::IndirectNoBase: { uint32_t address;
uint16_t zero = 0; uint16_t zero = 0;
address = *resolve<model, uint16_t>(instruction, pointer.index(), pointer, registers, memory, &zero); address = *resolve<model, uint16_t>(instruction, pointer.index(), pointer, registers, memory, &zero);
if constexpr (is_32bit(model)) { if constexpr (is_32bit(model)) {
address <<= pointer.scale(); address <<= pointer.scale();
} }
address += instruction.offset(); address += instruction.offset();
} break;
case Source::DirectAddress: return instruction.offset(); if constexpr (source == Source::IndirectNoBase) {
}
return address; return address;
} }
return address + *resolve<model, uint16_t>(instruction, pointer.base(), pointer, registers, memory);
}
template <Model model, typename IntT, typename InstructionT, typename RegistersT, typename MemoryT> template <Model model, typename IntT, typename InstructionT, typename RegistersT, typename MemoryT>
IntT *resolve( IntT *resolve(