Sherlock: annotated disassembly

Routines

Prev: BD51 Up: Map Next: BE5A
BDC2: Turn the player's remark into a statement
The relation is the position of the remark's verb in the list at 994D; the subject and object are the first two things named (BE3C, BE4B), each copied as a 6-byte entry into $9FF6 (people) or $9FFC (things) by BE22. Carry set if the remark names more than that.
BE22 copies thing A's 6-byte entry to $9FF6 (a person, +5 bit 6) or $9FFC; BE3C and BE4B step through the parser's object slots at $B172 and $B178.
How it works:
1. Start both searches at the top of the thing index (D04F).
2. Look the remark's verb word up in the list of relation words at 994D. Its position in that list (counting from 1) is the statement's relation. If it is not there the remark is not a statement: return Z.
3. Allow things that are not in the room to be named ($A038 = 2).
4. Find the thing that matches the subject words (BE3C). None means it is not a statement. A second match means the subject is ambiguous: return carry. Otherwise remember it and copy its six-byte entry to $9FF6 if it is a person or $9FFC if not (BE22), so that HE, IT and THEY can refer to it later.
5. Do the same for the object words (BE4B).
6. Return NZ: the statement's subject, relation and object are in $BA19, $BA1A and BA1B.
Input
$BA17 The remark's verb word
Output
F NZ if it made a statement, Z if it is not one
Carry set if a name was ambiguous
BDC2 CALL $D04F Call the routine "IX = just before the start of the thing index (8B6F)" (D04F) - Both searches start at the top of the thing index
BDC5 LD ($BA13),IX Store IX in "Variables used by the code at BA20-BF58" (BA13)
BDC9 LD ($BA15),IX Store IX in $BA15 in "Variables used by the code at BA20-BF58"
BDCD LD DE,($BA17) DE = the remark's verb word
BDD1 LD HL,$994D Point HL at "The case's relation words" (994D) - Find it in the list of relation words at 994D (B counts from 1)
BDD4 LD B,$01 Load B with $01
BDD6 LD A,(HL) Read the byte HL points at into A
BDD7 INC HL Step HL on to the next byte
BDD8 OR (HL) Set in A the bits that are set in the byte HL points at
BDD9 DEC HL Step HL back one byte
BDDA RET Z If the result is zero, return - Not there (the list ends with 0): not a statement (Z)
BDDB LD A,E Copy E into A
BDDC CP (HL) Compare A with the byte HL points at
BDDD JR NZ,$BDE5 If A differs from the byte HL points at, skip ahead to BDE5
BDDF INC HL Step HL on to the next byte
BDE0 LD A,D Copy D into A
BDE1 CP (HL) Compare A with the byte HL points at
BDE2 DEC HL Step HL back one byte
BDE3 JR Z,$BDEA If A equals the byte HL points at, skip ahead to BDEA
BDE5 INC HL Step HL on to the next byte
BDE6 INC HL Step HL on to the next byte
BDE7 INC B Add one to B
BDE8 JR $BDD6 Go back to BDD6
BDEA LD A,B Copy B into A - Its position is the relation
BDEB LD ($BA1A),A Store A in $BA1A in "Variables used by the code at BA20-BF58"
BDEE LD A,$02 Load A with $02 - The things named need not be here ($A038 = 2)
BDF0 LD ($A038),A Store A in $A038 in "Game variables"
BDF3 CALL $BE3C Call BE3C (inside "Turn the player's remark into a statement") - The first thing matching the subject words
BDF6 CP $FF Compare A with $FF
BDF8 RET Z If A equals $FF, return - None: not a statement
BDF9 LD ($BA19),A Store A in $BA19 in "Variables used by the code at BA20-BF58"
BDFC CALL $BE3C Call BE3C (inside "Turn the player's remark into a statement") - More than one: carry (which one is meant?)
BDFF CP $FF Compare A with $FF
BE01 JR NZ,$BE3A If A differs from $FF, jump on to BE3A
BE03 LD A,($BA19) Read $BA19 in "Variables used by the code at BA20-BF58" into A - Copy the subject's entry
BE06 CALL $BE22 Call BE22 (inside "Turn the player's remark into a statement")
BE09 CALL $BE4B Call BE4B (inside "Turn the player's remark into a statement") - The same for the object words
BE0C CP $FF Compare A with $FF
BE0E RET Z If A equals $FF, return
BE0F LD ($BA1B),A Store A in BA1B in "Variables used by the code at BA20-BF58"
BE12 CALL $BE4B Call BE4B (inside "Turn the player's remark into a statement")
BE15 CP $FF Compare A with $FF
BE17 JR NZ,$BE3A If A differs from $FF, skip ahead to BE3A
BE19 LD A,($BA1B) Read BA1B in "Variables used by the code at BA20-BF58" into A
BE1C CALL $BE22 Call BE22 (inside "Turn the player's remark into a statement")
BE1F OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller - Succeed (NZ)
BE21 RET Return to the caller
BE22 CALL $D237 Call the routine "Resolve an id (in A) to its full entity record" (D237) - HL = the thing's record
BE25 PUSH IX Save IX on the stack
BE27 POP HL Restore HL from the stack
BE28 BIT 6,(IX+$05) Test bit 6 of byte +5 of the record at IX - A person (+5 bit 6) goes to $9FF6, anything else to $9FFC
BE2C LD DE,$9FF6 Point DE at $9FF6 in "Game variables"
BE2F JR NZ,$BE34 If bit 6 of byte +5 of the record at IX is set, skip ahead to BE34
BE31 LD DE,$9FFC Point DE at $9FFC in "Game variables"
BE34 LD BC,$0006 Load BC with $0006 - Copy six bytes
BE37 LDIR Copy BC bytes from where HL points to where DE points, counting up
BE39 RET Return to the caller
BE3A SCF Set the carry flag for the caller - Carry: ambiguous
BE3B RET Return to the caller
BE3C LD IX,($BA13) Read "Variables used by the code at BA20-BF58" (BA13) into IX - Next thing matching the subject slot ($B172)
BE40 LD HL,$B172 Point HL at $B172 in "Parser variables"
BE43 CALL $D36A Call the routine "Find the next thing that matches a word slot of the..." (D36A)
BE46 LD ($BA13),IX Store IX in "Variables used by the code at BA20-BF58" (BA13)
BE4A RET Return to the caller
BE4B LD IX,($BA15) Read $BA15 in "Variables used by the code at BA20-BF58" into IX - Next thing matching the object slot ($B178)
BE4F LD HL,$B178 Point HL at $B178 in "Parser variables"
BE52 CALL $D36A Call the routine "Find the next thing that matches a word slot of the..." (D36A)
BE55 LD ($BA15),IX Store IX in $BA15 in "Variables used by the code at BA20-BF58"
BE59 RET Return to the caller
Prev: BD51 Up: Map Next: BE5A