Class CdRomAddress

Namespace
CHDSharp.Utils
Assembly
CHDSharpLib.dll

CD-ROM MSF (minute:second:frame) to LBA (logical block address) conversion helpers. MSF values use the binary-coded-decimal (BCD) representation found in CD sector headers and drive addressing (e.g. 2 minutes is 0x02, 10 minutes is 0x10).

public static class CdRomAddress
Inheritance
CdRomAddress
Inherited Members

Remarks

Per the Red Book, LBA 0 corresponds to MSF 00:02:00 (the 2-second lead-in offset, PregapFrames); a negative LBA denotes a position inside the lead-in. LbaToMsfAlt(int) / MsfToLbaAlt(byte, byte, byte) omit this offset for systems (Sega CD, PC Engine) that address frames relative to the start of the disc data.

Fields

FramesPerSecond

CD frames per second.

public const int FramesPerSecond = 75

Field Value

int

PregapFrames

The 2-second (150-frame) lead-in offset between MSF and LBA addressing.

public const int PregapFrames = 150

Field Value

int

SecondsPerMinute

Seconds per minute in an MSF address.

public const int SecondsPerMinute = 60

Field Value

int

Methods

LbaToMsf(int)

Converts an LBA to a BCD MSF address, adding the PregapFrames lead-in offset: LBA 0 becomes 00:02:00, LBA -150 becomes 00:00:00.

public static (byte m, byte s, byte f) LbaToMsf(int lba)

Parameters

lba int

The logical block address (may be negative for lead-in positions).

Returns

(byte m, byte s, byte f)

The BCD-encoded (minutes, seconds, frames) triple.

Exceptions

ArgumentOutOfRangeException

lba maps to a negative MSF position, or to more than 99 minutes (not representable in BCD).

LbaToMsfAlt(int)

Converts a frame count to a BCD MSF address without the PregapFrames lead-in offset (for systems that address frames from the start of the disc data, e.g. Sega CD / PC Engine).

public static (byte m, byte s, byte f) LbaToMsfAlt(int lba)

Parameters

lba int

The frame count (must be non-negative).

Returns

(byte m, byte s, byte f)

The BCD-encoded (minutes, seconds, frames) triple.

Exceptions

ArgumentOutOfRangeException

lba is negative, or maps to more than 99 minutes (not representable in BCD).

MsfToLba(byte, byte, byte)

Converts a BCD MSF address (e.g. 00:02:00 = (0x00, 0x02, 0x00)) to an LBA, subtracting the PregapFrames lead-in offset: (m*60 + s)*75 + f - 150.

public static int MsfToLba(byte m, byte s, byte f)

Parameters

m byte

Minutes, BCD-encoded (each nibble 0-9).

s byte

Seconds, BCD-encoded.

f byte

Frames, BCD-encoded.

Returns

int

The LBA, or a negative value for addresses before 00:02:00.

Exceptions

ArgumentOutOfRangeException

Any byte is not valid BCD (a nibble above 9).

MsfToLbaAlt(byte, byte, byte)

Converts a BCD MSF address to a frame count without the PregapFrames lead-in offset (for systems that address frames from the start of the disc data, e.g. Sega CD / PC Engine).

public static int MsfToLbaAlt(byte m, byte s, byte f)

Parameters

m byte

Minutes, BCD-encoded (each nibble 0-9).

s byte

Seconds, BCD-encoded.

f byte

Frames, BCD-encoded.

Returns

int

The absolute frame count.

Exceptions

ArgumentOutOfRangeException

Any byte is not valid BCD (a nibble above 9).