Routines
 Prev: 720A Up: Map Next: 7294
7222: Make a policeman start chasing Sam if appropriate
Used by the routine at 7377. Returns with the carry flag reset if the policeman spots, recognises and starts chasing Sam.
Input
H 0xDE or 0xDF (policeman)
7222 CALL \$70AA Is Sam close enough that the policeman has a chance of spotting him?
7225 CCF Return with the carry flag set if not
7226 RET C
7227 PUSH DE E and D hold the horizontal and vertical distances between Sam and the policeman; save these briefly
7228 PUSH HL Save the policeman's character number briefly
7229 LD H,\$E6 0xE6=Sam
722B CALL \$70D6 Check whether Sam is visible to passers-by
722E LD B,\$06 Prepare B for the case where Sam is visible to passers-by
7230 JR Z,\$7240 Jump if Sam is visible to passers-by
7232 CALL \$F436 Is Sam standing next to a light switch?
7235 JR Z,\$723F Jump if not
7237 LD A,(BC) A=window flags for Sam's location
7238 AND \$20 Set the zero flag if the light switch for this window is in the 'on' position
723A LD A,\$04 Prepare A for the case where Sam is standing next to a light switch in the 'on' position
723C JR Z,\$723F Jump if the light switch for this window is in the 'on' position
723E XOR A Prepare A for the case where Sam is neither visible to passers-by nor standing next to a light switch in the 'on' position
723F LD B,A B=0, 4 or 6
Now B=6 (if Sam is visible to passers-by), or 4 (if Sam is standing next to a light switch that is in the 'on' position), or 0 otherwise.
7240 CALL \$7294 Check whether Sam's disguise is known to the police
7243 POP HL Restore the policeman's character number to H
7244 POP DE Restore the horizontal and vertical distances between Sam and the policeman to E and D
7245 LD A,B A=0, 1, 4, 5, 6 or 7
7246 CP \$06 Is Sam visible to passers-by?
7248 JR NC,\$7251 Jump if so
724A CALL \$70D6 Is the policeman visible to passers-by?
724D JR NZ,\$7251 Jump if not
724F INC B B=2, 3, 6 or 7
7250 INC B
7251 LD A,B A=0-7
7252 LD L,A Save this value in L
7253 ADD A,A Point BC at an entry in the table at 720A
7257 LD C,A
7258 LD B,\$72
725A LD A,(BC) Pick up the first byte of the entry
725B CP D Compare it with the vertical distance between Sam and the policeman
725C RET C Return (with the carry flag set) if the vertical distance is greater
725D INC C Pick up the second byte of the entry
725E LD A,(BC)
725F CP E Compare it with the horizontal distance between Sam and the policeman
7260 RET C Return (with the carry flag set) if the horizontal distance is greater
7261 INC C Pick up the third byte of the entry
7262 LD A,(BC)
7263 SUB D Subtract both the horizontal and vertical distances between Sam and the policeman
7264 SUB E
7265 RET C Return (with the carry flag set) if the result is negative
7266 BIT 0,L Bit 0 of L is set if Sam's current disguise (if any) is known to the police
7268 LD L,\$1D Point HL at byte 0x1D of the policeman's buffer
726A JR NZ,\$728A Jump if Sam's current disguise is known to the police
Sam has been spotted by the policeman, but he's wearing a disguise that is not (yet) known to the police.
726C LD A,(\$7FC9) Collect Sam's current disguise ID (1-7) from 7FC9
726F RRCA Move bits 0-2 into bits 5-7
7270 RRCA
7271 RRCA
7272 LD C,A Copy these disguise identifier bits into C
7273 LD A,(HL) Pick up byte 0x1D of the policeman's buffer
7274 AND \$1F Keep only bits 0-4 (the disguise timeout counter)
7276 JR NZ,\$727A Jump unless they are all 0
7278 LD A,\$10 The disguise timeout counter will be initialised to 0x10
727A OR C Copy the disguise identifier bits from C into bits 5-7 of A
727B LD (HL),A Copy the disguise identifier bits and the timeout counter into byte 0x1D of the policeman's buffer
727C INC L L=0x1E
727D CALL \$6558 Determine Sam's location
7280 LD (HL),E Copy Sam's x-coordinate into byte 0x1E of the policeman's buffer
7281 INC L L=0x1F
7282 AND \$03 A=0 if z (Sam's z-coordinate) is 4, 2 if z is 2, or 1 if z is 1
7284 RRCA A=0x00 if z=4, 0x80 (bit 7 set) if z=2, or 0x40 (bit 6 set) if z=1
7285 RRCA
7286 OR D Copy Sam's y-coordinate into bits 0-5 of A
7287 LD (HL),A Copy this value into byte 0x1F of the policeman's buffer
7288 SCF Set the carry flag: the policeman is not chasing Sam
7289 RET
Sam has been spotted by the policeman, and his current disguise (if any) is known to the police.
728A LD A,(HL) Collect byte 0x1D of the policeman's buffer
728B AND A Is there a disguise ID in bits 5-7?
728C CALL NZ,\$71C6 If so, make that disguise known to the police (if it isn't already)
728F CALL \$71A0 Set the policeman's destination to Sam's current location
7292 AND A Clear the carry flag to indicate that the policeman is now chasing Sam
7293 RET
 Prev: 720A Up: Map Next: 7294