Skip to content

Z-Machine

Infocom's imaginary computer

Infocom fitted a megabyte mainframe game onto 32K home computers by compiling it for a computer that did not exist, the Z-machine, and writing a small interpreter for each real one. Marc Blank and S. W. Galley described it in July 1980; by 1984 Infocom's games ran on nineteen machines. Graham Nelson's Inform brought it back in 1993, and people still write games for it.

In 1980 the Zork on MIT’s mainframe needed, in Dave Lebling’s words, the “megabyte address space” of a DEC PDP-10. The home computers Infocom wanted to sell it for had 32K. Instead of rewriting the game for each of them, Infocom’s founders invented a computer that did not exist. They called it the Z-machine. The game was compiled once into Z-code, the imaginary machine’s language, and each real computer got a small program, an interpreter, that pretended to be a Z-machine. Nobody had to port the game: once a machine had an interpreter, every Infocom game ran on it. The idea outlived Infocom. Hobbyists worked the machine out again from the story files in the 1990s, and people still write new games for it.

Fast facts

  • Designed: 1979, by Joel Berez and Marc Blank; published by Blank and S. W. Galley in Creative Computing, July 1980.
  • Company: Infocom.
  • Source language: ZIL, the Zork Implementation Language, compiled by ZILCH.
  • Interpreter: ZIP, one for each computer. By June 1984 Infocom’s games came for nineteen machines.
  • Versions: six from Infocom (1 to 6), two later ones (7 and 8) for large games written with Graham Nelson’s Inform.
  • Largest game: 128K in versions 1 to 3, 256K in 4 and 5, 512K in 6 to 8.

The problem

Zork was written in MDL, a LISP-like language, on the Laboratory for Computer Science’s PDP-10, and it had grown, Lebling wrote in BYTE in December 1980, “to strain even the megabyte address space of that machine.” Roy Wagner told Computer Gaming World’s readers in 1984 that the original “required nearly a megabyte (1 million bytes) of memory on the mainframe computer”, while the three-part micro version used “only about one quarter of a megabyte.”

The market was the other half of the problem. Graham Nelson, looking back in 1996, put it this way: “until the late ’80s, there were never less than a dozen home computer models in use, housing four or five different microprocessors: 6502, Z80, 68000 and so on. The individual markets were small and the challenge was to find a product to sell to all of them.”

How it worked

Marc Blank and S. W. Galley laid the design out in Creative Computing in July 1980, under the title “How to Fit a Large Program Into a Small Machine”. Their first step was to strip MDL of what Zork did not use, such as coroutines and fancy input and output. The smaller language that was left became ZIL. That was not enough, because even compiled straight to machine code the game “would still have produced an executable program too large to fit.” So:

The solution was to invent a “virtual machine,” specifically designed to execute Zork programs; the virtual “Z-machine” has a machine language called “Z-code,” in which Zork programs can be expressed very compactly. Then all that was needed was a Zork Interpretive Program (ZIP), written in the machine language of any given target personal computer, that would imitate a Z-machine in carrying out the Z-code operations.

The saving came from designing the instruction set around adventure games. Anything a game did often could become a single Z-code instruction, so its code lived once in the interpreter instead of many times in the game. Lebling’s example was moving an object from one room to another, which “takes just 3 bytes of storage.” Blank and Galley’s was the parser, the part of Zork that reads the player’s English: on the PDP-10 it took 10K 36-bit words, while the Z-code parser, “which is actually better functionally”, took 3K bytes. They compared the approach to compiling Pascal into P-code.

Text got the same treatment. Most of an adventure is prose, so Z-code packs three characters into every two bytes, five bits each. Five bits give only 32 codes, so the machine has three alphabets (lower case, upper case, and digits and punctuation) and shift codes to move between them, an idea the authors took from the five-bit Baudot code of old Teletypes. With the shifts counted, they wrote, text “work[s] out to about five and a half bits per visible character”.

The game did not have to fit in memory either. The interpreter split memory into three parts. The part that changes during play (the objects, the variables and the stack) stayed in memory, and saving a game meant writing just that part to disk or tape. The interpreter itself stayed resident. The rest of the game sat on the disk in 256-byte pages, read in only when needed, with a page table to keep track of which were in memory. Lebling told BYTE’s readers the result: Zork games “aren’t limited by the size of the system’s user memory”, and are “limited primarily by the size of a 5-inch floppy disk”. About 100K of disk held “about 10,000 words of English prose and a similar amount (about 40 K bytes) of code”. The Z-Machine Standards Document, a 1990s reconstruction by Graham Nelson, suggests the Z-machine may have been the first use of virtual memory on a microcomputer.

The same document shows how a game looks from inside. The world is a tree of objects, each with a parent, a sibling and a child. At the start of Zork I, the room “West of House” contains the player, the small mailbox and the door, and the mailbox contains the leaflet. Each object carries flags (“attributes”) and numbered properties; the machine itself does not know what they mean. The whole of Zork I ran to about 5,500 instructions, 110 rooms and around 600 words.

ZIL

Infocom’s writers, who called themselves implementors, did not program the Z-machine directly. They wrote in ZIL on the company’s DEC mainframe; Commodore Magazine reported in 1988 that it was a DEC 20 “lovingly known as ‘Fred’”. Chris Reeve, Infocom’s vice-president of product development, told the magazine that ZIL “is symbolic, like LISP, and checks the relationships between an object and an action to see if it [is] feasible.” Only then was the game turned into Z-code and “converted to the various microcomputers”, so that “all versions are essentially written at the same time.”

Michael Berlyn, author of Suspended and Infidel, told a CompuServe conference in 1984 how much work the language saved: “The language doesn’t make you do tiring programming tasks like declaring variables, it does that for you. It’s also fairly intelligent about the background universe. For example, when I wrote Infidel, I didn’t have to ‘program’ what it meant to look around a room. The game system automatically knew what ‘look’ meant, and how to do it. It also knew that if there was no light there, that you couldn’t see.”

One game, many machines

When Personal Software advertised Zork in December 1980, it came in two formats, for the 32K Apple II and the 32K TRS-80 Model I. In the same month Lebling listed interpreters for the Apple II, PDP-11, PDP-10 and TRS-80. According to the Standards Document, Scott Cutler wrote the first TRS-80 interpreter and Bruce Daniels the first Apple II one.

By June 1984 Infocom’s “Incomplete Works” advertisement offered its games for the Apple II, Atari, Commodore 64, CP/M 8”, DECmate, DEC Rainbow, DEC RT-11, IBM PC and PCjr, Kaypro II, MS-DOS 2.0, NEC APC, NEC PC-8000, Osborne, Tandy 2000, TI Professional, TI 99/4A and TRS-80 Models I and III, adding that the IBM version also served the Compaq, and the MS-DOS one the Wang and the Mindset. Each of those was a separate interpreter; the game files were the same. The Standards Document adds the Epson QX-10, Apricot, Macintosh, Atari ST and Amiga by 1985. Early interpreters were written in each machine’s own assembly language, one program for every model; by 1985 Infocom had begun writing them in C.

Versions 1 to 8

The first byte of every story file, as the game files are called, gives the version of the Z-machine it needs. The Standards Document describes the versions:

Version Used for Infocom’s interpreter
1 and 2 The earliest Apple II and TRS-80 releases ZIP
3 The “Standard” series, from Deadline in 1982 to 1987 ZIP
4 The “Plus” series, from A Mind Forever Voyaging in 1985 EZIP/LZIP
5 The “Advanced” series, from Beyond Zork and Border Zone in 1987 XZIP
6 Graphical games: Zork Zero, Shogun, Journey, Arthur YZIP
7 and 8 Not Infocom’s: added in the 1990s for large Inform games —

Version 3 held on for years because it fitted the 8-bit machines. It allowed a 128K story, although in 1982 to 1984 the practical limit was about 110K, a typical disk. It also allowed only 255 objects and 32 attributes. Most new games of 1985 and 1986 stayed in version 3 because, as the document puts it, “there were still plenty of 8-bit home computers around which were too small for Version 4 games.” Trinity had been shelved as too big for version 3 before version 4 made it possible. From version 4 onwards the machine grew bigger and added features: character graphics, a split screen (first built so Seastalker could show a sonar display), sound, timed input, and in version 6 pictures and a mouse. Commodore Magazine reported in 1988 that Brian Moriarty used the enhanced interpreters to give Beyond Zork an on-screen map, mouse movement and programmable function keys.

The Z-machine after Infocom

When Activision closed Infocom’s Cambridge studio in 1989, the Z-machine could have gone with it. Players kept it going. Working from Infocom’s story files, hobbyists reconstructed the machine; the standard names for its instructions were agreed between 1994 and 1995 by Mark Howell, author of the disassembler Txd, and Graham Nelson. Nelson released Inform, a compiler for a language of his own, in 1993; “Inform was so called because it forms Infocom files”, he explained in Acorn User in 1996. He also drew the comparison that the technique is usually remembered by: Berez and Blank “were far ahead of their time - 17 years later and the Java bytecode machine may soon be in every phone and television set.” The same column counted TADS, Inform and Hugo as the living design systems, and said that Infocom’s own compiler, ZILCH, was “missing, believed deleted.”

Nelson’s Z-Machine Standards Document, first drafted in November 1995, set down exactly how an interpreter must behave; revision 1.1, prepared by Kevin Bracey and Jason C. Penney, was finalised in May 2006. It records that about 130 story files compiled by Infocom survive, alongside the many written with Inform since 1993.

In 2013 Retro Gamer put ZIL and the Z-machine at the head of its list of adventure-game engines that came before LucasFilm’s SCUMM, and Ron Gilbert, in the same feature, remembered that “Infocom, who did text adventures, had this engine called the Z-engine that they used to build their games”.

Released source code

Infocom’s own tools have partly resurfaced. In April 2019 early MDL files of the Zork toolchain, recovered from the MIT Laboratory for Computer Science’s backup tapes, were published on GitHub as PDP-10/zil. They include versions of ZIL, the ZILCH compiler, the ZAP assembler and a ZIP interpreter dated between September 1979 and March 1981. The repository states no licence. The same month the archivist Jason Scott posted the ZIL source code of Infocom’s games to GitHub, and in November 2025 Microsoft released the source of Zork I, II and III under the MIT licence (see Zork).

Sources

  • Marc S. Blank and S. W. Galley, “How to Fit a Large Program Into a Small Machine, or How to fit the Great Underground Empire on your desk-top”, Creative Computing vol. 6 no. 7, July 1980, pp. 80–88: MDL stripped down to ZIL; the “Z-machine”, Z-code and ZIP; the parser sizes; the P-code comparison; three characters in two bytes, alphabets and the Baudot comparison; “five and a half bits per visible character”; impure, resident and paged storage in 256-byte pages; saving a game. https://archive.org/details/creativecomputing-1980-07
  • P. David Lebling, “Zork and the Future of Computerized Fantasy Simulations”, BYTE vol. 5 no. 12, December 1980, pp. 172 onward: the megabyte address space; the three-byte instruction; interpreters for the Apple II, PDP-11, PDP-10 and TRS-80; disk swapping and the capacity of a floppy; Personal Software as distributor.
  • Personal Software advertisement, Creative Computing vol. 6 no. 12, December 1980: Zork for the 32K Apple II and II Plus and the 32K TRS-80 Model I Level II disk systems.
  • Infocom advertisement, “The Incomplete Works of Infocom, Inc.”, Compute! issue 49, June 1984: the list of machines.
  • Scorpia, report of the CompuServe GAMESIG conferences, Computer Gaming World issue 18, September 1984, pp. 14–15: Michael Berlyn on ZIL.
  • Roy Wagner, Commodore column, Computer Gaming World issue 19, November 1984, p. 33: mainframe and micro sizes of Zork.
  • Russ Ceccola, “Adventures at Infocom”, Commodore Magazine vol. 9 no. 1, January 1988, pp. 70–73 and 117–118: the DEC 20 called Fred; Chris Reeve on ZIL; ZIPs and EZIPs; Beyond Zork’s map and mouse.
  • Graham Nelson, “The new Brand X?”, Acorn User issue 174, November 1996, pp. 83–84: the market problem; Berez and Blank; the Java comparison; ZIL and ZILCH; TADS, Inform and Hugo; the name Inform.
  • Mike Bevan, SCUMM feature with the sidebar “Adventure game engines - before and after SCUMM”, Retro Gamer issue 110, January 2013, p. 74: ZIL and the Z-machine; Ron Gilbert on the “Z-engine”.
  • Graham Nelson and others, The Z-Machine Standards Document, version 1.1 (2006; web edition 2014) (web, secondary): preface (virtual memory, about 130 Infocom story files, the naming of opcodes, the history of the Standard), overview (the object tree), §1 (memory regions and story-file limits), §3 (text encoding), §11 (header and interpreter numbers), Appendix D (the history of the versions, interpreter names, the first interpreters and later platforms) and Appendix E (statistics for Zork I and other games). https://inform-fiction.org/zmachine/standards/z1point1/
  • PDP-10/zil, GitHub repository, created 30 April 2019 (web): the 1979–1981 MDL files of ZIL, ZILCH, ZAP and ZIP. https://github.com/PDP-10/zil

See also

Checked. Verified against primary sources and signed off by a person.