Skip to navigation


Driving model: ScaleWingSettings

Name: ScaleWingSettings [Show more] Type: Subroutine Category: Driving model Summary: Scale the wing settings and calculate the wing balance, for use in the driving model
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 1 of 5) calls ScaleWingSettings

The wing settings (0 to 40) are scaled to the range 90 to 218. The wing balance is calculated as: 60 + (rearWingSetting * 3 + frontWingSetting) / 2 which is in the range 60 to 140, with higher numbers when the rear wing is greater (i.e. pushes down more) than the front wing.
.ScaleWingSettings LDX #1 \ We are about to loop through the two wings, so set a \ counter in X so we do the rear wing setting first, and \ then the front wing setting .wing1 LDA frontWingSetting,X \ Set U = wing setting * 4 ASL A \ ASL A \ where the wing setting was entered by the player STA U LDA wingScaleFactor,X \ Set A to the wingScaleFactor for this wing, which is \ hard-coded to 205 for both wings JSR Multiply8x8 \ Set (A T) = A * U \ So by this point, we have: \ \ A = A * U / 256 \ = U * 205 / 256 \ = wing setting * 4 * 205 / 256 \ = wing setting * 820 / 256 \ \ The wing settings can be from 0 to 40, so this scales \ the setting to the range 0 to 128 CLC \ Set A = A + 90 ADC #90 \ \ which is in the range 90 to 218 STA wingSetting,X \ Store the scaled wing setting in wingSetting DEX \ Decrement the loop counter BPL wing1 \ Loop back until we have scaled both wing settings LDA rearWingSetting \ Set A = (rearWingSetting * 2 + rearWingSetting ASL A \ + frontWingSetting) / 2 + 60 ADC rearWingSetting \ = (rearWingSetting * 3 + frontWingSetting) / 2 ADC frontWingSetting \ + 60 LSR A \ ADC #60 \ which is in the range 60 to 140, with higher numbers \ when the rear wing is greater than the front wing STA wingBalance \ Store the wing balance in wingBalance RTS \ Return from the subroutine