diff options
author | bd <bdunahu@operationnull.com> | 2025-04-19 15:14:56 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-19 15:14:56 -0400 |
commit | 2b5ca09c90c5e091c094e9ed8f02079674b8aeda (patch) | |
tree | 227821d3d081d211e5e27c0eb7358061ed24a686 | |
parent | c375eba808841797a7339afcfe9c4426da53de75 (diff) |
Add new widget to display number in base 10 and 16
-rw-r--r-- | gui/digitlabel.cc | 39 | ||||
-rw-r--r-- | gui/digitlabel.h | 52 | ||||
-rw-r--r-- | gui/gui.cc | 36 | ||||
-rw-r--r-- | gui/gui.h | 2 | ||||
-rw-r--r-- | gui/gui.ui | 95 | ||||
-rw-r--r-- | gui/worker.cc | 1 |
6 files changed, 176 insertions, 49 deletions
diff --git a/gui/digitlabel.cc b/gui/digitlabel.cc new file mode 100644 index 0000000..a5c84f1 --- /dev/null +++ b/gui/digitlabel.cc @@ -0,0 +1,39 @@ +#include "digitlabel.h" + +DigitLabel::DigitLabel(QWidget *parent) : QLabel(parent) +{ + this->update_display(); +} + +void DigitLabel::clear() +{ + this->is_cleared = true; + setText(QString()); +} + +void DigitLabel::set_value(int v) +{ + this->is_cleared = false; + if (this->v != v) { + this->v = v; + update_display(); + } +} + +void DigitLabel::toggle_mode() +{ + this->is_hex = !this->is_hex; + this->update_display(); +} + +void DigitLabel::update_display() +{ + QString t; + if (this->is_cleared) { + setText(QString()); + } else { + t = (this->is_hex) ? QString::number(this->v, 6).toUpper() + : QString::number(this->v); + setText(t); + } +} diff --git a/gui/digitlabel.h b/gui/digitlabel.h new file mode 100644 index 0000000..9106cc9 --- /dev/null +++ b/gui/digitlabel.h @@ -0,0 +1,52 @@ +#ifndef DIGITLABEL_H +#define DIGITLABEL_H + +#include <QLabel> + +class DigitLabel : public QLabel +{ + Q_OBJECT + + public: + /** + * Constructor. + * @return a newly allocated DigitLabel. + */ + explicit DigitLabel(QWidget *parent = nullptr); + + /** + * Sets the empty flag. + */ + void clear(); + /** + * @param the value to set `this->v' with. + */ + void set_value(int v); + + public slots: + /** + * Toggles the base this label displays in, by setting `this->is_hex'. + */ + void toggle_mode(); + + private: + /** + * Refreshes the display of this label, taking base into consideration.. + */ + void update_display(); + + /** + * The decimal value associated with this label. + */ + int v = 0; + /** + * To display in hexidecimal or not. + */ + bool is_hex = true; + /** + * To display in hexidecimal or not. + */ + bool is_cleared = true; +}; + +#endif // DIGITLABEL_H @@ -19,7 +19,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) worker->moveToThread(&workerThread); // display clock cycles and PC - connect(worker, &Worker::clock_cycles, this, &GUI::onWorkerClockCycles); + connect(worker, &Worker::clock_cycles, this, &GUI::on_worker_refresh_gui); connect(worker, &Worker::if_info, this, &GUI::onWorkerFetchInfo); @@ -129,23 +129,17 @@ void displayTableHTML( textEdit->setReadOnly(true); } -void GUI::onWorkerClockCycles(int cycles, int pc) +void GUI::on_worker_refresh_gui(int cycles, int pc) { - QFont font = ui->cycles_label->font(); - font.setBold(true); - font.setItalic(true); - font.setPointSize(14); - ui->cycles_label->setFont(font); - ui->cycles_label->setText( - "Clock Cycles: " + QString::number(cycles) + "\t\t" + - "PC: " + QString::number(pc)); + ui->p_counter->set_value(pc); + ui->cycle_counter->set_value(cycles); } void GUI::onWorkerFetchInfo(const std::vector<int> info) { if (!info.empty()) { ui->fetch_squashed->setText(QString::number(info[0])); - ui->fetch_bits->setText(QString::asprintf("%04X", info[1])); + ui->fetch_bits->set_value(info[1]); } else { ui->fetch_squashed->clear(); ui->fetch_bits->clear(); @@ -156,7 +150,7 @@ void GUI::onWorkerDecodeInfo(const std::vector<int> info) { if (!info.empty()) { ui->decode_squashed->setText(QString::number(info[0])); - ui->decode_bits->setText(QString::asprintf("%04X", info[1])); + ui->decode_bits->set_value(info[1]); } else { ui->decode_squashed->clear(); ui->decode_bits->clear(); @@ -168,9 +162,9 @@ void GUI::onWorkerExecuteInfo(const std::vector<int> info) if (!info.empty()) { ui->execute_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); ui->execute_squashed->setText(QString::number(info[1])); - ui->execute_s1->setText(QString::asprintf("%04X", info[2])); - ui->execute_s2->setText(QString::asprintf("%04X", info[3])); - ui->execute_s3->setText(QString::asprintf("%04X", info[4])); + ui->execute_s1->set_value(info[2]); + ui->execute_s2->set_value(info[3]); + ui->execute_s3->set_value(info[4]); } else { ui->execute_mnemonic->clear(); ui->execute_squashed->clear(); @@ -185,9 +179,9 @@ void GUI::onWorkerMemoryInfo(const std::vector<int> info) if (!info.empty()) { ui->memory_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); ui->memory_squashed->setText(QString::number(info[1])); - ui->memory_s1->setText(QString::asprintf("%04X", info[2])); - ui->memory_s2->setText(QString::asprintf("%04X", info[3])); - ui->memory_s3->setText(QString::asprintf("%04X", info[4])); + ui->memory_s1->set_value(info[2]); + ui->memory_s2->set_value(info[3]); + ui->memory_s3->set_value(info[4]); } else { ui->memory_mnemonic->clear(); ui->memory_squashed->clear(); @@ -201,9 +195,9 @@ void GUI::onWorkerWriteBackInfo(const std::vector<int> info) { if (!info.empty()) { ui->write_mnemonic->setText(mnemonicToString((Mnemonic)info[0])); - ui->write_s1->setText(QString::asprintf("%04X", info[2])); - ui->write_s2->setText(QString::asprintf("%04X", info[3])); - ui->write_s3->setText(QString::asprintf("%04X", info[4])); + ui->write_s1->set_value(info[2]); + ui->write_s2->set_value(info[3]); + ui->write_s3->set_value(info[4]); } else { ui->write_mnemonic->clear(); ui->write_s1->clear(); @@ -45,7 +45,7 @@ class GUI : public QMainWindow bool is_pipelined); private slots: - void onWorkerClockCycles(int value, int pc); + void on_worker_refresh_gui(int value, int pc); void onWorkerFetchInfo(const std::vector<int> info); @@ -384,7 +384,7 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QLabel" name="fetch_bits"> + <widget class="DigitLabel" name="fetch_bits"> <property name="text"> <string/> </property> @@ -423,7 +423,7 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <widget class="QLabel" name="decode_bits"> + <widget class="DigitLabel" name="decode_bits"> <property name="text"> <string/> </property> @@ -462,21 +462,21 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> - <widget class="QLabel" name="execute_s1"> + <widget class="DigitLabel" name="execute_s1"> <property name="text"> <string/> </property> </widget> </item> <item> - <widget class="QLabel" name="execute_s2"> + <widget class="DigitLabel" name="execute_s2"> <property name="text"> <string/> </property> </widget> </item> <item> - <widget class="QLabel" name="execute_s3"> + <widget class="DigitLabel" name="execute_s3"> <property name="text"> <string/> </property> @@ -525,21 +525,21 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> - <widget class="QLabel" name="memory_s1"> + <widget class="DigitLabel" name="memory_s1"> <property name="text"> <string/> </property> </widget> </item> <item> - <widget class="QLabel" name="memory_s2"> + <widget class="DigitLabel" name="memory_s2"> <property name="text"> <string/> </property> </widget> </item> <item> - <widget class="QLabel" name="memory_s3"> + <widget class="DigitLabel" name="memory_s3"> <property name="text"> <string/> </property> @@ -585,21 +585,21 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_5"> <item> - <widget class="QLabel" name="write_s1"> + <widget class="DigitLabel" name="write_s1"> <property name="text"> <string/> </property> </widget> </item> <item> - <widget class="QLabel" name="write_s2"> + <widget class="DigitLabel" name="write_s2"> <property name="text"> <string/> </property> </widget> </item> <item> - <widget class="QLabel" name="write_s3"> + <widget class="DigitLabel" name="write_s3"> <property name="text"> <string/> </property> @@ -618,23 +618,59 @@ <item> <layout class="QVBoxLayout" name="verticalLayout_6"> <item> - <widget class="QLabel" name="label_15"> - <property name="font"> - <font> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Program State</string> - </property> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_13"> + <item> + <widget class="QLabel" name="state_header"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>State</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox"> + <property name="text"> + <string>Decimal</string> + </property> + </widget> + </item> + </layout> </item> <item> - <widget class="QLabel" name="cycles_label"> - <property name="text"> - <string>Clock Cycles</string> - </property> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_11"> + <item> + <widget class="QLabel" name="pc"> + <property name="text"> + <string>PC</string> + </property> + </widget> + </item> + <item> + <widget class="DigitLabel" name="p_counter"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="cycles"> + <property name="text"> + <string>Cycle</string> + </property> + </widget> + </item> + <item> + <widget class="DigitLabel" name="cycle_counter"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> </item> <item> <widget class="Line" name="line_10"> @@ -706,9 +742,14 @@ <customwidget> <class>DynamicWaysEntry</class> <extends>QWidget</extends> - <header location="global">dynamicwaysentry.h</header> + <header>dynamicwaysentry.h</header> <container>1</container> </customwidget> + <customwidget> + <class>DigitLabel</class> + <extends>QLabel</extends> + <header location="global">digitlabel.h</header> + </customwidget> </customwidgets> <resources/> <connections/> diff --git a/gui/worker.cc b/gui/worker.cc index 742e3f3..43db5bd 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -50,6 +50,7 @@ void Worker::configure( delete old; this->ct_mutex.unlock(); + std::cout << this->ct->get_clock_cycle() << ":" << this->ct->get_pc() << std::endl; emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); } |