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.
A turn-based event runs only while its bit in Flags_TurnEvents is set.
Handler_GameEvents A280 LD A,($A0C8) Leave the events alone when none are armed.
A283 OR A
A284 JR Z,Handler_GameEvents_1
Eight turn-based events share the flag byte.
A286 LD C,A Start with the first turn-based event.
A287 LD B,$08
This event is not running.
TurnEvent_NextBit A289 SRL C Skip an event that is not armed.
A28B JR NC,Handler_GameEvents_0
Count down this event. It fires when the counter at TurnEventCounters reaches zero.
A28D LD DE,$0000 Leave the event for a later turn when 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,Handler_GameEvents_0
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 This is the event whose counter expired.
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.
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.
Handler_GameEvents_0 A2B5 DJNZ TurnEvent_NextBit Every armed event is considered once per turn.
Scenic events live in Table_ScenicEventLocations2.
Handler_GameEvents_1 A2B7 LD HL,$B6BA There is nothing to move when no scenic event is active.
A2BA LD A,($BBCF)
A2BD OR A
A2BE JR Z,Handler_GameEvents_5
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 The next scenic item.
ScenicEvent_Item A2C4 LD A,(HL) Its item 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 An inactive item is left where it is.
A2CB JR Z,Handler_GameEvents_4
An event that is already in the player's room stays there.
A2CD LD C,A Skip an event whose room is CurrentRoom.
A2CE LD A,($A106)
A2D1 CP C
A2D2 JR Z,Handler_GameEvents_4
Each scenic event has a room group in B6BF.
A2D4 PUSH IX The scenic scan waits while a room is chosen.
A2D6 PUSH BC
A2D7 PUSH HL
A2D8 LD A,($BBCF) 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 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 Choose a room from this event's group.
A2E6 LD B,A
A2E7 LD A,$FF
Handler_GameEvents_2 A2E9 LD L,(IX+$00)
A2EC LD H,(IX+$01)
A2EF JR Handler_GameEvents_3
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 FF restarts the group. Otherwise step to the next room.
Handler_GameEvents_3 A2F2 CP (HL)
A2F3 JR Z,Handler_GameEvents_2
A2F5 DJNZ ScenicRoom_Next
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.
Handler_GameEvents_4 A302 DJNZ ScenicEvent_Next Every scenic event is considered once.
Handler_GameEvents_5 A304 RET Return.
View the equivalent code in;
Prev: A275 Up: Map Next: A305