Skip to navigation

Revs on the BBC Micro

Extra tracks: HookFlattenHills (Part 2 of 2)

Name: HookFlattenHills (Part 2 of 2) [Show more] Type: Subroutine Category: Extra tracks Summary: Flatten any hills in the verge buffer, calculate the hill height and track width, cut objects off at the hill height Deep dive: Secrets of the extra tracks Code hooks in the extra tracks
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This part of the routine sets the verge edge to being visible when the car is pointing along the track and the nose is pointing downwards.
.hill4 LDA playerHeading \ Set A to the player's heading along the track, which \ is an angle that represents the direction in which our \ car is facing with respect to the track, like this: \ \ 0 \ -32 | +32 Overhead view of car \ \ | / \ \ | / 0 = looking straight ahead \ \|/ +64 = looking sharp right \ -64 -----+----- +64 -64 = looking sharp left \ /|\ \ / | \ \ / | \ \ -96 | +96 \ 128 \ \ An angle of 0 means our car is facing forwards along \ the track, while an angle of +32 means we are facing \ 45 degrees to the right of straight on, and an angle \ of 128 means we are facing backwards along the track JSR Absolute8Bit \ Set A = |A|, which reflects the angle into \ the right half of the above diagram: \ \ 0 \ | 32 \ | / \ | / \ |/ \ +----- 64 \ |\ \ | \ \ | \ \ | 96 \ 127 CMP #25 \ If A >= 25, then the car is pointing to a greater BCS hill5 \ angle than 25 to either side of dead ahead (i.e. it is \ pointing outside of the -24 to +24 field of view, or \ greater than 33 degrees either side of 0), so jump to \ hill5 to call CheckVergeOnScreen in the usual way LDA playerPitchAngle \ If the player's pitch angle is positive, which means BPL hill5 \ the car's nose is pointing up, above the horizontal, \ then jump to hill5 to call CheckVergeOnScreen in the \ usual way \ If we get here then the car nose is pointing downwards \ and the car is pointing straight along the track, \ within a -33 to +33 degree field of view \ \ We therefore replace the call to CheckVergeOnScreen \ with the following, which clears bit 7 of V to flag \ the verge coordinate at index X as being visible \ on-screen LSR V \ Clear bit 7 of V RTS \ Return from the subroutine .hill5 JMP CheckVergeOnScreen \ Implement the call that we overwrote with the call to \ the hook routine, so we have effectively inserted the \ above code into the main game (the JMP ensures we \ return from the subroutine using a tail call) EQUB &7F, &85 \ These bytes appear to be unused EQUB &75, &A9 EQUB &CD, &4C EQUB &00, &0C EQUB &00