Skip to content

Commit

Permalink
QMemoryView octal/hex modes
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Jan 3, 2024
1 parent 7f783ce commit 9b6f976
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 18 deletions.
1 change: 1 addition & 0 deletions emulator/QtNeonBtl.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<file>images/iconScreenshot.svg</file>
<file>images/iconDebugger.svg</file>
<file>pk11.rom</file>
<file>images/iconHex.svg</file>
</qresource>
</RCC>
10 changes: 10 additions & 0 deletions emulator/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,15 @@ bool Settings_GetDebugMemoryByte()
return value.toBool();
}

void Settings_SetDebugMemoryNumeral(quint16 mode)
{
Global_getSettings()->setValue("DebugMemoryNumeral", mode);
}
quint16 Settings_GetDebugMemoryNumeral()
{
QVariant value = Global_getSettings()->value("DebugMemoryNumeral", 0);
return (quint16)value.toUInt();
}


//////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions emulator/images/iconHex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions emulator/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void Settings_SetDebugMemoryAddress(quint16 address);
quint16 Settings_GetDebugMemoryAddress();
bool Settings_GetDebugMemoryByte();
void Settings_SetDebugMemoryByte(bool flag);
void Settings_SetDebugMemoryNumeral(quint16 mode);
quint16 Settings_GetDebugMemoryNumeral();


//////////////////////////////////////////////////////////////////////
Expand Down
77 changes: 60 additions & 17 deletions emulator/qmemoryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ static const char * MemoryView_ModeNames[] =
"CPU", "HALT", "USER"
};

enum MemoryViewNumeralMode
{
MEMMODENUM_OCT = 0,
MEMMODENUM_HEX = 1,
};


QMemoryView::QMemoryView()
{
m_Mode = Settings_GetDebugMemoryMode();
if (m_Mode > MEMMODE_LAST) m_Mode = MEMMODE_LAST;
m_ByteMode = Settings_GetDebugMemoryByte();
m_NumeralMode = Settings_GetDebugMemoryNumeral();
m_wBaseAddress = Settings_GetDebugMemoryAddress();
m_cyLineMemory = 0;
m_nPageSize = 0;
Expand Down Expand Up @@ -63,9 +70,11 @@ QMemoryView::QMemoryView()
QAction* actionGotoAddr = m_toolbar->addAction(QIcon(":/images/iconEditAddress.svg"), "");
m_toolbar->addSeparator();
QAction* actionWordByte = m_toolbar->addAction(QIcon(":/images/iconWordByte.svg"), "");
QAction* actionOctalHex = m_toolbar->addAction(QIcon(":/images/iconHex.svg"), "");

QObject::connect(actionGotoAddr, SIGNAL(triggered()), this, SLOT(gotoAddress()));
QObject::connect(actionWordByte, SIGNAL(triggered()), this, SLOT(changeWordByteMode()));
QObject::connect(actionOctalHex, SIGNAL(triggered()), this, SLOT(changeNumeralMode()));

setFocusPolicy(Qt::ClickFocus);
}
Expand Down Expand Up @@ -124,6 +133,7 @@ void QMemoryView::contextMenuEvent(QContextMenuEvent *event)

menu.addSeparator();
menu.addAction(tr("Words / Bytes"), this, SLOT(changeWordByteMode()));
menu.addAction(tr("Octal / Hex"), this, SLOT(changeNumeralMode()));

menu.exec(event->globalPos());
}
Expand All @@ -150,6 +160,15 @@ void QMemoryView::changeWordByteMode()
repaint();
}

void QMemoryView::changeNumeralMode()
{
int newMode = m_NumeralMode ^ 1;
m_NumeralMode = newMode;
Settings_SetDebugMemoryNumeral(newMode);

repaint();
}

void QMemoryView::scrollBy(qint16 delta)
{
if (delta == 0) return;
Expand Down Expand Up @@ -249,14 +268,26 @@ void QMemoryView::paintEvent(QPaintEvent * /*event*/)

m_cyLineMemory = cyLine;

if (m_NumeralMode == MEMMODENUM_OCT)
m_PostionIncrement = cxChar * 7;
else
m_PostionIncrement = cxChar * 5;
if (m_ByteMode)
m_PostionIncrement += cxChar;

char buffer[7];
const char * ADDRESS_LINE = " addr";
painter.drawText(30, cyLine, ADDRESS_LINE);
for (int j = 0; j < 8; j++)
{
_snprintf(buffer, 7, "%d", j * 2);
painter.drawText(38 + (9 + j * 7) * cxChar, cyLine, buffer);
}
const char* ADDRESS_LINE_OCT_WORDS = " addr 0 2 4 6 10 12 14 16";
const char* ADDRESS_LINE_OCT_BYTES = " addr 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17";
const char* ADDRESS_LINE_HEX_WORDS = " addr 0 2 4 6 8 a c e";
const char* ADDRESS_LINE_HEX_BYTES = " addr 0 1 2 3 4 5 6 7 8 9 a b c d e f";
if (m_NumeralMode == MEMMODENUM_OCT && !m_ByteMode)
painter.drawText(38, cyLine, ADDRESS_LINE_OCT_WORDS);
else if (m_NumeralMode == MEMMODENUM_OCT && m_ByteMode)
painter.drawText(38, cyLine, ADDRESS_LINE_OCT_BYTES);
else if (m_ByteMode)
painter.drawText(38, cyLine, ADDRESS_LINE_HEX_BYTES);
else
painter.drawText(38, cyLine, ADDRESS_LINE_HEX_WORDS);

// Calculate m_nPageSize
m_nPageSize = this->height() / cyLine - 1;
Expand All @@ -265,11 +296,13 @@ void QMemoryView::paintEvent(QPaintEvent * /*event*/)
int y = 2 * cyLine;
for (;;) // Draw lines
{
DrawOctalValue(painter, 38 + 1 * cxChar, y, address);
if (m_NumeralMode == MEMMODENUM_OCT)
DrawOctalValue(painter, 38 + 1 * cxChar, y, address);
else
DrawHexValue(painter, 38 + 3 * cxChar, y, address);

int x = 38 + 9 * cxChar;
ushort wchars[16];

for (int j = 0; j < 8; j++) // Draw words as octal value
{
int addrtype;
Expand All @@ -283,27 +316,37 @@ void QMemoryView::paintEvent(QPaintEvent * /*event*/)
painter.setPen(colorMemoryRom);
else
painter.setPen(wChanged != 0 ? colorChanged : colorText);
if (m_ByteMode)

if (m_NumeralMode == MEMMODENUM_OCT && !m_ByteMode)
DrawOctalValue(painter, x, y, word);
else if (m_NumeralMode == MEMMODENUM_OCT && m_ByteMode)
{
PrintOctalValue(buffer, (word & 0xff));
painter.drawText(x, y, buffer + 3);
PrintOctalValue(buffer, (word >> 8));
painter.drawText(x + 3 * cxChar + cxChar / 2, y, buffer + 3);
painter.drawText(x + 4 * cxChar, y, buffer + 3);
}
else if (m_NumeralMode == MEMMODENUM_HEX && !m_ByteMode)
DrawHexValue(painter, x, y, word);
else if (m_NumeralMode == MEMMODENUM_HEX && m_ByteMode)
{
PrintHexValue(buffer, word);
painter.drawText(x, y, buffer + 2);
buffer[2] = 0;
painter.drawText(x + 3 * cxChar, y, buffer);
}
else
DrawOctalValue(painter, x, y, word);
}
else // No value
{
if (addrtype == ADDRTYPE_IO)
{
painter.setPen(colorMemoryIO);
painter.drawText(x, y, " IO ");
painter.drawText(x, y, " IO");
}
else
{
painter.setPen(colorMemoryNA);
painter.drawText(x, y, " NA ");
painter.drawText(x, y, " NA");
}
}

Expand All @@ -318,7 +361,7 @@ void QMemoryView::paintEvent(QPaintEvent * /*event*/)
wchars[j * 2 + 1] = wch2;

address += 2;
x += 7 * cxChar;
x += m_PostionIncrement;
}
painter.setPen(colorText);

Expand All @@ -338,7 +381,7 @@ void QMemoryView::paintEvent(QPaintEvent * /*event*/)
option.initFrom(this);
option.state |= QStyle::State_KeyboardFocusChange;
option.backgroundColor = QColor(Qt::gray);
option.rect = QRect(38, cyLine + fontmetrics.descent(), 83 * cxChar, cyLine * m_nPageSize);
option.rect = QRect(38, cyLine + fontmetrics.descent(), 28 * cxChar + 8 * m_PostionIncrement, cyLine * m_nPageSize);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
}
}
Expand Down
5 changes: 4 additions & 1 deletion emulator/qmemoryview.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class QMemoryView : public QWidget
public slots:
void changeMemoryMode();
void changeWordByteMode();
void changeNumeralMode();
void gotoAddress();
void scrollBy(qint16 delta);

Expand All @@ -40,10 +41,12 @@ protected slots:
private:
int m_Mode;
bool m_ByteMode; // false - word mode, true - byte mode
unsigned short m_wBaseAddress;
quint16 m_NumeralMode = 0;
quint16 m_wBaseAddress;
int m_cyLineMemory; // Line height in pixels
int m_nPageSize; // Page size in lines
int m_cyLine;
int m_PostionIncrement = 100; // Increment by X to the next word
QScrollBar *m_scrollbar;
QToolBar* m_toolbar;
};
Expand Down

0 comments on commit 9b6f976

Please sign in to comment.