Skip to content
Rico Tyrell edited this page Oct 25, 2015 · 2 revisions

The CIM file format is fairly straightforward for the full image type (area flags set to 0x1).

All values larger than a byte are stored in big-endian format


Header

Starting with the header, this describes the location of the Single Density Area (SDA) and High Density Area (HDA) Table of Contents (TOC) as well as the disc image.

ID - 4CC format, should contain "CIMF"
File Size - Unsigned integer indicating the total file size (minus 8 bytes, possibly offset from the chunk?)
Image Type - 4CC format, should contain "GDIM"
SDA Flags - Unsigned integer, for a full image, this should be 0x1, 0x2 for a partial image
HDA Flags - Unsigned integer, for a full image, this should be 0x1, 0x2 for a partial image
SDA TOC - Starting offset of the SDA TOC (from the beginning of the file)
SDA Disc - Starting offset of the SDA Disc (from the beginning of the file)
HDA TOC - Starting offset of the HDA TOC (from the beginning of the file)
HDA Disc - Starting offset of the HDA Disc (from the beginning of the file)

!! The rest of the header format is still being worked on !!
Either three or four bytes follow, which are: 0x01 0x02 0x20 [0x00]
After that, either nine or eight bytes are for padding (16-byte alignment)


TOC

The TOC contains the ID and the offset to the disc image.

ID - 4CC, either "STOC" for the SDA or "HTOC" for the HDA
Disc Offset - Unsigned integer for the offset to the disc after this chunk
Eight bytes of padding


Track

After the TOC is the description of the tracks

Control - Byte describing the track as either data (0x41) or audio (0x01)
Track Number - Byte housing the canonical track number (track numbers transcend areas)
Transform - Byte indicating the start of a track (0x00) and the offset (0x01) to the data
Form - Byte: MODE1 (0x01)/CCDA (0x02)
Hours - Byte in BCD format (hours may not exist, as minutes are used for values going beyond 60)
Minutes - Byte in BCD format
Seconds - Byte in BCD format (75 frames in a second)
Frames - Byte in BCD format


Disc

The Disc chunk doesn't do much other than inform the user of how much space is used (or wasted, depending on how you look at it).

ID - 4CC, either "SDSK" for the SDA or "HDSK" for the HDA
Size - Unsigned integer, total size of the area's disc image
Eight bytes of padding


Extracting tracks

When extracting the data for the tracks, it's important to remember that there is a difference between the address as it appears on the disc (for the purposes of creating a GDI) and where the data ends up going. The starting address of the track is contained in the track transform 0x00, as long as the track number is 1 or greater (as track 0 is the lead in). This is combined with the offset to the data (track transform 0x01), which is used when positioning the file pointer relative to the area's starting offset.

The lead out (track number 0xAA, transform 0x01) is necessary for completing the last track on the disc, otherwise there will be n-2 tracks (where n is the total track count).

Calculating the Logical Sector Number (LSN) is mostly straightforward. The goal is to convert the track's time into an LSN. This is achieved by adding the masked byte you need with 0x0F and adding it to the 4-bit shifted, masked 0xF0 multiplied by 10. Here's an example:

// 10 in BCD
BYTE BCD10 = 0x10;
BYTE LSN = ( BCD10 & 0x0F ) + ( ( ( BCD10 & 0xF0 ) >> 4 ) * 10 );

This is how the LSN for the frame is calculated. For seconds, multiply the result by 75 (75 frames in a second), and minutes is the same as calculating the seconds then multiplying by 60.

Clone this wiki locally