From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Format:CHD (MAME Compressed Hunks of Data)" |
|---|
| claim | "For the CD codecs cdzl (zlib), cdlz (LZMA sectors, zlib subcode) and cdzs (zstd) the decompressed hunk is a whole number of 2448-byte frames (2352 sector bytes then 96 subcode bytes; init fails if hunkbytes % 2448 != 0; CD_FRAMES_PER_HUNK is 8). The compressed hunk of these three (shared cd_codec_decompress) is: an ECC bitmap of (frames+7)/8 bytes (bit n set = frame n's 12-byte sync header and ECC were stripped), then the compressed length of the sector stream as a big-endian u16 (u24 if the decompressed size is 65536 or more), then the sector stream (frames*2352 bytes decompressed) and finally the subcode stream (frames*96 bytes; only decoded when WANT_SUBCODE, default 1). For each frame whose bit is set the reader writes the sync pattern 00 FF*10 00 and regenerates P/Q parity with ecc_generate; that regeneration exists when WANT_RAW_DATA_SECTOR is on (default 1 in chdconfig.h). The FLAC codec cdfl has a different layout: no bitmap and no length prefix, a FLAC stream of the sector bytes (as 44100 Hz stereo 16-bit samples) followed directly by the zlib subcode stream, and no sync or ECC regeneration; it shares the 2448-byte frame size and the hunkbytes % 2448 check." |
|---|
| scope | | level | "format" |
|---|
| applies_to | "CHD CD codecs, libchdr cd_codec_decompress" |
|---|
| observed_in | |
|---|
|
|---|
| data | | trigger | "decoding a hunk with a CD codec" |
|---|
| effect | "frame stride 2448; bitmap, length, sector stream, subcode stream" |
|---|
| function | "cd_codec_decompress" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "complen_bytes, ecc_bytes, header_bytes, complen_base, bitmap test, sync copy and ecc_generate" |
|---|
| repo | "https://github.com/rtissera/libchdr" |
|---|
| commit | "47d794151b2b64f6aba60304e6480f4f5a2bc24b" |
|---|
| path | "src/libchdr_cdrom.c" |
|---|
| lines | "531-600, 640-655" |
|---|
|
| type | "source" |
|---|
| detail | "cdzl init requires hunkbytes % CD_FRAME_SIZE == 0; stream sizes" |
|---|
| repo | "https://github.com/rtissera/libchdr" |
|---|
| commit | "47d794151b2b64f6aba60304e6480f4f5a2bc24b" |
|---|
| path | "src/libchdr_codec_cdzl.c" |
|---|
| lines | "15-47" |
|---|
|
| type | "source" |
|---|
| detail | "CD_MAX_SECTOR_DATA, CD_MAX_SUBCODE_DATA, CD_FRAMES_PER_HUNK" |
|---|
| repo | "https://github.com/rtissera/libchdr" |
|---|
| commit | "47d794151b2b64f6aba60304e6480f4f5a2bc24b" |
|---|
| path | "include/libchdr/cdrom.h" |
|---|
| lines | "26-34" |
|---|
|
| type | "source" |
|---|
| detail | "WANT_RAW_DATA_SECTOR default" |
|---|
| repo | "https://github.com/rtissera/libchdr" |
|---|
| commit | "47d794151b2b64f6aba60304e6480f4f5a2bc24b" |
|---|
| path | "include/libchdr/chdconfig.h" |
|---|
| lines | "6-7" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "CD codec hunk layout" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-19T11:59:03.652Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T13:17:08.488Z" |
|---|
| result | "confirmed" |
|---|
| method | "Read libchdr libchdr_cdrom.c cd_codec_decompress (both CHDR_CD_SCRATCH_BUFFER variants), codec_cdzl/cdlz/cdzs init and decompress, codec_cdfl.c decompress, cdrom.h and chdconfig.h at 47d7941. Layout, sync string, ECC bit test and the different cdfl layout all match." |
|---|
|
|
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T12:27:01.972Z" |
|---|
| summary | "cdfl does not use this layout: it has its own decompress (libchdr_codec_cdfl.c 75-175): FLAC sector stream then zlib subcode, no ECC bitmap, no length prefix, no sync/ECC regeneration. The layout…" |
|---|
| changed | |
|---|
|
|
|---|