From 1a6d0e907b3205f09435fbea274b33ac1aff0949 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Wed, 25 Mar 2020 22:33:12 +0100
Subject: [PATCH] Making the debugger spawn on invalid rom exceptions (invalid
address access, invalid opcode...) & starting the dissasembly view
---
sources/Cartridge/Cartridge.cpp | 26 +++++------
sources/Debugger/MemoryBusDebug.cpp | 2 +
sources/Renderer/QtRenderer/QtSFML.cpp | 6 +++
sources/main.cpp | 14 ++++--
ui/cpu.ui | 63 ++++++++++++++++----------
5 files changed, 69 insertions(+), 42 deletions(-)
diff --git a/sources/Cartridge/Cartridge.cpp b/sources/Cartridge/Cartridge.cpp
index 227903a..91a8036 100644
--- a/sources/Cartridge/Cartridge.cpp
+++ b/sources/Cartridge/Cartridge.cpp
@@ -15,22 +15,18 @@ namespace ComSquare::Cartridge
Cartridge::Cartridge(const std::string &romPath)
: Ram::Ram(0, Rom, "Cartridge")
{
- try {
- if (romPath.empty())
- throw InvalidRomException("Path is empty.");
- size_t size = Cartridge::getRomSize(romPath);
- FILE *rom = fopen(romPath.c_str(), "rb");
+ if (romPath.empty())
+ throw InvalidRomException("Path is empty.");
+ size_t size = Cartridge::getRomSize(romPath);
+ FILE *rom = fopen(romPath.c_str(), "rb");
- if (!rom)
- throw InvalidRomException("Could not open the rom file at " + romPath + ". " + strerror(errno));
- this->_size = size;
- this->_data = new uint8_t[size];
- std::memset(this->_data, 0, size);
- fread(this->_data, 1, size, rom);
- this->_loadHeader();
- } catch (InvalidRomException &ex) {
- std::cerr << "Invalid Rom Error: " << ex.what() << std::endl;
- }
+ if (!rom)
+ throw InvalidRomException("Could not open the rom file at " + romPath + ". " + strerror(errno));
+ this->_size = size;
+ this->_data = new uint8_t[size];
+ std::memset(this->_data, 0, size);
+ fread(this->_data, 1, size, rom);
+ this->_loadHeader();
}
size_t Cartridge::getRomSize(const std::string &romPath)
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index 17314cd..2d520d4 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -25,6 +25,8 @@ namespace ComSquare::Debugger
this->_ui.setupUi(this->_window);
this->_proxy.setSourceModel(&this->_model);
this->_ui.log->setModel(&this->_proxy);
+ this->_ui.log->setAlternatingRowColors(true);
+ this->_ui.log->verticalHeader()->hide();
this->_ui.log->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
this->_ui.log->horizontalHeader()->setStretchLastSection(true);
this->_ui.log->horizontalHeader()->setSectionsMovable(true);
diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp
index 0471f67..9a333a6 100644
--- a/sources/Renderer/QtRenderer/QtSFML.cpp
+++ b/sources/Renderer/QtRenderer/QtSFML.cpp
@@ -8,6 +8,8 @@
#include
#include
#include "QtSFML.hpp"
+#include "../../Exceptions/InvalidOpcode.hpp"
+#include "../../Exceptions/InvalidAddress.hpp"
#ifdef Q_WS_X11
#include
@@ -84,6 +86,10 @@ namespace ComSquare::Renderer
{
try {
this->_snes.update();
+ } catch (InvalidOpcode &e) {
+ this->_snes.enableCPUDebugging();
+ } catch (InvalidAddress &e) {
+ this->_snes.enableCPUDebugging();
} catch (std::exception &e) {
std::cerr << "An error occurred: " << e.what() << std::endl;
QApplication::quit();
diff --git a/sources/main.cpp b/sources/main.cpp
index ed678cd..8e5930b 100644
--- a/sources/main.cpp
+++ b/sources/main.cpp
@@ -68,8 +68,14 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
Renderer::QtSFML renderer(600, 800);
- SNES snes(argv[1], renderer);
- renderer.createWindow(snes, 60);
- parseArguments(argc, argv, snes);
- return QApplication::exec();
+ try {
+ SNES snes(argv[1], renderer);
+ renderer.createWindow(snes, 60);
+ parseArguments(argc, argv, snes);
+ return QApplication::exec();
+ }
+ catch(std::exception &ex) {
+ std::cerr << ex.what() << std::endl;
+ return 1;
+ }
}
\ No newline at end of file
diff --git a/ui/cpu.ui b/ui/cpu.ui
index 09dd3ed..a3b46d0 100644
--- a/ui/cpu.ui
+++ b/ui/cpu.ui
@@ -6,8 +6,8 @@
0
0
- 420
- 438
+ 971
+ 709
@@ -21,28 +21,18 @@
false
-
+
+ -
+
+
+
+ 1
+ 0
+
+
+
+
-
-
-
- Instructions History
-
-
- Qt::AlignCenter
-
-
-
- -
-
-
- -
-
-
- Clear History
-
-
-
- -
-
@@ -150,10 +140,37 @@
Qt::RightToLeft
+
+ false
+
+ -
+
+
-
+
+
+ Clear History
+
+
+
+ -
+
+
+ Instructions History
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+