2012-03-19 11:19:53 +00:00
|
|
|
#include <gba/gba.hpp>
|
|
|
|
|
2012-04-26 10:51:13 +00:00
|
|
|
namespace GameBoyAdvance {
|
2012-03-19 11:19:53 +00:00
|
|
|
|
|
|
|
Scheduler scheduler;
|
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
auto Scheduler::power() -> void {
|
|
|
|
host = co_active();
|
|
|
|
resume = cpu.thread;
|
2015-11-16 08:38:05 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
auto Scheduler::enter(Mode mode_) -> Event {
|
|
|
|
mode = mode_;
|
2012-03-19 11:19:53 +00:00
|
|
|
host = co_active();
|
2016-02-09 11:51:12 +00:00
|
|
|
co_switch(resume);
|
|
|
|
return event;
|
2012-03-19 11:19:53 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
auto Scheduler::exit(Event event_) -> void {
|
|
|
|
event = event_;
|
|
|
|
resume = co_active();
|
2012-03-19 11:19:53 +00:00
|
|
|
co_switch(host);
|
|
|
|
}
|
|
|
|
|
2016-02-09 11:51:12 +00:00
|
|
|
auto Scheduler::synchronize(cothread_t thread) -> void {
|
|
|
|
if(thread == cpu.thread) {
|
|
|
|
while(enter(Mode::SynchronizeCPU) != Event::Synchronize);
|
|
|
|
} else {
|
|
|
|
resume = thread;
|
|
|
|
while(enter(Mode::SynchronizeAll) != Event::Synchronize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Scheduler::synchronize() -> void {
|
|
|
|
if(co_active() == cpu.thread && mode == Mode::SynchronizeCPU) return exit(Event::Synchronize);
|
|
|
|
if(co_active() != cpu.thread && mode == Mode::SynchronizeAll) return exit(Event::Synchronize);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Scheduler::synchronizing() const -> bool {
|
|
|
|
return mode == Mode::SynchronizeAll;
|
2012-03-19 11:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|