From 9f434fa14dd8cff1badf01f5bd3719efc308af04 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 5 Feb 2022 19:21:48 -0800 Subject: [PATCH] GE Debugger: Allow setting secondary values. This makes it convenient to update the bufw of textures or similar. --- Windows/GEDebugger/TabState.cpp | 63 ++++++++++++++++++++++++++++----- Windows/InputBox.cpp | 8 +++++ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/Windows/GEDebugger/TabState.cpp b/Windows/GEDebugger/TabState.cpp index 5cbcd46f52..09e5aeffb1 100644 --- a/Windows/GEDebugger/TabState.cpp +++ b/Windows/GEDebugger/TabState.cpp @@ -17,6 +17,8 @@ #include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" +#include "Common/Data/Text/Parsers.h" +#include "Common/StringUtils.h" #include "Windows/resource.h" #include "Windows/InputBox.h" #include "Windows/GEDebugger/GEDebugger.h" @@ -145,7 +147,6 @@ static const TabStateRow stateLightingRows[] = { { L"Light dir 1", GE_CMD_LDX1, CMD_FMT_XYZ, GE_CMD_LIGHTENABLE1, GE_CMD_LDY1, GE_CMD_LDZ1 }, { L"Light dir 2", GE_CMD_LDX2, CMD_FMT_XYZ, GE_CMD_LIGHTENABLE2, GE_CMD_LDY2, GE_CMD_LDZ2 }, { L"Light dir 3", GE_CMD_LDX3, CMD_FMT_XYZ, GE_CMD_LIGHTENABLE3, GE_CMD_LDY3, GE_CMD_LDZ3 }, - // TODO: Is this a reasonable display format? { L"Light att 0", GE_CMD_LKA0, CMD_FMT_XYZ, GE_CMD_LIGHTENABLE0, GE_CMD_LKB0, GE_CMD_LKC0 }, { L"Light att 1", GE_CMD_LKA1, CMD_FMT_XYZ, GE_CMD_LIGHTENABLE1, GE_CMD_LKB1, GE_CMD_LKC1 }, { L"Light att 2", GE_CMD_LKA2, CMD_FMT_XYZ, GE_CMD_LIGHTENABLE2, GE_CMD_LKB2, GE_CMD_LKC2 }, @@ -288,21 +289,45 @@ static void ToggleWatchList(const TabStateRow &info) { static bool ToggleBreakpoint(const TabStateRow &info) { if (IsCmdBreakpoint(info.cmd)) { RemoveCmdBreakpoint(info.cmd); - RemoveCmdBreakpoint(info.otherCmd); - RemoveCmdBreakpoint(info.otherCmd2); + if (info.otherCmd) + RemoveCmdBreakpoint(info.otherCmd); + if (info.otherCmd2) + RemoveCmdBreakpoint(info.otherCmd2); return false; } AddCmdBreakpoint(info.cmd); - if (info.otherCmd) { + if (info.otherCmd) AddCmdBreakpoint(info.otherCmd); - } - if (info.otherCmd2) { + if (info.otherCmd2) AddCmdBreakpoint(info.otherCmd2); - } return true; } +bool PromptStateValue(const TabStateRow &info, HWND hparent, const wchar_t *title, u32 &value) { + if (info.fmt == CMD_FMT_FLOAT24 || info.fmt == CMD_FMT_XYZ) { + union { + u32 u; + float f; + } temp = { value << 8 }; + + std::string strvalue = StringFromFormat("%f", temp.f); + bool res = InputBox_GetString(GetModuleHandle(NULL), hparent, title, strvalue, strvalue); + if (!res) + return false; + + // Okay, the result could be a simple float, hex (0x...), or invalid. + if (sscanf(strvalue.c_str(), "0x%08x", &value) == 1) + return true; + if (sscanf(strvalue.c_str(), "%f", &temp.f) == 1) { + value = temp.u >> 8; + return true; + } + return false; + } + return InputBox_GetHex(GetModuleHandle(NULL), hparent, title, value, value); +} + CtrlStateValues::CtrlStateValues(const TabStateRow *rows, int rowCount, HWND hwnd) : GenericListControl(hwnd, stateValuesListDef), rows_(rows), rowCount_(rowCount) { @@ -886,12 +911,32 @@ void CtrlStateValues::OnDoubleClick(int row, int column) { default: { - // TODO: Floats/etc., and things with multiple cmds. + wchar_t title[1024]; const auto state = gpuDebug->GetGState(); + u32 newValue = state.cmdmem[info.cmd] & 0x00FFFFFF; - if (InputBox_GetHex(GetModuleHandle(NULL), GetHandle(), L"New value", newValue, newValue)) { + swprintf(title, 1023, L"New value for %s", info.title); + if (PromptStateValue(info, GetHandle(), title, newValue)) { newValue |= state.cmdmem[info.cmd] & 0xFF000000; SetCmdValue(newValue); + + if (info.otherCmd) { + newValue = state.cmdmem[info.otherCmd] & 0x00FFFFFF; + swprintf(title, 1023, L"New value for %s (secondary)", info.title); + if (PromptStateValue(info, GetHandle(), title, newValue)) { + newValue |= state.cmdmem[info.otherCmd] & 0xFF000000; + SetCmdValue(newValue); + + if (info.otherCmd2) { + newValue = state.cmdmem[info.otherCmd2] & 0x00FFFFFF; + swprintf(title, 1023, L"New value for %s (tertiary)", info.title); + if (PromptStateValue(info, GetHandle(), title, newValue)) { + newValue |= state.cmdmem[info.otherCmd2] & 0xFF000000; + SetCmdValue(newValue); + } + } + } + } } } break; diff --git a/Windows/InputBox.cpp b/Windows/InputBox.cpp index 314aac514c..1d4fd02e7e 100644 --- a/Windows/InputBox.cpp +++ b/Windows/InputBox.cpp @@ -110,10 +110,18 @@ bool InputBox_GetWString(HINSTANCE hInst, HWND hParent, const wchar_t *title, co bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, const wchar_t* title, u32 defaultvalue, u32& outvalue) { + const wchar_t *defaultTitle = L"Input value"; wchar_t temp[256]; wsprintf(temp, L"%08x", defaultvalue); textBoxContents = temp; + if (title && wcslen(title) <= 0) + windowTitle = defaultTitle; + else if (title && wcslen(title) < 255) + windowTitle = title; + else + windowTitle = defaultTitle; + INT_PTR value = DialogBox(hInst, (LPCWSTR)IDD_INPUTBOX, hParent, InputBoxFunc); if (value == IDOK)