.MakeMusic LDA enableSound ; If enableSound is non-zero then sound is enabled, so BNE makm1 ; jump to makm1 to play the current music RTS ; Otherwise sound is disabled, so return from the ; subroutine .makm1 LDA tuneSpeed ; Set tuneProgress = tuneProgress + tuneSpeed CLC ; ADC tuneProgress ; This moves the tune along by the current speed, STA tuneProgress ; setting the C flag only when the addition of this ; iteration's speed overflows the addition ; ; This ensures that we only send music to the APU once ; every 256 / tuneSpeed iterations, which keeps the ; music in sync and sends the music more regularly with ; higher values of tuneSpeed BCC makm2 ; If the addition didn't overflow, jump to makm2 to skip ; playing music in this VBlank JSR MakeMusicOnSQ1 ; Play the current music on the SQ1 channel JSR MakeMusicOnSQ2 ; Play the current music on the SQ2 channel JSR MakeMusicOnTRI ; Play the current music on the TRI channel JSR MakeMusicOnNOISE ; Play the current music on the NOISE channel .makm2 JSR ApplyEnvelopeSQ1 ; Apply volume and pitch changes to the SQ1 channel JSR ApplyEnvelopeSQ2 ; Apply volume and pitch changes to the SQ2 channel JSR ApplyEnvelopeTRI ; Apply volume and pitch changes to the TRI channel JMP ApplyEnvelopeNOISE ; Apply volume and pitch changes to the NOISE channel, ; returning from the subroutine using a tail callName: MakeMusic [Show more] Type: Subroutine Category: Sound Summary: Play the current music on the SQ1, SQ2, TRI and NOISE channels Deep dive: Music in NES EliteContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MakeSounds calls MakeMusic
[X]
Subroutine ApplyEnvelopeNOISE (category: Sound)
Apply volume and pitch changes to the NOISE channel
[X]
Subroutine ApplyEnvelopeSQ1 (category: Sound)
Apply volume and pitch changes to the SQ1 channel
[X]
Subroutine ApplyEnvelopeSQ2 (category: Sound)
Apply volume and pitch changes to the SQ2 channel
[X]
Subroutine ApplyEnvelopeTRI (category: Sound)
Apply volume and pitch changes to the TRI channel
[X]
Subroutine MakeMusicOnNOISE (category: Sound)
Play the current music on the NOISE channel
[X]
Subroutine MakeMusicOnSQ1 (category: Sound)
Play the current music on the SQ1 channel
[X]
Subroutine MakeMusicOnSQ2 (category: Sound)
Play the current music on the SQ2 channel
[X]
Subroutine MakeMusicOnTRI (category: Sound)
Play the current music on the TRI channel
[X]
Variable enableSound in workspace WP
Controls sound effects and music in David Whittaker's sound module
[X]
Label makm1 is local to this routine
[X]
Label makm2 is local to this routine
[X]
Variable tuneProgress in workspace WP
A variable for keeping track of progress while playing the current tune, so we send data to the APU at the correct time over multiple iterations of the MakeMusic routine, according to the tune speed in tuneSpeed