Aviator on the BBC Micro

# Dashboard: UpdateIndicator (Part 2 of 15)

```       Name: UpdateIndicator (Part 2 of 15)                          [Show more]
Type: Subroutine
Category: Dashboard
Summary: Calculations for the compass (indicator 0)
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 compass heading from yRotationHi and reduces it to
the range 0 to 73, before passing it to the DrawIndicatorHand to update the
on-screen compass.

.uind1

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

LDA yRotationHi        \ Set T = yRotationHi
STA T

\ We now calculate A = T * n / 256 with a hardcoded n,

\ 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

LSR A                  \ Bit 1 of n is 0

CLC                    \ Bit 2 of n is 1
ROR A

LSR A                  \ Bit 3 of n is 0

LSR A                  \ Bit 4 of n is 0

CLC                    \ Bit 5 of n is 1
ROR A

LSR A                  \ Bit 6 of n is 0

\ Bit 7 of n is 0 and the final right shift is missing

\ So by now, A is in the range 0 to 73 - here's why:
\
\ From the above, n = %00100100 (36), so we just
\ calculated:
\
\   A = (T * n / 256) << 1
\     = (T * 36 / 256) << 1
\     = T * 72 / 256
\
\ which takes the compass heading in the range 0 to 255
\ and reduces it to the range 0 to 73

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
```