Skip to content

Commit e26d895

Browse files
committed
Registers and cop0 state updates and reads are visualized by highlights.
Signed-off-by: Pavel Pisa <[email protected]>
1 parent 6312493 commit e26d895

File tree

8 files changed

+145
-13
lines changed

8 files changed

+145
-13
lines changed

qtmips_gui/cop0dock.cpp

+43-3
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,24 @@ Cop0Dock::Cop0Dock(QWidget *parent) : QDockWidget(parent) {
5050
} while(false)
5151

5252
cop0reg[0] = nullptr;
53-
for (int i = 1; i < machine::Cop0State::COP0REGS_CNT; i++)
53+
for (int i = 1; i < machine::Cop0State::COP0REGS_CNT; i++) {
5454
INIT(cop0reg[i], machine::Cop0State::cop0reg_name((machine::Cop0State::Cop0Registers)i));
55+
cop0reg_highlighted[i] = false;
56+
}
5557
#undef INIT
5658
scrollarea->setWidget(widg);
5759

5860
setWidget(scrollarea);
5961
setObjectName("Coprocessor0");
6062
setWindowTitle("Coprocessor0");
63+
64+
pal_normal = QPalette(cop0reg[1]->palette());
65+
pal_updated = QPalette(cop0reg[1]->palette());
66+
pal_read = QPalette(cop0reg[1]->palette());
67+
pal_normal.setColor(QPalette::WindowText, QColor(0, 0, 0));
68+
pal_updated.setColor(QPalette::WindowText, QColor(240, 0, 0));
69+
pal_read.setColor(QPalette::WindowText, QColor(0, 0, 240));
70+
cop0reg_highlighted_any = false;
6171
}
6272

6373
Cop0Dock::~Cop0Dock() {
@@ -76,18 +86,48 @@ void Cop0Dock::setup(machine::QtMipsMachine *machine) {
7686
}
7787

7888
const machine::Cop0State *cop0state = machine->cop0state();
79-
connect(cop0state, &machine::Cop0State::cop0reg_update,
80-
this, &Cop0Dock::cop0reg_changed);
8189

8290
for (int i = 1; i < machine::Cop0State::COP0REGS_CNT; i++)
8391
labelVal(cop0reg[i], cop0state->read_cop0reg((machine::Cop0State::Cop0Registers)i));
92+
93+
connect(cop0state, &machine::Cop0State::cop0reg_update,
94+
this, &Cop0Dock::cop0reg_changed);
95+
connect(cop0state, &machine::Cop0State::cop0reg_read,
96+
this, &Cop0Dock::cop0reg_read);
97+
connect(machine, SIGNAL(tick()), this, SLOT(clear_highlights()));
8498
}
8599

86100
void Cop0Dock::cop0reg_changed(enum machine::Cop0State::Cop0Registers reg, std::uint32_t val) {
87101
SANITY_ASSERT((uint)reg < machine::Cop0State::COP0REGS_CNT && (uint)reg,
88102
QString("Cop0Dock received signal with invalid cop0 register: ") +
89103
QString::number((uint)reg));
90104
labelVal(cop0reg[(uint)reg], val);
105+
cop0reg[reg]->setPalette(pal_updated);
106+
cop0reg_highlighted[reg] = true;
107+
cop0reg_highlighted_any = true;
108+
}
109+
110+
void Cop0Dock::cop0reg_read(enum machine::Cop0State::Cop0Registers reg, std::uint32_t val) {
111+
(void)val;
112+
SANITY_ASSERT((uint)reg < machine::Cop0State::COP0REGS_CNT && (uint)reg,
113+
QString("Cop0Dock received signal with invalid cop0 register: ") +
114+
QString::number((uint)reg));
115+
if (!cop0reg_highlighted[reg])
116+
cop0reg[reg]->setPalette(pal_read);
117+
cop0reg_highlighted[reg] = true;
118+
cop0reg_highlighted_any = true;
119+
}
120+
121+
void Cop0Dock::clear_highlights() {
122+
if (!cop0reg_highlighted_any)
123+
return;
124+
for (int i = 1; i < machine::Cop0State::COP0REGS_CNT; i++) {
125+
if (cop0reg_highlighted[i]) {
126+
cop0reg[i]->setPalette(pal_normal);
127+
cop0reg_highlighted[i] = false;
128+
}
129+
}
130+
cop0reg_highlighted_any = false;
91131
}
92132

93133
void Cop0Dock::labelVal(QLabel *label, std::uint32_t value) {

qtmips_gui/cop0dock.h

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <QFormLayout>
4242
#include <QScrollArea>
4343
#include <QPropertyAnimation>
44+
#include <QPalette>
4445
#include "qtmipsmachine.h"
4546
#include "statictable.h"
4647

@@ -54,12 +55,20 @@ class Cop0Dock : public QDockWidget {
5455

5556
private slots:
5657
void cop0reg_changed(enum machine::Cop0State::Cop0Registers reg, std::uint32_t val);
58+
void cop0reg_read(enum machine::Cop0State::Cop0Registers reg, std::uint32_t val);
59+
void clear_highlights();
5760

5861
private:
5962
StaticTable *widg;
6063
QScrollArea *scrollarea;
6164

6265
QLabel *cop0reg[machine::Cop0State::COP0REGS_CNT];
66+
bool cop0reg_highlighted[machine::Cop0State::COP0REGS_CNT];
67+
bool cop0reg_highlighted_any;
68+
69+
QPalette pal_normal;
70+
QPalette pal_updated;
71+
QPalette pal_read;
6372

6473
void labelVal(QLabel *label, std::uint32_t val);
6574
};

qtmips_gui/registersdock.cpp

+64-5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ RegistersDock::RegistersDock(QWidget *parent) : QDockWidget(parent) {
7474
scrollarea = new QScrollArea(this);
7575
scrollarea->setWidgetResizable(true);
7676
widg = new StaticTable(scrollarea);
77+
gp_highlighted = 0;
78+
hi_highlighted = false;
79+
lo_highlighted = false;
7780

7881
#define INIT(X, LABEL) do{ \
7982
X = new QLabel("0x00000000", widg); \
@@ -94,6 +97,13 @@ RegistersDock::RegistersDock(QWidget *parent) : QDockWidget(parent) {
9497
setWidget(scrollarea);
9598
setObjectName("Registers");
9699
setWindowTitle("Registers");
100+
101+
pal_normal = QPalette(gp[0]->palette());
102+
pal_updated = QPalette(gp[0]->palette());
103+
pal_read = QPalette(gp[0]->palette());
104+
pal_normal.setColor(QPalette::WindowText, QColor(0, 0, 0));
105+
pal_updated.setColor(QPalette::WindowText, QColor(240, 0, 0));
106+
pal_read.setColor(QPalette::WindowText, QColor(0, 0, 240));
97107
}
98108

99109
RegistersDock::~RegistersDock() {
@@ -118,16 +128,20 @@ void RegistersDock::setup(machine::QtMipsMachine *machine) {
118128
}
119129

120130
const machine::Registers *regs = machine->registers();
121-
connect(regs, SIGNAL(pc_update(std::uint32_t)), this, SLOT(pc_changed(std::uint32_t)));
122-
connect(regs, SIGNAL(gp_update(std::uint8_t,std::uint32_t)), this, SLOT(gp_changed(std::uint8_t,std::uint32_t)));
123-
connect(regs, SIGNAL(hi_lo_update(bool,std::uint32_t)), this, SLOT(hi_lo_changed(bool,std::uint32_t)));
124131

125132
// Load values
126133
labelVal(pc, regs->read_pc());
127134
labelVal(hi, regs->read_hi_lo(true));
128135
labelVal(lo, regs->read_hi_lo(false));
129136
for (int i = 0; i < 32; i++)
130137
labelVal(gp[i], regs->read_gp(i));
138+
139+
connect(regs, SIGNAL(pc_update(std::uint32_t)), this, SLOT(pc_changed(std::uint32_t)));
140+
connect(regs, SIGNAL(gp_update(std::uint8_t,std::uint32_t)), this, SLOT(gp_changed(std::uint8_t,std::uint32_t)));
141+
connect(regs, SIGNAL(hi_lo_update(bool,std::uint32_t)), this, SLOT(hi_lo_changed(bool,std::uint32_t)));
142+
connect(regs, SIGNAL(gp_read(std::uint8_t,std::uint32_t)), this, SLOT(gp_read(std::uint8_t,std::uint32_t)));
143+
connect(regs, SIGNAL(hi_lo_read(bool,std::uint32_t)), this, SLOT(hi_lo_read(bool,std::uint32_t)));
144+
connect(machine, SIGNAL(tick()), this, SLOT(clear_highlights()));
131145
}
132146

133147
void RegistersDock::pc_changed(std::uint32_t val) {
@@ -137,13 +151,58 @@ void RegistersDock::pc_changed(std::uint32_t val) {
137151
void RegistersDock::gp_changed(std::uint8_t i, std::uint32_t val) {
138152
SANITY_ASSERT(i < 32, QString("RegistersDock received signal with invalid gp register: ") + QString::number(i));
139153
labelVal(gp[i], val);
154+
gp[i]->setPalette(pal_updated);
155+
gp_highlighted |= 1 << i;
156+
}
157+
158+
void RegistersDock::gp_read(std::uint8_t i, std::uint32_t val) {
159+
(void)val;
160+
SANITY_ASSERT(i < 32, QString("RegistersDock received signal with invalid gp register: ") + QString::number(i));
161+
if (!(gp_highlighted & (1 << i))) {
162+
gp[i]->setPalette(pal_read);
163+
gp_highlighted |= 1 << i;
164+
}
140165
}
141166

142167
void RegistersDock::hi_lo_changed(bool hi, std::uint32_t val) {
143-
if (hi)
168+
if (hi) {
144169
labelVal(this->hi, val);
145-
else
170+
this->hi->setPalette(pal_updated);
171+
hi_highlighted = true;
172+
} else {
146173
labelVal(lo, val);
174+
this->lo->setPalette(pal_updated);
175+
lo_highlighted = true;
176+
}
177+
}
178+
179+
void RegistersDock::hi_lo_read(bool hi, std::uint32_t val) {
180+
(void)val;
181+
if (hi) {
182+
if (!hi_highlighted)
183+
this->hi->setPalette(pal_read);
184+
hi_highlighted = true;
185+
} else {
186+
if (!lo_highlighted)
187+
this->lo->setPalette(pal_read);
188+
lo_highlighted = true;
189+
}
190+
}
191+
192+
void RegistersDock::clear_highlights() {
193+
if (hi_highlighted)
194+
this->hi->setPalette(pal_normal);
195+
if (lo_highlighted)
196+
this->lo->setPalette(pal_normal);
197+
if (gp_highlighted != 0) {
198+
for (int i = 0; i < 32; i++) {
199+
if (gp_highlighted & (1 << i))
200+
gp[i]->setPalette(pal_normal);
201+
}
202+
}
203+
gp_highlighted = 0;
204+
hi_highlighted = false;
205+
lo_highlighted = false;
147206
}
148207

149208
void RegistersDock::labelVal(QLabel *label, std::uint32_t value) {

qtmips_gui/registersdock.h

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <QFormLayout>
4242
#include <QScrollArea>
4343
#include <QPropertyAnimation>
44+
#include <QPalette>
4445
#include "qtmipsmachine.h"
4546
#include "statictable.h"
4647

@@ -56,6 +57,9 @@ private slots:
5657
void pc_changed(std::uint32_t val);
5758
void gp_changed(std::uint8_t i, std::uint32_t val);
5859
void hi_lo_changed(bool hi, std::uint32_t val);
60+
void gp_read(std::uint8_t i, std::uint32_t val);
61+
void hi_lo_read(bool hi, std::uint32_t val);
62+
void clear_highlights();
5963

6064
private:
6165
StaticTable *widg;
@@ -66,6 +70,14 @@ private slots:
6670
QLabel *lo;
6771
QLabel *gp[32];
6872

73+
std::uint32_t gp_highlighted;
74+
bool hi_highlighted;
75+
bool lo_highlighted;
76+
77+
QPalette pal_normal;
78+
QPalette pal_updated;
79+
QPalette pal_read;
80+
6981
void labelVal(QLabel *label, std::uint32_t val);
7082
};
7183

qtmips_machine/cop0state.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ QString Cop0State::cop0reg_name(enum Cop0Registers reg) {
150150
}
151151

152152
std::uint32_t Cop0State::read_cop0reg_default(enum Cop0Registers reg) const {
153-
return cop0reg[(int)reg];
153+
std::uint32_t val;
154+
val = cop0reg[(int)reg];
155+
emit cop0reg_read(reg, val);
156+
return val;
154157
}
155158

156159
void Cop0State::write_cop0reg_default(enum Cop0Registers reg, std::uint32_t value) {

qtmips_machine/cop0state.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class Cop0State : public QObject {
8989

9090
signals:
9191
void cop0reg_update(enum Cop0Registers reg, std::uint32_t val);
92+
void cop0reg_read(enum Cop0Registers reg, std::uint32_t val) const;
9293

9394
public slots:
9495
void set_interrupt_signal(uint irq_num, bool active);

qtmips_machine/registers.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,31 @@ void Registers::pc_abs_jmp_28(std::uint32_t address) {
8787
}
8888

8989
std::uint32_t Registers::read_gp(std::uint8_t i) const {
90+
std::uint32_t value;
9091
SANITY_ASSERT(i < 32, QString("Trying to read from register ") + QString(i));
9192
if (!i) // $0 always reads as 0
9293
return 0;
93-
return this->gp[i - 1];
94+
value = this->gp[i - 1];
95+
emit gp_read(i, value);
96+
return value;
9497
}
9598

9699
void Registers::write_gp(std::uint8_t i, std::uint32_t value) {
97100
SANITY_ASSERT(i < 32, QString("Trying to write to register ") + QString(i));
98101
if (i == 0) // Skip write to $0
99102
return;
100-
emit gp_update(i, value);
101103
this->gp[i - 1] = value;
104+
emit gp_update(i, value);
102105
}
103106

104107
std::uint32_t Registers::read_hi_lo(bool is_hi) const {
108+
std::uint32_t value;
105109
if (is_hi)
106-
return hi;
110+
value = hi;
107111
else
108-
return lo;
112+
value = lo;
113+
emit hi_lo_read(is_hi, value);
114+
return value;
109115
}
110116

111117
void Registers::write_hi_lo(bool is_hi, std::uint32_t value) {

qtmips_machine/registers.h

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class Registers : public QObject {
6767
void pc_update(std::uint32_t val);
6868
void gp_update(std::uint8_t i, std::uint32_t val);
6969
void hi_lo_update(bool hi, std::uint32_t val);
70+
void gp_read(std::uint8_t i, std::uint32_t val) const;
71+
void hi_lo_read(bool hi, std::uint32_t val) const;
7072

7173
private:
7274
std::uint32_t gp[31]; // general-purpose registers ($0 is intentionally skipped)

0 commit comments

Comments
 (0)