Sherlock: annotated disassembly

Routines

Prev: AF6B Up: Map Next: AFE1
AFB3: Is word BC a special word? Then run its handler
Searches the table at AF6B (see there for which part) and jumps to the handler; otherwise NZ (AF67).
How it works:
1. Pick the table: the twelve special words at AF6B, or - when the parser is reading speech ($A024 = 2) - only the last six, from AF9B.
2. Each entry is four bytes: a dictionary word reference followed by the address of a handler. Compare the word in BC with each entry in turn.
3. No match: return NZ, and the word is an ordinary one.
4. A match: take the handler's address and jump to it. The handler does the work and returns to the parser's caller.
Input
BC The word reference
Output
F NZ if the word is not special (otherwise the handler runs)
AFB3 LD HL,$AF6B The ordinary words...
AFB6 LD A,($A024) Read $A024 in "Game variables" into A - ...unless this is speech
AFB9 CP $02 Compare A with $02
AFBB JR NZ,$AFC0 If A differs from $02, skip ahead to AFC0
AFBD LD HL,$AF9B Point HL at AF9B in "Special words and their handlers" - Speech: the last six
AFC0 PUSH DE Save DE on the stack
AFC1 LD E,$0C Load E with $0C - Twelve entries...
AFC3 JR NZ,$AFC7 If A differs from $02, skip ahead to AFC7
AFC5 LD E,$06 ...or six
AFC7 LD A,(HL) Read the byte HL points at into A - This word?
AFC8 INC HL Step HL on to the next byte
AFC9 CP C Compare A with C
AFCA JR NZ,$AFD0 If A differs from C, skip ahead to AFD0
AFCC LD A,(HL) Read the byte HL points at into A
AFCD CP B Compare A with B
AFCE JR Z,$AFDA If A equals B, skip ahead to AFDA
AFD0 INC HL Step HL on to the next byte - No: next entry
AFD1 INC HL Step HL on to the next byte
AFD2 INC HL Step HL on to the next byte
AFD3 DEC E Subtract one from E
AFD4 JR NZ,$AFC7 If E is not zero, go back to AFC7
AFD6 POP DE Restore DE from the stack - Not special
AFD7 JP $AF67 Go back to the routine "Not a special word: NZ" (AF67)
AFDA INC HL Step HL on to the next byte - Yes: its handler
AFDB LD E,(HL) Read the byte HL points at into E
AFDC INC HL Step HL on to the next byte
AFDD LD D,(HL) Read the byte HL points at into D
AFDE EX DE,HL Swap DE and HL
AFDF POP DE Restore DE from the stack
AFE0 JP (HL) Run it
Prev: AF6B Up: Map Next: AFE1