From 618c708df628c91ca619e90903ef39c0c59d99f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Sat, 28 Mar 2020 14:52:42 +0100 Subject: [PATCH] adding the window of the cgram debugger (-g to activate) --- sources/Debugger/cgramDebug.cpp | 20 +++++++++--------- sources/Debugger/cgramDebug.hpp | 37 +++++++++++++++++++++++++++++++++ sources/SNES.cpp | 30 ++++++++++---------------- sources/SNES.hpp | 3 +++ sources/main.cpp | 6 +++++- 5 files changed, 66 insertions(+), 30 deletions(-) diff --git a/sources/Debugger/cgramDebug.cpp b/sources/Debugger/cgramDebug.cpp index 8733de5..835fc1e 100644 --- a/sources/Debugger/cgramDebug.cpp +++ b/sources/Debugger/cgramDebug.cpp @@ -22,13 +22,7 @@ namespace ComSquare::Debugger this->_window->setAttribute(Qt::WA_QuitOnClose, false); this->_window->setAttribute(Qt::WA_DeleteOnClose); - /*this->_ui.setupUi(this->_window); - this->_ui.log->setModel(&this->_model); - this->_ui.log->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - //this->_ui.log->horizontalHeader()->setStretchLastSection(true); - this->_ui.log->horizontalHeader()->setSectionsMovable(false); - for (int i = 0; i < this->_model.column; i++) - this->_ui.log->setColumnWidth(i, this->_ui.log->width());*/ + this->_ui.setupUi(this->_window); this->_window->show(); } @@ -68,8 +62,14 @@ QVariant cgramModel::data(const QModelIndex &index, int role) const { if (role == Qt::TextAlignmentRole) return Qt::AlignCenter; - if (role != Qt::DisplayRole) - return QVariant(); if (role == Qt::BackgroundRole) return 1; -} \ No newline at end of file + this->_ppu.cgramRead(0); + if (role != Qt::DisplayRole) + return QVariant(); +} + +void cgramModel::ppu(const ComSquare::PPU::PPU &ppu) +{ + this->_ppu = ppu; +} diff --git a/sources/Debugger/cgramDebug.hpp b/sources/Debugger/cgramDebug.hpp index a41e5f2..e3f342c 100644 --- a/sources/Debugger/cgramDebug.hpp +++ b/sources/Debugger/cgramDebug.hpp @@ -11,6 +11,38 @@ #include #include "ClosableWindow.hpp" + +/*namespace ComSquare +{ + class SNES; + namespace Debugger + { + //! @brief Window that show the header of the currently running game. + class cgramViewer { + private: + //! @brief The QT window for this debugger. + ClosableWindow *_window{}; + //! @brief A reference to the snes (to disable the debugger). + SNES &_snes; + //! @brief The layout of the viewer. + Ui::CgramView _ui; + //! @brief The ppu containing the cgram. + ComSquare::PPU::PPU &_ppu; + public slots: + //! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU. + void disableDebugger(); + public: + //! @brief Focus the debugger's window. + void focus(); + + explicit cgramViewer(SNES &snes, ComSquare::PPU::PPU &ppu); + cgramViewer(const cgramViewer &) = delete; + cgramViewer &operator=(const cgramViewer &) = delete; + ~cgramViewer() = default; + }; + } +}*/ + /*namespace ComSquare::cgramDebugger { //! @brief The struct used to represent memory bus logs. @@ -30,6 +62,9 @@ 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; @@ -40,6 +75,8 @@ public: const cgramModel &operator=(const cgramModel &) = delete; ~cgramModel() override = default; + //! @brief set the reference to the ppu + void ppu(const ComSquare::PPU::PPU &ppu); //! @brief The number of row the table has. int rowCount(const QModelIndex &parent) const override; //! @brief The number of column the table has. diff --git a/sources/SNES.cpp b/sources/SNES.cpp index 2547b8f..bdeac42 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -130,26 +130,18 @@ namespace ComSquare void SNES::enableCgramDebugging() { - #ifdef DEBUGGER_ENABLED - if (this->_bus->isDebugger()) - std::static_pointer_cast(this->_bus)->focus(); + #ifdef DEBUGGER_ENABLED + if (this->_cgramViewer) + this->_cgramViewer->focus(); else - { - this->_bus = std::make_shared(*this, *this->_bus); - this->cpu->setMemoryBus(this->_bus); - } - #else - std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl; - #endif - } + this->_cgramViewer = std::make_unique(*this, *this->ppu); + #endif + } - void SNES::disableCgramDebugging() - { - #ifdef DEBUGGER_ENABLED - this->_bus = std::make_shared(*this->_bus); - this->cpu->setMemoryBus(this->_bus); - #else - std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl; - #endif + void SNES::disableCgramDebugging() + { + #ifdef DEBUGGER_ENABLED + this->_cgramViewer = nullptr; + #endif } } diff --git a/sources/SNES.hpp b/sources/SNES.hpp index 893ec3e..825367a 100644 --- a/sources/SNES.hpp +++ b/sources/SNES.hpp @@ -15,6 +15,7 @@ #ifdef DEBUGGER_ENABLED #include "Debugger/MemoryViewer.hpp" #include "Debugger/HeaderViewer.hpp" +#include "Debugger/cgramDebug.hpp" #endif @@ -28,6 +29,8 @@ namespace ComSquare std::unique_ptr _ramViewer; //! @brief The window that allow the user to view the cartridge's header. std::unique_ptr _headerViewer; + //! @brief The window that allow the user to view the CGRAM. + std::unique_ptr _cgramViewer; #endif //! @brief The memory bus that map addresses to components. std::shared_ptr _bus; diff --git a/sources/main.cpp b/sources/main.cpp index f01c0c2..3a4ba82 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -32,10 +32,11 @@ void parseArguments(int argc, char **argv, SNES &snes) {"memory", no_argument, 0, 'm'}, {"header", no_argument, 0, 'h'}, {"bus", no_argument, 0, 'b'}, + {"cgram", no_argument, 0, 'g'}, {0, 0, 0, 0} }; - int c = getopt_long(argc, argv, "camhb", long_options, &option_index); + int c = getopt_long(argc, argv, "camhbg", long_options, &option_index); if (c == -1) break; switch (c) { @@ -57,6 +58,9 @@ void parseArguments(int argc, char **argv, SNES &snes) case 'b': snes.enableMemoryBusDebugging(); break; + case 'g': + snes.enableCgramDebugging(); + break; default: break; }