Elite on the BBC Micro

Dashboard: REDU2, Removed [Elite-A, Docked]

```       Name: REDU2, Removed                                          [Show more]
Type: Subroutine
Category: Dashboard
Summary: Reduce the value of the pitch or roll dashboard indicator
Context: See this subroutine in context in the source code
References: No direct references to this subroutine in this source file

Reduce X by A, where X is either the current rate of pitch or the current
rate of roll.

The rate of pitch or roll ranges from 1 to 255 with 128 as the centre point.
This is the amount by which the pitch or roll is currently changing, so 1
means it is decreasing at the maximum rate, 128 means it is not changing,
and 255 means it is increasing at the maximum rate. These values correspond
to the line on the DC or RL indicators on the dashboard, with 1 meaning full
left, 128 meaning the middle, and 255 meaning full right.

If reducing X would bring it below 1, then X is set to 1.

If keyboard auto-recentre is configured and the result is greater than 128, we
reduce X down to the mid-point, 128. This is the equivalent of having a roll
or pitch in the right half of the indicator, when decreasing the roll or pitch
should jump us straight to the mid-point.

Other entry points:

RE3+2                Auto-recentre the value in X, if keyboard auto-recentre
is configured

\ --- Mod: Original Acornsoft code removed: ----------->

\.REDU2

\ STA T                 \ Store argument A in T so we can restore it later

\ TXA                   \ Copy argument X into A

\ SEC                   \ Set the C flag so we can do subtraction without the
\                       \ C flag affecting the result

\ SBC T                 \ Set X = A = argument X - argument A
\ TAX

\ BCS RE3               \ If the C flag is set, then we didn't underflow, so

\ LDX #1                \ We have an underflow, so set X to the minimum possible
\                       \ value, 1

\.RE3

\ BPL RE2+2             \ If X has bit 7 clear (i.e. the result < 128), then
\                       \ jump to RE2+2 above to return the result as is,
\                       \ because the result is on the left side of the centre
\                       \ point of 128, so we don't need to auto-centre

\                       \ Jumps to RE3+2 end up here

\                       \ If we get here, then we need to apply auto-recentre,
\                       \ if it is configured

\ LDA DJD               \ If keyboard auto-recentre is disabled, then
\ BNE RE2+2             \ jump to RE2+2 to restore A and return

\ LDX #128              \ If keyboard auto-recentre is enabled, set X to 128
\ BMI RE2+2             \ (the middle of our range) and jump to RE2+2 to
\                       \ restore A and return

\ --- End of removed code ----------------------------->
```