gergoerdi/clash-spaceinvaders

Proper memory access arbitration between video system and CPU

gergoerdi opened this issue · 3 comments

Get rid of doubled VRAM by simply not letting the CPU access VRAM while it is needed by the video system:

  • Video system loads VRAM contents in 8 bits at a time, then shifts it out into the video generator
  • CPU is suspended on video RAM read if it happens on the same cycle as video system's access

Note that because we have access to dual-port block RAM, there is no need to arbitrate on writes.

One easy (but perhaps, too easy) way to implement it would be to completely suspend the CPU during drawing the visible portion of the screen. Since we run the CPU at 12x the original speed, we probably have enough time during non-visible parts to do everything.

Not sure if this would be pedagogically a useful intermediate step towards proper read arbitration.

I've implemented this in 0fb3adc by changing cpuInMem to a Maybe value, and passing in Nothing when the video system is reading, once every 8 virtual (16 physical) pixels, into a shift-out register. The CPU aborts the current cycle's work in readMem if cpuInMem is Nothing, and retries in the next cycle.