aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/memorymodel.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-12 16:18:58 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-12 16:18:58 +0100
commitdf292aade4d174a7a5824f463b3a1dccf20e6c54 (patch)
tree85d26d5a0d5101f5caae6dcde20b515f98bcbb06 /qtmips_gui/memorymodel.cpp
parentfc27072b451dd8385401fadf198db69b0e87c72c (diff)
downloadqtmips-df292aade4d174a7a5824f463b3a1dccf20e6c54.tar.gz
qtmips-df292aade4d174a7a5824f463b3a1dccf20e6c54.tar.bz2
qtmips-df292aade4d174a7a5824f463b3a1dccf20e6c54.zip
Make memory and program listing editable.
Instruction parsing is rough and does not support branch offset computation. Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/memorymodel.cpp')
-rw-r--r--qtmips_gui/memorymodel.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/qtmips_gui/memorymodel.cpp b/qtmips_gui/memorymodel.cpp
index 12b3fcb..597b88f 100644
--- a/qtmips_gui/memorymodel.cpp
+++ b/qtmips_gui/memorymodel.cpp
@@ -225,3 +225,45 @@ void MemoryModel::cached_access(int cached) {
access_through_cache = cached;
update_all();
}
+
+Qt::ItemFlags MemoryModel::flags(const QModelIndex &index) const {
+ if (index.column() == 0)
+ return QAbstractTableModel::flags(index);
+ else
+ return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
+}
+
+bool MemoryModel::setData(const QModelIndex & index, const QVariant & value, int role) {
+ if (role == Qt::EditRole)
+ {
+ bool ok;
+ std::uint32_t address;
+ std::uint32_t data = value.toString().toULong(&ok, 16);
+ if (!ok)
+ return false;
+ machine::MemoryAccess *mem;
+ if (!get_row_address(address, index.row()))
+ return false;
+ if (index.column() == 0 || machine == nullptr)
+ return false;
+ mem = machine->memory_rw();
+ if (mem == nullptr)
+ return false;
+ if ((access_through_cache > 0) && (machine->cache_data_rw() != nullptr))
+ mem = machine->cache_data_rw();
+ address += cellSizeBytes() * (index.column() - 1);
+ switch (cell_size) {
+ case CELLSIZE_BYTE:
+ mem->write_byte(address, data);
+ break;
+ case CELLSIZE_HWORD:
+ mem->write_hword(address, data);
+ break;
+ default:
+ case CELLSIZE_WORD:
+ mem->write_word(address, data);
+ break;
+ }
+ }
+ return true;
+}