Entering the forest road (room 2) or the forest (room 3) runs the room-entry handler C6CC, which starts timer 8 (C973) at 4 and remembers the room.
At the end of each turn the count goes down by one. While it is 3, 2 or 1 the tick routine AA13 prints 'you see some pale bulbous eyes staring at you' and checks that Bilbo is still in the room he entered; if he has left (other than to the other forest room) something drops from above and stings him to death. When it reaches 0 the expire routine AA2E kills Bilbo if he is still in room 2 or 3, and does nothing if he has gone.
So on entering, the count drops to 3 at the end of that turn; two WAITs take it to 2 and then 1; and moving on the third turn takes it to 0 with Bilbo already gone. Any command that uses a turn counts as a wait. Walking back and forth between rooms 2 and 3 simply restarts the timer.
How a fight is decided
The attack value is the attacker's strength (object byte 5) plus the weapon's strength, capped at 255; the defence is the target's byte 6. Both are randomised by 917D. If the defence is at least the attack, the blow is wasted; if the attack wins by more than 16, the target is killed; otherwise it is wounded, with a message chosen by the margin (9190) and some loss of strength and defence. See 90DB for the details.
With the original sword (strength 64) Bilbo attacks at 128 against Thorin's defence of 120, so most blows wound him. Bare-handed Bilbo attacks at 64 and almost never gets through, except when the bug in 917D reduces Thorin's defence to 0. Thorin's own attack (104) against Bilbo's defence (64) is nearly always fatal.
Independent characters
The characters in the table at C9BA act on their own every turn (976C), using the very same routines as the player, which is why messages read 'thorin attacks you' or 'gandalf opens the round green door'. Their behaviour involves random choices, so every game is different - and Thorin's habit of sitting down and singing about gold comes from this system.
Drinking the wine makes the game slur its words
Drinking the wine in the Elvenking's cellar runs a routine attached to the wine's object record (A9ED), which sets the flag at $B5F1 and starts timer 7. While the flag is set, the character printer (7580) follows every S with an H, so everything the game says comes out slurred: 'you drink shome wine. gandalf goesh easht. thorin shitsh down and shtartsh shinging about gold.' Five turns later timer 7 expires (A9FF) and Bilbo sobers up.
Articles are stored in the word references
Nouns do not have fixed articles in the dictionary. Instead, the flag bits of each word reference say whether the word takes 'a', 'an', 'some' or 'the' (7436), and names such as Thorin have a flag that suppresses the article and capitalises them. The same noun can therefore be 'a key' in one place and 'the key' in another.
There are no capital letters in the game's text
Every word is stored in the dictionary in five-bit form, without case. Capitals are added only by the printer (7694): the first letter after a full stop or a new line, and the first letter of a name.
The game plays on if you do not type
If the player does not type anything for 20-25 seconds, 7240 types WAIT on their behalf and the other characters carry on with their business. This is one of the things that made The Hobbit feel alive in 1982, and one reason players were so often killed while thinking.
@ repeats the last command
Pressing SYMBOL SHIFT + 2 (@) as the first key of a line repeats the previous command without retyping it (6E71): the parser simply works through the old tokens again.
The game modifies its own code
In several places The Hobbit rewrites its own instructions to save space. 8869 pokes either a JR NZ or a JR Z opcode into two jumps before executing them; 9E71 and 9E76 change the offset in an LD A,(IX+n) instruction to search the exits of a room either by the door they pass through or by their destination; and 93CD and 93ED poke a SET or RES instruction so that LOCK and UNLOCK can share code.
Eating makes Bilbo stronger - up to a point
Each time Bilbo eats, his strength (the value used in fights, 90DB) goes up by 10 (9206). Starting at 64, a few meals make him noticeably more dangerous. But the game will not let strength reach 128: the meal that would take it there kills him instead, with the message 'your foul gluttony has killed you'.
The sword glows in the dark
The darkness check (954D) looks at one object only: the short strong sword. If Bilbo has it and it is 'on' and not broken, dark places are lit. In the emulator, walking east from room 41 into the smooth straight passage gives 'it is dark.' without the sword and a full description with it. In the book, Bilbo's sword Sting glows blue when orcs are near.
One route is closed at random in every game
At the start of each game (970B) one of five exits is removed at random. The way through only opens when Elrond reads the curious map (A6B8), which is also when he tells you where to go: 'go north from beorns house to get to the great river', for example. This is why the map matters, and why the route through Wilderland changes from game to game.
Who catches you decides where you wake up
When a character captures Bilbo (A316), he is taken to a dungeon. The wood elf and the butler take him to room 31 in the Elvenking's halls; anyone else (the goblins) take him to room 13 in the goblins' dungeon.
Dead goblins do not stay dead
The six goblins share a handler (A36A) that brings a dead goblin back to life somewhere else with a new adjective, after it 'falls down a hole and vanishes'. The game's supply of goblins is effectively endless.
Why Thorin sits down and sings about gold
Thorin's famous habit comes from A550: each time his behaviour program runs this routine there is a 1 in 9 chance (a random number of exactly 0) that he 'sits down and starts singing about gold'. The rest of the time he waits, says 'hurry up', or does nothing.
Gollum's riddles
Gollum asks one of two riddles, chosen at the start of the game (970B). One is the 'dark' riddle from the book ('it cannot be seen, cannot be felt, cannot be heard, cannot be smelt...'), for which the game wants the answer NIGHT. The other is not from The Hobbit at all: it is the riddle of the Sphinx ('which is the animal that has four feet in the morning, two at midday and three in the evening?'), answer MAN. Each is stored twice in a four-entry table (C6EB), so they are equally likely. A wrong answer, or none, gets 'someone strangles you from behind.'
The trolls' picture changes at dawn
The picture of the trolls' clearing is drawn at night, in black, until the trolls are turned to stone (A865). Then its first two bytes - the border and background colours - are changed to cyan, and from then on the same line drawing appears in daylight. The start-up code resets them to black for every new game.
How to win
The game is won (A8CA) when the valuable treasure is in the wooden chest - that is, when Bilbo brings the dragon's treasure home and puts it away. Nothing else is required; the check is made at the end of every turn.
Stealing the treasure while the dragon lives
Once the treasure has left the dragon's lair, the dragon's program (A5D5) runs every turn, with roughly a 1 in 6 chance each turn of 'the dragon descends and in a terrific spout of flames burns you to a crisp'. The HELP message in room 41 says it all: 'a living dragon is deadly, look to bard'. Bard, who repeats the last order he was given every turn (A79F), is the answer.
Thorin's key dies with him
The small curious key belonged to Thrain, Thorin's father ('this was thrains key', says Thorin when he finds it). If Thorin is killed, a handler attached to him (A631) makes the key shatter - so killing Thorin can make the game impossible to finish.
Two pictures borrow other pictures
The goblins' dungeon (room 13) and the trolls' clearing (room 5) have tiny pictures of their own - 29 and 93 bytes - which end not with an end marker but with a 'move' command. The two bytes it reads as coordinates are really the colour bytes at the start of the next picture in memory, and drawing simply carries on through that picture: the dungeon borrows the Elvenking's dungeon (room 31), and the trolls' clearing borrows room 28. The borrowed drawing comes out in the borrower's colours, so the two pairs do not look like the same picture at first glance.
The pictures are line drawings with fills
Every location picture is drawn at run time from a list of commands (8985): lines with fixed slopes, moves, flood fills and blocks of colour. The 22 pictures contain over 3,000 line segments and take up about 10K; as bitmaps they would have needed about 60K, more than the whole Spectrum. Drawing them takes long enough to watch, which is why the game waits for a key afterwards.
Most of the score comes from sightseeing
Three quarters of the score is simply for visiting places: the first time Bilbo enters one of fourteen rooms, its points are added (8CEA), from 2.5% for the lonelands to 20% for the lower halls of the Lonely Mountain. Being thrown into the goblins' dungeon is worth 7.5%.
Moving in the dark is dangerous
In a dark place Bilbo cannot choose his way: any movement command sends him in a random direction (8D19). If there is no exit that way, he falls and hits his head, which halves his strength; do it often enough and 'you fall and smash your skull'. With the glowing sword (954D) none of this happens.
The random numbers come from the program itself
The Hobbit has no random number table. The routine at 9BFD walks a counter through memory and mixes the bytes it finds - program code, messages, the ROM - with the previous result. Only the starting point is really random: it is taken from the Z80's R register at the moment the player presses the first key.
How "you attack" becomes "thorin attacks"
The dictionary stores each verb once, but three bits in each verb say which ending it takes in the third person: S, ES, IES, D, ING, or IES after rubbing out the last letter (74B8, B60F). The message printer adds the ending whenever the subject is not 'you', so a single message serves both 'you attack thorin' and 'thorin attacks you', and 'you carry' and 'gandalf carries'.
Seeing only half of what happens
When a character opens or closes a door from the far side, Bilbo can see the door but not the character. The game handles this (9921) by reporting the action with the actor replaced by 'someone': 'someone opens the round green door.'
The ring makes Bilbo a real burglar
Normally, trying to take something a character is holding gets 'gandalf is carrying the curious map.' But the check (9686) only applies while Bilbo is visible. With the ring on he is not, and he can simply take things out of other characters' hands. In the emulator, with the sword given to Gandalf, 'take sword' is refused normally, but with Bilbo invisible gives 'you take the short strong sword.' - and Thorin asks 'where's the thief?'.
Some characters sleep until you get near
The butler, the dragon and Bard are not active at the start of the game: their slots in the character table (C9BA) are empty. The butler is switched on when Bilbo first enters Beorn's house (C693); the dragon and Bard when he enters the Elvenking's cellar (C6AF). Until then they simply lie where they are, which is why the dragon never comes looking for Bilbo early in the game.
The forest river kills anyone not in a barrel
Room 33, the forest river below the Elvenking's trap door, has an entry handler (C6D9) that kills Bilbo - 'you are swept forcefully against the portcullis' - unless he arrives inside the barrel.
The side door only appears one turn in five
Once Bilbo has been in the Elvenking's cellar, timer 9 makes the side door of the Lonely Mountain appear with 'a loud crack' for one turn (A985) and then vanish again (A968), every five turns, unless it has been opened in the meantime. Closing it again hides it and restarts the cycle (A996). The HELP message there is simply 'wait a while.'
The ring has a price
Wearing the golden ring (A2C0) makes Bilbo invisible, but it also divides his strength by 4 - not the moment to pick a fight. It comes off by itself after a random 2 to 10 turns (timer 6, A9D4), and taking it off multiplies his strength by 4 again (A2EC). Because the division throws away the remainder, each use can cost him up to 3 points of strength for good.
Only Bard can kill the dragon
SHOOT (8FE0) treats Bard specially: his arrows never miss, while anyone else's always miss the dragon. A hit kills any living thing outright. So Bilbo must bring Bard (who wakes up when Bilbo reaches the Elvenking's cellar, C6AF) the bow and arrow and tell him to shoot the dragon; Bard then keeps obeying that order every turn (A79F).
The enchanted river
Swimming in the fast black river (A240) or drinking its black water (A258) makes the drinker fall asleep and die, as in the book, where Bombur falls into the enchanted stream in Mirkwood and sleeps for days. Ordinary water is harmless (A174).
A window needs friends
The goblins' dungeon has a window that Bilbo cannot reach on his own (A678). He has to be carried - by giving orders to a character strong enough to carry him - which is what the HELP message there means: 'a window should be no obstacle to a thief with friends'.
Crossing the enchanted river
The wooden boat on the enchanted river is reached with the rope (A708): throw it across, and if the boat is already moored on the far bank there is a 1-in-4 chance it lands cleanly in the boat, tying the two together; otherwise the throw falls short or slips out again. Once the rope has caught, PULL brings the boat over: 'the boat glides across the river and lands on this side' (A76A). Swimming across instead is fatal (A240). The HELP message at the river is 'boats can help. look carefully.'
Bilbo cannot capture anyone
There is a CAPTURE action (action 48, A316), and the rules would let Bilbo capture a goblin. But in the dictionary CAPTURE is a synonym for ATTACK (6040), so the tokeniser (6E8E) turns 'capture goblin' into 'attack goblin' before the parser sees it, and action 48 can never be reached from the keyboard - not even by ordering another character, because orders are typed too. Only the characters' own behaviour programs (C71C), which use action numbers directly, ever capture anyone. In the emulator, 'capture goblin' gives 'you attack the disgusting goblin.' - and the goblin captures Bilbo instead.
The golden key opens nothing
A golden key lies at the end of a dead-end path in the deep misty valley (room 79). The key check (A26A) only recognises the small curious key, the large key and the red key, and no object has a handler that accepts the golden key, so it opens nothing at all. The front door of Bag End cannot be locked or unlocked with any key either: its handler always replies 'the key does not fit this lock'.
The small curious key is buried three deep
In the goblins' dungeon, the small curious key is inside the goblins' cache, which is under a trap door, which is buried in the sand. Digging opens the sand (8FCF); the trap door is locked, and no key fits it (A26A), so it has to be broken open (9257).
An unused room description
Among the messages is 'a bewitched gloomy place surrounded by thick trees' (B4EF), a full description for room 25. Nothing in the game refers to it: the room record's description pointer is 0, so the room is described just by its three name words ('you are in a bewitched gloomy place').
Checked in the emulator
The following were confirmed by running the game: the fight results and the random-number bug; the pale bulbous eyes (wait twice, move on the third turn); the slurred speech after drinking the wine; the sword lighting dark places; the random hidden route and Gollum's riddle choice; stealing while wearing the ring; the ring dividing strength by 4, losing the remainder, and wearing off after a random number of turns; the deep bog killing at the end of the first turn; the spiders' place allowing the turn of arrival and three more; the trolls eating Bilbo if he stays after they have spoken, and dawn three turns later ('you are in in a clearing with two stone trolls'); the side door appearing for one turn in five after Bilbo has been in the Elvenking's cellar, and the dragon and Bard being switched on there; tools breaking when used to break things; 'capture' being treated as 'attack'. A scripted opening - taking the large key after dawn, unlocking the trolls' cave, taking the sword and rope, and giving the map to Elrond - played exactly as the code predicts, ending with 'elrond examines the curious map. elrond says "go east from the forest gate to get to the bewitched gloomy place"'.
Hitting a friend makes an enemy for good
Characters on the same side never attack each other (90B4). Bilbo can still attack Thorin, Gandalf, Elrond or Bard, but doing so permanently clears their 'Bilbo's side' bit, so from then on they will fight him - and anyone else - like any other character.
The best possible score is 75%
The score (at $B5E8, in tenths of a percent) is set to 0 at the start of a game and changed in exactly one place: the movement routine, when Bilbo first enters one of the fourteen rooms in the points table (8CEA), which add up to 75.0%. Nothing else scores - not killing the dragon, not finding the treasure, not even winning. A perfect game ends with 'you have mastered 75.0% of this adventure'.
Why Thorin and Gandalf fight when an invisible Bilbo hits Thorin
Three rules combine. Hitting Thorin clears his 'Bilbo's side' bit for good (90B4), so he no longer shares a side with Gandalf. Being attacked switches Thorin to the general fight-back program (C71C, at C94D), whose first instruction is simply 'attack', leaving the game to choose the target as it does for the player (8405). And the choice only considers things Thorin can see (9D92, which needs bit 7 of the candidate's flags): with the ring on, Bilbo is invisible, so the only candidate is Gandalf. Once Gandalf has been attacked he switches to the same fight-back program, and since Thorin is no longer on his side he can attack Thorin - and they carry on until one of them dies. In the emulator, with the ring kept on and Gandalf held in the room, 'hit thorin' was followed by 'thorin attacks gandalf. gandalf attacks thorin...' every time, ending in one case with 'with one well placed blow gandalf cleaves his skull. thorin is dead.'
Two routines that nothing ever calls
The finished game contains two complete routines that are never reached from anywhere: A0DE, which looks up whoever holds a given object, and A600, which finds and seals up an exit (its own reuse of 9E6E suggests it was meant for the boat). Neither is called by any other routine, referenced in any object's handler list, or used by any room-entry handler or timer. They read like abandoned code - perhaps an earlier approach to a puzzle that was solved a different way by the time the game shipped.