38
38
;;; FM playback state tracker
39
39
;;; ------
40
40
41
+ ;;; write to the ym2610 port that matches the current context
42
+ ym2610_write_func:
43
+ .blkb 3 ; space for `jp 0x....`
44
+
41
45
;;; context: current fm channel for opcode actions
42
46
_state_fm_start:
43
47
state_fm_channel::
@@ -82,6 +86,11 @@ init_nss_fm_state_tracker::
82
86
ld (hl) , # 0
83
87
ld bc , #_state_fm_end - _state_fm_start
84
88
ldir
89
+ ;; init ym2610 function pointer
90
+ ld a , # 0xc3 ; jp 0x....
91
+ ld (ym2610_write_func) , a
92
+ call fm_ctx_reset
93
+
85
94
ret
86
95
87
96
@@ -91,7 +100,29 @@ init_nss_fm_state_tracker::
91
100
;;; [a modified - other registers saved]
92
101
fm_ctx_reset::
93
102
ld a , # 0
103
+ call fm_ctx_set_current
104
+ ret
105
+
106
+
107
+ ;;; Set the current FM track and YM2610 load function for this track
108
+ ;;; ------
109
+ ;;; a : FM channel
110
+ fm_ctx_set_current::
111
+ ;; set FM context
94
112
ld (state_fm_channel) , a
113
+ ;; target the right YM2610 port (ch0,ch1: A, ch2,ch3: B)
114
+ cp # 2
115
+ jr c , _fm_ctx_12
116
+ ld a , #<ym2610_write_port_b
117
+ ld (ym2610_write_func + 1 ) , a
118
+ ld a , #>ym2610_write_port_b
119
+ ld (ym2610_write_func + 2 ) , a
120
+ ret
121
+ _fm_ctx_12:
122
+ ld a , #<ym2610_write_port_a
123
+ ld (ym2610_write_func + 1 ) , a
124
+ ld a , #>ym2610_write_port_a
125
+ ld (ym2610_write_func + 2 ) , a
95
126
ret
96
127
97
128
@@ -102,9 +133,8 @@ fm_ctx_reset::
102
133
;;; Set the current FM track to be FM1 for the next FM opcode processing
103
134
;;; ------
104
135
fm_ctx_1::
105
- ;; set new current FM channel
106
136
ld a , # 0
107
- ld (state_fm_channel) , a
137
+ call fm_ctx_set_current
108
138
ld a , # 1
109
139
ret
110
140
@@ -113,9 +143,8 @@ fm_ctx_1::
113
143
;;; Set the current FM track to be FM2 for the next FM opcode processing
114
144
;;; ------
115
145
fm_ctx_2::
116
- ;; set new current FM channel
117
146
ld a , # 1
118
- ld (state_fm_channel) , a
147
+ call fm_ctx_set_current
119
148
ld a , # 1
120
149
ret
121
150
@@ -124,9 +153,8 @@ fm_ctx_2::
124
153
;;; Set the current FM track to be FM3 for the next FM opcode processing
125
154
;;; ------
126
155
fm_ctx_3::
127
- ;; set new current FM channel
128
156
ld a , # 2
129
- ld (state_fm_channel) , a
157
+ call fm_ctx_set_current
130
158
ld a , # 1
131
159
ret
132
160
@@ -135,9 +163,8 @@ fm_ctx_3::
135
163
;;; Set the current FM track to be FM4 for the next FM opcode processing
136
164
;;; ------
137
165
fm_ctx_4::
138
- ;; set new current FM channel
139
166
ld a , # 3
140
- ld (state_fm_channel) , a
167
+ call fm_ctx_set_current
141
168
ld a , # 1
142
169
ret
143
170
@@ -150,7 +177,7 @@ fm_ctx_4::
150
177
fm_instrument_ext::
151
178
;; set new current FM channel
152
179
ld a , (hl)
153
- ld (state_fm_channel) , a
180
+ call fm_ctx_set_current
154
181
inc hl
155
182
jp fm_instrument
156
183
@@ -229,12 +256,6 @@ fm_set_ops_level::
229
256
add hl , bc
230
257
ld e , (hl)
231
258
232
- ;; e7: bit to target the right ym2610 port for channel
233
- ld a , (state_fm_channel)
234
- cp # 2
235
- jr c , _ops_channel12
236
- set 7 , e
237
- _ops_channel12:
238
259
;; b: OP1 start register in YM2610 for current channel
239
260
res 1 , a
240
261
add a , #REG_FM1_OP1_TOTAL_LEVEL
@@ -260,12 +281,7 @@ _ops_loop:
260
281
_ops_post_clamp:
261
282
and # 0x7f
262
283
ld c , a
263
- bit 7 , e
264
- jr z , _ops_port_a
265
- call ym2610_write_port_b
266
- jr _ops_next_op
267
- _ops_port_a:
268
- call ym2610_write_port_a
284
+ call ym2610_write_func
269
285
_ops_next_op:
270
286
;; next OP in instrument data
271
287
inc hl
@@ -355,56 +371,26 @@ fm_instrument::
355
371
ld a , (state_fm_channel)
356
372
ld b , a
357
373
358
- ;; configure writes to port a/b based on channel
359
- ld a , b
360
- cp # 2
361
- jp c , _fm_port_a
362
- jp _fm_port_b
363
-
364
- _fm_port_a:
365
374
;; a: start register in YM2610 for FM channel
366
375
ld a , #REG_FM1_OP1_DETUNE_MULTIPLY
367
376
res 1 , b
368
377
add b
369
- _fm_port_a_loop:
370
- ld b , a
371
- ld c , (hl)
372
- call ym2610_write_port_a
373
- add a , #NSS_FM_NEXT_REGISTER
374
- inc hl
375
- dec d
376
- jp nz , _fm_port_a_loop
377
- ;;
378
- ld d , #NSS_FM_END_OF_REGISTERS
379
- cp d
380
- jp nc , _fm_end
381
- ;; two additional properties a couples of regs away
382
- add a , #NSS_FM_NEXT_REGISTER_GAP
383
- ld d , # 2
384
- jp _fm_port_a_loop
385
- jp _fm_end
386
-
387
- _fm_port_b:
388
- ;; a: start register in ym2610 from FM channel
389
- ld a , #REG_FM1_OP1_DETUNE_MULTIPLY
390
- res 1 , b
391
- add b
392
- _fm_port_b_loop:
378
+ _fm_port_loop:
393
379
ld b , a
394
380
ld c , (hl)
395
- call ym2610_write_port_b
381
+ call ym2610_write_func
396
382
add a , #NSS_FM_NEXT_REGISTER
397
383
inc hl
398
384
dec d
399
- jp nz , _fm_port_b_loop
385
+ jp nz , _fm_port_loop
400
386
;;
401
387
ld d , #NSS_FM_END_OF_REGISTERS
402
388
cp d
403
389
jp nc , _fm_end
404
390
;; two additional properties a couples of regs away
405
391
add a , #NSS_FM_NEXT_REGISTER_GAP
406
392
ld d , # 2
407
- jp _fm_port_b_loop
393
+ jp _fm_port_loop
408
394
409
395
_fm_end:
410
396
;; set the output OPs for this instrument
@@ -521,7 +507,7 @@ _detune_positive:
521
507
fm_note_on_ext::
522
508
;; set new current FM channel
523
509
ld a , (hl)
524
- ld (state_fm_channel) , a
510
+ call fm_ctx_set_current
525
511
inc hl
526
512
jp fm_note_on
527
513
@@ -590,32 +576,14 @@ _fm_no_2_stop:
590
576
add d
591
577
;; b: f_num2 register for the FM channel
592
578
ld b , a
593
- ld a , e
594
- ;; TODO MACRO: write_port_a_or_b
595
- cp # 2
596
- jp c , _fm_fnum_2_port_a
597
- call ym2610_write_port_b
598
- jp _fm_post_fnum_2
599
- _fm_fnum_2_port_a:
600
- call ym2610_write_port_a
601
- _fm_post_fnum_2:
602
- ;; END MACRO
579
+ call ym2610_write_func
603
580
;; configure REG_FMx_FNUM_1
604
581
ld a , b
605
582
sub # 4
606
583
ld b , a
607
584
;; c: f_num LSB
608
585
ld c , l
609
- ld a , e
610
- ;; TODO MACRO: write_port_a_or_b
611
- cp # 2
612
- jp c , _fm_fnum_1_port_a
613
- call ym2610_write_port_b
614
- jp _fm_post_fnum_1
615
- _fm_fnum_1_port_a:
616
- call ym2610_write_port_a
617
- _fm_post_fnum_1:
618
- ;; END MACRO
586
+ call ym2610_write_func
619
587
620
588
;; start FM channel
621
589
;; a: FM channel (YM2610 encoding)
@@ -638,7 +606,7 @@ _fm_no_2_start:
638
606
;; fm context will now target the next channel
639
607
ld a , (state_fm_channel)
640
608
inc a
641
- ld (state_fm_channel) , a
609
+ call fm_ctx_set_current
642
610
643
611
ld a , # 1
644
612
ret
@@ -652,7 +620,7 @@ _fm_no_2_start:
652
620
fm_note_off_ext::
653
621
;; set new current FM channel
654
622
ld a , (hl)
655
- ld (state_fm_channel) , a
623
+ call fm_ctx_set_current
656
624
inc hl
657
625
jp fm_note_off
658
626
@@ -685,7 +653,7 @@ _fm_off_no_2:
685
653
;; FM context will now target the next channel
686
654
ld a , (state_fm_channel)
687
655
inc a
688
- ld (state_fm_channel) , a
656
+ call fm_ctx_set_current
689
657
690
658
ld a , # 1
691
659
ret
@@ -710,17 +678,7 @@ opx_set_common::
710
678
jp z , _no_adj
711
679
inc b
712
680
_no_adj:
713
-
714
- ;; TODO MACRO: write_port_a_or_b
715
- ld a , e
716
- cp # 2
717
- jp c , _opx_common_port_a
718
- call ym2610_write_port_b
719
- jp _opx_post_ common
720
- _opx_common_port_a:
721
- call ym2610_write_port_a
722
- _opx_post_ common :
723
- ;; END MACRO
681
+ call ym2610_write_func
724
682
725
683
pop de
726
684
pop bc
0 commit comments