1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
; Audio interfaces.
MapSetup_Sound_Off:: ; 3b4e
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
ld a, BANK(_MapSetup_Sound_Off)
ld [hROMBank], a
ld [MBC3RomBank], a
call _MapSetup_Sound_Off
pop af
ld [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
; 3b6a
UpdateSound:: ; 3b6a
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
ld a, BANK(_UpdateSound)
ld [hROMBank], a
ld [MBC3RomBank], a
call _UpdateSound
pop af
ld [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
; 3b86
_LoadMusicByte:: ; 3b86
; CurMusicByte = [a:de]
GLOBAL LoadMusicByte
ld [hROMBank], a
ld [MBC3RomBank], a
ld a, [de]
ld [CurMusicByte], a
ld a, BANK(LoadMusicByte)
ld [hROMBank], a
ld [MBC3RomBank], a
ret
; 3b97
PlayMusic:: ; 3b97
; Play music de.
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
ld a, BANK(_PlayMusic) ; and BANK(_MapSetup_Sound_Off)
ld [hROMBank], a
ld [MBC3RomBank], a
ld a, e
and a
jr z, .nomusic
call _PlayMusic
jr .end
.nomusic
call _MapSetup_Sound_Off
.end
pop af
ld [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
; 3bbc
PlayMusic2:: ; 3bbc
; Stop playing music, then play music de.
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
ld a, BANK(_PlayMusic)
ld [hROMBank], a
ld [MBC3RomBank], a
push de
ld de, MUSIC_NONE
call _PlayMusic
call DelayFrame
pop de
call _PlayMusic
pop af
ld [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
; 3be3
PlayCryHeader:: ; 3be3
; Play cry header de.
push hl
push de
push bc
push af
ld a, [hROMBank]
push af
; Cry headers are stuck in one bank.
ld a, BANK(CryHeaders)
ld [hROMBank], a
ld [MBC3RomBank], a
ld hl, CryHeaders
rept 6
add hl, de
endr
ld e, [hl]
inc hl
ld d, [hl]
inc hl
ld a, [hli]
ld [CryPitch], a
ld a, [hli]
ld [CryPitch + 1], a
ld a, [hli]
ld [CryLength], a
ld a, [hl]
ld [CryLength + 1], a
ld a, BANK(_PlayCryHeader)
ld [hROMBank], a
ld [MBC3RomBank], a
call _PlayCryHeader
pop af
ld [hROMBank], a
ld [MBC3RomBank], a
pop af
pop bc
pop de
pop hl
ret
; 3c23
PlaySFX:: ; 3c23
; Play sound effect de.
; Sound effects are ordered by priority (lowest to highest)
push hl
push de
push bc
push af
; Is something already playing?
call CheckSFX
jr nc, .play
; Does it have priority?
ld a, [CurSFX]
cp e
jr c, .done
.play
ld a, [hROMBank]
push af
ld a, BANK(_PlaySFX)
ld [hROMBank], a
ld [MBC3RomBank], a
ld a, e
ld [CurSFX], a
call _PlaySFX
pop af
ld [hROMBank], a
ld [MBC3RomBank], a
.done
pop af
pop bc
pop de
pop hl
ret
; 3c4e
WaitPlaySFX:: ; 3c4e
call WaitSFX
call PlaySFX
ret
; 3c55
WaitSFX:: ; 3c55
; infinite loop until sfx is done playing
push hl
.wait
ld hl, Channel5Flags
bit 0, [hl]
jr nz, .wait
ld hl, Channel6Flags
bit 0, [hl]
jr nz, .wait
ld hl, Channel7Flags
bit 0, [hl]
jr nz, .wait
ld hl, Channel8Flags
bit 0, [hl]
jr nz, .wait
pop hl
ret
; 3c74
IsSFXPlaying:: ; 3c74
; Return carry if no sound effect is playing.
; The inverse of CheckSFX.
push hl
ld hl, Channel5Flags
bit 0, [hl]
jr nz, .playing
ld hl, Channel6Flags
bit 0, [hl]
jr nz, .playing
ld hl, Channel7Flags
bit 0, [hl]
jr nz, .playing
ld hl, Channel8Flags
bit 0, [hl]
jr nz, .playing
pop hl
scf
ret
.playing
pop hl
and a
ret
; 3c97
MaxVolume:: ; 3c97
ld a, $77 ; max
ld [Volume], a
ret
; 3c9d
LowVolume:: ; 3c9d
ld a, $33 ; 40%
ld [Volume], a
ret
; 3ca3
VolumeOff:: ; 3ca3
xor a
ld [Volume], a
ret
; 3ca8
Unused_FadeOutMusic:: ; 3ca8
ld a, 4
ld [MusicFade], a
ret
; 3cae
FadeInMusic:: ; 3cae
ld a, 4 | 1 << 7
ld [MusicFade], a
ret
; 3cb4
SkipMusic:: ; 3cb4
; Skip a frames of music.
.loop
and a
ret z
dec a
call UpdateSound
jr .loop
; 3cbc
FadeToMapMusic:: ; 3cbc
push hl
push de
push bc
push af
call GetMapMusic
ld a, [wMapMusic]
cp e
jr z, .done
ld a, 8
ld [MusicFade], a
ld a, e
ld [MusicFadeIDLo], a
ld a, d
ld [MusicFadeIDHi], a
ld a, e
ld [wMapMusic], a
.done
pop af
pop bc
pop de
pop hl
ret
; 3cdf
PlayMapMusic:: ; 3cdf
push hl
push de
push bc
push af
call GetMapMusic
ld a, [wMapMusic]
cp e
jr z, .done
push de
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
pop de
ld a, e
ld [wMapMusic], a
call PlayMusic
.done
pop af
pop bc
pop de
pop hl
ret
; 3d03
EnterMapMusic:: ; 3d03
push hl
push de
push bc
push af
xor a
ld [wDontPlayMapMusicOnReload], a
ld de, MUSIC_BICYCLE
ld a, [PlayerState]
cp PLAYER_BIKE
jr z, .play
call GetMapMusic
.play
push de
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
pop de
ld a, e
ld [wMapMusic], a
call PlayMusic
pop af
pop bc
pop de
pop hl
ret
; 3d2f
TryRestartMapMusic:: ; 3d2f
ld a, [wDontPlayMapMusicOnReload]
and a
jr z, RestartMapMusic
xor a
ld [wMapMusic], a
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
xor a
ld [wDontPlayMapMusicOnReload], a
ret
; 3d47
RestartMapMusic:: ; 3d47
push hl
push de
push bc
push af
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld a, [wMapMusic]
ld e, a
ld d, 0
call PlayMusic
pop af
pop bc
pop de
pop hl
ret
; 3d62
SpecialMapMusic:: ; 3d62
ld a, [PlayerState]
cp PLAYER_SURF
jr z, .surf
cp PLAYER_SURF_PIKA
jr z, .surf
ld a, [StatusFlags2]
bit 2, a
jr nz, .contest
.no
and a
ret
.bike
ld de, MUSIC_BICYCLE
scf
ret
.surf
ld de, MUSIC_SURF
scf
ret
.contest
ld a, [MapGroup]
cp GROUP_ROUTE_35_NATIONAL_PARK_GATE
jr nz, .no
ld a, [MapNumber]
cp MAP_ROUTE_35_NATIONAL_PARK_GATE
jr z, .ranking
cp MAP_ROUTE_36_NATIONAL_PARK_GATE
jr nz, .no
.ranking
ld de, MUSIC_BUG_CATCHING_CONTEST_RANKING
scf
ret
; 3d97
GetMapMusic:: ; 3d97
call SpecialMapMusic
ret c
call GetMapHeaderMusic
ret
; 3d9f
Function3d9f:: ; 3d9f
; Places a BCD number at the
; upper center of the screen.
; Unreferenced.
ld a, 4 * 8
ld [Sprites + 38 * 4], a
ld [Sprites + 39 * 4], a
ld a, 10 * 8
ld [Sprites + 38 * 4 + 1], a
ld a, 11 * 8
ld [Sprites + 39 * 4 + 1], a
xor a
ld [Sprites + 38 * 4 + 3], a
ld [Sprites + 39 * 4 + 3], a
ld a, [wc296]
cp 100
jr nc, .max
add 1
daa
ld b, a
swap a
and $f
add "0"
ld [Sprites + 38 * 4 + 2], a
ld a, b
and $f
add "0"
ld [Sprites + 39 * 4 + 2], a
ret
.max
ld a, "9"
ld [Sprites + 38 * 4 + 2], a
ld [Sprites + 39 * 4 + 2], a
ret
; 3dde
CheckSFX:: ; 3dde
; Return carry if any SFX channels are active.
ld a, [Channel5Flags]
bit 0, a
jr nz, .playing
ld a, [Channel6Flags]
bit 0, a
jr nz, .playing
ld a, [Channel7Flags]
bit 0, a
jr nz, .playing
ld a, [Channel8Flags]
bit 0, a
jr nz, .playing
and a
ret
.playing
scf
ret
; 3dfe
TerminateExpBarSound:: ; 3dfe
xor a
ld [Channel5Flags], a
ld [SoundInput], a
ld [rNR10], a
ld [rNR11], a
ld [rNR12], a
ld [rNR13], a
ld [rNR14], a
ret
; 3e10
ChannelsOff:: ; 3e10
; Quickly turn off music channels
xor a
ld [Channel1Flags], a
ld [Channel2Flags], a
ld [Channel3Flags], a
ld [Channel4Flags], a
ld [SoundInput], a
ret
; 3e21
SFXChannelsOff:: ; 3e21
; Quickly turn off sound effect channels
xor a
ld [Channel5Flags], a
ld [Channel6Flags], a
ld [Channel7Flags], a
ld [Channel8Flags], a
ld [SoundInput], a
ret
; 3e32
|