Prev: B7F3 Up: Map Next: B92C
B87C: Berk Pick Up Entity
Used by the routine at Berk_Interact_With_Entity.
Berk Pick Up Entity for the player character using complex state at StateData_Boney.
Input
IX Address of complex state data for an entity
Berk_Pick_Up_Entity B87C LD BC,($72AA) Load BC with the last-collided entity pointer (Pointer_LastCollidedEntity).
B880 INC BC Advance the counter/pointer in BC by one.
B881 LD A,(BC) Fetch a byte through the pointer in BC.
B882 AND %00001000 Keep only bit 03 of the flag byte in A (mask 08).
B884 JR NZ,Berk_Pick_Up_Entity_FromCollision If the result was non-zero, jump to Berk_Pick_Up_Entity_FromCollision.
B886 XOR A Clear A as a false / no-match result.
B887 RET Return.
Pick-up from the last collision: reject if X is too far left, else test on-left.
Berk_Pick_Up_Entity_FromCollision B888 PUSH IX Stash IX on the stack.
B88A LD IX,($72AA) Load IX with the last-collided entity pointer (Pointer_LastCollidedEntity).
B88E LD A,(IX+$07) Load A with the current entity's x-coordinate.
B891 CP $49 Is the current entity's x-coordinate less than 49? If not, jump to Berk_Pick_Up_Entity_TestOnLeft.
B893 JR NC,Berk_Pick_Up_Entity_TestOnLeft
B895 XOR A Clear A as a no-entity-found result.
B896 JR Berk_Pick_Up_Entity_RestoreReturn Jump to Berk_Pick_Up_Entity_RestoreReturn to restore IX and return with no pick-up.
Confirm the collidee sits on Berk's left before marking the pick-up.
Berk_Pick_Up_Entity_TestOnLeft B898 CALL Test_EntityOnLeft Call Test_EntityOnLeft to test Entity On Left? If not, jump to Berk_Pick_Up_Entity_RetryCollision.
B89B JR NC,Berk_Pick_Up_Entity_RetryCollision
Mark the picked-up entity's direction/state as held (82).
Berk_Pick_Up_Entity_MarkDirection B89D LD (IX+$09),$82 Write 82 to the current entity's direction / state.
Exit the pick-up attempt, restoring Berk's entity pointer in IX.
Berk_Pick_Up_Entity_RestoreReturn B8A1 POP IX Restore IX from the stack.
B8A3 RET Return.
Retry pick-up via Berk_Pick_Up_Entity after the on-left test failed.
Berk_Pick_Up_Entity_RetryCollision B8A4 CALL Berk_Pick_Up_Entity Call Berk_Pick_Up_Entity to let Berk pick up an entity? If so, jump to Berk_Pick_Up_Entity_MarkDirection.
B8A7 JR C,Berk_Pick_Up_Entity_MarkDirection
B8A9 POP IX Restore IX from the stack.
B8AB RET Return.
This entry point is used by the routine at Berk_Interact_With_Entity.
Trap door height on left: choose open vs closed trap scripts from bit 01 of GameEventFlags.
Berk_Pick_Up_Entity_TrapDoorScripts B8AC BIT 4,(IX+$03) Is bit 04 of flags byte 3 (IX+03) set? If so, jump to Berk_ReadControls_Idle.
B8B0 JP NZ,Berk_ReadControls_Idle
B8B3 LD HL,$72B3 Point HL at the game event flags (GameEventFlags).
B8B6 BIT 1,(HL) Is "trap door is open / trap door event armed" (bit 01 of GameEventFlags) set? If so, jump to Berk_Pick_Up_Entity_TrapOpenScript.
B8B8 JR NZ,Berk_Pick_Up_Entity_TrapOpenScript
B8BA LD HL,$BB33 Point HL at Berk control/put-down script data (BB33).
B8BD JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Trap already open: run the open-trap interaction script (BB41).
Berk_Pick_Up_Entity_TrapOpenScript B8C0 LD HL,$BB41 Point HL at Berk control/put-down script data (BB41).
B8C3 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
This entry point is used by the routine at Update_Berk_ReadControls.
Handle right: clear facing-left, then walk or turn Berk right.
Berk_WalkRight B8C6 RES 1,(IX+$03) Clear Berk's facing-left flag (bit 01 of IX+03).
B8CA LD A,(IX+$04) Fetch Berk's room index.
B8CD CP $00 Is Berk in room 00? If not, continue the right-walk at Berk_WalkRight_TestBelow.
B8CF JR NZ,Berk_WalkRight_TestBelow
B8D1 LD A,(IX+$06) Fetch Berk's y-extent.
B8D4 CP $1B Is he still on the trap door row (y-extent 1B)? If not, continue the current script at AdvanceScriptInstruction.
B8D6 JP NZ,AdvanceScriptInstruction
Right walk outside room 00: test an entity below before turning or interacting.
Berk_WalkRight_TestBelow B8D9 CALL Test_EntityBelow Call Test_EntityBelow to test Entity Below? If not, jump to Berk_WalkRight_ByYExtent.
B8DC JR NC,Berk_WalkRight_ByYExtent
Already facing the walk-right way: continue the script or run face-right put-down BerkPutDownScript_WalkRightFace.
Berk_WalkRight_FaceCheck B8DE BIT 0,(IX+$09) Is bit 00 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
B8E2 JP NZ,AdvanceScriptInstruction
B8E5 LD HL,$BA77 Point HL at Berk control/put-down script data (BerkPutDownScript_WalkRightFace).
B8E8 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Right walk by y-extent: high rows put down, mid rows idle, else try a put-down.
Berk_WalkRight_ByYExtent B8EB CP $41 Is the current entity's y-extent equal to 41? If so, jump to Berk_Put_Down_Entity_AtYExtent41.
B8ED JP Z,Berk_Put_Down_Entity_AtYExtent41
B8F0 CP $38 Is the current entity's y-extent equal to 38? If so, jump to Berk_Put_Down_Entity_AtYExtent38.
B8F2 JR Z,Berk_Put_Down_Entity_AtYExtent38
B8F4 CP $3B Is the current entity's y-extent equal to 3B? If so, jump to Berk_Put_Down_Entity_TrapDoor.
B8F6 JP Z,Berk_Put_Down_Entity_TrapDoor
B8F9 CP $32 Is the current entity's y-extent less than 32? If not, jump to Berk_ReadControls_Idle.
B8FB JP NC,Berk_ReadControls_Idle
B8FE BIT 4,(IX+$03) Is bit 04 of flags byte 3 (IX+03) set? If so, jump to Berk_WalkRight_FaceCheck.
B902 JP NZ,Berk_WalkRight_FaceCheck
B905 LD BC,($72AA) Load BC with the last-collided entity pointer (Pointer_LastCollidedEntity).
B909 INC BC Advance the counter/pointer in BC by one.
B90A LD A,(BC) Fetch a byte through the pointer in BC.
B90B AND %00010000 Keep only bit 04 of the flag byte in A (mask 10).
B90D JR NZ,Berk_WalkRight_FaceCheck If the result was non-zero, jump to Berk_WalkRight_FaceCheck.
B90F BIT 3,(IX+$03) Is bit 03 of flags byte 3 (IX+03) set? If so, jump to Berk_WalkRight_TryPutDown.
B913 JR NZ,Berk_WalkRight_TryPutDown
B915 BIT 0,(IX+$09) Is bit 00 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
B919 JP NZ,AdvanceScriptInstruction
Try Berk_Put_Down_Entity to put down; on success lock held-state and run script BAF1.
Berk_WalkRight_TryPutDown B91C CALL Berk_Put_Down_Entity Call Berk_Put_Down_Entity to let Berk put down an entity? If not, jump to Berk_ReadControls_Idle.
B91F JP NC,Berk_ReadControls_Idle
B922 SET 3,(IX+$03) Set bit 03 of the current entity's flags byte 3.
B926 LD HL,$BAF1 Point HL at Berk control/put-down script data (BAF1).
B929 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Prev: B7F3 Up: Map Next: B92C