Prev: AB03 Up: Map Next: AB88
AB0A: Process Game Events
Used by the routine at GameLoop.
This routine manages two types of in-game events:
1. Turn-Based Events
These are timer-based hazards that count down with each game turn. When a turn counter reaches zero, the associated event handler is called via a jump table.
2. Scenic Events
Mostly atmospheric events that randomly appear in different locations to add flavor to the game world (like seagulls appearing at the beach).
The routine maintains a table of current locations for each scenic event. On each turn, it checks if any scenic event is NOT in the current room, then randomly relocates it to one of its valid rooms.
Each scenic event has a predefined group of rooms where the event can appear.
The routine ensures that:
  • Multiple turn-based dangers can threaten the player simultaneously
  • Scenic events don't repeatedly trigger in the same room
  • The game world feels dynamic with events occurring in different locations
First process the turn-based events (if any are active).
GameEventsProcessor AB0A LD A,($A77E) Load *Flag_TurnBasedEventState into A.
AB0D OR A Jump to GameScenicEventsProcessor if no turn-based events are currently active.
AB0E JR Z,GameScenicEventsProcessor
One of the events has triggered, find which one.
AB10 LD C,A Copy the turn-based event flags into C.
AB11 LD B,$08 Set a counter in B for the number of possible turn-based events (08).
Keep shifting the event flags one-by-one to find which bits are set.
GameEventChecker_Loop AB13 SRL C Shift C one position left to check the next event flag bit.
AB15 JR NC,GameEventChecker_Next Jump to GameEventChecker_Next if this event bit isn't set.
The currently processed turn-based event is active, so process it.
This is: Counter_Crab+(08-the current event counter).
AB17 LD DE,$0000 Calculate the turn-based event index and store it in HL.
AB1A LD HL,$A77F
AB1D LD A,$08
AB1F SUB B
AB20 LD E,A
AB21 ADD HL,DE
AB22 DEC (HL) Decrease the turn-based event counter at *HL by one.
AB23 JR NZ,GameEventChecker_Next Jump to GameEventChecker_Next if the event turn counter at *HL was still more than zero.
The event turn counter is zero, so activate the event itself.
AB25 LD IX,($A7C8) Load *Pointer_TurnBasedEvents_Jump into IX.
AB29 SLA E Double the index as this table contains addresses.
AB2B ADD IX,DE Add this offset to IX to point to the current handler.
AB2D LD L,(IX+$00) Get the handler address and store it in HL.
AB30 LD H,(IX+$01)
AB33 PUSH BC Stash the bit index and event flag byte on the stack.
AB34 LD DE,$AB39 Push GameEventChecker_Return onto the stack so that the next return will go on to continue processing events.
AB37 PUSH DE
AB38 JP (HL) Jump to the routine pointed to by *HL to action the current event.
Once the event handler has run, this is where the routine will resume.
GameEventChecker_Return AB39 POP BC Restore the event bit index counter and event flag byte from the stack.
GameEventChecker_Next AB3A DJNZ GameEventChecker_Loop Decrease the event bit counter by one and loop back to GameEventChecker_Loop until all the event status bits have been processed.
Process scenic events.
GameScenicEventsProcessor AB3C NOP No operation.
AB3D LD HL,($A7E2) Load HL with *Pointer_ScenicEventLocations.
AB40 LD A,($A7EE) Load *Count_ScenicEvents into A.
AB43 OR A Jump to GameEventsProcessor_Return if there are no more scenic events to run (the count is zero).
AB44 JR Z,GameEventsProcessor_Return
AB46 LD B,A Copy *Count_ScenicEvents into B as an event counter for the loop.
AB47 JR GameScenicEventChecker Jump to GameScenicEventChecker.
This is the main scenic event loop.
GameScenicEventChecker_Loop AB49 INC HL Increment the scenic event pointer location by one.
GameScenicEventChecker AB4A LD A,(HL)
AB4B PUSH HL
AB4C CALL $AED1
AB4F POP HL
AB50 AND A
AB51 JR Z,GameScenicEventChecker_Next
AB53 LD C,A
AB54 LD A,($A7C3)
AB57 CP C
AB58 JR Z,GameScenicEventChecker_Next
AB5A PUSH BC Stash the scenic event location pointer and event counter on the stack.
AB5B PUSH HL
This is: E=*Count_ScenicEvents-B.
AB5C LD A,($A7EE) Calculate the index of the currently processed event.
AB5F SUB B
AB60 LD E,A
AB61 LD IX,($A7E4) Load *Pointer_ScenicEventRooms into IX.
The routine at GetTableEntry is usually used to fetch an address from the given table, but here it's used to move IX to point to the index of the currently processed event (and this routine will fetch the address itself).
AB65 CALL GetTableEntry Call GetTableEntry.
AB68 CALL FetchFrames Load a random number from FetchFrames into B.
AB6B LD B,A
AB6C LD A,$FF Set A to FF (the room group terminator) for the comparison.
The table at Pointer_ScenicEventRooms is indexed by event (there are 08 entries), but each address points to a "group" of room IDs where this event could occur. Each set of room IDs for the event is terminated using FF.
GameScenicEvent_FetchRoomGroup AB6E LD L,(IX+$00) Get the room group address pointer and store it in HL.
AB71 LD H,(IX+$01)
AB74 JR GameScenicEvent_CountRoomsInGroup Jump to GameScenicEvent_CountRoomsInGroup.
Use the random number to select a room from the group - this loops through the rooms using B as a counter.
GameScenicEvent_CountRooms_Loop AB76 INC HL Move to the next room ID in the group.
GameScenicEvent_CountRoomsInGroup AB77 CP (HL) Jump to GameScenicEvent_FetchRoomGroup if the terminator is read from *HL.
AB78 JR Z,GameScenicEvent_FetchRoomGroup
AB7A DJNZ GameScenicEvent_CountRooms_Loop Decrease the random counter by one and loop back to GameScenicEvent_CountRooms_Loop until the counter is zero.
AB7C LD C,(HL)
AB7D POP HL
AB7E LD B,(HL)
AB7F PUSH HL
AB80 CALL $AF08 Call AF08.
AB83 POP HL Restore the event counter and scenic event location pointer from the stack.
AB84 POP BC
GameScenicEventChecker_Next AB85 DJNZ GameScenicEventChecker_Loop Decrease the scenic event counter by one and loop back to GameScenicEventChecker_Loop until all scenic events have been processed.
All done, now return.
GameEventsProcessor_Return AB87 RET Return.
Prev: AB03 Up: Map Next: AB88