Prev: 614B Up: Map Next: 6175
6158: Sounds: Engine
Used by the routine at NextEntity.
Plays the engine sound: four square waves using PlaySquareWave. The period of the waves is 3F minus the speed divided by 04 so the faster the car is going, the higher the pitch. There is no sound when the car is stationary.
SoundsEngine 6158 LD A,($5E0D) Fetch the speed of the car from Speed.
615B AND A Return if the car is stationary.
615C RET Z
615D RRCA Divide the speed by 04 by rotating it right twice.
615E RRCA
615F CPL Flip the bits, so the faster the car the shorter the period.
6160 AND %00111111 Keep only bits 0-5.
6162 LD D,A Set the period of the waves.
6163 LD C,$04 Set the wave counter to 04.
6165 LD A,($5E80) If Entity_Player is 03 then jump to SoundsEngine_Loop.
6168 CP $03
616A JR Z,SoundsEngine_Loop
616C LD B,$0C Set the delay counter to 0C (this has no effect, as it is overwritten).
SoundsEngine_Loop 616E CALL PlaySquareWave Play a square wave using PlaySquareWave.
6171 DEC C Decrease the wave counter by one and loop back to SoundsEngine_Loop until all 04 waves have been played.
6172 JR NZ,SoundsEngine_Loop
6174 RET Return.
Prev: 614B Up: Map Next: 6175