final version
This commit is contained in:
parent
098766bb65
commit
042bae9089
8 changed files with 143 additions and 21 deletions
|
|
@ -3,12 +3,15 @@
|
|||
#include <chrono>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
MachineController::MachineController(std::shared_ptr<Machine> machine, QObject *parent)
|
||||
: QObject(parent), m_machine(std::move(machine))
|
||||
{
|
||||
if (!m_machine) {
|
||||
m_machine = std::make_shared<Machine>();
|
||||
}
|
||||
m_lastUpdateTime = steady_clock::now();
|
||||
}
|
||||
|
||||
MachineController::~MachineController() {
|
||||
|
|
@ -38,14 +41,27 @@ void MachineController::step() {
|
|||
}
|
||||
|
||||
void MachineController::runLoop() {
|
||||
const auto minUpdateInterval = milliseconds(16);
|
||||
|
||||
while (m_running.load()) {
|
||||
try {
|
||||
if (m_machine) {
|
||||
m_machine->execute();
|
||||
m_machine->tick();
|
||||
emit tick();
|
||||
m_machine->tick();
|
||||
m_ticksSinceLastUpdate++;
|
||||
|
||||
// Throttle GUI updates to 60 Hz
|
||||
auto now = steady_clock::now();
|
||||
auto elapsed = duration_cast<milliseconds>(now - m_lastUpdateTime);
|
||||
|
||||
if (elapsed >= minUpdateInterval) {
|
||||
emit tick();
|
||||
m_lastUpdateTime = now;
|
||||
m_ticksSinceLastUpdate = 0;
|
||||
}
|
||||
|
||||
if (m_machine->isStopped()) {
|
||||
emit tick();
|
||||
m_running.store(false);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ private:
|
|||
std::atomic<bool> m_running{false};
|
||||
std::thread m_thread;
|
||||
std::shared_ptr<Machine> m_machine;
|
||||
std::atomic<int> m_ticksSinceLastUpdate{0};
|
||||
std::chrono::steady_clock::time_point m_lastUpdateTime;
|
||||
};
|
||||
|
||||
#endif // MACHINECONTROLLER_H
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
int main(int argc, char **argv) {
|
||||
loadInstructionSet();
|
||||
|
||||
qputenv("QT_QPA_PLATFORM", "xcb");
|
||||
|
||||
QApplication app(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
|
|
|||
|
|
@ -102,6 +102,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
// Connect menu actions
|
||||
connect(ui->actionLoad_Object_File, &QAction::triggered, this, &MainWindow::loadObjectFile);
|
||||
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog);
|
||||
connect(ui->actionFrequency, &QAction::triggered, this, &MainWindow::showFrequencyDialog);
|
||||
|
||||
setupMemoryDisplay();
|
||||
setupDisassemblyDisplay();
|
||||
|
|
@ -978,3 +980,51 @@ void MainWindow::loadObjectFile()
|
|||
tr("Failed to load object file: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showAboutDialog()
|
||||
{
|
||||
QMessageBox::about(this, tr("About SIC/XE Simulator"),
|
||||
tr("SIC/XE Simulator\nby Zan Skvarca\n2025"));
|
||||
}
|
||||
|
||||
void MainWindow::showFrequencyDialog()
|
||||
{
|
||||
if (!m_machine) return;
|
||||
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle(tr("Set Frequency"));
|
||||
dialog.setModal(true);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(&dialog);
|
||||
|
||||
QLabel *currentLabel = new QLabel(tr("Current frequency: %1 Hz").arg(m_machine->getSpeed()), &dialog);
|
||||
layout->addWidget(currentLabel);
|
||||
|
||||
QLabel *newLabel = new QLabel(tr("New frequency (Hz):"), &dialog);
|
||||
layout->addWidget(newLabel);
|
||||
|
||||
QLineEdit *freqInput = new QLineEdit(&dialog);
|
||||
freqInput->setValidator(new QIntValidator(1, 1000000000, &dialog));
|
||||
freqInput->setText(QString::number(m_machine->getSpeed()));
|
||||
layout->addWidget(freqInput);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
||||
QPushButton *submitBtn = new QPushButton(tr("Submit"), &dialog);
|
||||
QPushButton *cancelBtn = new QPushButton(tr("Cancel"), &dialog);
|
||||
buttonLayout->addWidget(submitBtn);
|
||||
buttonLayout->addWidget(cancelBtn);
|
||||
layout->addLayout(buttonLayout);
|
||||
|
||||
connect(submitBtn, &QPushButton::clicked, &dialog, &QDialog::accept);
|
||||
connect(cancelBtn, &QPushButton::clicked, &dialog, &QDialog::reject);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
bool ok;
|
||||
int newFreq = freqInput->text().toInt(&ok);
|
||||
if (ok && newFreq > 0) {
|
||||
m_machine->setSpeed(newFreq);
|
||||
QMessageBox::information(this, tr("Success"),
|
||||
tr("Frequency set to %1 Hz").arg(newFreq));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ private slots:
|
|||
void onDisassemblyGoToStart();
|
||||
void onDisassemblyGoToEnd();
|
||||
void loadObjectFile();
|
||||
void showAboutDialog();
|
||||
void showFrequencyDialog();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue