Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Module drain

Module drain 

Source
Expand description

Interrupt-serviced drain of a polled read.

The polled SectorReader starts a read (Setloc, ReadN) and then has to look at the controller every few milliseconds: the drive delivers a sector every 6.7 ms at double speed, keeps only a few, and hands over the newest when software is late. A frame loop that looks once per frame, and frames take 50 ms to 200 ms on a busy scene, loses most of a read that way.

This module is the cheap fix for a program that already loads with the polled reader and wants one read to proceed while the frame loop runs: it takes over only the popping. The caller starts the read the way it always did (prepare, start_read), calls start, and the CD interrupt handler pops each sector straight into the destination as it arrives. The caller looks at poll once a frame, and when it says DrainState::Done ends the read the way it always did (stop), with the polled reader’s Pause protocol, which has been proved on a console. Nothing else about the drive changes.

It is small on purpose, because the programs it is for are tight on RAM: no command state machine, no queue, no token. The handler, its exception wrapper and its private stack come to about 1.5 KB. The full transport in the crate root (install, submit) owns the whole drive, commands included, and is the one to use when every read can go through it. Do not use both in one program at the same time: each puts a wrapper in the exception vector and both would answer a CD interrupt.

§What the program has to hold to

  • From start until poll reports something other than DrainState::Running, or cancel, nothing else touches the CD controller: no polled command, no polled read.
  • The destination is not read or written by anything else until then.
  • After Done or Failed the program ends the read with the polled reader’s stop and calls cancel (or start again).
  • install_vblank_counter takes psx-rt’s handler back and drops the wrapper; start puts it in again when it notices, so a program that calls it for every scene needs nothing else.

Enums§

DrainFailure
Why a drain gave up.
DrainState
Where a drain stands.

Constants§

DRAIN_STACK_BYTES
Bytes of private stack the handler runs on. The handler is a flat loop with a small frame: the deepest call measured used 112 bytes (Half-Life, five weapon switches in the emulator, stack painted by start).

Functions§

cancel
End the drain: the CD source is closed and the state goes back to DrainState::Idle. Call it after Done or Failed, or to give up on a running one. It does not touch the drive: the caller ends the read with the polled reader’s stop.
poll
Where the drain is. Also runs the no-progress check: a drain that has stored nothing for the timeout_vblanks given to start fails.
stack_unused_bytes
Bytes of the handler’s stack never touched since start painted it (when it put the wrapper in the vector).
start⚠
Hand the sectors of a read the caller has just started to the CD interrupt handler.