Hacker News new | ask | show | jobs
by daniel5151 1943 days ago
One of the coolest technical aspects of early Infocom text adventure games is that most games weren't actually written using native assembly code for the platforms they ran on, and were instead compiled down to "z-code", a bytecode which ran on the "z-machine" virtual machine architecture. Z-machines are pretty niftly little bits of tech, as while they have a lot in common with regular 'ol machine code, the z-machine spec also includes dedicated instructions for fetching text input from the user, outputting text to the console, saving/loading data to disk, etc...

Having games target the abstract z-machine platform made it incredibly easy for Infocom to port games across platforms, as instead of re-writing every game from scratch, they could simply write a z-machine interpreter for said platform, and immediately gain access to their entire adventure game catalog!

A happy side-effect of all this is that it's super easy to run these classic adventure games on modern platforms, as instead of emulating the UI/UX of a 80s microcomputer, it's possible to write a z-machine interpreter that takes full advantage of modern GUIs.

One of my personal favorite modern z-machine interpreters is `encrusted` [1], which is written in Rust that runs on the Web thanks to WebAssembly. As a fun side-project, I ended up forking the project and making `embcrusted` [2], a z-machine interpreter that can run on embedded platforms without a full C-library. In a weekend or two of hacking, I was able to port a z-machine interpreter to my mechanical keyboard, in order to get the "authentic" experience of playing a text-adventure game through a teletype :)

[1] https://github.com/DeMille/encrusted

[2] https://github.com/daniel5151/embcrusted

3 comments

I was reading an article about the Z-Machine recently [1], and I was quite surprised that in addition to being a virtual machine, it also implemented virtual memory! Thus, pages could be swapped in and out of disk as needed. (Since CPUs like the 6502 didn't have a hardware MMU, I guess this was an explicit software step -- i.e. a called function that would check if the page was loaded, and if not, arrange for its load.)

With a virtual machine, virtual memory, and (for the time) a great natural language parser, it shows that the Infocom folks learned their craft in world of academia, high-end computer hardware, and ideas, instead of the more amateur (at the time) world of microcomputer enthusiasts.

[1] https://www.filfre.net/2012/01/zil-and-the-z-machine/

While cool in a way, it was also annoying that infocom games in the day took several seconds, then started the disk to load whatever the next response was.

The limited parsers of the competition responded almost instantly to input. The limited parsers were enough for everything needed, most everyone I knew just used the two word sentences even though more complex ones would work.

> then started the disk to load whatever the next response was.

In addition on some systems with smaller disks (eg. C64) needed the story file to be split up over two disks, because the story file and interpreter wouldn't both fit on one disk. So you were switching the floppy disk at various intervals as well. With the C1541 being no speed demon to begin with it was not fun. I remember being much happier playing it on CP/M and DOS machines later.

I used to play a lot of z-machine text adventures on the original iPod Touch with an app called Frotz. It was pretty cool to see stuff from the 80s running on a modern tiny portable computer like that.
Frotz is still around for iOS and it still works great!
In my youth I used to use BCD to handle large numbers and mathematics, so bit/byte representations have always been of interest. In that regard, I really appreciated the Infocom text compression.

Use your favourite seach engine to look up ZSCII which, roughly, is three characters per two bytes (five bits each) with special markers to switch between three different 'alphabets' for what characters the ZSCII bits represent.

Edit: Coincidentally there's a British quiz show called Only Connect, and a few days ago one of the contestants offered xyzzy as an answer to a question where they had to provide the fourth entry in a sequence. The host had never heard of it, and expected a different answer, but it fit and they got the points.