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
|
When your Pokémon's HP is in the red, the battle music is replaced by a continuous beeping noise. This can be quite annoying. If you want a brief alert that your HP is low, just follow this tutorial.
Edit [audio/engine.asm](../blob/master/audio/engine.asm):
```diff
UpdateChannels:
...
.Channel1:
ld a, [wLowHealthAlarm]
+ cp $ff
+ jr z, .Channel5
bit DANGER_ON_F, a
ret nz
.Channel5:
...
```
```diff
PlayDanger:
ld a, [wLowHealthAlarm]
bit DANGER_ON_F, a
ret z
+ cp $ff
+ ret z
; Don't do anything if SFX is being played
- and ~(1 << DANGER_ON_F)
ld d, a
call _CheckSFX
jr c, .increment
+ ld a, d
; Play the high tone
- and a
- jr z, .begin
+ and $1f
+ ld hl, DangerSoundHigh
+ jr z, .applychannel
; Play the low tone
cp 16
+ jr nz, .increment
- jr z, .halfway
-
- jr .increment
-
-.halfway
ld hl, DangerSoundLow
- jr .applychannel
-
-.begin
- ld hl, DangerSoundHigh
.applychannel
xor a
ldh [rNR10], a
ld a, [hli]
ldh [rNR11], a
ld a, [hli]
ldh [rNR12], a
ld a, [hli]
ldh [rNR13], a
ld a, [hli]
ldh [rNR14], a
.increment
ld a, d
+ and $e0
+ ld e, a
+ ld a, d
+ and $1f
inc a
cp 30 ; Ending frame
jr c, .noreset
- xor a
+ add 2
.noreset
- ; Make sure the danger sound is kept on
- or 1 << DANGER_ON_F
+ add e
+ jr nz, .load
+ dec a
+.load
ld [wLowHealthAlarm], a
; Enable channel 1 if it's off
ld a, [wSoundOutput]
and $11
ret nz
ld a, [wSoundOutput]
or $11
ld [wSoundOutput], a
ret
DangerSoundHigh:
db $80 ; duty 50%
db $e2 ; volume 14, envelope decrease sweep 2
db $50 ; frequency: $750
db $87 ; restart sound
DangerSoundLow:
db $80 ; duty 50%
db $e2 ; volume 14, envelope decrease sweep 2
db $ee ; frequency: $6ee
db $86 ; restart sound
```
And edit [engine/battle/core.asm](../blob/master/engine/battle/core.asm):
```diff
CheckDanger:
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
jr z, .no_danger
ld a, [wBattleLowHealthAlarm]
and a
jr nz, .done
ld a, [wPlayerHPPal]
cp HP_RED
jr z, .danger
.no_danger
ld hl, wLowHealthAlarm
+ ld [hl], 0
- res DANGER_ON_F, [hl]
jr .done
.danger
ld hl, wLowHealthAlarm
set DANGER_ON_F, [hl]
.done
ret
```
TODO: Explain changes.
With this short edit, the noise will stop after just four beeps. It plays when your HP first turns red, and when you send out a Pokémon with low HP.
|