From 93c5ade08250e419b7dbc3177db6fba93163fd34 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Wed, 13 Feb 2019 18:37:51 +0100 Subject: Include simple serial port terminal and prepare empty peripheral dock. Signed-off-by: Pavel Pisa --- qtmips_gui/coreview.cpp | 4 +++ qtmips_gui/coreview.h | 4 +++ qtmips_gui/coreview/logicblock.cpp | 9 +++-- qtmips_gui/coreview/logicblock.h | 12 +++++-- qtmips_gui/mainwindow.cpp | 13 +++++++ qtmips_gui/mainwindow.h | 6 ++++ qtmips_gui/peripheralsdock.cpp | 49 ++++++++++++++++++++++++++ qtmips_gui/peripheralsdock.h | 58 ++++++++++++++++++++++++++++++ qtmips_gui/qtmips_gui.pro | 8 +++-- qtmips_gui/terminaldock.cpp | 72 ++++++++++++++++++++++++++++++++++++++ qtmips_gui/terminaldock.h | 65 ++++++++++++++++++++++++++++++++++ 11 files changed, 294 insertions(+), 6 deletions(-) create mode 100644 qtmips_gui/peripheralsdock.cpp create mode 100644 qtmips_gui/peripheralsdock.h create mode 100644 qtmips_gui/terminaldock.cpp create mode 100644 qtmips_gui/terminaldock.h (limited to 'qtmips_gui') diff --git a/qtmips_gui/coreview.cpp b/qtmips_gui/coreview.cpp index 749bdcf..63f9ea6 100644 --- a/qtmips_gui/coreview.cpp +++ b/qtmips_gui/coreview.cpp @@ -69,6 +69,8 @@ CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene() NEW(DataMemory, mem_data, 580, 258, machine); NEW(Registers, regs, 230, 240); NEW(Alu, alu, 490, 233); + NEW(LogicBlock, peripherals, 610, 350, "Peripherals"); + NEW(LogicBlock, terminal, 610, 400, "Terminal"); // Fetch stage NEW(ProgramCounter, ft.pc, 2, 280, machine); NEW(Latch, ft.latch, 55, 250, machine, 20); @@ -195,6 +197,8 @@ CoreViewScene::CoreViewScene(machine::QtMipsMachine *machine) : QGraphicsScene() connect(ft.pc, SIGNAL(jump_to_pc(std::uint32_t)), this, SIGNAL(request_jump_to_program_counter(std::uint32_t))); connect(mem_program, SIGNAL(open_cache()), this, SIGNAL(request_cache_program())); connect(mem_data, SIGNAL(open_cache()), this, SIGNAL(request_cache_data())); + connect(peripherals, SIGNAL(open_block()), this, SIGNAL(request_peripherals())); + connect(terminal, SIGNAL(open_block()), this, SIGNAL(request_terminal())); } CoreViewScene::~CoreViewScene() { diff --git a/qtmips_gui/coreview.h b/qtmips_gui/coreview.h index a253e32..4852e25 100644 --- a/qtmips_gui/coreview.h +++ b/qtmips_gui/coreview.h @@ -68,12 +68,16 @@ signals: void request_jump_to_program_counter(std::uint32_t addr); void request_cache_program(); void request_cache_data(); + void request_peripherals(); + void request_terminal(); protected: coreview::ProgramMemory *mem_program; coreview::DataMemory *mem_data; coreview::Registers *regs; coreview::Alu *alu; + coreview::LogicBlock *peripherals; + coreview::LogicBlock *terminal; struct { coreview::ProgramCounter *pc; coreview::Latch *latch; diff --git a/qtmips_gui/coreview/logicblock.cpp b/qtmips_gui/coreview/logicblock.cpp index 2aabe7f..e2c5e24 100644 --- a/qtmips_gui/coreview/logicblock.cpp +++ b/qtmips_gui/coreview/logicblock.cpp @@ -47,7 +47,7 @@ using namespace coreview; LogicBlock::LogicBlock(QString name) : LogicBlock(QVector({name})) { } -LogicBlock::LogicBlock(QVector name) : QGraphicsItem(nullptr) { +LogicBlock::LogicBlock(QVector name) : QGraphicsObject(nullptr) { QFont font; font.setPointSize(7); @@ -82,7 +82,7 @@ void LogicBlock::paint(QPainter *painter, const QStyleOptionGraphicsItem *option } void LogicBlock::setPos(qreal x, qreal y) { - QGraphicsItem::setPos(x, y); + QGraphicsObject::setPos(x, y); for (int i = 0; i < connectors.size(); i++) { struct Con &c = connectors[i]; c.con->setPos(x + c.p.x(), y + c.p.y()); @@ -134,3 +134,8 @@ QPointF LogicBlock::con_pos(qreal x, qreal y) { py += GAP * sign(y); return QPointF(px, py); } + +void LogicBlock::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { + QGraphicsObject::mouseDoubleClickEvent(event); + emit open_block(); +} diff --git a/qtmips_gui/coreview/logicblock.h b/qtmips_gui/coreview/logicblock.h index 27c2951..a384b06 100644 --- a/qtmips_gui/coreview/logicblock.h +++ b/qtmips_gui/coreview/logicblock.h @@ -36,15 +36,17 @@ #ifndef LOGICBLOCK_H #define LOGICBLOCK_H -#include +#include #include #include #include +#include #include "connection.h" namespace coreview { -class LogicBlock : public QGraphicsItem { +class LogicBlock : public QGraphicsObject { + Q_OBJECT public: LogicBlock(QString name); LogicBlock(QVector name); @@ -61,6 +63,9 @@ public: // Using x=y and x=-y coordinates is not supported const Connector *new_connector(qreal x, qreal y); +signals: + void open_block(); + private: QVector text; QRectF box; @@ -72,6 +77,9 @@ private: }; QVector connectors; QPointF con_pos(qreal x, qreal y); + +protected: + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); }; } diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index 4e716cb..b77d0d6 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -60,6 +60,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { cache_program->hide(); cache_data = new CacheDock(this, "Data"); cache_data->hide(); + peripherals = new PeripheralsDock(this, settings); + peripherals->hide(); + terminal = new TerminalDock(this, settings); + terminal->hide(); // Execution speed actions speed_group = new QActionGroup(this); @@ -80,6 +84,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { connect(ui->actionMemory, SIGNAL(triggered(bool)), this, SLOT(show_memory())); connect(ui->actionProgram_Cache, SIGNAL(triggered(bool)), this, SLOT(show_cache_program())); connect(ui->actionData_Cache, SIGNAL(triggered(bool)), this, SLOT(show_cache_data())); + connect(ui->actionPeripherals, SIGNAL(triggered(bool)), this, SLOT(show_peripherals())); + connect(ui->actionTerminal, SIGNAL(triggered(bool)), this, SLOT(show_terminal())); connect(ui->actionAbout, SIGNAL(triggered(bool)), this, SLOT(about_qtmips())); connect(ui->actionAboutQt, SIGNAL(triggered(bool)), this, SLOT(about_qt())); connect(ui->ips1, SIGNAL(toggled(bool)), this, SLOT(set_speed())); @@ -105,6 +111,8 @@ MainWindow::~MainWindow() { delete memory; delete cache_program; delete cache_data; + delete peripherals; + delete terminal; delete ui; if (machine != nullptr) delete machine; @@ -153,6 +161,8 @@ void MainWindow::create_core(const machine::MachineConfig &config) { connect(corescene, SIGNAL(request_jump_to_program_counter(std::uint32_t)), program, SIGNAL(jump_to_pc(std::uint32_t))); connect(corescene, SIGNAL(request_cache_program()), this, SLOT(show_cache_program())); connect(corescene, SIGNAL(request_cache_data()), this, SLOT(show_cache_data())); + connect(corescene, SIGNAL(request_peripherals()), this, SLOT(show_peripherals())); + connect(corescene, SIGNAL(request_terminal()), this, SLOT(show_terminal())); // Connect signal from break to machine pause connect(machine->core(), SIGNAL(stop_on_exception_reached()), machine, SLOT(pause())); @@ -163,6 +173,7 @@ void MainWindow::create_core(const machine::MachineConfig &config) { memory->setup(machine); cache_program->setup(machine->cache_program()); cache_data->setup(machine->cache_data()); + terminal->setup(machine->serial_port()); // Connect signals for instruction address followup connect(machine->core(), SIGNAL(fetch_inst_addr_value(std::uint32_t)), @@ -211,6 +222,8 @@ SHOW_HANDLER(program) SHOW_HANDLER(memory) SHOW_HANDLER(cache_program) SHOW_HANDLER(cache_data) +SHOW_HANDLER(peripherals) +SHOW_HANDLER(terminal) #undef SHOW_HANDLER void MainWindow::about_qtmips() diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index 48883e5..61e6896 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -45,6 +45,8 @@ #include "programdock.h" #include "memorydock.h" #include "cachedock.h" +#include "peripheralsdock.h" +#include "terminaldock.h" #include "qtmipsmachine.h" #include "machineconfig.h" @@ -70,6 +72,8 @@ public slots: void show_memory(); void show_cache_data(); void show_cache_program(); + void show_peripherals(); + void show_terminal(); // Actions - help menu void about_qtmips(); void about_qt(); @@ -95,6 +99,8 @@ private: ProgramDock *program; MemoryDock *memory; CacheDock *cache_program, *cache_data; + PeripheralsDock *peripherals; + TerminalDock *terminal; QActionGroup *speed_group; diff --git a/qtmips_gui/peripheralsdock.cpp b/qtmips_gui/peripheralsdock.cpp new file mode 100644 index 0000000..ad423a0 --- /dev/null +++ b/qtmips_gui/peripheralsdock.cpp @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0+ +/******************************************************************************* + * QtMips - MIPS 32-bit Architecture Subset Simulator + * + * Implemented to support following courses: + * + * B35APO - Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b35apo + * + * B4M35PAP - Advanced Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start + * + * Copyright (c) 2017-2019 Karel Koci + * Copyright (c) 2019 Pavel Pisa + * + * Faculty of Electrical Engineering (http://www.fel.cvut.cz) + * Czech Technical University (http://www.cvut.cz/) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + ******************************************************************************/ + +#include "peripheralsdock.h" + +PeripheralsDock::PeripheralsDock(QWidget *parent, QSettings *settings) : QDockWidget(parent) { + top_widget = new QWidget(this); + setWidget(top_widget); + layout_box = new QVBoxLayout(top_widget); + + setObjectName("Peripherals"); + setWindowTitle("Peripherals"); +} + +void PeripheralsDock::setup(const machine::QtMipsMachine *machine) { + +} diff --git a/qtmips_gui/peripheralsdock.h b/qtmips_gui/peripheralsdock.h new file mode 100644 index 0000000..b611515 --- /dev/null +++ b/qtmips_gui/peripheralsdock.h @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0+ +/******************************************************************************* + * QtMips - MIPS 32-bit Architecture Subset Simulator + * + * Implemented to support following courses: + * + * B35APO - Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b35apo + * + * B4M35PAP - Advanced Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start + * + * Copyright (c) 2017-2019 Karel Koci + * Copyright (c) 2019 Pavel Pisa + * + * Faculty of Electrical Engineering (http://www.fel.cvut.cz) + * Czech Technical University (http://www.cvut.cz/) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + ******************************************************************************/ + +#ifndef PERIPHERALSDOCK_H +#define PERIPHERALSDOCK_H + +#include +#include +#include +#include "peripheral.h" +#include "qtmipsmachine.h" + +class PeripheralsDock : public QDockWidget { + Q_OBJECT +public: + PeripheralsDock(QWidget *parent, QSettings *settings); + + void setup(const machine::QtMipsMachine *machine); + +private: + QVBoxLayout *layout_box; + QWidget *top_widget, *top_form; + QFormLayout *layout_top_form; +}; + +#endif // PERIPHERALSDOCK_H diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro index 8822e38..fa1cbc6 100644 --- a/qtmips_gui/qtmips_gui.pro +++ b/qtmips_gui/qtmips_gui.pro @@ -51,7 +51,9 @@ SOURCES += \ hexlineedit.cpp \ programmodel.cpp \ programtableview.cpp \ - aboutdialog.cpp + aboutdialog.cpp \ + peripheralsdock.cpp \ + terminaldock.cpp HEADERS += \ mainwindow.h \ @@ -83,7 +85,9 @@ HEADERS += \ hexlineedit.h \ programmodel.h \ programtableview.h \ - aboutdialog.h + aboutdialog.h \ + peripheralsdock.h \ + terminaldock.h FORMS += \ NewDialog.ui \ diff --git a/qtmips_gui/terminaldock.cpp b/qtmips_gui/terminaldock.cpp new file mode 100644 index 0000000..31e8c68 --- /dev/null +++ b/qtmips_gui/terminaldock.cpp @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0+ +/******************************************************************************* + * QtMips - MIPS 32-bit Architecture Subset Simulator + * + * Implemented to support following courses: + * + * B35APO - Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b35apo + * + * B4M35PAP - Advanced Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start + * + * Copyright (c) 2017-2019 Karel Koci + * Copyright (c) 2019 Pavel Pisa + * + * Faculty of Electrical Engineering (http://www.fel.cvut.cz) + * Czech Technical University (http://www.cvut.cz/) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + ******************************************************************************/ + +#include +#include +#include + +#include "serialport.h" +#include "terminaldock.h" + +TerminalDock::TerminalDock(QWidget *parent, QSettings *settings) : QDockWidget(parent) { + top_widget = new QWidget(this); + setWidget(top_widget); + layout_box = new QVBoxLayout(top_widget); + + terminal_text = new QTextEdit(top_widget); + terminal_text->setMinimumSize(30, 30); + layout_box->addWidget(terminal_text); + append_cursor = new QTextCursor(terminal_text->document()); + + setObjectName("Terminal"); + setWindowTitle("Terminal"); +} + +TerminalDock::~TerminalDock() { + delete append_cursor; +} + +void TerminalDock::setup(const machine::SerialPort *ser_port) { + if (ser_port == nullptr) + return; + connect(ser_port, SIGNAL(tx_byte(uint)), this, SLOT(tx_byte(uint))); +} + +void TerminalDock::tx_byte(unsigned int data) { + if (data == '\n') + append_cursor->insertBlock(); + else + append_cursor->insertText(QString(QChar(data))); +} diff --git a/qtmips_gui/terminaldock.h b/qtmips_gui/terminaldock.h new file mode 100644 index 0000000..b0c76cf --- /dev/null +++ b/qtmips_gui/terminaldock.h @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0+ +/******************************************************************************* + * QtMips - MIPS 32-bit Architecture Subset Simulator + * + * Implemented to support following courses: + * + * B35APO - Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b35apo + * + * B4M35PAP - Advanced Computer Architectures + * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start + * + * Copyright (c) 2017-2019 Karel Koci + * Copyright (c) 2019 Pavel Pisa + * + * Faculty of Electrical Engineering (http://www.fel.cvut.cz) + * Czech Technical University (http://www.cvut.cz/) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + ******************************************************************************/ + +#ifndef TERMINALDOCK_H +#define TERMINALDOCK_H + +#include +#include +#include +#include +#include +#include "qtmipsmachine.h" + +class TerminalDock : public QDockWidget { + Q_OBJECT +public: + TerminalDock(QWidget *parent, QSettings *settings); + ~TerminalDock(); + + void setup(const machine::SerialPort *ser_port); + +public slots: + void tx_byte(unsigned int data); + +private: + QVBoxLayout *layout_box; + QWidget *top_widget, *top_form; + QFormLayout *layout_top_form; + QTextEdit *terminal_text; + QTextCursor *append_cursor; +}; + +#endif // TERMINALDOCK_H -- cgit v1.2.3