Prev: 45924 Up: Map Next: 46065
45939: 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 45939 LD A,(44680) Load the turn-based event flags into A.
45942 OR A Jump to GameScenicEventsProcessor if no turn-based events are currently active.
45943 JR Z,GameScenicEventsProcessor
One of the events has triggered, find which one.
45945 LD C,A Copy the turn-based event flags into C.
45946 LD B,8 Set a counter in B for the number of possible turn-based events (8).
Keep shifting the event flags one-by-one to find which bits are set.
GameEventChecker_Loop 45948 SRL C Test the next turn-based event flag.
45950 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+(8-the current event counter).
45952 LD DE,0 Calculate the turn-based event index and store it in HL.
45955 LD HL,44681
45958 LD A,8
45960 SUB B
45961 LD E,A
45962 ADD HL,DE
45963 DEC (HL) Decrease the turn-based event counter at *HL by one.
45964 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.
45966 LD IX,(44754) Load the turn-based handler pointer into IX.
45970 SLA E Double the index as this table contains addresses.
45972 ADD IX,DE Add this offset to IX to point to the current handler.
45974 LD L,(IX+0) Get the handler address and store it in HL.
45977 LD H,(IX+1)
45980 PUSH BC Keep the bit index and event flag byte on the stack.
45981 LD DE,45986 Push GameEventChecker_Return onto the stack so that the next return will go on to continue processing events.
45984 PUSH DE
45985 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 45986 POP BC Restore the event bit index counter and event flag byte from the stack.
GameEventChecker_Next 45987 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 45989 NOP A spare NOP, probably where an instruction was patched out, before the scenic events are processed.
45990 LD HL,(44780) Point HL at the scenic-event list.
45993 LD A,(44792) Read the scenic-event count into A.
45996 OR A Leave scenic events alone when none are defined.
45997 JR Z,ProcessGameEvents_4
45999 LD B,A Count the scenic events and read the first one.
46000 JR ProcessGameEvents_0
ScenicEvent_Loop 46002 INC HL Read this scenic event's item.
ProcessGameEvents_0 46003 LD A,(HL)
46004 PUSH HL Remember which scenic event this is.
46005 CALL GetItemRoom Call GetItemRoom to read which room holds the item.
46008 POP HL Restore the pointer to this scenic event from the stack.
46009 AND A Skip a scenic event that is not in play.
46010 JR Z,ProcessGameEvents_3
46012 LD C,A Remember which room holds this scenic item.
46013 LD A,(44749) Read the current room into A.
46016 CP C Skip a scenic event that is already in this room.
46017 JR Z,ProcessGameEvents_3
46019 PUSH BC Remember this scenic event while its next room is chosen.
46020 PUSH HL
46021 LD A,(44792) Read the scenic-event count into A.
46024 SUB B Turn the remaining count into this event's index.
46025 LD E,A
46026 LD IX,(44782) Point IX at this event's room list.
46030 CALL GetTableEntry Call GetTableEntry to look up the table entry.
46033 CALL FetchFrames Call FetchFrames to read the frame counter.
46036 LD B,A Use the frame counter as a step through the room list.
46037 LD A,255 Use 255 as the end of the room list.
ProcessGameEvents_1 46039 LD L,(IX+0) Point at this event's room list.
46042 LD H,(IX+1)
46045 JR ProcessGameEvents_2 Start at the first room in the list.
ScenicEvent_PickRoom 46047 INC HL Step to the next room in the list.
ProcessGameEvents_2 46048 CP (HL) Stop at the end of the room list.
46049 JR Z,ProcessGameEvents_1 Wrap to the start of the list at the terminator.
46051 DJNZ ScenicEvent_PickRoom Take another step while the frame count remains.
46053 LD C,(HL) Take the room chosen for this scenic item.
46054 POP HL Restore the pointer to this scenic event from the stack.
46055 LD B,(HL) Take this scenic event's item.
46056 PUSH HL Remember the scenic event while its item is moved.
46057 CALL SetItemRoom Call SetItemRoom to store the item's room.
46060 POP HL Restore HL, BC from the stack.
46061 POP BC
ProcessGameEvents_3 46062 DJNZ ScenicEvent_Loop Step down B by one and jump to ScenicEvent_Loop until it is zero.
ProcessGameEvents_4 46064 RET Return.
Prev: 45924 Up: Map Next: 46065