#include namespace GameBoyAdvance { #include "bios.cpp" #include "serialization.cpp" BIOS bios; System system; auto System::loaded() const -> bool { return _loaded; } auto System::init() -> void { } auto System::term() -> void { } auto System::power() -> void { bus.power(); player.power(); cpu.power(); ppu.power(); apu.power(); cartridge.power(); video.power(); scheduler.power(); } auto System::load() -> void { interface->loadRequest(ID::SystemManifest, "manifest.bml", true); auto document = BML::unserialize(information.manifest); if(auto bios = document["system/cpu/rom/name"].text()) { interface->loadRequest(ID::BIOS, bios, true); } cartridge.load(); serializeInit(); _loaded = true; } auto System::unload() -> void { if(!loaded()) return; cartridge.unload(); _loaded = false; } auto System::run() -> void { while(true) { scheduler.enter(); if(scheduler.exit_reason() == Scheduler::ExitReason::FrameEvent) break; } video.refresh(); } auto System::runToSave() -> void { scheduler.sync = Scheduler::SynchronizeMode::CPU; runThreadToSave(); scheduler.sync = Scheduler::SynchronizeMode::All; scheduler.active = ppu.thread; runThreadToSave(); scheduler.sync = Scheduler::SynchronizeMode::All; scheduler.active = apu.thread; runThreadToSave(); scheduler.sync = Scheduler::SynchronizeMode::None; } auto System::runThreadToSave() -> void { while(true) { scheduler.enter(); if(scheduler.exit_reason() == Scheduler::ExitReason::SynchronizeEvent) break; if(scheduler.exit_reason() == Scheduler::ExitReason::FrameEvent) { video.refresh(); } } } }