Prev: 6E90 Up: Map Next: 6EDC
6EA7: Get the x-coordinate range within which a character can see or be seen
Used by the routines at 6E3C and 78AA. Returns with C and B holding the lower and upper x-coordinates of the range within which the target character can see or be seen. This routine is called with DE holding either (a) the coordinates of a teacher (to determine where kids must be in order to get lines), or (b) the coordinates of a kid (to determine where a teacher must be in order to give lines).
Input
D Target character's floor: 0x9B (top), 0xA2 (middle) or 0xA9 (bottom)
E Target character's x-coordinate
6EA7 LD A,E A=x (character's x-coordinate)
6EA8 LD BC,$6000 B=0x60, C=0x00 (maximum and minimum bounds)
6EAB SUB $0A Is the character's x-coordinate < 10?
6EAD JR C,$6EC4 Jump if so
6EAF LD C,A C=x-10
6EB0 LD A,D A=floor nearest to the character
6EB1 CP $A9 Is the character nearest the bottom floor?
6EB3 JR Z,$6EC4 Jump if so
6EB5 CP $A2 Set the zero flag if the character is nearest the middle floor
6EB7 LD A,$26 This is the x-coordinate of the Exam Room wall
6EB9 JR Z,$6EBD Jump if the character is nearest the middle floor
6EBB LD A,$39 This is the x-coordinate of the Map Room wall
6EBD CP C Is the character more than 10 paces to the right of a wall?
6EBE JR C,$6EC4 Jump if so
6EC0 CP E Is the character to the left of a wall?
6EC1 JR NC,$6EC4 Jump if so
6EC3 LD C,A C=x-coordinate of the wall that the character is within 10 paces to the right of
Now C holds the lower x-coordinate of the visibility range. Time to calculate the upper x-coordinate.
6EC4 LD A,E A=x (character's x-coordinate)
6EC5 ADD A,$0A A=x+10
6EC7 CP B Is the character within 10 paces of the far right wall?
6EC8 RET NC Return if so
6EC9 LD B,A B=x+10
6ECA LD A,D A=floor nearest to the character
6ECB CP $A9 Is the character nearest the bottom floor?
6ECD RET Z Return if so
6ECE CP $A2 Set the zero flag if the character is nearest the middle floor
6ED0 LD A,$25 This is the x-coordinate of the White Room wall
6ED2 JR Z,$6ED6 Jump if the character is nearest the middle floor
6ED4 LD A,$38 This is the x-coordinate of the Reading Room wall
6ED6 CP B Is the character more than 10 paces to the left of a wall?
6ED7 RET NC Return if so
6ED8 CP E Is the character to the right of a wall?
6ED9 RET C Return if so
6EDA LD B,A B=x-coordinate of the wall
6EDB RET
Prev: 6E90 Up: Map Next: 6EDC