Sherlock: annotated disassembly

Routines

Prev: CBBB Up: Map Next: CC0B
CBC2: Print message DE about thing A, if it is in the player's room
Does nothing for $FF or 0, or when the thing is somewhere else. Otherwise switches output on ($5C3C = 1) and prints DE with the thing as its subject.
How it works:
1. Do nothing if the thing is $FF or 0 (nobody).
2. Find which room the thing is in (D495). If it is not the room the player is looking at ($A009), do nothing.
3. Otherwise switch printing on and climb from the thing to whatever holds it at the top, a cab for example, so that the message is about the outermost holder.
4. Make the player the current actor for a moment and ask whether the player can see that holder (C821). If not, return without printing.
5. If so, put the real actor back and print message DE with the holder's name as its subject (A59F).
Input
A The thing
DE The message
Output
Nothing is printed unless the player can see the thing
CBC2 CP $FF Compare A with $FF - Nothing for $FF or 0
CBC4 RET Z If A equals $FF, return
CBC5 AND A Clear the carry flag for the caller (A is unchanged)
CBC6 RET Z If A is zero, return
CBC7 LD B,A Copy A into B - B = the thing; is it in the room the player is looking at ($A009)?
CBC8 CALL $D495 Call the routine "GET-ACTOR-ROOM: what room is actor A currently in?" (D495)
CBCB LD C,A Copy A into C
CBCC LD A,($A009) Read the room the player is in, which decides what is shown ($A009) into A
CBCF CP C Compare A with C
CBD0 RET NZ If A differs from C, return
CBD1 LD A,$01 Load A with $01 - Yes: output on
CBD3 LD ($5C3C),A Store A in the output-switch byte (TV_FLAG) ($5C3C)
CBD6 PUSH DE Save DE on the stack
CBD7 LD A,B Copy B into A - Climb to whatever holds it at the top (a cab, say)
CBD8 CALL $D237 Call the routine "Resolve an id (in A) to its full entity record" (D237)
CBDB LD A,(IX+$01) Read the holder byte (+1) of the thing record at IX into A
CBDE CP $FF Compare A with $FF
CBE0 JR Z,$CBE5 If A equals $FF, skip ahead to CBE5
CBE2 LD B,A Copy A into B
CBE3 JR $CBD7 Go back to CBD7
CBE5 LD A,B Copy B into A - Its name is the message's subject (record + 7, on the stack)
CBE6 CALL $A4BC Call the routine "HL = thing A's record + 7" (A4BC)
CBE9 EX (SP),HL Swap HL with the word on top of the stack
CBEA LD A,($A036) Read $A036 in "Game variables" into A - For a moment make the player the current actor...
CBED PUSH AF Save AF on the stack
CBEE LD A,($9860) Read "The actor table: who acts, and where each is in..." (9860) into A
CBF1 LD ($A036),A Store A in $A036 in "Game variables"
CBF4 CALL $CC29 Call the routine "Set up the current actor: its record and room" (CC29)
CBF7 LD A,B Copy B into A - ...and ask whether he can see that (C821)
CBF8 CALL $C821 Call the routine "Can the current actor ($A036) see thing A?" (C821)
CBFB JR NZ,$CC00 If the zero flag is clear, skip ahead to CC00
CBFD POP AF Restore AF from the stack - No: return (leaving $A036 as the player - it is not put back)
CBFE POP HL Restore HL from the stack
CBFF RET Return to the caller
CC00 POP AF Restore AF from the stack - Yes: back to the real actor and print message DE (A59F)
CC01 LD ($A036),A Store A in $A036 in "Game variables"
CC04 CALL $CC29 Call the routine "Set up the current actor: its record and room" (CC29)
CC07 CALL $A59F Call the routine "Print the message at HL" (A59F)
CC0A RET Return to the caller
Prev: CBBB Up: Map Next: CC0B