Prev: 46780 Up: Map Next: 46868
46816: Handler: Scenic Events
Handles checking if a scenic event should occur ... and also, handles jumping to the correct related scenic event routine to action it.
Handler_ScenicEvents 46816 LD A,(44792) A=*Count_ScenicEvents.
46819 AND A Return if *Count_ScenicEvents is zero.
46820 RET Z
46821 LD B,A B=A.
46822 LD HL,(44780) HL=*Pointer_Spare.
46825 JR ScenicEvents_Process Jump to ScenicEvents_Process.
Handler_ScenicEvents_Loop 46827 INC HL Increment HL by one.
ScenicEvents_Process 46828 LD A,(HL) Load the scenic event item ID into A.
46829 CALL ValidateItemPresent Call ValidateItemPresent.
46832 JR NZ,ScenicEvents_Next Jump to ScenicEvents_Next if the scenic event item is neither here nor carried.
An event was found to be processed!
First though, stash away the current pointer and index in the search, so this can be resumed later.
46834 LD (44869),HL Write HL to *TempStore_TablePointer.
46837 LD (44871),BC Write BC to *TempStore_TableIndex.
Calculate the event index and get the event handler.
46841 LD A,(44792) E=*Count_ScenicEvents-B.
46844 SUB B
46845 LD E,A
46846 LD IX,(44776) Load IX with *Pointer_JumpTable_ScenicEvents which contains a pointer to the scenic event rountines jump table.
46850 CALL GetTableEntry Call GetTableEntry.
46853 LD DE,46858 Push ScenicEvents_PostProcessing onto the stack (as the return address).
46856 PUSH DE
46857 JP (HL) Jump to the event handler held by HL.
This is the return point after the handler has finished executing.
ScenicEvents_PostProcessing 46858 LD HL,(44869) Restore *TempStore_TablePointer to HL.
46861 LD BC,(44871) Restore *TempStore_TableIndex to BC.
ScenicEvents_Next 46865 DJNZ Handler_ScenicEvents_Loop Decrease the event counter by one and loop back to Handler_ScenicEvents_Loop until all events have been processed.
46867 RET Return.
Prev: 46780 Up: Map Next: 46868