Revs on the BBC Micro

# Extra tracks: HookSlopeJump

```       Name: HookSlopeJump                                           [Show more]
Type: Subroutine
Category: Extra tracks
Summary: Jump the car when driving fast over sloping segments
Deep dive: Secrets of the extra tracks
Code hooks in the extra tracks
Context: See this subroutine in context in the source code
References: This subroutine is called as follows:
* ModifyGameCode (Part 3 of 3) calls HookSlopeJump

This routine is called from part 5 of ApplyElevation to jump the car off the
ground when driving fast over sloping segments.

If the car is on the ground, replace the heightAboveTrack * 4 part of the
car's y-coordinate calculation with playerSpeedHi * yTrackSegmentI * 4, to
give:

(yPlayerCoordTop yPlayerCoordHi) =   (ySegmentCoordIHi ySegmentCoordILo)
+ carProgress * yTrackSegmentI
+ playerSpeedHi * yTrackSegmentI * 4
+ 172

So driving fast over sloping segments can make the car jump.

Arguments:

A                    Current value of heightAboveTrack

.HookSlopeJump

BNE slop1              \ If A is non-zero, skip the following (so the hook has
\ no effect when the car is off the ground)

\ If we get here then heightAboveTrack = 0, so the car
\ is on the ground

LDA playerSpeedHi      \ Set A = the high byte of the current speed

JSR MultiplyHeight     \ Set:
\
\   A = A * yTrackSegmentI
\     = playerSpeedHi * yTrackSegmentI
\
\ The value given in yTrackSegmentI is the y-coordinate
\ of the segment vector, i.e. the vector from this
\ segment to the next, which is the same as the change
\ in height as we move through the segment
\
\ So this value is higher with greater speed and on
\ segments that have higher slopes

BPL slop1              \ If A is positive, skip the following instruction

DEC W                  \ Decrement W to &FF, so (W A) has the correct sign

.slop1

ASL A                  \ Implement the shifts that we overwrote with the call
ROL W                  \ to the hook routine, so we have effectively inserted
\ the above code into the main game

RTS                    \ Return from the subroutine
```