From 3db06d7426d68c22631250fac57ac3ecb034e578 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Wed, 16 Jul 2014 16:20:03 +0200 Subject: [PATCH] Highlight arguments from disassembler selection --- pcsx2/gui/Debugger/CtrlDisassemblyView.cpp | 67 +++++++++++++++++++++- pcsx2/gui/Debugger/CtrlDisassemblyView.h | 3 + 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp b/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp index 9af9e05253..d722e5b0c0 100644 --- a/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp +++ b/pcsx2/gui/Debugger/CtrlDisassemblyView.cpp @@ -312,6 +312,69 @@ int getBackgroundColor(unsigned int address) return colors[n%6]; } +std::set CtrlDisassemblyView::getSelectedLineArguments() { + std::set args; + + DisassemblyLineInfo line; + for (u32 addr = selectRangeStart; addr < selectRangeEnd; addr += 4) { + manager.getLine(addr, displaySymbols, line); + size_t p = 0, nextp = line.params.find(','); + while (nextp != line.params.npos) { + args.insert(line.params.substr(p, nextp - p)); + p = nextp + 1; + nextp = line.params.find(',', p); + } + if (p < line.params.size()) { + args.insert(line.params.substr(p)); + } + } + + return args; +} + +void CtrlDisassemblyView::drawArguments(wxDC& dc, const DisassemblyLineInfo &line, int x, int y, wxColor& textColor, + const std::set ¤tArguments) +{ + if (line.params.empty()) + return; + + // Don't highlight the selected lines. + if (isInInterval(selectRangeStart, selectRangeEnd - selectRangeStart, line.info.opcodeAddress)) + { + dc.DrawText(wxString(line.params.c_str(),wxConvUTF8),x,y); + return; + } + + wxColor highlightedColor = wxColor(textColor == 0xFF0000FF ? 0xFFAABB77 : 0xFFAABB00); + + size_t p = 0, nextp = line.params.find(','); + while (nextp != line.params.npos) { + const std::string arg = line.params.substr(p, nextp - p); + if (currentArguments.find(arg) != currentArguments.end() && textColor != 0xFFFFFFFF) + { + dc.SetTextForeground(highlightedColor); + } + dc.DrawText(wxString(arg.c_str(),wxConvUTF8),x,y); + x += arg.size()*charWidth; + + p = nextp + 1; + nextp = line.params.find(',', p); + + dc.SetTextForeground(textColor); + dc.DrawText(L",",x,y); + x += charWidth; + } + if (p < line.params.size()) { + const std::string arg = line.params.substr(p); + if (currentArguments.find(arg) != currentArguments.end() && textColor != 0xFFFFFFFF) + { + dc.SetTextForeground(highlightedColor); + } + dc.DrawText(wxString(arg.c_str(),wxConvUTF8),x,y); + dc.SetTextForeground(textColor); + } +} + void CtrlDisassemblyView::render(wxDC& dc) { // init stuff @@ -347,6 +410,8 @@ void CtrlDisassemblyView::render(wxDC& dc) std::map addressPositions; unsigned int address = windowStart; + + const std::set currentArguments = getSelectedLineArguments(); DisassemblyLineInfo line; for (int i = 0; i < visibleRows+1; i++) { @@ -404,7 +469,7 @@ void CtrlDisassemblyView::render(wxDC& dc) dc.SetFont(font); dc.DrawText(wxString(addressText,wxConvUTF8),pixelPositions.addressStart,rowY1+2); - dc.DrawText(wxString(line.params.c_str(),wxConvUTF8),pixelPositions.argumentsStart,rowY1+2); + drawArguments(dc, line, pixelPositions.argumentsStart, rowY1 + 2, textColor, currentArguments); if (isInInterval(address,line.totalSize,cpu->getPC())) dc.DrawText(L"■",pixelPositions.opcodeStart-(charWidth+1),rowY1); diff --git a/pcsx2/gui/Debugger/CtrlDisassemblyView.h b/pcsx2/gui/Debugger/CtrlDisassemblyView.h index ce2fd11042..d06e377fa5 100644 --- a/pcsx2/gui/Debugger/CtrlDisassemblyView.h +++ b/pcsx2/gui/Debugger/CtrlDisassemblyView.h @@ -64,6 +64,9 @@ private: void copyInstructions(u32 startAddr, u32 endAddr, bool withDisasm); void disassembleToFile(); void editBreakpoint(); + std::set getSelectedLineArguments(); + void drawArguments(wxDC& dc, const DisassemblyLineInfo &line, int x, int y, wxColor& textColor, + const std::set ¤tArguments); void postEvent(wxEventType type, wxString text); void postEvent(wxEventType type, int value);