Prev: 28304 Up: Map Next: 28380
28327: Get the x-coordinate range within which a character can see or be seen
Used by the routines at 28220 and 30890. 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: 155 (top), 162 (middle) or 169 (bottom)
E Target character's x-coordinate
28327 LD A,E A=x (character's x-coordinate)
28328 LD BC,24576 B=96, C=0 (maximum and minimum bounds)
28331 SUB 10 Is the character's x-coordinate < 10?
28333 JR C,28356 Jump if so
28335 LD C,A C=x-10
28336 LD A,D A=floor nearest to the character
28337 CP 169 Is the character nearest the bottom floor?
28339 JR Z,28356 Jump if so
28341 CP 162 Set the zero flag if the character is nearest the middle floor
28343 LD A,38 This is the x-coordinate of the Exam Room wall
28345 JR Z,28349 Jump if the character is nearest the middle floor
28347 LD A,57 This is the x-coordinate of the Map Room wall
28349 CP C Is the character more than 10 paces to the right of a wall?
28350 JR C,28356 Jump if so
28352 CP E Is the character to the left of a wall?
28353 JR NC,28356 Jump if so
28355 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.
28356 LD A,E A=x (character's x-coordinate)
28357 ADD A,10 A=x+10
28359 CP B Is the character within 10 paces of the far right wall?
28360 RET NC Return if so
28361 LD B,A B=x+10
28362 LD A,D A=floor nearest to the character
28363 CP 169 Is the character nearest the bottom floor?
28365 RET Z Return if so
28366 CP 162 Set the zero flag if the character is nearest the middle floor
28368 LD A,37 This is the x-coordinate of the White Room wall
28370 JR Z,28374 Jump if the character is nearest the middle floor
28372 LD A,56 This is the x-coordinate of the Reading Room wall
28374 CP B Is the character more than 10 paces to the left of a wall?
28375 RET NC Return if so
28376 CP E Is the character to the right of a wall?
28377 RET C Return if so
28378 LD B,A B=x-coordinate of the wall
28379 RET
Prev: 28304 Up: Map Next: 28380