Add basic register view

This commit is contained in:
Henrik Rydgård 2024-11-06 15:53:38 +01:00
parent cf6d06c56a
commit 84a0293e54
6 changed files with 48 additions and 5 deletions

View File

@ -51,6 +51,9 @@ public:
virtual const char *GetName() = 0;
virtual u32 GetGPR32Value(int reg) {return 0;}
virtual void SetGPR32Value(int reg) {}
virtual float GetFPR32Value(int reg) { return -1.0f; }
virtual float GetVPR32Value(int reg) { return -1.0f; }
virtual u32 GetPC() = 0;
virtual void SetPC(u32 _pc) = 0;
virtual u32 GetLR() {return GetPC();}

View File

@ -48,6 +48,7 @@ public:
//overridden functions
const char *GetName() override;
u32 GetGPR32Value(int reg) override { return cpu->r[reg]; }
float GetFPR32Value(int reg) override { return cpu->f[reg]; }
u32 GetPC() override { return cpu->pc; }
u32 GetLR() override { return cpu->r[MIPS_REG_RA]; }
void DisAsm(u32 pc, char *out, size_t outSize) override;

View File

@ -14,6 +14,38 @@
#include "UI/ImDebugger/ImDebugger.h"
void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) {
if (!ImGui::Begin("Registers", open)) {
ImGui::End();
return;
}
if (ImGui::BeginTabBar("RegisterGroups", ImGuiTabBarFlags_None)) {
if (ImGui::BeginTabItem("GPR")) {
for (int i = 0; i < 32; i++) {
const u32 value = mipsDebug->GetGPR32Value(i);
ImGui::Text("%s: %08x (%d)", mipsDebug->GetRegName(0, i).c_str(), value, value);
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("FPR")) {
for (int i = 0; i < 32; i++) {
float fvalue = mipsDebug->GetFPR32Value(i);
u32 fivalue;
memcpy(&fivalue, &fvalue, sizeof(fivalue));
ImGui::Text("%s: %0.6f (%08x)", mipsDebug->GetRegName(1, i).c_str(), fvalue, fivalue);
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("VPR")) {
ImGui::Text("TODO");
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
ImGui::End();
}
void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) {
// Snapshot the coreState to avoid inconsistency.
const CoreState coreState = ::coreState;
@ -47,6 +79,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) {
if (ImGui::BeginMenu("Window")) {
ImGui::Checkbox("Dear ImGUI Demo", &demoOpen_);
ImGui::Checkbox("CPU debugger", &disasmOpen_);
ImGui::Checkbox("Registers", &regsOpen_);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
@ -60,6 +93,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) {
disasm_.Draw(mipsDebug, &disasmOpen_);
}
if (regsOpen_) {
DrawRegisterView(mipsDebug, &regsOpen_);
}
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::End();

View File

@ -60,4 +60,5 @@ struct ImDebugger {
// Open variables.
bool disasmOpen_ = true;
bool demoOpen_ = false;
bool regsOpen_ = true;
};

View File

@ -156,7 +156,7 @@ void ImDisasmView::assembleOpcode(u32 address, const std::string &defaultText) {
*/
}
void ImDisasmView::drawBranchLine(ImDrawList *drawList, Rect rect, std::map<u32, int> &addressPositions, const BranchLine &line) {
void ImDisasmView::drawBranchLine(ImDrawList *drawList, Rect rect, std::map<u32, float> &addressPositions, const BranchLine &line) {
u32 windowEnd = manager.getNthNextAddress(windowStart_, visibleRows_);
float topY;
@ -185,6 +185,7 @@ void ImDisasmView::drawBranchLine(ImDrawList *drawList, Rect rect, std::map<u32,
ImColor pen;
// highlight line in a different color if it affects the currently selected opcode
// TODO: Color line differently if forward or backward too!
if (line.first == curAddress_ || line.second == curAddress_) {
pen = ImColor(0xFF257AFA);
} else {
@ -354,15 +355,15 @@ void ImDisasmView::Draw(ImDrawList *drawList) {
//HICON breakPointDisable = (HICON)LoadIcon(GetModuleHandle(0), (LPCWSTR)IDI_STOPDISABLE);
unsigned int address = windowStart_;
std::map<u32, int> addressPositions;
std::map<u32, float> addressPositions;
const std::set<std::string> currentArguments = getSelectedLineArguments();
DisassemblyLineInfo line;
for (int i = 0; i < visibleRows_; i++) {
manager.getLine(address, displaySymbols_, line);
int rowY1 = rowHeight_ * i;
int rowY2 = rowHeight_ * (i + 1);
float rowY1 = rowHeight_ * i;
float rowY2 = rowHeight_ * (i + 1);
addressPositions[address] = rowY1;

View File

@ -134,7 +134,7 @@ private:
void calculatePixelPositions();
bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData);
void updateStatusBarText();
void drawBranchLine(ImDrawList *list, ImDisasmView::Rect rc, std::map<u32, int> &addressPositions, const BranchLine &line);
void drawBranchLine(ImDrawList *list, ImDisasmView::Rect rc, std::map<u32, float> &addressPositions, const BranchLine &line);
void CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructionsMode mode);
void NopInstructions(u32 startAddr, u32 endAddr);
std::set<std::string> getSelectedLineArguments();