![]() |
Routines |
| Prev: B364 | Up: Map | Next: B3F1 |
|
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's timer.
|
||||
| B380 | LD DE,$0000 | Initialise DE to 00. | ||
| B383 | LD HL,$AE89 | HL=Counter_Unused_0. | ||
| B386 | LD A,$08 | Calculate the event index (08-B) and store it in E. | ||
| B388 | SUB B | |||
| B389 | LD E,A | |||
| B38A | ADD HL,DE | Point HL at this event's countdown timer. | ||
| B38B | DEC (HL) | Decrease this event's countdown timer by one. | ||
| B38C | 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.
|
||||
| B38E | LD IX,($AED2) | IX=*Pointer_TurnBasedEvents_Jump. | ||
| B392 | SLA E | Double the event index, as each entry in the table is two bytes. | ||
| B394 | ADD IX,DE | Point IX at this event's entry in the table. | ||
| B396 | LD L,(IX+$00) | Read that handler's address into HL. | ||
| B399 | LD H,(IX+$01) | |||
| B39C | PUSH BC | Stash BC on the stack. | ||
| B39D | LD DE,$B3A2 | Stash GameEventChecker_Return on 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 BC 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. | |
|
Now handle the 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) | HL=*Pointer_Spare. | ||
| B3A9 | LD A,($AEF8) | Fetch the number of active scenic events from Count_ScenicEvents. | ||
| B3AC | OR A | |||
| B3AD | JR Z,GameEventsProcessor_Return | Jump to GameEventsProcessor_Return if there are no active scenic events. | ||
| B3AF | LD B,A | Set a counter in B for the number of scenic events. | ||
| B3B0 | JR GameScenicEventChecker | Jump to GameScenicEventChecker to process the first scenic event without advancing the table pointer. | ||
|
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 event's item ID. | |
| B3B4 | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| B3B5 | CALL GetItemRoom | Call GetItemRoom to read which room holds the item. | ||
| B3B8 | POP HL | Restore the scenic event table pointer 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 | Hold this event's room in C. | ||
| B3BD | LD A,($AECD) | A=*CurrentRoom. | ||
| B3C0 | CP C | Jump to GameScenicEventChecker_Next if this event's room is the current room. | ||
| B3C1 | JR Z,GameScenicEventChecker_Next | |||
|
Pick a room for this scenic event.
|
||||
| B3C3 | PUSH BC | Stash BC and HL on the stack. | ||
| B3C4 | PUSH HL | |||
| B3C5 | LD A,($AEF8) | Calculate which event's group this is. | ||
| B3C8 | SUB B | |||
| B3C9 | LD E,A | |||
|
Point at this event's room list.
|
||||
| B3CA | LD IX,($AEEE) | IX=*Pointer_Spare2. | ||
| 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 | Call FetchFrames to pick a random step count and store it in B. | ||
| B3D4 | LD B,A | |||
| B3D5 | LD A,$FF | A=the room group terminator (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 table pointer from the stack. | ||
| B3E7 | LD B,(HL) | Fetch this scenic event's item ID into B. | ||
| B3E8 | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| B3E9 | CALL SetItemRoom | Call SetItemRoom to store the item's room. | ||
| B3EC | POP HL | Restore HL and BC 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. | |
|
View the equivalent code in;
|
||||
| Prev: B364 | Up: Map | Next: B3F1 |