aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_gui')
-rw-r--r--qtmips_gui/memorydock.cpp3
-rw-r--r--qtmips_gui/memorydock.h1
-rw-r--r--qtmips_gui/memorymodel.cpp29
-rw-r--r--qtmips_gui/memorymodel.h11
-rw-r--r--qtmips_gui/memorytableview.cpp12
-rw-r--r--qtmips_gui/memorytableview.h4
6 files changed, 54 insertions, 6 deletions
diff --git a/qtmips_gui/memorydock.cpp b/qtmips_gui/memorydock.cpp
index 53cc2e0..856dfa2 100644
--- a/qtmips_gui/memorydock.cpp
+++ b/qtmips_gui/memorydock.cpp
@@ -41,6 +41,7 @@
#include <QLineEdit>
#include <QHeaderView>
#include "memorydock.h"
+#include "memorymodel.h"
#include "memorytableview.h"
@@ -81,6 +82,8 @@ MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : QDockWidget(paren
connect(this, &MemoryDock::machine_setup, memory_model, &MemoryModel::setup);
connect(cell_size, QOverload<int>::of(&QComboBox::currentIndexChanged),
memory_model, &MemoryModel::set_cell_size);
+ connect(memory_model, SIGNAL(cell_size_changed()),
+ memory_content, SLOT(adap_to_cell_size()));
}
void MemoryDock::setup(machine::QtMipsMachine *machine) {
diff --git a/qtmips_gui/memorydock.h b/qtmips_gui/memorydock.h
index 2b34b8c..81797a7 100644
--- a/qtmips_gui/memorydock.h
+++ b/qtmips_gui/memorydock.h
@@ -39,7 +39,6 @@
#include <QDockWidget>
#include <QLabel>
#include <QComboBox>
-#include "memorymodel.h"
#include "qtmipsmachine.h"
class MemoryDock : public QDockWidget {
diff --git a/qtmips_gui/memorymodel.cpp b/qtmips_gui/memorymodel.cpp
index 65ee586..13ae1c7 100644
--- a/qtmips_gui/memorymodel.cpp
+++ b/qtmips_gui/memorymodel.cpp
@@ -42,10 +42,12 @@ MemoryModel::MemoryModel(QObject *parent)
index0_offset = 0;
data_font.setStyleHint(QFont::TypeWriter);
machine = nullptr;
+ memory_change_counter = 0;
+ cache_data_change_counter = 0;
}
int MemoryModel::rowCount(const QModelIndex & /*parent*/) const {
- std::uint64_t rows = (0x100 + cells_per_row - 1) / cells_per_row;
+ std::uint64_t rows = (0x2000 + cells_per_row - 1) / cells_per_row;
return rows;
}
@@ -76,8 +78,7 @@ QVariant MemoryModel::data(const QModelIndex &index, int role) const {
QString s, t;
std::uint32_t address;
std::uint32_t data;
- address = index0_offset + (index.row() * cells_per_row * cellSizeBytes());
- if (address < index0_offset)
+ if (!get_row_address(address, index.row()))
return QString("");
if (index.column() == 0) {
t = QString::number(address, 16);
@@ -124,6 +125,8 @@ QVariant MemoryModel::data(const QModelIndex &index, int role) const {
void MemoryModel::setup(machine::QtMipsMachine *machine) {
this->machine = machine;
+ if (machine != nullptr)
+ connect(machine, SIGNAL(post_tick()), this, SLOT(check_for_updates()));
}
void MemoryModel::setCellsPerRow(unsigned int cells) {
@@ -135,5 +138,25 @@ void MemoryModel::setCellsPerRow(unsigned int cells) {
void MemoryModel::set_cell_size(int index) {
beginResetModel();
cell_size = (enum MemoryCellSize)index;
+ index0_offset -= index0_offset % cellSizeBytes();
endResetModel();
+ emit cell_size_changed();
+}
+
+void MemoryModel::check_for_updates() {
+ bool need_update = false;
+ if (machine == nullptr)
+ return;
+ if (machine->memory() == nullptr)
+ return;
+
+ if (memory_change_counter != machine->memory()->get_change_counter())
+ need_update = true;
+ if (machine->cache_data() != nullptr) {
+ if (cache_data_change_counter != machine->cache_data()->get_change_counter())
+ need_update = true;
+ }
+ if (!need_update)
+ return;
+ emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
diff --git a/qtmips_gui/memorymodel.h b/qtmips_gui/memorymodel.h
index bbe51c5..e85d476 100644
--- a/qtmips_gui/memorymodel.h
+++ b/qtmips_gui/memorymodel.h
@@ -79,9 +79,18 @@ public:
}
return 0;
}
+ inline bool get_row_address(std::uint32_t &address, int row) const {
+ address = index0_offset + (row * cells_per_row * cellSizeBytes());
+ return address >= index0_offset;
+ }
+
public slots:
void setup(machine::QtMipsMachine *machine);
void set_cell_size(int index);
+ void check_for_updates();
+
+signals:
+ void cell_size_changed();
private:
enum MemoryCellSize cell_size;
@@ -89,6 +98,8 @@ private:
std::uint32_t index0_offset;
QFont data_font;
machine::QtMipsMachine *machine;
+ std::uint32_t memory_change_counter;
+ std::uint32_t cache_data_change_counter;
};
diff --git a/qtmips_gui/memorytableview.cpp b/qtmips_gui/memorytableview.cpp
index 8435e35..9b5cddf 100644
--- a/qtmips_gui/memorytableview.cpp
+++ b/qtmips_gui/memorytableview.cpp
@@ -42,8 +42,7 @@ MemoryTableView::MemoryTableView(QWidget *parent) : Super(parent) {
}
-void MemoryTableView::resizeEvent(QResizeEvent *event) {
- Super::resizeEvent(event);
+void MemoryTableView::adjustColumnCount() {
MemoryModel *m = dynamic_cast<MemoryModel*>(model());
if (horizontalHeader()->count() >= 2 && m != nullptr) {
@@ -77,3 +76,12 @@ void MemoryTableView::resizeEvent(QResizeEvent *event) {
}
}
}
+
+void MemoryTableView::adap_to_cell_size() {
+ adjustColumnCount();
+}
+
+void MemoryTableView::resizeEvent(QResizeEvent *event) {
+ Super::resizeEvent(event);
+ adjustColumnCount();
+}
diff --git a/qtmips_gui/memorytableview.h b/qtmips_gui/memorytableview.h
index 2017b78..73b1ea9 100644
--- a/qtmips_gui/memorytableview.h
+++ b/qtmips_gui/memorytableview.h
@@ -51,7 +51,11 @@ public:
void resizeEvent(QResizeEvent *event) override;
+public slots:
+ void adap_to_cell_size();
+
private:
+ void adjustColumnCount();
};