Prev: AE96 Up: Map Next: AF05
AE99: Place Special Objects In Room
Used by the routine at BuildRoomObjects.
Copies each of the special objects at SpecialObjects which is in the room of the object at IX into the slots from SpecialObjectSlots, then clears the slots which are left over (up to RoomObjects). The address of the entry is kept in the new object so that UpdateSpecialObjects can copy its position back. Each special object is given a width and depth of 05, a height of 0C and flags of 14.
Input
IX The address of the player
Copy each special object that is in this room.
PlaceSpecialObjectsInRoom AE99 LD DE,$5BC8 Point DE at SpecialObjectSlots.
AE9C EXX Switch to the shadow registers.
AE9D LD IY,$76E3 Point IY at SpecialObjects.
AEA1 LD B,(IX+$08) Fetch the room number into the high byte of BC'.
PlaceSpecialObjectsInRoom_TestEntry AEA4 LD A,(IY+$00) Fetch the special object number.
AEA7 AND A Jump to PlaceSpecialObjectsInRoom_NextEntry if the entry is not in use.
AEA8 JR Z,PlaceSpecialObjectsInRoom_NextEntry
AEAA LD A,(IY+$08) Fetch the room of the special object.
AEAD CP B Jump to PlaceSpecialObjectsInRoom_NextEntry if it is not this room.
AEAE JR NZ,PlaceSpecialObjectsInRoom_NextEntry
AEB0 PUSH IY Stash the entry address on the stack.
AEB2 EXX Switch back to the main registers.
AEB3 POP HL Restore the entry address from the stack.
AEB4 PUSH HL Stash it on the stack again.
AEB5 LD A,(HL) Copy the object number to the slot.
AEB6 INC HL
AEB7 LD (DE),A
AEB8 INC DE
AEB9 INC HL Skip to the current position.
AEBA INC HL
AEBB INC HL
AEBC INC HL
AEBD LD BC,$0003 Set BC to 0003.
AEC0 LDIR Copy the x, y and z coordinates to the slot.
AEC2 EX DE,HL Point HL at the slot and DE at the room.
AEC3 LD (HL),$05 Write 05 as the width.
AEC5 INC HL
AEC6 LD (HL),$05 Write 05 as the depth.
AEC8 INC HL
AEC9 LD (HL),$0C Write 0C as the height.
AECB INC HL
AECC LD (HL),$14 Write 14 as the flags.
AECE INC HL Move on to the room.
AECF EX DE,HL Point HL at the entry and DE at the slot.
AED0 LD A,(HL) Copy the room to the slot.
AED1 INC HL
AED2 LD (DE),A
AED3 INC DE
AED4 LD B,$07 Set a counter of seven.
AED6 CALL ClearBytes Call ClearBytes.
AED9 POP BC Restore the entry address from the stack.
AEDA LD A,C Store the low byte of the address in the slot.
AEDB LD (DE),A
AEDC INC DE
AEDD LD A,B Store the high byte of the address in the slot.
AEDE LD (DE),A
AEDF INC DE
AEE0 LD B,$0E Set a counter of 0E.
AEE2 CALL ClearBytes Call ClearBytes.
AEE5 EXX Switch to the shadow registers.
PlaceSpecialObjectsInRoom_NextEntry AEE6 LD DE,$0009 Set DE to 0009.
AEE9 ADD IY,DE Move on to the next entry.
AEEB PUSH IY Copy IY to HL (using the stack).
AEED POP HL
AEEE LD DE,$7827 Point DE at SpritePointers.
AEF1 AND A Subtract SpritePointers from HL.
AEF2 SBC HL,DE
AEF4 JR C,PlaceSpecialObjectsInRoom_TestEntry Jump to PlaceSpecialObjectsInRoom_TestEntry if there are more entries.
AEF6 EXX Switch back to the main registers.
Clear any slots that were not filled.
PlaceSpecialObjectsInRoom_ClearSlots AEF7 LD HL,$5C08 Point HL at RoomObjects.
AEFA AND A Subtract the next slot from HL.
AEFB SBC HL,DE
AEFD RET Z Return if all of the slots have been done.
AEFE LD B,$20 Set a counter of 20.
AF00 CALL ClearBytes Call ClearBytes.
AF03 JR PlaceSpecialObjectsInRoom_ClearSlots Jump to PlaceSpecialObjectsInRoom_ClearSlots.
View the equivalent code in;
Prev: AE96 Up: Map Next: AF05