Skip to main content

Level loading and game start routines

Routines · Data · Address index

Program start-up, the new game, the game loop, and loading containers, images and palettes. The routines page explains how the entries are written.

0x1c9dc — Game start and update loop​

0x18ae5 — Program start-up​

0x1caf7 — Choose between a new game and the current level​

0x1cba6 — New-game start​

0x30816 — Decode a container​

0x306d4 — Load a container into a page​

  • Range: 0x306d4–0x30815
  • Role: 0x306d4(name, source page, destination page, palette) opens the file, reads the stored size and the next 8 header bytes, reads the palette area into palette when it is not null and the area is not empty, otherwise seeks past it (0x30742–0x30765), clears the palette size in its copy of the header, then reads the remaining stored size − 8 − palette size bytes to the end of the source page, at an address normalized to offset 0 (0x30774–0x307eb), and decodes them into the destination page (0x30808). The count returned by the read is not checked. The page addresses come from DS:0x62a7, set at run time, and the sizes from the page sizes.
  • Used by: Compressed containers (CPS) › Reading the file, Compressed containers (CPS) › Details and edge cases

0x19338, 0x193c7 — Load a CPS image​

0x2f448, 0x2f4ca, 0x2f609, 0x3095c, 0x30a21, 0x30a99 — IFF helpers​

  • Role: 0x2f448(name) opens the file with mode 1, closes it, opens it again with mode 3 and reads 4 bytes. On FORM it skips the next 4 bytes and returns the handle; otherwise it closes the file and returns −1. 0x2f4ca closes a handle unless it is −1. 0x2f609 finds a chunk. 0x3095c, 0x30a21 and 0x30a99 convert between planar and chunky pictures in the work pages. Only the IFF branch of the picture loader calls them (0x30c59, 0x31067, 0x31007, 0x3104a, 0x3105e).
  • Used by: Load a picture with its palette

0x30bb4 — Load a picture with its palette​

  • Range: 0x30bb4–0x31077
  • Status: the IFF branch from 0x30dda to 0x31064, the rest of the CMAP chunk and the decoding of BODY, is not read; no file of the game reaches it.
  • Role: Opens the file and reads 4 bytes. FORM selects an IFF branch (0x30c53) that accepts the form types ILBM and PBM (0x30c86–0x30cb2) and reads the BMHD (0x30cc1), CMAP (0x30dbb) and BODY chunks of a 64,000-byte picture; no file of the game starts with FORM. Otherwise it loads the container, passing its palette buffer only when the display mode DS:0x628a is 6, 3 or 5 (0x30c12–0x30c2d), and a null pointer otherwise, and returns the decoded size divided by 8,000 (0x30c0b–0x30c4b). The IFF branch returns the BMHD byte of the plane count (0x3106e). Used for the start menu (MENU.CPS, overlay 249 0x46f0b), the introduction (overlay 255 0x4d286, null palette) and the ending pictures (overlay 256 0x4f88d, among them HEROES.CPS), with the palette buffer at DS:0xf168.
  • Used by: Compressed containers (CPS) › Palette

0x3111d — Set the palette​

0x3248a — Pack block data​

0x33ec4, 0x33fc4 — Container decoders​

  • Ranges: 0x33ec4–0x33fb9, 0x33fc4–0x3404a
  • Role: 0x33ec4(source, destination, limit) decodes method 4 (LCW): commands 0x00–0x7f copy from a distance back in the output, 0x80 ends, 0x81–0xbf copy literal bytes, 0xfe fills, 0xff and 0xc0–0xfd copy from an offset counted from the start of the output; every count is clamped to the room left (cs:0xfc); it returns the bytes written and never reads the unpacked size. It also restores the map portion of LEVELS.TMP. 0x33fc4(source segment, destination segment) decodes method 3 from offset 0 of the source, which must be the method word: it reads the unpacked size, skips the palette area, then runs of literal bytes (positive control byte), repeated bytes (negative control byte) and long repeats with a big-endian count (zero control byte, 0x34005) until the size is reached exactly (0x3401b); it normalizes the destination after each run (0x34023). It takes only segments, so the source offset of 0 rests on the callers of the dispatcher: load a container normalizes the source, and the INF level loader uses the level-data buffer, at offset 0. It returns in AX the sum of the run lengths, kept to 16 bits (cs:0x17c, cleared at 0x33fcf, read at 0x34045).
  • Used by: Compressed containers (CPS) › Reading the file, Compressed containers (CPS) › Compression methods