Sherlock: annotated disassembly

Routines

Prev: D36A Up: Map Next: D3D5
D39B: Find the next room that matches a word slot of the parse
The room counterpart of D36A: B counts on through the rooms (up to 105, then A = $FF for none), each room's record (D224) has its name words matched against the slot (A4E0), and - unless $A038 is set - only rooms that pass D471 count. Returns the room in A and IX. Its address is handed to the parser's search at $B4E9 and $B590 (LD IY,D39B), as D36A's is for things.
Input
HL A word slot of the parse
IX The search position (a room number in B)
Output
A The next matching room, $FF if none
IX The search position
D39B PUSH IY Save IY on the stack - BC = where the last search stopped (a room number in B)
D39D PUSH DE Save DE on the stack
D39E PUSH BC Save BC on the stack
D39F PUSH IX Save IX on the stack
D3A1 POP BC Restore BC from the stack
D3A2 LD DE,$0001 Load DE with $0001
D3A5 INC B Add one to B - Next room
D3A6 LD A,B Copy B into A
D3A7 CP $6A Compare A with $6A - $6A rooms: the end (A = $FF)
D3A9 LD A,$FF Load A with $FF
D3AB JR Z,$D3CD If A equals $6A, skip ahead to D3CD
D3AD LD A,B Copy B into A
D3AE CALL $D224 Call the routine "Find a room record" (D224) - That room's record (D224)...
D3B1 PUSH IX Save IX on the stack
D3B3 POP IY Restore IY from the stack
D3B5 ADD IY,DE Add DE to IY - ...and its words (+1): do they name the slot's words? (A4E0)
D3B7 CALL $A4E0 Call A4E0 (inside "Do the pattern words at IY name the words...")
D3BA JR NZ,$D3A5 If the zero flag is clear, go back to D3A5
D3BC LD A,($A038) Read $A038 in "Game variables" into A - A match: if the room need not be next door ($A038), take it
D3BF AND A Test A for zero (this leaves A as it was and clears carry)
D3C0 JR NZ,$D3CC If A is not zero, skip ahead to D3CC
D3C2 PUSH BC Save BC on the stack - Otherwise only if it is next to the actor's room (D471)
D3C3 LD A,B Copy B into A
D3C4 CALL $D471 Call D471 (inside "Find the exit from the actor's room through...")
D3C7 POP BC Restore BC from the stack
D3C8 CP $FF Compare A with $FF
D3CA JR Z,$D3A5 If A equals $FF, go back to D3A5
D3CC LD A,B Copy B into A - Return it in A, and the search position in IX
D3CD PUSH BC Save BC on the stack
D3CE POP IX Restore IX from the stack
D3D0 POP BC Restore BC from the stack
D3D1 POP DE Restore DE from the stack
D3D2 POP IY Restore IY from the stack
D3D4 RET Return to the caller
Prev: D36A Up: Map Next: D3D5