Prev: AE2F Up: Map Next: B097
AF87: Run Game
Used by the routine at GameEntry.
The game proper. Clears the game variables and the object table, builds the lookup tables, runs the menu, then plays the game. Every pass of the main loop runs the handler of each object, builds the list of the objects that need drawing, redraws them and paces the frame.
After the first frame of the game
run-game
Clear the game's memory.
RunGame AF87 XOR A Clear A.
AF88 OUT ($FE),A Set the border to black, and the speaker off, by writing 00 to the ULA.
AF8A LD HL,$A709 Point HL at the first game variable, ControlMethod.
AF8D LD BC,$0726 Set a counter in BC of 0726 bytes, which covers the variables and the object table.
AF90 CALL FillMemory Call FillMemory to clear the variables and the object table.
This entry point is used by the routine at ShowGameOverScreen.
RunGame_Restart AF93 LD HL,$A70E Point HL at the second game variable, HelperActiveFlag.
AF96 LD BC,$0721 Set a counter in BC of 0721 bytes, which ends at the same address.
AF99 CALL FillMemory Call FillMemory to clear the area from HelperActiveFlag onwards a second time (this repeats the first clear).
AF9C CALL ClearScreen Call ClearScreen to clear the screen.
AF9F LD A,$43 Set A to the colour bright magenta ink on a black paper.
AFA1 CALL FillAttributes Call FillAttributes to fill the attribute file with it.
AFA4 CALL BuildLookupTables Call BuildLookupTables to build the lookup tables which are used to shift and to mirror sprites.
Start with five lives and stir the random seed with the refresh register.
AFA7 LD A,$05 Write 05 to Lives.
AFA9 LD ($A721),A
AFAC LD A,R Fetch the refresh register.
AFAE LD B,A Stash the refresh register in B.
AFAF LD A,($A70D) Fetch RandomSeed.
AFB2 ADD A,B Add the refresh register to it.
AFB3 LD ($A70D),A Write it back to RandomSeed.
Show the menu, play the tune and set up the new game.
AFB6 CALL GameMenu Call GameMenu to run the title screen and the menu until the player starts the game.
AFB9 LD DE,$D833 Point DE at the start tune, StartTune.
AFBC CALL PlayMusic Call PlayMusic to play it.
AFBF CALL InitialiseObjectStore Call InitialiseObjectStore to put the objects of the quest back in the object store.
AFC2 CALL ChooseStartRoom Call ChooseStartRoom to prepare the template of the player's starting position.
Put the player at the start of the game, which costs a life.
RunGame_NextLife AFC5 CALL LoseLife Call LoseLife to copy the template into the first two object records and take a life, ending the game when none are left.
This entry point is used by the routine at TestPassageAlongMinusX.
Build the room the player is in.
RunGame_NewRoom AFC8 CALL SaveRoomObjects Call SaveRoomObjects to save the state of the objects of the last room in the object store.
AFCB CALL BuildRoom Call BuildRoom to clear the buffer, build the scenery of the room and place the player at the door they came through.
AFCE CALL LoadRoomObjects Call LoadRoomObjects to bring the objects that are stored for this room into it.
AFD1 CALL CheckSpecialObjects Call CheckSpecialObjects to find out if the room has a special object in it, which stops random creatures from being made.
AFD4 CALL PrintScoreLabel Call PrintScoreLabel to print the score.
AFD7 CALL SetCreatureTimer Call SetCreatureTimer to set how long to wait before a creature is made.
Start of a frame: maybe create a creature, then run the handler of each object.
RunGame_MainLoop AFDA CALL CreateCreature Call CreateCreature to create a random creature when it is time to.
AFDD LD IX,$A76F Point IX at the first object record, ObjectsTable.
RunGame_NextObject AFE1 LD HL,$B00C Stack RunGame_ObjectDone as the address that the handler returns to.
AFE4 PUSH HL
AFE5 LD BC,$AE2F Point BC at the handler table, ObjectHandlerTable.
AFE8 LD A,(IX+$18) Copy the width and the height of the sprite drawn in the last frame to the previous width and height.
AFEB LD (IX+$1C),A
AFEE LD A,(IX+$19)
AFF1 LD (IX+$1D),A
AFF4 LD A,(IX+$1A) Copy the screen position of the sprite drawn in the last frame to the previous position.
AFF7 LD (IX+$1E),A
AFFA LD A,(IX+$1B)
AFFD LD (IX+$1F),A
B000 LD L,(IX+$00) Fetch the type of the object.
This entry point is used by the routines at DrawObjectsInOrder, SetPlayerSpeed and TestDoorPassage.
RunGame_JumpViaTable B003 LD H,$00 Point HL at the entry of the table at BC that belongs to the index in L: the address of the entry is BC plus twice the index.
B005 ADD HL,HL
B006 ADD HL,BC
B007 LD A,(HL) Fetch the address of the handler.
B008 INC HL
B009 LD H,(HL)
B00A LD L,A
B00B JP (HL) Jump to the handler, which returns to RunGame_ObjectDone.
The handler has run: stir the random seed with the refresh register and a byte of the ROM.
RunGame_ObjectDone B00C LD A,R Fetch the refresh register.
B00E LD B,A Stash the refresh register in B.
B00F LD A,($A715) Fetch the low byte of FrameCounter.
B012 INC A Add one to it.
B013 LD H,$00 Point HL at the byte of the ROM with that address.
B015 LD L,A
B016 ADD A,(HL) Add the byte of the ROM to the frame count.
B017 ADD A,B Add the refresh register to it.
B018 LD B,A Stash the result in B.
B019 LD A,($A70D) Fetch RandomSeed.
B01C ADD A,B Add the stirred value to it.
B01D LD ($A70D),A Write it back to RandomSeed.
Move on to the next object record, until all 36 have been run.
B020 LD DE,$0020 Move IX on to the next record, which is 20 bytes further on.
B023 ADD IX,DE
B025 PUSH IX Copy IX to HL (using the stack).
B027 POP HL
B028 LD DE,$AE2F Point DE at the end of the object table, ObjectHandlerTable.
B02B AND A Jump to RunGame_NextObject if there are more records to run.
B02C SBC HL,DE
B02E JP C,RunGame_NextObject
All the handlers have run: count the frame, draw the objects and check for the pause keys.
RunGame_FrameEnd B031 LD HL,($A715) Increment the frame counter in FrameCounter.
B034 INC HL
B035 LD ($A715),HL
B038 CALL ListObjectsToDraw Call ListObjectsToDraw to build the list of the objects that need drawing.
B03B CALL DrawChangedObjects Call DrawChangedObjects to restore the background behind the objects that have moved and to draw the objects.
B03E LD ($A73E),SP Write the stack pointer to A73E (nothing reads it).
B042 CALL PauseGame Call PauseGame to pause the game when the pause keys are pressed.
Pace the frame: the less drawing was done, the longer the delay.
B045 LD A,($A714) Set B to six less the amount of drawing done, which is held in DrawingWorkCount.
B048 NEG
B04A ADD A,$06
B04C LD B,A
B04D JP M,RunGame_CheckRedraw Jump to RunGame_CheckRedraw if there were more than six.
B050 JR Z,RunGame_CheckRedraw Jump to RunGame_CheckRedraw if there were six.
RunGame_Delay B052 LD HL,$0500 Set the length of a delay loop in HL.
RunGame_DelayLoop B055 DEC HL Count HL down to zero.
B056 LD A,L
B057 OR H
B058 JR NZ,RunGame_DelayLoop
B05A DJNZ RunGame_Delay Decrease the number of delay loops and repeat until it is zero.
Redraw the whole room when it has just been built.
RunGame_CheckRedraw B05C LD A,($A711) Jump to RunGame_FrameSound if the room does not need redrawing.
B05F AND A
B060 JR Z,RunGame_FrameSound
B062 XOR A Write 00 to RoomRedrawFlag.
B063 LD ($A711),A
B066 LD A,($A738) Fetch the colour of the room from RoomAttribute.
B069 CALL FillAttributes Call FillAttributes to fill the attribute file with it.
B06C CALL DisplayObjectsCarried Call DisplayObjectsCarried to draw the inventory.
B06F CALL DrawFrame Call DrawFrame to draw the frame around the room.
B072 CALL DrawLives Call DrawLives to draw the lives.
B075 CALL UpdateScreen Call UpdateScreen to copy the buffer to the screen.
B078 CALL PrintScoreLabel Call PrintScoreLabel to print the score.
B07B CALL ResetWipeFlags Call ResetWipeFlags to clear the flags that say that an object has moved.
B07E LD HL,$0004 Start the sound effect for a new room by writing 04 to SoundEffectCounter and 00 to SoundEffectType.
B081 LD ($A749),HL
RunGame_FrameSound B084 CALL PlaySoundEffect Call PlaySoundEffect to play the next step of the sound effect.
Start again from the beginning of the room if the player has gone.
B087 LD IX,$A76F Point IX at the first object record, ObjectsTable.
B08B LD A,(IX+$00) Jump to RunGame_NextLife if both of the object records of the player are free.
B08E OR (IX+$20)
B091 JP Z,RunGame_NextLife
B094 JP RunGame_MainLoop Jump to the main loop at RunGame_MainLoop.
Prev: AE2F Up: Map Next: B097