aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/coreview/programcounter.cpp
blob: a6565c7385cbbab54609759f035a44362b24e050 (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
#include "programcounter.h"

using namespace coreview;

//////////////////////
#define WIDTH 80
#define HEIGHT 100
#define PENW 1
//////////////////////

ProgramCounter::ProgramCounter(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr), value(this), name(this) {
    value.setText(QString("0x") + QString::number(machine->registers()->read_pc(), 16));
    value.setPos(0, HEIGHT/2 - value.boundingRect().height()/2);
    name.setText(QString("PC"));
    name.setPos(WIDTH/2 - name.boundingRect().width()/2, 0);

    connect(machine->registers(), SIGNAL(pc_update(std::uint32_t)), this, SLOT(pc_update(std::uint32_t)));

    con_in = new Connector();
    con_out = new Connector();
    setPos(x(), y()); // To set initial connectors positions
}

QRectF ProgramCounter::boundingRect() const {
    return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW);
}

void ProgramCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) {
    painter->drawRect(0, 0, WIDTH, HEIGHT);
}

void ProgramCounter::setPos(qreal x, qreal y) {
    QGraphicsObject::setPos(x, y);
    con_in->setPos(x, y + HEIGHT/2);
    con_out->setPos(x + WIDTH, y + HEIGHT/2);
}

const Connector *ProgramCounter::connector_in() const {
    return con_in;
}

const Connector *ProgramCounter::connector_out() const {
    return con_out;
}

void ProgramCounter::pc_update(std::uint32_t val) {
    value.setText(QString("0x") + QString::number(val, 16));
}