diff --git a/src/frontend/Debugger.cpp b/src/frontend/Debugger.cpp index 36f30c4b..15a6ee3a 100644 --- a/src/frontend/Debugger.cpp +++ b/src/frontend/Debugger.cpp @@ -1,6 +1,5 @@ #include #include -#include char const* regNames[] = { "zero", "at", "v0", "v1", @@ -98,10 +97,10 @@ void Debugger::RegisterView() { ImGui::TableNextRow(); for(u32 col = 0; col < 16; col+=4) { u32 paddr; - 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; - - u32 val = n64::Core::GetMem().Read(paddr); + + const u32 val = n64::Core::GetMem().Read(paddr); ImGui::TableSetColumnIndex(col+0); ImGui::Text("%02X", (val >> 24) & 0xff); @@ -144,23 +143,23 @@ void Debugger::RegisterView() { } bool Debugger::render() { - n64::Core& core = n64::Core::GetInstance(); - n64::Registers& regs = core.GetRegs(); - bool ret = true; + n64::Core &core = n64::Core::GetInstance(); + const n64::Registers& regs = n64::Core::GetRegs(); if(!enabled) return false; 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)) { - ret = false; - goto EXIT; + ImGui::End(); + return false; } 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::Text("Follow program counter:"); @@ -175,27 +174,27 @@ bool Debugger::render() { if(followPC) startAddr = regs.pc - 256; // TODO: arbitrary??? - if(ImGui::Button(core.breakpoints.contains(startAddr) ? "-" : "+")) { + if (ImGui::Button(core.breakpoints.contains(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; if(!ImGui::BeginTable("Disassembly", columns.size(), disasmTableFlags)) { - ret = false; - goto EXIT; + ImGui::End(); + return false; } - for(int i = 0; i < columns.size(); i++) - ImGui::TableSetupColumn(columns[i].name); + for(auto &[name, _] : columns) + ImGui::TableSetupColumn(name); 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 addrIsCurrent = addr == regs.nextPC; - auto addrIsBreakpoint = core.breakpoints.contains(addr); + const auto addrIsCurrent = addr == regs.nextPC; + const auto addrIsBreakpoint = core.breakpoints.contains(addr); ImColor colorChoice = ImGui::GetStyle().Colors[ImGuiCol_TableRowBg]; ImColor colorChoiceAlt = ImGui::GetStyle().Colors[ImGuiCol_TableRowBgAlt]; if(addrIsCurrent) { @@ -212,9 +211,9 @@ bool Debugger::render() { ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, colorChoiceAlt.Value); ImGui::TableNextRow(); - for(int i = 0; i < columns.size(); i++) { - ImGui::TableSetColumnIndex(i); - columns[i].func(addr, disasm); + for(int i = 0; auto &[_, func] : columns) { + ImGui::TableSetColumnIndex(i++); + func(addr, disasm); } ImGui::PopStyleColor(); @@ -225,7 +224,6 @@ bool Debugger::render() { RegisterView(); -EXIT: ImGui::End(); - return ret; + return true; } diff --git a/src/frontend/Debugger.hpp b/src/frontend/Debugger.hpp index 17f44fe0..659e2b7d 100644 --- a/src/frontend/Debugger.hpp +++ b/src/frontend/Debugger.hpp @@ -10,7 +10,7 @@ class Debugger final { static constexpr auto MAX_LINES_OF_DISASM = 150; struct Column { - const char* name; + const char* name = nullptr; void (*func)(s64, Disassembler::DisassemblyResult&) = nullptr; }; @@ -20,7 +20,7 @@ class Debugger final { Column{"Instruction", &InstructionFunc}, }; public: - void RegisterView(); + static void RegisterView(); bool followPC = true; void Open(bool wantFollowPC = true) { enabled = true; followPC = wantFollowPC; } void Close() { enabled = false; } diff --git a/src/frontend/SettingsWindow.cpp b/src/frontend/SettingsWindow.cpp index eb4409da..5d2c003d 100644 --- a/src/frontend/SettingsWindow.cpp +++ b/src/frontend/SettingsWindow.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -31,7 +30,7 @@ bool SettingsWindow::render() { applyEnabled = false; Options::GetInstance().Apply(); - for (auto &tab : tabs | std::views::values) { + for (const auto &tab : tabs | std::views::values) { tab->modified = false; } }