Prev: 6548 Up: Map Next: 658A
6557: Handler: Turn-Based Events
Used by the routine at GameLoop.
Count down the active turn-based events and run each one that expires.
HandlerTurnBasedEvents 6557 LD A,($6219) Fetch the turn-based event flags.
655A OR A No turn-based event is running.
655B JR Z,HandlerTurnBasedEvents_Step3
655D LD C,A Keep the event flags and test all eight bits.
655E LD B,$08
Each set bit is a countdown that is still running.
HandlerTurnBasedEvents_Loop1 6560 SRL C Take the next turn-based event bit.
6562 JR NC,HandlerTurnBasedEvents_Step2 This event is not running.
6564 LD DE,$0000 Count down the turn-based event whose bit was just set.
6567 LD HL,$621A
656A LD A,$08
656C SUB B
656D LD E,A
656E ADD HL,DE
656F DEC (HL)
6570 JR NZ,HandlerTurnBasedEvents_Step2 Leave this event when its countdown has not expired.
6572 LD IX,$62A2 Find the handler for this turn-based event.
6576 SLA E Index the handler for this event.
6578 ADD IX,DE
657A LD L,(IX+$00) Read that handler's address.
657D LD H,(IX+$01)
6580 PUSH BC Remember which events are still to be checked.
HandlerTurnBasedEvents_Step1 6581 LD DE,$6586 Run the handler, then return here for the remaining events.
6584 PUSH DE
6585 JP (HL)
6586 POP BC Restore the event flags still to be checked.
HandlerTurnBasedEvents_Step2 6587 DJNZ HandlerTurnBasedEvents_Loop1 Repeat for the remaining event bits.
HandlerTurnBasedEvents_Step3 6589 NOP Leave this event for the next turn.
Prev: 6548 Up: Map Next: 658A