-
Notifications
You must be signed in to change notification settings - Fork 15
/
bank_0E.asm
8148 lines (7234 loc) · 193 KB
/
bank_0E.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
ORG $0E8000
SPC700Engine:
dw SoundEffects-SPC700Engine-4
dw SPCEngine
arch spc700
base SPCEngine
APU_Start:
CLRP
MOV X,#$CF
MOV SP,X ; set SP to (01)cf;
MOV A,#$00
MOV.W ARam_0386,A
MOV.W ARam_0387,A
MOV.W ARam_0388,A
MOV.W ARam_0389,A ; zero 0386-9
MOV X,A
- MOV (X+),A
CMP X,#$E8
BNE - ; zero 00-e7;
if ver_is_japanese(!_VER) ;\======================== J ====================
MOV.W A,HotReset5A ;!
CMP A,#$5A ;!
BNE APU_0518 ;!
MOV.W A,HotResetA5 ;!
CMP A,#$A5 ;!
BEQ JAPU_0535 ;!
endif ;/===============================================
APU_0518:
MOV A,#$00
MOV X,A
- MOV.W ARam_0200+X,A
INC X
BNE - ; zero 0200-02ff;
- MOV.W ARam_0300+X,A
INC X
BNE - ; zero 0300-03ff;
if ver_is_japanese(!_VER) ;\======================== J ====================
JAPU_0535: ;!
MOV A,#$5A ;!
MOV.W HotReset5A,A ;!
MOV A,#$A5 ;!
MOV.W HotResetA5,A ;!
endif ;/===============================================
MOV X,#$0B
- MOV.W A,DefaultDSPRegs+X
MOV Y,A
MOV.W A,DefaultDSPVals+X
CALL WriteDSPReg ; write A to DSP reg Y;
DEC X
BPL - ; set initial DSP reg values;
MOV A,#$F0
MOV.W HW_SPCCONTROL,A ; reset ports, disable timers
MOV A,#$10
MOV.W HW_TIMER0,A ; set timer0 freq to 2ms
MOV A,#$36
MOV.B MasterTempo+1,A ; set $51 to #$36
MOV A,#$01
MOV.W HW_SPCCONTROL,A ; start timer 0
APU_Loop:
MOV.W Y,HW_COUNTER0 ; main loop
BEQ APU_Loop ; wait for counter 0 increment;
PUSH Y
MOV A,#$38
MUL YA
CLRC
ADC.B A,SPCTimer
MOV.B SPCTimer,A
BCC +
INC.B SPCTimer+1
CALL APU_06AE
MOV X,#$00
CALL CopyToSNES ; read/send APU0;
CALL APU_09E5
MOV X,#$01
CALL CopyToSNES ; read/send APU1;
CALL APU_0816
MOV X,#$03
CALL CopyToSNES ; read/send APU3;
+ MOV.B A,MasterTempo+1
POP Y
MUL YA
CLRC
ADC.B A,ARam_49
MOV.B ARam_49,A
BCC APU_058D
MOV.W A,ARam_0388
BNE +
CALL APU_0BC0
+ MOV X,#$02
CALL CopyToSNES ; read/send APU2;
BRA APU_Loop ; restart main loop;
APU_058D:
MOV.B A,SPCOutBuffer+2 ; if writing 0 to APU2 then
BEQ APU_Loop ; restart main loop;
MOV X,#$0E ; foreach voice;
MOV.B CurrentChannel,#$80
- MOV.B A,VoPhrasePtr+1+X
BEQ + ; skip call if vptr == 0;
CALL APU_1198 ; do per-voice fades/dsps?;
+ LSR.B CurrentChannel
DEC X
DEC X
BPL - ; loop for each voice;
BRA APU_Loop ; restart main loop;
CopyToSNES:
MOV A,X ; SEND 04+X TO APUX; get APUX to 00+X with "debounce"?;
MOV Y,A
MOV.B A,SPCOutBuffer+X
MOV.W HW_SNESIO0+X,A
- MOV.W A,HW_SNESIO0+X
CMP.W A,HW_SNESIO0+X
BNE -
MOV Y,A
MOV.B A,SPCInBuffer+X
MOV.B SPCInBuffer+X,Y
CBNE.B SPCInBuffer+X,+
MOV Y,#$00
MOV.B SPCInEdge+X,Y
RET ; return with old value in A;
+ MOV.B SPCInEdge+X,Y
MOV A,Y
RET ; return with new value in A;
HandleVCmd:
CMP A,#$D0 ; handle a note vcmd;
BCS + ; percussion note;
CMP A,#$C6
BCC APU_05E3 ; normal notenum OR $80;
- RET
+ MOV.B VoInstrument+1+X,A
SETC
SBC A,#$D0
MOV Y,#$06
MOV ARam_14,#$A5
MOV ARam_15,#$5F
CALL APU_0D56 ; set sample A-$D0 in bank $5FA5 width 6;
BNE - ; return if 1D vbit set;
INC Y
MOV.B A,(ARam_14)+Y ; get perc note num from instr tbl
APU_05E3:
AND A,#$7F
CLRC
ADC.B A,MasterTranspose ; add global transpose
MOV.W ARam_02B0+1+X,A
MOV.W A,ARam_02D0+1+X
MOV.W ARam_02B0+X,A
MOV A,#$00
MOV.W ARam_0330+X,A
MOV.W ARam_0360+X,A
MOV.B VoVibrato+X,A
MOV.W ARam_0110+X,A
MOV.B ARam_B0+X,A
OR.B (ARam_5C),(CurrentChannel) ; set volume changed flg
OR.B (ARam_47),(CurrentChannel) ; set key on shadow vbit
MOV.W A,ARam_0300+X
MOV.B VoPitchSlide+X,A
BEQ APU_062B
MOV.W A,ARam_0300+1+X
MOV.B VoPitchSlide+1+X,A
MOV.W A,ARam_0320+X
BNE +
MOV.W A,ARam_02B0+1+X
SETC
SBC.W A,ARam_0320+1+X
MOV.W ARam_02B0+1+X,A
+ MOV.W A,ARam_0320+1+X
CLRC
ADC.W A,ARam_02B0+1+X
CALL APU_0F5D
APU_062B:
MOV.W A,ARam_02B0+1+X
MOV Y,A
MOV.W A,ARam_02B0+X
MOVW.B ARam_10,YA
APU_0634:
MOV Y,#$00 ; set DSP pitch from $10/11;
MOV.B A,ARam_11
SETC
SBC A,#$34
BCS APU_0646
MOV.B A,ARam_11
SETC
SBC A,#$13
BCS APU_064A
DEC Y
ASL A
APU_0646:
ADDW.B YA,ARam_10
MOVW.B ARam_10,YA
APU_064A:
PUSH X
MOV.B A,ARam_11
CALL GetPitch
MOVW.B ARam_14,YA ; $14/5 = pitch for notenum $11
MOV.B A,ARam_11
INC A
CALL GetPitch ; get pitch for notenum $11 + 1;
POP X
SUBW.B YA,ARam_14
PUSH A
MOV.B A,ARam_10
MUL YA ; multiply pitch diff by fraction ($10);
ADDW.B YA,ARam_14
MOVW.B ARam_14,YA
MOV.B A,ARam_10
POP Y
MUL YA
MOV A,Y
MOV Y,#$00
ADDW.B YA,ARam_14
MOVW.B ARam_14,YA
MOV.W A,ARam_0210+X
MOV.B Y,ARam_14
MUL YA
MOVW.B PitchValue,YA
MOV.W A,ARam_0210+X
MOV.B Y,ARam_15
MUL YA
CLRC
ADC.B A,PitchValue+1
MOV.B PitchValue+1,A ; $16/7 = $14/15 * 0210+X
MOV A,X ; set voice X pitch DSP reg from 16/7;
XCN A ; (if vbit clear in 1D);
LSR A
OR A,#$02
MOV Y,A ; Y = voice X pitch DSP reg;
MOV.B A,PitchValue
CALL WriteDSPRegCond
INC Y
MOV.B A,PitchValue+1
WriteDSPRegCond:
PUSH A ; write A to DSP reg Y if vbit clear in $1D;
MOV.B A,CurrentChannel
AND.B A,ChannelsMuted
POP A
BNE +
WriteDSPReg:
MOV.W HW_DSPADDR,Y ; write A to DSP reg Y
MOV.W HW_DSPDATA,A
+ RET
APU_069E:
MOV A,#$0A
MOV.W ARam_0387,A
MOV.B A,MasterTempo+1
CALL APU_0E14 ; ADD #$0A TO TEMPO; zero tempo low;
MOV A,#$1D
MOV.B SPCInEdge+3,A
BRA APU_06D2
APU_06AE:
CMP.B SPCInEdge,#$12
BEQ APU_06C2
CMP.B SPCInEdge,#$11
BEQ APU_06C2
CMP.B SPCOutBuffer,#$11
BEQ APU_06C8
CMP.B SPCOutBuffer,#$1D
BEQ APU_06C8
APU_06C2:
MOV.B A,SPCInEdge
BMI APU_069E
BNE APU_06D2
APU_06C8:
MOV.W A,ARam_0382
BNE APU_071A
MOV.B A,SPCOutBuffer
BNE APU_074D
APU_06D1:
RET
APU_06D2:
MOV.B SPCOutBuffer,A
MOV.W A,ARam_0388
BEQ APU_06F7
MOV A,#$00
MOV.W ARam_0388,A
MOV.W A,ARam_0389
BNE +
MOV A,#$20
BRA APU_06F2 ; disable echo write;
+ MOV A,#$16
MOV.B EchoVolLeft+1,A
MOV.B EchoVolRight+1,A
CALL WriteDSPEchoVol ; set echo vol L/R to #$16;
MOV A,#$00
APU_06F2:
MOV Y,#DSP_FLG
CALL WriteDSPReg ; unmute sound, enable echo write;
APU_06F7:
MOV A,#$02
MOV.W ARam_0382,A
CMP.B SPCOutBuffer,#$11
BNE +
MOV.W A,ARam_0389
BEQ +
MOV A,#$00
CALL APU_0F22
+ MOV A,#$10
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 4;
SET4.B ChannelsMuted
MOV A,#$00
MOV.W ARam_0300+8,A
RET
APU_071A:
DEC.W ARam_0382 ; 0382 nonzero;
BNE APU_06D1 ; ret;
APU_071F:
MOV.B A,SPCOutBuffer
ASL A
MOV Y,A
MOV.W A,SFXPtrs1DF9-2+Y
MOV.B SFX1DF9PhrasePtr,A
MOV.W A,SFXPtrs1DF9-1+Y
MOV.B SFX1DF9PhrasePtr+1,A
BRA APU_0754
APU_072F:
CMP.B SPCOutBuffer,#$11
BNE +
MOV A,#$60
MOV.W ARam_0388,A
MOV Y,#DSP_FLG
CALL WriteDSPReg ; mute sound, disable echo write;
+ MOV SPCOutBuffer,#$00
CLR4.B ChannelsMuted
MOV X,#$08
MOV.B A,VoInstrument+9
BEQ +
JMP APU_0D4B
+ RET
APU_074D:
DEC.W ARam_0380
BNE APU_07A6
APU_0752:
INCW.B SFX1DF9PhrasePtr
APU_0754:
MOV X,#$00
MOV.B A,(SFX1DF9PhrasePtr+X)
BEQ APU_072F
BMI APU_0786
MOV.W ARam_0381,A
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
MOV.B ARam_10,A
BMI APU_0786
MOV Y,#DSP_VOLL+$40
CALL WriteDSPReg ; set voice 4 vol L;
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
BPL APU_077D
MOV X,A
MOV.B A,ARam_10
MOV Y,#DSP_VOLR+$40
CALL WriteDSPReg ; set voice 4 vol R (same as vol L);
MOV A,X
BRA APU_0786
APU_077D:
MOV Y,#DSP_VOLR+$40
CALL WriteDSPReg ; set voice 4 vol R (different from vol L);
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
APU_0786:
CMP A,#$DA
BEQ APU_07F3
CMP A,#$DD
BEQ APU_07C2
CMP A,#$EB
BEQ APU_07D5
CMP A,#$FF
BEQ APU_071F
MOV X,#$08
CALL HandleVCmd
MOV A,#$10
CALL APU_0D32 ; key on voice 4;
APU_07A0:
MOV.W A,ARam_0381
MOV.W ARam_0380,A
APU_07A6:
CLR7.B ARam_13
MOV X,#$08
MOV.B A,VoPitchSlide+X
BEQ APU_07B3
CALL PitchSlideDelta
BRA +
APU_07B3:
MOV A,#$02
CMP.W A,ARam_0380
BNE +
MOV A,#$10
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 4;
+ RET
APU_07C2:
MOV X,#$00
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
MOV.B CurrentChannel2,#$08
MOV X,#$08
CALL HandleVCmd
MOV A,#$10
CALL APU_0D32 ; key on voice 4;
APU_07D5:
MOV X,#$00
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
MOV.B VoPitchSlide+9,A
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
MOV.B VoPitchSlide+8,A
PUSH A
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
POP Y
MOV.B CurrentChannel2,#$08
MOV X,#$08
CALL APU_0F5D
BRA APU_07A0
APU_07F3:
MOV X,#$00
INCW.B SFX1DF9PhrasePtr
MOV.B A,(SFX1DF9PhrasePtr+X)
MOV Y,#$09 ; set DSP regs for voice 4 from 5570+(9*A);
MUL YA
MOV X,A
MOV Y,#DSP_VOLL+$40
MOV ARam_12,#$08
- MOV.W A,SFXDSPSettings+X
CALL WriteDSPReg
INC X
INC Y
DBNZ.B ARam_12,-
MOV.W A,SFXDSPSettings+X
MOV.W ARam_0210+8,A
JMP APU_0752
APU_0816:
CMP.B SPCOutBuffer+3,#$24
BEQ +
CMP.B SPCInEdge+3,#$24
BEQ ++
CMP.B SPCOutBuffer+3,#$1D
BEQ +
CMP.B SPCOutBuffer+3,#$05
BEQ +
++ MOV.B A,SPCInEdge+3
BNE APU_0837
+ MOV.B A,ARam_0C+1
BNE APU_084B
MOV.B A,SPCOutBuffer+3
BNE APU_0876
- RET
APU_0837:
MOV.B SPCOutBuffer+3,A
MOV.B ARam_0C+1,#$02
MOV A,#$40
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 6 now;
SET6.B ChannelsMuted ; don't set vol DSP for voice 6
MOV A,#$00
MOV.W ARam_0300+$0C,A
RET
APU_084B:
DBNZ.B ARam_0C+1,-
MOV.B A,SPCOutBuffer+3
ASL A
MOV Y,A
MOV.W A,SFXPtrs1DFC-2+Y
MOV.B SFX1DFCPhrasePtr,A
MOV.W A,SFXPtrs1DFC-1+Y
MOV.B SFX1DFCPhrasePtr+1,A
BRA APU_087D
APU_085E:
MOV.B SPCOutBuffer+3,#$00
CLR6.B ChannelsMuted ; OK to use voice 6 again
MOV A,#$00
MOV.B ARam_2F,A
MOV Y,#DSP_NON
CALL WriteDSPReg ; noise vbits off;
MOV X,#$0C
MOV.B A,VoInstrument+$0D
BEQ +
JMP APU_0D4B
+ RET
APU_0876:
DEC.W ARam_0384
BNE APU_08D3
APU_087B:
INCW.B SFX1DFCPhrasePtr
APU_087D:
MOV X,#$00
MOV.B A,(SFX1DFCPhrasePtr+X)
BEQ APU_085E
BMI APU_08AF
MOV.W ARam_0385,A
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
MOV.B ARam_10,A
BMI APU_08AF
MOV Y,#DSP_VOLL+$60
CALL WriteDSPReg ; set voice 6 vol L;
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
BPL +
MOV X,A
MOV.B A,ARam_10
MOV Y,#DSP_VOLR+$60
CALL WriteDSPReg ; set voice 6 vol R (same as vol L);
MOV A,X
BRA APU_08AF
+ MOV Y,#DSP_VOLR+$60
CALL WriteDSPReg ; set voice 6 vol R (different from vol R);
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
APU_08AF:
CMP A,#$DA
BEQ APU_0920
CMP A,#$DD
BEQ APU_08EF
CMP A,#$EB
BEQ APU_0902
CMP A,#$FF
BNE +
DECW.B SFX1DFCPhrasePtr
BRA APU_087D
+ MOV X,#$0C ; other $80+;
CALL HandleVCmd
MOV A,#$40
CALL APU_0D32 ; key on voice 6;
APU_08CD:
MOV.W A,ARam_0385
MOV.W ARam_0384,A
APU_08D3:
CLR7.B ARam_13
MOV X,#$0C
MOV.B A,VoPitchSlide+X ; pitch slide counter
BEQ APU_08E0
CALL PitchSlideDelta ; add pitch slide delta and set DSP pitch;
BRA +
APU_08E0:
MOV A,#$02
CMP.W A,ARam_0384
BNE +
MOV A,#$40
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 6 now;
+ RET
APU_08EF:
MOV X,#$00 ; DD;
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
MOV.B CurrentChannel2,#$0C
MOV X,#$0C
CALL HandleVCmd
MOV A,#$40
CALL APU_0D32 ; key on voice 6;
APU_0902:
MOV X,#$00 ; EB;
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
MOV.B VoPitchSlide+$0D,A
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
MOV.B VoPitchSlide+$0C,A
PUSH A
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
POP Y
MOV.B CurrentChannel2,#$0C
MOV X,#$0C
CALL APU_0F5D
BRA APU_08CD
APU_0920:
MOV A,#$00 ; DA;
MOV.B ARam_2F,A
MOV Y,#DSP_NON
CALL WriteDSPReg
APU_0929:
MOV X,#$00
INCW.B SFX1DFCPhrasePtr
MOV.B A,(SFX1DFCPhrasePtr+X)
BMI +
MOV Y,#$09 ; set DSP regs for voice 6 from 5570+(9*A);
MUL YA
MOV X,A
MOV Y,#DSP_VOLL+$60
MOV ARam_12,#$08
- MOV.W A,SFXDSPSettings+X
CALL WriteDSPReg
INC X
INC Y
DBNZ.B ARam_12,-
MOV.W A,SFXDSPSettings+X
MOV.W ARam_0210+$0C,A
JMP APU_087B
+ AND A,#$1F
MOV.B ARam_2E,A
MOV Y,#DSP_FLG
CALL WriteDSPReg ; set noise frequency;
MOV A,#$40
MOV.B ARam_2F,A
MOV Y,#DSP_NON
CALL WriteDSPReg ; enable noise on voice 6;
BRA APU_0929
SFXDSPRegs:
MOV Y,#$09 ; set DSP regs for voice 5 from 5570+(9*A);
MUL YA
MOV X,A
MOV Y,#DSP_VOLL+$50
MOV ARam_12,#$08
- MOV.W A,SFXDSPSettings+X
CALL WriteDSPReg
INC X
INC Y
DBNZ.B ARam_12,-
MOV.W A,SFXDSPSettings+X
MOV.W ARam_0210+$0A,A ; set voice 5 pitch mult from 5570+X;
RET
APU_097D:
MOV.B A,SPCOutBuffer+2 ; $01 = 02;
CMP A,#$06
BEQ +
AND A,#$FC
BNE APU_0A03
+ MOV.W A,ARam_0386
BNE APU_099A
MOV A,#$09
CALL SFXDSPRegs ; set voice 5 DSP from 5570+(9*9);
MOV A,#$01
BNE +
APU_0995:
MOV A,#$00 ; $01 = 03;
+ MOV.W ARam_0386,A
APU_099A:
BRA APU_0A03
APU_099C:
MOV A,#$60 ; $01 = FF (reset?);
MOV Y,#DSP_FLG
CALL WriteDSPReg ; mute all voices;
MOV A,#$FF
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off all voices now;
CALL StandardTransfer ; do standardish SPC transfer;
MOV A,#$00
MOV.B SPCOutBuffer,A
MOV.B SPCOutBuffer+1,A
MOV.B SPCOutBuffer+2,A
MOV.B SPCOutBuffer+3,A
MOV.B ChannelsMuted,A
MOV.W ARam_0387,A
MOV.W ARam_0388,A
MOV.W ARam_0386,A
MOV.W ARam_0389,A
MOV A,#$20
MOV Y,#DSP_FLG
CALL WriteDSPReg ; unmute voices;
RET
PitchSlideDelta:
MOV A,#$B0 ; add pitch slide delta and set DSP pitch;
MOV Y,#$02 ; pitch (notenum fixed-point);
DEC.B VoPitchSlide+X
CALL APU_1075 ; add pitch slide delta to value;
MOV.W A,ARam_02B0+1+X
MOV Y,A
MOV.W A,ARam_02B0+X
MOVW.B ARam_10,YA
MOV.B CurrentChannel,#$00 ; vbit flags = 0 (to force DSP set);
JMP APU_0634 ; force voice DSP pitch from 02B0/1;
APU_09E5:
MOV.B A,SPCInEdge+1
CMP A,#$FF
BEQ APU_099C
CMP A,#$02
BEQ APU_097D
CMP A,#$03
BEQ APU_0995
CMP A,#$01
BEQ APU_0A14
MOV.B A,SPCOutBuffer+1
CMP A,#$01
BEQ APU_0A03
MOV.B A,SPCInEdge+1
CMP A,#$04
BEQ APU_0A0E ; (jmp $0ace);
APU_0A03:
MOV.B A,SPCOutBuffer+1
CMP A,#$01
BEQ APU_0A51
CMP A,#$04
BEQ + ; (jmp $0b08);
APU_0A0D:
RET
APU_0A0E:
JMP APU_0ACE
+ JMP APU_0B08
APU_0A14:
MOV.B SPCOutBuffer+1,A ; $01 = 01
MOV A,#$04
MOV.W ARam_0383,A
MOV A,#$80
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 7;
SET7.B ChannelsMuted
MOV A,#$00
MOV Y,#$20
- MOV.W ARam_0300-1+Y,A
DBNZ Y,-
RET
APU_0A2E:
DEC.W ARam_0383
BNE APU_0A0D
MOV.B ARam_1C,#$30
BRA APU_0A68
- CMP.B ARam_1C,#$2A
BNE APU_0A99
MOV.B CurrentChannel2,#$0E
MOV X,#$0E
MOV Y,#$00
MOV.B VoPitchSlide+$0F,Y
MOV Y,#$12
MOV.B VoPitchSlide+$0E,Y
MOV A,#$B9
CALL APU_0F5D
BRA APU_0A99
APU_0A51:
MOV.W A,ARam_0383
BNE APU_0A2E
DBNZ.B ARam_1C,-
MOV.B SPCOutBuffer+1,#$00
CLR7.B ChannelsMuted
MOV X,#$0E
MOV.B A,VoInstrument+$0F
BEQ +
JMP APU_0D4B
+ RET
APU_0A68:
CALL APU_0AB1
MOV A,#$B2
MOV CurrentChannel2,#$0E
MOV X,#$0E
CALL HandleVCmd
MOV Y,#$00
MOV.B VoPitchSlide+$0F,Y
MOV Y,#$05
MOV.B VoPitchSlide+$0E,Y
MOV A,#$B5
CALL APU_0F5D
MOV A,#$38
MOV.B ARam_10,A
MOV Y,#DSP_VOLL+$70
CALL WriteDSPReg ; set voice 7 vol L to #$38;
MOV A,#$38
MOV.B ARam_10,A
MOV Y,#DSP_VOLR+$70
CALL WriteDSPReg ; set voice 7 vol R to #$38;
MOV A,#$80
CALL APU_0D32 ; key on voice 7;
APU_0A99:
MOV A,#$02
CBNE.B ARam_1C,+
MOV A,#$80
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 7;
+ CLR7.B ARam_13
MOV.B A,VoPitchSlide+$0E
BEQ +
MOV X,#$0E
CALL PitchSlideDelta
+ RET
APU_0AB1:
MOV A,#$08
APU_0AB3:
MOV Y,#$09 ; set DSP regs for voice 7 from 5570+(9*A);
MUL YA
MOV X,A
MOV Y,#DSP_VOLL+$70
MOV.B ARam_12,#$08
- MOV.W A,SFXDSPSettings+X
CALL WriteDSPReg
INC X
INC Y
DBNZ.B ARam_12,-
MOV.W A,SFXDSPSettings+X
MOV.W ARam_0210+$0E,A
RET
APU_0ACE:
MOV.B SPCOutBuffer+1,A ; $01 = 04 && $05 != 01
MOV A,#$04
MOV.W ARam_0383,A
MOV A,#$80
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 7 now;
SET7.B ChannelsMuted
MOV A,#$00
MOV Y,#$20
- MOV.W ARam_0300-1+Y,A
DBNZ Y,-
- RET
APU_0AE8:
DEC.W ARam_0383
BNE -
MOV.B ARam_1C,#$18
BRA +
APU_0AF2:
CMP.B ARam_1C,#$0C
BNE APU_0B33
+ MOV A,#$07
CALL APU_0AB3
MOV A,#$A4
MOV.B CurrentChannel2,#$0E
MOV X,#$0E
CALL HandleVCmd
BRA APU_0B1C
APU_0B08:
MOV.W A,ARam_0383
BNE APU_0AE8
DBNZ.B ARam_1C,APU_0AF2
MOV.B SPCOutBuffer+1,#$00
CLR7.B ChannelsMuted
MOV X,#$0E
MOV.B A,VoInstrument+$0F
JMP APU_0D4B
APU_0B1C:
MOV A,#$28
MOV.B ARam_10,A
MOV Y,#DSP_VOLL+$70
CALL WriteDSPReg ; set voice 7 vol L to #$28;
MOV A,#$28
MOV.B ARam_10,A
MOV Y,#DSP_VOLR+$70
CALL WriteDSPReg ; set voice 7 vol R to #$28;
MOV A,#$80
CALL APU_0D32 ; key on voice 7;
APU_0B33:
MOV A,#$02
CBNE.B ARam_1C,+
MOV A,#$80
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 7;
+ RET
APU_0B40:
SETC ; play song in A?;
CMP A,#$16
BEQ +
CMP A,#$10
BEQ +
CMP A,#$0F
BEQ +
CMP A,#$09
BCC ++
CMP A,#$0D
BCS ++
+ MOV Y,#$00
MOV.W ARam_0387,Y
++ MOV.B SPCOutBuffer+2,A
MOV.B ARam_0C,#$02
ASL A
MOV Y,A
MOV.W A,MusicData-2+Y
MOV.B BlockPtr,A
MOV.W A,MusicData-1+Y
MOV.B BlockPtr+1,A
MOV X,#$0E ; foreach voice;
- MOV A,#$0A
MOV.W ARam_0280+1+X,A ; pan
MOV A,#$FF
MOV.W ARam_0240+1+X,A ; voice base vol
MOV A,#$00
MOV.W ARam_02D0+1+X,A ; portamento off
MOV.B VoPanFade+1+X,A ; pan fade ctr
MOV.B VoPanFade+X,A ; vol fade ctr
MOV.B VoVibrato+1+X,A
MOV.B ARam_B0+1+X,A
MOV.B VoInstrument+X,A ; repeat ctr
MOV.B VoInstrument+1+X,A ; current instr
DEC X
DEC X
BPL -
MOV.B VolFadeTimer,A ; master vol fade ctr
MOV.B ARam_60,A ; echo vol fade ctr
MOV.B TempoSetTimer,A ; tempo fade ctr
MOV.B MasterTranspose,A ; global transpose
MOV.B MasterVolume,#$C0 ; master vol
MOV.B MasterTempo+1,#$36 ; tempo
MOV Y,#$20
- MOV.W ARam_0300-1+Y,A
DBNZ Y,- ; zero $0300-031f;
BRA +
APU_0BA3:
MOV.B SPCOutBuffer+2,A
+ MOV.B A,ChannelsMuted
EOR A,#$FF
MOV Y,#DSP_KOF
JMP WriteDSPReg ; key off all unmuted voices;
APU_0BAE:
MOV X,#$F0 ; fade volume out over 240 counts;
MOV.B VolFadeTimer,X
MOV A,#$00
MOV.B VolFadeVal,A
SETC
SBC.B A,MasterVolume
CALL APU_0F76
MOVW.B ARam_5A,YA ; set volume fade out after 240 counts
BRA APU_0BE7
APU_0BC0:
MOV.B A,SPCOutBuffer+2
BEQ APU_0BDE
CMP A,#$06
BEQ ++
AND A,#$FC
BNE +
++ MOV.W A,ARam_0386
BNE +
MOV A,#$20
MOV Y,#DSP_KOF
CALL WriteDSPReg ; key off voice 5;
SET5.B ChannelsMuted
BRA APU_0BDE
+ CLR5.B ChannelsMuted
APU_0BDE:
MOV.B A,SPCInEdge+2
BMI APU_0BAE
BEQ APU_0BE7
JMP APU_0B40 ; play song in A?;
APU_0BE7:
MOV.B A,ARam_0C
BNE APU_0BFE
MOV.B A,SPCOutBuffer+2
BNE APU_0C46
- RET
APU_0BF0:
MOV Y,#$00 ; read next word at $40 into YA;
MOV.B A,(BlockPtr)+Y
INCW.B BlockPtr
PUSH A
MOV.B A,(BlockPtr)+Y
INCW.B BlockPtr
MOV Y,A
POP A
RET
APU_0BFE:
DBNZ.B ARam_0C,-
APU_0C01:
CALL APU_0BF0 ; read next word at $40;
MOVW.B PitchValue,YA ; save in $16/17
MOV A,Y ; high byte zero?;
BNE APU_0C22
MOV.B A,PitchValue ; refetch lo byte
BEQ APU_0BA3 ; key off, return if also zero;
DEC.B MusicLoopCounter
BEQ APU_0C1C
BPL +
MOV.B MusicLoopCounter,A
+ CALL APU_0BF0 ; read next word at $40;
MOVW.B BlockPtr,YA ; "goto" that address
BRA APU_0C01 ; and continue;