From f16815c36f8a5ad58e63a67984311d3511a1a8b6 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 4 Jul 2021 23:20:07 +0200 Subject: [PATCH] Enabling more debuggers --- CMakeLists.txt | 14 ++- sources/Debugger/CGramDebug.cpp | 85 ++++++++----------- sources/Debugger/CGramDebug.hpp | 76 ++++++++--------- .../Debugger/TileViewer/RAMTileRenderer.cpp | 24 ++---- .../Debugger/TileViewer/RAMTileRenderer.hpp | 22 +++-- sources/Debugger/TileViewer/TileViewer.cpp | 50 ++++------- sources/Debugger/TileViewer/TileViewer.hpp | 23 ++--- sources/Ram/ExtendedRam.cpp | 36 -------- sources/Ram/ExtendedRam.hpp | 29 ------- sources/Ram/Ram.cpp | 10 +++ sources/Ram/Ram.hpp | 29 ++++--- sources/Renderer/QtRenderer/QtSFML.cpp | 4 +- sources/SNES.cpp | 50 +++++------ sources/SNES.hpp | 25 +++--- sources/main.cpp | 2 +- 15 files changed, 186 insertions(+), 293 deletions(-) delete mode 100644 sources/Ram/ExtendedRam.cpp delete mode 100644 sources/Ram/ExtendedRam.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 331197d..da0b10c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,8 +53,6 @@ set(SOURCES sources/CPU/Instructions/MathematicalOperations.cpp sources/CPU/Instructions/MemoryInstructions.cpp sources/CPU/Instructions/InternalInstruction.cpp - sources/Ram/ExtendedRam.cpp - sources/Ram/ExtendedRam.hpp sources/Utility/Utility.hpp sources/Utility/Utility.cpp sources/CPU/Instructions/BitsInstructions.cpp @@ -133,14 +131,14 @@ add_executable(comsquare # sources/Debugger/APUDebug.cpp # sources/Debugger/MemoryBusDebug.cpp # sources/Debugger/MemoryBusDebug.hpp -# sources/Debugger/CGramDebug.cpp -# sources/Debugger/CGramDebug.hpp + sources/Debugger/CGramDebug.cpp + sources/Debugger/CGramDebug.hpp sources/Debugger/RegisterViewer.cpp sources/Debugger/RegisterViewer.hpp -# sources/Debugger/TileViewer/TileViewer.cpp -# sources/Debugger/TileViewer/TileViewer.hpp -# sources/Debugger/TileViewer/RAMTileRenderer.cpp -# sources/Debugger/TileViewer/RAMTileRenderer.hpp + sources/Debugger/TileViewer/TileViewer.cpp + sources/Debugger/TileViewer/TileViewer.hpp + sources/Debugger/TileViewer/RAMTileRenderer.cpp + sources/Debugger/TileViewer/RAMTileRenderer.hpp ui/tileView.ui ui/registersView.ui ui/cpuView.ui diff --git a/sources/Debugger/CGramDebug.cpp b/sources/Debugger/CGramDebug.cpp index 1a273fb..387f4f9 100644 --- a/sources/Debugger/CGramDebug.cpp +++ b/sources/Debugger/CGramDebug.cpp @@ -3,26 +3,21 @@ // #include "CGramDebug.hpp" -#include "../SNES.hpp" +#include "SNES.hpp" #include #include -#include #include -#include "../Utility/Utility.hpp" +#include "Utility/Utility.hpp" namespace ComSquare::Debugger { CGramDebug::CGramDebug(SNES &snes, ComSquare::PPU::PPU &ppu) - : _window(new ClosableWindow(*this, &CGramDebug::disableViewer)), + : _window(new ClosableWindow([&snes] { snes.disableCgramViewer(); })), _snes(snes), _ui(), _model(ppu), _ppu(ppu) { - this->_window->setContextMenuPolicy(Qt::NoContextMenu); - this->_window->setAttribute(Qt::WA_QuitOnClose, false); - this->_window->setAttribute(Qt::WA_DeleteOnClose); - this->_ui.setupUi(this->_window); QMainWindow::connect(this->_ui.cgram_view, &QTableView::pressed, this, &CGramDebug::tileClicked); this->_ui.cgram_view->setModel(&this->_model); @@ -31,21 +26,11 @@ namespace ComSquare::Debugger QEvent::registerEventType(); } - void CGramDebug::disableViewer() - { - this->_snes.disableCgramDebugging(); - } - void CGramDebug::focus() { this->_window->activateWindow(); } - bool CGramDebug::isDebugger() - { - return true; - } - uint16_t CGramDebug::read(uint8_t addr) { return this->_ppu.cgramRead(addr); @@ -79,42 +64,44 @@ namespace ComSquare::Debugger return; this->updateInfoTile(index.row(), index.column()); } -} -CGramModel::CGramModel(ComSquare::PPU::PPU &ppu) : _ppu(ppu) {} + CGramModel::CGramModel(ComSquare::PPU::PPU &ppu) + : _ppu(ppu) + {} -int CGramModel::rowCount(const QModelIndex &) const -{ - return this->rows; -} + int CGramModel::rowCount(const QModelIndex &) const + { + return this->rows; + } -int CGramModel::columnCount(const QModelIndex &) const -{ - return this->column; -} + int CGramModel::columnCount(const QModelIndex &) const + { + return this->column; + } -QVariant CGramModel::data(const QModelIndex &index, int role) const -{ - u_int16_t addressValue; - uint8_t red; - uint8_t green; - uint8_t blue; + QVariant CGramModel::data(const QModelIndex &index, int role) const + { + u_int16_t addressValue; + uint8_t red; + uint8_t green; + uint8_t blue; - if (role == Qt::TextAlignmentRole) - return Qt::AlignCenter; - if (role != Qt::BackgroundRole) - return QVariant(); - int idDisplayTile = index.row() * 16 + index.column(); - uint16_t cgramAddress = idDisplayTile / 8 * 16 + (idDisplayTile % 8 * 2); - addressValue = this->_ppu.cgramRead(cgramAddress); - addressValue += this->_ppu.cgramRead(cgramAddress + 1) << 8U; + if (role == Qt::TextAlignmentRole) + return Qt::AlignCenter; + if (role != Qt::BackgroundRole) + return QVariant(); + int idDisplayTile = index.row() * 16 + index.column(); + uint16_t cgramAddress = idDisplayTile / 8 * 16 + (idDisplayTile % 8 * 2); + addressValue = this->_ppu.cgramRead(cgramAddress); + addressValue += this->_ppu.cgramRead(cgramAddress + 1) << 8U; - blue = (addressValue & 0x7D00U) >> 10U; - green = (addressValue & 0x03E0U) >> 5U; - red = (addressValue & 0x001FU); + blue = (addressValue & 0x7D00U) >> 10U; + green = (addressValue & 0x03E0U) >> 5U; + red = (addressValue & 0x001FU); - red = red * 255U / 31U; - green = green * 255U / 31U; - blue = blue * 255U / 31U; - return QColor(red, green, blue); + red = red * 255U / 31U; + green = green * 255U / 31U; + blue = blue * 255U / 31U; + return QColor(red, green, blue); + } } \ No newline at end of file diff --git a/sources/Debugger/CGramDebug.hpp b/sources/Debugger/CGramDebug.hpp index a8ad12c..d7d4d0a 100644 --- a/sources/Debugger/CGramDebug.hpp +++ b/sources/Debugger/CGramDebug.hpp @@ -2,52 +2,53 @@ // Created by cbihan on 3/27/20. // -#ifndef COMSQUARE_CGRAMDEBUG_HPP -#define COMSQUARE_CGRAMDEBUG_HPP +#pragma once #include -#include "../PPU/PPU.hpp" -#include "../../ui/ui_cgramView.h" +#include "PPU/PPU.hpp" +#include "ui/ui_cgramView.h" #include #include #include #include #include "ClosableWindow.hpp" -//! @brief The qt model that bind the logs to the view. -class CGramModel : public QAbstractTableModel -{ -Q_OBJECT -private: - //! @brief The ppu to log the cgram. - ComSquare::PPU::PPU &_ppu; -public: - //! @brief The number of columns - const int column = 16; - //! @brief The number of rows - const int rows = 16; - int x; - int y; - explicit CGramModel(ComSquare::PPU::PPU &ppu); - CGramModel(const CGramModel &) = delete; - const CGramModel &operator=(const CGramModel &) = delete; - ~CGramModel() override = default; - - //! @brief The number of row the table has. - int rowCount(const QModelIndex &parent) const override; - //! @brief The number of column the table has. - int columnCount(const QModelIndex &parent) const override; - //! @brief Return a data representing the table cell. - QVariant data(const QModelIndex &index, int role) const override; -}; - namespace ComSquare::Debugger { + //! @brief The qt model that bind the logs to the view. + class CGramModel : public QAbstractTableModel + { + Q_OBJECT + private: + //! @brief The ppu to log the cgram. + ComSquare::PPU::PPU &_ppu; + public: + //! @brief The number of columns + const int column = 16; + //! @brief The number of rows + const int rows = 16; + int x; + int y; + + explicit CGramModel(ComSquare::PPU::PPU &ppu); + CGramModel(const CGramModel &) = delete; + const CGramModel &operator=(const CGramModel &) = delete; + ~CGramModel() override = default; + + //! @brief The number of row the table has. + [[nodiscard]] int rowCount(const QModelIndex &parent) const override; + //! @brief The number of column the table has. + [[nodiscard]] int columnCount(const QModelIndex &parent) const override; + //! @brief Return a data representing the table cell. + [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; + }; + //! @brief window that allow the user to view all data going through the memory bus. - class CGramDebug : public QObject { + class CGramDebug : public QObject + { private: //! @brief The QT window for this debugger. - ClosableWindow *_window; + ClosableWindow *_window; //! @brief A reference to the snes (to disable the debugger). SNES &_snes; //! @brief A widget that contain the whole UI. @@ -56,14 +57,11 @@ namespace ComSquare::Debugger CGramModel _model; //! @brief A reference to the ppu ComSquare::PPU::PPU &_ppu; - public: - //! @brief Called when the window is closed. Turn off the debugger. - void disableViewer(); public: explicit CGramDebug(SNES &snes, ComSquare::PPU::PPU &ppu); CGramDebug(const CGramDebug &) = delete; CGramDebug &operator=(const CGramDebug &) = delete; - ~CGramDebug() = default; + ~CGramDebug() override = default; //! @brief Read data at the CGRAM address send it to the debugger. //! @param addr The address to read from. @@ -71,13 +69,9 @@ namespace ComSquare::Debugger uint16_t read(uint8_t addr); //! @brief Focus the debugger's window. void focus(); - //! @brief Return true if the Bus is overloaded with debugging features. - bool isDebugger(); //! @brief Update the text fields with corresponding tile info void updateInfoTile(int row, int column); //! @brief Update call updateInfoTile with the correct address void tileClicked(const QModelIndex &index); }; } - -#endif //COMSQUARE_CGRAMDEBUG_HPP diff --git a/sources/Debugger/TileViewer/RAMTileRenderer.cpp b/sources/Debugger/TileViewer/RAMTileRenderer.cpp index 18c79ea..015ccca 100644 --- a/sources/Debugger/TileViewer/RAMTileRenderer.cpp +++ b/sources/Debugger/TileViewer/RAMTileRenderer.cpp @@ -2,30 +2,21 @@ // Created by cbihan on 24/05/2021. // -#include #include #include "RAMTileRenderer.hpp" -#include "PPU/PPU.hpp" #include "PPU/Tile.hpp" -#include namespace ComSquare::Debugger { - RAMTileRenderer::RAMTileRenderer() - : _ram(nullptr), + RAMTileRenderer::RAMTileRenderer(Ram::Ram &ram, Ram::Ram &cgram) + : _ram(ram), _renderSize(0x5000), _nbColumns(16), _ramOffset(0), _bpp(2), + _tileRenderer(ram, cgram), buffer({{{0}}}) - { - } - - void RAMTileRenderer::setRam(std::shared_ptr ram) - { - this->_ram = ram; - this->_tileRenderer.setRam(ram); - } + {} void RAMTileRenderer::render() { @@ -35,7 +26,7 @@ namespace ComSquare::Debugger int resetX = bufX; for (auto &i : this->buffer) i.fill(0); - uint24_t limit = fmin(this->_ram->getSize(), this->_renderSize) + this->_ramOffset; + uint24_t limit = std::fmin(this->_ram.getSize(), this->_renderSize) + this->_ramOffset; for (uint24_t i = this->_ramOffset; i < limit; i += PPU::Tile::BaseByteSize * this->_bpp, nbTilesDrawn++) { if (bufX > 1024 || bufY > 1024) @@ -75,11 +66,6 @@ namespace ComSquare::Debugger this->_tileRenderer.setBpp(bpp); } - void RAMTileRenderer::setCgram(std::shared_ptr ram) - { - this->_tileRenderer.setCgram(ram); - } - void RAMTileRenderer::setRenderSize(int size) { this->_renderSize = size; diff --git a/sources/Debugger/TileViewer/RAMTileRenderer.hpp b/sources/Debugger/TileViewer/RAMTileRenderer.hpp index 8c4eeb0..7370fe3 100644 --- a/sources/Debugger/TileViewer/RAMTileRenderer.hpp +++ b/sources/Debugger/TileViewer/RAMTileRenderer.hpp @@ -10,10 +10,11 @@ namespace ComSquare::Debugger { - class RAMTileRenderer { + class RAMTileRenderer + { private: //! @brief ram to render - std::shared_ptr _ram; + Ram::Ram &_ram; //! @brief The size to render in the ram int _renderSize; //! @brief The number of tile columns to display @@ -29,34 +30,31 @@ namespace ComSquare::Debugger std::array, 1024> buffer; //! @brief Set the palette to use for render (index of palette) void setPaletteIndex(int paletteIndex); - //! @brief Set the ram to look for color references - void setCgram(std::shared_ptr ram); //! @brief Set the bpp to render graphics void setBpp(int bpp); //! @brief Set the number of maximum columns void setNbColumns(int nbColumns); //! @brief Set the size of ram to render void setRenderSize(int size); - //! @brief The ram to render - void setRam(std::shared_ptr ram); //! @brief Set the ram offset void setRamOffset(int offset); //! @brief Get the current bpp - int getBpp() const; + [[nodiscard]] int getBpp() const; //! @brief Get the index of the current palette used - int getPaletteIndex() const; + [[nodiscard]] int getPaletteIndex() const; //! @brief Get the numbr of maximum tile columns to render - int getNbColumns() const; + [[nodiscard]] int getNbColumns() const; //! @brief render the selected ram void render(); + //! @brief ctor - RAMTileRenderer(); + RAMTileRenderer(Ram::Ram &ram, Ram::Ram &cgram); //! @brief copy ctor RAMTileRenderer(const RAMTileRenderer &) = default; //! @brief dtor ~RAMTileRenderer() = default; - //! @brief assignment operator - RAMTileRenderer &operator=(const RAMTileRenderer &) = default; + //! @brief A RAMTileRender is not assignable. + RAMTileRenderer &operator=(const RAMTileRenderer &) = delete; }; } diff --git a/sources/Debugger/TileViewer/TileViewer.cpp b/sources/Debugger/TileViewer/TileViewer.cpp index 38c08e6..d622b1d 100644 --- a/sources/Debugger/TileViewer/TileViewer.cpp +++ b/sources/Debugger/TileViewer/TileViewer.cpp @@ -2,10 +2,6 @@ // Created by cbihan on 5/7/21. // -namespace ComSquare::Renderer -{ - class QtFullSFML; -} #include "Renderer/QtRenderer/QtSFML.hpp" #include "TileViewer.hpp" @@ -13,33 +9,30 @@ namespace ComSquare::Renderer #include #include #include -#include -#include "Utility/Utility.hpp" #include "RAMTileRenderer.hpp" #include "PPU/PPU.hpp" namespace ComSquare::Debugger { TileViewer::TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu) - : _window(new ClosableWindow(*this, &TileViewer::disableViewer)), + : _window(new ClosableWindow([&snes] { snes.disableTileViewer(); })), _snes(snes), _ui(), _ppu(ppu), - _ramTileRenderer() + _ramTileRenderer(ppu.vram, ppu.cgram) { - this->_ramTileRenderer.setRam(ppu.vram); - this->_ramTileRenderer.setCgram(ppu.cgram); - this->_window->setContextMenuPolicy(Qt::NoContextMenu); - this->_window->setAttribute(Qt::WA_QuitOnClose, false); - this->_window->setAttribute(Qt::WA_DeleteOnClose); - this->_ui.setupUi(this->_window); this->_sfWidget = std::make_unique(this->_ui.widget_sfml); - QMainWindow::connect(this->_ui.NbColumns, QOverload::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setNbColumns(nb); }); - QMainWindow::connect(this->_ui.ByteSize, QOverload::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setRenderSize(nb); }); - QMainWindow::connect(this->_ui.Address, QOverload::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setRamOffset(nb); }); - QMainWindow::connect(this->_ui.PaletteIndex, QOverload::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setPaletteIndex(nb); }); - QMainWindow::connect(this->_ui.BppFormat, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int index) -> void { this->_bppChangeUIHandler(index); }); + QMainWindow::connect(this->_ui.NbColumns, QOverload::of(&QSpinBox::valueChanged), this, + [this](int nb) -> void { this->setNbColumns(nb); }); + QMainWindow::connect(this->_ui.ByteSize, QOverload::of(&QSpinBox::valueChanged), this, + [this](int nb) -> void { this->setRenderSize(nb); }); + QMainWindow::connect(this->_ui.Address, QOverload::of(&QSpinBox::valueChanged), this, + [this](int nb) -> void { this->setRamOffset(nb); }); + QMainWindow::connect(this->_ui.PaletteIndex, QOverload::of(&QSpinBox::valueChanged), this, + [this](int nb) -> void { this->setPaletteIndex(nb); }); + QMainWindow::connect(this->_ui.BppFormat, QOverload::of(&QComboBox::currentIndexChanged), this, + [this](int index) -> void { this->_bppChangeUIHandler(index); }); // used to setup ui restrictions this->setBpp(this->getBpp()); @@ -47,21 +40,11 @@ namespace ComSquare::Debugger this->internalUpdate(); } - void TileViewer::disableViewer() - { - this->_snes.disableTileViewerDebugging(); - } - void TileViewer::focus() { this->_window->activateWindow(); } - bool TileViewer::isDebugger() - { - return true; - } - uint16_t TileViewer::read(uint8_t addr) { return this->_ppu.cgramRead(addr); @@ -138,9 +121,12 @@ namespace ComSquare::Debugger void TileViewer::_bppChangeUIHandler(int index) { switch (index) { - case 0: return this->setBpp(2); - case 1: return this->setBpp(4); - case 2: return this->setBpp(8); + case 0: + return this->setBpp(2); + case 1: + return this->setBpp(4); + case 2: + return this->setBpp(8); default: throw std::runtime_error("Invalid Index"); } diff --git a/sources/Debugger/TileViewer/TileViewer.hpp b/sources/Debugger/TileViewer/TileViewer.hpp index 1848899..e8f7fd8 100644 --- a/sources/Debugger/TileViewer/TileViewer.hpp +++ b/sources/Debugger/TileViewer/TileViewer.hpp @@ -4,11 +4,6 @@ #pragma once -namespace ComSquare::PPU -{ - class PPU; -} - #include #include #include @@ -16,7 +11,7 @@ namespace ComSquare::PPU #include "PPU/PPU.hpp" #include "Debugger/ClosableWindow.hpp" #include "Renderer/QtRenderer/QtSfmlTileRenderer.hpp" -#include "../../../ui/ui_tileView.h" +#include "ui/ui_tileView.h" #include "Ram/Ram.hpp" #include "RAMTileRenderer.hpp" @@ -24,10 +19,11 @@ namespace ComSquare::Debugger { //! @brief window that allow the user to view all data going through the memory bus. - class TileViewer : public QObject { + class TileViewer : public QObject + { private: //! @brief The QT window for this debugger. - ClosableWindow *_window; + ClosableWindow *_window; //! @brief A reference to the snes (to disable the debugger). SNES &_snes; //! @brief A widget that contain the whole UI. @@ -41,8 +37,6 @@ namespace ComSquare::Debugger //! @brief Change the bpp from the index given by the ui (QT combo box) void _bppChangeUIHandler(int index); public: - //! @brief Called when the window is closed. Turn off the debugger. - void disableViewer(); //! @brief ctor explicit TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu); //! @brief copy ctor @@ -58,8 +52,6 @@ namespace ComSquare::Debugger uint16_t read(uint8_t addr); //! @brief Focus the debugger's window. void focus(); - //! @brief Return true if the Bus is overloaded with debugging features. - bool isDebugger(); //! @brief Set the palette to use for render (index of palette) void setPaletteIndex(int paletteIndex); //! @brief Set the bpp to render graphics @@ -71,13 +63,12 @@ namespace ComSquare::Debugger //! @brief Set the ram offset void setRamOffset(int offset); //! @brief Get the current bpp - int getBpp() const; + [[nodiscard]] int getBpp() const; //! @brief Get the index of the current palette used - int getPaletteIndex() const; + [[nodiscard]] int getPaletteIndex() const; //! @brief Get the numbr of maximum tile columns to render - int getNbColumns() const; + [[nodiscard]] int getNbColumns() const; //! @brief Update the tile renderer void internalUpdate(); - }; } diff --git a/sources/Ram/ExtendedRam.cpp b/sources/Ram/ExtendedRam.cpp deleted file mode 100644 index 8e75476..0000000 --- a/sources/Ram/ExtendedRam.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -// Created by anonymus-raccoon on 2/13/20. -// - -#include -#include "ExtendedRam.hpp" -#include "../Exceptions/InvalidAddress.hpp" - -namespace ComSquare::Ram -{ - ExtendedRam::ExtendedRam(size_t size) - : _size(size) - { - this->_data = new uint16_t[size]; - std::memset(this->_data, 0, size * sizeof(uint16_t)); - } - - ExtendedRam::~ExtendedRam() - { - delete [] this->_data; - } - - uint16_t ExtendedRam::read(uint24_t addr) - { - if (addr >= this->_size) - throw InvalidAddress("ExtendedRam Read", addr); - return this->_data[addr]; - } - - void ExtendedRam::write(uint24_t addr, uint16_t data) - { - if (addr >= this->_size) - throw InvalidAddress("ExtendedRam Write", addr); - this->_data[addr] = data; - } -} \ No newline at end of file diff --git a/sources/Ram/ExtendedRam.hpp b/sources/Ram/ExtendedRam.hpp deleted file mode 100644 index f726277..0000000 --- a/sources/Ram/ExtendedRam.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// Created by anonymus-raccoon on 2/13/20. -// - -#ifndef COMSQUARE_EXTENDEDRAM_HPP -#define COMSQUARE_EXTENDEDRAM_HPP - -#include -#include -#include "../Models/Int24.hpp" - -namespace ComSquare::Ram -{ - class ExtendedRam { - private: - uint16_t *_data; - size_t _size; - public: - explicit ExtendedRam(size_t size); - ExtendedRam(const ExtendedRam &) = delete; - ExtendedRam &operator=(const ExtendedRam &) = delete; - ~ExtendedRam(); - - uint16_t read(uint24_t addr); - void write(uint24_t addr, uint16_t data); - }; -} - -#endif //COMSQUARE_EXTENDEDRAM_HPP diff --git a/sources/Ram/Ram.cpp b/sources/Ram/Ram.cpp index 58a2ac6..33c1b20 100644 --- a/sources/Ram/Ram.cpp +++ b/sources/Ram/Ram.cpp @@ -27,6 +27,16 @@ namespace ComSquare::Ram delete[] this->_data; } + uint8_t &Ram::operator[](uint24_t addr) + { + return this->_data[addr]; + } + + const uint8_t &Ram::operator[](uint24_t addr) const + { + return this->_data[addr]; + } + uint8_t Ram::read(uint24_t addr) { // TODO read/write after the size of the rom should noop or behave like a mirror. I don't really know. diff --git a/sources/Ram/Ram.hpp b/sources/Ram/Ram.hpp index 9589878..96e6b10 100644 --- a/sources/Ram/Ram.hpp +++ b/sources/Ram/Ram.hpp @@ -2,15 +2,15 @@ // Created by anonymus-raccoon on 1/28/20. // -#ifndef COMSQUARE_RAM_HPP -#define COMSQUARE_RAM_HPP +#pragma once -#include "../Memory/ARectangleMemory.hpp" +#include "Memory/ARectangleMemory.hpp" #include namespace ComSquare::Ram { - class Ram : public Memory::ARectangleMemory { + class Ram : public Memory::ARectangleMemory + { protected: //! @brief The ram. (Can be used for WRam, SRam, VRam etc) uint8_t *_data; @@ -41,19 +41,26 @@ namespace ComSquare::Ram //! @throw This function should thrown an InvalidAddress for address that are not mapped to the component. void write(uint24_t addr, uint8_t data) override; + //! @brief Retrieve the data at the address given. This can be used instead of read or write. + //! @param addr The address of the data to retrieve. + //! @return The data at the address given as parameter. + uint8_t &operator[](uint24_t addr); + //! @brief Retrieve the data at the address given. This can be used instead of read or write. + //! @param addr The address of the data to retrieve. + //! @return The data at the address given as parameter. + const uint8_t &operator[](uint24_t addr) const; //! @brief Get the name of this accessor (used for debug purpose) - std::string getName() const override; + [[nodiscard]] std::string getName() const override; //! @brief Get the component of this accessor (used for debug purpose) - Component getComponent() const override; + [[nodiscard]] Component getComponent() const override; //! @brief Get the size of the ram in bytes. - uint24_t getSize() const override; + [[nodiscard]] uint24_t getSize() const override; //! @brief Get the raw data of the RAM - uint8_t *getData() const; + //! @return A raw pointer to the data. + [[nodiscard]] uint8_t *getData() const; }; -} - -#endif //COMSQUARE_RAM_HPP +} \ No newline at end of file diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index de57527..93285f9 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -100,7 +100,7 @@ namespace ComSquare::Renderer void QtFullSFML::enableCgramViewer() { -// this->_snes.enableCgramDebugging(); + this->_snes.enableCgramViewer(); } void QtFullSFML::enableRegisterViewer() @@ -110,7 +110,7 @@ namespace ComSquare::Renderer void QtFullSFML::enableTileViewer() { -// this->_snes.enableTileViewerDebugging(); + this->_snes.enableTileViewer(); } #endif diff --git a/sources/SNES.cpp b/sources/SNES.cpp index 7878f50..9d7d1ae 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -132,19 +132,19 @@ namespace ComSquare // this->bus = std::make_shared(*this->bus); // this->cpu->setMemoryBus(this->bus); // } -// -// void SNES::enableCgramDebugging() -// { -// if (this->_cgramViewer) -// this->_cgramViewer->focus(); -// else -// this->_cgramViewer.emplace(*this, *this->ppu); -// } -// -// void SNES::disableCgramDebugging() -// { -// this->_cgramViewer = std::nullopt; -// } + + void SNES::enableCgramViewer() + { + if (this->_cgramViewer) + this->_cgramViewer->focus(); + else + this->_cgramViewer.emplace(*this, this->ppu); + } + + void SNES::disableCgramViewer() + { + this->_cgramViewer = std::nullopt; + } void SNES::disableRegisterViewer() { @@ -159,18 +159,18 @@ namespace ComSquare this->_registerViewer.emplace(*this); } -// void SNES::disableTileViewerDebugging() -// { -// this->_tileViewer = std::nullopt; -// } -// -// void SNES::enableTileViewerDebugging() -// { -// if (this->_tileViewer) -// this->_tileViewer->focus(); -// else -// this->_tileViewer.emplace(*this, *this->ppu); -// } + void SNES::disableTileViewer() + { + this->_tileViewer = std::nullopt; + } + + void SNES::enableTileViewer() + { + if (this->_tileViewer) + this->_tileViewer->focus(); + else + this->_tileViewer.emplace(*this, this->ppu); + } #endif }// namespace ComSquare diff --git a/sources/SNES.hpp b/sources/SNES.hpp index f3c068f..41e5e54 100644 --- a/sources/SNES.hpp +++ b/sources/SNES.hpp @@ -18,9 +18,10 @@ //#include #include "Debugger/MemoryViewer.hpp" #include "Debugger/HeaderViewer.hpp" -//#include "Debugger/CGramDebug.hpp" +//#include "Debugger/MemoryBusDebug.hpp" +#include "Debugger/CGramDebug.hpp" #include "Debugger/RegisterViewer.hpp" -//#include "Debugger/TileViewer/TileViewer.hpp" +#include "Debugger/TileViewer/TileViewer.hpp" #endif namespace ComSquare @@ -38,11 +39,11 @@ namespace ComSquare //! @brief The window that allow the user to view the cartridge's header. std::optional _headerViewer; //! @brief The window that allow the user to view the CGRAM. -// std::optional _cgramViewer; + std::optional _cgramViewer; //! @brief The window that allow the user to view registers. std::optional _registerViewer; //! @brief The window that allow the user to view the CGRAM as tiles. -// std::optional _tileViewer; + std::optional _tileViewer; #endif public: //! @brief The memory bus that map addresses to components. @@ -107,18 +108,18 @@ namespace ComSquare // void disableMemoryBusDebugging(); // //! @brief Enable the Memory Bus's debugging window. // void enableMemoryBusDebugging(); -// //! @brief Disable the CGRAM's debugging window. -// void disableCgramDebugging(); -// //! @brief Enable the CGRAM's debugging window. -// void enableCgramDebugging(); + //! @brief Disable the CGRAM's debugging window. + void disableCgramViewer(); + //! @brief Enable the CGRAM's debugging window. + void enableCgramViewer(); //! @brief Disable the Register's debugging window. void disableRegisterViewer(); //! @brief Enable the Register's debugging window. void enableRegisterViewer(); -// //! @brief Disable the TileViewer's debugging window. -// void disableTileViewerDebugging(); -// //! @brief Enable the TileViewer's debugging window. -// void enableTileViewerDebugging(); + //! @brief Disable the TileViewer's debugging window. + void disableTileViewer(); + //! @brief Enable the TileViewer's debugging window. + void enableTileViewer(); #endif }; }// namespace ComSquare \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index 7d17ac3..63046d6 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -78,7 +78,7 @@ void parseArguments(int argc, char **argv, SNES &snes) // snes.enableMemoryBusDebugging(); // break; // case 'g': -// snes.enableCgramDebugging(); +// snes.enableCgramViewer(); // break; case 'r': snes.enableRegisterViewer();