Prev: A6FD Up: Map Next: A779
A6FF: 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.
FE selects OR for the next condition and FF selects AND.
FF ends the instruction and starts another one.
Input
IX Pointer to the script bytecode
Handler_RunScript A6FF PUSH HL Stash HL, DE and BC on the stack.
A700 PUSH DE
A701 PUSH BC
Handler_RunScript_0 A702 LD HL,$A6FD HL=ScriptConditionMask.
A705 LD (HL),$40 Start the condition mask at 40 (only the zero flag set, meaning the conditions hold).
A707 INC HL Move HL on to the condition operator.
A708 LD (HL),$FF Start with the AND operator (FF).
Handler_RunScript_1 A70A LD E,(IX+$00) E=*IX+00.
A70D PUSH IX Stash IX on the stack.
A70F LD IX,$A785 IX=JumpTable_ScriptConditions.
A713 CALL GetTableEntry Call GetTableEntry.
A716 POP IX Restore IX from the stack.
A718 JP (HL) Jump to *HL.
A719 INC IX Move IX past the four bytes of that condition.
Handler_RunScript_2 A71B INC IX
Handler_RunScript_3 A71D INC IX
This entry point is used by the routine at Condition_AlwaysSucceeds.
Handler_RunScript_4 A71F INC IX }
A721 PUSH AF Copy the result flags of this condition into C (bit 6 is its zero flag).
A722 POP BC
A723 LD A,($A6FE) See whether the current operator in *ScriptConditionOperator is OR (FE).
A726 CP $FE
A728 LD A,($A6FD) A=*ScriptConditionMask.
A72B JR NZ,Handler_RunScript_5 Jump to Handler_RunScript_5 if *ScriptConditionOperator is not equal to FE.
A72D OR C The script operator is "or", so this check passes if either condition held (OR C).
A72E JR Handler_RunScript_6 Jump to Handler_RunScript_6.
Handler_RunScript_5 A730 AND C Otherwise both conditions must hold (AND C).
Handler_RunScript_6 A731 LD ($A6FD),A Store the combined condition result.
A734 LD A,(IX+$00) A=*IX+00.
A737 CP $FE Jump to Handler_RunScript_8 if A is less than FE.
A739 JR C,Handler_RunScript_8
A73B LD ($A6FE),A Store the new operator.
A73E INC IX Move IX on to the next script byte.
A740 JR Handler_RunScript_1 Jump to Handler_RunScript_1.
Handler_RunScript_7 A742 INC IX Move IX on to the action code.
Handler_RunScript_8 A744 LD E,(IX+$00) E=*IX+00.
A747 PUSH IX Stash IX on the stack.
A749 LD IX,$A7C1 IX=JumpTable_ScriptActions.
A74D CALL GetTableEntry Call GetTableEntry.
A750 POP IX Restore IX from the stack.
A752 LD A,($A6FD) Pass the condition mask to the action as its flags, so the zero flag says whether the conditions hold.
A755 LD C,A
A756 PUSH BC
A757 POP AF
A758 JP (HL) Jump to *HL.
A759 INC IX Move IX past the four bytes of that action.
Handler_RunScript_9 A75B INC IX
Handler_RunScript_10 A75D INC IX
Handler_RunScript_11 A75F INC IX }
This entry point is used by the routines at Action_JumpToScript, Action_CallScript and Action_ReturnFromScript.
Handler_RunScript_12 A761 LD A,(IX+$00) A=*IX+00.
A764 CP $FF Jump to Handler_RunScript_7 if A is equal to FF.
A766 JR Z,Handler_RunScript_7
A768 JR Handler_RunScript_0 Jump to Handler_RunScript_0.
Handler_RunScript_13 A76A JR NZ,Handler_RunScript_14 Jump to Handler_RunScript_14 if A is not equal to FF.
A76C LD A,$01 A=01.
A76E AND A The condition does not hold.
A76F RET Return.
Handler_RunScript_14 A770 XOR A A=00.
A771 RET Return.
Handler_RunScript_15 A772 CP $FF Return if A is not equal to FF.
A774 RET NZ
A775 LD A,($A805) A=*ScriptMatchedItem.
A778 RET Return.
Prev: A6FD Up: Map Next: A779