Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency #25

Open
fengb opened this issue Jul 19, 2019 · 1 comment
Open

Concurrency #25

fengb opened this issue Jul 19, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@fengb
Copy link
Owner

fengb commented Jul 19, 2019

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 fengb added the enhancement New feature or request label Jul 19, 2019
@fengb
Copy link
Owner Author

fengb commented Jan 7, 2020

Potential solution:

  • Every unit owns its own "private" memory space with free read/write
  • When reading from global, it receives memory that's effectively at the beginning of runloop.
  • When communicating outside its space, we need to defer the actual writes to end of runloop.

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.

@fengb fengb changed the title Threads Concurrency Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant