Saving Games

From AGI Wiki
Revision as of 13:35, 20 April 2019 by Andrew Korson (talk | contribs) (Created page with "== Saving Games in AGI == Saving a game (by using the '''save.game''' command) writes the current game state, including all information about loaded resources, vari...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Saving Games in AGI

Saving a game (by using the save.game command) writes the current game state, including all information about loaded resources, variables, flags, etc. to disk so it can be restored later.

AGI prompts the player for a directory (the default is the current directory, if running from a hard drive), then searches the selected directory for any existing save game files.

Each saved game is stored in a separate file. The number of save game files is limited to twelve. Each file has a description stored as the first data field that is displayed to the player when selecting game 'slots'. AGI also checks that the game ID stored in the save game file matches the current interpreter game ID or it does not add the save game file to the display list. Choosing a slot prompts the player to enter a description. Choosing an existing game slot will write over that existing save game file.

The naming convention for saved games is the game ID concatenated with "SG", with a file extension that contains the save game file number. As an example, King's Quest I save games would be "KQ1SG.1", "KQ1SG.2", ... up to "KQ1SG.12". If the game ID has not been set, the save games will simply be "SG.1", "SG.2", etc.

The set.simple command can be used to change the behavior of save and restore functions. When set.simple is called with a string argument that contains a non-zero length text string, AGI uses that string as the default save game description. Calls to save.game/restore.game will automatically save/restore the first save game file in the current save game directory that matches the default save game description. Calling set.simple with a string argument that is a null string will restore normal save/restore functionality. Note that the set.simple command is available on AGI versions 2.915 and above.

When saving or restoring, AGI first freezes the internal clock, and changes the print 'escape' character to '@', so the backslash (\) will display correctly for game directories. If a sound is playing, it is also stopped during save/restore operations.

Save Game Format

Saved games consist of the following data fields:

Size Data
31 bytes The description displayed by AGI when choosing a game slot; a null terminated string, padded with extra null characters as needed.
2 bytes Size of Game State Section
version dependent; (1505 bytes for 2.917) A memory dump of game state section in memory. Includes game ID, variables, flags, controllers, and other game state data.
2 bytes Size of Object Table Section
43 bytes times number of screen objects currently animated A memory dump of the entire screen objects table.
2 bytes Size of Inventory Objects Section
3 bytes times number of objects plus string data for each object An unencrypted copy of the game's OBJECT file data (except it does not include the two byte header and the MaxScreenObject byte).
2 bytes Size of Script Table Section
2 bytes times the max script size A memory dump of the script table data.
2 bytes Size of Scan Start List Section
4 bytes times number of loaded logics + 8 A four byte marker (0x00000000) marks the start of this section; then, for each loaded logic, the logic number (as a 16 bit word) and its current scan point (as a 16 bit offset from the logic start); another four byte marker (0xFFFF0000) marks the end of this section

The scan start table is created new each time a game is saved. AGI only allocated space for 30 entries in the table. In the highly unlikely event that you have more than 30 logics loaded when you save a game, the scan table will overflow into space used by AGI to display memory related messages and the memory pointers, which will crash AGI.