Skip to main content

Compressed containers (CPS)

File formats · Field reference · Schema

In brief​

Many of the game's files are compressed and wrapped in the same small container, known from other Westwood games as CPS. A ten-byte header gives the stored size, the compression method and the size of the data once unpacked; an optional palette and the compressed data follow. The container wraps:

  • the 116 .CPS images, such as AIRSEAL.CPS or MAP.CPS: each unpacks to a 320 × 200 picture of one byte per pixel;
  • the 16 level files, LEVEL1.INF to LEVEL16.INF — once unpacked, read them as level data (INF);
  • the five dungeon tile sets, such as DUNG.VCN — once unpacked, read them as dungeon tiles (VCN).
From the file CPS containers to the game. The file holds, in order: Header (10 bytes); Palette (two images only); Compressed data (rest of the file). The game: Read the header; Read or skip the palette; Unpack: stored, LCW or run lengths. In memory: A 320 × 200 page of one byte per pixel, or the unpacked INF or VCN data. Used by: Pictures and scenes, Level loading (INF), Tile sets (VCN).
The game turns it into a 320 × 200 page of one byte per pixel, or the unpacked INF or VCN data.

Organization​

PartSizeContents
Header10 bytesStored size, method, unpacked size, palette size.
Palettegiven by the headerA 256-colour palette, in two images only; empty everywhere else.
Compressed datarest of the fileThe packed content.

Reading the file​

The game reads a container each time it needs what it holds: a picture for a screen or a scene, the shapes of a level or of the interface, and the INF and VCN files of a level when it loads the level. To load an image, the game reads the stored size and the rest of the header, then the palette when the caller asked for one (otherwise it skips it), then the remaining bytes, and unpacks them according to the method.1

Compression methods​

MethodUsed byHow the data is unpacked
0no fileCopied unchanged, as many bytes as the unpacked size.
3SKELWAR.CPS onlyRun-length encoding, below.
4the 115 other images, the 16 INF files and the 5 VCN filesWestwood's LCW compression, also called Format 80, below.

Any other method value unpacks nothing: the destination is left as it was.2

Method 3 reads a control byte c, taken as signed, and repeats until the unpacked size has been produced:

c > 0: copy the next c bytes
c < 0: write the next byte −c times
c == 0: read a 16-bit count, high byte first, then a byte; write it count times

The 16-bit count is the only big-endian value of the container.

Method 4 reads a command byte b and repeats until the end command:

b = 0x00–0x7f: copy (b >> 4) + 3 bytes from (b & 15) × 256 + next byte bytes back in the output
b = 0x80: end
b = 0x81–0xbf: copy the next b & 63 bytes
b = 0xfe: read a count word and a byte; write the byte count times
b = 0xff: read a count word and an offset word; copy count bytes from that offset of the output
b = 0xc0–0xfd: read an offset word; copy (b & 63) + 3 bytes from that offset of the output

Offsets count from the start of the unpacked data. The method 4 decoder stops on the end command and never reads the unpacked size from the header; it only refuses to write more than 65,535 bytes. Every method 4 file of the collection ends with the end command on its last byte and unpacks to exactly the announced size.2

Palette​

HEROES.CPS, shown at the end of the game, and MENU.CPS, the start menu, carry a 768-byte palette: 256 colours of three values from 0 to 63 (red, green and blue). The game reads it only when it loads these pictures with the routine that accepts a palette, and only in display modes 3, 5 and 6; it then sets the screen palette from it, all 256 colours at once (in mode 5 the start menu first replaces it with the 768 bytes of MENU.EGA, and in mode 3 the ending does not set it at once but fades the screen in to it from black). Every other image is loaded by a routine that skips the palette area, which is empty in any case.3

What it becomes in memory​

Every .CPS file unpacks to 64,000 bytes: a picture 320 pixels wide and 200 high, stored row by row from the top, one byte per pixel, each byte a colour number of the 256-colour palette. The game unpacks it into one of its screen pages the same way in every display mode.4

Some images are sheets from which the game cuts shapes by rectangle; a rectangle gives its column and width in 8-pixel units and its row and height in pixels. The rectangles are built into the game for the item and thrown shapes5 and for the decoration sheet,6 and come from the level's door records for door images,7 from the DEC file named with the image for wall decorations,8 and from one of three built-in layouts and the DCR file for monster images.9 The other images are pictures copied to the screen. Images, palettes and fonts gives what each of the 116 files holds and what uses it.

The three monster layouts, as column, row, width in columns and height, for frames 1 to 6 (see monster images):

LayoutFrame 1Frame 2Frame 3Frame 4Frame 5Frame 6
00, 0, 7, 967, 40, 12, 5619, 40, 12, 5631, 0, 7, 960, 96, 7, 967, 96, 7, 96
10, 0, 7, 967, 0, 7, 9614, 0, 7, 9621, 0, 7, 9628, 0, 7, 960, 96, 7, 96
20, 0, 10, 8810, 0, 10, 8820, 0, 10, 8830, 0, 10, 880, 88, 10, 8810, 88, 10, 88

A level names the layout together with the image; the layout of each monster image is listed under monster images.

The bottom-right corner of a monster image, columns 302 to 319 and rows 184 to 199, is not a shape: it holds the colour swaps of the monster's two colour variants, three columns per frame. In each row, the first column names a colour used by the frame and the next two the colours that replace it in variants 1 and 2; colour 0 is never replaced. Monsters whose slot number leaves a remainder of 1 or 2 when divided by 3 are drawn in that variant.10

Example​

The first ten bytes of AIRSEAL.CPS, a 21,530-byte file:

offset bytes meaning
0000 18 54 stored size: 0x5418 = 21,528 bytes follow
0002 04 00 method 4: LCW
0004 00 fa 00 00 unpacked size: 0xfa00 = 64,000 bytes
0008 00 00 no palette
000a 91 f7 f3 … compressed data

Details and edge cases​

  • In SKELWAR.CPS, the stored size equals the length of the whole file, two bytes more than the bytes that follow it, while every other container gives the number of bytes that follow. The game asks for two bytes past the end of the file, gets what is there and does not check the count; the run-length decoder stops on the unpacked size, so the image is complete.
  • A monster image is unpacked in place: page 3 is both source and destination. The game reads the compressed bytes to the end of that page's buffer, 64,500 bytes long, and the decoder writes from the start of the same buffer. In SKELWAR.CPS, the output stays at least 493 bytes behind the input it has not read yet.11
  • The palette size is cleared in the loaded copy of the header before unpacking, and the method is read as a single byte.
  • The method 3 decoder expects the unpacked size to be reached exactly by the last run; it does not check that a run fits.

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references (REF-MW-006, REF-MW-008, REF-SCUMM-004). The method counts come from reading the 116 images, 16 INF and 5 VCN files of the file inventory.

Footnotes​

  1. Load a container into a page, load a CPS image and the INF loader. ↩

  2. Container decoding and the method 3 and 4 decoders. ↩ ↩2

  3. Load a picture with its palette, set the palette and the VGA driver's palette routine; for the ending, load a scene and fade the palette. ↩

  4. The VGA driver's shape encoder (MGA.OVL routine), the EGA driver's shape encoder and the monster colour variants. ↩

  5. Load the item and thrown shapes. ↩

  6. Load decoration shapes. ↩

  7. Load the shapes of a door graphic. ↩

  8. Assign a wall mapping. ↩

  9. Load monster shapes, the monster shape layouts and the DCR loader. ↩

  10. Monster colour variants and draw the monsters of a visible block. ↩

  11. Load monster shapes, load a CPS image, load a container into a page, the page sizes and the method 3 decoder. The margin comes from replaying the runs of the file at those positions. ↩