Skip to navigation


Flight model: GetMoments

Name: GetMoments [Show more] Type: Subroutine Category: Flight model Summary: Calculate the pitching, rolling and yawing moments due to the current pitch, roll and yaw rates
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyAerodynamics (Part 3 of 3) calls GetMoments * Multiply8x16 calls via GetMoments-1

This routine calculates: xTemp3 = yLiftDrag - (xTurn * 250 / 256) yTemp3 = xLiftDrag - (yTurn * 250 / 256) zTemp3 = -zTurn * 2 which contain the moments due to the plane's current movement. These then get scaled by altitude and put into (xMoments yMoments zMoments).
Other entry points: GetMoments-1 Contains an RTS
.GetMoments LDX #1 \ Set a counter in X to work through the x- and y-axes .torq1 LDA #125 \ Set R = 125 STA R LDA xTurnHi,X \ Set (Q P) = (xTurnTop xTurnHi) STA P \ = xTurn LDA xTurnTop,X STA Q ASL P \ Set (Q P) = (Q P) * 2 ROL Q \ = xTurn * 2 JSR Multiply8x16-2 \ Store X in VV and set: \ \ (G W V) = (Q P) * R \ = xTurn * 2 * 125 \ = xTurn * 250 LDA VV \ Set A and X to the axis number that the above call TAX \ stored in VV, which is the same as the axis counter X \ (so it's 0 for the x-axis and 1 for the y-axis) EOR #1 \ Set Y to the opposite axis number to X, so when we are TAY \ calculating xTemp3 in the following and X = 0, Y = 1 \ so we use yLiftDrag, and when we are calculating \ yTemp3, X = 1 and Y = 0, so we use xLiftDrag SEC \ Set xTemp3 = yLiftDrag - (G W) LDA xLiftDragLo,Y \ = yLiftDrag - (xTurn * 250 / 256) SBC W STA xTemp3Lo,X LDA xLiftDragHi,Y SBC G STA xTemp3Hi,X DEX \ Decrement the loop counter to move to the next axis BPL torq1 \ Loop back until we have processed both axes SEC \ Set (A zTemp3Lo) = 0 - (zTurnTop zTurnHi) LDA #0 \ = -zTurn SBC zTurnHi \ STA zTemp3Lo \ starting with the high bytes LDA #0 \ And then the low bytes SBC zTurnTop ASL zTemp3Lo \ Set (zTemp3Hi zTemp3Lo) = (A zTemp3Lo) << 1 ROL A \ = -zTurn * 2 STA zTemp3Hi RTS \ Return from the subroutine