From 38b65b595c0f31b46858bb9adcdbc0b7639593dc Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Sun, 16 Feb 2020 20:55:48 +0100
Subject: [PATCH] Adding a step feature
---
resources/appResources.qrc | 1 +
resources/icons/step.svg | 1 +
sources/Debugger/DebugCpu.cpp | 13 +++++++++++++
sources/Debugger/DebugCpu.hpp | 4 ++++
ui/cpu.ui | 16 ++++++++++++++++
5 files changed, 35 insertions(+)
create mode 100644 resources/icons/step.svg
diff --git a/resources/appResources.qrc b/resources/appResources.qrc
index d9b3d42..8e8574c 100644
--- a/resources/appResources.qrc
+++ b/resources/appResources.qrc
@@ -1,5 +1,6 @@
+ icons/step.svg
Logo.png
icons/play.svg
diff --git a/resources/icons/step.svg b/resources/icons/step.svg
new file mode 100644
index 0000000..d905272
--- /dev/null
+++ b/resources/icons/step.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/sources/Debugger/DebugCpu.cpp b/sources/Debugger/DebugCpu.cpp
index 375fbb9..a0afc3e 100644
--- a/sources/Debugger/DebugCpu.cpp
+++ b/sources/Debugger/DebugCpu.cpp
@@ -16,6 +16,7 @@ namespace ComSquare::Debugger
this->_ui.setupUi(this);
QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
+ QMainWindow::connect(this->_ui.actionStep, &QAction::triggered, this, &CPUDebug::step);
this->show();
}
@@ -33,6 +34,12 @@ namespace ComSquare::Debugger
unsigned CPUDebug::_executeInstruction(uint8_t opcode)
{
+ if (this->_isPaused)
+ return 0;
+ if (this->_isStepping) {
+ this->_isStepping = false;
+ this->_isPaused = true;
+ }
this->_ui.logger->append(CPUDebug::_getInstructionString(opcode).c_str());
return CPU::_executeInstruction(opcode);
}
@@ -46,6 +53,12 @@ namespace ComSquare::Debugger
this->_ui.actionPause->setText("Pause");
}
+ void CPUDebug::step()
+ {
+ this->_isStepping = true;
+ this->_isPaused = false;
+ }
+
std::string CPUDebug::_getInstructionString(uint8_t opcode)
{
switch (opcode) {
diff --git a/sources/Debugger/DebugCpu.hpp b/sources/Debugger/DebugCpu.hpp
index 2c5ab1e..0506b28 100644
--- a/sources/Debugger/DebugCpu.hpp
+++ b/sources/Debugger/DebugCpu.hpp
@@ -20,6 +20,8 @@ namespace ComSquare::Debugger
Ui::CPUView _ui;
//! @brief If this is set to true, the execution of the CPU will be paused.
bool _isPaused = true;
+ //! @brief If this is set to true, the CPU will execute one instruction and pause itself.
+ bool _isStepping = false;
//! @brief A reference to the snes (to disable the debugger).
SNES &_snes;
//! @brief Reimplement the basic instruction execution method to log instructions inside the logger view.
@@ -29,6 +31,8 @@ namespace ComSquare::Debugger
public slots:
//! @brief Pause/Resume the CPU.
void pause();
+ //! @brief Step - Execute a single instruction.
+ void step();
public:
//! @brief Convert a basic CPU to a debugging CPU.
explicit CPUDebug(ComSquare::CPU::CPU &cpu, SNES &snes);
diff --git a/ui/cpu.ui b/ui/cpu.ui
index aea3729..2b563b3 100644
--- a/ui/cpu.ui
+++ b/ui/cpu.ui
@@ -84,6 +84,7 @@
false
+
@@ -100,6 +101,21 @@
P
+
+
+
+ :/resources/icons/step.svg:/resources/icons/step.svg
+
+
+ Step
+
+
+ Execute a single instruction
+
+
+ S
+
+