Prev: 91B0 Up: Map Next: 9206
91B9: PUT IN, PUT ON and DROP IN
The handler for putting the target into (or on) a container, the instrument. The target must be something that can be picked up (8CBA), and not already in the container ('I cannot do that'). Except for PUT ON, the container must be open ('the chest is closed'). There must be room: the container's size (byte 2), minus the target's size, minus the size of what is already inside (9C3D), must be positive ('the chest is too full'). Then the target takes the container's location and the container becomes its holder.
91B9 CALL $8CBA Is the target something that can even be picked up at all?
91BC LD A,($B5DA) Is the instrument (the container) actually the same object as the target's own holder already?
91BF CP (IX+$01)
91C2 JP Z,$72C5 Yes: "I cannot do that." (it's already there)
91C5 LD IY,($B5FA) IY = the instrument's (the container's) own record
91C9 LD A,($B5D8) Is this actually PUT ON (action 18), rather than PUT IN or DROP IN?
91CC CP $12
91CE JR Z,$91D6 PUT ON: no need for the container to be open
91D0 BIT 5,(IY+$07) PUT IN or DROP IN: is the container open?
91D4 JR Z,$9201 No: say so and stop, below
91D6 LD A,(IY+$02) A = the container's own capacity (its size)
91D9 SUB (IX+$02) Subtract the target's own size
91DC JR C,$91E8 Already too big even on its own: fail, below
91DE PUSH AF Save what is left
91DF LD A,($B5DA) A = how much the container already holds
91E2 CALL $9C3D
91E5 LD B,A
91E6 POP AF Subtract that too
91E7 SUB B
91E8 LD HL,$AD0D "the X is too full."
91EB JP C,$72D4 Not enough room at all: say so and stop
91EE JP Z,$72D4 Exactly full, with no room to spare: likewise
91F1 CALL $9C99 Dry run? Then stop here: it would work
91F4 LD A,(IY+$10) The target moves to the container's own room...
91F7 LD (IX+$10),A
91FA LD A,($B5DA) ...and the container becomes its new holder
91FD LD (IX+$01),A
9200 RET
9201 LD A,$05 A = the state code for OPEN/CLOSED
9203 JP $A094 "the X is closed."
Prev: 91B0 Up: Map Next: 9206