Skip to navigation

Aviator on the BBC Micro

Flight model: ApplyBumpyRide

Name: ApplyBumpyRide [Show more] Type: Subroutine Category: Flight model Summary: Apply a random amount of roll or bumpiness to the plane Deep dive: Take-offs and landings
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ProcessLanding (Part 1 of 7) calls ApplyBumpyRide

Add zVelocityPHi, randomised and scaled, to the 16-bit variable specified in X. Specifically, we add (A 0) right-shifted by Y + 1 places, where A is the current value of zVelocityPHi, AND'd with a random number to produce a random number in the range 0 to zVelocityPHi. So this calculates: (A 0) variable = variable + ------- 2^(Y+1) where A is a random number in the range 0 to zVelocityPHi. When applied to the zRotation variable, this rolls the plane randomly, and when applied to the yPlane variable, it bumps the plane up or down. The amount of roll or bumpiness is dependent on the forward velocity of the plane, so the higher the speed, the bumpier the ride.
Arguments: X The offset from xTurnHi of the low byte of the variable to zero: * &EC = (zRotationHi zRotationLo) to apply roll * &EE = (yPlaneHi yPlaneLo) to apply bumpiness Y The scale factor C flag If this is set, subtract the scaled value, so we calculate: (A 0) variable = variable - ------- 2^(Y+1)
.ApplyBumpyRide LDA zVelocityPHi \ If zVelocityPHi is negative, return from the BMI ScaleByAltitude-1 \ subroutine (as ScaleByAltitude-1 contains an RTS) AND VIA+&64 \ AND with the 6522 User VIA T1C-L timer 1 low-order \ counter (SHEILA &44), which decrements one million \ times a second and will therefore be pretty random \ \ Because we are AND'ing zVelocityPHi with a random \ number, the result will be random but can't be higher \ than the original value of zVelocityPHi, so this \ produces a random number in the range 0 to \ zVelocityPHi \ Fall through into AddScaled with the N flag clear (as \ we passed through the BMI above)