| The Hobbit (v1.0) | Routines |
| Prev: 7C3E | Up: Map | Next: 7C9C |
|
The parser. It works through the tokens in 7093 (the pointer to the next token is kept at $B5CD) and turns them into one or more 24-byte command frames, starting at B8B8 and growing downwards in memory (B8A0, B888...). The number of frames built is counted in $B5F7.
A frame holds: the verb (offset 0; bit 7 of byte 1 marks a command with ALL, and bit 6 marks an extra frame that only holds an exception for ALL EXCEPT), an adverb, direction or particle (offset 2), and two noun phrases of 10 bytes each (offsets 4 and 14). A noun phrase is two prepositions, a noun and two adjectives, so 'put the small curious key in the wooden chest' becomes PUT, (KEY, SMALL, CURIOUS), (IN, CHEST, WOODEN).
The parser is a state machine. Register E holds a set of flags saying what may come next: bit 1 'a verb may start here', bit 2 'an adverb is allowed', bit 3 'we have just had AND', bit 4 'an article is allowed', bit 6 'the first noun phrase is still empty', bit 7 'the second noun phrase is still empty', bit 0 'the verb has been followed by a direction'. Register D holds the class of the token being processed.
For each token, 7F3D fetches it and the class (top nibble, divided by 8) indexes the jump table at 7C9C, which sends it to a handler: adverbs to 7DBC, IN/INTO to 7E5F, directions to 7DB6, verbs to 7DFD, GO/RUN to 7DF9, nouns to 7E9B, adjectives to 7E93, prepositions to 7E6C, articles to 7E5A, special words to 8009, AND to 7DD5, THEN (and full stop) to 7CC4 and the end of the line to 7CC0.
A word that is not allowed where it appears goes to 7FEE, which prints 'what?' (inside a quotation it is ignored instead, so that orders to other characters are more forgiving).
If a previous command was left unfinished ($B60A set, for example after the game asked 'which key?'), the parser starts in a different state so that the words just typed are fitted into the old frame (see 7CFC).
|
||||
| 7C4F | LD IY,$B8B8 | IY = the first command frame | ||
| 7C53 | XOR A | Not inside a quotation | ||
|
This entry point is used by the routine at 80B5.
|
||||
| 7C54 | LD ($B60B),A | } | ||
| 7C57 | CALL $7F29 | No ALL or ALL EXCEPT in force | ||
| 7C5A | LD ($B5F7),A | No frames built yet | ||
| 7C5D | LD E,$FF | State: everything allowed | ||
| 7C5F | LD A,($B60A) | Is an unfinished command waiting to be completed? | ||
| 7C62 | AND A | |||
| 7C63 | LD D,$A0 | (Pretend the previous word was AND) | ||
| 7C65 | JP NZ,$7CDE | Yes: go straight to the end-of-line processing, which merges the new words in | ||
| 7C68 | LD D,$C0 | Previous class: end of line | ||
| 7C6A | XOR A | START OF A COMMAND: no prepositions yet | ||
| 7C6B | LD ($7C44),A | |||
| 7C6E | LD A,E | Allow a verb (bit 1), an adverb (bit 2), and both noun phrases (bits 6 and 7)... | ||
| 7C6F | OR $C7 | |||
| 7C71 | LD E,A | |||
| 7C72 | LD A,($B609) | ...but after ALL EXCEPT... | ||
| 7C75 | CP $02 | |||
| 7C77 | JR NZ,$7C7B | |||
| 7C79 | RES 1,E | ...no new verb is allowed | ||
| 7C7B | CALL $7F2E | Clear the frame | ||
| 7C7E | LD HL,$7C45 | NEXT NOUN PHRASE: clear the 10-byte noun phrase buffer | ||
| 7C81 | LD B,$0A | |||
| 7C83 | CALL $70D9 | |||
| 7C86 | SET 4,E | Articles are allowed again | ||
|
This entry point is used by the routine at 7E5A.
|
||||
| 7C88 | CALL $7F3D | NEXT WORD: fetch it; A and D = its class, BC = the word | ||
| 7C8B | PUSH DE | |||
| 7C8C | RRCA | Class / 8 = offset into the jump table | ||
| 7C8D | RRCA | |||
| 7C8E | RRCA | |||
| 7C8F | LD E,A | |||
| 7C90 | LD D,$00 | |||
| 7C92 | LD HL,$7C9C | HL = the handler for this class | ||
| 7C95 | ADD HL,DE | |||
| 7C96 | LD E,(HL) | |||
| 7C97 | INC HL | |||
| 7C98 | LD D,(HL) | |||
| 7C99 | EX DE,HL | |||
| 7C9A | POP DE | |||
| 7C9B | JP (HL) | Go to it | ||
| Prev: 7C3E | Up: Map | Next: 7C9C |