Prev: 9D50 Up: Map Next: 9DBD
9D97: Condition: Count The Visible Objects
Counts the visible objects at the location or container in A. A character id counts what that character holds. An object is visible when bit 7 of its attribute byte is set.
Input
A Location or container id (the character id counts objects held)
Output
A The number of objects
ObjectCount 9D97 PUSH IX Initialise the object count.
9D99 PUSH IY
9D9B PUSH BC
9D9C LD B,$00
9D9E LD IX,$C060 Use the slot before the object table as this object.
ObjectCount_Loop 9DA2 CALL Table_FindTheRecord Call Table_FindTheRecord to fetch the next record in IY.
9DA5 JR Z,ObjectCount_End Jump to ObjectCount_End at the end of the object index.
9DA7 CP (IY+$01) Jump back to ObjectCount_Loop without counting this object if its location is not the id in A.
9DAA JR NZ,ObjectCount_Loop
9DAC BIT 7,(IY+$07) Jump back to ObjectCount_Loop without counting this object if it is not visible.
9DB0 JR Z,ObjectCount_Loop
9DB2 INC B Count one more object.
9DB3 JP ObjectCount_Loop Jump back to ObjectCount_Loop to find the record.
ObjectCount_End 9DB6 LD A,B Store the object count in A.
9DB7 POP BC Restore BC, IY and IX from the stack.
9DB8 POP IY
9DBA POP IX
9DBC RET Return.
View the equivalent code in;
Prev: 9D50 Up: Map Next: 9DBD