![]() |
Routines |
| Prev: 44591 | Up: Map | Next: 45207 |
|
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.
|
||||||
|
Clear the game's memory.
|
||||||
| RunGame | 44935 | XOR A | Clear A. | |||
| 44936 | OUT (254),A | Set the border to black, and the speaker off, by writing 0 to the ULA. | ||||
| 44938 | LD HL,42761 | Point HL at the first game variable, ControlMethod. | ||||
| 44941 | LD BC,1830 | Set a counter in BC of 1830 bytes, which covers the variables and the object table. | ||||
| 44944 | CALL FillMemory | Call FillMemory to clear the variables and the object table. | ||||
|
This entry point is used by the routine at ShowGameOverScreen.
|
||||||
| RunGame_Restart | 44947 | LD HL,42766 | Point HL at the second game variable, HelperActiveFlag. | |||
| 44950 | LD BC,1825 | Set a counter in BC of 1825 bytes, which ends at the same address. | ||||
| 44953 | CALL FillMemory | Call FillMemory to clear the area from HelperActiveFlag onwards a second time (this repeats the first clear). | ||||
| 44956 | CALL ClearScreen | Call ClearScreen to clear the screen. | ||||
| 44959 | LD A,67 | Set A to the colour bright magenta ink on a black paper. | ||||
| 44961 | CALL FillAttributes | Call FillAttributes to fill the attribute file with it. | ||||
| 44964 | 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.
|
||||||
| 44967 | LD A,5 | Write 5 to Lives. | ||||
| 44969 | LD (42785),A | |||||
| 44972 | LD A,R | Fetch the refresh register. | ||||
| 44974 | LD B,A | Stash the refresh register in B. | ||||
| 44975 | LD A,(42765) | Fetch RandomSeed. | ||||
| 44978 | ADD A,B | Add the refresh register to it. | ||||
| 44979 | LD (42765),A | Write it back to RandomSeed. | ||||
|
Show the menu, play the tune and set up the new game.
|
||||||
| 44982 | CALL GameMenu | Call GameMenu to run the title screen and the menu until the player starts the game. | ||||
| 44985 | LD DE,55347 | Point DE at the start tune, StartTune. | ||||
| 44988 | CALL PlayMusic | Call PlayMusic to play it. | ||||
| 44991 | CALL InitialiseObjectStore | Call InitialiseObjectStore to put the objects of the quest back in the object store. | ||||
| 44994 | 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 | 44997 | 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 | 45000 | CALL SaveRoomObjects | Call SaveRoomObjects to save the state of the objects of the last room in the object store. | |||
| 45003 | CALL BuildRoom | Call BuildRoom to clear the buffer, build the scenery of the room and place the player at the door they came through. | ||||
| 45006 | CALL LoadRoomObjects | Call LoadRoomObjects to bring the objects that are stored for this room into it. | ||||
| 45009 | CALL CheckSpecialObjects | Call CheckSpecialObjects to find out if the room has a special object in it, which stops random creatures from being made. | ||||
| 45012 | CALL PrintScoreLabel | Call PrintScoreLabel to print the score. | ||||
| 45015 | 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 | 45018 | CALL CreateCreature | Call CreateCreature to create a random creature when it is time to. | |||
| 45021 | LD IX,42863 | Point IX at the first object record, ObjectsTable. | ||||
| RunGame_NextObject | 45025 | LD HL,45068 | Stack RunGame_ObjectDone as the address that the handler returns to. | |||
| 45028 | PUSH HL | |||||
| 45029 | LD BC,44591 | Point BC at the handler table, ObjectHandlerTable. | ||||
| 45032 | LD A,(IX+24) | Copy the width and the height of the sprite drawn in the last frame to the previous width and height. | ||||
| 45035 | LD (IX+28),A | |||||
| 45038 | LD A,(IX+25) | |||||
| 45041 | LD (IX+29),A | |||||
| 45044 | LD A,(IX+26) | Copy the screen position of the sprite drawn in the last frame to the previous position. | ||||
| 45047 | LD (IX+30),A | |||||
| 45050 | LD A,(IX+27) | |||||
| 45053 | LD (IX+31),A | |||||
| 45056 | LD L,(IX+0) | Fetch the type of the object. | ||||
|
|
||||||
| RunGame_JumpViaTable | 45059 | LD H,0 | 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. | |||
| 45061 | ADD HL,HL | |||||
| 45062 | ADD HL,BC | |||||
| 45063 | LD A,(HL) | Fetch the address of the handler. | ||||
| 45064 | INC HL | |||||
| 45065 | LD H,(HL) | |||||
| 45066 | LD L,A | |||||
| 45067 | 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 | 45068 | LD A,R | Fetch the refresh register. | |||
| 45070 | LD B,A | Stash the refresh register in B. | ||||
| 45071 | LD A,(42773) | Fetch the low byte of FrameCounter. | ||||
| 45074 | INC A | Add one to it. | ||||
| 45075 | LD H,0 | Point HL at the byte of the ROM with that address. | ||||
| 45077 | LD L,A | |||||
| 45078 | ADD A,(HL) | Add the byte of the ROM to the frame count. | ||||
| 45079 | ADD A,B | Add the refresh register to it. | ||||
| 45080 | LD B,A | Stash the result in B. | ||||
| 45081 | LD A,(42765) | Fetch RandomSeed. | ||||
| 45084 | ADD A,B | Add the stirred value to it. | ||||
| 45085 | LD (42765),A | Write it back to RandomSeed. | ||||
|
Move on to the next object record, until all 54 have been run.
|
||||||
| 45088 | LD DE,32 | Move IX on to the next record, which is 32 bytes further on. | ||||
| 45091 | ADD IX,DE | |||||
| 45093 | PUSH IX | Copy IX to HL (using the stack). | ||||
| 45095 | POP HL | |||||
| 45096 | LD DE,44591 | Point DE at the end of the object table, ObjectHandlerTable. | ||||
| 45099 | AND A | Jump to RunGame_NextObject if there are more records to run. | ||||
| 45100 | SBC HL,DE | |||||
| 45102 | JP C,RunGame_NextObject | |||||
|
All the handlers have run: count the frame, draw the objects and check for the pause keys.
|
||||||
| RunGame_FrameEnd | 45105 | LD HL,(42773) | Increment the frame counter in FrameCounter. | |||
| 45108 | INC HL | |||||
| 45109 | LD (42773),HL | |||||
| 45112 | CALL ListObjectsToDraw | Call ListObjectsToDraw to build the list of the objects that need drawing. | ||||
| 45115 | CALL DrawChangedObjects | Call DrawChangedObjects to restore the background behind the objects that have moved and to draw the objects. | ||||
| 45118 | LD (42814),SP | Write the stack pointer to 42814 (nothing reads it). | ||||
| 45122 | 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.
|
||||||
| 45125 | LD A,(42772) | Set B to six less the amount of drawing done, which is held in DrawingWorkCount. | ||||
| 45128 | NEG | |||||
| 45130 | ADD A,6 | |||||
| 45132 | LD B,A | |||||
| 45133 | JP M,RunGame_CheckRedraw | Jump to RunGame_CheckRedraw if there were more than six. | ||||
| 45136 | JR Z,RunGame_CheckRedraw | Jump to RunGame_CheckRedraw if there were six. | ||||
| RunGame_Delay | 45138 | LD HL,1280 | Set the length of a delay loop in HL. | |||
| RunGame_DelayLoop | 45141 | DEC HL | Count HL down to zero. | |||
| 45142 | LD A,L | |||||
| 45143 | OR H | |||||
| 45144 | JR NZ,RunGame_DelayLoop | |||||
| 45146 | 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 | 45148 | LD A,(42769) | Jump to RunGame_FrameSound if the room does not need redrawing. | |||
| 45151 | AND A | |||||
| 45152 | JR Z,RunGame_FrameSound | |||||
| 45154 | XOR A | Write 0 to RoomRedrawFlag. | ||||
| 45155 | LD (42769),A | |||||
| 45158 | LD A,(42808) | Fetch the colour of the room from RoomAttribute. | ||||
| 45161 | CALL FillAttributes | Call FillAttributes to fill the attribute file with it. | ||||
| 45164 | CALL DisplayObjectsCarried | Call DisplayObjectsCarried to draw the inventory. | ||||
| 45167 | CALL DrawFrame | Call DrawFrame to draw the frame around the room. | ||||
| 45170 | CALL DrawLives | Call DrawLives to draw the lives. | ||||
| 45173 | CALL UpdateScreen | Call UpdateScreen to copy the buffer to the screen. | ||||
| 45176 | CALL PrintScoreLabel | Call PrintScoreLabel to print the score. | ||||
| 45179 | CALL ResetWipeFlags | Call ResetWipeFlags to clear the flags that say that an object has moved. | ||||
| 45182 | LD HL,4 | Start the sound effect for a new room by writing 4 to SoundEffectCounter and 0 to SoundEffectType. | ||||
| 45185 | LD (42825),HL | |||||
| RunGame_FrameSound | 45188 | 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.
|
||||||
| 45191 | LD IX,42863 | Point IX at the first object record, ObjectsTable. | ||||
| 45195 | LD A,(IX+0) | Jump to RunGame_NextLife if both of the object records of the player are free. | ||||
| 45198 | OR (IX+32) | |||||
| 45201 | JP Z,RunGame_NextLife | |||||
| 45204 | JP RunGame_MainLoop | Jump to the main loop at RunGame_MainLoop. | ||||
| Prev: 44591 | Up: Map | Next: 45207 |