diff --git a/CMakeLists.txt b/CMakeLists.txt index d2f7462..2a26978 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,11 @@ add_executable(unit_tests tests/testRectangleMemory.cpp tests/CPU/Math/testCMP.cpp sources/PPU/Backgrounds.cpp - sources/PPU/Background.cpp sources/PPU/Background.hpp sources/CPU/DMA/DMA.cpp sources/CPU/DMA/DMA.hpp) + sources/PPU/Background.cpp + sources/PPU/Background.hpp + sources/CPU/DMA/DMA.cpp + sources/CPU/DMA/DMA.hpp +) # include criterion & coverage target_link_libraries(unit_tests criterion -lgcov) @@ -169,7 +173,7 @@ add_executable(ComSquare sources/Renderer/QtRenderer/QtSFML.hpp sources/Renderer/QtRenderer/QtWidgetSFML.cpp sources/Renderer/QtRenderer/QtWidgetSFML.hpp - ui/cpu.ui + ui/cpuView.ui ui/ramView.ui ui/cartridgeView.ui ui/apuView.ui @@ -215,7 +219,14 @@ add_executable(ComSquare sources/Debugger/CGramDebug.hpp sources/Models/Vector2.hpp sources/PPU/Backgrounds.cpp - sources/PPU/Background.cpp sources/PPU/Background.hpp sources/CPU/DMA/DMA.cpp sources/CPU/DMA/DMA.hpp) + sources/PPU/Background.cpp + sources/PPU/Background.hpp + sources/CPU/DMA/DMA.cpp + sources/CPU/DMA/DMA.hpp + sources/Debugger/CPU/DMA/DMADebug.cpp + sources/Debugger/CPU/DMA/DMADebug.hpp + ui/dmaView.ui +) target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED) diff --git a/sources/Debugger/CPU/CPUDebug.hpp b/sources/Debugger/CPU/CPUDebug.hpp index db00d37..69d3e0e 100644 --- a/sources/Debugger/CPU/CPUDebug.hpp +++ b/sources/Debugger/CPU/CPUDebug.hpp @@ -9,7 +9,7 @@ #include "../../CPU/CPU.hpp" #include "../../Renderer/SFRenderer.hpp" #include "../../SNES.hpp" -#include "../../../ui/ui_cpu.h" +#include "../../../ui/ui_cpuView.h" #include "../ClosableWindow.hpp" namespace ComSquare::Debugger diff --git a/sources/Debugger/CPU/DMA/DMADebug.cpp b/sources/Debugger/CPU/DMA/DMADebug.cpp new file mode 100644 index 0000000..4222c97 --- /dev/null +++ b/sources/Debugger/CPU/DMA/DMADebug.cpp @@ -0,0 +1,32 @@ +// +// Created by anonymus-raccoon on 5/28/20. +// + +#include "DMADebug.hpp" +#include "../../../SNES.hpp" + +namespace ComSquare::Debugger +{ + DMADebug::DMADebug(SNES &snes) + : _window(new ClosableWindow(*this, &DMADebug::disableDebugger)), + _ui(), + _snes(snes) + { + this->_window->setContextMenuPolicy(Qt::NoContextMenu); + this->_window->setAttribute(Qt::WA_QuitOnClose, false); + this->_window->setAttribute(Qt::WA_DeleteOnClose); + + this->_ui.setupUi(this->_window); + this->_window->show(); + } + + void DMADebug::focus() + { + this->_window->activateWindow(); + } + + void DMADebug::disableDebugger() + { + this->_snes.disableDMADebugging(); + } +} \ No newline at end of file diff --git a/sources/Debugger/CPU/DMA/DMADebug.hpp b/sources/Debugger/CPU/DMA/DMADebug.hpp new file mode 100644 index 0000000..6bf2aa0 --- /dev/null +++ b/sources/Debugger/CPU/DMA/DMADebug.hpp @@ -0,0 +1,43 @@ +// +// Created by anonymus-raccoon on 5/28/20. +// + +#ifndef COMSQUARE_DMADEBUG_HPP +#define COMSQUARE_DMADEBUG_HPP + +#include +#include "../../ClosableWindow.hpp" +#include "../../../../ui/ui_dmaView.h" + +namespace ComSquare +{ + class SNES; + + namespace Debugger + { + class DMADebug : public QObject { + private: + //! @brief The QT window for this debugger. + ClosableWindow *_window; + //! @brief A widget that contain the whole UI. + Ui::DMAView _ui; + + //! @brief The snes instance to read/write to DMA channels. + SNES &_snes; + public: + //! @brief Called when the window is closed. Turn off the debugger. + void disableDebugger(); + + explicit DMADebug(SNES &snes); + DMADebug( + const DMADebug &) = delete; + DMADebug &operator=(const DMADebug &) = delete; + ~DMADebug() =default; + + //! @brief Focus the debugger's window. + void focus(); + }; + }; +} + +#endif //COMSQUARE_DMADEBUG_HPP diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 760bfd8..8c234a4 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -41,32 +41,44 @@ namespace ComSquare::Renderer QMainWindow::connect(reset, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::reset); game->addAction(reset); + + QMenu *debugger = this->_window.menuBar()->addMenu("&Debugger"); QAction *cpuDebugger = new QAction("CPU's Debugger", &this->_window); cpuDebugger->setShortcut(Qt::Key_F1); QMainWindow::connect(cpuDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugCPU); debugger->addAction(cpuDebugger); + 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); + QAction *headerViewer = new QAction("Header viewer", &this->_window); headerViewer->setShortcut(Qt::Key_F3); QMainWindow::connect(headerViewer, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableHeaderViewer); debugger->addAction(headerViewer); + QAction *apuDebugger = new QAction("APU's Debugger", &this->_window); apuDebugger->setShortcut(Qt::Key_F4); QMainWindow::connect(apuDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugAPU); debugger->addAction(apuDebugger); + QAction *busDebugger = new QAction("Memory bus Viewer", &this->_window); busDebugger->setShortcut(Qt::Key_F5); QMainWindow::connect(busDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugBus); debugger->addAction(busDebugger); + QAction *cgramDebugger = new QAction("Palette Viewer", &this->_window); cgramDebugger->setShortcut(Qt::Key_F6); QMainWindow::connect(cgramDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableCgramViewer); debugger->addAction(cgramDebugger); + QAction *dmaDebugger = new QAction("DMA Viewer", &this->_window); + dmaDebugger->setShortcut(Qt::Key_F7); + QMainWindow::connect(dmaDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDMAViewer); + debugger->addAction(dmaDebugger); + this->_window.show(); } @@ -134,4 +146,9 @@ namespace ComSquare::Renderer { this->_snes.enableCgramDebugging(); } + + void QtFullSFML::enableDMAViewer() + { + this->_snes.enableDMADebugging(); + } } \ No newline at end of file diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp index 661422c..fc9d45a 100644 --- a/sources/Renderer/QtRenderer/QtSFML.hpp +++ b/sources/Renderer/QtRenderer/QtSFML.hpp @@ -35,8 +35,12 @@ namespace ComSquare::Renderer void enableDebugBus(); //! @brief Action called when clicking on the enable Palette viewer button. void enableCgramViewer(); + //! @brief Action called when clicking on the enable DMA viewer button. + void enableDMAViewer(); + //! @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); QtFullSFML(const QtFullSFML &) = delete; QtFullSFML &operator=(const QtFullSFML &) = delete; diff --git a/sources/SNES.cpp b/sources/SNES.cpp index 153c1e8..8ccbed3 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -153,4 +153,21 @@ namespace ComSquare this->_cgramViewer = nullptr; #endif } + + void SNES::disableDMADebugging() + { + #ifdef DEBUGGER_ENABLED + this->_dmaViewer = nullptr; + #endif + } + + void SNES::enableDMADebugging() + { + #ifdef DEBUGGER_ENABLED + if (this->_dmaViewer) + this->_dmaViewer->focus(); + else + this->_dmaViewer = std::make_unique(*this); + #endif + } } diff --git a/sources/SNES.hpp b/sources/SNES.hpp index 5babc05..3755434 100644 --- a/sources/SNES.hpp +++ b/sources/SNES.hpp @@ -16,6 +16,7 @@ #include "Debugger/MemoryViewer.hpp" #include "Debugger/HeaderViewer.hpp" #include "Debugger/CGramDebug.hpp" +#include "Debugger/CPU/DMA/DMADebug.hpp" #endif @@ -31,6 +32,8 @@ namespace ComSquare std::unique_ptr _headerViewer; //! @brief The window that allow the user to view the CGRAM. std::unique_ptr _cgramViewer; + //! @brief The window that allow the user to view the DMA's properties. + std::unique_ptr _dmaViewer; #endif //! @brief The memory bus that map addresses to components. std::shared_ptr _bus; @@ -77,6 +80,10 @@ namespace ComSquare void disableCgramDebugging(); //! @brief Enable the Cgram's debugging window. void enableCgramDebugging(); + //! @brief Disable the DMA's debugging window. + void disableDMADebugging(); + //! @brief Enable the DMA's debugging window. + void enableDMADebugging(); //! @brief Create all the components using a common memory bus for all of them. SNES(const std::string &ramPath, Renderer::IRenderer &renderer); diff --git a/ui/cpu.ui b/ui/cpuView.ui similarity index 100% rename from ui/cpu.ui rename to ui/cpuView.ui diff --git a/ui/dmaView.ui b/ui/dmaView.ui new file mode 100644 index 0000000..10f622e --- /dev/null +++ b/ui/dmaView.ui @@ -0,0 +1,125 @@ + + + DMAView + + + + 0 + 0 + 795 + 534 + + + + DMA's Debugger + + + + :/resources/Logo.png:/resources/Logo.png + + + + + + + QAbstractScrollArea::AdjustIgnored + + + 28 + + + 86 + + + 61 + + + + Channel 1 + + + + + Channel 2 + + + + + Channel 3 + + + + + Channel 4 + + + + + Channel 5 + + + + + Channel 6 + + + + + Channel 7 + + + + + Channel 8 + + + + + Mode + + + + + Fixed + + + + + Increment + + + + + Direction + + + + + Port + + + + + A Address + + + + + Count + + + + + Enabled + + + + + + + + + + + + diff --git a/ui/ui_cpu.h b/ui/ui_cpuView.h similarity index 98% rename from ui/ui_cpu.h rename to ui/ui_cpuView.h index 54b8db8..00998e3 100644 --- a/ui/ui_cpu.h +++ b/ui/ui_cpuView.h @@ -1,17 +1,13 @@ /******************************************************************************** -** Form generated from reading UI file 'cpu.ui' +** Form generated from reading UI file 'cpuView.ui' ** -<<<<<<< HEAD -** Created by: Qt User Interface Compiler version 5.13.2 -======= ** Created by: Qt User Interface Compiler version 5.14.2 ->>>>>>> 24bcafeea3896022704904815d263f69f22e5096 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ -#ifndef UI_CPU_H -#define UI_CPU_H +#ifndef UI_CPUVIEW_H +#define UI_CPUVIEW_H #include #include @@ -458,4 +454,4 @@ namespace Ui { QT_END_NAMESPACE -#endif // UI_CPU_H +#endif // UI_CPUVIEW_H