Pitch wheel

This commit is contained in:
pikalaxalt 2016-05-10 14:33:24 -04:00
parent 46ecd5b869
commit f8c14d97e5
7 changed files with 100 additions and 98 deletions

View File

@ -111,7 +111,7 @@ _UpdateSound:: ; e805c
cp $2 ; 1 or 0? cp $2 ; 1 or 0?
jr c, .noteover jr c, .noteover
dec [hl] dec [hl]
jr .asm_e8093 jr .continue_sound_update
.noteover .noteover
; reset vibrato delay ; reset vibrato delay
@ -124,12 +124,11 @@ _UpdateSound:: ; e805c
; turn vibrato off for now ; turn vibrato off for now
ld hl, Channel1Flags2 - Channel1 ld hl, Channel1Flags2 - Channel1
add hl, bc add hl, bc
res SOUND_UNKN_09, [hl] res SOUND_PITCH_WHEEL, [hl]
; get next note ; get next note
call ParseMusic call ParseMusic
.asm_e8093 .continue_sound_update
; call ApplyPitchWheel
call Functione84f9
; duty cycle ; duty cycle
ld hl, Channel1DutyCycle - Channel1 ld hl, Channel1DutyCycle - Channel1
add hl, bc add hl, bc
@ -144,7 +143,7 @@ _UpdateSound:: ; e805c
ld a, [hl] ld a, [hl]
ld [wCurTrackFrequency + 1], a ld [wCurTrackFrequency + 1], a
; ;
call Functione8466 ; handle vibrato and other things call HandleTrackVibrato ; handle vibrato and other things
call HandleNoise call HandleNoise
; turn off music when playing sfx? ; turn off music when playing sfx?
ld a, [SFXPriority] ld a, [SFXPriority]
@ -176,19 +175,19 @@ _UpdateSound:: ; e805c
; are we in a sfx channel right now? ; are we in a sfx channel right now?
ld a, [CurChannel] ld a, [CurChannel]
cp $4 ; sfx cp $4 ; sfx
jr nc, .asm_e80ee jr nc, .sfx_channel
ld hl, Channel5Flags - Channel1 ld hl, Channel5Flags - Channel1
add hl, bc add hl, bc
bit SOUND_CHANNEL_ON, [hl] bit SOUND_CHANNEL_ON, [hl]
jr nz, .asm_e80fc jr nz, .sound_channel_on
.asm_e80ee .sfx_channel
call UpdateChannels call UpdateChannels
ld hl, Channel1Tracks - Channel1 ld hl, Channel1Tracks - Channel1
add hl, bc add hl, bc
ld a, [SoundOutput] ld a, [SoundOutput]
or [hl] or [hl]
ld [SoundOutput], a ld [SoundOutput], a
.asm_e80fc .sound_channel_on
; clear note flags ; clear note flags
ld hl, Channel1NoteFlags - Channel1 ld hl, Channel1NoteFlags - Channel1
add hl, bc add hl, bc
@ -719,16 +718,16 @@ FadeMusic: ; e8358
; e83d1 ; e83d1
LoadNote: ; e83d1 LoadNote: ; e83d1
; check mute?? ; wait for pitch wheel to finish
ld hl, Channel1Flags2 - Channel1 ld hl, Channel1Flags2 - Channel1
add hl, bc add hl, bc
bit SOUND_UNKN_09, [hl] bit SOUND_PITCH_WHEEL, [hl]
ret z ret z
; get note duration ; get note duration
ld hl, Channel1NoteDuration - Channel1 ld hl, Channel1NoteDuration - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
ld hl, wc297 ; ???? ld hl, wCurNoteDuration
sub [hl] sub [hl]
jr nc, .ok jr nc, .ok
ld a, 1 ld a, 1
@ -740,8 +739,8 @@ LoadNote: ; e83d1
ld e, [hl] ld e, [hl]
inc hl inc hl
ld d, [hl] ld d, [hl]
; ???? ; get direction of pitch wheel
ld hl, Channel1Field0x21 - Channel1 ld hl, Channel1PitchWheelTarget - Channel1
add hl, bc add hl, bc
ld a, e ld a, e
sub [hl] sub [hl]
@ -749,15 +748,13 @@ LoadNote: ; e83d1
ld a, d ld a, d
sbc a, 0 sbc a, 0
ld d, a ld d, a
; ???? ld hl, Channel1PitchWheelTarget + 1 - Channel1
ld hl, Channel1Field0x22 - Channel1
add hl, bc add hl, bc
sub [hl] sub [hl]
jr nc, .greater_than jr nc, .greater_than
; ????
ld hl, Channel1Flags3 - Channel1 ld hl, Channel1Flags3 - Channel1
add hl, bc add hl, bc
set SOUND_UNKN_11, [hl] set SOUND_PITCH_WHEEL_DIR, [hl]
; get frequency ; get frequency
ld hl, Channel1Frequency - Channel1 ld hl, Channel1Frequency - Channel1
add hl, bc add hl, bc
@ -765,7 +762,7 @@ LoadNote: ; e83d1
inc hl inc hl
ld d, [hl] ld d, [hl]
; ???? ; ????
ld hl, Channel1Field0x21 - Channel1 ld hl, Channel1PitchWheelTarget - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
sub e sub e
@ -774,7 +771,7 @@ LoadNote: ; e83d1
sbc a, 0 sbc a, 0
ld d, a ld d, a
; ???? ; ????
ld hl, Channel1Field0x22 - Channel1 ld hl, Channel1PitchWheelTarget + 1 - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
sub d sub d
@ -782,18 +779,17 @@ LoadNote: ; e83d1
jr .resume jr .resume
.greater_than .greater_than
; ????
ld hl, Channel1Flags3 - Channel1 ld hl, Channel1Flags3 - Channel1
add hl, bc add hl, bc
res SOUND_UNKN_11, [hl] res SOUND_PITCH_WHEEL_DIR, [hl]
; get frequency ; get frequency
ld hl, Channel1Frequency - Channel1 ld hl, Channel1Frequency - Channel1
add hl, bc add hl, bc
ld e, [hl] ld e, [hl]
inc hl inc hl
ld d, [hl] ld d, [hl]
; ???? ; get distance from pitch wheel target
ld hl, Channel1Field0x21 - Channel1 ld hl, Channel1PitchWheelTarget - Channel1
add hl, bc add hl, bc
ld a, e ld a, e
sub [hl] sub [hl]
@ -801,15 +797,17 @@ LoadNote: ; e83d1
ld a, d ld a, d
sbc a, 0 sbc a, 0
ld d, a ld d, a
; ???? ld hl, Channel1PitchWheelTarget + 1 - Channel1
ld hl, Channel1Field0x22 - Channel1
add hl, bc add hl, bc
sub [hl] sub [hl]
ld d, a ld d, a
.resume .resume
; de = x * [wCurNoteDuration] + y
; x + 1 -> d
; y -> a
push bc push bc
ld hl, wc297 ld hl, wCurNoteDuration
ld b, 0; loop count ld b, 0 ; quotient
.loop .loop
inc b inc b
ld a, e ld a, e
@ -823,18 +821,16 @@ LoadNote: ; e83d1
jr .loop jr .loop
.quit .quit
ld a, e ; result ld a, e ; remainder
add [hl] add [hl]
ld d, b ; loop count ld d, b ; quotient
; ????
pop bc pop bc
ld hl, Channel1Field0x23 - Channel1 ld hl, Channel1PitchWheelAmount - Channel1
add hl, bc add hl, bc
ld [hl], d ld [hl], d ; quotient
ld hl, Channel1Field0x24 - Channel1 ld hl, Channel1PitchWheelAmountFraction - Channel1
add hl, bc add hl, bc
ld [hl], a ld [hl], a ; remainder
; clear ????
ld hl, Channel1Field0x25 - Channel1 ld hl, Channel1Field0x25 - Channel1
add hl, bc add hl, bc
xor a xor a
@ -843,7 +839,7 @@ LoadNote: ; e83d1
; e8466 ; e8466
Functione8466: ; e8466 HandleTrackVibrato: ; e8466
; handle vibrato and other things ; handle vibrato and other things
; unknowns: wCurTrackDuty, wCurTrackFrequency ; unknowns: wCurTrackDuty, wCurTrackFrequency
ld hl, Channel1Flags2 - Channel1 ld hl, Channel1Flags2 - Channel1
@ -963,11 +959,11 @@ Functione8466: ; e8466
; e84f9 ; e84f9
Functione84f9: ; e84f9 ApplyPitchWheel: ; e84f9
; quit if ???? ; quit if pitch wheel inactive
ld hl, Channel1Flags2 - Channel1 ld hl, Channel1Flags2 - Channel1
add hl, bc add hl, bc
bit SOUND_UNKN_09, [hl] bit SOUND_PITCH_WHEEL, [hl]
ret z ret z
; de = Frequency ; de = Frequency
ld hl, Channel1Frequency - Channel1 ld hl, Channel1Frequency - Channel1
@ -975,24 +971,24 @@ Functione84f9: ; e84f9
ld e, [hl] ld e, [hl]
inc hl inc hl
ld d, [hl] ld d, [hl]
; ; check whether pitch wheel is going up or down
ld hl, Channel1Flags3 - Channel1 ld hl, Channel1Flags3 - Channel1
add hl, bc add hl, bc
bit SOUND_UNKN_11, [hl] bit SOUND_PITCH_WHEEL_DIR, [hl]
jr z, .next jr z, .decreasing
; ; frequency += [Channel*PitchWheelAmount]
ld hl, Channel1Field0x23 - Channel1 ld hl, Channel1PitchWheelAmount - Channel1
add hl, bc add hl, bc
ld l, [hl] ld l, [hl]
ld h, 0 ld h, 0
add hl, de add hl, de
ld d, h ld d, h
ld e, l ld e, l
; get ???? ; [Channel*Field0x25] += [Channel*PitchWheelAmountFraction]
ld hl, Channel1Field0x24 - Channel1 ; if rollover: Frequency += 1
ld hl, Channel1PitchWheelAmountFraction - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
; add it to ????
ld hl, Channel1Field0x25 - Channel1 ld hl, Channel1Field0x25 - Channel1
add hl, bc add hl, bc
add [hl] add [hl]
@ -1003,23 +999,26 @@ Functione84f9: ; e84f9
ld a, 0 ld a, 0
adc d adc d
ld d, a ld d, a
; ; Compare the dw at [Channel*PitchWheelTarget] to de.
ld hl, Channel1Field0x22 - Channel1 ; If frequency is greater, we're finished.
; Otherwise, load the frequency and set two flags.
ld hl, Channel1PitchWheelTarget + 1 - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
cp d cp d
jp c, .quit1 jp c, .finished_pitch_wheel
jr nz, .quit2 jr nz, .continue_pitch_wheel
ld hl, Channel1Field0x21 - Channel1 ld hl, Channel1PitchWheelTarget - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
cp e cp e
jp c, .quit1 jp c, .finished_pitch_wheel
jr .quit2 jr .continue_pitch_wheel
.next .decreasing
; frequency -= [Channel*PitchWheelAmount]
ld a, e ld a, e
ld hl, Channel1Field0x23 - Channel1 ld hl, Channel1PitchWheelAmount - Channel1
add hl, bc add hl, bc
ld e, [hl] ld e, [hl]
sub e sub e
@ -1027,7 +1026,9 @@ Functione84f9: ; e84f9
ld a, d ld a, d
sbc a, 0 sbc a, 0
ld d, a ld d, a
ld hl, Channel1Field0x24 - Channel1 ; [Channel*Field0x25] *= 2
; if rollover: Frequency -= 1
ld hl, Channel1PitchWheelAmountFraction - Channel1
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
add a add a
@ -1038,27 +1039,30 @@ Functione84f9: ; e84f9
ld a, d ld a, d
sbc a, 0 sbc a, 0
ld d, a ld d, a
ld hl, Channel1Field0x22 - Channel1 ; Compare the dw at [Channel*PitchWheelTarget] to de.
; If frequency is lower, we're finished.
; Otherwise, load the frequency and set two flags.
ld hl, Channel1PitchWheelTarget + 1 - Channel1
add hl, bc add hl, bc
ld a, d ld a, d
cp [hl] cp [hl]
jr c, .quit1 jr c, .finished_pitch_wheel
jr nz, .quit2 jr nz, .continue_pitch_wheel
ld hl, Channel1Field0x21 - Channel1 ld hl, Channel1PitchWheelTarget - Channel1
add hl, bc add hl, bc
ld a, e ld a, e
cp [hl] cp [hl]
jr nc, .quit2 jr nc, .continue_pitch_wheel
.quit1 .finished_pitch_wheel
ld hl, Channel1Flags2 - Channel1 ld hl, Channel1Flags2 - Channel1
add hl, bc add hl, bc
res SOUND_UNKN_09, [hl] res SOUND_PITCH_WHEEL, [hl]
ld hl, Channel1Flags3 - Channel1 ld hl, Channel1Flags3 - Channel1
add hl, bc add hl, bc
res SOUND_UNKN_11, [hl] res SOUND_PITCH_WHEEL_DIR, [hl]
ret ret
.quit2 .continue_pitch_wheel
ld hl, Channel1Frequency - Channel1 ld hl, Channel1Frequency - Channel1
add hl, bc add hl, bc
ld [hl], e ld [hl], e
@ -1170,9 +1174,9 @@ ParseMusic: ; e85e1
ld hl, Channel1Flags - Channel1 ld hl, Channel1Flags - Channel1
add hl, bc add hl, bc
bit SOUND_SFX, [hl] bit SOUND_SFX, [hl]
jp nz, Functione8698 jp nz, ParseSFXOrRest
bit SOUND_REST, [hl] ; rest bit SOUND_REST, [hl] ; rest
jp nz, Functione8698 jp nz, ParseSFXOrRest
bit SOUND_NOISE, [hl] ; noise sample bit SOUND_NOISE, [hl] ; noise sample
jp nz, GetNoiseSample jp nz, GetNoiseSample
; normal note ; normal note
@ -1286,7 +1290,7 @@ RestoreVolume: ; e8679
; e8698 ; e8698
Functione8698: ; e8698 ParseSFXOrRest: ; e8698
; turn noise sampling on ; turn noise sampling on
ld hl, Channel1NoteFlags - Channel1 ld hl, Channel1NoteFlags - Channel1
add hl, bc add hl, bc
@ -1414,7 +1418,7 @@ MusicCommands: ; e8720
dw Music_SoundStatus ; update sound status dw Music_SoundStatus ; update sound status
dw MusicDE ; ???? + duty cycle dw MusicDE ; ???? + duty cycle
dw Music_ToggleSFX ; dw Music_ToggleSFX ;
dw MusicE0 ; dw Music_SlidePitchTo ;
dw Music_Vibrato ; vibrato dw Music_Vibrato ; vibrato
dw MusicE2 ; unused dw MusicE2 ; unused
dw Music_ToggleNoise ; music noise sampling dw Music_ToggleNoise ; music noise sampling
@ -1796,11 +1800,11 @@ Music_Vibrato: ; e8882
; e88bd ; e88bd
MusicE0: ; e88bd Music_SlidePitchTo: ; e88bd
; ???? ; ????
; params: 2 ; params: 2
call GetMusicByte call GetMusicByte
ld [wc297], a ld [wCurNoteDuration], a
call GetMusicByte call GetMusicByte
ld d, a ld d, a
@ -1812,15 +1816,15 @@ MusicE0: ; e88bd
and $f and $f
ld d, a ld d, a
call GetFrequency call GetFrequency
ld hl, Channel1Field0x21 - Channel1 ld hl, Channel1PitchWheelTarget - Channel1
add hl, bc add hl, bc
ld [hl], e ld [hl], e
ld hl, Channel1Field0x22 - Channel1 ld hl, Channel1PitchWheelTarget + 1 - Channel1
add hl, bc add hl, bc
ld [hl], d ld [hl], d
ld hl, Channel1Flags2 - Channel1 ld hl, Channel1Flags2 - Channel1
add hl, bc add hl, bc
set SOUND_UNKN_09, [hl] set SOUND_PITCH_WHEEL, [hl]
ret ret
; e88e4 ; e88e4

View File

@ -13,13 +13,13 @@ Music_Evolution_Ch1: ; f06ed
dutycycle $2 dutycycle $2
notetype $c, $92 notetype $c, $92
octave 3 octave 3
unknownmusic0xe0 $0, 4, A_ slidepitchto 0, 4, A_
note C_, 1 note C_, 1
unknownmusic0xe0 $0, 4, A_ slidepitchto 0, 4, A_
note G_, 1 note G_, 1
unknownmusic0xe0 $0, 4, A_ slidepitchto 0, 4, A_
note C_, 1 note C_, 1
unknownmusic0xe0 $0, 4, A_ slidepitchto 0, 4, A_
note G_, 1 note G_, 1
note __, 4 note __, 4
dutycycle $3 dutycycle $3

View File

@ -11,16 +11,16 @@ Music_HealPokemon_Ch1: ; f06a0
tone $0001 tone $0001
notetype $c, $81 notetype $c, $81
note __, 2 note __, 2
unknownmusic0xe0 $0, 4, __ slidepitchto 0, 4, __
note B_, 2 note B_, 2
unknownmusic0xe0 $0, 5, E_ slidepitchto 0, 5, E_
note B_, 2 note B_, 2
unknownmusic0xe0 $0, 4, E_ slidepitchto 0, 4, E_
note E_, 2 note E_, 2
note __, 4 note __, 4
unknownmusic0xe0 $0, 3, __ slidepitchto 0, 3, __
note E_, 4 note E_, 4
unknownmusic0xe0 $0, 4, __ slidepitchto 0, 4, __
note B_, 4 note B_, 4
endchannel endchannel
; f06c4 ; f06c4

View File

@ -41,7 +41,7 @@ SOUND_REST EQU 5
; Flags2 ; Flags2
SOUND_VIBRATO EQU 0 SOUND_VIBRATO EQU 0
SOUND_UNKN_09 EQU 1 SOUND_PITCH_WHEEL EQU 1
SOUND_DUTY EQU 2 SOUND_DUTY EQU 2
SOUND_UNKN_0B EQU 3 SOUND_UNKN_0B EQU 3
SOUND_CRY_PITCH EQU 4 SOUND_CRY_PITCH EQU 4
@ -51,7 +51,7 @@ SOUND_UNKN_0F EQU 7
; Flags3 ; Flags3
SOUND_VIBRATO_DIR EQU 0 SOUND_VIBRATO_DIR EQU 0
SOUND_UNKN_11 EQU 1 SOUND_PITCH_WHEEL_DIR EQU 1
; NoteFlags ; NoteFlags
NOTE_UNKN_0 EQU 0 NOTE_UNKN_0 EQU 0

View File

@ -78,11 +78,10 @@ togglesfx: macro
db togglesfx_cmd db togglesfx_cmd
endm endm
enum unknownmusic0xe0_cmd enum slidepitchto_cmd
unknownmusic0xe0: macro slidepitchto: macro
db unknownmusic0xe0_cmd db slidepitchto_cmd
db \1 ; unknown db \1 ; unknown
; db \2 ; unknown
dn \2, \3 ; octave, pitch dn \2, \3 ; octave, pitch
endm endm

View File

@ -146,10 +146,9 @@ channel_struct: MACRO
\1VibratoDelay:: db ; number of frames a note plays until vibrato starts \1VibratoDelay:: db ; number of frames a note plays until vibrato starts
\1VibratoExtent:: db \1VibratoExtent:: db
\1VibratoRate:: db ; hi:frames for each alt lo:frames to the next alt \1VibratoRate:: db ; hi:frames for each alt lo:frames to the next alt
\1Field0x21:: ds 1 ; c122 \1PitchWheelTarget:: dw ; frequency endpoint for pitch wheel
\1Field0x22:: ds 1 ; c123 \1PitchWheelAmount:: db ; c124
\1Field0x23:: ds 1 ; c124 \1PitchWheelAmountFraction:: db ; c125
\1Field0x24:: ds 1 ; c125
\1Field0x25:: ds 1 ; c126 \1Field0x25:: ds 1 ; c126
ds 1 ; c127 ds 1 ; c127
\1CryPitch:: dw \1CryPitch:: dw

View File

@ -34,7 +34,7 @@ wCurTrackDuty:: ds 1
wCurTrackIntensity:: ds 1 wCurTrackIntensity:: ds 1
wCurTrackFrequency:: dw wCurTrackFrequency:: dw
wc296:: ds 1 ; BCD value, dummied out wc296:: ds 1 ; BCD value, dummied out
wc297:: ds 1 ; used in MusicE0 and LoadNote wCurNoteDuration:: ds 1 ; used in MusicE0 and LoadNote
CurMusicByte:: ; c298 CurMusicByte:: ; c298
ds 1 ds 1