Prev: 48472 Up: Map Next: 48807
48491: Handle Pickup And Drop
Used by the routine at HandlePlayerLegs.
Picks up or drops an object when the player presses the control for it. A valve which is close enough is picked up. If the player is carrying three objects already then the one that has been carried longest is dropped where the new one was. Otherwise, if the player is carrying something and there is a free place for a special object in the room, the object that has been carried longest is dropped where the player stands, and the player is lifted up by 12 to stand on it.
The routine looks for objects by making the player a little wider, deeper and taller, which is put right when the routine ends.
The objects carried are four lots of four bytes from ObjectsCarriedHeader: the object number, the flags and the address of the entry in SpecialObjects. The first is the place for a new object and the last is the one that has been carried longest.
Input
IX The address of the bottom half of the player
Return unless this is a new press while the player is standing in the room.
HandlePickupAndDrop 48491 LD A,(23315) Jump to HandlePickupAndDrop_WaitForRelease if PickupDropPressedFlag is set.
48494 AND A
48495 JP NZ,HandlePickupAndDrop_WaitForRelease
48498 CALL TestPickupDropKey Call TestPickupDropKey.
48501 RET Z Return if the control is not pressed.
48502 CALL TestPlayerInRoom Call TestPlayerInRoom.
48505 RET NC Return if the player is not inside the room.
Return if the player is jumping.
48506 BIT 3,(IX+12) Return if the player is jumping.
48510 RET NZ
Return if the player is in the air.
48511 BIT 2,(IX+12) Return if the player is in the air.
48515 RET Z
Test whether there is room to drop an object, by raising the player by 12.
48516 XOR A Write 0 to *NoRoomToDropFlag.
48517 LD (23347),A
48520 LD A,(IX+3) Fetch the height of the player.
48523 LD B,A Keep it in B.
48524 ADD A,12 Add 12.
48526 LD (IX+3),A Set the new height of the player.
48529 CALL TestObjectIntersections Call TestObjectIntersections.
48532 LD (IX+3),B Restore the height of the player.
48535 JR NC,HandlePickupAndDrop_Pressed Jump to HandlePickupAndDrop_Pressed if there is room.
48537 LD A,1 Write 1 to *NoRoomToDropFlag.
48539 LD (23347),A
Mark the press and enlarge the player.
HandlePickupAndDrop_Pressed 48542 CALL PlayLowBeep Call PlayLowBeep.
48545 LD A,1 Write 1 to *PickupDropPressedFlag and *ObjectsCarriedChangedFlag.
48547 LD (23315),A
48550 LD (23316),A
48553 LD B,2 Set a counter of 2 special objects.
48555 LD L,(IX+4) Fetch the width of the player.
48558 LD A,L Copy it into A.
48559 ADD A,4 Add 4.
48561 LD (IX+4),A Set the new width.
48564 LD H,(IX+5) Fetch the depth of the player.
48567 LD A,H Copy it into A.
48568 ADD A,4 Add 4.
48570 LD (IX+5),A Set the new depth.
48573 PUSH HL Stash the old width and depth.
48574 LD L,(IX+6) Fetch the height of the player.
48577 LD A,L Copy it into A.
48578 ADD A,4 Add 4.
48580 LD (IX+6),A Set the new height.
48583 PUSH HL Stash the old height.
48584 LD IY,23496 Point IY at SpecialObjectSlots.
Try to pick up a nearby valve.
HandlePickupAndDrop_LookForObject 48588 CALL TestObjectCanBePickedUp Call TestObjectCanBePickedUp.
48591 JP C,HandlePickupAndDrop_PickUp Jump to HandlePickupAndDrop_PickUp if it can be picked up.
48594 LD DE,32 Point IY at the next special object.
48597 ADD IY,DE
48599 DJNZ HandlePickupAndDrop_LookForObject Jump to HandlePickupAndDrop_LookForObject until both have been tried.
Look for a free slot to drop into.
48601 CALL TestPickupDropKey Call TestPickupDropKey.
48604 JR Z,HandlePickupAndDrop_Done Jump to HandlePickupAndDrop_Done if it is zero.
48606 LD B,2 Set a counter of 2 special objects.
48608 LD IY,23496 Point IY at SpecialObjectSlots.
48612 LD DE,32 Set DE to 0032.
HandlePickupAndDrop_TestSlot 48615 LD A,(IY+0) Fetch the object number of the special object.
48618 AND A Jump to HandlePickupAndDrop_Drop if it is zero.
48619 JR Z,HandlePickupAndDrop_Drop
48621 ADD IY,DE Point IY at the next special object.
48623 DJNZ HandlePickupAndDrop_TestSlot Jump to HandlePickupAndDrop_TestSlot until all of them have been tried.
Put the size of the player back.
HandlePickupAndDrop_Done 48625 POP HL Restore the old height from the stack.
48626 LD (IX+6),L Set the height of the player.
48629 POP HL Restore the old width and depth from the stack.
48630 LD (IX+4),L Set the width of the player.
48633 LD (IX+5),H Set the depth of the player.
48636 RET Return.
Wait until the control is released.
HandlePickupAndDrop_WaitForRelease 48637 CALL TestPickupDropKey Call TestPickupDropKey.
48640 RET NZ Return if it is not zero.
48641 XOR A Write 0 to *PickupDropPressedFlag.
48642 LD (23315),A
48645 RET Return.
Drop the object that has been carried longest.
HandlePickupAndDrop_Drop 48646 LD HL,23428 Point HL at ObjectsCarried_Third.
48649 LD A,(HL) Fetch its object number.
48650 INC HL Move on to the flags.
48651 AND A Jump to HandlePickupAndDrop_Shift if it is zero.
48652 JR Z,HandlePickupAndDrop_Shift
48654 LD A,(23347) Fetch NoRoomToDropFlag.
48657 AND A Jump to HandlePickupAndDrop_Done if it is not zero.
48658 JR NZ,HandlePickupAndDrop_Done
48660 DEC HL Point HL at the object number.
48661 LD A,(HL) Fetch it.
48662 INC HL Move on to the flags.
48663 LD (IY+0),A Set it as the object number of the special object.
Put the object where the player is, and lift the player on top of it.
HandlePickupAndDrop_Place 48666 PUSH HL Stash the address of the flags of the object carried.
48667 LD BC,3 Set BC to 0003.
48670 PUSH IX Copy IX to HL (using the stack).
48672 POP HL
48673 PUSH IY Copy IY to DE (using the stack).
48675 POP DE
48676 INC DE Point DE at the x position of the object.
48677 INC HL Point HL at the x position of the player.
48678 LDIR Copy the position of the player to the object.
48680 LD A,(IX+3) Fetch the height of the player.
48683 ADD A,12 Add 12.
48685 LD (IX+3),A Set the new height of the player.
48688 LD A,(IX+35) Fetch the height of the top half of the player.
48691 ADD A,12 Add 12.
48693 LD (IX+35),A Set the new height of the top half of the player.
48696 CALL CalculatePixelPositionOfOtherObject Call CalculatePixelPositionOfOtherObject.
Set up the rest of the object.
HandlePickupAndDrop_SetObject 48699 LD (IY+4),5 Set the width of the object to 5.
48703 LD (IY+5),5 Set the depth of the object to 5.
48707 LD (IY+6),12 Set the height of the object to 12.
48711 POP HL Restore the address of the flags of the object carried from the stack.
48712 LD A,(HL) Fetch the flags.
48713 INC HL Move on to the address of the table entry.
48714 LD (IY+7),A Set the flags of the object.
48717 LD A,(IX+8) Fetch the room of the player.
48720 LD (IY+8),A Set the room of the object.
48723 LD A,(HL) Fetch the low byte of the table entry address.
48724 INC HL Move on to the high byte.
48725 LD (IY+16),A Set the low byte of the table entry address of the object.
48728 LD A,(HL) Fetch the high byte of the table entry address.
48729 LD (IY+17),A Set the high byte of the table entry address of the object.
48732 SET 0,(IY+13) Set bit 0 of the object flags.
Shift the carried list along and clear ObjectsCarriedHeader.
HandlePickupAndDrop_Shift 48736 LD HL,23427 Point HL at ObjectsCarried_SecondEnd.
48739 LD DE,23431 Point DE at ObjectsCarried_ThirdEnd.
48742 LD BC,12 Set BC to 0012.
48745 LDDR Move the objects.
48747 LD DE,23416 Point DE at ObjectsCarriedHeader.
48750 LD B,4 Set the number of bytes to clear to 4.
48752 CALL ClearBytes Call ClearBytes.
48755 JP HandlePickupAndDrop_Done Jump to HandlePickupAndDrop_Done.
Pick up the object that IY points at.
HandlePickupAndDrop_PickUp 48758 LD HL,23416 Point HL at ObjectsCarriedHeader.
48761 XOR A Write 0 to *EggTopDisabledFlag.
48762 LD (23355),A
48765 LD A,(IY+0) Fetch the object number of the object.
48768 LD (HL),A Store it.
48769 INC HL Move on to the flags.
48770 LD A,(IY+7) Fetch the flags of the object.
48773 LD (HL),A Store them.
48774 INC HL Move on to the address of the table entry.
48775 LD E,(IY+16) Fetch the low byte of the table entry address of the object.
48778 LD D,(IY+17) Fetch the high byte.
48781 XOR A Write 0 to the table entry.
48782 LD (DE),A
48783 LD (HL),E Store the low byte of the table entry address.
48784 INC HL Move on to the high byte.
48785 LD (HL),D Store it.
48786 CALL SetWipeAndDrawFlagsForObject Call SetWipeAndDrawFlagsForObject.
48789 LD (IY+0),1 Set the sprite number to 1.
48793 LD HL,23428 Point HL at ObjectsCarried_Third.
48796 LD A,(HL) Fetch its object number.
48797 INC HL Move on to the flags.
48798 AND A Jump to HandlePickupAndDrop_Shift if it is zero.
48799 JR Z,HandlePickupAndDrop_Shift
48801 LD (IY+0),A Set it as the object number of the special object.
48804 PUSH HL Stash the address of the flags.
48805 JR HandlePickupAndDrop_SetObject Jump to HandlePickupAndDrop_SetObject.
View the equivalent code in;
Prev: 48472 Up: Map Next: 48807