aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qtmips_gui/coreview.cpp3
-rw-r--r--qtmips_gui/coreview.h2
-rw-r--r--qtmips_gui/coreview/alu.cpp62
-rw-r--r--qtmips_gui/coreview/alu.h37
-rw-r--r--qtmips_gui/qtmips_gui.pro9
5 files changed, 110 insertions, 3 deletions
diff --git a/qtmips_gui/coreview.cpp b/qtmips_gui/coreview.cpp
index 6630ad1..b7c17fc 100644
--- a/qtmips_gui/coreview.cpp
+++ b/qtmips_gui/coreview.cpp
@@ -11,17 +11,20 @@ CoreView::CoreView(QWidget *parent, machine::QtMipsMachine *machine) : QGraphics
scene.addLine(0, 400, 800, 400);
pc = new coreview::ProgramCounter(machine);
+ alu = new coreview::Alu();
pc_multiplexer = new coreview::Multiplexer(4);
testlatch = new coreview::Latch(machine, 300);
pc2pc = new coreview::Connection(pc_multiplexer->connector_out(), pc->connector_in());
scene.addItem(pc);
+ scene.addItem(alu);
scene.addItem(pc_multiplexer);
scene.addItem(testlatch);
scene.addItem(pc2pc);
pc->setPos(100,100);
+ alu->setPos(200, 100);
pc_multiplexer->setPos(60, 100);
pc_multiplexer->set(2);
diff --git a/qtmips_gui/coreview.h b/qtmips_gui/coreview.h
index 7e9081a..8c0701e 100644
--- a/qtmips_gui/coreview.h
+++ b/qtmips_gui/coreview.h
@@ -8,6 +8,7 @@
#include "coreview/programcounter.h"
#include "coreview/multiplexer.h"
#include "coreview/latch.h"
+#include "coreview/alu.h"
class CoreView : public QGraphicsView {
Q_OBJECT
@@ -21,6 +22,7 @@ private:
machine::QtMipsMachine *machine;
coreview::ProgramCounter *pc;
+ coreview::Alu *alu;
coreview::Multiplexer *pc_multiplexer;
coreview::Connection *pc2pc;
coreview::Latch *testlatch;
diff --git a/qtmips_gui/coreview/alu.cpp b/qtmips_gui/coreview/alu.cpp
new file mode 100644
index 0000000..76cf8ad
--- /dev/null
+++ b/qtmips_gui/coreview/alu.cpp
@@ -0,0 +1,62 @@
+#include "alu.h"
+
+//////////////////////
+#define WIDTH 40
+#define HEIGHT 120
+#define DENT 10
+#define PENW 1
+//////////////////////
+
+coreview::Alu::Alu() : QGraphicsObject(nullptr), name(this) {
+ name.setText("ALU");
+ name.setPos(3, 25);
+
+ con_in_a = new Connector();
+ con_in_b = new Connector();
+ con_out = new Connector();
+ con_ctl = new Connector();
+
+ setPos(x(), y()); // set connector's position
+}
+
+QRectF coreview::Alu::boundingRect() const {
+ return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW);
+}
+
+void coreview::Alu::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+ 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 coreview::Alu::setPos(qreal x, qreal y) {
+ QGraphicsObject::setPos(x, y);
+ qreal off = ((HEIGHT/2) - DENT) / 2;
+ con_in_a->setPos(0, off);
+ con_in_b->setPos(0, HEIGHT - off);
+ con_out->setPos(WIDTH, HEIGHT/2);
+ con_ctl->setPos(WIDTH/2, HEIGHT - (WIDTH/2));
+}
+
+const coreview::Connector *coreview::Alu::connector_in_a() const {
+ return con_in_a;
+}
+
+const coreview::Connector *coreview::Alu::connector_in_b() const {
+ return con_in_b;
+}
+
+const coreview::Connector *coreview::Alu::connector_out() const {
+ return con_out;
+}
+
+const coreview::Connector *coreview::Alu::connector_ctl() const {
+ return con_ctl;
+}
diff --git a/qtmips_gui/coreview/alu.h b/qtmips_gui/coreview/alu.h
new file mode 100644
index 0000000..4c9a73b
--- /dev/null
+++ b/qtmips_gui/coreview/alu.h
@@ -0,0 +1,37 @@
+#ifndef COREVIEW_ALU_H
+#define COREVIEW_ALU_H
+
+#include <QGraphicsObject>
+#include <qtmipsmachine.h>
+#include "../coreview.h"
+#include "connection.h"
+
+namespace coreview {
+
+class Alu : public QGraphicsObject {
+public:
+ Alu();
+
+ 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;
+ const Connector *connector_ctl() const;
+
+private:
+ QGraphicsSimpleTextItem name;
+ Connector *con_in_a, *con_in_b, *con_out, *con_ctl;
+};
+
+}
+
+#else
+
+namespace coreview {
+ class Alu;
+}
+
+#endif // COREVIEW_ALU_H
diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro
index 969450e..66d9189 100644
--- a/qtmips_gui/qtmips_gui.pro
+++ b/qtmips_gui/qtmips_gui.pro
@@ -23,7 +23,8 @@ SOURCES += \
coreview/programcounter.cpp \
coreview/multiplexer.cpp \
coreview/connection.cpp \
- coreview/latch.cpp
+ coreview/latch.cpp \
+ coreview/alu.cpp
HEADERS += \
mainwindow.h \
@@ -35,13 +36,15 @@ HEADERS += \
coreview/programcounter.h \
coreview/multiplexer.h \
coreview/connection.h \
- coreview/latch.h
+ coreview/latch.h \
+ coreview/alu.h
FORMS += \
NewDialog.ui \
MainWindow.ui \
CacheContent.ui \
- CacheStatistics.ui
+ CacheStatistics.ui \
+ programmemory.ui
RESOURCES += \
icons.qrc