Sherlock: annotated disassembly

Routines

Prev: B39D Up: Map Next: B483
B405: Copy the typed objects into the two object slots, in the verb's order
Once a verb record has matched (B39D): works out from the record (A2BD, $A01D/$A01E) and the preposition typed whether the parse node's first or second group of words is the direct object, notes the order at $B182, and copies six bytes of words from the node into the direct-object slot $B172 and the indirect-object slot $B178, setting bit 0 of B16D/$B16E when a slot is not empty.
TAKE LAMP: no preposition, $A01E = $40, BC = $0812 - the direct object from the node's first group (+8), the indirect from the second (+18). GIVE WATSON LAMP: no preposition, $A01E = $61 (bit 5 set), BC = $1208 - the other way round, and the game says 'You give the oil lamp to Watson.' GIVE LAMP TO WATSON: TO matches the node's first group's preposition (+14), $A01D = $0C, bit 5 flipped, BC = $0812. TALK TO WATSON: TO typed ($B188) but not attached to a group, so $A01D's bit 5 ($28) is used as it is: $0812.
How it works:
1. If the pattern matched with its middle words swapped (A = 1), swap the two prepositions at $B188 and $B18A.
2. Gather the verb's flags (A2BD).
3. With no preposition typed, bit 5 of $A01E decides the order of the two noun phrases (GIVE WATSON LAMP).
4. Otherwise see which of the node's two groups the preposition belongs to (+14 or +16) and put each group in the matching slot.
Input
A 1 if the pattern matched with its middle words swapped, 0 if not
IY The parse node
Output
The two object slots filled in the verb's order
B405 AND A Test A for zero (this leaves A as it was and clears carry) - A = 1: the verb record matched with its middle words swapped (A4CD); swap $B188 and $B18A to suit
B406 JR Z,$B416 If A is zero, skip ahead to B416
B408 LD HL,($B188) Read $B188 in "Parser variables" into HL
B40B LD DE,($B18A) Read $B18A in "Parser variables" into DE
B40F LD ($B188),DE Store DE in $B188 in "Parser variables"
B413 LD ($B18A),HL Store HL in $B18A in "Parser variables"
B416 CALL $A2BD Gather the verb's flags ($A01D, $A01E)
B419 LD HL,$B188 Point HL at $B188 in "Parser variables" - No preposition typed ($B188 = 0)?
B41C LD A,(HL) Read the byte at $B188 in "Parser variables" into A
B41D INC HL Step HL on to the next byte
B41E OR (HL) Set in A the bits that are set in the byte HL points at
B41F JR NZ,$B426 If the result is not zero, skip ahead to B426
B421 LD A,($A01E) Read $A01E in "Game variables" into A - Then $A01E bit 5, flipped, picks the order (GIVE WATSON LAMP)
B424 JR $B445 Skip ahead to B445
B426 DEC HL Step HL back one byte - Is it the preposition of the node's first group (+14)...
B427 LD A,(HL) Read the byte HL points at into A
B428 CP (IY+$0E) Compare A with byte +14 of the record at IY
B42B JR NZ,$B435 If A differs from byte +14 of the record at IY, skip ahead to B435
B42D INC HL Step HL on to the next byte
B42E LD A,(HL) Read the byte HL points at into A
B42F CP (IY+$0F) Compare A with byte +15 of the record at IY
B432 JR Z,$B440 If A equals byte +15 of the record at IY, skip ahead to B440
B434 DEC HL Step HL back one byte
B435 LD A,(HL) Read the byte HL points at into A - ...or of its second (+16)?
B436 CP (IY+$10) Compare A with byte +16 of the record at IY
B439 JR NZ,$B440 If A differs from byte +16 of the record at IY, skip ahead to B440
B43B INC HL Step HL on to the next byte
B43C LD A,(HL) Read the byte HL points at into A
B43D CP (IY+$11) Compare A with byte +17 of the record at IY
B440 LD A,($A01D) Read $A01D in "Game variables" into A - $A01D bit 5 - flipped if so - picks the order
B443 JR NZ,$B447 If A differs from byte +17 of the record at IY, skip ahead to B447
B445 XOR $20 Flip in A the bits that are set in $20
B447 BIT 5,A Test bit 5 of A - Bit 5 set: B = 8 (the direct object is the first group), C = 18
B449 LD BC,$1208 Load BC with $1208
B44C JR Z,$B451 If bit 5 of A is clear, skip ahead to B451
B44E LD BC,$0812 Clear: the other way round
B451 LD HL,$B182 Point HL at $B182 in "Parser variables" - Note the order at $B182
B454 LD (HL),B Store B at the address HL points to
B455 INC HL Step HL on to the next byte
B456 LD (HL),C Store C at the address HL points to
B457 LD A,B Copy B into A - Copy the direct object's six bytes into $B172 (count at B16D)
B458 LD DE,$B172 Point DE at $B172 in "Parser variables"
B45B LD HL,$B16D Point HL at "Parser variables" (B16D)
B45E CALL $B468 Call B468 (inside "Copy the typed objects into the two object...")
B461 LD A,C Copy C into A - and the indirect object's into $B178 ($B16E)
B462 LD DE,$B178 Point DE at $B178 in "Parser variables"
B465 LD HL,$B16E Point HL at $B16E in "Parser variables"
B468 PUSH BC Save BC on the stack - HL = the node + the offset; copy six bytes
B469 LD C,A Copy A into C
B46A LD B,$00 Load B with $00
B46C PUSH HL Save HL on the stack
B46D PUSH IY Save IY on the stack
B46F POP HL Restore HL from the stack
B470 ADD HL,BC Add BC to HL
B471 LD BC,$0006 Load BC with $0006
B474 LDIR Copy BC bytes from where HL points to where DE points, counting up
B476 XOR A Clear A to zero (and the carry flag) - Any of them non-zero?
B477 LD B,$06 Load B with $06
B479 DEC HL Step HL back one byte
B47A OR (HL) Set in A the bits that are set in the byte HL points at
B47B DJNZ $B479 Count B down and, while it is not zero, go back to B479
B47D POP HL Restore HL from the stack
B47E POP BC Restore BC from the stack
B47F RET Z If the zero flag is set, return
B480 SET 0,(HL) Set bit 0 of the byte HL points at - Then the slot is used: set bit 0 of its count
B482 RET Return to the caller
Prev: B39D Up: Map Next: B483