AGI Specifications: Chapter 10 - Savegame Files
10.1 Introduction
AGI saved game files are named as follows:
<gameId>SG.<num>
where <gameId> is the ID of the game, e.g. KQ1, SQ2, etc., and where <num> is a number starting at 1. The format of the saved game file was relatively consistent between versions 2.4XX and 2.9XX apart from one minor addition. The specification below currently focuses on the format used by that version range. The format of AGI v3 saved games has not yet been explored, but it is known that AGI v2.272 differs somewhat in format and almost certainly those versions prior to 2.272 will therefore be different as well.
The saved game file consists of six sections. The first section contains only the description of the saved game. We'll call this the header. The other five sections follow a high level format where the first two bytes give the length of the section and the remainder is the data for that section.
Note that the byte offsets for each section are specified as being from the start of that section and not the start of the file.
Where a numeric value is specified over multiple bytes, it is always little-endian, unless otherwise noted.
10.2 Saved Game Format
Header
Byte Meaning 0-30Savegame description. This can be up to 30 printable characters, and is padded out with NUL (\0) bytes to a total of 31 bytes.
General State
Byte Meaning 0-1Length of general state section2-8Game ID("SQ2", "KQ3", "LLLLL", etc.), NUL padded9-264Variables, 1 variable per byte265-296Flags, 8 flags per byte, starting with highest bit first297-300Clock ticks since game started. 1 clock tick == 50ms301-302Horizon303-304Key Dir305-306Upper left X position for active block307-308Upper Left Y position for active block309-310Lower Right X position for active block311-312Lower Right Y position for active block313-314Player control (1) / Program control (0)315-316Current picture number317-318Blocking flag (1 = true, 0 = false)319-320Max drawn. Always set to 15. Maximum number of animated objects that can be drawn at a time. <ref>AGI v2.001 (as used by the booter version of Donald Duck's Playground) had a command called max.drawn() with opcode value 143 that allow this value to be set by a Logic script. This command is missing from subsequent AGI v2 versions. It is possible that the inclusion of the maximum number of animated objects value in the OBJECT file in later AGI v2 versions replaced the need for the max.drawn() command.</ref>321-322Script size. Set by script.size. Max number of script event entries. Default is 50.323-324Current number of script event entries.325-524Key to controller map (4 bytes each). First 2 bytes keycode, second 2 bytes controller num.525-148424 strings, each 40 bytes long <ref>Versions outside of the 2.4XX tp 2.9XX range may have had 12 strings. Version 2.272 is an example of this.</ref>1485-1486Text foreground colour1487-1488Text background colour1489-1490Text Attribute value (a combined foreground/background value)1491-1492Accept input = 1, Prevent input = 01493-1494User input row number on the screen (as set by configure.screen command)1495-1496Cursor character1497-1498Show status line = 1, Don't show status line = 01499-1500Status line row number on the screen (as set by configure.screen command)1501-1502Picture top row number on the screen (as set by configure.screen command)1503-1504Picture bottom row number on the screen (indirectly set by configure.screen)(1505-1506)Stores a pushed position within the script event list. Used by push.script and pop.script. <ref>This field was not present in AGI versions prior to 2.9XX, i.e. it was not present prior to the inclusion of the push.script() and pop.script() commands. This is the only real difference between 2.4XX and 2.9XX saved game files.</ref>
Notes: <references />
Animated Objects
Byte Meaning 0-1Length of animated objects section. Dividing this by 43 gives the number of animated objects.WIPWORK IN PROGRESS
Inventory Objects
Almost an exact copy of the OBJECT file, but always unencrypted, and with the 3 byte header replaced by the 2 byte length of the section, and with room numbers reflecting the current location of each object (rather than starting location).
Byte Meaning 0-1Length of inventory objects section. Dividing this by 3 gives the number of objects.
Following the two bytes above we have a three byte entry for each inventory item all of which conform to the following format:
Byte Meaning 0-1Offset of inventory item name i2Starting room number for inventory item i, or 255 for carried or 0 for limbo.
where i is the entry number starting at 0. All offsets are taken from the start of entry for inventory item 0 (not the start of the section).
Then comes the textual names themselves. This is simply a list of NULL terminated strings. The offsets mentioned in the above section point to the first character in the string and the last character is the one before the 0x00.
Note that the saving of the object names in the saved game file (and the offsets to those names) is completely redundant since the names cannot change during game play. But they're present regardless.
Script Events
Stores a transcript of relevant logic script commands leading to the current state in the current room.
Byte Meaning 0-1Length of script events section. Dividing this by 2 gives the number of script events.
Following the two bytes above we have a two byte entry for each script event item, each of which conform to the following format:
Byte Meaning 0Script event type. A value from 0 to 8 defined as follows:load.logics 0 load.view 1 load.pic 2 load.sound 3 draw.pic 4 add.to.pic 5 discard.pic 6 discard.view 7 overlay.pic 81The resource number that relates to the above event type. For add.to.pic this is 0.
The add.to.pic event type is a special case. It is stored over 8 bytes, i.e. over 4 script entries. This appears to be a hack of sorts that the original AGI interpreter used for storing this event type. The other seven types have a clear action and resource number that the action applies to. The add.to.pic command doesn't follow this form. Instead it is stored as follows:
WORD IN PROGRESS
Scan Start Offsets
Byte Meaning 0-1Length of scan start offsets section. Subtract 8 then divide by 4 gives the number of entries.2-5Start of list. Always four zeros, i.e. 00 00 00 00...A variable number of 4-byte scan start offset entries, format as described in table below?-?End of list. Always FF FF 00 00
Each of the 4-byte scan start offset entries conforms to the following format:
Byte Meaning 0-1Logic number that the scan start offset is for.2-3Current scan start offset value of the logic.
Notes:
- Only logics that are currently loaded are in the scan offset list, i.e. they're removed from the list when the room changes.
- The order logics appear in this list is the order that they were loaded.
- The new.room command unloads all logics except for logic 0, so logic 0 never leaves this list and is always the first item.
< Previous: Chapter 9 - Sound ResourcesNext: Chapter 11 - Other Game Data >