summaryrefslogtreecommitdiff
path: root/audio/engine.asm
diff options
context:
space:
mode:
Diffstat (limited to 'audio/engine.asm')
-rw-r--r--audio/engine.asm335
1 files changed, 92 insertions, 243 deletions
diff --git a/audio/engine.asm b/audio/engine.asm
index d0f64088b..482b1d1db 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,7 @@ _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 +69,17 @@ 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 +208,7 @@ _UpdateSound:: ; e805c
ld [rNR51], a
ret
-; e8125
-
-UpdateChannels: ; e8125
+UpdateChannels:
ld hl, .ChannelFnPtrs
ld a, [wCurChannel]
and $7
@@ -510,9 +500,7 @@ 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 +521,7 @@ _CheckSFX: ; e82e7
scf
ret
-; e8307
-
-PlayDanger: ; e8307
+PlayDanger:
ld a, [wLowHealthAlarm]
bit DANGER_ON_F, a
ret z
@@ -595,23 +581,19 @@ 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 +705,7 @@ 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 +825,7 @@ 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 +942,7 @@ HandleTrackVibrato: ; e8466
.quit
ret
-; e84f9
-
-ApplyPitchWheel: ; e84f9
+ApplyPitchWheel:
; quit if pitch wheel inactive
ld hl, CHANNEL_FLAGS2
add hl, bc
@@ -1081,9 +1057,7 @@ 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 +1083,7 @@ HandleNoise: ; e858c
ld [wNoiseSampleDelay], a
ret
-; e85af
-
-ReadNoiseSample: ; e85af
+ReadNoiseSample:
; sample struct:
; [wx] [yy] [zz]
; w: ? either 2 or 3
@@ -1161,9 +1133,7 @@ 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 +1241,7 @@ ParseMusic: ; e85e1
ld [hli], a ; bank
ret
-; e8679
-
-RestoreVolume: ; e8679
+RestoreVolume:
; ch5 only
ld a, [wCurChannel]
cp CHAN5
@@ -1292,9 +1260,7 @@ RestoreVolume: ; e8679
ld [wSFXPriority], a
ret
-; e8698
-
-ParseSFXOrRest: ; e8698
+ParseSFXOrRest:
; turn noise sampling on
ld hl, CHANNEL_NOTE_FLAGS
add hl, bc
@@ -1324,9 +1290,7 @@ 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 +1346,7 @@ GetNoiseSample: ; e86c5
ld [wNoiseSampleDelay], a
ret
-; e870f
-
-ParseMusicCommand: ; e870f
+ParseMusicCommand:
; reload command
ld a, [wCurMusicByte]
; get command #
@@ -1401,9 +1363,7 @@ 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 +1413,18 @@ 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 +1445,7 @@ 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 +1478,7 @@ 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 +1493,7 @@ Music_JumpChannel: ; e87bc
ld [hl], d
ret
-; e87cc
-
-Music_LoopChannel: ; e87cc
+Music_LoopChannel:
; loops xx - 1 times
; 00: infinite
; params: 3
@@ -1603,9 +1554,7 @@ 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 +1567,7 @@ Music_SetCondition: ; e880e
ld [hl], a
ret
-; e8817
-
-Music_JumpIf: ; e8817
+Music_JumpIf:
; conditional jump
; used with FA
; params: 3
@@ -1666,9 +1613,7 @@ 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 +1665,7 @@ MusicEE; e883e
ld [hl], d
ret
-; e886d
-
-MusicF9: ; e886d
+MusicF9:
; sets some flag
; seems to be unused
; params: 0
@@ -1730,9 +1673,7 @@ MusicF9: ; e886d
ld [wc2b5], a
ret
-; e8873
-
-MusicE2: ; e8873
+MusicE2:
; seems to have been dummied out
; params: 1
call GetMusicByte
@@ -1744,9 +1685,7 @@ MusicE2: ; e8873
set SOUND_UNKN_0B, [hl]
ret
-; e8882
-
-Music_Vibrato: ; e8882
+Music_Vibrato:
; vibrato
; params: 2
; 1: [xx]
@@ -1801,9 +1740,7 @@ 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 +1771,7 @@ 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 +1785,7 @@ Music_Tone: ; e88e4
ld [hl], a
ret
-; e88f7
-
-MusicE7: ; e88f7
+MusicE7:
; unused
; params: 1
ld hl, CHANNEL_FLAGS2
@@ -1864,9 +1797,7 @@ 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 +1817,7 @@ Music_SoundDuty: ; e8906
ld [hl], a
ret
-; e891e
-
-MusicE8: ; e891e
+MusicE8:
; unused
; params: 1
ld hl, CHANNEL_FLAGS2
@@ -1900,9 +1829,7 @@ MusicE8: ; e891e
ld [hl], a
ret
-; e892d
-
-Music_ToggleSFX: ; e892d
+Music_ToggleSFX:
; toggle something
; params: none
ld hl, CHANNEL_FLAGS1
@@ -1916,9 +1843,7 @@ 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 +1865,7 @@ Music_ToggleNoise: ; e893b
ld [wMusicNoiseSampleSet], a
ret
-; e894f
-
-Music_SFXToggleNoise: ; e894f
+Music_SFXToggleNoise:
; toggle sfx noise sampling
; params:
; on: 1
@@ -1963,9 +1886,7 @@ 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 +1904,7 @@ Music_NoteType: ; e8963
call Music_Intensity
ret
-; e8977
-
-Music_SoundStatus: ; e8977
+Music_SoundStatus:
; update sound status
; params: 1
call GetMusicByte
@@ -1995,9 +1914,7 @@ Music_SoundStatus: ; e8977
set NOTE_UNKN_3, [hl]
ret
-; e8984
-
-Music_DutyCycle: ; e8984
+Music_DutyCycle:
; duty cycle
; params: 1
call GetMusicByte
@@ -2009,9 +1926,7 @@ Music_DutyCycle: ; e8984
ld [hl], a
ret
-; e8991
-
-Music_Intensity: ; e8991
+Music_Intensity:
; intensity
; params: 1
; hi: pressure
@@ -2022,9 +1937,7 @@ Music_Intensity: ; e8991
ld [hl], a
ret
-; e899a
-
-Music_Tempo: ; e899a
+Music_Tempo:
; global tempo
; params: 2
; de: tempo
@@ -2035,16 +1948,14 @@ 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 +1964,7 @@ 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 +1974,7 @@ Music_ForceOctave: ; e89b1
ld [hl], a
ret
-; e89ba
-
-Music_StereoPanning: ; e89ba
+Music_StereoPanning:
; stereo panning
; params: 1
; stereo on?
@@ -2078,9 +1985,7 @@ Music_StereoPanning: ; e89ba
call GetMusicByte
ret
-; e89c5
-
-Music_Panning: ; e89c5
+Music_Panning:
; force panning
; params: 1
call SetLRTracks
@@ -2091,9 +1996,7 @@ Music_Panning: ; e89c5
ld [hl], a
ret
-; e89d2
-
-Music_Volume: ; e89d2
+Music_Volume:
; set volume
; params: 1
; see Volume
@@ -2109,9 +2012,7 @@ 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 +2038,21 @@ 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 +2086,7 @@ Music_RestartChannel: ; e8a08
pop bc ; restore current channel
ret
-; e8a30
-
-Music_NewSong: ; e8a30
+Music_NewSong:
; new song
; params: 2
; de: song id
@@ -2206,9 +2099,7 @@ 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 +2131,7 @@ GetMusicByte: ; e8a3e
ld a, [wCurMusicByte]
ret
-; e8a5d
-
-GetFrequency: ; e8a5d
+GetFrequency:
; generate frequency
; input:
; d: octave
@@ -2294,9 +2183,7 @@ 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 +2222,7 @@ 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 +2243,7 @@ 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 +2272,7 @@ SetGlobalTempo: ; e8ac7
pop bc ; restore current channel
ret
-; e8b03
-
-Tempo: ; e8b03
+Tempo:
; input:
; de: note length
; update Tempo
@@ -2407,18 +2288,14 @@ 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 +2315,7 @@ SetLRTracks: ; e8b1b
pop de
ret
-; e8b30
-
-_PlayMusic:: ; e8b30
+_PlayMusic::
; load music
call MusicOff
ld hl, wMusicID
@@ -2482,9 +2357,7 @@ _PlayMusic:: ; e8b30
call MusicOn
ret
-; e8b79
-
-_PlayCry:: ; e8b79
+_PlayCry::
; Play cry de using parameters:
; wCryPitch
; wCryLength
@@ -2595,9 +2468,7 @@ _PlayCry:: ; e8b79
call MusicOn
ret
-; e8c04
-
-_PlaySFX:: ; e8c04
+_PlaySFX::
; clear channels if they aren't already
call MusicOff
ld hl, wChannel5Flags1
@@ -2696,9 +2567,7 @@ _PlaySFX:: ; e8c04
ld [wSFXPriority], a
ret
-; e8ca6
-
-PlayStereoSFX:: ; e8ca6
+PlayStereoSFX::
; play sfx de
call MusicOff
@@ -2799,9 +2668,7 @@ PlayStereoSFX:: ; e8ca6
call MusicOn
ret
-; e8d1b
-
-LoadChannel: ; e8d1b
+LoadChannel:
; prep channel for use
; input:
; de:
@@ -2845,9 +2712,7 @@ 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 +2742,7 @@ ChannelInit: ; e8d5b
pop de
ret
-; e8d76
-
-LoadMusicByte:: ; e8d76
+LoadMusicByte::
; input:
; de = current music address
; output:
@@ -2889,17 +2752,13 @@ LoadMusicByte:: ; e8d76
ld a, [wCurMusicByte]
ret
-; e8d80
-
-
INCLUDE "audio/notes.asm"
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 +2772,18 @@ 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 +2794,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 +2812,7 @@ 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 +2829,7 @@ 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 +2848,3 @@ PlayTrainerEncounterMusic:: ; e900a
ld e, [hl]
call PlayMusic
ret
-; e9027