Project

Completed

Building Infocom games from source

Compiling the original Infocom ZIL source for Zork, Planetfall, Hitchhiker’s Guide and 30 more into playable games.

Source ↗

I love games, have done ever since owning a ZX Spectrum in the early-80s; seeing Jetpac on a friend’s machine was love at first sight, as were a lot of games by Ultimate Play The Game. This was followed by a C64 with a tape unit and 1541 disk drive.

I was a big fan of Infocom games back then. The large cardboard boxes with 5.25” disks and accessories, maps, artwork…there was something to behold of those games. Admittedly I wasn’t very good at adventure games, but they had a way of capturing one’s imagination in a way that not a lot of games did at that time.

Half the frustration was in working out what the parser would accept, and getting very annoyed with it. I’ve not really looked at the games much since then, but from time to time I like to play retro games, 8bit, 16bit, and sometimes these text-based adventure games come up.

I came across the-infocom-files on GitHub. I was browsing retro game stuff and seeing the Infocom stuff kind of got my juices flowing again. I wonder if I’d be any good at them now that I’m older, with more patience, or whether I would invent new swear words.

The repo hosts tidied-up source code for Infocom’s games. I wanted to know if I could turn that source into something I could actually play. It turns out you can: I started with Zork I and finished with 35 playable Infocom games.

First off, I did all of this on a Mac. If you’re on Windows or Linux, the steps are almost the same, and there’s a section near the end covering the differences, but fair warning, I’ve not tested it on those platforms.

What’s in the repo

Infocom wrote its games in ZIL (Zork Implementation Language), a Lisp-like language descended from MDL, which was used at MIT. ZIL doesn’t compile to native code. It compiles to a story file for the Z-machine, a virtual machine Infocom designed so the same game could run on every home computer of the era. All you need to play a story file today is a Z-machine interpreter.

Step 1: Install ZILF on macOS

ZILF is written in C# and is distributed via pre-compiled binaries.

  1. Go to the ZILF Download Page and grab the latest macOS arm64 (for Apple Silicon M1/M2/M3/M4) or macOS x64 (for older Intel Macs) bundle. Other OS are available via GitHub.

  2. Extract the downloaded archive into a folder named zilf inside your development environment (e.g., ~/developer/zilf).

tar -xvf zilf-1.9.0-osx-arm64.tar.gz
  1. Handle macOS Gatekeeper: Because ZILF is downloaded outside the Mac App Store, your terminal might kill the process upon launch (Process killed) or flag it. You can bypass this by clearing the quarantine flag via Terminal:
xattr -dr com.apple.quarantine ~/developer/zilf/

For ease of use put ZILF on your path.

cd ~/developer/zilf

export PATH="$PWD/zilf/bin:$PATH"

Step 2: Grab the Original ZIL Source Files

The official historical ZIL files released during the open-source initiative are hosted online.

  1. Clone or download the Zork I source code from the official archive on GitHub:
git clone https://github.com/historicalsource/zork1

Step 3: Run the Multi-Stage Compilation

ZIL source files cannot be transformed directly into a game file in one click. It requires two distinct components inside your ZILF folder: zilf (the compiler) and zapf (the assembler).

From inside the game folder, it’s two commands:

cd zork1

zilf zork1.zil

zapf zork1.zap

This compiles the assembly text into the final game file, producing zork1.z3 (or .z5 depending on the version target).

When I ran it ZILF printed warnings, but nothing serious.

That’s it: an 84 KB file, zork1.z3, in the same format Infocom shipped on floppy disks in the early 80s.

Step 4: Play and Test Your Build

The resulting game file is a virtual machine image. To run it, you need a Z-machine interpreter.

You have two choices:

  • Download Spatterlight, a modern Interactive Fiction interpreter designed for macOS.
  • Install the classic command-line interpreter Frotz via Homebrew.

I’m going with the latter:

brew install frotz

frotz zork1.z3

image

That installs three versions:

  • frotz, the full-screen terminal version with a status bar
  • dfrotz, a “dumb” version that just reads and writes plain text
  • sfrotz, a graphical SDL version

dfrotz is handy for testing, because you can pipe a list of commands in and check that the game responds properly:

printf 'open mailbox\nread leaflet\nnorth\nnorth\nup\ntake egg\n...' | dfrotz -m -p zork1.z3

Zork II and III

The sequels use exactly the same layout.

git clone https://github.com/the-infocom-files/zork2.git
git clone https://github.com/the-infocom-files/zork3.git

(cd zork2 && zilf zork2.zil && zapf zork2.zap)
(cd zork3 && zilf zork3.zil && zapf zork3.zap)

Both compiled with no errors (26 warnings each), producing an 89 KB zork2.z3 and an 85 KB zork3.z3.

Zork II starts in the Barrow with the lantern and sword. Zork III opens with the Dungeon Master’s dream sequence at the bottom of the Endless Stair.

One quirk: the banner shows Release 1 and a serial number based on the build date, not the original Infocom release numbers. That’s expected when you build from source yourself.

The rest of the catalogue

With Zork working, I wanted to try other titles. You can find the Infocom source repo here on The Infocom Files.

I tried Deadline, Planetfall, Leather Goddesses of Phobos and The Hitchhiker’s Guide to the Galaxy. These turned out to be easier than Zork: each repo includes its own parser and verbs, so there’s no shared engine to clone. It’s just clone, zilf, zapf.

That worked so well that I went through the rest of the titles. Almost every game has a main file with the same name as its repo, so a simple loop builds most of them:

for g in amfv ballyhoo beyondzork borderzone bureaucracy cutthroats deadline \
         enchanter hitchhiker hollywoodhijinx infidel journey leathergoddesses \
         lurkinghorror moonmist nordandbert planetfall plunderedhearts seastalker \
         sherlock sorcerer spellbreaker starcross stationfall suspect suspended \
         trinity wishbringer witness; do
  git clone https://github.com/the-infocom-files/$g.git
  (cd $g && zilf $g.zil && zapf $g.zap)
done

Every one of those compiled first time. A few things stood out:

  • Not all .z3. Infocom extended the Z-machine as its games got bigger. Most of the classics are version 3 (.z3). A Mind Forever Voyaging, Trinity, Bureaucracy and Nord and Bert are version 4 (.z4). Beyond Zork, Border Zone and Sherlock are version 5 (.z5). ZILF picks the right version from the <VERSION> line in the source.
  • Bigger games. The early titles are 80 to 125 KB. Trinity, A Mind Forever Voyaging and Beyond Zork are around 250 KB.
  • Some odd openings, all expected. Beyond Zork asks “Is this a VT220?”. Bureaucracy makes you fill in a licence application form before you can play. Leather Goddesses opens with a content warning and has you choose a toilet in Joe’s Bar, which is how the game decides your character’s gender.

The tricky ones: Infocom’s new parser

Four of the later games, Zork Zero, Shogun, Journey and Arthur, are version 6 games that originally had graphics. Journey built with the loop above, but the other three failed with around a hundred errors each.

The cause was that they use Infocom’s later “new parser”, a shared library that isn’t in their repos. It lives in a separate repo, zillib, and ZILF needs to be told where to find it with -ip (include path):

git clone https://github.com/the-infocom-files/zillib.git

(cd zork0 && zilf -ip ../zillib -ip ../zillib/parser zork0.zil && zapf zork0.zap)
(cd shogun && zilf -ip ../zillib -ip ../zillib/parser a5.zil && zapf a5.zap)

Note that Shogun’s main file is a5.zil, its old internal project name, so you’ll want to rename the output to shogun.z6.

That fixed Zork Zero and Shogun. Arthur needed a few small edits to its source before it would build:

  1. Old file paths. Arthur loads the parser with <XFLOAD "~PARSER/PARSER.REST"> and the hints with <INSERT-FILE "~ZILLIB/CLUES">. Those ~PARSER and ~ZILLIB paths pointed at folders on Infocom’s own systems. Changing them to <INSERT-FILE "parser.rest"> and <INSERT-FILE "clues"> lets ZILF find them on the include path.
  2. Upper-case package names. Arthur writes things like <INCLUDE "PDEFS">, while the parser library itself uses <INCLUDE "pdefs">. ZILF treats those as two different packages, so it loaded the parser definitions twice and complained that everything was “already defined”. Lower-casing the names in Arthur’s INCLUDE and USE lines fixed that.
  3. One missing constant. The shared parser checks whether the player’s action is V?DO?, the action for a DO command. Arthur’s developers commented that command out, so the constant never exists and ZILF refuses to compile. Adding <CONSTANT V?DO? -1> gives it a value that can never match a real action.

After that, Arthur compiled cleanly, and it starts properly in the Churchyard, with Merlin, a torque and a chivalry score.

One caveat for all four version 6 games: the artwork was stored in separate picture files that aren’t part of the source code. The games still run, but text-only, with a one-off “picture resources are missing” warning from Frotz. Journey is the least comfortable of the four, because it’s built around menus rather than typed commands.

What I didn’t build

I skipped the repos that aren’t full games: the InvisiClues hint files, the three Infocom samplers, the German and “mini” versions of Zork, and a second, raw copy of Hitchhiker’s Guide.

A shortcut to play them

I copied every story file into its own folder under ~/Games (for example ~/Games/planetfall/planetfall.z3), then added a function to my .zshrc:

# Play Infocom games in ~/Games: `infocom` lists them, `infocom planetfall` plays one
infocom() {
  if [[ -z $1 ]]; then
    print -l ~/Games/*/*.z[1-8](N:t:r)
    return
  fi
  local game=( ~/Games/$1/$1.z[1-8](N) )
  (( $#game )) || { print -u2 "infocom: no game '$1' in ~/Games"; return 1 }
  frotz $game[1]
}
_infocom() { compadd ~/Games/*/*.z[1-8](N:t:r) }
compdef _infocom infocom

# Play Zork: `zork` for Zork I, `zork 2` / `zork 3` for the sequels
zork() { infocom zork${1:-1} }

Typing infocom lists everything, infocom hitchhiker starts a game, and Tab completes the names. zork still drops me straight into the field west of the white house.

On Windows or Linux

I only tested this on macOS, but nothing in the process is Mac-specific. ZILF publishes official builds for all three platforms, and Frotz is everywhere. The only changes are how you install the two tools.

macOSLinuxWindows
ZILFosx-arm64 tarballlinux-x64 or linux-arm64 tarball, .deb or .rpmwin-x64 zip or .msi installer
Interpreterbrew install frotzsudo apt install frotz (or your distro’s equivalent)Windows Frotz or Gargoyle
Shellzshbash or zshPowerShell

Linux is almost identical to macOS. Download the Linux tarball for your CPU from the ZILF releases page, put its bin folder on your PATH, and every command above works as written. If you use bash rather than zsh, this simpler shortcut does the same job:

infocom() { frotz ~/Games/"$1"/"$1".z[1-8]; }

Windows needs the most translation, but it’s still straightforward. Install Git, download the ZILF Windows zip, and run the same zilf and zapf commands from PowerShell. The zip has no top-level folder, so extract it into one. The Zork I build looks like this:

git clone https://github.com/the-infocom-files/zork-substrate.git
git clone https://github.com/the-infocom-files/zork1.git
Expand-Archive zilf-0.11.1-win-x64.zip -DestinationPath zilf
$env:Path = "$PWD\zilf\bin;$env:Path"
cd zork1
zilf zork1.zil
zapf zork1.zap

Then open zork1.z3 in Windows Frotz. It has a proper windowed interface, so there’s no terminal shortcut to set up. Alternatively, Windows users can install WSL and follow the Linux steps exactly.

Whichever platform you build on, the story files are identical. A .z3 built on a Mac plays the same in Windows Frotz, Gargoyle, or a phone app.

A note on licences

The Zork repos carry an MIT licence from Microsoft, so those are fine to share. You can read the press release about Zork on the Microsoft website.

The other games’ repos have no licence file, so building and playing them yourself is fine.

Summary

StepTool
Get the game sourcegit clone (one repo per game)
Get shared codezork-substrate for Zork, zillib for V6
Compile ZIL to assemblyzilf
Assemble the story filezapf
Playfrotz (or any Z-machine interpreter)

All 35 games now start and respond in Frotz. It still amazes me that code written more than 40 years ago compiles with a modern open-source toolchain and runs exactly as intended.

In some ways, I think playing these text-only adventures are a nice antidote to modern games, and perfect for winter evenings and lazy Sunday’s! Just remember, save often, and watch out for grues.