starting implementing cgram debugger

This commit is contained in:
Clément Le Bihan
2020-03-27 18:52:41 +01:00
parent 71f1d8f12d
commit 1354c86a4a
8 changed files with 443 additions and 12 deletions
+75
View File
@@ -0,0 +1,75 @@
//
// Created by cbihan on 3/27/20.
//
#include "cgramDebug.hpp"
#include "../SNES.hpp"
#include <QColor>
#include "../Utility/Utility.hpp"
#include "../Exceptions/InvalidAction.hpp"
#include "../Exceptions/InvalidAddress.hpp"
namespace ComSquare::cgramDebugger
{
cgramDebug::cgramDebug(SNES &snes, ComSquare::PPU::PPU &ppu)
: _window(new ClosableWindow<cgramDebug>(*this, &cgramDebug::disableViewer)),
_snes(snes),
_ui(),
_model(),
_ppu(ppu),
{
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
this->_window->setAttribute(Qt::WA_DeleteOnClose);
this->_ui.setupUi(this->_window);
this->_ui.log->setModel(&this->_model);
this->_ui.log->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
//this->_ui.log->horizontalHeader()->setStretchLastSection(true);
this->_ui.log->horizontalHeader()->setSectionsMovable(false);
for (int i = 0; i < this->_model.column; i++)
this->_ui.log->setColumnWidth(i, this->_ui.log->width());
this->_window->show();
}
void cgramDebug::disableViewer()
{
this->_snes.disableCgramDebugging();
}
void cgramDebug::focus()
{
this->_window->activateWindow();
}
bool cgramDebug::isDebugger()
{
return true;
}
uint16_t cgramDebug::read(uint8_t addr)
{
return this->_ppu.cgramRead(addr);
}
}
int cgramModel::rowCount(const QModelIndex &) const
{
return this->rows;
}
int cgramModel::columnCount(const QModelIndex &) const
{
return this->column;
}
QVariant cgramModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::TextAlignmentRole)
return Qt::AlignCenter;
if (role != Qt::DisplayRole)
return QVariant();
if (role == Qt::BackgroundRole)
}
+89
View File
@@ -0,0 +1,89 @@
//
// Created by cbihan on 3/27/20.
//
#ifndef COMSQUARE_CGRAMDEBUG_HPP
#define COMSQUARE_CGRAMDEBUG_HPP
#include <QtWidgets/QMainWindow>
#include "../PPU/PPU.hpp"
#include "../../ui/ui_cgramView.h"
#include <QtCore/QSortFilterProxyModel>
#include "ClosableWindow.hpp"
/*namespace ComSquare::cgramDebugger
{
//! @brief The struct used to represent memory bus logs.
struct BusLog {
BusLog(bool write, uint24_t addr, std::shared_ptr<Memory::AMemory> &accessor, uint8_t oldData, uint8_t newData);
bool write;
uint24_t addr;
std::shared_ptr<Memory::AMemory> accessor;
uint8_t oldData;
uint8_t newData;
};
}*/
//! @brief The qt model that bind the logs to the view.
class cgramModel : public QAbstractTableModel
{
Q_OBJECT
public:
//! @brief The number of columns
const int column = 16;
//! @brief The number of rows
const int rows = 16;
cgramModel() = default;
cgramModel(const cgramModel &) = delete;
const cgramModel &operator=(const cgramModel &) = delete;
~cgramModel() override = default;
//! @brief The number of row the table has.
int rowCount(const QModelIndex &parent) const override;
//! @brief The number of column the table has.
int columnCount(const QModelIndex &parent) const override;
//! @brief Return a data representing the table cell.
QVariant data(const QModelIndex &index, int role) const override;
};
namespace ComSquare::cgramDebugger
{
//! @brief window that allow the user to view all data going through the memory bus.
class cgramDebug {
private:
//! @brief The QT window for this debugger.
ClosableWindow<cgramDebug> *_window;
//! @brief A reference to the snes (to disable the debugger).
SNES &_snes;
//! @brief A widget that contain the whole UI.
Ui::cgramView _ui;
//! @brief The Log visualizer model for QT.
cgramModel _model;
//! @brief A reference to the ppu
ComSquare::PPU::PPU &_ppu;
public:
//! @brief Called when the window is closed. Turn off the debugger.
void disableViewer();
public:
explicit cgramDebug(SNES &snes, ComSquare::PPU::PPU &ppu);
cgramDebug(const cgramDebug &) = delete;
cgramDebug &operator=(const cgramDebug &) = delete;
~cgramDebug() = default;
//! @brief Read data at the CGRAM address send it to the debugger.
//! @param addr The address to read from.
//! @return The color value in BGR, looks like this xbbbbbgggggrrrrr.
uint16_t read(uint8_t addr) override;
//! @brief Focus the debugger's window.
void focus();
//! @brief Return true if the Bus is overloaded with debugging features.
bool isDebugger() override;
};
}
#endif //COMSQUARE_CGRAMDEBUG_HPP