Skip to navigation

Sound: MakeSound

Name: MakeSound [Show more] Type: Subroutine Category: Sound Summary: Make a sound
Arguments: A The number of the sound to make (0 to 6): * 0 = rotating enemy (two-part) * 1 = rotating meanie (two-part) * 2 = create/absorb object white noise * 3 = music * 4 = scanner * 5 = ping * 6 = game over (two-part)
Other entry points: MakeSound-6 Make a two-part sound at the pitches defined in X and Y, where X is the pitch for sound data block #0 and Y is the pitch for sound data block #1
STX soundData+4 \ Set the third parameter of sound data block #0 to X, \ to set the pitch of the first sound STY soundData+12 \ Set the third parameter of sound data block #1 to X, \ to set the pitch of the second sound .MakeSound PHA \ Store the sound number on the stack SEC \ Decrement A, keeping the result positive SBC #1 BCS soun1 ADC #1 .soun1 JSR DefineEnvelope \ Define envelope data A from the envelopeData table, so \ sounds #0 and #1 both define envelope data 0, while \ sounds #2 to #6 define envelope data 1 to 5 PLA \ Retrieve the sound number from the stack and put it TAX \ into X, so we can use it as an index LDA soundNumberData,X \ Set A to the corresponding entry from soundNumberData \ for the sound number in X, which tells us which blocks \ of sound data to use from the soundData table when \ making the sound CMP #1 \ If A <> 1 then jump to soun2 to make the sound using BNE soun2 \ the sound data in soundData block number A \ If A = 1 then this is a two-part sound, with the first \ part using the sound data in soundData block number A \ and the second using the sound data in soundData block \ zero JSR soun2 \ Call soun2 to make the first sound using the sound \ data in soundData block number A LDA #0 \ Set A = 0 and fall through into soun2 to make the \ second sound using the sound data in soundData block \ zero .soun2 \ At this point we have the number of a soundData block \ in A, in the range 0 to 4, so now we make the sound \ using that sound data ASL A \ Set (Y X) = soundData + A * 8 ASL A \ ASL A \ starting with the low byte (we set the high byte in ADC #LO(soundData) \ MakeSoundEnvelope) TAX \ \ Each sound data block in soundData contains 8 bytes \ of data, so this sets (Y X) to the address within \ the soundData table of the data block specified in A LDA #7 \ Set A = 7 for the OSWORD command to make a sound 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)