![]() |
Routines |
Prev: 43779 | Up: Map | Next: 43912 |
Used by the routine at GameLoop.
This routine manages two types of in-game events:
|
||||
First process the turn-based events (if any are active).
|
||||
GameEventsProcessor | 43786 | LD A,(42878) | Load *Flag_TurnBasedEventState into A. | |
43789 | OR A | Jump to GameScenicEventsProcessor if no turn-based events are currently active. | ||
43790 | JR Z,GameScenicEventsProcessor | |||
One of the events has triggered, find which one.
|
||||
43792 | LD C,A | Copy the turn-based event flags into C. | ||
43793 | 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 | 43795 | SRL C | Shift C one position left to check the next event flag bit. | |
43797 | 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+(8-the current event counter).
|
||||
43799 | LD DE,0 | Calculate the turn-based event index and store it in HL. | ||
43802 | LD HL,42879 | |||
43805 | LD A,8 | |||
43807 | SUB B | |||
43808 | LD E,A | |||
43809 | ADD HL,DE | |||
43810 | DEC (HL) | Decrease the turn-based event counter at *HL by one. | ||
43811 | 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.
|
||||
43813 | LD IX,(42952) | Load *Pointer_TurnBasedEvents_Jump into IX. | ||
43817 | SLA E | Double the index as this table contains addresses. | ||
43819 | ADD IX,DE | Add this offset to IX to point to the current handler. | ||
43821 | LD L,(IX+0) | Get the handler address and store it in HL. | ||
43824 | LD H,(IX+1) | |||
43827 | PUSH BC | Stash the bit index and event flag byte on the stack. | ||
43828 | LD DE,43833 | Push GameEventChecker_Return onto the stack so that the next return will go on to continue processing events. | ||
43831 | PUSH DE | |||
43832 | 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 | 43833 | POP BC | Restore the event bit index counter and event flag byte from the stack. | |
GameEventChecker_Next | 43834 | 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 | 43836 | NOP | No operation. | |
43837 | LD HL,(42978) | Load HL with *Pointer_ScenicEventLocations. | ||
43840 | LD A,(42990) | Load *Count_ScenicEvents into A. | ||
43843 | OR A | Jump to GameEventsProcessor_Return if there are no more scenic events to run (the count is zero). | ||
43844 | JR Z,GameEventsProcessor_Return | |||
43846 | LD B,A | Copy *Count_ScenicEvents into B as an event counter for the loop. | ||
43847 | JR GameScenicEventChecker | Jump to GameScenicEventChecker. | ||
This is the main scenic event loop.
|
||||
GameScenicEventChecker_Loop | 43849 | INC HL | Increment the scenic event pointer location by one. | |
GameScenicEventChecker | 43850 | LD A,(HL) | ||
43851 | PUSH HL | |||
43852 | CALL 44753 | |||
43855 | POP HL | |||
43856 | AND A | |||
43857 | JR Z,GameScenicEventChecker_Next | |||
43859 | LD C,A | |||
43860 | LD A,(42947) | |||
43863 | CP C | |||
43864 | JR Z,GameScenicEventChecker_Next | |||
43866 | PUSH BC | Stash the scenic event location pointer and event counter on the stack. | ||
43867 | PUSH HL | |||
|
||||
43868 | LD A,(42990) | Calculate the index of the currently processed event. | ||
43871 | SUB B | |||
43872 | LD E,A | |||
43873 | LD IX,(42980) | 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).
|
||||
43877 | CALL GetTableEntry | Call GetTableEntry. | ||
43880 | CALL FetchFrames | Load a random number from FetchFrames into B. | ||
43883 | LD B,A | |||
43884 | LD A,255 | Set A to 255 (the room group terminator) for the comparison. | ||
The table at Pointer_ScenicEventRooms is indexed by event (there are 8 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 255.
|
||||
GameScenicEvent_FetchRoomGroup | 43886 | LD L,(IX+0) | Get the room group address pointer and store it in HL. | |
43889 | LD H,(IX+1) | |||
43892 | 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 | 43894 | INC HL | Move to the next room ID in the group. | |
GameScenicEvent_CountRoomsInGroup | 43895 | CP (HL) | Jump to GameScenicEvent_FetchRoomGroup if the terminator is read from *HL. | |
43896 | JR Z,GameScenicEvent_FetchRoomGroup | |||
43898 | DJNZ GameScenicEvent_CountRooms_Loop | Decrease the random counter by one and loop back to GameScenicEvent_CountRooms_Loop until the counter is zero. | ||
43900 | LD C,(HL) | |||
43901 | POP HL | |||
43902 | LD B,(HL) | |||
43903 | PUSH HL | |||
43904 | CALL 44808 | Call 44808. | ||
43907 | POP HL | Restore the event counter and scenic event location pointer from the stack. | ||
43908 | POP BC | |||
GameScenicEventChecker_Next | 43909 | 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 | 43911 | RET | Return. |
Prev: 43779 | Up: Map | Next: 43912 |