added visible memory
This commit is contained in:
parent
c918993060
commit
280a3b62fc
4 changed files with 265 additions and 2 deletions
|
|
@ -10,7 +10,10 @@
|
|||
#include <QRegularExpressionValidator>
|
||||
#include <QDoubleValidator>
|
||||
#include <QPushButton>
|
||||
#include <cstdint>
|
||||
#include <cstdint>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QFont>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
|
@ -60,6 +63,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
|
||||
connect(m_controller.get(), &MachineController::tick, this, &MainWindow::updateRegisterDisplays);
|
||||
connect(m_controller.get(), &MachineController::tick, this, &MainWindow::updateMemoryDisplay);
|
||||
|
||||
connectRegisterFields();
|
||||
|
||||
|
|
@ -67,9 +71,18 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(ui->StopBtn, &QPushButton::clicked, this, &MainWindow::stopExecution);
|
||||
connect(ui->StepBtn, &QPushButton::clicked, this, &MainWindow::stepExecution);
|
||||
|
||||
connect(ui->MemoryInc256Btn, &QPushButton::clicked, this, &MainWindow::onMemoryInc256);
|
||||
connect(ui->MemoryInc4096Btn, &QPushButton::clicked, this, &MainWindow::onMemoryInc4096);
|
||||
connect(ui->MemoryInc65536Btn, &QPushButton::clicked, this, &MainWindow::onMemoryInc65536);
|
||||
connect(ui->MemoryDec256Btn, &QPushButton::clicked, this, &MainWindow::onMemoryDec256);
|
||||
connect(ui->MemoryDec4096Btn, &QPushButton::clicked, this, &MainWindow::onMemoryDec4096);
|
||||
connect(ui->MemoryDec65536Btn, &QPushButton::clicked, this, &MainWindow::onMemoryDec65536);
|
||||
|
||||
setupMemoryDisplay();
|
||||
loadDemoProgram();
|
||||
|
||||
updateRegisterDisplays();
|
||||
updateMemoryDisplay();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
|
@ -412,3 +425,130 @@ void MainWindow::loadDemoProgram()
|
|||
qDebug() << "Program loaded. TEMP at 0x" << QString::number(TEMP_ADDR, 16).toUpper();
|
||||
qDebug() << "PC set to 0x00. Ready to execute.";
|
||||
}
|
||||
|
||||
void MainWindow::setupMemoryDisplay()
|
||||
{
|
||||
// Set the title
|
||||
ui->MemorygroupBox->setTitle("Memory (RAM)");
|
||||
}
|
||||
|
||||
void MainWindow::onMemoryInc256()
|
||||
{
|
||||
m_memoryOffset += 256;
|
||||
if (m_memoryOffset > 1048576 - 256) {
|
||||
m_memoryOffset = 1048576 - 256;
|
||||
}
|
||||
updateMemoryDisplay();
|
||||
}
|
||||
|
||||
void MainWindow::onMemoryInc4096()
|
||||
{
|
||||
m_memoryOffset += 4096;
|
||||
if (m_memoryOffset > 1048576 - 256) {
|
||||
m_memoryOffset = 1048576 - 256;
|
||||
}
|
||||
updateMemoryDisplay();
|
||||
}
|
||||
|
||||
void MainWindow::onMemoryInc65536()
|
||||
{
|
||||
m_memoryOffset += 65536;
|
||||
if (m_memoryOffset > 1048576 - 256) {
|
||||
m_memoryOffset = 1048576 - 256;
|
||||
}
|
||||
updateMemoryDisplay();
|
||||
}
|
||||
|
||||
void MainWindow::onMemoryDec256()
|
||||
{
|
||||
m_memoryOffset -= 256;
|
||||
if (m_memoryOffset < 0) {
|
||||
m_memoryOffset = 0;
|
||||
}
|
||||
updateMemoryDisplay();
|
||||
}
|
||||
|
||||
void MainWindow::onMemoryDec4096()
|
||||
{
|
||||
m_memoryOffset -= 4096;
|
||||
if (m_memoryOffset < 0) {
|
||||
m_memoryOffset = 0;
|
||||
}
|
||||
updateMemoryDisplay();
|
||||
}
|
||||
|
||||
void MainWindow::onMemoryDec65536()
|
||||
{
|
||||
m_memoryOffset -= 65536;
|
||||
if (m_memoryOffset < 0) {
|
||||
m_memoryOffset = 0;
|
||||
}
|
||||
updateMemoryDisplay();
|
||||
}
|
||||
|
||||
void MainWindow::updateMemoryDisplay()
|
||||
{
|
||||
if (!m_machine) return;
|
||||
|
||||
// Create a widget to hold the memory display
|
||||
QWidget* container = new QWidget();
|
||||
QVBoxLayout* layout = new QVBoxLayout(container);
|
||||
layout->setSpacing(1);
|
||||
layout->setContentsMargins(5, 5, 5, 5);
|
||||
|
||||
// Create monospace font for memory display
|
||||
QFont monoFont("Courier New");
|
||||
monoFont.setPointSize(9);
|
||||
|
||||
// Header with current offset range
|
||||
QString headerText = QString("Address Hex Value Char [0x%1 - 0x%2]")
|
||||
.arg(m_memoryOffset, 5, 16, QChar('0')).toUpper()
|
||||
.arg(m_memoryOffset + 255, 5, 16, QChar('0')).toUpper();
|
||||
QLabel* header = new QLabel(headerText);
|
||||
QFont headerFont = monoFont;
|
||||
headerFont.setBold(true);
|
||||
header->setFont(headerFont);
|
||||
layout->addWidget(header);
|
||||
|
||||
// Get PC for highlighting
|
||||
int pc = m_machine->getPC();
|
||||
|
||||
// Display memory byte by byte - ONLY 256 bytes from current offset
|
||||
for (int i = 0; i < 256; i++) {
|
||||
int addr = m_memoryOffset + i;
|
||||
int byte = m_machine->getByte(addr);
|
||||
|
||||
QString addressStr = QString("0x%1").arg(addr, 5, 16, QChar('0')).toUpper();
|
||||
|
||||
// Hex value column
|
||||
QString hexStr = QString("0x%1").arg(byte, 2, 16, QChar('0')).toUpper();
|
||||
|
||||
// Char representation
|
||||
QString charStr;
|
||||
if (byte >= 32 && byte <= 126) {
|
||||
charStr = QChar(byte);
|
||||
} else {
|
||||
charStr = '.';
|
||||
}
|
||||
|
||||
QString line = QString("%1 %2 %3")
|
||||
.arg(addressStr, -12)
|
||||
.arg(hexStr, -12)
|
||||
.arg(charStr);
|
||||
|
||||
QLabel* memLine = new QLabel(line);
|
||||
memLine->setFont(monoFont);
|
||||
|
||||
// Highlight the current PC address
|
||||
if (pc == addr) {
|
||||
memLine->setStyleSheet("background-color: #FFFF99; font-weight: bold;");
|
||||
}
|
||||
|
||||
layout->addWidget(memLine);
|
||||
}
|
||||
|
||||
layout->addStretch();
|
||||
container->setLayout(layout);
|
||||
|
||||
ui->MemoryScrollArea->setWidget(container);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue