diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e3bd76..bbb0d09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,15 +123,15 @@ add_executable(ComSquare sources/CPU/Instructions/InternalInstruction.cpp sources/Ram/ExtendedRam.cpp sources/Ram/ExtendedRam.hpp - sources/Debugger/DebugCpu.cpp - sources/Debugger/DebugCpu.hpp + sources/Debugger/CPUDebug.cpp + sources/Debugger/CPUDebug.hpp sources/Renderer/QtRenderer/QtSFML.cpp sources/Renderer/QtRenderer/QtSFML.hpp sources/Renderer/QtRenderer/QtWidgetSFML.cpp sources/Renderer/QtRenderer/QtWidgetSFML.hpp ui/cpu.ui resources/appResources.qrc - sources/Utility/Utility.hpp) + sources/Utility/Utility.hpp sources/Debugger/RamViewer.cpp sources/Debugger/RamViewer.hpp) target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED) diff --git a/sources/Debugger/DebugCpu.cpp b/sources/Debugger/CPUDebug.cpp similarity index 99% rename from sources/Debugger/DebugCpu.cpp rename to sources/Debugger/CPUDebug.cpp index 77f6784..873e53b 100644 --- a/sources/Debugger/DebugCpu.cpp +++ b/sources/Debugger/CPUDebug.cpp @@ -2,7 +2,7 @@ // Created by anonymus-raccoon on 2/14/20. // -#include "DebugCpu.hpp" +#include "CPUDebug.hpp" #include "../Utility/Utility.hpp" using namespace ComSquare::CPU; diff --git a/sources/Debugger/DebugCpu.hpp b/sources/Debugger/CPUDebug.hpp similarity index 93% rename from sources/Debugger/DebugCpu.hpp rename to sources/Debugger/CPUDebug.hpp index 823505f..e118495 100644 --- a/sources/Debugger/DebugCpu.hpp +++ b/sources/Debugger/CPUDebug.hpp @@ -2,8 +2,8 @@ // Created by anonymus-raccoon on 2/14/20. // -#ifndef COMSQUARE_DEBUGCPU_HPP -#define COMSQUARE_DEBUGCPU_HPP +#ifndef COMSQUARE_CPUDEBUG_HPP +#define COMSQUARE_CPUDEBUG_HPP #include "../CPU/CPU.hpp" #include "../Renderer/SFRenderer.hpp" @@ -43,11 +43,11 @@ namespace ComSquare::Debugger explicit CPUDebug(ComSquare::CPU::CPU &cpu, SNES &snes); CPUDebug(const CPUDebug &) = delete; CPUDebug &operator=(const CPUDebug &) = delete; - ~CPUDebug() = default; + ~CPUDebug() override = default; //! @brief Override the basic cpu's update to allow pausing of the CPU only. unsigned update() override; }; } -#endif //COMSQUARE_DEBUGCPU_HPP +#endif //COMSQUARE_CPUDEBUG_HPP diff --git a/sources/Debugger/RamViewer.cpp b/sources/Debugger/RamViewer.cpp new file mode 100644 index 0000000..6ead5b6 --- /dev/null +++ b/sources/Debugger/RamViewer.cpp @@ -0,0 +1,19 @@ +// +// 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(); + } +} \ No newline at end of file diff --git a/sources/Debugger/RamViewer.hpp b/sources/Debugger/RamViewer.hpp new file mode 100644 index 0000000..eaac6aa --- /dev/null +++ b/sources/Debugger/RamViewer.hpp @@ -0,0 +1,30 @@ +// +// Created by anonymus-raccoon on 2/17/20. +// + +#ifndef COMSQUARE_RAMVIEWER_HPP +#define COMSQUARE_RAMVIEWER_HPP + +#include + +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 diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 1ee8b0f..9f6ca27 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -43,6 +43,10 @@ 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); + ramViewer->setShortcut(Qt::Key_F2); + QMainWindow::connect(ramViewer, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableRamViewer); + debugger->addAction(ramViewer); this->_window.show(); } @@ -78,4 +82,9 @@ namespace ComSquare::Renderer { this->_snes.cpu->RESB(); } + + void QtFullSFML::enableRamViewer() + { + this->_snes.enableRamViewer(); + } } \ No newline at end of file diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp index d8b56e8..cdec362 100644 --- a/sources/Renderer/QtRenderer/QtSFML.hpp +++ b/sources/Renderer/QtRenderer/QtSFML.hpp @@ -23,8 +23,10 @@ namespace ComSquare::Renderer SNES &_snes; void _onUpdate() override; public: - //! @brief Action called when clicking on the enable CPU button. + //! @brief Action called when clicking on the enable CPU debugger button. void enableDebugCPU(); + //! @brief Action called when clicking on the enable Ram viewer button. + void enableRamViewer(); //! @brief Action called when clicking on the reset button. void reset(); QtFullSFML(SNES &snes, QWidget* parent, const QPoint& position, const QSize& size, int frameRate = 0); diff --git a/sources/SNES.cpp b/sources/SNES.cpp index 2070e26..9a0983e 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -6,7 +6,7 @@ #include #include "SNES.hpp" #ifdef DEBUGGER_ENABLED - #include "Debugger/DebugCpu.hpp" + #include "Debugger/CPUDebug.hpp" #endif namespace ComSquare @@ -36,6 +36,20 @@ namespace ComSquare this->cpu = std::make_shared(*this->cpu); } + void SNES::enableRamViewer() + { + #ifdef DEBUGGER_ENABLED + this->_ramViewer = std::make_shared(*this); + #endif + } + + void SNES::disableRamDebugging() + { + #ifdef DEBUGGER_ENABLED + this->_ramViewer = nullptr; + #endif + } + void SNES::update() { try { diff --git a/sources/SNES.hpp b/sources/SNES.hpp index 2348f8b..7364b81 100644 --- a/sources/SNES.hpp +++ b/sources/SNES.hpp @@ -12,11 +12,18 @@ #include "PPU/PPU.hpp" #include "APU/APU.hpp" #include "Renderer/IRenderer.hpp" +#ifdef DEBUGGER_ENABLED +#include "Debugger/RamViewer.hpp" +#endif namespace ComSquare { //! @brief Container of all the components of the SNES. class SNES { +#ifdef DEBUGGER_ENABLED + private: + std::shared_ptr _ramViewer; +#endif public: //! @brief Cartridge containing instructions (ROM). std::shared_ptr cartridge; @@ -38,6 +45,10 @@ namespace ComSquare void disableCPUDebugging(); //! @brief Enable the CPU's debugging window. void enableCPUDebugging(); + //! @brief Disable the Ram's debugging window. + void disableRamDebugging(); + //! @brief Enable the Ram's debugging window. + void enableRamViewer(); //! @brief Create all the components using a common memory bus for all of them. SNES(const std::shared_ptr &bus, const std::string &ramPath, Renderer::IRenderer &renderer);