Skip to content

Commit

Permalink
QDisasmView: tuning breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Jan 5, 2024
1 parent 3213f1f commit 765ca08
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
2 changes: 1 addition & 1 deletion emulator/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const int UKNC_SCREEN_HEIGHT = 288;
#define COLOR_JUMPNO qRgb(180, 180, 180)
#define COLOR_JUMPHINT qRgb( 40, 128, 160)
#define COLOR_HINT qRgb( 40, 40, 160)
#define COLOR_BREAKPOINT qRgb(255, 64, 64)
#define COLOR_BREAKPOINT qRgb(228, 64, 64)

QFont Common_GetMonospacedFont();
QColor Common_GetColorShifted(const QPalette& palette, QRgb rgb);
Expand Down
16 changes: 14 additions & 2 deletions emulator/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ bool Emulator_AddCPUBreakpoint(quint16 address)
}
for (int i = 0; i < MAX_BREAKPOINTCOUNT; i++) // Put in the first empty cell
{
if (m_EmulatorCPUBps[i] > address) // found the place
{
memcpy(m_EmulatorCPUBps + i + 1, m_EmulatorCPUBps + i, sizeof(uint16_t) * (m_wEmulatorCPUBpsCount - i));
m_EmulatorCPUBps[i] = address;
break;
}
if (m_EmulatorCPUBps[i] == 0177777)
{
m_EmulatorCPUBps[i] = address;
Expand All @@ -226,6 +232,12 @@ bool Emulator_AddPPUBreakpoint(quint16 address)
}
for (int i = 0; i < MAX_BREAKPOINTCOUNT; i++) // Put in the first empty cell
{
if (m_EmulatorPPUBps[i] > address) // found the place
{
memcpy(m_EmulatorPPUBps + i + 1, m_EmulatorPPUBps + i, sizeof(uint16_t) * (m_wEmulatorPPUBpsCount - i));
m_EmulatorPPUBps[i] = address;
break;
}
if (m_EmulatorPPUBps[i] == 0177777)
{
m_EmulatorPPUBps[i] = address;
Expand All @@ -247,7 +259,7 @@ bool Emulator_RemoveCPUBreakpoint(quint16 address)
m_wEmulatorCPUBpsCount--;
if (m_wEmulatorCPUBpsCount > i) // fill the hole
{
m_EmulatorCPUBps[i] = m_EmulatorCPUBps[m_wEmulatorCPUBpsCount];
memcpy(m_EmulatorCPUBps + i, m_EmulatorCPUBps + i + 1, sizeof(uint16_t) * (m_wEmulatorCPUBpsCount - i));
m_EmulatorCPUBps[m_wEmulatorCPUBpsCount] = 0177777;
}
return true;
Expand All @@ -267,7 +279,7 @@ bool Emulator_RemovePPUBreakpoint(quint16 address)
m_wEmulatorPPUBpsCount--;
if (m_wEmulatorPPUBpsCount > i) // fill the hole
{
m_EmulatorPPUBps[i] = m_EmulatorPPUBps[m_wEmulatorPPUBpsCount];
memcpy(m_EmulatorPPUBps + i, m_EmulatorPPUBps + i + 1, sizeof(uint16_t) * (m_wEmulatorPPUBpsCount - i));
m_EmulatorPPUBps[m_wEmulatorPPUBpsCount] = 0177777;
}
return true;
Expand Down
44 changes: 34 additions & 10 deletions emulator/qdisasmview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


const int MAX_DISASMLINECOUNT = 50;
const int HINT_CHARPOS = 52;


//////////////////////////////////////////////////////////////////////
Expand All @@ -30,6 +31,7 @@ QDisasmView::QDisasmView()
this->setMinimumSize(cxChar * 55, cyLine * 10 + cyLine / 2);

setFocusPolicy(Qt::ClickFocus);
setMouseTracking(true);
}

void QDisasmView::updateWindowText()
Expand Down Expand Up @@ -65,6 +67,16 @@ void QDisasmView::contextMenuEvent(QContextMenuEvent *event)
menu.exec(event->globalPos());
}

void QDisasmView::mouseMoveEvent(QMouseEvent * event)
{
if (event->x() < m_cxDisasmBreakpointZone)
setCursor(QCursor(Qt::PointingHandCursor));
else
setCursor(QCursor(Qt::ArrowCursor));

QWidget::mouseMoveEvent(event);
}

void QDisasmView::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
Expand Down Expand Up @@ -347,14 +359,14 @@ void QDisasmView::updateData()
}
}

void QDisasmView::drawJump(QPainter &painter, int yFrom, int delta, int x, int cyLine, QColor color)
void QDisasmView::drawJump(QPainter &painter, int yFrom, int delta, int x, QColor color)
{
int dist = abs(delta);
if (dist < 2) dist = 2;
if (dist > 20) dist = 16;

int yTo = yFrom + delta * cyLine - (cyLine * 2 / 3);
yFrom -= cyLine / 3;
int yTo = yFrom + delta * m_cyDisasmLine - (m_cyDisasmLine * 2 / 3);
yFrom -= m_cyDisasmLine / 3;

QPainterPath path;
path.moveTo(x, yFrom);
Expand Down Expand Up @@ -419,28 +431,33 @@ int QDisasmView::drawDisassemble(QPainter &painter, CProcessor *pProc, quint16 c
int cyLine = fontmetrics.lineSpacing();
m_cxDisasmBreakpointZone = cxChar * 2;
m_cyDisasmLine = cyLine;
int xHint = HINT_CHARPOS * cxChar;
QColor colorBackground = palette().color(QPalette::Base);
QColor colorText = palette().color(QPalette::Text);
QColor colorPrev = Common_GetColorShifted(palette(), COLOR_PREVIOUS);
QColor colorChanged = Common_GetColorShifted(palette(), COLOR_VALUECHANGED);
QColor colorValue = Common_GetColorShifted(palette(), COLOR_VALUE);
QColor colorValueRom = Common_GetColorShifted(palette(), COLOR_VALUEROM);
QColor colorSubtitle = Common_GetColorShifted(palette(), COLOR_SUBTITLE);
QColor colorJump = Common_GetColorShifted(palette(), COLOR_JUMP);
QColor colorWindow = palette().color(QPalette::Window);

quint16 proccurrent = pProc->GetPC();

// Draw breakpoint zone
painter.fillRect(0, 0, m_cxDisasmBreakpointZone, this->height(), colorWindow);

// Draw current line background
if (m_SubtitleItems.isEmpty()) //NOTE: Subtitles can move lines down
{
int yCurrent = (proccurrent - (current - 5)) * cyLine + fontmetrics.descent();
QColor colorCurrent = palette().color(QPalette::Window);
painter.fillRect(0, yCurrent, this->width(), cyLine, colorCurrent);
painter.fillRect(0, yCurrent, xHint, cyLine, colorWindow);
}

int y = cyLine;
for (int lineindex = 0; lineindex < m_DisasmLineItems.count(); lineindex++) // Draw the lines
{
DisasmLineItem& lineitem = m_DisasmLineItems[lineindex];
const DisasmLineItem& lineitem = m_DisasmLineItems[lineindex];
if (lineitem.type == LINETYPE_NONE)
break;
quint16 address = lineitem.address;
Expand All @@ -460,11 +477,12 @@ int QDisasmView::drawDisassemble(QPainter &painter, CProcessor *pProc, quint16 c

if (Emulator_IsBreakpoint(m_okDisasmProcessor, address)) // Breakpoint
{
drawBreakpoint(painter, cxChar / 2, y, cxChar);
drawBreakpoint(painter, 0, y, (cxChar + cyLine) / 2);
}

painter.setPen(colorText);
DrawOctalValue(painter, 5 * cxChar, y, address); // Address

// Value at the address
quint16 value = lineitem.value;
int memorytype = lineitem.addrtype;
Expand Down Expand Up @@ -525,17 +543,23 @@ int QDisasmView::drawDisassemble(QPainter &painter, CProcessor *pProc, quint16 c
QColor jumpcolor = colorJump;
if (address == proccurrent)
jumpcolor = Common_GetColorShifted(palette(), m_okDisasmJumpPredict ? COLOR_JUMPYES : COLOR_JUMPNO);
drawJump(painter, y, delta, posAfterArgs * cxChar, cyLine, jumpcolor);
drawJump(painter, y, delta, posAfterArgs * cxChar, jumpcolor);
}
}

if (address == proccurrent && *m_strDisasmHint != 0) // For current instruction, draw "Instruction Hints"
{
int cyHint = cyLine * (*m_strDisasmHint2 == 0 ? 1 : 2);
QLinearGradient gradient(xHint, 0, xHint + 24 * cxChar, 0);
gradient.setColorAt(0, colorWindow);
gradient.setColorAt(1, colorBackground);
painter.fillRect(xHint, y - cyLine + fontmetrics.descent(), 24 * cxChar, cyHint, gradient);

QColor hintcolor = Common_GetColorShifted(palette(), isjump ? COLOR_JUMPHINT : COLOR_HINT);
painter.setPen(hintcolor);
painter.drawText(52 * cxChar, y, m_strDisasmHint);
painter.drawText(xHint, y, m_strDisasmHint);
if (*m_strDisasmHint2 != 0)
painter.drawText(52 * cxChar, y + cyLine, m_strDisasmHint2);
painter.drawText(xHint, y + cyLine, m_strDisasmHint2);
painter.setPen(colorText);
}
}
Expand Down
5 changes: 3 additions & 2 deletions emulator/qdisasmview.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public slots:
void contextMenuEvent(QContextMenuEvent *event) override;
void focusInEvent(QFocusEvent *) override;
void focusOutEvent(QFocusEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void mousePressEvent(QMouseEvent *) override;

void parseSubtitles(QTextStream& stream);
Expand All @@ -84,8 +85,8 @@ public slots:

const DisasmSubtitleItem * findSubtitle(quint16 address, quint16 typemask);

void drawJump(QPainter& painter, int yFrom, int delta, int x, int cyLine, QColor color);
void drawBreakpoint(QPainter& painter, int x, int y, int cyLine);
void drawJump(QPainter& painter, int yFrom, int delta, int x, QColor color);
void drawBreakpoint(QPainter& painter, int x, int y, int size);
int drawDisassemble(QPainter& painter, CProcessor* pProc, quint16 current, quint16 previous);
};

Expand Down

0 comments on commit 765ca08

Please sign in to comment.