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 sectorlbainto this buffer”.MemorySourceholds a whole image (the tests’ synthetic discs);CueSourcemaps an LBA to a byte range of one of a cue sheet’s files and asks anImageReaderfor it, which a web page implements over slices of the user’s file (a closure(file, offset, buffer) -> bytes readis one),MemoryImagesover whole files in memory and, natively only,FileImagesover 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,TRACKwithMODE1/2352orAUDIO,INDEX 00/01; several FILEs laid end to end;PREGAPrefused).Disc: tracks plus a source.Disc::from_cue_path(native) is the reference’sDisc.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_countis the number of LBAs. - File
Images - The cue sheet’s files on disk (native only: nothing else in the crate touches a file).
- Memory
Images - The cue sheet’s files, each whole in memory.
- Memory
Source - 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§
- Image
Reader - Bytes of the files a cue sheet names:
out.len()bytes of filefile(its index inCueSheet::files) fromoffset; returns how many were read (fewer at the end of a file). A web page implements this overBlob.sliceof the user’s file, or hands in a closure. - Sector
Source - Where a disc’s sectors come from.
lbais inside the disc (0 <= lba < sector_count:Discanswers 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_bytesanswers the length in bytes of a file the sheet names (a page asks theFilethe user chose;Disc::from_cue_pathasks the filesystem). - relative_
msf - A track-relative position (no lead-in).
- to_bcd