Prev: 8A80 Up: Map Next: 8AFF
8ADB: Find Item In Room
Used by the routine at HandlerHunchback.
Searches the eight records that start at ItemEntity_Wine for one that is in use and is in the same room as an entity. The records have eight bytes each, laid out in the same way as an entity.
Input
IX The entity
Output
C 01 if a record was found, otherwise 00
DE The position of the record that was found (X in E and Y in D)
HL The address of the Y position of the record that was found
FindItemInRoom 8ADB LD HL,$EB18 Point HL at the first of the item records at ItemEntity_Wine.
8ADE LD DE,$0008 DE=0008 (the size of each record).
8AE1 LD B,$08 B=08 (the number of records to look at).
FindItemInRoom_Loop 8AE3 PUSH HL Stash the address of the record on the stack.
8AE4 LD A,(HL) Fetch the sprite ID of the record.
8AE5 AND A Test whether the record is in use.
8AE6 JR Z,FindItemInRoom_Next Jump to FindItemInRoom_Next if it is not.
8AE8 INC HL Move HL on to the room of the record.
8AE9 LD A,(HL) Fetch the room of the record.
8AEA CP (IX+$01) Compare it with the room of the entity.
8AED JR NZ,FindItemInRoom_Next Jump to FindItemInRoom_Next if they are different.
8AEF POP DE Restore the address of the record into DE.
8AF0 INC HL Move HL on to the X position of the record.
8AF1 INC HL
8AF2 LD E,(HL) Fetch the X position of the record.
8AF3 INC HL Move HL on to the Y position of the record.
8AF4 LD D,(HL) Fetch the Y position of the record.
8AF5 LD C,$01 Set the result in C to 01 (found).
8AF7 RET Return.
FindItemInRoom_Next 8AF8 POP HL Restore the address of the record from the stack.
8AF9 ADD HL,DE Move HL on to the next record.
8AFA DJNZ FindItemInRoom_Loop Decrease the record counter by one and loop back to FindItemInRoom_Loop until all eight records have been checked.
8AFC LD C,$00 Set the result in C to 00 (not found).
8AFE RET Return.
Prev: 8A80 Up: Map Next: 8AFF