Skip to content

Commit

Permalink
Tuning debugger views
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Jan 8, 2025
1 parent 040896f commit 0f67b25
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 21 deletions.
1 change: 1 addition & 0 deletions emulator/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const int BK_SCREEN_HEIGHT = 256;
#define COLOR_JUMPNO qRgb(192,192,192)
#define COLOR_JUMPHINT qRgb(40,128,160)
#define COLOR_HINT qRgb(40,40,160)
#define COLOR_BREAKPOINT qRgb(255,0,0)

QFont Common_GetMonospacedFont();
QColor Common_GetColorShifted(const QPalette& palette, QRgb rgb);
Expand Down
32 changes: 24 additions & 8 deletions emulator/qdebugview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,31 @@ void QDebugMemoryMapCtrl::paintEvent(QPaintEvent * /*event*/)
painter.drawRect(x1, y1, x2 - x1, y2 - y1);
painter.drawText(x, ybase + 2, "000000");

for (int i = 1; i < 8; i++)
for (int i = 0; i < 8; i++)
{
int ycur = y2 - cyLine * i * 2;
if (i < 7)
painter.drawLine(x1, ycur, x1 + 8, ycur);
else
painter.drawLine(x1, ycur, x2, ycur);
quint16 addr = (quint16)i * 020000;
DrawOctalValue(painter, x, y2 - cyLine * i * 2 + cyLine / 3, addr);
int yp = y2 - cyLine * i * 2;
quint16 address = (quint16)i * 020000;

if (i > 0)
{
painter.drawLine(x1, yp, x2, yp);
DrawOctalValue(painter, x, y2 - cyLine * i * 2 + cyLine / 3, address);
}

int addrtype;
g_pBoard->GetWordView(address, getProc()->GetHALT(), false, &addrtype);
QString addrtypestr;
switch (addrtype & (ADDRTYPE_RAM | ADDRTYPE_ROM | ADDRTYPE_IO | ADDRTYPE_DENY))
{
case ADDRTYPE_ROM: addrtypestr = "ROM"; break;
case ADDRTYPE_RAM: addrtypestr = "RAM"; break;
case ADDRTYPE_IO: addrtypestr = "I/O"; break;
case ADDRTYPE_DENY: addrtypestr = "N/A"; break;
default:
addrtypestr.clear();
}
if (!addrtypestr.isEmpty())
painter.drawText(xtype, yp - (cyLine * 2) / 3, addrtypestr);
}

quint16 sp = getProc()->GetSP();
Expand Down
54 changes: 41 additions & 13 deletions emulator/qdisasmview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include <QFileDialog>
#include <QMenu>
#include <QStyleOptionFocusRect>
#include "main.h"
#include "qdisasmview.h"
#include "Emulator.h"
#include "emubase/Emubase.h"


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


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

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

void QDisasmView::updateWindowText()
Expand All @@ -54,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 @@ -98,7 +111,7 @@ void QDisasmView::showHideSubtitles()
else
{
QFileDialog dlg;
dlg.setNameFilter(tr("BKBTL subtitles (*.lst)"));
dlg.setNameFilter(tr("Disasm subtitles (*.lst)"));
if (dlg.exec() == QDialog::Rejected)
return;
QString fileName = dlg.selectedFiles().at(0);
Expand Down Expand Up @@ -384,7 +397,7 @@ void QDisasmView::paintEvent(QPaintEvent * /*event*/)

void QDisasmView::drawBreakpoint(QPainter& painter, int x, int y, int size)
{
QColor colorBreakpoint = qRgb(192, 0, 0);
QColor colorBreakpoint = Common_GetColorShifted(palette(), COLOR_BREAKPOINT);
painter.setBrush(colorBreakpoint);
painter.setPen(colorBreakpoint);
painter.drawEllipse(x, y, size, -size);
Expand All @@ -401,28 +414,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 @@ -442,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 @@ -511,14 +530,23 @@ int QDisasmView::drawDisassemble(QPainter &painter, CProcessor *pProc, quint16 c
}
}

if (address == proccurrent && *m_strDisasmHint != 0) // For current instruction, draw "Instruction Hints"
if (address == proccurrent)
{
QColor hintcolor = Common_GetColorShifted(palette(), isjump ? COLOR_JUMPHINT : COLOR_HINT);
painter.setPen(hintcolor);
painter.drawText(52 * cxChar, y, m_strDisasmHint);
if (*m_strDisasmHint2 != 0)
painter.drawText(52 * cxChar, y + cyLine, m_strDisasmHint2);
painter.setPen(colorText);
int cyHint = cyLine * (*m_strDisasmHint2 == 0 ? 1 : 2);
QLinearGradient gradient(xHint - cxChar, 0, xHint + 25 * cxChar, 0);
gradient.setColorAt(0, colorWindow);
gradient.setColorAt(1, colorBackground);
painter.fillRect(xHint - cxChar, y - cyLine + fontmetrics.descent(), 25 * cxChar, cyHint, gradient);

if (*m_strDisasmHint != 0) // For current instruction, draw "Instruction Hints"
{
QColor hintcolor = Common_GetColorShifted(palette(), isjump ? COLOR_JUMPHINT : COLOR_HINT);
painter.setPen(hintcolor);
painter.drawText(xHint, y, m_strDisasmHint);
if (*m_strDisasmHint2 != 0)
painter.drawText(xHint, y + cyLine, m_strDisasmHint2);
painter.setPen(colorText);
}
}
}

Expand Down
1 change: 1 addition & 0 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 Down

0 comments on commit 0f67b25

Please # to comment.