Prev: 8566 Up: Map Next: 85B2
8598: A random coordinate near the middle of the room
Used by the routine at SPAWN_MONSTER_INTO_ROOM.
Returns $60 plus or minus (R modulo the limit in B less 8), the sign from another bit of R. SPAWN_MONSTER_INTO_ROOM calls it once for x and once for y with the room's half-extents, so a new creature appears somewhere inside the walk area. It also steps HL on, to the next field.
RANDOM_POSITION 8598 LD A,B
8599 SUB $08
859B LD B,A
859C LD A,R
859E INC HL
RANDOM_POSITION_0 859F CP B
85A0 JR C,RANDOM_POSITION_1
85A2 SUB B
85A3 JR RANDOM_POSITION_0
RANDOM_POSITION_1 85A5 LD C,A
85A6 LD A,R
85A8 BIT 1,A
85AA LD A,$60
85AC JR Z,RANDOM_POSITION_2
85AE ADD A,C
85AF RET
RANDOM_POSITION_2 85B0 SUB C
85B1 RET
Prev: 8566 Up: Map Next: 85B2