mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-21 14:45:10 +00:00
Enabling the memory bus debugger
This commit is contained in:
@@ -3,25 +3,19 @@
|
||||
//
|
||||
|
||||
#include "MemoryBusDebug.hpp"
|
||||
#include "../SNES.hpp"
|
||||
#include "../Utility/Utility.hpp"
|
||||
#include "../Exceptions/InvalidAction.hpp"
|
||||
#include "../Exceptions/InvalidAddress.hpp"
|
||||
#include "SNES.hpp"
|
||||
#include "Utility/Utility.hpp"
|
||||
#include "Exceptions/InvalidAction.hpp"
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
MemoryBusDebug::MemoryBusDebug(SNES &snes, const Memory::MemoryBus &bus)
|
||||
: MemoryBus(bus),
|
||||
_window(new ClosableWindow<MemoryBusDebug>(*this, &MemoryBusDebug::disableViewer)),
|
||||
_snes(snes),
|
||||
_ui(),
|
||||
_model(),
|
||||
_proxy(this->_model)
|
||||
MemoryBusDebug::MemoryBusDebug(SNES &snes, Memory::IMemoryBus &bus)
|
||||
: _window(new ClosableWindow([&snes] { snes.disableMemoryBusDebugging(); })),
|
||||
_bus(bus),
|
||||
_ui(),
|
||||
_model(),
|
||||
_proxy(this->_model)
|
||||
{
|
||||
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
this->_window->setAttribute(Qt::WA_QuitOnClose, false);
|
||||
this->_window->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
this->_ui.setupUi(this->_window);
|
||||
this->_proxy.setSourceModel(&this->_model);
|
||||
this->_ui.log->setModel(&this->_proxy);
|
||||
@@ -133,178 +127,165 @@ namespace ComSquare::Debugger
|
||||
this->_window->show();
|
||||
}
|
||||
|
||||
void MemoryBusDebug::disableViewer()
|
||||
{
|
||||
this->_snes.disableMemoryBusDebugging();
|
||||
}
|
||||
|
||||
void MemoryBusDebug::focus()
|
||||
{
|
||||
this->_window->activateWindow();
|
||||
}
|
||||
|
||||
bool MemoryBusDebug::isDebugger()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t MemoryBusDebug::read(uint24_t addr)
|
||||
{
|
||||
if (this->forceSilence)
|
||||
return MemoryBus::read(addr);
|
||||
return this->read(addr, false);
|
||||
uint8_t value = this->_bus.read(addr);
|
||||
this->_model.log(BusLog(false, addr, this->getAccessor(addr), value, value));
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t MemoryBusDebug::read(uint24_t addr, bool silence)
|
||||
std::optional<uint8_t> MemoryBusDebug::peek(uint24_t addr)
|
||||
{
|
||||
if (!silence && !this->forceSilence) {
|
||||
auto accessor = this->getAccessor(addr);
|
||||
if (!accessor) {
|
||||
this->_model.log(BusLog(true, addr, accessor, this->_openBus, this->_openBus));
|
||||
} else {
|
||||
uint8_t value = accessor->read(accessor->getRelativeAddress(addr));
|
||||
this->_model.log(BusLog(false, addr, accessor, value, value));
|
||||
}
|
||||
}
|
||||
return MemoryBus::read(addr, silence);
|
||||
return this->_bus.peek(addr);
|
||||
}
|
||||
|
||||
void MemoryBusDebug::write(uint24_t addr, uint8_t data)
|
||||
{
|
||||
auto accessor = this->getAccessor(addr);
|
||||
std::optional<uint8_t> value = std::nullopt;
|
||||
try {
|
||||
if (accessor)
|
||||
value = accessor->read(accessor->getRelativeAddress(addr));
|
||||
} catch (InvalidAddress &) {
|
||||
value = std::nullopt;
|
||||
}
|
||||
if (!forceSilence)
|
||||
this->_model.log(BusLog(true, addr, accessor, value, data));
|
||||
MemoryBus::write(addr, data);
|
||||
std::optional<uint8_t> value = this->peek(addr);
|
||||
this->_model.log(BusLog(true, addr, this->getAccessor(addr), value, data));
|
||||
this->_bus.write(addr, data);
|
||||
}
|
||||
|
||||
BusLog::BusLog(bool _write, uint24_t _addr, std::shared_ptr<Memory::IMemory> &_accessor, std::optional<uint8_t> _oldData, uint8_t _newData) :
|
||||
write(_write), addr(_addr), accessor(std::move(_accessor)), oldData(_oldData), newData(_newData)
|
||||
Memory::IMemory *MemoryBusDebug::getAccessor(uint24_t addr)
|
||||
{
|
||||
return this->_bus.getAccessor(addr);
|
||||
}
|
||||
|
||||
BusLog::BusLog(bool _write, uint24_t _addr,
|
||||
Memory::IMemory *_accessor,
|
||||
std::optional<uint8_t> _oldData,
|
||||
uint8_t _newData)
|
||||
: write(_write),
|
||||
addr(_addr),
|
||||
accessor(_accessor),
|
||||
oldData(_oldData),
|
||||
newData(_newData)
|
||||
{}
|
||||
}
|
||||
|
||||
int BusLogModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return this->_logs.size();
|
||||
}
|
||||
|
||||
int BusLogModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return this->column;
|
||||
}
|
||||
|
||||
QVariant BusLogModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::TextAlignmentRole)
|
||||
return Qt::AlignCenter;
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
ComSquare::Debugger::BusLog log = this->_logs[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
return QString(log.write ? "Write" : "Read");
|
||||
case 1:
|
||||
return QString(ComSquare::Utility::to_hex(log.addr).c_str());
|
||||
case 2:
|
||||
return QString(log.accessor ? log.accessor->getName().c_str() : "Bus");
|
||||
case 3: {
|
||||
uint24_t addr = log.accessor->getRelativeAddress(log.addr);
|
||||
return QString(log.accessor ? log.accessor->getValueName(addr).c_str() : "Open bus");
|
||||
int BusLogModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return static_cast<int>(this->_logs.size());
|
||||
}
|
||||
case 4:
|
||||
if (!log.oldData)
|
||||
return QString("???");
|
||||
return QString(ComSquare::Utility::to_hex(*log.oldData).c_str());
|
||||
case 5:
|
||||
return QString(ComSquare::Utility::to_hex(log.newData).c_str());
|
||||
default:
|
||||
return QVariant();
|
||||
|
||||
int BusLogModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return this->column;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole || orientation == Qt::Vertical)
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case 0:
|
||||
return QString("Type");
|
||||
case 1:
|
||||
return QString("Address");
|
||||
case 2:
|
||||
return QString("Component");
|
||||
case 3:
|
||||
return QString("Data Name");
|
||||
case 4:
|
||||
return QString("Old Data");
|
||||
case 5:
|
||||
return QString("New Data");
|
||||
default:
|
||||
return QString("");
|
||||
QVariant BusLogModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::TextAlignmentRole)
|
||||
return Qt::AlignCenter;
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
BusLog log = this->_logs[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
return QString(log.write ? "Write" : "Read");
|
||||
case 1:
|
||||
return QString(ComSquare::Utility::to_hex(log.addr).c_str());
|
||||
case 2:
|
||||
return QString(log.accessor ? log.accessor->getName().c_str() : "Bus");
|
||||
case 3: {
|
||||
uint24_t addr = log.accessor->getRelativeAddress(log.addr);
|
||||
return QString(log.accessor ? log.accessor->getValueName(addr).c_str() : "Open bus");
|
||||
}
|
||||
case 4:
|
||||
if (!log.oldData)
|
||||
return QString("???");
|
||||
return QString(ComSquare::Utility::to_hex(*log.oldData).c_str());
|
||||
case 5:
|
||||
return QString(ComSquare::Utility::to_hex(log.newData).c_str());
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BusLogModel::log(const ComSquare::Debugger::BusLog& log)
|
||||
{
|
||||
int row = this->_logs.size();
|
||||
this->beginInsertRows(QModelIndex(), row, row);
|
||||
this->_logs.push_back(log);
|
||||
this->insertRow(row);
|
||||
this->endInsertRows();
|
||||
}
|
||||
|
||||
ComSquare::Debugger::BusLog BusLogModel::getLogAt(int index)
|
||||
{
|
||||
return this->_logs[index];
|
||||
}
|
||||
|
||||
void BusLogModel::clearLogs()
|
||||
{
|
||||
this->beginResetModel();
|
||||
this->_logs.clear();
|
||||
this->endResetModel();
|
||||
}
|
||||
|
||||
BusLoggerProxy::BusLoggerProxy(BusLogModel &parent) : QSortFilterProxyModel(), _parent(parent) {}
|
||||
|
||||
bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &) const
|
||||
{
|
||||
ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow);
|
||||
|
||||
if (!log.accessor)
|
||||
return true;
|
||||
ComSquare::Component component = log.accessor->getComponent();
|
||||
switch (component) {
|
||||
case ComSquare::Component::Cpu:
|
||||
return this->filters[log.write].cpu;
|
||||
case ComSquare::Component::Ppu:
|
||||
return this->filters[log.write].ppu;
|
||||
case ComSquare::Component::Apu:
|
||||
return this->filters[log.write].apu;
|
||||
case ComSquare::Component::Rom:
|
||||
return this->filters[log.write].rom;
|
||||
case ComSquare::Component::WRam:
|
||||
return this->filters[log.write].wram;
|
||||
case ComSquare::Component::VRam:
|
||||
return this->filters[log.write].vram;
|
||||
case ComSquare::Component::CGRam:
|
||||
return this->filters[log.write].cgram;
|
||||
case ComSquare::Component::OAMRam:
|
||||
return this->filters[log.write].oamram;
|
||||
case ComSquare::Component::SRam:
|
||||
return this->filters[log.write].sram;
|
||||
default:
|
||||
return true;
|
||||
QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole || orientation == Qt::Vertical)
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case 0:
|
||||
return QString("Type");
|
||||
case 1:
|
||||
return QString("Address");
|
||||
case 2:
|
||||
return QString("Component");
|
||||
case 3:
|
||||
return QString("Data Name");
|
||||
case 4:
|
||||
return QString("Old Data");
|
||||
case 5:
|
||||
return QString("New Data");
|
||||
default:
|
||||
return QString("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BusLoggerProxy::refresh()
|
||||
{
|
||||
this->invalidateFilter();
|
||||
}
|
||||
void BusLogModel::log(const BusLog &log)
|
||||
{
|
||||
int row = static_cast<int>(this->_logs.size());
|
||||
this->beginInsertRows(QModelIndex(), row, row);
|
||||
this->_logs.push_back(log);
|
||||
this->insertRow(row);
|
||||
this->endInsertRows();
|
||||
}
|
||||
|
||||
BusLog BusLogModel::getLogAt(int index)
|
||||
{
|
||||
return this->_logs[index];
|
||||
}
|
||||
|
||||
void BusLogModel::clearLogs()
|
||||
{
|
||||
this->beginResetModel();
|
||||
this->_logs.clear();
|
||||
this->endResetModel();
|
||||
}
|
||||
|
||||
BusLoggerProxy::BusLoggerProxy(BusLogModel &parent)
|
||||
: QSortFilterProxyModel(), _parent(parent)
|
||||
{}
|
||||
|
||||
bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &) const
|
||||
{
|
||||
BusLog log = this->_parent.getLogAt(sourceRow);
|
||||
|
||||
if (!log.accessor)
|
||||
return true;
|
||||
Component component = log.accessor->getComponent();
|
||||
switch (component) {
|
||||
case Component::Cpu:
|
||||
return this->filters[log.write].cpu;
|
||||
case Component::Ppu:
|
||||
return this->filters[log.write].ppu;
|
||||
case Component::Apu:
|
||||
return this->filters[log.write].apu;
|
||||
case Component::Rom:
|
||||
return this->filters[log.write].rom;
|
||||
case Component::WRam:
|
||||
return this->filters[log.write].wram;
|
||||
case Component::VRam:
|
||||
return this->filters[log.write].vram;
|
||||
case Component::CGRam:
|
||||
return this->filters[log.write].cgram;
|
||||
case Component::OAMRam:
|
||||
return this->filters[log.write].oamram;
|
||||
case Component::SRam:
|
||||
return this->filters[log.write].sram;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void BusLoggerProxy::refresh()
|
||||
{
|
||||
this->invalidateFilter();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user