diff options
Diffstat (limited to 'audio/engine.asm')
-rw-r--r-- | audio/engine.asm | 616 |
1 files changed, 308 insertions, 308 deletions
diff --git a/audio/engine.asm b/audio/engine.asm index 7aefca7fd..21a472fec 100644 --- a/audio/engine.asm +++ b/audio/engine.asm @@ -38,8 +38,8 @@ _MapSetup_Sound_Off:: ; e8000 dec e jr nz, .clearsound - ld hl, Channels ; start of channel data - ld de, ChannelsEnd - Channels ; length of area to clear (entire sound wram area) + ld hl, wChannels ; start of channel data + ld de, wChannelsEnd - wChannels ; length of area to clear (entire sound wram area) .clearchannels xor a ld [hli], a @@ -60,29 +60,29 @@ _MapSetup_Sound_Off:: ; e8000 MusicFadeRestart: ; e803d ; restart but keep the music id to fade in to - ld a, [MusicFadeID + 1] + ld a, [wMusicFadeID + 1] push af - ld a, [MusicFadeID] + ld a, [wMusicFadeID] push af call _MapSetup_Sound_Off pop af - ld [MusicFadeID], a + ld [wMusicFadeID], a pop af - ld [MusicFadeID + 1], a + ld [wMusicFadeID + 1], a ret ; e8051 MusicOn: ; e8051 ld a, 1 - ld [MusicPlaying], a + ld [wMusicPlaying], a ret ; e8057 MusicOff: ; e8057 xor a - ld [MusicPlaying], a + ld [wMusicPlaying], a ret ; e805c @@ -90,22 +90,22 @@ MusicOff: ; e8057 _UpdateSound:: ; e805c ; called once per frame ; no use updating audio if it's not playing - ld a, [MusicPlaying] + ld a, [wMusicPlaying] and a ret z ; start at ch1 xor a - ld [CurChannel], a ; just - ld [SoundOutput], a ; off + ld [wCurChannel], a ; just + ld [wSoundOutput], a ; off ld bc, wChannel1 .loop ; is the channel active? - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_CHANNEL_ON, [hl] jp z, .nextchannel ; check time left in the current note - ld hl, Channel1NoteDuration - wChannel1 + ld hl, wChannel1NoteDuration - wChannel1 add hl, bc ld a, [hl] cp $2 ; 1 or 0? @@ -115,14 +115,14 @@ _UpdateSound:: ; e805c .noteover ; reset vibrato delay - ld hl, Channel1VibratoDelay - wChannel1 + ld hl, wChannel1VibratoDelay - wChannel1 add hl, bc ld a, [hl] - ld hl, Channel1VibratoDelayCount - wChannel1 + ld hl, wChannel1VibratoDelayCount - wChannel1 add hl, bc ld [hl], a ; turn vibrato off for now - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc res SOUND_PITCH_WHEEL, [hl] ; get next note @@ -130,7 +130,7 @@ _UpdateSound:: ; e805c .continue_sound_update call ApplyPitchWheel ; duty cycle - ld hl, Channel1DutyCycle - wChannel1 + ld hl, wChannel1DutyCycle - wChannel1 add hl, bc ld a, [hli] ld [wCurTrackDuty], a @@ -146,50 +146,50 @@ _UpdateSound:: ; e805c call HandleTrackVibrato ; handle vibrato and other things call HandleNoise ; turn off music when playing sfx? - ld a, [SFXPriority] + ld a, [wSFXPriority] and a jr z, .next ; are we in a sfx channel right now? - ld a, [CurChannel] + ld a, [wCurChannel] cp CHAN5 jr nc, .next ; are any sfx channels active? ; if so, mute - ld hl, Channel5Flags + ld hl, wChannel5Flags bit SOUND_CHANNEL_ON, [hl] jr nz, .restnote - ld hl, Channel6Flags + ld hl, wChannel6Flags bit SOUND_CHANNEL_ON, [hl] jr nz, .restnote - ld hl, Channel7Flags + ld hl, wChannel7Flags bit SOUND_CHANNEL_ON, [hl] jr nz, .restnote - ld hl, Channel8Flags + ld hl, wChannel8Flags bit SOUND_CHANNEL_ON, [hl] jr z, .next .restnote - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_REST, [hl] ; Rest .next ; are we in a sfx channel right now? - ld a, [CurChannel] + ld a, [wCurChannel] cp CHAN5 jr nc, .sfx_channel - ld hl, Channel5Flags - wChannel1 + ld hl, wChannel5Flags - wChannel1 add hl, bc bit SOUND_CHANNEL_ON, [hl] jr nz, .sound_channel_on .sfx_channel call UpdateChannels - ld hl, Channel1Tracks - wChannel1 + ld hl, wChannel1Tracks - wChannel1 add hl, bc - ld a, [SoundOutput] + ld a, [wSoundOutput] or [hl] - ld [SoundOutput], a + ld [wSoundOutput], a .sound_channel_on ; clear note flags - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc xor a ld [hl], a @@ -199,9 +199,9 @@ _UpdateSound:: ; e805c add hl, bc ld c, l ld b, h - ld a, [CurChannel] + ld a, [wCurChannel] inc a - ld [CurChannel], a + ld [wCurChannel], a cp $8 ; are we done? jp nz, .loop ; do it all again @@ -212,7 +212,7 @@ _UpdateSound:: ; e805c ld a, [wVolume] ld [rNR50], a ; write SO on/off to hardware register - ld a, [SoundOutput] + ld a, [wSoundOutput] ld [rNR51], a ret @@ -220,7 +220,7 @@ _UpdateSound:: ; e805c UpdateChannels: ; e8125 ld hl, .ChannelFnPtrs - ld a, [CurChannel] + ld a, [wCurChannel] and $7 add a ld e, a @@ -248,12 +248,12 @@ UpdateChannels: ; e8125 bit DANGER_ON_F, a ret nz .Channel5: - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc bit NOTE_UNKN_3, [hl] jr z, .asm_e8159 ; - ld a, [SoundInput] + ld a, [wSoundInput] ld [rNR10], a .asm_e8159 bit NOTE_REST, [hl] ; rest @@ -317,7 +317,7 @@ UpdateChannels: ; e8125 .Channel2: .Channel6: - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc bit NOTE_REST, [hl] ; rest jr nz, .ch2rest @@ -377,7 +377,7 @@ UpdateChannels: ; e8125 .Channel3: .Channel7: - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc bit NOTE_REST, [hl] ; rest jr nz, .ch3rest @@ -478,7 +478,7 @@ endr .Channel4: .Channel8: - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc bit NOTE_REST, [hl] ; rest jr nz, .ch4rest @@ -514,16 +514,16 @@ endr _CheckSFX: ; e82e7 ; return carry if any sfx channels are active - ld hl, Channel5Flags + ld hl, wChannel5Flags bit SOUND_CHANNEL_ON, [hl] jr nz, .sfxon - ld hl, Channel6Flags + ld hl, wChannel6Flags bit SOUND_CHANNEL_ON, [hl] jr nz, .sfxon - ld hl, Channel7Flags + ld hl, wChannel7Flags bit SOUND_CHANNEL_ON, [hl] jr nz, .sfxon - ld hl, Channel8Flags + ld hl, wChannel8Flags bit SOUND_CHANNEL_ON, [hl] jr nz, .sfxon and a @@ -576,13 +576,13 @@ PlayDanger: ; e8307 or 1 << DANGER_ON_F ld [wLowHealthAlarm], a ; is hw ch1 on? - ld a, [SoundOutput] + ld a, [wSoundOutput] and $11 ret nz ; if not, turn it on - ld a, [SoundOutput] + ld a, [wSoundOutput] or $11 - ld [SoundOutput], a + ld [wSoundOutput], a ret ; e8350 @@ -604,32 +604,32 @@ Tablee8354: ; e8354 FadeMusic: ; e8358 ; fade music if applicable ; usage: -; write to MusicFade +; write to wMusicFade ; song fades out at the given rate -; load song id in MusicFadeID +; load song id in wMusicFadeID ; fade new song in ; notes: ; max # frames per volume level is $3f ; fading? - ld a, [MusicFade] + ld a, [wMusicFade] and a ret z ; has the count ended? - ld a, [MusicFadeCount] + ld a, [wMusicFadeCount] and a jr z, .update ; count down dec a - ld [MusicFadeCount], a + ld [wMusicFadeCount], a ret .update - ld a, [MusicFade] + ld a, [wMusicFade] ld d, a ; get new count and $3f - ld [MusicFadeCount], a + ld [wMusicFadeCount], a ; get SO1 volume ld a, [wVolume] and VOLUME_SO1_LEVEL @@ -647,18 +647,18 @@ FadeMusic: ; e8358 xor a ld [wVolume], a ; did we just get on a bike? - ld a, [PlayerState] + ld a, [wPlayerState] cp PLAYER_BIKE jr z, .bicycle push bc ; restart sound call MusicFadeRestart ; get new song id - ld a, [MusicFadeID] + ld a, [wMusicFadeID] and a jr z, .quit ; this assumes there are fewer than 256 songs! ld e, a - ld a, [MusicFadeID + 1] + ld a, [wMusicFadeID + 1] ld d, a ; load new song call _PlayMusic @@ -667,7 +667,7 @@ FadeMusic: ; e8358 pop bc ; stop fading xor a - ld [MusicFade], a + ld [wMusicFade], a ret .bicycle @@ -679,15 +679,15 @@ FadeMusic: ; e8358 xor a ld [wVolume], a ; get new song id - ld a, [MusicFadeID] + ld a, [wMusicFadeID] ld e, a - ld a, [MusicFadeID + 1] + ld a, [wMusicFadeID + 1] ld d, a ; load new song call _PlayMusic pop bc ; fade in - ld hl, MusicFade + ld hl, wMusicFade set MUSIC_FADE_IN_F, [hl] ret @@ -702,7 +702,7 @@ FadeMusic: ; e8358 .maxvolume ; we're done xor a - ld [MusicFade], a + ld [wMusicFade], a ret .updatevolume @@ -717,12 +717,12 @@ FadeMusic: ; e8358 LoadNote: ; e83d1 ; wait for pitch wheel to finish - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc bit SOUND_PITCH_WHEEL, [hl] ret z ; get note duration - ld hl, Channel1NoteDuration - wChannel1 + ld hl, wChannel1NoteDuration - wChannel1 add hl, bc ld a, [hl] ld hl, wCurNoteDuration @@ -732,13 +732,13 @@ LoadNote: ; e83d1 .ok ld [hl], a ; get frequency - ld hl, Channel1Frequency - wChannel1 + ld hl, wChannel1Frequency - wChannel1 add hl, bc ld e, [hl] inc hl ld d, [hl] ; get direction of pitch wheel - ld hl, Channel1PitchWheelTarget - wChannel1 + ld hl, wChannel1PitchWheelTarget - wChannel1 add hl, bc ld a, e sub [hl] @@ -746,21 +746,21 @@ LoadNote: ; e83d1 ld a, d sbc 0 ld d, a - ld hl, Channel1PitchWheelTarget + 1 - wChannel1 + ld hl, wChannel1PitchWheelTarget + 1 - wChannel1 add hl, bc sub [hl] jr nc, .greater_than - ld hl, Channel1Flags3 - wChannel1 + ld hl, wChannel1Flags3 - wChannel1 add hl, bc set SOUND_PITCH_WHEEL_DIR, [hl] ; get frequency - ld hl, Channel1Frequency - wChannel1 + ld hl, wChannel1Frequency - wChannel1 add hl, bc ld e, [hl] inc hl ld d, [hl] ; ???? - ld hl, Channel1PitchWheelTarget - wChannel1 + ld hl, wChannel1PitchWheelTarget - wChannel1 add hl, bc ld a, [hl] sub e @@ -769,7 +769,7 @@ LoadNote: ; e83d1 sbc 0 ld d, a ; ???? - ld hl, Channel1PitchWheelTarget + 1 - wChannel1 + ld hl, wChannel1PitchWheelTarget + 1 - wChannel1 add hl, bc ld a, [hl] sub d @@ -777,17 +777,17 @@ LoadNote: ; e83d1 jr .resume .greater_than - ld hl, Channel1Flags3 - wChannel1 + ld hl, wChannel1Flags3 - wChannel1 add hl, bc res SOUND_PITCH_WHEEL_DIR, [hl] ; get frequency - ld hl, Channel1Frequency - wChannel1 + ld hl, wChannel1Frequency - wChannel1 add hl, bc ld e, [hl] inc hl ld d, [hl] ; get distance from pitch wheel target - ld hl, Channel1PitchWheelTarget - wChannel1 + ld hl, wChannel1PitchWheelTarget - wChannel1 add hl, bc ld a, e sub [hl] @@ -795,7 +795,7 @@ LoadNote: ; e83d1 ld a, d sbc 0 ld d, a - ld hl, Channel1PitchWheelTarget + 1 - wChannel1 + ld hl, wChannel1PitchWheelTarget + 1 - wChannel1 add hl, bc sub [hl] ld d, a @@ -823,13 +823,13 @@ LoadNote: ; e83d1 add [hl] ld d, b ; quotient pop bc - ld hl, Channel1PitchWheelAmount - wChannel1 + ld hl, wChannel1PitchWheelAmount - wChannel1 add hl, bc ld [hl], d ; quotient - ld hl, Channel1PitchWheelAmountFraction - wChannel1 + ld hl, wChannel1PitchWheelAmountFraction - wChannel1 add hl, bc ld [hl], a ; remainder - ld hl, Channel1Field25 - wChannel1 + ld hl, wChannel1Field25 - wChannel1 add hl, bc xor a ld [hl], a @@ -839,11 +839,11 @@ LoadNote: ; e83d1 HandleTrackVibrato: ; e8466 ; handle duty, cry pitch, and vibrato - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc bit SOUND_DUTY, [hl] ; duty jr z, .next - ld hl, Channel1SFXDutyLoop - wChannel1 + ld hl, wChannel1SFXDutyLoop - wChannel1 add hl, bc ld a, [hl] rlca @@ -851,15 +851,15 @@ HandleTrackVibrato: ; e8466 ld [hl], a and $c0 ld [wCurTrackDuty], a - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_DUTY_OVERRIDE, [hl] .next - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc bit SOUND_CRY_PITCH, [hl] jr z, .vibrato - ld hl, Channel1CryPitch - wChannel1 + ld hl, wChannel1CryPitch - wChannel1 add hl, bc ld e, [hl] inc hl @@ -877,19 +877,19 @@ HandleTrackVibrato: ; e8466 ld [hl], d .vibrato ; is vibrato on? - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc bit SOUND_VIBRATO, [hl] ; vibrato jr z, .quit ; is vibrato active for this note yet? ; is the delay over? - ld hl, Channel1VibratoDelayCount - wChannel1 + ld hl, wChannel1VibratoDelayCount - wChannel1 add hl, bc ld a, [hl] and a jr nz, .subexit ; is the extent nonzero? - ld hl, Channel1VibratoExtent - wChannel1 + ld hl, wChannel1VibratoExtent - wChannel1 add hl, bc ld a, [hl] and a @@ -897,7 +897,7 @@ HandleTrackVibrato: ; e8466 ; save it for later ld d, a ; is it time to toggle vibrato up/down? - ld hl, Channel1VibratoRate - wChannel1 + ld hl, wChannel1VibratoRate - wChannel1 add hl, bc ld a, [hl] and $f ; count @@ -916,7 +916,7 @@ HandleTrackVibrato: ; e8466 ld a, [wCurTrackFrequency] ld e, a ; toggle vibrato up/down - ld hl, Channel1Flags3 - wChannel1 + ld hl, wChannel1Flags3 - wChannel1 add hl, bc bit SOUND_VIBRATO_DIR, [hl] ; vibrato up/down jr z, .down @@ -948,7 +948,7 @@ HandleTrackVibrato: ; e8466 .no_carry ld [wCurTrackFrequency], a ; - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_VIBRATO_OVERRIDE, [hl] .quit @@ -958,23 +958,23 @@ HandleTrackVibrato: ; e8466 ApplyPitchWheel: ; e84f9 ; quit if pitch wheel inactive - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc bit SOUND_PITCH_WHEEL, [hl] ret z ; de = Frequency - ld hl, Channel1Frequency - wChannel1 + ld hl, wChannel1Frequency - wChannel1 add hl, bc ld e, [hl] inc hl ld d, [hl] ; check whether pitch wheel is going up or down - ld hl, Channel1Flags3 - wChannel1 + ld hl, wChannel1Flags3 - wChannel1 add hl, bc bit SOUND_PITCH_WHEEL_DIR, [hl] jr z, .decreasing ; frequency += [Channel*PitchWheelAmount] - ld hl, Channel1PitchWheelAmount - wChannel1 + ld hl, wChannel1PitchWheelAmount - wChannel1 add hl, bc ld l, [hl] ld h, 0 @@ -983,10 +983,10 @@ ApplyPitchWheel: ; e84f9 ld e, l ; [Channel*Field25] += [Channel*PitchWheelAmountFraction] ; if rollover: Frequency += 1 - ld hl, Channel1PitchWheelAmountFraction - wChannel1 + ld hl, wChannel1PitchWheelAmountFraction - wChannel1 add hl, bc ld a, [hl] - ld hl, Channel1Field25 - wChannel1 + ld hl, wChannel1Field25 - wChannel1 add hl, bc add [hl] ld [hl], a @@ -999,13 +999,13 @@ ApplyPitchWheel: ; e84f9 ; Compare the dw at [Channel*PitchWheelTarget] to de. ; If frequency is greater, we're finished. ; Otherwise, load the frequency and set two flags. - ld hl, Channel1PitchWheelTarget + 1 - wChannel1 + ld hl, wChannel1PitchWheelTarget + 1 - wChannel1 add hl, bc ld a, [hl] cp d jp c, .finished_pitch_wheel jr nz, .continue_pitch_wheel - ld hl, Channel1PitchWheelTarget - wChannel1 + ld hl, wChannel1PitchWheelTarget - wChannel1 add hl, bc ld a, [hl] cp e @@ -1015,7 +1015,7 @@ ApplyPitchWheel: ; e84f9 .decreasing ; frequency -= [Channel*PitchWheelAmount] ld a, e - ld hl, Channel1PitchWheelAmount - wChannel1 + ld hl, wChannel1PitchWheelAmount - wChannel1 add hl, bc ld e, [hl] sub e @@ -1025,7 +1025,7 @@ ApplyPitchWheel: ; e84f9 ld d, a ; [Channel*Field25] *= 2 ; if rollover: Frequency -= 1 - ld hl, Channel1PitchWheelAmountFraction - wChannel1 + ld hl, wChannel1PitchWheelAmountFraction - wChannel1 add hl, bc ld a, [hl] add a @@ -1039,33 +1039,33 @@ ApplyPitchWheel: ; e84f9 ; 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 - wChannel1 + ld hl, wChannel1PitchWheelTarget + 1 - wChannel1 add hl, bc ld a, d cp [hl] jr c, .finished_pitch_wheel jr nz, .continue_pitch_wheel - ld hl, Channel1PitchWheelTarget - wChannel1 + ld hl, wChannel1PitchWheelTarget - wChannel1 add hl, bc ld a, e cp [hl] jr nc, .continue_pitch_wheel .finished_pitch_wheel - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc res SOUND_PITCH_WHEEL, [hl] - ld hl, Channel1Flags3 - wChannel1 + ld hl, wChannel1Flags3 - wChannel1 add hl, bc res SOUND_PITCH_WHEEL_DIR, [hl] ret .continue_pitch_wheel - ld hl, Channel1Frequency - wChannel1 + ld hl, wChannel1Frequency - wChannel1 add hl, bc ld [hl], e inc hl ld [hl], d - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_FREQ_OVERRIDE, [hl] set NOTE_DUTY_OVERRIDE, [hl] @@ -1075,16 +1075,16 @@ ApplyPitchWheel: ; e84f9 HandleNoise: ; e858c ; is noise sampling on? - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_NOISE, [hl] ; noise sampling ret z ; are we in a sfx channel? - ld a, [CurChannel] + ld a, [wCurChannel] bit 2, a ; sfx jr nz, .next ; is ch8 on? (noise) - ld hl, Channel8Flags + ld hl, wChannel8Flags bit SOUND_CHANNEL_ON, [hl] ; on? jr z, .next ; is ch8 playing noise? @@ -1109,8 +1109,8 @@ ReadNoiseSample: ; e85af ; zz: intensity ; yy: frequency - ; de = [NoiseSampleAddress] - ld hl, NoiseSampleAddress + ; de = [wNoiseSampleAddress] + ld hl, wNoiseSampleAddress ld e, [hl] inc hl ld d, [hl] @@ -1138,12 +1138,12 @@ ReadNoiseSample: ; e85af xor a ld [wCurTrackFrequency + 1], a - ld hl, NoiseSampleAddress + ld hl, wNoiseSampleAddress ld [hl], e inc hl ld [hl], d - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_NOISE_SAMPLING, [hl] ret @@ -1166,9 +1166,9 @@ ParseMusic: ; e85e1 jr ParseMusic ; start over .readnote -; CurMusicByte contains current note +; wCurMusicByte contains current note ; special notes - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_SFX, [hl] jp nz, ParseSFXOrRest @@ -1178,65 +1178,65 @@ ParseMusic: ; e85e1 jp nz, GetNoiseSample ; normal note ; set note duration (bottom nybble) - ld a, [CurMusicByte] + ld a, [wCurMusicByte] and $f call SetNoteDuration ; get note pitch (top nybble) - ld a, [CurMusicByte] + ld a, [wCurMusicByte] swap a and $f jr z, .rest ; pitch 0-> rest ; update pitch - ld hl, Channel1Pitch - wChannel1 + ld hl, wChannel1Pitch - wChannel1 add hl, bc ld [hl], a ; store pitch in e ld e, a ; store octave in d - ld hl, Channel1Octave - wChannel1 + ld hl, wChannel1Octave - wChannel1 add hl, bc ld d, [hl] ; update frequency call GetFrequency - ld hl, Channel1Frequency - wChannel1 + ld hl, wChannel1Frequency - wChannel1 add hl, bc ld [hl], e inc hl ld [hl], d ; ???? - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_NOISE_SAMPLING, [hl] jp LoadNote .rest ; note = rest - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_REST, [hl] ; Rest ret .endchannel ; $ff is reached in music data - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_SUBROUTINE, [hl] ; in a subroutine? jr nz, .readcommand ; execute - ld a, [CurChannel] + ld a, [wCurChannel] cp CHAN5 jr nc, .chan_5to8 ; ???? - ld hl, Channel5Flags - wChannel1 + ld hl, wChannel5Flags - wChannel1 add hl, bc bit SOUND_CHANNEL_ON, [hl] jr nz, .ok .chan_5to8 - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_REST, [hl] call nz, RestoreVolume ; end music - ld a, [CurChannel] + ld a, [wCurChannel] cp CHAN5 jr nz, .ok ; ???? @@ -1245,15 +1245,15 @@ ParseMusic: ; e85e1 .ok ; stop playing ; turn channel off - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc res SOUND_CHANNEL_ON, [hl] ; note = rest - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_REST, [hl] ; clear music id & bank - ld hl, Channel1MusicID - wChannel1 + ld hl, wChannel1MusicID - wChannel1 add hl, bc xor a ld [hli], a ; id hi @@ -1265,51 +1265,51 @@ ParseMusic: ; e85e1 RestoreVolume: ; e8679 ; ch5 only - ld a, [CurChannel] + ld a, [wCurChannel] cp CHAN5 ret nz xor a - ld hl, Channel6CryPitch + ld hl, wChannel6CryPitch ld [hli], a ld [hl], a - ld hl, Channel8CryPitch + ld hl, wChannel8CryPitch ld [hli], a ld [hl], a - ld a, [LastVolume] + ld a, [wLastVolume] ld [wVolume], a xor a - ld [LastVolume], a - ld [SFXPriority], a + ld [wLastVolume], a + ld [wSFXPriority], a ret ; e8698 ParseSFXOrRest: ; e8698 ; turn noise sampling on - ld hl, Channel1NoteFlags - wChannel1 + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_NOISE_SAMPLING, [hl] ; noise sample ; update note duration - ld a, [CurMusicByte] + ld a, [wCurMusicByte] call SetNoteDuration ; top nybble doesnt matter? ; update intensity from next param call GetMusicByte - ld hl, Channel1Intensity - wChannel1 + ld hl, wChannel1Intensity - wChannel1 add hl, bc ld [hl], a ; update lo frequency from next param call GetMusicByte - ld hl, Channel1FrequencyLo - wChannel1 + ld hl, wChannel1FrequencyLo - wChannel1 add hl, bc ld [hl], a ; are we on the last channel? (noise sampling) - ld a, [CurChannel] + ld a, [wCurChannel] maskbits NUM_MUSIC_CHANS cp CHAN4 ret z ; update hi frequency from next param call GetMusicByte - ld hl, Channel1FrequencyHi - wChannel1 + ld hl, wChannel1FrequencyHi - wChannel1 add hl, bc ld [hl], a ret @@ -1317,29 +1317,29 @@ ParseSFXOrRest: ; e8698 ; e86c5 GetNoiseSample: ; e86c5 -; load ptr to sample header in NoiseSampleAddress +; load ptr to sample header in wNoiseSampleAddress ; are we on the last channel? - ld a, [CurChannel] + ld a, [wCurChannel] and NUM_MUSIC_CHANS +- 1 cp CHAN4 ; ret if not ret nz ; update note duration - ld a, [CurMusicByte] + ld a, [wCurMusicByte] and $f call SetNoteDuration ; check current channel - ld a, [CurChannel] + ld a, [wCurChannel] bit 2, a ; are we in a sfx channel? jr nz, .sfx - ld hl, Channel8Flags + ld hl, wChannel8Flags bit SOUND_CHANNEL_ON, [hl] ; is ch8 on? (noise) ret nz - ld a, [MusicNoiseSampleSet] + ld a, [wMusicNoiseSampleSet] jr .next .sfx - ld a, [SFXNoiseSampleSet] + ld a, [wSFXNoiseSampleSet] .next ; load noise sample set id into de ld e, a @@ -1352,7 +1352,7 @@ GetNoiseSample: ; e86c5 ld h, [hl] ld l, a ; get pitch - ld a, [CurMusicByte] + ld a, [wCurMusicByte] swap a ; non-rest note? and $f @@ -1362,11 +1362,11 @@ GetNoiseSample: ; e86c5 ld d, 0 add hl, de add hl, de - ; load sample pointer into NoiseSampleAddress + ; load sample pointer into wNoiseSampleAddress ld a, [hli] - ld [NoiseSampleAddress], a + ld [wNoiseSampleAddress], a ld a, [hl] - ld [NoiseSampleAddress + 1], a + ld [wNoiseSampleAddress + 1], a ; clear ???? xor a ld [wNoiseSampleDelay], a @@ -1376,7 +1376,7 @@ GetNoiseSample: ; e86c5 ParseMusicCommand: ; e870f ; reload command - ld a, [CurMusicByte] + ld a, [wCurMusicByte] ; get command # sub $d0 ; first command ld e, a @@ -1462,16 +1462,16 @@ Music_EndChannel: ; e8781 ; end music stream ; return to caller of the subroutine ; reset subroutine flag - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc res SOUND_SUBROUTINE, [hl] ; copy LastMusicAddress to MusicAddress - ld hl, Channel1LastMusicAddress - wChannel1 + ld hl, wChannel1LastMusicAddress - wChannel1 add hl, bc ld e, [hl] inc hl ld d, [hl] - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld [hl], e inc hl @@ -1490,25 +1490,25 @@ Music_CallChannel: ; e8796 ld d, a push de ; copy MusicAddress to LastMusicAddress - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld e, [hl] inc hl ld d, [hl] - ld hl, Channel1LastMusicAddress - wChannel1 + ld hl, wChannel1LastMusicAddress - wChannel1 add hl, bc ld [hl], e inc hl ld [hl], d ; load pointer into MusicAddress pop de - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld [hl], e inc hl ld [hl], d ; set subroutine flag - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc set SOUND_SUBROUTINE, [hl] ret @@ -1523,7 +1523,7 @@ Music_JumpChannel: ; e87bc ld e, a call GetMusicByte ld d, a - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld [hl], e inc hl @@ -1542,7 +1542,7 @@ Music_LoopChannel: ; e87cc ; get loop count call GetMusicByte - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_LOOPING, [hl] ; has the loop been initiated? jr nz, .checkloop @@ -1551,11 +1551,11 @@ Music_LoopChannel: ; e87cc ; initiate loop dec a set SOUND_LOOPING, [hl] ; set loop flag - ld hl, Channel1LoopCount - wChannel1 + ld hl, wChannel1LoopCount - wChannel1 add hl, bc ld [hl], a ; store loop counter .checkloop - ld hl, Channel1LoopCount - wChannel1 + ld hl, wChannel1LoopCount - wChannel1 add hl, bc ld a, [hl] and a ; are we done? @@ -1568,7 +1568,7 @@ Music_LoopChannel: ; e87cc call GetMusicByte ld d, a ; load new pointer into MusicAddress - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld [hl], e inc hl @@ -1577,11 +1577,11 @@ Music_LoopChannel: ; e87cc .endloop ; reset loop flag - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc res SOUND_LOOPING, [hl] ; skip to next command - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld e, [hl] inc hl @@ -1603,7 +1603,7 @@ Music_SetCondition: ; e880e ; set condition call GetMusicByte - ld hl, Channel1Condition - wChannel1 + ld hl, wChannel1Condition - wChannel1 add hl, bc ld [hl], a ret @@ -1621,13 +1621,13 @@ Music_JumpIf: ; e8817 ; a = condition call GetMusicByte ; if existing condition matches, jump to new address - ld hl, Channel1Condition - wChannel1 + ld hl, wChannel1Condition - wChannel1 add hl, bc cp [hl] jr z, .jump ; skip to next command ; get address - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld e, [hl] inc hl @@ -1649,7 +1649,7 @@ Music_JumpIf: ; e8817 call GetMusicByte ld d, a ; update pointer in MusicAddress - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld [hl], e inc hl @@ -1667,12 +1667,12 @@ MusicEE; e883e ; if ????, jump ; get channel - ld a, [CurChannel] + ld a, [wCurChannel] maskbits NUM_MUSIC_CHANS ld e, a ld d, 0 - ; hl = Channel1JumpCondition + channel id - ld hl, Channel1JumpCondition + ; hl = wChannel1JumpCondition + channel id + ld hl, wChannel1JumpCondition add hl, de ; if set, jump ld a, [hl] @@ -1680,7 +1680,7 @@ MusicEE; e883e jr nz, .jump ; skip to next command ; get address - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld e, [hl] inc hl @@ -1703,7 +1703,7 @@ MusicEE; e883e call GetMusicByte ld d, a ; update address - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld [hl], e inc hl @@ -1726,10 +1726,10 @@ MusicE2: ; e8873 ; seems to have been dummied out ; params: 1 call GetMusicByte - ld hl, Channel1Field2c - wChannel1 + ld hl, wChannel1Field2c - wChannel1 add hl, bc ld [hl], a - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_UNKN_0B, [hl] ret @@ -1746,28 +1746,28 @@ Music_Vibrato: ; e8882 ; z: rate (# frames per cycle) ; set vibrato flag? - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_VIBRATO, [hl] ; start at lower frequency (extent is positive) - ld hl, Channel1Flags3 - wChannel1 + ld hl, wChannel1Flags3 - wChannel1 add hl, bc res SOUND_VIBRATO_DIR, [hl] ; get delay call GetMusicByte ; update delay - ld hl, Channel1VibratoDelay - wChannel1 + ld hl, wChannel1VibratoDelay - wChannel1 add hl, bc ld [hl], a ; update delay count - ld hl, Channel1VibratoDelayCount - wChannel1 + ld hl, wChannel1VibratoDelayCount - wChannel1 add hl, bc ld [hl], a ; update extent ; this is split into halves only to get added back together at the last second ; get extent/rate call GetMusicByte - ld hl, Channel1VibratoExtent - wChannel1 + ld hl, wChannel1VibratoExtent - wChannel1 add hl, bc ld d, a ; get top nybble @@ -1780,7 +1780,7 @@ Music_Vibrato: ; e8882 or e ld [hl], a ; update rate - ld hl, Channel1VibratoRate - wChannel1 + ld hl, wChannel1VibratoRate - wChannel1 add hl, bc ; get bottom nybble ld a, d @@ -1813,13 +1813,13 @@ Music_SlidePitchTo: ; e88bd and $f ld d, a call GetFrequency - ld hl, Channel1PitchWheelTarget - wChannel1 + ld hl, wChannel1PitchWheelTarget - wChannel1 add hl, bc ld [hl], e - ld hl, Channel1PitchWheelTarget + 1 - wChannel1 + ld hl, wChannel1PitchWheelTarget + 1 - wChannel1 add hl, bc ld [hl], d - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_PITCH_WHEEL, [hl] ret @@ -1829,10 +1829,10 @@ Music_SlidePitchTo: ; e88bd Music_Tone: ; e88e4 ; tone ; params: 1 (dw) - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_CRY_PITCH, [hl] - ld hl, Channel1CryPitch + 1 - wChannel1 + ld hl, wChannel1CryPitch + 1 - wChannel1 add hl, bc call GetMusicByte ld [hld], a @@ -1845,11 +1845,11 @@ Music_Tone: ; e88e4 MusicE7: ; e88f7 ; unused ; params: 1 - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_UNKN_0E, [hl] call GetMusicByte - ld hl, Channel1Field29 - wChannel1 + ld hl, wChannel1Field29 - wChannel1 add hl, bc ld [hl], a ret @@ -1859,19 +1859,19 @@ MusicE7: ; e88f7 Music_SoundDuty: ; e8906 ; sequence of 4 duty cycles to be looped ; params: 1 (4 2-bit duty cycle arguments) - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_DUTY, [hl] ; duty cycle ; sound duty sequence call GetMusicByte rrca rrca - ld hl, Channel1SFXDutyLoop - wChannel1 + ld hl, wChannel1SFXDutyLoop - wChannel1 add hl, bc ld [hl], a ; update duty cycle and $c0 ; only uses top 2 bits - ld hl, Channel1DutyCycle - wChannel1 + ld hl, wChannel1DutyCycle - wChannel1 add hl, bc ld [hl], a ret @@ -1881,11 +1881,11 @@ Music_SoundDuty: ; e8906 MusicE8: ; e891e ; unused ; params: 1 - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_UNKN_0D, [hl] call GetMusicByte - ld hl, Channel1Field2a - wChannel1 + ld hl, wChannel1Field2a - wChannel1 add hl, bc ld [hl], a ret @@ -1895,7 +1895,7 @@ MusicE8: ; e891e Music_ToggleSFX: ; e892d ; toggle something ; params: none - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_SFX, [hl] jr z, .on @@ -1915,7 +1915,7 @@ Music_ToggleNoise: ; e893b ; noise on: 1 ; noise off: 0 ; check if noise sampling is on - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_NOISE, [hl] jr z, .on @@ -1927,7 +1927,7 @@ Music_ToggleNoise: ; e893b ; turn noise sampling on set SOUND_NOISE, [hl] call GetMusicByte - ld [MusicNoiseSampleSet], a + ld [wMusicNoiseSampleSet], a ret ; e894f @@ -1938,7 +1938,7 @@ Music_SFXToggleNoise: ; e894f ; on: 1 ; off: 0 ; check if noise sampling is on - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc bit SOUND_NOISE, [hl] jr z, .on @@ -1950,7 +1950,7 @@ Music_SFXToggleNoise: ; e894f ; turn noise sampling on set SOUND_NOISE, [hl] call GetMusicByte - ld [SFXNoiseSampleSet], a + ld [wSFXNoiseSampleSet], a ret ; e8963 @@ -1962,10 +1962,10 @@ Music_NoteType: ; e8963 ; params: 2 ; note length call GetMusicByte - ld hl, Channel1NoteLength - wChannel1 + ld hl, wChannel1NoteLength - wChannel1 add hl, bc ld [hl], a - ld a, [CurChannel] + ld a, [wCurChannel] maskbits NUM_MUSIC_CHANS cp CHAN4 ret z @@ -1979,8 +1979,8 @@ Music_SoundStatus: ; e8977 ; update sound status ; params: 1 call GetMusicByte - ld [SoundInput], a - ld hl, Channel1NoteFlags - wChannel1 + ld [wSoundInput], a + ld hl, wChannel1NoteFlags - wChannel1 add hl, bc set NOTE_UNKN_3, [hl] ret @@ -1994,7 +1994,7 @@ Music_DutyCycle: ; e8984 rrca rrca and $c0 - ld hl, Channel1DutyCycle - wChannel1 + ld hl, wChannel1DutyCycle - wChannel1 add hl, bc ld [hl], a ret @@ -2007,7 +2007,7 @@ Music_Intensity: ; e8991 ; hi: pressure ; lo: velocity call GetMusicByte - ld hl, Channel1Intensity - wChannel1 + ld hl, wChannel1Intensity - wChannel1 add hl, bc ld [hl], a ret @@ -2036,9 +2036,9 @@ Music_Octave3: ; e89a6 Music_Octave2: ; e89a6 Music_Octave1: ; e89a6 ; set octave based on lo nybble of the command - ld hl, Channel1Octave - wChannel1 + ld hl, wChannel1Octave - wChannel1 add hl, bc - ld a, [CurMusicByte] + ld a, [wCurMusicByte] and 7 ld [hl], a ret @@ -2050,7 +2050,7 @@ Music_ForceOctave: ; e89b1 ; this forces all notes up by the starting octave ; params: 1 call GetMusicByte - ld hl, Channel1PitchOffset - wChannel1 + ld hl, wChannel1PitchOffset - wChannel1 add hl, bc ld [hl], a ret @@ -2061,7 +2061,7 @@ Music_StereoPanning: ; e89ba ; stereo panning ; params: 1 ; stereo on? - ld a, [Options] + ld a, [wOptions] bit STEREO, a jr nz, Music_Panning ; skip param @@ -2075,7 +2075,7 @@ Music_Panning: ; e89c5 ; params: 1 call SetLRTracks call GetMusicByte - ld hl, Channel1Tracks - wChannel1 + ld hl, wChannel1Tracks - wChannel1 add hl, bc and [hl] ld [hl], a @@ -2090,11 +2090,11 @@ Music_Volume: ; e89d2 ; read param even if it's not used call GetMusicByte ; is the song fading? - ld a, [MusicFade] + ld a, [wMusicFade] and a ret nz ; reload param - ld a, [CurMusicByte] + ld a, [wCurMusicByte] ; set volume ld [wVolume], a ret @@ -2116,7 +2116,7 @@ Music_TempoRelative: ; e89e1 .negative ld d, -1 .ok - ld hl, Channel1Tempo - wChannel1 + ld hl, wChannel1Tempo - wChannel1 add hl, bc ld a, [hli] ld h, [hl] @@ -2133,7 +2133,7 @@ Music_SFXPriorityOn: ; e89fd ; turn sfx priority on ; params: none ld a, 1 - ld [SFXPriority], a + ld [wSFXPriority], a ret ; e8a03 @@ -2142,7 +2142,7 @@ Music_SFXPriorityOff: ; e8a03 ; turn sfx priority off ; params: none xor a - ld [SFXPriority], a + ld [wSFXPriority], a ret ; e8a08 @@ -2156,17 +2156,17 @@ Music_RestartChannel: ; e8a08 ; zzyy: pointer to new music data ; update music id - ld hl, Channel1MusicID - wChannel1 + ld hl, wChannel1MusicID - wChannel1 add hl, bc ld a, [hli] - ld [MusicID], a + ld [wMusicID], a ld a, [hl] - ld [MusicID + 1], a + ld [wMusicID + 1], a ; update music bank - ld hl, Channel1MusicBank - wChannel1 + ld hl, wChannel1MusicBank - wChannel1 add hl, bc ld a, [hl] - ld [MusicBank], a + ld [wMusicBank], a ; get pointer to new channel header call GetMusicByte ld l, a @@ -2205,20 +2205,20 @@ GetMusicByte: ; e8a3e push hl push de ; load address into de - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld a, [hli] ld e, a ld d, [hl] ; load bank into a - ld hl, Channel1MusicBank - wChannel1 + ld hl, wChannel1MusicBank - wChannel1 add hl, bc ld a, [hl] ; get byte - call _LoadMusicByte ; load data into CurMusicByte + call _LoadMusicByte ; load data into wCurMusicByte inc de ; advance to next byte for next time this is called ; update channeldata address - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc ld a, e ld [hli], a @@ -2227,7 +2227,7 @@ GetMusicByte: ; e8a3e pop de pop hl ; store channeldata in a - ld a, [CurMusicByte] + ld a, [wCurMusicByte] ret ; e8a5d @@ -2242,7 +2242,7 @@ GetFrequency: ; e8a5d ; get octave ; get starting octave - ld hl, Channel1PitchOffset - wChannel1 + ld hl, wChannel1PitchOffset - wChannel1 add hl, bc ld a, [hl] swap a ; hi nybble @@ -2251,7 +2251,7 @@ GetFrequency: ; e8a5d add d push af ; we'll use this later ; get starting octave - ld hl, Channel1PitchOffset - wChannel1 + ld hl, wChannel1PitchOffset - wChannel1 add hl, bc ld a, [hl] and $f ; lo nybble @@ -2293,7 +2293,7 @@ SetNoteDuration: ; e8a8d ld e, a ld d, 0 ; store NoteLength in a - ld hl, Channel1NoteLength - wChannel1 + ld hl, wChannel1NoteLength - wChannel1 add hl, bc ld a, [hl] ; multiply NoteLength by delay units @@ -2301,13 +2301,13 @@ SetNoteDuration: ; e8a8d call .Multiply ld a, l ; low ; store Tempo in de - ld hl, Channel1Tempo - wChannel1 + ld hl, wChannel1Tempo - wChannel1 add hl, bc ld e, [hl] inc hl ld d, [hl] ; add ???? to the next result - ld hl, Channel1Field16 - wChannel1 + ld hl, wChannel1Field16 - wChannel1 add hl, bc ld l, [hl] ; multiply Tempo by last result (NoteLength * LOW(delay)) @@ -2316,11 +2316,11 @@ SetNoteDuration: ; e8a8d ld e, l ld d, h ; store result in ???? - ld hl, Channel1Field16 - wChannel1 + ld hl, wChannel1Field16 - wChannel1 add hl, bc ld [hl], e ; store result in NoteDuration - ld hl, Channel1NoteDuration - wChannel1 + ld hl, wChannel1NoteDuration - wChannel1 add hl, bc ld [hl], d ret @@ -2353,7 +2353,7 @@ SetNoteDuration: ; e8a8d SetGlobalTempo: ; e8ac7 push bc ; save current channel ; are we dealing with music or sfx? - ld a, [CurChannel] + ld a, [wCurChannel] cp CHAN5 jr nc, .sfxchannels ld bc, wChannel1 @@ -2385,14 +2385,14 @@ Tempo: ; e8b03 ; input: ; de: note length ; update Tempo - ld hl, Channel1Tempo - wChannel1 + ld hl, wChannel1Tempo - wChannel1 add hl, bc ld [hl], e inc hl ld [hl], d ; clear ???? xor a - ld hl, Channel1Field16 - wChannel1 + ld hl, wChannel1Field16 - wChannel1 add hl, bc ld [hl], a ret @@ -2401,7 +2401,7 @@ Tempo: ; e8b03 StartChannel: ; e8b11 call SetLRTracks - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc set SOUND_CHANNEL_ON, [hl] ; turn channel on ret @@ -2413,7 +2413,7 @@ SetLRTracks: ; e8b1b ; seems to be redundant since this is overwritten by stereo data later push de ; store current channel in de - ld a, [CurChannel] + ld a, [wCurChannel] maskbits NUM_MUSIC_CHANS ld e, a ld d, 0 @@ -2422,7 +2422,7 @@ SetLRTracks: ; e8b1b add hl, de ; de = channel 0-3 ld a, [hl] ; load lr tracks into Tracks - ld hl, Channel1Tracks - wChannel1 + ld hl, wChannel1Tracks - wChannel1 add hl, bc ld [hl], a pop de @@ -2433,7 +2433,7 @@ SetLRTracks: ; e8b1b _PlayMusic:: ; e8b30 ; load music call MusicOff - ld hl, MusicID + ld hl, wMusicID ld [hl], e ; song number inc hl ld [hl], d ; (always 0) @@ -2442,7 +2442,7 @@ _PlayMusic:: ; e8b30 add hl, de ; byte add hl, de ; pointer ld a, [hli] - ld [MusicBank], a + ld [wMusicBank], a ld e, [hl] inc hl ld d, [hl] ; music header address @@ -2461,14 +2461,14 @@ _PlayMusic:: ; e8b30 jr nz, .loop xor a ld [wc2b5], a - ld [Channel1JumpCondition], a - ld [Channel2JumpCondition], a - ld [Channel3JumpCondition], a - ld [Channel4JumpCondition], a - ld [NoiseSampleAddress], a - ld [NoiseSampleAddress + 1], a + ld [wChannel1JumpCondition], a + ld [wChannel2JumpCondition], a + ld [wChannel3JumpCondition], a + ld [wChannel4JumpCondition], a + ld [wNoiseSampleAddress], a + ld [wNoiseSampleAddress + 1], a ld [wNoiseSampleDelay], a - ld [MusicNoiseSampleSet], a + ld [wMusicNoiseSampleSet], a call MusicOn ret @@ -2476,13 +2476,13 @@ _PlayMusic:: ; e8b30 _PlayCry:: ; e8b79 ; Play cry de using parameters: -; CryPitch -; CryLength +; wCryPitch +; wCryLength call MusicOff ; Overload the music id with the cry id - ld hl, MusicID + ld hl, wMusicID ld [hl], e inc hl ld [hl], d @@ -2494,7 +2494,7 @@ _PlayCry:: ; e8b79 add hl, de ld a, [hli] - ld [MusicBank], a + ld [wMusicBank], a ld e, [hl] inc hl @@ -2513,33 +2513,33 @@ _PlayCry:: ; e8b79 push af call LoadChannel - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc set SOUND_REST, [hl] - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_CRY_PITCH, [hl] - ld hl, Channel1CryPitch - wChannel1 + ld hl, wChannel1CryPitch - wChannel1 add hl, bc - ld a, [CryPitch] + ld a, [wCryPitch] ld [hli], a - ld a, [CryPitch + 1] + ld a, [wCryPitch + 1] ld [hl], a ; No tempo for channel 4 - ld a, [CurChannel] + ld a, [wCurChannel] maskbits NUM_MUSIC_CHANS cp CHAN4 jr nc, .start ; Tempo is effectively length - ld hl, Channel1Tempo - wChannel1 + ld hl, wChannel1Tempo - wChannel1 add hl, bc - ld a, [CryLength] + ld a, [wCryLength] ld [hli], a - ld a, [CryLength+1] + ld a, [wCryLength+1] ld [hl], a .start call StartChannel @@ -2550,17 +2550,17 @@ _PlayCry:: ; e8b79 ; Stereo only: Play cry from the monster's side. ; This only applies in-battle. - ld a, [Options] + ld a, [wOptions] bit STEREO, a jr z, .next -; [Tracks] &= [CryTracks] - ld hl, Channel1Tracks - wChannel1 +; [Tracks] &= [wCryTracks] + ld hl, wChannel1Tracks - wChannel1 add hl, bc ld a, [hl] - ld hl, CryTracks + ld hl, wCryTracks and [hl] - ld hl, Channel1Tracks - wChannel1 + ld hl, wChannel1Tracks - wChannel1 add hl, bc ld [hl], a @@ -2570,18 +2570,18 @@ _PlayCry:: ; e8b79 jr nz, .loop ; Cries play at max volume, so we save the current volume for later. - ld a, [LastVolume] + ld a, [wLastVolume] and a jr nz, .end ld a, [wVolume] - ld [LastVolume], a + ld [wLastVolume], a ld a, MAX_VOLUME ld [wVolume], a .end ld a, 1 ; stop playing music - ld [SFXPriority], a + ld [wSFXPriority], a call MusicOn ret @@ -2590,7 +2590,7 @@ _PlayCry:: ; e8b79 _PlaySFX:: ; e8c04 ; clear channels if they aren't already call MusicOff - ld hl, Channel5Flags + ld hl, wChannel5Flags bit SOUND_CHANNEL_ON, [hl] ; ch5 on? jr z, .ch6 res SOUND_CHANNEL_ON, [hl] ; turn it off @@ -2603,10 +2603,10 @@ _PlaySFX:: ; e8c04 ld a, $80 ld [rNR14], a ; restart sound (freq hi = 0) xor a - ld [SoundInput], a ; global sound off + ld [wSoundInput], a ; global sound off ld [rNR10], a ; sweep = 0 .ch6 - ld hl, Channel6Flags + ld hl, wChannel6Flags bit SOUND_CHANNEL_ON, [hl] jr z, .ch7 res SOUND_CHANNEL_ON, [hl] ; turn it off @@ -2619,7 +2619,7 @@ _PlaySFX:: ; e8c04 ld a, $80 ld [rNR24], a ; restart sound (freq hi = 0) .ch7 - ld hl, Channel7Flags + ld hl, wChannel7Flags bit SOUND_CHANNEL_ON, [hl] jr z, .ch8 res SOUND_CHANNEL_ON, [hl] ; turn it off @@ -2633,7 +2633,7 @@ _PlaySFX:: ; e8c04 ld a, $80 ld [rNR34], a ; restart sound (freq hi = 0) .ch8 - ld hl, Channel8Flags + ld hl, wChannel8Flags bit SOUND_CHANNEL_ON, [hl] jr z, .chscleared res SOUND_CHANNEL_ON, [hl] ; turn it off @@ -2646,11 +2646,11 @@ _PlaySFX:: ; e8c04 ld a, $80 ld [rNR44], a ; restart sound (freq hi = 0) xor a - ld [NoiseSampleAddress], a - ld [NoiseSampleAddress + 1], a + ld [wNoiseSampleAddress], a + ld [wNoiseSampleAddress + 1], a .chscleared ; start reading sfx header for # chs - ld hl, MusicID + ld hl, wMusicID ld [hl], e inc hl ld [hl], d @@ -2660,7 +2660,7 @@ _PlaySFX:: ; e8c04 add hl, de ; pointers ; get bank ld a, [hli] - ld [MusicBank], a + ld [wMusicBank], a ; get address ld e, [hl] inc hl @@ -2674,7 +2674,7 @@ _PlaySFX:: ; e8c04 .startchannels push af call LoadChannel ; bc = current channel - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc set SOUND_SFX, [hl] call StartChannel @@ -2683,7 +2683,7 @@ _PlaySFX:: ; e8c04 jr nz, .startchannels call MusicOn xor a - ld [SFXPriority], a + ld [wSFXPriority], a ret ; e8ca6 @@ -2694,12 +2694,12 @@ PlayStereoSFX:: ; e8ca6 call MusicOff ; standard procedure if stereo's off - ld a, [Options] + ld a, [wOptions] bit STEREO, a jp z, _PlaySFX ; else, let's go ahead with this - ld hl, MusicID + ld hl, wMusicID ld [hl], e inc hl ld [hl], d @@ -2712,7 +2712,7 @@ PlayStereoSFX:: ; e8ca6 ; bank ld a, [hli] - ld [MusicBank], a + ld [wMusicBank], a ; address ld e, [hl] inc hl @@ -2729,13 +2729,13 @@ PlayStereoSFX:: ; e8ca6 push af call LoadChannel - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc set SOUND_SFX, [hl] push de ; get tracks for this channel - ld a, [CurChannel] + ld a, [wCurChannel] maskbits NUM_MUSIC_CHANS ld e, a ld d, 0 @@ -2745,30 +2745,30 @@ PlayStereoSFX:: ; e8ca6 ld hl, wStereoPanningMask and [hl] - ld hl, Channel1Tracks - wChannel1 + ld hl, wChannel1Tracks - wChannel1 add hl, bc ld [hl], a - ld hl, Channel1Field30 - wChannel1 + ld hl, wChannel1Field30 - wChannel1 add hl, bc ld [hl], a - ld a, [CryTracks] + ld a, [wCryTracks] cp 2 ; ch 1-2 jr c, .skip ; ch3-4 ld a, [wSFXDuration] - ld hl, Channel1Field2e - wChannel1 + ld hl, wChannel1Field2e - wChannel1 add hl, bc ld [hl], a - ld hl, Channel1Field2f - wChannel1 + ld hl, wChannel1Field2f - wChannel1 add hl, bc ld [hl], a - ld hl, Channel1Flags2 - wChannel1 + ld hl, wChannel1Flags2 - wChannel1 add hl, bc set SOUND_UNKN_0F, [hl] @@ -2776,7 +2776,7 @@ PlayStereoSFX:: ; e8ca6 pop de ; turn channel on - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc set SOUND_CHANNEL_ON, [hl] ; on @@ -2799,7 +2799,7 @@ LoadChannel: ; e8d1b call LoadMusicByte inc de and $7 ; bit 0-2 (current channel) - ld [CurChannel], a + ld [wCurChannel], a ld c, a ld b, 0 ld hl, ChannelPointers @@ -2808,12 +2808,12 @@ LoadChannel: ; e8d1b ld c, [hl] inc hl ld b, [hl] ; bc = channel pointer - ld hl, Channel1Flags - wChannel1 + ld hl, wChannel1Flags - wChannel1 add hl, bc res SOUND_CHANNEL_ON, [hl] ; channel off call ChannelInit ; load music pointer - ld hl, Channel1MusicAddress - wChannel1 + ld hl, wChannel1MusicAddress - wChannel1 add hl, bc call LoadMusicByte ld [hli], a @@ -2822,16 +2822,16 @@ LoadChannel: ; e8d1b ld [hl], a inc de ; load music id - ld hl, Channel1MusicID - wChannel1 + ld hl, wChannel1MusicID - wChannel1 add hl, bc - ld a, [MusicID] + ld a, [wMusicID] ld [hli], a - ld a, [MusicID + 1] + ld a, [wMusicID + 1] ld [hl], a ; load music bank - ld hl, Channel1MusicBank - wChannel1 + ld hl, wChannel1MusicBank - wChannel1 add hl, bc - ld a, [MusicBank] + ld a, [wMusicBank] ld [hl], a ret @@ -2845,7 +2845,7 @@ ChannelInit: ; e8d5b push de xor a ; get channel struct location and length - ld hl, Channel1MusicID - wChannel1 ; start + ld hl, wChannel1MusicID - wChannel1 ; start add hl, bc ld e, wChannel2 - wChannel1 ; channel struct length ; clear channel @@ -2854,14 +2854,14 @@ ChannelInit: ; e8d5b dec e jr nz, .loop ; set tempo to default ($100) - ld hl, Channel1Tempo - wChannel1 + ld hl, wChannel1Tempo - wChannel1 add hl, bc xor a ld [hli], a inc a ld [hl], a ; set note length to default ($1) (fast) - ld hl, Channel1NoteLength - wChannel1 + ld hl, wChannel1NoteLength - wChannel1 add hl, bc ld [hl], a pop de @@ -2873,10 +2873,10 @@ LoadMusicByte:: ; e8d76 ; input: ; de = current music address ; output: -; a = CurMusicByte - ld a, [MusicBank] +; a = wCurMusicByte + ld a, [wMusicBank] call _LoadMusicByte - ld a, [CurMusicByte] + ld a, [wCurMusicByte] ret ; e8d80 @@ -2892,7 +2892,7 @@ INCLUDE "audio/drumkits.asm" GetLRTracks: ; e8fc2 ; gets the default sound l/r channels ; stores mono/stereo table in hl - ld a, [Options] + ld a, [wOptions] bit STEREO, a ; made redundant, could have had a purpose in gold jr nz, .stereo @@ -2973,7 +2973,7 @@ PlayTrainerEncounterMusic:: ; e900a ; input: e = trainer type ; turn fade off xor a - ld [MusicFade], a + ld [wMusicFade], a ; play nothing for one frame push de ld de, MUSIC_NONE |