Splitting the debug window of the component to allow quick change of a component

This commit is contained in:
Anonymus Raccoon
2020-03-20 16:41:45 +01:00
parent acf2807dc6
commit ea19186269
18 changed files with 407 additions and 248 deletions
+18 -10
View File
@@ -5,33 +5,41 @@
#include "CPUDebug.hpp"
#include "../Utility/Utility.hpp"
#include "../Exceptions/InvalidOpcode.hpp"
#include <QtEvents>
#include <iostream>
using namespace ComSquare::CPU;
namespace ComSquare::Debugger
{
CPUDebug::CPUDebug(CPU &basicCPU, SNES &snes)
: CPU(basicCPU), QMainWindow(), _ui(), _snes(snes)
: CPU(basicCPU), _window(new ClosableWindow(this, &CPUDebug::disableDebugger)), _ui(), _snes(snes)
{
this->setContextMenuPolicy(Qt::NoContextMenu);
this->setAttribute(Qt::WA_QuitOnClose, false);
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
this->_window->setAttribute(Qt::WA_DeleteOnClose);
this->_ui.setupUi(this);
this->_ui.setupUi(this->_window);
QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
QMainWindow::connect(this->_ui.actionStep, &QAction::triggered, this, &CPUDebug::step);
QMainWindow::connect(this->_ui.clear, &QPushButton::released, this, &CPUDebug::clearHistory);
this->show();
this->_window->show();
this->_updateRegistersPanel();
}
void CPUDebug::disableDebugger()
{
this->_snes.disableCPUDebugging();
}
CPUDebug::~CPUDebug()
{
std::cout << "Destructor" << std::endl;
}
unsigned CPUDebug::update()
{
try {
if (!this->isVisible()) {
this->_snes.disableCPUDebugging();
return 0;
}
if (this->_isPaused)
return 0xFF;
return CPU::update();
+6 -2
View File
@@ -9,12 +9,14 @@
#include "../Renderer/SFRenderer.hpp"
#include "../SNES.hpp"
#include "../../ui/ui_cpu.h"
#include "ClosableWindow.hpp"
namespace ComSquare::Debugger
{
//! @brief A custom CPU with a window that show it's registers and the disassembly.
class CPUDebug : public CPU::CPU, public QMainWindow {
class CPUDebug : public CPU::CPU, public QObject {
private:
ClosableWindow<CPUDebug> *_window;
//! @brief A widget that contain the whole UI.
Ui::CPUView _ui;
//! @brief If this is set to true, the execution of the CPU will be paused.
@@ -56,6 +58,8 @@ namespace ComSquare::Debugger
void step();
//! @brief Clear the history panel.
void clearHistory();
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
void disableDebugger();
public:
//! @brief Update the UI when reseting the CPU.
void RESB() override;
@@ -63,7 +67,7 @@ namespace ComSquare::Debugger
explicit CPUDebug(ComSquare::CPU::CPU &cpu, SNES &snes);
CPUDebug(const CPUDebug &) = delete;
CPUDebug &operator=(const CPUDebug &) = delete;
~CPUDebug() override = default;
~CPUDebug() override;
//! @brief Override the basic cpu's update to allow pausing of the CPU only.
unsigned update() override;
+34
View File
@@ -0,0 +1,34 @@
//
// Created by anonymus-raccoon on 3/20/20.
//
#ifndef COMSQUARE_CLOSABLEWINDOW_HPP
#define COMSQUARE_CLOSABLEWINDOW_HPP
#include <QtWidgets/QMainWindow>
namespace ComSquare::Debugger
{
template <typename T>
class ClosableWindow : public QMainWindow {
protected:
void closeEvent(QCloseEvent *) override
{
(this->_obj->*this->_onClose)();
}
private:
T *_obj;
void (T::*_onClose)();
public:
explicit ClosableWindow(T *obj, void (T::*onClose)())
: _obj(obj), _onClose(onClose)
{ }
ClosableWindow(const ClosableWindow &) = delete;
ClosableWindow &operator=(const ClosableWindow &) = delete;
~ClosableWindow() override = default;
};
}
#endif //COMSQUARE_CLOSABLEWINDOW_HPP
+19
View File
@@ -0,0 +1,19 @@
//
// Created by anonymus-raccoon on 3/20/20.
//
#include "MemoryBusDebug.hpp"
namespace ComSquare::Debugger
{
MemoryBusDebug::MemoryBusDebug(const ComSquare::Memory::MemoryBus &bus)
: MemoryBus(bus), QMainWindow(), _ui()
{
this->setContextMenuPolicy(Qt::NoContextMenu);
this->setAttribute(Qt::WA_QuitOnClose, false);
this->_ui.setupUi(this);
// QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
this->show();
}
}
+27
View File
@@ -0,0 +1,27 @@
//
// Created by anonymus-raccoon on 3/20/20.
//
#ifndef COMSQUARE_MEMORYBUSDEBUG_HPP
#define COMSQUARE_MEMORYBUSDEBUG_HPP
#include <QtWidgets/QMainWindow>
#include "../Memory/MemoryBus.hpp"
#include "../../ui/ui_busView.h"
namespace ComSquare::Debugger
{
//! @brief window that allow the user to view all data going through the memory bus.
class MemoryBusDebug : public Memory::MemoryBus, public QMainWindow {
private:
//! @brief A widget that contain the whole UI.
Ui::BusView _ui;
public:
explicit MemoryBusDebug(const Memory::MemoryBus &bus);
MemoryBusDebug(const MemoryBusDebug &) = delete;
MemoryBusDebug &operator=(const MemoryBusDebug &) = delete;
~MemoryBusDebug() override = default;
};
}
#endif //COMSQUARE_MEMORYBUSDEBUG_HPP