From 42737c0a6680b2bfb27a6197df5b41a124169983 Mon Sep 17 00:00:00 2001 From: zanostro Date: Thu, 13 Nov 2025 20:22:50 +0100 Subject: [PATCH] qol --- simulator_SIC_XE/gui/qt/MachineController.cpp | 33 ++++++-- simulator_SIC_XE/gui/qt/MachineController.h | 7 +- simulator_SIC_XE/gui/qt/main.cpp | 2 + simulator_SIC_XE/gui/qt/mainwindow.ui | 81 ++++++++++++++++--- simulator_SIC_XE/include/machine.h | 2 +- 5 files changed, 107 insertions(+), 18 deletions(-) diff --git a/simulator_SIC_XE/gui/qt/MachineController.cpp b/simulator_SIC_XE/gui/qt/MachineController.cpp index f066e23..0ea4178 100644 --- a/simulator_SIC_XE/gui/qt/MachineController.cpp +++ b/simulator_SIC_XE/gui/qt/MachineController.cpp @@ -1,9 +1,14 @@ #include "MachineController.h" +#include "../../include/machine.h" #include +#include -MachineController::MachineController(QObject *parent) - : QObject(parent) +MachineController::MachineController(std::shared_ptr machine, QObject *parent) + : QObject(parent), m_machine(std::move(machine)) { + if (!m_machine) { + m_machine = std::make_shared(); + } } MachineController::~MachineController() { @@ -21,12 +26,30 @@ void MachineController::stop() { } void MachineController::step() { - emit tick(); + try { + if (m_machine) { + m_machine->execute(); + m_machine->tick(); + emit tick(); + } + } catch (const std::exception &e) { + emit error(QString::fromStdString(e.what())); + } } void MachineController::runLoop() { while (m_running.load()) { - emit tick(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + try { + if (m_machine) { + m_machine->execute(); + m_machine->tick(); + emit tick(); + } + } catch (const std::exception &e) { + emit error(QString::fromStdString(e.what())); + // Stop on fatal error + m_running.store(false); + break; + } } } diff --git a/simulator_SIC_XE/gui/qt/MachineController.h b/simulator_SIC_XE/gui/qt/MachineController.h index bc29329..fa904a3 100644 --- a/simulator_SIC_XE/gui/qt/MachineController.h +++ b/simulator_SIC_XE/gui/qt/MachineController.h @@ -4,11 +4,14 @@ #include #include #include +#include + +class Machine; class MachineController : public QObject { Q_OBJECT public: - explicit MachineController(QObject *parent = nullptr); + explicit MachineController(std::shared_ptr machine = nullptr, QObject *parent = nullptr); ~MachineController() override; void start(); @@ -17,11 +20,13 @@ public: signals: void tick(); + void error(const QString &msg); private: void runLoop(); std::atomic m_running{false}; std::thread m_thread; + std::shared_ptr m_machine; }; #endif // MACHINECONTROLLER_H diff --git a/simulator_SIC_XE/gui/qt/main.cpp b/simulator_SIC_XE/gui/qt/main.cpp index 877769b..f9b6517 100644 --- a/simulator_SIC_XE/gui/qt/main.cpp +++ b/simulator_SIC_XE/gui/qt/main.cpp @@ -1,7 +1,9 @@ #include #include "mainwindow.h" +#include "../../include/opcode.h" int main(int argc, char **argv) { + loadInstructionSet(); QApplication app(argc, argv); MainWindow w; w.show(); diff --git a/simulator_SIC_XE/gui/qt/mainwindow.ui b/simulator_SIC_XE/gui/qt/mainwindow.ui index 1a59260..9f505ab 100644 --- a/simulator_SIC_XE/gui/qt/mainwindow.ui +++ b/simulator_SIC_XE/gui/qt/mainwindow.ui @@ -1,25 +1,84 @@ - + - - - MainWindow - + 0 0 - 640 - 480 + 1137 + 649 MainWindow - - - + + + + + 0 + 0 + 231 + 601 + + + + + + + 230 + 0 + 891 + 601 + + + + + + 0 + 0 + 881 + 181 + + + + Register values + + + + + 0 + 20 + 881 + 161 + + + + + + + TextLabel + + + + + + + + + + + + 0 + 0 + 1137 + 20 + + + + - + diff --git a/simulator_SIC_XE/include/machine.h b/simulator_SIC_XE/include/machine.h index 0bcb448..b92934e 100644 --- a/simulator_SIC_XE/include/machine.h +++ b/simulator_SIC_XE/include/machine.h @@ -91,6 +91,7 @@ public: void setSpeed(int kHz); void start(); void stop(); + void tick(); // error handling methods void notImplemented(string mnemonic); @@ -115,7 +116,6 @@ private: // Execution control std::atomic running{false}; std::atomic speedkHz{1}; // Default 1 kHz - void tick(); // simulate a clock tick };