Auto-restore

From IFWiki

The auto-restore mechanism for Glulx was invented by Aaron Black.

After creating windows (and other Glk initialization and protected variables, if necessary), if the story file has just been loaded and the RESTART command hasn't been used, and glk_gestalt(0x14FE,0x140C) returns nonzero, then it should attempt to restore a saved game; if that fails, just start the game normally. In this way, even if there are initial questions before the main command prompt, the game can still be restored, without having to deal with those questions every time.

Inform 6

TODO

Inform 7

Note that this code is untested (the author uses neither Inform6 nor Inform7, but is providing it for the convenience of those who do use Inform). (If it is wrong and you know how to fix it, you may do so.)

Auto-restore (for Glulx only) by Aaron Black begins here.

[Public domain]

Use authorial modesty.

Include (-
  Global auto_restoring_var = 0;
-).

Before starting the virtual machine: (-
  @glk $0022 0 auto_restoring_var;
-).

Include (-
  [ AUTORESTORE_R;
    @jnz auto_restoring_var 0;
    @copy $140C sp;
    @copy $14FE sp;
    @glk $0004 2 sp;
    @jz sp 0;
    @callf IMMEDIATELY_RESTORE_SAVED_R 0;
    @return 0;
  ];
-).

The auto-restore rule translates into I6 as "AUTORESTORE_R".

The auto-restore rule is listed first in the when play begins rules.

Auto-restore ends here.