Prev: 49166 Up: Map Next: 49319
49175: Drop Object
Used by the routine at HandlePickupAndDrop.
Drops the oldest carried object into the free object record in IY, at the position of the player. If there is no object in the oldest place in the inventory, the carried objects are only moved along. The player rises by 12, to be out of the way of the object that is dropped.
Input
IX Record of the object of the legs of the player
IY Free object record
DropObject 49175 LD HL,42798 Take the oldest of the carried objects, ObjectsCarried_Oldest.
49178 LD A,(HL) Fetch the type of it.
49179 INC HL
49180 AND A Jump to DropObject_MoveAlong to move the objects along if there is none.
49181 JR Z,DropObject_MoveAlong
49183 LD A,(42817) Fetch the flag from NoRoomToDropFlag.
49186 AND A Jump to HandlePickupAndDrop_Done if there is no room above the player.
49187 JR NZ,HandlePickupAndDrop_Done
49189 DEC HL Fetch the type of the object again.
49190 LD A,(HL)
49191 INC HL
49192 LD (IY+0),A Make it the type of the new object.
49195 PUSH HL Stash the address of the flags of the carried object on the stack.
Copy the player to the new object, which gives it the position, the speeds and the room of the player.
49196 LD BC,31 Set the number of bytes to copy in BC.
49199 PUSH IX Take the player, using the stack.
49201 POP HL
49202 PUSH IY Take the new object, using the stack.
49204 POP DE
49205 INC DE Move on to the second byte of each of them.
49206 INC HL
49207 LDIR Copy the record of the player to the new object.
Raise both of the object records of the player, to be above the dropped object.
49209 LD A,(IX+3) Add 12 to the height of the legs.
49212 ADD A,12
49214 LD (IX+3),A
49217 LD A,(IX+35) Add 12 to the height of the body.
49220 ADD A,12
49222 LD (IX+35),A
Make the new object ready to be drawn.
49225 PUSH IX Stash the records of the player and the object on the stack.
49227 PUSH IY
49229 PUSH IY Take the new object as the one being updated, using the stack.
49231 POP IX
49233 CALL SetSpriteOffset_Minus16_Minus8 Call SetSpriteOffset_Minus16_Minus8 to set where the sprite is drawn.
49236 CALL CalculatePixelCoordinates Call CalculatePixelCoordinates to work out where the sprite goes on the screen.
49239 CALL ApplyGravityAndMove Call ApplyGravityAndMove to find where the object can be.
49242 CALL SetWipeAndDrawFlags Call SetWipeAndDrawFlags to mark the object to be drawn.
49245 POP IY Restore the records of the object and the player from the stack.
49247 POP IX
This entry point is used by the routine at PickUpObject.
Set up the dropped object, which is also done when an object is swapped for one that is picked up.
DropObject_SetUp 49249 LD (IY+4),5 Set the half size along x to 5.
49253 LD (IY+5),5 Set the half size along y to 5.
49257 LD (IY+6),12 Set the size along z to 12.
49261 POP HL Restore the address of the flags of the carried object from the stack.
49262 LD A,(HL) Fetch the flags of the carried object.
49263 INC HL
49264 LD (IY+7),A Set them as the flags of the new object.
49267 LD A,(IX+8) Copy the room of the player to the new object.
49270 LD (IY+8),A
49273 LD A,(HL) Fetch the low byte of the address of the object in the store.
49274 INC HL
49275 LD (IY+16),A Keep the low byte of the store address in the new object.
49278 LD A,(HL) Fetch the high byte of the address of the object in the store.
49279 LD (IY+17),A
49282 LD H,A Set HL to the address of the object in the store.
49283 LD L,(IY+16)
49286 LD A,(IY+0) Write the type of the object to its entry in the store, so that it stays in the room.
49289 LD (HL),A
49290 SET 0,(IY+13) Set bit 0 of the hit flags of the new object.
49294 CALL SetWipeAndDrawFlagsForObject Call SetWipeAndDrawFlagsForObject to mark the new object to be drawn.
This entry point is used by the routine at PickUpObject.
Move the carried objects along one place, which gets rid of the oldest and leaves the first place empty.
DropObject_MoveAlong 49297 LD HL,42797 Start at the last byte of the third entry of ObjectsCarried.
49300 LD DE,42801 Take the last byte of the fourth entry.
49303 LD BC,12 Set the number of bytes in BC to 12, three objects.
49306 LDDR Move them along, copying down from the end.
49308 LD DE,42786 Take the first place of the inventory, ObjectsCarried.
49311 LD B,4 Set a counter in B of four bytes.
49313 CALL ClearBytes Call ClearBytes to clear the first place of the inventory.
49316 JP HandlePickupAndDrop_Done Jump to HandlePickupAndDrop_Done.
Prev: 49166 Up: Map Next: 49319