Skip to content

Commit

Permalink
Debugger breakpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Aug 1, 2020
1 parent af0d798 commit 6378c32
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 51 deletions.
63 changes: 59 additions & 4 deletions emulator/ConsoleView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ void ConsoleView_ShowHelp()
_T(" rN XXXXXX Set register N to value XXXXXX; N=0..7,ps\r\n")
_T(" s Step Into; executes one instruction\r\n")
_T(" so Step Over; executes and stops after the current instruction\r\n")
_T(" b List breakpoints set for the current processor\r\n")
_T(" bXXXXXX Set breakpoint at address XXXXXX\r\n")
_T(" bcXXXXXX Remove breakpoint at address XXXXXX\r\n")
_T(" u Save memory dump to file memdumpXPU.bin\r\n")
_T(" udl Save display list dump to file displaylist.txt\r\n")
#if !defined(PRODUCT)
Expand Down Expand Up @@ -634,9 +637,9 @@ void DoConsoleCommand()
WORD bpaddress = (WORD)(pProc->GetPC() + instrLength * 2);

if (m_okCurrentProc)
Emulator_SetCPUBreakpoint(bpaddress);
Emulator_SetTempCPUBreakpoint(bpaddress);
else
Emulator_SetPPUBreakpoint(bpaddress);
Emulator_SetTempPPUBreakpoint(bpaddress);
Emulator_Start();
}
break;
Expand Down Expand Up @@ -716,17 +719,69 @@ void DoConsoleCommand()
{
if (m_okCurrentProc)
{
Emulator_SetCPUBreakpoint(value);
Emulator_SetTempCPUBreakpoint(value);
Emulator_Start();
}
else
{
Emulator_SetPPUBreakpoint(value);
Emulator_SetTempPPUBreakpoint(value);
Emulator_Start();
}
}
}
break;
case _T('b'):
if (command[1] == 0) // b - list breakpoints
{
const uint16_t* pbps = m_okCurrentProc ? Emulator_GetCPUBreakpointList() : Emulator_GetPPUBreakpointList();
if (pbps == nullptr || *pbps == 0177777)
{
ConsoleView_Print(_T(" No breakpoints.\r\n"));
}
else
{
while (*pbps != 0177777)
{
ConsoleView_PrintFormat(_T(" %06ho\r\n"), *pbps);
pbps++;
}
}
}
else if (command[1] == _T('c'))
{
if (command[2] == 0) // bc
{
//TODO: bc - clear all breakpoints
ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND);
}
else // bcXXXXXX - remove breakpoint XXXXXX
{
WORD value;
if (!ParseOctalValue(command + 2, &value))
ConsoleView_Print(MESSAGE_WRONG_VALUE);
else
{
bool result = m_okCurrentProc ? Emulator_RemoveCPUBreakpoint(value) : Emulator_RemovePPUBreakpoint(value);
if (!result)
ConsoleView_Print(_T(" Failed to remove breakpoint.\r\n"));
DisasmView_Redraw();
}
}
}
else // bXXXXXX - add breakpoint XXXXXX
{
WORD value;
if (! ParseOctalValue(command + 1, &value))
ConsoleView_Print(MESSAGE_WRONG_VALUE);
else
{
bool result = m_okCurrentProc ? Emulator_AddCPUBreakpoint(value) : Emulator_AddPPUBreakpoint(value);
if (!result)
ConsoleView_Print(_T(" Failed to add breakpoint.\r\n"));
DisasmView_Redraw();
}
}
break;
#if !defined(PRODUCT)
case _T('t'):
if (command[1] == _T('c')) // "tc" -- clear trace log
Expand Down
4 changes: 2 additions & 2 deletions emulator/DebugView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ void DebugView_DrawPorts(HDC hdc, BOOL okProcessor, const CMemoryController* pMe

uint16_t* addresses = okProcessor ? m_DebugViewCPUPorts : m_DebugViewPPUPorts;
int addrcount = okProcessor
? sizeof(m_DebugViewCPUPorts) / sizeof(m_DebugViewCPUPorts[0])
: sizeof(m_DebugViewPPUPorts) / sizeof(m_DebugViewPPUPorts[0]);
? sizeof(m_DebugViewCPUPorts) / sizeof(m_DebugViewCPUPorts[0])
: sizeof(m_DebugViewPPUPorts) / sizeof(m_DebugViewPPUPorts[0]);
for (int i = 0; i < addrcount; i++)
{
uint16_t address = addresses[i];
Expand Down
30 changes: 26 additions & 4 deletions emulator/DisasmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ void DisasmView_Create(HWND hwndParent, int x, int y, int width, int height)
g_hwndDisasm, NULL, g_hInst, NULL);
}

void DisasmView_Redraw()
{
RedrawWindow(g_hwndDisasm, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
}

// Adjust position of client windows
void DisasmView_AdjustWindowLayout()
{
Expand Down Expand Up @@ -914,6 +919,18 @@ int DisasmView_GetInstructionHint(const WORD* memory, const CProcessor * pProc,
return result;
}

void DisasmView_DrawBreakpoint(HDC hdc, int x, int y, int size)
{
COLORREF colorBreakpoint = Settings_GetColor(ColorDebugBreakpoint);
HBRUSH hBreakBrush = CreateSolidBrush(colorBreakpoint);
HGDIOBJ hOldBrush = SelectObject(hdc, hBreakBrush);
HGDIOBJ hOldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
Ellipse(hdc, x, y, x + size, y + size);
::SelectObject(hdc, hOldPen);
::SelectObject(hdc, hOldBrush);
::DeleteObject(hBreakBrush);
}

int DisasmView_DrawDisassemble(HDC hdc, CProcessor* pProc, WORD base, WORD previous, int x, int y)
{
int result = -1;
Expand All @@ -939,9 +956,9 @@ int DisasmView_DrawDisassemble(HDC hdc, CProcessor* pProc, WORD base, WORD previ
// Draw current line background
if (!m_okDisasmSubtitles) //NOTE: Subtitles can move lines down
{
int yCurrent = (proccurrent - (current - 5)) * cyLine;
HBRUSH hBrushCurrent = ::CreateSolidBrush(colorBackCurr);
HGDIOBJ oldBrush = ::SelectObject(hdc, hBrushCurrent);
int yCurrent = (proccurrent - (current - 5)) * cyLine;
PatBlt(hdc, 0, yCurrent, 1000, cyLine, PATCOPY);
::SelectObject(hdc, oldBrush);
::DeleteObject(hBrushCurrent);
Expand Down Expand Up @@ -981,6 +998,11 @@ int DisasmView_DrawDisassemble(HDC hdc, CProcessor* pProc, WORD base, WORD previ
}
}

if (Emulator_IsBreakpoint(m_okDisasmProcessor, address)) // Breakpoint
{
DisasmView_DrawBreakpoint(hdc, x + cxChar / 2, y, cyLine);
}

DrawOctalValue(hdc, x + 5 * cxChar, y, address); // Address
// Value at the address
WORD value = memory[index];
Expand All @@ -992,15 +1014,15 @@ int DisasmView_DrawDisassemble(HDC hdc, CProcessor* pProc, WORD base, WORD previ
// Current position
if (address == current)
{
TextOut(hdc, x + 1 * cxChar, y, _T(" >"), 3);
//TextOut(hdc, x + 2 * cxChar, y, _T(" > "), 3);
result = y; // Remember line for the focus rect
}
if (address == proccurrent)
TextOut(hdc, x + 1 * cxChar, y, _T("PC>>"), 4);
TextOut(hdc, x + 2 * cxChar, y, _T("PC>"), 3);
else if (address == previous)
{
::SetTextColor(hdc, colorPrev);
TextOut(hdc, x + 1 * cxChar, y, _T(" > "), 4);
TextOut(hdc, x + 2 * cxChar, y, _T(" > "), 3);
}

BOOL okData = FALSE;
Expand Down
Loading

0 comments on commit 6378c32

Please sign in to comment.