Prev: D4A7 Up: Map Next: D4EF
D4CC: Count Objects In Location
Input
A Location ID (or FF for current character location)
Output
A Count of visible objects found in the specified location
CountObjectsInLocation D4CC PUSH IX Stash IX, IY, HL and BC on the stack.
D4CE PUSH IY
D4D0 PUSH HL
D4D1 PUSH BC
D4D2 CALL AdjustObjectTableForSum Call AdjustObjectTableForSum to set up the object table pointer.
D4D5 LD B,$00 Initialise the object counter in B to zero.
D4D7 LD C,A Store the location ID in C for later use.
CountObjectsInLocation_Loop D4D8 CALL FetchNextObject Call FetchNextObject.
D4DB JR Z,CountObjectsInLocation_End Jump to CountObjectsInLocation_End if we've reached the end of the object table (FF).
D4DD LD A,C Restore the location ID from C into A.
D4DE CALL CheckObjectMatchCriteria Call CheckObjectMatchCriteria to check if this object matches the location and visibility criteria.
Skip this object if it doesn't match the criteria (carry flag not set).
D4E1 JR NC,CountObjectsInLocation_Loop Jump back to CountObjectsInLocation_Loop to continue checking objects if this one doesn't match.
This object matches the criteria, so count it.
D4E3 INC B Increment the object counter in B by one.
D4E4 JR CountObjectsInLocation_Loop Jump back to CountObjectsInLocation_Loop to check the next object.
CountObjectsInLocation_End D4E6 LD A,B Transfer the object count from B to A.
D4E7 AND A Set flags based on the count (zero flag set if no objects found).
D4E8 POP BC Restore BC, HL, IY and IX from the stack.
D4E9 POP HL
D4EA POP IY
D4EC POP IX
D4EE RET Return.
Prev: D4A7 Up: Map Next: D4EF