Skip to navigation


Sound: MakeSound

Name: MakeSound [Show more] Type: Subroutine Category: Sound Summary: Make a sound Deep dive: The engine sounds
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyTyresAndSkids calls MakeSound * MakeDrivingSounds calls MakeSound * ApplyBounce calls via MakeSound-3 * CheckForCrash calls via MakeSound-3 * MakeDrivingSounds calls via MakeSound-3 * SquealTyres calls via MakeSound-3

Arguments: A The sound number from the soundData table (0 to 4) Y The volume level to use for the sound, or the envelope number (the latter is used for sound #3 only, and is always set to envelope 1, which is the only envelope)
Other entry points: MakeSound-3 Make the sound at the current volume level
LDY volumeLevel \ Set Y to the current volumeLevel, to use as the sound \ amplitude below .MakeSound STX xStoreSound \ Store the value of X in xStoreSound, so we can \ preserve it through the call to the MakeSound routine ASL A \ Set A = A * 8 ASL A \ ASL A \ so we can use it as an index into the soundData table, \ which has 8 bytes per entry CLC \ Set (Y X) = soundData + A ADC #LO(soundData) \ TAX \ starting with the low byte in X, which gets set to the \ following, as LO(soundData) is 16: \ \ * 16 for sound #0 \ * 24 for sound #1 \ * 32 for sound #2 \ * 40 for sound #3 \ * 48 for sound #4 \ \ This means that soundData - 16 + X points to the sound \ data block for the sound we are making, which we now \ use to set the volume or envelope for the sound to Y, \ and flag the correct sound buffer as being in use TYA \ Set byte #2 of the sound data (low byte of amplitude STA soundData-16+2,X \ or envelope number) to Y LDA soundData-16,X \ Set Y to byte #0 of the sound data (channel/flush), AND #3 \ and extract the channel number into Y TAY LDA #7 \ Set A = 7 for the OSWORD command to make a sound STA soundBuffer,Y \ Set the Y-th sound buffer status to 7, which is \ non-zero and indicates that we are making a sound on \ this channel BNE MakeSoundEnvelope \ Jump to MakeSoundEnvelope to set up Y and apply the \ OSWORD command to the (Y X) block, which makes the \ relevant sound (this BNE is effectively a JMP as A is \ never zero)