Prev: C33C Up: Map Next: C4ED
C374: Run Frame
Used by the routines at RunLife and ExplodeShip.
Does the work for one frame of the game: increases the frame counter at FrameCounter, saves the position where the ship can restart with SaveRestartPosition (every fourth frame) and clears the scroll speeds. Unless the ship is out of control, it is then moved by UpdateShipSpeeds and tested against the terrain and the map objects. The shots are moved by UpdateShots and the rest of the world by ScrollWorld, which comes back at RunFrame_Draw. Then a part that has just been collected is fitted and the ship is drawn.
RunFrame C374 LD HL,($9A64) The frame counter.
C377 INC HL The next frame.
C378 LD ($9A64),HL Write the frame counter back.
C37B BIT 0,L On even frames the falling timer is left alone.
C37D JR Z,RunFrame_Counter
C37F LD A,($896F) The falling timer.
C382 AND A Leave it once it has run out.
C383 JR Z,RunFrame_Counter
C385 DEC A One frame less on the timer.
C386 LD ($896F),A Write the falling timer back.
RunFrame_Counter C389 LD A,L The low byte of the frame counter.
C38A AND %00000011 Only the bottom two bits of the frame.
C38C CALL Z,SaveRestartPosition Save the restart position every fourth frame.
C38F PUSH IY Keep the pointer that was in IY.
C391 XOR A The scroll starts at rest.
C392 LD ($CCBB),A No horizontal scroll yet.
C395 LD ($CCBA),A No vertical scroll yet.
C398 LD A,($8F53) The ship state.
C39B CP $0B State 0B or more means the ship is gone.
C39D JR NC,RunFrame_Shots
C39F LD IX,$C8E5 The ship.
C3A3 CALL UpdateShipSpeeds Change the ship's speeds from the controls.
C3A6 LD A,$FF The ship uses collision mode FF.
C3A8 LD ($5C25),A Remember that mode for the terrain test.
C3AB LD A,($96AB) The crystal-delivery flag.
C3AE AND A A delivered stack skips the terrain test.
C3AF JR NZ,RunFrame_Shots
C3B1 CALL SetShipSpeeds Give the ship the opposite of the scroll, so it stays put.
C3B4 LD C,$30 The ship's collision width is 30.
C3B6 LD A,($F5F6) The ninth part flag.
C3B9 AND A Is the ninth part fitted?
C3BA LD B,$04 Four extra rows of height without that part.
C3BC JR Z,RunFrame_Add Jump to RunFrame_Add if the zero flag is set.
C3BE LD B,$00 No extra rows.
RunFrame_Add C3C0 LD A,($C1A9) The height of the ship.
C3C3 ADD A,B Add the extra rows.
C3C4 LD B,A That is the collision height.
C3C5 CALL CheckTerrainCollision Test the ship against the terrain.
C3C8 CALL CheckMapObjectCollisions Test the ship against the map objects.
C3CB LD HL,($C8EC) The ship's horizontal speed.
C3CE LD ($C8FE),HL Keep it for the end of the frame.
C3D1 LD HL,($C8EE) The ship's vertical speed.
C3D4 LD ($C900),HL Keep it for the end of the frame.
C3D7 CALL SetShipSpeeds Set the ship speeds from the scroll again.
C3DA CALL MoveObject Move the ship by those speeds.
RunFrame_Shots C3DD CALL UpdateShots Call UpdateShots.
C3E0 JP ScrollWorld Jump to ScrollWorld.
This entry point is used by the routine at ScrollWorld.
RunFrame_Draw C3E3 POP IY Back to the pointer saved at the start of the frame.
C3E5 LD A,($96AB) The crystal-delivery flag.
C3E8 AND A A delivered stack draws nothing more this frame.
C3E9 RET NZ
C3EA LD A,($8F53) The ship state.
C3ED CP $0B An explosion past ten draws nothing more.
C3EF RET NC
C3F0 CALL StartCrystalObject Call StartCrystalObject.
C3F3 LD A,($9A64) The frame counter.
C3F6 AND %00000001 Bit 0 set means an odd frame.
C3F8 JR NZ,RunFrame_Ship Jump to RunFrame_Ship if the zero flag is clear.
C3FA CALL CheckItemDelivery Call CheckItemDelivery.
C3FD LD A,($C904) The carried-item marker.
C400 AND A Jump to RunFrame_Ship if A is not zero.
C401 JR NZ,RunFrame_Ship
C403 LD A,($8F53) The ship state.
C406 CP $0A State ten skips the flame test.
C408 JR Z,RunFrame_Ship
C40A LD A,($BC12) A finished slope check skips the flames.
C40D AND A Jump to RunFrame_Ship if A is not zero.
C40E JR NZ,RunFrame_Ship
C410 LD A,($5C36) The steering direction.
C413 AND A Jump to DrawShipTop_Pause if A is zero.
C414 JP Z,DrawShipTop_Pause
C417 LD B,A The direction being steered.
C418 LD A,($C8FD) The ship's facing.
C41B XOR B Flip the bits of A that are set in B.
C41C BIT 7,A Jump to DrawShipTop_Pause if bit 7 of A is clear.
C41E JP Z,DrawShipTop_Pause
This entry point is used by the routine at UpdateCrystalStack.
RunFrame_Ship C421 LD HL,$0000 The draw scratch starts clear.
C424 LD ($5C1C),HL The draw scratch starts at zero.
C427 LD A,($C903) The ship's screen row.
C42A LD ($A289),A The row the sprites are drawn on.
C42D LD HL,$0606 A width and height of six.
C430 LD ($5C28),HL The sprite size is six by six.
C433 LD IX,$C8E5 The ship.
C437 LD A,($8F53) The ship state.
C43A CP $0A State ten skips the flame colour.
C43C JR Z,RunFrame_Erase
C43E LD C,(IX+$18) The ship's facing.
C441 LD A,($5C36) The direction being steered.
C444 AND A Jump to RunFrame_Check if A is zero.
C445 JR Z,RunFrame_Check
C447 XOR C Compare it with the facing byte.
C448 AND %10000000 Only the facing bit.
C44A LD ($C7C0),A Note that the steering and the facing differ.
C44D JR Z,RunFrame_Check Jump to RunFrame_Check if the zero flag is set.
C44F XOR A Clear A.
C450 LD ($5C39),A Clear the shot scratch.
RunFrame_Erase C453 LD HL,($C902) Where the ship was drawn.
C456 LD ($BF83),HL Keep that, so it can be erased.
C459 LD DE,($C1AA) The ship graphic in the buffer.
C45D LD A,($C1A9) The height of the ship.
C460 LD ($5C1C),A The height, kept for the draw.
C463 LD IY,$A629 The erase aligned row directly.
C467 CALL SelectMirroredErase Call SelectMirroredErase.
C46A LD HL,($BF83) Fetch the word at BF83 into HL.
C46D CALL GetScreenAddress Call GetScreenAddress.
C470 EXX Switch to the alternate registers.
C471 LD A,(IX+$1F) Read offset 1F of IX.
C474 AND A Jump to RunFrame_Check if A is zero.
C475 JR Z,RunFrame_Check
C477 BIT 7,A Jump to RunFrame_FitPart if bit 7 of A is clear.
C479 JR Z,RunFrame_FitPart
C47B CALL BuildCarriedItemGraphic Call BuildCarriedItemGraphic.
C47E LD A,$80 A=80.
C480 LD ($C27A),A A piece has been drawn.
C483 JR RunFrame_Facing Jump to RunFrame_Facing.
RunFrame_FitPart C485 LD B,A B=A.
C486 DEC A Step A back.
C487 LD HL,$F5EE The first part flag.
C48A CALL AddAToHL Call AddAToHL.
C48D LD (HL),B Write B where HL points.
C48E CALL DrawSpritesDirectly Call DrawSpritesDirectly.
C491 CALL BuildShip Call BuildShip.
C494 LD A,$80 A=80.
C496 LD ($C27A),A A piece has been drawn.
C499 LD IX,$C8E5 The ship.
C49D LD HL,$0000 HL=00.
C4A0 LD ($5C1C),HL No saved row count.
C4A3 LD HL,$0606 HL=0606.
C4A6 LD ($5C28),HL The ship sprite is six bytes wide.
C4A9 JR RunFrame_Facing Jump to RunFrame_Facing.
RunFrame_Check C4AB LD A,(IX+$1F) Read offset 1F of IX.
C4AE AND A Jump to RunFrame_Erase if A is not zero.
C4AF JR NZ,RunFrame_Erase
RunFrame_Facing C4B1 LD A,($5C36) The steering direction.
C4B4 AND A Jump to RunFrame_Explosion if A is zero.
C4B5 JR Z,RunFrame_Explosion
C4B7 LD (IX+$18),A Write A to offset 18 of IX.
RunFrame_Explosion C4BA LD A,($8F53) The ship state.
C4BD CP $0A Jump to RunFrame_DrawShip if A is 0A.
C4BF JR Z,RunFrame_DrawShip
C4C1 LD A,($C903) The row the ship was drawn on.
C4C4 LD ($A28A),A The row the ship was drawn on.
C4C7 LD DE,($C1AA) Fetch the word at ShipBufferAddress into DE.
C4CB LD HL,($C902) Fetch the word at C902 into HL.
C4CE LD ($BF83),HL The position the ship was drawn at.
C4D1 CALL GetScreenAddress Call GetScreenAddress.
C4D4 LD A,($C1A9) The height of the ship.
C4D7 LD ($5C1D),A The height of the ship.
C4DA LD IX,$A678 The draw aligned row directly.
C4DE CALL SelectMirroredDraw Call SelectMirroredDraw.
RunFrame_DrawShip C4E1 CALL DrawSpritesDirectly Call DrawSpritesDirectly.
C4E4 CALL ColourShip Call ColourShip.
C4E7 LD A,($8F53) The ship state.
C4EA CP $0A Return if A is 0A or more.
C4EC RET NC
Continue on to DrawShipTop.
Prev: C33C Up: Map Next: C4ED