Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portable debugui.cpp #253

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ add_executable (pureikyubu
src/bootrtc.cpp
src/config.cpp
src/cp.cpp
src/cuinull.cpp
src/debug.cpp
src/debugui.cpp
src/di.cpp
src/dsp.cpp
src/dspcore.cpp
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ Build using Visual Studio 2022. To build, open `scripts/pureikyubu.sln` and clic

### Generic Linux (Ubuntu) version

The Linux build does not yet have support for graphics, sound and a full Debug UI. All emulation output can be seen only through debug messages.

```
# Choose a suitable folder to store a clone of the repository, cd there and then
git clone https://github.com/emu-russia/pureikyubu.git
cd pureikyubu
cd build
cmake ..
make
./pureikyubu pong.dol
```

Requirements: CMake, pthread.
Expand Down
6 changes: 6 additions & 0 deletions scripts/pureikyubu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
<ClCompile Include="..\src\config.cpp" />
<ClCompile Include="..\src\cp.cpp" />
<ClCompile Include="..\src\cui.cpp" />
<ClCompile Include="..\src\cuinull.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\src\debug.cpp" />
<ClCompile Include="..\src\debugui.cpp" />
<ClCompile Include="..\src\di.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions scripts/pureikyubu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,8 @@
<ClCompile Include="..\src\su.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\cuinull.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
45 changes: 41 additions & 4 deletions src/cui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ namespace Debug
Sleep(100);
}

/// <summary>
/// Convert Windows VK to abstract Cui VK, to improve code portability.
/// </summary>
static CuiVkey WindowVKToCuiVkey(WORD vk)
{
switch (vk)
{
case VK_UP: return CuiVkey::Up;
case VK_DOWN: return CuiVkey::Down;
case VK_LEFT: return CuiVkey::Left;
case VK_RIGHT: return CuiVkey::Right;
case VK_PRIOR: return CuiVkey::PageUp;
case VK_NEXT: return CuiVkey::PageDown;
case VK_HOME: return CuiVkey::Home;
case VK_END: return CuiVkey::End;
case VK_ESCAPE: return CuiVkey::Escape;
case VK_RETURN: return CuiVkey::Enter;
case VK_BACK: return CuiVkey::Backspace;
case VK_DELETE: return CuiVkey::Delete;
case VK_F1: return CuiVkey::F1;
case VK_F2: return CuiVkey::F2;
case VK_F3: return CuiVkey::F3;
case VK_F4: return CuiVkey::F4;
case VK_F5: return CuiVkey::F5;
case VK_F6: return CuiVkey::F6;
case VK_F7: return CuiVkey::F7;
case VK_F8: return CuiVkey::F8;
case VK_F9: return CuiVkey::F9;
case VK_F10: return CuiVkey::F10;
case VK_F11: return CuiVkey::F11;
case VK_F12: return CuiVkey::F12;
default: break;
}
return CuiVkey::Unknown;
}

void Cui::CuiThreadProc(void* Parameter)
{
INPUT_RECORD record;
Expand Down Expand Up @@ -103,15 +139,16 @@ namespace Debug
bool shiftPressed = (ctrl & SHIFT_PRESSED) != 0;
bool ctrlPressed = (ctrl & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) != 0;

cui->OnKeyPress(ascii, vcode, shiftPressed, ctrlPressed);
CuiVkey cui_vk = WindowVKToCuiVkey(vcode);
cui->OnKeyPress(ascii, cui_vk, shiftPressed, ctrlPressed);

for (auto it = cui->windows.begin(); it != cui->windows.end(); ++it)
{
CuiWindow* wnd = *it;

if (wnd->active)
{
wnd->OnKeyPress(ascii, vcode, shiftPressed, ctrlPressed);
wnd->OnKeyPress(ascii, cui_vk, shiftPressed, ctrlPressed);
}
}
}
Expand All @@ -131,7 +168,7 @@ namespace Debug
}
}

void Cui::OnKeyPress(char Ascii, int Vkey, bool shift, bool ctrl)
void Cui::OnKeyPress(char Ascii, CuiVkey Vkey, bool shift, bool ctrl)
{
}

Expand Down Expand Up @@ -188,7 +225,7 @@ namespace Debug

#pragma region "CuiWindow"

CuiWindow::CuiWindow(RECT& rect, std::string name, Cui* parent)
CuiWindow::CuiWindow(CuiRect& rect, std::string name, Cui* parent)
{
wndRect = rect;
wndName = name;
Expand Down
52 changes: 48 additions & 4 deletions src/cui.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,46 @@ namespace Debug
White,
};

/// <summary>
/// In order not to use Win32 RECT this intermediate portable representation is used.
/// </summary>
struct CuiRect
{
long left;
long top;
long right;
long bottom;
};

enum class CuiVkey
{
Unknown = 0,
Up,
Down,
Left,
Right,
PageUp,
PageDown,
Home,
End,
Escape,
Enter,
Backspace,
Delete,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
};

class Cui;

class CuiWindow
Expand All @@ -34,11 +74,13 @@ namespace Debug

std::string wndName;

#ifdef _WINDOWS
// This is where the contents of the window are stored. The region data is displayed by the wndRect coordinates.
CHAR_INFO* backBuf = nullptr;
#endif

// Window layout in CUI.
RECT wndRect;
CuiRect wndRect;

void PutChar(CuiColor back, CuiColor front, int x, int y, char c);

Expand All @@ -50,14 +92,14 @@ namespace Debug
Cui* cui = nullptr;

public:
CuiWindow(RECT& rect, std::string name, Cui* parent);
CuiWindow(CuiRect& rect, std::string name, Cui* parent);
virtual ~CuiWindow();

// Redraw itself if invalidated.
virtual void OnDraw() = 0;

// Key event. Comes only if the window is active (SetFocus true)
virtual void OnKeyPress(char Ascii, int Vkey, bool shift, bool ctrl) = 0;
virtual void OnKeyPress(char Ascii, CuiVkey Vkey, bool shift, bool ctrl) = 0;

void Invalidate() { invalidated = true; }
bool NeedRedraw() { return invalidated; }
Expand All @@ -79,8 +121,10 @@ namespace Debug
{
std::list<CuiWindow*> windows;

#ifdef _WINDOWS
HANDLE StdInput;
HANDLE StdOutput;
#endif

size_t conWidth;
size_t conHeight;
Expand All @@ -101,7 +145,7 @@ namespace Debug
// A global CUI key event handler (for example, to switch focus between windows).
// In addition, each active window also receives key event.

virtual void OnKeyPress(char Ascii, int Vkey, bool shift, bool ctrl);
virtual void OnKeyPress(char Ascii, CuiVkey Vkey, bool shift, bool ctrl);

void ShowCursor(bool show);
void SetCursor(int x, int y);
Expand Down
35 changes: 35 additions & 0 deletions src/cuinull.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Empty CUI implementation, can be used for custom Cui implementations (e.g. imgui).
#include "pch.h"

namespace Debug
{
// CuiWindow

CuiWindow::CuiWindow(CuiRect& rect, std::string name, Cui* parent) {}
CuiWindow::~CuiWindow() {}

void CuiWindow::Print(CuiColor back, CuiColor front, int x, int y, std::string text) {}
void CuiWindow::Print(CuiColor front, int x, int y, std::string text) {}
void CuiWindow::Print(CuiColor back, CuiColor front, int x, int y, const char* fmt, ...) {}
void CuiWindow::Print(CuiColor front, int x, int y, const char* fmt, ...) {}
void CuiWindow::Fill(CuiColor back, CuiColor front, char c) {}
void CuiWindow::FillLine(CuiColor back, CuiColor front, int y, char c) {}

void CuiWindow::SetCursor(int x, int y) {}

// Cui

Cui::Cui(std::string title, size_t width, size_t height) {}
Cui::~Cui() {}

void Cui::AddWindow(CuiWindow* wnd) {}

void Cui::SetWindowFocus(const std::string& name) {}

void Cui::OnKeyPress(char Ascii, CuiVkey Vkey, bool shift, bool ctrl) {}

void Cui::ShowCursor(bool show) {}
void Cui::SetCursor(int x, int y) {}

void Cui::InvalidateAll() {}
}
9 changes: 9 additions & 0 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ namespace Debug
static Json::Value* ShowHelp(std::vector<std::string>& args)
{
JDI::Hub.Help();
Report(Channel::Header, "## Debugger F-Keys\n");
Report(Channel::Norm, "- F1: Registers (left/right arrows to select registers)\n");
Report(Channel::Norm, "- F2: Memory dump\n");
Report(Channel::Norm, "- F3: Instruction disassembly\n");
Report(Channel::Norm, "- F5: Start emulation to breakpoint/pause emulation (break)\n");
Report(Channel::Norm, "- F9: Toogle instruction breakpoint\n");
Report(Channel::Norm, "- F10: Step over\n");
Report(Channel::Norm, "- F11: Step into\n");
Report(Channel::Norm, "- F12: Skip instruction\n");
return nullptr;
}

Expand Down
Loading