.clan17 LDY zRotationLo \ Set (A Y) = zRotation LDA zRotationHi JSR Multiply8x16-6 \ Set (G W V) = (A Y) * R \ = zRotation * yVelocity / 2 \ \ Note that the value of yVelocity used is the original \ value, rather than the halved value that we set in \ part 5 if this is an emergency landing SEC \ Negate (G W), so (G W) = -zRotation * yVelocity / 2 JSR Negate16Bit LDA #0 \ Set T = 0 to act as a high byte in (T G W) STA T LDA G \ Set (T A W) = (T G W) BPL clan18 \ If the high byte in G is positive, jump to clan18 to \ skip the following instruction DEC T \ Decrement T to &FF so it has the correct sign for \ (T A W), so we now have: \ \ (T A W) = -zRotation * yVelocity / 2 .clan18 LDX #1 \ We now want to halve (T A W) twice, so set a shift \ counter in X .clan19 LSR T \ Set (T A W) = (T A W) / 2 ROR A ROR W DEX \ Decrement the shift counter BPL clan19 \ Loop back until we have shifted right by two places, \ so now we have the following: \ \ (A W) = (A W) / 4 \ = (-zRotation * yVelocity / 2) / 4 \ = -zRotation * yVelocity / 8 \ \ We can ignore the value of T as it was only used to \ feed bits of the correct polarity into the high byte STA zTurnTop \ Set (zTurnTop zTurnHi) = (A W) LDA W \ = -zRotation * yVelocity / 8 STA zTurnHi \ \ so this applies a turn moment to the plane that is in \ the opposite direction to the current roll rotation, \ and which is proportionate to the speed, so if we come \ in fast and at a large roll angle, then the plane will \ be turned fast in the opposite direction LDX #&EC \ Set (zRotationHi zRotationLo) = 0 JSR ResetVariable LDA xRotationHi \ If the high byte of the plane's rotation around the BPL clan20 \ x-axis is positive, then the plane is tilting \ backwards, so jump to clan20 to skip the following LDA ucStatus \ If ucStatus is non-zero, then the undercarriage BNE clan20 \ is down, so jump to clan20 LDX #&EA \ If we get here then the undercarriage is up and the JSR ResetVariable \ plane is tilted forwards as we're landing, so we set \ (xRotationHi xRotationLo) = 0 to belly-flop the \ plane forwards onto the ground, so it lands (and \ slides) horizontally along the ground .clan20 LDA R \ If R >= 12, i.e. yVelocity >= 24, jump to clan21 to CMP #12 \ return from the subroutine BCS clan21 LDA yPlaneLo \ If yPlaneLo <> yLandingGear, jump to clan21 to return CMP yLandingGear \ from the subroutine BNE clan21 LDA #1 \ If we get here then the vertical velocity is <= 24, STA onGround \ and the distance between the plane and the ground is \ equal to the distance from the cockpit to the bottom \ of the plane... in other words, we are exactly on the \ ground and moving very slowly, so set onGround = 1 to \ denote that we are on the ground .clan21 RTS \ Return from the subroutineName: ProcessLanding (Part 7 of 7) [Show more] Type: Subroutine Category: Flight model Summary: We have successfully touched down without crashing, so process the effects of landing on the plane Deep dive: Take-offs and landingsContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
This part processes a successful landing.
[X]
Entry point Multiply8x16-6 in subroutine Multiply8x16 (category: Maths)
Store X in VV and calculate (G W V) = (A Y) * R
[X]
Subroutine Negate16Bit (category: Maths)
Negate a 16-bit number
[X]
Subroutine ResetVariable (category: Utility routines)
Set a 16-bit in the variable workspace to 0
[X]
Label clan18 is local to this routine
[X]
Label clan19 is local to this routine
[X]
Label clan20 is local to this routine
[X]
Label clan21 is local to this routine
[X]
Variable onGround in workspace Main variable workspace
"On the ground" status
[X]
Variable ucStatus in workspace Main variable workspace
Undercarriage status
[X]
Variable xRotationHi in workspace Main variable workspace
Plane rotation angle around the x-axis (high byte)
[X]
Variable yLandingGear in workspace Main variable workspace
The vertical distance between the cockpit and the lowest part of the plane
[X]
Variable yPlaneLo in workspace Main variable workspace
Plane altitude/y-coordinate (low byte)
[X]
Variable zRotationHi in workspace Main variable workspace
Plane rotation angle around the z-axis (high byte)
[X]
Variable zRotationLo in workspace Main variable workspace
Plane rotation angle around the z-axis (low byte)
[X]
Variable zTurnHi in workspace Main variable workspace
Turn rate around the z-axis (high byte)
[X]
Variable zTurnTop in workspace Main variable workspace
Turn rate around the z-axis (top byte)