B | Upper limit of range |
C | Lower limit of range |
D | y-coordinate of target character |
E | x-coordinate of target character |
B' | Number of characters to test |
H' | Number of first character to check eyesight of |
27954 | D9 | EXX | |
27955 | 2E02 | LD L,2 | |
27957 | 56 | LD D,(HL) | D=character's y-coordinate |
27958 | 2D | DEC L | |
27959 | 5E | LD E,(HL) | E=character's x-coordinate |
27960 | 7A | LD A,D | Transfer y-coordinate to A |
27961 | D9 | EXX | |
27962 | 92 | SUB D | Subtract target's y-coordinate |
27963 | 3002 | JR NC,27967 | Jump if character is below or level with the target |
27965 | ED44 | NEG | |
27967 | FE04 | CP 4 | Is the character within 4 vertical character spaces of the target? |
27969 | 3009 | JR NC,27980 | Jump if not |
27971 | D9 | EXX | |
27972 | 7B | LD A,E | A=x-coordinate of character |
27973 | D9 | EXX | |
27974 | B9 | CP C | Compare this with the lower limit and upper limits of the range within which the target can be seen, and jump to 27987 if the character is within seeing range |
27975 | 3803 | JR C,27980 | |
27977 | B8 | CP B | |
27978 | 3807 | JR C,27987 | |
27980 | D9 | EXX |
27981 | 24 | INC H | The last character was not even within seeing range of the target. Try the next character |
27982 | 10E3 | DJNZ 27955 | |
27984 | D9 | EXX | |
27985 | AF | XOR A | Signal: none of the characters was within range |
27986 | C9 | RET |
27987 | BB | CP E | Does the character's x-coordinate match the target's? |
27988 | 2809 | JR Z,27999 | Jump if so |
27990 | 3E00 | LD A,0 | The carry flag is now set if the character is to the left of the target |
27992 | 1F | RRA | A=128 if character is to left of target, 0 if to right |
27993 | D9 | EXX | |
27994 | 2E00 | LD L,0 | HL points to the character's animatory state |
27996 | AE | XOR (HL) | Compare this orientation with the direction in which the character's facing |
27997 | D9 | EXX | |
27998 | 07 | RLCA | |
27999 | 3F | CCF | Set the carry flag if the character's facing the right way to see target |
28000 | 78 | LD A,B | Set A to something non-zero |
28001 | C9 | RET |