Prev: 48270 Up: Map Next: 48863
48638: Start Game
Used by the routine at GameEntry.
Checks that the game was started by the tape loader, clears the game variables, shows the game selection menu, sets up the status panel and the first life, and then falls into the main loop.
The first check is part of the copy protection: the game returns to BASIC if the high byte of the system variable FRAMES is not 99 (the loader arranges for it to be). The routine at BuildRandomTable makes a second check on the memory refresh register.
start-game
Check that the game was started by the tape loader.
StartGame 48638 LD A,(23673) Return if the high byte of the system variable FRAMES (23673) is not 99.
48641 CP 99
48643 RET NZ
Clear the game variables.
48644 LD SP,24064 Set the stack pointer to GameEntry, so that the stack grows down from the start of the game.
48647 LD HL,48042 Point at the start of the game variables (RandomSeed).
48650 LD BC,596 Set the number of bytes to clear to 596.
48653 JR StartGame_Clear Jump to StartGame_Clear.
This entry point is used by the routines at GameOver and UpdateLogoPiece.
Starting a new game after a game over keeps the random seed, the font pointer, the stack pointer and the control settings at the start of the game variables.
StartGame_KeepSettings 48655 DEFB 33,180,187,1,74,2 Instructions skipped when starting from scratch: load HL with CellColumn and BC with 586.
StartGame_Clear 48661 CALL FillMemory Clear the game variables.
Seed the random number generator and show the game selection menu.
48664 LD HL,(23672) Fetch the low word of the system variable FRAMES.
48667 LD (48050),HL Use it as the starting value of the frame counter.
48670 CALL ClearScreen Clear the screen.
48673 CALL BuildShiftTables Build the pixel shifting tables used when drawing sprites.
48676 CALL GameMenu Show the game selection menu.
48679 LD DE,51192 Point at the notes of the start-of-game tune.
48682 CALL PlayMusic Play the tune.
Draw the status panel around the playing area.
48685 CALL ClearScreen Clear the screen.
48688 CALL DrawPlayingAreaBorder Draw the border of the playing area.
48691 CALL DrawInventoryTube Draw the inventory tube.
48694 LD HL,3896 Set the screen position of the word "SCORE" (3896).
48697 LD DE,49895 Point at the text "SCORE".
48700 CALL PrintStringWithAttribute Print "SCORE".
48703 CALL PrintScore Print the score.
48706 CALL DrawCompassIcon Draw the compass icon.
48709 CALL DrawCompassText Draw the compass text.
48712 CALL ClearScreenBuffer Clear the playing area.
Set up the first life.
48715 LD A,10 Set the player's speed to 10.
48717 LD (48062),A
48720 LD A,(48861) Fetch the opcode of the instruction at 48861 (24).
48723 SRL A Divide it by four to get six lives.
48725 SRL A
48727 LD (48077),A Set the number of lives.
48730 CALL ChooseStartPosition Choose a random starting position for the player.
48733 LD A,64 Set the direction that the player starts facing.
48735 LD (52284),A
48738 CALL StartNewLife Start the player's first life.
48741 CALL PlaceMonsters Place the four monsters in the village.
48744 CALL PlaceItems Place the starting items in the village.
48747 CALL DrawMonsterIcons Draw the icons of the four monsters in the status panel.
48750 CALL BuildRandomTable Build the table of random values.
This entry point is used by the routine at GameOver.
The main loop. Each pass updates every object, draws the view, and then checks for the game being paused.
MainLoop 48753 LD IX,48270 Start with the first object, which is the player.
MainLoop_UpdateObjects 48757 LD A,(IX+0) Fetch the type of the object.
48760 LD BC,54681 Point at the table of routines that handle each type of object.
48763 CALL JumpToTableRoutine Run the routine that handles this type of object.
48766 CALL RandomNumber Update the random number generator.
48769 LD BC,16 Set the size of an object to 16 bytes.
48772 ADD IX,BC Move on to the next object.
48774 PUSH IX Copy the address of the next object to HL (using the stack).
48776 POP HL
48777 LD BC,48638 Point at the end of the object table.
48780 AND A Subtract the end of the object table from the address of the next object.
48781 SBC HL,BC
48783 JR C,MainLoop_UpdateObjects Jump to MainLoop_UpdateObjects until every object has been updated.
Run the once-per-frame updates.
48785 CALL IncrementFrameCounter Increase the frame counter and update the random number generator.
48788 LD A,(48127) Jump to MainLoop_Redraw if the game has finished (the flag at GameFinishedFlag is set), skipping the rest of the frame.
48791 AND A
48792 JP NZ,MainLoop_Redraw
48795 CALL SpawnItem Update the creatures that chase the player.
48798 CALL SpawnBall Update the shots fired at the player.
48801 CALL SpawnGhost Spawn a new creature if it is time to do so.
48804 CALL SpawnBonus Update the ghost.
48807 CALL PlaySoundEffect Play the next note of the current sound effect.
48810 CALL ColourInventoryItems Update the items shown in the inventory tube.
48813 CALL DrawView Draw the view of the village into the screen buffer.
Colour the area around the player according to the player's health.
48816 LD A,(48115) Fetch the player's health.
48819 LD HL,49253 Point at the table of attribute colours.
48822 CALL AddAToHL Add the health to the address to point at its colour.
48825 LD A,(HL) Fetch the attribute.
48826 EX AF,AF' Switch to AF' to hold the attribute.
48827 LD HL,28784 Set the position of the player's feet on the screen (28784).
48830 CALL CalculateAttributeAddress Get the address in the attribute buffer for this position.
48833 LD B,4 Set the width of the area to 4 attributes.
48835 EX AF,AF' Fetch the attribute.
48836 CALL ColourPlayerAttributes Colour the attributes.
48839 CALL CheckPlayerDead Check whether the player has lost a life.
48842 CALL CheckMonstersDefeated Check whether the player has beaten all four monsters.
Update the screen and check for the pause key.
MainLoop_Redraw 48845 CALL CopyBuffersToScreen Copy the screen buffer onto the screen.
48848 LD A,(48123) Fetch the flag at FlashColour.
48851 LD (48124),A Keep a copy of it for the next frame in PreviousFlashColour.
48854 XOR A Clear the accumulator.
48855 LD (48123),A Reset the flag.
48858 CALL PauseGame Check whether the game has been paused.
48861 JR MainLoop Jump to MainLoop for the next frame.
Prev: 48270 Up: Map Next: 48863