Category Archives: Gruepal

DrupalZM – Opening the Small Mailbox Reveals…

Even though it seems like I encounter a new set of issues at every step, things are progressing really nicely with the zmachine module. The lexical parser is done, it parses the input buffer and creates the parse table, looking up each word in the game dictionary. I had a few bugs with memory addressing and setting attributes of objects, but those are cleared up now.

I dont have any user interface to put commands into the input buffer yet, but I am able to set a “script” in the program so it will execute commands one by one, as can be seen below. This shows how much progress is done – as can be seen, it recognizes commands properly, but there are still a few bugs (notice how even though I take the leaflet and its in my inventory, its still in the mailbox as well – I’m not updating the objects 100% correctly yet). Also, if you try to move from the first room it crashes, which I think is actually related to the previously mentioned object issue. But anyway – here’s a nice transcript of how much is working so far!

ZORK I: The Great Underground Empire
Copyright (c) 1981, 1982, 1983 Infocom, Inc. All rights reserved.
ZORK is a registered trademark of Infocom, Inc.
Revision 88 / Serial number 840726

West of House
You are standing in an open field west of a white house, with a boarded front door.
There is a small mailbox here.

>open mailbox
Opening the small mailbox reveals a leaflet.

>take leaflet
Taken.

>read it
“WELCOME TO ZORK!

ZORK is a game of adventure, danger, and low cunning. In it you will explore some of the most amazing territory ever seen by mortals. No computer should be without one!”

>look
West of House
You are standing in an open field west of a white house, with a boarded front door.
There is a small mailbox here.
The small mailbox contains:
A leaflet

>i
You are carrying:
A leaflet

>jump
Are you enjoying yourself?

>jump
Wheeeeeeeeee!!!!!

>jump
Very good. Now you can go to the second grade.

>take me
How romantic!

>hello sailor
Nothing happens here.

>look at me
That’s difficult unless your eyes are prehensile.

>quit
Your score is 0 (total of 350 points), in 11 moves.
This gives you the rank of Beginner.
Do you wish to leave the game? (Y is affirmative): >
Ok.

Now to fix things up with the objects!

DrupalZM – West of House

I’m pretty excited about DrupalZM, things are going fairly smoothly. I fixed up a few major bugs with signed number calculations and the z-character -> zscii -> ascii converter. I also implemented more opcodes, as well as the output buffer that takes care of rendering text to the screen properly and in a controlled fashion. The machine now executes until it expects user input! Definitely exciting, as this means that the object table is being correctly manipulated and read (e.g. the west of house object, the cretin (the player), the mailbox, etc). Below is text from DrupalZM – the expected text for the starting room of Zork I!

ZORK I: The Great Underground Empire
Copyright (c) 1981, 1982, 1983 Infocom, Inc. All rights reserved.
ZORK is a registered trademark of Infocom, Inc.
Revision 88 / Serial number 840726

West of House
You are standing in an open field west of a white house, with a boarded front door.
There is a small mailbox here.

>

More soon!

DrupalZM – A Good Start!

So I had some free time this weekend and decided to work on DrupalZM a bit.

A Little About the Machine

The Z-machine is an interesting virtual machine. Unlike the average system architecture, the Z-machine has no registers in the typical sense, and keeps a separate stack from main memory. It can store local variables on its stack that can be used for the current call, and global variables in memory that can be used across calls. It has opcodes for the typical operations like math, boolean logic, calling, jumping, comparing, etc, but it also has text adventure specific opcodes, like an opcode for looking up game objects and their properties (e.g. is the mailbox open, whats the name of this room, is the light on or off, etc), opcodes for looking up dictionary and lexical data for parsing, and high level opcodes like print to the screen, save, restart, etc.

Additionally, the total size of an opcode and operands can vary in length (since there are no registers, the opcodes allow you to assign results to many different locations from the stack to memory), and sometimes can be followed by high level data like a string of characters. It’s an interesting quasi-mix of typical low level processor functionality and high level operations. It’s actually pretty cool, and a bit of a challenge (I think) to program.

For those who wish to see technical specification in its full glory, you can check it out here.

Progress So Far

So that being said, I’ve set out on the long road. So far, I’ve accomplished the following:

  1. Created a Drupal module that installs the custom content type “z-machine”, that allows z-machine nodes to be added (basically a description of the game and the file it points to). This will allow Drupal site admins to easily add new stories to their website.
  2. Memory, Stack, and PC storage per user per z-machine, which means that a user’s progress will be saved at all times in any game he/she is playing. Saving and Restoring will still be available if desired of course, but there will be no need to save when done playing.
  3. When a user goes to a z-machine page, code will execute that will either read the machine from the appropriate file, or use the user’s memory if its available (i.e. they’ve played before).
  4. All opcode types except extended opcodes are processed and directed, in all forms. So this includes 0OP, 1OP, 2OPs, and VARs, in their Long, Short, and variable forms
  5. Storage and branching is fully supported for all opcodes. Return values will be stored in their correct location (Stack, local variables, global variables), and instructions that require a branch will do so to the correct address, both in their positive and negative forms (if true/if false).
  6. The stack is fully implemented, both in normal pushes and pops, as well as storing call information such as next PC, local variables, and return variable. Upon a return call, the z-machine will correctly clean the stack up and set the PC correctly
  7. About 20 opcodes (which means 40-60 or so with their different forms) have been implemented so far
  8. A full zcharacter <-> zscii <-> asciii conversion system has been implemented with abbreviation table lookup
  9. Basic object and property handling has been implemented
  10. For what’s been done so far, it fully supports versions 1-3 and some support 4-5, and little support for 6-8.
  11. I’ve made quite a bit of progress, but there is still a tonnn to go. But it’s a lot of fun. The machine can execute about 150 instructions before dying from an unknown opcode. But, in those 150 instructions, I’m already seeing text on the webbrowser! Here’s a small excerpt:

    Instruction:178 print: ZORK I: The Great Underground Empire
    Copyright (c) 1981, 1982, 1983 Infocom, Inc.
    Instruction:178 print: All rights reserved.
    Instruction:187 print:

    Instruction:16
    loadbstack push
    Instruction:73
    andstack push
    Instruction:160
    Instruction:178 print: ZORK is a registered trademark of Infocom, Inc.

    Pretty exciting! More to come…

DrupalZM – My New Project

For those eager to purchase a PSX64, don’t worry, I’m still planning on selling a batch at the upcoming World of Commodore Expo and then selling online. The following project is slow moving right now – Shredz64 is still my priority.

The Project Idea
That being said, I’ve been itching for a new project to work on. I have a few Commodore related hardware ideas, but I’m putting them off until most of the PSX64 sales are done with. I wanted another fun software project to work on in the meantime. I’m a huge fan of text adventures, both the Infocom classics (The Zork series, HGTTG, Lurking Horror, etc) and the great interactive fiction that’s still being written by the IF community (if you’re an IF fan and haven’t yet, check out the Interactive Fiction Archive, there are thousands of awesome stories on there to play, many are really amazing).

I’m also a Drupal developer as a part of my day job – we often get into conversations at work about cool vintage technologies we miss, and text adventures are one of the topics that comes up often. During one such conversation, a coworker (Hi Seth!) and I got onto the subject of how it would be great if there was a Drupal Z-machine module that allowed Drupal sites to offer text adventures for users to play online (no need for downloads). And I thought, now THAT would be a fun project. I had always wanted to write a virtual machine/emulator, and being a fan of the text adventure genre, this was perfect.

Now of course there are java, a whole slew of local, and mobile Z-machines out there (and maybe even other PHP implementations), but this is more of a fun academic exercise for myself – a big learning opportunity – the Z-machine has a hefty list of opcodes and nuances. I normally wouldn’t post this early into a project in case I lost interest or my time grew short, but I feel confident about this one, and I really want to let people follow along if they’re interested.

I’m going to post what I learn about the Z-machine from the tech specs on the web as I go, coupled with the work I do to implement that in PHP/Drupal. So far I’ve done some work reading the data file from disk, parsing information from it, and parsing op codes and operands, but I will save these details for the next (series) of posts.

Wish me luck!