Skip to navigation

Flight model: UpdateFlightModel (Part 2 of 4)

Name: UpdateFlightModel (Part 2 of 4) [Show more] Type: Subroutine Category: Flight model Summary: Apply any throttle key presses to the current thrust value Deep dive: The key logger
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
\ Now we process the thrust keys CLC \ Clear the C flag for the addition below LDA keyLoggerLo+3 \ Fetch the low byte for the throttle key BEQ umod11 \ If A = 0 then neither key in this key pair is being \ pressed, so jump down to umod11 to skip the throttle \ calculations below \ We now want to add the key logger value to the current \ thrust value, which we do like this: \ \ (Y X) = (keyLoggerHi+3 keyLoggerLo+3) \ + (thrustHi thrustLo) ADC thrustLo \ We start by adding the low bytes TAX LDA keyLoggerHi+3 \ And then add the high bytes, so now (Y X) contains the ADC thrustHi \ updated thrust value TAY BMI umod8 \ If the result is negative, jump to umod8 to set both X \ and Y to zero, so the minimum thrust value is zero CPY #5 \ If the high byte in Y < 5, then the result is within BCC umod10 \ bounds, so jump to umod10 to store the new thrust \ value LDY #5 \ Set Y = 5 and jump to umod9 to set X to 0, so the BNE umod9 \ maximum thrust value is (5 0), or 1280 (this BNE is \ effectively a JMP, as Y is never zero) .umod8 LDY #0 \ If we get here then the new thrust in (Y X) turned out \ to be negative, so we set Y = 0 and then X = 0 to zero \ the thrust .umod9 LDX #0 \ Zero the low byte of the new thrust as we are either \ at the maximum value of (5 0) or the minimum value of \ (0 0) .umod10 STX thrustLo \ Store the thrust value in (thrustHi thrustLo) to the STY thrustHi \ updated thrust value in (Y X) LDX #11 \ Update the thrust indicator JSR UpdateIndicator