2014-01-07 03:34:14 +00:00
|
|
|
; The first of three duplicated sound engines.
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_UpdateMusic::
|
2019-07-28 04:21:39 +00:00
|
|
|
ld c, Ch1
|
2014-01-07 03:34:14 +00:00
|
|
|
.loop
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelSoundIDs
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .nextChannel
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .applyAffects ; if sfx channel
|
|
|
|
ld a, [wMuteAudioAndPauseMusic]
|
2014-01-07 03:34:14 +00:00
|
|
|
and a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .applyAffects
|
2014-01-07 03:34:14 +00:00
|
|
|
bit 7, a
|
|
|
|
jr nz, .nextChannel
|
|
|
|
set 7, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wMuteAudioAndPauseMusic], a
|
|
|
|
xor a ; disable all channels' output
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR51], a
|
|
|
|
ldh [rNR30], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $80
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR30], a
|
2014-01-07 03:34:14 +00:00
|
|
|
jr .nextChannel
|
2015-08-09 05:32:44 +00:00
|
|
|
.applyAffects
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_ApplyMusicAffects
|
2014-01-07 03:34:14 +00:00
|
|
|
.nextChannel
|
|
|
|
ld a, c
|
|
|
|
inc c ; inc channel number
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch8
|
2014-06-09 20:58:02 +00:00
|
|
|
jr nz, .loop
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; this routine checks flags for music effects currently applied
|
|
|
|
; to the channel and calls certain functions based on flags.
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_ApplyMusicAffects:
|
2014-01-07 03:34:14 +00:00
|
|
|
ld b, $0
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteDelayCounters ; delay until next note
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-07-16 17:25:02 +00:00
|
|
|
cp 1 ; if the delay is 1, play next note
|
2015-07-22 15:22:46 +00:00
|
|
|
jp z, Audio1_PlayNextNote
|
2014-01-07 03:34:14 +00:00
|
|
|
dec a ; otherwise, decrease the delay timer
|
|
|
|
ld [hl], a
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
jr nc, .startChecks ; if a sfx channel
|
2019-07-28 04:21:39 +00:00
|
|
|
ld hl, wChannelSoundIDs + Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .startChecks
|
|
|
|
ret
|
|
|
|
.startChecks
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
bit BIT_ROTATE_DUTY_CYCLE, [hl]
|
2014-01-07 03:34:14 +00:00
|
|
|
jr z, .checkForExecuteMusic
|
2019-08-17 19:40:34 +00:00
|
|
|
call Audio1_ApplyDutyCyclePattern
|
2014-01-07 03:34:14 +00:00
|
|
|
.checkForExecuteMusic
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags2
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
bit BIT_EXECUTE_MUSIC, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, .checkForPitchSlide
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
bit BIT_NOISE_OR_SFX, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, .skipPitchSlideVibrato
|
|
|
|
.checkForPitchSlide
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
bit BIT_PITCH_SLIDE_ON, [hl]
|
2014-01-07 03:34:14 +00:00
|
|
|
jr z, .checkVibratoDelay
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_ApplyPitchSlide
|
2014-01-07 03:34:14 +00:00
|
|
|
.checkVibratoDelay
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoDelayCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a ; check if delay is over
|
|
|
|
jr z, .checkForVibrato
|
|
|
|
dec [hl] ; otherwise, dec delay
|
2019-08-17 19:40:34 +00:00
|
|
|
.skipPitchSlideVibrato
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
.checkForVibrato
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoExtents
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr nz, .vibrato
|
|
|
|
ret ; no vibrato
|
|
|
|
.vibrato
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoRates
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and $f
|
|
|
|
and a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .applyVibrato
|
|
|
|
dec [hl] ; decrement counter
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
2015-08-09 05:32:44 +00:00
|
|
|
.applyVibrato
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, [hl]
|
|
|
|
swap [hl]
|
|
|
|
or [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a ; reload the counter
|
|
|
|
ld hl, wChannelFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl] ; get note pitch
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
; This is the only code that sets/resets the vibrato direction bit, so it
|
|
|
|
; continuously alternates which path it takes.
|
|
|
|
bit BIT_VIBRATO_DIRECTION, [hl]
|
|
|
|
jr z, .unset
|
|
|
|
res BIT_VIBRATO_DIRECTION, [hl]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $f
|
|
|
|
ld d, a
|
|
|
|
ld a, e
|
|
|
|
sub d
|
|
|
|
jr nc, .noCarry
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
.noCarry
|
|
|
|
jr .done
|
|
|
|
.unset
|
2015-08-09 05:32:44 +00:00
|
|
|
set BIT_VIBRATO_DIRECTION, [hl]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $f0
|
|
|
|
swap a
|
|
|
|
add e
|
|
|
|
jr nc, .done
|
|
|
|
ld a, $ff
|
|
|
|
.done
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, REG_FREQUENCY_LO
|
|
|
|
call Audio1_GetRegisterPointer
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], d
|
|
|
|
ret
|
|
|
|
|
|
|
|
; this routine executes all music commands that take up no time,
|
2019-08-17 19:40:34 +00:00
|
|
|
; like tempo changes, duty cycle changes etc. and doesn't return
|
2014-01-07 03:34:14 +00:00
|
|
|
; until the first note is reached
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_PlayNextNote:
|
2015-08-09 05:32:44 +00:00
|
|
|
; reload the vibrato delay counter
|
|
|
|
ld hl, wChannelVibratoDelayCounterReloadValues
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoDelayCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
|
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
res BIT_PITCH_SLIDE_ON, [hl]
|
|
|
|
res BIT_PITCH_SLIDE_DECREASING, [hl]
|
|
|
|
call Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_sound_ret:
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2020-07-16 17:25:02 +00:00
|
|
|
cp sound_ret_cmd
|
|
|
|
jp nz, Audio1_sound_call
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
bit BIT_SOUND_CALL, [hl]
|
2014-01-07 03:34:14 +00:00
|
|
|
jr nz, .returnFromCall
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch4
|
2014-01-07 03:34:14 +00:00
|
|
|
jr nc, .noiseOrSfxChannel
|
2015-08-09 05:32:44 +00:00
|
|
|
jr .disableChannelOutput
|
2014-01-07 03:34:14 +00:00
|
|
|
.noiseOrSfxChannel
|
2015-08-09 05:32:44 +00:00
|
|
|
res BIT_NOISE_OR_SFX, [hl]
|
|
|
|
ld hl, wChannelFlags2
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
res BIT_EXECUTE_MUSIC, [hl]
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch7
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nz, .skipSfxChannel3
|
|
|
|
; restart hardware channel 3 (wave channel) output
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $0
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR30], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $80
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR30], a
|
2015-08-09 05:32:44 +00:00
|
|
|
.skipSfxChannel3
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, .dontDisable
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wDisableChannelOutputWhenSfxEnds]
|
2014-01-07 03:34:14 +00:00
|
|
|
and a
|
2019-08-17 19:40:34 +00:00
|
|
|
jr z, .dontDisable
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wDisableChannelOutputWhenSfxEnds], a
|
|
|
|
jr .disableChannelOutput
|
2019-08-17 19:40:34 +00:00
|
|
|
.dontDisable
|
|
|
|
jr .afterDisable
|
2014-01-07 03:34:14 +00:00
|
|
|
.returnFromCall
|
|
|
|
res 1, [hl]
|
|
|
|
ld d, $0
|
|
|
|
ld a, c
|
|
|
|
add a
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelCommandPointers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
push hl ; store current channel address
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelReturnAddresses
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld e, l
|
|
|
|
ld d, h
|
|
|
|
pop hl
|
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
|
|
|
inc de
|
|
|
|
ld a, [de]
|
|
|
|
ld [hl], a ; loads channel address to return to
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2015-08-09 05:32:44 +00:00
|
|
|
.disableChannelOutput
|
|
|
|
ld hl, Audio1_HWChannelDisableMasks
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [rNR51]
|
2014-01-07 03:34:14 +00:00
|
|
|
and [hl]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR51], a
|
2019-08-17 19:40:34 +00:00
|
|
|
.afterDisable
|
2019-07-28 04:21:39 +00:00
|
|
|
ld a, [wChannelSoundIDs + Ch5]
|
2015-08-09 05:32:44 +00:00
|
|
|
cp CRY_SFX_START
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nc, .maybeCry
|
2015-08-09 05:32:44 +00:00
|
|
|
jr .skipCry
|
2019-08-17 19:40:34 +00:00
|
|
|
.maybeCry
|
2019-07-28 04:21:39 +00:00
|
|
|
ld a, [wChannelSoundIDs + Ch5]
|
2015-08-09 05:32:44 +00:00
|
|
|
cp CRY_SFX_END
|
|
|
|
jr z, .skipCry
|
|
|
|
jr c, .cry
|
|
|
|
jr .skipCry
|
|
|
|
.cry
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2019-08-17 19:40:34 +00:00
|
|
|
jr z, .skipRewind
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GoBackOneCommandIfCry
|
2014-01-07 03:34:14 +00:00
|
|
|
ret c
|
2019-08-17 19:40:34 +00:00
|
|
|
.skipRewind
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSavedVolume]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR50], a
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSavedVolume], a
|
|
|
|
.skipCry
|
|
|
|
ld hl, wChannelSoundIDs
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], b
|
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_sound_call:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp sound_call_cmd
|
|
|
|
jp nz, Audio1_sound_loop
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
push af
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
|
|
|
pop af
|
|
|
|
ld e, a
|
|
|
|
push de ; store pointer
|
|
|
|
ld d, $0
|
|
|
|
ld a, c
|
|
|
|
add a
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelCommandPointers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
push hl
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelReturnAddresses
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld e, l
|
|
|
|
ld d, h
|
|
|
|
pop hl
|
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
ld a, [hld]
|
|
|
|
ld [de], a ; copy current channel address
|
|
|
|
pop de
|
|
|
|
ld [hl], e
|
|
|
|
inc hl
|
|
|
|
ld [hl], d ; overwrite current address with pointer
|
|
|
|
ld b, $0
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
set BIT_SOUND_CALL, [hl] ; set the call flag
|
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_sound_loop:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp sound_loop_cmd
|
|
|
|
jp nz, Audio1_note_type
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, a
|
|
|
|
and a
|
|
|
|
jr z, .infiniteLoop
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelLoopCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
cp e
|
|
|
|
jr nz, .loopAgain
|
|
|
|
ld a, $1 ; if no more loops to make,
|
|
|
|
ld [hl], a
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte ; skip pointer
|
|
|
|
call Audio1_GetNextMusicByte
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
.loopAgain ; inc loop count
|
|
|
|
inc a
|
|
|
|
ld [hl], a
|
|
|
|
; fall through
|
|
|
|
.infiniteLoop ; overwrite current address with pointer
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
push af
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld b, a
|
|
|
|
ld d, $0
|
|
|
|
ld a, c
|
|
|
|
add a
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelCommandPointers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
pop af
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], b
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_note_type:
|
2014-01-07 03:34:14 +00:00
|
|
|
and $f0
|
2020-07-16 17:25:02 +00:00
|
|
|
cp note_type_cmd
|
|
|
|
jp nz, Audio1_toggle_perfect_pitch
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, d
|
2014-01-07 03:34:14 +00:00
|
|
|
and $f
|
|
|
|
ld b, $0
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteSpeeds
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a ; store low nibble as speed
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch4
|
2014-01-07 03:34:14 +00:00
|
|
|
jr z, .noiseChannel ; noise channel has 0 params
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch3
|
2014-01-07 03:34:14 +00:00
|
|
|
jr z, .musicChannel3
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch7
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nz, .skipChannel3
|
|
|
|
ld hl, wSfxWaveInstrument
|
|
|
|
jr .channel3
|
2014-01-07 03:34:14 +00:00
|
|
|
.musicChannel3
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wMusicWaveInstrument
|
|
|
|
.channel3
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $f
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a ; store low nibble of param as wave instrument
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $30
|
|
|
|
sla a
|
|
|
|
ld d, a
|
|
|
|
; fall through
|
|
|
|
|
|
|
|
; if channel 3, store high nibble as volume
|
|
|
|
; else, store volume (high nibble) and fade (low nibble)
|
2015-08-09 05:32:44 +00:00
|
|
|
.skipChannel3
|
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelVolumes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], d
|
|
|
|
.noiseChannel
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_toggle_perfect_pitch:
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
2020-07-16 17:25:02 +00:00
|
|
|
cp toggle_perfect_pitch_cmd
|
|
|
|
jr nz, Audio1_vibrato
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
xor $1
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a ; flip bit 0 of wChannelFlags1
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_vibrato:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp vibrato_cmd
|
|
|
|
jr nz, Audio1_pitch_slide
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelVibratoDelayCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2014-06-09 20:58:02 +00:00
|
|
|
ld [hl], a ; store delay
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoDelayCounterReloadValues
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a ; store delay
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
|
|
|
|
; The high nybble of the command byte is the extent of the vibrato.
|
|
|
|
; Let n be the extent.
|
|
|
|
; The upper nybble of the channel's byte in the wChannelVibratoExtents
|
|
|
|
; array will store the extent above the note: (n / 2) + (n % 2).
|
|
|
|
; The lower nybble will store the extent below the note: (n / 2).
|
|
|
|
; These two values add to the total extent, n.
|
2014-01-07 03:34:14 +00:00
|
|
|
and $f0
|
|
|
|
swap a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelVibratoExtents
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
srl a
|
|
|
|
ld e, a
|
|
|
|
adc b
|
|
|
|
swap a
|
|
|
|
or e
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a
|
|
|
|
|
|
|
|
; The low nybble of the command byte is the rate of the vibrato.
|
|
|
|
; The high and low nybbles of the channel's byte in the wChannelVibratoRates
|
|
|
|
; array are both initialised to this value because the high nybble is the
|
|
|
|
; counter reload value and the low nybble is the counter itself, which should
|
|
|
|
; start at its value upon reload.
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $f
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoRates
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
swap a
|
|
|
|
or d
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_pitch_slide:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp pitch_slide_cmd
|
|
|
|
jr nz, Audio1_duty_cycle
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
|
|
|
ld b, 0
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideLengthModifiers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
|
|
|
and $f0
|
|
|
|
swap a
|
|
|
|
ld b, a
|
|
|
|
ld a, d
|
|
|
|
and $f
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_CalculateFrequency
|
|
|
|
ld b, 0
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], d
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], e
|
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
set BIT_PITCH_SLIDE_ON, [hl]
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_note_length
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_duty_cycle:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp duty_cycle_cmd
|
|
|
|
jr nz, Audio1_tempo
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
rrca
|
|
|
|
rrca
|
|
|
|
and $c0
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCycles
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
ld [hl], a ; store duty cycle
|
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_tempo:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp tempo_cmd
|
|
|
|
jr nz, Audio1_stereo_panning
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
jr nc, .sfxChannel
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wMusicTempo], a ; store first param
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wMusicTempo + 1], a ; store second param
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wChannelNoteDelayCountersFractionalPart], a ; clear RAM
|
|
|
|
ld [wChannelNoteDelayCountersFractionalPart + 1], a
|
|
|
|
ld [wChannelNoteDelayCountersFractionalPart + 2], a
|
|
|
|
ld [wChannelNoteDelayCountersFractionalPart + 3], a
|
2014-01-07 03:34:14 +00:00
|
|
|
jr .musicChannelDone
|
|
|
|
.sfxChannel
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSfxTempo], a ; store first param
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSfxTempo + 1], a ; store second param
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wChannelNoteDelayCountersFractionalPart + 4], a ; clear RAM
|
|
|
|
ld [wChannelNoteDelayCountersFractionalPart + 5], a
|
|
|
|
ld [wChannelNoteDelayCountersFractionalPart + 6], a
|
|
|
|
ld [wChannelNoteDelayCountersFractionalPart + 7], a
|
2014-01-07 03:34:14 +00:00
|
|
|
.musicChannelDone
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_stereo_panning:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp stereo_panning_cmd
|
|
|
|
jr nz, Audio1_unknownmusic0xef
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
|
|
|
ld [wStereoPanning], a ; store panning
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
|
|
|
; this appears to never be used
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_unknownmusic0xef:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp unknownmusic0xef_cmd
|
|
|
|
jr nz, Audio1_duty_cycle_pattern
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
push bc
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_PlaySound
|
2014-01-07 03:34:14 +00:00
|
|
|
pop bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wDisableChannelOutputWhenSfxEnds]
|
2014-01-07 03:34:14 +00:00
|
|
|
and a
|
|
|
|
jr nz, .skip
|
2019-07-28 04:21:39 +00:00
|
|
|
ld a, [wChannelSoundIDs + Ch8]
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wDisableChannelOutputWhenSfxEnds], a
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2019-07-28 04:21:39 +00:00
|
|
|
ld [wChannelSoundIDs + Ch8], a
|
2014-01-07 03:34:14 +00:00
|
|
|
.skip
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_duty_cycle_pattern:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp duty_cycle_pattern_cmd
|
|
|
|
jr nz, Audio1_volume
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
|
|
|
ld b, 0
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCyclePatterns
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
ld [hl], a ; store full pattern
|
|
|
|
and %11000000
|
|
|
|
ld hl, wChannelDutyCycles
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
ld [hl], a ; store first duty cycle
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
set BIT_ROTATE_DUTY_CYCLE, [hl]
|
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_volume:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp volume_cmd
|
|
|
|
jr nz, Audio1_execute_music
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR50], a ; store volume
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_execute_music:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp execute_music_cmd
|
|
|
|
jr nz, Audio1_octave
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, $0
|
|
|
|
ld hl, wChannelFlags2
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
set BIT_EXECUTE_MUSIC, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_octave:
|
2014-01-07 03:34:14 +00:00
|
|
|
and $f0
|
2020-07-16 17:25:02 +00:00
|
|
|
cp octave_cmd
|
|
|
|
jr nz, Audio1_sfx_note
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelOctaves
|
|
|
|
ld b, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, d
|
|
|
|
and $f
|
|
|
|
ld [hl], a ; store low nibble as octave
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
; sfx_note is either square_note or noise_note depending on the channel
|
|
|
|
Audio1_sfx_note:
|
2020-07-16 17:25:02 +00:00
|
|
|
cp sfx_note_cmd
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, Audio1_pitch_sweep
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch4 ; is this a noise or sfx channel?
|
2019-08-17 19:40:34 +00:00
|
|
|
jr c, Audio1_pitch_sweep ; no
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags2
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
bit BIT_EXECUTE_MUSIC, [hl] ; is execute_music being used?
|
|
|
|
jr nz, Audio1_pitch_sweep ; yes
|
|
|
|
call Audio1_note_length
|
2015-08-09 05:32:44 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
; This code seems to do the same thing as what Audio1_ApplyDutyCycleAndSoundLength
|
2015-08-09 05:32:44 +00:00
|
|
|
; does below.
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCycles
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
or d
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, REG_DUTY_SOUND_LEN
|
|
|
|
call Audio1_GetRegisterPointer
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], d
|
2015-08-09 05:32:44 +00:00
|
|
|
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, REG_VOLUME_ENVELOPE
|
|
|
|
call Audio1_GetRegisterPointer
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], d
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, a
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch8
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, 0
|
|
|
|
jr z, .skip
|
|
|
|
; Channels 1 through 3 have 2 registers that control frequency, but the noise
|
|
|
|
; channel a single register (the polynomial counter) that controls frequency,
|
|
|
|
; so this command has one less byte on the noise channel.
|
2014-01-07 03:34:14 +00:00
|
|
|
push de
|
2015-07-22 15:22:46 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2014-01-07 03:34:14 +00:00
|
|
|
pop de
|
2015-08-09 05:32:44 +00:00
|
|
|
.skip
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
|
|
|
push de
|
2019-08-17 19:40:34 +00:00
|
|
|
call Audio1_ApplyDutyCycleAndSoundLength
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_EnableChannelOutput
|
2014-01-07 03:34:14 +00:00
|
|
|
pop de
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_ApplyWavePatternAndFrequency
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_pitch_sweep:
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2015-07-22 15:22:46 +00:00
|
|
|
jr c, Audio1_note ; if not a sfx
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
2020-07-16 17:25:02 +00:00
|
|
|
cp pitch_sweep_cmd
|
|
|
|
jr nz, Audio1_note
|
2014-01-07 03:34:14 +00:00
|
|
|
ld b, $0
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags2
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
bit BIT_EXECUTE_MUSIC, [hl]
|
2015-07-22 15:22:46 +00:00
|
|
|
jr nz, Audio1_note ; no
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_GetNextMusicByte
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR10], a
|
2019-08-17 19:40:34 +00:00
|
|
|
jp Audio1_sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2015-07-22 15:22:46 +00:00
|
|
|
Audio1_note:
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch4
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, Audio1_note_length ; if not noise channel
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $f0
|
2020-07-16 17:25:02 +00:00
|
|
|
cp drum_note_cmd
|
2019-09-04 03:36:02 +00:00
|
|
|
jr z, .drum_note
|
2020-07-16 17:25:02 +00:00
|
|
|
jr nc, Audio1_note_length
|
2019-08-17 19:40:34 +00:00
|
|
|
|
|
|
|
; this executes when on the noise channel and
|
2020-07-16 17:25:02 +00:00
|
|
|
; the command id is less than drum_note_cmd ($b0)
|
2019-08-17 19:40:34 +00:00
|
|
|
; in this case, the upper nybble is used as the noise instrument ($1-$a)
|
|
|
|
; and the lower nybble is the length minus 1 (0-15)
|
|
|
|
; however, this doesn't work for instrument #2 because the command id
|
|
|
|
; is captured by the noise_note command (command id $2x)
|
2019-09-04 03:36:02 +00:00
|
|
|
; this essentially acts like a drum_note command that is only 1 byte
|
2019-08-17 19:40:34 +00:00
|
|
|
; instead of 2 and can only be used with instruments 1 and 3 through 10
|
|
|
|
; this is unused by the game
|
2014-01-07 03:34:14 +00:00
|
|
|
swap a
|
|
|
|
ld b, a
|
|
|
|
ld a, d
|
|
|
|
and $f
|
|
|
|
ld d, a
|
|
|
|
ld a, b
|
|
|
|
push de
|
|
|
|
push bc
|
2019-08-17 19:40:34 +00:00
|
|
|
jr .playDnote
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2019-09-04 03:36:02 +00:00
|
|
|
.drum_note
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $f
|
|
|
|
push af
|
|
|
|
push bc
|
2019-09-04 03:36:02 +00:00
|
|
|
call Audio1_GetNextMusicByte ; get drum_note instrument
|
2019-08-17 19:40:34 +00:00
|
|
|
.playDnote
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wDisableChannelOutputWhenSfxEnds]
|
2014-01-07 03:34:14 +00:00
|
|
|
and a
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, .skipDnote
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_PlaySound
|
2019-08-17 19:40:34 +00:00
|
|
|
.skipDnote
|
2014-01-07 03:34:14 +00:00
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_note_length:
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
push af
|
|
|
|
and $f
|
|
|
|
inc a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, a ; store note length (in 16ths)
|
|
|
|
ld d, b
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteSpeeds
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
ld l, b
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_MultiplyAdd
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
jr nc, .sfxChannel
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wMusicTempo]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wMusicTempo + 1]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, a
|
|
|
|
jr .skip
|
|
|
|
.sfxChannel
|
|
|
|
ld d, $1
|
|
|
|
ld e, $0
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch8
|
2014-01-07 03:34:14 +00:00
|
|
|
jr z, .skip ; if noise channel
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_SetSfxTempo
|
|
|
|
ld a, [wSfxTempo]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSfxTempo + 1]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, a
|
|
|
|
.skip
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, l ; a = note_length * note_speed
|
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelNoteDelayCountersFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld l, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_MultiplyAdd
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, l
|
2015-08-09 05:32:44 +00:00
|
|
|
ld d, h ; de = note_delay_frac_part + (note_length * note_speed * tempo)
|
|
|
|
ld hl, wChannelNoteDelayCountersFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], e
|
|
|
|
ld a, d
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteDelayCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags2
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
bit BIT_EXECUTE_MUSIC, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, Audio1_note_pitch
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
bit BIT_NOISE_OR_SFX, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
jr z, Audio1_note_pitch
|
2014-01-07 03:34:14 +00:00
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_note_pitch:
|
2014-01-07 03:34:14 +00:00
|
|
|
pop af
|
|
|
|
and $f0
|
2020-07-16 17:25:02 +00:00
|
|
|
cp rest_cmd
|
2014-01-07 03:34:14 +00:00
|
|
|
jr nz, .notRest
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .next
|
|
|
|
; If this isn't an SFX channel, try the corresponding SFX channel.
|
2019-07-28 04:21:39 +00:00
|
|
|
ld hl, wChannelSoundIDs + Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr nz, .done
|
|
|
|
; fall through
|
2015-08-09 05:32:44 +00:00
|
|
|
.next
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch3
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .channel3
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch7
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nz, .notChannel3
|
|
|
|
.channel3
|
|
|
|
ld b, 0
|
|
|
|
ld hl, Audio1_HWChannelDisableMasks
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [rNR51]
|
2014-01-07 03:34:14 +00:00
|
|
|
and [hl]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR51], a ; disable hardware channel 3's output
|
2014-01-07 03:34:14 +00:00
|
|
|
jr .done
|
2015-08-09 05:32:44 +00:00
|
|
|
.notChannel3
|
|
|
|
ld b, REG_VOLUME_ENVELOPE
|
|
|
|
call Audio1_GetRegisterPointer
|
|
|
|
ld a, $8 ; fade in sound
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hli], a
|
|
|
|
inc hl
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, $80 ; restart sound
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], a
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
.notRest
|
|
|
|
swap a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelOctaves
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld b, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_CalculateFrequency
|
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags1
|
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
bit BIT_PITCH_SLIDE_ON, [hl]
|
|
|
|
jr z, .skipPitchSlide
|
|
|
|
call Audio1_InitPitchSlideVars
|
|
|
|
.skipPitchSlide
|
2014-01-07 03:34:14 +00:00
|
|
|
push de
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .sfxChannel ; if sfx channel
|
|
|
|
; If this isn't an SFX channel, try the corresponding SFX channel.
|
2019-07-28 04:21:39 +00:00
|
|
|
ld hl, wChannelSoundIDs + Ch5
|
2015-08-09 05:32:44 +00:00
|
|
|
ld d, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, a
|
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nz, .noSfx
|
|
|
|
jr .sfxChannel
|
|
|
|
.noSfx
|
2014-01-07 03:34:14 +00:00
|
|
|
pop de
|
|
|
|
ret
|
2015-08-09 05:32:44 +00:00
|
|
|
.sfxChannel
|
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelVolumes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, REG_VOLUME_ENVELOPE
|
|
|
|
call Audio1_GetRegisterPointer
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], d
|
2019-08-17 19:40:34 +00:00
|
|
|
call Audio1_ApplyDutyCycleAndSoundLength
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_EnableChannelOutput
|
2014-01-07 03:34:14 +00:00
|
|
|
pop de
|
|
|
|
ld b, $0
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
bit BIT_PERFECT_PITCH, [hl] ; has toggle_perfect_pitch been used?
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .skipFrequencyInc
|
|
|
|
inc e ; if yes, increment the frequency by 1
|
|
|
|
jr nc, .skipFrequencyInc
|
2014-01-07 03:34:14 +00:00
|
|
|
inc d
|
2015-08-09 05:32:44 +00:00
|
|
|
.skipFrequencyInc
|
|
|
|
ld hl, wChannelFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], e
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_ApplyWavePatternAndFrequency
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_EnableChannelOutput:
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, Audio1_HWChannelEnableMasks
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [rNR51]
|
2015-08-09 05:32:44 +00:00
|
|
|
or [hl] ; set this channel's bits
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch8
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .noiseChannelOrNoSfx
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
jr nc, .skip ; if sfx channel
|
2015-08-09 05:32:44 +00:00
|
|
|
; If this isn't an SFX channel, try the corresponding SFX channel.
|
2019-07-28 04:21:39 +00:00
|
|
|
ld hl, wChannelSoundIDs + Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr nz, .skip
|
2015-08-09 05:32:44 +00:00
|
|
|
.noiseChannelOrNoSfx
|
|
|
|
; If this is the SFX noise channel or a music channel whose corresponding
|
|
|
|
; SFX channel is off, apply stereo panning.
|
|
|
|
ld a, [wStereoPanning]
|
|
|
|
ld hl, Audio1_HWChannelEnableMasks
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
and [hl]
|
|
|
|
ld d, a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [rNR51]
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, Audio1_HWChannelDisableMasks
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
and [hl] ; reset this channel's output bits
|
|
|
|
or d ; set this channel's output bits that enabled in [wStereoPanning]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
|
|
|
.skip
|
|
|
|
ld a, d
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR51], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_ApplyDutyCycleAndSoundLength:
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelNoteDelayCounters ; use the note delay as sound length
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch3
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .skipDuty ; if music channel 3
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch7
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .skipDuty ; if sfx channel 3
|
2019-08-17 19:40:34 +00:00
|
|
|
; include duty cycle (except on channel 3 which doesn't have it)
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and $3f
|
|
|
|
ld d, a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCycles
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
or d
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
.skipDuty
|
|
|
|
ld b, REG_DUTY_SOUND_LEN
|
|
|
|
call Audio1_GetRegisterPointer
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], d
|
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_ApplyWavePatternAndFrequency:
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch3
|
2014-01-07 03:34:14 +00:00
|
|
|
jr z, .channel3
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch7
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nz, .notChannel3
|
2014-01-07 03:34:14 +00:00
|
|
|
; fall through
|
|
|
|
.channel3
|
|
|
|
push de
|
2015-08-09 05:32:44 +00:00
|
|
|
ld de, wMusicWaveInstrument
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch3
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .next
|
|
|
|
ld de, wSfxWaveInstrument
|
|
|
|
.next
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, [de]
|
|
|
|
add a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld d, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, a
|
2015-07-22 15:22:46 +00:00
|
|
|
ld hl, Audio1_WavePointers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
2020-07-04 02:11:35 +00:00
|
|
|
ld hl, rWave_0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld b, $f
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, $0 ; stop hardware channel 3
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR30], a
|
2014-01-07 03:34:14 +00:00
|
|
|
.loop
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hli], a
|
|
|
|
ld a, b
|
|
|
|
dec b
|
|
|
|
and a
|
|
|
|
jr nz, .loop
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, $80 ; start hardware channel 3
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR30], a
|
2014-01-07 03:34:14 +00:00
|
|
|
pop de
|
2015-08-09 05:32:44 +00:00
|
|
|
.notChannel3
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
2015-08-09 05:32:44 +00:00
|
|
|
or $80 ; use counter mode (i.e. disable output when the counter reaches 0)
|
|
|
|
and $c7 ; zero the unused bits in the register
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, REG_FREQUENCY_LO
|
|
|
|
call Audio1_GetRegisterPointer
|
|
|
|
ld [hl], e ; store frequency low byte
|
2014-01-07 03:34:14 +00:00
|
|
|
inc hl
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], d ; store frequency high byte
|
|
|
|
call Audio1_ApplyFrequencyModifier
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_SetSfxTempo:
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_IsCry
|
|
|
|
jr nc, .notCry
|
|
|
|
ld d, 0
|
|
|
|
ld a, [wTempoModifier]
|
2014-01-07 03:34:14 +00:00
|
|
|
add $80
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .next
|
2014-01-07 03:34:14 +00:00
|
|
|
inc d
|
2015-08-09 05:32:44 +00:00
|
|
|
.next
|
|
|
|
ld [wSfxTempo + 1], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSfxTempo], a
|
|
|
|
jr .done
|
|
|
|
.notCry
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSfxTempo + 1], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $1
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSfxTempo], a
|
|
|
|
.done
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_ApplyFrequencyModifier:
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_IsCry
|
|
|
|
jr nc, .done
|
|
|
|
; if playing a cry, add the cry's frequency modifier
|
|
|
|
ld a, [wFrequencyModifier]
|
2014-01-07 03:34:14 +00:00
|
|
|
add e
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .noCarry
|
2014-01-07 03:34:14 +00:00
|
|
|
inc d
|
2015-08-09 05:32:44 +00:00
|
|
|
.noCarry
|
2014-01-07 03:34:14 +00:00
|
|
|
dec hl
|
|
|
|
ld e, a
|
|
|
|
ld [hl], e
|
|
|
|
inc hl
|
|
|
|
ld [hl], d
|
2015-08-09 05:32:44 +00:00
|
|
|
.done
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_GoBackOneCommandIfCry:
|
2015-08-09 05:32:44 +00:00
|
|
|
call Audio1_IsCry
|
|
|
|
jr nc, .done
|
|
|
|
ld hl, wChannelCommandPointers
|
2014-01-07 03:34:14 +00:00
|
|
|
ld e, c
|
2015-08-09 05:32:44 +00:00
|
|
|
ld d, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
sla e
|
|
|
|
rl d
|
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
sub 1
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], a
|
|
|
|
inc hl
|
|
|
|
ld a, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
sbc 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], a
|
|
|
|
scf
|
|
|
|
ret
|
2015-08-09 05:32:44 +00:00
|
|
|
.done
|
2014-01-07 03:34:14 +00:00
|
|
|
scf
|
|
|
|
ccf
|
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_IsCry:
|
2015-08-09 05:32:44 +00:00
|
|
|
; Returns whether the currently playing audio is a cry in carry.
|
2019-07-28 04:21:39 +00:00
|
|
|
ld a, [wChannelSoundIDs + Ch5]
|
2015-08-09 05:32:44 +00:00
|
|
|
cp CRY_SFX_START
|
|
|
|
jr nc, .next
|
|
|
|
jr .no
|
|
|
|
.next
|
|
|
|
cp CRY_SFX_END
|
|
|
|
jr z, .no
|
|
|
|
jr c, .yes
|
|
|
|
.no
|
2014-01-07 03:34:14 +00:00
|
|
|
scf
|
|
|
|
ccf
|
|
|
|
ret
|
2015-08-09 05:32:44 +00:00
|
|
|
.yes
|
2014-01-07 03:34:14 +00:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_ApplyPitchSlide:
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
bit BIT_PITCH_SLIDE_DECREASING, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
jp nz, .frequencyDecreasing
|
|
|
|
; frequency increasing
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencySteps
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld l, [hl]
|
|
|
|
ld h, b
|
|
|
|
add hl, de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
push hl
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencyStepsFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
|
|
|
add [hl]
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
adc e
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
adc d
|
|
|
|
ld d, a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
cp d
|
2015-08-09 05:32:44 +00:00
|
|
|
jp c, .reachedTargetFrequency
|
|
|
|
jr nz, .applyUpdatedFrequency
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
cp e
|
2015-08-09 05:32:44 +00:00
|
|
|
jp c, .reachedTargetFrequency
|
|
|
|
jr .applyUpdatedFrequency
|
|
|
|
.frequencyDecreasing
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencySteps
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
|
|
|
sub e
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
|
|
|
sbc b
|
|
|
|
ld d, a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencyStepsFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
add a
|
|
|
|
ld [hl], a
|
|
|
|
ld a, e
|
|
|
|
sbc b
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
|
|
|
sbc b
|
|
|
|
ld d, a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, d
|
|
|
|
cp [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
jr c, .reachedTargetFrequency
|
|
|
|
jr nz, .applyUpdatedFrequency
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, e
|
|
|
|
cp [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
jr c, .reachedTargetFrequency
|
|
|
|
.applyUpdatedFrequency
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], e
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], d
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, REG_FREQUENCY_LO
|
|
|
|
call Audio1_GetRegisterPointer
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, e
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], d
|
|
|
|
ret
|
2015-08-09 05:32:44 +00:00
|
|
|
.reachedTargetFrequency
|
2019-08-17 19:40:34 +00:00
|
|
|
; Turn off pitch slide when the target frequency has been reached.
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
res BIT_PITCH_SLIDE_ON, [hl]
|
|
|
|
res BIT_PITCH_SLIDE_DECREASING, [hl]
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_InitPitchSlideVars:
|
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], d
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], e
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteDelayCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideLengthModifiers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
sub [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .next
|
|
|
|
ld a, 1
|
|
|
|
.next
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, e
|
|
|
|
sub [hl]
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
|
|
|
sbc b
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
sub [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
jr c, .targetFrequencyGreater
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
set BIT_PITCH_SLIDE_DECREASING, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
jr .next2
|
|
|
|
.targetFrequencyGreater
|
|
|
|
; If the target frequency is greater, subtract the current frequency from
|
|
|
|
; the target frequency to get the absolute difference.
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
sub e
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
|
|
|
|
; Bug. Instead of borrowing from the high byte of the target frequency as it
|
|
|
|
; should, it borrows from the high byte of the current frequency instead.
|
|
|
|
; This means that the result will be 0x200 greater than it should be if the
|
|
|
|
; low byte of the current frequency is greater than the low byte of the
|
|
|
|
; target frequency.
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
sbc b
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
sub d
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2019-08-17 19:40:34 +00:00
|
|
|
res BIT_PITCH_SLIDE_DECREASING, [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
|
|
|
|
.next2
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideLengthModifiers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
.divideLoop
|
2014-01-07 03:34:14 +00:00
|
|
|
inc b
|
|
|
|
ld a, e
|
|
|
|
sub [hl]
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .divideLoop
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, d
|
|
|
|
and a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .doneDividing
|
2014-01-07 03:34:14 +00:00
|
|
|
dec a
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr .divideLoop
|
|
|
|
.doneDividing
|
|
|
|
ld a, e ; a = remainder - dividend
|
2014-01-07 03:34:14 +00:00
|
|
|
add [hl]
|
2015-08-09 05:32:44 +00:00
|
|
|
ld d, b ; d = quotient + 1
|
|
|
|
ld b, 0
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencySteps
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], d ; store quotient + 1
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencyStepsFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a ; store remainder - dividend
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [hl], a ; store remainder - dividend
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_ApplyDutyCyclePattern:
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCyclePatterns
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
rlca
|
|
|
|
rlca
|
|
|
|
ld [hl], a
|
|
|
|
and $c0
|
|
|
|
ld d, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, REG_DUTY_SOUND_LEN
|
|
|
|
call Audio1_GetRegisterPointer
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, [hl]
|
|
|
|
and $3f
|
|
|
|
or d
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_GetNextMusicByte:
|
2015-08-09 05:32:44 +00:00
|
|
|
ld d, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
|
|
|
add a
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelCommandPointers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld a, [hli]
|
|
|
|
ld e, a
|
|
|
|
ld a, [hld]
|
|
|
|
ld d, a
|
|
|
|
ld a, [de] ; get next music command
|
|
|
|
inc de
|
|
|
|
ld [hl], e ; store address of next command
|
|
|
|
inc hl
|
|
|
|
ld [hl], d
|
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_GetRegisterPointer:
|
2015-08-09 05:32:44 +00:00
|
|
|
; hl = address of hardware sound register b for software channel c
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, Audio1_HWChannelBaseAddresses
|
2014-01-07 03:34:14 +00:00
|
|
|
add l
|
|
|
|
jr nc, .noCarry
|
|
|
|
inc h
|
|
|
|
.noCarry
|
|
|
|
ld l, a
|
|
|
|
ld a, [hl]
|
|
|
|
add b
|
|
|
|
ld l, a
|
|
|
|
ld h, $ff
|
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_MultiplyAdd:
|
2015-08-09 05:32:44 +00:00
|
|
|
; hl = l + (a * de)
|
|
|
|
ld h, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
.loop
|
|
|
|
srl a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nc, .skipAdd
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
2015-08-09 05:32:44 +00:00
|
|
|
.skipAdd
|
2014-01-07 03:34:14 +00:00
|
|
|
sla e
|
|
|
|
rl d
|
|
|
|
and a
|
|
|
|
jr z, .done
|
|
|
|
jr .loop
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_CalculateFrequency:
|
2015-08-09 05:32:44 +00:00
|
|
|
; return the frequency for note a, octave b in de
|
|
|
|
ld h, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld l, a
|
|
|
|
add hl, hl
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2015-07-22 15:22:46 +00:00
|
|
|
ld hl, Audio1_Pitches
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
|
|
|
ld a, b
|
|
|
|
.loop
|
2015-08-09 05:32:44 +00:00
|
|
|
cp 7
|
2014-01-07 03:34:14 +00:00
|
|
|
jr z, .done
|
|
|
|
sra d
|
|
|
|
rr e
|
|
|
|
inc a
|
|
|
|
jr .loop
|
|
|
|
.done
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, 8
|
2014-01-07 03:34:14 +00:00
|
|
|
add d
|
|
|
|
ld d, a
|
|
|
|
ret
|
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_PlaySound::
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSoundID], a
|
2020-07-16 17:25:02 +00:00
|
|
|
cp SFX_STOP_ALL_MUSIC
|
2015-08-09 05:32:44 +00:00
|
|
|
jp z, .stopAllAudio
|
2019-08-17 19:40:34 +00:00
|
|
|
cp MAX_SFX_ID_1
|
2015-08-09 05:32:44 +00:00
|
|
|
jp z, .playSfx
|
|
|
|
jp c, .playSfx
|
2014-01-07 03:34:14 +00:00
|
|
|
cp $fe
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .playMusic
|
|
|
|
jp nc, .playSfx
|
|
|
|
|
|
|
|
.playMusic
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wUnusedC000], a
|
|
|
|
ld [wDisableChannelOutputWhenSfxEnds], a
|
|
|
|
ld [wMusicTempo + 1], a
|
|
|
|
ld [wMusicWaveInstrument], a
|
|
|
|
ld [wSfxWaveInstrument], a
|
2020-07-14 14:21:18 +00:00
|
|
|
ld d, NUM_CHANNELS
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelReturnAddresses
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelCommandPointers
|
|
|
|
call .FillMem
|
2020-07-14 14:21:18 +00:00
|
|
|
ld d, NUM_MUSIC_CHANS
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelSoundIDs
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelFlags1
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelDutyCycles
|
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCyclePatterns
|
|
|
|
call .FillMem
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoDelayCounters
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelVibratoExtents
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelVibratoRates
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelFrequencyLowBytes
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelVibratoDelayCounterReloadValues
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelFlags2
|
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideLengthModifiers
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencySteps
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencyStepsFractionalPart
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyFractionalPart
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyHighBytes
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyLowBytes
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyHighBytes
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyLowBytes
|
2015-08-09 05:32:44 +00:00
|
|
|
call .FillMem
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $1
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelLoopCounters
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelNoteDelayCounters
|
|
|
|
call .FillMem
|
|
|
|
ld hl, wChannelNoteSpeeds
|
|
|
|
call .FillMem
|
|
|
|
ld [wMusicTempo], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $ff
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wStereoPanning], a
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR50], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $8
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR10], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, 0
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR51], a
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR30], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $80
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR30], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $77
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR50], a
|
2015-08-09 05:32:44 +00:00
|
|
|
jp .playSoundCommon
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2015-08-09 05:32:44 +00:00
|
|
|
.playSfx
|
2014-01-07 03:34:14 +00:00
|
|
|
ld l, a
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld h, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, h
|
|
|
|
add hl, hl
|
|
|
|
add hl, de
|
2015-07-22 15:22:46 +00:00
|
|
|
ld de, SFX_Headers_1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld a, h
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSfxHeaderPointer], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, l
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSfxHeaderPointer + 1], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, [hl]
|
|
|
|
and $c0
|
|
|
|
rlca
|
|
|
|
rlca
|
|
|
|
ld c, a
|
2015-08-09 05:32:44 +00:00
|
|
|
.sfxChannelLoop
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, c
|
|
|
|
ld a, c
|
|
|
|
add a
|
|
|
|
add c
|
|
|
|
ld c, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
|
|
|
ld a, [wSfxHeaderPointer]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld h, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSfxHeaderPointer + 1]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld l, a
|
|
|
|
add hl, bc
|
|
|
|
ld c, d
|
|
|
|
ld a, [hl]
|
|
|
|
and $f
|
2015-08-09 05:32:44 +00:00
|
|
|
ld e, a ; software channel ID
|
|
|
|
ld d, 0
|
|
|
|
ld hl, wChannelSoundIDs
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2019-08-17 19:40:34 +00:00
|
|
|
jr z, .playChannel
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, e
|
2019-08-17 19:40:34 +00:00
|
|
|
cp Ch8
|
|
|
|
jr nz, .notNoiseChannel
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSoundID]
|
2019-08-17 19:40:34 +00:00
|
|
|
cp NOISE_INSTRUMENTS_END
|
|
|
|
jr nc, .notNoiseInstrument
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
2019-08-17 19:40:34 +00:00
|
|
|
.notNoiseInstrument
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
cp NOISE_INSTRUMENTS_END
|
|
|
|
jr z, .playChannel
|
|
|
|
jr c, .playChannel
|
|
|
|
.notNoiseChannel
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSoundID]
|
2014-01-07 03:34:14 +00:00
|
|
|
cp [hl]
|
2019-08-17 19:40:34 +00:00
|
|
|
jr z, .playChannel
|
|
|
|
jr c, .playChannel
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
2019-08-17 19:40:34 +00:00
|
|
|
.playChannel
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
|
|
|
push de
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
add hl, hl
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelReturnAddresses
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelCommandPointers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], a
|
|
|
|
pop de
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelSoundIDs
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCycles
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelDutyCyclePatterns
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoDelayCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoExtents
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoRates
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelVibratoDelayCounterReloadValues
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideLengthModifiers
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencySteps
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideFrequencyStepsFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyFractionalPart
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideCurrentFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyHighBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2019-08-17 19:40:34 +00:00
|
|
|
ld hl, wChannelPitchSlideTargetFrequencyLowBytes
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelFlags2
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
|
|
|
ld a, $1
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelLoopCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteDelayCounters
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteSpeeds
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
|
|
|
ld a, e
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch5
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nz, .skipSweepDisable
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $8
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR10], a ; sweep off
|
2019-08-17 19:40:34 +00:00
|
|
|
.skipSweepDisable
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, c
|
|
|
|
and a
|
2015-08-09 05:32:44 +00:00
|
|
|
jp z, .playSoundCommon
|
2014-01-07 03:34:14 +00:00
|
|
|
dec c
|
2015-08-09 05:32:44 +00:00
|
|
|
jp .sfxChannelLoop
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2015-08-09 05:32:44 +00:00
|
|
|
.stopAllAudio
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $80
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR52], a ; sound hardware on
|
|
|
|
ldh [rNR30], a ; wave playback on
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR51], a ; no sound output
|
|
|
|
ldh [rNR32], a ; mute channel 3 (wave channel)
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $8
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR10], a ; sweep off
|
|
|
|
ldh [rNR12], a ; mute channel 1 (pulse channel 1)
|
|
|
|
ldh [rNR22], a ; mute channel 2 (pulse channel 2)
|
|
|
|
ldh [rNR42], a ; mute channel 4 (noise channel)
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $40
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR14], a ; counter mode
|
|
|
|
ldh [rNR24], a
|
|
|
|
ldh [rNR44], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $77
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR50], a ; full volume
|
2014-01-07 03:34:14 +00:00
|
|
|
xor a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wUnusedC000], a
|
|
|
|
ld [wDisableChannelOutputWhenSfxEnds], a
|
|
|
|
ld [wMuteAudioAndPauseMusic], a
|
|
|
|
ld [wMusicTempo + 1], a
|
|
|
|
ld [wSfxTempo + 1], a
|
|
|
|
ld [wMusicWaveInstrument], a
|
|
|
|
ld [wSfxWaveInstrument], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, $a0
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelCommandPointers
|
|
|
|
call .FillMem
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $1
|
|
|
|
ld d, $18
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelNoteDelayCounters
|
|
|
|
call .FillMem
|
|
|
|
ld [wMusicTempo], a
|
|
|
|
ld [wSfxTempo], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $ff
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wStereoPanning], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; fills d bytes at hl with a
|
2015-08-09 05:32:44 +00:00
|
|
|
.FillMem
|
2014-01-07 03:34:14 +00:00
|
|
|
ld b, d
|
|
|
|
.loop
|
|
|
|
ld [hli], a
|
|
|
|
dec b
|
|
|
|
jr nz, .loop
|
|
|
|
ret
|
|
|
|
|
2015-08-09 05:32:44 +00:00
|
|
|
.playSoundCommon
|
|
|
|
ld a, [wSoundID]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld l, a
|
|
|
|
ld e, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld h, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld d, h
|
|
|
|
add hl, hl
|
|
|
|
add hl, de
|
2015-07-22 15:22:46 +00:00
|
|
|
ld de, SFX_Headers_1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, de
|
|
|
|
ld e, l
|
|
|
|
ld d, h
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelCommandPointers
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, [de] ; get channel number
|
|
|
|
ld b, a
|
|
|
|
rlca
|
|
|
|
rlca
|
|
|
|
and $3
|
|
|
|
ld c, a
|
|
|
|
ld a, b
|
|
|
|
and $f
|
|
|
|
ld b, c
|
|
|
|
inc b
|
|
|
|
inc de
|
2015-08-09 05:32:44 +00:00
|
|
|
ld c, 0
|
|
|
|
.commandPointerLoop
|
2014-01-07 03:34:14 +00:00
|
|
|
cp c
|
2015-08-09 05:32:44 +00:00
|
|
|
jr z, .next
|
2014-01-07 03:34:14 +00:00
|
|
|
inc c
|
|
|
|
inc hl
|
|
|
|
inc hl
|
2015-08-09 05:32:44 +00:00
|
|
|
jr .commandPointerLoop
|
|
|
|
.next
|
2014-01-07 03:34:14 +00:00
|
|
|
push hl
|
|
|
|
push bc
|
|
|
|
push af
|
2015-08-09 05:32:44 +00:00
|
|
|
ld b, 0
|
2014-01-07 03:34:14 +00:00
|
|
|
ld c, a
|
2015-08-09 05:32:44 +00:00
|
|
|
ld hl, wChannelSoundIDs
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSoundID]
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], a
|
|
|
|
pop af
|
2019-07-28 04:21:39 +00:00
|
|
|
cp Ch4
|
2015-08-09 05:32:44 +00:00
|
|
|
jr c, .skipSettingFlag
|
|
|
|
ld hl, wChannelFlags1
|
2014-01-07 03:34:14 +00:00
|
|
|
add hl, bc
|
2015-08-09 05:32:44 +00:00
|
|
|
set BIT_NOISE_OR_SFX, [hl]
|
|
|
|
.skipSettingFlag
|
2014-01-07 03:34:14 +00:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ld a, [de] ; get channel pointer
|
|
|
|
ld [hli], a
|
|
|
|
inc de
|
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
|
|
|
inc de
|
|
|
|
inc c
|
|
|
|
dec b
|
|
|
|
ld a, b
|
|
|
|
and a
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nz, .commandPointerLoop
|
|
|
|
ld a, [wSoundID]
|
|
|
|
cp CRY_SFX_START
|
2019-08-17 19:40:34 +00:00
|
|
|
jr nc, .maybeCry
|
2015-08-09 05:32:44 +00:00
|
|
|
jr .done
|
2019-08-17 19:40:34 +00:00
|
|
|
.maybeCry
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSoundID]
|
|
|
|
cp CRY_SFX_END
|
|
|
|
jr z, .done
|
|
|
|
jr c, .cry
|
|
|
|
jr .done
|
|
|
|
.cry
|
2019-07-28 04:21:39 +00:00
|
|
|
ld hl, wChannelSoundIDs + Ch5
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hli], a
|
|
|
|
ld [hli], a
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], a
|
2019-07-28 04:21:39 +00:00
|
|
|
ld hl, wChannelCommandPointers + Ch7 * 2 ; sfx wave channel pointer
|
2019-08-17 19:40:34 +00:00
|
|
|
ld de, Audio1_CryRet
|
2014-01-07 03:34:14 +00:00
|
|
|
ld [hl], e
|
|
|
|
inc hl
|
2019-08-17 19:40:34 +00:00
|
|
|
ld [hl], d ; overwrite pointer to point to sound_ret
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wSavedVolume]
|
2014-01-07 03:34:14 +00:00
|
|
|
and a
|
2015-08-09 05:32:44 +00:00
|
|
|
jr nz, .done
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [rNR50]
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wSavedVolume], a
|
2014-01-07 03:34:14 +00:00
|
|
|
ld a, $77
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [rNR50], a ; full volume
|
2015-08-09 05:32:44 +00:00
|
|
|
.done
|
2014-01-07 03:34:14 +00:00
|
|
|
ret
|
|
|
|
|
2019-08-17 19:40:34 +00:00
|
|
|
Audio1_CryRet:
|
2019-07-28 04:21:39 +00:00
|
|
|
sound_ret
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_HWChannelBaseAddresses:
|
2015-08-09 05:32:44 +00:00
|
|
|
; the low bytes of each HW channel's base address
|
|
|
|
db HW_CH1_BASE, HW_CH2_BASE, HW_CH3_BASE, HW_CH4_BASE ; channels 0-3
|
|
|
|
db HW_CH1_BASE, HW_CH2_BASE, HW_CH3_BASE, HW_CH4_BASE ; channels 4-7
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_HWChannelDisableMasks:
|
2015-08-09 05:32:44 +00:00
|
|
|
db HW_CH1_DISABLE_MASK, HW_CH2_DISABLE_MASK, HW_CH3_DISABLE_MASK, HW_CH4_DISABLE_MASK ; channels 0-3
|
|
|
|
db HW_CH1_DISABLE_MASK, HW_CH2_DISABLE_MASK, HW_CH3_DISABLE_MASK, HW_CH4_DISABLE_MASK ; channels 4-7
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_HWChannelEnableMasks:
|
2015-08-09 05:32:44 +00:00
|
|
|
db HW_CH1_ENABLE_MASK, HW_CH2_ENABLE_MASK, HW_CH3_ENABLE_MASK, HW_CH4_ENABLE_MASK ; channels 0-3
|
|
|
|
db HW_CH1_ENABLE_MASK, HW_CH2_ENABLE_MASK, HW_CH3_ENABLE_MASK, HW_CH4_ENABLE_MASK ; channels 4-7
|
2014-01-07 03:34:14 +00:00
|
|
|
|
2016-06-12 07:19:19 +00:00
|
|
|
Audio1_Pitches:
|
2020-06-28 02:24:13 +00:00
|
|
|
INCLUDE "audio/notes.asm"
|