Skip to navigation

Aviator on the BBC Micro

Dashboard: UpdateIndicator (Part 14 of 15)

Name: UpdateIndicator (Part 14 of 15) [Show more] Type: Subroutine Category: Dashboard Summary: Calculations for the joystick position display (indicator 8 or 10)
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 joystick position from aileronPosition and elevatorPosition and reduces it to -8 to +8 (for the x-position in aileronPosition) and to -32 to +32 (for the y-position in elevatorPosition), before passing it to the DrawJoystickCross to update the cross in the joystick position display. The x-position is reduced more because the joystick position display is taller than it is wide. Note that this indicator has two IDs, 8 and 10, so that it gets updated twice as often by UpdateDashboard.
.uind25 \ If we get here then the indicator number in X is 8 or \ 10 LDA #128 \ Redraw the existing cross on the joystick position JSR DrawJoystickCross \ display using EOR logic, which removes it LDA #%00100010 \ Redraw the joystick position display's x-axis, in case STA row24_block18_7 \ the old cross was overwriting the axis STA row24_block21_7 LDA #%01000100 STA row24_block19_7 LDA #%10011001 \ Redraw the joystick position display's y-axis, in case STA row24_block20_7 \ the old cross was overwriting the axis LDA #%10001000 STA row21_block20_7 STA row22_block20_7 STA row23_block20_7 STA row25_block20_7 STA row26_block20_7 STA row27_block20_7 LDA aileronPosition \ Set A = aileronPosition, the x-position of the \ joystick SEC \ Set the C flag so the following call to ScaleSigned \ divides the joystick x-position by 16 JSR ScaleSigned \ Scale the value in A down by a factor of 16, retaining \ the sign and being sensitive to small values STA xJoyCoord \ Store the scaled value of A in xJoyCoord, so we can \ pass it to DrawJoystickCross below to draw the new \ cross, but also so we can erase this cross when we \ need to update the indicator in the future LDA elevatorPosition \ Set A = elevatorPosition, the y-position of the \ joystick CLC \ Clear the C flag so the following call to ScaleSigned \ divides the joystick y-position by 4 JSR ScaleSigned \ Scale the value in A down by a factor of 4, retaining \ the sign and being sensitive to small values EOR #&FF \ Set A = -A using two's complement CLC \ ADC #1 \ This flips the sign of the y-position, because the \ joystick value will be high when we pull up, but this \ corresponds to moving the stick down, which should be \ shown lower down the indicator STA yJoyCoord \ Store the scaled value of A in yJoyCoord, so we can \ pass it to DrawJoystickCross below to draw the new \ cross, but also so we can erase this cross when we \ need to update the indicator in the future LDA #0 \ Draw a new cross on the joystick position display JSR DrawJoystickCross RTS \ Return from the subroutine