Routines 
Prev: 29194  Up: Map  Next: 29332 
Used by the routine at 29559. Returns with the carry flag reset if the policeman spots, recognises and starts chasing Sam.


29218  CALL 28842  Is Sam close enough that the policeman has a chance of spotting him?  
29221  CCF  Return with the carry flag set if not  
29222  RET C  
29223  PUSH DE  E and D hold the horizontal and vertical distances between Sam and the policeman; save these briefly  
29224  PUSH HL  Save the policeman's character number briefly  
29225  LD H,230  230=Sam  
29227  CALL 28886  Check whether Sam is visible to passersby  
29230  LD B,6  Prepare B for the case where Sam is visible to passersby  
29232  JR Z,29248  Jump if Sam is visible to passersby  
29234  CALL 62518  Is Sam standing next to a light switch?  
29237  JR Z,29247  Jump if not  
29239  LD A,(BC)  A=window flags for Sam's location  
29240  AND 32  Set the zero flag if the light switch for this window is in the 'on' position  
29242  LD A,4  Prepare A for the case where Sam is standing next to a light switch in the 'on' position  
29244  JR Z,29247  Jump if the light switch for this window is in the 'on' position  
29246  XOR A  Prepare A for the case where Sam is neither visible to passersby nor standing next to a light switch in the 'on' position  
29247  LD B,A  B=0, 4 or 6  
Now B=6 (if Sam is visible to passersby), or 4 (if Sam is standing next to a light switch that is in the 'on' position), or 0 otherwise.


29248  CALL 29332  Check whether Sam's disguise is known to the police  
29251  POP HL  Restore the policeman's character number to H  
29252  POP DE  Restore the horizontal and vertical distances between Sam and the policeman to E and D  
29253  LD A,B  A=0, 1, 4, 5, 6 or 7  
29254  CP 6  Is Sam visible to passersby?  
29256  JR NC,29265  Jump if so  
29258  CALL 28886  Is the policeman visible to passersby?  
29261  JR NZ,29265  Jump if not  
29263  INC B  B=2, 3, 6 or 7  
29264  INC B  
29265  LD A,B  A=07  
29266  LD L,A  Save this value in L  
29267  ADD A,A  Point BC at an entry in the table at 29194  
29268  ADD A,B  
29269  ADD A,10  
29271  LD C,A  
29272  LD B,114  
29274  LD A,(BC)  Pick up the first byte of the entry  
29275  CP D  Compare it with the vertical distance between Sam and the policeman  
29276  RET C  Return (with the carry flag set) if the vertical distance is greater  
29277  INC C  Pick up the second byte of the entry  
29278  LD A,(BC)  
29279  CP E  Compare it with the horizontal distance between Sam and the policeman  
29280  RET C  Return (with the carry flag set) if the horizontal distance is greater  
29281  INC C  Pick up the third byte of the entry  
29282  LD A,(BC)  
29283  SUB D  Subtract both the horizontal and vertical distances between Sam and the policeman  
29284  SUB E  
29285  RET C  Return (with the carry flag set) if the result is negative  
29286  BIT 0,L  Bit 0 of L is set if Sam's current disguise (if any) is known to the police  
29288  LD L,29  Point HL at byte 29 of the policeman's buffer  
29290  JR NZ,29322  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.


29292  LD A,(32713)  Collect Sam's current disguise ID (17) from 32713  
29295  RRCA  Move bits 02 into bits 57  
29296  RRCA  
29297  RRCA  
29298  LD C,A  Copy these disguise identifier bits into C  
29299  LD A,(HL)  Pick up byte 29 of the policeman's buffer  
29300  AND 31  Keep only bits 04 (the disguise timeout counter)  
29302  JR NZ,29306  Jump unless they are all 0  
29304  LD A,16  The disguise timeout counter will be initialised to 16  
29306  OR C  Copy the disguise identifier bits from C into bits 57 of A  
29307  LD (HL),A  Copy the disguise identifier bits and the timeout counter into byte 29 of the policeman's buffer  
29308  INC L  L=30  
29309  CALL 25944  Determine Sam's location  
29312  LD (HL),E  Copy Sam's xcoordinate into byte 30 of the policeman's buffer  
29313  INC L  L=31  
29314  AND 3  A=0 if z (Sam's zcoordinate) is 4, 2 if z is 2, or 1 if z is 1  
29316  RRCA  A=0 if z=4, 128 (bit 7 set) if z=2, or 64 (bit 6 set) if z=1  
29317  RRCA  
29318  OR D  Copy Sam's ycoordinate into bits 05 of A  
29319  LD (HL),A  Copy this value into byte 31 of the policeman's buffer  
29320  SCF  Set the carry flag: the policeman is not chasing Sam  
29321  RET  
Sam has been spotted by the policeman, and his current disguise (if any) is known to the police.


29322  LD A,(HL)  Collect byte 29 of the policeman's buffer  
29323  AND A  Is there a disguise ID in bits 57?  
29324  CALL NZ,29126  If so, make that disguise known to the police (if it isn't already)  
29327  CALL 29088  Set the policeman's destination to Sam's current location  
29330  AND A  Clear the carry flag to indicate that the policeman is now chasing Sam  
29331  RET 
Prev: 29194  Up: Map  Next: 29332 