![]() |
Routines |
| Prev: 45924 | Up: Map | Next: 46065 |
|
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 | 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 | |||
|
Eight turn-based events share the flag byte.
|
||||
| 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 is not set. | ||
|
Count down this event's timer.
|
||||
| 45952 | LD DE,0 | Initialise DE to 0. | ||
| 45955 | LD HL,44681 | HL=Counter_Unused_0. | ||
| 45958 | LD A,8 | Calculate the event index (8-B) and store it in E. | ||
| 45960 | SUB B | |||
| 45961 | LD E,A | |||
| 45962 | ADD HL,DE | Point HL at this event's countdown timer. | ||
| 45963 | DEC (HL) | Decrease this event's countdown timer by one. | ||
| 45964 | JR NZ,GameEventChecker_Next | Jump to GameEventChecker_Next if this event's countdown timer is still running. | ||
|
The timer has expired, so run this event's handler.
|
||||
| 45966 | LD IX,(44754) | IX=*Pointer_TurnBasedEvents_Jump. | ||
| 45970 | SLA E | Double the event index, as each entry in the table is two bytes. | ||
| 45972 | ADD IX,DE | Point IX at this event's entry in the table. | ||
| 45974 | LD L,(IX+0) | Read that handler's address into HL. | ||
| 45977 | LD H,(IX+1) | |||
| 45980 | PUSH BC | Stash BC on the stack. | ||
| 45981 | LD DE,45986 | Stash GameEventChecker_Return on the stack so the next return resumes event processing. | ||
| 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 BC from the stack. | |
|
Test the next turn-based event.
|
||||
| GameEventChecker_Next | 45987 | DJNZ GameEventChecker_Loop | Decrease the event bit counter by one and loop back to GameEventChecker_Loop until all eight events have been considered. | |
|
Now handle the 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) | HL=*Pointer_Spare. | ||
| 45993 | LD A,(44792) | Fetch the number of active scenic events from Count_ScenicEvents. | ||
| 45996 | OR A | |||
| 45997 | JR Z,GameEventsProcessor_Return | Jump to GameEventsProcessor_Return if there are no active scenic events. | ||
| 45999 | LD B,A | Set a counter in B for the number of scenic events. | ||
| 46000 | JR GameScenicEventChecker | Jump to GameScenicEventChecker to process the first scenic event without advancing the table pointer. | ||
|
Room 0 means this scenic item is inactive.
|
||||
| GameScenicEventChecker_Loop | 46002 | INC HL | Move on to the next scenic item. | |
| GameScenicEventChecker | 46003 | LD A,(HL) | Fetch this scenic event's item ID. | |
| 46004 | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| 46005 | CALL GetItemRoom | Call GetItemRoom to read which room holds the item. | ||
| 46008 | POP HL | Restore the scenic event table pointer from the stack. | ||
| 46009 | AND A | Jump to GameScenicEventChecker_Next if the item is inactive. | ||
| 46010 | JR Z,GameScenicEventChecker_Next | |||
|
An event that is already in the player's room stays there.
|
||||
| 46012 | LD C,A | Hold this event's room in C. | ||
| 46013 | LD A,(44749) | A=*CurrentRoom. | ||
| 46016 | CP C | Jump to GameScenicEventChecker_Next if this event's room is the current room. | ||
| 46017 | JR Z,GameScenicEventChecker_Next | |||
|
Pick a room for this scenic event.
|
||||
| 46019 | PUSH BC | Stash BC and HL on the stack. | ||
| 46020 | PUSH HL | |||
| 46021 | LD A,(44792) | Calculate which event's group this is. | ||
| 46024 | SUB B | |||
| 46025 | LD E,A | |||
|
Point at this event's room list.
|
||||
| 46026 | LD IX,(44782) | IX=*Pointer_Spare2. | ||
| 46030 | CALL GetTableEntry | Call GetTableEntry to look up the table entry. | ||
|
The frame counter picks how far to walk into the room group. 255 ends the group and the walk wraps.
|
||||
| 46033 | CALL FetchFrames | Call FetchFrames to pick a random step count and store it in B. | ||
| 46036 | LD B,A | |||
| 46037 | LD A,255 | A=the room group terminator (255). | ||
| GameScenicEvent_FetchRoomGroup | 46039 | LD L,(IX+0) | Point HL at the start of this room group. | |
| 46042 | LD H,(IX+1) | |||
| 46045 | JR GameScenicEvent_CountRoomsInGroup | Jump to GameScenicEvent_CountRoomsInGroup. | ||
|
Walk the room group. 255 restarts it, and the frame count chooses where to stop. Then move the scenic item there.
|
||||
| GameScenicEvent_CountRooms_Loop | 46047 | INC HL | Move to the next room in the group. | |
| GameScenicEvent_CountRoomsInGroup | 46048 | CP (HL) | Jump back to GameScenicEvent_FetchRoomGroup when the terminator matches. | |
| 46049 | JR Z,GameScenicEvent_FetchRoomGroup | |||
| 46051 | DJNZ GameScenicEvent_CountRooms_Loop | Decrease the step counter by one and loop back to GameScenicEvent_CountRooms_Loop until the counter is zero. | ||
| 46053 | LD C,(HL) | Fetch the destination room into C. | ||
| 46054 | POP HL | Restore the scenic event table pointer from the stack. | ||
| 46055 | LD B,(HL) | Fetch this scenic event's item ID into B. | ||
| 46056 | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| 46057 | CALL SetItemRoom | Call SetItemRoom to store the item's room. | ||
| 46060 | POP HL | Restore HL and BC from the stack. | ||
| 46061 | POP BC | |||
|
Move on to the next scenic event.
|
||||
| GameScenicEventChecker_Next | 46062 | 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 | 46064 | RET | Return. | |
|
View the equivalent code in;
|
||||
| Prev: 45924 | Up: Map | Next: 46065 |