This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy paths1.sounddriver.asm
2728 lines (2415 loc) · 80.5 KB
/
s1.sounddriver.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
; ---------------------------------------------------------------------------
; Modified SMPS 68k Type 1b sound driver
; ---------------------------------------------------------------------------
; Constants
SMPS_TRACK_COUNT = (SMPS_RAM.v_track_ram_end-SMPS_RAM.v_track_ram)/SMPS_Track.len
SMPS_MUSIC_TRACK_COUNT = (SMPS_RAM.v_music_track_ram_end-SMPS_RAM.v_music_track_ram)/SMPS_Track.len
SMPS_MUSIC_FM_DAC_TRACK_COUNT = (SMPS_RAM.v_music_fmdac_tracks_end-SMPS_RAM.v_music_fmdac_tracks)/SMPS_Track.len
SMPS_MUSIC_FM_TRACK_COUNT = (SMPS_RAM.v_music_fm_tracks_end-SMPS_RAM.v_music_fm_tracks)/SMPS_Track.len
SMPS_MUSIC_PSG_TRACK_COUNT = (SMPS_RAM.v_music_psg_tracks_end-SMPS_RAM.v_music_psg_tracks)/SMPS_Track.len
SMPS_SFX_TRACK_COUNT = (SMPS_RAM.v_sfx_track_ram_end-SMPS_RAM.v_sfx_track_ram)/SMPS_Track.len
SMPS_SFX_FM_TRACK_COUNT = (SMPS_RAM.v_sfx_fm_tracks_end-SMPS_RAM.v_sfx_fm_tracks)/SMPS_Track.len
SMPS_SFX_PSG_TRACK_COUNT = (SMPS_RAM.v_sfx_psg_tracks_end-SMPS_RAM.v_sfx_psg_tracks)/SMPS_Track.len
SMPS_SPECIAL_SFX_TRACK_COUNT = (SMPS_RAM.v_spcsfx_track_ram_end-SMPS_RAM.v_spcsfx_track_ram)/SMPS_Track.len
SMPS_SPECIAL_SFX_FM_TRACK_COUNT = (SMPS_RAM.v_spcsfx_fm_tracks_end-SMPS_RAM.v_spcsfx_fm_tracks)/SMPS_Track.len
; ---------------------------------------------------------------------------
; Go_SoundTypes:
Go_SoundPriorities: dc.l SoundPriorities
; Go_SoundD0:
Go_SpecSoundIndex: dc.l SpecSoundIndex
Go_MusicIndex: dc.l MusicIndex
Go_SoundIndex: dc.l SoundIndex
Go_Modulation: dc.l ModulationIndex
; off_74010:
Go_PSGIndex: dc.l PSG_Index
dc.l $A0
dc.l UpdateMusic
Go_SpeedUpIndex: dc.l SpeedUpIndex
; ---------------------------------------------------------------------------
; PSG instruments used in music
; ---------------------------------------------------------------------------
PSG_Index:
dc.l PSG1, PSG2, PSG3
dc.l PSG4, PSG6, PSG5
dc.l PSG7, PSG8, PSG9
PSG1: binclude "sound/psg/psg1.bin"
PSG2: binclude "sound/psg/psg2.bin"
PSG3: binclude "sound/psg/psg3.bin"
PSG4: binclude "sound/psg/psg4.bin"
PSG5: binclude "sound/psg/psg5.bin"
PSG6: binclude "sound/psg/psg6.bin"
PSG7: binclude "sound/psg/psg7.bin"
PSG8: binclude "sound/psg/psg8.bin"
PSG9: binclude "sound/psg/psg9.bin"
ModulationIndex:
dc.b $D, 1, 7, 4
dc.b 1, 1, 1, 4
dc.b 2, 1, 2, 4
dc.b 8, 1, 6, 4
; ---------------------------------------------------------------------------
; New tempos for songs during speed shoes
; ---------------------------------------------------------------------------
SpeedUpIndex: dc.b 7 ; GHZ
dc.b $72 ; LZ
dc.b $73 ; MZ
dc.b $26 ; SLZ
dc.b $15 ; SYZ
dc.b 8 ; SBZ
dc.b $FF ; Invincibility
dc.b 5 ; Extra Life
even
; All songs after will use their music index pointer instead
; ---------------------------------------------------------------------------
; Music Pointers
; ---------------------------------------------------------------------------
MusicIndex:
ptr_mus81: dc.l Music81
ptr_mus82: dc.l Music82
ptr_mus83: dc.l Music83
ptr_mus84: dc.l Music84
ptr_mus85: dc.l Music85
ptr_mus86: dc.l Music86
ptr_mus87: dc.l Music87
ptr_mus88: dc.l Music88
ptr_mus89: dc.l Music89
ptr_mus8A: dc.l Music8A
ptr_mus8B: dc.l Music8B
ptr_mus8C: dc.l Music8C
ptr_mus8D: dc.l Music8D
ptr_mus8E: dc.l Music8E
ptr_mus8F: dc.l Music8F
ptr_mus90: dc.l Music90
ptr_mus91: dc.l Music91 ; Note the lack of a pointer for music $92
ptr_musend:
; ---------------------------------------------------------------------------
; Priority of sound. New music or SFX must have a priority higher than or equal
; to what is stored in v_sndprio or it won't play. If bit 7 of new priority is
; set ($80 and up), the new music or SFX will not set its priority -- meaning
; any music or SFX can override it (as long as it can override whatever was
; playing before). Usually, SFX will only override SFX, special SFX ($D0-$DF)
; will only override special SFX and music will only override music.
; ---------------------------------------------------------------------------
; SoundTypes:
SoundPriorities:
dc.b $80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80 ; $81
dc.b $80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$70 ; $90
dc.b $70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70 ; $A0
dc.b $70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70 ; $B0
dc.b $70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$70,$80 ; $C0
dc.b $80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80 ; $D0
dc.b $80,$80,$80,$80,$80 ; $E0
even
; ---------------------------------------------------------------------------
; Updates SMPS
; ---------------------------------------------------------------------------
UpdateMusic:
stopZ80
waitZ80
btst #7,(z80_dac_status).l
beq.s .driverinput
startZ80
nop
nop
nop
nop
nop
bra.s UpdateMusic
; ---------------------------------------------------------------------------
.driverinput:
lea (v_snddriver_ram&$FFFFFF).l,a6
clr.b SMPS_RAM.f_voice_selector(a6)
tst.b SMPS_RAM.f_pausemusic(a6)
bne.w PauseMusic
subq.b #1,SMPS_RAM.v_main_tempo_timeout(a6)
bne.s .skipdelay
jsr TempoWait(pc)
.skipdelay:
move.b SMPS_RAM.v_fadeout_counter(a6),d0
beq.s .skipfadeout
jsr DoFadeOut(pc)
.skipfadeout:
tst.b SMPS_RAM.f_fadein_flag(a6)
beq.s .nofadein
jsr DoFadeIn(pc)
.nofadein:
tst.w SMPS_RAM.v_soundqueue0(a6)
beq.s .noqueue
jsr CycleSoundQueue(pc)
.noqueue:
lea SMPS_RAM.v_music_dac_track(a6),a5
tst.b SMPS_Track.PlaybackControl(a5)
bpl.s .nodac
jsr DACUpdateTrack(pc)
.nodac:
clr.b SMPS_RAM.f_updating_dac(a6)
moveq #SMPS_MUSIC_FM_TRACK_COUNT-1,d7 ; 6 FM tracks
.loopfm1:
adda.w #SMPS_Track.len,a5
tst.b SMPS_Track.PlaybackControl(a5)
bpl.s .nofm1
jsr FMUpdateTrack(pc)
.nofm1:
dbf d7,.loopfm1
moveq #SMPS_MUSIC_PSG_TRACK_COUNT-1,d7 ; 3 PSG tracks
.looppsg1:
adda.w #SMPS_Track.len,a5
tst.b SMPS_Track.PlaybackControl(a5)
bpl.s .nopsg1
jsr PSGUpdateTrack(pc)
.nopsg1:
dbf d7,.looppsg1
move.b #$80,SMPS_RAM.f_voice_selector(a6)
moveq #SMPS_SFX_FM_TRACK_COUNT-1,d7 ; 3 FM tracks (SFX)
.loopfm2:
adda.w #SMPS_Track.len,a5
tst.b SMPS_Track.PlaybackControl(a5)
bpl.s .nofm2
jsr FMUpdateTrack(pc)
.nofm2:
dbf d7,.loopfm2
moveq #SMPS_SFX_PSG_TRACK_COUNT-1,d7 ; 3 PSG tracks (SFX)
.looppsg2:
adda.w #SMPS_Track.len,a5
tst.b SMPS_Track.PlaybackControl(a5)
bpl.s .nopsg2
jsr PSGUpdateTrack(pc)
.nopsg2:
dbf d7,.looppsg2
move.b #$40,SMPS_RAM.f_voice_selector(a6)
adda.w #SMPS_Track.len,a5
tst.b SMPS_Track.PlaybackControl(a5)
bpl.s .nofm3
jsr FMUpdateTrack(pc)
.nofm3:
adda.w #SMPS_Track.len,a5
tst.b SMPS_Track.PlaybackControl(a5)
bpl.s DoStartZ80
jsr PSGUpdateTrack(pc)
DoStartZ80:
startZ80
rts
; ---------------------------------------------------------------------------
DACUpdateTrack:
subq.b #1,SMPS_Track.DurationTimeout(a5)
bne.s .nodelay
move.b #$80,SMPS_RAM.f_updating_dac(a6)
movea.l SMPS_Track.DataPointer(a5),a4
.command:
moveq #0,d5
move.b (a4)+,d5
cmpi.b #$E0,d5
bcs.s .notcommand
jsr CoordFlag(pc)
bra.s .command
; ---------------------------------------------------------------------------
.notcommand:
tst.b d5
bpl.s .duration
move.b d5,SMPS_Track.SavedDAC(a5)
move.b (a4)+,d5
bpl.s .duration
subq.w #1,a4
move.b SMPS_Track.SavedDuration(a5),SMPS_Track.DurationTimeout(a5)
bra.s .checknote
; ---------------------------------------------------------------------------
.duration:
jsr SetDuration(pc)
.checknote:
move.l a4,SMPS_Track.DataPointer(a5)
btst #2,SMPS_Track.PlaybackControl(a5)
bne.s .nodelay
moveq #0,d0
move.b SMPS_Track.SavedDAC(a5),d0
cmpi.b #$80,d0
beq.s .nodelay
btst #3,d0
bne.s .timpani
tst.b (z80_dac_update).l ; is the dac update flag set?
bne.s .nodelay ; if not, branch
move.b d0,(z80_dac_sample).l
.nodelay:
rts
; ---------------------------------------------------------------------------
.timpani:
subi.b #$88,d0
move.b .timpanipitch(pc,d0.w),d0
tst.b (z80_dac_update).l ; is the dac update flag set?
bne.s .nodac ; if not, branch
move.b d0,(z80_dac3_pitch).l
move.b #$83,(z80_dac_sample).l ; use timpani sample
.nodac:
rts
; ---------------------------------------------------------------------------
.timpanipitch: dc.b dpcmLoopCounter(8250)
dc.b dpcmLoopCounter(7500)
dc.b dpcmLoopCounter(6350)
dc.b dpcmLoopCounter(6250)
; the values below are invalid and will play at a very slow rate.
dc.b $FF
dc.b $FF
dc.b $FF
dc.b $FF
even
; ---------------------------------------------------------------------------
FMUpdateTrack:
subq.b #1,SMPS_Track.DurationTimeout(a5)
bne.s .notegoing
bclr #4,SMPS_Track.PlaybackControl(a5)
jsr FMDoNext(pc)
jsr FMPrepareNote(pc)
jsr FMPan_Set(pc)
bra.w FMNoteOn
; ---------------------------------------------------------------------------
.notegoing:
jsr NoteTimeoutUpdate(pc)
jsr DoModulation(pc)
bra.w FMUpdateFreq
; ---------------------------------------------------------------------------
FMDoNext:
movea.l SMPS_Track.DataPointer(a5),a4
bclr #1,SMPS_Track.PlaybackControl(a5)
.command:
moveq #0,d5
move.b (a4)+,d5
cmpi.b #$E0,d5
bcs.s .notcommand
jsr CoordFlag(pc)
bra.s .command
; ---------------------------------------------------------------------------
.notcommand:
jsr FMNoteOff(pc)
tst.b d5
bpl.s .duration
jsr FMSetFreq(pc)
move.b (a4)+,d5
bpl.s .duration
subq.w #1,a4
bra.w FinishTrackUpdate
; ---------------------------------------------------------------------------
.duration:
jsr SetDuration(pc)
bra.w FinishTrackUpdate
; ---------------------------------------------------------------------------
FMSetFreq:
subi.b #$80,d5
beq.s TrackSetRest
add.b SMPS_Track.Transpose(a5),d5
andi.w #$7F,d5
lsl.w #1,d5
lea FMFrequencies(pc),a0
move.w (a0,d5.w),d6
move.w d6,SMPS_Track.Freq(a5)
rts
; ---------------------------------------------------------------------------
SetDuration:
move.b d5,d0
move.b SMPS_Track.TempoDivider(a5),d1
.loop:
subq.b #1,d1
beq.s .save
add.b d5,d0
bra.s .loop
; ---------------------------------------------------------------------------
.save:
move.b d0,SMPS_Track.SavedDuration(a5) ; Save duration
move.b d0,SMPS_Track.DurationTimeout(a5) ; Save duration timeout
rts
; ---------------------------------------------------------------------------
TrackSetRest:
bset #1,SMPS_Track.PlaybackControl(a5)
clr.w SMPS_Track.Freq(a5)
FinishTrackUpdate:
move.l a4,SMPS_Track.DataPointer(a5) ; Store new track position
move.b SMPS_Track.SavedDuration(a5),SMPS_Track.DurationTimeout(a5) ; Reset note timeout
btst #4,SMPS_Track.PlaybackControl(a5) ; Is track set to not attack note?
bne.s .locret ; If so, branch
move.b SMPS_Track.NoteTimeoutMaster(a5),SMPS_Track.NoteTimeout(a5) ; Reset note fill timeout
clr.b SMPS_Track.VolEnvIndex(a5) ; Reset PSG volume envelope index (even on FM tracks...)
btst #3,SMPS_Track.PlaybackControl(a5) ; Is modulation on?
beq.s .locret ; If not, return
movea.l SMPS_Track.ModulationPtr(a5),a0 ; Modulation data pointer
move.b (a0)+,SMPS_Track.ModulationWait(a5) ; Reset wait
move.b (a0)+,SMPS_Track.ModulationSpeed(a5) ; Reset speed
move.b (a0)+,SMPS_Track.ModulationDelta(a5) ; Reset delta
move.b (a0)+,d0 ; Get steps
lsr.b #1,d0 ; Halve them
move.b d0,SMPS_Track.ModulationSteps(a5) ; Then store
clr.w SMPS_Track.ModulationVal(a5) ; Reset frequency change
.locret:
rts
; ---------------------------------------------------------------------------
NoteTimeoutUpdate:
tst.b SMPS_Track.NoteTimeout(a5)
beq.s .locret
subq.b #1,SMPS_Track.NoteTimeout(a5)
bne.s .locret
bset #1,SMPS_Track.PlaybackControl(a5)
tst.b SMPS_Track.VoiceControl(a5)
bmi.w .psg
jsr FMNoteOff(pc)
addq.w #4,sp
rts
; ---------------------------------------------------------------------------
.psg:
jsr PSGNoteOff(pc)
addq.w #4,sp
.locret:
rts
; ---------------------------------------------------------------------------
DoModulation:
addq.w #4,sp
btst #3,SMPS_Track.PlaybackControl(a5)
beq.s .nomods
tst.b SMPS_Track.ModulationWait(a5)
beq.s .waitdone
subq.b #1,SMPS_Track.ModulationWait(a5)
rts
; ---------------------------------------------------------------------------
.waitdone:
subq.b #1,SMPS_Track.ModulationSpeed(a5)
beq.s .nextstep
rts
; ---------------------------------------------------------------------------
.nextstep:
movea.l SMPS_Track.ModulationPtr(a5),a0
move.b 1(a0),SMPS_Track.ModulationSpeed(a5)
tst.b SMPS_Track.ModulationSteps(a5)
bne.s .noflip
move.b 3(a0),SMPS_Track.ModulationSteps(a5)
neg.b SMPS_Track.ModulationDelta(a5)
rts
; ---------------------------------------------------------------------------
.noflip:
subq.b #1,SMPS_Track.ModulationSteps(a5)
move.b SMPS_Track.ModulationDelta(a5),d6
ext.w d6
add.w SMPS_Track.ModulationVal(a5),d6
move.w d6,SMPS_Track.ModulationVal(a5)
add.w SMPS_Track.Freq(a5),d6
subq.w #4,sp
.nomods:
rts
; ---------------------------------------------------------------------------
FMPrepareNote:
btst #1,SMPS_Track.PlaybackControl(a5)
bne.s locret_744E0
move.w SMPS_Track.Freq(a5),d6
beq.s FMSetRest
FMUpdateFreq:
move.b SMPS_Track.Detune(a5),d0
ext.w d0
add.w d0,d6
btst #2,SMPS_Track.PlaybackControl(a5)
bne.s locret_744E0
tst.b SMPS_RAM.v_se_mode_flag(a6)
beq.s .nofm3sm
cmpi.b #2,SMPS_Track.VoiceControl(a5)
beq.s FM3SpcUpdateFreq
.nofm3sm:
move.w d6,d1
lsr.w #8,d1
move.b #$A4,d0
jsr WriteFMIorII(pc)
move.b d6,d1
move.b #$A0,d0
jsr WriteFMIorII(pc)
locret_744E0:
rts
; ---------------------------------------------------------------------------
FMSetRest:
bset #1,SMPS_Track.PlaybackControl(a5)
rts
; ---------------------------------------------------------------------------
FM3SpcUpdateFreq:
lea .fm3freqs(pc),a1
lea SMPS_RAM.v_detune_start(a6),a2
moveq #bytesToWcnt(.fm3freqs_end-.fm3freqs),d7
.loopfm3:
move.w d6,d1
move.w (a2)+,d0
add.w d0,d1
move.w d1,d3
lsr.w #8,d1
move.b (a1)+,d0
jsr WriteFMI(pc)
move.b d3,d1
move.b (a1)+,d0
jsr WriteFMI(pc)
dbf d7,.loopfm3
rts
; ---------------------------------------------------------------------------
.fm3freqs: dc.b $AD, $A9
dc.b $AC, $A8
dc.b $AE, $AA
dc.b $A6, $A2
.fm3freqs_end: even
; ---------------------------------------------------------------------------
FMPan_Set:
btst #1,SMPS_Track.PlaybackControl(a5)
bne.s .tables
moveq #0,d0
move.b SMPS_Track.PanNumber(a5),d0
lsl.w #1,d0
jmp .tables(pc,d0.w)
; ---------------------------------------------------------------------------
.tables:
rts
; ---------------------------------------------------------------------------
bra.s FMPan_Cont
; ---------------------------------------------------------------------------
bra.s FMPan_Reset
; ---------------------------------------------------------------------------
bra.s FMPan_Reset
; ---------------------------------------------------------------------------
FMPan_Chk:
btst #1,SMPS_Track.PlaybackControl(a5)
bne.s .table
moveq #0,d0
move.b SMPS_Track.PanNumber(a5),d0
lsl.w #1,d0
jmp .table(pc,d0.w)
; ---------------------------------------------------------------------------
.table:
rts
; ---------------------------------------------------------------------------
rts
; ---------------------------------------------------------------------------
bra.s FMPan_Cont
; ---------------------------------------------------------------------------
bra.s FMPan_Cont
; ---------------------------------------------------------------------------
FMPan_Reset:
move.b SMPS_Track.PanLength(a5),SMPS_Track.PanContinue(a5)
clr.b SMPS_Track.PanStart(a5)
FMPan_Cont:
move.b SMPS_Track.PanContinue(a5),d0
cmp.b SMPS_Track.PanLength(a5),d0
bne.s loc_7457E
move.b SMPS_Track.PanLimit(a5),d3
cmp.b SMPS_Track.PanStart(a5),d3
bpl.s loc_74576
cmpi.b #2,SMPS_Track.PanNumber(a5)
beq.s locret_745AE
clr.b SMPS_Track.PanStart(a5)
loc_74576:
clr.b SMPS_Track.PanContinue(a5)
addq.b #1,SMPS_Track.PanStart(a5)
loc_7457E:
moveq #0,d0
move.b SMPS_Track.PanTable(a5),d0
subq.w #1,d0
lsl.w #2,d0
movea.l FM_Pan_Table(pc,d0.w),a0
moveq #0,d0
move.b SMPS_Track.PanStart(a5),d0
subq.w #1,d0
move.b (a0,d0.w),d1
move.b SMPS_Track.AMSFMSPan(a5),d0
andi.b #$37,d0
or.b d0,d1
move.b #$B4,d0
jsr WriteFMIorIIMain(pc)
addq.b #1,SMPS_Track.PanContinue(a5)
locret_745AE:
rts
; ---------------------------------------------------------------------------
FM_Pan_Table: dc.l pan_1_data
dc.l pan_2_data
dc.l pan_3_data
pan_1_data: dc.b $40, $80
pan_2_data: dc.b $40, $C0, $80
pan_3_data: dc.b $C0, $80, $C0, $40
even
; ---------------------------------------------------------------------------
PauseMusic:
bmi.s .unpausemusic
cmpi.b #2,SMPS_RAM.f_pausemusic(a6)
beq.w .unpausedallfm
move.b #2,SMPS_RAM.f_pausemusic(a6)
moveq #2,d2
move.b #$B4,d0
moveq #0,d1
.killpanloop:
jsr WriteFMI(pc)
jsr WriteFMII(pc)
addq.b #1,d0
dbf d2,.killpanloop
moveq #2,d2
moveq #$28,d0
.noteoffloop:
move.b d2,d1
jsr WriteFMI(pc)
addq.b #4,d1
jsr WriteFMI(pc)
dbf d2,.noteoffloop
jsr PSGSilenceAll(pc)
bra.w DoStartZ80
; ---------------------------------------------------------------------------
.unpausemusic:
clr.b SMPS_RAM.f_pausemusic(a6)
moveq #SMPS_Track.len,d3
lea SMPS_RAM.v_music_fmdac_tracks(a6),a5
moveq #SMPS_MUSIC_FM_DAC_TRACK_COUNT-1,d4 ; 6 FM + 1 DAC tracks
.bgmfmloop:
btst #7,SMPS_Track.PlaybackControl(a5) ; Is track playing?
beq.s .bgmfmnext ; Branch if not
btst #2,SMPS_Track.PlaybackControl(a5) ; Is track being overridden?
bne.s .bgmfmnext ; Branch if yes
move.b #$B4,d0 ; Command to set AMS/FMS/panning
move.b SMPS_Track.AMSFMSPan(a5),d1 ; Get value from track RAM
jsr WriteFMIorII(pc)
.bgmfmnext:
adda.w d3,a5
dbf d4,.bgmfmloop
lea SMPS_RAM.v_sfx_fm_tracks(a6),a5
moveq #SMPS_SFX_FM_TRACK_COUNT-1,d4 ; 3 FM tracks (SFX)
.sfxfmloop:
btst #7,SMPS_Track.PlaybackControl(a5) ; Is track playing?
beq.s .sfxfmnext ; Branch if not
btst #2,SMPS_Track.PlaybackControl(a5) ; Is track being overridden?
bne.s .sfxfmnext ; Branch if yes
move.b #$B4,d0 ; Command to set AMS/FMS/panning
move.b SMPS_Track.AMSFMSPan(a5),d1 ; Get value from track RAM
jsr WriteFMIorII(pc)
.sfxfmnext:
adda.w d3,a5
dbf d4,.sfxfmloop
lea SMPS_RAM.v_spcsfx_track_ram(a6),a5
btst #7,SMPS_Track.PlaybackControl(a5) ; Is track playing?
beq.s .unpausedallfm ; Branch if not
btst #2,SMPS_Track.PlaybackControl(a5) ; Is track being overridden?
bne.s .unpausedallfm ; Branch if yes
move.b #$B4,d0 ; Command to set AMS/FMS/panning
move.b SMPS_Track.AMSFMSPan(a5),d1 ; Get value from track RAM
jsr WriteFMIorII(pc)
.unpausedallfm:
bra.w DoStartZ80
; ---------------------------------------------------------------------------
CycleSoundQueue:
movea.l (Go_SoundPriorities).l,a0
lea SMPS_RAM.v_soundqueue0(a6),a1 ; load music track number
_move.b SMPS_RAM.v_sndprio(a6),d3 ; Get priority of currently playing SFX
moveq #SMPS_RAM.v_soundqueue_end-SMPS_RAM.v_soundqueue_start-1,d4 ; number of soundqueues
.inputloop:
move.b (a1),d0 ; move track number to d0
move.b d0,d1
clr.b (a1)+ ; Clear entry
subi.b #bgm__First,d0 ; Make it into 0-based index
bcs.s .nextinput ; If negative (i.e., it was $80 or lower), branch
andi.w #$7F,d0 ; Clear high byte and sign bit
move.b (a0,d0.w),d2 ; Get sound type
cmp.b d3,d2 ; Is it a lower priority sound?
bcs.s .nextinput
move.b d2,d3 ; Store new priority
move.b d1,SMPS_RAM.v_sound_id(a6) ; Queue sound for playing
.nextinput:
dbf d4,.inputloop
tst.b d3 ; We don't want to change sound priority if it is negative
bmi.s PlaySoundID
_move.b d3,SMPS_RAM.v_sndprio(a6) ; Set new sound priority
PlaySoundID:
moveq #0,d7
move.b SMPS_RAM.v_sound_id(a6),d7
move.b #$80,SMPS_RAM.v_sound_id(a6)
cmpi.b #$80,d7
beq.s .nosound
bcs.w StopAllSound
cmpi.b #bgm__Last+$E,d7
bls.w dPlaySnd_Music
cmpi.b #sfx__First,d7
bcs.w .nosound
cmpi.b #sfx__Last,d7
bls.w dPlaySnd_SFX
cmpi.b #spec__First,d7
bcs.w .nosound
cmpi.b #spec__Last+5,d7
bcs.w dPlaySnd_SpecSFX
cmpi.b #flg__First,d7
bcs.s dPlaySnd_DAC
cmpi.b #flg__Last+1,d7
bls.s dPlaySnd_Cmd
.nosound:
rts
; ---------------------------------------------------------------------------
dPlaySnd_Cmd:
subi.b #flg__First,d7
lsl.w #2,d7
jmp Sound_ExIndex(pc,d7.w)
; ---------------------------------------------------------------------------
Sound_ExIndex:
ptr_flgE0: bra.w PlaySnd_FadeOut
ptr_flgE1: bra.w StopSFX
ptr_flgE2: bra.w PlaySnd_ShoesOn
ptr_flgE3: bra.w PlaySnd_ShoesOff
ptr_flgE4: bra.w StopSpecialSFX
ptr_flgend:
; ---------------------------------------------------------------------------
dPlaySnd_DAC:
addi.b #$B1,d7
move.b d7,(z80_dac_sample).l
nop
nop
nop
clr.b (a0)+
rts
; ---------------------------------------------------------------------------
dPlaySnd_Music:
cmpi.b #bgm_ExtraLife,d7
bne.s .bgmnot1up
tst.b SMPS_RAM.f_1up_playing(a6)
bne.w .exit
lea SMPS_RAM.v_music_track_ram(a6),a5
moveq #SMPS_MUSIC_TRACK_COUNT-1,d0 ; 1 DAC + 6 FM + 3 PSG tracks
.noint:
bclr #2,SMPS_Track.PlaybackControl(a5)
adda.w #SMPS_Track.len,a5
dbf d0,.noint
lea SMPS_RAM.v_sfx_track_ram(a6),a5
moveq #SMPS_SFX_TRACK_COUNT-1,d0 ; 3 FM + 3 PSG tracks (SFX)
.loop0:
bclr #7,SMPS_Track.PlaybackControl(a5)
adda.w #SMPS_Track.len,a5
dbf d0,.loop0
movea.l a6,a0
lea SMPS_RAM.v_1up_ram_copy(a6),a1
move.w #bytesToLcnt(SMPS_RAM.v_1up_ram_end-SMPS_RAM.v_1up_ram),d0 ; Backup $220 bytes: all variables and music track data
.memcopy:
move.l (a0)+,(a1)+
dbf d0,.memcopy
move.b #$80,SMPS_RAM.f_1up_playing(a6)
_clr.b SMPS_RAM.v_sndprio(a6)
bra.s .initmusic
; ---------------------------------------------------------------------------
.bgmnot1up:
clr.b SMPS_RAM.f_1up_playing(a6)
clr.b SMPS_RAM.v_fadein_counter(a6)
.initmusic:
jsr InitMusicPlayback(pc)
movea.l (Go_SpeedUpIndex).l,a4
subi.b #bgm__First,d7
move.b (a4,d7.w),SMPS_RAM.v_speeduptempo(a6)
movea.l (Go_MusicIndex).l,a4
lsl.w #2,d7
movea.l (a4,d7.w),a4
moveq #0,d0
move.w (a4),d0
add.l a4,d0
move.l d0,SMPS_RAM.v_voice_ptr(a6)
move.b 5(a4),d0
move.b d0,SMPS_RAM.v_tempo_mod(a6)
tst.b SMPS_RAM.f_speedup(a6)
beq.s .nospeedshoes
move.b SMPS_RAM.v_speeduptempo(a6),d0
.nospeedshoes:
move.b d0,SMPS_RAM.v_main_tempo(a6)
move.b d0,SMPS_RAM.v_main_tempo_timeout(a6)
moveq #0,d1
movea.l a4,a3
addq.w #6,a4
moveq #0,d7
move.b 2(a3),d7
beq.w .bgm_fmdone
subq.b #1,d7
move.b #$C0,d1
move.b 4(a3),d4
moveq #SMPS_Track.len,d6
move.b #1,d5
lea SMPS_RAM.v_music_fmdac_tracks(a6),a1
lea FMDACInitBytes(pc),a2
.bgm_fmloadloop:
bset #7,SMPS_Track.PlaybackControl(a1)
move.b (a2)+,SMPS_Track.VoiceControl(a1)
move.b d4,SMPS_Track.TempoDivider(a1)
move.b d6,SMPS_Track.StackPointer(a1)
move.b d1,SMPS_Track.AMSFMSPan(a1)
move.b d5,SMPS_Track.DurationTimeout(a1)
moveq #0,d0
move.w (a4)+,d0
add.l a3,d0
move.l d0,SMPS_Track.DataPointer(a1)
move.w (a4)+,SMPS_Track.Transpose(a1)
adda.w d6,a1
dbf d7,.bgm_fmloadloop
cmpi.b #7,2(a3)
bne.s .silencefm6
moveq #$2B,d0
moveq #0,d1
jsr WriteFMI(pc)
bra.w .bgm_fmdone
; ---------------------------------------------------------------------------
.silencefm6:
moveq #$28,d0
moveq #6,d1
jsr WriteFMI(pc)
move.b #$42,d0
moveq #$7F,d1
jsr WriteFMII(pc)
move.b #$4A,d0
moveq #$7F,d1
jsr WriteFMII(pc)
move.b #$46,d0
moveq #$7F,d1
jsr WriteFMII(pc)
move.b #$4E,d0
moveq #$7F,d1
jsr WriteFMII(pc)
move.b #$B6,d0
move.b #$C0,d1
jsr WriteFMII(pc)
.bgm_fmdone:
moveq #0,d7
move.b 3(a3),d7
beq.s .bgm_psgdone
subq.b #1,d7
lea SMPS_RAM.v_music_psg_tracks(a6),a1
lea PSGInitBytes(pc),a2
.bgm_psgloadloop:
bset #7,SMPS_Track.PlaybackControl(a1)
move.b (a2)+,SMPS_Track.VoiceControl(a1)
move.b d4,SMPS_Track.TempoDivider(a1)
move.b d6,SMPS_Track.StackPointer(a1)
move.b d5,SMPS_Track.DurationTimeout(a1)
moveq #0,d0
move.w (a4)+,d0
add.l a3,d0
move.l d0,SMPS_Track.DataPointer(a1)
move.w (a4)+,SMPS_Track.Transpose(a1)
move.b (a4)+,d0
move.b (a4)+,SMPS_Track.VoiceIndex(a1)
adda.w d6,a1
dbf d7,.bgm_psgloadloop
.bgm_psgdone:
lea SMPS_RAM.v_sfx_track_ram(a6),a1
moveq #SMPS_SFX_TRACK_COUNT-1,d7
.sfxloop:
tst.b SMPS_Track.PlaybackControl(a1)
bpl.w .nextsfx
moveq #0,d0
move.b SMPS_Track.VoiceControl(a1),d0
bmi.s .psgsfx
subq.b #2,d0
lsl.b #2,d0
bra.s .getch
; ---------------------------------------------------------------------------
.psgsfx:
lsr.b #3,d0
.getch:
lea SFX_BGMChannelRAM(pc),a0
movea.l (a0,d0.w),a0
bset #2,SMPS_Track.PlaybackControl(a0)
.nextsfx:
adda.w d6,a1
dbf d7,.sfxloop
tst.w SMPS_RAM.v_spcsfx_fm4_track+SMPS_Track.PlaybackControl(a6)
bpl.s .checkspecialpsg
bset #2,SMPS_RAM.v_music_fm4_track+SMPS_Track.PlaybackControl(a6)
.checkspecialpsg:
tst.w SMPS_RAM.v_spcsfx_psg3_track+SMPS_Track.PlaybackControl(a6)
bpl.s .sendfmnoteoff
bset #2,SMPS_RAM.v_music_psg3_track+SMPS_Track.PlaybackControl(a6)
.sendfmnoteoff:
lea SMPS_RAM.v_music_fm_tracks(a6),a5
moveq #SMPS_MUSIC_FM_TRACK_COUNT-1,d4
.fmnoteoffloop:
jsr FMNoteOff(pc)
adda.w d6,a5
dbf d4,.fmnoteoffloop
moveq #SMPS_MUSIC_PSG_TRACK_COUNT-1,d4
.psgnoteoffloop:
jsr PSGNoteOff(pc)
adda.w d6,a5
dbf d4,.psgnoteoffloop
.exit:
addq.w #4,sp
rts
; ---------------------------------------------------------------------------
FMDACInitBytes:
dc.b 6, 0, 1, 2, 4, 5, 6
even
PSGInitBytes:
dc.b $80, $A0, $C0
even
; ---------------------------------------------------------------------------
dPlaySnd_SFX:
tst.b SMPS_RAM.f_1up_playing(a6)
bne.w .exits
cmpi.b #sfx_Ring,d7
bne.s .notring
tst.b SMPS_RAM.v_ring_speaker(a6)
bne.s .noswap
move.b #sfx_RingLeft,d7
.noswap:
bchg #0,SMPS_RAM.v_ring_speaker(a6)
.notring:
cmpi.b #sfx_Push,d7
bne.s .notpush
tst.b SMPS_RAM.f_push_playing(a6)
bne.w .exits
move.b #$80,SMPS_RAM.f_push_playing(a6)
.notpush:
movea.l (Go_SoundIndex).l,a0
subi.b #sfx__First,d7
lsl.w #2,d7
movea.l (a0,d7.w),a3
movea.l a3,a1
moveq #0,d0
move.w (a1)+,d0
add.l a3,d0
move.l d0,SMPS_RAM.v_lfo_voice_ptr(a6)
move.b (a1)+,d5
; DANGER! there is a missing 'moveq #0,d7' here, without which SFXes whose
; index entry is above $3F will cause a crash. This was fixed in Ristar's driver.
move.b (a1)+,d7
subq.b #1,d7
moveq #SMPS_Track.len,d6
.chanloop:
moveq #0,d3
move.b SMPS_Track.VoiceControl(a1),d3
move.b d3,d4
bmi.s .psg
subq.w #2,d3
lsl.w #2,d3
lea SFX_BGMChannelRAM(pc),a5
movea.l (a5,d3.w),a5
bset #2,SMPS_Track.PlaybackControl(a5)
bra.s .continue
; ---------------------------------------------------------------------------