merge cpu into ppu

This commit is contained in:
Clément Le Bihan
2020-05-14 18:22:07 +02:00
9 changed files with 104 additions and 41 deletions
+14 -5
View File
@@ -5,11 +5,9 @@
#include "CPUDebug.hpp"
#include "../../Utility/Utility.hpp"
#include "../../Exceptions/InvalidOpcode.hpp"
#include "../../CPU/CPU.hpp"
#include <QtEvents>
#include <QPainter>
#include <iostream>
#include <utility>
using namespace ComSquare::CPU;
@@ -21,7 +19,7 @@ namespace ComSquare::Debugger
_ui(),
_model(*this),
_painter(*this),
_stackModel(*this->_bus, *this),
_stackModel(this->_bus, *this),
_snes(snes)
{
this->_window->setContextMenuPolicy(Qt::NoContextMenu);
@@ -70,6 +68,12 @@ namespace ComSquare::Debugger
this->_snes.disableCPUDebugging();
}
void CPUDebug::setMemoryBus(std::shared_ptr<Memory::MemoryBus> bus)
{
this->_stackModel.setMemoryBus(bus);
CPU::setMemoryBus(bus);
}
unsigned CPUDebug::update()
{
try {
@@ -379,7 +383,12 @@ QSize RowPainter::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) co
return QSize();
}
StackModel::StackModel(ComSquare::Memory::MemoryBus &bus, ComSquare::Debugger::CPUDebug &cpu) : _bus(bus), _cpu(cpu) { }
StackModel::StackModel(std::shared_ptr<ComSquare::Memory::MemoryBus> bus, ComSquare::Debugger::CPUDebug &cpu) : _bus(bus), _cpu(cpu) { }
void StackModel::setMemoryBus(std::shared_ptr<ComSquare::Memory::MemoryBus> bus)
{
this->_bus = std::move(bus);
}
int StackModel::rowCount(const QModelIndex &) const
{
@@ -405,7 +414,7 @@ QVariant StackModel::data(const QModelIndex &index, int role) const
return QVariant();
uint16_t addr = index.row() * 2 + index.column();
try {
uint8_t value = this->_bus.read(addr);
uint8_t value = this->_bus->read(addr, true);
return (ComSquare::Utility::to_hex(value, ComSquare::Utility::NoPrefix).c_str());
} catch (std::exception &) {
return "??";
+8 -2
View File
@@ -34,10 +34,10 @@ class StackModel : public QAbstractTableModel
{
Q_OBJECT
private:
ComSquare::Memory::MemoryBus &_bus;
std::shared_ptr<ComSquare::Memory::MemoryBus> _bus;
ComSquare::Debugger::CPUDebug &_cpu;
public:
explicit StackModel(ComSquare::Memory::MemoryBus &bus, ComSquare::Debugger::CPUDebug &cpu);
explicit StackModel(std::shared_ptr<ComSquare::Memory::MemoryBus> bus, ComSquare::Debugger::CPUDebug &cpu);
StackModel(const StackModel &) = delete;
const StackModel &operator=(const StackModel &) = delete;
~StackModel() override = default;
@@ -50,6 +50,9 @@ public:
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;
//! @brief Change the memory bus used by the view.
void setMemoryBus(std::shared_ptr<ComSquare::Memory::MemoryBus> bus);
};
//! @brief The qt model that show the history.
@@ -285,6 +288,9 @@ namespace ComSquare::Debugger
//! @brief Override the basic cpu's update to allow pausing of the CPU only.
unsigned update() override;
//! @brief Change the memory bus used by the CPU.
void setMemoryBus(std::shared_ptr<Memory::MemoryBus> bus) override;
};
}
+5 -5
View File
@@ -42,13 +42,13 @@ namespace ComSquare::Debugger
ctx.mFlag = true;
ctx.xFlag = true;
} else {
uint8_t m = this->_bus->read(pc - 1);
uint8_t m = this->_bus->read(pc - 1, true);
ctx.mFlag &= ~m & 0b00100000u;
ctx.xFlag &= ~m & 0b00010000u;
}
}
if (instruction.opcode == 0xE2) { // SEP
uint8_t m = this->_bus->read(pc - 1);
uint8_t m = this->_bus->read(pc - 1, true);
ctx.mFlag |= m & 0b00100000u;
ctx.xFlag |= m & 0b00010000u;
}
@@ -150,7 +150,7 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getAbsoluteValue(uint24_t pc)
{
uint24_t value = this->_bus->read(pc) + (this->_bus->read(pc + 1, true) << 8u);
uint24_t value = this->_bus->read(pc, true) + (this->_bus->read(pc + 1, true) << 8u);
return Utility::to_hex(value, Utility::HexString::AsmPrefix);
}
@@ -193,13 +193,13 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getAbsoluteIndexByXValue(uint24_t pc)
{
uint24_t value = this->_bus->read(pc) + (this->_bus->read(pc + 1, true) << 8u);
uint24_t value = this->_bus->read(pc, true) + (this->_bus->read(pc + 1, true) << 8u);
return Utility::to_hex(value, Utility::HexString::AsmPrefix) + ", x";
}
std::string CPUDebug::_getAbsoluteIndexByYValue(uint24_t pc)
{
uint24_t value = this->_bus->read(pc) + (this->_bus->read(pc + 1, true) << 8u);
uint24_t value = this->_bus->read(pc, true) + (this->_bus->read(pc + 1, true) << 8u);
return Utility::to_hex(value, Utility::HexString::AsmPrefix) + ", y";
}
+1 -1
View File
@@ -150,7 +150,7 @@ namespace ComSquare::Debugger
uint8_t MemoryBusDebug::read(uint24_t addr, bool silence)
{
if (!silence && !forceSilence) {
if (!silence && !this->forceSilence) {
auto accessor = this->getAccessor(addr);
if (!accessor) {
this->_model.log(BusLog(true, addr, accessor, this->_openBus, this->_openBus));