Format:Nintendo LZ77 (LZ10 and LZ11)
| On this wiki | Facts · Code · Notes · Topics |
|---|
Nintendo's LZSS family used in GBA/DS BIOS LZ77UnComp and countless first-party and third-party files: a 4-byte header (type byte 0x10 or 0x11 plus a 24-bit little-endian size), flag bytes with 8 items, MSB first.
Overview
The GBA and DS BIOS decompress LZ77 data written in the format below, so many games store assets this way. Header: byte 0 = type (0x10 = LZ10, the BIOS format; 0x11 = LZ11, an extended variant used by DS/3DS-era tools and games), bytes 1-3 = uncompressed size, 24-bit little endian. See Fact:Nintendo LZ77 (LZ10 and LZ11)/magic/LZ10 and LZ11 headers.
The same family on Platform:Game Boy Advance and Platform:Nintendo DS also has sibling types in the BIOS: 0x20 Huffman and 0x30 run-length (mGBA src/gba/bios.c, _unHuffman and _unRl: comments at lines 739 and 800 name the signature bytes 0x20 and 0x30; Huffman keeps the data bit width in the low nibble of the header word, the size in bits 8-31; RL blocks have a flag byte with bit 7 set for a compressed run of (flag & 0x7F) + 3 bytes). Unverified: some games use a 0x40 type byte for a further LZ variant; test by decoding with an LZ10 tool and comparing sizes.
Block layout (from magical/nlzss)
- Each flag byte covers 8 items, most significant bit first: 0 = copy one literal byte, 1 = a back reference.
- LZ10: token of 2 bytes, big endian: length = (high nibble) + 3, displacement = (low 12 bits) + 1.
- LZ11: first nibble of the token selects the form: 0 = 8-bit count in the next byte (length = value + 0x11), 1 = 16-bit count (length = value + 0x111), 2 to 15 = the nibble is the count minus 1 (length = nibble + 1); a 12-bit displacement + 1 always follows in the low nibble of the last count byte and the next byte. See Fact:Nintendo LZ77 (LZ10 and LZ11)/behavior/Token coding.
- The nlzss tool also has an "overlay" mode (displacement bias 3 instead of 1) for ARM9 overlays and arm9.bin compressed in place with the data read backwards. Unverified in detail.
Identification
Files starting with 10 or 11 followed by a plausible 3-byte size, and a BIOS call SWI 0x11 (LZ77UnCompWRAM) or 0x12 (LZ77UnCompVRAM) in code (confirmed: GBA_SWI_LZ77_UNCOMP_WRAM = 0x11 and GBA_SWI_LZ77_UNCOMP_VRAM = 0x12 in mgba-emu/mgba include/mgba/internal/gba/bios.h @ 9660a668f2).
Code & repositories
- https://github.com/magical/nlzss @
f27414f373eab53bfe3c1a819c40eb800323e690· license: MIT
Python LZ10/LZ11 compressor and decompressor, MIT.
Tested on: source read, not run: source read · checked 2026-10-18; last activity 2014-05-15