FOR MODDERS AND HACKERS

Decoding graphics

From a .16 file to pixels: expand the LZW stream, find the records, read each record's size, unpack the pixels, then look up the colours. Every number below comes from rules GFX-0001 to GFX-0008; the build recomputes the archive offsets and checks them against those rules.

Working code (MIT): lzw.go · decode.go · catalog.go · model.go

  1. 1. File.16 .4 .BIT .PCS
  2. 2. ExpandLZW
  3. 3. Recordscount + offsets
  4. 4. Recordwidth, height
  5. 5. Pixels4-bit or 1-bit
  6. 6. ColoursEGA palette

1. Compressed or not

GFX-0001 Original: Incomplete
LZW-compressedPROPORT.PCSBRITISH.BITTITLE.BITTILES.16ITEMS.16DNG1–3.16MON0–7.16CREATE.16TEXT.16STORY1–6.16END1.16END2.16ULTIMA.16STARTSC.16ENDSC.16
Stored directlyWD.BITIBM.CHRUNES.CHBRITISH.PTH

On CGA and Hercules, picture names end in .4; Hercules fixed fonts end in .HCS.

2. Expand the LZW stream

GFX-0001 Original: Incomplete
PartValue
Header4-byte little-endian expanded length
Code orderLeast significant bit first
Code widthStarts at 9 bits, grows to 12
ClearCode 256; the stream must start with it. It resets the width, the next entry and the previous sequence.
EndCode 257
First new entryCode 258
Grow the widthWhen the next entry index reaches 2^width
Dictionary4,096 entries; when full, stop adding until the next clear
After the endRedux checks the declared length and that any padding is zero

Redux's decoding model as pseudocode

length = u32le(data[0:4])
reset(): width = 9; next = 258; prev = none
for each code (LSB-first, width bits):
  if code == 256: reset(); continue
  if code == 257: stop
  if code < next:    entry = dict[code]
  elif code == next: entry = prev + prev[0]
  else: corrupt
  output(entry)
  if prev and next < 4096:
    dict[next] = prev + entry[0]; next += 1
    if next == 2**width and width < 12: width += 1
  prev = entry
check len(output) == length
How sure is this?

One complete file has been checked: expanding the shipped TILES.16 with this model reproduces its source sheets byte for byte. Every stream transition, the full-dictionary case, trailing padding and corrupt input have not been checked against original samples, and a working decoder is not proof of every original rule.

3. Find the records

GFX-0002 Original: EstablishedGFX-0003 Original: IncompleteGFX-0004 Original: Established

After expanding, each archive starts with a little-endian 16-bit count, then a table of offsets from the start of the expanded data. A zero offset means an empty slot.

ArchiveCountOffset tableRecords
Pictures: CREATE, TEXT, STORY1–6, END1–2, ULTIMA, STARTSC, ENDSCRecords4 bytes each: low word, then a high word that is zero in the reviewed buildsCREATE 11, TEXT 6, STORY 3/4/2/2/2/8, END 3 each, ULTIMA 5, STARTSC 3, ENDSC 1
Dungeon panels: DNG1–328 slots4 bytes each; slots 8 and 24 are empty26 panels
Items: ITEMS20 imagesTwo 16-bit offsets per image: image, mask, image, mask…40 records
Monsters: MON0–76 imagesTwo 16-bit offsets per image, as for items12 records per file
One-bit: TITLE, BRITISH, WDRecords16-bit offsetsTITLE 10; BRITISH and WD 1 each
Proportional font: PROPORT.PCS91 glyphs16-bit offsetsCharacters 0x20–0x7A; 0x4FC bytes in all

The first record always sits right after the table, at 2 + entry size × entries; for ordinary pictures that is 2 + 4 × count. The build recomputes the fixed archives' offsets and checks each against the rules:

ArchiveTable ends atFirst record
Dungeon panels (28 slots)2 + 4 × 28114 = 0x72
ITEMS (20 images + 20 masks)2 + 2 × 4082 = 0x52
MON0–7 (6 images + 6 masks)2 + 2 × 1226 = 0x1A
TITLE (10 records)2 + 2 × 1022 = 0x16
BRITISH, WD (1 record)2 + 2 × 14 = 0x04
PROPORT.PCS (91 glyphs)2 + 2 × 91184 = 0xB8

4. Read a record

GFX-0002 Original: EstablishedGFX-0004 Original: Established

Each record starts with a 16-bit width and a 16-bit height, then its rows. Ordinary pictures round the stored width up to a multiple of eight:

stored_width  = 8 * ceil(width / 8)
payload_bytes = stored_width * height / 2

Don't apply this rounding everywhere: the dungeon, item and monster archives use their dimensions as given. A proportional-font glyph record is 12 bytes: width, height (always 8), then eight row bytes. The space glyph has width zero but still has a record, and a glyph's width is not its text advance.

5. Unpack the pixels

GFX-0002 Original: EstablishedGFX-0003 Original: Incomplete
0xA7: left pixel = high nibble = 10; right pixel = low nibble = 7. 4 bits per pixel: the left pixel is the high nibble.
0xB4: pixels, left to right: 1 0 1 1 0 1 0 0. Masks, 1 bit per pixel: bit 7 is the earliest pixel.

Example bytes for illustration, not taken from the game. In ITEMS and MON archives each image's mask follows it as its own record. Which mask polarity means "draw", and how opaque black is treated, have not been verified.

6. Look up the colours

GFX-0006 Original: Incomplete

The files store palette indexes, not colours. Redux's review exporter maps them to the standard 16-colour EGA palette:

  • 0 #000000
  • 1 #0000AA
  • 2 #00AA00
  • 3 #00AAAA
  • 4 #AA0000
  • 5 #AA00AA
  • 6 #AA5500
  • 7 #AAAAAA
  • 8 #555555
  • 9 #5555FF
  • 10 #55FF55
  • 11 #55FFFF
  • 12 #FF5555
  • 13 #FF55FF
  • 14 #FFFF55
  • 15 #FFFFFF

Read from pkg/graphics/legacy/model.go when this page was built.

Dungeon combat and the ending change some tiles' colours. Redux's current model swaps palette-index bits 1 and 2 for selected tiles in dungeons and uses a separate lossy mapping for the ending, applied as it draws. The original driver tables are not decoded yet.

The tile sheet: TILES.16

GFX-0008 Original: Established
Tiles
512
16 × 16 pixels each
Per tile
128 bytes
16 rows of 8 bytes
Expanded
65,536 bytes
No header or offset table

TILES.16 uses the same LZW wrapper but none of the archive layouts above. Tile n starts at byte 128 × n of the expanded data; each row is 4 bits per pixel with the left pixel in the high nibble. The data is the four 16,384-byte source sheets joined in order. The CGA TILES.4 expands to 32,768 bytes, 64 per tile.

The signature path: BRITISH.PTH

GFX-0007 Original: Established
76543210
bit 7
X sign
bit 6–4
X distance
bit 3
Y sign
bit 2–0
Y distance
  • Plot the current point using the previous command's pen state, then move.
  • A distance above 2 lifts the pen for the next step.
  • A zero byte ends a segment. Startup draws four segments, starting at (44,68), (64,94), (143,78) and (167,105).

Not written up yet

  • The colour tables in EGA.DRV, and exactly which tiles they change (GFX-0006).
  • The fixed fonts' exact packing. Redux reads 128 glyphs of 8 × 8, one byte per row, 1,024 bytes; not independently verified (GFX-0005).
  • Mask polarity and how masks are composited (GFX-0003).
  • CGA (.4) and Hercules (.HCS) variants beyond their names and the CGA tile sheet's size.

Rule reference

Graphics-format facts distinguish archive structure, builder-defined output, Redux decoder policy, and unverified retail/driver behavior. Original artwork, fonts, narrative assets, and generated extracts remain user-supplied data rather than payloads embedded in this reference.

Compression catalogue and decoding model

GFX-0001Original: IncompleteRedux: Unverified

The compressed catalogue contains PROPORT.PCS, BRITISH.BIT, TITLE.BIT, TILES.16, ITEMS.16, DNG1.16-DNG3.16, MON0.16-MON7.16, CREATE.16, TEXT.16, STORY1.16-STORY6.16, END1.16, END2.16, ULTIMA.16, STARTSC.16, and ENDSC.16. WD.BIT, IBM.CH, RUNES.CH, and BRITISH.PTH are direct files in the reviewed loading arrangement. Applicable CGA/Hercules picture names use .4; Hercules fixed fonts use .HCS.

Redux's reviewed decoding model is a four-byte little-endian expanded length, then LSB-first variable-width LZW codes. It requires an initial clear code 256, uses end code 257, first generated code 258, and widths 9 through 12. Clear resets width, next-entry index, and the previous sequence. After outputting a sequence, append previous-sequence plus its first new byte to the dictionary; increment the next-entry index, and increase width when that index reaches 2^width. The standard next-entry self-reference case appends the previous sequence's first byte to itself. Once full, the 4096-entry dictionary stops adding entries until clear. Redux validates declared output length and zero terminal padding.

The compression catalogue is established, but this pass did not independently verify all stream transitions, full-dictionary cases, padding, or corruption acceptance against original binary samples. A functioning Redux decoder is not independent proof of every original decoder rule. One complete file has since been checked: expanding the shipped TILES.16 with this model reproduces its source sheets byte for byte (GFX-0008).

Four-bit picture and dungeon-panel archives

GFX-0002Original: EstablishedRedux: Matches

Expanded ordinary archives begin with a little-endian 16-bit count, followed by four bytes per entry: low offset word and a high word that is zero in the reviewed builder outputs. Each nonmissing record begins with width and height words, then 4bpp pixels with the left pixel in the high nibble.

Ordinary picture output rounds storage width upward to a multiple of eight:

stored_width = 8 * ceil(declared_width / 8)
payload_bytes = stored_width * height / 2

Builder-established counts are CREATE 11; STORY1-6 respectively 3,4,2,2,2,8; TEXT 6; END1/2 three each; ULTIMA 5; STARTSC 3; ENDSC 1. Dungeon-panel archives declare 28 slots, with 8 and 24 absent and zero-offset. The ordinary first payload offset is 2 + 4*count; for the dungeon panels it is 0x72.

Do not generalize the ordinary builder's rounding operation to every builder: the dungeon/item/monster builder uses input dimensions directly. Redux validates payload dimensions and offsets for its supported archives. Exact correspondence of every shipped file or nonzero high word is not claimed.

Paired images and masks

GFX-0003Original: IncompleteRedux: Unverified

ITEMS.16 and the monster archives use a logical count followed by twice that many 16-bit offsets: image, mask, image, mask. Each physical record has its own width/height prefix. Images are 4bpp; masks are 1bpp with the earliest pixel in the most-significant bit. Builder counts are 20 logical items/40 records and six logical monster images/12 records per archive; first offsets are 0x52 and 0x1A respectively.

Mask bit order is established. The original compositing polarity and treatment of opaque black were not independently verified in the drawing implementation or authored masks in this pass. Redux's image/mask interpretation must not be promoted into a universal original corruption or compositing specification.

One-bit archives and proportional font records

GFX-0004Original: EstablishedRedux: Matches

One-bit bitmap archives use a 16-bit count and 16-bit offsets, then width/height and packed rows. TITLE has ten builder records and first payload 0x16; BRITISH and WD have one and first payload 0x04. Their builder-defined expanded totals are 2,116 and 1,772 bytes respectively. These are not measured compressed-file sizes.

The proportional font covers characters 0x20 through 0x7A: 91 glyphs. A count and 91 offset words precede 12-byte records containing width, height 8, and eight row bytes. First payload is 0xB8, total expanded size 0x4FC (1,276 bytes). Space has width zero but still owns a stored record. Glyph width differs from text advance: spacing and nine-pixel line advance are separate rendering rules.

Fixed character-set boundary

GFX-0005Original: IncompleteRedux: Unverified

The DOS loading path selects IBM.CH as charset 0 and RUNES.CH as charset 1, with seven-bit glyph indexing in their consumers; Hercules selects .HCS instead. The precise fixed-font binary packing was not independently verified here.

Redux expects 128 consecutive 8x8 glyphs, one MSB-first byte per row, requiring 1,024 bytes. Its derived PNG sheets are 16 by 8 glyphs and are not the original font files. The proportional font's working format is not proof of every fixed font's layout.

Tile-color transformation boundary

GFX-0006Original: IncompleteRedux: Unverified

Dungeon tactical setup and the ending request separate tile-color operations. The exact binary driver tables, affected tile lists, and palette transformations were not independently byte-decoded in this conversion pass.

The current rendering model uses a selective dungeon permutation that exchanges palette-index bits 1 and 2, and a separate lossy ending permutation. Redux applies its selected mappings at draw time before lighting/tinting, preserving gameplay tile identity instead of modifying the shared sheet. This describes the remake's strategy; it does not certify every driver's pixels or original timing.

Signature path and asset families

GFX-0007Original: EstablishedRedux: Matches

BRITISH.PTH uses command bytes: bits 4-6 encode X magnitude, bit 7 its sign; bits 0-2 encode Y magnitude, bit 3 its sign. Plot the current point according to the preceding command's pen state before applying movement. A magnitude above two leaves the next iteration pen-up. Zero terminates a segment. Startup consumes four segments at (44,68), (64,94), (143,78), and (167,105); this is not proof that every file contains exactly four segments without trailing bytes.

Dungeon assets use DNG/ITEMS/MON families; creation uses CREATE/PROPORT; illustrated introduction uses TEXT/STORY; startup uses TITLE/BRITISH/WD/ULTIMA/STARTSC; ending uses END/ENDSC. TILES.16 shares the compression wrapper but not these archive layouts; its layout is given in GFX-0008. Intermediate build inputs are not automatically shipped runtime formats.

Tile sheet

GFX-0008Original: EstablishedRedux: Not implemented

TILES.16 expands to 65,536 bytes with no header or offset table: 512 tiles of 16 x 16 pixels, 128 bytes each, in tile-number order. Each tile is 16 rows of 8 bytes, top to bottom, at 4 bits per pixel. The expanded data is exactly the four 16,384-byte sheets EGA0.T to EGA3.T from the original source tree, joined in order; the tile editor worked on 128 tiles at a time.

The left pixel is in the high nibble, as in GFX-0002 pictures. This order is inferred from agreement with Redux's derived tile sheet; the display driver's own reading was not examined.

TILES.4, used for CGA, expands to 32,768 bytes: the four 8,192-byte sheets CGA0.TC to CGA3.TC joined, 64 bytes per tile, consistent with 16 x 16 pixels at 2 bits per pixel. Its pixel order within a byte was not verified.

Redux does not decode TILES.16. It draws tiles from a bundled 512 x 256 sheet, 32 tiles across, with tile n at column n mod 32 and row n / 32 (integer division).