Prev: 5FEF Up: Map Next: 6028
6009: Run Main Loop
Used by the routines at HandlerCup and Pause_Loop.
The game loop. Each pass runs the handler for each of the three entities held from Entity_Player (the player's car and the two opponent cars), in turn. The handler is chosen by the entity state held in the first byte of the entity, using the table at JumpTable_Main. Once every entity has been handled NextEntity plays the engine sound, checks for a pause and starts the loop again.
State Meaning
00 Inactive
01 Player car driving
02 Opponent car driving
03 Player car exploding
MainLoop_NewPass 6009 LD IX,$5E80 Point IX at the first entity, the player's car (Entity_Player).
600D LD SP,$5E00 Set the stack pointer to 5E00.
This entry point is used by the routine at NextEntity.
Dispatch the handler for this entity.
MainLoop 6010 LD HL,$6A73 Stash NextEntity on the stack as the return address for the handler.
6013 PUSH HL
6014 LD HL,$6028 Point HL at the table of handlers (JumpTable_Main).
6017 LD A,(IX+$00) Fetch the entity state from *IX+00.
601A RLCA Rotate the state left, ready to use it as an index into the table of words.
601B AND %01111110 Keep only bits 1-6.
601D LD C,A Make the offset into the table of handlers in BC.
601E LD B,$00
6020 ADD HL,BC Add the offset to the address of the table.
6021 LD A,(HL) Fetch the address of the handler from the table into HL.
6022 INC HL
6023 LD H,(HL)
6024 LD L,A
6025 JP IndirectJump Jump to the handler via IndirectJump.
Prev: 5FEF Up: Map Next: 6028