Prev: BC64 Up: Map Next: BD3C
BC81: Script Routine: (34) Thing Upstairs action
Chase Berk with the Thing Upstairs entity when the two overlap; otherwise keep the script moving.
Input
IX Address of complex state data for an entity
ScriptRoutine_ThingUpstairsChase BC81 CALL Test_ThingUpstairs_Overlap Call Test_ThingUpstairs_Overlap to test whether the Thing Upstairs entity overlaps Berk / the camera-follow entity.
BC84 OR A Is A zero? If not, jump to ScriptRoutine_ThingUpstairsChase_MoveTick.
BC85 JR NZ,ScriptRoutine_ThingUpstairsChase_MoveTick
BC87 LD IY,$909B Point IY at the camera-follow entity (StateData_Berk).
BC8B SET 0,(IY+$03) Set bit 00 of the referenced entity's flags byte 3.
BC8F BIT 4,(IY+$03) Is bit 04 of flags byte 3 (IY+03) set? If not, jump to ScriptRoutine_ThingUpstairsChase_RunStorage.
BC93 JR Z,ScriptRoutine_ThingUpstairsChase_RunStorage
BC95 LD IY,($72AC) Load IY with the current-entity pointer (Pointer_CurrentEntity).
BC99 BIT 7,(IY+$02) Is bit 07 of the referenced entity's flags byte 2 set? If not, jump to ScriptRoutine_ThingUpstairsChase_RunStorage.
BC9D JR Z,ScriptRoutine_ThingUpstairsChase_RunStorage
BC9F XOR A Clear the referenced entity type (deactivate the slot).
BCA0 LD (IY+$00),A Set the referenced entity's entity type.
BCA3 LD HL,$BA35 Point HL at Berk script data BerkPutDownScript_CameraFollow.
BCA6 LD ($72B1),HL Store HL in Berk's script position pointer (Pointer_BerkScriptPosition).
BCA9 LD HL,$BC0E Point HL at the Thing Upstairs script tail (BC0E).
BCAC JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
No chase overlap: run the Thing Upstairs storage/idle script at BBFC.
ScriptRoutine_ThingUpstairsChase_RunStorage BCAF LD HL,$BBFC Point HL at Thing Upstairs storage at BBFC.
BCB2 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Chase tick: random skip, honour move-delay BBDF, else retarget via Update_ThingUpstairs_Movement.
ScriptRoutine_ThingUpstairsChase_MoveTick BCB5 LD A,$0A Load A with 0A.
BCB7 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
BCBA CP $03 Is 0A less than 03? If so, jump to AdvanceScriptInstruction.
BCBC JP C,AdvanceScriptInstruction
BCBF LD A,($BBDF) Load A from BBDF.
BCC2 OR A Is A zero? If not, jump to ScriptRoutine_ThingUpstairsChase_DecMoveDelay.
BCC3 JR NZ,ScriptRoutine_ThingUpstairsChase_DecMoveDelay
BCC5 CALL Update_ThingUpstairs_Movement Call Update_ThingUpstairs_Movement to update Thing Upstairs Movement.
BCC8 JR ScriptRoutine_ThingUpstairsChase_ApplyDirection Jump to ScriptRoutine_ThingUpstairsChase_ApplyDirection to continue this routine.
Count down the Thing Upstairs move-delay byte at BBDF.
ScriptRoutine_ThingUpstairsChase_DecMoveDelay BCCA DEC A Step 0A back by one.
BCCB LD ($BBDF),A Set Thing Upstairs flag byte BBDF.
Apply direction bits: step right, left, down or up, then continue the script.
ScriptRoutine_ThingUpstairsChase_ApplyDirection BCCE LD A,(IX+$09) Load A with the current entity's direction / state.
BCD1 BIT 0,A Is bit 00 of the current entity's direction / state set? If so, call ScriptRoutine_ThingUpstairsChase_TryMoveRight.
BCD3 CALL NZ,ScriptRoutine_ThingUpstairsChase_TryMoveRight
BCD6 BIT 1,A Is bit 01 of the current entity's direction / state set? If so, call ScriptRoutine_ThingUpstairsChase_TryMoveLeft.
BCD8 CALL NZ,ScriptRoutine_ThingUpstairsChase_TryMoveLeft
BCDB BIT 2,A Is bit 02 of the current entity's direction / state set? If so, call ScriptRoutine_ThingUpstairsChase_TryMoveDown.
BCDD CALL NZ,ScriptRoutine_ThingUpstairsChase_TryMoveDown
BCE0 BIT 3,A Is bit 03 of the current entity's direction / state set? If so, call ScriptRoutine_ThingUpstairsChase_TryMoveUp.
BCE2 CALL NZ,ScriptRoutine_ThingUpstairsChase_TryMoveUp
BCE5 JP AdvanceScriptInstruction Jump to AdvanceScriptInstruction to run the next script instruction.
Try moving the Thing Upstairs entity right, or retarget when X-extent hits the right bound.
ScriptRoutine_ThingUpstairsChase_TryMoveRight BCE8 PUSH AF Stash AF on the stack.
BCE9 LD A,(IX+$08) Load A with the current entity's x-extent.
BCEC CP $FC Is the current entity's x-extent less than FC? If so, jump to ScriptRoutine_ThingUpstairsChase_IncX.
BCEE JR C,ScriptRoutine_ThingUpstairsChase_IncX
BCF0 CALL Update_ThingUpstairs_Movement Call Update_ThingUpstairs_Movement to update Thing Upstairs Movement.
BCF3 JR ScriptRoutine_ThingUpstairsChase_RestoreReturnRight Jump to ScriptRoutine_ThingUpstairsChase_RestoreReturnRight to continue this routine.
Nudge the Thing Upstairs entity one character right (X and X-extent).
ScriptRoutine_ThingUpstairsChase_IncX BCF5 INC (IX+$07) Increment the entity's x-coordinate.
Advance the Thing Upstairs entity's X-extent as part of the right-step.
ScriptRoutine_ThingUpstairsChase_IncXExtent BCF8 INC (IX+$08) Increment the entity's x-extent.
Restore flags and return from the right-step attempt.
ScriptRoutine_ThingUpstairsChase_RestoreReturnRight BCFB POP AF Restore AF from the stack.
BCFC RET Return.
Try moving the Thing Upstairs entity left, or retarget when X hits the left bound.
ScriptRoutine_ThingUpstairsChase_TryMoveLeft BCFD PUSH AF Stash AF on the stack.
BCFE LD A,(IX+$07) Load A with the current entity's x-coordinate.
BD01 CP $22 Is the current entity's x-coordinate less than 22? If not, jump to ScriptRoutine_ThingUpstairsChase_DecX.
BD03 JR NC,ScriptRoutine_ThingUpstairsChase_DecX
BD05 CALL Update_ThingUpstairs_Movement Call Update_ThingUpstairs_Movement to update Thing Upstairs Movement.
BD08 JR ScriptRoutine_ThingUpstairsChase_RestoreReturnLeft Jump to ScriptRoutine_ThingUpstairsChase_RestoreReturnLeft to continue this routine.
Nudge the Thing Upstairs entity one character left.
ScriptRoutine_ThingUpstairsChase_DecX BD0A DEC (IX+$07) Move this entity one character left.
BD0D DEC (IX+$08)
Restore flags and return from the left-step attempt.
ScriptRoutine_ThingUpstairsChase_RestoreReturnLeft BD10 POP AF Restore AF from the stack.
BD11 RET Return.
Try moving the Thing Upstairs entity up, or retarget when Y hits the top bound.
ScriptRoutine_ThingUpstairsChase_TryMoveUp BD12 PUSH AF Stash AF on the stack.
BD13 LD A,(IX+$05) Load A with the current entity's y-coordinate.
BD16 CP $14 Is the current entity's y-coordinate less than 14? If not, jump to ScriptRoutine_ThingUpstairsChase_DecY.
BD18 JR NC,ScriptRoutine_ThingUpstairsChase_DecY
BD1A CALL Update_ThingUpstairs_Movement Call Update_ThingUpstairs_Movement to update Thing Upstairs Movement.
BD1D JR ScriptRoutine_ThingUpstairsChase_RestoreReturnUp Jump to ScriptRoutine_ThingUpstairsChase_RestoreReturnUp to continue this routine.
Nudge the Thing Upstairs entity one character up.
ScriptRoutine_ThingUpstairsChase_DecY BD1F DEC (IX+$05) Move this entity one character up.
BD22 DEC (IX+$06)
Restore flags and return from the up-step attempt.
ScriptRoutine_ThingUpstairsChase_RestoreReturnUp BD25 POP AF Restore AF from the stack.
BD26 RET Return.
Try moving the Thing Upstairs entity down, or retarget when Y-extent hits the bottom bound.
ScriptRoutine_ThingUpstairsChase_TryMoveDown BD27 PUSH AF Stash AF on the stack.
BD28 LD A,(IX+$06) Load A with the current entity's y-extent.
BD2B CP $24 Is the current entity's y-extent less than 24? If so, jump to ScriptRoutine_ThingUpstairsChase_IncY.
BD2D JR C,ScriptRoutine_ThingUpstairsChase_IncY
BD2F CALL Update_ThingUpstairs_Movement Call Update_ThingUpstairs_Movement to update Thing Upstairs Movement.
BD32 JR ScriptRoutine_ThingUpstairsChase_RestoreReturnDown Jump to ScriptRoutine_ThingUpstairsChase_RestoreReturnDown to continue this routine.
Nudge the Thing Upstairs entity one character down.
ScriptRoutine_ThingUpstairsChase_IncY BD34 INC (IX+$05) Move this entity one character down.
BD37 INC (IX+$06)
Restore flags and return from the down-step attempt.
ScriptRoutine_ThingUpstairsChase_RestoreReturnDown BD3A POP AF Restore AF from the stack.
BD3B RET Return.
Prev: BC64 Up: Map Next: BD3C