-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathac97play.asm
6763 lines (5944 loc) · 141 KB
/
ac97play.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
; ****************************************************************************
; ac97play.asm (for Retro DOS)
; ----------------------------------------------------------------------------
; AC97PLAY.COM ! AC'97 (ICH) .WAV PLAYER program by Erdogan TAN
;
; 28/11/2024
;
; [ Last Modification: 18/12/2024 ]
;
; Modified from PLAYWAV8.COM .wav player program by Erdogan Tan, 25/11/2024
;
; Assembler: FASM 1.73
; fasm ac97play.asm AC97PLAY.COM
; ----------------------------------------------------------------------------
; In the visualization part of the code, the source code of Matan Alfasi's
; (Ami-Asaf) player.exe program was partially used.
; ----------------------------------------------------------------------------
; Previous versions of this Wav Player were based in part on .wav file player
; (for DOS) source code written by Jeff Leyla in 2002.
; playwav8.asm (25/11/2024)
; TUNELOOP version (playing without AC97 interrupt) - 06/11/2023 - Erdogan Tan
; sample rate conversion version - 18/11/2023 - Erdogan Tan
; CODE
; 13/11/2024
macro sys_msg op1,op2
{ ; 30/05/2024
mov si, op1 ; message
mov bl, op2 ; text color
xor bh, bh ; video page 0
mov ah, 0Eh
call p_msg
}
; player internal variables and other equates.
;BUFFERSIZE equ 64 * 1024 ; 64k file buffer size.
; 17/11/2024
BUFFERSIZE equ 65520
ENDOFFILE equ 1 ; flag for knowing end of file
use16
org 100h
include 'ac97.inc' ; 17/02/2017
_STARTUP:
; 30/05/2024
; Prints the Credits Text.
sys_msg Credits, 0Bh
; 30/05/2024
call setFree ; deallocate unused DOS mem
; 17/02/2017
; Clear BSS (uninitialized data) area
xor ax, ax ; 0
mov cx, (bss_end - bss_start)/2
mov di, bss_start
rep stosw
; Detect (& Enable) AC'97 Audio Device
call DetectAC97
;jnc short GetFileName
; 30/05/2024
jnc short allocate_memory
; 30/05/2024
_dev_not_ready:
; couldn't find the audio device!
sys_msg noDevMsg, 0Fh
jmp Exit
; 30/05/2024
allocate_memory:
; 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
;;;
; 28/11/2024
Player_InitalizePSP:
mov si, 81h
mov [PSP_CurrentOffset], si
cmp byte [si], 0Dh ; "CR": No command line parameters
ja short Player_ParseParameters
jmp pmsg_usage
Player_ParseParameters:
; 29/11/2024
; 18/12/2024
;mov dx, wav_file_name
cmp byte [IsInSplash], 0
jna short check_p_command
call write_audio_dev_info
mov dx, SplashFileName
jmp short _1
check_p_command:
cmp byte [command], 'P'
je short Player_ParsePreviousParameter
mov si, [PSP_CurrentOffset]
cmp byte [si], 0Dh
ja short Player_ParseNextParameter
jmp_Player_Quit:
jmp Player_Quit
Player_ParsePreviousParameter:
; 29/11/2024
;mov byte [command], 0
mov si, [PSP_CurrentOffset]
cmp si, 81h
je short Player_ParseNextParameter
;; Search for previous space character
dec si
mov cx, 2
PSPParsePrev_Search:
dec si
mov al, [si]
cmp al, 20h
jne short PSPParsePrev_Search
cmp si, 81h
jna PSPParsePrev_Copy
loop PSPParsePrev_Search
PSPParsePrev_Copy:
mov [PSP_CurrentOffset], si
Player_ParseNextParameter:
; 29/11/2024
call GetFileName
jcxz jmp_Player_Quit
; 28/11/2024
mov dx, wav_file_name
;;;
_1:
; open the file
; open existing file
; 14/11/2024
;mov al, OPEN ; open existing file
; 28/11/2024
;mov dx, wav_file_name
call openFile ; no error? ok.
jnc getwavparms ; 14/11/2024
; 28/11/2024
cmp byte [IsInSplash], 0
ja Player_SplashScreen
; 29/11/2024
cmp byte [filecount], 0
ja short check_p_command
call ClearScreen
sys_msg Credits, 0Bh
call write_audio_dev_info
wav_file_open_error:
; file not found!
sys_msg noFileErrMsg, 0Ch
_exit_:
jmp Exit
; 29/11/2024
; 30/05/2024
GetFileName:
mov di, wav_file_name
mov si, [PSP_CurrentOffset]
xor cx, cx ; 0
ScanName:
lodsb
;test al, al
;jz short a_4
; 29/11/2024
cmp al, 0Dh
jna short a_4
cmp al, 20h
je short ScanName ; scan start of name.
stosb
mov ah, 0FFh
;;;
; 14/11/2024
; (max. path length = 64 bytes for MSDOS ?) (*)
;xor cx, cx ; 0
;;;
a_0:
inc ah
a_1:
;;;
; 14/11/2024
inc cx
;;;
lodsb
stosb
cmp al, '.'
je short a_0
; 29/11/2024
cmp al, 20h
;and al, al
;jnz short a_1
;;;
; 14/11/2024
jna short a_3
and ah, ah
jz short a_2
cmp al, '\'
jne short a_2
mov ah, 0
a_2:
cmp cl, 75 ; 64+8+'.'+3 -> offset 75 is the last chr
jb short a_1
; 29/11/2024
sub cx, cx
jmp short a_4
a_3:
; 29/11/2024
dec di
;;;
or ah, ah ; if period NOT found,
jnz short a_4 ; then add a .WAV extension.
SetExt:
; 29/11/2024
;dec di
mov dword [di], '.WAV' ; ! 64+12 is DOS limit
; but writing +4 must not
; destroy the following data
;mov byte [di+4], 0 ; so, 80 bytes path + 0 is possible here
; 29/11/2024
add cx, 4
add di, 4
a_4:
mov byte [di], 0
dec si
mov [PSP_CurrentOffset], si
retn
getwavparms:
; 14/11/2024
call getWAVParameters
jc short _exit_ ; nothing to do
; 17/11/2024
mov bl, 4
sub bl, byte [WAVE_BlockAlign]
; = 0 for 16 bit stereo
; = 2 for 8 bit stereo or 16 bit mono
; = 3 for 8 bit mono
shr bl, 1 ; 0 --> 0, 2 --> 1, 3 --> 1
; 15/11/2024
adc bl, 0 ; 3 --> 1 --> 2
mov byte [fbs_shift], bl ; = 2 mono and 8 bit
; = 0 stereo and 16 bit
; = 1 mono or 8 bit
; 30/05/2024
call codecConfig ; unmute codec, set rates.
jc init_err
; 28/11/2024
cmp byte [IsInSplash], 0
jna short Player_Template
; 28/11/2024
Player_SplashScreen:
; 15/11/2024
;; Set video mode to 03h (not necessary)
mov ax, 03h
int 10h
; 15/11/2024
;; Get the cursor type
mov ah, 03h
int 10h
mov [cursortype], cx ; save
; 15/11/2024
;; Set the cursor to invisible
mov ah, 01h
mov cx, 2607h
int 10h
; 15/11/2024
;xor dx, dx
;call setCursorPosition
;; Print the splash screen in white
mov ax, 1300h
mov bx, 000Fh
mov cx, 1999
mov dx, 0
mov bp, SplashScreen
int 10h
;;;
;;;
; 22/11/2024
; set wave volume led addresses
mov bx, 13*80*2
mov bp, 80
mov di, wleds_addr
wleds_sa_1:
mov cx, 7
wleds_sa_2:
mov ax, 80*2
mul cx
add ax, bx
stosw
loop wleds_sa_2
mov ax, bx
stosw
inc bx
inc bx
dec bp
jnz short wleds_sa_1
;;;
; 28/11/2024
cmp word [filehandle], -1
jne short StartPlay
;;; wait for 3 seconds
mov cx, 002Dh
mov dx, 0C6C0h
mov ah, 86h
int 15h
;;;
; 28/11/2024
mov byte [IsInSplash], 0
;mov dx, wav_file_name
;jmp _1
; 29/11/2024
jmp Player_ParseNextParameter
; 28/11/2024
Player_Template:
;;;
; 09/12/2024
; 29/11/2024
inc byte [filecount]
mov byte [command], 0
;;;
xor dx, dx
call setCursorPosition
;; Print the splash screen in white
mov ax, 1300h
mov bx, 000Fh
mov cx, 1999
; 09/12/2024
; dx = 0
;mov dx, 0
mov bp, Template
int 10h
;;;
; 14/11/2024
call SetTotalTime
call UpdateFileInfo
; 28/11/2024
StartPlay:
; 25/11/2023
; ------------------------------------------
; 18/11/2023 (ich_wav4.asm)
; 13/11/2023 (ich_wav3.asm)
cmp byte [VRA], 1
jb short chk_sample_rate
playwav_48_khz:
mov word [loadfromwavfile], loadFromFile
;mov word [loadsize], 0 ; 65536
;;;
; 17/11/2024
;mov word [buffersize], 32768
mov ax, BUFFERSIZE/2 ; 32760
mov [buffersize], ax ; 16 bit samples
shl ax, 1 ; bytes
mov cl, [fbs_shift]
shr ax, cl
mov [loadsize], ax ; 16380 or 32760 or 65520
;;;
jmp PlayNow ; 30/05/2024
chk_sample_rate:
; set conversion parameters
; (for 8, 11.025, 16, 22.050, 24, 32 kHZ)
mov ax, [WAVE_SampleRate]
cmp ax, 48000
je short playwav_48_khz
chk_22khz:
cmp ax, 22050
jne short chk_11khz
cmp byte [WAVE_BitsPerSample], 8
jna short chk_22khz_1
mov bx, load_22khz_stereo_16_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_22khz_2
mov bx, load_22khz_mono_16_bit
jmp short chk_22khz_2
chk_22khz_1:
mov bx, load_22khz_stereo_8_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_22khz_2
mov bx, load_22khz_mono_8_bit
chk_22khz_2:
mov ax, 7514 ; (442*17)
mov dx, 37
mov cx, 17
jmp set_sizes
chk_11khz:
cmp ax, 11025
jne short chk_44khz
cmp byte [WAVE_BitsPerSample], 8
jna short chk_11khz_1
mov bx, load_11khz_stereo_16_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_11khz_2
mov bx, load_11khz_mono_16_bit
jmp short chk_11khz_2
chk_11khz_1:
mov bx, load_11khz_stereo_8_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_11khz_2
mov bx, load_11khz_mono_8_bit
chk_11khz_2:
mov ax, 3757 ; (221*17)
mov dx, 74
mov cx, 17
jmp set_sizes
chk_44khz:
cmp ax, 44100
jne short chk_16khz
cmp byte [WAVE_BitsPerSample], 8
jna short chk_44khz_1
mov bx, load_44khz_stereo_16_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_44khz_2
mov bx, load_44khz_mono_16_bit
jmp short chk_44khz_2
chk_44khz_1:
mov bx, load_44khz_stereo_8_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_44khz_2
mov bx, load_44khz_mono_8_bit
chk_44khz_2:
;mov ax, 15065 ; (655*23)
; 18/11/2023 ((file size + bss + stack) <= 64KB)
;mov ax, 14076 ; (612*23)
; 17/11/2024
mov ax, 12650 ; (550*23)
mov dx, 25
mov cx, 23
jmp set_sizes
chk_16khz:
cmp ax, 16000
jne short chk_8khz
cmp byte [WAVE_BitsPerSample], 8
jna short chk_16khz_1
mov bx, load_16khz_stereo_16_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_16khz_2
mov bx, load_16khz_mono_16_bit
jmp short chk_16khz_2
chk_16khz_1:
mov bx, load_16khz_stereo_8_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_16khz_2
mov bx, load_16khz_mono_8_bit
chk_16khz_2:
;mov ax, 5461
; 17/11/2024
mov ax, 5460
mov dx, 3
mov cx, 1
jmp set_sizes
chk_8khz:
cmp ax, 8000
jne short chk_24khz
cmp byte [WAVE_BitsPerSample], 8
jna short chk_8khz_1
mov bx, load_8khz_stereo_16_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_8khz_2
mov bx, load_8khz_mono_16_bit
jmp short chk_8khz_2
chk_8khz_1:
mov bx, load_8khz_stereo_8_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_8khz_2
mov bx, load_8khz_mono_8_bit
chk_8khz_2:
mov ax, 2730
mov dx, 6
mov cx, 1
jmp short set_sizes
chk_24khz:
cmp ax, 24000
jne short chk_32khz
cmp byte [WAVE_BitsPerSample], 8
jna short chk_24khz_1
mov bx, load_24khz_stereo_16_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_24khz_2
mov bx, load_24khz_mono_16_bit
jmp short chk_24khz_2
chk_24khz_1:
mov bx, load_24khz_stereo_8_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_24khz_2
mov bx, load_24khz_mono_8_bit
chk_24khz_2:
;mov ax, 8192
; 17/11/2024
mov ax, 8190
mov dx, 2
mov cx, 1
jmp short set_sizes
chk_32khz:
cmp ax, 32000
jne short vra_needed
cmp byte [WAVE_BitsPerSample], 8
jna short chk_32khz_1
mov bx, load_32khz_stereo_16_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_32khz_2
mov bx, load_32khz_mono_16_bit
jmp short chk_32khz_2
chk_32khz_1:
mov bx, load_32khz_stereo_8_bit
cmp byte [WAVE_NumChannels], 1
jne short chk_32khz_2
mov bx, load_32khz_mono_8_bit
chk_32khz_2:
;mov ax, 10922
; 17/11/2024
mov ax, 10920
mov dx, 3
mov cx, 2
;jmp short set_sizes
set_sizes:
;;;
; 17/11/2024
push cx
mov cl, 2
sub cl, [fbs_shift]
; = 2 for 16 bit stereo
; = 1 for 16 bit mono or 8 bit stereo
; = 0 for 8 bit mono
shl ax, cl
pop cx
mov [loadsize], ax ; (one) read count in bytes
;;;
mul dx
cmp cx, 1
je short s_2
s_1:
div cx
s_2:
;;;
; ax = byte count of (to be) converted samples
; 17/11/2024
;;;
mov cl, [fbs_shift]
shl ax, cl
; *1 for 16 bit stereo
; *2 for 16 bit mono or 8 bit stereo
; *4 for for 8 bit mono
;;;
; ax = 16 bit stereo byte count (target buffer size)
shr ax, 1 ; buffer size is 16 bit sample count
mov [buffersize], ax
mov [loadfromwavfile], bx
jmp short PlayNow
vra_needed:
; 13/11/2023
pop ax ; discard return address to the caller
; 30/05/2024
vra_err:
sys_msg msg_no_vra, 0Fh
jmp Exit
; 15/11/2024
; 30/05/2024
; 13/11/2023 (ich_wav4.asm)
;loadfromwavfile:
; dw loadFromFile
;loadsize: ; read from wav file
; dw 0
;buffersize: ; write to DMA buffer
; dd 32768 ; 16 bit samples (not bytes)
PlayNow:
;;;
; 14/11/2024
;mov al, 3 ; 0 = max, 31 = min
; 14/12/2024
mov al, [volume]
call SetPCMOutVolume@
; 15/11/2024
;;call SetMasterVolume
;call SetPCMOutVolume
; 29/11/2024
cmp byte [IsInSplash], 0
;ja short PlayNow@
; 02/12/2024
jna short PlayNow@
;PlayNow@:
; 28/11/2024
;cmp byte [IsInSplash], 0
;ja short _3
;
;call UpdateVolume
;
; 02/12/2024
jmp short _3
; 02/12/2024
PlayNow@:
; reset file loading and EOF parameters
;mov word [count], 0
mov word [LoadedDataBytes], 0
mov word [LoadedDataBytes+2], 0
mov byte [flags], 0
mov byte [stopped], 0
;jmp short PlayNow@@
PlayNow@@:
;;;
;
; 14/11/2024
call UpdateProgressBar
;;;
; 30/05/2024
; playwav4.asm
_2:
call check4keyboardstop ; flush keyboard buffer
jc short _2 ; 07/11/2023
; play the .wav file. Most of the good stuff is in here.
_3:
call PlayWav
; 29/11/2024
; 28/11/2024
call closeFile
;mov dx, wav_file_name
cmp byte [IsInSplash], 0
;jna short Exit
jna short _4 ; 29/11/2024
mov byte [IsInSplash], 0
;jmp _1
; 29/11/2024
jmp Player_ParseNextParameter
; 29/11/2024
_4:
cmp byte [command], 'Q'
je short Exit
jmp check_p_command
; close the .wav file and exit.
Exit:
; 15/11/2024
;; Restore Cursor Type
mov cx, [cursortype]
cmp cx, 0
jz short Exit@
mov ah, 01h
int 10h
Exit@:
; 29/11/2024
;call closeFile
Exit@@:
mov ax, 4C00h ; bye !
int 21h
here:
jmp short here ; do not come here !
; 30/05/2024
pmsg_usage:
sys_msg msg_usage, 0Fh ; 14/11/2024
jmp short Exit
; 30/05/2024
init_err:
sys_msg msg_init_err, 0Fh
jmp short Exit
; 29/11/2024
Player_Quit:
call ClearScreen
jmp short Exit@@
ClearScreen:
mov ax, 03h
int 10h
retn
; --------------------------------------------
; 29/05/2024 (TRDOS 386, playwav7.s)
; ((Modified from playwav4.asm, ich_wav4.asm))
; ------------------
;playwav_vra:
PlayWav:
; create Buffer Descriptor List
; Generic Form of Buffer Descriptor
; ---------------------------------
; 63 62 61-48 47-32 31-0
; --- --- -------- ------- -----
; IOC BUP -reserved- Buffer Buffer
; Length Pointer
; [15:0] [31:0]
push es
mov ax, [BDL_BUFFER] ; get segment # for BDL
mov es, ax
mov cx, 32 / 2 ; make 32 entries in BDL
xor di, di
_0:
movzx eax, word [WAV_BUFFER1]
shl eax, 4 ; convert seg:off ->0:offset
stosd ; store pointer to wavbuffer1
;mov eax, BUFFERSIZE / 2 ; size of buffer (32K) in (16bit) words
; 13/11/2023 (ich_wav3.asm) - 18/11/2023 (ich_wav4.asm)
mov eax, [buffersize]
;or eax, IOC + BUP
; 06/11/2023 (TUNELOOP version, without interrupt)
or eax, BUP
stosd
movzx eax, word [WAV_BUFFER2]
shl eax, 4 ; convert seg:off ->0:offset
stosd ; store pointer to wavbuffer2
;mov eax, BUFFERSIZE / 2 ; size of half buffer (32K)
; 13/11/2023 (ich_wav3.asm) - 18/11/2023 (ich_wav4.asm)
mov eax, [buffersize]
;or eax, IOC + BUP
; 06/11/2023 (TUNELOOP version, without interrupt)
or eax, BUP
stosd
loop _0
pop es
; 18/12/2024
mov word [count], cx ; 0
; 14/11/2024
;mov dword [LoadedDataBytes], 0
; 19/11/2024
RePlayWav:
; load 64k into buffer 1
mov ax, [WAV_BUFFER1]
;call loadFromFile
; 13/11/2023
call word [loadfromwavfile]
; 14/11/2024
mov ax, [count]
add [LoadedDataBytes], ax
adc word [LoadedDataBytes+2], 0
; and 64k into buffer 2
mov ax, [WAV_BUFFER2]
;call loadFromFile
; 13/11/2023
call word [loadfromwavfile]
; 14/11/2024
mov ax, [count]
add [LoadedDataBytes], ax
adc word [LoadedDataBytes+2], 0
; write NABMBAR+10h with offset of buffer descriptor list
movzx eax, word [BDL_BUFFER]
shl eax, 4 ; convert seg:off to 0:off
mov dx, [NABMBAR]
add dx, PO_BDBAR_REG ; set pointer to BDL
out dx, eax ; write to AC97 controller
; 19/05/2024
call delay1_4ms
mov al, 31
call setLastValidIndex
; 19/05/2024
;call delay1_4ms
; 17/02/2017
mov dx, [NABMBAR]
add dx, PO_CR_REG ; PCM out Control Register
;mov al, IOCE + RPBM ; Enable 'Interrupt On Completion' + run
; ; (LVBI interrupt will not be enabled)
; 06/11/2023 (TUNELOOP version, without interrupt)
mov al, RPBM
out dx, al ; Start bus master operation.
; 19/05/2024
; 06/11/2023
call delay1_4ms ; 30/05/2024
;call delay1_4ms
;call delay1_4ms
;call delay1_4ms
; while DMA engine is running, examine current index and wait until it hits 1
; as soon as it's 1, we need to refresh the data in wavbuffer1 with another
; 64k. Likewise when it's playing buffer 2, refresh buffer 1 and repeat.
; 18/11/2023
; 08/11/2023
; 07/11/2023
; 19/11/2024
mov byte [wleds], 1
;;;
; 09/12/2024
mov ax, 10548 ; (48000*10/182)*4
cmp byte [VRA], 0
jna short sL0 ; 48kHZ (interpolation)
;
mov ax, [WAVE_SampleRate]
mov cx, 10
mul cx
mov cl, 182
div cx
; ax = samples per 1/18.2 second
;mov cl, byte [WAVE_BlockAlign]
; 09/12/2024
;mov cl, 4 ; 16 bit, stereo
;mul cx
shl ax, 2 ; * 4
sL0:
mov [wleds_dif], ax ; buffer read differential (distance)
; for wave volume leds update
; (byte stream per 1/18.2 second)
;;;
; 28/11/2024
cmp byte [IsInSplash], 0
jna short tuneLoop
sL1:
call updateLVI ; /set LVI != CIV/
jz short sL3
call getCurrentIndex
test al, BIT0
jz short sL1 ; loop if buffer 2 is not playing
; load buffer 1
mov ax, [WAV_BUFFER1]
call word [loadfromwavfile]
jc short sL3
sL2:
call updateLVI
jz short sL3
call getCurrentIndex
test al, BIT0
jnz short sL2 ; loop if buffer 1 is not playing
; load buffer 2
mov ax, [WAV_BUFFER2]
call word [loadfromwavfile]
jnc short sL1
sL3:
mov dx, [NABMBAR]
add dx, PO_CR_REG ; PCM out Control Register
mov al, 0
out dx, al ; stop player
; 29/11/2024
;; reset file loading and EOF parameters
;;mov word [count], 0
;mov word [LoadedDataBytes], 0
;mov word [LoadedDataBytes+2], 0
;mov byte [flags], 0
retn
; 29/11/2024
tuneLoop:
; 30/05/2024
; 18/11/2023 (ich_wav4.asm)
; 08/11/2023
; 06/11/2023
tLWait:
; 18/11/2024
cmp byte [stopped], 0
;jna short tL@
; 21/11/2024
ja short tLWait@
mov al, [tLP]
cmp al, '1'
ja short tL2@
je short tL1@
mov al, '1'
mov [tLP], al
jmp short tL1@
tLWait@: ; 21/11/2024
;;;
; 09/12/2024
cmp byte [stopped], 3
jnb _exitt_
;;;
call checkUpdateEvents
jc _exitt_
;;;
; 29/11/2024
cmp byte [command], 'N'
je _exitt_
cmp byte [command], 'P'
je _exitt_
;;;
cmp byte [tLO], '0'
je short tLWait
call tLZ
mov byte [tLO], '0'
jmp short tLWait
;tLO: db 0
tL1@:
;mov al, '1'
; 19/11/2024
mov [tLO], al
call tL0
tL1:
call updateLVI ; /set LVI != CIV/
jz short _exitt_ ; 08/11/2023
;;;
;call check4keyboardstop
; 14/11/2024
call checkUpdateEvents
jc short _exitt_
; 18/11/2024
cmp byte [stopped], 0
ja short tLWait@ ; 21/11/2024
;;;
call getCurrentIndex
test al, BIT0
jz short tL1 ; loop if buffer 2 is not playing
; load buffer 1
mov ax, [WAV_BUFFER1]
;call loadFromFile
; 18/11/2023
call word [loadfromwavfile]
jc short _exitt_ ; end of file
; 14/11/2024
mov ax, [count]
add [LoadedDataBytes], ax