Merge branch 'Debugger' of github.com:AnonymusRaccoon/ComSquare into CPU

This commit is contained in:
Anonymus Raccoon
2020-05-14 17:58:00 +02:00
9 changed files with 39 additions and 15 deletions
+1 -1
View File
@@ -370,7 +370,7 @@ namespace ComSquare::APU
explicit APU(std::shared_ptr<MemoryMap> &map);
APU(const APU &) = default;
APU &operator=(const APU &) = default;
~APU() = default;
~APU() override = default;
//! @brief Read from the internal APU register.
//! @param addr The address to read from. The address 0x00 should refer to the first byte of the register.
-1
View File
@@ -7,7 +7,6 @@
#include <utility>
#include <iostream>
#include "../Exceptions/InvalidAddress.hpp"
#include "../Exceptions/InvalidOpcode.hpp"
namespace ComSquare::CPU
{
+2 -1
View File
@@ -732,6 +732,7 @@ namespace ComSquare::CPU
CPU(const CPU &) = default;
CPU &operator=(const CPU &) = delete;
~CPU() override = default;
//! @brief This function continue to execute the Cartridge code.
//! @return The number of CPU cycles that elapsed
virtual unsigned update();
@@ -766,7 +767,7 @@ namespace ComSquare::CPU
virtual bool isDebugger();
//! @brief Change the memory bus used by the CPU.
void setMemoryBus(std::shared_ptr<Memory::MemoryBus> bus);
virtual void setMemoryBus(std::shared_ptr<Memory::MemoryBus> bus);
};
}
+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);
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;
};
}
+3 -2
View File
@@ -165,9 +165,10 @@ namespace ComSquare::Debugger
void MemoryBusDebug::write(uint24_t addr, uint8_t data)
{
auto accessor = this->getAccessor(addr);
uint8_t value;
uint8_t value = 0;
try {
value = accessor->read(addr - accessor->getStart());
if (accessor)
value = accessor->read(addr - accessor->getStart());
} catch (InvalidAddress &) {
value = 0;
}
+2
View File
@@ -56,6 +56,8 @@ namespace ComSquare::Memory
void MemoryBus::mapComponents(SNES &console)
{
this->_memoryAccessors.clear();
// The WRam and PU registers are always mapped at the same address no matter the mapping mode.
console.wram->setMemoryRegion(0x7E, 0x7F, 0x0000, 0xFFFF);
this->_memoryAccessors.push_back(console.wram);
+8 -2
View File
@@ -42,8 +42,10 @@ namespace ComSquare
cpuDebug->focus();
if (pause)
cpuDebug->pause();
} else
} else {
this->cpu = std::make_shared<Debugger::CPUDebug>(*this->cpu, *this);
this->_bus->mapComponents(*this);
}
#else
std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
(void)pause;
@@ -53,6 +55,7 @@ namespace ComSquare
void SNES::disableCPUDebugging()
{
this->cpu = std::make_shared<CPU::CPU>(*this->cpu);
this->_bus->mapComponents(*this);
}
void SNES::enableRamViewer()
@@ -94,8 +97,10 @@ namespace ComSquare
#ifdef DEBUGGER_ENABLED
if (this->apu->isDebugger())
std::static_pointer_cast<Debugger::APUDebug>(this->apu)->focus();
else
else {
this->apu = std::make_shared<Debugger::APUDebug>(*this->apu, *this);
this->_bus->mapComponents(*this);
}
#else
std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
#endif
@@ -104,6 +109,7 @@ namespace ComSquare
void SNES::disableAPUDebugging()
{
this->apu = std::make_shared<APU::APU>(*this->apu);
this->_bus->mapComponents(*this);
}
void SNES::enableMemoryBusDebugging()
+1 -1
View File
@@ -1,7 +1,7 @@
/********************************************************************************
** Form generated from reading UI file 'cpu.ui'
**
** Created by: Qt User Interface Compiler version 5.14.1
** Created by: Qt User Interface Compiler version 5.14.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/