From 765ca089daf6d363c600d342b2a5235aec62a372 Mon Sep 17 00:00:00 2001 From: Nikita Zimin Date: Fri, 5 Jan 2024 14:09:20 +0300 Subject: [PATCH] QDisasmView: tuning breakpoints --- emulator/Common.h | 2 +- emulator/Emulator.cpp | 16 +++++++++++++-- emulator/qdisasmview.cpp | 44 +++++++++++++++++++++++++++++++--------- emulator/qdisasmview.h | 5 +++-- 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/emulator/Common.h b/emulator/Common.h index b05d824..7700545 100644 --- a/emulator/Common.h +++ b/emulator/Common.h @@ -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); diff --git a/emulator/Emulator.cpp b/emulator/Emulator.cpp index d820b83..e5e0f27 100644 --- a/emulator/Emulator.cpp +++ b/emulator/Emulator.cpp @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/emulator/qdisasmview.cpp b/emulator/qdisasmview.cpp index 5c99912..381574c 100644 --- a/emulator/qdisasmview.cpp +++ b/emulator/qdisasmview.cpp @@ -10,6 +10,7 @@ const int MAX_DISASMLINECOUNT = 50; +const int HINT_CHARPOS = 52; ////////////////////////////////////////////////////////////////////// @@ -30,6 +31,7 @@ QDisasmView::QDisasmView() this->setMinimumSize(cxChar * 55, cyLine * 10 + cyLine / 2); setFocusPolicy(Qt::ClickFocus); + setMouseTracking(true); } void QDisasmView::updateWindowText() @@ -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) @@ -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); @@ -419,6 +431,8 @@ 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); @@ -426,21 +440,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 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; @@ -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; @@ -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); } } diff --git a/emulator/qdisasmview.h b/emulator/qdisasmview.h index 7d81887..f3874a4 100644 --- a/emulator/qdisasmview.h +++ b/emulator/qdisasmview.h @@ -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); @@ -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); };