| Routines

29100: Send a policeman to Sam's last known whereabouts

Continues from the routine at 29559. The policeman recently spotted Sam while he was wearing a disguise unknown to the police; this routine sends that policeman back to where he first spotted Sam when the disguise becomes known.
Input
H | 222 or 223 (policeman)
29100 | LD L,31 | Pick up byte 31 of the policeman's buffer
29102 | LD A,(HL)
29103 | AND 63 | D=Sam's y-coordinate when he was spotted by the policeman while wearing a disguise unknown to the police
29105 | LD D,A
29106 | LD A,(HL) | Pick up byte 31 again
29107 | LD C,4 | Initialise the destination z-coordinate to 4
29109 | AND 192 | Was Sam's z-coordinate 4 (on the sidewalk or road) when he was spotted?
29111 | JR Z,29116 | Jump if so
29113 | RLCA | Move bits 6 and 7 of A into bits 0 and 1
29114 | RLCA
29115 | LD C,A | C=Sam's z-coordinate when he was spotted
29116 | DEC L | L=30
29117 | LD E,(HL) | E=Sam's x-coordinate when he was spotted
29118 | CALL 29076 | Set the policeman's destination coordinates to (E,D)
29121 | CALL 29091 | Copy the destination coordinates and location identifier to 32731
29124 | LD L,29 | Point HL at byte 29 of the policeman's buffer
This entry point is used by the routine at 29218.
29126 | LD A,(HL) | Pick up byte 29 of the policeman's buffer
29127 | LD (HL),0 | Set byte 29 of the policeman's buffer to 0 now that the disguise Sam was wearing is known to the police
29129 | RLCA | Move bits 5-7 of A (which hold the ID of the disguise that Sam was wearing) into bits 0-2
29130 | RLCA
29131 | RLCA
29132 | AND 7 | Keep only bits 0-2
29134 | ADD A,160 | Now A=64, 32, 16, 8, 4, 2, or 1, with the set bit corresponding to the disguise that Sam was wearing
29136 | LD D,A
29137 | LD E,21
29139 | LD A,(DE)
29140 | LD DE,32744 | 32744 holds the disguise status flags
29143 | EX DE,HL | Set the appropriate bit at 32744, making the disguise known to the police
29144 | OR (HL)
29145 | LD (HL),A
29146 | JP 32009 | Set the attribute bytes for Sam's current disguise in the bottom right corner of the screen