Prev: 41821 Up: Map Next: 42002
41837: 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 41837 LD SP,24064 Reset the stack pointer to just below the start of the game.
41840 LD A,(23673) Fetch the high byte of the system frame counter.
41843 CP 86 Return unless it holds 86 which is the value the tape loader leaves there.
41845 RET NZ
Clear the game variables.
41846 LD HL,41479 Clear everything from MovementSoundCounter onwards, 358 bytes in all, which covers every game variable.
41849 LD BC,358
41852 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 41854 LD HL,41532 Clear everything from SoundNotesLeft onwards, 305 bytes in all.
41857 LD BC,305
InitialiseGame_Clear 41860 CALL FillMemory Fill the memory with zero.
Set up the machine and show the title screen.
41863 CALL BuildShiftTables Build the pixel shifting lookup tables.
41866 LD A,195 Write the opcode for a 195 (JP) instruction to SpriteJumpOpcode, ready for the sprite drawing routines to use.
41868 LD (41508),A
41871 XOR A Set the border to black.
41872 OUT (254),A
41874 CALL GameMenu Show the title screen and wait for the player to start the game.
41877 LD A,(41500) Fetch the option flags.
41880 OR %00001000 Set bit 3, which records that a game is under way.
41882 LD (41500),A Store the option flags again.
41885 CALL PrepareTopScoreText Convert the top score into text for the telegram panel.
41888 CALL SetUpPlayers Give both players their starting values.
41891 CALL ClearBuffer Clear the off-screen playfield buffer.
41894 LD A,1 Write 1 to StageRunningFlag to show that a new stage is starting.
41896 LD (41536),A
41899 LD A,(41500) Fetch the option flags again.
41902 BIT 0,A Test bit 0, which is set for a two player game.
41904 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 41907 LD A,(41574) Fetch the border and paper colour for the stage and keep the stage colour in E.
41910 LD E,A
41911 CALL DrawGameScreen Draw the screen furniture.
The main loop. It runs once for every frame of the game.
MainLoop 41914 XOR A Write 0 to ObjectsDrawnCount to clear the count of objects drawn this frame.
41915 LD (41539),A
41918 LD SP,24064 Reset the stack pointer, so that nothing can build up on the stack.
41921 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.
41924 LD IX,41597 Point IX at ObjectSlot_01.
MainLoopNextObject 41928 LD A,(IX+0) Fetch the type of the object in this slot.
41931 LD BC,42002 Point BC at ObjectHandlerTable.
41934 CALL RunTableRoutine Call the handler for the type of object.
41937 CALL UpdateRandomNumbers Update the random number seeds.
41940 LD BC,16 Set the size of an object slot in BC.
41943 ADD IX,BC Move IX on to the next slot.
41945 PUSH IX Copy the slot address into HL (using the stack).
41947 POP HL
41948 LD BC,41837 The address past the last object slot goes into BC.
41951 AND A Loop back to MainLoopNextObject until IX has moved past the last slot.
41952 SBC HL,BC
41954 JR C,MainLoopNextObject
Now do everything which does not belong to a single object.
41956 CALL AdvanceFrameCounter Advance the frame counter.
41959 CALL RunStageScript Create any objects which the current stage needs.
41962 CALL DrawScenery Draw the scenery sprites.
41965 CALL DrawTown Draw the town.
41968 CALL FlashChamber Flash the chamber of the revolver which has just fired.
41971 CALL CopyBufferAndClear Copy the playfield buffer to the screen.
41974 CALL PlaySoundEffect Play the next note of any sound effect.
41977 CALL TypeTelegram Print the next letter of the telegram.
41980 CALL FinishTownStage Check whether the outlaw has been caught.
41983 CALL CreateTownObjects Create new townspeople, the outlaw and the other town objects.
41986 CALL PauseGame Pause the game if the pause key is being pressed.
41989 LD A,(41572) Fetch the number of targets remaining in the stage and keep the number of targets left in C.
41992 LD C,A
41993 LD A,(41539) Fetch the count of objects drawn this frame.
41996 OR C Combine the two counts.
41997 JP Z,ReturnToTown Jump to ReturnToTown if the stage has nothing left to do.
42000 JR MainLoop Otherwise loop back to MainLoop for the next frame.
Prev: 41821 Up: Map Next: 42002