| Routines

64162: Check whether a falling character has hit anyone on the head

Used by the routine at 64227. Returns with the zero flag set if the falling character has struck another character, and knocks that other character over.
Input
H | Character number (215-230)
64162 | LD L,1 | Point HL at byte 1 of the falling character's buffer
64164 | LD E,(HL) | E=falling character's x-coordinate
64165 | DEC E | Decrement this
64166 | INC L | L=2
64167 | LD D,(HL) | D=falling character's y-coordinate
64168 | INC D | Add 3 to this
64169 | INC D
64170 | INC D
64171 | LD HL,55042 | H=215 (first potential target character to check), L=2
The following loop compares the falling character's coordinates with those of every other character to see if there was a collision.
64174 | LD A,D | A=3+falling character's y-coordinate
64175 | CP (HL) | Does it match the potential target's y-coordinate?
64176 | JR NZ,64208 | Jump if not to check the next potential target
64178 | DEC L | L=1
64179 | LD A,(HL) | A=T (potential target character's x-coordinate)
64180 | SUB E | A=T-x+1 (where x is the falling character's x-coordinate)
64181 | CP 3 | Is this less than 3?
64183 | JR NC,64206 | Jump if not to check the next potential target
64185 | LD BC,64005 | Point BC at the uninterruptible subcommand routine at 64005
64188 | RRCA | Does T=x?
64189 | JR NC,64193 | Jump if not
64191 | LD C,9 | BC=64009
64193 | DEC L | L=0
64194 | LD A,(HL) | A=target character's animatory state
64195 | AND 7 | Keep only bits 0-2
64197 | CP 4 | Is the target character in standing/walking animation phase 1-4?
64199 | JR NC,64206 | Jump if not to check the next potential target
64201 | LD A,H | A=target character's character number
64202 | CALL 63981 | Attempt to place the address of the uninterruptible subcommand routine at 64005 (if T=x-1 or x+1) or 64009 (if T=x) into bytes 18 and 19 of the target character's buffer
64205 | RET Z | Return with the zero flag set if the attempt was successful (the target character was not already occupied by some other uninterruptible subcommand)
64206 | LD L,2 | Point HL at byte 2 of the target character's buffer
64208 | INC H | Next potential target character to check
64209 | LD A,H | A=next target character number
64210 | CP 231 | Have we checked every potential target?
64212 | JR NZ,64174 | Jump back if not
64214 | ADD A,A | Reset the zero flag (no one was struck by the falling character)
64215 | RET |