Skip to navigation


Dashboard: UpdateIndicator (Part 9 of 15)

Name: UpdateIndicator (Part 9 of 15) [Show more] Type: Subroutine Category: Dashboard Summary: Calculations for the turn indicator (indicator 5), the bottom part of the slip-and-turn indicator Deep dive: Hard-coded division in the dashboard routines
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This section takes the turn rate around the y-axis (i.e. the yaw rate) from (yTurnTop yTurnHi) and reduces it to the range -19 to +19, before passing it to the DrawIndicatorHand to update the bottom part of the slip-and-turn indicator.
.uind14 \ If we get here then the indicator number in X is 5 LDA yTurnHi \ Set (A T) = (yTurnTop yTurnHi) STA T \ = yTurn LDA yTurnTop BPL uind15 \ If the turn rate is positive, jump down to uind9 LDA #0 \ The turn rate is negative, so we make it positive SEC \ by calculating: SBC T \ STA T \ (A T) = (0 0) - (A T) \ \ starting with the low bytes LDA #0 \ And then the high bytes SBC yTurnTop .uind15 \ By this point, (A T) = |yTurn| BNE uind16 \ If the high byte in A is non-zero, this means that \ (A T) > 255, so skip the following three instructions \ to set A to the maximum value of 140 LDA T \ A is 0, so set A = T, so A now contains the correct \ value of |yTurn| CMP #140 \ If T < 140, jump to uind17 to skip the following two BCC uind17 \ instructions .uind16 LDA #140 \ Set T = 140, so T is always a maximum value of 140 STA T .uind17 \ At this point, T contains |yTurn|, capped to a maximum \ value of 140 \ We now calculate A = T * n / 256 with a hardcoded n, \ using unrolled shift-and-add multiplication \ We don't need an LDA T instruction as A already \ contains the same value as T LSR A \ Bit 0 of n is 0 CLC \ Bit 1 of n is 1 ADC T ROR A LSR A \ Bit 2 of n is 0 LSR A \ Bit 3 of n is 0 CLC \ Bit 4 of n is 1 ADC T ROR A LSR A \ Bit 5 of n is 0 LSR A \ Bit 6 of n is 0 \ Bit 7 of n is 0 and the final right shift is missing \ From the above, n = %00010010 (18), so we just \ calculated: \ \ A = (T * n / 256) << 1 \ = (T * 18 / 256) << 1 \ = T * 36 / 256 \ \ which takes |yTurn| in the range 0 to 140 and reduces \ it to the range 0 to 19 BIT yTurnTop \ If the top byte in yTurnTop is negative (and therefore BMI uind18 \ so is the turn rate), jump to uind18 to skip the \ following STA T \ Negate the value in A by calculating: LDA #0 \ SEC \ A = 0 - A SBC T .uind18 \ So by now, A is in the range -19 to +19 \ \ The maximum turn rate shown on the indicator is \ 4 x 180 degrees per minute, which is shown when \ T = 140, so yTurn is stored as around 35 * the turn \ rate, as 140 / 4 = 35 JMP DrawIndicatorHand \ Apply min and max limits to the value in A and update \ the indicator on-screen, returning from the subroutine \ using a tail call