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
Handler_RunScript 42751 PUSH HL Stash HL, DE and BC on the stack.
42752 PUSH DE
42753 PUSH BC
Handler_RunScript_0 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).
Handler_RunScript_1 42762 LD E,(IX+0) E=*IX+0.
42765 PUSH IX Stash IX on the stack.
42767 LD IX,42885 IX=JumpTable_ScriptConditions.
42771 CALL GetTableEntry Call GetTableEntry.
42774 POP IX Restore IX from the stack.
42776 JP (HL) Jump to *HL.
42777 INC IX Move IX past the four bytes of that condition.
Handler_RunScript_2 42779 INC IX
Handler_RunScript_3 42781 INC IX
This entry point is used by the routine at Condition_AlwaysSucceeds.
Handler_RunScript_4 42783 INC IX }
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) A=*ScriptConditionMask.
42795 JR NZ,Handler_RunScript_5 Jump to Handler_RunScript_5 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 Handler_RunScript_6 Jump to Handler_RunScript_6.
Handler_RunScript_5 42800 AND C Otherwise both conditions must hold (AND C).
Handler_RunScript_6 42801 LD (42749),A Store the combined condition result.
42804 LD A,(IX+0) A=*IX+0.
42807 CP 254 Jump to Handler_RunScript_8 if A is less than 254.
42809 JR C,Handler_RunScript_8
42811 LD (42750),A Store the new operator.
42814 INC IX Move IX on to the next script byte.
42816 JR Handler_RunScript_1 Jump to Handler_RunScript_1.
Handler_RunScript_7 42818 INC IX Move IX on to the action code.
Handler_RunScript_8 42820 LD E,(IX+0) E=*IX+0.
42823 PUSH IX Stash IX on the stack.
42825 LD IX,42945 IX=JumpTable_ScriptActions.
42829 CALL GetTableEntry Call GetTableEntry.
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 *HL.
42841 INC IX Move IX past the four bytes of that action.
Handler_RunScript_9 42843 INC IX
Handler_RunScript_10 42845 INC IX
Handler_RunScript_11 42847 INC IX }
This entry point is used by the routines at Action_JumpToScript, Action_CallScript and Action_ReturnFromScript.
Handler_RunScript_12 42849 LD A,(IX+0) A=*IX+0.
42852 CP 255 Jump to Handler_RunScript_7 if A is equal to 255.
42854 JR Z,Handler_RunScript_7
42856 JR Handler_RunScript_0 Jump to Handler_RunScript_0.
Handler_RunScript_13 42858 JR NZ,Handler_RunScript_14 Jump to Handler_RunScript_14 if A is not equal to 255.
42860 LD A,1 A=1.
42862 AND A The condition does not hold.
42863 RET Return.
Handler_RunScript_14 42864 XOR A A=0.
42865 RET Return.
Handler_RunScript_15 42866 CP 255 Return if A is not equal to 255.
42868 RET NZ
42869 LD A,(43013) A=*ScriptMatchedItem.
42872 RET Return.
Prev: 42749 Up: Map Next: 42873