Prev: 24838 Up: Map Next: 24907
24859: Sounds: Cup/ Refuel
Used by the routine at HandlerPlayer.
Plays the next step of the sound made when a cup is collected or the car is refuelled. This is called every frame but only makes a sound on every other frame. The step counter is held at SoundCounter. For the refuel sound it counts down from 7 and bit 7 is clear; each step has a higher pitch than the one before. For the cup sound it starts at 135 (bit 7 set) and each step has a lower pitch than the one before. Each step plays 32 square waves using PlaySquareWave, and there are six of them. The cup sound: The refuel sound:
SoundsCupRefuel 24859 LD A,(24105) Fetch the game timer from GameTimer.
24862 AND %00000001 Keep only bit 0.
24864 RET NZ Return on every other frame.
24865 LD HL,24134 Point HL at the step counter (SoundCounter).
24868 LD A,(HL) Fetch the step counter.
24869 BIT 7,A Jump to SoundsCup if bit 7 is set, as that is the cup sound.
24871 JR NZ,SoundsCup
24873 AND A Return if the step counter is zero, as there is no sound to play.
24874 RET Z
24875 DEC A Decrease the step counter by one.
24876 LD (HL),A Write the new step counter back to SoundCounter.
24877 RET Z Return if the step counter has reached zero, as the sound is over.
Work out the period of the waves from the step counter.
SoundsRefuel 24878 RLCA Multiply the step counter by 4 by rotating it left twice.
24879 RLCA
24880 AND %00011100 Keep only bits 2-4.
24882 OR %00100000 Set bit 5.
24884 LD D,A Set the period of the waves.
24885 LD C,32 Set the wave counter to 32.
SoundsCupRefuel_Loop 24887 CALL PlaySquareWave Play a square wave using PlaySquareWave.
24890 DEC C Decrease the wave counter by one and loop back to SoundsCupRefuel_Loop until all 32 waves have been played.
24891 JR NZ,SoundsCupRefuel_Loop
24893 RET Return.
The cup sound keeps bit 7 set in the step counter, and inverts the step so that the pitch falls rather than rises.
SoundsCup 24894 AND %01111111 Keep only the step counter (bits 0-6).
24896 RET Z Return if the step counter is zero, as the sound is over.
24897 DEC A Decrease the step counter by one.
24898 OR %10000000 Set bit 7 so that the sound stays the cup sound.
24900 LD (HL),A Write the new step counter back to SoundCounter.
24901 AND %01111111 Keep only the step counter (bits 0-6).
24903 RET Z Return if the step counter has reached zero.
24904 CPL Flip the bits, so that the pitch falls with each step.
24905 JR SoundsRefuel Jump to SoundsRefuel.
Prev: 24838 Up: Map Next: 24907