-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbpm-fs.asm
1453 lines (1382 loc) · 44.4 KB
/
bpm-fs.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Famistudio at the start of bank 2.
; Only these subs are called from the outside: init, play, update
; See "famistudio.txt" for the original Famistudio source code.
temp equ $9f
temp_pitch equ $a0 ; temp_pitch
temp_x equ $a1 ; tmp_x
dat_ptr equ $a2 ; data pointer (2 bytes)
ptr2 equ $a4 ; 2 bytes, overlaps
env_val equ $0200 ; famistudio_env_value
env_rep equ $020b ; famistudio_env_repeat
env_adr_lo equ $0216 ; famistudio_env_addr_lo
env_adr_hi equ $0221 ; famistudio_env_addr_hi
env_ptr equ $022c ; famistudio_env_ptr
ptch_env_val_lo equ $0237 ; famistudio_pitch_env_value_lo
ptch_env_val_hi equ $023a ; famistudio_pitch_env_value_hi
ptch_env_rep equ $023d ; famistudio_pitch_env_repeat
ptch_env_adr_lo equ $0240 ; famistudio_pitch_env_addr_lo
ptch_env_adr_hi equ $0243 ; famistudio_pitch_env_addr_hi
ptch_env_ptr equ $0246 ; famistudio_pitch_env_ptr
ptch_env_fine equ $0249 ; famistudio_pitch_env_fine_value
slide_step equ $024c ; famistudio_slide_step
slide_ptch_lo equ $0250 ; famistudio_slide_pitch_lo
slide_ptch_hi equ $0254 ; famistudio_slide_pitch_hi
chn_ptr_lo equ $0258 ; famistudio_chn_ptr_lo
chn_ptr_hi equ $025d ; famistudio_chn_ptr_hi
chn_note equ $0262 ; famistudio_chn_note
chn_instru equ $0267 ; famistudio_chn_instrument
song_spd equ $026b ; famistudio_song_speed
chn_rep equ $026c ; famistudio_chn_repeat
chn_ret_lo equ $0271 ; famistudio_chn_return_lo
chn_ret_hi equ $0276 ; famistudio_chn_return_hi
chn_ref_len equ $027b ; famistudio_chn_ref_len
chn_vol_trk equ $0280 ; famistudio_chn_volume_track
chn_env_ovr equ $0285 ; famistudio_chn_env_override
chn_note_delay equ $028a ; famistudio_chn_note_delay
chn_cut_delay equ $028f ; famistudio_chn_cut_delay
duty_cycle equ $0294 ; famistudio_duty_cycle (3 cycles)
tempo_step_lo equ $0297 ; famistudio_tempo_step_lo
tempo_step_hi equ $0298 ; famistudio_tempo_step_hi
tempo_acc_lo equ $0299 ; famistudio_tempo_acc_lo
tempo_acc_hi equ $029a ; famistudio_tempo_acc_hi
tempo_adv_row equ $029b ; famistudio_tempo_advance_row
pal_adj equ $029c ; famistudio_pal_adjust
songlist_lo equ $029d ; famistudio_song_list_lo
songlist_hi equ $029e ; famistudio_song_list_hi
instru_lo equ $029f ; famistudio_instrument_lo
instru_hi equ $02a0 ; famistudio_instrument_hi
dpcm_list_lo equ $02a1 ; famistudio_dpcm_list_lo
dpcm_list_hi equ $02a2 ; famistudio_dpcm_list_hi
dpcm_effect equ $02a3 ; famistudio_dpcm_effect
pulse1_prev equ $02a4 ; famistudio_pulse1_prev
pulse2_prev equ $02a5 ; famistudio_pulse2_prev
out_buf equ $02a6 ; famistudio_output_buf (11 bytes)
sfx_adr_lo equ $02b1 ; famistudio_sfx_addr_lo
sfx_adr_hi equ $02b2 ; famistudio_sfx_addr_hi
sfx_rep equ $02b3 ; famistudio_sfx_repeat
sfx_ptr_lo equ $02b4 ; famistudio_sfx_ptr_lo
sfx_ptr_hi equ $02b5 ; famistudio_sfx_ptr_hi
sfx_ofs equ $02b6 ; famistudio_sfx_offset
sfx_buf equ $02b7 ; famistudio_sfx_buffer
sq1_vol equ $4000
sq1_sweep equ $4001
sq1_lo equ $4002
sq1_hi equ $4003
sq2_vol equ $4004
sq2_sweep equ $4005
sq2_lo equ $4006
sq2_hi equ $4007
tri_linear equ $4008
tri_lo equ $400a
tri_hi equ $400b
noise_vol equ $400c
noise_lo equ $400e
noise_hi equ $400f
dmc_freq equ $4010
dmc_raw equ $4011
dmc_start equ $4012
dmc_len equ $4013
snd_chn equ $4015
CHN_CNT equ 5 ; FAMISTUDIO_NUM_CHANNELS
DUTY_CYC_CNT equ 3 ; FAMISTUDIO_NUM_DUTY_CYCLES
SLIDE_CNT equ 4 ; FAMISTUDIO_NUM_SLIDES
ENV_CNT equ 11 ; FAMISTUDIO_NUM_ENVELOPES
PTCH_ENV_CNT equ 3 ; FAMISTUDIO_NUM_PITCH_ENVELOPES
ENV_VOL_OFF equ 0 ; FAMISTUDIO_ENV_VOLUME_OFF
ENV_NOTE_OFF equ 1 ; FAMISTUDIO_ENV_NOTE_OFF
ENV_DUTY_OFF equ 2 ; FAMISTUDIO_ENV_DUTY_OFF
CHN0_ENVS equ 0 ; FAMISTUDIO_CH0_ENVS
CHN1_ENVS equ 3 ; FAMISTUDIO_CH1_ENVS
CHN2_ENVS equ 6 ; FAMISTUDIO_CH2_ENVS
CHN3_ENVS equ 8 ; FAMISTUDIO_CH3_ENVS
NOI_SLI_IND equ 3 ; FAMISTUDIO_NOISE_SLIDE_INDEX
macro add _src
clc
adc _src
endm
macro sub _src
sec
sbc _src
endm
macro asr_a
cmp #$80
ror a
endm
base $8000
init ; "famistudio_init"
; "reset APU, initialize sound engine with some music data"
; in:
; A = platform (0=PAL, other=NTSC)
; YYXX = pointer to music data
; an entry point from outside
; called by: main program init
;
stx songlist_lo
sty songlist_hi
stx dat_ptr+0
sty dat_ptr+1
tax
beq +
lda #97
+ sta pal_adj
jsr stop
;
ldy #1
lda (dat_ptr),y ; music data
sta instru_lo
iny
lda (dat_ptr),y ; music data
sta instru_hi
iny
lda (dat_ptr),y ; music data
sta dpcm_list_lo
iny
lda (dat_ptr),y ; music data
sta dpcm_list_hi
;
lda #$80
sta pulse1_prev
sta pulse2_prev
;
lda #%00001111
sta snd_chn
lda #%10000000
sta tri_linear
lda #%00000000
sta noise_hi
lda #%00110000
sta sq1_vol
sta sq2_vol
sta noise_vol
lda #%00001000
sta sq1_sweep
sta sq2_sweep
jmp stop
stop ; "famistudio_music_stop"
; called by: init, play
;
lda #0
sta song_spd
sta dpcm_effect
;
ldx #0
set_channels sta chn_rep,x
sta chn_instru,x
sta chn_note,x
sta chn_ref_len,x
sta chn_vol_trk,x
sta chn_env_ovr,x
lda #$ff
sta chn_note_delay,x
sta chn_cut_delay,x
lda #0
inx
cpx #CHN_CNT
bne set_channels
;
ldx #0
- sta duty_cycle,x ; set_duty_cycles
inx
cpx #DUTY_CYC_CNT
bne -
;
ldx #0
- sta slide_step,x ; set_slides
inx
cpx #SLIDE_CNT
bne -
;
ldx #0
- lda #<dummy_env ; set_envelopes
sta env_adr_lo,x
lda #>dummy_env
sta env_adr_hi,x
lda #0
sta env_rep,x
sta env_val,x
sta env_ptr,x
inx
cpx #ENV_CNT
bne -
;
ldx #0
- lda #<dummy_ptch_env ; set_pitch_envelopes
sta ptch_env_adr_lo,x
lda #>dummy_ptch_env
sta ptch_env_adr_hi,x
lda #0
sta ptch_env_rep,x
sta ptch_env_val_lo,x
sta ptch_env_val_hi,x
sta ptch_env_fine,x
lda #1
sta ptch_env_ptr,x
inx
cpx #PTCH_ENV_CNT
bne -
;
jmp sample_stop
play ; "famistudio_music_play"
; an entry point from outside, at start + $00dd
; called by: main program init
;
ldx songlist_lo
stx dat_ptr+0
ldx songlist_hi
stx dat_ptr+1
ldy #0
cmp (dat_ptr),y ; music data
bcc +
rts ; unaccessed
+ asl a
sta dat_ptr+0
asl a
tax
asl a
adc dat_ptr+0
stx dat_ptr+0
adc dat_ptr+0
adc #5
tay
lda songlist_lo
sta dat_ptr+0
jsr stop
;
ldx #0
- lda (dat_ptr),y ; music data
sta chn_ptr_lo,x
iny
lda (dat_ptr),y ; music data
sta chn_ptr_hi,x
iny
lda #0
sta chn_rep,x
sta chn_instru,x
sta chn_note,x
sta chn_ref_len,x
lda #$f0
sta chn_vol_trk,x
lda #$ff
sta chn_note_delay,x
sta chn_cut_delay,x
inx
cpx #CHN_CNT
bne -
;
lda pal_adj
beq +
iny
iny
+ lda (dat_ptr),y ; music data
sta tempo_step_lo
iny
lda (dat_ptr),y ; music data
sta tempo_step_hi
lda #0
sta tempo_acc_lo
lda #6
sta tempo_acc_hi
sta song_spd
rts
mus_pause ; "famistudio_music_pause" (unaccessed)
tax
beq +
jsr sample_stop ; pause
lda #0
sta env_val+CHN0_ENVS+ENV_VOL_OFF
sta env_val+CHN1_ENVS+ENV_VOL_OFF
sta env_val+CHN2_ENVS+ENV_VOL_OFF
sta env_val+CHN3_ENVS+ENV_VOL_OFF
lda song_spd
ora #%10000000
bne ++
+ lda song_spd ; unpause
and #%01111111
++ sta song_spd ; done
rts
get_pitch ; "famistudio_get_note_pitch_macro"
; called by: update
;
clc
lda ptch_env_fine,y
adc ptch_env_val_lo,y
sta ptr2+0
lda ptch_env_fine,y
and #%10000000
beq +
lda #$ff
+ adc ptch_env_val_hi,y
sta ptr2+1
lda slide_step,y
beq +
ucod2 ; unaccessed chunk
lda slide_ptch_hi,y
asr_a
sta temp
lda slide_ptch_lo,y
ror a
add ptr2+0
sta ptr2+0
lda temp
adc ptr2+1
sta ptr2+1
+ clc
lda note_tbl_lsb,x
adc ptr2+0
sta ptr2+0
lda note_tbl_msb,x
adc ptr2+1
sta ptr2+1
rts
upd_row ; "famistudio_update_row"
; called by: upd_row_delays
;
jsr upd_chn
bcc +++
txa
tay
ldx chn_env,y
lda chn_instru,y
cpy #4
bcc ++
lda chn_note+4
bne +
jsr sample_stop ; unaccessed
ldx #4 ; unaccessed
bne +++ ; unaccessed
+ jsr sub11
ldx #4
jmp +++
++ jsr set_instru
+++ rts
upd_row_delays ; "famistudio_update_row_with_delays"
; called by: update
;
lda tempo_adv_row
beq +
lda chn_note_delay,x
bmi ++
lda #$ff ; unaccessed
sta chn_note_delay,x ; unaccessed
jsr upd_row ; unaccessed
jmp ++ ; unaccessed
+ lda chn_note_delay,x
bmi +++
sub #1
sta chn_note_delay,x
bpl +++
++ jsr upd_row
+++ lda chn_cut_delay,x
bmi +
sub #1 ; unaccessed
sta chn_cut_delay,x ; unaccessed
bpl + ; unaccessed
lda #0 ; unaccessed
sta chn_note,x ; unaccessed
+ rts
update ; "famistudio_update"
; an entry point from outside, at start + $021b
; called by: main program nmi
;
lda dat_ptr+0
pha
lda dat_ptr+1
pha
lda song_spd
bmi +
bne ++
+ jmp upd_chn_snd ; unaccessed
++ lda tempo_acc_hi
cmp song_spd
ldx #0
stx tempo_adv_row
bcc +
sbc song_spd
sta tempo_acc_hi
ldx #1
stx tempo_adv_row
;
+ ldx #0
- jsr upd_row_delays
inx
cpx #CHN_CNT
bne -
;
ldx #0
-- lda env_rep,x
beq +
dec env_rep,x
bne +++
+ lda env_adr_lo,x
sta dat_ptr+0
lda env_adr_hi,x
sta dat_ptr+1
;
ldy env_ptr,x
- lda (dat_ptr),y
bpl +
add #64
sta env_val,x
iny
bne ++
+ bne +
iny
lda (dat_ptr),y
tay
jmp -
;
+ iny
sta env_rep,x
++ tya
sta env_ptr,x
+++ inx
cpx #ENV_CNT
bne --
;
ldx #0
jmp cod2
cod1 ; unaccessed chunk
;
lda ptch_env_rep,x
sub #1
sta ptch_env_rep,x
and #%01111111
beq cod3
;
lda ptch_env_adr_lo,x
sta dat_ptr+0
lda ptch_env_adr_hi,x
sta dat_ptr+1
;
ldy ptch_env_ptr,x
dey
dey
lda (dat_ptr),y
add #$40
;
sta temp_pitch ; pitch_relative
clc
adc ptch_env_val_lo,x
sta ptch_env_val_lo,x
lda temp_pitch
bpl +
lda #$ff
+ adc ptch_env_val_hi,x ; pitch_relative_pos
sta ptch_env_val_hi,x
jmp cod7
cod2 lda ptch_env_rep,x
cmp #$81
bcs cod1
and #%01111111
beq cod3
dec ptch_env_rep,x
bne cod7
;
cod3 lda ptch_env_adr_lo,x
sta dat_ptr+0
lda ptch_env_adr_hi,x
sta dat_ptr+1
ldy #0
lda (dat_ptr),y
sta temp
ldy ptch_env_ptr,x
cod4 lda (dat_ptr),y
bpl cod5
add #$40
bit temp
bmi ucod3
sta ptch_env_val_lo,x
ora #%00000000
bmi +
lda #0
jmp ++
+ lda #$ff
++ sta ptch_env_val_hi,x
iny
jmp cod6
ucod3 ; unaccessed chunk
sta temp_pitch
clc
adc ptch_env_val_lo,x
sta ptch_env_val_lo,x
lda temp_pitch
and #%10000000
bpl +
lda #$ff
+ adc ptch_env_val_hi,x
sta ptch_env_val_hi,x
iny
jmp cod6
cod5 bne +
iny
lda (dat_ptr),y
tay
jmp cod4
+ iny
ora temp
sta ptch_env_rep,x
cod6 tya
sta ptch_env_ptr,x
cod7 inx
cpx #PTCH_ENV_CNT
bne cod2
ldx #0 ; update_slides
slide_proc lda slide_step,x ; slide_process
beq slide_next
ucod4 ; unaccessed chunk
clc
lda slide_step,x
adc slide_ptch_lo,x
sta slide_ptch_lo,x
lda slide_step,x
and #%10000000
beq pos_slide
lda #$ff ; negative_slide
adc slide_ptch_hi,x
sta slide_ptch_hi,x
bpl slide_next
jmp clr_slide
pos_slide adc slide_ptch_hi,x ; positive_slide
sta slide_ptch_hi,x
bmi slide_next
clr_slide lda #0 ; clear_slide
sta slide_step,x
slide_next inx
cpx #SLIDE_CNT
bne slide_proc
upd_chn_snd ; "famistudio_update_channel_sound"
macro upd_chn_snd_macro _arg1, _arg2
lda chn_note+_arg1
bne +
jmp ++ ; unaccessed
+ add env_val+_arg2+ENV_NOTE_OFF ; nocut
;
add pal_adj
tax
ldy #_arg1
jsr get_pitch
lda ptr2+0
sta out_buf+_arg2+1
lda ptr2+1
sta out_buf+_arg2+2
;
lda chn_vol_trk+_arg1 ; compute_volume
ora env_val+_arg2+ENV_VOL_OFF
tax
lda vol_tbl,x
++ ; set_volume
endm
upd_chn_snd_macro 0, 0
ldx env_val+0+ENV_DUTY_OFF
ora duty_tbl,x
sta out_buf+0
upd_chn_snd_macro 1, 3
ldx env_val+3+ENV_DUTY_OFF
ora duty_tbl,x
sta out_buf+3
upd_chn_snd_macro 2, 6
ora #%10000000
sta out_buf+6
; noise (mostly unaccessed)
lda chn_note+3
bne + ; never taken
jmp ++
+ add env_val+8+ENV_NOTE_OFF ; nocut
;
ldy slide_step+NOI_SLI_IND
beq +
sta temp
lda slide_ptch_lo+NOI_SLI_IND
sta ptr2+0
lda slide_ptch_hi+NOI_SLI_IND
asr_a
ror ptr2+0
asr_a
ror ptr2+0
asr_a
ror ptr2+0
asr_a
lda ptr2+0
ror a
add temp
+ and #%00001111 ; no_noise_slide
eor #%00001111
sta temp
ldx env_val+8+ENV_DUTY_OFF
lda duty_tbl,x
asl a
and #%10000000
ora temp
sta out_buf+10
;
lda chn_vol_trk+3 ; compute_volume
ora env_val+8+ENV_VOL_OFF
tax
lda vol_tbl,x
;
++ ldx env_val+8+ENV_DUTY_OFF ; set_volume
ora duty_tbl,x
ora #%11110000
sta out_buf+9
;
lda song_spd ; update_sound_done
bmi +
clc
lda tempo_acc_lo
adc tempo_step_lo
sta tempo_acc_lo
lda tempo_acc_hi
adc tempo_step_hi
sta tempo_acc_hi
;
+ ldx #0 ; skip_famitracker_tempo_update
jsr sfx_upd
ldx #$0f
jsr sfx_upd
;
lda out_buf+0
sta sq1_vol
lda out_buf+1
sta sq1_lo
lda out_buf+2
;
cmp pulse1_prev
beq +
sta pulse1_prev
sta sq1_hi
;
+ lda out_buf+3 ; no_pulse1_upd
sta sq2_vol
lda out_buf+4
sta sq2_lo
lda out_buf+5
cmp pulse2_prev
beq +
sta pulse2_prev
sta sq2_hi
;
+ lda out_buf+6 ; no_pulse2_upd
sta tri_linear
lda out_buf+7
sta tri_lo
lda out_buf+8
sta tri_hi
;
lda out_buf+9
sta noise_vol
lda out_buf+10
sta noise_lo
pla
sta dat_ptr+1
pla
sta dat_ptr+0
rts
set_instru ; "famistudio_set_instrument"
; called by: upd_row
;
sty temp_pitch
asl a
tay
lda instru_hi
adc #0
sta dat_ptr+1
lda instru_lo
sta dat_ptr+0
lda (dat_ptr),y
sta env_adr_lo,x
iny
lda (dat_ptr),y
iny
sta env_adr_hi,x
inx
stx temp_x
ldx temp_pitch
lda chn_env_ovr,x
lsr a
ldx temp_x
bcc +
iny ; unaccessed
jmp ++ ; unaccessed
;
+ lda (dat_ptr),y
sta env_adr_lo,x
iny
lda (dat_ptr),y
sta env_adr_hi,x
;
++ lda #1
sta env_ptr-1,x
lda #0
sta env_val+10,x
sta env_rep,x
sta env_ptr,x
lda temp_pitch
cmp #2
bne +
iny
iny
bne ++ ; unconditional
;
+ inx
iny
lda (dat_ptr),y
sta env_adr_lo,x
iny
lda (dat_ptr),y
sta env_adr_hi,x
lda #0
sta env_rep,x
sta env_ptr,x
stx temp_x
ldx temp_pitch
lda chn_to_duty,x
tax
lda duty_cycle,x
ldx temp_x
sta env_val,x
;
++ ldx temp_pitch
lda chn_env_ovr,x
bmi +
lda chn_to_ptch_env,x
bmi +
tax
lda #1
sta ptch_env_ptr,x
lda #0
sta ptch_env_rep,x
sta ptch_env_val_lo,x
sta ptch_env_val_hi,x
iny
lda (dat_ptr),y
sta ptch_env_adr_lo,x
iny
lda (dat_ptr),y
sta ptch_env_adr_hi,x
;
+ ldx temp_pitch
rts
upd_chn ; "famistudio_update_channel"
; called by: upd_row
;
lda chn_rep,x
beq +
dec chn_rep,x
clc
rts
;
+ lda #0
sta temp_x
lda chn_ptr_lo,x
sta dat_ptr+0
lda chn_ptr_hi,x
sta dat_ptr+1
ldy #0
cod12 lda (dat_ptr),y
inc dat_ptr+0
bne +
inc dat_ptr+1
+ cmp #$61
bcs +
jmp cod13
+ ora #%00000000
bpl +
jmp cod14
+ cmp #$70
bcc +
and #%00001111
asl a
asl a
asl a
asl a
sta chn_vol_trk,x
jmp cod12
+ stx temp
; "jmp_to_opcode"
and #%00001111
tax
lda jmp_tbl_lo,x ; jump to index X in jump table
sta ptr2+0
lda jmp_tbl_hi,x
sta ptr2+1
ldx temp
jmp (ptr2)
opcode2 stx temp
lda chn_to_ptch_env,x
tax
lda (dat_ptr),y
inc dat_ptr+0
bne +
inc dat_ptr+1 ; unaccessed
+ sta ptch_env_fine,x
ldx temp
jmp cod12
clr_ptch_ovr ; "opcode_clear_pitch_override_flag"
lda #$7f
and chn_env_ovr,x
sta chn_env_ovr,x
jmp cod12
ovr_ptch_env ; "opcode_override_pitch_envelope"
lda #$80
ora chn_env_ovr,x
sta chn_env_ovr,x
stx temp
lda chn_to_ptch_env,x
tax
lda (dat_ptr),y
sta ptch_env_adr_lo,x
iny
lda (dat_ptr),y
sta ptch_env_adr_hi,x
lda #0
tay
sta ptch_env_rep,x
lda #1
sta ptch_env_ptr,x
ldx temp
clc
lda #2
adc dat_ptr+0
sta dat_ptr+0
bcc +
inc dat_ptr+1 ; unaccessed
+ jmp cod12
clr_arp_ovr ; "opcode_clear_arpeggio_override_flag" (unaccessed)
lda #$fe
and chn_env_ovr,x
sta chn_env_ovr,x
jmp cod12
ovr_arp_env ; "opcode_override_arpeggio_envelope" (unaccessed)
lda #1
ora chn_env_ovr,x
sta chn_env_ovr,x
stx temp
lda chn_to_arp,x
tax
lda (dat_ptr),y
sta env_adr_lo,x
iny
lda (dat_ptr),y
sta env_adr_hi,x
lda #0
tay
sta env_rep,x
sta env_val,x
sta env_ptr,x
ldx temp
clc
lda #2
adc dat_ptr+0
sta dat_ptr+0
bcc +
inc dat_ptr+1
+ jmp cod12
rst_arp ; "opcode_reset_arpeggio" (unaccessed)
stx temp
lda chn_to_arp,x
tax
lda #0
sta env_rep,x
sta env_val,x
sta env_ptr,x
ldx temp
jmp cod12
opcode3 stx temp
lda chn_to_duty,x
tax
lda (dat_ptr),y
sta duty_cycle,x
sta temp_pitch
ldx temp
lda chn_to_duty_env,x
tax
lda temp_pitch
sta env_val,x
ldx temp
inc dat_ptr+0
bne +
inc dat_ptr+1 ; unaccessed
+ jmp cod12
opcode4 lda (dat_ptr),y
sta chn_note_delay,x
inc dat_ptr+0
bne +
inc dat_ptr+1 ; unaccessed
+ jmp cod17
opcode5 ; unaccessed chunk
lda #$40
sta temp_x
lda (dat_ptr),y
sta chn_cut_delay,x
inc dat_ptr+0
bne +
inc dat_ptr+1
+ jmp cod12
opcode1 ; unaccessed chunk
lda #$80
ora temp_x
sta temp_x
jmp cod12
noi_slide ; "noise_slide" (unaccessed)
lda (dat_ptr),y
iny
sta slide_step+NOI_SLI_IND
lda (dat_ptr),y
iny
sec
sbc (dat_ptr),y
sta slide_ptch_lo+NOI_SLI_IND
bpl +
lda #$ff ; negative_noise_slide
bmi ++
+ lda #0 ; positive_noise_slide
++ ; noise_shift
rept 4
asl slide_ptch_lo+3
rol a
endr
sta slide_ptch_hi+3
jmp +
slide ; "opcode_slide" (unaccessed)
cpx #3
beq noi_slide
stx temp
lda chn_to_slide,x
tax
lda (dat_ptr),y
iny
sta slide_step,x
lda (dat_ptr),y
add pal_adj
sta temp_pitch
iny
lda (dat_ptr),y
ldy temp_pitch
adc pal_adj
stx temp_pitch
tax