Skip to content

Commit

Permalink
WIP; fixing problem with texture rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Jul 16, 2024
1 parent 56e3f6a commit 3d763ad
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 97 deletions.
43 changes: 7 additions & 36 deletions emulator/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,6 @@ void DebugLogFormat(LPCTSTR pszFormat, ...)
const TCHAR* REGISTER_NAME[] = { _T("R0"), _T("R1"), _T("R2"), _T("R3"), _T("R4"), _T("R5"), _T("SP"), _T("PC") };


void GetFontWidthAndHeight(HDC hdc, int* pWidth, int* pHeight)
{
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
if (pWidth != NULL)
*pWidth = tm.tmAveCharWidth;
if (pHeight != NULL)
*pHeight = tm.tmHeight;
}

// Print octal 16-bit value to buffer
// buffer size at least 7 characters
void PrintOctalValue(TCHAR* buffer, WORD value)
Expand Down Expand Up @@ -226,41 +216,22 @@ void PrintBinaryValue(TCHAR* buffer, WORD value)
}

// Parse octal value from text
BOOL ParseOctalValue(LPCTSTR text, WORD* pValue)
bool ParseOctalValue(const char* text, uint16_t* pValue)
{
WORD value = 0;
TCHAR* pChar = (TCHAR*) text;
char* pChar = (char*) text;
for (int p = 0; ; p++)
{
if (p > 6) return FALSE;
TCHAR ch = *pChar; pChar++;
if (p > 6) return false;
char ch = *pChar; pChar++;
if (ch == 0) break;
if (ch < _T('0') || ch > _T('7')) return FALSE;
if (ch < '0' || ch > '7') return false;
value = (value << 3);
TCHAR digit = ch - _T('0');
char digit = ch - '0';
value += digit;
}
*pValue = value;
return TRUE;
}

void DrawOctalValue(HDC hdc, int x, int y, WORD value)
{
TCHAR buffer[7];
PrintOctalValue(buffer, value);
TextOut(hdc, x, y, buffer, (int)_tcsnlen(buffer, 6));
}
void DrawHexValue(HDC hdc, int x, int y, WORD value)
{
TCHAR buffer[7];
PrintHexValue(buffer, value);
TextOut(hdc, x, y, buffer, (int)_tcsnlen(buffer, 6));
}
void DrawBinaryValue(HDC hdc, int x, int y, WORD value)
{
TCHAR buffer[17];
PrintBinaryValue(buffer, value);
TextOut(hdc, x, y, buffer, 16);
return true;
}

void CopyTextToClipboard(LPCTSTR text)
Expand Down
7 changes: 1 addition & 6 deletions emulator/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,14 @@ const int UKNC_SCREEN_WIDTH = 640;
const int UKNC_SCREEN_HEIGHT = 288;


void GetFontWidthAndHeight(HDC hdc, int* pWidth, int* pHeight);
void PrintOctalValue(TCHAR* buffer, WORD value);
void PrintHexValue(TCHAR* buffer, WORD value);
void PrintBinaryValue(TCHAR* buffer, WORD value);
BOOL ParseOctalValue(LPCTSTR text, WORD* pValue);
void DrawOctalValue(HDC hdc, int x, int y, WORD value);
void DrawHexValue(HDC hdc, int x, int y, WORD value);
void DrawBinaryValue(HDC hdc, int x, int y, WORD value);
bool ParseOctalValue(const char* text, uint16_t* pValue);

void CopyTextToClipboard(LPCTSTR text);

TCHAR Translate_KOI8R(BYTE ch);
void DrawCharKOI8R(HDC hdc, int x, int y, BYTE ch);

BOOL ShowSaveDialog(HWND hwndOwner, LPCTSTR strTitle, LPCTSTR strFilter, LPCTSTR strDefExt, TCHAR* bufFileName);
BOOL ShowOpenDialog(HWND hwndOwner, LPCTSTR strTitle, LPCTSTR strFilter, TCHAR* bufFileName);
Expand Down
24 changes: 17 additions & 7 deletions emulator/ConsoleView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ void ConsoleView_ImGuiWidget()
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), ImGuiChildFlags_None,
ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_AlwaysVerticalScrollbar))
{
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::Selectable("Clear"))
ConsoleView_ClearConsole();
ImGui::EndPopup();
}

//TODO: ImGuiListClipper
for (std::string item : m_ConsoleItems)
{
Expand All @@ -66,6 +59,9 @@ void ConsoleView_ImGuiWidget()
}
}

if (ImGui::IsWindowHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Right))
ImGui::OpenPopup("Console_context");

// Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame.
// Using a scrollbar or mouse-wheel will take away from the bottom edge.
if (m_ScrollToBottom || (/*AutoScroll &&*/ ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
Expand All @@ -91,6 +87,13 @@ void ConsoleView_ImGuiWidget()
}
ImGui::EndDisabled();

if (ImGui::BeginPopupContextItem("Console_context"))
{
if (ImGui::Selectable("Clear"))
ConsoleView_ClearConsole();
ImGui::EndPopup();
}

ImGui::End();
}

Expand Down Expand Up @@ -155,6 +158,13 @@ void ConsoleView_StepOver()
// Execute command
ConsoleView_DoConsoleCommand();
}
void ConsoleView_AddBreakpoint(uint16_t address)
{
// Put command to console prompt
sprintf(m_ConsoleInputBuf, "b%06ho", address);
// Execute command
ConsoleView_DoConsoleCommand();
}
void ConsoleView_DeleteBreakpoint(uint16_t address)
{
// Put command to console prompt
Expand Down
36 changes: 33 additions & 3 deletions emulator/DebugViews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void StackView_ImGuiWidget()
// Breakpoints

uint16_t m_BreakpointsContextAddress = 0177777;
char m_BreakpointBuf[7] = { 0 };

void Breakpoints_ImGuiWidget()
{
Expand All @@ -129,6 +130,7 @@ void Breakpoints_ImGuiWidget()
uint16_t addressBreakpointClick = 0177777;

const uint16_t* pbps = g_okDebugCpuPpu ? Emulator_GetCPUBreakpointList() : Emulator_GetPPUBreakpointList();
int bpcount = 0;
if (pbps != nullptr && *pbps != 0177777)
{
while (*pbps != 0177777)
Expand All @@ -143,10 +145,10 @@ void Breakpoints_ImGuiWidget()
if (isDeleteHovered)
{
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), ICON_FA_MINUS_CIRCLE);
ImGui::SameLine(0.0f, 0.0f);
ImGui::SameLine();
}

ImGui::SetCursorPosX(24.0f);
ImGui::SetCursorPosX(26.0f);
uint16_t address = *pbps;
ImGui::Text("%06ho", address);

Expand All @@ -158,6 +160,7 @@ void Breakpoints_ImGuiWidget()
if (isDeleteHovered && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) // Click on Delete sign
addressBreakpointClick = address;

bpcount++;
pbps++;
}
}
Expand All @@ -166,7 +169,7 @@ void Breakpoints_ImGuiWidget()
ConsoleView_DeleteBreakpoint(addressBreakpointClick);

bool linesHovered = ImGui::IsMouseHoveringRect(linesMin, linesMax);
if (!linesHovered && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) // Context menu in empty area
if (ImGui::IsWindowHovered() && !linesHovered && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) // Context menu in empty area
{
m_BreakpointsContextAddress = 0177777;
ImGui::OpenPopup("Breakpoints_context");
Expand All @@ -185,6 +188,33 @@ void Breakpoints_ImGuiWidget()
ImGui::EndPopup();
}

if (bpcount < MAX_BREAKPOINTCOUNT)
{
ImGui::TextDisabled(ICON_FA_PLUS_CIRCLE);
ImGui::SameLine();
ImGui::SetCursorPosX(26.0f);
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll;
uint16_t address;
bool addressParsed = false;
if (*m_BreakpointBuf != 0)
addressParsed = ParseOctalValue(m_BreakpointBuf, &address);
ImGui::PushItemWidth(ImGui::CalcTextSize("000000 ").x);
if (ImGui::InputText("###BreakpointNew", m_BreakpointBuf, IM_ARRAYSIZE(m_BreakpointBuf), input_text_flags))
{
if (addressParsed)
{
ConsoleView_AddBreakpoint(address);
*m_BreakpointBuf = 0;
}
}
if (*m_BreakpointBuf != 0 && !addressParsed)
{
ImGui::SameLine();
ImGui::Text(ICON_FA_EXCLAMATION_TRIANGLE);
}
ImGui::PopItemWidth();
}

ImGui::End();
}

Expand Down
25 changes: 18 additions & 7 deletions emulator/DisasmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void Disasm_DrawForRunningEmulator()

void DisasmView_DrawJump(ImDrawList* draw_list, ImVec2 lineMin, int delta, float cyLine)
{
ImU32 col = ImGui::ColorConvertFloat4ToU32(ImVec4(0.67f, 0.67f, 0.67f, 0.67f));
ImU32 col = ImGui::ColorConvertFloat4ToU32(ImVec4(0.5f, 0.7f, 1.0f, 0.67f));

int dist = abs(delta);
if (dist < 2) dist = 2;
Expand All @@ -115,14 +115,25 @@ void DisasmView_DrawJump(ImDrawList* draw_list, ImVec2 lineMin, int delta, float
float yTo = lineMin.y + delta * cyLine;

ImVec2 p1(lineMin.x + cyLine * 0.2f, lineMin.y + cyLine / 2.0f); // point from
ImVec2 p2(lineMin.x + dist * cyLine * 0.4f, p1.y);
ImVec2 p3(lineMin.x + dist * cyLine * 1.2f, yTo);
ImVec2 p2(lineMin.x + dist * cyLine * 0.32f, p1.y);
ImVec2 p3(lineMin.x + dist * cyLine * 0.9f, yTo);
ImVec2 p4(lineMin.x, yTo - cyLine * 0.1f); // point to
ImVec2 p5(lineMin.x + cyLine * 0.6f, yTo - cyLine * 0.15f); // arrow
ImVec2 p6(lineMin.x + cyLine * 0.6f, yTo + cyLine * 0.15f); // arrow
draw_list->AddBezierCubic(p1, p2, p3, p4, col, 1.0);
draw_list->AddLine(p4, p5, col);
draw_list->AddLine(p4, p6, col);

// Arrow sides
ImVec2 p5(lineMin.x + cyLine * 0.8f, yTo); // upper side
ImVec2 p6(lineMin.x + cyLine * 0.8f, yTo); // down side
if (delta > 0) // jump down
{
p5.y -= cyLine * 0.27f;
p6.y += cyLine * 0.01f;
}
else // jump up
{
p5.y -= cyLine * 0.10f;
p6.y += cyLine * 0.15f;
}
draw_list->AddTriangleFilled(p4, p5, p6, col);
}

// В режиме останова делаем подробный дизасм
Expand Down
40 changes: 16 additions & 24 deletions emulator/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ const BYTE m_arrDigitKeyScans[] =

const uint32_t ScreenView_StandardGRBColors[16 * 8] =
{
0xFF000000, 0xFF000080, 0xFF800000, 0xFF800080, 0xFF008000, 0xFf008080, 0xFF808000, 0xFF808080,
0xFF000000, 0xFF0000FF, 0xFFFF0000, 0xFFFF00FF, 0xFF00FF00, 0xFF00FFFF, 0xFFFFFF00, 0xFFFFFFFF,
0xFF000000, 0xFF000060, 0xFF800000, 0xFF800060, 0xFF008000, 0xFF008060, 0xFF808000, 0xFF808060,
0xFF000000, 0xFF0000DF, 0xFFFF0000, 0xFFFF00DF, 0xFF00FF00, 0xFF00FFDF, 0xFFFFFF00, 0xFFFFFFDF,
0xFF000000, 0xFF000080, 0xFF600000, 0xFF600080, 0xFF008000, 0xFF008080, 0xFF608000, 0xFF608080,
0xFF000000, 0xFF0000FF, 0xFFDF0000, 0xFFDF00FF, 0xFF00FF00, 0xFF00FFFF, 0xFFDFFF00, 0xFFDFFFFF,
0xFF000000, 0xFF000060, 0xFF600000, 0xFF600060, 0xFF008000, 0xFF008060, 0xFF608000, 0xFF608060,
0xFF000000, 0xFF0000DF, 0xFFDF0000, 0xFFDF00DF, 0xFF00FF00, 0xFF00FFDF, 0xFFDFFF00, 0xFFDFFFDF,
0xFF000000, 0xFF000080, 0xFF800000, 0xFF800080, 0xFF006000, 0xFF006080, 0xFF806000, 0xFF806080,
0xFF000000, 0xFF0000FF, 0xFFFF0000, 0xFFFF00FF, 0xFF00DF00, 0xFF00DFFF, 0xFFFFDF00, 0xFFFFDFFF,
0xFF000000, 0xFF000060, 0xFF800000, 0xFF800060, 0xFF006000, 0xFF006060, 0xFF806000, 0xFF806060,
0xFF000000, 0xFF0000DF, 0xFFFF0000, 0xFFFF00DF, 0xFF00DF00, 0xFF00DFDF, 0xFFFFDF00, 0xFFFFDFDF,
0xFF000000, 0xFF000080, 0xFF600000, 0xFF600080, 0xFF006000, 0xFF006080, 0xFF606000, 0xFF606080,
0xFF000000, 0xFF0000FF, 0xFFDF0000, 0xFFDF00FF, 0xFF00DF00, 0xFF00DFFF, 0xFFDFDF00, 0xFFDFDFFF,
0xFF000000, 0xFF000060, 0xFF600000, 0xFF600060, 0xFF006000, 0xFF006060, 0xFF606000, 0xFF606060,
0xFF000000, 0xFF0000DF, 0xFFDF0000, 0xFFDF00DF, 0xFF00DF00, 0xFF00DFDF, 0xFFDFDF00, 0xFFDFDFDF,
0xFF000000, 0xFF800000, 0xFF008000, 0xFF808000, 0xFF000080, 0xFF800080, 0xFF008080, 0xFF808080,
0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFFFFFF00, 0xFF0000FF, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF,
0xFF000000, 0xFF600000, 0xFF008000, 0xFF608000, 0xFF000080, 0xFF600080, 0xFF008080, 0xFF608080,
0xFF000000, 0xFFDF0000, 0xFF00FF00, 0xFFDFFF00, 0xFF0000FF, 0xFFDF00FF, 0xFF00FFFF, 0xFFDFFFFF,
0xFF000000, 0xFF800000, 0xFF006000, 0xFF806000, 0xFF000080, 0xFF800080, 0xFF006080, 0xFF806080,
0xFF000000, 0xFFFF0000, 0xFF00DF00, 0xFFFFDF00, 0xFF0000FF, 0xFFFF00FF, 0xFF00DFFF, 0xFFFFDFFF,
0xFF000000, 0xFF600000, 0xFF006000, 0xFF606000, 0xFF000080, 0xFF600080, 0xFF006080, 0xFF606080,
0xFF000000, 0xFFDF0000, 0xFF00DF00, 0xFFDFDF00, 0xFF0000FF, 0xFFDF00FF, 0xFF00DFFF, 0xFFDFDFFF,
0xFF000000, 0xFF800000, 0xFF008000, 0xFF808000, 0xFF000060, 0xFF800060, 0xFF008060, 0xFF808060,
0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFFFFFF00, 0xFF0000DF, 0xFFFF00DF, 0xFF00FFDF, 0xFFFFFFDF,
0xFF000000, 0xFF600000, 0xFF008000, 0xFF608000, 0xFF000060, 0xFF600060, 0xFF008060, 0xFF608060,
0xFF000000, 0xFFDF0000, 0xFF00FF00, 0xFFDFFF00, 0xFF0000DF, 0xFFDF00DF, 0xFF00FFDF, 0xFFDFFFDF,
0xFF000000, 0xFF800000, 0xFF006000, 0xFF806000, 0xFF000060, 0xFF800060, 0xFF006060, 0xFF806060,
0xFF000000, 0xFFFF0000, 0xFF00DF00, 0xFFFFDF00, 0xFF0000DF, 0xFFFF00DF, 0xFF00DFDF, 0xFFFFDFDF,
0xFF000000, 0xFF600000, 0xFF006000, 0xFF606000, 0xFF000060, 0xFF600060, 0xFF006060, 0xFF606060,
0xFF000000, 0xFFDF0000, 0xFF00DF00, 0xFFDFDF00, 0xFF0000DF, 0xFFDF00DF, 0xFF00DFDF, 0xFFDFDFDF,
};


Expand Down Expand Up @@ -720,12 +720,6 @@ bool Emulator_SystemFrame()
double dFramesPerSecond = m_nFrameCount * 1000.0 / nTicksElapsed;
double dSpeed = dFramesPerSecond / 25.0 * 100;
g_dFramesPercent = dSpeed;
//TCHAR buffer[16];
//_sntprintf(buffer, sizeof(buffer) / sizeof(TCHAR) - 1, _T("%03.f%%"), dSpeed);
//MainWindow_SetStatusbarText(StatusbarPartFPS, buffer);

//bool floppyEngine = g_pBoard->IsFloppyEngineOn();
//MainWindow_SetStatusbarText(StatusbarPartFloppyEngine, floppyEngine ? _T("Motor") : nullptr);

m_nFrameCount = 0;
m_dwTickCount = dwCurrentTicks;
Expand All @@ -744,15 +738,13 @@ bool Emulator_SystemFrame()

TCHAR buffer[20];
_sntprintf(buffer, sizeof(buffer) / sizeof(TCHAR) - 1, _T("Uptime: %02d:%02d:%02d"), hours, minutes, seconds);
//MainWindow_SetStatusbarText(StatusbarPartUptime, buffer);
}

// Update "Sound" indicator every 5 frames
m_nEmulatorSoundChanges += g_pBoard->GetSoundChanges();
if (m_nUptimeFrameCount % 5 == 0)
{
bool soundOn = m_nEmulatorSoundChanges > 0;
//MainWindow_SetStatusbarText(StatusbarPartSound, soundOn ? _T("Sound") : nullptr);
m_nEmulatorSoundChanges = 0;
}

Expand Down
1 change: 1 addition & 0 deletions emulator/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void ConsoleView_ImGuiWidget();
void ConsoleView_Print(const char* message);
void ConsoleView_StepInto();
void ConsoleView_StepOver();
void ConsoleView_AddBreakpoint(uint16_t address);
void ConsoleView_DeleteBreakpoint(uint16_t address);
void ConsoleView_DeleteAllBreakpoints();

Expand Down
31 changes: 27 additions & 4 deletions emulator/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,47 @@ void ImGuiMainMenu()
{
if (!g_okEmulatorRunning)
{
if (ImGui::MenuItem("Run"))
if (ImGui::MenuItem(ICON_FA_PLAY " Run"))
Emulator_Start();
}
else
{
if (ImGui::MenuItem("Stop"))
if (ImGui::MenuItem(ICON_FA_PAUSE " Stop"))
Emulator_Stop();
}
if (ImGui::MenuItem("Reset"))
if (ImGui::MenuItem(ICON_FA_REDO " Reset"))
Emulator_Reset();


bool autostart = Settings_GetAutostart();
if (ImGui::MenuItem("Autostart", nullptr, &autostart))
{
Settings_SetAutostart(!Settings_GetAutostart());
}

ImGui::Separator();

WORD speed = Settings_GetRealSpeed();
bool checked25 = speed == 0x7ffe;
ImGui::BeginDisabled(checked25);
if (ImGui::MenuItem("Speed 25%", nullptr, &checked25)) MainWindow_DoEmulatorSpeed(0x7ffe);
ImGui::EndDisabled();
bool checked50 = speed == 0x7fff;
ImGui::BeginDisabled(checked50);
if (ImGui::MenuItem("Speed 50%", nullptr, &checked50)) MainWindow_DoEmulatorSpeed(0x7fff);
ImGui::EndDisabled();
bool checked100 = speed == 1;
ImGui::BeginDisabled(checked100);
if (ImGui::MenuItem("Speed 100%", nullptr, &checked100)) MainWindow_DoEmulatorSpeed(1);
ImGui::EndDisabled();
bool checked200 = speed == 200;
ImGui::BeginDisabled(checked200);
if (ImGui::MenuItem("Speed 200%", nullptr, &checked200)) MainWindow_DoEmulatorSpeed(2);
ImGui::EndDisabled();
bool checkedMax = speed == 0;
ImGui::BeginDisabled(checkedMax);
if (ImGui::MenuItem("Speed MAX", nullptr, &checkedMax)) MainWindow_DoEmulatorSpeed(0);
ImGui::EndDisabled();

ImGui::EndMenu();
}
if (ImGui::BeginMenu("Debug"))
Expand Down
6 changes: 6 additions & 0 deletions emulator/ScreenView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,11 @@ void ScreenView_ScanKeyboard()
}
}

// External key event - e.g. from KeyboardView
void ScreenView_KeyEvent(BYTE keyscan, BOOL pressed)
{
ScreenView_PutKeyEventToQueue(MAKEWORD(keyscan, pressed ? 128 : 0));
}


//////////////////////////////////////////////////////////////////////
Loading

0 comments on commit 3d763ad

Please sign in to comment.