![]() |
Routines |
| Prev: A275 | Up: Map | Next: A305 |
|
Used by the routine at GameStart.
Counts down the turn-based events in Flags_TurnEvents and, when a counter reaches zero, runs the handler from JumpTable_TurnEvents.
Then relocates any scenic event that is not already in the current room, picking the new room from the group at Table_ScenicEventRoomGroups.
|
||||
|
First process the turn-based events (if any are active).
|
||||
| Handler_GameEvents | A280 | LD A,($A0C8) | A=*Flags_TurnEvents. | |
| A283 | OR A | Jump to ScenicEvents_Start if no turn-based events are currently active. | ||
| A284 | JR Z,ScenicEvents_Start | |||
|
Eight turn-based events share the flag byte.
|
||||
| A286 | LD C,A | Copy the turn-based event flags into C. | ||
| A287 | 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.
|
||||
| TurnEvent_NextBit | A289 | SRL C | Shift the next event flag into the carry. | |
| A28B | JR NC,TurnEvent_Next | Jump to TurnEvent_Next if this event bit is not set. | ||
|
Count down this event's timer.
|
||||
| A28D | LD DE,$0000 | Initialise DE to 00. | ||
| A290 | LD HL,$A0C9 | HL=TurnEventCounters. | ||
| A293 | LD A,$08 | Calculate the event index (08-B) and store it in E. | ||
| A295 | SUB B | |||
| A296 | LD E,A | |||
| A297 | ADD HL,DE | Point HL at this event's countdown timer. | ||
| A298 | DEC (HL) | Decrease this event's countdown timer by one. | ||
| A299 | JR NZ,TurnEvent_Next | Jump to TurnEvent_Next if this event's countdown timer is still running. | ||
|
The timer has expired, so run this event's script.
|
||||
| A29B | PUSH IX | Stash IX and BC on the stack. | ||
| A29D | PUSH BC | |||
| A29E | LD IX,$BBB9 | IX=JumpTable_TurnEvents. | ||
| A2A2 | SLA E | Double the event index, as each entry in the table is two bytes. | ||
| A2A4 | ADD IX,DE | Point IX at this event's entry in the table. | ||
| A2A6 | LD L,(IX+$00) | Read that script's address into HL. | ||
| A2A9 | LD H,(IX+$01) | |||
| A2AC | PUSH HL | Copy the script address from HL into IX (using the stack). | ||
| A2AD | POP IX | |||
| A2AF | CALL Handler_RunScript | Call Handler_RunScript. | ||
| A2B2 | POP BC | Restore BC and IX from the stack. | ||
| A2B3 | POP IX | |||
|
Test the next turn-based event.
|
||||
| TurnEvent_Next | A2B5 | DJNZ TurnEvent_NextBit | Decrease the event bit counter by one and loop back to TurnEvent_NextBit until all eight events have been considered. | |
|
Now handle the scenic events.
|
||||
| ScenicEvents_Start | A2B7 | LD HL,$B6BA | HL=Table_ScenicEventItems. | |
| A2BA | LD A,($BBCF) | Fetch the number of active scenic events from Count_ScenicEvents. | ||
| A2BD | OR A | |||
| A2BE | JR Z,Handler_GameEvents_Return | Jump to Handler_GameEvents_Return if there are no active scenic events. | ||
| A2C0 | LD B,A | Set a counter in B for the number of scenic events. | ||
| A2C1 | JR ScenicEvent_Item | Jump to ScenicEvent_Item to process the first scenic event without advancing the table pointer. | ||
|
Room 00 means this scenic item is inactive.
|
||||
| ScenicEvent_Next | A2C3 | INC HL | Move on to the next scenic item. | |
| ScenicEvent_Item | A2C4 | LD A,(HL) | Fetch this scenic event's item ID. | |
| A2C5 | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| A2C6 | CALL ItemLocator | Call ItemLocator to read where this item is. | ||
| A2C9 | POP HL | Restore the scenic event table pointer from the stack. | ||
| A2CA | AND A | Jump to ScenicEvent_Done if the item is inactive. | ||
| A2CB | JR Z,ScenicEvent_Done | |||
|
An event that is already in the player's room stays there.
|
||||
| A2CD | LD C,A | Hold this event's room in C. | ||
| A2CE | LD A,($A106) | A=*CurrentRoom. | ||
| A2D1 | CP C | Jump to ScenicEvent_Done if this event's room is the current room. | ||
| A2D2 | JR Z,ScenicEvent_Done | |||
|
Pick a room for this scenic event.
|
||||
| A2D4 | PUSH IX | Stash IX, BC and HL on the stack. | ||
| A2D6 | PUSH BC | |||
| A2D7 | PUSH HL | |||
| A2D8 | LD A,($BBCF) | Calculate which event's group this is. | ||
| A2DB | SUB B | |||
| A2DC | LD E,A | |||
|
Point at this event's room list.
|
||||
| A2DD | LD IX,$B6BF | IX=Table_ScenicEventRoomGroups. | ||
| A2E1 | CALL GetTableEntry | Call GetTableEntry to fetch this event's room group. | ||
|
The refresh register picks how far to walk into the room group. FF ends the group and the walk wraps.
|
||||
| A2E4 | LD A,R | Use the Memory Refresh Register to pick a random step count and store it in B. | ||
| A2E6 | LD B,A | |||
| A2E7 | LD A,$FF | A=the room group terminator (FF). | ||
| ScenicRoom_Reload | A2E9 | LD L,(IX+$00) | Point HL at the start of this room group. | |
| A2EC | LD H,(IX+$01) | |||
| A2EF | JR ScenicRoom_Check | Jump to ScenicRoom_Check. | ||
|
Walk the room group. FF restarts it, and the refresh count chooses where to stop. Then move the scenic item there.
|
||||
| ScenicRoom_Next | A2F1 | INC HL | Move to the next room in the group. | |
| ScenicRoom_Check | A2F2 | CP (HL) | Jump back to ScenicRoom_Reload when the terminator matches. | |
| A2F3 | JR Z,ScenicRoom_Reload | |||
| A2F5 | DJNZ ScenicRoom_Next | Decrease the step counter by one and loop back to ScenicRoom_Next until the counter is zero. | ||
| A2F7 | LD C,(HL) | Fetch the destination room into C. | ||
| A2F8 | POP HL | Restore the scenic event table pointer from the stack. | ||
| A2F9 | LD B,(HL) | Fetch this scenic event's item ID into B. | ||
| A2FA | PUSH HL | Stash the scenic event table pointer on the stack. | ||
| A2FB | CALL Handler_UpdateItemLocation | Call Handler_UpdateItemLocation. | ||
| A2FE | POP HL | Restore HL, BC and IX from the stack. | ||
| A2FF | POP BC | |||
| A300 | POP IX | |||
|
Move on to the next scenic event.
|
||||
| ScenicEvent_Done | A302 | DJNZ ScenicEvent_Next | Decrease the scenic event counter by one and loop back to ScenicEvent_Next until every scenic event has been considered. | |
| Handler_GameEvents_Return | A304 | RET | Return. | |
|
View the equivalent code in;
|
||||
| Prev: A275 | Up: Map | Next: A305 |