Prev: 42749 Up: Map Next: 42873
42751: Handler: Run Script
Executes the bytecode at IX.
Each instruction is a condition from JumpTable_ScriptConditions followed by an action from JumpTable_ScriptActions. A condition that fails skips its action.
254 selects OR for the next condition and 255 selects AND.
255 ends the instruction and starts another one.
Input
IX Pointer to the script bytecode
Preserve the caller's registers for Action_EndScript.
Handler_RunScript 42751 PUSH HL Stash HL, DE and BC on the stack.
42752 PUSH DE
42753 PUSH BC
Begin a new instruction: clear the condition mask and reset the operator to AND.
RunScript_NewInstruction 42754 LD HL,42749 HL=ScriptConditionMask.
42757 LD (HL),64 Start the condition mask at 64 (only the zero flag set, meaning the conditions hold).
42759 INC HL Move HL on to the condition operator.
42760 LD (HL),255 Start with the AND operator (255).
Dispatch the condition opcode at *IX through JumpTable_ScriptConditions.
RunScript_DispatchCondition 42762 LD E,(IX+0) Fetch the condition opcode from *IX+0 into E.
42765 PUSH IX Stash IX on the stack.
42767 LD IX,42885 IX=JumpTable_ScriptConditions.
42771 CALL GetTableEntry Call GetTableEntry to fetch the condition routine address into HL.
42774 POP IX Restore IX from the stack.
42776 JP (HL) Jump to the condition routine held in HL.
Conditions of different lengths jump into this run of INC IX at different points, so each entry point skips the right number of bytes.
RunScript_SkipCondition_FourBytes 42777 INC IX Move IX past the four bytes of this condition.
RunScript_SkipCondition_ThreeBytes 42779 INC IX Move IX past the three bytes of this condition.
RunScript_SkipCondition_TwoBytes 42781 INC IX Move IX past the two bytes of this condition.
This entry point is used by the routine at Condition_AlwaysSucceeds.
RunScript_SkipCondition_OneByte 42783 INC IX Move IX past the one byte of this condition.
Combine this condition's result with the running mask using AND or OR.
42785 PUSH AF Copy the result flags of this condition into C (bit 6 is its zero flag).
42786 POP BC
42787 LD A,(42750) See whether the current operator in *ScriptConditionOperator is OR (254).
42790 CP 254
42792 LD A,(42749) Fetch the running condition mask from *ScriptConditionMask.
42795 JR NZ,RunScript_CombineWithAnd Jump to RunScript_CombineWithAnd if *ScriptConditionOperator is not equal to 254.
42797 OR C The script operator is "or", so this check passes if either condition held (OR C).
42798 JR RunScript_StoreConditionMask Jump to RunScript_StoreConditionMask.
RunScript_CombineWithAnd 42800 AND C Otherwise both conditions must hold (AND C).
RunScript_StoreConditionMask 42801 LD (42749),A Store the combined condition result at ScriptConditionMask.
After the condition, either chain another with AND/OR, or dispatch the action.
42804 LD A,(IX+0) Fetch the next script byte from *IX+0.
42807 CP 254 Jump to RunScript_DispatchAction if it is an action opcode (less than 254).
42809 JR C,RunScript_DispatchAction
42811 LD (42750),A Store the new AND/OR operator at ScriptConditionOperator.
42814 INC IX Move IX on to the next script byte.
42816 JR RunScript_DispatchCondition Jump to RunScript_DispatchCondition.
Advance past a chained action separator, then dispatch the action opcode.
RunScript_NextAction 42818 INC IX Move IX on to the action opcode.
RunScript_DispatchAction 42820 LD E,(IX+0) Fetch the action opcode from *IX+0 into E.
42823 PUSH IX Stash IX on the stack.
42825 LD IX,42945 IX=JumpTable_ScriptActions.
42829 CALL GetTableEntry Call GetTableEntry to fetch the action routine address into HL.
42832 POP IX Restore IX from the stack.
42834 LD A,(42749) Pass the condition mask to the action as its flags, so the zero flag says whether the conditions hold.
42837 LD C,A
42838 PUSH BC
42839 POP AF
42840 JP (HL) Jump to the action routine held in HL.
Actions of different lengths jump into this run of INC IX at different points, so each entry point skips the right number of bytes.
RunScript_SkipAction_FourBytes 42841 INC IX Move IX past the four bytes of this action.
RunScript_SkipAction_ThreeBytes 42843 INC IX Move IX past the three bytes of this action.
RunScript_SkipAction_TwoBytes 42845 INC IX Move IX past the two bytes of this action.
RunScript_SkipAction_OneByte 42847 INC IX Move IX past the one byte of this action.
This entry point is used by the routines at Action_JumpToScript, Action_CallScript and Action_ReturnFromScript.
Decide whether another action follows, or whether to start a new instruction.
RunScript_AfterAction 42849 LD A,(IX+0) Fetch the next script byte from *IX+0.
42852 CP 255 Jump to RunScript_NextAction if it is the chained-action marker 255.
42854 JR Z,RunScript_NextAction
42856 JR RunScript_NewInstruction Jump to RunScript_NewInstruction.
RunScript_InvertConditionResult 42858 JR NZ,RunScript_ConditionHolds Jump to RunScript_ConditionHolds if the zero flag is not set.
42860 LD A,1 Load 1 so the following AND A clears the zero flag.
42862 AND A Clear the zero flag; the inverted condition does not hold.
42863 RET Return.
RunScript_ConditionHolds 42864 XOR A Clear A and set the zero flag; the inverted condition holds.
42865 RET Return.
RunScript_ResolveMatchedItem 42866 CP 255 Return if the operand is not the matched-item sentinel 255.
42868 RET NZ
42869 LD A,(43013) Fetch the matched item ID from *ScriptMatchedItem.
42872 RET Return.
Prev: 42749 Up: Map Next: 42873