From 9d4f293a3c13ec406089a977a8db477afef02dcb Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sat, 15 May 2021 13:32:34 +0100 Subject: [PATCH] More Debugger related work. Signed-off-by: Andrea Odetti --- source/CMakeLists.txt | 1 - source/frontends/ncurses/nframe.cpp | 5 ++ source/frontends/qt/qtframe.cpp | 5 ++ source/frontends/sdl/imgui/sdlsettings.cpp | 54 ++++++++++++++++------ source/frontends/sdl/imgui/sdlsettings.h | 5 ++ source/frontends/sdl/sdlframe.cpp | 24 ++++++++-- source/linux/duplicates/AppleWin.cpp | 3 -- 7 files changed, 74 insertions(+), 23 deletions(-) delete mode 100644 source/linux/duplicates/AppleWin.cpp diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 68b648f2..dd4a2b91 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -81,7 +81,6 @@ set(SOURCE_FILES linux/network/tfe2.cpp linux/network/slirp2.cpp - linux/duplicates/AppleWin.cpp linux/duplicates/Debugger_Display.cpp linux/duplicates/Debugger_Win32.cpp linux/duplicates/Joystick.cpp diff --git a/source/frontends/ncurses/nframe.cpp b/source/frontends/ncurses/nframe.cpp index 8ec1900a..e3f0f24f 100644 --- a/source/frontends/ncurses/nframe.cpp +++ b/source/frontends/ncurses/nframe.cpp @@ -366,3 +366,8 @@ namespace na2 } } + +void SingleStep(bool /* bReinit */) +{ + +} diff --git a/source/frontends/qt/qtframe.cpp b/source/frontends/qt/qtframe.cpp index 39a77f8c..305de1b9 100644 --- a/source/frontends/qt/qtframe.cpp +++ b/source/frontends/qt/qtframe.cpp @@ -142,3 +142,8 @@ BYTE* QtFrame::GetResource(WORD id, LPCSTR lpType, DWORD expectedSize) return reinterpret_cast(myResource.data()); } + +void SingleStep(bool /* bReinit */) +{ + +} diff --git a/source/frontends/sdl/imgui/sdlsettings.cpp b/source/frontends/sdl/imgui/sdlsettings.cpp index 9bfd4328..0bf6aab6 100644 --- a/source/frontends/sdl/imgui/sdlsettings.cpp +++ b/source/frontends/sdl/imgui/sdlsettings.cpp @@ -18,7 +18,6 @@ #include "Utilities.h" #include "Memory.h" -#include "Debugger/Debug.h" #include "Debugger/DebugDefs.h" #include "Tfe/tfe.h" @@ -854,20 +853,15 @@ namespace sa2 const ImGuiTableFlags flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_ScrollY; if (ImGui::BeginTable("Console", 1, flags)) { - for (int i = 0; i < CONSOLE_HEIGHT; ++i) + for (int i = g_nConsoleDisplayTotal; i >= CONSOLE_FIRST_LINE; --i) { - const conchar_t * src = g_aConsoleDisplay[CONSOLE_HEIGHT - i - 1]; + const conchar_t * src = g_aConsoleDisplay[i]; char line[CONSOLE_WIDTH + 1]; - COLORREF currentColor = ConsoleColor_GetColor(src[0]); - line[0] = ConsoleChar_GetChar(src[0]); - size_t length = 1; - if (!line[0]) - { - continue; - } + size_t length = 0; ImGui::TableNextRow(); ImGui::TableNextColumn(); + COLORREF currentColor = DebuggerGetColor( FG_CONSOLE_OUTPUT ); const auto textAndReset = [&line, &length, & currentColor] () { line[length] = 0; @@ -876,7 +870,7 @@ namespace sa2 ImGui::TextColored(color, "%s", line); }; - for (size_t j = length; j < CONSOLE_WIDTH; ++j) + for (size_t j = 0; j < CONSOLE_WIDTH; ++j) { const conchar_t g = src[j]; if (ConsoleColor_IsColorOrMouse(g)) @@ -888,10 +882,26 @@ namespace sa2 currentColor = ConsoleColor_GetColor(g); } line[length] = ConsoleChar_GetChar(g); - ++length; + if (line[length]) + { + ++length; + } + else + { + break; + } } textAndReset(); } + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(g_aConsoleInput); + + if (myScrollConsole) + { + ImGui::SetScrollHereY(1.0f); + myScrollConsole = false; + } ImGui::EndTable(); } } @@ -900,7 +910,8 @@ namespace sa2 { if (ImGui::Begin("Debugger", &myShowDebugger)) { - if (ImGui::BeginTabBar("Settings")) + ImGui::BeginChild("Console", ImVec2(0, -ImGui::GetFrameHeightWithSpacing())); + if (ImGui::BeginTabBar("Tabs")) { if (ImGui::BeginTabItem("CPU")) { @@ -931,6 +942,10 @@ namespace sa2 { frame->ChangeMode(MODE_PAUSED); } + if ((ImGui::SameLine(), ImGui::Button("Debug"))) + { + frame->ChangeMode(MODE_DEBUG); + } ImGui::SameLine(); ImGui::Text("%016llu - %04X", g_nCumulativeCycles, regs.pc); @@ -961,9 +976,20 @@ namespace sa2 } ImGui::EndTabBar(); } + ImGui::EndChild(); + if (ImGui::InputText("Prompt", myInputBuffer, IM_ARRAYSIZE(myInputBuffer), ImGuiInputTextFlags_EnterReturnsTrue)) + { + for (const char *ch = myInputBuffer; *ch; ++ch) + { + DebuggerInputConsoleChar(*ch); + } + DebuggerProcessKey(VK_RETURN); + myScrollConsole = true; + myInputBuffer[0] = 0; + ImGui::SetKeyboardFocusHere(-1); + } } ImGui::End(); } - } diff --git a/source/frontends/sdl/imgui/sdlsettings.h b/source/frontends/sdl/imgui/sdlsettings.h index d228606b..afe83f9b 100644 --- a/source/frontends/sdl/imgui/sdlsettings.h +++ b/source/frontends/sdl/imgui/sdlsettings.h @@ -2,6 +2,8 @@ #include "frontends/sdl/imgui/gles.h" #include "frontends/sdl/sdirectsound.h" +#include "Debugger/Debug.h" +#include "Debugger/Debugger_Console.h" namespace sa2 { @@ -24,6 +26,9 @@ namespace sa2 bool mySyncCPU = true; bool myShowAbout = false; + bool myScrollConsole = true; + char myInputBuffer[CONSOLE_WIDTH] = ""; + int myStepCycles = 0; int mySpeakerVolume; int myMockingboardVolume; diff --git a/source/frontends/sdl/sdlframe.cpp b/source/frontends/sdl/sdlframe.cpp index 33b7daa6..21f141ef 100644 --- a/source/frontends/sdl/sdlframe.cpp +++ b/source/frontends/sdl/sdlframe.cpp @@ -17,6 +17,7 @@ #include "Mockingboard.h" #include "MouseInterface.h" #include "Log.h" +#include "Debugger/Debug.h" #include "linux/paddle.h" #include "linux/keyboard.h" @@ -532,12 +533,20 @@ namespace sa2 { // when running in adaptive speed // the value msNextFrame is only a hint for when the next frame will arrive - if (g_nAppMode == MODE_RUNNING) + switch (g_nAppMode) { - const size_t cyclesToExecute = mySpeed.getCyclesTillNext(msNextFrame * 1000); - Execute(cyclesToExecute); - } - // else do nothing, it is either paused, debugged or stepped + case MODE_RUNNING: + { + const size_t cyclesToExecute = mySpeed.getCyclesTillNext(msNextFrame * 1000); + Execute(cyclesToExecute); + break; + } + case MODE_STEPPING: + { + DebugContinueStepping(); + break; + } + }; } void SDLFrame::ChangeMode(const AppMode_e mode) @@ -572,3 +581,8 @@ namespace sa2 } } + +void SingleStep(bool /* bReinit */) +{ + dynamic_cast(GetFrame()).Execute(0); +} diff --git a/source/linux/duplicates/AppleWin.cpp b/source/linux/duplicates/AppleWin.cpp deleted file mode 100644 index e671e1a0..00000000 --- a/source/linux/duplicates/AppleWin.cpp +++ /dev/null @@ -1,3 +0,0 @@ -void SingleStep(bool /* bReinit */) -{ -}