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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Machine> m_machine;
|
||||
std::unique_ptr<MachineController> 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
|
||||
|
|
|
|||
|
|
@ -584,6 +584,120 @@
|
|||
<height>601</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="MemorygroupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>711</width>
|
||||
<height>251</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
</property>
|
||||
<widget class="QScrollArea" name="MemoryScrollArea">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>20</y>
|
||||
<width>711</width>
|
||||
<height>171</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>709</width>
|
||||
<height>169</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="MemoryInc4096Btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>460</x>
|
||||
<y>200</y>
|
||||
<width>121</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>>> M[+0x01000]</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="MemoryInc256Btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>360</x>
|
||||
<y>200</y>
|
||||
<width>101</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>> M[+0x00100]</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="MemoryInc65536Btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>580</x>
|
||||
<y>200</y>
|
||||
<width>121</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>>>> M[+0x10000]</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="MemoryDec256Btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>250</x>
|
||||
<y>200</y>
|
||||
<width>101</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>< M[-0x00100]</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="MemoryDec4096Btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>200</y>
|
||||
<width>121</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><< M[-0x01000]</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="MemoryDec65536Btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>200</y>
|
||||
<width>121</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><<< M[-0x10000]</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue