diff --git a/README.md b/README.md index 3cb6640..6db025e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+

License diff --git a/main.cpp b/main.cpp index e781c4b..9376351 100644 --- a/main.cpp +++ b/main.cpp @@ -4,21 +4,54 @@ #include #include +#include #include "sources/SNES.hpp" #include "sources/Renderer/SFRenderer.hpp" #include "sources/Renderer/QtRenderer/QtSFML.hpp" using namespace ComSquare; +void usage(char *bin) +{ + std::cout << "ComSquare:" << std::endl << "\tUsage: " << bin << " rom_path" << std::endl; +} + +void parseArguments(int argc, char **argv, SNES &snes) +{ + while (true) { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + static struct option long_options[] = { + {"cpu-debug", no_argument, 0, 'c' }, + {0, 0, 0, 0 } + }; + + char c = getopt_long(argc, argv, "c:pu-debug", long_options, &option_index); + if (c == -1) + break; + switch (c) { + case 0: + usage(argv[0]); + break; + case 'c': + snes.enableCPUDebugging(); + break; + default: + break; + } + } +} + int main(int argc, char **argv) { if (argc < 2) { - std::cout << "ComSquare:" << std::endl << "\tUsage: " << argv[0] << " rom_path" << std::endl; + usage(argv[0]); return 1; } QApplication app(argc, argv); Renderer::QtSFML renderer(600, 800); SNES snes(std::make_shared(), argv[1], renderer); renderer.createWindow(snes, 60); + parseArguments(argc, argv, snes); return QApplication::exec(); } \ No newline at end of file diff --git a/resources/Black.svg b/resources/Black.svg index ce9b135..ddd5d49 100644 --- a/resources/Black.svg +++ b/resources/Black.svg @@ -1 +1 @@ -Fichier 5 +Fichier 5 diff --git a/sources/CPU/Instructions/MathematicalOperations.cpp b/sources/CPU/Instructions/MathematicalOperations.cpp index 37a38e6..83455f8 100644 --- a/sources/CPU/Instructions/MathematicalOperations.cpp +++ b/sources/CPU/Instructions/MathematicalOperations.cpp @@ -12,7 +12,7 @@ namespace ComSquare::CPU unsigned value = this->_bus->read(valueAddr) + this->_registers.p.c; if (this->_registers.p.m) value += this->_bus->read(valueAddr + 1) << 8u; - unsigned negativeMask = this->_isEmulationMode ? 0xF0u : 0xF000u; + unsigned negativeMask = this->_isEmulationMode ? 0x80u : 0x8000u; unsigned maxValue = this->_isEmulationMode ? UINT8_MAX : UINT16_MAX; this->_registers.p.c = static_cast(this->_registers.a) + value > maxValue; diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 8ffeed4..26c9c98 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -70,7 +70,12 @@ namespace ComSquare::Renderer void QtFullSFML::_onUpdate() { - this->_snes.update(); + try { + this->_snes.update(); + } catch (std::exception &e) { + std::cerr << "An error occurred: " << e.what() << std::endl; + QApplication::quit(); + } } void QtFullSFML::enableDebugCPU() diff --git a/sources/SNES.cpp b/sources/SNES.cpp index 6026a56..14fa48a 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -52,12 +52,8 @@ namespace ComSquare void SNES::update() { - try { - unsigned cycleCount = this->cpu->update(); - this->ppu->update(cycleCount); - this->apu->update(cycleCount); - } catch (std::exception &e) { - std::cerr << "An error occurred: " << e.what() << std::endl; - } + unsigned cycleCount = this->cpu->update(); + this->ppu->update(cycleCount); + this->apu->update(cycleCount); } }