Module disc

Module disc 

Source
Expand description

The disc: a track table and sectors (disc.py).

Addresses. A sector’s LBA is its index in the disc image: LBA 0 is the first stored sector, which is absolute time 00:02:00 (the two-second lead-in gap is not stored). So msf = lba + 150 frames. The SCSI READ command and every track start in this module are in this LBA, and the READ TOC answers are MSF = LBA + 150 [doc: pcetech 8; emu: Mesen2 PceScsiBus.cpp, Geargrafx cdrom_physical_image.cpp read absolute image sectors]. A raw sector is 2352 bytes; a Mode 1 data sector keeps its 2048 payload bytes at +16 (12 sync, 4 header).

This is the one module designed for the browser and not only transcribed. The table of contents and the LBA/MSF logic are the reference’s; where the reference opens files (and expands a CHD with chdman), this crate has three separate pieces:

  • SectorSource: the sector store as a trait, “raw sector lba into this buffer”. MemorySource holds a whole image (the tests’ synthetic discs); CueSource maps an LBA to a byte range of one of a cue sheet’s files and asks an ImageReader for it, which a web page implements over slices of the user’s file (a closure (file, offset, buffer) -> bytes read is one), MemoryImages over whole files in memory and, natively only, FileImages over open files.
  • parse_cue: the cue sheet from its text plus a way to learn each named file’s length, so it needs no filesystem. The grammar is the reference’s (FILE, TRACK with MODE1/2352 or AUDIO, INDEX 00/01; several FILEs laid end to end; PREGAP refused).
  • Disc: tracks plus a source. Disc::from_cue_path (native) is the reference’s Disc.from_cue.

CHD is not read here (the reference shells out to chdman, which a browser has not, and a CHD reader would be a separately licensed dependency): extract a CHD to bin/cue first, as the gate does.

Other differences forced by Rust: LBAs are i64 and the divisions are Python’s (an audio command may name a position before LBA 0); Disc keeps its source behind a RefCell so the drive and the audio player can share one disc (Rc<Disc>), as the reference’s two objects share one; to_bcd returns the low eight bits (the reference returns an unbounded integer for a value past 159, which a register read could not hold).

Structs§

CueFile
CueSheet
A parsed cue sheet: where each file lies on the disc, and the track table.
CueSource
The sectors of a cue sheet’s files, through an ImageReader.
Disc
A sector store plus a TOC. sector_count is the number of LBAs.
FileImages
The cue sheet’s files on disk (native only: nothing else in the crate touches a file).
MemoryImages
The cue sheet’s files, each whole in memory.
MemorySource
A whole disc image in memory, the sectors end to end.
Track

Constants§

DATA_SECTOR
FRAMES_PER_SECOND
LEAD_IN_FRAMES
the two-second gap before LBA 0 [doc: Red Book; emu: all four]
RAW_SECTOR
SYNC

Traits§

ImageReader
Bytes of the files a cue sheet names: out.len() bytes of file file (its index in CueSheet::files) from offset; returns how many were read (fewer at the end of a file). A web page implements this over Blob.slice of the user’s file, or hands in a closure.
SectorSource
Where a disc’s sectors come from. lba is inside the disc (0 <= lba < sector_count: Disc answers zeros outside by itself); the source fills all 2352 bytes, with zeros for whatever it cannot read.

Functions§

from_bcd
lba_to_msf
The absolute MSF of an LBA (the +150 lead-in applied).
msf_frames
msf_to_lba
parse_cue
A cue sheet from its text. file_bytes answers the length in bytes of a file the sheet names (a page asks the File the user chose; Disc::from_cue_path asks the filesystem).
relative_msf
A track-relative position (no lead-in).
to_bcd