aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/qtmipsmachine.cpp12
-rw-r--r--qtmips_machine/qtmipsmachine.h3
2 files changed, 11 insertions, 4 deletions
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 <QTime>
#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;