mirror of https://github.com/pret/pokecrystal.git
Identified two magic numbers and cleaned up some comments (#783)
Improve the audio engine's comments and replace some magic numbers with constants
This commit is contained in:
parent
5e9d43e39b
commit
7b9d8767d4
|
@ -101,7 +101,7 @@ _UpdateSound::
|
||||||
ld hl, CHANNEL_NOTE_DURATION
|
ld hl, CHANNEL_NOTE_DURATION
|
||||||
add hl, bc
|
add hl, bc
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
cp $2 ; 1 or 0?
|
cp 2 ; 1 or 0?
|
||||||
jr c, .noteover
|
jr c, .noteover
|
||||||
dec [hl]
|
dec [hl]
|
||||||
jr .continue_sound_update
|
jr .continue_sound_update
|
||||||
|
@ -212,7 +212,7 @@ _UpdateSound::
|
||||||
UpdateChannels:
|
UpdateChannels:
|
||||||
ld hl, .ChannelFnPtrs
|
ld hl, .ChannelFnPtrs
|
||||||
ld a, [wCurChannel]
|
ld a, [wCurChannel]
|
||||||
and $7
|
maskbits NUM_CHANNELS
|
||||||
add a
|
add a
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, 0
|
ld d, 0
|
||||||
|
@ -1141,7 +1141,6 @@ ParseMusic:
|
||||||
jr z, .sound_ret
|
jr z, .sound_ret
|
||||||
cp FIRST_MUSIC_CMD
|
cp FIRST_MUSIC_CMD
|
||||||
jr c, .readnote
|
jr c, .readnote
|
||||||
; then it's a command
|
|
||||||
.readcommand
|
.readcommand
|
||||||
call ParseMusicCommand
|
call ParseMusicCommand
|
||||||
jr ParseMusic ; start over
|
jr ParseMusic ; start over
|
||||||
|
@ -1366,39 +1365,39 @@ ParseMusicCommand:
|
||||||
|
|
||||||
MusicCommands:
|
MusicCommands:
|
||||||
; entries correspond to audio constants (see macros/scripts/audio.asm)
|
; entries correspond to audio constants (see macros/scripts/audio.asm)
|
||||||
dw Music_Octave8 ; octave 8
|
dw Music_Octave8
|
||||||
dw Music_Octave7 ; octave 7
|
dw Music_Octave7
|
||||||
dw Music_Octave6 ; octave 6
|
dw Music_Octave6
|
||||||
dw Music_Octave5 ; octave 5
|
dw Music_Octave5
|
||||||
dw Music_Octave4 ; octave 4
|
dw Music_Octave4
|
||||||
dw Music_Octave3 ; octave 3
|
dw Music_Octave3
|
||||||
dw Music_Octave2 ; octave 2
|
dw Music_Octave2
|
||||||
dw Music_Octave1 ; octave 1
|
dw Music_Octave1
|
||||||
dw Music_NoteType ; note length + volume envelope
|
dw Music_NoteType ; note length + volume envelope
|
||||||
dw Music_Transpose ; transpose
|
dw Music_Transpose
|
||||||
dw Music_Tempo ; tempo
|
dw Music_Tempo
|
||||||
dw Music_DutyCycle ; duty cycle
|
dw Music_DutyCycle
|
||||||
dw Music_VolumeEnvelope ; volume envelope
|
dw Music_VolumeEnvelope
|
||||||
dw Music_PitchSweep ; update pitch sweep
|
dw Music_PitchSweep
|
||||||
dw Music_DutyCyclePattern ; duty cycle pattern
|
dw Music_DutyCyclePattern
|
||||||
dw Music_ToggleSFX ; sound on/off
|
dw Music_ToggleSFX
|
||||||
dw Music_PitchSlide ; pitch slide
|
dw Music_PitchSlide
|
||||||
dw Music_Vibrato ; vibrato
|
dw Music_Vibrato
|
||||||
dw MusicE2 ; unused
|
dw MusicE2 ; unused
|
||||||
dw Music_ToggleNoise ; music noise sampling
|
dw Music_ToggleNoise
|
||||||
dw Music_ForceStereoPanning ; force stereo panning
|
dw Music_ForceStereoPanning
|
||||||
dw Music_Volume ; volume
|
dw Music_Volume
|
||||||
dw Music_PitchOffset ; pitch offset
|
dw Music_PitchOffset
|
||||||
dw MusicE7 ; unused
|
dw MusicE7 ; unused
|
||||||
dw MusicE8 ; unused
|
dw MusicE8 ; unused
|
||||||
dw Music_TempoRelative ; tempo adjust
|
dw Music_TempoRelative
|
||||||
dw Music_RestartChannel ; restart current channel from header
|
dw Music_RestartChannel
|
||||||
dw Music_NewSong ; new song
|
dw Music_NewSong
|
||||||
dw Music_SFXPriorityOn ; sfx priority on
|
dw Music_SFXPriorityOn
|
||||||
dw Music_SFXPriorityOff ; sfx priority off
|
dw Music_SFXPriorityOff
|
||||||
dw MusicEE ; unused
|
dw MusicEE ; unused
|
||||||
dw Music_StereoPanning ; stereo panning
|
dw Music_StereoPanning
|
||||||
dw Music_SFXToggleNoise ; sfx noise sampling
|
dw Music_SFXToggleNoise
|
||||||
dw MusicF1 ; nothing
|
dw MusicF1 ; nothing
|
||||||
dw MusicF2 ; nothing
|
dw MusicF2 ; nothing
|
||||||
dw MusicF3 ; nothing
|
dw MusicF3 ; nothing
|
||||||
|
@ -1408,12 +1407,12 @@ MusicCommands:
|
||||||
dw MusicF7 ; nothing
|
dw MusicF7 ; nothing
|
||||||
dw MusicF8 ; nothing
|
dw MusicF8 ; nothing
|
||||||
dw MusicF9 ; unused
|
dw MusicF9 ; unused
|
||||||
dw Music_SetCondition ; set condition
|
dw Music_SetCondition
|
||||||
dw Music_JumpIf ; jumpif
|
dw Music_JumpIf
|
||||||
dw Music_Jump ; jump
|
dw Music_Jump
|
||||||
dw Music_Loop ; loop
|
dw Music_Loop
|
||||||
dw Music_Call ; call
|
dw Music_Call
|
||||||
dw Music_Ret ; return
|
dw Music_Ret
|
||||||
|
|
||||||
MusicF1:
|
MusicF1:
|
||||||
MusicF2:
|
MusicF2:
|
||||||
|
@ -2107,29 +2106,23 @@ GetMusicByte:
|
||||||
; input: bc = start of current channel
|
; input: bc = start of current channel
|
||||||
push hl
|
push hl
|
||||||
push de
|
push de
|
||||||
; load address into de
|
|
||||||
ld hl, CHANNEL_MUSIC_ADDRESS
|
ld hl, CHANNEL_MUSIC_ADDRESS
|
||||||
add hl, bc
|
add hl, bc
|
||||||
ld a, [hli]
|
ld a, [hli]
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, [hl]
|
ld d, [hl]
|
||||||
; load bank into a
|
|
||||||
ld hl, CHANNEL_MUSIC_BANK
|
ld hl, CHANNEL_MUSIC_BANK
|
||||||
add hl, bc
|
add hl, bc
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
; get byte
|
call _LoadMusicByte ; load data into [wCurMusicByte]
|
||||||
call _LoadMusicByte ; load data into wCurMusicByte
|
|
||||||
inc de ; advance to next byte for next time this is called
|
inc de ; advance to next byte for next time this is called
|
||||||
; update channeldata address
|
|
||||||
ld hl, CHANNEL_MUSIC_ADDRESS
|
ld hl, CHANNEL_MUSIC_ADDRESS
|
||||||
add hl, bc
|
add hl, bc
|
||||||
ld a, e
|
ld a, e
|
||||||
ld [hli], a
|
ld [hli], a
|
||||||
ld [hl], d
|
ld [hl], d
|
||||||
; cleanup
|
|
||||||
pop de
|
pop de
|
||||||
pop hl
|
pop hl
|
||||||
; store channeldata in a
|
|
||||||
ld a, [wCurMusicByte]
|
ld a, [wCurMusicByte]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -2191,7 +2184,6 @@ SetNoteDuration:
|
||||||
inc a
|
inc a
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, 0
|
ld d, 0
|
||||||
; store NoteLength in a
|
|
||||||
ld hl, CHANNEL_NOTE_LENGTH
|
ld hl, CHANNEL_NOTE_LENGTH
|
||||||
add hl, bc
|
add hl, bc
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
|
@ -2306,7 +2298,6 @@ SetLRTracks:
|
||||||
maskbits NUM_MUSIC_CHANS
|
maskbits NUM_MUSIC_CHANS
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, 0
|
ld d, 0
|
||||||
; get this channel's lr tracks
|
|
||||||
call GetLRTracks
|
call GetLRTracks
|
||||||
add hl, de ; de = channel 0-3
|
add hl, de ; de = channel 0-3
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
|
@ -2396,7 +2387,7 @@ _PlayCry::
|
||||||
inc a
|
inc a
|
||||||
.loop
|
.loop
|
||||||
push af
|
push af
|
||||||
call LoadChannel
|
call LoadChannel ; bc = current channel
|
||||||
|
|
||||||
ld hl, CHANNEL_FLAGS1
|
ld hl, CHANNEL_FLAGS1
|
||||||
add hl, bc
|
add hl, bc
|
||||||
|
@ -2439,7 +2430,7 @@ _PlayCry::
|
||||||
bit STEREO, a
|
bit STEREO, a
|
||||||
jr z, .next
|
jr z, .next
|
||||||
|
|
||||||
; [Tracks] &= [wCryTracks]
|
; [CHANNEL_TRACKS] &= [wCryTracks]
|
||||||
ld hl, CHANNEL_TRACKS
|
ld hl, CHANNEL_TRACKS
|
||||||
add hl, bc
|
add hl, bc
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
|
@ -2671,13 +2662,11 @@ PlayStereoSFX::
|
||||||
ret
|
ret
|
||||||
|
|
||||||
LoadChannel:
|
LoadChannel:
|
||||||
; prep channel for use
|
; input: de = audio pointer
|
||||||
; input:
|
; sets bc to current channel pointer
|
||||||
; de:
|
|
||||||
; get pointer to current channel
|
|
||||||
call LoadMusicByte
|
call LoadMusicByte
|
||||||
inc de
|
inc de
|
||||||
and $7 ; bit 0-2 (current channel)
|
maskbits NUM_CHANNELS
|
||||||
ld [wCurChannel], a
|
ld [wCurChannel], a
|
||||||
ld c, a
|
ld c, a
|
||||||
ld b, 0
|
ld b, 0
|
||||||
|
|
|
@ -374,7 +374,7 @@ Pokedex_UpdateDexEntryScreen:
|
||||||
ld a, [wLastVolume]
|
ld a, [wLastVolume]
|
||||||
and a
|
and a
|
||||||
jr z, .max_volume
|
jr z, .max_volume
|
||||||
ld a, $77
|
ld a, MAX_VOLUME
|
||||||
ld [wLastVolume], a
|
ld [wLastVolume], a
|
||||||
|
|
||||||
.max_volume
|
.max_volume
|
||||||
|
|
|
@ -49,7 +49,7 @@ UpdateSound::
|
||||||
ret
|
ret
|
||||||
|
|
||||||
_LoadMusicByte::
|
_LoadMusicByte::
|
||||||
; wCurMusicByte = [a:de]
|
; [wCurMusicByte] = [a:de]
|
||||||
ldh [hROMBank], a
|
ldh [hROMBank], a
|
||||||
ld [MBC3RomBank], a
|
ld [MBC3RomBank], a
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue