Prev: A35D Up: Map Next: A412
A36D: Initialise Game
Used by the routine at GameStart.
The real start of the game. It checks the loader's signature, clears the game variables, builds the lookup tables, shows the title screen and menu, sets up the first player and then falls into the main loop at MainLoop.
When a game has ended and the high score has been shown, control comes back to RestartGame so that the title screen is shown again.
InitialiseGame A36D LD SP,$5E00 Reset the stack pointer to just below the start of the game.
A370 LD A,($5C79) Fetch the high byte of the system frame counter.
A373 CP $56 Return unless it holds 56 which is the value the tape loader leaves there.
A375 RET NZ
Clear the game variables.
A376 LD HL,$A207 Clear everything from MovementSoundCounter onwards, 0166 bytes in all, which covers every game variable.
A379 LD BC,$0166
A37C JR InitialiseGame_Clear Skip over the shorter clear below.
This entry point is used by the routine at CheckTopScore.
This entry point is used when the game has ended. It keeps the frame counter, the random seeds and the control method chosen on the menu.
RestartGame A37E LD HL,$A23C Clear everything from SoundNotesLeft onwards, 0131 bytes in all.
A381 LD BC,$0131
InitialiseGame_Clear A384 CALL FillMemory Fill the memory with zero.
Set up the machine and show the title screen.
A387 CALL BuildShiftTables Build the pixel shifting lookup tables.
A38A LD A,$C3 Write the opcode for a C3 (JP) instruction to SpriteJumpOpcode, ready for the sprite drawing routines to use.
A38C LD ($A224),A
A38F XOR A Set the border to black.
A390 OUT ($FE),A
A392 CALL GameMenu Show the title screen and wait for the player to start the game.
A395 LD A,($A21C) Fetch the option flags.
A398 OR %00001000 Set bit 3, which records that a game is under way.
A39A LD ($A21C),A Store the option flags again.
A39D CALL PrepareTopScoreText Convert the top score into text for the telegram panel.
A3A0 CALL SetUpPlayers Give both players their starting values.
A3A3 CALL ClearBuffer Clear the off-screen playfield buffer.
A3A6 LD A,$01 Write 01 to StageRunningFlag to show that a new stage is starting.
A3A8 LD ($A240),A
A3AB LD A,($A21C) Fetch the option flags again.
A3AE BIT 0,A Test bit 0, which is set for a two player game.
A3B0 CALL NZ,ShowPlayerNumber Print the current player number if there are two players.
This entry point is used by the routines at FinishTownStage, GiveReward and ReturnToTown.
Draw the screen for the next stage of the game and run it.
StartStage A3B3 LD A,($A266) Fetch the border and paper colour for the stage and keep the stage colour in E.
A3B6 LD E,A
A3B7 CALL DrawGameScreen Draw the screen furniture.
The main loop. It runs once for every frame of the game.
MainLoop A3BA XOR A Write 00 to ObjectsDrawnCount to clear the count of objects drawn this frame.
A3BB LD ($A243),A
A3BE LD SP,$5E00 Reset the stack pointer, so that nothing can build up on the stack.
A3C1 CALL CheckSheriffLost Check whether the player has been lost and deal with it if so.
Run the handler for each of the fifteen object slots in turn.
A3C4 LD IX,$A27D Point IX at ObjectSlot_01.
MainLoopNextObject A3C8 LD A,(IX+$00) Fetch the type of the object in this slot.
A3CB LD BC,$A412 Point BC at ObjectHandlerTable.
A3CE CALL RunTableRoutine Call the handler for the type of object.
A3D1 CALL UpdateRandomNumbers Update the random number seeds.
A3D4 LD BC,$0010 Set the size of an object slot in BC.
A3D7 ADD IX,BC Move IX on to the next slot.
A3D9 PUSH IX Copy the slot address into HL (using the stack).
A3DB POP HL
A3DC LD BC,$A36D The address past the last object slot goes into BC.
A3DF AND A Loop back to MainLoopNextObject until IX has moved past the last slot.
A3E0 SBC HL,BC
A3E2 JR C,MainLoopNextObject
Now do everything which does not belong to a single object.
A3E4 CALL AdvanceFrameCounter Advance the frame counter.
A3E7 CALL RunStageScript Create any objects which the current stage needs.
A3EA CALL DrawScenery Draw the scenery sprites.
A3ED CALL DrawTown Draw the town.
A3F0 CALL FlashChamber Flash the chamber of the revolver which has just fired.
A3F3 CALL CopyBufferAndClear Copy the playfield buffer to the screen.
A3F6 CALL PlaySoundEffect Play the next note of any sound effect.
A3F9 CALL TypeTelegram Print the next letter of the telegram.
A3FC CALL FinishTownStage Check whether the outlaw has been caught.
A3FF CALL CreateTownObjects Create new townspeople, the outlaw and the other town objects.
A402 CALL PauseGame Pause the game if the pause key is being pressed.
A405 LD A,($A264) Fetch the number of targets remaining in the stage and keep the number of targets left in C.
A408 LD C,A
A409 LD A,($A243) Fetch the count of objects drawn this frame.
A40C OR C Combine the two counts.
A40D JP Z,ReturnToTown Jump to ReturnToTown if the stage has nothing left to do.
A410 JR MainLoop Otherwise loop back to MainLoop for the next frame.
Prev: A35D Up: Map Next: A412