From c06242f07721a7d86dc2d9795622d6646ae6c88f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 4 Jan 2018 18:44:28 +0100 Subject: Implement some machine execution speed control for gui --- qtmips_gui/MainWindow.ui | 69 +++++++++++++++++++--------------------- qtmips_gui/mainwindow.cpp | 28 +++++++++++++++- qtmips_gui/mainwindow.h | 4 +++ qtmips_machine/qtmipsmachine.cpp | 8 ++--- 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/qtmips_gui/MainWindow.ui b/qtmips_gui/MainWindow.ui index 56f5319..0ab35d1 100644 --- a/qtmips_gui/MainWindow.ui +++ b/qtmips_gui/MainWindow.ui @@ -73,22 +73,14 @@ Machine - - - Simulation speed - - - - - - - - - - + + + + + @@ -119,6 +111,10 @@ + + + + @@ -188,42 +184,48 @@ Ctrl+P - + + + true + 1 instruction per second - - - - 2 instructions per second + + Run CPU in speed of single instruction per second - + + + true + 5 instructions per second + + Run CPU in speed of 5 instructions per second + - + + + true + 10 instructions per second - - - - Unlimited + + Run CPU in speed of 10 instructions per second - + - false + true - Custom... + Unlimited - - - - Machine control + + Run CPU without any clock constrains @@ -251,11 +253,6 @@ Registers - - - Assembler - - diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index 9384890..d1a9770 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -21,12 +21,24 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { registers = new RegistersDock(this); registers->hide(); + // Execution speed actions + speed_group = new QActionGroup(this); + speed_group->addAction(ui->ips1); + speed_group->addAction(ui->ips5); + speed_group->addAction(ui->ips10); + speed_group->addAction(ui->ipsUnlimited); + ui->ips1->setChecked(true); + // Connect signals from menu connect(ui->actionExit, SIGNAL(triggered(bool)), this, SLOT(close())); connect(ui->actionNew, SIGNAL(triggered(bool)), this, SLOT(new_machine())); connect(ui->actionCache, SIGNAL(triggered(bool)), this, SLOT(show_cache_content())); connect(ui->actionCache_statistics, SIGNAL(triggered(bool)), this, SLOT(show_cache_statictics())); connect(ui->actionRegisters, SIGNAL(triggered(bool)), this, SLOT(show_registers())); + connect(ui->ips1, SIGNAL(toggled(bool)), this, SLOT(set_speed())); + connect(ui->ips5, SIGNAL(toggled(bool)), this, SLOT(set_speed())); + connect(ui->ips10, SIGNAL(toggled(bool)), this, SLOT(set_speed())); + connect(ui->ipsUnlimited, SIGNAL(toggled(bool)), this, SLOT(set_speed())); // Restore application state from settings restoreState(settings->value("windowState").toByteArray()); @@ -63,7 +75,7 @@ void MainWindow::create_core(machine::MachineConfig *config) { // Create machine view corescene = new CoreViewScene(coreview, machine); - machine->set_speed(1000); // Set default speed to 1 sec + set_speed(); // Update machine speed to current settings // Connect machine signals and slots connect(ui->actionRun, SIGNAL(triggered(bool)), machine, SLOT(play())); @@ -100,6 +112,20 @@ void MainWindow::show_registers() { show_dockwidget(registers); } +void MainWindow::set_speed() { + if (machine == nullptr) + return; // just ignore + + if (ui->ips1->isChecked()) + machine->set_speed(1000); + else if (ui->ips5->isChecked()) + machine->set_speed(500); + else if (ui->ips10->isChecked()) + machine->set_speed(100); + else + machine->set_speed(0); +} + void MainWindow::closeEvent(QCloseEvent *event) { settings->setValue("windowGeometry", saveGeometry()); settings->setValue("windowState", saveState()); diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index 6f588ac..d2ab9bb 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -31,6 +31,8 @@ public slots: void show_cache_content(); void show_cache_statictics(); void show_registers(); + // Actions - execution speed + void set_speed(); // Machine signals void machine_status(enum machine::QtMipsMachine::Status st); void machine_exit(); @@ -51,6 +53,8 @@ private: CacheStatisticsDock *cache_statictics; RegistersDock *registers; + QActionGroup *speed_group; + QSettings *settings; machine::QtMipsMachine *machine; // Current simulated machine diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp index 3d79c7c..a652363 100644 --- a/qtmips_machine/qtmipsmachine.cpp +++ b/qtmips_machine/qtmipsmachine.cpp @@ -35,15 +35,13 @@ QtMipsMachine::QtMipsMachine(const MachineConfig &cc) { else cr = new CoreSingle(regs, coremem, cc.delay_slot()); - run_speed = 1; run_t = new QTimer(this); + set_speed(0); // In default run as fast as possible connect(run_t, SIGNAL(timeout()), this, SLOT(step())); } void QtMipsMachine::set_speed(unsigned val) { - run_speed = val; - if (run_t->isActive()) - play(); + run_t->setInterval(val); } const Registers *QtMipsMachine::registers() { @@ -78,7 +76,7 @@ bool QtMipsMachine::exited() { void QtMipsMachine::play() { CTL_GUARD; set_status(ST_RUNNING); - run_t->start(run_speed); + run_t->start(); } void QtMipsMachine::pause() { -- cgit v1.2.3