Zork And The Z-Machine: Bringing The Mainframe To 8-bit Home Computers

Computer games have been around about as long as computers have. And though it may be hard to believe, Zork, a text-based adventure game, was the Fortnite of its time. But Zork is more than that. For portability and size reasons, Zork itself is written in Zork Implementation Language (ZIL), makes heavy use of the brand-new concept of object-oriented programming, and runs on a virtual machine. All this back in 1979. They used every trick in the book to pack as much of the Underground Empire into computers that had only 32 kB of RAM. But more even more than a technological tour de force, Zork is an unmissable milestone in the history of computer gaming. But it didn’t spring up out of nowhere.

DEC PDP-10 Flip Chip module
DEC PDP-10 Flip Chip module

The computer revolution had just taken a fierce hold during the second World War, and showed no sign of subsiding during the 1950s and 1960s. More affordable computer systems were becoming available for purchase by businesses as well as universities. MIT’s Laboratory for Computer Science (LCS) was fortunate to have ties to ARPA, which gave MIT’s LCS and AI labs (formerly part of Project MAC) access to considerable computing resources, mostly in the form of DEC PDP systems.

The result: students at the MIT Dynamic Modeling Group (part of LCS) having access to a PDP-10 KA10 mainframe — heavy iron at the time. Though this PDP-10 was the original 1968 model with discrete transistor Flip Chip modules and wire-wrapping, it had been heavily modified, adding virtual memory and paging support to expand the original 1,152 kB of core memory. Running the MIT-developed Incompatible Timesharing System (ITS) OS, it was a highly capable multi-user system.

Naturally, it got mostly used for playing games.

Are you ready for an adventure?

In the Spring of 1977, a game arrived at MIT called Colossal Cave Adventure (or ‘Adventure’ for short). This game was the first interactive fiction computer game, providing the player with a text adventure involving a big cave system that’s rumored to be filled with treasures. Reminiscent of ‘choose your own adventure’ books, the player would make choices that would lead them through the cave’s rooms, either succeeding at recovering treasure and escaping alive, or meeting an untimely demise.

Inspired by this game, a group of students at LCS figured that they could do better than this Stanford-developed project. The main weakness they spotted was that Adventure was implemented in FORTRAN, a language not exactly know for its strong dynamic text-handling features, let alone the needs of an interactive fiction game. Because of this, Adventure essentially hard-coded the entire game, limiting flexibility and complicating extending and maintaining the game.

In Adventure, each room has a numeric ID, with an associated description in a table. Another table defines its short description. Another table lists which rooms lie relative to other rooms using their numeric IDs. This means that in order to add a room, one has to modify all of these tables, taking care not to cause any issues with those changes.

Hacker rivalry

Using the natural language experience that existed at LCS and the AI departments back then, it was Dave Lebling who first put together a simple parser and beginnings of a game engine akin to that of Adventure, using the LISP-derived MDL programming language. Using the strong natural language processing capability of MDL, Marc Blank, Bruce Daniels and Tim Anderson then built upon Lebling’s efforts to create the first prototype game that would ultimately turn into the game we know as ‘Zork’ today.

The revolution of Zork was that it could grasp entire sentences due to the strong natural language features of MDL, in contrast to the simple commands of Adventure, where ‘LAMP GET’ and ‘GET LAMP’ were equivalent. It could grasp full sentences, and even multiple sentences (commands) strung together into a single sentence. The strong parser, coupled with the ease of modelling new rooms in an object-oriented style using MDL, meant that after the parser and game engine had been written the world could be expanded practically at will.

A room in Zork could be defined using a simple bit of code like this:

"This is an open field west of a white house, with a boarded front door."
"West of House"
<EXIT "NORTH" "NHOUS" "SOUTH" "SHOUS" "WEST" "FORE1" "EAST" #NEXIT "The door is locked, and there is evidently no key.">

This defines the ‘white house’ from the beginning of the game, along with exits from this room, special properties of exits (e.g. a locked door) and the objects in the room. This ensures that all properties of a room, including its description, short description, properties and tags are in one location. The game engine can then toggle individual tags (bits) on rooms, keeping a central database of all rooms and their current status. Managing which rooms are connected during game design is done using proper names, not numeric IDs in a table.

Smash hit

Suffice it to say, Zork was absolutely fantastic on mainframes. It was ported to the far more widespread DEC TOPS-20 OS for the PDP-10 by popular demand from other interested gamers. Though the Zork developers were generous enough to give the game away for free, they did distribute it as a read-only, encrypted version. They even stored the source code for Zork in a secure folder on the ITS mainframe, for which they had to patch the otherwise fully open and unsecured ITS mainframe OS.

At this time in computer history, there were still relatively few computers in the world. The concept of a home computer was only beginning to take hold, with the introduction of computers like TRS-80 and the Apple II in 1977, though even that system was incredibly limited compared to the mainframes that were being used for text adventures at the time by students around the US. The thought of porting a game like Zork, a 1 MB executable, to home computers seemed rather far-fetched.

While home computers were still scarce, the concept of selling software to regular consumers was also new. This was the time when the Atari 2600 had just gone on sale, starting the second generation game consoles that were expandable to play more that one game through the use of plug-in cartridges. It was a new market, with many questions among MIT, Stanford and other students regarding the open hacker culture versus the world of commercial software. Some, like Richard Stallman, not changing their stance on this much since their student days at MIT.

As the Zork developers were graduating, they realized that with the success of Zork on their hands, they had this one chance to commercialize it, taking their lives and careers into an entirely different direction from their original goals. With little standing in their way, Infocom was founded on June 22nd, 1979.

Now we just have to port it

This only left the tiny little detail of getting Zork from the PDP-10 mainframe systems onto those dinky little home computers; at this point Infocom didn’t actually have anything to sell yet. They mulled various game ideas that could be adapted to work on home computers, but porting Zork just made too much sense. They just had to crack the problem of getting 1 MB of MDL-based game code onto microcomputers with 32 kB of RAM (or less) and relatively anemic amounts of storage.

They also didn’t want to have to port the game separately to the TRS-80, Apple II, or any upcoming new systems. What if one could use the existing MDL source code? This was the start of the design of the Z-Machine, as it came to be known.

Of course, the initial approach to making Zork fit on a microcomputer was to make the game smaller by removing content. After lots of cutting they had something close to the size of Adventure. They then did something similar with MDL, removing all features that weren’t needed for Zork. This created the Zork Implementation Language (ZIL) which they could cleanly port Zork to from MDL. The ZIL compiler was then able to produce much smaller binaries than the MDL compiler.

Looking at the description of Zork’s brass lantern in ZIL we can see that it’s easier to read than MDL:

(DESC "brass lantern")
(FDESC "A battery-powered lantern is on the trophy
(LDESC "There is a brass lantern (battery-powered)
(SIZE 15)>

This was great, of course, but this still didn’t make Zork run on a TRS-80. They could at this point of course have written a ZIL compiler for each platform, along with a ZIL runtime, to then spend a lot of time tweaking each game on every target platform. Instead they opted to write this virtual machine: the Z-Machine. Essentially an ideal platform for text adventure games, directly supporting ZIL binaries and also implementing a number of optimizations, most important of which was the packing of characters into 5 bits, reminiscent of Baudot code.

With all of those optimizations, a virtual machine, and a custom programming language, they managed to squeeze the trimmed-down world of Zork I into a mere 77 kB ‘story file’, along with the interpreter (the VM). Since this was still too much to fit into the 32 kB of a mainstream microcomputer of the time, the VM implements a virtual memory system, with just the dynamic data (variables) loaded into RAM and any static data (text) only got read from the floppy disk when needed.

Towards the future

The Apple II had floppy disks with 140 kB capacity, and the TRS-80 had 180 kB, which meant that the space problem had been solved. Only the interpreter needed to be optimized for the target platform, which meant that for all future Infocom games the same interpreter could be used for each and every game that got released, without having to port it to individual platforms.They had more content waiting in the wings from the mainframe version of Zork. They were set for a sequel.

After the commercial success of Zork I, they’d continue to release the parts that were cut from the original mainframe version in the form of Zork II, as well as Zork III. Year over year, the sale of Zork I would keep rising, and it became a must-have game often provided with new systems. New Z-Machine versions were developed that added additional features for even more advanced games.Today we can still enjoy Infocom games without having to worry about compatibility issues: the MDL source to Zork as well as the source for other classic Infocom games have been released. If you haven’t played Zork in a while, or ever, give it a spin and then have a look under the hood. It’s not a stretch to say that a group of hackers at US universities during the 1970s have very likely defined the world of video gaming and interactive story telling.

30 thoughts on “Zork And The Z-Machine: Bringing The Mainframe To 8-bit Home Computers

    1. A Colossal Adventure is based on Bedquilt Cave in Mammoth Cave Nat’l Park. Bedquilt Cave is basically the backdoor to Colossal Cave. Pry bar Room, Hall of the Mountain King, Y2 room and others are landmarks in the cave. Y2 is a survey marker. The original author William Crowthers was a member of the Cave Research Foundation which is the organization that surveys and maps the Mammoth Cave System.

  1. “With all of those optimizations, a virtual machine, and a custom programming language, they managed to squeeze the trimmed-down world of Zork I into a mere 77 kB ‘story file’, along with the interpreter (the VM). Since this was still too much to fit into the 32 kB of a mainstream microcomputer of the time, the VM implements a virtual memory system, with just the dynamic data (variables) loaded into RAM and any static data (text) only got read from the floppy disk when needed”

    Techniques to borrow for today’s machines. Now all we need is bring back the floppy.

    1. “With all of those optimizations, a virtual machine, and a custom programming language, they managed to squeeze the trimmed-down web app into a mere 77 GB ‘story file’, along with the interpreter (the VM). Since this was still too much to fit into the 32 GB of a mainstream microcomputer of the time, the VM implements a virtual memory system, with just the dynamic data (variables) loaded into RAM and any static data (text) only got read from the SSD when needed”

      There, I’ve updated it for modern javascript implementations.

  2. Used to play adventure on Friday evenings on an intel machine, later my own CP/M machine. Zork seemed a little shallow in comparison: You solved a puzzle, got in, got a treasure and went on, while in adventure, once you solved a puzzle, there was lots more to explore. I found adventure for windows, and my children enjoyed it in the 90’s!

  3. I played through Zork as a young person on a Commodore 64, then a few years later in about 1992 I had the pleasure of meeting Patrick Volkerding at Moorhead State University who introduced me to Slackware. I don’t honestly remember if it was that distro or another, but not long after that I discovered a copy of Adventure on one of my Linux installs. I *may* even have it floating around somewhere yet.. I’ve got stacks of old hard drives.. and yes, floppies, though I suspect most of them are corrupt at this point.

  4. Back in ’83 I had Zork for my (dads) TRS-80, and I thought it was very cool. Then on a school excursion I got to play Zork on a mainframe, and I was absolutely staggered by the difference! The language parsing was superior in almost every way. I lost a lot of enthusiasim for playing TRS-80 Zork that day.
    Of late I’ve become interested in Zork again, but have only ever seen copies that run on ’80s era microcomputer emulators. Was the “Mainframe” version of Zork ever “ported” to the PC?

    1. > Was the “Mainframe” version of Zork ever “ported” to the PC?

      I’ve seen various attempts at porting it, though many seem to be based on earlier versions of the game and/or the Fortran version. And some are made using other adventure game creation languages, which probably means the parser and world model are subtly different from the original.

      Some of that can be found at https://ifdb.tads.org/viewgame?id=4gxk83ja4twckm6j

      Another attempt I saw was to implement enough of MDL to run the game from a patched version of the original source. Though what I saw of it seemed awkward to use, and had its own share of new bugs.

      That can be found at http://www.ifarchive.org/indexes/if-archive/programming/mdl/interpreters/confusion/

      Finally – and perhaps most promisingly? – there is another project at porting the original MDL source code to C++, making only minor changes along the way. I haven’t worked up enough courage to play it more than the very beginning, but the author has said that it should be playable to the end (with the caveat that things may have broken since the last time he tried it). I submitted a few minor bug reports, and he responded pretty quickly.

      That project can be found at https://bitbucket.org/jclaar3/zork/src/master/ and the Downloads section should have Windows, Mac and Linux versions.

  5. I remember playing this (Colossal Cave) on a Honeywell Level-66 mainframe in 1982. It was a purely text based version. I remember the first time I played I lost badly (!) and a colleague explained the need to draw a map of where you’d been, what you could see, and what was at each location. So, the next few times I played I got significantly further, but still died. But great fun all the same.
    After a few weeks of playing (and dying!) he showed me the map that he’d created, and I realised that I’d covered about 20% of the whole thing.
    I’m not sure about the original implementation of the game, but ours gave you a score at the end when you died. I seem to remember that ours was a score out of a maximum of 360 possible points. Sometime later, following an O/S upgrade, it changed to a max of 366 points, and we spent ages trying to find a new or hidden room.


    1. xyzzy.

      I was just a kid at the time, but 300 baud and my dad’s account on “centervax” got me into adventure (Colossal Cave) sometime back in the very late 70s or early 80s. I know that one of my dad’s postdocs had a purported map of the maze of twisty passages in his office. You could navigate by the slight changes in the way the description was phrased, IIRC.

      Fun times. I nearly laughed myself silly after “Surely you don’t plan to fight the dragon with your bare hands?”

    2. I had a huge map of colossal cave drawn in red pilot point on sheets of tractor feed paper taped together. I set out once to map the maze of twisty little passages all alike by dropping things (the pillow BEFORE the vase) in the rooms, but did not finish.

  6. Me and the high school computer nerds played zork on the mainframe pdp 1170 I think it was a multi user green screen terminal system , loads of fun in 1980…
    In the 90s the info shop Dos software was discounted and I snapped up 3 or 4 of these text based games like zork and got them rigged up with a dos batch file to pipe the user input and game output redirecting to the 1200 baud bbs that I was running. The o line caller could pick one of the games and play it . Even save and restore between calls…
    Programmers retreat bbs.

  7. Back in the mid 80s, in 6th grade Beginning Programming, which was taught on the Apple ][, we were encouraged to play Zork and then try to build our own text adventure.

    I started implementing a text adventure but by the time I was finished I had written an AD&D map editor instead. But the DM preferred graph paper, so I quickly moved on to writing character generators.

  8. Around 2000, I saw a BIG stack of grey boxes in the trash in a thrift store. I didn’t know what they were but asked if they were being thrown away. They were so I asked if I can have them. Cashier said I could so I took them home. The stack was about 5 foot tall of Infocom games. Most had all of the goodies and were in great condition for various platforms..

    I copied and sold the games. Made over $1000.

    The goodies were really great.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.