-
Notifications
You must be signed in to change notification settings - Fork 1
/
engine.asm
1759 lines (1566 loc) · 32.5 KB
/
engine.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
.include "engineMacros.asm"
.include "adsr.asm"
.export pulsarRefresh, initPulsar
initPhase = 5 ;set "envelopePhase" to this value to start it
attackPhase = 4
decayPhase = 3
sustainPhase = 2
releasePhase = 1
offPhase = 0 ;envelope stops at this stage
VOICE_A = 0
VOICE_B = 1
VOICE_C = 2
VOICE_D = 3
VOICE_E = 4
initPulsar:
jsr pulsarInitAPU
rts
pulsarRefresh:
jsr pulsarRefreshVoiceA
jsr pulsarRefreshVoiceB
jsr pulsarRefreshVoiceC
jsr pulsarRefreshVoiceD
jsr pulsarRefreshVoiceE
.IF SRAM_MAP=32
.IF ENABLE_ECHO=1
jsr pulsarEchoEffectA
jsr pulsarEchoEffectB
jsr pulsarEchoEffectD
.ENDIF
.ENDIF
jsr pulsarRunFxTable
jsr pulsarWriteApuA
jsr pulsarWriteApuB
jsr pulsarWriteApuC
jsr pulsarWriteApuD
jsr pulsarWriteApuE
@x: inc pulsarPassCounter
rts
pulsarRunFxTable:
.IF SRAM_MAP=32
lda #SRAM_HEADER_BANK
jsr setMMC1r1
.ENDIF
ldy editorCurrentSong
lda SRAM_SONG_MUTE,y
sta engineTmp0
lda SRAM_SONG_SOLO,y
sta engineTmp1
.IF SRAM_MAP=32
lda #SRAM_FX_BANK
jsr setMMC1r1
.ENDIF
ldx plyrFxTable
cpx #$FF
bne @go
@x1: rts
@go:
ldy plyrFxTableIndex
cpy #$10
bcc @a
lda #$FF
sta plyrFxTable
sta plyrFxTableVoice
bmi @x1
@a: lda fxRowsIndex,y
tay
lda editFxAddressLo,x
sta plyrFxVector
lda editFxAddressHi,x
sta plyrFxVector+1
lda engineTmp0 ;*SRAM*
and #$01
bne @noNoteA
lda engineTmp1 ;*SRAM*
bmi @soloA
cmp #$00
bne @noNoteA
@soloA: lda (plyrFxVector),y ;*SRAM* note A
bmi @noNoteA
jsr pulsarFxTableGetNote
sta V_APU+$02
stx V_APU+$03
iny
lda (plyrFxVector),y ;*SRAM* volume A
iny
ora (plyrFxVector),y ;*SRAM* duty A
ora #$30
sta V_APU+$00
jmp @doB
@noNoteA: iny
iny
@doB: iny
lda engineTmp0 ;*SRAM*
and #$02
bne @noNoteB
lda engineTmp1 ;*SRAM*
bmi @soloB
cmp #$01
bne @noNoteB
@soloB: lda (plyrFxVector),y ;*SRAM* note B
bmi @noNoteB
jsr pulsarFxTableGetNote
sta V_APU+$06
stx V_APU+$07
iny
lda (plyrFxVector),y ;*SRAM* volume B
iny
ora (plyrFxVector),y ;*SRAM* duty B
ora #$30
sta V_APU+$04
jmp @doC
@noNoteB: iny
iny
@doC: iny
lda engineTmp0 ;*SRAM*
and #$04
bne @noNoteC
lda engineTmp1 ;*SRAM*
bmi @soloC
cmp #$02
bne @noNoteC
@soloC: lda (plyrFxVector),y ;*SRAM* note c
bmi @noNoteC
jsr pulsarFxTableGetNote
sta V_APU+$0A
stx V_APU+$0B
lda #$81
sta V_APU+$08
@noNoteC: iny
lda engineTmp0 ;*SRAM*
and #$08
bne @noNoteD
lda engineTmp1 ;*SRAM*
bmi @soloD
cmp #$03
bne @noNoteD
@soloD: lda (plyrFxVector),y ;*SRAM* note D
bmi @noNoteD
cmp #$10
bcc @notToneNoise
and #$0F
ora #$80
@notToneNoise:
sta V_APU+$0E
iny
lda (plyrFxVector),y ;*SRAM* amp D
ora #$30
sta V_APU+$0C
@noNoteD:
lda plyrFxTableCounter
clc
adc plyrFxTableSpeed
sta plyrFxTableCounter
bcc @x
inc plyrFxTableIndex
@x: rts
pulsarFxTableGetNote:
tax
lda fxNoteTableLo,x
pha
lda fxNoteTableHi,x
tax
pla
rts
fxNoteTableLo:
.byte $f1,$7f,$13,$ad,$4d,$f3,$9d,$4c,$00,$b8,$74,$34
.byte $f8,$bf,$89,$56,$26,$f9,$ce,$a6,$80,$5c,$3a,$1a
.byte $fb,$df,$c4,$ab,$93,$7c,$67,$52,$3f,$2d,$1c,$0c
.byte $fd,$ef,$e1,$d5,$c9,$bd,$b3,$a9,$9f,$96,$8e,$86
.byte $7e,$77,$70,$6a,$64,$5e,$59,$54,$4f,$4b,$46,$42
.byte $3f,$3b,$38,$34,$31,$2f,$2c,$29,$27,$25,$23,$21
.byte $1f,$1d,$1b,$1a,$18,$17,$15,$14
.byte $13,$12,$11,$10,$0f,$0e,$0d
fxNoteTableHi:
.byte $07,$07,$07,$06,$06,$05,$05,$05,$05,$04,$04,$04
.byte $03,$03,$03,$03,$03,$02,$02,$02,$02,$02,$02,$02
.byte $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00
pulsarRefreshVoiceA:
lda pulsarIntensity+$00
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @yesRefresh
rts
@yesRefresh:
refreshVoice VOICE_A
rts
pulsarRefreshVoiceB:
lda pulsarIntensity+$01
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @yesRefresh
rts
@yesRefresh:
refreshVoice VOICE_B
rts
pulsarRefreshVoiceC:
lda pulsarIntensity+$02
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @yesRefresh
rts
@yesRefresh:
refreshVoice VOICE_C
rts
pulsarRefreshVoiceD:
lda pulsarIntensity+$03
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @yesRefresh
rts
@yesRefresh:
refreshVoice VOICE_D
rts
pulsarRefreshVoiceE:
lda pulsarIntensity+$04
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @yesRefresh
rts
@yesRefresh:
refreshVoice VOICE_E
rts
.IF SRAM_MAP=32
.IF ENABLE_ECHO=1
pulsarEchoEffectA:
echoEffect VOICE_A
pulsarEchoEffectB:
echoEffect VOICE_B
pulsarEchoEffectD:
echoEffect VOICE_D
pulsarUpdateEchoA:
plyrUpdateEchoIndex VOICE_A
pulsarUpdateEchoB:
plyrUpdateEchoIndex VOICE_B
pulsarUpdateEchoD:
plyrUpdateEchoIndex VOICE_D
.ENDIF
.ENDIF
pulsarPassCounterMasks:
.BYTE %00000001,%00000010,%00000100,%00001000
pulsarWriteApuA:
jmp @jump
@echoNormal:
lda V_APU+3
lsr a
lsr a
lsr a
lsr a
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @hard
jmp @normal
@hard: lda V_APU+3
and #$07
sta APU_03
sta pitchHiOld
lda V_APU+2
sta APU_02
sta pitchLoOld
rts
@jump: lda V_APU+0
sta APU_00
lda V_APU+1
sta APU_01
lda plyrInstrumentCopy+(0*STEPS_PER_INSTRUMENT)+INSTRUMENT_ROW_HARDFREQ
beq @notHard
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @hard
@notHard:
lda plyrInstrumentCopy + (0 * STEPS_PER_INSTRUMENT) + INSTRUMENT_ROW_TABLE
bpl @normal
lda plyrCurrentNote
bmi @normal
lda plyrNoteCounter
beq @normal
lda plyrFxTable
bpl @normal
.IF SRAM_MAP=32
.IF ENABLE_ECHO=1
lda plyrEchoSpeed
beq @noEcho
lda envelopePhase
cmp #ENVELOPE_SUSTAIN_PHASE
bcs @noEcho
jmp @echoNormal
.ENDIF
.ENDIF
@noEcho: lda V_APU+3
and #$07
sec
sbc pitchHiOld
beq @noHi
bmi @down
cmp #$02
bcs @normal
lda V_APU+3
and #$07
sta pitchHiOld
lda #$40
sta APU_17
lda #$FF
sta APU_02
lda #$87
sta APU_01
lda #$C0
sta APU_17
lda #$0F
sta APU_01
jmp @noHi
@down: cmp #$FD
bcc @normal
lda V_APU+3
and #$07
sta pitchHiOld
lda #$40
sta APU_17
lda #$00
sta APU_02
lda #$8F
sta APU_01
lda #$C0
sta APU_17
lda #$0F
sta APU_01
jmp @noHi
@normal: lda V_APU+3
and #$07
cmp pitchHiOld
beq @noHi
sta pitchHiOld
sta APU_03
@noHi: lda V_APU+2
cmp pitchLoOld
beq @noLo
sta pitchLoOld
sta APU_02
@noLo: rts
.IF 1=1
pulsarWriteApuB:
jmp @jump
@echoNormal:
lda V_APU+7
lsr a
lsr a
lsr a
lsr a
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @hard
jmp @normal
@hard: lda V_APU+7
and #$07
sta APU_07
sta pitchHiOld+1
lda V_APU+6
sta APU_06
sta pitchLoOld+1
rts
@jump: lda V_APU+4
sta APU_04
lda V_APU+5
sta APU_05
lda plyrInstrumentCopy + (1*STEPS_PER_INSTRUMENT) + INSTRUMENT_ROW_HARDFREQ
beq @notHard
ldx pulsarPassCounter
and pulsarPassCounterMasks,x
bne @hard
@notHard:
lda plyrInstrumentCopy + (1 * STEPS_PER_INSTRUMENT) + INSTRUMENT_ROW_TABLE
bpl @normal
lda plyrCurrentNote+1
bmi @normal
lda plyrNoteCounter+1
beq @normal
lda plyrFxTable
bpl @normal
.IF SRAM_MAP=32
.IF ENABLE_ECHO=1
lda plyrEchoSpeed+1
beq @noEcho
lda envelopePhase+1
cmp #ENVELOPE_SUSTAIN_PHASE
bcs @noEcho
jmp @echoNormal
.ENDIF
.ENDIF
@noEcho: lda V_APU+7
and #$07
sec
sbc pitchHiOld+1
beq @noHi
bmi @down
cmp #$02
bcs @normal
lda V_APU+7
and #$07
sta pitchHiOld+1
lda #$40
sta APU_17
lda #$FF
sta APU_06
lda #$87
sta APU_05
lda #$C0
sta APU_17
lda #$0F
sta APU_05
jmp @noHi
@down: cmp #$FD
bcc @normal
lda V_APU+7
and #$07
sta pitchHiOld+1
lda #$40
sta APU_17
lda #$00
sta APU_06
lda #$8F
sta APU_05
lda #$C0
sta APU_17
lda #$0F
sta APU_05
jmp @noHi
@normal: lda V_APU+7
and #$07
cmp pitchHiOld+1
beq @noHi
sta pitchHiOld+1
sta APU_07
@noHi: lda V_APU+6
cmp pitchLoOld+1
beq @noLo
sta pitchLoOld+1
sta APU_06
@noLo: rts
.ENDIF
pulsarWriteApuC:
lda V_APU+8
sta APU_08
lda V_APU+9
sta APU_09
lda plyrNoteCounter+$02
beq @down
lda plyrFxTable
bpl @down
lda V_APU+$0B
sec
sbc old_V_APUB
beq @a
bmi @down
lda V_APU+$0B
sta $400B
sta old_V_APUB
@a: lda V_APU+$0A
sta $400a
rts
@down: lda V_APU+$0A
sta $400a
lda V_APU+$0B
sta $400b
sta old_V_APUB
rts
pulsarWriteApuD:
lda V_APU+$0C
sta APU_0C
lda V_APU+$0D
sta APU_0D
lda V_APU+$0E
sta APU_0E
lda V_APU+$0F
sta APU_0F
rts
pulsarWriteApuE:
lda plyrDpcmMuted
beq @a
lda #$0F
sta APU_15
rts
@a:
lda plyrDpcmOn
beq @x
lda dpcmPitch
sta APU_10
lda dpcmDC
sta APU_11
lda dpcmStart
sta APU_12
lda dpcmLength
sta APU_13
lda APU_15
and #$0F
ora plyrDpcmOn
sta APU_15
lda #$00
sta plyrDpcmOn
@x:
rts
pulsarInitAPU:
lda #$00
sta APU_15
ldx #$00
lda #$00
@a: sta APU,x
sta V_APU,x
inx
cpx #$10
bcc @a
sta plyrSlideSpeed
sta plyrSlideSpeed+1
sta plyrSlideSpeed+2
sta plyrCurrentSpeedTable
sta plyrSpeedTableIndex
sta plyrCurrentChainTranspose
sta plyrCurrentChainTranspose+1
sta plyrCurrentChainTranspose+2
sta plyrCurrentChainTranspose+3
sta plyrCurrentChainTranspose+4
sta plyrCurrentDuty
sta plyrCurrentDuty+1
sta plyrDutyTableDelay
sta plyrDutyTableDelay+1
sta plyrDutyIndex
sta plyrDutyIndex+1
sta plyrTableIndex
sta plyrTableIndex+1
sta plyrTableIndex+2
sta plyrTableIndex+3
sta plyrTablePitch
sta plyrTablePitch+1
sta plyrTablePitch+2
sta plyrTablePitch+3
sta plyrCurrentInstrument
sta plyrCurrentInstrument+1
sta plyrCurrentInstrument+2
sta plyrCurrentInstrument+3
sta plyrCurrentInstrument+4
sta plyrDelayNoteCounter
sta plyrDelayNoteCounter+1
sta plyrDelayNoteCounter+2
sta plyrDelayNoteCounter+3
sta plyrDelayNoteCounter+4
sta plyrKeyOn
sta plyrKeyOn+$01
sta plyrKeyOn+$02
sta plyrKeyOn+$03
sta plyrKeyOn+$04
sta plyrDpcmOn
sta noteNumber
sta noteNumber+1
sta noteNumber+2
sta noteNumber+3
sta noteAddNote
sta noteAddNote+1
sta noteAddNote+2
sta noteAddFrac
sta noteAddFrac+1
sta noteAddFrac+2
sta envelopeAmp
sta envelopeAmp+1
sta envelopeAmp+2
sta envelopeAmp+3
sta envelopePhase
sta envelopePhase+1
sta envelopePhase+2
sta envelopePhase+3
sta plyrChordNotes
sta plyrChordNotes+1
sta plyrChordNotes+2
sta plyrChordNotes+3
sta plyrDetuneHi
sta plyrDetuneHi+1
sta plyrDetuneHi+2
lda #$0F
sta plyrTableVolume
sta plyrTableVolume+1
sta plyrTableVolume+2
sta plyrTableVolume+3
sta pulsarIntensity
sta pulsarIntensity+1
sta pulsarIntensity+2
sta pulsarIntensity+3
sta pulsarIntensity+4
lda #$FF
sta pitchHiOld
sta pitchHiOld+1
sta plyrDelayNote
sta plyrDelayNote+1
sta plyrDelayNote+2
sta plyrDelayNote+3
sta plyrDelayNote+4
sta plyrNoteCounter
sta plyrNoteCounter+1
sta plyrNoteCounter+2
sta plyrNoteCounter+3
sta plyrNoteCounter+4
sta plyrKillCounter
sta plyrKillCounter+1
sta plyrKillCounter+2
sta plyrKillCounter+3
sta plyrKillCounter+4
sta plyrRetriggerSpeed
sta plyrRetriggerSpeed+1
sta plyrRetriggerSpeed+2
sta plyrRetriggerSpeed+3
sta plyrRetriggerSpeed+4
sta plyrRetriggerCounter
sta plyrRetriggerCounter+1
sta plyrRetriggerCounter+2
sta plyrRetriggerCounter+3
sta plyrRetriggerCounter+4
sta plyrTableJump
sta plyrTableJump+1
sta plyrTableJump+2
sta plyrTableJump+3
sta plyrTableJump+4
sta plyrPatternJump
sta plyrPatternJump+1
sta plyrPatternJump+2
sta plyrPatternJump+3
sta plyrPatternJump+4
sta plyrFxTable
lda #$00
sta dpcmPitch
sta dpcmStart
sta dpcmLength
lda #$40
sta dpcmDC
lda #$08
sta APU_01
sta V_APU+$01
sta APU_05
sta V_APU+$05
lda #%00001111
sta APU_15
ldx #$04
ldy #$00
@clearIns:
lda #$00
sta plyrInstrumentCopy,y ;envelope
iny
lda #$0F
sta plyrInstrumentCopy,y ;level
iny
lda #$00
sta plyrInstrumentCopy,y ;gate
iny
sta plyrInstrumentCopy,y ;duty
iny
lda #$FF
sta plyrInstrumentCopy,y ;table
iny
lda #$00
sta plyrInstrumentCopy,y ;sweep
iny
lda #$80
sta plyrInstrumentCopy,y ;sweep q
iny
lda #$FF
sta plyrInstrumentCopy,y ;vib
iny
lda #$00
sta plyrInstrumentCopy,y ;detune
iny
sta plyrInstrumentCopy,y ;hard frq
iny
lda #$FF
sta plyrInstrumentCopy,y ;echo
iny
;lda #$00
;sta plyrInstrumentCopy,y ;aux
;iny
dex
bne @clearIns
.IF SRAM_MAP=32
.IF ENABLE_ECHO=1
lda #$00
sta plyrEchoSpeed
sta plyrEchoSpeed+1
sta plyrEchoSpeed+2
sta plyrEchoSpeed+3
lda #$00
sta plyrEchoIndex
sta plyrEchoIndex+1
sta plyrEchoIndex+2
sta plyrEchoIndex+3
lda #$00
sta plyrEchoCounter
sta plyrEchoCounter+1
sta plyrEchoCounter+2
sta plyrEchoCounter+3
lda #SRAM_ECHO_BANK
jsr setMMC1r1
ldx #$00
lda #$FF
@b: sta plyrEchoBuffer03_A,x
sta plyrEchoBuffer02_A,x
sta plyrEchoBuffer00_A,x
sta plyrEchoBuffer03_B,x
sta plyrEchoBuffer02_B,x
sta plyrEchoBuffer00_B,x
sta plyrEchoBuffer02_D,x
sta plyrEchoBuffer00_D,x
inx
cpx #SIZE_OF_ECHO_BUFFER
bcc @b
.ENDIF
.ENDIF
rts
envelopePhaseIndexes:
.BYTE 0,3,2,1,0,0
DUTY_TABLE:
.BYTE $00,$40,$80,$C0
LOCK_UP: ldx #$00
@a: stx $2007
inx
jmp @a
;-------------------------------------------------------------------------------
; FX Handling Code
;-------------------------------------------------------------------------------
;
;IN : A = command data, Y = command number, X = voice
;
plyrDoCommand:
@a: sta engineTmp0
cpx #$02
bcs @b
lda commandFlagAB,y
bne @ok
rts
@b: cpx #$03
bcs @c
lda commandFlagC,y
bne @ok
rts
@c: bne @d
lda commandFlagD,y
bne @ok
rts
@d: lda commandFlagE,y
beq @x
@ok: lda commandAddressHi,y
pha
lda commandAddressLo,y
pha
lda engineTmp0
@x: rts
commandAddressHi:
.HIBYTES commandA-1,commandB-1,commandC-1,commandD-1,commandE-1
.HIBYTES commandF-1,commandG-1,commandH-1,commandI-1,commandJ-1
.HIBYTES commandK-1,commandL-1,commandM-1,commandN-1,commandO-1
.HIBYTES commandP-1,commandQ-1,commandR-1,commandS-1,commandT-1
.HIBYTES commandU-1,commandV-1,commandW-1,commandX-1,commandY-1
.HIBYTES commandZ-1
commandAddressLo:
.LOBYTES commandA-1,commandB-1,commandC-1,commandD-1,commandE-1
.LOBYTES commandF-1,commandG-1,commandH-1,commandI-1,commandJ-1
.LOBYTES commandK-1,commandL-1,commandM-1,commandN-1,commandO-1
.LOBYTES commandP-1,commandQ-1,commandR-1,commandS-1,commandT-1
.LOBYTES commandU-1,commandV-1,commandW-1,commandX-1,commandY-1
.LOBYTES commandZ-1
;
;Run Table
;
commandA:
cpx #$04
bcc @notE
and #NUMBER_OF_TABLES-1
sta plyrTableTrackE
lda #$00
sta plyrTableIndex,x
sta plyrTableCounter,x
rts
@notE:
and #NUMBER_OF_TABLES-1
pha
lda commandInstrumentAddressLo,x
sta engineTmp0
lda commandInstrumentAddressHi,x
sta engineTmp1
ldy #INSTRUMENT_ROW_TABLE
pla
sta (engineTmp0),y
lda #$00
sta plyrTableIndex,x
sta plyrTableCounter,x
rts
;
;Vibrato or, for DPCM, set loop on/off
;
commandB:
cpx #$04
bcc @notE
pha
.IF SRAM_MAP=32
lda #SRAM_DRUMKIT_BANK
jsr setMMC1r1
.ENDIF
ldy plyrCurrentInstrument=$04
lda SRAM_DRUMKIT_ROOTS,y ;*SRAM*
sta engineTmp0
lda plyrCurrentNote,x
cmp engineTmp0
bcc @noDrum
sbc engineTmp0
cmp #$0C
bcs @noDrum
tay
lda drumkitRowsIndex,y
tay
iny
iny
iny
iny
pla
and #$01
sta plyrInstrumentCopyE,y
rts
@noDrum: pla
rts
@notE: cpx #$03
bcs @x
cmp #$FF
beq @a
cmp #NUMBER_OF_VIBRATOS
bcs @x
@a: pha
lda commandInstrumentAddressLo,x
sta engineTmp0
lda commandInstrumentAddressHi,x
sta engineTmp1
ldy #INSTRUMENT_ROW_VIBRATO
pla
sta (engineTmp0),y
@x: rts
;
;Pattern Chord
;
commandC:
sta plyrChordNotes,x
lda #$00
sta plyrPatternChordIndex,x
sta plyrPatternChordCounter,x
rts
;
;Delay Note Start
commandD:
clc
adc #$01
sta plyrDelayNoteCounter,x
lda plyrCurrentNote,x
sta plyrDelayNote,x
rts
;
; Set envelope or for DPCM, set end offset for current note
;
commandE: cpx #$04
bcc @notE
pha
ldy plyrCurrentInstrument+$04
.IF SRAM_MAP=32
lda #SRAM_DRUMKIT_BANK
jsr setMMC1r1
.ENDIF
lda SRAM_DRUMKIT_ROOTS,y ;*SRAM*
sta engineTmp0
lda plyrCurrentNote,x
cmp engineTmp0
bcc @noDrum
sbc engineTmp0
cmp #$0C