Adventure Programming the Psion Organiser II.
by Jim Mahaffey.
ADVENTURE or COLOSSAL CAVE is the granddaddy of all "interactive fiction" computer games, in which the player can move in an imaginary world, interacting with objects, communicating with other entities, and generally getting in trouble at every turn. From this first whimsical program hundreds of clones, copies, and improvements have been developed, from the ZORK trilogy to the very advanced Myst games. Perhaps none of these knock-offs has quite the majestic charm of this first attempt.
The adventure concept was the original work of Willie Crowther, at MIT. Most of the tricks and features were added by Don Woods at the Stanford AI Lab. The program was originally written in FORTRAN IV, for a PDP-10. Bob Supnik made an RT-11 version for the PDP-11, and that was about as small a machine as would run ADVENTURE. It was quite a huge program, for the time, and would run only on expensive mainframes, under time-sharing. I think I first saw it in 1974.
Then Dick Murphy broke the large-machine barrier by fitting it on a PDP-8, the first semi-practical personal computer. Admittedly it had to run on a maximum PDP-8 (32K words), with lots of disk space for virtual memory swapping, but at least the users were not tied down by their computer account numbers, and people actually began to find the end of the cave. Murphy managed to cram the thing into the small machine, with no loss of function, by hand-optimising the assembly-code produced by the FORTRAN IV compiler.
Following in Murphy's footsteps, I have miniaturised the program severely, so that it will fit on a micro-machine - essentially a Psion Organiser II CM. I have retained all of Crowther's beautiful imagery of descriptions, with the exception of his long-winded depiction of the active volcano. All of the treasures, traps, and tricks are retained. (Some of the tricks are so obscure you can only figure them out by reading the program!) You will waste many hours crawling through this cave.
If you are bothered by the all-caps prose in ADVENTURE, bear in mind that this thing was originally written in the era of Western Electric Teletypes, 6-bit ASCII, and the almighty FORTRAN. I have thus retained the flavour of old-time computing, and the soft glow of a time when a computer that could run ADVENTURE weighed several tons.
Of course I couldn't retain everything. The original program will give a long-winded description of a location when first you see it, then short descriptions if you go there again. Your ORGII version will always give the long version. There is no pirate to steal your treasure and hide it in the maze. (I always hated the pirate.) There is no vending machine full of batteries in the maze. When your lantern starts to fade the program will nag you about it, but it is not a fatal condition. The maze is simplified. Some of the appropriate responses to commands, particularly inoperable ones, are not available. For example, if you say "abracadabra" the computer will simply not know what you're talking about, instead of saying "Good try, but that is an old worn-out magic word." In the original program you can't get the bird while you're holding the rod (trust me, it's important). In this version the rod can't even be in the room with you. Remember, the true object of this game is to discover the rules.
Scoring is simplified, but it is still weighted according to difficulty. A perfect score is 100, meaning that you have found all the treasures and hauled them back to the well-house. The score program is loaded and run only if you say QUIT. You can always change your mind about quitting, and you still get a score. As was the case with the PDP-8 version, there is no way to store a game in mid-cave and come back to it, but if you simply stop playing, your Organiser will turn itself off and you can resume play later.
This ORGII version of adventure was inspired by Trevor Toms' work with a minimal Z80-based machine, the Sinclair ZX 81, introduced in 1981. Trevor built a simplified adventure engine that would run in 16K bytes in the ZX 81, which is possibly the simplest general-purpose computer ever sold. The language was ZX BASIC. This dialect of BASIC was an efficient interpreter, designed specifically to take maximum advantage of the small memory reach of the ZX machine using aggressive context-switch tactics. The meaning of a keystroke was completely dependent on its place in a program statement. The letter S, for example, could mean ARCCOS, SAVE, LPRINT, or just S, depending on its perceived use. So a lot of complex programming could be crammed into a small space in a small machine, and an artificial-intelligence demo as complex as ADVENTURE was possible in a machine even smaller than the PDP-8. Of course the classic ADVENTURE was impossible - there was simply not enough storage for the place descriptions, the 100 rooms, and all the treasures- but Toms built an alternative adventure scenario, called "The City of Alzan."
A further challenge was not only to fit an adventure engine and a game data-base into an ORGII, but to fit it into a CM. A CM has only about 6K bytes of usable memory! An immediate problem is the storage of variable arrays. The FORTRAN version and all later BASIC versions of ADVENTURE access rooms in the caves by indexing into 2-dimensional data arrays. Such indexing was not possible in my little CM, because global variable arrays must live in primary memory throughout program execution. A data array describing 15 rooms would entirely occupy my 6K.
But the ORGII has a powerful semi-BASIC language, and many tricks are possible. A useful feature is the fact that subprograms can be accessed as virtual memory modules- a subprogram and its local variables is swapped into primary only when called, and is swapped out after it runs. You can therefore have a program of size limited only by two factors: the size of your global arrays and the size of your secondary or "disc" storage. I eliminated the huge, global room array by converting it to a series of 8 subprograms, each dumbly running through a series of ELSEIF commands to find the room description and movement vector appropriate to a variable, ROOM%. Command, phrase, and object "arrays" are similarly chopped into small self-running subprograms without using addressable variables.
Using such designs I could have added complexity, phrasing, and descriptions until I ran out of space on device B and C, but speed started to be a problem. The ADVENTURE you will run on your ORGII is thus a product delicately balanced between rich complexity and usable speed. Enjoy it. Examine it. Let me know of problems or questions, and please consider building your own ADVENTURE scenario. I will be glad to supply technical details upon request.
Download the full Adventure program for the Psion Organiser II CM, XP or LZ.
Or: "City of Alzan" which is an amusing small adventure which Jim wrote as a test and warm-up for the full-blown 'Adventure'.
City of Alzan.zip