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 11: if the player is in segment 40 or later, cancel drift * Section 12: cancel drift * Section 21: if the player is in segment 34 or later, cancel drift * Section 22: 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.41 * Section 3: scale the steering by 1.28 * Section 5: scale the steering by 1.08 * Section 6: scale the steering by 1.08 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 #16 \ 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 #215 \ Set Y = 215 so we scale the steering by 1.41 JMP joys12 \ Jump to part 3 to scale the steering .joys2 PHA \ Store the player's track section number * 8 on the \ stack so we can retrieve it below CMP #88 \ If the track section <> 88 (i.e. section 11), jump to BNE joys3 \ joys3 to keep checking LDA #39 \ Set A = 39 so we disable drift if the player is in \ segment 40 or later in track section 11 BNE joys4 \ Jump to joys4 (this BNE is effectively a JMP as A is \ never zero) .joys3 CMP #168 \ If the track section <> 168 (i.e. section 21), jump to BNE joys5 \ joys5 to keep checking LDA #33 \ Set A = 33 so we disable drift if the player is in \ segment 34 or later in track section 21 .joys4 CMP objSectionSegmt,Y \ If A < the player's segment number in the current BCC joys6 \ track section, jump to joys6 to cancel drift BCS joys7 \ Jump to joys7 to keep checking (this BCS is \ effectively a JMP as we just passed through a BCC) .joys5 CMP #96 \ If the track section = 96 (i.e. section 12), jump to BEQ joys6 \ joys6 to cancel drift CMP #176 \ If the track section <> 176 (i.e. section 22), jump to BNE joys7 \ joys7 to keep checking .joys6 LSR playerDrift \ Clear bit 7 of playerDrift to denote that the player \ is not drifting sideways (i.e. cancel any drift) .joys7 PLA \ Retrieve the player's track section number * 8 from \ the stack JMP joys8 \ Jump to part 2