megadev-system
Megadev system coordination
Inspect the selected toolchain and the game's current communication, interrupt and Word RAM owners. Use verified integration for actual Megadev definitions and BIOS boundaries. The Lab's sy_* functions are project code, not SDK APIs. Do not substitute SGDK tasks, joypad or streaming functions.
Give each request a complete lifetime
Read command protocol when designing or changing the wire contract. Assign one writer to each mailbox field, publish metadata before its commit word, and hold it stable until the receiver retires the request. An aligned word commit does not make a multiword header atomic.
Distinguish request identity, command kind, progress and completion. Match replies to the current request; a nonzero status or a reused opcode alone is not enough. Use fixed buffer descriptors or validated bounded offsets/counts instead of passing a Main pointer for the Sub CPU to dereference.
Keep ownership separate from completion
Read handoffs and recovery before adding cancellation, deadlines or buffer reuse. A reply does not substitute for checking Word RAM mode/ownership. A timeout does not prove that the worker stopped or returned its memory.
Keep abandoned work isolated until it returns safely. Discard its output, retire both sides of the handshake, then admit another request. If the peer never returns, keep that resource unavailable and let the game continue or offer an explicit recovery path appropriate to its design. Do not silently reset the Sub CPU, force an ownership change or restart disc/audio services to recover a menu action.
Preserve platform service
Use bounded foreground work slices and keep the Sub BIOS/CD access service running. Two CPUs are not an unlimited background thread pool. The Lab's one job slot and one chunk per display tick are illustrative policies, not required game architecture.