aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/memorymodel.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-10 20:41:14 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-10 20:41:14 +0100
commit53605cd996338dafc507d4126a2a49b865b04db1 (patch)
tree82b03aed3c3c022c34416343e0cbef4287d24c34 /qtmips_gui/memorymodel.cpp
parent2fdc9e0e64c234832e13735a9e6972a699ed9bed (diff)
downloadqtmips-53605cd996338dafc507d4126a2a49b865b04db1.tar.gz
qtmips-53605cd996338dafc507d4126a2a49b865b04db1.tar.bz2
qtmips-53605cd996338dafc507d4126a2a49b865b04db1.zip
Memory QTableView working for part of the memory range.
Unfortunately, QModelIndex supports only integers for rows and columns. Even if only size to maxint is used then Qt engine crashes. Workaround for Qt limitations is material for followup patches. Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/memorymodel.cpp')
-rw-r--r--qtmips_gui/memorymodel.cpp29
1 files changed, 26 insertions, 3 deletions
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));
}