2022-05-12 23:46:08 +00:00
|
|
|
//
|
|
|
|
// Instruction.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 12/05/2022.
|
|
|
|
// Copyright © 2022 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Instruction.hpp"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
using namespace InstructionSet::M68k;
|
|
|
|
|
2024-10-14 01:34:01 +00:00
|
|
|
std::string Preinstruction::operand_description(const int index, const int opcode) const {
|
2022-05-12 23:46:08 +00:00
|
|
|
switch(mode(index)) {
|
|
|
|
default: assert(false);
|
|
|
|
|
|
|
|
case AddressingMode::None:
|
|
|
|
return "";
|
|
|
|
|
|
|
|
case AddressingMode::DataRegisterDirect:
|
|
|
|
return std::string("D") + std::to_string(reg(index));
|
|
|
|
|
|
|
|
case AddressingMode::AddressRegisterDirect:
|
|
|
|
return std::string("A") + std::to_string(reg(index));
|
|
|
|
case AddressingMode::AddressRegisterIndirect:
|
|
|
|
return std::string("(A") + std::to_string(reg(index)) + ")";
|
|
|
|
case AddressingMode::AddressRegisterIndirectWithPostincrement:
|
|
|
|
return std::string("(A") + std::to_string(reg(index)) + ")+";
|
|
|
|
case AddressingMode::AddressRegisterIndirectWithPredecrement:
|
|
|
|
return std::string("-(A") + std::to_string(reg(index)) + ")";
|
|
|
|
case AddressingMode::AddressRegisterIndirectWithDisplacement:
|
|
|
|
return std::string("(d16, A") + std::to_string(reg(index)) + ")";
|
|
|
|
case AddressingMode::AddressRegisterIndirectWithIndex8bitDisplacement:
|
|
|
|
return std::string("(d8, A") + std::to_string(reg(index)) + ", Xn)";
|
|
|
|
|
|
|
|
case AddressingMode::ProgramCounterIndirectWithDisplacement:
|
|
|
|
return "(d16, PC)";
|
|
|
|
case AddressingMode::ProgramCounterIndirectWithIndex8bitDisplacement:
|
|
|
|
return "(d8, PC, Xn)";
|
|
|
|
|
|
|
|
case AddressingMode::AbsoluteShort:
|
|
|
|
return "(xxx).w";
|
|
|
|
case AddressingMode::AbsoluteLong:
|
|
|
|
return "(xxx).l";
|
|
|
|
|
2022-10-25 13:58:01 +00:00
|
|
|
case AddressingMode::ExtensionWord:
|
2022-05-12 23:46:08 +00:00
|
|
|
case AddressingMode::ImmediateData:
|
|
|
|
return "#";
|
|
|
|
|
|
|
|
case AddressingMode::Quick:
|
|
|
|
if(opcode == -1) {
|
|
|
|
return "Q";
|
|
|
|
}
|
|
|
|
return std::to_string(int(quick(uint16_t(opcode), operation)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
namespace {
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2024-10-14 01:34:01 +00:00
|
|
|
const char *_to_string(const Operation operation, const bool is_quick) {
|
2022-05-12 23:46:08 +00:00
|
|
|
switch(operation) {
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::Undefined: return "None";
|
|
|
|
case Operation::NOP: return "NOP";
|
|
|
|
case Operation::ABCD: return "ABCD";
|
|
|
|
case Operation::SBCD: return "SBCD";
|
|
|
|
case Operation::NBCD: return "NBCD";
|
|
|
|
|
|
|
|
case Operation::ADDb: return "ADD.b";
|
|
|
|
case Operation::ADDw: return "ADD.w";
|
|
|
|
case Operation::ADDl: return "ADD.l";
|
|
|
|
|
|
|
|
case Operation::ADDAw: return is_quick ? "ADD.w" : "ADDA.w";
|
|
|
|
case Operation::ADDAl: return is_quick ? "ADD.l" : "ADDA.l";
|
|
|
|
|
|
|
|
case Operation::ADDXb: return "ADDX.b";
|
|
|
|
case Operation::ADDXw: return "ADDX.w";
|
|
|
|
case Operation::ADDXl: return "ADDX.l";
|
|
|
|
|
|
|
|
case Operation::SUBb: return "SUB.b";
|
|
|
|
case Operation::SUBw: return "SUB.w";
|
|
|
|
case Operation::SUBl: return "SUB.l";
|
|
|
|
|
|
|
|
case Operation::SUBAw: return is_quick ? "SUB.w" : "SUBA.w";
|
|
|
|
case Operation::SUBAl: return is_quick ? "SUB.l" : "SUBA.l";
|
|
|
|
|
|
|
|
case Operation::SUBXb: return "SUBX.b";
|
|
|
|
case Operation::SUBXw: return "SUBX.w";
|
|
|
|
case Operation::SUBXl: return "SUBX.l";
|
|
|
|
|
|
|
|
case Operation::MOVEb: return "MOVE.b";
|
|
|
|
case Operation::MOVEw: return "MOVE.w";
|
|
|
|
case Operation::MOVEl: return is_quick ? "MOVE.q" : "MOVE.l";
|
|
|
|
|
|
|
|
case Operation::MOVEAw: return "MOVEA.w";
|
|
|
|
case Operation::MOVEAl: return "MOVEA.l";
|
|
|
|
|
2022-10-26 17:34:01 +00:00
|
|
|
case Operation::MOVESb: return "MOVES.b";
|
|
|
|
case Operation::MOVESw: return "MOVES.w";
|
|
|
|
case Operation::MOVESl: return "MOVES.l";
|
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::LEA: return "LEA";
|
|
|
|
case Operation::PEA: return "PEA";
|
|
|
|
|
|
|
|
case Operation::MOVEtoSR: return "MOVEtoSR";
|
|
|
|
case Operation::MOVEfromSR: return "MOVEfromSR";
|
|
|
|
case Operation::MOVEtoCCR: return "MOVEtoCCR";
|
2022-10-26 16:39:40 +00:00
|
|
|
case Operation::MOVEfromCCR: return "MOVEfromCCR";
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::MOVEtoUSP: return "MOVEtoUSP";
|
|
|
|
case Operation::MOVEfromUSP: return "MOVEfromUSP";
|
2022-10-26 16:50:15 +00:00
|
|
|
case Operation::MOVEtoC: return "MOVEtoC";
|
|
|
|
case Operation::MOVEfromC: return "MOVEfromC";
|
2022-09-06 01:52:20 +00:00
|
|
|
|
|
|
|
case Operation::ORItoSR: return "ORItoSR";
|
|
|
|
case Operation::ORItoCCR: return "ORItoCCR";
|
|
|
|
case Operation::ANDItoSR: return "ANDItoSR";
|
|
|
|
case Operation::ANDItoCCR: return "ANDItoCCR";
|
|
|
|
case Operation::EORItoSR: return "EORItoSR";
|
|
|
|
case Operation::EORItoCCR: return "EORItoCCR";
|
|
|
|
|
|
|
|
case Operation::BTST: return "BTST";
|
|
|
|
case Operation::BCLR: return "BCLR";
|
|
|
|
case Operation::BCHG: return "BCHG";
|
|
|
|
case Operation::BSET: return "BSET";
|
|
|
|
|
|
|
|
case Operation::CMPb: return "CMP.b";
|
|
|
|
case Operation::CMPw: return "CMP.w";
|
|
|
|
case Operation::CMPl: return "CMP.l";
|
|
|
|
|
|
|
|
case Operation::CMPAw: return "CMPA.w";
|
|
|
|
case Operation::CMPAl: return "CMPA.l";
|
|
|
|
|
|
|
|
case Operation::TSTb: return "TST.b";
|
|
|
|
case Operation::TSTw: return "TST.w";
|
|
|
|
case Operation::TSTl: return "TST.l";
|
|
|
|
|
|
|
|
case Operation::JMP: return "JMP";
|
|
|
|
case Operation::JSR: return "JSR";
|
|
|
|
case Operation::RTS: return "RTS";
|
2022-10-27 14:12:52 +00:00
|
|
|
case Operation::RTD: return "RTD";
|
|
|
|
case Operation::RTM: return "RTM";
|
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::DBcc: return "DBcc";
|
|
|
|
case Operation::Scc: return "Scc";
|
2022-10-27 14:12:52 +00:00
|
|
|
case Operation::TRAPcc: return "TRAPcc";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::Bccb:
|
|
|
|
case Operation::Bccl:
|
|
|
|
case Operation::Bccw: return "Bcc";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::BSRb:
|
|
|
|
case Operation::BSRl:
|
|
|
|
case Operation::BSRw: return "BSR";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-10-28 17:57:00 +00:00
|
|
|
case Operation::CASb: return "CAS.b";
|
|
|
|
case Operation::CASw: return "CAS.w";
|
|
|
|
case Operation::CASl: return "CAS.l";
|
|
|
|
|
2022-10-28 18:02:49 +00:00
|
|
|
case Operation::CAS2w: return "CAS2.w";
|
|
|
|
case Operation::CAS2l: return "CAS2.l";
|
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::CLRb: return "CLR.b";
|
|
|
|
case Operation::CLRw: return "CLR.w";
|
|
|
|
case Operation::CLRl: return "CLR.l";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::NEGXb: return "NEGX.b";
|
|
|
|
case Operation::NEGXw: return "NEGX.w";
|
|
|
|
case Operation::NEGXl: return "NEGX.l";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::NEGb: return "NEG.b";
|
|
|
|
case Operation::NEGw: return "NEG.w";
|
|
|
|
case Operation::NEGl: return "NEG.l";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::ASLb: return "ASL.b";
|
|
|
|
case Operation::ASLw: return "ASL.w";
|
|
|
|
case Operation::ASLl: return "ASL.l";
|
|
|
|
case Operation::ASLm: return "ASL.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::ASRb: return "ASR.b";
|
|
|
|
case Operation::ASRw: return "ASR.w";
|
|
|
|
case Operation::ASRl: return "ASR.l";
|
|
|
|
case Operation::ASRm: return "ASR.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::LSLb: return "LSL.b";
|
|
|
|
case Operation::LSLw: return "LSL.w";
|
|
|
|
case Operation::LSLl: return "LSL.l";
|
|
|
|
case Operation::LSLm: return "LSL.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::LSRb: return "LSR.b";
|
|
|
|
case Operation::LSRw: return "LSR.w";
|
|
|
|
case Operation::LSRl: return "LSR.l";
|
|
|
|
case Operation::LSRm: return "LSR.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::ROLb: return "ROL.b";
|
|
|
|
case Operation::ROLw: return "ROL.w";
|
|
|
|
case Operation::ROLl: return "ROL.l";
|
|
|
|
case Operation::ROLm: return "ROL.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::RORb: return "ROR.b";
|
|
|
|
case Operation::RORw: return "ROR.w";
|
|
|
|
case Operation::RORl: return "ROR.l";
|
|
|
|
case Operation::RORm: return "ROR.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::ROXLb: return "ROXL.b";
|
|
|
|
case Operation::ROXLw: return "ROXL.w";
|
|
|
|
case Operation::ROXLl: return "ROXL.l";
|
|
|
|
case Operation::ROXLm: return "ROXL.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::ROXRb: return "ROXR.b";
|
|
|
|
case Operation::ROXRw: return "ROXR.w";
|
|
|
|
case Operation::ROXRl: return "ROXR.l";
|
|
|
|
case Operation::ROXRm: return "ROXR.w";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::MOVEMtoMl: return "MOVEM.l";
|
|
|
|
case Operation::MOVEMtoMw: return "MOVEM.w";
|
|
|
|
case Operation::MOVEMtoRl: return "MOVEM.l";
|
|
|
|
case Operation::MOVEMtoRw: return "MOVEM.w";
|
|
|
|
|
|
|
|
case Operation::MOVEPl: return "MOVEP.l";
|
|
|
|
case Operation::MOVEPw: return "MOVEP.w";
|
|
|
|
|
|
|
|
case Operation::ANDb: return "AND.b";
|
|
|
|
case Operation::ANDw: return "AND.w";
|
|
|
|
case Operation::ANDl: return "AND.l";
|
|
|
|
|
|
|
|
case Operation::EORb: return "EOR.b";
|
|
|
|
case Operation::EORw: return "EOR.w";
|
|
|
|
case Operation::EORl: return "EOR.l";
|
|
|
|
|
|
|
|
case Operation::NOTb: return "NOT.b";
|
|
|
|
case Operation::NOTw: return "NOT.w";
|
|
|
|
case Operation::NOTl: return "NOT.l";
|
|
|
|
|
|
|
|
case Operation::ORb: return "OR.b";
|
|
|
|
case Operation::ORw: return "OR.w";
|
|
|
|
case Operation::ORl: return "OR.l";
|
|
|
|
|
2022-10-22 19:20:30 +00:00
|
|
|
case Operation::MULUw: return "MULU";
|
|
|
|
case Operation::MULSw: return "MULS";
|
2022-10-30 15:32:36 +00:00
|
|
|
case Operation::MULSorMULUl: return "[MULS/MULU]{L}.l";
|
|
|
|
|
2022-10-22 19:20:30 +00:00
|
|
|
case Operation::DIVUw: return "DIVU";
|
|
|
|
case Operation::DIVSw: return "DIVS";
|
2022-10-30 15:32:36 +00:00
|
|
|
case Operation::DIVSorDIVUl: return "[DIVS/DIVU]{L}.l";
|
2022-09-06 01:52:20 +00:00
|
|
|
|
|
|
|
case Operation::RTE: return "RTE";
|
|
|
|
case Operation::RTR: return "RTR";
|
|
|
|
|
|
|
|
case Operation::TRAP: return "TRAP";
|
|
|
|
case Operation::TRAPV: return "TRAPV";
|
2022-10-30 01:42:53 +00:00
|
|
|
|
2022-10-22 19:20:30 +00:00
|
|
|
case Operation::CHKw: return "CHK";
|
2022-10-30 01:42:53 +00:00
|
|
|
case Operation::CHKl: return "CHK.l";
|
2022-09-06 01:52:20 +00:00
|
|
|
|
2022-10-30 01:32:48 +00:00
|
|
|
case Operation::CHKorCMP2b: return "[CHK/CMP]2.b";
|
|
|
|
case Operation::CHKorCMP2w: return "[CHK/CMP]2.w";
|
|
|
|
case Operation::CHKorCMP2l: return "[CHK/CMP]2.l";
|
2022-10-28 18:02:49 +00:00
|
|
|
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::EXG: return "EXG";
|
|
|
|
case Operation::SWAP: return "SWAP";
|
|
|
|
|
|
|
|
case Operation::TAS: return "TAS";
|
|
|
|
|
|
|
|
case Operation::EXTbtow: return "EXT.w";
|
|
|
|
case Operation::EXTwtol: return "EXT.l";
|
2022-10-30 15:20:43 +00:00
|
|
|
case Operation::EXTbtol: return "EXTB.l";
|
2022-09-06 01:52:20 +00:00
|
|
|
|
|
|
|
case Operation::LINKw: return "LINK";
|
2022-10-30 01:42:53 +00:00
|
|
|
case Operation::LINKl: return "LINK.l";
|
2022-09-06 01:52:20 +00:00
|
|
|
case Operation::UNLINK: return "UNLINK";
|
|
|
|
|
|
|
|
case Operation::STOP: return "STOP";
|
|
|
|
case Operation::RESET: return "RESET";
|
2022-05-12 23:46:08 +00:00
|
|
|
|
2022-10-26 02:35:44 +00:00
|
|
|
case Operation::BKPT: return "BKPT";
|
2022-10-27 14:12:52 +00:00
|
|
|
|
|
|
|
case Operation::BFCHG: return "BFCHG";
|
|
|
|
case Operation::BFCLR: return "BFCLR";
|
|
|
|
case Operation::BFEXTS: return "BFEXTS";
|
|
|
|
case Operation::BFEXTU: return "BFEXTU";
|
|
|
|
case Operation::BFFFO: return "BFFFO";
|
|
|
|
case Operation::BFINS: return "BFINS";
|
|
|
|
case Operation::BFSET: return "BFSET";
|
|
|
|
case Operation::BFTST: return "BFTST";
|
|
|
|
|
|
|
|
case Operation::PACK: return "PACK";
|
|
|
|
case Operation::UNPK: return "UNPK";
|
2022-10-26 02:35:44 +00:00
|
|
|
|
2022-05-12 23:46:08 +00:00
|
|
|
default:
|
|
|
|
assert(false);
|
2022-09-09 20:48:12 +00:00
|
|
|
return "???";
|
2022-05-12 23:46:08 +00:00
|
|
|
}
|
2022-09-06 01:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-10-14 01:34:01 +00:00
|
|
|
const char *InstructionSet::M68k::to_string(const Operation operation) {
|
2022-09-06 01:52:20 +00:00
|
|
|
return _to_string(operation, false);
|
|
|
|
}
|
|
|
|
|
2024-10-14 01:34:01 +00:00
|
|
|
std::string Preinstruction::to_string(const int opcode) const {
|
2022-09-06 01:52:20 +00:00
|
|
|
if(operation == Operation::Undefined) return "None";
|
|
|
|
|
|
|
|
const char *const instruction = _to_string(operation, mode<0>() == AddressingMode::Quick);
|
|
|
|
const bool flip_operands = (operation == Operation::MOVEMtoRl) || (operation == Operation::MOVEMtoRw);
|
2022-05-12 23:46:08 +00:00
|
|
|
|
|
|
|
const std::string operand1 = operand_description(0 ^ int(flip_operands), opcode);
|
|
|
|
const std::string operand2 = operand_description(1 ^ int(flip_operands), opcode);
|
|
|
|
|
|
|
|
std::string result = instruction;
|
|
|
|
if(!operand1.empty()) result += std::string(" ") + operand1;
|
|
|
|
if(!operand2.empty()) result += std::string(", ") + operand2;
|
|
|
|
|
2022-10-28 17:36:40 +00:00
|
|
|
const int extension_words = additional_extension_words();
|
|
|
|
if(extension_words) result += std::string(" [+") + std::to_string(extension_words) + "]";
|
|
|
|
|
2022-05-12 23:46:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
2022-09-06 15:26:16 +00:00
|
|
|
|
|
|
|
const char *Preinstruction::operation_string() const {
|
|
|
|
return _to_string(operation, mode<0>() == AddressingMode::Quick);
|
|
|
|
}
|