diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp index df9e0a8..446d0b7 100644 --- a/sources/CPU/CPU.cpp +++ b/sources/CPU/CPU.cpp @@ -209,22 +209,16 @@ namespace ComSquare::CPU unsigned CPU::update(unsigned maxCycles) { - if (this->isDisabled) - return 0xFF; + if (this->isDisabled || this->_isStopped) + return 0; unsigned cycles = this->runDMA(maxCycles); - while (cycles < maxCycles) { - if (this->_isStopped) { - cycles += 1; - continue; - } - + this->_checkInterrupts(); + while (cycles < maxCycles && !this->_isWaitingForInterrupt) { this->_checkInterrupts(); - - if (!this->_isWaitingForInterrupt) - cycles += this->executeInstruction(); - else - return 0xFF; + cycles += this->executeInstruction(); + if (maxCycles > cycles) + cycles += this->runDMA(maxCycles - cycles); } return cycles; } diff --git a/sources/Debugger/CPU/CPUDebug.cpp b/sources/Debugger/CPU/CPUDebug.cpp index 6f0ed1a..68a4f31 100644 --- a/sources/Debugger/CPU/CPUDebug.cpp +++ b/sources/Debugger/CPU/CPUDebug.cpp @@ -87,10 +87,10 @@ namespace ComSquare::Debugger::CPU unsigned CPUDebug::update() { try { - unsigned cycles = this->_cpu.runDMA(INT_MAX); + unsigned cycles = 0; - if (this->_isPaused) - return 0xFF; + if (this->_isPaused || this->_cpu._isStopped) + return 0; for (int i = 0; i < 0xFF; i++) { auto breakpoint = std::find_if(this->breakpoints.begin(), this->breakpoints.end(), [this](auto &brk) { @@ -104,6 +104,7 @@ namespace ComSquare::Debugger::CPU } this->_logInstruction(); cycles += this->_cpu.executeInstruction(); + cycles += this->_cpu.runDMA(INT_MAX); this->_updateRegistersPanel(); if (this->_isStepping) { this->_isStepping = false; @@ -115,12 +116,12 @@ namespace ComSquare::Debugger::CPU } catch (const DebuggableError &e) { this->pause(true); CPUDebug::showError(e); - return 0xFF; + return 0; } catch (const std::exception &e) { std::cerr << "An error occurred: " << e.what() << std::endl; QApplication::quit(); } - return 0xFF; + return 0; } void CPUDebug::_logInstruction() diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp index 65ce5d3..aac0a4b 100644 --- a/sources/Debugger/MemoryBusDebug.cpp +++ b/sources/Debugger/MemoryBusDebug.cpp @@ -6,6 +6,7 @@ #include "SNES.hpp" #include "Utility/Utility.hpp" #include "Exceptions/InvalidAction.hpp" +#include namespace ComSquare::Debugger { @@ -27,6 +28,11 @@ namespace ComSquare::Debugger for (int i = 0; i < this->_model.column; i++) this->_ui.log->setColumnWidth(i, this->_ui.log->width()); + QMainWindow::connect(&this->_model, &BusLogModel::rowsInserted, [this] { + if (this->_autoScroll) + this->_ui.log->scrollToBottom(); + }); + QMainWindow::connect(this->_ui.fromAPU, &QCheckBox::toggled, [this](bool checked) { this->_proxy.filters[0].apu = checked; this->_proxy.refresh(); @@ -108,6 +114,10 @@ namespace ComSquare::Debugger this->_proxy.refresh(); }); + QMainWindow::connect(this->_ui.autoscroll, &QPushButton::pressed, [this]() { + this->_autoScroll = !this->_autoScroll; + }); + QMainWindow::connect(this->_ui.clearBtn, &QPushButton::pressed, [this]() { this->_model.clearLogs(); this->_proxy.refresh(); diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp index 4266eab..b93ee06 100644 --- a/sources/Debugger/MemoryBusDebug.hpp +++ b/sources/Debugger/MemoryBusDebug.hpp @@ -118,6 +118,8 @@ namespace ComSquare::Debugger BusLogModel _model; //! @brief A QT proxy to filter the logs. BusLoggerProxy _proxy; + //! @brief True if the table should autoscroll. False otherwise. + bool _autoScroll = true; public: explicit MemoryBusDebug(SNES &snes, Memory::IMemoryBus &bus); MemoryBusDebug(const MemoryBusDebug &) = delete; diff --git a/sources/SNES.cpp b/sources/SNES.cpp index 304bb64..d6cce03 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -38,7 +38,9 @@ namespace ComSquare return; } - unsigned cycleCount = this->cpu.update(0x0C); + unsigned cycleCount = this->cpu.update(0xFF); + if (cycleCount == 0) + cycleCount = 0xFF; this->ppu.update(cycleCount); this->apu.update(cycleCount); } diff --git a/ui/busView.ui b/ui/busView.ui index d2b5cb5..a1e9ecb 100644 --- a/ui/busView.ui +++ b/ui/busView.ui @@ -385,6 +385,19 @@ + + + + Qt::LeftToRight + + + Autoscroll + + + true + + +