Skip to navigation

Driving model: ApplyTyresAndSkids

Name: 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 Skidding
Context: 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
.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 subroutine