Routines |
Prev: B295 | Up: Map | Next: B2FC |
This checks that the character is inside of bounds, when indoors.
Used by the routine at bounds_check.
|
||||||||||||
interior_bounds_check | B29F | LD A,($81BE) | Fetch index into room dimensions (roomdef_bounds_index) | |||||||||
Point BC at roomdef_dimensions[roomdef_bounds_index]
|
||||||||||||
B2A2 | ADD A,A | Multiply index by the size of a bounds (4) | ||||||||||
B2A3 | ADD A,A | |||||||||||
B2A4 | LD BC,$6B85 | Point BC at roomdef_dimensions[0] | ||||||||||
B2A7 | ADD A,C | Combine BC with the scaled index | ||||||||||
B2A8 | LD C,A | |||||||||||
B2A9 | JR NC,interior_bounds_check_0 | |||||||||||
B2AB | INC B | |||||||||||
Check X axis
Note that the room dimensions are given in an unusual order: x1, x0, y1, y0.
|
||||||||||||
interior_bounds_check_0 | B2AC | LD HL,$81A4 | Point HL at saved_pos | |||||||||
B2AF | LD A,(BC) | Fetch bounds.x1 | ||||||||||
B2B0 | CP (HL) | Compare bounds.x1 with saved_pos_x | ||||||||||
B2B1 | JR C,stop | If bounds.x1 < saved_pos_x jump to 'stop' | ||||||||||
B2B3 | INC BC | Fetch bounds.x0 | ||||||||||
B2B4 | LD A,(BC) | |||||||||||
B2B5 | ADD A,$04 | Add 4 | ||||||||||
B2B7 | CP (HL) | Compare (bounds.x0 + 4) with saved_pos_x | ||||||||||
B2B8 | JR NC,stop | If (bounds.x0 + 4) >= saved_pos_x jump to 'stop' | ||||||||||
B2BA | INC HL | Advance HL to saved_pos_y | ||||||||||
B2BB | INC HL | |||||||||||
Bug: The next instruction is stray code. DE is incremented but never used.
|
||||||||||||
B2BC | INC DE | (bug) | ||||||||||
Check Y axis
|
||||||||||||
B2BD | INC BC | Point BC at bounds.y1 | ||||||||||
B2BE | LD A,(BC) | Fetch bounds.y1 | ||||||||||
B2BF | SUB $04 | Subtract 4 | ||||||||||
B2C1 | CP (HL) | Compare (bounds.y1 - 4) with saved_pos_y | ||||||||||
B2C2 | JR C,stop | If (bounds.y1 - 4) < saved_pos_y jump to 'stop' | ||||||||||
B2C4 | INC BC | Point BC at bounds.y0 | ||||||||||
B2C5 | LD A,(BC) | Fetch bounds.y0 | ||||||||||
B2C6 | CP (HL) | Compare bounds.y0 with saved_pos_y | ||||||||||
B2C7 | JR NC,stop | If bounds.y0 >= saved_pos_y jump to 'stop' | ||||||||||
Bomb out if there are no bounds to consider.
|
||||||||||||
B2C9 | LD HL,$81BF | Point HL at roomdef_object_bounds_count | ||||||||||
B2CC | LD B,(HL) | Fetch the count of object bounds | ||||||||||
B2CD | LD A,B | Move it to A so we can test it | ||||||||||
B2CE | AND A | Is the count zero? | ||||||||||
B2CF | RET Z | Return with Z set if so | ||||||||||
B2D0 | INC HL | Step over to roomdef_object_bounds | ||||||||||
Start loop (outer)
|
||||||||||||
interior_bounds_check_1 | B2D1 | PUSH BC | Preserve the loop counter | |||||||||
B2D2 | PUSH HL | Preserve the bounds pointer | ||||||||||
B2D3 | LD DE,$81A4 | Point HL at saved_pos | ||||||||||
B2D6 | LD B,$02 | 2 iterations - once per axis | ||||||||||
Start loop (inner)
|
||||||||||||
interior_bounds_check_2 | B2D8 | LD A,(DE) | Fetch saved_pos_x, or saved_pos_y on the second pass | |||||||||
B2D9 | CP (HL) | Is it less than the lower bound? | ||||||||||
B2DA | JR C,next | Jump to the next iteration if so | ||||||||||
B2DC | INC HL | Step to the upper bound | ||||||||||
B2DD | CP (HL) | Is it greater or equal to the upper bound? | ||||||||||
B2DE | JR NC,next | Jump to the next iteration if so | ||||||||||
B2E0 | INC DE | Step to the next saved_pos axis | ||||||||||
B2E1 | INC DE | |||||||||||
B2E2 | INC HL | Step to the next bound axis | ||||||||||
B2E3 | DJNZ interior_bounds_check_2 | ...loop (inner) | ||||||||||
Found.
|
||||||||||||
B2E5 | POP HL | Restore the bounds pointer | ||||||||||
B2E6 | POP BC | Restore the loop counter | ||||||||||
Toggle movement direction preference.
|
||||||||||||
stop | B2E7 | LD A,(IY+$07) | Fetch IY->counter_and_flags | |||||||||
B2EA | XOR $20 | Toggle vischar_BYTE7_Y_DOMINANT | ||||||||||
B2EC | LD (IY+$07),A | Store IY->counter_and_flags | ||||||||||
B2EF | OR $01 | Clear Z flag | ||||||||||
B2F1 | RET | Return with Z clear | ||||||||||
Next iteration.
|
||||||||||||
next | B2F2 | POP HL | Restore the bounds pointer | |||||||||
B2F3 | LD DE,$0004 | Advance to next bound | ||||||||||
B2F6 | ADD HL,DE | |||||||||||
B2F7 | POP BC | Restore the loop counter | ||||||||||
B2F8 | DJNZ interior_bounds_check_1 | ...loop (outer) | ||||||||||
Not found.
|
||||||||||||
B2FA | AND B | B is zero, AND it with itself to set Z flag | ||||||||||
B2FB | RET | Return with Z set |
Prev: B295 | Up: Map | Next: B2FC |