Fix issue in instruction view address centering
Previously, centering assumed that all .text code was placed at 0x0.
MODIFY
src/instructionmodel.cpp
src/instructionmodel.cpp
namespace Ripes {
-namespace {
-uint32_t indexToAddress(const QModelIndex& index) {
- return (index.row() * 4) + ProcessorHandler::get()->getProgram()->getSection(TEXT_SECTION_NAME)->address;
-}
-} // namespace
-
InstructionModel::InstructionModel(QObject* parent) : QAbstractTableModel(parent) {
for (int i = 0; i < ProcessorHandler::get()->getProcessor()->stageCount(); i++) {
m_stageNames << ProcessorHandler::get()->getProcessor()->stageName(i);

MODIFY
src/instructionmodel.h
src/instructionmodel.h
@@ -13,6 +13,14 @@ namespace Ripes {
class Parser;
class Pipeline;
+static inline uint32_t indexToAddress(const QModelIndex& index) {
+ return (index.row() * 4) + ProcessorHandler::get()->getProgram()->getSection(TEXT_SECTION_NAME)->address;
+}
+
+static inline unsigned addressToIndex(uint32_t addr) {
+ return (addr - ProcessorHandler::get()->getProgram()->getSection(TEXT_SECTION_NAME)->address) / 4;
+}
+
class InstructionModel : public QAbstractTableModel {
Q_OBJECT
public:

MODIFY
src/processortab.cpp
src/processortab.cpp
@@ -241,7 +241,7 @@ void ProcessorTab::reset() {
}
void ProcessorTab::setInstructionViewCenterAddr(uint32_t address) {
- const auto index = address / ProcessorHandler::get()->currentISA()->bytes();
+ const auto index = addressToIndex(address);
const auto view = m_ui->instructionView;
const auto rect = view->rect();
int indexTop = view->indexAt(rect.topLeft()).row();

Fix issue in instruction view address centering

Previously, centering assumed that all .text code was placed at 0x0.