From df292aade4d174a7a5824f463b3a1dccf20e6c54 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Tue, 12 Feb 2019 16:18:58 +0100 Subject: Make memory and program listing editable. Instruction parsing is rough and does not support branch offset computation. Signed-off-by: Pavel Pisa --- qtmips_gui/memorymodel.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ qtmips_gui/memorymodel.h | 2 ++ qtmips_gui/programmodel.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ qtmips_gui/programmodel.h | 2 ++ 4 files changed, 87 insertions(+) (limited to 'qtmips_gui') 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; +} diff --git a/qtmips_gui/memorymodel.h b/qtmips_gui/memorymodel.h index 83bc057..7d12f91 100644 --- a/qtmips_gui/memorymodel.h +++ b/qtmips_gui/memorymodel.h @@ -57,6 +57,8 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex & index, const QVariant & value, int role); bool adjustRowAndOffset(int &row, int optimal_row, std::uint32_t address); void update_all(); diff --git a/qtmips_gui/programmodel.cpp b/qtmips_gui/programmodel.cpp index 4a758b7..5112bb8 100644 --- a/qtmips_gui/programmodel.cpp +++ b/qtmips_gui/programmodel.cpp @@ -203,3 +203,44 @@ void ProgramModel::toggle_hw_break(const QModelIndex & index) { machine->insert_hwbreak(address); update_all(); } + +Qt::ItemFlags ProgramModel::flags(const QModelIndex &index) const { + if (index.column() != 2 && index.column() != 3) + return QAbstractTableModel::flags(index); + else + return QAbstractTableModel::flags(index) | Qt::ItemIsEditable; +} + +bool ProgramModel::setData(const QModelIndex & index, const QVariant & value, int role) { + if (role == Qt::EditRole) + { + bool ok; + std::uint32_t address; + std::uint32_t data; + 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; + switch (index.column()) { + case 2: + data = value.toString().toULong(&ok, 16); + if (!ok) + return false; + mem->write_word(address, data); + break; + case 3: + data = machine::Instruction::from_string(value.toString(), &ok).data(); + if (!ok) + return false; + mem->write_word(address, data); + break; + default: + return false; + } + } + return true; +} diff --git a/qtmips_gui/programmodel.h b/qtmips_gui/programmodel.h index a6db493..9beecef 100644 --- a/qtmips_gui/programmodel.h +++ b/qtmips_gui/programmodel.h @@ -51,6 +51,8 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + Qt::ItemFlags flags(const QModelIndex &index) const; + bool setData(const QModelIndex & index, const QVariant & value, int role); bool adjustRowAndOffset(int &row, int optimal_row, std::uint32_t address); void update_all(); -- cgit v1.2.3