diff options
-rw-r--r-- | qtmips_gui/MainWindow.ui | 6 | ||||
-rw-r--r-- | qtmips_gui/lcddisplaydock.cpp | 57 | ||||
-rw-r--r-- | qtmips_gui/lcddisplaydock.h | 57 | ||||
-rw-r--r-- | qtmips_gui/lcddisplayview.cpp | 52 | ||||
-rw-r--r-- | qtmips_gui/lcddisplayview.h | 31 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 6 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.h | 3 | ||||
-rw-r--r-- | qtmips_gui/qtmips_gui.pro | 4 | ||||
-rw-r--r-- | qtmips_machine/lcddisplay.cpp | 145 | ||||
-rw-r--r-- | qtmips_machine/lcddisplay.h | 83 | ||||
-rw-r--r-- | qtmips_machine/qtmips_machine.pro | 2 | ||||
-rw-r--r-- | qtmips_machine/qtmipsmachine.cpp | 7 | ||||
-rw-r--r-- | qtmips_machine/qtmipsmachine.h | 3 |
13 files changed, 456 insertions, 0 deletions
diff --git a/qtmips_gui/MainWindow.ui b/qtmips_gui/MainWindow.ui index 753460b..13d02fc 100644 --- a/qtmips_gui/MainWindow.ui +++ b/qtmips_gui/MainWindow.ui @@ -75,6 +75,7 @@ <addaction name="actionData_Cache"/> <addaction name="actionPeripherals"/> <addaction name="actionTerminal"/> + <addaction name="actionLcdDisplay"/> <addaction name="actionCop0State"/> </widget> <widget class="QMenu" name="menuMachine"> @@ -396,6 +397,11 @@ <string>Terminal</string> </property> </action> + <action name="actionLcdDisplay"> + <property name="text"> + <string>LCD display</string> + </property> + </action> <action name="actionShow_Symbol"> <property name="text"> <string>Show Symbol</string> diff --git a/qtmips_gui/lcddisplaydock.cpp b/qtmips_gui/lcddisplaydock.cpp new file mode 100644 index 0000000..6517f4a --- /dev/null +++ b/qtmips_gui/lcddisplaydock.cpp @@ -0,0 +1,57 @@ +// 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<cynerd@email.cz> + * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz> + * + * 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 <QString> +#include <QTextBlock> +#include <QTextCursor> + +#include "lcddisplaydock.h" +#include "lcddisplayview.h" + +LcdDisplayDock::LcdDisplayDock(QWidget *parent, QSettings *settings) : QDockWidget(parent) { + lcd_display_widget = new LcdDisplayView(this); + setWidget(lcd_display_widget); + + setObjectName("LCD Display"); + setWindowTitle("LCD Display"); +} + +LcdDisplayDock::~LcdDisplayDock() { + delete lcd_display_widget; +} + +void LcdDisplayDock::setup(machine::LcdDisplay *lcd_display) { + lcd_display_widget->setup(lcd_display); +} diff --git a/qtmips_gui/lcddisplaydock.h b/qtmips_gui/lcddisplaydock.h new file mode 100644 index 0000000..9a4f866 --- /dev/null +++ b/qtmips_gui/lcddisplaydock.h @@ -0,0 +1,57 @@ +// 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<cynerd@email.cz> + * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz> + * + * 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 LCDDISPLAYDOCK_H +#define LCDDISPLAYDOCK_H + +#include <QDockWidget> +#include "lcddisplayview.h" +#include "qtmipsmachine.h" + +class LcdDisplayDock : public QDockWidget { + Q_OBJECT +public: + LcdDisplayDock(QWidget *parent, QSettings *settings); + ~LcdDisplayDock(); + + void setup(machine::LcdDisplay *lcd_display); + +//public slots: + +private: + LcdDisplayView *lcd_display_widget; +}; + +#endif // LCDDISPLAYDOCK_H diff --git a/qtmips_gui/lcddisplayview.cpp b/qtmips_gui/lcddisplayview.cpp new file mode 100644 index 0000000..450e7d4 --- /dev/null +++ b/qtmips_gui/lcddisplayview.cpp @@ -0,0 +1,52 @@ +#include <QPainter> +#include <QStyle> +#include "lcddisplay.h" +#include "lcddisplayview.h" + +LcdDisplayView::LcdDisplayView(QWidget *parent) : Super(parent) { + setMinimumSize(100, 100); + fb_pixels = nullptr; +} + +LcdDisplayView::~LcdDisplayView() { + if (fb_pixels != nullptr) + delete fb_pixels; +} + +void LcdDisplayView::setup(machine::LcdDisplay *lcd_display) { + if (lcd_display == nullptr) + return; + connect(lcd_display, SIGNAL(pixel_update(uint,uint,uint,uint,uint)), + this, SLOT(pixel_update(uint,uint,uint,uint,uint))); + if (fb_pixels != nullptr) + delete fb_pixels; + fb_pixels = nullptr; + fb_pixels = new QImage(lcd_display->height(), + lcd_display->width(), QImage::Format_RGB32); + fb_pixels->fill(qRgb(0, 0, 0)); + update(); +} + +void LcdDisplayView::pixel_update(uint x, uint y, uint r, uint g, uint b) { + if (fb_pixels != nullptr) { + fb_pixels->setPixel(x, y, qRgb(r, g, b)); + update(); + } +} + +void LcdDisplayView::paintEvent(QPaintEvent *event) { + if (fb_pixels == nullptr) + return Super::paintEvent(event); + if (fb_pixels->width() == 0) + return Super::paintEvent(event); + + QPainter painter(this); + QSize widgetSize = rect().size(); + const auto newHeight = widgetSize.width() * fb_pixels->height() / fb_pixels->width(); + if(newHeight <= widgetSize.height()) + widgetSize.setHeight(newHeight); + else + widgetSize.setWidth(widgetSize.height() * fb_pixels->width() / fb_pixels->height()); + painter.drawImage(rect(), fb_pixels->scaled(widgetSize)); +} + diff --git a/qtmips_gui/lcddisplayview.h b/qtmips_gui/lcddisplayview.h new file mode 100644 index 0000000..010a106 --- /dev/null +++ b/qtmips_gui/lcddisplayview.h @@ -0,0 +1,31 @@ +#ifndef LCDDISPLAYVIEW_H +#define LCDDISPLAYVIEW_H + +#include <QWidget> +#include <QImage> + +#include "lcddisplay.h" + +class LcdDisplayView : public QWidget +{ + Q_OBJECT + + using Super = QWidget; + +public: + explicit LcdDisplayView(QWidget *parent = 0); + ~LcdDisplayView(); + + void setup(machine::LcdDisplay *lcd_display); + +public slots: + void pixel_update(uint x, uint y, uint r, uint g, uint b); + +protected: + virtual void paintEvent(QPaintEvent *event) override; + +private: + QImage *fb_pixels; +}; + +#endif // LCDDISPLAYVIEW_H diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index cdf943d..4b2b7fd 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -74,6 +74,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { peripherals->hide(); terminal = new TerminalDock(this, settings); terminal->hide(); + lcd_display = new LcdDisplayDock(this, settings); + lcd_display->hide(); cop0dock = new Cop0Dock(this); cop0dock->hide(); @@ -100,6 +102,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { 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->actionLcdDisplay, SIGNAL(triggered(bool)), this, SLOT(show_lcd_display())); connect(ui->actionCop0State, SIGNAL(triggered(bool)), this, SLOT(show_cop0dock())); connect(ui->actionAbout, SIGNAL(triggered(bool)), this, SLOT(about_qtmips())); connect(ui->actionAboutQt, SIGNAL(triggered(bool)), this, SLOT(about_qt())); @@ -128,6 +131,7 @@ MainWindow::~MainWindow() { delete cache_data; delete peripherals; delete terminal; + delete lcd_display; delete ui; if (machine != nullptr) delete machine; @@ -211,6 +215,7 @@ void MainWindow::create_core(const machine::MachineConfig &config, bool load_exe cache_data->setup(machine->cache_data()); terminal->setup(machine->serial_port()); peripherals->setup(machine->peripheral_spi_led()); + lcd_display->setup(machine->peripheral_lcd_display()); cop0dock->setup(machine); // Connect signals for instruction address followup @@ -293,6 +298,7 @@ SHOW_HANDLER(cache_program, Qt::RightDockWidgetArea) SHOW_HANDLER(cache_data, Qt::RightDockWidgetArea) SHOW_HANDLER(peripherals, Qt::RightDockWidgetArea) SHOW_HANDLER(terminal, Qt::RightDockWidgetArea) +SHOW_HANDLER(lcd_display, Qt::RightDockWidgetArea) SHOW_HANDLER(cop0dock, Qt::RightDockWidgetArea) #undef SHOW_HANDLER diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index 1ee8032..788c118 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -47,6 +47,7 @@ #include "cachedock.h" #include "peripheralsdock.h" #include "terminaldock.h" +#include "lcddisplaydock.h" #include "cop0dock.h" #include "qtmipsmachine.h" @@ -76,6 +77,7 @@ public slots: void show_cache_program(); void show_peripherals(); void show_terminal(); + void show_lcd_display(); void show_cop0dock(); void show_symbol_dialog(); // Actions - help menu @@ -105,6 +107,7 @@ private: CacheDock *cache_program, *cache_data; PeripheralsDock *peripherals; TerminalDock *terminal; + LcdDisplayDock *lcd_display; Cop0Dock *cop0dock; diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro index 4c52596..5bedaa1 100644 --- a/qtmips_gui/qtmips_gui.pro +++ b/qtmips_gui/qtmips_gui.pro @@ -65,6 +65,8 @@ SOURCES += \ peripheralsdock.cpp \ terminaldock.cpp \ peripheralsview.cpp \ + lcddisplaydock.cpp \ + lcddisplayview.cpp \ coreview/multitext.cpp \ fontsize.cpp \ gotosymboldialog.cpp \ @@ -106,6 +108,8 @@ HEADERS += \ peripheralsdock.h \ terminaldock.h \ peripheralsview.h \ + lcddisplaydock.h \ + lcddisplayview.h \ coreview/multitext.h \ fontsize.h \ gotosymboldialog.h \ diff --git a/qtmips_machine/lcddisplay.cpp b/qtmips_machine/lcddisplay.cpp new file mode 100644 index 0000000..1d96b9d --- /dev/null +++ b/qtmips_machine/lcddisplay.cpp @@ -0,0 +1,145 @@ +// 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<cynerd@email.cz> + * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz> + * + * 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 "lcddisplay.h" + +using namespace machine; + +LcdDisplay::LcdDisplay() { + size_t need_bytes; + fb_size = 0x4b000; + fb_bpp = 16; + fb_width = 480; + fb_height = 320; + if (fb_bpp > 12) { + fb_linesize = ((fb_bpp + 7) >> 3) * fb_width; + } else { + fb_linesize = (fb_bpp * fb_width + 7) >> 3; + } + need_bytes = fb_linesize * fb_height; + + if (fb_size <= need_bytes) + fb_size = need_bytes; + + fb_data = new uchar[fb_size]; + std::fill(fb_data, fb_data + fb_size, 0); +} + +LcdDisplay::~LcdDisplay() { + if (fb_data != nullptr) + delete[] fb_data; +} + +std::uint32_t LcdDisplay::pixel_address(uint x, uint y) +{ + std::uint32_t address; + address = y * fb_linesize; + if (fb_bpp > 12) + address += x * ((fb_bpp + 7) >> 3); + else + address += x * fb_bpp / 8; + + return address; +} + + +bool LcdDisplay::wword(std::uint32_t address, std::uint32_t value) { + address &= ~3; + uint x, y, r, g, b; + std::uint32_t c; + std::uint32_t last_addr = address + 3; + std::uint32_t pixel_addr; + + if (address + 3 >= fb_size) + return 0; +#if 0 + printf("LcdDisplay::wword address 0x%08lx data 0x%08lx\n", + (unsigned long)address, (unsigned long)value); +#endif + + fb_data[address + 0] = (value >> 24) & 0xff; + fb_data[address + 1] = (value >> 16) & 0xff; + fb_data[address + 2] = (value >> 8) & 0xff; + fb_data[address + 3] = (value >> 0) & 0xff; + + y = address / fb_linesize; + if (fb_bpp > 12) + x = (address - y * fb_linesize) / ((fb_bpp + 7) >> 3); + else + x = (address - y * fb_linesize) * 8 / fb_bpp; + + while ((pixel_addr = pixel_address(x, y)) <= last_addr) { + c = fb_data[pixel_addr] << 8; + c |= fb_data[pixel_addr + 1]; + + r = ((c >> 11) & 0x1f) << 3; + g = ((c >> 5) & 0x3f) << 2; + b = ((c >> 0) & 0x1f) << 3; + + emit pixel_update(x, y, r, g, b); + + if (++x >= fb_width) { + x = 0; + y++; + } + } + + emit write_notification(address, value); + + return true; +} + +std::uint32_t LcdDisplay::rword(std::uint32_t address, bool debug_access) const { + address &= ~3; + (void)debug_access; + std::uint32_t value; + + if (address + 3 >= fb_size) + return 0; + + value = (std::uint32_t)fb_data[address + 0] << 24; + value |= (std::uint32_t)fb_data[address + 1] << 16; + value |= (std::uint32_t)fb_data[address + 2] << 8; + value |= (std::uint32_t)fb_data[address + 3] << 0; + +#if 0 + printf("LcdDisplay::rword address 0x%08lx data 0x%08lx\n", + (unsigned long)address, (unsigned long)value); +#endif + + emit read_notification(address, &value); + + return value; +} diff --git a/qtmips_machine/lcddisplay.h b/qtmips_machine/lcddisplay.h new file mode 100644 index 0000000..15a1e80 --- /dev/null +++ b/qtmips_machine/lcddisplay.h @@ -0,0 +1,83 @@ +// 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<cynerd@email.cz> + * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz> + * + * 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 LCDDISPLAY_H +#define LCDDISPLAY_H + +#include <QObject> +#include <QMap> +#include <cstdint> +#include <qtmipsexception.h> +#include "machinedefs.h" +#include "memory.h" + +namespace machine { + +class LcdDisplay : public MemoryAccess { + Q_OBJECT +public: + LcdDisplay(); + ~LcdDisplay(); + +signals: + void write_notification(std::uint32_t address, std::uint32_t value); + void read_notification(std::uint32_t address, std::uint32_t *value) const; + void pixel_update(uint x, uint y, uint r, uint g, uint b); + +public: + bool wword(std::uint32_t address, std::uint32_t value); + std::uint32_t rword(std::uint32_t address, bool debug_access = false) const; + + inline uint width() { + return fb_width; + } + + inline uint height() { + return fb_height; + } + +private: + std::uint32_t pixel_address(uint x, uint y); + uchar *fb_data; + size_t fb_size; + unsigned fb_bpp; + unsigned fb_width; + unsigned fb_height; + unsigned fb_linesize; +}; + +} + +#endif // LCDDISPLAY_H diff --git a/qtmips_machine/qtmips_machine.pro b/qtmips_machine/qtmips_machine.pro index 7223bcd..e138fef 100644 --- a/qtmips_machine/qtmips_machine.pro +++ b/qtmips_machine/qtmips_machine.pro @@ -29,6 +29,7 @@ SOURCES += \ peripheral.cpp \ serialport.cpp \ peripspiled.cpp \ + lcddisplay.cpp \ symboltable.cpp \ cop0state.cpp @@ -49,5 +50,6 @@ HEADERS += \ peripheral.h \ serialport.h \ peripspiled.h \ + lcddisplay.h \ symboltable.h \ cop0state.h diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp index 362b243..982e581 100644 --- a/qtmips_machine/qtmipsmachine.cpp +++ b/qtmips_machine/qtmipsmachine.cpp @@ -75,6 +75,9 @@ QtMipsMachine::QtMipsMachine(const MachineConfig &cc, bool load_symtab, bool loa perip_spi_led = new PeripSpiLed(); addressapce_insert_range(perip_spi_led, 0xffffc100, 0xffffc1ff, true); + perip_lcd_display = new LcdDisplay(); + addressapce_insert_range(perip_lcd_display, 0xffe00000, 0xffe4afff, true); + cch_program = new Cache(cpu_mem, &cc.cache_program(), cc.memory_access_time_read(), cc.memory_access_time_write(), cc.memory_access_time_burst()); cch_data = new Cache(cpu_mem, &cc.cache_data(), cc.memory_access_time_read(), @@ -191,6 +194,10 @@ PeripSpiLed *QtMipsMachine::peripheral_spi_led() { return perip_spi_led; } +LcdDisplay *QtMipsMachine::peripheral_lcd_display() { + return perip_lcd_display; +} + const SymbolTable *QtMipsMachine::symbol_table() { return symtab; } diff --git a/qtmips_machine/qtmipsmachine.h b/qtmips_machine/qtmipsmachine.h index 6c0c007..0d9875a 100644 --- a/qtmips_machine/qtmipsmachine.h +++ b/qtmips_machine/qtmipsmachine.h @@ -49,6 +49,7 @@ #include <peripheral.h> #include <serialport.h> #include <peripspiled.h> +#include <lcddisplay.h> #include <symboltable.h> namespace machine { @@ -71,6 +72,7 @@ public: Cache *cache_data_rw(); SerialPort *serial_port(); PeripSpiLed *peripheral_spi_led(); + LcdDisplay *peripheral_lcd_display(); const SymbolTable *symbol_table(); const Core *core(); const CoreSingle *core_singe(); @@ -126,6 +128,7 @@ private: PhysAddrSpace *physaddrspace; SerialPort *ser_port; PeripSpiLed *perip_spi_led; + LcdDisplay *perip_lcd_display; Cache *cch_program, *cch_data; Cop0State *cop0st; Core *cr; |