diff --git a/simulator_SIC_XE/gui/qt/mainwindow.cpp b/simulator_SIC_XE/gui/qt/mainwindow.cpp index e024b67..f49990a 100644 --- a/simulator_SIC_XE/gui/qt/mainwindow.cpp +++ b/simulator_SIC_XE/gui/qt/mainwindow.cpp @@ -10,7 +10,10 @@ #include #include #include -#include +#include +#include +#include +#include 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); +} diff --git a/simulator_SIC_XE/gui/qt/mainwindow.h b/simulator_SIC_XE/gui/qt/mainwindow.h index e6c6c46..0507803 100644 --- a/simulator_SIC_XE/gui/qt/mainwindow.h +++ b/simulator_SIC_XE/gui/qt/mainwindow.h @@ -31,12 +31,20 @@ public: private slots: void updateRegisterDisplays(); + void updateMemoryDisplay(); void onRegisterFieldChanged(); + void onMemoryInc256(); + void onMemoryInc4096(); + void onMemoryInc65536(); + void onMemoryDec256(); + void onMemoryDec4096(); + void onMemoryDec65536(); private: Ui::MainWindow *ui; std::shared_ptr m_machine; std::unique_ptr m_controller; + int m_memoryOffset = 0; void connectRegisterFields(); void updateSingleRegisterDisplay(const QString& fieldName, int value); @@ -44,6 +52,7 @@ private: void updateFloatRegisterFormats(const QString& regPrefix, double value); void handleFloatRegisterFieldChanged(QLineEdit* field, const QString& objectName); void loadDemoProgram(); + void setupMemoryDisplay(); }; #endif // MAINWINDOW_H diff --git a/simulator_SIC_XE/gui/qt/mainwindow.ui b/simulator_SIC_XE/gui/qt/mainwindow.ui index 3de39ab..7722091 100644 --- a/simulator_SIC_XE/gui/qt/mainwindow.ui +++ b/simulator_SIC_XE/gui/qt/mainwindow.ui @@ -584,6 +584,120 @@ 601 + + + + 0 + 0 + 711 + 251 + + + + GroupBox + + + + + 0 + 20 + 711 + 171 + + + + true + + + + + 0 + 0 + 709 + 169 + + + + + + + + 460 + 200 + 121 + 23 + + + + >> M[+0x01000] + + + + + + 360 + 200 + 101 + 23 + + + + > M[+0x00100] + + + + + + 580 + 200 + 121 + 23 + + + + >>> M[+0x10000] + + + + + + 250 + 200 + 101 + 23 + + + + < M[-0x00100] + + + + + + 130 + 200 + 121 + 23 + + + + << M[-0x01000] + + + + + + 10 + 200 + 121 + 21 + + + + <<< M[-0x10000] + + + diff --git a/simulator_SIC_XE/include/constants.h b/simulator_SIC_XE/include/constants.h index 0034171..9c8988c 100644 --- a/simulator_SIC_XE/include/constants.h +++ b/simulator_SIC_XE/include/constants.h @@ -6,7 +6,7 @@ // ============================== // Memory and system constants -constexpr int MEMORY_SIZE = 65536; +constexpr int MEMORY_SIZE = 1 << 20; // 1 MB memory constexpr int NUM_DEVICES = 256; constexpr int WORD_SIZE = 24; constexpr int WORD_MASK = 0xFFFFFF;