# Driving model: ApplySteeringSpeed

```       Name: ApplySteeringSpeed                                      [Show more]
Type: Subroutine
Category: Driving model
Summary: Apply steering to the car's speed in xVelocity and zVelocity
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 ApplySteeringSpeed

Calculate the following in parallel:

zVelocity = zVelocity + xVelocity * steering

xVelocity = xVelocity - zVelocity * steering

.ApplySteeringSpeed

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

LDY #9                 \ Set Y = 9, so in the call to MultiplyCoords+7 we use
\ zVelocity as the 16-bit signed number

LDA #%10000000         \ Clear bit 6 and set bit 7 of H, to store the result
STA H                  \ rather than adding, and negate the result 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 = -zVelocity * steering

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

LDY #8                 \ Set Y = 8, so in the call to MultiplyCoords+7 we use
\ xVelocity as the 16-bit signed number

LDA #%01000000         \ Set bit 6 and clear bit 7 of H, to add the result
STA H                  \ rather than replacing, and leave the sign of the
\ result alone in the call to MultiplyCoords+7

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

JSR MultiplyCoords+7   \ Set:
\
\   variableA = variableA + variableY * variableX
\
\ so:
\
\   zVelocity = zVelocity + xVelocity * steering

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

JSR AddSteeringForce   \ Set xVelocity = xVelocity + xSteeringForce
\               = xVelocity - zVelocity * steering

RTS                    \ Return from the subroutine
```