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
.CPSimages, such asAIRSEAL.CPSorMAP.CPS: each unpacks to a 320 × 200 picture of one byte per pixel; - the 16 level files,
LEVEL1.INFtoLEVEL16.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).
Organization
| Part | Size | Contents |
|---|---|---|
| Header | 10 bytes | Stored size, method, unpacked size, palette size. |
| Palette | given by the header | A 256-colour palette, in two images only; empty everywhere else. |
| Compressed data | rest of the file | The 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
| Method | Used by | How the data is unpacked |
|---|---|---|
| 0 | no file | Copied unchanged, as many bytes as the unpacked size. |
| 3 | SKELWAR.CPS only | Run-length encoding, below. |
| 4 | the 115 other images, the 16 INF files and the 5 VCN files | Westwood'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):
| Layout | Frame 1 | Frame 2 | Frame 3 | Frame 4 | Frame 5 | Frame 6 |
|---|---|---|---|---|---|---|
| 0 | 0, 0, 7, 96 | 7, 40, 12, 56 | 19, 40, 12, 56 | 31, 0, 7, 96 | 0, 96, 7, 96 | 7, 96, 7, 96 |
| 1 | 0, 0, 7, 96 | 7, 0, 7, 96 | 14, 0, 7, 96 | 21, 0, 7, 96 | 28, 0, 7, 96 | 0, 96, 7, 96 |
| 2 | 0, 0, 10, 88 | 10, 0, 10, 88 | 20, 0, 10, 88 | 30, 0, 10, 88 | 0, 88, 10, 88 | 10, 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.
Related pages
- Level data (INF) and dungeon tiles (VCN): the formats found inside the container.
- Wall decorations (DEC) and monster decorations (DCR): the rectangles cut from images.
- The world: how the game loads a level.
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.