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

Module reader

Module reader 

Source
Expand description

Polled CD-ROM data-sector reads: seek, stream and pop 2048-byte sectors.

SectorReader holds the Cd token and drives the controller through its register steps, so the register map, the IRQ acknowledge order and the BCD arithmetic exist once, in super. What it adds is the command sequence the pack loader and the FMV streamer have run on silicon: a SetMode-then-Setloc-then-ReadN start with every IRQ masked and every FIFO in a known state, a wait loop that drains stale responses (and a stale data sector into a bounce buffer) before it acknowledges them, and a Pause that leaves the drive spun up. The comments that record silicon findings travel with the code.

Sectors come out of the data FIFO by CPU reads (PIO), not DMA channel 3. The CL1/CL2 silicon probes convicted the chopping-burst DMA path on real hardware: the transfer is a state-dependent lottery, and the channel can latch its start bit and stay busy forever while moving nothing, which read as all-zero sectors. PIO is the recipe the same probes proved byte-perfect: arm the data request, wait until the FIFO reports data, pop all 2048 bytes. It costs about 1.3 ms more per sector than a working DMA, and it cannot wedge the DMA controller.

§What prepare does to the machine

SectorReader::prepare polls the controller’s own IRQ flags, so it keeps CD-ROM interrupts away from the CPU for the length of a stream:

  • I_MASK is set to VBlank-only (by prepare, and again by each start_read) until SectorReader::stop puts the previous value back. Every other source stops reaching the CPU in between: a CD-ROM IRQ with no handler would otherwise be an unhandled-IRQ storm.
  • The latched CD-ROM I_STAT bit is acked and the controller’s five IRQ enables are switched on, then every pending controller IRQ is acked.
  • On the first prepare of a reader, IRQs latched by earlier activity (the BIOS disc boot’s file load) are drained. Pausing instead would hang on an emulator that has no active read to pause.
  • SetMode is sent: double speed and 2048-byte user data by default.

No DMA channel is enabled: nothing here uses one.

Structs§

SectorReader
Blocking, polled CD-ROM sector reader.

Constants§

DIAG_CD_ERROR
SectorReader::diagnostics cause byte: the drive raised INT5; the snapshot carries the error response’s status and error-code bytes.
DIAG_PARAM_STUCK
SectorReader::diagnostics cause byte: the parameter FIFO never freed up.
DIAG_SITE_READ
SectorReader::diagnostics command byte standing in for a read_sector wait (ReadN is streaming; no command byte is in flight).
DIAG_TIMEOUT
SectorReader::diagnostics cause byte: the wait spun out; the snapshot carries the raw status register and the last IRQ flag seen.
SECTOR_WORDS
One CD sector’s user data in 32-bit words.