Aviator on the BBC Micro

# Dashboard: UpdateIndicator (Part 15 of 15)

```       Name: UpdateIndicator (Part 15 of 15)                         [Show more]
Type: Subroutine
Category: Dashboard
Summary: Calculations for the thrust indicator (indicator 11)
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 thrust from (thrustHi thrustLo) and reduces it to the
range 0 to 60, before falling througn into DrawIndicatorBar to update the
rudder indicator.

.uind26

\ If we get here then the indicator number in X is 11

LDA #128               \ Set S = 128, to denote that when we fall through into
STA S                  \ DrawIndicatorBar below, joyCoord is the y-coordinate,
\ so we draw the indicator's vertical bar from point
\ (H + W, joyCoord)

LDA #125               \ Set W = 125 to use as the centre y-coordinate for the
STA W                  \ thrust indicator (i.e. the left end of the bar, as we
\ are only showing positive thrust values)

LDA thrustHi           \ Set (R A) = (thrustHi thrustLo)
STA R                  \           = Thrust
LDA thrustLo

LDX #3                 \ Set X = 3 to act as a shift counter in the following
\ loop, where we right shift (R A) four times

.uind27

LSR R                  \ Set (R A) = (R A) / 2
ROR A                  \           = Thrust / 2

DEX                    \ Decrement the shift counter

BPL uind27             \ Loop back until we have shifted right by 4 places, so
\ we now have:
\
\   (R A) = (R A) / 8
\         = Thrust / 8
\
\ We now ignore the high byte in R, so presumably it is
\ zero

STA R                  \ Set A = A + A / 2
LSR A                  \       = 1.5 * A
ADC R                  \       = 1.5 * (Thrust / 8), rounded up
\       = Thrust * 3 / 16

LSR A                  \ Set A = A / 4
LSR A                  \       = Thrust * 3 / 64

STA H                  \ Store the scaled value in H, which has now been
\ reduced from the range 0 to 1280 down to 0 to 60,
\ to use as the x-coordinate offset from the left end of
\ the indicator in DrawIndicatorBar

LDX #3                 \ Set X = 3 so the current value of the indicator gets
\ stored in yJoyCoord+3 in DrawIndicatorBar

LDY #243               \ Set Y = 243 to use as the y-coordinate of the top of
\ the vertical bar

LDA #7                 \ Set A = 7 to set the height of the vertical bar at 7
\ pixels

\ Fall through into DrawIndicatorBar to update indicator
\ 11 by drawing a vertical bar of height 7 pixels with
\ the top at (125 + H, 243)
```