.ApplyTurnAndThrust LDX #2 \ Set a counter in X to work through the three axes (the \ comments below cover the iteration for the x-axis) .turn1 LDA xMomentsScLo,X \ Set dxTurn = xMomentsSc + xControlsSc CLC \ ADC xControlsScLo,X \ starting with the low bytes STA dxTurnLo,X LDA xMomentsScHi,X \ And then the high bytes ADC xControlsScHi,X STA dxTurnHi,X LDA xMomentsScTop,X \ And then the top bytes ADC xControlsScTop,X STA dxTurnTop,X DEX \ Decrement the loop counter to move to the next axis BPL turn1 \ Loop back until we have added all three axes, so we \ now have the following, where all values are 24-bit \ numbers: \ \ dxTurn = xMomentsSc + xControlsSc \ dyTurn = yMomentsSc + yControlsSc \ dzTurn = zMomentsSc + zControlsSc LDA #0 \ Set S = 0, to use as the top byte of yGravity STA S LDA yGravityLo \ Set dxTurn = dxTurn + yGravity CLC \ ADC dxTurnLo \ starting with the low bytes STA dxTurnLo \ We now add the high bytes, but because dxTurn is a \ 24-bit number and yGravity is only a 16-bit number, \ we have to add an extra top byte to yGravity, which we \ do in S as follows: \ \ (S yGravityHi yGravityLo) LDA yGravityHi \ Set A to the high byte of yGravity BPL turn2 \ If yGravityHi is negative, decrement S to &FF so it DEC S \ has the correct sign for (S yGravityHi yGravityLo) .turn2 ADC dxTurnHi \ We then add the high bytes STA dxTurnHi LDA dxTurnTop \ And finally we add the top bytes, so we now have: ADC S \ STA dxTurnTop \ dxTurn = dxTurn + yGravity SEC \ Set dzTurn = dzTurn - zSlipMomentSc LDA dzTurnLo \ SBC zSlipMomentScLo \ starting with the low bytes STA dzTurnLo LDA dzTurnHi \ And then the high bytes SBC zSlipMomentScHi STA dzTurnHi LDA dzTurnTop \ And then the top bytes SBC zSlipMomentScTop STA dzTurnTopName: ApplyTurnAndThrust (Part 1 of 2) [Show more] Type: Subroutine Category: Flight model Summary: Calculate the (dxTurn, dyTurn, dzTurn) vectorContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyFlightModel (Part 4 of 7) calls ApplyTurnAndThrust
This part of the routine calculates the following: [ dxTurn ] [ xMomentsSc ] [ xControlsSc ] [ dyTurn ] = [ yMomentsSc ] + [ yControlsSc ] [ dzTurn ] [ zMomentsSc ] [ zControlsSc ] [ yGravity ] [ 0 ] + [ 0 ] - [ 0 ] [ 0 ] [ zSlipMoment ]
Arguments: L The current value of onGround: * 0 = we are not on the ground * 1 = we are on the ground
[X]
Variable dxTurnHi in workspace Main variable workspace
Rate of change of the plane's turn rate in the x-axis (high byte)
[X]
Variable dxTurnLo in workspace Main variable workspace
Rate of change of the plane's turn rate in the x-axis (low byte)
[X]
Variable dxTurnTop in workspace Main variable workspace
Rate of change of the plane's turn rate in the x-axis (top byte)
[X]
Variable dzTurnHi in workspace Main variable workspace
Rate of change of the plane's rate turn in the z-axis (high byte)
[X]
Variable dzTurnLo in workspace Main variable workspace
Rate of change of the plane's turn rate in the z-axis (low byte)
[X]
Variable dzTurnTop in workspace Main variable workspace
Rate of change of the plane's turn rate in the z-axis (top byte)
[X]
Label turn1 is local to this routine
[X]
Label turn2 is local to this routine
[X]
Variable xControlsScHi in workspace Main variable workspace
Scaled angular force due to the plane's controls in the x-axis (high byte)
[X]
Variable xControlsScLo in workspace Main variable workspace
Scaled angular force due to the plane's controls in the x-axis (low byte)
[X]
Variable xControlsScTop in workspace Main variable workspace
Scaled angular force due to the plane's controls in the x-axis (top byte)
[X]
Variable xMomentsScHi in workspace Main variable workspace
Scaled angular force due to forces on the plane in the x-axis (high byte)
[X]
Variable xMomentsScLo in workspace Main variable workspace
Scaled angular force due to forces on the plane in the x-axis (low byte)
[X]
Variable xMomentsScTop in workspace Main variable workspace
Scaled angular force due to forces on the plane in the x-axis (top byte)
[X]
Variable yGravityHi in workspace Main variable workspace
High byte of point 253 (y-coordinate)
[X]
Variable yGravityLo in workspace Main variable workspace
Low byte of point 253 (y-coordinate)
[X]
Variable zSlipMomentScHi in workspace Main variable workspace
Scaled angular force in the z-axis due to aircraft slip (high byte)
[X]
Variable zSlipMomentScLo in workspace Main variable workspace
Scaled angular force in the z-axis due to aircraft slip (low byte)
[X]
Variable zSlipMomentScTop in workspace Main variable workspace
Scaled angular force in the z-axis due to aircraft slip (top byte)