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.
First process the turn-based events (if any are active).
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 Clear the offset used while counting this threat down.
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 on the stack.
48888 LD DE,48893 Push 48893 so the next return resumes here.
48891 PUSH DE
48892 JP (HL) Jump to that handler.
48893 POP BC Restore the bit scan from the stack.
Test the next turn-based event.
Handler_TurnBasedEvents_Next 48894 DJNZ Handler_TurnBasedEvents_Loop Decrease the event bit counter by one and loop back to Handler_TurnBasedEvents_Loop until all eight events have been considered.
Process scenic events.
Handler_TurnBasedEvents_Scenic 48896 NOP 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 set the group terminator in A.
48937 LD B,A
48938 LD A,255
Walk the room group. 255 restarts it, and the frame count chooses where to stop.
Handler_TurnBasedEvents_RoomWalk 48940 LD L,(IX+0) Point HL at the start of this room group.
48943 LD H,(IX+1)
48946 JR Handler_TurnBasedEvents_RoomCheck Jump to 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 Decrease the step counter by one and loop back to Handler_TurnBasedEvents_RoomStep until the counter is zero.
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.
Move on to the next scenic event.
Handler_TurnBasedEvents_ScenicNext 48958 DJNZ Handler_TurnBasedEvents_ScenicAdvance Decrease the scenic event counter by one and loop back to Handler_TurnBasedEvents_ScenicAdvance until every scenic event has been considered.
All done, now return.
Handler_TurnBasedEvents_Return 48960 RET Return.
View the equivalent code in;
Prev: 48831 Up: Map Next: 48961