diff options
Diffstat (limited to 'qtmips_gui/coreview')
| -rw-r--r-- | qtmips_gui/coreview/adder.cpp | 69 | ||||
| -rw-r--r-- | qtmips_gui/coreview/adder.h | 32 | ||||
| -rw-r--r-- | qtmips_gui/coreview/alu.cpp | 9 | ||||
| -rw-r--r-- | qtmips_gui/coreview/alu.h | 11 | ||||
| -rw-r--r-- | qtmips_gui/coreview/connection.cpp | 90 | ||||
| -rw-r--r-- | qtmips_gui/coreview/connection.h | 46 | ||||
| -rw-r--r-- | qtmips_gui/coreview/constant.cpp | 48 | ||||
| -rw-r--r-- | qtmips_gui/coreview/constant.h | 35 | ||||
| -rw-r--r-- | qtmips_gui/coreview/instructionview.cpp | 9 | ||||
| -rw-r--r-- | qtmips_gui/coreview/instructionview.h | 20 | ||||
| -rw-r--r-- | qtmips_gui/coreview/junction.cpp | 36 | ||||
| -rw-r--r-- | qtmips_gui/coreview/junction.h | 28 | ||||
| -rw-r--r-- | qtmips_gui/coreview/latch.cpp | 22 | ||||
| -rw-r--r-- | qtmips_gui/coreview/latch.h | 17 | ||||
| -rw-r--r-- | qtmips_gui/coreview/memory.cpp | 124 | ||||
| -rw-r--r-- | qtmips_gui/coreview/memory.h | 39 | ||||
| -rw-r--r-- | qtmips_gui/coreview/multiplexer.cpp | 16 | ||||
| -rw-r--r-- | qtmips_gui/coreview/multiplexer.h | 7 | ||||
| -rw-r--r-- | qtmips_gui/coreview/programcounter.cpp | 26 | ||||
| -rw-r--r-- | qtmips_gui/coreview/programcounter.h | 8 | ||||
| -rw-r--r-- | qtmips_gui/coreview/registers.cpp | 95 | ||||
| -rw-r--r-- | qtmips_gui/coreview/registers.h | 44 | 
22 files changed, 679 insertions, 152 deletions
diff --git a/qtmips_gui/coreview/adder.cpp b/qtmips_gui/coreview/adder.cpp new file mode 100644 index 0000000..cd227ab --- /dev/null +++ b/qtmips_gui/coreview/adder.cpp @@ -0,0 +1,69 @@ +#include "adder.h" +#include <cmath> + +using namespace coreview; + +////////////////////// +#define WIDTH 13 +#define HEIGHT 40 +#define DENT 3 +#define PENW 1 +////////////////////// + +Adder::Adder() : QGraphicsItem(nullptr), plus("+", this) { +    QFont font; +    font.setPointSize(7); +    plus.setFont(font); +    QRectF plus_box = plus.boundingRect(); +    plus.setPos(DENT + (WIDTH-DENT)/2 - plus_box.width()/2, HEIGHT/2 - plus_box.height()/2); + +    con_in_a = new Connector(0); +    con_in_b = new Connector(0); +    con_out = new Connector(M_PI); + +    setPos(x(), y()); // set connector's position +} + +Adder::~Adder() { +    delete con_in_a; +    delete con_in_b; +    delete con_out; +} + +QRectF Adder::boundingRect() const { +    return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW); +} + +void Adder::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) { +    const QPointF poly[] = { +        QPointF(0, 0), +        QPointF(WIDTH, WIDTH), +        QPointF(WIDTH, HEIGHT - WIDTH), +        QPointF(0, HEIGHT), +        QPointF(0, (HEIGHT/2) + DENT), +        QPointF(DENT, HEIGHT / 2), +        QPointF(0, (HEIGHT / 2) - DENT) +    }; +    painter->drawPolygon(poly, sizeof(poly) / sizeof(QPointF)); +} + +void Adder::setPos(qreal x, qreal y) { +    QGraphicsItem::setPos(x, y); + +    qreal off = ((HEIGHT/2) - DENT) / 2; +    con_in_a->setPos(x, y + off); +    con_in_b->setPos(x, y + HEIGHT - off); +    con_out->setPos(x + WIDTH, y + HEIGHT/2); +} + +const Connector *Adder::connector_in_a() const { +    return con_in_a; +} + +const Connector *Adder::connector_in_b() const { +    return con_in_b; +} + +const Connector *Adder::connector_out() const { +    return con_out; +} diff --git a/qtmips_gui/coreview/adder.h b/qtmips_gui/coreview/adder.h new file mode 100644 index 0000000..9de81a1 --- /dev/null +++ b/qtmips_gui/coreview/adder.h @@ -0,0 +1,32 @@ +#ifndef ADDER_H +#define ADDER_H + +#include <QGraphicsItem> +#include <QPainter> +#include <QGraphicsSimpleTextItem> +#include "connection.h" + +namespace coreview { + +class Adder : public QGraphicsItem { +public: +    Adder(); +    ~Adder(); + +    QRectF boundingRect() const; +    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +    void setPos(qreal x, qreal y); +    const Connector *connector_in_a() const; +    const Connector *connector_in_b() const; +    const Connector *connector_out() const; + +private: +    QGraphicsSimpleTextItem plus; + +    Connector *con_in_a, *con_in_b, *con_out; +}; + +} + +#endif // ADDER_H diff --git a/qtmips_gui/coreview/alu.cpp b/qtmips_gui/coreview/alu.cpp index bb48c7e..e048578 100644 --- a/qtmips_gui/coreview/alu.cpp +++ b/qtmips_gui/coreview/alu.cpp @@ -7,9 +7,11 @@  #define PENW 1  ////////////////////// -coreview::Alu::Alu() : QGraphicsObject(nullptr), name(this) { -    name.setText("ALU"); +coreview::Alu::Alu() : QGraphicsItem(nullptr), name("ALU", this) {      name.setPos(3, 25); +    QFont font; +    font.setPointSize(7); +    name.setFont(font);      con_in_a = new Connector();      con_in_b = new Connector(); @@ -37,7 +39,8 @@ void coreview::Alu::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt  }  void coreview::Alu::setPos(qreal x, qreal y) { -    QGraphicsObject::setPos(x, y); +    QGraphicsItem::setPos(x, y); +    // TODO fix this (should be relative to x and y)      qreal off = ((HEIGHT/2) - DENT) / 2;      con_in_a->setPos(0, off);      con_in_b->setPos(0, HEIGHT - off); diff --git a/qtmips_gui/coreview/alu.h b/qtmips_gui/coreview/alu.h index 4c9a73b..25d7351 100644 --- a/qtmips_gui/coreview/alu.h +++ b/qtmips_gui/coreview/alu.h @@ -1,14 +1,13 @@  #ifndef COREVIEW_ALU_H  #define COREVIEW_ALU_H -#include <QGraphicsObject> +#include <QGraphicsItem>  #include <qtmipsmachine.h> -#include "../coreview.h"  #include "connection.h"  namespace coreview { -class Alu : public QGraphicsObject { +class Alu : public QGraphicsItem {  public:      Alu(); @@ -28,10 +27,4 @@ private:  } -#else - -namespace coreview { -    class Alu; -} -  #endif // COREVIEW_ALU_H diff --git a/qtmips_gui/coreview/connection.cpp b/qtmips_gui/coreview/connection.cpp index f2b730c..85f7a96 100644 --- a/qtmips_gui/coreview/connection.cpp +++ b/qtmips_gui/coreview/connection.cpp @@ -1,11 +1,16 @@  #include "connection.h" +#include <cmath>  using namespace coreview; +Connector::Connector(qreal angle) { +    ang = angle; +} +  void Connector::setPos(qreal x, qreal y) {      qx = x;      qy = y; -    emit updated(); +    emit updated(QPointF(qx, qy));  }  qreal Connector::x() const { @@ -16,16 +21,28 @@ qreal Connector::y() const {      return qy;  } +QLineF Connector::vector() const { +    return QLineF(point(), QPointF(x() + cos(ang), y() + sin(ang))); +} +  QPointF Connector::point() const {      return QPointF(qx, qy);  } +qreal Connector::angle() const { +    return ang; +} +  Connection::Connection(const Connector *a, const Connector *b) : QGraphicsObject(nullptr) { -    connect(a, SIGNAL(updated()), this, SLOT(moved())); -    connect(b, SIGNAL(updated()), this, SLOT(moved())); -    this->a = a; -    this->b = b; -    update_pos(); +    pen_width = 1; + +    ang_start = a->angle(); +    ang_end = b->angle(); + +    connect(a, SIGNAL(updated(QPointF)), this, SLOT(moved_start(QPointF))); +    connect(b, SIGNAL(updated(QPointF)), this, SLOT(moved_end(QPointF))); +    moved_start(a->point()); +    moved_end(b->point());  }  void Connection::setHasText(bool has) { @@ -35,7 +52,6 @@ void Connection::setHasText(bool has) {      } else if (!has && value != nullptr) {          delete value;      } -    update_pos();  }  void Connection::setText(QString val) { @@ -44,36 +60,56 @@ void Connection::setText(QString val) {          value->setText(val);  } -void Connection::moved() { -    update_pos(); +void Connection::setAxes(QVector<QLineF> axes) { +    break_axes = axes; +} + +void Connection::moved_start(QPointF p) { +    p_start = p; +    recalc_line(); +} + +void Connection::moved_end(QPointF p) { +    p_end = p; +    recalc_line();  }  QRectF Connection::boundingRect() const {      QRectF rect;      for (int i = 0; i < (points.size() - 1); i++) { -        qreal x = points[i].x(); -        if (x > points[i+1].x()) -            x = points[i+1].x(); -        qreal y = points[i].y(); -        if (y > points[i+1].y()) -            y = points[i+1].y(); -        // TODO pen width -        rect = rect.united(QRectF(x - 0.5, y - 0.5, fabs(points[i].x() - points[i+1].x()) + 1, fabs(points[i].y() - points[i+1].y()) + 1)); +        qreal x = points[i].x() > points[i+1].x() ? points[i].x() : points[i+1].x(); +        qreal y = points[i].y() > points[i+1].y() ? points[i].y() : points[i+1].y(); +        rect |= QRectF(x - pen_width/2.0, y - pen_width/2.0, fabs(points[i].x() - points[i+1].x()) + pen_width, fabs(points[i].y() - points[i+1].y()) + pen_width);      } -    //return rect; -    return QRectF(0, 0, 300, 300); +    return rect;  }  void Connection::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) { -    for (int i = 0; i < (points.size() - 1); i++) -        painter->drawLine(points[i], points[i+1]); -    // TODO meaby use QPath instead? +    QPen pen; +    pen.setWidth(pen_width); +    // TODO color? +    painter->setPen(pen); + +    painter->drawPolyline(QPolygonF(points));  } -void Connection::update_pos() { +void Connection::recalc_line() {      points.clear(); -    points.append(a->point()); -    points.append(b->point()); -    // TODO more than one line -    // TODO update position of value + +    points.append(p_start); + +    QLineF cur_l(p_start, QPointF(p_start.x() + cos(ang_start), p_start.y() + sin(ang_start))); +    for (int i = 0; i < break_axes.size(); i++) { +        recalc_line_add_point(cur_l, break_axes[i]); +        cur_l = break_axes[i]; +    } +    recalc_line_add_point(cur_l, QLineF(QPoint(p_end.x() + cos(ang_end), p_end.y() + sin(ang_end)), p_end)); + +    points.append(p_end); +} + +void Connection::recalc_line_add_point(const QLineF &l1, const QLineF &l2) { +    QPointF intersec; +    if (l1.intersect(l2, &intersec) != QLineF::NoIntersection) +        points.append(intersec);  } diff --git a/qtmips_gui/coreview/connection.h b/qtmips_gui/coreview/connection.h index efe3942..0ee981e 100644 --- a/qtmips_gui/coreview/connection.h +++ b/qtmips_gui/coreview/connection.h @@ -2,59 +2,67 @@  #define COREVIEW_CONNECTION_H  #include <QGraphicsObject> -#include <QList> -#include <cmath> -#include "../coreview.h" +#include <QPainter> +#include <QVector>  namespace coreview {  class Connector : public QObject {      Q_OBJECT  public: +    Connector(qreal angle); +      void setPos(qreal x, qreal y);      qreal x() const;      qreal y() const;      QPointF point() const; +    QLineF vector() const; + +    qreal angle() const;  signals: -    void updated(); +    void updated(QPointF);  private: +    qreal ang;      qreal qx, qy;  };  class Connection : public QGraphicsObject {      Q_OBJECT  public: -    Connection(const Connector *a, const Connector *b); +    Connection(const Connector *start, const Connector *end); + +    QRectF boundingRect() const; +    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);      void setHasText(bool has);      void setText(QString val); +    void setAxes(QVector<QLineF>); +  private slots: -    void moved(); +    void moved_start(QPointF); +    void moved_end(QPointF);  private:      QGraphicsSimpleTextItem *value; -    QList<QPointF> points; -    const Connector *a, *b; +    QVector<QPointF> points; +    QPointF p_start, p_end; +    qreal ang_start, ang_end; +    QVector<QLineF> break_axes;      QString text; -    QRectF boundingRect() const; -    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +    int pen_width;      // TODO line width and possibly bus width - -    void update_pos(); +    void recalc_line(); +    void recalc_line_add_point(const QLineF &l1, const QLineF &l2);  }; -} - -#else +#define CON_AXIS_X(Y) QLineF(QPointF(0, Y), QPointF(1, Y)) +#define CON_AXIS_Y(X) QLineF(QPointF(X, 0), QPointF(X, 1)) -namespace coreview { -    class Connector; -    class Connection; -}; +}  #endif // COREVIEW_CONNECTION_H diff --git a/qtmips_gui/coreview/constant.cpp b/qtmips_gui/coreview/constant.cpp new file mode 100644 index 0000000..2f39fce --- /dev/null +++ b/qtmips_gui/coreview/constant.cpp @@ -0,0 +1,48 @@ +#include "constant.h" +#include <cmath> + +using namespace coreview; + +////////////////////// +#define OFFSET 6 +////////////////////// + +Constant::Constant(const Connector *con, const QString &text) : QGraphicsObject(nullptr), text(text, this) { +    QFont font; +    font.setPointSize(7); +    this->text.setFont(font); + +    con_our = new Connector(M_PI); +    conn = new Connection(con_our, con); +    connect(con, SIGNAL(updated(QPointF)), this, SLOT(ref_con_updated(QPointF))); +    ref_con_updated(con->point()); // update initial connector position +} + +Constant::~Constant() { +    delete conn; +    delete con_our; +} + +QRectF Constant::boundingRect() const { +    return conn->boundingRect(); +} + +void Constant::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { +    conn->paint(painter, option, widget); +} + +void Constant::set_text(const QString &text) { +    this->text.setText(text); +    set_text_pos(); // update text positioning +} + +void Constant::ref_con_updated(QPointF p) { +    con_our->setPos(p.x() - OFFSET, p.y()); +    set_text_pos(); +} + +void Constant::set_text_pos() { +    // We are using here our known position of con_our +    QRectF box = text.boundingRect(); +    text.setPos(con_our->x() - box.width() - 2, con_our->y() - box.height()/2); +} diff --git a/qtmips_gui/coreview/constant.h b/qtmips_gui/coreview/constant.h new file mode 100644 index 0000000..2d60f04 --- /dev/null +++ b/qtmips_gui/coreview/constant.h @@ -0,0 +1,35 @@ +#ifndef CONSTANT_H +#define CONSTANT_H + +#include <QGraphicsObject> +#include <QPainter> +#include <QGraphicsSimpleTextItem> +#include "connection.h" + +namespace coreview { + +class Constant : public QGraphicsObject { +    Q_OBJECT +public: +    Constant(const Connector *con, const QString &text); +    ~Constant(); + +    QRectF boundingRect() const; +    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +    void set_text(const QString &text); + +private slots: +    void ref_con_updated(QPointF); + +private: +    QGraphicsSimpleTextItem text; +    Connector *con_our; +    Connection *conn; + +    void set_text_pos(); +}; + +} + +#endif // CONSTANT_H diff --git a/qtmips_gui/coreview/instructionview.cpp b/qtmips_gui/coreview/instructionview.cpp new file mode 100644 index 0000000..202aa3c --- /dev/null +++ b/qtmips_gui/coreview/instructionview.cpp @@ -0,0 +1,9 @@ +#include "instructionview.h" + +using namespace coreview; + +InstructionView::InstructionView() : QObject(), QGraphicsSimpleTextItem() { } + +void InstructionView::instruction_update(machine::Instruction &i) { +    setText(i.to_str()); +} diff --git a/qtmips_gui/coreview/instructionview.h b/qtmips_gui/coreview/instructionview.h new file mode 100644 index 0000000..8db4756 --- /dev/null +++ b/qtmips_gui/coreview/instructionview.h @@ -0,0 +1,20 @@ +#ifndef INSTRUCTIONVIEW_H +#define INSTRUCTIONVIEW_H + +#include <QGraphicsSimpleTextItem> +#include "qtmipsmachine.h" + +namespace coreview { + +class InstructionView : public QObject, public QGraphicsSimpleTextItem { +    Q_OBJECT +public: +    InstructionView(); + +public slots: +    void instruction_update(machine::Instruction &i); +}; + +} + +#endif // INSTRUCTIONVIEW_H diff --git a/qtmips_gui/coreview/junction.cpp b/qtmips_gui/coreview/junction.cpp new file mode 100644 index 0000000..271284c --- /dev/null +++ b/qtmips_gui/coreview/junction.cpp @@ -0,0 +1,36 @@ +#include "junction.h" + +using namespace coreview; + +////////////////////// +#define DOT_SIZE 4 +////////////////////// + +Junction::Junction() : QGraphicsItem(nullptr) { } + +Junction::~Junction() { +    for (int i = 0; i < cons.size(); i++) +        delete cons[i]; +} + +QRectF Junction::boundingRect() const { +    return QRectF(-DOT_SIZE/2, -DOT_SIZE/2, DOT_SIZE, DOT_SIZE); +} + +void Junction::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) { +    painter->setBrush(QBrush(QColor(0, 0, 0))); +    painter->drawEllipse(-DOT_SIZE/2, -DOT_SIZE/2, DOT_SIZE, DOT_SIZE); +} + +void Junction::setPos(qreal x, qreal y) { +   QGraphicsItem::setPos(x, y); +   foreach (Connector *con, cons) +       con->setPos(x, y); +} + +Connector *Junction::new_connector(qreal angle) { +    Connector*n = new Connector(angle); +    cons.append(n); +    setPos(x(), y()); // set connector's position +    return n; +} diff --git a/qtmips_gui/coreview/junction.h b/qtmips_gui/coreview/junction.h new file mode 100644 index 0000000..1a8f5d7 --- /dev/null +++ b/qtmips_gui/coreview/junction.h @@ -0,0 +1,28 @@ +#ifndef JUNCTION_H +#define JUNCTION_H + +#include <QGraphicsItem> +#include <QPainter> +#include <QList> +#include "connection.h" + +namespace coreview { + +class Junction : public QGraphicsItem { +public: +    Junction(); +    ~Junction(); + +    QRectF boundingRect() const; +    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +    void setPos(qreal x, qreal y); +    Connector *new_connector(qreal angle); + +private: +    QList<Connector*> cons; +}; + +} + +#endif // JUNCTION_H diff --git a/qtmips_gui/coreview/latch.cpp b/qtmips_gui/coreview/latch.cpp index 13351a2..c3bab4f 100644 --- a/qtmips_gui/coreview/latch.cpp +++ b/qtmips_gui/coreview/latch.cpp @@ -1,15 +1,21 @@  #include "latch.h" +#include <cmath>  using namespace coreview;  ////////////////////// -#define WIDTH 10 +#define WIDTH 7  #define PENW 1  //////////////////////  Latch::Latch(machine::QtMipsMachine *machine, qreal height) : QGraphicsObject(nullptr) {      this->height = height; +    title = new QGraphicsSimpleTextItem(this); +    QFont font; +    font.setPointSize(6); +    title->setFont(font); +      wedge_animation = new QPropertyAnimation(this, "wedge_clr");      wedge_animation->setDuration(100);      wedge_animation->setStartValue(QColor(0, 0, 0)); @@ -20,7 +26,9 @@ Latch::Latch(machine::QtMipsMachine *machine, qreal height) : QGraphicsObject(nu  }  QRectF Latch::boundingRect() const { -    return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, height + PENW); +    QRectF b(-PENW / 2, -PENW / 2, WIDTH + PENW, height + PENW); +    b |= title->boundingRect(); +    return b;  }  void Latch::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) { @@ -44,6 +52,12 @@ void Latch::set_wedge_color(QColor &c) {      update();  } +void Latch::setTitle(const QString &str) { +    title->setText(str); +    QRectF box = title->boundingRect(); +    title->setPos(WIDTH/2 - box.width()/2, - box.height() - 1); +} +  void Latch::setPos(qreal x, qreal y) {      QGraphicsObject::setPos(x, y);      for (int i = 0; i < connectors.size(); i++) { @@ -55,8 +69,8 @@ void Latch::setPos(qreal x, qreal y) {  struct Latch::ConnectorPair Latch::new_connector(qreal cy) {      SANITY_ASSERT(cy < height, "Latch: Trying to create connector outside of latch height");      ConnectorPair cp; -    cp.in = new Connector(); -    cp.out = new Connector(); +    cp.in = new Connector(0); +    cp.out = new Connector(M_PI);      connectors.append(cp);      connectors_off.append(cy);      setPos(x(), y()); // Update connectors position diff --git a/qtmips_gui/coreview/latch.h b/qtmips_gui/coreview/latch.h index 951f16a..59f4df0 100644 --- a/qtmips_gui/coreview/latch.h +++ b/qtmips_gui/coreview/latch.h @@ -2,11 +2,10 @@  #define COREVIEW_LATCH_H  #include <QGraphicsObject> -#include <QList>  #include <QPropertyAnimation> +#include <QVector>  #include "qtmipsexception.h"  #include "qtmipsmachine.h" -#include "../coreview.h"  #include "connection.h"  namespace coreview { @@ -23,6 +22,8 @@ public:      QColor wedge_color();      void set_wedge_color(QColor &c); +    void setTitle(const QString &str); +      void setPos(qreal x, qreal y);      struct ConnectorPair { Connector *in, *out; }; @@ -37,8 +38,10 @@ private slots:  private:      qreal height; -    QList<ConnectorPair> connectors; -    QList<qreal> connectors_off; +    QVector<ConnectorPair> connectors; +    QVector<qreal> connectors_off; + +    QGraphicsSimpleTextItem *title;      QPropertyAnimation *wedge_animation;      QColor wedge_clr; @@ -46,10 +49,4 @@ private:  } -#else - -namespace coreview { -    class Latch; -}; -  #endif // COREVIEW_LATCH_H diff --git a/qtmips_gui/coreview/memory.cpp b/qtmips_gui/coreview/memory.cpp index c732687..13355db 100644 --- a/qtmips_gui/coreview/memory.cpp +++ b/qtmips_gui/coreview/memory.cpp @@ -1,63 +1,119 @@  #include "memory.h" +#include <cmath>  using namespace coreview;  ////////////////////// -#define WIDTH 80 -#define HEIGHT 100 +#define WIDTH 680 +#define HEIGHT 30  #define PENW 1  //////////////////////  Memory::Memory(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr) { -#define CON_INIT(X) do { \ -            X.in = new Connector(); \ -            X.out = new Connector(); \ -            X.read = new Connector(); \ -            X.write = new Connector(); \ -        } while(false) -    CON_INIT(con_program); -    CON_INIT(con_data); -#undef CON_INIT -    // TODO cache? +    con_pc = new Connector(M_PI_2); +    con_inst = new Connector(M_PI_2); +    con_address = new Connector(M_PI_2); +    con_data_in = new Connector(M_PI_2); +    con_data_out = new Connector(M_PI_2); +    con_req_write = new Connector(M_PI_2); +    con_req_read = new Connector(M_PI_2); + +    if (machine->config().cache()) { +        // TODO cache? +    } + +    name = new QGraphicsSimpleTextItem("Memory", this); +    QRectF name_box = name->boundingRect(); +    name->setPos(WIDTH/2 - name_box.width()/2, HEIGHT/2 - name_box.height()/2); + +    // TODO add labels for connections + +    QFont font; +    font.setPointSize(7); + +    // TODO better placement +    name_program = new QGraphicsSimpleTextItem("Program", this); +    name_box = name_program->boundingRect(); +    name_program->setPos(1, HEIGHT - 1 - name_box.height()); +    name_program->setFont(font); + +    name_data = new QGraphicsSimpleTextItem("Data", this); +    name_box = name_data->boundingRect(); +    name_data->setPos(WIDTH - 1 - name_box.width(), HEIGHT - 1 - name_box.height()); +    name_data->setFont(font); + +    setPos(x(), y()); // set connector's position +} + +Memory::~Memory() { +    delete con_pc; +    delete con_inst; +    delete con_address; +    delete con_data_out; +    delete con_data_in; +    delete con_req_write; +    delete con_req_read; + +    delete name; +    delete name_program; +    delete name_data;  }  QRectF Memory::boundingRect() const { -    // TODO +    return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW);  }  void Memory::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) { -    // TODO +    painter->drawRect(0, 0, WIDTH, HEIGHT); +    // TODO cache  }  void Memory::setPos(qreal x, qreal y) {      QGraphicsObject::setPos(x, y); -    // TODO con + +    con_pc->setPos(x + 30, y); +    con_inst->setPos(x + 40, y); + +    con_address->setPos(x + WIDTH - 70, y); +    con_data_in->setPos(x + WIDTH - 60, y); +    con_req_write->setPos(x + WIDTH- 50, y); +    con_req_read->setPos(x + WIDTH - 40, y); +    con_data_out->setPos(x + WIDTH - 30, y);  } -const Connector *Memory::connector_in(bool program) const { -    if (program) -        return con_program.in; -    else -        return con_data.in; +const Connector *Memory::connector_pc() const { +    return con_pc;  } -const Connector *Memory::connector_out(bool program) const { -    if (program) -        return con_program.out; -    else -        return con_data.out; +const Connector *Memory::connector_inst() const { +    return con_inst;  } -const Connector *Memory::connector_read(bool program) const { -    if (program) -        return con_program.read; -    else -        return con_data.read; +const Connector *Memory::connector_address() const { +    return con_address; +} + +const Connector *Memory::connector_data_out() const { +    return con_data_out; +} + +const Connector *Memory::connector_data_in() const { +    return con_data_in; +} + +const Connector *Memory::connector_req_write() const { +    return con_req_write;  } -const Connector *Memory::connector_write(bool program) const { -    if (program) -        return con_program.write; +const Connector *Memory::connector_req_read() const { +    return con_req_read; +} + +void Memory::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { +    QGraphicsObject::mouseDoubleClickEvent(event); + +    if (event->pos().x() < WIDTH/2) +        emit open_program_mem();      else -        return con_data.write; +        emit open_data_mem();  } diff --git a/qtmips_gui/coreview/memory.h b/qtmips_gui/coreview/memory.h index 0f0d40d..067d62f 100644 --- a/qtmips_gui/coreview/memory.h +++ b/qtmips_gui/coreview/memory.h @@ -3,39 +3,48 @@  #include <QGraphicsObject>  #include <QPainter> +#include <QGraphicsSceneMouseEvent> +#include <QGraphicsSimpleTextItem>  #include <qtmipsmachine.h> -#include "../coreview.h"  #include "connection.h" -namespace coreview{ +namespace coreview {  class Memory : public QGraphicsObject  {      Q_OBJECT  public:      Memory(machine::QtMipsMachine *machine); +    ~Memory();      QRectF boundingRect() const;      void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);      void setPos(qreal x, qreal y); -    const Connector *connector_in(bool program) const; -    const Connector *connector_out(bool program) const; -    const Connector *connector_read(bool program) const; -    const Connector *connector_write(bool program) const; +    const Connector *connector_pc() const; +    const Connector *connector_inst() const; +    const Connector *connector_address() const; +    const Connector *connector_data_out() const; +    const Connector *connector_data_in() const; +    const Connector *connector_req_write() const; +    const Connector *connector_req_read() const;      // TODO integrate cache -private: -    struct { -        Connector *in, *out, *read, *write; -    } con_program, con_data; -}; +signals: +    void open_data_mem(); +    void open_program_mem(); -} +protected: +    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); -#else +private: +    // Connectors for instruction memory +    Connector *con_pc, *con_inst; +    // Connectors for data memory +    Connector *con_address, *con_data_out, *con_data_in, *con_req_write, *con_req_read; + +    QGraphicsSimpleTextItem *name, *name_program, *name_data; +}; -namespace coreview { -    class Memory;  }  #endif // MEMORY_H diff --git a/qtmips_gui/coreview/multiplexer.cpp b/qtmips_gui/coreview/multiplexer.cpp index 6f6abe1..b8bab5a 100644 --- a/qtmips_gui/coreview/multiplexer.cpp +++ b/qtmips_gui/coreview/multiplexer.cpp @@ -1,9 +1,10 @@  #include "multiplexer.h" +#include <cmath>  using namespace coreview;  ////////////////////// -#define WIDTH 20 +#define WIDTH 10  #define HEIGHT 20  #define PENW 1  ////////////////////// @@ -12,11 +13,11 @@ Multiplexer::Multiplexer(unsigned size) {      this->size = size;      seton = 0;      ctlfrom = false; -    con_ctl = new Connector(); -    con_out = new Connector(); +    con_ctl = new Connector(M_PI_2); +    con_out = new Connector(M_PI);      con_in = new Connector*[size];      for (unsigned i = 0; i < size; i++) -        con_in[i] = new Connector(); +        con_in[i] = new Connector(0);      setPos(x(), y()); // Set connectors possitions  } @@ -33,6 +34,10 @@ QRectF Multiplexer::boundingRect() const {  }  void Multiplexer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) { +    painter->setPen(QColor(200, 200, 200)); +    painter->drawLine(0, (HEIGHT / 2) + (seton * HEIGHT), WIDTH, (HEIGHT * size) / 2); + +    painter->setPen(QColor(0, 0, 0));      const QPointF poly[] = {          QPointF(0, 0),          QPointF(WIDTH, WIDTH), @@ -40,9 +45,6 @@ void Multiplexer::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio          QPointF(0, HEIGHT * size)      };      painter->drawPolygon(poly, sizeof(poly) / sizeof(QPointF)); - -    painter->setPen(QColor(200, 200, 200)); -    painter->drawLine(0, (HEIGHT / 2) + (seton * HEIGHT), WIDTH, (HEIGHT * size) / 2);  }  void Multiplexer::setPos(qreal x, qreal y) { diff --git a/qtmips_gui/coreview/multiplexer.h b/qtmips_gui/coreview/multiplexer.h index 16378fe..2ce7dab 100644 --- a/qtmips_gui/coreview/multiplexer.h +++ b/qtmips_gui/coreview/multiplexer.h @@ -3,7 +3,6 @@  #include <QGraphicsItem>  #include "qtmipsexception.h" -#include "../coreview.h"  #include "connection.h"  namespace coreview { @@ -32,10 +31,4 @@ private:  } -#else - -namespace coreview { -    class Multiplexer; -} -  #endif // COREVIEW_MULTIPLEXER_H diff --git a/qtmips_gui/coreview/programcounter.cpp b/qtmips_gui/coreview/programcounter.cpp index 1f4e623..b66d7ac 100644 --- a/qtmips_gui/coreview/programcounter.cpp +++ b/qtmips_gui/coreview/programcounter.cpp @@ -1,23 +1,29 @@  #include "programcounter.h" +#include <cmath>  using namespace coreview;  ////////////////////// -#define WIDTH 80 -#define HEIGHT 50 +#define WIDTH 72 +#define HEIGHT 25  #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(1, HEIGHT/2 - value.boundingRect().height()/2); -    name.setText(QString("PC")); +ProgramCounter::ProgramCounter(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr), name("PC", this), value(this) { +    QFont font; + +    font.setPointSize(7);      name.setPos(WIDTH/2 - name.boundingRect().width()/2, 0); +    name.setFont(font); +    font.setPointSize(8); +    value.setText(QString("0x") + QString::number(machine->registers()->read_pc(), 16)); +    value.setPos(1, HEIGHT - value.boundingRect().height()); +    value.setFont(font);      connect(machine->registers(), SIGNAL(pc_update(std::uint32_t)), this, SLOT(pc_update(std::uint32_t))); -    con_in = new Connector(); -    con_out = new Connector(); +    con_in = new Connector(M_PI_2); +    con_out = new Connector(-M_PI_2);      setPos(x(), y()); // To set initial connectors positions  } @@ -31,8 +37,8 @@ void ProgramCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem *op  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); +    con_in->setPos(x + WIDTH/2, y); +    con_out->setPos(x + WIDTH/2, y + HEIGHT);  }  const Connector *ProgramCounter::connector_in() const { diff --git a/qtmips_gui/coreview/programcounter.h b/qtmips_gui/coreview/programcounter.h index 220b42e..c60ad36 100644 --- a/qtmips_gui/coreview/programcounter.h +++ b/qtmips_gui/coreview/programcounter.h @@ -4,7 +4,6 @@  #include <QGraphicsObject>  #include <QPainter>  #include "qtmipsmachine.h" -#include "../coreview.h"  #include "connection.h"  namespace coreview { @@ -25,18 +24,13 @@ private slots:      void pc_update(std::uint32_t val);  private: -    QGraphicsSimpleTextItem value;      QGraphicsSimpleTextItem name; +    QGraphicsSimpleTextItem value;      Connector *con_in, *con_out;  };  } -#else - -namespace coreview { -    class ProgramCounter; -};  #endif // COREVIEW_PROGRAMCOUNTER_H diff --git a/qtmips_gui/coreview/registers.cpp b/qtmips_gui/coreview/registers.cpp new file mode 100644 index 0000000..12684e8 --- /dev/null +++ b/qtmips_gui/coreview/registers.cpp @@ -0,0 +1,95 @@ +#include "registers.h" +#include <cmath> + +using namespace coreview; + +////////////////////// +#define WIDTH 680 +#define HEIGHT 30 +#define PENW 1 +////////////////////// + +Registers::Registers() : QGraphicsObject(nullptr) { +    con_read1 = new Connector(-M_PI_2); +    con_read1_reg = new Connector(-M_PI_2); +    con_read2 = new Connector(-M_PI_2); +    con_read2_reg = new Connector(-M_PI_2); +    con_write = new Connector(-M_PI_2); +    con_write_reg = new Connector(-M_PI_2); +    con_ctl_write = new Connector(-M_PI_2); + +    // TODO do we want to have any hooks on real registers? + +    // TODO add labels for connections + +    name = new QGraphicsSimpleTextItem("Registers", this); +    QRectF name_box = name->boundingRect(); +    name->setPos(WIDTH/2 - name_box.width()/2, HEIGHT/2 - name_box.height()/2); + +    setPos(x(), y()); // set connector's position +} + +Registers::~Registers() { +    delete con_read1; +    delete con_read1_reg; +    delete con_read2; +    delete con_read2_reg; +    delete con_write; +    delete con_write_reg; +    delete con_ctl_write; +} + +QRectF Registers::boundingRect() const { +    return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW); +} + +void Registers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute((unused)), QWidget *widget __attribute((unused))) { +    painter->drawRect(0, 0, WIDTH, HEIGHT); +    // TODO anything else? +} + +void Registers::setPos(qreal x, qreal y) { +    QGraphicsObject::setPos(x, y); + +    con_read1_reg->setPos(x + 30, y + HEIGHT); +    con_read2_reg->setPos(x + 40, y + HEIGHT); +    con_read1->setPos(x + 60, y + HEIGHT); +    con_read2->setPos(x + 70, y + HEIGHT); + +    con_write_reg->setPos(x + WIDTH - 40, y + HEIGHT); +    con_write->setPos(x + WIDTH - 30, y + HEIGHT); +    con_ctl_write->setPos(x + WIDTH - 20, y + HEIGHT); +} + +const Connector *Registers::connector_read1() const { +    return con_read1; +} + +const Connector *Registers::connector_read1_reg() const { +    return con_read1_reg; +} + +const Connector *Registers::connector_read2() const { +    return con_read2; +} + +const Connector *Registers::connector_read2_reg() const { +    return con_read2_reg; +} + +const Connector *Registers::connector_write() const { +    return con_write; +} + +const Connector *Registers::connector_write_reg() const { +    return con_write_reg; +} + +const Connector *Registers::connector_ctl_write() const { +    return con_ctl_write; +} + +void Registers::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { +    QGraphicsObject::mouseDoubleClickEvent(event); +    emit open_registers(); +} diff --git a/qtmips_gui/coreview/registers.h b/qtmips_gui/coreview/registers.h new file mode 100644 index 0000000..ece710d --- /dev/null +++ b/qtmips_gui/coreview/registers.h @@ -0,0 +1,44 @@ +#ifndef COREVIEW_REGISTERS_H +#define COREVIEW_REGISTERS_H + +#include <QGraphicsObject> +#include <QPainter> +#include <QGraphicsSimpleTextItem> +#include "connection.h" + +namespace coreview { + +class Registers : public QGraphicsObject { +    Q_OBJECT +public: +    Registers(); +    ~Registers(); + +    QRectF boundingRect() const; +    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +    void setPos(qreal x, qreal y); +    const Connector *connector_read1() const; +    const Connector *connector_read1_reg() const; +    const Connector *connector_read2() const; +    const Connector *connector_read2_reg() const; +    const Connector *connector_write() const; +    const Connector *connector_write_reg() const; +    const Connector *connector_ctl_write() const; + +signals: +    void open_registers(); + +protected: +    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + +private: +    Connector *con_read1, *con_read1_reg, *con_read2, *con_read2_reg; +    Connector *con_write, *con_write_reg, *con_ctl_write; + +    QGraphicsSimpleTextItem *name; +}; + +} + +#endif // COREVIEW_REGISTERS_H  | 
