![]() |
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. It fires when the counter reaches zero.
|
||||
| 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 counter is still running. | ||
|
The counter has expired, so run this event's handler.
|
||||
| 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 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 the event bit index counter and event flag byte 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. | |
|
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) | Jump to GameEventsProcessor_Return if no scenic event is active. | ||
| 45993 | LD A,(44792) | |||
| 45996 | OR A | |||
| 45997 | JR Z,GameEventsProcessor_Return | |||
| 45999 | LD B,A | Visit each scenic event in turn. | ||
| 46000 | JR GameScenicEventChecker | |||
|
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 item's ID. | |
| 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 | 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 | Remember which room holds this scenic item. | ||
| 46013 | LD A,(44749) | Read the current room into A. | ||
| 46016 | CP C | Jump to GameScenicEventChecker_Next if this event's room is the current room. | ||
| 46017 | JR Z,GameScenicEventChecker_Next | |||
|
Each scenic event has a room group to pick from.
|
||||
| 46019 | PUSH BC | Keep the scenic scan while a room is chosen. | ||
| 46020 | PUSH HL | |||
| 46021 | LD A,(44792) | Calculate which event's group this is. | ||
| 46024 | SUB B | |||
| 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. | ||
|
The frame counter picks how far to walk into the room group. 255 ends the group and the walk wraps.
|
||||
| 46033 | CALL FetchFrames | Load a step count from the frame counter and set the group terminator in A. | ||
| 46036 | LD B,A | |||
| 46037 | LD A,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 pointer from the stack. | ||
| 46055 | LD B,(HL) | Fetch the item ID into B and stash the pointer again. | ||
| 46056 | PUSH HL | |||
| 46057 | CALL SetItemRoom | Call SetItemRoom to store the item's room. | ||
| 46060 | POP HL | Restore the scenic scan 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 |