-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rad_Player.asm
1010 lines (900 loc) · 28.5 KB
/
Rad_Player.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
EFFECT_NONE = $00
EFFECT_NOTE_SLIDE_UP = $01
EFFECT_NOTE_SLIDE_DOWN = $02
EFFECT_NOTE_SLIDE_TO = $03
EFFECT_NOTE_SLIDE_VOLUME = $05
EFFECT_VOLUME_SLIDE = $0A
EFFECT_SET_VOLUME = $0C
EFFECT_PATTERN_BREAK = $0D
EFFECT_SET_SPEED = $0F
FNUMBER_MIN = $0156
FNUMBER_MAX = $02AE
FIFTY_HZ_COUNT = 286360
SLOW_TIMER = 786703
SongData .struct
version .byte $00 ; bit 1 is RAD 1, bit 2 is RAD 2
songLength .byte $00
InitialSpeed .byte $06
hasSlowTimer .byte $00 ;BOOL $00 = False, $01 = True
.ends
; special characters for notes
; C C# D D# E F F# G G# A A# B
note_array .byte $43, $90, $44, $91, $45, $46, $92, $47, $93, $41, $94, $42, $43
TuneInfo .dstruct SongData
; ************************************************************************************************
; We are assuming that the RAD File is already Loaded Somewhere
; ************************************************************************************************
RAD_INIT_PLAYER
JSL OPL3_INIT ; Init OPL3
JSR RAD_ALL_NOTES_OFF
; zero the pattern memory
LDX #0
LDA #0
RI_RESET
STA PATTERNS,X
INX
BNE RI_RESET
; READ the RAD file
setaxl
LDA #<>RAD_FILE_TEMP ; Set the Pointer where the File Begins
STA OPL2_ADDY_PTR_LO;
LDA #<`RAD_FILE_TEMP
STA OPL2_ADDY_PTR_HI;
setas
; get the version of the file
LDY #$0010
LDA [OPL2_ADDY_PTR_LO],Y
CMP #$10 ; BCD version 1.0 or 2.1
BNE RI_LOAD_VERSION_21
JSL READ_VERSION_10
RTL ; End of RAD_INIT_PLAYER
RI_LOAD_VERSION_21
CMP #$21
BNE RI_INVALID
JSL READ_VERSION_21
RI_INVALID
RTL ; End of RAD_INIT_PLAYER
; ************************************************************************************************
; Read a RAD file version 2.1
; ************************************************************************************************
READ_VERSION_21
;not implemented
LDA #2
STA @lTuneInfo.version
JSR READ_TIMER
JSR PARSER_RAD_FILE_INSTRUMENT_21; Parse the Instrument
RTL ; End of READ_VERSION_21
; ************************************************************************************************
; The timer setting is at offset $11 for both 1.0 and 2.1 RAD Formats
; ************************************************************************************************
READ_TIMER
LDY #$11
LDA [OPL2_ADDY_PTR_LO],Y
BIT #$40
BEQ RT_NOT_SLOW
LDA #1
STA @lTuneInfo.hasSlowTimer
LDA #<SLOW_TIMER
STA TIMER0_CMP_L
LDA #>SLOW_TIMER
STA TIMER0_CMP_M
LDA #<`SLOW_TIMER
STA TIMER0_CMP_H
BRA SET_TIMER
RT_NOT_SLOW
BIT #$20
BEQ RT_NOT_BPM
INY
setal
LDA [OPL2_ADDY_PTR_LO],Y
setas
INY
BRA SET_TIMER
RT_NOT_BPM
LDA #0
STA @lTuneInfo.hasSlowTimer
LDA #<FIFTY_HZ_COUNT
STA TIMER0_CMP_L
LDA #>FIFTY_HZ_COUNT
STA TIMER0_CMP_M
LDA #<`FIFTY_HZ_COUNT
STA TIMER0_CMP_H
SET_TIMER
JSR INIT_TIMER0
RTS
; ************************************************************************************************
; Read a RAD file version 1.1
; ************************************************************************************************
READ_VERSION_10
.as
LDA #1
STA @lTuneInfo.version
JSR PARSER_RAD_FILE_INSTRUMENT_10; Parse the Instrument
JSR PROCESS_ORDER_LIST_10 ; Parse the Order List
JSR READ_PATTERNS_10
JSR READ_TIMER
RTL ; End of READ_VERSION_10
ADLIB_OFFSETS .byte 7,1,8,2,9,3,10,4,5,11,6
; ************************************************************************************************
; Read the instrument table.
; RAD V1.0 Format
; ************************************************************************************************
PARSER_RAD_FILE_INSTRUMENT_10
INY ; $11 bit 7: description, bit6: slow timer, bits4..0: speed
LDA [OPL2_ADDY_PTR_LO],Y
;Will Ignore the has slowSlowTimer for now
AND #$1F
STA @lTuneInfo.InitialSpeed
LDA [OPL2_ADDY_PTR_LO],Y
AND #$80
BEQ READ_INSTR_DATA
Not_Done_With_Description
INY ; Move the Pointer Forward
LDA [OPL2_ADDY_PTR_LO],Y
CMP #$00 ; Check for the End of Text
BNE Not_Done_With_Description
READ_INSTR_DATA
INY ; This points after either After Description or next to Offset 0x11
; Let's Init the Address Point for the instrument Tables
LDA #<`INSTRUMENT_ACCORDN
STA RAD_ADDR + 2
; Let's Read Some Instruments HERE
ProcessNextInstruments_10
setas
LDA [OPL2_ADDY_PTR_LO],Y ; Read Instrument Number
BEQ DoneProcessingInstrument_10
setal
; find the address of the instrument by multiplying by the record length
DEC A
STA @lUNSIGNED_MULT_A
LDA #INSTR_REC_LEN
STA @lUNSIGNED_MULT_B
LDA @lUNSIGNED_MULT_RESULT ; not sure why this one requires a long address - bank is still 0
CLC
ADC #<>INSTRUMENT_ACCORDN
STA RAD_ADDR
LDA #0
setas
INY
STZ RAD_TEMP
STA [RAD_ADDR] ; Not a drum instrument
Transfer_Instrument_Info
LDX RAD_TEMP
LDA ADLIB_OFFSETS,X ; RAD uses a different order for registers
TAX
LDA [OPL2_ADDY_PTR_LO],Y ; Read Register
PHY
TXY
STA [RAD_ADDR],Y ; Write to the instrument table
PLY
INY
INC RAD_TEMP
LDA RAD_TEMP
CMP #11
BCC Transfer_Instrument_Info
PHY ; store the position in the file on the stack
LDY #12 ; beginning of text
LDA #$20
;TODO: set description to 'RAD INST #'
BLANK_INSTR_DESCR
STA [RAD_ADDR],Y
INY
CPY #22
BNE BLANK_INSTR_DESCR
PLY
BRA ProcessNextInstruments_10
DoneProcessingInstrument_10
INY
RTS
; ************************************************************************************************
; Read the instrument table.
; RAD V2.1 Format
; ************************************************************************************************
PARSER_RAD_FILE_INSTRUMENT_21
PR_LOOP
; skip the description
LDA [OPL2_ADDY_PTR_LO],Y
INY
CMP #0
BNE PR_LOOP
; Let's Init the Address Point for the instrument Tables
LDA #<`INSTRUMENT_ACCORDN
STA RAD_ADDR + 2
; Let's Read Some Instruments HERE
ProcessNextInstruments_21
setas
LDA [OPL2_ADDY_PTR_LO],Y ; Read Instrument Number
BEQ DoneProcessingInstrument_21
; TODO _ CONTINUE HERE
DoneProcessingInstrument_21
INY
RTS
; ************************************************************************************************
; * Read the orders list
; ************************************************************************************************
PROCESS_ORDER_LIST_10
LDA [OPL2_ADDY_PTR_LO],Y ; Read Song Length
STA @lTuneInfo.songLength
TAX
INY
setal
LDA #<>ORDERS
STA RAD_ADDR
LDA #<`ORDERS
STA RAD_ADDR + 2
setas
READ_ORDER
LDA [OPL2_ADDY_PTR_LO],Y
INY
STA [RAD_ADDR]
INC RAD_ADDR
BCS ORDER_CONTINUE
INC RAD_ADDR + 1
ORDER_CONTINUE
DEX
BNE READ_ORDER
RTS
; ************************************************************************************************
; * Read the pattern table
; * Y contains the position in the file
; ************************************************************************************************
READ_PATTERNS_10
; RAD_PATTRN holds the pattern number
STZ RAD_PATTRN
; high byte of the pattern address
LDA #<`PATTERNS
STA RAD_PTN_DEST + 2
NEXT_PATTERN
; read the file offset
setal
LDA [OPL2_ADDY_PTR_LO],Y
BEQ SKIP_PATTERN
PHY
TAY
; compute the start address of the pattern
LDA RAD_PATTRN
AND #$00FF
STA @lUNSIGNED_MULT_A
LDA #PATTERN_BYTES
STA @lUNSIGNED_MULT_B
LDA @lUNSIGNED_MULT_RESULT
INC A ; skip the pattern byte
STA RAD_PTN_DEST
setas
JSR READ_PATTERN_10
PLY
SKIP_PATTERN
INY
INY
setas
INC RAD_PATTRN
LDA RAD_PATTRN
CMP #32
BNE NEXT_PATTERN
RTS
; ************************************************************************************************
; * Read the pattern table
; * Y contains the position in the RAD 1.0 file
; * RAD_PTN_DEST is the address to write to
; ************************************************************************************************
READ_PATTERN_10
LDA [OPL2_ADDY_PTR_LO],Y ; read the line number - bit 7 indicates the last line
STA @lRAD_LINE
INY
setal
AND #$7F
STA @lUNSIGNED_MULT_A
LDA #LINE_BYTES
STA @lUNSIGNED_MULT_B
LDA @lUNSIGNED_MULT_RESULT
INC A ; skip the line number
STA @lRAD_LINE_PTR
setas
READ_NOTE
LDX RAD_LINE_PTR ; X contains the offset in the destination memory
LDA [OPL2_ADDY_PTR_LO],Y ; channel - bit 7 indicates the last note
INY
STA @lRAD_LAST_NOTE
AND #$F
STA @lRAD_CHANNEL
setal
TXA
CLC
ADC RAD_CHANNEL ; multiply channel by 3
ADC RAD_CHANNEL
ADC RAD_CHANNEL
TAX
setas
LDA [OPL2_ADDY_PTR_LO],Y ; note / octave
PHY
TXY
STA [RAD_PTN_DEST],Y
PLY
INY
INX
LDA [OPL2_ADDY_PTR_LO],Y ; instrument/effect
PHY
TXY
STA [RAD_PTN_DEST],Y
PLY
INY
INX
AND #$F
BEQ CHECK_LASTNOTE
LDA [OPL2_ADDY_PTR_LO],Y ; effect parameter
PHY
TXY
STA [RAD_PTN_DEST],Y
PLY
INY
INX
CHECK_LASTNOTE
LDA @lRAD_LAST_NOTE
BPL READ_NOTE
LDA @lRAD_LINE
BPL READ_PATTERN_10
RTS
;*****************************
; Draw 18 '-' in line 0 of the display
;*****************************
DRAW_BLANKS
.as
PHY
PHX
LDX #18
LDY #0
LDA #'-'
BL_NEXT
STA [SCREENBEGIN], Y
INY
DEX
BNE BL_NEXT
PLX
PLY
RTS
;**********************************************************
; Draw the RAD_PTN_DEST address at position specified by Y
;**********************************************************
DISPLAY_RAD_PTN_DEST
.as
PHY
LDA RAD_PTN_DEST+2
JSR WRITE_HEX
INY
INY
LDA RAD_PTN_DEST+1
JSR WRITE_HEX
INY
INY
LDA RAD_PTN_DEST
JSR WRITE_HEX
PLY
RTS
;**********************************************************
; Draw the value of A at position specified by Y
;**********************************************************
WRITE_A_LNG
.al
PHA
PHA
setas
PLA
JSR WRITE_HEX
DEY
DEY
PLA
JSR WRITE_HEX
setal
PLA
RTS
; ************************************************************************************************
; * Turn off all notes to all 9 channels
; ************************************************************************************************
RAD_ALL_NOTES_OFF
.as
PHY
setal
LDA #<>OPL3_R_BASE
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_LL + 2
setas
LDY #$A0
LDA #0
NEXT_NOTE_OFF
STA [OPL2_IND_ADDY_LL],Y
INY
CPY #$B9
BNE NEXT_NOTE_OFF
PLY
RTS
; ************************************************************************************************
; * Play the notes given a pattern and line number.
; ************************************************************************************************
RAD_PLAYNOTES
.as
PHY
JSR DRAW_BLANKS
setal
LDA PATTERN_NUM
AND #$FF
DEC A ; start at 0
STA @lUNSIGNED_MULT_A
LDA #PATTERN_BYTES
STA @lUNSIGNED_MULT_B
LDA @lUNSIGNED_MULT_RESULT
INC A ; skip the pattern number byte
STA RAD_PTN_DEST
setas
LDA #<`PATTERNS
STA RAD_PTN_DEST + 2
LDY #SCREEN_WIDTH * 2
JSR DISPLAY_RAD_PTN_DEST ; display the address of the pattern
setal
LDA LINE_NUM_HEX
AND #$7F
STA @lUNSIGNED_MULT_A
LDA #LINE_BYTES
STA @lUNSIGNED_MULT_B
LDA @lUNSIGNED_MULT_RESULT
INC A ; skip the line number byte
LDY #SCREEN_WIDTH + 2
JSR WRITE_A_LNG ; display the line offset from the pattern address
TAY ; Y contains the line offset
LDA #0
setas
STZ OPL2_REG_REGION
PN_NEXT_NOTE
STA @lOPL2_CHANNEL
; check if we're going to play the note for this channel
TAX
LDA CHANNELS,X
BNE PN_PLAY_NOTE
INY ; skip the channel data
INY
INY
BRA PN_CONTINUE
PN_PLAY_NOTE
LDA [RAD_PTN_DEST],Y ; octave/note
AND #$7F
JSR RAD_WRITE_OCT_NOTE
LDA [RAD_PTN_DEST],Y ; bit 7 is bit 4 of the instrument number
AND #$80
LSR A
LSR A
LSR A
STA RAD_TEMP
INY
LDA [RAD_PTN_DEST],Y ; instrument/effect
AND #$F0
LSR A
LSR A
LSR A
LSR A
ADC RAD_TEMP
BEQ SKIP_INSTRUMENT
DEC A ; instruments are starting at 0
STA @lINSTR_NUMBER
PHY
LDX OPL2_CHANNEL
LDA #0
XBA
LDA @lregisterOffsets_operator0,X
TAX
JSR LOAD_INSTRUMENT
PLY
SKIP_INSTRUMENT
LDA @lOPL2_NOTE
BEQ SKIP_NOTE ; if the note is 0, don't play anything.
CMP #$0F ; NOTE OFF
BEQ RAD_NOTE_OFF
setal
PHY
JSR OPL2_GET_REG_OFFSET
JSL OPL2_PLAYNOTE
PLY
setas
SKIP_NOTE
LDA #0
XBA
LDA [RAD_PTN_DEST],Y ; instrument/effect
INY
AND #$F
BEQ SKIP_EFFECT
ASL A ; double bytes
TAX
JSR (RAD_EFFECT_TABLE,X)
SKIP_EFFECT
INY
PN_CONTINUE
; increment the channel
LDA #0 ; clear B
XBA
LDA @lOPL2_CHANNEL
INC A
CMP #9
BNE PN_NEXT_NOTE
PLY
RTS
RAD_NOTE_OFF
.as
LDA @lOPL2_CHANNEL
CLC
ADC #$B0
STA OPL2_IND_ADDY_LL
LDA #0
STA [OPL2_IND_ADDY_LL]
INY
;INY
INY
BRA PN_CONTINUE
RAD_EFFECT_TABLE
.word <>RAD_EFFECT_NONE ; 00
.word <>RAD_EFFECT_NOTE_SLIDE_UP ; 01
.word <>RAD_EFFECT_NOTE_SLIDE_DOWN ; 02
.word <>RAD_EFFECT_NOTE_SLIDE_TO ; 03
.word <>RAD_NOOP
.word <>RAD_EFFECT_NOTE_SLIDE_VOLUME ; 05
.word <>RAD_NOOP
.word <>RAD_NOOP
.word <>RAD_NOOP
.word <>RAD_NOOP
.word <>RAD_EFFECT_VOLUME_SLIDE ; 0A
.word <>RAD_NOOP
.word <>RAD_EFFECT_SET_VOLUME ; 0C
.word <>RAD_EFFECT_PATTERN_BREAK ; 0D
.word <>RAD_NOOP
.word <>RAD_EFFECT_SET_SPEED ; 0F
; ******************************************************
; * Y contains the pointer to the effect parameter
; ******************************************************
RAD_NOOP
RAD_EFFECT_NONE
RAD_EFFECT_NOTE_SLIDE_TO
RAD_EFFECT_NOTE_SLIDE_VOLUME
.as
RTS
RAD_EFFECT_VOLUME_SLIDE
.as
PHY
LDA [RAD_PTN_DEST],Y ; store value of the effect in RAD_CHANNE_EFFCT
STA RAD_CHANNE_EFFCT
setal
LDA #<>OPL3_R_BASE
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_LL + 2
setaxs
; READ the current volume, offset $40, 00 is loud, 63 is
LDA OPL2_CHANNEL
TAX
LDA @lregisterOffsets_operator0,X
CLC
ADC #$40
TAY
; first operator
LDA [OPL2_IND_ADDY_LL],Y ; volume
PHA
AND #$3F
CLC
ADC RAD_CHANNE_EFFCT ; check for values greater than 50
CMP #$40 ; if there's an overflow, use #$3F (low volume)
BCC NO_OVERFLOW_0
LDA #$3F
NO_OVERFLOW_0
AND #$3F
STA RAD_TEMP
PLA
AND #$C0
ORA RAD_TEMP
STA [OPL2_IND_ADDY_LL],Y
INY
INY
INY
; second operator
LDA [OPL2_IND_ADDY_LL],Y ; volume
PHA
AND #$3F
CLC
ADC RAD_CHANNE_EFFCT
CMP #$40 ; if there's an overflow, use #$3F (low volume)
BCC NO_OVERFLOW_1
LDA #$3F
NO_OVERFLOW_1
AND #$3F
STA RAD_TEMP
PLA
AND #$C0
ORA RAD_TEMP
STA [OPL2_IND_ADDY_LL],Y
setxl
PLY
RTS
RAD_EFFECT_PATTERN_BREAK
.as
LDA [RAD_PTN_DEST],Y ; effect parameter
DEC A ; DECREMENT by 1, because the next timer interrupt will increment at the beginning
STA LINE_NUM_HEX
LDA #0 ; convert the effect to a decimal line number
STA @lLINE_NUM_DEC
JSR INCREMENT_ORDER
PLY ; don't return to the calling method, return to the parent
PLY
RTS
RAD_EFFECT_SET_SPEED
.as
LDA [RAD_PTN_DEST],Y ; effect parameter
STA @lTuneInfo.InitialSpeed
JSR DISPLAY_SPEED
RTS
; ******************************************************
; * Y contains the pointer to the effect parameter
; ******************************************************
RAD_EFFECT_NOTE_SLIDE_UP
RAD_EFFECT_NOTE_SLIDE_DOWN
.as
PHY
LSR
STA RAD_EFFECT ; 1 slide down, 2 slide up
LDA [RAD_PTN_DEST],Y ; store value of the effect in RAD_CHANNE_EFFCT
STA RAD_CHANNE_EFFCT
setal
LDA #<>OPL3_R_BASE
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_LL + 2
setaxs
; read the current fnumber into accumulator
LDA OPL2_CHANNEL
CLC
ADC #$A0
TAY
LDA [OPL2_IND_ADDY_LL],Y ; read low fnumber byte
setxl
TYX
LDY #SCREEN_WIDTH + 10
JSR WRITE_HEX
TXY
setxs
PHA ; store A on the stack
TYA
CLC
ADC #$10
TAY
LDA [OPL2_IND_ADDY_LL],Y ; read bits 0,1 of high fnumber
STA RAD_TEMP ; store the entire value of $B0
setxl
TYX
LDY #SCREEN_WIDTH * 2 + 8
JSR WRITE_HEX
AND #3
LDY #SCREEN_WIDTH + 8
JSR WRITE_HEX
TXY
XBA
PLA ; A is now the FNUMBER
TAX ; X is now the FNUMBER
; if effect is 1, then decrease fnumber, otherwise, increase
LDA RAD_EFFECT
BIT #2
BEQ SLIDE_UP
setal
TXA
SEC
SBC RAD_CHANNE_EFFCT ; substract the effect parameter
setas
BRA FINISH_SLIDE
SLIDE_UP
setal
TXA
CLC
ADC RAD_CHANNE_EFFCT ; substract the effect parameter
setas
FINISH_SLIDE
; now store the value back into fnumber
setxs
XBA
AND #3
ORA RAD_TEMP
STA [OPL2_IND_ADDY_LL],Y
TYA
SEC
SBC #$10
TAY
XBA
STA [OPL2_IND_ADDY_LL],Y
setxl
PLY
RTS
; ******************************************************
; * Y contains the pointer to the effect parameter
; ******************************************************
RAD_EFFECT_SET_VOLUME
.as
PHY
setal
LDA #<>OPL3_R_BASE
STA OPL2_IND_ADDY_LL
LDA #`OPL3_R_BASE
STA OPL2_IND_ADDY_LL + 2
setas
LDA [RAD_PTN_DEST],Y ; effect parameter
AND #$7F
BEQ HANDLE_ZERO
DEC A
HANDLE_ZERO
EOR #$3F ; complement
STA RAD_TEMP
setxs
LDX OPL2_CHANNEL
LDA @lregisterOffsets_operator0,X
CLC
ADC #$40
TAY
LDA [OPL2_IND_ADDY_LL],Y
AND #$C0 ;
CLC
ADC RAD_TEMP
STA [OPL2_IND_ADDY_LL],Y
INY
INY
INY
LDA [OPL2_IND_ADDY_LL],Y
AND #$C0 ;
CLC
ADC RAD_TEMP
STA [OPL2_IND_ADDY_LL],Y
setxl
PLY
RTS
; ********************************
; * A contain the octave/note byte
; ********************************
RAD_WRITE_OCT_NOTE
.as
PHY
PHA
PHA
LDA @lOPL2_CHANNEL
ASL A ; multiply the channel by 2 for the screen position
TAY
PLA
BEQ DONT_DISPLAY_00
JSR WRITE_HEX
DONT_DISPLAY_00
AND #$70 ; octave
LSR
LSR
LSR
LSR
STA @lOPL2_OCTAVE
PLA
AND #$0F ; note
STA @lOPL2_NOTE
PLY
RTS
;
RAD_SETINSTRUMENT
PHY
; Carrier
setas
LDA #$01
STA OPL2_OPERATOR
setal
LDA #<`INSTRUMENT_ACCORDN
STA OPL2_ADDY_PTR_HI
LDA OPL2_PARAMETER0
AND #$00FF
DEC A
ASL A
ASL A
ASL A
ASL A
CLC
ADC #<>INSTRUMENT_ACCORDN
STA OPL2_ADDY_PTR_LO
setal
LDA #$0020
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0000
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
setal
LDA #$0040
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0002
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
setal
LDA #$0060
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0004
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
setal
LDA #$0080
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0006
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
setal
LDA #$00E0
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0009
LDA [OPL2_ADDY_PTR_LO],Y
AND #$0F
STA [OPL2_IND_ADDY_LL]
; MODULATOR
LDA #$00
STA OPL2_OPERATOR
; opl2.setRegister(0x20 + registerOffset, instruments[instrumentIndex][1]);
setal
LDA #$0020
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0001
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
; opl2.setRegister(0x40 + registerOffset, instruments[instrumentIndex][3]);
setal
LDA #$0040
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0003
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
; opl2.setRegister(0x60 + registerOffset, instruments[instrumentIndex][5]);
setal
LDA #$0060
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0005
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
; opl2.setRegister(0x80 + registerOffset, instruments[instrumentIndex][7]);
setal
LDA #$0080
JSL OPL2_GET_REG_OFFSET
setas
LDY #$00071
LDA [OPL2_ADDY_PTR_LO],Y
STA [OPL2_IND_ADDY_LL]
; opl2.setRegister(0xE0 + registerOffset, (instruments[instrumentIndex][9] & 0xF0) >> 4);
setal
LDA #$00E0
JSL OPL2_GET_REG_OFFSET
setas
LDY #$0009
LDA [OPL2_ADDY_PTR_LO],Y
AND #$F0
LSR A
LSR A
LSR A
LSR A
STA [OPL2_IND_ADDY_LL]
; opl2.setRegister(0xC0 + channel, instruments[instrumentIndex][8]);
LDA OPL2_CHANNEL
CLC
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
CLC
LDA #<>OPL3_R_BASE