Prev: 6557 Up: Map Next: 65D2
658A: Handler: Scenic Events
Walk the scenic-event bits and fire a handler when the player is in its room.
HandlerScenicEvents 658A LD A,($6222) Fetch the scenic-event flags.
658D OR A No scenic event is running.
658E JR Z,HandlerScenicEvents_Step2
6590 LD C,A Keep the scenic flags and test all eight bits.
6591 LD B,$08
Each set bit is a scenic event that can plant a message.
HandlerScenicEvents_Loop1 6593 SRL C Take the next scenic-event bit.
6595 JR NC,HandlerScenicEvents_Step1 This scenic event is not running.
6597 LD DE,$0000 Index this scenic event's message list.
659A LD A,$08
659C SUB B
659D LD E,A
659E SLA E
65A0 PUSH BC Remember which scenic bits are still to be checked.
65A1 LD A,($5C78) Let the frame counter choose how far to walk the message list.
65A4 LD B,A
65A5 LD IX,$62B2 Find the messages for this scenic event.
65A9 ADD IX,DE Point at this event's messages and prepare the end marker.
65AB LD A,$FF
HandlerScenicEvents_Loop2 65AD LD L,(IX+$00) Read the address of this event's message list.
65B0 LD H,(IX+$01)
HandlerScenicEvents_Loop3 65B3 CP (HL) Walk the list for as many frames as have passed.
65B4 INC HL
65B5 JR Z,HandlerScenicEvents_Loop2
65B7 DJNZ HandlerScenicEvents_Loop3
65B9 DEC HL Step back to the message those frames selected.
65BA SRA E Recover the event number from the list index.
65BC LD IX,$6224 Find the room this scenic event belongs to.
65C0 ADD IX,DE Point at this event's room.
65C2 POP BC Restore the scenic flags still to be checked.
65C3 LD A,($6223) Fetch the current room.
65C6 CP (IX+$00) Leave the event alone when the player is already in its room.
65C9 JR Z,HandlerScenicEvents_Step1
65CB LD A,(HL) Plant the chosen message in this event's room.
65CC LD (IX+$00),A
HandlerScenicEvents_Step1 65CF DJNZ HandlerScenicEvents_Loop1 Repeat for the remaining scenic events.
HandlerScenicEvents_Step2 65D1 RET Return.
Prev: 6557 Up: Map Next: 65D2