Prev: 6D31 Up: Map Next: 6D62
6D32: Check whether a target character can be seen by another character
Used by the routines at 6D62 and 6D7D. This routine checks through B' 'spotter' characters starting with character H'. If any spotter is close enough to the target to be able to see it, the routine returns with A holding a non-zero value, H holding the spotter's character number, and the carry flag set if the spotter is facing the right way to see it (reset otherwise). If no spotters are close enough to the target to be able to see it, the routine returns with A holding 0 and the carry flag reset.
Input
B Upper x-coordinate of the target range
C Lower x-coordinate of the target range
D Target character's y-coordinate
E Target character's x-coordinate
B' Number of spotters to check
H' Character number of the first spotter to check
6D32 EXX
6D33 LD L,$02 Pick up the spotter's coordinates in DE'; we are going to check whether this character can see the target
6D35 LD D,(HL)
6D36 DEC L
6D37 LD E,(HL)
6D38 LD A,D Transfer the spotter's y-coordinate to A
6D39 EXX
6D3A SUB D Subtract the target's y-coordinate
6D3B JR NC,$6D3F Jump if the spotter is below or level with the target
6D3D NEG
6D3F CP $04 Is the spotter within 3 y-coordinates of the target?
6D41 JR NC,$6D4C Jump if not
6D43 EXX
6D44 LD A,E A=spotter's x-coordinate
6D45 EXX
6D46 CP C Compare this with the lower and upper limits of the range within which the target can be seen, and jump to 6D53 if the spotter is within seeing range
6D47 JR C,$6D4C
6D49 CP B
6D4A JR C,$6D53
This entry point is used by the routine at 6D62.
6D4C EXX
This entry point is used by the routine at 6D7D.
6D4D INC H The last spotter was not within seeing range of the target; try the next spotter
6D4E DJNZ $6D33
6D50 EXX
6D51 XOR A Signal: none of the spotters was within range
6D52 RET
We've found a spotter within seeing range of the target. But is he facing the right way?
6D53 CP E Does the spotter's x-coordinate match the target's?
6D54 JR Z,$6D5F Jump if so
6D56 LD A,$00 The carry flag is now set if the spotter is to the left of the target
6D58 RRA A=0x80 if the spotter is to the left of the target, 0x00 if to the right
6D59 EXX
6D5A LD L,$00 Point HL' at the spotter's animatory state
6D5C XOR (HL) Compare this orientation with the direction in which the spotter is facing
6D5D EXX
6D5E RLCA
6D5F CCF Set the carry flag if the spotter's facing the right way to see the target
6D60 LD A,B Set A to something non-zero to indicate that the spotter was within range
6D61 RET
Prev: 6D31 Up: Map Next: 6D62