-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSGLib.asm
1152 lines (1151 loc) · 27.7 KB
/
PSGLib.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
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 4.0.0 #11528 (MINGW64)
;--------------------------------------------------------
.module PSGLib
.optsdcc -mz80
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
.globl _PSGSFXSubstringRetAddr
.globl _PSGSFXSubstringLen
.globl _PSGSFXLoopFlag
.globl _PSGSFXSkipFrames
.globl _PSGSFXLoopPoint
.globl _PSGSFXPointer
.globl _PSGSFXStart
.globl _PSGSFXStatus
.globl _PSGSFXChan3Volume
.globl _PSGSFXChan2Volume
.globl _PSGChannel3SFX
.globl _PSGChannel2SFX
.globl _PSGChan3LowTone
.globl _PSGChan2HighTone
.globl _PSGChan2LowTone
.globl _PSGChan3Volume
.globl _PSGChan2Volume
.globl _PSGChan1Volume
.globl _PSGChan0Volume
.globl _PSGMusicSubstringRetAddr
.globl _PSGMusicSubstringLen
.globl _PSGMusicVolumeAttenuation
.globl _PSGMusicLastLatch
.globl _PSGLoopFlag
.globl _PSGMusicSkipFrames
.globl _PSGMusicLoopPoint
.globl _PSGMusicPointer
.globl _PSGMusicStart
.globl _PSGMusicStatus
.globl _PSGStop
.globl _PSGResume
.globl _PSGPlay
.globl _PSGCancelLoop
.globl _PSGPlayNoRepeat
.globl _PSGGetStatus
.globl _PSGSilenceChannels
.globl _PSGRestoreVolumes
.globl _PSGSetMusicVolumeAttenuation
.globl _PSGSFXStop
.globl _PSGSFXPlay
.globl _PSGSFXCancelLoop
.globl _PSGSFXGetStatus
.globl _PSGSFXPlayLoop
.globl _PSGFrame
.globl _PSGSFXFrame
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
_PSGPort = 0x007f
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
.area _DATA
_PSGMusicStatus::
.ds 1
_PSGMusicStart::
.ds 2
_PSGMusicPointer::
.ds 2
_PSGMusicLoopPoint::
.ds 2
_PSGMusicSkipFrames::
.ds 1
_PSGLoopFlag::
.ds 1
_PSGMusicLastLatch::
.ds 1
_PSGMusicVolumeAttenuation::
.ds 1
_PSGMusicSubstringLen::
.ds 1
_PSGMusicSubstringRetAddr::
.ds 2
_PSGChan0Volume::
.ds 1
_PSGChan1Volume::
.ds 1
_PSGChan2Volume::
.ds 1
_PSGChan3Volume::
.ds 1
_PSGChan2LowTone::
.ds 1
_PSGChan2HighTone::
.ds 1
_PSGChan3LowTone::
.ds 1
_PSGChannel2SFX::
.ds 1
_PSGChannel3SFX::
.ds 1
_PSGSFXChan2Volume::
.ds 1
_PSGSFXChan3Volume::
.ds 1
_PSGSFXStatus::
.ds 1
_PSGSFXStart::
.ds 2
_PSGSFXPointer::
.ds 2
_PSGSFXLoopPoint::
.ds 2
_PSGSFXSkipFrames::
.ds 1
_PSGSFXLoopFlag::
.ds 1
_PSGSFXSubstringLen::
.ds 1
_PSGSFXSubstringRetAddr::
.ds 2
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
.area _INITIALIZED
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
.area _DABS (ABS)
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
.area _HOME
.area _GSINIT
.area _GSFINAL
.area _GSINIT
;--------------------------------------------------------
; Home
;--------------------------------------------------------
.area _HOME
.area _HOME
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area _CODE
;PSGLib.c:70: void PSGStop (void) {
; ---------------------------------
; Function PSGStop
; ---------------------------------
_PSGStop::
;PSGLib.c:74: if (PSGMusicStatus) {
ld a,(#_PSGMusicStatus + 0)
or a, a
ret Z
;PSGLib.c:75: PSGPort=PSGLatch|PSGChannel0|PSGVolumeData|0x0F; // latch channel 0, volume=0xF (silent)
ld a, #0x9f
out (_PSGPort), a
;PSGLib.c:76: PSGPort=PSGLatch|PSGChannel1|PSGVolumeData|0x0F; // latch channel 1, volume=0xF (silent)
ld a, #0xbf
out (_PSGPort), a
;PSGLib.c:77: if (!PSGChannel2SFX)
ld a,(#_PSGChannel2SFX + 0)
or a, a
jr NZ,00102$
;PSGLib.c:78: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|0x0F; // latch channel 2, volume=0xF (silent)
ld a, #0xdf
out (_PSGPort), a
00102$:
;PSGLib.c:79: if (!PSGChannel3SFX)
ld a,(#_PSGChannel3SFX + 0)
or a, a
jr NZ,00104$
;PSGLib.c:80: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|0x0F; // latch channel 3, volume=0xF (silent)
ld a, #0xff
out (_PSGPort), a
00104$:
;PSGLib.c:81: PSGMusicStatus=PSG_STOPPED;
ld hl,#_PSGMusicStatus + 0
ld (hl), #0x00
;PSGLib.c:83: }
ret
;PSGLib.c:85: void PSGResume (void) {
; ---------------------------------
; Function PSGResume
; ---------------------------------
_PSGResume::
;PSGLib.c:89: if (!PSGMusicStatus) {
ld a,(#_PSGMusicStatus + 0)
or a, a
ret NZ
;PSGLib.c:90: PSGPort=PSGLatch|PSGChannel0|PSGVolumeData|PSGChan0Volume; // restore channel 0 volume
ld a,(#_PSGChan0Volume + 0)
or a, #0x90
out (_PSGPort), a
;PSGLib.c:91: PSGPort=PSGLatch|PSGChannel1|PSGVolumeData|PSGChan1Volume; // restore channel 1 volume
ld a,(#_PSGChan1Volume + 0)
or a, #0xb0
out (_PSGPort), a
;PSGLib.c:92: if (!PSGChannel2SFX) {
ld a,(#_PSGChannel2SFX + 0)
or a, a
jr NZ,00102$
;PSGLib.c:93: PSGPort=PSGLatch|PSGChannel2|(PSGChan2LowTone&0x0F); // restore channel 2 frequency
ld a,(#_PSGChan2LowTone + 0)
and a, #0x0f
or a, #0xc0
out (_PSGPort), a
;PSGLib.c:94: PSGPort=PSGChan2HighTone&0x3F;
ld a,(#_PSGChan2HighTone + 0)
and a, #0x3f
out (_PSGPort), a
;PSGLib.c:95: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|PSGChan2Volume; // restore channel 2 volume
ld a,(#_PSGChan2Volume + 0)
or a, #0xd0
out (_PSGPort), a
00102$:
;PSGLib.c:97: if (!PSGChannel3SFX) {
ld a,(#_PSGChannel3SFX + 0)
or a, a
jr NZ,00104$
;PSGLib.c:98: PSGPort=PSGLatch|PSGChannel3|(PSGChan3LowTone&0x0F); // restore channel 3 frequency
ld a,(#_PSGChan3LowTone + 0)
and a, #0x0f
or a, #0xe0
out (_PSGPort), a
;PSGLib.c:99: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|PSGChan3Volume; // restore channel 3 volume
ld a,(#_PSGChan3Volume + 0)
or a, #0xf0
out (_PSGPort), a
00104$:
;PSGLib.c:101: PSGMusicStatus=PSG_PLAYING;
ld hl,#_PSGMusicStatus + 0
ld (hl), #0x01
;PSGLib.c:103: }
ret
;PSGLib.c:105: void PSGPlay (void *song) {
; ---------------------------------
; Function PSGPlay
; ---------------------------------
_PSGPlay::
;PSGLib.c:109: PSGStop();
call _PSGStop
;PSGLib.c:110: PSGLoopFlag=1;
ld hl,#_PSGLoopFlag + 0
ld (hl), #0x01
;PSGLib.c:111: PSGMusicStart=song; // store the begin point of music
pop de
pop bc
push bc
push de
ld (_PSGMusicStart), bc
;PSGLib.c:112: PSGMusicPointer=song; // set music pointer to begin of music
ld (_PSGMusicPointer), bc
;PSGLib.c:113: PSGMusicLoopPoint=song; // looppointer points to begin too
ld (_PSGMusicLoopPoint), bc
;PSGLib.c:115: PSGMusicSkipFrames=0; // reset the skip frames
ld hl,#_PSGMusicSkipFrames + 0
ld (hl), #0x00
;PSGLib.c:116: PSGMusicSubstringLen=0; // reset the substring len (for compression)
ld hl,#_PSGMusicSubstringLen + 0
ld (hl), #0x00
;PSGLib.c:117: PSGMusicLastLatch=PSGLatch|PSGChannel0|PSGVolumeData|0x0F; // latch channel 0, volume=0xF (silent)
ld hl,#_PSGMusicLastLatch + 0
ld (hl), #0x9f
;PSGLib.c:118: PSGMusicStatus=PSG_PLAYING;
ld hl,#_PSGMusicStatus + 0
ld (hl), #0x01
;PSGLib.c:119: }
ret
;PSGLib.c:121: void PSGCancelLoop (void) {
; ---------------------------------
; Function PSGCancelLoop
; ---------------------------------
_PSGCancelLoop::
;PSGLib.c:125: PSGLoopFlag=0;
ld hl,#_PSGLoopFlag + 0
ld (hl), #0x00
;PSGLib.c:126: }
ret
;PSGLib.c:128: void PSGPlayNoRepeat (void *song) {
; ---------------------------------
; Function PSGPlayNoRepeat
; ---------------------------------
_PSGPlayNoRepeat::
;PSGLib.c:132: PSGPlay(song);
pop bc
pop hl
push hl
push bc
push hl
call _PSGPlay
pop af
;PSGLib.c:133: PSGLoopFlag=0;
ld hl,#_PSGLoopFlag + 0
ld (hl), #0x00
;PSGLib.c:134: }
ret
;PSGLib.c:136: unsigned char PSGGetStatus (void) {
; ---------------------------------
; Function PSGGetStatus
; ---------------------------------
_PSGGetStatus::
;PSGLib.c:140: return(PSGMusicStatus);
ld iy, #_PSGMusicStatus
ld l, 0 (iy)
;PSGLib.c:141: }
ret
;PSGLib.c:143: void PSGSilenceChannels (void) {
; ---------------------------------
; Function PSGSilenceChannels
; ---------------------------------
_PSGSilenceChannels::
;PSGLib.c:147: PSGPort=PSGLatch|PSGChannel0|PSGVolumeData|0x0F;
ld a, #0x9f
out (_PSGPort), a
;PSGLib.c:148: PSGPort=PSGLatch|PSGChannel1|PSGVolumeData|0x0F;
ld a, #0xbf
out (_PSGPort), a
;PSGLib.c:149: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|0x0F;
ld a, #0xdf
out (_PSGPort), a
;PSGLib.c:150: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|0x0F;
ld a, #0xff
out (_PSGPort), a
;PSGLib.c:151: }
ret
;PSGLib.c:153: void PSGRestoreVolumes (void) {
; ---------------------------------
; Function PSGRestoreVolumes
; ---------------------------------
_PSGRestoreVolumes::
push ix
ld ix,#0
add ix,sp
push af
;PSGLib.c:158: PSGPort=PSGLatch|PSGChannel0|PSGVolumeData|(((PSGChan0Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan0Volume&0x0F)+PSGMusicVolumeAttenuation);
ld iy, #_PSGMusicVolumeAttenuation
ld a, 0 (iy)
ld -2 (ix), a
xor a, a
ld -1 (ix), a
ld c, 0 (iy)
;PSGLib.c:157: if (PSGMusicStatus) {
ld a,(#_PSGMusicStatus + 0)
or a, a
jr Z,00102$
;PSGLib.c:158: PSGPort=PSGLatch|PSGChannel0|PSGVolumeData|(((PSGChan0Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan0Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan0Volume + 0)
and a, #0x0f
ld e, a
ld d, #0x00
pop hl
push hl
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00168$
xor a, #0x80
00168$:
jp P, 00115$
ld de, #0x000f
jr 00116$
00115$:
ld a,(#_PSGChan0Volume + 0)
and a, #0x0f
add a, c
ld e, a
rla
sbc a, a
00116$:
ld a, e
or a, #0x90
out (_PSGPort), a
;PSGLib.c:159: PSGPort=PSGLatch|PSGChannel1|PSGVolumeData|(((PSGChan1Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan1Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan1Volume + 0)
and a, #0x0f
ld e, a
ld d, #0x00
pop hl
push hl
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00169$
xor a, #0x80
00169$:
jp P, 00117$
ld de, #0x000f
jr 00118$
00117$:
ld a,(#_PSGChan1Volume + 0)
and a, #0x0f
add a, c
ld e, a
rla
sbc a, a
00118$:
ld a, e
or a, #0xb0
out (_PSGPort), a
00102$:
;PSGLib.c:161: if (PSGChannel2SFX)
ld a,(#_PSGChannel2SFX + 0)
or a, a
jr Z,00106$
;PSGLib.c:162: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|PSGSFXChan2Volume;
ld a,(#_PSGSFXChan2Volume + 0)
or a, #0xd0
out (_PSGPort), a
jr 00107$
00106$:
;PSGLib.c:163: else if (PSGMusicStatus)
ld a,(#_PSGMusicStatus + 0)
or a, a
jr Z,00107$
;PSGLib.c:164: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|(((PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan2Volume + 0)
and a, #0x0f
ld e, a
ld d, #0x00
pop hl
push hl
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00170$
xor a, #0x80
00170$:
jp P, 00119$
ld de, #0x000f
jr 00120$
00119$:
ld a,(#_PSGChan2Volume + 0)
and a, #0x0f
add a, c
ld e, a
rla
sbc a, a
00120$:
ld a, e
or a, #0xd0
out (_PSGPort), a
00107$:
;PSGLib.c:165: if (PSGChannel3SFX)
ld a,(#_PSGChannel3SFX + 0)
or a, a
jr Z,00111$
;PSGLib.c:166: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|PSGSFXChan3Volume;
ld a,(#_PSGSFXChan3Volume + 0)
or a, #0xf0
out (_PSGPort), a
jr 00113$
00111$:
;PSGLib.c:167: else if (PSGMusicStatus)
ld a,(#_PSGMusicStatus + 0)
or a, a
jr Z,00113$
;PSGLib.c:168: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|(((PSGChan3Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan3Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan3Volume + 0)
and a, #0x0f
ld l, a
ld h, #0x00
pop de
push de
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00171$
xor a, #0x80
00171$:
jp P, 00121$
ld bc, #0x000f
jr 00122$
00121$:
ld a,(#_PSGChan3Volume + 0)
and a, #0x0f
add a, c
ld c, a
rla
sbc a, a
00122$:
ld a, c
or a, #0xf0
out (_PSGPort), a
00113$:
;PSGLib.c:169: }
ld sp, ix
pop ix
ret
;PSGLib.c:171: void PSGSetMusicVolumeAttenuation (unsigned char attenuation) {
; ---------------------------------
; Function PSGSetMusicVolumeAttenuation
; ---------------------------------
_PSGSetMusicVolumeAttenuation::
push ix
ld ix,#0
add ix,sp
push af
;PSGLib.c:175: PSGMusicVolumeAttenuation=attenuation;
ld a, 4 (ix)
ld (#_PSGMusicVolumeAttenuation + 0),a
;PSGLib.c:176: if (PSGMusicStatus) {
ld a,(#_PSGMusicStatus + 0)
or a, a
jp Z, 00107$
;PSGLib.c:177: PSGPort=PSGLatch|PSGChannel0|PSGVolumeData|(((PSGChan0Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan0Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan0Volume + 0)
and a, #0x0f
ld c, a
ld e, #0x00
ld iy, #_PSGMusicVolumeAttenuation
ld a, 0 (iy)
ld -2 (ix), a
xor a, a
ld -1 (ix), a
ld a, c
add a, -2 (ix)
ld b, a
ld a, e
adc a, -1 (ix)
ld e, a
ld c, 0 (iy)
ld a, #0x0f
cp a, b
ld a, #0x00
sbc a, e
jp PO, 00152$
xor a, #0x80
00152$:
jp P, 00109$
ld de, #0x000f
jr 00110$
00109$:
ld a,(#_PSGChan0Volume + 0)
and a, #0x0f
add a, c
ld e, a
rla
sbc a, a
00110$:
ld a, e
or a, #0x90
out (_PSGPort), a
;PSGLib.c:178: PSGPort=PSGLatch|PSGChannel1|PSGVolumeData|(((PSGChan1Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan1Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan1Volume + 0)
and a, #0x0f
ld e, a
ld d, #0x00
pop hl
push hl
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00153$
xor a, #0x80
00153$:
jp P, 00111$
ld de, #0x000f
jr 00112$
00111$:
ld a,(#_PSGChan1Volume + 0)
and a, #0x0f
add a, c
ld e, a
rla
sbc a, a
00112$:
ld a, e
or a, #0xb0
out (_PSGPort), a
;PSGLib.c:179: if (!PSGChannel2SFX)
ld a,(#_PSGChannel2SFX + 0)
or a, a
jr NZ,00102$
;PSGLib.c:180: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|(((PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan2Volume + 0)
and a, #0x0f
ld l, a
ld h, #0x00
pop de
push de
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00154$
xor a, #0x80
00154$:
jp P, 00113$
ld de, #0x000f
jr 00114$
00113$:
ld a,(#_PSGChan2Volume + 0)
and a, #0x0f
add a, c
ld e, a
rla
sbc a, a
00114$:
ld a, e
or a, #0xd0
out (_PSGPort), a
00102$:
;PSGLib.c:181: if (!PSGChannel3SFX)
ld a,(#_PSGChannel3SFX + 0)
or a, a
jr NZ,00107$
;PSGLib.c:182: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|(((PSGChan3Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan3Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan3Volume + 0)
and a, #0x0f
ld l, a
ld h, #0x00
pop de
push de
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00155$
xor a, #0x80
00155$:
jp P, 00115$
ld bc, #0x000f
jr 00116$
00115$:
ld a,(#_PSGChan3Volume + 0)
and a, #0x0f
add a, c
ld c, a
rla
sbc a, a
00116$:
ld a, c
or a, #0xf0
out (_PSGPort), a
00107$:
;PSGLib.c:184: }
ld sp, ix
pop ix
ret
;PSGLib.c:186: void PSGSFXStop (void) {
; ---------------------------------
; Function PSGSFXStop
; ---------------------------------
_PSGSFXStop::
push ix
ld ix,#0
add ix,sp
push af
;PSGLib.c:190: if (PSGSFXStatus) {
ld a,(#_PSGSFXStatus + 0)
or a, a
jp Z, 00113$
;PSGLib.c:195: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|(((PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation);
ld iy, #_PSGMusicVolumeAttenuation
ld a, 0 (iy)
ld -2 (ix), a
xor a, a
ld -1 (ix), a
ld c, 0 (iy)
;PSGLib.c:191: if (PSGChannel2SFX) {
ld a,(#_PSGChannel2SFX + 0)
or a, a
jr Z,00105$
;PSGLib.c:192: if (PSGMusicStatus) {
ld a,(#_PSGMusicStatus + 0)
or a, a
jr Z,00102$
;PSGLib.c:193: PSGPort=PSGLatch|PSGChannel2|(PSGChan2LowTone&0x0F);
ld a,(#_PSGChan2LowTone + 0)
and a, #0x0f
or a, #0xc0
out (_PSGPort), a
;PSGLib.c:194: PSGPort=PSGChan2HighTone&0x3F;
ld a,(#_PSGChan2HighTone + 0)
and a, #0x3f
out (_PSGPort), a
;PSGLib.c:195: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|(((PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan2Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan2Volume + 0)
and a, #0x0f
ld e, a
ld d, #0x00
pop hl
push hl
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00154$
xor a, #0x80
00154$:
jp P, 00115$
ld de, #0x000f
jr 00116$
00115$:
ld a,(#_PSGChan2Volume + 0)
and a, #0x0f
add a, c
ld e, a
rla
sbc a, a
00116$:
ld a, e
or a, #0xd0
out (_PSGPort), a
jr 00103$
00102$:
;PSGLib.c:197: PSGPort=PSGLatch|PSGChannel2|PSGVolumeData|0x0F;
ld a, #0xdf
out (_PSGPort), a
00103$:
;PSGLib.c:199: PSGChannel2SFX=PSG_STOPPED;
ld hl,#_PSGChannel2SFX + 0
ld (hl), #0x00
00105$:
;PSGLib.c:202: if (PSGChannel3SFX) {
ld a,(#_PSGChannel3SFX + 0)
or a, a
jr Z,00110$
;PSGLib.c:203: if (PSGMusicStatus) {
ld a,(#_PSGMusicStatus + 0)
or a, a
jr Z,00107$
;PSGLib.c:204: PSGPort=PSGLatch|PSGChannel3|(PSGChan3LowTone&0x0F);
ld a,(#_PSGChan3LowTone + 0)
and a, #0x0f
or a, #0xe0
out (_PSGPort), a
;PSGLib.c:205: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|(((PSGChan3Volume&0x0F)+PSGMusicVolumeAttenuation>15)?15:(PSGChan3Volume&0x0F)+PSGMusicVolumeAttenuation);
ld a,(#_PSGChan3Volume + 0)
and a, #0x0f
ld l, a
ld h, #0x00
pop de
push de
add hl, de
ld a, #0x0f
cp a, l
ld a, #0x00
sbc a, h
jp PO, 00155$
xor a, #0x80
00155$:
jp P, 00117$
ld bc, #0x000f
jr 00118$
00117$:
ld a,(#_PSGChan3Volume + 0)
and a, #0x0f
add a, c
ld c, a
rla
sbc a, a
00118$:
ld a, c
or a, #0xf0
out (_PSGPort), a
jr 00108$
00107$:
;PSGLib.c:207: PSGPort=PSGLatch|PSGChannel3|PSGVolumeData|0x0F;
ld a, #0xff
out (_PSGPort), a
00108$:
;PSGLib.c:209: PSGChannel3SFX=PSG_STOPPED;
ld hl,#_PSGChannel3SFX + 0
ld (hl), #0x00
00110$:
;PSGLib.c:211: PSGSFXStatus=PSG_STOPPED;
ld hl,#_PSGSFXStatus + 0
ld (hl), #0x00
00113$:
;PSGLib.c:213: }
ld sp, ix
pop ix
ret
;PSGLib.c:215: void PSGSFXPlay (void *sfx, unsigned char channels) {
; ---------------------------------
; Function PSGSFXPlay
; ---------------------------------
_PSGSFXPlay::
;PSGLib.c:220: PSGSFXStop();
call _PSGSFXStop
;PSGLib.c:221: PSGSFXLoopFlag=0;
ld hl,#_PSGSFXLoopFlag + 0
ld (hl), #0x00
;PSGLib.c:222: PSGSFXStart=sfx; // store begin of SFX
pop de
pop bc
push bc
push de
ld (_PSGSFXStart), bc
;PSGLib.c:223: PSGSFXPointer=sfx; // set the pointer to begin of SFX
ld (_PSGSFXPointer), bc
;PSGLib.c:224: PSGSFXLoopPoint=sfx; // looppointer points to begin too
ld (_PSGSFXLoopPoint), bc
;PSGLib.c:225: PSGSFXSkipFrames=0; // reset the skip frames
ld hl,#_PSGSFXSkipFrames + 0
ld (hl), #0x00
;PSGLib.c:226: PSGSFXSubstringLen=0; // reset the substring len
ld hl,#_PSGSFXSubstringLen + 0
ld (hl), #0x00
;PSGLib.c:227: PSGChannel2SFX=(channels&SFX_CHANNEL2)?PSG_PLAYING:PSG_STOPPED;
ld hl, #4+0
add hl, sp
ld c, (hl)
bit 0, c
jr Z,00103$
ld de, #0x0001
jr 00104$
00103$:
ld de, #0x0000
00104$:
ld hl,#_PSGChannel2SFX + 0
ld (hl), e
;PSGLib.c:228: PSGChannel3SFX=(channels&SFX_CHANNEL3)?PSG_PLAYING:PSG_STOPPED;
bit 1, c
jr Z,00105$
ld bc, #0x0001
jr 00106$
00105$:
ld bc, #0x0000
00106$:
ld hl,#_PSGChannel3SFX + 0
ld (hl), c
;PSGLib.c:229: PSGSFXStatus=PSG_PLAYING;
ld hl,#_PSGSFXStatus + 0
ld (hl), #0x01
;PSGLib.c:230: }
ret
;PSGLib.c:232: void PSGSFXCancelLoop (void) {
; ---------------------------------
; Function PSGSFXCancelLoop
; ---------------------------------
_PSGSFXCancelLoop::
;PSGLib.c:236: PSGSFXLoopFlag=0;
ld hl,#_PSGSFXLoopFlag + 0
ld (hl), #0x00
;PSGLib.c:237: }
ret
;PSGLib.c:239: unsigned char PSGSFXGetStatus (void) {
; ---------------------------------
; Function PSGSFXGetStatus
; ---------------------------------
_PSGSFXGetStatus::
;PSGLib.c:243: return(PSGSFXStatus);
ld iy, #_PSGSFXStatus
ld l, 0 (iy)
;PSGLib.c:244: }
ret
;PSGLib.c:246: void PSGSFXPlayLoop (void *sfx, unsigned char channels) {
; ---------------------------------
; Function PSGSFXPlayLoop
; ---------------------------------
_PSGSFXPlayLoop::
;PSGLib.c:251: PSGSFXPlay(sfx, channels);
ld iy, #4
add iy, sp
ld a, 0 (iy)
push af
inc sp
dec iy
dec iy
ld l, 0 (iy)
ld h, 1 (iy)
push hl
call _PSGSFXPlay
pop af
inc sp
;PSGLib.c:252: PSGSFXLoopFlag=1;
ld hl,#_PSGSFXLoopFlag + 0
ld (hl), #0x01
;PSGLib.c:253: }
ret
;PSGLib.c:255: void PSGFrame (void) {
; ---------------------------------
; Function PSGFrame
; ---------------------------------
_PSGFrame::
;PSGLib.c:450: __endasm;
ld a,(_PSGMusicStatus) ; check if we have got to play a tune
or a
ret z
ld a,(_PSGMusicSkipFrames) ; check if we have got to skip frames
or a
jp nz,_skipFrame
ld hl,(_PSGMusicPointer) ; read current address
_intLoop:
ld b,(hl) ; load PSG byte (in B)
inc hl ; point to next byte
ld a,(_PSGMusicSubstringLen) ; read substring len
or a
jr z,_continue ; check if it is 0 (we are not in a substring)
dec a ; decrease len
ld (_PSGMusicSubstringLen),a ; save len
jr nz,_continue
ld hl,(_PSGMusicSubstringRetAddr) ; substring is over, retrieve return address
_continue:
ld a,b ; copy PSG byte into A
cp #0x80 ; is it a latch?
jr c,_noLatch ; if < $80 then it is NOT a latch
ld (_PSGMusicLastLatch),a ; it is a latch - save it in "LastLatch"
; we have got the latch PSG byte both in A and in B
; and we have to check if the value should pass to PSG or not
bit 4,a ; test if it is a volume
jr nz,_latch_Volume ; jump if volume data
bit 6,a ; test if the latch it is for channels 0-1 or for 2-3
jp z,_send2PSG_A ; send data to PSG if it is for channels 0-1
; we have got the latch (tone, chn 2 or 3) PSG byte both in A and in B
; and we have to check if the value should be passed to PSG or not
bit 5,a ; test if tone it is for channel 2 or 3
jr z,_ifchn2 ; jump if channel 2
ld (_PSGChan3LowTone),a ; save tone LOW data
ld a,(_PSGChannel3SFX) ; channel 3 free?
or a
jp nz,_intLoop
ld a,(_PSGChan3LowTone)
and #3 ; test if channel 3 is set to use the frequency of channel 2
cp #3
jr nz,_send2PSG_B ; if channel 3 does not use frequency of channel 2 jump
ld a,(_PSGSFXStatus) ; test if an SFX is playing
or a
jr z,_send2PSG_B ; if no SFX is playing jump
ld (_PSGChannel3SFX),a ; otherwise mark channel 3 as occupied
ld a,#0x80|#0b01100000|#0b00010000|#0x0F ; and silence channel 3
out (#0x7f),a
jp _intLoop
_ifchn2:
ld (_PSGChan2LowTone),a ; save tone LOW data
ld a,(_PSGChannel2SFX) ; channel 2 free?
or a
jr z,_send2PSG_B
jp _intLoop
_latch_Volume:
bit 6,a ; test if the latch it is for channels 0-1 or for 2-3
jr nz,_latch_Volume_23 ; volume is for channel 2 or 3
bit 5,a ; test if volume it is for channel 0 or 1
jr z,_chn0 ; jump for channel 0
ld (_PSGChan1Volume),a ; save volume data
jp _sendVolume2PSG_A
_chn0:
ld (_PSGChan0Volume),a ; save volume data
jp _sendVolume2PSG_A
_latch_Volume_23:
bit 5,a ; test if volume it is for channel 2 or 3
jr z,_chn2 ; jump for channel 2
ld (_PSGChan3Volume),a ; save volume data
ld a,(_PSGChannel3SFX) ; channel 3 free?
or a
jr z,_sendVolume2PSG_B
jp _intLoop
_chn2:
ld (_PSGChan2Volume),a ; save volume data
ld a,(_PSGChannel2SFX) ; channel 2 free?
or a
jr z,_sendVolume2PSG_B
jp _intLoop
_skipFrame:
dec a
ld (_PSGMusicSkipFrames),a
ret
_noLatch:
cp #0x40
jr c,_command ; if < $40 then it is a command
; it is a data
ld a,(_PSGMusicLastLatch) ; retrieve last latch
jp _output_NoLatch
_command:
cp #0x38
jr z,_done ; no additional frames
jr c,_otherCommands ; other commands?
and #0x07 ; take only the last 3 bits for skip frames
ld (_PSGMusicSkipFrames),a ; we got additional frames
_done:
ld (_PSGMusicPointer),hl ; save current address
ret ; frame done
_otherCommands:
cp #0x08
jr nc,_substring
cp #0x00
jr z,_musicLoop
cp #0x01
jr z,_setLoopPoint
; ***************************************************************************
; we should never get here!
; if we do, it means the PSG file is probably corrupted, so we just RET
; ***************************************************************************
ret