Make selecting a cache block set the memory viewer to the cache block address
MODIFY
src/cachesim/cachegraphic.cpp
src/cachesim/cachegraphic.cpp
@@ -88,6 +88,9 @@ void CacheGraphic::updateWay(unsigned lineIdx, unsigned wayIdx) {
const QString text = encodeRadixValue(data, Radix::Hex);
blockTextItem->setText(text);
blockTextItem->setToolTip("Address: " + encodeRadixValue(addressForBlock, Radix::Hex));
+ // Store the address within the userrole of the block text. Doing this, we are able to easily retrieve the
+ // address for the block if the block is clicked.
+ blockTextItem->setData(Qt::UserRole, addressForBlock);
}
} else {
// The way is invalid so no block text should be present

MODIFY
src/cachesim/cacheview.cpp
src/cachesim/cacheview.cpp
#include "cacheview.h"
#include <qmath.h>
+#include <QGraphicsSimpleTextItem>
#include <QWheelEvent>
namespace Ripes {
@@ -14,6 +15,21 @@ CacheView::CacheView(QWidget* parent) : QGraphicsView(parent) {
setupMatrix();
}
+void CacheView::mousePressEvent(QMouseEvent* event) {
+ // If we press on a cache data block, get the address stored for that block and emit a signal indicating that the
+ // address was selected through the cache
+ for (const auto& item : items(event->pos())) {
+ if (auto* textItem = dynamic_cast<QGraphicsSimpleTextItem*>(item)) {
+ const QVariant data = textItem->data(Qt::UserRole);
+ if (data.isValid()) {
+ emit cacheAddressSelected(data.toUInt());
+ break;
+ }
+ }
+ }
+ QGraphicsView::mousePressEvent(event);
+}
+
void CacheView::wheelEvent(QWheelEvent* e) {
if (e->modifiers() & Qt::ControlModifier) {
if (e->delta() > 0)

MODIFY
src/cachesim/cacheview.h
src/cachesim/cacheview.h
namespace Ripes {
class CacheView : public QGraphicsView {
+ Q_OBJECT
public:
CacheView(QWidget* parent);
protected:
void wheelEvent(QWheelEvent*) override;
+ void mousePressEvent(QMouseEvent* event) override;
+
+signals:
+ void cacheAddressSelected(uint32_t);
private slots:
void setupMatrix();

MODIFY
src/cachesim/cachewidget.cpp
src/cachesim/cachewidget.cpp
@@ -18,6 +18,9 @@ CacheWidget::CacheWidget(QWidget* parent) : QWidget(parent), m_ui(new Ui::CacheW
auto* cacheGraphic = new CacheGraphic(*m_cacheSim);
m_ui->cacheView->setScene(scene);
scene->addItem(cacheGraphic);
+
+ connect(m_ui->cacheView, &CacheView::cacheAddressSelected,
+ [=](uint32_t address) { emit cacheAddressSelected(address); });
}
void CacheWidget::setType(CacheSim::CacheType type) {

MODIFY
src/cachesim/cachewidget.h
src/cachesim/cachewidget.h
@@ -23,6 +23,9 @@ public:
void setType(CacheSim::CacheType type);
+signals:
+ void cacheAddressSelected(uint32_t);
+
private:
Ui::CacheWidget* m_ui;
CacheSim* m_cacheSim = nullptr;

MODIFY
src/memorytab.cpp
src/memorytab.cpp
@@ -16,6 +16,12 @@ MemoryTab::MemoryTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, par
m_ui->dataCache->setType(CacheSim::CacheType::DataCache);
m_ui->instructionCache->setType(CacheSim::CacheType::InstrCache);
+
+ // Make selection changes in the cache trigger the memory viewer to set its central address to the selected address
+ connect(m_ui->dataCache, &CacheWidget::cacheAddressSelected, m_ui->memoryViewerWidget,
+ &MemoryViewerWidget::setCentralAddress);
+ connect(m_ui->instructionCache, &CacheWidget::cacheAddressSelected, m_ui->memoryViewerWidget,
+ &MemoryViewerWidget::setCentralAddress);
}
void MemoryTab::update() {

Make selecting a cache block set the memory viewer to the cache block address