Prev: 48831 Up: Map Next: 48961
48846: Handler: Turn-Based Events
Used by the routine at GameLoop.
Count down the timed threats and, when one expires, run its handler.
Handler_TurnBasedEvents 48846 LD A,(47670) Jump to Handler_TurnBasedEvents_Scenic when the event mask is zero.
48849 OR A
48850 JR Z,Handler_TurnBasedEvents_Scenic
48852 LD C,A Count the eight event bits, and skip a threat whose bit is clear.
48853 LD B,8
Handler_TurnBasedEvents_Loop 48855 SRL C
48857 JR NC,Handler_TurnBasedEvents_Next
48859 LD DE,0 DE=0000.
48862 LD HL,47671 Count this threat's timer down. Leave it alone while time remains.
48865 LD A,8
48867 SUB B
48868 LD E,A
48869 ADD HL,DE
48870 DEC (HL)
48871 JR NZ,Handler_TurnBasedEvents_Next
48873 LD IX,(47838) Take this threat's handler.
48877 SLA E
48879 ADD IX,DE
48881 LD L,(IX+0)
48884 LD H,(IX+1)
48887 PUSH BC Keep the bit scan safe, return here, and jump to that handler.
48888 LD DE,48893
48891 PUSH DE
48892 JP (HL)
48893 POP BC Restore the bit scan from the stack.
Handler_TurnBasedEvents_Next 48894 DJNZ Handler_TurnBasedEvents_Loop Repeat from Handler_TurnBasedEvents_Loop for the remaining event bits.
Handler_TurnBasedEvents_Scenic 48896 NOP Start at the scenic list. Jump to Handler_TurnBasedEvents_Return when the scenic count is zero.
48897 LD HL,47688
48900 LD A,(47872)
48903 OR A
48904 JR Z,Handler_TurnBasedEvents_Return
48906 LD B,A Start at the first scenic entry.
48907 JR Handler_TurnBasedEvents_ScenicSlot
Handler_TurnBasedEvents_ScenicAdvance 48909 INC HL Advance to the next scenic entry.
Handler_TurnBasedEvents_ScenicSlot 48910 LD A,(HL) Jump to Handler_TurnBasedEvents_ScenicNext when this scenic slot is empty.
48911 OR A
48912 JR Z,Handler_TurnBasedEvents_ScenicNext
48914 LD A,(47771) Jump to Handler_TurnBasedEvents_ScenicNext when this event is already in the current room.
48917 CP (HL)
48918 JR Z,Handler_TurnBasedEvents_ScenicNext
48920 PUSH HL Call GetTableEntry to fetch this event's room list.
48921 PUSH BC
48922 LD A,(47872)
48925 SUB B
48926 LD E,A
48927 LD IX,47772
48931 CALL GetTableEntry
48934 LD A,(23672) Use the frame counter as a step count and start at the first room in the list.
48937 LD B,A
48938 LD A,255
Handler_TurnBasedEvents_RoomWalk 48940 LD L,(IX+0)
48943 LD H,(IX+1)
48946 JR Handler_TurnBasedEvents_RoomCheck
Handler_TurnBasedEvents_RoomStep 48948 INC HL Step to the next room in the list.
Handler_TurnBasedEvents_RoomCheck 48949 CP (HL) Jump back to Handler_TurnBasedEvents_RoomWalk when the end marker matches.
48950 JR Z,Handler_TurnBasedEvents_RoomWalk
48952 DJNZ Handler_TurnBasedEvents_RoomStep Repeat from Handler_TurnBasedEvents_RoomStep until the step count runs out.
48954 LD A,(HL) Take the room the walk landed on.
48955 POP BC Restore the scenic counter and scenic entry pointer from the stack.
48956 POP HL
48957 LD (HL),A Store that room back in this scenic slot.
Handler_TurnBasedEvents_ScenicNext 48958 DJNZ Handler_TurnBasedEvents_ScenicAdvance Repeat from Handler_TurnBasedEvents_ScenicAdvance for the remaining scenic events.
Handler_TurnBasedEvents_Return 48960 RET Return.
View the equivalent code in;
Prev: 48831 Up: Map Next: 48961