View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Amir Karger > Language-Zcode-0.8 > Language::Zcode



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.8   Source  


Language::Zcode - Play with Z-code and the Z-machine


Translate a Z-code file into Perl. The following (if piped to a file) will create an executable which will will execute just as if you ran zork1.z3 under a Z-code interpreter. Note: the executable will not be standalone; it will use Language::Zcode::Runtime::* modules. Creating a downloadable single-file executable is a TODO.

    use Language::Zcode::Parser; # parse Z-file
    use Language::Zcode::Translator; # language-specific output routines

    my $Zfile = "zork1.z3";
    my $Parser = new Language::Zcode::Parser "Perl";

    my $T = new Language::Zcode::Translator "Perl";
    print $T->program_start();
    for my $rtn ($Parser->find_subs($Zfile)) {
        print $T->routine_start($rtn->address, $rtn->locals); 
        print $T->translate_command($_) for $rtn->commands;
        print $T->routine_end();
    print $T->write_memory();
    print $T->program_end();

Create a Z-machine...

    Nothing here yet.

Parse a Quetzal save file.

    Nothing here yet.


Z-code is the machine language for the Z-machine, the virtual machine that the Infocom text adventure games (among others) run on. Language::Zcode provides tools to parse story files written in Z-code, and to translate ("compile") them to executables in other languages (such as Perl).

This module does not contain a Z-machine interpreter: you can't run a Z-machine file without translating it to some other language first. Pick up Michael Edmonson's Games::Rezrov if you want to play Zork, rather than translate it to Perl. (I stole almost all of Games::Rezrov to start this module.)


Language::Zcode should be able to handle almost any story file, except for fancy stuff like Unicode. Parsing will let you look at a story file's commands and strings, like the (ca. 1992) txd program. Looking at objects (like infodump does) is a bit harder, but doable using the API. Grammar/action tables are totally not supported.

Translating to Perl

The "compiled" Perl executables basically support early-to-mid-80's Infocom technology. That is:

This means (although I haven't tested exhaustively) that you should be able to play most Infocom games, if you're lucky enough to have the story files. Most modern (late Infocom, Inform) games won't work. I hope to have support for those in the next version.

Translating to PIR

PIR is also known as Parrot Intermediate Representation or IMCC. Language::Zcode is only doing this as a proof of concept. A few v3 opcodes are implemented, badly. See "HISTORY".

Translating to XML

Barely even a proof of concept. A static file, rather than an executable. But with some good XSL work (by someone who actually knows XSL), you could have a very pretty display of the game's commands and strings. Further XML TODOs left to the imagination.


(Only includes TODOs within the current set of supported commands.)

See Todo for far more information.



It all started with Dan Sugalski's suggestion that Parrot could run Z-code natively. He subtly hinted at this idea as early as 12/2001 ( and dedicated a whole slide to it in a 2002 RubyConf presentation.

Dan's idea was to make the Parrot VM think it's a Z-machine, running the Z-code opcodes instead of the regular Parrot ones. Or, as he put it, "parrot -b:zmachine zork.dat". Whoa! Why do it? Because it proves how powerful Parrot is. "Plus, it's really cool."

Given that I had no clue at all how to do this, I got some advice from the Parrot mailing list, and it was suggested that I:

  1. Write a program that translates ("compiles") Z-code to Perl.
  2. Compile Z-code to PIR, writing new Parrot opcodes for Z-machine opcodes. The PIR and C could just be translations of the Perl code from step 1.
  3. Convince Parrot to read Z-code directly, and then execute the Z Parrot opcodes that I'd written in step 2.
  4. ...
  5. Profit!

Language::Zcode v0.8 is step 1, and later versions will do part of step 2. Given how long it took to get this far, I'm not all that confident about step 5, but we'll see.

See Changes for version information.


Amir Karger <>


Copyright (c) 2004 Amir Karger. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


syntax highlighting: