-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.s
1802 lines (1707 loc) · 34.8 KB
/
player.s
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
;
; ft_music_play
;
; The player routine
;
ft_music_play:
lda var_PlayerFlags ; Skip if player is disabled
and #%00000001 ;;; ;; ; bit 0 = enable playing
bne :+
rts ; Not playing, return
:
.if .defined(USE_FDS)
lda #$00
sta var_ch_ModEffWritten
.endif
; Run delayed channels
ldx #$00
@ChanLoop:
CH_LOOP_START @ChanLoopEpilog
lda var_ch_Delay, x
beq @SkipDelay
sec
sbc #$01
sta var_ch_Delay, x
bne @SkipDelay
jsr ft_read_pattern ; Read the delayed note
jmp @ChanLoopEpilog ; ;; ;;;
@SkipDelay:
lda #$00 ;;; ;; ; Clear note trigger flag
sta var_ch_Trigger, x ; ;; ;;;
@ChanLoopEpilog:
CH_LOOP_END @ChanLoop
; Speed division
lda var_Tempo_Accum + 1
bmi ft_do_row_update ; Counter < 0
ora var_Tempo_Accum
beq ft_do_row_update ; Counter = 0
jmp ft_skip_row_update
; Read a row
ft_do_row_update:
.if .defined(USE_DPCM)
lda #$00
sta var_ch_DPCM_Retrig
.endif
lda var_PlayerFlags ;;; ;; ;
and #%00000010
beq :+
eor var_PlayerFlags
and #%11111100
sta var_PlayerFlags
:
; Switches to new frames are delayed to next row to resolve issues with delayed notes.
; It won't work if new pattern adresses are loaded before the delayed note is played
lda var_Load_Frame
beq @SkipFrameLoad
;;; ;; ; from 0.4.6
ldx #$00
@Delay:
CH_LOOP_START @DelayEpilog
lda var_ch_Delay, x
beq @DelayEpilog
lda #$00
sta var_ch_Delay, x
jsr ft_read_pattern ; skip over missed delay note
@DelayEpilog:
CH_LOOP_END @Delay
lda #$00
sta var_Load_Frame
lda var_Current_Frame
jsr ft_load_frame
@SkipFrameLoad:
; Read one row from all patterns
ldx #$00
ft_read_channels:
CH_LOOP_START ft_read_channels_epilog
jsr ft_read_pattern ; Get new notes
ft_read_channels_epilog:
CH_LOOP_END ft_read_channels
; Should jump?
lda var_Jump
beq @NoJump
; Yes, jump
sec
sbc #$01
sta var_Current_Frame
; jsr ft_load_frame
lda #$01
sta var_Load_Frame
jmp @NoPatternEnd
@NoJump:
; Should skip?
lda var_Skip
beq @NoSkip
; Yes, skip
.if .defined(ENABLE_ROW_SKIP)
; Store next row number in Temp2
sec
sbc #$01
sta var_SkipTo
.endif
jmp @NextFrame
@NoSkip:
; Current row in all channels are processed, update info
inc var_Pattern_Pos
lda var_Pattern_Pos ; See if end is reached
cmp var_Pattern_Length
bne @NoPatternEnd
@NextFrame: ;;; ;; ; shared
; End of current frame, load next
lda #$01
sta var_Load_Frame
inc var_Current_Frame
lda var_Current_Frame
cmp var_Frame_Count
bne @NoPatternEnd
lda #$00
sta var_Current_Frame
@NoPatternEnd:
jsr ft_restore_speed ; Reset frame divider counter
ft_skip_row_update:
; Speed division
sec
lda var_Tempo_Accum ; Decrement speed counter
sbc var_Tempo_Count
sta var_Tempo_Accum
lda var_Tempo_Accum + 1
sbc var_Tempo_Count + 1
sta var_Tempo_Accum + 1
ldx #$00
ft_loop_fx_state:
CH_LOOP_START ft_loop_fx_state_epilog
; Note cut effect (Sxx)
lda var_ch_NoteCut, x
beq @BeginRelease
bpl :+ ;;; ;; ;
and #$7F
sta var_ch_NoteCut, x
bpl :++ ; always
: sta var_ch_NoteCut, x
dec var_ch_NoteCut, x
: beq :+
bpl @BeginRelease
: lda #$00 ; ;; ;;;
sta var_ch_NoteCut, x
sta var_ch_Note, x ; todo: make a subroutine for note cut
.if .defined(USE_DPCM)
lda ft_channel_type, x
cmp #CHAN_DPCM
beq @BeginRelease ; 0CC: check
lda #$00
.endif
sta var_ch_PortaToLo, x
sta var_ch_PortaToHi, x
sta var_ch_TimerPeriodLo, x
sta var_ch_TimerPeriodHi, x
.if .defined(USE_VRC7)
lda ft_channel_type, x
cmp #CHAN_VRC7
bne @BeginRelease
lda #$00 ; Halt VRC7 channel
sta var_ch_vrc7_Command - VRC7_OFFSET, x
.endif
@BeginRelease:
lda var_ch_NoteRelease, x ;;; ;; ; Delayed note release
beq @BeginTranspose
bpl :+ ;;; ;; ;
and #$7F
sta var_ch_NoteRelease, x
bpl :++ ; always
: sta var_ch_NoteRelease, x
dec var_ch_NoteRelease, x
: beq :+
bpl @BeginTranspose
: lda #$00 ; ;; ;;;
sta var_ch_NoteRelease, x
lda var_ch_State, x
and #STATE_RELEASE ;;; ;; ;
bne @BeginTranspose
ora #STATE_RELEASE
sta var_ch_State, x
.if .defined(USE_DPCM)
lda ft_channel_type, x
cmp #CHAN_DPCM
bne :+
lda #$FF
sta var_ch_Note, x
bmi @BeginTranspose ; always
:
.endif
.if .defined(USE_VRC7)
lda ft_channel_type, x ;;; ;; ;
cmp #CHAN_VRC7
beq @BeginTranspose
.endif
jsr ft_instrument_release
@BeginTranspose:
lda var_ch_Transpose, x ;;; ;; ;
beq @DoneTranspose
bmi @Negative
sec
sbc #$10
sta var_ch_Transpose, x
bpl @DoneTranspose ; else var_ch_Transpose, x == #$Fx
and #$0F
clc
jsr ft_clear_transpose
; jmp @DoneTranspose
beq @DoneTranspose ; always
@Negative:
sec
sbc #$10
sta var_ch_Transpose, x
bmi @DoneTranspose ; else var_ch_Transpose, x == #$7x
eor #$8F
sec
jsr ft_clear_transpose
@DoneTranspose:
lda var_ch_VolDelay, x
beq :+
cmp #$10
bcs :+
asl a
asl a
asl a
asl a
sta var_ch_VolDelay, x
:
ft_loop_fx_state_epilog:
CH_LOOP_END ft_loop_fx_state ; ;; ;;;
; Update channel instruments and effects
ldx #$00
; Loop through wave channels
ft_loop_channels:
CH_LOOP_START ft_loop_channels_epilog
.if .defined(USE_ALL) ;;; ;; ; Skip DPCM
cpx #EFF_CHANS
.elseif .defined(USE_N163)
cpx var_EffChannels
.else
cpx #EFF_CHANS
.endif
beq ft_update_apu
; Do channel effects, like portamento and vibrato
jsr ft_run_effects
; Instrument sequences
lda var_ch_Note, x
beq :+
jsr ft_run_instrument ; Update instruments
: jsr ft_calc_period
;;; ;; ; Decrement volume delay counter after everything else is done
; preferred behaviour for delayed effects?
lda var_ch_VolDelay, x
and #$0F
bne :+
lda var_ch_VolDelay, x
and #$F0
beq :+
lsr a
sta var_ch_VolColumn, x
lda #$00
sta var_ch_VolDelay, x
:
lda var_ch_VolDelay, x
cmp #$10
bcc :+
sbc #$10
sta var_ch_VolDelay, x
:
ft_loop_channels_epilog: ; ;; ;;;
CH_LOOP_END ft_loop_channels
ft_update_apu:
; Finally update APU and expansion chip registers
jsr ft_update_2a03
ft_update_ext: ;; Patch
.if .defined(USE_VRC6)
jsr ft_update_vrc6
.endif
.if .defined(USE_VRC7)
jsr ft_update_vrc7
.endif
.if .defined(USE_FDS)
jsr ft_update_fds
.endif
.if .defined(USE_MMC5)
jsr ft_update_mmc5
.endif
.if .defined(USE_N163)
jsr ft_update_n163
.endif
.if .defined(USE_S5B)
jsr ft_update_s5b
.endif
END: ; End of music routine, return
rts
; Process a pattern row in channel X
ft_read_pattern:
ldy var_ch_NoteDelay, x ; First check if in the middle of a row delay
beq :+
dey
tya
sta var_ch_NoteDelay, x
rts ; And skip
: sty var_Sweep ; Y = 0
.if .defined(USE_BANKSWITCH)
;;; ;; ; First setup the bank
lda var_InitialBank
beq :+
jsr ft_bankswitch
: ; Go on
.endif
lda var_ch_PatternAddrLo, x ; Load pattern address
sta var_Temp_Pattern
lda var_ch_PatternAddrHi, x
sta var_Temp_Pattern + 1
.if .defined(USE_BANKSWITCH)
;;; ;; ; Then etup the pattern bank
lda var_ch_Bank, x
beq :+
jsr ft_bankswitch
:
.endif
ft_read_note:
nop ;;; ;; ;
lda (var_Temp_Pattern), y ; Read pattern command
bpl :+
jmp @Effect
: bne :+ ; Rest
jmp @JumpToDone ; branch
: cmp #$7F
; beq @NoteOff ; Note off
bne :+
jsr ft_push_echo_buffer
jmp @NoteOff
: cmp #$7E
; beq @NoteRelease ; Note release
bne :+
jmp @NoteRelease
:
;;; ;; ; Echo buffer access
cmp #$70
bcc @NoEcho
and #$0F ; sec; sbc #$70
bne :+ ; first echo
txa ; for the tax below
bpl :+++ ; always, unless there are more than 0x80 channels
: sta var_Temp ; = echo index
txa
clc
: adc #CHANNELS
dec var_Temp
bne :-
: stx var_Temp ; = channel index
tax
lda var_ch_EchoBuffer, x ; actually load the note
bne :+
ldx var_Temp
jsr ft_push_echo_buffer ;;; ;; ;
jmp @JumpToDone
: ldx var_Temp
@NoEcho:
; ;; ;;;
; Read a note
sta var_ch_Note, x ; Note on
jsr ft_push_echo_buffer ;;; ;; ;
jsr ft_translate_freq
lda #$01 ;;; ;; ; Set note trigger flag
sta var_ch_Trigger, x ; ;; ;;;
lda var_ch_NoteCut, x
bmi :+
lda #$00
sta var_ch_NoteCut, x
:
lda var_ch_NoteRelease, x
bmi :+
lda #$00
sta var_ch_NoteRelease, x
:
.if 0
lda var_ch_Transpose, x
and #$F0
beq :+
;lda #$00
;sta var_ch_Transpose, x
:
.endif
lda var_ch_VolSlide, x
bne :+
lda var_ch_VolDefault, x
sta var_ch_VolColumn, x
:
.if .defined(USE_DPCM)
lda ft_channel_type, x ;;; ;; ;
cmp #CHAN_DPCM
bne :+
jsr ft_set_trigger ;;; ;; ;
jmp @ReadIsDone
: ; DPCM skip
.endif
.if .defined(USE_VRC7)
lda ft_channel_type, x
cmp #CHAN_VRC7
bne :+
jsr ft_vrc7_trigger
jmp @RestoreDuty
: ; VRC7 skip
.endif
.if 0
.if .defined(USE_N163) ;;; ;; ;
lda ft_channel_type, x
cmp #CHAN_N163
bne :+
;jsr ft_n163_load_wave2
:
.endif ; ;; ;;;
.endif
jsr ft_reset_instrument
jsr ft_set_trigger ;;; ;; ;
.if .defined(USE_FDS) ;;; ;; ; removed var_VolTemp
lda ft_channel_type, x
cmp #CHAN_FDS
bne :+
lda #$1F ; FDS max vol is 31
bpl :++ ; always
: lda #$0F ; Default max vol is 15
:
.else
lda #$0F ; Default max vol is 15
.endif
sta var_ch_Volume, x
; lda #$00
; sta var_ch_ArpeggioCycle, x
.ifdef USE_S5B ;;; ;; ;
lda ft_channel_type, x
cpx #CHAN_S5B
beq @ResetSlide
.endif ; ;; ;;;
@RestoreDuty:
lda var_ch_DutyDefault, x
sta var_ch_DutyCurrent, x
@ResetSlide:
; Clear the slide effect on new notes
lda var_ch_Effect, x
cmp #EFF_SLIDE_UP
beq :+
cmp #EFF_SLIDE_DOWN
bne :++
: lda #EFF_NONE
sta var_ch_Effect, x
:
cpx #APU_NOI ;;; ;; ;
bne :+
lda #$80 ; should be enough
sta var_ch_TimerPeriodHi, x ; ;; ;;;
: cpx #APU_TRI ; Skip if not square
bcs @JumpToDone ; assume default layout
lda #$00
sta var_ch_Sweep, x ; Reset sweep
@JumpToDone:
jmp @ReadIsDone
@NoteRelease:
.if .defined(USE_DPCM)
lda ft_channel_type, x ;;; ;; ;
cmp #CHAN_DPCM ; ;; ;;;
bne :+
lda #$FF
sta var_ch_Note, x
jmp @ReadIsDone
:
.endif
lda var_ch_State, x
and #STATE_RELEASE
bne @JumpToDone
ora #STATE_RELEASE
sta var_ch_State, x
.if .defined(USE_VRC7)
lda ft_channel_type, x ;;; ;; ;
cmp #CHAN_VRC7 ; ;; ;;;
beq @JumpToDone
.endif
jsr ft_instrument_release
jmp @ReadIsDone
@NoteOff:
lda #$00
sta var_ch_Note, x
.if .defined(USE_DPCM)
lda ft_channel_type, x ;;; ;; ;
cmp #CHAN_DPCM ; ;; ;;;
bne :+
jmp @ReadIsDone
: lda #$00
.endif
.if .defined(USE_VRC7)
lda ft_channel_type, x
cmp #CHAN_VRC7
bne :+
lda #$00 ; Halt VRC7 channel
sta var_ch_vrc7_Command - VRC7_OFFSET, x
sta var_ch_PortaToLo, x
sta var_ch_PortaToHi, x
sta var_ch_TimerPeriodLo, x
sta var_ch_TimerPeriodHi, x
jmp @ReadIsDone
: lda #$00
.endif
sta var_ch_Volume, x
sta var_ch_PortaToLo, x
sta var_ch_PortaToHi, x
sta var_ch_TimerPeriodLo, x
sta var_ch_TimerPeriodHi, x
cpx #$02 ; Skip all but the square channels
bcs :+
lda #$FF
sta var_ch_PrevFreqHigh, x
: jmp @ReadIsDone
@VolumeCommand: ; Handle volume
asl a
asl a
asl a
;asl a
and #$78
sta var_ch_VolColumn, x
sta var_ch_VolDefault, x ;;; ;; ;
iny
jmp ft_read_note
@InstCommand: ; Instrument change
and #$0F
asl a
jsr ft_load_instrument
iny
jmp ft_read_note
@Effect:
cmp #$F0 ; See if volume
bcs @VolumeCommand
cmp #$E0 ; See if a quick instrument command
bcs @InstCommand
and #$7F ; Look up the command address
sty var_Temp ; from the command table
tay
lda ft_command_table, y
sta var_Temp_Pointer
iny
lda ft_command_table, y
sta var_Temp_Pointer + 1
ldy var_Temp
iny
lda #>ft_read_note ;; Reloc
pha
lda #<ft_read_note ;; Reloc
pha
jmp (var_Temp_Pointer) ; And jump there
@ReadIsDone:
lda var_ch_DefaultDelay, x ; See if there's a default delay
cmp #$FF
beq :+ ; If so then use it
sta var_ch_NoteDelay, x
bne ft_read_is_done ; always
: iny
lda (var_Temp_Pattern), y ; A note is immediately followed by the amount of rows until next note
sta var_ch_NoteDelay, x
ft_read_is_done:
clc ; Store pattern address
iny
tya
adc var_Temp_Pattern
sta var_ch_PatternAddrLo, x
lda #$00
adc var_Temp_Pattern + 1
sta var_ch_PatternAddrHi, x
lda var_Sweep ; Check sweep
beq :+
sta var_ch_Sweep, x ; Store sweep, only used for square 1 and 2
lda #$00
sta var_Sweep
sta var_ch_PrevFreqHigh, x
: rts
; Read pattern to A and move to next byte
ft_get_pattern_byte:
lda (var_Temp_Pattern), y ; Get the instrument number
pha
iny
pla
rts
.macro pushEcho count
.if count = 0
pla
sta var_ch_EchoBuffer, x
.else
lda var_ch_EchoBuffer + CHANNELS * (count - 1), x
sta var_ch_EchoBuffer + CHANNELS * count, x
pushEcho (count - 1)
.endif
.endmacro
ft_push_echo_buffer: ;;; ;; ; Echo buffer store
pha
pushEcho ECHO_BUFFER_LENGTH
rts
;;; ;; ;
ft_set_trigger:
lda var_ch_State, x
and #($FF - STATE_RELEASE)
sta var_ch_State, x
rts
;;; ;; ; 050B
ft_set_hold:
lda var_ch_State, x
ora #STATE_HOLD
sta var_ch_State, x
rts
ft_get_hold_clear:
lda var_ch_State, x
and #STATE_HOLD
pha
eor var_ch_State, x
sta var_ch_State, x
pla
rts
; ;; ;;;
;
; Command table
;
ft_command_table:
.word ft_cmd_instrument ; 80
; .word ft_cmd_hold
.word ft_set_hold ; 82
.word ft_cmd_duration ; 84
.word ft_cmd_noduration ; 86
.word ft_cmd_speed ; 88
.word ft_cmd_tempo ; 8A
.word ft_cmd_jump ; 8C
.word ft_cmd_skip ; 8E
.word ft_cmd_halt ; 90
.word ft_cmd_effvolume ; 92
.word ft_cmd_clear ; 94
.word ft_cmd_porta_up ; 96
.word ft_cmd_porta_down ; 98
.word ft_cmd_portamento ; 9A
.word ft_cmd_arpeggio ; 9C
.word ft_cmd_vibrato ; 9E
.word ft_cmd_tremolo ; A0
.word ft_cmd_pitch ; A2
.word ft_cmd_reset_pitch ; A4
.word ft_cmd_duty ; A6
.word ft_cmd_delay ; A8
.word ft_cmd_sweep ; AA
.word ft_cmd_dac ; AC
.word ft_cmd_sample_offset ; AE
.word ft_cmd_slide_up ; B0
.word ft_cmd_slide_down ; B2
.word ft_cmd_vol_slide ; B4
.word ft_cmd_note_cut ; B6
.word ft_cmd_retrigger ; B8
.word ft_cmd_dpcm_pitch ; BA
;;; ;; ;
.word ft_cmd_note_release ; BC
.word ft_cmd_linear_counter ; BE
.word ft_cmd_groove ; C0
.word ft_cmd_delayed_volume ; C2
.word ft_cmd_transpose ; C4
.if .defined(USE_VRC7)
.word ft_cmd_vrc7_patch_change
.word ft_cmd_vrc7_port
.word ft_cmd_vrc7_write
.endif
.if .defined(USE_FDS)
.word ft_cmd_fds_mod_depth
.word ft_cmd_fds_mod_rate_hi
.word ft_cmd_fds_mod_rate_lo
.word ft_cmd_fds_volume
.word ft_cmd_fds_mod_bias
.endif
.if .defined(USE_N163)
.word ft_cmd_n163_wave_buffer
.endif
.if .defined(USE_S5B) ;;; ;; ;
.word ft_cmd_s5b_env_type
.word ft_cmd_s5b_env_rate_hi
.word ft_cmd_s5b_env_rate_lo
.word ft_cmd_s5b_noise
.endif ; ;; ;;;
; .word ft_cmd_expand
;
; Command functions
;
.if 0
; Loop expansion
ft_cmd_expand:
lda var_ch_LoopCounter, x ; See if already looping
bne :+
; Load new loop
jsr ft_get_pattern_byte ; number of loops
sta var_ch_LoopCounter, x
jsr ft_get_pattern_byte ; length in bytes
sta var_Temp
; Calculate pattern pointer
sec
lda var_Temp_Pattern
sbc var_Temp
sta var_Temp_Pattern
lda var_Temp_Pattern + 1
sbc #$00
sta var_Temp_Pattern + 1
ldy #$00
jmp ft_read_note
: ; Already looping
sec
sbc #$01
beq :+ ; Check if done
sta var_ch_LoopCounter, x
iny ; number of loops, ignore
jsr ft_get_pattern_byte ; length in bytes
sta var_Temp
; Calculate pattern pointer
sec
lda var_Temp_Pattern
sbc var_Temp
sta var_Temp_Pattern
lda var_Temp_Pattern + 1
sbc #$00
sta var_Temp_Pattern + 1
ldy #$00
jmp ft_read_note
: ; Loop is done
sta var_ch_LoopCounter, x
iny ; number of loops, ignore
iny ; length in bytes, ignore
rts
.endif
; Change instrument
ft_cmd_instrument:
jsr ft_get_pattern_byte
jmp ft_load_instrument
;;; ;; ; 050B
;ft_cmd_hold:
; jsr ft_set_hold
; rts
; Set default note duration
ft_cmd_duration:
jsr ft_get_pattern_byte
sta var_ch_DefaultDelay, x
rts
; No default note duration
ft_cmd_noduration:
lda #$FF
sta var_ch_DefaultDelay, x
rts
; Effect: Speed (Fxx)
ft_cmd_speed:
jsr ft_get_pattern_byte
sta var_Speed
lda #$00 ;;; ;; ;
sta var_GroovePointer ; ;; ;;;
jmp ft_calculate_speed
; Effect: Tempo (Fxx)
ft_cmd_tempo:
jsr ft_get_pattern_byte
sta var_Tempo
jmp ft_calculate_speed
;;; ;; ; Effect: Groove (Oxx)
ft_cmd_groove:
jsr ft_get_pattern_byte
sta var_GroovePointer
lda #$00
sta var_Speed
jmp ft_calculate_speed
; Effect: Jump (Bxx)
ft_cmd_jump:
jsr ft_get_pattern_byte
sta var_Jump
rts
; Effect: Skip (Dxx)
ft_cmd_skip:
jsr ft_get_pattern_byte
sta var_Skip
rts
; Effect: Halt (Cxx)
ft_cmd_halt:
jsr ft_get_pattern_byte
lda var_PlayerFlags
ora #%00000010
sta var_PlayerFlags
rts
;;; ;; ; Effect: Hardware envelope control (Exx)
ft_cmd_effvolume:
jsr ft_get_pattern_byte
bmi :+
asl a
asl a
asl a
sta var_Temp
lda var_ch_LengthCounter, x
and #$01
ora #$02
bpl :++ ; always
: and #%00000011
sta var_Temp
lda var_ch_LengthCounter, x
and #%11111000
: ora var_Temp
sta var_ch_LengthCounter, x
rts
; Effect: Portamento (3xx)
ft_cmd_portamento:
jsr ft_get_pattern_byte
sta var_ch_EffParam, x
lda #EFF_PORTAMENTO
sta var_ch_Effect, x
rts
; Effect: Portamento up (1xx)
ft_cmd_porta_up:
jsr ft_get_pattern_byte
sta var_ch_EffParam, x
lda #EFF_PORTA_UP
sta var_ch_Effect, x
rts
; Effect: Portamento down (2xx)
ft_cmd_porta_down:
jsr ft_get_pattern_byte
sta var_ch_EffParam, x
lda #EFF_PORTA_DOWN
sta var_ch_Effect, x
rts
; Effect: Arpeggio (0xy)
ft_cmd_arpeggio:
jsr ft_get_pattern_byte
sta var_ch_EffParam, x
; lda #$00
; sta var_ch_ArpeggioCycle, x
lda #EFF_ARPEGGIO
sta var_ch_Effect, x
rts
ft_cmd_clear:
lda #$00
sta var_ch_EffParam, x
sta var_ch_Effect, x
sta var_ch_PortaToLo, x
sta var_ch_PortaToHi, x
rts
; Effect: Hardware sweep (Hxy / Ixy)
ft_cmd_sweep:
jsr ft_get_pattern_byte
sta var_Sweep
rts
; Effect: Vibrato (4xy)
ft_cmd_vibrato:
jsr ft_get_pattern_byte
pha
lda var_ch_VibratoSpeed, x
bne @FinishPos
.if .defined(USE_OLDVIBRATO)
lda var_SongFlags
and #FLAG_OLDVIBRATO
beq :+
lda #48
:
.endif
sta var_ch_VibratoPos, x
@FinishPos:
pla
pha
and #$F0
sta var_ch_VibratoDepth, x
pla
and #$0F
sta var_ch_VibratoSpeed, x
rts
; Effect: Tremolo (7xy)
ft_cmd_tremolo:
jsr ft_get_pattern_byte
pha
and #$F0
sta var_ch_TremoloDepth, x
pla
and #$0F
sta var_ch_TremoloSpeed, x
cmp #$00
beq @ResetTremolo
rts
@ResetTremolo: ; Clear tremolo
sta var_ch_TremoloPos, x
rts
; Effect: Pitch (Pxx)
ft_cmd_pitch:
jsr ft_get_pattern_byte
sta var_ch_FinePitch, x
rts
ft_cmd_reset_pitch:
lda #$80
sta var_ch_FinePitch, x
rts
; Effect: Delay (Gxx)
ft_cmd_delay:
pla ; discard return destination
pla
jsr ft_get_pattern_byte
sta var_ch_Delay, x
dey
jmp ft_read_is_done
; Effect: delta counter setting (Zxx)
ft_cmd_dac:
.if .defined(USE_DPCM)
jsr ft_get_pattern_byte
sta var_ch_DPCMDAC
.endif
rts
; Effect: Duty cycle (Vxx)
ft_cmd_duty:
jsr ft_get_pattern_byte
sta var_ch_DutyCurrent, x ;;; ;; ;
sta var_ch_DutyDefault, x
.if .defined(USE_N163)
lda ft_channel_type, x
cmp #CHAN_N163
bne :+
jmp ft_n163_load_wave2
:
.endif
rts
; Effect: Sample offset
ft_cmd_sample_offset:
.if .defined(USE_DPCM)
jsr ft_get_pattern_byte
sta var_ch_DPCM_Offset
.endif
rts
; Effect: Slide pitch up
ft_cmd_slide_up:
jsr ft_get_pattern_byte ; Fetch speed / note
sta var_ch_EffParam, x
lda #EFF_SLIDE_UP_LOAD
sta var_ch_Effect, x
rts
; Effect: Slide pitch down
ft_cmd_slide_down:
jsr ft_get_pattern_byte ; Fetch speed / note
sta var_ch_EffParam, x
lda #EFF_SLIDE_DOWN_LOAD
sta var_ch_Effect, x
rts
; Effect: Volume slide
ft_cmd_vol_slide:
jsr ft_get_pattern_byte ; Fetch speed / note
sta var_ch_VolSlide, x
bne :+ ;;; ;; ;
lda var_ch_VolColumn, x
sta var_ch_VolDefault, x ; ;; ;;;
: rts
; Effect: Note cut (Sxx)
ft_cmd_note_cut:
jsr ft_get_pattern_byte
ora #$80
sta var_ch_NoteCut, x
lda ft_channel_type, x
cmp #CHAN_TRI ;;; ;; ;
bne :+
lda var_Linear_Counter
ora #$80
sta var_Linear_Counter
lda var_ch_LengthCounter + APU_TRI
and #%11111100
sta var_ch_LengthCounter + APU_TRI ; ;; ;;;
: rts
ft_cmd_linear_counter: ;;; ;; ;
jsr ft_get_pattern_byte
sta var_Linear_Counter
lda var_ch_LengthCounter + APU_TRI