Skip to content

Commit 118a486

Browse files
committed
WIP
1 parent c391be8 commit 118a486

File tree

10 files changed

+811
-582
lines changed

10 files changed

+811
-582
lines changed

nullsound/nss-adpcm-a.s

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,21 @@ _state_adpcm_start:
5656

5757
;;; ADPCM-A1
5858
state_a1:
59-
;;; state
59+
;;; { ...
6060
state_a_start:
61-
;;; stream pipeline
62-
state_a:
63-
state_a_pipeline: .blkb 1 ; actions to run at every tick (load note, vol, other regs)
64-
state_a_fx: .blkb 1 ; enabled FX for this channel
65-
;;; volume state tracker
66-
state_a_vol_cfg: .blkb 1 ; configured volume
67-
state_a_vol16: .blkb 2 ; current decimal volume
61+
6862
;;; FX state trackers
6963
state_a_fx_vol_slide: .blkb SLIDE_SIZE
7064
state_a_fx_trigger: .blkb TRIGGER_SIZE
65+
;;; volume state tracker
66+
state_a_fx: .blkb 1 ; enabled FX for this channel
67+
state_a_vol_cfg: .blkb 1 ; configured volume
68+
state_a_vol16: .blkb 2 ; current decimal volume
69+
70+
;;; actions to run at the end of every tick
71+
state_a:
72+
state_a_pipeline: .blkb 1 ; action: load note, load vol, load other regs
73+
7174
;;; ADPCM-A-specific state
7275
state_a_out_vol: .blkb 1 ; ym2610 volume after the FX pipeline
7376
;;; pan
@@ -89,6 +92,8 @@ state_a5:
8992
;;; ADPCM-A6
9093
state_a6:
9194
.blkb ADPCM_A_STATE_SIZE
95+
96+
;;; ... }
9297
state_a6_end:
9398

9499
;;; context: current adpcm channel for opcode actions

nullsound/nss-adpcm-b.s

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,31 @@
5959
_state_adpcm_b_start:
6060

6161
;;; ADPCM-B mirrored state
62-
;;; state
62+
;;; { ...
6363
state_b_start:
64-
;;; additional note and FX state tracker
65-
state_b_note_fx: .blkb 1 ; enabled note FX for this channel
66-
state_b_note_cfg: .blkb 1 ; configured note
67-
state_b_note16: .blkb 2 ; current decimal note
64+
65+
;;; note FX state tracker
6866
state_b_fx_note_slide: .blkb SLIDE_SIZE
6967
state_b_fx_vibrato: .blkb VIBRATO_SIZE
7068
state_b_fx_arpeggio: .blkb ARPEGGIO_SIZE
7169
state_b_fx_legato: .blkb LEGATO_SIZE
72-
;;; stream pipeline
73-
state_b:
74-
state_b_pipeline: .blkb 1 ; actions to run at every tick (load note, vol, other regs)
75-
state_b_fx: .blkb 1 ; enabled FX for this channel
76-
;;; volume state tracker
77-
state_b_vol_cfg: .blkb 1 ; configured volume
78-
state_b_vol16: .blkb 2 ; current decimal volume
70+
;;; note state tracker
71+
state_b_note_fx: .blkb 1 ; enabled note FX for this channel
72+
state_b_note_cfg: .blkb 1 ; configured note
73+
state_b_note16: .blkb 2 ; current decimal note
74+
7975
;;; FX state trackers
8076
state_b_fx_vol_slide: .blkb SLIDE_SIZE
8177
state_b_trigger: .blkb TRIGGER_SIZE
78+
;;; volume state tracker
79+
state_b_fx: .blkb 1 ; enabled FX for this channel
80+
state_b_vol_cfg: .blkb 1 ; configured volume
81+
state_b_vol16: .blkb 2 ; current decimal volume
82+
83+
;;; actions to run at the end of every tick
84+
state_b:
85+
state_b_pipeline: .blkb 1 ; action: load note, load vol, load other regs
86+
8287
;;; ADPCM-B-specific state
8388
;;; Note
8489
state_b_note:
@@ -94,6 +99,8 @@ state_b_out_vol: .blkb 1 ; ym2610 volume after the FX pip
9499
;;; pan
95100
state_b_pan: .blkb 1 ; configured pan (b7: left, b6: right)
96101
;;;
102+
103+
;;; ... }
97104
state_b_end:
98105

99106

@@ -388,6 +395,7 @@ adpcm_b_instrument::
388395

389396
;; a: start of ADPCM-B property registers
390397
ld a, #REG_ADPCM_B_ADDR_START_LSB
398+
;; TODO remove useless +0?
391399
add b
392400

393401
_adpcm_b_loop:

nullsound/nss-fm.s

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,32 @@ state_fm_ym2610_channel::
9292

9393
;;; FM1
9494
state_fm1:
95-
;;; state
95+
;;; { ...
9696
state_fm_start:
97-
;;; additional note and FX state tracker
98-
state_fm_note_fx: .blkb 1 ; enabled note FX for this channel
99-
state_fm_note_cfg: .blkb 1 ; configured note
100-
state_fm_note16: .blkb 2 ; current decimal note
97+
98+
;;; note FX state tracker
10199
state_fm_fx_note_slide: .blkb SLIDE_SIZE
102100
state_fm_fx_vibrato: .blkb VIBRATO_SIZE
103101
state_fm_fx_arpeggio: .blkb ARPEGGIO_SIZE
104102
state_fm_fx_legato: .blkb LEGATO_SIZE
105-
;;; stream pipeline
106-
state_fm:
107-
state_fm_pipeline: .blkb 1 ; actions to run at every tick (load note, vol, other regs)
108-
state_fm_fx: .blkb 1 ; enabled FX for this channel
103+
;;; note state tracker
104+
state_fm_note_fx: .blkb 1 ; enabled note FX
105+
state_fm_note_cfg: .blkb 1 ; configured note
106+
state_fm_note16: .blkb 2 ; current decimal note
107+
108+
;;; common FX state tracker
109+
state_fm_fx_vol_slide: .blkb SLIDE_SIZE
110+
state_fm_fx_trigger: .blkb TRIGGER_SIZE
109111
;;; volume state tracker
112+
state_fm_fx: .blkb 1 ; enabled FX
110113
state_fm_vol_cfg: .blkb 1 ; configured volume
111114
state_fm_vol16: .blkb 2 ; current decimal volume
112-
;;; FX state trackers
113-
state_fm_fx_vol_slide: .blkb SLIDE_SIZE
114-
state_fm_fx_trigger: .blkb TRIGGER_SIZE
115-
;;; FM-specific state
115+
116+
;;; actions to run at the end of every tick
117+
state_fm:
118+
state_fm_pipeline: .blkb 1 ; action: load note, load vol, load other regs
119+
120+
;;; FM-specific YM2610 state tracker
116121
;;; Note
117122
state_fm_note:
118123
state_fm_instrument: .blkb 1 ; instrument
@@ -130,8 +135,10 @@ state_fm_out_op1: .blkb 1 ; ym2610 volume for OP1 after th
130135
state_fm_out_op2: .blkb 1 ; ym2610 volume for OP2 after the FX pipeline
131136
state_fm_out_op3: .blkb 1 ; ym2610 volume for OP3 after the FX pipeline
132137
state_fm_out_op4: .blkb 1 ; ym2610 volume for OP4 after the FX pipeline
133-
;;;
138+
139+
;;; ... }
134140
state_fm_end:
141+
135142
;;; FM2
136143
state_fm2:
137144
.blkb FM_STATE_SIZE

nullsound/nss-ssg.s

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,32 @@ state_mirrored_enabled:
7575

7676
;;; SSG A
7777
state_mirrored_ssg_a:
78+
;;; { ...
7879
;;; state
80+
81+
;;; note FX state tracker
7982
state_mirrored_ssg_start:
80-
;;; additional note and FX state tracker
81-
state_ssg_note_fx: .blkb 1 ; enabled note FX for this channel
82-
state_ssg_note_cfg: .blkb 1 ; configured note
83-
state_ssg_note16: .blkb 2 ; current decimal note
8483
state_ssg_fx_note_slide: .blkb SLIDE_SIZE
8584
state_ssg_fx_vibrato: .blkb VIBRATO_SIZE
8685
state_ssg_fx_arpeggio: .blkb ARPEGGIO_SIZE
8786
state_ssg_fx_legato: .blkb LEGATO_SIZE
88-
;;; stream pipeline
89-
state_mirrored_ssg:
90-
state_ssg_pipeline: .blkb 1 ; actions to run at every tick (eval macro, load note, vol, other regs)
91-
state_ssg_fx: .blkb 1 ; enabled FX for this channel
87+
;;; note state tracker
88+
state_ssg_note_fx: .blkb 1 ; enabled note FX for this channel
89+
state_ssg_note_cfg: .blkb 1 ; configured note
90+
state_ssg_note16: .blkb 2 ; current decimal note
91+
92+
;;; common FX state tracker
93+
state_ssg_fx_vol_slide: .blkb SLIDE_SIZE
94+
state_ssg_trigger: .blkb TRIGGER_SIZE
9295
;;; volume state tracker
96+
state_ssg_fx: .blkb 1 ; enabled FX for this channel
9397
state_ssg_vol_cfg: .blkb 1 ; configured volume
9498
state_ssg_vol16: .blkb 2 ; current decimal volume
95-
;;; FX state trackers
96-
state_ssg_fx_vol_slide: .blkb SLIDE_SIZE
97-
state_ssg_trigger: .blkb TRIGGER_SIZE
99+
100+
;;; actions to run at the end of every tick
101+
state_mirrored_ssg:
102+
state_ssg_pipeline: .blkb 1 ; actions: eval macro, load note, load vol, load other regs
103+
98104
;;; SSG-specific state
99105
;;; Note
100106
state_ssg_note_pos16: .blkb 2 ; fixed-point note after the FX pipeline
@@ -111,10 +117,14 @@ state_ssg_macro_data: .blkb 2 ; address of the start of the ma
111117
state_ssg_macro_pos: .blkb 2 ; address of the current position in the macro program
112118
state_ssg_macro_load: .blkb 2 ; function to load the SSG registers modified by the macro program
113119
state_ssg_out_vol: .blkb 1 ; ym2610 volume for SSG channel after the FX pipeline
120+
121+
;;; ... }
114122
state_mirrored_ssg_end:
123+
115124
;;; SSG B
116125
state_mirrored_ssg_b:
117126
.blkb SSG_STATE_SIZE
127+
118128
;;; SSG C
119129
state_mirrored_ssg_c:
120130
.blkb SSG_STATE_SIZE

nullsound/stream.s

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ _post_process_nss_opcodes:
266266
;; process the current stream pipeline
267267
;; the next processing will take place once a new tick is reached
268268
call run_fm_pipeline
269-
call run_ssg_pipeline
270-
call run_adpcm_a_pipeline
271-
call run_adpcm_b_pipeline
269+
;; call run_ssg_pipeline
270+
;; call run_adpcm_a_pipeline
271+
;; call run_adpcm_b_pipeline
272272
ld a, (state_timer_tick_reached)
273273
res TIMER_CONSUMER_STREAM_BIT, a
274274
ld (state_timer_tick_reached), a
@@ -562,11 +562,12 @@ nss_opcodes:
562562
.nss_op_unused
563563
.nss_op ssg_pitch
564564
;; 0x40
565+
.nss_op_unused
565566
.nss_op_unused
567+
;; .nss_op ext_note_op2
566568
.nss_op_unused
567569
.nss_op_unused
568-
.nss_op_unused
569-
.nss_op_unused
570+
.nss_op set_2ch
570571
.nss_op fm_cut
571572
.nss_op ssg_cut
572573
.nss_op adpcm_a_cut

nullsound/struct-fx.inc

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
@@ -37,33 +37,58 @@
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
4561
cfg_note: .blkb 1 ; configured note
4662
note16: .blkb 2 ; current decimal note
63+
;;; optional note FX state tracker
64+
note_fx: .blkb 1 ; enabled note FX
4765
fx_note_slide: .blkb SLIDE_SIZE
4866
fx_vibrato: .blkb VIBRATO_SIZE
4967
fx_arpeggio: .blkb ARPEGGIO_SIZE
5068
fx_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
5571
cfg_vol: .blkb 1 ; configured volume
5672
vol16: .blkb 2 ; current decimal volume
57-
;;; misc fx state tracker
73+
;;; common FX state tracker
74+
fx_fx: .blkb 1 ; enabled FX
5875
fx_vol_slide: .blkb SLIDE_SIZE
5976
fx_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

Comments
 (0)