| 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
 | PlayPikachuSoundClip: ; 0x50000
; Plays the pcm (pulse-code modulation) sound clip of one of the pikachu noises.
	sla a
	ld c, a
	ld b, $0
	ld hl, PikachuSoundClipPointers
	add hl, bc
	ld a, [hli]
	ld h, [hl]
	ld l, a
	push hl
	di
	ld b, $4
.asm_50010
	ld a, [rLY]
	and a
	jr nz, .asm_50010
	dec b
	jr nz, .asm_50010
	xor a
	ld [rNR50], a
	ld [rNR51], a
	ld a, $80
	ld [rNR52], a
	xor a
	ld [rNR30], a
	ld hl, wd84b
	ld c, $30
	ld b, $10
.asm_5002b
	ld a, [$ff00+c]
	ld [hli], a
	ld a, $ff
	ld [$ff00+c], a
	inc c
	dec b
	jr nz, .asm_5002b
	ld a, $80
	ld [rNR30], a
	ld a, $ff
	ld [rNR31], a
	ld a, $20
	ld [rNR32], a
	ld a, $ff
	ld [rNR33], a
	ld a, $87
	ld [rNR34], a
	ld a, $77
	ld [rNR50], a
	ld a, $44
	ld [rNR51], a
	pop hl
	call PlayPikachuPCM
	xor a
	ld [rNR50], a
	ld [rNR51], a
	ld [rNR52], a
	ld hl, wd84b
	ld c, $30
	ld b, $10
.asm_50062
	ld a, [hli]
	ld [$ff00+c], a
	inc c
	dec b
	jr nz, .asm_50062
	ld a, $77
	ld [rNR50], a
	ld a, $ff
	ld [rNR51], a
	ld a, $80
	ld [rNR52], a
	ei
	ret
PikachuSoundClipPointers: ; 0x50076
	dw PikachuBillboardBonusSoundClip
	dw PikachuThundershockSoundClip
PikachuBillboardBonusSoundClip:  ; 0x5007a
	dw $caf  ; length of the pcm data (todo: there is probably a way to do this dynamically with rgbds)
	INCBIN "audio/sound_clips/pi_ka_chu.pcm"
	db $1f  ; unused
PikachuThundershockSoundClip:  ; 0x50d2c
	dw $1227  ; length of the pcm data (todo: there is probably a way to do this dynamically with rgbds)
	INCBIN "audio/sound_clips/piiiiikaaaa.pcm"
	db $f0, $00, $00  ; unused
PlayPikachuPCM: ; 0x51f56
; Plays the audio PCM at [hl]
	ld a, [hli]
	ld c, a
	ld a, [hli]
	ld b, a
	; bc = number of bytes in the sound clip's PCM (pulse-code modulation)
.loop
	ld a, [hli]
	ld d, a
	ld a, $3
.playSingleSample
	dec a
	jr nz, .playSingleSample
	call LoadNextSoundClipSample
	call PlaySoundClipSample
	call LoadNextSoundClipSample
	call PlaySoundClipSample
	call LoadNextSoundClipSample
	call PlaySoundClipSample
	call LoadNextSoundClipSample
	call PlaySoundClipSample
	call LoadNextSoundClipSample
	call PlaySoundClipSample
	call LoadNextSoundClipSample
	call PlaySoundClipSample
	call LoadNextSoundClipSample
	call PlaySoundClipSample
	call LoadNextSoundClipSample
	dec bc
	ld a, c
	or b
	jr nz, .loop
	ret
LoadNextSoundClipSample: ; 0x51f94
	ld a, d
	and $80
	srl a
	srl a
	ld [rNR32], a
	sla d
	ret
PlaySoundClipSample: ; 0x51fa0
	ld a, $3
.loop
	dec a
	jr nz, .loop
	ret
 |