| Routines

28240: Check whether a character is on a staircase

Used by the routines at 23887, 24263, 28436, 28460, 28484, 28576, 28992 and 62423 to check whether ERIC is on a staircase, and by the routines at 25843 and 25944 to check whether ERIC or a teacher is on a staircase. Returns with the carry flag reset if the character is not on a staircase. Otherwise returns with the carry flag set and A holding 0 (if the staircase goes up and to the left) or 128 (if the staircase goes up and to the right).
Input
H | Character number (200-204, 210)
28240 | LD H,210 | 210=ERIC
This entry point is used by the routines at 25843 and 25944.
28242 | LD L,1 | Collect the character's coordinates in DE
28244 | LD E,(HL)
28245 | INC L
28246 | LD D,(HL)
28247 | LD A,D | A=character's y-coordinate
28248 | CP 3 | Is the character on the top floor?
28250 | RET Z | Return with the carry flag reset if so
28251 | CP 10 | Is the character on the middle floor?
28253 | RET Z | Return with the carry flag reset if so
28254 | CP 17 | Is the character on the bottom floor?
28256 | RET Z | Return with the carry flag reset if so
28257 | CP 14 | The assembly hall stage has y-coordinate 14
28259 | JR NZ,28269 | Jump if the character's y-coordinate doesn't match that
28261 | LD A,E | A=character's x-coordinate
28262 | CP 82 | This is the x-coordinate of the right-hand edge of the assembly hall stage
28264 | JR NC,28269 | Jump if the character's to the right of this
28266 | CP 76 | This is the x-coordinate of the left-hand edge of the assembly hall stage
28268 | RET NC | Return with the carry flag reset if the character's on the stage
The character is not standing on the top floor, middle floor, bottom floor or assembly hall stage, so he must be on a staircase. Determine the orientation of the staircase.
28269 | LD A,D | A=character's y-coordinate
28270 | CP 10 | Is the character somewhere between the middle and bottom floors?
28272 | JR NC,28287 | Jump if so
28274 | LD A,E | A=character's x-coordinate
28275 | CP 64 | Is the character on the stairs leading up to the Revision Library?
28277 | JR C,28283 | Jump if so
28279 | LD A,0 | Signal: character is on an up-and-to-the-left staircase
28281 | SCF | Signal: character's on a staircase
28282 | RET | Return with the carry flag set and A=0
28283 | LD A,128 | Signal: character is on an up-and-to-the-right staircase
28285 | SCF | Signal: character's on a staircase
28286 | RET | Return with the carry flag set and A=128
28287 | CP 15 |
28289 | LD A,E | A=character's x-coordinate
28290 | JR C,28298 | Jump if the character is on or above the level of the assembly hall stage
28292 | CP 128 | Is the character on either the stairs leading down from the stage or the stairs leading down from the toilets in the boys' skool?
28294 | JR C,28279 | Jump if so
28296 | JR 28283 | The character is on the stairs leading down to the bottom floor in the girls' skool
28298 | CP 64 | Is the character on either the stairs leading down to the stage or the stairs leading down to the bottom floor in the girls' skool?
28300 | JR NC,28283 | Jump if so
28302 | LD A,0 | Signal: character is on an up-and-to-the-left staircase (the one leading down from the toilets in the boys' skool, in fact)
28304 | RET | Return with the carry flag set and A=0