Routines 
Prev: 6D62  Up: Map  Next: 6DA3 
Used by the routine at 7596. Returns with the character number of the nearest main kid (or 0 if none of them was close enough) in A.


6D7D  CALL $6CEE  Get the lower and upper xcoordinates of the teacher's range of vision in C and B  
6D80  LD L,$00  Default assumption: no kids nearby  
6D82  EXX  
6D83  LD H,$CE  0xCE=BOY WANDER  
6D85  LD BC,$05FF  B'=5 (main kids including ERIC), C'=255 (initial value for the distance of the nearest main kid)  
6D88  EXX  
6D89  CALL $6D32  Find the first main kid within range (if any)  
6D8C  AND A  Set the zero flag if we've checked all the main kids  
6D8D  LD A,L  A=character number of the nearest kid so far, or 0 if there are none  
6D8E  RET Z  Return if we've finished checking all the main kids  
6D8F  LD A,E  A=teacher's xcoordinate  
6D90  EXX  
6D91  SUB E  Subtract the xcoordinate of the kid  
6D92  JR NC,$6D96  Jump if the kid's to the left of teacher  
6D94  NEG  
6D96  CP C  Is this kid closer to the teacher than the last?  
6D97  JR NC,$6D9E  Jump if not  
6D99  LD C,A  C'=distance from the teacher of the nearest kid found so far  
6D9A  LD A,H  A=character number of this kid  
6D9B  EXX  
6D9C  LD L,A  Store the character number of the nearest kid in L  
6D9D  EXX  
6D9E  CALL $6D4D  Find the next main kid within range (if any)  
6DA1  JR $6D8C  Jump back to compare distances 
Prev: 6D62  Up: Map  Next: 6DA3 