| 1 |
#include <gba/gba.hpp> |
| 2 |
|
| 3 |
namespace GameBoyAdvance { |
| 4 |
|
| 5 |
#include "bios.cpp" |
| 6 |
#include "serialization.cpp" |
| 7 |
BIOS bios; |
| 8 |
System system; |
| 9 |
|
| 10 |
void System::init() { |
| 11 |
} |
| 12 |
|
| 13 |
void System::term() { |
| 14 |
} |
| 15 |
|
| 16 |
void System::power() { |
| 17 |
bus.power(); |
| 18 |
player.power(); |
| 19 |
cpu.power(); |
| 20 |
ppu.power(); |
| 21 |
apu.power(); |
| 22 |
cartridge.power(); |
| 23 |
scheduler.power(); |
| 24 |
} |
| 25 |
|
| 26 |
void System::load() { |
| 27 |
string manifest = string::read({interface->path(ID::System), "manifest.bml"}); |
| 28 |
auto document = Markup::Document(manifest); |
| 29 |
|
| 30 |
interface->loadRequest(ID::BIOS, document["system/cpu/rom/name"].data); |
| 31 |
if(!file::exists({interface->path(ID::System), document["system/cpu/rom/name"].data})) { |
| 32 |
interface->notify("Error: required Game Boy Advance firmware bios.rom not found.\n"); |
| 33 |
} |
| 34 |
|
| 35 |
serialize_init(); |
| 36 |
} |
| 37 |
|
| 38 |
void System::run() { |
| 39 |
while(true) { |
| 40 |
scheduler.enter(); |
| 41 |
if(scheduler.exit_reason() == Scheduler::ExitReason::FrameEvent) break; |
| 42 |
} |
| 43 |
interface->videoRefresh(video.palette, ppu.output, 4 * 240, 240, 160); |
| 44 |
} |
| 45 |
|
| 46 |
void System::runtosave() { |
| 47 |
scheduler.sync = Scheduler::SynchronizeMode::CPU; |
| 48 |
runthreadtosave(); |
| 49 |
|
| 50 |
scheduler.sync = Scheduler::SynchronizeMode::All; |
| 51 |
scheduler.active = ppu.thread; |
| 52 |
runthreadtosave(); |
| 53 |
|
| 54 |
scheduler.sync = Scheduler::SynchronizeMode::All; |
| 55 |
scheduler.active = apu.thread; |
| 56 |
runthreadtosave(); |
| 57 |
|
| 58 |
scheduler.sync = Scheduler::SynchronizeMode::None; |
| 59 |
} |
| 60 |
|
| 61 |
void System::runthreadtosave() { |
| 62 |
while(true) { |
| 63 |
scheduler.enter(); |
| 64 |
if(scheduler.exit_reason() == Scheduler::ExitReason::SynchronizeEvent) break; |
| 65 |
if(scheduler.exit_reason() == Scheduler::ExitReason::FrameEvent) { |
| 66 |
interface->videoRefresh(video.palette, ppu.output, 4 * 240, 240, 160); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
} |