diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ad390..78787a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,11 +131,12 @@ add_executable(ComSquare sources/Renderer/QtRenderer/QtWidgetSFML.hpp ui/cpu.ui ui/ramView.ui + ui/cartridgeView.ui resources/appResources.qrc sources/Utility/Utility.hpp sources/Debugger/MemoryViewer.cpp sources/Debugger/MemoryViewer.hpp - sources/Utility/Utility.cpp) + sources/Utility/Utility.cpp sources/Debugger/HeaderViewer.cpp sources/Debugger/HeaderViewer.hpp) target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED) diff --git a/main.cpp b/main.cpp index 6a0773b..01aa3e1 100644 --- a/main.cpp +++ b/main.cpp @@ -22,22 +22,30 @@ void parseArguments(int argc, char **argv, SNES &snes) int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { - {"cpu-debug", no_argument, 0, 'c' }, + {"cpu", no_argument, 0, 'c' }, + {"memory", no_argument, 0, 'm' }, + {"header", no_argument, 0, 'h' }, {0, 0, 0, 0 } }; - char c = getopt_long(argc, argv, "c", long_options, &option_index); + char c = getopt_long(argc, argv, "cmh", long_options, &option_index); if (c == -1) break; switch (c) { - case 0: - usage(argv[0]); - break; - case 'c': - snes.enableCPUDebugging(); - break; - default: - break; + case 0: + usage(argv[0]); + break; + case 'c': + snes.enableCPUDebugging(); + break; + case 'm': + snes.enableRamViewer(); + break; + case 'h': + snes.enableHeaderViewer(); + break; + default: + break; } } } diff --git a/sources/Debugger/HeaderViewer.cpp b/sources/Debugger/HeaderViewer.cpp new file mode 100644 index 0000000..92b421b --- /dev/null +++ b/sources/Debugger/HeaderViewer.cpp @@ -0,0 +1,53 @@ +// +// Created by anonymus-raccoon on 2/18/20. +// + +#include "HeaderViewer.hpp" +#include "../Utility/Utility.hpp" + +namespace ComSquare::Debugger +{ + HeaderViewer::HeaderViewer(ComSquare::Cartridge::Cartridge &cartridge) : + _cartridge(cartridge), + _ui() + { + this->setContextMenuPolicy(Qt::NoContextMenu); + this->setAttribute(Qt::WA_QuitOnClose, false); + + this->_ui.setupUi(this); + this->_ui.nameLineEdit->setText(cartridge.header.gameName.c_str()); + std::string memType; + if (cartridge.header.mappingMode & Cartridge::LoRom) + memType += "LoRom "; + if (cartridge.header.mappingMode & Cartridge::HiRom) + memType += "HiRom "; + if (cartridge.header.mappingMode & Cartridge::SlowRom) + memType += "SlowRom "; + if (cartridge.header.mappingMode & Cartridge::FastRom) + memType += "FastRom "; + if (cartridge.header.mappingMode & Cartridge::ExRom) + memType += "ExRom "; + this->_ui.mappingLineEdit->setText(memType.c_str()); + this->_ui.romSizeLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.romSize).c_str()); + this->_ui.sRamSizeLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.sramSize).c_str()); + this->_ui.versionLineEdit->setText(std::to_string(cartridge.header.version).c_str()); + this->_ui.creatorIDLineEdit->setText(std::to_string(cartridge.header.creatorID).c_str()); + this->_ui.checksumLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.checksum).c_str()); + this->_ui.checksumComplementLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.checksumComplement).c_str()); + + this->_ui.coProcessorLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.cop).c_str()); + this->_ui.breakLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.brk).c_str()); + this->_ui.abortLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.abort).c_str()); + this->_ui.nMInteruptLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.nmi).c_str()); + this->_ui.resetLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.reset).c_str()); + this->_ui.interruptRequestLineEdit->setText(ComSquare::Utility::to_hex(cartridge.header.emulationInterrupts.irq).c_str()); + + this->_ui.coProcessorLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.cop).c_str()); + this->_ui.breakLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.brk).c_str()); + this->_ui.abortLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.abort).c_str()); + this->_ui.nMInteruptLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.nmi).c_str()); + this->_ui.resetLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.reset).c_str()); + this->_ui.interruptRequestLineEditNat->setText(ComSquare::Utility::to_hex(cartridge.header.nativeInterrupts.irq).c_str()); + this->show(); + } +} \ No newline at end of file diff --git a/sources/Debugger/HeaderViewer.hpp b/sources/Debugger/HeaderViewer.hpp new file mode 100644 index 0000000..b8e1226 --- /dev/null +++ b/sources/Debugger/HeaderViewer.hpp @@ -0,0 +1,29 @@ +// +// Created by anonymus-raccoon on 2/18/20. +// + +#ifndef COMSQUARE_HEADERVIEWER_HPP +#define COMSQUARE_HEADERVIEWER_HPP + +#include +#include "../Cartridge/Cartridge.hpp" +#include "../../ui/ui_cartridgeView.h" + +namespace ComSquare::Debugger +{ + //! @brief Window that show the header of the currently running game. + class HeaderViewer : public QMainWindow { + private: + //! @brief The cartrdige containing the header. + Cartridge::Cartridge &_cartridge; + //! @brief The layout of the viewer. + Ui::CatridgeView _ui; + public: + explicit HeaderViewer(Cartridge::Cartridge &cartridge); + HeaderViewer(const HeaderViewer &) = delete; + HeaderViewer &operator=(const HeaderViewer &) = delete; + ~HeaderViewer() override = default; + }; +} + +#endif //COMSQUARE_HEADERVIEWER_HPP diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 26c9c98..1b9be1b 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -47,6 +47,10 @@ namespace ComSquare::Renderer ramViewer->setShortcut(Qt::Key_F2); QMainWindow::connect(ramViewer, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableRamViewer); debugger->addAction(ramViewer); + QAction *headerViewer = new QAction("Header viewer", &this->_window); + headerViewer->setShortcut(Qt::Key_F3); + QMainWindow::connect(headerViewer, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableHeaderViewer); + debugger->addAction(headerViewer); this->_window.show(); } @@ -92,4 +96,9 @@ namespace ComSquare::Renderer { this->_snes.enableRamViewer(); } + + void QtFullSFML::enableHeaderViewer() + { + this->_snes.enableHeaderViewer(); + } } \ No newline at end of file diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp index cdec362..aac6531 100644 --- a/sources/Renderer/QtRenderer/QtSFML.hpp +++ b/sources/Renderer/QtRenderer/QtSFML.hpp @@ -27,6 +27,8 @@ namespace ComSquare::Renderer void enableDebugCPU(); //! @brief Action called when clicking on the enable Ram viewer button. void enableRamViewer(); + //! @brief Action called when clicking on the enable Header viewer button. + void enableHeaderViewer(); //! @brief Action called when clicking on the reset button. void reset(); QtFullSFML(SNES &snes, QWidget* parent, const QPoint& position, const QSize& size, int frameRate = 0); diff --git a/sources/SNES.cpp b/sources/SNES.cpp index 14fa48a..5ffe583 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -43,7 +43,7 @@ namespace ComSquare #endif } - void SNES::disableRamDebugging() + void SNES::disableRamViewer() { #ifdef DEBUGGER_ENABLED this->_ramViewer = nullptr; @@ -56,4 +56,18 @@ namespace ComSquare this->ppu->update(cycleCount); this->apu->update(cycleCount); } + + void SNES::enableHeaderViewer() + { + #ifdef DEBUGGER_ENABLED + this->_headerViewer = std::make_shared(*this->cartridge); + #endif + } + + void SNES::disableHeaderViewer() + { + #ifdef DEBUGGER_ENABLED + this->_headerViewer = nullptr; + #endif + } } diff --git a/sources/SNES.hpp b/sources/SNES.hpp index 9c7ef7f..868936d 100644 --- a/sources/SNES.hpp +++ b/sources/SNES.hpp @@ -14,6 +14,8 @@ #include "Renderer/IRenderer.hpp" #ifdef DEBUGGER_ENABLED #include "Debugger/MemoryViewer.hpp" +#include "Debugger/HeaderViewer.hpp" + #endif namespace ComSquare @@ -22,7 +24,10 @@ namespace ComSquare class SNES { #ifdef DEBUGGER_ENABLED private: + //! @brief The window that allow the user to view a memory. std::shared_ptr _ramViewer; + //! @brief The window that allow the user to view the cartridge's header. + std::shared_ptr _headerViewer; #endif public: //! @brief Cartridge containing instructions (ROM). @@ -46,9 +51,13 @@ namespace ComSquare //! @brief Enable the CPU's debugging window. void enableCPUDebugging(); //! @brief Disable the Ram's debugging window. - void disableRamDebugging(); + void disableRamViewer(); //! @brief Enable the Ram's debugging window. void enableRamViewer(); + //! @brief Disable the Header's debugging window. + void disableHeaderViewer(); + //! @brief Enable the Header's debugging window. + void enableHeaderViewer(); //! @brief Create all the components using a common memory bus for all of them. SNES(const std::shared_ptr &bus, const std::string &ramPath, Renderer::IRenderer &renderer); diff --git a/ui/cartridgeView.ui b/ui/cartridgeView.ui new file mode 100644 index 0000000..fcccf42 --- /dev/null +++ b/ui/cartridgeView.ui @@ -0,0 +1,381 @@ + + + CatridgeView + + + + 0 + 0 + 300 + 375 + + + + Header Viewer + + + + :/resources/Logo.png:/resources/Logo.png + + + + + + + 0 + + + + General + + + + + 0 + 0 + 281 + 316 + + + + + + + Name + + + + + + + true + + + + + + + Mapping + + + + + + + true + + + + + + + Rom Type + + + + + + + true + + + + + + + Rom Size + + + + + + + true + + + + + + + SRam Size + + + + + + + true + + + + + + + Version + + + + + + + true + + + + + + + Creator ID + + + + + + + true + + + + + + + Checksum + + + + + + + true + + + + + + + Complement + + + + + + + true + + + + + + + + + Emulation + + + + + 0 + 0 + 281 + 351 + + + + + + + Co-Processor + + + + + + + true + + + + + + + Break + + + + + + + true + + + + + + + Abort + + + + + + + true + + + + + + + NM Interupt + + + + + + + true + + + + + + + Reset + + + + + + + true + + + + + + + Interrupt Request + + + + + + + true + + + + + + + + + Native + + + + + 0 + 0 + 281 + 351 + + + + + + + Co-Processor + + + + + + + true + + + + + + + Break + + + + + + + true + + + + + + + Abort + + + + + + + true + + + + + + + NM Interupt + + + + + + + true + + + + + + + Reset + + + + + + + true + + + + + + + Interrupt Request + + + + + + + true + + + + + + + + + + + + + + + +