3131 .lclequ ADPCM_A_MAX_VOL , 0x1f
3232
3333 ;; getters for ADPCM-A state
34+ .lclequ INSTR_VOL , (state_a_instr_vol - state_a)
3435 .lclequ OUT_VOL , (state_a_out_vol - state_a)
3536 .lclequ PAN , (state_a_pan - state_a)
3637
3738 . equ NSS_ADPCM_A_INSTRUMENT_PROPS , 4
3839 . equ NSS_ADPCM_A_NEXT_REGISTER , 8
3940
40- ;; specific pipeline state for SSG channel
41+ ;; specific pipeline state for ADPCM-A channel
4142 .lclequ STATE_START_NOTE , 0x04
4243 .lclequ BIT_START_NOTE , 2
4344
4445
45-
4646 .area DATA
4747
4848
4949;;; ADPCM playback state tracker
5050;;; ------
51- ;; This padding ensures the entire _state_ssg data sticks into
52- ;; a single 256 byte boundary to make 16bit arithmetic faster
53- .blkb ALIGN_OFFSET_ADPCM_A
5451
55- _state_adpcm_start:
52+ .align_begin state_adpcm
53+ ;;; { ...
5654
5755;;; ADPCM-A1
5856state_a1:
59- ;;; state
57+ ;;; { ...
6058state_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
59+
6560;;; volume state tracker
6661state_a_vol_cfg: .blkb 1 ; configured volume
6762state_a_vol16: .blkb 2 ; current decimal volume
6863;;; FX state trackers
64+ state_a_fx: .blkb 1 ; enabled FX for this channel
6965state_a_fx_vol_slide: .blkb SLIDE_SIZE
7066state_a_fx_trigger: .blkb TRIGGER_SIZE
67+
68+ ;;; actions to run at the end of every tick
69+ state_a:
70+ state_a_pipeline: .blkb 1 ; action: load note, load vol, load other regs
71+
7172;;; ADPCM-A-specific state
73+ state_a_instr_vol: .blkb 1 ; instrument volume
7274state_a_out_vol: .blkb 1 ; ym2610 volume after the FX pipeline
7375;;; pan
7476state_a_pan: .blkb 1 ; configured pan (b7: left, b6: right)
@@ -89,18 +91,21 @@ state_a5:
8991;;; ADPCM-A6
9092state_a6:
9193.blkb ADPCM_A_STATE_SIZE
94+
95+ ;;; ... }
9296state_a6_end:
9397
98+ ;;; ... }
99+ .align_end state_adpcm
100+
94101;;; context: current adpcm channel for opcode actions
95102state_adpcm_a_channel::
96103 .blkb 1
97104
98-
99105;;; Global volume attenuation for all ADPCM-A channels
100106state_adpcm_a_volume_attenuation:: .blkb 1
101107
102108
103- _state_adpcm_end:
104109
105110
106111
@@ -128,7 +133,7 @@ init_nss_adpcm_state_tracker::
128133 ld bc , #(state_a6_end - 1 - state_a_start)
129134 ldir
130135 ;; init flags
131- ld iy , #state_a1
136+ ld iy , #state_a_pipeline
132137 ld bc , #ADPCM_A_STATE_SIZE
133138 ld d , # 6
134139_a_init:
@@ -417,9 +422,9 @@ _adpcm_a_loop:
417422 dec d
418423 jp nz , _adpcm_a_loop
419424
420- ;; d: ADPCM-A channel
421- ld a , (state_adpcm_a_channel )
422- ld d , a
425+ ;; instrument volume
426+ ld a , (hl )
427+ ld INSTR_VOL(ix) , a
423428
424429 pop de
425430 pop hl
@@ -583,11 +588,21 @@ _adpcm_a_clamp_level:
583588
584589;;; Compute the YM2610 output volume from the current channel
585590;;; ------
591+ ;;; IN:
592+ ;;; ix: FM pipeline
593+ ;;; iy: Volume FX
586594;;; modified: c
587595compute_ym2610_a_vol::
588- ;; c: note vol for current channel
589- ld c , VOL16 + 1 (ix)
590-
596+ ;; c: instrument attenuation [-0x1f..0]
597+ ld a , # - 0x1f
598+ add INSTR_VOL(ix)
599+ ld c , a
600+
601+ ;; c: current volume after instrument attenuation [-0x1f..0x1f]
602+ ld a , VOL16 + 1 (ix)
603+ add c
604+ ld c , a
605+
591606 ;; attenuation to match the configured ADPCM-A output level
592607 ld a , (state_adpcm_a_volume_attenuation)
593608 neg
0 commit comments