Enabling more debuggers

This commit is contained in:
Zoe Roux
2021-07-04 23:20:07 +02:00
parent 15fde029a7
commit f16815c36f
15 changed files with 186 additions and 293 deletions

View File

@@ -53,8 +53,6 @@ set(SOURCES
sources/CPU/Instructions/MathematicalOperations.cpp sources/CPU/Instructions/MathematicalOperations.cpp
sources/CPU/Instructions/MemoryInstructions.cpp sources/CPU/Instructions/MemoryInstructions.cpp
sources/CPU/Instructions/InternalInstruction.cpp sources/CPU/Instructions/InternalInstruction.cpp
sources/Ram/ExtendedRam.cpp
sources/Ram/ExtendedRam.hpp
sources/Utility/Utility.hpp sources/Utility/Utility.hpp
sources/Utility/Utility.cpp sources/Utility/Utility.cpp
sources/CPU/Instructions/BitsInstructions.cpp sources/CPU/Instructions/BitsInstructions.cpp
@@ -133,14 +131,14 @@ add_executable(comsquare
# sources/Debugger/APUDebug.cpp # sources/Debugger/APUDebug.cpp
# sources/Debugger/MemoryBusDebug.cpp # sources/Debugger/MemoryBusDebug.cpp
# sources/Debugger/MemoryBusDebug.hpp # sources/Debugger/MemoryBusDebug.hpp
# sources/Debugger/CGramDebug.cpp sources/Debugger/CGramDebug.cpp
# sources/Debugger/CGramDebug.hpp sources/Debugger/CGramDebug.hpp
sources/Debugger/RegisterViewer.cpp sources/Debugger/RegisterViewer.cpp
sources/Debugger/RegisterViewer.hpp sources/Debugger/RegisterViewer.hpp
# sources/Debugger/TileViewer/TileViewer.cpp sources/Debugger/TileViewer/TileViewer.cpp
# sources/Debugger/TileViewer/TileViewer.hpp sources/Debugger/TileViewer/TileViewer.hpp
# sources/Debugger/TileViewer/RAMTileRenderer.cpp sources/Debugger/TileViewer/RAMTileRenderer.cpp
# sources/Debugger/TileViewer/RAMTileRenderer.hpp sources/Debugger/TileViewer/RAMTileRenderer.hpp
ui/tileView.ui ui/tileView.ui
ui/registersView.ui ui/registersView.ui
ui/cpuView.ui ui/cpuView.ui

View File

@@ -3,26 +3,21 @@
// //
#include "CGramDebug.hpp" #include "CGramDebug.hpp"
#include "../SNES.hpp" #include "SNES.hpp"
#include <QColor> #include <QColor>
#include <string> #include <string>
#include <iostream>
#include <QtWidgets/QTableWidget> #include <QtWidgets/QTableWidget>
#include "../Utility/Utility.hpp" #include "Utility/Utility.hpp"
namespace ComSquare::Debugger namespace ComSquare::Debugger
{ {
CGramDebug::CGramDebug(SNES &snes, ComSquare::PPU::PPU &ppu) CGramDebug::CGramDebug(SNES &snes, ComSquare::PPU::PPU &ppu)
: _window(new ClosableWindow<CGramDebug>(*this, &CGramDebug::disableViewer)), : _window(new ClosableWindow([&snes] { snes.disableCgramViewer(); })),
_snes(snes), _snes(snes),
_ui(), _ui(),
_model(ppu), _model(ppu),
_ppu(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); this->_ui.setupUi(this->_window);
QMainWindow::connect(this->_ui.cgram_view, &QTableView::pressed, this, &CGramDebug::tileClicked); QMainWindow::connect(this->_ui.cgram_view, &QTableView::pressed, this, &CGramDebug::tileClicked);
this->_ui.cgram_view->setModel(&this->_model); this->_ui.cgram_view->setModel(&this->_model);
@@ -31,21 +26,11 @@ namespace ComSquare::Debugger
QEvent::registerEventType(); QEvent::registerEventType();
} }
void CGramDebug::disableViewer()
{
this->_snes.disableCgramDebugging();
}
void CGramDebug::focus() void CGramDebug::focus()
{ {
this->_window->activateWindow(); this->_window->activateWindow();
} }
bool CGramDebug::isDebugger()
{
return true;
}
uint16_t CGramDebug::read(uint8_t addr) uint16_t CGramDebug::read(uint8_t addr)
{ {
return this->_ppu.cgramRead(addr); return this->_ppu.cgramRead(addr);
@@ -79,42 +64,44 @@ namespace ComSquare::Debugger
return; return;
this->updateInfoTile(index.row(), index.column()); 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 int CGramModel::rowCount(const QModelIndex &) const
{ {
return this->rows; return this->rows;
} }
int CGramModel::columnCount(const QModelIndex &) const int CGramModel::columnCount(const QModelIndex &) const
{ {
return this->column; return this->column;
} }
QVariant CGramModel::data(const QModelIndex &index, int role) const QVariant CGramModel::data(const QModelIndex &index, int role) const
{ {
u_int16_t addressValue; u_int16_t addressValue;
uint8_t red; uint8_t red;
uint8_t green; uint8_t green;
uint8_t blue; uint8_t blue;
if (role == Qt::TextAlignmentRole) if (role == Qt::TextAlignmentRole)
return Qt::AlignCenter; return Qt::AlignCenter;
if (role != Qt::BackgroundRole) if (role != Qt::BackgroundRole)
return QVariant(); return QVariant();
int idDisplayTile = index.row() * 16 + index.column(); int idDisplayTile = index.row() * 16 + index.column();
uint16_t cgramAddress = idDisplayTile / 8 * 16 + (idDisplayTile % 8 * 2); uint16_t cgramAddress = idDisplayTile / 8 * 16 + (idDisplayTile % 8 * 2);
addressValue = this->_ppu.cgramRead(cgramAddress); addressValue = this->_ppu.cgramRead(cgramAddress);
addressValue += this->_ppu.cgramRead(cgramAddress + 1) << 8U; addressValue += this->_ppu.cgramRead(cgramAddress + 1) << 8U;
blue = (addressValue & 0x7D00U) >> 10U; blue = (addressValue & 0x7D00U) >> 10U;
green = (addressValue & 0x03E0U) >> 5U; green = (addressValue & 0x03E0U) >> 5U;
red = (addressValue & 0x001FU); red = (addressValue & 0x001FU);
red = red * 255U / 31U; red = red * 255U / 31U;
green = green * 255U / 31U; green = green * 255U / 31U;
blue = blue * 255U / 31U; blue = blue * 255U / 31U;
return QColor(red, green, blue); return QColor(red, green, blue);
}
} }

View File

@@ -2,52 +2,53 @@
// Created by cbihan on 3/27/20. // Created by cbihan on 3/27/20.
// //
#ifndef COMSQUARE_CGRAMDEBUG_HPP #pragma once
#define COMSQUARE_CGRAMDEBUG_HPP
#include <QtWidgets/QMainWindow> #include <QtWidgets/QMainWindow>
#include "../PPU/PPU.hpp" #include "PPU/PPU.hpp"
#include "../../ui/ui_cgramView.h" #include "ui/ui_cgramView.h"
#include <QtCore/QSortFilterProxyModel> #include <QtCore/QSortFilterProxyModel>
#include <QEvent> #include <QEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <QTableView> #include <QTableView>
#include "ClosableWindow.hpp" #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 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. //! @brief window that allow the user to view all data going through the memory bus.
class CGramDebug : public QObject { class CGramDebug : public QObject
{
private: private:
//! @brief The QT window for this debugger. //! @brief The QT window for this debugger.
ClosableWindow<CGramDebug> *_window; ClosableWindow *_window;
//! @brief A reference to the snes (to disable the debugger). //! @brief A reference to the snes (to disable the debugger).
SNES &_snes; SNES &_snes;
//! @brief A widget that contain the whole UI. //! @brief A widget that contain the whole UI.
@@ -56,14 +57,11 @@ namespace ComSquare::Debugger
CGramModel _model; CGramModel _model;
//! @brief A reference to the ppu //! @brief A reference to the ppu
ComSquare::PPU::PPU &_ppu; ComSquare::PPU::PPU &_ppu;
public:
//! @brief Called when the window is closed. Turn off the debugger.
void disableViewer();
public: public:
explicit CGramDebug(SNES &snes, ComSquare::PPU::PPU &ppu); explicit CGramDebug(SNES &snes, ComSquare::PPU::PPU &ppu);
CGramDebug(const CGramDebug &) = delete; CGramDebug(const CGramDebug &) = delete;
CGramDebug &operator=(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. //! @brief Read data at the CGRAM address send it to the debugger.
//! @param addr The address to read from. //! @param addr The address to read from.
@@ -71,13 +69,9 @@ namespace ComSquare::Debugger
uint16_t read(uint8_t addr); uint16_t read(uint8_t addr);
//! @brief Focus the debugger's window. //! @brief Focus the debugger's window.
void focus(); void focus();
//! @brief Return true if the Bus is overloaded with debugging features.
bool isDebugger();
//! @brief Update the text fields with corresponding tile info //! @brief Update the text fields with corresponding tile info
void updateInfoTile(int row, int column); void updateInfoTile(int row, int column);
//! @brief Update call updateInfoTile with the correct address //! @brief Update call updateInfoTile with the correct address
void tileClicked(const QModelIndex &index); void tileClicked(const QModelIndex &index);
}; };
} }
#endif //COMSQUARE_CGRAMDEBUG_HPP

View File

@@ -2,30 +2,21 @@
// Created by cbihan on 24/05/2021. // Created by cbihan on 24/05/2021.
// //
#include <complex>
#include <cmath> #include <cmath>
#include "RAMTileRenderer.hpp" #include "RAMTileRenderer.hpp"
#include "PPU/PPU.hpp"
#include "PPU/Tile.hpp" #include "PPU/Tile.hpp"
#include <iostream>
namespace ComSquare::Debugger namespace ComSquare::Debugger
{ {
RAMTileRenderer::RAMTileRenderer() RAMTileRenderer::RAMTileRenderer(Ram::Ram &ram, Ram::Ram &cgram)
: _ram(nullptr), : _ram(ram),
_renderSize(0x5000), _renderSize(0x5000),
_nbColumns(16), _nbColumns(16),
_ramOffset(0), _ramOffset(0),
_bpp(2), _bpp(2),
_tileRenderer(ram, cgram),
buffer({{{0}}}) buffer({{{0}}})
{ {}
}
void RAMTileRenderer::setRam(std::shared_ptr<Ram::Ram> ram)
{
this->_ram = ram;
this->_tileRenderer.setRam(ram);
}
void RAMTileRenderer::render() void RAMTileRenderer::render()
{ {
@@ -35,7 +26,7 @@ namespace ComSquare::Debugger
int resetX = bufX; int resetX = bufX;
for (auto &i : this->buffer) for (auto &i : this->buffer)
i.fill(0); 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++) { for (uint24_t i = this->_ramOffset; i < limit; i += PPU::Tile::BaseByteSize * this->_bpp, nbTilesDrawn++) {
if (bufX > 1024 || bufY > 1024) if (bufX > 1024 || bufY > 1024)
@@ -75,11 +66,6 @@ namespace ComSquare::Debugger
this->_tileRenderer.setBpp(bpp); this->_tileRenderer.setBpp(bpp);
} }
void RAMTileRenderer::setCgram(std::shared_ptr<Ram::Ram> ram)
{
this->_tileRenderer.setCgram(ram);
}
void RAMTileRenderer::setRenderSize(int size) void RAMTileRenderer::setRenderSize(int size)
{ {
this->_renderSize = size; this->_renderSize = size;

View File

@@ -10,10 +10,11 @@
namespace ComSquare::Debugger namespace ComSquare::Debugger
{ {
class RAMTileRenderer { class RAMTileRenderer
{
private: private:
//! @brief ram to render //! @brief ram to render
std::shared_ptr<Ram::Ram> _ram; Ram::Ram &_ram;
//! @brief The size to render in the ram //! @brief The size to render in the ram
int _renderSize; int _renderSize;
//! @brief The number of tile columns to display //! @brief The number of tile columns to display
@@ -29,34 +30,31 @@ namespace ComSquare::Debugger
std::array<std::array<uint32_t, 1024>, 1024> buffer; std::array<std::array<uint32_t, 1024>, 1024> buffer;
//! @brief Set the palette to use for render (index of palette) //! @brief Set the palette to use for render (index of palette)
void setPaletteIndex(int paletteIndex); void setPaletteIndex(int paletteIndex);
//! @brief Set the ram to look for color references
void setCgram(std::shared_ptr<Ram::Ram> ram);
//! @brief Set the bpp to render graphics //! @brief Set the bpp to render graphics
void setBpp(int bpp); void setBpp(int bpp);
//! @brief Set the number of maximum columns //! @brief Set the number of maximum columns
void setNbColumns(int nbColumns); void setNbColumns(int nbColumns);
//! @brief Set the size of ram to render //! @brief Set the size of ram to render
void setRenderSize(int size); void setRenderSize(int size);
//! @brief The ram to render
void setRam(std::shared_ptr<Ram::Ram> ram);
//! @brief Set the ram offset //! @brief Set the ram offset
void setRamOffset(int offset); void setRamOffset(int offset);
//! @brief Get the current bpp //! @brief Get the current bpp
int getBpp() const; [[nodiscard]] int getBpp() const;
//! @brief Get the index of the current palette used //! @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 //! @brief Get the numbr of maximum tile columns to render
int getNbColumns() const; [[nodiscard]] int getNbColumns() const;
//! @brief render the selected ram //! @brief render the selected ram
void render(); void render();
//! @brief ctor //! @brief ctor
RAMTileRenderer(); RAMTileRenderer(Ram::Ram &ram, Ram::Ram &cgram);
//! @brief copy ctor //! @brief copy ctor
RAMTileRenderer(const RAMTileRenderer &) = default; RAMTileRenderer(const RAMTileRenderer &) = default;
//! @brief dtor //! @brief dtor
~RAMTileRenderer() = default; ~RAMTileRenderer() = default;
//! @brief assignment operator //! @brief A RAMTileRender is not assignable.
RAMTileRenderer &operator=(const RAMTileRenderer &) = default; RAMTileRenderer &operator=(const RAMTileRenderer &) = delete;
}; };
} }

View File

@@ -2,10 +2,6 @@
// Created by cbihan on 5/7/21. // Created by cbihan on 5/7/21.
// //
namespace ComSquare::Renderer
{
class QtFullSFML;
}
#include "Renderer/QtRenderer/QtSFML.hpp" #include "Renderer/QtRenderer/QtSFML.hpp"
#include "TileViewer.hpp" #include "TileViewer.hpp"
@@ -13,33 +9,30 @@ namespace ComSquare::Renderer
#include <QColor> #include <QColor>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <QtWidgets/QTableWidget>
#include "Utility/Utility.hpp"
#include "RAMTileRenderer.hpp" #include "RAMTileRenderer.hpp"
#include "PPU/PPU.hpp" #include "PPU/PPU.hpp"
namespace ComSquare::Debugger namespace ComSquare::Debugger
{ {
TileViewer::TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu) TileViewer::TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu)
: _window(new ClosableWindow<TileViewer>(*this, &TileViewer::disableViewer)), : _window(new ClosableWindow([&snes] { snes.disableTileViewer(); })),
_snes(snes), _snes(snes),
_ui(), _ui(),
_ppu(ppu), _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->_ui.setupUi(this->_window);
this->_sfWidget = std::make_unique<Renderer::QtSFMLTileRenderer>(this->_ui.widget_sfml); this->_sfWidget = std::make_unique<Renderer::QtSFMLTileRenderer>(this->_ui.widget_sfml);
QMainWindow::connect(this->_ui.NbColumns, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setNbColumns(nb); }); QMainWindow::connect(this->_ui.NbColumns, QOverload<int>::of(&QSpinBox::valueChanged), this,
QMainWindow::connect(this->_ui.ByteSize, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setRenderSize(nb); }); [this](int nb) -> void { this->setNbColumns(nb); });
QMainWindow::connect(this->_ui.Address, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setRamOffset(nb); }); QMainWindow::connect(this->_ui.ByteSize, QOverload<int>::of(&QSpinBox::valueChanged), this,
QMainWindow::connect(this->_ui.PaletteIndex, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int nb) -> void { this->setPaletteIndex(nb); }); [this](int nb) -> void { this->setRenderSize(nb); });
QMainWindow::connect(this->_ui.BppFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) -> void { this->_bppChangeUIHandler(index); }); QMainWindow::connect(this->_ui.Address, QOverload<int>::of(&QSpinBox::valueChanged), this,
[this](int nb) -> void { this->setRamOffset(nb); });
QMainWindow::connect(this->_ui.PaletteIndex, QOverload<int>::of(&QSpinBox::valueChanged), this,
[this](int nb) -> void { this->setPaletteIndex(nb); });
QMainWindow::connect(this->_ui.BppFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this](int index) -> void { this->_bppChangeUIHandler(index); });
// used to setup ui restrictions // used to setup ui restrictions
this->setBpp(this->getBpp()); this->setBpp(this->getBpp());
@@ -47,21 +40,11 @@ namespace ComSquare::Debugger
this->internalUpdate(); this->internalUpdate();
} }
void TileViewer::disableViewer()
{
this->_snes.disableTileViewerDebugging();
}
void TileViewer::focus() void TileViewer::focus()
{ {
this->_window->activateWindow(); this->_window->activateWindow();
} }
bool TileViewer::isDebugger()
{
return true;
}
uint16_t TileViewer::read(uint8_t addr) uint16_t TileViewer::read(uint8_t addr)
{ {
return this->_ppu.cgramRead(addr); return this->_ppu.cgramRead(addr);
@@ -138,9 +121,12 @@ namespace ComSquare::Debugger
void TileViewer::_bppChangeUIHandler(int index) void TileViewer::_bppChangeUIHandler(int index)
{ {
switch (index) { switch (index) {
case 0: return this->setBpp(2); case 0:
case 1: return this->setBpp(4); return this->setBpp(2);
case 2: return this->setBpp(8); case 1:
return this->setBpp(4);
case 2:
return this->setBpp(8);
default: default:
throw std::runtime_error("Invalid Index"); throw std::runtime_error("Invalid Index");
} }

View File

@@ -4,11 +4,6 @@
#pragma once #pragma once
namespace ComSquare::PPU
{
class PPU;
}
#include <QtCore/QSortFilterProxyModel> #include <QtCore/QSortFilterProxyModel>
#include <QEvent> #include <QEvent>
#include <QMouseEvent> #include <QMouseEvent>
@@ -16,7 +11,7 @@ namespace ComSquare::PPU
#include "PPU/PPU.hpp" #include "PPU/PPU.hpp"
#include "Debugger/ClosableWindow.hpp" #include "Debugger/ClosableWindow.hpp"
#include "Renderer/QtRenderer/QtSfmlTileRenderer.hpp" #include "Renderer/QtRenderer/QtSfmlTileRenderer.hpp"
#include "../../../ui/ui_tileView.h" #include "ui/ui_tileView.h"
#include "Ram/Ram.hpp" #include "Ram/Ram.hpp"
#include "RAMTileRenderer.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. //! @brief window that allow the user to view all data going through the memory bus.
class TileViewer : public QObject { class TileViewer : public QObject
{
private: private:
//! @brief The QT window for this debugger. //! @brief The QT window for this debugger.
ClosableWindow<TileViewer> *_window; ClosableWindow *_window;
//! @brief A reference to the snes (to disable the debugger). //! @brief A reference to the snes (to disable the debugger).
SNES &_snes; SNES &_snes;
//! @brief A widget that contain the whole UI. //! @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) //! @brief Change the bpp from the index given by the ui (QT combo box)
void _bppChangeUIHandler(int index); void _bppChangeUIHandler(int index);
public: public:
//! @brief Called when the window is closed. Turn off the debugger.
void disableViewer();
//! @brief ctor //! @brief ctor
explicit TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu); explicit TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu);
//! @brief copy ctor //! @brief copy ctor
@@ -58,8 +52,6 @@ namespace ComSquare::Debugger
uint16_t read(uint8_t addr); uint16_t read(uint8_t addr);
//! @brief Focus the debugger's window. //! @brief Focus the debugger's window.
void focus(); 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) //! @brief Set the palette to use for render (index of palette)
void setPaletteIndex(int paletteIndex); void setPaletteIndex(int paletteIndex);
//! @brief Set the bpp to render graphics //! @brief Set the bpp to render graphics
@@ -71,13 +63,12 @@ namespace ComSquare::Debugger
//! @brief Set the ram offset //! @brief Set the ram offset
void setRamOffset(int offset); void setRamOffset(int offset);
//! @brief Get the current bpp //! @brief Get the current bpp
int getBpp() const; [[nodiscard]] int getBpp() const;
//! @brief Get the index of the current palette used //! @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 //! @brief Get the numbr of maximum tile columns to render
int getNbColumns() const; [[nodiscard]] int getNbColumns() const;
//! @brief Update the tile renderer //! @brief Update the tile renderer
void internalUpdate(); void internalUpdate();
}; };
} }

View File

@@ -1,36 +0,0 @@
//
// Created by anonymus-raccoon on 2/13/20.
//
#include <cstring>
#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;
}
}

View File

@@ -1,29 +0,0 @@
//
// Created by anonymus-raccoon on 2/13/20.
//
#ifndef COMSQUARE_EXTENDEDRAM_HPP
#define COMSQUARE_EXTENDEDRAM_HPP
#include <cstddef>
#include <cstdint>
#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

View File

@@ -27,6 +27,16 @@ namespace ComSquare::Ram
delete[] this->_data; 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) 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. // TODO read/write after the size of the rom should noop or behave like a mirror. I don't really know.

View File

@@ -2,15 +2,15 @@
// Created by anonymus-raccoon on 1/28/20. // Created by anonymus-raccoon on 1/28/20.
// //
#ifndef COMSQUARE_RAM_HPP #pragma once
#define COMSQUARE_RAM_HPP
#include "../Memory/ARectangleMemory.hpp" #include "Memory/ARectangleMemory.hpp"
#include <string> #include <string>
namespace ComSquare::Ram namespace ComSquare::Ram
{ {
class Ram : public Memory::ARectangleMemory { class Ram : public Memory::ARectangleMemory
{
protected: protected:
//! @brief The ram. (Can be used for WRam, SRam, VRam etc) //! @brief The ram. (Can be used for WRam, SRam, VRam etc)
uint8_t *_data; 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. //! @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; 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) //! @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) //! @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. //! @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 //! @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

View File

@@ -100,7 +100,7 @@ namespace ComSquare::Renderer
void QtFullSFML::enableCgramViewer() void QtFullSFML::enableCgramViewer()
{ {
// this->_snes.enableCgramDebugging(); this->_snes.enableCgramViewer();
} }
void QtFullSFML::enableRegisterViewer() void QtFullSFML::enableRegisterViewer()
@@ -110,7 +110,7 @@ namespace ComSquare::Renderer
void QtFullSFML::enableTileViewer() void QtFullSFML::enableTileViewer()
{ {
// this->_snes.enableTileViewerDebugging(); this->_snes.enableTileViewer();
} }
#endif #endif

View File

@@ -132,19 +132,19 @@ namespace ComSquare
// this->bus = std::make_shared<Memory::MemoryBus>(*this->bus); // this->bus = std::make_shared<Memory::MemoryBus>(*this->bus);
// this->cpu->setMemoryBus(this->bus); // this->cpu->setMemoryBus(this->bus);
// } // }
//
// void SNES::enableCgramDebugging() void SNES::enableCgramViewer()
// { {
// if (this->_cgramViewer) if (this->_cgramViewer)
// this->_cgramViewer->focus(); this->_cgramViewer->focus();
// else else
// this->_cgramViewer.emplace(*this, *this->ppu); this->_cgramViewer.emplace(*this, this->ppu);
// } }
//
// void SNES::disableCgramDebugging() void SNES::disableCgramViewer()
// { {
// this->_cgramViewer = std::nullopt; this->_cgramViewer = std::nullopt;
// } }
void SNES::disableRegisterViewer() void SNES::disableRegisterViewer()
{ {
@@ -159,18 +159,18 @@ namespace ComSquare
this->_registerViewer.emplace(*this); this->_registerViewer.emplace(*this);
} }
// void SNES::disableTileViewerDebugging() void SNES::disableTileViewer()
// { {
// this->_tileViewer = std::nullopt; this->_tileViewer = std::nullopt;
// } }
//
// void SNES::enableTileViewerDebugging() void SNES::enableTileViewer()
// { {
// if (this->_tileViewer) if (this->_tileViewer)
// this->_tileViewer->focus(); this->_tileViewer->focus();
// else else
// this->_tileViewer.emplace(*this, *this->ppu); this->_tileViewer.emplace(*this, this->ppu);
// } }
#endif #endif
}// namespace ComSquare }// namespace ComSquare

View File

@@ -18,9 +18,10 @@
//#include <Debugger/CPU/CPUDebug.hpp> //#include <Debugger/CPU/CPUDebug.hpp>
#include "Debugger/MemoryViewer.hpp" #include "Debugger/MemoryViewer.hpp"
#include "Debugger/HeaderViewer.hpp" #include "Debugger/HeaderViewer.hpp"
//#include "Debugger/CGramDebug.hpp" //#include "Debugger/MemoryBusDebug.hpp"
#include "Debugger/CGramDebug.hpp"
#include "Debugger/RegisterViewer.hpp" #include "Debugger/RegisterViewer.hpp"
//#include "Debugger/TileViewer/TileViewer.hpp" #include "Debugger/TileViewer/TileViewer.hpp"
#endif #endif
namespace ComSquare namespace ComSquare
@@ -38,11 +39,11 @@ namespace ComSquare
//! @brief The window that allow the user to view the cartridge's header. //! @brief The window that allow the user to view the cartridge's header.
std::optional<Debugger::HeaderViewer> _headerViewer; std::optional<Debugger::HeaderViewer> _headerViewer;
//! @brief The window that allow the user to view the CGRAM. //! @brief The window that allow the user to view the CGRAM.
// std::optional<Debugger::CGramDebug> _cgramViewer; std::optional<Debugger::CGramDebug> _cgramViewer;
//! @brief The window that allow the user to view registers. //! @brief The window that allow the user to view registers.
std::optional<Debugger::RegisterViewer> _registerViewer; std::optional<Debugger::RegisterViewer> _registerViewer;
//! @brief The window that allow the user to view the CGRAM as tiles. //! @brief The window that allow the user to view the CGRAM as tiles.
// std::optional<Debugger::TileViewer> _tileViewer; std::optional<Debugger::TileViewer> _tileViewer;
#endif #endif
public: public:
//! @brief The memory bus that map addresses to components. //! @brief The memory bus that map addresses to components.
@@ -107,18 +108,18 @@ namespace ComSquare
// void disableMemoryBusDebugging(); // void disableMemoryBusDebugging();
// //! @brief Enable the Memory Bus's debugging window. // //! @brief Enable the Memory Bus's debugging window.
// void enableMemoryBusDebugging(); // void enableMemoryBusDebugging();
// //! @brief Disable the CGRAM's debugging window. //! @brief Disable the CGRAM's debugging window.
// void disableCgramDebugging(); void disableCgramViewer();
// //! @brief Enable the CGRAM's debugging window. //! @brief Enable the CGRAM's debugging window.
// void enableCgramDebugging(); void enableCgramViewer();
//! @brief Disable the Register's debugging window. //! @brief Disable the Register's debugging window.
void disableRegisterViewer(); void disableRegisterViewer();
//! @brief Enable the Register's debugging window. //! @brief Enable the Register's debugging window.
void enableRegisterViewer(); void enableRegisterViewer();
// //! @brief Disable the TileViewer's debugging window. //! @brief Disable the TileViewer's debugging window.
// void disableTileViewerDebugging(); void disableTileViewer();
// //! @brief Enable the TileViewer's debugging window. //! @brief Enable the TileViewer's debugging window.
// void enableTileViewerDebugging(); void enableTileViewer();
#endif #endif
}; };
}// namespace ComSquare }// namespace ComSquare

View File

@@ -78,7 +78,7 @@ void parseArguments(int argc, char **argv, SNES &snes)
// snes.enableMemoryBusDebugging(); // snes.enableMemoryBusDebugging();
// break; // break;
// case 'g': // case 'g':
// snes.enableCgramDebugging(); // snes.enableCgramViewer();
// break; // break;
case 'r': case 'r':
snes.enableRegisterViewer(); snes.enableRegisterViewer();