I’m sure I’m just missing something in the documentation or misunderstanding something about how instructions are parsed.
I’m updating my interpreter for z5 support and running test programs against it. So far, so good with Praxix and czech (both passing 100% for supported features), but not so with etude.z5
. It can’t even get to the initial input cursor without crashing.
I ran txd.exe
against the .z5 file and I’m looking at the etude source code.
I’m getting tripped up on the var instruction read
.
In the txd output, I see these instructions
31c5: e2 17 05 9a 00 4d STOREB #059a,#00,#4d
31cb: e2 17 05 9a 01 00 STOREB #059a,#01,#00
31d1: cd 4f 02 05 9a STORE L01,#059a
31d6: 0d 04 00 STORE L03,#00
31d9: e4 bf 02 04 READ L01 -> L03
In my parsing of the instruction, bf
is 10 11 11 11
where 10
gets the next byte as a var byte, then the next 2 bits 11
tells me to stop fetching bytes, though it looks to me like I should be grabbing the next byte 04
In the source, this seems to coincide with these instructions
print "^> ";
inbuf->0 = (INBUFSIZE-3);
inbuf->1 = 0;
inbufvar = inbuf;
ix = 0;
@aread inbufvar ix;
This appears to be passing 0
as the second parameter to @aread
, which… explains why the decoded instruction only had me read one var?
Ultimately, this means that read
only receives one parameter: the text-buffer (baddr1)
I don’t see anything in the z-machine docs (neither Nelson nor Klooster) that says what to do to handle this case. Klooster writes
Finally, if baddr2 is not zero in V5+,
the sequence stored in the buffer is tokenised,
just as if a tokenise baddr1 baddr2 instruction was used.
OK, but what if baddr2 IS zero? Or have I misunderstood how var instructions are processed in some subtle way? I’ve played dozens and dozens of games and never encountered this issue, but maybe z5 has a chance of it occuring? At any rate, etude triggers it so I want to tighten things up and claim victory over this bug.