Skip to main content

Loading, failures and the end of the game

Saving and restoring · Camp menus · Saved games (SAV)

In brief​

Loading a saved game reads the whole file, checks only the size of each part, then settles the level in progress and restores the characters, the party, the items, the level records and the options. A save that cannot be written, a slot without a file or a short file is reported; walls that do not pack into a record end the program. At the end of the game, the game writes FINAL.SAV and plays the ending.

How a saved game is loaded. The whole file is read; if any of the seven parts is short, nothing is restored and the load fails. Otherwise the level in progress is settled; the characters are restored and their timers turned back into deadlines; the party and world variables, the items, the level records, the options and the conjured-weapon types are restored; the portraits are drawn again; the saved level is loaded from its record; and the held item is given back. From the start menu, the loader stops after the portraits.
Only the sizes are checked; every value is restored as it is read.

Loading a saved game​

The game first reads the whole file and checks that each part has its expected size. If a part is short, nothing is restored and the load fails. Otherwise it:

  1. settles the level in progress;
  2. restores the characters, turns their timers back into deadlines counted from the current time, and schedules each character's timer update for its earliest timer;
  3. restores the party and world variables and the items, writes the saved level records over LEVELS.TMP, then restores the options and the conjured-weapon item types;
  4. draws every portrait again from the character's portrait number;
  5. loads the saved level and sublevel. The save writer always records the current level, so this level is restored from its record, as on a level change;
  6. gives back the held item: in mouse control it is still held; in keyboard control it is put in the party's block, at one of two positions chosen at random from the party's facing.

When a game is loaded from the start-up screen, the loader stops after step 4, and the start of the game loads the saved level.1

When saving or loading fails​

The player picks a slot in the slot menus. When the game cannot write the saved game, it shows that saving failed, then that the disk may be full or write-protected.2

The load menu checks which of the six slots have an EOBDATA<n>.SAV file and reads their descriptions. Picking a slot without a file shows that no game is saved there and asks again; leaving the menu loads nothing. A file that exists but is too short for one of its seven parts is rejected with a message that the file may be corrupt, and nothing of the game in progress changes. Bytes after the seventh part are never read.3

The game neither checks nor repairs the contents. Every value is restored as it is read: the level and sublevel, the party's block, the record bits, the items and the characters. The only values it does not take from the file are each character's pointer to its face image, which it keeps from the running game, and the timers, which it turns back into deadlines. A file whose current level has no record bit, for example, starts that level from its files, with its initial monsters.3

A level's walls must pack into the 1,200 bytes of its record. When they do not, the game shows "Map compression failure" with the packed size, waits for a key and ends the program, before it writes LEVELS.TMP or opens the saved game, so neither file changes. This can happen when leaving a level or when saving. In the reference LEVELS.TMP, the decodable records use 204 to 935 bytes.3

Anomaly

ANOMALY-73 — The packer writes the whole packed walls at the start of the record and the size is checked only afterwards: walls that pack into more than 1,200 bytes first overwrite the monster part of the record and, beyond 2,130 bytes, whatever follows it in memory. The program then ends without writing anything, so no consequence for play is known. A faithful reimplementation only needs to end the game as described.3

The end of the game​

FINAL.SAV is written at one moment only: on level 16, sublevel 1, when a monster dies whose type has MONSTER_CAP_WALL_SPECIAL_TYPE_1 and is not type 0 — inferred to be the final opponent's second form, see when a monster dies. The game then saves as it does for a slot, settling the level first, under the name FINAL.SAV; it then releases most of its memory blocks, plays the ending and returns to DOS. There is no way back into the game.4

The file holds the game exactly as it was at that moment, including the current level's record. Nothing in this executable reads it: the load menu and the save reader only use EOBDATA<n>.SAV.4

Anomaly

ANOMALY-72 (bug) — The writer computes the description's address as for any slot, 20 bytes per slot from the start of the descriptions, so slot −1 reads the 20 bytes that precede them. The first part of FINAL.SAV is therefore not a description but a copy of unrelated game variables, ending with the byte that records which save slots exist. No effect in this game, since nothing reads that part. A reimplementation that writes FINAL.SAV reproduces the original only by copying the same 20 bytes.4

Details and edge cases​

  • Saving changes the game. Settling the level happens in the running game: saving while an item is in the air drops it at once, and the block's script can react to it. Loading does the same to the game being replaced, so such a script runs on the current level before the saved game replaces it.5
  • Time away does not count. Temporary walls and character timers are stored as the time they have left, so a level's temporary walls resume, on return, with the time they had when the party left it.6
  • Monster counts. When a record is restored, each block's monster count is rebuilt by adding one for every one of the 30 slots, whatever the slot's state. Unused slots and dead monsters, whose block is [00:00], all count towards [00:00].6
  • Only the sizes are checked. The loader compares the length of each part with the expected size and checks nothing else; see when saving or loading fails.1

Anomaly

ANOMALY-71 — The five temporary-wall slots are saved in the record of the level being left and replaced when the party arrives on a level that has a record, but nothing resets them when the next level has none. A Wall of Force still standing when the party leaves a level for one it has never visited (or one without a record) therefore stays in its slot, with the same block number and deadline. When it expires, the game sets the four faces of the block with that number on the new level to reference 0, no wall, without looking at what they held: rock, a door, stairs or a decoration there disappear, and the block becomes open on every side. The wall lasts 546 + 273 ticks per mage level of the caster, for example 3,003 ticks, about 2¾ minutes, at mage level 9, enough to reach stairs, a pit or a teleporter. The original wall is not lost: it is in the old level's record and comes back with its remaining time when the party returns. A faithful reimplementation keeps the slots across such a level change and applies the expiry to the new level.7

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references. File sizes and hashes are in the file inventory.

Footnotes​

  1. Load a saved game and read a saved game, with the chunk lengths, the timer conversion, character timer updates, the held item and the level start selector. The message scroll counter lies outside the parts of the file, and only the move routine reads or writes it. ↩ ↩2

  2. Save menu and the save writer. ↩

  3. Load a saved game with its slot list, read a saved game, the chunk lengths and pack and unpack a level record, with the block-data packer and the exit (ANOMALY-73). Packed sizes measured on the reference LEVELS.TMP of the file inventory. ↩ ↩2 ↩3 ↩4

  4. Write FINAL.SAV, called by kill a monster before the ending and the exit; the save writer, the file names and the slot descriptions, with the description address for slot −1 (ANOMALY-72). ↩ ↩2 ↩3

  5. Settle the level, with the flying-object records, the block event dispatcher and door completion. ↩

  6. Pack and unpack a level record, the saved-level bits and the temporary-wall slots. Schemas: SAV.ksy and LEVELS_TMP.ksy. ↩ ↩2

  7. The temporary-wall slots and temporary walls, whose expiry routine proves ANOMALY-71; pack and unpack a level record, the map reader, read a level record and the INF level loader. ↩