-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaymodx.txt
3765 lines (3765 loc) · 236 KB
/
playmodx.txt
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
1 ; ****************************************************************************
2 ; playmod3.asm (for MSDOS)
3 ; ----------------------------------------------------------------------------
4 ; PLAYMOD3.COM ! ICH AC97 MOD PLAYER & VGA DEMO program by Erdogan TAN
5 ;
6 ; 18/02/2017
7 ;
8 ; [ Last Modification: 19/05/2024 ]
9 ;
10 ; Derived from source code of 'PLAYWAV.COM' ('PLAYWAV.ASM') by Erdogan Tan
11 ; (17/02/2017)
12 ; Modified from 'PLAYMOD2.COM' ('playmod2.asm') source code
13 ; AC97 MOD PLAYER & VGA DEMO program (tuneloop version)
14 ; by Erdogan TAN (12/05/2024)
15 ;
16 ; Derived from source code of 'PLAY.EXE' (TINYPLAY) by Carlos Hasan (1993)
17 ; PLAY.EXE: PLAY.ASM, MODLOAD.ASM, MODPLAY.ASM, SB.ASM
18 ;
19 ; Assembler: NASM 2.15
20 ; ----------------------------------------------------------------------------
21 ; nasm playmod3.asm -l playmod3.lst -o PLAYMOD3.COM
22 ; ****************************************************************************
23
24 ; Tiny MOD Player v0.1b by Carlos Hasan.
25 ; July 14th, 1993.
26
27 ;=============================================================================
28 ; PLAYWAV.ASM / PLAYER.ASM / TINYPLAY.ASM
29 ;=============================================================================
30 ; Audio controller, codec & PCI functions are derived from '.wav file player
31 ; for DOS' source code by Jeff Leyda (PLAYER.EXE), Sep 02, 2002.
32
33 ; AC97 Interrupt version ; 12/05/2024
34
35 [BITS 16]
36 [org 100h]
37
38 Start:
39 ; 15/05/2024
40 ; 13/05/2024
41 ; Clear BSS (uninitialized data) area
42 ;xor ax, ax ; 0
43 ;mov cx, (EOF - bss_start)/2
44 ;mov di, bss_start
45 ;rep stosw
46
47 00000000 E8C900 call DetectICH ; Detect AC97 Audio Device
48 GetFileName: ; Parse the Command line...
49 00000003 BE8000 mov si, 80h
50 00000006 8A1C mov bl, [si]
51 00000008 30FF xor bh, bh
52 0000000A 43 inc bx
53 0000000B C60000 mov byte [si+bx], 0 ; make AsciiZ filename.
54 0000000E 46 inc si
55 ScanName:
56 0000000F AC lodsb
57 00000010 84C0 test al, al
58 00000012 0F84AC00 je pmsg_2017
59 00000016 3C20 cmp al, 20h
60 00000018 74F5 je short ScanName ; scan start of name.
61 0000001A 89F7 mov di, si
62 0000001C 4F dec di
63 ScanPeriod:
64 0000001D AC lodsb
65 0000001E 3C2E cmp al, '.' ; if period NOT found,
66 00000020 7410 je short PrintMesg ; then add a .MOD extension.
67 00000022 84C0 test al, al
68 00000024 75F7 jnz short ScanPeriod
69 00000026 4E dec si
70 SetExt:
71 ;mov byte [si+0], '.'
72 ;mov byte [si+1], 'M'
73 ;mov byte [si+2], 'O'
74 ;mov byte [si+3], 'D'
75 00000027 66C7042E4D4F44 mov dword [si], '.MOD'
76 0000002E C6440400 mov byte [si+4], 0
77
78 PrintMesg:
79 00000032 B80009 mov ax, 0900h ; Prints the Credits Text.
80 ;lea dx, [Credits]
81 00000035 BA[880E] mov dx, Credits
82 00000038 CD21 int 21h
83
84 ; 13/05/2024
85 0000003A E8AC0C call write_ac97_dev_info
86 0000003D B80009 mov ax, 0900h ; Prints the Credits Text.
87 00000040 BA[B90E] mov dx, CRLF
88 00000043 CD21 int 21h
89 LoadMod:
90 ; es:di = Filename address
91 00000045 06 push es
92 00000046 57 push di
93 00000047 E8A105 call LoadModule ; Load the MODule...
94
95 0000004A 833E[7261]00 cmp word [ErrorInfo], 0 ; any error loading?
96 0000004F 740A je short init_codec
97
98 00000051 B80009 mov ax, 0900h ; yes, print error and Exit.
99 ;lea dx, [ErrorMesg]
100 00000054 BA[BC0E] mov dx, ErrorMesg
101 00000057 CD21 int 21h
102 00000059 EB60 jmp Exit
103
104 init_codec:
105 ; 13/05/2024
106 ;call write_ac97_dev_info
107
108 ; 08/05/2024
109 ; 17/02/2017
110 ;mov dx, [stats_cmd]
111 ;or dl, IO_ENA+BM_ENA ; enable IO and bus master
112 ;call pciRegWrite16 ; pciRegWrite8
113
114 ; 18/02/2017
115 ;mov word [sample_rate], 22050 ; Mixing at 22.050 kHz
116 ; 15/05/2024
117 0000005B C706[B065]C05D mov word [sample_rate], 24000
118 ; 16/05/2024
119 ;mov word [sample_rate], 16000
120
121 ; 08/05/2024
122 ; (48 kHZ mixing is necessary
123 ; if the AC97 hardware/codec has not got VRA feature)
124 ; ((or frequency converting code would be needed))
125 ;mov word [sample_rate], 48000 ; Mixing at 48 kHz
126
127 ; setup the Codec (actually mixer registers)
128 00000061 E87F02 call codecConfig ; unmute codec, set rates.
129 00000064 731A jnc short PlayNow
130
131 _codec_err:
132 00000066 0E push cs
133 00000067 1F pop ds
134 00000068 BA[7100] mov dx, CodecErrMsg
135 0000006B B409 mov ah, 9
136 0000006D CD21 int 21h
137 0000006F EB4A jmp Exit
138
139 00000071 436F64656320457272- CodecErrMsg db "Codec Error!"
139 0000007A 6F7221
140 0000007D 0D0A24 db CR,LF,"$"
141 PlayNow:
142 00000080 B8[7010] mov ax, BdlBuffer
143 00000083 A3[5E10] mov [BDL_BUFFER], ax
144
145 00000086 B8[7011] mov ax, DmaBuffer ; DmaBuffer (4096 bytes) buff addr
146 00000089 A3[6010] mov [DMA_BUFFER1], ax ; 2048 byte half buffer 1
147
148 0000008C 050028 add ax, BUFFERSIZE ; code/current segment
149 0000008F A3[6210] mov [DMA_BUFFER2], ax ; 2048 byte half buffer 2
150
151 ;mov word [MixSpeed], 22050 ; Mixing at 22.050 kHz
152
153 00000092 E8240B call StartPlaying
154
155 00000095 B81300 mov ax, 0013h ; Set Mode 320x200x256
156 00000098 CD10 int 10h
157
158 0000009A B98000 mov cx, 128 ; Make a lookup table
159 0000009D 31DB xor bx, bx ; for fastest pixel
160 0000009F BA002D mov dx, 320*(100-64) ; addressing.
161 MakeOfs:
162 000000A2 8997[80C2] mov [RowOfs+bx], dx
163 000000A6 8997[82C2] mov [RowOfs+bx+2], dx
164 000000AA 81C24001 add dx, 320
165 000000AE 83C304 add bx, 4
166 000000B1 E2EF loop MakeOfs
167
168 ; Note: Normally IRQ 0 calls the ModPlay Polling at 18.2Hz thru
169 ; the software interrupt 1Ch. If the IRQ 0 is disabled, then
170 ; the INT 1Ch MUST BE CALLED at least MixSpeed/1024 times per
171 ; second, or the module will sound "looped".
172 ; Because we need better sync with the ModPlayer to draw the scope,
173 ; the polling is called from my routine, and then the irq 0 must be
174 ; disabled. The [DmaBuffer] points to the current buffer of 8-bit
175 ; samples played by the Sound Blaster. Note that some samples are
176 ; discarded in the next code, just for fun!
177
178 ;in al, 21h ; disable irq 0!
179 ;or al, 00000001b
180 ;out 21h, al
181
182 000000B3 E8ED03 call ModPlay ; 13/02/2017
183
184 ;in al, 21h ; enable irq 0!
185 ;and al, 11111110b
186 ;out 21h, al
187
188 000000B6 B80300 mov ax, 0003h ; Set Text Mode 80x25x16
189 000000B9 CD10 int 10h
190
191 ; 16/05/2024
192 ;call StopPlaying ; STOP!
193 Exit:
194 ;call FreeModule ; Free MODule core.
195 error_exit:
196 000000BB B8004C mov ax, 4C00h ; Bye!
197 000000BE CD21 int 21h
198 here:
199 000000C0 EBFE jmp short here
200
201 pmsg_2017:
202 000000C2 B80009 mov ax, 0900h ; Prints the Credits Text.
203 ;lea dx, [msg_2017]
204 000000C5 BA[280E] mov dx, msg_2017
205 000000C8 CD21 int 21h
206 000000CA EBEF jmp short Exit
207
208 DetectICH:
209 ; 18/02/2017
210 ; Detech Intel ICH based AC97 Audio Device
211 000000CC E8D301 call pciFindDevice ; AC97.ASM (PLAYWAV.COM)
212 000000CF 733F jnc short _1
213
214 ; couldn't find the audio device!
215 ;push cs
216 ;pop ds
217 000000D1 BA[DA00] mov dx, noDevMsg
218 000000D4 B409 mov ah, 9
219 000000D6 CD21 int 21h
220 000000D8 EBE1 jmp short error_exit
221
222 000000DA 4572726F723A20556E- noDevMsg db "Error: Unable to find Intel ICH based audio device!",CR,LF,"$"
222 000000E3 61626C6520746F2066-
222 000000EC 696E6420496E74656C-
222 000000F5 204943482062617365-
222 000000FE 6420617564696F2064-
222 00000107 6576696365210D0A24
223
224 _1:
225 ; 18/02/2017
226 ; eax = BUS/DEV/FN
227 ; 00000000BBBBBBBBDDDDDFFF00000000
228 ; edx = DEV/VENDOR
229 ; DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
230
231 00000110 66A3[6610] mov [bus_dev_fn], eax
232 00000114 668916[6A10] mov [dev_vendor], edx
233
234 ; get ICH base address regs for mixer and bus master
235
236 00000119 B010 mov al, NAMBAR_REG
237 0000011B E8F600 call pciRegRead16 ; read PCI registers 10-11
238 ;and dx, IO_ADDR_MASK ; mask off BIT0
239 ; 14/05/2024
240 0000011E 80E2FE and dl, 0FEh
241
242 00000121 8916[5010] mov [NAMBAR], dx ; save audio mixer base addr
243
244 00000125 B014 mov al, NABMBAR_REG
245 00000127 E8EA00 call pciRegRead16
246 ;and dx, IO_ADDR_MASK
247 ; 14/05/2024
248 0000012A 80E2C0 and dl, 0C0h
249
250 0000012D 8916[5210] mov [NABMBAR], dx ; save bus master base addr
251
252 ; 08/05/2024
253 ; 06/11/2023
254 ;; init controller
255 ;; 17/02/2017
256 ;mov al, PCI_CMD_REG ; command register (04h)
257 ;call pciRegRead16 ; pciRegRead8
258 ;
259 ;; eax = BUS/DEV/FN/REG
260 ;; dx = PCI Command Register Content ; 17/02/2017
261 ;; 00000000CCCCCCCC
262 ;mov [stats_cmd], dx
263 ;
264 ; 06/11/2023
265 ;mov al, PCI_IO_BASE ; IO base address register (10h)
266 ;call pciRegRead32
267 ;
268 ;and dx, 0FFC0h ; IO_ADDR_MASK (0FFFE) ?
269 ;mov [ac97_io_base], dx
270
271 00000131 B03C mov al, AC97_INT_LINE ; Interrupt line register (3Ch)
272 00000133 E8D600 call pciRegRead8 ; 17/02/2017
273
274 00000136 8816[6410] mov [ac97_int_ln_reg], dl
275
276 ; 28/11/2016
277 ;mov bx, 1 ; 08/05/2024
278 0000013A 30F6 xor dh, dh ; 17/02/2017
279 ; 10/11/2023
280 ;mov cx, dx
281 ;shl bx, cl
282
283 ; 04/11/2023
284 0000013C FA cli
285
286 ;not bx
287 0000013D E4A1 in al, 0A1h ; irq 8-15
288 0000013F 88C4 mov ah, al
289 00000141 E421 in al, 21h ; irq 0-7
290
291 ; 04/11/2023
292 ; save IRQ status
293 00000143 A3[5810] mov [IRQ_status], ax
294
295 ; 12/05/2024 (enable AC97 IRQ)
296 ;mov cl, dl
297 ;mov bx, 1
298 ;shl bx, cl
299 ;not bx
300 ;and ax, bx
301 ;out 21h, al
302 ;mov al, ah
303 ;out 0A1h, al
304
305 ; 15/05/2024
306 ;and ax, bx ; unmask
307 00000146 0FB3D0 btr ax, dx ; unmask
308 00000149 E621 out 21h, al ; enable interrupt (if irq <= 7)
309 0000014B 88E0 mov al, ah
310 0000014D E6A1 out 0A1h, al ; enable interrupt (if irq > 7)
311 ;not bx
312
313 ; 08/05/2024
314 ;mov dx, 4D1h ;8259 ELCR1
315 ;in al, dx
316 ;mov ah, al
317 ;mov dx, 4D0h
318 ;in al, dx
319 ;;or ax, bx
320 ;bts ax, cx
321 ;mov dx, 4D0h
322 ;out dx, al ;set level-triggered mode
323 ;mov al, ah
324 ;mov dx, 4D1h
325 ;out dx, al ;set level-triggered mode
326
327 ; 24/11/2016 - Erdogan Tan
328 ;mov bx, cx
329 ; 10/11/2023
330 0000014F 89D3 mov bx, dx
331 00000151 8A9F[410F] mov bl, [bx+irq_int]
332 00000155 C1E302 shl bx, 2 ; * 4
333
334 ; set up interrupt vector
335 ; 30/11/2016
336 00000158 06 push es
337 00000159 31C0 xor ax, ax
338 0000015B 8EC0 mov es, ax
339 ; 04/11/2023
340 ; save interrupt vector
341 ;mov ax, [es:bx]
342 ; 13/05/2024
343 0000015D B8[7201] mov ax, ac97_int_handler
344 00000160 268707 xchg ax, [es:bx]
345 00000163 A3[5A10] mov [IRQ_vector], ax
346 ;mov ax, [es:bx+2]
347 ; 13/05/2024
348 00000166 8CC8 mov ax, cs
349 00000168 26874702 xchg ax, [es:bx+2]
350 0000016C A3[5C10] mov [IRQ_vector+2], ax
351
352 ; 13/05/2024
353 ;mov word [es:bx], ac97_int_handler
354 ;mov ax, cs
355 ;mov [es:bx+2], ax
356
357 0000016F 07 pop es
358
359 ; 04/11/2023
360 00000170 FB sti
361
362 00000171 C3 retn
363
364 ; 16/05/2024
365 %if 0
366 ; 15/05/2024
367 ac97_int_handler:
368 ; 13/05/2024
369 ; 12/05/2024
370 ; 11/05/2024
371 ; 11/11/2023
372 ; 10/11/2023
373 ; 17/02/2016
374 push eax ; 11/11/2023
375 push dx
376 ; 05/11/2023
377 ;push cx
378 ;push bx
379 ;push si
380 ;push di
381
382 ; 10/11/2023
383 ; EOI at first
384 mov al, 20h
385 test byte [ac97_int_ln_reg], 8
386 jz short _ih_0
387 out 0A0h, al ; 20h ; EOI
388 _ih_0:
389 out 20h, al ; 20h ; EOI
390
391 ; 11/11/2023
392 ; 09/11/2023
393 mov dx, GLOB_STS_REG
394 add dx, [NABMBAR]
395 in eax, dx
396
397 ; 12/05/2024
398 ; 09/11/2023
399 ;cmp eax, 0FFFFFFFFh ; -1
400 ;je short _ih_3
401 ; 15/05/2024
402 inc eax ; 0FFFFFFFFh
403 jz short _ih_3
404 dec eax ; 0
405 jz short _ih_3
406
407 ; 15/05/2024
408 cmp byte [tLoop], 1
409 jb short _ih_2
410
411 ; 12/05/2024
412 ;test al, 40h ; PCM Out Interrupt
413 ; 15/05/2024
414 test al, PCM_OUT_IRQ
415 jnz short _ih_1
416
417 ; 15/05/2024
418 ;test eax, eax
419 ;jz short _ih_3
420
421 ; 12/05/2024
422 ;test ax, PCM_OUT_IRQ
423 ;jnz short _ih_1
424
425 ;mov dx, GLOB_STS_REG
426 ;add dx, [NABMBAR]
427 ; 12/05/2024
428 ;out dx, eax
429 jmp short _ih_2
430 ;jmp short _ih_3
431
432 ; .....
433 ;mov al, 1
434 ; 10/11/2023
435 ;mov [tLoop], al ; 1
436
437 ;cmp [inside], al ; 1
438 ;jnb short _ih_2 ; busy
439
440 ;mov [inside], al ; 1
441 ;
442 ;; 09/11/2023
443 ;mov dx, [NABMBAR]
444 ;add dx, PO_SR_REG ; set pointer to Status reg
445 ;in al, dx
446 ;; 10/11/2023
447 ;;;out dx, eax
448 ;;out dx, al ; clear interrupt event
449 ; ; (by writing 1 to same bits)
450 ;
451 ;;mov [pcm_irq_status], al ; 05/11/2023
452 ;test al, BCIS ; Buffer Completion Interrupt Status (Bit 3)
453 ;jz short _ih_3
454 ; .....
455
456 _ih_1:
457 ; 11/11/2023
458 ;push eax
459 ; 15/05/2024
460 push ax
461
462 ; 13/05/2024
463 mov ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
464 mov dx, PO_SR_REG
465 add dx, [NABMBAR]
466 out dx, ax
467
468 ; 13/05/2024
469 mov dx, PO_CIV_REG
470 add dx, [NABMBAR]
471 in al, dx
472 mov ah, al
473 dec al
474 and al, 1Fh
475 mov dx, PO_LVI_REG
476 add dx, [NABMBAR]
477 out dx, al
478 and ah, 1
479 ; 13/05/2024
480 inc ah
481 mov [tBuff], ah ; 1 = Buffer 1, 2 = Buffer 2
482
483 ; 13/05/2024
484 ; 10/11/2023
485 ; 28/11/2016 - Erdogan Tan
486 ;call tuneLoop
487
488 ; 11/11/2023
489 ;pop eax
490 ; 15/05/2024
491 pop ax
492
493 mov dx, GLOB_STS_REG
494 add dx, [NABMBAR]
495 _ih_2: ; 12/05/2024
496 out dx, eax
497
498 ; 12/05/2024
499 _ih_3:
500 ; 11/11/2023
501 ;mov dx, [NABMBAR]
502 ;add dx, PO_SR_REG ; set pointer to Status reg
503 ;mov ax, 1Ch
504 ;out dx, ax
505
506 ; ; 10/11/2023
507 ; mov al, 20h
508 ; test byte [ac97_int_ln_reg], 8
509 ; jz short _ih_3
510 ; out 0A0h, al ; 20h ; EOI
511 ;_ih_3:
512 ; out 20h, al ; 20h ; EOI
513 ;_ih_4:
514 ;mov byte [inside], 0
515 ;pop di
516 ;pop si
517 ;pop bx
518 ;pop cx
519 pop dx
520 pop eax ; 11/11/2023
521 iret
522 %else
523 ; 16/05/2024
524 ; 15/05/2024
525 ac97_int_handler:
526 ; 13/05/2024
527 ; 12/05/2024
528 ; 11/05/2024
529 ; 11/11/2023
530 ; 10/11/2023
531 ; 17/02/2016
532 00000172 50 push ax ; + ; 16/05/2024
533 ;push eax ; * ; 11/11/2023
534 00000173 52 push dx ; **
535 ; 05/11/2023
536 ;push cx
537 ;push bx
538 ;push si
539 ;push di
540
541 ; 16/05/2024
542 ; 10/11/2023
543 ; EOI at first
544 00000174 B020 mov al, 20h
545 00000176 F606[6410]08 test byte [ac97_int_ln_reg], 8
546 0000017B 7402 jz short _ih_0
547 0000017D E6A0 out 0A0h, al ; 20h ; EOI
548 _ih_0:
549 0000017F E620 out 20h, al ; 20h ; EOI
550
551 ; 16/05/2024
552 ; mov dx, GLOB_STS_REG
553 ; add dx, [NABMBAR]
554 ; in eax, dx
555 ;
556 ; inc eax ; 0FFFFFFFFh
557 ; jz short _ih_3
558 ; dec eax ; 0
559 ; ;jz short _ih_3
560 ;_ih_3:
561 ; ; 16/05/2024
562 ; push eax ; ***
563
564 ; 16/05/2024
565 ; 24/11/2023 (TRDOS386 'audio.s')
566 00000181 8B16[5210] mov dx, [NABMBAR]
567 00000185 83C216 add dx, PO_SR_REG
568 00000188 ED in ax, dx
569
570 00000189 A808 test al, BCIS ; bit 3, 8
571 0000018B 7428 jz short _ih_2
572
573 ; 15/05/2024
574 0000018D 803E[5710]01 cmp byte [tLoop], 1
575 00000192 7221 jb short _ih_2
576 _ih_1:
577 ; 16/05/2024
578 ; 13/05/2024
579 ;mov ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
580 ;add dx, PO_SR_REG
581 ;add dx, [NABMBAR]
582 ;out dx, ax
583
584 ; 16/05/2024
585 00000194 50 push ax ; ****
586
587 ; 13/05/2024
588 00000195 BA1400 mov dx, PO_CIV_REG
589 00000198 0316[5210] add dx, [NABMBAR]
590 0000019C EC in al, dx
591 0000019D 88C4 mov ah, al
592 0000019F FEC8 dec al
593 000001A1 241F and al, 1Fh
594 000001A3 BA1500 mov dx, PO_LVI_REG
595 000001A6 0316[5210] add dx, [NABMBAR]
596 000001AA EE out dx, al
597 000001AB 80E401 and ah, 1
598 ; 13/05/2024
599 000001AE FEC4 inc ah
600 000001B0 8826[5410] mov [tBuff], ah ; 1 = Buffer 1, 2 = Buffer 2
601
602 ; 13/05/2024
603 ; 10/11/2023
604 ; 28/11/2016 - Erdogan Tan
605 ;call tuneLoop
606
607 ; 16/05/2024
608 000001B4 58 pop ax ; ****
609
610 ; 16/05/2024
611 _ih_2:
612 ;mov ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
613 000001B5 8B16[5210] mov dx, [NABMBAR]
614 000001B9 83C216 add dx, PO_SR_REG
615 000001BC EF out dx, ax
616
617 ; ; 16/05/2024
618 ; pop eax ; ***
619 ;
620 ; or eax, eax
621 ; jz short _ih_4
622 ;
623 ; mov dx, GLOB_STS_REG
624 ; add dx, [NABMBAR]
625 ; out dx, eax
626
627 ; 16/05/2024
628 _ih_4:
629 ; 10/11/2023
630 ;mov al, 20h
631 ;test byte [ac97_int_ln_reg], 8
632 ;jz short _ih_5
633 ;out 0A0h, al ; 20h ; EOI
634 ;_ih_5:
635 ;out 20h, al ; 20h ; EOI
636 ;_ih_6:
637 ;pop di
638 ;pop si
639 ;pop bx
640 ;pop cx
641 000001BD 5A pop dx ; **
642 ;pop eax ; * ; 11/11/2023
643 000001BE 58 pop ax ; + ; 16/05/2024
644 000001BF CF iret
645 %endif
646
647 ;=============================================================================
648 ; PCI.ASM
649 ;=============================================================================
650
651 ; EQUATES
652
653 ;constants of stuff that seem hard to remember at times.
654
655 TRUE EQU 1
656 FALSE EQU 0
657
658 ENABLED EQU 1
659 DISABLED EQU 0
660
661 BIT0 EQU 1
662 BIT1 EQU 2
663 BIT2 EQU 4
664 BIT3 EQU 8
665 BIT4 EQU 10h
666 BIT5 EQU 20h
667 BIT6 EQU 40h
668 BIT7 EQU 80h
669 BIT8 EQU 100h
670 BIT9 EQU 200h
671 BIT10 EQU 400h
672 BIT11 EQU 800h
673 BIT12 EQU 1000h
674 BIT13 EQU 2000h
675 BIT14 EQU 4000h
676 BIT15 EQU 8000h
677 BIT16 EQU 10000h
678 BIT17 EQU 20000h
679 BIT18 EQU 40000h
680 BIT19 EQU 80000h
681 BIT20 EQU 100000h
682 BIT21 EQU 200000h
683 BIT22 EQU 400000h
684 BIT23 EQU 800000h
685 BIT24 EQU 1000000h
686 BIT25 EQU 2000000h
687 BIT26 EQU 4000000h
688 BIT27 EQU 8000000h
689 BIT28 EQU 10000000h
690 BIT29 EQU 20000000h
691 BIT30 EQU 40000000h
692 BIT31 EQU 80000000h
693
694 ;special characters
695 NUL EQU 0
696 NULL EQU 0
697 BELL EQU 07
698 BS EQU 08
699 TAB EQU 09
700 LF EQU 10
701 CR EQU 13
702 ESCAPE EQU 27 ;ESC is a reserved word....
703
704
705 ;file stuff
706 READONLY EQU BIT0
707 HIDDEN EQU BIT1
708 SYSTEM EQU BIT2
709 VOLUME EQU BIT3 ;ignored for file access
710 DIRECTORY EQU BIT4 ;must be 0 for file access
711 ARCHIVE EQU BIT5
712 SHAREABLE EQU BIT7 ;for novell networks
713 OPEN EQU 2 ; open existing file
714 CREATE EQU 1 ; create new file
715
716 ; PCI equates
717 ; PCI function address (PFA)
718 ; bit 31 = 1
719 ; bit 23:16 = bus number (0-255)
720 ; bit 15:11 = device number (0-31)
721 ; bit 10:8 = function number (0-7)
722 ; bit 7:0 = register number (0-255)
723
724 IO_ADDR_MASK EQU 0FFFEh ; mask off bit 0 for reading BARs
725 PCI_INDEX_PORT EQU 0CF8h
726 PCI_DATA_PORT EQU 0CFCh
727 PCI32 EQU BIT31 ; bitflag to signal 32bit access
728 PCI16 EQU BIT30 ; bitflag for 16bit access
729
730 PCI_FN0 EQU 0 << 8
731 PCI_FN1 EQU 1 << 8
732 PCI_FN2 EQU 2 << 8
733 PCI_FN3 EQU 3 << 8
734 PCI_FN4 EQU 4 << 8
735 PCI_FN5 EQU 5 << 8
736 PCI_FN6 EQU 6 << 8
737 PCI_FN7 EQU 7 << 8
738
739 PCI_CMD_REG EQU 04h ; reg 04, command reg
740 IO_ENA EQU BIT0 ; i/o decode enable
741 MEM_ENA EQU BIT1 ; memory decode enable
742 BM_ENA EQU BIT2 ; bus master enable
743
744 ; CODE
745
746 ; AC97.ASM
747 ; PCI device register reader/writers.
748 ; NASM version: Erdogan Tan (29/11/2016)
749 ; Last Update: 17/02/2017
750
751 ;===============================================================
752 ; 8/16/32bit PCI reader
753 ;
754 ; Entry: EAX=PCI Bus/Device/fn/register number
755 ; BIT30 set if 32 bit access requested
756 ; BIT29 set if 16 bit access requested
757 ; otherwise defaults to 8bit read
758 ;
759 ; Exit: DL,DX,EDX register data depending on requested read size
760 ;
761 ; Note: this routine is meant to be called via pciRegRead8, pciRegread16,
762 ; or pciRegRead32, listed below.
763 ;
764 ; Note2: don't attempt to read 32bits of data from a non dword aligned reg
765 ; number. Likewise, don't do 16bit reads from non word aligned reg #
766 ;
767 pciRegRead:
768 000001C0 6653 push ebx
769 000001C2 51 push cx
770 000001C3 6689C3 mov ebx, eax ; save eax, dh
771 000001C6 88F1 mov cl, dh
772 000001C8 6625FFFFFFBF and eax, (~PCI32)+PCI16 ; clear out data size request
773 000001CE 660D00000080 or eax, BIT31 ; make a PCI access request
774 000001D4 24FC and al, ~3 ; NOT 3 ; force index to be dword
775
776 000001D6 BAF80C mov dx, PCI_INDEX_PORT
777 000001D9 66EF out dx, eax ; write PCI selector
778
779 000001DB BAFC0C mov dx, PCI_DATA_PORT
780 000001DE 88D8 mov al, bl
781 000001E0 2403 and al, 3 ; figure out which port to
782 000001E2 00C2 add dl, al ; read to
783
784 000001E4 66ED in eax, dx ; do 32bit read
785 000001E6 66F7C300000080 test ebx, PCI32
786 000001ED 7403 jz short _pregr1
787
788 000001EF 6689C2 mov edx, eax ; return 32bits of data
789 _pregr1:
790 000001F2 89C2 mov dx, ax ; return 16bits of data
791 000001F4 66F7C3000000C0 test ebx, PCI32+PCI16
792 000001FB 7502 jnz short _pregr2
793 000001FD 88CE mov dh, cl ; restore dh for 8 bit read
794 _pregr2:
795 000001FF 6689D8 mov eax, ebx ; restore eax
796 00000202 6625FFFFFFBF and eax, (~PCI32)+PCI16 ; clear out data size request
797 00000208 59 pop cx
798 00000209 665B pop ebx
799 0000020B C3 retn
800
801 pciRegRead8:
802 0000020C 6625FFFFFF3F and eax, (~PCI16)+PCI32 ; set up 8 bit read size
803 00000212 EBAC jmp short pciRegRead ; call generic PCI access
804
805 pciRegRead16:
806 00000214 6625FFFFFF3F and eax, (~PCI16)+PCI32 ; set up 16 bit read size
807 0000021A 660D00000040 or eax, PCI16 ; call generic PCI access
808 00000220 EB9E jmp short pciRegRead
809
810 pciRegRead32:
811 00000222 6625FFFFFF3F and eax, (~PCI16)+PCI32 ; set up 32 bit read size
812 00000228 660D00000080 or eax, PCI32 ; call generic PCI access
813 0000022E EB90 jmp short pciRegRead
814
815 ;===============================================================
816 ; 8/16/32bit PCI writer
817 ;
818 ; Entry: EAX=PCI Bus/Device/fn/register number
819 ; BIT31 set if 32 bit access requested
820 ; BIT30 set if 16 bit access requested
821 ; otherwise defaults to 8bit read
822 ; DL/DX/EDX data to write depending on size
823 ;
824 ;
825 ; note: this routine is meant to be called via pciRegWrite8, pciRegWrite16,
826 ; or pciRegWrite32 as detailed below.
827 ;
828 ; Note2: don't attempt to write 32bits of data from a non dword aligned reg
829 ; number. Likewise, don't do 16bit writes from non word aligned reg #
830 ;
831 pciRegWrite:
832 00000230 6653 push ebx
833 00000232 51 push cx
834 00000233 6689C3 mov ebx, eax ; save eax, dx
835 00000236 89D1 mov cx, dx
836 00000238 660D00000080 or eax, BIT31 ; make a PCI access request
837 0000023E 6625FFFFFFBF and eax, ~PCI16 ; NOT PCI16 ; clear out data size request
838 00000244 24FC and al, ~3 ; NOT 3 ; force index to be dword
839
840 00000246 BAF80C mov dx, PCI_INDEX_PORT
841 00000249 66EF out dx, eax ; write PCI selector
842
843 0000024B BAFC0C mov dx, PCI_DATA_PORT
844 0000024E 88D8 mov al, bl
845 00000250 2403 and al, 3 ; figure out which port to
846 00000252 00C2 add dl, al ; write to
847
848 00000254 6689D0 mov eax, edx ; put data into eax
849 00000257 89C8 mov ax, cx
850
851 00000259 EE out dx, al
852 0000025A 66F7C3000000C0 test ebx, PCI16+PCI32 ; only 8bit access? bail
853 00000261 740C jz short _pregw1
854
855 00000263 EF out dx, ax ; write 16 bit value
856 00000264 66F7C300000040 test ebx, PCI16 ; 16bit requested? bail
857 0000026B 7502 jnz short _pregw1
858
859 0000026D 66EF out dx, eax ; write full 32bit
860 _pregw1:
861 0000026F 6689D8 mov eax, ebx ; restore eax
862 00000272 6625FFFFFFBF and eax, (~PCI32)+PCI16 ; clear out data size request
863 00000278 89CA mov dx, cx ; restore dx
864 0000027A 59 pop cx
865 0000027B 665B pop ebx
866 0000027D C3 ret
867
868 pciRegWrite8:
869 0000027E 6625FFFFFF3F and eax, (~PCI16)+PCI32 ; set up 8 bit write size
870 00000284 EBAA jmp short pciRegWrite ; call generic PCI access
871
872 pciRegWrite16:
873 00000286 6625FFFFFF3F and eax, (~PCI16)+PCI32 ; set up 16 bit write size
874 0000028C 660D00000040 or eax, PCI16 ; call generic PCI access
875 00000292 EB9C jmp short pciRegWrite
876
877 pciRegWrite32:
878 00000294 6625FFFFFF3F and eax, (~PCI16)+PCI32 ; set up 32 bit write size
879 0000029A 660D00000080 or eax, PCI32 ; call generic PCI access
880 000002A0 EB8E jmp short pciRegWrite
881
882 ; AC97.ASM (PLAYWAV.COM)
883 ; 17/02/2017 (Modifed by Erdogan Tan for various ICH device IDs)
884 ;===============================================================
885 ; PCIFindDevice: scan through PCI space looking for a device+vendor ID
886 ;
887 ; ENTRY: none
888 ;; Entry: EAX=Device+Vendor ID
889 ;
890 ; Exit: EAX=PCI address if device found
891 ; EDX=Device+Vendor ID
892 ; CY clear if found, set if not found. EAX invalid if CY set.
893 ;
894 ; [old stackless] Destroys: ebx, esi, edi, cl
895 ;
896 pciFindDevice:
897 ;push cx
898 ;push eax ; *
899 ;push esi
900 ;push edi
901
902 ;mov esi, eax ; save off vend+device ID
903
904 ; 17/02/2017
905 000002A2 BE[510F] mov si, valid_ids ; address of Valid ICH (AC97) Device IDs
906 000002A5 B91500 mov cx, valid_id_count
907 pfd_0:
908 000002A8 66BF00FFFF7F mov edi, (80000000h - 100h) ; start with bus 0, dev 0 func 0
909 nextPCIdevice:
910 000002AE 6681C700010000 add edi, 100h
911 000002B5 6681FF00F8FF80 cmp edi, 80FFF800h ; scanned all devices?
912 ;stc
913 ;je short PCIScanExit ; not found
914 000002BC 720D jb short pfd_1
915 000002BE 66BF00000080 mov edi, 80000000h
916 000002C4 83C604 add si, 4 ; scan for next device ID
917 000002C7 E202 loop pfd_1
918 000002C9 F9 stc
919 ;jmp short PCIScanExit
920 000002CA C3 retn
921 pfd_1:
922 000002CB 6689F8 mov eax, edi ; read PCI registers
923 000002CE E851FF call pciRegRead32
924 ;cmp edx, esi ; found device?
925 000002D1 663B14 cmp edx, dword [si]
926 000002D4 75D8 jne short nextPCIdevice
927 ;clc
928 PCIScanExit:
929 ;pushf
930 000002D6 66B800000080 mov eax, BIT31
931 000002DC 66F7D0 not eax
932 000002DF 6621F8 and eax, edi ; return only bus/dev/fn #
933 ;popf
934
935 ;pop edi
936 ;pop esi
937 ;pop edx ; *
938 ;pop cx
939 000002E2 C3 retn
940
941 ;=============================================================================
942 ; CODEC.ASM
943 ;=============================================================================
944
945 ; EQUATES
946
947 ;Codec registers.
948 ;
949 ;Not all codecs are created equal. Refer to the spec for your specific codec.
950 ;
951 ;All registers are 16bits wide. Access to codec registers over the AC97 link
952 ;is defined by the OEM.
953 ;
954 ;Secondary codec's are accessed by ORing in BIT7 of all register accesses.
955 ;
956
957 ; each codec/mixer register is 16bits
958
959 CODEC_RESET_REG equ 00 ; reset codec
960 CODEC_MASTER_VOL_REG equ 02 ; master volume
961 CODEC_HP_VOL_REG equ 04 ; headphone volume
962 CODEC_MASTER_MONO_VOL_REG equ 06 ; master mono volume
963 CODEC_MASTER_TONE_REG equ 08 ; master tone (R+L)
964 CODEC_PCBEEP_VOL_REG equ 0ah ; PC beep volume
965 CODEC_PHONE_VOL_REG equ 0bh ; phone volume
966 CODEC_MIC_VOL_REG equ 0eh ; MIC volume
967 CODEC_LINE_IN_VOL_REG equ 10h ; line input volume
968 CODEC_CD_VOL_REG equ 12h ; CD volume
969 CODEC_VID_VOL_REG equ 14h ; video volume
970 CODEC_AUX_VOL_REG equ 16h ; aux volume
971 CODEC_PCM_OUT_REG equ 18h ; PCM output volume
972 CODEC_RECORD_SELECT_REG equ 1ah ; record select input
973 CODEC_RECORD_VOL_REG equ 1ch ; record volume
974 CODEC_RECORD_MIC_VOL_REG equ 1eh ; record mic volume
975 CODEC_GP_REG equ 20h ; general purpose
976 CODEC_3D_CONTROL_REG equ 22h ; 3D control
977 ; 24h is reserved
978 CODEC_POWER_CTRL_REG equ 26h ; powerdown control
979 CODEC_EXT_AUDIO_REG equ 28h ; extended audio
980 CODEC_EXT_AUDIO_CTRL_REG equ 2ah ; extended audio control
981 CODEC_PCM_FRONT_DACRATE_REG equ 2ch ; PCM out sample rate
982 CODEC_PCM_SURND_DACRATE_REG equ 2eh ; surround sound sample rate
983 CODEC_PCM_LFE_DACRATE_REG equ 30h ; LFE sample rate
984 CODEC_LR_ADCRATE_REG equ 32h ; PCM in sample rate
985 CODEC_MIC_ADCRATE_REG equ 34h ; mic in sample rate
986
987 ; registers 36-7a are reserved on the ICH
988
989 CODEC_VENDORID1_REG equ 7ch ; codec vendor ID 1
990 CODEC_VENDORID2_REG equ 7eh ; codec vendor ID 2
991
992 ; Mixer registers 0 through 51h reside in the ICH and are not forwarded over
993 ; the AC97 link to the codec, which I think is a little weird. Looks like
994 ; the ICH makes it so you don't need a fully functional codec to play audio?