     1                                  ; ****************************************************************************
     2                                  ; twavplay.asm (for Retro DOS)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; TWAVPLAY.COM ! AC'97 (ICH) WAV PLAYER & VGA DEMO program by Erdogan TAN
     5                                  ;
     6                                  ; 06/02/2025
     7                                  ;
     8                                  ; [ Last Modification: 10/02/2025 ]
     9                                  ;
    10                                  ; Assembler: NASM 2.15
    11                                  ; ----------------------------------------------------------------------------
    12                                  ;	   nasm  twavplay.asm -l twavplay.lst -o TWAVPLAY.COM
    13                                  ; ****************************************************************************
    14                                  
    15                                  %macro	sys_msg	2
    16                                  	mov	si, %1	; message
    17                                  	mov	bl, %2	; text color
    18                                  	xor	bh, bh	; video page 0
    19                                  	mov	ah, 0Eh
    20                                  	call	p_msg	
    21                                  %endmacro
    22                                  
    23                                  %macro SbOut 1
    24                                  %%wait:
    25                                  	in	al, dx
    26                                  	or	al, al
    27                                  	js	short %%wait
    28                                  	mov	al, %1	; command
    29                                  	out	dx, al
    30                                  %endmacro
    31                                  
    32                                  ; ----------------------------------------------------------------------------
    33                                  
    34                                  ;BUFFERSIZE equ 65520 ; AC97
    35                                  ; 07/02/2025
    36                                  ;BUFFERSIZE equ 33680 ; AC97
    37                                  ; 08/02/2025	
    38                                  ;BUFFERSIZE equ 10548 ; AC97 ; 48kHZ 16bit stereo audio block (18.2 block/s) 
    39                                  
    40                                  ENDOFFILE equ 1	; flag for knowing end of file
    41                                  
    42                                  ;LOADSIZE equ 16384 ; SB16
    43                                  ;dma_buffer_size equ 32768  ; SB16
    44                                  ; 08/02/2025
    45                                  ;LOADSIZE equ 10560 ; SB16 ; 48kHZ 16bit stereo audio block (18.2 block/s)
    46                                  
    47                                  ; ----------------------------------------------------------------------------
    48                                  ; Reference:
    49                                  ; ----------
    50                                  ; Tiny Player v2.11 by Carlos Hasan.
    51                                  ;	June, 1994.
    52                                  
    53                                  ;=============================================================================
    54                                  ;	code
    55                                  ;=============================================================================
    56                                  
    57                                  [BITS 16] ; 16-bit intructions
    58                                  
    59                                  [ORG 100h]
    60                                  
    61                                  	; 06/02/2025
    62                                  Start:
    63                                  	; Prints the Credits Text.
    64                                  	sys_msg Credits, 0Bh
    16 00000000 BE[E468]            <1>  mov si, %1
    17 00000003 B30B                <1>  mov bl, %2
    18 00000005 30FF                <1>  xor bh, bh
    19 00000007 B40E                <1>  mov ah, 0Eh
    20 00000009 E86525              <1>  call p_msg
    65                                  
    66                                  	; deallocate unused DOS memory
    67 0000000C E85025                  	call    setFree
    68                                  
    69                                  	; Clear BSS (uninitialized data) area
    70 0000000F 31C0                    	xor	ax, ax ; 0
    71 00000011 B95C05                  	mov	cx, (bss_end - bss_start)/2
    72 00000014 BF[106C]                	mov	di, bss_start
    73 00000017 F3AB                    	rep	stosw
    74                                  
    75                                  	; Detect (& Enable) AC'97 or SB16 Audio Device
    76 00000019 E8E620                  	call	detect_audio_device
    77 0000001C 730E                    	jnc     short GetFileName
    78                                  
    79                                  _dev_not_ready:
    80                                  	; couldn't find the audio device!
    81                                  	sys_msg noDevMsg, 0Fh
    16 0000001E BE[5169]            <1>  mov si, %1
    17 00000021 B30F                <1>  mov bl, %2
    18 00000023 30FF                <1>  xor bh, bh
    19 00000025 B40E                <1>  mov ah, 0Eh
    20 00000027 E84725              <1>  call p_msg
    82 0000002A EB60                            jmp     Exit
    83                                  
    84                                  ; ----------------------------------------------------------------------------
    85                                  
    86                                  GetFileName:
    87 0000002C BE8100                  	mov	si, 81h
    88 0000002F AC                      	lodsb
    89 00000030 3C0D                    	cmp	al, 0Dh	; CR : No command line parameters
    90 00000032 7702                    	ja	short _x
    91 00000034 EB4A                    	jmp	pmsg_usage
    92                                  
    93                                  _x:
    94 00000036 BF[486C]                	mov	di, wav_file_name
    95 00000039 31C9                    	xor	cx, cx ; 0
    96 0000003B EB05                    	jmp	short _y
    97                                  
    98                                  ScanName:       
    99 0000003D AC                      	lodsb
   100                                  
   101 0000003E 3C0D                    	cmp	al, 0Dh	; CR
   102 00000040 7634                    	jna	short a_4
   103                                  _y:
   104 00000042 3C20                    	cmp	al, 20h
   105 00000044 74F7                    	je	short ScanName	; scan start of name.
   106 00000046 AA                      	stosb
   107 00000047 B4FF                    	mov	ah, 0FFh
   108                                  a_0:	
   109 00000049 FEC4                    	inc	ah
   110                                  a_1:
   111 0000004B 41                      	inc	cx
   112 0000004C AC                      	lodsb
   113 0000004D AA                      	stosb
   114 0000004E 3C2E                    	cmp	al, '.'
   115 00000050 74F7                    	je	short a_0
   116 00000052 3C20                    	cmp	al, 20h
   117 00000054 7611                    	jna	short a_3
   118 00000056 20E4                    	and	ah, ah
   119 00000058 7406                    	jz	short a_2
   120                                  
   121 0000005A 3C5C                    	cmp	al, '\'
   122 0000005C 7502                    	jne	short a_2
   123 0000005E B400                    	mov	ah, 0
   124                                  a_2:
   125 00000060 80F94B                  	cmp	cl, 75	; 64+8+'.'+3 -> offset 75 is the last chr
   126 00000063 72E6                    	jb	short a_1
   127 00000065 EB0F                    	jmp	short a_4
   128                                  a_3:
   129 00000067 4F                      	dec	di
   130 00000068 08E4                    	or	ah, ah		; if period NOT found,
   131 0000006A 750A                    	jnz	short a_4 	; then add a .WAV extension.
   132                                  SetExt:
   133 0000006C 66C7052E574156          	mov	dword [di], '.WAV' ; ! 64+12 is DOS limit
   134                                  				   ;   but writing +4 must not
   135                                  				   ;   destroy the following data
   136                                  				; so, 80 bytes path + 0 is possible here
   137 00000073 83C704                  	add	di, 4
   138                                  a_4:	
   139 00000076 C60500                  	mov	byte [di], 0
   140                                  	
   141 00000079 803E[486C]20            	cmp	byte [wav_file_name], 20h
   142 0000007E 7713                    	ja	short open_wav_file
   143                                  
   144                                  ; ----------------------------------------------------------------------------
   145                                  
   146                                  pmsg_usage: 
   147                                  	sys_msg msg_usage, 0Fh
    16 00000080 BE[3069]            <1>  mov si, %1
    17 00000083 B30F                <1>  mov bl, %2
    18 00000085 30FF                <1>  xor bh, bh
    19 00000087 B40E                <1>  mov ah, 0Eh
    20 00000089 E8E524              <1>  call p_msg
   148                                  
   149                                  Exit:
   150 0000008C B8004C                  	mov	ax, 4C00h	; bye !
   151 0000008F CD21                    	int	21h
   152                                  halt:
   153 00000091 EBFE                    	jmp	short halt
   154                                  
   155                                  ; ----------------------------------------------------------------------------
   156                                  
   157                                  open_wav_file:
   158                                          ; open existing file
   159 00000093 BA[486C]                	mov	dx, wav_file_name
   160 00000096 E8FC00                          call    openFile ; no error? ok.
   161 00000099 731C                            jnc     short _z
   162                                  
   163                                  	; file not found!
   164                                  	sys_msg	noFileErrMsg, 0Fh
    16 0000009B BE[8369]            <1>  mov si, %1
    17 0000009E B30F                <1>  mov bl, %2
    18 000000A0 30FF                <1>  xor bh, bh
    19 000000A2 B40E                <1>  mov ah, 0Eh
    20 000000A4 E8CA24              <1>  call p_msg
   165                                  
   166 000000A7 EBE3                    	jmp	short Exit
   167                                  
   168                                  not_valid_wav:
   169                                  	; not a proper/valid wav file !
   170                                  	sys_msg	not_valid_wavf, 0Fh
    16 000000A9 BE[9E69]            <1>  mov si, %1
    17 000000AC B30F                <1>  mov bl, %2
    18 000000AE 30FF                <1>  xor bh, bh
    19 000000B0 B40E                <1>  mov ah, 0Eh
    20 000000B2 E8BC24              <1>  call p_msg
   171                                  
   172 000000B5 EBD5                    	jmp	short Exit
   173                                  
   174                                  _z:
   175 000000B7 E8F100                         	call    getWAVParameters
   176 000000BA 72ED                    	jc	short not_valid_wav
   177                                  
   178 000000BC B304                    	mov	bl, 4
   179 000000BE 8A0E[3C6C]              	mov	cl, [WAVE_BlockAlign]
   180 000000C2 28CB                    	sub	bl, cl	; = 0 for 16 bit stereo
   181                                  			; = 2 for 8 bit stereo or 16 bit mono
   182                                  			; = 3 for 8 bit mono
   183                                  
   184 000000C4 D0EB                    	shr	bl, 1	; 0 --> 0, 2 --> 1, 3 --> 1
   185 000000C6 80D300                  	adc	bl, 0	; 3 --> 1 --> 2
   186 000000C9 881E[9C6C]              	mov	[fbs_shift], bl	; = 2 mono and 8 bit
   187                                  				; = 0 stereo and 16 bit
   188                                  				; = 1 mono or 8 bit
   189                                  
   190                                  	; 07/02/2025
   191 000000CD 803E[AA6C]01            	cmp	byte [audio_hardware], 1 ; SB16 ?
   192                                  	;jne	short write_info
   193                                  	; 08/02/2025
   194                                  	;jne	short audio_hardware_init
   195 000000D2 750A                    	jne	short _r
   196                                  				; no, skip [g_samples] calculation
   197                                  
   198                                  	; count of audio samples for graphics data
   199 000000D4 B80001                  	mov	ax, 256
   200 000000D7 D0E9                    	shr	cl, 1
   201                                  	; 0 = 8 bit mono, 1 = 16 bit mono or 8 bit stereo
   202                                  	; 2 = 16 bit stereo  
   203 000000D9 D3E0                    	shl	ax, cl
   204 000000DB A3[CA76]                	mov	[g_samples], ax ; 256 .. 1024
   205                                  
   206                                  	; 08/02/2025
   207                                  _r:
   208                                  	; calculate 18.2 block/s buffer size for proper wave scope
   209 000000DE A1[346C]                	mov	ax, [WAVE_SampleRate]
   210 000000E1 BA2800                  	mov	dx, 4*10
   211 000000E4 F7E2                    	mul	dx
   212 000000E6 B9B600                  	mov	cx, 182
   213 000000E9 F7F1                    	div	cx
   214 000000EB 88D9                    	mov	cl, bl	; 0 = stereo & 16bit
   215                                  			; 1 = mono 16bit or stereo 8bit
   216                                  			; 2 = mono & 8bit
   217 000000ED 24FC                    	and	al, ~3 ; NOT 3
   218 000000EF D3E8                    	shr	ax, cl
   219                                  		; AX = 
   220                                  		; 10548 bytes for 48kHZ 16bit stereo
   221                                  		; 9692 bytes for 44kHZ 16bit stereo
   222                                  		; 7032 bytes for 32kHZ 16bit stereo
   223                                  		; 5272 bytes for 24kHz 16bit stereo
   224                                  		; 4844 bytes for 22kHZ 16bit stereo 
   225                                  		; 3516 bytes for 16kHZ 16bit stereo
   226                                  		; 2636 bytes for 12kHZ 16bit stereo
   227                                  		; 2420 bytes for 11kHZ 16bit stereo
   228                                  		; 1756 bytes for 8kHZ 16bit stereo
   229                                  
   230 000000F1 A3[B876]                	mov	[loadsize], ax
   231                                  	
   232 000000F4 803E[AA6C]01            	cmp	byte [audio_hardware], 1 ; SB16 ?
   233 000000F9 7404                    	je	short _t		; yes	
   234                                  
   235                                  	; AC97 codec plays 16 bit stereo PCM data only
   236 000000FB D3E0                    	shl	ax, cl
   237                                  	; count of 16 bit samples
   238 000000FD D1E8                    	shr	ax, 1
   239                                  _t:
   240 000000FF A3[BA76]                	mov	[buffersize], ax ; (if audio hardware supports vra)	
   241                                  		 
   242                                  ; ----------------------------------------------------------------------------
   243                                  
   244                                  	; 08/02/2025
   245                                  
   246                                  audio_hardware_init:
   247                                  
   248 00000102 E8FF18                  	call	audio_system_init
   249 00000105 7285                    	jc	short Exit
   250                                  
   251                                  write_info:
   252                                  
   253 00000107 E8B716                  	call	write_audio_dev_info
   254                                  
   255 0000010A E87818                  	call	write_wav_file_info
   256                                  
   257                                  	; 07/02/2025
   258                                  
   259                                  	sys_msg	msgPressAKey, 07h
    16 0000010D BE[DA6B]            <1>  mov si, %1
    17 00000110 B307                <1>  mov bl, %2
    18 00000112 30FF                <1>  xor bh, bh
    19 00000114 B40E                <1>  mov ah, 0Eh
    20 00000116 E85824              <1>  call p_msg
   260                                  
   261 00000119 30E4                    	xor	ah, ah
   262 0000011B CD16                    	int	16h
   263                                  
   264 0000011D 3C1B                    	cmp	al, 1Bh ; ESC
   265                                  	;jne	short _continue
   266                                  	;jmp	short Exit
   267                                  	; 08/02/2025
   268                                  	;je	short Exit
   269                                  	; 08/02/2025 (*)
   270 0000011F 7503                    	jne	short _continue
   271 00000121 E968FF                  	jmp	Exit
   272                                  
   273                                  _continue:
   274                                  	;call	audio_system_init
   275                                  	;jc	short Exit
   276                                  
   277                                  ; ----------------------------------------------------------------------------
   278                                  
   279                                  PlayNow: 
   280 00000124 B90001                  	mov	cx, 256
   281 00000127 31DB                    	xor	bx, bx
   282 00000129 BF[B06C]                	mov	di, RowOfs
   283                                  MakeOfs:
   284 0000012C 89D8                    	mov	ax, bx
   285 0000012E C1E007                  	shl	ax, 7 ; * 128
   286 00000131 B050                    	mov	al, 80
   287 00000133 F6E4                    	mul	ah
   288 00000135 AB                      	stosw
   289 00000136 43                      	inc	bx
   290 00000137 E2F3                    	loop	MakeOfs
   291                                  
   292                                  ; ----------------------------------------------------------------------------
   293                                  
   294                                  	;;;;
   295                                  setgraphmode:
   296                                  	; set VGA 640x480x16 graphics mode
   297 00000139 B81200                          mov     ax, 12h
   298 0000013C CD10                            int     10h
   299 0000013E BAC003                          mov     dx, 3C0h
   300 00000141 30C0                            xor     al, al
   301                                  setgraphmodel0:
   302 00000143 EE                              out     dx, al
   303 00000144 EE                              out     dx, al
   304 00000145 FEC0                            inc     al
   305 00000147 3C10                            cmp     al, 10h
   306 00000149 72F8                            jb	short setgraphmodel0
   307 0000014B B020                            mov     al, 20h
   308 0000014D EE                              out     dx, al
   309                                  	;;;;
   310                                  
   311                                  ; ----------------------------------------------------------------------------
   312                                  	
   313                                  	;mov	si, LOGO_ADDRESS
   314 0000014E E82A24                  	call	putlbm
   315                                  ;	; 07/02/2025
   316                                  ;	jnc	short loadlbm_ok
   317                                  ;
   318                                  ;loadlbm_err:
   319                                  ;	call	settextmode
   320                                  ;	sys_msg	LOGO_ERROR_MSG, 0Ch
   321                                  ;	jmp	Exit
   322                                  ;
   323                                  ;LOGO_ERROR_MSG:
   324                                  ;	db "Error loading the IFF/ILBM logo picture !", 0Dh, 0Ah, 0
   325                                  ;
   326                                  ;loadlbm_ok:
   327                                  
   328                                  ; ----------------------------------------------------------------------------
   329                                  	
   330                                  	; 08/02/2025
   331 00000151 803E[AA6C]01            	cmp	byte [audio_hardware], 1
   332 00000156 7522                    	jne	short skip_sdc
   333                                  	
   334                                  	; 07/02/2025
   335                                  	; parepare g_buffer wave graphics parameters
   336                                  
   337 00000158 BB[3D25]                	mov	bx, sdc_16bit_stereo
   338                                  
   339 0000015B A0[3C6C]                	mov	al, [WAVE_BlockAlign]
   340 0000015E 3C04                    	cmp	al, 4
   341 00000160 7414                    	je	short set_sdc_p_ok
   342 00000162 BB[5425]                	mov	bx, sdc_8bit_mono
   343 00000165 3C01                    	cmp	al, 1
   344 00000167 740D                    	je	short set_sdc_p_ok
   345 00000169 BB[4A25]                	mov	bx, sdc_8bit_stereo
   346 0000016C 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
   347 00000171 7403                    	je	short set_sdc_p_ok
   348 00000173 BB[4225]                	mov	bx, sdc_16bit_mono
   349                                  set_sdc_p_ok:
   350 00000176 891E[C876]              	mov	[sound_data_copy], bx
   351                                  
   352                                  skip_sdc:
   353                                  
   354                                  ; ----------------------------------------------------------------------------
   355                                  
   356                                  	; play the .wav file.
   357                                  
   358 0000017A E86200                  	call	PlayWav
   359                                  
   360                                  ; ----------------------------------------------------------------------------
   361                                  
   362                                  	; close the .wav file and exit.
   363 0000017D E82100                  	call	closeFile
   364                                  
   365                                  ; ----------------------------------------------------------------------------
   366                                  
   367                                  	; 07/02/2025
   368 00000180 803E[AA6C]01            	cmp	byte [audio_hardware], 1
   369 00000185 7508                    	jne	short terminate
   370                                  
   371                                  	; restore old interrupt vector
   372 00000187 A0[9A6C]                	mov	al, [audio_intr] ; 5 or 7
   373 0000018A 30E4                    	xor	ah, ah ; reset
   374 0000018C E8DB21                  	call	set_hardware_int_vector
   375                                  
   376                                  ; ----------------------------------------------------------------------------
   377                                  
   378                                  terminate:
   379 0000018F E8A122                  	call	settextmode
   380                                  	
   381 00000192 E9F7FE                  	jmp	Exit
   382                                  
   383                                  ; ----------------------------------------------------------------------------
   384                                  
   385                                  	; 06/02/2025
   386                                  	; INPUT: ds:dx = file name address
   387                                  	; OUTPUT: [FileHandle]
   388                                  openFile:
   389 00000195 B8003D                  	mov	ax, 3D00h	; open File for read
   390 00000198 CD21                    	int	21h
   391 0000019A 7301                    	jnc	short _of1
   392                                  	; cf = 1 -> not found or access error
   393 0000019C C3                      	retn
   394                                  _of1:
   395 0000019D A3[DF68]                	mov	[FileHandle], ax
   396 000001A0 C3                      	retn
   397                                  
   398                                  ; ----------------------------------------------------------------------------
   399                                  
   400                                  	; 06/02/2025
   401                                  	; INPUT: [FileHandle]
   402                                  	; OUTPUT: none
   403                                  closeFile:
   404 000001A1 8B1E[DF68]              	mov	bx, [FileHandle]
   405 000001A5 B8003E                  	mov	ax, 3E00h
   406 000001A8 CD21                    	int	21h	; close file
   407 000001AA C3                      	retn
   408                                  
   409                                  ; ----------------------------------------------------------------------------
   410                                  
   411                                  	; 06/02/2025
   412                                  getWAVParameters:
   413 000001AB BA[1C6C]                        mov     dx, WAVFILEHEADERbuff
   414 000001AE 8B1E[DF68]              	mov	bx, [FileHandle]
   415 000001B2 B92C00                          mov     cx, 44	; 44 bytes
   416 000001B5 B43F                    	mov	ah, 3Fh
   417 000001B7 CD21                            int     21h
   418 000001B9 7223                    	jc	short gwavp_retn
   419                                  
   420 000001BB 83F82C                  	cmp	ax, 44
   421 000001BE 721E                    	jb	short gwavp_retn
   422                                  
   423 000001C0 66813E[246C]574156-     	cmp	dword [RIFF_Format], 'WAVE'
   423 000001C8 45                 
   424 000001C9 7512                    	jne	short gwavp_stc_retn
   425                                  
   426 000001CB 833E[306C]01            	cmp	word [WAVE_AudioFormat], 1 ; Offset 20, must be 1 (= PCM)
   427 000001D0 750B                    	jne	short gwavp_stc_retn
   428                                  
   429                                  	; (OpenMPT creates wav files with a new type header,
   430                                  	;  this program can not use the new type
   431                                  	;  because of 'data' offset is not at DATA_SubchunkID.)
   432                                  	; ((GoldWave creates common type wav file.))
   433                                  
   434 000001D2 66813E[406C]646174-     	cmp	dword [DATA_SubchunkID], 'data'
   434 000001DA 61                 
   435 000001DB 7401                    	je	short gwavp_retn
   436                                  
   437                                  gwavp_stc_retn:
   438 000001DD F9                      	stc
   439                                  gwavp_retn:
   440 000001DE C3                      	retn
   441                                  
   442                                  ;=============================================================================
   443                                  ;
   444                                  ;=============================================================================
   445                                  
   446                                  	; 08/02/2025 (*) (Wave scope/graphics synchronization)
   447                                  	; 06/02/2025
   448                                  PlayWav:
   449 000001DF 803E[AA6C]01            	cmp	byte [audio_hardware], 1
   450 000001E4 7751                    	ja	short playwav_ac97
   451                                  
   452                                  playwav_sb16:
   453 000001E6 803E[AE6C]01            	cmp	byte [stopped], 1
   454                                  	; 07/02/2025
   455 000001EB 720C                    	jb	short playwav_sb16_@
   456                                  
   457                                  	; replay
   458 000001ED C606[AE6C]00            	mov	byte [stopped], 0
   459 000001F2 C606[006C]01            	mov	byte [half_buffer], 1
   460                                  
   461 000001F7 EB0B                    	jmp	short playwav_sb16_@@
   462                                  
   463                                  playwav_sb16_@:
   464                                  	; set audio interrupt vector (to user's handler)
   465 000001F9 A0[AB6C]                	mov	al, [IRQnum]
   466 000001FC B401                    	mov	ah, 1 ; set
   467 000001FE BA[F023]                	mov	dx, IRQ_service
   468 00000201 E86621                  	call	set_hardware_int_vector
   469                                  
   470                                  playwav_sb16_@@:
   471                                  	;mov	ax, wav_buffer1
   472                                  	; 08/02/2025 (*)
   473 00000204 B8[D07A]                	mov	ax, dma_buffer
   474 00000207 E86402                  	call	SB16_LoadFromFile
   475                                  
   476 0000020A A1[BE76]                	mov	ax, [count]
   477 0000020D 0106[C076]              	add	[LoadedDataBytes], ax
   478 00000211 8316[C276]00            	adc	word [LoadedDataBytes+2], 0
   479                                  
   480                                  	;mov	ax, wav_buffer2
   481                                  	; 08/02/2025 (*)
   482 00000216 B8[D07A]                	mov	ax, dma_buffer
   483 00000219 0306[B876]              	add	ax, [loadsize] ; = add ax, [buffersize]
   484 0000021D E84E02                  	call	SB16_LoadFromFile
   485                                  
   486 00000220 A1[BE76]                	mov	ax, [count]
   487 00000223 0106[C076]              	add	[LoadedDataBytes], ax
   488 00000227 8316[C276]00            	adc	word [LoadedDataBytes+2], 0
   489                                  
   490 0000022C E89C18                  	call	sb16_init_play
   491                                  
   492 0000022F C606[AB6C]00            	mov	byte [IRQnum], 0
   493 00000234 E98C00                  	jmp	SB16_TuneLoop
   494                                  
   495                                  playwav_ac97:
   496                                  	; 08/02/2025
   497 00000237 803E[AE6C]01            	cmp	byte [stopped], 1
   498 0000023C 720A                    	jb	short playwav_ac97_@
   499                                  
   500 0000023E C606[AE6C]00            	mov	byte [stopped], 0
   501                                  
   502 00000243 E8C71D                  	call	ac97_RePlayWav
   503                                  
   504 00000246 EB06                    	jmp	short AC97_TuneLoop
   505                                  
   506                                  playwav_ac97_@:
   507 00000248 E87C1B                  	call	ac97_play_setup
   508                                  
   509 0000024B E8811D                  	call	ac97_init_play
   510                                  
   511                                  	;jmp	short AC97_TuneLoop
   512                                  
   513                                  ; ----------------------------------------------------------------------------
   514                                  
   515                                  	; 08/02/2025
   516                                  	; 06/02/2025
   517                                  AC97_TuneLoop:
   518                                  	; 04/02/2025 (cgaplay.asm)
   519                                  
   520                                  ;tuneLoop:
   521                                  tLWait:
   522 0000024E 803E[AE6C]00            	cmp	byte [stopped], 0
   523 00000253 760E                    	jna	short tL1 
   524                                  tLWait@:
   525 00000255 803E[AE6C]03            	cmp	byte [stopped], 3
   526 0000025A 7305                    	jnb	short tL0
   527                                  
   528 0000025C E8A700                  	call	checkUpdateEvents
   529 0000025F 73ED                    	jnc	short tLWait
   530                                  tL0:
   531 00000261 EB21                    	jmp	_exitt_
   532                                  tL1:
   533 00000263 E8681E                  	call	updateLVI	; /set LVI != CIV/
   534 00000266 74F9                    	jz	short tL0
   535                                  
   536 00000268 E89B00                  	call	checkUpdateEvents
   537 0000026B 72F4                    	jc	short tL0
   538                                  
   539 0000026D 803E[AE6C]00            	cmp	byte [stopped], 0
   540 00000272 77E1                    	ja	short tLWait@
   541                                  
   542 00000274 E84E1E                  	call	getCurrentIndex
   543 00000277 A801                    	test	al, BIT0
   544 00000279 74E8                    	jz	short tL1	; loop if buffer 2 is not playing
   545                                  
   546                                  	; load buffer 1
   547 0000027B A1[B276]                	mov     ax, [WAV_BUFFER_1]
   548 0000027E FF16[B676]              	call	word [loadfromwavfile]
   549 00000282 7304                    	jnc	short tL2
   550                                  
   551                                  	; end of file
   552                                  _exitt_:
   553                                  	; Stop Playing
   554 00000284 E8DE1D                  	call	ac97_stop
   555                                  
   556 00000287 C3                      	retn
   557                                  
   558                                  tL2:
   559 00000288 A1[BE76]                	mov	ax, [count]
   560 0000028B 0106[C076]              	add	[LoadedDataBytes], ax
   561 0000028F 8316[C276]00            	adc	word [LoadedDataBytes+2], 0
   562                                  tL3:
   563 00000294 E8371E                  	call    updateLVI
   564 00000297 74EB                    	jz	short _exitt_
   565                                  
   566 00000299 E86A00                  	call	checkUpdateEvents
   567 0000029C 72E6                    	jc	short _exitt_
   568                                  
   569 0000029E 803E[AE6C]00            	cmp	byte [stopped], 0
   570 000002A3 77B0                    	ja	short tLWait@
   571                                  
   572 000002A5 E81D1E                  	call    getCurrentIndex
   573 000002A8 A801                    	test	al, BIT0
   574                                  	;jnz	short tL2	; loop if buffer 1 is not playing
   575                                  	; 08/02/2025
   576 000002AA 75E8                    	jnz	short tL3
   577                                  
   578                                  	; load buffer 2
   579 000002AC A1[B476]                	mov     ax, [WAV_BUFFER_2]
   580 000002AF FF16[B676]              	call	word [loadfromwavfile]
   581 000002B3 72CF                    	jc	short _exitt_
   582                                  
   583 000002B5 A1[BE76]                	mov	ax, [count]
   584 000002B8 0106[C076]              	add	[LoadedDataBytes], ax
   585 000002BC 8316[C276]00            	adc	word [LoadedDataBytes+2], 0
   586                                  
   587 000002C1 EB8B                    	jmp	short tLWait
   588                                  
   589                                  ; ----------------------------------------------------------------------------
   590                                  
   591                                  	; 08/02/2025 (*)
   592                                  	; 06/02/2025
   593                                  SB16_TuneLoop:
   594                                  	; 04/02/2025 (cgaplay2.asm)
   595                                  ;TuneLoop:
   596                                  .tLWait:
   597 000002C3 803E[AE6C]00            	cmp	byte [stopped], 0
   598 000002C8 7609                    	jna	short .tL2
   599                                  .tL1:
   600 000002CA E83900                  	call	checkUpdateEvents
   601 000002CD 73F4                    	jnc	short .tLWait
   602                                  ._exit_:
   603 000002CF E87D18                  	call	sb16_stop
   604                                  
   605 000002D2 C3                      	retn
   606                                  .tL2:
   607                                  	; Check SB 16 interrupt status
   608 000002D3 803E[AB6C]00            	cmp	byte [IRQnum], 0
   609 000002D8 76F0                    	jna	short .tL1
   610                                  
   611 000002DA 8036[006C]01            	xor	byte [half_buffer], 1
   612                                  
   613 000002DF C606[AB6C]00            	mov	byte [IRQnum], 0
   614                                  
   615                                  	; load buffer 1
   616 000002E4 B8[D07A]                	mov     ax, dma_buffer  ; wav_buffer1
   617 000002E7 803E[006C]00            	cmp	byte [half_buffer], 0
   618 000002EC 7604                    	jna	short .tL3
   619                                  
   620                                  	; load buffer 2
   621                                  	;add	ax, LOADSIZE	; ax = wav_buffer2
   622                                  	; 08/02/2025 (*)
   623 000002EE 0306[B876]              	add	ax, [loadsize]
   624                                  .tL3:
   625 000002F2 E87901                  	call	SB16_LoadFromFile
   626 000002F5 72D8                    	jc	short ._exit_	; end of file
   627                                  
   628 000002F7 A1[BE76]                	mov	ax, [count]
   629 000002FA 0106[C076]              	add	[LoadedDataBytes], ax
   630 000002FE 8316[C276]00            	adc	word [LoadedDataBytes+2], 0
   631                                  
   632 00000303 EBC5                    	jmp	short .tL1
   633                                  
   634                                  ;=============================================================================
   635                                  ;
   636                                  ;=============================================================================
   637                                  
   638                                  c4ue_ok:
   639 00000305 C3                      	retn
   640                                  
   641                                  	; 06/02/2025
   642                                  checkUpdateEvents:
   643 00000306 E87F00                  	call	check4keyboardstop
   644 00000309 72FA                    	jc	short c4ue_ok
   645                                  
   646 0000030B 50                      	push	ax ; *
   647 0000030C 09C0                    	or	ax, ax
   648 0000030E 7444                    	jz	short c4ue_cpt
   649                                  
   650 00000310 3C20                    	cmp	al, 20h ; SPACE (spacebar) ; pause/play
   651 00000312 7520                    	jne	short c4ue_chk_s
   652 00000314 803E[AE6C]00            	cmp	byte [stopped], 0
   653 00000319 7705                    	ja	short c4ue_chk_ps
   654                                  
   655 0000031B E8571D                  	call	audio_pause
   656                                  
   657 0000031E EB34                    	jmp	short c4ue_cpt
   658                                  
   659                                  c4ue_chk_ps:
   660 00000320 803E[AE6C]01            	cmp	byte [stopped], 1
   661 00000325 7705                    	ja	short c4ue_replay
   662                                  
   663                                  	; continue to play (after a pause)
   664 00000327 E85C1D                  	call	audio_play
   665                                  
   666 0000032A EB28                    	jmp	short c4ue_cpt
   667                                  
   668                                  c4ue_replay:
   669 0000032C 58                      	pop	ax ; *
   670 0000032D 58                      	pop	ax ; return address
   671                                  
   672 0000032E E80101                  	call	move_to_beginning
   673                                  
   674                                  	;mov	byte [stopped], 0
   675                                  
   676 00000331 E9ABFE                  	jmp	PlayWav
   677                                  
   678                                  c4ue_chk_s:
   679 00000334 3C53                    	cmp	al, 'S'	; stop
   680 00000336 750C                    	jne	short c4ue_chk_fb
   681 00000338 803E[AE6C]00            	cmp	byte [stopped], 0
   682 0000033D 7715                    	ja	c4ue_cpt ; Already stopped/paused
   683                                  
   684 0000033F E8191D                  	call	audio_stop
   685                                  
   686 00000342 EB10                    	jmp	short c4ue_cpt
   687                                  
   688                                  c4ue_chk_fb:
   689 00000344 3C46                    	cmp	al, 'F'
   690 00000346 7505                    	jne	short c4ue_chk_b
   691 00000348 E8C300                  	call 	move_forward
   692 0000034B EB07                    	jmp	short c4ue_cpt
   693                                  
   694                                  c4ue_chk_b:
   695 0000034D 3C42                    	cmp	al, 'B'
   696 0000034F 7503                    	jne	short c4ue_cpt
   697                                  
   698 00000351 E8BA00                  	call 	move_backward
   699                                  
   700                                  c4ue_cpt:
   701 00000354 1E                      	push	ds
   702 00000355 BB4000                  	mov	bx, 40h
   703 00000358 8EDB                    	mov	ds, bx
   704 0000035A BB6C00                  	mov	bx, 6Ch  ; counter (INT 08h, 18.2 ticks per sec)
   705                                  	;cli
   706 0000035D 8B07                    	mov	ax, [bx]
   707 0000035F 8B5702                  	mov	dx, [bx+2]
   708                                  	;sti
   709 00000362 1F                      	pop	ds
   710 00000363 59                      	pop	cx ; *
   711 00000364 3B16[C676]              	cmp	dx, [timerticks+2]
   712 00000368 7506                    	jne	short c4ue_utt
   713 0000036A 3B06[C476]              	cmp	ax, [timerticks]
   714 0000036E 7409                    	je	short c4ue_skip_utt
   715                                  c4ue_utt:
   716 00000370 A3[C476]                	mov	[timerticks], ax
   717 00000373 8916[C676]              	mov	[timerticks+2], dx
   718 00000377 EB05                    	jmp	short c4ue_cpt_@
   719                                  
   720                                  c4ue_skip_utt:
   721 00000379 21C9                    	and	cx, cx
   722 0000037B 7401                    	jz	short c4ue_cpt_@
   723                                  c4ue_vb_ok:
   724 0000037D C3                      	retn
   725                                  
   726                                  c4ue_cpt_@:
   727 0000037E 803E[AE6C]00            	cmp	byte [stopped], 0
   728 00000383 77F8                    	ja	short c4ue_vb_ok
   729                                  
   730 00000385 E9B120                  	jmp	drawscopes
   731                                  
   732                                  ;=============================================================================
   733                                  ;
   734                                  ;=============================================================================
   735                                  
   736                                  	; 06/02/2025
   737                                  check4keyboardstop:
   738 00000388 B401                    	mov	ah, 1
   739 0000038A CD16                    	int	16h
   740                                  	;clc
   741 0000038C 7419                    	jz	short _cksr
   742                                  
   743 0000038E 30E4                    	xor	ah, ah
   744 00000390 CD16                    	int	16h
   745                                  
   746                                  	; (change PCM out volume)
   747 00000392 3C2B                    	cmp	al, '+'
   748 00000394 7506                    	jne	short p_1
   749                                  
   750 00000396 FE06[AD6C]              	inc	byte [volume]
   751 0000039A EB08                    	jmp	short p_2
   752                                  p_1:
   753 0000039C 3C2D                    	cmp	al, '-'
   754 0000039E 750A                    	jne	short p_4
   755                                  
   756 000003A0 FE0E[AD6C]              	dec	byte [volume]
   757                                  p_2:
   758 000003A4 E81E00                  	call	SetPCMOutVolume
   759                                  _cksr:
   760 000003A7 31C0                    	xor	ax, ax
   761                                  p_3:
   762 000003A9 C3                      	retn
   763                                  p_4:
   764 000003AA 80FC01                  	cmp	ah, 01h  ; ESC
   765 000003AD 7414                        	je	short p_quit
   766 000003AF 3C03                    	cmp	al, 03h  ; CTRL+C
   767 000003B1 7410                    	je	short p_quit
   768                                  
   769 000003B3 3C20                    	cmp	al, 20h
   770 000003B5 74F2                    	je	short p_3
   771                                  
   772 000003B7 3C0D                    	cmp	al, 0Dh ; CR/ENTER
   773 000003B9 74EE                    	je	short p_3
   774                                  
   775 000003BB 24DF                    	and	al, 0DFh
   776                                  
   777 000003BD 3C51                    	cmp	al, 'Q'
   778 000003BF 7402                    	je	short p_quit
   779                                  
   780 000003C1 F8                      	clc
   781 000003C2 C3                      	retn
   782                                  
   783                                  p_quit:
   784 000003C3 F9                      	stc
   785 000003C4 C3                      	retn
   786                                  
   787                                  ;-----------------------------------------------------------------------------
   788                                  ;
   789                                  ;-----------------------------------------------------------------------------
   790                                  
   791                                  	; 06/02/2025
   792                                  SetPCMOutVolume:
   793 000003C5 803E[AA6C]01            	cmp	byte [audio_hardware], 1
   794 000003CA 741B                    	je	short sb16_set_volume
   795                                  
   796                                  ;-----------------------------------------------------------------------------
   797                                  
   798                                  ac97_set_volume:
   799 000003CC A0[AD6C]                	mov	al, [volume]
   800 000003CF B41F                    	mov	ah, 31
   801 000003D1 38E0                    	cmp	al, ah ; 31
   802 000003D3 7605                    	jna	short _ac97sv_@
   803 000003D5 88E0                    	mov	al, ah
   804 000003D7 A2[AD6C]                	mov	[volume], al ; max = 31, min = 0
   805                                  _ac97sv_@:
   806                                  	; max = 0, min = 31
   807 000003DA 28C4                    	sub	ah, al
   808 000003DC 88E0                    	mov	al, ah
   809 000003DE 8B16[A66C]              	mov	dx, [NAMBAR]
   810                                    	;add	dx, CODEC_MASTER_VOL_REG
   811 000003E2 83C218                  	add	dx, CODEC_PCM_OUT_REG
   812 000003E5 EF                      	out	dx, ax
   813 000003E6 C3                      	retn
   814                                  
   815                                  ;-----------------------------------------------------------------------------
   816                                  
   817                                  sb16_set_volume:
   818 000003E7 A0[AD6C]                	mov	al, [volume]
   819 000003EA B40F                    	mov	ah, 15
   820 000003EC 38E0                    	cmp	al, ah ; 15
   821 000003EE 7605                    	jna	short _sb16sv_@
   822 000003F0 88E0                    	mov	al, ah
   823 000003F2 A2[AD6C]                	mov	[volume], al ; max = 15, min = 0
   824                                  _sb16sv_@:
   825                                  	; al = sound volume (15 = max, 0 = min)
   826 000003F5 50                      	push	ax
   827                                  	; Tell the SB 16 card which register to write
   828 000003F6 8B16[A66C]              	mov	dx, [audio_io_base]
   829                                  	;add	dx, 4 ; Mixer chip address port
   830 000003FA 80C204                  	add	dl, 4
   831 000003FD B022                    	mov	al, 22h
   832 000003FF EE                      	out	dx, al
   833 00000400 58                      	pop	ax
   834                                  	;and	al, 0Fh
   835                                  	; Set the volume for both L and R
   836 00000401 B311                    	mov	bl, 11h
   837 00000403 F6E3                    	mul	bl
   838                                  	; Set new volume
   839 00000405 8B16[A66C]              	mov	dx, [audio_io_base]
   840                                  	;add	dx, 5
   841 00000409 80C205                  	add	dl, 5
   842 0000040C EE                      	out	dx, al
   843 0000040D C3                      	retn
   844                                  
   845                                  ;=============================================================================
   846                                  ; 07/02/2025 - change song (wave file) play position
   847                                  ;=============================================================================
   848                                  
   849                                  move_backward:
   850                                  	; 07/02/2025
   851                                  move_forward:
   852                                  	;; In order to go backwards 5 seconds:
   853                                  	;; Update file pointer to the beginning, skip headers
   854 0000040E 88C1                    	mov	cl, al ; 'B' or 'F'
   855                                  
   856                                  	; 04/02/2025 - cgaplay.asm
   857                                  	; 01/01/2025 (cgaplay.asm, 16bit registers)
   858                                  	; 01/12/2024 (32bit registers)
   859                                  move_backward_or_forward:
   860                                  	; 17/11/2024
   861                                  	; 04/11/2024
   862                                  	; (Ref: player.asm, Matan Alfasi, 2017)
   863                                    
   864                                  	; 04/11/2024
   865 00000410 B80500                  	mov	ax, 5
   866 00000413 8B1E[3C6C]              	mov	bx, [WAVE_BlockAlign]
   867 00000417 F7E3                    	mul	bx
   868 00000419 8B1E[346C]              	mov	bx, [WAVE_SampleRate]
   869 0000041D F7E3                    	mul	bx
   870                                  	; dx:ax = transfer byte count for 5 seconds
   871                                  
   872                                  	; 17/11/2024
   873 0000041F 80F942                  	cmp	cl, 'B'
   874 00000422 8B1E[C076]              	mov	bx, [LoadedDataBytes]
   875 00000426 8B0E[C276]              	mov	cx, [LoadedDataBytes+2]
   876 0000042A 750C                    	jne	short move_fw ; cl = 'F'
   877                                  move_bw:
   878 0000042C 29C3                    	sub	bx, ax
   879 0000042E 19D1                    	sbb	cx, dx
   880 00000430 7322                    	jnc	short move_file_pointer
   881                                  move_to_beginning:
   882 00000432 31C9                    	xor	cx, cx ; 0
   883 00000434 31DB                    	xor	bx, bx ; 0
   884 00000436 EB1C                    	jmp	short move_file_pointer
   885                                  move_fw: 
   886 00000438 01C3                    	add	bx, ax
   887 0000043A 11D1                    	adc	cx, dx
   888 0000043C 720E                    	jc	short move_to_end
   889 0000043E 3B0E[466C]              	cmp	cx, [DATA_SubchunkSize+2]
   890 00000442 7708                    	ja	short move_to_end
   891 00000444 720E                    	jb	short move_file_pointer
   892 00000446 3B1E[446C]              	cmp	bx, [DATA_SubchunkSize]
   893 0000044A 7608                    	jna	short move_file_pointer
   894                                  move_to_end:
   895 0000044C 8B1E[446C]              	mov	bx, [DATA_SubchunkSize]
   896 00000450 8B0E[466C]              	mov	cx, [DATA_SubchunkSize+2]
   897                                  move_file_pointer:
   898 00000454 89DA                    	mov	dx, bx
   899 00000456 8916[C076]              	mov	[LoadedDataBytes], dx
   900 0000045A 890E[C276]              	mov	[LoadedDataBytes+2], cx
   901 0000045E 83C22C                  	add	dx, 44 ; + header
   902 00000461 83D100                  	adc	cx, 0
   903                                  
   904                                  	; seek
   905 00000464 8B1E[DF68]              	mov	bx, [FileHandle]
   906 00000468 B80042                  	mov	ax, 4200h
   907 0000046B CD21                    	int	21h
   908                                  
   909 0000046D C3                      	retn
   910                                  
   911                                  ;=============================================================================
   912                                  ; Wave Data Loading procedure for Sound Blaster 16 (there is not a conversion)
   913                                  ;=============================================================================
   914                                  
   915                                  	; 08/02/2025 (*)
   916                                  	; 07/02/2025
   917                                  SB16_LoadFromFile:
   918 0000046E F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
   919                                  					; last of the file?
   920 00000473 7402                    	jz	short sblff_0		; no
   921 00000475 F9                      	stc
   922 00000476 C3                      	retn
   923                                  
   924                                  sblff_0:
   925 00000477 89C7                    	mov	di, ax ; save buffer address
   926                                  
   927 00000479 8B1E[DF68]              	mov	bx, [FileHandle]
   928                                  
   929                                  	;mov	cx, LOADSIZE
   930                                  	; 08/02/2025 (*)
   931 0000047D 8B0E[B876]              	mov	cx, [loadsize]
   932 00000481 89C2                    	mov	dx, ax ; buffer address
   933                                  
   934                                  	; load/read file
   935                                  	; bx = file handle
   936                                  	; ds = cs
   937                                  	; ds:dx = buffer
   938                                  	; cx = read count
   939                                  
   940 00000483 B43F                           	mov	ah, 3Fh
   941 00000485 CD21                    	int	21h
   942 00000487 7212                    	jc	short sblff_2 ; error !
   943                                  
   944 00000489 A3[BE76]                	mov	[count], ax
   945                                  
   946 0000048C 39C8                    	cmp	ax, cx
   947 0000048E 740A                    	je	short _endLFF
   948                                  
   949                                  	; di = buffer address
   950 00000490 01C7                    	add	di, ax
   951                                  sblff_1:
   952 00000492 E80A00                  	call    sb_padfill		; blank pad the remainder
   953                                          ;clc				; don't exit with CY yet.
   954 00000495 800E[9D6C]01                    or	byte [flags], ENDOFFILE	; end of file flag
   955                                  	; 07/02/2025
   956                                  	;cmp	word [count], 1
   957                                  _endLFF:
   958 0000049A C3                              retn
   959                                  
   960                                  sblff_2:
   961 0000049B 31C0                    	xor	ax, ax
   962 0000049D EBF3                    	jmp	short sblff_1
   963                                  
   964                                  ;-----------------------------------------------------------------------------
   965                                  
   966                                  ; entry ds:ax points to last byte in file
   967                                  ; cx = target size
   968                                  ; note: must do byte size fill
   969                                  ; destroys bx, cx
   970                                  
   971                                  sb_padfill:
   972                                  	; 24/11/2024
   973                                  	;   di = offset (to be filled with ZEROs)
   974                                  	;   es = ds = cs
   975                                  	;   ax = di = number of bytes loaded
   976                                  	;   cx = buffer size (> loaded bytes)
   977 0000049F 29C1                    	sub	cx, ax
   978 000004A1 31C0                    	xor	ax, ax
   979 000004A3 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
   980 000004A8 7702                    	ja	short padfill@
   981 000004AA B080                    	mov	al, 80h
   982                                  padfill@:
   983 000004AC F3AA                    	rep	stosb
   984 000004AE C3                      	retn
   985                                  
   986                                  ;=============================================================================
   987                                  ; AC97 procedures - load and convert sound data
   988                                  ;=============================================================================
   989                                  
   990                                  	; 08/02/2025 (*) (Wave scope/graphics synchronization)
   991                                  	; 07/02/2025
   992                                  	; 04/02/2025 - cgaplay.asm
   993                                  
   994                                  ;-----------------------------------------------------------------------------
   995                                  ; 07/12/2024
   996                                  ;-----------------------------------------------------------------------------
   997                                  
   998                                  ; /////
   999                                  	; 08/02/2025 (*)
  1000                                  	; 30/05/2024 (ich_wav4.asm, 19/05/2024)
  1001                                  loadFromFile:
  1002                                  	; 07/11/2023
  1003 000004AF F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1004                                  					; last of the file?
  1005 000004B4 7402                    	jz	short lff_0		; no
  1006 000004B6 F9                      	stc
  1007 000004B7 C3                      	retn
  1008                                  
  1009                                  lff_0:
  1010                                  	; 08/11/2023
  1011 000004B8 89C5                    	mov	bp, ax ; save buffer segment
  1012                                  
  1013                                  	; 17/11/2024
  1014 000004BA 8B1E[DF68]              	mov	bx, [FileHandle]
  1015                                  
  1016                                  	; 17/11/2024
  1017 000004BE 8B0E[B876]              	mov	cx, [loadsize]
  1018 000004C2 31FF                    	xor	di, di ; 0
  1019                                  
  1020                                  	;mov	cl, [fbs_shift]
  1021                                  	;and	cl, cl
  1022                                  	;jz	short lff_1 ; stereo, 16 bit
  1023                                  	; 17/11/2024
  1024 000004C4 803E[9C6C]00            	cmp	byte [fbs_shift], 0
  1025 000004C9 7653                    	jna	short lff_1 ; stereo, 16 bit
  1026                                  
  1027                                  	;mov	di, BUFFERSIZE - 1 ; 65535
  1028                                  
  1029                                  	;; fbs_shift =
  1030                                  	;;	2 for mono and 8 bit sample (multiplier = 4)
  1031                                  	;;	1 for mono or 8 bit sample (multiplier = 2)
  1032                                  	;shr	di, cl
  1033                                  	;inc	di ; 16384 for 8 bit and mono
  1034                                  	;	   ; 32768 for 8 bit or mono
  1035                                  	
  1036                                  	; 17/11/2024
  1037                                  	;mov	cx, [loadsize] ; 16380 or 32760
  1038                                  
  1039                                  	;mov	ax, cs
  1040 000004CB BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  1041                                  
  1042                                  	; 17/02/2017 (stereo/mono, 8bit/16bit corrections)
  1043                                  	; load file into memory
  1044                                  	;mov	cx, di ; 17/11/2024
  1045                                  	;mov	bx, [FileHandle] ; 17/11/2024
  1046                                  	;mov    ds, ax
  1047 000004CE B43F                           	mov	ah, 3Fh
  1048 000004D0 CD21                    	int	21h
  1049                                  
  1050                                  	;mov	bx, cs
  1051                                  	;mov	ds, bx
  1052                                  	; 17/11/2024
  1053                                  	;push	cs
  1054                                  	;pop	ds
  1055                                  
  1056 000004D2 7268                    	jc	lff_4 ; error !
  1057                                  
  1058                                  	; 14/11/2024
  1059 000004D4 A3[BE76]                	mov	[count], ax
  1060                                  
  1061                                  	; 17/11/2024
  1062                                  	; 08/11/2023
  1063                                  	;xor	dx, dx ; 0
  1064                                  
  1065 000004D7 21C0                    	and	ax, ax
  1066 000004D9 7458                    	jz	short lff_3
  1067                                  
  1068 000004DB 8A1E[9C6C]              	mov	bl, [fbs_shift]
  1069                                  
  1070 000004DF 06                      	push	es
  1071                                  	;mov	di, dx ; 0 ; [fbs_off]
  1072                                  	; 17/11/2024
  1073                                  	; di = 0
  1074                                  	;mov	bp, [fbs_seg] ; buffer segment
  1075 000004E0 8EC5                    	mov	es, bp
  1076 000004E2 BE[D07A]                	mov	si, temp_buffer ; temporary buffer address
  1077 000004E5 89C1                    	mov	cx, ax ; byte count
  1078 000004E7 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8 ; bits per sample (8 or 16)
  1079 000004EC 751B                    	jne	short lff_7 ; 16 bit samples
  1080                                  	; 8 bit samples
  1081 000004EE FECB                    	dec	bl  ; shift count, 1 = stereo, 2 = mono
  1082 000004F0 740C                    	jz	short lff_6 ; 8 bit, stereo
  1083                                  lff_5:
  1084                                  	; mono & 8 bit
  1085 000004F2 AC                      	lodsb
  1086 000004F3 2C80                    	sub	al, 80h ; 08/11/2023
  1087 000004F5 C1E008                  	shl	ax, 8 ; convert 8 bit sample to 16 bit sample
  1088 000004F8 AB                      	stosw	; left channel
  1089 000004F9 AB                      	stosw	; right channel
  1090 000004FA E2F6                    	loop	lff_5
  1091 000004FC EB12                    	jmp	short lff_9
  1092                                  lff_6:
  1093                                  	; stereo & 8 bit
  1094 000004FE AC                      	lodsb
  1095 000004FF 2C80                    	sub	al, 80h ; 08/11/2023
  1096 00000501 C1E008                  	shl	ax, 8 ; convert 8 bit sample to 16 bit sample
  1097 00000504 AB                      	stosw
  1098 00000505 E2F7                    	loop	lff_6
  1099 00000507 EB07                    	jmp	short lff_9
  1100                                  lff_7:
  1101 00000509 D1E9                    	shr	cx, 1 ; word count
  1102                                  lff_8:
  1103 0000050B AD                      	lodsw
  1104 0000050C AB                      	stosw	; left channel
  1105 0000050D AB                      	stosw	; right channel
  1106 0000050E E2FB                    	loop	lff_8
  1107                                  lff_9:
  1108 00000510 07                      	pop	es
  1109                                  	
  1110                                  	;or	di, di
  1111                                  	;jz	short endLFF ; 64KB ok 
  1112                                  	;mov	ax, di ; [fbs_off]
  1113                                  	;dec	ax
  1114                                  	; 17/11/2024
  1115 00000511 89F8                    	mov	ax, di 
  1116                                  	;cmp	ax, BUFFERSIZE ; 65520
  1117                                  	;jnb	short endLFF
  1118                                  
  1119                                  	;;mov	cx, BUFFERSIZE - 1 ; 65535
  1120                                  	; 17/11/2024
  1121                                  	;mov	cx, BUFFERSIZE
  1122                                  	; 08/02/2025 (*)
  1123 00000513 8B0E[BA76]              	mov	cx, [buffersize] ; words
  1124 00000517 D1E1                    	shl	cx, 1 ; bytes
  1125                                  	; 17/11/2024
  1126                                  	; ax = di
  1127 00000519 39C8                    	cmp	ax, cx
  1128                                  	;jnb	short endLFF
  1129                                  	;jmp	short lff_3
  1130 0000051B 7216                    	jb	short lff_3
  1131 0000051D C3                      	retn
  1132                                  	
  1133                                  lff_1:  
  1134                                  	;mov	bp, ax ; save buffer segment
  1135 0000051E 31D2                    	xor	dx, dx
  1136                                  	; load file into memory
  1137                                          ;mov	cx, (BUFFERSIZE / 2)	; 32k chunk
  1138                                  	
  1139                                  	; 17/11/2024
  1140                                  	;mov	cx, [buffersize] ; BUFFERSIZE / 2
  1141                                  	; 17/11/2024 (*)
  1142                                  	; cx = [loadsize] = 2*[buffersize]
  1143                                  
  1144                                  	;mov	bx, [FileHandle] ; 17/11/2024
  1145 00000520 8ED8                    	mov     ds, ax ; mov ds, bp
  1146 00000522 B43F                           	mov	ah, 3Fh
  1147 00000524 CD21                    	int	21h
  1148                                  
  1149                                  	;mov	di, cs
  1150                                  	;mov	ds, di
  1151                                  	; 17/11/2024
  1152 00000526 0E                      	push	cs
  1153 00000527 1F                      	pop	ds
  1154                                  
  1155                                  	; 07/11/2023
  1156 00000528 7212                    	jc	short lff_4 ; error !
  1157                                  
  1158                                  	; 14/11/2024
  1159 0000052A A3[BE76]                	mov	[count], ax
  1160                                  	; 17/11/2024
  1161                                  	; di = 0
  1162                                  
  1163 0000052D 39C8                    	cmp	ax, cx
  1164 0000052F 740A                    	je	short endLFF
  1165                                  	; 17/11/2024
  1166                                  	; di = 0
  1167 00000531 89C7                    	mov	di, ax
  1168                                  lff_3:
  1169 00000533 E80A00                  	call    padfill			; blank pad the remainder
  1170                                          ;clc				; don't exit with CY yet.
  1171 00000536 800E[9D6C]01                    or	byte [flags], ENDOFFILE	; end of file flag
  1172                                  endLFF:
  1173 0000053B C3                              retn
  1174                                  lff_4:
  1175 0000053C 31C0                    	xor	ax, ax
  1176 0000053E EBF3                    	jmp	short lff_3
  1177                                  
  1178                                  ;-----------------------------------------------------------------------------
  1179                                  
  1180                                  ; entry ds:ax points to last byte in file
  1181                                  ; cx = target size
  1182                                  ; note: must do byte size fill
  1183                                  ; destroys bx, cx
  1184                                  
  1185                                  padfill:
  1186                                  	; 14/12/2024
  1187                                  	; 17/11/2024
  1188                                  	;   di = offset (to be filled with ZEROs)
  1189                                  	;   bp = buffer segment
  1190                                  	;   ax = di = number of bytes loaded
  1191                                  	;   cx = buffer size (> loaded bytes)
  1192                                  	; 07/11/2023
  1193                                  	; 06/11/2023
  1194                                  	; 17/02/2017
  1195 00000540 06                      	push	es
  1196                                          ;push	di
  1197                                  	;mov	di, [fbs_seg]
  1198                                  	;mov	es, di
  1199 00000541 8EC5                            mov	es, bp
  1200 00000543 29C1                    	sub	cx, ax
  1201                                  	; 08/11/2023
  1202                                  	;mov	di, ax ; (wrong)
  1203                                  	; 17/11/2024
  1204                                  	;mov	di, dx ; buffer offset
  1205                                  	;add	di, ax
  1206                                  	; 07/11/2023
  1207                                  	;add	di, [fbs_off]
  1208                                   	; 25/11/2024
  1209 00000545 31C0                    	xor	ax, ax
  1210                                  	; 14/12/2024
  1211 00000547 F3AA                    	rep	stosb
  1212                                  	;mov	[fbs_off], di
  1213                                  	;pop	di
  1214 00000549 07                              pop	es
  1215 0000054A C3                      	retn
  1216                                  
  1217                                  ; /////
  1218                                  
  1219                                  ;-----------------------------------------------------------------------------
  1220                                  ; interpolation procedures
  1221                                  ;-----------------------------------------------------------------------------
  1222                                  
  1223                                  ; 07/02/2025
  1224                                  ; 04/02/2025 - cgaplay.asm
  1225                                  ; --------------------------------------------------------
  1226                                  ; 02/02/2025 - playwav8.asm - ac97play.asm - cgaplay.asm 
  1227                                  ; 01/01/2025 - cgaplay.asm
  1228                                  ; 18/12/2024 - ac97play.asm
  1229                                  ; ----------
  1230                                  ; 30/05/2024 - playwav6.asm
  1231                                  ; 18/11/2023 - ich_wav3.asm & ich_wav4.asm
  1232                                  ; 15/11/2023 - PLAYWAV5.COM, ich_wav5.asm
  1233                                  ; 14/11/2023
  1234                                  ; 13/11/2023 - Erdogan Tan - (VRA, sample rate conversion)
  1235                                  ; --------------------------------------------------------
  1236                                  
  1237                                  ;;Note:	At the end of every buffer load,
  1238                                  ;;	during buffer switch/swap, there will be discontinuity
  1239                                  ;;	between the last converted sample and the 1st sample
  1240                                  ;;	of the next buffer.
  1241                                  ;;	(like as a dot noises vaguely between normal sound samples)
  1242                                  ;;	-To avoid this defect, the 1st sample of
  1243                                  ;;	the next buffer may be read from the wav file but
  1244                                  ;;	the file pointer would need to be set to 1 sample back
  1245                                  ;;	again via seek system call. Time comsumption problem! -
  1246                                  ;;
  1247                                  ;;	Erdogan Tan - 15/11/2023
  1248                                  ;;
  1249                                  ;;	((If entire wav data would be loaded at once.. conversion
  1250                                  ;;	defect/noise would disappear.. but for DOS, to keep
  1251                                  ;;	64KB buffer limit is important also it is important
  1252                                  ;;	for running under 1MB barrier without HIMEM.SYS or DPMI.
  1253                                  ;;	I have tested this program by using 2-30MB wav files.))
  1254                                  ;;
  1255                                  ;;	Test Computer:	ASUS desktop/mainboard, M2N4-SLI, 2010.
  1256                                  ;;			AMD Athlon 64 X2 2200 MHZ CPU.
  1257                                  ;;		       	NFORCE4 (CK804) AC97 audio hardware.
  1258                                  ;;			Realtek ALC850 codec.
  1259                                  ;;		       	Retro DOS v4.2 (MSDOS 6.22) operating system.
  1260                                  
  1261                                  ;-----------------------------------------------------------------------------
  1262                                  ;-----------------------------------------------------------------------------
  1263                                  
  1264                                  load_8khz_mono_8_bit:
  1265                                  	; 02/02/2025
  1266                                  	; 15/11/2023
  1267                                  	; 14/11/2023
  1268                                  	; 13/11/2023
  1269 0000054B F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1270                                  					; last of the file?
  1271 00000550 7402                    	jz	short lff8m_0		; no
  1272 00000552 F9                      	stc
  1273 00000553 C3                      	retn
  1274                                  
  1275                                  lff8m_0:
  1276 00000554 8EC0                    	mov	es, ax ; buffer segment
  1277 00000556 31FF                    	xor	di, di
  1278 00000558 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  1279                                  	; ds = cs
  1280                                  
  1281                                  	; load file into memory
  1282 0000055B 8B0E[B876]                      mov	cx, [loadsize]
  1283 0000055F 8B1E[DF68]              	mov	bx, [FileHandle]
  1284 00000563 B43F                           	mov	ah, 3Fh
  1285 00000565 CD21                    	int	21h
  1286                                  	;jc	short lff8m_5 ; error !
  1287                                  	; 14/11/2023
  1288 00000567 7303                    	jnc	short lff8m_6
  1289 00000569 E98E00                  	jmp	lff8m_5
  1290                                  
  1291                                  lff8m_6:
  1292                                  	; 14/11/2024
  1293 0000056C A3[BE76]                	mov	[count], ax
  1294                                  
  1295 0000056F 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  1296 00000571 21C0                    	and	ax, ax
  1297                                  	;jz	short lff8m_3
  1298                                  	; 15/11/2023
  1299 00000573 747E                    	jz	short lff8_eof
  1300                                  
  1301 00000575 89C1                    	mov	cx, ax	; byte count
  1302                                  lff8m_1:
  1303 00000577 AC                      	lodsb
  1304 00000578 A2[B817]                	mov	[previous_val], al
  1305 0000057B 2C80                    	sub	al, 80h
  1306 0000057D C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1307 00000580 AB                      	stosw		; original sample (left channel)
  1308 00000581 AB                      	stosw		; original sample (right channel)
  1309                                  	;xor	ax, ax
  1310                                  	; 02/02/2025
  1311 00000582 8A04                    	mov	al, [si]
  1312 00000584 49                      	dec	cx
  1313 00000585 7502                    	jnz	short lff8m_2
  1314                                  	; 14/11/2023
  1315 00000587 B080                    	mov	al, 80h
  1316                                  lff8m_2:
  1317                                  	;mov	[next_val], ax
  1318 00000589 88C7                    	mov	bh, al	; [next_val]
  1319 0000058B 8A26[B817]              	mov	ah, [previous_val]
  1320 0000058F 00E0                    	add	al, ah	; [previous_val]
  1321 00000591 D0D8                    	rcr	al, 1
  1322 00000593 88C2                    	mov	dl, al	; this is interpolated middle (3th) sample
  1323 00000595 00E0                    	add	al, ah	; [previous_val]
  1324 00000597 D0D8                    	rcr	al, 1	
  1325 00000599 88C3                    	mov	bl, al 	; this is temporary interpolation value
  1326 0000059B 00E0                    	add	al, ah	; [previous_val]
  1327 0000059D D0D8                    	rcr	al, 1
  1328 0000059F 2C80                    	sub	al, 80h
  1329 000005A1 C1E008                  	shl	ax, 8
  1330 000005A4 AB                      	stosw		; this is 1st interpolated sample (L)
  1331 000005A5 AB                      	stosw		; this is 1st interpolated sample (R)
  1332 000005A6 88D8                    	mov	al, bl
  1333 000005A8 00D0                    	add	al, dl
  1334 000005AA D0D8                    	rcr	al, 1
  1335 000005AC 2C80                    	sub	al, 80h
  1336 000005AE C1E008                  	shl	ax, 8
  1337 000005B1 AB                      	stosw		; this is 2nd interpolated sample (L)
  1338 000005B2 AB                      	stosw		; this is 2nd interpolated sample (R)
  1339 000005B3 88D0                    	mov	al, dl
  1340 000005B5 2C80                    	sub	al, 80h
  1341 000005B7 C1E008                  	shl	ax, 8
  1342 000005BA AB                      	stosw		; this is middle (3th) interpolated sample (L)
  1343 000005BB AB                      	stosw		; this is middle (3th) interpolated sample (R)
  1344                                  	;mov	al, [next_val]
  1345 000005BC 88F8                    	mov	al, bh
  1346 000005BE 00D0                    	add	al, dl
  1347 000005C0 D0D8                    	rcr	al, 1
  1348 000005C2 88C3                    	mov	bl, al	; this is temporary interpolation value
  1349 000005C4 00D0                    	add	al, dl
  1350 000005C6 D0D8                    	rcr	al, 1
  1351 000005C8 2C80                    	sub	al, 80h
  1352 000005CA C1E008                  	shl	ax, 8
  1353 000005CD AB                      	stosw		; this is 4th interpolated sample (L)
  1354 000005CE AB                      	stosw		; this is 4th interpolated sample (R)
  1355                                  	;mov	al, [next_val]
  1356 000005CF 88F8                    	mov	al, bh
  1357 000005D1 00D8                    	add	al, bl
  1358 000005D3 D0D8                    	rcr	al, 1
  1359 000005D5 2C80                    	sub	al, 80h
  1360 000005D7 C1E008                  	shl	ax, 8
  1361 000005DA AB                      	stosw		; this is 5th interpolated sample (L)
  1362 000005DB AB                      	stosw		; this is 5th interpolated sample (R)
  1363                                  	; 8 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1364 000005DC 09C9                    	or	cx, cx
  1365 000005DE 7597                    	jnz	short lff8m_1
  1366                                  
  1367                                  	; --------------
  1368                                  
  1369                                  lff8s_3:
  1370                                  lff8m_3:
  1371                                  lff8s2_3:
  1372                                  lff8m2_3:
  1373                                  lff16s_3:
  1374                                  lff16m_3:
  1375                                  lff16s2_3:
  1376                                  lff16m2_3:
  1377                                  lff24_3:
  1378                                  lff32_3:
  1379                                  lff44_3:
  1380                                  lff22_3:
  1381                                  lff11_3:
  1382                                  lff12_3:	; 02/02/2025
  1383 000005E0 8B0E[BA76]              	mov	cx, [buffersize] ; 16 bit (48 kHZ, stereo) sample size
  1384 000005E4 D1E1                    	shl	cx, 1	; byte count
  1385 000005E6 29F9                    	sub	cx, di
  1386 000005E8 7606                    	jna	short lff8m_4
  1387                                  	;inc	cx
  1388 000005EA D1E9                    	shr	cx, 1
  1389 000005EC 31C0                    	xor	ax, ax	; fill (remain part of) buffer with zeros
  1390 000005EE F3AB                    	rep	stosw
  1391                                  lff8m_4:
  1392 000005F0 0E                      	push	cs
  1393 000005F1 07                      	pop	es
  1394 000005F2 C3                      	retn
  1395                                  
  1396                                  lff8_eof:
  1397                                  lff16_eof:
  1398                                  lff24_eof:
  1399                                  lff32_eof:
  1400                                  lff44_eof:
  1401                                  lff22_eof:
  1402                                  lff11_eof:
  1403                                  lff12_eof:	; 02/02/2025
  1404                                  	; 15/11/2023
  1405 000005F3 C606[9D6C]01            	mov	byte [flags], ENDOFFILE
  1406 000005F8 EBE6                    	jmp	short lff8m_3
  1407                                  
  1408                                  lff8s_5:
  1409                                  lff8m_5:
  1410                                  lff8s2_5:
  1411                                  lff8m2_5:
  1412                                  lff16s_5:
  1413                                  lff16m_5:
  1414                                  lff16s2_5:
  1415                                  lff16m2_5:
  1416                                  lff24_5:
  1417                                  lff32_5:
  1418                                  lff44_5:
  1419                                  lff22_5:
  1420                                  lff11_5:
  1421                                  lff12_5:	; 02/02/2025
  1422 000005FA B021                    	mov	al, '!'  ; error
  1423 000005FC E862FC                  	call	tL0
  1424                                  	
  1425                                  	;jmp	short lff8m_3
  1426                                  	; 15/11/2023
  1427 000005FF EBF2                    	jmp	lff8_eof
  1428                                  
  1429                                  ;-----------------------------------------------------------------------------
  1430                                  
  1431                                  load_8khz_stereo_8_bit:
  1432                                  	; 02/02/2025
  1433                                  	; 15/11/2023
  1434                                  	; 14/11/2023
  1435                                  	; 13/11/2023
  1436 00000601 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1437                                  					; last of the file?
  1438 00000606 7402                    	jz	short lff8s_0		; no
  1439 00000608 F9                      	stc
  1440 00000609 C3                      	retn
  1441                                  
  1442                                  lff8s_0:
  1443 0000060A 8EC0                    	mov	es, ax ; buffer segment
  1444 0000060C 31FF                    	xor	di, di
  1445 0000060E BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  1446                                  	; ds = cs
  1447                                  
  1448                                  	; load file into memory
  1449 00000611 8B0E[B876]                      mov	cx, [loadsize]
  1450 00000615 8B1E[DF68]              	mov	bx, [FileHandle]
  1451 00000619 B43F                           	mov	ah, 3Fh
  1452 0000061B CD21                    	int	21h
  1453 0000061D 72DB                    	jc	short lff8s_5 ; error !
  1454                                  
  1455                                  	; 14/11/2024
  1456 0000061F A3[BE76]                	mov	[count], ax
  1457                                  
  1458 00000622 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  1459                                  	
  1460 00000624 D1E8                    	shr	ax, 1
  1461                                  	;;and	ax, ax
  1462                                  	;jz	short lff8s_3
  1463                                  	; 15/11/2023
  1464 00000626 74CB                    	jz	short lff8_eof
  1465                                  
  1466 00000628 89C1                    	mov	cx, ax	; word count
  1467                                  lff8s_1:
  1468 0000062A AC                      	lodsb
  1469 0000062B A2[B817]                	mov	[previous_val_l], al
  1470 0000062E 2C80                    	sub	al, 80h
  1471 00000630 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1472 00000633 AB                      	stosw		; original sample (L)
  1473 00000634 AC                      	lodsb
  1474 00000635 A2[BA17]                	mov	[previous_val_r], al
  1475 00000638 2C80                    	sub	al, 80h
  1476 0000063A C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1477 0000063D AB                      	stosw		; original sample (R)
  1478                                  
  1479                                  	;xor	ax, ax
  1480                                  	; 02/02/2025
  1481 0000063E 8B04                    	mov	ax, [si]
  1482 00000640 49                      	dec	cx
  1483 00000641 7503                    	jnz	short lff8s_2
  1484                                  		; convert 8 bit sample to 16 bit sample
  1485                                  	; 14/11/2023
  1486 00000643 B88080                  	mov	ax, 8080h
  1487                                  lff8s_2:
  1488 00000646 A2[BC17]                	mov	[next_val_l], al
  1489 00000649 8826[BE17]              	mov	[next_val_r], ah
  1490 0000064D 8A26[B817]              	mov	ah, [previous_val_l]
  1491 00000651 00E0                    	add	al, ah
  1492 00000653 D0D8                    	rcr	al, 1
  1493 00000655 88C2                    	mov	dl, al	; this is interpolated middle (3th) sample (L)
  1494 00000657 00E0                    	add	al, ah
  1495 00000659 D0D8                    	rcr	al, 1	
  1496 0000065B 88C3                    	mov	bl, al	; this is temporary interpolation value (L)
  1497 0000065D 00E0                    	add	al, ah
  1498 0000065F D0D8                    	rcr	al, 1
  1499 00000661 2C80                    	sub	al, 80h
  1500 00000663 C1E008                  	shl	ax, 8
  1501 00000666 AB                      	stosw		; this is 1st interpolated sample (L)
  1502 00000667 A0[BE17]                	mov	al, [next_val_r]
  1503 0000066A 8A26[BA17]              	mov	ah, [previous_val_r]
  1504 0000066E 00E0                    	add	al, ah
  1505 00000670 D0D8                    	rcr	al, 1
  1506 00000672 88C6                    	mov	dh, al	; this is interpolated middle (3th) sample (R)
  1507 00000674 00E0                    	add	al, ah
  1508 00000676 D0D8                    	rcr	al, 1
  1509 00000678 88C7                    	mov	bh, al	; this is temporary interpolation value (R)
  1510 0000067A 00E0                    	add	al, ah
  1511 0000067C D0D8                    	rcr	al, 1
  1512 0000067E 2C80                    	sub	al, 80h
  1513 00000680 C1E008                  	shl	ax, 8
  1514 00000683 AB                      	stosw		; this is 1st interpolated sample (R)
  1515 00000684 88D8                    	mov	al, bl
  1516 00000686 00D0                    	add	al, dl
  1517 00000688 D0D8                    	rcr	al, 1
  1518 0000068A 2C80                    	sub	al, 80h
  1519 0000068C C1E008                  	shl	ax, 8
  1520 0000068F AB                      	stosw		; this is 2nd interpolated sample (L)
  1521 00000690 88F8                    	mov	al, bh
  1522 00000692 00F0                    	add	al, dh
  1523 00000694 D0D8                    	rcr	al, 1
  1524 00000696 2C80                    	sub	al, 80h
  1525 00000698 C1E008                  	shl	ax, 8
  1526 0000069B AB                      	stosw 		; this is 2nd interpolated sample (R)
  1527 0000069C 88D0                    	mov	al, dl
  1528 0000069E 2C80                    	sub	al, 80h
  1529 000006A0 C1E008                  	shl	ax, 8
  1530 000006A3 AB                      	stosw		; this is middle (3th) interpolated sample (L)
  1531 000006A4 88F0                    	mov	al, dh
  1532 000006A6 2C80                    	sub	al, 80h
  1533 000006A8 C1E008                  	shl	ax, 8
  1534 000006AB AB                      	stosw		; this is middle (3th) interpolated sample (R)
  1535 000006AC A0[BC17]                	mov	al, [next_val_l]
  1536 000006AF 00D0                    	add	al, dl
  1537 000006B1 D0D8                    	rcr	al, 1
  1538 000006B3 88C3                    	mov	bl, al	; this is temporary interpolation value (L)
  1539 000006B5 00D0                    	add	al, dl
  1540 000006B7 D0D8                    	rcr	al, 1
  1541 000006B9 2C80                    	sub	al, 80h
  1542 000006BB C1E008                  	shl	ax, 8
  1543 000006BE AB                      	stosw		; this is 4th interpolated sample (L)
  1544 000006BF A0[BE17]                	mov	al, [next_val_r]
  1545 000006C2 00F0                    	add	al, dh
  1546 000006C4 D0D8                    	rcr	al, 1
  1547 000006C6 88C7                    	mov	bh, al	; this is temporary interpolation value (R)
  1548 000006C8 00F0                    	add	al, dh
  1549 000006CA D0D8                    	rcr	al, 1
  1550 000006CC 2C80                    	sub	al, 80h
  1551 000006CE C1E008                  	shl	ax, 8
  1552 000006D1 AB                      	stosw		; this is 4th interpolated sample (R)
  1553 000006D2 A0[BC17]                	mov	al, [next_val_l]
  1554 000006D5 00D8                    	add	al, bl
  1555 000006D7 D0D8                    	rcr	al, 1
  1556 000006D9 2C80                    	sub	al, 80h
  1557 000006DB C1E008                  	shl	ax, 8
  1558 000006DE AB                      	stosw		; this is 5th interpolated sample (L)
  1559 000006DF A0[BE17]                	mov	al, [next_val_r]
  1560 000006E2 00F8                    	add	al, bh
  1561 000006E4 D0D8                    	rcr	al, 1
  1562 000006E6 2C80                    	sub	al, 80h
  1563 000006E8 C1E008                  	shl	ax, 8
  1564 000006EB AB                      	stosw		; this is 5th interpolated sample (R)
  1565                                  	; 8 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  1566 000006EC E303                    	jcxz	lff8s_6
  1567 000006EE E939FF                  	jmp	lff8s_1
  1568                                  lff8s_6:
  1569 000006F1 E9ECFE                  	jmp	lff8s_3
  1570                                  
  1571                                  ;-----------------------------------------------------------------------------
  1572                                  
  1573                                  load_8khz_mono_16_bit:
  1574                                  	; 02/02/2025
  1575                                  	; 13/11/2023
  1576 000006F4 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1577                                  					; last of the file?
  1578 000006F9 7402                    	jz	short lff8m2_0		; no
  1579 000006FB F9                      	stc
  1580 000006FC C3                      	retn
  1581                                  
  1582                                  lff8m2_0:
  1583 000006FD 8EC0                    	mov	es, ax ; buffer segment
  1584 000006FF 31FF                    	xor	di, di
  1585 00000701 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  1586                                  	; ds = cs
  1587                                  
  1588                                  	; load file into memory
  1589 00000704 8B0E[B876]                      mov	cx, [loadsize]
  1590 00000708 8B1E[DF68]              	mov	bx, [FileHandle]
  1591 0000070C B43F                           	mov	ah, 3Fh
  1592 0000070E CD21                    	int	21h
  1593 00000710 7273                    	jc	short lff8m2_7 ; error !
  1594                                  
  1595                                  	; 14/11/2024
  1596 00000712 A3[BE76]                	mov	[count], ax
  1597                                  
  1598 00000715 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  1599                                  	
  1600 00000717 D1E8                    	shr	ax, 1
  1601                                  	;and	ax, ax
  1602 00000719 7503                    	jnz	short lff8m2_8
  1603                                  	;jmp	lff8m2_3
  1604                                  	; 15/11/2023
  1605 0000071B E9D5FE                  	jmp	lff8_eof
  1606                                  
  1607                                  lff8m2_8:
  1608 0000071E 89C1                    	mov	cx, ax	; word count
  1609                                  lff8m2_1:
  1610 00000720 AD                      	lodsw
  1611 00000721 AB                      	stosw		; original sample (left channel)
  1612 00000722 AB                      	stosw		; original sample (right channel)
  1613 00000723 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1614 00000726 A3[B817]                	mov	[previous_val], ax
  1615                                  	; 02/02/2025
  1616 00000729 8B04                    	mov	ax, [si]
  1617 0000072B 49                      	dec	cx
  1618 0000072C 7502                    	jnz	short lff8m2_2
  1619 0000072E 31C0                    	xor	ax, ax
  1620                                  lff8m2_2:
  1621 00000730 80C480                  	add	ah, 80h ; convert sound level to 0-65535 format
  1622 00000733 89C5                    	mov	bp, ax	; [next_val]
  1623 00000735 0306[B817]              	add	ax, [previous_val]
  1624 00000739 D1D8                    	rcr	ax, 1
  1625 0000073B 89C2                    	mov	dx, ax	; this is interpolated middle (3th) sample
  1626 0000073D 0306[B817]              	add	ax, [previous_val]
  1627 00000741 D1D8                    	rcr	ax, 1	; this is temporary interpolation value
  1628 00000743 89C3                    	mov	bx, ax 		
  1629 00000745 0306[B817]              	add	ax, [previous_val]
  1630 00000749 D1D8                    	rcr	ax, 1
  1631 0000074B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1632 0000074E AB                      	stosw		; this is 1st interpolated sample (L)
  1633 0000074F AB                      	stosw		; this is 1st interpolated sample (R)
  1634 00000750 89D8                    	mov	ax, bx
  1635 00000752 01D0                    	add	ax, dx
  1636 00000754 D1D8                    	rcr	ax, 1
  1637 00000756 80EC80                  	sub	ah, 80h
  1638 00000759 AB                      	stosw		; this is 2nd interpolated sample (L)
  1639 0000075A AB                      	stosw		; this is 2nd interpolated sample (R)
  1640 0000075B 89D0                    	mov	ax, dx
  1641 0000075D 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1642 00000760 AB                      	stosw		; this is middle (3th) interpolated sample (L)
  1643 00000761 AB                      	stosw		; this is middle (3th) interpolated sample (R)
  1644 00000762 89E8                    	mov	ax, bp
  1645 00000764 01D0                    	add	ax, dx
  1646 00000766 D1D8                    	rcr	ax, 1
  1647 00000768 89C3                    	mov	bx, ax	; this is temporary interpolation value
  1648 0000076A 01D0                    	add	ax, dx
  1649 0000076C D1D8                    	rcr	ax, 1
  1650 0000076E 80EC80                  	sub	ah, 80h
  1651 00000771 AB                      	stosw		; this is 4th interpolated sample (L)
  1652 00000772 AB                      	stosw		; this is 4th interpolated sample (R)
  1653 00000773 89E8                    	mov	ax, bp
  1654 00000775 01D8                    	add	ax, bx
  1655 00000777 D1D8                    	rcr	ax, 1
  1656 00000779 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1657 0000077C AB                      	stosw		; this is 5th interpolated sample (L)
  1658 0000077D AB                      	stosw		; this is 5th interpolated sample (R)
  1659                                  	; 8 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1660 0000077E 09C9                    	or	cx, cx
  1661 00000780 759E                    	jnz	short lff8m2_1
  1662 00000782 E95BFE                  	jmp	lff8m2_3
  1663                                  
  1664                                  lff8m2_7:
  1665                                  lff8s2_7:
  1666 00000785 E972FE                  	jmp	lff8m2_5  ; error
  1667                                  
  1668                                  ;-----------------------------------------------------------------------------
  1669                                  
  1670                                  load_8khz_stereo_16_bit:
  1671                                  	; 02/02/2025
  1672                                  	; 16/11/2023
  1673                                  	; 15/11/2023
  1674                                  	; 13/11/2023
  1675 00000788 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1676                                  					; last of the file?
  1677 0000078D 7402                    	jz	short lff8s2_0		; no
  1678 0000078F F9                      	stc
  1679 00000790 C3                      	retn
  1680                                  
  1681                                  lff8s2_0:
  1682 00000791 8EC0                    	mov	es, ax ; buffer segment
  1683 00000793 31FF                    	xor	di, di
  1684 00000795 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  1685                                  	; ds = cs
  1686                                  
  1687                                  	; load file into memory
  1688 00000798 8B0E[B876]                      mov	cx, [loadsize]
  1689 0000079C 8B1E[DF68]              	mov	bx, [FileHandle]
  1690 000007A0 B43F                           	mov	ah, 3Fh
  1691 000007A2 CD21                    	int	21h
  1692 000007A4 72DF                    	jc	short lff8s2_7 ; error !
  1693                                  
  1694                                  	; 14/11/2024
  1695 000007A6 A3[BE76]                	mov	[count], ax
  1696                                  
  1697 000007A9 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  1698                                  	
  1699 000007AB C1E802                  	shr	ax, 2	; 16/11/2023
  1700                                  	;and	ax, ax
  1701 000007AE 7503                    	jnz	short lff8s2_8
  1702                                  	;jmp	lff8s2_3
  1703                                  	; 15/11/2023
  1704 000007B0 E940FE                  	jmp	lff8_eof
  1705                                  
  1706                                  lff8s2_8:
  1707 000007B3 89C1                    	mov	cx, ax	; dword count
  1708                                  lff8s2_1:
  1709 000007B5 AD                      	lodsw
  1710 000007B6 AB                      	stosw		; original sample (L)
  1711                                  	; 15/11/2023
  1712 000007B7 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1713 000007BA A3[B817]                	mov	[previous_val_l], ax
  1714 000007BD AD                      	lodsw
  1715 000007BE AB                      	stosw		; original sample (R)
  1716 000007BF 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1717 000007C2 A3[BA17]                	mov	[previous_val_r], ax
  1718                                  	; 02/02/2025
  1719 000007C5 8B04                    	mov	ax, [si]
  1720 000007C7 8B5402                  	mov	dx, [si+2]
  1721                                  	; 16/11/2023
  1722 000007CA 49                      	dec	cx
  1723 000007CB 7504                    	jnz	short lff8s2_2
  1724 000007CD 31D2                    	xor	dx, dx
  1725 000007CF 31C0                    	xor	ax, ax
  1726                                  lff8s2_2:
  1727 000007D1 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1728 000007D4 A3[BC17]                	mov	[next_val_l], ax
  1729 000007D7 80C680                  	add	dh, 80h	; convert sound level to 0-65535 format
  1730 000007DA 8916[BE17]              	mov	[next_val_r], dx
  1731 000007DE 0306[B817]              	add	ax, [previous_val_l]
  1732 000007E2 D1D8                    	rcr	ax, 1
  1733 000007E4 89C2                    	mov	dx, ax	; this is interpolated middle (3th) sample (L)
  1734 000007E6 0306[B817]              	add	ax, [previous_val_l]
  1735 000007EA D1D8                    	rcr	ax, 1	
  1736 000007EC 89C3                    	mov	bx, ax 	; this is temporary interpolation value (L)
  1737 000007EE 0306[B817]              	add	ax, [previous_val_l]
  1738 000007F2 D1D8                    	rcr	ax, 1
  1739 000007F4 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1740 000007F7 AB                      	stosw		; this is 1st interpolated sample (L)
  1741 000007F8 A1[BE17]                	mov	ax, [next_val_r]
  1742 000007FB 0306[BA17]              	add	ax, [previous_val_r]
  1743 000007FF D1D8                    	rcr	ax, 1
  1744 00000801 89C5                    	mov	bp, ax	; this is interpolated middle (3th) sample (R)
  1745 00000803 0306[BA17]              	add	ax, [previous_val_r]
  1746 00000807 D1D8                    	rcr	ax, 1
  1747 00000809 50                      	push	ax ; *	; this is temporary interpolation value (R)
  1748 0000080A 0306[BA17]              	add	ax, [previous_val_r]
  1749 0000080E D1D8                    	rcr	ax, 1
  1750 00000810 80EC80                  	sub	ah, 80h
  1751 00000813 AB                      	stosw		; this is 1st interpolated sample (R)
  1752 00000814 89D8                    	mov	ax, bx
  1753 00000816 01D0                    	add	ax, dx
  1754 00000818 D1D8                    	rcr	ax, 1
  1755 0000081A 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1756 0000081D AB                      	stosw		; this is 2nd interpolated sample (L)
  1757 0000081E 58                      	pop	ax ; *
  1758 0000081F 01E8                    	add	ax, bp
  1759 00000821 D1D8                    	rcr	ax, 1
  1760 00000823 80EC80                  	sub	ah, 80h
  1761 00000826 AB                      	stosw 		; this is 2nd interpolated sample (R)
  1762 00000827 89D0                    	mov	ax, dx
  1763 00000829 80EC80                  	sub	ah, 80h
  1764 0000082C AB                      	stosw		; this is middle (3th) interpolated sample (L)
  1765 0000082D 89E8                    	mov	ax, bp
  1766 0000082F 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1767 00000832 AB                      	stosw		; this is middle (3th) interpolated sample (R)
  1768 00000833 A1[BC17]                	mov	ax, [next_val_l]
  1769 00000836 01D0                    	add	ax, dx
  1770 00000838 D1D8                    	rcr	ax, 1
  1771 0000083A 89C3                    	mov	bx, ax	; this is temporary interpolation value (L)
  1772 0000083C 01D0                    	add	ax, dx
  1773 0000083E D1D8                    	rcr	ax, 1
  1774 00000840 80EC80                  	sub	ah, 80h
  1775 00000843 AB                      	stosw		; this is 4th interpolated sample (L)
  1776 00000844 A1[BE17]                	mov	ax, [next_val_r]
  1777 00000847 01E8                    	add	ax, bp
  1778 00000849 D1D8                    	rcr	ax, 1
  1779 0000084B 50                      	push	ax ; ** ; this is temporary interpolation value (R)
  1780 0000084C 01E8                    	add	ax, bp
  1781 0000084E D1D8                    	rcr	ax, 1
  1782 00000850 80EC80                  	sub	ah, 80h
  1783 00000853 AB                      	stosw		; this is 4th interpolated sample (R)
  1784 00000854 A1[BC17]                	mov	ax, [next_val_l]
  1785 00000857 01D8                    	add	ax, bx
  1786 00000859 D1D8                    	rcr	ax, 1
  1787 0000085B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1788 0000085E AB                      	stosw		; this is 5th interpolated sample (L)
  1789 0000085F 58                      	pop	ax ; **
  1790 00000860 0306[BE17]              	add	ax, [next_val_r]
  1791 00000864 D1D8                    	rcr	ax, 1
  1792 00000866 80EC80                  	sub	ah, 80h
  1793 00000869 AB                      	stosw		; this is 5th interpolated sample (R)
  1794                                  	; 8 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  1795 0000086A E303                    	jcxz	lff8_s2_9
  1796 0000086C E946FF                  	jmp	lff8s2_1
  1797                                  lff8_s2_9:
  1798 0000086F E96EFD                  	jmp	lff8s2_3
  1799                                  
  1800                                  ;-----------------------------------------------------------------------------
  1801                                  ;-----------------------------------------------------------------------------
  1802                                  
  1803                                  load_16khz_mono_8_bit:
  1804                                  	; 02/02/2025
  1805                                  	; 14/11/2023
  1806                                  	; 13/11/2023
  1807 00000872 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1808                                  					; last of the file?
  1809 00000877 7402                    	jz	short lff16m_0		; no
  1810 00000879 F9                      	stc
  1811 0000087A C3                      	retn
  1812                                  
  1813                                  lff16m_0:
  1814 0000087B 8EC0                    	mov	es, ax ; buffer segment
  1815 0000087D 31FF                    	xor	di, di
  1816 0000087F BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  1817                                  	; ds = cs
  1818                                  
  1819                                  	; load file into memory
  1820 00000882 8B0E[B876]                      mov	cx, [loadsize]
  1821 00000886 8B1E[DF68]              	mov	bx, [FileHandle]
  1822 0000088A B43F                           	mov	ah, 3Fh
  1823 0000088C CD21                    	int	21h
  1824 0000088E 7246                    	jc	short lff16m_7 ; error !
  1825                                  
  1826                                  	; 14/11/2024
  1827 00000890 A3[BE76]                	mov	[count], ax
  1828                                  
  1829 00000893 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  1830                                  	
  1831 00000895 21C0                    	and	ax, ax
  1832 00000897 7503                    	jnz	short lff16m_8
  1833                                  	;jmp	lff16m_3
  1834                                  	; 15/11/2023
  1835 00000899 E957FD                  	jmp	lff16_eof
  1836                                  
  1837                                  lff16m_8:
  1838 0000089C 89C1                    	mov	cx, ax	; byte count
  1839                                  lff16m_1:
  1840 0000089E AC                      	lodsb
  1841                                  	;mov	[previous_val], al
  1842 0000089F 88C3                    	mov	bl, al
  1843 000008A1 2C80                    	sub	al, 80h
  1844 000008A3 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1845 000008A6 AB                      	stosw		; original sample (left channel)
  1846 000008A7 AB                      	stosw		; original sample (right channel)
  1847                                  	;xor	ax, ax
  1848                                  	; 02/02/2025
  1849 000008A8 8A04                    	mov	al, [si]
  1850 000008AA 49                      	dec	cx
  1851 000008AB 7502                    	jnz	short lff16m_2
  1852                                  	; 14/11/2023
  1853 000008AD B080                    	mov	al, 80h
  1854                                  lff16m_2:
  1855                                  	;mov	[next_val], al
  1856 000008AF 88C7                    	mov	bh, al
  1857                                  	;add	al, [previous_val]
  1858 000008B1 00D8                    	add	al, bl
  1859 000008B3 D0D8                    	rcr	al, 1
  1860 000008B5 88C2                    	mov	dl, al	; this is interpolated middle (temp) sample
  1861                                  	;add	al, [previous_val]
  1862 000008B7 00D8                    	add	al, bl
  1863 000008B9 D0D8                    	rcr	al, 1
  1864 000008BB 2C80                    	sub	al, 80h
  1865 000008BD C1E008                  	shl	ax, 8
  1866 000008C0 AB                      	stosw		; this is 1st interpolated sample (L)
  1867 000008C1 AB                      	stosw		; this is 1st interpolated sample (R)
  1868                                  	;mov	al, [next_val]
  1869 000008C2 88F8                    	mov	al, bh
  1870 000008C4 00D0                    	add	al, dl
  1871 000008C6 D0D8                    	rcr	al, 1
  1872 000008C8 2C80                    	sub	al, 80h
  1873 000008CA C1E008                  	shl	ax, 8
  1874 000008CD AB                      	stosw		; this is 2nd interpolated sample (L)
  1875 000008CE AB                      	stosw		; this is 2nd interpolated sample (R)
  1876                                  	
  1877                                  	; 16 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1878 000008CF 09C9                    	or	cx, cx
  1879 000008D1 75CB                    	jnz	short lff16m_1
  1880 000008D3 E90AFD                  	jmp	lff16m_3
  1881                                  
  1882                                  lff16m_7:
  1883                                  lff16s_7:
  1884 000008D6 E921FD                  	jmp	lff16m_5  ; error
  1885                                  
  1886                                  ;-----------------------------------------------------------------------------
  1887                                  
  1888                                  load_16khz_stereo_8_bit:
  1889                                  	; 02/02/2025
  1890                                  	; 14/11/2023
  1891                                  	; 13/11/2023
  1892 000008D9 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1893                                  					; last of the file?
  1894 000008DE 7402                    	jz	short lff16s_0		; no
  1895 000008E0 F9                      	stc
  1896 000008E1 C3                      	retn
  1897                                  
  1898                                  lff16s_0:
  1899 000008E2 8EC0                    	mov	es, ax ; buffer segment
  1900 000008E4 31FF                    	xor	di, di
  1901 000008E6 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  1902                                  	; ds = cs
  1903                                  
  1904                                  	; load file into memory
  1905 000008E9 8B0E[B876]                      mov	cx, [loadsize]
  1906 000008ED 8B1E[DF68]              	mov	bx, [FileHandle]
  1907 000008F1 B43F                           	mov	ah, 3Fh
  1908 000008F3 CD21                    	int	21h
  1909 000008F5 72DF                    	jc	short lff16s_7 ; error !
  1910                                  
  1911                                  	; 14/11/2024
  1912 000008F7 A3[BE76]                	mov	[count], ax
  1913                                  
  1914 000008FA 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  1915                                  	
  1916 000008FC D1E8                    	shr	ax, 1
  1917                                  	;and	ax, ax
  1918 000008FE 7503                    	jnz	short lff16s_8
  1919                                  	;jmp	lff16s_3
  1920                                  	; 15/11/2023
  1921 00000900 E9F0FC                  	jmp	lff16_eof
  1922                                  
  1923                                  lff16s_8:
  1924 00000903 89C1                    	mov	cx, ax	; word count
  1925                                  lff16s_1:
  1926 00000905 AC                      	lodsb
  1927 00000906 A2[B817]                	mov	[previous_val_l], al
  1928 00000909 2C80                    	sub	al, 80h
  1929 0000090B C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1930 0000090E AB                      	stosw		; original sample (L)
  1931 0000090F AC                      	lodsb
  1932 00000910 A2[BA17]                	mov	[previous_val_r], al
  1933 00000913 2C80                    	sub	al, 80h
  1934 00000915 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1935 00000918 AB                      	stosw		; original sample (R)
  1936                                  
  1937                                  	;xor	ax, ax
  1938                                  	; 02/02/2025
  1939 00000919 8B04                    	mov	ax, [si]
  1940 0000091B 49                      	dec	cx
  1941 0000091C 7503                    	jnz	short lff16s_2
  1942                                  		; convert 8 bit sample to 16 bit sample
  1943                                  	; 14/11/2023
  1944 0000091E B88080                  	mov	ax, 8080h
  1945                                  lff16s_2:
  1946                                  	;mov	[next_val_l], al
  1947                                  	;mov	[next_val_r], ah
  1948 00000921 89C3                    	mov	bx, ax
  1949 00000923 0206[B817]              	add	al, [previous_val_l]
  1950 00000927 D0D8                    	rcr	al, 1
  1951 00000929 88C2                    	mov	dl, al	; this is temporary interpolation value (L)
  1952 0000092B 0206[B817]              	add	al, [previous_val_l]
  1953 0000092F D0D8                    	rcr	al, 1
  1954 00000931 2C80                    	sub	al, 80h
  1955 00000933 C1E008                  	shl	ax, 8
  1956 00000936 AB                      	stosw		; this is 1st interpolated sample (L)
  1957 00000937 88F8                    	mov	al, bh	; [next_val_r]
  1958 00000939 0206[BA17]              	add	al, [previous_val_r]
  1959 0000093D D0D8                    	rcr	al, 1
  1960 0000093F 88C6                    	mov	dh, al	; this is temporary interpolation value (R)
  1961 00000941 0206[BA17]              	add	al, [previous_val_r]
  1962 00000945 D0D8                    	rcr	al, 1
  1963 00000947 2C80                    	sub	al, 80h
  1964 00000949 C1E008                  	shl	ax, 8
  1965 0000094C AB                      	stosw		; this is 1st interpolated sample (R)
  1966 0000094D 88D0                    	mov	al, dl
  1967 0000094F 00D8                    	add	al, bl	; [next_val_l]
  1968 00000951 D0D8                    	rcr	al, 1
  1969 00000953 2C80                    	sub	al, 80h
  1970 00000955 C1E008                  	shl	ax, 8
  1971 00000958 AB                      	stosw		; this is 2nd interpolated sample (L)
  1972 00000959 88F0                    	mov	al, dh
  1973 0000095B 00F8                    	add	al, bh	; [next_val_r]
  1974 0000095D D0D8                    	rcr	al, 1
  1975 0000095F 2C80                    	sub	al, 80h
  1976 00000961 C1E008                  	shl	ax, 8
  1977 00000964 AB                      	stosw 		; this is 2nd interpolated sample (R)
  1978                                  	
  1979                                  	; 16 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  1980 00000965 09C9                    	or	cx, cx
  1981 00000967 759C                    	jnz	short lff16s_1
  1982 00000969 E974FC                  	jmp	lff16s_3
  1983                                  
  1984                                  ;-----------------------------------------------------------------------------
  1985                                  
  1986                                  load_16khz_mono_16_bit:
  1987                                  	; 02/02/2025
  1988                                  	; 15/11/2023
  1989                                  	; 13/11/2023
  1990 0000096C F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  1991                                  					; last of the file?
  1992 00000971 7402                    	jz	short lff16m2_0		; no
  1993 00000973 F9                      	stc
  1994 00000974 C3                      	retn
  1995                                  
  1996                                  lff16m2_0:
  1997 00000975 8EC0                    	mov	es, ax ; buffer segment
  1998 00000977 31FF                    	xor	di, di
  1999 00000979 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2000                                  	; ds = cs
  2001                                  
  2002                                  	; load file into memory
  2003 0000097C 8B0E[B876]                      mov	cx, [loadsize]
  2004 00000980 8B1E[DF68]              	mov	bx, [FileHandle]
  2005 00000984 B43F                           	mov	ah, 3Fh
  2006 00000986 CD21                    	int	21h
  2007 00000988 7243                    	jc	short lff16m2_7 ; error !
  2008                                  
  2009                                  	; 14/11/2024
  2010 0000098A A3[BE76]                	mov	[count], ax
  2011                                  
  2012 0000098D 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2013                                  	
  2014 0000098F D1E8                    	shr	ax, 1
  2015                                  	;and	ax, ax
  2016 00000991 7503                    	jnz	short lff16m2_8
  2017                                  	;jmp	lff16m2_3
  2018                                  	; 15/11/2023
  2019 00000993 E95DFC                  	jmp	lff16_eof
  2020                                  
  2021                                  lff16m2_8:
  2022 00000996 89C1                    	mov	cx, ax	; word count
  2023                                  lff16m2_1:
  2024 00000998 AD                      	lodsw
  2025 00000999 AB                      	stosw		; original sample (left channel)
  2026 0000099A AB                      	stosw		; original sample (right channel)
  2027 0000099B 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2028                                  	;mov	[previous_val], ax
  2029 0000099E 89C3                    	mov	bx, ax	
  2030                                  	; 02/02/2025
  2031 000009A0 8B04                    	mov	ax, [si]
  2032 000009A2 49                      	dec	cx
  2033 000009A3 7502                    	jnz	short lff16m2_2
  2034 000009A5 31C0                    	xor	ax, ax
  2035                                  lff16m2_2:
  2036 000009A7 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2037 000009AA 89C5                    	mov	bp, ax	; [next_val]
  2038                                  	;add	ax, [previous_val]
  2039 000009AC 01D8                    	add	ax, bx
  2040 000009AE D1D8                    	rcr	ax, 1
  2041 000009B0 89C2                    	mov	dx, ax	; this is temporary interpolation value
  2042                                  	;add	ax, [previous_val]
  2043 000009B2 01D8                    	add	ax, bx
  2044 000009B4 D1D8                    	rcr	ax, 1
  2045 000009B6 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2046 000009B9 AB                      	stosw		; this is 1st interpolated sample (L)
  2047 000009BA AB                      	stosw		; this is 1st interpolated sample (R)
  2048 000009BB 89E8                    	mov	ax, bp 
  2049 000009BD 01D0                    	add	ax, dx
  2050 000009BF D1D8                    	rcr	ax, 1
  2051 000009C1 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2052 000009C4 AB                      	stosw		; this is 2nd interpolated sample (L)
  2053 000009C5 AB                      	stosw		; this is 2nd interpolated sample (R)
  2054                                  	; 16 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2055 000009C6 09C9                    	or	cx, cx
  2056 000009C8 75CE                    	jnz	short lff16m2_1
  2057 000009CA E913FC                  	jmp	lff16m2_3
  2058                                  
  2059                                  lff16m2_7:
  2060                                  lff16s2_7:
  2061 000009CD E92AFC                  	jmp	lff16m2_5  ; error
  2062                                  
  2063                                  ;-----------------------------------------------------------------------------
  2064                                  
  2065                                  load_16khz_stereo_16_bit:
  2066                                  	; 02/02/2025
  2067                                  	; 16/11/2023
  2068                                  	; 15/11/2023
  2069                                  	; 13/11/2023
  2070 000009D0 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2071                                  					; last of the file?
  2072 000009D5 7402                    	jz	short lff16s2_0		; no
  2073 000009D7 F9                      	stc
  2074 000009D8 C3                      	retn
  2075                                  
  2076                                  lff16s2_0:
  2077 000009D9 8EC0                    	mov	es, ax ; buffer segment
  2078 000009DB 31FF                    	xor	di, di
  2079 000009DD BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2080                                  	; ds = cs
  2081                                  
  2082                                  	; load file into memory
  2083 000009E0 8B0E[B876]                      mov	cx, [loadsize]
  2084 000009E4 8B1E[DF68]              	mov	bx, [FileHandle]
  2085 000009E8 B43F                           	mov	ah, 3Fh
  2086 000009EA CD21                    	int	21h
  2087 000009EC 72DF                    	jc	short lff16s2_7 ; error !
  2088                                  
  2089                                  	; 14/11/2024
  2090 000009EE A3[BE76]                	mov	[count], ax
  2091                                  
  2092 000009F1 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2093                                  	
  2094                                  	;shr	ax, 1
  2095 000009F3 C1E802                  	shr	ax, 2	; 16/11/2023
  2096                                  	;and	ax, ax
  2097 000009F6 7503                    	jnz	short lff16s2_8
  2098                                  	;jmp	lff16s2_3
  2099                                  	; 15/11/2023
  2100 000009F8 E9F8FB                  	jmp	lff16_eof
  2101                                  
  2102                                  lff16s2_8:
  2103 000009FB 89C1                    	mov	cx, ax	; dword count
  2104                                  lff16s2_1:
  2105 000009FD AD                      	lodsw
  2106 000009FE AB                      	stosw		; original sample (L)
  2107 000009FF 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2108 00000A02 A3[B817]                	mov	[previous_val_l], ax
  2109 00000A05 AD                      	lodsw
  2110 00000A06 AB                      	stosw		; original sample (R)
  2111 00000A07 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2112 00000A0A A3[BA17]                	mov	[previous_val_r], ax
  2113                                  	; 02/02/2025
  2114 00000A0D 8B04                    	mov	ax, [si]
  2115 00000A0F 8B5402                  	mov	dx, [si+2]
  2116                                  	; 16/11/2023
  2117 00000A12 49                      	dec	cx
  2118 00000A13 7504                    	jnz	short lff16s2_2
  2119 00000A15 31D2                    	xor	dx, dx
  2120 00000A17 31C0                    	xor	ax, ax
  2121                                  lff16s2_2:
  2122 00000A19 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2123                                  	;mov	[next_val_l], ax
  2124 00000A1C 89C5                    	mov	bp, ax
  2125 00000A1E 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format
  2126 00000A21 8916[BE17]              	mov	[next_val_r], dx
  2127 00000A25 0306[B817]              	add	ax, [previous_val_l]
  2128 00000A29 D1D8                    	rcr	ax, 1
  2129 00000A2B 89C2                    	mov	dx, ax	; this is temporary interpolation value (L)
  2130 00000A2D 0306[B817]              	add	ax, [previous_val_l]
  2131 00000A31 D1D8                    	rcr	ax, 1
  2132 00000A33 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2133 00000A36 AB                      	stosw		; this is 1st interpolated sample (L)
  2134 00000A37 A1[BE17]                	mov	ax, [next_val_r]
  2135 00000A3A 0306[BA17]              	add	ax, [previous_val_r]
  2136 00000A3E D1D8                    	rcr	ax, 1
  2137 00000A40 89C3                    	mov	bx, ax	; this is temporary interpolation value (R)
  2138 00000A42 0306[BA17]              	add	ax, [previous_val_r]
  2139 00000A46 D1D8                    	rcr	ax, 1
  2140 00000A48 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2141 00000A4B AB                      	stosw		; this is 1st interpolated sample (R)
  2142                                  	;mov	ax, [next_val_l]
  2143 00000A4C 89E8                    	mov	ax, bp
  2144 00000A4E 01D0                    	add	ax, dx
  2145 00000A50 D1D8                    	rcr	ax, 1
  2146 00000A52 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2147 00000A55 AB                      	stosw		; this is 2nd interpolated sample (L)
  2148 00000A56 A1[BE17]                	mov	ax, [next_val_r]
  2149 00000A59 01D8                    	add	ax, bx
  2150 00000A5B D1D8                    	rcr	ax, 1
  2151 00000A5D 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2152 00000A60 AB                      	stosw 		; this is 2nd interpolated sample (R)
  2153                                  	
  2154                                  	; 16 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2155 00000A61 09C9                    	or	cx, cx
  2156 00000A63 7598                    	jnz	short lff16s2_1
  2157 00000A65 E978FB                  	jmp	lff16s2_3
  2158                                  
  2159                                  ;-----------------------------------------------------------------------------
  2160                                  ;-----------------------------------------------------------------------------
  2161                                  
  2162                                  load_24khz_mono_8_bit:
  2163                                  	; 02/02/2025
  2164                                  	; 15/11/2023
  2165 00000A68 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2166                                  					; last of the file?
  2167 00000A6D 7402                    	jz	short lff24m_0		; no
  2168 00000A6F F9                      	stc
  2169 00000A70 C3                      	retn
  2170                                  
  2171                                  lff24m_0:
  2172 00000A71 8EC0                    	mov	es, ax ; buffer segment
  2173 00000A73 31FF                    	xor	di, di
  2174 00000A75 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2175                                  	; ds = cs
  2176                                  
  2177                                  	; load file into memory
  2178 00000A78 8B0E[B876]                      mov	cx, [loadsize]
  2179 00000A7C 8B1E[DF68]              	mov	bx, [FileHandle]
  2180 00000A80 B43F                           	mov	ah, 3Fh
  2181 00000A82 CD21                    	int	21h
  2182 00000A84 7231                    	jc	short lff24m_7 ; error !
  2183                                  
  2184                                  	; 14/11/2024
  2185 00000A86 A3[BE76]                	mov	[count], ax
  2186                                  
  2187 00000A89 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2188                                  	
  2189 00000A8B 21C0                    	and	ax, ax
  2190 00000A8D 7503                    	jnz	short lff24m_8
  2191 00000A8F E961FB                  	jmp	lff24_eof
  2192                                  
  2193                                  lff24m_8:
  2194 00000A92 89C1                    	mov	cx, ax	; byte count
  2195                                  lff24m_1:
  2196 00000A94 AC                      	lodsb
  2197                                  	;mov	[previous_val], al
  2198 00000A95 88C3                    	mov	bl, al
  2199 00000A97 2C80                    	sub	al, 80h
  2200 00000A99 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2201 00000A9C AB                      	stosw		; original sample (left channel)
  2202 00000A9D AB                      	stosw		; original sample (right channel)
  2203                                  	;xor	ax, ax
  2204                                  	; 02/02/2025
  2205 00000A9E 8A04                    	mov	al, [si]
  2206 00000AA0 49                      	dec	cx
  2207 00000AA1 7502                    	jnz	short lff24m_2
  2208 00000AA3 B080                    	mov	al, 80h
  2209                                  lff24m_2:
  2210                                  	;;mov	[next_val], al
  2211                                  	;mov	bh, al
  2212                                  	;add	al, [previous_val]
  2213 00000AA5 00D8                    	add	al, bl
  2214 00000AA7 D0D8                    	rcr	al, 1
  2215 00000AA9 2C80                    	sub	al, 80h
  2216 00000AAB C1E008                  	shl	ax, 8
  2217 00000AAE AB                      	stosw		; this is interpolated sample (L)
  2218 00000AAF AB                      	stosw		; this is interpolated sample (R)
  2219                                  	
  2220                                  	; 24 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2221 00000AB0 09C9                    	or	cx, cx
  2222 00000AB2 75E0                    	jnz	short lff24m_1
  2223 00000AB4 E929FB                  	jmp	lff24_3
  2224                                  
  2225                                  lff24m_7:
  2226                                  lff24s_7:
  2227 00000AB7 E940FB                  	jmp	lff24_5  ; error
  2228                                  
  2229                                  ;-----------------------------------------------------------------------------
  2230                                  
  2231                                  load_24khz_stereo_8_bit:
  2232                                  	; 02/02/2025
  2233                                  	; 15/11/2023
  2234 00000ABA F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2235                                  					; last of the file?
  2236 00000ABF 7402                    	jz	short lff24s_0		; no
  2237 00000AC1 F9                      	stc
  2238 00000AC2 C3                      	retn
  2239                                  
  2240                                  lff24s_0:
  2241 00000AC3 8EC0                    	mov	es, ax ; buffer segment
  2242 00000AC5 31FF                    	xor	di, di
  2243 00000AC7 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2244                                  	; ds = cs
  2245                                  
  2246                                  	; load file into memory
  2247 00000ACA 8B0E[B876]                      mov	cx, [loadsize]
  2248 00000ACE 8B1E[DF68]              	mov	bx, [FileHandle]
  2249 00000AD2 B43F                           	mov	ah, 3Fh
  2250 00000AD4 CD21                    	int	21h
  2251 00000AD6 72DF                    	jc	short lff24s_7 ; error !
  2252                                  
  2253                                  	; 14/11/2024
  2254 00000AD8 A3[BE76]                	mov	[count], ax
  2255                                  
  2256 00000ADB 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2257                                  	
  2258 00000ADD D1E8                    	shr	ax, 1
  2259                                  	;and	ax, ax
  2260 00000ADF 7503                    	jnz	short lff24s_8
  2261 00000AE1 E90FFB                  	jmp	lff24_eof
  2262                                  
  2263                                  lff24s_8:
  2264 00000AE4 89C1                    	mov	cx, ax	; word count
  2265                                  lff24s_1:
  2266 00000AE6 AC                      	lodsb
  2267 00000AE7 A2[B817]                	mov	[previous_val_l], al
  2268 00000AEA 2C80                    	sub	al, 80h
  2269 00000AEC C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2270 00000AEF AB                      	stosw		; original sample (L)
  2271 00000AF0 AC                      	lodsb
  2272 00000AF1 A2[BA17]                	mov	[previous_val_r], al
  2273 00000AF4 2C80                    	sub	al, 80h
  2274 00000AF6 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2275 00000AF9 AB                      	stosw		; original sample (R)
  2276                                  	;xor	ax, ax
  2277                                  	; 02/02/2025
  2278 00000AFA 8B04                    	mov	ax, [si]
  2279 00000AFC 49                      	dec	cx
  2280 00000AFD 7503                    	jnz	short lff24s_2
  2281                                  		; convert 8 bit sample to 16 bit sample
  2282 00000AFF B88080                  	mov	ax, 8080h
  2283                                  lff24s_2:
  2284                                  	;;mov	[next_val_l], al
  2285                                  	;;mov	[next_val_r], ah
  2286                                  	;mov	bx, ax
  2287 00000B02 88E7                    	mov	bh, ah
  2288 00000B04 0206[B817]              	add	al, [previous_val_l]
  2289 00000B08 D0D8                    	rcr	al, 1
  2290                                  	;mov	dl, al
  2291 00000B0A 2C80                    	sub	al, 80h
  2292 00000B0C C1E008                  	shl	ax, 8
  2293 00000B0F AB                      	stosw		; this is interpolated sample (L)
  2294 00000B10 88F8                    	mov	al, bh	; [next_val_r]
  2295 00000B12 0206[BA17]              	add	al, [previous_val_r]
  2296 00000B16 D0D8                    	rcr	al, 1
  2297                                  	;mov	dh, al
  2298 00000B18 2C80                    	sub	al, 80h
  2299 00000B1A C1E008                  	shl	ax, 8
  2300 00000B1D AB                      	stosw		; this is interpolated sample (R)
  2301                                  		
  2302                                  	; 24 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2303 00000B1E 09C9                    	or	cx, cx
  2304 00000B20 75C4                    	jnz	short lff24s_1
  2305 00000B22 E9BBFA                  	jmp	lff24_3
  2306                                  
  2307                                  ;-----------------------------------------------------------------------------
  2308                                  
  2309                                  load_24khz_mono_16_bit:
  2310                                  	; 02/02/2025
  2311                                  	; 15/11/2023
  2312 00000B25 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2313                                  					; last of the file?
  2314 00000B2A 7402                    	jz	short lff24m2_0		; no
  2315 00000B2C F9                      	stc
  2316 00000B2D C3                      	retn
  2317                                  
  2318                                  lff24m2_0:
  2319 00000B2E 8EC0                    	mov	es, ax ; buffer segment
  2320 00000B30 31FF                    	xor	di, di
  2321 00000B32 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2322                                  	; ds = cs
  2323                                  
  2324                                  	; load file into memory
  2325 00000B35 8B0E[B876]                      mov	cx, [loadsize]
  2326 00000B39 8B1E[DF68]              	mov	bx, [FileHandle]
  2327 00000B3D B43F                           	mov	ah, 3Fh
  2328 00000B3F CD21                    	int	21h
  2329 00000B41 722E                    	jc	short lff24m2_7 ; error !
  2330                                  
  2331                                  	; 14/11/2024
  2332 00000B43 A3[BE76]                	mov	[count], ax
  2333                                  
  2334 00000B46 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2335                                  	
  2336 00000B48 D1E8                    	shr	ax, 1
  2337                                  	;and	ax, ax
  2338 00000B4A 7503                    	jnz	short lff24m2_8
  2339 00000B4C E9A4FA                  	jmp	lff24_eof
  2340                                  
  2341                                  lff24m2_8:
  2342 00000B4F 89C1                    	mov	cx, ax	; word count
  2343                                  lff24m2_1:
  2344 00000B51 AD                      	lodsw
  2345 00000B52 AB                      	stosw		; original sample (left channel)
  2346 00000B53 AB                      	stosw		; original sample (right channel)
  2347 00000B54 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2348                                  	;mov	[previous_val], ax
  2349                                  	;mov	bx, ax	
  2350                                  	;mov	ax, [si
  2351                                  	; 02/02/2025
  2352 00000B57 8B1C                    	mov	bx, [si]
  2353 00000B59 49                      	dec	cx
  2354 00000B5A 7502                    	jnz	short lff24m2_2
  2355                                  	;xor	ax, ax
  2356 00000B5C 31DB                    	xor	bx, bx
  2357                                  lff24m2_2:
  2358                                  	; 02/02/2025
  2359 00000B5E 80C780                  	add	bh, 80h ; convert sound level 0 to 65535 format
  2360                                  	;add	ah, 80h
  2361                                  	;mov	bp, ax	; [next_val]
  2362                                  	;add	ax, [previous_val]
  2363                                  	; ax = [previous_val]
  2364                                  	; bx = [next_val]
  2365 00000B61 01D8                    	add	ax, bx
  2366 00000B63 D1D8                    	rcr	ax, 1
  2367 00000B65 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2368 00000B68 AB                      	stosw		; this is interpolated sample (L)
  2369 00000B69 AB                      	stosw		; this is interpolated sample (R)
  2370                                  	; 24 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2371 00000B6A 09C9                    	or	cx, cx
  2372 00000B6C 75E3                    	jnz	short lff24m2_1
  2373 00000B6E E96FFA                  	jmp	lff24_3
  2374                                  
  2375                                  lff24m2_7:
  2376                                  lff24s2_7:
  2377 00000B71 E986FA                  	jmp	lff24_5  ; error
  2378                                  
  2379                                  ;-----------------------------------------------------------------------------
  2380                                  
  2381                                  load_24khz_stereo_16_bit:
  2382                                  	; 02/02/2025
  2383                                  	; 16/11/2023
  2384                                  	; 15/11/2023
  2385 00000B74 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2386                                  					; last of the file?
  2387 00000B79 7402                    	jz	short lff24s2_0		; no
  2388 00000B7B F9                      	stc
  2389 00000B7C C3                      	retn
  2390                                  
  2391                                  lff24s2_0:
  2392 00000B7D 8EC0                    	mov	es, ax ; buffer segment
  2393 00000B7F 31FF                    	xor	di, di
  2394 00000B81 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2395                                  	; ds = cs
  2396                                  
  2397                                  	; load file into memory
  2398 00000B84 8B0E[B876]                      mov	cx, [loadsize]
  2399 00000B88 8B1E[DF68]              	mov	bx, [FileHandle]
  2400 00000B8C B43F                           	mov	ah, 3Fh
  2401 00000B8E CD21                    	int	21h
  2402 00000B90 72DF                    	jc	short lff24s2_7 ; error !
  2403                                  
  2404                                  	; 14/11/2024
  2405 00000B92 A3[BE76]                	mov	[count], ax
  2406                                  
  2407 00000B95 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2408                                  	
  2409                                  	;shr	ax, 1
  2410 00000B97 C1E802                  	shr	ax, 2	; 16/11/2023
  2411                                  	;and	ax, ax
  2412 00000B9A 7503                    	jnz	short lff24s2_8
  2413 00000B9C E954FA                  	jmp	lff24_eof
  2414                                  
  2415                                  lff24s2_8:
  2416 00000B9F 89C1                    	mov	cx, ax	; dword count
  2417                                  lff24s2_1:
  2418 00000BA1 AD                      	lodsw
  2419 00000BA2 AB                      	stosw		; original sample (L)
  2420 00000BA3 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2421 00000BA6 A3[B817]                	mov	[previous_val_l], ax
  2422 00000BA9 AD                      	lodsw
  2423 00000BAA AB                      	stosw		; original sample (R)
  2424 00000BAB 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2425                                  	;mov	[previous_val_r], ax
  2426 00000BAE 89C3                    	mov	bx, ax
  2427                                  	; 02/02/2025
  2428 00000BB0 8B04                    	mov	ax, [si]
  2429 00000BB2 8B5402                  	mov	dx, [si+2]
  2430                                  	; 16/11/2023
  2431 00000BB5 49                      	dec	cx
  2432 00000BB6 7504                    	jnz	short lff24s2_2
  2433 00000BB8 31D2                    	xor	dx, dx
  2434 00000BBA 31C0                    	xor	ax, ax
  2435                                  lff24s2_2:
  2436 00000BBC 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2437                                  	;;mov	[next_val_l], ax
  2438                                  	;mov	bp, ax
  2439 00000BBF 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format 
  2440                                  	;mov	[next_val_r], dx
  2441 00000BC2 0306[B817]              	add	ax, [previous_val_l]
  2442 00000BC6 D1D8                    	rcr	ax, 1
  2443 00000BC8 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2444 00000BCB AB                      	stosw		; this is interpolated sample (L)
  2445                                  	;mov	ax, [next_val_r]
  2446 00000BCC 89D0                    	mov	ax, dx
  2447                                  	;add	ax, [previous_val_r]
  2448 00000BCE 01D8                    	add	ax, bx
  2449 00000BD0 D1D8                    	rcr	ax, 1
  2450 00000BD2 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2451 00000BD5 AB                      	stosw		; this is interpolated sample (R)
  2452                                  	
  2453                                  	; 24 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2454 00000BD6 09C9                    	or	cx, cx
  2455 00000BD8 75C7                    	jnz	short lff24s2_1
  2456 00000BDA E903FA                  	jmp	lff24_3
  2457                                  
  2458                                  ;-----------------------------------------------------------------------------
  2459                                  ;-----------------------------------------------------------------------------
  2460                                  
  2461                                  load_32khz_mono_8_bit:
  2462                                  	; 02/02/2025
  2463                                  	; 15/11/2023
  2464 00000BDD F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2465                                  					; last of the file?
  2466 00000BE2 7402                    	jz	short lff32m_0		; no
  2467 00000BE4 F9                      	stc
  2468 00000BE5 C3                      	retn
  2469                                  
  2470                                  lff32m_0:
  2471 00000BE6 8EC0                    	mov	es, ax ; buffer segment
  2472 00000BE8 31FF                    	xor	di, di
  2473 00000BEA BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2474                                  	; ds = cs
  2475                                  
  2476                                  	; load file into memory
  2477 00000BED 8B0E[B876]                      mov	cx, [loadsize]
  2478 00000BF1 8B1E[DF68]              	mov	bx, [FileHandle]
  2479 00000BF5 B43F                           	mov	ah, 3Fh
  2480 00000BF7 CD21                    	int	21h
  2481 00000BF9 723A                    	jc	short lff32m_7 ; error !
  2482                                  
  2483                                  	; 14/11/2024
  2484 00000BFB A3[BE76]                	mov	[count], ax
  2485                                  
  2486 00000BFE 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2487                                  	
  2488 00000C00 21C0                    	and	ax, ax
  2489 00000C02 7503                    	jnz	short lff32m_8
  2490 00000C04 E9ECF9                  	jmp	lff32_eof
  2491                                  
  2492                                  lff32m_8:
  2493 00000C07 89C1                    	mov	cx, ax	; byte count
  2494                                  lff32m_1:
  2495 00000C09 AC                      	lodsb
  2496                                  	;mov	[previous_val], al
  2497 00000C0A 88C3                    	mov	bl, al
  2498 00000C0C 2C80                    	sub	al, 80h
  2499 00000C0E C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2500 00000C11 AB                      	stosw		; original sample (left channel)
  2501 00000C12 AB                      	stosw		; original sample (right channel)
  2502                                  	;xor	ax, ax
  2503                                  	; 02/02/2025
  2504 00000C13 8A04                    	mov	al, [si]
  2505 00000C15 49                      	dec	cx
  2506 00000C16 7502                    	jnz	short lff32m_2
  2507 00000C18 B080                    	mov	al, 80h
  2508                                  lff32m_2:
  2509                                  	;;mov	[next_val], al
  2510                                  	;mov	bh, al
  2511                                  	;add	al, [previous_val]
  2512 00000C1A 00D8                    	add	al, bl
  2513 00000C1C D0D8                    	rcr	al, 1
  2514 00000C1E 2C80                    	sub	al, 80h
  2515 00000C20 C1E008                  	shl	ax, 8
  2516 00000C23 AB                      	stosw		; this is interpolated sample (L)
  2517 00000C24 AB                      	stosw		; this is interpolated sample (R)
  2518                                  	
  2519                                  	; different than 8-16-24 kHZ !
  2520                                  	; 'original-interpolated-original' trio samples
  2521 00000C25 E30B                    	jcxz	lff32m_3
  2522                                  
  2523 00000C27 AC                      	lodsb
  2524 00000C28 2C80                    	sub	al, 80h
  2525 00000C2A C1E008                  	shl	ax, 8
  2526 00000C2D AB                      	stosw		; original sample (left channel)
  2527 00000C2E AB                      	stosw		; original sample (right channel)
  2528                                  
  2529                                  	; 32 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2530 00000C2F 49                      	dec	cx
  2531 00000C30 75D7                    	jnz	short lff32m_1
  2532                                  lff32m_3:
  2533 00000C32 E9ABF9                  	jmp	lff32_3
  2534                                  
  2535                                  lff32m_7:
  2536                                  lff32s_7:
  2537 00000C35 E9C2F9                  	jmp	lff32_5  ; error
  2538                                  
  2539                                  ;-----------------------------------------------------------------------------
  2540                                  
  2541                                  load_32khz_stereo_8_bit:
  2542                                  	; 02/02/2025
  2543                                  	; 15/11/2023
  2544 00000C38 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2545                                  					; last of the file?
  2546 00000C3D 7402                    	jz	short lff32s_0		; no
  2547 00000C3F F9                      	stc
  2548 00000C40 C3                      	retn
  2549                                  
  2550                                  lff32s_0:
  2551 00000C41 8EC0                    	mov	es, ax ; buffer segment
  2552 00000C43 31FF                    	xor	di, di
  2553 00000C45 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2554                                  	; ds = cs
  2555                                  
  2556                                  	; load file into memory
  2557 00000C48 8B0E[B876]                      mov	cx, [loadsize]
  2558 00000C4C 8B1E[DF68]              	mov	bx, [FileHandle]
  2559 00000C50 B43F                           	mov	ah, 3Fh
  2560 00000C52 CD21                    	int	21h
  2561 00000C54 72DF                    	jc	short lff32s_7 ; error !
  2562                                  
  2563                                  	; 14/11/2024
  2564 00000C56 A3[BE76]                	mov	[count], ax
  2565                                  
  2566 00000C59 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2567                                  	
  2568 00000C5B D1E8                    	shr	ax, 1
  2569                                  	;and	ax, ax
  2570 00000C5D 7503                    	jnz	short lff32s_8
  2571 00000C5F E991F9                  	jmp	lff32_eof
  2572                                  
  2573                                  lff32s_8:
  2574 00000C62 89C1                    	mov	cx, ax	; word count
  2575                                  lff32s_1:
  2576 00000C64 AC                      	lodsb
  2577 00000C65 A2[B817]                	mov	[previous_val_l], al
  2578 00000C68 2C80                    	sub	al, 80h
  2579 00000C6A C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2580 00000C6D AB                      	stosw		; original sample (L)
  2581 00000C6E AC                      	lodsb
  2582 00000C6F A2[BA17]                	mov	[previous_val_r], al
  2583 00000C72 2C80                    	sub	al, 80h
  2584 00000C74 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2585 00000C77 AB                      	stosw		; original sample (R)
  2586                                  	; 02/02/2025
  2587 00000C78 8B04                    	mov	ax, [si]
  2588 00000C7A 49                      	dec	cx
  2589 00000C7B 7503                    	jnz	short lff32s_2
  2590                                  		; convert 8 bit sample to 16 bit sample
  2591                                  	;xor	ax, ax
  2592 00000C7D B88080                  	mov	ax, 8080h
  2593                                  lff32s_2:
  2594                                  	;;mov	[next_val_l], al
  2595                                  	;;mov	[next_val_r], ah
  2596                                  	;mov	bx, ax
  2597 00000C80 88E7                    	mov	bh, ah
  2598 00000C82 0206[B817]              	add	al, [previous_val_l]
  2599 00000C86 D0D8                    	rcr	al, 1
  2600                                  	;mov	dl, al
  2601 00000C88 2C80                    	sub	al, 80h
  2602 00000C8A C1E008                  	shl	ax, 8
  2603 00000C8D AB                      	stosw		; this is interpolated sample (L)
  2604 00000C8E 88F8                    	mov	al, bh	; [next_val_r]
  2605 00000C90 0206[BA17]              	add	al, [previous_val_r]
  2606 00000C94 D0D8                    	rcr	al, 1
  2607                                  	;mov	dh, al
  2608 00000C96 2C80                    	sub	al, 80h
  2609 00000C98 C1E008                  	shl	ax, 8
  2610 00000C9B AB                      	stosw		; this is interpolated sample (R)
  2611                                  
  2612                                  	; different than 8-16-24 kHZ !
  2613                                  	; 'original-interpolated-original' trio samples
  2614 00000C9C E311                    	jcxz	lff32s_3
  2615                                  
  2616 00000C9E AC                      	lodsb
  2617 00000C9F 2C80                    	sub	al, 80h
  2618 00000CA1 C1E008                  	shl	ax, 8
  2619 00000CA4 AB                      	stosw		; original sample (left channel)
  2620                                  
  2621 00000CA5 AC                      	lodsb
  2622 00000CA6 2C80                    	sub	al, 80h
  2623 00000CA8 C1E008                  	shl	ax, 8
  2624 00000CAB AB                      	stosw		; original sample (right channel)
  2625                                  		
  2626                                  	; 32 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2627 00000CAC 49                      	dec	cx
  2628 00000CAD 75B5                    	jnz	short lff32s_1
  2629                                  lff32s_3:
  2630 00000CAF E92EF9                  	jmp	lff32_3
  2631                                  
  2632                                  ;-----------------------------------------------------------------------------
  2633                                  
  2634                                  load_32khz_mono_16_bit:
  2635                                  	; 02/02/2025
  2636                                  	; 15/11/2023
  2637 00000CB2 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2638                                  					; last of the file?
  2639 00000CB7 7402                    	jz	short lff32m2_0		; no
  2640 00000CB9 F9                      	stc
  2641 00000CBA C3                      	retn
  2642                                  
  2643                                  lff32m2_0:
  2644 00000CBB 8EC0                    	mov	es, ax ; buffer segment
  2645 00000CBD 31FF                    	xor	di, di
  2646 00000CBF BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2647                                  	; ds = cs
  2648                                  
  2649                                  	; load file into memory
  2650 00000CC2 8B0E[B876]                      mov	cx, [loadsize]
  2651 00000CC6 8B1E[DF68]              	mov	bx, [FileHandle]
  2652 00000CCA B43F                           	mov	ah, 3Fh
  2653 00000CCC CD21                    	int	21h
  2654 00000CCE 7232                    	jc	short lff32m2_7 ; error !
  2655                                  
  2656                                  	; 14/11/2024
  2657 00000CD0 A3[BE76]                	mov	[count], ax
  2658                                  
  2659 00000CD3 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2660                                  	
  2661 00000CD5 D1E8                    	shr	ax, 1
  2662                                  	;and	ax, ax
  2663 00000CD7 7503                    	jnz	short lff32m2_8
  2664 00000CD9 E917F9                  	jmp	lff32_eof
  2665                                  
  2666                                  lff32m2_8:
  2667 00000CDC 89C1                    	mov	cx, ax	; word count
  2668                                  lff32m2_1:
  2669 00000CDE AD                      	lodsw
  2670 00000CDF AB                      	stosw		; original sample (left channel)
  2671 00000CE0 AB                      	stosw		; original sample (right channel)
  2672 00000CE1 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2673                                  	;mov	[previous_val], ax
  2674                                  	;mov	bx, ax	
  2675                                  	; 02/02/2025
  2676                                  	;mov	ax, [si]
  2677 00000CE4 8B1C                    	mov	bx, [si]
  2678 00000CE6 49                      	dec	cx
  2679 00000CE7 7502                    	jnz	short lff32m2_2
  2680                                  	;xor	ax, ax
  2681 00000CE9 31DB                    	xor	bx, bx
  2682                                  lff32m2_2:
  2683                                  	; 02/02/2025
  2684 00000CEB 80C780                  	add	bh, 80h ; convert sound level 0 to 65535 format
  2685                                  	;add	ah, 80h
  2686                                  	;mov	bp, ax	; [next_val]
  2687                                  	;add	ax, [previous_val]
  2688                                  	; ax = [previous_val]
  2689                                  	; bx = [next_val]
  2690 00000CEE 01D8                    	add	ax, bx
  2691 00000CF0 D1D8                    	rcr	ax, 1
  2692 00000CF2 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2693 00000CF5 AB                      	stosw		; this is interpolated sample (L)
  2694 00000CF6 AB                      	stosw		; this is interpolated sample (R)
  2695                                  
  2696                                  	; different than 8-16-24 kHZ !
  2697                                  	; 'original-interpolated-original' trio samples
  2698 00000CF7 E306                    	jcxz	lff32m2_3
  2699                                  
  2700 00000CF9 AD                      	lodsw
  2701 00000CFA AB                      	stosw		; original sample (left channel)
  2702 00000CFB AB                      	stosw		; original sample (right channel)
  2703                                  
  2704                                  	; 32 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2705 00000CFC 49                      	dec	cx
  2706 00000CFD 75DF                    	jnz	short lff32m2_1
  2707                                  lff32m2_3:
  2708 00000CFF E9DEF8                  	jmp	lff32_3
  2709                                  
  2710                                  lff32m2_7:
  2711                                  lff32s2_7:
  2712 00000D02 E9F5F8                  	jmp	lff32_5  ; error
  2713                                  
  2714                                  ;-----------------------------------------------------------------------------
  2715                                  
  2716                                  load_32khz_stereo_16_bit:
  2717                                  	; 02/02/2025
  2718                                  	; 16/11/2023
  2719                                  	; 15/11/2023
  2720 00000D05 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2721                                  					; last of the file?
  2722 00000D0A 7402                    	jz	short lff32s2_0		; no
  2723 00000D0C F9                      	stc
  2724 00000D0D C3                      	retn
  2725                                  
  2726                                  lff32s2_0:
  2727 00000D0E 8EC0                    	mov	es, ax ; buffer segment
  2728 00000D10 31FF                    	xor	di, di
  2729 00000D12 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2730                                  	; ds = cs
  2731                                  
  2732                                  	; load file into memory
  2733 00000D15 8B0E[B876]                      mov	cx, [loadsize]
  2734 00000D19 8B1E[DF68]              	mov	bx, [FileHandle]
  2735 00000D1D B43F                           	mov	ah, 3Fh
  2736 00000D1F CD21                    	int	21h
  2737 00000D21 72DF                    	jc	short lff32s2_7 ; error !
  2738                                  
  2739 00000D23 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2740                                  	
  2741 00000D25 C1E802                  	shr	ax, 2	; 16/11/2023 (word left ch + word right ch)
  2742                                  	;and	ax, ax
  2743 00000D28 7503                    	jnz	short lff32s2_8
  2744 00000D2A E9C6F8                  	jmp	lff32_eof
  2745                                  
  2746                                  lff32s2_8:
  2747 00000D2D 89C1                    	mov	cx, ax	; dword count
  2748                                  lff32s2_1:
  2749 00000D2F AD                      	lodsw
  2750 00000D30 AB                      	stosw		; original sample (L)
  2751 00000D31 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2752 00000D34 A3[B817]                	mov	[previous_val_l], ax
  2753 00000D37 AD                      	lodsw
  2754 00000D38 AB                      	stosw		; original sample (R)
  2755 00000D39 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2756                                  	;mov	[previous_val_r], ax
  2757 00000D3C 89C3                    	mov	bx, ax
  2758                                  	; 02/02/2025
  2759 00000D3E 8B04                    	mov	ax, [si]
  2760 00000D40 8B5402                  	mov	dx, [si+2]
  2761                                  	; 16/11/2023
  2762 00000D43 49                      	dec	cx
  2763 00000D44 7504                    	jnz	short lff32s2_2
  2764 00000D46 31D2                    	xor	dx, dx
  2765 00000D48 31C0                    	xor	ax, ax
  2766                                  lff32s2_2:
  2767 00000D4A 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2768                                  	;;mov	[next_val_l], ax
  2769                                  	;mov	bp, ax
  2770 00000D4D 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format
  2771                                  	;mov	[next_val_r], dx
  2772 00000D50 0306[B817]              	add	ax, [previous_val_l]
  2773 00000D54 D1D8                    	rcr	ax, 1
  2774 00000D56 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2775 00000D59 AB                      	stosw		; this is interpolated sample (L)
  2776                                  	;mov	ax, [next_val_r]
  2777 00000D5A 89D0                    	mov	ax, dx
  2778                                  	;add	ax, [previous_val_r]
  2779 00000D5C 01D8                    	add	ax, bx
  2780 00000D5E D1D8                    	rcr	ax, 1
  2781 00000D60 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2782 00000D63 AB                      	stosw		; this is interpolated sample (R)
  2783                                  
  2784                                  	; different than 8-16-24 kHZ !
  2785                                  	; 'original-interpolated-original' trio samples
  2786 00000D64 E307                    	jcxz	lff32s2_3
  2787                                  
  2788 00000D66 AD                      	lodsw
  2789 00000D67 AB                      	stosw	; original sample (L)
  2790 00000D68 AD                      	lodsw
  2791 00000D69 AB                      	stosw	; original sample (R)
  2792                                  	
  2793                                  	; 32 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2794 00000D6A 49                      	dec	cx
  2795 00000D6B 75C2                    	jnz	short lff32s2_1
  2796                                  lff32s2_3:
  2797 00000D6D E970F8                  	jmp	lff32_3
  2798                                  
  2799                                  ;-----------------------------------------------------------------------------
  2800                                  ;-----------------------------------------------------------------------------
  2801                                  
  2802                                  load_22khz_mono_8_bit:
  2803                                  	; 02/02/2025
  2804                                  	; 16/11/2023
  2805 00000D70 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2806                                  					; last of the file?
  2807 00000D75 7402                    	jz	short lff22m_0		; no
  2808 00000D77 F9                      	stc
  2809 00000D78 C3                      	retn
  2810                                  
  2811                                  lff22m_0:
  2812 00000D79 8EC0                    	mov	es, ax ; buffer segment
  2813 00000D7B 31FF                    	xor	di, di
  2814 00000D7D BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2815                                  	; ds = cs
  2816                                  
  2817                                  	; load file into memory
  2818 00000D80 8B0E[B876]                      mov	cx, [loadsize]
  2819 00000D84 8B1E[DF68]              	mov	bx, [FileHandle]
  2820 00000D88 B43F                           	mov	ah, 3Fh
  2821 00000D8A CD21                    	int	21h
  2822 00000D8C 724B                    	jc	short lff22m_7 ; error !
  2823                                  
  2824                                  	; 14/11/2024
  2825 00000D8E A3[BE76]                	mov	[count], ax
  2826                                  
  2827 00000D91 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2828                                  	
  2829 00000D93 21C0                    	and	ax, ax
  2830 00000D95 7503                    	jnz	short lff22m_8
  2831 00000D97 E959F8                  	jmp	lff22_eof
  2832                                  
  2833                                  lff22m_8:
  2834 00000D9A 89C1                    	mov	cx, ax	; byte count
  2835                                  lff22m_9:
  2836 00000D9C BD0500                  	mov	bp, 5	; interpolation (one step) loop count
  2837 00000D9F C606[C017]03            	mov	byte [faz], 3  ; 3 steps/phases
  2838                                  lff22m_1:
  2839                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  2840 00000DA4 AC                      	lodsb
  2841                                  	; 02/02/2025
  2842 00000DA5 8A14                    	mov	dl, [si]
  2843 00000DA7 49                      	dec	cx
  2844 00000DA8 7502                    	jnz	short lff22m_2_1
  2845 00000DAA B280                    	mov	dl, 80h
  2846                                  lff22m_2_1:	
  2847                                  	; al = [previous_val]
  2848                                  	; dl = [next_val]
  2849 00000DAC E8D405                  	call	interpolating_3_8bit_mono ; 1 of 17
  2850 00000DAF E325                    	jcxz	lff22m_3
  2851                                  lff22m_2_2:
  2852 00000DB1 AC                      	lodsb
  2853                                  	; 02/02/2025
  2854 00000DB2 8A14                    	mov	dl, [si]
  2855 00000DB4 49                      	dec	cx
  2856 00000DB5 7502                    	jnz	short lff22m_2_3
  2857 00000DB7 B280                    	mov	dl, 80h
  2858                                  lff22m_2_3:
  2859 00000DB9 E83C06                   	call	interpolating_2_8bit_mono ; 2 of 17 .. 6 of 17
  2860 00000DBC E318                    	jcxz	lff22m_3
  2861 00000DBE 4D                      	dec	bp
  2862 00000DBF 75F0                    	jnz	short lff22m_2_2
  2863                                  
  2864 00000DC1 A0[C017]                	mov	al, [faz]
  2865 00000DC4 FEC8                    	dec	al
  2866 00000DC6 74D4                    	jz	short lff22m_9
  2867 00000DC8 FE0E[C017]              	dec	byte [faz]
  2868 00000DCC BD0400                  	mov	bp, 4
  2869 00000DCF FEC8                    	dec	al
  2870 00000DD1 75D1                    	jnz	short lff22m_1 ; 3:2:2:2:2 ; 7-11 of 17
  2871 00000DD3 45                      	inc	bp ; 5
  2872 00000DD4 EBCE                    	jmp	short lff22m_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  2873                                  
  2874                                  lff22m_3:
  2875                                  lff22s_3:
  2876 00000DD6 E907F8                  	jmp	lff22_3	; padfill
  2877                                  		; (put zeros in the remain words of the buffer)
  2878                                  lff22m_7:
  2879                                  lff22s_7:
  2880 00000DD9 E91EF8                  	jmp	lff22_5  ; error
  2881                                  
  2882                                  ;-----------------------------------------------------------------------------
  2883                                  
  2884                                  load_22khz_stereo_8_bit:
  2885                                  	; 02/02/2025
  2886                                  	; 16/11/2023
  2887 00000DDC F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2888                                  					; last of the file?
  2889 00000DE1 7402                    	jz	short lff22s_0		; no
  2890 00000DE3 F9                      	stc
  2891 00000DE4 C3                      	retn
  2892                                  
  2893                                  lff22s_0:
  2894 00000DE5 8EC0                    	mov	es, ax ; buffer segment
  2895 00000DE7 31FF                    	xor	di, di
  2896 00000DE9 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2897                                  	; ds = cs
  2898                                  
  2899                                  	; load file into memory
  2900 00000DEC 8B0E[B876]                      mov	cx, [loadsize]
  2901 00000DF0 8B1E[DF68]              	mov	bx, [FileHandle]
  2902 00000DF4 B43F                           	mov	ah, 3Fh
  2903 00000DF6 CD21                    	int	21h
  2904 00000DF8 72DF                    	jc	short lff22s_7 ; error !
  2905                                  
  2906                                  	; 14/11/2024
  2907 00000DFA A3[BE76]                	mov	[count], ax
  2908                                  
  2909 00000DFD 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2910                                  	
  2911 00000DFF D1E8                    	shr	ax, 1
  2912                                  	;and	ax, ax
  2913 00000E01 7503                    	jnz	short lff22s_8
  2914 00000E03 E9EDF7                  	jmp	lff22_eof
  2915                                  
  2916                                  lff22s_8:
  2917 00000E06 89C1                    	mov	cx, ax	; word count
  2918                                  lff22s_9:
  2919 00000E08 BD0500                  	mov	bp, 5	; interpolation (one step) loop count
  2920 00000E0B C606[C017]03            	mov	byte [faz], 3  ; 3 steps/phase
  2921                                  lff22s_1:
  2922                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  2923 00000E10 AD                      	lodsw
  2924                                  	; 02/02/2025
  2925 00000E11 8B14                    	mov	dx, [si]
  2926 00000E13 49                      	dec	cx
  2927 00000E14 7503                    	jnz	short lff22s_2_1
  2928 00000E16 BA8080                  	mov	dx, 8080h
  2929                                  lff22s_2_1:	
  2930                                  	; al = [previous_val_l]
  2931                                  	; ah = [previous_val_r]
  2932                                  	; dl = [next_val_l]
  2933                                  	; dl = [next_val_r]	
  2934 00000E19 E89105                  	call	interpolating_3_8bit_stereo ; 1 of 17
  2935 00000E1C E3B8                    	jcxz	lff22s_3
  2936                                  lff22s_2_2:
  2937 00000E1E AD                      	lodsw
  2938                                  	; 02/02/2025
  2939 00000E1F 8B14                    	mov	dx, [si]
  2940 00000E21 49                      	dec	cx
  2941 00000E22 7503                    	jnz	short lff22s_2_3
  2942 00000E24 BA8080                  	mov	dx, 8080h
  2943                                  lff22s_2_3:
  2944 00000E27 E8E505                   	call	interpolating_2_8bit_stereo ; 2 of 17 .. 6 of 17
  2945 00000E2A E3AA                    	jcxz	lff22s_3
  2946 00000E2C 4D                      	dec	bp
  2947 00000E2D 75EF                    	jnz	short lff22s_2_2
  2948                                  
  2949 00000E2F A0[C017]                	mov	al, [faz]
  2950 00000E32 FEC8                    	dec	al
  2951 00000E34 74D2                    	jz	short lff22s_9
  2952 00000E36 FE0E[C017]              	dec	byte [faz]
  2953 00000E3A BD0400                  	mov	bp, 4
  2954 00000E3D FEC8                    	dec	al
  2955 00000E3F 75CF                    	jnz	short lff22s_1 ; 3:2:2:2:2 ; 7-11 of 17
  2956 00000E41 45                      	inc	bp ; 5
  2957 00000E42 EBCC                    	jmp	short lff22s_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  2958                                  
  2959                                  ;-----------------------------------------------------------------------------
  2960                                  
  2961                                  load_22khz_mono_16_bit:
  2962                                  	; 02/02/2025
  2963                                  	; 16/11/2023
  2964 00000E44 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  2965                                  					; last of the file?
  2966 00000E49 7402                    	jz	short lff22m2_0		; no
  2967 00000E4B F9                      	stc
  2968 00000E4C C3                      	retn
  2969                                  
  2970                                  lff22m2_0:
  2971 00000E4D 8EC0                    	mov	es, ax ; buffer segment
  2972 00000E4F 31FF                    	xor	di, di
  2973 00000E51 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  2974                                  	; ds = cs
  2975                                  
  2976                                  	; load file into memory
  2977 00000E54 8B0E[B876]                      mov	cx, [loadsize]
  2978 00000E58 8B1E[DF68]              	mov	bx, [FileHandle]
  2979 00000E5C B43F                           	mov	ah, 3Fh
  2980 00000E5E CD21                    	int	21h
  2981 00000E60 724B                    	jc	short lff22m2_7 ; error !
  2982                                  
  2983                                  	; 14/11/2024
  2984 00000E62 A3[BE76]                	mov	[count], ax
  2985                                  
  2986 00000E65 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  2987                                  	
  2988 00000E67 D1E8                    	shr	ax, 1
  2989                                  	;and	ax, ax
  2990 00000E69 7503                    	jnz	short lff22m2_8
  2991 00000E6B E985F7                  	jmp	lff22_eof
  2992                                  
  2993                                  lff22m2_8:
  2994 00000E6E 89C1                    	mov	cx, ax	; word count
  2995                                  lff22m2_9:
  2996 00000E70 BD0500                  	mov	bp, 5	; interpolation (one step) loop count
  2997 00000E73 C606[C017]03            	mov	byte [faz], 3  ; 3 steps/phases
  2998                                  lff22m2_1:
  2999                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  3000 00000E78 AD                      	lodsw
  3001                                  	; 02/02/2025
  3002 00000E79 8B14                    	mov	dx, [si]
  3003 00000E7B 49                      	dec	cx
  3004 00000E7C 7502                    	jnz	short lff22m2_2_1
  3005 00000E7E 31D2                    	xor	dx, dx
  3006                                  lff22m2_2_1:	
  3007                                  	; ax = [previous_val]
  3008                                  	; dx = [next_val]
  3009 00000E80 E8B505                  	call	interpolating_3_16bit_mono ; 1 of 17
  3010 00000E83 E325                    	jcxz	lff22m2_3
  3011                                  lff22m2_2_2:
  3012 00000E85 AD                      	lodsw
  3013                                  	; 02/02/2025
  3014 00000E86 8B14                    	mov	dx, [si]
  3015 00000E88 49                      	dec	cx
  3016 00000E89 7502                    	jnz	short lff22m2_2_3
  3017 00000E8B 31D2                    	xor	dx, dx
  3018                                  lff22m2_2_3:
  3019 00000E8D E81506                   	call	interpolating_2_16bit_mono ; 2 of 17 .. 6 of 17
  3020 00000E90 E318                    	jcxz	lff22m2_3
  3021 00000E92 4D                      	dec	bp
  3022 00000E93 75F0                    	jnz	short lff22m2_2_2
  3023                                  
  3024 00000E95 A0[C017]                	mov	al, [faz]
  3025 00000E98 FEC8                    	dec	al
  3026 00000E9A 74D4                    	jz	short lff22m2_9
  3027 00000E9C FE0E[C017]              	dec	byte [faz]
  3028 00000EA0 BD0400                  	mov	bp, 4
  3029 00000EA3 FEC8                    	dec	al
  3030 00000EA5 75D1                    	jnz	short lff22m2_1 ; 3:2:2:2:2 ; 7-11 of 17
  3031 00000EA7 45                      	inc	bp ; 5
  3032 00000EA8 EBCE                    	jmp	short lff22m2_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  3033                                  
  3034                                  lff22m2_3:
  3035                                  lff22s2_3:
  3036 00000EAA E933F7                  	jmp	lff22_3	; padfill
  3037                                  		; (put zeros in the remain words of the buffer)
  3038                                  lff22m2_7:
  3039                                  lff22s2_7:
  3040 00000EAD E94AF7                  	jmp	lff22_5  ; error
  3041                                  
  3042                                  ;-----------------------------------------------------------------------------
  3043                                  
  3044                                  load_22khz_stereo_16_bit:
  3045                                  	; 16/11/2023
  3046 00000EB0 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3047                                  					; last of the file?
  3048 00000EB5 7402                    	jz	short lff22s2_0		; no
  3049 00000EB7 F9                      	stc
  3050 00000EB8 C3                      	retn
  3051                                  
  3052                                  lff22s2_0:
  3053 00000EB9 8EC0                    	mov	es, ax ; buffer segment
  3054 00000EBB 31FF                    	xor	di, di
  3055 00000EBD BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3056                                  	; ds = cs
  3057                                  
  3058                                  	; load file into memory
  3059 00000EC0 8B0E[B876]                      mov	cx, [loadsize]
  3060 00000EC4 8B1E[DF68]              	mov	bx, [FileHandle]
  3061 00000EC8 B43F                           	mov	ah, 3Fh
  3062 00000ECA CD21                    	int	21h
  3063 00000ECC 72DF                    	jc	short lff22s2_7 ; error !
  3064                                  
  3065                                  	; 14/11/2024
  3066 00000ECE A3[BE76]                	mov	[count], ax
  3067                                  
  3068 00000ED1 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3069                                  	
  3070 00000ED3 C1E802                  	shr	ax, 2	; dword (left chan word + right chan word)
  3071                                  	;and	ax, ax
  3072 00000ED6 7503                    	jnz	short lff22s2_8
  3073 00000ED8 E918F7                  	jmp	lff22_eof
  3074                                  
  3075                                  lff22s2_8:
  3076 00000EDB 89C1                    	mov	cx, ax	; dword count
  3077                                  lff22s2_9:
  3078 00000EDD BD0500                  	mov	bp, 5	; interpolation (one step) loop count
  3079 00000EE0 C606[C017]03            	mov	byte [faz], 3  ; 3 steps/phase
  3080                                  lff22s2_1:
  3081                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  3082 00000EE5 AD                      	lodsw
  3083 00000EE6 89C3                    	mov	bx, ax
  3084 00000EE8 AD                      	lodsw
  3085 00000EE9 8B14                    	mov	dx, [si]
  3086 00000EEB 8916[BC17]              	mov	[next_val_l], dx
  3087 00000EEF 8B5402                  	mov	dx, [si+2]
  3088 00000EF2 49                      	dec	cx
  3089 00000EF3 7506                    	jnz	short lff22s2_2_1
  3090 00000EF5 31D2                    	xor	dx, dx ; 0
  3091 00000EF7 8916[BC17]              	mov	[next_val_l], dx
  3092                                  lff22s2_2_1:
  3093                                  	; bx = [previous_val_l]
  3094                                  	; ax = [previous_val_r]
  3095                                  	; [next_val_l]
  3096                                  	; dx = [next_val_r]
  3097 00000EFB E85E05                  	call	interpolating_3_16bit_stereo ; 1 of 17 
  3098 00000EFE E3AA                    	jcxz	lff22s2_3
  3099                                  lff22s2_2_2:
  3100 00000F00 AD                      	lodsw
  3101 00000F01 89C3                    	mov	bx, ax
  3102 00000F03 AD                      	lodsw
  3103 00000F04 8B14                    	mov	dx, [si]
  3104 00000F06 8916[BC17]              	mov	[next_val_l], dx
  3105 00000F0A 8B5402                  	mov	dx, [si+2]
  3106 00000F0D 49                      	dec	cx
  3107 00000F0E 7506                    	jnz	short lff22s2_2_3
  3108 00000F10 31D2                    	xor	dx, dx ; 0
  3109 00000F12 8916[BC17]              	mov	[next_val_l], dx
  3110                                  lff22s2_2_3:
  3111 00000F16 E89E05                   	call	interpolating_2_16bit_stereo ; 2 of 17 .. 6 of 17
  3112 00000F19 E38F                    	jcxz	lff22s2_3
  3113 00000F1B 4D                      	dec	bp
  3114 00000F1C 75E2                    	jnz	short lff22s2_2_2
  3115                                  
  3116 00000F1E A0[C017]                	mov	al, [faz]
  3117 00000F21 FEC8                    	dec	al
  3118 00000F23 74B8                    	jz	short lff22s2_9
  3119 00000F25 FE0E[C017]              	dec	byte [faz]
  3120 00000F29 BD0400                  	mov	bp, 4
  3121 00000F2C FEC8                    	dec	al
  3122 00000F2E 75B5                    	jnz	short lff22s2_1 ; 3:2:2:2:2 ; 7-11 of 17
  3123 00000F30 45                      	inc	bp ; 5
  3124 00000F31 EBB2                    	jmp	short lff22s2_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  3125                                  
  3126                                  ;-----------------------------------------------------------------------------
  3127                                  ;-----------------------------------------------------------------------------
  3128                                  
  3129                                  load_11khz_mono_8_bit:
  3130                                  	; 18/11/2023
  3131 00000F33 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3132                                  					; last of the file?
  3133 00000F38 7402                    	jz	short lff11m_0		; no
  3134 00000F3A F9                      	stc
  3135 00000F3B C3                      	retn
  3136                                  
  3137                                  lff11m_0:
  3138 00000F3C 8EC0                    	mov	es, ax ; buffer segment
  3139 00000F3E 31FF                    	xor	di, di
  3140 00000F40 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3141                                  	; ds = cs
  3142                                  
  3143                                  	; load file into memory
  3144 00000F43 8B0E[B876]                      mov	cx, [loadsize]
  3145 00000F47 8B1E[DF68]              	mov	bx, [FileHandle]
  3146 00000F4B B43F                           	mov	ah, 3Fh
  3147 00000F4D CD21                    	int	21h
  3148 00000F4F 7240                    	jc	short lff11m_7 ; error !
  3149                                  
  3150                                  	; 14/11/2024
  3151 00000F51 A3[BE76]                	mov	[count], ax
  3152                                  
  3153 00000F54 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3154                                  	
  3155 00000F56 21C0                    	and	ax, ax
  3156 00000F58 7503                    	jnz	short lff11m_8
  3157 00000F5A E996F6                  	jmp	lff11_eof
  3158                                  
  3159                                  lff11m_8:
  3160 00000F5D 89C1                    	mov	cx, ax	; byte count
  3161                                  lff11m_9:
  3162 00000F5F BD0600                  	mov	bp, 6	; interpolation (one step) loop count
  3163                                  lff11m_1:
  3164                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3165 00000F62 AC                      	lodsb
  3166                                  	; 02/02/2025
  3167 00000F63 8A14                    	mov	dl, [si]
  3168 00000F65 49                      	dec	cx
  3169 00000F66 7502                    	jnz	short lff11m_2_1
  3170 00000F68 B280                    	mov	dl, 80h
  3171                                  lff11m_2_1:	
  3172                                  	; al = [previous_val]
  3173                                  	; dl = [next_val]
  3174 00000F6A E87005                  	call	interpolating_5_8bit_mono
  3175 00000F6D E31F                    	jcxz	lff11m_3
  3176                                  lff11m_2_2:
  3177 00000F6F AC                      	lodsb
  3178                                  	; 02/02/2025
  3179 00000F70 8A14                    	mov	dl, [si]
  3180 00000F72 49                      	dec	cx
  3181 00000F73 7502                    	jnz	short lff11m_2_3
  3182 00000F75 B280                    	mov	dl, 80h
  3183                                  lff11m_2_3:
  3184 00000F77 E84C06                   	call	interpolating_4_8bit_mono
  3185 00000F7A E312                    	jcxz	lff11m_3
  3186                                  
  3187 00000F7C 4D                      	dec	bp
  3188 00000F7D 74E0                    	jz	short lff11m_9
  3189                                  
  3190 00000F7F AC                      	lodsb
  3191                                  	; 02/02/2025
  3192 00000F80 8A14                    	mov	dl, [si]
  3193 00000F82 49                      	dec	cx
  3194 00000F83 7502                    	jnz	short lff11m_2_4
  3195 00000F85 B280                    	mov	dl, 80h
  3196                                  lff11m_2_4:
  3197 00000F87 E83C06                  	call	interpolating_4_8bit_mono
  3198 00000F8A E302                    	jcxz	lff11m_3
  3199 00000F8C EBD4                    	jmp	short lff11m_1
  3200                                  
  3201                                  lff11m_3:
  3202                                  lff11s_3:
  3203 00000F8E E94FF6                  	jmp	lff11_3	; padfill
  3204                                  		; (put zeros in the remain words of the buffer)
  3205                                  lff11m_7:
  3206                                  lff11s_7:
  3207 00000F91 E966F6                  	jmp	lff11_5  ; error
  3208                                  
  3209                                  ;-----------------------------------------------------------------------------
  3210                                  
  3211                                  load_11khz_stereo_8_bit:
  3212                                  	; 02/02/2025
  3213                                  	; 18/11/2023
  3214 00000F94 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3215                                  					; last of the file?
  3216 00000F99 7402                    	jz	short lff11s_0		; no
  3217 00000F9B F9                      	stc
  3218 00000F9C C3                      	retn
  3219                                  
  3220                                  lff11s_0:
  3221 00000F9D 8EC0                    	mov	es, ax ; buffer segment
  3222 00000F9F 31FF                    	xor	di, di
  3223 00000FA1 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3224                                  	; ds = cs
  3225                                  
  3226                                  	; load file into memory
  3227 00000FA4 8B0E[B876]                      mov	cx, [loadsize]
  3228 00000FA8 8B1E[DF68]              	mov	bx, [FileHandle]
  3229 00000FAC B43F                           	mov	ah, 3Fh
  3230 00000FAE CD21                    	int	21h
  3231 00000FB0 72DF                    	jc	short lff11s_7 ; error !
  3232                                  
  3233                                  	; 14/11/2024
  3234 00000FB2 A3[BE76]                	mov	[count], ax
  3235                                  
  3236 00000FB5 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3237                                  	
  3238 00000FB7 D1E8                    	shr	ax, 1
  3239                                  	;and	ax, ax
  3240 00000FB9 7503                    	jnz	short lff11s_8
  3241 00000FBB E935F6                  	jmp	lff11_eof
  3242                                  
  3243                                  lff11s_8:
  3244 00000FBE 89C1                    	mov	cx, ax	; word count
  3245                                  lff11s_9:
  3246 00000FC0 BD0600                  	mov	bp, 6	; interpolation (one step) loop count
  3247                                  lff11s_1:
  3248                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3249 00000FC3 AD                      	lodsw
  3250                                  	; 02/02/2025
  3251 00000FC4 8B14                    	mov	dx, [si]
  3252 00000FC6 49                      	dec	cx
  3253 00000FC7 7503                    	jnz	short lff11s_2_1
  3254 00000FC9 BA8080                  	mov	dx, 8080h
  3255                                  lff11s_2_1:	
  3256                                  	; al = [previous_val_l]
  3257                                  	; ah = [previous_val_r]
  3258                                  	; dl = [next_val_l]
  3259                                  	; dl = [next_val_r]	
  3260 00000FCC E85E05                  	call	interpolating_5_8bit_stereo
  3261 00000FCF E3BD                    	jcxz	lff11s_3
  3262                                  lff11s_2_2:
  3263 00000FD1 AD                      	lodsw
  3264                                  	; 02/02/2025
  3265 00000FD2 8B14                    	mov	dx, [si]
  3266 00000FD4 49                      	dec	cx
  3267 00000FD5 7503                    	jnz	short lff11s_2_3
  3268 00000FD7 BA8080                  	mov	dx, 8080h
  3269                                  lff11s_2_3:
  3270 00000FDA E81C06                   	call	interpolating_4_8bit_stereo
  3271 00000FDD E3AF                    	jcxz	lff11s_3
  3272                                  	
  3273 00000FDF 4D                      	dec	bp
  3274 00000FE0 74DE                    	jz	short lff11s_9
  3275                                  
  3276 00000FE2 AD                      	lodsw
  3277                                  	; 02/02/2025
  3278 00000FE3 8B14                    	mov	dx, [si]
  3279 00000FE5 49                      	dec	cx
  3280 00000FE6 7503                    	jnz	short lff11s_2_4
  3281 00000FE8 BA8080                  	mov	dx, 8080h
  3282                                  lff11s_2_4:
  3283 00000FEB E80B06                  	call	interpolating_4_8bit_stereo
  3284 00000FEE E39E                    	jcxz	lff11s_3
  3285 00000FF0 EBD1                    	jmp	short lff11s_1
  3286                                  
  3287                                  ;-----------------------------------------------------------------------------
  3288                                  
  3289                                  load_11khz_mono_16_bit:
  3290                                  	; 02/02/2025
  3291                                  	; 18/11/2023
  3292 00000FF2 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3293                                  					; last of the file?
  3294 00000FF7 7402                    	jz	short lff11m2_0		; no
  3295 00000FF9 F9                      	stc
  3296 00000FFA C3                      	retn
  3297                                  
  3298                                  lff11m2_0:
  3299 00000FFB 8EC0                    	mov	es, ax ; buffer segment
  3300 00000FFD 31FF                    	xor	di, di
  3301 00000FFF BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3302                                  	; ds = cs
  3303                                  
  3304                                  	; load file into memory
  3305 00001002 8B0E[B876]                      mov	cx, [loadsize]
  3306 00001006 8B1E[DF68]              	mov	bx, [FileHandle]
  3307 0000100A B43F                           	mov	ah, 3Fh
  3308 0000100C CD21                    	int	21h
  3309 0000100E 723D                    	jc	short lff11m2_7 ; error !
  3310                                  
  3311                                  	; 14/11/2024
  3312 00001010 A3[BE76]                	mov	[count], ax
  3313                                  
  3314 00001013 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3315                                  	
  3316 00001015 D1E8                    	shr	ax, 1
  3317                                  	;and	ax, ax
  3318 00001017 7503                    	jnz	short lff11m2_8
  3319 00001019 E9D7F5                  	jmp	lff11_eof
  3320                                  
  3321                                  lff11m2_8:
  3322 0000101C 89C1                    	mov	cx, ax	; word count
  3323                                  lff11m2_9:
  3324 0000101E BD0600                  	mov	bp, 6	; interpolation (one step) loop count
  3325                                  lff11m2_1:
  3326                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3327 00001021 AD                      	lodsw
  3328                                  	; 02/02/2025
  3329 00001022 8B14                    	mov	dx, [si]
  3330 00001024 49                      	dec	cx
  3331 00001025 7502                    	jnz	short lff11m2_2_1
  3332 00001027 31D2                    	xor	dx, dx
  3333                                  lff11m2_2_1:	
  3334                                  	; ax = [previous_val]
  3335                                  	; dx = [next_val]
  3336 00001029 E82A06                  	call	interpolating_5_16bit_mono
  3337 0000102C E34D                    	jcxz	lff11m2_3
  3338                                  lff11m2_2_2:
  3339 0000102E AD                      	lodsw
  3340                                  	; 02/02/2025
  3341 0000102F 8B14                    	mov	dx, [si]
  3342 00001031 49                      	dec	cx
  3343 00001032 7502                    	jnz	short lff11m2_2_3
  3344 00001034 31D2                    	xor	dx, dx
  3345                                  lff11m2_2_3:
  3346 00001036 E8F806                   	call	interpolating_4_16bit_mono
  3347 00001039 E340                    	jcxz	lff11m2_3
  3348                                  
  3349 0000103B 4D                      	dec	bp
  3350 0000103C 74E0                    	jz	short lff11m2_9
  3351                                  
  3352 0000103E AD                      	lodsw
  3353                                  	; 02/02/2025
  3354 0000103F 8B14                    	mov	dx, [si]
  3355 00001041 49                      	dec	cx
  3356 00001042 7502                    	jnz	short lff11m2_2_4
  3357 00001044 31D2                    	xor	dx, dx
  3358                                  lff11m2_2_4:
  3359 00001046 E8E806                   	call	interpolating_4_16bit_mono
  3360 00001049 E330                    	jcxz	lff11m2_3
  3361 0000104B EBD4                    	jmp	short lff11m2_1
  3362                                  
  3363                                  lff11m2_7:
  3364                                  lff11s2_7:
  3365 0000104D E9AAF5                  	jmp	lff11_5  ; error
  3366                                  
  3367                                  ;-----------------------------------------------------------------------------
  3368                                  
  3369                                  load_11khz_stereo_16_bit:
  3370                                  	; 18/11/2023
  3371 00001050 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3372                                  					; last of the file?
  3373 00001055 7402                    	jz	short lff11s2_0		; no
  3374 00001057 F9                      	stc
  3375 00001058 C3                      	retn
  3376                                  
  3377                                  lff11s2_0:
  3378 00001059 8EC0                    	mov	es, ax ; buffer segment
  3379 0000105B 31FF                    	xor	di, di
  3380 0000105D BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3381                                  	; ds = cs
  3382                                  
  3383                                  	; load file into memory
  3384 00001060 8B0E[B876]                      mov	cx, [loadsize]
  3385 00001064 8B1E[DF68]              	mov	bx, [FileHandle]
  3386 00001068 B43F                           	mov	ah, 3Fh
  3387 0000106A CD21                    	int	21h
  3388 0000106C 72DF                    	jc	short lff11s2_7 ; error !
  3389                                  
  3390                                  	; 14/11/2024
  3391 0000106E A3[BE76]                	mov	[count], ax
  3392                                  
  3393 00001071 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3394                                  	
  3395 00001073 C1E802                  	shr	ax, 2	; dword (left chan word + right chan word)
  3396                                  	;and	ax, ax
  3397 00001076 7506                    	jnz	short lff11s2_8
  3398 00001078 E978F5                  	jmp	lff11_eof
  3399                                  
  3400                                  lff11m2_3:
  3401                                  lff11s2_3:
  3402 0000107B E962F5                  	jmp	lff11_3	; padfill
  3403                                  		; (put zeros in the remain words of the buffer)
  3404                                  
  3405                                  lff11s2_8:
  3406 0000107E 89C1                    	mov	cx, ax	; dword count
  3407                                  lff11s2_9:
  3408 00001080 BD0600                  	mov	bp, 6	; interpolation (one step) loop count
  3409                                  lff11s2_1:
  3410                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3411 00001083 AD                      	lodsw
  3412 00001084 89C3                    	mov	bx, ax
  3413 00001086 AD                      	lodsw
  3414 00001087 8B14                    	mov	dx, [si]
  3415 00001089 8916[BC17]              	mov	[next_val_l], dx
  3416 0000108D 8B5402                  	mov	dx, [si+2]
  3417 00001090 8916[BE17]              	mov	[next_val_r], dx
  3418 00001094 49                      	dec	cx
  3419 00001095 750A                    	jnz	short lff11s2_2_1
  3420 00001097 31D2                    	xor	dx, dx ; 0
  3421 00001099 8916[BC17]              	mov	[next_val_l], dx
  3422 0000109D 8916[BE17]              	mov	[next_val_r], dx
  3423                                  lff11s2_2_1:
  3424                                  	; bx = [previous_val_l]
  3425                                  	; ax = [previous_val_r]
  3426                                  	; [next_val_l]
  3427                                  	; dx = [next_val_r]
  3428 000010A1 E8F505                  	call	interpolating_5_16bit_stereo
  3429 000010A4 E3D5                    	jcxz	lff11s2_3
  3430                                  lff11s2_2_2:
  3431 000010A6 AD                      	lodsw
  3432 000010A7 89C3                    	mov	bx, ax
  3433 000010A9 AD                      	lodsw
  3434 000010AA 8B14                    	mov	dx, [si]
  3435 000010AC 8916[BC17]              	mov	[next_val_l], dx
  3436 000010B0 8B5402                  	mov	dx, [si+2]
  3437 000010B3 8916[BE17]              	mov	[next_val_r], dx
  3438 000010B7 49                      	dec	cx
  3439 000010B8 750A                    	jnz	short lff11s2_2_3
  3440 000010BA 31D2                    	xor	dx, dx ; 0
  3441 000010BC 8916[BC17]              	mov	[next_val_l], dx
  3442 000010C0 8916[BE17]              	mov	[next_val_r], dx
  3443                                  lff11s2_2_3:
  3444 000010C4 E89506                   	call	interpolating_4_16bit_stereo
  3445 000010C7 E3B2                    	jcxz	lff11s2_3
  3446                                  	
  3447 000010C9 4D                      	dec	bp
  3448 000010CA 74B4                    	jz	short lff11s2_9
  3449                                  
  3450 000010CC AD                      	lodsw
  3451 000010CD 89C3                    	mov	bx, ax
  3452 000010CF AD                      	lodsw
  3453 000010D0 8B14                    	mov	dx, [si]
  3454 000010D2 8916[BC17]              	mov	[next_val_l], dx
  3455 000010D6 8B5402                  	mov	dx, [si+2]
  3456 000010D9 8916[BE17]              	mov	[next_val_r], dx
  3457 000010DD 49                      	dec	cx
  3458 000010DE 750A                    	jnz	short lff11s2_2_4
  3459 000010E0 31D2                    	xor	dx, dx ; 0
  3460 000010E2 8916[BC17]              	mov	[next_val_l], dx
  3461 000010E6 8916[BE17]              	mov	[next_val_r], dx
  3462                                  lff11s2_2_4:
  3463 000010EA E86F06                   	call	interpolating_4_16bit_stereo
  3464 000010ED E38C                    	jcxz	lff11s2_3
  3465 000010EF EB92                    	jmp	short lff11s2_1
  3466                                  
  3467                                  ;-----------------------------------------------------------------------------
  3468                                  ;-----------------------------------------------------------------------------
  3469                                  
  3470                                  load_44khz_mono_8_bit:
  3471                                  	; 02/02/2025
  3472                                  	; 18/11/2023
  3473 000010F1 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3474                                  					; last of the file?
  3475 000010F6 7402                    	jz	short lff44m_0		; no
  3476 000010F8 F9                      	stc
  3477 000010F9 C3                      	retn
  3478                                  
  3479                                  lff44m_0:
  3480 000010FA 8EC0                    	mov	es, ax ; buffer segment
  3481 000010FC 31FF                    	xor	di, di
  3482 000010FE BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3483                                  	; ds = cs
  3484                                  
  3485                                  	; load file into memory
  3486 00001101 8B0E[B876]                      mov	cx, [loadsize]
  3487 00001105 8B1E[DF68]              	mov	bx, [FileHandle]
  3488 00001109 B43F                           	mov	ah, 3Fh
  3489 0000110B CD21                    	int	21h
  3490 0000110D 723F                    	jc	short lff44m_7 ; error !
  3491                                  
  3492                                  	; 14/11/2024
  3493 0000110F A3[BE76]                	mov	[count], ax
  3494                                  
  3495 00001112 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3496                                  	
  3497 00001114 21C0                    	and	ax, ax
  3498 00001116 7503                    	jnz	short lff44m_8
  3499 00001118 E9D8F4                  	jmp	lff44_eof
  3500                                  
  3501                                  lff44m_8:
  3502 0000111B 89C1                    	mov	cx, ax	; byte count
  3503                                  lff44m_9:
  3504 0000111D BD0A00                  	mov	bp, 10	; interpolation (one step) loop count
  3505 00001120 C606[C017]02            	mov	byte [faz], 2  ; 2 steps/phases
  3506                                  lff44m_1:
  3507                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3508                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3509 00001125 AC                      	lodsb
  3510                                  	; 02/02/2025
  3511 00001126 8A14                    	mov	dl, [si]
  3512 00001128 49                      	dec	cx
  3513 00001129 7502                    	jnz	short lff44m_2_1
  3514 0000112B B280                    	mov	dl, 80h
  3515                                  lff44m_2_1:	
  3516                                  	; al = [previous_val]
  3517                                  	; dl = [next_val]
  3518 0000112D E8C802                  	call	interpolating_2_8bit_mono
  3519 00001130 E319                    	jcxz	lff44m_3
  3520                                  lff44m_2_2:
  3521 00001132 AC                      	lodsb
  3522 00001133 2C80                    	sub	al, 80h
  3523 00001135 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3524 00001138 AB                      	stosw		; (L)
  3525 00001139 AB                      	stosw		; (R)	
  3526                                  
  3527 0000113A 49                      	dec	cx
  3528 0000113B 740E                    	jz	short lff44m_3	
  3529 0000113D 4D                      	dec	bp
  3530 0000113E 75F2                    	jnz	short lff44m_2_2
  3531                                  	
  3532 00001140 FE0E[C017]              	dec	byte [faz]
  3533 00001144 74D7                    	jz	short lff44m_9 
  3534 00001146 BD0B00                  	mov	bp, 11
  3535 00001149 EBDA                    	jmp	short lff44m_1
  3536                                  
  3537                                  lff44m_3:
  3538                                  lff44s_3:
  3539 0000114B E992F4                  	jmp	lff44_3	; padfill
  3540                                  		; (put zeros in the remain words of the buffer)
  3541                                  lff44m_7:
  3542                                  lff44s_7:
  3543 0000114E E9A9F4                  	jmp	lff44_5  ; error
  3544                                  
  3545                                  ;-----------------------------------------------------------------------------
  3546                                  
  3547                                  load_44khz_stereo_8_bit:
  3548                                  	; 02/02/2025
  3549                                  	; 16/11/2023
  3550 00001151 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3551                                  					; last of the file?
  3552 00001156 7402                    	jz	short lff44s_0		; no
  3553 00001158 F9                      	stc
  3554 00001159 C3                      	retn
  3555                                  
  3556                                  lff44s_0:
  3557 0000115A 8EC0                    	mov	es, ax ; buffer segment
  3558 0000115C 31FF                    	xor	di, di
  3559 0000115E BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3560                                  	; ds = cs
  3561                                  
  3562                                  	; load file into memory
  3563 00001161 8B0E[B876]                      mov	cx, [loadsize]
  3564 00001165 8B1E[DF68]              	mov	bx, [FileHandle]
  3565 00001169 B43F                           	mov	ah, 3Fh
  3566 0000116B CD21                    	int	21h
  3567 0000116D 72DF                    	jc	short lff44s_7 ; error !
  3568                                  
  3569                                  	; 14/11/2024
  3570 0000116F A3[BE76]                	mov	[count], ax
  3571                                  
  3572 00001172 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3573                                  	
  3574 00001174 D1E8                    	shr	ax, 1
  3575                                  	;and	ax, ax
  3576 00001176 7503                    	jnz	short lff44s_8
  3577 00001178 E978F4                  	jmp	lff44_eof
  3578                                  
  3579                                  lff44s_8:
  3580 0000117B 89C1                    	mov	cx, ax	; word count
  3581                                  lff44s_9:
  3582 0000117D BD0A00                  	mov	bp, 10	; interpolation (one step) loop count
  3583 00001180 C606[C017]02            	mov	byte [faz], 2  ; 2 steps/phase
  3584                                  lff44s_1:
  3585                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3586                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3587 00001185 AD                      	lodsw
  3588                                  	; 02/02/2025
  3589 00001186 8B14                    	mov	dx, [si]
  3590 00001188 49                      	dec	cx
  3591 00001189 7503                    	jnz	short lff44s_2_1
  3592 0000118B BA8080                  	mov	dx, 8080h
  3593                                  lff44s_2_1:	
  3594                                  	; al = [previous_val_l]
  3595                                  	; ah = [previous_val_r]
  3596                                  	; dl = [next_val_l]
  3597                                  	; dl = [next_val_r]	
  3598 0000118E E87E02                  	call	interpolating_2_8bit_stereo
  3599 00001191 E3B8                    	jcxz	lff44s_3
  3600                                  lff44s_2_2:
  3601 00001193 AC                      	lodsb
  3602 00001194 2C80                    	sub	al, 80h
  3603 00001196 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3604 00001199 AB                      	stosw		; (L)
  3605 0000119A AC                      	lodsb
  3606 0000119B 2C80                    	sub	al, 80h
  3607 0000119D C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3608 000011A0 AB                      	stosw		; (R)
  3609                                  
  3610 000011A1 49                      	dec	cx
  3611 000011A2 74A7                    	jz	short lff44s_3	
  3612 000011A4 4D                      	dec	bp
  3613 000011A5 75EC                    	jnz	short lff44s_2_2
  3614                                  	
  3615 000011A7 FE0E[C017]              	dec	byte [faz]
  3616 000011AB 74D0                    	jz	short lff44s_9 
  3617 000011AD BD0B00                  	mov	bp, 11
  3618 000011B0 EBD3                    	jmp	short lff44s_1
  3619                                  
  3620                                  ;-----------------------------------------------------------------------------
  3621                                  
  3622                                  load_44khz_mono_16_bit:
  3623                                  	; 02/02/2025
  3624                                  	; 18/11/2023
  3625 000011B2 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3626                                  					; last of the file?
  3627 000011B7 7402                    	jz	short lff44m2_0		; no
  3628 000011B9 F9                      	stc
  3629 000011BA C3                      	retn
  3630                                  
  3631                                  lff44m2_0:
  3632 000011BB 8EC0                    	mov	es, ax ; buffer segment
  3633 000011BD 31FF                    	xor	di, di
  3634 000011BF BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3635                                  	; ds = cs
  3636                                  
  3637                                  	; load file into memory
  3638 000011C2 8B0E[B876]                      mov	cx, [loadsize]
  3639 000011C6 8B1E[DF68]              	mov	bx, [FileHandle]
  3640 000011CA B43F                           	mov	ah, 3Fh
  3641 000011CC CD21                    	int	21h
  3642 000011CE 723A                    	jc	short lff44m2_7 ; error !
  3643                                  
  3644                                  	; 14/11/2024
  3645 000011D0 A3[BE76]                	mov	[count], ax
  3646                                  
  3647 000011D3 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3648                                  	
  3649 000011D5 D1E8                    	shr	ax, 1
  3650                                  	;and	ax, ax
  3651 000011D7 7503                    	jnz	short lff44m2_8
  3652 000011D9 E917F4                  	jmp	lff44_eof
  3653                                  
  3654                                  lff44m2_8:
  3655 000011DC 89C1                    	mov	cx, ax	; word count
  3656                                  lff44m2_9:
  3657 000011DE BD0A00                  	mov	bp, 10	; interpolation (one step) loop count
  3658 000011E1 C606[C017]02            	mov	byte [faz], 2  ; 2 steps/phases
  3659                                  lff44m2_1:
  3660                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3661                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3662 000011E6 AD                      	lodsw
  3663                                  	; 02/02/2025
  3664 000011E7 8B14                    	mov	dx, [si]
  3665 000011E9 49                      	dec	cx
  3666 000011EA 7502                    	jnz	short lff44m2_2_1
  3667 000011EC 31D2                    	xor	dx, dx
  3668                                  lff44m2_2_1:	
  3669                                  	; ax = [previous_val]
  3670                                  	; dx = [next_val]
  3671 000011EE E8B402                  	call	interpolating_2_16bit_mono
  3672 000011F1 E314                    	jcxz	lff44m2_3
  3673                                  lff44m2_2_2:
  3674 000011F3 AD                      	lodsw
  3675 000011F4 AB                      	stosw		; (L)eft Channel
  3676 000011F5 AB                      	stosw		; (R)ight Channel
  3677                                  
  3678 000011F6 49                      	dec	cx
  3679 000011F7 740E                    	jz	short lff44m2_3	
  3680 000011F9 4D                      	dec	bp
  3681 000011FA 75F7                    	jnz	short lff44m2_2_2
  3682                                  	
  3683 000011FC FE0E[C017]              	dec	byte [faz]
  3684 00001200 74DC                    	jz	short lff44m2_9 
  3685 00001202 BD0B00                  	mov	bp, 11
  3686 00001205 EBDF                    	jmp	short lff44m2_1
  3687                                  
  3688                                  lff44m2_3:
  3689                                  lff44s2_3:
  3690 00001207 E9D6F3                  	jmp	lff44_3	; padfill
  3691                                  		; (put zeros in the remain words of the buffer)
  3692                                  lff44m2_7:
  3693                                  lff44s2_7:
  3694 0000120A E9EDF3                  	jmp	lff44_5  ; error
  3695                                  
  3696                                  ;-----------------------------------------------------------------------------
  3697                                  
  3698                                  load_44khz_stereo_16_bit:
  3699                                  	; 18/11/2023
  3700 0000120D F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3701                                  					; last of the file?
  3702 00001212 7402                    	jz	short lff44s2_0		; no
  3703 00001214 F9                      	stc
  3704 00001215 C3                      	retn
  3705                                  
  3706                                  lff44s2_0:
  3707 00001216 8EC0                    	mov	es, ax ; buffer segment
  3708 00001218 31FF                    	xor	di, di
  3709 0000121A BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3710                                  	; ds = cs
  3711                                  
  3712                                  	; load file into memory
  3713 0000121D 8B0E[B876]                      mov	cx, [loadsize]
  3714 00001221 8B1E[DF68]              	mov	bx, [FileHandle]
  3715 00001225 B43F                           	mov	ah, 3Fh
  3716 00001227 CD21                    	int	21h
  3717 00001229 72DF                    	jc	short lff44s2_7 ; error !
  3718                                  
  3719                                  	; 14/11/2024
  3720 0000122B A3[BE76]                	mov	[count], ax
  3721                                  
  3722 0000122E 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3723                                  	
  3724 00001230 C1E802                  	shr	ax, 2	; dword (left chan word + right chan word)
  3725                                  	;and	ax, ax
  3726 00001233 7503                    	jnz	short lff44s2_8
  3727 00001235 E9BBF3                  	jmp	lff44_eof
  3728                                  
  3729                                  lff44s2_8:
  3730 00001238 89C1                    	mov	cx, ax	; dword count
  3731                                  lff44s2_9:
  3732 0000123A BD0A00                  	mov	bp, 10	; interpolation (one step) loop count
  3733 0000123D C606[C017]02            	mov	byte [faz], 2  ; 2 steps/phase
  3734                                  lff44s2_1:
  3735                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3736                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3737 00001242 AD                      	lodsw
  3738 00001243 89C3                    	mov	bx, ax
  3739 00001245 AD                      	lodsw
  3740 00001246 8B14                    	mov	dx, [si]
  3741 00001248 8916[BC17]              	mov	[next_val_l], dx
  3742 0000124C 8B5402                  	mov	dx, [si+2]
  3743 0000124F 49                      	dec	cx
  3744 00001250 7506                    	jnz	short lff44s2_2_1
  3745 00001252 31D2                    	xor	dx, dx ; 0
  3746 00001254 8916[BC17]              	mov	[next_val_l], dx
  3747                                  lff44s2_2_1:
  3748                                  	; bx = [previous_val_l]
  3749                                  	; ax = [previous_val_r]
  3750                                  	; [next_val_l]
  3751                                  	; dx = [next_val_r]
  3752 00001258 E85C02                  	call	interpolating_2_16bit_stereo
  3753 0000125B E3AA                    	jcxz	lff44s2_3
  3754                                  lff44s2_2_2:
  3755                                  	;lodsw
  3756                                  	;stosw		; (L)
  3757                                  	;lodsw
  3758                                  	;stosw		; (R)
  3759 0000125D A5                      	movsw		; (L)eft Channel
  3760 0000125E A5                      	movsw		; (R)ight Channel
  3761                                  
  3762 0000125F 49                      	dec	cx
  3763 00001260 74A5                    	jz	short lff44s2_3	
  3764 00001262 4D                      	dec	bp
  3765 00001263 75F8                    	jnz	short lff44s2_2_2
  3766                                  	
  3767 00001265 FE0E[C017]              	dec	byte [faz]
  3768 00001269 74CF                    	jz	short lff44s2_9 
  3769 0000126B BD0B00                  	mov	bp, 11
  3770 0000126E EBD2                    	jmp	short lff44s2_1
  3771                                  
  3772                                  ;-----------------------------------------------------------------------------
  3773                                  ;-----------------------------------------------------------------------------
  3774                                  
  3775                                  	; 02/02/2025
  3776                                  load_12khz_mono_8_bit:
  3777 00001270 F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3778                                  					; last of the file?
  3779 00001275 7402                    	jz	short lff12m_0		; no
  3780 00001277 F9                      	stc
  3781 00001278 C3                      	retn
  3782                                  
  3783                                  lff12m_0:
  3784 00001279 8EC0                    	mov	es, ax ; buffer segment
  3785 0000127B 31FF                    	xor	di, di
  3786 0000127D BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3787                                  	; ds = cs
  3788                                  
  3789                                  	; load file into memory
  3790 00001280 8B0E[B876]                      mov	cx, [loadsize]
  3791 00001284 8B1E[DF68]              	mov	bx, [FileHandle]
  3792 00001288 B43F                           	mov	ah, 3Fh
  3793 0000128A CD21                    	int	21h
  3794 0000128C 7247                    	jc	short lff12m_7 ; error !
  3795                                  
  3796                                  	; 02/02/2025
  3797 0000128E A3[BE76]                	mov	[count], ax
  3798                                  
  3799 00001291 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3800                                  
  3801 00001293 21C0                    	and	ax, ax
  3802 00001295 7503                    	jnz	short lff12m_8
  3803 00001297 E959F3                  	jmp	lff12_eof
  3804                                  
  3805                                  lff12m_8:
  3806 0000129A 89C1                    	mov	cx, ax	; byte count
  3807                                  lff12m_1:
  3808                                  	; original-interpolated-interpolated-interpolated
  3809 0000129C AC                      	lodsb
  3810                                  	; 02/02/2025
  3811 0000129D 8A14                    	mov	dl, [si]
  3812 0000129F 49                      	dec	cx
  3813 000012A0 7502                    	jnz	short lff12m_2
  3814 000012A2 B280                    	mov	dl, 80h
  3815                                  lff12m_2:	
  3816                                  	; al = [previous_val]
  3817                                  	; dl = [next_val]
  3818 000012A4 E81F03                   	call	interpolating_4_8bit_mono
  3819 000012A7 E342                    	jcxz	lff12m_3
  3820 000012A9 EBF1                    	jmp	short lff12m_1
  3821                                  
  3822                                  ;-----------------------------------------------------------------------------
  3823                                  
  3824                                  	; 02/02/2025
  3825                                  load_12khz_stereo_8_bit:
  3826 000012AB F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3827                                  					; last of the file?
  3828 000012B0 7402                    	jz	short lff12s_0		; no
  3829 000012B2 F9                      	stc
  3830 000012B3 C3                      	retn
  3831                                  
  3832                                  lff12s_0:
  3833 000012B4 8EC0                    	mov	es, ax ; buffer segment
  3834 000012B6 31FF                    	xor	di, di
  3835 000012B8 BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3836                                  	; ds = cs
  3837                                  
  3838                                  	; load file into memory
  3839 000012BB 8B0E[B876]                      mov	cx, [loadsize]
  3840 000012BF 8B1E[DF68]              	mov	bx, [FileHandle]
  3841 000012C3 B43F                           	mov	ah, 3Fh
  3842 000012C5 CD21                    	int	21h
  3843 000012C7 720C                    	jc	short lff12s_7 ; error !
  3844                                  
  3845                                  	; 02/02/2025
  3846 000012C9 A3[BE76]                	mov	[count], ax
  3847                                  
  3848 000012CC 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3849                                  	
  3850 000012CE D1E8                    	shr	ax, 1
  3851                                  	;and	ax, ax
  3852 000012D0 7506                    	jnz	short lff12s_8
  3853 000012D2 E91EF3                  	jmp	lff12_eof
  3854                                  
  3855                                  lff12m_7:
  3856                                  lff12s_7:
  3857 000012D5 E922F3                  	jmp	lff12_5  ; error
  3858                                  
  3859                                  lff12s_8:
  3860 000012D8 89C1                    	mov	cx, ax	; word count
  3861                                  lff12s_1:
  3862                                  	; original-interpolated-interpolated-interpolated
  3863 000012DA AD                      	lodsw
  3864                                  	; 02/02/2025
  3865 000012DB 8B14                    	mov	dx, [si]
  3866 000012DD 49                      	dec	cx
  3867 000012DE 7503                    	jnz	short lff12s_2
  3868 000012E0 BA8080                  	mov	dx, 8080h
  3869                                  lff12s_2:	
  3870                                  	; al = [previous_val_l]
  3871                                  	; ah = [previous_val_r]
  3872                                  	; dl = [next_val_l]
  3873                                  	; dh = [next_val_r]
  3874 000012E3 E81303                  	call	interpolating_4_8bit_stereo
  3875 000012E6 67E302                  	jecxz	lff12s_3
  3876 000012E9 EBEF                    	jmp	short lff12s_1
  3877                                  
  3878                                  lff12m_3:
  3879                                  lff12s_3:
  3880 000012EB E9F2F2                  	jmp	lff12_3	; padfill
  3881                                  		; (put zeros in the remain words of the buffer)
  3882                                  
  3883                                  ;-----------------------------------------------------------------------------
  3884                                  
  3885                                  	; 02/02/2025
  3886                                  load_12khz_mono_16_bit:
  3887 000012EE F606[9D6C]01            	test    byte [flags], ENDOFFILE	; have we already read the
  3888                                  					; last of the file?
  3889 000012F3 7402                    	jz	short lff12m2_0		; no
  3890 000012F5 F9                      	stc
  3891 000012F6 C3                      	retn
  3892                                  
  3893                                  lff12m2_0:
  3894 000012F7 8EC0                    	mov	es, ax ; buffer segment
  3895 000012F9 31FF                    	xor	di, di
  3896 000012FB BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3897                                  	; ds = cs
  3898                                  
  3899                                  	; load file into memory
  3900 000012FE 8B0E[B876]                      mov	cx, [loadsize]
  3901 00001302 8B1E[DF68]              	mov	bx, [FileHandle]
  3902 00001306 B43F                           	mov	ah, 3Fh
  3903 00001308 CD21                    	int	21h
  3904 0000130A 721E                    	jc	short lff12m2_7 ; error !
  3905                                  
  3906                                  	; 02/02/2025
  3907 0000130C A3[BE76]                	mov	[count], ax
  3908                                  
  3909 0000130F 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3910                                  	
  3911 00001311 D1E8                    	shr	ax, 1
  3912                                  	;and	ax, ax
  3913 00001313 7503                    	jnz	short lff12m2_8
  3914 00001315 E9DBF2                  	jmp	lff12_eof
  3915                                  
  3916                                  lff12m2_8:
  3917 00001318 89C1                    	mov	cx, ax	; word count
  3918                                  lff12m2_1:
  3919                                  	; original-interpolated-interpolated-interpolated
  3920 0000131A AD                      	lodsw
  3921                                  	; 02/02/2025
  3922 0000131B 8B14                    	mov	dx, [si]
  3923 0000131D 49                      	dec	cx
  3924 0000131E 7502                    	jnz	short lff12m2_2
  3925 00001320 31D2                    	xor	dx, dx
  3926                                  lff12m2_2:	
  3927                                  	; ax = [previous_val]
  3928                                  	; dx = [next_val]
  3929 00001322 E80C04                   	call	interpolating_4_16bit_mono
  3930 00001325 67E3C3                  	jecxz	lff12m_3
  3931 00001328 EBF0                    	jmp	short lff12m2_1
  3932                                  
  3933                                  lff12m2_7:
  3934                                  lff12s2_7:
  3935 0000132A E9CDF2                  	jmp	lff12_5  ; error
  3936                                  
  3937                                  ;-----------------------------------------------------------------------------
  3938                                  
  3939                                  	; 02/02/2025
  3940                                  load_12khz_stereo_16_bit:
  3941 0000132D F606[9D6C]01                    test    byte [flags], ENDOFFILE	; have we already read the
  3942                                  					; last of the file?
  3943 00001332 7402                    	jz	short lff12s2_0		; no
  3944 00001334 F9                      	stc
  3945 00001335 C3                      	retn
  3946                                  
  3947                                  lff12s2_0:
  3948 00001336 8EC0                    	mov	es, ax ; buffer segment
  3949 00001338 31FF                    	xor	di, di
  3950 0000133A BA[D07A]                	mov	dx, temp_buffer ; temporary buffer for wav data
  3951                                  	; ds = cs
  3952                                  
  3953                                  	; load file into memory
  3954 0000133D 8B0E[B876]                      mov	cx, [loadsize]
  3955 00001341 8B1E[DF68]              	mov	bx, [FileHandle]
  3956 00001345 B43F                           	mov	ah, 3Fh
  3957 00001347 CD21                    	int	21h
  3958 00001349 72DF                    	jc	short lff12s2_7 ; error !
  3959                                  
  3960                                  	; 02/02/2025
  3961 0000134B A3[BE76]                	mov	[count], ax
  3962                                  
  3963 0000134E 89D6                    	mov	si, dx ; temp_buffer ; temporary buffer address
  3964                                  	
  3965 00001350 C1E802                  	shr	ax, 2	; dword (left chan word + right chan word)
  3966                                  	;and	ax, ax
  3967 00001353 7506                    	jnz	short lff12s2_8
  3968 00001355 E99BF2                  	jmp	lff12_eof
  3969                                  
  3970                                  lff12m2_3:
  3971                                  lff12s2_3:
  3972 00001358 E985F2                  	jmp	lff12_3	; padfill
  3973                                  		; (put zeros in the remain words of the buffer)
  3974                                  
  3975                                  lff12s2_8:
  3976 0000135B 89C1                    	mov	cx, ax	; dword count
  3977                                  lff12s2_1:
  3978                                  	; original-interpolated-interpolated-interpolated
  3979 0000135D AD                      	lodsw
  3980 0000135E 89C3                    	mov	bx, ax
  3981 00001360 AD                      	lodsw
  3982                                  	; 02/02/2025
  3983 00001361 8B14                    	mov	dx, [si]
  3984 00001363 8916[BC17]              	mov	[next_val_l], dx
  3985 00001367 8B5402                  	mov	dx, [si+2]
  3986 0000136A 8916[BE17]              	mov	[next_val_r], dx
  3987 0000136E 49                      	dec	cx
  3988 0000136F 750A                    	jnz	short lff12s2_2
  3989 00001371 31D2                    	xor	dx, dx ; 0
  3990 00001373 8916[BC17]              	mov	[next_val_l], dx
  3991 00001377 8916[BE17]              	mov	[next_val_r], dx
  3992                                  lff12s2_2:
  3993                                  	; bx = [previous_val_l]
  3994                                  	; ax = [previous_val_r]
  3995                                  	; [next_val_l]
  3996                                  	; [next_val_r]
  3997 0000137B E8DE03                  	call	interpolating_4_16bit_stereo
  3998 0000137E 67E3D7                  	jecxz	lff12s2_3
  3999 00001381 EBDA                    	jmp	short lff12s2_1
  4000                                  
  4001                                  ;-----------------------------------------------------------------------------
  4002                                  ;-----------------------------------------------------------------------------
  4003                                  
  4004                                  interpolating_3_8bit_mono:
  4005                                  	; 02/02/2025
  4006                                  	; 16/11/2023
  4007                                  	; al = [previous_val]
  4008                                  	; dl = [next_val]
  4009                                  	; original-interpolated-interpolated
  4010 00001383 88C3                    	mov	bl, al
  4011 00001385 2C80                    	sub	al, 80h
  4012 00001387 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4013 0000138A AB                      	stosw		; original sample (L)
  4014 0000138B AB                      	stosw		; original sample (R)
  4015 0000138C 88D8                    	mov	al, bl
  4016 0000138E 00D0                    	add	al, dl
  4017 00001390 D0D8                    	rcr	al, 1
  4018 00001392 88C7                    	mov	bh, al	; interpolated middle (temporary)
  4019 00001394 00D8                    	add	al, bl
  4020 00001396 D0D8                    	rcr	al, 1
  4021 00001398 2C80                    	sub	al, 80h
  4022 0000139A C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4023 0000139D AB                      	stosw		; interpolated sample 1 (L)
  4024 0000139E AB                      	stosw		; interpolated sample 1 (R)
  4025 0000139F 88F8                    	mov	al, bh
  4026 000013A1 00D0                    	add	al, dl	; [next_val]
  4027 000013A3 D0D8                    	rcr	al, 1
  4028                                  	; 02/02/2025
  4029 000013A5 2C80                    	sub	al, 80h
  4030 000013A7 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4031 000013AA AB                      	stosw		; interpolated sample 2 (L)
  4032 000013AB AB                      	stosw		; interpolated sample 2 (R)
  4033 000013AC C3                      	retn
  4034                                  
  4035                                  ;-----------------------------------------------------------------------------
  4036                                  
  4037                                  interpolating_3_8bit_stereo:
  4038                                  	; 02/02/2025
  4039                                  	; 16/11/2023
  4040                                  	; al = [previous_val_l]
  4041                                  	; ah = [previous_val_r]
  4042                                  	; dl = [next_val_l]
  4043                                  	; dh = [next_val_r]
  4044                                  	; original-interpolated-interpolated
  4045 000013AD 89C3                    	mov	bx, ax
  4046 000013AF 2C80                    	sub	al, 80h
  4047 000013B1 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4048 000013B4 AB                      	stosw		; original sample (L)
  4049 000013B5 88F8                    	mov	al, bh
  4050 000013B7 2C80                    	sub	al, 80h
  4051 000013B9 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4052 000013BC AB                      	stosw		; original sample (R)
  4053 000013BD 88D8                    	mov	al, bl
  4054 000013BF 00D0                    	add	al, dl	; [next_val_l]
  4055 000013C1 D0D8                    	rcr	al, 1
  4056 000013C3 50                      	push	ax ; *	; al = interpolated middle (L) (temporary)
  4057 000013C4 00D8                    	add	al, bl	; [previous_val_l]
  4058 000013C6 D0D8                    	rcr	al, 1
  4059 000013C8 2C80                    	sub	al, 80h
  4060 000013CA C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4061 000013CD AB                      	stosw		; interpolated sample 1 (L)
  4062 000013CE 88F8                    	mov	al, bh
  4063 000013D0 00F0                    	add	al, dh	; [next_val_r]
  4064 000013D2 D0D8                    	rcr	al, 1
  4065 000013D4 50                      	push	ax ; ** ; al = interpolated middle (R) (temporary)
  4066 000013D5 00F8                    	add	al, bh	; [previous_val_r]
  4067 000013D7 D0D8                    	rcr	al, 1
  4068 000013D9 2C80                    	sub	al, 80h
  4069 000013DB C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4070 000013DE AB                      	stosw		; interpolated sample 1 (R)
  4071 000013DF 5B                      	pop	bx ; **
  4072 000013E0 58                      	pop	ax ; *
  4073 000013E1 00D0                    	add	al, dl	; [next_val_l]
  4074 000013E3 D0D8                    	rcr	al, 1
  4075                                  	; 02/02/2025
  4076 000013E5 2C80                    	sub	al, 80h
  4077 000013E7 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4078 000013EA AB                      	stosw		; interpolated sample 2 (L)
  4079 000013EB 88D8                    	mov	al, bl
  4080 000013ED 00F0                    	add	al, dh	; [next_val_r]
  4081 000013EF D0D8                    	rcr	al, 1
  4082                                  	; 02/02/2025
  4083 000013F1 2C80                    	sub	al, 80h
  4084 000013F3 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4085 000013F6 AB                      	stosw		; interpolated sample 2 (R)
  4086 000013F7 C3                      	retn
  4087                                  
  4088                                  ;-----------------------------------------------------------------------------
  4089                                  
  4090                                  interpolating_2_8bit_mono:
  4091                                  	; 16/11/2023
  4092                                  	; al = [previous_val]
  4093                                  	; dl = [next_val]
  4094                                  	; original-interpolated
  4095 000013F8 88C3                    	mov	bl, al
  4096 000013FA 2C80                    	sub	al, 80h
  4097 000013FC C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4098 000013FF AB                      	stosw		; original sample (L)
  4099 00001400 AB                      	stosw		; original sample (R)
  4100 00001401 88D8                    	mov	al, bl
  4101 00001403 00D0                    	add	al, dl
  4102 00001405 D0D8                    	rcr	al, 1
  4103 00001407 2C80                    	sub	al, 80h
  4104 00001409 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4105 0000140C AB                      	stosw		; interpolated sample (L)
  4106 0000140D AB                      	stosw		; interpolated sample (R)
  4107 0000140E C3                      	retn
  4108                                  
  4109                                  ;-----------------------------------------------------------------------------
  4110                                  
  4111                                  interpolating_2_8bit_stereo:
  4112                                  	; 16/11/2023
  4113                                  	; al = [previous_val_l]
  4114                                  	; ah = [previous_val_r]
  4115                                  	; dl = [next_val_l]
  4116                                  	; dh = [next_val_r]
  4117                                  	; original-interpolated
  4118 0000140F 89C3                    	mov	bx, ax
  4119 00001411 2C80                    	sub	al, 80h
  4120 00001413 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4121 00001416 AB                      	stosw		; original sample (L)
  4122 00001417 88F8                    	mov	al, bh
  4123 00001419 2C80                    	sub	al, 80h
  4124 0000141B C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4125 0000141E AB                      	stosw		; original sample (R)
  4126 0000141F 88D8                    	mov	al, bl	; [previous_val_l]
  4127 00001421 00D0                    	add	al, dl	; [next_val_l]	
  4128 00001423 D0D8                    	rcr	al, 1
  4129 00001425 2C80                    	sub	al, 80h
  4130 00001427 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4131 0000142A AB                      	stosw		; interpolated sample (L)
  4132 0000142B 88F8                    	mov	al, bh
  4133 0000142D 00F0                    	add	al, dh	; [next_val_r]
  4134 0000142F D0D8                    	rcr	al, 1
  4135 00001431 2C80                    	sub	al, 80h
  4136 00001433 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4137 00001436 AB                      	stosw		; interpolated sample (R)
  4138 00001437 C3                      	retn
  4139                                  
  4140                                  ;-----------------------------------------------------------------------------
  4141                                  
  4142                                  interpolating_3_16bit_mono:
  4143                                  	; 16/11/2023
  4144                                  	; ax = [previous_val]
  4145                                  	; dx = [next_val]
  4146                                  	; original-interpolated-interpolated
  4147                                  
  4148 00001438 AB                      	stosw		; original sample (L)
  4149 00001439 AB                      	stosw		; original sample (R)
  4150 0000143A 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4151 0000143D 50                      	push	ax ; *	; [previous_val]
  4152 0000143E 80C680                  	add	dh, 80h
  4153 00001441 01D0                    	add	ax, dx
  4154 00001443 D1D8                    	rcr	ax, 1
  4155 00001445 5B                      	pop	bx ; *
  4156 00001446 93                      	xchg	bx, ax	; bx  = interpolated middle (temporary)
  4157 00001447 01D8                    	add	ax, bx	; [previous_val] + interpolated middle
  4158 00001449 D1D8                    	rcr	ax, 1
  4159 0000144B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4160 0000144E AB                      	stosw 		; interpolated sample 1 (L)
  4161 0000144F AB                      	stosw		; interpolated sample 1 (R)
  4162 00001450 89D8                    	mov	ax, bx
  4163 00001452 01D0                    	add	ax, dx	 ;interpolated middle + [next_val]
  4164 00001454 D1D8                    	rcr	ax, 1
  4165 00001456 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4166 00001459 AB                      	stosw		; interpolated sample 2 (L)
  4167 0000145A AB                      	stosw		; interpolated sample 2 (R)
  4168 0000145B C3                      	retn
  4169                                  
  4170                                  ;-----------------------------------------------------------------------------
  4171                                  
  4172                                  interpolating_3_16bit_stereo:
  4173                                  	; 16/11/2023
  4174                                  	; bx = [previous_val_l]
  4175                                  	; ax = [previous_val_r]
  4176                                  	; [next_val_l]
  4177                                  	; dx = [next_val_r]
  4178                                  	; original-interpolated-interpolated
  4179                                  
  4180 0000145C 93                      	xchg	ax, bx
  4181 0000145D AB                      	stosw		; original sample (L)
  4182 0000145E 93                      	xchg	ax, bx
  4183 0000145F AB                      	stosw		; original sample (R)
  4184 00001460 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4185 00001463 50                      	push	ax ; *	; [previous_val_r]
  4186 00001464 80C780                  	add	bh, 80h
  4187 00001467 8006[BD17]80            	add	byte [next_val_l+1], 80h
  4188 0000146C A1[BC17]                	mov	ax, [next_val_l]
  4189 0000146F 01D8                    	add	ax, bx	; [previous_val_l]
  4190 00001471 D1D8                    	rcr	ax, 1
  4191 00001473 93                      	xchg	ax, bx	; ax = [previous_val_l]	
  4192 00001474 01D8                    	add	ax, bx	; bx = interpolated middle (L)
  4193 00001476 D1D8                    	rcr	ax, 1
  4194 00001478 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4195 0000147B AB                      	stosw 		; interpolated sample 1 (L)
  4196 0000147C 58                      	pop	ax  ; *
  4197 0000147D 80C680                  	add	dh, 80h ; convert sound level 0 to 65535 format
  4198 00001480 52                      	push	dx  ; * ; [next_val_r]
  4199 00001481 92                      	xchg	ax, dx
  4200 00001482 01D0                    	add	ax, dx	; [next_val_r] + [previous_val_r]
  4201 00001484 D1D8                    	rcr	ax, 1	; / 2
  4202 00001486 50                      	push	ax ; ** ; interpolated middle (R)
  4203 00001487 01D0                    	add	ax, dx	; + [previous_val_r]
  4204 00001489 D1D8                    	rcr	ax, 1
  4205 0000148B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4206 0000148E AB                      	stosw 		; interpolated sample 1 (R)
  4207 0000148F A1[BC17]                	mov	ax, [next_val_l]
  4208 00001492 01D8                    	add	ax, bx	; + interpolated middle (L)
  4209 00001494 D1D8                    	rcr	ax, 1
  4210 00001496 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4211 00001499 AB                      	stosw 		; interpolated sample 2 (L)
  4212 0000149A 58                      	pop	ax ; **
  4213 0000149B 5A                      	pop	dx ; *
  4214 0000149C 01D0                    	add	ax, dx	; interpolated middle + [next_val_r]
  4215 0000149E D1D8                    	rcr	ax, 1	; / 2
  4216 000014A0 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4217 000014A3 AB                      	stosw 		; interpolated sample 2 (L)
  4218 000014A4 C3                      	retn
  4219                                  
  4220                                  ;-----------------------------------------------------------------------------
  4221                                  
  4222                                  
  4223                                  interpolating_2_16bit_mono:
  4224                                  	; 16/11/2023
  4225                                  	; ax = [previous_val]
  4226                                  	; dx = [next_val]
  4227                                  	; original-interpolated
  4228                                  
  4229 000014A5 AB                      	stosw		; original sample (L)
  4230 000014A6 AB                      	stosw		; original sample (R)
  4231 000014A7 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4232 000014AA 80C680                  	add	dh, 80h
  4233 000014AD 01D0                    	add	ax, dx
  4234 000014AF D1D8                    	rcr	ax, 1
  4235 000014B1 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4236 000014B4 AB                      	stosw		; interpolated sample (L)
  4237 000014B5 AB                      	stosw		; interpolated sample (R)
  4238 000014B6 C3                      	retn
  4239                                  
  4240                                  ;-----------------------------------------------------------------------------
  4241                                  
  4242                                  interpolating_2_16bit_stereo:
  4243                                  	; 16/11/2023
  4244                                  	; bx = [previous_val_l]
  4245                                  	; ax = [previous_val_r]
  4246                                  	; [next_val_l]
  4247                                  	; dx = [next_val_r]
  4248                                  	; original-interpolated
  4249                                  
  4250 000014B7 93                      	xchg	ax, bx
  4251 000014B8 AB                      	stosw		; original sample (L)
  4252 000014B9 93                      	xchg	ax, bx
  4253 000014BA AB                      	stosw		; original sample (R)
  4254 000014BB 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4255 000014BE 80C680                  	add	dh, 80h
  4256 000014C1 01D0                    	add	ax, dx	; [previous_val_r] + [next_val_r]
  4257 000014C3 D1D8                    	rcr	ax, 1	; / 2
  4258 000014C5 50                      	push	ax ; *	; interpolated sample (R)
  4259 000014C6 A1[BC17]                	mov	ax, [next_val_l]
  4260 000014C9 80C480                  	add	ah, 80h
  4261 000014CC 80C780                  	add	bh, 80h
  4262 000014CF 01D8                    	add	ax, bx	; [next_val_l] + [previous_val_l]
  4263 000014D1 D1D8                    	rcr	ax, 1	; / 2		
  4264 000014D3 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4265 000014D6 AB                      	stosw 		; interpolated sample (L)
  4266 000014D7 58                      	pop	ax ; *	
  4267 000014D8 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4268 000014DB AB                      	stosw 		; interpolated sample (R)
  4269 000014DC C3                      	retn
  4270                                  
  4271                                  ;-----------------------------------------------------------------------------
  4272                                  
  4273                                  interpolating_5_8bit_mono:
  4274                                  	; 17/11/2023
  4275                                  	; al = [previous_val]
  4276                                  	; dl = [next_val]
  4277                                  	; original-interpltd-interpltd-interpltd-interpltd
  4278 000014DD 88C3                    	mov	bl, al
  4279 000014DF 2C80                    	sub	al, 80h
  4280 000014E1 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4281 000014E4 AB                      	stosw		; original sample (L)
  4282 000014E5 AB                      	stosw		; original sample (R)
  4283 000014E6 88D8                    	mov	al, bl
  4284 000014E8 00D0                    	add	al, dl
  4285 000014EA D0D8                    	rcr	al, 1
  4286 000014EC 88C7                    	mov	bh, al	; interpolated middle (temporary)
  4287 000014EE 00D8                    	add	al, bl  ; [previous_val]
  4288 000014F0 D0D8                    	rcr	al, 1
  4289 000014F2 88C6                    	mov	dh, al	; interpolated 1st quarter (temporary)
  4290 000014F4 00D8                    	add	al, bl
  4291 000014F6 D0D8                    	rcr	al, 1
  4292 000014F8 2C80                    	sub	al, 80h
  4293 000014FA C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4294 000014FD AB                      	stosw		; interpolated sample 1 (L)
  4295 000014FE AB                      	stosw		; interpolated sample 1 (R)
  4296 000014FF 88F8                    	mov	al, bh
  4297 00001501 00F0                    	add	al, dh
  4298 00001503 D0D8                    	rcr	al, 1
  4299 00001505 2C80                    	sub	al, 80h
  4300 00001507 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4301 0000150A AB                      	stosw		; interpolated sample 2 (L)
  4302 0000150B AB                      	stosw		; interpolated sample 2 (R)
  4303 0000150C 88F8                    	mov	al, bh
  4304 0000150E 00D0                    	add	al, dl	; [next_val]
  4305 00001510 D0D8                    	rcr	al, 1
  4306 00001512 88C6                    	mov	dh, al	; interpolated 3rd quarter (temporary)
  4307 00001514 00F8                    	add	al, bh
  4308 00001516 D0D8                    	rcr	al, 1
  4309 00001518 2C80                    	sub	al, 80h
  4310 0000151A C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4311 0000151D AB                      	stosw		; interpolated sample 3 (L)
  4312 0000151E AB                      	stosw		; interpolated sample 3 (R)
  4313 0000151F 88F0                    	mov	al, dh
  4314 00001521 00D0                    	add	al, dl
  4315 00001523 D0D8                    	rcr	al, 1
  4316 00001525 2C80                    	sub	al, 80h
  4317 00001527 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4318 0000152A AB                      	stosw		; interpolated sample 4 (L)
  4319 0000152B AB                      	stosw		; interpolated sample 4 (R)
  4320 0000152C C3                      	retn
  4321                                  
  4322                                  ;-----------------------------------------------------------------------------
  4323                                  
  4324                                  interpolating_5_8bit_stereo:
  4325                                  	; 17/11/2023
  4326                                  	; al = [previous_val_l]
  4327                                  	; ah = [previous_val_r]
  4328                                  	; dl = [next_val_l]
  4329                                  	; dh = [next_val_r]
  4330                                  	; original-interpltd-interpltd-interpltd-interpltd
  4331 0000152D 89C3                    	mov	bx, ax
  4332 0000152F 2C80                    	sub	al, 80h
  4333 00001531 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4334 00001534 AB                      	stosw		; original sample (L)
  4335 00001535 88F8                    	mov	al, bh
  4336 00001537 2C80                    	sub	al, 80h
  4337 00001539 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4338 0000153C AB                      	stosw		; original sample (R)
  4339 0000153D 52                      	push	dx ; *
  4340 0000153E 88D8                    	mov	al, bl
  4341 00001540 00D0                    	add	al, dl	; [next_val_l]
  4342 00001542 D0D8                    	rcr	al, 1
  4343 00001544 50                      	push	ax ; **	; al = interpolated middle (L) (temporary)
  4344 00001545 00D8                    	add	al, bl	; [previous_val_l]
  4345 00001547 D0D8                    	rcr	al, 1
  4346 00001549 86D8                    	xchg	al, bl
  4347 0000154B 00D8                    	add	al, bl	; bl = interpolated 1st quarter (L) (temp)
  4348 0000154D D0D8                    	rcr	al, 1
  4349 0000154F 2C80                    	sub	al, 80h
  4350 00001551 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4351 00001554 AB                      	stosw		; interpolated sample 1 (L)
  4352 00001555 88F8                    	mov	al, bh
  4353 00001557 00F0                    	add	al, dh	; [next_val_r]
  4354 00001559 D0D8                    	rcr	al, 1
  4355 0000155B 50                      	push	ax ; *** ; al = interpolated middle (R) (temporary)
  4356 0000155C 00F8                    	add	al, bh	; [previous_val_r]
  4357 0000155E D0D8                    	rcr	al, 1
  4358 00001560 86F8                    	xchg	al, bh
  4359 00001562 00F8                    	add	al, bh	; bh = interpolated 1st quarter (R) (temp)
  4360 00001564 D0D8                    	rcr	al, 1
  4361 00001566 2C80                    	sub	al, 80h
  4362 00001568 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4363 0000156B AB                      	stosw		; interpolated sample 1 (R)
  4364 0000156C 5A                      	pop	dx ; ***
  4365 0000156D 58                      	pop	ax ; **	; al = interpolated middle (L) (temporary)
  4366 0000156E 86D8                    	xchg	al, bl	; al = interpolated 1st quarter (L) (temp)
  4367 00001570 00D8                    	add	al, bl	; bl = interpolated middle (L) (temporary)
  4368 00001572 D0D8                    	rcr	al, 1
  4369 00001574 2C80                    	sub	al, 80h
  4370 00001576 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4371 00001579 AB                      	stosw		; interpolated sample 2 (L)	
  4372 0000157A 88D0                    	mov	al, dl 	; interpolated middle (R) (temporary)
  4373 0000157C 86F8                    	xchg	al, bh	; al = interpolated 1st quarter (R) (temp)
  4374 0000157E 00F8                    	add	al, bh	; bh = interpolated middle (R) (temporary)
  4375 00001580 D0D8                    	rcr	al, 1
  4376 00001582 2C80                    	sub	al, 80h
  4377 00001584 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4378 00001587 AB                      	stosw		; interpolated sample 2 (R)
  4379 00001588 5A                      	pop	dx ; *
  4380 00001589 88D8                    	mov	al, bl	; interpolated middle (L) (temporary)
  4381 0000158B 00D0                    	add	al, dl	; [next_val_l]
  4382 0000158D D0D8                    	rcr	al, 1
  4383 0000158F 86D8                    	xchg	al, bl	; al = interpolated middle (R) (temporary)
  4384 00001591 00D8                    	add	al, bl	; bl = interpolated 3rd quarter (L) (temp)
  4385 00001593 D0D8                    	rcr	al, 1
  4386 00001595 2C80                    	sub	al, 80h
  4387 00001597 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4388 0000159A AB                      	stosw		; interpolated sample 3 (L)
  4389 0000159B 88F8                    	mov	al, bh	
  4390 0000159D 00F0                    	add	al, dh	; interpolated middle (R) + [next_val_r]
  4391 0000159F D0D8                    	rcr	al, 1
  4392 000015A1 86F8                    	xchg	al, bh	; al = interpolated middle (R)
  4393 000015A3 00F8                    	add	al, bh	; bh = interpolated 3rd quarter (R) (temp)
  4394 000015A5 D0D8                    	rcr	al, 1
  4395 000015A7 2C80                    	sub	al, 80h
  4396 000015A9 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4397 000015AC AB                      	stosw		; interpolated sample 3 (R)
  4398 000015AD 88D8                    	mov	al, bl
  4399 000015AF 00D0                    	add	al, dl	; [next_val_l]
  4400 000015B1 D0D8                    	rcr	al, 1
  4401 000015B3 2C80                    	sub	al, 80h
  4402 000015B5 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4403 000015B8 AB                      	stosw		; interpolated sample 4 (L)
  4404 000015B9 88F8                    	mov	al, bh
  4405 000015BB 00F0                    	add	al, dh	; [next_val_r]
  4406 000015BD D0D8                    	rcr	al, 1
  4407 000015BF 2C80                    	sub	al, 80h
  4408 000015C1 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4409 000015C4 AB                      	stosw		; interpolated sample 4 (R)
  4410 000015C5 C3                      	retn
  4411                                  
  4412                                  ;-----------------------------------------------------------------------------
  4413                                  
  4414                                  interpolating_4_8bit_mono:
  4415                                  	; 17/11/2023
  4416                                  	; al = [previous_val]
  4417                                  	; dl = [next_val]
  4418                                  	; original-interpolated-interpolated-interpolated
  4419 000015C6 88C3                    	mov	bl, al
  4420 000015C8 2C80                    	sub	al, 80h
  4421 000015CA C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4422 000015CD AB                      	stosw		; original sample (L)
  4423 000015CE AB                      	stosw		; original sample (R)
  4424 000015CF 88D8                    	mov	al, bl
  4425 000015D1 00D0                    	add	al, dl
  4426 000015D3 D0D8                    	rcr	al, 1
  4427 000015D5 86D8                    	xchg	al, bl  ; al = [previous_val]
  4428 000015D7 00D8                    	add	al, bl	; bl = interpolated middle (sample 2)
  4429 000015D9 D0D8                    	rcr	al, 1
  4430 000015DB 2C80                    	sub	al, 80h
  4431 000015DD C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4432 000015E0 AB                      	stosw		; interpolated sample 1 (L)
  4433 000015E1 AB                      	stosw		; interpolated sample 1 (R)
  4434 000015E2 88D8                    	mov	al, bl	; interpolated middle (sample 2)
  4435 000015E4 2C80                    	sub	al, 80h
  4436 000015E6 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4437 000015E9 AB                      	stosw		; interpolated sample 2 (L)
  4438 000015EA AB                      	stosw		; interpolated sample 2 (R)
  4439 000015EB 88D8                    	mov	al, bl
  4440 000015ED 00D0                    	add	al, dl	; [next_val]
  4441 000015EF D0D8                    	rcr	al, 1
  4442 000015F1 2C80                    	sub	al, 80h
  4443 000015F3 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4444 000015F6 AB                      	stosw		; interpolated sample 3 (L)
  4445 000015F7 AB                      	stosw		; interpolated sample 3 (R)
  4446 000015F8 C3                      	retn
  4447                                  
  4448                                  ;-----------------------------------------------------------------------------
  4449                                  
  4450                                  interpolating_4_8bit_stereo:
  4451                                  	; 17/11/2023
  4452                                  	; al = [previous_val_l]
  4453                                  	; ah = [previous_val_r]
  4454                                  	; dl = [next_val_l]
  4455                                  	; dh = [next_val_r]
  4456                                  	; original-interpolated-interpolated-interpolated
  4457 000015F9 89C3                    	mov	bx, ax
  4458 000015FB 2C80                    	sub	al, 80h
  4459 000015FD C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4460 00001600 AB                      	stosw		; original sample (L)
  4461 00001601 88F8                    	mov	al, bh
  4462 00001603 2C80                    	sub	al, 80h
  4463 00001605 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4464 00001608 AB                      	stosw		; original sample (R)
  4465 00001609 88D8                    	mov	al, bl
  4466 0000160B 00D0                    	add	al, dl	; [next_val_l]
  4467 0000160D D0D8                    	rcr	al, 1
  4468 0000160F 86D8                    	xchg	al, bl	; al = [previous_val_l]
  4469 00001611 00D8                    	add	al, bl	; bl = interpolated middle (L) (sample 2)
  4470 00001613 D0D8                    	rcr	al, 1
  4471 00001615 2C80                    	sub	al, 80h
  4472 00001617 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4473 0000161A AB                      	stosw		; interpolated sample 1 (L)
  4474 0000161B 88F8                    	mov	al, bh
  4475 0000161D 00F0                    	add	al, dh	; [next_val_r]
  4476 0000161F D0D8                    	rcr	al, 1
  4477 00001621 86F8                    	xchg	al, bh	; al = [previous_val_h]
  4478 00001623 00F8                    	add	al, bh	; bh = interpolated middle (R) (sample 2)
  4479 00001625 D0D8                    	rcr	al, 1
  4480 00001627 2C80                    	sub	al, 80h
  4481 00001629 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4482 0000162C AB                      	stosw		; interpolated sample 1 (R)
  4483 0000162D 88D8                    	mov	al, bl	; interpolated middle (L) (sample 2)
  4484 0000162F 2C80                    	sub	al, 80h
  4485 00001631 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4486 00001634 AB                      	stosw		; interpolated sample 2 (L)
  4487 00001635 88F8                    	mov	al, bh	; interpolated middle (L) (sample 2)
  4488 00001637 2C80                    	sub	al, 80h
  4489 00001639 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4490 0000163C AB                      	stosw		; interpolated sample 2 (L)
  4491 0000163D 88D8                    	mov	al, bl
  4492 0000163F 00D0                    	add	al, dl	; [next_val_l]
  4493 00001641 D0D8                    	rcr	al, 1
  4494 00001643 2C80                    	sub	al, 80h
  4495 00001645 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4496 00001648 AB                      	stosw		; interpolated sample 3 (L)
  4497 00001649 88F8                    	mov	al, bh
  4498 0000164B 00F0                    	add	al, dh	; [next_val_r]
  4499 0000164D D0D8                    	rcr	al, 1
  4500 0000164F 2C80                    	sub	al, 80h
  4501 00001651 C1E008                  	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4502 00001654 AB                      	stosw		; interpolated sample 3 (R)
  4503 00001655 C3                      	retn
  4504                                  
  4505                                  ;-----------------------------------------------------------------------------
  4506                                  
  4507                                  interpolating_5_16bit_mono:
  4508                                  	; 18/11/2023
  4509                                  	; ax = [previous_val]
  4510                                  	; dx = [next_val]
  4511                                  	; original-interpltd-interpltd-interpltd-interpltd
  4512 00001656 AB                      	stosw		; original sample (L)
  4513 00001657 AB                      	stosw		; original sample (R)
  4514 00001658 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4515 0000165B 89C3                    	mov	bx, ax	; [previous_val]
  4516 0000165D 80C680                  	add	dh, 80h
  4517 00001660 01D0                    	add	ax, dx
  4518 00001662 D1D8                    	rcr	ax, 1
  4519 00001664 50                      	push	ax ; *	; interpolated middle (temporary)
  4520 00001665 01D8                    	add	ax, bx	; interpolated middle + [previous_val]
  4521 00001667 D1D8                    	rcr	ax, 1
  4522 00001669 50                      	push	ax ; **	; interpolated 1st quarter (temporary)
  4523 0000166A 01D8                    	add	ax, bx	; 1st quarter + [previous_val]
  4524 0000166C D1D8                    	rcr	ax, 1	
  4525 0000166E 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4526 00001671 AB                      	stosw 		; interpolated sample 1 (L)
  4527 00001672 AB                      	stosw		; interpolated sample 1 (R)
  4528 00001673 58                      	pop	ax ; **
  4529 00001674 5B                      	pop	bx ; *
  4530 00001675 01D8                    	add	ax, bx	; 1st quarter + middle
  4531 00001677 D1D8                    	rcr	ax, 1	; / 2
  4532 00001679 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again	
  4533 0000167C AB                      	stosw		; interpolated sample 2 (L)
  4534 0000167D AB                      	stosw		; interpolated sample 2 (R)
  4535 0000167E 89D8                    	mov	ax, bx
  4536 00001680 01D0                    	add	ax, dx	; interpolated middle + [next_val]
  4537 00001682 D1D8                    	rcr	ax, 1
  4538 00001684 50                      	push	ax ; *	; interpolated 3rd quarter (temporary)
  4539 00001685 01D8                    	add	ax, bx	; + interpolated middle
  4540 00001687 D1D8                    	rcr	ax, 1
  4541 00001689 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4542 0000168C AB                      	stosw		; interpolated sample 3 (L)
  4543 0000168D AB                      	stosw		; interpolated sample 3 (R)
  4544 0000168E 58                      	pop	ax ; *	
  4545 0000168F 01D0                    	add	ax, dx	; 3rd quarter + [next_val]
  4546 00001691 D1D8                    	rcr	ax, 1	; / 2
  4547 00001693 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4548 00001696 AB                      	stosw		; interpolated sample 4 (L)
  4549 00001697 AB                      	stosw		; interpolated sample 4 (R)
  4550 00001698 C3                      	retn
  4551                                  
  4552                                  ;-----------------------------------------------------------------------------
  4553                                  
  4554                                  interpolating_5_16bit_stereo:
  4555                                  	; 18/11/2023
  4556                                  	; bx = [previous_val_l]
  4557                                  	; ax = [previous_val_r]
  4558                                  	; [next_val_l]
  4559                                  	; [next_val_r]
  4560                                  	; original-interpltd-interpltd-interpltd-interpltd
  4561 00001699 51                      	push	cx ; !
  4562 0000169A 93                      	xchg	ax, bx
  4563 0000169B AB                      	stosw		; original sample (L)
  4564 0000169C 93                      	xchg	ax, bx
  4565 0000169D AB                      	stosw		; original sample (R)
  4566 0000169E 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4567 000016A1 50                      	push	ax ; *	; [previous_val_r]
  4568 000016A2 80C780                  	add	bh, 80h
  4569 000016A5 8006[BD17]80            	add	byte [next_val_l+1], 80h
  4570 000016AA A1[BC17]                	mov	ax, [next_val_l]
  4571 000016AD 01D8                    	add	ax, bx	; [previous_val_l]
  4572 000016AF D1D8                    	rcr	ax, 1
  4573 000016B1 89C1                    	mov	cx, ax	; interpolated middle (L)
  4574 000016B3 01D8                    	add	ax, bx
  4575 000016B5 D1D8                    	rcr	ax, 1
  4576 000016B7 89C2                    	mov	dx, ax	; interpolated 1st quarter (L)
  4577 000016B9 01D8                    	add	ax, bx	; [previous_val_l]
  4578 000016BB D1D8                    	rcr	ax, 1
  4579 000016BD 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4580 000016C0 AB                      	stosw 		; interpolated sample 1 (L)
  4581 000016C1 89C8                    	mov	ax, cx
  4582 000016C3 01D0                    	add	ax, dx	; middle (L) + 1st quarter (L)
  4583 000016C5 D1D8                    	rcr	ax, 1	; / 2
  4584 000016C7 89C3                    	mov	bx, ax  ; interpolated sample 2 (L)
  4585 000016C9 5A                      	pop	dx ; *	; [previous_val_r]
  4586 000016CA 89D0                    	mov	ax, dx
  4587 000016CC 8006[BF17]80            	add	byte [next_val_r+1], 80h
  4588 000016D1 0306[BE17]              	add	ax, [next_val_r]
  4589 000016D5 D1D8                    	rcr	ax, 1
  4590 000016D7 50                      	push	ax ; *	; interpolated middle (R)
  4591 000016D8 01D0                    	add	ax, dx
  4592 000016DA D1D8                    	rcr	ax, 1
  4593 000016DC 50                      	push	ax ; **	; interpolated 1st quarter (R)
  4594 000016DD 01D0                    	add	ax, dx	; [previous_val_r]
  4595 000016DF D1D8                    	rcr	ax, 1
  4596 000016E1 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4597 000016E4 AB                      	stosw 		; interpolated sample 1 (R)
  4598 000016E5 89D8                    	mov	ax, bx
  4599 000016E7 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4600 000016EA AB                      	stosw 		; interpolated sample 2 (L)
  4601 000016EB 58                      	pop	ax ; **
  4602 000016EC 5A                      	pop	dx ; *
  4603 000016ED 01D0                    	add	ax, dx	; 1st quarter (R) + middle (R)
  4604 000016EF D1D8                    	rcr	ax, 1	; / 2
  4605 000016F1 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4606 000016F4 AB                      	stosw 		; interpolated sample 2 (R)
  4607 000016F5 89C8                    	mov	ax, cx
  4608 000016F7 0306[BC17]              	add	ax, [next_val_l]
  4609 000016FB D1D8                    	rcr	ax, 1
  4610 000016FD 50                      	push	ax ; * 	; interpolated 3rd quarter (L)
  4611 000016FE 01C8                    	add	ax, cx	; interpolated middle (L)
  4612 00001700 D1D8                    	rcr	ax, 1
  4613 00001702 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4614 00001705 AB                      	stosw 		; interpolated sample 3 (L)
  4615 00001706 89D0                    	mov	ax, dx
  4616 00001708 0306[BE17]              	add	ax, [next_val_r]
  4617 0000170C D1D8                    	rcr	ax, 1
  4618 0000170E 50                      	push	ax ; ** ; interpolated 3rd quarter (R)
  4619 0000170F 01D0                    	add	ax, dx	; interpolated middle (R)
  4620 00001711 D1D8                    	rcr	ax, 1
  4621 00001713 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4622 00001716 AB                      	stosw 		; interpolated sample 3 (R)
  4623 00001717 5B                      	pop	bx ; **
  4624 00001718 58                      	pop	ax ; *
  4625 00001719 0306[BC17]              	add	ax, [next_val_l]
  4626 0000171D D1D8                    	rcr	ax, 1
  4627 0000171F 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4628 00001722 AB                      	stosw 		; interpolated sample 4 (L)
  4629 00001723 89D8                    	mov	ax, bx	
  4630 00001725 0306[BE17]              	add	ax, [next_val_r]
  4631 00001729 D1D8                    	rcr	ax, 1
  4632 0000172B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4633 0000172E AB                      	stosw 		; interpolated sample 4 (R)
  4634 0000172F 59                      	pop	cx ; !
  4635 00001730 C3                      	retn
  4636                                  
  4637                                  ;-----------------------------------------------------------------------------
  4638                                  
  4639                                  interpolating_4_16bit_mono:
  4640                                  	; 18/11/2023
  4641                                  	; ax = [previous_val]
  4642                                  	; dx = [next_val]
  4643                                  	; 02/02/2025
  4644                                  	; original-interpolated-interpolated-interpolated
  4645                                  
  4646 00001731 AB                      	stosw		; original sample (L)
  4647 00001732 AB                      	stosw		; original sample (R)
  4648 00001733 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4649 00001736 89C3                    	mov	bx, ax	; [previous_val]
  4650 00001738 80C680                  	add	dh, 80h
  4651 0000173B 01D0                    	add	ax, dx	; [previous_val] + [next_val]
  4652 0000173D D1D8                    	rcr	ax, 1
  4653 0000173F 93                      	xchg	ax, bx
  4654 00001740 01D8                    	add	ax, bx	; [previous_val] + interpolated middle
  4655 00001742 D1D8                    	rcr	ax, 1
  4656 00001744 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4657 00001747 AB                      	stosw 		; interpolated sample 1 (L)
  4658 00001748 AB                      	stosw		; interpolated sample 1 (R)
  4659 00001749 89D8                    	mov	ax, bx	; interpolated middle
  4660 0000174B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4661 0000174E AB                      	stosw 		; interpolated sample 2 (L)
  4662 0000174F AB                      	stosw		; interpolated sample 2 (R)
  4663 00001750 89D8                    	mov	ax, bx
  4664 00001752 01D0                    	add	ax, dx	; interpolated middle + [next_val]
  4665 00001754 D1D8                    	rcr	ax, 1
  4666 00001756 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4667 00001759 AB                      	stosw		; interpolated sample 3 (L)
  4668 0000175A AB                      	stosw		; interpolated sample 3 (R)
  4669 0000175B C3                      	retn
  4670                                  
  4671                                  ;-----------------------------------------------------------------------------
  4672                                  
  4673                                  interpolating_4_16bit_stereo:
  4674                                  	; 18/11/2023
  4675                                  	; bx = [previous_val_l]
  4676                                  	; ax = [previous_val_r]
  4677                                  	; [next_val_l]
  4678                                  	; [next_val_r]
  4679                                  	; original-interpolated-interpolated-interpolated
  4680 0000175C 93                      	xchg	ax, bx
  4681 0000175D AB                      	stosw		; original sample (L)
  4682 0000175E 93                      	xchg	ax, bx
  4683 0000175F AB                      	stosw		; original sample (R)
  4684 00001760 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4685 00001763 89C2                    	mov	dx, ax	; [previous_val_r]
  4686 00001765 80C780                  	add	bh, 80h
  4687 00001768 8006[BD17]80            	add	byte [next_val_l+1], 80h
  4688 0000176D A1[BC17]                	mov	ax, [next_val_l]
  4689 00001770 01D8                    	add	ax, bx	; [previous_val_l]
  4690 00001772 D1D8                    	rcr	ax, 1
  4691 00001774 93                      	xchg	ax, bx
  4692 00001775 01D8                    	add	ax, bx	; bx = interpolated middle (L)
  4693 00001777 D1D8                    	rcr	ax, 1
  4694 00001779 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4695 0000177C AB                      	stosw 		; interpolated sample 1 (L)
  4696 0000177D 8006[BF17]80            	add	byte [next_val_r+1], 80h
  4697 00001782 89D0                    	mov	ax, dx	; [previous_val_r]
  4698 00001784 0306[BE17]              	add	ax, [next_val_r]
  4699 00001788 D1D8                    	rcr	ax, 1
  4700 0000178A 92                      	xchg	ax, dx
  4701 0000178B 01D0                    	add	ax, dx	; dx = interpolated middle (R)
  4702 0000178D D1D8                    	rcr	ax, 1
  4703 0000178F 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4704 00001792 AB                      	stosw 		; interpolated sample 1 (R)
  4705 00001793 89D8                    	mov	ax, bx
  4706 00001795 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4707 00001798 AB                      	stosw 		; interpolated sample 2 (L)
  4708 00001799 89D0                    	mov	ax, dx
  4709 0000179B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4710 0000179E AB                      	stosw 		; interpolated sample 2 (R)
  4711 0000179F 89D8                    	mov	ax, bx
  4712 000017A1 0306[BC17]              	add	ax, [next_val_l]
  4713 000017A5 D1D8                    	rcr	ax, 1
  4714 000017A7 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4715 000017AA AB                      	stosw 		; interpolated sample 3 (L)
  4716 000017AB 89D0                    	mov	ax, dx
  4717 000017AD 0306[BE17]              	add	ax, [next_val_r]
  4718 000017B1 D1D8                    	rcr	ax, 1
  4719 000017B3 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4720 000017B6 AB                      	stosw 		; interpolated sample 3 (R)
  4721 000017B7 C3                      	retn
  4722                                  
  4723                                  ; 13/11/2023
  4724                                  previous_val:
  4725 000017B8 0000                    previous_val_l: dw 0
  4726 000017BA 0000                    previous_val_r: dw 0
  4727                                  next_val:
  4728 000017BC 0000                    next_val_l: dw 0
  4729 000017BE 0000                    next_val_r: dw 0
  4730                                  
  4731                                  ; 16/11/2023
  4732 000017C0 00                      faz:	db 0
  4733                                  
  4734                                  ;=============================================================================
  4735                                  ;	Write AC'97 Hadrware Information
  4736                                  ;=============================================================================
  4737                                  	
  4738                                  	; 08/02/2025
  4739                                  	; 07/02/2025
  4740                                  	; 04/02/2025 - cgaplay.asm
  4741                                  
  4742                                  write_audio_dev_info:
  4743                                  	; 08/02/2025
  4744 000017C1 30FF                    	xor	bh, bh
  4745 000017C3 803E[AA6C]01            	cmp	byte [audio_hardware], 1
  4746 000017C8 753B                    	jne	short write_ac97_pci_dev_info
  4747                                  
  4748                                  ;-----------------------------------------------------------------------------
  4749                                  	
  4750                                  	; 08/02/2025
  4751                                  	; 07/02/2025
  4752                                  	; 04/02/2025 - cgaplay2.asm	
  4753                                  write_sb16_dev_info:
  4754                                  	;xor	bh, bh ; 08/02/2025
  4755 000017CA A1[A66C]                	mov	ax, [audio_io_base]
  4756 000017CD 88C3                    	mov	bl, al
  4757 000017CF 88DA                    	mov	dl, bl
  4758 000017D1 80E30F                  	and	bl, 0Fh
  4759 000017D4 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4760 000017D8 A2[C16B]                	mov	[msgBasePort+2], al
  4761 000017DB 88D3                    	mov	bl, dl
  4762 000017DD C0EB04                  	shr	bl, 4
  4763 000017E0 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4764 000017E4 A2[C06B]                	mov	[msgBasePort+1], al
  4765 000017E7 88E3                    	mov	bl, ah
  4766                                  	; 20/12/2024
  4767                                  	;mov	dl, bl
  4768                                  	;and	bl, 0Fh
  4769 000017E9 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4770 000017ED A2[BF6B]                	mov	[msgBasePort], al
  4771                                  
  4772                                  	; 07/02/2025
  4773                                  	;xor	ax, ax
  4774                                  	;mov	al, [IRQnum]
  4775                                  	; 27/11/2024
  4776 000017F0 A0[9A6C]                	mov	al, [audio_intr]
  4777                                  	;mov	cl, 10
  4778                                  	;div	cl
  4779                                  	;add	ah, 30h
  4780                                  	;mov	[msgIRQ], ah
  4781                                  	; 25/11/2024
  4782 000017F3 0430                    	add	al, 30h
  4783                                  	; 07/02/2025
  4784 000017F5 A2[D66B]                	mov	[msgSB16IRQ], al
  4785                                  
  4786                                  	sys_msg msgSB16Info, 07h
    16 000017F8 BE[896B]            <1>  mov si, %1
    17 000017FB B307                <1>  mov bl, %2
    18 000017FD 30FF                <1>  xor bh, bh
    19 000017FF B40E                <1>  mov ah, 0Eh
    20 00001801 E86D0D              <1>  call p_msg
  4787                                  
  4788 00001804 C3                      	retn
  4789                                  
  4790                                  ;-----------------------------------------------------------------------------
  4791                                  
  4792                                  write_ac97_pci_dev_info:
  4793                                  	; 01/01/2025 (cgaplay.asm)
  4794                                  	; 19/11/2024
  4795                                  	; 30/05/2024
  4796                                  	; 06/06/2017
  4797                                  	; 03/06/2017
  4798                                  	; BUS/DEV/FN
  4799                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  4800                                  	; DEV/VENDOR
  4801                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  4802                                  
  4803 00001805 66A1[9E6C]              	mov	eax, [dev_vendor]
  4804                                  	;xor	bh, bh
  4805 00001809 88C3                    	mov	bl, al
  4806 0000180B 88DA                    	mov	dl, bl
  4807 0000180D 80E30F                  	and	bl, 0Fh
  4808 00001810 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4809 00001814 A2[936A]                	mov	[msgVendorId+3], al
  4810 00001817 88D3                    	mov	bl, dl
  4811 00001819 C0EB04                  	shr	bl, 4
  4812 0000181C 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4813 00001820 A2[926A]                	mov	[msgVendorId+2], al
  4814 00001823 88E3                    	mov	bl, ah
  4815 00001825 88DA                    	mov	dl, bl
  4816 00001827 80E30F                  	and	bl, 0Fh
  4817 0000182A 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4818 0000182E A2[916A]                	mov	[msgVendorId+1], al
  4819 00001831 88D3                    	mov	bl, dl
  4820 00001833 C0EB04                  	shr	bl, 4
  4821 00001836 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4822 0000183A A2[906A]                	mov	[msgVendorId], al
  4823 0000183D 66C1E810                	shr	eax, 16
  4824 00001841 88C3                    	mov	bl, al
  4825 00001843 88DA                    	mov	dl, bl
  4826 00001845 80E30F                  	and	bl, 0Fh
  4827 00001848 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4828 0000184C A2[A46A]                	mov	[msgDevId+3], al
  4829 0000184F 88D3                    	mov	bl, dl
  4830 00001851 C0EB04                  	shr	bl, 4
  4831 00001854 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4832 00001858 A2[A36A]                	mov	[msgDevId+2], al
  4833 0000185B 88E3                    	mov	bl, ah
  4834 0000185D 88DA                    	mov	dl, bl
  4835 0000185F 80E30F                  	and	bl, 0Fh
  4836 00001862 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4837 00001866 A2[A26A]                	mov	[msgDevId+1], al
  4838 00001869 88D3                    	mov	bl, dl
  4839 0000186B C0EB04                  	shr	bl, 4
  4840 0000186E 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4841 00001872 A2[A16A]                	mov	[msgDevId], al
  4842                                  
  4843 00001875 66A1[A26C]              	mov	eax, [bus_dev_fn]
  4844 00001879 66C1E808                	shr	eax, 8
  4845 0000187D 88C3                    	mov	bl, al
  4846 0000187F 88DA                    	mov	dl, bl
  4847 00001881 80E307                  	and	bl, 7 ; bit 0,1,2
  4848 00001884 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4849 00001888 A2[C86A]                	mov	[msgFncNo+1], al
  4850 0000188B 88D3                    	mov	bl, dl
  4851 0000188D C0EB03                  	shr	bl, 3
  4852 00001890 88DA                    	mov	dl, bl
  4853 00001892 80E30F                  	and	bl, 0Fh
  4854 00001895 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4855 00001899 A2[BA6A]                	mov	[msgDevNo+1], al
  4856 0000189C 88D3                    	mov	bl, dl
  4857 0000189E C0EB04                  	shr	bl, 4
  4858 000018A1 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4859 000018A5 A2[B96A]                	mov	[msgDevNo], al
  4860 000018A8 88E3                    	mov	bl, ah
  4861 000018AA 88DA                    	mov	dl, bl
  4862 000018AC 80E30F                  	and	bl, 0Fh
  4863 000018AF 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4864 000018B3 A2[AE6A]                	mov	[msgBusNo+1], al
  4865 000018B6 88D3                    	mov	bl, dl
  4866 000018B8 C0EB04                  	shr	bl, 4
  4867 000018BB 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4868 000018BF A2[AD6A]                	mov	[msgBusNo], al
  4869                                  
  4870                                  	;mov	ax, [ac97_NamBar]
  4871 000018C2 A1[A66C]                	mov	ax, [NAMBAR]
  4872 000018C5 88C3                    	mov	bl, al
  4873 000018C7 88DA                    	mov	dl, bl
  4874 000018C9 80E30F                  	and	bl, 0Fh
  4875 000018CC 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4876 000018D0 A2[D76A]                	mov	[msgNamBar+3], al
  4877 000018D3 88D3                    	mov	bl, dl
  4878 000018D5 C0EB04                  	shr	bl, 4
  4879 000018D8 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4880 000018DC A2[D66A]                	mov	[msgNamBar+2], al
  4881 000018DF 88E3                    	mov	bl, ah
  4882 000018E1 88DA                    	mov	dl, bl
  4883 000018E3 80E30F                  	and	bl, 0Fh
  4884 000018E6 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4885 000018EA A2[D56A]                	mov	[msgNamBar+1], al
  4886 000018ED 88D3                    	mov	bl, dl
  4887 000018EF C0EB04                  	shr	bl, 4
  4888 000018F2 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4889 000018F6 A2[D46A]                	mov	[msgNamBar], al
  4890                                  
  4891                                  	;mov	ax, [NABMBAR]
  4892 000018F9 A1[A86C]                	mov	ax, [NABMBAR]
  4893 000018FC 88C3                    	mov	bl, al
  4894 000018FE 88DA                    	mov	dl, bl
  4895 00001900 80E30F                  	and	bl, 0Fh
  4896 00001903 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4897 00001907 A2[E76A]                	mov	[msgNabmBar+3], al
  4898 0000190A 88D3                    	mov	bl, dl
  4899 0000190C C0EB04                  	shr	bl, 4
  4900 0000190F 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4901 00001913 A2[E66A]                	mov	[msgNabmBar+2], al
  4902 00001916 88E3                    	mov	bl, ah
  4903 00001918 88DA                    	mov	dl, bl
  4904 0000191A 80E30F                  	and	bl, 0Fh
  4905 0000191D 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4906 00001921 A2[E56A]                	mov	[msgNabmBar+1], al
  4907 00001924 88D3                    	mov	bl, dl
  4908 00001926 C0EB04                  	shr	bl, 4
  4909 00001929 8A87[4E6A]              	mov	al, [bx+hex_chars]
  4910 0000192D A2[E46A]                	mov	[msgNabmBar], al
  4911                                  
  4912 00001930 6631C0                  	xor	eax, eax
  4913 00001933 A0[9A6C]                	mov	al, [ac97_int_ln_reg]
  4914 00001936 B10A                    	mov	cl, 10
  4915 00001938 F6F1                    	div	cl
  4916                                  	; 23/11/2024
  4917                                  	;add	[msgIRQ], ax
  4918 0000193A 053030                  	add	ax, 3030h
  4919 0000193D A3[F06A]                	mov	[msgIRQ], ax
  4920                                  	; 07/02/2025
  4921                                  	;and	al, al
  4922 00001940 3C30                    	cmp	al, 30h
  4923 00001942 7508                    	jnz	short _w_ac97imsg_
  4924 00001944 A0[F16A]                	mov	al, [msgIRQ+1]
  4925 00001947 B420                    	mov	ah, ' '
  4926 00001949 A3[F06A]                	mov	[msgIRQ], ax
  4927                                  _w_ac97imsg_:
  4928                                  	sys_msg msgAC97Info, 07h
    16 0000194C BE[5F6A]            <1>  mov si, %1
    17 0000194F B307                <1>  mov bl, %2
    18 00001951 30FF                <1>  xor bh, bh
    19 00001953 B40E                <1>  mov ah, 0Eh
    20 00001955 E8190C              <1>  call p_msg
  4929                                  
  4930                                  	; 19/11/2024
  4931                                          ;retn
  4932                                  
  4933                                  ;-----------------------------------------------------------------------------
  4934                                  
  4935                                  	; 30/05/2024
  4936                                  write_VRA_info:
  4937                                  	sys_msg	msgVRAheader, 07h
    16 00001958 BE[446B]            <1>  mov si, %1
    17 0000195B B307                <1>  mov bl, %2
    18 0000195D 30FF                <1>  xor bh, bh
    19 0000195F B40E                <1>  mov ah, 0Eh
    20 00001961 E80D0C              <1>  call p_msg
  4938 00001964 803E[9B6C]00            	cmp	byte [VRA], 0
  4939 00001969 760D                    	jna	short _w_VRAi_no
  4940                                  _w_VRAi_yes:
  4941                                  	sys_msg msgVRAyes, 07h
    16 0000196B BE[526B]            <1>  mov si, %1
    17 0000196E B307                <1>  mov bl, %2
    18 00001970 30FF                <1>  xor bh, bh
    19 00001972 B40E                <1>  mov ah, 0Eh
    20 00001974 E8FA0B              <1>  call p_msg
  4942 00001977 C3                      	retn
  4943                                  _w_VRAi_no:
  4944                                  	sys_msg msgVRAno, 07h
    16 00001978 BE[586B]            <1>  mov si, %1
    17 0000197B B307                <1>  mov bl, %2
    18 0000197D 30FF                <1>  xor bh, bh
    19 0000197F B40E                <1>  mov ah, 0Eh
    20 00001981 E8ED0B              <1>  call p_msg
  4945 00001984 C3                      	retn
  4946                                  
  4947                                  ;=============================================================================
  4948                                  ;	Write WAV File Information
  4949                                  ;=============================================================================
  4950                                  
  4951                                  	; 07/02/2025
  4952                                  
  4953                                  write_wav_file_info:
  4954                                  	sys_msg msgWavFileName, 0Fh
    16 00001985 BE[F56A]            <1>  mov si, %1
    17 00001988 B30F                <1>  mov bl, %2
    18 0000198A 30FF                <1>  xor bh, bh
    19 0000198C B40E                <1>  mov ah, 0Eh
    20 0000198E E8E00B              <1>  call p_msg
  4955                                  	sys_msg wav_file_name, 0Fh
    16 00001991 BE[486C]            <1>  mov si, %1
    17 00001994 B30F                <1>  mov bl, %2
    18 00001996 30FF                <1>  xor bh, bh
    19 00001998 B40E                <1>  mov ah, 0Eh
    20 0000199A E8D40B              <1>  call p_msg
  4956                                  
  4957                                  write_sample_rate:
  4958 0000199D A1[346C]                	mov	ax, [WAVE_SampleRate]
  4959                                  	; ax = sample rate (hertz)
  4960 000019A0 31D2                    	xor	dx, dx
  4961 000019A2 B90A00                  	mov	cx, 10
  4962 000019A5 F7F1                    	div	cx
  4963 000019A7 0016[1A6B]              	add	[msgHertz+4], dl
  4964 000019AB 29D2                    	sub	dx, dx
  4965 000019AD F7F1                    	div	cx
  4966 000019AF 0016[196B]              	add	[msgHertz+3], dl
  4967 000019B3 29D2                    	sub	dx, dx
  4968 000019B5 F7F1                    	div	cx
  4969 000019B7 0016[186B]              	add	[msgHertz+2], dl
  4970 000019BB 29D2                    	sub	dx, dx
  4971 000019BD F7F1                    	div	cx
  4972 000019BF 0016[176B]              	add	[msgHertz+1], dl
  4973 000019C3 0006[166B]              	add	[msgHertz], al
  4974                                  	
  4975                                  	sys_msg	msgSampleRate, 0Fh
    16 000019C7 BE[076B]            <1>  mov si, %1
    17 000019CA B30F                <1>  mov bl, %2
    18 000019CC 30FF                <1>  xor bh, bh
    19 000019CE B40E                <1>  mov ah, 0Eh
    20 000019D0 E89E0B              <1>  call p_msg
  4976                                  
  4977 000019D3 BD[316B]                	mov	bp, msg16Bits
  4978 000019D6 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16
  4979 000019DB 7403                    	je	short wsr_1
  4980 000019DD BD[216B]                	mov	bp, msg8Bits
  4981                                  wsr_1:
  4982                                  	sys_msg	bp, 0Fh
    16 000019E0 89EE                <1>  mov si, %1
    17 000019E2 B30F                <1>  mov bl, %2
    18 000019E4 30FF                <1>  xor bh, bh
    19 000019E6 B40E                <1>  mov ah, 0Eh
    20 000019E8 E8860B              <1>  call p_msg
  4983                                  
  4984 000019EB BD[2A6B]                	mov	bp, msgMono
  4985 000019EE 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  4986 000019F3 7403                    	je	short wsr_2
  4987 000019F5 BD[3B6B]                	mov	bp, msgStereo
  4988                                  wsr_2:
  4989                                  	sys_msg	bp, 0Fh
    16 000019F8 89EE                <1>  mov si, %1
    17 000019FA B30F                <1>  mov bl, %2
    18 000019FC 30FF                <1>  xor bh, bh
    19 000019FE B40E                <1>  mov ah, 0Eh
    20 00001A00 E86E0B              <1>  call p_msg
  4990 00001A03 C3                              retn
  4991                                  
  4992                                  ;=============================================================================
  4993                                  ;	Audio System Initialization
  4994                                  ;=============================================================================
  4995                                  	
  4996                                  	; 08/02/2025
  4997                                  	; 06/02/2025
  4998                                  audio_system_init:
  4999 00001A04 803E[AA6C]01            	cmp	byte [audio_hardware], 1
  5000 00001A09 7415                    	je	short sb16_init
  5001                                  
  5002 00001A0B E8C401                  	call	ac97_init
  5003 00001A0E 730F                    	jnc	short init_ok
  5004                                  
  5005                                  	; 08/02/2025
  5006 00001A10 BD[EC69]                	mov	bp, ac97_init_err_msg
  5007                                  
  5008                                  init_error:
  5009                                  	;sys_msg init_err_msg, 0Fh
  5010                                  	sys_msg	bp, 0Fh
    16 00001A13 89EE                <1>  mov si, %1
    17 00001A15 B30F                <1>  mov bl, %2
    18 00001A17 30FF                <1>  xor bh, bh
    19 00001A19 B40E                <1>  mov ah, 0Eh
    20 00001A1B E8530B              <1>  call p_msg
  5011                                  
  5012 00001A1E F9                      	stc
  5013                                  init_ok:
  5014 00001A1F C3                      	retn
  5015                                  
  5016                                  ;=============================================================================
  5017                                  ;	Sound Blaster 16 Initialization
  5018                                  ;=============================================================================
  5019                                  
  5020                                  	; 08/02/2025 (*) (wave graphics/scope synchronization)
  5021                                  	; 08/02/2025
  5022                                  	; 06/02/2025
  5023                                  sb16_init:
  5024                                  	; 04/02/2025 - cgaplay2.asm
  5025                                  	; 25/11/2024
  5026                                  	; 24/11/2024
  5027                                  	; Ref: TRDOS 386 Kernel v2.0.9, audio.s (06/06/2024)
  5028                                  	;      SbInit_play procedure (06/08/2022, v2.0.5)
  5029                                  
  5030 00001A20 8CD8                    	mov	ax, ds
  5031 00001A22 89C2                    	mov	dx, ax
  5032 00001A24 C1EA0C                  	shr	dx, 12
  5033 00001A27 C1E004                  	shl	ax, 4
  5034 00001A2A 05[D07A]                	add	ax, dma_buffer
  5035 00001A2D 83D200                  	adc	dx, 0
  5036 00001A30 89C3                    	mov	bx, ax	; linear address
  5037                                  	; dx = page number
  5038                                  
  5039                                  	;mov	cx, dma_buffer_size ; 32768
  5040                                  	; 08/02/2025 (*)
  5041 00001A32 8B0E[BA76]              	mov	cx, [buffersize] ; = [loadsize] for SB16
  5042 00001A36 D1E1                    	shl	cx, 1	; 2*[buffersize] = dma buffer size
  5043                                  
  5044 00001A38 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16
  5045 00001A3D 7532                    	jne	short sbInit_0 ; set 8 bit DMA buffer
  5046                                  
  5047                                  	; 26/11/2024
  5048 00001A3F 89D0                    	mov	ax, dx	; page number
  5049                                  	
  5050                                  	; convert byte count to word count
  5051                                  	; 26/11/2024
  5052                                  	;dec	cx
  5053 00001A41 D1E9                    	shr	cx, 1
  5054 00001A43 49                      	dec	cx	; word count - 1
  5055                                  
  5056                                  	; convert byte offset to word offset
  5057 00001A44 D1E8                    	shr	ax, 1
  5058 00001A46 D1DB                    	rcr	bx, 1
  5059                                  	; 26/11/2024
  5060                                  	;shr	bx, 1
  5061                                  
  5062                                  	; 16 bit DMA buffer setting (DMA channel 5)
  5063 00001A48 B005                    	mov	al, 05h  ; set mask bit for channel 5 (4+1)
  5064 00001A4A E6D4                    	out	0D4h, al
  5065                                  	
  5066 00001A4C 30C0                    	xor	al, al   ; stops all DMA processes on selected channel
  5067 00001A4E E6D8                    	out	0D8h, al ; clear selected channel register
  5068                                  
  5069 00001A50 88D8                    	mov	al, bl	 ; byte 0 of DMA buffer offset in words (physical)
  5070 00001A52 E6C4                    	out	0C4h, al ; DMA channel 5 port number
  5071                                  
  5072 00001A54 88F8                    	mov	al, bh   ; byte 1 of DMA buffer offset in words (physical)
  5073 00001A56 E6C4                    	out	0C4h, al
  5074                                  	
  5075                                  	; 26/11/2024
  5076 00001A58 80E2FE                  	and	dl, 0FEh ; clear bit 0 (not necessary, it will be ignored)
  5077                                  
  5078 00001A5B 88D0                    	mov	al, dl   ; byte 2 of DMA buffer address (physical)
  5079 00001A5D E68B                    	out	8Bh, al  ; page register port addr for channel 5
  5080                                  
  5081 00001A5F 88C8                    	mov	al, cl   ; low byte of DMA count - 1
  5082 00001A61 E6C6                    	out	0C6h, al ; count register port addr for channel 5
  5083                                  
  5084 00001A63 88E8                    	mov	al, ch   ; high byte of DMA count - 1
  5085 00001A65 E6C6                    	out	0C6h, al
  5086                                  
  5087                                  	; channel 5, read, autoinitialized, single mode
  5088 00001A67 B059                    	mov	al, 59h
  5089 00001A69 E6D6                    	out	0D6h, al ; DMA mode register port address
  5090                                  
  5091 00001A6B B001                    	mov	al, 01h  ; clear mask bit for channel 5
  5092 00001A6D E6D4                    	out	0D4h, al ; DMA mask register port address
  5093                                  
  5094 00001A6F EB25                    	jmp	short ResetDsp
  5095                                  
  5096                                  sbInit_0:
  5097 00001A71 49                      	dec	cx	; byte count - 1
  5098                                  
  5099                                  	; 8 bit DMA buffer setting (DMA channel 1)
  5100 00001A72 B005                    	mov	al, 05h ; set mask bit for channel 1 (4+1)
  5101 00001A74 E60A                    	out	0Ah, al ; DMA mask register
  5102                                  
  5103 00001A76 30C0                    	xor	al, al  ; stops all DMA processes on selected channel
  5104 00001A78 E60C                    	out	0Ch, al ; clear selected channel register
  5105                                  
  5106 00001A7A 88D8                    	mov	al, bl	; byte 0 of DMA buffer address (physical)
  5107 00001A7C E602                    	out	02h, al ; DMA channel 1 port number
  5108                                  
  5109 00001A7E 88F8                    	mov	al, bh  ; byte 1 of DMA buffer address (physical)
  5110 00001A80 E602                    	out	02h, al
  5111                                  
  5112 00001A82 88D0                    	mov	al, dl  ; byte 2 of DMA buffer address (physical)
  5113 00001A84 E683                    	out	83h, al ; page register port addr for channel 1
  5114                                  
  5115 00001A86 88C8                    	mov	al, cl  ; low byte of DMA count - 1
  5116 00001A88 E603                    	out	03h, al ; count register port addr for channel 1
  5117                                  
  5118 00001A8A 88E8                    	mov	al, ch  ; high byte of DMA count - 1
  5119 00001A8C E603                    	out	03h, al
  5120                                  
  5121                                  	; channel 1, read, autoinitialized, single mode
  5122 00001A8E B059                    	mov	al, 59h
  5123 00001A90 E60B                    	out	0Bh, al ; DMA mode register port address
  5124                                  
  5125 00001A92 B001                    	mov	al, 01h ; clear mask bit for channel 1
  5126 00001A94 E60A                    	out	0Ah, al ; DMA mask register port address
  5127                                  
  5128                                  ResetDsp:
  5129 00001A96 8B16[A66C]              	mov	dx, [audio_io_base]
  5130                                  	;add	dx, 06h
  5131 00001A9A 80C206                  	add	dl, 06h
  5132 00001A9D B001                    	mov	al, 1
  5133 00001A9F EE                      	out	dx, al
  5134                                  
  5135 00001AA0 EC                      	in	al, dx
  5136 00001AA1 EC                      	in	al, dx
  5137 00001AA2 EC                      	in	al, dx
  5138 00001AA3 EC                      	in	al, dx
  5139                                  
  5140 00001AA4 31C0                    	xor	ax, ax
  5141 00001AA6 EE                      	out	dx, al
  5142                                  
  5143 00001AA7 B96400                  	mov	cx, 100
  5144                                  WaitId:
  5145 00001AAA 8B16[A66C]              	mov	dx, [audio_io_base]
  5146 00001AAE 80C20E                  	add	dl, 0Eh
  5147 00001AB1 EC                      	in	al, dx
  5148 00001AB2 08C0                    	or	al, al
  5149                                  	;js	short sb_GetId
  5150                                  	; 26/11/2024
  5151 00001AB4 790C                    	jns	short sb_next
  5152                                  	;loop	WaitId
  5153                                  	;jmp	sb_Exit
  5154                                  
  5155                                  sb_GetId:
  5156 00001AB6 8B16[A66C]              	mov	dx, [audio_io_base]
  5157                                  	;add	dx, 0Ah
  5158 00001ABA 80C20A                  	add	dl, 0Ah
  5159 00001ABD EC                      	in	al, dx
  5160 00001ABE 3CAA                    	cmp	al, 0AAh
  5161 00001AC0 7408                    	je	short SbOk
  5162                                  sb_next:
  5163 00001AC2 E2E6                    	loop	WaitId
  5164                                  	;stc
  5165                                  
  5166                                  	; 08/02/2025
  5167 00001AC4 BD[C069]                	mov	bp, sb16_init_err_msg
  5168 00001AC7 E949FF                  	jmp	init_error
  5169                                  
  5170                                  SbOk:
  5171 00001ACA C3                      	retn
  5172                                  
  5173                                  ;-----------------------------------------------------------------------------
  5174                                  ;-----------------------------------------------------------------------------
  5175                                  
  5176                                  	; 08/02/2025 (*) (Wave scope/graphics synchronization)
  5177                                  	; 07/02/2025
  5178                                  	; 06/02/2025
  5179                                  
  5180                                  sb16_init_play:
  5181 00001ACB 8B16[A66C]              	mov	dx, [audio_io_base]
  5182                                  	;add	dx, 0Ch
  5183 00001ACF 80C20C                  	add	dl, 0Ch
  5184                                  	SbOut	0D1h	; Turn on speaker
    24                              <1> %%wait:
    25 00001AD2 EC                  <1>  in al, dx
    26 00001AD3 08C0                <1>  or al, al
    27 00001AD5 78FB                <1>  js short %%wait
    28 00001AD7 B0D1                <1>  mov al, %1
    29 00001AD9 EE                  <1>  out dx, al
  5185                                  	SbOut	41h	; 8 bit or 16 bit transfer
    24                              <1> %%wait:
    25 00001ADA EC                  <1>  in al, dx
    26 00001ADB 08C0                <1>  or al, al
    27 00001ADD 78FB                <1>  js short %%wait
    28 00001ADF B041                <1>  mov al, %1
    29 00001AE1 EE                  <1>  out dx, al
  5186 00001AE2 8B1E[346C]              	mov	bx, [WAVE_SampleRate] ; sampling rate (Hz)
  5187                                  	SbOut	bh	; sampling rate high byte
    24                              <1> %%wait:
    25 00001AE6 EC                  <1>  in al, dx
    26 00001AE7 08C0                <1>  or al, al
    27 00001AE9 78FB                <1>  js short %%wait
    28 00001AEB 88F8                <1>  mov al, %1
    29 00001AED EE                  <1>  out dx, al
  5188                                  	SbOut	bl	; sampling rate low byte
    24                              <1> %%wait:
    25 00001AEE EC                  <1>  in al, dx
    26 00001AEF 08C0                <1>  or al, al
    27 00001AF1 78FB                <1>  js short %%wait
    28 00001AF3 88D8                <1>  mov al, %1
    29 00001AF5 EE                  <1>  out dx, al
  5189                                  
  5190                                  	; 25/11/2024
  5191                                  StartDMA:
  5192                                  	; autoinitialized mode
  5193 00001AF6 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  5194 00001AFB 740E                    	je	short sb_play_1
  5195                                  	; 8 bit samples
  5196 00001AFD BBC600                  	mov	bx, 0C6h ; 8 bit output (0C6h)
  5197 00001B00 803E[326C]02            	cmp	byte [WAVE_NumChannels], 2 ; 1 = mono, 2 = stereo
  5198 00001B05 7211                    	jb	short sb_play_2
  5199 00001B07 B720                    	mov	bh, 20h	; 8 bit stereo (20h)
  5200 00001B09 EB0D                    	jmp	short sb_play_2
  5201                                  sb_play_1:
  5202                                  	; 16 bit samples
  5203 00001B0B BBB610                  	mov	bx, 10B6h ; 16 bit output (0B6h)
  5204 00001B0E 803E[326C]02            	cmp	byte [WAVE_NumChannels], 2 ; 1 = mono, 2 = stereo
  5205 00001B13 7203                    	jb	short sb_play_2
  5206 00001B15 80C720                  	add	bh, 20h	; 16 bit stereo (30h)
  5207                                  sb_play_2:
  5208                                  	; PCM output (8/16 bit mono autoinitialized transfer)
  5209                                  	SbOut   bl	; bCommand
    24                              <1> %%wait:
    25 00001B18 EC                  <1>  in al, dx
    26 00001B19 08C0                <1>  or al, al
    27 00001B1B 78FB                <1>  js short %%wait
    28 00001B1D 88D8                <1>  mov al, %1
    29 00001B1F EE                  <1>  out dx, al
  5210                                  	SbOut	bh	; bMode
    24                              <1> %%wait:
    25 00001B20 EC                  <1>  in al, dx
    26 00001B21 08C0                <1>  or al, al
    27 00001B23 78FB                <1>  js short %%wait
    28 00001B25 88F8                <1>  mov al, %1
    29 00001B27 EE                  <1>  out dx, al
  5211                                  	; 25/11/2024
  5212                                  	;mov	bx, dma_buffer_size/2
  5213                                  	; 08/02/2025 (*)
  5214 00001B28 8B1E[BA76]              	mov	bx, [buffersize] ; = [loadsize] for SB16
  5215                                  			; half buffer size
  5216 00001B2C 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit DMA
  5217 00001B31 7502                    	jne	short sb_play_3
  5218 00001B33 D1EB                    	shr	bx, 1	; byte count to word count (samples)
  5219                                  sb_play_3:
  5220 00001B35 4B                      	dec	bx ; wBlkSize is one less than the actual size
  5221                                  	SbOut   bl
    24                              <1> %%wait:
    25 00001B36 EC                  <1>  in al, dx
    26 00001B37 08C0                <1>  or al, al
    27 00001B39 78FB                <1>  js short %%wait
    28 00001B3B 88D8                <1>  mov al, %1
    29 00001B3D EE                  <1>  out dx, al
  5222                                  	SbOut   bh
    24                              <1> %%wait:
    25 00001B3E EC                  <1>  in al, dx
    26 00001B3F 08C0                <1>  or al, al
    27 00001B41 78FB                <1>  js short %%wait
    28 00001B43 88F8                <1>  mov al, %1
    29 00001B45 EE                  <1>  out dx, al
  5223                                  
  5224                                  	; 24/11/2024
  5225                                  	;mov	byte [stopped], 0 ; playing !
  5226                                  
  5227                                  	; 06/02/2025
  5228 00001B46 C606[AD6C]0D            	mov	byte [volume], 13 ; max = 15, min = 0
  5229                                  
  5230                                  	; 07/02/2025
  5231 00001B4B E877E8                  	call	SetPCMOutVolume
  5232                                  
  5233 00001B4E C3                      	retn
  5234                                  
  5235                                  ;-----------------------------------------------------------------------------
  5236                                  
  5237                                  	; 09/02/2025
  5238                                  	; 06/02/2025
  5239                                  	; 02/01/2025
  5240                                  	; 24/11/2024
  5241                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
  5242                                  	;      sb16_stop procedure (06/08/2022, v2.0.5)	
  5243                                  sb16_stop:
  5244                                  	; 09/02/2025
  5245                                  	; 02/01/2025
  5246                                  	;mov	byte [stopped], 2
  5247                                  	;
  5248 00001B4F 8B16[A66C]              	mov	dx, [audio_io_base]
  5249                                  	;add	dx, 0Ch
  5250 00001B53 80C20C                  	add	dl, 0Ch
  5251                                  
  5252 00001B56 B3D9                    	mov	bl, 0D9h ; exit auto-initialize 16 bit transfer
  5253                                  	; stop  autoinitialized DMA transfer mode 
  5254 00001B58 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  5255 00001B5D 7402                    	je	short sb16_stop_1
  5256                                  	;mov	bl, 0DAh ; exit auto-initialize 8 bit transfer
  5257 00001B5F FEC3                    	inc	bl
  5258                                  sb16_stop_1:
  5259                                  	SbOut	bl ; exit auto-initialize transfer command
    24                              <1> %%wait:
    25 00001B61 EC                  <1>  in al, dx
    26 00001B62 08C0                <1>  or al, al
    27 00001B64 78FB                <1>  js short %%wait
    28 00001B66 88D8                <1>  mov al, %1
    29 00001B68 EE                  <1>  out dx, al
  5260                                  
  5261 00001B69 30C0                    	xor     al, al ; stops all DMA processes on selected channel
  5262                                  
  5263 00001B6B 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  5264 00001B70 7404                    	je	short sb16_stop_2
  5265 00001B72 E60C                    	out	0Ch, al ; clear selected channel register
  5266 00001B74 EB02                    	jmp	short sb16_stop_3
  5267                                  
  5268                                  sb16_stop_2:
  5269 00001B76 E6D8                    	out	0D8h, al ; clear selected channel register
  5270                                  
  5271                                  sb16_stop_3:
  5272                                  	; 24/11/2024
  5273 00001B78 C606[AE6C]02            	mov	byte [stopped], 2 ; stop !
  5274                                  SbDone:
  5275                                  	;mov	dx, [audio_io_base]
  5276                                  	;add	dx, 0Ch
  5277                                  	SbOut   0D0h
    24                              <1> %%wait:
    25 00001B7D EC                  <1>  in al, dx
    26 00001B7E 08C0                <1>  or al, al
    27 00001B80 78FB                <1>  js short %%wait
    28 00001B82 B0D0                <1>  mov al, %1
    29 00001B84 EE                  <1>  out dx, al
  5278                                  	SbOut   0D3h
    24                              <1> %%wait:
    25 00001B85 EC                  <1>  in al, dx
    26 00001B86 08C0                <1>  or al, al
    27 00001B88 78FB                <1>  js short %%wait
    28 00001B8A B0D3                <1>  mov al, %1
    29 00001B8C EE                  <1>  out dx, al
  5279                                  sb16_stop_4:
  5280 00001B8D C3                      	retn
  5281                                  
  5282                                  ;-----------------------------------------------------------------------------
  5283                                  
  5284                                  	; 06/02/2025
  5285                                  	; 02/01/2025
  5286                                  	; 24/11/2024
  5287                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
  5288                                  	;      sb16_pause procedure (06/08/2022, v2.0.5)	
  5289                                  sb16_pause:
  5290                                  	; 02/01/2025
  5291 00001B8E C606[AE6C]01            	mov	byte [stopped], 1 ; paused
  5292                                  	;
  5293 00001B93 8B16[A66C]              	mov	dx, [audio_io_base]
  5294                                  	;add	dx, 0Ch ; Command & Data Port
  5295 00001B97 80C20C                  	add	dl, 0Ch
  5296 00001B9A 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  5297 00001B9F 7404                    	je	short sb_pause_1
  5298                                  	; 8 bit samples
  5299 00001BA1 B3D0                    	mov	bl, 0D0h ; 8 bit DMA mode
  5300 00001BA3 EB02                    	jmp	short sb_pause_2
  5301                                  sb_pause_1:
  5302                                  	; 16 bit samples
  5303 00001BA5 B3D5                    	mov	bl, 0D5h ; 16 bit DMA mode
  5304                                  sb_pause_2:
  5305                                  	SbOut   bl ; bCommand
    24                              <1> %%wait:
    25 00001BA7 EC                  <1>  in al, dx
    26 00001BA8 08C0                <1>  or al, al
    27 00001BAA 78FB                <1>  js short %%wait
    28 00001BAC 88D8                <1>  mov al, %1
    29 00001BAE EE                  <1>  out dx, al
  5306                                  sb_pause_3:
  5307 00001BAF C3                      	retn
  5308                                  
  5309                                  ;-----------------------------------------------------------------------------
  5310                                  
  5311                                  	; 06/02/2025
  5312                                  	; 02/01/2025
  5313                                  	; 24/11/2024
  5314                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
  5315                                  	;      sb16_continue procedure (06/08/2022, v2.0.5)
  5316                                  sb16_play:
  5317                                  sb16_continue:
  5318                                  	; 02/01/2025
  5319                                  	; continue to play (after pause)
  5320 00001BB0 C606[AE6C]00            	mov	byte [stopped], 0
  5321                                  	;
  5322 00001BB5 8B16[A66C]              	mov	dx, [audio_io_base]
  5323                                  	;add	dx, 0Ch ; Command & Data Port
  5324 00001BB9 80C20C                  	add	dl, 0Ch
  5325 00001BBC 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16 ; 16 bit samples
  5326 00001BC1 7404                    	je	short sb_cont_1
  5327                                  	; 8 bit samples
  5328 00001BC3 B3D4                    	mov	bl, 0D4h ; 8 bit DMA mode
  5329 00001BC5 EB02                    	jmp	short sb_cont_2
  5330                                  sb_cont_1:
  5331                                  	; 16 bit samples
  5332 00001BC7 B3D6                    	mov	bl, 0D6h ; 16 bit DMA mode
  5333                                  sb_cont_2:     
  5334                                  	SbOut   bl ; bCommand
    24                              <1> %%wait:
    25 00001BC9 EC                  <1>  in al, dx
    26 00001BCA 08C0                <1>  or al, al
    27 00001BCC 78FB                <1>  js short %%wait
    28 00001BCE 88D8                <1>  mov al, %1
    29 00001BD0 EE                  <1>  out dx, al
  5335                                  sb_cont_3:
  5336 00001BD1 C3                      	retn
  5337                                  
  5338                                  ;=============================================================================
  5339                                  ;	AC'97 Audio System Initialization
  5340                                  ;============================================================================
  5341                                  
  5342                                  	; 06/02/2025
  5343                                  ac97_init:
  5344                                  	; 04/02/2025 - cgaplay.asm
  5345                                  codecConfig:
  5346                                  	; 30/05/2024
  5347                                  	; 19/05/2024
  5348                                  	; 19/11/2023
  5349                                  	; 15/11/2023
  5350                                  	; 04/11/2023
  5351                                  	; 17/02/2017 
  5352                                  	; 07/11/2016 (Erdogan Tan)
  5353                                  
  5354                                  	;AC97_EA_VRA equ 1
  5355                                  	AC97_EA_VRA equ BIT0
  5356                                  
  5357                                  	; 04/11/2023
  5358                                  init_ac97_controller:
  5359 00001BD2 66A1[A26C]              	mov	eax, [bus_dev_fn]
  5360 00001BD6 B004                    	mov	al, PCI_CMD_REG
  5361 00001BD8 E80806                  	call	pciRegRead16		; read PCI command register
  5362 00001BDB 80CA05                  	or      dl, IO_ENA+BM_ENA	; enable IO and bus master
  5363 00001BDE E87E06                  	call	pciRegWrite16
  5364                                  
  5365                                  	;call	delay_100ms
  5366                                  
  5367                                  	; 19/05/2024
  5368                                  	; ('PLAYMOD3.ASM', Erdogan Tan, 18/05/2024)
  5369                                  
  5370                                  init_ac97_codec:
  5371                                  	; 18/11/2023
  5372 00001BE1 BD2800                  	mov	bp, 40
  5373                                  	; 29/05/2024
  5374                                  	;mov	bp, 1000
  5375                                  _initc_1:
  5376                                  	; 30/05/2024
  5377 00001BE4 BA3000                  	mov	dx, GLOB_STS_REG ; 30h
  5378 00001BE7 0316[A86C]              	add	dx, [NABMBAR]
  5379 00001BEB 66ED                    	in	eax, dx
  5380                                  
  5381                                  	; 19/05/2024
  5382 00001BED E8B404                  	call	delay1_4ms
  5383                                  
  5384 00001BF0 6683F8FF                	cmp	eax, 0FFFFFFFFh ; -1
  5385 00001BF4 7508                    	jne	short _initc_3
  5386                                  _initc_2:
  5387 00001BF6 4D                      	dec	bp
  5388 00001BF7 741E                    	jz	short _ac97_codec_ready
  5389                                  
  5390 00001BF9 E89D04                  	call	delay_100ms
  5391 00001BFC EBE6                    	jmp	short _initc_1
  5392                                  _initc_3:
  5393 00001BFE 66A900030010            	test	eax, CTRL_ST_CREADY
  5394 00001C04 7511                    	jnz	short _ac97_codec_ready
  5395                                  
  5396                                  	; 30/05/2024
  5397 00001C06 803E[2F69]01            	cmp	byte [reset], 1
  5398 00001C0B 73E9                    	jnb	short _initc_2
  5399                                  
  5400 00001C0D E81D01                  	call	reset_ac97_codec
  5401                                  	; 30/05/2024
  5402 00001C10 C606[2F69]01            	mov	byte [reset], 1
  5403                                  	; 19/05/2024
  5404 00001C15 EBDF                    	jmp	short _initc_2
  5405                                  
  5406                                  _ac97_codec_ready:
  5407 00001C17 8B16[A66C]              	mov	dx, [NAMBAR]
  5408                                  	;add	dx, 0 ; ac_reg_0 ; reset register
  5409 00001C1B EF                      	out	dx, ax
  5410                                  	
  5411 00001C1C E87A04                  	call	delay_100ms
  5412                                  
  5413                                  	; 19/11/2023
  5414 00001C1F 09ED                    	or	bp, bp
  5415 00001C21 7525                    	jnz	short _ac97_codec_init_ok
  5416                                  
  5417 00001C23 31C0                    	xor	ax, ax ; 0
  5418 00001C25 8B16[A66C]              	mov	dx, [NAMBAR]
  5419 00001C29 83C226                  	add	dx, CODEC_REG_POWERDOWN
  5420 00001C2C EF                      	out	dx, ax
  5421                                  
  5422                                  	; 30/05/2024
  5423 00001C2D E87404                  	call	delay1_4ms
  5424                                  
  5425                                  	; 19/11/2023
  5426                                  	; wait for 1 second
  5427                                  	; 19/05/2024
  5428 00001C30 B9E803                  	mov	cx, 1000 ; 1000*4*0.25ms = 1s
  5429                                  	;;mov	cx, 10
  5430                                  	; 30/05/2024
  5431                                  	;mov	cx, 40
  5432                                  _ac97_codec_rloop:
  5433                                  	;call	delay_100ms
  5434                                  
  5435                                  	; 30/05/2024
  5436 00001C33 8B16[A66C]              	mov	dx, [NAMBAR]
  5437 00001C37 83C226                  	add	dx, CODEC_REG_POWERDOWN
  5438 00001C3A ED                      	in	ax, dx
  5439                                  
  5440 00001C3B E86604                  	call	delay1_4ms
  5441                                  	
  5442 00001C3E 83E00F                  	and	ax, 0Fh
  5443 00001C41 3C0F                    	cmp	al, 0Fh
  5444 00001C43 7403                    	je	short _ac97_codec_init_ok
  5445 00001C45 E2EC                    	loop	_ac97_codec_rloop 
  5446                                  
  5447                                  init_ac97_codec_err1:
  5448                                  	;stc	; cf = 1 ; 19/05/2024
  5449                                  init_ac97_codec_err2:
  5450 00001C47 C3                      	retn
  5451                                  
  5452                                  _ac97_codec_init_ok:
  5453 00001C48 E89B00                  	call 	reset_ac97_controller
  5454                                  
  5455                                  	; 30/05/2024
  5456                                  	; 19/05/2024
  5457                                  	;call	delay_100ms
  5458                                  
  5459                                  	; 30/05/2024
  5460 00001C4B E85604                  	call	delay1_4ms
  5461 00001C4E E85304                  	call	delay1_4ms
  5462 00001C51 E85004                  	call	delay1_4ms
  5463 00001C54 E84D04                  	call	delay1_4ms
  5464                                  
  5465                                  setup_ac97_codec:
  5466                                  	; 12/11/2023
  5467 00001C57 813E[346C]80BB          	cmp	word [WAVE_SampleRate], 48000
  5468 00001C5D 7453                    	je	short skip_rate
  5469                                  	
  5470                                  	; 30/05/2024
  5471                                  	; 19/05/2024
  5472                                  	;call	delay1_4ms
  5473                                  
  5474                                  	; 30/05/2024
  5475                                  	;cmp	byte [VRA], 0
  5476                                  	;jna	short skip_rate
  5477                                  
  5478                                  	; 11/11/2023
  5479 00001C5F 8B16[A66C]              	mov	dx, [NAMBAR]
  5480 00001C63 83C22A                  	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5481 00001C66 ED                      	in	ax, dx
  5482                                  
  5483                                  	; 30/05/2024
  5484                                  	; 19/05/2024
  5485 00001C67 E83A04                  	call	delay1_4ms
  5486                                  	
  5487                                  	; 13/11/2024
  5488                                  	;and	al, NOT BIT1 ; Clear DRA
  5489                                  	;;;
  5490                                  	; 30/05/2024
  5491                                  	;and	al, NOT (BIT1+BIT0) ; Clear DRA+VRA
  5492                                  	; 01/01/2025 (NASM)
  5493 00001C6A 24FC                    	and	al, ~(BIT1+BIT0)
  5494 00001C6C EF                      	out	dx, ax
  5495                                  
  5496 00001C6D E83D01                  	call	check_vra
  5497                                  
  5498 00001C70 803E[9B6C]00            	cmp	byte [VRA], 0
  5499 00001C75 763B                    	jna	short skip_rate
  5500                                  
  5501 00001C77 8B16[A66C]              	mov	dx, [NAMBAR]
  5502 00001C7B 83C22A                  	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5503 00001C7E ED                      	in	ax, dx
  5504                                  	;and	al, ~BIT1 ; Clear DRA
  5505                                  	;;;
  5506                                  
  5507 00001C7F 0C01                    	or	al, AC97_EA_VRA ; 1 ; 04/11/2023
  5508                                  	; 30/05/2024
  5509 00001C81 8B16[A66C]              	mov	dx, [NAMBAR]
  5510 00001C85 83C22A                  	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5511                                  
  5512 00001C88 EF                      	out	dx, ax			; Enable variable rate audio
  5513                                  
  5514 00001C89 B90A00                  	mov	cx, 10
  5515                                  check_vra_loop:
  5516 00001C8C E80A04                  	call	delay_100ms
  5517                                  	; 30/05/2024
  5518                                  	;call	delay1_4ms
  5519                                  
  5520                                  	; 30/05/2024
  5521 00001C8F 8B16[A66C]              	mov	dx, [NAMBAR]
  5522 00001C93 83C22A                  	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5523                                  	; 11/11/2023
  5524 00001C96 ED                      	in	ax, dx
  5525                                  	
  5526 00001C97 A801                    	test	al, AC97_EA_VRA ; 1
  5527 00001C99 7509                    	jnz	short set_rate
  5528                                  
  5529                                  	; 11/11/2023
  5530 00001C9B E2EF                    	loop	check_vra_loop
  5531                                  
  5532                                  ;vra_not_supported:	; 19/05/2024
  5533 00001C9D C606[9B6C]00            	mov	byte [VRA], 0
  5534 00001CA2 EB0E                    	jmp	short skip_rate
  5535                                  
  5536                                  set_rate:
  5537 00001CA4 A1[346C]                	mov	ax, [WAVE_SampleRate] ; 17/02/2017 (Erdogan Tan)
  5538                                  
  5539 00001CA7 8B16[A66C]              	mov    	dx, [NAMBAR]               	
  5540 00001CAB 83C22C                  	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch
  5541 00001CAE EF                      	out	dx, ax 			; PCM Front/Center Output Sample Rate
  5542                                  
  5543                                  	;call	delay_100ms
  5544                                  	; 30/05/2024
  5545 00001CAF E8F203                  	call	delay1_4ms
  5546                                  
  5547                                  	; 12/11/2023
  5548                                  skip_rate:
  5549 00001CB2 B80202                  	mov	ax, 0202h
  5550 00001CB5 8B16[A66C]                	mov	dx, [NAMBAR]
  5551 00001CB9 83C202                    	add	dx, CODEC_MASTER_VOL_REG	; 02h
  5552 00001CBC EF                      	out	dx, ax
  5553                                  
  5554                                  	; 11/11/2023
  5555 00001CBD E8E403                  	call	delay1_4ms
  5556 00001CC0 E8E103                  	call	delay1_4ms
  5557 00001CC3 E8DE03                  	call	delay1_4ms
  5558 00001CC6 E8DB03                  	call	delay1_4ms
  5559                                  
  5560 00001CC9 B80202                  	mov	ax, 0202h
  5561 00001CCC 8B16[A66C]                	mov	dx, [NAMBAR]
  5562 00001CD0 83C218                    	add	dx, CODEC_PCM_OUT_REG		; 18h
  5563 00001CD3 EF                        	out	dx, ax
  5564                                  	
  5565                                  	; 11/11/2023
  5566 00001CD4 E8CD03                  	call	delay1_4ms
  5567 00001CD7 E8CA03                  	call	delay1_4ms
  5568 00001CDA E8C703                  	call	delay1_4ms
  5569 00001CDD E8C403                  	call	delay1_4ms
  5570                                  
  5571                                  	; 30/05/2024
  5572                                  	; 19/05/2024
  5573                                  	;clc
  5574                                  
  5575                                  	; 06/02/2025
  5576 00001CE0 C606[AD6C]1D            	mov	byte [volume], 29 ; max = 31, min = 0
  5577                                  
  5578 00001CE5 C3                              retn
  5579                                  
  5580                                  ;-----------------------------------------------------------------------------
  5581                                  
  5582                                  reset_ac97_controller:
  5583                                  	; 19/05/2024
  5584                                  	; 11/11/2023
  5585                                  	; 10/06/2017
  5586                                  	; 29/05/2017
  5587                                  	; 28/05/2017
  5588                                  	; reset AC97 audio controller registers
  5589 00001CE6 31C0                    	xor     ax, ax
  5590 00001CE8 BA0B00                          mov	dx, PI_CR_REG
  5591 00001CEB 0316[A86C]              	add	dx, [NABMBAR]
  5592 00001CEF EE                      	out     dx, al
  5593                                  
  5594                                  	; 19/05/2024
  5595 00001CF0 E8B103                  	call	delay1_4ms
  5596                                  
  5597 00001CF3 BA1B00                          mov     dx, PO_CR_REG
  5598 00001CF6 0316[A86C]              	add	dx, [NABMBAR]
  5599 00001CFA EE                      	out     dx, al
  5600                                  
  5601                                  	; 19/05/2024
  5602 00001CFB E8A603                  	call	delay1_4ms
  5603                                  
  5604 00001CFE BA2B00                          mov     dx, MC_CR_REG
  5605 00001D01 0316[A86C]              	add	dx, [NABMBAR]
  5606 00001D05 EE                      	out     dx, al
  5607                                  
  5608                                  	; 19/05/2024
  5609 00001D06 E89B03                  	call	delay1_4ms
  5610                                  
  5611 00001D09 B002                            mov     al, RR
  5612 00001D0B BA0B00                          mov     dx, PI_CR_REG
  5613 00001D0E 0316[A86C]              	add	dx, [NABMBAR]
  5614 00001D12 EE                      	out     dx, al
  5615                                  
  5616                                  	; 19/05/2024
  5617 00001D13 E88E03                  	call	delay1_4ms
  5618                                  
  5619 00001D16 BA1B00                          mov     dx, PO_CR_REG
  5620 00001D19 0316[A86C]              	add	dx, [NABMBAR]
  5621 00001D1D EE                      	out     dx, al
  5622                                  
  5623                                  	; 19/05/2024
  5624 00001D1E E88303                  	call	delay1_4ms
  5625                                  
  5626 00001D21 BA2B00                          mov     dx, MC_CR_REG
  5627 00001D24 0316[A86C]              	add	dx, [NABMBAR]
  5628 00001D28 EE                      	out     dx, al
  5629                                  
  5630                                  	; 19/05/2024
  5631 00001D29 E87803                  	call	delay1_4ms
  5632                                  
  5633 00001D2C C3                      	retn
  5634                                  
  5635                                  ;-----------------------------------------------------------------------------
  5636                                  
  5637                                  reset_ac97_codec:
  5638                                  	; 11/11/2023
  5639                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  5640 00001D2D BA2C00                  	mov	dx, GLOB_CNT_REG ; 2Ch
  5641 00001D30 0316[A86C]              	add	dx, [NABMBAR]
  5642 00001D34 66ED                    	in	eax, dx
  5643                                  
  5644                                  	;test	eax, 2
  5645                                  	; 06/08/2022
  5646 00001D36 A802                    	test	al, 2
  5647 00001D38 7405                    	jz	short _r_ac97codec_cold
  5648                                  
  5649 00001D3A E80E00                  	call	warm_ac97codec_reset
  5650 00001D3D 7306                    	jnc	short _r_ac97codec_ok
  5651                                  _r_ac97codec_cold:
  5652 00001D3F E83400                          call    cold_ac97codec_reset
  5653 00001D42 7301                            jnc     short _r_ac97codec_ok
  5654                                  	
  5655                                  	; 16/04/2017
  5656                                          ;xor	eax, eax	; timeout error
  5657                                         	;stc
  5658 00001D44 C3                      	retn
  5659                                  
  5660                                  _r_ac97codec_ok:
  5661 00001D45 6631C0                          xor     eax, eax
  5662                                          ;mov	al, VIA_ACLINK_C00_READY ; 1
  5663 00001D48 FEC0                            inc	al
  5664 00001D4A C3                      	retn
  5665                                  
  5666                                  ;-----------------------------------------------------------------------------
  5667                                  
  5668                                  warm_ac97codec_reset:
  5669                                  	; 11/11/2023
  5670                                  	; 06/08/2022 - TRDOS 386 v2.0.5
  5671                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  5672 00001D4B 66B806000000            	mov	eax, 6
  5673 00001D51 BA2C00                  	mov	dx, GLOB_CNT_REG ; 2Ch
  5674 00001D54 0316[A86C]              	add	dx, [NABMBAR]
  5675 00001D58 66EF                    	out	dx, eax
  5676                                  
  5677 00001D5A B90A00                  	mov	cx, 10	; total 1s
  5678                                  _warm_ac97c_rst_wait:
  5679 00001D5D E83903                  	call	delay_100ms
  5680                                  
  5681 00001D60 BA3000                  	mov	dx, GLOB_STS_REG ; 30h
  5682 00001D63 0316[A86C]              	add	dx, [NABMBAR]
  5683 00001D67 66ED                    	in	eax, dx
  5684                                  
  5685 00001D69 66A900030010            	test	eax, CTRL_ST_CREADY
  5686 00001D6F 7504                    	jnz	short _warm_ac97c_rst_ok
  5687                                  
  5688 00001D71 49                              dec     cx
  5689 00001D72 75E9                            jnz     short _warm_ac97c_rst_wait
  5690                                  
  5691                                  _warm_ac97c_rst_fail:
  5692 00001D74 F9                              stc
  5693                                  _warm_ac97c_rst_ok:
  5694 00001D75 C3                      	retn
  5695                                  
  5696                                  ;-----------------------------------------------------------------------------
  5697                                  
  5698                                  cold_ac97codec_reset:
  5699                                  	; 11/11/2023
  5700                                  	; 06/08/2022 - TRDOS 386 v2.0.5
  5701                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  5702 00001D76 66B802000000                    mov	eax, 2
  5703 00001D7C BA2C00                  	mov	dx, GLOB_CNT_REG ; 2Ch
  5704 00001D7F 0316[A86C]              	add	dx, [NABMBAR]
  5705 00001D83 66EF                    	out	dx, eax
  5706                                  
  5707 00001D85 E81103                  	call	delay_100ms 	; wait 100 ms
  5708 00001D88 E80E03                  	call	delay_100ms 	; wait 100 ms
  5709 00001D8B E80B03                  	call	delay_100ms 	; wait 100 ms
  5710 00001D8E E80803                  	call	delay_100ms 	; wait 100 ms
  5711                                  
  5712 00001D91 B91000                  	mov	cx, 16	; total 20*100 ms = 2s
  5713                                  
  5714                                  _cold_ac97c_rst_wait:
  5715 00001D94 BA3000                  	mov	dx, GLOB_STS_REG ; 30h
  5716 00001D97 0316[A86C]              	add	dx, [NABMBAR]
  5717 00001D9B 66ED                    	in	eax, dx
  5718                                  
  5719 00001D9D 66A900030010            	test	eax, CTRL_ST_CREADY
  5720 00001DA3 7507                    	jnz	short _cold_ac97c_rst_ok
  5721                                  
  5722 00001DA5 E8F102                  	call	delay_100ms
  5723                                  
  5724 00001DA8 49                              dec     cx
  5725 00001DA9 75E9                            jnz     short _cold_ac97c_rst_wait
  5726                                  
  5727                                  _cold_ac97c_rst_fail:
  5728 00001DAB F9                              stc
  5729                                  _cold_ac97c_rst_ok:
  5730 00001DAC C3                      	retn
  5731                                  
  5732                                  ;-----------------------------------------------------------------------------
  5733                                  
  5734                                  ; 13/11/2024
  5735                                  ; 30/05/2024
  5736                                  %if 1
  5737                                  check_vra:
  5738                                  	; 30/05/2024
  5739 00001DAD C606[9B6C]01            	mov	byte [VRA], 1
  5740                                  
  5741                                  	; 29/05/2024 - audio.s (TRDOS 386 Kernel) - 27/05/2024
  5742                                  	; 24/05/2024
  5743                                  	; 23/05/2024
  5744 00001DB2 8B16[A66C]              	mov	dx, [NAMBAR]
  5745 00001DB6 83C228                  	add	dx, CODEC_EXT_AUDIO_REG	; 28h
  5746 00001DB9 ED                      	in	ax, dx
  5747                                  
  5748                                  	; 30/05/2024
  5749                                  	; 23/05/2024
  5750 00001DBA E8E702                  	call	delay1_4ms
  5751                                  
  5752                                  	; 30/05/2024
  5753 00001DBD A801                    	test	al, BIT0
  5754                                  	;test	al, 1 ; BIT0 ; Variable Rate Audio bit
  5755 00001DBF 7505                    	jnz	short check_vra_ok
  5756                                  
  5757                                  vra_not_supported:
  5758                                  	; 13/11/2023
  5759 00001DC1 C606[9B6C]00            	mov	byte [VRA], 0
  5760                                  check_vra_ok:
  5761 00001DC6 C3                      	retn
  5762                                  %endif
  5763                                  
  5764                                  ;-----------------------------------------------------------------------------
  5765                                  ;-----------------------------------------------------------------------------
  5766                                  
  5767                                  	; 08/02/2025 (*)
  5768                                  	; !!!! 18.2 block/second buffer sizing for proper wave scopes !!!!
  5769                                  	; (wave graphics synchronization) 
  5770                                  
  5771                                  	; 08/02/2025
  5772                                  ac97_play_setup:
  5773                                  
  5774                                  	; 07/02/2025
  5775                                  	; 06/02/2025
  5776                                  
  5777                                  ;ac97_init_play:
  5778                                  	;;;
  5779                                  	; 04/02/2025
  5780                                  	; 01/01/2025 (cgaplay.asm)
  5781                                  	; 28/11/2024 (ac97play.asm)
  5782                                  	; 25/11/2023
  5783                                  	; 18/11/2023 (ich_wav4.asm)
  5784                                  	; 13/11/2023 (ich_wav3.asm)
  5785                                  
  5786 00001DC7 803E[9B6C]01            	cmp	byte [VRA], 1
  5787 00001DCC 7209                    	jb	short chk_sample_rate
  5788                                  
  5789                                  playwav_48_khz:
  5790 00001DCE C706[B676][AF04]        	mov	word [loadfromwavfile], loadFromFile
  5791                                  
  5792                                  ; 08/02/2025
  5793                                  %if 0
  5794                                  	;mov	word [loadsize], 0 ; 65536
  5795                                  	;;;
  5796                                  	; 17/11/2024
  5797                                  	;mov	word [buffersize], 32768
  5798                                  	mov	ax, BUFFERSIZE/2 ; 32760
  5799                                  	; 07/02/2025
  5800                                  	; ax = 16840
  5801                                  	mov	[buffersize], ax	; 16 bit samples
  5802                                  	shl	ax, 1			; bytes
  5803                                  	mov	cl, [fbs_shift]
  5804                                  	shr	ax, cl
  5805                                  	mov	[loadsize], ax ; 16380 or 32760 or 65520
  5806                                  	;;;
  5807                                  	; 07/02/2025
  5808                                  	;jmp	_PlayNow
  5809                                  %endif
  5810                                  	; 08/02/2025
  5811                                  	;retn
  5812                                  	; 09/02/2025
  5813 00001DD4 E9D801                  	jmp	allocate_memory
  5814                                  
  5815                                  chk_sample_rate:
  5816                                  	; set conversion parameters
  5817                                  	; (for 8, 11.025, 16, 22.050, 24, 32 kHZ)
  5818 00001DD7 A1[346C]                	mov	ax, [WAVE_SampleRate]
  5819 00001DDA 3D80BB                  	cmp	ax, 48000
  5820 00001DDD 74EF                    	je	short playwav_48_khz
  5821                                  chk_22khz:
  5822 00001DDF 3D2256                  	cmp	ax, 22050
  5823 00001DE2 752F                    	jne	short chk_11khz
  5824 00001DE4 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  5825 00001DE9 760F                    	jna	short chk_22khz_1
  5826 00001DEB BB[B00E]                	mov	bx, load_22khz_stereo_16_bit
  5827 00001DEE 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5828 00001DF3 7512                    	jne	short chk_22khz_2
  5829 00001DF5 BB[440E]                	mov	bx, load_22khz_mono_16_bit
  5830 00001DF8 EB0D                    	jmp	short chk_22khz_2
  5831                                  chk_22khz_1:
  5832 00001DFA BB[DC0D]                	mov	bx, load_22khz_stereo_8_bit
  5833 00001DFD 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5834 00001E02 7503                    	jne	short chk_22khz_2
  5835 00001E04 BB[700D]                	mov	bx, load_22khz_mono_8_bit
  5836                                  chk_22khz_2:
  5837                                  	;;mov	ax, 7514  ; (442*17)
  5838                                  	; 07/02/2025
  5839                                  	;mov	ax, 3842  ; (226*17)	
  5840                                  	; 08/02/2025 (*)
  5841 00001E07 B8B704                  	mov	ax, 1207  ; (71*17)		
  5842 00001E0A BA2500                  	mov	dx, 37
  5843 00001E0D B91100                  	mov	cx, 17
  5844 00001E10 E97701                  	jmp	set_sizes
  5845                                  chk_11khz:
  5846 00001E13 3D112B                  	cmp	ax, 11025
  5847 00001E16 752F                    	jne	short chk_44khz
  5848 00001E18 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  5849 00001E1D 760F                    	jna	short chk_11khz_1
  5850 00001E1F BB[5010]                	mov	bx, load_11khz_stereo_16_bit
  5851 00001E22 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5852 00001E27 7512                    	jne	short chk_11khz_2
  5853 00001E29 BB[F20F]                	mov	bx, load_11khz_mono_16_bit
  5854 00001E2C EB0D                    	jmp	short chk_11khz_2
  5855                                  chk_11khz_1:
  5856 00001E2E BB[940F]                	mov	bx, load_11khz_stereo_8_bit
  5857 00001E31 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5858 00001E36 7503                    	jne	short chk_11khz_2
  5859 00001E38 BB[330F]                	mov	bx, load_11khz_mono_8_bit
  5860                                  chk_11khz_2:
  5861                                  	;;mov	ax, 3757  ; (221*17)
  5862                                  	; 07/02/2025
  5863                                  	;mov	ax, 1921  ; (113*17)
  5864                                  	; 08/02/2025 (*)
  5865 00001E3B B86402                  	mov	ax, 612  ; (36*17)	
  5866 00001E3E BA4A00                  	mov	dx, 74
  5867 00001E41 B91100                  	mov	cx, 17
  5868 00001E44 E94301                  	jmp	set_sizes
  5869                                  chk_44khz:
  5870 00001E47 3D44AC                  	cmp	ax, 44100
  5871 00001E4A 752F                    	jne	short chk_16khz
  5872 00001E4C 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  5873 00001E51 760F                    	jna	short chk_44khz_1
  5874 00001E53 BB[0D12]                	mov	bx, load_44khz_stereo_16_bit
  5875 00001E56 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5876 00001E5B 7512                    	jne	short chk_44khz_2
  5877 00001E5D BB[B211]                	mov	bx, load_44khz_mono_16_bit
  5878 00001E60 EB0D                    	jmp	short chk_44khz_2
  5879                                  chk_44khz_1:
  5880 00001E62 BB[5111]                	mov	bx, load_44khz_stereo_8_bit
  5881 00001E65 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5882 00001E6A 7503                    	jne	short chk_44khz_2
  5883 00001E6C BB[F110]                	mov	bx, load_44khz_mono_8_bit
  5884                                  chk_44khz_2:
  5885                                  	;;;;mov	ax, 15065 ; (655*23)
  5886                                  	; 18/11/2023 ((file size + bss + stack) <= 64KB)
  5887                                  	;;;mov	ax, 14076 ; (612*23)
  5888                                  	; 17/11/2024
  5889                                  	;;mov	ax, 12650 ; (550*23)
  5890                                  	; 07/02/2025
  5891                                  	;mov	ax, 8418  ; (366*23)
  5892                                  	; 08/02/2025 (*)
  5893 00001E6F B88609                  	mov	ax, 2438  ; (106*23)
  5894 00001E72 BA1900                  	mov	dx, 25
  5895 00001E75 B91700                  	mov	cx, 23
  5896 00001E78 E90F01                  	jmp	set_sizes
  5897                                  chk_16khz:
  5898 00001E7B 3D803E                  	cmp	ax, 16000
  5899 00001E7E 752F                    	jne	short chk_8khz
  5900 00001E80 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  5901 00001E85 760F                    	jna	short chk_16khz_1
  5902 00001E87 BB[D009]                	mov	bx, load_16khz_stereo_16_bit
  5903 00001E8A 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5904 00001E8F 7512                    	jne	short chk_16khz_2
  5905 00001E91 BB[6C09]                	mov	bx, load_16khz_mono_16_bit
  5906 00001E94 EB0D                    	jmp	short chk_16khz_2
  5907                                  chk_16khz_1:
  5908 00001E96 BB[D908]                	mov	bx, load_16khz_stereo_8_bit
  5909 00001E99 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5910 00001E9E 7503                    	jne	short chk_16khz_2
  5911 00001EA0 BB[7208]                	mov	bx, load_16khz_mono_8_bit
  5912                                  chk_16khz_2:
  5913                                  	;;;mov	ax, 5461
  5914                                  	; 17/11/2024
  5915                                  	;;mov	ax, 5460
  5916                                  	; 07/02/2025
  5917                                  	;mov	ax, 2806
  5918                                  	; 08/02/2025 (*)
  5919 00001EA3 B86F03                  	mov	ax, 879
  5920 00001EA6 BA0300                  	mov	dx, 3
  5921 00001EA9 B90100                  	mov	cx, 1
  5922 00001EAC E9DB00                  	jmp	set_sizes
  5923                                  chk_8khz:
  5924 00001EAF 3D401F                  	cmp	ax, 8000
  5925 00001EB2 752F                    	jne	short chk_24khz
  5926 00001EB4 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  5927 00001EB9 760F                    	jna	short chk_8khz_1
  5928 00001EBB BB[8807]                	mov	bx, load_8khz_stereo_16_bit
  5929 00001EBE 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5930 00001EC3 7512                    	jne	short chk_8khz_2
  5931 00001EC5 BB[F406]                	mov	bx, load_8khz_mono_16_bit
  5932 00001EC8 EB0D                    	jmp	short chk_8khz_2
  5933                                  chk_8khz_1:
  5934 00001ECA BB[0106]                	mov	bx, load_8khz_stereo_8_bit
  5935 00001ECD 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5936 00001ED2 7503                    	jne	short chk_8khz_2
  5937 00001ED4 BB[4B05]                	mov	bx, load_8khz_mono_8_bit
  5938                                  chk_8khz_2:
  5939                                  	;;mov	ax, 2730
  5940                                  	; 07/02/2025
  5941                                  	;mov	ax, 1403
  5942                                  	; 08/02/2025 (*)
  5943 00001ED7 B8B801                  	mov	ax, 440
  5944 00001EDA BA0600                  	mov	dx, 6
  5945 00001EDD B90100                  	mov	cx, 1
  5946 00001EE0 E9A700                  	jmp	set_sizes  ; 02/02/2025
  5947                                  chk_24khz:
  5948 00001EE3 3DC05D                  	cmp	ax, 24000
  5949 00001EE6 752E                    	jne	short chk_32khz
  5950 00001EE8 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  5951 00001EED 760F                    	jna	short chk_24khz_1
  5952 00001EEF BB[740B]                	mov	bx, load_24khz_stereo_16_bit
  5953 00001EF2 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5954 00001EF7 7512                    	jne	short chk_24khz_2
  5955 00001EF9 BB[250B]                	mov	bx, load_24khz_mono_16_bit
  5956 00001EFC EB0D                    	jmp	short chk_24khz_2
  5957                                  chk_24khz_1:
  5958 00001EFE BB[BA0A]                	mov	bx, load_24khz_stereo_8_bit
  5959 00001F01 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5960 00001F06 7503                    	jne	short chk_24khz_2
  5961 00001F08 BB[680A]                	mov	bx, load_24khz_mono_8_bit
  5962                                  chk_24khz_2:
  5963                                  	;;;mov	ax, 8192
  5964                                  	; 17/11/2024
  5965                                  	;;mov	ax, 8190
  5966                                  	; 07/02/2025
  5967                                  	;mov	ax, 4210
  5968                                  	; 08/02/2025 (*)
  5969 00001F0B B82605                  	mov	ax, 1318
  5970 00001F0E BA0200                  	mov	dx, 2
  5971 00001F11 B90100                  	mov	cx, 1
  5972 00001F14 EB74                    	jmp	short set_sizes
  5973                                  
  5974                                  chk_32khz:
  5975 00001F16 3D007D                  	cmp	ax, 32000
  5976                                  	;jne	short vra_needed
  5977                                  	; 02/02/2025
  5978 00001F19 753E                    	jne	short chk_12khz
  5979 00001F1B 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  5980 00001F20 760F                    	jna	short chk_32khz_1
  5981 00001F22 BB[050D]                	mov	bx, load_32khz_stereo_16_bit
  5982 00001F25 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5983 00001F2A 7512                    	jne	short chk_32khz_2
  5984 00001F2C BB[B20C]                	mov	bx, load_32khz_mono_16_bit
  5985 00001F2F EB0D                    	jmp	short chk_32khz_2
  5986                                  chk_32khz_1:
  5987 00001F31 BB[380C]                	mov	bx, load_32khz_stereo_8_bit
  5988 00001F34 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  5989 00001F39 7503                    	jne	short chk_32khz_2
  5990 00001F3B BB[DD0B]                	mov	bx, load_32khz_mono_8_bit
  5991                                  chk_32khz_2:
  5992                                  	;;;mov	ax, 10922
  5993                                  	; 17/11/2024
  5994                                  	;;mov	ax, 10920
  5995                                  	; 07/02/2025
  5996                                  	;mov	ax, 5613
  5997                                  	; 08/02/2025 (*)
  5998 00001F3E B8DE06                  	mov	ax, 1758
  5999 00001F41 BA0300                  	mov	dx, 3
  6000 00001F44 B90200                  	mov	cx, 2
  6001                                  	; 02/02/2025
  6002 00001F47 EB41                    	jmp	short set_sizes
  6003                                  
  6004                                  	; 01/01/2025 (cgaplay.asm)
  6005                                  vra_needed:
  6006                                  	; 13/11/2023
  6007 00001F49 58                      	pop	ax ; discard return address to the caller
  6008                                  	; 30/05/2024
  6009                                  vra_err:
  6010                                  	sys_msg msg_no_vra, 0Fh
    16 00001F4A BE[156A]            <1>  mov si, %1
    17 00001F4D B30F                <1>  mov bl, %2
    18 00001F4F 30FF                <1>  xor bh, bh
    19 00001F51 B40E                <1>  mov ah, 0Eh
    20 00001F53 E81B06              <1>  call p_msg
  6011 00001F56 E933E1                  	jmp	Exit
  6012                                  
  6013                                  	;;;;
  6014                                  	; 02/02/2025
  6015                                  chk_12khz:
  6016 00001F59 3DE02E                  	cmp	ax, 12000
  6017 00001F5C 75EB                    	jne	short vra_needed
  6018 00001F5E 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  6019 00001F63 760F                    	jna	short chk_12khz_1
  6020 00001F65 BB[2D13]                	mov	bx, load_12khz_stereo_16_bit
  6021 00001F68 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  6022 00001F6D 7512                    	jne	short chk_12khz_2
  6023 00001F6F BB[EE12]                	mov	bx, load_12khz_mono_16_bit
  6024 00001F72 EB0D                    	jmp	short chk_12khz_2
  6025                                  chk_12khz_1:
  6026 00001F74 BB[AB12]                	mov	bx, load_12khz_stereo_8_bit
  6027 00001F77 803E[326C]01            	cmp	byte [WAVE_NumChannels], 1
  6028 00001F7C 7503                    	jne	short chk_12khz_2
  6029 00001F7E BB[7012]                	mov	bx, load_12khz_mono_8_bit
  6030                                  chk_12khz_2:
  6031                                  	;;;mov	ax, 4096
  6032                                  	;;mov	ax, 4095 ; playwav8.asm
  6033                                  	; 07/02/2025
  6034                                  	;mov	ax, 2105
  6035                                  	; 08/02/2025 (*)
  6036 00001F81 B89302                  	mov	ax, 659
  6037 00001F84 BA0400                  	mov	dx, 4
  6038 00001F87 B90100                  	mov	cx, 1
  6039                                  	; 02/02/2025
  6040                                  	;jmp	short set_sizes
  6041                                  	;;;;
  6042                                  
  6043                                  ;-----------------------------------------------------------------------------
  6044                                  
  6045                                  set_sizes:
  6046                                  	;;;
  6047                                  	; 17/11/2024
  6048 00001F8A 51                      	push	cx
  6049 00001F8B B102                    	mov	cl, 2
  6050 00001F8D 2A0E[9C6C]              	sub	cl, [fbs_shift]
  6051                                  		; = 2 for 16 bit stereo
  6052                                  		; = 1 for 16 bit mono or 8 bit stereo
  6053                                  		; = 0 for 8 bit mono
  6054 00001F91 D3E0                    	shl	ax, cl
  6055 00001F93 59                      	pop	cx
  6056 00001F94 A3[B876]                	mov	[loadsize], ax	; (one) read count in bytes
  6057                                  	;;;
  6058 00001F97 F7E2                    	mul	dx
  6059 00001F99 83F901                  	cmp	cx, 1
  6060 00001F9C 7402                    	je	short s_2
  6061                                  s_1:
  6062 00001F9E F7F1                    	div	cx
  6063                                  s_2:	
  6064                                  	;;;
  6065                                  	; ax = byte count of (to be) converted samples 
  6066                                  	
  6067                                  	; 17/11/2024
  6068                                  	;;;
  6069 00001FA0 8A0E[9C6C]              	mov	cl, [fbs_shift]
  6070                                  
  6071 00001FA4 D3E0                    	shl	ax, cl
  6072                                  		; *1 for 16 bit stereo
  6073                                  		; *2 for 16 bit mono or 8 bit stereo
  6074                                  		; *4 for for 8 bit mono
  6075                                  	;;;
  6076                                  
  6077                                  	; ax = 16 bit stereo byte count (target buffer size)
  6078                                  	
  6079 00001FA6 D1E8                    	shr	ax, 1	; buffer size is 16 bit sample count
  6080 00001FA8 A3[BA76]                	mov	[buffersize], ax  ; ** ; 09/02/2025
  6081 00001FAB 891E[B676]              	mov	[loadfromwavfile], bx
  6082                                  
  6083                                  	; 08/02/2025
  6084                                  	;retn
  6085                                  
  6086                                  ; ----------------------------------------------------------------------------
  6087                                  
  6088                                  	; 09/02/2025
  6089                                  	; 08/02/2025
  6090                                  
  6091                                  allocate_memory:
  6092                                  	; allocate 256 bytes of data for DCM_OUT Buffer Descriptor List. (BDL)
  6093                                  
  6094                                  	;mov	ax, BDL_SIZE / 16
  6095                                  	; 09/02/2025
  6096 00001FAF BB1000                  	mov	bx, BDL_SIZE / 16
  6097 00001FB2 E8B205                  	call	memAlloc
  6098 00001FB5 A3[B076]                	mov	[BDL_BUFFER], ax	; segment
  6099                                  
  6100                                  	; allocate 2 buffers, 64k each for now.
  6101                                  
  6102                                  	;;mov	ax, BUFFERSIZE / 16	; 64k for .WAV file
  6103                                  	;mov	bx, [buffersize]	; word count
  6104                                  	; 09/02/2025
  6105 00001FB8 89C3                    	mov	bx, ax ; **
  6106 00001FBA 83C307                  	add	bx, 7
  6107 00001FBD C1EB03                  	shr	bx, 3	; / 8		; paragraph count
  6108 00001FC0 53                      	push	bx
  6109 00001FC1 E8A305                  	call	memAlloc
  6110 00001FC4 A3[B276]                	mov	[WAV_BUFFER_1], ax	; segment
  6111                                  
  6112                                  	;;mov	ax, BUFFERSIZE / 16
  6113                                  	;mov	bx, [buffersize]	; word count
  6114                                  	;add	bx, 7
  6115                                  	;shr	bx, 3	; / 8		; paragraph count
  6116 00001FC7 5B                      	pop	bx
  6117 00001FC8 E89C05                  	call	memAlloc
  6118 00001FCB A3[B476]                	mov	[WAV_BUFFER_2], ax	; segment
  6119                                  
  6120 00001FCE C3                      	retn
  6121                                  
  6122                                  ;-----------------------------------------------------------------------------
  6123                                  ;-----------------------------------------------------------------------------
  6124                                  
  6125                                  	; 08/02/2025
  6126                                  ac97_init_play:
  6127                                  
  6128                                  	; 06/02/2025
  6129                                  _PlayNow:
  6130                                  	; 01/01/2025 (cgaplay.asm)
  6131                                  	; 18/12/2024 (ac97play.asm)
  6132                                  	; 30/12/2024 (cgaplay.s)
  6133                                  	; 29/12/2024 (vgaplay3.s)
  6134                                  	; 02/12/2024 (ac97play.s)
  6135                                  
  6136                                  	; 29/05/2024 (TRDOS 386, playwav7.s)
  6137                                  	; ((Modified from playwav4.asm, ich_wav4.asm))
  6138                                  	; ------------------
  6139                                  
  6140                                  	; create Buffer Descriptor List
  6141                                  
  6142                                  	;  Generic Form of Buffer Descriptor
  6143                                  	;  ---------------------------------
  6144                                  	;  63   62    61-48    47-32   31-0
  6145                                  	;  ---  ---  --------  ------- -----
  6146                                  	;  IOC  BUP -reserved- Buffer  Buffer
  6147                                  	;		      Length   Pointer
  6148                                  	;		      [15:0]   [31:0]
  6149                                  
  6150                                  	; 09/02/2025
  6151                                  	; 08/02/2025
  6152 00001FCF 06                      	push	es
  6153 00001FD0 A1[B076]                	mov	ax, [BDL_BUFFER]	; get segment # for BDL
  6154 00001FD3 8EC0                    	mov	es, ax
  6155                                  
  6156 00001FD5 B91000                  	mov	cx, 32 / 2		; make 32 entries in BDL
  6157 00001FD8 31FF                    	xor	di, di
  6158                                  	;mov	di, bdl_buffer
  6159                                  _pw0:
  6160 00001FDA 660FB706[B276]          	movzx	eax, word [WAV_BUFFER_1]
  6161 00001FE0 66C1E004                	shl	eax, 4			; convert seg:off ->0:offset
  6162 00001FE4 66AB                    	stosd				; store pointer to wavbuffer1
  6163                                  
  6164                                  	;mov	eax, BUFFERSIZE / 2	; size of buffer (32K) in (16bit) words
  6165                                  	; 13/11/2023 (ich_wav3.asm) - 18/11/2023 (ich_wav4.asm)
  6166 00001FE6 66A1[BA76]              	mov	eax, [buffersize]
  6167                                  
  6168                                  	;or	eax, IOC + BUP
  6169                                  	; 06/11/2023 (TUNELOOP version, without interrupt)
  6170 00001FEA 660D00000040            	or	eax, BUP
  6171 00001FF0 66AB                    	stosd
  6172                                  
  6173 00001FF2 660FB706[B476]          	movzx	eax, word [WAV_BUFFER_2]
  6174 00001FF8 66C1E004                	shl	eax, 4			; convert seg:off ->0:offset
  6175 00001FFC 66AB                    	stosd				; store pointer to wavbuffer2
  6176                                  
  6177                                  	;mov	eax, BUFFERSIZE / 2 ; size of half buffer (32K)
  6178                                  	; 13/11/2023 (ich_wav3.asm) - 18/11/2023 (ich_wav4.asm)
  6179 00001FFE 66A1[BA76]              	mov	eax, [buffersize]
  6180                                  
  6181                                  	;or	eax, IOC + BUP
  6182                                  	; 06/11/2023 (TUNELOOP version, without interrupt)
  6183 00002002 660D00000040            	or	eax, BUP
  6184 00002008 66AB                    	stosd
  6185                                  
  6186 0000200A E2CE                    	loop	_pw0
  6187 0000200C 07                      	pop	es
  6188                                  
  6189                                  	; 18/12/2024
  6190                                  	;mov	word [count], cx ; 0
  6191                                  	; 14/11/2024
  6192                                  	;mov	dword [LoadedDataBytes], 0
  6193                                  
  6194                                  	; 08/02/2025
  6195                                  	; 19/11/2024
  6196                                  ac97_RePlayWav:
  6197                                  	; load 64k into buffer 1
  6198 0000200D A1[B276]                        mov     ax, [WAV_BUFFER_1]
  6199                                          ;call	loadFromFile
  6200                                  	; 13/11/2023
  6201 00002010 FF16[B676]              	call	word [loadfromwavfile]
  6202                                  	; 14/11/2024
  6203 00002014 A1[BE76]                	mov	ax, [count]
  6204 00002017 0106[C076]              	add	[LoadedDataBytes], ax
  6205 0000201B 8316[C276]00            	adc	word [LoadedDataBytes+2], 0
  6206                                  
  6207                                  	; and 64k into buffer 2
  6208 00002020 A1[B476]                	mov     ax, [WAV_BUFFER_2]
  6209                                         	;call	loadFromFile
  6210                                  	; 13/11/2023
  6211 00002023 FF16[B676]              	call	word [loadfromwavfile]
  6212                                  	; 14/11/2024
  6213                                  	; 08/02/2025
  6214 00002027 6631C0                  	xor	eax, eax
  6215 0000202A A1[BE76]                	mov	ax, [count]
  6216                                  	;add	[LoadedDataBytes], ax
  6217                                  	;adc	word [LoadedDataBytes+2], 0
  6218 0000202D 660106[C076]            	add	[LoadedDataBytes], eax
  6219                                  
  6220                                  	; write NABMBAR+10h with offset of buffer descriptor list
  6221                                  
  6222                                  	; 09/02/2025
  6223 00002032 660FB706[B076]          	movzx	eax, word [BDL_BUFFER]
  6224 00002038 66C1E004                	shl	eax, 4			; convert seg:off to 0:off
  6225                                  	; 08/02/2025	
  6226                                  	;mov	ax, cs
  6227                                  	;shl	eax, 4
  6228                                  	;add	eax, bdl_buffer
  6229                                  	;
  6230 0000203C 8B16[A86C]              	mov	dx, [NABMBAR]
  6231 00002040 83C210                  	add	dx, PO_BDBAR_REG	; set pointer to BDL
  6232 00002043 66EF                    	out	dx, eax			; write to AC97 controller
  6233                                  
  6234                                  	; 19/05/2024
  6235 00002045 E85C00                  	call	delay1_4ms
  6236                                  
  6237 00002048 B01F                    	mov	al, 31
  6238 0000204A E8AC00                  	call	setLastValidIndex
  6239                                  
  6240                                  	; 19/05/2024
  6241                                  	;call	delay1_4ms
  6242                                  
  6243                                  	; 07/02/2025
  6244                                  	;mov	al, [volume]
  6245 0000204D E875E3                  	call	SetPCMOutVolume
  6246                                  
  6247                                  	; 17/02/2017
  6248 00002050 8B16[A86C]              	mov	dx, [NABMBAR]
  6249 00002054 83C21B                          add	dx, PO_CR_REG		; PCM out Control Register
  6250                                  	;mov	al, IOCE + RPBM		; Enable 'Interrupt On Completion' + run
  6251                                  	;				; (LVBI interrupt will not be enabled)
  6252                                  	; 06/11/2023 (TUNELOOP version, without interrupt)
  6253 00002057 B001                    	mov	al, RPBM
  6254 00002059 EE                      	out	dx, al			; Start bus master operation.
  6255                                  
  6256                                  	; 19/05/2024
  6257                                  	; 06/11/2023
  6258                                  	;call	delay1_4ms	; 30/05/2024
  6259                                  
  6260 0000205A C3                      	retn
  6261                                  
  6262                                  ;-----------------------------------------------------------------------------
  6263                                  ;-----------------------------------------------------------------------------
  6264                                  
  6265                                  ; 01/01/2025 (cgaplay.asm)
  6266                                  ; 29/12/2024 (vgaplay3.s)
  6267                                  ; 18/12/2024 (ac97play.s)
  6268                                  ;
  6269                                  ; 18/11/2024
  6270                                  ; Ref: TRDOS 386 v2.0.9, audio.s, Erdogan Tan, 06/06/2024
  6271                                  
  6272                                  
  6273                                  	; 06/02/2025
  6274                                  audio_stop:
  6275 0000205B 803E[AA6C]01            	cmp	byte [audio_hardware], 1
  6276 00002060 7703                    	ja	short ac97_stop
  6277 00002062 E9EAFA                  	jmp	sb16_stop
  6278                                  
  6279                                  ;-----------------------------------------------------------------------------
  6280                                  
  6281                                  ac97_stop:
  6282                                  	; 18/11/2024
  6283 00002065 C606[AE6C]02            	mov	byte [stopped], 2
  6284                                  
  6285                                  ac97_po_cmd@:
  6286 0000206A 30C0                    	xor	al, al ; 0
  6287                                  ac97_po_cmd:
  6288 0000206C 8B16[A86C]              	mov     dx, [NABMBAR]
  6289 00002070 83C21B                          add     dx, PO_CR_REG	; PCM out control register
  6290 00002073 EE                      	out	dx, al
  6291 00002074 C3                      	retn
  6292                                  
  6293                                  ;-----------------------------------------------------------------------------
  6294                                  ;-----------------------------------------------------------------------------
  6295                                  
  6296                                  	; 06/02/2025
  6297                                  audio_pause:
  6298 00002075 803E[AA6C]01            	cmp	byte [audio_hardware], 1
  6299 0000207A 7703                    	ja	short ac97_pause
  6300 0000207C E90FFB                  	jmp	sb16_pause
  6301                                  
  6302                                  ;-----------------------------------------------------------------------------
  6303                                  
  6304                                  ac97_pause:
  6305 0000207F C606[AE6C]01            	mov	byte [stopped], 1 ; paused
  6306                                  	;mov	al, 0
  6307                                  	;jmp	short ac97_po_cmd
  6308 00002084 EBE4                    	jmp	short ac97_po_cmd@
  6309                                  
  6310                                  ;-----------------------------------------------------------------------------
  6311                                  ;-----------------------------------------------------------------------------
  6312                                  
  6313                                  	; 06/02/2025
  6314                                  audio_play:
  6315 00002086 803E[AA6C]01            	cmp	byte [audio_hardware], 1
  6316 0000208B 7703                    	ja	short ac97_play
  6317 0000208D E920FB                  	jmp	sb16_play
  6318                                  
  6319                                  ;-----------------------------------------------------------------------------
  6320                                  
  6321                                  ac97_play: ; continue to play (after pause)
  6322 00002090 C606[AE6C]00            	mov	byte [stopped], 0
  6323 00002095 B001                    	mov	al, RPBM
  6324 00002097 EBD3                    	jmp	short ac97_po_cmd
  6325                                  
  6326                                  ;-----------------------------------------------------------------------------
  6327                                  
  6328                                  PORTB		EQU 061h
  6329                                  REFRESH_STATUS	EQU 010h	; Refresh signal status
  6330                                  
  6331                                  delay_100ms:
  6332                                  	; 11/11/2023
  6333                                  	; 29/05/2017
  6334                                  	; 24/03/2017 ('codec.asm')
  6335                                  	; wait 100 ms
  6336 00002099 51                      	push	cx
  6337 0000209A B99001                  	mov	cx, 400  ; 400*0.25ms
  6338                                  _delay_x_ms:
  6339 0000209D E80400                  	call	delay1_4ms
  6340 000020A0 E2FB                            loop	_delay_x_ms
  6341 000020A2 59                      	pop	cx
  6342 000020A3 C3                      	retn
  6343                                  
  6344                                  delay1_4ms:
  6345 000020A4 50                              push    ax
  6346 000020A5 51                              push    cx
  6347 000020A6 B91000                          mov     cx, 16			; close enough.
  6348 000020A9 E461                    	in	al, PORTB
  6349 000020AB 2410                    	and	al, REFRESH_STATUS
  6350 000020AD 88C4                    	mov	ah, al			; Start toggle state
  6351 000020AF 09C9                    	or	cx, cx
  6352 000020B1 7401                    	jz	short _d4ms1
  6353 000020B3 41                      	inc	cx			; Throwaway first toggle
  6354                                  _d4ms1:
  6355 000020B4 E461                    	in	al, PORTB		; Read system control port
  6356 000020B6 2410                    	and	al, REFRESH_STATUS	; Refresh toggles 15.085 microseconds
  6357 000020B8 38C4                    	cmp	ah, al
  6358 000020BA 74F8                    	je	short _d4ms1		; Wait for state change
  6359                                  
  6360 000020BC 88C4                    	mov	ah, al			; Update with new state
  6361 000020BE 49                      	dec	cx
  6362 000020BF 75F3                    	jnz	short _d4ms1
  6363                                  
  6364                                  	; 30/05/2024
  6365 000020C1 F8                      	clc
  6366                                  
  6367 000020C2 59                              pop     cx
  6368 000020C3 58                              pop     ax
  6369 000020C4 C3                              retn
  6370                                  
  6371                                  ;-----------------------------------------------------------------------------
  6372                                  
  6373                                  ; returns AL = current index value
  6374                                  getCurrentIndex:
  6375                                  	; 08/11/2023
  6376                                  	;push	dx
  6377 000020C5 8B16[A86C]              	mov	dx, [NABMBAR]
  6378 000020C9 83C214                  	add	dx, PO_CIV_REG
  6379 000020CC EC                      	in	al, dx
  6380                                  	;pop	dx
  6381                                  uLVI2:	;	06/11/2023
  6382 000020CD C3                      	retn
  6383                                  
  6384                                  ;-----------------------------------------------------------------------------
  6385                                  
  6386                                  updateLVI:
  6387                                  	; 06/11/2023
  6388 000020CE 8B16[A86C]              	mov	dx, [NABMBAR]
  6389 000020D2 83C214                  	add	dx, PO_CIV_REG
  6390                                  	; (Current Index Value and Last Valid Index value)
  6391 000020D5 ED                      	in	ax, dx
  6392                                  
  6393 000020D6 38E0                    	cmp	al, ah ; is current index = last index ?
  6394 000020D8 75F3                    	jne	short uLVI2
  6395                                  
  6396                                  	; 08/11/2023
  6397 000020DA E8E8FF                  	call	getCurrentIndex
  6398                                   
  6399 000020DD F606[9D6C]01            	test	byte [flags], ENDOFFILE
  6400                                  	;jnz	short uLVI1
  6401 000020E2 7411                    	jz	short uLVI0  ; 08/11/2023
  6402                                  
  6403                                  	; 08/11/2023
  6404 000020E4 50                      	push	ax
  6405 000020E5 8B16[A86C]              	mov	dx, [NABMBAR]
  6406 000020E9 83C216                  	add	dx, PO_SR_REG  ; PCM out status register
  6407 000020EC ED                      	in	ax, dx
  6408                                  
  6409 000020ED A803                    	test	al, 3 ; bit 1 = Current Equals Last Valid (CELV)
  6410                                  		      ; (has been processed)
  6411                                  		      ; bit 0 = 1 -> DMA Controller Halted (DCH)
  6412 000020EF 58                      	pop	ax
  6413 000020F0 7407                    	jz	short uLVI1
  6414                                  uLVI3:
  6415 000020F2 31C0                    	xor	ax, ax
  6416                                  	; zf = 1
  6417 000020F4 C3                      	retn
  6418                                  uLVI0:
  6419                                          ; not at the end of the file yet.
  6420 000020F5 FEC8                    	dec	al
  6421 000020F7 241F                    	and	al, 1Fh
  6422                                  uLVI1:
  6423                                  	;call	setLastValidIndex
  6424                                  ;uLVI2:
  6425                                  	;retn
  6426                                  
  6427                                  ;-----------------------------------------------------------------------------
  6428                                  
  6429                                  ;input AL = index # to stop on
  6430                                  setLastValidIndex:
  6431                                  	; 08/11/2023
  6432                                  	;push	dx
  6433 000020F9 8B16[A86C]              	mov	dx, [NABMBAR]
  6434 000020FD 83C215                  	add	dx, PO_LVI_REG
  6435 00002100 EE                              out     dx, al
  6436                                  	;pop	dx
  6437 00002101 C3                      	retn
  6438                                  
  6439                                  ;=============================================================================
  6440                                  ;	Detect (& Enable) Audio Device
  6441                                  ;=============================================================================
  6442                                  
  6443                                  	; 06/02/2025
  6444                                  
  6445                                  detect_audio_device:
  6446                                  
  6447                                  	; check for SB16 at first
  6448 00002102 E8CF01                  	call	DetectSB16
  6449 00002105 730E                    	jnc	short detected
  6450                                  	
  6451 00002107 E80803                  	call	Get_CPU_Type
  6452 0000210A 720D                    	jc	short not_detected
  6453                                  	
  6454 0000210C E80B00                  	call	DetectAC97
  6455 0000210F 7208                    	jc	short not_detected
  6456                                  
  6457 00002111 FE06[AA6C]              	inc	byte [audio_hardware] ; 2 = AC'97
  6458                                  detected:
  6459 00002115 FE06[AA6C]              	inc	byte [audio_hardware] ; 1 = SB16
  6460                                  	
  6461                                  not_detected:			      ; 0 = none
  6462 00002119 C3                      	retn
  6463                                  
  6464                                  ;=============================================================================
  6465                                  ;	Detect AC'97 Hardware
  6466                                  ;=============================================================================
  6467                                  
  6468                                  	; 06/02/2025
  6469                                  	; 04/02/2025 - cgaplay.asm
  6470                                  	; 30/05/2024
  6471                                  DetectAC97:
  6472                                  DetectICH:
  6473                                  	; 22/11/2023
  6474                                  	; 19/11/2023
  6475                                  	; 01/11/2023 - TRDOS 386 Kernel v2.0.7
  6476                                  
  6477                                  	; 19/11/2023
  6478 0000211A BE[7C22]                	mov	si, valid_ids	; address of Valid ICH (AC97) Device IDs
  6479 0000211D B91500                  	mov	cx, valid_id_count
  6480                                  pfd_1:
  6481 00002120 66AD                    	lodsd
  6482 00002122 E83000                  	call	pciFindDevice
  6483 00002125 7303                    	jnc	short d_ac97_1
  6484 00002127 E2F7                    	loop	pfd_1
  6485                                  
  6486                                  	;stc
  6487 00002129 C3                      	retn
  6488                                  
  6489                                  d_ac97_1:
  6490                                  	; eax = BUS/DEV/FN
  6491                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  6492                                  	; edx = DEV/VENDOR
  6493                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  6494                                  
  6495                                  	; playwav4.asm - 19/05/2024
  6496                                  
  6497 0000212A 66A3[A26C]              	mov	[bus_dev_fn], eax
  6498 0000212E 668916[9E6C]            	mov	[dev_vendor], edx
  6499                                  
  6500                                  	; get ICH base address regs for mixer and bus master
  6501                                  
  6502 00002133 B010                            mov     al, NAMBAR_REG
  6503 00002135 E8AB00                          call    pciRegRead16			; read PCI registers 10-11
  6504                                          ;and    dx, IO_ADDR_MASK 		; mask off BIT0
  6505                                  	; 19/05/2024
  6506 00002138 80E2FE                  	and	dl, 0FEh
  6507                                  
  6508 0000213B 8916[A66C]                      mov     [NAMBAR], dx			; save audio mixer base addr
  6509                                  
  6510 0000213F B014                    	mov     al, NABMBAR_REG
  6511 00002141 E89F00                          call    pciRegRead16
  6512                                          ;and    dx, IO_ADDR_MASK
  6513                                  	; 19/05/2024
  6514 00002144 80E2C0                  	and	dl, 0C0h
  6515                                  
  6516 00002147 8916[A86C]                      mov     [NABMBAR], dx			; save bus master base addr
  6517                                  
  6518 0000214B B03C                    	mov	al, AC97_INT_LINE ; Interrupt line register (3Ch)
  6519 0000214D E88B00                  	call	pciRegRead8 ; 17/02/2017
  6520                                  
  6521 00002150 8816[9A6C]              	mov	[ac97_int_ln_reg], dl
  6522                                  
  6523                                  	;clc
  6524                                  
  6525 00002154 C3                      	retn
  6526                                  
  6527                                  ;-----------------------------------------------------------------------------
  6528                                  
  6529                                  ; 06/02/2025
  6530                                  ; 04/02/2025 (cgaplay.asm)
  6531                                  ; 29/12/2024 (vgaplay3.s)
  6532                                  ; 18/12/2024 (ac97play.s)
  6533                                  ; --------------------------------------------------------
  6534                                  ; 27/05/2024 - (TRDOS 386 Kernel) audio.s
  6535                                  ; --------------------------------------------------------
  6536                                  
  6537                                  NOT_PCI32_PCI16	EQU 03FFFFFFFh ; NOT BIT31+BIT30 ; 19/03/2017
  6538                                  NOT_BIT31 EQU 7FFFFFFFh
  6539                                  
  6540                                  pciFindDevice:
  6541                                  	; 19/11/2023
  6542                                  	; 03/04/2017 ('pci.asm', 20/03/2017)
  6543                                  	;
  6544                                  	; scan through PCI space looking for a device+vendor ID
  6545                                  	;
  6546                                  	; Entry: EAX=Device+Vendor ID
  6547                                  	;
  6548                                  	; Exit: EAX=PCI address if device found
  6549                                  	;	EDX=Device+Vendor ID
  6550                                  	;       CY clear if found, set if not found. EAX invalid if CY set.
  6551                                  	;
  6552                                  	; Destroys: ebx, edi ; 19/11/2023
  6553                                  
  6554                                          ; 19/11/2023
  6555 00002155 6689C3                  	mov	ebx, eax
  6556 00002158 66BF00000080            	mov	edi, 80000000h
  6557                                  nextPCIdevice:
  6558 0000215E 6689F8                  	mov 	eax, edi		; read PCI registers
  6559 00002161 E88D00                  	call	pciRegRead32
  6560                                  	; 19/11/2023
  6561 00002164 6639DA                  	cmp	edx, ebx
  6562 00002167 7414                    	je	short PCIScanExit	; found
  6563                                  	; 19/11/2023
  6564 00002169 6681FF00F8FF80          	cmp	edi, 80FFF800h
  6565 00002170 7309                    	jnb	short pfd_nf		; not found
  6566 00002172 6681C700010000          	add	edi, 100h
  6567 00002179 EBE3                    	jmp	short nextPCIdevice
  6568                                  pfd_nf:
  6569 0000217B F9                      	stc
  6570 0000217C C3                      	retn
  6571                                  PCIScanExit:
  6572                                  	;pushf
  6573 0000217D 66B8FFFFFF7F            	mov	eax, NOT_BIT31 	; 19/03/2017
  6574 00002183 6621F8                  	and	eax, edi	; return only bus/dev/fn #
  6575 00002186 C3                      	retn
  6576                                  
  6577                                  ; --------------------------------------------------------
  6578                                  
  6579                                  pciRegRead:
  6580                                  	; 30/05/2024
  6581                                  	; 03/04/2017 ('pci.asm', 20/03/2017)
  6582                                  	;
  6583                                  	; 8/16/32bit PCI reader
  6584                                  	;
  6585                                  	; Entry: EAX=PCI Bus/Device/fn/register number
  6586                                  	;           BIT30 set if 32 bit access requested
  6587                                  	;           BIT29 set if 16 bit access requested
  6588                                  	;           otherwise defaults to 8 bit read
  6589                                  	;
  6590                                  	; Exit:  DL,DX,EDX register data depending on requested read size
  6591                                  	;
  6592                                  	; Note1: this routine is meant to be called via pciRegRead8,
  6593                                  	;	 pciRegread16 or pciRegRead32, listed below.
  6594                                  	;
  6595                                  	; Note2: don't attempt to read 32 bits of data from a non dword
  6596                                  	;	 aligned reg number. Likewise, don't do 16 bit reads from
  6597                                  	;	 non word aligned reg #
  6598                                  	
  6599 00002187 6653                    	push	ebx
  6600 00002189 51                      	push	cx
  6601 0000218A 6689C3                          mov     ebx, eax		; save eax, dh
  6602 0000218D 88F1                            mov     cl, dh
  6603                                  
  6604 0000218F 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; clear out data size request
  6605 00002195 660D00000080                    or      eax, BIT31		; make a PCI access request
  6606                                  	; 01/01/2025 (NASM)
  6607 0000219B 24FC                            and     al, ~3 ; NOT 3		; force index to be dword
  6608                                  
  6609 0000219D BAF80C                          mov     dx, PCI_INDEX_PORT
  6610 000021A0 66EF                    	out	dx, eax			; write PCI selector
  6611                                  		
  6612 000021A2 BAFC0C                          mov     dx, PCI_DATA_PORT
  6613 000021A5 88D8                            mov     al, bl
  6614 000021A7 2403                            and     al, 3			; figure out which port to
  6615 000021A9 00C2                            add     dl, al			; read to
  6616                                  
  6617 000021AB 66F7C3000000C0          	test    ebx, PCI32+PCI16
  6618 000021B2 7507                            jnz     short _pregr0
  6619                                  
  6620 000021B4 EC                      	in	al, dx			; return 8 bits of data
  6621                                  
  6622 000021B5 88C2                    	mov	dl, al
  6623 000021B7 88CE                    	mov     dh, cl			; restore dh for 8 bit read
  6624 000021B9 EB13                    	jmp	short _pregr2
  6625                                  _pregr0:	
  6626 000021BB 66F7C300000080          	test    ebx, PCI32
  6627 000021C2 7505                            jnz	short _pregr1
  6628                                  
  6629 000021C4 ED                      	in	ax, dx
  6630                                  
  6631 000021C5 89C2                    	mov     dx, ax			; return 16 bits of data
  6632 000021C7 EB05                    	jmp	short _pregr2
  6633                                  _pregr1:
  6634 000021C9 66ED                    	in	eax, dx			; return 32 bits of data
  6635                                  
  6636 000021CB 6689C2                  	mov	edx, eax
  6637                                  _pregr2:
  6638 000021CE 6689D8                  	mov     eax, ebx		; restore eax
  6639 000021D1 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; clear out data size request
  6640 000021D7 59                      	pop	cx
  6641 000021D8 665B                    	pop	ebx
  6642 000021DA C3                      	retn
  6643                                  
  6644                                  pciRegRead8:
  6645 000021DB 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; set up 8 bit read size
  6646 000021E1 EBA4                            jmp     short pciRegRead	; call generic PCI access
  6647                                  
  6648                                  pciRegRead16:
  6649 000021E3 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; set up 16 bit read size
  6650 000021E9 660D00000040                    or      eax, PCI16		; call generic PCI access
  6651 000021EF EB96                            jmp     short pciRegRead
  6652                                  
  6653                                  pciRegRead32:
  6654 000021F1 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; set up 32 bit read size
  6655 000021F7 660D00000080                    or      eax, PCI32		; call generic PCI access
  6656 000021FD EB88                            jmp     pciRegRead
  6657                                  
  6658                                  ; --------------------------------------------------------
  6659                                  
  6660                                  pciRegWrite:
  6661                                  	; 30/05/2024
  6662                                  	; 03/04/2017 ('pci.asm', 29/11/2016)
  6663                                  	;
  6664                                  	; 8/16/32bit PCI writer
  6665                                  	;
  6666                                  	; Entry: EAX=PCI Bus/Device/fn/register number
  6667                                  	;           BIT31 set if 32 bit access requested
  6668                                  	;           BIT30 set if 16 bit access requested
  6669                                  	;           otherwise defaults to 8bit read
  6670                                  	;        DL/DX/EDX data to write depending on size
  6671                                  	;
  6672                                  	; Note1: this routine is meant to be called via pciRegWrite8,
  6673                                  	;	 pciRegWrite16 or pciRegWrite32 as detailed below.
  6674                                  	;
  6675                                  	; Note2: don't attempt to write 32bits of data from a non dword
  6676                                  	;	 aligned reg number. Likewise, don't do 16 bit writes from
  6677                                  	;	 non word aligned reg #
  6678                                  
  6679 000021FF 6653                    	push	ebx
  6680 00002201 6651                    	push	ecx
  6681 00002203 6689C3                          mov     ebx, eax		; save eax, edx
  6682 00002206 6689D1                          mov     ecx, edx
  6683 00002209 6625FFFFFF3F            	and     eax, NOT_PCI32_PCI16	; clear out data size request
  6684 0000220F 660D00000080                    or      eax, BIT31		; make a PCI access request
  6685                                  	; 01/01/2025 (NASM)
  6686 00002215 24FC                            and     al, ~3 ; NOT 3		; force index to be dword
  6687                                  
  6688 00002217 BAF80C                          mov     dx, PCI_INDEX_PORT
  6689 0000221A 66EF                    	out	dx, eax			; write PCI selector
  6690                                  		
  6691 0000221C BAFC0C                          mov     dx, PCI_DATA_PORT
  6692 0000221F 88D8                            mov     al, bl
  6693 00002221 2403                            and     al, 3			; figure out which port to
  6694 00002223 00C2                            add     dl, al			; write to
  6695                                  
  6696 00002225 66F7C3000000C0          	test    ebx, PCI32+PCI16
  6697 0000222C 7505                            jnz     short _pregw0
  6698                                  	
  6699 0000222E 88C8                    	mov	al, cl 			; put data into al
  6700 00002230 EE                      	out	dx, al
  6701                                  	
  6702 00002231 EB13                    	jmp	short _pregw2
  6703                                  _pregw0:
  6704 00002233 66F7C300000080          	test    ebx, PCI32
  6705 0000223A 7505                            jnz     short _pregw1
  6706                                  	
  6707 0000223C 89C8                    	mov	ax, cx			; put data into ax
  6708 0000223E EF                      	out	dx, ax
  6709                                  
  6710 0000223F EB05                    	jmp	short _pregw2
  6711                                  _pregw1:
  6712 00002241 6689C8                  	mov	eax, ecx		; put data into eax
  6713 00002244 66EF                    	out	dx, eax
  6714                                  _pregw2:
  6715 00002246 6689D8                          mov     eax, ebx		; restore eax
  6716 00002249 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; clear out data size request
  6717 0000224F 6689CA                          mov     edx, ecx		; restore dx
  6718 00002252 6659                    	pop	ecx
  6719 00002254 665B                    	pop	ebx
  6720 00002256 C3                      	retn
  6721                                  
  6722                                  pciRegWrite8:
  6723 00002257 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; set up 8 bit write size
  6724 0000225D EBA0                            jmp	short pciRegWrite	; call generic PCI access
  6725                                  
  6726                                  pciRegWrite16:
  6727 0000225F 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; set up 16 bit write size
  6728 00002265 660D00000040                    or      eax, PCI16		; call generic PCI access
  6729 0000226B EB92                            jmp	short pciRegWrite
  6730                                  
  6731                                  pciRegWrite32:
  6732 0000226D 6625FFFFFF3F                    and     eax, NOT_PCI32_PCI16	; set up 32 bit write size
  6733 00002273 660D00000080                    or      eax, PCI32		; call generic PCI access
  6734 00002279 EB84                            jmp	pciRegWrite
  6735                                  
  6736                                  ; -------------------------------------------------------------
  6737                                  ; ac97.inc (11/11/2023)
  6738                                  ; -------------------------------------------------------------
  6739                                  
  6740                                  ; 06/02/2025
  6741                                  ; 04/02/2025 - cgaplay.asm
  6742                                  
  6743                                  ; special characters
  6744                                  LF      EQU 10
  6745                                  CR      EQU 13
  6746                                  
  6747                                  ; PCI stuff
  6748                                  
  6749                                  BIT0  EQU 1
  6750                                  BIT1  EQU 2
  6751                                  BIT2  EQU 4
  6752                                  BIT8  EQU 100h
  6753                                  BIT9  EQU 200h
  6754                                  BIT28 EQU 10000000h
  6755                                  BIT30 EQU 40000000h
  6756                                  BIT31 EQU 80000000h
  6757                                  
  6758                                  BUP		equ	BIT30		; Buffer Underrun Policy.
  6759                                  					; if this buffer is the last buffer
  6760                                  					; in a playback, fill the remaining
  6761                                  					; samples with 0 (silence) or not.
  6762                                  					; It's a good idea to set this to 1
  6763                                  					; for the last buffer in playback,
  6764                                  					; otherwise you're likely to get a lot
  6765                                  					; of noise at the end of the sound.
  6766                                  
  6767                                  RR		equ	BIT1		; reset registers. Nukes all regs
  6768                                                                          ; except bits 4:2 of this register.
  6769                                                                          ; Only set this bit if BIT 0 is 0
  6770                                  RPBM		equ	BIT0		; Run/Pause
  6771                                  					; set this bit to start the codec!
  6772                                  IO_ENA		EQU	BIT0		; i/o decode enable
  6773                                  BM_ENA		EQU	BIT2		; bus master enable
  6774                                  
  6775                                  PCI_INDEX_PORT  EQU     0CF8h
  6776                                  PCI_DATA_PORT   EQU     0CFCh
  6777                                  PCI32           EQU     BIT31           ; bitflag to signal 32bit access
  6778                                  PCI16           EQU     BIT30           ; bitflag for 16bit access
  6779                                  
  6780                                  AC97_INT_LINE	equ	3Ch		; AC97 Interrupt Line register offset
  6781                                  
  6782                                  ; Intel ICH2 equates. It is assumed that ICH0 and plain ole ICH are compatible.
  6783                                  
  6784                                  INTEL_VID       equ     8086h           ; Intel's PCI vendor ID
  6785                                  ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
  6786                                  SIS_VID		equ	1039h
  6787                                  NVIDIA_VID	equ	10DEh	 ; Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source c.
  6788                                  AMD_VID		equ	1022h
  6789                                  
  6790                                  ICH_DID         equ     2415h           ; ICH device ID
  6791                                  ICH0_DID        equ     2425h           ; ICH0
  6792                                  ICH2_DID        equ     2445h           ; ICH2 I think there are more ICHes.
  6793                                                                          ; they all should be compatible.
  6794                                  
  6795                                  ; 17/02/2017 (Erdogan Tan, ref: ALSA Device IDs, ALSA project)
  6796                                  ICH3_DID	equ     2485h           ; ICH3
  6797                                  ICH4_DID        equ     24C5h           ; ICH4
  6798                                  ICH5_DID	equ     24D5h           ; ICH5
  6799                                  ICH6_DID	equ     266Eh           ; ICH6
  6800                                  ESB6300_DID	equ     25A6h           ; 6300ESB
  6801                                  ESB631X_DID	equ     2698h           ; 631XESB
  6802                                  ICH7_DID	equ	27DEh		; ICH7
  6803                                  ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
  6804                                  MX82440_DID	equ	7195h
  6805                                  SI7012_DID	equ	7012h
  6806                                  NFORCE_DID	equ	01B1h
  6807                                  NFORCE2_DID	equ	006Ah
  6808                                  AMD8111_DID	equ	746Dh
  6809                                  AMD768_DID	equ	7445h
  6810                                  ; 03/11/2023 - Erdogan Tan - Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source code
  6811                                  CK804_DID	equ	0059h
  6812                                  MCP04_DID	equ	003Ah
  6813                                  CK8_DID		equ	008Ah
  6814                                  NFORCE3_DID	equ	00DAh
  6815                                  CK8S_DID	equ	00EAh
  6816                                  
  6817                                  NAMBAR_REG	equ	10h		; native audio mixer BAR
  6818                                  NABMBAR_REG	equ	14h		; native audio bus mastering BAR
  6819                                  
  6820                                  CODEC_MASTER_VOL_REG	equ	02h	; master volume
  6821                                  CODEC_MASTER_TONE_REG	equ	08h	; master tone (R+L)
  6822                                  CODEC_PCM_OUT_REG 	equ	18h     ; PCM output volume
  6823                                  CODEC_EXT_AUDIO_REG	equ	28h	; extended audio
  6824                                  CODEC_EXT_AUDIO_CTRL_REG equ	2Ah	; extended audio control
  6825                                  CODEC_PCM_FRONT_DACRATE_REG equ	2Ch	; PCM out sample rate
  6826                                  
  6827                                  ; ICH supports 3 different types of register sets for three types of things
  6828                                  ; it can do, thus:
  6829                                  ;
  6830                                  ; PCM in (for recording) aka PI
  6831                                  ; PCM out (for playback) aka PO
  6832                                  ; MIC in (for recording) aka MC
  6833                                  
  6834                                  PI_BDBAR_REG	equ	0		; PCM in buffer descriptor BAR
  6835                                  PO_BDBAR_REG	equ	10h		; PCM out buffer descriptor BAR
  6836                                  
  6837                                  GLOB_CNT_REG	equ	2Ch		; Global control register
  6838                                  GLOB_STS_REG 	equ	30h		; Global Status register (RO)
  6839                                  
  6840                                  PI_CR_REG 	equ	0Bh		; PCM in Control Register
  6841                                  PO_CR_REG	equ	1Bh		; PCM out Control Register
  6842                                  MC_CR_REG	equ	2Bh		; MIC in Control Register
  6843                                  
  6844                                  PCI_CMD_REG	EQU	04h		; reg 04h, command register
  6845                                  
  6846                                  CTRL_ST_CREADY		equ	BIT8+BIT9+BIT28 ; Primary Codec Ready
  6847                                  CODEC_REG_POWERDOWN	equ	26h
  6848                                  
  6849                                  PO_CIV_REG	equ	14h		; PCM out current Index value (RO)
  6850                                  PO_LVI_REG	equ	15h		; PCM out Last Valid Index
  6851                                  PO_SR_REG	equ	16h		; PCM out Status register
  6852                                  
  6853                                  BDL_SIZE	equ	32*8		; Buffer Descriptor List size
  6854                                  
  6855                                  ; 07/02/2025
  6856                                  PO_PICB_REG	equ 18h	; PCM Out Position In Current Buffer Register
  6857                                  
  6858                                  ; -------------------------------------------------------------
  6859                                  
  6860                                  ; 06/05/2025
  6861                                  
  6862                                  ; 22/12/2024
  6863 0000227B 90                      align 4
  6864                                  
  6865                                  ; 29/05/2024 (TRDOS 386)
  6866                                  ; 17/02/2017
  6867                                  ; Valid ICH device IDs
  6868                                  
  6869                                  valid_ids:
  6870                                  	;dd (ICH_DID shl 16) + INTEL_VID	; 8086h:2415h
  6871 0000227C 86801524                	dd (ICH_DID << 16) + INTEL_VID		; 8086h:2415h
  6872 00002280 86802524                	dd (ICH0_DID << 16) + INTEL_VID		; 8086h:2425h
  6873 00002284 86804524                	dd (ICH2_DID << 16) + INTEL_VID		; 8086h:2445h
  6874 00002288 86808524                	dd (ICH3_DID << 16) + INTEL_VID		; 8086h:2485h
  6875 0000228C 8680C524                	dd (ICH4_DID << 16) + INTEL_VID		; 8086h:24C5h
  6876 00002290 8680D524                	dd (ICH5_DID << 16) + INTEL_VID		; 8086h:24D5h
  6877 00002294 86806E26                	dd (ICH6_DID << 16) + INTEL_VID		; 8086h:266Eh
  6878 00002298 8680A625                	dd (ESB6300_DID << 16) + INTEL_VID	; 8086h:25A6h
  6879 0000229C 86809826                	dd (ESB631X_DID << 16) + INTEL_VID	; 8086h:2698h
  6880 000022A0 8680DE27                	dd (ICH7_DID << 16) + INTEL_VID		; 8086h:27DEh
  6881                                  	; 03/11/2023 - Erdogan Tan
  6882 000022A4 86809571                	dd (MX82440_DID << 16) + INTEL_VID	; 8086h:7195h
  6883 000022A8 39101270                	dd (SI7012_DID << 16)  + SIS_VID	; 1039h:7012h
  6884 000022AC DE10B101                	dd (NFORCE_DID << 16)  + NVIDIA_VID	; 10DEh:01B1h
  6885 000022B0 DE106A00                	dd (NFORCE2_DID << 16) + NVIDIA_VID	; 10DEh:006Ah
  6886 000022B4 22106D74                	dd (AMD8111_DID << 16) + AMD_VID	; 1022h:746Dh
  6887 000022B8 22104574                	dd (AMD768_DID << 16)  + AMD_VID	; 1022h:7445h
  6888 000022BC DE105900                	dd (CK804_DID << 16) + NVIDIA_VID	; 10DEh:0059h
  6889 000022C0 DE103A00                	dd (MCP04_DID << 16) + NVIDIA_VID	; 10DEh:003Ah
  6890 000022C4 DE108A00                	dd (CK8_DID << 16) + NVIDIA_VID		; 1022h:008Ah
  6891 000022C8 DE10DA00                	dd (NFORCE3_DID << 16) + NVIDIA_VID	; 10DEh:00DAh
  6892 000022CC DE10EA00                	dd (CK8S_DID << 16) + NVIDIA_VID	; 10DEh:00EAh
  6893                                  
  6894                                  valid_id_count equ (($ - valid_ids)>>2)	; 05/11/2023
  6895                                  
  6896 000022D0 00000000                	dd 0
  6897                                  
  6898                                  ;=============================================================================
  6899                                  ;	Detect Sound Blaster 16 sound card (or compatible hardware)
  6900                                  ;=============================================================================
  6901                                  
  6902                                  	; 06/02/2025
  6903                                  	; 04/02/2025 - cgaplay2.asm
  6904                                  	; 24/11/2024
  6905                                  	; Ref: TRDOS 386 Kernel v2.0.9 audio.s (06/06/2024)
  6906                                  	;      DetectSB procedure (06/08/2022, v2.0.5)
  6907                                  DetectSB16:
  6908                                  	; 06/08/2022 - TRDOS 386 v2.0.5
  6909                                  	; 24/04/2017
  6910                                  ScanPort:
  6911 000022D4 BB1002                  	mov	bx, 0210h	; start scanning ports
  6912                                  				; 210h, 220h, .. 260h
  6913                                  ResetDSP:       
  6914                                  	; 26/11/2024
  6915 000022D7 89DA                    	mov	dx, bx		; try to reset the DSP.
  6916 000022D9 80C206                  	add	dl, 06h
  6917                                  
  6918 000022DC B001                    	mov	al, 1
  6919 000022DE EE                      	out	dx, al
  6920                                  
  6921 000022DF EC                      	in	al, dx
  6922 000022E0 EC                      	in	al, dx
  6923 000022E1 EC                      	in	al, dx
  6924 000022E2 EC                      	in	al, dx
  6925                                  
  6926 000022E3 30C0                    	xor     al, al
  6927 000022E5 EE                      	out	dx, al
  6928                                  
  6929                                  	;add	dx, 08h
  6930 000022E6 80C208                  	add	dl, 08h
  6931 000022E9 B96400                  	mov	cx, 100
  6932                                  WaitID:
  6933 000022EC EC                      	in	al, dx
  6934 000022ED 08C0                    	or      al, al
  6935 000022EF 7804                    	js      short GetID
  6936 000022F1 E2F9                    	loop    WaitID
  6937 000022F3 EB0D                    	jmp     short NextPort
  6938                                  GetID:          
  6939                                  	;sub	dx, 04h
  6940 000022F5 80EA04                  	sub	dl, 04h
  6941 000022F8 EC                      	in	al, dx
  6942 000022F9 3CAA                    	cmp     al, 0AAh
  6943 000022FB 740F                    	je      short Found
  6944                                  	;add	dx, 04h
  6945 000022FD 80C204                  	add	dl, 04h
  6946 00002300 E2EA                    	loop    WaitID
  6947                                  NextPort:
  6948                                  	;add	bx, 10h		; if not response,
  6949 00002302 80C310                  	add	bl, 10h
  6950                                  	;cmp	bx, 260h	; try the next port.
  6951 00002305 80FB60                  	cmp	bl, 60h
  6952 00002308 76CD                    	jbe     short ResetDSP
  6953 0000230A F9                      	stc
  6954 0000230B C3                      	retn
  6955                                  Found:
  6956 0000230C 891E[A66C]              	mov     [audio_io_base], bx ; SB Port Address Found!
  6957                                  ScanIRQ:
  6958                                  SetIrqs:
  6959 00002310 28C0                    	sub 	al, al ; 0
  6960 00002312 A2[AB6C]                	mov 	[IRQnum], al ; reset
  6961                                  	; 27/11/2024
  6962                                  	;mov	[audio_intr], al
  6963                                  
  6964                                  	; 25/11/2024
  6965                                  	; save IRQ status
  6966 00002315 E421                    	in      al, 21h		; save the IMR.
  6967 00002317 A2[AC6C]                	mov	[IRQstatus], al
  6968                                  
  6969                                  	; ah > 0 -> set IRQ vector
  6970                                  	; al = IRQ number
  6971 0000231A B80501                  	mov	ax, 105h ; IRQ 5
  6972                                  	; 26/11/2024
  6973 0000231D BA[E223]                	mov	dx, IRQ5_service
  6974 00002320 E84700                  	call	set_hardware_int_vector
  6975 00002323 B80701                  	mov	ax, 107h ; IRQ 7
  6976                                  	; 26/11/2024
  6977 00002326 BA[E923]                	mov	dx, IRQ7_service
  6978 00002329 E83E00                  	call	set_hardware_int_vector
  6979                                  
  6980 0000232C 8B16[A66C]              	mov     dx, [audio_io_base] ; tells to the SB to
  6981                                  	;add	dx, 0Ch		    ; generate a IRQ!
  6982 00002330 80C20C                  	add	dl, 0Ch
  6983                                  WaitSb:
  6984 00002333 EC                      	in	al, dx
  6985 00002334 08C0                    	or      al, al
  6986 00002336 78FB                    	js      short WaitSb
  6987 00002338 B0F2                    	mov     al, 0F2h
  6988 0000233A EE                      	out	dx, al
  6989                                  	; 24/11/2024
  6990 0000233B 31C9                    	xor     cx, cx	; wait until IRQ level
  6991                                  WaitIRQ: 
  6992 0000233D A0[AB6C]                	mov	al, [IRQnum]
  6993 00002340 3C00                    	cmp     al, 0 ; is changed or timeout.
  6994 00002342 7705                    	ja	short IrqOk
  6995 00002344 49                      	dec	cx
  6996 00002345 75F6                    	jnz	short WaitIRQ
  6997 00002347 EB0F                    	jmp	short RestoreIrqs
  6998                                  IrqOk:
  6999                                  	;;;
  7000                                  	; 27/11/2024
  7001 00002349 A2[9A6C]                	mov	[audio_intr], al
  7002 0000234C 8B16[A66C]              	mov 	dx, [audio_io_base]
  7003                                  	;add	dx, 0Eh
  7004 00002350 80C20E                  	add	dl, 0Eh ; 8bit DMA-mode int ack
  7005 00002353 EC                      	in	al, dx	; SB acknowledge.
  7006                                  	;
  7007                                  	; 10/02/2025
  7008                                  	; 16bit DMA mode intr ack is
  7009                                  	; not necessary for initial IRQ scan
  7010                                  	;
  7011                                  	;inc	dx ; 0Fh ; 16bit DMA-mode int ack
  7012                                  	;in	al, dx	; SB 16 acknowledge.
  7013                                  	;
  7014                                  	;;;
  7015 00002354 B020                    	mov	al, 20h
  7016 00002356 E620                    	out	20h, al	; Hardware acknowledge.
  7017                                  RestoreIrqs:
  7018                                  	; ah = 0 -> reset IRQ vector
  7019                                  	; al = IRQ number
  7020 00002358 B80500                  	mov	ax, 5 ; IRQ 5
  7021 0000235B E80C00                  	call	set_hardware_int_vector
  7022 0000235E B80700                  	mov	ax, 7 ; IRQ 7
  7023 00002361 E80600                  	call	set_hardware_int_vector
  7024                                  
  7025 00002364 803E[AB6C]01            	cmp     byte [IRQnum], 1 ; IRQ level was changed?
  7026                                  	
  7027 00002369 C3                      	retn
  7028                                  
  7029                                  ;-----------------------------------------------------------------------------
  7030                                  
  7031                                  	; 06/02/2025
  7032                                  	; 24/11/2024
  7033                                  set_hardware_int_vector:
  7034 0000236A 08E4                    	or	ah, ah
  7035 0000236C 753F                    	jnz	short shintv_1 ; set user's audio interrupt handler
  7036                                  
  7037                                  rhintv_1:		
  7038                                  	; reset the interrupt vector to the old interrupt handler
  7039 0000236E 1E                      	push	ds
  7040 0000236F 3C05                    	cmp	al, 5
  7041 00002371 751D                    	jne	short rhintv_2
  7042                                  
  7043                                  	; 25/11/2024
  7044                                  	; restore IRQ 5 status
  7045 00002373 8A26[AC6C]              	mov	ah, [IRQstatus]
  7046 00002377 E421                    	in	al, 21h
  7047 00002379 80E420                  	and	ah, 00100000b ; 20h
  7048 0000237C 08E0                    	or	al, ah
  7049 0000237E E621                    	out     21h, al
  7050                                  
  7051 00002380 8B16[146C]              	mov	dx, [old_irq5v_o]
  7052 00002384 8E1E[166C]              	mov	ds, [old_irq5v_s]
  7053                                  shintv_3:
  7054 00002388 B00D                    	mov	al, 0Dh
  7055 0000238A B425                    	mov	ah, 25h
  7056 0000238C CD21                    	int	21h
  7057 0000238E 1F                      	pop	ds
  7058 0000238F C3                      	retn
  7059                                  
  7060                                  rhintv_2:
  7061                                  	; 25/11/2024
  7062                                  	; restore IRQ 7 status
  7063 00002390 8A26[AC6C]              	mov	ah, [IRQstatus]
  7064 00002394 E421                    	in	al, 21h
  7065 00002396 80E480                  	and	ah, 10000000b ; 80h
  7066 00002399 08E0                    	or	al, ah
  7067 0000239B E621                    	out     21h, al
  7068                                  
  7069 0000239D 8B16[186C]              	mov	dx, [old_irq7v_o]
  7070 000023A1 8E1E[1A6C]              	mov	ds, [old_irq7v_s]
  7071                                  shintv_4:
  7072 000023A5 B00F                    	mov	al, 0Fh
  7073 000023A7 B425                    	mov	ah, 25h
  7074 000023A9 CD21                    	int	21h
  7075 000023AB 1F                      	pop	ds
  7076 000023AC C3                      	retn
  7077                                  
  7078                                  shintv_1:
  7079 000023AD 06                      	push	es
  7080                                  
  7081 000023AE 3C05                    	cmp	al, 5
  7082 000023B0 7518                    	jne	short shintv_2
  7083                                  
  7084                                  	; INT 0Dh = IRQ 5 (default) interrupt number
  7085                                  
  7086                                  	; 25/11/2024
  7087                                  	; enable IRQ 5
  7088                                  	; 26/11/2024
  7089 000023B2 E421                    	in	al, 21h
  7090 000023B4 24DF                    	and	al, 11011111b
  7091 000023B6 E621                    	out     21h, al
  7092                                  
  7093 000023B8 B00F                    	mov	al, 0Fh
  7094 000023BA B435                    	mov	ah, 35h	; Get Interrupt Vector 
  7095 000023BC CD21                    	int	21h
  7096 000023BE 8C06[166C]              	mov	[old_irq5v_s], es
  7097 000023C2 891E[146C]              	mov	[old_irq5v_o], bx
  7098 000023C6 07                      	pop	es
  7099 000023C7 1E                      	push	ds
  7100                                  	; 27/11/2024
  7101                                  	;mov	dx, IRQ5_service
  7102 000023C8 EBBE                    	jmp	short shintv_3
  7103                                  
  7104                                  shintv_2:	
  7105                                  	; al = 7
  7106                                  	; INT 0Fh = IRQ 7 (default) interrupt number
  7107                                  
  7108                                  	; 25/11/2024
  7109                                  	; enable IRQ 7
  7110                                  	; 26/11/2024
  7111 000023CA E421                    	in	al, 21h
  7112 000023CC 247F                    	and	al, 01111111b
  7113 000023CE E621                    	out     21h, al
  7114                                  	
  7115 000023D0 B00F                    	mov	al, 0Fh
  7116 000023D2 B435                    	mov	ah, 35h	; Get Interrupt Vector 
  7117 000023D4 CD21                    	int	21h
  7118 000023D6 8C06[1A6C]              	mov	[old_irq7v_s], es
  7119 000023DA 891E[186C]              	mov	[old_irq7v_o], bx
  7120 000023DE 07                      	pop	es
  7121 000023DF 1E                      	push	ds
  7122                                  	; 27/11/2024
  7123                                  	;mov	dx, IRQ7_service
  7124 000023E0 EBC3                    	jmp	short shintv_4
  7125                                  
  7126                                  IRQ5_service:
  7127 000023E2 2EC606[AB6C]05          	mov	byte [cs:IRQnum], 5
  7128 000023E8 CF                      	iret
  7129                                  
  7130                                  IRQ7_service:
  7131 000023E9 2EC606[AB6C]07          	mov	byte [cs:IRQnum], 7
  7132 000023EF CF                      	iret
  7133                                  
  7134                                  	; 27/11/2024
  7135                                  IRQ_service:
  7136 000023F0 1E                      	push	ds
  7137 000023F1 52                      	push	dx
  7138 000023F2 50                      	push	ax
  7139                                  	;
  7140 000023F3 0E                      	push	cs
  7141 000023F4 1F                      	pop	ds
  7142 000023F5 C606[AB6C]05            	mov	byte [IRQnum], 5
  7143 000023FA 8B16[A66C]              	mov     dx, [audio_io_base]
  7144                                  	;add	dx, 0Eh
  7145 000023FE 80C20E                  	add	dl, 0Eh ; 8bit DMA-mode int ack
  7146 00002401 803E[3E6C]08            	cmp	byte [WAVE_BitsPerSample], 8
  7147 00002406 7601                    	jna	short irq_ack_@
  7148                                  	;inc	dl ; 0Fh ; 16bit DMA-mode int ack
  7149                                  	; 10/02/2025
  7150 00002408 42                      	inc	dx
  7151                                  irq_ack_@:
  7152 00002409 EC                      	in	al, dx	; SB acknowledge.
  7153                                  	;
  7154 0000240A B020                    	mov	al, 20h
  7155 0000240C E620                    	out	20h, al	; Hardware acknowledge
  7156                                  	;
  7157 0000240E 58                      	pop	ax
  7158 0000240F 5A                      	pop	dx
  7159 00002410 1F                      	pop	ds
  7160 00002411 CF                      	iret
  7161                                  
  7162                                  ;-----------------------------------------------------------------------------
  7163                                  ; get CPU type - AC'97 audio system will not be checked if CPU is not 80386+
  7164                                  ;-----------------------------------------------------------------------------
  7165                                  ; Ref: ibmdos7.s - 10/07/2024 (Retro DOS v5.0, PCDOS 7.1 kernel)
  7166                                  
  7167                                  	; 07/02/2025
  7168                                  	; 06/02/2025
  7169                                  Get_CPU_Type:
  7170 00002412 9C                      	pushf
  7171 00002413 31C0                    	xor	ax, ax			; 0000 into AX
  7172 00002415 50                      	push	ax			; put it on the stack...
  7173 00002416 9D                      	popf				; ...then shove it into the flags
  7174 00002417 9C                      	pushf				; get it back out of the flags...
  7175 00002418 58                      	pop	ax			; ...and into ax
  7176 00002419 2500F0                  	and	ax, 0F000h		; mask off high four bits
  7177 0000241C 3D00F0                  	cmp	ax, 0F000h		; was it all 1's?
  7178 0000241F 740F                    	je	short cpu_8086		; yes; it's an 8086 or 8088
  7179                                  
  7180 00002421 B800F0                  	mov	ax, 0F000h		; now try to set the high four bits..
  7181 00002424 50                      	push	ax
  7182 00002425 9D                      	popf
  7183 00002426 9C                      	pushf
  7184 00002427 58                      	pop	ax			; ...and see what happens
  7185 00002428 2500F0                  	and	ax, 0F000h		; any high bits set ?
  7186 0000242B 7403                    	jz	short cpu_286		; no, it's an 80286
  7187                                  cpu_386:				; yes, it's an 80386
  7188 0000242D 9D                      	popf
  7189 0000242E F8                      	clc
  7190 0000242F C3                      	retn
  7191                                  cpu_8086:
  7192                                  cpu_286:
  7193 00002430 9D                      	popf
  7194 00002431 F9                      	stc
  7195 00002432 C3                      	retn
  7196                                  
  7197                                  ;-----------------------------------------------------------------------------
  7198                                  ; settextmode - restore the VGA 80x25x16 text mode
  7199                                  ;-----------------------------------------------------------------------------
  7200                                  	
  7201                                  	; 07/02/2025
  7202                                  settextmode:
  7203 00002433 B80300                  	mov	ax, 0003h
  7204 00002436 CD10                    	int	10h
  7205 00002438 C3                      	retn
  7206                                  	
  7207                                  ;=============================================================================
  7208                                  ; drawscopes - draw wave/voice sample scopes
  7209                                  ;=============================================================================
  7210                                  	
  7211                                  	; 07/02/2025
  7212                                  drawscopes:
  7213 00002439 E8A600                  	call	get_current_sound_data
  7214 0000243C BE[D076]                	mov	si, g_buffer
  7215                                  
  7216 0000243F 31C9                    	xor     cx, cx
  7217 00002441 31D2                    	xor     dx, dx
  7218 00002443 31FF                    	xor	di, di
  7219                                  drawscope0:
  7220 00002445 AD                      	lodsw
  7221 00002446 80F480                  	xor	ah, 80h
  7222 00002449 30FF                    	xor	bh, bh
  7223 0000244B 88E3                    	mov	bl, ah	; Left Channel
  7224 0000244D D1E3                    	shl	bx, 1
  7225 0000244F 8B87[B06C]              	mov	ax, [RowOfs+bx]
  7226 00002453 8985[B06E]              	mov	[NewScope_L+di], ax
  7227 00002457 30FF                    	xor	bh, bh
  7228 00002459 AD                      	lodsw
  7229 0000245A 80F480                  	xor	ah, 80h
  7230 0000245D 88E3                    	mov	bl, ah	; Right Channel
  7231 0000245F D1E3                    	shl	bx, 1
  7232 00002461 8B87[B06C]              	mov	ax, [RowOfs+bx]
  7233 00002465 8985[B070]              	mov	[NewScope_R+di], ax
  7234 00002469 83C702                  	add	di, 2
  7235 0000246C FEC1                    	inc	cl
  7236 0000246E 75D5                    	jnz	short drawscope0
  7237                                  
  7238 00002470 BAC403                  	mov	dx, 3C4h
  7239 00002473 B80208                  	mov	ax, 0802h
  7240 00002476 EF                      	out	dx, ax
  7241                                  
  7242                                  	;mov	dx, 3CEh
  7243 00002477 B2CE                    	mov	dl, 0CEh
  7244 00002479 B008                    	mov	al, 08h
  7245 0000247B EE                      	out	dx, al
  7246                                  
  7247 0000247C 42                      	inc	dx
  7248                                  
  7249 0000247D 31F6                    	xor	si, si
  7250 0000247F 06                      	push	es  ; ***
  7251 00002480 BB00A0                  	mov	bx, 0A000h
  7252 00002483 8EC3                    	mov	es, bx
  7253 00002485 BB4506                  	mov	bx, 0645h
  7254                                  	; 0A0645h
  7255                                  drawscopel4:
  7256 00002488 B080                    	mov     al, 80h
  7257                                  drawscopel2:
  7258 0000248A 50                      	push	ax ; **
  7259 0000248B 52                      	push	dx ; *
  7260 0000248C EE                      	out	dx, al
  7261                                  
  7262                                  	;mov	cx, 32
  7263 0000248D B120                    	mov	cl, 32
  7264 0000248F B800FF                  	mov	ax, 0FF00h
  7265                                  drawscopel3:
  7266 00002492 8BBC[B072]                      mov	di, [OldScope_L+si]
  7267 00002496 8B94[B06E]              	mov	dx, [NewScope_L+si]
  7268 0000249A 39D7                            cmp	di, dx
  7269 0000249C 7410                            je	short drawscopef3
  7270 0000249E 01DF                    	add	di, bx
  7271 000024A0 268805                  	mov	[es:di], al ; L
  7272 000024A3 89D7                            mov     di, dx
  7273 000024A5 01DF                    	add	di, bx
  7274 000024A7 268825                  	mov	[es:di], ah ; L
  7275 000024AA 8994[B072]                      mov     [OldScope_L+si], dx
  7276                                  drawscopef3:
  7277 000024AE 8BBC[B074]              	mov	di, [OldScope_R+si]
  7278 000024B2 8B94[B070]              	mov	dx, [NewScope_R+si]
  7279 000024B6 39D7                    	cmp	di, dx
  7280 000024B8 7412                    	je	short drawscopef4
  7281 000024BA 01DF                    	add	di, bx
  7282 000024BC 26884526                	mov	[es:di+38], al ; R
  7283 000024C0 89D7                    	mov     di, dx
  7284 000024C2 01DF                    	add	di, bx
  7285 000024C4 26886526                	mov	[es:di+38], ah ; R
  7286 000024C8 8994[B074]              	mov     [OldScope_R+si], dx
  7287                                  drawscopef4:
  7288 000024CC 83C610                  	add	si, 2*8
  7289 000024CF 43                      	inc	bx
  7290 000024D0 E2C0                    	loop    drawscopel3
  7291                                  
  7292 000024D2 5A                              pop     dx ; *
  7293 000024D3 58                              pop     ax ; **
  7294 000024D4 81EEFE01                	sub	si, 2*256-2
  7295 000024D8 83EB20                  	sub	bx, 32
  7296 000024DB D0E8                            shr     al, 1
  7297 000024DD 75AB                            jnz	short drawscopel2
  7298                                  	; 07/02/2025
  7299 000024DF F8                      	clc
  7300 000024E0 07                      	pop	es ; ***
  7301 000024E1 C3                              retn
  7302                                  
  7303                                  ;=============================================================================
  7304                                  ; Get Current Sound Data
  7305                                  ;=============================================================================
  7306                                  ; Reference: TRDOS 386 v2.0.9 Kernel - audio.s file (28/01/2025)
  7307                                  
  7308                                  	; 08/02/2025 (*)
  7309                                  	; !!! 18.2 block/second buffer sizing for proper wave scopes !!!
  7310                                  	; (wave graphics synchronization) 
  7311                                  
  7312                                  	; 07/02/2025
  7313                                  get_current_sound_data:
  7314                                  	; get current sound (PCM out) data for graphics
  7315                                  
  7316 000024E2 BF[D076]                	mov	di, g_buffer
  7317                                  
  7318 000024E5 803E[AA6C]01            	cmp	byte [audio_hardware], 1
  7319 000024EA 7731                    	ja	short ac97_current_sound_data
  7320                                  
  7321                                  ;-----------------------------------------------------------------------------
  7322                                  	
  7323                                  	; 08/02/2025 (*)		
  7324                                  sb16_current_sound_data:
  7325 000024EC 8B0E[CA76]              	mov	cx, [g_samples]
  7326                                  	
  7327 000024F0 803E[3E6C]10            	cmp	byte [WAVE_BitsPerSample], 16
  7328 000024F5 750C                    	jne	short sb16_gcd_1 ; 8 bit DMA channel
  7329 000024F7 E4C6                    	in	al, 0C6h ; DMA channel 5 count register
  7330 000024F9 88C4                    	mov	ah, al
  7331 000024FB E4C6                    	in	al, 0C6h
  7332 000024FD 86C4                    	xchg	ah, al
  7333 000024FF D1E0                    	shl	ax, 1 ; word count -> byte count
  7334 00002501 EB08                    	jmp	short sb16_gcd_2
  7335                                  sb16_gcd_1:
  7336 00002503 E403                    	in	al, 03h ; DMA channel 1 count register
  7337 00002505 88C4                    	mov	ah, al
  7338 00002507 E403                    	in	al, 03h
  7339 00002509 86C4                    	xchg	ah, al
  7340                                  
  7341                                  sb16_gcd_2:
  7342                                  	;cmp	ax, cx
  7343                                  	;jnb	short sb16_gcd_3
  7344                                  	;; remain count < graphics bytes
  7345                                  	;mov	ax, cx ; fix remain count to data size
  7346                                  	; 08/02/2025 (*)
  7347 0000250B 8B1E[BA76]              	mov	bx, [buffersize] ; half buffer size
  7348 0000250F 39D8                    	cmp	ax, bx
  7349 00002511 7602                    	jna	short sb16_gcd_3 ; 2nd half
  7350 00002513 31DB                    	xor	bx, bx ; 1st half
  7351                                  sb16_gcd_3:
  7352                                  	;mov	si, dma_buffer+dma_buffer_size ; 32768
  7353                                  	;sub	si, ax
  7354                                  	; 08/02/2025 (*)
  7355 00002515 8DB7[D07A]              	lea	si, [dma_buffer+bx] ; start of 1st half or 2nd half
  7356                                  
  7357                                  	; si = dma buffer offset
  7358                                  	; cx = load (source) count
  7359                                  	; di = g_buffer
  7360                                  
  7361 00002519 FF26[C876]              	jmp	word [sound_data_copy]
  7362                                  
  7363                                  ;-----------------------------------------------------------------------------
  7364                                  
  7365                                  	; 10/02/2025
  7366                                  	; 09/02/2025
  7367                                  	; 08/02/2025 (*)
  7368                                  	; 08/02/2025
  7369                                  	; 07/02/2025
  7370                                  ac97_current_sound_data:
  7371                                  	;mov	cx, 1024 ; always 16bit stereo
  7372                                  	; 08/02/2025
  7373 0000251D B90002                  	mov	cx, 512
  7374                                  
  7375 00002520 BA1400                  	mov	dx, PO_CIV_REG ; Position In Current Buff Reg
  7376 00002523 0316[A86C]              	add	dx, [NABMBAR]
  7377 00002527 EC                      	in	al, dx	; current index value
  7378 00002528 8B1E[B276]              	mov	bx, [WAV_BUFFER_1]
  7379 0000252C A801                    	test	al, 1
  7380 0000252E 7404                    	jz	short ac97_gcd_1
  7381 00002530 8B1E[B476]              	mov	bx, [WAV_BUFFER_2]
  7382                                  ac97_gcd_1:
  7383                                  	; 10/02/2025
  7384                                  	;mov	dx, PO_PICB_REG ; Position In Current Buff Reg
  7385                                  	;add	dx, [NABMBAR]
  7386                                  	;in	ax, dx	; remain words
  7387                                  	; 08/02/2025
  7388                                  	;shl	ax, 1	; remain bytes
  7389                                  ac97_gcd_2:
  7390                                  	;cmp	ax, cx
  7391                                  	;jnb	short ac97_gcd_3
  7392                                  	;; remain count < graphics bytes
  7393                                  	;mov	ax, cx ; fix remain count to data size
  7394                                  	; 09/02/2025
  7395                                  	; 08/02/2025 (*)
  7396 00002534 31F6                    	xor	si, si ; 1st half
  7397                                  ac97_gcd_3:
  7398 00002536 1E                      	push	ds
  7399                                  
  7400                                  	; 08/02/2025
  7401                                  	;mov	si, [buffersize] ; 16 bit sample count
  7402                                  	;sub	si, ax
  7403                                  	;shl	si, 1 ; byte offset
  7404                                  
  7405                                  	; 09/02/2025
  7406                                  	; si = 0, start of the wave/pcm data (dma) buffer
  7407                                  	; (buffer size is adjusted for playing in 1/18.2 second) 
  7408                                  
  7409 00002537 8EDB                    	mov	ds, bx
  7410                                  
  7411                                  	; ds:si = dma buffer offset
  7412                                  	; cx = load (source) count
  7413                                  	; es:di = g_buffer
  7414                                  
  7415                                  	; AC97 dma buffer contains 16bit stereo samples (only)
  7416                                  	; copy samples to g_buffer
  7417                                  
  7418                                  	;shr	cx, 1
  7419 00002539 F3A5                    	rep	movsw
  7420                                  	
  7421 0000253B 1F                      	pop	ds
  7422 0000253C C3                      	retn
  7423                                  
  7424                                  ;-----------------------------------------------------------------------------
  7425                                  
  7426                                  	; 07/02/2025
  7427                                  sdc_16bit_stereo:
  7428                                  	; si = dma buffer offset
  7429                                  	; cx = load (source) count = 1024
  7430                                  	; di = g_buffer
  7431 0000253D D1E9                    	shr	cx, 1
  7432 0000253F F3A5                    	rep	movsw
  7433 00002541 C3                      	retn
  7434                                  
  7435                                  ;-----------------------------------------------------------------------------
  7436                                  
  7437                                  	; 07/02/2025
  7438                                  sdc_16bit_mono:
  7439                                  	; si = dma buffer offset
  7440                                  	; cx = load (source) count = 512
  7441                                  	; di = g_buffer
  7442 00002542 D1E9                    	shr	cx, 1
  7443                                  sdc_16bm_loop:
  7444 00002544 AD                      	lodsw
  7445 00002545 AB                      	stosw
  7446 00002546 AB                      	stosw
  7447 00002547 E2FB                    	loop	sdc_16bm_loop
  7448 00002549 C3                      	retn
  7449                                  
  7450                                  ;-----------------------------------------------------------------------------
  7451                                  
  7452                                  	; 07/02/2025
  7453                                  sdc_8bit_stereo:
  7454                                  	; si = dma buffer offset
  7455                                  	; cx = load (source) count = 512
  7456                                  	; di = g_buffer
  7457                                  
  7458                                  	; convert to 16 bit sample
  7459                                  sdc_8bs_loop:
  7460 0000254A AC                      	lodsb
  7461 0000254B 2C80                    	sub	al, 80h ; middle = 0, min = -128, max = 127
  7462 0000254D C1E008                  	shl	ax, 8
  7463 00002550 AB                      	stosw
  7464 00002551 E2F7                    	loop	sdc_8bs_loop
  7465 00002553 C3                      	retn
  7466                                  
  7467                                  ;-----------------------------------------------------------------------------
  7468                                  
  7469                                  	; 07/02/2025
  7470                                  sdc_8bit_mono:
  7471                                  	; si = dma buffer offset
  7472                                  	; cx = load (source) count = 256
  7473                                  	; di = g_buffer
  7474                                  
  7475                                  	; convert to 16 bit sample
  7476                                  sdc_8bm_loop:
  7477 00002554 AC                      	lodsb
  7478 00002555 2C80                    	sub	al, 80h ; middle = 0, min = -128, max = 127
  7479 00002557 C1E008                  	shl	ax, 8
  7480 0000255A AB                      	stosw	; L
  7481                                  	; convert to stereo
  7482 0000255B AB                      	stosw	; R
  7483 0000255C E2F6                    	loop	sdc_8bm_loop
  7484 0000255E C3                      	retn
  7485                                  
  7486                                  ;-----------------------------------------------------------------------------
  7487                                  ; Memory Allocation
  7488                                  ;-----------------------------------------------------------------------------
  7489                                  
  7490                                  	; 07/02/2025
  7491                                  	; Release memory not used
  7492                                  setFree:
  7493 0000255F BB0010                  	mov	bx, 65536/16	; 4K paragraphs ; 17/02/2017 (Erdogan Tan)
  7494                                  
  7495 00002562 B44A                    	mov	ah, 4Ah		; pass new length to DOS
  7496 00002564 CD21                    	int	21h
  7497                                  
  7498 00002566 C3                      	retn			; back to caller 
  7499                                  				; new size (allocated memory) = 64KB
  7500                                  
  7501                                  ;-----------------------------------------------------------------------------
  7502                                  
  7503                                  	; 08/02/2025
  7504                                  	; bx = number of paragraphs
  7505                                  
  7506                                  	; 07/02/2025
  7507                                  memAlloc:
  7508                                  	; input: AX = # of paragraphs required
  7509                                  	; output: AX = segment of block to use
  7510                                  
  7511                                  	; 08/02/2025
  7512                                  	;mov	bx, ax
  7513 00002567 B448                    	mov	ah, 48h
  7514 00002569 CD21                    	int	21h
  7515 0000256B C3                      	retn
  7516                                  
  7517                                  ;-----------------------------------------------------------------------------
  7518                                  ; Print/Display Text
  7519                                  ;-----------------------------------------------------------------------------
  7520                                  
  7521                                  	; 07/02/2025
  7522                                  	; 04/02/2025 - cgaplay.asm
  7523                                  	; 01/01/2025 
  7524                                  	; 21/12/2024
  7525                                  	; 14/11/2024
  7526                                  PrintString:
  7527 0000256C B40E                    	mov	ah, 0Eh
  7528 0000256E BB0F00                  	mov	bx, 0Fh ; char attribute & color (white)
  7529                                  p_msg:
  7530                                  	; ah = 0Eh
  7531                                  	; bh = 0
  7532                                  	; bl = color
  7533                                  	; ds:si = msg address
  7534                                  p_next_chr:
  7535 00002571 AC                      	lodsb
  7536 00002572 08C0                    	or	al, al
  7537 00002574 7404                    	jz	short p_retn ; retn
  7538 00002576 CD10                    	int	10h
  7539 00002578 EBF7                    	jmp	short p_next_chr
  7540                                  p_retn:
  7541 0000257A C3                      	retn
  7542                                  
  7543                                  ;-----------------------------------------------------------------------------
  7544                                  
  7545                                  ;=============================================================================
  7546                                  ;	Load IFF/ILBM files for VGA 640x480x16 graphics mode
  7547                                  ;=============================================================================
  7548                                  
  7549                                  ; EX1B.ASM (21/6/1994, Carlos Hasan; MSDOS, 'RUNME.EXE', 'TNYPL211')
  7550                                  
  7551                                  ; 21/10/2017 (TRDOS 386, 'tmodplay.s', Erdogan Tan, NASM syntax)
  7552                                  
  7553                                  ;-----------------------------------------------------------------------------
  7554                                  ; EQUATES AND STRUCTURES
  7555                                  ;-----------------------------------------------------------------------------
  7556                                  
  7557                                  ID_FORM equ 4D524F46h		; IFF/ILBM chunk IDs
  7558                                  ID_ILBM equ 4D424C49h
  7559                                  ID_BMHD equ 44484D42h
  7560                                  ID_CMAP equ 50414D43h
  7561                                  ID_BODY equ 59444F42h
  7562                                  
  7563                                  struc Form			; IFF/ILBM header file format
  7564 00000000 ????????                  .ID:		resd 1
  7565 00000004 ????????                  .Length:	resd 1
  7566 00000008 ????????                  .Type:	resd 1
  7567                                    .size:
  7568                                  endstruc
  7569                                  
  7570                                  struc Chunk			; IFF/ILBM header chunk format
  7571 00000000 ????????                  .ID:		resd 1
  7572 00000004 ????????                  .Length:	resd 1
  7573                                    .size:
  7574                                  endstruc
  7575                                  
  7576                                  struc BMHD			; IFF/ILBM BMHD chunk format
  7577 00000000 ????                      .Width: 	resw 1
  7578 00000002 ????                      .Height:	resw 1
  7579 00000004 ????                      .PosX:	resw 1
  7580 00000006 ????                      .PosY:	resw 1
  7581 00000008 ??                        .Planes:	resb 1
  7582 00000009 ??                        .Masking:	resb 1
  7583 0000000A ??                        .Compression:	resb 1
  7584 0000000B ??                        .Pad:		resb 1
  7585 0000000C ????                      .Transparent:	resw 1
  7586 0000000E ??                        .AspectX	resb 1
  7587 0000000F ??                        .AspectY:	resb 1
  7588 00000010 ????                      .PageWidth:	resw 1
  7589 00000012 ????                      .PageHeight:	resw 1
  7590                                    .size:
  7591                                  endstruc
  7592                                  
  7593                                  struc CMAP			; IFF/ILBM CMAP chunk format
  7594 00000000 <res 300h>                .Colors:	resb 768
  7595                                    .size:
  7596                                  endstruc
  7597                                  
  7598                                  ;------------------------------------------------------------------------------
  7599                                  ; bswap - macro to reverse the byte order of a 32-bit register, converting
  7600                                  ;         a value in little/big endian form to big/little endian form.
  7601                                  ;------------------------------------------------------------------------------
  7602                                  
  7603                                  ;%macro	bswap   1
  7604                                  ;       xchg    al, ah
  7605                                  ;       rol     eax, 16
  7606                                  ;       xchg    al, ah
  7607                                  ;%endmacro
  7608                                  
  7609                                  ;------------------------------------------------------------------------------
  7610                                  ; putlbm - draw the IFF/ILBM picture on VGA 640x480x16 graphics mode
  7611                                  ; In:
  7612                                  ;  ESI = IFF/ILBM image file address
  7613                                  ;------------------------------------------------------------------------------
  7614                                  
  7615                                  	; 07/02/2025
  7616                                  putlbm:
  7617                                  	; 06/02/2025
  7618 0000257B BE[4626]                	mov	si, LOGO_ADDRESS
  7619                                  	
  7620                                  	;pushad
  7621                                  
  7622                                  ; check if this is a valid IFF/ILBM Deluxe Paint file
  7623                                  
  7624                                  ;	cmp	dword [si+Form.ID], ID_FORM
  7625                                  ;	jne	short putlbmd0
  7626                                  ;	cmp	dword [si+Form.Type], ID_ILBM
  7627                                  ;	jne	short putlbmd0
  7628                                  
  7629                                  ; get the IFF/ILBM file length in bytes
  7630                                  
  7631                                  	;mov	eax, [esi+Form.Length]
  7632                                          ;bswap	eax
  7633                                  	;mov	ecx, eax
  7634                                  
  7635 0000257E 8B4C06                  	mov	cx, [si+Form.Length+2]
  7636 00002581 86E9                    	xchg	cl, ch
  7637                                  
  7638                                  ; decrease the file length and updates the file pointer
  7639                                  
  7640                                  	;sub	ecx, 4
  7641 00002583 83E904                  	sub	cx, 4	
  7642                                  
  7643 00002586 83C60C                  	add	si, Form.size
  7644                                  
  7645                                  ; IFF/ILBM main parser body loop
  7646                                  
  7647                                  putlbml0:
  7648                                  	;test	ecx, ecx
  7649 00002589 85C9                    	test	cx, cx
  7650 0000258B 7E51                            jle	short putlbmd1
  7651                                  
  7652                                  ; get the next chunk ID and length in bytes
  7653                                  
  7654                                  	;mov	ebx, [si+Chunk.ID]
  7655                                  	;mov	eax, [si+Chunk.Length]
  7656                                  	;bswap	eax
  7657                                  	;xchg	ebx, eax
  7658 0000258D 8B04                    	mov	ax, [si+Chunk.ID]
  7659 0000258F 8B5C06                  	mov	bx, [si+Chunk.Length+2]
  7660 00002592 86DF                    	xchg	bh, bl	
  7661                                  
  7662 00002594 83C608                          add     si, Chunk.size
  7663                                  
  7664                                  ; word align the chunk length and decrease the file length counter
  7665                                  
  7666                                  	;inc	ebx
  7667 00002597 43                      	inc	bx
  7668 00002598 80E3FE                  	and	bl, 0FEh ; ~1
  7669                                  	;sub	ecx, Chunk.size
  7670 0000259B 83E908                  	sub	cx, Chunk.size
  7671                                          
  7672                                  	;sub	ecx, ebx
  7673 0000259E 29D9                    	sub	cx, bx
  7674                                  
  7675                                  ; check for the BMHD/CMAP/BODY chunk headers
  7676                                  
  7677                                  	;cmp	eax, ID_BMHD
  7678 000025A0 3D424D                  	cmp	ax, 'BM'
  7679 000025A3 7410                    	je	short putlbmf0
  7680                                  	;cmp	eax, ID_CMAP
  7681 000025A5 3D434D                  	cmp	ax, 'CM'
  7682 000025A8 7436                    	je	short putlbmf1
  7683                                  	;cmp	eax, ID_BODY
  7684 000025AA 3D424F                  	cmp	ax, 'BO'
  7685 000025AD 7444                            je      short putlbmf2
  7686                                  
  7687                                  ; advance to the next IFF/ILBM chunk structure
  7688                                  
  7689                                  putlbmc0:
  7690                                  	;add	esi, ebx
  7691 000025AF 01DE                    	add	si, bx
  7692 000025B1 EBD6                    	jmp     short putlbml0
  7693                                  
  7694                                  putlbmd0:
  7695 000025B3 F9                      	stc
  7696                                  	;popad
  7697 000025B4 C3                      	retn
  7698                                  
  7699                                  ; process the BMHD bitmap header chunk
  7700                                  
  7701                                  putlbmf0:
  7702 000025B5 807C0804                	cmp	byte [si+BMHD.Planes], 4
  7703 000025B9 75F8                    	jne	short putlbmd0
  7704 000025BB 807C0A01                	cmp	byte [si+BMHD.Compression], 1
  7705 000025BF 75F2                    	jne	short putlbmd0
  7706 000025C1 807C0B00                	cmp	byte [si+BMHD.Pad], 0
  7707 000025C5 75EC                    	jne	short putlbmd0
  7708                                  	;movzx	eax, word [esi+BMHD.Width]
  7709 000025C7 8B04                    	mov	ax, [si+BMHD.Width]
  7710 000025C9 86E0                    	xchg	al, ah
  7711                                  	;add	eax, 7
  7712                                  	;shr	eax, 3
  7713 000025CB 83C007                  	add	ax, 7
  7714 000025CE C1E803                  	shr	ax, 3
  7715                                  	;mov	[picture.width], eax
  7716 000025D1 A3[106C]                	mov	[picture.width], ax
  7717                                  	;movzx	eax, word [esi+BMHD.Height]
  7718 000025D4 8B4402                  	mov	ax, [si+BMHD.Height]
  7719 000025D7 86E0                    	xchg	al, ah
  7720                                  	;mov	[picture.height], eax
  7721 000025D9 A3[126C]                	mov	[picture.height], ax
  7722 000025DC EBD1                    	jmp	short putlbmc0
  7723                                  
  7724                                  putlbmd1:
  7725 000025DE F8                      	clc
  7726                                  	;popad
  7727 000025DF C3                      	retn
  7728                                  
  7729                                  ; process the CMAP colormap chunk
  7730                                  
  7731                                  putlbmf1:
  7732 000025E0 BAC803                  	mov	dx, 3C8h
  7733 000025E3 30C0                    	xor	al, al
  7734 000025E5 EE                      	out	dx, al
  7735                                  
  7736 000025E6 42                      	inc	dx
  7737                                  putlbml1:
  7738 000025E7 8A04                    	mov	al, [si]
  7739 000025E9 C0E802                  	shr	al, 2
  7740 000025EC EE                      	out	dx, al
  7741                                  
  7742 000025ED 46                      	inc	si
  7743 000025EE 4B                      	dec	bx
  7744 000025EF 7FF6                    	jg	short putlbml1
  7745 000025F1 EB96                    	jmp	putlbml0
  7746                                  
  7747                                  ; process the BODY bitmap body chunk
  7748                                  
  7749                                  putlbmf2:
  7750                                  	;pushad
  7751 000025F3 60                      	pusha
  7752                                          ;mov	edi, 0A0000h
  7753                                          ;cld
  7754 000025F4 06                      	push	es
  7755 000025F5 BF00A0                  	mov	di, 0A000h
  7756 000025F8 8EC7                    	mov	es, di
  7757 000025FA 31FF                    	xor	di, di
  7758 000025FC BACE03                  	mov	dx, 3CEh
  7759 000025FF B808FF                  	mov	ax, 0FF08h
  7760 00002602 EF                      	out	dx, ax
  7761                                  	;mov	dx, 3C4h
  7762 00002603 B2C4                    	mov	dl, 0C4h
  7763 00002605 B002                    	mov     al, 02h
  7764 00002607 EE                              out	dx, al
  7765 00002608 42                      	inc	dx
  7766                                  	;mov	ecx, [picture.height]
  7767 00002609 8B0E[126C]              	mov	cx, [picture.height]
  7768                                  putlbml2:
  7769                                  	;push	ecx
  7770 0000260D 51                      	push	cx
  7771 0000260E B011                    	mov	al, 11h
  7772                                  putlbml3:
  7773                                  	;push	eax
  7774                                  	;push	edi
  7775 00002610 50                      	push	ax
  7776 00002611 57                      	push	di
  7777 00002612 EE                              out	dx, al
  7778                                  	;mov	ebx, [picture.width]
  7779 00002613 8B1E[106C]              	mov	bx, [picture.width]
  7780                                  putlbml4:
  7781 00002617 AC                              lodsb
  7782 00002618 30ED                    	xor	ch, ch
  7783 0000261A 84C0                            test	al, al
  7784 0000261C 7C09                            jl	short putlbmf3
  7785                                  	;movzx	ecx, al
  7786 0000261E 88C1                    	mov	cl, al 
  7787                                  	;inc	ecx
  7788 00002620 41                      	inc	cx
  7789                                  	;sub	ebx, ecx
  7790 00002621 29CB                    	sub	bx, cx
  7791 00002623 F3A4                    	rep	movsb
  7792 00002625 EB0A                    	jmp	short putlbmc4
  7793                                  putlbmf3:
  7794 00002627 F6D8                    	neg	al
  7795                                  	;movzx	ecx, al
  7796 00002629 88C1                    	mov	cl, al ; ch = 0
  7797                                  	;inc	ecx
  7798                                  	;sub	ebx, ecx
  7799 0000262B 41                      	inc	cx
  7800 0000262C 29CB                    	sub	bx, cx
  7801 0000262E AC                      	lodsb
  7802 0000262F F3AA                    	rep	stosb
  7803                                  putlbmc4:
  7804                                  	;test	ebx, ebx
  7805 00002631 85DB                    	test	bx, bx
  7806 00002633 7FE2                    	jg	short putlbml4
  7807                                  	;pop	edi
  7808                                  	;pop	eax
  7809 00002635 5F                      	pop	di
  7810 00002636 58                      	pop	ax
  7811 00002637 00C0                    	add	al, al
  7812 00002639 73D5                    	jnc	short putlbml3
  7813                                  	;add	edi, 80
  7814 0000263B 83C750                  	add	di, 80
  7815                                  	;pop	ecx
  7816 0000263E 59                      	pop	cx
  7817 0000263F E2CC                    	loop	putlbml2
  7818 00002641 07                      	pop	es
  7819                                  	;popad
  7820 00002642 61                      	popa
  7821 00002643 E969FF                          jmp	putlbmc0
  7822                                  
  7823                                  ;------------------------------------------------------------------------------
  7824                                  ;------------------------------------------------------------------------------
  7825                                  
  7826                                  align 2
  7827                                  
  7828                                  ; 22/10/2017
  7829                                  LOGO_ADDRESS:
  7830                                  ; 27/10/2017
  7831 00002646 <bin 4298h>             incbin "TINYPLAY.LBM"
  7832                                  
  7833                                  ;=============================================================================
  7834                                  ;		preinitialized data
  7835                                  ;=============================================================================
  7836                                  	
  7837 000068DE 00                      		db 0
  7838 000068DF FFFFFFFF                FileHandle:	dd -1
  7839 000068E3 00                      		db 0
  7840                                  
  7841 000068E4 54696E792057415620-     Credits:	db 'Tiny WAV Player for Retro DOS by Erdogan Tan. '
  7841 000068ED 506C6179657220666F-
  7841 000068F6 7220526574726F2044-
  7841 000068FF 4F5320627920457264-
  7841 00006908 6F67616E2054616E2E-
  7841 00006911 20                 
  7842 00006912 466562727561727920-     		db 'February 2025.',10,13,0
  7842 0000691B 323032352E0A0D00   
  7843 00006923 31302F30322F323032-     		db '10/02/2025',10,13
  7843 0000692C 350A0D             
  7844 0000692F 00                      reset:		db 0
  7845                                  
  7846 00006930 0A0D                    msg_usage:	db 10,13
  7847 00006932 75736167653A207477-     		db 'usage: twavplay filename.wav',10,13,0
  7847 0000693B 6176706C6179206669-
  7847 00006944 6C656E616D652E7761-
  7847 0000694D 760A0D00           
  7848                                  
  7849 00006951 0A0D                    noDevMsg:	db 10,13
  7850 00006953 4572726F723A20556E-     		db 'Error: Unable to find a proper audio device !'
  7850 0000695C 61626C6520746F2066-
  7850 00006965 696E6420612070726F-
  7850 0000696E 70657220617564696F-
  7850 00006977 206465766963652021 
  7851 00006980 0A0D00                  		db 10,13,0
  7852                                  
  7853 00006983 0A0D                    noFileErrMsg:	db 10,13
  7854 00006985 4572726F723A206669-     		db 'Error: file not found.',10,13,0
  7854 0000698E 6C65206E6F7420666F-
  7854 00006997 756E642E0A0D00     
  7855                                  
  7856 0000699E 0A0D                    not_valid_wavf:	db 10,13
  7857 000069A0 4E6F7420612070726F-     		db 'Not a proper/valid WAV file !',10,13,0
  7857 000069A9 7065722F76616C6964-
  7857 000069B2 205741562066696C65-
  7857 000069BB 20210A0D00         
  7858                                  
  7859                                  		; 08/02/2025
  7860                                  sb16_init_err_msg:
  7861 000069C0 0A0D                    		db 10,13
  7862 000069C2 536F756E6420426C61-     		db 'Sound Blaster 16 initialization error !',10,13,0
  7862 000069CB 737465722031362069-
  7862 000069D4 6E697469616C697A61-
  7862 000069DD 74696F6E206572726F-
  7862 000069E6 7220210A0D00       
  7863                                  ac97_init_err_msg:
  7864 000069EC 0A0D                    		db 10,13
  7865 000069EE 414339372068617264-     		db 'AC97 hardware initialization error !',10,13,0
  7865 000069F7 7761726520696E6974-
  7865 00006A00 69616C697A6174696F-
  7865 00006A09 6E206572726F722021-
  7865 00006A12 0A0D00             
  7866                                  		
  7867                                  ;init_err_msg:	;db 10,13
  7868                                  		;db 'Audio system initialization error !',10,13,0
  7869                                  
  7870 00006A15 0A0D                    msg_no_vra:	db 10,13
  7871 00006A17 4E6F20565241207375-     		db "No VRA support ! Only 48 kHZ sample rate supported !"
  7871 00006A20 70706F72742021204F-
  7871 00006A29 6E6C79203438206B48-
  7871 00006A32 5A2073616D706C6520-
  7871 00006A3B 726174652073757070-
  7871 00006A44 6F727465642021     
  7872 00006A4B 0A0D00                  		db 10,13,0
  7873                                  
  7874 00006A4E 303132333435363738-     hex_chars:	db "0123456789ABCDEF", 0
  7874 00006A57 3941424344454600   
  7875                                  
  7876 00006A5F 0D0A                    msgAC97Info:	db 0Dh, 0Ah
  7877 00006A61 414339372041756469-     		db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah
  7877 00006A6A 6F20436F6E74726F6C-
  7877 00006A73 6C6572202620436F64-
  7877 00006A7C 656320496E666F0D0A 
  7878 00006A85 56656E646F72204944-     		db "Vendor ID: "
  7878 00006A8E 3A20               
  7879 00006A90 303030306820446576-     msgVendorId:	db "0000h Device ID: "
  7879 00006A99 6963652049443A20   
  7880 00006AA1 30303030680D0A          msgDevId:	db "0000h", 0Dh, 0Ah
  7881 00006AA8 4275733A20              		db "Bus: "
  7882 00006AAD 303068204465766963-     msgBusNo:	db "00h Device: "
  7882 00006AB6 653A20             
  7883 00006AB9 3030682046756E6374-     msgDevNo:	db "00h Function: "
  7883 00006AC2 696F6E3A20         
  7884 00006AC7 303068                  msgFncNo:	db "00h"
  7885 00006ACA 0D0A                    		db 0Dh, 0Ah
  7886                                  
  7887 00006ACC 4E414D4241523A20        		db "NAMBAR: "
  7888 00006AD4 30303030682020          msgNamBar:	db "0000h  "
  7889 00006ADB 4E41424D4241523A20      		db "NABMBAR: "
  7890 00006AE4 303030306820204952-     msgNabmBar:	db "0000h  IRQ: "
  7890 00006AED 513A20             
  7891 00006AF0 3030                    msgIRQ:		dw 3030h
  7892 00006AF2 0D0A00                  		db 0Dh, 0Ah, 0
  7893                                  
  7894 00006AF5 0D0A5741562046696C-     msgWavFileName:	db 0Dh, 0Ah, "WAV File Name: ",0
  7894 00006AFE 65204E616D653A2000 
  7895 00006B07 0D0A53616D706C6520-     msgSampleRate:	db 0Dh, 0Ah, "Sample Rate: "
  7895 00006B10 526174653A20       
  7896 00006B16 303030303020487A2C-     msgHertz:	db "00000 Hz, ", 0 
  7896 00006B1F 2000               
  7897 00006B21 3820626974732C2000      msg8Bits:	db "8 bits, ", 0 
  7898 00006B2A 4D6F6E6F0D0A00          msgMono:	db "Mono", 0Dh, 0Ah, 0
  7899 00006B31 313620626974732C20-     msg16Bits:	db "16 bits, ", 0
  7899 00006B3A 00                 
  7900 00006B3B 53746572656F            msgStereo:	db "Stereo"
  7901 00006B41 0D0A00                  nextline:	db 0Dh, 0Ah, 0
  7902                                  
  7903 00006B44 56524120737570706F-     msgVRAheader:	db "VRA support: "
  7903 00006B4D 72743A20           
  7904 00006B51 00                      		db 0	
  7905 00006B52 5945530D0A00            msgVRAyes:	db "YES", 0Dh, 0Ah, 0
  7906 00006B58 4E4F200D0A              msgVRAno:	db "NO ", 0Dh, 0Ah
  7907 00006B5D 28496E746572706F6C-     		db "(Interpolated sample rate playing method)"
  7907 00006B66 617465642073616D70-
  7907 00006B6F 6C6520726174652070-
  7907 00006B78 6C6179696E67206D65-
  7907 00006B81 74686F6429         
  7908 00006B86 0D0A00                  		db 0Dh, 0Ah, 0
  7909                                  
  7910 00006B89 0D0A                    msgSB16Info:	db 0Dh, 0Ah
  7911 00006B8B 20417564696F204861-     		db " Audio Hardware: Sound Blaster 16", 0Dh, 0Ah
  7911 00006B94 7264776172653A2053-
  7911 00006B9D 6F756E6420426C6173-
  7911 00006BA6 7465722031360D0A   
  7912 00006BAE 202020202020426173-     		db "      Base Port: "
  7912 00006BB7 6520506F72743A20   
  7913                                  msgBasePort:
  7914 00006BBF 303030680D0A            		db "000h", 0Dh, 0Ah
  7915 00006BC5 202020202020202020-     		db "            IRQ: "
  7915 00006BCE 2020204952513A20   
  7916                                  msgSB16IRQ:
  7917 00006BD6 30                      		db 30h
  7918 00006BD7 0D0A00                  		db 0Dh, 0Ah, 0
  7919                                  
  7920                                  ; 07/02/2025
  7921 00006BDA 0D0A                    msgPressAKey:	db 0Dh, 0Ah
  7922 00006BDC 202E2E2E2070726573-     		db ' ... press a key to continue ... '
  7922 00006BE5 732061206B65792074-
  7922 00006BEE 6F20636F6E74696E75-
  7922 00006BF7 65202E2E2E20       
  7923 00006BFD 0D0A00                  		db 0Dh, 0Ah, 0
  7924                                  
  7925                                  ; 07/02/2025
  7926 00006C00 01                      half_buffer:	db 1
  7927                                  
  7928 00006C01 2E2E20565241204F4B-     vra_ok:		db '.. VRA OK ..', 0Dh, 0Ah,0
  7928 00006C0A 202E2E0D0A00       
  7929                                  
  7930                                  ;=============================================================================
  7931                                  ;		uninitialized data
  7932                                  ;=============================================================================
  7933                                  
  7934                                  ; 06/02/2025
  7935                                  
  7936                                  ; BSS
  7937                                  
  7938                                  bss_start:
  7939                                  
  7940                                  ABSOLUTE bss_start
  7941                                  
  7942                                  alignb 4
  7943                                  
  7944                                  ;------------------------------------------------------------------------------
  7945                                  ; IFF/ILBM DATA
  7946                                  ;------------------------------------------------------------------------------
  7947                                  
  7948                                  ; 07/02/2025
  7949 00006C10 ????                    picture.width:	resw 1 	; current picture width and height
  7950 00006C12 ????                    picture.height:	resw 1
  7951                                  
  7952                                  ;------------------------------------------------------------------------------
  7953                                  
  7954                                  ; 07/02/2025 (SB16)
  7955 00006C14 ????                    old_irq5v_o:	resw 1
  7956 00006C16 ????                    old_irq5v_s:	resw 1
  7957 00006C18 ????                    old_irq7v_o:	resw 1
  7958 00006C1A ????                    old_irq7v_s:	resw 1
  7959                                  
  7960                                  ;------------------------------------------------------------------------------
  7961                                  
  7962                                  ;;;;;;;
  7963                                  WAVFILEHEADERbuff:
  7964 00006C1C ????????                RIFF_ChunkID:	resd 1	; Must be equal to "RIFF" - big-endian
  7965                                  			; 0x52494646
  7966 00006C20 ????????                RIFF_ChunkSize: resd 1	; Represents total file size, not
  7967                                          		; including the first 2 fields
  7968                                  			; (Total_File_Size - 8), little-endian
  7969 00006C24 ????????                RIFF_Format:	resd 1	; Must be equal to "WAVE" - big-endian
  7970                                  			; 0x57415645
  7971                                  
  7972                                  ;; WAVE header parameters ("Sub-chunk")
  7973                                  WAVE_SubchunkID:
  7974 00006C28 ????????                		resd 1	; Must be equal to "fmt " - big-endian
  7975                                  			; 0x666d7420
  7976                                  WAVE_SubchunkSize:
  7977 00006C2C ????????                		resd 1	; Represents total chunk size
  7978                                  WAVE_AudioFormat:
  7979 00006C30 ????                    		resw 1	; PCM (Raw) - is 1, other - is a form
  7980                                  			; of compression, not supported.
  7981                                  WAVE_NumChannels:
  7982 00006C32 ????                    		resw 1	; Number of channels, Mono-1, Stereo-2
  7983                                  WAVE_SampleRate:
  7984 00006C34 ????????                		resd 1	; Frequency rate, in Hz (8000, 44100 ...)
  7985 00006C38 ????????                WAVE_ByteRate:	resd 1	; SampleRate * NumChannels * BytesPerSample
  7986                                  WAVE_BlockAlign:
  7987 00006C3C ????                    		resw 1	; NumChannels * BytesPerSample
  7988                                  			; Number of bytes for one sample.
  7989                                  WAVE_BitsPerSample:
  7990 00006C3E ????                    		resw 1	; 8 = 8 bits, 16 = 16 bits, etc.
  7991                                  
  7992                                  ;; DATA header parameters
  7993                                  DATA_SubchunkID:
  7994 00006C40 ????????                		resd 1	; Must be equal to "data" - big-endian
  7995                                          		; 0x64617461
  7996                                  DATA_SubchunkSize:
  7997 00006C44 ????????                		resd 1	; NumSamples * NumChannels * BytesPerSample
  7998                                          		; Number of bytes in the data.
  7999                                  ;;;;;;;
  8000                                  
  8001                                  ;------------------------------------------------------------------------------
  8002                                  
  8003 00006C48 <res 50h>               wav_file_name:	resb 80 ; wave file, path name (<= 80 bytes)
  8004                                  
  8005 00006C98 ????                    		resw 1
  8006                                  
  8007                                  ;------------------------------------------------------------------------------
  8008                                  
  8009                                  ac97_int_ln_reg:
  8010 00006C9A ??                      audio_intr:	resb 1
  8011 00006C9B ??                      VRA:		resb 1	; Variable Rate Audio Support Status
  8012 00006C9C ??                      fbs_shift:	resb 1
  8013 00006C9D ??                      flags:		resb 1
  8014                                  
  8015 00006C9E ????????                dev_vendor:	resd 1
  8016 00006CA2 ????????                bus_dev_fn:	resd 1
  8017                                  audio_io_base:		; Sound Blaster 16 base port address (220h)
  8018 00006CA6 ????                    NAMBAR:		resw 1
  8019 00006CA8 ????                    NABMBAR:	resw 1
  8020                                  
  8021 00006CAA ??                      audio_hardware:	resb 1
  8022 00006CAB ??                      IRQnum:		resb 1
  8023 00006CAC ??                      IRQstatus:	resb 1
  8024 00006CAD ??                      volume:		resb 1
  8025 00006CAE ??                      stopped:	resb 1
  8026                                  
  8027                                  ;------------------------------------------------------------------------------
  8028                                  
  8029 00006CAF ??                      alignb 16
  8030                                  
  8031 00006CB0 <res 200h>              RowOfs:		resw 256
  8032                                  
  8033 00006EB0 <res 200h>              NewScope_L:	resw 256
  8034 000070B0 <res 200h>              NewScope_R:	resw 256
  8035 000072B0 <res 200h>              OldScope_L:	resw 256
  8036 000074B0 <res 200h>              OldScope_R:	resw 256
  8037                                  
  8038                                  ;------------------------------------------------------------------------------
  8039                                  
  8040                                  ; 08/02/2025
  8041                                  ; 256 byte buffer for descriptor list
  8042 000076B0 ????                    BDL_BUFFER:	resw 1	; segment of 256 byte BDL buffer
  8043                                  ; DMA buffers
  8044 000076B2 ????                    WAV_BUFFER_1:	resw 1	; segment of 1st wav/pcm data buffer
  8045 000076B4 ????                    WAV_BUFFER_2:	resw 1	; segment of 2nd wav/pcm data buffer
  8046                                  
  8047                                  ;------------------------------------------------------------------------------
  8048                                  
  8049                                  loadfromwavfile:
  8050 000076B6 ????                    		resw 1	; 'loadfromfile' or load+conversion proc address
  8051 000076B8 ????                    loadsize:	resw 1	; (.wav file) read count (bytes) per one time
  8052 000076BA ????????                buffersize:	resd 1	; 16 bit samples (not bytes)
  8053                                  
  8054 000076BE ????                    count:		resw 1	; byte count of one (wav file) read
  8055                                  LoadedDataBytes:
  8056 000076C0 ????????                		resd 1	; total read/load count
  8057                                  		
  8058 000076C4 ????????                timerticks:	resd 1	; (to eliminate excessive lookup of events in tuneloop)
  8059                                  			; (in order to get the emulator/qemu to run correctly)
  8060                                  bss_end:
  8061                                  
  8062                                  ;------------------------------------------------------------------------------
  8063                                  
  8064                                  ; 07/02/2025
  8065                                  sound_data_copy:	; address pointer for g_buffer fast (conversion) copy
  8066 000076C8 ????                    		resw 1
  8067 000076CA ????                    g_samples:	resw 1	; count of samples for g_buffer copy/transfer
  8068                                  
  8069 000076CC ????????                alignb 16
  8070                                  ; 08/02/2025
  8071                                  ;bdl_buffer:	resb 256
  8072 000076D0 <res 400h>              g_buffer:	resb 1024 ; 16 bit stereo samples for wave graphics display
  8073                                  
  8074                                  ;dma_buffer:
  8075                                  ;temp_buffer:	;resb 50600 ; (44.1kHZ stereo 12650 samples)
  8076                                  ;		; 07/02/2025
  8077                                  ;		resb 33680  ; (44.1kHZ stereo 8418 samples)
  8078                                  
  8079                                  ; 08/02/2025
  8080                                  temp_buffer:	
  8081                                  		; max. 10656 bytes (no-VRA AC97)
  8082                                  		; 10600: 44.1 kHZ stereo 2438 samples, 2650 (48kHZ) samples
  8083                                  		; 10656: 11.025 kHZ stereo 612 samples, 2664 (48kHZ) samples
  8084                                  		; 10508: 22.050 kHZ stereo 1207 samples, 2627 (48kHZ) samples
  8085                                  		; 10544: 24 kHZ stereo 1318 samples, 2636 (48kHZ) samples
  8086                                  		; 10548: 32 kHZ stereo 1758 samples, 2637 (48kHZ) samples
  8087                                  		; 10548: 16 kHZ stereo 879 samples, 2637 (48kHZ) samples
  8088                                  		; 10544: 12 kHZ stereo 659 samples, 2636 (48kHZ) samples
  8089                                  		; 10560: 8 kHZ stereo 440 samples, 2640 (48kHZ) samples
  8090                                  		
  8091                                  dma_buffer:	; max. 21120 bytes (SB16)
  8092 00007AD0 <res 2940h>             		resb 10560
  8093 0000A410 <res 2940h>             		resb 10560
  8094                                  
  8095                                  ;------------------------------------------------------------------------------
  8096                                  
  8097                                  ;wav_buffer1 equ dma_buffer
  8098                                  ;wav_buffer2 equ wav_buffer1 + LOADSIZE ; + 16384
  8099                                  
  8100                                  ;------------------------------------------------------------------------------
