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_MASKis set to VBlank-only (byprepare, and again by eachstart_read) untilSectorReader::stopputs 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_STATbit is acked and the controller’s five IRQ enables are switched on, then every pending controller IRQ is acked. - On the first
prepareof 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. SetModeis sent: double speed and 2048-byte user data by default.
No DMA channel is enabled: nothing here uses one.
Structs§
- Sector
Reader - Blocking, polled CD-ROM sector reader.
Constants§
- DIAG_
CD_ ERROR SectorReader::diagnosticscause byte: the drive raised INT5; the snapshot carries the error response’s status and error-code bytes.- DIAG_
PARAM_ STUCK SectorReader::diagnosticscause byte: the parameter FIFO never freed up.- DIAG_
SITE_ READ SectorReader::diagnosticscommand byte standing in for aread_sectorwait (ReadN is streaming; no command byte is in flight).- DIAG_
TIMEOUT SectorReader::diagnosticscause 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.