Code: Select all
CDROM Disk Images CHD (MAME)
----------------------------
All numbers are stored in Motorola (big-endian) byte ordering.
V1/V2 header:
000h 08h ID "MComprHD" (MAME Compressed Hunks of Data)
008h 4 Length of header (4Ch=V1, 50h=V2)
00Ch 4 Drive format version (probably 1/2 = V1/V2)
010h 4 Flags (bit0=DriveHasParent, bit1=AllowWrites)
014h 4 Compression type (0=None, 1=ZLIB)
018h 4 Number of sectors per hunk
01Ch 4 Total number of hunks represented
020h 4 Number of cylinders on hard disk
024h 4 Number of heads on hard disk
028h 4 Number of sectors on hard disk
02Ch 10h MD5 checksum on raw data
03Ch 10h MD5 checksum on parent file
N/A - V1: Uses fixed 200h-byte Sector size
04Ch (4) V2: Number of bytes per sector
... ? Supposedly followed by map and/or data at whatever locations
V1/V2 map format (64bit entries with 44bit+20bit):
44bit Starting offset within the file
20bit Length of data; if == hunksize, data is uncompressed
Unknown if offset is in Upper 44bit or Lower 44bit.
V3/V4 header:
000h 08h ID "MComprHD" (MAME Compressed Hunks of Data)
008h 4 Length of header (78h=V3, 6Ch=V4)
00Ch 4 Drive format version (probably 3/4=V3/V4)
010h 4 Flags (bit0=DriveHasParent, bit1=AllowWrites)
014h 4 Compression type (0=None, 1=ZLIB, 2=ZLIB_PLUS) (V4: 3=AV)
018h 4 Total Number of hunks represented
01Ch 08h Logical size of the data (in bytes) ;uh, logical of what?
024h 08h Offset to the first blob of metadata
02Ch 10h V3: MD5 checksum on raw data ;\.
03Ch 10h V3: MD5 checksum on parent file ;
04Ch 4 V3: Number of bytes per hunk ; V3
050h 14h V3: SHA1 checksum on raw data ;
064h 14h V3: SHA1 checksum on parent file ;/
02Ch 4 V4: Number of bytes per hunk ;\.
030h 14h V4: SHA1 checksum on raw+meta ; V4
044h 14h V4: SHA1 checksum on raw+meta of parent ;
058h 14h V4: SHA1 checksum on raw data ;/
... ? Supposedly followed by map, metadata, and/or data ?
V3/V4 map format:
000h 8 Starting offset within the file
008h 4 CRC32 of the uncompressed data
00Ch 2 Lower 16 bits of length ;\mixed-endian?
00Eh 1 Upper 8 bits of length ;/
00Fh 1 Flags, indicating compression info (=whut? maybe below V34 stuff?)
V34_MAP_ENTRY_FLAG_TYPE_MASK = 0x0f; // what type of hunk
V34_MAP_ENTRY_FLAG_NO_CRC = 0x10; // no CRC is present
V3-V4 entry types
V34_MAP_ENTRY_TYPE_INVALID = 0 invalid type
V34_MAP_ENTRY_TYPE_COMPRESSED = 1 standard compression
V34_MAP_ENTRY_TYPE_UNCOMPRESSED = 2 uncompressed data
V34_MAP_ENTRY_TYPE_MINI = 3 mini: use offset as raw data
V34_MAP_ENTRY_TYPE_SELF_HUNK = 4 same as another hunk in this file
V34_MAP_ENTRY_TYPE_PARENT_HUNK = 5 same as a hunk in the parent file
V34_MAP_ENTRY_TYPE_2ND_COMPRESSED = 6 compressed with secondary algorithm
(2nd algorithm is usually FLAC CDDA)
V5 header:
000h 8 ID "MComprHD" (MAME Compressed Hunks of Data)
008h 4 Length of header (7Ch=V5)
00Ch 4 Drive format version (05h=V5)
010h 4x4 Which custom compressors are used?
020h 8 Logical size of the data (in bytes)
028h 8 Offset to the map (3D797h)
030h 8 Offset to the first blob of metadata (7Ch)
038h 4 Number of bytes per hunk (512k maximum)
03Ch 4 Number of bytes per unit within each hunk
040h 14h SHA1 on raw data
054h 14h SHA1 on raw+meta
068h 14h SHA1 on raw+meta of parent (0=No parent)
... .. Metadata Chunk(s)
... .. Compressed Sectors (aka hunks)
... .. Map
If compressors[0] == 0, we are uncompressed (including maps)
V5 uncompressed map format:
000h 4 32bit offset; // starting offset / hunk size ;=whut? ;"/"=divide?
V5 compressed map format header:
000h 4 Length of compressed map
004h 6 Offset of first block (48bit) (E4h, after meta)
00Ah 2 CRC16 of the map
00Ch 1 bits used to encode complength
00Dh 1 bits used to encode self-refs
00Eh 1 bits used to encode parent unit refs
00Fh 1 Reserved for future use (probably zero)
... probably followed by some kind of bitstream with whatever values
... GUESS: 2bit compression type
... GUESS: Nbit compression length
... GUESS: whatever self-refs and parent unit refs?
... GUESS: 16bit CRC16
... (which will result in below info; when expanding Nbit to 24bit, etc.)
Each compressed map entry, once expanded, looks like:
000h 1 Compression type
001h 3 Compressed length (24bit)
004h 6 Offset (48bit) (=sum of base+preceeding lengths?)
00Ah 2 CRC16 of the data (before/after decompression?)
V5 compression codecs:
0,0,0,0 = CHD_CODEC_NONE ;-uncompressed data
"zlib" = CHD_CODEC_ZLIB ;\.
"lzma" = CHD_CODEC_LZMA ; general codecs
"huff" = CHD_CODEC_HUFFMAN ;
"flac" = CHD_CODEC_FLAC ;/
"cdzl" = CHD_CODEC_CD_ZLIB ;\.
"cdlz" = CHD_CODEC_CD_LZMA ; general codecs with CD frontend
"cdfl" = CHD_CODEC_CD_FLAC ;/
"avhu" = CHD_CODEC_AVHUFF ;-A/V codecs
V3/V4/V5 Metadata
Overall Metadata chunk format:
000h 4 Chunk ID (aka Blob Tag) (eg. "CHT2" for each CDROM track)
004h 1 Unknown (1) maybe some kind of flag/type?
005h 1 Unknown (0) ;\maybe MSB(s) of below size?
006h 1 Unknown (0) ;/
007h 1? Chunk Data Size
008h 8 Offset to next Chunk (or 0=None, in last chunk)
010h .. Chunk Data (eg. "TRACK:1 TYPE:MODE2_RAW ... POSTGAP:0",00h for CHT2)
There can be one or more chunks (a CDROM image has one CHT2 chunk per track).
Summary of Chunk IDs and corresponding Data entries:
ID_______Data_______________________________________________________
"GDDD" "CYLS,HEADS,SECS,BPS" ;-hard disk standard info
"IDNT" ? ;-hard disk identify info
"KEY " ? ;-hard disk key info
"CIS " ? ;-pcmcia CIS info
"CHCD" ? ;\.
"CHTR" "TRACK TYPE SUBTYPE FRAMES" ; CD-ROM
"CHT2" "TRACK TYPE SUBTYPE FRAMES PREGAP PGTYPE PGSUB POSTGAP" ;/
"CHGT" ? ;\Sega
"CHGD" "TRACK TYPE SUBTYPE FRAMES PAD PREGAP PGTYPE PGSUB POSTGAP" ;/GD-ROM
"AVAV" "FPS.%06d WIDTH HEIGHT INTERLACED CHANNELS SAMPLERATE" ;\AV
"AVLD" ? (A/V Laserdisc frame) ;/
The ASCII items are separated by spaces as shown above (or commas for GDDD).
The last item in each chunk is terminated by 00h (at least so for CHT2).
Most items are followed by a colon and decimal string (eg. TRACK:1), except,
TYPE,PGTYPE,SUBTYPE,PGSUB are followed by text strings (eg. TYPE:MODE2_RAW).
CYLS:# Hard disc number of cylinders
HEADS:# Hard disc number of heads
SECS:# Hard disc number of sectors
BPS:# Hard disc bytes per sector
TRACK:# CDROM current track number (1..99)
TYPE:string CDROM sector type/size
SUBTYPE:string CDROM subchannel info (usually "NONE")
FRAMES:# CDROM number of sectors per track (with/without pregap?)
PAD:# Sega GDROM only: whatever pad value?
PREGAP:# CDROM ... maybe number of pregap sectors? (can be HUGE !!??)
PGTYPE:string CDROM ... whatever type? (usually "MODE1"??)
PGSUB:string CDROM ... whatever subchannel (usually "RW"??)
POSTGAP:# CDROM ... maybe number of pstgap sectors? (usually 0)
FPS:#.###### AV Video(?)-frames per second? with 6-digit fraction?
WIDTH:# AV Width (in pixels?)
HEIGHT:# AV Height (in pixels?) (with/without interlace?)
INTERLACED:# AV Interlace (maybe a flag that might be maybe 0 or 1?)
CHANNELS:# AV Channels (dunno)
SAMPLERATE:# AV Samplerate (maybe some audio value in Hertz?)
For TYPE (and PGTYPE?):
"MODE1/2048" or "MODE1" 800h-byte ;\Data Mode1
"MODE1/2352" or "MODE1_RAW" 930h-byte ;/
"MODE2/2336" or "MODE2" 920h-byte ;\.
"MODE2/2336" or "MODE2_FORM_MIX" (dupe?) 920h-byte ;
"MODE2/2048" or "MODE2_FORM1" 800h-byte ; Data Mode2
"MODE2/2324" or "MODE2_FORM2" 914h-byte ;
"MODE2/2352" or "MODE2_RAW" or "CDI/2352" 930h-byte ;/
"AUDIO" 930h-byte ;-Audio CD-DA
For SUBTYPE and PGSUB:
"RW" 60h-byte interleaved ;normal "cooked" 96 bytes per sector
"RW_RAW" 60h-byte uninterleaved ;raw uninterleaved 96 bytes per sector
"NONE" 0-byte ;no subcode data stored