summaryrefslogtreecommitdiff
path: root/audio.asm
diff options
context:
space:
mode:
Diffstat (limited to 'audio.asm')
-rw-r--r--audio.asm91
1 files changed, 54 insertions, 37 deletions
diff --git a/audio.asm b/audio.asm
index 2f161426..8b2ee0e3 100644
--- a/audio.asm
+++ b/audio.asm
@@ -365,7 +365,7 @@ SECTION "Audio Engine 1", ROMX, BANK[AUDIO_1]
PlayBattleMusic:: ; 0x90c6
xor a
ld [wMusicHeaderPointer], a
- ld [wd083], a
+ ld [wLowHealthAlarm], a
dec a
ld [wc0ee], a
call PlaySound ; stop music
@@ -455,63 +455,80 @@ Music_Cities1AlternateTempo:: ; 0x9b81
SECTION "Audio Engine 2", ROMX, BANK[AUDIO_2]
-Func_2136e:: ; 2136e (8:536e)
- ld a, [wd083]
+Music_DoLowHealthAlarm:: ; 2136e (8:536e)
+ ld a, [wLowHealthAlarm]
cp $ff
- jr z, .asm_2139b
- bit 7, a
- ret z
- and $7f
- jr nz, .asm_21383
- call Func_213a7
- ld a, $1e
- jr .asm_21395
+ jr z, .disableAlarm
+
+ bit 7, a ;alarm enabled?
+ ret z ;nope
+
+ and $7f ;low 7 bits are the timer.
+ jr nz, .asm_21383 ;if timer > 0, play low tone.
+
+ call .playToneHi
+ ld a, 30 ;keep this tone for 30 frames.
+ jr .asm_21395 ;reset the timer.
+
.asm_21383
- cp $14
- jr nz, .asm_2138a
- call Func_213ac
+ cp 20
+ jr nz, .asm_2138a ;if timer == 20,
+ call .playToneLo ;actually set the sound registers.
+
.asm_2138a
ld a, $86
- ld [wc02a], a
- ld a, [wd083]
- and $7f
+ ld [wc02a], a ;disable sound channel?
+ ld a, [wLowHealthAlarm]
+ and $7f ;decrement alarm timer.
dec a
+
.asm_21395
+ ; reset the timer and enable flag.
set 7, a
- ld [wd083], a
+ ld [wLowHealthAlarm], a
ret
-.asm_2139b
+
+.disableAlarm
xor a
- ld [wd083], a
- ld [wc02a], a
- ld de, Unknown_213c4 ; $53c4
- jr asm_213af
-
-Func_213a7: ; 213a7 (8:53a7)
- ld de, Unknown_213bc ; $53bc
- jr asm_213af
-
-Func_213ac: ; 213ac (8:53ac)
- ld de, Unknown_213c0 ; $53c0
-asm_213af: ; 213af (8:53af)
- ld hl, $ff10
+ ld [wLowHealthAlarm], a ;disable alarm
+ ld [wc02a], a ;re-enable sound channel?
+ ld de, .toneDataSilence
+ jr .playTone
+
+;update the sound registers to change the frequency.
+;the tone set here stays until we change it.
+.playToneHi
+ ld de, .toneDataHi
+ jr .playTone
+
+.playToneLo
+ ld de, .toneDataLo
+
+;update sound channel 1 to play the alarm, overriding all other sounds.
+.playTone
+ ld hl, rNR10 ;channel 1 sound register
ld c, $5
xor a
-.asm_213b5
+
+.copyLoop
ld [hli], a
ld a, [de]
inc de
dec c
- jr nz, .asm_213b5
+ jr nz, .copyLoop
ret
-Unknown_213bc: ; 213bc (8:53bc)
+;bytes to write to sound channel 1 registers for health alarm.
+;starting at FF11 (FF10 is always zeroed), so these bytes are:
+;length, envelope, freq lo, freq hi
+.toneDataHi
db $A0,$E2,$50,$87
-Unknown_213c0: ; 213c0 (8:53c0)
+.toneDataLo
db $B0,$E2,$EE,$86
-Unknown_213c4: ; 213c4 (8:53c4)
+;written to stop the alarm
+.toneDataSilence
db $00,$00,$00,$80