ref: 66bc517605860c9f716a176ed467d34097985895
parent: 8a6d46f3d9ba4fb6939eb9ea9949f47aa8608d4a
parent: 2b018159997e3b580efd114ff4e3548a0de3cbc5
author: dannye <corrnondacqb@yahoo.com>
date: Sun Aug 9 20:00:12 EDT 2015
Merge branch 'master' of https://github.com/YamaArashi/pokered
--- a/audio.asm
+++ b/audio.asm
@@ -364,10 +364,10 @@
PlayBattleMusic:: ; 0x90c6
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld [wLowHealthAlarm], a
dec a
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound ; stop music
call DelayFrame
ld c, BANK(Music_GymLeaderBattle)
@@ -406,7 +406,7 @@
ld c, BANK(Music_MeetRival)
ld a, MUSIC_MEET_RIVAL
call PlayMusic
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld de, Music_MeetRival_branch_b1a2
call Audio1_OverwriteChannelPointer
ld de, Music_MeetRival_branch_b21d
@@ -425,7 +425,7 @@
ld c, BANK(Music_MeetRival)
ld a, MUSIC_MEET_RIVAL
call PlayMusic
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld de, Music_MeetRival_branch_b119
jp Audio1_OverwriteChannelPointer
@@ -432,23 +432,23 @@
; applies both the alternate start and alternate tempo
Music_RivalAlternateStartAndTempo:: ; 0x9b75
call Music_RivalAlternateStart
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld de, Music_MeetRival_branch_b19b
jp Audio1_OverwriteChannelPointer
; an alternate tempo for Cities1 which is used for the Hall of Fame room
Music_Cities1AlternateTempo:: ; 0x9b81
- ld a, $a
- ld [wcfc8], a
- ld [wcfc9], a
- ld a, $ff
- ld [wMusicHeaderPointer], a
+ ld a, 10
+ ld [wAudioFadeOutCounterReloadValue], a
+ ld [wAudioFadeOutCounter], a
+ ld a, $ff ; stop playing music after the fade-out is finished
+ ld [wAudioFadeOutControl], a
ld c, 100
- call DelayFrames
+ call DelayFrames ; wait for the fade-out to finish
ld c, BANK(Music_Cities1)
ld a, MUSIC_CITIES1
call PlayMusic
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld de, Music_Cities1_branch_aa6f
jp Audio1_OverwriteChannelPointer
@@ -477,7 +477,7 @@
.asm_2138a
ld a, $86
- ld [wc02a], a ;disable sound channel?
+ ld [wChannelSoundIDs + CH4], a ;disable sound channel?
ld a, [wLowHealthAlarm]
and $7f ;decrement alarm timer.
dec a
@@ -491,7 +491,7 @@
.disableAlarm
xor a
ld [wLowHealthAlarm], a ;disable alarm
- ld [wc02a], a ;re-enable sound channel?
+ ld [wChannelSoundIDs + CH4], a ;re-enable sound channel?
ld de, .toneDataSilence
jr .playTone
@@ -542,7 +542,7 @@
ld a, SFX_CAUGHT_MON
call PlaySoundWaitForCurrent
; then immediately overwrtie the channel pointers
- ld hl, wc00e
+ ld hl, wChannelCommandPointers + CH4 * 2
ld de, SFX_08_PokeFlute_Ch1
call Audio2_OverwriteChannelPointer
ld de, SFX_08_PokeFlute_Ch2
@@ -572,7 +572,7 @@
.gotSfxPointer
push bc
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySoundWaitForCurrent
pop bc
ld b, $0
--- a/audio/engine_1.asm
+++ b/audio/engine_1.asm
@@ -3,8 +3,8 @@
Audio1_UpdateMusic:: ; 0x9103
ld c, CH0
.loop
- ld b, $0
- ld hl, wc026
+ ld b, 0
+ ld hl, wChannelSoundIDs
add hl, bc
ld a, [hl]
and a
@@ -11,21 +11,21 @@
jr z, .nextChannel
ld a, c
cp CH4
- jr nc, .asm_912e ; if sfx channel
- ld a, [wc002]
+ jr nc, .applyAffects ; if sfx channel
+ ld a, [wMuteAudioAndPauseMusic]
and a
- jr z, .asm_912e
+ jr z, .applyAffects
bit 7, a
jr nz, .nextChannel
set 7, a
- ld [wc002], a
- xor a
- ld [$ff25], a
- ld [$ff1a], a
+ ld [wMuteAudioAndPauseMusic], a
+ xor a ; disable all channels' output
+ ld [rNR51], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
jr .nextChannel
-.asm_912e
+.applyAffects
call Audio1_ApplyMusicAffects
.nextChannel
ld a, c
@@ -36,15 +36,9 @@
; this routine checks flags for music effects currently applied
; to the channel and calls certain functions based on flags.
-; known flags for wc02e:
-; 0: toggleperfectpitch has been used
-; 1: call has been used
-; 3: a toggle used only by this routine for vibrato
-; 4: pitchbend flag
-; 6: dutycycle flag
Audio1_ApplyMusicAffects: ; 0x9138
ld b, $0
- ld hl, wc0b6 ; delay until next note
+ ld hl, wChannelNoteDelayCounters ; delay until next note
add hl, bc
ld a, [hl]
cp $1 ; if the delay is 1, play next note
@@ -54,7 +48,7 @@
ld a, c
cp CH4
jr nc, .startChecks ; if a sfx channel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
@@ -61,38 +55,38 @@
jr z, .startChecks
ret
.startChecks
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- bit 6, [hl] ; dutycycle
+ bit BIT_ROTATE_DUTY, [hl]
jr z, .checkForExecuteMusic
call Audio1_ApplyDutyCycle
.checkForExecuteMusic
- ld b, $0
- ld hl, wc036
+ ld b, 0
+ ld hl, wChannelFlags2
add hl, bc
- bit 0, [hl]
+ bit BIT_EXECUTE_MUSIC, [hl]
jr nz, .checkForPitchBend
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- bit 2, [hl]
- jr nz, .disablePitchBendVibrato
+ bit BIT_NOISE_OR_SFX, [hl]
+ jr nz, .skipPitchBendVibrato
.checkForPitchBend
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- bit 4, [hl] ; pitchbend
+ bit BIT_PITCH_BEND_ON, [hl]
jr z, .checkVibratoDelay
jp Audio1_ApplyPitchBend
.checkVibratoDelay
- ld hl, wc04e ; vibrato delay
+ ld hl, wChannelVibratoDelayCounters
add hl, bc
ld a, [hl]
and a ; check if delay is over
jr z, .checkForVibrato
dec [hl] ; otherwise, dec delay
-.disablePitchBendVibrato
+.skipPitchBendVibrato
ret
.checkForVibrato
- ld hl, wc056 ; vibrato rate
+ ld hl, wChannelVibratoExtents
add hl, bc
ld a, [hl]
and a
@@ -100,27 +94,29 @@
ret ; no vibrato
.vibrato
ld d, a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, bc
ld a, [hl]
and $f
and a
- jr z, .vibratoAlreadyDone
- dec [hl] ; apply vibrato pitch change
+ jr z, .applyVibrato
+ dec [hl] ; decrement counter
ret
-.vibratoAlreadyDone
+.applyVibrato
ld a, [hl]
swap [hl]
or [hl]
- ld [hl], a ; reset the vibrato value and start again
- ld hl, wc066
+ ld [hl], a ; reload the counter
+ ld hl, wChannelFrequencyLowBytes
add hl, bc
ld e, [hl] ; get note pitch
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- bit 3, [hl] ; this is the only code that sets/resets bit three so
- jr z, .unset ; it continuously alternates which path it takes
- res 3, [hl]
+; 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]
ld a, d
and $f
ld d, a
@@ -127,11 +123,11 @@
ld a, e
sub d
jr nc, .noCarry
- ld a, $0
+ ld a, 0
.noCarry
jr .done
.unset
- set 3, [hl]
+ set BIT_VIBRATO_DIRECTION, [hl]
ld a, d
and $f0
swap a
@@ -140,8 +136,8 @@
ld a, $ff
.done
ld d, a
- ld b, $3
- call Audio1_9838
+ ld b, REG_FREQUENCY_LO
+ call Audio1_GetRegisterPointer
ld [hl], d
ret
@@ -149,16 +145,18 @@
; like tempo changes, duty changes etc. and doesn't return
; until the first note is reached
Audio1_PlayNextNote: ; 0x91d0
- ld hl, wc06e
+; reload the vibrato delay counter
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, bc
ld a, [hl]
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, bc
ld [hl], a
- ld hl, wc02e
+
+ ld hl, wChannelFlags1
add hl, bc
- res 4, [hl]
- res 5, [hl]
+ res BIT_PITCH_BEND_ON, [hl]
+ res BIT_PITCH_BEND_DECREASING, [hl]
call Audio1_endchannel
ret
@@ -167,34 +165,35 @@
ld d, a
cp $ff ; is this command an endchannel?
jp nz, Audio1_callchannel ; no
- ld b, $0 ; yes
- ld hl, wc02e
+ ld b, 0
+ ld hl, wChannelFlags1
add hl, bc
- bit 1, [hl]
+ bit BIT_CHANNEL_CALL, [hl]
jr nz, .returnFromCall
ld a, c
cp CH3
jr nc, .noiseOrSfxChannel
- jr .asm_923f
+ jr .disableChannelOutput
.noiseOrSfxChannel
- res 2, [hl]
- ld hl, wc036
+ res BIT_NOISE_OR_SFX, [hl]
+ ld hl, wChannelFlags2
add hl, bc
- res 0, [hl]
+ res BIT_EXECUTE_MUSIC, [hl]
cp CH6
- jr nz, .notSfxChannel3
+ jr nz, .skipSfxChannel3
+; restart hardware channel 3 (wave channel) output
ld a, $0
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
-.notSfxChannel3
+ ld [rNR30], a
+.skipSfxChannel3
jr nz, .asm_9222
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr z, .asm_9222
xor a
- ld [wc003], a
- jr .asm_923f
+ ld [wDisableChannelOutputWhenSfxEnds], a
+ jr .disableChannelOutput
.asm_9222
jr .asm_9248
.returnFromCall
@@ -203,10 +202,10 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
push hl ; store current channel address
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld e, l
ld d, h
@@ -217,36 +216,36 @@
ld a, [de]
ld [hl], a ; loads channel address to return to
jp Audio1_endchannel
-.asm_923f
- ld hl, Unknown_9b1f
+.disableChannelOutput
+ ld hl, Audio1_HWChannelDisableMasks
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
and [hl]
- ld [$ff25], a
+ ld [rNR51], a
.asm_9248
- ld a, [wc02a]
- cp $14
+ ld a, [wChannelSoundIDs + CH4]
+ cp CRY_SFX_START
jr nc, .asm_9251
- jr .asm_926e
+ jr .skipCry
.asm_9251
- ld a, [wc02a]
- cp $86
- jr z, .asm_926e
- jr c, .asm_925c
- jr .asm_926e
-.asm_925c
+ ld a, [wChannelSoundIDs + CH4]
+ cp CRY_SFX_END
+ jr z, .skipCry
+ jr c, .cry
+ jr .skipCry
+.cry
ld a, c
cp CH4
jr z, .asm_9265
- call Audio1_96c7
+ call Audio1_GoBackOneCommandIfCry
ret c
.asm_9265
- ld a, [wc005]
- ld [$ff24], a
+ ld a, [wSavedVolume]
+ ld [rNR50], a
xor a
- ld [wc005], a
-.asm_926e
- ld hl, wc026
+ ld [wSavedVolume], a
+.skipCry
+ ld hl, wChannelSoundIDs
add hl, bc
ld [hl], b
ret
@@ -254,7 +253,7 @@
Audio1_callchannel: ; 0x9274
cp $fd ; is this command a callchannel?
jp nz, Audio1_loopchannel ; no
- call Audio1_GetNextMusicByte ; yes
+ call Audio1_GetNextMusicByte
push af
call Audio1_GetNextMusicByte
ld d, a
@@ -265,10 +264,10 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
push hl
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld e, l
ld d, h
@@ -283,20 +282,20 @@
inc hl
ld [hl], d ; overwrite current address with pointer
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- set 1, [hl] ; set the call flag
+ set BIT_CHANNEL_CALL, [hl] ; set the call flag
jp Audio1_endchannel
Audio1_loopchannel: ; 0x92a9
cp $fe ; is this command a loopchannel?
jp nz, Audio1_notetype ; no
- call Audio1_GetNextMusicByte ; yes
+ call Audio1_GetNextMusicByte
ld e, a
and a
jr z, .infiniteLoop
- ld b, $0
- ld hl, wc0be
+ ld b, 0
+ ld hl, wChannelLoopCounters
add hl, bc
ld a, [hl]
cp e
@@ -319,7 +318,7 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
pop af
ld [hli], a
@@ -330,10 +329,10 @@
and $f0
cp $d0 ; is this command a notetype?
jp nz, Audio1_toggleperfectpitch ; no
- ld a, d ; yes
+ ld a, d
and $f
ld b, $0
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, bc
ld [hl], a ; store low nibble as speed
ld a, c
@@ -345,15 +344,15 @@
cp CH2
jr z, .musicChannel3
cp CH6
- jr nz, .notChannel3
- ld hl, wc0e7
- jr .sfxChannel3
+ jr nz, .skipChannel3
+ ld hl, wSfxWaveInstrument
+ jr .channel3
.musicChannel3
- ld hl, wc0e6
-.sfxChannel3
+ ld hl, wMusicWaveInstrument
+.channel3
ld a, d
and $f
- ld [hl], a ; store low nibble of param as duty
+ ld [hl], a ; store low nibble of param as wave instrument
ld a, d
and $30
sla a
@@ -362,9 +361,9 @@
; if channel 3, store high nibble as volume
; else, store volume (high nibble) and fade (low nibble)
-.notChannel3
- ld b, $0
- ld hl, wc0de
+.skipChannel3
+ ld b, 0
+ ld hl, wChannelVolumes
add hl, bc
ld [hl], d
.noiseChannel
@@ -374,31 +373,38 @@
ld a, d
cp $e8 ; is this command a toggleperfectpitch?
jr nz, Audio1_vibrato ; no
- ld b, $0 ; yes
- ld hl, wc02e
+ ld b, 0
+ ld hl, wChannelFlags1
add hl, bc
ld a, [hl]
xor $1
- ld [hl], a ; flip bit 0 of wc02e
+ ld [hl], a ; flip bit 0 of wChannelFlags1
jp Audio1_endchannel
Audio1_vibrato: ; 0x9335
cp $ea ; is this command a vibrato?
jr nz, Audio1_pitchbend ; no
- call Audio1_GetNextMusicByte ; yes
- ld b, $0
- ld hl, wc04e
+ call Audio1_GetNextMusicByte
+ ld b, 0
+ ld hl, wChannelVibratoDelayCounters
add hl, bc
ld [hl], a ; store delay
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, bc
ld [hl], a ; store delay
call Audio1_GetNextMusicByte
ld d, a
+
+; 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.
and $f0
swap a
- ld b, $0
- ld hl, wc056
+ ld b, 0
+ ld hl, wChannelVibratoExtents
add hl, bc
srl a
ld e, a
@@ -405,25 +411,32 @@
adc b
swap a
or e
- ld [hl], a ; store rate as both high and low nibbles
+ 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.
ld a, d
and $f
ld d, a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, bc
swap a
or d
- ld [hl], a ; store depth as both high and low nibbles
+ ld [hl], a
+
jp Audio1_endchannel
Audio1_pitchbend: ; 0x936d
cp $eb ; is this command a pitchbend?
jr nz, Audio1_duty ; no
- call Audio1_GetNextMusicByte ; yes
- ld b, $0
- ld hl, wc076
+ call Audio1_GetNextMusicByte
+ ld b, 0
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
- ld [hl], a ; store first param
+ ld [hl], a
call Audio1_GetNextMusicByte
ld d, a
and $f0
@@ -431,18 +444,18 @@
ld b, a
ld a, d
and $f
- call Audio1_9858
- ld b, $0
- ld hl, wc0a6
+ call Audio1_CalculateFrequency
+ ld b, 0
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
- ld [hl], d ; store unknown part of second param
- ld hl, wc0ae
+ ld [hl], d
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
- ld [hl], e ; store unknown part of second param
- ld b, $0
- ld hl, wc02e
+ ld [hl], e
+ ld b, 0
+ ld hl, wChannelFlags1
add hl, bc
- set 4, [hl] ; set pitchbend flag
+ set BIT_PITCH_BEND_ON, [hl]
call Audio1_GetNextMusicByte
ld d, a
jp Audio1_notelength
@@ -450,12 +463,12 @@
Audio1_duty: ; 0x93a5
cp $ec ; is this command a duty?
jr nz, Audio1_tempo ; no
- call Audio1_GetNextMusicByte ; yes
+ call Audio1_GetNextMusicByte
rrca
rrca
and $c0
- ld b, $0
- ld hl, wc03e
+ ld b, 0
+ ld hl, wChannelDuties
add hl, bc
ld [hl], a ; store duty
jp Audio1_endchannel
@@ -463,29 +476,29 @@
Audio1_tempo: ; 0x93ba
cp $ed ; is this command a tempo?
jr nz, Audio1_stereopanning ; no
- ld a, c ; yes
+ ld a, c
cp CH4
jr nc, .sfxChannel
call Audio1_GetNextMusicByte
- ld [wc0e8], a ; store first param
+ ld [wMusicTempo], a ; store first param
call Audio1_GetNextMusicByte
- ld [wc0e9], a ; store second param
+ ld [wMusicTempo + 1], a ; store second param
xor a
- ld [wc0ce], a ; clear RAM
- ld [wc0cf], a
- ld [wc0d0], a
- ld [wc0d1], a
+ ld [wChannelNoteDelayCountersFractionalPart], a ; clear RAM
+ ld [wChannelNoteDelayCountersFractionalPart + 1], a
+ ld [wChannelNoteDelayCountersFractionalPart + 2], a
+ ld [wChannelNoteDelayCountersFractionalPart + 3], a
jr .musicChannelDone
.sfxChannel
call Audio1_GetNextMusicByte
- ld [wc0ea], a ; store first param
+ ld [wSfxTempo], a ; store first param
call Audio1_GetNextMusicByte
- ld [wc0eb], a ; store second param
+ ld [wSfxTempo + 1], a ; store second param
xor a
- ld [wc0d2], a ; clear RAM
- ld [wc0d3], a
- ld [wc0d4], a
- ld [wc0d5], a
+ ld [wChannelNoteDelayCountersFractionalPart + 4], a ; clear RAM
+ ld [wChannelNoteDelayCountersFractionalPart + 5], a
+ ld [wChannelNoteDelayCountersFractionalPart + 6], a
+ ld [wChannelNoteDelayCountersFractionalPart + 7], a
.musicChannelDone
jp Audio1_endchannel
@@ -492,8 +505,8 @@
Audio1_stereopanning: ; 0x93fa
cp $ee ; is this command a stereopanning?
jr nz, Audio1_unknownmusic0xef ; no
- call Audio1_GetNextMusicByte ; yes
- ld [wc004], a ; store panning
+ call Audio1_GetNextMusicByte
+ ld [wStereoPanning], a ; store panning
jp Audio1_endchannel
; this appears to never be used
@@ -500,17 +513,17 @@
Audio1_unknownmusic0xef: ; 0x9407
cp $ef ; is this command an unknownmusic0xef?
jr nz, Audio1_dutycycle ; no
- call Audio1_GetNextMusicByte ; yes
+ call Audio1_GetNextMusicByte
push bc
- call Audio1_9876
+ call Audio1_PlaySound
pop bc
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr nz, .skip
- ld a, [wc02d]
- ld [wc003], a
+ ld a, [wChannelSoundIDs + CH7]
+ ld [wDisableChannelOutputWhenSfxEnds], a
xor a
- ld [wc02d], a
+ ld [wChannelSoundIDs + CH7], a
.skip
jp Audio1_endchannel
@@ -517,34 +530,34 @@
Audio1_dutycycle: ; 0x9426
cp $fc ; is this command a dutycycle?
jr nz, Audio1_volume ; no
- call Audio1_GetNextMusicByte ; yes
- ld b, $0
- ld hl, wc046
+ call Audio1_GetNextMusicByte
+ ld b, 0
+ ld hl, wChannelDutyCycles
add hl, bc
ld [hl], a ; store full cycle
and $c0
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld [hl], a ; store first duty
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- set 6, [hl] ; set dutycycle flag
+ set BIT_ROTATE_DUTY, [hl]
jp Audio1_endchannel
Audio1_volume: ; 0x9444
cp $f0 ; is this command a volume?
jr nz, Audio1_executemusic ; no
- call Audio1_GetNextMusicByte ; yes
- ld [$ff24], a ; store volume
+ call Audio1_GetNextMusicByte
+ ld [rNR50], a ; store volume
jp Audio1_endchannel
Audio1_executemusic: ; 0x9450
cp $f8 ; is this command an executemusic?
jr nz, Audio1_octave ; no
- ld b, $0 ; yes
- ld hl, wc036
+ ld b, $0
+ ld hl, wChannelFlags2
add hl, bc
- set 0, [hl]
+ set BIT_EXECUTE_MUSIC, [hl]
jp Audio1_endchannel
Audio1_octave: ; 0x945f
@@ -551,8 +564,8 @@
and $f0
cp $e0 ; is this command an octave?
jr nz, Audio1_unknownsfx0x20 ; no
- ld hl, wc0d6 ; yes
- ld b, $0
+ ld hl, wChannelOctaves
+ ld b, 0
add hl, bc
ld a, d
and $f
@@ -561,47 +574,54 @@
Audio1_unknownsfx0x20: ; 0x9472
cp $20 ; is this command an unknownsfx0x20?
- jr nz, Audio1_unknownsfx0x10 ; no
+ jr nz, Audio1_unknownsfx0x10
ld a, c
cp CH3 ; is this a noise or sfx channel?
jr c, Audio1_unknownsfx0x10 ; no
- ld b, $0
- ld hl, wc036
+ ld b, 0
+ ld hl, wChannelFlags2
add hl, bc
- bit 0, [hl]
- jr nz, Audio1_unknownsfx0x10 ; no
- call Audio1_notelength ; yes
+ bit BIT_EXECUTE_MUSIC, [hl] ; is executemusic being used?
+ jr nz, Audio1_unknownsfx0x10 ; yes
+ call Audio1_notelength
+
+; This code seems to do the same thing as what Audio1_ApplyDutyAndSoundLength
+; does below.
ld d, a
- ld b, $0
- ld hl, wc03e
+ ld b, 0
+ ld hl, wChannelDuties
add hl, bc
ld a, [hl]
or d
ld d, a
- ld b, $1
- call Audio1_9838
+ ld b, REG_DUTY_SOUND_LEN
+ call Audio1_GetRegisterPointer
ld [hl], d
+
call Audio1_GetNextMusicByte
ld d, a
- ld b, $2
- call Audio1_9838
+ ld b, REG_VOLUME_ENVELOPE
+ call Audio1_GetRegisterPointer
ld [hl], d
call Audio1_GetNextMusicByte
ld e, a
ld a, c
cp CH7
- ld a, $0
- jr z, .sfxNoiseChannel ; only two params for noise channel
+ 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.
push de
call Audio1_GetNextMusicByte
pop de
-.sfxNoiseChannel
+.skip
ld d, a
push de
- call Audio1_9629
- call Audio1_95f8
+ call Audio1_ApplyDutyAndSoundLength
+ call Audio1_EnableChannelOutput
pop de
- call Audio1_964b
+ call Audio1_ApplyWavePatternAndFrequency
ret
Audio1_unknownsfx0x10:
@@ -612,12 +632,12 @@
cp $10 ; is this command a unknownsfx0x10?
jr nz, Audio1_note ; no
ld b, $0
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
- bit 0, [hl]
+ bit BIT_EXECUTE_MUSIC, [hl]
jr nz, Audio1_note ; no
- call Audio1_GetNextMusicByte ; yes
- ld [$ff10], a
+ call Audio1_GetNextMusicByte
+ ld [rNR10], a
jp Audio1_endchannel
Audio1_note:
@@ -627,7 +647,7 @@
ld a, d
and $f0
cp $b0 ; is this command a dnote?
- jr z, Audio1_dnote ; yes
+ jr z, Audio1_dnote
jr nc, Audio1_notelength ; no
swap a
ld b, a
@@ -647,11 +667,11 @@
call Audio1_GetNextMusicByte ; get dnote instrument
asm_94fd
ld d, a
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr nz, .asm_9508
ld a, d
- call Audio1_9876
+ call Audio1_PlaySound
.asm_9508
pop bc
pop de
@@ -661,20 +681,20 @@
push af
and $f
inc a
- ld b, $0
+ ld b, 0
ld e, a ; store note length (in 16ths)
ld d, b
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, bc
ld a, [hl]
ld l, b
- call Audio1_9847
+ call Audio1_MultiplyAdd
ld a, c
cp CH4
jr nc, .sfxChannel
- ld a, [wc0e8]
+ ld a, [wMusicTempo]
ld d, a
- ld a, [wc0e9]
+ ld a, [wMusicTempo + 1]
ld e, a
jr .skip
.sfxChannel
@@ -682,34 +702,34 @@
ld e, $0
cp CH7
jr z, .skip ; if noise channel
- call Audio1_9693
- ld a, [wc0ea]
+ call Audio1_SetSfxTempo
+ ld a, [wSfxTempo]
ld d, a
- ld a, [wc0eb]
+ ld a, [wSfxTempo + 1]
ld e, a
.skip
- ld a, l
- ld b, $0
- ld hl, wc0ce
+ ld a, l ; a = note_length * note_speed
+ ld b, 0
+ ld hl, wChannelNoteDelayCountersFractionalPart
add hl, bc
ld l, [hl]
- call Audio1_9847
+ call Audio1_MultiplyAdd
ld e, l
- ld d, h
- ld hl, wc0ce
+ ld d, h ; de = note_delay_frac_part + (note_length * note_speed * tempo)
+ ld hl, wChannelNoteDelayCountersFractionalPart
add hl, bc
ld [hl], e
ld a, d
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld [hl], a
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
- bit 0, [hl]
+ bit BIT_EXECUTE_MUSIC, [hl]
jr nz, Audio1_notepitch
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- bit 2, [hl]
+ bit BIT_NOISE_OR_SFX, [hl]
jr z, Audio1_notepitch
pop hl
ret
@@ -721,167 +741,173 @@
jr nz, .notRest
ld a, c
cp CH4
- jr nc, .sfxChannel
- ld hl, wc02a
+ jr nc, .next
+; If this isn't an SFX channel, try the corresponding SFX channel.
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
jr nz, .done
; fall through
-.sfxChannel
+.next
ld a, c
cp CH2
- jr z, .musicChannel3
+ jr z, .channel3
cp CH6
- jr nz, .notSfxChannel3
-.musicChannel3
- ld b, $0
- ld hl, Unknown_9b1f
+ jr nz, .notChannel3
+.channel3
+ ld b, 0
+ ld hl, Audio1_HWChannelDisableMasks
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
and [hl]
- ld [$ff25], a
+ ld [rNR51], a ; disable hardware channel 3's output
jr .done
-.notSfxChannel3
- ld b, $2
- call Audio1_9838
- ld a, $8
+.notChannel3
+ ld b, REG_VOLUME_ENVELOPE
+ call Audio1_GetRegisterPointer
+ ld a, $8 ; fade in sound
ld [hli], a
inc hl
- ld a, $80
+ ld a, $80 ; restart sound
ld [hl], a
.done
ret
.notRest
swap a
- ld b, $0
- ld hl, wc0d6
+ ld b, 0
+ ld hl, wChannelOctaves
add hl, bc
ld b, [hl]
- call Audio1_9858
- ld b, $0
- ld hl, wc02e
+ call Audio1_CalculateFrequency
+ ld b, 0
+ ld hl, wChannelFlags1
add hl, bc
- bit 4, [hl]
- jr z, .asm_95b8
- call Audio1_978f
-.asm_95b8
+ bit BIT_PITCH_BEND_ON, [hl]
+ jr z, .skipPitchBend
+ call Audio1_InitPitchBendVars
+.skipPitchBend
push de
ld a, c
cp CH4
- jr nc, .skip ; if sfx channel
- ld hl, wc02a
- ld d, $0
+ jr nc, .sfxChannel ; if sfx channel
+; If this isn't an SFX channel, try the corresponding SFX channel.
+ ld hl, wChannelSoundIDs + CH4
+ ld d, 0
ld e, a
add hl, de
ld a, [hl]
and a
- jr nz, .asm_95cb
- jr .skip
-.asm_95cb
+ jr nz, .noSfx
+ jr .sfxChannel
+.noSfx
pop de
ret
-.skip
- ld b, $0
- ld hl, wc0de
+.sfxChannel
+ ld b, 0
+ ld hl, wChannelVolumes
add hl, bc
ld d, [hl]
- ld b, $2
- call Audio1_9838
+ ld b, REG_VOLUME_ENVELOPE
+ call Audio1_GetRegisterPointer
ld [hl], d
- call Audio1_9629
- call Audio1_95f8
+ call Audio1_ApplyDutyAndSoundLength
+ call Audio1_EnableChannelOutput
pop de
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- bit 0, [hl] ; has toggleperfectpitch been used?
- jr z, .skip2
- inc e ; if yes, increment the pitch by 1
- jr nc, .skip2
+ bit BIT_PERFECT_PITCH, [hl] ; has toggleperfectpitch been used?
+ jr z, .skipFrequencyInc
+ inc e ; if yes, increment the frequency by 1
+ jr nc, .skipFrequencyInc
inc d
-.skip2
- ld hl, wc066
+.skipFrequencyInc
+ ld hl, wChannelFrequencyLowBytes
add hl, bc
ld [hl], e
- call Audio1_964b
+ call Audio1_ApplyWavePatternAndFrequency
ret
-Audio1_95f8: ; 0x95f8
- ld b, $0
- ld hl, Unknown_9b27
+Audio1_EnableChannelOutput: ; 0x95f8
+ ld b, 0
+ ld hl, Audio1_HWChannelEnableMasks
add hl, bc
- ld a, [$ff25]
- or [hl]
+ ld a, [rNR51]
+ or [hl] ; set this channel's bits
ld d, a
ld a, c
cp CH7
- jr z, .sfxNoiseChannel
+ jr z, .noiseChannelOrNoSfx
cp CH4
jr nc, .skip ; if sfx channel
- ld hl, wc02a
+; If this isn't an SFX channel, try the corresponding SFX channel.
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
jr nz, .skip
-.sfxNoiseChannel
- ld a, [wc004]
- ld hl, Unknown_9b27
+.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
add hl, bc
and [hl]
ld d, a
- ld a, [$ff25]
- ld hl, Unknown_9b1f
+ ld a, [rNR51]
+ ld hl, Audio1_HWChannelDisableMasks
add hl, bc
- and [hl]
- or d
+ and [hl] ; reset this channel's output bits
+ or d ; set this channel's output bits that enabled in [wStereoPanning]
ld d, a
.skip
ld a, d
- ld [$ff25], a
+ ld [rNR51], a
ret
-Audio1_9629: ; 0x9629
- ld b, $0
- ld hl, wc0b6
+Audio1_ApplyDutyAndSoundLength: ; 0x9629
+ ld b, 0
+ ld hl, wChannelNoteDelayCounters ; use the note delay as sound length
add hl, bc
ld d, [hl]
ld a, c
cp CH2
- jr z, .channel3 ; if music channel 3
+ jr z, .skipDuty ; if music channel 3
cp CH6
- jr z, .channel3 ; if sfx channel 3
+ jr z, .skipDuty ; if sfx channel 3
+; include duty (except on channel 3 which doesn't have it)
ld a, d
and $3f
ld d, a
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld a, [hl]
or d
ld d, a
-.channel3
- ld b, $1
- call Audio1_9838
+.skipDuty
+ ld b, REG_DUTY_SOUND_LEN
+ call Audio1_GetRegisterPointer
ld [hl], d
ret
-Audio1_964b: ; 0x964b
+Audio1_ApplyWavePatternAndFrequency: ; 0x964b
ld a, c
cp CH2
jr z, .channel3
cp CH6
- jr nz, .notSfxChannel3
+ jr nz, .notChannel3
; fall through
.channel3
push de
- ld de, wc0e6
+ ld de, wMusicWaveInstrument
cp CH2
- jr z, .musicChannel3
- ld de, wc0e7
-.musicChannel3
+ jr z, .next
+ ld de, wSfxWaveInstrument
+.next
ld a, [de]
add a
- ld d, $0
+ ld d, 0
ld e, a
ld hl, Audio1_WavePointers
add hl, de
@@ -888,10 +914,10 @@
ld e, [hl]
inc hl
ld d, [hl]
- ld hl, $ff30
+ ld hl, $ff30 ; wave pattern RAM
ld b, $f
- ld a, $0
- ld [$ff1a], a
+ ld a, $0 ; stop hardware channel 3
+ ld [rNR30], a
.loop
ld a, [de]
inc de
@@ -900,111 +926,114 @@
dec b
and a
jr nz, .loop
- ld a, $80
- ld [$ff1a], a
+ ld a, $80 ; start hardware channel 3
+ ld [rNR30], a
pop de
-.notSfxChannel3
+.notChannel3
ld a, d
- or $80
- and $c7
+ or $80 ; use counter mode (i.e. disable output when the counter reaches 0)
+ and $c7 ; zero the unused bits in the register
ld d, a
- ld b, $3
- call Audio1_9838
- ld [hl], e
+ ld b, REG_FREQUENCY_LO
+ call Audio1_GetRegisterPointer
+ ld [hl], e ; store frequency low byte
inc hl
- ld [hl], d
- call Audio1_96b5
+ ld [hl], d ; store frequency high byte
+ call Audio1_ApplyFrequencyModifier
ret
-Audio1_9693: ; 0x9693
- call Audio1_96e5
- jr nc, .asm_96ab
- ld d, $0
- ld a, [wc0f2]
+Audio1_SetSfxTempo: ; 0x9693
+ call Audio1_IsCry
+ jr nc, .notCry
+ ld d, 0
+ ld a, [wTempoModifier]
add $80
- jr nc, .asm_96a2
+ jr nc, .next
inc d
-.asm_96a2
- ld [wc0eb], a
+.next
+ ld [wSfxTempo + 1], a
ld a, d
- ld [wc0ea], a
- jr .asm_96b4
-.asm_96ab
+ ld [wSfxTempo], a
+ jr .done
+.notCry
xor a
- ld [wc0eb], a
+ ld [wSfxTempo + 1], a
ld a, $1
- ld [wc0ea], a
-.asm_96b4
+ ld [wSfxTempo], a
+.done
ret
-Audio1_96b5: ; 0x96b5
- call Audio1_96e5
- jr nc, .asm_96c6
- ld a, [wc0f1]
+Audio1_ApplyFrequencyModifier: ; 0x96b5
+ call Audio1_IsCry
+ jr nc, .done
+; if playing a cry, add the cry's frequency modifier
+ ld a, [wFrequencyModifier]
add e
- jr nc, .asm_96c1
+ jr nc, .noCarry
inc d
-.asm_96c1
+.noCarry
dec hl
ld e, a
ld [hl], e
inc hl
ld [hl], d
-.asm_96c6
+.done
ret
-Audio1_96c7: ; 0x96c7
- call Audio1_96e5
- jr nc, .asm_96e2
- ld hl, wc006
+Audio1_GoBackOneCommandIfCry: ; 0x96c7
+ call Audio1_IsCry
+ jr nc, .done
+ ld hl, wChannelCommandPointers
ld e, c
- ld d, $0
+ ld d, 0
sla e
rl d
add hl, de
ld a, [hl]
- sub $1
+ sub 1
ld [hl], a
inc hl
ld a, [hl]
- sbc $0
+ sbc 0
ld [hl], a
scf
ret
-.asm_96e2
+.done
scf
ccf
ret
-Audio1_96e5: ; 0x96e5
- ld a, [wc02a]
- cp $14
- jr nc, .asm_96ee
- jr .asm_96f4
-.asm_96ee
- cp $86
- jr z, .asm_96f4
- jr c, .asm_96f7
-.asm_96f4
+Audio1_IsCry: ; 0x96e5
+; Returns whether the currently playing audio is a cry in carry.
+ ld a, [wChannelSoundIDs + CH4]
+ cp CRY_SFX_START
+ jr nc, .next
+ jr .no
+.next
+ cp CRY_SFX_END
+ jr z, .no
+ jr c, .yes
+.no
scf
ccf
ret
-.asm_96f7
+.yes
scf
ret
Audio1_ApplyPitchBend: ; 0x96f9
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
- bit 5, [hl]
- jp nz, .asm_9740
- ld hl, wc09e
+ bit BIT_PITCH_BEND_DECREASING, [hl]
+ jp nz, .frequencyDecreasing
+; frequency increasing
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld e, [hl]
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld l, [hl]
ld h, b
@@ -1011,41 +1040,41 @@
add hl, de
ld d, h
ld e, l
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, bc
push hl
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld a, [hl]
pop hl
add [hl]
ld [hl], a
- ld a, $0
+ ld a, 0
adc e
ld e, a
- ld a, $0
+ ld a, 0
adc d
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, [hl]
cp d
- jp c, .asm_9786
- jr nz, .asm_9773
- ld hl, wc0ae
+ jp c, .reachedTargetFrequency
+ jr nz, .applyUpdatedFrequency
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, [hl]
cp e
- jp c, .asm_9786
- jr .asm_9773
-.asm_9740
- ld hl, wc09e
+ jp c, .reachedTargetFrequency
+ jr .applyUpdatedFrequency
+.frequencyDecreasing
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld a, [hl]
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld e, [hl]
sub e
@@ -1053,7 +1082,7 @@
ld a, d
sbc b
ld d, a
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld a, [hl]
add a
@@ -1064,55 +1093,56 @@
ld a, d
sbc b
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, d
cp [hl]
- jr c, .asm_9786
- jr nz, .asm_9773
- ld hl, wc0ae
+ jr c, .reachedTargetFrequency
+ jr nz, .applyUpdatedFrequency
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, e
cp [hl]
- jr c, .asm_9786
-.asm_9773
- ld hl, wc09e
+ jr c, .reachedTargetFrequency
+.applyUpdatedFrequency
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld [hl], e
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld [hl], d
- ld b, $3
- call Audio1_9838
+ ld b, REG_FREQUENCY_LO
+ call Audio1_GetRegisterPointer
ld a, e
ld [hli], a
ld [hl], d
ret
-.asm_9786
- ld hl, wc02e
+.reachedTargetFrequency
+; Turn off pitch bend when the target frequency has been reached.
+ ld hl, wChannelFlags1
add hl, bc
- res 4, [hl]
- res 5, [hl]
+ res BIT_PITCH_BEND_ON, [hl]
+ res BIT_PITCH_BEND_DECREASING, [hl]
ret
-Audio1_978f: ; 0x978f
- ld hl, wc096
+Audio1_InitPitchBendVars: ; 0x978f
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld [hl], d
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld [hl], e
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld a, [hl]
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
sub [hl]
- jr nc, .asm_97a7
- ld a, $1
-.asm_97a7
+ jr nc, .next
+ ld a, 1
+.next
ld [hl], a
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, e
sub [hl]
@@ -1119,74 +1149,84 @@
ld e, a
ld a, d
sbc b
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
sub [hl]
- jr c, .asm_97c3
+ jr c, .targetFrequencyGreater
ld d, a
- ld b, $0
- ld hl, wc02e
+ ld b, 0
+ ld hl, wChannelFlags1
add hl, bc
- set 5, [hl]
- jr .asm_97e6
-.asm_97c3
- ld hl, wc096
+ set BIT_PITCH_BEND_DECREASING, [hl]
+ jr .next2
+.targetFrequencyGreater
+; If the target frequency is greater, subtract the current frequency from
+; the target frequency to get the absolute difference.
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld e, [hl]
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, [hl]
sub e
ld e, a
+
+; 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.
ld a, d
sbc b
ld d, a
- ld hl, wc0a6
+
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, [hl]
sub d
ld d, a
- ld b, $0
- ld hl, wc02e
+ ld b, 0
+ ld hl, wChannelFlags1
add hl, bc
- res 5, [hl]
-.asm_97e6
- ld hl, wc076
+ res BIT_PITCH_BEND_DECREASING, [hl]
+
+.next2
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
-.asm_97ea
+.divideLoop
inc b
ld a, e
sub [hl]
ld e, a
- jr nc, .asm_97ea
+ jr nc, .divideLoop
ld a, d
and a
- jr z, .asm_97f8
+ jr z, .doneDividing
dec a
ld d, a
- jr .asm_97ea
-.asm_97f8
- ld a, e
+ jr .divideLoop
+.doneDividing
+ ld a, e ; a = remainder - dividend
add [hl]
- ld d, b
- ld b, $0
- ld hl, wc07e
+ ld d, b ; d = quotient + 1
+ ld b, 0
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
- ld [hl], d
- ld hl, wc086
+ ld [hl], d ; store quotient + 1
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
- ld [hl], a
- ld hl, wc08e
+ ld [hl], a ; store remainder - dividend
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, bc
- ld [hl], a
+ ld [hl], a ; store remainder - dividend
ret
Audio1_ApplyDutyCycle: ; 0x980d
- ld b, $0
- ld hl, wc046
+ ld b, 0
+ ld hl, wChannelDutyCycles
add hl, bc
ld a, [hl]
rlca
@@ -1194,8 +1234,8 @@
ld [hl], a
and $c0
ld d, a
- ld b, $1
- call Audio1_9838
+ ld b, REG_DUTY_SOUND_LEN
+ call Audio1_GetRegisterPointer
ld a, [hl]
and $3f
or d
@@ -1203,11 +1243,11 @@
ret
Audio1_GetNextMusicByte: ; 0x9825
- ld d, $0
+ ld d, 0
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
ld a, [hli]
ld e, a
@@ -1220,9 +1260,10 @@
ld [hl], d
ret
-Audio1_9838: ; 0x9838
+Audio1_GetRegisterPointer: ; 0x9838
+; hl = address of hardware sound register b for software channel c
ld a, c
- ld hl, Unknown_9b17
+ ld hl, Audio1_HWChannelBaseAddresses
add l
jr nc, .noCarry
inc h
@@ -1234,13 +1275,14 @@
ld h, $ff
ret
-Audio1_9847: ; 0x9847
- ld h, $0
+Audio1_MultiplyAdd: ; 0x9847
+; hl = l + (a * de)
+ ld h, 0
.loop
srl a
- jr nc, .noCarry
+ jr nc, .skipAdd
add hl, de
-.noCarry
+.skipAdd
sla e
rl d
and a
@@ -1249,8 +1291,9 @@
.done
ret
-Audio1_9858: ; 0x9858
- ld h, $0
+Audio1_CalculateFrequency: ; 0x9858
+; return the frequency for note a, octave b in de
+ ld h, 0
ld l, a
add hl, hl
ld d, h
@@ -1262,7 +1305,7 @@
ld d, [hl]
ld a, b
.loop
- cp $7
+ cp 7
jr z, .done
sra d
rr e
@@ -1269,98 +1312,99 @@
inc a
jr .loop
.done
- ld a, $8
+ ld a, 8
add d
ld d, a
ret
-Audio1_9876:: ; 0x9876
- ld [wc001], a
+Audio1_PlaySound:: ; 0x9876
+ ld [wSoundID], a
cp $ff
- jp z, Audio1_9a34
- cp $b9
- jp z, Audio1_994e
- jp c, Audio1_994e
+ jp z, .stopAllAudio
+ cp MAX_SFX_ID
+ jp z, .playSfx
+ jp c, .playSfx
cp $fe
- jr z, .asm_988d
- jp nc, Audio1_994e
-.asm_988d
+ jr z, .playMusic
+ jp nc, .playSfx
+
+.playMusic
xor a
- ld [wc000], a
- ld [wc003], a
- ld [wc0e9], a
- ld [wc0e6], a
- ld [wc0e7], a
+ ld [wUnusedC000], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
+ ld [wMusicTempo + 1], a
+ ld [wMusicWaveInstrument], a
+ ld [wSfxWaveInstrument], a
ld d, $8
- ld hl, wc016
- call FillAudioRAM1
- ld hl, wc006
- call FillAudioRAM1
+ ld hl, wChannelReturnAddresses
+ call .FillMem
+ ld hl, wChannelCommandPointers
+ call .FillMem
ld d, $4
- ld hl, wc026
- call FillAudioRAM1
- ld hl, wc02e
- call FillAudioRAM1
- ld hl, wc03e
- call FillAudioRAM1
- ld hl, wc046
- call FillAudioRAM1
- ld hl, wc04e
- call FillAudioRAM1
- ld hl, wc056
- call FillAudioRAM1
- ld hl, wc05e
- call FillAudioRAM1
- ld hl, wc066
- call FillAudioRAM1
- ld hl, wc06e
- call FillAudioRAM1
- ld hl, wc036
- call FillAudioRAM1
- ld hl, wc076
- call FillAudioRAM1
- ld hl, wc07e
- call FillAudioRAM1
- ld hl, wc086
- call FillAudioRAM1
- ld hl, wc08e
- call FillAudioRAM1
- ld hl, wc096
- call FillAudioRAM1
- ld hl, wc09e
- call FillAudioRAM1
- ld hl, wc0a6
- call FillAudioRAM1
- ld hl, wc0ae
- call FillAudioRAM1
+ ld hl, wChannelSoundIDs
+ call .FillMem
+ ld hl, wChannelFlags1
+ call .FillMem
+ ld hl, wChannelDuties
+ call .FillMem
+ ld hl, wChannelDutyCycles
+ call .FillMem
+ 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
+ ld hl, wChannelPitchBendLengthModifiers
+ call .FillMem
+ ld hl, wChannelPitchBendFrequencySteps
+ call .FillMem
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
+ call .FillMem
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
+ call .FillMem
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
+ call .FillMem
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
+ call .FillMem
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
+ call .FillMem
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
+ call .FillMem
ld a, $1
- ld hl, wc0be
- call FillAudioRAM1
- ld hl, wc0b6
- call FillAudioRAM1
- ld hl, wc0c6
- call FillAudioRAM1
- ld [wc0e8], a
+ ld hl, wChannelLoopCounters
+ call .FillMem
+ ld hl, wChannelNoteDelayCounters
+ call .FillMem
+ ld hl, wChannelNoteSpeeds
+ call .FillMem
+ ld [wMusicTempo], a
ld a, $ff
- ld [wc004], a
+ ld [wStereoPanning], a
xor a
- ld [$ff24], a
+ ld [rNR50], a
ld a, $8
- ld [$ff10], a
- ld a, $0
- ld [$ff25], a
+ ld [rNR10], a
+ ld a, 0
+ ld [rNR51], a
xor a
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $77
- ld [$ff24], a
- jp Audio1_9a8f
+ ld [rNR50], a
+ jp .playSoundCommon
-Audio1_994e: ; 0x994e
+.playSfx
ld l, a
ld e, a
- ld h, $0
+ ld h, 0
ld d, h
add hl, hl
add hl, de
@@ -1367,32 +1411,32 @@
ld de, SFX_Headers_1
add hl, de
ld a, h
- ld [wc0ec], a
+ ld [wSfxHeaderPointer], a
ld a, l
- ld [wc0ed], a
+ ld [wSfxHeaderPointer + 1], a
ld a, [hl]
and $c0
rlca
rlca
ld c, a
-.asm_9967
+.sfxChannelLoop
ld d, c
ld a, c
add a
add c
ld c, a
- ld b, $0
- ld a, [wc0ec]
+ ld b, 0
+ ld a, [wSfxHeaderPointer]
ld h, a
- ld a, [wc0ed]
+ ld a, [wSfxHeaderPointer + 1]
ld l, a
add hl, bc
ld c, d
ld a, [hl]
and $f
- ld e, a
- ld d, $0
- ld hl, wc026
+ ld e, a ; software channel ID
+ ld d, 0
+ ld hl, wChannelSoundIDs
add hl, de
ld a, [hl]
and a
@@ -1400,7 +1444,7 @@
ld a, e
cp $7
jr nz, .asm_999a
- ld a, [wc001]
+ ld a, [wSoundID]
cp $14
jr nc, .asm_9993
ret
@@ -1410,7 +1454,7 @@
jr z, .asm_99a3
jr c, .asm_99a3
.asm_999a
- ld a, [wc001]
+ ld a, [wSoundID]
cp [hl]
jr z, .asm_99a3
jr c, .asm_99a3
@@ -1423,132 +1467,132 @@
add hl, hl
ld d, h
ld e, l
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld [hli], a
ld [hl], a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
ld [hli], a
ld [hl], a
pop de
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, de
ld [hl], a
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, de
ld [hl], a
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, de
ld [hl], a
- ld hl, wc046
+ ld hl, wChannelDutyCycles
add hl, de
ld [hl], a
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, de
ld [hl], a
- ld hl, wc056
+ ld hl, wChannelVibratoExtents
add hl, de
ld [hl], a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, de
ld [hl], a
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, de
ld [hl], a
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, de
ld [hl], a
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, de
ld [hl], a
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, de
ld [hl], a
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, de
ld [hl], a
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, de
ld [hl], a
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, de
ld [hl], a
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, de
ld [hl], a
ld a, $1
- ld hl, wc0be
+ ld hl, wChannelLoopCounters
add hl, de
ld [hl], a
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, de
ld [hl], a
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, de
ld [hl], a
ld a, e
- cp $4
+ cp CH4
jr nz, .asm_9a2b
ld a, $8
- ld [$ff10], a
+ ld [rNR10], a ; sweep off
.asm_9a2b
ld a, c
and a
- jp z, Audio1_9a8f
+ jp z, .playSoundCommon
dec c
- jp .asm_9967
+ jp .sfxChannelLoop
-Audio1_9a34: ; 0x9a34
+.stopAllAudio
ld a, $80
- ld [$ff26], a
- ld [$ff1a], a
+ ld [rNR52], a ; sound hardware on
+ ld [rNR30], a ; wave playback on
xor a
- ld [$ff25], a
- ld [$ff1c], a
+ ld [rNR51], a ; no sound output
+ ld [rNR32], a ; mute channel 3 (wave channel)
ld a, $8
- ld [$ff10], a
- ld [$ff12], a
- ld [$ff17], a
- ld [$ff21], a
+ ld [rNR10], a ; sweep off
+ ld [rNR12], a ; mute channel 1 (pulse channel 1)
+ ld [rNR22], a ; mute channel 2 (pulse channel 2)
+ ld [rNR42], a ; mute channel 4 (noise channel)
ld a, $40
- ld [$ff14], a
- ld [$ff19], a
- ld [$ff23], a
+ ld [rNR14], a ; counter mode
+ ld [rNR24], a
+ ld [rNR44], a
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a ; full volume
xor a
- ld [wc000], a
- ld [wc003], a
- ld [wc002], a
- ld [wc0e9], a
- ld [wc0eb], a
- ld [wc0e6], a
- ld [wc0e7], a
+ ld [wUnusedC000], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
+ ld [wMuteAudioAndPauseMusic], a
+ ld [wMusicTempo + 1], a
+ ld [wSfxTempo + 1], a
+ ld [wMusicWaveInstrument], a
+ ld [wSfxWaveInstrument], a
ld d, $a0
- ld hl, wc006
- call FillAudioRAM1
+ ld hl, wChannelCommandPointers
+ call .FillMem
ld a, $1
ld d, $18
- ld hl, wc0b6
- call FillAudioRAM1
- ld [wc0e8], a
- ld [wc0ea], a
+ ld hl, wChannelNoteDelayCounters
+ call .FillMem
+ ld [wMusicTempo], a
+ ld [wSfxTempo], a
ld a, $ff
- ld [wc004], a
+ ld [wStereoPanning], a
ret
; fills d bytes at hl with a
-FillAudioRAM1: ; 0x9a89
+.FillMem
ld b, d
.loop
ld [hli], a
@@ -1556,11 +1600,11 @@
jr nz, .loop
ret
-Audio1_9a8f: ; 0x9a8f
- ld a, [wc001]
+.playSoundCommon
+ ld a, [wSoundID]
ld l, a
ld e, a
- ld h, $0
+ ld h, 0
ld d, h
add hl, hl
add hl, de
@@ -1568,7 +1612,7 @@
add hl, de
ld e, l
ld d, h
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld a, [de] ; get channel number
ld b, a
rlca
@@ -1580,31 +1624,31 @@
ld b, c
inc b
inc de
- ld c, $0
-.asm_9ab1
+ ld c, 0
+.commandPointerLoop
cp c
- jr z, .asm_9ab9
+ jr z, .next
inc c
inc hl
inc hl
- jr .asm_9ab1
-.asm_9ab9
+ jr .commandPointerLoop
+.next
push hl
push bc
push af
- ld b, $0
+ ld b, 0
ld c, a
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, bc
- ld a, [wc001]
+ ld a, [wSoundID]
ld [hl], a
pop af
- cp $3
- jr c, .asm_9ad2
- ld hl, wc02e
+ cp CH3
+ jr c, .skipSettingFlag
+ ld hl, wChannelFlags1
add hl, bc
- set 2, [hl]
-.asm_9ad2
+ set BIT_NOISE_OR_SFX, [hl]
+.skipSettingFlag
pop bc
pop hl
ld a, [de] ; get channel pointer
@@ -1619,52 +1663,53 @@
and a
ld a, [de]
inc de
- jr nz, .asm_9ab1
- ld a, [wc001]
- cp $14
+ jr nz, .commandPointerLoop
+ ld a, [wSoundID]
+ cp CRY_SFX_START
jr nc, .asm_9aeb
- jr .asm_9b15
+ jr .done
.asm_9aeb
- ld a, [wc001]
- cp $86
- jr z, .asm_9b15
- jr c, .asm_9af6
- jr .asm_9b15
-.asm_9af6
- ld hl, wc02a
+ ld a, [wSoundID]
+ cp CRY_SFX_END
+ jr z, .done
+ jr c, .cry
+ jr .done
+.cry
+ ld hl, wChannelSoundIDs + CH4
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
- ld hl, wc012 ; sfx noise channel pointer
- ld de, Noise1_endchannel
+ ld hl, wChannelCommandPointers + CH6 * 2 ; sfx wave channel pointer
+ ld de, Audio1_CryEndchannel
ld [hl], e
inc hl
ld [hl], d ; overwrite pointer to point to endchannel
- ld a, [wc005]
+ ld a, [wSavedVolume]
and a
- jr nz, .asm_9b15
- ld a, [$ff24]
- ld [wc005], a
+ jr nz, .done
+ ld a, [rNR50]
+ ld [wSavedVolume], a
ld a, $77
- ld [$ff24], a
-.asm_9b15
+ ld [rNR50], a ; full volume
+.done
ret
-Noise1_endchannel: ; 0x9b16
+Audio1_CryEndchannel: ; 0x9b16
endchannel
-Unknown_9b17: ; 0x9b17
- db $10, $15, $1A, $1F ; channels 0-3
- db $10, $15, $1A, $1F ; channels 4-7
+Audio1_HWChannelBaseAddresses: ; 0x9b17
+; 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
-Unknown_9b1f: ; 0x9b1f
- db $EE, $DD, $BB, $77 ; channels 0-3
- db $EE, $DD, $BB, $77 ; channels 4-7
+Audio1_HWChannelDisableMasks: ; 0x9b1f
+ 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
-Unknown_9b27: ; 0x9b27
- db $11, $22, $44, $88 ; channels 0-3
- db $11, $22, $44, $88 ; channels 4-7
+Audio1_HWChannelEnableMasks: ; 0x9b27
+ 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
Audio1_Pitches: ; 0x9b2f
dw $F82C ; C_
--- a/audio/engine_2.asm
+++ b/audio/engine_2.asm
@@ -4,7 +4,7 @@
ld c, CH0
.loop
ld b, $0
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, bc
ld a, [hl]
and a
@@ -12,18 +12,18 @@
ld a, c
cp CH4
jr nc, .applyAffects ; if sfx channel
- ld a, [wc002]
+ ld a, [wMuteAudioAndPauseMusic]
and a
jr z, .applyAffects
bit 7, a
jr nz, .nextChannel
set 7, a
- ld [wc002], a
+ ld [wMuteAudioAndPauseMusic], a
xor a
- ld [$ff25], a
- ld [$ff1a], a
+ ld [rNR51], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
jr .nextChannel
.applyAffects
call Audio2_ApplyMusicAffects
@@ -36,7 +36,7 @@
; this routine checks flags for music effects currently applied
; to the channel and calls certain functions based on flags.
-; known flags for wc02e:
+; known flags for wChannelFlags1:
; 0: toggleperfectpitch has been used
; 1: call has been used
; 3: a toggle used only by this routine for vibrato
@@ -44,7 +44,7 @@
; 6: dutycycle flag
Audio2_ApplyMusicAffects: ; 218ae (8:58ae)
ld b, $0
- ld hl, wc0b6 ; delay until next note
+ ld hl, wChannelNoteDelayCounters ; delay until next note
add hl, bc
ld a, [hl]
cp $1 ; if the delay is 1, play next note
@@ -54,7 +54,7 @@
ld a, c
cp CH4
jr nc, .startChecks ; if a sfx channel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
@@ -61,7 +61,7 @@
jr z, .startChecks
ret
.startChecks
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 6, [hl] ; dutycycle
jr z, .checkForExecuteMusic
@@ -68,22 +68,22 @@
call Audio2_ApplyDutyCycle
.checkForExecuteMusic
ld b, $0
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, .checkForPitchBend
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 2, [hl]
jr nz, .disablePitchBendVibrato
.checkForPitchBend
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 4, [hl] ; pitchbend
jr z, .checkVibratoDelay
jp Audio2_ApplyPitchBend
.checkVibratoDelay
- ld hl, wc04e ; vibrato delay
+ ld hl, wChannelVibratoDelayCounters ; vibrato delay
add hl, bc
ld a, [hl]
and a ; check if delay is over
@@ -92,7 +92,7 @@
.disablePitchBendVibrato
ret
.checkForVibrato
- ld hl, wc056 ; vibrato rate
+ ld hl, wChannelVibratoExtents ; vibrato rate
add hl, bc
ld a, [hl]
and a
@@ -100,7 +100,7 @@
ret ; no vibrato
.vibrato
ld d, a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, bc
ld a, [hl]
and $f
@@ -113,10 +113,10 @@
swap [hl]
or [hl]
ld [hl], a ; reset the vibrato value and start again
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
add hl, bc
ld e, [hl] ; get note pitch
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 3, [hl] ; this is the only code that sets/resets bit three so
jr z, .unset ; it continuously alternates which path it takes
@@ -149,13 +149,13 @@
; like tempo changes, duty changes etc. and doesn't return
; until the first note is reached
Audio2_PlayNextNote: ; 21946 (8:5946)
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, bc
ld a, [hl]
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, bc
ld [hl], a
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
res 4, [hl]
res 5, [hl]
@@ -175,7 +175,7 @@
cp $ff ; is this command an endchannel?
jp nz, Audio2_callchannel ; no
ld b, $0 ; yes
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 1, [hl]
jr nz, .returnFromCall
@@ -185,22 +185,22 @@
jr .asm_219c0
.noiseOrSfxChannel
res 2, [hl]
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
res 0, [hl]
cp CH6
jr nz, .notSfxChannel3
ld a, $0
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
.notSfxChannel3
jr nz, .asm_219a3
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr z, .asm_219a3
xor a
- ld [wc003], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
jr .asm_219c0
.asm_219a3
jr .asm_219c9
@@ -210,10 +210,10 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
push hl ; store current channel address
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld e, l
ld d, h
@@ -227,16 +227,16 @@
.asm_219c0
ld hl, Unknown_222de
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
and [hl]
- ld [$ff25], a
+ ld [rNR51], a
.asm_219c9
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $14
jr nc, .asm_219d2
jr .asm_219ef
.asm_219d2
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $86
jr z, .asm_219ef
jr c, .asm_219dd
@@ -248,12 +248,12 @@
call Audio2_21e6d
ret c
.asm_219e6
- ld a, [wc005]
- ld [$ff24], a
+ ld a, [wSavedVolume]
+ ld [rNR50], a
xor a
- ld [wc005], a
+ ld [wSavedVolume], a
.asm_219ef
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, bc
ld [hl], b
ret
@@ -272,10 +272,10 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
push hl
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld e, l
ld d, h
@@ -290,7 +290,7 @@
inc hl
ld [hl], d ; overwrite current address with pointer
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 1, [hl] ; set the call flag
jp Audio2_endchannel
@@ -303,7 +303,7 @@
and a
jr z, .infiniteLoop
ld b, $0
- ld hl, wc0be
+ ld hl, wChannelLoopCounters
add hl, bc
ld a, [hl]
cp e
@@ -326,7 +326,7 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
pop af
ld [hli], a
@@ -340,7 +340,7 @@
ld a, d ; yes
and $f
ld b, $0
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, bc
ld [hl], a ; store low nibble as speed
ld a, c
@@ -353,10 +353,10 @@
jr z, .musicChannel3
cp CH6
jr nz, .notChannel3
- ld hl, wc0e7
+ ld hl, wSfxWaveInstrument
jr .sfxChannel3
.musicChannel3
- ld hl, wc0e6
+ ld hl, wMusicWaveInstrument
.sfxChannel3
ld a, d
and $f
@@ -371,7 +371,7 @@
; else, store volume (high nibble) and fade (low nibble)
.notChannel3
ld b, $0
- ld hl, wc0de
+ ld hl, wChannelVolumes
add hl, bc
ld [hl], d
.noiseChannel
@@ -382,11 +382,11 @@
cp $e8 ; is this command a toggleperfectpitch?
jr nz, Audio2_vibrato ; no
ld b, $0 ; yes
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
ld a, [hl]
xor $1
- ld [hl], a ; flip bit 0 of wc02e
+ ld [hl], a ; flip bit 0 of wChannelFlags1
jp Audio2_endchannel
Audio2_vibrato: ; 21ab6 (8:5ab6)
@@ -394,10 +394,10 @@
jr nz, Audio2_pitchbend ; no
call Audio2_GetNextMusicByte ; yes
ld b, $0
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, bc
ld [hl], a ; store delay
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, bc
ld [hl], a ; store delay
call Audio2_GetNextMusicByte
@@ -405,7 +405,7 @@
and $f0
swap a
ld b, $0
- ld hl, wc056
+ ld hl, wChannelVibratoExtents
add hl, bc
srl a
ld e, a
@@ -416,7 +416,7 @@
ld a, d
and $f
ld d, a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, bc
swap a
or d
@@ -428,7 +428,7 @@
jr nz, Audio2_duty ; no
call Audio2_GetNextMusicByte ; yes
ld b, $0
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
ld [hl], a ; store first param
call Audio2_GetNextMusicByte
@@ -440,14 +440,14 @@
and $f
call Audio2_22017
ld b, $0
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld [hl], d ; store unknown part of second param
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld [hl], e ; store unknown part of second param
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 4, [hl] ; set pitchbend flag
call Audio2_GetNextMusicByte
@@ -462,7 +462,7 @@
rrca
and $c0
ld b, $0
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld [hl], a ; store duty
jp Audio2_endchannel
@@ -474,25 +474,25 @@
cp CH4
jr nc, .sfxChannel
call Audio2_GetNextMusicByte
- ld [wc0e8], a ; store first param
+ ld [wMusicTempo], a ; store first param
call Audio2_GetNextMusicByte
- ld [wc0e9], a ; store second param
+ ld [wMusicTempo + 1], a ; store second param
xor a
- ld [wc0ce], a ; clear RAM
- ld [wc0cf], a
- ld [wc0d0], a
- ld [wc0d1], a
+ ld [wChannelNoteDelayCountersFractionalPart], a ; clear RAM
+ ld [wChannelNoteDelayCountersFractionalPart + 1], a
+ ld [wChannelNoteDelayCountersFractionalPart + 2], a
+ ld [wChannelNoteDelayCountersFractionalPart + 3], a
jr .musicChannelDone
.sfxChannel
call Audio2_GetNextMusicByte
- ld [wc0ea], a ; store first param
+ ld [wSfxTempo], a ; store first param
call Audio2_GetNextMusicByte
- ld [wc0eb], a ; store second param
+ ld [wSfxTempo + 1], a ; store second param
xor a
- ld [wc0d2], a ; clear RAM
- ld [wc0d3], a
- ld [wc0d4], a
- ld [wc0d5], a
+ ld [wChannelNoteDelayCountersFractionalPart + 4], a ; clear RAM
+ ld [wChannelNoteDelayCountersFractionalPart + 5], a
+ ld [wChannelNoteDelayCountersFractionalPart + 6], a
+ ld [wChannelNoteDelayCountersFractionalPart + 7], a
.musicChannelDone
jp Audio2_endchannel
@@ -500,7 +500,7 @@
cp $ee ; is this command a stereopanning?
jr nz, Audio2_unknownmusic0xef ; no
call Audio2_GetNextMusicByte ; yes
- ld [wc004], a ; store panning
+ ld [wStereoPanning], a ; store panning
jp Audio2_endchannel
; this appears to never be used
@@ -509,15 +509,15 @@
jr nz, Audio2_dutycycle ; no
call Audio2_GetNextMusicByte ; yes
push bc
- call Audio2_22035
+ call Audio2_PlaySound
pop bc
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr nz, .skip
- ld a, [wc02d]
- ld [wc003], a
+ ld a, [wChannelSoundIDs + CH7]
+ ld [wDisableChannelOutputWhenSfxEnds], a
xor a
- ld [wc02d], a
+ ld [wChannelSoundIDs + CH7], a
.skip
jp Audio2_endchannel
@@ -526,14 +526,14 @@
jr nz, Audio2_volume ; no
call Audio2_GetNextMusicByte ; yes
ld b, $0
- ld hl, wc046
+ ld hl, wChannelDutyCycles
add hl, bc
ld [hl], a ; store full cycle
and $c0
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld [hl], a ; store first duty
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 6, [hl] ; set dutycycle flag
jp Audio2_endchannel
@@ -542,7 +542,7 @@
cp $f0 ; is this command a volume?
jr nz, Audio2_executemusic ; no
call Audio2_GetNextMusicByte ; yes
- ld [$ff24], a ; store volume
+ ld [rNR50], a ; store volume
jp Audio2_endchannel
Audio2_executemusic: ; 21bd1 (8:5bd1)
@@ -549,7 +549,7 @@
cp $f8 ; is this command an executemusic?
jr nz, Audio2_octave ; no
ld b, $0 ; yes
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
set 0, [hl]
jp Audio2_endchannel
@@ -558,7 +558,7 @@
and $f0
cp $e0 ; is this command an octave?
jr nz, Audio2_unknownsfx0x20 ; no
- ld hl, wc0d6 ; yes
+ ld hl, wChannelOctaves ; yes
ld b, $0
add hl, bc
ld a, d
@@ -573,7 +573,7 @@
cp CH3 ; is this a noise or sfx channel?
jr c, Audio2_unknownsfx0x10 ; no
ld b, $0
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, Audio2_unknownsfx0x10 ; no
@@ -580,7 +580,7 @@
call Audio2_notelength
ld d, a
ld b, $0
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld a, [hl]
or d
@@ -619,12 +619,12 @@
cp $10 ; is this command a unknownsfx0x10?
jr nz, Audio2_note ; no
ld b, $0
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, Audio2_note ; no
call Audio2_GetNextMusicByte ; yes
- ld [$ff10], a
+ ld [rNR10], a
jp Audio2_endchannel
Audio2_note: ; 21c5c (8:5c5c)
@@ -654,11 +654,11 @@
call Audio2_GetNextMusicByte ; get dnote instrument
asm_21c7e
ld d, a
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr nz, .asm_21c89
ld a, d
- call Audio2_22035
+ call Audio2_PlaySound
.asm_21c89
pop bc
pop de
@@ -671,7 +671,7 @@
ld b, $0
ld e, a ; store note length (in 16ths)
ld d, b
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, bc
ld a, [hl]
ld l, b
@@ -679,9 +679,9 @@
ld a, c
cp CH4
jr nc, .sfxChannel
- ld a, [wc0e8]
+ ld a, [wMusicTempo]
ld d, a
- ld a, [wc0e9]
+ ld a, [wMusicTempo + 1]
ld e, a
jr .skip
.sfxChannel
@@ -690,31 +690,31 @@
cp CH7
jr z, .skip ; if noise channel
call Audio2_21e2f
- ld a, [wc0ea]
+ ld a, [wSfxTempo]
ld d, a
- ld a, [wc0eb]
+ ld a, [wSfxTempo + 1]
ld e, a
.skip
ld a, l
ld b, $0
- ld hl, wc0ce
+ ld hl, wChannelNoteDelayCountersFractionalPart
add hl, bc
ld l, [hl]
call Audio2_22006
ld e, l
ld d, h
- ld hl, wc0ce
+ ld hl, wChannelNoteDelayCountersFractionalPart
add hl, bc
ld [hl], e
ld a, d
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld [hl], a
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, Audio2_notepitch
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 2, [hl]
jr z, Audio2_notepitch
@@ -729,7 +729,7 @@
ld a, c
cp CH4
jr nc, .sfxChannel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
@@ -745,9 +745,9 @@
ld b, $0
ld hl, Unknown_222de
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
and [hl]
- ld [$ff25], a
+ ld [rNR51], a
jr .done
.notSfxChannel3
ld b, $2
@@ -762,12 +762,12 @@
.notRest
swap a
ld b, $0
- ld hl, wc0d6
+ ld hl, wChannelOctaves
add hl, bc
ld b, [hl]
call Audio2_22017
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 4, [hl]
jr z, .asm_21d39
@@ -777,7 +777,7 @@
ld a, c
cp CH4
jr nc, .skip ; if sfx channel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
ld d, $0
ld e, a
add hl, de
@@ -790,7 +790,7 @@
ret
.skip
ld b, $0
- ld hl, wc0de
+ ld hl, wChannelVolumes
add hl, bc
ld d, [hl]
ld b, $2
@@ -800,7 +800,7 @@
call Audio2_21d79
pop de
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 0, [hl] ; has toggleperfectpitch been used?
jr z, .skip2
@@ -808,7 +808,7 @@
jr nc, .skip2
inc d
.skip2
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
add hl, bc
ld [hl], e
call Audio2_21dcc
@@ -818,7 +818,7 @@
ld b, $0
ld hl, Unknown_222e6
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
or [hl]
ld d, a
ld a, c
@@ -826,18 +826,18 @@
jr z, .sfxNoiseChannel
cp CH4
jr nc, .skip ; if sfx channel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
jr nz, .skip
.sfxNoiseChannel
- ld a, [wc004]
+ ld a, [wStereoPanning]
ld hl, Unknown_222e6
add hl, bc
and [hl]
ld d, a
- ld a, [$ff25]
+ ld a, [rNR51]
ld hl, Unknown_222de
add hl, bc
and [hl]
@@ -845,12 +845,12 @@
ld d, a
.skip
ld a, d
- ld [$ff25], a
+ ld [rNR51], a
ret
Audio2_21daa: ; 21daa (8:5daa)
ld b, $0
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld d, [hl]
ld a, c
@@ -861,7 +861,7 @@
ld a, d
and $3f
ld d, a
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld a, [hl]
or d
@@ -881,10 +881,10 @@
; fall through
.channel3
push de
- ld de, wc0e6
+ ld de, wMusicWaveInstrument
cp CH2
jr z, .musicChannel3
- ld de, wc0e7
+ ld de, wSfxWaveInstrument
.musicChannel3
ld a, [de]
add a
@@ -898,7 +898,7 @@
ld hl, $ff30
ld b, $f
ld a, $0
- ld [$ff1a], a
+ ld [rNR30], a
.loop
ld a, [de]
inc de
@@ -908,7 +908,7 @@
and a
jr nz, .loop
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
pop de
.notSfxChannel3
ld a, d
@@ -935,9 +935,9 @@
bit 7, a
jr z, .asm_21e2e
xor a
- ld [wc0f1], a
+ ld [wFrequencyModifier], a
ld a, $80
- ld [wc0f2], a
+ ld [wTempoModifier], a
.asm_21e2e
ret
@@ -948,20 +948,20 @@
jr nc, .asm_21e4c
.asm_21e39
ld d, $0
- ld a, [wc0f2]
+ ld a, [wTempoModifier]
add $80
jr nc, .asm_21e43
inc d
.asm_21e43
- ld [wc0eb], a
+ ld [wSfxTempo + 1], a
ld a, d
- ld [wc0ea], a
+ ld [wSfxTempo], a
jr .asm_21e55
.asm_21e4c
xor a
- ld [wc0eb], a
+ ld [wSfxTempo + 1], a
ld a, $1
- ld [wc0ea], a
+ ld [wSfxTempo], a
.asm_21e55
ret
@@ -971,7 +971,7 @@
call Audio2_21e9f
jr nc, .asm_21e6c
.asm_21e60
- ld a, [wc0f1]
+ ld a, [wFrequencyModifier]
add e
jr nc, .asm_21e67
inc d
@@ -987,7 +987,7 @@
Audio2_21e6d: ; 21e6d (8:5e6d)
call Audio2_21e8b
jr nc, .asm_21e88
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld e, c
ld d, $0
sla e
@@ -1008,7 +1008,7 @@
ret
Audio2_21e8b: ; 21e8b (8:5e8b)
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $14
jr nc, .asm_21e94
jr .asm_21e9a
@@ -1025,9 +1025,9 @@
ret
Audio2_21e9f: ; 21e9f (8:5e9f)
- ld a, [wc02d]
+ ld a, [wChannelSoundIDs + CH7]
ld b, a
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
or b
cp $9d
jr nc, .asm_21ead
@@ -1045,17 +1045,17 @@
ret
Audio2_ApplyPitchBend: ; 21eb8 (8:5eb8)
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 5, [hl]
jp nz, .asm_21eff
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld e, [hl]
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld l, [hl]
ld h, b
@@ -1062,10 +1062,10 @@
add hl, de
ld d, h
ld e, l
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, bc
push hl
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld a, [hl]
pop hl
@@ -1077,13 +1077,13 @@
ld a, $0
adc d
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, [hl]
cp d
jp c, .asm_21f45
jr nz, .asm_21f32
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, [hl]
cp e
@@ -1090,13 +1090,13 @@
jp c, .asm_21f45
jr .asm_21f32
.asm_21eff
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld a, [hl]
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld e, [hl]
sub e
@@ -1104,7 +1104,7 @@
ld a, d
sbc b
ld d, a
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld a, [hl]
add a
@@ -1115,22 +1115,22 @@
ld a, d
sbc b
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, d
cp [hl]
jr c, .asm_21f45
jr nz, .asm_21f32
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, e
cp [hl]
jr c, .asm_21f45
.asm_21f32
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld [hl], e
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld [hl], d
ld b, $3
@@ -1140,7 +1140,7 @@
ld [hl], d
ret
.asm_21f45
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
res 4, [hl]
res 5, [hl]
@@ -1147,16 +1147,16 @@
ret
Audio2_21f4e: ; 21f4e (8:5f4e)
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld [hl], d
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld [hl], e
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld a, [hl]
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
sub [hl]
jr nc, .asm_21f66
@@ -1163,7 +1163,7 @@
ld a, $1
.asm_21f66
ld [hl], a
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, e
sub [hl]
@@ -1170,24 +1170,24 @@
ld e, a
ld a, d
sbc b
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
sub [hl]
jr c, .asm_21f82
ld d, a
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 5, [hl]
jr .asm_21fa5
.asm_21f82
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld e, [hl]
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, [hl]
sub e
@@ -1195,17 +1195,17 @@
ld a, d
sbc b
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, [hl]
sub d
ld d, a
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
res 5, [hl]
.asm_21fa5
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
.asm_21fa9
inc b
@@ -1224,13 +1224,13 @@
add [hl]
ld d, b
ld b, $0
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld [hl], d
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld [hl], a
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, bc
ld [hl], a
ret
@@ -1237,7 +1237,7 @@
Audio2_ApplyDutyCycle: ; 21fcc (8:5fcc)
ld b, $0
- ld hl, wc046
+ ld hl, wChannelDutyCycles
add hl, bc
ld a, [hl]
rlca
@@ -1258,7 +1258,7 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
ld a, [hli]
ld e, a
@@ -1325,8 +1325,8 @@
ld d, a
ret
-Audio2_22035:: ; 22035 (8:6035)
- ld [wc001], a
+Audio2_PlaySound:: ; 22035 (8:6035)
+ ld [wSoundID], a
cp $ff
jp z, Audio2_221f3
cp $e9
@@ -1337,75 +1337,75 @@
jp nc, Audio2_2210d
.asm_2204c
xor a
- ld [wc000], a
- ld [wc003], a
- ld [wc0e9], a
- ld [wc0e6], a
- ld [wc0e7], a
+ ld [wUnusedC000], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
+ ld [wMusicTempo + 1], a
+ ld [wMusicWaveInstrument], a
+ ld [wSfxWaveInstrument], a
ld d, $8
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
call FillAudioRAM2
- ld hl, wc006
+ ld hl, wChannelCommandPointers
call FillAudioRAM2
ld d, $4
- ld hl, wc026
+ ld hl, wChannelSoundIDs
call FillAudioRAM2
- ld hl, wc02e
+ ld hl, wChannelFlags1
call FillAudioRAM2
- ld hl, wc03e
+ ld hl, wChannelDuties
call FillAudioRAM2
- ld hl, wc046
+ ld hl, wChannelDutyCycles
call FillAudioRAM2
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
call FillAudioRAM2
- ld hl, wc056
+ ld hl, wChannelVibratoExtents
call FillAudioRAM2
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
call FillAudioRAM2
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
call FillAudioRAM2
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
call FillAudioRAM2
- ld hl, wc036
+ ld hl, wChannelFlags2
call FillAudioRAM2
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
call FillAudioRAM2
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
call FillAudioRAM2
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
call FillAudioRAM2
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
call FillAudioRAM2
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
call FillAudioRAM2
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
call FillAudioRAM2
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
call FillAudioRAM2
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
call FillAudioRAM2
ld a, $1
- ld hl, wc0be
+ ld hl, wChannelLoopCounters
call FillAudioRAM2
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
call FillAudioRAM2
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
call FillAudioRAM2
- ld [wc0e8], a
+ ld [wMusicTempo], a
ld a, $ff
- ld [wc004], a
+ ld [wStereoPanning], a
xor a
- ld [$ff24], a
+ ld [rNR50], a
ld a, $8
- ld [$ff10], a
+ ld [rNR10], a
ld a, $0
- ld [$ff25], a
+ ld [rNR51], a
xor a
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
jp Audio2_2224e
Audio2_2210d: ; 2210d (8:610d)
@@ -1418,9 +1418,9 @@
ld de, SFX_Headers_2
add hl, de
ld a, h
- ld [wc0ec], a
+ ld [wSfxHeaderPointer], a
ld a, l
- ld [wc0ed], a
+ ld [wSfxHeaderPointer + 1], a
ld a, [hl]
and $c0
rlca
@@ -1433,9 +1433,9 @@
add c
ld c, a
ld b, $0
- ld a, [wc0ec]
+ ld a, [wSfxHeaderPointer]
ld h, a
- ld a, [wc0ed]
+ ld a, [wSfxHeaderPointer + 1]
ld l, a
add hl, bc
ld c, d
@@ -1443,7 +1443,7 @@
and $f
ld e, a
ld d, $0
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, de
ld a, [hl]
and a
@@ -1451,7 +1451,7 @@
ld a, e
cp $7
jr nz, .asm_22159
- ld a, [wc001]
+ ld a, [wSoundID]
cp $14
jr nc, .asm_22152
ret
@@ -1461,7 +1461,7 @@
jr z, .asm_22162
jr c, .asm_22162
.asm_22159
- ld a, [wc001]
+ ld a, [wSoundID]
cp [hl]
jr z, .asm_22162
jr c, .asm_22162
@@ -1474,77 +1474,77 @@
add hl, hl
ld d, h
ld e, l
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld [hli], a
ld [hl], a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
ld [hli], a
ld [hl], a
pop de
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, de
ld [hl], a
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, de
ld [hl], a
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, de
ld [hl], a
- ld hl, wc046
+ ld hl, wChannelDutyCycles
add hl, de
ld [hl], a
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, de
ld [hl], a
- ld hl, wc056
+ ld hl, wChannelVibratoExtents
add hl, de
ld [hl], a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, de
ld [hl], a
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, de
ld [hl], a
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, de
ld [hl], a
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, de
ld [hl], a
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, de
ld [hl], a
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, de
ld [hl], a
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, de
ld [hl], a
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, de
ld [hl], a
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, de
ld [hl], a
ld a, $1
- ld hl, wc0be
+ ld hl, wChannelLoopCounters
add hl, de
ld [hl], a
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, de
ld [hl], a
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, de
ld [hl], a
ld a, e
@@ -1551,7 +1551,7 @@
cp $4
jr nz, .asm_221ea
ld a, $8
- ld [$ff10], a
+ ld [rNR10], a
.asm_221ea
ld a, c
and a
@@ -1561,41 +1561,41 @@
Audio2_221f3: ; 221f3 (8:61f3)
ld a, $80
- ld [$ff26], a
- ld [$ff1a], a
+ ld [rNR52], a
+ ld [rNR30], a
xor a
- ld [$ff25], a
- ld [$ff1c], a
+ ld [rNR51], a
+ ld [rNR32], a
ld a, $8
- ld [$ff10], a
- ld [$ff12], a
- ld [$ff17], a
- ld [$ff21], a
+ ld [rNR10], a
+ ld [rNR12], a
+ ld [rNR22], a
+ ld [rNR42], a
ld a, $40
- ld [$ff14], a
- ld [$ff19], a
- ld [$ff23], a
+ ld [rNR14], a
+ ld [rNR24], a
+ ld [rNR44], a
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
xor a
- ld [wc000], a
- ld [wc003], a
- ld [wc002], a
- ld [wc0e9], a
- ld [wc0eb], a
- ld [wc0e6], a
- ld [wc0e7], a
+ ld [wUnusedC000], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
+ ld [wMuteAudioAndPauseMusic], a
+ ld [wMusicTempo + 1], a
+ ld [wSfxTempo + 1], a
+ ld [wMusicWaveInstrument], a
+ ld [wSfxWaveInstrument], a
ld d, $a0
- ld hl, wc006
+ ld hl, wChannelCommandPointers
call FillAudioRAM2
ld a, $1
ld d, $18
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
call FillAudioRAM2
- ld [wc0e8], a
- ld [wc0ea], a
+ ld [wMusicTempo], a
+ ld [wSfxTempo], a
ld a, $ff
- ld [wc004], a
+ ld [wStereoPanning], a
ret
; fills d bytes at hl with a
@@ -1608,7 +1608,7 @@
ret
Audio2_2224e: ; 2224e (8:624e)
- ld a, [wc001]
+ ld a, [wSoundID]
ld l, a
ld e, a
ld h, $0
@@ -1619,7 +1619,7 @@
add hl, de
ld e, l
ld d, h
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld a, [de] ; get channel number
ld b, a
rlca
@@ -1645,14 +1645,14 @@
push af
ld b, $0
ld c, a
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, bc
- ld a, [wc001]
+ ld a, [wSoundID]
ld [hl], a
pop af
cp $3
jr c, .asm_22291
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 2, [hl]
.asm_22291
@@ -1671,34 +1671,34 @@
ld a, [de]
inc de
jr nz, .asm_22270
- ld a, [wc001]
+ ld a, [wSoundID]
cp $14
jr nc, .asm_222aa
jr .asm_222d4
.asm_222aa
- ld a, [wc001]
+ ld a, [wSoundID]
cp $86
jr z, .asm_222d4
jr c, .asm_222b5
jr .asm_222d4
.asm_222b5
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
- ld hl, wc012 ; sfx noise channel pointer
+ ld hl, wChannelCommandPointers + CH6 * 2 ; sfx noise channel pointer
ld de, Noise2_endchannel
ld [hl], e
inc hl
ld [hl], d ; overwrite pointer to point to endchannel
- ld a, [wc005]
+ ld a, [wSavedVolume]
and a
jr nz, .asm_222d4
- ld a, [$ff24]
- ld [wc005], a
+ ld a, [rNR50]
+ ld [wSavedVolume], a
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
.asm_222d4
ret
--- a/audio/engine_3.asm
+++ b/audio/engine_3.asm
@@ -4,7 +4,7 @@
ld c, CH0
.loop
ld b, $0
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, bc
ld a, [hl]
and a
@@ -12,18 +12,18 @@
ld a, c
cp CH4
jr nc, .applyAffects ; if sfx channel
- ld a, [wc002]
+ ld a, [wMuteAudioAndPauseMusic]
and a
jr z, .applyAffects
bit 7, a
jr nz, .nextChannel
set 7, a
- ld [wc002], a
+ ld [wMuteAudioAndPauseMusic], a
xor a
- ld [$ff25], a
- ld [$ff1a], a
+ ld [rNR51], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
jr .nextChannel
.applyAffects
call Audio3_ApplyMusicAffects
@@ -36,7 +36,7 @@
; this routine checks flags for music effects currently applied
; to the channel and calls certain functions based on flags.
-; known flags for wc02e:
+; known flags for wChannelFlags1:
; 0: toggleperfectpitch has been used
; 1: call has been used
; 3: a toggle used only by this routine for vibrato
@@ -44,7 +44,7 @@
; 6: dutycycle flag
Audio3_ApplyMusicAffects: ; 7d1ac (1f:51ac)
ld b, $0
- ld hl, wc0b6 ; delay until next note
+ ld hl, wChannelNoteDelayCounters ; delay until next note
add hl, bc
ld a, [hl]
cp $1 ; if delay is 1, play next note
@@ -54,7 +54,7 @@
ld a, c
cp CH4
jr nc, .startChecks ; if a sfx channel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
@@ -61,7 +61,7 @@
jr z, .startChecks
ret
.startChecks
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 6, [hl] ; dutycycle
jr z, .checkForExecuteMusic
@@ -68,22 +68,22 @@
call Audio3_ApplyDutyCycle
.checkForExecuteMusic
ld b, $0
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, .checkForPitchBend
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 2, [hl]
jr nz, .disablePitchBendVibrato
.checkForPitchBend
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 4, [hl] ; pitchbend
jr z, .checkVibratoDelay
jp Audio3_ApplyPitchBend
.checkVibratoDelay
- ld hl, wc04e ; vibrato delay
+ ld hl, wChannelVibratoDelayCounters ; vibrato delay
add hl, bc
ld a, [hl]
and a ; check if delay is over
@@ -92,7 +92,7 @@
.disablePitchBendVibrato
ret
.checkForVibrato
- ld hl, wc056 ; vibrato rate
+ ld hl, wChannelVibratoExtents ; vibrato rate
add hl, bc
ld a, [hl]
and a
@@ -100,7 +100,7 @@
ret ; no vibrato
.vibrato
ld d, a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, bc
ld a, [hl]
and $f
@@ -113,10 +113,10 @@
swap [hl]
or [hl]
ld [hl], a ; reset the vibrato value and start again
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
add hl, bc
ld e, [hl] ; get note pitch
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 3, [hl] ; this is the only code that sets/resets bit three so
jr z, .unset ; it continuously alternates which path it takes
@@ -149,13 +149,13 @@
; like tempo changes, duty changes etc. and doesn't return
; until the first note is reached
Audio3_PlayNextNote: ; 7d244 (1f:5244)
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, bc
ld a, [hl]
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, bc
ld [hl], a
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
res 4, [hl]
res 5, [hl]
@@ -168,7 +168,7 @@
cp $ff ; is this command an endchannel?
jp nz, Audio3_callchannel ; no
ld b, $0 ; yes
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 1, [hl]
jr nz, .returnFromCall
@@ -178,22 +178,22 @@
jr .asm_7d2b3
.noiseOrSfxChannel
res 2, [hl]
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
res 0, [hl]
cp CH6
jr nz, .notSfxChannel3
ld a, $0
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
.notSfxChannel3
jr nz, .asm_7d296
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr z, .asm_7d296
xor a
- ld [wc003], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
jr .asm_7d2b3
.asm_7d296
jr .asm_7d2bc
@@ -203,10 +203,10 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
push hl ; store current channel address
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld e, l
ld d, h
@@ -220,16 +220,16 @@
.asm_7d2b3
ld hl, Unknown_7db93
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
and [hl]
- ld [$ff25], a
+ ld [rNR51], a
.asm_7d2bc
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $14
jr nc, .asm_7d2c5
jr .asm_7d2e2
.asm_7d2c5
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $86
jr z, .asm_7d2e2
jr c, .asm_7d2d0
@@ -241,12 +241,12 @@
call Audio3_7d73b
ret c
.asm_7d2d9
- ld a, [wc005]
- ld [$ff24], a
+ ld a, [wSavedVolume]
+ ld [rNR50], a
xor a
- ld [wc005], a
+ ld [wSavedVolume], a
.asm_7d2e2
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, bc
ld [hl], b
ret
@@ -265,10 +265,10 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
push hl
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld e, l
ld d, h
@@ -283,7 +283,7 @@
inc hl
ld [hl], d ; overwrite current address with pointer
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 1, [hl] ; set the call flag
jp Audio3_endchannel
@@ -296,7 +296,7 @@
and a
jr z, .infiniteLoop
ld b, $0
- ld hl, wc0be
+ ld hl, wChannelLoopCounters
add hl, bc
ld a, [hl]
cp e
@@ -319,7 +319,7 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
pop af
ld [hli], a
@@ -333,7 +333,7 @@
ld a, d ; yes
and $f
ld b, $0
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, bc
ld [hl], a ; store low nibble as speed
ld a, c
@@ -346,10 +346,10 @@
jr z, .musicChannel3
cp CH6
jr nz, .notChannel3
- ld hl, wc0e7
+ ld hl, wSfxWaveInstrument
jr .sfxChannel3
.musicChannel3
- ld hl, wc0e6
+ ld hl, wMusicWaveInstrument
.sfxChannel3
ld a, d
and $f
@@ -364,7 +364,7 @@
; else, store volume (high nibble) and fade (low nibble)
.notChannel3
ld b, $0
- ld hl, wc0de
+ ld hl, wChannelVolumes
add hl, bc
ld [hl], d
.noiseChannel
@@ -375,11 +375,11 @@
cp $e8 ; is this command a toggleperfectpitch?
jr nz, Audio3_vibrato ; no
ld b, $0 ; yes
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
ld a, [hl]
xor $1
- ld [hl], a ; flip bit 0 of wc02e
+ ld [hl], a ; flip bit 0 of wChannelFlags1
jp Audio3_endchannel
Audio3_vibrato: ; 7d3a9 (1f:53a9)
@@ -387,10 +387,10 @@
jr nz, Audio3_pitchbend ; no
call Audio3_GetNextMusicByte ; yes
ld b, $0
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, bc
ld [hl], a ; store delay
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, bc
ld [hl], a ; store delay
call Audio3_GetNextMusicByte
@@ -398,7 +398,7 @@
and $f0
swap a
ld b, $0
- ld hl, wc056
+ ld hl, wChannelVibratoExtents
add hl, bc
srl a
ld e, a
@@ -409,7 +409,7 @@
ld a, d
and $f
ld d, a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, bc
swap a
or d
@@ -421,7 +421,7 @@
jr nz, Audio3_duty ; no
call Audio3_GetNextMusicByte ; yes
ld b, $0
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
ld [hl], a ; store first param
call Audio3_GetNextMusicByte
@@ -433,14 +433,14 @@
and $f
call Audio3_7d8cc
ld b, $0
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld [hl], d ; store unknown part of second param
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld [hl], e ; store unknown part of second param
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 4, [hl] ; set pitchbend flag
call Audio3_GetNextMusicByte
@@ -455,7 +455,7 @@
rrca
and $c0
ld b, $0
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld [hl], a ; store duty
jp Audio3_endchannel
@@ -467,25 +467,25 @@
cp CH4
jr nc, .sfxChannel
call Audio3_GetNextMusicByte
- ld [wc0e8], a ; store first param
+ ld [wMusicTempo], a ; store first param
call Audio3_GetNextMusicByte
- ld [wc0e9], a ; store second param
+ ld [wMusicTempo + 1], a ; store second param
xor a
- ld [wc0ce], a ; clear RAM
- ld [wc0cf], a
- ld [wc0d0], a
- ld [wc0d1], a
+ ld [wChannelNoteDelayCountersFractionalPart], a ; clear RAM
+ ld [wChannelNoteDelayCountersFractionalPart + 1], a
+ ld [wChannelNoteDelayCountersFractionalPart + 2], a
+ ld [wChannelNoteDelayCountersFractionalPart + 3], a
jr .musicChannelDone
.sfxChannel
call Audio3_GetNextMusicByte
- ld [wc0ea], a ; store first param
+ ld [wSfxTempo], a ; store first param
call Audio3_GetNextMusicByte
- ld [wc0eb], a ; store second param
+ ld [wSfxTempo + 1], a ; store second param
xor a
- ld [wc0d2], a ; clear RAM
- ld [wc0d3], a
- ld [wc0d4], a
- ld [wc0d5], a
+ ld [wChannelNoteDelayCountersFractionalPart + 4], a ; clear RAM
+ ld [wChannelNoteDelayCountersFractionalPart + 5], a
+ ld [wChannelNoteDelayCountersFractionalPart + 6], a
+ ld [wChannelNoteDelayCountersFractionalPart + 7], a
.musicChannelDone
jp Audio3_endchannel
@@ -493,7 +493,7 @@
cp $ee ; is this command a stereopanning?
jr nz, Audio3_unknownmusic0xef ; no
call Audio3_GetNextMusicByte ; yes
- ld [wc004], a ; store panning
+ ld [wStereoPanning], a ; store panning
jp Audio3_endchannel
; this appears to never be used
@@ -502,15 +502,15 @@
jr nz, Audio3_dutycycle ; no
call Audio3_GetNextMusicByte ; yes
push bc
- call Audio3_7d8ea
+ call Audio3_PlaySound
pop bc
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr nz, .skip
- ld a, [wc02d]
- ld [wc003], a
+ ld a, [wChannelSoundIDs + CH7]
+ ld [wDisableChannelOutputWhenSfxEnds], a
xor a
- ld [wc02d], a
+ ld [wChannelSoundIDs + CH7], a
.skip
jp Audio3_endchannel
@@ -519,14 +519,14 @@
jr nz, Audio3_volume ; no
call Audio3_GetNextMusicByte ; yes
ld b, $0
- ld hl, wc046
+ ld hl, wChannelDutyCycles
add hl, bc
ld [hl], a ; store full cycle
and $c0
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld [hl], a ; store first duty
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 6, [hl] ; set duty flag
jp Audio3_endchannel
@@ -535,7 +535,7 @@
cp $f0 ; is this command a volume?
jr nz, Audio3_executemusic ; no
call Audio3_GetNextMusicByte ; yes
- ld [$ff24], a ; store volume
+ ld [rNR50], a ; store volume
jp Audio3_endchannel
Audio3_executemusic: ; 7d4c4 (1f:54c4)
@@ -542,7 +542,7 @@
cp $f8 ; is this command an executemusic?
jr nz, Audio3_octave ; no
ld b, $0 ; yes
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
set 0, [hl]
jp Audio3_endchannel
@@ -551,7 +551,7 @@
and $f0
cp $e0 ; is this command an octave?
jr nz, Audio3_unknownsfx0x20 ; no
- ld hl, wc0d6 ; yes
+ ld hl, wChannelOctaves ; yes
ld b, $0
add hl, bc
ld a, d
@@ -566,7 +566,7 @@
cp CH3 ; is this a noise or sfx channel?
jr c, Audio3_unknownsfx0x10 ; no
ld b, $0
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, Audio3_unknownsfx0x10 ; no
@@ -573,7 +573,7 @@
call Audio3_notelength ; yes
ld d, a
ld b, $0
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld a, [hl]
or d
@@ -612,12 +612,12 @@
cp $10 ; is this command an unknownsfx0x10?
jr nz, Audio3_note ; no
ld b, $0
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, Audio3_note ; no
call Audio3_GetNextMusicByte ; yes
- ld [$ff10], a
+ ld [rNR10], a
jp Audio3_endchannel
Audio3_note: ; 7d54f (1f:554f)
@@ -647,11 +647,11 @@
call Audio3_GetNextMusicByte ; get dnote instrument
asm_7d571
ld d, a
- ld a, [wc003]
+ ld a, [wDisableChannelOutputWhenSfxEnds]
and a
jr nz, .asm_7d57c
ld a, d
- call Audio3_7d8ea
+ call Audio3_PlaySound
.asm_7d57c
pop bc
pop de
@@ -664,7 +664,7 @@
ld b, $0
ld e, a ; store note length (in 16ths)
ld d, b
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, bc
ld a, [hl]
ld l, b
@@ -672,9 +672,9 @@
ld a, c
cp CH4
jr nc, .sfxChannel
- ld a, [wc0e8]
+ ld a, [wMusicTempo]
ld d, a
- ld a, [wc0e9]
+ ld a, [wMusicTempo + 1]
ld e, a
jr .skip
.sfxChannel
@@ -683,31 +683,31 @@
cp CH7
jr z, .skip ; if noise channel
call Audio3_7d707
- ld a, [wc0ea]
+ ld a, [wSfxTempo]
ld d, a
- ld a, [wc0eb]
+ ld a, [wSfxTempo + 1]
ld e, a
.skip
ld a, l
ld b, $0
- ld hl, wc0ce
+ ld hl, wChannelNoteDelayCountersFractionalPart
add hl, bc
ld l, [hl]
call Audio3_7d8bb
ld e, l
ld d, h
- ld hl, wc0ce
+ ld hl, wChannelNoteDelayCountersFractionalPart
add hl, bc
ld [hl], e
ld a, d
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld [hl], a
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, bc
bit 0, [hl]
jr nz, Audio3_notepitch
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 2, [hl]
jr z, Audio3_notepitch
@@ -722,7 +722,7 @@
ld a, c
cp CH4
jr nc, .sfxChannel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
@@ -738,9 +738,9 @@
ld b, $0
ld hl, Unknown_7db93
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
and [hl]
- ld [$ff25], a
+ ld [rNR51], a
jr .quit
.notSfxChannel3
ld b, $2
@@ -755,12 +755,12 @@
.notRest
swap a
ld b, $0
- ld hl, wc0d6
+ ld hl, wChannelOctaves
add hl, bc
ld b, [hl]
call Audio3_7d8cc
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 4, [hl]
jr z, .asm_7d62c
@@ -770,7 +770,7 @@
ld a, c
cp CH4
jr nc, .skip ; if sfx Channel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
ld d, $0
ld e, a
add hl, de
@@ -783,7 +783,7 @@
ret
.skip
ld b, $0
- ld hl, wc0de
+ ld hl, wChannelVolumes
add hl, bc
ld d, [hl]
ld b, $2
@@ -793,7 +793,7 @@
call Audio3_7d66c
pop de
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 0, [hl] ; has toggleperfectpitch been used?
jr z, .skip2
@@ -801,7 +801,7 @@
jr nc, .skip2
inc d
.skip2
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
add hl, bc
ld [hl], e
call Audio3_7d6bf
@@ -811,7 +811,7 @@
ld b, $0
ld hl, Unknown_7db9b
add hl, bc
- ld a, [$ff25]
+ ld a, [rNR51]
or [hl]
ld d, a
ld a, c
@@ -819,18 +819,18 @@
jr z, .sfxNoiseChannel
cp CH4
jr nc, .skip ; if sfx channel
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
add hl, bc
ld a, [hl]
and a
jr nz, .skip
.sfxNoiseChannel
- ld a, [wc004]
+ ld a, [wStereoPanning]
ld hl, Unknown_7db9b
add hl, bc
and [hl]
ld d, a
- ld a, [$ff25]
+ ld a, [rNR51]
ld hl, Unknown_7db93
add hl, bc
and [hl]
@@ -838,12 +838,12 @@
ld d, a
.skip
ld a, d
- ld [$ff25], a
+ ld [rNR51], a
ret
Audio3_7d69d: ; 7d69d (1f:569d)
ld b, $0
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld d, [hl]
ld a, c
@@ -854,7 +854,7 @@
ld a, d
and $3f
ld d, a
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, bc
ld a, [hl]
or d
@@ -874,10 +874,10 @@
; fall through
.channel3
push de
- ld de, wc0e6
+ ld de, wMusicWaveInstrument
cp CH2
jr z, .musicChannel3
- ld de, wc0e7
+ ld de, wSfxWaveInstrument
.musicChannel3
ld a, [de]
add a
@@ -891,7 +891,7 @@
ld hl, $ff30
ld b, $f
ld a, $0
- ld [$ff1a], a
+ ld [rNR30], a
.loop
ld a, [de]
inc de
@@ -901,7 +901,7 @@
and a
jr nz, .loop
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
pop de
.notSfxChannel3
ld a, d
@@ -920,20 +920,20 @@
call Audio3_7d759
jr nc, .asm_7d71f
ld d, $0
- ld a, [wc0f2]
+ ld a, [wTempoModifier]
add $80
jr nc, .asm_7d716
inc d
.asm_7d716
- ld [wc0eb], a
+ ld [wSfxTempo + 1], a
ld a, d
- ld [wc0ea], a
+ ld [wSfxTempo], a
jr .asm_7d728
.asm_7d71f
xor a
- ld [wc0eb], a
+ ld [wSfxTempo + 1], a
ld a, $1
- ld [wc0ea], a
+ ld [wSfxTempo], a
.asm_7d728
ret
@@ -940,7 +940,7 @@
Audio3_7d729: ; 7d729 (1f:5729)
call Audio3_7d759
jr nc, .asm_7d73a
- ld a, [wc0f1]
+ ld a, [wFrequencyModifier]
add e
jr nc, .asm_7d735
inc d
@@ -956,7 +956,7 @@
Audio3_7d73b: ; 7d73b (1f:573b)
call Audio3_7d759
jr nc, .asm_7d756
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld e, c
ld d, $0
sla e
@@ -977,7 +977,7 @@
ret
Audio3_7d759: ; 7d759 (1f:5759)
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $14
jr nc, .asm_7d762
jr .asm_7d768
@@ -994,17 +994,17 @@
ret
Audio3_ApplyPitchBend: ; 7d76d (1f:576d)
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
bit 5, [hl]
jp nz, .asm_7d7b4
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld e, [hl]
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld l, [hl]
ld h, b
@@ -1011,10 +1011,10 @@
add hl, de
ld d, h
ld e, l
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, bc
push hl
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld a, [hl]
pop hl
@@ -1026,13 +1026,13 @@
ld a, $0
adc d
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, [hl]
cp d
jp c, .asm_7d7fa
jr nz, .asm_7d7e7
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, [hl]
cp e
@@ -1039,13 +1039,13 @@
jp c, .asm_7d7fa
jr .asm_7d7e7
.asm_7d7b4
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld a, [hl]
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld e, [hl]
sub e
@@ -1053,7 +1053,7 @@
ld a, d
sbc b
ld d, a
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld a, [hl]
add a
@@ -1064,22 +1064,22 @@
ld a, d
sbc b
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, d
cp [hl]
jr c, .asm_7d7fa
jr nz, .asm_7d7e7
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, e
cp [hl]
jr c, .asm_7d7fa
.asm_7d7e7
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld [hl], e
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld [hl], d
ld b, $3
@@ -1089,7 +1089,7 @@
ld [hl], d
ret
.asm_7d7fa
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
res 4, [hl]
res 5, [hl]
@@ -1096,16 +1096,16 @@
ret
Audio3_7d803: ; 7d803 (1f:5803)
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld [hl], d
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld [hl], e
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, bc
ld a, [hl]
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
sub [hl]
jr nc, .asm_7d81b
@@ -1112,7 +1112,7 @@
ld a, $1
.asm_7d81b
ld [hl], a
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, e
sub [hl]
@@ -1119,24 +1119,24 @@
ld e, a
ld a, d
sbc b
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
sub [hl]
jr c, .asm_7d837
ld d, a
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 5, [hl]
jr .asm_7d85a
.asm_7d837
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, bc
ld d, [hl]
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, bc
ld e, [hl]
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, bc
ld a, [hl]
sub e
@@ -1144,17 +1144,17 @@
ld a, d
sbc b
ld d, a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, bc
ld a, [hl]
sub d
ld d, a
ld b, $0
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
res 5, [hl]
.asm_7d85a
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, bc
.asm_7d85e
inc b
@@ -1173,13 +1173,13 @@
add [hl]
ld d, b
ld b, $0
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, bc
ld [hl], d
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, bc
ld [hl], a
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, bc
ld [hl], a
ret
@@ -1186,7 +1186,7 @@
Audio3_ApplyDutyCycle: ; 7d881 (1f:5881)
ld b, $0
- ld hl, wc046
+ ld hl, wChannelDutyCycles
add hl, bc
ld a, [hl]
rlca
@@ -1207,7 +1207,7 @@
ld a, c
add a
ld e, a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
ld a, [hli]
ld e, a
@@ -1274,8 +1274,8 @@
ld d, a
ret
-Audio3_7d8ea:: ; 7d8ea (1f:58ea)
- ld [wc001], a
+Audio3_PlaySound:: ; 7d8ea (1f:58ea)
+ ld [wSoundID], a
cp $ff
jp z, Audio3_7daa8
cp $c2
@@ -1286,75 +1286,75 @@
jp nc, Audio3_7d9c2
.asm_7d901
xor a
- ld [wc000], a
- ld [wc003], a
- ld [wc0e9], a
- ld [wc0e6], a
- ld [wc0e7], a
+ ld [wUnusedC000], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
+ ld [wMusicTempo + 1], a
+ ld [wMusicWaveInstrument], a
+ ld [wSfxWaveInstrument], a
ld d, $8
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
call FillAudioRAM3
- ld hl, wc006
+ ld hl, wChannelCommandPointers
call FillAudioRAM3
ld d, $4
- ld hl, wc026
+ ld hl, wChannelSoundIDs
call FillAudioRAM3
- ld hl, wc02e
+ ld hl, wChannelFlags1
call FillAudioRAM3
- ld hl, wc03e
+ ld hl, wChannelDuties
call FillAudioRAM3
- ld hl, wc046
+ ld hl, wChannelDutyCycles
call FillAudioRAM3
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
call FillAudioRAM3
- ld hl, wc056
+ ld hl, wChannelVibratoExtents
call FillAudioRAM3
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
call FillAudioRAM3
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
call FillAudioRAM3
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
call FillAudioRAM3
- ld hl, wc036
+ ld hl, wChannelFlags2
call FillAudioRAM3
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
call FillAudioRAM3
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
call FillAudioRAM3
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
call FillAudioRAM3
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
call FillAudioRAM3
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
call FillAudioRAM3
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
call FillAudioRAM3
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
call FillAudioRAM3
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
call FillAudioRAM3
ld a, $1
- ld hl, wc0be
+ ld hl, wChannelLoopCounters
call FillAudioRAM3
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
call FillAudioRAM3
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
call FillAudioRAM3
- ld [wc0e8], a
+ ld [wMusicTempo], a
ld a, $ff
- ld [wc004], a
+ ld [wStereoPanning], a
xor a
- ld [$ff24], a
+ ld [rNR50], a
ld a, $8
- ld [$ff10], a
+ ld [rNR10], a
ld a, $0
- ld [$ff25], a
+ ld [rNR51], a
xor a
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $80
- ld [$ff1a], a
+ ld [rNR30], a
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
jp Audio3_7db03
Audio3_7d9c2: ; 7d9c2 (1f:59c2)
@@ -1367,9 +1367,9 @@
ld de, SFX_Headers_3
add hl, de
ld a, h
- ld [wc0ec], a
+ ld [wSfxHeaderPointer], a
ld a, l
- ld [wc0ed], a
+ ld [wSfxHeaderPointer + 1], a
ld a, [hl]
and $c0
rlca
@@ -1382,9 +1382,9 @@
add c
ld c, a
ld b, $0
- ld a, [wc0ec]
+ ld a, [wSfxHeaderPointer]
ld h, a
- ld a, [wc0ed]
+ ld a, [wSfxHeaderPointer + 1]
ld l, a
add hl, bc
ld c, d
@@ -1392,7 +1392,7 @@
and $f
ld e, a
ld d, $0
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, de
ld a, [hl]
and a
@@ -1400,7 +1400,7 @@
ld a, e
cp $7
jr nz, .asm_7da0e
- ld a, [wc001]
+ ld a, [wSoundID]
cp $14
jr nc, .asm_7da07
ret
@@ -1410,7 +1410,7 @@
jr z, .asm_7da17
jr c, .asm_7da17
.asm_7da0e
- ld a, [wc001]
+ ld a, [wSoundID]
cp [hl]
jr z, .asm_7da17
jr c, .asm_7da17
@@ -1423,77 +1423,77 @@
add hl, hl
ld d, h
ld e, l
- ld hl, wc016
+ ld hl, wChannelReturnAddresses
add hl, de
ld [hli], a
ld [hl], a
- ld hl, wc006
+ ld hl, wChannelCommandPointers
add hl, de
ld [hli], a
ld [hl], a
pop de
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, de
ld [hl], a
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, de
ld [hl], a
- ld hl, wc03e
+ ld hl, wChannelDuties
add hl, de
ld [hl], a
- ld hl, wc046
+ ld hl, wChannelDutyCycles
add hl, de
ld [hl], a
- ld hl, wc04e
+ ld hl, wChannelVibratoDelayCounters
add hl, de
ld [hl], a
- ld hl, wc056
+ ld hl, wChannelVibratoExtents
add hl, de
ld [hl], a
- ld hl, wc05e
+ ld hl, wChannelVibratoRates
add hl, de
ld [hl], a
- ld hl, wc066
+ ld hl, wChannelFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc06e
+ ld hl, wChannelVibratoDelayCounterReloadValues
add hl, de
ld [hl], a
- ld hl, wc076
+ ld hl, wChannelPitchBendLengthModifiers
add hl, de
ld [hl], a
- ld hl, wc07e
+ ld hl, wChannelPitchBendFrequencySteps
add hl, de
ld [hl], a
- ld hl, wc086
+ ld hl, wChannelPitchBendFrequencyStepsFractionalPart
add hl, de
ld [hl], a
- ld hl, wc08e
+ ld hl, wChannelPitchBendCurrentFrequencyFractionalPart
add hl, de
ld [hl], a
- ld hl, wc096
+ ld hl, wChannelPitchBendCurrentFrequencyHighBytes
add hl, de
ld [hl], a
- ld hl, wc09e
+ ld hl, wChannelPitchBendCurrentFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc0a6
+ ld hl, wChannelPitchBendTargetFrequencyHighBytes
add hl, de
ld [hl], a
- ld hl, wc0ae
+ ld hl, wChannelPitchBendTargetFrequencyLowBytes
add hl, de
ld [hl], a
- ld hl, wc036
+ ld hl, wChannelFlags2
add hl, de
ld [hl], a
ld a, $1
- ld hl, wc0be
+ ld hl, wChannelLoopCounters
add hl, de
ld [hl], a
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
add hl, de
ld [hl], a
- ld hl, wc0c6
+ ld hl, wChannelNoteSpeeds
add hl, de
ld [hl], a
ld a, e
@@ -1500,7 +1500,7 @@
cp $4
jr nz, .asm_7da9f
ld a, $8
- ld [$ff10], a
+ ld [rNR10], a
.asm_7da9f
ld a, c
and a
@@ -1510,41 +1510,41 @@
Audio3_7daa8: ; 7daa8 (1f:5aa8)
ld a, $80
- ld [$ff26], a
- ld [$ff1a], a
+ ld [rNR52], a
+ ld [rNR30], a
xor a
- ld [$ff25], a
- ld [$ff1c], a
+ ld [rNR51], a
+ ld [rNR32], a
ld a, $8
- ld [$ff10], a
- ld [$ff12], a
- ld [$ff17], a
- ld [$ff21], a
+ ld [rNR10], a
+ ld [rNR12], a
+ ld [rNR22], a
+ ld [rNR42], a
ld a, $40
- ld [$ff14], a
- ld [$ff19], a
- ld [$ff23], a
+ ld [rNR14], a
+ ld [rNR24], a
+ ld [rNR44], a
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
xor a
- ld [wc000], a
- ld [wc003], a
- ld [wc002], a
- ld [wc0e9], a
- ld [wc0eb], a
- ld [wc0e6], a
- ld [wc0e7], a
+ ld [wUnusedC000], a
+ ld [wDisableChannelOutputWhenSfxEnds], a
+ ld [wMuteAudioAndPauseMusic], a
+ ld [wMusicTempo + 1], a
+ ld [wSfxTempo + 1], a
+ ld [wMusicWaveInstrument], a
+ ld [wSfxWaveInstrument], a
ld d, $a0
- ld hl, wc006
+ ld hl, wChannelCommandPointers
call FillAudioRAM3
ld a, $1
ld d, $18
- ld hl, wc0b6
+ ld hl, wChannelNoteDelayCounters
call FillAudioRAM3
- ld [wc0e8], a
- ld [wc0ea], a
+ ld [wMusicTempo], a
+ ld [wSfxTempo], a
ld a, $ff
- ld [wc004], a
+ ld [wStereoPanning], a
ret
; fills d bytes at hl with a
@@ -1557,7 +1557,7 @@
ret
Audio3_7db03: ; 7db03 (1f:5b03)
- ld a, [wc001]
+ ld a, [wSoundID]
ld l, a
ld e, a
ld h, $0
@@ -1568,7 +1568,7 @@
add hl, de
ld e, l
ld d, h
- ld hl, wc006
+ ld hl, wChannelCommandPointers
ld a, [de] ; get channel number
ld b, a
rlca
@@ -1594,14 +1594,14 @@
push af
ld b, $0
ld c, a
- ld hl, wc026
+ ld hl, wChannelSoundIDs
add hl, bc
- ld a, [wc001]
+ ld a, [wSoundID]
ld [hl], a
pop af
cp $3
jr c, .asm_7db46
- ld hl, wc02e
+ ld hl, wChannelFlags1
add hl, bc
set 2, [hl]
.asm_7db46
@@ -1620,34 +1620,34 @@
ld a, [de]
inc de
jr nz, .asm_7db25
- ld a, [wc001]
+ ld a, [wSoundID]
cp $14
jr nc, .asm_7db5f
jr .asm_7db89
.asm_7db5f
- ld a, [wc001]
+ ld a, [wSoundID]
cp $86
jr z, .asm_7db89
jr c, .asm_7db6a
jr .asm_7db89
.asm_7db6a
- ld hl, wc02a
+ ld hl, wChannelSoundIDs + CH4
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
- ld hl, wc012 ; sfx noise channel pointer
+ ld hl, wChannelCommandPointers + CH6 * 2 ; sfx noise channel pointer
ld de, Noise3_endchannel
ld [hl], e
inc hl
ld [hl], d ; overwrite pointer to point to endchannel
- ld a, [wc005]
+ ld a, [wSavedVolume]
and a
jr nz, .asm_7db89
- ld a, [$ff24]
- ld [wc005], a
+ ld a, [rNR50]
+ ld [wSavedVolume], a
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
.asm_7db89
ret
--- a/constants/hardware_constants.asm
+++ b/constants/hardware_constants.asm
@@ -107,4 +107,3 @@
rUNKNOWN6 EQU $ff76 ; (00h) - Always 00h (Read Only)
rUNKNOWN7 EQU $ff77 ; (00h) - Always 00h (Read Only)
rIE EQU $ffff ; Interrupt Enable (R/W)
-
--- a/constants/music_constants.asm
+++ b/constants/music_constants.asm
@@ -1,3 +1,42 @@
+; HW sound channel register base addresses
+HW_CH1_BASE EQU (rNR10 % $100)
+HW_CH2_BASE EQU ((rNR21 % $100) - 1)
+HW_CH3_BASE EQU (rNR30 % $100)
+HW_CH4_BASE EQU ((rNR41 % $100) - 1)
+
+; HW sound channel enable bit masks
+HW_CH1_ENABLE_MASK EQU %00010001
+HW_CH2_ENABLE_MASK EQU %00100010
+HW_CH3_ENABLE_MASK EQU %01000100
+HW_CH4_ENABLE_MASK EQU %10001000
+
+; HW sound channel disable bit masks
+HW_CH1_DISABLE_MASK EQU (~HW_CH1_ENABLE_MASK & $ff)
+HW_CH2_DISABLE_MASK EQU (~HW_CH2_ENABLE_MASK & $ff)
+HW_CH3_DISABLE_MASK EQU (~HW_CH3_ENABLE_MASK & $ff)
+HW_CH4_DISABLE_MASK EQU (~HW_CH4_ENABLE_MASK & $ff)
+
+REG_DUTY_SOUND_LEN EQU 1
+REG_VOLUME_ENVELOPE EQU 2
+REG_FREQUENCY_LO EQU 3
+
+MAX_SFX_ID EQU $B9
+
+CRY_SFX_START EQU $14
+CRY_SFX_END EQU $86
+
+; wChannelFlags1 constants
+BIT_PERFECT_PITCH EQU 0 ; controlled by toggleperfectpitch command
+BIT_CHANNEL_CALL EQU 1 ; if in channel call
+BIT_NOISE_OR_SFX EQU 2 ; if channel is the music noise channel or an SFX channel
+BIT_VIBRATO_DIRECTION EQU 3 ; if the pitch is above or below normal (cycles)
+BIT_PITCH_BEND_ON EQU 4 ; if pitch bend is active
+BIT_PITCH_BEND_DECREASING EQU 5 ; if the pitch bend frequency is decreasing (instead of increasing)
+BIT_ROTATE_DUTY EQU 6 ; if rotating duty
+
+; wChannelFlags2 constant (only has one flag)
+BIT_EXECUTE_MUSIC EQU 0 ; if in execute music
+
; Song ids are calculated by address to save space.
music_const: MACRO
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -772,7 +772,7 @@
dec b
jr nz,.loop
ld a,%00001000
- ld [$ff10],a ; Channel 1 sweep register
+ ld [rNR10],a ; Channel 1 sweep register
ret
.isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame
ld a,[W_SUBANIMCOUNTER]
@@ -2335,19 +2335,19 @@
call GetCryData
ld b,a
pop hl
- ld a,[wc0f1]
+ ld a,[wFrequencyModifier]
add [hl]
- ld [wc0f1],a
+ ld [wFrequencyModifier],a
inc hl
- ld a,[wc0f2]
+ ld a,[wTempoModifier]
add [hl]
- ld [wc0f2],a
+ ld [wTempoModifier],a
jr .done
.NotCryMove
ld a,[hli]
- ld [wc0f1],a
+ ld [wFrequencyModifier],a
ld a,[hli]
- ld [wc0f2],a
+ ld [wTempoModifier],a
.done
ld a,b
ret
@@ -2956,7 +2956,7 @@
ld a,[W_ISINBATTLE]
cp a,2
jr z,.BlockBall ; if in trainer battle, play different animation
- ld a,[wd11e]
+ ld a,[wPokeBallAnimData]
ld b,a
; upper nybble: how many animations (from PokeBallAnimations) to play
@@ -3029,8 +3029,8 @@
ld b, $1
ld c, SFX_NOT_VERY_EFFECTIVE
.playSound
- ld [wc0f1], a
+ ld [wFrequencyModifier], a
ld a, b
- ld [wc0f2], a
+ ld [wTempoModifier], a
ld a, c
jp PlaySound
--- a/engine/battle/bank_e_misc.asm
+++ b/engine/battle/bank_e_misc.asm
@@ -92,9 +92,9 @@
ld a, h
ld [wListPointer + 1], a
ld a, e
- ld [wcf8d], a
+ ld [wUnusedCF8D], a
ld a, d
- ld [wcf8e], a
+ ld [wUnusedCF8D + 1], a
ld bc, ItemPrices
ld a, c
ld [wItemPrices], a
--- a/engine/battle/common_text.asm
+++ b/engine/battle/common_text.asm
@@ -61,9 +61,9 @@
.playSFX
xor a
- ld [wc0f1], a
+ ld [wFrequencyModifier], a
ld a, $80
- ld [wc0f2], a
+ ld [wTempoModifier], a
ld a, SFX_SILPH_SCOPE
call PlaySound
jp WaitForSoundToFinish
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -834,8 +834,17 @@
.wild
ld hl, W_PLAYERBATTSTATUS1
res AttackingMultipleTimes, [hl]
+; Bug. This only zeroes the high byte of the player's accumulated damage,
+; setting the accumulated damage to itself mod 256 instead of 0 as was probably
+; intended. That alone is problematic, but this mistake has another more severe
+; effect. This function's counterpart for when the player mon faints,
+; RemoveFaintedPlayerMon, zeroes both the high byte and the low byte. In a link
+; battle, the other player's Game Boy will call that function in response to
+; the enemy mon (the player mon from the other side's perspective) fainting,
+; and the states of the two Game Boys will go out of sync unless the damage
+; was congruent to 0 modulo 256.
xor a
- ld [wPlayerNumHits], a
+ ld [wPlayerBideAccumulatedDamage], a
ld hl, wEnemyStatsToDouble ; clear enemy statuses
ld [hli], a
ld [hli], a
@@ -858,12 +867,12 @@
dec a
jr z, .wild_win
xor a
- ld [wc0f1], a
- ld [wc0f2], a
+ ld [wFrequencyModifier], a
+ ld [wTempoModifier], a
ld a, SFX_FAINT_FALL
call PlaySoundWaitForCurrent
.sfxwait
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp SFX_FAINT_FALL
jr z, .sfxwait
ld a, SFX_FAINT_THUD
@@ -943,7 +952,7 @@
EndLowHealthAlarm: ; 3c643 (f:4643)
xor a
ld [wLowHealthAlarm], a ;disable low health alarm
- ld [wc02a], a
+ ld [wChannelSoundIDs + CH4], a
inc a
ld [wccf6], a
ret
@@ -1036,7 +1045,7 @@
PlayBattleVictoryMusic: ; 3c6ee (f:46ee)
push af
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySoundWaitForCurrent
ld c, BANK(Music_DefeatedTrainer)
pop af
@@ -1092,8 +1101,7 @@
ld [wLowHealthAlarm], a ;disable low health alarm
call WaitForSoundToFinish
.skipWaitForSound
-; bug? if the player mon faints while the enemy mon is using bide,
-; the accumulated damage is overwritten. xxx what values can [wLowHealthAlarm] have here?
+; a is 0, so this zeroes the enemy's accumulated damage.
ld hl, wEnemyBideAccumulatedDamage
ld [hli], a
ld [hl], a
@@ -1936,7 +1944,7 @@
ld [hl], $0
ret z
xor a
- ld [wc02a], a
+ ld [wChannelSoundIDs + CH4], a
ret
.asm_3cde6
ld hl, wLowHealthAlarm
@@ -2954,7 +2962,7 @@
lb bc, 1, 2
call PrintNumber
coord hl, 8, 11
- ld de, wd11e
+ ld de, wMaxPP
lb bc, 1, 2
call PrintNumber
call GetCurrentMove
@@ -5279,7 +5287,7 @@
ld d,a ; d = type 1 of defender
ld e,[hl] ; e = type 2 of defender
ld a,[W_PLAYERMOVETYPE]
- ld [wd11e],a
+ ld [wMoveType],a
ld a,[H_WHOSETURN]
and a
jr z,.next
@@ -5293,9 +5301,9 @@
ld d,a ; d = type 1 of defender
ld e,[hl] ; e = type 2 of defender
ld a,[W_ENEMYMOVETYPE]
- ld [wd11e],a
+ ld [wMoveType],a
.next
- ld a,[wd11e] ; move type
+ ld a,[wMoveType]
cp b ; does the move type match type 1 of the attacker?
jr z,.sameTypeAttackBonus
cp c ; does the move type match type 2 of the attacker?
@@ -5320,8 +5328,8 @@
ld hl,wDamageMultipliers
set 7,[hl]
.skipSameTypeAttackBonus
- ld a,[wd11e]
- ld b,a ; b = move type
+ ld a,[wMoveType]
+ ld b,a
ld hl,TypeEffects
.loop
ld a,[hli] ; a = "attacking type" of the current type pair
@@ -5384,29 +5392,29 @@
; function to tell how effective the type of an enemy attack is on the player's current pokemon
; this doesn't take into account the effects that dual types can have
; (e.g. 4x weakness / resistance, weaknesses and resistances canceling)
-; the result is stored in [wd11e]
+; the result is stored in [wTypeEffectiveness]
; ($05 is not very effective, $10 is neutral, $14 is super effective)
; as far is can tell, this is only used once in some AI code to help decide which move to use
AIGetTypeEffectiveness: ; 3e449 (f:6449)
ld a,[W_ENEMYMOVETYPE]
- ld d,a ; d = type of enemy move
+ ld d,a ; d = type of enemy move
ld hl,wBattleMonType
- ld b,[hl] ; b = type 1 of player's pokemon
+ ld b,[hl] ; b = type 1 of player's pokemon
inc hl
- ld c,[hl] ; c = type 2 of player's pokemon
+ ld c,[hl] ; c = type 2 of player's pokemon
ld a,$10
- ld [wd11e],a ; initialize [wd11e] to neutral effectiveness
+ ld [wTypeEffectiveness],a ; initialize to neutral effectiveness
ld hl,TypeEffects
.loop
ld a,[hli]
cp a,$ff
ret z
- cp d ; match the type of the move
+ cp d ; match the type of the move
jr nz,.nextTypePair1
ld a,[hli]
- cp b ; match with type 1 of pokemon
+ cp b ; match with type 1 of pokemon
jr z,.done
- cp c ; or match with type 2 of pokemon
+ cp c ; or match with type 2 of pokemon
jr z,.done
jr .nextTypePair2
.nextTypePair1
@@ -5416,7 +5424,7 @@
jr .loop
.done
ld a,[hl]
- ld [wd11e],a ; store damage multiplier
+ ld [wTypeEffectiveness],a ; store damage multiplier
ret
INCLUDE "data/type_effects.asm"
@@ -6569,12 +6577,12 @@
CalculateModifiedStat: ; 3eda5 (f:6da5)
push bc
push bc
- ld a, [wd11e]
+ ld a, [wCalculateWhoseStats]
and a
ld a, c
ld hl, wBattleMonAttack
ld de, wPlayerMonUnmodifiedAttack
- ld bc, wPlayerMonAttackMod
+ ld bc, wPlayerMonStatMods
jr z, .next
ld hl, wEnemyMonAttack
ld de, wEnemyMonUnmodifiedAttack
@@ -6985,8 +6993,8 @@
; unreferenced
ResetCryModifiers: ; 3f069 (f:7069)
xor a
- ld [wc0f1], a
- ld [wc0f2], a
+ ld [wFrequencyModifier], a
+ ld [wTempoModifier], a
jp PlaySound
; animates the mon "growing" out of the pokeball
--- a/engine/battle/end_of_battle.asm
+++ b/engine/battle/end_of_battle.asm
@@ -46,7 +46,7 @@
.resetVariables
xor a
ld [wLowHealthAlarm], a ;disable low health alarm
- ld [wc02a], a
+ ld [wChannelSoundIDs + CH4], a
ld [W_ISINBATTLE], a
ld [W_BATTLETYPE], a
ld [W_MOVEMISSED], a
--- a/engine/battle/experience.asm
+++ b/engine/battle/experience.asm
@@ -231,8 +231,8 @@
ld bc, 1 + NUM_STATS * 2
call CopyData
.recalcStatChanges
- xor a
- ld [wd11e], a
+ xor a ; battle mon
+ ld [wCalculateWhoseStats], a
callab CalculateModifiedStats
callab ApplyBurnAndParalysisPenaltiesToPlayer
callab ApplyBadgeStatBoosts
--- a/engine/battle/trainer_ai.asm
+++ b/engine/battle/trainer_ai.asm
@@ -191,7 +191,7 @@
AIMoveChoiceModification3: ; 39817 (e:5817)
ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset)
ld de, wEnemyMonMoves ; enemy moves
- ld b, $5
+ ld b, NUM_MOVES + 1
.nextMove
dec b
ret z ; processed all 4 moves
@@ -208,7 +208,7 @@
pop de
pop bc
pop hl
- ld a, [wd11e]
+ ld a, [wTypeEffectiveness]
cp $10
jr z, .nextMove
jr c, .notEffectiveMove
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -256,9 +256,9 @@
dec c
jr nz, .unpatchEnemyMonsLoop
ld a, wEnemyMonOT % $100
- ld [wcf8d], a
+ ld [wUnusedCF8D], a
ld a, wEnemyMonOT / $100
- ld [wcf8e], a
+ ld [wUnusedCF8D + 1], a
xor a
ld [wTradeCenterPointerTableIndex], a
ld a, $ff
@@ -824,12 +824,12 @@
add hl, bc
ld a, [hl]
ld [wTradedEnemyMonSpecies], a
- ld a, $a
- ld [wMusicHeaderPointer], a
+ ld a, 10
+ ld [wAudioFadeOutControl], a
ld a, $2
- ld [wc0f0], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_SAFARI_ZONE
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld c, 100
call DelayFrames
@@ -915,12 +915,12 @@
inc a ; LINK_STATE_IN_CABLE_CLUB
ld [wLinkState], a
ld [$ffb5], a
- ld a, $a
- ld [wMusicHeaderPointer], a
+ ld a, 10
+ ld [wAudioFadeOutControl], a
ld a, BANK(Music_Celadon)
- ld [wc0f0], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_CELADON
- ld [wc0ee], a
+ ld [wNewSoundID], a
jp PlaySound
EmptyFunc3: ; 5aaf (1:5aaf)
--- a/engine/evolution.asm
+++ b/engine/evolution.asm
@@ -8,9 +8,9 @@
push af
xor a
ld [wLowHealthAlarm], a
- ld [wc02a], a
+ ld [wChannelSoundIDs + CH4], a
dec a
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
@@ -68,7 +68,7 @@
.done
ld [wcf1d], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, [wcf1d]
call PlayCry
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -166,7 +166,7 @@
ld de, W_MONHEADER
call CopyData
ld a, [wd0b5]
- ld [W_MONHDEXNUM], a
+ ld [W_MONHINDEX], a
pop af
ld [wd11e], a
ld hl, wLoadedMonHPExp - 1
@@ -257,12 +257,12 @@
call nz, PlayDefaultMusic
ret
-; checks if the evolved mon's name is different from the standard name (i.e. it has a nickname)
-; if so, rename it to is evolved form's standard name
RenameEvolvedMon: ; 3aef7 (e:6ef7)
+; Renames the mon to its new, evolved form's standard name unless it had a
+; nickname, in which case the nickname is kept.
ld a, [wd0b5]
push af
- ld a, [W_MONHDEXNUM]
+ ld a, [W_MONHINDEX]
ld [wd0b5], a
call GetName
pop af
@@ -275,7 +275,7 @@
cp [hl]
inc hl
ret nz
- cp $50
+ cp "@"
jr nz, .compareNamesLoop
ld a, [wWhichPokemon]
ld bc, 11
--- a/engine/hall_of_fame.asm
+++ b/engine/hall_of_fame.asm
@@ -280,9 +280,9 @@
jp CopyData
HoFFadeOutScreenAndMusic: ; 70423 (1c:4423)
- ld a, $a
- ld [wcfc8], a
- ld [wcfc9], a
+ ld a, 10
+ ld [wAudioFadeOutCounterReloadValue], a
+ ld [wAudioFadeOutCounter], a
ld a, $ff
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
jp GBFadeOutToWhite
--- a/engine/hidden_object_functions14.asm
+++ b/engine/hidden_object_functions14.asm
@@ -2,7 +2,7 @@
call EnableAutoTextBoxDrawing
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ld a, [wTrainerSpriteOffset]
+ ld a, [wHiddenObjectFunctionArgument]
jp PrintPredefTextID
TMNotebook: ; 529a4 (14:69a4)
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -19,8 +19,8 @@
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e]
- cp $2
+ ld a, [wNumSetBits]
+ cp 2
tx_pre_id SaveOptionText
jr c, .ownThreeOrMoreMon
tx_pre_id StrengthsAndWeaknessesText
@@ -63,7 +63,7 @@
SafariZoneGameOver: ; 1e9b0 (7:69b0)
call EnableAutoTextBoxDrawing
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
dec a
call PlaySound
ld c, BANK(SFX_Safari_Zone_PA)
@@ -70,7 +70,7 @@
ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
.asm_1e9c2
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $b9
jr nz, .asm_1e9c2
ld a, TEXT_SAFARI_GAME_OVER
@@ -374,7 +374,7 @@
db $06
TX_ASM
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld c, 16
call DelayFrames
--- a/engine/intro.asm
+++ b/engine/intro.asm
@@ -325,10 +325,10 @@
call DelayFrames
.next
ld a, BANK(Music_IntroBattle)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_INTRO_BATTLE
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
call IntroClearMiddleOfScreen
call ClearSprites
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -312,7 +312,7 @@
ld b,$63
.next12
ld a,b
- ld [wd11e],a
+ ld [wPokeBallAnimData],a
.BallSuccess2
ld c,20
call DelayFrames
@@ -331,7 +331,7 @@
ld [wcf91],a
pop af
ld [wWhichPokemon],a
- ld a,[wd11e]
+ ld a,[wPokeBallAnimData]
cp a,$10
ld hl,ItemUseBallText00
jp z,.printText0
@@ -856,7 +856,7 @@
.notFullHP ; if the pokemon's current HP doesn't equal its max HP
xor a
ld [wLowHealthAlarm],a ;disable low health alarm
- ld [wc02a],a
+ ld [wChannelSoundIDs + CH4],a
push hl
push de
ld bc,32
@@ -1643,7 +1643,7 @@
call WaitForSoundToFinish ; wait for sound to end
callba Music_PokeFluteInBattle ; play in-battle pokeflute music
.musicWaitLoop ; wait for music to finish playing
- ld a,[wc02c]
+ ld a,[wChannelSoundIDs + CH6]
and a ; music off?
jr nz,.musicWaitLoop
.skipMusic
@@ -1716,8 +1716,8 @@
ld c, BANK(SFX_Pokeflute)
call PlayMusic
.musicWaitLoop ; wait for music to finish playing
- ld a,[wc028]
- cp a,$b8
+ ld a,[wChannelSoundIDs + CH2]
+ cp a, SFX_POKEFLUE
jr z,.musicWaitLoop
call PlayDefaultMusic ; start playing normal music again
.done
@@ -1895,7 +1895,7 @@
ld [wPlayerMoveListIndex],a
jr nz,.chooseMon
ld hl,wPartyMon1Moves
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
push hl
ld a,[hl]
@@ -1937,7 +1937,7 @@
cp b ; is the pokemon whose PP was restored active in battle?
jr nz,.skipUpdatingInBattleData
ld hl,wPartyMon1PP
- ld bc,wPartyMon2 - wPartyMon1
+ ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
ld de,wBattleMonPP
ld bc,4
@@ -1959,12 +1959,12 @@
ld [wMonDataLocation],a
call GetMaxPP
ld hl,wPartyMon1Moves
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
- ld bc,21
+ ld bc, wPartyMon1PP - wPartyMon1Moves
add hl,bc ; hl now points to move's PP
- ld a,[wd11e]
- ld b,a ; b = max PP
+ ld a,[wMaxPP]
+ ld b,a
ld a,[wPPRestoreItem]
cp a,MAX_ETHER
jr z,.fullyRestorePP
@@ -2009,7 +2009,7 @@
.elixirLoop
push bc
ld hl,wPartyMon1Moves
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
ld a,[hl]
and a ; does the current slot have a move?
@@ -2283,13 +2283,10 @@
; also, when a PP Up is used, it increases the current PP by one PP Up bonus
; INPUT:
; [wWhichPokemon] = index of pokemon in party
-; [wd11e] = mode
-; 0: Pokemon Center healing
-; 1: using a PP Up
; [wCurrentMenuItem] = index of move (when using a PP Up)
RestoreBonusPP: ; e606 (3:6606)
ld hl,wPartyMon1Moves
- ld bc,wPartyMon2 - wPartyMon1
+ ld bc, wPartyMon2 - wPartyMon1
ld a,[wWhichPokemon]
call AddNTimes
push hl
@@ -2296,7 +2293,7 @@
ld de,wNormalMaxPPList - 1
predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList
pop hl
- ld c,21
+ ld c, wPartyMon1PP - wPartyMon1Moves
ld b,0
add hl,bc ; hl now points to move 1 PP
ld de,wNormalMaxPPList
@@ -2307,7 +2304,7 @@
ld a,b
cp a,5 ; reached the end of the pokemon's moves?
ret z ; if so, return
- ld a,[wd11e]
+ ld a,[wUsingPPUp]
dec a ; using a PP Up?
jr nz,.skipMenuItemIDCheck
; if using a PP Up, check if this is the move it's being used on
@@ -2329,8 +2326,6 @@
; INPUT:
; [de] = normal max PP
; [hl] = move PP
-; [wd11e] = max number of times to add bonus
-; set to 1 when using a PP Up, set to 255 otherwise
AddBonusPP: ; e642 (3:6642)
push bc
ld a,[de] ; normal max PP of move
@@ -2358,9 +2353,9 @@
.addAmount
add b
ld b,a
- ld a,[wd11e]
- dec a
- jr z,.done
+ ld a,[wUsingPPUp]
+ dec a ; is the player using a PP Up right now?
+ jr z,.done ; if so, only add the bonus once
dec c
jr nz,.loop
.done
@@ -2379,7 +2374,7 @@
; 04: player's in-battle pokemon
; [wCurrentMenuItem] = move index
; OUTPUT:
-; [wd11e] = max PP
+; [wMaxPP] = max PP
GetMaxPP: ; e677 (3:6677)
ld a,[wMonDataLocation]
and a
@@ -2432,12 +2427,12 @@
ld l,e
inc hl ; hl = wcd73
ld [hl],a
- xor a
- ld [wd11e],a ; no limit on PP Up amount
+ xor a ; add the bonus for the existing PP Up count
+ ld [wUsingPPUp],a
call AddBonusPP ; add bonus PP from PP Ups
ld a,[hl]
and a,%00111111 ; mask out the PP Up count
- ld [wd11e],a ; store max PP
+ ld [wMaxPP],a ; store max PP
ret
GetSelectedMoveOffset: ; e6e3 (3:66e3)
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -395,7 +395,7 @@
ld b, $1
call CountSetBits
pop hl
- ld de, wd11e
+ ld de, wNumSetBits
lb bc, 1, 2
jp PrintNumber
@@ -405,7 +405,7 @@
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
pop hl
- ld de, wd11e
+ ld de, wNumSetBits
lb bc, 1, 3
jp PrintNumber
--- a/engine/menu/pokedex.asm
+++ b/engine/menu/pokedex.asm
@@ -169,7 +169,7 @@
ld hl,wPokedexSeen
ld b,wPokedexSeenEnd - wPokedexSeen
call CountSetBits
- ld de,wd11e
+ ld de, wNumSetBits
coord hl, 16, 3
lb bc, 1, 3
call PrintNumber ; print number of seen pokemon
@@ -176,7 +176,7 @@
ld hl,wPokedexOwned
ld b,wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld de,wd11e
+ ld de, wNumSetBits
coord hl, 16, 6
lb bc, 1, 3
call PrintNumber ; print number of owned pokemon
@@ -397,7 +397,7 @@
ld hl,wd72c
set 1,[hl]
ld a,$33 ; 3/7 volume
- ld [$ff24],a
+ ld [rNR50],a
call GBPalWhiteOut ; zero all palettes
call ClearScreen
ld a,[wd11e] ; pokemon ID
@@ -566,7 +566,7 @@
ld hl,wd72c
res 1,[hl]
ld a,$77 ; max volume
- ld [$ff24],a
+ ld [rNR50],a
ret
HeightWeightText: ; 40448 (10:4448)
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -80,7 +80,7 @@
ld hl, wd72c
set 1, [hl]
ld a, $33
- ld [$ff24], a ; Reduce the volume
+ ld [rNR50], a ; Reduce the volume
call GBPalWhiteOutWithDelay3
call ClearScreen
call UpdateSprites
@@ -138,7 +138,7 @@
call PlaceString ; "STATUS/"
coord hl, 14, 2
call PrintLevel ; Pokémon level
- ld a, [W_MONHDEXNUM]
+ ld a, [W_MONHINDEX]
ld [wd11e], a
ld [wd0b5], a
predef IndexToPokedex
@@ -372,7 +372,7 @@
call PrintNumber
ld a, "/"
ld [hli], a
- ld de, wd11e
+ ld de, wMaxPP
lb bc, 1, 2
call PrintNumber
pop hl
@@ -417,7 +417,7 @@
call StatusScreen_ClearName
coord hl, 9, 1
call StatusScreen_ClearName
- ld a, [W_MONHDEXNUM]
+ ld a, [W_MONHINDEX]
ld [wd11e], a
call GetMonName
coord hl, 9, 1
@@ -431,7 +431,7 @@
ld hl, wd72c
res 1, [hl]
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
call GBPalWhiteOut
jp ClearScreen
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -129,12 +129,12 @@
ld a,[H_LOADEDROMBANK]
push af
ld a, BANK(Music_PalletTown)
- ld [wc0ef],a
- ld [wc0f0],a
- ld a,$A
- ld [wMusicHeaderPointer],a
+ ld [wAudioROMBank],a
+ ld [wAudioSavedROMBank],a
+ ld a, 10
+ ld [wAudioFadeOutControl],a
ld a,$FF
- ld [wc0ee],a
+ ld [wNewSoundID],a
call PlaySound ; stop music
pop af
ld [H_LOADEDROMBANK],a
--- a/engine/overworld/elevator.asm
+++ b/engine/overworld/elevator.asm
@@ -33,7 +33,7 @@
ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
.musicLoop
- ld a, [wc02a]
+ ld a, [wChannelSoundIDs + CH4]
cp $b9
jr z, .musicLoop
call UpdateSprites
--- a/engine/overworld/healing_machine.asm
+++ b/engine/overworld/healing_machine.asm
@@ -15,18 +15,18 @@
ld hl, wOAMBuffer + $84
ld de, PokeCenterOAMData
call CopyHealingMachineOAM
- ld a, $4
- ld [wMusicHeaderPointer], a
+ ld a, 4
+ ld [wAudioFadeOutControl], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
-.asm_70464
- ld a, [wMusicHeaderPointer]
- and a
- jr nz, .asm_70464
+.waitLoop
+ ld a, [wAudioFadeOutControl]
+ and a ; is fade-out finished?
+ jr nz, .waitLoop ; if not, check again
ld a, [wPartyCount]
ld b, a
-.asm_7046e
+.partyLoop
call CopyHealingMachineOAM
ld a, SFX_HEALING_MACHINE
call PlaySound
@@ -33,26 +33,26 @@
ld c, 30
call DelayFrames
dec b
- jr nz, .asm_7046e
- ld a, [wc0ef]
+ jr nz, .partyLoop
+ ld a, [wAudioROMBank]
cp BANK(Audio3_UpdateMusic)
- ld [wc0f0], a
- jr nz, .asm_70495
+ ld [wAudioSavedROMBank], a
+ jr nz, .next
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, BANK(Music_PkmnHealed)
- ld [wc0ef], a
-.asm_70495
+ ld [wAudioROMBank], a
+.next
ld a, MUSIC_PKMN_HEALED
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld d, $28
call FlashSprite8Times
-.asm_704a2
- ld a, [wc026]
- cp MUSIC_PKMN_HEALED
- jr z, .asm_704a2
+.waitLoop2
+ ld a, [wChannelSoundIDs]
+ cp MUSIC_PKMN_HEALED ; is the healed music still playing?
+ jr z, .waitLoop2 ; if so, check gain
ld c, 32
call DelayFrames
pop af
--- a/engine/overworld/npc_movement.asm
+++ b/engine/overworld/npc_movement.asm
@@ -163,10 +163,10 @@
PewterMovementScript_WalkToMuseum: ; 1a514 (6:6514)
ld a, BANK(Music_MuseumGuy)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, [wSpriteIndex]
swap a
@@ -219,10 +219,10 @@
PewterMovementScript_WalkToGym: ; 1a581 (6:6581)
ld a, BANK(Music_MuseumGuy)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, [wSpriteIndex]
swap a
--- a/engine/overworld/oaks_aide.asm
+++ b/engine/overworld/oaks_aide.asm
@@ -4,45 +4,45 @@
call YesNoChoice
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_59086
+ jr nz, .choseNo
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e]
- ld [$ffdd], a
+ ld a, [wNumSetBits]
+ ld [hOaksAideNumMonsOwned], a
ld b, a
- ld a, [$ffdb]
+ ld a, [hOaksAideRequirement]
cp b
- jr z, .asm_59059
- jr nc, .asm_5907c
-.asm_59059
+ jr z, .giveItem
+ jr nc, .notEnoughOwnedMons
+.giveItem
ld hl, OaksAideHereYouGoText
call PrintText
- ld a, [$ffdc]
+ ld a, [hOaksAideItemReward]
ld b, a
ld c, 1
call GiveItem
- jr nc, .BagFull
+ jr nc, .bagFull
ld hl, OaksAideGotItemText
call PrintText
ld a, $1
- jr .asm_5908e
-.BagFull
+ jr .done
+.bagFull
ld hl, OaksAideNoRoomText
call PrintText
xor a
- jr .asm_5908e
-.asm_5907c
+ jr .done
+.notEnoughOwnedMons
ld hl, OaksAideUhOhText
call PrintText
ld a, $80
- jr .asm_5908e
-.asm_59086
+ jr .done
+.choseNo
ld hl, OaksAideComeBackText
call PrintText
ld a, $ff
-.asm_5908e
- ld [$ffdb], a
+.done
+ ld [hOaksAideResult], a
ret
OaksAideHiText: ; 59091 (16:5091)
--- a/engine/overworld/pokecenter.asm
+++ b/engine/overworld/pokecenter.asm
@@ -24,12 +24,12 @@
predef HealParty
callba AnimateHealingMachine ; do the healing machine animation
xor a
- ld [wMusicHeaderPointer], a
- ld a, [wc0f0]
- ld [wc0ef], a
- ld a, [wd35b]
- ld [wcfca], a
- ld [wc0ee], a
+ ld [wAudioFadeOutControl], a
+ ld a, [wAudioSavedROMBank]
+ ld [wAudioROMBank], a
+ ld a, [wMapMusicSoundID]
+ ld [wLastMusicSoundID], a
+ ld [wNewSoundID], a
call PlaySound
ld hl, PokemonFightingFitText
call PrintText
--- a/engine/pokedex_rating.asm
+++ b/engine/pokedex_rating.asm
@@ -2,18 +2,18 @@
ld hl, wPokedexSeen
ld b, wPokedexSeenEnd - wPokedexSeen
call CountSetBits
- ld a, [wd11e] ; result of CountSetBits (seen count)
- ld [$FFDB], a
+ ld a, [wNumSetBits]
+ ld [hDexRatingNumMonsSeen], a
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e] ; result of CountSetBits (own count)
- ld [$FFDC], a
+ ld a, [wNumSetBits]
+ ld [hDexRatingNumMonsOwned], a
ld hl, DexRatingsTable
.findRating
ld a, [hli]
ld b, a
- ld a, [$FFDC] ; number of pokemon owned
+ ld a, [hDexRatingNumMonsOwned]
cp b
jr c, .foundRating
inc hl
@@ -24,7 +24,7 @@
ld h, [hl]
ld l, a ; load text pointer into hl
CheckAndResetEventA EVENT_HALL_OF_FAME_DEX_RATING
- jr nz, .label3
+ jr nz, .hallOfFame
push hl
ld hl, PokedexRatingText_441cc
call PrintText
@@ -31,23 +31,23 @@
pop hl
call PrintText
callba PlayPokedexRatingSfx
- jp WaitForTextScrollButtonPress ; wait for button press
-.label3
+ jp WaitForTextScrollButtonPress
+.hallOfFame
ld de, wcc5b
- ld a, [$FFDB]
+ ld a, [hDexRatingNumMonsSeen]
ld [de], a
inc de
- ld a, [$FFDC]
+ ld a, [hDexRatingNumMonsOwned]
ld [de], a
inc de
-.label4
+.copyRatingTextLoop
ld a, [hli]
- cp a, $50
- jr z, .label5
+ cp a, "@"
+ jr z, .doneCopying
ld [de], a
inc de
- jr .label4
-.label5
+ jr .copyRatingTextLoop
+.doneCopying
ld [de], a
ret
--- a/engine/slot_machine.asm
+++ b/engine/slot_machine.asm
@@ -411,7 +411,7 @@
call PrintText
.done
xor a
- ld [wc002], a
+ ld [wMuteAudioAndPauseMusic], a
ret
.rollWheel3DownByOneSymbol
call SlotMachine_AnimWheel3
@@ -654,7 +654,7 @@
SlotMachine_PayCoinsToPlayer: ; 3776b (d:776b)
ld a, $1
- ld [wc002], a
+ ld [wMuteAudioAndPauseMusic], a
call WaitForSoundToFinish
; Put 1 in the temp coins variable. This value is added to the player's coins
--- a/engine/titlescreen.asm
+++ b/engine/titlescreen.asm
@@ -18,8 +18,8 @@
ld [hli], a
ld [hl], a
ld a, BANK(Music_TitleScreen)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
DisplayTitleScreen: ; 42dd (1:42dd)
call GBPalWhiteOut
@@ -212,7 +212,7 @@
call Delay3
call WaitForSoundToFinish
ld a, MUSIC_TITLE_SCREEN
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
xor a
ld [wcc5b], a
--- a/home.asm
+++ b/home.asm
@@ -240,7 +240,7 @@
; loads pokemon data from one of multiple sources to wLoadedMon
-; loads base stats to W_MONHDEXNUM
+; loads base stats to W_MONHEADER
; INPUT:
; [wWhichPokemon] = index of pokemon within party/box
; [wMonDataLocation] = source
@@ -251,7 +251,7 @@
; OUTPUT:
; [wcf91] = pokemon ID
; wLoadedMon = base address of pokemon data
-; W_MONHDEXNUM = base address of base stats
+; W_MONHEADER = base address of base stats
LoadMonData:: ; 1372 (0:1372)
jpab LoadMonData_
@@ -332,9 +332,9 @@
ld a, [hli]
ld b, a ; cry id
ld a, [hli]
- ld [wc0f1], a
+ ld [wFrequencyModifier], a
ld a, [hl]
- ld [wc0f2], a
+ ld [wTempoModifier], a
call BankswitchBack
; Cry headers have 3 channels,
@@ -551,7 +551,7 @@
ld a,[hl]
ret
-; copies the base stat data of a pokemon to W_MONHDEXNUM (W_MONHEADER)
+; copies the base stat data of a pokemon to W_MONHEADER
; INPUT:
; [wd0b5] = pokemon ID
GetMonHeader:: ; 1537 (0:1537)
@@ -606,7 +606,7 @@
call FarCopyData
.done
ld a,[wd0b5]
- ld [W_MONHDEXNUM],a
+ ld [W_MONHINDEX],a
pop af
ld [wd11e],a
pop hl
@@ -998,8 +998,8 @@
xor a
jp FillMemory
-Func_28cb:: ; 28cb (0:28cb)
- ld a, [wMusicHeaderPointer]
+FadeOutAudio:: ; 28cb (0:28cb)
+ ld a, [wAudioFadeOutControl]
and a
jr nz, .asm_28dc
ld a, [wd72c]
@@ -1006,19 +1006,19 @@
bit 1, a
ret nz
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
ret
.asm_28dc
- ld a, [wcfc9]
+ ld a, [wAudioFadeOutCounter]
and a
- jr z, .asm_28e7
+ jr z, .counterReachedZero
dec a
- ld [wcfc9], a
+ ld [wAudioFadeOutCounter], a
ret
-.asm_28e7
- ld a, [wcfc8]
- ld [wcfc9], a
- ld a, [$ff24]
+.counterReachedZero
+ ld a, [wAudioFadeOutCounterReloadValue]
+ ld [wAudioFadeOutCounter], a
+ ld a, [rNR50]
and a
jr z, .asm_2903
ld b, a
@@ -1031,20 +1031,20 @@
dec a
swap a
or c
- ld [$ff24], a
+ ld [rNR50], a
ret
.asm_2903
- ld a, [wMusicHeaderPointer]
+ ld a, [wAudioFadeOutControl]
ld b, a
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
- ld a, [wc0f0]
- ld [wc0ef], a
+ ld a, [wAudioSavedROMBank]
+ ld [wAudioROMBank], a
ld a, b
- ld [wc0ee], a
+ ld [wNewSoundID], a
jp PlaySound
; this function is used to display sign messages, sprite dialog, etc.
@@ -1292,7 +1292,7 @@
; hl = address of string of bytes
; b = length of string of bytes
; OUTPUT:
-; [wd11e] = number of set bits
+; [wNumSetBits] = number of set bits
CountSetBits:: ; 2b7f (0:2b7f)
ld c,0
.loop
@@ -1309,7 +1309,7 @@
dec b
jr nz,.loop
ld a,c
- ld [wd11e],a ; store number of set bits
+ ld [wNumSetBits],a
ret
; subtracts the amount the player paid from their money
@@ -2604,12 +2604,12 @@
and a
ret nz
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, $ff
call PlaySound
ld a, BANK(Music_MeetEvilTrainer)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, [wEngagedTrainerClass]
ld b, a
ld hl, EvilTrainerList
@@ -2634,7 +2634,7 @@
.maleTrainer
ld a, MUSIC_MEET_MALE_TRAINER
.PlaySound
- ld [wc0ee], a
+ ld [wNewSoundID], a
jp PlaySound
INCLUDE "data/trainer_types.asm"
@@ -3217,8 +3217,8 @@
and $80
ret nz
push hl
-.asm_374f
- ld hl, wc02a
+.waitLoop
+ ld hl, wChannelSoundIDs + CH4
xor a
or [hl]
inc hl
@@ -3226,7 +3226,7 @@
inc hl
inc hl
or [hl]
- jr nz, .asm_374f
+ jr nz, .waitLoop
pop hl
ret
@@ -3313,9 +3313,9 @@
call CopyData
.gotPtr
ld a,e
- ld [wcf8d],a
+ ld [wUnusedCF8D],a
ld a,d
- ld [wcf8e],a
+ ld [wUnusedCF8D + 1],a
pop de
pop bc
pop hl
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -3,75 +3,95 @@
xor a
ld c, a
ld d, a
- ld [wcfca], a
- jr Func_2324
+ ld [wLastMusicSoundID], a
+ jr PlayDefaultMusicCommon
-Func_2312:: ; 2312 (0:2312)
- ld c, $a
- ld d, $0
+PlayDefaultMusicFadeOutCurrent:: ; 2312 (0:2312)
+; Fade out the current music and then play the default music.
+ ld c, 10
+ ld d, 0
ld a, [wd72e]
- bit 5, a
- jr z, Func_2324
+ bit 5, a ; has a battle just ended?
+ jr z, PlayDefaultMusicCommon
xor a
- ld [wcfca], a
- ld c, $8
+ ld [wLastMusicSoundID], a
+ ld c, 8
ld d, c
-Func_2324:: ; 2324 (0:2324)
+
+PlayDefaultMusicCommon:: ; 2324 (0:2324)
ld a, [wWalkBikeSurfState]
and a
- jr z, .asm_2343
+ jr z, .walking
cp $2
- jr z, .asm_2332
+ jr z, .surfing
ld a, MUSIC_BIKE_RIDING
- jr .asm_2334
-.asm_2332
+ jr .next
+
+.surfing
ld a, MUSIC_SURFING
-.asm_2334
+
+.next
ld b, a
ld a, d
- and a
+ and a ; should current music be faded out first?
ld a, BANK(Music_BikeRiding)
- jr nz, .asm_233e
- ld [wc0ef], a
-.asm_233e
- ld [wc0f0], a
- jr .asm_234c
-.asm_2343
- ld a, [wd35b]
+ jr nz, .next2
+
+; Only change the audio ROM bank if the current music isn't going to be faded
+; out before the default music begins.
+ ld [wAudioROMBank], a
+
+.next2
+; [wAudioSavedROMBank] will be copied to [wAudioROMBank] after fading out the
+; current music (if the current music is faded out).
+ ld [wAudioSavedROMBank], a
+ jr .next3
+
+.walking
+ ld a, [wMapMusicSoundID]
ld b, a
- call Func_2385
- jr c, .asm_2351
-.asm_234c
- ld a, [wcfca]
- cp b
- ret z
-.asm_2351
+ call CompareMapMusicBankWithCurrentBank
+ jr c, .next4
+
+.next3
+ ld a, [wLastMusicSoundID]
+ cp b ; is the default music already playing?
+ ret z ; if so, do nothing
+
+.next4
ld a, c
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, b
- ld [wcfca], a
- ld [wc0ee], a
+ ld [wLastMusicSoundID], a
+ ld [wNewSoundID], a
jp PlaySound
-Func_235f:: ; 235f (0:235f)
- ld a, [wc0ef]
+UpdateMusic6Times:: ; 235f (0:235f)
+; This is called when entering a map, before fading out the current music and
+; playing the default music (i.e. the map's music or biking/surfing music).
+ ld a, [wAudioROMBank]
ld b, a
cp BANK(Audio1_UpdateMusic)
jr nz, .checkForAudio2
-.audio1
+
+; audio 1
ld hl, Audio1_UpdateMusic
- jr .asm_2378
+ jr .next
+
.checkForAudio2
cp BANK(Audio2_UpdateMusic)
jr nz, .audio3
-.audio2
+
+; audio 2
ld hl, Audio2_UpdateMusic
- jr .asm_2378
+ jr .next
+
.audio3
ld hl, Audio3_UpdateMusic
-.asm_2378
- ld c, $6
-.asm_237a
+
+.next
+ ld c, 6
+.loop
push bc
push hl
call Bankswitch
@@ -78,37 +98,44 @@
pop hl
pop bc
dec c
- jr nz, .asm_237a
+ jr nz, .loop
ret
-Func_2385:: ; 2385 (0:2385)
- ld a, [wd35c]
+CompareMapMusicBankWithCurrentBank:: ; 2385 (0:2385)
+; Compares the map music's audio ROM bank with the current audio ROM bank
+; and updates the audio ROM bank variables.
+; Returns whether the banks are different in carry.
+ ld a, [wMapMusicROMBank]
ld e, a
- ld a, [wc0ef]
+ ld a, [wAudioROMBank]
cp e
- jr nz, .asm_2394
- ld [wc0f0], a
+ jr nz, .differentBanks
+ ld [wAudioSavedROMBank], a
and a
ret
-.asm_2394
- ld a, c
+.differentBanks
+ ld a, c ; this is a fade-out counter value and it's always non-zero
and a
ld a, e
- jr nz, .asm_239c
- ld [wc0ef], a
-.asm_239c
- ld [wc0f0], a
+ jr nz, .next
+; If the fade-counter is non-zero, we don't change the audio ROM bank because
+; it's needed to keep playing the music as it fades out. The FadeOutAudio
+; routine will take care of copying [wAudioSavedROMBank] to [wAudioROMBank]
+; when the music has faded out.
+ ld [wAudioROMBank], a
+.next
+ ld [wAudioSavedROMBank], a
scf
ret
PlayMusic:: ; 23a1 (0:23a1)
ld b, a
- ld [wc0ee], a
+ ld [wNewSoundID], a
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, c
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, b
; plays music specified by a. If value is $ff, music is stopped
@@ -117,66 +144,74 @@
push de
push bc
ld b, a
- ld a, [wc0ee]
+ ld a, [wNewSoundID]
and a
- jr z, .asm_23c8
+ jr z, .next
xor a
- ld [wc02a], a
- ld [wc02b], a
- ld [wc02c], a
- ld [wc02d], a
-.asm_23c8
- ld a, [wMusicHeaderPointer]
- and a
- jr z, .asm_23e3
- ld a, [wc0ee]
- and a
- jr z, .asm_2425
+ ld [wChannelSoundIDs + CH4], a
+ ld [wChannelSoundIDs + CH5], a
+ ld [wChannelSoundIDs + CH6], a
+ ld [wChannelSoundIDs + CH7], a
+.next
+ ld a, [wAudioFadeOutControl]
+ and a ; has a fade-out length been specified?
+ jr z, .noFadeOut
+ ld a, [wNewSoundID]
+ and a ; is the new sound ID 0?
+ jr z, .done ; if so, do nothing
xor a
- ld [wc0ee], a
- ld a, [wcfca]
- cp $ff
- jr nz, .asm_2414
+ ld [wNewSoundID], a
+ ld a, [wLastMusicSoundID]
+ cp $ff ; has the music been stopped?
+ jr nz, .fadeOut ; if not, fade out the current music
+; If it has been stopped, start playing the new music immediately.
xor a
- ld [wMusicHeaderPointer], a
-.asm_23e3
+ ld [wAudioFadeOutControl], a
+.noFadeOut
xor a
- ld [wc0ee], a
+ ld [wNewSoundID], a
ld a, [H_LOADEDROMBANK]
- ld [$ffb9], a
- ld a, [wc0ef]
+ ld [hSavedROMBank], a
+ ld a, [wAudioROMBank]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
- cp BANK(Audio1_9876)
+ cp BANK(Audio1_PlaySound)
jr nz, .checkForAudio2
-.audio1
+
+; audio 1
ld a, b
- call Audio1_9876
- jr .asm_240b
+ call Audio1_PlaySound
+ jr .next2
+
.checkForAudio2
- cp BANK(Audio2_22035)
+ cp BANK(Audio2_PlaySound)
jr nz, .audio3
-.audio2
+
+; audio 2
ld a, b
- call Audio2_22035
- jr .asm_240b
+ call Audio2_PlaySound
+ jr .next2
+
.audio3
ld a, b
- call Audio3_7d8ea
-.asm_240b
- ld a, [$ffb9]
+ call Audio3_PlaySound
+
+.next2
+ ld a, [hSavedROMBank]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
- jr .asm_2425
-.asm_2414
+ jr .done
+
+.fadeOut
ld a, b
- ld [wcfca], a
- ld a, [wMusicHeaderPointer]
- ld [wcfc8], a
- ld [wcfc9], a
+ ld [wLastMusicSoundID], a
+ ld a, [wAudioFadeOutControl]
+ ld [wAudioFadeOutCounterReloadValue], a
+ ld [wAudioFadeOutCounter], a
ld a, b
- ld [wMusicHeaderPointer], a
-.asm_2425
+ ld [wAudioFadeOutControl], a
+
+.done
pop bc
pop de
pop hl
--- a/home/init.asm
+++ b/home/init.asm
@@ -98,8 +98,8 @@
predef LoadSGB
ld a, BANK(SFX_Shooting_Star)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, $9c
ld [H_AUTOBGTRANSFERDEST + 1], a
xor a
@@ -127,11 +127,11 @@
StopAllSounds::
ld a, BANK(Audio1_UpdateMusic)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
xor a
- ld [wMusicHeaderPointer], a
- ld [wc0ee], a
- ld [wcfca], a
+ ld [wAudioFadeOutControl], a
+ ld [wNewSoundID], a
+ ld [wLastMusicSoundID], a
dec a
jp PlaySound
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -658,7 +658,7 @@
ld [wCurrentTileBlockMapViewPointer + 1],a
.loadNewMap ; load the connected map that was entered
call LoadMapHeader
- call Func_2312 ; music
+ call PlayDefaultMusicFadeOutCurrent
ld b,$09
call GoPAL_SET
; Since the sprite set shouldn't change, this will just update VRAM slots at
@@ -750,16 +750,16 @@
ld [MBC1RomBank], a
call ResetStatusAndHalveMoneyOnBlackout
call SpecialWarpIn
- call Func_2312
+ call PlayDefaultMusicFadeOutCurrent
jp SpecialEnterMap
StopMusic::
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.wait
- ld a, [wMusicHeaderPointer]
+ ld a, [wAudioFadeOutControl]
and a
jr nz, .wait
jp StopAllSounds
@@ -1224,7 +1224,7 @@
call CheckTilePassable
jr nc,.noCollision
.collision
- ld a,[wc02a]
+ ld a,[wChannelSoundIDs + CH4]
cp a,SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
ld a,SFX_COLLISION
@@ -1927,7 +1927,7 @@
jr z,.stopSurfing ; stop surfing if the tile is passable
jr .loop
.collision
- ld a,[wc02a]
+ ld a,[wChannelSoundIDs + CH4]
cp a,SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
ld a,SFX_COLLISION
@@ -2279,9 +2279,9 @@
add hl,bc
add hl,bc
ld a,[hli]
- ld [wd35b],a ; music 1
+ ld [wMapMusicSoundID],a ; music 1
ld a,[hl]
- ld [wd35c],a ; music 2
+ ld [wMapMusicROMBank],a ; music 2
pop af
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a
@@ -2352,8 +2352,8 @@
ld a,[W_FLAGS_D733]
bit 1,a
jr nz,.restoreRomBank
- call Func_235f ; music related
- call Func_2312 ; music related
+ call UpdateMusic6Times
+ call PlayDefaultMusicFadeOutCurrent
.restoreRomBank
pop af
ld [H_LOADEDROMBANK],a
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -38,21 +38,21 @@
ld a, [H_VBLANKOCCURRED]
and a
- jr z, .vblanked
+ jr z, .skipZeroing
xor a
ld [H_VBLANKOCCURRED], a
-.vblanked
+.skipZeroing
ld a, [H_FRAMECOUNTER]
and a
- jr z, .decced
+ jr z, .skipDec
dec a
ld [H_FRAMECOUNTER], a
-.decced
- call Func_28cb
+.skipDec
+ call FadeOutAudio
- ld a, [wc0ef] ; music ROM bank
+ ld a, [wAudioROMBank] ; music ROM bank
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
--- a/hram.asm
+++ b/hram.asm
@@ -182,8 +182,10 @@
hJoy6 EQU $FFB6
hJoy7 EQU $FFB7
-H_LOADEDROMBANK EQU $FFB8
+H_LOADEDROMBANK EQU $FFB8
+hSavedROMBank EQU $FFB9
+
; is automatic background transfer during V-blank enabled?
; if nonzero, yes
; if zero, no
@@ -272,6 +274,19 @@
hGymGateIndex EQU $FFDB
hGymTrashCanRandNumMask EQU $FFDB
+
+hDexRatingNumMonsSeen EQU $FFDB
+hDexRatingNumMonsOwned EQU $FFDC
+
+; $00 = bag full
+; $01 = got item
+; $80 = didn't meet required number of owned mons
+; $FF = player cancelled
+hOaksAideResult EQU $FFDB
+
+hOaksAideRequirement EQU $FFDB ; required number of owned mons
+hOaksAideItemReward EQU $FFDC
+hOaksAideNumMonsOwned EQU $FFDD
hItemToRemoveID EQU $FFDB
hItemToRemoveIndex EQU $FFDC
--- a/main.asm
+++ b/main.asm
@@ -86,7 +86,7 @@
; 2: boxmon
; 3: daycaremon
; Return monster id at wcf91 and its data at wLoadedMon.
-; Also load base stats at W_MONHDEXNUM for convenience.
+; Also load base stats at W_MONHEADER for convenience.
ld a, [wDayCareMonSpecies]
ld [wcf91], a
@@ -284,7 +284,7 @@
ld [hld], a ; zero [$c1ic] (directions in which collisions occurred)
ld a, [$ff91]
- ld [hld], a ; [$c1ib] = adjusted X coordiate
+ ld [hld], a ; [$c1ib] = adjusted X coordinate
ld a, [$ff90]
ld [hl], a ; [$c1ia] = adjusted Y coordinate
--- a/scripts/celadonmansion3.asm
+++ b/scripts/celadonmansion3.asm
@@ -30,7 +30,7 @@
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e]
+ ld a, [wNumSetBits]
cp 150
jr nc, .CompletedDex
ld hl, .GameDesigner
--- a/scripts/ceruleancity.asm
+++ b/scripts/ceruleancity.asm
@@ -65,7 +65,7 @@
and a
jr z, .asm_19512
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.asm_19512
ld c, BANK(Music_MeetRival)
@@ -172,7 +172,7 @@
ld [hSpriteIndexOrTextID], a
call DisplayTextID
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStart
ld a, $1
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -511,7 +511,7 @@
ld [hJoyHeld], a
call EnableAutoTextBoxDrawing
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStart
ld a, $15
@@ -612,7 +612,7 @@
call FillMemory
ld [hl], $ff
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStart
ld a, $1
@@ -969,8 +969,8 @@
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e]
- cp $2
+ ld a, [wNumSetBits]
+ cp 2
jr c, .asm_1d279
CheckEvent EVENT_GOT_POKEDEX
jr z, .asm_1d279
--- a/scripts/pewterpokecenter.asm
+++ b/scripts/pewterpokecenter.asm
@@ -59,9 +59,9 @@
ld c, 24
call DelayFrames
- ld a, [wc026]
+ ld a, [wChannelSoundIDs]
ld b, a
- ld a, [wc027]
+ ld a, [wChannelSoundIDs + CH1]
or b
jr nz, .loop
--- a/scripts/pokemontower2.asm
+++ b/scripts/pokemontower2.asm
@@ -23,7 +23,7 @@
call ArePlayerCoordsInArray
ret nc
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld c, BANK(Music_MeetRival)
ld a, MUSIC_MEET_RIVAL
@@ -77,7 +77,7 @@
ld [H_SPRITEINDEX], a
call MoveSprite
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStart
ld a, $2
--- a/scripts/redshouse1f.asm
+++ b/scripts/redshouse1f.asm
@@ -29,14 +29,14 @@
call ReloadMapData
predef HealParty
ld a, MUSIC_PKMN_HEALED
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.next
- ld a, [wc026]
+ ld a, [wChannelSoundIDs]
cp MUSIC_PKMN_HEALED
jr z, .next
- ld a, [wd35b]
- ld [wc0ee], a
+ ld a, [wMapMusicSoundID]
+ ld [wNewSoundID], a
call PlaySound
call GBFadeInFromWhite
ld hl, MomHealText2
--- a/scripts/route11gateupstairs.asm
+++ b/scripts/route11gateupstairs.asm
@@ -20,9 +20,9 @@
CheckEvent EVENT_GOT_ITEMFINDER, 1
jr c, .asm_4949b
ld a, 30 ; pokemon needed
- ld [$ffdb], a
+ ld [hOaksAideRequirement], a
ld a, ITEMFINDER ; oak's aide reward
- ld [$ffdc], a
+ ld [hOaksAideItemReward], a
ld [wd11e], a
call GetItemName
ld h, d
@@ -30,8 +30,8 @@
ld de, wcc5b
ld bc, $000d
call CopyData
- predef OaksAideScript ; call oak's aide script
- ld a, [$ffdb]
+ predef OaksAideScript
+ ld a, [hOaksAideResult]
dec a
jr nz, .asm_494a1
SetEvent EVENT_GOT_ITEMFINDER
--- a/scripts/route15gateupstairs.asm
+++ b/scripts/route15gateupstairs.asm
@@ -10,9 +10,9 @@
CheckEvent EVENT_GOT_EXP_ALL
jr nz, .asm_49683
ld a, 50 ; pokemon needed
- ld [$ffdb], a
+ ld [hOaksAideRequirement], a
ld a, EXP__ALL ; oak's aide reward
- ld [$ffdc], a
+ ld [hOaksAideItemReward], a
ld [wd11e], a
call GetItemName
ld hl, wcd6d
@@ -19,8 +19,8 @@
ld de, wcc5b
ld bc, $000d
call CopyData
- predef OaksAideScript ; call oak's aide script
- ld a, [$ffdb]
+ predef OaksAideScript
+ ld a, [hOaksAideResult]
cp $1
jr nz, .asm_49689
SetEvent EVENT_GOT_EXP_ALL
--- a/scripts/route22.asm
+++ b/scripts/route22.asm
@@ -89,7 +89,7 @@
and a
jr z, .asm_50f4e
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.asm_50f4e
ld c, BANK(Music_MeetRival)
@@ -168,7 +168,7 @@
ld [hSpriteIndexOrTextID], a
call DisplayTextID
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStart
ld a, [wcf0d]
@@ -242,11 +242,11 @@
and a
jr z, .skipYVisibilityTesta
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.skipYVisibilityTesta
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateTempo
ld a, $2
@@ -327,7 +327,7 @@
ld [hSpriteIndexOrTextID], a
call DisplayTextID
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStartAndTempo
ld a, [wcf0d]
--- a/scripts/route2gate.asm
+++ b/scripts/route2gate.asm
@@ -10,9 +10,9 @@
CheckEvent EVENT_GOT_HM05
jr nz, .asm_5d60d
ld a, 10 ; pokemon needed
- ld [$ffdb], a
+ ld [hOaksAideRequirement], a
ld a, HM_05 ; oak's aide reward
- ld [$ffdc], a
+ ld [hOaksAideItemReward], a
ld [wd11e], a
call GetItemName
ld hl, wcd6d
@@ -19,8 +19,8 @@
ld de, wcc5b
ld bc, $000d
call CopyData
- predef OaksAideScript ; call oak's aide script
- ld a, [$ffdb]
+ predef OaksAideScript
+ ld a, [hOaksAideResult]
cp $1
jr nz, .asm_5d613
SetEvent EVENT_GOT_HM05
--- a/scripts/silphco7.asm
+++ b/scripts/silphco7.asm
@@ -131,7 +131,7 @@
ld a, PLAYER_DIR_DOWN
ld [wPlayerMovingDirection], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld c, BANK(Music_MeetRival)
ld a, MUSIC_MEET_RIVAL
@@ -220,7 +220,7 @@
ld [hSpriteIndexOrTextID], a
call DisplayTextID
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStart
ld de, MovementData_51d1d
--- a/scripts/ssanne2.asm
+++ b/scripts/ssanne2.asm
@@ -25,7 +25,7 @@
call ArePlayerCoordsInArray
ret nc
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld c, BANK(Music_MeetRival)
ld a, MUSIC_MEET_RIVAL
@@ -146,7 +146,7 @@
ld [H_SPRITEINDEX], a
call MoveSprite
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
callba Music_RivalAlternateStart
ld a, $3
--- a/scripts/ssanne7.asm
+++ b/scripts/ssanne7.asm
@@ -44,21 +44,21 @@
SSAnne7RubText: ; 618ec (18:58ec)
TX_FAR _SSAnne7RubText
TX_ASM
- ld a, [wc0ef]
+ ld a, [wAudioROMBank]
cp BANK(Audio3_UpdateMusic)
- ld [wc0f0], a
+ ld [wAudioSavedROMBank], a
jr nz, .asm_61908
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, Bank(Music_PkmnHealed)
- ld [wc0ef], a
+ ld [wAudioROMBank], a
.asm_61908
ld a, MUSIC_PKMN_HEALED
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.asm_61910
- ld a, [wc026]
+ ld a, [wChannelSoundIDs]
cp MUSIC_PKMN_HEALED
jr z, .asm_61910
call PlayDefaultMusic
--- a/scripts/vermiliondock.asm
+++ b/scripts/vermiliondock.asm
@@ -40,7 +40,7 @@
SetEventForceReuseHL EVENT_SS_ANNE_LEFT
ld a, $ff
ld [wJoyIgnore], a
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld c, BANK(Music_Surfing)
ld a, MUSIC_SURFING
--- a/text.asm
+++ b/text.asm
@@ -94,7 +94,7 @@
cont "AIDE!"
para "If you caught @"
- TX_NUM $ffdb, 1, 3
+ TX_NUM hOaksAideRequirement, 1, 3
db $0
line "kinds of #MON,"
cont "I'm supposed to"
@@ -106,7 +106,7 @@
para "So, ", $52, "! Have"
line "you caught at"
cont "least @"
- TX_NUM $ffdb, 1, 3
+ TX_NUM hOaksAideRequirement, 1, 3
text " kinds of"
cont "#MON?"
done
@@ -115,12 +115,12 @@
text "Let's see..."
line "Uh-oh! You have"
cont "caught only @"
- TX_NUM $ffdd, 1, 3
+ TX_NUM hOaksAideNumMonsOwned, 1, 3
db $0
cont "kinds of #MON!"
para "You need @"
- TX_NUM $ffdb, 1, 3
+ TX_NUM hOaksAideRequirement, 1, 3
text " kinds"
line "if you want the"
cont "@"
@@ -132,7 +132,7 @@
text "Oh. I see."
para "When you get @"
- TX_NUM $ffdb, 1, 3
+ TX_NUM hOaksAideRequirement, 1, 3
db $0
line "kinds, come back"
cont "for @"
@@ -143,7 +143,7 @@
_OaksAideHereYouGoText:: ; 8028c (20:428c)
text "Great! You have"
line "caught @"
- TX_NUM $ffdd, 1, 3
+ TX_NUM hOaksAideNumMonsOwned, 1, 3
text " kinds "
cont "of #MON!"
cont "Congratulations!"
--- a/text/maps/oaks_lab.asm
+++ b/text/maps/oaks_lab.asm
@@ -547,10 +547,10 @@
line "letion is:"
para "@"
- TX_NUM $ffdb, 1, 3
+ TX_NUM hDexRatingNumMonsSeen, 1, 3
text " #MON seen"
line "@"
- TX_NUM $ffdc, 1, 3
+ TX_NUM hDexRatingNumMonsOwned, 1, 3
text " #MON owned"
para "PROF.OAK's"
--- a/wram.asm
+++ b/wram.asm
@@ -61,68 +61,148 @@
SECTION "WRAM Bank 0", WRAM0
-wc000:: ds 1
-wc001:: ds 1
-wc002:: ds 1
-wc003:: ds 1
-wc004:: ds 1
-wc005:: ds 1
-wc006:: ds 8
-wc00e:: ds 4
-wc012:: ds 4
-wc016:: ds 16
-wc026:: ds 1
-wc027:: ds 1
-wc028:: ds 2
-wc02a:: ds 1
-wc02b:: ds 1
-wc02c:: ds 1
-wc02d:: ds 1
-wc02e:: ds 8
-wc036:: ds 8
-wc03e:: ds 8
-wc046:: ds 8
-wc04e:: ds 8
-wc056:: ds 8
-wc05e:: ds 8
-wc066:: ds 8
-wc06e:: ds 8
-wc076:: ds 8
-wc07e:: ds 8
-wc086:: ds 8
-wc08e:: ds 8
-wc096:: ds 8
-wc09e:: ds 8
-wc0a6:: ds 8
-wc0ae:: ds 8
-wc0b6:: ds 8
-wc0be:: ds 8
-wc0c6:: ds 8
-wc0ce:: ds 1
-wc0cf:: ds 1
-wc0d0:: ds 1
-wc0d1:: ds 1
-wc0d2:: ds 1
-wc0d3:: ds 1
-wc0d4:: ds 1
-wc0d5:: ds 1
-wc0d6:: ds 8
-wc0de:: ds 8
-wc0e6:: ds 1
-wc0e7:: ds 1
-wc0e8:: ds 1
-wc0e9:: ds 1
-wc0ea:: ds 1
-wc0eb:: ds 1
-wc0ec:: ds 1
-wc0ed:: ds 1
-wc0ee:: ds 1
-wc0ef:: ds 1
-wc0f0:: ds 1
-wc0f1:: ds 1
-wc0f2:: ds 14
+wUnusedC000:: ; c000
+ ds 1
+wSoundID:: ; c001
+ ds 1
+wMuteAudioAndPauseMusic:: ; c002
+; bit 7: whether sound has been muted
+; all bits: whether the effective is active
+; Store 1 to activate effect (any value in the range [1, 127] works).
+; All audio is muted and music is paused. Sfx continues playing until it
+; ends normally.
+; Store 0 to resume music.
+ ds 1
+
+wDisableChannelOutputWhenSfxEnds:: ; c003
+ ds 1
+
+wStereoPanning:: ; c004
+ ds 1
+
+wSavedVolume:: ; c005
+ ds 1
+
+wChannelCommandPointers:: ; c006
+ ds 16
+
+wChannelReturnAddresses:: ; c016
+ ds 16
+
+wChannelSoundIDs:: ; c026
+ ds 8
+
+wChannelFlags1:: ; c02e
+ ds 8
+
+wChannelFlags2:: ; c036
+ ds 8
+
+wChannelDuties:: ; c03e
+ ds 8
+
+wChannelDutyCycles:: ; c046
+ ds 8
+
+wChannelVibratoDelayCounters:: ; c04e
+; reloaded at the beginning of a note. counts down until the vibrato begins.
+ ds 8
+
+wChannelVibratoExtents:: ; c056
+ ds 8
+
+wChannelVibratoRates:: ; c05e
+; high nybble is rate (counter reload value) and low nybble is counter.
+; time between applications of vibrato.
+ ds 8
+
+wChannelFrequencyLowBytes:: ; c066
+ ds 8
+
+wChannelVibratoDelayCounterReloadValues:: ; c06e
+; delay of the beginning of the vibrato from the start of the note
+ ds 8
+
+wChannelPitchBendLengthModifiers:: ; c076
+ ds 8
+
+wChannelPitchBendFrequencySteps:: ; c07e
+ ds 8
+
+wChannelPitchBendFrequencyStepsFractionalPart:: ; c086
+ ds 8
+
+wChannelPitchBendCurrentFrequencyFractionalPart:: ; c08e
+ ds 8
+
+wChannelPitchBendCurrentFrequencyHighBytes:: ; c096
+ ds 8
+
+wChannelPitchBendCurrentFrequencyLowBytes:: ; c09e
+ ds 8
+
+wChannelPitchBendTargetFrequencyHighBytes:: ; c0a6
+ ds 8
+
+wChannelPitchBendTargetFrequencyLowBytes:: ; c0ae
+ ds 8
+
+wChannelNoteDelayCounters:: ; c0b6
+; Note delays are stored as 16-bit fixed-point numbers where the integer part
+; is 8 bits and the fractional part is 8 bits.
+ ds 8
+
+wChannelLoopCounters:: ; c0be
+ ds 8
+
+wChannelNoteSpeeds:: ; c0c6
+ ds 8
+
+wChannelNoteDelayCountersFractionalPart:: ; c0ce
+ ds 8
+
+wChannelOctaves:: ; c0d6
+ ds 8
+
+wChannelVolumes:: ; c0de
+; also includes fade for hardware channels that support it
+ ds 8
+
+wMusicWaveInstrument::
+ ds 1
+
+wSfxWaveInstrument::
+ ds 1
+
+wMusicTempo:: ; c0e8
+ ds 2
+
+wSfxTempo:: ; c0ea
+ ds 2
+
+wSfxHeaderPointer:: ; c0ec
+ ds 2
+
+wNewSoundID:: ; c0ee
+ ds 1
+
+wAudioROMBank:: ; c0ef
+ ds 1
+
+wAudioSavedROMBank:: ; c0f0
+ ds 1
+
+wFrequencyModifier:: ; c0f1
+ ds 1
+
+wTempoModifier:: ; c0f2
+ ds 1
+
+ ds 13
+
+
SECTION "Sprite State Data", WRAM0[$c100]
wSpriteStateData1:: ; c100
@@ -1226,8 +1306,10 @@
wListPointer:: ; cf8b
ds 2
-wcf8d:: ds 1 ; used in GetMonName
-wcf8e:: ds 1 ; also used in GetMonName (probably as a pointer)
+wUnusedCF8D:: ; cf8d
+; 2 bytes
+; used to store pointers, but never read
+ ds 2
wItemPrices:: ; cf8f
ds 2
@@ -1287,14 +1369,36 @@
; background tile number in front of the player (either 1 or 2 steps ahead)
ds 1
-wMusicHeaderPointer:: ; cfc7
-; (the current music channel address - $4000) / 3
+wAudioFadeOutControl:: ; cfc7
+; The desired fade counter reload value is stored here prior to calling
+; PlaySound in order to cause the current music to fade out before the new
+; music begins playing. Storing 0 causes no fade out to occur and the new music
+; to begin immediately.
+; This variable has another use related to fade-out, as well. PlaySound stores
+; the sound ID of the music that should be played after the fade-out is finished
+; in this variable. FadeOutAudio checks if it's non-zero every V-Blank and
+; fades out the current audio if it is. Once it has finished fading out the
+; audio, it zeroes this variable and starts playing the sound ID stored in it.
ds 1
-wcfc8:: ds 1 ; used with audio
-wcfc9:: ds 1 ; also used with audio
-wcfca:: ds 1 ; also used with audio too
+wAudioFadeOutCounterReloadValue:: ; cfc8
+ ds 1
+wAudioFadeOutCounter:: ; cfc9
+ ds 1
+
+wLastMusicSoundID:: ; cfca
+; This is used to determine whether the default music is already playing when
+; attempting to play the default music (in order to avoid restarting the same
+; music) and whether the music has already been stopped when attempting to
+; fade out the current music (so that the new music can be begin immediately
+; instead of waiting).
+; It sometimes contains the sound ID of the last music played, but it may also
+; contain $ff (if the music has been stopped) or 0 (because some routines zero
+; it in order to prevent assumptions from being made about the current state of
+; the music).
+ ds 1
+
wUpdateSpritesEnabled:: ; cfcb
; $00 = causes sprites to be hidden and the value to change to $ff
; $01 = enabled
@@ -1789,7 +1893,10 @@
ds 1
W_MONHEADER:: ; d0b8
-W_MONHDEXNUM:: ; d0b8
+
+W_MONHINDEX:: ; d0b8
+; In the ROM base stats data stucture, this is the dex number, but it is
+; overwritten with the internal index number after the header is copied to WRAM.
ds 1
W_MONHBASESTATS:: ; d0b9
@@ -1882,6 +1989,23 @@
; which will be the first mon sent out.
ds 1
+; lower nybble: number of shakes
+; upper nybble: number of animations to play
+wPokeBallAnimData:: ; d11e
+
+wUsingPPUp:: ; d11e
+
+wMaxPP:: ; d11e
+
+; 0 for player, non-zero for enemy
+wCalculateWhoseStats:: ; d11e
+
+wTypeEffectiveness:: ; d11e
+
+wMoveType:: ; d11e
+
+wNumSetBits:: ; d11e
+
wd11e:: ds 1 ; used as a Pokemon and Item storage value. Also used as an output value for CountSetBits
wForcePlayerToChooseMon:: ; d11f
@@ -2104,8 +2228,11 @@
wPlayerID:: ; d359
ds 2
-wd35b:: ds 1 ; used with audio stuff
-wd35c:: ds 1 ; storage for audio bank for current map?
+wMapMusicSoundID:: ; d35b
+ ds 1
+
+wMapMusicROMBank:: ; d35c
+ ds 1
wMapPalOffset:: ; d35d
; offset subtracted from FadePal4 to get the background and object palettes for the current map