11;;;
22;;; nullsound - modular sound driver
3- ;;; Copyright (c) 2024 Damien Ciabrini
3+ ;;; Copyright (c) 2024-2025 Damien Ciabrini
44;;; This file is part of ngdevkit
55;;;
66;;; ngdevkit is free software: you can redistribute it and/or modify
3737 .local fx_trigger
3838
3939
40- ;;; The pipeline structure holds properties and state trackers common to all channels
41- ;;; fields before field `pipeline` are optional based on the type of channel
42-
43- ;;; optional note and FX state tracker
44- note_fx: .blkb 1 ; enabled note FX
40+ ;;; The channel state tracker holds properties of volume and configured FX, as
41+ ;;; well as their current state at every moment of the playback.
42+ ;;;
43+ ;;; The channel state tracker structure is split into three separate parts
44+ ;;; - all NSS state that are common to all type of channels (e.g. volume, trigger FX)
45+ ;;; some channels have a note state (FM/SSG/ADPCM-B), this comes before every other
46+ ;;; field in the state tracker
47+ ;;; - the pipeline state, i.e. what are the actions to perform at the next tick,
48+ ;;; e.g. load a note/volume/custom-register into the YM2610
49+ ;;; - every other field, usually YM2610-specific fields for a given type of
50+ ;;; channel (e.g. OPx for FM channels, Delta-N factor for ADPCM-B...)
51+ ;;;
52+ ;;; At runtime, the channel state tracker is always referenced from the pipeline field,
53+ ;;; which means other field are accessed via either a negative of postive offset
54+ ;;;
55+
56+ ;;;
57+ ;;; Common layout of a channel state tracker
58+ ;;;
59+
60+ ;;; note state tracker
4561cfg_note: .blkb 1 ; configured note
4662note16: .blkb 2 ; current decimal note
63+ ;;; optional note FX state tracker
64+ note_fx: .blkb 1 ; enabled note FX
4765fx_note_slide: .blkb SLIDE_SIZE
4866fx_vibrato: .blkb VIBRATO_SIZE
4967fx_arpeggio: .blkb ARPEGGIO_SIZE
5068fx_legato: .blkb LEGATO_SIZE
51- ;;; strean pipeline
52- pipeline: .blkb 1 ; actions to run at every tick (load note, vol, other regs)
53- fx_fx: .blkb 1 ; enabled FX. This must be the second field of a channel's state
69+
5470;;; volume state tracker
5571cfg_vol: .blkb 1 ; configured volume
5672vol16: .blkb 2 ; current decimal volume
57- ;;; misc fx state tracker
73+ ;;; common FX state tracker
74+ fx_fx: .blkb 1 ; enabled FX
5875fx_vol_slide: .blkb SLIDE_SIZE
5976fx_trigger: .blkb TRIGGER_SIZE
6077
78+ ;;; strean pipeline
79+ ;;; actions to run at the end of every tick
80+ pipeline: .blkb 1 ; action: load note, load vol, load other regs
81+
6182
62- ;;; common FX for note and volume are prefix with those common fields
83+ ;;;
84+ ;;; common FX getters for all channels
85+ ;;;
86+
87+ ;;; common state getter shared by volume and (optional) note fields
6388_data_ctx:
64- _data_fx: .blkb 1 ; enabled FX for this data
6589_data_cfg: .blkb 1 ; configured data
6690_data16: .blkb 2 ; current decimal data
91+ _data_fx: .blkb 1 ; enabled FX for this data
6792
6893;;; FX: slide
6994_vol_slide:
@@ -73,7 +98,7 @@ _vol_slide_end: .blkw 1 ; volume slide end
7398_vol_slide_max: .blkb 1 ; volume slide max for channel
7499_vol_slide_size:
75100
76- ;;; FX: vibrato
101+ ;;; FX: vibrato/tremolo
77102_vibrato:
78103_vibrato_speed: .blkb 1 ; vibrato_speed
79104_vibrato_depth: .blkb 1 ; vibrato_depth
@@ -108,29 +133,34 @@ _trigger_cur: .blkb 1 ; per-action current accumulator
108133_trigger_size:
109134
110135
111- ;; FX getter for a channel's state
112- ;; The offset assumes that that the FX structure are located
113- ;; at the same location in reference to the pipeline field,
114- ;; and they are the same for all channels
136+ ;; The offset of every field is the same for all channels, and is
137+ ;; based on the common layout defined above, starting from the
138+ ;; pipeline field (referenced by register ix)
115139 .lclequ PIPELINE , (pipeline - pipeline)
116- .lclequ FX , (fx_fx - pipeline)
117- ;; note and volume can both have a slide a vibrato/tremolo FX, so their
118- ;; attribute share the same alignement in memory.
119- .lclequ VOL_CTX , FX
140+
141+ ;; volume and note properties are sometimes processed by a common code
142+ ;; so they need to share the same alignment in memory
120143 .lclequ VOL , (cfg_vol - pipeline)
121144 .lclequ VOL16 , (vol16 - pipeline)
122- .lclequ NOTE_CTX , NOTE_FX
123- .lclequ NOTE_FX , (note_fx - pipeline)
145+ .lclequ FX , (fx_fx - pipeline)
124146 .lclequ NOTE , (cfg_note - pipeline)
125147 .lclequ NOTE16 , (note16 - pipeline)
126- ;; getter for accessing the pipeline from the start of a FM, SSG, ADPCM-B
127- .lclequ PIPELINE_FROM_NOTE , (pipeline - note_fx)
148+ .lclequ NOTE_FX , (note_fx - pipeline)
149+ ;; when the common code needs to access the fields above, it uses
150+ ;; another set of getters, whose offset is relative to a volume
151+ ;; or note context (referenced by register iy)
152+ .lclequ VOL_CTX , VOL
153+ .lclequ NOTE_CTX , NOTE
154+ .lclequ DATA_CFG , (_data_cfg - _data_ctx)
155+ .lclequ DATA16 , (_data16 - _data_ctx)
156+ .lclequ DATA_FX , (_data_fx - _data_ctx)
128157
129158 ;; FX that are common to the volume and note properties have getters
130- ;; relative to the propertie. they are accessed with register iy
131- .lclequ DATA_FX , (_data_fx - _data_ctx )
159+ ;; whose offset is relative to the volume context or note context
160+ ;; (referenced by register iy )
132161 .lclequ DATA_CFG , (_data_cfg - _data_ctx)
133162 .lclequ DATA16 , (_data16 - _data_ctx)
163+ .lclequ DATA_FX , (_data_fx - _data_ctx)
134164 ;; FX slide
135165 .lclequ SLIDE_CFG , (_vol_slide_cfg - _data_ctx)
136166 .lclequ SLIDE_INC16 , (_vol_slide_inc16 - _data_ctx)
@@ -167,6 +197,10 @@ _trigger_size:
167197 .lclequ TRIGGER_CUR , (_trigger_cur - _trigger + fx_trigger - pipeline)
168198 .lclequ TRIGGER_SIZE , (_trigger_size - _trigger)
169199
200+ ;; common getter for accessing the pipeline from the start of
201+ ;; the FM, SSG or ADPCM-B channel
202+ .lclequ PIPELINE_FROM_NOTE , (pipeline - note_fx)
203+
170204 ;; Enabled FX
171205 .lclequ BIT_FX_TRIGGER , 0
172206 .lclequ BIT_FX_SLIDE , 1
@@ -179,6 +213,7 @@ _trigger_size:
179213 .lclequ TRIGGER_LOAD_NOTE_FUNC , 0
180214 .lclequ TRIGGER_LOAD_VOL_FUNC , 2
181215 .lclequ TRIGGER_STOP_NOTE_FUNC , 4
216+
182217 ;; Trigger FX configuration
183218 .lclequ BIT_TRIGGER_ACTION_DELAY , 0
184219 .lclequ BIT_TRIGGER_ACTION_CUT , 1
0 commit comments