Format:Nintendo BIOS Huffman and run-length
| On this wiki | Facts · Code · Notes · Topics |
|---|
The two other compressed-data types of the GBA/DS BIOS besides LZ77: Huffman (header byte 0x2n, tree then 32-bit bitstream) and run-length (0x30), as mGBA decodes them.
Sibling types of Format:Nintendo LZ77 (LZ10 and LZ11): every BIOS-compressed blob starts with a 32-bit little-endian header whose low byte is the type and whose bits 8-31 are the decompressed size in bytes. Used by Platform:Game Boy Advance/BIOS calls 0x13 (HuffUnComp) and 0x14/0x15 (RLUnComp) and by the same calls on Platform:Nintendo DS.
Run-length (type 0x30)
After the header come blocks: a flag byte; if bit 7 is set, the next byte is repeated (flag & 0x7F) + 3 times, otherwise (flag & 0x7F) + 1 literal bytes follow. Decoding stops when the size is reached. See Fact:Nintendo BIOS Huffman and run-length/behavior/Run-length blocks.
Huffman (type 0x2n)
The low nibble of the header byte is the symbol width in bits (4 or 8 in practice). Byte 4 is the tree size field: the tree occupies (byte4 * 2) + 1 bytes starting at offset 5; the 32-bit-aligned bitstream starts right after the tree. Each tree node is a byte: bits 0-5 offset, bit 6 right child is a leaf, bit 7 left child is a leaf; the children are the byte pair at (node_address & ~1) + offset * 2 + 2 (left) and +1 more (right), and a leaf byte is the output symbol. The bitstream is read most significant bit first from little-endian 32-bit words, bit 1 = right, 0 = left; symbols fill each output word from the least significant end. mGBA does not support widths where 32 % width != 0 or width 1. See Fact:Nintendo BIOS Huffman and run-length/behavior/Huffman tree and bitstream.
Recognition
A 4-byte header whose low byte is 0x24 or 0x28 followed by a size is Huffman; 0x30 is run-length; 0x10 is LZ77. Unverified: that values with other low nibbles (0x21, 0x22) occur in shipped data; test by scanning asset tables for 0x2n headers.
Code & repositories
- https://github.com/mgba-emu/mgba @
9660a668f2093cb4aba5983f52bebf8878dc5b8b· license: MPL-2.0
GBA/GB emulator (MPL-2.0). Read for SWI names (include/mgba/internal/gba/bios.h), HLE BIOS and decompressors (src/gba/bios.c), save chips (src/gba/savedata.c, memory.c) and ROM/multiboot detection (src/gba/gba.c).
Tested on: source read, not run · checked 2026-10-19; last activity 2026-10-17; Note: the latest release ships binaries; the wiki links only the source, never the binaries
Evidence & references
mGBA (MPL-2.0) src/gba/bios.c at commit 9660a668f2093cb4aba5983f52bebf8878dc5b8b: _unHuffman lines 721-791, node bitfield lines 716-719, _unRl from line 793.