![]() |
Routines |
| Prev: A6FD | Up: Map | Next: A779 |
|
Used by the routines at Handler_GameEvents, Handler_ScenicEvents, Handler_DispatchVerb and ChangeRoom.
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.
|
||||||||
|
Preserve the caller's registers for Action_EndScript.
|
||||||||
| Handler_RunScript | A6FF | PUSH HL | Stash HL, DE and BC on the stack. | |||||
| A700 | PUSH DE | |||||||
| A701 | PUSH BC | |||||||
|
Begin a new instruction: clear the condition mask and reset the operator to AND.
|
||||||||
| RunScript_NewInstruction | 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). |
||||||
|
Dispatch the condition opcode at *IX through JumpTable_ScriptConditions.
|
||||||||
| RunScript_DispatchCondition | A70A | LD E,(IX+$00) | Fetch the condition opcode from *IX+00 into E. | |||||
| A70D | PUSH IX | Stash IX on the stack. | ||||||
| A70F | LD IX,$A785 | IX=JumpTable_ScriptConditions. | ||||||
| A713 | CALL GetTableEntry | Call GetTableEntry to fetch the condition routine address into HL. | ||||||
| A716 | POP IX | Restore IX from the stack. | ||||||
| A718 | 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 | A719 | INC IX | Move IX past the four bytes of this condition. | |||||
|
This entry point is used by the routines at Condition_ItemLocationEquals, Condition_ItemLocationDiffers, Condition_GroupItemEquals, Condition_GroupItemDiffers, Condition_RoomPairMatches and Condition_RoomPairDiffers.
|
||||||||
| RunScript_SkipCondition_ThreeBytes | A71B | INC IX | Move IX past the three bytes of this condition. | |||||
|
This entry point is used by the routines at Condition_ItemIsPresent, Condition_ItemIsAbsent, Condition_ItemIsCarried, Condition_ItemIsNotCarried, Condition_ItemIsHere, Condition_InRoom, Condition_NotInRoom, Condition_FlagIsSet, Condition_FlagIsClear, Condition_InventoryCountEquals, Condition_InventoryCountDiffers, Condition_MarkedRoomEquals, Condition_MarkedRoomDiffers, Condition_PhraseMatches, Condition_PhraseDoesNotMatch, Condition_ParserSucceeds, Condition_ParserFails, Condition_ParserResultEquals, Condition_ParserResultDiffers, Condition_CanTakeItem, Condition_CannotTakeItem, Condition_IsCarryingForDrop and Condition_IsNotCarryingForDrop.
|
||||||||
| RunScript_SkipCondition_TwoBytes | A71D | 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 | A71F | INC IX | Move IX past the one byte of this condition. | |||||
|
Combine this condition's result with the running mask using AND or OR.
|
||||||||
| 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) | Fetch the running condition mask from *ScriptConditionMask. | ||||||
| A72B | JR NZ,RunScript_CombineWithAnd | Jump to RunScript_CombineWithAnd 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 RunScript_StoreConditionMask | Jump to RunScript_StoreConditionMask. | ||||||
| RunScript_CombineWithAnd | A730 | AND C | Otherwise both conditions must hold (AND C). |
|||||
| RunScript_StoreConditionMask | A731 | LD ($A6FD),A | Store the combined condition result at ScriptConditionMask. | |||||
|
After the condition, either chain another with AND/OR, or dispatch the action.
|
||||||||
| A734 | LD A,(IX+$00) | Fetch the next script byte from *IX+00. | ||||||
| A737 | CP $FE | Jump to RunScript_DispatchAction if it is an action opcode (less than FE). | ||||||
| A739 | JR C,RunScript_DispatchAction | |||||||
| A73B | LD ($A6FE),A | Store the new AND/OR operator at ScriptConditionOperator. | ||||||
| A73E | INC IX | Move IX on to the next script byte. | ||||||
| A740 | JR RunScript_DispatchCondition | Jump to RunScript_DispatchCondition. | ||||||
|
Advance past a chained action separator, then dispatch the action opcode.
|
||||||||
| RunScript_NextAction | A742 | INC IX | Move IX on to the action opcode. | |||||
| RunScript_DispatchAction | A744 | LD E,(IX+$00) | Fetch the action opcode from *IX+00 into E. | |||||
| A747 | PUSH IX | Stash IX on the stack. | ||||||
| A749 | LD IX,$A7C1 | IX=JumpTable_ScriptActions. | ||||||
| A74D | CALL GetTableEntry | Call GetTableEntry to fetch the action routine address into HL. | ||||||
| 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 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 | A759 | INC IX | Move IX past the four bytes of this action. | |||||
|
This entry point is used by the routines at Action_JumpToScript, Action_CallScript, Action_PrintMessage, Action_PrintMessageAndNewline, Action_PlaceItem, Action_TransformItem, Action_SetTurnCounter and Action_WriteSavedByte.
|
||||||||
| RunScript_SkipAction_ThreeBytes | A75B | INC IX | Move IX past the three bytes of this action. | |||||
|
This entry point is used by the routines at Action_BringItemHere, Action_DestroyItem, Handler_PickUpItem, Handler_DropItem, Action_GoToRoom, Action_SetFlag, Action_ClearFlag, Action_AddToScore, Action_Pause, Action_MarkScenicEvent, Action_SetEventFlag, Action_ClearEventFlag, Action_StartTurnEvent, Action_StopTurnEvent, Action_MovePlayer and Action_SetCarryingLimit.
|
||||||||
| RunScript_SkipAction_TwoBytes | A75D | INC IX | Move IX past the two bytes of this action. | |||||
|
This entry point is used by the routines at Action_ReturnFromScript, Action_EndScript, Action_IncrementInventory, Action_DecrementInventory, Action_LoadGame, Action_SaveGame, Action_DescribeRoom, Action_ListInventory, Action_OfferSave and Action_PrintScore.
|
||||||||
| RunScript_SkipAction_OneByte | A75F | 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 | A761 | LD A,(IX+$00) | Fetch the next script byte from *IX+00. | |||||
| A764 | CP $FF | Jump to RunScript_NextAction if it is the chained-action marker FF. | ||||||
| A766 | JR Z,RunScript_NextAction | |||||||
| A768 | JR RunScript_NewInstruction | Jump to RunScript_NewInstruction. | ||||||
|
This entry point is used by the routines at Condition_ItemIsAbsent, Condition_ItemIsNotCarried, Condition_NotInRoom, Condition_ItemLocationDiffers, Condition_FlagIsSet, Condition_GroupItemDiffers, Condition_InventoryCountDiffers, Condition_MarkedRoomDiffers, Condition_PhraseDoesNotMatch, Condition_ParserSucceeds, Condition_ParserFails, Condition_ParserResultDiffers, Condition_RoomPairDiffers, Condition_CannotTakeItem and Condition_IsNotCarryingForDrop.
Invert a condition result: succeed when the tested flag was clear.
|
||||||||
| RunScript_InvertConditionResult | A76A | JR NZ,RunScript_ConditionHolds | Jump to RunScript_ConditionHolds if the zero flag is not set. | |||||
| A76C | LD A,$01 | Load 01 so the following AND A clears the zero flag. | ||||||
| A76E | AND A | Clear the zero flag; the inverted condition does not hold. | ||||||
| A76F | RET | Return. | ||||||
| RunScript_ConditionHolds | A770 | XOR A | Clear A and set the zero flag; the inverted condition holds. | |||||
| A771 | RET | Return. | ||||||
|
This entry point is used by the routines at Condition_ItemIsPresent, Condition_ItemIsAbsent, Condition_ItemIsCarried, Condition_ItemIsNotCarried, Condition_ItemIsHere, Condition_ItemLocationEquals, Condition_ItemLocationDiffers, Condition_CanTakeItem, Condition_CannotTakeItem, Condition_IsCarryingForDrop, Condition_IsNotCarryingForDrop, Action_PlaceItem, Action_BringItemHere, Action_TransformItem, Action_DestroyItem, Handler_PickUpItem, Handler_DropItem and Action_MarkScenicEvent.
When the operand is FF substitute the matched item ID from ScriptMatchedItem.
|
||||||||
| RunScript_ResolveMatchedItem | A772 | CP $FF | Return if the operand is not the matched-item sentinel FF. | |||||
| A774 | RET NZ | |||||||
| A775 | LD A,($A805) | Fetch the matched item ID from *ScriptMatchedItem. | ||||||
| A778 | RET | Return. | ||||||
| Prev: A6FD | Up: Map | Next: A779 |