mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-31 17:33:07 +00:00
Finishing to clean tests and adding the start of the bus logger
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "MemoryBusDebug.hpp"
|
||||
#include "../SNES.hpp"
|
||||
#include "../Utility/Utility.hpp"
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
@@ -11,12 +12,20 @@ namespace ComSquare::Debugger
|
||||
: MemoryBus(bus),
|
||||
_window(new ClosableWindow(*this, &MemoryBusDebug::disableViewer)),
|
||||
_snes(snes),
|
||||
_ui()
|
||||
_ui(),
|
||||
_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->_ui.log->setModel(&this->_model);
|
||||
this->_ui.log->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
|
||||
this->_ui.log->horizontalHeader()->setStretchLastSection(true);
|
||||
this->_ui.log->horizontalHeader()->setSectionsMovable(true);
|
||||
for (int i = 0; i < 5; i++)
|
||||
this->_ui.log->setColumnWidth(i, this->_ui.log->width());
|
||||
this->_window->show();
|
||||
}
|
||||
|
||||
@@ -34,4 +43,71 @@ namespace ComSquare::Debugger
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MemoryBusDebug::read(uint24_t addr)
|
||||
{
|
||||
return MemoryBus::read(addr);
|
||||
}
|
||||
|
||||
void MemoryBusDebug::write(uint24_t addr, uint8_t data)
|
||||
{
|
||||
MemoryBus::write(addr, data);
|
||||
}
|
||||
}
|
||||
|
||||
int BusLogModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return this->_logs.size();
|
||||
}
|
||||
|
||||
int BusLogModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
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.getName().c_str());
|
||||
case 3:
|
||||
return QString(log.accessor.getValueName(log.addr - log.accessor.getStart()).c_str());
|
||||
case 4:
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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("");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,43 @@
|
||||
#include "../../ui/ui_busView.h"
|
||||
#include "ClosableWindow.hpp"
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
//! @brief The struct used to represent memory bus logs.
|
||||
struct BusLog {
|
||||
bool write;
|
||||
uint24_t addr;
|
||||
Memory::AMemory &accessor;
|
||||
uint8_t oldData;
|
||||
uint8_t newData;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//! @brief The qt model that bind the logs to the view.
|
||||
class BusLogModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
//! @brief The logs to display.
|
||||
std::vector<ComSquare::Debugger::BusLog> _logs;
|
||||
public:
|
||||
BusLogModel() = default;
|
||||
BusLogModel(const BusLogModel &) = delete;
|
||||
const BusLogModel &operator=(const BusLogModel &) = delete;
|
||||
~BusLogModel() 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;
|
||||
//! @brief Override the headers to use hex values.
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
};
|
||||
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
//! @brief window that allow the user to view all data going through the memory bus.
|
||||
@@ -21,7 +58,12 @@ namespace ComSquare::Debugger
|
||||
SNES &_snes;
|
||||
//! @brief A widget that contain the whole UI.
|
||||
Ui::BusView _ui;
|
||||
public slots:
|
||||
//! @brief The Log visualizer model for QT.
|
||||
BusLogModel _model;
|
||||
|
||||
//! @brief Log a read/write to the debugger.
|
||||
// void log()
|
||||
public:
|
||||
//! @brief Called when the window is closed. Turn off the debugger and revert to a basic CPU.
|
||||
void disableViewer();
|
||||
public:
|
||||
@@ -30,6 +72,16 @@ namespace ComSquare::Debugger
|
||||
MemoryBusDebug &operator=(const MemoryBusDebug &) = delete;
|
||||
~MemoryBusDebug() = default;
|
||||
|
||||
//! @brief Read data at a global address and log it to the debugger.
|
||||
//! @param addr The address to read from.
|
||||
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
|
||||
uint8_t read(uint24_t addr) override;
|
||||
|
||||
//! @brief Write a data to a global address and log it to the debugger.
|
||||
//! @param addr The address to write to.
|
||||
//! @param data The data to write.
|
||||
void write(uint24_t addr, uint8_t data) override;
|
||||
|
||||
//! @brief Focus the debugger's window.
|
||||
void focus();
|
||||
|
||||
|
||||
@@ -149,10 +149,10 @@ namespace ComSquare::Debugger
|
||||
|
||||
unsigned MemoryViewer::switchToAddrTab(uint24_t addr)
|
||||
{
|
||||
std::shared_ptr<Memory::IMemory> accessor = this->_bus.getAccessor(addr);
|
||||
std::shared_ptr<Memory::AMemory> accessor = this->_bus.getAccessor(addr);
|
||||
if (!accessor)
|
||||
throw InvalidAddress("Memory viewer switch to address", addr);
|
||||
Memory::IMemory *ptr;
|
||||
Memory::AMemory *ptr;
|
||||
if (accessor->isMirror())
|
||||
ptr = accessor->getMirrored().get();
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user