Prev: D026 Up: Map Next: DBEB
DB9E: Mark nearby items
This iterates over itemstructs, testing to see if each item is within the range (-1..22, 0..15) of the current map position. If it is it sets the flags itemstruct_ROOM_FLAG_NEARBY_6 and itemstruct_ROOM_FLAG_NEARBY_7 on the item, otherwise it clears both of those flags.
This is similar to is_item_discoverable_interior in that it iterates over all item_structs.
Used by the routines at setup_movable_items and main_loop.
mark_nearby_items DB9E LD A,($68A0) Get the global current room index
DBA1 CP $FF Is it room_NONE?
DBA3 JR NZ,mni_room_set Jump if not
DBA5 XOR A Otherwise set it to room_0_OUTDOORS
mni_room_set DBA6 LD C,A Preload the room index into C
DBA7 LD DE,($81BB) Point DE at the map position
DBAB LD B,$10 Set B for 16 iterations (item__LIMIT)
DBAD LD HL,$76C9 Point HL at the first item_struct's room member
Start loop
mni_loop DBB0 PUSH HL Preserve item_struct pointer
Compare room
DBB1 LD A,(HL) Load the room index and flags
DBB2 AND $3F Extract the room index
DBB4 CP C Same room?
DBB5 JR NZ,mni_reset Jump if not
Is the item's X coordinate within (-1..22) of the map's X position?
DBB7 INC HL Advance HL to itemstruct.iso_pos.x
DBB8 INC HL
DBB9 INC HL
DBBA INC HL
DBBB LD A,E Copy map X position into A
DBBC DEC A Reduce it by 2
DBBD DEC A
DBBE CP (HL) Compare it to itemstruct.iso_pos.x
DBBF JR Z,mni_chk_x_hi Jump if equal (continuing test)
DBC1 JR NC,mni_reset Reset if under lower bound
mni_chk_x_hi DBC3 ADD A,$19 Add 25 to make (map X position + 23)
DBC5 CP (HL) Compare to X value in itemstruct
DBC6 JR C,mni_reset Reset if over upper bound
Is the item's Y coordinate within (0..15) of the map's Y position?
DBC8 LD A,D Copy map Y position into A
DBC9 INC HL Advance HL to itemstruct.iso_pos.y
DBCA DEC A Reduce it by 1
DBCB CP (HL) Compare it to itemstruct.iso_pos.y
DBCC JR Z,mni_chk_y_hi Jump if equal (continuing test)
DBCE JR NC,mni_reset Reset if under lower bound
mni_chk_y_hi DBD0 ADD A,$11 Add 17 to make (map Y position + 16)
DBD2 CP (HL) Compare to Y value in itemstruct
DBD3 JR C,mni_reset Reset if over upper bound
mni_set DBD5 POP HL Restore itemstruct pointer
DBD6 SET 7,(HL) Set itemstruct_ROOM_FLAG_NEARBY_6 and itemstruct_ROOM_FLAG_NEARBY_7
DBD8 SET 6,(HL)
DBDA JR mni_advance Jump to next iteration
mni_reset DBDC POP HL Restore itemstruct pointer
DBDD RES 7,(HL) Clear itemstruct_ROOM_FLAG_NEARBY_6 and itemstruct_ROOM_FLAG_NEARBY_7
DBDF RES 6,(HL)
mni_advance DBE1 LD A,$07 Advance HL by stride
DBE3 ADD A,L
DBE4 LD L,A
DBE5 JR NC,mni_next
DBE7 INC H
mni_next DBE8 DJNZ mni_loop ...loop
DBEA RET Return
Prev: D026 Up: Map Next: DBEB