![]() |
Routines |
| Prev: AB03 | Up: Map | Next: AB88 |
|
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 | AB0A | LD A,($A77E) | Load *Flag_TurnBasedEventState into A. | |
| AB0D | OR A | Jump to GameScenicEventsProcessor if no turn-based events are currently active. | ||
| AB0E | JR Z,GameScenicEventsProcessor | |||
|
Eight turn-based events share the flag byte.
|
||||
| AB10 | LD C,A | Copy the turn-based event flags into C. | ||
| AB11 | 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 | AB13 | SRL C | Shift C right so bit 0 (the next event flag) goes into the carry flag. | |
| AB15 | JR NC,GameEventChecker_Next | Jump to GameEventChecker_Next if this event bit is not set. | ||
|
Count down this event's timer.
|
||||
| AB17 | LD DE,$0000 | Initialise DE to 00. | ||
| AB1A | LD HL,$A77F | HL=Counter_Drowning. | ||
| AB1D | LD A,$08 | Calculate the event index (08-B) and store it in E. | ||
| AB1F | SUB B | |||
| AB20 | LD E,A | |||
| AB21 | ADD HL,DE | Point HL at this event's countdown timer. | ||
| AB22 | DEC (HL) | Decrease this event's countdown timer by one. | ||
| AB23 | 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.
|
||||
| AB25 | LD IX,($A7C8) | IX=*Pointer_TurnBasedEvents_Jump. | ||
| AB29 | SLA E | Double the event index, as each entry in the table is two bytes. | ||
| AB2B | ADD IX,DE | Point IX at this event's entry in the table. | ||
| AB2D | LD L,(IX+$00) | Read that handler's address into HL. | ||
| AB30 | LD H,(IX+$01) | |||
| AB33 | PUSH BC | Stash BC on the stack. | ||
| AB34 | LD DE,$AB39 | Stash GameEventChecker_Return on the stack so the next return resumes event processing. | ||
| AB37 | PUSH DE | |||
| AB38 | 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 | AB39 | POP BC | Restore BC from the stack. | |
|
Test the next turn-based event.
|
||||
| GameEventChecker_Next | AB3A | 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 | AB3C | NOP | No operation. | |
| AB3D | LD HL,($A7E2) | HL=*Pointer_ScenicEventItems. | ||
| AB40 | LD A,($A7EE) | Fetch the number of active scenic events from Count_ScenicEvents. | ||
| AB43 | OR A | |||
| AB44 | JR Z,GameEventsProcessor_Return | Jump to GameEventsProcessor_Return if there are no active scenic events. | ||
| AB46 | LD B,A | Set a counter in B for the number of scenic events. | ||
| AB47 | JR GameScenicEventChecker | Jump to GameScenicEventChecker to process the first scenic event without advancing the table pointer. | ||
|
This is the main scenic event loop.
|
||||
| GameScenicEventChecker_Loop | AB49 | INC HL | Move on to the next scenic item. | |
| GameScenicEventChecker | AB4A | LD A,(HL) | Fetch this scenic event's item ID. | |
| AB4B | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| AB4C | CALL ItemLocator | Call ItemLocator to find where this scenic event's item is. | ||
| AB4F | POP HL | Restore the scenic event table pointer from the stack. | ||
| AB50 | AND A | Set the flags from the item location in A. | ||
| AB51 | JR Z,GameScenicEventChecker_Next | Jump to GameScenicEventChecker_Next if the item is inactive. | ||
| AB53 | LD C,A | Hold this event's room in C. | ||
| AB54 | LD A,($A7C3) | A=*CurrentRoom. | ||
| AB57 | CP C | Compare the current room with the item location. | ||
| AB58 | JR Z,GameScenicEventChecker_Next | Jump to GameScenicEventChecker_Next if the item is in the current room. | ||
|
Pick a room for this scenic event.
|
||||
| AB5A | PUSH BC | Stash BC and HL on the stack. | ||
| AB5B | PUSH HL | |||
|
Calculate which scenic event's room group this is.
|
||||
| AB5C | LD A,($A7EE) | Calculate the index of the currently processed event. | ||
| AB5F | SUB B | |||
| AB60 | LD E,A | |||
|
Point at this event's room list.
|
||||
| AB61 | LD IX,($A7E4) | IX=*Pointer_ScenicEventRooms. | ||
|
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).
|
||||
| AB65 | CALL GetTableEntry | Call GetTableEntry. | ||
|
The routine at FetchFrames picks how far to walk into the room group.
|
||||
| AB68 | CALL FetchFrames | Call FetchFrames to pick a random step count and store it in B. | ||
| AB6B | LD B,A | |||
| AB6C | LD A,$FF | A=the room group terminator (FF). | ||
|
The table at Pointer_ScenicEventRooms is indexed by event (there are 11 entries), and 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 FF.
|
||||
| GameScenicEvent_FetchRoomGroup | AB6E | LD L,(IX+$00) | Point HL at the start of this room group. | |
| AB71 | LD H,(IX+$01) | |||
| AB74 | 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 | AB76 | INC HL | Move to the next room ID in the group. | |
| GameScenicEvent_CountRoomsInGroup | AB77 | CP (HL) | Jump back to GameScenicEvent_FetchRoomGroup when the terminator matches. | |
| AB78 | JR Z,GameScenicEvent_FetchRoomGroup | |||
| AB7A | DJNZ GameScenicEvent_CountRooms_Loop | Decrease the random counter by one and loop back to GameScenicEvent_CountRooms_Loop until the counter is zero. | ||
| AB7C | LD C,(HL) | Fetch the destination room into C. | ||
| AB7D | POP HL | Restore the scenic event table pointer from the stack. | ||
| AB7E | LD B,(HL) | Fetch this scenic event's item ID into B. | ||
| AB7F | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| AB80 | CALL Handler_UpdateItemLocation | Call Handler_UpdateItemLocation. | ||
| AB83 | POP HL | Restore HL and BC from the stack. | ||
| AB84 | POP BC | |||
| GameScenicEventChecker_Next | AB85 | 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 | AB87 | RET | Return. | |
|
View the equivalent code in;
|
||||
| Prev: AB03 | Up: Map | Next: AB88 |