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
- Range:
0x1c9dc–0x1caf6; repeated path0x1ca20–0x1caf2. - Role: Called once, by the program start-up (
0x18c70). The loop body has no exit test: the program ends from inside a callee, through the exit routine. Sets the first ambient-sound deadline, calls the start selection, then repeats, in this order: the party status check (0x1ca2a), input (0x1ca32), timed updates (0x1ca35), the scene redraw when the state-change flag is set (0x1ca3a–0x1ca4a), the ambient sound when its deadline has passed (0x1ca4c–0x1cae5) and the environmental-sound flush (0x1caeb). - Comparative source: REF-SCUMM-014,
runLoop. - Used by: The game loop › How the game ends, The game loop › One pass of the game loop, Level records and level changes › A new game, How a script runs › Scripts and the game's state, Timed scripts › Timed block scripts, Sound effects
0x18ae5 — Program start-up
- Range:
0x18ae5–0x18c76 - Role: Called once from
0x18acb. Allocates the game's buffers, among them the level-data buffer (0x18b5a–0x18b69), which is the buffer of page 3, 64,500 bytes (page sizes). The INF level loader reads into it as many bytes as the file's stored size says, a signed 16-bit word, with no check against that capacity (0x48dae–0x48dbf); the original files store at most 5,763 bytes. It then calls overlay 249 entry 90x46c27(0x18c50), the start menu (0x18c55,call 0x2add:0x2f, its only caller) and the game loop (0x18c70), which does not return. Before it, the C start-up code clearsDS:0x6c68–0xf2e5(0x100a9–0x100b9), which includes the saved-level bits and the temporary-wall slots. So the start menu, and a new game, run once per run of the program. - Used by: Level records and level changes › A new game, Level records (LEVELS.TMP) › Lifetime of the file, The game loop › How the game ends
0x1caf7 — Choose between a new game and the current level
- Range:
0x1caf7–0x1cba5 - Role: Runs once when the game starts, after the start-up screen.
Starts a new game when the
level start selector is 0, that is after a party was
created or transferred; otherwise, after a saved game was read from the
start-up screen, loads the restored current level and
sublevel at
0x1cb25, then clears the selector. - Used by: Changing level › When the game loads a level, Changing level › When the game loads a level
0x1cba6 — New-game start
- Role: Loads level 4, sublevel 0, with the party on block 171 facing
direction 2, through the INF level loader. It does
not touch
LEVELS.TMPor the saved-level bits. - Used by: Level records and level changes › A new game, Level 4: the forest › In brief, Changing level › When the game loads a level, Changing level › When the game loads a level
0x30816 — Decode a container
- Range:
0x30816–0x308bf - Role: Takes a far pointer to a container's method word, reads the
method as a byte (
0x30820) and decodes: method 0 copies the 32-bit unpacked size of bytes with the far copy (0x30836), method 3 goes to0x33fc4with the source and destination segments only (0x30874), method 4 to0x33ec4with a limit of 65,535 bytes (0x30884). Any other method jumps to the exit (0x30833) and writes nothing. Called by the container loader and the INF loader, whose output goes to the shared buffer. - Used by: Compressed containers (CPS) › Reading the file, Compressed containers (CPS) › Compression methods, Level data › Loading a level
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 intopalettewhen 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 fromDS: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
- Ranges:
0x19338–0x193c6,0x193c7–0x193ee - Role:
0x19338buildsNAME.CPSwith the format%s.%s(DS:0x2ff3,DS:0x2ff9) and loads it without a palette, so the palette area is skipped; a last argument other than −1 then has the page copied through the driver.0x193c7(name, source page, destination page)calls it with −1. Most image loads go through these two routines, among them the decoration, door and monster images. - Used by: Compressed containers (CPS) › Reading the file, Compressed containers (CPS) › Palette, Compressed containers (CPS) › Details and edge cases, Dialogue screen
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. OnFORMit skips the next 4 bytes and returns the handle; otherwise it closes the file and returns −1.0x2f4cacloses a handle unless it is −1.0x2f609finds a chunk.0x3095c,0x30a21and0x30a99convert 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
0x30ddato0x31064, the rest of theCMAPchunk and the decoding ofBODY, is not read; no file of the game reaches it. - Role: Opens the file and reads 4 bytes.
FORMselects an IFF branch (0x30c53) that accepts the form typesILBMandPBM(0x30c86–0x30cb2) and reads theBMHD(0x30cc1),CMAP(0x30dbb) andBODYchunks of a 64,000-byte picture; no file of the game starts withFORM. Otherwise it loads the container, passing its palette buffer only when the display modeDS:0x628ais 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 theBMHDbyte of the plane count (0x3106e). Used for the start menu (MENU.CPS, overlay 2490x46f0b), the introduction (overlay 2550x4d286, null palette) and the ending pictures (overlay 2560x4f88d, among themHEROES.CPS), with the palette buffer atDS:0xf168. - Used by: Compressed containers (CPS) › Palette
0x3111d — Set the palette
- Role: Passes a 768-byte palette with first entry 0 and last entry 255
to driver slot 48 (
DS:0x65e2), the VGA driver's palette routine. - Used by: Compressed containers (CPS) › Palette, Palettes (PAL, EGA, COL)
0x3248a — Pack block data
- Role:
0x3248a(source, destination, length)packslengthbytes (0x1000for the walls) into the destination and returns the packed size. The length is that of the input (0x324b3–0x324b9); no output limit is passed or tested, so the whole packed stream is written before the caller compares its size with the room in the record (ANOMALY-73). Its output is read back by the type-4 decoder. - Used by: Loading, failures and the end of the game › When saving or loading fails
0x33ec4, 0x33fc4 — Container decoders
- Ranges:
0x33ec4–0x33fb9,0x33fc4–0x3404a - Role:
0x33ec4(source, destination, limit)decodes method 4 (LCW): commands0x00–0x7fcopy from a distance back in the output,0x80ends,0x81–0xbfcopy literal bytes,0xfefills,0xffand0xc0–0xfdcopy 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 ofLEVELS.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 at0x33fcf, read at0x34045). - Used by: Compressed containers (CPS) › Reading the file, Compressed containers (CPS) › Compression methods