mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-19 13:45:11 +00:00
CGRAM debugger supports mouse clicks on tiles and the PPU's constructor init the cgram (debug)
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include "../SNES.hpp"
|
||||
#include <QColor>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <QtWidgets/QTableWidget>
|
||||
#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) {}
|
||||
@@ -105,3 +118,10 @@ QVariant CGramModel::data(const QModelIndex &index, int role) const
|
||||
blue = blue * 255U / 31U;
|
||||
return QColor(red, green, blue);
|
||||
}
|
||||
|
||||
void CGramModel::enterEvent(QMouseEvent *event)
|
||||
{
|
||||
this->x = event->x();
|
||||
this->y = event->y();
|
||||
emit mouseEnter();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#include "../PPU/PPU.hpp"
|
||||
#include "../../ui/ui_cgramView.h"
|
||||
#include <QtCore/QSortFilterProxyModel>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QTableView>
|
||||
#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<CGramDebug> *_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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
<height>324</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
@@ -45,11 +48,17 @@
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="autoScrollMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
|
||||
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::NoDragDrop</enum>
|
||||
|
||||
Reference in New Issue
Block a user