Prev: BF66 Up: Map Next: C0D4
BF79: Pick up, or put down
Used by the routine at PLAYER_LEGS.
Called from the legs' update routine (PLAYER_LEGS) every turn. One press does one thing: pick up the bucket or a collectable that he is on or beside; failing that, put down the last of the things he carries (CARRIED_LAST), under himself, so that he stands on it; and if he carries nothing there, move what he carries one place along towards it. TAKE_HELD latches the press, so holding the key does nothing more, and every press that gets that far plays the pick-up sound. Knight Lore's handle_pickup_drop and the routines after it, joined into one.
Nothing happens unless he is inside the room's walls (CHK_PLYR_OOB, not in a doorway), not jumping (bit 3 of +$0C) and standing on something (bit 2). Before anything else it looks for an object up to 12 units above his head: if there is one, NO_HEADROOM is set and nothing is put down, because putting something down lifts him 12 units onto it.
He carries up to three things, in the four-byte slots CARRIED_SHOWN (the newest), the one after, and CARRIED_LAST (the oldest, put down next): the graphic, the flags from +7, and the address of the thing's quest record (QUEST_RECORDS). CARRIED is a fourth slot in front of them, where a thing just picked up waits for the slots to be moved along. They behave as a queue: the first picked up is the first put down.
Input
IX the player's legs (OBJECTS)
TAKE_OR_LEAVE BF79 LD A,(TAKE_HELD) the key is still held from the last press: wait for it to go up
BF7C AND A
BF7D JP NZ,WAIT_TAKE_RELEASE
BF80 CALL CHK_PICKUP_DROP not pressed: nothing to do
BF83 RET Z
BF84 CALL CHK_PLYR_OOB only inside the room's walls
BF87 RET NC
BF88 BIT 3,(IX+$0C) not while jumping (bit 3 of +$0C); only when standing on something (bit 2)
BF8C RET NZ
BF8D BIT 2,(IX+$0C)
BF91 RET Z
BF92 XOR A anything within 12 units above his head? His Z is raised to look, then put back
BF93 LD (NO_HEADROOM),A
BF96 LD A,(IX+$03)
BF99 LD B,A
BF9A ADD A,$0C
BF9C LD (IX+$03),A
BF9F CALL DO_ANY_OBJS_INTERSECT
BFA2 LD (IX+$03),B
BFA5 JR NC,TAKE_OR_LEAVE_0
BFA7 LD A,$01 yes: there is no room for him to stand on what he puts down (this never ran in the build's sessions)
BFA9 LD (NO_HEADROOM),A
TAKE_OR_LEAVE_0 BFAC LD A,$01 latch the key, and have the panel's carried things redrawn (SHOW_CARRIED)
BFAE LD (TAKE_HELD),A
BFB1 LD (PANEL_DUE),A
BFB4 LD B,$30 each half-size +4, so that a thing just out of reach counts; the old ones go on the stack
BFB6 LD L,(IX+$04)
BFB9 LD A,L
BFBA ADD A,$04
BFBC LD (IX+$04),A
BFBF LD H,(IX+$05)
BFC2 LD A,H
BFC3 ADD A,$04
BFC5 LD (IX+$05),A
BFC8 PUSH HL
BFC9 LD L,(IX+$06)
BFCC LD A,L
BFCD ADD A,$04
BFCF LD (IX+$06),A
BFD2 PUSH HL
BFD3 LD IY,ROOM_OBJECTS the 48 records of the room's things: the first that can be picked up (CAN_PICK_UP) is taken
TAKE_OR_LEAVE_1 BFD7 CALL CAN_PICK_UP
BFDA JP C,PICK_UP
BFDD LD DE,$0020
BFE0 ADD IY,DE
BFE2 DJNZ TAKE_OR_LEAVE_1
BFE4 CALL CHK_PICKUP_DROP nothing to pick up. This test cannot fail: INPUT has not changed since the same test at the start
BFE7 JR Z,TAKE_DONE
BFE9 LD DE,$0020 the first free record among the room's 48, to put a thing down in; none: nothing is put down
BFEC LD B,$30
BFEE LD IY,ROOM_OBJECTS
TAKE_OR_LEAVE_2 BFF2 LD A,(IY+$00)
BFF5 AND A
BFF6 JR Z,PUT_DOWN
BFF8 ADD IY,DE
BFFA DJNZ TAKE_OR_LEAVE_2
TAKE_DONE BFFC POP HL his half-sizes back
BFFD LD (IX+$06),L
C000 POP HL
C001 LD (IX+$04),L
C004 LD (IX+$05),H
C007 LD HL,$0105 the pick-up sound: sound 1, for five turns (EFFECT_NOTE)
C00A LD (SOUND_COUNT),HL
C00D RET
WAIT_TAKE_RELEASE C00E CALL CHK_PICKUP_DROP clear the latch once the key is up
C011 RET NZ
C012 XOR A
C013 LD (TAKE_HELD),A
C016 RET
Put down the last thing he carries, into the free record at IY.
PUT_DOWN C017 LD HL,CARRIED_LAST nothing in the last slot: just move the slots along
C01A LD A,(HL)
C01B INC HL
C01C AND A
C01D JR Z,SHIFT_CARRIED
C01F LD A,(NO_HEADROOM) no headroom: put nothing down
C022 AND A
C023 JR NZ,TAKE_DONE
C025 DEC HL the thing's graphic into the free record; HL on to the slot's flags
C026 LD A,(HL)
C027 INC HL
C028 LD (IY+$00),A
C02B PUSH HL
C02C LD BC,$001F the rest of the record from the player's legs: his position, so that it goes down where he stands
C02F PUSH IX
C031 POP HL
C032 PUSH IY
C034 POP DE
C035 INC DE
C036 INC HL
C037 LDIR
C039 LD A,(IX+$03) lift both of his records by 12, the thing's height, so that he stands on it
C03C ADD A,$0C
C03E LD (IX+$03),A
C041 LD A,(IX+$23)
C044 ADD A,$0C
C046 LD (IX+$23),A
C049 PUSH IX with IX on the thing: its drawing nudge (DRAW_AT_L16_D8), its place on the screen (CALC_PIXEL_XY), a turn's fall (DEC_DZ_AND_UPDATE_UVZ), and mark it to be drawn
C04B PUSH IY
C04D PUSH IY
C04F POP IX
C051 CALL DRAW_AT_L16_D8
C054 CALL CALC_PIXEL_XY
C057 CALL DEC_DZ_AND_UPDATE_UVZ
C05A CALL SET_WIPE_AND_DRAW_FLAGS
C05D POP IY
C05F POP IX
Fill in the record of a thing put down: IY the record, its graphic and position already set; the slot's flags byte on the stack.
FILL_PUT_DOWN C061 LD (IY+$04),$05 half-sizes 5, 5 and 12
C065 LD (IY+$05),$05
C069 LD (IY+$06),$0C
C06D POP HL +7 the flags from the slot; +8 the room, the player's
C06E LD A,(HL)
C06F INC HL
C070 LD (IY+$07),A
C073 LD A,(IX+$08)
C076 LD (IY+$08),A
C079 LD A,(HL) +$10 and +$11: the address of its quest record, from the slot
C07A INC HL
C07B LD (IY+$10),A
C07E LD A,(HL)
C07F LD (IY+$11),A
C082 LD H,A the graphic back into the quest record, which picking it up had emptied: it is in this room again
C083 LD L,(IY+$10)
C086 LD A,(IY+$00)
C089 LD (HL),A
C08A SET 0,(IY+$0D) bit 0 of +$0D: just put down. Nothing has been found that reads it (Knight Lore's charms have a use for it)
C08E CALL SET_WIPE_AND_DRAW_IY mark it to be drawn
Move the carried things one slot along.
SHIFT_CARRIED C091 LD HL,$A72D twelve bytes up by four, copied from the top down so that they do not overwrite themselves: the slot in front moves into CARRIED_SHOWN, and so on to CARRIED_LAST
C094 LD DE,$A731
C097 LD BC,$000C
C09A LDDR
C09C LD DE,CARRIED the slot in front is empty
C09F LD B,$04
C0A1 CALL CLEAR_BYTES
C0A4 JP TAKE_DONE
Pick up the thing at IY.
PICK_UP C0A7 LD HL,CARRIED graphic, flags and quest record's address into the slot in front; the quest record's graphic zeroed, so that the thing is not put back in its room when he leaves
C0AA LD A,(IY+$00)
C0AD LD (HL),A
C0AE INC HL
C0AF LD A,(IY+$07)
C0B2 LD (HL),A
C0B3 INC HL
C0B4 LD E,(IY+$10)
C0B7 LD D,(IY+$11)
C0BA XOR A
C0BB LD (DE),A
C0BC LD (HL),E
C0BD INC HL
C0BE LD (HL),D
C0BF CALL SET_WIPE_AND_DRAW_IY mark it to be rubbed out, and make it graphic 1, which the drawing code rubs out and then empties (DRAW_OBJECT)
C0C2 LD (IY+$00),$01
C0C6 LD HL,CARRIED_LAST carrying fewer than three: move the slots along
C0C9 LD A,(HL)
C0CA INC HL
C0CB AND A
C0CC JR Z,SHIFT_CARRIED
C0CE LD (IY+$00),A three: the oldest goes down where this one was, in the same record -- picking up swaps (this never ran in the build's sessions)
C0D1 PUSH HL
C0D2 JR FILL_PUT_DOWN
Prev: BF66 Up: Map Next: C0D4