diff --git a/sources/Debugger/CGramDebug.cpp b/sources/Debugger/CGramDebug.cpp index 9c3e4e3..16a6050 100644 --- a/sources/Debugger/CGramDebug.cpp +++ b/sources/Debugger/CGramDebug.cpp @@ -7,9 +7,8 @@ #include #include #include +#include #include "../Utility/Utility.hpp" -#include "../Exceptions/InvalidAction.hpp" -#include "../Exceptions/InvalidAddress.hpp" namespace ComSquare::Debugger { @@ -26,7 +25,7 @@ namespace ComSquare::Debugger this->_ui.setupUi(this->_window); this->_ui.cgram_view->setModel(&this->_model); - + updateInfoTile(0); this->_window->show(); } @@ -49,6 +48,22 @@ namespace ComSquare::Debugger { return this->_ppu.cgramRead(addr); } + + void CGramDebug::updateInfoTile(uint8_t addr) + { + uint16_t cgramValue = this->_ppu.cgramRead(addr); + std::cout << "val " << cgramValue << std::endl; + uint8_t blue = (cgramValue & 0x7D00U) >> 10U; + uint8_t green = (cgramValue & 0x03E0U) >> 5U; + uint8_t red = (cgramValue & 0x001FU); + + this->_ui.indexLineEdit->setText(std::to_string(addr).c_str()); + this->_ui.valueLineEdit->setText(std::to_string(cgramValue).c_str()); + this->_ui.rLineEdit->setText(std::to_string(red).c_str()); + this->_ui.gLineEdit->setText(std::to_string(green).c_str()); + this->_ui.bLineEdit->setText(std::to_string(blue).c_str()); + this->_ui.hexLineEdit->setText(Utility::to_hex(cgramValue).c_str()); + } } CGramModel::CGramModel(ComSquare::PPU::PPU &ppu) : _ppu(ppu) {} diff --git a/sources/Debugger/CGramDebug.hpp b/sources/Debugger/CGramDebug.hpp index 8cdcbff..5be7822 100644 --- a/sources/Debugger/CGramDebug.hpp +++ b/sources/Debugger/CGramDebug.hpp @@ -111,12 +111,12 @@ namespace ComSquare::Debugger //! @param addr The address to read from. //! @return The color value in BGR, looks like this xbbbbbgggggrrrrr. uint16_t read(uint8_t addr); - //! @brief Focus the debugger's window. void focus(); - //! @brief Return true if the Bus is overloaded with debugging features. bool isDebugger(); + //! @brief Update the text fields with corresponding tile info + void updateInfoTile(uint8_t addr); }; } diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 0471f67..d90a581 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -59,6 +59,10 @@ namespace ComSquare::Renderer busDebugger->setShortcut(Qt::Key_F5); QMainWindow::connect(busDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableDebugBus); debugger->addAction(busDebugger); + QAction *cgramDebugger = new QAction("Palette Viewer", &this->_window); + cgramDebugger->setShortcut(Qt::Key_F6); + QMainWindow::connect(cgramDebugger, &QAction::triggered, this->_sfWidget.get(), &QtFullSFML::enableCgramViewer); + debugger->addAction(cgramDebugger); this->_window.show(); } @@ -119,4 +123,9 @@ namespace ComSquare::Renderer { this->_snes.enableMemoryBusDebugging(); } + + void QtFullSFML::enableCgramViewer() + { + this->_snes.enableCgramDebugging(); + } } \ No newline at end of file diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp index b971b82..661422c 100644 --- a/sources/Renderer/QtRenderer/QtSFML.hpp +++ b/sources/Renderer/QtRenderer/QtSFML.hpp @@ -33,6 +33,8 @@ namespace ComSquare::Renderer void enableDebugAPU(); //! @brief Action called when clicking on the enable Memory Bus debugger button. void enableDebugBus(); + //! @brief Action called when clicking on the enable Palette viewer button. + void enableCgramViewer(); //! @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/main.cpp b/sources/main.cpp index 3a4ba82..9c4de9b 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -19,7 +19,8 @@ void usage(char *bin) << "\t-c, --cpu: \tEnable the debugger of the CPU." << std::endl << "\t-m, --memory: \tEnable the memory viewer panel." << std::endl << "\t-h, --header: \tShow the header of the cartridge." << std::endl - << "\t-b, --bus: \tShow the memory bus's log." << std::endl; + << "\t-b, --bus: \tShow the memory bus's log." << std::endl + << "\t-g, --cgram: \tShow the palette viewer." << std::endl; } void parseArguments(int argc, char **argv, SNES &snes)