![]() |
Routines |
| Prev: B107 | Up: Map | Next: B1C7 |
|
This tests whether the position in saved_pos_x touches any wall or fence boundary.
A position (x,y,h) touches a wall if (minx + 2 >= x <= maxx + 3) and (miny >= y <= maxy + 3) and (minh >= h <= maxh + 1).
Used by the routines at touch and spawn_character.
|
||||||||||||
| bounds_check | B14C | LD A,($68A0) | Get the global current room index | |||||||||
|
Interior boundaries are handled by another routine.
|
||||||||||||
| B14F | AND A | Is it indoors? | ||||||||||
| B150 | JP NZ,interior_bounds_check | Use the interior bounds check routine instead, if so (exit via) | ||||||||||
| B153 | LD B,$18 | 24 iterations / 24 wall definitions | ||||||||||
| B155 | LD DE,$B53E | Point DE at the first wall definition | ||||||||||
|
Start loop
|
||||||||||||
| bounds_loop | B158 | PUSH BC | Preserve the loop counter | |||||||||
| B159 | PUSH DE | Preserve the wall definition pointer | ||||||||||
|
Check against minimum X
|
||||||||||||
| B15A | LD A,(DE) | Read minimum x | ||||||||||
| B15B | CALL multiply_by_8 | Multiply it by 8 returning the result in BC | ||||||||||
| B15E | INC BC | And add two | ||||||||||
| B15F | INC BC | |||||||||||
| B160 | LD HL,($81A4) | Read saved_pos_x | ||||||||||
| B163 | SBC HL,BC | Compute saved_pos_x - ((wall minimum x) * 8 + 2) | ||||||||||
| B165 | JR C,bounds_next | Jump to the next iteration if saved_pos_x is left of minimum x | ||||||||||
|
Check against maximum X
|
||||||||||||
| B167 | INC DE | Move to maximum x field | ||||||||||
| B168 | LD A,(DE) | Read maximum x | ||||||||||
| B169 | CALL multiply_by_8 | Multiply it by 8 returning the result in BC | ||||||||||
| B16C | INC BC | And add four | ||||||||||
| B16D | INC BC | |||||||||||
| B16E | INC BC | |||||||||||
| B16F | INC BC | |||||||||||
| B170 | LD HL,($81A4) | Re-read saved_pos_x | ||||||||||
| B173 | SBC HL,BC | Compute saved_pos_x - ((wall maximum x) * 8 + 4) | ||||||||||
| B175 | JR NC,bounds_next | Jump to next iteration if saved_pos_x is right of maximum x | ||||||||||
|
Check against minimum Y
|
||||||||||||
| B177 | INC DE | Move to minimum y field | ||||||||||
| B178 | LD A,(DE) | Read minimum y | ||||||||||
| B179 | CALL multiply_by_8 | Multiply it by 8 returning the result in BC | ||||||||||
| B17C | LD HL,($81A6) | Read saved_pos_y | ||||||||||
| B17F | SBC HL,BC | Compute saved_pos_y - ((wall minimum y) * 8) | ||||||||||
| B181 | JR C,bounds_next | Jump to the next iteration if saved_pos_y is below minimum y | ||||||||||
|
Check against maximum Y
|
||||||||||||
| B183 | INC DE | Move to maximum y field | ||||||||||
| B184 | LD A,(DE) | Read maximum y | ||||||||||
| B185 | CALL multiply_by_8 | Multiply it by 8 returning the result in BC | ||||||||||
| B188 | INC BC | And add four | ||||||||||
| B189 | INC BC | |||||||||||
| B18A | INC BC | |||||||||||
| B18B | INC BC | |||||||||||
| B18C | LD HL,($81A6) | Re-read saved_pos_y | ||||||||||
| B18F | SBC HL,BC | Compute saved_pos_y - ((wall maximum y) * 8 + 4) | ||||||||||
| B191 | JR NC,bounds_next | Jump to next iteration if saved_pos_y is above maximum y | ||||||||||
|
Check minimum height
|
||||||||||||
| B193 | INC DE | Move to minimum height field | ||||||||||
| B194 | LD A,(DE) | Read minimum height | ||||||||||
| B195 | CALL multiply_by_8 | Multiply it by 8 returning the result in BC | ||||||||||
| B198 | LD HL,($81A8) | Read saved_height | ||||||||||
| B19B | SBC HL,BC | Compute saved_height - ((wall minimum height) * 8) | ||||||||||
| B19D | JR C,bounds_next | Jump to the next iteration if saved_height is below minimum height | ||||||||||
|
Check maximum height
|
||||||||||||
| B19F | INC DE | Move to maximum height field | ||||||||||
| B1A0 | LD A,(DE) | Read maximum height | ||||||||||
| B1A1 | CALL multiply_by_8 | Multiply it by 8 returning the result in BC | ||||||||||
| B1A4 | INC BC | And add two | ||||||||||
| B1A5 | INC BC | |||||||||||
| B1A6 | LD HL,($81A8) | Re-read saved_height | ||||||||||
| B1A9 | SBC HL,BC | Compute saved_height - ((wall maximum height) * 8) | ||||||||||
| B1AB | JR NC,bounds_next | Jump to the next iteration if saved_height is above maximum height | ||||||||||
|
Passed all checks - in contact with wall
|
||||||||||||
| B1AD | POP DE | Restore the wall definition pointer | ||||||||||
| B1AE | POP BC | Restore the loop counter | ||||||||||
| B1AF | LD A,(IY+$07) | Toggle counter_and_flags vischar_BYTE7_Y_DOMINANT flag | ||||||||||
| B1B2 | XOR $20 | |||||||||||
| B1B4 | LD (IY+$07),A | |||||||||||
| B1B7 | OR $01 | Clear Z flag | ||||||||||
| B1B9 | RET | Return with Z clear | ||||||||||
| bounds_next | B1BA | POP DE | Restore the wall definition pointer | |||||||||
| B1BB | POP BC | Restore the loop counter | ||||||||||
| B1BC | LD HL,$0006 | Set the wall definition stride | ||||||||||
| B1BF | ADD HL,DE | Point to next wall definition | ||||||||||
| B1C0 | EX DE,HL | Move the wall definition pointer into DE | ||||||||||
| B1C1 | DEC B | ...loop | ||||||||||
| B1C2 | JP NZ,bounds_loop | |||||||||||
| B1C5 | AND B | B is zero, AND it with itself to set Z flag | ||||||||||
| B1C6 | RET | Return with Z set | ||||||||||
| Prev: B107 | Up: Map | Next: B1C7 |