.ApplyTyresAndSkids LDA heightAboveTrack \ If heightAboveTrack >= 2, jump to gfor1 to stop the CMP #2 \ tyres from squealing BCS gfor1 JSR ApplyTyreForces \ Calculate the tyre forces on the car LDA tyreSqueal,X \ Set A to tyreSqueal for tyre X AND #%11000000 \ If either of bit 6 or 7 is set in A, jump to gfor3 to BNE gfor3 \ make the tyres squeal LDA mainLoopCounterLo \ If bit 1 of mainLoopCounterLo is set, which it is on AND #%00000010 \ two out of every four iterations round the main loop, BNE gfor2 \ then jump to gfor2 to return from the subroutine .gfor1 LDX #3 \ Flush the buffer for sound channel 3 to stop any tyre JSR FlushSoundBuffer \ squeals we might already be making .gfor2 RTS \ Return from the subroutine .gfor3 JSR ApplySkidForces \ Calculate the tyre forces when the car is skidding, \ returning them in xTyreForceNose and zTyreForceNose or \ xTyreForceRear and zTyreForceRear LDA soundBuffer+3 \ If sound buffer 3 is currently being used, then we are BNE gfor4 \ already making the sound of the tyres squealing, so \ jump to gfor4 to return from the subroutine LDY #1 \ Make sound #3 (tyre squeal) using envelope 1 LDA #3 JSR MakeSound .gfor4 RTS \ Return from the subroutineName: ApplyTyresAndSkids [Show more] Type: Subroutine Category: Driving model Summary: Calculate the forces on the front or rear tyres and apply skid forces and sound effects where applicable Deep dive: The core driving model SkiddingContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyDrivingModel calls ApplyTyresAndSkids
Calculate the following: * If heightAboveTrack >= 2, stop the tyres from squealing * If heightAboveTrack < 2: * Call ApplyTyreForces * If either bit 6 or 7 is set in tyreSqueal for tyre X, then: * Call ApplySkidForces and make the tyres squeal otherwise: * On every other main loop iteration, stop the tyres from squealing
Arguments: X The set of tyres to process: * 0 = front tyres * 1 = rear tyres
[X]
Subroutine ApplySkidForces (category: Driving model)
Calculate the tyre forces when the car is skidding
[X]
Subroutine ApplyTyreForces (category: Driving model)
Calculate the tyre forces on the car
[X]
Subroutine FlushSoundBuffer (category: Sound)
Flush the specified sound buffer
[X]
Subroutine MakeSound (category: Sound)
Make a sound
[X]
Label gfor1 is local to this routine
[X]
Label gfor2 is local to this routine
[X]
Label gfor3 is local to this routine
[X]
Label gfor4 is local to this routine
[X]
Variable heightAboveTrack in workspace Zero page
The car's height above the track, for when it is being dropped from the crane, or jumping from hitting the verge too fast
[X]
Variable mainLoopCounterLo in workspace Zero page
Low byte of the main loop counter, which increments on each iteration of the main driving loop
[X]
Variable soundBuffer (category: Sound)
Details of each sound channel's buffer status
[X]
Variable tyreSqueal (category: Driving model)
A flag to determine whether the front or rear tyres are squealing