// // Created by anonymus-raccoon on 1/27/20. // #include #include #include "SNES.hpp" #ifdef DEBUGGER_ENABLED #include "Debugger/CPUDebug.hpp" #endif namespace ComSquare { SNES::SNES(const std::shared_ptr &bus, const std::string &romPath, Renderer::IRenderer &renderer) : cartridge(new Cartridge::Cartridge(romPath)), cpu(new CPU::CPU(bus, cartridge->header)), ppu(new PPU::PPU(bus, renderer)), apu(new APU::APU()), wram(new Ram::Ram(16384)), sram(new Ram::Ram(this->cartridge->header.sramSize)) { bus->mapComponents(*this); } void SNES::enableCPUDebugging() { #ifdef DEBUGGER_ENABLED this->cpu = std::make_shared(*this->cpu, *this); #else std::cerr << "Debugging features are not enabled. You can't enable the debugger." << std::endl; #endif } void SNES::disableCPUDebugging() { this->cpu = std::make_shared(*this->cpu); } void SNES::enableRamViewer() { #ifdef DEBUGGER_ENABLED this->_ramViewer = std::make_shared(*this); #endif } void SNES::disableRamDebugging() { #ifdef DEBUGGER_ENABLED this->_ramViewer = nullptr; #endif } void SNES::update() { try { unsigned cycleCount = this->cpu->update(); this->ppu->update(cycleCount); this->apu->update(cycleCount); } catch (std::exception &e) { std::cerr << "An error occurred: " << e.what() << std::endl; } } }