Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/audio/low_health_alarm.asm
1270 views
1
Music_DoLowHealthAlarm::
2
ld a, [wLowHealthAlarm]
3
cp DISABLE_LOW_HEALTH_ALARM
4
jr z, .disableAlarm
5
6
bit BIT_LOW_HEALTH_ALARM, a
7
ret z
8
9
and LOW_HEALTH_TIMER_MASK
10
jr nz, .notToneHi ;if timer > 0, play low tone.
11
12
call .playToneHi
13
ld a, 30 ;keep this tone for 30 frames.
14
jr .resetTimer
15
16
.notToneHi
17
cp 20
18
jr nz, .noTone ;if timer == 20,
19
call .playToneLo ;actually set the sound registers.
20
21
.noTone
22
ld a, CRY_SFX_END
23
ld [wChannelSoundIDs + CHAN5], a ;disable sound channel?
24
ld a, [wLowHealthAlarm]
25
and LOW_HEALTH_TIMER_MASK
26
dec a
27
28
.resetTimer
29
; reset the timer and enable flag.
30
set BIT_LOW_HEALTH_ALARM, a
31
ld [wLowHealthAlarm], a
32
ret
33
34
.disableAlarm
35
xor a
36
ld [wLowHealthAlarm], a ;disable alarm
37
ld [wChannelSoundIDs + CHAN5], a ;re-enable sound channel?
38
ld de, .toneDataSilence
39
jr .playTone
40
41
;update the sound registers to change the frequency.
42
;the tone set here stays until we change it.
43
.playToneHi
44
ld de, .toneDataHi
45
jr .playTone
46
47
.playToneLo
48
ld de, .toneDataLo
49
50
;update sound channel 1 to play the alarm, overriding all other sounds.
51
.playTone
52
ld hl, rAUD1SWEEP ;channel 1 sound register
53
ld c, $5
54
xor a
55
56
.copyLoop
57
ld [hli], a
58
ld a, [de]
59
inc de
60
dec c
61
jr nz, .copyLoop
62
ret
63
64
MACRO alarm_tone
65
db \1 ; length
66
db \2 ; envelope
67
dw \3 ; frequency
68
ENDM
69
70
;bytes to write to sound channel 1 registers for health alarm.
71
;starting at FF11 (FF10 is always zeroed).
72
.toneDataHi
73
alarm_tone $A0, $E2, $8750
74
75
.toneDataLo
76
alarm_tone $B0, $E2, $86EE
77
78
;written to stop the alarm
79
.toneDataSilence
80
alarm_tone $00, $00, $8000
81
82