Prev: B364 Up: Map Next: B3F1
B373: Process Game Events
Used by the routine at GameLoop.
Advance turn-based events, then any scenic events, before the player types again.
First process the turn-based events (if any are active).
ProcessGameEvents B373 LD A,($AE88) Load the turn-based event flags into A.
B376 OR A Jump to GameScenicEventsProcessor if no turn-based events are currently active.
B377 JR Z,GameScenicEventsProcessor
One of the events has triggered, find which one.
B379 LD C,A Copy the turn-based event flags into C.
B37A 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 B37C SRL C Test the next turn-based event flag.
B37E 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: the turn-based event counters+(08-the current event counter).
B380 LD DE,$0000 Calculate the turn-based event index and store it in HL.
B383 LD HL,$AE89
B386 LD A,$08
B388 SUB B
B389 LD E,A
B38A ADD HL,DE
B38B DEC (HL) Decrease the turn-based event counter at *HL by one.
B38C 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.
B38E LD IX,($AED2) Load the turn-based handler pointer into IX.
B392 SLA E Double the index as this table contains addresses.
B394 ADD IX,DE Add this offset to IX to point to the current handler.
B396 LD L,(IX+$00) Get the handler address and store it in HL.
B399 LD H,(IX+$01)
B39C PUSH BC Keep the bit index and event flag byte on the stack.
B39D LD DE,$B3A2 Push GameEventChecker_Return onto the stack so that the next return will go on to continue processing events.
B3A0 PUSH DE
B3A1 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 B3A2 POP BC Restore the event bit index counter and event flag byte from the stack.
GameEventChecker_Next B3A3 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 B3A5 NOP A spare NOP, probably where an instruction was patched out, before the scenic events are processed.
B3A6 LD HL,($AEEC) Point HL at the scenic-event list.
B3A9 LD A,($AEF8) Read the scenic-event count into A.
B3AC OR A Leave scenic events alone when none are defined.
B3AD JR Z,ProcessGameEvents_4
B3AF LD B,A Count the scenic events and read the first one.
B3B0 JR ProcessGameEvents_0
ScenicEvent_Loop B3B2 INC HL Read this scenic event's item.
ProcessGameEvents_0 B3B3 LD A,(HL)
B3B4 PUSH HL Remember which scenic event this is.
B3B5 CALL GetItemRoom Call GetItemRoom to read which room holds the item.
B3B8 POP HL Restore the pointer to this scenic event from the stack.
B3B9 AND A Skip a scenic event that is not in play.
B3BA JR Z,ProcessGameEvents_3
B3BC LD C,A Remember which room holds this scenic item.
B3BD LD A,($AECD) Read the current room into A.
B3C0 CP C Skip a scenic event that is already in this room.
B3C1 JR Z,ProcessGameEvents_3
B3C3 PUSH BC Remember this scenic event while its next room is chosen.
B3C4 PUSH HL
B3C5 LD A,($AEF8) Read the scenic-event count into A.
B3C8 SUB B Turn the remaining count into this event's index.
B3C9 LD E,A
B3CA LD IX,($AEEE) Point IX at this event's room list.
B3CE CALL GetTableEntry Call GetTableEntry to look up the table entry.
B3D1 CALL FetchFrames Call FetchFrames to read the frame counter.
B3D4 LD B,A Use the frame counter as a step through the room list.
B3D5 LD A,$FF Use FF as the end of the room list.
ProcessGameEvents_1 B3D7 LD L,(IX+$00) Point at this event's room list.
B3DA LD H,(IX+$01)
B3DD JR ProcessGameEvents_2 Start at the first room in the list.
ScenicEvent_PickRoom B3DF INC HL Step to the next room in the list.
ProcessGameEvents_2 B3E0 CP (HL) Stop at the end of the room list.
B3E1 JR Z,ProcessGameEvents_1 Wrap to the start of the list at the terminator.
B3E3 DJNZ ScenicEvent_PickRoom Take another step while the frame count remains.
B3E5 LD C,(HL) Take the room chosen for this scenic item.
B3E6 POP HL Restore the pointer to this scenic event from the stack.
B3E7 LD B,(HL) Take this scenic event's item.
B3E8 PUSH HL Remember the scenic event while its item is moved.
B3E9 CALL SetItemRoom Call SetItemRoom to store the item's room.
B3EC POP HL Restore HL, BC from the stack.
B3ED POP BC
ProcessGameEvents_3 B3EE DJNZ ScenicEvent_Loop Step down B by one and jump to ScenicEvent_Loop until it is zero.
ProcessGameEvents_4 B3F0 RET Return.
Prev: B364 Up: Map Next: B3F1