| The Hobbit (v1.0) | Routines |
| Prev: 858F | Up: Map | Next: 869D |
|
Decides which of the command's two noun phrases is the target and which the instrument, from the preposition the action expects and bit 5 of the action's flags. The target's words are copied to $8333 and also to $B5D1 (for IT), and the instrument's to $8339. Bit 0 of 832E and $832F is set if the phrase actually has a noun.
I originally described this as also making 'with the sword hit thorin' work alongside 'hit thorin with the sword'. Testing it in the emulator shows that is not so: putting the prepositional phrase before the plain noun - 'with sword hit thorin', 'hit with sword thorin', 'with large key unlock heavy door' - always fails, usually with a nonsensical result such as 'you cannot attack the short strong sword.' (the sword having been read as the target). Only the ordinary phrasing works reliably. What the crossing test in 8614 is actually for is not fully confirmed; it may cover cases within the two fixed phrase slots that ordinary play does not exercise, such as an action whose own table entry could match the two collected prepositions either way round.
|
||||
| 8614 | AND A | Did 71EA find the two words in the natural order (A=0) or crossed over (A=1)? | ||
| 8615 | JR Z,$8625 | Natural order: nothing to undo | ||
| 8617 | LD HL,($834B) | Crossed over: swap the two prepositions collected by 858F... | ||
| 861A | LD DE,($834D) | |||
| 861E | LD ($834B),DE | |||
| 8622 | LD ($834D),HL | ...putting them back the natural way round | ||
| 8625 | CALL $70EA | Work out the action's own flag bytes | ||
| 8628 | LD HL,$834B | Was any preposition collected at all? | ||
| 862B | LD A,(HL) | |||
| 862C | INC HL | |||
| 862D | OR (HL) | |||
| 862E | JR NZ,$8635 | Yes, at least one: work out which noun phrase it actually came from, below | ||
| 8630 | LD A,($B60E) | None at all (e.g. plain TAKE): use the action's own default choice of which phrase is the target | ||
| 8633 | JR $8654 | |||
| 8635 | DEC HL | Back to the first collected preposition | ||
| 8636 | LD A,(HL) | Does it match the SECOND noun phrase's own first preposition? | ||
| 8637 | CP (IY+$0E) | |||
| 863A | JR NZ,$8644 | No: try matching it against the second phrase's other preposition instead | ||
| 863C | INC HL | Low bytes matched: check the high bytes too | ||
| 863D | LD A,(HL) | |||
| 863E | CP (IY+$0F) | |||
| 8641 | JR Z,$864F | A full match: this preposition belongs to the SECOND noun phrase | ||
| 8643 | DEC HL | No match after all: back to the low byte | ||
| 8644 | LD A,(HL) | Does it match the second phrase's OTHER preposition slot instead? | ||
| 8645 | CP (IY+$10) | |||
| 8648 | JR NZ,$864F | Neither: give up trying to tell which phrase it belongs to | ||
| 864A | INC HL | Matched: check the high byte too | ||
| 864B | LD A,(HL) | |||
| 864C | CP (IY+$11) | |||
| 864F | LD A,($B60D) | A = the action's main flags | ||
| 8652 | JR NZ,$8656 | The preposition was NOT shown to belong to the second phrase: use the flags as they are | ||
| 8654 | XOR $20 | It WAS shown to belong to the second phrase: flip the "which phrase is the target" bit | ||
| 8656 | BIT 5,A | Is the SECOND noun phrase the target? | ||
| 8658 | LD BC,$1208 | Assume not: (second phrase's noun offset, first phrase's noun offset) | ||
| 865B | JR Z,$8660 | |||
| 865D | LD BC,$0812 | It is: swap the two offsets round instead | ||
| 8660 | LD HL,$8345 | Remember the two offsets, for use below | ||
| 8663 | LD (HL),B | |||
| 8664 | INC HL | |||
| 8665 | LD (HL),C | |||
| 8666 | LD A,B | A = whichever offset is the TARGET's own noun | ||
| 8667 | LD DE,$8333 | Copy its words into the target work area... | ||
| 866A | LD HL,$832E | ...and mark whether a target noun was actually given | ||
| 866D | CALL $8682 | |||
| 8670 | LD A,C | The target's own words also become the new meaning of the word IT... | ||
| 8671 | LD HL,$8333 | |||
| 8674 | LD DE,$B5D1 | |||
| 8677 | LD BC,$0006 | |||
| 867A | LDIR | |||
| 867C | LD DE,$8339 | A = whichever offset is the INSTRUMENT's own noun | ||
| 867F | LD HL,$832F | Copy its words into the instrument work area too | ||
| 8682 | PUSH BC | (Shared code, reached both directly above and by falling in here) save BC | ||
| 8683 | LD C,A | C = the frame offset to copy from | ||
| 8684 | LD B,$00 | |||
| 8686 | PUSH HL | Save the flag-byte address for a moment | ||
| 8687 | PUSH IY | HL = the frame, plus that offset... | ||
| 8689 | POP HL | |||
| 868A | ADD HL,BC | |||
| 868B | LD BC,$0006 | Copy 6 bytes: the noun and its two adjectives | ||
| 868E | LDIR | |||
| 8690 | XOR A | Was anything actually copied (is any of it non-zero)? | ||
| 8691 | LD B,$06 | |||
| 8693 | DEC HL | |||
| 8694 | OR (HL) | |||
| 8695 | DJNZ $8693 | |||
| 8697 | POP HL | Restore the flag-byte address | ||
| 8698 | POP BC | Restore BC | ||
| 8699 | RET Z | Nothing was given: leave the flag alone | ||
| 869A | SET 0,(HL) | Something was given: record that a noun really was named | ||
| 869C | RET | |||
| Prev: 858F | Up: Map | Next: 869D |