pokered/home/audio.asm

215 lines
4.1 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
PlayDefaultMusic::
2014-05-31 08:22:15 +00:00
call WaitForSoundToFinish
xor a
ld c, a
ld d, a
2015-08-09 05:32:44 +00:00
ld [wLastMusicSoundID], a
jr PlayDefaultMusicCommon
2014-05-31 08:22:15 +00:00
2016-06-12 00:24:04 +00:00
PlayDefaultMusicFadeOutCurrent::
2015-08-09 05:32:44 +00:00
; Fade out the current music and then play the default music.
ld c, 10
ld d, 0
2014-05-31 08:22:15 +00:00
ld a, [wd72e]
2015-08-09 05:32:44 +00:00
bit 5, a ; has a battle just ended?
jr z, PlayDefaultMusicCommon
2014-05-31 08:22:15 +00:00
xor a
2015-08-09 05:32:44 +00:00
ld [wLastMusicSoundID], a
ld c, 8
2014-05-31 08:22:15 +00:00
ld d, c
2015-08-09 05:32:44 +00:00
2016-06-12 00:24:04 +00:00
PlayDefaultMusicCommon::
2014-09-13 07:50:56 +00:00
ld a, [wWalkBikeSurfState]
2014-05-31 08:22:15 +00:00
and a
2015-08-09 05:32:44 +00:00
jr z, .walking
2014-05-31 08:22:15 +00:00
cp $2
2015-08-09 05:32:44 +00:00
jr z, .surfing
2014-05-31 08:22:15 +00:00
ld a, MUSIC_BIKE_RIDING
2015-08-09 05:32:44 +00:00
jr .next
.surfing
2014-05-31 08:22:15 +00:00
ld a, MUSIC_SURFING
2015-08-09 05:32:44 +00:00
.next
2014-05-31 08:22:15 +00:00
ld b, a
ld a, d
2015-08-09 05:32:44 +00:00
and a ; should current music be faded out first?
2014-06-09 20:18:29 +00:00
ld a, BANK(Music_BikeRiding)
2015-08-09 05:32:44 +00:00
jr nz, .next2
; Only change the audio ROM bank if the current music isn't going to be faded
; out before the default music begins.
ld [wAudioROMBank], a
.next2
; [wAudioSavedROMBank] will be copied to [wAudioROMBank] after fading out the
; current music (if the current music is faded out).
ld [wAudioSavedROMBank], a
jr .next3
.walking
ld a, [wMapMusicSoundID]
2014-05-31 08:22:15 +00:00
ld b, a
2015-08-09 05:32:44 +00:00
call CompareMapMusicBankWithCurrentBank
jr c, .next4
.next3
ld a, [wLastMusicSoundID]
cp b ; is the default music already playing?
ret z ; if so, do nothing
.next4
2014-05-31 08:22:15 +00:00
ld a, c
2015-08-09 05:32:44 +00:00
ld [wAudioFadeOutControl], a
2014-05-31 08:22:15 +00:00
ld a, b
2015-08-09 05:32:44 +00:00
ld [wLastMusicSoundID], a
ld [wNewSoundID], a
2014-05-31 08:22:15 +00:00
jp PlaySound
2016-06-12 00:24:04 +00:00
UpdateMusic6Times::
2015-08-09 05:32:44 +00:00
; 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]
2014-05-31 08:22:15 +00:00
ld b, a
cp BANK(Audio1_UpdateMusic)
jr nz, .checkForAudio2
2015-08-09 05:32:44 +00:00
; audio 1
ld hl, Audio1_UpdateMusic
2015-08-09 05:32:44 +00:00
jr .next
.checkForAudio2
cp BANK(Audio2_UpdateMusic)
jr nz, .audio3
2015-08-09 05:32:44 +00:00
; audio 2
ld hl, Audio2_UpdateMusic
2015-08-09 05:32:44 +00:00
jr .next
.audio3
ld hl, Audio3_UpdateMusic
2015-08-09 05:32:44 +00:00
.next
ld c, 6
.loop
2014-05-31 08:22:15 +00:00
push bc
push hl
call Bankswitch
pop hl
pop bc
dec c
2015-08-09 05:32:44 +00:00
jr nz, .loop
2014-05-31 08:22:15 +00:00
ret
2016-06-12 00:24:04 +00:00
CompareMapMusicBankWithCurrentBank::
2015-08-09 05:32:44 +00:00
; Compares the map music's audio ROM bank with the current audio ROM bank
; and updates the audio ROM bank variables.
; Returns whether the banks are different in carry.
ld a, [wMapMusicROMBank]
2014-05-31 08:22:15 +00:00
ld e, a
2015-08-09 05:32:44 +00:00
ld a, [wAudioROMBank]
2014-05-31 08:22:15 +00:00
cp e
2015-08-09 05:32:44 +00:00
jr nz, .differentBanks
ld [wAudioSavedROMBank], a
2014-05-31 08:22:15 +00:00
and a
ret
2015-08-09 05:32:44 +00:00
.differentBanks
ld a, c ; this is a fade-out counter value and it's always non-zero
2014-05-31 08:22:15 +00:00
and a
ld a, e
2015-08-09 05:32:44 +00:00
jr nz, .next
; If the fade-counter is non-zero, we don't change the audio ROM bank because
; it's needed to keep playing the music as it fades out. The FadeOutAudio
; routine will take care of copying [wAudioSavedROMBank] to [wAudioROMBank]
; when the music has faded out.
ld [wAudioROMBank], a
.next
ld [wAudioSavedROMBank], a
2014-05-31 08:22:15 +00:00
scf
ret
2016-06-12 00:24:04 +00:00
PlayMusic::
2014-05-31 08:22:15 +00:00
ld b, a
2015-08-09 05:32:44 +00:00
ld [wNewSoundID], a
2014-05-31 08:22:15 +00:00
xor a
2015-08-09 05:32:44 +00:00
ld [wAudioFadeOutControl], a
2014-05-31 08:22:15 +00:00
ld a, c
2015-08-09 05:32:44 +00:00
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
2014-05-31 08:22:15 +00:00
ld a, b
; plays music specified by a. If value is $ff, music is stopped
2016-06-12 00:24:04 +00:00
PlaySound::
2014-05-31 08:22:15 +00:00
push hl
push de
push bc
ld b, a
2015-08-09 05:32:44 +00:00
ld a, [wNewSoundID]
2014-05-31 08:22:15 +00:00
and a
2015-08-09 05:32:44 +00:00
jr z, .next
2014-05-31 08:22:15 +00:00
xor a
ld [wChannelSoundIDs + CHAN5], a
ld [wChannelSoundIDs + CHAN6], a
ld [wChannelSoundIDs + CHAN7], a
ld [wChannelSoundIDs + CHAN8], a
2015-08-09 05:32:44 +00:00
.next
ld a, [wAudioFadeOutControl]
and a ; has a fade-out length been specified?
jr z, .noFadeOut
ld a, [wNewSoundID]
and a ; is the new sound ID 0?
jr z, .done ; if so, do nothing
2014-05-31 08:22:15 +00:00
xor a
2015-08-09 05:32:44 +00:00
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.
2014-05-31 08:22:15 +00:00
xor a
2015-08-09 05:32:44 +00:00
ld [wAudioFadeOutControl], a
.noFadeOut
2014-05-31 08:22:15 +00:00
xor a
2015-08-09 05:32:44 +00:00
ld [wNewSoundID], a
ldh a, [hLoadedROMBank]
ldh [hSavedROMBank], a
2015-08-09 05:32:44 +00:00
ld a, [wAudioROMBank]
ldh [hLoadedROMBank], a
ld [MBC1RomBank], a
2015-08-09 05:32:44 +00:00
cp BANK(Audio1_PlaySound)
jr nz, .checkForAudio2
2015-08-09 05:32:44 +00:00
; audio 1
2014-05-31 08:22:15 +00:00
ld a, b
2015-08-09 05:32:44 +00:00
call Audio1_PlaySound
jr .next2
.checkForAudio2
2015-08-09 05:32:44 +00:00
cp BANK(Audio2_PlaySound)
jr nz, .audio3
2015-08-09 05:32:44 +00:00
; audio 2
2014-05-31 08:22:15 +00:00
ld a, b
2015-08-09 05:32:44 +00:00
call Audio2_PlaySound
jr .next2
.audio3
2014-05-31 08:22:15 +00:00
ld a, b
2015-08-09 05:32:44 +00:00
call Audio3_PlaySound
.next2
ldh a, [hSavedROMBank]
ldh [hLoadedROMBank], a
ld [MBC1RomBank], a
2015-08-09 05:32:44 +00:00
jr .done
.fadeOut
2014-05-31 08:22:15 +00:00
ld a, b
2015-08-09 05:32:44 +00:00
ld [wLastMusicSoundID], a
ld a, [wAudioFadeOutControl]
ld [wAudioFadeOutCounterReloadValue], a
ld [wAudioFadeOutCounter], a
2014-05-31 08:22:15 +00:00
ld a, b
2015-08-09 05:32:44 +00:00
ld [wAudioFadeOutControl], a
.done
2014-05-31 08:22:15 +00:00
pop bc
pop de
pop hl
ret