From 11e858f0f114541c8a167c1fa229fae28f8bafa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 11 Dec 2024 17:00:57 +0100 Subject: [PATCH] Add input to memview. Use step counters to control updates. --- UI/ImDebugger/ImDebugger.cpp | 16 ++++++++++++++++ UI/ImDebugger/ImDebugger.h | 3 +++ UI/ImDebugger/ImDisasmView.cpp | 32 ++++++++++++-------------------- UI/ImDebugger/ImDisasmView.h | 2 +- UI/ImDebugger/ImGe.cpp | 9 ++++++++- UI/ImDebugger/ImGe.h | 2 ++ UI/ImDebugger/ImMemView.cpp | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 75 insertions(+), 22 deletions(-) diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 9a6b58db6a..000acb35c2 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -35,6 +35,7 @@ // GPU things #include "GPU/Common/GPUDebugInterface.h" +#include "GPU/Debugger/Stepping.h" #include "UI/ImDebugger/ImDebugger.h" #include "UI/ImDebugger/ImGe.h" @@ -879,6 +880,20 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu return; } + // Watch the step counters to figure out when to update things. + + if (lastCpuStepCount_ != Core_GetSteppingCounter()) { + lastCpuStepCount_ = Core_GetSteppingCounter(); + disasm_.View().NotifyStep(); + } + + if (lastGpuStepCount_ != GPUStepping::GetSteppingCounter()) { + // A GPU step has happened since last time. This means that we should re-center the cursor. + // Snapshot(); + lastGpuStepCount_ = GPUStepping::GetSteppingCounter(); + geDebugger_.View().NotifyStep(); + } + ImControl control{}; if (ImGui::BeginMainMenuBar()) { @@ -1096,6 +1111,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu } void ImDebugger::Snapshot() { + } void ImMemWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, int index) { diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index c40c6841b1..880c4d9509 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -171,6 +171,9 @@ private: ImMemWindow mem_[4]; // We support 4 separate instances of the memory viewer. ImStructViewer structViewer_; + int lastCpuStepCount_ = -1; + int lastGpuStepCount_ = -1; + // Open variables. ImConfig cfg_{}; }; diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index 4bd26b7662..0391d15cb5 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -450,15 +450,6 @@ void ImDisasmView::Draw(ImDrawList *drawList) { ProcessKeyboardShortcuts(ImGui::IsItemFocused()); - int coreStep = Core_GetSteppingCounter(); - if (coreStep != lastSteppingCount_) { - // A step has happened since last time. This means that we should re-center the cursor. - if (followPC_) { - gotoPC(); - } - lastSteppingCount_ = coreStep; - } - if (pressed) { // INFO_LOG(Log::System, "Clicked %f,%f", mousePos.x, mousePos.y); if (mousePos.x < rowHeight_) { // Left column @@ -479,6 +470,12 @@ void ImDisasmView::Draw(ImDrawList *drawList) { drawList->PopClipRect(); } +void ImDisasmView::NotifyStep() { + if (followPC_) { + gotoPC(); + } +} + void ImDisasmView::ScrollRelative(int amount) { if (amount > 0) { windowStart_ = manager.getNthNextAddress(windowStart_, amount); @@ -763,16 +760,6 @@ void ImDisasmView::CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructions } } -void ImDisasmView::NopInstructions(u32 selectRangeStart, u32 selectRangeEnd) { - for (u32 addr = selectRangeStart; addr < selectRangeEnd; addr += 4) { - Memory::Write_U32(0, addr); - } - - if (currentMIPS) { - currentMIPS->InvalidateICache(selectRangeStart, selectRangeEnd - selectRangeStart); - } -} - void ImDisasmView::PopupMenu() { bool renameFunctionPopup = false; if (ImGui::BeginPopup("context")) { @@ -812,7 +799,12 @@ void ImDisasmView::PopupMenu() { assembleOpcode(curAddress_, ""); } if (ImGui::MenuItem("NOP instructions (destructive)")) { - NopInstructions(selectRangeStart_, selectRangeEnd_); + for (u32 addr = selectRangeStart_; addr < selectRangeEnd_; addr += 4) { + Memory::Write_U32(0, addr); + } + if (currentMIPS) { + currentMIPS->InvalidateICache(selectRangeStart_, selectRangeEnd_ - selectRangeStart_); + } } ImGui::Separator(); if (ImGui::MenuItem("Rename function")) { diff --git a/UI/ImDebugger/ImDisasmView.h b/UI/ImDebugger/ImDisasmView.h index 3cbd515720..4364fa9230 100644 --- a/UI/ImDebugger/ImDisasmView.h +++ b/UI/ImDebugger/ImDisasmView.h @@ -28,6 +28,7 @@ public: void Draw(ImDrawList *drawList); void PopupMenu(); + void NotifyStep(); void ScrollRelative(int amount); @@ -131,7 +132,6 @@ private: void updateStatusBarText(); void drawBranchLine(ImDrawList *list, Bounds rc, std::map &addressPositions, const BranchLine &line); void CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructionsMode mode); - void NopInstructions(u32 startAddr, u32 endAddr); std::set getSelectedLineArguments(); void drawArguments(ImDrawList *list, Bounds rc, const DisassemblyLineInfo &line, float x, float y, ImColor textColor, const std::set ¤tArguments); diff --git a/UI/ImDebugger/ImGe.cpp b/UI/ImDebugger/ImGe.cpp index a6a450b588..c96a38caca 100644 --- a/UI/ImDebugger/ImGe.cpp +++ b/UI/ImDebugger/ImGe.cpp @@ -14,6 +14,7 @@ #include "GPU/Debugger/State.h" #include "GPU/Debugger/GECommandTable.h" #include "GPU/Debugger/Breakpoints.h" +#include "GPU/Debugger/Stepping.h" #include "GPU/Debugger/Debugger.h" #include "GPU/GPUState.h" @@ -82,6 +83,12 @@ void DrawDebugStatsWindow(ImConfig &cfg) { ImGui::End(); } +void ImGeDisasmView::NotifyStep() { + if (followPC_) { + gotoPC_ = true; + } +} + void ImGeDisasmView::Draw(GPUDebugInterface *gpuDebug) { const u32 branchColor = 0xFFA0FFFF; const u32 gteColor = 0xFFFFEFA0; @@ -123,7 +130,7 @@ void ImGeDisasmView::Draw(GPUDebugInterface *gpuDebug) { } if (pc != 0xFFFFFFFF) { - if (gotoPC_ || followPC_) { + if (gotoPC_) { selectedAddr_ = pc; gotoPC_ = false; } diff --git a/UI/ImDebugger/ImGe.h b/UI/ImDebugger/ImGe.h index a001977cf4..5e382e22c4 100644 --- a/UI/ImDebugger/ImGe.h +++ b/UI/ImDebugger/ImGe.h @@ -28,6 +28,8 @@ public: selectedAddr_ = addr; } + void NotifyStep(); + private: u32 selectedAddr_ = INVALID_ADDR; u32 dragAddr_ = INVALID_ADDR; diff --git a/UI/ImDebugger/ImMemView.cpp b/UI/ImDebugger/ImMemView.cpp index ff767343c9..47c342e6e2 100644 --- a/UI/ImDebugger/ImMemView.cpp +++ b/UI/ImDebugger/ImMemView.cpp @@ -201,6 +201,39 @@ void ImMemView::Draw(ImDrawList *drawList) { } } + ImGuiIO& io = ImGui::GetIO(); + ImVec2 mousePos = ImVec2(io.MousePos.x - canvas_p0.x, io.MousePos.y - canvas_p0.y); + if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { + // INFO_LOG(Log::System, "Mousedown %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); + onMouseDown(mousePos.x, mousePos.y, 1); + } + if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { + // INFO_LOG(Log::CPU, "Mousedown %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); + onMouseDown(mousePos.x, mousePos.y, 2); + } + if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { + // INFO_LOG(Log::System, "Mouseup %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); + if (is_hovered) { + onMouseUp(mousePos.x, mousePos.y, 1); + } + } + if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { + // INFO_LOG(Log::System, "Mousedrag %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); + if (is_hovered) { + onMouseMove(mousePos.x, mousePos.y, 1); + } + } + + if (is_hovered) { + if (io.MouseWheel > 0.0f) { // TODO: Scale steps by the value. + windowStart_ -= 4; + } else if (io.MouseWheel < 0.0f) { + windowStart_ += 4; + } + } + + ProcessKeyboardShortcuts(ImGui::IsItemFocused()); + ImGui_PopFont(); drawList->PopClipRect(); }