Logo Computer scientist,
engineer, and educator
• Software
• The KBOX project

Zork on Android using KBOX and Frotz (etc)

Anchorhead Interactive fiction (IF) contines to hold the attention of a small but loyal group of followers. I suspect that many of this group, myself included, grew up telling Advent to rub the electric lamp in the 1970s. The Zork range of games produced by Infocom was probably the first commercial success in this area, and these games are still regularly played by enthuiasts; there is, at the same time, a movement to promote interactive fiction as a literary endeavour, rather than purely a form of gaming.

What both the literary and the gaming varieties of interactive fiction have in common is that they continue to be largely based on forms of virtual machine architecture popularised in the 1980s, and designed for text-in, text-out interaction — they are essentially terminal-based. The Z-machine ('Z-code') platform is probably still the most popular of the various IF technologies, despite its technical limitations. All the original Infcom games used this format, and many modern offerings do also. Glulx is a more modern virtual machine format, conceptually similar to Z-machine, with fewer of its more glaring limitations. TADS is an alternative to Glulx and Z-machine with a rather different architecture. All three of these environments have in common that, although they offer some support for graphics, sound, and more modern forms of user interface, they can be made to work in a text-only environment.

IF has generated relatively little interest among users of mobile devices. There are (at least) two reasons for this. First, mobile handsets generally don't have real keyboards, and all mainstream IF games rely heavily on keyboard input. This isn't a problem that is likely to be solved by improving the way that existing IF games work on mobile devices. There are a few brave attempts to adapt the IF idiom to the finger-prodding interface of mobile devices, but most of the impressive IF games — the ones that people actually want to play — are are not readily adaptable to such an interface. This situation may change if there is sufficient interest in doing IF on mobile devices; in the meantime, we are stuck with doing the best we can with the existing, terminal-based games and the programs that support them. If we have to use keyboard input, then the program should, as a minimum, offer proper line editing and support external keyboards. The fact that most Android devices do not provide virtual keyboards with enough keys (cursor, delete, backspace) to edit properly is no excuse not to provide the facility in the application — 3rd-party virtual keyboards (and, of course, real keyboards) are available to remedy this lack.

This brings us to the second problem: the lack of good, stable implementations of IF virtual machines for Android and similar platforms, with decent font and keyboard support. This is the case even for Z-machine, which is well-documented, and of which implementations exist for just about every other platform and programming language. Typically Z-machine is the first IF architecture to be ported to a new platform, simply because it is so well understood.

For Android, the best-known (only?) implementations of a Z-machine platform for IF are JFrotz, ZMPP, and Twisty. None of these (so far as I can tell) offer reliable line editing or line history, even with an external keyboard, or a virtual keyboard that offers editing keys. None correctly handled games that needed sophisticated screen management, such as Beyond Zork, with its popup menus and ASCII-art maps (and I'm using the word 'sophisticated' in 1970s terms here, not pipelined texture mapping and suchlike). Of the three, only JFrotz allowed any choice of display fonts, but it's very slow, even on a fast device.

Twisty is relatively stable but has few configuration choices, and some games rendered incorrectly. ZMPP looks very nice — it was the only app I could find that supported proper variable-pitch text rendering — but (so far as I can see) it provides no way to get access to game files other than those from the IF Archive (in-program access to the IF archive is a nice feature, but this rules out the Infocom games, which are not really in the public domain). ZMPP also shows advertisements although, to be fair, they are unobtrusive.

I couldn't find any reasonably stable Android implementations of a Glulx or TADS environment. There's been some preliminary work, and it's possible that you might be able to get the JavaScript version of Glulx to work in your mobile Web browser, but none of this is very encouraging. It's possible that the approach I describe here is currently the only way to play TADS or Glulx games on Android.

An alternative approach to IF on Android, using a proper terminal emualtor

One of the main features of IF games is that they are (nearly always) designed to be able run in a terminal. This makes it very easy to port the IF interpreters to different platforms, so long as there is a terminal, or terminal emulator, available. Android does not supply a terminal emulator, or any of the usual tools that a terminal-based environment would supply. This means that anybody who wants to implement a Z-machine (or whatever) for Android has first of all to implement a terminal. Doing this properly is difficult which, I guess, is why most Android IF apps offer such limited choices of font, background colour, etc., and why line editing is such a chore (because it requires a terminal with proper cursor control).

But there are 3rd-party terminal emulators for Android, which do all this stuff properly. Jack Palevitch's Android Terminal, for example, is robust and highly customizable, and is free and open source. So why not use an existing terminal as the basis for playing IF games on Android? Terminal emulators are designed for running applications that run in a console; typically such applications are for system administration, but a console will host an interpreter for Z-Machine (or whatever) easily enough.

THe KBOX project

My KBOX project is an attempt to merge Jack Palevich's terminal app with just enough Linux infrastructure to make it relatively straightforward to port existing Linux/Unix console applications to run on Android. It does this without rooting or any of the other nasty stuff that people often employ to make their Android systems more Linux-like. Among the various things that KBOX provides are the the libraries needed to do the extensive screen and keyboard control that a decent IF interpreter implementation will need. In addition, KBOX includes a package manager, and packages are available for Frotz (for Z-machine games), glulxe (for Glulx games), and frobtads (for TADS2/TADS3 games). Frotz is essentially the reference implementation of a Z-machine — given the limitations of a pure terminal environment it provides the most complete implementation of the Z-machine specification. It does not support graphics or sound, but none of the other Android Z-machine implementations do either. Best of all, because Frotz is implemented in highly optimized, compiled C code, not Dalvik Java, it's very fast. glulxe is the equivalent for Glulx games; again, it's lightweight and very fast. frobtads is an interpreter for console-mode TADS games; it's slightly less useful that Frotz and glulxe because many more TADS games include graphics than Z-machine or Glulx games do. Nevertheless, at least some TADS games play reasonably well.

So if you're desperately keen to play Beyond Zork, Ecdysis, or King of Shreds and Patches on your Android handset, and none of the available Android apps cut the mustard, then running a console-mode interpreter under KBOX may be a viable approach. It requires a bit of setting up in the first instance, and familiarity with the Linux command-line is certainly helpful; but my guess is that anybody who wants to play IF games is unlikely to be put off by a bit of typing.

How to install KBOX terminal, and various IF interpreters

The setup procedure is a bit fiddly, but only has to be done once.
  • Download and install the KBOX terminal, using the instructions here. Essentially, download the Android app and install it using any Android file manager (you might have to enable support for off-Market apps in the Settings app to be able to install KBOX; KBOX will never be available on the Android Market).
  • Download the appropriate interpreter package(s) for the games you want to play, using the Web browser on your Android device. Alternatively, download them some other way and get them onto your device (perhaps using USB). I'm assuming that you've downloaded using a browser, and the files are in the Download directory on your device — adjust the instructions that follow if you've done something else.

    Available interpreters at preset are as follows:

  • If you aren't going to be using a hardware keyboard, I would recommend installing a fully-featured virtual keyboard like Klaus Weidner's Hacker's Keyboard. This will provide the line editing keys that most Android keyboards lack. As well as making Frotz work better, a virtual keyboard with editing keys will make it easier to enter the installation commands below.
  • Start the KBOX terminal using the Android launcher. You'll get a command prompt (all being well). The first start-up might take some time, because there is some intialization to do.
  • Install the interpreter package(s) using the command prompt, like this:
    $ dpkg -i /sdcard/Download/frotz_2.4.3_kbox.deb
    $ dpkg -i /sdcard/Download/glulxe_0.5.1_kbox.deb
    $ dpkg -i /sdcard/Download/frobtads_1.2.2_kbox.deb
    
    If you have an external SD card, your Download directory might be in a different place. Try, perhaps:
    $ dpkg -i /storage/extSdCcard/Download/frotz_2.4.3_kbox.deb
    
    This is where downloads from the Web browser go on my Samsung Galaxy Tab 2. I appreciate that this step might be a bit fiddly for people who are not used to working at the Linux command prompt.

    Repeat for the glulxe package, if necessary.
  • Test Frotz by typing frotz at the prompt. It won't run anything, but you should see a usage message. Same for glulxe and frobtads
That's it.

Running Frotz, etc

To use Frotz, glulxe, or frobtads, you'll need to copy some game files onto your device; again, you can do this by downloading them using the browser, or copying over USB. I'm assuming that the game files are in the Download directory although, of course, you can use any directory you like, so long as you can find it at the command prompt on the device. To run a game:
$ cd /sdcard/Download
$ frotz somefile.z5 
or
$ glulxe somefile.gblorb
or
$ frob somefile.gam
Frotz generally can't work out how wide the terminal is (in terms of characters), so if you're working on a small screen, or with a large font, you'll need to help it out. Do this by specifying the width in the frotz command like this:
$ frotz -w 65 somefile.z5 
The screenshot at the top of this article is from a Galaxy Tab 2 in portrait mode, with 16-point font and 65 character width. The keyboard is Klaus Weidner's Hacker's Keboard, set to 5-row mode, so that you get the arrow keys for editing lines and cycling through the line history.

You might need to experiment with this width if you change the font size. Frotz will work with both landscape and portrait orientation, but it will get confused if you change from one to another in the middle of a game.

WIth all the interpreters, if you save a game, then by default the save file will be written into the current directory (which was /sdcard/Download in the example above). Be aware that the same default filename is used by a number of different games, so you should probably change it if you have more than one game in progress at a time.

Be aware that neither Frotz nor glulxe respond very well to having their screen size changed at runtime. This will happen if you change the font, but it can also happen if you rotate the screen, or even allow the virtual keyboard to pop up and down. It's certainly better to keep the virtual keyboard up all the time. Of course, it's even better to use an external keyboard, but that isn't always practicable.

In general, frobtads seems to work the least well of the three interpreters available — this, I think, is because many games embed images in the text, and the inability to display these images in a console interferes with the screen layout.

Future directions

I'm aware that the approach I've outlined to playing IF on Android is likely to be of interest primarily to people who have familiarity with working at the Linux command prompt. Once an interpreter is running things are straightforward enough, but getting it to run means fiddling about with files and directories, which isn't everybody's idea of fun. I'm guessing that people with an interest in IF are going to be willing to tolerate a bit of typing but, at the same time, I expect that many of these people will not be familiar with working at a Linux command prompt.

It would be possible to produce a version of KBOX that has Frotz and other IF interpreters built in, so users wouldn't need to install them at the prompt. It would also be possible to provide some facility to search the Android media storage locations for compatible game files, so you wouldn't have to type the filename at a prompt In the longer term, it would even be possible to provide a Frotz-specific user interface to the terminal, so that all the file selection stuff was done with common Android dialogs.

Whether it's worthwhile to do any of this, I'm not sure. In the end, the main limitation to the success of IF on Android is that Android devices don't usually have keyboards, and that isn't something that can easily be fixed in software.

Comments welcome, as always.

Copyright © 1994-2015 Kevin Boone. Updated Apr 18 2013