A basic memory viewer has been created

This commit is contained in:
Anonymus Raccoon
2020-02-18 00:45:13 +01:00
parent 1bbf9cfe77
commit 92e48db363
13 changed files with 196 additions and 75 deletions
+57
View File
@@ -0,0 +1,57 @@
//
// Created by anonymus-raccoon on 2/17/20.
//
#include <iostream>
#include "MemoryViewer.hpp"
#include "../SNES.hpp"
#include "../Utility/Utility.hpp"
MemoryViewerModel::MemoryViewerModel(std::shared_ptr<Ram> memory, QObject *parent) :
QAbstractTableModel(parent),
_memory(std::move(memory))
{ }
int MemoryViewerModel::rowCount(const QModelIndex &) const
{
return this->_memory->getSize() / 16u;
}
int MemoryViewerModel::columnCount(const QModelIndex &parent) const
{
if (parent.row() == this->rowCount(parent) - 1)
return this->_memory->getSize() - (parent.row() << 8u);
return 16;
}
QVariant MemoryViewerModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
return QString(ComSquare::Utility::to_hex(this->_memory->read_internal((index.row() << 4u) + index.column())).c_str());
}
QVariant MemoryViewerModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
return QString(ComSquare::Utility::to_hex(static_cast<uint8_t>(section)).c_str());
else
return QString(ComSquare::Utility::to_hex(static_cast<uint16_t>(section)).c_str());
}
namespace ComSquare::Debugger
{
MemoryViewer::MemoryViewer(ComSquare::SNES &snes) :
QMainWindow(), _snes(snes), _ui(), _model(snes.wram)
{
this->setContextMenuPolicy(Qt::NoContextMenu);
this->setAttribute(Qt::WA_QuitOnClose, false);
this->_ui.setupUi(this);
this->_ui.tableView->setModel(&this->_model);
this->show();
}
}
+55
View File
@@ -0,0 +1,55 @@
//
// Created by anonymus-raccoon on 2/17/20.
//
#ifndef COMSQUARE_MEMORYVIEWER_HPP
#define COMSQUARE_MEMORYVIEWER_HPP
#include <QtWidgets/QMainWindow>
#include "../../ui/ui_ramView.h"
#include "../Ram/Ram.hpp"
using ComSquare::Ram::Ram;
//! @brief The qt model that bind the ram to the view.
class MemoryViewerModel : public QAbstractTableModel
{
Q_OBJECT
private:
std::shared_ptr<Ram> _memory;
public:
explicit MemoryViewerModel(std::shared_ptr<Ram> memory, QObject *parent = nullptr);
MemoryViewerModel(const MemoryViewerModel &) = delete;
const MemoryViewerModel &operator=(const MemoryViewerModel &) = delete;
~MemoryViewerModel() override = default;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
};
namespace ComSquare
{
class SNES;
namespace Debugger
{
//! @brief Class responsible of the Memory Viewer.
class MemoryViewer : public QMainWindow {
private:
//! @brief SNES containing all rams to view.
SNES &_snes;
//! @brief The layout of the viewer.
Ui::RamView _ui;
//! @brief The Ram visualizer model for QT.
MemoryViewerModel _model;
public:
explicit MemoryViewer(SNES &snes);
MemoryViewer(const MemoryViewer &) = delete;
MemoryViewer &operator=(const MemoryViewer &) = delete;
~MemoryViewer() override = default;
};
}
}
#endif //COMSQUARE_MEMORYVIEWER_HPP
-19
View File
@@ -1,19 +0,0 @@
//
// Created by anonymus-raccoon on 2/17/20.
//
#include "RamViewer.hpp"
#include "../SNES.hpp"
namespace ComSquare::Debugger
{
RamViewer::RamViewer(ComSquare::SNES &snes) :
QMainWindow(), _snes(snes)
{
this->setContextMenuPolicy(Qt::NoContextMenu);
this->setAttribute(Qt::WA_QuitOnClose, false);
// this->_ui.setupUi(this);
this->show();
}
}
-30
View File
@@ -1,30 +0,0 @@
//
// Created by anonymus-raccoon on 2/17/20.
//
#ifndef COMSQUARE_RAMVIEWER_HPP
#define COMSQUARE_RAMVIEWER_HPP
#include <QtWidgets/QMainWindow>
namespace ComSquare
{
class SNES;
namespace Debugger
{
class RamViewer : public QMainWindow {
private:
//! @brief SNES containing all rams to view.
SNES &_snes;
//! @brief The layout of the viewer.
// Ui::RamView _ui;
public:
explicit RamViewer(SNES &snes);
RamViewer(const RamViewer &) = delete;
RamViewer &operator=(const RamViewer &) = delete;
~RamViewer() override = default;
};
}
}
#endif //COMSQUARE_RAMVIEWER_HPP