Prev: D562 Up: Map Next: D59E
D56A: Script Routine: (37) Collectible action
Pick a random continuation from the collectible's script table.
Input
IX Address of complex state data for an entity
ScriptRoutine_CollectibleRandomScript D56A LD A,$04 ..
D56C CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value and keep it in B.
D56F LD B,A
D570 INC B Advance the loop index in B.
D571 ADD A,A Double A to form a word index into the script/handler table.
D572 LD C,A Keep the index in C.
D573 LD A,$80 Load A with 80.
Rotate a bit mask until it differs from this collectible's direction / state.
ScriptRoutine_CollectibleRandomScript_RotateMask D575 RLC A Rotate the collectible bitmask in A left circular.
D577 DJNZ ScriptRoutine_CollectibleRandomScript_RotateMask Decrease the loop counter in B and jump to ScriptRoutine_CollectibleRandomScript_RotateMask if more iterations remain.
D579 CP (IX+$09) Does A match this entity's direction/state (IX+09)? If so, jump to ScriptRoutine_CollectibleRandomScript.
D57C JR Z,ScriptRoutine_CollectibleRandomScript
D57E LD (IX+$09),A Set the current entity's direction / state.
D581 AND %00000011 Keep only the low two direction bits of A.
D583 JR NZ,ScriptRoutine_CollectibleRandomScript_RandomMax1E Jump to ScriptRoutine_CollectibleRandomScript_RandomMax1E to continue if the comparison did not match.
D585 LD A,$02 Load A with 02.
D587 JR ScriptRoutine_CollectibleRandomScript_SetCounterAndScript Jump to ScriptRoutine_CollectibleRandomScript_SetCounterAndScript to continue this routine.
Use random maximum 1E when the new mask is not in the low two direction bits.
ScriptRoutine_CollectibleRandomScript_RandomMax1E D589 LD A,$1E Load A with 1E.
Reseed the collectible counter and launch the matching script word from Data_CollectibleScriptTable.
ScriptRoutine_CollectibleRandomScript_SetCounterAndScript D58B CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
D58E INC A Advance 1E by one.
D58F LD ($72BC),A Set the collectible counter (CollectibleCounter).
D592 LD HL,$D562 Point HL at unused padding before the collectible script (Data_CollectibleScriptTable).
D595 ADD HL,BC Add the length/offset in BC to the pointer in HL.
D596 LD C,(HL) Fetch the new script address into BC.
D597 INC HL
D598 LD B,(HL)
D599 LD L,C Copy the script address from BC into HL.
D59A LD H,B
D59B JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Prev: D562 Up: Map Next: D59E