fixed disassembler
This commit is contained in:
parent
dfef02df47
commit
71b524519d
|
@ -56,9 +56,9 @@ uint8_t CPU::Tick()
|
||||||
Byte opcode = Read(pc.Raw++);
|
Byte opcode = Read(pc.Raw++);
|
||||||
currentInstruction = &(InstructionTable[opcode]);
|
currentInstruction = &(InstructionTable[opcode]);
|
||||||
|
|
||||||
pastPCs.push_back(currentInstruction);
|
pastInstructions.push_back(std::make_pair(pc.Raw - 1, currentInstruction));
|
||||||
if (pastPCs.size() > 50)
|
if (pastInstructions.size() > 50)
|
||||||
pastPCs.pop_front();
|
pastInstructions.pop_front();
|
||||||
|
|
||||||
if (currentInstruction->Operation == nullptr || currentInstruction->Mode == nullptr)
|
if (currentInstruction->Operation == nullptr || currentInstruction->Mode == nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -240,7 +240,7 @@ private: // CPU internals
|
||||||
uint8_t remainingCycles = 0;
|
uint8_t remainingCycles = 0;
|
||||||
uint8_t additionalCycles = 0; //< E.g. when a page boundary was crossed
|
uint8_t additionalCycles = 0; //< E.g. when a page boundary was crossed
|
||||||
uint64_t totalCycles = 0;
|
uint64_t totalCycles = 0;
|
||||||
std::deque<Instruction*> pastPCs; //< For debugging, saves the past 50 instructions
|
std::deque<std::pair<Word, Instruction*>> pastInstructions; //< For debugging, saves the past 50 instructions
|
||||||
bool halted = false;
|
bool halted = false;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
@ -28,17 +28,17 @@ void Disassembler::OnRender()
|
||||||
std::string disassembly;
|
std::string disassembly;
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.8f, 0.8f, 0.8f, 1.0f });
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.8f, 0.8f, 0.8f, 1.0f });
|
||||||
if (cpu->pastPCs.size() < 50)
|
if (cpu->pastInstructions.size() < 50)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 50 - cpu->pastPCs.size(); i++)
|
for (int i = 0; i < 50 - cpu->pastInstructions.size(); i++)
|
||||||
{
|
{
|
||||||
ImGui::Text("-");
|
ImGui::Text("-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Word pc : cpu->pastPCs)
|
for (auto pair : cpu->pastInstructions)
|
||||||
{
|
{
|
||||||
Disassemble(disassembly, pc);
|
Disassemble(disassembly, pair.first, pair.second);
|
||||||
ImGui::Text("- %s", disassembly.c_str());
|
ImGui::Text("- %s", disassembly.c_str());
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
@ -70,18 +70,24 @@ void Disassembler::OnRender()
|
||||||
|
|
||||||
void Disassembler::Disassemble(std::string& target, uint16_t& pc)
|
void Disassembler::Disassemble(std::string& target, uint16_t& pc)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
|
||||||
ss << FORMAT << pc << ": ";
|
|
||||||
Instruction* currentInstr = &cpu->InstructionTable[cpu->Read(pc)];
|
Instruction* currentInstr = &cpu->InstructionTable[cpu->Read(pc)];
|
||||||
|
Disassemble(target, pc, currentInstr);
|
||||||
|
pc += currentInstr->Size;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < currentInstr->Size; i++)
|
void Disassembler::Disassemble(std::string& target, uint16_t pc, const Instruction* instr)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << FORMAT << pc << ": ";
|
||||||
|
|
||||||
|
for (int i = 0; i < instr->Size; i++)
|
||||||
{
|
{
|
||||||
ss << FORMAT << std::setw(2) << (Word)cpu->Read(pc + i) << " ";
|
ss << FORMAT << std::setw(2) << (Word)cpu->Read(pc + i) << " ";
|
||||||
}
|
}
|
||||||
ss << std::string(15 - ss.str().size(), ' ') << currentInstr->Mnemonic << " ";
|
ss << std::string(15 - ss.str().size(), ' ') << instr->Mnemonic << " ";
|
||||||
|
|
||||||
Address absoluteAddress;
|
Address absoluteAddress;
|
||||||
switch (currentInstr->AddrType)
|
switch (instr->AddrType)
|
||||||
{
|
{
|
||||||
case Addressing::ACC:
|
case Addressing::ACC:
|
||||||
ss << "A";
|
ss << "A";
|
||||||
|
@ -118,7 +124,7 @@ void Disassembler::Disassemble(std::string& target, uint16_t& pc)
|
||||||
ss << "#$" << FORMAT << std::setw(2) << value;
|
ss << "#$" << FORMAT << std::setw(2) << value;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Addressing::IMP:
|
case Addressing::IMP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Addressing::IND:
|
case Addressing::IND:
|
||||||
|
@ -172,6 +178,5 @@ void Disassembler::Disassemble(std::string& target, uint16_t& pc)
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc += currentInstr->Size;
|
|
||||||
target = ss.str();
|
target = ss.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "DebugWindow.hpp"
|
#include "DebugWindow.hpp"
|
||||||
|
|
||||||
class CPU;
|
class CPU;
|
||||||
|
struct Instruction;
|
||||||
|
|
||||||
class Disassembler :
|
class Disassembler :
|
||||||
public DebugWindow
|
public DebugWindow
|
||||||
|
@ -14,6 +15,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Disassemble(std::string& target, uint16_t& pc);
|
void Disassemble(std::string& target, uint16_t& pc);
|
||||||
|
void Disassemble(std::string& target, uint16_t pc, const Instruction* instr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CPU* cpu;
|
CPU* cpu;
|
||||||
|
|
Loading…
Reference in a new issue