fengb / fundude

Gameboy emulator: Zig -> wasm
https://fengb.github.io/fundude/
MIT License
181 stars 8 forks source link

Concurrency #25

Open fengb opened 5 years ago

fengb commented 5 years ago

All of the sub-components are independent hardware. To model this correctly, we should push each one onto a separate thread.

MMU is the biggest problem since it's effectively global memory, but the Gameboy has some well-defined semantics around it. We might need to rethink IO.

fengb commented 4 years ago

Potential solution:

With these, the main loop can become:

while (track >= 0) : (track -= 4) {
    const mmu = fd.mmu;

    // mmu is now const
    const cpu = async fd.cpu.step(mmu, 4);
    const video = async fd.video.step(mmu, 4);
    const timer = async fd.timer.step(mmu, 4);
    const audio = async fd.audio.step(mmu, 4);

    fd.mmu.apply(await cpu);
    fd.mmu.apply(await video);
    fd.mmu.apply(await timer);
    fd.mmu.apply(await audio);
}

Yes this reinvents Erlang actors.