aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/memorymodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_gui/memorymodel.cpp')
-rw-r--r--qtmips_gui/memorymodel.cpp70
1 files changed, 65 insertions, 5 deletions
diff --git a/qtmips_gui/memorymodel.cpp b/qtmips_gui/memorymodel.cpp
index 71df4ce..65ee586 100644
--- a/qtmips_gui/memorymodel.cpp
+++ b/qtmips_gui/memorymodel.cpp
@@ -36,10 +36,12 @@
#include "memorymodel.h"
MemoryModel::MemoryModel(QObject *parent)
- :QAbstractTableModel(parent) {
+ :QAbstractTableModel(parent), data_font("Monospace") {
cell_size = CELLSIZE_WORD;
cells_per_row = 1;
index0_offset = 0;
+ data_font.setStyleHint(QFont::TypeWriter);
+ machine = nullptr;
}
int MemoryModel::rowCount(const QModelIndex & /*parent*/) const {
@@ -48,7 +50,7 @@ int MemoryModel::rowCount(const QModelIndex & /*parent*/) const {
}
int MemoryModel::columnCount(const QModelIndex & /*parent*/) const {
- return 2;
+ return cells_per_row + 1;
}
QVariant MemoryModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -71,9 +73,67 @@ QVariant MemoryModel::headerData(int section, Qt::Orientation orientation, int r
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);
+ QString s, t;
+ std::uint32_t address;
+ std::uint32_t data;
+ address = index0_offset + (index.row() * cells_per_row * cellSizeBytes());
+ if (address < index0_offset)
+ return QString("");
+ if (index.column() == 0) {
+ t = QString::number(address, 16);
+ s.fill('0', 8 - t.count());
+ return "0x" + s + t.toUpper();
+ }
+ if (machine == nullptr)
+ return QString("");
+ if (machine->memory() == nullptr)
+ return QString("");
+ address += cellSizeBytes() * (index.column() - 1);
+ if (address < index0_offset)
+ return QString("");
+ switch (cell_size) {
+ case CELLSIZE_BYTE:
+ data = machine->memory()->read_byte(address);
+ break;
+ case CELLSIZE_HWORD:
+ data = machine->memory()->read_hword(address);
+ break;
+ case CELLSIZE_WORD:
+ data = machine->memory()->read_word(address);
+ break;
+ }
+
+ t = QString::number(data, 16);
+ s.fill('0', cellSizeBytes() * 2 - t.count());
+ t = s + t;
+
+ machine::LocationStatus loc_stat = machine::LOCSTAT_NONE;
+ if (machine->cache_data() != nullptr) {
+ loc_stat = machine->cache_data()->location_status(address);
+ if (loc_stat & machine::LOCSTAT_DIRTY)
+ t += " D";
+ else if (loc_stat & machine::LOCSTAT_CACHED)
+ t += " C";
+ }
+ return t;
}
+ if (role==Qt::FontRole)
+ return data_font;
return QVariant();
}
+
+void MemoryModel::setup(machine::QtMipsMachine *machine) {
+ this->machine = machine;
+}
+
+void MemoryModel::setCellsPerRow(unsigned int cells) {
+ beginResetModel();
+ cells_per_row = cells;
+ endResetModel();
+}
+
+void MemoryModel::set_cell_size(int index) {
+ beginResetModel();
+ cell_size = (enum MemoryCellSize)index;
+ endResetModel();
+}