summaryrefslogtreecommitdiff
path: root/home/audio.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home/audio.asm')
-rw-r--r--home/audio.asm171
1 files changed, 127 insertions, 44 deletions
diff --git a/home/audio.asm b/home/audio.asm
index eded85e9..41fb503a 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -24,6 +24,8 @@ PlayDefaultMusicCommon::
jr z, .walking
cp $2
jr z, .surfing
+ call CheckForNoBikingMusicMap
+ jr c, .walking
ld a, MUSIC_BIKE_RIDING
jr .next
@@ -66,33 +68,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_1F
+ jr z, .found
+ cp VICTORY_ROAD_2F
+ jr z, .found
+ cp VICTORY_ROAD_3F
+ jr z, .found
+ cp INDIGO_PLATEAU
+ jr z, .found
+ and a
+ ret
+.found
+ scf
+ ret
-.next
+UpdateMusic6Times::
ld c, 6
+UpdateMusicCTimes::
.loop
push bc
push hl
- call Bankswitch
+ farcall Audio1_UpdateMusic
pop hl
pop bc
dec c
@@ -135,7 +136,20 @@ PlayMusic::
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, b
+ jr PlaySound
+Func_2223::
+ xor a
+ ld [wChannelSoundIDs + Ch5], a
+ ld [wChannelSoundIDs + Ch6], a
+ ld [wChannelSoundIDs + Ch7], a
+ ld [wChannelSoundIDs + Ch8], a
+ ldh [rNR10], a
+ ret
+
+StopAllMusic::
+ ld a, SFX_STOP_ALL_MUSIC
+ ld [wNewSoundID], a
; plays music specified by a. If value is $ff, music is stopped
PlaySound::
push hl
@@ -168,47 +182,116 @@ PlaySound::
.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::
ldh a, [hLoadedROMBank]
- ldh [hSavedROMBank], a
+ push af
ld a, [wAudioROMBank]
- ldh [hLoadedROMBank], a
- ld [MBC1RomBank], a
+ 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
+ pop bc
+ pop de
+ pop hl
+ ret
+
+InitSFXVariables::
+ push hl
+ push de
+ push bc
+ homecall Audio2_InitSFXVariables
+ pop bc
+ pop de
+ pop hl
+ ret
+
+StopAllAudio::
+ push hl
+ push de
+ push bc
+ homecall Audio2_StopAllAudio
+ pop bc
+ pop de
+ pop hl
+ ret
+
+DetermineAudioFunction::
+ ldh a, [hLoadedROMBank]
+ push af
+ ld a, [wAudioROMBank]
+ call BankswitchCommon
+; determine the audio function, based on the bank
cp BANK(Audio1_PlaySound)
jr nz, .checkForAudio2
; audio 1
ld a, b
call Audio1_PlaySound
- jr .next2
+ jr .done
.checkForAudio2
cp BANK(Audio2_PlaySound)
- jr nz, .audio3
+ jr nz, .checkForAudio3
; audio 2
ld a, b
call Audio2_PlaySound
- jr .next2
+ jr .done
-.audio3
+.checkForAudio3
+ cp BANK(Audio3_PlaySound)
+ jr nz, .audio4
+; audio 3
ld a, b
call Audio3_PlaySound
-
-.next2
- ldh a, [hSavedROMBank]
- ldh [hLoadedROMBank], a
- ld [MBC1RomBank], a
jr .done
-.fadeOut
+.audio4
+; invalid banks will default to audio 4
+; 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