Prev: A275 Up: Map Next: A305
A280: Handler: Process Game Events
Used by the routine at GameStart.
Counts down the turn-based events in Flags_TurnEvents and, when a counter reaches zero, runs the handler from JumpTable_TurnEvents.
Then relocates any scenic event that is not already in the current room, picking the new room from the group at B6BF.
First process the turn-based events (if any are active).
Handler_GameEvents A280 LD A,($A0C8) Jump to ScenicEvents_Start if no turn-based events are currently active.
A283 OR A
A284 JR Z,ScenicEvents_Start
Eight turn-based events share the flag byte.
A286 LD C,A Start with the first turn-based event.
A287 LD B,$08
Keep shifting the event flags one-by-one to find which bits are set.
TurnEvent_NextBit A289 SRL C Jump to TurnEvent_Next if this event bit is not set.
A28B JR NC,TurnEvent_Next
Count down this event. It fires when the counter at TurnEventCounters reaches zero.
A28D LD DE,$0000 Jump to TurnEvent_Next if the counter is still running.
A290 LD HL,$A0C9
A293 LD A,$08
A295 SUB B
A296 LD E,A
A297 ADD HL,DE
A298 DEC (HL)
A299 JR NZ,TurnEvent_Next
The counter has expired, so run this event's script from JumpTable_TurnEvents.
A29B PUSH IX The scripts are listed at JumpTable_TurnEvents.
A29D PUSH BC
A29E LD IX,$BBB9
A2A2 SLA E Point at this event's script entry.
A2A4 ADD IX,DE
A2A6 LD L,(IX+$00) Read that script's address.
A2A9 LD H,(IX+$01)
A2AC PUSH HL Copy the script address from HL into IX (using the stack).
A2AD POP IX
A2AF CALL Handler_RunScript Run that script.
A2B2 POP BC Restore the event counter and event pointer from the stack.
A2B3 POP IX
Test the next turn-based event.
TurnEvent_Next A2B5 DJNZ TurnEvent_NextBit Decrease the event bit counter by one and loop back to TurnEvent_NextBit until all eight events have been considered.
Process scenic events.
ScenicEvents_Start A2B7 LD HL,$B6BA Jump to Handler_GameEvents_Return if no scenic event is active.
A2BA LD A,($BBCF)
A2BD OR A
A2BE JR Z,Handler_GameEvents_Return
A2C0 LD B,A Visit each scenic event in turn.
A2C1 JR ScenicEvent_Item
Room 00 means this scenic item is inactive.
ScenicEvent_Next A2C3 INC HL Move on to the next scenic item.
ScenicEvent_Item A2C4 LD A,(HL) Fetch this scenic item's ID.
A2C5 PUSH HL
A2C6 CALL ItemLocator Call ItemLocator to read where this item is.
A2C9 POP HL Restore the event-list pointer from the stack.
A2CA AND A Jump to ScenicEvent_Done if the item is inactive.
A2CB JR Z,ScenicEvent_Done
An event that is already in the player's room stays there.
A2CD LD C,A Jump to ScenicEvent_Done if this event's room is *CurrentRoom.
A2CE LD A,($A106)
A2D1 CP C
A2D2 JR Z,ScenicEvent_Done
Each scenic event has a room group in B6BF.
A2D4 PUSH IX Keep the scenic scan while a room is chosen.
A2D6 PUSH BC
A2D7 PUSH HL
A2D8 LD A,($BBCF) Calculate which event's group this is.
A2DB SUB B
A2DC LD E,A
A2DD LD IX,$B6BF The room groups are listed at B6BF.
A2E1 CALL GetTableEntry Call GetTableEntry to fetch this event's room group.
The refresh register picks how far to walk into the room group. FF ends the group and the walk wraps.
A2E4 LD A,R Load a step count from the refresh register and set the group terminator in A.
A2E6 LD B,A
A2E7 LD A,$FF
ScenicRoom_Reload A2E9 LD L,(IX+$00) Point HL at the start of this room group.
A2EC LD H,(IX+$01)
A2EF JR ScenicRoom_Check Jump to ScenicRoom_Check.
Walk the room group. FF restarts it, and the refresh count chooses where to stop. Then move the scenic item there.
ScenicRoom_Next A2F1 INC HL Move to the next room in the group.
ScenicRoom_Check A2F2 CP (HL) Jump back to ScenicRoom_Reload when the terminator matches.
A2F3 JR Z,ScenicRoom_Reload
A2F5 DJNZ ScenicRoom_Next Decrease the step counter by one and loop back to ScenicRoom_Next until the counter is zero.
A2F7 LD C,(HL) Fetch the destination room into C.
A2F8 POP HL Restore the scenic-event pointer from the stack.
A2F9 LD B,(HL) Fetch the item ID into B and stash the pointer again.
A2FA PUSH HL
A2FB CALL Handler_UpdateItemLocation Call Handler_UpdateItemLocation.
A2FE POP HL Restore the scenic scan from the stack.
A2FF POP BC
A300 POP IX
Move on to the next scenic event.
ScenicEvent_Done A302 DJNZ ScenicEvent_Next Decrease the scenic event counter by one and loop back to ScenicEvent_Next until every scenic event has been considered.
Handler_GameEvents_Return A304 RET Return.
View the equivalent code in;
Prev: A275 Up: Map Next: A305