diff options
Diffstat (limited to 'qtmips_gui')
-rw-r--r-- | qtmips_gui/memorydock.cpp | 73 | ||||
-rw-r--r-- | qtmips_gui/memorydock.h | 20 | ||||
-rw-r--r-- | qtmips_gui/memorymodel.cpp | 72 | ||||
-rw-r--r-- | qtmips_gui/memorymodel.h | 75 | ||||
-rw-r--r-- | qtmips_gui/qtmips_gui.pro | 6 |
5 files changed, 187 insertions, 59 deletions
diff --git a/qtmips_gui/memorydock.cpp b/qtmips_gui/memorydock.cpp index 86f8f26..eea7122 100644 --- a/qtmips_gui/memorydock.cpp +++ b/qtmips_gui/memorydock.cpp @@ -33,57 +33,50 @@ * ******************************************************************************/ +#include <QWidget> +#include <QPushButton> +#include <QVBoxLayout> +#include <QTableView> +#include <QComboBox> +#include <QLineEdit> +#include <QHeaderView> #include "memorydock.h" -DataView::DataView(QWidget *parent, QSettings *settings) : MemoryView(parent, settings->value("DataViewAddr0", 0).toULongLong()) { - this->settings = settings; -} -QList<QWidget*> DataView::row_widget(std::uint32_t address, QWidget *parent) { - QList<QWidget*> widgs; - QLabel *l; - QFont f; - f.setStyleHint(QFont::Monospace); +MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : QDockWidget(parent) { + setObjectName("Memory"); + setWindowTitle("Memory"); - l = new QLabel(QString("0x") + QString("%1").arg(address, 8, 16, QChar('0')).toUpper(), parent); - l->setTextInteractionFlags(Qt::TextSelectableByMouse); - l->setFont(f); - widgs.append(l); + QWidget *content = new QWidget(); - l = new QLabel(parent); - l->setTextInteractionFlags(Qt::TextSelectableByMouse); - l->setFont(f); - if (memory != nullptr) { - machine::LocationStatus loc_stat = machine::LOCSTAT_NONE; - QString val; - val = QString("0x") + QString("%1").arg(memory->read_word(address), 8, 16, QChar('0')).toUpper(); - if (cache_data != nullptr) { - loc_stat = cache_data->location_status(address); - if (loc_stat & machine::LOCSTAT_DIRTY) - val += " D"; - else if (loc_stat & machine::LOCSTAT_CACHED) - val += " C"; - } - l->setText(val); - } - widgs.append(l); + QComboBox *cell_size = new QComboBox(); + cell_size->addItem("Word", MemoryModel::CELLSIZE_WORD); + cell_size->addItem("Half-word", MemoryModel::CELLSIZE_HWORD); + cell_size->addItem("Byte", MemoryModel::CELLSIZE_BYTE); - return widgs; -} + QTableView *memory_content = new QTableView(); + // memory_content->setSizePolicy(); + MemoryModel *memory_model = new MemoryModel(0); + memory_content->setModel(memory_model); + memory_content->verticalHeader()->hide(); + //memory_content->setHorizontalHeader(memory_model->); -void DataView::addr0_save_change(std::uint32_t val) { - settings->setValue("DataViewAddr0", val); -} + QLineEdit *go_edit = new QLineEdit(); + go_edit->setText("0x00000000"); + go_edit->setInputMask("\\0\\xHhhhhhhh"); -MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : QDockWidget(parent) { - view = new DataView(this, settings); - setWidget(view); + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(cell_size); + layout->addWidget(memory_content); + layout->addWidget(go_edit); + layout->addWidget(go_edit); - setObjectName("Memory"); - setWindowTitle("Memory"); + content->setLayout(layout); + + setWidget(content); } void MemoryDock::setup(machine::QtMipsMachine *machine) { - view->setup(machine); + } diff --git a/qtmips_gui/memorydock.h b/qtmips_gui/memorydock.h index 7eb7d0a..8971457 100644 --- a/qtmips_gui/memorydock.h +++ b/qtmips_gui/memorydock.h @@ -39,33 +39,19 @@ #include <QDockWidget> #include <QLabel> #include <QComboBox> +#include "memorymodel.h" #include "qtmipsmachine.h" -#include "memoryview.h" - -class DataView : public MemoryView { - Q_OBJECT -public: - DataView(QWidget *parent, QSettings *settings); - -protected: - QList<QWidget*> row_widget(std::uint32_t address, QWidget *parent); - - void addr0_save_change(std::uint32_t val); - -private: - QComboBox *cb_size; - QSettings *settings; -}; class MemoryDock : public QDockWidget { Q_OBJECT + public: MemoryDock(QWidget *parent, QSettings *settings); void setup(machine::QtMipsMachine *machine); private: - DataView *view; + }; #endif // MEMORYDOCK_H diff --git a/qtmips_gui/memorymodel.cpp b/qtmips_gui/memorymodel.cpp new file mode 100644 index 0000000..5596b35 --- /dev/null +++ b/qtmips_gui/memorymodel.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<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 "memorymodel.h" + +MemoryModel::MemoryModel(QObject *parent) + :QAbstractTableModel(parent) { + cell_size = CELLSIZE_WORD; + cells_per_row = 1; + index0_offset = 0; + updateHeaderLabels(); +} + +void MemoryModel::updateHeaderLabels() { + setHeaderData(0, Qt::Horizontal, QString("Address")); + for (unsigned int i = 0; i < cells_per_row; i++) { + std::uint32_t addr = i * cellSizeBytes(); + setHeaderData(i + 1, Qt::Horizontal, QString("+0x") + + QString::number(addr, 16)); + } +} + +int MemoryModel::rowCount(const QModelIndex & /*parent*/) const { + std::uint64_t rows = (0x10000000 + cells_per_row - 1) / cells_per_row; + return rows; +} + +int MemoryModel::columnCount(const QModelIndex & /*parent*/) const { + return 2; +} + +QVariant MemoryModel::data(const QModelIndex &index, int role) const { + if (role == Qt::DisplayRole) + { + return QString("Row%1, Column%2") + .arg(index.row() + 1) + .arg(index.column() +1); + } + return QVariant(); +} diff --git a/qtmips_gui/memorymodel.h b/qtmips_gui/memorymodel.h new file mode 100644 index 0000000..badb224 --- /dev/null +++ b/qtmips_gui/memorymodel.h @@ -0,0 +1,75 @@ +// 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 MEMORYMODEL_H +#define MEMORYMODEL_H + +#include <QAbstractTableModel> + +class MemoryModel : public QAbstractTableModel +{ + Q_OBJECT +public: + enum MemoryCellSize { + CELLSIZE_BYTE, + CELLSIZE_HWORD, + CELLSIZE_WORD, + }; + + MemoryModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; +private: + void updateHeaderLabels(); + inline unsigned int cellSizeBytes() { + switch (cell_size) { + case CELLSIZE_BYTE: + return 1; + case CELLSIZE_HWORD: + return 2; + case CELLSIZE_WORD: + return 4; + } + return 0; + } + + enum MemoryCellSize cell_size; + unsigned int cells_per_row; + std::uint32_t index0_offset; +}; + + +#endif // MEMORYMODEL_H diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro index b15eca1..4f40454 100644 --- a/qtmips_gui/qtmips_gui.pro +++ b/qtmips_gui/qtmips_gui.pro @@ -46,7 +46,8 @@ SOURCES += \ cacheview.cpp \ cachedock.cpp \ graphicsview.cpp \ - coreview/value.cpp + coreview/value.cpp \ + memorymodel.cpp HEADERS += \ mainwindow.h \ @@ -73,7 +74,8 @@ HEADERS += \ cacheview.h \ cachedock.h \ graphicsview.h \ - coreview/value.h + coreview/value.h \ + memorymodel.h FORMS += \ NewDialog.ui \ |