Prev: 9960 Up: Map Next: 99F0
99AA: Run Main Loop
Used by the routine at UpdateCounters.
Every actor (the player, the animals, the tribesmen, the objects and so on) is held in a 0C byte record in the actor table, which runs from ImmortalData to StoredActorTable. The first byte of each record is the sprite ID, and this is also the index into the jump table at JumpTable which selects the handler routine for the actor.
The handler for one actor is run per pass of MainLoop_NextActor. When the frame counter changes the actor currently being processed is remembered in SavedActorPointer (this happens every frame, 50 times a second), the player's actor (ImmortalData) is processed straight away and then the loop carries on from where it was interrupted. Once every actor has been processed, UpdateCounters runs.
MainLoop 99AA LD SP,$6000 Set the stack pointer to GameEntry.
99AD EI Enable interrupts.
99AE LD IX,$970E Point IX at the first actor after the player, at ImmortalData_Actors.
This entry point is used by the routine at NextActor.
Check if the frame counter has changed since the last time through.
MainLoop_NextActor 99B2 LD A,($5C78) Fetch the low byte of the frame counter from FRAMES into C.
99B5 LD C,A
99B6 LD A,($9696) Fetch the frame counter from the previous pass from LastFrame.
99B9 CP C Jump to MainLoop_RunHandler if the frame counter has not changed.
99BA JR Z,MainLoop_RunHandler
FrameUpdate 99BC DI Disable interrupts.
99BD LD A,($5C78) Remember the new frame counter in LastFrame.
99C0 LD ($9696),A
99C3 LD A,$01 Set the frame updated flag in FrameUpdated.
99C5 LD ($9697),A
99C8 LD ($96A9),IX Remember which actor was being processed in SavedActorPointer.
99CC LD IX,$9702 Point IX at the player's actor at ImmortalData.
Update the random number seed using the Z80 refresh register.
MainLoop_RunHandler 99D0 LD A,R Fetch the Z80 refresh register as a source of randomness.
99D2 LD C,A Stash it in C.
99D3 LD A,($9695) Fetch the random seed from RandomNumber.
99D6 ADC A,C Mix in the refresh register value and the carry flag.
99D7 LD ($9695),A Store the new random seed in RandomNumber.
Run the handler for this actor. The handler returns to NextActor, so push that address first, then use the sprite ID to find the handler in the jump table.
99DA LD HL,$99F0 Stash the return address NextActor on the stack so the handler returns to it.
99DD PUSH HL
99DE LD BC,$9B3E Point BC at the handler jump table at JumpTable.
See See Ending.
99E1 LD A,(IX+$00) Fetch the sprite ID of the actor into HL.
99E4 LD L,A
99E5 LD H,$00
99E7 ADD HL,HL Double the sprite ID to get the offset into the jump table.
99E8 ADD HL,BC Add the jump table address to get the address of the actor's entry.
99E9 LD A,(HL) Fetch the address of the handler from the jump table.
99EA INC HL
99EB LD H,(HL)
99EC LD L,A
99ED JP IndirectJump Jump to IndirectJump, which jumps to the address held in HL.
Prev: 9960 Up: Map Next: 99F0