aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qtmips_gui/registersdock.cpp64
-rw-r--r--qtmips_gui/registersdock.h25
-rw-r--r--qtmips_gui/registersdock.ui26
3 files changed, 84 insertions, 31 deletions
diff --git a/qtmips_gui/registersdock.cpp b/qtmips_gui/registersdock.cpp
index e8a5907..d038462 100644
--- a/qtmips_gui/registersdock.cpp
+++ b/qtmips_gui/registersdock.cpp
@@ -1,10 +1,68 @@
#include "registersdock.h"
RegistersDock::RegistersDock(QWidget *parent) : QDockWidget(parent) {
- ui = new Ui::RegistersDock();
- ui->setupUi(this);
+ regs = nullptr;
+
+ widg = new QScrollArea(this);
+ layout = new QFormLayout(widg);
+
+#define INIT(X, LABEL) do{ \
+ X = new QLabel(widg); \
+ X->setTextInteractionFlags(Qt::TextSelectableByMouse); \
+ layout->addRow(LABEL, X); \
+ } while(false)
+
+ INIT(pc, "PC:");
+ for (int i = 0; i < 32; i++)
+ INIT(gp[i], QString("GP") + QString::number(i) + QString(" ($") + QString::number(i) + QString("):"));
+ INIT(lo, "LO:");
+ INIT(hi, "HI:");
+
+#undef INIT
+
+ setWidget(widg);
}
RegistersDock::~RegistersDock() {
- delete ui;
+ delete layout;
+ delete pc, hi, lo;
+ for (int i = 0; i < 32; i++)
+ delete gp[i];
+}
+
+void RegistersDock::setup(QtMipsMachine *machine) {
+ regs = machine->registers();
+ connect(regs, SIGNAL(pc_update(std::uint32_t)), this, SLOT(pc_changed(std::uint32_t)));
+ connect(regs, SIGNAL(gp_update(std::uint8_t,std::uint32_t)), this, SLOT(gp_changed(std::uint8_t,std::uint32_t)));
+ connect(regs, SIGNAL(hi_lo_update(bool,std::uint32_t)), this, SLOT(hi_lo_changed(bool,std::uint32_t)));
+
+ // Load values
+ labelVal(pc, regs->read_pc(), false);
+ labelVal(hi, regs->read_hi_lo(true), true);
+ labelVal(lo, regs->read_hi_lo(false), true);
+ for (int i = 0; i < 32; i++)
+ labelVal(gp[i], regs->read_gp(i), true);
+}
+
+void RegistersDock::pc_changed(std::uint32_t val) {
+ labelVal(pc, val, false);
+}
+
+void RegistersDock::gp_changed(std::uint8_t i, std::uint32_t val) {
+ SANITY_ASSERT(i < 32, QString("RegistersDock received signal with invalid gp register: ") + QString::number(i));
+ labelVal(gp[i], val, true);
+}
+
+void RegistersDock::hi_lo_changed(bool hi, std::uint32_t val) {
+ if (hi)
+ labelVal(this->hi, val, true);
+ else
+ labelVal(lo, val, true);
+}
+
+void RegistersDock::labelVal(QLabel *label, std::uint32_t value, bool dec) {
+ QString t = QString("0x") + QString::number(value, 16);
+ if (dec)
+ t += QString(" (") + QString::number(value) + QString(")");
+ label->setText(t);
}
diff --git a/qtmips_gui/registersdock.h b/qtmips_gui/registersdock.h
index 338edc3..90be659 100644
--- a/qtmips_gui/registersdock.h
+++ b/qtmips_gui/registersdock.h
@@ -2,16 +2,37 @@
#define REGISTERSDOCK_H
#include <QDockWidget>
-#include "ui_registersdock.h"
+#include <QLabel>
+#include <QFormLayout>
+#include <QScrollArea>
+#include <QPropertyAnimation>
+#include "qtmipsmachine.h"
class RegistersDock : public QDockWidget {
+ Q_OBJECT
public:
RegistersDock(QWidget *parent);
~RegistersDock();
+ void setup(QtMipsMachine *machine);
+
+private slots:
+ void pc_changed(std::uint32_t val);
+ void gp_changed(std::uint8_t i, std::uint32_t val);
+ void hi_lo_changed(bool hi, std::uint32_t val);
+
private:
- Ui::RegistersDock *ui;
+ const Registers *regs;
+
+ QScrollArea *widg;
+ QFormLayout *layout;
+
+ QLabel *pc;
+ QLabel *hi;
+ QLabel *lo;
+ QLabel *gp[32];
+ void labelVal(QLabel *label, std::uint32_t val, bool dec);
};
#endif // REGISTERSDOCK_H
diff --git a/qtmips_gui/registersdock.ui b/qtmips_gui/registersdock.ui
deleted file mode 100644
index 9b51505..0000000
--- a/qtmips_gui/registersdock.ui
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>RegistersDock</class>
- <widget class="QDockWidget" name="RegistersDock">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>300</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Registers</string>
- </property>
- <widget class="QWidget" name="dockWidgetContents">
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QTableWidget" name="tableWidget"/>
- </item>
- </layout>
- </widget>
- </widget>
- <resources/>
- <connections/>
-</ui>