-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paths2b.sounddriver.asm
6272 lines (5956 loc) · 87.4 KB
/
s2b.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
; ---------------------------------------------------------------------------
; NOTES:
;
; This code is compressed in the ROM, but you can edit it here as uncompressed
; and it will automatically be assembled and compressed into the correct place
; during the build process.
;
; This Z80 code can use labels and equates defined in the 68k code,
; and the 68k code can use the labels and equates defined in here.
; This is fortunate, as they contain references to each other's addresses.
;
; If you want to add significant amounts of extra code to this driver,
; try putting your code as far down as possible.
; That will make you less likely to run into space shortages from dislocated data alignment.
;
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Setup defines and macros
zStack = $1B80
zBankRegister = $6000
zROMWindow = $8000
; In what I believe is an unfortunate design choice in AS,
; both the phased and unphased PCs must be within the target processor's range,
; which means phase is useless here despite being designed to fix this problem...
; oh well, I set it up to fix this later when processing the .p file
!org 0 ; Z80 code starting at address 0 has special meaning to s2p2bin.exe
CPU Z80UNDOC
listing purecode
; Macro to perform a bank switch... after using this,
; the start of zROMWindow points to the start of the given 68k address,
; rounded down to the nearest $8000 byte boundary
bankswitch macro addr68k
xor a ; a = 0
ld e,1 ; e = 1
ld hl,zBankRegister
cnt := 0
rept 9
; this is either ld (hl),a or ld (hl),e
db (73h|((((addr68k)&(1<<(15+cnt)))==0)<<2))
cnt := (cnt+1)
endm
endm
; macro to make a certain error message clearer should you happen to get it...
rsttarget macro {INTLABEL}
if ($&7)||($>38h)
fatal "Function __LABEL__ is at 0\{$}h, but must be at a multiple of 8 bytes <= 38h to be used with the rst instruction."
endif
if "__LABEL__"<>""
__LABEL__ label $
endif
endm
; Function to turn a 68k address into a word the Z80 can use to access it,
; assuming the correct bank has been switched to first
zmake68kPtr function addr,zROMWindow+(addr&7FFFh)
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Z80 'ROM' start:
; zEntryPoint:
di ; disable interrupts
ld sp,zStack
jp zStartDAC
; ---------------------------------------------------------------------------
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
align 8
; zsub_8:
zWaitForYM: rsttarget
; Performs the annoying task of waiting for the FM to not be busy
ld a,(4000h)
add a,a
jr c,zWaitForYM
ret
; End of function WaitForYM
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
align 8
; zsub_10:
zWriteFMIorII: rsttarget
bit 2,(ix+1)
jr z,zWriteFMI
jr zWriteFMII
; End of function zWriteFMIorII
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
align 8
; zsub_18
zWriteFMI: rsttarget
; Write reg/data pair to part I; 'a' is register, 'c' is data
push af
rst zWaitForYM
pop af
ld (4000h),a
push af
rst zWaitForYM
ld a,c
ld (4001h),a
pop af
ret
; End of function zWriteFMI
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
align 8
; zsub_28:
zWriteFMII: rsttarget
; Write reg/data pair to part II; 'a' is register, 'c' is data
push af
rst zWaitForYM
pop af
ld (4002h),a
push af
rst zWaitForYM
ld a,c
ld (4003h),a
pop af
ret
; End of function zWriteFMII
; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
org 38h
VInt: rsttarget
push af
exx
call zBankSwitchToMusic
xor a
ld (byte_11AA), a ; 00 - Music Mode
ld ix, byte_1B80 ; 1B80 - Sound RAM
ld a, (byte_1B83) ; 1B83 = Pause Mode
or a
jr z, loc_51 ; 00 = not paused
call DoPause
jp RestoreDACBank
; ---------------------------------------------------------------------------
loc_51: ; CODE XREF: RAM:0049j
dec (ix+1) ; decrement Tempo Timeout (1B81)
call z, DoTempoDelay ; reached 00 - delay all tracks
ld a, (byte_1B84) ; 1B84 - remaining Fade Out Steps
or a
call nz, DoFadeOut
ld a, (byte_1B8E) ; 1B8E - Fade In Enable
or a
call nz, DoFadeIn
ld a, (byte_1B89) ; check Sound Queue
or (ix+0Ah)
or (ix+0Bh)
call nz, DoSoundQueue ; at least one of the 3 slots was filled
ld a, (byte_1B88)
cp 80h
call nz, PlaySoundID
ld a, 0FFh
ld (byte_1B87), a ; 1B87 - processing DAC channel (FF = yes)
ld ix, byte_1B97 ; 1B97 - Music Tracks
bit 7, (ix+0)
call nz, DrumUpdateTrack
xor a
ld (byte_1B87), a ; 1B87 = 00 - not processing the DAC channel anymore
ld b, 6
loc_8F: ; CODE XREF: RAM:009Dj
push bc
ld de, 2Ah
add ix, de
bit 7, (ix+0)
call nz, UpdateFMTrack
pop bc
djnz loc_8F
ld b, 3
loc_A1: ; CODE XREF: RAM:00AFj
push bc
ld de, 2Ah
add ix, de
bit 7, (ix+0)
call nz, UpdatePSGTrack
pop bc
djnz loc_A1
bankswitch SoundIndex
ld a, 80h
ld (byte_11AA), a ; 00 - SFX Mode
ld b, 3
loc_C7: ; CODE XREF: RAM:00D5j
push bc
ld de, 2Ah
add ix, de
bit 7, (ix+0)
call nz, UpdateFMTrack
pop bc
djnz loc_C7
ld b, 3
loc_D9: ; CODE XREF: RAM:00E7j
push bc
ld de, 2Ah
add ix, de
bit 7, (ix+0)
call nz, UpdatePSGTrack
pop bc
djnz loc_D9
RestoreDACBank: ; CODE XREF: RAM:004Ej RAM:0D09j
bankswitch DACSamples_Start
ld a, (byte_11A8) ; check, if a new DAC sound was queued
or a
jp m, loc_105 ; yes - jump
exx
ld b, 1
pop af
ei
ret
; ---------------------------------------------------------------------------
loc_105: ; CODE XREF: RAM:00FCj
ld a, 80h
ex af, af'
ld a, (byte_11A8)
sub 81h
ld (byte_11A8), a
add a, a
add a, a
add a, 75h ; add lower byte from 0F75
ld (loc_121+1), a
add a, 2
ld (loc_124+2), a
pop af
ld hl, loc_13C
ex (sp), hl
loc_121: ; DATA XREF: RAM:0114w
ld hl, (word_F75)
loc_124: ; DATA XREF: RAM:0119w
ld de, (word_F75+2)
loc_128: ; DATA XREF: RAM:01FAw
ld bc, 100h
ei
ret
; ---------------------------------------------------------------------------
; InitDriver:
zStartDAC:
call StopAllSound
ei
ld iy, DPCMData
ld de, 0
loc_138: ; CODE XREF: RAM:013Aj RAM:0176j
ld a, d
or e
jr z, loc_138
loc_13C: ; CODE XREF: RAM:loc_13Cj
; DATA XREF: RAM:011Do
djnz $
di
ld a, 2Ah
ld (4000h), a
ld a, (hl)
rlca
rlca
rlca
rlca
and 0Fh
ld (loc_14F+2), a
ex af, af'
loc_14F: ; DATA XREF: RAM:014Bw
add a, (iy+0)
ld (4001h), a
ex af, af'
ld b, c
ei
nop
loc_159: ; CODE XREF: RAM:loc_159j
djnz $
di
push af
pop af
ld a, 2Ah
ld (4000h), a
ld b, c
ld a, (hl)
inc hl
dec de
and 0Fh
ld (loc_16D+2), a
ex af, af'
loc_16D: ; DATA XREF: RAM:0169w
add a, (iy+0)
ld (4001h), a
ex af, af'
ei
nop
jp loc_138
; ---------------------------------------------------------------------------
DPCMData: db 0, 1, 2, 4, 8, 10h, 20h, 40h ; DATA XREF: RAM:0131o
db 80h,0FFh,0FEh,0FCh,0F8h,0F0h,0E0h,0C0h
BGMChnPtrs: dw 1C15h, 0, 1C3Fh, 1C69h, 1CBDh, 1CE7h, 1D11h, 1D11h
; DATA XREF: RAM:loc_86Br RAM:loc_91Fr ...
SFXChnPtrs: dw 1D3Bh, 0, 1D65h, 1D8Fh, 1DB9h, 1DE3h, 1E0Dh, 1E0Dh
; DATA XREF: RAM:loc_929r
; ---------------------------------------------------------------------------
DrumUpdateTrack: ; CODE XREF: RAM:0086p
dec (ix+0Bh)
ret nz
ld l, (ix+3)
ld h, (ix+4)
loc_1B3: ; CODE XREF: RAM:01BCj
ld a, (hl)
inc hl
cp 0E0h
jr c, loc_1BF
call zCoordFlag
jp loc_1B3
; ---------------------------------------------------------------------------
loc_1BF: ; CODE XREF: RAM:01B7j
or a
jp p, loc_1D5
ld (ix+0Dh), a
ld a, (hl)
or a
jp p, loc_1D4
ld a, (ix+0Ch)
ld (ix+0Bh), a
jp loc_1D8
; ---------------------------------------------------------------------------
loc_1D4: ; CODE XREF: RAM:01C8j
inc hl
loc_1D5: ; CODE XREF: RAM:01C0j
call TickMultiplier
loc_1D8: ; CODE XREF: RAM:01D1j
ld (ix+3), l
ld (ix+4), h
bit 2, (ix+0)
ret nz
ld a, (ix+0Dh)
cp 80h
ret z ; Drum 80 (null-drum) - return
sub 81h
add a, a ; else look up the DAC playlist
add a, 8Dh
ld (loc_1F1+2), a
loc_1F1: ; DATA XREF: RAM:01EEw
ld bc, (byte_F8D)
ld a, c
ld (byte_11A8), a ; request new DAC sound to be played
ld a, b
ld (loc_128+1), a ; set playback speed
ret
; =============== S U B R O U T I N E =======================================
UpdateFMTrack: ; CODE XREF: RAM:0099p RAM:00D1p
; FUNCTION CHUNK AT 0B9C SIZE 00000010 BYTES
dec (ix+0Bh)
jr nz, loc_210
res 4, (ix+0)
call TrkUpdate_FM
call SendFMFreq
jp DoNoteOn
; ---------------------------------------------------------------------------
loc_210: ; CODE XREF: UpdateFMTrack+3j
call DoNoteStop
call DoModulation
jp RefreshFMFreq
; End of function UpdateFMTrack
; =============== S U B R O U T I N E =======================================
TrkUpdate_FM: ; CODE XREF: UpdateFMTrack+9p
; FUNCTION CHUNK AT 027C SIZE 00000029 BYTES
; FUNCTION CHUNK AT 0E18 SIZE 0000001E BYTES
ld l, (ix+3)
ld h, (ix+4)
res 1, (ix+0)
loc_223: ; CODE XREF: TrkUpdate_FM+13j
ld a, (hl)
inc hl
cp 0E0h
jr c, loc_22F
call zCoordFlag
jp loc_223
; ---------------------------------------------------------------------------
loc_22F: ; CODE XREF: TrkUpdate_FM+Ej
push af
call DoNoteOff
pop af
or a
jp p, loc_241
call GetFMFreq
ld a, (hl)
or a
jp m, FinishTrkUpdate
inc hl
loc_241: ; CODE XREF: TrkUpdate_FM+1Cj
call TickMultiplier
jp FinishTrkUpdate
; End of function TrkUpdate_FM
; ---------------------------------------------------------------------------
GetFMFreq: ; CODE XREF: TrkUpdate_FM+1Fp
sub 80h
jr z, loc_25F
add a, (ix+5)
add a, a
add a, 1Bh
ld (loc_254+2), a
loc_254: ; DATA XREF: RAM:0251w
ld de, (FMFreqs)
ld (ix+0Dh), e
ld (ix+0Eh), d
ret
; ---------------------------------------------------------------------------
loc_25F: ; CODE XREF: RAM:0249j
set 1, (ix+0)
xor a
ld (ix+0Dh), a
ld (ix+0Eh), a
ret
; =============== S U B R O U T I N E =======================================
TickMultiplier: ; CODE XREF: RAM:loc_1D5p
; TrkUpdate_FM:loc_241p ...
ld c, a
ld b, (ix+2)
loc_26F: ; CODE XREF: TickMultiplier+Ej
djnz loc_278
ld (ix+0Ch), a
ld (ix+0Bh), a
ret
; ---------------------------------------------------------------------------
loc_278: ; CODE XREF: TickMultiplier:loc_26Fj
add a, c
jp loc_26F
; End of function TickMultiplier
; ---------------------------------------------------------------------------
; START OF FUNCTION CHUNK FOR TrkUpdate_FM
FinishTrkUpdate: ; CODE XREF: TrkUpdate_FM+24j
; TrkUpdate_FM+2Bj ...
ld (ix+3), l
ld (ix+4), h
ld a, (ix+0Ch)
ld (ix+0Bh), a
bit 4, (ix+0)
ret nz
ld a, (ix+10h)
ld (ix+0Fh), a
ld (ix+9), 0
bit 3, (ix+0)
ret z
ld l, (ix+11h)
ld h, (ix+12h)
jp loc_E18
; END OF FUNCTION CHUNK FOR TrkUpdate_FM
; =============== S U B R O U T I N E =======================================
DoNoteStop: ; CODE XREF: UpdateFMTrack:loc_210p
; UpdatePSGTrack:loc_4A8p
ld a, (ix+0Fh)
or a
ret z
dec (ix+0Fh)
ret nz
set 1, (ix+0)
pop de
bit 7, (ix+1)
jp nz, PSGNoteOff
jp DoNoteOff
; End of function DoNoteStop
; =============== S U B R O U T I N E =======================================
DoModulation: ; CODE XREF: UpdateFMTrack+15p
; UpdatePSGTrack+18p
pop de
bit 1, (ix+0)
ret nz
bit 3, (ix+0)
ret z
ld a, (ix+13h)
or a
jr z, loc_2D2
dec (ix+13h)
ret
; ---------------------------------------------------------------------------
loc_2D2: ; CODE XREF: DoModulation+Fj
dec (ix+14h)
ret nz
ld l, (ix+11h)
ld h, (ix+12h)
inc hl
ld a, (hl)
ld (ix+14h), a
ld a, (ix+16h)
or a
jr nz, loc_2F6
inc hl
inc hl
ld a, (hl)
ld (ix+16h), a
ld a, (ix+15h)
neg
ld (ix+15h), a
ret
; ---------------------------------------------------------------------------
loc_2F6: ; CODE XREF: DoModulation+28j
dec (ix+16h)
ld l, (ix+17h)
ld h, (ix+18h)
ld b, 0
ld c, (ix+15h)
bit 7, c
jp z, loc_30B
ld b, 0FFh
loc_30B: ; CODE XREF: DoModulation+49j
add hl, bc
ld (ix+17h), l
ld (ix+18h), h
ld c, (ix+0Dh)
ld b, (ix+0Eh)
add hl, bc
ex de, hl
jp (hl)
; End of function DoModulation
; ---------------------------------------------------------------------------
FMFreqs: dw 25Eh, 284h, 2ABh, 2D3h, 2FEh, 32Dh, 35Ch, 38Fh, 3C5h, 3FFh, 43Ch, 47Ch
; DATA XREF: RAM:loc_254r
dw 0A5Eh,0A84h,0AABh,0AD3h,0AFEh,0B2Dh,0B5Ch,0B8Fh,0BC5h,0BFFh,0C3Ch,0C7Ch
dw 125Eh,1284h,12ABh,12D3h,12FEh,132Dh,135Ch,138Fh,13C5h,13FFh,143Ch,147Ch
dw 1A5Eh,1A84h,1AABh,1AD3h,1AFEh,1B2Dh,1B5Ch,1B8Fh,1BC5h,1BFFh,1C3Ch,1C7Ch
dw 225Eh,2284h,22ABh,22D3h,22FEh,232Dh,235Ch,238Fh,23C5h,23FFh,243Ch,247Ch
dw 2A5Eh,2A84h,2AABh,2AD3h,2AFEh,2B2Dh,2B5Ch,2B8Fh,2BC5h,2BFFh,2C3Ch,2C7Ch
dw 325Eh,3284h,32ABh,32D3h,32FEh,332Dh,335Ch,338Fh,33C5h,33FFh,343Ch,347Ch
dw 3A5Eh,3A84h,3AABh,3AD3h,3AFEh,3B2Dh,3B5Ch,3B8Fh,3BC5h,3BFFh,3C3Ch,3C7Ch
; =============== S U B R O U T I N E =======================================
SendFMFreq: ; CODE XREF: UpdateFMTrack+Cp
bit 1, (ix+0)
ret nz
ld e, (ix+0Dh)
ld d, (ix+0Eh)
ld a, d
or e
jp z, loc_542
RefreshFMFreq: ; CODE XREF: UpdateFMTrack+18j
bit 2, (ix+0)
ret nz
ld h, 0
ld l, (ix+19h)
bit 7, l
jr z, loc_3FB
ld h, 0FFh
loc_3FB: ; CODE XREF: SendFMFreq+1Cj
add hl, de
ld c, h
ld a, (ix+1)
and 3
add a, 0A4h
rst zWriteFMIorII
ld c, l
sub 4
rst zWriteFMIorII
ret
; End of function SendFMFreq
; ---------------------------------------------------------------------------
PSGFreqs: dw 356h, 326h, 2F9h, 2CEh, 2A5h, 280h, 25Ch, 23Ah, 21Ah, 1FBh, 1DFh, 1C4h
; DATA XREF: RAM:loc_4EAr
dw 1ABh, 193h, 17Dh, 167h, 153h, 140h, 12Eh, 11Dh, 10Dh, 0FEh, 0EFh, 0E2h
dw 0D6h, 0C9h, 0BEh, 0B4h, 0A9h, 0A0h, 97h, 8Fh, 87h, 7Fh, 78h, 71h
dw 6Bh, 65h, 5Fh, 5Ah, 55h, 50h, 4Bh, 47h, 43h, 40h, 3Ch, 39h
dw 36h, 33h, 30h, 2Dh, 2Bh, 28h, 26h, 24h, 22h, 20h, 1Fh, 1Dh
dw 1Bh, 1Ah, 18h, 17h, 16h, 15h, 13h, 12h, 11h, 0
; =============== S U B R O U T I N E =======================================
UpdatePSGTrack: ; CODE XREF: RAM:00ABp RAM:00E3p
dec (ix+0Bh)
jr nz, loc_4A8
res 4, (ix+0)
call TrkUpdate_PSG
call SendPSGFreq
jp DoPSGNoteOn
; ---------------------------------------------------------------------------
loc_4A8: ; CODE XREF: UpdatePSGTrack+3j
call DoNoteStop
call DoVolEnv
call DoModulation
jp RefreshPSGFreq
; End of function UpdatePSGTrack
; =============== S U B R O U T I N E =======================================
TrkUpdate_PSG: ; CODE XREF: UpdatePSGTrack+9p
ld l, (ix+3)
ld h, (ix+4)
res 1, (ix+0)
loc_4BE: ; CODE XREF: TrkUpdate_PSG+13j
ld a, (hl)
inc hl
cp 0E0h
jr c, loc_4CA
call zCoordFlag
jp loc_4BE
; ---------------------------------------------------------------------------
loc_4CA: ; CODE XREF: TrkUpdate_PSG+Ej
or a
jp p, loc_4D7
call GetPSGFreq
ld a, (hl)
or a
jp m, FinishTrkUpdate
inc hl
loc_4D7: ; CODE XREF: TrkUpdate_PSG+17j
call TickMultiplier
jp FinishTrkUpdate
; End of function TrkUpdate_PSG
; ---------------------------------------------------------------------------
GetPSGFreq: ; CODE XREF: TrkUpdate_PSG+1Ap
sub 81h
jr c, loc_4F5
add a, (ix+5)
add a, a
add a, 0Ah
ld (loc_4EA+2), a
loc_4EA: ; DATA XREF: RAM:04E7w
ld de, (PSGFreqs)
ld (ix+0Dh), e
ld (ix+0Eh), d
ret
; ---------------------------------------------------------------------------
loc_4F5: ; CODE XREF: RAM:04DFj
set 1, (ix+0)
ld a, 0FFh
ld (ix+0Dh), a
ld (ix+0Eh), a
jp PSGNoteOff
; =============== S U B R O U T I N E =======================================
SendPSGFreq: ; CODE XREF: UpdatePSGTrack+Cp
bit 7, (ix+0Eh)
jr nz, loc_542
ld e, (ix+0Dh)
ld d, (ix+0Eh)
RefreshPSGFreq: ; CODE XREF: UpdatePSGTrack+1Bj
ld a, (ix+0)
and 6
ret nz
ld h, 0
ld l, (ix+19h)
bit 7, l
jr z, loc_521
ld h, 0FFh
loc_521: ; CODE XREF: SendPSGFreq+19j
add hl, de
ld a, (ix+1)
cp 0E0h
jr nz, loc_52B
ld a, 0C0h
loc_52B: ; CODE XREF: SendPSGFreq+23j
ld b, a
ld a, l
and 0Fh
or b
ld (7F11h), a
ld a, l
srl h
rra
srl h
rra
rra
rra
and 3Fh
ld (7F11h), a
ret
; ---------------------------------------------------------------------------
loc_542: ; CODE XREF: SendFMFreq+Dj
; SendPSGFreq+4j
set 1, (ix+0)
ret
; End of function SendPSGFreq
; =============== S U B R O U T I N E =======================================
DoVolEnv: ; CODE XREF: UpdatePSGTrack+15p
; FUNCTION CHUNK AT 059F SIZE 00000004 BYTES
ld a, (ix+8)
or a
ret z
DoPSGNoteOn: ; CODE XREF: UpdatePSGTrack+Fj
ld b, (ix+6)
ld a, (ix+8)
or a
jr z, SendPSGVolume
ld hl, VolEnvPtrs
dec a
add a, a
ld e, a
ld d, 0
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
add a, (ix+9)
ld l, a
adc a, h
sub l
ld h, a
ld a, (hl)
inc (ix+9)
or a
jp p, loc_574
cp 80h
jr z, loc_59F
loc_574: ; CODE XREF: DoVolEnv+26j
add a, b
cp 10h
jr c, loc_57B
ld a, 0Fh
loc_57B: ; CODE XREF: DoVolEnv+30j
ld b, a
; End of function DoVolEnv
; =============== S U B R O U T I N E =======================================
SendPSGVolume: ; CODE XREF: DoVolEnv+Cj DoFadeOut+57p ...
ld a, (ix+0)
and 6
ret nz
bit 4, (ix+0)
jr nz, loc_592
loc_588: ; CODE XREF: SendPSGVolume+1Aj
; SendPSGVolume+20j
ld a, (ix+1)
or b
add a, 10h
ld (7F11h), a
ret
; ---------------------------------------------------------------------------
loc_592: ; CODE XREF: SendPSGVolume+Aj
ld a, (ix+10h)
or a
jr z, loc_588
ld a, (ix+0Fh)
or a
jr nz, loc_588
ret
; End of function SendPSGVolume
; ---------------------------------------------------------------------------
; START OF FUNCTION CHUNK FOR DoVolEnv
loc_59F: ; CODE XREF: DoVolEnv+2Bj
dec (ix+9)
ret
; END OF FUNCTION CHUNK FOR DoVolEnv
; =============== S U B R O U T I N E =======================================
PSGNoteOff: ; CODE XREF: DoNoteStop+12j RAM:0501j ...
bit 2, (ix+0)
ret nz
ld a, (ix+1)
or 1Fh
ld (7F11h), a
ret
; End of function PSGNoteOff
; ---------------------------------------------------------------------------
; START OF FUNCTION CHUNK FOR StopAllSound
SilencePSG: ; CODE XREF: DoPause+Dj
; StopAllSound+23j ...
ld hl, 7F11h
ld (hl), 9Fh
ld (hl), 0BFh
ld (hl), 0DFh
ld (hl), 0FFh
ret
; END OF FUNCTION CHUNK FOR StopAllSound
; =============== S U B R O U T I N E =======================================
DoPause: ; CODE XREF: RAM:004Bp
jp m, UnpauseMusic ; 80-FF - request Unpause
cp 2 ; 02 - already paused?
ret z ; yes - return
ld (ix+3), 2 ; 01 - request Pause, set to 02
call SilenceFM
jp SilencePSG
; ---------------------------------------------------------------------------
UnpauseMusic: ; CODE XREF: DoPausej
push ix
ld (ix+3), 0
ld ix, 1B97h
ld b, 7
call sub_5FA
bankswitch SoundIndex
ld ix, 1D3Bh
ld b, 3
call sub_5FA
call zBankSwitchToMusic
pop ix
ret
; End of function DoPause
; =============== S U B R O U T I N E =======================================
sub_5FA: ; CODE XREF: DoPause+1Cp DoPause+34p ...
bit 7, (ix+0)
jr z, loc_619
bit 2, (ix+0)
jr nz, loc_619
ld c, (ix+7)
ld a, (ix+1)
and 3
add a, 0B4h ; '´'
rst 10h
push bc
ld a, (ix+8)
call SendFMIns
pop bc
loc_619: ; CODE XREF: sub_5FA+4j sub_5FA+Aj
ld de, 2Ah ; '*'
add ix, de
djnz sub_5FA
ret
; End of function sub_5FA
; =============== S U B R O U T I N E =======================================
DoSoundQueue: ; CODE XREF: RAM:006Ep
ld a, (byte_1B88)
cp 80h
ret nz ; Play Sound slot is full - return
ld hl, byte_1B89
ld a, (byte_1B80) ; 1B80 - current SFX Priority
ld c, a
ld b, 3
loc_630: ; CODE XREF: DoSoundQueue:loc_65Bj
ld a, (hl)
ld e, a
ld (hl), 0
inc hl
cp MusID__First
jr c, loc_65B
sub 0A0h
jr nc, loc_642
ld a, e
ld (byte_1B88), a
ret
; ---------------------------------------------------------------------------
loc_642: ; CODE XREF: DoSoundQueue+1Aj
push hl
add a, 30h ; add lower byte of 0F30 (SndPriorities)
ld l, a
adc a, 0Fh ; higher byte of 0F30 (SndPriorities)
sub l
ld h, a
ld a, (hl)
cp c
jr c, loc_653
ld c, a
ld a, e
ld (byte_1B88), a
loc_653: ; CODE XREF: DoSoundQueue+2Bj
pop hl
ld a, c
or a
ret m
ld (byte_1B80), a
ret
; ---------------------------------------------------------------------------
loc_65B: ; CODE XREF: DoSoundQueue+16j
djnz loc_630
ret
; End of function DoSoundQueue
; ---------------------------------------------------------------------------
PlaySoundID: ; CODE XREF: RAM:0076p
or a
jp z, StopAllSound
ret p ; 00-7F - Stop All
ld (ix+8), 80h
cp MusID__End
jp c, zPlayMusic ; 80-9F - Music
cp 0A0h
ret c
cp 0E1h
jp c, PlaySFX ; A0-E0 - SFX
cp 0F9h
ret c ; E2-F8 - unused
cp 0FEh
ret nc ; FE-FF - unused
PlaySnd_Command: ; F9-FD - Special Commands
sub 0F9h
add a, a
add a, a
ld (loc_681+1), a
loc_681: ; CODE XREF: RAM:loc_681j
; DATA XREF: RAM:067Ew
jr $
; ---------------------------------------------------------------------------
jp FadeOutMusic ; F9
; ---------------------------------------------------------------------------
nop
jp PlaySegaSound ; FA
; ---------------------------------------------------------------------------
nop
jp SpeedUpMusic ; FB
; ---------------------------------------------------------------------------