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).
GameEventsProcessor 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
Eight turn-based events share the flag byte.
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 is not set.
Count down this event. It fires when the counter reaches zero.
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 counter is still running.
The counter has expired, so run this event's handler.
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 the next return resumes event processing.
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.
Test the next turn-based event.
GameEventChecker_Next B3A3 DJNZ GameEventChecker_Loop Decrease the event bit counter by one and loop back to GameEventChecker_Loop until all eight events have been considered.
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) Jump to GameEventsProcessor_Return if no scenic event is active.
B3A9 LD A,($AEF8)
B3AC OR A
B3AD JR Z,GameEventsProcessor_Return
B3AF LD B,A Visit each scenic event in turn.
B3B0 JR GameScenicEventChecker
Room 00 means this scenic item is inactive.
GameScenicEventChecker_Loop B3B2 INC HL Move on to the next scenic item.
GameScenicEventChecker B3B3 LD A,(HL) Fetch this scenic item's ID.
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 Jump to GameScenicEventChecker_Next if the item is inactive.
B3BA JR Z,GameScenicEventChecker_Next
An event that is already in the player's room stays there.
B3BC LD C,A Remember which room holds this scenic item.
B3BD LD A,($AECD) Read the current room into A.
B3C0 CP C Jump to GameScenicEventChecker_Next if this event's room is the current room.
B3C1 JR Z,GameScenicEventChecker_Next
Each scenic event has a room group to pick from.
B3C3 PUSH BC Keep the scenic scan while a room is chosen.
B3C4 PUSH HL
B3C5 LD A,($AEF8) Calculate which event's group this is.
B3C8 SUB B
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.
The frame counter picks how far to walk into the room group. FF ends the group and the walk wraps.
B3D1 CALL FetchFrames Load a step count from the frame counter and set the group terminator in A.
B3D4 LD B,A
B3D5 LD A,$FF
GameScenicEvent_FetchRoomGroup B3D7 LD L,(IX+$00) Point HL at the start of this room group.
B3DA LD H,(IX+$01)
B3DD JR GameScenicEvent_CountRoomsInGroup Jump to GameScenicEvent_CountRoomsInGroup.
Walk the room group. FF restarts it, and the frame count chooses where to stop. Then move the scenic item there.
GameScenicEvent_CountRooms_Loop B3DF INC HL Move to the next room in the group.
GameScenicEvent_CountRoomsInGroup B3E0 CP (HL) Jump back to GameScenicEvent_FetchRoomGroup when the terminator matches.
B3E1 JR Z,GameScenicEvent_FetchRoomGroup
B3E3 DJNZ GameScenicEvent_CountRooms_Loop Decrease the step counter by one and loop back to GameScenicEvent_CountRooms_Loop until the counter is zero.
B3E5 LD C,(HL) Fetch the destination room into C.
B3E6 POP HL Restore the scenic-event pointer from the stack.
B3E7 LD B,(HL) Fetch the item ID into B and stash the pointer again.
B3E8 PUSH HL
B3E9 CALL SetItemRoom Call SetItemRoom to store the item's room.
B3EC POP HL Restore the scenic scan from the stack.
B3ED POP BC
Move on to the next scenic event.
GameScenicEventChecker_Next B3EE DJNZ GameScenicEventChecker_Loop Decrease the scenic event counter by one and loop back to GameScenicEventChecker_Loop until every scenic event has been considered.
All done, now return.
GameEventsProcessor_Return B3F0 RET Return.
Prev: B364 Up: Map Next: B3F1