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 4, 2024
1 parent cb8c356 commit a8bb386
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
/emulator/debug
/emulator/release
/emulator/Makefile.*
Expand Down
2 changes: 1 addition & 1 deletion emulator/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const int NEON_SCREEN_HEIGHT = 300;
#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
8 changes: 7 additions & 1 deletion emulator/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,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 @@ -233,7 +239,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 Down
36 changes: 26 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 @@ -29,6 +30,7 @@ QDisasmView::QDisasmView()
this->setMinimumSize(cxChar * 55, cyLine * 10 + cyLine / 2);

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

void QDisasmView::updateWindowText()
Expand All @@ -55,6 +57,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 @@ -330,14 +342,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 @@ -402,7 +414,7 @@ int QDisasmView::drawDisassemble(QPainter &painter, CProcessor *pProc, quint16 c
int cyLine = fontmetrics.lineSpacing();
m_cxDisasmBreakpointZone = cxChar * 2;
m_cyDisasmLine = cyLine;
int xHint = 52 * cxChar;
int xHint = HINT_CHARPOS * cxChar;
QColor colorBackground = palette().color(QPalette::Base);
QColor colorText = palette().color(QPalette::Text);
QColor colorPrev = Common_GetColorShifted(palette(), COLOR_PREVIOUS);
Expand All @@ -411,21 +423,24 @@ int QDisasmView::drawDisassemble(QPainter &painter, CProcessor *pProc, quint16 c
QColor colorValueRom = Common_GetColorShifted(palette(), COLOR_VALUEROM);
QColor colorSubtitle = Common_GetColorShifted(palette(), COLOR_SUBTITLE);
QColor colorJump = Common_GetColorShifted(palette(), COLOR_JUMP);
QColor colorCurrent = palette().color(QPalette::Window);
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();
painter.fillRect(0, yCurrent, xHint, 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 @@ -445,11 +460,12 @@ int QDisasmView::drawDisassemble(QPainter &painter, CProcessor *pProc, quint16 c

if (Emulator_IsBreakpoint(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 @@ -510,15 +526,15 @@ 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, colorCurrent);
gradient.setColorAt(0, colorWindow);
gradient.setColorAt(1, colorBackground);
painter.fillRect(xHint, y - cyLine + fontmetrics.descent(), 24 * cxChar, cyHint, gradient);

Expand Down
5 changes: 3 additions & 2 deletions emulator/qdisasmview.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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 @@ -80,8 +81,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 a8bb386

Please sign in to comment.