// // Created by anonymus-raccoon on 1/27/20. // #include #include #include "SNES.hpp" #ifdef DEBUGGER_ENABLED #include "Debugger/CPU/CPUDebug.hpp" #include "Debugger/APUDebug.hpp" #include "Debugger/MemoryBusDebug.hpp" #include "Debugger/CGramDebug.hpp" #endif namespace ComSquare { SNES::SNES(const std::string &romPath, Renderer::IRenderer &renderer) : _bus(std::make_shared()), cartridge(new Cartridge::Cartridge(romPath)), wram(new Ram::Ram(16384, WRam, "WRam")), sram(new Ram::Ram(this->cartridge->header.sramSize, SRam, "SRam")), apuRam(new APU::MemoryMap()), cpu(new CPU::CPU(this->_bus, cartridge->header)), ppu(new PPU::PPU(renderer)), apu(new APU::APU(this->apuRam)) { this->_bus->mapComponents(*this); } void SNES::update() { unsigned cycleCount = this->cpu->update(); this->ppu->update(cycleCount); this->apu->update(cycleCount); } void SNES::enableCPUDebugging(bool pause) { #ifdef DEBUGGER_ENABLED if (this->cpu->isDebugger()) { auto cpuDebug = std::static_pointer_cast(this->cpu); cpuDebug->focus(); if (pause) cpuDebug->pause(); } else this->cpu = std::make_shared(*this->cpu, *this); #else std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl; (void)pause; #endif } void SNES::disableCPUDebugging() { this->cpu = std::make_shared(*this->cpu); } void SNES::enableRamViewer() { #ifdef DEBUGGER_ENABLED if (this->_ramViewer) this->_ramViewer->focus(); else this->_ramViewer = std::make_unique(*this, *this->_bus); #endif } void SNES::disableRamViewer() { #ifdef DEBUGGER_ENABLED this->_ramViewer = nullptr; #endif } void SNES::enableHeaderViewer() { #ifdef DEBUGGER_ENABLED if (this->_headerViewer) this->_headerViewer->focus(); else this->_headerViewer = std::make_unique(*this); #endif } void SNES::disableHeaderViewer() { #ifdef DEBUGGER_ENABLED this->_headerViewer = nullptr; #endif } void SNES::enableAPUDebugging() { #ifdef DEBUGGER_ENABLED if (this->apu->isDebugger()) std::static_pointer_cast(this->apu)->focus(); else this->apu = std::make_shared(*this->apu, *this); #else std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl; #endif } void SNES::disableAPUDebugging() { this->apu = std::make_shared(*this->apu); } void SNES::enableMemoryBusDebugging() { #ifdef DEBUGGER_ENABLED if (this->_bus->isDebugger()) std::static_pointer_cast(this->_bus)->focus(); else { this->_bus = std::make_shared(*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 } void SNES::disableMemoryBusDebugging() { #ifdef DEBUGGER_ENABLED this->_bus = std::make_shared(*this->_bus); this->cpu->setMemoryBus(this->_bus); #else std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl; #endif } void SNES::enableCgramDebugging() { #ifdef DEBUGGER_ENABLED if (this->_cgramViewer) this->_cgramViewer->focus(); else this->_cgramViewer = std::make_unique(*this, *this->ppu); #endif } void SNES::disableCgramDebugging() { #ifdef DEBUGGER_ENABLED this->_cgramViewer = nullptr; #endif } }