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
startuntilpollreports something other thanDrainState::Running, orcancel, 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
DoneorFailedthe program ends the read with the polled reader’sstopand callscancel(orstartagain). install_vblank_countertakes psx-rt’s handler back and drops the wrapper;startputs it in again when it notices, so a program that calls it for every scene needs nothing else.
Enums§
- Drain
Failure - Why a drain gave up.
- Drain
State - 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 afterDoneorFailed, or to give up on a running one. It does not touch the drive: the caller ends the read with the polled reader’sstop. - poll
- Where the drain is. Also runs the no-progress check: a drain that has
stored nothing for the
timeout_vblanksgiven tostartfails. - stack_
unused_ bytes - Bytes of the handler’s stack never touched since
startpainted 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.