| The Hobbit (v1.0) | HowItWorks |
This is a complete annotated disassembly of the main code block of the original 1982 release (v1.0) of The Hobbit by Veronika Megler and Philip Mitchell, published by Melbourne House. The block is 37,888 bytes long, loads at 24576 (6000) and is started by RANDOMIZE USR 27648. Reassembling the disassembly with SkoolKit gives back the original block byte for byte.
The code and data were identified by running the game in a Z80 emulator, by tracing every table and pointer, and by hand. Many descriptions were confirmed by playing the relevant scene in the emulator; the Trivia page lists what was checked this way. Everything else is a careful reading of the code.
Besides the routine and data pages, see: the map of Wilderland, the location pictures, the characters, the objects, trivia and bugs.
| Address | Contents |
|---|---|
| $6000 | Dictionary letter index, main dictionary (the words the player can type, with their classes and synonyms) and message dictionary |
| $6C00 | Start-up, main loop, keyboard and line input, tokeniser, message interpreter, text output, 6-pixel font (7815) |
| $7C4F | Parser, game commands (HELP, SCORE, SAVE, LOAD, PRINT...), command execution |
| $8965 | Picture drawing |
| $8C2D | Action handlers: LOOK, TAKE, DROP, movement, fights, eating, doors and containers... |
| $9611 | End of turn: timers and the independent characters; object and room utilities |
| $A174 | Special handlers for particular objects, characters, rooms and timers |
| $AA47 | The action table (the 59 things that can be done) |
| $AC31 | Message abbreviations and the messages |
| $B5CB | Game variables, verb endings, orders buffer and command frames |
| $B8D0 | Room pointers and room records |
| $BF53 | Object index and object records (everything, including Bilbo and the characters) |
| $C61F | Default action handlers, room-entry handlers, riddles, hidden routes, behaviour programs, timers, character table |
| $CC00 | Location pictures |
The main loop (6D0A) reads a line of typing (6DCD). If the player does nothing for about 20 seconds the game types WAIT itself (7240), so the world goes on without him. The tokeniser (6E8E) looks each word up in the dictionary, allowing abbreviations and replacing synonyms (HIT, KILL and CAPTURE all become ATTACK). The parser (7C4F) builds command frames: a verb, a particle and two noun phrases each, several per line, with AND, THEN, ALL, EXCEPT, IT and quoted orders to other characters.
Each frame is matched against the action table (858F) and the objects that fit its words are tried one by one in silent 'dry runs' until one works (8405); if that is ambiguous the game asks 'which key?' and lets the reply finish the command. The action is then performed (946F) by the object's own handler if it has one, or by a default handler, and reported ('you open the door.', 'thorin attacks you.'). Then the turn ends (9611): every other character acts (976C) and the ten timers tick (C973).
Everything that exists is an object with a 16-byte header (C00B): Bilbo is object 0, and characters, doors, rivers and swords all share the same format - size, weight, strength, defence, side, flags, four words, locations, and a list of its own action handlers. Being inside, on, tied to or carried by something is just a matter of whose number is in the 'held by' byte. The 79 rooms (B97A) have a name, an optional description, a preposition, light, and exits that may pass through doors (see the map). All of it - objects, rooms, variables, timers, characters - is copied aside at start-up and copied back to restart the game, and exactly those areas are what SAVE writes to tape.
Each character runs a little program of its own (C71C): do an action, move, call a special routine, jump, react to what is done to it. They use the same action routines as the player, which is why the game can say 'gandalf opens the round green door' or 'thorin sits down and starts singing about gold' with the same code that handles Bilbo. They can be given orders with SAY TO, which they may refuse (8F9E). Some are asleep until Bilbo gets near: the butler, Bard and the dragon (C693, C6AF).
Messages are programs (72D4): dictionary words, one-byte abbreviations for common words, and control codes for 'the actor', 'his or your', 'is or are', jumps and sub-messages. Verbs get their endings automatically when the subject is not 'you' (74B8), articles come from flags in each word reference (7436), and capital letters are added only by the printer (7694), which also wraps words and slows down long bursts of text. The story window uses a 6-pixel font (77BC), and the input window the ROM font.
The 22 location pictures (CC00) are drawn at run time from a tiny vector language - moves, lines with fixed slopes, flood fills and blocks of colour - by 8985. Two of them borrow the drawing of another picture by running on into it.
The random number generator (9BFD) takes its seed from the R register when the first key is pressed and then reads bytes of the program itself; its way of folding numbers into a range skews them towards the high end. Chance decides fights, which route is closed and which riddle Gollum asks, whether characters obey, and much of what they do.