-
Notifications
You must be signed in to change notification settings - Fork 1
/
ich_wav.asm
1067 lines (932 loc) · 23.7 KB
/
ich_wav.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
; 19/05/2024
; 11/11/2023
; 08/11/2023
; 06/11/2023
; 05/11/2023
; 04/11/2023
; 03/11/2023
; DOS based .WAV player using AC'97 and codec interface.
; ---------------------------------------------------------------
; NASM version: Erdogan Tan (29/11/2016)
; Last Update: 17/02/2017 (by Erdogan Tan)
; TUNELOOP version (playing without interrupt) - 06/11/2023 - Erdogan Tan
; ICHWAV.ASM
; player internal variables and other equates.
BUFFERSIZE equ 64 * 1024 ; 64k file buffer size.
ENDOFFILE equ BIT0 ; flag for knowing end of file
;===========================================================================
; entry: none. File is already open and [filehandle] filled.
; exit: not until the song is finished or the user aborts.
;
playWav:
; 07/11/2023
; clear buffer 2
;push es
;mov ax, [WAV_BUFFER2]
;mov es, ax
;sub ax, ax
;mov di, ax ; 17/02/2017
;mov cx, (BUFFERSIZE/2)
;rep stosw
;pop es
; load 64k into buffer 1
mov ax, [WAV_BUFFER1]
call loadFromFile
; and 64k into buffer 2
mov ax, [WAV_BUFFER2]
call loadFromFile
; register reset the DMA engine. This may cause a pop noise on the output
; lines when the device is reset. Prolly a better idea to mute output, then
; reset.
;
; 11/11/2023
;mov dx, [NABMBAR]
;add dx, PO_CR_REG ; set pointer to Ctrl reg
;mov al, RR ; set reset
;out dx, al ; self clearing bit
; write last valid index to 31 to start with.
; The Last Valid Index register tells the DMA engine when to stop playing.
;
; As we progress through the song we change the last valid index to always be
; something other than the index we're currently playing.
;
; 08/11/2023
;; 07/11/2023
;mov al, 1
;;mov al, 31
;call setLastValidIndex
; create Buffer Descriptor List
;
; A buffer descriptor list is a list of pointers and control bits that the
; DMA engine uses to know where to get the .wav data and how to play it.
;
; I set it up to use only 2 buffers of .wav data, and whenever 1 buffer is
; playing, I refresh the other one with good data.
;
;
; For the control bits, you can specify that the DMA engine fire an interrupt
; after a buffer has been processed, but I poll the current index register
; to know when it's safe to update the other buffer.
;
; I set the BUP bit, which tells the DMA engine to just play 0's (silence)
; if it ever runs out of data to play. Good for safety.
;
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:
; set buffer descriptor 0 to start of data file in memory
movzx eax, word [WAV_BUFFER1]
shl eax, 4 ; convert seg:off ->0:offset
stosd ; store pointer to wavbuffer1
;
; set length to 32k samples. 1 sample is 16bits or 2bytes.
; Set control (bits 31:16) to BUP, bits 15:0=number of samples.
;
; 17/02/2017 (Erdogan Tan)
; Intel® 82801AA (ICH) & Intel® 82801AB (ICH0) I/O Controller Hub AC’97
; Programmer’s Reference Manual
; 2.2.1 Buffer Descriptor List (on Page 13)
;
; Generic Form of Buffer Descriptor
; ---------------------------------
; 63 62 61-48 47-32 31-0
; --- --- -------- ------- -----
; IOC BUP -reserved- Buffer Buffer
; Length Pointer
; [15:0] [31:0]
;
; IOC: Interrupt On Completion.
; 1 = Enabled.
; When this is set, it means that the controller should
; issue an interrupt upon completion of this buffer.
; It should also set the IOC bit in the status register
; 0 = Disabled
;
; BUP: Buffer Underrun Policy.
; 0 = When this buffer is complete,
; if the next buffer is not yet ready
; (i.e., the last valid buffer has been processed),
; then continue to transmit the last valid sample.
; 1 = When this buffer is complete,
; if this is the last valid buffer, transmit zeros after
; this buffer has been processed completely.
; This bit typically is set only if this is the last
; buffer in the current stream.
;
; [31:0]: Buffer pointer. This field points to the location of
; the data buffer. Since samples can be as wide as one
; word, the buffer must be aligned with word boundaries,
; to prevent samples from straddling DWord boundaries.
;
; [15:0]: Buffer Length: This is the length of the data buffer,
; in number of samples. The controller uses this data
; to determine the length of the buffer, in bytes.
; "0" indicates no sample to process.
; ICH2AC97.INC
; IOC equ BIT31 ; Fire an interrupt whenever this
; buffer is complete.
; BUP equ BIT30 ; Buffer Underrun Policy.
; if this buffer is the last buffer
; in a playback, fill the remaining
; samples with 0 (silence) or not.
; It's a good idea to set this to 1
; for the last buffer in playback,
; otherwise you're likely to get a lot
; of noise at the end of the sound.
;
; Bits 15:0 contain the length of the buffer, in number of samples, which
; are 16 bits each, coupled in left and right pairs, or 32bits each.
; Luckily for us, that's the same format as .wav files.
;
; A value of FFFF is 65536 samples. Running at 44.1Khz, that's just about
; 1.5 seconds of sample time. FFFF * 32bits is 1FFFFh bytes or 128k of data.
;
; A value of 0 in these bits means play no samples.
;
; ICHWAV.ASM
; 19/05/2024
mov eax, BUFFERSIZE / 2 ; size of buffer (32K) in (16bit) words
;or eax, IOC + BUP
; 06/11/2023 (TUNELOOP version, without interrupt)
or eax, BUP
stosd
; 2nd buffer:
movzx eax, word [WAV_BUFFER2]
shl eax, 4 ; convert seg:off ->0:offset
stosd ; store pointer to wavbuffer2
; set length to 64k (32k of two 16 bit samples)
; Set control (bits 31:16) to BUP, bits 15:0=number of samples
;
mov eax, BUFFERSIZE / 2
;or eax, IOC + BUP
; 06/11/2023 (TUNELOOP version, without interrupt)
or eax, BUP
stosd
loop _0
pop es
;
; tell the DMA engine where to find our list of Buffer Descriptors.
; this 32bit value is a flat mode memory offset (ie no segment:offset)
;
; 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
;
; All set. Let's play some music.
;
; 08/11/2023
; 07/11/2023
; 08/12/2016
; 07/10/2016
;mov al, 1
mov al, 31
call setLastValidIndex
; 06/11/2023 (not neccessary)
;; 05/11/2023
;; reset current index
;mov al, 0
;call setCurrentIndex
; 06/11/2023
;mov byte [tLoop], 1 ; 30/11/2016
; 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
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.
; 06/11/2023 (TUNELOOP version, without interrupt)
%if 0
; 08/12/2016
; 28/11/2016
p_loop:
call check4keyboardstop ; keyboard halt?
jc short r_loop ; no ; 05/11/2023
;mov byte [tLoop], 0
; 04/11/2023
;mov byte [audio_play_cmd], 0
;call ac97_stop
;retn
_exit_:
; 04/11/2023
; finished with song, stop everything
call ac97_stop
; restore previous interrupt vector and interrupt_status
cli
in al, 0A1h ; irq 8-15
mov al, [IRQ_status+1]
out 0A1h, al
in al, 021h ; irq 0-7
mov al, [IRQ_status]
out 21h, al
; ...
push es
xor ax, ax
mov es, ax
mov ax, [IRQ_vector]
mov [es:bx], ax
mov ax, [IRQ_vector+2]
mov [es:bx+2], ax
pop es
sti
retn
r_loop:
; 07/12/2016 - Erdogan Tan
nop
nop
nop
; 17/02/2017
mov al, [tBuff]
dec al ; 1-32 -> 0-31 or 0 -> 0FFh
js short p_loop
mov byte [tBuff], 0 ; reset
and al, 1
jnz short q_loop
mov ax, [WAV_BUFFER2] ; [tBuff]=2 (from tuneLoop)
s_loop:
call loadFromFile
;jc short _exit_
; 05/11/2023
jc short exit_loop
jmp short r_loop
q_loop:
mov ax, [WAV_BUFFER1] ; [tBuff]=1 (from tuneLoop)
;call loadFromFile
;jc short _exit_
;jmp short r_loop
; 05/11/2023
jmp short s_loop
exit_loop:
mov byte [tLoop], 0
retn
tuneLoop:
; 05/11/2023
; 08/12/2016
; 28/11/2016 - Erdogan Tan
cmp byte [tLoop], 1
jb short _exit_ ; 05/11/2023
_tlp_1:
; 17/02/2017
call getCurrentIndex
inc al ; 0-31 -> 1-32
mov [tBuff], al
; 05/11/2023
dec ax
dec ax
and al, 1Fh
call setLastValidIndex
; 05/11/2023
; 17/02/2017 - Buffer switch test (temporary)
push ds
push si
mov si, 0B800h ; video display page segment
mov ds, si
sub si, si ; 0
mov ah, 4Eh
and al, 1
add al, '1'
mov [si], ax ; show current play buffer (1, 2)
pop si
pop ds
; 17/02/2017
;test byte [irq_status], LVBCI ; last buff completion intr.
;jz short _tlp2 ; BCIS ; Buffer completion interrupt
; Last Valid Buffer Completion Interrupt (LVBCI).
; 1 = Last valid buffer has been processed.
; It remains active until cleared by software.
; This bit indicates the occurrence of the event
; signified by the last valid buffer being processed.
; Thus, this is an event status bit that can be cleared
; by software once this event has been recognized.
; This event causes an interrupt if the enable bit
; in the Control Register is set. The interrupt is
; cleared when the software clears this bit.
; In the case of Transmits (PCM out, Modem out) this bit
; is set, after the last valid buffer has been
; fetched (not after transmitting it).
; While in the case of Receives, this bit is set after
; the data for the last buffer has been written to memory.
; 0 = Cleared by writing a "1" to this bit position.
; Note: We are not using LVBCI
; Last Buffer Completion Interrupt !!!
; 17/02/2017
;mov dx, [NABMBAR]
;add dx, PO_SR_REG ; PCM out Status register
;mov al, [irq_status]
;out dx, al ; Clear (LVBCI) interrupt status
;retn
;_tlp2:
; Buffer Completion Interrupt Status (BCIS).
; 1 = Set by the hardware after the last sample
; of a buffer has been processed, AND if the Interrupt
; on Completion (IOC) bit is set in the command byte of
; the buffer descriptor. It remains active
; until cleared by software.
; 0 = Cleared by writing a "1" to this bit position.
; 17/02/2017
mov dx, [NABMBAR]
add dx, PO_SR_REG ; PCM out Status register
mov al, [pcm_irq_status] ; 05/11/2023
out dx, al ; Clear (BCI) interrupt status
retn
;_exit_:
; mov byte [tLoop], 0
;_exit:
; ; finished with song, stop everything
; mov dx, [NABMBAR]
; add dx, PO_CR_REG ; PCM out Control Register
; mov al, 0
; out dx, al ; stop player
;_return:
; retn
%endif
; 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.
; 08/11/2023
; 07/11/2023
%if 1
tuneLoop:
; 08/11/2023
; 06/11/2023
mov al, '1'
call tL0
tL1:
call updateLVI ; /set LVI != CIV/
jz short _exit_ ; 08/11/2023
call check4keyboardstop
jc short _exit_
call getCurrentIndex
test al, BIT0
jz short tL1 ; loop if buffer 2 is not playing
; load buffer 1
mov ax, [WAV_BUFFER1]
call loadFromFile
jc short _exit_ ; end of file
mov al, '2'
call tL0
tL2:
call updateLVI
jz short _exit_ ; 08/11/2023
call check4keyboardstop
jc short _exit_
call getCurrentIndex
test al, BIT0
jnz short tL2 ; loop if buffer 1 is not playing
; load buffer 2
mov ax, [WAV_BUFFER2]
call loadFromFile
jnc short tuneLoop
_exit_:
mov dx, [NABMBAR]
add dx, PO_CR_REG ; PCM out Control Register
mov al, 0
out dx, al ; stop player
add al, '0'
;call tL0
;
;retn
; 06/11/2023
;jmp short tL0
;retn
; 06/11/2023
tL0:
; 08/11/2023
; 05/11/2023
; 17/02/2017 - Buffer switch test (temporary)
; 06/11/2023
; al = buffer indicator ('1', '2' or '0' -stop- )
push ds
;push bx
mov bx, 0B800h ; video display page segment
mov ds, bx
sub bx, bx ; 0
mov ah, 4Eh
mov [bx], ax ; show current play buffer (1, 2)
;pop bx
pop ds
retn
%endif
; 08/11/2023
; 07/11/2023
%if 0
tuneLoop:
; 07/11/2023
;mov dx, NABMBAR
;add dx, PO_CIV_REG ; 14h
tL1:
call updateLVI ; set LVI != CIV
call check4keyboardstop
jc short _exit_
call getCurrentIndex
test al, BIT0
jz short tL1 ; loop if buffer 2 is not playing
; load buffer 1
mov ax, [WAV_BUFFER1]
call loadFromFile
jc short _exit_ ; end of file
tL2:
call updateLVI
call check4keyboardstop
jc short _exit_
call getCurrentIndex
test al, BIT0
jnz short tL2 ; loop if buffer 1 is not playing
; load buffer 2
mov ax, [WAV_BUFFER2]
call loadFromFile
jnc short tuneLoop
_exit_:
mov dx, [NABMBAR]
add dx, PO_CR_REG ; PCM out Control Register
mov al, 0
out dx, al ; stop player
retn
%endif
; load data from file in 32k chunks. Would be nice to load 1 64k chunk,
; but in DOS you can only load FFFF bytes at a time.
;
; entry: ax = segment to load data to
; exit: CY set if end of file reached.
; note: last file buffer is padded with 0's to avoid pops at the end of song.
; assumes file is already open. uses [filehandle]
; 07/11/2023
%if 0
loadFromFile:
; 07/11/2023
; 06/11/2023
; 17/02/2017
;push ax
;push cx
;push dx
;push bx
;push es
;push ds
test byte [flags], ENDOFFILE ; have we already read the
;stc ; last of the file?
; 05/11/2023
;jnz endLFF
jz short lff_12 ; 06/11/2023
; 06/11/2023
;;mov byte [tLoop], 0
;jmp endLFF
stc
retn
lff_12: ; 06/11/2023
mov [fbs_seg], ax ; save buffer segment
xor dx, dx
lff_0:
mov [fbs_off], dx ; buffer offset
mov bx, (BUFFERSIZE / 2) ; 32k chunk
mov cl, [fbs_shift]
and cl, cl
jz short lff_1 ; stereo, 16 bit
; fbs_shift =
; 2 for mono and 8 bit sample (multiplier = 4)
; 1 for mono or 8 bit sample (multiplier = 2)
shr bx, cl ; 32K / multiplier
mov ax, cs
mov dx, temp_buffer ; temporary buffer for wav data
lff_1:
; 17/02/2017 (stereo/mono, 8bit/16bit corrections)
; load file into memory
mov cx, bx
mov bx, [filehandle]
mov ds, ax
mov ah, 3fh
int 21h
mov bx, cs
mov ds, bx
jc short lff_9 ; error !
and ax, ax
jz short lff_10
mov bl, [fbs_shift] ; shift count
or bl, bl
jz short lff_7 ; 16 bit stereo samples
push es
; 06/11/2023
;push di
;push si
mov di, [fbs_off]
mov si, [fbs_seg] ; buffer segment
mov es, si
mov si, temp_buffer ; temporary buffer address
mov cl, [bps] ; bits per sample (8 or 16)
cmp cl, 8
jne short lff_4 ; 16 bit samples
; 8 bit samples
mov cx, ax ; byte count
dec bl ; shift count, 1 = stereo, 2 = mono
jz short lff_3 ; 8 bit, stereo
lff_2:
; mono & 8 bit
lodsb
shl ax, 8 ; convert 8 bit sample to 16 bit sample
stosw ; left channel
stosw ; right channel
loop lff_2
jmp short lff_6
lff_3:
; stereo & 8 bit
lodsb
shl ax, 8 ; convert 8 bit sample to 16 bit sample
stosw
loop lff_3
jmp short lff_6
lff_4:
; 16 bit mono samples
mov cx, ax ; word count
lff_5:
lodsw
stosw ; left channel
stosw ; right channel
loop lff_5
lff_6:
mov ax, di ; save next buffer offset/position
; 06/11/2023
;pop si
;pop di
pop es
;lff_7:
; 06/11/2023
and ax, ax
jz short endLFF ; end of 2nd half
mov cx, (BUFFERSIZE / 2)
lff_7:
cmp ax, cx
je short endLFF ; 06/11/2023
;jb short lff_11
;xor cx, cx
;sub cx, ax
;neg cx
jmp short lff_11
lff_8:
; 07/11/2023
cmp word [fbs_off], (BUFFERSIZE / 2) ; 32768
jnb short endLFF
mov dx, ax ; buffer offset
mov ax, [fbs_seg] ; buffer segment
jmp lff_0
lff_9:
; 07/11/2023
;; 06/11/2023 (temporary)
;mov al, '!' ; error
;call tL0
xor ax, ax
lff_10:
; 07/11/2023
;mov cx, (BUFFERSIZE / 2)
lff_11:
call padfill ; blank pad the remainder
;clc ; don't exit with CY yet.
or byte [flags], ENDOFFILE ; end of file flag
endLFF:
;pop ds
;pop es
; 06/11/2023
;pop bx
;pop dx
;pop cx
;pop ax
retn
%endif
; 08/11/2023
; 07/11/2023
%if 1
loadFromFile:
; 07/11/2023
test byte [flags], ENDOFFILE ; have we already read the
; last of the file?
jz short lff_0 ; no
stc
retn
lff_0:
; 08/11/2023
mov bp, ax ; save buffer segment
mov cl, [fbs_shift]
and cl, cl
jz short lff_1 ; stereo, 16 bit
mov di, BUFFERSIZE - 1 ; 65535
; fbs_shift =
; 2 for mono and 8 bit sample (multiplier = 4)
; 1 for mono or 8 bit sample (multiplier = 2)
shr di, cl
inc di ; 16384 for 8 bit and mono
; 32768 for 8 bit or mono
mov ax, cs
mov dx, temp_buffer ; temporary buffer for wav data
; 17/02/2017 (stereo/mono, 8bit/16bit corrections)
; load file into memory
mov cx, di
mov bx, [filehandle]
mov ds, ax
mov ah, 3Fh
int 21h
mov bx, cs
mov ds, bx
jc short lff_4 ; error !
; 08/11/2023
xor dx, dx ; 0
and ax, ax
jz short lff_3
mov bl, [fbs_shift]
push es
mov di, dx ; 0 ; [fbs_off]
;mov bp, [fbs_seg] ; buffer segment
mov es, bp
mov si, temp_buffer ; temporary buffer address
mov cx, ax ; byte count
cmp byte [bps], 8 ; bits per sample (8 or 16)
jne short lff_7 ; 16 bit samples
; 8 bit samples
dec bl ; shift count, 1 = stereo, 2 = mono
jz short lff_6 ; 8 bit, stereo
lff_5:
; mono & 8 bit
lodsb
sub al, 80h ; 08/11/2023
shl ax, 8 ; convert 8 bit sample to 16 bit sample
stosw ; left channel
stosw ; right channel
loop lff_5
jmp short lff_9
lff_6:
; stereo & 8 bit
lodsb
sub al, 80h ; 08/11/2023
shl ax, 8 ; convert 8 bit sample to 16 bit sample
stosw
loop lff_6
jmp short lff_9
lff_7:
shr cx, 1 ; word count
lff_8:
lodsw
stosw ; left channel
stosw ; right channel
loop lff_8
lff_9:
pop es
or di, di
jz short endLFF ; 64KB ok
mov ax, di ; [fbs_off]
dec ax
mov cx, BUFFERSIZE - 1 ; 65535
jmp short lff_3
lff_1:
;mov bp, ax ; save buffer segment
xor dx, dx
; load file into memory
mov cx, (BUFFERSIZE / 2) ; 32k chunk
mov bx, [filehandle]
mov ds, ax
mov ah, 3Fh
int 21h
mov di, cs
mov ds, di
; 07/11/2023
jc short lff_4 ; error !
cmp ax, cx
jne short lff_3
lff_2:
; 08/11/2023
add dx, ax
;mov cx, (BUFFERSIZE / 2) ; 32k chunk
;mov bx, [filehandle]
mov ds, bp
mov ah, 3Fh
int 21h
;mov di, cs
mov ds, di
jc short lff_4 ; error !
cmp ax, cx
je short endLFF
lff_3:
call padfill ; blank pad the remainder
;clc ; don't exit with CY yet.
or byte [flags], ENDOFFILE ; end of file flag
endLFF:
retn
lff_4:
; 08/11/2023
mov al, '!' ; error
call tL0
xor ax, ax
jmp short lff_3
%endif
; entry ds:ax points to last byte in file
; cx=target size
; note: must do byte size fill
; destroys bx, cx
;
padfill:
; 07/11/2023
; 06/11/2023
; 17/02/2017
push es
;push di
;mov di, [fbs_seg]
;mov es, di
mov es, bp
sub cx, ax
; 08/11/2023
;mov di, ax ; (wrong)
mov di, dx ; buffer offset
add di, ax
; 07/11/2023
;add di, [fbs_off]
xor al, al
rep stosb
;mov [fbs_off], di
;pop di
pop es
retn
; returns AL = current index value
getCurrentIndex:
; 08/11/2023
;push dx
mov dx, [NABMBAR]
add dx, PO_CIV_REG
in al, dx
;pop dx
uLVI2: ; 06/11/2023
retn
; examines the CIV and the LVI. When they're the same, we set LVI <> CIV
; that way, we never run out of buffers to play
; 08/11/2023
%if 0
; 07/11/2023
updateLVI:
push ax
push dx
; 06/11/2023
mov dx, [NABMBAR]
add dx, PO_CIV_REG
; (Current Index Value and Last Valid Index value)
in ax, dx
cmp al, ah ; is current index = last index ?
jne short uLVI1
call setNewIndex
uLVI1:
pop dx
pop ax
retn
setNewIndex:
; 07/11/2023
push ax
call getCurrentIndex ; get CIV
test byte [flags], ENDOFFILE
jnz short sni_1
; not at the end of the file yet.
dec al ; make new index <> current
and al, INDEX_MASK ; make sure new value is 0-31
sni_1:
call setLastValidIndex ; write new value
clc
pop ax
retn
%endif
; 08/11/2023
; 07/11/2023
;%if 1
updateLVI:
; 06/11/2023
mov dx, [NABMBAR]
add dx, PO_CIV_REG
; (Current Index Value and Last Valid Index value)
in ax, dx
cmp al, ah ; is current index = last index ?
jne short uLVI2
; 08/11/2023
call getCurrentIndex
test byte [flags], ENDOFFILE
;jnz short uLVI1
jz short uLVI0 ; 08/11/2023
; 08/11/2023
push ax
mov dx, [NABMBAR]
add dx, PO_SR_REG ; PCM out status register
in ax, dx
test al, 3 ; bit 1 = Current Equals Last Valid (CELV)
; (has been processed)
; bit 0 = 1 -> DMA Controller Halted (DCH)
pop ax
jz short uLVI1
uLVI3:
xor ax, ax
; zf = 1
retn
uLVI0:
; not at the end of the file yet.
dec al
and al, 1Fh
uLVI1:
;call setLastValidIndex
;uLVI2:
;retn
;%endif
;input AL = index # to stop on
setLastValidIndex:
; 08/11/2023
;push dx
mov dx, [NABMBAR]
add dx, PO_LVI_REG
out dx, al
;pop dx
retn
; 06/11/2023
; ; 05/11/2023
;setCurrentIndex:
; ;push dx
; mov dx, [NABMBAR]
; add dx, PO_CIV_REG
; out dx, al
; ;pop dx
; retn
; checks if either shift key has been pressed. Exits with CY if so.
;
check4keyboardstop:
; 06/11/2023
%if 1
; 19/05/2024
; 08/11/2023
; 04/11/2023
mov ah, 1