Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Nemesis (Sega Mega Drive)

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

Tile compression of Sega Mega Drive games: a 16-bit big-endian header (bit 15 = XOR mode, low 15 bits = tile count), a table of nibble-run codes terminated by 0xFF, then a bit stream of variable-length codes, with 6-bit pattern 111111 introducing an inline run.

Overview

Nemesis is a Huffman-like nibble-run coder named after Roger Sanders (Nemesis) who reverse engineered it; Sonic games use it for 8x8 4-bpp tiles (32 bytes per tile). Decoded from Flamewing's mdcomp (src/lib/nemesis.cc).

Stream

  1. 16-bit big-endian word: bit 15 set = alternating (XOR) output mode; bits 0-14 = number of 32-byte tiles. The decoder stops after tiles * 0x20 * 8 output bits.
  2. Code table: entries until a byte 0xFF. Entry byte with bit 7 set starts a new nibble value (low 4 bits); other entries give run length ((byte & 0x70) >> 4) + 1 for the current nibble, followed by one byte holding the code bits; the code length is in the same entry (Unverified details of the length field).
  3. Bit stream (MSB first): codes map to (nibble, run length). Code bits 111111 (6 bits) mean an inline run: 3 bits repeat count - 1 then a 4-bit nibble. See Fact:Nemesis (Sega Mega Drive)/behavior/Header and inline run.

Code & repositories

  • https://github.com/flamewing/mdcomp @ 72c6df405a75d322c5b3722da46c3abb864d3793 · license: LGPL-3.0-or-later (declared by the contributor; GitHub's detector did not recognize COPYING)
    Sega Mega Drive compression library and tools (Kosinski, Kosinski+, Nemesis, Enigma, Comper, Saxman, LZKN1 ...), LGPL-3.0-or-later.
    Tested on: source read, not run: source read · checked 2026-10-18; last activity 2026-10-11; Note: the latest release ships binaries; the wiki links only the source, never the binaries

See also

Format:Kosinski, Format:Enigma (Sega Mega Drive)