aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qtmips_gui/MainWindow.ui6
-rw-r--r--qtmips_gui/mainwindow.cpp29
-rw-r--r--qtmips_gui/mainwindow.h1
-rw-r--r--qtmips_gui/qtmips_gui.pro9
-rw-r--r--qtmips_gui/samples.qrc8
-rw-r--r--qtmips_gui/samples/cop0-test-ia.S74
-rw-r--r--qtmips_gui/samples/simple-lw-sw-ia.S26
-rw-r--r--qtmips_gui/samples/template-os.S114
-rw-r--r--qtmips_gui/samples/template.S109
-rw-r--r--qtmips_gui/srceditor.cpp12
-rw-r--r--qtmips_gui/srceditor.h3
-rw-r--r--qtmips_gui/textsignalaction.cpp68
-rw-r--r--qtmips_gui/textsignalaction.h66
13 files changed, 517 insertions, 8 deletions
diff --git a/qtmips_gui/MainWindow.ui b/qtmips_gui/MainWindow.ui
index fde3041..87fd062 100644
--- a/qtmips_gui/MainWindow.ui
+++ b/qtmips_gui/MainWindow.ui
@@ -58,6 +58,11 @@
<property name="title">
<string>File</string>
</property>
+ <widget class="QMenu" name="menuExamples">
+ <property name="title">
+ <string>Examples</string>
+ </property>
+ </widget>
<addaction name="actionNewMachine"/>
<addaction name="actionReload"/>
<addaction name="actionPrint"/>
@@ -66,6 +71,7 @@
<addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
<addaction name="actionClose"/>
+ <addaction name="menuExamples"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp
index c78deb8..e84359f 100644
--- a/qtmips_gui/mainwindow.cpp
+++ b/qtmips_gui/mainwindow.cpp
@@ -53,6 +53,7 @@
#include "simpleasm.h"
#include "extprocess.h"
#include "savechangeddialog.h"
+#include "textsignalaction.h"
#ifdef __EMSCRIPTEN__
#include <QFileInfo>
@@ -169,6 +170,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
}
}
+ QDir samples_dir(":/samples");
+ for (QString fname: samples_dir.entryList(QDir::Files)) {
+ TextSignalAction *textsigac = new TextSignalAction(fname, ":/samples/" + fname);
+ ui->menuExamples->addAction(textsigac);
+ connect(textsigac, SIGNAL( activated(QString)), this, SLOT(example_source(QString)));
+ }
+
#ifdef __EMSCRIPTEN__
ui->actionBuildExe->setEnabled(false);
#endif
@@ -458,7 +466,7 @@ void MainWindow::save_exit_or_ignore(bool cancel, QStringList &tosavelist) {
return;
for (const auto &fname : tosavelist) {
SrcEditor *editor = source_editor_for_file(fname, false);
- if (fname.isEmpty()) {
+ if (editor->saveAsRequired()) {
save_unnamed = true;
} else if (editor != nullptr) {
editor->saveFile();
@@ -470,7 +478,7 @@ void MainWindow::save_exit_or_ignore(bool cancel, QStringList &tosavelist) {
SrcEditor *editor = dynamic_cast<SrcEditor *>(w);
if (editor == nullptr)
continue;
- if (!editor->filename().isEmpty())
+ if (!editor->saveAsRequired())
continue;
central_window->setCurrentWidget(editor);
save_source_as();
@@ -745,7 +753,7 @@ void MainWindow::src_editor_save_to(QString filename) {
void MainWindow::save_source() {
if (current_srceditor == nullptr)
return;
- if (current_srceditor->filename().isEmpty())
+ if (current_srceditor->saveAsRequired())
return save_source_as();
#ifndef __EMSCRIPTEN__
if (!current_srceditor->saveFile()) {
@@ -783,7 +791,7 @@ void MainWindow::close_source_decided(int result) {
return;
SrcEditor *editor = current_srceditor;
if (result == QMessageBox::Save) {
- if (editor->filename().isEmpty()) {
+ if (editor->saveAsRequired()) {
save_source_as();
return;
}
@@ -805,6 +813,19 @@ void MainWindow::close_source() {
update_open_file_list();
}
+void MainWindow::example_source(QString source_file) {
+ SrcEditor *editor = new SrcEditor();
+
+ if (editor->loadFile(source_file)) {
+ editor->setSaveAsRequired(true);
+ add_src_editor_to_tabs(editor);
+ update_open_file_list();
+ } else {
+ QMessageBox::critical(this, "QtMips Error", tr("Cannot open example file '%1' for reading.").arg(source_file));
+ delete(editor);
+ }
+}
+
void MainWindow::message_selected(messagetype::Type type, QString file, int line,
int column, QString text, QString hint) {
diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h
index ba2998e..51e154b 100644
--- a/qtmips_gui/mainwindow.h
+++ b/qtmips_gui/mainwindow.h
@@ -89,6 +89,7 @@ public slots:
void close_source();
void close_source_check();
void close_source_decided(int result);
+ void example_source(QString source_file);
void compile_source();
void build_execute();
void build_execute_no_check();
diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro
index 16cd5cf..1d376d6 100644
--- a/qtmips_gui/qtmips_gui.pro
+++ b/qtmips_gui/qtmips_gui.pro
@@ -82,7 +82,8 @@ SOURCES += \
messagesmodel.cpp \
messagesview.cpp \
extprocess.cpp \
- savechangeddialog.cpp
+ savechangeddialog.cpp \
+ textsignalaction.cpp
HEADERS += \
mainwindow.h \
@@ -133,7 +134,8 @@ HEADERS += \
messagesmodel.h \
messagesview.h \
extprocess.h \
- savechangeddialog.h
+ savechangeddialog.h \
+ textsignalaction.h
wasm: SOURCES += \
qhtml5file_html5.cpp
@@ -149,7 +151,8 @@ FORMS += \
gotosymboldialog.ui
RESOURCES += \
- icons.qrc
+ icons.qrc \
+ samples.qrc
# ICON is config specific to macOS
# see https://doc.qt.io/qt-5/appicon.html#setting-the-application-icon-on-macos
diff --git a/qtmips_gui/samples.qrc b/qtmips_gui/samples.qrc
new file mode 100644
index 0000000..605c6b1
--- /dev/null
+++ b/qtmips_gui/samples.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/">
+ <file>samples/cop0-test-ia.S</file>
+ <file>samples/simple-lw-sw-ia.S</file>
+ <file>samples/template.S</file>
+ <file>samples/template-os.S</file>
+ </qresource>
+</RCC>
diff --git a/qtmips_gui/samples/cop0-test-ia.S b/qtmips_gui/samples/cop0-test-ia.S
new file mode 100644
index 0000000..3bfe586
--- /dev/null
+++ b/qtmips_gui/samples/cop0-test-ia.S
@@ -0,0 +1,74 @@
+.set SERIAL_PORT_BASE, 0xffffc000
+
+.set SERP_RX_ST_REG_o, 0x00
+.set SERP_RX_ST_REG_READY_m, 0x1
+.set SERP_RX_ST_REG_IE_m, 0x2
+
+.set SERP_RX_DATA_REG_o, 0x04
+
+.set SERP_TX_ST_REG_o, 0x08
+.set SERP_TX_ST_REG_READY_m, 0x1
+.set SERP_TX_ST_REG_IE_m, 0x2
+
+.set SERP_TX_DATA_REG_o, 0x0c
+
+
+.globl _start
+.set noat
+.set noreorder
+.ent _start
+
+.text
+
+_start:
+ addi $1, $0, 0x101
+ addi $2, $0, 0x102
+ synci 0($zero)
+ addi $3, $0, 0x103
+ addi $4, $0, 0x104
+ la $20, skip
+ mtc0 $20, $14, 0 // EPC
+ eret
+ addi $5, $0, 0x105
+ addi $6, $0, 0x106
+skip:
+ addi $7, $0, 0x107
+ addi $8, $0, 0x108
+ mfc0 $9, $14, 0 // EPC
+
+ break
+ mfc0 $10, $14, 0 // EPC
+
+ la $20, irq_entry - 0x180
+ mtc0 $20, $15, 1 // EBase
+
+ li $21, SERIAL_PORT_BASE
+ li $20, SERP_RX_ST_REG_IE_m
+ sw $20, SERP_RX_ST_REG_o($21)
+ li $20, 0x00000801
+ mtc0 $20, $12, 0 // Status
+
+loop: mfc0 $10, $14, 0 // EPC
+ beq $zero, $zero, loop
+ nop
+
+
+irq_entry:
+ mfc0 $26, $13, 0 // Cause
+ andi $27, $26, 0x00000800
+ bne $27, $0, rx_irq
+ nop
+ mfc0 $27, $12, 0 // Status
+ nor $26, $26, $0
+ andi $26, $26, 0x0000ff00
+ and $27, $27, $26
+ mtc0 $27, $12, 0 // Status
+ eret
+
+rx_irq:
+ li $26, SERIAL_PORT_BASE
+ lw $27, SERP_RX_DATA_REG_o($26)
+ sw $27, SERP_TX_DATA_REG_o($26)
+ eret
+
+.end _start
diff --git a/qtmips_gui/samples/simple-lw-sw-ia.S b/qtmips_gui/samples/simple-lw-sw-ia.S
new file mode 100644
index 0000000..d2c3f2c
--- /dev/null
+++ b/qtmips_gui/samples/simple-lw-sw-ia.S
@@ -0,0 +1,26 @@
+.globl _start
+.set noat
+.set noreorder
+
+.text
+
+_start:
+loop:
+ // load the word from absolute address
+ lw $2, 0x2000($0)
+ // store the word to absolute address
+ sw $2, 0x2004($0)
+
+ // stop execution wait for debugger/user
+ //break
+ // ensure that continuation does not
+ // interpret random data
+ beq $0, $0, loop
+ nop
+
+.data
+
+src_val:
+ .word 0x12345678
+dst_val:
+ .word 0
diff --git a/qtmips_gui/samples/template-os.S b/qtmips_gui/samples/template-os.S
new file mode 100644
index 0000000..6c2264f
--- /dev/null
+++ b/qtmips_gui/samples/template-os.S
@@ -0,0 +1,114 @@
+// Template file with defines of peripheral registers
+// QtMips simulator https://github.com/cvut/QtMips/
+// developed by Karel Koci and Pavel Pisa.
+//
+// template.S - example file
+//
+// (C) 2019 by Pavel Pisa
+// e-mail: pisa@cmp.felk.cvut.cz
+// homepage: http://cmp.felk.cvut.cz/~pisa
+// work: http://www.pikron.com/
+// license: public domain
+
+.globl _start
+.globl __start
+.set noreorder
+.ent _start
+
+// Serial port/terminal registers
+// There is mirror of this region at address 0xffff0000
+// to match QtSpim and Mars emulators
+
+.equ SERIAL_PORT_BASE, 0xffffc000 // base address of serial port region
+
+.equ SERP_RX_ST_REG, 0xffffc000 // Receiver status register
+.equ SERP_RX_ST_REG_o, 0x0000 // Offset of RX_ST_REG
+.equ SERP_RX_ST_REG_READY_m, 0x1 // Data byte is ready to be read
+.equ SERP_RX_ST_REG_IE_m, 0x2 // Enable Rx ready interrupt
+
+.equ SERP_RX_DATA_REG, 0xffffc004 // Received data byte in 8 LSB bits
+.equ SERP_RX_DATA_REG_o, 0x0004 // Offset of RX_DATA_REG
+
+.equ SERP_TX_ST_REG, 0xffffc008 // Transmitter status register
+.equ SERP_TX_ST_REG_o, 0x0008 // Offset of TX_ST_REG
+.equ SERP_TX_ST_REG_READY_m, 0x1 // Transmitter can accept next byte
+.equ SERP_TX_ST_REG_IE_m, 0x2 // Enable Tx ready interrupt
+
+.equ SERP_TX_DATA_REG, 0xffffc00c // Write word to send 8 LSB bits to terminal
+.equ SERP_TX_DATA_REG_o, 0x000c // Offset of TX_DATA_REG
+
+
+// Memory mapped peripheral for dial knobs input,
+// LED and RGB LEDs output designed to match
+// MZ_APO education Zynq based board developed
+// by Petr Porazil and Pavel Pisa at PiKRON.com company
+
+.equ SPILED_REG_BASE 0xffffc100 // base of SPILED port region
+
+.equ SPILED_REG_LED_LINE, 0xffffc104 // 32 bit word mapped as output
+.equ SPILED_REG_LED_LINE_o, 0x0004 // Offset of the LED_LINE
+.equ SPILED_REG_LED_RGB1, 0xffffc110 // RGB LED 1 color components
+.equ SPILED_REG_LED_RGB1_o, 0x0010 // Offset of LED_RGB1
+.equ SPILED_REG_LED_RGB2, 0xffffc114 // RGB LED 2 color components
+.equ SPILED_REG_LED_RGB2_o, 0x0014 // Offset of LED_RGB2
+.equ SPILED_REG_KNOBS_8BIT, 0xffffc124 // Three 8 bit knob values
+.equ SPILED_REG_KNOBS_8BIT_o, 0x0024 // Offset of KNOBS_8BIT
+
+// The simple 16-bit per pixel (RGB565) frame-buffer
+// display size is 480 x 320 pixel
+// Pixel format RGB565 expect
+// bits 11 .. 15 red component
+// bits 5 .. 10 green component
+// bits 0 .. 4 blue component
+.equ LCD_FB_START, 0xffe00000
+.equ LCD_FB_END, 0xffe4afff
+
+// Mapping of interrupts
+// Irq number Cause/Status Bit Source
+// 2 / HW0 10 Serial port ready to accept character to Tx
+// 3 / HW1 11 There is received character ready to be read
+// 7 / HW5 15 Counter reached value in Compare register
+
+
+// Linux kernel compatible system calls subset
+
+.equ __NR_exit, 4001 // void exit(int status)
+.equ __NR_read, 4003 // ssize_t read(int fd, void *buf, size_t count)
+.equ __NR_write, 4004 // ssize_t write(int fd, const void *buf, size_t count)
+.equ __NR_close, 4006 // int close(int fd)
+.equ __NR_open, 4005 // int open(const char *pathname, int flags, mode_t mode)
+.equ __NR_brk, 4045 // void * brk(void *addr)
+.equ __NR_truncate, 4092 // int ftruncate(int fd, off_t length)
+.equ __NR_readv, 4145 // ssize_t readv(int fd, const struct iovec *iov, int iovcnt)
+.equ __NR_writev, 4146 // ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
+.equ __NR_set_thread_area, 4283 // int set_thread_area(unsigned long addr)
+
+// Original MIPS start address after reset
+.org 0x80020000
+
+.text
+
+__start:
+_start:
+
+ addi $v0, $zero, __NR_write
+ addi $a0, $zero, 1
+ la $a1, text_1
+ addi $a2, $zero, text_1_e - text_1
+ syscall
+
+ addi $v0, $zero, __NR_exit
+ addi $a0, $zero, 0
+
+final: break
+ beq $zero, $zero, final
+ nop
+
+.end _start
+
+.data
+
+data_1: .word 1, 2, 3, 4
+
+text_1: .ascii "Hello word.\n" // store ASCII text, no termination
+text_1_e:
diff --git a/qtmips_gui/samples/template.S b/qtmips_gui/samples/template.S
new file mode 100644
index 0000000..58de4a3
--- /dev/null
+++ b/qtmips_gui/samples/template.S
@@ -0,0 +1,109 @@
+// Template file with defines of peripheral registers
+// QtMips simulator https://github.com/cvut/QtMips/
+// developed by Karel Koci and Pavel Pisa.
+//
+// template.S - example file
+//
+// (C) 2019 by Pavel Pisa
+// e-mail: pisa@cmp.felk.cvut.cz
+// homepage: http://cmp.felk.cvut.cz/~pisa
+// work: http://www.pikron.com/
+// license: public domain
+
+.globl _start
+.globl __start
+.set noreorder
+.ent _start
+
+// Serial port/terminal registers
+// There is mirror of this region at address 0xffff0000
+// to match QtSpim and Mars emulators
+
+.equ SERIAL_PORT_BASE, 0xffffc000 // base address of serial port region
+
+.equ SERP_RX_ST_REG, 0xffffc000 // Receiver status register
+.equ SERP_RX_ST_REG_o, 0x0000 // Offset of RX_ST_REG
+.equ SERP_RX_ST_REG_READY_m, 0x1 // Data byte is ready to be read
+.equ SERP_RX_ST_REG_IE_m, 0x2 // Enable Rx ready interrupt
+
+.equ SERP_RX_DATA_REG, 0xffffc004 // Received data byte in 8 LSB bits
+.equ SERP_RX_DATA_REG_o, 0x0004 // Offset of RX_DATA_REG
+
+.equ SERP_TX_ST_REG, 0xffffc008 // Transmitter status register
+.equ SERP_TX_ST_REG_o, 0x0008 // Offset of TX_ST_REG
+.equ SERP_TX_ST_REG_READY_m, 0x1 // Transmitter can accept next byte
+.equ SERP_TX_ST_REG_IE_m, 0x2 // Enable Tx ready interrupt
+
+.equ SERP_TX_DATA_REG, 0xffffc00c // Write word to send 8 LSB bits to terminal
+.equ SERP_TX_DATA_REG_o, 0x000c // Offset of TX_DATA_REG
+
+
+// Memory mapped peripheral for dial knobs input,
+// LED and RGB LEDs output designed to match
+// MZ_APO education Zynq based board developed
+// by Petr Porazil and Pavel Pisa at PiKRON.com company
+
+.equ SPILED_REG_BASE 0xffffc100 // base of SPILED port region
+
+.equ SPILED_REG_LED_LINE, 0xffffc104 // 32 bit word mapped as output
+.equ SPILED_REG_LED_LINE_o, 0x0004 // Offset of the LED_LINE
+.equ SPILED_REG_LED_RGB1, 0xffffc110 // RGB LED 1 color components
+.equ SPILED_REG_LED_RGB1_o, 0x0010 // Offset of LED_RGB1
+.equ SPILED_REG_LED_RGB2, 0xffffc114 // RGB LED 2 color components
+.equ SPILED_REG_LED_RGB2_o, 0x0014 // Offset of LED_RGB2
+.equ SPILED_REG_KNOBS_8BIT, 0xffffc124 // Three 8 bit knob values
+.equ SPILED_REG_KNOBS_8BIT_o, 0x0024 // Offset of KNOBS_8BIT
+
+// The simple 16-bit per pixel (RGB565) frame-buffer
+// display size is 480 x 320 pixel
+// Pixel format RGB565 expect
+// bits 11 .. 15 red component
+// bits 5 .. 10 green component
+// bits 0 .. 4 blue component
+.equ LCD_FB_START, 0xffe00000
+.equ LCD_FB_END, 0xffe4afff
+
+// Mapping of interrupts
+// Irq number Cause/Status Bit Source
+// 2 / HW0 10 Serial port ready to accept character to Tx
+// 3 / HW1 11 There is received character ready to be read
+// 7 / HW5 15 Counter reached value in Compare register
+
+// Original MIPS start address after reset
+.org 0x80020000
+
+.text
+
+__start:
+_start:
+
+loop: la $a0, SERIAL_PORT_BASE // load base address of serial port
+ // it is pseodooperation lui $a0, 0xffff ; ori $a0, $a0, 0xc000
+ // can be optimized as addi $a0, $zero, 0xffffc000-0x100000000
+ // in this particular case
+
+ la $a1, text_1 // load address of text
+
+next_char:lb $t1, 0($a1) // load one byte after another
+ beq $t1, $zero, end_char // is this the terminal zero byte
+ addi $a1, $a1, 1 // move pointer to next text byte
+tx_busy: lw $t0, SERP_TX_ST_REG_o($a0) // read status of transmitter
+ andi $t0, $t0, SERP_TX_ST_REG_READY_m // mask ready bit
+ beq $t0, $zero, tx_busy // if not ready wait for ready condition
+ nop // fill branch instruction delay slot
+ sw $t1,SERP_TX_DATA_REG_o($a0) // write byte to Tx data register
+ beq $zero, $zero, next_char // unconditional branch to process next byte
+ nop // fill delay slot
+
+end_char: break // stop continuous execution
+ // request developer interaction
+ beq $zero, $zero, loop
+ nop // fill delay slot
+
+.end _start
+
+.data
+
+data_1: .word 1, 2, 3, 4 // example how to fill data words
+
+text_1: .asciz "Hello word.\n" // store zero terminated ASCII text
diff --git a/qtmips_gui/srceditor.cpp b/qtmips_gui/srceditor.cpp
index 18da3b5..298b9f2 100644
--- a/qtmips_gui/srceditor.cpp
+++ b/qtmips_gui/srceditor.cpp
@@ -45,6 +45,7 @@
void SrcEditor::setup_common() {
QFont font;
+ saveAsRequiredFl = true;
font.setFamily("Courier");
font.setFixedPitch(true);
font.setPointSize(10);
@@ -75,6 +76,8 @@ QString SrcEditor::title() {
void SrcEditor::setFileName(QString filename) {
QFileInfo fi(filename);
+ saveAsRequiredFl = filename.isEmpty() || filename.startsWith(":/");
+
fname = filename;
tname = fi.fileName();
delete highlighter;
@@ -87,7 +90,6 @@ void SrcEditor::setFileName(QString filename) {
}
}
-
bool SrcEditor::loadFile(QString filename) {
QFile file(filename);
if (file.open(QFile::ReadOnly | QFile::Text)) {
@@ -129,3 +131,11 @@ void SrcEditor::setCursorToLine(int ln) {
bool SrcEditor::isModified() const {
return document()->isModified();
}
+
+void SrcEditor::setSaveAsRequired(bool val) {
+ saveAsRequiredFl = val;
+}
+
+bool SrcEditor::saveAsRequired() {
+ return saveAsRequiredFl;
+}
diff --git a/qtmips_gui/srceditor.h b/qtmips_gui/srceditor.h
index 880520e..328bfb1 100644
--- a/qtmips_gui/srceditor.h
+++ b/qtmips_gui/srceditor.h
@@ -56,11 +56,14 @@ public:
void setCursorToLine(int ln);
void setFileName(QString filename);
bool isModified() const;
+ void setSaveAsRequired(bool val);
+ bool saveAsRequired();
private:
QSyntaxHighlighter *highlighter;
void setup_common();
QString fname;
QString tname;
+ bool saveAsRequiredFl;
};
#endif // SRCEDITOR_H
diff --git a/qtmips_gui/textsignalaction.cpp b/qtmips_gui/textsignalaction.cpp
new file mode 100644
index 0000000..fc5f924
--- /dev/null
+++ b/qtmips_gui/textsignalaction.cpp
@@ -0,0 +1,68 @@
+// 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 <QApplication>
+#include "textsignalaction.h"
+
+TextSignalAction::TextSignalAction(QObject *parent) : Super(parent) {
+ connect(this, SIGNAL(triggered(bool)), this, SLOT(process_triggered(bool)));
+}
+
+TextSignalAction::TextSignalAction(const QString &text, QObject *parent) :
+ Super(text, parent), signal_text(text) {
+ connect(this, SIGNAL(triggered(bool)), this, SLOT(process_triggered(bool)));
+}
+
+TextSignalAction::TextSignalAction(const QString &text, const QString &signal_text,
+ QObject *parent) :
+ Super(text, parent), signal_text(signal_text) {
+ connect(this, SIGNAL(triggered(bool)), this, SLOT(process_triggered(bool)));
+}
+
+TextSignalAction::TextSignalAction(const QIcon &icon, const QString &text, QObject *parent) :
+ Super(icon, text, parent), signal_text(text) {
+ connect(this, SIGNAL(triggered(bool)), this, SLOT(process_triggered(bool)));
+}
+
+TextSignalAction::TextSignalAction(const QIcon &icon, const QString &text, const QString &signal_text,
+ QObject *parent) :
+ Super(icon, text, parent), signal_text(signal_text) {
+ connect(this, SIGNAL(triggered(bool)), this, SLOT(process_triggered(bool)));
+}
+
+void TextSignalAction::process_triggered(bool checked) {
+ (void)checked;
+ emit activated(signal_text);
+}
diff --git a/qtmips_gui/textsignalaction.h b/qtmips_gui/textsignalaction.h
new file mode 100644
index 0000000..2373cdb
--- /dev/null
+++ b/qtmips_gui/textsignalaction.h
@@ -0,0 +1,66 @@
+// 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 TEXTSIGNALACTION_H
+#define TEXTACTION_H
+
+#include <QObject>
+#include <QAction>
+
+class TextSignalAction : public QAction
+{
+ Q_OBJECT
+
+ using Super = QAction;
+
+public:
+ TextSignalAction(QObject *parent = nullptr);
+ TextSignalAction(const QString &text, QObject *parent = nullptr);
+ TextSignalAction(const QString &text, const QString &signal_text,
+ QObject *parent = nullptr);
+ TextSignalAction(const QIcon &icon, const QString &text, QObject *parent = nullptr);
+ TextSignalAction(const QIcon &icon, const QString &text, const QString &signal_text,
+ QObject *parent = nullptr);
+signals:
+ void activated(QString signal_text);
+
+protected slots:
+ void process_triggered(bool checked);
+
+protected:
+ QString signal_text;
+};
+
+#endif // TEXTSIGNALACTION_H