Sherlock: annotated disassembly

Routines

Prev: CAAE Up: Map Next: CB28
CAAF: Announce a character coming into the player's room
For any actor but you (0), 1 and 100 (DC6C): if it was not in the player's room before the action (C491) and is now, prints 68ED, '<actor> ENTERS.' (CBC2).
Input
$A036 The actor
Output
An entrance announced, or the direct object's arrival noted
CAAF CALL $DC6C Actor 0, 1 or 100 (DC6C)?
CAB2 RET Z Yes: nothing to announce
CAB3 LD A,($C491) Read "Rooms saved before an action" (C491) into A - The actor's room before the action (C491)...
CAB6 LD HL,$A009 Point HL at the room the player is in, which decides what is shown ($A009)
CAB9 CP (HL) ...equal to the player's room ($A009)?
CABA RET Z Yes: was already here, no entrance
CABB LD A,($A036) Read $A036 in "Game variables" into A - Where is the actor now (D495)?
CABE CALL $D495 Call the routine "GET-ACTOR-ROOM: what room is actor A currently in?" (D495)
CAC1 LD HL,$A009 Point HL at the room the player is in, which decides what is shown ($A009)
CAC4 CP (HL) ...the player's room?
CAC5 JR NZ,$CAD0 No: skip the announcement
CAC7 LD A,($A036) Print '<actor> ENTERS.' (68ED) via CBC2
CACA LD DE,$68ED Point DE at the message "THE ENTERS." (68ED)
CACD CALL $CBC2 Call the routine "Print message DE about thing A, if it is in the..." (CBC2)
CAD0 LD A,($A00F) Read $A00F in "Game variables" into A - Direct object has to be here (requirement code 7 or more)?
CAD3 CP $07 Compare A with $07
CAD5 RET C No: finished
CAD6 LD A,($A034) Read $A034 in "Game variables" into A - Where is the direct object now (D495)?
CAD9 CALL $D495 Call the routine "GET-ACTOR-ROOM: what room is actor A currently in?" (D495)
CADC CP $FF Compare A with $FF - $FF: it has no room of its own (CAE0 onwards tries a different test)
CADE JR NZ,$CB12 If A differs from $FF, jump on to CB12
CAE0 LD B,(IX+$00) Read the first byte of the record at IX into B - Scan the bytes at IX+$0F onwards, up to the record's size, for the player's room
CAE3 LD A,($A009) Read the room the player is in, which decides what is shown ($A009) into A
CAE6 CP (IX+$0F) Compare A with byte +15 of the record at IX
CAE9 JR Z,$CAF0 If A equals byte +15 of the record at IX, skip ahead to CAF0
CAEB INC IX Step IX on to the next byte
CAED DJNZ $CAE6 Count B down and, while it is not zero, go back to CAE6
CAEF RET Not found: return
CAF0 LD A,($A036) Read $A036 in "Game variables" into A - Found: save the actor in B and blank $A036
CAF3 LD B,A Copy A into B
CAF4 LD A,$FF Load A with $FF
CAF6 LD ($A036),A Store A in $A036 in "Game variables"
CAF9 LD A,$01 Load A with $01 - Switch output on ($5C3C = 1)
CAFB LD ($5C3C),A Store A in the output-switch byte (TV_FLAG) ($5C3C)
CAFE LD A,($A009) Read the room the player is in, which decides what is shown ($A009) into A - Look for an exit of the player's room (D471)...
CB01 CALL $D471 Call D471 (inside "Find the exit from the actor's room through...")
CB04 CP $FF Compare A with $FF - ...and if there is one, narrate it (CA76)
CB06 CALL NZ,$CA76 If A differs from $FF, call the routine "Narrate the action, unless the verb is script-only" (CA76)
CB09 SUB A Clear A to zero - Switch output off again
CB0A LD ($5C3C),A Store A in the output-switch byte (TV_FLAG) ($5C3C)
CB0D LD A,B Copy B into A - Restore the actor
CB0E LD ($A036),A Store A in $A036 in "Game variables"
CB11 RET Return to the caller
CB12 LD A,($C492) Read C492 in "Rooms saved before an action" into A - Direct object has a room: was it in the player's room before the action (C492)?
CB15 LD HL,$A009 Point HL at the room the player is in, which decides what is shown ($A009)
CB18 CP (HL) Compare A with the byte at the room the player is in, which decides what is shown ($A009)
CB19 RET Z Yes: no entrance
CB1A LD A,($A034) Read $A034 in "Game variables" into A - Is the object the actor itself ($A036)?
CB1D LD HL,$A036 Point HL at $A036 in "Game variables"
CB20 CP (HL) Compare A with the byte at $A036 in "Game variables"
CB21 RET Z Yes: already announced above
CB22 LD DE,$68ED Point DE at the message "THE ENTERS." (68ED) - Else print '<thing> ENTERS.' (68ED)
CB25 JP $CBC2 Jump on to the routine "Print message DE about thing A, if it is in the..." (CBC2)
Prev: CAAE Up: Map Next: CB28