diff options
Diffstat (limited to 'audio/engine.asm')
-rw-r--r-- | audio/engine.asm | 262 |
1 files changed, 92 insertions, 170 deletions
diff --git a/audio/engine.asm b/audio/engine.asm index d0f64088b..a3d68a1b1 100644 --- a/audio/engine.asm +++ b/audio/engine.asm @@ -6,7 +6,7 @@ ; FadeMusic ; PlayStereoSFX -_MapSetup_Sound_Off:: ; e8000 +_MapSetup_Sound_Off:: ; restart sound operation ; clear all relevant hardware registers & wram push hl @@ -56,9 +56,8 @@ _MapSetup_Sound_Off:: ; e8000 pop hl ret -; e803d -MusicFadeRestart: ; e803d +MusicFadeRestart: ; restart but keep the music id to fade in to ld a, [wMusicFadeID + 1] push af @@ -71,23 +70,20 @@ MusicFadeRestart: ; e803d ld [wMusicFadeID + 1], a ret -; e8051 -MusicOn: ; e8051 +MusicOn: ld a, 1 ld [wMusicPlaying], a ret -; e8057 -MusicOff: ; e8057 +MusicOff: xor a ld [wMusicPlaying], a ret -; e805c -_UpdateSound:: ; e805c +_UpdateSound:: ; called once per frame ; no use updating audio if it's not playing ld a, [wMusicPlaying] @@ -216,9 +212,8 @@ _UpdateSound:: ; e805c ld [rNR51], a ret -; e8125 -UpdateChannels: ; e8125 +UpdateChannels: ld hl, .ChannelFnPtrs ld a, [wCurChannel] and $7 @@ -510,9 +505,8 @@ endr ld [rNR44], a ret -; e82e7 -_CheckSFX: ; e82e7 +_CheckSFX: ; return carry if any sfx channels are active ld hl, wChannel5Flags1 bit SOUND_CHANNEL_ON, [hl] @@ -533,9 +527,8 @@ _CheckSFX: ; e82e7 scf ret -; e8307 -PlayDanger: ; e8307 +PlayDanger: ld a, [wLowHealthAlarm] bit DANGER_ON_F, a ret z @@ -595,23 +588,20 @@ PlayDanger: ; e8307 ld [wSoundOutput], a ret -; e8350 -DangerSoundHigh: ; e8350 +DangerSoundHigh: db $80 ; duty 50% db $e2 ; volume 14, envelope decrease sweep 2 db $50 ; frequency: $750 db $87 ; restart sound -; e8354 -DangerSoundLow: ; e8354 +DangerSoundLow: db $80 ; duty 50% db $e2 ; volume 14, envelope decrease sweep 2 db $ee ; frequency: $6ee db $86 ; restart sound -; e8358 -FadeMusic: ; e8358 +FadeMusic: ; fade music if applicable ; usage: ; write to wMusicFade @@ -723,9 +713,8 @@ FadeMusic: ; e8358 ld [wVolume], a ret -; e83d1 -LoadNote: ; e83d1 +LoadNote: ; wait for pitch wheel to finish ld hl, CHANNEL_FLAGS2 add hl, bc @@ -845,9 +834,8 @@ LoadNote: ; e83d1 ld [hl], a ret -; e8466 -HandleTrackVibrato: ; e8466 +HandleTrackVibrato: ; handle duty, cry pitch, and vibrato ld hl, CHANNEL_FLAGS2 add hl, bc @@ -964,9 +952,8 @@ HandleTrackVibrato: ; e8466 .quit ret -; e84f9 -ApplyPitchWheel: ; e84f9 +ApplyPitchWheel: ; quit if pitch wheel inactive ld hl, CHANNEL_FLAGS2 add hl, bc @@ -1081,9 +1068,8 @@ ApplyPitchWheel: ; e84f9 set NOTE_DUTY_OVERRIDE, [hl] ret -; e858c -HandleNoise: ; e858c +HandleNoise: ; is noise sampling on? ld hl, CHANNEL_FLAGS1 add hl, bc @@ -1109,9 +1095,8 @@ HandleNoise: ; e858c ld [wNoiseSampleDelay], a ret -; e85af -ReadNoiseSample: ; e85af +ReadNoiseSample: ; sample struct: ; [wx] [yy] [zz] ; w: ? either 2 or 3 @@ -1161,9 +1146,8 @@ ReadNoiseSample: ; e85af .quit ret -; e85e1 -ParseMusic: ; e85e1 +ParseMusic: ; parses until a note is read or the song is ended call GetMusicByte ; store next byte in a cp $ff ; is the song over? @@ -1271,9 +1255,8 @@ ParseMusic: ; e85e1 ld [hli], a ; bank ret -; e8679 -RestoreVolume: ; e8679 +RestoreVolume: ; ch5 only ld a, [wCurChannel] cp CHAN5 @@ -1292,9 +1275,8 @@ RestoreVolume: ; e8679 ld [wSFXPriority], a ret -; e8698 -ParseSFXOrRest: ; e8698 +ParseSFXOrRest: ; turn noise sampling on ld hl, CHANNEL_NOTE_FLAGS add hl, bc @@ -1324,9 +1306,8 @@ ParseSFXOrRest: ; e8698 ld [hl], a ret -; e86c5 -GetNoiseSample: ; e86c5 +GetNoiseSample: ; load ptr to sample header in wNoiseSampleAddress ; are we on the last channel? ld a, [wCurChannel] @@ -1382,9 +1363,8 @@ GetNoiseSample: ; e86c5 ld [wNoiseSampleDelay], a ret -; e870f -ParseMusicCommand: ; e870f +ParseMusicCommand: ; reload command ld a, [wCurMusicByte] ; get command # @@ -1401,9 +1381,8 @@ ParseMusicCommand: ; e870f ld l, a jp hl -; e8720 -MusicCommands: ; e8720 +MusicCommands: ; entries correspond to macros/sound.asm enumeration dw Music_Octave8 ; octave 8 dw Music_Octave7 ; octave 7 @@ -1453,21 +1432,19 @@ MusicCommands: ; e8720 dw Music_LoopChannel ; loop dw Music_CallChannel ; call dw Music_EndChannel ; return -; e8780 -MusicF1: ; e8780 -MusicF2: ; e8780 -MusicF3: ; e8780 -MusicF4: ; e8780 -MusicF5: ; e8780 -MusicF6: ; e8780 -MusicF7: ; e8780 -MusicF8: ; e8780 +MusicF1: +MusicF2: +MusicF3: +MusicF4: +MusicF5: +MusicF6: +MusicF7: +MusicF8: ret -; e8781 -Music_EndChannel: ; e8781 +Music_EndChannel: ; called when $ff is encountered w/ subroutine flag set ; end music stream ; return to caller of the subroutine @@ -1488,9 +1465,8 @@ Music_EndChannel: ; e8781 ld [hl], d ret -; e8796 -Music_CallChannel: ; e8796 +Music_CallChannel: ; call music stream (subroutine) ; parameters: ll hh ; pointer to subroutine ; get pointer from next 2 bytes @@ -1523,9 +1499,8 @@ Music_CallChannel: ; e8796 set SOUND_SUBROUTINE, [hl] ret -; e87bc -Music_JumpChannel: ; e87bc +Music_JumpChannel: ; jump ; parameters: ll hh ; pointer ; get pointer from next 2 bytes @@ -1540,9 +1515,8 @@ Music_JumpChannel: ; e87bc ld [hl], d ret -; e87cc -Music_LoopChannel: ; e87cc +Music_LoopChannel: ; loops xx - 1 times ; 00: infinite ; params: 3 @@ -1603,9 +1577,8 @@ Music_LoopChannel: ; e87cc ld [hl], e ret -; e880e -Music_SetCondition: ; e880e +Music_SetCondition: ; set condition for a jump ; used with FB ; params: 1 @@ -1618,9 +1591,8 @@ Music_SetCondition: ; e880e ld [hl], a ret -; e8817 -Music_JumpIf: ; e8817 +Music_JumpIf: ; conditional jump ; used with FA ; params: 3 @@ -1666,9 +1638,8 @@ Music_JumpIf: ; e8817 ld [hl], d ret -; e883e -MusicEE; e883e +MusicEE ; conditional jump ; checks a byte in ram corresponding to the current channel ; doesn't seem to be set by any commands @@ -1720,9 +1691,8 @@ MusicEE; e883e ld [hl], d ret -; e886d -MusicF9: ; e886d +MusicF9: ; sets some flag ; seems to be unused ; params: 0 @@ -1730,9 +1700,8 @@ MusicF9: ; e886d ld [wc2b5], a ret -; e8873 -MusicE2: ; e8873 +MusicE2: ; seems to have been dummied out ; params: 1 call GetMusicByte @@ -1744,9 +1713,8 @@ MusicE2: ; e8873 set SOUND_UNKN_0B, [hl] ret -; e8882 -Music_Vibrato: ; e8882 +Music_Vibrato: ; vibrato ; params: 2 ; 1: [xx] @@ -1801,9 +1769,8 @@ Music_Vibrato: ; e8882 ld [hl], a ret -; e88bd -Music_SlidePitchTo: ; e88bd +Music_SlidePitchTo: ; set the target for pitch wheel ; params: 2 ; note duration @@ -1834,9 +1801,8 @@ Music_SlidePitchTo: ; e88bd set SOUND_PITCH_WHEEL, [hl] ret -; e88e4 -Music_Tone: ; e88e4 +Music_Tone: ; tone ; params: 1 (dw) ld hl, CHANNEL_FLAGS2 @@ -1850,9 +1816,8 @@ Music_Tone: ; e88e4 ld [hl], a ret -; e88f7 -MusicE7: ; e88f7 +MusicE7: ; unused ; params: 1 ld hl, CHANNEL_FLAGS2 @@ -1864,9 +1829,8 @@ MusicE7: ; e88f7 ld [hl], a ret -; e8906 -Music_SoundDuty: ; e8906 +Music_SoundDuty: ; sequence of 4 duty cycles to be looped ; params: 1 (4 2-bit duty cycle arguments) ld hl, CHANNEL_FLAGS2 @@ -1886,9 +1850,8 @@ Music_SoundDuty: ; e8906 ld [hl], a ret -; e891e -MusicE8: ; e891e +MusicE8: ; unused ; params: 1 ld hl, CHANNEL_FLAGS2 @@ -1900,9 +1863,8 @@ MusicE8: ; e891e ld [hl], a ret -; e892d -Music_ToggleSFX: ; e892d +Music_ToggleSFX: ; toggle something ; params: none ld hl, CHANNEL_FLAGS1 @@ -1916,9 +1878,8 @@ Music_ToggleSFX: ; e892d set SOUND_SFX, [hl] ret -; e893b -Music_ToggleNoise: ; e893b +Music_ToggleNoise: ; toggle music noise sampling ; can't be used as a straight toggle since the param is not read from on->off ; params: @@ -1940,9 +1901,8 @@ Music_ToggleNoise: ; e893b ld [wMusicNoiseSampleSet], a ret -; e894f -Music_SFXToggleNoise: ; e894f +Music_SFXToggleNoise: ; toggle sfx noise sampling ; params: ; on: 1 @@ -1963,9 +1923,8 @@ Music_SFXToggleNoise: ; e894f ld [wSFXNoiseSampleSet], a ret -; e8963 -Music_NoteType: ; e8963 +Music_NoteType: ; note length ; # frames per 16th note ; intensity: see Music_Intensity @@ -1983,9 +1942,8 @@ Music_NoteType: ; e8963 call Music_Intensity ret -; e8977 -Music_SoundStatus: ; e8977 +Music_SoundStatus: ; update sound status ; params: 1 call GetMusicByte @@ -1995,9 +1953,8 @@ Music_SoundStatus: ; e8977 set NOTE_UNKN_3, [hl] ret -; e8984 -Music_DutyCycle: ; e8984 +Music_DutyCycle: ; duty cycle ; params: 1 call GetMusicByte @@ -2009,9 +1966,8 @@ Music_DutyCycle: ; e8984 ld [hl], a ret -; e8991 -Music_Intensity: ; e8991 +Music_Intensity: ; intensity ; params: 1 ; hi: pressure @@ -2022,9 +1978,8 @@ Music_Intensity: ; e8991 ld [hl], a ret -; e899a -Music_Tempo: ; e899a +Music_Tempo: ; global tempo ; params: 2 ; de: tempo @@ -2035,16 +1990,15 @@ Music_Tempo: ; e899a call SetGlobalTempo ret -; e89a6 -Music_Octave8: ; e89a6 -Music_Octave7: ; e89a6 -Music_Octave6: ; e89a6 -Music_Octave5: ; e89a6 -Music_Octave4: ; e89a6 -Music_Octave3: ; e89a6 -Music_Octave2: ; e89a6 -Music_Octave1: ; e89a6 +Music_Octave8: +Music_Octave7: +Music_Octave6: +Music_Octave5: +Music_Octave4: +Music_Octave3: +Music_Octave2: +Music_Octave1: ; set octave based on lo nybble of the command ld hl, CHANNEL_OCTAVE add hl, bc @@ -2053,9 +2007,8 @@ Music_Octave1: ; e89a6 ld [hl], a ret -; e89b1 -Music_ForceOctave: ; e89b1 +Music_ForceOctave: ; set starting octave ; this forces all notes up by the starting octave ; params: 1 @@ -2065,9 +2018,8 @@ Music_ForceOctave: ; e89b1 ld [hl], a ret -; e89ba -Music_StereoPanning: ; e89ba +Music_StereoPanning: ; stereo panning ; params: 1 ; stereo on? @@ -2078,9 +2030,8 @@ Music_StereoPanning: ; e89ba call GetMusicByte ret -; e89c5 -Music_Panning: ; e89c5 +Music_Panning: ; force panning ; params: 1 call SetLRTracks @@ -2091,9 +2042,8 @@ Music_Panning: ; e89c5 ld [hl], a ret -; e89d2 -Music_Volume: ; e89d2 +Music_Volume: ; set volume ; params: 1 ; see Volume @@ -2109,9 +2059,8 @@ Music_Volume: ; e89d2 ld [wVolume], a ret -; e89e1 -Music_TempoRelative: ; e89e1 +Music_TempoRelative: ; set global tempo to current channel tempo +/- param ; params: 1 signed call GetMusicByte @@ -2137,27 +2086,24 @@ Music_TempoRelative: ; e89e1 call SetGlobalTempo ret -; e89fd -Music_SFXPriorityOn: ; e89fd +Music_SFXPriorityOn: ; turn sfx priority on ; params: none ld a, 1 ld [wSFXPriority], a ret -; e8a03 -Music_SFXPriorityOff: ; e8a03 +Music_SFXPriorityOff: ; turn sfx priority off ; params: none xor a ld [wSFXPriority], a ret -; e8a08 -Music_RestartChannel: ; e8a08 +Music_RestartChannel: ; restart current channel from channel header (same bank) ; params: 2 (5) ; ll hh: pointer to new channel header @@ -2191,9 +2137,8 @@ Music_RestartChannel: ; e8a08 pop bc ; restore current channel ret -; e8a30 -Music_NewSong: ; e8a30 +Music_NewSong: ; new song ; params: 2 ; de: song id @@ -2206,9 +2151,8 @@ Music_NewSong: ; e8a30 pop bc ret -; e8a3e -GetMusicByte: ; e8a3e +GetMusicByte: ; returns byte from current address in a ; advances to next byte in music data ; input: bc = start of current channel @@ -2240,9 +2184,8 @@ GetMusicByte: ; e8a3e ld a, [wCurMusicByte] ret -; e8a5d -GetFrequency: ; e8a5d +GetFrequency: ; generate frequency ; input: ; d: octave @@ -2294,9 +2237,8 @@ GetFrequency: ; e8a5d ld d, a ret -; e8a8d -SetNoteDuration: ; e8a8d +SetNoteDuration: ; input: a = note duration in 16ths ; store delay units in de inc a @@ -2335,9 +2277,8 @@ SetNoteDuration: ; e8a8d ld [hl], d ret -; e8ab8 -.Multiply: ; e8ab8 +.Multiply: ; multiplies a and de ; adds the result to l ; stores the result in hl @@ -2358,9 +2299,8 @@ SetNoteDuration: ; e8a8d jr nz, .loop ret -; e8ac7 -SetGlobalTempo: ; e8ac7 +SetGlobalTempo: push bc ; save current channel ; are we dealing with music or sfx? ld a, [wCurChannel] @@ -2389,9 +2329,8 @@ SetGlobalTempo: ; e8ac7 pop bc ; restore current channel ret -; e8b03 -Tempo: ; e8b03 +Tempo: ; input: ; de: note length ; update Tempo @@ -2407,18 +2346,16 @@ Tempo: ; e8b03 ld [hl], a ret -; e8b11 -StartChannel: ; e8b11 +StartChannel: call SetLRTracks ld hl, CHANNEL_FLAGS1 add hl, bc set SOUND_CHANNEL_ON, [hl] ; turn channel on ret -; e8b1b -SetLRTracks: ; e8b1b +SetLRTracks: ; set tracks for a the current channel to default ; seems to be redundant since this is overwritten by stereo data later push de @@ -2438,9 +2375,8 @@ SetLRTracks: ; e8b1b pop de ret -; e8b30 -_PlayMusic:: ; e8b30 +_PlayMusic:: ; load music call MusicOff ld hl, wMusicID @@ -2482,9 +2418,8 @@ _PlayMusic:: ; e8b30 call MusicOn ret -; e8b79 -_PlayCry:: ; e8b79 +_PlayCry:: ; Play cry de using parameters: ; wCryPitch ; wCryLength @@ -2595,9 +2530,8 @@ _PlayCry:: ; e8b79 call MusicOn ret -; e8c04 -_PlaySFX:: ; e8c04 +_PlaySFX:: ; clear channels if they aren't already call MusicOff ld hl, wChannel5Flags1 @@ -2696,9 +2630,8 @@ _PlaySFX:: ; e8c04 ld [wSFXPriority], a ret -; e8ca6 -PlayStereoSFX:: ; e8ca6 +PlayStereoSFX:: ; play sfx de call MusicOff @@ -2799,9 +2732,8 @@ PlayStereoSFX:: ; e8ca6 call MusicOn ret -; e8d1b -LoadChannel: ; e8d1b +LoadChannel: ; prep channel for use ; input: ; de: @@ -2845,9 +2777,8 @@ LoadChannel: ; e8d1b ld [hl], a ret -; e8d5b -ChannelInit: ; e8d5b +ChannelInit: ; make sure channel is cleared ; set default tempo and note length in case nothing is loaded ; input: @@ -2877,9 +2808,8 @@ ChannelInit: ; e8d5b pop de ret -; e8d76 -LoadMusicByte:: ; e8d76 +LoadMusicByte:: ; input: ; de = current music address ; output: @@ -2889,7 +2819,6 @@ LoadMusicByte:: ; e8d76 ld a, [wCurMusicByte] ret -; e8d80 INCLUDE "audio/notes.asm" @@ -2899,7 +2828,7 @@ INCLUDE "audio/wave_samples.asm" INCLUDE "audio/drumkits.asm" -GetLRTracks: ; e8fc2 +GetLRTracks: ; gets the default sound l/r channels ; stores mono/stereo table in hl ld a, [wOptions] @@ -2913,22 +2842,19 @@ GetLRTracks: ; e8fc2 ld hl, StereoTracks ret -; e8fd1 -MonoTracks: ; e8fd1 +MonoTracks: ; bit corresponds to track # ; hi: left channel ; lo: right channel db $11, $22, $44, $88 -; e8fd5 -StereoTracks: ; e8fd5 +StereoTracks: ; made redundant ; seems to be modified on a per-song basis db $11, $22, $44, $88 -; e8fd9 -ChannelPointers: ; e8fd9 +ChannelPointers: ; music channels dw wChannel1 dw wChannel2 @@ -2939,9 +2865,8 @@ ChannelPointers: ; e8fd9 dw wChannel6 dw wChannel7 dw wChannel8 -; e8fe9 -ClearChannels:: ; e8fe9 +ClearChannels:: ; runs ClearChannel for all 4 channels ; doesn't seem to be used, but functionally identical to MapSetup_Sound_Off ld hl, rNR50 @@ -2958,9 +2883,8 @@ ClearChannels:: ; e8fe9 jr nz, .loop ret -; e8ffe -ClearChannel: ; e8ffe +ClearChannel: ; input: hl = beginning hw sound register (rNR10, rNR20, rNR30, rNR40) ; output: 00 00 80 00 80 @@ -2977,9 +2901,8 @@ ClearChannel: ; e8ffe ld [hli], a ; rNR14, rNR24, rNR34, rNR44 ; restart sound (freq hi = 0) ret -; e900a -PlayTrainerEncounterMusic:: ; e900a +PlayTrainerEncounterMusic:: ; input: e = trainer type ; turn fade off xor a @@ -2998,4 +2921,3 @@ PlayTrainerEncounterMusic:: ; e900a ld e, [hl] call PlayMusic ret -; e9027 |