Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/home/audio.asm
1270 views
1
PlayDefaultMusic::
2
call WaitForSoundToFinish
3
xor a
4
ld c, a
5
ld d, a
6
ld [wLastMusicSoundID], a
7
jr PlayDefaultMusicCommon
8
9
PlayDefaultMusicFadeOutCurrent::
10
; Fade out the current music and then play the default music.
11
ld c, 10
12
ld d, 0
13
ld a, [wStatusFlags4]
14
bit BIT_BATTLE_OVER_OR_BLACKOUT, a
15
jr z, PlayDefaultMusicCommon
16
xor a
17
ld [wLastMusicSoundID], a
18
ld c, 8
19
ld d, c
20
21
PlayDefaultMusicCommon::
22
ld a, [wWalkBikeSurfState]
23
and a
24
jr z, .walking
25
cp $2
26
jr z, .surfing
27
ld a, MUSIC_BIKE_RIDING
28
jr .next
29
30
.surfing
31
ld a, MUSIC_SURFING
32
33
.next
34
ld b, a
35
ld a, d
36
and a ; should current music be faded out first?
37
ld a, BANK(Music_BikeRiding)
38
jr nz, .next2
39
40
; Only change the audio ROM bank if the current music isn't going to be faded
41
; out before the default music begins.
42
ld [wAudioROMBank], a
43
44
.next2
45
; [wAudioSavedROMBank] will be copied to [wAudioROMBank] after fading out the
46
; current music (if the current music is faded out).
47
ld [wAudioSavedROMBank], a
48
jr .next3
49
50
.walking
51
ld a, [wMapMusicSoundID]
52
ld b, a
53
call CompareMapMusicBankWithCurrentBank
54
jr c, .next4
55
56
.next3
57
ld a, [wLastMusicSoundID]
58
cp b ; is the default music already playing?
59
ret z ; if so, do nothing
60
61
.next4
62
ld a, c
63
ld [wAudioFadeOutControl], a
64
ld a, b
65
ld [wLastMusicSoundID], a
66
ld [wNewSoundID], a
67
jp PlaySound
68
69
UpdateMusic6Times::
70
; This is called when entering a map, before fading out the current music and
71
; playing the default music (i.e. the map's music or biking/surfing music).
72
ld a, [wAudioROMBank]
73
ld b, a
74
cp BANK(Audio1_UpdateMusic)
75
jr nz, .checkForAudio2
76
; audio 1
77
ld hl, Audio1_UpdateMusic
78
jr .next
79
80
.checkForAudio2
81
cp BANK(Audio2_UpdateMusic)
82
jr nz, .audio3
83
; audio 2
84
ld hl, Audio2_UpdateMusic
85
jr .next
86
87
.audio3
88
ld hl, Audio3_UpdateMusic
89
90
.next
91
ld c, 6
92
.loop
93
push bc
94
push hl
95
call Bankswitch
96
pop hl
97
pop bc
98
dec c
99
jr nz, .loop
100
ret
101
102
CompareMapMusicBankWithCurrentBank::
103
; Compares the map music's audio ROM bank with the current audio ROM bank
104
; and updates the audio ROM bank variables.
105
; Returns whether the banks are different in carry.
106
ld a, [wMapMusicROMBank]
107
ld e, a
108
ld a, [wAudioROMBank]
109
cp e
110
jr nz, .differentBanks
111
ld [wAudioSavedROMBank], a
112
and a
113
ret
114
.differentBanks
115
ld a, c ; this is a fade-out counter value and it's always non-zero
116
and a
117
ld a, e
118
jr nz, .next
119
; If the fade-counter is non-zero, we don't change the audio ROM bank because
120
; it's needed to keep playing the music as it fades out. The FadeOutAudio
121
; routine will take care of copying [wAudioSavedROMBank] to [wAudioROMBank]
122
; when the music has faded out.
123
ld [wAudioROMBank], a
124
.next
125
ld [wAudioSavedROMBank], a
126
scf
127
ret
128
129
PlayMusic::
130
ld b, a
131
ld [wNewSoundID], a
132
xor a
133
ld [wAudioFadeOutControl], a
134
ld a, c
135
ld [wAudioROMBank], a
136
ld [wAudioSavedROMBank], a
137
ld a, b
138
139
; plays music specified by a. If value is $ff, music is stopped
140
PlaySound::
141
push hl
142
push de
143
push bc
144
ld b, a
145
ld a, [wNewSoundID]
146
and a
147
jr z, .next
148
xor a
149
ld [wChannelSoundIDs + CHAN5], a
150
ld [wChannelSoundIDs + CHAN6], a
151
ld [wChannelSoundIDs + CHAN7], a
152
ld [wChannelSoundIDs + CHAN8], a
153
.next
154
ld a, [wAudioFadeOutControl]
155
and a ; has a fade-out length been specified?
156
jr z, .noFadeOut
157
ld a, [wNewSoundID]
158
and a ; is the new sound ID 0?
159
jr z, .done ; if so, do nothing
160
xor a
161
ld [wNewSoundID], a
162
ld a, [wLastMusicSoundID]
163
cp $ff ; has the music been stopped?
164
jr nz, .fadeOut ; if not, fade out the current music
165
; If it has been stopped, start playing the new music immediately.
166
xor a
167
ld [wAudioFadeOutControl], a
168
.noFadeOut
169
xor a
170
ld [wNewSoundID], a
171
ldh a, [hLoadedROMBank]
172
ldh [hSavedROMBank], a
173
ld a, [wAudioROMBank]
174
ldh [hLoadedROMBank], a
175
ld [rROMB], a
176
cp BANK(Audio1_PlaySound)
177
jr nz, .checkForAudio2
178
; audio 1
179
ld a, b
180
call Audio1_PlaySound
181
jr .next2
182
183
.checkForAudio2
184
cp BANK(Audio2_PlaySound)
185
jr nz, .audio3
186
; audio 2
187
ld a, b
188
call Audio2_PlaySound
189
jr .next2
190
191
.audio3
192
ld a, b
193
call Audio3_PlaySound
194
195
.next2
196
ldh a, [hSavedROMBank]
197
ldh [hLoadedROMBank], a
198
ld [rROMB], a
199
jr .done
200
201
.fadeOut
202
ld a, b
203
ld [wLastMusicSoundID], a
204
ld a, [wAudioFadeOutControl]
205
ld [wAudioFadeOutCounterReloadValue], a
206
ld [wAudioFadeOutCounter], a
207
ld a, b
208
ld [wAudioFadeOutControl], a
209
210
.done
211
pop bc
212
pop de
213
pop hl
214
ret
215
216