From 04ab3211f8a052e7f0a05b36206403197e526284 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Wed, 13 Feb 2019 11:50:28 +0100 Subject: Add speed option to run core for time chunks without visualization. Signed-off-by: Pavel Pisa --- qtmips_machine/qtmipsmachine.cpp | 12 +++++++++--- qtmips_machine/qtmipsmachine.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'qtmips_machine') diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp index 69deeb1..81f733b 100644 --- a/qtmips_machine/qtmipsmachine.cpp +++ b/qtmips_machine/qtmipsmachine.cpp @@ -33,6 +33,7 @@ * ******************************************************************************/ +#include #include "qtmipsmachine.h" #include "programloader.h" @@ -102,8 +103,9 @@ const MachineConfig &QtMipsMachine::config() { return mcnf; } -void QtMipsMachine::set_speed(unsigned val) { - run_t->setInterval(val); +void QtMipsMachine::set_speed(unsigned int ips, unsigned int time_chunk) { + this->time_chunk = time_chunk; + run_t->setInterval(ips); } const Registers *QtMipsMachine::registers() { @@ -174,7 +176,11 @@ void QtMipsMachine::step_internal(bool skip_break) { set_status(ST_BUSY); emit tick(); try { - cr->step(skip_break); + QTime start_time = QTime::currentTime(); + do { + cr->step(skip_break); + } while(time_chunk != 0 && stat == ST_BUSY && + start_time.msecsTo(QTime::currentTime()) < time_chunk); } catch (QtMipsException &e) { run_t->stop(); set_status(ST_TRAPPED); diff --git a/qtmips_machine/qtmipsmachine.h b/qtmips_machine/qtmipsmachine.h index 4ad39c5..2a191f0 100644 --- a/qtmips_machine/qtmipsmachine.h +++ b/qtmips_machine/qtmipsmachine.h @@ -57,7 +57,7 @@ public: ~QtMipsMachine(); const MachineConfig &config(); - void set_speed(unsigned); + void set_speed(unsigned int ips, unsigned int time_chunk = 0); const Registers *registers(); const Memory *memory(); @@ -111,6 +111,7 @@ private: Core *cr; QTimer *run_t; + unsigned int time_chunk; std::uint32_t program_end; enum Status stat; -- cgit v1.2.3