[z-machine] Returning 2 from @save in z5

David Kinder d.kinder@btinternet.com
Tue, 30 Sep 2003 23:09:45 +0100


> This seems to be a universal problem. I haven't yet verified this by running a
> test story through them, but I've checked the sources of Frotz, Malyon, Zip and
> Rezrov and they all seem to work by storing 2 to the target of the @restore,
> not the @save.

I think you'll find that if you run a test program (at least in Frotz, but probably
the others) you'll find that the interpreters *do* do the right thing, even if you
try to do a @restore with a different result location.

Anyway, I think that the following is where you're going wrong:

> Suppose we load an arbitrary game from disk. The PC is pointing at the instruction
> after the @save which saved the game.

At least in Frotz, this is not true. The instruction decoder in Frotz doesn't get
the store value before calling the opcode subroutine: it expects the opcode routine
to do that as it's final step. So, when @save is called the PC is pointing to the
byte that gives the store variable, and it's this PC that is written out in
the saved file.

Now, when @restore happens, it loads in the saved game and resets the PC, and only
*then* does it read the store variable and increment the PC. That way, if @restore
is successful, it writes 2 to the @save opcodes store variable, not its own!

Mind you, I haven't tested it either, so I could be wrong... but I'm fairly
confident I'm not.

David