From 16eb04ba5def828994a814640f22434ac65160e4 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 6 Jul 2021 23:24:45 +0200 Subject: [PATCH] Fixing the APUs deebugger --- sources/APU/APU.cpp | 3 +++ sources/APU/APU.hpp | 3 +++ sources/Debugger/APUDebug.cpp | 23 ++++++++++++++++++----- sources/Debugger/APUDebug.hpp | 9 ++++++--- sources/Debugger/CPU/CPUDebug.cpp | 3 +++ sources/Renderer/QtRenderer/QtSFML.cpp | 2 +- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp index af703df..0653979 100644 --- a/sources/APU/APU.cpp +++ b/sources/APU/APU.cpp @@ -798,6 +798,9 @@ namespace ComSquare::APU void APU::update(unsigned cycles) { + if (this->isDisabled) + return; + unsigned total = 0; if (this->_paddingCycles > cycles) { diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp index b9a3576..913e742 100644 --- a/sources/APU/APU.hpp +++ b/sources/APU/APU.hpp @@ -370,6 +370,9 @@ namespace ComSquare::APU APU &operator=(const APU &) = delete; ~APU() override = default; + //! @brief Is this APU disabled? + bool isDisabled = false; + //! @brief Read from the APU ram. //! @param addr The address to read from. The address 0x0000 should refer to the first byte of the register. //! @throw InvalidAddress will be thrown if the address is more than $FFFF (the number of register). diff --git a/sources/Debugger/APUDebug.cpp b/sources/Debugger/APUDebug.cpp index 27f94bd..0d68bfe 100644 --- a/sources/Debugger/APUDebug.cpp +++ b/sources/Debugger/APUDebug.cpp @@ -12,6 +12,7 @@ namespace ComSquare::Debugger::APU { APUDebug::APUDebug(ComSquare::APU::APU &apu, SNES &snes) : _window(new ClosableWindow([&snes] { snes.disableAPUDebugging(); })), + _timer(), _ui(), _apu(apu) { @@ -25,6 +26,17 @@ namespace ComSquare::Debugger::APU this->_ui.logger->setShowGrid(false); this->_window->show(); this->_updatePanel(); + + this->_timer.setInterval(1000 / 60); + this->_timer.setSingleShot(false); + connect(&_timer, SIGNAL(timeout()), this, SLOT(update())); + this->_timer.start(); + this->_apu.isDisabled = true; + } + + APUDebug::~APUDebug() + { + this->_apu.isDisabled = false; } void APUDebug::_updatePanel() @@ -369,17 +381,15 @@ namespace ComSquare::Debugger::APU return this->_instructions[opcode]; } - void APUDebug::update(unsigned maxCycles) + void APUDebug::update() { - unsigned cycles = 0; - try { if (this->_isPaused) { this->_apu._dsp.update(); return; } - while (cycles < maxCycles) { - cycles += this->_apu._executeInstruction(); + for (int i = 0; i < 0xFF; i++) { + this->_apu._executeInstruction(); this->_updatePanel(); this->_updateLogger(); if (this->_isStepping) { @@ -391,6 +401,9 @@ namespace ComSquare::Debugger::APU this->_apu._dsp.update(); } catch (const InvalidOpcode &e) { this->pause(); + } catch (const std::exception &e) { + std::cerr << "An error occurred: " << e.what() << std::endl; + QApplication::quit(); } } diff --git a/sources/Debugger/APUDebug.hpp b/sources/Debugger/APUDebug.hpp index 8007af2..71ed444 100644 --- a/sources/Debugger/APUDebug.hpp +++ b/sources/Debugger/APUDebug.hpp @@ -6,6 +6,7 @@ #include "ClosableWindow.hpp" #include "ui/ui_apuView.h" +#include namespace ComSquare { @@ -319,6 +320,8 @@ namespace ComSquare //! @brief The QT window for this debugger. ClosableWindow *_window; + //! @brief Internal timer used for update intervals. + QTimer _timer; //! @brief A widget that contain the whole UI. Ui::APUView _ui; @@ -348,14 +351,14 @@ namespace ComSquare void pause(); //! @brief Step - Execute a single instruction. void step(); - //! @brief Override the apu's update to disable debugging. - void update(unsigned cycles); + //! @brief Update the debugger and the underlying APU. + void update(); public: //! @brief Convert a basic APU to a debugging APU. explicit APUDebug(ComSquare::APU::APU &apu, SNES &snes); APUDebug(const APUDebug &) = delete; APUDebug &operator=(const APUDebug &) = delete; - ~APUDebug() override = default; + ~APUDebug() override; //! @brief Focus the debugger's window. void focus(); diff --git a/sources/Debugger/CPU/CPUDebug.cpp b/sources/Debugger/CPU/CPUDebug.cpp index 1a5aad7..3fe1b6d 100644 --- a/sources/Debugger/CPU/CPUDebug.cpp +++ b/sources/Debugger/CPU/CPUDebug.cpp @@ -116,6 +116,9 @@ namespace ComSquare::Debugger::CPU this->pause(true); CPUDebug::showError(e); return 0xFF; + } catch (const std::exception &e) { + std::cerr << "An error occurred: " << e.what() << std::endl; + QApplication::quit(); } } diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 1e56176..d0a2c2b 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -64,7 +64,7 @@ namespace ComSquare::Renderer this->_snes.enableCPUDebuggingWithError(e); } #endif - catch (std::exception &e) { + catch (const std::exception &e) { std::cerr << "An error occurred: " << e.what() << std::endl; QApplication::quit(); }