added breakpoints
This commit is contained in:
parent
53a7baf91f
commit
1220631e7e
23 changed files with 303 additions and 220 deletions
|
@ -5,8 +5,8 @@
|
|||
#include <imgui/imgui.h>
|
||||
#include "../CPU.hpp"
|
||||
|
||||
CPUWatcher::CPUWatcher(CPU* cpu) :
|
||||
DebugWindow("CPU Watch"), cpu(cpu)
|
||||
CPUWatcher::CPUWatcher(Debugger* debugger, CPU* cpu) :
|
||||
DebugWindow("CPU Watch", debugger), cpu(cpu)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ void CPUWatcher::OnRender()
|
|||
ImGui::InputScalar("X", ImGuiDataType_U8, &cpu->idx, (const void*)0, (const void*)0, "%02X", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::InputScalar("Y", ImGuiDataType_U8, &cpu->idy, (const void*)0, (const void*)0, "%02X", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::InputScalar("PC", ImGuiDataType_U16, &cpu->pc, (const void*)0, (const void*)0, "%04X", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::InputScalar("SP", ImGuiDataType_U8, &cpu->sp, (const void*)0, (const void*)0, "%04X", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::InputScalar("P", ImGuiDataType_U8, &cpu->status.Raw, (const void*)0, (const void*)0, "%04X", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::InputScalar("SP", ImGuiDataType_U8, &cpu->sp, (const void*)0, (const void*)0, "%02X", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::InputScalar("P", ImGuiDataType_U8, &cpu->status.Raw, (const void*)0, (const void*)0, "%02X", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_ReadOnly);
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
|
|
@ -8,7 +8,7 @@ class CPUWatcher :
|
|||
public DebugWindow
|
||||
{
|
||||
public:
|
||||
CPUWatcher(CPU* cpu);
|
||||
CPUWatcher(Debugger* debugger, CPU* cpu);
|
||||
|
||||
virtual void OnRender() override;
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
class Debugger;
|
||||
|
||||
class DebugWindow
|
||||
{
|
||||
public:
|
||||
DebugWindow(const std::string& title) :
|
||||
title(title)
|
||||
DebugWindow(const std::string& title, Debugger* parent) :
|
||||
title(title), parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -16,4 +18,7 @@ public:
|
|||
public:
|
||||
const std::string title;
|
||||
bool isOpen = false;
|
||||
|
||||
protected:
|
||||
Debugger* parent;
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include "../Bus.hpp"
|
||||
#include "../Log.hpp"
|
||||
#include "CPUWatcher.hpp"
|
||||
#include "PPUWatcher.hpp"
|
||||
#include "Disassembler.hpp"
|
||||
|
@ -13,11 +14,12 @@
|
|||
Debugger::Debugger(Bus* bus) :
|
||||
bus(bus)
|
||||
{
|
||||
windows.push_back(new CPUWatcher(&bus->cpu));
|
||||
windows.push_back(new PPUWatcher(&bus->ppu));
|
||||
windows.push_back(new Disassembler(&bus->cpu));
|
||||
windows.push_back(new MemoryViewer(bus));
|
||||
windows.push_back(new NametableViewer(bus));
|
||||
windows.push_back(new CPUWatcher(this, &bus->cpu));
|
||||
windows.push_back(new PPUWatcher(this, &bus->ppu));
|
||||
disassembler = new Disassembler(this, &bus->cpu);
|
||||
windows.push_back(disassembler);
|
||||
windows.push_back(new MemoryViewer(this, bus));
|
||||
windows.push_back(new NametableViewer(this, bus));
|
||||
}
|
||||
|
||||
Debugger::~Debugger()
|
||||
|
@ -26,10 +28,32 @@ Debugger::~Debugger()
|
|||
delete window;
|
||||
}
|
||||
|
||||
bool Debugger::Frame()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!bus->ppu.IsFrameDone())
|
||||
{
|
||||
bus->Tick();
|
||||
if (disassembler->BreakpointHit())
|
||||
{
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::runtime_error& err)
|
||||
{
|
||||
LOG_CORE_FATAL("Fatal Bus error: {0}", err.what());
|
||||
bus->cpu.Halt();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Debugger::Update()
|
||||
{
|
||||
if (running)
|
||||
return bus->Frame();
|
||||
return Frame();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "DebugWindow.hpp"
|
||||
|
||||
class Bus;
|
||||
class Disassembler;
|
||||
|
||||
class Debugger
|
||||
{
|
||||
|
@ -11,6 +12,7 @@ public:
|
|||
Debugger(Bus* bus);
|
||||
~Debugger();
|
||||
|
||||
bool Frame();
|
||||
bool Update();
|
||||
void Render();
|
||||
|
||||
|
@ -24,4 +26,5 @@ private:
|
|||
uint16_t resetVector = 0x0000;
|
||||
|
||||
std::vector<DebugWindow*> windows;
|
||||
Disassembler* disassembler;
|
||||
};
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
#include <imgui/imgui.h>
|
||||
#include "../Mapper.hpp"
|
||||
#include "../CPU.hpp"
|
||||
#include "Debugger.hpp"
|
||||
|
||||
#define FORMAT std::setfill('0') << std::setw(4) << std::hex << std::uppercase
|
||||
|
||||
Disassembler::Disassembler(CPU* cpu) :
|
||||
DebugWindow("Disassembler"), cpu(cpu)
|
||||
Disassembler::Disassembler(Debugger* debugger, CPU* cpu) :
|
||||
DebugWindow("Disassembler", debugger), cpu(cpu)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -19,12 +20,23 @@ void Disassembler::OnRender()
|
|||
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (!ImGui::Begin(title.c_str(), &isOpen))
|
||||
if (!ImGui::Begin(title.c_str(), &isOpen, ImGuiWindowFlags_MenuBar))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
if (ImGui::BeginMenu("Tools"))
|
||||
{
|
||||
ImGui::MenuItem("Breakpoints", NULL, &showBreakpoints);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
std::string disassembly;
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.8f, 0.8f, 0.8f, 1.0f });
|
||||
|
@ -65,9 +77,23 @@ void Disassembler::OnRender()
|
|||
}
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
if (showBreakpoints)
|
||||
{
|
||||
BreakpointWindow();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
bool Disassembler::BreakpointHit()
|
||||
{
|
||||
auto bpFound = breakpoints.find(cpu->pc.Raw);
|
||||
if (bpFound != breakpoints.end() && bpFound->active)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Disassembler::Disassemble(std::string& target, uint16_t& pc)
|
||||
{
|
||||
Instruction* currentInstr = &cpu->InstructionTable[cpu->Read(pc)];
|
||||
|
@ -180,3 +206,32 @@ void Disassembler::Disassemble(std::string& target, uint16_t pc, const Instructi
|
|||
|
||||
target = ss.str();
|
||||
}
|
||||
|
||||
void Disassembler::BreakpointWindow()
|
||||
{
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (!ImGui::Begin("Breakpoints", &showBreakpoints))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::InputScalar("##", ImGuiDataType_U16, &tempBreakpoint, (const void*)0, (const void*)0, "%04X", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Add Breakpoint"))
|
||||
{
|
||||
breakpoints.insert(Breakpoint(tempBreakpoint));
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
char label[6];
|
||||
for (const Breakpoint& breakpoint : breakpoints)
|
||||
{
|
||||
std::sprintf(label, "$%04X", breakpoint.GetAddress());
|
||||
ImGui::Checkbox(label, &breakpoint.active);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
|
|
@ -1,22 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include "DebugWindow.hpp"
|
||||
#include "../Types.hpp"
|
||||
|
||||
class CPU;
|
||||
struct Instruction;
|
||||
|
||||
struct Breakpoint
|
||||
{
|
||||
Breakpoint(Word addr) :
|
||||
address(addr), active(true)
|
||||
{}
|
||||
|
||||
Word address;
|
||||
mutable bool active;
|
||||
|
||||
inline Word GetAddress() const { return address; }
|
||||
|
||||
inline bool operator<(const Breakpoint& other) const { return (address < other.address); }
|
||||
inline bool operator<(Word other) const { return (address < other); }
|
||||
};
|
||||
|
||||
class Disassembler :
|
||||
public DebugWindow
|
||||
{
|
||||
public:
|
||||
Disassembler(CPU* cpu);
|
||||
Disassembler(Debugger* debugger, CPU* cpu);
|
||||
|
||||
virtual void OnRender() override;
|
||||
bool BreakpointHit();
|
||||
|
||||
private:
|
||||
void Disassemble(std::string& target, uint16_t& pc);
|
||||
void Disassemble(std::string& target, uint16_t pc, const Instruction* instr);
|
||||
|
||||
void BreakpointWindow();
|
||||
|
||||
private:
|
||||
CPU* cpu;
|
||||
bool showBreakpoints = false;
|
||||
Word tempBreakpoint = 0x0000;
|
||||
std::set<Breakpoint> breakpoints;
|
||||
};
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include <imgui/imgui.h>
|
||||
#include "../Bus.hpp"
|
||||
|
||||
MemoryViewer::MemoryViewer(Bus* bus) :
|
||||
DebugWindow("Memory Viewer"), bus(bus)
|
||||
MemoryViewer::MemoryViewer(Debugger* debugger, Bus* bus) :
|
||||
DebugWindow("Memory Viewer", debugger), bus(bus)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class MemoryViewer :
|
|||
public DebugWindow
|
||||
{
|
||||
public:
|
||||
MemoryViewer(Bus* bus);
|
||||
MemoryViewer(Debugger* debugger, Bus* bus);
|
||||
|
||||
virtual void OnRender() override;
|
||||
|
||||
|
|
|
@ -1,36 +1,83 @@
|
|||
#include "NametableViewer.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include "../Bus.hpp"
|
||||
|
||||
NametableViewer::NametableViewer(Bus* bus) :
|
||||
DebugWindow("Nametable Viewer"), bus(bus)
|
||||
NametableViewer::NametableViewer(Debugger* debugger, Bus* bus) :
|
||||
DebugWindow("Nametable Viewer", debugger), bus(bus), texture(0)
|
||||
{
|
||||
glCreateTextures(GL_TEXTURE_2D, 1, &texture);
|
||||
glTextureStorage2D(texture, 1, GL_R8, 32, 32);
|
||||
|
||||
glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
NametableViewer::~NametableViewer()
|
||||
{
|
||||
glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
void NametableViewer::OnRender()
|
||||
{
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
|
||||
if (!ImGui::Begin(title.c_str(), &isOpen))
|
||||
if (!ImGui::Begin(title.c_str(), &isOpen, ImGuiWindowFlags_MenuBar))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::BeginTabBar("Nametables");
|
||||
for (uint8_t index = 0; index < 4; index++)
|
||||
if (ImGui::BeginMenuBar())
|
||||
{
|
||||
char baseAddress[6];
|
||||
std::sprintf(baseAddress, "$2%X00", index * 4);
|
||||
if (ImGui::BeginMenu("Views"))
|
||||
{
|
||||
ImGui::MenuItem("Rendered View", NULL, &renderNametable);
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
ImGui::BeginTabBar("Nametables");
|
||||
for (uint8_t index = 0; index < 2; index++)
|
||||
{
|
||||
char baseAddress[12];
|
||||
std::sprintf(baseAddress, "Nametable %c", 'A' + index);
|
||||
if (ImGui::BeginTabItem(baseAddress))
|
||||
{
|
||||
DisplayNametable(index);
|
||||
if (renderNametable)
|
||||
{
|
||||
glTextureSubImage2D(texture, 0, 0, 0, 32, 32, GL_RED, GL_UNSIGNED_BYTE, &bus->VRAM[0x400 * index]);
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
|
||||
if (renderNametable)
|
||||
{
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
|
||||
if (!ImGui::Begin("Rendered Nametable", &renderNametable))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float smallerSize = std::min(ImGui::GetWindowWidth(), ImGui::GetWindowHeight()) - 20.0f;
|
||||
if (smallerSize < 40.0f)
|
||||
smallerSize = 40.0f;
|
||||
|
||||
ImGui::Image((ImTextureID)texture, ImVec2{smallerSize, smallerSize - 20.0f});
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ class NametableViewer :
|
|||
public DebugWindow
|
||||
{
|
||||
public:
|
||||
NametableViewer(Bus* bus);
|
||||
NametableViewer(Debugger* debugger, Bus* bus);
|
||||
~NametableViewer();
|
||||
|
||||
virtual void OnRender() override;
|
||||
|
||||
|
@ -17,4 +18,6 @@ private:
|
|||
|
||||
private:
|
||||
Bus* bus;
|
||||
uint32_t texture;
|
||||
bool renderNametable = false;
|
||||
};
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include <imgui/imgui.h>
|
||||
#include "../PPU.hpp"
|
||||
|
||||
PPUWatcher::PPUWatcher(PPU* ppu) :
|
||||
DebugWindow("PPU Watch"), ppu(ppu)
|
||||
PPUWatcher::PPUWatcher(Debugger* debugger, PPU* ppu) :
|
||||
DebugWindow("PPU Watch", debugger), ppu(ppu)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ class PPUWatcher :
|
|||
public DebugWindow
|
||||
{
|
||||
public:
|
||||
PPUWatcher(PPU* ppu);
|
||||
PPUWatcher(Debugger* debugger, PPU* ppu);
|
||||
|
||||
virtual void OnRender() override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue