diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp index 85573df..e932e21 100644 --- a/sources/CPU/CPU.cpp +++ b/sources/CPU/CPU.cpp @@ -209,6 +209,8 @@ namespace ComSquare::CPU unsigned CPU::update(unsigned maxCycles) { + if (this->isDisabled) + return 0xFF; unsigned cycles = this->runDMA(maxCycles); while (cycles < maxCycles) { @@ -221,6 +223,8 @@ namespace ComSquare::CPU if (!this->_isWaitingForInterrupt) cycles += this->executeInstruction(); + else + return 0xFF; } return cycles; } diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index dd0dd9c..1ca1a4a 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -647,6 +647,9 @@ namespace ComSquare::CPU //! @brief Is an abort requested bool IsAbortRequested = false; + //! @brief True if you want to disable updates of this CPU. + bool isDisabled = false; + #ifdef DEBUGGER_ENABLED friend Debugger::CPU::CPUDebug; friend Debugger::RegisterViewer; diff --git a/sources/Debugger/CPU/CPUDebug.cpp b/sources/Debugger/CPU/CPUDebug.cpp index 018f814..cf017ae 100644 --- a/sources/Debugger/CPU/CPUDebug.cpp +++ b/sources/Debugger/CPU/CPUDebug.cpp @@ -62,7 +62,7 @@ namespace ComSquare::Debugger::CPU this->_updateRegistersPanel(); this->_updateDisassembly(this->_cpu._registers.pac, 0); - this->_cpu._isStopped = true; + this->_cpu.isDisabled = true; this->_callback = this->_cpu.onReset.addCallback([this] { this->disassembled.clear(); this->_updateDisassembly(0xFFFF - this->_cpu._cartridgeHeader.emulationInterrupts.reset); @@ -78,7 +78,7 @@ namespace ComSquare::Debugger::CPU CPUDebug::~CPUDebug() { this->_cpu.onReset.removeCallback(this->_callback); - this->_cpu._isStopped = false; + this->_cpu.isDisabled = false; } unsigned CPUDebug::update() diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index af8d550..1e56176 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "Models/Logger.hpp" #include "SNES.hpp" #include "QtSFML.hpp" @@ -68,6 +70,14 @@ namespace ComSquare::Renderer } } + void QtFullSFML::openRom() + { + auto rom = QFileDialog::getOpenFileName(nullptr, tr("Open a ROM"), QDir::homePath(), + tr("Rom files (*.sfc, *.smc);;Audio rom files (*.spc);;All files (*)")); + if (!rom.isEmpty()) + this->_snes.loadRom(rom.toStdString()); + } + void QtFullSFML::reset() { this->_snes.cpu.RESB(); @@ -129,8 +139,9 @@ namespace ComSquare::Renderer this->_window.setCentralWidget(this->_sfWidget); QMenu *file = this->_window.menuBar()->addMenu("&File"); - //TODO implement rom opening from this menu. - (void)file; + auto *open = new QAction("Open", &this->_window); + QMainWindow::connect(open, &QAction::triggered, this->_sfWidget, &QtFullSFML::openRom); + file->addAction(open); QMenu *game = this->_window.menuBar()->addMenu("&Game"); auto *reset = new QAction("Reset", &this->_window); diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp index f697d4d..7193450 100644 --- a/sources/Renderer/QtRenderer/QtSFML.hpp +++ b/sources/Renderer/QtRenderer/QtSFML.hpp @@ -22,6 +22,9 @@ namespace ComSquare::Renderer SNES &_snes; void onUpdate() override; public: + //! @brief Open the select rom dialog and load a new one if the option is selected. + void openRom(); + #ifdef DEBUGGER_ENABLED //! @brief Action called when clicking on the enable CPU debugger button. void enableDebugCPU(); diff --git a/sources/SNES.cpp b/sources/SNES.cpp index f4a8dc5..7f75592 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -47,6 +47,8 @@ namespace ComSquare { this->cartridge.loadRom(path); this->bus.mapComponents(*this); + this->cpu.RESB(); + this->apu.reset(); if (this->cartridge.getType() == Cartridge::Audio) this->apu.loadFromSPC(this->cartridge); } diff --git a/sources/main.cpp b/sources/main.cpp index 63046d6..db4514c 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -65,21 +65,21 @@ void parseArguments(int argc, char **argv, SNES &snes) case 'c': snes.enableCPUDebugging(); break; -// case 'a': -// snes.enableAPUDebugging(); -// break; + case 'a': + snes.enableAPUDebugging(); + break; case 'm': snes.enableRamViewer(); break; case 'H': snes.enableHeaderViewer(); break; -// case 'b': -// snes.enableMemoryBusDebugging(); -// break; -// case 'g': -// snes.enableCgramViewer(); -// break; + case 'b': + snes.enableMemoryBusDebugging(); + break; + case 'g': + snes.enableCgramViewer(); + break; case 'r': snes.enableRegisterViewer(); break;