Prev: 6428 Up: Map Next: 6486
6457: Run Main Loop
Used by the routine at CreateActor.
The main loop of the game. Each pass through the loop runs the handler for one actor. The handler is chosen by the actor ID, using the table at ActorHandlers. The address of NextActor is put on the stack first, so that when the handler returns, the game moves on to the next actor.
A pass is started at MainLoop_NewPass with the first of the six actors which start at ActorSpawnSlots. Whenever the frame counter has changed, FrameUpdate runs an extra pass over the first four actors (which are Charlie and the sound effect actor).
Input
IX Actor
MainLoop_NewPass 6457 LD SP,$5F00 Set the stack pointer to SecurityCheck.
645A EI Enable interrupts.
645B LD IX,$5F55 Start with the first of the six spawn slots (ActorSpawnSlots).
645F XOR A Write 00 to ActorsInPlay to reset the current nasties.
6460 LD ($5F1B),A
This entry point is used by the routines at FrameUpdate and NextActor.
Run the frame update if the frame counter has changed.
MainLoop 6463 LD A,($5C78) Compare FRAMES and LastFrame.
6466 LD C,A
6467 LD A,($5F22)
If interrupts are enabled, then FrameUpdate will be called and DI executed.
646A CP C If they are not equal call FrameUpdate.
646B CALL NZ,FrameUpdate
Make the handler return to NextActor, then find the handler.
646E LD HL,$71A3 Point HL at NextActor (the routine for the next actor).
6471 PUSH HL Stash it on the stack, so that the handler returns to it.
6472 LD HL,$6486 Point HL at ActorHandlers.
6475 LD A,(IX+$00) Fetch the actor ID.
This entry point is used by the routine at HandleMonster.
MainLoop_Dispatch 6478 RLCA Double the ID, as there are two bytes for each handler.
6479 AND %01111110 Keep only bits 1-6 (bits 0-5 of the ID, doubled).
647B LD C,A Use the result as an offset into the table of handlers.
647C LD B,$00
647E ADD HL,BC Find the entry for the handler of this actor.
647F LD A,(HL) Fetch the low byte of the handler address.
6480 INC HL Move onto the high byte.
6481 LD H,(HL) Fetch the high byte of the handler address.
6482 LD L,A Put the low byte in L, so that HL is the address of the handler.
6483 JP $5CB0 Jump to NMIADD which should just jump to the address in HL.
Prev: 6428 Up: Map Next: 6486