diff options
author | Karel Kočí <cynerd@email.cz> | 2017-12-15 22:45:28 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-12-15 22:45:28 +0100 |
commit | e6ca4b4568e311b47239bfe83de15ed9e91c57b9 (patch) | |
tree | 3da2f72faf360058bae02c35b0c724233bd64d61 /qtmips_machine | |
parent | bbea996112eb7ac81ec50d2af08f4bd681d0e50d (diff) | |
download | qtmips-e6ca4b4568e311b47239bfe83de15ed9e91c57b9.tar.gz qtmips-e6ca4b4568e311b47239bfe83de15ed9e91c57b9.tar.bz2 qtmips-e6ca4b4568e311b47239bfe83de15ed9e91c57b9.zip |
Implement few initial graphic elements
Diffstat (limited to 'qtmips_machine')
-rw-r--r-- | qtmips_machine/qtmipsmachine.cpp | 17 | ||||
-rw-r--r-- | qtmips_machine/qtmipsmachine.h | 2 | ||||
-rw-r--r-- | qtmips_machine/registers.cpp | 3 | ||||
-rw-r--r-- | qtmips_machine/registers.h | 3 |
4 files changed, 23 insertions, 2 deletions
diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp index 7b44a7b..191a7c7 100644 --- a/qtmips_machine/qtmipsmachine.cpp +++ b/qtmips_machine/qtmipsmachine.cpp @@ -9,6 +9,7 @@ QtMipsMachine::QtMipsMachine(const MachineConfig &cc) { program.to_memory(mem); program_end = program.end(); + program_ended = false; MemoryAccess *coremem; switch (cc.cache()) { @@ -35,6 +36,8 @@ QtMipsMachine::QtMipsMachine(const MachineConfig &cc) { void QtMipsMachine::set_speed(unsigned val) { run_speed = val; + if (run_t->isActive()) + play(); } const Registers *QtMipsMachine::registers() { @@ -54,19 +57,31 @@ const Core *QtMipsMachine::core() { } void QtMipsMachine::play() { + if (program_ended) + return; run_t->start(run_speed); } void QtMipsMachine::pause() { + if (program_ended) + return; run_t->stop(); } void QtMipsMachine::step() { + if (program_ended) // Ignore if program ended + return; + emit tick(); cr->step(); - if (regs->read_pc() >= program_end) + if (regs->read_pc() >= program_end) { + program_ended = true; + run_t->stop(); emit program_exit(); + } } void QtMipsMachine::restart() { + if (!program_ended) + run_t->stop(); // Stop timer if program is still running // TODO } diff --git a/qtmips_machine/qtmipsmachine.h b/qtmips_machine/qtmipsmachine.h index 829e571..c185f28 100644 --- a/qtmips_machine/qtmipsmachine.h +++ b/qtmips_machine/qtmipsmachine.h @@ -32,6 +32,7 @@ public slots: signals: void program_exit(); + void tick(); // Time tick private: Registers *regs; @@ -43,6 +44,7 @@ private: QTimer *run_t; std::uint32_t program_end; + bool program_ended; }; #endif // QTMIPSMACHINE_H diff --git a/qtmips_machine/registers.cpp b/qtmips_machine/registers.cpp index a18421e..b77b1b7 100644 --- a/qtmips_machine/registers.cpp +++ b/qtmips_machine/registers.cpp @@ -44,6 +44,7 @@ void Registers::pc_abs_jmp(std::uint32_t address) { if (address % 4) throw QTMIPS_EXCEPTION(UnalignedJump, "Trying to jump to unaligned address", QString::number(address, 16)); this->pc = address; + emit pc_update(this->pc); } void Registers::pc_abs_jmp_28(std::uint32_t address) { @@ -61,6 +62,7 @@ void Registers::write_gp(std::uint8_t i, std::uint32_t value) { SANITY_ASSERT(i < 32, QString("Trying to write to register ") + QString(i)); if (i == 0) // Skip write to $0 return; + emit gp_update(i, value); this->gp[i - 1] = value; } @@ -76,6 +78,7 @@ void Registers::write_hi_lo(bool hi, std::uint32_t value) { this->hi = value; else this->lo = value; + emit hi_lo_update(hi, value); } bool Registers::operator==(const Registers &c) const { diff --git a/qtmips_machine/registers.h b/qtmips_machine/registers.h index dd7e393..4a693db 100644 --- a/qtmips_machine/registers.h +++ b/qtmips_machine/registers.h @@ -26,7 +26,8 @@ public: signals: void pc_update(std::uint32_t val); - // TODO signals + void gp_update(std::uint8_t i, std::uint32_t val); + void hi_lo_update(bool hi, std::uint32_t val); private: std::uint32_t gp[31]; // general-purpose registers ($0 is intentionally skipped) |