-
Notifications
You must be signed in to change notification settings - Fork 1
/
playwav5.asm
1231 lines (1047 loc) · 25.9 KB
/
playwav5.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
; ****************************************************************************
; PLAYWAV.ASM - ICH AC97 .wav player for DOS. PLAYWAV.COM
; ----------------------------------------------------------------------------
; Last Update: 20/05/2024 (Previous: 08/05/2024)
; ----------------------------------------------------------------------------
; Beginning: 17/02/2017
; ----------------------------------------------------------------------------
; Assembler: NASM version 2.15
; nasm playwav.asm -l playwav.lst -o PLAYWAV.COM
; ----------------------------------------------------------------------------
; Derived from '.wav file player for DOS' Jeff Leyda, Sep 02, 2002
; ****************************************************************************
; Modidified from 'PLAYER.COM' for VIA VT8233 wav player source code by
; (PLAYER.ASM) by Erdogan Tan (07/11/2016 - 08/12/2016)
; AC97 interrupt version - 09/11/2023 - Erdogan Tan
; sample rate conversion version - 13/11/2023 - Erdogan Tan
; LVI interrupt version (instead of IOC) - 18/11/2023 - Erdogan Tan
[BITS 16]
[ORG 100h]
%include 'ac97.inc' ; 17/02/2017
_STARTUP:
; memory allocation
call setFree ; deallocate unused DOS mem
; 17/02/2017
; Clear BSS (uninitialized data) area
xor ax, ax ; 0
mov cx, (EOF - bss_start)/2
mov di, bss_start
rep stosw
; allocate 256 bytes of data for DCM_OUT Buffer Descriptor List. (BDL)
mov ax, BDL_SIZE / 16
call memAlloc
mov [BDL_BUFFER], ax ; segment
; allocate 2 buffers, 64k each for now.
mov ax, BUFFERSIZE / 16 ; 64k for .WAV file
call memAlloc
mov [WAV_BUFFER1], ax ; segment
mov ax, BUFFERSIZE / 16
call memAlloc
mov [WAV_BUFFER2], ax
; Detect/reset AC97
call pciFindDevice
jnc short _1
; couldn't find the audio device!
push cs
pop ds
mov dx, noDevMsg
mov ah, 9
int 21h
jmp exit
; 17/02/2017
noDevMsg: db "Error: Unable to find intel ICH based audio device!",CR,LF,"$"
_1:
; eax = BUS/DEV/FN
; 00000000BBBBBBBBDDDDDFFF00000000
; edx = DEV/VENDOR
; DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
mov [bus_dev_fn], eax
mov [dev_vendor], edx
; get ICH base address regs for mixer and bus master
mov al, NAMBAR_REG
call pciRegRead16 ; read PCI registers 10-11
;and dx, IO_ADDR_MASK ; mask off BIT0
; 19/05/2024
and dl, 0FEh
mov [NAMBAR], dx ; save audio mixer base addr
mov al, NABMBAR_REG
call pciRegRead16
;and dx, IO_ADDR_MASK
; 19/05/2024
and dl, 0C0h
mov [NABMBAR], dx ; save bus master base addr
; 06/11/2023
;; init controller
;; 17/02/2017
;mov al, PCI_CMD_REG ; command register (04h)
;call pciRegRead16 ; pciRegRead8
;
;; eax = BUS/DEV/FN/REG
;; dx = PCI Command Register Content ; 17/02/2017
;; 00000000CCCCCCCC
;mov [stats_cmd], dx
;
; 06/11/2023
;mov al, PCI_IO_BASE ; IO base address register (10h)
;call pciRegRead32
;
;and dx, 0FFC0h ; IO_ADDR_MASK (0FFFE) ?
;mov [ac97_io_base], dx
mov al, AC97_INT_LINE ; Interrupt line register (3Ch)
call pciRegRead8 ; 17/02/2017
mov [ac97_int_ln_reg], dl
; 09/11/2023
; 05/11/2023
%if 1
; 28/11/2016
;mov bx, 1 ; 08/05/2024
xor dh, dh ; 17/02/2017
; 10/11/2023
;mov cx, dx
;shl bx, cl
; 04/11/2023
cli
;not bx
in al, 0A1h ; irq 8-15
mov ah, al
in al, 21h ; irq 0-7
; 04/11/2023
; save IRQ status
mov [IRQ_status], ax
; 12/05/2024 (enable AC97 IRQ)
;mov cl, dl
;mov bx, 1
;shl bx, cl
;not bx
;and ax, bx
;out 21h, al
;mov al, ah
;out 0A1h, al
;and ax, bx ; unmask
btr ax, dx ; unmask
out 21h, al ; enable interrupt (if irq <= 7)
mov al, ah
out 0A1h, al ; enable interrupt (if irq > 7)
;not bx
; 04/11/2023
;mov dx, 4D1h ;8259 ELCR1
;in al, dx
;mov ah, al
;mov dx, 4D0h
;in al, dx
;;or ax, bx
;bts ax, cx
;mov dx, 4D0h
;out dx, al ;set level-triggered mode
;mov al, ah
;mov dx, 4D1h
;out dx, al ;set level-triggered mode
; 24/11/2016 - Erdogan Tan
;mov bx, cx
; 10/11/2023
mov bx, dx
mov bl, [bx+irq_int]
shl bx, 2 ; * 4
; set up interrupt vector
; 30/11/2016
push es
xor ax, ax
mov es, ax
; 04/11/2023
; save interrupt vector
;mov ax, [es:bx]
; 13/05/2024
mov ax, ac97_int_handler
xchg ax, [es:bx]
mov [IRQ_vector], ax
;mov ax, [es:bx+2]
; 13/05/2024
mov ax, cs
xchg ax, [es:bx+2]
mov [IRQ_vector+2], ax
; 13/05/2024
;mov word [es:bx], ac97_int_handler
;mov ax, cs
;mov [es:bx+2], ax
pop es
; 04/11/2023
sti
%endif
call write_ac97_dev_info
; check the command line for a file to play
;push ds
call processCmdline ; get the filename
; open the file
mov al, OPEN ; open existing file
call openFile ; no error? ok.
;pop ds
jnc short _gsr
; file not found!
;push cs
;pop ds
mov dx, noFileErrMsg
mov ah, 9
int 21h
jmp exit
noFileErrMsg:
db "Error: file not found.",CR,LF,"$"
_gsr:
call getSampleRate ; read the sample rate
; pass it onto codec.
jc short exit ; 19/11/2016 - nothing to do
mov [sample_rate], ax
; 19/11/2016
mov [stmo], cl
mov [bps], dl
; 17/02/2017
mov byte [fbs_shift], 0 ; 0 = stereo and 16 bit
dec cl
jnz short _gsr_1 ; stereo
inc byte [fbs_shift] ; 1 = mono or 8 bit
_gsr_1:
cmp dl, 8
ja short _gsr_2 ; 16 bit samples
inc byte [fbs_shift] ; 2 = mono and 8 bit
_gsr_2:
call write_sample_rate
; 05/11/2023
_2:
call check4keyboardstop ; flush keyboard buffer
jc short _2 ; 07/11/2023
; 09/11/2023
;; 05/11/2023
;mov eax, [bus_dev_fn]
;mov al, PCI_CMD_REG
;call pciRegRead16 ; read PCI command register
;; 17/02/2017
;;mov dx, [stats_cmd]
;or dl, IO_ENA+BM_ENA ; enable IO and bus master
;call pciRegWrite16 ; pciRegWrite8
;; 06/11/2023
;;mov eax, [bus_dev_fn]
;;mov al, PCI_CMD_REG
;;call pciRegRead8 ; read PCI command register
;;or dl, IO_ENA+BM_ENA ; enable IO and bus master
;;call pciRegWrite8
; setup the Codec (actually mixer registers)
call codecConfig ; unmute codec, set rates.
; 11/11/2023
jc short init_err
;
; position file pointer to start in actual wav data
; MUCH improvement should really be done here to check if sample size is
; supported, make sure there are 2 channels, etc.
;
mov ah, 42h
mov al, 0 ; from start of file
mov bx, [filehandle]
xor cx, cx
mov dx, 44 ; jump past .wav/riff header
int 21h
; play the .wav file. Most of the good stuff is in here.
call playWav
; close the .wav file and exit.
close_exit: ; 11/11/2023
call closeFile
exit:
mov ax, 4c00h
int 21h
here:
jmp short here
; 11/11/2023
init_err:
mov dx, msg_init_err
vra_err: ; 12/11/2023
mov ah, 9
int 21h
jmp short close_exit
; MEMALLOC.ASM
;-- SETFREE: Release memory not used ----------------
;-- Input : ES = address of PSP
;-- Output : none
;-- Register : AX, BX, CL and FLAGS are changed
;-- Info : Since the stack-segment is always the last segment in an
; EXE-file, ES:0000 points to the beginning and SS:SP
; to the end of the program in memory. Through this the
; length of the program can be calculated
; call this routine once at the beginning of the program to free up memory
; assigned to it by DOS.
setFree:
mov bx, 65536/16 ; 4K paragraphs ; 17/02/2017 (Erdogan Tan)
mov ah, 4ah ; pass new length to DOS
int 21h
retn ; back to caller
; new size (allocated memory) = 64KB
memAlloc:
; input: AX = # of paragraphs required
; output: AX = segment of block to use
push bx
mov bx, ax
mov ah, 48h
int 21h
pop bx
retn
; CMDLINE.ASM
; parse the command line
; entry: none
; exit: DS:DX to the 1st supplied item on the command line
processCmdline:
push bx
push si
;mov ah, 51h
;int 21h
;mov ds, bx
mov si, 80h
movzx bx, byte [si]
add si, bx
inc si
mov byte [si], NULL ; zero terminate
mov si, 81h
cmdlineloop:
lodsb
cmp al, NULL ; found end of line?
je short exitpc
cmp al, ' ' ; found a space?
je short cmdlineloop
; must be the filename here.
exitpc:
dec si ; point to start of filename
mov dx, si
pop si
pop bx
retn
; FILE.ASM
;open or create file
;
;input: ds:dx-->filename (asciiz)
; al=file Mode (create or open)
;output: none cs:[filehandle] filled
;
openFile:
push ax
push cx
mov ah, 3bh ; start with a mode
add ah, al ; add in create or open mode
xor cx, cx
int 21h
jc short _of1
;mov [cs:filehandle], ax
mov [filehandle], ax
_of1:
pop cx
pop ax
retn
; close the currently open file
; input: none, uses cs:[filehandle]
closeFile:
push ax
push bx
cmp word [filehandle], -1
jz short _cf1
mov bx, [filehandle]
mov ax,3e00h
int 21h ;close file
_cf1:
pop bx
pop ax
retn
getSampleRate:
; 08/12/2016
; reads the sample rate from the .wav file.
; entry: none - assumes file is already open
; 19/11/2016 - Erdogan Tan
; exit: ax = sample rate (11025, 22050, 44100, 48000)
; cx = number of channels (mono=1, stereo=2)
; dx = bits per sample (8, 16)
push bx
mov ah, 42h
mov al, 0 ; from start of file
mov bx, [filehandle]
xor cx, cx
mov dx, 08h ; "WAVE"
int 21h
mov dx, smpRBuff
mov cx, 28 ; 28 bytes
mov ah, 3fh
int 21h
cmp word [smpRBuff], 'WA'
jne short gsr_stc
cmp word [smpRBuff+2], 'VE'
jne short gsr_stc
cmp word [smpRBuff+12], 1 ; Offset 20, must be 1 (= PCM)
jne short gsr_stc
mov cx, [smpRBuff+14] ; return num of channels in CX
mov ax, [smpRBuff+16] ; return sample rate in AX
mov dx, [smpRBuff+26] ; return bits per sample value in DX
gsr_retn:
pop bx
retn
gsr_stc:
stc
jmp short gsr_retn
;%include 'ac97.asm' ; 29/11/2016 (AC97 codec configuration)
%include 'ac97_vra.asm' ; 19/11/2023 (AC97 codec configuration)
;;%include 'ich_wav.asm' ; 17/02/2017 (ICH AC97 wav playing functions)
;%include 'ich_wav3.asm' ; 13/11/2023 (ICH AC97 wav playing functions)
%include 'ich_wav5.asm' ; 18/11/2023 (ICH AC97 wav playing functions)
; UTILS.ASM
;----------------------------------------------------------------------------
; delay1_4ms - Delay for 1/4 millisecond.
; 1mS = 1000us
; Entry:
; None
; Exit:
; None
;
; Modified:
; None
;
PORTB EQU 061h
REFRESH_STATUS EQU 010h ; Refresh signal status
delay1_4ms:
push ax
push cx
mov cx, 16 ; close enough.
in al,PORTB
and al,REFRESH_STATUS
mov ah,al ; Start toggle state
or cx, cx
jz short _d4ms1
inc cx ; Throwaway first toggle
_d4ms1:
in al,PORTB ; Read system control port
and al,REFRESH_STATUS ; Refresh toggles 15.085 microseconds
cmp ah,al
je short _d4ms1 ; Wait for state change
mov ah,al ; Update with new state
dec cx
jnz short _d4ms1
pop cx
pop ax
retn
; 13/11/2016 - Erdogan Tan
write_ac97_dev_info:
; BUS/DEV/FN
; 00000000BBBBBBBBDDDDDFFF00000000
; DEV/VENDOR
; DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
xor bh, bh
mov esi, [dev_vendor]
mov ax, si
mov bl, al
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgVendorId+3], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgVendorId+2], al
mov bl, ah
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgVendorId+1], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgVendorId], al
shr esi, 16
mov ax, si
mov bl, al
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgDevId+3], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgDevId+2], al
mov bl, ah
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgDevId+1], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgDevId], al
mov esi, [bus_dev_fn]
shr esi, 8
mov ax, si
mov bl, al
mov dl, bl
and bl, 7 ; bit 0,1,2
mov al, [bx+hex_chars]
mov [msgFncNo+1], al
mov bl, dl
shr bl, 3
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgDevNo+1], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgDevNo], al
mov bl, ah
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgBusNo+1], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgBusNo], al
mov ax, [NAMBAR]
mov bl, al
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgNamBar+3], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgNamBar+2], al
mov bl, ah
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgNamBar+1], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgNamBar], al
; 08/05/2024 (ebx->bx)
; 05/11/2023
mov ax, [NABMBAR]
mov bl, al
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgNabmBar+3], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgNabmBar+2], al
mov bl, ah
mov dl, bl
and bl, 0Fh
mov al, [bx+hex_chars]
mov [msgNabmBar+1], al
mov bl, dl
shr bl, 4
mov al, [bx+hex_chars]
mov [msgNabmBar], al
; 24/11/2016
xor ah, ah
mov al, [ac97_int_ln_reg]
mov cl, 10
div cl
add [msgIRQ], ax
and al, al
jnz short _pmi
mov al, [msgIRQ+1]
mov ah, ' '
mov [msgIRQ], ax
_pmi:
mov dx, msgAC97Info
mov ah, 9
int 21h
retn
write_sample_rate:
; ax = sample rate (hertz)
xor dx, dx
mov cx, 10
div cx
add [msgHertz+4], dl
sub dx, dx
div cx
add [msgHertz+3], dl
sub dx, dx
div cx
add [msgHertz+2], dl
sub dx, dx
div cx
add [msgHertz+1], dl
add [msgHertz], al
mov dx, msgSampleRate
mov ah, 9
int 21h
; 19/11/2016
mov dx, msg16Bits
cmp byte [bps], 16
je short wsr_1
mov dx, msg8Bits
wsr_1:
mov ah, 9
int 21h
mov dx, msgMono
cmp byte [stmo], 1
je short wsr_2
mov dx, msgStereo
wsr_2:
mov ah, 9
int 21h
retn
; 19/05/2024
; 10/11/2023
; 09/11/2023
; 06/11/2023
%if 1
ac97_int_handler:
; 19/05/2024
; 16/05/2024 ('PLAYMOD3.ASM', 18/05/2024, Erdogan Tan)
; 11/11/2023
; 10/11/2023
; 17/02/2016
push ax ; + ; 16/05/2024
;push eax ; * ; 11/11/2023
push dx ; **
; 05/11/2023
;push cx
;push bx
;push si
;push di
; 10/11/2023
; EOI at first
mov al, 20h
test byte [ac97_int_ln_reg], 8
jz short _ih_0
out 0A0h, al ; 20h ; EOI
_ih_0:
out 20h, al ; 20h ; EOI
; 16/05/2024
; mov dx, GLOB_STS_REG
; add dx, [NABMBAR]
; in eax, dx
;
; inc eax ; 0FFFFFFFFh
; jz short _ih_3
; dec eax ; 0
; ;jz short _ih_3
;_ih_3:
; ; 16/05/2024
; push eax ; ***
; 16/05/2024
; 24/11/2023 (TRDOS386 'audio.s')
mov dx, [NABMBAR]
add dx, PO_SR_REG
in ax, dx
; 20/05/2024
test al, LVBCI ; bit 2, 4
jz short _ih_2
; 19/05/2024
; 15/05/2024
;cmp byte [tLoop], 1
;jb short _ih_2
_ih_1:
; 19/05/2024
push ax ; ****
; 10/11/2023
; 28/11/2016 - Erdogan Tan
call tuneLoop
; 19/05/2024
pop ax ; ****
; 16/05/2024
_ih_2:
;mov ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
mov dx, [NABMBAR]
add dx, PO_SR_REG
out dx, ax
; ; 16/05/2024
; pop eax ; ***
;
; or eax, eax
; jz short _ih_4
;
; mov dx, GLOB_STS_REG
; add dx, [NABMBAR]
; out dx, eax
; 16/05/2024
_ih_4:
; 10/11/2023
;mov al, 20h
;test byte [ac97_int_ln_reg], 8
;jz short _ih_5
;out 0A0h, al ; 20h ; EOI
;_ih_5:
;out 20h, al ; 20h ; EOI
;_ih_6:
;pop di
;pop si
;pop bx
;pop cx
pop dx ; **
;pop eax ; * ; 11/11/2023
pop ax ; + ; 16/05/2024
iret
%else
ac97_int_handler:
; 19/11/2023
; 18/11/2023
; 11/11/2023
; 10/11/2023
; 17/02/2016
push eax ; 11/11/2023
push dx
; 05/11/2023
;push cx
;push bx
;push si
;push di
; ; 10/11/2023
; ; EOI at first
; mov al, 20h
; test byte [ac97_int_ln_reg], 8
; jz short _ih_0
; out 0A0h, al ; 20h ; EOI
;_ih_0:
; out 20h, al ; 20h ; EOI
; 11/11/2023
; 09/11/2023
mov dx, GLOB_STS_REG
add dx, [NABMBAR]
in eax, dx
; 09/11/2023,
cmp eax, 0FFFFFFFFh ; -1
je short _ih_2
test al, 40h ; PCM Out Interrupt
jnz short _ih_1
test eax, eax
jz short _ih_2
;mov dx, GLOB_STS_REG
;add dx, [NABMBAR]
out dx, eax
jmp short _ih_2
_ih_1:
; 11/11/2023
push eax
;mov ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
;mov dx, PO_SR_REG
;add dx, [NABMBAR]
;out dx, ax
; 10/11/2023
; 28/11/2016 - Erdogan Tan
call tuneLoop
; 11/11/2023
pop eax
mov dx, GLOB_STS_REG
add dx, [NABMBAR]
out dx, eax
_ih_2:
; 11/11/2023
mov dx, [NABMBAR]
add dx, PO_SR_REG ; set pointer to Status reg
mov ax, 1Ch ; clear FIFOE, BCIS, LVBCI
out dx, ax
_ih_3: ; 19/11/2023
mov al, 20h
test byte [ac97_int_ln_reg], 8
jz short _ih_0
out 0A0h, al ; 20h ; EOI
_ih_0:
out 20h, al ; 20h ; EOI
pop dx
pop eax
iret
%endif
ac97_stop:
; 11/11/2023
; 09/11/2023
; 05/11/2023
; 04/11/2023
; 28/05/2017 (TRDOS 386 v2, 'audio.s')
;mov byte [tLoop], 0 ; stop ! ; 05/11/2023
;_ac97_stop:
; 11/11/2023
mov dx, [NAMBAR]
;add dx, 0 ; ac_reg_0 ; reset register
out dx, ax
; 04/11/2023
; 09/10/2017 (TRDOS 386 v2, 'audio.s')
; 11/06/2017
xor al, al ; 0
call ac97_po_cmd
; (Ref: KolibriOS, intelac97.asm, 'stop:')
; Clear FIFOE, BCIS, LVBCI (Ref: Intel ICH hub manual)
mov ax, 1Ch
mov dx, [NABMBAR]
add dx, PO_SR_REG
out dx, ax
; 11/06/2017
mov al, RR
ac97_po_cmd:
; 11/06/2017
; 29/05/2017
mov dx, [NABMBAR]
add dx, PO_CR_REG ; PCM out control register
out dx, al
retn
print_msg:
; 13/11/2016 - Erdogan Tan
; esi = ASCIIZ text address
;
mov bx, 7h
mov ah, 0Eh
pm_next_char:
lodsb
and al, al
jz short pm_retn
int 10h
jmp short pm_next_char
pm_retn:
retn
; 06/11/2023
;dword2str:
; ; 13/11/2016 - Erdogan Tan
; ; eax = dword value
; ;
; call dwordtohex
; mov [dword_str], edx
; mov [dword_str+4], eax
; mov si, dword_str
; retn
; trdos386.s (unix386.s) - 10/05/2015
; Convert binary number to hexadecimal string
bytetohex:
; INPUT ->
; AL = byte (binary number)
; OUTPUT ->
; AX = hexadecimal string
;
push bx
xor bh, bh
mov bl, al
shr bl, 4
mov bl, [bx+hex_chars]
xchg bl, al
and bl, 0Fh
mov ah, [bx+hex_chars]
pop bx
retn
wordtohex:
; INPUT ->
; AX = word (binary number)
; OUTPUT ->
; EAX = hexadecimal string
;
push bx
xor bh, bh
xchg ah, al
push ax
mov bl, ah
shr bl, 4
mov al, [bx+hex_chars]
mov bl, ah
and bl, 0Fh
mov ah, [bx+hex_chars]
shl eax, 16
pop ax
pop bx
jmp short bytetohex
; 06/11/2023
;dwordtohex:
; ; INPUT ->
; ; EAX = dword (binary number)
; ; OUTPUT ->
; ; EDX:EAX = hexadecimal string
; ;
; push eax
; shr eax, 16
; call wordtohex
; mov edx, eax
; pop eax
; call wordtohex