From 957e15f23a9f5671c4fc9ec867969105b9ee4ccc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 13 Feb 2022 10:53:01 -0800 Subject: [PATCH] GE Debugger: Highlight changed matrix values. --- Windows/GEDebugger/TabVertices.cpp | 55 +++++++++++++++++++++++++++--- Windows/GEDebugger/TabVertices.h | 6 +++- Windows/W32Util/Misc.cpp | 8 ++++- Windows/W32Util/Misc.h | 2 ++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/Windows/GEDebugger/TabVertices.cpp b/Windows/GEDebugger/TabVertices.cpp index 24215e2307..0576b96032 100644 --- a/Windows/GEDebugger/TabVertices.cpp +++ b/Windows/GEDebugger/TabVertices.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include "Common/CommonTypes.h" #include "Common/StringUtils.h" #include "Core/System.h" @@ -28,6 +29,7 @@ #include "GPU/GeDisasm.h" #include "GPU/Common/GPUDebugInterface.h" #include "GPU/Debugger/Breakpoints.h" +#include "GPU/Debugger/Stepping.h" static const GenericListViewColumn vertexListCols[] = { { L"X", 0.1f }, @@ -370,14 +372,57 @@ CtrlMatrixList::CtrlMatrixList(HWND hwnd) Update(); } -bool CtrlMatrixList::GetValue(int row, int col, float &val) { +bool CtrlMatrixList::OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) { + const auto state = gpuDebug->GetGState(); + const auto lastState = GPUStepping::LastState(); + + bool changed = false; + if (col < MATRIXLIST_COL_0) { + for (int c = MATRIXLIST_COL_0; c <= MATRIXLIST_COL_3; ++c) { + changed = changed || ColChanged(lastState, state, row, c); + } + } else { + changed = ColChanged(lastState, state, row, col); + } + + // At the column level, we have to reset the color back. + static int lastRow = -1; + static COLORREF rowDefaultText; + if (lastRow != row) { + rowDefaultText = msg->clrText; + lastRow = row; + } + + if (changed) { + msg->clrText = RGB(255, 0, 0); + return true; + } else if (msg->clrText != rowDefaultText) { + msg->clrText = rowDefaultText; + return true; + } + + return false; +} + +bool CtrlMatrixList::ColChanged(const GPUgstate &lastState, const GPUgstate &state, int row, int col) { + union { + float f; + uint32_t u; + } newVal, oldVal; + if (!GetValue(state, row, col, newVal.f) || !GetValue(lastState, row, col, oldVal.f)) + return false; + + // If there's any difference in bits, highlight. + return newVal.u != oldVal.u; +} + +bool CtrlMatrixList::GetValue(const GPUgstate &state, int row, int col, float &val) { if (!gpuDebug || row < 0 || row >= MATRIXLIST_ROW_COUNT || col < 0 || col >= MATRIXLIST_COL_COUNT) return false; if (col < MATRIXLIST_COL_0) col = MATRIXLIST_COL_0; - auto state = gpuDebug->GetGState(); if (row >= MATRIXLIST_ROW_BONE_0_0) { int b = (row - MATRIXLIST_ROW_BONE_0_0) / 3; int r = (row - MATRIXLIST_ROW_BONE_0_0) % 3; @@ -419,7 +464,7 @@ void CtrlMatrixList::GetColumnText(wchar_t *dest, int row, int col) { } float val; - if (!GetValue(row, col, val)) { + if (!GetValue(gpuDebug->GetGState(), row, col, val)) { wcscpy(dest, L"Invalid"); return; } @@ -534,7 +579,7 @@ void CtrlMatrixList::OnDoubleClick(int row, int column) { } float val; - if (!GetValue(row, column, val)) + if (!GetValue(gpuDebug->GetGState(), row, column, val)) return; std::string strvalue = StringFromFormat("%f", val); @@ -594,7 +639,7 @@ void CtrlMatrixList::OnRightClick(int row, int column, const POINT &point) { case ID_DISASM_COPYINSTRUCTIONDISASM: { float val; - if (GetValue(row, column, val)) { + if (GetValue(gpuDebug->GetGState(), row, column, val)) { wchar_t dest[512]; swprintf(dest, 511, L"%f", val); W32Util::CopyTextToClipboard(GetHandle(), dest); diff --git a/Windows/GEDebugger/TabVertices.h b/Windows/GEDebugger/TabVertices.h index 1b02d734f8..116f60f06c 100644 --- a/Windows/GEDebugger/TabVertices.h +++ b/Windows/GEDebugger/TabVertices.h @@ -83,8 +83,12 @@ protected: void OnDoubleClick(int row, int column) override; void OnRightClick(int row, int column, const POINT &point) override; + bool ListenColPrePaint() override { return true; } + bool OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) override; + private: - bool GetValue(int row, int col, float &val); + bool GetValue(const GPUgstate &state, int row, int col, float &val); + bool ColChanged(const GPUgstate &lastState, const GPUgstate &state, int row, int col); void ToggleBreakpoint(int row); }; diff --git a/Windows/W32Util/Misc.cpp b/Windows/W32Util/Misc.cpp index 02a234eb50..37bdfd475e 100644 --- a/Windows/W32Util/Misc.cpp +++ b/Windows/W32Util/Misc.cpp @@ -234,7 +234,7 @@ int GenericListControl::HandleNotify(LPARAM lParam) { return 0; } - if (mhdr->code == NM_CUSTOMDRAW && ListenRowPrePaint()) { + if (mhdr->code == NM_CUSTOMDRAW && (ListenRowPrePaint() || ListenColPrePaint())) { LPNMLVCUSTOMDRAW msg = (LPNMLVCUSTOMDRAW)lParam; switch (msg->nmcd.dwDrawStage) { case CDDS_PREPAINT: @@ -244,6 +244,12 @@ int GenericListControl::HandleNotify(LPARAM lParam) { if (OnRowPrePaint((int)msg->nmcd.dwItemSpec, msg)) { return CDRF_NEWFONT; } + return ListenColPrePaint() ? CDRF_NOTIFYSUBITEMDRAW : CDRF_DODEFAULT; + + case CDDS_SUBITEM | CDDS_ITEMPREPAINT: + if (OnColPrePaint((int)msg->nmcd.dwItemSpec, msg->iSubItem, msg)) { + return CDRF_NEWFONT; + } return CDRF_DODEFAULT; } diff --git a/Windows/W32Util/Misc.h b/Windows/W32Util/Misc.h index e3c8630fc0..8a43c55b59 100644 --- a/Windows/W32Util/Misc.h +++ b/Windows/W32Util/Misc.h @@ -64,7 +64,9 @@ protected: virtual void OnToggle(int item, bool newValue) { }; virtual bool ListenRowPrePaint() { return false; } + virtual bool ListenColPrePaint() { return false; } virtual bool OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) { return false; } + virtual bool OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) { return false; } private: static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);