fixed disassembler

This commit is contained in:
Lauchmelder 2022-02-28 17:04:20 +01:00
parent dfef02df47
commit 71b524519d
No known key found for this signature in database
GPG key ID: C2403C69D78F011D
4 changed files with 22 additions and 15 deletions

View file

@ -56,9 +56,9 @@ uint8_t CPU::Tick()
Byte opcode = Read(pc.Raw++);
currentInstruction = &(InstructionTable[opcode]);
pastPCs.push_back(currentInstruction);
if (pastPCs.size() > 50)
pastPCs.pop_front();
pastInstructions.push_back(std::make_pair(pc.Raw - 1, currentInstruction));
if (pastInstructions.size() > 50)
pastInstructions.pop_front();
if (currentInstruction->Operation == nullptr || currentInstruction->Mode == nullptr)
{

View file

@ -240,7 +240,7 @@ private: // CPU internals
uint8_t remainingCycles = 0;
uint8_t additionalCycles = 0; //< E.g. when a page boundary was crossed
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;
#ifndef NDEBUG

View file

@ -28,17 +28,17 @@ void Disassembler::OnRender()
std::string disassembly;
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("-");
}
}
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::PopStyleColor();
@ -70,18 +70,24 @@ void Disassembler::OnRender()
void Disassembler::Disassemble(std::string& target, uint16_t& pc)
{
std::stringstream ss;
ss << FORMAT << 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 << std::string(15 - ss.str().size(), ' ') << currentInstr->Mnemonic << " ";
ss << std::string(15 - ss.str().size(), ' ') << instr->Mnemonic << " ";
Address absoluteAddress;
switch (currentInstr->AddrType)
switch (instr->AddrType)
{
case Addressing::ACC:
ss << "A";
@ -118,7 +124,7 @@ void Disassembler::Disassemble(std::string& target, uint16_t& pc)
ss << "#$" << FORMAT << std::setw(2) << value;
} break;
case Addressing::IMP:
case Addressing::IMP:
break;
case Addressing::IND:
@ -172,6 +178,5 @@ void Disassembler::Disassemble(std::string& target, uint16_t& pc)
} break;
}
pc += currentInstr->Size;
target = ss.str();
}

View file

@ -3,6 +3,7 @@
#include "DebugWindow.hpp"
class CPU;
struct Instruction;
class Disassembler :
public DebugWindow
@ -14,6 +15,7 @@ public:
private:
void Disassemble(std::string& target, uint16_t& pc);
void Disassemble(std::string& target, uint16_t pc, const Instruction* instr);
private:
CPU* cpu;