Language::Zcode::Runtime::State is a Perl module to handle saving, restoring, etc. the game state.
Getter/setter: currently in the process of restoring or not?
Start executing the Z-machine.
In the normal case (starting a new game, or restarting), this is as simple as calling the Z-machine subroutine whose address is stored in the header.
If we're restoring from a save file, it's more complicated. See "resume_execution".
Wrapper around Z-code subroutine calls. The main reason we need it is for save/restore.
In the normal case, z_call just calls the Z-code subroutine at address arg0 with the given args (arg5-argn), if any. Args 1-4 aren't used by z_call, but (hack alert!) they go into the Perl call stack, which is needed for saving Z-machine state.
Input: subroutine address to call, local variables & eval stack (arrayrefs), next PC, store variable, args to the Z-sub.
See "The call stack" for far more detail on this sub and save/restore.
Implement the @save opcode, saving the current Z-machine state (as opposed to writing a table to a file, the other use of the @save opcode)
Note that this sub also gets called at the very end of the restoring process.
Returns 0 for failed save, 1 for successful save, 2 for "just finished restoring".
Create a Z-machine call stack by peeking at the Perl call stack.
When calling Z_machine subroutines, we call z_call with all the information contained in a Z stack frame. We retrieve that information from the Perl call stack and build a Z-machine call stack with it.
Implement the @restore opcode, restoring the current Z-machine state (as opposed to reading a table from a file, the other use of the @restore opcode)