aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/registersdock.cpp
blob: 20eb9e424831c3f058805ceadf7282fc6366ae12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "registersdock.h"

RegistersDock::RegistersDock(QWidget *parent) : QDockWidget(parent) {
    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 layout;
    delete pc, hi, lo;
    for (int i = 0; i < 32; i++)
        delete gp[i];
}

void RegistersDock::setup(machine::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);
}