Clean up PlayDanger

This commit is contained in:
mid-kid 2018-06-04 14:34:35 +02:00
parent e8f847b537
commit 38ede6d7f0

View File

@ -539,47 +539,57 @@ PlayDanger: ; e8307
ld a, [wLowHealthAlarm] ld a, [wLowHealthAlarm]
bit DANGER_ON_F, a bit DANGER_ON_F, a
ret z ret z
; Don't do anything if SFX is being played
and $ff ^ (1 << DANGER_ON_F) and $ff ^ (1 << DANGER_ON_F)
ld d, a ld d, a
call _CheckSFX call _CheckSFX
jr c, .asm_e8335 jr c, .increment
; Play the high tone
and a and a
jr z, .asm_e8323 jr z, .begin
cp 16 ; halfway
jr z, .asm_e831e
jr .asm_e8335
.asm_e831e ; Play the low tone
ld hl, Tablee8354 cp 16
jr .updatehw jr z, .halfway
.asm_e8323 jr .increment
ld hl, Tablee8350
.updatehw .halfway
ld hl, DangerSoundLow
jr .applychannel
.begin
ld hl, DangetSoundHigh
.applychannel
xor a xor a
ld [rNR10], a ; sweep off ld [rNR10], a
ld a, [hli] ld a, [hli]
ld [rNR11], a ; sound length / duty cycle ld [rNR11], a
ld a, [hli] ld a, [hli]
ld [rNR12], a ; ch1 volume envelope ld [rNR12], a
ld a, [hli] ld a, [hli]
ld [rNR13], a ; ch1 frequency lo ld [rNR13], a
ld a, [hli] ld a, [hli]
ld [rNR14], a ; ch1 frequency hi ld [rNR14], a
.asm_e8335
.increment
ld a, d ld a, d
inc a inc a
cp 30 cp 30 ; Ending frame
jr c, .asm_e833c jr c, .noreset
xor a xor a
.asm_e833c .noreset
; Make sure the danger sound is kept on
or 1 << DANGER_ON_F or 1 << DANGER_ON_F
ld [wLowHealthAlarm], a ld [wLowHealthAlarm], a
; is hw ch1 on?
; Enable channel 1 if it's off
ld a, [wSoundOutput] ld a, [wSoundOutput]
and $11 and $11
ret nz ret nz
; if not, turn it on
ld a, [wSoundOutput] ld a, [wSoundOutput]
or $11 or $11
ld [wSoundOutput], a ld [wSoundOutput], a
@ -587,14 +597,14 @@ PlayDanger: ; e8307
; e8350 ; e8350
Tablee8350: ; e8350 DangetSoundHigh: ; e8350
db $80 ; duty 50% db $80 ; duty 50%
db $e2 ; volume 14, envelope decrease sweep 2 db $e2 ; volume 14, envelope decrease sweep 2
db $50 ; frequency: $750 db $50 ; frequency: $750
db $87 ; restart sound db $87 ; restart sound
; e8354 ; e8354
Tablee8354: ; e8354 DangerSoundLow: ; e8354
db $80 ; duty 50% db $80 ; duty 50%
db $e2 ; volume 14, envelope decrease sweep 2 db $e2 ; volume 14, envelope decrease sweep 2
db $ee ; frequency: $6ee db $ee ; frequency: $6ee