Monday, March 11, 2019

Chapter 8. PARSER: New Commands and Routines (Part 1)

8.1 Introduction

Ever since the first version of Zork 1, there has been an AGAIN command. However, it basically used the previously saved PRSA, PRSO, and PRSI in a PERFORM call. The use of EZIP allowed new routines to be created to handle the various new buffers and provide new commands. Starting with AMFV, a new method to manage the input and token buffers allowed for a more sophisticated AGAIN command. The game also introduced the OOPS command where unknown words in a command could be corrected one by one. Beyond Zork added the UNDO command which allows the user to “go back” one command.
Also two new buffers were created, AGAIN-LEXV and OOPS-INBUF, for three new routines. In essence, they could be also considered previous LEXV and previous INBUF, respectively.

8.2 STUFF

  • Arguments: source buffer, destination buffer, length
  • Returns: TRUE
STUFF copies a set length of tokens from the source buffer to the destination buffer. If no length is given, the maximum length (29 tokens) is used. First, the two bytes (maximum and actual number of tokens) at the start of the token buffer are copied.  Then all the token buffer data is copied up to the amount requested. The routine always returns TRUE. Beyond Zork was able to replace this routine with a new opcode (COPY_TABLE). Sherlock still used STUFF.

8.3 INBUF-STUFF

  • Arguments: source buffer, destination buffer
  • Returns: TRUE
INBUF-STUFF just copies the entire contents one character at at time of the source input buffer to the destination input buffer. With XZIP, Beyond Zork and Sherlock used a new instruction (COPY_TABLE) to handle this routines.

8.4 New AGAIN command

In Infocom games since AMFV, the AGAIN command is more formally processed and checked specifically by PARSER. If it is given, several checks are done before the old command is copied back and processed:
  1. Check that last command was not orphaned
  2. Check that last command was valid
  3. Check that the actor in last command is still present. This is to ensure that any non-player actor is present if an actor direct command is used again.
  4. Check the subsequent token (if it exists) is not a end-of-command token (THEN, AND. period, or comma). Then print the error message.
If all the above checks pass, PARSER copies the old input buffer from OOPS-INBUF into INBUF. It does the same for the AGAIN-LEXV to LEXV.
If commands exist after an AGAIN command, the entire token and input buffers are temporarily saved into reserve buffers, RESERVE-LEXV and RESERVE-INBUF, respectively, because they would’ve been overwritten while performing the AGAIN command. The start of the next command is also saved in RESERVE-PTR. The previous WINNER, P-MERGED flag, and DIR (just in case) are restored from global variables. The previous token and input buffers, AGAIN-LEXV and OOPS-INBUF, are again copied back into LEXV and INBUF, respectively. Finally, OTBL is copied back into ITBL. PARSER then continues to process the newly restored command as normal. On the next iteration of PARSER, it will detect that RESERVE-PTR is set and copy the remain command info from RESERVE-LEXV and RESERVE-INBUF data back into LEXV and INBUF, respectively. The next command starts in the restored data at the location indicated by RESERVE-PTR.

No comments:

Post a Comment