Move instruction view according to which instruction is in IF stage
MODIFY
src/instructionmodel.cpp
src/instructionmodel.cpp
@@ -85,6 +85,7 @@ QVariant InstructionModel::data(const QModelIndex& index, int role) const {
}
if (byteIndex == m_pcsptr.IF.pc && m_pcsptr.IF.initialized && m_pcsptr.IF.invalidReason == 0) {
emit textChanged(Stage::IF, m_parserPtr->genStringRepr(memRead(row * 4)));
+ emit currentIFRow(row); // for moving view to IF position
retStrings << "IF";
}
if (byteIndex == m_pcsptr.MEM.pc && m_pcsptr.MEM.initialized && m_pcsptr.MEM.invalidReason == 0) {

MODIFY
src/instructionmodel.h
src/instructionmodel.h
@@ -26,6 +26,8 @@ public:
void update();
+ int m_currentIFrow = 0;
+
private:
const StagePCS& m_pcsptr;
const StagePCS& m_pcsptrPre;
@@ -38,6 +40,7 @@ private:
signals:
void textChanged(Stage stage, QString text) const;
+ void currentIFRow(int) const;
public slots:
};

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -25,8 +25,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
m_ui->tabbar->addFancyTab(QIcon(QPixmap(":/icons/binary-code.svg")), "Code");
m_ui->tabbar->addFancyTab(QIcon(QPixmap(":/icons/cpu.svg")), "Processor");
m_ui->tabbar->addFancyTab(QIcon(QPixmap(":/icons/ram-memory.svg")), "Memory");
- m_ui->tabbar->addFancyTab(QIcon(QPixmap(":/icons/server.svg")), "Cache");
- m_ui->tabbar->addFancyTab(QIcon(QPixmap(":/icons/graph.svg")), "Results");
+ // m_ui->tabbar->addFancyTab(QIcon(QPixmap(":/icons/server.svg")), "Cache");
+ // m_ui->tabbar->addFancyTab(QIcon(QPixmap(":/icons/graph.svg")), "Results");
connect(m_ui->tabbar, &FancyTabBar::activeIndexChanged, m_ui->stackedWidget, &QStackedWidget::setCurrentIndex);
m_ui->tabbar->setActiveIndex(1);
@@ -55,7 +55,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
m_ui->consoles->hide();
};
});
+ connect(m_ui->processortab, &ProcessorTab::update, this, &MainWindow::updateMemoryTab);
connect(this, &MainWindow::update, m_ui->processortab, &ProcessorTab::restart);
+ connect(this, &MainWindow::updateMemoryTab, m_ui->memorytab, &MemoryTab::update);
}
MainWindow::~MainWindow() {

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -26,9 +26,11 @@ private slots:
void on_actionAbout_triggered();
void on_actionOpen_documentation_triggered();
+ void processorUpdated() { emit updateMemoryTab(); }
signals:
void update();
+ void updateMemoryTab();
private:
Ui::MainWindow* m_ui;

MODIFY
src/memorymodel.h
src/memorymodel.h
@@ -19,11 +19,11 @@ public:
long long getCentralAddress() const { return m_centralAddress; }
int getModelRows() const { return rowCount(); }
+ void updateModel();
public slots:
void jumpToAddress(uint32_t address);
private:
- void updateModel();
void setInvalidAddresLine(int row);
// instead of direct access to the memory, we should have a pointer to the runner, which can return requested

MODIFY
src/memorytab.cpp
src/memorytab.cpp
@@ -92,6 +92,11 @@ void MemoryTab::initializeMemoryView() {
connect(m_model, &MemoryModel::dataChanged, m_ui->memoryView, &MemoryView::setVisibleRows);
}
+void MemoryTab::update() {
+ m_ui->registerContainer->update();
+ m_model->updateModel();
+}
+
MemoryTab::~MemoryTab() {
delete m_ui;
}

MODIFY
src/memorytab.h
src/memorytab.h
@@ -28,6 +28,8 @@ public:
public slots:
void saveAddress();
+ void update();
+
private:
void initializeMemoryView();
void initializeRegisterView();

MODIFY
src/processortab.cpp
src/processortab.cpp
#include "processortab.h"
+#include <QScrollBar>
#include "instructionmodel.h"
#include "pipelinewidget.h"
#include "ui_processortab.h"
@@ -85,7 +86,7 @@ void ProcessorTab::initInstructionView() {
m_ui->instructionView->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
connect(this, &ProcessorTab::update, m_ui->instructionView, QOverload<>::of(&QWidget::update));
connect(this, &ProcessorTab::update, m_instrModel, &InstructionModel::update);
-
+ connect(m_instrModel, &InstructionModel::currentIFRow, this, &ProcessorTab::setCurrentInstruction);
// Connect instruction model text changes to the pipeline widget (changing instruction names displayed above each
// stage)
connect(m_instrModel, &InstructionModel::textChanged, m_ui->pipelineWidget, &PipelineWidget::stageTextChanged);
@@ -126,11 +127,29 @@ void ProcessorTab::on_reset_clicked() {
m_ui->run->setEnabled(true);
}
+void ProcessorTab::setCurrentInstruction(int row) {
+ // model emits signal with current IF instruction row
+ auto instructionView = m_ui->instructionView;
+ auto rect = instructionView->rect();
+ int indexTop = instructionView->indexAt(rect.topLeft()).row();
+ int indexBot = instructionView->indexAt(rect.bottomLeft()).row();
+
+ int nItems = indexBot - indexTop;
+
+ // move scrollbar if if is not visible
+ if (row <= indexTop || row >= indexBot) {
+ auto scrollbar = m_ui->instructionView->verticalScrollBar();
+ scrollbar->setValue(row - nItems / 2);
+ }
+}
+
void ProcessorTab::on_step_clicked() {
auto pipeline = Pipeline::getPipeline();
auto state = pipeline->step();
emit update();
+ // Move instruction view
+
if (pipeline->isFinished()) {
m_ui->step->setEnabled(false);
m_ui->start->setEnabled(false);

MODIFY
src/processortab.h
src/processortab.h
@@ -27,24 +27,16 @@ public slots:
void restart();
private slots:
-
void on_expandView_clicked();
-
void on_displayValues_toggled(bool checked);
-
void on_run_clicked();
-
void on_reset_clicked();
-
void on_step_clicked();
-
void toggleTimer(bool state);
-
void on_zoomIn_clicked();
-
void on_zoomOut_clicked();
-
void on_save_clicked();
+ void setCurrentInstruction(int row);
private:
Ui::ProcessorTab* m_ui;

Move instruction view according to which instruction is in IF stage