Skip to content

Commit

Permalink
Refactor "sample" sound effect as an sSfx struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Nov 21, 2024
1 parent 2774867 commit 50e503a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
39 changes: 17 additions & 22 deletions src/sample.asm
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ kSampleGap2Size = kDmcSampleAlign - (* .mod kDmcSampleAlign)
;;; @preserve X, Y, T0+
.EXPORT Func_PlaySfxSample
.PROC Func_PlaySfxSample
sta Zp_Next_sChanSfx_arr + eChan::Dmc + sChanSfx::Param1_byte ; eSample
lda #0
sta Zp_Next_sChanSfx_arr + eChan::Dmc + sChanSfx::Param3_byte ; timer
lda #eSound::Sample
sta Zp_Next_sChanSfx_arr + eChan::Dmc + sChanSfx::Param3_byte ; eSample
lda #<Data_Sample_sSfx
sta Zp_Next_sChanSfx_arr + eChan::Dmc + sChanSfx::Param1_byte ; addr lo
lda #>Data_Sample_sSfx
sta Zp_Next_sChanSfx_arr + eChan::Dmc + sChanSfx::Param2_byte ; addr hi
lda #eSound::Bytecode
sta Zp_Next_sChanSfx_arr + eChan::Dmc + sChanSfx::Sfx_eSound
rts
.ENDPROC
Expand Down Expand Up @@ -171,22 +173,12 @@ kSampleGap2Size = kDmcSampleAlign - (* .mod kDmcSampleAlign)
D_END
.ENDPROC

;;; SFX function for playing delta modulated samples on the DMC. When starting
;;; this sound, Param1_byte should hold the eSample value, and Param3_byte
;;; should be initialized to zero.
;;; @param X The channel number (0-4) times four (so, 0, 4, 8, 12, or 16).
;;; @return C Set if the sound is finished, cleared otherwise.
;;; @preserve X, T0+
.EXPORT Func_SfxSample
.PROC Func_SfxSample
ldy Ram_Audio_sChanSfx_arr + sChanSfx::Param1_byte, x ; eSample
lda Ram_Audio_sChanSfx_arr + sChanSfx::Param3_byte, x ; timer
beq _Initialize
cmp Data_SampleFrames_u8_arr, y
blt _Continue
sec ; set C to indicate that the sound is finished
rts
.PROC Data_Sample_sSfx
sfx_Func _Initialize
sfx_Func _Wait
sfx_End
_Initialize:
ldy Ram_Audio_sChanSfx_arr + eChan::Dmc + sChanSfx::Param3_byte ; eSample
lda Data_SampleRate_u8_arr, y
sta Hw_DmcFlags_wo
lda #$40
Expand All @@ -195,9 +187,12 @@ _Initialize:
sta Hw_DmcSampleStart_wo
lda Data_SampleLength_u8_arr, y
sta Hw_DmcSampleLength_wo
_Continue:
inc Ram_Audio_sChanSfx_arr + sChanSfx::Param3_byte, x ; timer
clc ; clear C to indicate that the sound is still going
sec ; set C to indicate that the function is finished
rts
_Wait:
tya ; repeat count
ldy Ram_Audio_sChanSfx_arr + eChan::Dmc + sChanSfx::Param3_byte ; eSample
cmp Data_SampleFrames_u8_arr, y
rts
.ENDPROC

Expand Down
2 changes: 0 additions & 2 deletions src/sound.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
.IMPORT Func_Noop
.IMPORT Func_SfxDialogText
.IMPORT Func_SfxExplode
.IMPORT Func_SfxSample
.IMPORT Ram_Audio_sChanCtrl_arr
.IMPORT Ram_Audio_sChanSfx_arr
.IMPORTZP Zp_AudioTmp_byte
Expand Down Expand Up @@ -184,7 +183,6 @@ _CallAudioTmpPtr:
d_entry table, Bytecode, Func_SfxBytecode
d_entry table, DialogText, Func_SfxDialogText
d_entry table, Explode, Func_SfxExplode
d_entry table, Sample, Func_SfxSample
D_END
.ENDREPEAT

Expand Down
1 change: 0 additions & 1 deletion src/sound.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Bytecode
DialogText
Explode
Sample
NUM_VALUES
.ENDENUM

Expand Down

0 comments on commit 50e503a

Please sign in to comment.