Elite on the BBC Micro

# Dashboard: REDU2 [Master version]

```       Name: REDU2                                                   [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
Variations: See code variations for this subroutine in the different versions
References: This subroutine is called as follows:
* DOKEY calls REDU2

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:

.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
\ because the result is on the left side of the centre
\ point of 128, so we don't need to auto-centre

.djd1

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

LDA DJD                \ If keyboard auto-recentre is disabled, then