Zork Machine Interpreter and Debugger (ZORKMID for short)

I have written a new Z-machine interpreter, with many debugging features, and is also hopefully much cleaner than the other ones I (and others) have previously done. In addition, in checks various errors.

Please make any bug reports, features suggestions, questions, complaints, etc on here and/or on ifMUD.

Download (source (public domain), and man page): http://zzo38computer.org/zmachine/interp/zorkmid.zip

Note that it only implements ZIP (Z-code version 3); I may later write EZORKMID and XZORKMID for implementing other Z-code versions.

This interpreter does a lot of error checking in order that you can check if the program is correct; in most such cases the debugger is then activated so that you can examine the program to see what went wrong. The debugger also allows editing data in memory (including locations above ENDLOD), single-stepping through the program, disassembling codes, decoding packed text strings, checking the highest stack usage of the program, setting breakpoints (both at specific addresses as well as for specific instruction opcodes), and a few other things.

This is also believed to be the only existing Z-machine interpreter that supports small-endian story files (although I do not recommend using this feature except for testing and for extremely specialized implementations; it is included only for completeness).

This interpreter passes ziptest.

1 Like

I compiled it in Linux and tried it on a couple of Infocom games. It loads them and prints the opening fine, but doesn’t recognize any commands that I type.

Works for me, for the Infocom games I have tried anyways. Can you please post your steps of reproducing the bug? (This means, command-line parameters, commands you tried to type, the responses you got (if any), what story file (and story version), etc)

$ ./zorkmid ~/IF/Infocom/Zork1V88.z3

ZORK I: The Great Underground Empire
Copyright © 1981, 1982, 1983 Infocom, Inc. All rights reserved.
ZORK is a registered trademark of Infocom, Inc.
Revision 88 / Serial number 840726

West of House
You are standing in an open field west of a white house, with a boarded front
There is a small mailbox here.

I don’t know the word “i”.

I don’t know the word “examine”.

I don’t know the word “quit”.

It just doesn’t seem to know any words. The same happens with every story file I’ve tried. The included EXE file works fine in Wine; maybe there’s something wrong with the way I compiled the binary (but I just typed gcc zorkmid.c -o zorkmid).

I use a 64-bit system. Maybe the code’s not 64-bit clean?

same problem for me, with gcc version 4.8.2, on Linux mint 64 bit, the commands I type are not recognised.

On 32 bits gcc 4.7.2 (Debian 7 GNU/Linux), same problem.
(with the z5 from ia600700.us.archive.org/5/items … chineFile/)

I changed it (to fix some sequence points, to make it to use stdint.h, and a few other corrections), and it still doesn’t work on Linux. I tried it both on Windows and Linux, and I have the same problem you do on Linux but it works on Windows.

OK, I found the mistake and have fixed it. It now works on Linux (at least, the one I tried).

Works great for me now. Thanks!

New version is available:

  • ANSI support removed; ZTERM added. (It could be possible to make a external ZTERM/ANSI interface, if you want to use ANSI.)
  • Minor support for symbolic debugging is added.
  • A bug fix dealing with scripting. (Previously it would not even check if scripting is turned on when trying to script.)
  • Disassembler syntax has been changed to distinguish positive and negative predicate branches.

You can write some comment/suggestion/question/complaint, if you like to do so!

A new version is now available; a manual page is now included. ANSI and ZTERM have been removed for now.
Download from http://zzo38computer.org/zmachine/interp/zorkmid.zip

EZORKMID has not yet been written; I intend to do so soon.

Please notify me of anything wrong with the manual page. (One thing known to be wrong is that the backslash doesn’t display.) You can also notify me of other bugs, suggestions, complaints, etc, please.

There have been a few other bugs; I have now (hopefully) fixed them. Here are list of bug fixes:

  • Flags for objects would previously display as all 0 in the debugger.
  • Selecting a new scripting file previously caused a segmentation fault if no scripting file was previously open.

As a player of IF, I was wondering how your Z-machine interpreter is going to be different/better than the popular options already available? Thank you.

It is mainly a matter of preference, and you can also install multiple interpreters if needed (such as one for ZIP and one for EZIP). Also, you will need a C compiler if you want to run this program because executables are not provided (I no longer use Windows; I am now on Linux, and on Linux it is better to compile it yourself; it will probably still work on Windows though if you can compile it).

One of the main features this program has is a debugger, as well as a lot of error checking. Using this debugger you can look at and trace the codes of Zork, and I have also found this debugger useful for debugging other Z-machine interpreters. Also, the code of ZORKMID is only 1807 lines long (part of this is taken up by the debugger code), and seems to me that it may be easy to learn from to learn how to write your own implementation.

This program is not GUI. It run on command-line using a terminal or terminal emulator (which you must provide) connected to stdin/stdout. (Redirection from/to files/devices is also possible, which may be used to automate testing or to allow making as a remote service or to execute a filter on the output or something else.)

There are other features too (some of which I have not seen anywhere else):

  • Instruction profiling to count how often each instruction opcode is used
  • Disassembler
  • Optional use of an external file/device for random numbers (for example, you can use /dev/urandom on Linux, or you can use this to generate the same random numbers each time)
  • Stack highwaters
  • Edit memory at runtime in the debugger
  • Both big-endian and small-endian story files are supported
  • Permanent shifts are implemented
  • Debugger and save games can both be disabled by command-line switch if needed
  • The “embrace fwords” option
  • Tandy option
  • Screen pausing and word wrapping are configurable and can be disabled
  • A command-line switch can enable “escapes”, which can be executed in place of your input

The following escapes are provided:

  • Scroll one line of text after a MORE prompt (normally it scrolls one page instead)
  • Disable screen pausing until next READ instruction
  • Break into debugger
  • Restart
  • Quit
  • Count instructions executed between READ instructions
  • Set scripting filename
  • Display status line

You can provide additional feature requests here if you want to.

Thank you.

Have you made any progress for a version to handle V5 files?