Prev: BD58 Up: Map Next: BEA7
BD6B: 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 0C 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 BD6B LD A,($5B13) Jump to HandlePickupAndDrop_WaitForRelease if PickupDropPressedFlag is set.
BD6E AND A
BD6F JP NZ,HandlePickupAndDrop_WaitForRelease
BD72 CALL TestPickupDropKey Call TestPickupDropKey.
BD75 RET Z Return if the control is not pressed.
BD76 CALL TestPlayerInRoom Call TestPlayerInRoom.
BD79 RET NC Return if the player is not inside the room.
Return if the player is jumping.
BD7A BIT 3,(IX+$0C) Return if the player is jumping.
BD7E RET NZ
Return if the player is in the air.
BD7F BIT 2,(IX+$0C) Return if the player is in the air.
BD83 RET Z
Test whether there is room to drop an object, by raising the player by 0C.
BD84 XOR A Write 00 to *NoRoomToDropFlag.
BD85 LD ($5B33),A
BD88 LD A,(IX+$03) Fetch the height of the player.
BD8B LD B,A Keep it in B.
BD8C ADD A,$0C Add 0C.
BD8E LD (IX+$03),A Set the new height of the player.
BD91 CALL TestObjectIntersections Call TestObjectIntersections.
BD94 LD (IX+$03),B Restore the height of the player.
BD97 JR NC,HandlePickupAndDrop_Pressed Jump to HandlePickupAndDrop_Pressed if there is room.
BD99 LD A,$01 Write 01 to *NoRoomToDropFlag.
BD9B LD ($5B33),A
Mark the press and enlarge the player.
HandlePickupAndDrop_Pressed BD9E CALL PlayLowBeep Call PlayLowBeep.
BDA1 LD A,$01 Write 01 to *PickupDropPressedFlag and *ObjectsCarriedChangedFlag.
BDA3 LD ($5B13),A
BDA6 LD ($5B14),A
BDA9 LD B,$02 Set a counter of 02 special objects.
BDAB LD L,(IX+$04) Fetch the width of the player.
BDAE LD A,L Copy it into A.
BDAF ADD A,$04 Add 04.
BDB1 LD (IX+$04),A Set the new width.
BDB4 LD H,(IX+$05) Fetch the depth of the player.
BDB7 LD A,H Copy it into A.
BDB8 ADD A,$04 Add 04.
BDBA LD (IX+$05),A Set the new depth.
BDBD PUSH HL Stash the old width and depth.
BDBE LD L,(IX+$06) Fetch the height of the player.
BDC1 LD A,L Copy it into A.
BDC2 ADD A,$04 Add 04.
BDC4 LD (IX+$06),A Set the new height.
BDC7 PUSH HL Stash the old height.
BDC8 LD IY,$5BC8 Point IY at SpecialObjectSlots.
Try to pick up a nearby valve.
HandlePickupAndDrop_LookForObject BDCC CALL TestObjectCanBePickedUp Call TestObjectCanBePickedUp.
BDCF JP C,HandlePickupAndDrop_PickUp Jump to HandlePickupAndDrop_PickUp if it can be picked up.
BDD2 LD DE,$0020 Point IY at the next special object.
BDD5 ADD IY,DE
BDD7 DJNZ HandlePickupAndDrop_LookForObject Jump to HandlePickupAndDrop_LookForObject until both have been tried.
Look for a free slot to drop into.
BDD9 CALL TestPickupDropKey Call TestPickupDropKey.
BDDC JR Z,HandlePickupAndDrop_Done Jump to HandlePickupAndDrop_Done if it is zero.
BDDE LD B,$02 Set a counter of 02 special objects.
BDE0 LD IY,$5BC8 Point IY at SpecialObjectSlots.
BDE4 LD DE,$0020 Set DE to 0020.
HandlePickupAndDrop_TestSlot BDE7 LD A,(IY+$00) Fetch the object number of the special object.
BDEA AND A Jump to HandlePickupAndDrop_Drop if it is zero.
BDEB JR Z,HandlePickupAndDrop_Drop
BDED ADD IY,DE Point IY at the next special object.
BDEF DJNZ HandlePickupAndDrop_TestSlot Jump to HandlePickupAndDrop_TestSlot until all of them have been tried.
Put the size of the player back.
HandlePickupAndDrop_Done BDF1 POP HL Restore the old height from the stack.
BDF2 LD (IX+$06),L Set the height of the player.
BDF5 POP HL Restore the old width and depth from the stack.
BDF6 LD (IX+$04),L Set the width of the player.
BDF9 LD (IX+$05),H Set the depth of the player.
BDFC RET Return.
Wait until the control is released.
HandlePickupAndDrop_WaitForRelease BDFD CALL TestPickupDropKey Call TestPickupDropKey.
BE00 RET NZ Return if it is not zero.
BE01 XOR A Write 00 to *PickupDropPressedFlag.
BE02 LD ($5B13),A
BE05 RET Return.
Drop the object that has been carried longest.
HandlePickupAndDrop_Drop BE06 LD HL,$5B84 Point HL at ObjectsCarried_Third.
BE09 LD A,(HL) Fetch its object number.
BE0A INC HL Move on to the flags.
BE0B AND A Jump to HandlePickupAndDrop_Shift if it is zero.
BE0C JR Z,HandlePickupAndDrop_Shift
BE0E LD A,($5B33) Fetch NoRoomToDropFlag.
BE11 AND A Jump to HandlePickupAndDrop_Done if it is not zero.
BE12 JR NZ,HandlePickupAndDrop_Done
BE14 DEC HL Point HL at the object number.
BE15 LD A,(HL) Fetch it.
BE16 INC HL Move on to the flags.
BE17 LD (IY+$00),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 BE1A PUSH HL Stash the address of the flags of the object carried.
BE1B LD BC,$0003 Set BC to 0003.
BE1E PUSH IX Copy IX to HL (using the stack).
BE20 POP HL
BE21 PUSH IY Copy IY to DE (using the stack).
BE23 POP DE
BE24 INC DE Point DE at the x position of the object.
BE25 INC HL Point HL at the x position of the player.
BE26 LDIR Copy the position of the player to the object.
BE28 LD A,(IX+$03) Fetch the height of the player.
BE2B ADD A,$0C Add 0C.
BE2D LD (IX+$03),A Set the new height of the player.
BE30 LD A,(IX+$23) Fetch the height of the top half of the player.
BE33 ADD A,$0C Add 0C.
BE35 LD (IX+$23),A Set the new height of the top half of the player.
BE38 CALL CalculatePixelPositionOfOtherObject Call CalculatePixelPositionOfOtherObject.
Set up the rest of the object.
HandlePickupAndDrop_SetObject BE3B LD (IY+$04),$05 Set the width of the object to 05.
BE3F LD (IY+$05),$05 Set the depth of the object to 05.
BE43 LD (IY+$06),$0C Set the height of the object to 0C.
BE47 POP HL Restore the address of the flags of the object carried from the stack.
BE48 LD A,(HL) Fetch the flags.
BE49 INC HL Move on to the address of the table entry.
BE4A LD (IY+$07),A Set the flags of the object.
BE4D LD A,(IX+$08) Fetch the room of the player.
BE50 LD (IY+$08),A Set the room of the object.
BE53 LD A,(HL) Fetch the low byte of the table entry address.
BE54 INC HL Move on to the high byte.
BE55 LD (IY+$10),A Set the low byte of the table entry address of the object.
BE58 LD A,(HL) Fetch the high byte of the table entry address.
BE59 LD (IY+$11),A Set the high byte of the table entry address of the object.
BE5C SET 0,(IY+$0D) Set bit 0 of the object flags.
Shift the carried list along and clear ObjectsCarriedHeader.
HandlePickupAndDrop_Shift BE60 LD HL,$5B83 Point HL at ObjectsCarried_SecondEnd.
BE63 LD DE,$5B87 Point DE at ObjectsCarried_ThirdEnd.
BE66 LD BC,$000C Set BC to 000C.
BE69 LDDR Move the objects.
BE6B LD DE,$5B78 Point DE at ObjectsCarriedHeader.
BE6E LD B,$04 Set the number of bytes to clear to 04.
BE70 CALL ClearBytes Call ClearBytes.
BE73 JP HandlePickupAndDrop_Done Jump to HandlePickupAndDrop_Done.
Pick up the object that IY points at.
HandlePickupAndDrop_PickUp BE76 LD HL,$5B78 Point HL at ObjectsCarriedHeader.
BE79 XOR A Write 00 to *EggTopDisabledFlag.
BE7A LD ($5B3B),A
BE7D LD A,(IY+$00) Fetch the object number of the object.
BE80 LD (HL),A Store it.
BE81 INC HL Move on to the flags.
BE82 LD A,(IY+$07) Fetch the flags of the object.
BE85 LD (HL),A Store them.
BE86 INC HL Move on to the address of the table entry.
BE87 LD E,(IY+$10) Fetch the low byte of the table entry address of the object.
BE8A LD D,(IY+$11) Fetch the high byte.
BE8D XOR A Write 00 to the table entry.
BE8E LD (DE),A
BE8F LD (HL),E Store the low byte of the table entry address.
BE90 INC HL Move on to the high byte.
BE91 LD (HL),D Store it.
BE92 CALL SetWipeAndDrawFlagsForObject Call SetWipeAndDrawFlagsForObject.
BE95 LD (IY+$00),$01 Set the sprite number to 01.
BE99 LD HL,$5B84 Point HL at ObjectsCarried_Third.
BE9C LD A,(HL) Fetch its object number.
BE9D INC HL Move on to the flags.
BE9E AND A Jump to HandlePickupAndDrop_Shift if it is zero.
BE9F JR Z,HandlePickupAndDrop_Shift
BEA1 LD (IY+$00),A Set it as the object number of the special object.
BEA4 PUSH HL Stash the address of the flags.
BEA5 JR HandlePickupAndDrop_SetObject Jump to HandlePickupAndDrop_SetObject.
View the equivalent code in;
Prev: BD58 Up: Map Next: BEA7