From 2b5ca09c90c5e091c094e9ed8f02079674b8aeda Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 19 Apr 2025 15:14:56 -0400 Subject: Add new widget to display number in base 10 and 16 --- gui/digitlabel.cc | 39 +++++++++++++++++++++++ gui/digitlabel.h | 52 ++++++++++++++++++++++++++++++ gui/gui.cc | 36 +++++++++------------ gui/gui.h | 2 +- gui/gui.ui | 95 +++++++++++++++++++++++++++++++++++++++---------------- gui/worker.cc | 1 + 6 files changed, 176 insertions(+), 49 deletions(-) create mode 100644 gui/digitlabel.cc create mode 100644 gui/digitlabel.h (limited to 'gui') 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 + +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 diff --git a/gui/gui.cc b/gui/gui.cc index 6cb9ada..94ddd0e 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -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 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 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 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 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 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(); diff --git a/gui/gui.h b/gui/gui.h index 4c47874..b7016ab 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -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 info); diff --git a/gui/gui.ui b/gui/gui.ui index d442c8a..2447a93 100644 --- a/gui/gui.ui +++ b/gui/gui.ui @@ -384,7 +384,7 @@ - + @@ -423,7 +423,7 @@ - + @@ -462,21 +462,21 @@ - + - + - + @@ -525,21 +525,21 @@ - + - + - + @@ -585,21 +585,21 @@ - + - + - + @@ -618,23 +618,59 @@ - - - - true - - - - Program State - - + + + + + + true + + + + State + + + + + + + Decimal + + + + - - - Clock Cycles - - + + + + + PC + + + + + + + + + + + + + + Cycle + + + + + + + + + + + @@ -706,9 +742,14 @@ DynamicWaysEntry QWidget -
dynamicwaysentry.h
+
dynamicwaysentry.h
1
+ + DigitLabel + QLabel +
digitlabel.h
+
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()); } -- cgit v1.2.3