-
Notifications
You must be signed in to change notification settings - Fork 3
/
OPL2_Library.asm
1443 lines (1387 loc) · 43.9 KB
/
OPL2_Library.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
.cpu "65816"
.include "OPL3_def.asm"
.include "OPL2_Instruments.asm"
.include "OPL2_Midi_Drums.asm"
.include "OPL2_Midi_Instruments.asm"
.include "OPL2_Midi_Instruments_Win31.asm"
;In some assemblers, BGE (Branch if Greater than or Equal) and BLT (Branch if Less Than) are synonyms for BCS and BCC, respectively.
; BCS ( A > = DATA )
; BCC ( A < DATA )
; BMI ( < ) (Signed)
; BPL ( > )
; BEQ ( A == DATA )
; BNE ( A < > DATA )
NOTE_INTRO .byte $3C, $42, $44, $45, $47, $49, $4B, $4C
IOPL2_TONE_TEST
setas
setxl
LDX #0
OPL2_TONE_TESTING_L1
LDA NOTE_INTRO, X
AND #$F
STA OPL2_NOTE ; start at C
LDA NOTE_INTRO, X
AND #$70
LSR A
LSR A
LSR A
LSR A
STA OPL2_OCTAVE
TXA
AND #$03 ; replace modulo 3 - play each note on a different channel
STA OPL2_CHANNEL
JSL OPL2_PLAYNOTE
LDY #$0000
; Delay around 30ms
OPL2_TONE_TESTING_L2
NOP
NOP
NOP
NOP
INY
CPY #$FFFF
BNE OPL2_TONE_TESTING_L2
;
; DELAY of 300ms Here
;
INX
CPX #8
BNE OPL2_TONE_TESTING_L1
RTL
OPL3_INIT
.as
setal
; Just Making sure all the necessary variables are cleared before doing anything
LDA #$0000
STA OPL2_REG_REGION
STA OPL2_REG_OFFSET
STA OPL2_NOTE
STA OPL2_PARAMETER0
STA OPL2_PARAMETER2
; instrument library address
LDA #<>INSTRUMENT_ACCORDN
STA RAD_ADDR
LDA #<`INSTRUMENT_ACCORDN
STA RAD_ADDR + 2
setas
;LDA $2F
;STA OPL3_R_CONN_SEL
LDA #1
STA OPL3_R_OPL3_MODE
RTL
OPL2_Reset
RTL
OPL2_Get_FrequencyBlock
RTL
;OPL2_GET_REGISTER
;OPL2_PARAMETER0 = Register ;
; Return
;A = Value ;
OPL2_GET_REGISTER ;Return Byte, Param: (byte reg, byte value);
setal
CLC
LDA #<>OPL3_R_BASE
ADC OPL2_PARAMETER0
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
RTL
OPL2_GET_WAVEFORM_SELECT ; Return Bool
setal
LDA #<>OPL3_R_BASE
ADC #$0001
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$20
RTL
OPL2_GET_SCALINGLEVEL ; Return Byte, Param: (byte channel, byte operatorNum);
setal
LDA #$0040 ;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$C0
LSR A
LSR A
LSR A
LSR A
LSR A
LSR A
RTL
;OPL2_GET_BLOCK
OPL2_GET_BLOCK ; Return Byte, Param: (byte channel);
setas
CLC
LDA OPL2_CHANNEL
AND #$0F ; This is just precaution, it should be between 0 to 8
ADC #$B0
STA OPL2_REG_OFFSET
LDA #$00
STA OPL2_REG_OFFSET+1;
setaxl
;Address Creation in $AFE700 Memory Section
CLC
LDA #<>OPL3_R_BASE
ADC OPL2_REG_OFFSET
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$1C
LSR A
LSR A
RTL
OPL2_GET_KEYON ; Return Bool, Param: (byte channel);
setas
CLC
LDA OPL2_CHANNEL
AND #$0F ; This is just precaution, it should be between 0 to 8
ADC #$B0
STA OPL2_REG_OFFSET
LDA #$00
STA OPL2_REG_OFFSET+1;
setaxl
;Address Creation in $AFE700 Memory Section
CLC
LDA #<>OPL3_R_BASE
ADC OPL2_REG_OFFSET
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$20
RTL
OPL2_GET_FEEDBACK ; Return Byte, Param: (byte channel);
setas
CLC
LDA OPL2_CHANNEL
AND #$0F ; This is just precaution, it should be between 0 to 8
ADC #$C0
STA OPL2_REG_OFFSET
LDA #$00
STA OPL2_REG_OFFSET+1;
setaxl
;Address Creation in $AFE700 Memory Section
CLC
LDA #<>OPL3_R_BASE
ADC OPL2_REG_OFFSET
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$E0
LSR
RTL
OPL2_GET_SYNTHMODE ; Return Bool, Param: (byte channel);
setas
CLC
LDA OPL2_CHANNEL
AND #$0F ; This is just precaution, it should be between 0 to 8
ADC #$C0
STA OPL2_REG_OFFSET
LDA #$00
STA OPL2_REG_OFFSET+1;
setaxl
;Address Creation in $AFE700 Memory Section
CLC
LDA #<>OPL3_R_BASE
ADC OPL2_REG_OFFSET
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$01
RTL
OPL2_GET_DEEPTREMOLO ; Return Bool, Param: (none);
setal
LDA #$00BD;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$80
RTL
OPL2_GET_DEEPVIBRATO ; Return Bool, Param: (none);
setal
LDA #<>OPL3_R_BASE
ADC #$00BD
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$40
RTL
OPL2_GET_PERCUSSION ; Return Bool, Param: (none);
setal
LDA #<>OPL3_R_BASE
ADC #$00BD
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$20
RTL
OPL2_GET_DRUMS ; Return Byte, Param: (none);
setal
LDA #<>OPL3_R_BASE
ADC #$00BD
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA [OPL2_IND_ADDY_LL]
AND #$1F
RTL
OPL2_Get_WaveForm ; Return Byte, Param: (byte channel, byte operatorNum);
RTL
;
;OPL2_PLAYNOTE
; Inputs
; OPL2_CHANNEL @ $000027 ;
; OPL2_NOTE @ $000030 ; Notes start at 1 to 12
; OPL2_OCTAVE @ $000031 ;
; OPL2_PARAMETER0 Will Change
OPL2_PLAYNOTE ;Return void, Param: (byte channel, byte octave, byte note);
setas
PHX
LDA #$00
STA OPL2_PARAMETER0 ; Set Keyon False
JSR OPL2_SET_KEYON
; Set Octave
JSR OPL2_SET_BLOCK ; OPL2_SET_BLOCK Already to OPL2_OCTAVE
; Now lets go pick the FNumber for the note we want
setxs
LDA OPL2_NOTE
DEC A
ASL A
TAX
LDA @lnoteFNumbers,X
STA OPL2_PARAMETER0 ; Store the 8it in Param OPL2_PARAMETER0
INX
LDA @lnoteFNumbers,X
STA OPL2_PARAMETER1 ; Store the 8bit in Param OPL2_PARAMETER1
JSL OPL2_SET_FNUMBER
LDA #$01
STA OPL2_PARAMETER0 ; Set Keyon False
JSR OPL2_SET_KEYON
setxl
PLX
RTL
; **************************************************************
; * Not used
; **************************************************************
OPL2_PLAYDRUM ;Return void, Param: (byte drum, byte octave, byte note);
RTL
;
;
;OPL2_SET_INSTRUMENT
; Inputs
; OPL2_CHANNEL @ $000027 ; Channel
; OPL2_ADDY_PTR_LO @ $00:0008 ; Pointer to Instrument
; OPL2_ADDY_PTR_MD @ $00:0009 ;
; OPL2_ADDY_PTR_HI @ $00:000A ;
; OPL2_PARAMETER3 @ $00:0035
OPL2_SET_INSTRUMENT ;Return Byte, Param: (byte channel, const unsigned char *instrument);
SEC ; Set the WaveFormSelect to True
JSL OPL2_SET_WAVEFORMSELECT;
setas
setxl
LDY #$0000
LDX #$0000
LDA [OPL2_ADDY_PTR_LO],Y ; Pointer Location 0 in Instrument Profile
STA OPL2_PARAMETER3
INY
;Base drum...
CMP #$06
BNE PERCUSSION_NEXT07
BRL Percussion_6
;Snare drum...
PERCUSSION_NEXT07
CMP #$07
BNE PERCUSSION_NEXT08
BRL Percussion_7
;Tom Tom
PERCUSSION_NEXT08
CMP #$08
BNE PERCUSSION_NEXT09
BRL Percussion_8
;Top Cymbal
PERCUSSION_NEXT09
CMP #$09
BNE PERCUSSION_NEXT0A
BRL Percussion_9
;Hi Hat
PERCUSSION_NEXT0A
CMP #$0A
BNE Percussion_Default
BRL Percussion_A
; Melodic Instruments
Percussion_Default
LDA #$00
STA OPL2_OPERATOR
; The Channel Has been Set Already
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 1 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$0040;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 2 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$0060;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 3 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$0080;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 4 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$00E0;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 5 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
; Zone $C0
setxs
LDA OPL2_CHANNEL
AND #$0F
TAX
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 6 in Instrument Profile
STA @lOPL3_R_FEEDBACK,X
INY
; Deal with Operator 1
LDA #$01
STA OPL2_OPERATOR
; The Channel Has been Set Already
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 7 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$0040;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 8 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$0060;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 9 in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$0080;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location A in Instrument Profile
STA [OPL2_IND_ADDY_LL]
INY
setal
LDA #$00E0;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location B in Instrument Profile
STA [OPL2_IND_ADDY_LL]
RTL
Percussion_A
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 1 in Instrument Profile
STA @lOPL3_R_AM_VID_EG_KSR_MULT + $11
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 2 in Instrument Profile
STA @lOPL3_R_KSL_TL + $11
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 3 in Instrument Profile
STA @lOPL3_R_AR_DR + $11
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 4 in Instrument Profile
STA @lOPL3_R_SL_RR + $11
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 5 in Instrument Profile
STA @lOPL3_R_WAVE_SELECT + $11
RTL
Percussion_9
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 1 in Instrument Profile
STA @lOPL3_R_AM_VID_EG_KSR_MULT + $15
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 2 in Instrument Profile
STA @lOPL3_R_KSL_TL + $15
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 3 in Instrument Profile
STA @lOPL3_R_AR_DR + $15
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 4 in Instrument Profile
STA @lOPL3_R_SL_RR + $15
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 5 in Instrument Profile
STA @lOPL3_R_WAVE_SELECT + $15
RTL
Percussion_8
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 1 in Instrument Profile
STA @lOPL3_R_AM_VID_EG_KSR_MULT + $12
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 2 in Instrument Profile
STA @lOPL3_R_KSL_TL + $12
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 3 in Instrument Profile
STA @lOPL3_R_AR_DR + $12
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 4 in Instrument Profile
STA @lOPL3_R_SL_RR + $12
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 5 in Instrument Profile
STA @lOPL3_R_WAVE_SELECT + $12
RTL
Percussion_7
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 1 in Instrument Profile
STA @lOPL3_R_AM_VID_EG_KSR_MULT + $14
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 2 in Instrument Profile
STA @lOPL3_R_KSL_TL + $14
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 3 in Instrument Profile
STA @lOPL3_R_AR_DR + $14
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 4 in Instrument Profile
STA @lOPL3_R_SL_RR + $14
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 5 in Instrument Profile
STA @lOPL3_R_WAVE_SELECT + $14
RTL
; If Percussion Type 6, Use the Profile to Adjust those Registers
Percussion_6
setas
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 1 in Instrument Profile
STA @lOPL3_R_AM_VID_EG_KSR_MULT + $10
STA @lOPL3_R_AM_VID_EG_KSR_MULT + $13
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 2 in Instrument Profile
STA @lOPL3_R_KSL_TL + $10
STA @lOPL3_R_KSL_TL + $13
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 3 in Instrument Profile
STA @lOPL3_R_AR_DR + $10
STA @lOPL3_R_AR_DR + $13
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 4 in Instrument Profile
STA @lOPL3_R_SL_RR + $10
STA @lOPL3_R_SL_RR + $13
INY
LDA [OPL2_ADDY_PTR_LO], Y ; Pointer Location 5 in Instrument Profile
STA @lOPL3_R_WAVE_SELECT + $10
STA @lOPL3_R_WAVE_SELECT + $13
RTL
;
;OPL2_PARAMETER0 = Register ;
;OPL2_PARAMETER1 = Value ;
OPL2_SET_REGISTER ;Return Byte, Param: (byte reg, byte value);
setal
CLC
LDA #<>OPL3_R_BASE
ADC OPL2_PARAMETER0
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
LDA OPL2_PARAMETER1
STA [OPL2_IND_ADDY_LL]
RTL
OPL2_SET_WAVEFORMSELECT ;Return Byte, Param: (bool enable);
setal
LDA #<>OPL3_R_BASE + $0001
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_HL
setas
BCS OPL2_Set_WaveFormSelect_set
;clear
LDA [OPL2_IND_ADDY_LL]
AND #$DF
STA [OPL2_IND_ADDY_LL]
RTL
OPL2_Set_WaveFormSelect_set
;set
LDA [OPL2_IND_ADDY_LL]
ORA #$20
STA [OPL2_IND_ADDY_LL]
RTL
;OPL2_SET_TREMOLO
; Inputs
; Carry (1 = Enable, 0 = Disable)
;OPL2_OPERATOR = $000026 ;
;OPL2_CHANNEL = $000027 ;
;OPL2_ENABLE = $000028 ;
;OPL2_REG_OFFSET = $00002A ;
; Output
;
; Note: Only Support Stereo (dual Write) - No Individual (R-L Channel) Target
OPL2_SET_TREMOLO ;Return Byte, Param: (byte channel, byte operatorNum, bool enable);
PHP ; Push the Carry
setal
CLC
LDA #$0020 ;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
; Now Check if we are going to enable the bit or disable it
PLP ; Pull the Carry out
setas
BCS OPL2_Set_Tremolo_Set;
; Clear the Bit
LDA [OPL2_IND_ADDY_LL]
AND #$7F
STA [OPL2_IND_ADDY_LL]
BRA OPL2_Set_Tremolo_Exit
; Set the Bit
OPL2_Set_Tremolo_Set
LDA [OPL2_IND_ADDY_LL]
ORA #$80
STA [OPL2_IND_ADDY_LL]
; Let's get out of here
OPL2_Set_Tremolo_Exit
RTL
;OPL2_GET_TREMOLO
; Inputs
;OPL2_OPERATOR = $000026 ;
;OPL2_CHANNEL = $000027 ;
;OPL2_ENABLE = $000028 ;
;OPL2_REG_OFFSET = $00002A ;
; Output
; A = Tremolo Status Bit7
OPL2_GET_TREMOLO ; Return Bool, Param: (byte channel, byte operatorNum);
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$80
RTL
;OPL2_SET_VIBRATO
; Inputs
; C = Enable
;OPL2_OPERATOR = $000026 ;
;OPL2_CHANNEL = $000027 ;
;OPL2_ENABLE = $000028 ;
;OPL2_REG_OFFSET = $00002A ;
; C = Enable (1 = Enable, 0 = Disable)
OPL2_SET_VIBRATO ;Return Byte, Param: (byte channel, byte operatorNum, bool enable);
PHP ; Push the Carry
setal
CLC
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
; Now Check if we are going to enable the bit or disable it
PLP ; Pull the Carry out
setas
BCS OPL2_Set_Vibrato_Set;
; Clear the Bit
LDA [OPL2_IND_ADDY_LL]
AND #$BF
STA [OPL2_IND_ADDY_LL]
BRA OPL2_Set_Vibrato_Exit
; Set the Bit
OPL2_Set_Vibrato_Set
LDA [OPL2_IND_ADDY_LL]
ORA #$40
STA [OPL2_IND_ADDY_LL]
; Let's get out of here
OPL2_Set_Vibrato_Exit
RTL
;
;OPL2_GET_VIBRATO
; Inputs
;OPL2_OPERATOR = $000026 ;
;OPL2_CHANNEL = $000027 ;
;OPL2_ENABLE = $000028 ;
;OPL2_REG_OFFSET = $00002A ;
; Output
; A = Tremolo Status Bit6
OPL2_GET_VIBRATO ; Return Bool, Param: (byte channel, byte operatorNum);
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$40
RTL
;
;OPL2_SET_MAINTAINSUSTAIN
; Inputs
; C = Enable
;OPL2_OPERATOR = $000028 ;
;OPL2_CHANNEL = $000029 ;
;OPL2_ENABLE = $00002A ;
;OPL2_REG_OFFSET = $00002B ;
; C = Enable (1 = Enable, 0 = Disable)
OPL2_SET_MAINTAINSUSTAIN ;Return Byte, Param: (byte channel, byte operatorNum, bool enable);
PHP ; Push the Carry
setal
CLC
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
; Now Check if we are going to enable the bit or disable it
PLP ; Pull the Carry out
setas
BCS OPL2_Set_MaintainSustain_Set;
; Clear the Bit
LDA [OPL2_IND_ADDY_LL]
AND #$DF
STA [OPL2_IND_ADDY_LL]
BRA OPL2_Set_MaintainSustain_Exit
OPL2_Set_MaintainSustain_Set
LDA [OPL2_IND_ADDY_LL]
ORA #$20
STA [OPL2_IND_ADDY_LL]
; Let's get out of here
OPL2_Set_MaintainSustain_Exit
RTL
;OPL2_GET_MAINTAINSUSTAIN
OPL2_GET_MAINTAINSUSTAIN ; Return Bool, Param: (byte channel, byte operatorNum);
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$20
RTL
;OPL2_SET_ENVELOPESCALING
; Inputs
; C = Enable
;OPL2_OPERATOR = $000028 ;
;OPL2_CHANNEL = $000029 ;
;OPL2_ENABLE = $00002A ;
;OPL2_REG_OFFSET = $00002B ;
; C = Enable (1 = Enable, 0 = Disable)
OPL2_SET_ENVELOPESCALING ;Return Byte, Param: (byte channel, byte operatorNum, bool enable);
PHP ; Push the Carry
setal
CLC
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
; Now Check if we are going to enable the bit or disable it
PLP ; Pull the Carry out
setas
BCS OPL2_Set_EnvelopeScaling_Set;
; Clear the Bit
LDA [OPL2_IND_ADDY_LL]
AND #$EF
STA [OPL2_IND_ADDY_LL]
BRA OPL2_Set_EnvelopeScaling_Exit
OPL2_Set_EnvelopeScaling_Set
LDA [OPL2_IND_ADDY_LL]
ORA #$10
STA [OPL2_IND_ADDY_LL]
; Let's get out of here
OPL2_Set_EnvelopeScaling_Exit
RTL
;
OPL2_GET_ENVELOPESCALING ; Return Bool, Param: (byte channel, byte operatorNum);
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$10
RTL
OPL2_GET_MODFREQMULTIPLE ; Return Byte, Param: (byte channel, byte operatorNum);
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$0F
RTL
;
;OPL2_SET_MULTIPLIER
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; OPL2_PARAMETER0 = Multiplier
OPL2_SET_MODFREQMULTIPLE ;Return Byte, Param: (byte channel, byte operatorNum, byte multiplier);
setal
LDA #$0020;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA OPL2_PARAMETER0
AND #$0F
STA OPL2_PARAMETER0
LDA [OPL2_IND_ADDY_LL]
AND #$F0
ORA OPL2_PARAMETER0
STA [OPL2_IND_ADDY_LL]
RTL
;
;
; REGISTERS REGION $40
;
;OPL2_SET_SCALINGLEVEL
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; OPL2_PARAMETER0 = ScalingLevel
OPL2_SET_SCALINGLEVEL ;Return Byte, Param: (byte channel, byte operatorNum, byte scaling);
setal
LDA #$0040;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA OPL2_PARAMETER0 ; Attack
AND #$03
ASL
ASL
ASL
ASL
ASL
ASL
STA OPL2_PARAMETER0
LDA [OPL2_IND_ADDY_LL]
AND #$3F
ORA OPL2_PARAMETER0
STA [OPL2_IND_ADDY_LL]
RTL
;OPL2_SET_VOLUME
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; OPL2_PARAMETER0 = Volume
OPL2_SET_VOLUME ;Return Byte, Param: (byte channel, byte operatorNum, byte volume);
setal
LDA #$0040 ;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA OPL2_PARAMETER0 ; Volume
AND #$3F
STA OPL2_PARAMETER0
LDA [OPL2_IND_ADDY_LL]
AND #$C0
ORA OPL2_PARAMETER0
STA [OPL2_IND_ADDY_LL]
RTL
;OPL2_GET_VOLUME
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; Output
; A = Volume
OPL2_GET_VOLUME ; Return Byte, Param: (byte channel, byte operatorNum);
setal
LDA #$0040 ;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$3F
RTL
;
;
; REGISTERS REGION $60
;
;OPL2_SET_ATTACK
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; OPL2_PARAMETER0 = Attack
OPL2_SET_ATTACK ;Return Byte, Param: (byte channel, byte operatorNum, byte attack);
setal
LDA #$0060 ;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA OPL2_PARAMETER0 ; Attack
AND #$0F
ASL
ASL
ASL
ASL
STA OPL2_PARAMETER0
LDA [OPL2_IND_ADDY_LL]
AND #$0F
ORA OPL2_PARAMETER0
STA [OPL2_IND_ADDY_LL]
RTL
;
;OPL2_GET_ATTACK
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; Output
; A = Attack
OPL2_GET_ATTACK ; Return Byte, Param: (byte channel, byte operatorNum);
setal
LDA #$0060
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$F0
LSR
LSR
LSR
LSR
RTL
;OPL2_Set_Decay
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; OPL2_PARAMETER0 = Decay
OPL2_SET_DECAY ;Return Byte, Param: (byte channel, byte operatorNum, byte decay);
setal
LDA #$0060;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA OPL2_PARAMETER0 ; Attack
AND #$0F
STA OPL2_PARAMETER0
LDA [OPL2_IND_ADDY_LL]
AND #$F0
ORA OPL2_PARAMETER0
STA [OPL2_IND_ADDY_LL]
RTL
;
;OPL2_GET_DECAY
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; Output
; A = Decay
OPL2_GET_DECAY ; Return Byte, Param: (byte channel, byte operatorNum);
setal
LDA #$0060
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA [OPL2_IND_ADDY_LL]
AND #$0F
RTL
;
; REGISTERS REGION $80
;
;OPL2_SET_SUSTAIN
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; OPL2_PARAMETER0 = Sustain
OPL2_SET_SUSTAIN ;Return Byte, Param: (byte channel, byte operatorNum, byte sustain);
setal
LDA #$0080;
STA OPL2_REG_REGION
JSR OPL2_GET_REG_OFFSET
setas
LDA OPL2_PARAMETER0 ; Attack
AND #$0F
ASL
ASL
ASL
ASL
STA OPL2_PARAMETER0
LDA [OPL2_IND_ADDY_LL]
AND #$0F
ORA OPL2_PARAMETER0
STA [OPL2_IND_ADDY_LL]
RTL
;
; OPL2_GET_SUSTAIN
; Inputs
; OPL2_OPERATOR @ $000026 ;
; OPL2_CHANNEL @ $000027 ;
; OPL2_REG_OFFSET @ $00002A ;
; Output