Prev: 44983 Up: Map Next: 45192
44986: Run Game
Used by the routine at LeaveRoomToWest.
The main game loop. The first call builds the objects of the room the player is in. Then every pass of the loop visits each of the 40 objects in the objects table in turn, calling the routine for its graphic number from the jump table at UpdateRoutineTable to move and update it. Once every object has been dealt with the objects are sorted and drawn, the screen is brought up to date and the game waits a little (the more objects in view, the shorter the wait) before the next pass.
After the first pass
run-game
RunGame 44986 CALL BuildRoomObjects Build the objects for the room the player is in.
Every pass of the main loop starts here. The random seed used by the fire is refreshed, then each object in the table is updated in turn.
RunGame_Frame 44989 LD A,(23458) Fetch the frame counter from FrameCounter.
44992 LD (23484),A Store it as the seed for the fire at FireSeed (it is stepped for every object).
44995 LD IX,23560 Point IX at ObjectsTable.
Update the object that IX points at.
RunGame_NextObject 44999 LD SP,23456 Reset the stack pointer to RandomSeed1, as the update routines do not have to tidy up the stack.
45002 LD HL,23484 Point HL at FireSeed.
45005 INC (HL) Step the fire seed on.
45006 LD HL,45028 Point HL at RunGame_ObjectUpdated.
45009 PUSH HL Stash it on the stack, so that the update routine returns there.
45010 CALL SaveSpriteInfo Work out the screen position and size of the object, and keep a note of its old ones.
This entry point is used by the routine at HandleLastAppearingSparkle.
RunGame_UpdateObject 45013 LD L,(IX+0) Fetch the graphic number of the object into L.
45016 LD BC,45206 Point BC at UpdateRoutineTable.
This entry point is used by the routines at HandleEndingSparkles, GetGuardSpeeds, SetPlayerSpeed and DrawObjectsInOrder.
Jump to the routine whose address is held in word L of the table that BC points at (H is cleared first).
RunGame_JumpToHandler 45019 LD H,0 Clear H, so that HL holds the graphic number.
45021 ADD HL,HL Double it to get the offset of a word in the table.
45022 ADD HL,BC Add the address of the table.
45023 LD A,(HL) Read the low byte of the routine address.
45024 INC HL Move on to the high byte.
45025 LD H,(HL) Read the high byte into H.
45026 LD L,A Put the low byte into L.
45027 JP (HL) Jump to the update routine.
The update routine of each object returns here.
RunGame_ObjectUpdated 45028 LD A,R Read the refresh register, which is as good as random.
45030 LD C,A Move it into C.
45031 LD A,(23461) Fetch the second random seed from RandomSeed2.
45034 ADD A,C Add the random value to it.
45035 LD (23461),A Store it back as the new second seed at RandomSeed2.
45038 LD BC,32 Set BC to the size of an object.
45041 ADD IX,BC Move IX on to the next object.
45043 PUSH IX Copy IX to HL (using the stack).
45045 POP HL
45046 LD BC,24840 Set BC to the address just beyond the objects table, Font.
45049 AND A Subtract it from HL, to see if IX is past the end of the table.
45050 SBC HL,BC
45052 JR NC,RunGame_FinishFrame Jump to RunGame_FinishFrame if every object has been updated.
45054 JR RunGame_NextObject Jump to RunGame_NextObject for the next object.
Every object has been updated; now finish the frame.
RunGame_FinishFrame 45056 LD HL,(23458) Fetch the frame counter from FrameCounter.
45059 INC HL Increase it.
45060 LD (23458),HL Store it again at FrameCounter.
45063 LD A,(23461) Fetch the second random seed from RandomSeed2.
45066 ADD A,(HL) Add the byte of the ROM that the frame counter points at, and the frame counter itself, to it.
45067 ADD A,L
45068 ADD A,H
45069 LD (23461),A Store it as the new second seed at RandomSeed2.
45072 LD HL,23474 Point HL at NotFirstRoomFlag.
45075 SET 0,(HL) Set bit 0, so that the special objects table gets updated the next time round.
45077 CALL PauseGame Check for the pause key.
45080 CALL SpawnCauldronBubbles Create the bubbles of the cauldron if the player is in the cauldron room.
45083 CALL ListObjectsToDraw Make a list of the objects that need to be drawn.
45086 CALL DrawChangedObjects Draw the objects of the list into the screen buffer.
45089 LD A,(23493) Fetch the rising blocks flag from SparkleHeight.
45092 AND A Test it.
45093 CALL NZ,PlaySoundFromHeight_PlaySoundFromValue Play the sound of rising blocks if there are any.
Slow the game down when few objects were drawn this frame: the delay is made up of as many short delay loops as the number of objects drawn is below 6.
45096 LD A,(23486) Fetch the number of objects that were drawn from ObjectsDrawn.
45099 NEG Negate it.
45101 ADD A,6 Add 6 to it, to get the number of delay loops.
45103 LD B,A Copy it into B.
45104 JP M,RunGame_UpdateDisplay Jump to RunGame_UpdateDisplay if it is negative (more than 6 objects were drawn).
45107 JR Z,RunGame_UpdateDisplay Jump to RunGame_UpdateDisplay if it is zero.
RunGame_Delay 45109 LD HL,1280 Set HL to the number of times to count down for each delay loop.
RunGame_DelayLoop 45112 DEC HL Decrement the counter.
45113 LD A,L Check whether the counter has reached zero.
45114 OR H
45115 JR NZ,RunGame_DelayLoop Jump to RunGame_DelayLoop until the counter is zero.
45117 DJNZ RunGame_Delay Jump to RunGame_Delay until all of the delay loops are done.
If a new room has just been entered, draw the panel and the scenery.
RunGame_UpdateDisplay 45119 LD A,(23479) Fetch the flag which says that the room has just been drawn from RedrawPanelFlag.
45122 AND A Jump to RunGame_Continue if it is zero.
45123 JR Z,RunGame_Continue
45125 XOR A Reset the flag at RedrawPanelFlag.
45126 LD (23479),A
45129 LD A,(23469) Fetch the attribute of the room from RoomAttribute.
45132 CALL FillAttributes Colour the whole screen with it.
45135 CALL DisplayObjects Draw the objects the player is carrying.
45138 CALL SetBorderAttributes Colour the panel.
45141 CALL ColourSunMoon Colour the sun and moon window.
45144 CALL DrawPanel Draw the panel.
45147 LD IX,50253 Point IX at SunMoonObject.
45151 CALL DisplaySunMoonFrame Draw the sun or moon.
45154 CALL PrintDayCaption Draw the day number.
45157 CALL PrintDays Draw the number of days.
45160 CALL PrintLivesGraphic Draw the lives graphics.
45163 CALL PrintLives Print the number of lives.
45166 CALL UpdateScreen Copy the screen buffer to the display.
45169 CALL ResetWipeFlags Reset the wipe flag of all of the objects.
Start another frame, or lose a life if the player is gone.
RunGame_Continue 45172 XOR A Write 0 to *SparkleHeight (the rising blocks flag).
45173 LD (23493),A
45176 LD IX,23560 Point IX at ObjectsTable.
45180 LD A,(IX+0) Fetch the graphic number of the bottom half of the player.
45183 OR (IX+32) Combine it with the graphic number of the top half of the player.
45186 JP Z,StartLife Jump to StartLife if neither half is present, as the player has been killed.
45189 JP RunGame_Frame Jump to RunGame_Frame for another pass of the game loop.
View the equivalent code in;
Prev: 44983 Up: Map Next: 45192