Revs on the BBC Micro

# Driving model: ApplySteeringForce

```       Name: ApplySteeringForce                                      [Show more]
Type: Subroutine
Category: Driving model
Summary: Apply steering to xTyreForceNose and zTyreForceNose
Deep dive: The core driving model
Matching the code to the driving model
Context: See this subroutine in context in the source code
References: This subroutine is called as follows:
* ApplyDrivingModel calls ApplySteeringForce

Calculate the following in parallel:

xTyreForceNose = xTyreForceNose + zTyreForceNose * steering

zTyreForceNose = zTyreForceNose - xTyreForceNose * steering

.ApplySteeringForce

LDX #2                 \ Set X = 2, so in the call to MultiplyCoords we use
\ (steeringHi steeringLo) as the 16-bit sign-magnitude
\ value to multiply

LDY #12                \ Set Y = 12, so in the call to MultiplyCoords we use
\ zTyreForceNose as the 16-bit signed number

LDA #%00000000         \ Clear bits 6 and 7 of H, to store the result rather
STA H                  \ than adding, and leave the sign of the result alone in
\ the call to MultiplyCoords+7

LDA #14                \ Set A = 14, so in the call to MultiplyCoords+7, we
\ store the result in xSteeringForce

JSR MultiplyCoords+7   \ Set:
\
\   variableA = variableY * variableX
\
\ so:
\
\   xSteeringForce = zTyreForceNose * steering

LDX #2                 \ Set X = 2, so in the call to MultiplyCoords we use
\ (steeringHi steeringLo) as the 16-bit sign-magnitude
\ value to multiply

LDY #10                \ Set Y = 10, so in the call to MultiplyCoords we use
\ xTyreForceNose as the 16-bit signed number

LDA #%11000000         \ Set bits 6 and 7 of H, to add the result rather than
STA H                  \ replacing, and negate the result in the call to
\ MultiplyCoords+7

LDA #12                \ Set A = 12, so in the call to MultiplyCoords+7, we
\ store the result in zTyreForceNose

JSR MultiplyCoords+7   \ Set:
\
\   variableA = variableA - variableY * variableX
\
\ so:
\
\   zTyreForceNose =   zTyreForceNose
\                    - xTyreForceNose * steering

LDX #10                \ Set X = 8, so the call to AddSteeringForce adds
\ xSteeringForce to xTyreForceNose

JSR AddSteeringForce   \ Set xTyreForceNose = xTyreForceNose + xSteeringForce
\           = xTyreForceNose + zTyreForceNose * steering

RTS                    \ Return from the subroutine
```