From a8671f7a6af647da460192e4da408bea3ed3cb55 Mon Sep 17 00:00:00 2001 From: TomCh Date: Sat, 23 May 2020 18:40:12 +0100 Subject: [PATCH] Debugger: Extend 'cycles' command to do (partial) timings relative to a user-specified instruction (#787) (PR #789) --- source/Debugger/Debug.cpp | 15 +++++++++++++-- source/Debugger/Debugger_Commands.cpp | 1 + source/Debugger/Debugger_Display.cpp | 9 ++++++++- source/Debugger/Debugger_Display.h | 8 +++++--- source/Debugger/Debugger_Help.cpp | 10 ++++++++-- source/Debugger/Debugger_Types.h | 4 +++- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 4e78252b..cb69665a 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -6909,11 +6909,16 @@ Update_t CmdCyclesInfo(int nArgs) else { if (strcmp(g_aArgs[1].sArg, "abs") == 0) - g_videoScannerDisplayInfo.isAbsCycle = true; + g_videoScannerDisplayInfo.cycleMode = VideoScannerDisplayInfo::abs; else if (strcmp(g_aArgs[1].sArg, "rel") == 0) - g_videoScannerDisplayInfo.isAbsCycle = false; + g_videoScannerDisplayInfo.cycleMode = VideoScannerDisplayInfo::rel; + else if (strcmp(g_aArgs[1].sArg, "part") == 0) + g_videoScannerDisplayInfo.cycleMode = VideoScannerDisplayInfo::part; else return Help_Arg_1(CMD_CYCLES_INFO); + + if (g_videoScannerDisplayInfo.cycleMode == VideoScannerDisplayInfo::part) + CmdCyclesReset(0); } TCHAR sText[CONSOLE_WIDTH]; @@ -6923,6 +6928,12 @@ Update_t CmdCyclesInfo(int nArgs) return UPDATE_ALL; } +Update_t CmdCyclesReset(int /*nArgs*/) +{ + g_videoScannerDisplayInfo.savedCumulativeCycles = g_nCumulativeCycles; + return UPDATE_ALL; +} + // View ___________________________________________________________________________________________ // See: CmdWindowViewOutput (int nArgs) diff --git a/source/Debugger/Debugger_Commands.cpp b/source/Debugger/Debugger_Commands.cpp index 487350bf..42b7fc57 100644 --- a/source/Debugger/Debugger_Commands.cpp +++ b/source/Debugger/Debugger_Commands.cpp @@ -123,6 +123,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA {TEXT("PAGEDOWN4K" ) , CmdCursorPageDown4K , CMD_CURSOR_PAGE_DOWN_4K , "Scroll down 4096 bytes" }, // Ctrl // Cycles info {TEXT("CYCLES") , CmdCyclesInfo , CMD_CYCLES_INFO, "Cycles display configuration" }, + {TEXT("RCC") , CmdCyclesReset , CMD_CYCLES_RESET, "Reset cycles counter" }, // Disassembler Data {TEXT("Z") , CmdDisasmDataDefByte1 , CMD_DISASM_DATA , "Treat byte [range] as data" }, {TEXT("X") , CmdDisasmDataDefCode , CMD_DISASM_CODE , "Treat byte [range] as code" }, diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index cd16dc73..fbd99901 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -3789,8 +3789,15 @@ void DrawVideoScannerInfo (int line) PrintText("cycles:", rect); rect.left += nameWidth * nFontWidth; + UINT cycles = 0; + if (g_videoScannerDisplayInfo.cycleMode == VideoScannerDisplayInfo::abs) + cycles = (UINT)g_nCumulativeCycles; + else if (g_videoScannerDisplayInfo.cycleMode == VideoScannerDisplayInfo::rel) + cycles = g_videoScannerDisplayInfo.cycleDelta; + else // "part" + cycles = (UINT)g_videoScannerDisplayInfo.lastCumulativeCycles - (UINT)g_videoScannerDisplayInfo.savedCumulativeCycles; + char sValue[10]; - const UINT cycles = g_videoScannerDisplayInfo.isAbsCycle ? (UINT)g_nCumulativeCycles : g_videoScannerDisplayInfo.cycleDelta; sprintf_s(sValue, sizeof(sValue), "%08X", cycles); PrintText(sValue, rect); } diff --git a/source/Debugger/Debugger_Display.h b/source/Debugger/Debugger_Display.h index ae7d11c8..fb4deedd 100644 --- a/source/Debugger/Debugger_Display.h +++ b/source/Debugger/Debugger_Display.h @@ -102,15 +102,17 @@ class VideoScannerDisplayInfo { public: - VideoScannerDisplayInfo(void) : isDecimal(false), isHorzReal(false), isAbsCycle(false), + VideoScannerDisplayInfo(void) : isDecimal(false), isHorzReal(false), cycleMode(rel), lastCumulativeCycles(0), cycleDelta(0) {} - void Reset(void) { lastCumulativeCycles = g_nCumulativeCycles; cycleDelta = 0; } + void Reset(void) { lastCumulativeCycles = savedCumulativeCycles = g_nCumulativeCycles; cycleDelta = 0; } bool isDecimal; bool isHorzReal; - bool isAbsCycle; + enum CYCLE_MODE {abs=0, rel, part}; + CYCLE_MODE cycleMode; unsigned __int64 lastCumulativeCycles; + unsigned __int64 savedCumulativeCycles; UINT cycleDelta; }; diff --git a/source/Debugger/Debugger_Help.cpp b/source/Debugger/Debugger_Help.cpp index b2d4ea9e..d190a865 100644 --- a/source/Debugger/Debugger_Help.cpp +++ b/source/Debugger/Debugger_Help.cpp @@ -1408,11 +1408,17 @@ Update_t CmdHelpSpecific (int nArgs) break; // Cycles case CMD_CYCLES_INFO: - ConsoleColorizePrint(sText, " Usage: "); + ConsoleColorizePrint(sText, " Usage: "); ConsoleBufferPush(" Where:"); - ConsoleBufferPush(" changes cycle output to absolute/relative"); + ConsoleBufferPush(" abs = absolute number of cycles since power-on"); + ConsoleBufferPush(" rel = number of cycles since last step or breakpoint"); + ConsoleBufferPush(" part= number of cycles relative to current instruction"); + break; + case CMD_CYCLES_RESET: + ConsoleBufferPush(" Use in conjunctioned with 'cycles part' to reset to current instruction"); break; // Video-Scanner + case CMD_VIDEO_SCANNER_INFO: ConsoleColorizePrint(sText, " Usage: "); ConsoleBufferPush(" Where:"); diff --git a/source/Debugger/Debugger_Types.h b/source/Debugger/Debugger_Types.h index eb38cf46..c28c9b53 100644 --- a/source/Debugger/Debugger_Types.h +++ b/source/Debugger/Debugger_Types.h @@ -377,6 +377,7 @@ , CMD_CURSOR_PAGE_DOWN_4K // Down to nearest 4K boundary // Cycles info , CMD_CYCLES_INFO + , CMD_CYCLES_RESET // Disassembler Data , CMD_DISASM_DATA , CMD_DISASM_CODE @@ -666,7 +667,8 @@ Update_t CmdCursorPageUp4K (int nArgs); // Cycles info - Update_t CmdCyclesInfo (int nArgs); + Update_t CmdCyclesInfo (int nArgs); + Update_t CmdCyclesReset (int nArgs); // Disk Update_t CmdDisk (int nArgs);