diff --git a/sources/Debugger/CGramDebug.cpp b/sources/Debugger/CGramDebug.cpp index 6694841..f2ae435 100644 --- a/sources/Debugger/CGramDebug.cpp +++ b/sources/Debugger/CGramDebug.cpp @@ -6,6 +6,8 @@ #include "../SNES.hpp" #include #include +#include +#include #include "../Utility/Utility.hpp" namespace ComSquare::Debugger @@ -22,9 +24,11 @@ namespace ComSquare::Debugger this->_window->setAttribute(Qt::WA_DeleteOnClose); this->_ui.setupUi(this->_window); + QMainWindow::connect(this->_ui.cgram_view, &QTableView::pressed, this, &CGramDebug::tileClicked); this->_ui.cgram_view->setModel(&this->_model); - updateInfoTile(0); + updateInfoTile(0, 0); this->_window->show(); + QEvent::registerEventType(); } void CGramDebug::disableViewer() @@ -47,8 +51,10 @@ namespace ComSquare::Debugger return this->_ppu.cgramRead(addr); } - void CGramDebug::updateInfoTile(uint8_t addr) + void CGramDebug::updateInfoTile(int row, int column) { + int idTile = row * 16 + column; + uint16_t addr = idTile / 8 * 16 + (idTile % 8 * 2); uint16_t cgramValue = this->_ppu.cgramRead(addr); cgramValue += this->_ppu.cgramRead(addr + 1) << 8; uint8_t blue = (cgramValue & 0x7D00U) >> 10U; @@ -56,8 +62,8 @@ namespace ComSquare::Debugger uint8_t red = (cgramValue & 0x001FU); uint24_t hexColorValue = 0; - this->_ui.indexLineEdit->setText(std::to_string(addr).c_str()); - this->_ui.valueLineEdit->setText(std::to_string(cgramValue).c_str()); + this->_ui.indexLineEdit->setText(std::to_string(addr / 2).c_str()); + this->_ui.valueLineEdit->setText(Utility::to_hex(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()); @@ -66,6 +72,13 @@ namespace ComSquare::Debugger hexColorValue += (blue * 255U / 31U); this->_ui.hexLineEdit->setText(Utility::to_hex(hexColorValue).c_str()); } + + void CGramDebug::tileClicked(const QModelIndex &index) + { + if (!index.isValid()) + return; + this->updateInfoTile(index.row(), index.column()); + } } CGramModel::CGramModel(ComSquare::PPU::PPU &ppu) : _ppu(ppu) {} @@ -104,4 +117,11 @@ QVariant CGramModel::data(const QModelIndex &index, int role) const green = green * 255U / 31U; blue = blue * 255U / 31U; return QColor(red, green, blue); -} \ No newline at end of file +} + +void CGramModel::enterEvent(QMouseEvent *event) +{ + this->x = event->x(); + this->y = event->y(); + emit mouseEnter(); +} diff --git a/sources/Debugger/CGramDebug.hpp b/sources/Debugger/CGramDebug.hpp index 5be7822..018b2e6 100644 --- a/sources/Debugger/CGramDebug.hpp +++ b/sources/Debugger/CGramDebug.hpp @@ -9,6 +9,9 @@ #include "../PPU/PPU.hpp" #include "../../ui/ui_cgramView.h" #include +#include +#include +#include #include "ClosableWindow.hpp" @@ -70,6 +73,8 @@ public: const int column = 16; //! @brief The number of rows const int rows = 16; + int x; + int y; explicit CGramModel(ComSquare::PPU::PPU &ppu); CGramModel(const CGramModel &) = delete; const CGramModel &operator=(const CGramModel &) = delete; @@ -81,12 +86,16 @@ public: int columnCount(const QModelIndex &parent) const override; //! @brief Return a data representing the table cell. QVariant data(const QModelIndex &index, int role) const override; + //! @brief Qt Mouse hover enter event + void enterEvent(QMouseEvent *event); +signals: + void mouseEnter(); }; namespace ComSquare::Debugger { //! @brief window that allow the user to view all data going through the memory bus. - class CGramDebug { + class CGramDebug : public QObject { private: //! @brief The QT window for this debugger. ClosableWindow *_window; @@ -116,7 +125,9 @@ namespace ComSquare::Debugger //! @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); + void updateInfoTile(int row, int column); + //! @brief Update call updateInfoTile with the correct address + void tileClicked(const QModelIndex &index); }; } diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 3eacb63..c6c337c 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -17,7 +17,11 @@ namespace ComSquare::PPU oamram(new Ram::Ram(544, ComSquare::OAMRam, "OAMRAM")), cgram(new Ram::Ram(512, ComSquare::CGRam, "CGRAM")) { + uint8_t data = 1; this->_registers._isLowByte = true; + for (int i = 0; i < 512; i++, data += 11) { + this->cgram->write_internal(i, data); + } } uint8_t PPU::read(uint24_t addr) @@ -31,7 +35,6 @@ namespace ComSquare::PPU return this->_registers._mpy.mpyh; default: throw InvalidAddress("PPU Internal Registers read ", addr); - //std::cout << "PPU Internal Registers read" << addr << std::endl; } } diff --git a/ui/cgramView.ui b/ui/cgramView.ui index d0bf2dd..23f9a6e 100644 --- a/ui/cgramView.ui +++ b/ui/cgramView.ui @@ -36,6 +36,9 @@ 324 + + true + false @@ -45,11 +48,17 @@ QFrame::Sunken + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + 0 - QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked + QAbstractItemView::AnyKeyPressed|QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked QAbstractItemView::NoDragDrop