mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-02 10:15:45 +00:00
Merge branch 'master' of github.com:AnonymusRaccoon/ComSquare into Debugger
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
// //! @brief Convert a basic CPU to a debugging CPU.
|
||||
|
||||
//
|
||||
// Created by Melefo on 19/02/2020.
|
||||
//
|
||||
|
||||
#include "APUDebug.hpp"
|
||||
#include "../Utility/Utility.hpp"
|
||||
#include "../Exceptions/InvalidOpcode.hpp"
|
||||
|
||||
using namespace ComSquare::APU;
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
APUDebug::APUDebug(APU &apu, SNES &snes) :
|
||||
APU(apu),
|
||||
_window(new ClosableWindow(*this, &APUDebug::disableDebugger)),
|
||||
_ui(),
|
||||
_snes(snes)
|
||||
APU(apu),
|
||||
_window(new ClosableWindow<APUDebug>(*this, &APUDebug::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);
|
||||
QMainWindow::connect(this->_ui.resumeButton, &QPushButton::clicked, this, &APUDebug::pause);
|
||||
QMainWindow::connect(this->_ui.stepButton, &QPushButton::clicked, this, &APUDebug::step);
|
||||
this->_window->show();
|
||||
this->_updatePanel();
|
||||
}
|
||||
@@ -473,6 +475,12 @@ namespace ComSquare::Debugger
|
||||
|
||||
int APUDebug::_executeInstruction()
|
||||
{
|
||||
if (this->_isPaused)
|
||||
return 0xFF;
|
||||
if (this->_isStepping) {
|
||||
this->_isStepping = false;
|
||||
this->_isPaused = true;
|
||||
}
|
||||
this->_ui.logger->append(APUDebug::_getInstructionString().c_str());
|
||||
this->_updatePanel();
|
||||
return APU::_executeInstruction();
|
||||
@@ -480,9 +488,32 @@ namespace ComSquare::Debugger
|
||||
|
||||
void APUDebug::update(unsigned cycles)
|
||||
{
|
||||
return APU::update(cycles);
|
||||
try {
|
||||
if (this->_isPaused)
|
||||
return;
|
||||
APU::update(cycles);
|
||||
} catch (InvalidOpcode &e) {
|
||||
this->pause();
|
||||
this->_ui.logger->append(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void APUDebug::step()
|
||||
{
|
||||
this->_isStepping = true;
|
||||
this->_isPaused = false;
|
||||
}
|
||||
|
||||
void APUDebug::pause()
|
||||
{
|
||||
this->_isPaused = !this->_isPaused;
|
||||
if (this->_isPaused)
|
||||
this->_ui.resumeButton->setText("Resume");
|
||||
else
|
||||
this->_ui.resumeButton->setText("Pause");
|
||||
}
|
||||
|
||||
|
||||
void APUDebug::disableDebugger()
|
||||
{
|
||||
this->_snes.disableAPUDebugging();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
class APUDebug : public APU::APU {
|
||||
class APUDebug : public APU::APU, public QObject {
|
||||
private:
|
||||
//! @brief The QT window for this debugger.
|
||||
ClosableWindow<APUDebug> *_window;
|
||||
@@ -19,6 +19,11 @@ namespace ComSquare::Debugger
|
||||
//! @brief A widget that contain the whole UI.
|
||||
Ui::APUView _ui;
|
||||
|
||||
//! @brief If this is set to true, the execution of the APU will be paused.
|
||||
bool _isPaused = true;
|
||||
//! @brief If this is set to true, the APU will execute one instruction and pause itself.
|
||||
bool _isStepping = false;
|
||||
|
||||
//! @brief A reference to the snes (to disable the debugger).
|
||||
SNES &_snes;
|
||||
|
||||
@@ -33,8 +38,11 @@ namespace ComSquare::Debugger
|
||||
|
||||
//! @brief return the mnemonic of the current instruction done.
|
||||
std::string _getInstructionString();
|
||||
|
||||
public slots:
|
||||
//! @brief Pause/Resume the APU.
|
||||
void pause();
|
||||
//! @brief Step - Execute a single instruction.
|
||||
void step();
|
||||
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic APU.
|
||||
void disableDebugger();
|
||||
public:
|
||||
@@ -47,6 +55,7 @@ namespace ComSquare::Debugger
|
||||
//! @brief Override the apu's update to disable debugging.
|
||||
void update(unsigned cycles) override;
|
||||
|
||||
|
||||
//! @brief Return true if the CPU is overloaded with debugging features.
|
||||
bool isDebugger() override;
|
||||
|
||||
@@ -55,4 +64,4 @@ namespace ComSquare::Debugger
|
||||
};
|
||||
}
|
||||
|
||||
#endif //COMSQUARE_APUDEBUG_HPP
|
||||
#endif //COMSQUARE_APUDEBUG_HPP
|
||||
@@ -14,7 +14,7 @@ namespace ComSquare::Debugger
|
||||
{
|
||||
CPUDebug::CPUDebug(CPU &basicCPU, SNES &snes)
|
||||
: CPU(basicCPU),
|
||||
_window(new ClosableWindow(*this, &CPUDebug::disableDebugger)),
|
||||
_window(new ClosableWindow<CPUDebug>(*this, &CPUDebug::disableDebugger)),
|
||||
_ui(),
|
||||
_snes(snes)
|
||||
{
|
||||
@@ -175,7 +175,7 @@ namespace ComSquare::Debugger
|
||||
std::string CPUDebug::_getAbsoluteValue(uint24_t pc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "$" << std::hex << (this->_bus->read(pc) + (this->_bus->read(pc + 1) << 8u), true);
|
||||
ss << "$" << std::hex << (this->_bus->read(pc) + (this->_bus->read(pc + 1, true) << 8u));
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
HeaderViewer::HeaderViewer(ComSquare::SNES &snes)
|
||||
: _window(new ClosableWindow(*this, &HeaderViewer::disableDebugger)),
|
||||
: _window(new ClosableWindow<HeaderViewer>(*this, &HeaderViewer::disableDebugger)),
|
||||
_snes(snes),
|
||||
_cartridge(*snes.cartridge),
|
||||
_ui()
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace ComSquare::Debugger
|
||||
{
|
||||
MemoryBusDebug::MemoryBusDebug(SNES &snes, const Memory::MemoryBus &bus)
|
||||
: MemoryBus(bus),
|
||||
_window(new ClosableWindow(*this, &MemoryBusDebug::disableViewer)),
|
||||
_window(new ClosableWindow<MemoryBusDebug>(*this, &MemoryBusDebug::disableViewer)),
|
||||
_snes(snes),
|
||||
_ui(),
|
||||
_model(),
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <QtWidgets/QSpinBox>
|
||||
#include "MemoryViewer.hpp"
|
||||
#include "../SNES.hpp"
|
||||
#include "../Utility/Utility.hpp"
|
||||
#include "../Memory/MemoryShadow.hpp"
|
||||
#include "../Exceptions/InvalidAddress.hpp"
|
||||
|
||||
@@ -65,7 +64,7 @@ void MemoryViewerModel::setMemory(std::shared_ptr<Ram> memory)
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
MemoryViewer::MemoryViewer(ComSquare::SNES &snes, Memory::MemoryBus &bus) :
|
||||
_window(new ClosableWindow(*this, &MemoryViewer::disableViewer)),
|
||||
_window(new ClosableWindow<MemoryViewer>(*this, &MemoryViewer::disableViewer)),
|
||||
_snes(snes),
|
||||
_bus(bus),
|
||||
_ui(),
|
||||
|
||||
Reference in New Issue
Block a user