; $1F22: New sound { Disable sound 1 channel 0 legato Disable sound 1 channel 1 legato Disable sound 1 channel 2 legato Disable sound 1 channel 3 legato Sound 1 channel instruction list pointer set = [$2AED + [current sound 1 index]] Go to [$1F4D + [current sound 1 index]] { Number of sound 1 voices to set up = 1..4 Sound 1 priority = 0/1 ; Flag. Current sound 1 may not be changed other than to 1 (power bomb explosion) or 2 (silence) } } ; $1FD1: Process sound 1 { ; Process sound 1 - initialisation { If [sound 1 initialisation flag] != FFh: { Sound initialisation { Sound 1 initialisation flag = FFh Sound 1 channel voice bitsets = 0 Sound 1 channel voice indices = 0 Sound 1 channel voice masks = FFh Sound 1 channel disable bytes = FFh Sound 1 channel index = 0 Sound 1 channel index * 2 = 0 Remaining enabled sound effect voices = [enabled sound effect voices] for (voice ID = 8, [voice ID] != 0, decrement voice ID) { Remaining enabled sound effect voices <<= 1 If carry set: continue If [number of sound 1 voices to set up] = 0: return Decrement number of sound 1 voices to set up Sound 1 channel disable byte = 0 $24 = sound 1 channel voice bitset $26 = sound 1 channel voice mask $28 = sound 1 channel voice index Voice index = ([voice ID] - 1) * 2 Sound 1 channel backup of track output volume = [track output volume] Sound 1 channel backup of track phase inversion options = [track phase inversion options] Sound 1 channel voice index = [voice index] Execute [$296E + [voice index]] { Enable voice [voice index] Current music voice bitset &= ~(1 << [voice index]) Disable echo on voice [voice index] Sound 1 enabled voices |= 1 << [voice index] Sound 1 channel voice bitset = 1 << [voice index] Sound 1 channel voice mask = ~(1 << [voice index]) } Increment sound 1 channel index Sound 1 channel index * 2 += 2 } } Sound 1 channel 0 instruction list pointer = [[sound 1 channel instruction list pointer set]] Sound 1 channel 1 instruction list pointer = [[sound 1 channel instruction list pointer set] + 2] Sound 1 channel 2 instruction list pointer = [[sound 1 channel instruction list pointer set] + 4] Sound 1 channel 3 instruction list pointer = [[sound 1 channel instruction list pointer set] + 6] Sound 1 channel 0 DSP index = [sound 1 channel 0 voice index] * 8 Sound 1 channel 1 DSP index = [sound 1 channel 1 voice index] * 8 Sound 1 channel 2 DSP index = [sound 1 channel 2 voice index] * 8 Sound 1 channel 3 DSP index = [sound 1 channel 3 voice index] * 8 Sound 1 channel instruction list indices = 0 Sound 1 channel instruction timers = 1 } } ; Process sound 1 - channel 0 { If [sound 1 channel 0 disable byte] != FFh: { Decrement sound 1 channel 0 instruction timer If [sound 1 channel 0 instruction timer] = 0: { If sound 1 channel 0 legato disabled: { Disable sound 1 channel 0 pitch slide Sound 1 channel 0 subnote delta = 0 Sound 1 channel 0 target note = 0 If [sound 1 channel 0 release flag] != FFh: Key off flags |= [sound 1 channel 0 voice bitset] Sound 1 channel 0 release timer = 2 Sound 1 channel 0 instruction timer = 1 Sound 1 channel 0 release flag = FFh Decrement sound 1 channel 0 release timer If [sound 1 channel 0 release timer] != 0: Go to BRANCH_CHANNEL_0_END Sound 1 channel 0 release flag = 0 Current music voice bitset &= [sound 1 channel 0 voice mask] Noise enable flags &= [sound 1 channel 0 voice mask] } for (;;): { A = next sound 1 channel 0 data byte If [A] = F9h: Sound 1 channel 0 ADSR settings = next sound 1 channel 0 data byte Sound 1 channel 0 ADSR settings |= next sound 1 channel 0 data byte << 8 Sound 1 channel 0 update ADSR settings flag = FFh continue If [A] = F5h: Enable sound 1 channel 0 pitch slide type legato Else: Disable sound 1 channel 0 pitch slide type legato If [A] = F5h/F8h: Sound 1 channel 0 subnote delta = next sound 1 channel 0 data byte Sound 1 channel 0 target note = next sound 1 channel 0 data byte Enable sound 1 channel 0 pitch slide A = next sound 1 channel 0 data byte If [A] = FFh: Reset sound 1 channel 0 Go to BRANCH_CHANNEL_0_END If [A] = FEh: Sound 1 channel 0 repeat counter = next sound 1 channel 0 data byte Sound 1 channel 0 repeat point = [sound 1 channel 0 instruction list index] A = next sound 1 channel 0 data byte If [A] = FDh: { Decrement sound 1 channel 0 repeat counter If [sound 1 channel 0 repeat counter] = 0: continue Sound 1 channel 0 instruction list index = [sound 1 channel 0 repeat point] A = next sound 1 channel 0 data byte } While [A] = FBh: Sound 1 channel 0 instruction list index = [sound 1 channel 0 repeat point] A = next sound 1 channel 0 data byte If [A] = FCh: Noise enable flags |= [sound 1 channel 0 voice bitset] continue break } X = [sound 1 channel 0 voice index] Set voice's instrument settings Track output volume = next sound 1 channel 0 data byte Track phase inversion options = 0 $10 = (next sound 1 channel 0 data byte) * 100h Calculate and write DSP voice volumes if voice is not sound effect enabled A = next sound 1 channel 0 data byte If [A] != F6h: Sound 1 channel 0 note = [A] Sound 1 channel 0 subnote = 0 $11.$10 = [sound 1 channel 0 note] X = [sound 1 channel 0 voice index] Play note Sound 1 channel 0 instruction timer = next sound 1 channel 0 data byte If [sound 1 channel 0 update ADSR settings flag] != 0: DSP sound 1 channel 0 ADSR settings = [sound 1 channel 0 ADSR settings] If sound 1 channel 0 legato disabled: Key on flags |= [sound 1 channel 0 voice bitset] } If sound 1 channel 0 pitch slide enabled: { If sound 1 channel 0 pitch slide type legato enabled: Enable sound 1 channel 0 legato If [sound 1 channel 0 note] >= [sound 1 channel 0 target note]: Sound 1 channel 0 subnote -= [sound 1 channel 0 subnote delta] If [sound 1 channel 0 subnote] < 0: Decrement sound 1 channel 0 note If [sound 1 channel 0 note] = [sound 1 channel 0 target note]: Disable sound 1 channel 0 pitch slide Disable sound 1 channel 0 legato Else: Sound 1 channel 0 subnote += [sound 1 channel 0 subnote delta] If [sound 1 channel 0 subnote] >= 100h: Increment sound 1 channel 0 note If [sound 1 channel 0 note] = [sound 1 channel 0 target note]: Disable sound 1 channel 0 pitch slide Disable sound 1 channel 0 legato $11.$10 = [sound 1 channel 0 note] X = [sound 1 channel 0 voice index] Play note } } BRANCH_CHANNEL_0_END: } }