More small improvements

This commit is contained in:
IrisZ64
2025-12-15 21:46:22 +01:00
parent 19b9d56ba7
commit faa02bf0bb
3 changed files with 26 additions and 29 deletions

View File

@@ -1,6 +1,5 @@
#include <Debugger.hpp> #include <Debugger.hpp>
#include <imgui.h> #include <imgui.h>
#include <execution>
char const* regNames[] = { char const* regNames[] = {
"zero", "at", "v0", "v1", "zero", "at", "v0", "v1",
@@ -101,7 +100,7 @@ void Debugger::RegisterView() {
if (!n64::Core::GetRegs().cop0.MapVAddr(n64::Cop0::LOAD, vaddr + row * 0x10 + col, paddr)) if (!n64::Core::GetRegs().cop0.MapVAddr(n64::Cop0::LOAD, vaddr + row * 0x10 + col, paddr))
continue; continue;
u32 val = n64::Core::GetMem().Read<u32>(paddr); const u32 val = n64::Core::GetMem().Read<u32>(paddr);
ImGui::TableSetColumnIndex(col+0); ImGui::TableSetColumnIndex(col+0);
ImGui::Text("%02X", (val >> 24) & 0xff); ImGui::Text("%02X", (val >> 24) & 0xff);
@@ -145,22 +144,22 @@ void Debugger::RegisterView() {
bool Debugger::render() { bool Debugger::render() {
n64::Core &core = n64::Core::GetInstance(); n64::Core &core = n64::Core::GetInstance();
n64::Registers& regs = core.GetRegs(); const n64::Registers& regs = n64::Core::GetRegs();
bool ret = true;
if(!enabled) if(!enabled)
return false; return false;
static s64 startAddr = 0xFFFF'FFFF'8000'0000; static s64 startAddr = 0xFFFF'FFFF'8000'0000;
int step = 4, stepFast = 256; constexpr int step = 4;
constexpr int stepFast = 256;
if(!ImGui::Begin("Debugger", &enabled)) { if(!ImGui::Begin("Debugger", &enabled)) {
ret = false; ImGui::End();
goto EXIT; return false;
} }
ImGui::BeginDisabled(followPC); ImGui::BeginDisabled(followPC);
ImGui::InputScalar("Address", ImGuiDataType_S64, (void*)&startAddr, (void*)&step, (void*)&stepFast, "%016lX", ImGuiInputTextFlags_CharsHexadecimal); ImGui::InputScalar("Address", ImGuiDataType_S64, &startAddr, &step, &stepFast, "%016lX", ImGuiInputTextFlags_CharsHexadecimal);
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::Text("Follow program counter:"); ImGui::Text("Follow program counter:");
@@ -179,23 +178,23 @@ bool Debugger::render() {
core.ToggleBreakpoint(startAddr); core.ToggleBreakpoint(startAddr);
} }
auto disasmTableFlags = ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | constexpr auto disasmTableFlags = ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter |
ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody; ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
if(!ImGui::BeginTable("Disassembly", columns.size(), disasmTableFlags)) { if(!ImGui::BeginTable("Disassembly", columns.size(), disasmTableFlags)) {
ret = false; ImGui::End();
goto EXIT; return false;
} }
for(int i = 0; i < columns.size(); i++) for(auto &[name, _] : columns)
ImGui::TableSetupColumn(columns[i].name); ImGui::TableSetupColumn(name);
ImGui::TableHeadersRow(); ImGui::TableHeadersRow();
for(u64 addr = startAddr; addr < startAddr + MAX_LINES_OF_DISASM * sizeof(u32); addr += sizeof(u32)) { for(auto addr = startAddr; addr < startAddr + MAX_LINES_OF_DISASM * sizeof(u32); addr += sizeof(u32)) {
auto disasm = Disassembler::GetInstance().Disassemble(addr); auto disasm = Disassembler::GetInstance().Disassemble(addr);
auto addrIsCurrent = addr == regs.nextPC; const auto addrIsCurrent = addr == regs.nextPC;
auto addrIsBreakpoint = core.breakpoints.contains(addr); const auto addrIsBreakpoint = core.breakpoints.contains(addr);
ImColor colorChoice = ImGui::GetStyle().Colors[ImGuiCol_TableRowBg]; ImColor colorChoice = ImGui::GetStyle().Colors[ImGuiCol_TableRowBg];
ImColor colorChoiceAlt = ImGui::GetStyle().Colors[ImGuiCol_TableRowBgAlt]; ImColor colorChoiceAlt = ImGui::GetStyle().Colors[ImGuiCol_TableRowBgAlt];
if(addrIsCurrent) { if(addrIsCurrent) {
@@ -212,9 +211,9 @@ bool Debugger::render() {
ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, colorChoiceAlt.Value); ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, colorChoiceAlt.Value);
ImGui::TableNextRow(); ImGui::TableNextRow();
for(int i = 0; i < columns.size(); i++) { for(int i = 0; auto &[_, func] : columns) {
ImGui::TableSetColumnIndex(i); ImGui::TableSetColumnIndex(i++);
columns[i].func(addr, disasm); func(addr, disasm);
} }
ImGui::PopStyleColor(); ImGui::PopStyleColor();
@@ -225,7 +224,6 @@ bool Debugger::render() {
RegisterView(); RegisterView();
EXIT:
ImGui::End(); ImGui::End();
return ret; return true;
} }

View File

@@ -10,7 +10,7 @@ class Debugger final {
static constexpr auto MAX_LINES_OF_DISASM = 150; static constexpr auto MAX_LINES_OF_DISASM = 150;
struct Column { struct Column {
const char* name; const char* name = nullptr;
void (*func)(s64, Disassembler::DisassemblyResult&) = nullptr; void (*func)(s64, Disassembler::DisassemblyResult&) = nullptr;
}; };
@@ -20,7 +20,7 @@ class Debugger final {
Column{"Instruction", &InstructionFunc}, Column{"Instruction", &InstructionFunc},
}; };
public: public:
void RegisterView(); static void RegisterView();
bool followPC = true; bool followPC = true;
void Open(bool wantFollowPC = true) { enabled = true; followPC = wantFollowPC; } void Open(bool wantFollowPC = true) { enabled = true; followPC = wantFollowPC; }
void Close() { enabled = false; } void Close() { enabled = false; }

View File

@@ -1,5 +1,4 @@
#include <SettingsWindow.hpp> #include <SettingsWindow.hpp>
#include <log.hpp>
#include <Options.hpp> #include <Options.hpp>
#include <imgui.h> #include <imgui.h>
#include <ranges> #include <ranges>
@@ -31,7 +30,7 @@ bool SettingsWindow::render() {
applyEnabled = false; applyEnabled = false;
Options::GetInstance().Apply(); Options::GetInstance().Apply();
for (auto &tab : tabs | std::views::values) { for (const auto &tab : tabs | std::views::values) {
tab->modified = false; tab->modified = false;
} }
} }