Skip to navigation

Revs on the BBC Micro

Extra tracks: HookJoystick (Part 1 of 3)

Name: HookJoystick (Part 1 of 3) [Show more] Type: Subroutine Category: Extra tracks Summary: Apply enhanced joystick steering to specific track sections 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: * newContentHi calls HookJoystick * newContentLo calls HookJoystick

This routine is called from ProcessDrivingKeys to zero the playerDrift flag when the player is in one of the specified track sections, which has the effect of cancelling drift: * Section 2: if the player is in segment 0 or 1, cancel drift * Section 21: cancel drift In addition, scale the steering in the following sections to make it easier to steer when using a joystick: * Section 2: scale the steering by 1.48 * Section 20: scale the steering by 1.16 * Section 21: scale the steering by 1.16 Specifically, the scaling is applied as follows: (A T) = scale_factor * x-axis ^ 2 which replaces this existing code in ProcessDrivingKeys: (A T) = x-axis^2
Arguments: U The joystick x-axis high byte
.HookJoystick LDY currentPlayer \ Set A to the track section number * 8 for the current LDA objTrackSection,Y \ player CMP #40 \ If the track section <> 16 (i.e. section 2), jump to BNE joys2 \ joys2 to keep checking LDA objSectionSegmt,Y \ Set A = objSectionSegmt, which keeps track of the \ player's segment number in the current track section CMP #2 \ If A < 2, jump to joys1 BCC joys1 LSR playerDrift \ A = 0 or 1, which means the player is in one of the \ first two segments in the section so clear bit 7 of \ playerDrift to denote that the player is not drifting \ sideways (i.e. cancel any drift) .joys1 LDY #220 \ Set Y = 220 so we scale the steering by 1.48 JMP joys6 \ Jump to part 3 to scale the steering .joys2 JMP joys3 \ Jump to part 2 EQUB &4C, &1B \ These bytes appear to be unused EQUB &46