Prev: A688 Up: Map Next: A749
A68B: Run Game
Used by the routine at LeaveRoomToWest.
The main game loop. The first call builds the objects of the room. Every pass through RunGame_Frame is one frame: each object is updated, the visible objects are sorted and drawn, the screen is refreshed and the panel is updated.
After the first pass
run-game
Build the objects of the room.
RunGame A68B CALL BuildRoomObjects Call BuildRoomObjects.
This entry point is used by the routine at GameOver.
Give every object a chance to update itself.
RunGame_Frame A68E LD IX,$5B88 Point IX at PlayerBottomObject.
RunGame_NextObject A692 LD SP,$F100 Set the stack pointer to ReversedByteTable.
A695 LD HL,$A6C0 Point HL at RunGame_ObjectUpdated.
A698 PUSH HL Stash the return address on the stack.
A699 LD A,(IX+$18) Fetch the width of the sprite.
A69C LD (IX+$1C),A Store it as the previous width.
A69F LD A,(IX+$19) Fetch the height of the sprite.
A6A2 LD (IX+$1D),A Store it as the previous height.
A6A5 LD A,(IX+$1A) Fetch the pixel x position of the sprite.
A6A8 LD (IX+$1E),A Store it as the previous x position.
A6AB LD A,(IX+$1B) Fetch the pixel y position of the sprite.
A6AE LD (IX+$1F),A Store it as the previous y position.
This entry point is used by the routine at HandleLastAppearingSparkle.
Jump to the update routine for the sprite.
RunGame_UpdateObject A6B1 LD L,(IX+$00) Fetch the sprite number into L.
A6B4 LD BC,$A7EA Point BC at ObjectUpdateRoutines.
This entry point is used by the routines at SetPlayerSpeed and DrawObjectsInOrder.
RunGame_JumpToHandler A6B7 LD H,$00 Clear the high byte of HL.
A6B9 ADD HL,HL Double the sprite number.
A6BA ADD HL,BC Add the address of the table.
A6BB LD A,(HL) Fetch the low byte of the routine.
A6BC INC HL Move on to the high byte.
A6BD LD H,(HL) Fetch the high byte of the routine.
A6BE LD L,A Put the low byte in L.
A6BF JP (HL) Jump to the update routine.
Stir RandomSeed2 from the refresh register.
RunGame_ObjectUpdated A6C0 LD A,R Fetch the refresh register.
A6C2 LD C,A Copy it to C.
A6C3 LD A,($5B05) Fetch RandomSeed2.
A6C6 ADD A,C Add the refresh register to it.
A6C7 LD ($5B05),A Set RandomSeed2.
Move on to the next object.
A6CA LD BC,$0020 Move IX on by 0020 bytes.
A6CD ADD IX,BC
A6CF PUSH IX Copy IX to HL (using the stack).
A6D1 POP HL
A6D2 LD BC,$6288 Point BC at UnusedAfterObjects.
A6D5 AND A Subtract UnusedAfterObjects from HL.
A6D6 SBC HL,BC
A6D8 JR NC,RunGame_FinishFrame Jump to RunGame_FinishFrame if there are no more objects.
A6DA JR RunGame_NextObject Jump to RunGame_NextObject.
Stir RandomSeed2 from the ROM byte at FrameCounter.
RunGame_FinishFrame A6DC LD HL,($5B02) Fetch FrameCounter.
A6DF INC HL Move on to the next address.
A6E0 LD ($5B02),HL Set FrameCounter.
A6E3 LD A,($5B05) Fetch RandomSeed2.
A6E6 ADD A,(HL) Add the byte of ROM.
A6E7 ADD A,L Add the low byte of the address.
A6E8 ADD A,H Add the high byte of the address.
A6E9 LD ($5B05),A Set RandomSeed2.
A6EC LD HL,$5B12 Point HL at RoomFlags.
A6EF SET 0,(HL) Set bit 0 of RoomFlags.
Draw the room into the screen buffer.
A6F1 CALL ListObjectsToDraw Call ListObjectsToDraw.
A6F4 CALL DrawChangedObjects Call DrawChangedObjects.
A6F7 LD A,($5B24) Fetch GameOverFlag.
A6FA AND A Jump to RunGame_GameOver if it is set.
A6FB JP NZ,RunGame_GameOver
Slow the game down when few objects are drawn.
A6FE LD A,($5B1E) Fetch ObjectsDrawn.
A701 NEG Negate it.
A703 ADD A,$06 Add 06.
A705 LD B,A Keep the number of delay loops in B.
A706 JP M,RunGame_UpdateDisplay Jump to RunGame_UpdateDisplay if there were more than 06 objects.
A709 JR Z,RunGame_UpdateDisplay Jump to RunGame_UpdateDisplay if there were exactly 06 objects.
RunGame_Delay A70B LD HL,$0300 Set the delay counter to 0300.
RunGame_DelayLoop A70E DEC HL Decrease the delay counter.
A70F LD A,L Jump to RunGame_DelayLoop until the delay counter is zero.
A710 OR H
A711 JR NZ,RunGame_DelayLoop
A713 DJNZ RunGame_Delay Jump to RunGame_Delay until all of the delay loops are done.
Update the status panel.
RunGame_UpdateDisplay A715 CALL UpdateLightYears Call UpdateLightYears.
A718 LD A,($5B17) Fetch RedrawPanelFlag.
A71B AND A Jump to RunGame_Continue if it is not set.
A71C JR Z,RunGame_Continue
A71E CALL DrawPanel Call DrawPanel.
A721 CALL UpdatePanel Call UpdatePanel.
RunGame_RefreshScreen A724 XOR A Write 00 to RedrawPanelFlag.
A725 LD ($5B17),A
A728 CALL UpdateScreen Call UpdateScreen.
A72B CALL ResetWipeFlags Call ResetWipeFlags.
Check whether the game is paused and whether the player is alive.
RunGame_Continue A72E CALL PauseGame Call PauseGame.
A731 LD IX,$5B88 Point IX at PlayerBottomObject.
A735 LD A,(IX+$00) Fetch the sprite number of the player.
A738 OR (IX+$20) Combine it with the sprite number of PlayerTopObject.
A73B JP Z,StartLife Jump to StartLife if both are zero.
A73E JP RunGame_Frame Jump to RunGame_Frame.
Only refresh the screen if the panel needs to be redrawn.
RunGame_GameOver A741 LD A,($5B17) Fetch RedrawPanelFlag.
A744 AND A Jump to RunGame_Continue if it is not set.
A745 JR Z,RunGame_Continue
A747 JR RunGame_RefreshScreen Jump to RunGame_RefreshScreen.
View the equivalent code in;
Prev: A688 Up: Map Next: A749