Aviator on the BBC Micro

# Dashboard: UpdateIndicator (Part 11 of 15)

```       Name: UpdateIndicator (Part 11 of 15)                         [Show more]
Type: Subroutine
Category: Dashboard
Summary: Calculations for the artificial horizon (indicator 7)
Context: See this subroutine in context in the source code
References: No direct references to this subroutine in this source file

Calculations for the artificial horizon's line vector are all performed in
the ArtificialHorizon routine, which calculates the starting coordinates and
deltas for the vector line. This routine simply takes those results, sets the
direction bits for the line, and moves the starting point so the line is
centred on the artificial horizon indicator.

.uind20

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

LDY #0                 \ Set Y = 0, to use as an argument to ArtificialHorizon

STY K                  \ Set K = 0, to use as an argument to ArtificialHorizon

STY R                  \ Set R = 0, to use as the first guess for the direction
\ of the horizon line (we will change it below if
\ required)

JSR ArtificialHorizon  \ Call ArtificialHorizon with K = 0, Y = 0 to calculate
\ the x-coordinate of the line's starting point in A

CLC                    \ Clear the C flag (this appears to have no effect)

STA S                  \ Set H = S, so this sets the x-coordinate of the line's
\ starting point

LDY #3                 \ Set Y = 3

JSR ArtificialHorizon  \ Call ArtificialHorizon with K = 0, Y = 3 to calculate
\ the y-coordinate of the line's starting point in A

STA H                  \ Set H = A, so this sets the y-coordinate of the line's
\ starting point

LDY #0                 \ Set Y = 0, to use as an argument to ArtificialHorizon

LDA #1                 \ Set K = 1, to use as an argument to ArtificialHorizon
STA K

JSR ArtificialHorizon  \ Call ArtificialHorizon with K = 1, Y = 0 to calculate
\ the x-delta of the line

SEC                    \ Set A = A - S
SBC S                  \       = A - x-coordinate of start

BPL uind21             \ If A is positive, the sign of the x-delta is correct,

STA T                  \ The returned x-delta is negative, so store it in T so
\ we can negate it below

LDA #%10000000         \ Set bit 7 of R to indicate that the x-delta for the
STA R                  \ line is negative and the y-delta is positive

LDA #0                 \ Set A = 0 - T
SEC                    \
SBC T                  \ so the x-delta in A is now positive

.uind21

CLC                    \ Set W = A + 1
STA W                  \ so this sets the line's x-delta, making sure the line
\ is at least one pixel wide

LDY #3                 \ Set Y = 3, to use as an argument to ArtificialHorizon

JSR ArtificialHorizon  \ Call ArtificialHorizon with K = 1, Y = 3 to calculate
\ the y-delta of the line

SEC                    \ Set A = A - H
SBC H                  \       = A - y-coordinate of start

BPL uind22             \ If A is positive, the sign of the y-delta is correct,

STA T                  \ The returned y-delta is negative, so store it in T so
\ we can negate it below

LDA #%01000000         \ Set bit 6 of R to indicate that the y-delta is
ORA R                  \ negative, making sure to leave bit 7 as it is
STA R

LDA #0                 \ Set A = A - T
SEC                    \
SBC T                  \ so the y-delta in A is now positive

.uind22

CLC                    \ Set G = A + 1
STA G                  \ so this sets the line's y-delta, making sure the line
\ is at least 1 pixel tall

LDA S                  \ Set S = S + 53
CLC                    \
ADC #53                \ so the start x-coordinate is moved to be relative to
STA S                  \ the centre of the artificial horizon indicator, which
\ is at (53, 160 + 29)

LDA H                  \ Set H = H - 29
CLC                    \
ADC #227               \ so the start y-coordinate is moved to be relative to
STA H                  \ the centre of the artificial horizon indicator, which
\ is at (53, 160 + 29)

JMP DrawIndicatorLine  \ Draw the new artificial horizon, returning from the
\ subroutine using a tail call
```