Saved games and level records
Overlay 251 · image 0x490e0–0x4a4fa (5,147 bytes) · 15 stub entries
All overlays · ← 250 · Loading a level · 252 · Dialogues and scripted sequences →
In brief
Overlay 251 saves and restores the game. It packs each level into a record in LEVELS.TMP, writes and reads EOBDATA<n>.SAV as seven chunks, runs the load and save menus and settles the current level — ending flying objects and door operations — before a level is saved or left. The rules are described in saving and restoring; the files in the SAV and LEVELS.TMP formats.
Every address on this page is a file offset in START.EXE; calls into resident code are given as analysis addresses. See how addresses are written.
How it fits together
Who saves and who loads. Dashed boxes are outside this overlay.
Entry points
Stub entries whose target is resolved, from the stub bytes or another independent anchor, or through the portal reading.
| Encoded entry | Target | Role |
|---|---|---|
| entries 0–14 | 0x49266, 0x4a355, 0x49b60, 0x4a1d1, 0x493ca, 0x49587, 0x4945a, 0x4a2b8, 0x498c5, 0x4950f, 0x490e0, 0x49fa5, 0x49368, 0x49684, 0x4a117 | See the routines |
Routines at a glance
| Routine | Address |
|---|---|
| Pack and unpack a level record | 0x490e0, 0x49266 |
Read a level record from LEVELS.TMP | 0x49368 |
Write a level record to LEVELS.TMP | 0x493ca |
| Convert character timers | 0x4945a, 0x4950f |
| Load a saved game | 0x49587 |
| Save menu | 0x49684 |
| Save a game | 0x498c5 |
| Write characters and items | 0x499c0 |
| Read a saved game | 0x49b60 |
| Settle the level | 0x49fa5 |
| Complete door operations | 0x4a04d |
| Refresh the slot list | 0x4a117 |
| Choose a slot | 0x4a355 |
| Draw a slot button | 0x4a1d1 |
| Find the slot button under a point | 0x4a2b8 |
Routines
Pack and unpack a level record
| Address | Range |
|---|---|
0x490e0, 0x49266 | 0x490e0–0x49265, 0x49266–0x49367 |
0x490e0 fills a 0x852-byte level record: the four wall bytes
of the 1,024 level blocks, packed by the
block-data packer into at most 0x4b0 bytes; the 900 bytes of
the monster slots at +0x4b0; and the 30 bytes of the
temporary-wall slots at +0x834, whose deadlines are
stored as the ticks remaining (1 when already due). 0x49266 reverses it:
it decodes the walls with the type-4 decoder,
restores the monster slots, adds one to word +4 of each slot's block for
all 30 slots (0x49300; the wall bytes are written at 0x492ba, and the block's
script offset is never written), restores the temporary walls and turns their remaining ticks
back into deadlines. Bytes +4 to +9 of the blocks are not stored. The
packer writes its whole output at the record start (0x49130–0x49147)
and only then is the size compared with 0x4b0 (0x4914d); a larger
result formats "Map compression failure: size of map = %d" (DS:0x1372),
shows it, reads a key and
exits (0x49154–0x49193), before either caller
opens a file. The bytes past 0x4b0 have already been written over the
monster part and beyond (ANOMALY-73). Both
stop the shared counter around the conversion and
restart it afterwards (0x491b8–0x49259, 0x4932d–0x4935b),
whatever its state before.
Comparative source: REF-SCUMM-015, the level
records of readOriginalSaveFile.
Used by: Loading, failures and the end of the game › When saving or loading fails, Level block › Changes during play, Level maps (MAZ) › Reading the file, Level records (LEVELS.TMP) › Organization, Changing level › Returning to a level, Level data › What each part of the files becomes, Monster slot › Copying runtime state, Saved games (SAV) › Organization, Level records and level changes › Level records, Scripted walls and doors › Walls, The game clock › Pauses, The game loop › How the game ends, Loading, failures and the end of the game, Script virtual machine › How a run starts, The engine, Anomalies and bugs
Read a level record from LEVELS.TMP
| Address | Range |
|---|---|
0x49368 | — |
Reads the record of a level from LEVELS.TMP, at
(level − 1) × 0x852, and unpacks it with 0x49266. Called by
the map reader when the level's
saved-level bit is set.
Used by: Level maps (MAZ) › Reading the file, Changing level › Returning to a level, Monster slot › Copying runtime state, Level records and level changes › Changing level, Scripted walls and doors › Walls, Level records (LEVELS.TMP) › Organization, Loading, failures and the end of the game › Details and edge cases
Write a level record to LEVELS.TMP
| Address | Range |
|---|---|
0x493ca | — |
Packs the current level with 0x490e0, writes the
record to LEVELS.TMP at (level − 1) × 0x852 and sets the level's
saved-level bit.
Used by: Change level or load monster resources › Behavior, Level records (LEVELS.TMP) › Organization, Changing level › Returning to a level, Sublevels › The two records, Monster slot › Copying runtime state, Level records and level changes › Changing level, Level records and level changes › A new game, Level records (LEVELS.TMP) › Lifetime of the file, Level 8: reference tables
Convert character timers
| Address | Range |
|---|---|
0x4945a, 0x4950f | 0x4945a–0x4950e, 0x4950f–0x49586 |
For each present character (eligibility mask
CHARACTER_ELIGIBLE_PRESENT), 0x4945a turns the ten
timer deadlines into
the ticks remaining on the shared counter, or 1 for a
timer already due; 0x4950f adds the counter back to every nonzero timer
and then re-arms the character updates. The
save writer calls them around the character chunk; the
save reader calls 0x4950f after restoring the characters.
Comparative source: REF-SCUMM-015, the timer
conversion of readOriginalSaveFile.
Used by: Character record › Character timers, Character record › Portrait, Loading, failures and the end of the game › Loading a saved game, Saving and restoring › What a saved game holds
Load a saved game
| Address | Range |
|---|---|
0x49587 | 0x49587–0x49683 |
The load menu, at a window position given by its two
arguments. It refreshes the slot list (0x4a117: for slots 0–5, whether
EOBDATA<n>.sav exists, kept as one bit per slot in DS:0xee3e, and its
description), lets the player pick a slot (0x4a355;
6 means the menu was left, and the routine returns 0), shows string 65,
"There is no game saved in that slot!", and asks again for a slot whose
bit is clear, then calls the save reader and, when it fails,
shows string 16, that the file may be corrupt (0x49643–0x4965e). It
returns the reader's result. Its three literal callers are the start-up
state machine 0x47086, at 0x470d1, the
camp menu, at 0x4491b, and the
defeat sequence, at analysis address 0x1ffdc.
Used by: Loading, failures and the end of the game › Loading a saved game, Loading, failures and the end of the game › When saving or loading fails, The game loop › When the party is defeated, Camp menus › Saving and loading, Saved games (SAV)
Save menu
| Address | Range |
|---|---|
0x49684 | 0x49684–0x498c4 |
Lets the player pick a slot and edit its description, kept in the
slot descriptions, then calls the
save writer at 0x49858. Reached as entry 13 of the overlay,
called from the game menu of overlay 247 at 0x44949. In order:
- Refresh the slot list and choose a slot with
title 0. Cancel (6) returns 0 (
0x4971d–0x49728). - A slot whose bit of
DS:0xee3eis set asks string 55 of the message list (replace the saved game?) through the two-choice question in window 11, Yes selected first (0x49700–0x49714); No goes back to step 1. - The chosen slot's line (rows 17 apart) is filled over 162 pixels with
the interface colour
DS:0xe606(driver slot 22) and the text input edits the slot's 20-byte description in place, 19 characters at most; Escape (a return of −1) starts the input again (0x4974a–0x497a7). - An empty description (length 0) shows string 54 (a name is needed) with
an OK button through the message box, then goes back to step 3
(
0x497a9–0x497f9). - The field is cleared again, the description printed in colour 15, and
the save writer called with the slot. When it returns 0,
strings 15 (saving failed) and 66 (the disk may be full or
write-protected) are shown one after the other (
0x49860–0x4989f). - Text window 11 is put back to its earlier bounds; the writer's result is returned.
Used by: Saving and restoring › What a saved game holds, Camp menus › Saving and loading, The start menu, questions and text, Loading, failures and the end of the game
Save a game
| Address | Range |
|---|---|
0x498c5 | 0x498c5–0x49b5f |
Settles the level with 0x49fa5, reads all of
LEVELS.TMP into the level-data buffer, packs the
current level into its record there and sets its
saved-level bit. It then writes EOBDATA<slot>.SAV —
or FINAL.SAV when the slot is −1 (file names) — as
seven chunks: the slot's description, the
characters (timers converted by
0x4945a at 0x499bd and back by 0x4950f at
0x499f2), the 0x5c-byte block starting at the
current level, the items, the 17
level records, the three option settings and item types
51 to 56 of the item-type table. For slot −1 the
description address is computed like the others, DS:0xee3f + 20 ×
slot (0x49993–0x499a1), and so is DS:0xee2b, before the table
(ANOMALY-72). The result of opening
the file is not tested; each write's length is. Packing the current level
(0x490e0, called at 0x49920) restarts the shared counter,
although the camp menu that leads here has stopped it.
Comparative source: REF-SCUMM-015,
saveAsOriginalSaveFile.
Used by: Loading, failures and the end of the game › The end of the game, Level records and level changes › A new game, Flag operation targets › Forbidding rest, Saving and restoring › What persists, at a glance, Item entry › Block chains, Item type entry › Changes during play, Saved games (SAV) › Organization, Saving and restoring › What a saved game holds, The game clock › Pauses, Level records (LEVELS.TMP) › Lifetime of the file, The engine, Where an item is, Magic, Anomalies and bugs, Item types (ITEMTYPE.DAT) › Reading the file
Write characters and items
| Address | Range |
|---|---|
0x499c0 | — |
The part of the save writer that writes the characters, the level-state block and the items through the file write helper.
Used by: —
Read a saved game
| Address | Range |
|---|---|
0x49b60 | 0x49b60–0x49fa4 |
Reads EOBDATA<slot>.SAV into the
level-data buffer and checks each of the seven chunks
against its expected length; a short read clears the
level start selector and restores nothing. Otherwise it
settles the current level with 0x49fa5 and restores, in
order: the characters, keeping each one's face-image pointer, followed by
0x4950f; the level-state block; the items; the level records,
written over LEVELS.TMP; the option settings; and item types 51 to 56.
The description is skipped. It redraws every portrait from CHARGENA or
OUTPORTS according to the character's portrait number. Unless the
selector is 0xff, it then calls the INF level loader for the
saved level and sublevel and gives back the
held item: in mouse control it stays the held item;
otherwise it is put in the party's block at one of two positions chosen
at random from the party's facing. It neither saves nor restores the four
wall tables (DS:0x2178–0x22b7), so the loaded record
applies only its own mappings (ANOMALY-63: the whole range
0x49b60–0x49fa4, with the level 8 data).
Comparative source: REF-SCUMM-015,
readOriginalSaveFile.
Used by: Anomalies and bugs, Character record › Character timers, Character record › Portrait, Flag operation targets › Forbidding rest, Walls and doors › Faces that the level does not map, Changing level › When the game loads a level, Saved games (SAV) › Organization, Loading, failures and the end of the game › Loading a saved game, Level records and level changes › A new game, Loading, failures and the end of the game › When saving or loading fails, Level records (LEVELS.TMP) › Lifetime of the file, Magic, Initial items (ITEM.DAT) › Reading the file
Settle the level
| Address | Range |
|---|---|
0x49fa5 | 0x49fa5–0x4a116 |
Called before a level is saved or left. It clears byte +0x0a of
the 30 monster slots; ends every
flying object — a thrown item drops to the floor of the
block where it is (its position loses bit 2) and its block receives
BLOCK_EVENT_ITEM_PLACED through the
block event dispatcher, while other flying objects
simply vanish; and ends with the
door completion loop. Its callers are the
save writer, the save reader and the
level-change command. The landing item's event is
dispatched at 0x4a00e and its record cleared only at 0x4a01f, so a nested
settling sees the record still active
(ANOMALY-155).
Used by: Change level or load monster resources › Behavior, Changing level › Returning to a level, Monster slot › Copying runtime state, Level records and level changes › Changing level, Level records and level changes › Settling the level, Script virtual machine › How a run starts, Change level or load monster resources, The engine, Magic, Loading, failures and the end of the game
Complete door operations
| Address | Range |
|---|---|
0x4a04d | 0x4a04d–0x4a110, the last part of 0x49fa5 |
Completes the active door operations at once by
walking each one to its endpoint. It skips a slot with block 0 (0x4a06b;
ANOMALY-148).
Comparative source: REF-SCUMM-010, completeDoorOperations.
Used by: Walls and doors › What a wall lets through, Wall mapping flags › Doors, Wall properties › Where each bit is tested, Level records and level changes › Settling the level, Scripted walls and doors, Loading, failures and the end of the game
Refresh the slot list
| Address | Range |
|---|---|
0x4a117 | 0x4a117–0x4a1d0 |
Called by the load menu at 0x495c6 and the
save menu at 0x496c1. For slots 0 to 5 it builds the name
EOBDATA<n>.sav (DS:0x1421) and tests whether the file exists: if so it
sets bit n of DS:0xee3e and reads the first 20 bytes of the file, the
description, into the slot descriptions; if not it
clears the bit and fills the description with zeros. Around the scan it
clears DS:0x61f4 (resident 0x2f2cc) and sets it again (0x2f2d6), so
that the file search does not look for missing
save files on other drives.
Used by: Camp menus › Saving and loading
Choose a slot
| Address | Range |
|---|---|
0x4a355 | 0x4a355–0x4a4fa |
0x4a355(x, y, title), called by the load menu with title 1
("Load Game") and the save menu with title 0 ("Save Game"),
strings DS:0x144b and DS:0x1441 reached through the pointers at DS:0x136a.
It draws a 176 × 144 panel with the title and the seven
buttons — the six slots and Cancel — on page 2, copies it to
(x, y) on the screen and then reads input until a button is chosen:
| Input | Effect |
|---|---|
| None waiting | The button under the pointer becomes the selection (0x4a2b8) |
Left-button press (0x41) | Chooses the button under the press, if any |
| Enter (43), Space (61) | Chooses the selection |
| Keypad 8 (96) | Previous button; from slot 0 to Cancel |
| Keypad 2 (98) | Next button; from Cancel to slot 0 |
Any other code is ignored, among them Escape and the right button. When the selection changes, the old label is redrawn in colour 15 and the new one in colour 6. The chosen button is drawn pressed, then raised after a short wait (five screen refreshes). It returns the button: 0 to 5 for a slot, 6 for Cancel.
Used by: Camp menus › Saving and loading
Draw a slot button
| Address | Range | Status |
|---|---|---|
0x4a1d1 | 0x4a1d1–0x4a2b7 | Raised and pressed boxes inferred from the colour swap |
0x4a1d1(button, style, colour), relative to the menu origin
(DS:0xeeec, DS:0xeeee). Buttons 0 to 5 are 167 × 14 at (4, 20 + 17 ×
button), labelled with the slot's description when its bit of
DS:0xee3e is set, otherwise "Empty Slot" (DS:0x1436); button 6 and
above is Cancel (DS:0x142f), 53 × 14 at (118, 126). A negative button
draws nothing. Style 0 draws the label only; styles 1 and 2 first draw the
box through the button box, which calls the
framed box with the two edge colours swapped
between them. The label is printed at (4, 3) inside the box in the given
colour, through the shadowed text routine.
Used by: Choose a slot, Camp menus › Saving and loading, Texts
Find the slot button under a point
| Address | Range |
|---|---|
0x4a2b8 | 0x4a2b8–0x4a354 |
0x4a2b8(x, y) returns the first of buttons 0 to 5 whose rectangle
contains the point (point in a rectangle), 6 for
the Cancel button and −1 otherwise. It returns −1 at once while the
control-state byte DS:0x6655 is nonzero, so in that
state neither the pointer nor a click selects a slot.
Used by: Choose a slot, Camp menus › Saving and loading
Sources
The executable is identified in the file inventory; the overlay layout is described on the overlays page. Comparative sources are listed in the technical references.