mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-20 06:05:11 +00:00
A basic memory viewer has been created
This commit is contained in:
@@ -63,7 +63,7 @@ add_executable(unit_tests
|
||||
tests/CPU/testInternal.cpp
|
||||
sources/Ram/ExtendedRam.cpp
|
||||
sources/Ram/ExtendedRam.hpp
|
||||
sources/Utility/Utility.hpp)
|
||||
sources/Utility/Utility.hpp sources/Utility/Utility.cpp)
|
||||
|
||||
# include criterion & coverage
|
||||
target_link_libraries(unit_tests criterion -lgcov)
|
||||
@@ -130,8 +130,12 @@ add_executable(ComSquare
|
||||
sources/Renderer/QtRenderer/QtWidgetSFML.cpp
|
||||
sources/Renderer/QtRenderer/QtWidgetSFML.hpp
|
||||
ui/cpu.ui
|
||||
ui/ramView.ui
|
||||
resources/appResources.qrc
|
||||
sources/Utility/Utility.hpp sources/Debugger/RamViewer.cpp sources/Debugger/RamViewer.hpp)
|
||||
sources/Utility/Utility.hpp
|
||||
sources/Debugger/MemoryViewer.cpp
|
||||
sources/Debugger/MemoryViewer.hpp
|
||||
sources/Utility/Utility.cpp)
|
||||
|
||||
target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED)
|
||||
|
||||
|
||||
57
sources/Debugger/MemoryViewer.cpp
Normal file
57
sources/Debugger/MemoryViewer.cpp
Normal 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
sources/Debugger/MemoryViewer.hpp
Normal file
55
sources/Debugger/MemoryViewer.hpp
Normal 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
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -42,4 +42,9 @@ namespace ComSquare::Ram
|
||||
throw InvalidAddress("Ram memset start", start);
|
||||
std::memset(&this->_data[start], value, sizeof(uint8_t) * (end - start));
|
||||
}
|
||||
|
||||
size_t Ram::getSize()
|
||||
{
|
||||
return this->_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ namespace ComSquare::Ram
|
||||
private:
|
||||
//! @brief The ram. (Can be used for WRam, SRam, VRam etc)
|
||||
uint8_t *_data;
|
||||
//! @brief The size of the ram.
|
||||
//! @brief The size of the ram (iny bytes).
|
||||
size_t _size;
|
||||
public:
|
||||
//! @brief Load a rom from it's path.
|
||||
//! @brief Create a ram of a given size in bytes.
|
||||
explicit Ram(size_t size);
|
||||
//! @brief The ram can't be copied.
|
||||
Ram(const Ram &) = delete;
|
||||
@@ -40,6 +40,9 @@ namespace ComSquare::Ram
|
||||
//! @param end end address to replace
|
||||
//! @param value replace value
|
||||
void memset(uint24_t start, uint24_t end, uint8_t value);
|
||||
|
||||
//! @brief Get the size of the ram in bytes.
|
||||
size_t getSize();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace ComSquare::Renderer
|
||||
cpuDebugger->setShortcut(Qt::Key_F1);
|
||||
QMainWindow::connect(cpuDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugCPU);
|
||||
debugger->addAction(cpuDebugger);
|
||||
QAction *ramViewer = new QAction("Ram viewer", &this->_window);
|
||||
QAction *ramViewer = new QAction("Memory viewer", &this->_window);
|
||||
ramViewer->setShortcut(Qt::Key_F2);
|
||||
QMainWindow::connect(ramViewer, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableRamViewer);
|
||||
debugger->addAction(ramViewer);
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace ComSquare
|
||||
void SNES::enableRamViewer()
|
||||
{
|
||||
#ifdef DEBUGGER_ENABLED
|
||||
this->_ramViewer = std::make_shared<Debugger::RamViewer>(*this);
|
||||
this->_ramViewer = std::make_shared<Debugger::MemoryViewer>(*this);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "APU/APU.hpp"
|
||||
#include "Renderer/IRenderer.hpp"
|
||||
#ifdef DEBUGGER_ENABLED
|
||||
#include "Debugger/RamViewer.hpp"
|
||||
#include "Debugger/MemoryViewer.hpp"
|
||||
#endif
|
||||
|
||||
namespace ComSquare
|
||||
@@ -22,7 +22,7 @@ namespace ComSquare
|
||||
class SNES {
|
||||
#ifdef DEBUGGER_ENABLED
|
||||
private:
|
||||
std::shared_ptr<Debugger::RamViewer> _ramViewer;
|
||||
std::shared_ptr<Debugger::MemoryViewer> _ramViewer;
|
||||
#endif
|
||||
public:
|
||||
//! @brief Cartridge containing instructions (ROM).
|
||||
|
||||
29
sources/Utility/Utility.cpp
Normal file
29
sources/Utility/Utility.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 2/17/20.
|
||||
//
|
||||
|
||||
#include "Utility.hpp"
|
||||
|
||||
namespace ComSquare::Utility
|
||||
{
|
||||
std::string to_hex(uint8_t i)
|
||||
{
|
||||
char buf[5];
|
||||
sprintf(buf, "0x%02X", i);
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string to_hex(uint16_t i)
|
||||
{
|
||||
char buf[7];
|
||||
sprintf(buf, "0x%04X", i);
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string to_hex(uint24_t i)
|
||||
{
|
||||
char buf[9];
|
||||
sprintf(buf, "0x%06X", i);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
@@ -12,26 +12,11 @@
|
||||
|
||||
namespace ComSquare::Utility
|
||||
{
|
||||
std::string to_hex(uint8_t i)
|
||||
{
|
||||
char buf[5];
|
||||
sprintf(buf, "0x%02X", i);
|
||||
return buf;
|
||||
}
|
||||
std::string to_hex(uint8_t i);
|
||||
|
||||
std::string to_hex(uint16_t i)
|
||||
{
|
||||
char buf[7];
|
||||
sprintf(buf, "0x%04X", i);
|
||||
return buf;
|
||||
}
|
||||
std::string to_hex(uint16_t i);
|
||||
|
||||
std::string to_hex(uint24_t i)
|
||||
{
|
||||
char buf[9];
|
||||
sprintf(buf, "0x%06X", i);
|
||||
return buf;
|
||||
}
|
||||
std::string to_hex(uint24_t i);
|
||||
}
|
||||
|
||||
#endif //COMSQUARE_UTILITY_HPP
|
||||
|
||||
32
ui/ramView.ui
Normal file
32
ui/ramView.ui
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RamView</class>
|
||||
<widget class="QMainWindow" name="RamView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Memory Viewer</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../resources/appResources.qrc">
|
||||
<normaloff>:/resources/Logo.png</normaloff>:/resources/Logo.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources/appResources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user