Routines 
Prev: 28841  Up: Map  Next: 28885 
Used by the routine at 29218. Compares the policeman's coordinates with Sam's, and returns with the carry flag set if they are close enough that the policeman has a chance of spotting Sam (if other conditions are favourable).


28842  LD L,1  Point HL at byte 1 of the policeman's buffer  
28844  LD A,(58881)  A=Sam's xcoordinate  
28847  SUB (HL)  Subtract the policeman's xcoordinate  
28848  DEC HL  Point HL at byte 0 of the policeman's buffer  
28849  JR NC,28859  Jump if the policeman's xcoordinate is less than or equal to Sam's  
28851  NEG  A=horizontal distance between Sam and the policeman  
28853  BIT 7,(HL)  Is the policeman facing left (and thus facing Sam)?  
28855  JR Z,28866  Jump if so  
28857  JR 28863  
28859  BIT 7,(HL)  Is the policeman facing right (and thus facing Sam)?  
28861  JR NZ,28866  Jump if so  
28863  CP 3  Is the policeman (who is not facing Sam) at least 3 xcoordinates away from Sam?  
28865  RET NC  Return with the carry flag reset if so  
28866  CP 16  Is the policeman at least 16 xcoordinates away from Sam?  
28868  RET NC  Return with the carry flag reset if so  
At this point, the policeman is either facing Sam and located less than 16 xcoordinates away from him, or facing away from Sam and located less than 3 xcoordinates away from him. Now we check the vertical distance between the two characters.


28869  LD E,A  E=horizontal distance between Sam and the policeman  
28870  LD L,2  Point HL at byte 2 of the policeman's buffer  
28872  LD A,(58882)  A=Sam's ycoordinate  
28875  SUB (HL)  Subtract the policeman's ycoordinate  
28876  JR NC,28880  Jump if the policeman's ycoordinate is less than or equal to Sam's  
28878  NEG  
28880  LD D,A  D=vertical distance between Sam and the policeman  
28881  ADD A,E  Add the horizontal distance between Sam and the policeman  
28882  CP 33  Set the carry flag if the result is less than 33  
28884  RET 
Prev: 28841  Up: Map  Next: 28885 