Documentation
¶
Overview ¶
Package romloader handles loading ROM files from various sources, including compressed archives (ZIP, 7z, gzip, tar.gz, RAR).
Index ¶
- Variables
- func DiscExtensions() []string
- func Load(path string, extensions []string) ([]byte, string, error)
- func LoadBIOS(path string) ([]byte, error)
- type Disc
- func (d *Disc) Close() error
- func (d *Disc) NumTrackIndexes(i int) int
- func (d *Disc) NumTracks() int
- func (d *Disc) ReadSector(lba int) ([]byte, error)
- func (d *Disc) ReadSectorData(lba int) ([]byte, error)
- func (d *Disc) Track(i int) (number int, typ string, frames int, pregap int, startLBA int, control uint8)
- func (d *Disc) TrackIndex(i, n int) (indexNumber int, lba int)
Constants ¶
This section is empty.
Variables ¶
var ErrFileTooLarge = errors.New("file exceeds maximum size limit")
ErrFileTooLarge is returned when extracted content exceeds size limit
var ErrNoFile = errors.New("no matching file found in archive")
ErrNoFile is returned when no matching file is found in an archive
var ErrUnsupportedDisc = errors.New("romloader: unsupported disc format (expected .chd or .cue)")
ErrUnsupportedDisc is returned by OpenDisc when the path's extension is neither .chd nor .cue.
var ErrUnsupportedFormat = errors.New("unsupported file format")
ErrUnsupportedFormat is returned for unrecognized file formats
Functions ¶
func DiscExtensions ¶ added in v0.4.0
func DiscExtensions() []string
DiscExtensions returns the lowercase file extensions OpenDisc accepts, each with a leading dot (".chd", ".cue"), sorted ascending. Callers that scan a directory or filter a file list use it to discover which files are disc images without hardcoding the set. Unlike ROM images, where the core declares the extensions it understands, the disc formats are owned by romloader: a core reads a disc through a format-agnostic interface and never sees the file, so romloader is the only component that knows which container formats it can open.
func Load ¶
Load reads a ROM from a file path. It auto-detects compressed archives via magic bytes and extracts the first file matching one of the given extensions. For raw (non-archive) files, the extension must match or the file is loaded as-is if no archive format is detected.
Returns the ROM data, the filename (basename only, useful for display), and any error.
Types ¶
type Disc ¶ added in v0.3.0
type Disc struct {
// contains filtered or unexported fields
}
Disc is a streaming reader over a disc image. It owns the open file handles and decodes sectors on demand, so the whole image is never read into memory. Internally it is a facade over a format-specific backend (CHD or bin/cue); OpenDisc selects the backend. Its method set uses only stdlib types so it satisfies a disc-reader interface structurally without a shared type.
func OpenDisc ¶ added in v0.3.0
OpenDisc opens a disc image for streaming, selected by extension: ".chd" is opened as a CHD image, ".cue" as a cue sheet whose referenced bin track files are opened and held for the disc's lifetime. Any other extension returns ErrUnsupportedDisc. File handles are held open for on-demand sector reads until Close is called.
func (*Disc) NumTrackIndexes ¶ added in v0.4.0
NumTrackIndexes returns the count of index entries (index numbers >= 1) exposed for track index i in [0, NumTracks). Index 0 (the pregap) is never reported here; it is implied for any FAD below the first entry.
func (*Disc) ReadSector ¶ added in v0.3.0
ReadSector returns the raw 2352-byte sector at the given LBA.
func (*Disc) ReadSectorData ¶ added in v0.4.1
ReadSectorData returns the cooked user data of the sector at the given absolute LBA: the 2048-byte user-data region of a Mode 1 or Mode 2 (Form 1) data sector with the sync/header (and Mode 2 subheader) stripped. Audio sectors have no header and are returned whole (the full 2352 bytes). Use it when a consumer identifies a disc by its volume/boot headers rather than raw sector bytes; ReadSector remains the raw view.
func (*Disc) Track ¶ added in v0.3.0
func (d *Disc) Track(i int) (number int, typ string, frames int, pregap int, startLBA int, control uint8)
Track returns the TOC fields for track index i in [0, NumTracks).
func (*Disc) TrackIndex ¶ added in v0.4.0
TrackIndex returns the nth index entry of track index i. n is a 0-based ordinal into the exposed list in [0, NumTrackIndexes(i)), not the index number; entry 0 is the lowest-numbered exposed index (normally INDEX 01). The returned lba is the absolute disc LBA of the index.