-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSNDPM.MAC
1288 lines (1278 loc) · 35.5 KB
/
SNDPM.MAC
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
.TITLE SNDPM ;REMOTE SOUND BOARD VERSION
.SBTTL (RUSTY'S POKEY MUSIC) DRIVER, 6809 VERSION(gregr)
.INCLUDE SNDCMN
.SBTTL RPM CONFIGURATION
;---
VC1 =1 ;VOICE MASK BITS
VC2 =2
VC3 =4
VC4 =8
VC5 =10
VC6 =20
VC7 =40
VC8 =80
;===
;GLOBALS
.GLOBB $INTCT
.GLOBL TUNTAB
;===
.SBTTL *** USER OPTIONS/ADDRESSES
;*** MODIFY THE FOLLOWING PER YOUR REQUIREMENTS ***
;ASSEMBLY OPTIONS:
..SV3 = 0 ;NO SPLIT VOICE 3 (INTO TWO 8 BIT VOICES)
..SV4 = 0 ;NO SPLIT VOICE 4 INTO DUAL 8 BIT FREQ (0=16 BIT FREQ)
..PRI = 5 ;NUMBER OF PRIORITY CHANNELS FOR V4 (0-5) OR V4B (0-4)
..DRE = 1 ;DYNAMIC RECONFIGURATION ENABLE (0=DISABLE)
..SYM = 1 ;SYNTHISIZER MODE ENABLE (0=DISABLE)
..FRE = 1 ;FREQ. ENVELOPES ENABLE (0=DISABLE)
..AME = 1 ;AMPLITUDE ENVELOPE ENABLE (0=DISABLE)
..SCK = 0 ;SYNC. CHECK ENABLE (0=DISABLE)
..CNT = 0 ;NOTE COUNTER ENABLE (0=DISABLE)
;
; POKEY HARDWARE ADDRESSES
;
; ;4 POKEYS, INTERLEAVED ON 8 BYTES,USE SECOND PAIR
POKEY == 1810 ;3.5KHZ LOW PASS FILTER
PKI1 = POKEY+15.+18
PKC1 = POKEY+8.+18
PKR1 == POKEY+10.+18
POTGO1 == POKEY+11.+18
PKFL3 = POKEY
PKVX3 = POKEY+1
PKFH3 = POKEY+2
PKV3 = POKEY+3
PKFL4 = POKEY+4
PKVX4 = POKEY+5
PKFH4 = POKEY+6
PKV4 = POKEY+7
;
POKEY2 == POKEY+8 ;3.5KHZ LOW PASS FILTER
PKI2 = POKEY2+15.+18
PKC2 = POKEY2+8.+18
PKR2 == POKEY2+10.+18
POTGO2 == POKEY2+11.+18
PKFL1 = POKEY2
PKVX1 = POKEY2+1
PKFH1 = POKEY2+2
PKV1 = POKEY2+3
PKFL2 = POKEY2+4
PKVX2 = POKEY2+5
PKFH2 = POKEY2+6
PKV2 = POKEY2+7
;
.PAGE
.SBTTL POKEY ZERO PAGE VARIABLES
.SBTTL *** D-PAGE STARTING ADDRESS
.DPAGE DPRAM/100 ;DPAGE IS IN BLOCK RAM
;
;
;MISC. COMMON POKEY VARIABLES
;
; .BSECT
;FASV:: .BLKB 1 ;FREQUENCY ADJUST MSB SAVE (COMMON POKEY TEMP)
.GLOBB FASV
;VIU:: .BLKB 1 ;FLAGS TO TELL WHICH VOICES ARE IN USE
.GLOBB VIU
;---
..SVV = 0 ;?ANY VOICE SPLIT AT ALL?
.IF NE,..SV4!..SV3!..DRE
..SVV = 1 ;0==>16 BIT, 1==>SPLIT 8 BIT
.ENDC
;---
.IF NE,..DRE
;DREF:: .BLKB 1
.GLOBB DREF
..PRI =5 ;DYNAMIC RECONFIG NEEDS ALL 8 VOICES
.ENDC ;NE,..DRE
;===
.PAGE
.SBTTL POKEY VOICE VARIABLES
.ASECT
.SBTTL *** RAM STARTING ADDRESS
.=PMRAM
;
..NBPV =0 ;FIGURE OUT # OF BYTES PER VOICE
.MACRO .BPV .A1,.A2
'.A1 =..NBPV ;ASSIGN THE SYMBOL
..NBPV =..NBPV+1 ;BUMP BY AT LEAST ONE BYTE
.IIF NB,'.A2,..NBPV=..NBPV-1+'.A2 ;ELSE BUMP BY SPECIFIED SIZE
.ENDM
;===
;POKEY (EVERY VOICE)
.BPV OPTR,2 ;POINTER TO START OF CURRENT TUNE
;VOICE IN USE IF HI BYTE NON-ZERO
.IF NE,..AME
.BPV APTR,2 ;POINTER TO START OF CURRENT AMP. ENVELOPE
.ENDC
.IF NE,..FRE
.BPV FPTR,2 ;POINTER TO START OF CURRENT FREQ. ENVELOPE
.ENDC
.BPV ONOTE,2 ;CURRENT OUTPUT NOTE COUNT
.BPV ODUR,2 ;CURRENT OUTPUT DURATION REMAINING
.BPV VVOL ;MEDIAN VOICE VOLUME
.BPV VSEQ ;VOICE DURATION SEQUENCE #
.BPV ORATE ;NEG OF CURRENT OUTPUT RATE (BIGGER # = SHORTER DUR.)
.BPV OKEY ;CURRENT KEY OFFSET
.IF NE,..SCK
.BPV OCHK ;CHECK MASK FOR ALIGNMENT OF DIFFERENT VOICES
.ENDC
.BPV VAC ;VOICE AMPLITUDE CONTROL BITS
.IF NE,..SYM
.BPV VSF ;VOICE SYNTH. MODE FLAG
.BPV VSA,2 ;VOICE SYNTH. MODE FREQ. ADJUST
.ENDC
.BPV OPTSV,2 ;OUTPUT POINTER SUB-PHRASE SAVE
.BPV OPTLL,2 ;OUTPUT POINTER LOOP SAVE
.BPV VLC ;LOOP COUNTER
.IF NE,..CNT
.BPV VCNT ;NOTE COUNTER
.ENDC
.BPV OPTRET,2 ;RETURN ADDRESS FROM GOSUB
;===
VOICE:: ;RAM VOICE BLOCKS
;
VOICE1: .BLKB ..NBPV ;POKEY (VOICE 1)
;
VOICE2: .BLKB ..NBPV ;POKEY (VOICE 2)
;
VOICE3: .BLKB ..NBPV ;POKEY (VOICE 3 OR 3A)
;
VOICE4: .BLKB ..NBPV ;POKEY (4 OR VOICE 4A)
;
.IF EQ,..SV4 ;IF VOICE 4 NOT SPLIT..
;
;*** NON-SPLIT 16 BIT VOICE 4
;
.IF GE,..PRI-2 ;?NON-SPLIT 16 BIT PRIORITY 2 VOICE 5?
VOICE5: .BLKB ..NBPV
.ENDC
.IF GE,..PRI-3 ;?NON-SPLIT 16 BIT PRIORITY 3 VOICE 6?
VOICE6: .BLKB ..NBPV
.ENDC
.IF GE,..PRI-4 ;?NON-SPLIT 16 BIT PRIORITY 4 VOICE 7?
VOICE7: .BLKB ..NBPV
.ENDC
.IF GE,..PRI-5 ;?NON-SPLIT 16 BIT PRIORITY 5 VOICE 8?
VOICE8: .BLKB ..NBPV
.ENDC
;---
.IFF ;*** SPLIT 8 BIT VOICE 4
;
VOICE5: .BLKB ..NBPV ;SPLIT 8 BIT PRIORITY 1 VOICE 5
;
.IF GE,..PRI-2 ;?SPLIT 8 BIT PRIORITY 2 VOICE 6?
VOICE6: .BLKB ..NBPV
.ENDC
.IF GE,..PRI-3 ;?SPLIT 8 BIT PRIORITY 3 VOICE 7?
VOICE7: .BLKB ..NBPV
.ENDC
.IF GE,..PRI-4 ;?SPLIT 8 BIT PRIORITY 4 VOICE 8?
VOICE8: .BLKB ..NBPV
.ENDC
.ENDC ;EQ,..SV4
;---
;VOICE 3B STORAGE
;
.IF NE,..SV3 ;IF VOICE 3B (VOICE 8) ENABLED..
VOICE8: .BLKB ..NBPV
.ENDC
;---
VOICEZ:: ;END OF RAM VOICE BLOCKS
;===
;---
VSIZE== ..NBPV ;RAM SIZE PER VOICE
;---
.IRPC VNUM,<12345678> ;ASSIGN SPECIAL GLOBALS
.IF DF,VC'VNUM
OPTR'VNUM== OPTR+VOICE'VNUM ;POINTER TO THE START OF THE CURRENT TUNE/SOUND
VIU'VNUM== OPTR+VOICE'VNUM ;NON-ZERO SAYS THE VOICE IS IN USE
.IF NE,..CNT
VCNT'VNUM== VCNT+VOICE'VNUM ;NOTE COUNTER
.ENDC ;NE,..CNT
.ENDC ;DF,VC'VNUM
.ENDR
;===
.PAGE
.SBTTL VOICE PARAMETERS
;---
;MACRO TO GENERATE TABLED PARAMETERS
;
; VNUM VOICE NUMBER FROM 1 THRU 8
; POKOUT HARDWARE POKEY FREQ ADDRESS TO USE (e.g. PKFL1,PKFH3,PKFH4)
; DURING NORMAL USE
; SIZE WHAT BIT SIZE THE VOICE IS. (8 OR 16)
; 8 IMPLIES SPLIT VOICE, 16 IMPLIES FULL MUSIC VOICE
; DROUT WHEN DYNAMICALLY RECONFIGURED, USE THIS HARDWARE POKEY
; ADDRESS INSTEAD OF POKOUT.
; MPRI PRIORITY MASK. USE VC* IF OTHER BETTER PRIORITY VOICES.
; IF BEST PRIORITY, USE 0.
;
.MACRO .TVC VNUM,POKOUT,SIZE,DROUT,MPRI
VC$IZE =0 ;TABLE STARTS WITH NO ENTRIES
;---
TVC'VNUM: ;LABEL THIS DESCRIPTOR BLOCK
VC$'VNUM=TVC'VNUM-TVC ; AND ITS OFFSET INTO TABLE
;---
VC$RAM =VC$IZE ;POINTER TO VOICE'S RAM
VC$IZE =2+VC$IZE
.WORD VOICE'VNUM
;---
VC$BIT =VC$IZE ;BIT MASK FOR THIS VOICE
VC$IZE =1+VC$IZE
.BYTE VC'VNUM ;VOICE1=1 THRU VOICE8=80
;---
VC$PKF =VC$IZE ;BASE POINTER INTO HARDWARE POKEY
VC$IZE =2+VC$IZE
.WORD 'POKOUT
;---
.IF NE,..SV4!..SV3 ;?VOICES NORMALLY SPLIT?
VC$SVF =VC$IZE ;1 FOR SPLIT VOICE, 0 FOR FULL 16 BIT
VC$IZE =1+VC$IZE
.IIF NE,<SIZE-8>*<SIZE-16>,.ERROR ONLY 8 OR 16 BIT CHANNELS ALLOWED
.IF EQ,SIZE-8
.BYTE 1 ;SPLIT VOICE (ONLY 8 BITS)
.IFF ;ELSE SIZE IS 16
.BYTE 0 ;FULL UNSPLIT 16 BIT VOICE
.ENDC ;EQ,SIZE-8
.ENDC ;NE,..SVV
;---
.IF GE,..PRI-2 ;?PRIORITIES IN USE?
VC$PRI =VC$IZE ;PRIORITY MASK
VC$IZE =1+VC$IZE
.BYTE 'MPRI
.ENDC ;GE,..PRI-2
;---
.IF NE,..DRE ;?DYNAMICALLY RECONFIGURED?
VC$PKD =VC$IZE ;THEN USE THIS POKEY ADDRESS INSTEAD
VC$IZE =2+VC$IZE
.WORD 'DROUT
.ENDC ;NE,..DRE
;---
.ENDM
;===
.CSECT TVC ;TABLE OF VOICE PARAMETERS
TVC: ;
;POKEY (VOICE 1)
.TVC 1,PKFL1,16 PKFL1 0
;
;POKEY (VOICE 2)
.TVC 2,PKFL2,16 PKFL2 0
;
;POKEY (VOICE 3 OR 3A)
.TVC 3,PKFL3,16 PKFL3 0
;
.IF EQ,..SV4 ;IF VOICE 4 NOT SPLIT..
;
;*** NON-SPLIT 16 BIT VOICE 4
.TVC 4,PKFL4,16 PKFL4 0
;
.IF GE,..PRI-2 ;?NON-SPLIT 16 BIT PRIORITY 2 VOICE 5?
.TVC 5,PKFL4,16 PKFH4 VC4
.ENDC
.IF GE,..PRI-3 ;?NON-SPLIT 16 BIT PRIORITY 3 VOICE 6?
.TVC 6,PKFL4,16 PKFH1 VC4!VC5
.ENDC
.IF GE,..PRI-4 ;?NON-SPLIT 16 BIT PRIORITY 4 VOICE 7?
.TVC 7,PKFL4,16 PKFH2 VC4!VC5!VC6
.ENDC
.IF GE,..PRI-5 ;?NON-SPLIT 16 BIT PRIORITY 5 VOICE 8?
.TVC 8,PKFL4,16 PKFH3 VC4!VC5!VC6!VC7
.ENDC
;---
.IFF ;SPLIT VOICE 4
;
;*** SPLIT 8 BIT VOICE 4
.TVC 4,PKFL4,8 PKFL4 0
;
.TVC 5,PKFH4,8 PKFH4 0
;
.IF GE,..PRI-2 ;?SPLIT 8 BIT PRIORITY 2 VOICE 6?
.TVC 6,PKFH4,8 PKFH1 VC5
.ENDC
.IF GE,..PRI-3 ;?SPLIT 8 BIT PRIORITY 3 VOICE 7?
.TVC 7,PKFH4,8 PKFH2 VC5!VC6
.ENDC
.IF GE,..PRI-4 ;?SPLIT 8 BIT PRIORITY 4 VOICE 8?
.TVC 8,PKFH4,8 PKFH3 VC5!VC6!VC7
.ENDC
.ENDC ;EQ,..SV4
;---
;VOICE 3B STORAGE
;
.IF NE,..SV3 ;IF VOICE 3B (VOICE 8) ENABLED..
.TVC 8,PKFH3,8 PKFH3 0
.ENDC
;---
TVCZ: ;END OF VOICE RAM BLOCKS
;===
.PAGE
.SBTTL MACRO DEFINITIONS
;
;.TUNE
; SET UP ADDR. OF TUNE AND SET FLAG TO START PLAYING
; 1) CALL APPROPRIATE PKCUT TO INIT VOICE, SETUP Y DESCRIPTOR
; 2) B:= WORD OFFSET INTO TUNE TABLE DIRECTORY
; 3) CALL NWTUNE TO SETUP NEW STARTING VALS
;---
.MACRO .TUNE VNUM,TNUM ;POKEY VOICE (1-8), TUNE #
.TUNE. \VNUM,TNUM ;SLASH USED FOR GENERATING LABELS
.ENDM
;---
.MACRO .TUNE. VNUM,TNUM ;POKEY VOICE (1-8), TUNE #
JSR PKCUT'VNUM ;CLEAR OUT AND INIT THIS VOICE
LDB #<2*'TNUM'.>
JSR NWTUNE
.ENDM
;===
PMSF2:: ;SPECIAL EFFECT(PROTON TORPEDO)
.TUNE 1,1
.TUNE 2,2
.TUNE 3,3
.TUNE 4,4
RTS
;---
PMBEN:: ;BENS THEME (START OF TOWER)
.TUNE 1,7
.TUNE 2,8
.TUNE 3,9
.TUNE 4,10
RTS
;---
PMCNT:: ;CANTENA (HI SCORE)
.TUNE 1,11
.TUNE 2,12
.TUNE 3,13
.TUNE 4,14
RTS
;---
PMEND:: ;(AFTER DETH STAR EXPLOSION)
.TUNE 1,15
.TUNE 2,16
.TUNE 3,17
.TUNE 4,18
RTS
;---
PMREB:: ;REBEL THEME (TRANSITION INTO TRENCH)
.TUNE 1,19
.TUNE 2,20
.TUNE 3,21
.TUNE 4,22
RTS
;---
PMRRP:: ;REBEL THEME WITH REPEATS(TRENCH WITH REPEATS)
.TUNE 1,23
.TUNE 2,24
.TUNE 3,25
.TUNE 4,26
RTS
;---
PMTH5:: ;MAIN THEME (START OF GAME)
.TUNE 1,27
.TUNE 2,28
.TUNE 3,29
.TUNE 4,30
RTS
;---
PM4TH:: ;BATTLE MUSIC IN FOURTHS
.TUNE 1,31
.TUNE 2,32
.TUNE 3,33
.TUNE 4,34
RTS
;---
PMTHB:: ;THEME TYPE B
.TUNE 1,35
.TUNE 2,36
.TUNE 3,37
.TUNE 4,38
RTS
;---
PMDES:: ;DESCENT TO DETH STAR
.TUNE 1,39
.TUNE 2,40
.TUNE 3,41
.TUNE 4,42
RTS
;===
PMDAR:: ;LORD VADER'S THEME
.TUNE 1,43
.TUNE 2,44
.TUNE 3,45
.TUNE 4,46
RTS
;===
PMTST:: ;MUSIC CHANNEL TEST TONES
.TUNE 3,47 ;CHANNEL #S CHANGED TO BE IN ORDER OF
;POKEYS ON BOARD (WAS 1,2,3,4, NOW 3,4,1,2)
.TUNE 4,48
.TUNE 1,49
.TUNE 2,50
RTS
;===
.PAGE
.SBTTL *** YOUR OWN RPM SOUND TEST ROUTINE
;
;START OF RPM DRIVER TEST PROGRAM
;
;
..TST = 0 ;SELF-TEST MODE.. (0 = OPERATIONAL MODE)
;
.CSECT RPM
.PAGE
.SBTTL RPM POKEY INITIALIZATION
;
;ISND
; SUB. TO INITIALIZE POKEY FOR USE
;
ISND:: LDA #0 ;SET UP FOR POKEY VOICE 1
STA PKI1 ;ALSO, INIT POKEY DEVICES
STA PKI2
.IF NE,..DRE
STA DREF ;CLEAR DYN. RECON. FLAG
.ENDC ;NE,..DRE
;---
;INIT ALL DEFINED VOICES
.IRPC VNUM,<12345678>
.IF DF,VC$'VNUM
JSR PKCUT'VNUM ;CUTOFF THIS VOICE AND INIT IT
.ENDC
.ENDR
;---
LDA #3
STA PKI1 ;OUTPUT SECOND BYTE TO POKEY INIT.
STA PKI2
.IF EQ,..SV3
.IF EQ,..SV4
LDA #78 ;VOICES 3 AND 4 ARE 16 BIT EACH
.IFF
LDA #50 ;VOICE 3 IS 16 BIT, VOICE 4 SPLIT INTO 2 8 BIT
.ENDC
.ENDC
;---
.IF NE,..SV3
.IF EQ,..SV4
LDA #28 ;VOICE 3 IS 2 8 BIT CHANNELS, VOICE 4 IS 16 BIT
.IFF
LDA #0 ;4 CHANNELS SEPERATE (3 AND 4 ARE DUAL 8 BIT)
.ENDC
.ENDC
;---
STA PKC1
LDA #78
STA PKC2 ;TIE CHANNEL 2 TO 1, 4 TO 3
;---
RTS
.PAGE
.IF NE,..DRE
;
;RCS,RCN
; SET OR RESET DYNAMIC RECONFIGURATION FLAG AND INIT ALL VOICES
;
RCS::
LDA #0 ;ALL CHANNELS SEPERATE
STA PKC1
STA PKC2
LDA #1 ;SET FLAG THAT ARE ALL 8-BIT VOICES NOW
BNE RECON
;
;RESET POKEYS BACK TO DEFAULT CONFIG..
RCN:: ;---
.IF EQ,..SV3
.IF EQ,..SV4
LDA #78 ;VOICES 3 AND 4 ARE 16 BIT EACH
.IFF
LDA #50 ;VOICE 3 IS 16 BIT, VOICE 4 SPLIT INTO 2 8 BIT
.ENDC
.ENDC
;---
.IF NE,..SV3
.IF EQ,..SV4
LDA #28 ;VOICE 3 IS 2 8 BIT CHANNELS, VOICE 4 IS 16 BIT
.IFF
LDA #0 ;4 CHANNELS SEPERATE (3 AND 4 ARE DUAL 8 BIT)
.ENDC
.ENDC
STA PKC1
;---
LDA #78
STA PKC2 ;TIE CHANNEL 2 TO 1, 4 TO 3
;---
CLRA ;CLEAR FLAG (NORMAL CONFIGURATION)
;===
RECON:
STA DREF ;INDICATE CURRENT CONFIGURATION
;---
;RESET/INIT ALL VALID VOICES (PARANOID)
.IRPC VNUM,<12345678>
.IF DF,VC$'VNUM
BSR PKCUT'VNUM
.ENDC ;DF,VC$'VNUM
.ENDR
;---
RTS
.ENDC ;NE,..DRE
;===
.IRPC VNUM,<12345678>
.IF DF,VC$'VNUM
PKCUT'VNUM::
LDA #VC$'VNUM
BRA POKVI ;INIT THIS VOICE
.ENDC ;DF,VC$'VNUM
.ENDR
;===
;
;POKVI,Y
; SUB. TO INIT A POKEY VOICE
; POKVI:
; A:=OFFSET INTO VOICE DESCRIPTOR TABLE
; POKVIY:
; Y:=POINTER TO THIS VOICE'S DESCRIPTOR TABLE
;
POKVI:
LDX #TVC ;BASE OF VOICE
LEAY A(X) ;Y-->VOICE DESCRIPTOR TABLE
POKVIY: ;Y SETUP BY NOW
LDU VC$RAM(Y) ;U-->VOICE RAM BLOCK
;;; ;NOW IS MAINLINE ROUTINE
;;; ;AVOIDING IRQ INTERACTIONS
;;;
LDA VC$BIT(Y) ;BIT FOR THIS VOICE
COMA ;PREPARE TURNOFF MASK
ANDA VIU
STA VIU ;TURN OFF VIU BIT
;---
LDA #7
STA VVOL(U) ;SET UP TO MEDIAN VOLUME
LDA #-64. ;REMEMBER TO PRE-NEGATE
STA ORATE(U) ;SET UP TO MED. RATE
LDA #0A0 ;DEFAULT TO PURE TONES
STA VAC(U) ;STORE AS VOICE CONTROL BITS
;---
LDD #0 ; CLEARING OUT VARIABLES
STD OPTR(U) ;CLEAR VOICE IN USE FLAG(HI BYTE POINTER)
STA OKEY(U) ;SET BACK TO UNUSED KEY
STA VSEQ(U) ;CLEAR ENV. SEQ. COUNT
STD ODUR(U)
STA VLC(U) ;CLEAR LOOP COUNT
STD OPTSV(U) ;CLEAR SUB-PHRASE POINTER (FLAG)
;---
.IF NE,..SYM
STA VSF(U) ;CLEAR SYNTH. MODE
STD VSA(U) ;CLEAR SYNTH. MODE ADJUSTMENT
.ENDC ;NE,..SYM
;---
.IF NE,..CNT ;IF NOTE COUNTER ENABLED..
STA VCNT(U) ;CLEAR NOTE COUNT
.ENDC ;NE,..CNT
;---
; END OF CLEARING OUT VARIABLES
.IF NE,..AME!..FRE
LDD FETAB
.IF NE,..AME
STD APTR(U)
.ENDC ;NE,..AME
.IF NE,..FRE
STD FPTR(U)
.ENDC ;NE,..FRE
.ENDC ;NE,..AME!..FRE
;---
.IF NE,..SCK ;IF SYNC. CHECK ENABLED..
LDA #0FF
STA OCHK(U) ;CLEAR CURRENT CHECK MASK
.ENDC ;NE,..SCK
;===
;TURN OFF POKEY AMPLITUDE
LDX VC$PKF(Y) ;SELECT THE POKEY OUTPUT PORT
.IF NE,..DRE
LDB DREF
BEQ 62$ ;?DYNAMICALLY RECONFIG'D?
LDX VC$PKD(Y) ;THEN USE DRE PORT INSTEAD
CLR 1(X) ;ONLY DO LO 8 BITS
RTS
.ENDC ;NE,..DRE
62$: ;---
.IF NE,..SV4!..SV3
LDB VC$SVF(Y)
BEQ 67$ ;B IF REGULAR VOICE IS SPLIT
CLR 1(X) ;OUTPUT 8 BIT CHANNEL
RTS
.ENDC ;NE,..SV4!..SV3
67$: ;---
CLR 3(X) ;AMPLITUDE GOES IN SECOND CHANNEL FOR 16 BIT
RTS
;===
;
; NWTUNE
; SETS UP NEW TUNE INTO GIVEN VOICE
;
; MUST BE PRECEEDED BY PKCUT TO CLEAR OUT
; ANY OLD VOICE AND SETUP Y-->DESCRIPTOR TABLE
;
; B:= TUNE # WORD OFFSET INTO TUNE TABLE
;
NWTUNE:
LDX #TUNTAB ;BASE OF TUNE DIRECTORY
ABX ;ALLOW 128 WORD ENTRIES
LDD 0(X) ;POINTER TO TUNE
LDX VC$RAM(Y) ;X-->VOICE RAM BLOCK
STD OPTR(X)
LDA VIU ;SET VOICE IN USE BIT
ORA VC$BIT(Y) ;THATS OUR BIT
STA VIU
RTS
;===
.PAGE
.SBTTL INTERRUPT ROUTINES, PKDR, POKOUT
;
;PKDR
; POKEY 4MS INTERRUPT DRIVER
;
PKDR::
LDA $INTCT ;WHICH POKEY TO UPDATE THIS FRAME
LSRA
BCC 10$ ;IF VOICE 2 THIS FRAME
LDA #VC$1
BSR POKOUT ;OUTPUT TO POKEY (VOICE 1)
LDA #VC$3
BSR POKOUT ;OUTPUT TO POKEY (VOICE 3)
;---
.IF DF,VC$5
LDA #VC$5 ;OUTPUT VOICE 5 IF IT EXISTS
BSR POKOUT
.ENDC ;DV,VC$5
.IF DF,VC$7
LDA #VC$7 ;OUTPUT VOICE 7 IF IT EXISTS
BSR POKOUT
.ENDC ;DF,VC$7
;---
RTS
;===
10$: ;IF HERE, TIME TO OUTPUT VOICE 2
LDA #VC$2
BSR POKOUT ;OUTPUT TO POKEY (VOICE 2)
LDA #VC$4
BSR POKOUT ;OUTPUT TO POKEY (VOICE 4 OR 4A)
;---
.IF DF,VC$6
LDA #VC$6 ;OUTPUT VOICE 6 IF DEFINED
BSR POKOUT
.ENDC ;DF,VC$6
;---
.IF DF,VC$8
LDA #VC$8 ;OUTPUT VOICE 8 IF IT EXISTS
BSR POKOUT
.ENDC ;DF,VC$8
;---
RTS
;===
;
;POKOUT
; COMMON OUTPUT ROUTINE FOR ALL POKEY VOICES
; A:= OFFSET INTO CURRENT VOICE DESCRIPTOR TABLE
;
POKOUT: ;---
LDX #TVC ;BASE OF VOICE DESCRIPTOR TABLE
LEAY A(X) ;Y--> THIS VOICE'S DESCRIPTOR TABLE
LDU VC$RAM(Y) ;U--> RAM BLOCK FOR THIS VOICE
;---
LDA OPTR(U) ;?VOICE IN USE? (INUSE IF HI POINTER SET)
BNE 3$ ;B THEN PROCESS IT
RTS ;ELSE, RETURN
3$: ;---
;SEE IF TIME TO UPDATE CURRENT NOTE
INC VSEQ(U) ;INC. ENVELOPE SEQ. COUNT
BNE 5$ ;IF NOT AT END OF ENV. YET
DEC VSEQ(U) ;ELSE, KEEP AT FINAL ENV. COUNT
5$: ;---
LDB ORATE(U) ;PRE-NEGATED RATE (8 BITS, SIGN IMPLIED)
LDA #0FF ;EXTEND IMPLIED SIGN
ADDD ODUR(U) ;BY ADDING NEGATIVE OF CURRENT RATE,
STD ODUR(U) ;UPDATE CURRENT NOTE DURATION
LBPL POKSN ;B IF STILL SAME NOTE
;---
POKNL: ;IF HERE, HAVE A NEW NOTE TO PLAY
LDX OPTR(U) ;GET THIS NOTE IN TUNE
LDB (X)++ ;BUMP TO NEXT INSTRUCTION
STX OPTR(U)
TSTB ;CHECK THE OPCODE(FIRST BYTE)
LBMI PKFUN ;B IF A FUNCTION
;---
BEQ 9$ ;?SOUNDFUL NOTE?(NOT A REST)
ADDB OKEY(U) ;THEN POSITION NOTE TO CURRENT KEY
9$: ;---
.IF NE,..SVV ;ANY 8 BIT PORTS EVER EXIST
.IF NE,..SV3!..SV4 ;8 BIT DUE TO SPLIT VOICE
.IF NE,..DRE ;OR DUE TO DYNAMIC RECONFIG
LDA VC$SVF(Y) ;SPLIT VOICE OR DYN RECONF
ORA DREF
.IFF ;NE,..DRE
LDA VC$SVF(Y) ;SPLIT VOICE ONLY, NO DYNAM RECONF
.ENDC ;NE,..DRE
.IFF ;NE,..SV3!..SV4
LDA DREF ;ELSE NO SPLIT VOICE, BUT HAVE DYN RECONF
.ENDC ;NE,..SV3!..SV4
BEQ 68$ ;B IF FULL 16 BIT PORT
CLRA ;ELSE USE 8 BIT VALUE DIRECTLY
BRA 69$
.ENDC ;NE,..SVV
68$: ;---ELSE IS 16 BIT -- CALC MUSIC NOTE
LSLB ;WORD OFFSET
LDX #NOTTAB ;BASE OF NOTE CONVERSION TABLE
ABX ;UNSIGNED, FULL RANGE
;---
.IF NE,..SYM ;IF SYNTH. MODE ENABLED
LDD ONOTE(U) ;COMPUTE DELTA BETWEEN NEW AND OLD
SUBD 0(X) ;SUB NEW NOTE VALUE
STD VSA(U) ;SAVE DELTA FOR SYNTH MODE
.ENDC ;NE,..SYM
;---
LDD 0(X) ;GET NOTE VALUE
69$: ;---
STD ONOTE(U) ;STORE AS OUTPUT NOTE
;---
LDX OPTR(U) ;GET DURATION OF CURRENT NOTE
LDA -1(X) ;(WE PREVIOUSLY BUMPED POINTER TO NEXT NOTE)
BNE 30$ ;?AT FINAL NOTE?
LDD OPTSV(U) ;CHECK FOR ENDING SUB-PHRASE OR MAIN TUNE
LBEQ POKVIY ;B END OF MAIN TUNE, INIT THIS VOICE
STD OPTR(U) ;IF HERE, RETURNING FROM SUB-PHRASE
LDD #0
STD OPTSV(U) ;RESET SUB-PHRASE FLAG
JMP POKNL ;J GET A NOTE GOING
;---
30$: ;---STILL HAVE A NEW NOTE, GET AND STORE DURATION
;A:=DURATION (SECOND BYTE)
;X-->FOLLOWING INSTR
CLRB ;PREPARE LSB
LSRA ;SHIFT AND REMOVE LSB (TIED NOTE FLAG)
LSRA ;MULT. DUR * 128 (CARRY IS MSB OF LSB BYTE)
RORB ;ROTATE INTO LSB'S
ADDD ODUR(U) ;SUBTRACT ANY OVERRUN FROM PREV. NOTE
; SUBD #0FFFF ;(?6502 VERSION)ADD 1 TO COMPENSATE FOR SUBTRACT TEST
STD ODUR(U)
;---
.IF NE,..CNT ;IF NOTE COUNTER ENABLED..
INC VCNT(U) ;INC. NOTE COUNT
.ENDC ;NE,..CNT
;---
LDA -1(X) ;GET BACK DURATION
ANDA #01 ;TEST IF NOTE IS TIED
BNE 50$ ;?NOTE NOT TIED?
STA VSEQ(U) ;CLEAR SEQ. COUNTER FOR NOT TIED NOTE
;---
.IF NE,..SYM
CLRB ;AND NO SYNTH ADJUST FOR NOT TIED
STD VSA(U)
.ENDC ;NE,..SYM
;---
.IF NE,..PRI
LDA VIU ;TEST IF THIS IS NOT HIGH PRIORITY
ANDA VC$PRI(Y) ;IN USE BITS VS PRIORITY MASK
; BEQ PKNOFF ;IF THIS IS HIGH PRIORITY FOR THIS VOICE
BEQ POKSN ;LET AMPLITUDE ENVELOPE DO PRE-GAP
.IF NE,..DRE
LDA DREF
; BNE PKNOFF
BNE POKSN ;LET AMPLITUDE ENVELOPE DO PRE-GAP
.ENDC ;NE,..DRE
RTS ;ELSE, DON'T UPDATE POKEY WITH THIS VOICE
.IFF
; JMP PKNOFF ;J TURN OFF POKEY BETWEEN NOTES (NOT TIED)
JMP POKSN ;LET AMPLITUDE ENVELOPE DO PRE-GAP
.ENDC ;NE,..PRI
50$: ;===
;NOTE IS TIED, TEST FOR SYNTH MODE ON
.IF NE,..SYM
LDA VSF(U) ;TEST SYNTH MODE FLAG
BNE POKSN ;B IF SYNTH MODE ON
;NOTE IS TIED AND SYNTH MODE NOT ON, CLEAR FREQ. ADJUSTMENT
CLRB
STD VSA(U) ;CLEAR SYNTH. ADJUST
.ENDC ;NE,..SYM
;===
POKSN: ;HAVE SAME NOTE AS LAST TIME, PLAY IT WITH ENVELOPES
.IF NE,..PRI ;IF PRIORITY OF CHANNEL 4 ENABLED..
LDA VIU
ANDA VC$PRI(Y) ;IN USE FLAGS VS PRIORITY MASK
BEQ 61$ ;IF AT HIGHEST PRIORITY, PLAY NOTE
.IF NE,..DRE
LDA DREF
BNE 61$ ;ELSE IF RECONFIGURED, THEN ALL ARE AT BEST PRIORITY
.ENDC ;NE,..DRE
RTS ;ELSE, RETURN WITHOUT POKEY UPDATE
.ENDC ;NE,..PRI
61$: ;---
.IF NE,..SYM
LDA $INTCT
ANDA #06 ;?TIME TO CHANGE ADJUST?
BNE 3$
ASR VSA(U) ;DIVIDE SYNTH ADJUST BY 2
ROR VSA+1(U) ; SO ADD 1/2 AS MUCH EACH TIME
.ENDC ;NE,..SYM
3$: ;---FIRST ADD FREQ. ENV. TO NOTE FREQ.
.IF NE,..FRE ;IF FREQ. ENV. ENABLED..
LDB VSEQ(U) ;GET FREQ. ENV. SEQ. #
LSRB ;FOR 128 BYTE TABLE
LDX FPTR(U) ;BASE OF FREQUENCY TABLE
ABX
LDB 0(X) ;GET CURRENT FREQ. ENV. SETTING
SEX ;CONVERT TO 16 BIT
;---
.IF NE,..DRE ;IF DRE'D TO 8 BITS
TST DREF ;MUSIC FREQ IS *8, SOUNDS ARE AS IS.
BNE 78$ ;B IF RECONFIG'D TO 8 BITS
.ENDC ;NE,..DRE
;---
.IF NE,..SV4!..SV3 ;IF SPLIT VOICE ENABLED..
TST VC$SVF(Y) ;?16 BIT MUSIC VOICE?
BNE 78$ ;B IF A SPLIT VOICE
.ENDC ;NE,..SVV
;---
LSLB ;MULT FREQ ENV *8 FOR MUSIC
ROLA
LSLB
ROLA
LSLB
ROLA
78$: ;---
ADDD ONOTE(U) ;ADD IN THE NOTES FREQUENCY
.IFF ;NO FREQ ADJUSTMENT
LDD ONOTE(U) ;GET OUR FREQUENCY
.ENDC ;NE,..FRE
;---
.IF NE,..SYM ;IF SYNTH. MODE ENABLED..
ADDD VSA(U) ;ADD SYNTH ADJUST TO SUM OF NOTE FREQ. AND ENV.
.ENDC ;NE,..SYM
;===
LDX VC$PKF(Y) ;SELECT THE POKEY OUTPUT PORT
.IF NE,..DRE
TST DREF
BEQ 62$ ;?DYNAMICALLY RECONFIG'D?
LDX VC$PKD(Y) ;THEN USE DRE PORT INSTEAD
BRA 63$ ;AND ONLY DO LO 8 BITS
.ENDC ;NE,..DRE
62$: ;---
.IF NE,..SV4!..SV3
TST VC$SVF(Y)
BNE 63$ ;B IF REGULAR VOICE IS SPLIT
.ENDC ;NE,..SV4!..SV3
;---
STA 2(X) ;OUTPUT MSB OF 16 BIT
63$: ;---
STB 0(X) ;OUTPUT LO 8 BIT
;===
LDD ONOTE(U) ;CHECK FOR A REST(NO OUTPUT)
BNE PKNON ;IF NOT A REST
;---
PKNOFF: ;HAVE A REST OR NOTE IS OFF, SET UP TO FORCE OUTPUT TO OFF
LDA #0F0
STA FASV ;STORE MASK TO ZERO OUT AMPLITUDE
BRA PKNC
;---
PKNON: ;NOW OUTPUT AMPLITUDE, THIS VOICE
LDA #0FF ;SET UP MASK TO PERMIT CURRENT VOLUME
STA FASV
PKNC: ;---
.IF NE,..AME ;IF AMP. ENVELOPE ENABLED..
LDB VSEQ(U) ;;DIVIDE ENV. SEQ # BY 8 (32 BYTE ENV. TABLE)
;USE STRAIGHT, LIMIT AT 31(QUARTER SECOND)
CMPB #31.
IFHS
LDB #31.
ENDIF
LDX APTR(U)
LDA B(X) ;GET CURRENT VOLUME ENV. ADJ.
ADDA VVOL(U)
BPL 5$ ;IF NUM NOT .LT. 0
CLRA ;ELSE, SET VOLUME TO OFF
5$: ;---
CMPA #10 ;CHECK FOR VOLUME TOO LARGE
BLT 6$ ;IF VOLUME OK
LDA #0F ;ELSE, SET TO MAX.
6$:
.IFF ;IF AMP. ENV. DISABLED, JUST GET VOLUME
LDA VVOL(U)
.ENDC ;NE,..AME
;---
ORA VAC(U) ;SET UP CURRENT VOICE CONTROL
ANDA FASV ;MASK WITH NOTE ON/OFF SETTING
LDX VC$PKF(Y) ;SELECT THE POKEY OUTPUT PORT
.IF NE,..DRE
LDB DREF
BEQ 62$ ;?DYNAMICALLY RECONFIG'D?
LDX VC$PKD(Y) ;THEN USE DRE PORT INSTEAD
STA 1(X) ;ONLY DO LO 8 BITS
RTS ;EXIT ALL DONE
.ENDC ;NE,..DRE
62$: ;---
.IF NE,..SV4!..SV3
LDB VC$SVF(Y)
BEQ 67$ ;B IF REGULAR VOICE IS SPLIT
STA 1(X) ;OUTPUT 8 BIT CHANNEL
RTS ;EXIT ALL DONE
.ENDC ;NE,..SV4!..SV3
67$: ;---
STA 3(X) ;AMPLITUDE GOES IN SECOND CHANNEL FOR 16 BIT
RTS ;EXIT ALL DONE
;===
PKFUN: ;HAVE A FUNCTION, NOT A NOTE..
;B:= OPCODE
LDX OPTR(U)
LDA -1(X) ;A:= DATA VALUE
LSLB
CMPB #PKDTZ-PKDT
LBHS POKNL ;NULL OUT IF NOT IN RANGE
LDX #PKDT ;DISPATCH BASE
JMP @B(X) ;GOTO ROUTINE
;===
PKDT: ;DISPATCH TABLE
.WORD PKARAT,PKCRAT
.WORD PKAAMP,PKCAMP
.WORD PKAKEY,PKCKEY
.IF NE,..FRE
.WORD PKFRQE
.IFF
.WORD POKNL ;IF FREQ. ENV. DISABLED..
.ENDC
.IF NE,..AME
.WORD PKAMPE
.IFF
.WORD POKNL ;AMPLITUDE DISABLED
.ENDC
.IF NE,..SCK
.WORD PKCHK,PKRCHK
.IFF
.WORD POKNL,POKNL
.ENDC
.WORD PKCON,PKPKC
.IF NE,..SYM
.WORD PKSYN
.IFF
.WORD POKNL
.ENDC
.WORD PKCPH
.WORD PKSL,PKEL
.WORD PKGOSB,PKRET
PKDTZ:
.PAGE
.IF NE,..SCK ;IF SYNC. CHECK ENABLED
PKCHK: ;HAVE A TIMING CHECK FUNCTION, WAIT FOR OTHER VOICES TO CATCH UP
LDB VC$BIT(Y) ;GET OUR BIT MASK
COMB
STB OCHK(U) ;SET UP FOR OTHERS TO SYNC ON
.IRPC VNUM,<12345678>
.IF DF,TVC'VNUM
ANDA OCHK+TVC'VNUM ;TEST IF OTHERS SYNCED UP AGAIN
.ENDC ;DF,TVC'VNUM
.ENDR
LBEQ POKNL ;B IF ALL CHECK POINTS REACHED ALREADY
;---
;THIS VOICE AHEAD OF REST, WAIT FOR OTHERS
LDD OPTR(U) ;BACK UP THE RPM PC
SUBD #2
STD OPTR(U) ;KEEP DOING THIS TILL WE GET IT RIGHT
LDD #0
STD ODUR(U) ;CLEAR CURRENT DURATION(SO WILL BE NEW AGAIN)
RTS ;RETURN FROM POKEY DRIVER, THIS VOICE
;===
PKRCHK: ;RESET CHECK FLAG, THIS CHANNEL
LDA #0FF ;RESET MASK, THIS VOICE REACHED CHECK
STA OCHK(U)
JMP POKNL
.ENDC ;.NE,..SCK
;===
.IF NE,..AME ;IF AMP. ENV. ENABLED..
PKAMPE: ;HAVE AN AMPLITUDE ENV. FUNCTION
LSLA ;WORD POINTER
TFR A,B ;PREPARE FOR UNSIGNED 256 LENGTH ADD
LDX #AETAB ;BASE OF AMPLITUDE DIRECTORY
ABX
LDD 0(X) ;GET AMP POINTER
STD APTR(U)
JMP POKNL
.ENDC ;NE,..AME
;===