From 506174a8266eb9842ff9e50a89ddf86cb975be30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 8 Jan 2018 21:43:58 +0100 Subject: Add coreview progress --- qtmips_gui/coreview.cpp | 128 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 20 deletions(-) (limited to 'qtmips_gui/coreview.cpp') diff --git a/qtmips_gui/coreview.cpp b/qtmips_gui/coreview.cpp index f5d86d9..e845184 100644 --- a/qtmips_gui/coreview.cpp +++ b/qtmips_gui/coreview.cpp @@ -1,9 +1,18 @@ #include "coreview.h" +#include + +////////////////////////////////////////////////////////////////////////////// +/// Size of visible view area +#define SC_WIDTH 720 +#define SC_HEIGHT 540 +////////////////////////////////////////////////////////////////////////////// CoreView::CoreView(QWidget *parent) : QGraphicsView(parent) { setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); +} - setSceneRect(0, 0, scene_width, scene_height); +void CoreView::setScene(QGraphicsScene *scene) { + QGraphicsView::setScene(scene); update_scale(); } @@ -13,9 +22,12 @@ void CoreView::resizeEvent(QResizeEvent *event) { } void CoreView::update_scale() { + if (scene() == nullptr) + return; // Skip if we have no scene + // Note: there is somehow three pixels error when viewing so we have to always compensate - const int w = scene_width + 3; - const int h = scene_height + 3; + const int w = scene()->width() + 3; + const int h = scene()->height() + 3; qreal scale = 1; if (height() > h && width() > w) { @@ -31,31 +43,107 @@ void CoreView::update_scale() { } CoreViewScene::CoreViewScene(CoreView *view, machine::QtMipsMachine *machine) : QGraphicsScene(view) { - this->machine = machine; + setSceneRect(0, 0, SC_WIDTH, SC_HEIGHT); // Identification cross (TODO remove) QPen pen; pen.setBrush(QBrush(QColor(220, 220, 220))); - addLine(400, 0, 400, 800, pen); - addLine(0, 400, 800, 400, pen); - addRect(0.5, 0.5, 799.5, 799.5, pen); + addLine(width()/2, 0, width()/2, height(), pen); + addLine(0, height()/2, width(), height()/2, pen); + addRect(0.5, 0.5, width() - 0.5, height() - 0.5, pen); // TODO remove - pc = new coreview::ProgramCounter(machine); - alu = new coreview::Alu(); - pc_multiplexer = new coreview::Multiplexer(4); - testlatch = new coreview::Latch(machine, 300); +#define NEW(TYPE, VAR, ...) do { \ + VAR = new coreview::TYPE(__VA_ARGS__);\ + addItem(VAR);\ + } while(false) +#define NEW_CON(VAR, ...) NEW(Connection, VAR, __VA_ARGS__) - pc2pc = new coreview::Connection(pc_multiplexer->connector_out(), pc->connector_in()); + NEW(ProgramCounter, pc, machine); + NEW(Latch, pc_latch, machine, 20); + NEW(Adder, pc_adder); + NEW(Constant, pc_adder_4, pc_adder->connector_in_b(), "4"); + NEW(Junction, pc_junction); + NEW(Alu, alu); + NEW(Memory, mem, machine); + NEW(Registers, regs); + NEW(Multiplexer, pc_multiplexer, 4); + NEW(Multiplexer, mem_or_reg, 2); - addItem(pc); - addItem(alu); - addItem(pc_multiplexer); - addItem(testlatch); - addItem(pc2pc); + struct coreview::Latch::ConnectorPair pc_latch_pair = pc_latch->new_connector(10); + NEW_CON(pc2pc_latch, pc->connector_out(), pc_latch_pair.in); + NEW_CON(pc_latch2pc_joint, pc_latch_pair.out, pc_junction->new_connector(0)); + NEW_CON(pc_joint2pc_adder, pc_junction->new_connector(M_PI_2), pc_adder->connector_in_a()); + NEW_CON(pc_joint2mem, pc_junction->new_connector(-M_PI_2), mem->connector_pc()); + pc_joint2mem->setAxes({CON_AXIS_X(430)}); + NEW_CON(pc_multiplexer2pc, pc_multiplexer->connector_out(), pc->connector_in()); + pc_multiplexer2pc->setAxes({CON_AXIS_Y(90), CON_AXIS_X(80)}); - pc->setPos(100,100); - alu->setPos(200, 100); + pc->setPos(2, 330); + pc_latch->setPos(50, 370); + pc_adder->setPos(100, 350); + pc_junction->setPos(80, pc_latch_pair.out->y()); + alu->setPos(470, 230); + mem->setPos(20, 510); + regs->setPos(20, 0); pc_multiplexer->setPos(60, 100); - pc_multiplexer->set(2); + mem_or_reg->setPos(570, 180); + + connect(regs, SIGNAL(open_registers()), this, SIGNAL(request_registers())); + connect(mem, SIGNAL(open_data_mem()), this, SIGNAL(request_data_memory())); + connect(mem, SIGNAL(open_program_mem()), this, SIGNAL(request_program_memory())); +} + +CoreViewScene::~CoreViewScene() { + delete pc2pc_latch; + delete pc_latch2pc_joint; + delete pc_joint2pc_adder; + delete pc_joint2mem; + delete pc_multiplexer2pc; + + delete pc; + delete pc_latch; + delete pc_adder; + delete pc_adder_4; + delete pc_junction; + delete alu; + delete pc_multiplexer; +} + +CoreViewSceneSimple::CoreViewSceneSimple(CoreView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) { + delay_slot_latch = new coreview::Latch(machine, 150); + + addItem(delay_slot_latch); + + delay_slot_latch->setPos(160, 50); +} + +CoreViewSceneSimple::~CoreViewSceneSimple() { + +} + +CoreViewScenePipelined::CoreViewScenePipelined(CoreView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) { + latch_if_id = new coreview::Latch(machine, 350); + latch_id_ex = new coreview::Latch(machine, 350); + latch_ex_mem = new coreview::Latch(machine, 350); + latch_mem_wb = new coreview::Latch(machine, 350); + + latch_if_id->setTitle("IF/ID"); + latch_id_ex->setTitle("ID/EX"); + latch_ex_mem->setTitle("EX/MEM"); + latch_mem_wb->setTitle("MEM/WB"); + + addItem(latch_if_id); + addItem(latch_id_ex); + addItem(latch_ex_mem); + addItem(latch_mem_wb); + + latch_if_id->setPos(158, 90); + latch_id_ex->setPos(392, 90); + latch_ex_mem->setPos(536, 90); + latch_mem_wb->setPos(680, 90); +} + +CoreViewScenePipelined::~CoreViewScenePipelined() { + } -- cgit v1.2.3