summaryrefslogtreecommitdiff
path: root/home/audio.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home/audio.asm')
-rw-r--r--home/audio.asm200
1 files changed, 138 insertions, 62 deletions
diff --git a/home/audio.asm b/home/audio.asm
index 7c0c5238..8157e758 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -17,13 +17,14 @@ PlayDefaultMusicFadeOutCurrent::
ld [wLastMusicSoundID], a
ld c, 8
ld d, c
-
PlayDefaultMusicCommon::
ld a, [wWalkBikeSurfState]
and a
jr z, .walking
cp $2
jr z, .surfing
+ call CheckForNoBikingMusicMap
+ jr c, .walking
ld a, MUSIC_BIKE_RIDING
jr .next
@@ -34,7 +35,7 @@ PlayDefaultMusicCommon::
ld b, a
ld a, d
and a ; should current music be faded out first?
- ld a, BANK(Music_BikeRiding)
+ ld a, $1f ; BANK(Music_BikeRiding)
jr nz, .next2
; Only change the audio ROM bank if the current music isn't going to be faded
@@ -66,35 +67,32 @@ PlayDefaultMusicCommon::
ld [wNewSoundID], a
jp PlaySound
-UpdateMusic6Times::
-; This is called when entering a map, before fading out the current music and
-; playing the default music (i.e. the map's music or biking/surfing music).
- ld a, [wAudioROMBank]
- ld b, a
- cp BANK(Audio1_UpdateMusic)
- jr nz, .checkForAudio2
-
-; audio 1
- ld hl, Audio1_UpdateMusic
- jr .next
-
-.checkForAudio2
- cp BANK(Audio2_UpdateMusic)
- jr nz, .audio3
-
-; audio 2
- ld hl, Audio2_UpdateMusic
- jr .next
-
-.audio3
- ld hl, Audio3_UpdateMusic
+CheckForNoBikingMusicMap::
+; probably used to not change music upon getting on bike
+ ld a, [wCurMap]
+ cp ROUTE_23
+ jr z, .found
+ cp VICTORY_ROAD_1
+ jr z, .found
+ cp VICTORY_ROAD_2
+ jr z, .found
+ cp VICTORY_ROAD_3
+ jr z, .found
+ cp INDIGO_PLATEAU
+ jr z, .found
+ and a
+ ret
+.found
+ scf
+ ret
-.next
- ld c, 6
+UpdateMusic6Times::
+ ld c, $6
+UpdateMusicCTimes::
.loop
push bc
push hl
- call Bankswitch
+ callba Audio1_UpdateMusic ; 2:509d
pop hl
pop bc
dec c
@@ -137,7 +135,20 @@ PlayMusic::
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, b
+ jr PlaySound
+
+Func_2223::
+ xor a
+ ld [wChannelSoundIDs + CH4], a
+ ld [wChannelSoundIDs + CH5], a
+ ld [wChannelSoundIDs + CH6], a
+ ld [wChannelSoundIDs + CH7], a
+ ld [rNR10], a
+ ret
+StopAllMusic::
+ ld a, $FF
+ ld [wNewSoundID], a
; plays music specified by a. If value is $ff, music is stopped
PlaySound::
push hl
@@ -154,65 +165,130 @@ PlaySound::
ld [wChannelSoundIDs + CH7], a
.next
ld a, [wAudioFadeOutControl]
- and a ; has a fade-out length been specified?
+ and a
jr z, .noFadeOut
ld a, [wNewSoundID]
- and a ; is the new sound ID 0?
- jr z, .done ; if so, do nothing
+ and a
+ jr z, .done
xor a
ld [wNewSoundID], a
ld a, [wLastMusicSoundID]
- cp $ff ; has the music been stopped?
- jr nz, .fadeOut ; if not, fade out the current music
-; If it has been stopped, start playing the new music immediately.
+ cp $ff
+ jr nz, .fadeOut
xor a
ld [wAudioFadeOutControl], a
.noFadeOut
xor a
ld [wNewSoundID], a
+ call DetermineAudioFunction
+ jr .done
+
+.fadeOut
+ ld a, b
+ ld [wLastMusicSoundID], a
+ ld a, [wAudioFadeOutControl]
+ ld [wAudioFadeOutCounterReloadValue], a
+ ld [wAudioFadeOutCounter], a
+ ld a, b
+ ld [wAudioFadeOutControl], a
+.done
+ pop bc
+ pop de
+ pop hl
+ ret
+
+GetNextMusicByte::
ld a, [H_LOADEDROMBANK]
- ld [hSavedROMBank], a
+ push af
ld a, [wAudioROMBank]
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
- cp BANK(Audio1_PlaySound)
- jr nz, .checkForAudio2
+ call BankswitchCommon
+ ld d, $0
+ ld a, c
+ add a
+ ld e, a
+ ld hl, wChannelCommandPointers
+ add hl, de
+ ld a, [hli]
+ ld e, a
+ ld a, [hld]
+ ld d, a
+ ld a, [de]
+ inc de
+ ld [hl], e
+ inc hl
+ ld [hl], d
+ ld e, a
+ pop af
+ call BankswitchCommon
+ ld a, e
+ ret
+
+InitMusicVariables::
+ push hl
+ push de
+ push bc
+ homecall Audio2_InitMusicVariables ; 8:59f8
+ pop bc
+ pop de
+ pop hl
+ ret
+
+InitSFXVariables::
+ push hl
+ push de
+ push bc
+ homecall Audio2_InitSFXVariables ; 8:5ab7
+ pop bc
+ pop de
+ pop hl
+ ret
-; audio 1
+StopAllAudio::
+ push hl
+ push de
+ push bc
+ homecall Audio2_StopAllAudio
+ pop bc
+ pop de
+ pop hl
+ ret
+
+DetermineAudioFunction::
+ ld a, [H_LOADEDROMBANK]
+ push af
+ ld a, [wAudioROMBank]
+ call BankswitchCommon
+; determine the audio function, based on the bank
+ cp BANK(Audio1_PlaySound)
+ jr nz, .checkForBank08
+; bank 02 (audio 1)
ld a, b
call Audio1_PlaySound
- jr .next2
+ jr .done
-.checkForAudio2
+.checkForBank08
cp BANK(Audio2_PlaySound)
- jr nz, .audio3
-
-; audio 2
+ jr nz, .checkForBank1F
+; bank 08 (audio 2)
ld a, b
call Audio2_PlaySound
- jr .next2
+ jr .done
-.audio3
+.checkForBank1F
+ cp BANK(Audio3_PlaySound)
+ jr nz, .bank20
+; bank 1f (audio 3)
ld a, b
call Audio3_PlaySound
-
-.next2
- ld a, [hSavedROMBank]
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
jr .done
-.fadeOut
+.bank20
+; invalid banks will default to XX:6bd4
+; this is seen when encountering Missingno, as its sprite dimensions overflow to wAudioROMBank
ld a, b
- ld [wLastMusicSoundID], a
- ld a, [wAudioFadeOutControl]
- ld [wAudioFadeOutCounterReloadValue], a
- ld [wAudioFadeOutCounter], a
- ld a, b
- ld [wAudioFadeOutControl], a
-
+ call Audio4_PlaySound
.done
- pop bc
- pop de
- pop hl
+ pop af
+ call BankswitchCommon
ret
+