Cleaning up

This commit is contained in:
Zoe Roux
2021-07-04 02:56:44 +02:00
57 changed files with 5597 additions and 5173 deletions
+93 -116
View File
@@ -2,208 +2,185 @@
// Created by anonymus-raccoon on 1/27/20.
//
#include <ios>
#include <iostream>
#include "SNES.hpp"
#include <ios>
#ifdef DEBUGGER_ENABLED
#include "Debugger/CPU/CPUDebug.hpp"
#include "Debugger/APUDebug.hpp"
#include "Debugger/CPU/CPUDebug.hpp"
#include "Debugger/MemoryBusDebug.hpp"
#include "Debugger/CGramDebug.hpp"
#include "Debugger/TileViewer/TileViewer.hpp"
#endif
namespace ComSquare
{
SNES::SNES(const std::string &romPath, Renderer::IRenderer &renderer) :
bus(std::make_shared<Memory::MemoryBus>()),
cartridge(std::make_shared<Cartridge::Cartridge>(romPath)),
wram(std::make_shared<Ram::Ram>(16384, WRam, "WRam")),
sram(std::make_shared<Ram::Ram>(this->cartridge->header.sramSize, SRam, "SRam")),
cpu(std::make_shared<CPU::CPU>(this->bus, cartridge->header)),
ppu(std::make_shared<PPU::PPU>(renderer)),
apu(std::make_shared<APU::APU>(renderer))
SNES::SNES(Renderer::IRenderer &renderer)
: bus(),
cartridge(),
wram(16384, WRam, "WRam"),
sram(this->cartridge.header.sramSize, SRam, "SRam"),
cpu(this->bus, cartridge.header),
ppu(renderer),
apu(renderer)
{}
SNES::SNES(const std::string &romPath, Renderer::IRenderer &renderer)
: bus(),
cartridge(romPath),
wram(16384, WRam, "WRam"),
sram(this->cartridge.header.sramSize, SRam, "SRam"),
cpu(this->bus, cartridge.header),
ppu(renderer),
apu(renderer)
{
this->bus->mapComponents(*this);
if (this->cartridge->getType() == Cartridge::Audio)
this->apu->loadFromSPC(this->cartridge);
this->bus.mapComponents(*this);
if (this->cartridge.getType() == Cartridge::Audio)
this->apu.loadFromSPC(this->cartridge);
}
void SNES::update()
{
if (this->cartridge->getType() == Cartridge::Audio)
{
this->apu->update(0x01);
if (this->cartridge.getType() == Cartridge::Audio) {
this->apu.update(0x01);
return;
}
unsigned cycleCount = this->cpu->update();
this->ppu->update(cycleCount);
this->apu->update(cycleCount);
unsigned cycleCount = this->cpu.update();
this->ppu.update(cycleCount);
this->apu.update(cycleCount);
}
void SNES::loadRom(const std::string &path)
{
this->cartridge.loadRom(path);
this->bus.mapComponents(*this);
if (this->cartridge.getType() == Cartridge::Audio)
this->apu.loadFromSPC(this->cartridge);
}
#ifdef DEBUGGER_ENABLED
void SNES::enableCPUDebuggingWithError(const DebuggableError &exception)
{
this->enableCPUDebugging(true);
#ifdef DEBUGGER_ENABLED
auto cpuDebug = std::static_pointer_cast<Debugger::CPUDebug>(this->cpu);
cpuDebug->showError(exception);
#else
(void)exception;
#endif
auto cpuDebug = std::static_pointer_cast<Debugger::CPUDebug>(this->cpu);
cpuDebug->showError(exception);
}
void SNES::enableCPUDebugging(bool pause)
{
#ifdef DEBUGGER_ENABLED
if (this->cpu->isDebugger()) {
auto cpuDebug = std::static_pointer_cast<Debugger::CPUDebug>(this->cpu);
cpuDebug->focus();
if (pause)
cpuDebug->pause(true);
} 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;
#endif
if (this->cpu->isDebugger()) {
auto cpuDebug = std::static_pointer_cast<Debugger::CPUDebug>(this->cpu);
cpuDebug->focus();
if (pause)
cpuDebug->pause(true);
} else {
this->cpu = std::make_shared<Debugger::CPUDebug>(*this->cpu, *this);
this->bus.mapComponents(*this);
}
}
void SNES::disableCPUDebugging()
{
this->cpu = std::make_shared<CPU::CPU>(*this->cpu);
this->bus->mapComponents(*this);
this->bus.mapComponents(*this);
}
void SNES::enableRamViewer()
{
#ifdef DEBUGGER_ENABLED
if (this->_ramViewer)
this->_ramViewer->focus();
else
this->_ramViewer = std::make_unique<Debugger::MemoryViewer>(*this, *this->bus);
#endif
if (this->_ramViewer)
this->_ramViewer->focus();
else
this->_ramViewer.emplace(*this, *this->bus);
}
void SNES::disableRamViewer()
{
#ifdef DEBUGGER_ENABLED
this->_ramViewer = nullptr;
#endif
this->_ramViewer = std::nullopt;
}
void SNES::enableHeaderViewer()
{
#ifdef DEBUGGER_ENABLED
if (this->_headerViewer)
this->_headerViewer->focus();
else
this->_headerViewer = std::make_unique<Debugger::HeaderViewer>(*this);
#endif
if (this->_headerViewer)
this->_headerViewer->focus();
else
this->_headerViewer.emplace(*this);
}
void SNES::disableHeaderViewer()
{
#ifdef DEBUGGER_ENABLED
this->_headerViewer = nullptr;
#endif
this->_headerViewer = std::nullopt;
}
void SNES::enableAPUDebugging()
{
#ifdef DEBUGGER_ENABLED
if (this->apu->isDebugger())
std::static_pointer_cast<Debugger::APUDebug>(this->apu)->focus();
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
if (this->apu->isDebugger())
std::static_pointer_cast<Debugger::APUDebug>(this->apu)->focus();
else {
this->apu = std::make_shared<Debugger::APUDebug>(*this->apu, *this);
this->bus.mapComponents(*this);
}
}
void SNES::disableAPUDebugging()
{
this->apu = std::make_shared<APU::APU>(*this->apu);
this->bus->mapComponents(*this);
this->bus.mapComponents(*this);
}
void SNES::enableMemoryBusDebugging()
{
#ifdef DEBUGGER_ENABLED
if (this->bus->isDebugger())
std::static_pointer_cast<Debugger::MemoryBusDebug>(this->bus)->focus();
else
{
this->bus = std::make_shared<Debugger::MemoryBusDebug>(*this, *this->bus);
this->cpu->setMemoryBus(this->bus);
}
#else
std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
#endif
if (this->bus.isDebugger())
std::static_pointer_cast<Debugger::MemoryBusDebug>(this->bus)->focus();
else {
this->bus = std::make_shared<Debugger::MemoryBusDebug>(*this, *this->bus);
this->cpu->setMemoryBus(this->bus);
}
}
void SNES::disableMemoryBusDebugging()
{
#ifdef DEBUGGER_ENABLED
this->bus = std::make_shared<Memory::MemoryBus>(*this->bus);
this->cpu->setMemoryBus(this->bus);
#else
std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl;
#endif
this->bus = std::make_shared<Memory::MemoryBus>(*this->bus);
this->cpu->setMemoryBus(this->bus);
}
void SNES::enableCgramDebugging()
{
#ifdef DEBUGGER_ENABLED
if (this->_cgramViewer)
this->_cgramViewer->focus();
else
this->_cgramViewer = std::make_unique<Debugger::CGramDebug>(*this, *this->ppu);
#endif
if (this->_cgramViewer)
this->_cgramViewer->focus();
else
this->_cgramViewer.emplace(*this, *this->ppu);
}
void SNES::disableCgramDebugging()
{
#ifdef DEBUGGER_ENABLED
this->_cgramViewer = nullptr;
#endif
this->_cgramViewer = std::nullopt;
}
void SNES::disableRegisterDebugging()
{
#ifdef DEBUGGER_ENABLED
this->_registerViewer = nullptr;
#endif
this->_registerViewer = std::nullopt;
}
void SNES::enableRegisterDebugging()
{
#ifdef DEBUGGER_ENABLED
if (this->_registerViewer)
this->_registerViewer->focus();
else
this->_registerViewer = std::make_unique<Debugger::RegisterViewer>(*this);
#endif
if (this->_registerViewer)
this->_registerViewer->focus();
else
this->_registerViewer.emplace(*this);
}
void SNES::disableTileViewerDebugging()
{
#ifdef DEBUGGER_ENABLED
this->_tileViewer = nullptr;
#endif
this->_tileViewer = std::nullopt;
}
void SNES::enableTileViewerDebugging()
{
#ifdef DEBUGGER_ENABLED
if (this->_tileViewer)
this->_tileViewer->focus();
else
this->_tileViewer = std::make_unique<Debugger::TileViewer>(*this, *this->ppu);
#endif
if (this->_tileViewer)
this->_tileViewer->focus();
else
this->_tileViewer.emplace(*this, *this->ppu);
}
}
#endif
}// namespace ComSquare