Prev: BC8E Up: Map Next: BEDF
BDFE: 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 63 (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 BDFE LD A,($5C79) Return if the high byte of the system variable FRAMES (5C79) is not 63.
BE01 CP $63
BE03 RET NZ
Clear the game variables.
BE04 LD SP,$5E00 Set the stack pointer to GameEntry, so that the stack grows down from the start of the game.
BE07 LD HL,$BBAA Point at the start of the game variables (RandomSeed).
BE0A LD BC,$0254 Set the number of bytes to clear to 0254.
BE0D 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 BE0F DEFB $21,$B4,$BB,$01,$4A,$02 Instructions skipped when starting from scratch: load HL with CellColumn and BC with 024A.
StartGame_Clear BE15 CALL FillMemory Clear the game variables.
Seed the random number generator and show the game selection menu.
BE18 LD HL,($5C78) Fetch the low word of the system variable FRAMES.
BE1B LD ($BBB2),HL Use it as the starting value of the frame counter.
BE1E CALL ClearScreen Clear the screen.
BE21 CALL BuildShiftTables Build the pixel shifting tables used when drawing sprites.
BE24 CALL GameMenu Show the game selection menu.
BE27 LD DE,$C7F8 Point at the notes of the start-of-game tune.
BE2A CALL PlayMusic Play the tune.
Draw the status panel around the playing area.
BE2D CALL ClearScreen Clear the screen.
BE30 CALL DrawPlayingAreaBorder Draw the border of the playing area.
BE33 CALL DrawInventoryTube Draw the inventory tube.
BE36 LD HL,$0F38 Set the screen position of the word "SCORE" (0F38).
BE39 LD DE,$C2E7 Point at the text "SCORE".
BE3C CALL PrintStringWithAttribute Print "SCORE".
BE3F CALL PrintScore Print the score.
BE42 CALL DrawCompassIcon Draw the compass icon.
BE45 CALL DrawCompassText Draw the compass text.
BE48 CALL ClearScreenBuffer Clear the playing area.
Set up the first life.
BE4B LD A,$0A Set the player's speed to 0A.
BE4D LD ($BBBE),A
BE50 LD A,($BEDD) Fetch the opcode of the instruction at BEDD (18).
BE53 SRL A Divide it by four to get six lives.
BE55 SRL A
BE57 LD ($BBCD),A Set the number of lives.
BE5A CALL ChooseStartPosition Choose a random starting position for the player.
BE5D LD A,$40 Set the direction that the player starts facing.
BE5F LD ($CC3C),A
BE62 CALL StartNewLife Start the player's first life.
BE65 CALL PlaceMonsters Place the four monsters in the village.
BE68 CALL PlaceItems Place the starting items in the village.
BE6B CALL DrawMonsterIcons Draw the icons of the four monsters in the status panel.
BE6E 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 BE71 LD IX,$BC8E Start with the first object, which is the player.
MainLoop_UpdateObjects BE75 LD A,(IX+$00) Fetch the type of the object.
BE78 LD BC,$D599 Point at the table of routines that handle each type of object.
BE7B CALL JumpToTableRoutine Run the routine that handles this type of object.
BE7E CALL RandomNumber Update the random number generator.
BE81 LD BC,$0010 Set the size of an object to 10 bytes.
BE84 ADD IX,BC Move on to the next object.
BE86 PUSH IX Copy the address of the next object to HL (using the stack).
BE88 POP HL
BE89 LD BC,$BDFE Point at the end of the object table.
BE8C AND A Subtract the end of the object table from the address of the next object.
BE8D SBC HL,BC
BE8F JR C,MainLoop_UpdateObjects Jump to MainLoop_UpdateObjects until every object has been updated.
Run the once-per-frame updates.
BE91 CALL IncrementFrameCounter Increase the frame counter and update the random number generator.
BE94 LD A,($BBFF) Jump to MainLoop_Redraw if the game has finished (the flag at GameFinishedFlag is set), skipping the rest of the frame.
BE97 AND A
BE98 JP NZ,MainLoop_Redraw
BE9B CALL SpawnItem Update the creatures that chase the player.
BE9E CALL SpawnBall Update the shots fired at the player.
BEA1 CALL SpawnGhost Spawn a new creature if it is time to do so.
BEA4 CALL SpawnBonus Update the ghost.
BEA7 CALL PlaySoundEffect Play the next note of the current sound effect.
BEAA CALL ColourInventoryItems Update the items shown in the inventory tube.
BEAD CALL DrawView Draw the view of the village into the screen buffer.
Colour the area around the player according to the player's health.
BEB0 LD A,($BBF3) Fetch the player's health.
BEB3 LD HL,$C065 Point at the table of attribute colours.
BEB6 CALL AddAToHL Add the health to the address to point at its colour.
BEB9 LD A,(HL) Fetch the attribute.
BEBA EX AF,AF' Switch to AF' to hold the attribute.
BEBB LD HL,$7070 Set the position of the player's feet on the screen (7070).
BEBE CALL CalculateAttributeAddress Get the address in the attribute buffer for this position.
BEC1 LD B,$04 Set the width of the area to 04 attributes.
BEC3 EX AF,AF' Fetch the attribute.
BEC4 CALL ColourPlayerAttributes Colour the attributes.
BEC7 CALL CheckPlayerDead Check whether the player has lost a life.
BECA CALL CheckMonstersDefeated Check whether the player has beaten all four monsters.
Update the screen and check for the pause key.
MainLoop_Redraw BECD CALL CopyBuffersToScreen Copy the screen buffer onto the screen.
BED0 LD A,($BBFB) Fetch the flag at FlashColour.
BED3 LD ($BBFC),A Keep a copy of it for the next frame in PreviousFlashColour.
BED6 XOR A Clear the accumulator.
BED7 LD ($BBFB),A Reset the flag.
BEDA CALL PauseGame Check whether the game has been paused.
BEDD JR MainLoop Jump to MainLoop for the next frame.
Prev: BC8E Up: Map Next: BEDF