Z-Machine#
Open 8bitworkshop IDE
Click here to write interactive fiction for the Z-Machine in the 8bitworkshop IDE now!
Z-Machine Specifications#
- Lifespan
1979-present (Z-machine versions 1-8)
- Media
Story files (
.z1-.z8), typically distributed on disk- CPU
Virtual machine (16-bit, stack-based), implemented in software
- Memory
128K-512K address space (version-dependent)
- Display
Text-based (virtual terminal), typically 80x24
- Sound
None (some interpreters support beeps)
- Input
Text parser (keyboard)
- Best-known games
Zork, The Hitchhiker’s Guide to the Galaxy, Planetfall
History#
The Z-Machine is a virtual machine created by Infocom for its line of interactive fiction games. It was designed in 1979 by Joel Berez and Marc Blank, who wanted a portable architecture so that games could run on many different computers (the name “Z” comes from the original codename “Zork”).
Each game is a “story file” containing a program for the Z-Machine. The story file is interpreted by a “Z-machine interpreter” (called ZIP in Infocom terminology), which was written for dozens of platforms: the Apple II, Commodore 64, IBM PC, TRS-80, Atari 8-bit, Amiga, and many more. The same story file runs unchanged on all of them.
The Z-Machine standard defines versions 1 through 8. Versions 1-5 were used for Infocom’s early and mid-period games; versions 6 and 7 added graphics and sound support (used by Journey and other later titles); version 8 was used for the later games like Beyond Zork and Zork Zero.
Today the Z-Machine lives on through the Inform compiler, which compiles modern interactive fiction into Z-machine story files, and through interpreters like Frotz and the web-based Quixe. The 8bitworkshop IDE supports development in Inform 6 and Dialog.
The Z-Machine Architecture#
The Z-Machine is a stack-based virtual machine with the following components:
16-bit words - the basic unit of data (and 8-bit bytes)
Program counter - points into the story file’s code
Stack - holds subroutine arguments, return values, and local variables
Variables - 16-bit registers: 240 global variables, 15 local variables per routine
Object tree - a hierarchy of objects with properties (used for room/object modeling)
Dictionary - the game’s vocabulary, used by the text parser
Text compression - Z-character encoding packs text into 5-bit characters with abbreviations and ZSCII escape sequences
The standard Z-machine has a 128K address space (versions 1-5) or 512K (version 8), plus a 64K “high memory” area for the game’s code and a “low memory” area for global variables and the object tree.
Memory Layout#
Region |
Contents |
|---|---|
|
Header (magic number, version, flags, etc.) |
Low memory |
Globals, object tree, dictionary, abbreviations |
High memory |
Code, strings, arrays |
(Version 6+) |
Graphics, sound resources |
The Object Model#
Interactive fiction is built around the Z-machine’s object model:
Objects represent rooms, items, and actors
Objects have properties (descriptions, state) and parent/sibling/child links forming a tree
The parser matches player input against the dictionary and invokes routines that manipulate the object tree
The Inform Compiler#
Inform is the primary language for writing Z-machine games. The 8bitworkshop IDE supports two flavors:
Inform 6#
Inform 6 is the “classic” Inform language, a procedural language with syntax derived from C and Pascal:
! Hello world in Inform 6
[ Main;
print "Hello, world!^";
quit;
];
Inform 6 programs are compiled with the inform6 compiler to produce
Z-machine story files. The 8bitworkshop IDE includes several Inform 6
example programs, including the “House Tutorial” series that walks through
building a complete game.
Dialog#
Dialog is a modern declarative language for interactive fiction that compiles to Z-machine story files. It emphasizes rules and relations rather than procedural code. The IDE includes Cloak of Darkness as a Dialog example.