aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/lcddisplay.cpp145
-rw-r--r--qtmips_machine/lcddisplay.h83
-rw-r--r--qtmips_machine/qtmips_machine.pro2
-rw-r--r--qtmips_machine/qtmipsmachine.cpp7
-rw-r--r--qtmips_machine/qtmipsmachine.h3
5 files changed, 240 insertions, 0 deletions
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;