diff --git a/InstructionSets/M68k/Instruction.hpp b/InstructionSets/M68k/Instruction.hpp index 314729f8d..75c55ed29 100644 --- a/InstructionSets/M68k/Instruction.hpp +++ b/InstructionSets/M68k/Instruction.hpp @@ -250,6 +250,8 @@ enum class AddressingMode: uint8_t { /// .q; value is embedded in the opcode. Quick = 0b01'110, }; +/// Guaranteed to be 1+[largest value used by AddressingMode]. +static constexpr int AddressingModeCount = 0b10'110; /*! A preinstruction is as much of an instruction as can be decoded with diff --git a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp index b5528d16a..d87e7f656 100644 --- a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp +++ b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp @@ -17,6 +17,9 @@ namespace CPU { namespace MC68000Mk2 { +#define AddressingDispatch(x) \ + x, x##__end = x + InstructionSet::M68k::AddressingModeCount + /// States for the state machine which are named by /// me for their purpose rather than automatically by file position. /// These are negative to avoid ambiguity with the other group. @@ -25,11 +28,6 @@ enum ExecutionState: int { Decode, WaitForDTACK, - /// Perform the proper sequence to fetch a byte or word operand. - FetchOperand_bw, - /// Perform the proper sequence to fetch a long-word operand. - FetchOperand_l, - StoreOperand, StoreOperand_bw, StoreOperand_l, @@ -64,42 +62,26 @@ enum ExecutionState: int { // Further consideration may be necessary. Especially once this is // up on its feet and profiling becomes an option. - FetchAddressRegisterIndirect_bw, - FetchAddressRegisterIndirectWithPostincrement_bw, - FetchAddressRegisterIndirectWithPredecrement_bw, - FetchAddressRegisterIndirectWithDisplacement_bw, - FetchAddressRegisterIndirectWithIndex8bitDisplacement_bw, - FetchProgramCounterIndirectWithDisplacement_bw, - FetchProgramCounterIndirectWithIndex8bitDisplacement_bw, - FetchAbsoluteShort_bw, - FetchAbsoluteLong_bw, - FetchImmediateData_bw, - - FetchAddressRegisterIndirect_l, - FetchAddressRegisterIndirectWithPostincrement_l, - FetchAddressRegisterIndirectWithPredecrement_l, - FetchAddressRegisterIndirectWithDisplacement_l, - FetchAddressRegisterIndirectWithIndex8bitDisplacement_l, - FetchProgramCounterIndirectWithDisplacement_l, - FetchProgramCounterIndirectWithIndex8bitDisplacement_l, - FetchAbsoluteShort_l, - FetchAbsoluteLong_l, - FetchImmediateData_l, - - CalcEffectiveAddress, // - - CalcAddressRegisterIndirect, // - - CalcAddressRegisterIndirectWithPostincrement, // - - CalcAddressRegisterIndirectWithPredecrement, // - - CalcAddressRegisterIndirectWithDisplacement, // np - CalcAddressRegisterIndirectWithIndex8bitDisplacement, // np n - CalcProgramCounterIndirectWithDisplacement, // np - CalcProgramCounterIndirectWithIndex8bitDisplacement, // np n - CalcAbsoluteShort, // np - CalcAbsoluteLong, // np np - - CalcEffectiveAddressIdleFor8bitDisplacementAndPreDec, // As per CalcEffectiveAddress unless one of the - // 8-bit displacement modes is in use, in which case - // an extra idle bus state is prefixed. + /// Perform the proper sequence to fetch a byte or word operand. + AddressingDispatch(FetchOperand_bw), + /// Perform the proper sequence to fetch a long-word operand. + AddressingDispatch(FetchOperand_l), + /// Perform the sequence to calculate an effective address, but don't fetch from it. + /// There's a lack of uniformity in the bus programs used by the 68000 for relevant + /// instructions; this entry point uses: + /// + /// Dn - An - + /// (An)+ - -(An) - + /// (d16, An) np (d8, An, Xn) np n + /// (d16, PC) np (d8, PC, Xn) np n + /// (xxx).w np (xxx).l np np + AddressingDispatch(CalcEffectiveAddress), + /// Similar to CalcEffectiveAddress, but varies slightly in the patterns: + /// + /// -(An) n + /// (d8, An, Xn) n np n + /// (d8, PC, Xn) n np n + CalcEffectiveAddressIdleFor8bitDisplacementAndPreDec, // Various forms of perform; each of these will // perform the current instruction, then do the @@ -189,6 +171,8 @@ enum ExecutionState: int { ProgramCounterIndirectWithIndex8bitDisplacement_n_np, }; +#undef AddressingDispatch + // MARK: - The state machine. template @@ -215,7 +199,15 @@ void Processor> 12].w))) + \ uint32_t(int8_t(prefetch_.b)); - BeginState(FetchAddressRegisterIndirectWithIndex8bitDisplacement_bw): + BeginStateMode(FetchOperand_bw, AddressRegisterIndirectWithIndex8bitDisplacement): effective_address_[next_operand_].l = d8Xn(registers_[8 + instruction_.reg(next_operand_)].l); SetDataAddress(effective_address_[next_operand_].l); @@ -1375,7 +1298,7 @@ void Processor