     1                                  ; ****************************************************************************
     2                                  ; twavply2.s (for TRDOS 386)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; TWAVPLY2.PRG ! AC'97 (ICH) WAV PLAYER & VGA DEMO program by Erdogan TAN
     5                                  ;
     6                                  ; 09/12/2023
     7                                  ;
     8                                  ; [ Last Modification: 09/12/2023 ]
     9                                  ;
    10                                  ; Modified from: twavplay.s (VIA VT8237R WAV PLAYER & VGA DEMO) program
    11                                  ;	         by Erdogan Tan (24/08/2020) 
    12                                  ;
    13                                  ; Modified from: 'playwav6.s' (AC'97 WAV player) source code
    14                                  ;		 by Erdogan Tan (27/11/2023)
    15                                  ; 
    16                                  ; Assembler: NASM 2.15
    17                                  ; ----------------------------------------------------------------------------
    18                                  ;	   nasm  twavplay.s -l twavplay.txt -o TWAVPLAY.PRG	
    19                                  ; ****************************************************************************
    20                                  
    21                                  ; 09/12/2023
    22                                  ; Modified from: twavplay.s (VIA VT8237R WAV PLAYER & VGA DEMO) program
    23                                  ;	         by Erdogan Tan (24/08/2020)
    24                                  
    25                                  ; 14/07/2020
    26                                  ; 31/12/2017
    27                                  ; TRDOS 386 (v2.0) system calls
    28                                  _ver 	equ 0
    29                                  _exit 	equ 1
    30                                  _fork 	equ 2
    31                                  _read 	equ 3
    32                                  _write	equ 4
    33                                  _open	equ 5
    34                                  _close 	equ 6
    35                                  _wait 	equ 7
    36                                  _create	equ 8
    37                                  _rename	equ 9
    38                                  _delete	equ 10
    39                                  _exec	equ 11
    40                                  _chdir	equ 12
    41                                  _time 	equ 13
    42                                  _mkdir 	equ 14
    43                                  _chmod	equ 15
    44                                  _rmdir	equ 16
    45                                  _break	equ 17
    46                                  _drive	equ 18
    47                                  _seek	equ 19
    48                                  _tell 	equ 20
    49                                  _memory	equ 21
    50                                  _prompt	equ 22
    51                                  _path	equ 23
    52                                  _env	equ 24
    53                                  _stime	equ 25
    54                                  _quit	equ 26
    55                                  _intr	equ 27
    56                                  _dir	equ 28
    57                                  _emt 	equ 29
    58                                  _ldrvt 	equ 30
    59                                  _video 	equ 31
    60                                  _audio	equ 32
    61                                  _timer	equ 33
    62                                  _sleep	equ 34
    63                                  _msg    equ 35
    64                                  _geterr	equ 36
    65                                  _fpstat	equ 37
    66                                  _pri	equ 38
    67                                  _rele	equ 39
    68                                  _fff	equ 40
    69                                  _fnf	equ 41
    70                                  _alloc	equ 42
    71                                  _dalloc equ 43
    72                                  _calbac equ 44
    73                                  _dma	equ 45		
    74                                  
    75                                  %macro sys 1-4
    76                                      ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
    77                                      ; 03/09/2015	
    78                                      ; 13/04/2015
    79                                      ; Retro UNIX 386 v1 system call.	
    80                                      %if %0 >= 2   
    81                                          mov ebx, %2
    82                                          %if %0 >= 3    
    83                                              mov ecx, %3
    84                                              %if %0 = 4
    85                                                 mov edx, %4   
    86                                              %endif
    87                                          %endif
    88                                      %endif
    89                                      mov eax, %1
    90                                      ;int 30h
    91                                      int 40h ; TRDOS 386 (TRDOS v2.0)	   
    92                                  %endmacro
    93                                  
    94                                  ; TRDOS 386 (and Retro UNIX 386 v1) system call format:
    95                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    96                                  
    97                                  ; 19/06/2017
    98                                  BUFFERSIZE equ 32768
    99                                  ; 23/08/2020
   100                                  ENDOFFILE equ 1	; flag for knowing end of file
   101                                  
   102                                  ; ----------------------------------------------------------------------------
   103                                  ; Tiny MOD Player v0.1b by Carlos Hasan.
   104                                  ;	July 14th, 1993.
   105                                  
   106                                  ;=============================================================================
   107                                  ;  
   108                                  ;=============================================================================
   109                                  
   110                                  [BITS 32]
   111                                  [org 0]
   112                                  
   113                                  Start:
   114                                  	; clear bss
   115 00000000 B9[00000500]            	mov	ecx, EOF
   116 00000005 BF[5D650000]            	mov	edi, bss_start
   117 0000000A 29F9                    	sub	ecx, edi
   118 0000000C D1E9                    	shr	ecx, 1
   119 0000000E 31C0                    	xor	eax, eax
   120 00000010 F366AB                  	rep	stosw
   121                                  
   122                                  	; 09/12/2023
   123                                  	; Detect (& Enable) AC'97 Audio Device
   124 00000013 E8D1040000              	call	DetectAC97
   125 00000018 731B                    	jnc     short GetFileName
   126                                  
   127                                  _dev_not_ready:
   128                                  ; couldn't find the audio device!
   129                                  	sys	_msg, noDevMsg, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000001A BB[85630000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000001F B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000024 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000029 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 0000002E CD40                <1>  int 40h
   130 00000030 E98E040000                      jmp     Exit
   131                                  
   132                                  GetFileName:
   133 00000035 89E6                    	mov	esi, esp
   134 00000037 AD                      	lodsd
   135 00000038 83F802                  	cmp	eax, 2 ; two arguments 
   136                                  		; (program file name & mod file name)
   137                                  	;jb	pmsg_usage ; nothing to do
   138                                  	; 09/12/2023
   139 0000003B 7305                    	jnb	short _x
   140 0000003D E98F040000              	jmp	pmsg_usage
   141                                  
   142                                  _x:
   143 00000042 AD                      	lodsd ; program file name address 
   144 00000043 AD                      	lodsd ; wav file name address (file to be read)
   145 00000044 89C6                    	mov	esi, eax
   146 00000046 BF[94650000]            	mov	edi, wav_file_name
   147                                  ScanName:       
   148 0000004B AC                      	lodsb
   149 0000004C 84C0                    	test	al, al
   150                                  	;jz	pmsg_usage
   151                                  	; 09/12/2023
   152 0000004E 7505                    	jnz	short _y
   153 00000050 E97C040000              	jmp	pmsg_usage
   154                                  _y:
   155 00000055 3C20                    	cmp	al, 20h
   156 00000057 74F2                    	je	short ScanName	; scan start of name.
   157 00000059 AA                      	stosb
   158 0000005A B4FF                    	mov	ah, 0FFh
   159                                  a_0:	
   160 0000005C FEC4                    	inc	ah
   161                                  a_1:
   162 0000005E AC                      	lodsb
   163 0000005F AA                      	stosb
   164 00000060 3C2E                    	cmp	al, '.'
   165 00000062 74F8                    	je	short a_0	
   166 00000064 20C0                    	and	al, al
   167 00000066 75F6                    	jnz	short a_1
   168                                  
   169 00000068 08E4                    	or	ah, ah		 ; if period NOT found,
   170 0000006A 750B                    	jnz	short PrintPMesg ; then add a .MOD extension.
   171                                  SetExt:
   172 0000006C 4F                      	dec	edi
   173 0000006D C7072E574156            	mov	dword [edi], '.WAV'
   174 00000073 C6470400                	mov	byte [edi+4], 0
   175                                  PrintPMesg: 
   176                                  	; 23/08/2020
   177 00000077 C605[4A630000]00        	mov	byte [credits_zero], 0
   178                                       
   179                                  	; Prints the Credits Text.
   180                                  	sys	_msg, Credits, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000007E BB[E4620000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000083 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000088 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000008D B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000092 CD40                <1>  int 40h
   181                                  _1:
   182                                  	; 19/06/2017
   183                                  	; Allocate Audio Buffer (for user)
   184                                  	;sys	_audio, 0200h, BUFFERSIZE, audio_buffer
   185                                  	; 09/12/2023
   186                                  	sys	_audio, 0200h, [buffersize], audio_buffer
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000094 BB00020000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000099 8B0D[E1030000]      <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000009F BA[00800000]        <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000000A4 B820000000          <1>  mov eax, %1
    90                              <1> 
    91 000000A9 CD40                <1>  int 40h
   187 000000AB 7218                    	jc	short error_exit
   188                                  _2:
   189                                  	; 23/08/2020
   190                                  	; Initialize Audio Device (bl = 1 -> Interrupt method)
   191                                  	;sys	_audio, 0301h, 0, audio_int_handler 
   192                                  	;jc	short error_exit
   193                                  	
   194                                  	; 24/08/2020
   195                                  
   196                                  	; 20/10/2017
   197                                  	; Initialize Audio Device (bl = 0 -> SRB method)
   198                                  	sys	_audio, 0300h, 1, srb
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000000AD BB00030000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000000B2 B901000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000000B7 BA[F5650000]        <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000000BC B820000000          <1>  mov eax, %1
    90                              <1> 
    91 000000C1 CD40                <1>  int 40h
   199                                  	;jc	short error_exit
   200                                  	; 09/12/2023
   201 000000C3 731B                    	jnc	short open_wav_file
   202                                  
   203                                  error_exit:
   204                                  	sys	_msg, trdos386_err_msg, 255, 0Eh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000000C5 BB[C9630000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000000CA B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000000CF BA0E000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000000D4 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000000D9 CD40                <1>  int 40h
   205 000000DB E9E3030000              	jmp	Exit
   206                                  
   207                                  	; 09/12/2023
   208                                  open_wav_file:
   209                                  	; 23/08/2020
   210                                  
   211                                  ; open the wav file
   212                                          ; open existing file
   213 000000E0 E826040000                      call    openFile ; no error? ok.
   214 000000E5 731B                            jnc     short _3
   215                                  
   216                                  ; file not found!
   217                                  	sys	_msg, noFileErrMsg, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000000E7 BB[B0630000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000000EC B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000000F1 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000000F6 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000000FB CD40                <1>  int 40h
   218                                  _z:
   219 000000FD E9C1030000                      jmp	Exit
   220                                  
   221                                  _3:
   222 00000102 E83E040000                     	call    getSampleRate	; read the sample rate
   223                                                               	; pass it onto codec.
   224                                  	;jc	Exit
   225                                  	; 09/12/2023
   226 00000107 72F4                    	jc	short _z
   227                                  
   228 00000109 66A3[72650000]          	mov	[sample_rate], ax
   229 0000010F 880D[70650000]          	mov	[stmo], cl
   230 00000115 8815[71650000]          	mov	[bps], dl
   231                                  
   232                                  	; 09/12/2023
   233                                  	; 'playwav6.s (27/11/2023)
   234                                  	
   235                                  	; 26/11/2023
   236 0000011B C605[E7650000]00        	mov	byte [fbs_shift], 0 ; 0 = stereo and 16 bit
   237 00000122 FEC9                    	dec	cl
   238 00000124 7506                    	jnz	short _gsr_1 ; stereo
   239 00000126 FE05[E7650000]          	inc	byte [fbs_shift] ; 1 = mono or 8 bit
   240                                  _gsr_1:	
   241 0000012C 80FA08                  	cmp	dl, 8 
   242 0000012F 7706                    	ja	short _gsr_2 ; 16 bit samples
   243 00000131 FE05[E7650000]          	inc	byte [fbs_shift] ; 2 = mono and 8 bit
   244                                  _gsr_2:
   245                                  
   246                                  	; 10/06/2017
   247                                  	sys	_audio, 0E00h ; get audio controller info
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000137 BB000E0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000013C B820000000          <1>  mov eax, %1
    90                              <1> 
    91 00000141 CD40                <1>  int 40h
   248                                  	;jc	error_exit
   249                                  	; 09/12/2023
   250 00000143 7280                    	jc	short error_exit
   251                                  
   252                                  	; 09/12/2023
   253                                  	;cmp	ah, 2 ; ICH ? (Intel AC'97 Audio Controller)
   254                                  	;jne	_dev_not_ready		
   255                                  
   256                                  	; EAX = IRQ Number in AL
   257                                  	;	Audio Device Number in AH 
   258                                  	; EBX = DEV/VENDOR ID
   259                                  	;       (DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV)
   260                                  	; ECX = BUS/DEV/FN 
   261                                  	;       (00000000BBBBBBBBDDDDDFFF00000000)
   262                                  	; EDX = Base IO Addr (DX) for SB16 & VT8233
   263                                  	; EDX = NABMBAR/NAMBAR (for AC97)
   264                                  	;      (Low word, DX = NAMBAR address)
   265                                  
   266                                  	; 09/12/2023
   267 00000145 A2[E6650000]            	mov	[ac97_int_ln_reg], al
   268 0000014A 891D[E8650000]          	mov	[dev_vendor], ebx
   269 00000150 890D[EC650000]          	mov	[bus_dev_fn], ecx
   270                                  	;mov	[ac97_NamBar], dx
   271                                  	;shr	dx, 16
   272                                  	;mov	[ac97_NabmBar], dx
   273 00000156 8915[F0650000]          	mov	[ac97_NamBar], edx	
   274                                  
   275                                  	; 09/12/2023  
   276 0000015C E806070000              	call	write_ac97_pci_dev_info
   277                                  	; 09/12/2023
   278 00000161 E8C8080000              	call	write_VRA_info
   279                                  
   280                                  	; 24/08/2020
   281 00000166 E831060000              	call	write_wav_file_info
   282                                  
   283                                  ; 09/12/2023
   284                                  ; -----------------------------------
   285                                  ; 'playwav6.s' (27/11/2023)
   286                                  
   287 0000016B 803D[F8650000]01        	cmp	byte [VRA], 1
   288 00000172 7205                    	jb	short chk_sample_rate
   289                                  
   290                                  playwav_48_khz:	
   291                                  	;mov	dword [loadfromwavfile], loadFromFile
   292                                  	;mov	dword [buffersize], 65536
   293 00000174 E96C020000              	jmp	PlayNow
   294                                  
   295                                  chk_sample_rate:
   296                                  	; set conversion parameters
   297                                  	; (for 8, 11.025, 16, 22.050, 24, 32 kHZ)
   298 00000179 66A1[72650000]          	mov	ax, [sample_rate]
   299 0000017F 663D80BB                	cmp	ax, 48000
   300 00000183 74EF                    	je	short playwav_48_khz
   301                                  chk_22khz:
   302 00000185 663D2256                	cmp	ax, 22050
   303 00000189 7545                    	jne	short chk_11khz
   304 0000018B 803D[71650000]08        	cmp	byte [bps], 8
   305 00000192 7615                    	jna	short chk_22khz_1
   306 00000194 BB[B1160000]            	mov	ebx, load_22khz_stereo_16_bit
   307 00000199 803D[70650000]01        	cmp	byte [stmo], 1 
   308 000001A0 751A                    	jne	short chk_22khz_2
   309 000001A2 BB[24160000]            	mov	ebx, load_22khz_mono_16_bit
   310 000001A7 EB13                    	jmp	short chk_22khz_2
   311                                  chk_22khz_1:
   312 000001A9 BB[9D150000]            	mov	ebx, load_22khz_stereo_8_bit
   313 000001AE 803D[70650000]01        	cmp	byte [stmo], 1 
   314 000001B5 7505                    	jne	short chk_22khz_2
   315 000001B7 BB[14150000]            	mov	ebx, load_22khz_mono_8_bit
   316                                  chk_22khz_2:
   317 000001BC B85A1D0000              	mov	eax, 7514  ; (442*17)
   318 000001C1 BA25000000              	mov	edx, 37
   319 000001C6 B911000000              	mov	ecx, 17 
   320 000001CB E9BA010000              	jmp	set_sizes	
   321                                  chk_11khz:
   322 000001D0 663D112B                	cmp	ax, 11025
   323 000001D4 7545                    	jne	short chk_44khz
   324 000001D6 803D[71650000]08        	cmp	byte [bps], 8
   325 000001DD 7615                    	jna	short chk_11khz_1
   326 000001DF BB[CD180000]            	mov	ebx, load_11khz_stereo_16_bit
   327 000001E4 803D[70650000]01        	cmp	byte [stmo], 1 
   328 000001EB 751A                    	jne	short chk_11khz_2
   329 000001ED BB[54180000]            	mov	ebx, load_11khz_mono_16_bit
   330 000001F2 EB13                    	jmp	short chk_11khz_2
   331                                  chk_11khz_1:
   332 000001F4 BB[DA170000]            	mov	ebx, load_11khz_stereo_8_bit
   333 000001F9 803D[70650000]01        	cmp	byte [stmo], 1 
   334 00000200 7505                    	jne	short chk_11khz_2
   335 00000202 BB[62170000]            	mov	ebx, load_11khz_mono_8_bit
   336                                  chk_11khz_2:
   337 00000207 B8AD0E0000              	mov	eax, 3757  ; (221*17)
   338 0000020C BA4A000000              	mov	edx, 74
   339 00000211 B911000000              	mov	ecx, 17
   340 00000216 E96F010000              	jmp	set_sizes 
   341                                  chk_44khz:
   342 0000021B 663D44AC                	cmp	ax, 44100
   343 0000021F 7545                    	jne	short chk_16khz
   344 00000221 803D[71650000]08        	cmp	byte [bps], 8
   345 00000228 7615                    	jna	short chk_44khz_1
   346 0000022A BB[F41A0000]            	mov	ebx, load_44khz_stereo_16_bit
   347 0000022F 803D[70650000]01        	cmp	byte [stmo], 1 
   348 00000236 751A                    	jne	short chk_44khz_2
   349 00000238 BB[7B1A0000]            	mov	ebx, load_44khz_mono_16_bit
   350 0000023D EB13                    	jmp	short chk_44khz_2
   351                                  chk_44khz_1:
   352 0000023F BB[FE190000]            	mov	ebx, load_44khz_stereo_8_bit
   353 00000244 803D[70650000]01        	cmp	byte [stmo], 1 
   354 0000024B 7505                    	jne	short chk_44khz_2
   355 0000024D BB[82190000]            	mov	ebx, load_44khz_mono_8_bit
   356                                  chk_44khz_2:
   357 00000252 B8D93A0000              	mov	eax, 15065 ; (655*23)
   358 00000257 BA19000000              	mov	edx, 25
   359 0000025C B917000000              	mov	ecx, 23
   360 00000261 E924010000              	jmp	set_sizes 
   361                                  chk_16khz:
   362 00000266 663D803E                	cmp	ax, 16000
   363 0000026A 7545                    	jne	short chk_8khz
   364 0000026C 803D[71650000]08        	cmp	byte [bps], 8
   365 00000273 7615                    	jna	short chk_16khz_1
   366 00000275 BB[59100000]            	mov	ebx, load_16khz_stereo_16_bit
   367 0000027A 803D[70650000]01        	cmp	byte [stmo], 1 
   368 00000281 751A                    	jne	short chk_16khz_2
   369 00000283 BB[D80F0000]            	mov	ebx, load_16khz_mono_16_bit
   370 00000288 EB13                    	jmp	short chk_16khz_2
   371                                  chk_16khz_1:
   372 0000028A BB[1E0F0000]            	mov	ebx, load_16khz_stereo_8_bit
   373 0000028F 803D[70650000]01        	cmp	byte [stmo], 1 
   374 00000296 7505                    	jne	short chk_16khz_2
   375 00000298 BB[9F0E0000]            	mov	ebx, load_16khz_mono_8_bit
   376                                  chk_16khz_2:
   377 0000029D B855150000              	mov	eax, 5461
   378 000002A2 BA03000000              	mov	edx, 3
   379 000002A7 B901000000              	mov	ecx, 1
   380 000002AC E9D9000000              	jmp	set_sizes 
   381                                  chk_8khz:
   382 000002B1 663D401F                	cmp	ax, 8000
   383 000002B5 7545                    	jne	short chk_24khz
   384 000002B7 803D[71650000]08        	cmp	byte [bps], 8
   385 000002BE 7615                    	jna	short chk_8khz_1
   386 000002C0 BB[540D0000]            	mov	ebx, load_8khz_stereo_16_bit
   387 000002C5 803D[70650000]01        	cmp	byte [stmo], 1 
   388 000002CC 751A                    	jne	short chk_8khz_2
   389 000002CE BB[840C0000]            	mov	ebx, load_8khz_mono_16_bit
   390 000002D3 EB13                    	jmp	short chk_8khz_2
   391                                  chk_8khz_1:
   392 000002D5 BB[540B0000]            	mov	ebx, load_8khz_stereo_8_bit
   393 000002DA 803D[70650000]01        	cmp	byte [stmo], 1 
   394 000002E1 7505                    	jne	short chk_8khz_2
   395 000002E3 BB[7B0A0000]            	mov	ebx, load_8khz_mono_8_bit
   396                                  chk_8khz_2:
   397 000002E8 B8AA0A0000              	mov	eax, 2730
   398 000002ED BA06000000              	mov	edx, 6
   399 000002F2 B901000000              	mov	ecx, 1
   400 000002F7 E98E000000              	jmp	set_sizes 
   401                                  chk_24khz:
   402 000002FC 663DC05D                	cmp	ax, 24000
   403 00000300 7542                    	jne	short chk_32khz
   404 00000302 803D[71650000]08        	cmp	byte [bps], 8
   405 00000309 7615                    	jna	short chk_24khz_1
   406 0000030B BB[83120000]            	mov	ebx, load_24khz_stereo_16_bit
   407 00000310 803D[70650000]01        	cmp	byte [stmo], 1 
   408 00000317 751A                    	jne	short chk_24khz_2
   409 00000319 BB[20120000]            	mov	ebx, load_24khz_mono_16_bit
   410 0000031E EB13                    	jmp	short chk_24khz_2
   411                                  chk_24khz_1:
   412 00000320 BB[96110000]            	mov	ebx, load_24khz_stereo_8_bit
   413 00000325 803D[70650000]01        	cmp	byte [stmo], 1 
   414 0000032C 7505                    	jne	short chk_24khz_2
   415 0000032E BB[2F110000]            	mov	ebx, load_24khz_mono_8_bit
   416                                  chk_24khz_2:
   417 00000333 B800200000              	mov	eax, 8192
   418 00000338 BA02000000              	mov	edx, 2
   419 0000033D B901000000              	mov	ecx, 1
   420 00000342 EB46                    	jmp	short set_sizes 
   421                                  chk_32khz:
   422 00000344 663D007D                	cmp	ax, 32000
   423 00000348 7574                    	jne	short vra_needed
   424 0000034A 803D[71650000]08        	cmp	byte [bps], 8
   425 00000351 7615                    	jna	short chk_32khz_1
   426 00000353 BB[84140000]            	mov	ebx, load_32khz_stereo_16_bit
   427 00000358 803D[70650000]01        	cmp	byte [stmo], 1 
   428 0000035F 751A                    	jne	short chk_32khz_2
   429 00000361 BB[1A140000]            	mov	ebx, load_32khz_mono_16_bit
   430 00000366 EB13                    	jmp	short chk_32khz_2
   431                                  chk_32khz_1:
   432 00000368 BB[7D130000]            	mov	ebx, load_32khz_stereo_8_bit
   433 0000036D 803D[70650000]01        	cmp	byte [stmo], 1 
   434 00000374 7505                    	jne	short chk_32khz_2
   435 00000376 BB[0A130000]            	mov	ebx, load_32khz_mono_8_bit
   436                                  chk_32khz_2:
   437 0000037B B8AA2A0000              	mov	eax, 10922
   438 00000380 BA03000000              	mov	edx, 3
   439 00000385 B902000000              	mov	ecx, 2
   440                                  	;jmp	short set_sizes 
   441                                  set_sizes:
   442 0000038A 803D[70650000]01        	cmp	byte [stmo], 1
   443 00000391 7402                    	je	short ss_1
   444 00000393 D1E0                    	shl	eax, 1
   445                                  ss_1:
   446 00000395 803D[71650000]08        	cmp	byte [bps], 8
   447 0000039C 7602                    	jna	short ss_2
   448                                  	; 16 bit samples
   449 0000039E D1E0                    	shl	eax, 1
   450                                  ss_2:
   451 000003A0 A3[DD030000]            	mov	[loadsize], eax
   452 000003A5 F7E2                    	mul	edx
   453                                  	;cmp	ecx, 1
   454                                  	;je	short ss_3
   455                                  ;ss_3:
   456 000003A7 F7F1                    	div	ecx
   457 000003A9 8A0D[E7650000]          	mov	cl, [fbs_shift]
   458 000003AF D3E0                    	shl	eax, cl
   459                                  	; 26/11/2023
   460                                  	;shr	eax, 1	; buffer size is 16 bit sample count
   461 000003B1 A3[E1030000]            	mov	[buffersize], eax ; buffer size in bytes 
   462 000003B6 891D[D9030000]          	mov	[loadfromwavfile], ebx
   463 000003BC EB27                    	jmp	short PlayNow
   464                                  
   465                                  vra_needed:
   466                                  	sys	_msg, msg_no_vra, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000003BE BB[E9630000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000003C3 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000003C8 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000003CD B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000003D2 CD40                <1>  int 40h
   467 000003D4 E9EA000000              	jmp	Exit
   468                                  
   469                                  	; 26/11/2023
   470                                  	; 13/11/2023
   471                                  loadfromwavfile:
   472 000003D9 [A3050000]              	dd	loadFromFile
   473                                  loadsize:	; read from wav file
   474 000003DD 00000000                	dd	0
   475                                  buffersize:	; write to DMA buffer
   476 000003E1 00000100                	dd	65536 ; bytes
   477                                  
   478                                  ; -----------------------------------
   479                                  
   480                                  	; 23/08/2020
   481                                  PlayNow: 
   482                                  	; 27/10/2017
   483 000003E5 66B90001                	mov	cx, 256
   484 000003E9 31DB                    	xor	ebx, ebx
   485 000003EB BF[00660000]            	mov	edi, RowOfs
   486                                  MakeOfs:
   487                                  	; 29/10/2017
   488                                  	;mov	ax, 128
   489                                  	;mul	bx
   490                                  	;mov	al, ah
   491                                  	;mov	ah, 80
   492                                  	;mul	ah
   493 000003F0 89D8                    	mov	eax, ebx
   494 000003F2 66C1E007                	shl	ax, 7 ; * 128
   495 000003F6 B050                    	mov	al, 80
   496 000003F8 F6E4                    	mul	ah
   497 000003FA 66AB                    	stosw
   498 000003FC 43                      	inc	ebx
   499 000003FD E2F1                    	loop	MakeOfs
   500                                  
   501                                  	; 23/08/2020
   502                                  
   503                                  	; DIRECT VGA MEMORY ACCESS
   504                                  	; bl = 0, bh = 5
   505                                  	; Direct access/map to VGA memory (0A0000h)
   506                                  
   507                                  	sys	_video, 0500h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000003FF BB00050000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000404 B81F000000          <1>  mov eax, %1
    90                              <1> 
    91 00000409 CD40                <1>  int 40h
   508 0000040B 3D00000A00              	cmp	eax, 0A0000h
   509 00000410 7405                    	je	short _4
   510                                  	; 09/12/2023
   511 00000412 E9AEFCFFFF              	jmp	error_exit
   512                                  
   513                                  
   514                                  ; Note: Normally IRQ 0 calls the ModPlay Polling at 18.2Hz thru
   515                                  ;       the software interrupt 1Ch. If the IRQ 0 is disabled, then
   516                                  ;       the INT 1Ch MUST BE CALLED at least MixSpeed/1024 times per
   517                                  ;       second, or the module will sound "looped".
   518                                  ;       Because we need better sync with the ModPlayer to draw the scope,
   519                                  ;       the polling is called from my routine, and then the irq 0 must be
   520                                  ;       disabled. The [DmaBuffer] points to the current buffer of 8-bit
   521                                  ;       samples played by the Sound Blaster. Note that some samples are
   522                                  ;       discarded in the next code, just for fun!
   523                                  
   524                                  _4:
   525                                  	;mov     ax, 0013h	; Set Mode 320x200x256
   526                                  	;int     31h
   527                                  
   528                                  	; 21/10/2017
   529                                  	;mov	ax, 0012h	; Set Mode 640x480x16
   530                                  	;int	31h
   531                                  
   532                                  	; 22/10/2017
   533 00000417 E8A61C0000              	call	setgraphmode	; Set video mode to 640*480x16
   534                                  
   535                                  	; 22/10/2017
   536                                  	;call	loadlbm
   537                                  	;jc	short loadlbm_err
   538                                  
   539 0000041C BE[EE220000]            	mov	esi, LOGO_ADDRESS
   540 00000421 E88E1D0000              	call	putlbm
   541                                  	;jnc	short loadlbm_ok
   542 00000426 731D                    	jnc	short _5 ; 
   543                                  
   544                                  	;mov	byte [error_color], 0Eh ; Yellow
   545                                  
   546                                  loadlbm_err:
   547                                  	; 21/10/2017
   548                                  	;mov	ax, 0003h	; Set Text Mode 80x25x16
   549                                  	;int	31h
   550                                  	; 22/10/2017
   551 00000428 E8B21C0000              	call	settextmode
   552                                  
   553                                  	sys	_msg, LOGO_ERROR_MSG, 255, 0Ch
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000042D BB[C2220000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000432 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000437 BA0C000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000043C B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000441 CD40                <1>  int 40h
   554 00000443 EB7E                    	jmp	short Exit
   555                                  
   556                                  loadlbm_ok: 
   557                                  	; 21/10/2017
   558                                  _5:
   559                                  	; 09/10/2017 (2*BUFFERSIZE, 64K)
   560                                  	; 23/06/2017
   561                                  	; Map DMA buffer to user's memory space
   562                                  	;sys	_audio, 0D00h, 2*BUFFERSIZE, DMA_Buffer
   563                                  	; 09/12/2023
   564 00000445 A1[E1030000]            	mov	eax, [buffersize]
   565 0000044A D1E0                    	shl	eax, 1 ; *2
   566                                  	; round up to page boundary (may not be necessary)
   567 0000044C 05FF0F0000              	add	eax, 4095
   568 00000451 2500F0FFFF              	and	eax, ~4095
   569 00000456 A3[00700000]            	mov	[DMA_buffer_size], eax
   570                                  	;sys	_audio, 0D00h, 131072, DMA_Buffer
   571                                  	sys	_audio, 0D00h, [DMA_buffer_size], DMA_Buffer
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000045B BB000D0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000460 8B0D[00700000]      <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000466 BA[00000200]        <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000046B B820000000          <1>  mov eax, %1
    90                              <1> 
    91 00000470 CD40                <1>  int 40h
   572                                  	;jc	error_exit
   573                                  
   574                                  	; 23/08/2020
   575                                  
   576                                  ; position file pointer to start in actual wav data
   577                                  ; MUCH improvement should really be done here to check if sample size is
   578                                  ; supported, make sure there are 2 channels, etc.  
   579                                  ;
   580                                          ;mov     ah, 42h
   581                                          ;mov     al, 0	; from start of file
   582                                          ;mov     bx, [FileHandle]
   583                                          ;xor     cx, cx
   584                                          ;mov     dx, 44	; jump past .wav/riff header
   585                                          ;int     21h
   586                                  
   587                                  	sys	_seek, [FileHandle], 44, 0
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000472 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000478 B92C000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000047D BA00000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000482 B813000000          <1>  mov eax, %1
    90                              <1> 
    91 00000487 CD40                <1>  int 40h
   588                                  
   589                                  ; play the .wav file. Most of the good stuff is in here.
   590                                  
   591 00000489 E8CA010000                      call    PlayWav
   592                                  
   593                                  ; close the .wav file and exit.
   594                                  
   595                                  StopPlaying:
   596                                  	; Stop Playing
   597                                  	sys	_audio, 0700h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000048E BB00070000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000493 B820000000          <1>  mov eax, %1
    90                              <1> 
    91 00000498 CD40                <1>  int 40h
   598                                  	; Cancel callback service (for user)
   599                                  	sys	_audio, 0900h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000049A BB00090000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000049F B820000000          <1>  mov eax, %1
    90                              <1> 
    91 000004A4 CD40                <1>  int 40h
   600                                  	; Deallocate Audio Buffer (for user)
   601                                  	sys	_audio, 0A00h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000004A6 BB000A0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000004AB B820000000          <1>  mov eax, %1
    90                              <1> 
    91 000004B0 CD40                <1>  int 40h
   602                                  	; Disable Audio Device
   603                                  	sys	_audio, 0C00h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000004B2 BB000C0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000004B7 B820000000          <1>  mov eax, %1
    90                              <1> 
    91 000004BC CD40                <1>  int 40h
   604                                  
   605                                  	; 23/08/2020
   606 000004BE E81C1C0000              	call	settextmode
   607                                  Exit:  
   608 000004C3 E85C000000                      call    closeFile
   609                                           
   610                                  	sys	_exit	; Bye!
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81                              <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000004C8 B801000000          <1>  mov eax, %1
    90                              <1> 
    91 000004CD CD40                <1>  int 40h
   611                                  here:
   612 000004CF EBFE                    	jmp	short here
   613                                  
   614                                  pmsg_usage:
   615                                  	sys	_msg, msg_usage, 255, 0Bh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000004D1 BB[E4620000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000004D6 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000004DB BA0B000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000004E0 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000004E5 CD40                <1>  int 40h
   616 000004E7 EBDA                    	jmp	short Exit
   617                                  
   618                                  DetectAC97:
   619                                  	; 09/12/2023
   620                                  	; Detect (BH=1) AC'97 (BL=2) Audio Device
   621                                          sys	_audio, 0102h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000004E9 BB02010000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000004EE B820000000          <1>  mov eax, %1
    90                              <1> 
    91 000004F3 CD40                <1>  int 40h
   622 000004F5 7213                    	jc	short DetectAC97_retn
   623                                  
   624                                  	; Get AC'97 Codec info
   625                                  	; (Function 14, sub function 1)
   626                                  	sys	_audio, 0E01h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000004F7 BB010E0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000004FC B820000000          <1>  mov eax, %1
    90                              <1> 
    91 00000501 CD40                <1>  int 40h
   627                                  	; Save Variable Rate Audio support bit
   628 00000503 2401                    	and	al, 1
   629 00000505 A2[F8650000]            	mov	[VRA], al
   630                                  
   631                                  DetectAC97_retn:
   632 0000050A C3                      	retn
   633                                  	
   634                                  	; 23/08/2020
   635                                  
   636                                  ;open or create file
   637                                  ;
   638                                  ;input: ds:dx-->filename (asciiz)
   639                                  ;       al=file Mode (create or open)
   640                                  ;output: none  cs:[FileHandle] filled
   641                                  ;
   642                                  openFile:
   643                                  	;mov	ah, 3Bh	; start with a mode
   644                                  	;add	ah, al	; add in create or open mode
   645                                  	;xor	cx, cx
   646                                  	;int	21h
   647                                  	;jc	short _of1
   648                                  	;;mov	[cs:FileHandle], ax
   649                                  
   650                                  	sys	_open, wav_file_name, 0
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000050B BB[94650000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000510 B900000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000515 B805000000          <1>  mov eax, %1
    90                              <1> 
    91 0000051A CD40                <1>  int 40h
   651 0000051C 7205                    	jc	short _of1
   652                                  
   653 0000051E A3[DF620000]            	mov	[FileHandle], eax
   654                                  _of1:
   655 00000523 C3                      	retn
   656                                  
   657                                  ; close the currently open file
   658                                  ; input: none, uses cs:[FileHandle]
   659                                  closeFile:
   660 00000524 833D[DF620000]FF        	cmp	dword [FileHandle], -1
   661 0000052B 7417                    	je	short _cf1
   662                                  	;mov    bx, [FileHandle]  
   663                                  	;mov    ax, 3E00h
   664                                          ;int    21h              ;close file
   665                                  
   666                                  	sys	_close, [FileHandle]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000052D 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000533 B806000000          <1>  mov eax, %1
    90                              <1> 
    91 00000538 CD40                <1>  int 40h
   667 0000053A C705[DF620000]FFFF-     	mov 	dword [FileHandle], -1
   667 00000542 FFFF               
   668                                  _cf1:
   669 00000544 C3                      	retn
   670                                  
   671                                  getSampleRate:
   672                                  	
   673                                  ; reads the sample rate from the .wav file.
   674                                  ; entry: none - assumes file is already open
   675                                  ; exit: ax = sample rate (11025, 22050, 44100, 48000)
   676                                  ;	cx = number of channels (mono=1, stereo=2)
   677                                  ;	dx = bits per sample (8, 16)
   678                                  
   679 00000545 53                      	push    ebx
   680                                  
   681                                          ;mov	ah, 42h
   682                                          ;mov	al, 0	; from start of file
   683                                          ;mov	bx, [FileHandle]
   684                                          ;xor	cx, cx
   685                                          ;mov	dx, 08h	; "WAVE"
   686                                          ;int	21h
   687                                  	
   688                                  	sys	_seek, [FileHandle], 8, 0
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000546 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000054C B908000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000551 BA00000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000556 B813000000          <1>  mov eax, %1
    90                              <1> 
    91 0000055B CD40                <1>  int 40h
   689                                  
   690                                          ;mov	dx, smpRBuff
   691                                          ;mov	cx, 28	; 28 bytes
   692                                  	;mov	ah, 3fh
   693                                          ;int	21h
   694                                  
   695                                  	sys	_read, [FileHandle], smpRBuff, 28
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000055D 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000563 B9[78650000]        <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000568 BA1C000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000056D B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000572 CD40                <1>  int 40h
   696                                  
   697 00000574 813D[78650000]5741-     	cmp	dword [smpRBuff], 'WAVE'
   697 0000057C 5645               
   698 0000057E 7520                    	jne	short gsr_stc
   699                                  
   700 00000580 66833D[84650000]01      	cmp	word [smpRBuff+12], 1	; Offset 20, must be 1 (= PCM)
   701 00000588 7516                    	jne	short gsr_stc
   702                                  
   703 0000058A 668B0D[86650000]        	mov	cx, [smpRBuff+14]	; return num of channels in CX
   704 00000591 66A1[88650000]                  mov     ax, [smpRBuff+16]	; return sample rate in AX
   705 00000597 668B15[92650000]        	mov	dx, [smpRBuff+26]	; return bits per sample value in DX
   706                                  gsr_retn:
   707 0000059E 5B                              pop     ebx
   708 0000059F C3                              retn
   709                                  gsr_stc:
   710 000005A0 F9                      	stc
   711 000005A1 EBFB                    	jmp	short gsr_retn
   712                                  
   713                                  ;=============================================================================
   714                                  
   715                                  ; 09/12/2023	
   716                                  %if 0
   717                                  	; 'playwav6.s'  (27/11/2023)
   718                                  
   719                                  audio_int_handler:
   720                                  	; 18/08/2020 (14/10/2020, 'wavplay2.s')
   721                                  
   722                                  	;mov	byte [srb], 1 ; interrupt (or signal response byte)
   723                                  	
   724                                  	;cmp	byte [cbs_busy], 1
   725                                  	;jnb	short _callback_bsy_retn
   726                                  	
   727                                  	;mov	byte [cbs_busy], 1
   728                                  
   729                                  	mov	al, [half_buff]
   730                                  
   731                                  	cmp	al, 1
   732                                  	jb	short _callback_retn
   733                                  
   734                                  	; 18/08/2020
   735                                  	mov	byte [srb], 1
   736                                  
   737                                  	xor	byte [half_buff], 3 ; 2->1, 1->2
   738                                  
   739                                  	add	al, '0'
   740                                  tL0:	; 26/11/2023
   741                                  	mov	ah, 4Eh
   742                                  	mov	ebx, 0B8000h ; video display page address
   743                                  	mov	[ebx], ax ; show playing buffer (1, 2)
   744                                  _callback_retn:
   745                                  	;mov	byte [cbs_busy], 0
   746                                  _callback_bsy_retn:
   747                                  	sys	_rele ; return from callback service 
   748                                  	; we must not come here !
   749                                  	sys	_exit
   750                                  
   751                                  %endif
   752                                  
   753                                  ;=============================================================================
   754                                  
   755                                  ; 09/12/2023
   756                                  ; 'playwav6.s' (27/11/2023)
   757                                  
   758                                  loadFromFile:
   759                                  	; 26/11/2023
   760 000005A3 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
   761                                  					; last of the file?
   762 000005AA 7402                    	jz	short lff_0		; no
   763 000005AC F9                      	stc
   764 000005AD C3                      	retn
   765                                  lff_0:
   766                                  	; 13/06/2017
   767                                  	;mov	edx, BUFFERSIZE
   768                                  	; 26/11/2023
   769 000005AE BF[00800000]            	mov	edi, audio_buffer
   770 000005B3 8B15[E1030000]          	mov	edx, [buffersize]	; bytes
   771 000005B9 8A0D[E7650000]          	mov	cl, [fbs_shift]
   772 000005BF 20C9                    	and	cl, cl
   773 000005C1 7409                    	jz	short lff_1 ; stereo, 16 bit
   774                                  
   775                                  	; fbs_shift =
   776                                  	;	2 for mono and 8 bit sample (multiplier = 4)
   777                                  	;	1 for mono or 8 bit sample (multiplier = 2)
   778 000005C3 D3EA                    	shr	edx, cl
   779                                  	;inc	edx
   780                                  
   781 000005C5 BE[00000400]            	mov     esi, temp_buffer
   782 000005CA EB02                    	jmp	short lff_2
   783                                  lff_1:
   784                                  	;mov	esi, audio_buffer
   785 000005CC 89FE                    	mov	esi, edi ; audio_buffer
   786                                  lff_2:
   787                                  	; 17/03/2017
   788                                  	; esi = buffer address
   789                                  	; edx = buffer size
   790                                   
   791                                  	; 26/11/2023
   792                                  	; load file into memory
   793                                  	sys 	_read, [FileHandle], esi
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000005CE 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000005D4 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000005D6 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000005DB CD40                <1>  int 40h
   794 000005DD 89D1                    	mov	ecx, edx
   795 000005DF 724A                    	jc	short padfill ; error !
   796                                  
   797 000005E1 21C0                    	and	eax, eax
   798 000005E3 7446                    	jz	short padfill
   799                                  lff_3:
   800                                  	; 26/11/2023
   801 000005E5 8A1D[E7650000]          	mov	bl, [fbs_shift]
   802 000005EB 20DB                    	and	bl, bl
   803 000005ED 745C                    	jz	short lff_11
   804                                  
   805 000005EF 29C1                    	sub	ecx, eax
   806 000005F1 89CD                    	mov	ebp, ecx
   807                                  
   808                                  	;mov	esi, temp_buffer
   809                                  	;mov	edi, audio_buffer
   810 000005F3 89C1                    	mov	ecx, eax   ; byte count
   811                                  
   812 000005F5 803D[71650000]08        	cmp	byte [bps], 8 ; bits per sample (8 or 16)
   813 000005FC 751E                    	jne	short lff_6 ; 16 bit samples
   814                                  	; 8 bit samples
   815 000005FE FECB                    	dec	bl  ; shift count, 1 = stereo, 2 = mono
   816 00000600 740E                    	jz	short lff_5 ; 8 bit, stereo
   817                                  lff_4:
   818                                  	; mono & 8 bit
   819 00000602 AC                      	lodsb
   820 00000603 2C80                    	sub	al, 80h ; 08/11/2023
   821 00000605 C1E008                  	shl	eax, 8 ; convert 8 bit sample to 16 bit sample
   822 00000608 66AB                    	stosw	; left channel
   823 0000060A 66AB                    	stosw	; right channel
   824 0000060C E2F4                    	loop	lff_4
   825 0000060E EB16                    	jmp	short lff_8
   826                                  lff_5:
   827                                  	; stereo & 8 bit
   828 00000610 AC                      	lodsb
   829 00000611 2C80                    	sub	al, 80h ; 08/11/2023
   830 00000613 C1E008                  	shl	eax, 8 ; convert 8 bit sample to 16 bit sample
   831 00000616 66AB                    	stosw
   832 00000618 E2F6                    	loop	lff_5
   833 0000061A EB0A                    	jmp	short lff_8
   834                                  lff_6:
   835 0000061C D1E9                    	shr	ecx, 1 ; word count
   836                                  lff_7:
   837 0000061E 66AD                    	lodsw
   838 00000620 66AB                    	stosw	; left channel
   839 00000622 66AB                    	stosw	; right channel
   840 00000624 E2F8                    	loop	lff_7
   841                                  lff_8:
   842                                  	; 27/11/2023
   843 00000626 F8                      	clc
   844 00000627 89E9                    	mov	ecx, ebp
   845 00000629 E314                    	jecxz	endLFF_retn
   846                                  	
   847                                  padfill:
   848 0000062B 803D[71650000]10        	cmp 	byte [bps], 16
   849 00000632 740C                    	je	short lff_10
   850                                  	; Minimum Value = 0
   851 00000634 30C0                            xor     al, al
   852 00000636 F3AA                    	rep	stosb
   853                                  lff_9:
   854 00000638 800D[F4650000]01                or	byte [flags], ENDOFFILE	; end of file flag
   855                                  endLFF_retn:
   856 0000063F C3                              retn
   857                                  lff_10:
   858 00000640 31C0                    	xor	eax, eax
   859                                  	; Minimum value = 8000h (-32768)
   860 00000642 D1E9                    	shr	ecx, 1 
   861 00000644 B480                    	mov	ah, 80h ; ax = -32768
   862 00000646 F366AB                  	rep	stosw
   863 00000649 EBED                    	jmp	short lff_9
   864                                  
   865                                  lff_11:
   866                                  	; 16 bit stereo
   867                                  	; ecx = buffer size
   868                                  	; eax = read count
   869 0000064B 29C1                    	sub	ecx, eax
   870 0000064D 76F0                    	jna	short endLFF_retn
   871 0000064F 01C7                    	add	edi, eax  ; audio_buffer + eax
   872 00000651 EBED                    	jmp	short lff_10 ; padfill
   873                                  
   874                                  error_exit_2:
   875                                  	; 26/11/2023 - temporary
   876                                  	;sys	_msg, test_2, 255, 0Ch
   877 00000653 E96DFAFFFF              	jmp	error_exit
   878                                  
   879                                  ;=============================================================================
   880                                  ;      
   881                                  ;=============================================================================
   882                                  
   883                                  PlayWav:
   884                                  	; 09/12/2023
   885                                  	;; 23/08/2020
   886                                  	;; load 32768 bytes into audio buffer
   887                                  	;;mov	edi, audio_buffer
   888                                  	;;mov	edx, BUFFERSIZE
   889                                  	;call	loadFromFile
   890                                  	; 09/12/2023
   891 00000658 FF15[D9030000]          	call	dword [loadfromwavfile]
   892 0000065E 72F3                    	jc	short error_exit_2
   893                                  
   894                                  	;mov	byte [half_buff], 1 ; (DMA) Buffer 1
   895                                  
   896                                  	; 18/08/2020 (27/07/2020, 'wavplay2.s')
   897 00000660 F605[F4650000]01        	test    byte [flags], ENDOFFILE  ; end of file
   898 00000667 7512                    	jnz	short _6 ; yes
   899                                  			 ; bypass filling dma half buffer 2
   900                                  
   901                                  	; bh = 16 : update (current, first) dma half buffer
   902                                  	; bl = 0  : then switch to the next (second) half buffer
   903                                  	sys	_audio, 1000h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000669 BB00100000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000066E B820000000          <1>  mov eax, %1
    90                              <1> 
    91 00000673 CD40                <1>  int 40h
   904                                  
   905                                  	; 27/07/2020
   906                                  	; [audio_flag] = 1  (in TRDOS 386 kernel)
   907                                  
   908                                  	; audio_buffer must be filled again after above system call 
   909                                  	; (Because audio interrupt will be generated by VT8237R
   910                                  	; at the end of the first half of dma buffer.. so, 
   911                                  	; the second half must be ready. 'sound_play' will use it.)
   912                                  
   913                                  	; 09/12/2023
   914                                  	;; 13/10/2017
   915                                  	;;mov	edi, audio_buffer
   916                                  	;;mov	edx, BUFFERSIZE
   917                                  	;call    loadFromFile
   918                                  	; 09/12/2023
   919 00000675 FF15[D9030000]          	call	dword [loadfromwavfile]
   920                                  	;jc	short p_return
   921                                  
   922                                  _6:
   923                                  	; Set Master Volume Level
   924                                  	sys	_audio, 0B00h, 1D1Dh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000067B BB000B0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000680 B91D1D0000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000685 B820000000          <1>  mov eax, %1
    90                              <1> 
    91 0000068A CD40                <1>  int 40h
   925                                  	; 24/06/2017
   926                                  	;mov	byte [volume_level], 1Dh
   927 0000068C 880D[F7650000]          	mov	[volume_level], cl	
   928                                  
   929                                  	;mov	byte [srb], 0
   930                                  
   931                                  	; Start	to play
   932 00000692 A0[71650000]            	mov	al, [bps]
   933 00000697 C0E804                  	shr	al, 4 ; 8 -> 0, 16 -> 1
   934 0000069A D0E0                    	shl	al, 1 ; 16 -> 2, 8 -> 0
   935 0000069C 8A1D[70650000]          	mov	bl, [stmo]
   936 000006A2 FECB                    	dec	bl
   937 000006A4 08C3                    	or	bl, al
   938 000006A6 668B0D[72650000]        	mov	cx, [sample_rate] 
   939 000006AD B704                    	mov	bh, 4 ; start to play	
   940                                  	sys	_audio
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81                              <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000006AF B820000000          <1>  mov eax, %1
    90                              <1> 
    91 000006B4 CD40                <1>  int 40h
   941                                  
   942                                  	; 27/07/2020
   943                                  	; Here..
   944                                  	; If byte [flags] <> ENDOFFILE ...
   945                                  	; user's audio_buffer has been copied to dma half buffer 2
   946                                  
   947                                  	; [audio_flag] = 0  (in TRDOS 386 kernel)
   948                                  
   949                                  	; audio_buffer must be filled again after above system call 
   950                                  	; (Because, audio interrupt will be generated by VT8237R
   951                                  	; at the end of the first half of dma buffer.. so, 
   952                                  	; the 2nd half of dma buffer is ready but the 1st half
   953                                  	; must be filled again.)
   954                                  
   955                                  	; 27/07/2020
   956 000006B6 F605[F4650000]01        	test    byte [flags], ENDOFFILE  ; end of file
   957 000006BD 750C                    	jnz	short p_loop ; yes
   958                                  
   959                                  	; 13/10/2017
   960                                  	;mov	edi, audio_buffer
   961                                  	;mov	edx, BUFFERSIZE
   962                                  	; 09/12/2023
   963                                  	;mov	edx, [buffersize]
   964                                  	;call	loadFromFile
   965 000006BF FF15[D9030000]          	call	dword [loadfromwavfile]
   966                                  	;jc	short p_return
   967                                  	;mov	byte [half_buff], 2 ; (DMA) Buffer 2
   968                                  
   969                                  	; we need to wait for 'SRB' (audio interrupt)
   970                                  	; (we can not return from 'PlayWav' here 
   971                                  	;  even if we have got an error from file reading)
   972                                  	; ((!!current audio data must be played!!))
   973                                  
   974                                  	;mov	ebx, 0B8000h ; video display page address
   975                                  	;mov	ah, 4Eh
   976                                  	;add	al, [half_buffer]
   977                                  	;mov	[ebx], ax ; show playing buffer (1, 2)
   978                                  
   979                                  	;; load 32768 bytes into audio buffer
   980                                  	;; (for the second half of DMA buffer)
   981                                  	;; 20/05/2017
   982                                  	;mov	edi, audio_buffer
   983                                  	;mov	edx, BUFFERSIZE
   984                                  	;call	loadFromFile
   985                                  	;jc	short p_return
   986                                  	;mov	byte [half_buff], 2 ; (DMA) Buffer 2
   987                                  
   988                                  	; 23/08/2020
   989                                  
   990                                  	; 27/10/2017
   991                                  	
   992                                  	; 03/08/2020
   993                                       	;jmp	short modp_gs ; 23/06/2017
   994                                  
   995                                  	; 24/08/2020
   996 000006C5 FE05[F6650000]          	inc	byte [counter]
   997                                  p_loop:
   998 000006CB 803D[F5650000]00        	cmp	byte [srb], 0
   999 000006D2 7611                    	jna	short q_loop
  1000                                  
  1001 000006D4 C605[F5650000]00        	mov	byte [srb], 0
  1002                                  modp_gs:
  1003                                  	; 24/08/2020
  1004                                  	;mov	edi, audio_buffer
  1005                                  	;mov	edx, BUFFERSIZE
  1006                                  	; 09/12/2023
  1007                                  	;call	loadFromFile
  1008                                  	;mov	edx, [buffersize]
  1009 000006DB FF15[D9030000]          	call	dword [loadfromwavfile]
  1010 000006E1 723A                    	jc	short q_return
  1011                                  
  1012                                  	; 23/08/2020
  1013 000006E3 EB6B                    	jmp	r_loop
  1014                                  q_loop:
  1015                                  	; 24/08/2020
  1016 000006E5 F605[F6650000]3F        	test	byte [counter], 63
  1017 000006EC 7562                    	jnz	short r_loop
  1018                                  k_loop:
  1019 000006EE B401                    	mov     ah, 1		; any key pressed?
  1020 000006F0 CD32                    	int     32h		; no, Loop.
  1021 000006F2 745C                    	jz	short r_loop
  1022                                  
  1023 000006F4 B400                    	mov     ah, 0		; flush key buffer...
  1024 000006F6 CD32                    	int     32h
  1025                                  
  1026                                  	; 19/10/2017 (modplay6.s)
  1027 000006F8 3C20                    	cmp	al, 20h
  1028 000006FA 740E                    	je	short change_pan
  1029                                  	; 09/10/2017 (playmod5.s)
  1030 000006FC 3C2B                    	cmp	al, '+' ; increase sound volume
  1031 000006FE 741E                    	je	short inc_volume_level
  1032 00000700 3C2D                    	cmp	al, '-'
  1033 00000702 743D                    	je	short dec_volume_level
  1034                                  
  1035                                  	; 19/10/2017 (modplay6.s)
  1036 00000704 24DF                    	and	al, 0DFh
  1037 00000706 3C50                    	cmp	al, 'P'
  1038 00000708 7513                    	jne	short q_return
  1039                                  
  1040                                  change_pan:
  1041                                  	; 19/10/2017 (modplay6.s)
  1042 0000070A 8A0D[F9650000]          	mov	cl, [pan_shift]
  1043 00000710 FEC1                    	inc	cl
  1044 00000712 80E103                  	and	cl, 3
  1045 00000715 880D[F9650000]          	mov	[pan_shift], cl
  1046 0000071B EB33                    	jmp	short r_loop
  1047                                  
  1048                                  q_return:
  1049 0000071D C3                      	retn
  1050                                  
  1051                                  	; 09/10/2017 (playmod5.s)
  1052                                  	; 24/06/2017 (wavplay2.s)
  1053                                  inc_volume_level:
  1054 0000071E 8A0D[F7650000]          	mov	cl, [volume_level]
  1055 00000724 80F91F                  	cmp	cl, 1Fh ; 31
  1056                                  	;jnb	short r_loop
  1057                                  	; 09/12/2023
  1058 00000727 73C5                    	jnb	short k_loop
  1059 00000729 FEC1                    	inc	cl
  1060                                  change_volume_level:
  1061 0000072B 880D[F7650000]          	mov	[volume_level], cl
  1062 00000731 88CD                    	mov	ch, cl
  1063                                  	; Set Master Volume Level
  1064                                  	sys	_audio, 0B00h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000733 BB000B0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83                              <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000738 B820000000          <1>  mov eax, %1
    90                              <1> 
    91 0000073D CD40                <1>  int 40h
  1065 0000073F EB0F                    	jmp	short r_loop
  1066                                  dec_volume_level:
  1067 00000741 8A0D[F7650000]          	mov	cl, [volume_level]
  1068 00000747 80F901                  	cmp	cl, 1 ; 1
  1069                                  	;jna	short r_loop
  1070                                  	; 09/12/2023
  1071 0000074A 76A2                    	jna	short k_loop
  1072 0000074C FEC9                    	dec	cl
  1073 0000074E EBDB                    	jmp	short change_volume_level
  1074                                  
  1075                                  r_loop:
  1076                                  	; 24/08/2020
  1077 00000750 FE05[F6650000]          	inc	byte [counter]
  1078                                  	; 09/12/2023
  1079                                  	;jnz	short q_loop
  1080                                  	;test	byte [counter], 0Fh
  1081 00000756 758D                    	jnz	short q_loop
  1082                                  _10:
  1083                                  	; 09/12/2023
  1084 00000758 F605[E7650000]FF        	test	byte [fbs_shift], 0FFh
  1085 0000075F 7405                    	jz	short _9
  1086                                  
  1087                                  	; 23/08/2020
  1088                                  	;test	byte [stmo], 2
  1089                                  	;;jz	p_loop
  1090                                  	;; 09/12/2023
  1091                                  	;jz	short _8
  1092                                  	;cmp	byte [bps], 16
  1093                                  	;;jne	p_loop
  1094                                  	;; 09/12/2023
  1095                                  	;je	short _9
  1096                                  _8:
  1097 00000761 E965FFFFFF              	jmp	p_loop
  1098                                  
  1099                                  _9:
  1100                                  	; 27/10/2017
  1101                                  	; Get Current DMA buffer Pointer 
  1102                                  	; 23/06/2017 ('modplay6.s')
  1103                                  	; bh = 15, get current pointer (DMA buffer offset)
  1104                                  	; bl = 0, for PCM OUT
  1105                                  	; ecx = 0
  1106                                  	;
  1107                                  	sys	_audio, 0F00h, 0
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000766 BB000F0000          <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000076B B900000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85                              <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000770 B820000000          <1>  mov eax, %1
    90                              <1> 
    91 00000775 CD40                <1>  int 40h
  1108                                  
  1109                                  	; 28/10/2017
  1110 00000777 24FC                    	and	al, 0FCh  ; dword alignment (stereo, 16 bit)	
  1111                                  	; 23/06/2017
  1112 00000779 BE[00000200]            	mov     esi, DMA_Buffer
  1113 0000077E 01C6                    	add     esi, eax	; add offset value
  1114                                  
  1115                                  	; 24/06/2017
  1116                                  	;mov	ecx, DMA_Buffer + (65536 - (256*4))
  1117                                  	; 09/12/2023
  1118 00000780 8B0D[00700000]          	mov	ecx, [DMA_buffer_size]
  1119 00000786 81C1[00FC0100]          	add	ecx, DMA_Buffer - (256*4)
  1120                                  
  1121 0000078C 39CE                    	cmp	esi, ecx 
  1122 0000078E 7602                    	jna	short _7
  1123 00000790 89CE                    	mov	esi, ecx
  1124                                  _7:
  1125                                  	; 23/10/2017 ('tmodplay.s')
  1126 00000792 E84F190000              	call	drawscopes
  1127                                  
  1128 00000797 E92FFFFFFF              	jmp	p_loop
  1129                                  
  1130                                  ;=============================================================================
  1131                                  ; 
  1132                                  ;=============================================================================
  1133                                  
  1134                                  ;dword2str:
  1135                                  ;	; 13/11/2016 - Erdogan Tan 
  1136                                  ;	; eax = dword value
  1137                                  ;	;
  1138                                  ;	call	dwordtohex
  1139                                  ;	mov	[dword_str], edx
  1140                                  ;	mov	[dword_str+4], eax
  1141                                  ;	mov	si, dword_str
  1142                                  ;	retn
  1143                                  
  1144                                  	; 05/03/2017 (TRDOS 386)
  1145                                  	; trdos386.s (unix386.s) - 10/05/2015
  1146                                  	; Convert binary number to hexadecimal string
  1147                                  
  1148                                  ;bytetohex:
  1149                                  ;	; INPUT ->
  1150                                  ;	; 	AL = byte (binary number)
  1151                                  ;	; OUTPUT ->
  1152                                  ;	;	AX = hexadecimal string
  1153                                  ;	;
  1154                                  ;	push	ebx
  1155                                  ;	movzx	ebx, al
  1156                                  ;	shr	bl, 4
  1157                                  ;	mov	bl, [ebx+hex_chars] 	 	
  1158                                  ;	xchg	bl, al
  1159                                  ;	and	bl, 0Fh
  1160                                  ;	mov	ah, [ebx+hex_chars] 
  1161                                  ;	pop	ebx	
  1162                                  ;	retn
  1163                                  
  1164                                  ;wordtohex:
  1165                                  ;	; INPUT ->
  1166                                  ;	; 	AX = word (binary number)
  1167                                  ;	; OUTPUT ->
  1168                                  ;	;	EAX = hexadecimal string
  1169                                  ;	;
  1170                                  ;	push	ebx
  1171                                  ;	xor	ebx, ebx
  1172                                  ;	xchg	ah, al
  1173                                  ;	push	eax
  1174                                  ;	mov	bl, ah
  1175                                  ;	shr	bl, 4
  1176                                  ;	mov	al, [ebx+hex_chars] 	 	
  1177                                  ;	mov	bl, ah
  1178                                  ;	and	bl, 0Fh
  1179                                  ;	mov	ah, [ebx+hex_chars]
  1180                                  ;	shl	eax, 16
  1181                                  ;	pop	eax
  1182                                  ;	pop	ebx
  1183                                  ;	jmp	short bytetohex
  1184                                  
  1185                                  ;dwordtohex:
  1186                                  ;	; INPUT ->
  1187                                  ;	; 	EAX = dword (binary number)
  1188                                  ;	; OUTPUT ->
  1189                                  ;	;	EDX:EAX = hexadecimal string
  1190                                  ;	;
  1191                                  ;	push	eax
  1192                                  ;	shr	eax, 16
  1193                                  ;	call	wordtohex
  1194                                  ;	mov	edx, eax
  1195                                  ;	pop	eax
  1196                                  ;	call	wordtohex
  1197                                  ;	retn
  1198                                  
  1199                                  ; 09/12/2023
  1200                                  ; 'playwav6.s' (27/11/2023)
  1201                                  
  1202                                  write_wav_file_info:
  1203                                  	; 01/05/2017
  1204                                  	sys	_msg, msgWavFileName, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000079C BB[C9640000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000007A1 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000007A6 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000007AB B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000007B0 CD40                <1>  int 40h
  1205                                  	sys	_msg, wav_file_name, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000007B2 BB[94650000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000007B7 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000007BC BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000007C1 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000007C6 CD40                <1>  int 40h
  1206                                  
  1207                                  write_sample_rate:
  1208                                  	; 01/05/2017
  1209 000007C8 66A1[72650000]          	mov	ax, [sample_rate]
  1210                                  	; ax = sample rate (hertz)
  1211 000007CE 31D2                    	xor	edx, edx
  1212 000007D0 66B90A00                	mov	cx, 10
  1213 000007D4 66F7F1                  	div	cx
  1214 000007D7 0015[EE640000]          	add	[msgHertz+4], dl
  1215 000007DD 29D2                    	sub	edx, edx
  1216 000007DF 66F7F1                  	div	cx
  1217 000007E2 0015[ED640000]          	add	[msgHertz+3], dl
  1218 000007E8 29D2                    	sub	edx, edx
  1219 000007EA 66F7F1                  	div	cx
  1220 000007ED 0015[EC640000]          	add	[msgHertz+2], dl
  1221 000007F3 29D2                    	sub	edx, edx
  1222 000007F5 66F7F1                  	div	cx
  1223 000007F8 0015[EB640000]          	add	[msgHertz+1], dl
  1224 000007FE 0005[EA640000]          	add	[msgHertz], al
  1225                                  	
  1226                                  	sys	_msg, msgSampleRate, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000804 BB[DB640000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000809 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000080E BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000813 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000818 CD40                <1>  int 40h
  1227                                  
  1228 0000081A BE[05650000]            	mov	esi, msg16Bits
  1229 0000081F 803D[71650000]10        	cmp	byte [bps], 16
  1230 00000826 7405                    	je	short wsr_1
  1231 00000828 BE[F5640000]            	mov	esi, msg8Bits
  1232                                  wsr_1:
  1233                                  	sys	_msg, esi, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000082D 89F3                <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000082F B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000834 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000839 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 0000083E CD40                <1>  int 40h
  1234                                  
  1235 00000840 BE[FE640000]            	mov	esi, msgMono
  1236 00000845 803D[70650000]01        	cmp	byte [stmo], 1
  1237 0000084C 7405                    	je	short wsr_2
  1238 0000084E BE[0F650000]            	mov	esi, msgStereo		
  1239                                  wsr_2:
  1240                                  	sys	_msg, esi, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000853 89F3                <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000855 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000085A BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000085F B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000864 CD40                <1>  int 40h
  1241 00000866 C3                              retn
  1242                                  
  1243                                  write_ac97_pci_dev_info:
  1244                                  	; 06/06/2017
  1245                                  	; 03/06/2017
  1246                                  	; BUS/DEV/FN
  1247                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  1248                                  	; DEV/VENDOR
  1249                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  1250                                  
  1251 00000867 8B35[E8650000]          	mov	esi, [dev_vendor]
  1252 0000086D 89F0                    	mov	eax, esi
  1253 0000086F 0FB6D8                  	movzx	ebx, al
  1254 00000872 88DA                    	mov	dl, bl
  1255 00000874 80E30F                  	and	bl, 0Fh
  1256 00000877 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1257 0000087D A2[67640000]            	mov	[msgVendorId+3], al
  1258 00000882 88D3                    	mov	bl, dl
  1259 00000884 C0EB04                  	shr	bl, 4
  1260 00000887 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1261 0000088D A2[66640000]            	mov	[msgVendorId+2], al
  1262 00000892 88E3                    	mov	bl, ah
  1263 00000894 88DA                    	mov	dl, bl
  1264 00000896 80E30F                  	and	bl, 0Fh
  1265 00000899 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1266 0000089F A2[65640000]            	mov	[msgVendorId+1], al
  1267 000008A4 88D3                    	mov	bl, dl
  1268 000008A6 C0EB04                  	shr	bl, 4
  1269 000008A9 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1270 000008AF A2[64640000]            	mov	[msgVendorId], al
  1271 000008B4 C1E810                  	shr	eax, 16
  1272 000008B7 88C3                    	mov	bl, al
  1273 000008B9 88DA                    	mov	dl, bl
  1274 000008BB 80E30F                  	and	bl, 0Fh
  1275 000008BE 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1276 000008C4 A2[78640000]            	mov	[msgDevId+3], al
  1277 000008C9 88D3                    	mov	bl, dl
  1278 000008CB C0EB04                  	shr	bl, 4
  1279 000008CE 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1280 000008D4 A2[77640000]            	mov	[msgDevId+2], al
  1281 000008D9 88E3                    	mov	bl, ah
  1282 000008DB 88DA                    	mov	dl, bl
  1283 000008DD 80E30F                  	and	bl, 0Fh
  1284 000008E0 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1285 000008E6 A2[76640000]            	mov	[msgDevId+1], al
  1286 000008EB 88D3                    	mov	bl, dl
  1287 000008ED C0EB04                  	shr	bl, 4
  1288 000008F0 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1289 000008F6 A2[75640000]            	mov	[msgDevId], al
  1290                                  
  1291 000008FB 8B35[EC650000]          	mov	esi, [bus_dev_fn]
  1292 00000901 C1EE08                  	shr	esi, 8
  1293 00000904 6689F0                  	mov	ax, si
  1294 00000907 88C3                    	mov	bl, al
  1295 00000909 88DA                    	mov	dl, bl
  1296 0000090B 80E307                  	and	bl, 7 ; bit 0,1,2
  1297 0000090E 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1298 00000914 A2[9C640000]            	mov	[msgFncNo+1], al
  1299 00000919 88D3                    	mov	bl, dl
  1300 0000091B C0EB03                  	shr	bl, 3
  1301 0000091E 88DA                    	mov	dl, bl
  1302 00000920 80E30F                  	and	bl, 0Fh
  1303 00000923 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1304 00000929 A2[8E640000]            	mov	[msgDevNo+1], al
  1305 0000092E 88D3                    	mov	bl, dl
  1306 00000930 C0EB04                  	shr	bl, 4
  1307 00000933 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1308 00000939 A2[8D640000]            	mov	[msgDevNo], al
  1309 0000093E 88E3                    	mov	bl, ah
  1310 00000940 88DA                    	mov	dl, bl
  1311 00000942 80E30F                  	and	bl, 0Fh
  1312 00000945 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1313 0000094B A2[82640000]            	mov	[msgBusNo+1], al
  1314 00000950 88D3                    	mov	bl, dl
  1315 00000952 C0EB04                  	shr	bl, 4
  1316 00000955 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1317 0000095B A2[81640000]            	mov	[msgBusNo], al
  1318                                  
  1319 00000960 66A1[F0650000]          	mov	ax, [ac97_NamBar]
  1320 00000966 88C3                    	mov	bl, al
  1321 00000968 88DA                    	mov	dl, bl
  1322 0000096A 80E30F                  	and	bl, 0Fh
  1323 0000096D 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1324 00000973 A2[AB640000]            	mov	[msgNamBar+3], al
  1325 00000978 88D3                    	mov	bl, dl
  1326 0000097A C0EB04                  	shr	bl, 4
  1327 0000097D 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1328 00000983 A2[AA640000]            	mov	[msgNamBar+2], al
  1329 00000988 88E3                    	mov	bl, ah
  1330 0000098A 88DA                    	mov	dl, bl
  1331 0000098C 80E30F                  	and	bl, 0Fh
  1332 0000098F 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1333 00000995 A2[A9640000]            	mov	[msgNamBar+1], al
  1334 0000099A 88D3                    	mov	bl, dl
  1335 0000099C C0EB04                  	shr	bl, 4
  1336 0000099F 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1337 000009A5 A2[A8640000]            	mov	[msgNamBar], al
  1338                                  
  1339 000009AA 66A1[F2650000]          	mov	ax, [ac97_NabmBar]
  1340 000009B0 88C3                    	mov	bl, al
  1341 000009B2 88DA                    	mov	dl, bl
  1342 000009B4 80E30F                  	and	bl, 0Fh
  1343 000009B7 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1344 000009BD A2[BB640000]            	mov	[msgNabmBar+3], al
  1345 000009C2 88D3                    	mov	bl, dl
  1346 000009C4 C0EB04                  	shr	bl, 4
  1347 000009C7 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1348 000009CD A2[BA640000]            	mov	[msgNabmBar+2], al
  1349 000009D2 88E3                    	mov	bl, ah
  1350 000009D4 88DA                    	mov	dl, bl
  1351 000009D6 80E30F                  	and	bl, 0Fh
  1352 000009D9 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1353 000009DF A2[B9640000]            	mov	[msgNabmBar+1], al
  1354 000009E4 88D3                    	mov	bl, dl
  1355 000009E6 C0EB04                  	shr	bl, 4
  1356 000009E9 8A83[22640000]          	mov	al, [ebx+hex_chars]
  1357 000009EF A2[B8640000]            	mov	[msgNabmBar], al
  1358                                  
  1359 000009F4 30E4                    	xor	ah, ah
  1360 000009F6 A0[E6650000]            	mov	al, [ac97_int_ln_reg]
  1361 000009FB B10A                    	mov	cl, 10
  1362 000009FD F6F1                    	div	cl
  1363 000009FF 660105[C4640000]        	add	[msgIRQ], ax
  1364 00000A06 20C0                    	and	al, al
  1365 00000A08 750D                    	jnz	short _w_ac97imsg_
  1366 00000A0A A0[C5640000]            	mov	al, [msgIRQ+1]
  1367 00000A0F B420                    	mov	ah, ' '
  1368 00000A11 66A3[C4640000]          	mov	[msgIRQ], ax
  1369                                  _w_ac97imsg_:
  1370                                  	sys	_msg, msgAC97Info, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000A17 BB[33640000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000A1C B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000A21 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000A26 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000A2B CD40                <1>  int 40h
  1371                                  
  1372 00000A2D C3                              retn
  1373                                  
  1374                                  write_VRA_info:
  1375                                  	; 25/11/2023
  1376                                  	sys	_msg, msgVRAheader, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000A2E BB[18650000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000A33 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000A38 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000A3D B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000A42 CD40                <1>  int 40h
  1377 00000A44 803D[F8650000]00        	cmp	byte [VRA], 0
  1378 00000A4B 7617                    	jna	short _w_VRAi_no
  1379                                  _w_VRAi_yes:
  1380                                  	sys	_msg, msgVRAyes, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000A4D BB[26650000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000A52 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000A57 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000A5C B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000A61 CD40                <1>  int 40h
  1381 00000A63 C3                      	retn
  1382                                  _w_VRAi_no:
  1383                                  	sys	_msg, msgVRAno, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000A64 BB[2C650000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000A69 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000A6E BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000A73 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000A78 CD40                <1>  int 40h
  1384 00000A7A C3                      	retn
  1385                                  
  1386                                  ; 09/12/2023
  1387                                  ; --------------------------------------------------------
  1388                                  ; 'playwav6.s' (27/11/2023)
  1389                                  
  1390                                  ; 26/11/2023
  1391                                  ; 25/11/2023 - playwav6.s (32 bit registers, TRDOS 386 adaption)
  1392                                  ; 15/11/2023 - PLAYWAV5.COM, ich_wav5.asm
  1393                                  ; 14/11/2023
  1394                                  ; 13/11/2023 - Erdogan Tan - (VRA, sample rate conversion)
  1395                                  ; --------------------------------------------------------
  1396                                  
  1397                                  ;;Note:	At the end of every buffer load,
  1398                                  ;;	during buffer switch/swap, there will be discontinuity
  1399                                  ;;	between the last converted sample and the 1st sample
  1400                                  ;;	of the next buffer.
  1401                                  ;;	(like as a dot noises vaguely between normal sound samples)
  1402                                  ;;	-To avoid this defect, the 1st sample of
  1403                                  ;;	the next buffer may be read from the wav file but
  1404                                  ;;	the file pointer would need to be set to 1 sample back
  1405                                  ;;	again via seek system call. Time comsumption problem! -
  1406                                  ;;
  1407                                  ;;	Erdogan Tan - 15/11/2023
  1408                                  ;;
  1409                                  ;;	((If entire wav data would be loaded at once.. conversion
  1410                                  ;;	defect/noise would disappear.. but for DOS, to keep
  1411                                  ;;	64KB buffer limit is important also it is important
  1412                                  ;;	for running under 1MB barrier without HIMEM.SYS or DPMI.
  1413                                  ;;	I have tested this program by using 2-30MB wav files.))
  1414                                  ;;
  1415                                  ;;	Test Computer:	ASUS desktop/mainboard, M2N4-SLI, 2010.
  1416                                  ;;			AMD Athlon 64 X2 2200 MHZ CPU.
  1417                                  ;;		       	NFORCE4 (CK804) AC97 audio hardware.
  1418                                  ;;			Realtek ALC850 codec.
  1419                                  ;;		       	Retro DOS v4.2 (MSDOS 6.22) operating system.
  1420                                  
  1421                                  load_8khz_mono_8_bit:
  1422                                  	; 15/11/2023
  1423                                  	; 14/11/2023
  1424                                  	; 13/11/2023
  1425 00000A7B F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1426                                  					; last of the file?
  1427 00000A82 7402                    	jz	short lff8m_0		; no
  1428 00000A84 F9                      	stc
  1429 00000A85 C3                      	retn
  1430                                  
  1431                                  lff8m_0:
  1432 00000A86 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1433                                          ;mov	edx, [loadsize]
  1434                                  
  1435                                  	; esi = buffer address
  1436                                  	;; edx = buffer size
  1437                                  
  1438                                  	; load file into memory
  1439                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000A8B 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000A91 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000A93 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000A99 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000A9E CD40                <1>  int 40h
  1440 00000AA0 7305                    	jnc	short lff8m_6
  1441 00000AA2 E9AB000000              	jmp	lff8m_5  ; error !
  1442                                  
  1443                                  lff8m_6:
  1444 00000AA7 BF[00800000]            	mov	edi, audio_buffer
  1445 00000AAC 21C0                    	and	eax, eax
  1446 00000AAE 0F8495000000            	jz	lff8_eof
  1447                                  
  1448 00000AB4 89C1                    	mov	ecx, eax		; byte count
  1449                                  lff8m_1:
  1450 00000AB6 AC                      	lodsb
  1451 00000AB7 A2[B9200000]            	mov	[previous_val], al
  1452 00000ABC 2C80                    	sub	al, 80h
  1453 00000ABE 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1454 00000AC2 66AB                    	stosw		; original sample (left channel)
  1455 00000AC4 66AB                    	stosw		; original sample (right channel)
  1456                                  	;xor	eax, eax
  1457 00000AC6 B080                    	mov	al, 80h
  1458 00000AC8 49                      	dec	ecx
  1459 00000AC9 7402                    	jz	short lff8m_2
  1460 00000ACB 8A06                    	mov	al, [esi]
  1461                                  lff8m_2:
  1462                                  	;mov	[next_val], ax
  1463 00000ACD 88C7                    	mov	bh, al	; [next_val]
  1464 00000ACF 8A25[B9200000]          	mov	ah, [previous_val]
  1465 00000AD5 00E0                    	add	al, ah	; [previous_val]
  1466 00000AD7 D0D8                    	rcr	al, 1
  1467 00000AD9 88C2                    	mov	dl, al	; this is interpolated middle (3th) sample
  1468 00000ADB 00E0                    	add	al, ah	; [previous_val]
  1469 00000ADD D0D8                    	rcr	al, 1	
  1470 00000ADF 88C3                    	mov	bl, al 	; this is temporary interpolation value	
  1471 00000AE1 00E0                    	add	al, ah	; [previous_val]
  1472 00000AE3 D0D8                    	rcr	al, 1
  1473 00000AE5 2C80                    	sub	al, 80h
  1474 00000AE7 66C1E008                	shl	ax, 8	
  1475 00000AEB 66AB                    	stosw		; this is 1st interpolated sample (L)
  1476 00000AED 66AB                    	stosw		; this is 1st interpolated sample (R)
  1477 00000AEF 88D8                    	mov	al, bl
  1478 00000AF1 00D0                    	add	al, dl
  1479 00000AF3 D0D8                    	rcr	al, 1
  1480 00000AF5 2C80                    	sub	al, 80h
  1481 00000AF7 66C1E008                	shl	ax, 8
  1482 00000AFB 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1483 00000AFD 66AB                    	stosw		; this is 2nd interpolated sample (R)
  1484 00000AFF 88D0                    	mov	al, dl
  1485 00000B01 2C80                    	sub	al, 80h
  1486 00000B03 66C1E008                	shl	ax, 8
  1487 00000B07 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1488 00000B09 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1489                                  	;mov	al, [next_val]
  1490 00000B0B 88F8                    	mov	al, bh
  1491 00000B0D 00D0                    	add	al, dl
  1492 00000B0F D0D8                    	rcr	al, 1
  1493 00000B11 88C3                    	mov	bl, al	; this is temporary interpolation value
  1494 00000B13 00D0                    	add	al, dl
  1495 00000B15 D0D8                    	rcr	al, 1
  1496 00000B17 2C80                    	sub	al, 80h
  1497 00000B19 66C1E008                	shl	ax, 8
  1498 00000B1D 66AB                    	stosw		; this is 4th interpolated sample (L)
  1499 00000B1F 66AB                    	stosw		; this is 4th interpolated sample (R)
  1500                                  	;mov	al, [next_val]
  1501 00000B21 88F8                    	mov	al, bh
  1502 00000B23 00D8                    	add	al, bl
  1503 00000B25 D0D8                    	rcr	al, 1
  1504 00000B27 2C80                    	sub	al, 80h
  1505 00000B29 66C1E008                	shl	ax, 8
  1506 00000B2D 66AB                    	stosw		; this is 5th interpolated sample (L)
  1507 00000B2F 66AB                    	stosw		; this is 5th interpolated sample (R)
  1508                                  	; 8 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1509 00000B31 09C9                    	or	ecx, ecx
  1510 00000B33 7581                    	jnz	short lff8m_1
  1511                                  
  1512                                  	; --------------
  1513                                  
  1514                                  lff8s_3:
  1515                                  lff8m_3:
  1516                                  lff8s2_3:
  1517                                  lff8m2_3:
  1518                                  lff16s_3:
  1519                                  lff16m_3:
  1520                                  lff16s2_3:
  1521                                  lff16m2_3:
  1522                                  lff24_3:
  1523                                  lff32_3:
  1524                                  lff44_3:
  1525                                  lff22_3:
  1526                                  lff11_3:
  1527 00000B35 8B0D[E1030000]          	mov	ecx, [buffersize] ; 16 bit (48 kHZ, stereo) sample size
  1528 00000B3B D1E1                    	shl	ecx, 1	; byte count
  1529 00000B3D 29F9                    	sub	ecx, edi
  1530 00000B3F 7607                    	jna	short lff8m_4
  1531                                  	;inc	ecx
  1532 00000B41 C1E902                  	shr	ecx, 2
  1533 00000B44 31C0                    	xor	eax, eax ; fill (remain part of) buffer with zeros	
  1534 00000B46 F3AB                    	rep	stosd
  1535                                  lff8m_4:
  1536 00000B48 C3                      	retn
  1537                                  
  1538                                  lff8_eof:
  1539                                  lff16_eof:
  1540                                  lff24_eof:
  1541                                  lff32_eof:
  1542                                  lff44_eof:
  1543                                  lff22_eof:
  1544                                  lff11_eof:
  1545                                  	; 15/11/2023
  1546 00000B49 C605[F4650000]01        	mov	byte [flags], ENDOFFILE
  1547 00000B50 EBE3                    	jmp	short lff8m_3
  1548                                  
  1549                                  lff8s_5:
  1550                                  lff8m_5:
  1551                                  lff8s2_5:
  1552                                  lff8m2_5:
  1553                                  lff16s_5:
  1554                                  lff16m_5:
  1555                                  lff16s2_5:
  1556                                  lff16m2_5:
  1557                                  lff24_5:
  1558                                  lff32_5:
  1559                                  lff44_5:
  1560                                  lff22_5:
  1561                                  lff11_5:
  1562                                  	; 09/12/2023	
  1563                                  	;mov	al, '!'  ; error
  1564                                  	;call	tL0
  1565                                  	
  1566                                  	;jmp	short lff8m_3
  1567                                  	; 15/11/2023
  1568 00000B52 EBF5                    	jmp	lff8_eof
  1569                                  
  1570                                  	; --------------
  1571                                  
  1572                                  load_8khz_stereo_8_bit:
  1573                                  	; 15/11/2023
  1574                                  	; 14/11/2023
  1575                                  	; 13/11/2023
  1576 00000B54 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1577                                  					; last of the file?
  1578 00000B5B 7402                    	jz	short lff8s_0		; no
  1579 00000B5D F9                      	stc
  1580 00000B5E C3                      	retn
  1581                                  
  1582                                  lff8s_0:
  1583 00000B5F BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1584                                          ;mov	edx, [loadsize]
  1585                                  
  1586                                  	; esi = buffer address
  1587                                  	;; edx = buffer size
  1588                                  
  1589                                  	; load file into memory
  1590                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000B64 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000B6A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000B6C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000B72 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000B77 CD40                <1>  int 40h
  1591 00000B79 72D7                    	jc	short lff8s_5 ; error !
  1592                                  
  1593 00000B7B BF[00800000]            	mov	edi, audio_buffer
  1594                                  	
  1595 00000B80 D1E8                    	shr	eax, 1
  1596 00000B82 74C5                    	jz	short lff8_eof
  1597                                  
  1598 00000B84 89C1                    	mov	ecx, eax	; word count
  1599                                  lff8s_1:
  1600 00000B86 AC                      	lodsb
  1601 00000B87 A2[B9200000]            	mov	[previous_val_l], al
  1602 00000B8C 2C80                    	sub	al, 80h
  1603 00000B8E 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1604 00000B92 66AB                    	stosw		; original sample (L)
  1605 00000B94 AC                      	lodsb
  1606 00000B95 A2[BB200000]            	mov	[previous_val_r], al
  1607 00000B9A 2C80                    	sub	al, 80h
  1608 00000B9C 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1609 00000BA0 66AB                    	stosw		; original sample (R)
  1610                                  
  1611                                  	;xor	eax, eax
  1612 00000BA2 66B88080                	mov	ax, 8080h
  1613 00000BA6 49                      	dec	ecx
  1614 00000BA7 7403                    	jz	short lff8s_2
  1615                                  		; convert 8 bit sample to 16 bit sample
  1616 00000BA9 668B06                  	mov	ax, [esi]
  1617                                  lff8s_2:
  1618 00000BAC A2[BD200000]            	mov	[next_val_l], al
  1619 00000BB1 8825[BF200000]          	mov	[next_val_r], ah
  1620 00000BB7 8A25[B9200000]          	mov	ah, [previous_val_l]
  1621 00000BBD 00E0                    	add	al, ah
  1622 00000BBF D0D8                    	rcr	al, 1
  1623 00000BC1 88C2                    	mov	dl, al	; this is interpolated middle (3th) sample (L)
  1624 00000BC3 00E0                    	add	al, ah
  1625 00000BC5 D0D8                    	rcr	al, 1	
  1626 00000BC7 88C3                    	mov	bl, al	; this is temporary interpolation value (L)
  1627 00000BC9 00E0                    	add	al, ah
  1628 00000BCB D0D8                    	rcr	al, 1
  1629 00000BCD 2C80                    	sub	al, 80h
  1630 00000BCF 66C1E008                	shl	ax, 8
  1631 00000BD3 66AB                    	stosw		; this is 1st interpolated sample (L)
  1632 00000BD5 A0[BF200000]            	mov	al, [next_val_r]
  1633 00000BDA 8A25[BB200000]          	mov	ah, [previous_val_r]
  1634 00000BE0 00E0                    	add	al, ah
  1635 00000BE2 D0D8                    	rcr	al, 1
  1636 00000BE4 88C6                    	mov	dh, al	; this is interpolated middle (3th) sample (R)
  1637 00000BE6 00E0                    	add	al, ah
  1638 00000BE8 D0D8                    	rcr	al, 1
  1639 00000BEA 88C7                    	mov	bh, al	; this is temporary interpolation value (R)
  1640 00000BEC 00E0                    	add	al, ah
  1641 00000BEE D0D8                    	rcr	al, 1
  1642 00000BF0 2C80                    	sub	al, 80h
  1643 00000BF2 66C1E008                	shl	ax, 8
  1644 00000BF6 66AB                    	stosw		; this is 1st interpolated sample (R)
  1645 00000BF8 88D8                    	mov	al, bl
  1646 00000BFA 00D0                    	add	al, dl
  1647 00000BFC D0D8                    	rcr	al, 1
  1648 00000BFE 2C80                    	sub	al, 80h
  1649 00000C00 66C1E008                	shl	ax, 8
  1650 00000C04 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1651 00000C06 88F8                    	mov	al, bh
  1652 00000C08 00F0                    	add	al, dh
  1653 00000C0A D0D8                    	rcr	al, 1
  1654 00000C0C 2C80                    	sub	al, 80h
  1655 00000C0E 66C1E008                	shl	ax, 8
  1656 00000C12 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  1657 00000C14 88D0                    	mov	al, dl
  1658 00000C16 2C80                    	sub	al, 80h
  1659 00000C18 66C1E008                	shl	ax, 8
  1660 00000C1C 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1661 00000C1E 88F0                    	mov	al, dh
  1662 00000C20 2C80                    	sub	al, 80h
  1663 00000C22 66C1E008                	shl	ax, 8
  1664 00000C26 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1665 00000C28 A0[BD200000]            	mov	al, [next_val_l]
  1666 00000C2D 00D0                    	add	al, dl
  1667 00000C2F D0D8                    	rcr	al, 1
  1668 00000C31 88C3                    	mov	bl, al	; this is temporary interpolation value (L)
  1669 00000C33 00D0                    	add	al, dl
  1670 00000C35 D0D8                    	rcr	al, 1
  1671 00000C37 2C80                    	sub	al, 80h
  1672 00000C39 66C1E008                	shl	ax, 8
  1673 00000C3D 66AB                    	stosw		; this is 4th interpolated sample (L)
  1674 00000C3F A0[BF200000]            	mov	al, [next_val_r]
  1675 00000C44 00F0                    	add	al, dh
  1676 00000C46 D0D8                    	rcr	al, 1
  1677 00000C48 88C7                    	mov	bh, al	; this is temporary interpolation value (R)
  1678 00000C4A 00F0                    	add	al, dh
  1679 00000C4C D0D8                    	rcr	al, 1
  1680 00000C4E 2C80                    	sub	al, 80h
  1681 00000C50 66C1E008                	shl	ax, 8
  1682 00000C54 66AB                    	stosw		; this is 4th interpolated sample (R)
  1683 00000C56 A0[BD200000]            	mov	al, [next_val_l]
  1684 00000C5B 00D8                    	add	al, bl
  1685 00000C5D D0D8                    	rcr	al, 1
  1686 00000C5F 2C80                    	sub	al, 80h
  1687 00000C61 66C1E008                	shl	ax, 8
  1688 00000C65 66AB                    	stosw		; this is 5th interpolated sample (L)
  1689 00000C67 A0[BF200000]            	mov	al, [next_val_r]
  1690 00000C6C 00F8                    	add	al, bh
  1691 00000C6E D0D8                    	rcr	al, 1
  1692 00000C70 2C80                    	sub	al, 80h
  1693 00000C72 66C1E008                	shl	ax, 8
  1694 00000C76 66AB                    	stosw		; this is 5th interpolated sample (R)
  1695                                  	; 8 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  1696 00000C78 E305                    	jecxz	lff8s_6
  1697 00000C7A E907FFFFFF              	jmp	lff8s_1
  1698                                  lff8s_6:
  1699 00000C7F E9B1FEFFFF              	jmp	lff8s_3
  1700                                  
  1701                                  load_8khz_mono_16_bit:
  1702                                  	; 13/11/2023
  1703 00000C84 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1704                                  					; last of the file?
  1705 00000C8B 7402                    	jz	short lff8m2_0		; no
  1706 00000C8D F9                      	stc
  1707 00000C8E C3                      	retn
  1708                                  
  1709                                  lff8m2_0:
  1710 00000C8F BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1711                                          ;mov	edx, [loadsize]
  1712                                  
  1713                                  	; esi = buffer address
  1714                                  	;; edx = buffer size
  1715                                  
  1716                                  	; load file into memory
  1717                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000C94 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000C9A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000C9C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000CA2 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000CA7 CD40                <1>  int 40h
  1718 00000CA9 0F82A0000000            	jc	lff8m2_7 ; error !
  1719                                  
  1720 00000CAF BF[00800000]            	mov	edi, audio_buffer
  1721                                  	
  1722 00000CB4 D1E8                    	shr	eax, 1
  1723 00000CB6 7505                    	jnz	short lff8m2_8
  1724 00000CB8 E98CFEFFFF              	jmp	lff8_eof
  1725                                  
  1726                                  lff8m2_8:
  1727 00000CBD 89C1                    	mov	ecx, eax	; word count
  1728                                  lff8m2_1:
  1729 00000CBF 66AD                    	lodsw
  1730 00000CC1 66AB                    	stosw		; original sample (left channel)
  1731 00000CC3 66AB                    	stosw		; original sample (right channel)
  1732 00000CC5 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1733 00000CC8 66A3[B9200000]          	mov	[previous_val], ax
  1734 00000CCE 31C0                    	xor	eax, eax
  1735 00000CD0 49                      	dec	ecx
  1736 00000CD1 7403                    	jz	short lff8m2_2
  1737 00000CD3 668B06                  	mov	ax, [esi]
  1738                                  lff8m2_2:
  1739 00000CD6 80C480                  	add	ah, 80h ; convert sound level to 0-65535 format
  1740 00000CD9 89C5                    	mov	ebp, eax	; [next_val]
  1741 00000CDB 660305[B9200000]        	add	ax, [previous_val]
  1742 00000CE2 66D1D8                  	rcr	ax, 1
  1743 00000CE5 89C2                    	mov	edx, eax ; this is interpolated middle (3th) sample
  1744 00000CE7 660305[B9200000]        	add	ax, [previous_val]
  1745 00000CEE 66D1D8                  	rcr	ax, 1	; this is temporary interpolation value
  1746 00000CF1 89C3                    	mov	ebx, eax 		
  1747 00000CF3 660305[B9200000]        	add	ax, [previous_val]
  1748 00000CFA 66D1D8                  	rcr	ax, 1
  1749 00000CFD 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1750 00000D00 66AB                    	stosw		; this is 1st interpolated sample (L)
  1751 00000D02 66AB                    	stosw		; this is 1st interpolated sample (R)
  1752 00000D04 89D8                    	mov	eax, ebx
  1753 00000D06 6601D0                  	add	ax, dx
  1754 00000D09 66D1D8                  	rcr	ax, 1
  1755 00000D0C 80EC80                  	sub	ah, 80h
  1756 00000D0F 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1757 00000D11 66AB                    	stosw		; this is 2nd interpolated sample (R)
  1758 00000D13 89D0                    	mov	eax, edx
  1759 00000D15 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1760 00000D18 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1761 00000D1A 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1762 00000D1C 89E8                    	mov	eax, ebp
  1763 00000D1E 6601D0                  	add	ax, dx
  1764 00000D21 66D1D8                  	rcr	ax, 1
  1765 00000D24 89C3                    	mov	ebx, eax ; this is temporary interpolation value
  1766 00000D26 6601D0                  	add	ax, dx
  1767 00000D29 66D1D8                  	rcr	ax, 1
  1768 00000D2C 80EC80                  	sub	ah, 80h
  1769 00000D2F 66AB                    	stosw		; this is 4th interpolated sample (L)
  1770 00000D31 66AB                    	stosw		; this is 4th interpolated sample (R)
  1771 00000D33 89E8                    	mov	eax, ebp
  1772 00000D35 6601D8                  	add	ax, bx
  1773 00000D38 66D1D8                  	rcr	ax, 1
  1774 00000D3B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1775 00000D3E 66AB                    	stosw		; this is 5th interpolated sample (L)
  1776 00000D40 66AB                    	stosw		; this is 5th interpolated sample (R)
  1777                                  	; 8 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1778 00000D42 09C9                    	or	ecx, ecx
  1779 00000D44 0F8575FFFFFF            	jnz	lff8m2_1
  1780 00000D4A E9E6FDFFFF              	jmp	lff8m2_3
  1781                                  
  1782                                  lff8m2_7:
  1783                                  lff8s2_7:
  1784 00000D4F E9FEFDFFFF              	jmp	lff8m2_5  ; error
  1785                                  
  1786                                  load_8khz_stereo_16_bit:
  1787                                  	; 16/11/2023
  1788                                  	; 15/11/2023
  1789                                  	; 13/11/2023
  1790 00000D54 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1791                                  					; last of the file?
  1792 00000D5B 7402                    	jz	short lff8s2_0		; no
  1793 00000D5D F9                      	stc
  1794 00000D5E C3                      	retn
  1795                                  
  1796                                  lff8s2_0:
  1797 00000D5F BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1798                                          ;mov	edx, [loadsize]
  1799                                  
  1800                                  	; esi = buffer address
  1801                                  	;; edx = buffer size
  1802                                  
  1803                                  	; load file into memory
  1804                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000D64 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000D6A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000D6C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000D72 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000D77 CD40                <1>  int 40h
  1805 00000D79 72D4                    	jc	short lff8s2_7 ; error !
  1806                                  
  1807 00000D7B BF[00800000]            	mov	edi, audio_buffer
  1808                                  	
  1809 00000D80 C1E802                  	shr	eax, 2
  1810 00000D83 7505                    	jnz	short lff8s2_8
  1811 00000D85 E9BFFDFFFF              	jmp	lff8_eof
  1812                                  
  1813                                  lff8s2_8:
  1814 00000D8A 89C1                    	mov	ecx, eax ; dword count
  1815                                  lff8s2_1:
  1816 00000D8C 66AD                    	lodsw
  1817 00000D8E 66AB                    	stosw		; original sample (L)
  1818                                  	; 15/11/2023
  1819 00000D90 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1820 00000D93 66A3[B9200000]          	mov	[previous_val_l], ax
  1821 00000D99 66AD                    	lodsw
  1822 00000D9B 66AB                    	stosw		; original sample (R)
  1823 00000D9D 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1824 00000DA0 66A3[BB200000]          	mov	[previous_val_r], ax
  1825 00000DA6 31D2                    	xor	edx, edx
  1826 00000DA8 31C0                    	xor	eax, eax
  1827                                  	; 16/11/2023
  1828 00000DAA 49                      	dec	ecx
  1829 00000DAB 7407                    	jz	short lff8s2_2
  1830 00000DAD 668B06                  	mov	ax, [esi]
  1831 00000DB0 668B5602                	mov	dx, [esi+2]
  1832                                  lff8s2_2:
  1833 00000DB4 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1834 00000DB7 66A3[BD200000]          	mov	[next_val_l], ax
  1835 00000DBD 80C680                  	add	dh, 80h	; convert sound level to 0-65535 format
  1836 00000DC0 668915[BF200000]        	mov	[next_val_r], dx
  1837 00000DC7 660305[B9200000]        	add	ax, [previous_val_l]
  1838 00000DCE 66D1D8                  	rcr	ax, 1
  1839 00000DD1 89C2                    	mov	edx, eax ; this is interpolated middle (3th) sample (L)
  1840 00000DD3 660305[B9200000]        	add	ax, [previous_val_l]
  1841 00000DDA 66D1D8                  	rcr	ax, 1	
  1842 00000DDD 89C3                    	mov	ebx, eax ; this is temporary interpolation value (L)
  1843 00000DDF 660305[B9200000]        	add	ax, [previous_val_l]
  1844 00000DE6 66D1D8                  	rcr	ax, 1
  1845 00000DE9 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1846 00000DEC 66AB                    	stosw		; this is 1st interpolated sample (L)
  1847 00000DEE 66A1[BF200000]          	mov	ax, [next_val_r]
  1848 00000DF4 660305[BB200000]        	add	ax, [previous_val_r]
  1849 00000DFB 66D1D8                  	rcr	ax, 1
  1850 00000DFE 89C5                    	mov	ebp, eax ; this is interpolated middle (3th) sample (R)
  1851 00000E00 660305[BB200000]        	add	ax, [previous_val_r]
  1852 00000E07 66D1D8                  	rcr	ax, 1
  1853 00000E0A 50                      	push	eax ; *	; this is temporary interpolation value (R)
  1854 00000E0B 660305[BB200000]        	add	ax, [previous_val_r]
  1855 00000E12 66D1D8                  	rcr	ax, 1
  1856 00000E15 80EC80                  	sub	ah, 80h
  1857 00000E18 66AB                    	stosw		; this is 1st interpolated sample (R)
  1858 00000E1A 89D8                    	mov	eax, ebx
  1859 00000E1C 6601D0                  	add	ax, dx
  1860 00000E1F 66D1D8                  	rcr	ax, 1
  1861 00000E22 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1862 00000E25 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1863 00000E27 58                      	pop	eax ; *
  1864 00000E28 6601E8                  	add	ax, bp
  1865 00000E2B 66D1D8                  	rcr	ax, 1
  1866 00000E2E 80EC80                  	sub	ah, 80h
  1867 00000E31 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  1868 00000E33 89D0                    	mov	eax, edx
  1869 00000E35 80EC80                  	sub	ah, 80h
  1870 00000E38 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1871 00000E3A 89E8                    	mov	eax, ebp
  1872 00000E3C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1873 00000E3F 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1874 00000E41 66A1[BD200000]          	mov	ax, [next_val_l]
  1875 00000E47 6601D0                  	add	ax, dx
  1876 00000E4A 66D1D8                  	rcr	ax, 1
  1877 00000E4D 89C3                    	mov	ebx, eax ; this is temporary interpolation value (L)
  1878 00000E4F 6601D0                  	add	ax, dx
  1879 00000E52 66D1D8                  	rcr	ax, 1
  1880 00000E55 80EC80                  	sub	ah, 80h
  1881 00000E58 66AB                    	stosw		; this is 4th interpolated sample (L)
  1882 00000E5A 66A1[BF200000]          	mov	ax, [next_val_r]
  1883 00000E60 6601E8                  	add	ax, bp
  1884 00000E63 66D1D8                  	rcr	ax, 1
  1885 00000E66 50                      	push	eax ; ** ; this is temporary interpolation value (R)
  1886 00000E67 6601E8                  	add	ax, bp
  1887 00000E6A 66D1D8                  	rcr	ax, 1
  1888 00000E6D 80EC80                  	sub	ah, 80h
  1889 00000E70 66AB                    	stosw		; this is 4th interpolated sample (R)
  1890 00000E72 66A1[BD200000]          	mov	ax, [next_val_l]
  1891 00000E78 6601D8                  	add	ax, bx
  1892 00000E7B 66D1D8                  	rcr	ax, 1
  1893 00000E7E 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1894 00000E81 66AB                    	stosw		; this is 5th interpolated sample (L)
  1895 00000E83 58                      	pop	eax ; **
  1896 00000E84 660305[BF200000]        	add	ax, [next_val_r]
  1897 00000E8B 66D1D8                  	rcr	ax, 1
  1898 00000E8E 80EC80                  	sub	ah, 80h
  1899 00000E91 66AB                    	stosw		; this is 5th interpolated sample (R)
  1900                                  	; 8 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  1901 00000E93 E305                    	jecxz	lff8_s2_9
  1902 00000E95 E9F2FEFFFF              	jmp	lff8s2_1
  1903                                  lff8_s2_9:
  1904 00000E9A E996FCFFFF              	jmp	lff8s2_3
  1905                                  
  1906                                  ; .....................
  1907                                  
  1908                                  load_16khz_mono_8_bit:
  1909                                  	; 14/11/2023
  1910                                  	; 13/11/2023
  1911 00000E9F F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1912                                  					; last of the file?
  1913 00000EA6 7402                    	jz	short lff16m_0		; no
  1914 00000EA8 F9                      	stc
  1915 00000EA9 C3                      	retn
  1916                                  
  1917                                  lff16m_0:
  1918 00000EAA BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1919                                          ;mov	edx, [loadsize]
  1920                                  
  1921                                  	; esi = buffer address
  1922                                  	;; edx = buffer size
  1923                                  
  1924                                  	; load file into memory
  1925                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000EAF 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000EB5 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000EB7 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000EBD B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000EC2 CD40                <1>  int 40h
  1926 00000EC4 7253                    	jc	short lff16m_7 ; error !
  1927                                  
  1928 00000EC6 BF[00800000]            	mov	edi, audio_buffer
  1929                                  	
  1930 00000ECB 21C0                    	and	eax, eax
  1931 00000ECD 7505                    	jnz	short lff16m_8
  1932 00000ECF E975FCFFFF              	jmp	lff16_eof
  1933                                  
  1934                                  lff16m_8:
  1935 00000ED4 89C1                    	mov	ecx, eax		; byte count
  1936                                  lff16m_1:
  1937 00000ED6 AC                      	lodsb
  1938                                  	;mov	[previous_val], al
  1939 00000ED7 88C3                    	mov	bl, al
  1940 00000ED9 2C80                    	sub	al, 80h
  1941 00000EDB 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1942 00000EDF 66AB                    	stosw		; original sample (left channel)
  1943 00000EE1 66AB                    	stosw		; original sample (right channel)
  1944                                  	;xor	ax, ax
  1945                                  	; 14/11/22023
  1946 00000EE3 B080                    	mov	al, 80h
  1947 00000EE5 49                      	dec	ecx
  1948 00000EE6 7402                    	jz	short lff16m_2
  1949 00000EE8 8A06                    	mov	al, [esi]
  1950                                  lff16m_2:
  1951                                  	;mov	[next_val], al
  1952 00000EEA 88C7                    	mov	bh, al
  1953                                  	;add	al, [previous_val]
  1954 00000EEC 00D8                    	add	al, bl
  1955 00000EEE D0D8                    	rcr	al, 1
  1956 00000EF0 88C2                    	mov	dl, al	; this is interpolated middle (temp) sample
  1957                                  	;add	al, [previous_val]
  1958 00000EF2 00D8                    	add	al, bl
  1959 00000EF4 D0D8                    	rcr	al, 1
  1960 00000EF6 2C80                    	sub	al, 80h
  1961 00000EF8 66C1E008                	shl	ax, 8
  1962 00000EFC 66AB                    	stosw		; this is 1st interpolated sample (L)
  1963 00000EFE 66AB                    	stosw		; this is 1st interpolated sample (R)
  1964                                  	;mov	al, [next_val]
  1965 00000F00 88F8                    	mov	al, bh
  1966 00000F02 00D0                    	add	al, dl
  1967 00000F04 D0D8                    	rcr	al, 1
  1968 00000F06 2C80                    	sub	al, 80h
  1969 00000F08 66C1E008                	shl	ax, 8
  1970 00000F0C 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1971 00000F0E 66AB                    	stosw		; this is 2nd interpolated sample (R)
  1972                                  	
  1973                                  	; 16 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1974 00000F10 09C9                    	or	ecx, ecx
  1975 00000F12 75C2                    	jnz	short lff16m_1
  1976 00000F14 E91CFCFFFF              	jmp	lff16m_3
  1977                                  
  1978                                  lff16m_7:
  1979                                  lff16s_7:
  1980 00000F19 E934FCFFFF              	jmp	lff16m_5  ; error
  1981                                  
  1982                                  load_16khz_stereo_8_bit:
  1983                                  	; 14/11/2023
  1984                                  	; 13/11/2023
  1985 00000F1E F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1986                                  					; last of the file?
  1987 00000F25 7402                    	jz	short lff16s_0		; no
  1988 00000F27 F9                      	stc
  1989 00000F28 C3                      	retn
  1990                                  
  1991                                  lff16s_0:
  1992 00000F29 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1993                                          ;mov	edx, [loadsize]
  1994                                  
  1995                                  	; esi = buffer address
  1996                                  	;; edx = buffer size
  1997                                  
  1998                                  	; load file into memory
  1999                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000F2E 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000F34 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000F36 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000F3C B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000F41 CD40                <1>  int 40h
  2000 00000F43 72D4                    	jc	short lff16s_7 ; error !
  2001                                  
  2002 00000F45 BF[00800000]            	mov	edi, audio_buffer
  2003                                  	
  2004 00000F4A D1E8                    	shr	eax, 1
  2005 00000F4C 7505                    	jnz	short lff16s_8
  2006 00000F4E E9F6FBFFFF              	jmp	lff16_eof
  2007                                  
  2008                                  lff16s_8:
  2009 00000F53 89C1                    	mov	ecx, eax	; word count
  2010                                  lff16s_1:
  2011 00000F55 AC                      	lodsb
  2012 00000F56 A2[B9200000]            	mov	[previous_val_l], al
  2013 00000F5B 2C80                    	sub	al, 80h
  2014 00000F5D 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2015 00000F61 66AB                    	stosw		; original sample (L)
  2016 00000F63 AC                      	lodsb
  2017 00000F64 A2[BB200000]            	mov	[previous_val_r], al
  2018 00000F69 2C80                    	sub	al, 80h
  2019 00000F6B 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2020 00000F6F 66AB                    	stosw		; original sample (R)
  2021                                  
  2022                                  	;xor	eax, eax
  2023 00000F71 66B88080                	mov	ax, 8080h
  2024 00000F75 49                      	dec	ecx
  2025 00000F76 7403                    	jz	short lff16s_2
  2026                                  		; convert 8 bit sample to 16 bit sample
  2027 00000F78 668B06                  	mov	ax, [esi]
  2028                                  lff16s_2:
  2029                                  	;mov	[next_val_l], al
  2030                                  	;mov	[next_val_r], ah
  2031 00000F7B 89C3                    	mov	ebx, eax
  2032 00000F7D 0205[B9200000]          	add	al, [previous_val_l]
  2033 00000F83 D0D8                    	rcr	al, 1
  2034 00000F85 88C2                    	mov	dl, al	; this is temporary interpolation value (L)
  2035 00000F87 0205[B9200000]          	add	al, [previous_val_l]
  2036 00000F8D D0D8                    	rcr	al, 1
  2037 00000F8F 2C80                    	sub	al, 80h
  2038 00000F91 66C1E008                	shl	ax, 8
  2039 00000F95 66AB                    	stosw		; this is 1st interpolated sample (L)
  2040 00000F97 88F8                    	mov	al, bh	; [next_val_r]
  2041 00000F99 0205[BB200000]          	add	al, [previous_val_r]
  2042 00000F9F D0D8                    	rcr	al, 1
  2043 00000FA1 88C6                    	mov	dh, al	; this is temporary interpolation value (R)
  2044 00000FA3 0205[BB200000]          	add	al, [previous_val_r]
  2045 00000FA9 D0D8                    	rcr	al, 1
  2046 00000FAB 2C80                    	sub	al, 80h
  2047 00000FAD 66C1E008                	shl	ax, 8
  2048 00000FB1 66AB                    	stosw		; this is 1st interpolated sample (R)
  2049 00000FB3 88D0                    	mov	al, dl
  2050 00000FB5 00D8                    	add	al, bl	; [next_val_l]
  2051 00000FB7 D0D8                    	rcr	al, 1
  2052 00000FB9 2C80                    	sub	al, 80h
  2053 00000FBB 66C1E008                	shl	ax, 8
  2054 00000FBF 66AB                    	stosw		; this is 2nd interpolated sample (L)
  2055 00000FC1 88F0                    	mov	al, dh
  2056 00000FC3 00F8                    	add	al, bh	; [next_val_r]
  2057 00000FC5 D0D8                    	rcr	al, 1
  2058 00000FC7 2C80                    	sub	al, 80h
  2059 00000FC9 66C1E008                	shl	ax, 8
  2060 00000FCD 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  2061                                  	
  2062                                  	; 16 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2063 00000FCF 09C9                    	or	ecx, ecx
  2064 00000FD1 7582                    	jnz	short lff16s_1
  2065 00000FD3 E95DFBFFFF              	jmp	lff16s_3
  2066                                  
  2067                                  load_16khz_mono_16_bit:
  2068                                  	; 15/11/2023
  2069                                  	; 13/11/2023
  2070 00000FD8 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2071                                  					; last of the file?
  2072 00000FDF 7402                    	jz	short lff16m2_0		; no
  2073 00000FE1 F9                      	stc
  2074 00000FE2 C3                      	retn
  2075                                  
  2076                                  lff16m2_0:
  2077 00000FE3 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2078                                          ;mov	edx, [loadsize]
  2079                                  
  2080                                  	; esi = buffer address
  2081                                  	;; edx = buffer size
  2082                                  
  2083                                  	; load file into memory
  2084                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000FE8 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000FEE 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000FF0 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000FF6 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000FFB CD40                <1>  int 40h
  2085 00000FFD 7255                    	jc	short lff16m2_7 ; error !
  2086                                  
  2087 00000FFF BF[00800000]            	mov	edi, audio_buffer
  2088                                  	
  2089 00001004 D1E8                    	shr	eax, 1
  2090 00001006 7505                    	jnz	short lff16m2_8
  2091 00001008 E93CFBFFFF              	jmp	lff16_eof
  2092                                  
  2093                                  lff16m2_8:
  2094 0000100D 89C1                    	mov	ecx, eax  ; word count
  2095                                  lff16m2_1:
  2096 0000100F 66AD                    	lodsw
  2097 00001011 66AB                    	stosw		; original sample (left channel)
  2098 00001013 66AB                    	stosw		; original sample (right channel)
  2099 00001015 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2100                                  	;mov	[previous_val], ax
  2101 00001018 89C3                    	mov	ebx, eax	
  2102 0000101A 31C0                    	xor	eax, eax
  2103 0000101C 49                      	dec	ecx
  2104 0000101D 7403                    	jz	short lff16m2_2
  2105 0000101F 668B06                  	mov	ax, [esi]
  2106                                  lff16m2_2:
  2107 00001022 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2108 00001025 89C5                    	mov	ebp, eax	; [next_val]
  2109                                  	;add	ax, [previous_val]
  2110 00001027 6601D8                  	add	ax, bx
  2111 0000102A 66D1D8                  	rcr	ax, 1
  2112 0000102D 89C2                    	mov	edx, eax ; this is temporary interpolation value
  2113                                  	;add	ax, [previous_val]
  2114 0000102F 6601D8                  	add	ax, bx
  2115 00001032 66D1D8                  	rcr	ax, 1
  2116 00001035 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2117 00001038 66AB                    	stosw		; this is 1st interpolated sample (L)
  2118 0000103A 66AB                    	stosw		; this is 1st interpolated sample (R)
  2119 0000103C 89E8                    	mov	eax, ebp 
  2120 0000103E 6601D0                  	add	ax, dx
  2121 00001041 66D1D8                  	rcr	ax, 1
  2122 00001044 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2123 00001047 66AB                    	stosw		; this is 2nd interpolated sample (L)
  2124 00001049 66AB                    	stosw		; this is 2nd interpolated sample (R)
  2125                                  	; 16 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2126 0000104B 09C9                    	or	ecx, ecx
  2127 0000104D 75C0                    	jnz	short lff16m2_1
  2128 0000104F E9E1FAFFFF              	jmp	lff16m2_3
  2129                                  
  2130                                  lff16m2_7:
  2131                                  lff16s2_7:
  2132 00001054 E9F9FAFFFF              	jmp	lff16m2_5  ; error
  2133                                  
  2134                                  load_16khz_stereo_16_bit:
  2135                                  	; 16/11/2023
  2136                                  	; 15/11/2023
  2137                                  	; 13/11/2023
  2138 00001059 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2139                                  					; last of the file?
  2140 00001060 7402                    	jz	short lff16s2_0		; no
  2141 00001062 F9                      	stc
  2142 00001063 C3                      	retn
  2143                                  
  2144                                  lff16s2_0:
  2145 00001064 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2146                                          ;mov	edx, [loadsize]
  2147                                  
  2148                                  	; esi = buffer address
  2149                                  	;; edx = buffer size
  2150                                  
  2151                                  	; load file into memory
  2152                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001069 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000106F 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001071 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001077 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000107C CD40                <1>  int 40h
  2153 0000107E 72D4                    	jc	short lff16s2_7 ; error !
  2154                                  
  2155 00001080 BF[00800000]            	mov	edi, audio_buffer
  2156                                  	
  2157 00001085 C1E802                  	shr	eax, 2
  2158 00001088 7505                    	jnz	short lff16s2_8
  2159 0000108A E9BAFAFFFF              	jmp	lff16_eof
  2160                                  
  2161                                  lff16s2_8:
  2162 0000108F 89C1                    	mov	ecx, eax  ; dword count
  2163                                  lff16s2_1:
  2164 00001091 66AD                    	lodsw
  2165 00001093 66AB                    	stosw		; original sample (L)
  2166 00001095 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2167 00001098 66A3[B9200000]          	mov	[previous_val_l], ax
  2168 0000109E 66AD                    	lodsw
  2169 000010A0 66AB                    	stosw		; original sample (R)
  2170 000010A2 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2171 000010A5 66A3[BB200000]          	mov	[previous_val_r], ax
  2172 000010AB 31D2                    	xor	edx, edx
  2173 000010AD 31C0                    	xor	eax, eax
  2174                                  	; 16/11/2023
  2175 000010AF 49                      	dec	ecx
  2176 000010B0 7407                    	jz	short lff16s2_2
  2177 000010B2 668B06                  	mov	ax, [esi]
  2178 000010B5 668B5602                	mov	dx, [esi+2]
  2179                                  lff16s2_2:
  2180 000010B9 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2181                                  	;mov	[next_val_l], ax
  2182 000010BC 89C5                    	mov	ebp, eax
  2183 000010BE 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format 
  2184 000010C1 668915[BF200000]        	mov	[next_val_r], dx
  2185 000010C8 660305[B9200000]        	add	ax, [previous_val_l]
  2186 000010CF 66D1D8                  	rcr	ax, 1
  2187 000010D2 89C2                    	mov	edx, eax ; this is temporary interpolation value (L)
  2188 000010D4 660305[B9200000]        	add	ax, [previous_val_l]
  2189 000010DB 66D1D8                  	rcr	ax, 1
  2190 000010DE 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2191 000010E1 66AB                    	stosw		; this is 1st interpolated sample (L)
  2192 000010E3 66A1[BF200000]          	mov	ax, [next_val_r]
  2193 000010E9 660305[BB200000]        	add	ax, [previous_val_r]
  2194 000010F0 66D1D8                  	rcr	ax, 1
  2195 000010F3 89C3                    	mov	ebx, eax ; this is temporary interpolation value (R)
  2196 000010F5 660305[BB200000]        	add	ax, [previous_val_r]
  2197 000010FC 66D1D8                  	rcr	ax, 1
  2198 000010FF 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2199 00001102 66AB                    	stosw		; this is 1st interpolated sample (R)
  2200                                  	;mov	ax, [next_val_l]
  2201 00001104 89E8                    	mov	eax, ebp
  2202 00001106 6601D0                  	add	ax, dx
  2203 00001109 66D1D8                  	rcr	ax, 1
  2204 0000110C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2205 0000110F 66AB                    	stosw		; this is 2nd interpolated sample (L)
  2206 00001111 66A1[BF200000]          	mov	ax, [next_val_r]
  2207 00001117 6601D8                  	add	ax, bx
  2208 0000111A 66D1D8                  	rcr	ax, 1
  2209 0000111D 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2210 00001120 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  2211                                  	
  2212                                  	; 16 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2213 00001122 09C9                    	or	ecx, ecx
  2214 00001124 0F8567FFFFFF            	jnz	lff16s2_1
  2215 0000112A E906FAFFFF              	jmp	lff16s2_3
  2216                                  
  2217                                  ; .....................
  2218                                  
  2219                                  load_24khz_mono_8_bit:
  2220                                  	; 15/11/2023
  2221 0000112F F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2222                                  					; last of the file?
  2223 00001136 7402                    	jz	short lff24m_0		; no
  2224 00001138 F9                      	stc
  2225 00001139 C3                      	retn
  2226                                  
  2227                                  lff24m_0:
  2228 0000113A BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2229                                          ;mov	edx, [loadsize]
  2230                                  
  2231                                  	; esi = buffer address
  2232                                  	;; edx = buffer size
  2233                                  
  2234                                  	; load file into memory
  2235                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000113F 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001145 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001147 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000114D B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001152 CD40                <1>  int 40h
  2236 00001154 723B                    	jc	short lff24m_7 ; error !
  2237                                  
  2238 00001156 BF[00800000]            	mov	edi, audio_buffer
  2239                                  	
  2240 0000115B 21C0                    	and	eax, eax
  2241 0000115D 7505                    	jnz	short lff24m_8
  2242 0000115F E9E5F9FFFF              	jmp	lff24_eof
  2243                                  
  2244                                  lff24m_8:
  2245 00001164 89C1                    	mov	ecx, eax	; byte count
  2246                                  lff24m_1:
  2247 00001166 AC                      	lodsb
  2248                                  	;mov	[previous_val], al
  2249 00001167 88C3                    	mov	bl, al
  2250 00001169 2C80                    	sub	al, 80h
  2251 0000116B 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2252 0000116F 66AB                    	stosw		; original sample (left channel)
  2253 00001171 66AB                    	stosw		; original sample (right channel)
  2254                                  	;xor	eax, eax
  2255 00001173 B080                    	mov	al, 80h
  2256 00001175 49                      	dec	ecx
  2257 00001176 7402                    	jz	short lff24m_2
  2258 00001178 8A06                    	mov	al, [esi]
  2259                                  lff24m_2:
  2260                                  	;;mov	[next_val], al
  2261                                  	;mov	bh, al
  2262                                  	;add	al, [previous_val]
  2263 0000117A 00D8                    	add	al, bl
  2264 0000117C D0D8                    	rcr	al, 1
  2265 0000117E 2C80                    	sub	al, 80h
  2266 00001180 66C1E008                	shl	ax, 8
  2267 00001184 66AB                    	stosw		; this is interpolated sample (L)
  2268 00001186 66AB                    	stosw		; this is interpolated sample (R)
  2269                                  	
  2270                                  	; 24 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2271 00001188 09C9                    	or	ecx, ecx
  2272 0000118A 75DA                    	jnz	short lff24m_1
  2273 0000118C E9A4F9FFFF              	jmp	lff24_3
  2274                                  
  2275                                  lff24m_7:
  2276                                  lff24s_7:
  2277 00001191 E9BCF9FFFF              	jmp	lff24_5  ; error
  2278                                  
  2279                                  load_24khz_stereo_8_bit:
  2280                                  	; 15/11/2023
  2281 00001196 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2282                                  					; last of the file?
  2283 0000119D 7402                    	jz	short lff24s_0		; no
  2284 0000119F F9                      	stc
  2285 000011A0 C3                      	retn
  2286                                  
  2287                                  lff24s_0:
  2288 000011A1 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2289                                          ;mov	edx, [loadsize]
  2290                                  
  2291                                  	; esi = buffer address
  2292                                  	;; edx = buffer size
  2293                                  
  2294                                  	; load file into memory
  2295                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000011A6 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000011AC 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000011AE 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000011B4 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000011B9 CD40                <1>  int 40h
  2296 000011BB 72D4                    	jc	short lff24s_7 ; error !
  2297                                  
  2298 000011BD BF[00800000]            	mov	edi, audio_buffer
  2299                                  	
  2300 000011C2 D1E8                    	shr	eax, 1
  2301 000011C4 7505                    	jnz	short lff24s_8
  2302 000011C6 E97EF9FFFF              	jmp	lff24_eof
  2303                                  
  2304                                  lff24s_8:
  2305 000011CB 89C1                    	mov	ecx, eax  ; word count
  2306                                  lff24s_1:
  2307 000011CD AC                      	lodsb
  2308 000011CE A2[B9200000]            	mov	[previous_val_l], al
  2309 000011D3 2C80                    	sub	al, 80h
  2310 000011D5 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2311 000011D9 66AB                    	stosw		; original sample (L)
  2312 000011DB AC                      	lodsb
  2313 000011DC A2[BB200000]            	mov	[previous_val_r], al
  2314 000011E1 2C80                    	sub	al, 80h
  2315 000011E3 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2316 000011E7 66AB                    	stosw		; original sample (R)
  2317                                  
  2318                                  	;xor	eax, eax
  2319 000011E9 66B88080                	mov	ax, 8080h
  2320 000011ED 49                      	dec	ecx
  2321 000011EE 7403                    	jz	short lff24s_2
  2322                                  		; convert 8 bit sample to 16 bit sample
  2323 000011F0 668B06                  	mov	ax, [esi]
  2324                                  lff24s_2:
  2325                                  	;;mov	[next_val_l], al
  2326                                  	;;mov	[next_val_r], ah
  2327                                  	;mov	bx, ax
  2328 000011F3 88E7                    	mov	bh, ah
  2329 000011F5 0205[B9200000]          	add	al, [previous_val_l]
  2330 000011FB D0D8                    	rcr	al, 1
  2331                                  	;mov	dl, al
  2332 000011FD 2C80                    	sub	al, 80h
  2333 000011FF 66C1E008                	shl	ax, 8
  2334 00001203 66AB                    	stosw		; this is interpolated sample (L)
  2335 00001205 88F8                    	mov	al, bh	; [next_val_r]
  2336 00001207 0205[BB200000]          	add	al, [previous_val_r]
  2337 0000120D D0D8                    	rcr	al, 1
  2338                                  	;mov	dh, al
  2339 0000120F 2C80                    	sub	al, 80h
  2340 00001211 66C1E008                	shl	ax, 8
  2341 00001215 66AB                    	stosw		; this is interpolated sample (R)
  2342                                  		
  2343                                  	; 24 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2344 00001217 09C9                    	or	ecx, ecx
  2345 00001219 75B2                    	jnz	short lff24s_1
  2346 0000121B E915F9FFFF              	jmp	lff24_3
  2347                                  
  2348                                  load_24khz_mono_16_bit:
  2349                                  	; 15/11/2023
  2350 00001220 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2351                                  					; last of the file?
  2352 00001227 7402                    	jz	short lff24m2_0		; no
  2353 00001229 F9                      	stc
  2354 0000122A C3                      	retn
  2355                                  
  2356                                  lff24m2_0:
  2357 0000122B BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2358                                          ;mov	edx, [loadsize]
  2359                                  
  2360                                  	; esi = buffer address
  2361                                  	;; edx = buffer size
  2362                                  
  2363                                  	; load file into memory
  2364                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001230 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001236 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001238 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000123E B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001243 CD40                <1>  int 40h
  2365 00001245 7237                    	jc	short lff24m2_7 ; error !
  2366                                  
  2367 00001247 BF[00800000]            	mov	edi, audio_buffer
  2368                                  	
  2369 0000124C D1E8                    	shr	eax, 1
  2370 0000124E 7505                    	jnz	short lff24m2_8
  2371 00001250 E9F4F8FFFF              	jmp	lff24_eof
  2372                                  
  2373                                  lff24m2_8:
  2374 00001255 89C1                    	mov	ecx, eax  ; word count
  2375                                  lff24m2_1:
  2376 00001257 66AD                    	lodsw
  2377 00001259 66AB                    	stosw		; original sample (left channel)
  2378 0000125B 66AB                    	stosw		; original sample (right channel)
  2379 0000125D 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2380                                  	;mov	[previous_val], ax
  2381                                  	;mov	ebx, eax	
  2382                                  	;xor	eax, eax
  2383 00001260 31DB                    	xor	ebx, ebx
  2384 00001262 49                      	dec	ecx
  2385 00001263 7403                    	jz	short lff24m2_2
  2386                                  	;mov	ax, [esi]
  2387 00001265 668B1E                  	mov	bx, [esi]
  2388                                  lff24m2_2:
  2389                                  	;add	ah, 80h ; convert sound level 0 to 65535 format
  2390                                  	;mov	ebp, eax	; [next_val]
  2391                                  	;add	ax, [previous_val]
  2392                                  	; ax = [previous_val]
  2393                                  	; bx = [next_val]
  2394 00001268 6601D8                  	add	ax, bx
  2395 0000126B 66D1D8                  	rcr	ax, 1
  2396 0000126E 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2397 00001271 66AB                    	stosw		; this is interpolated sample (L)
  2398 00001273 66AB                    	stosw		; this is interpolated sample (R)
  2399                                  	; 24 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2400 00001275 09C9                    	or	ecx, ecx
  2401 00001277 75DE                    	jnz	short lff24m2_1
  2402 00001279 E9B7F8FFFF              	jmp	lff24_3
  2403                                  
  2404                                  lff24m2_7:
  2405                                  lff24s2_7:
  2406 0000127E E9CFF8FFFF              	jmp	lff24_5  ; error
  2407                                  
  2408                                  load_24khz_stereo_16_bit:
  2409                                  	; 16/11/2023
  2410                                  	; 15/11/2023
  2411 00001283 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2412                                  					; last of the file?
  2413 0000128A 7402                    	jz	short lff24s2_0		; no
  2414 0000128C F9                      	stc
  2415 0000128D C3                      	retn
  2416                                  
  2417                                  lff24s2_0:
  2418 0000128E BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2419                                          ;mov	edx, [loadsize]
  2420                                  
  2421                                  	; esi = buffer address
  2422                                  	;; edx = buffer size
  2423                                  
  2424                                  	; load file into memory
  2425                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001293 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001299 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000129B 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000012A1 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000012A6 CD40                <1>  int 40h
  2426 000012A8 72D4                    	jc	short lff24s2_7 ; error !
  2427                                  
  2428 000012AA BF[00800000]            	mov	edi, audio_buffer
  2429                                  	
  2430 000012AF C1E802                  	shr	eax, 2
  2431 000012B2 7505                    	jnz	short lff24s2_8
  2432 000012B4 E990F8FFFF              	jmp	lff24_eof
  2433                                  
  2434                                  lff24s2_8:
  2435 000012B9 89C1                    	mov	ecx, eax  ; dword count
  2436                                  lff24s2_1:
  2437 000012BB 66AD                    	lodsw
  2438 000012BD 66AB                    	stosw		; original sample (L)
  2439 000012BF 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2440 000012C2 66A3[B9200000]          	mov	[previous_val_l], ax
  2441 000012C8 66AD                    	lodsw
  2442 000012CA 66AB                    	stosw		; original sample (R)
  2443 000012CC 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2444                                  	;mov	[previous_val_r], ax
  2445 000012CF 89C3                    	mov	ebx, eax
  2446 000012D1 31D2                    	xor	edx, edx
  2447 000012D3 31C0                    	xor	eax, eax
  2448                                  	; 16/11/2023
  2449 000012D5 49                      	dec	ecx
  2450 000012D6 7407                    	jz	short lff24s2_2
  2451 000012D8 668B06                  	mov	ax, [esi]
  2452 000012DB 668B5602                	mov	dx, [esi+2]
  2453                                  lff24s2_2:
  2454 000012DF 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2455                                  	;;mov	[next_val_l], ax
  2456                                  	;mov	ebp, eax
  2457 000012E2 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format 
  2458                                  	;mov	[next_val_r], dx
  2459 000012E5 660305[B9200000]        	add	ax, [previous_val_l]
  2460 000012EC 66D1D8                  	rcr	ax, 1
  2461 000012EF 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2462 000012F2 66AB                    	stosw		; this is interpolated sample (L)
  2463                                  	;mov	ax, [next_val_r]
  2464 000012F4 89D0                    	mov	eax, edx
  2465                                  	;add	ax, [previous_val_r]
  2466 000012F6 6601D8                  	add	ax, bx
  2467 000012F9 66D1D8                  	rcr	ax, 1
  2468 000012FC 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2469 000012FF 66AB                    	stosw		; this is interpolated sample (R)
  2470                                  	
  2471                                  	; 24 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2472 00001301 09C9                    	or	ecx, ecx
  2473 00001303 75B6                    	jnz	short lff24s2_1
  2474 00001305 E92BF8FFFF              	jmp	lff24_3
  2475                                  
  2476                                  ; .....................
  2477                                  
  2478                                  load_32khz_mono_8_bit:
  2479                                  	; 15/11/2023
  2480 0000130A F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2481                                  					; last of the file?
  2482 00001311 7402                    	jz	short lff32m_0		; no
  2483 00001313 F9                      	stc
  2484 00001314 C3                      	retn
  2485                                  
  2486                                  lff32m_0:
  2487 00001315 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2488                                          ;mov	edx, [loadsize]
  2489                                  
  2490                                  	; esi = buffer address
  2491                                  	;; edx = buffer size
  2492                                  
  2493                                  	; load file into memory
  2494                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000131A 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001320 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001322 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001328 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000132D CD40                <1>  int 40h
  2495 0000132F 7247                    	jc	short lff32m_7 ; error !
  2496                                  
  2497 00001331 BF[00800000]            	mov	edi, audio_buffer
  2498                                  	
  2499 00001336 21C0                    	and	eax, eax
  2500 00001338 7505                    	jnz	short lff32m_8
  2501 0000133A E90AF8FFFF              	jmp	lff32_eof
  2502                                  
  2503                                  lff32m_8:
  2504 0000133F 89C1                    	mov	ecx, eax	; byte count
  2505                                  lff32m_1:
  2506 00001341 AC                      	lodsb
  2507                                  	;mov	[previous_val], al
  2508 00001342 88C3                    	mov	bl, al
  2509 00001344 2C80                    	sub	al, 80h
  2510 00001346 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2511 0000134A 66AB                    	stosw		; original sample (left channel)
  2512 0000134C 66AB                    	stosw		; original sample (right channel)
  2513                                  	;xor	eax, eax
  2514 0000134E B080                    	mov	al, 80h
  2515 00001350 49                      	dec	ecx
  2516 00001351 7402                    	jz	short lff32m_2
  2517 00001353 8A06                    	mov	al, [esi]
  2518                                  lff32m_2:
  2519                                  	;;mov	[next_val], al
  2520                                  	;mov	bh, al
  2521                                  	;add	al, [previous_val]
  2522 00001355 00D8                    	add	al, bl
  2523 00001357 D0D8                    	rcr	al, 1
  2524 00001359 2C80                    	sub	al, 80h
  2525 0000135B 66C1E008                	shl	ax, 8
  2526 0000135F 66AB                    	stosw		; this is interpolated sample (L)
  2527 00001361 66AB                    	stosw		; this is interpolated sample (R)
  2528                                  	
  2529                                  	; different than 8-16-24 kHZ !
  2530                                  	; 'original-interpolated-original' trio samples 
  2531 00001363 E30E                    	jecxz	lff32m_3
  2532                                  
  2533 00001365 AC                      	lodsb
  2534 00001366 2C80                    	sub	al, 80h
  2535 00001368 66C1E008                	shl	ax, 8
  2536 0000136C 66AB                    	stosw		; original sample (left channel)
  2537 0000136E 66AB                    	stosw		; original sample (right channel)
  2538                                  
  2539                                  	; 32 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2540 00001370 49                      	dec	ecx
  2541 00001371 75CE                    	jnz	short lff32m_1
  2542                                  lff32m_3:
  2543 00001373 E9BDF7FFFF              	jmp	lff32_3
  2544                                  
  2545                                  lff32m_7:
  2546                                  lff32s_7:
  2547 00001378 E9D5F7FFFF              	jmp	lff32_5  ; error
  2548                                  
  2549                                  load_32khz_stereo_8_bit:
  2550                                  	; 15/11/2023
  2551 0000137D F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2552                                  					; last of the file?
  2553 00001384 7402                    	jz	short lff32s_0		; no
  2554 00001386 F9                      	stc
  2555 00001387 C3                      	retn
  2556                                  
  2557                                  lff32s_0:
  2558 00001388 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2559                                          ;mov	edx, [loadsize]
  2560                                  
  2561                                  	; esi = buffer address
  2562                                  	;; edx = buffer size
  2563                                  
  2564                                  	; load file into memory
  2565                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000138D 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001393 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001395 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000139B B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000013A0 CD40                <1>  int 40h
  2566 000013A2 72D4                    	jc	short lff32s_7 ; error !
  2567                                  
  2568 000013A4 BF[00800000]            	mov	edi, audio_buffer
  2569                                  	
  2570 000013A9 D1E8                    	shr	eax, 1
  2571 000013AB 7505                    	jnz	short lff32s_8
  2572 000013AD E997F7FFFF              	jmp	lff32_eof
  2573                                  
  2574                                  lff32s_8:
  2575 000013B2 89C1                    	mov	ecx, eax  ; word count
  2576                                  lff32s_1:
  2577 000013B4 AC                      	lodsb
  2578 000013B5 A2[B9200000]            	mov	[previous_val_l], al
  2579 000013BA 2C80                    	sub	al, 80h
  2580 000013BC 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2581 000013C0 66AB                    	stosw		; original sample (L)
  2582 000013C2 AC                      	lodsb
  2583 000013C3 A2[BB200000]            	mov	[previous_val_r], al
  2584 000013C8 2C80                    	sub	al, 80h
  2585 000013CA 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2586 000013CE 66AB                    	stosw		; original sample (R)
  2587                                  
  2588                                  	;xor	eax, eax
  2589 000013D0 66B88080                	mov	ax, 8080h
  2590 000013D4 49                      	dec	ecx
  2591 000013D5 7403                    	jz	short lff32s_2
  2592                                  		; convert 8 bit sample to 16 bit sample
  2593 000013D7 668B06                  	mov	ax, [esi]
  2594                                  lff32s_2:
  2595                                  	;;mov	[next_val_l], al
  2596                                  	;;mov	[next_val_r], ah
  2597                                  	;mov	bx, ax
  2598 000013DA 88E7                    	mov	bh, ah
  2599 000013DC 0205[B9200000]          	add	al, [previous_val_l]
  2600 000013E2 D0D8                    	rcr	al, 1
  2601                                  	;mov	dl, al
  2602 000013E4 2C80                    	sub	al, 80h
  2603 000013E6 66C1E008                	shl	ax, 8
  2604 000013EA 66AB                    	stosw		; this is interpolated sample (L)
  2605 000013EC 88F8                    	mov	al, bh	; [next_val_r]
  2606 000013EE 0205[BB200000]          	add	al, [previous_val_r]
  2607 000013F4 D0D8                    	rcr	al, 1
  2608                                  	;mov	dh, al
  2609 000013F6 2C80                    	sub	al, 80h
  2610 000013F8 66C1E008                	shl	ax, 8
  2611 000013FC 66AB                    	stosw		; this is interpolated sample (R)
  2612                                  
  2613                                  	; different than 8-16-24 kHZ !
  2614                                  	; 'original-interpolated-original' trio samples 
  2615 000013FE E315                    	jecxz	lff32s_3
  2616                                  
  2617 00001400 AC                      	lodsb
  2618 00001401 2C80                    	sub	al, 80h
  2619 00001403 66C1E008                	shl	ax, 8
  2620 00001407 66AB                    	stosw		; original sample (left channel)
  2621                                  
  2622 00001409 AC                      	lodsb
  2623 0000140A 2C80                    	sub	al, 80h
  2624 0000140C 66C1E008                	shl	ax, 8
  2625 00001410 66AB                    	stosw		; original sample (right channel)
  2626                                  		
  2627                                  	; 32 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2628 00001412 49                      	dec	ecx
  2629 00001413 759F                    	jnz	short lff32s_1
  2630                                  lff32s_3:
  2631 00001415 E91BF7FFFF              	jmp	lff32_3
  2632                                  
  2633                                  load_32khz_mono_16_bit:
  2634                                  	; 15/11/2023
  2635 0000141A F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2636                                  					; last of the file?
  2637 00001421 7402                    	jz	short lff32m2_0		; no
  2638 00001423 F9                      	stc
  2639 00001424 C3                      	retn
  2640                                  
  2641                                  lff32m2_0:
  2642 00001425 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2643                                          ;mov	edx, [loadsize]
  2644                                  
  2645                                  	; esi = buffer address
  2646                                  	;; edx = buffer size
  2647                                  
  2648                                  	; load file into memory
  2649                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000142A 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001430 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001432 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001438 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000143D CD40                <1>  int 40h
  2650 0000143F 723E                    	jc	short lff32m2_7 ; error !
  2651                                  
  2652 00001441 BF[00800000]            	mov	edi, audio_buffer
  2653                                  	
  2654 00001446 D1E8                    	shr	eax, 1
  2655 00001448 7505                    	jnz	short lff32m2_8
  2656 0000144A E9FAF6FFFF              	jmp	lff32_eof
  2657                                  
  2658                                  lff32m2_8:
  2659 0000144F 89C1                    	mov	ecx, eax  ; word count
  2660                                  lff32m2_1:
  2661 00001451 66AD                    	lodsw
  2662 00001453 66AB                    	stosw		; original sample (left channel)
  2663 00001455 66AB                    	stosw		; original sample (right channel)
  2664 00001457 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2665                                  	;mov	[previous_val], ax
  2666                                  	;mov	ebx, eax	
  2667                                  	;xor	eax, eax
  2668 0000145A 31DB                    	xor	ebx, ebx
  2669 0000145C 49                      	dec	ecx
  2670 0000145D 7403                    	jz	short lff32m2_2
  2671                                  	;mov	ax, [esi]
  2672 0000145F 668B1E                  	mov	bx, [esi]
  2673                                  lff32m2_2:
  2674                                  	;add	ah, 80h ; convert sound level 0 to 65535 format
  2675                                  	;mov	ebp, eax	; [next_val]
  2676                                  	;add	ax, [previous_val]
  2677                                  	; ax = [previous_val]
  2678                                  	; bx = [next_val]
  2679 00001462 6601D8                  	add	ax, bx
  2680 00001465 66D1D8                  	rcr	ax, 1
  2681 00001468 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2682 0000146B 66AB                    	stosw		; this is interpolated sample (L)
  2683 0000146D 66AB                    	stosw		; this is interpolated sample (R)
  2684                                  
  2685                                  	; different than 8-16-24 kHZ !
  2686                                  	; 'original-interpolated-original' trio samples 
  2687 0000146F E309                    	jecxz	lff32m2_3
  2688                                  
  2689 00001471 66AD                    	lodsw
  2690 00001473 66AB                    	stosw		; original sample (left channel)
  2691 00001475 66AB                    	stosw		; original sample (right channel)
  2692                                  
  2693                                  	; 32 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2694 00001477 49                      	dec	ecx
  2695 00001478 75D7                    	jnz	short lff32m2_1
  2696                                  lff32m2_3:
  2697 0000147A E9B6F6FFFF              	jmp	lff32_3
  2698                                  
  2699                                  lff32m2_7:
  2700                                  lff32s2_7:
  2701 0000147F E9CEF6FFFF              	jmp	lff32_5  ; error
  2702                                  
  2703                                  load_32khz_stereo_16_bit:
  2704                                  	; 16/11/2023
  2705                                  	; 15/11/2023
  2706 00001484 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2707                                  					; last of the file?
  2708 0000148B 7402                    	jz	short lff32s2_0		; no
  2709 0000148D F9                      	stc
  2710 0000148E C3                      	retn
  2711                                  
  2712                                  lff32s2_0:
  2713 0000148F BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2714                                          ;mov	edx, [loadsize]
  2715                                  
  2716                                  	; esi = buffer address
  2717                                  	;; edx = buffer size
  2718                                  
  2719                                  	; load file into memory
  2720                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001494 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000149A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000149C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000014A2 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000014A7 CD40                <1>  int 40h
  2721 000014A9 72D4                    	jc	short lff32s2_7 ; error !
  2722                                  
  2723 000014AB BF[00800000]            	mov	edi, audio_buffer
  2724                                  	
  2725 000014B0 C1E802                  	shr	eax, 2
  2726 000014B3 7505                    	jnz	short lff32s2_8
  2727 000014B5 E98FF6FFFF              	jmp	lff32_eof
  2728                                  
  2729                                  lff32s2_8:
  2730 000014BA 89C1                    	mov	ecx, eax ; dword count
  2731                                  lff32s2_1:
  2732 000014BC 66AD                    	lodsw
  2733 000014BE 66AB                    	stosw		; original sample (L)
  2734 000014C0 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2735 000014C3 66A3[B9200000]          	mov	[previous_val_l], ax
  2736 000014C9 66AD                    	lodsw
  2737 000014CB 66AB                    	stosw		; original sample (R)
  2738 000014CD 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2739                                  	;mov	[previous_val_r], ax
  2740 000014D0 89C3                    	mov	ebx, eax
  2741 000014D2 31D2                    	xor	edx, edx
  2742 000014D4 31C0                    	xor	eax, eax
  2743                                  	; 16/11/2023
  2744 000014D6 49                      	dec	ecx
  2745 000014D7 7407                    	jz	short lff32s2_2
  2746 000014D9 668B06                  	mov	ax, [esi]
  2747 000014DC 668B5602                	mov	dx, [esi+2]
  2748                                  lff32s2_2:
  2749 000014E0 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2750                                  	;;mov	[next_val_l], ax
  2751                                  	;mov	ebp, eax
  2752 000014E3 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format 
  2753                                  	;mov	[next_val_r], dx
  2754 000014E6 660305[B9200000]        	add	ax, [previous_val_l]
  2755 000014ED 66D1D8                  	rcr	ax, 1
  2756 000014F0 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2757 000014F3 66AB                    	stosw		; this is interpolated sample (L)
  2758                                  	;mov	ax, [next_val_r]
  2759 000014F5 89D0                    	mov	eax, edx
  2760                                  	;add	ax, [previous_val_r]
  2761 000014F7 6601D8                  	add	ax, bx
  2762 000014FA 66D1D8                  	rcr	ax, 1
  2763 000014FD 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2764 00001500 66AB                    	stosw		; this is interpolated sample (R)
  2765                                  
  2766                                  	; different than 8-16-24 kHZ !
  2767                                  	; 'original-interpolated-original' trio samples 
  2768 00001502 E30B                    	jecxz	lff32s2_3
  2769                                  
  2770 00001504 66AD                    	lodsw
  2771 00001506 66AB                    	stosw	; original sample (L)
  2772 00001508 66AD                    	lodsw
  2773 0000150A 66AB                    	stosw	; original sample (R)
  2774                                  	
  2775                                  	; 32 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2776 0000150C 49                      	dec	ecx
  2777 0000150D 75AD                    	jnz	short lff32s2_1
  2778                                  lff32s2_3:
  2779 0000150F E921F6FFFF              	jmp	lff32_3
  2780                                  
  2781                                  ; .....................
  2782                                  
  2783                                  load_22khz_mono_8_bit:
  2784                                  	; 16/11/2023
  2785 00001514 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2786                                  					; last of the file?
  2787 0000151B 7402                    	jz	short lff22m_0		; no
  2788 0000151D F9                      	stc
  2789 0000151E C3                      	retn
  2790                                  
  2791                                  lff22m_0:
  2792 0000151F BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2793                                          ;mov	edx, [loadsize]
  2794                                  
  2795                                  	; esi = buffer address
  2796                                  	;; edx = buffer size
  2797                                  
  2798                                  	; load file into memory
  2799                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001524 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000152A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000152C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001532 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001537 CD40                <1>  int 40h
  2800 00001539 725D                    	jc	short lff22m_7 ; error !
  2801                                  
  2802 0000153B BF[00800000]            	mov	edi, audio_buffer
  2803                                  	
  2804 00001540 21C0                    	and	eax, eax
  2805 00001542 7505                    	jnz	short lff22m_8
  2806 00001544 E900F6FFFF              	jmp	lff22_eof
  2807                                  
  2808                                  lff22m_8:
  2809 00001549 89C1                    	mov	ecx, eax	; byte count
  2810                                  lff22m_9:
  2811 0000154B BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  2812 00001550 C605[C1200000]03        	mov	byte [faz], 3  ; 3 steps/phases
  2813                                  lff22m_1:
  2814                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  2815 00001557 AC                      	lodsb
  2816 00001558 B280                    	mov	dl, 80h
  2817 0000155A 49                      	dec	ecx
  2818 0000155B 7402                    	jz	short lff22m_2_1
  2819 0000155D 8A16                    	mov	dl, [esi]
  2820                                  lff22m_2_1:	
  2821                                  	; al = [previous_val]
  2822                                  	; dl = [next_val]
  2823 0000155F E80F060000              	call	interpolating_3_8bit_mono ; 1 of 17
  2824 00001564 E32D                    	jecxz	lff22m_3
  2825                                  lff22m_2_2:
  2826 00001566 AC                      	lodsb
  2827 00001567 B280                    	mov	dl, 80h
  2828 00001569 49                      	dec	ecx
  2829 0000156A 7402                    	jz	short lff22m_2_3
  2830 0000156C 8A16                    	mov	dl, [esi]
  2831                                  lff22m_2_3:
  2832 0000156E E884060000               	call	interpolating_2_8bit_mono ; 2 of 17 .. 6 of 17
  2833 00001573 E31E                    	jecxz	lff22m_3
  2834 00001575 4D                      	dec	ebp
  2835 00001576 75EE                    	jnz	short lff22m_2_2
  2836                                  
  2837 00001578 A0[C1200000]            	mov	al, [faz]
  2838 0000157D FEC8                    	dec	al
  2839 0000157F 74CA                    	jz	short lff22m_9
  2840 00001581 FE0D[C1200000]          	dec	byte [faz]
  2841 00001587 BD04000000              	mov	ebp, 4
  2842 0000158C FEC8                    	dec	al
  2843 0000158E 75C7                    	jnz	short lff22m_1 ; 3:2:2:2:2 ; 7-11 of 17
  2844 00001590 45                      	inc	ebp ; 5
  2845 00001591 EBC4                    	jmp	short lff22m_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  2846                                  
  2847                                  lff22m_3:
  2848                                  lff22s_3:
  2849 00001593 E99DF5FFFF              	jmp	lff22_3	; padfill
  2850                                  		; (put zeros in the remain words of the buffer)
  2851                                  lff22m_7:
  2852                                  lff22s_7:
  2853 00001598 E9B5F5FFFF              	jmp	lff22_5  ; error
  2854                                  
  2855                                  load_22khz_stereo_8_bit:
  2856                                  	; 16/11/2023
  2857 0000159D F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2858                                  					; last of the file?
  2859 000015A4 7402                    	jz	short lff22s_0		; no
  2860 000015A6 F9                      	stc
  2861 000015A7 C3                      	retn
  2862                                  
  2863                                  lff22s_0:
  2864 000015A8 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2865                                          ;mov	edx, [loadsize]
  2866                                  
  2867                                  	; esi = buffer address
  2868                                  	;; edx = buffer size
  2869                                  
  2870                                  	; load file into memory
  2871                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000015AD 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000015B3 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000015B5 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000015BB B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000015C0 CD40                <1>  int 40h
  2872 000015C2 72D4                    	jc	short lff22s_7 ; error !
  2873                                  
  2874 000015C4 BF[00800000]            	mov	edi, audio_buffer
  2875                                  	
  2876 000015C9 D1E8                    	shr	eax, 1
  2877 000015CB 7505                    	jnz	short lff22s_8
  2878 000015CD E977F5FFFF              	jmp	lff22_eof
  2879                                  
  2880                                  lff22s_8:
  2881 000015D2 89C1                    	mov	ecx, eax	; word count
  2882                                  lff22s_9:
  2883 000015D4 BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  2884 000015D9 C605[C1200000]03        	mov	byte [faz], 3  ; 3 steps/phase
  2885                                  lff22s_1:
  2886                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  2887 000015E0 66AD                    	lodsw
  2888 000015E2 66BA8080                	mov	dx, 8080h
  2889 000015E6 49                      	dec	ecx
  2890 000015E7 7403                    	jz	short lff22s_2_1 
  2891 000015E9 668B16                  	mov	dx, [esi]
  2892                                  lff22s_2_1:	
  2893                                  	; al = [previous_val_l]
  2894                                  	; ah = [previous_val_r]
  2895                                  	; dl = [next_val_l]
  2896                                  	; dh = [next_val_r]	
  2897 000015EC E8B3050000              	call	interpolating_3_8bit_stereo ; 1 of 17 
  2898 000015F1 E3A0                    	jecxz	lff22s_3
  2899                                  lff22s_2_2:
  2900 000015F3 66AD                    	lodsw
  2901 000015F5 66BA8080                	mov	dx, 8080h
  2902 000015F9 49                      	dec	ecx
  2903 000015FA 7403                    	jz	short lff22s_2_3
  2904 000015FC 668B16                  	mov	dx, [esi]
  2905                                  lff22s_2_3:
  2906 000015FF E810060000               	call	interpolating_2_8bit_stereo ; 2 of 17 .. 6 of 17
  2907 00001604 E38D                    	jecxz	lff22s_3
  2908 00001606 4D                      	dec	ebp
  2909 00001607 75EA                    	jnz	short lff22s_2_2
  2910                                  
  2911 00001609 A0[C1200000]            	mov	al, [faz]
  2912 0000160E FEC8                    	dec	al
  2913 00001610 74C2                    	jz	short lff22s_9
  2914 00001612 FE0D[C1200000]          	dec	byte [faz]
  2915 00001618 BD04000000              	mov	ebp, 4
  2916 0000161D FEC8                    	dec	al
  2917 0000161F 75BF                    	jnz	short lff22s_1 ; 3:2:2:2:2 ; 7-11 of 17
  2918 00001621 45                      	inc	ebp ; 5
  2919 00001622 EBBC                    	jmp	short lff22s_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  2920                                  
  2921                                  load_22khz_mono_16_bit:
  2922                                  	; 16/11/2023
  2923 00001624 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2924                                  					; last of the file?
  2925 0000162B 7402                    	jz	short lff22m2_0		; no
  2926 0000162D F9                      	stc
  2927 0000162E C3                      	retn
  2928                                  
  2929                                  lff22m2_0:
  2930 0000162F BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2931                                          ;mov	edx, [loadsize]
  2932                                  
  2933                                  	; esi = buffer address
  2934                                  	;; edx = buffer size
  2935                                  
  2936                                  	; load file into memory
  2937                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001634 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000163A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000163C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001642 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001647 CD40                <1>  int 40h
  2938 00001649 7261                    	jc	short lff22m2_7 ; error !
  2939                                  
  2940 0000164B BF[00800000]            	mov	edi, audio_buffer
  2941                                  	
  2942 00001650 D1E8                    	shr	eax, 1
  2943 00001652 7505                    	jnz	short lff22m2_8
  2944 00001654 E9F0F4FFFF              	jmp	lff22_eof
  2945                                  
  2946                                  lff22m2_8:
  2947 00001659 89C1                    	mov	ecx, eax	; word count
  2948                                  lff22m2_9:
  2949 0000165B BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  2950 00001660 C605[C1200000]03        	mov	byte [faz], 3  ; 3 steps/phases
  2951                                  lff22m2_1:
  2952                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  2953 00001667 66AD                    	lodsw
  2954 00001669 31D2                    	xor	edx, edx
  2955 0000166B 49                      	dec	ecx
  2956 0000166C 7403                    	jz	short lff22m2_2_1
  2957 0000166E 668B16                  	mov	dx, [esi]
  2958                                  lff22m2_2_1:	
  2959                                  	; ax = [previous_val]
  2960                                  	; dx = [next_val]
  2961 00001671 E8CF050000              	call	interpolating_3_16bit_mono ; 1 of 17
  2962 00001676 E32F                    	jecxz	lff22m2_3
  2963                                  lff22m2_2_2:
  2964 00001678 66AD                    	lodsw
  2965 0000167A 31D2                    	xor	edx, edx
  2966 0000167C 49                      	dec	ecx
  2967 0000167D 7403                    	jz	short lff22m2_2_3
  2968 0000167F 668B16                  	mov	dx, [esi]
  2969                                  lff22m2_2_3:
  2970 00001682 E851060000               	call	interpolating_2_16bit_mono ; 2 of 17 .. 6 of 17
  2971 00001687 E31E                    	jecxz	lff22m2_3
  2972 00001689 4D                      	dec	ebp
  2973 0000168A 75EC                    	jnz	short lff22m2_2_2
  2974                                  
  2975 0000168C A0[C1200000]            	mov	al, [faz]
  2976 00001691 FEC8                    	dec	al
  2977 00001693 74C6                    	jz	short lff22m2_9
  2978 00001695 FE0D[C1200000]          	dec	byte [faz]
  2979 0000169B BD04000000              	mov	ebp, 4
  2980 000016A0 FEC8                    	dec	al
  2981 000016A2 75C3                    	jnz	short lff22m2_1 ; 3:2:2:2:2 ; 7-11 of 17
  2982 000016A4 45                      	inc	ebp ; 5
  2983 000016A5 EBC0                    	jmp	short lff22m2_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  2984                                  
  2985                                  lff22m2_3:
  2986                                  lff22s2_3:
  2987 000016A7 E989F4FFFF              	jmp	lff22_3	; padfill
  2988                                  		; (put zeros in the remain words of the buffer)
  2989                                  lff22m2_7:
  2990                                  lff22s2_7:
  2991 000016AC E9A1F4FFFF              	jmp	lff22_5  ; error
  2992                                  
  2993                                  load_22khz_stereo_16_bit:
  2994                                  	; 16/11/2023
  2995 000016B1 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2996                                  					; last of the file?
  2997 000016B8 7402                    	jz	short lff22s2_0		; no
  2998 000016BA F9                      	stc
  2999 000016BB C3                      	retn
  3000                                  
  3001                                  lff22s2_0:
  3002 000016BC BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3003                                          ;mov	edx, [loadsize]
  3004                                  
  3005                                  	; esi = buffer address
  3006                                  	;; edx = buffer size
  3007                                  
  3008                                  	; load file into memory
  3009                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000016C1 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000016C7 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000016C9 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000016CF B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000016D4 CD40                <1>  int 40h
  3010 000016D6 72D4                    	jc	short lff22s2_7 ; error !
  3011                                  
  3012 000016D8 BF[00800000]            	mov	edi, audio_buffer
  3013                                  	
  3014 000016DD C1E802                  	shr	eax, 2	; dword (left chan word + right chan word)
  3015 000016E0 7505                    	jnz	short lff22s2_8
  3016 000016E2 E962F4FFFF              	jmp	lff22_eof
  3017                                  
  3018                                  lff22s2_8:
  3019 000016E7 89C1                    	mov	ecx, eax	; dword count
  3020                                  lff22s2_9:
  3021 000016E9 BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  3022 000016EE C605[C1200000]03        	mov	byte [faz], 3  ; 3 steps/phase
  3023                                  lff22s2_1:
  3024                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  3025 000016F5 66AD                    	lodsw
  3026 000016F7 89C3                    	mov	ebx, eax
  3027 000016F9 66AD                    	lodsw
  3028 000016FB 8B16                    	mov	edx, [esi]
  3029 000016FD 668915[BD200000]        	mov	[next_val_l], dx
  3030                                  	; 26/11/2023
  3031 00001704 C1EA10                  	shr	edx, 16
  3032 00001707 49                      	dec	ecx
  3033 00001708 7509                    	jnz	short lff22s2_2_1
  3034 0000170A 31D2                    	xor	edx, edx ; 0
  3035 0000170C 668915[BD200000]        	mov	[next_val_l], dx
  3036                                  lff22s2_2_1:
  3037                                  	; bx = [previous_val_l]
  3038                                  	; ax = [previous_val_r]
  3039                                  	; [next_val_l]
  3040                                  	; dx = [next_val_r]
  3041 00001713 E85D050000              	call	interpolating_3_16bit_stereo ; 1 of 17 
  3042 00001718 E38D                    	jecxz	lff22s2_3
  3043                                  lff22s2_2_2:
  3044 0000171A 66AD                    	lodsw
  3045 0000171C 89C3                    	mov	ebx, eax
  3046 0000171E 66AD                    	lodsw
  3047 00001720 8B16                    	mov	edx, [esi]
  3048 00001722 668915[BD200000]        	mov	[next_val_l], dx
  3049                                  	; 26/11/2023
  3050 00001729 C1EA10                  	shr	edx, 16
  3051 0000172C 49                      	dec	ecx
  3052 0000172D 7509                    	jnz	short lff22s2_2_3
  3053 0000172F 31D2                    	xor	edx, edx ; 0
  3054 00001731 668915[BD200000]        	mov	[next_val_l], dx
  3055                                  lff22s2_2_3:
  3056 00001738 E8B3050000               	call	interpolating_2_16bit_stereo ; 2 of 17 .. 6 of 17
  3057 0000173D E31E                    	jecxz	lff22s2_2_4
  3058                                  
  3059 0000173F 4D                      	dec	ebp
  3060 00001740 75D8                    	jnz	short lff22s2_2_2
  3061                                  
  3062 00001742 A0[C1200000]            	mov	al, [faz]
  3063 00001747 FEC8                    	dec	al
  3064 00001749 749E                    	jz	short lff22s2_9
  3065 0000174B FE0D[C1200000]          	dec	byte [faz]
  3066 00001751 BD04000000              	mov	ebp, 4
  3067 00001756 FEC8                    	dec	al
  3068 00001758 759B                    	jnz	short lff22s2_1 ; 3:2:2:2:2 ; 7-11 of 17
  3069 0000175A 45                      	inc	ebp ; 5
  3070 0000175B EB98                    	jmp	short lff22s2_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  3071                                  
  3072                                  lff22s2_2_4:
  3073                                  	; 26/11/2023
  3074 0000175D E9D3F3FFFF              	jmp	lff22_3	; padfill
  3075                                  
  3076                                  ; .....................
  3077                                  
  3078                                  load_11khz_mono_8_bit:
  3079                                  	; 18/11/2023
  3080 00001762 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3081                                  					; last of the file?
  3082 00001769 7402                    	jz	short lff11m_0		; no
  3083 0000176B F9                      	stc
  3084 0000176C C3                      	retn
  3085                                  
  3086                                  lff11m_0:
  3087 0000176D BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3088                                          ;mov	edx, [loadsize]
  3089                                  
  3090                                  	; esi = buffer address
  3091                                  	;; edx = buffer size
  3092                                  
  3093                                  	; load file into memory
  3094                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001772 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001778 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000177A 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001780 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001785 CD40                <1>  int 40h
  3095 00001787 7247                    	jc	short lff11m_7 ; error !
  3096                                  
  3097 00001789 BF[00800000]            	mov	edi, audio_buffer
  3098                                  	
  3099 0000178E 21C0                    	and	eax, eax
  3100 00001790 7505                    	jnz	short lff11m_8
  3101 00001792 E9B2F3FFFF              	jmp	lff11_eof
  3102                                  
  3103                                  lff11m_8:
  3104 00001797 89C1                    	mov	ecx, eax		; byte count
  3105                                  lff11m_9:
  3106 00001799 BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3107                                  lff11m_1:
  3108                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3109 0000179E AC                      	lodsb
  3110 0000179F B280                    	mov	dl, 80h
  3111 000017A1 49                      	dec	ecx
  3112 000017A2 7402                    	jz	short lff11m_2_1
  3113 000017A4 8A16                    	mov	dl, [esi]
  3114                                  lff11m_2_1:	
  3115                                  	; al = [previous_val]
  3116                                  	; dl = [next_val]
  3117 000017A6 E876050000              	call	interpolating_5_8bit_mono
  3118 000017AB E328                    	jecxz	lff11m_3
  3119                                  lff11m_2_2:
  3120 000017AD AC                      	lodsb
  3121 000017AE B280                    	mov	dl, 80h
  3122 000017B0 49                      	dec	ecx
  3123 000017B1 7402                    	jz	short lff11m_2_3
  3124 000017B3 8A16                    	mov	dl, [esi]
  3125                                  lff11m_2_3:
  3126 000017B5 E873060000               	call	interpolating_4_8bit_mono
  3127 000017BA E319                    	jecxz	lff11m_3
  3128                                  
  3129 000017BC 4D                      	dec	ebp
  3130 000017BD 74DA                    	jz	short lff11m_9
  3131                                  
  3132 000017BF AC                      	lodsb
  3133 000017C0 B280                    	mov	dl, 80h
  3134 000017C2 49                      	dec	ecx
  3135 000017C3 7402                    	jz	short lff11m_2_4
  3136 000017C5 8A16                    	mov	dl, [esi]
  3137                                  lff11m_2_4:
  3138 000017C7 E861060000              	call	interpolating_4_8bit_mono
  3139 000017CC E307                    	jecxz	lff11m_3
  3140 000017CE EBCE                    	jmp	short lff11m_1
  3141                                  
  3142                                  lff11m_7:
  3143                                  lff11s_7:
  3144 000017D0 E97DF3FFFF              	jmp	lff11_5  ; error
  3145                                  
  3146                                  lff11m_3:
  3147                                  lff11s_3:
  3148 000017D5 E95BF3FFFF              	jmp	lff11_3	; padfill
  3149                                  		; (put zeros in the remain words of the buffer)
  3150                                  
  3151                                  load_11khz_stereo_8_bit:
  3152                                  	; 18/11/2023
  3153 000017DA F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3154                                  					; last of the file?
  3155 000017E1 7402                    	jz	short lff11s_0		; no
  3156 000017E3 F9                      	stc
  3157 000017E4 C3                      	retn
  3158                                  
  3159                                  lff11s_0:
  3160 000017E5 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3161                                          ;mov	edx, [loadsize]
  3162                                  
  3163                                  	; esi = buffer address
  3164                                  	;; edx = buffer size
  3165                                  
  3166                                  	; load file into memory
  3167                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000017EA 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000017F0 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000017F2 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000017F8 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000017FD CD40                <1>  int 40h
  3168 000017FF 72CF                    	jc	short lff11s_7 ; error !
  3169                                  
  3170 00001801 BF[00800000]            	mov	edi, audio_buffer
  3171                                  	
  3172 00001806 D1E8                    	shr	eax, 1
  3173 00001808 7505                    	jnz	short lff11s_8
  3174 0000180A E93AF3FFFF              	jmp	lff11_eof
  3175                                  
  3176                                  lff11s_8:
  3177 0000180F 89C1                    	mov	ecx, eax	; word count
  3178                                  lff11s_9:
  3179 00001811 BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3180                                  lff11s_1:
  3181                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3182 00001816 66AD                    	lodsw
  3183 00001818 66BA8080                	mov	dx, 8080h
  3184 0000181C 49                      	dec	ecx
  3185 0000181D 7403                    	jz	short lff11s_2_1 
  3186 0000181F 668B16                  	mov	dx, [esi]
  3187                                  lff11s_2_1:	
  3188                                  	; al = [previous_val_l]
  3189                                  	; ah = [previous_val_r]
  3190                                  	; dl = [next_val_l]
  3191                                  	; dh = [next_val_r]	
  3192 00001822 E859050000              	call	interpolating_5_8bit_stereo
  3193 00001827 E3AC                    	jecxz	lff11s_3
  3194                                  lff11s_2_2:
  3195 00001829 66AD                    	lodsw
  3196 0000182B 66BA8080                	mov	dx, 8080h
  3197 0000182F 49                      	dec	ecx
  3198 00001830 7403                    	jz	short lff11s_2_3
  3199 00001832 668B16                  	mov	dx, [esi]
  3200                                  lff11s_2_3:
  3201 00001835 E832060000               	call	interpolating_4_8bit_stereo
  3202 0000183A E399                    	jecxz	lff11s_3
  3203                                  	
  3204 0000183C 4D                      	dec	ebp
  3205 0000183D 74D2                    	jz	short lff11s_9
  3206                                  
  3207 0000183F 66AD                    	lodsw
  3208 00001841 66BA8080                	mov	dx, 8080h
  3209 00001845 49                      	dec	ecx
  3210 00001846 7403                    	jz	short lff11s_2_4
  3211 00001848 668B16                  	mov	dx, [esi]
  3212                                  lff11s_2_4:
  3213 0000184B E81C060000              	call	interpolating_4_8bit_stereo
  3214 00001850 E383                    	jecxz	lff11s_3
  3215 00001852 EBC2                    	jmp	short lff11s_1
  3216                                  
  3217                                  load_11khz_mono_16_bit:
  3218                                  	; 18/11/2023
  3219 00001854 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3220                                  					; last of the file?
  3221 0000185B 7402                    	jz	short lff11m2_0		; no
  3222 0000185D F9                      	stc
  3223 0000185E C3                      	retn
  3224                                  
  3225                                  lff11m2_0:
  3226 0000185F BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3227                                          ;mov	edx, [loadsize]
  3228                                  
  3229                                  	; esi = buffer address
  3230                                  	;; edx = buffer size
  3231                                  
  3232                                  	; load file into memory
  3233                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001864 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000186A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000186C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001872 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001877 CD40                <1>  int 40h
  3234 00001879 724D                    	jc	short lff11m2_7 ; error !
  3235                                  
  3236 0000187B BF[00800000]            	mov	edi, audio_buffer
  3237                                  	
  3238 00001880 D1E8                    	shr	eax, 1
  3239 00001882 7505                    	jnz	short lff11m2_8
  3240 00001884 E9C0F2FFFF              	jmp	lff11_eof
  3241                                  
  3242                                  lff11m2_8:
  3243 00001889 89C1                    	mov	ecx, eax	; word count
  3244                                  lff11m2_9:
  3245 0000188B BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3246                                  lff11m2_1:
  3247                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3248 00001890 66AD                    	lodsw
  3249 00001892 31D2                    	xor	edx, edx
  3250 00001894 49                      	dec	ecx
  3251 00001895 7403                    	jz	short lff11m2_2_1
  3252 00001897 668B16                  	mov	dx, [esi]
  3253                                  lff11m2_2_1:	
  3254                                  	; ax = [previous_val]
  3255                                  	; dx = [next_val]
  3256 0000189A E83A060000              	call	interpolating_5_16bit_mono
  3257 0000189F E362                    	jecxz	lff11m2_3
  3258                                  lff11m2_2_2:
  3259 000018A1 66AD                    	lodsw
  3260 000018A3 31D2                    	xor	edx, edx
  3261 000018A5 49                      	dec	ecx
  3262 000018A6 7403                    	jz	short lff11m2_2_3
  3263 000018A8 668B16                  	mov	dx, [esi]
  3264                                  lff11m2_2_3:
  3265 000018AB E853070000               	call	interpolating_4_16bit_mono
  3266 000018B0 E351                    	jecxz	lff11m2_3
  3267                                  
  3268 000018B2 4D                      	dec	ebp
  3269 000018B3 74D6                    	jz	short lff11m2_9
  3270                                  
  3271 000018B5 66AD                    	lodsw
  3272 000018B7 31D2                    	xor	edx, edx
  3273 000018B9 49                      	dec	ecx
  3274 000018BA 7403                    	jz	short lff11m2_2_4
  3275 000018BC 668B16                  	mov	dx, [esi]
  3276                                  lff11m2_2_4:
  3277 000018BF E83F070000               	call	interpolating_4_16bit_mono
  3278 000018C4 E33D                    	jecxz	lff11m2_3
  3279 000018C6 EBC8                    	jmp	short lff11m2_1
  3280                                  
  3281                                  lff11m2_7:
  3282                                  lff11s2_7:
  3283 000018C8 E985F2FFFF              	jmp	lff11_5  ; error
  3284                                  
  3285                                  load_11khz_stereo_16_bit:
  3286                                  	; 18/11/2023
  3287 000018CD F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3288                                  					; last of the file?
  3289 000018D4 7402                    	jz	short lff11s2_0		; no
  3290 000018D6 F9                      	stc
  3291 000018D7 C3                      	retn
  3292                                  
  3293                                  lff11s2_0:
  3294 000018D8 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3295                                          ;mov	edx, [loadsize]
  3296                                  
  3297                                  	; esi = buffer address
  3298                                  	;; edx = buffer size
  3299                                  
  3300                                  	; load file into memory
  3301                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000018DD 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000018E3 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000018E5 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000018EB B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000018F0 CD40                <1>  int 40h
  3302 000018F2 72D4                    	jc	short lff11s2_7 ; error !
  3303                                  
  3304 000018F4 BF[00800000]            	mov	edi, audio_buffer
  3305                                  	
  3306 000018F9 C1E802                  	shr	eax, 2	; dword (left chan word + right chan word)
  3307 000018FC 750A                    	jnz	short lff11s2_8
  3308 000018FE E946F2FFFF              	jmp	lff11_eof
  3309                                  
  3310                                  lff11m2_3:
  3311                                  lff11s2_3:
  3312 00001903 E92DF2FFFF              	jmp	lff11_3	; padfill
  3313                                  		; (put zeros in the remain words of the buffer)
  3314                                  
  3315                                  lff11s2_8:
  3316 00001908 89C1                    	mov	ecx, eax	; dword count
  3317                                  lff11s2_9:
  3318 0000190A BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3319                                  lff11s2_1:
  3320                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3321 0000190F 66AD                    	lodsw
  3322 00001911 89C3                    	mov	ebx, eax
  3323 00001913 66AD                    	lodsw
  3324 00001915 8B16                    	mov	edx, [esi]
  3325 00001917 8915[BD200000]          	mov	[next_val_l], edx
  3326                                  	; 26/11/2023
  3327 0000191D C1EA10                  	shr	edx, 16
  3328                                  	;mov	[next_val_r], dx
  3329 00001920 49                      	dec	ecx
  3330 00001921 7509                    	jnz	short lff11s2_2_1
  3331 00001923 31D2                    	xor	edx, edx ; 0
  3332 00001925 668915[BD200000]        	mov	[next_val_l], dx
  3333                                  	;mov	[next_val_r], dx
  3334                                  lff11s2_2_1:
  3335                                  	; bx = [previous_val_l]
  3336                                  	; ax = [previous_val_r]
  3337                                  	; [next_val_l]
  3338                                  	; dx = [next_val_r]
  3339 0000192C E803060000              	call	interpolating_5_16bit_stereo
  3340 00001931 E3D0                    	jecxz	lff11s2_3
  3341                                  lff11s2_2_2:
  3342 00001933 66AD                    	lodsw
  3343 00001935 89C3                    	mov	ebx, eax
  3344 00001937 66AD                    	lodsw
  3345 00001939 8B16                    	mov	edx, [esi]
  3346 0000193B 668915[BD200000]        	mov	[next_val_l], dx
  3347                                  	; 26/11/2023
  3348 00001942 C1EA10                  	shr	edx, 16
  3349                                  	;mov	[next_val_r], dx
  3350 00001945 49                      	dec	ecx
  3351 00001946 7509                    	jnz	short lff11s2_2_3
  3352 00001948 31D2                    	xor	edx, edx ; 0
  3353 0000194A 668915[BD200000]        	mov	[next_val_l], dx
  3354                                  	;mov	[next_val_r], dx
  3355                                  lff11s2_2_3:
  3356 00001951 E8E6060000               	call	interpolating_4_16bit_stereo
  3357 00001956 E3AB                    	jecxz	lff11s2_3
  3358                                  	
  3359 00001958 4D                      	dec	ebp
  3360 00001959 74AF                    	jz	short lff11s2_9
  3361                                  
  3362 0000195B 66AD                    	lodsw
  3363 0000195D 89C3                    	mov	ebx, eax
  3364 0000195F 66AD                    	lodsw
  3365 00001961 8B16                    	mov	edx, [esi]
  3366 00001963 668915[BD200000]        	mov	[next_val_l], dx
  3367                                  	; 26/11/2023
  3368 0000196A C1EA10                  	shr	edx, 16
  3369                                  	;mov	[next_val_r], dx
  3370 0000196D 49                      	dec	ecx
  3371 0000196E 7509                    	jnz	short lff11s2_2_4
  3372 00001970 31D2                    	xor	edx, edx ; 0
  3373 00001972 668915[BD200000]        	mov	[next_val_l], dx
  3374                                  	;mov	[next_val_r], dx
  3375                                  lff11s2_2_4:
  3376 00001979 E8BE060000               	call	interpolating_4_16bit_stereo
  3377 0000197E E383                    	jecxz	lff11s2_3
  3378 00001980 EB8D                    	jmp	short lff11s2_1
  3379                                  
  3380                                  ; .....................
  3381                                  
  3382                                  load_44khz_mono_8_bit:
  3383                                  	; 18/11/2023
  3384 00001982 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3385                                  					; last of the file?
  3386 00001989 7402                    	jz	short lff44m_0		; no
  3387 0000198B F9                      	stc
  3388 0000198C C3                      	retn
  3389                                  
  3390                                  lff44m_0:
  3391 0000198D BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3392                                          ;mov	edx, [loadsize]
  3393                                  
  3394                                  	; esi = buffer address
  3395                                  	;; edx = buffer size
  3396                                  
  3397                                  	; load file into memory
  3398                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001992 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001998 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000199A 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000019A0 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000019A5 CD40                <1>  int 40h
  3399 000019A7 7250                    	jc	short lff44m_7 ; error !
  3400                                  
  3401 000019A9 BF[00800000]            	mov	edi, audio_buffer
  3402                                  	
  3403 000019AE 21C0                    	and	eax, eax
  3404 000019B0 7505                    	jnz	short lff44m_8
  3405 000019B2 E992F1FFFF              	jmp	lff44_eof
  3406                                  
  3407                                  lff44m_8:
  3408 000019B7 89C1                    	mov	ecx, eax	; byte count
  3409                                  lff44m_9:
  3410 000019B9 BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3411 000019BE C605[C1200000]02        	mov	byte [faz], 2  ; 2 steps/phases
  3412                                  lff44m_1:
  3413                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3414                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3415 000019C5 AC                      	lodsb
  3416 000019C6 B280                    	mov	dl, 80h
  3417 000019C8 49                      	dec	ecx
  3418 000019C9 7402                    	jz	short lff44m_2_1
  3419 000019CB 8A16                    	mov	dl, [esi]
  3420                                  lff44m_2_1:	
  3421                                  	; al = [previous_val]
  3422                                  	; dl = [next_val]
  3423 000019CD E825020000              	call	interpolating_2_8bit_mono
  3424 000019D2 E320                    	jecxz	lff44m_3
  3425                                  lff44m_2_2:
  3426 000019D4 AC                      	lodsb
  3427 000019D5 2C80                    	sub	al, 80h
  3428 000019D7 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3429 000019DB 66AB                    	stosw		; (L)
  3430 000019DD 66AB                    	stosw		; (R)	
  3431                                  
  3432 000019DF 49                      	dec	ecx
  3433 000019E0 7412                    	jz	short lff44m_3	
  3434 000019E2 4D                      	dec	ebp
  3435 000019E3 75EF                    	jnz	short lff44m_2_2
  3436                                  	
  3437 000019E5 FE0D[C1200000]          	dec	byte [faz]
  3438 000019EB 74CC                    	jz	short lff44m_9 
  3439 000019ED BD0B000000              	mov	ebp, 11
  3440 000019F2 EBD1                    	jmp	short lff44m_1
  3441                                  
  3442                                  lff44m_3:
  3443                                  lff44s_3:
  3444 000019F4 E93CF1FFFF              	jmp	lff44_3	; padfill
  3445                                  		; (put zeros in the remain words of the buffer)
  3446                                  lff44m_7:
  3447                                  lff44s_7:
  3448 000019F9 E954F1FFFF              	jmp	lff44_5  ; error
  3449                                  
  3450                                  load_44khz_stereo_8_bit:
  3451                                  	; 16/11/2023
  3452 000019FE F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3453                                  					; last of the file?
  3454 00001A05 7402                    	jz	short lff44s_0		; no
  3455 00001A07 F9                      	stc
  3456 00001A08 C3                      	retn
  3457                                  
  3458                                  lff44s_0:
  3459 00001A09 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3460                                          ;mov	edx, [loadsize]
  3461                                  
  3462                                  	; esi = buffer address
  3463                                  	;; edx = buffer size
  3464                                  
  3465                                  	; load file into memory
  3466                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001A0E 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001A14 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001A16 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001A1C B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001A21 CD40                <1>  int 40h
  3467 00001A23 72D4                    	jc	short lff44s_7 ; error !
  3468                                  
  3469 00001A25 BF[00800000]            	mov	edi, audio_buffer
  3470                                  	
  3471 00001A2A D1E8                    	shr	eax, 1
  3472 00001A2C 7505                    	jnz	short lff44s_8
  3473 00001A2E E916F1FFFF              	jmp	lff44_eof
  3474                                  
  3475                                  lff44s_8:
  3476 00001A33 89C1                    	mov	ecx, eax	; word count
  3477                                  lff44s_9:
  3478 00001A35 BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3479 00001A3A C605[C1200000]02        	mov	byte [faz], 2  ; 2 steps/phase
  3480                                  lff44s_1:
  3481                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3482                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3483 00001A41 66AD                    	lodsw
  3484 00001A43 66BA8080                	mov	dx, 8080h
  3485 00001A47 49                      	dec	ecx
  3486 00001A48 7403                    	jz	short lff44s_2_1 
  3487 00001A4A 668B16                  	mov	dx, [esi]
  3488                                  lff44s_2_1:	
  3489                                  	; al = [previous_val_l]
  3490                                  	; ah = [previous_val_r]
  3491                                  	; dl = [next_val_l]
  3492                                  	; dh = [next_val_r]	
  3493 00001A4D E8C2010000              	call	interpolating_2_8bit_stereo
  3494 00001A52 E3A0                    	jecxz	lff44s_3
  3495                                  lff44s_2_2:
  3496 00001A54 AC                      	lodsb
  3497 00001A55 2C80                    	sub	al, 80h
  3498 00001A57 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3499 00001A5B 66AB                    	stosw		; (L)
  3500 00001A5D AC                      	lodsb
  3501 00001A5E 2C80                    	sub	al, 80h
  3502 00001A60 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3503 00001A64 66AB                    	stosw		; (R)
  3504                                  
  3505 00001A66 49                      	dec	ecx
  3506 00001A67 748B                    	jz	short lff44s_3	
  3507 00001A69 4D                      	dec	ebp
  3508 00001A6A 75E8                    	jnz	short lff44s_2_2
  3509                                  	
  3510 00001A6C FE0D[C1200000]          	dec	byte [faz]
  3511 00001A72 74C1                    	jz	short lff44s_9 
  3512 00001A74 BD0B000000              	mov	ebp, 11
  3513 00001A79 EBC6                    	jmp	short lff44s_1
  3514                                  
  3515                                  load_44khz_mono_16_bit:
  3516                                  	; 18/11/2023
  3517 00001A7B F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3518                                  					; last of the file?
  3519 00001A82 7402                    	jz	short lff44m2_0		; no
  3520 00001A84 F9                      	stc
  3521 00001A85 C3                      	retn
  3522                                  
  3523                                  lff44m2_0:
  3524 00001A86 BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3525                                          ;mov	edx, [loadsize]
  3526                                  
  3527                                  	; esi = buffer address
  3528                                  	;; edx = buffer size
  3529                                  
  3530                                  	; load file into memory
  3531                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001A8B 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001A91 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001A93 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001A99 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001A9E CD40                <1>  int 40h
  3532 00001AA0 724D                    	jc	short lff44m2_7 ; error !
  3533                                  
  3534 00001AA2 BF[00800000]            	mov	edi, audio_buffer
  3535                                  	
  3536 00001AA7 D1E8                    	shr	eax, 1
  3537 00001AA9 7505                    	jnz	short lff44m2_8
  3538 00001AAB E999F0FFFF              	jmp	lff44_eof
  3539                                  
  3540                                  lff44m2_8:
  3541 00001AB0 89C1                    	mov	ecx, eax	; word count
  3542                                  lff44m2_9:
  3543 00001AB2 BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3544 00001AB7 C605[C1200000]02        	mov	byte [faz], 2  ; 2 steps/phases
  3545                                  lff44m2_1:
  3546                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3547                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3548 00001ABE 66AD                    	lodsw
  3549 00001AC0 31D2                    	xor	edx, edx
  3550 00001AC2 49                      	dec	ecx
  3551 00001AC3 7403                    	jz	short lff44m2_2_1
  3552 00001AC5 668B16                  	mov	dx, [esi]
  3553                                  lff44m2_2_1:	
  3554                                  	; ax = [previous_val]
  3555                                  	; dx = [next_val]
  3556 00001AC8 E80B020000              	call	interpolating_2_16bit_mono
  3557 00001ACD E31B                    	jecxz	lff44m2_3
  3558                                  lff44m2_2_2:
  3559 00001ACF 66AD                    	lodsw
  3560 00001AD1 66AB                    	stosw		; (L)eft Channel
  3561 00001AD3 66AB                    	stosw		; (R)ight Channel
  3562                                  
  3563 00001AD5 49                      	dec	ecx
  3564 00001AD6 7412                    	jz	short lff44m2_3	
  3565 00001AD8 4D                      	dec	ebp
  3566 00001AD9 75F4                    	jnz	short lff44m2_2_2
  3567                                  	
  3568 00001ADB FE0D[C1200000]          	dec	byte [faz]
  3569 00001AE1 74CF                    	jz	short lff44m2_9 
  3570 00001AE3 BD0B000000              	mov	ebp, 11
  3571 00001AE8 EBD4                    	jmp	short lff44m2_1
  3572                                  
  3573                                  lff44m2_3:
  3574                                  lff44s2_3:
  3575 00001AEA E946F0FFFF              	jmp	lff44_3	; padfill
  3576                                  		; (put zeros in the remain words of the buffer)
  3577                                  lff44m2_7:
  3578                                  lff44s2_7:
  3579 00001AEF E95EF0FFFF              	jmp	lff44_5  ; error
  3580                                  
  3581                                  load_44khz_stereo_16_bit:
  3582                                  	; 18/11/2023
  3583 00001AF4 F605[F4650000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3584                                  					; last of the file?
  3585 00001AFB 7402                    	jz	short lff44s2_0		; no
  3586 00001AFD F9                      	stc
  3587 00001AFE C3                      	retn
  3588                                  
  3589                                  lff44s2_0:
  3590 00001AFF BE[00000400]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3591                                          ;mov	edx, [loadsize]
  3592                                  
  3593                                  	; esi = buffer address
  3594                                  	;; edx = buffer size
  3595                                  
  3596                                  	; load file into memory
  3597                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001B04 8B1D[DF620000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001B0A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001B0C 8B15[DD030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001B12 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001B17 CD40                <1>  int 40h
  3598 00001B19 72D4                    	jc	short lff44s2_7 ; error !
  3599                                  
  3600 00001B1B BF[00800000]            	mov	edi, audio_buffer
  3601                                  	
  3602 00001B20 C1E802                  	shr	eax, 2	; dword (left chan word + right chan word)
  3603 00001B23 7505                    	jnz	short lff44s2_8
  3604 00001B25 E91FF0FFFF              	jmp	lff44_eof
  3605                                  
  3606                                  lff44s2_8:
  3607 00001B2A 89C1                    	mov	ecx, eax	; dword count
  3608                                  lff44s2_9:
  3609 00001B2C BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3610 00001B31 C605[C1200000]02        	mov	byte [faz], 2  ; 2 steps/phase
  3611                                  lff44s2_1:
  3612                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3613                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3614 00001B38 66AD                    	lodsw
  3615 00001B3A 89C3                    	mov	ebx, eax
  3616 00001B3C 66AD                    	lodsw
  3617                                  	;mov	dx, [esi]
  3618                                  	;mov	[next_val_l], dx
  3619                                  	;mov	dx, [esi+2]
  3620                                  	; 26/11/2023
  3621 00001B3E 8B16                    	mov	edx, [esi]
  3622 00001B40 668915[BD200000]        	mov	[next_val_l], dx
  3623 00001B47 C1EA10                  	shr	edx, 16
  3624 00001B4A 49                      	dec	ecx
  3625 00001B4B 7509                    	jnz	short lff44s2_2_1
  3626 00001B4D 31D2                    	xor	edx, edx ; 0
  3627 00001B4F 668915[BD200000]        	mov	[next_val_l], dx
  3628                                  lff44s2_2_1:
  3629                                  	; bx = [previous_val_l]
  3630                                  	; ax = [previous_val_r]
  3631                                  	; [next_val_l]
  3632                                  	; dx = [next_val_r]
  3633 00001B56 E895010000              	call	interpolating_2_16bit_stereo
  3634 00001B5B E38D                    	jecxz	lff44s2_3
  3635                                  lff44s2_2_2:
  3636                                  	;movsw		; (L)eft Channel
  3637                                  	;movsw		; (R)ight Channel
  3638 00001B5D A5                      	movsd
  3639                                  
  3640 00001B5E 49                      	dec	ecx
  3641 00001B5F 7489                    	jz	short lff44s2_3	
  3642 00001B61 4D                      	dec	ebp
  3643 00001B62 75F9                    	jnz	short lff44s2_2_2
  3644                                  	
  3645 00001B64 FE0D[C1200000]          	dec	byte [faz]
  3646 00001B6A 74C0                    	jz	short lff44s2_9 
  3647 00001B6C BD0B000000              	mov	ebp, 11
  3648 00001B71 EBC5                    	jmp	short lff44s2_1
  3649                                  
  3650                                  ; .....................
  3651                                  
  3652                                  interpolating_3_8bit_mono:
  3653                                  	; 16/11/2023
  3654                                  	; al = [previous_val]
  3655                                  	; dl = [next_val]
  3656                                  	; original-interpolated-interpolated
  3657 00001B73 88C3                    	mov	bl, al
  3658 00001B75 2C80                    	sub	al, 80h
  3659 00001B77 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3660 00001B7B 66AB                    	stosw		; original sample (L)
  3661 00001B7D 66AB                    	stosw		; original sample (R)
  3662 00001B7F 88D8                    	mov	al, bl
  3663 00001B81 00D0                    	add	al, dl	
  3664 00001B83 D0D8                    	rcr	al, 1
  3665 00001B85 88C7                    	mov	bh, al	; interpolated middle (temporary)
  3666 00001B87 00D8                    	add	al, bl
  3667 00001B89 D0D8                    	rcr	al, 1
  3668 00001B8B 2C80                    	sub	al, 80h
  3669 00001B8D 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3670 00001B91 66AB                    	stosw		; interpolated sample 1 (L)
  3671 00001B93 66AB                    	stosw		; interpolated sample 1 (R)
  3672 00001B95 88F8                    	mov	al, bh
  3673 00001B97 00D0                    	add	al, dl	; [next_val]
  3674 00001B99 D0D8                    	rcr	al, 1
  3675 00001B9B 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3676 00001B9F 66AB                    	stosw		; interpolated sample 2 (L)
  3677 00001BA1 66AB                    	stosw		; interpolated sample 2 (R)
  3678 00001BA3 C3                      	retn
  3679                                  
  3680                                  interpolating_3_8bit_stereo:
  3681                                  	; 16/11/2023
  3682                                  	; al = [previous_val_l]
  3683                                  	; ah = [previous_val_r]
  3684                                  	; dl = [next_val_l]
  3685                                  	; dh = [next_val_r]	
  3686                                  	; original-interpolated-interpolated
  3687 00001BA4 89C3                    	mov	ebx, eax
  3688 00001BA6 2C80                    	sub	al, 80h
  3689 00001BA8 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3690 00001BAC 66AB                    	stosw		; original sample (L)
  3691 00001BAE 88F8                    	mov	al, bh
  3692 00001BB0 2C80                    	sub	al, 80h
  3693 00001BB2 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3694 00001BB6 66AB                    	stosw		; original sample (R)
  3695 00001BB8 88D8                    	mov	al, bl
  3696 00001BBA 00D0                    	add	al, dl	; [next_val_l]	
  3697 00001BBC D0D8                    	rcr	al, 1
  3698 00001BBE 50                      	push	eax ; *	; al = interpolated middle (L) (temporary)
  3699 00001BBF 00D8                    	add	al, bl	; [previous_val_l]
  3700 00001BC1 D0D8                    	rcr	al, 1
  3701 00001BC3 2C80                    	sub	al, 80h
  3702 00001BC5 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3703 00001BC9 66AB                    	stosw		; interpolated sample 1 (L)
  3704 00001BCB 88F8                    	mov	al, bh
  3705 00001BCD 00F0                    	add	al, dh	; [next_val_r]
  3706 00001BCF D0D8                    	rcr	al, 1
  3707 00001BD1 50                      	push	eax ; ** ; al = interpolated middle (R) (temporary)
  3708 00001BD2 00F8                    	add	al, bh	; [previous_val_r]
  3709 00001BD4 D0D8                    	rcr	al, 1
  3710 00001BD6 2C80                    	sub	al, 80h
  3711 00001BD8 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3712 00001BDC 66AB                    	stosw		; interpolated sample 1 (R)
  3713 00001BDE 5B                      	pop	ebx ; **
  3714 00001BDF 58                      	pop	eax ; *
  3715 00001BE0 00D0                    	add	al, dl	; [next_val_l]
  3716 00001BE2 D0D8                    	rcr	al, 1
  3717 00001BE4 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3718 00001BE8 66AB                    	stosw		; interpolated sample 2 (L)
  3719 00001BEA 88D8                    	mov	al, bl
  3720 00001BEC 00F0                    	add	al, dh	; [next_val_r]
  3721 00001BEE D0D8                    	rcr	al, 1
  3722 00001BF0 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3723 00001BF4 66AB                    	stosw		; interpolated sample 2 (R)
  3724 00001BF6 C3                      	retn
  3725                                  
  3726                                  interpolating_2_8bit_mono:
  3727                                  	; 16/11/2023
  3728                                  	; al = [previous_val]
  3729                                  	; dl = [next_val]
  3730                                  	; original-interpolated
  3731 00001BF7 88C3                    	mov	bl, al
  3732 00001BF9 2C80                    	sub	al, 80h
  3733 00001BFB 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3734 00001BFF 66AB                    	stosw		; original sample (L)
  3735 00001C01 66AB                    	stosw		; original sample (R)
  3736 00001C03 88D8                    	mov	al, bl
  3737 00001C05 00D0                    	add	al, dl	
  3738 00001C07 D0D8                    	rcr	al, 1
  3739 00001C09 2C80                    	sub	al, 80h
  3740 00001C0B 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3741 00001C0F 66AB                    	stosw		; interpolated sample (L)
  3742 00001C11 66AB                    	stosw		; interpolated sample (R)
  3743 00001C13 C3                      	retn
  3744                                  
  3745                                  interpolating_2_8bit_stereo:
  3746                                  	; 16/11/2023
  3747                                  	; al = [previous_val_l]
  3748                                  	; ah = [previous_val_r]
  3749                                  	; dl = [next_val_l]
  3750                                  	; dh = [next_val_r]	
  3751                                  	; original-interpolated
  3752 00001C14 89C3                    	mov	ebx, eax
  3753 00001C16 2C80                    	sub	al, 80h
  3754 00001C18 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3755 00001C1C 66AB                    	stosw		; original sample (L)
  3756 00001C1E 88F8                    	mov	al, bh
  3757 00001C20 2C80                    	sub	al, 80h
  3758 00001C22 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3759 00001C26 66AB                    	stosw		; original sample (R)
  3760 00001C28 88D8                    	mov	al, bl	; [previous_val_l]
  3761 00001C2A 00D0                    	add	al, dl	; [next_val_l]	
  3762 00001C2C D0D8                    	rcr	al, 1
  3763 00001C2E 2C80                    	sub	al, 80h
  3764 00001C30 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3765 00001C34 66AB                    	stosw		; interpolated sample (L)
  3766 00001C36 88F8                    	mov	al, bh
  3767 00001C38 00F0                    	add	al, dh	; [next_val_r]
  3768 00001C3A D0D8                    	rcr	al, 1
  3769 00001C3C 2C80                    	sub	al, 80h
  3770 00001C3E 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3771 00001C42 66AB                    	stosw		; interpolated sample (R)
  3772 00001C44 C3                      	retn
  3773                                  
  3774                                  interpolating_3_16bit_mono:
  3775                                  	; 16/11/2023
  3776                                  	; ax = [previous_val]
  3777                                  	; dx = [next_val]
  3778                                  	; original-interpolated-interpolated
  3779                                  
  3780 00001C45 66AB                    	stosw		; original sample (L)
  3781 00001C47 66AB                    	stosw		; original sample (R)
  3782 00001C49 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  3783 00001C4C 50                      	push	eax ; *	; [previous_val]
  3784 00001C4D 80C680                  	add	dh, 80h
  3785 00001C50 6601D0                  	add	ax, dx
  3786 00001C53 66D1D8                  	rcr	ax, 1
  3787 00001C56 5B                      	pop	ebx ; *		
  3788 00001C57 93                      	xchg	ebx, eax ; bx  = interpolated middle (temporary)
  3789 00001C58 6601D8                  	add	ax, bx	; [previous_val] + interpolated middle
  3790 00001C5B 66D1D8                  	rcr	ax, 1
  3791 00001C5E 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3792 00001C61 66AB                    	stosw 		; interpolated sample 1 (L)
  3793 00001C63 66AB                    	stosw		; interpolated sample 1 (R)
  3794 00001C65 89D8                    	mov	eax, ebx
  3795 00001C67 6601D0                  	add	ax, dx	 ;interpolated middle + [next_val]
  3796 00001C6A 66D1D8                  	rcr	ax, 1
  3797 00001C6D 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3798 00001C70 66AB                    	stosw		; interpolated sample 2 (L)
  3799 00001C72 66AB                    	stosw		; interpolated sample 2 (R)
  3800 00001C74 C3                      	retn
  3801                                  
  3802                                  interpolating_3_16bit_stereo:
  3803                                  	; 16/11/2023
  3804                                  	; bx = [previous_val_l]
  3805                                  	; ax = [previous_val_r]
  3806                                  	; [next_val_l]
  3807                                  	; dx = [next_val_r]
  3808                                  	; original-interpolated-interpolated
  3809                                  
  3810 00001C75 93                      	xchg	eax, ebx
  3811 00001C76 66AB                    	stosw		; original sample (L)
  3812 00001C78 93                      	xchg	eax, ebx
  3813 00001C79 66AB                    	stosw		; original sample (R)
  3814 00001C7B 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  3815 00001C7E 50                      	push	eax ; *	; [previous_val_r]
  3816 00001C7F 80C780                  	add	bh, 80h
  3817 00001C82 8005[BE200000]80        	add	byte [next_val_l+1], 80h
  3818 00001C89 66A1[BD200000]          	mov	ax, [next_val_l]
  3819 00001C8F 6601D8                  	add	ax, bx	; [previous_val_l]
  3820 00001C92 66D1D8                  	rcr	ax, 1
  3821 00001C95 93                      	xchg	eax, ebx ; ax = [previous_val_l]	
  3822 00001C96 6601D8                  	add	ax, bx	; bx = interpolated middle (L)
  3823 00001C99 66D1D8                  	rcr	ax, 1
  3824 00001C9C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3825 00001C9F 66AB                    	stosw 		; interpolated sample 1 (L)
  3826 00001CA1 58                      	pop	eax  ; *
  3827 00001CA2 80C680                  	add	dh, 80h ; convert sound level 0 to 65535 format
  3828 00001CA5 52                      	push	edx  ; * ; [next_val_r]
  3829 00001CA6 92                      	xchg	eax, edx
  3830 00001CA7 6601D0                  	add	ax, dx	; [next_val_r] + [previous_val_r]
  3831 00001CAA 66D1D8                  	rcr	ax, 1	; / 2
  3832 00001CAD 50                      	push	eax ; ** ; interpolated middle (R)
  3833 00001CAE 6601D0                  	add	ax, dx	; + [previous_val_r]
  3834 00001CB1 66D1D8                  	rcr	ax, 1
  3835 00001CB4 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3836 00001CB7 66AB                    	stosw 		; interpolated sample 1 (R)
  3837 00001CB9 66A1[BD200000]          	mov	ax, [next_val_l]
  3838 00001CBF 6601D8                  	add	ax, bx	; + interpolated middle (L)
  3839 00001CC2 66D1D8                  	rcr	ax, 1
  3840 00001CC5 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3841 00001CC8 66AB                    	stosw 		; interpolated sample 2 (L)
  3842 00001CCA 58                      	pop	eax ; **
  3843 00001CCB 5A                      	pop	edx ; *	
  3844 00001CCC 6601D0                  	add	ax, dx	; interpolated middle + [next_val_r]
  3845 00001CCF 66D1D8                  	rcr	ax, 1	; / 2
  3846 00001CD2 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3847 00001CD5 66AB                    	stosw 		; interpolated sample 2 (L)
  3848 00001CD7 C3                      	retn
  3849                                  
  3850                                  interpolating_2_16bit_mono:
  3851                                  	; 16/11/2023
  3852                                  	; ax = [previous_val]
  3853                                  	; dx = [next_val]
  3854                                  	; original-interpolated
  3855                                  
  3856 00001CD8 66AB                    	stosw		; original sample (L)
  3857 00001CDA 66AB                    	stosw		; original sample (R)
  3858 00001CDC 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  3859 00001CDF 80C680                  	add	dh, 80h
  3860 00001CE2 6601D0                  	add	ax, dx
  3861 00001CE5 66D1D8                  	rcr	ax, 1
  3862 00001CE8 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3863 00001CEB 66AB                    	stosw		; interpolated sample (L)
  3864 00001CED 66AB                    	stosw		; interpolated sample (R)
  3865 00001CEF C3                      	retn
  3866                                  
  3867                                  interpolating_2_16bit_stereo:
  3868                                  	; 16/11/2023
  3869                                  	; bx = [previous_val_l]
  3870                                  	; ax = [previous_val_r]
  3871                                  	; [next_val_l]
  3872                                  	; dx = [next_val_r]
  3873                                  	; original-interpolated
  3874                                  
  3875 00001CF0 93                      	xchg	eax, ebx
  3876 00001CF1 66AB                    	stosw		; original sample (L)
  3877 00001CF3 93                      	xchg	eax, ebx
  3878 00001CF4 66AB                    	stosw		; original sample (R)
  3879 00001CF6 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  3880 00001CF9 80C680                  	add	dh, 80h
  3881 00001CFC 6601D0                  	add	ax, dx	; [previous_val_r] + [next_val_r]
  3882 00001CFF 66D1D8                  	rcr	ax, 1	; / 2
  3883 00001D02 50                      	push	eax ; *	; interpolated sample (R)
  3884 00001D03 66A1[BD200000]          	mov	ax, [next_val_l]
  3885 00001D09 80C480                  	add	ah, 80h
  3886 00001D0C 80C780                  	add	bh, 80h
  3887 00001D0F 6601D8                  	add	ax, bx	; [next_val_l] + [previous_val_l]
  3888 00001D12 66D1D8                  	rcr	ax, 1	; / 2		
  3889 00001D15 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3890 00001D18 66AB                    	stosw 		; interpolated sample (L)
  3891 00001D1A 58                      	pop	eax ; *	
  3892 00001D1B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  3893 00001D1E 66AB                    	stosw 		; interpolated sample (R)
  3894 00001D20 C3                      	retn
  3895                                  
  3896                                  interpolating_5_8bit_mono:
  3897                                  	; 17/11/2023
  3898                                  	; al = [previous_val]
  3899                                  	; dl = [next_val]
  3900                                  	; original-interpltd-interpltd-interpltd-interpltd
  3901 00001D21 88C3                    	mov	bl, al
  3902 00001D23 2C80                    	sub	al, 80h
  3903 00001D25 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3904 00001D29 66AB                    	stosw		; original sample (L)
  3905 00001D2B 66AB                    	stosw		; original sample (R)
  3906 00001D2D 88D8                    	mov	al, bl
  3907 00001D2F 00D0                    	add	al, dl	
  3908 00001D31 D0D8                    	rcr	al, 1
  3909 00001D33 88C7                    	mov	bh, al	; interpolated middle (temporary)
  3910 00001D35 00D8                    	add	al, bl  ; [previous_val]
  3911 00001D37 D0D8                    	rcr	al, 1 	
  3912 00001D39 88C6                    	mov	dh, al	; interpolated 1st quarter (temporary)
  3913 00001D3B 00D8                    	add	al, bl
  3914 00001D3D D0D8                    	rcr	al, 1
  3915 00001D3F 2C80                    	sub	al, 80h
  3916 00001D41 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3917 00001D45 66AB                    	stosw		; interpolated sample 1 (L)
  3918 00001D47 66AB                    	stosw		; interpolated sample 1 (R)
  3919 00001D49 88F8                    	mov	al, bh
  3920 00001D4B 00F0                    	add	al, dh
  3921 00001D4D D0D8                    	rcr	al, 1
  3922 00001D4F 2C80                    	sub	al, 80h
  3923 00001D51 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3924 00001D55 66AB                    	stosw		; interpolated sample 2 (L)
  3925 00001D57 66AB                    	stosw		; interpolated sample 2 (R)
  3926 00001D59 88F8                    	mov	al, bh
  3927 00001D5B 00D0                    	add	al, dl	; [next_val]
  3928 00001D5D D0D8                    	rcr	al, 1
  3929 00001D5F 88C6                    	mov	dh, al	; interpolated 3rd quarter (temporary)
  3930 00001D61 00F8                    	add	al, bh
  3931 00001D63 D0D8                    	rcr	al, 1
  3932 00001D65 2C80                    	sub	al, 80h
  3933 00001D67 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3934 00001D6B 66AB                    	stosw		; interpolated sample 3 (L)
  3935 00001D6D 66AB                    	stosw		; interpolated sample 3 (R)
  3936 00001D6F 88F0                    	mov	al, dh
  3937 00001D71 00D0                    	add	al, dl
  3938 00001D73 D0D8                    	rcr	al, 1
  3939 00001D75 2C80                    	sub	al, 80h
  3940 00001D77 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3941 00001D7B 66AB                    	stosw		; interpolated sample 4 (L)
  3942 00001D7D 66AB                    	stosw		; interpolated sample 4 (R)
  3943 00001D7F C3                      	retn
  3944                                  
  3945                                  interpolating_5_8bit_stereo:
  3946                                  	; 17/11/2023
  3947                                  	; al = [previous_val_l]
  3948                                  	; ah = [previous_val_r]
  3949                                  	; dl = [next_val_l]
  3950                                  	; dh = [next_val_r]	
  3951                                  	; original-interpltd-interpltd-interpltd-interpltd
  3952 00001D80 89C3                    	mov	ebx, eax
  3953 00001D82 2C80                    	sub	al, 80h
  3954 00001D84 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3955 00001D88 66AB                    	stosw		; original sample (L)
  3956 00001D8A 88F8                    	mov	al, bh
  3957 00001D8C 2C80                    	sub	al, 80h
  3958 00001D8E 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3959 00001D92 66AB                    	stosw		; original sample (R)
  3960 00001D94 52                      	push	edx ; *
  3961 00001D95 88D8                    	mov	al, bl
  3962 00001D97 00D0                    	add	al, dl	; [next_val_l]
  3963 00001D99 D0D8                    	rcr	al, 1
  3964 00001D9B 50                      	push	eax ; **	; al = interpolated middle (L) (temporary)
  3965 00001D9C 00D8                    	add	al, bl	; [previous_val_l]
  3966 00001D9E D0D8                    	rcr	al, 1
  3967 00001DA0 86C3                    	xchg	al, bl	
  3968 00001DA2 00D8                    	add	al, bl	; bl = interpolated 1st quarter (L) (temp)
  3969 00001DA4 D0D8                    	rcr	al, 1
  3970 00001DA6 2C80                    	sub	al, 80h
  3971 00001DA8 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3972 00001DAC 66AB                    	stosw		; interpolated sample 1 (L)
  3973 00001DAE 88F8                    	mov	al, bh
  3974 00001DB0 00F0                    	add	al, dh	; [next_val_r]
  3975 00001DB2 D0D8                    	rcr	al, 1
  3976 00001DB4 50                      	push	eax ; *** ; al = interpolated middle (R) (temporary)
  3977 00001DB5 00F8                    	add	al, bh	; [previous_val_r]
  3978 00001DB7 D0D8                    	rcr	al, 1
  3979 00001DB9 86C7                    	xchg	al, bh	
  3980 00001DBB 00F8                    	add	al, bh	; bh = interpolated 1st quarter (R) (temp)
  3981 00001DBD D0D8                    	rcr	al, 1
  3982 00001DBF 2C80                    	sub	al, 80h
  3983 00001DC1 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3984 00001DC5 66AB                    	stosw		; interpolated sample 1 (R)
  3985 00001DC7 5A                      	pop	edx ; ***
  3986 00001DC8 58                      	pop	eax ; **	; al = interpolated middle (L) (temporary)
  3987 00001DC9 86C3                    	xchg	al, bl	; al = interpolated 1st quarter (L) (temp)
  3988 00001DCB 00D8                    	add	al, bl	; bl = interpolated middle (L) (temporary)
  3989 00001DCD D0D8                    	rcr	al, 1
  3990 00001DCF 2C80                    	sub	al, 80h
  3991 00001DD1 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3992 00001DD5 66AB                    	stosw		; interpolated sample 2 (L)	
  3993 00001DD7 88D0                    	mov	al, dl 	; interpolated middle (R) (temporary)
  3994 00001DD9 86C7                    	xchg	al, bh	; al = interpolated 1st quarter (R) (temp)
  3995 00001DDB 00F8                    	add	al, bh	; bh = interpolated middle (R) (temporary)
  3996 00001DDD D0D8                    	rcr	al, 1
  3997 00001DDF 2C80                    	sub	al, 80h
  3998 00001DE1 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3999 00001DE5 66AB                    	stosw		; interpolated sample 2 (R)
  4000 00001DE7 5A                      	pop	edx ; *
  4001 00001DE8 88D8                    	mov	al, bl	; interpolated middle (L) (temporary)
  4002 00001DEA 00D0                    	add	al, dl	; [next_val_l]
  4003 00001DEC D0D8                    	rcr	al, 1
  4004 00001DEE 86C3                    	xchg	al, bl	; al = interpolated middle (R) (temporary)	
  4005 00001DF0 00D8                    	add	al, bl	; bl = interpolated 3rd quarter (L) (temp) 
  4006 00001DF2 D0D8                    	rcr	al, 1
  4007 00001DF4 2C80                    	sub	al, 80h
  4008 00001DF6 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4009 00001DFA 66AB                    	stosw		; interpolated sample 3 (L)
  4010 00001DFC 88F8                    	mov	al, bh	
  4011 00001DFE 00F0                    	add	al, dh	; interpolated middle (R) + [next_val_r]
  4012 00001E00 D0D8                    	rcr	al, 1
  4013 00001E02 86C7                    	xchg	al, bh	; al = interpolated middle (R)
  4014 00001E04 00F8                    	add	al, bh	; bh = interpolated 3rd quarter (R) (temp)
  4015 00001E06 D0D8                    	rcr	al, 1
  4016 00001E08 2C80                    	sub	al, 80h
  4017 00001E0A 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4018 00001E0E 66AB                    	stosw		; interpolated sample 3 (R)
  4019 00001E10 88D8                    	mov	al, bl
  4020 00001E12 00D0                    	add	al, dl	; [next_val_l]
  4021 00001E14 D0D8                    	rcr	al, 1
  4022 00001E16 2C80                    	sub	al, 80h
  4023 00001E18 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4024 00001E1C 66AB                    	stosw		; interpolated sample 4 (L)
  4025 00001E1E 88F8                    	mov	al, bh
  4026 00001E20 00F0                    	add	al, dh	; [next_val_r]
  4027 00001E22 D0D8                    	rcr	al, 1
  4028 00001E24 2C80                    	sub	al, 80h
  4029 00001E26 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4030 00001E2A 66AB                    	stosw		; interpolated sample 4 (R)
  4031 00001E2C C3                      	retn
  4032                                  
  4033                                  interpolating_4_8bit_mono:
  4034                                  	; 17/11/2023
  4035                                  	; al = [previous_val]
  4036                                  	; dl = [next_val]
  4037                                  	; original-interpolated-interpolated-interpolated
  4038 00001E2D 88C3                    	mov	bl, al
  4039 00001E2F 2C80                    	sub	al, 80h
  4040 00001E31 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4041 00001E35 66AB                    	stosw		; original sample (L)
  4042 00001E37 66AB                    	stosw		; original sample (R)
  4043 00001E39 88D8                    	mov	al, bl
  4044 00001E3B 00D0                    	add	al, dl	
  4045 00001E3D D0D8                    	rcr	al, 1
  4046 00001E3F 86C3                    	xchg	al, bl  ; al = [previous_val]
  4047 00001E41 00D8                    	add	al, bl	; bl = interpolated middle (sample 2)
  4048 00001E43 D0D8                    	rcr	al, 1 	
  4049 00001E45 2C80                    	sub	al, 80h
  4050 00001E47 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4051 00001E4B 66AB                    	stosw		; interpolated sample 1 (L)
  4052 00001E4D 66AB                    	stosw		; interpolated sample 1 (R)
  4053 00001E4F 88D8                    	mov	al, bl	; interpolated middle (sample 2)
  4054 00001E51 2C80                    	sub	al, 80h
  4055 00001E53 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4056 00001E57 66AB                    	stosw		; interpolated sample 2 (L)
  4057 00001E59 66AB                    	stosw		; interpolated sample 2 (R)
  4058 00001E5B 88D8                    	mov	al, bl
  4059 00001E5D 00D0                    	add	al, dl	; [next_val]
  4060 00001E5F D0D8                    	rcr	al, 1
  4061 00001E61 2C80                    	sub	al, 80h
  4062 00001E63 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4063 00001E67 66AB                    	stosw		; interpolated sample 3 (L)
  4064 00001E69 66AB                    	stosw		; interpolated sample 3 (R)
  4065 00001E6B C3                      	retn
  4066                                  
  4067                                  interpolating_4_8bit_stereo:
  4068                                  	; 17/11/2023
  4069                                  	; al = [previous_val_l]
  4070                                  	; ah = [previous_val_r]
  4071                                  	; dl = [next_val_l]
  4072                                  	; dh = [next_val_r]	
  4073                                  	; original-interpolated-interpolated-interpolated
  4074 00001E6C 89C3                    	mov	ebx, eax
  4075 00001E6E 2C80                    	sub	al, 80h
  4076 00001E70 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4077 00001E74 66AB                    	stosw		; original sample (L)
  4078 00001E76 88F8                    	mov	al, bh
  4079 00001E78 2C80                    	sub	al, 80h
  4080 00001E7A 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4081 00001E7E 66AB                    	stosw		; original sample (R)
  4082 00001E80 88D8                    	mov	al, bl
  4083 00001E82 00D0                    	add	al, dl	; [next_val_l]
  4084 00001E84 D0D8                    	rcr	al, 1
  4085 00001E86 86C3                    	xchg	al, bl	; al = [previous_val_l]
  4086 00001E88 00D8                    	add	al, bl	; bl = interpolated middle (L) (sample 2)
  4087 00001E8A D0D8                    	rcr	al, 1
  4088 00001E8C 2C80                    	sub	al, 80h
  4089 00001E8E 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4090 00001E92 66AB                    	stosw		; interpolated sample 1 (L)
  4091 00001E94 88F8                    	mov	al, bh
  4092 00001E96 00F0                    	add	al, dh	; [next_val_r]
  4093 00001E98 D0D8                    	rcr	al, 1
  4094 00001E9A 86C7                    	xchg	al, bh	; al = [previous_val_h]
  4095 00001E9C 00F8                    	add	al, bh	; bh = interpolated middle (R) (sample 2)
  4096 00001E9E D0D8                    	rcr	al, 1
  4097 00001EA0 2C80                    	sub	al, 80h
  4098 00001EA2 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4099 00001EA6 66AB                    	stosw		; interpolated sample 1 (R)
  4100 00001EA8 88D8                    	mov	al, bl	; interpolated middle (L) (sample 2)
  4101 00001EAA 2C80                    	sub	al, 80h
  4102 00001EAC 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4103 00001EB0 66AB                    	stosw		; interpolated sample 2 (L)
  4104 00001EB2 88F8                    	mov	al, bh	; interpolated middle (L) (sample 2)
  4105 00001EB4 2C80                    	sub	al, 80h
  4106 00001EB6 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4107 00001EBA 66AB                    	stosw		; interpolated sample 2 (L)
  4108 00001EBC 88D8                    	mov	al, bl
  4109 00001EBE 00D0                    	add	al, dl	; [next_val_l]
  4110 00001EC0 D0D8                    	rcr	al, 1
  4111 00001EC2 2C80                    	sub	al, 80h
  4112 00001EC4 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4113 00001EC8 66AB                    	stosw		; interpolated sample 3 (L)
  4114 00001ECA 88F8                    	mov	al, bh
  4115 00001ECC 00F0                    	add	al, dh	; [next_val_r]
  4116 00001ECE D0D8                    	rcr	al, 1
  4117 00001ED0 2C80                    	sub	al, 80h
  4118 00001ED2 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4119 00001ED6 66AB                    	stosw		; interpolated sample 3 (R)
  4120 00001ED8 C3                      	retn
  4121                                  
  4122                                  interpolating_5_16bit_mono:
  4123                                  	; 18/11/2023
  4124                                  	; ax = [previous_val]
  4125                                  	; dx = [next_val]
  4126                                  	; original-interpltd-interpltd-interpltd-interpltd
  4127 00001ED9 66AB                    	stosw		; original sample (L)
  4128 00001EDB 66AB                    	stosw		; original sample (R)
  4129 00001EDD 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4130 00001EE0 89C3                    	mov	ebx, eax ; [previous_val]
  4131 00001EE2 80C680                  	add	dh, 80h
  4132 00001EE5 6601D0                  	add	ax, dx
  4133 00001EE8 66D1D8                  	rcr	ax, 1
  4134 00001EEB 50                      	push	eax ; *	; interpolated middle (temporary)
  4135 00001EEC 6601D8                  	add	ax, bx	; interpolated middle + [previous_val] 
  4136 00001EEF 66D1D8                  	rcr	ax, 1
  4137 00001EF2 50                      	push	eax ; **	; interpolated 1st quarter (temporary)
  4138 00001EF3 6601D8                  	add	ax, bx	; 1st quarter + [previous_val]
  4139 00001EF6 66D1D8                  	rcr	ax, 1	
  4140 00001EF9 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4141 00001EFC 66AB                    	stosw 		; interpolated sample 1 (L)
  4142 00001EFE 66AB                    	stosw		; interpolated sample 1 (R)
  4143 00001F00 58                      	pop	eax ; **	
  4144 00001F01 5B                      	pop	ebx ; *
  4145 00001F02 6601D8                  	add	ax, bx	; 1st quarter + middle
  4146 00001F05 66D1D8                  	rcr	ax, 1	; / 2
  4147 00001F08 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again	
  4148 00001F0B 66AB                    	stosw		; interpolated sample 2 (L)
  4149 00001F0D 66AB                    	stosw		; interpolated sample 2 (R)		
  4150 00001F0F 89D8                    	mov	eax, ebx
  4151 00001F11 6601D0                  	add	ax, dx	; interpolated middle + [next_val]
  4152 00001F14 66D1D8                  	rcr	ax, 1
  4153 00001F17 50                      	push	eax ; *	; interpolated 3rd quarter (temporary)
  4154 00001F18 6601D8                  	add	ax, bx	; + interpolated middle
  4155 00001F1B 66D1D8                  	rcr	ax, 1
  4156 00001F1E 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4157 00001F21 66AB                    	stosw		; interpolated sample 3 (L)
  4158 00001F23 66AB                    	stosw		; interpolated sample 3 (R)
  4159 00001F25 58                      	pop	eax ; *	
  4160 00001F26 6601D0                  	add	ax, dx	; 3rd quarter + [next_val]
  4161 00001F29 66D1D8                  	rcr	ax, 1	; / 2
  4162 00001F2C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4163 00001F2F 66AB                    	stosw		; interpolated sample 4 (L)
  4164 00001F31 66AB                    	stosw		; interpolated sample 4 (R)
  4165 00001F33 C3                      	retn
  4166                                  
  4167                                  interpolating_5_16bit_stereo:
  4168                                  	; 18/11/2023
  4169                                  	; bx = [previous_val_l]
  4170                                  	; ax = [previous_val_r]
  4171                                  	; [next_val_l]
  4172                                  	; [next_val_r]
  4173                                  	; original-interpltd-interpltd-interpltd-interpltd
  4174 00001F34 51                      	push	ecx ; !
  4175 00001F35 93                      	xchg	eax, ebx
  4176 00001F36 66AB                    	stosw		; original sample (L)
  4177 00001F38 93                      	xchg	eax, ebx
  4178 00001F39 66AB                    	stosw		; original sample (R)
  4179 00001F3B 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4180 00001F3E 50                      	push	eax ; *	; [previous_val_r]
  4181 00001F3F 80C780                  	add	bh, 80h
  4182 00001F42 8005[BE200000]80        	add	byte [next_val_l+1], 80h
  4183 00001F49 66A1[BD200000]          	mov	ax, [next_val_l]
  4184 00001F4F 6601D8                  	add	ax, bx	; [previous_val_l]
  4185 00001F52 66D1D8                  	rcr	ax, 1
  4186 00001F55 89C1                    	mov	ecx, eax ; interpolated middle (L)
  4187 00001F57 6601D8                  	add	ax, bx	
  4188 00001F5A 66D1D8                  	rcr	ax, 1
  4189 00001F5D 89C2                    	mov	edx, eax ; interpolated 1st quarter (L)	
  4190 00001F5F 6601D8                  	add	ax, bx	; [previous_val_l]
  4191 00001F62 66D1D8                  	rcr	ax, 1
  4192 00001F65 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4193 00001F68 66AB                    	stosw 		; interpolated sample 1 (L)
  4194 00001F6A 89C8                    	mov	eax, ecx
  4195 00001F6C 6601D0                  	add	ax, dx	; middle (L) + 1st quarter (L) 
  4196 00001F6F 66D1D8                  	rcr	ax, 1	; / 2
  4197 00001F72 89C3                    	mov	ebx, eax  ; interpolated sample 2 (L)
  4198 00001F74 5A                      	pop	edx ; *	; [previous_val_r]
  4199 00001F75 89D0                    	mov	eax, edx
  4200 00001F77 8005[C0200000]80        	add	byte [next_val_r+1], 80h
  4201 00001F7E 660305[BF200000]        	add	ax, [next_val_r]
  4202 00001F85 66D1D8                  	rcr	ax, 1
  4203 00001F88 50                      	push	eax ; *	; interpolated middle (R)
  4204 00001F89 6601D0                  	add	ax, dx
  4205 00001F8C 66D1D8                  	rcr	ax, 1
  4206 00001F8F 50                      	push	eax ; ** ; interpolated 1st quarter (R)
  4207 00001F90 6601D0                  	add	ax, dx	; [previous_val_r]
  4208 00001F93 66D1D8                  	rcr	ax, 1
  4209 00001F96 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4210 00001F99 66AB                    	stosw 		; interpolated sample 1 (R)
  4211 00001F9B 89D8                    	mov	eax, ebx
  4212 00001F9D 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4213 00001FA0 66AB                    	stosw 		; interpolated sample 2 (L)
  4214 00001FA2 58                      	pop	eax ; **
  4215 00001FA3 5A                      	pop	edx ; *
  4216 00001FA4 6601D0                  	add	ax, dx	; 1st quarter (R) + middle (R)
  4217 00001FA7 66D1D8                  	rcr	ax, 1	; / 2
  4218 00001FAA 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4219 00001FAD 66AB                    	stosw 		; interpolated sample 2 (R)
  4220 00001FAF 89C8                    	mov	eax, ecx
  4221 00001FB1 660305[BD200000]        	add	ax, [next_val_l]
  4222 00001FB8 66D1D8                  	rcr	ax, 1
  4223 00001FBB 50                      	push	eax ; * ; interpolated 3rd quarter (L)
  4224 00001FBC 6601C8                  	add	ax, cx	; interpolated middle (L)
  4225 00001FBF 66D1D8                  	rcr	ax, 1
  4226 00001FC2 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4227 00001FC5 66AB                    	stosw 		; interpolated sample 3 (L)
  4228 00001FC7 89D0                    	mov	eax, edx
  4229 00001FC9 660305[BF200000]        	add	ax, [next_val_r]
  4230 00001FD0 66D1D8                  	rcr	ax, 1
  4231 00001FD3 50                      	push	eax ; ** ; interpolated 3rd quarter (R)
  4232 00001FD4 6601D0                  	add	ax, dx	; interpolated middle (R)
  4233 00001FD7 66D1D8                  	rcr	ax, 1
  4234 00001FDA 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4235 00001FDD 66AB                    	stosw 		; interpolated sample 3 (R)
  4236 00001FDF 5B                      	pop	ebx ; **
  4237 00001FE0 58                      	pop	eax ; *
  4238 00001FE1 660305[BD200000]        	add	ax, [next_val_l]
  4239 00001FE8 66D1D8                  	rcr	ax, 1
  4240 00001FEB 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4241 00001FEE 66AB                    	stosw 		; interpolated sample 4 (L)
  4242 00001FF0 89D8                    	mov	eax, ebx	
  4243 00001FF2 660305[BF200000]        	add	ax, [next_val_r]
  4244 00001FF9 66D1D8                  	rcr	ax, 1
  4245 00001FFC 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4246 00001FFF 66AB                    	stosw 		; interpolated sample 4 (R)
  4247 00002001 59                      	pop	ecx ; !
  4248 00002002 C3                      	retn
  4249                                  
  4250                                  interpolating_4_16bit_mono:
  4251                                  	; 18/11/2023
  4252                                  	; ax = [previous_val]
  4253                                  	; dx = [next_val]
  4254                                  	; original-interpolated
  4255                                  
  4256 00002003 66AB                    	stosw		; original sample (L)
  4257 00002005 66AB                    	stosw		; original sample (R)
  4258 00002007 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4259 0000200A 89C3                    	mov	ebx, eax ; [previous_val]
  4260 0000200C 80C680                  	add	dh, 80h
  4261 0000200F 6601D0                  	add	ax, dx	; [previous_val] + [next_val]
  4262 00002012 66D1D8                  	rcr	ax, 1
  4263 00002015 93                      	xchg	eax, ebx	
  4264 00002016 6601D8                  	add	ax, bx	; [previous_val] + interpolated middle
  4265 00002019 66D1D8                  	rcr	ax, 1
  4266 0000201C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4267 0000201F 66AB                    	stosw 		; interpolated sample 1 (L)
  4268 00002021 66AB                    	stosw		; interpolated sample 1 (R)
  4269 00002023 89D8                    	mov	eax, ebx ; interpolated middle
  4270 00002025 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4271 00002028 66AB                    	stosw 		; interpolated sample 2 (L)
  4272 0000202A 66AB                    	stosw		; interpolated sample 2 (R)
  4273 0000202C 89D8                    	mov	eax, ebx
  4274 0000202E 6601D0                  	add	ax, dx	; interpolated middle + [next_val]
  4275 00002031 66D1D8                  	rcr	ax, 1
  4276 00002034 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4277 00002037 66AB                    	stosw		; interpolated sample 3 (L)
  4278 00002039 66AB                    	stosw		; interpolated sample 3 (R)
  4279 0000203B C3                      	retn
  4280                                  
  4281                                  interpolating_4_16bit_stereo:
  4282                                  	; 18/11/2023
  4283                                  	; bx = [previous_val_l]
  4284                                  	; ax = [previous_val_r]
  4285                                  	; [next_val_l]
  4286                                  	; [next_val_r]
  4287                                  	; original-interpolated-interpolated-interpolated
  4288 0000203C 93                      	xchg	eax, ebx
  4289 0000203D 66AB                    	stosw		; original sample (L)
  4290 0000203F 93                      	xchg	eax, ebx
  4291 00002040 66AB                    	stosw		; original sample (R)
  4292 00002042 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4293 00002045 89C2                    	mov	edx, eax ; [previous_val_r]
  4294 00002047 80C780                  	add	bh, 80h
  4295 0000204A 8005[BE200000]80        	add	byte [next_val_l+1], 80h
  4296 00002051 66A1[BD200000]          	mov	ax, [next_val_l]
  4297 00002057 6601D8                  	add	ax, bx	; [previous_val_l]
  4298 0000205A 66D1D8                  	rcr	ax, 1
  4299 0000205D 93                      	xchg	eax, ebx	
  4300 0000205E 6601D8                  	add	ax, bx	; bx = interpolated middle (L)
  4301 00002061 66D1D8                  	rcr	ax, 1
  4302 00002064 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4303 00002067 66AB                    	stosw 		; interpolated sample 1 (L)
  4304 00002069 8005[C0200000]80        	add	byte [next_val_r+1], 80h
  4305 00002070 89D0                    	mov	eax, edx ; [previous_val_r]
  4306 00002072 660305[BF200000]        	add	ax, [next_val_r]
  4307 00002079 66D1D8                  	rcr	ax, 1
  4308 0000207C 92                      	xchg	eax, edx	
  4309 0000207D 6601D0                  	add	ax, dx	; dx = interpolated middle (R)
  4310 00002080 66D1D8                  	rcr	ax, 1
  4311 00002083 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4312 00002086 66AB                    	stosw 		; interpolated sample 1 (R)
  4313 00002088 89D8                    	mov	eax, ebx
  4314 0000208A 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4315 0000208D 66AB                    	stosw 		; interpolated sample 2 (L)
  4316 0000208F 89D0                    	mov	eax, edx
  4317 00002091 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4318 00002094 66AB                    	stosw 		; interpolated sample 2 (R)
  4319 00002096 89D8                    	mov	eax, ebx
  4320 00002098 660305[BD200000]        	add	ax, [next_val_l]
  4321 0000209F 66D1D8                  	rcr	ax, 1
  4322 000020A2 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4323 000020A5 66AB                    	stosw 		; interpolated sample 3 (L)
  4324 000020A7 89D0                    	mov	eax, edx
  4325 000020A9 660305[BF200000]        	add	ax, [next_val_r]
  4326 000020B0 66D1D8                  	rcr	ax, 1
  4327 000020B3 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4328 000020B6 66AB                    	stosw 		; interpolated sample 3 (R)
  4329 000020B8 C3                      	retn
  4330                                  
  4331                                  ; 13/11/2023
  4332                                  previous_val:
  4333 000020B9 0000                    previous_val_l: dw 0
  4334 000020BB 0000                    previous_val_r: dw 0
  4335                                  next_val:
  4336 000020BD 0000                    next_val_l: dw 0
  4337 000020BF 0000                    next_val_r: dw 0
  4338                                  
  4339                                  ; 16/11/2023
  4340 000020C1 00                      faz:	db 0	
  4341                                  	
  4342                                  ;=============================================================================
  4343                                  ;	gfx.asm - draw scopes in VGA 640x480x16 mode      
  4344                                  ;=============================================================================
  4345                                  
  4346                                  ; EX1A.ASM (21/6/1994, Carlos Hasan; MSDOS, 'RUNME.EXE', 'TNYPL211')
  4347                                  
  4348                                  ;-----------------------------------------------------------------------------
  4349                                  ; setgraphmode - setup the VGA 640x480x16 graphics mode
  4350                                  ;-----------------------------------------------------------------------------
  4351                                  	; 22/10/2017
  4352                                  setgraphmode:
  4353                                  	;pushad
  4354 000020C2 66B81200                	mov	ax,0012h
  4355                                  	;int	10h
  4356 000020C6 CD31                    	int 	31h
  4357 000020C8 66BAC003                	mov	dx,3C0h
  4358 000020CC 30C0                    	xor	al,al
  4359                                  setgraphmodel0:
  4360                                  	;out	dx,al
  4361 000020CE B401                    	mov	ah, 1 ; outb
  4362 000020D0 CD34                    	int	34h
  4363                                  	;out	dx, al
  4364                                  	;mov	ah, 1
  4365 000020D2 CD34                    	int	34h
  4366 000020D4 FEC0                    	inc	al
  4367 000020D6 3C10                    	cmp	al, 10h
  4368 000020D8 72F4                    	jb	short setgraphmodel0
  4369 000020DA B020                    	mov	al, 20h
  4370                                  	;out	dx, al
  4371                                  	;mov	ah, 1
  4372 000020DC CD34                    	int	34h
  4373                                  	;popad
  4374 000020DE C3                      	retn
  4375                                  
  4376                                  ;-----------------------------------------------------------------------------
  4377                                  ; settextmode - restore the VGA 80x25x16 text mode
  4378                                  ;-----------------------------------------------------------------------------
  4379                                  	; 22/10/2017
  4380                                  settextmode:
  4381                                  	;pushad
  4382 000020DF 66B80300                	mov	ax, 0003h
  4383                                  	;int	10h
  4384 000020E3 CD31                    	int	31h
  4385                                  	;popad
  4386 000020E5 C3                      	retn
  4387                                  
  4388                                  ;-----------------------------------------------------------------------------
  4389                                  ; drawscopes - draw the track voices sample scopes
  4390                                  ; In:
  4391                                  ;  ESI = (current) sample buffer
  4392                                  ;-----------------------------------------------------------------------------
  4393                                  	; 29/10/2017
  4394                                  	; 28/10/2017
  4395                                  	; (ESI = Current DMA buffer offset)
  4396                                  	; 27/10/2017
  4397                                  	; 26/10/2017
  4398                                  	; 23/10/2017
  4399                                  drawscopes:
  4400                                  	;pushad
  4401                                    	;mov	esi, g_buff
  4402                                  	;mov	esi, edx
  4403 000020E6 31C9                    	xor     ecx, ecx	
  4404 000020E8 31D2                    	xor     edx, edx
  4405 000020EA 31FF                    	xor	edi, edi
  4406                                  drawscope0:
  4407 000020EC 66AD                    	lodsw
  4408 000020EE 80F480                  	xor	ah, 80h
  4409 000020F1 0FB6DC                  	movzx	ebx, ah  ; Left Channel
  4410 000020F4 66D1E3                  	shl	bx, 1
  4411 000020F7 668B83[00660000]        	mov	ax, [RowOfs+ebx]
  4412 000020FE 668987[00680000]        	mov	[NewScope_L+edi], ax
  4413 00002105 30FF                    	xor	bh, bh
  4414 00002107 66AD                    	lodsw
  4415 00002109 80F480                  	xor	ah, 80h
  4416 0000210C 88E3                    	mov	bl, ah	; Right Channel
  4417 0000210E 66D1E3                  	shl	bx, 1
  4418 00002111 668B83[00660000]        	mov	ax, [RowOfs+ebx]
  4419 00002118 668987[006A0000]        	mov	[NewScope_R+edi], ax
  4420 0000211F 6683C702                	add	di, 2
  4421 00002123 FEC1                    	inc	cl
  4422 00002125 75C5                    	jnz	short drawscope0	
  4423                                  
  4424 00002127 66BAC403                        mov	dx, 3C4h
  4425                                          ;mov	ax, 0802h
  4426                                          ;out	dx, ax
  4427 0000212B 66BB0208                        mov	bx, 0802h
  4428 0000212F B403                    	mov	ah, 3 ; outw
  4429 00002131 CD34                    	int	34h
  4430 00002133 66BACE03                	mov	dx, 3CEh
  4431 00002137 B008                            mov	al, 08h
  4432                                         ;out	dx, al
  4433 00002139 B401                            mov	ah, 1 ; outb
  4434 0000213B CD34                    	int	34h
  4435 0000213D 6642                    	inc	dx
  4436                                  
  4437                                  	; 26/10/2017
  4438 0000213F 31F6                            xor	esi, esi
  4439                                         ;xor	edi, edi
  4440 00002141 BB45060A00                      mov     ebx, 0A0645h
  4441                                  drawscopel4:
  4442 00002146 B080                            mov     al, 80h
  4443                                  drawscopel2:
  4444 00002148 50                              push    eax ; *
  4445 00002149 52                              push    edx ; **
  4446                                  	;out	dx, al
  4447 0000214A B401                    	mov	ah, 1 ; outb
  4448 0000214C CD34                    	int	34h
  4449                                  
  4450 0000214E B4FF                            mov	ah, 0FFh
  4451                                          ;mov	ecx, 32
  4452 00002150 B120                    	mov	cl, 32
  4453 00002152 28C0                    	sub     al, al
  4454                                  drawscopel3:
  4455                                  	; 23/10/2017
  4456 00002154 668B96[006C0000]                mov	dx, [OldScope_L+esi]
  4457 0000215B 663B96[00680000]                cmp	dx, [NewScope_L+esi]
  4458 00002162 7414                            je	short drawscopef3
  4459 00002164 88041A                          mov	[edx+ebx], al ; L
  4460 00002167 668B96[00680000]                mov     dx, [NewScope_L+esi]
  4461 0000216E 88241A                  	mov	[edx+ebx], ah ; L
  4462 00002171 668996[006C0000]                mov     [OldScope_L+esi], dx
  4463                                  drawscopef3:
  4464                                  	; 27/10/2017
  4465 00002178 668B96[006E0000]                mov	dx, [OldScope_R+esi]
  4466 0000217F 663B96[006A0000]                cmp	dx, [NewScope_R+esi]
  4467 00002186 7416                            je	short drawscopef4
  4468 00002188 88441A26                	mov	[edx+ebx+38], al ; R
  4469 0000218C 668B96[006A0000]                mov     dx, [NewScope_R+esi]
  4470 00002193 88641A26                        mov	[edx+ebx+38], ah ; R
  4471 00002197 668996[006E0000]                mov     [OldScope_R+esi], dx
  4472                                  drawscopef4:
  4473 0000219E 83C610                  	add	esi, 2*8
  4474 000021A1 43                      	inc	ebx
  4475 000021A2 E2B0                    	loop    drawscopel3
  4476                                  
  4477 000021A4 5A                              pop     edx ; **
  4478 000021A5 58                              pop     eax ; *
  4479 000021A6 81EEFE010000            	sub	esi, 2*256-2
  4480 000021AC 83EB20                  	sub	ebx, 32
  4481 000021AF D0E8                            shr     al, 1
  4482 000021B1 7595                            jnz	short drawscopel2
  4483                                  	;popad
  4484 000021B3 C3                              retn
  4485                                  
  4486                                  ;=============================================================================
  4487                                  ;	Load IFF/ILBM files for VGA 640x480x16 graphics mode       
  4488                                  ;=============================================================================
  4489                                  
  4490                                  ; EX1B.ASM (21/6/1994, Carlos Hasan; MSDOS, 'RUNME.EXE', 'TNYPL211')
  4491                                  
  4492                                  ; 21/10/2017 (TRDOS 386, 'tmodplay.s', Erdogan Tan, NASM syntax)
  4493                                  
  4494                                  ;-----------------------------------------------------------------------------
  4495                                  ; EQUATES AND STRUCTURES
  4496                                  ;-----------------------------------------------------------------------------
  4497                                  
  4498                                  ID_FORM equ 4D524F46h		; IFF/ILBM chunk IDs
  4499                                  ID_ILBM equ 4D424C49h
  4500                                  ID_BMHD equ 44484D42h
  4501                                  ID_CMAP equ 50414D43h
  4502                                  ID_BODY equ 59444F42h
  4503                                  
  4504                                  struc Form			; IFF/ILBM header file format
  4505 00000000 ????????                  .ID:		resd 1
  4506 00000004 ????????                  .Length:	resd 1
  4507 00000008 ????????                  .Type:	resd 1
  4508                                    .size:
  4509                                  endstruc
  4510                                  
  4511                                  struc Chunk			; IFF/ILBM header chunk format
  4512 00000000 ????????                  .ID:		resd 1
  4513 00000004 ????????                  .Length:	resd 1
  4514                                    .size:	
  4515                                  endstruc
  4516                                  
  4517                                  struc BMHD			; IFF/ILBM BMHD chunk format
  4518 00000000 ????                      .Width: 	resw 1
  4519 00000002 ????                      .Height:	resw 1
  4520 00000004 ????                      .PosX:	resw 1
  4521 00000006 ????                      .PosY:	resw 1
  4522 00000008 ??                        .Planes:	resb 1
  4523 00000009 ??                        .Masking:	resb 1
  4524 0000000A ??                        .Compression:	resb 1
  4525 0000000B ??                        .Pad:		resb 1
  4526 0000000C ????                      .Transparent:	resw 1
  4527 0000000E ??                        .AspectX	resb 1
  4528 0000000F ??                        .AspectY:	resb 1
  4529 00000010 ????                      .PageWidth:	resw 1
  4530 00000012 ????                      .PageHeight:	resw 1
  4531                                    .size:	
  4532                                  endstruc
  4533                                  
  4534                                  struc CMAP			; IFF/ILBM CMAP chunk format
  4535 00000000 <res 300h>                .Colors:	resb 768
  4536                                    .size:	
  4537                                  endstruc
  4538                                  
  4539                                  ;LOGO_ADDRESS	equ 100000h	; virtual address at the end of the 1st 1MB
  4540                                  
  4541                                  ;------------------------------------------------------------------------------
  4542                                  ; bswap - macro to reverse the byte order of a 32-bit register, converting
  4543                                  ;         a value in little/big endian form to big/little endian form.
  4544                                  ;------------------------------------------------------------------------------
  4545                                  %macro	bswap   1
  4546                                          xchg    al, ah
  4547                                          rol     eax, 16
  4548                                          xchg    al, ah
  4549                                  %endmacro
  4550                                  
  4551                                  ;------------------------------------------------------------------------------
  4552                                  ; putlbm - draw the IFF/ILBM picture on VGA 640x480x16 graphics mode
  4553                                  ; In:
  4554                                  ;  ESI = IFF/ILBM image file address
  4555                                  ;------------------------------------------------------------------------------
  4556                                  putlbm:
  4557 000021B4 60                              pushad
  4558                                  
  4559                                  ; check if this is a valid IFF/ILBM Deluxe Paint file
  4560                                  
  4561 000021B5 813E464F524D                    cmp     dword [esi+Form.ID], ID_FORM
  4562 000021BB 7551                            jne     short putlbmd0
  4563 000021BD 817E08494C424D                  cmp     dword [esi+Form.Type], ID_ILBM
  4564 000021C4 7548                            jne     short putlbmd0
  4565                                  
  4566                                  ; get the IFF/ILBM file length in bytes
  4567                                  
  4568 000021C6 8B4604                          mov     eax, [esi+Form.Length]
  4569                                          bswap   eax
  4546 000021C9 86C4                <1>  xchg al, ah
  4547 000021CB C1C010              <1>  rol eax, 16
  4548 000021CE 86C4                <1>  xchg al, ah
  4570 000021D0 89C1                            mov     ecx, eax
  4571                                  
  4572                                  ; decrease the file length and update the file pointer
  4573                                  
  4574 000021D2 83E904                          sub     ecx, 4
  4575 000021D5 83C60C                          add     esi, Form.size
  4576                                  
  4577                                  ; IFF/ILBM main parser body loop
  4578                                  
  4579                                  putlbml0:
  4580 000021D8 85C9                            test    ecx, ecx
  4581 000021DA 7E64                            jle     short putlbmd1
  4582                                  
  4583                                  ; get the next chunk ID and length in bytes
  4584                                  
  4585 000021DC 8B1E                            mov     ebx, [esi+Chunk.ID]
  4586 000021DE 8B4604                          mov     eax, [esi+Chunk.Length]
  4587                                          bswap   eax
  4546 000021E1 86C4                <1>  xchg al, ah
  4547 000021E3 C1C010              <1>  rol eax, 16
  4548 000021E6 86C4                <1>  xchg al, ah
  4588 000021E8 93                              xchg    ebx, eax
  4589 000021E9 83C608                          add     esi, Chunk.size
  4590                                  
  4591                                  ; word align the chunk length and decrease the file length counter
  4592                                  
  4593 000021EC 43                              inc     ebx
  4594 000021ED 80E3FE                          and     bl, 0FEh ; ~1
  4595 000021F0 83E908                          sub     ecx, Chunk.size
  4596 000021F3 29D9                            sub     ecx, ebx
  4597                                  
  4598                                  ; check for the BMHD/CMAP/BODY chunk headers
  4599                                  
  4600 000021F5 3D424D4844                      cmp     eax, ID_BMHD
  4601 000021FA 7415                            je      short putlbmf0
  4602 000021FC 3D434D4150                      cmp     eax, ID_CMAP
  4603 00002201 7440                            je      short putlbmf1
  4604 00002203 3D424F4459                      cmp     eax, ID_BODY
  4605 00002208 7455                            je      short putlbmf2
  4606                                  
  4607                                  ; advance to the next IFF/ILBM chunk structure
  4608                                  
  4609                                  putlbmc0:
  4610 0000220A 01DE                            add     esi, ebx
  4611 0000220C EBCA                            jmp     short putlbml0
  4612                                  
  4613                                  putlbmd0:
  4614 0000220E F9                              stc
  4615 0000220F 61                              popad
  4616 00002210 C3                              retn
  4617                                  
  4618                                  ; process the BMHD bitmap header chunk
  4619                                  
  4620                                  putlbmf0:
  4621 00002211 807E0804                        cmp     byte [esi+BMHD.Planes], 4
  4622 00002215 75F7                            jne     short putlbmd0
  4623 00002217 807E0A01                        cmp     byte [esi+BMHD.Compression], 1
  4624 0000221B 75F1                            jne     short putlbmd0
  4625 0000221D 807E0B00                        cmp     byte [esi+BMHD.Pad], 0
  4626 00002221 75EB                            jne     short putlbmd0
  4627 00002223 0FB706                          movzx   eax, word [esi+BMHD.Width]
  4628 00002226 86C4                            xchg    al, ah
  4629 00002228 83C007                          add     eax, 7
  4630 0000222B C1E803                          shr     eax, 3
  4631 0000222E A3[68650000]                    mov     [picture.width], eax
  4632 00002233 0FB74602                        movzx   eax, word [esi+BMHD.Height]
  4633 00002237 86C4                            xchg    al, ah
  4634 00002239 A3[6C650000]                    mov     [picture.height], eax
  4635 0000223E EBCA                            jmp     short putlbmc0
  4636                                  
  4637                                  putlbmd1:
  4638 00002240 F8                              clc
  4639 00002241 61                              popad
  4640 00002242 C3                              retn
  4641                                  
  4642                                  ; process the CMAP colormap chunk
  4643                                  
  4644                                  putlbmf1:
  4645 00002243 66BAC803                        mov     dx, 3C8h
  4646 00002247 30C0                            xor     al, al
  4647                                          ;out	dx, al
  4648 00002249 B401                    	mov	ah, 1 ; outb
  4649 0000224B CD34                    	int	34h
  4650 0000224D 6642                            inc     dx
  4651                                  putlbml1:
  4652 0000224F 8A06                            mov     al, [esi]
  4653 00002251 C0E802                          shr     al, 2
  4654                                          ;out	dx, al
  4655                                  	;mov	ah, 1 ; outb
  4656 00002254 CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  4657 00002256 46                              inc     esi
  4658 00002257 4B                              dec     ebx
  4659 00002258 7FF5                            jg      short putlbml1
  4660 0000225A E979FFFFFF                      jmp     putlbml0
  4661                                  
  4662                                  ; process the BODY bitmap body chunk
  4663                                  
  4664                                  putlbmf2:
  4665 0000225F 60                              pushad
  4666 00002260 BF00000A00                      mov     edi, 0A0000h
  4667                                          ;cld
  4668 00002265 66BACE03                        mov     dx, 3CEh
  4669                                          ;mov	ax, 0FF08h
  4670                                          ;out	dx, ax
  4671 00002269 66BB08FF                	mov	bx, 0FF08h
  4672 0000226D B403                    	mov	ah, 3 ; outw
  4673 0000226F CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  4674 00002271 66BAC403                        mov     dx, 3C4h
  4675 00002275 B002                            mov     al, 02h
  4676                                          ;out	dx, al
  4677 00002277 B401                    	mov	ah, 1 ; outb
  4678 00002279 CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  4679 0000227B 6642                            inc     dx
  4680 0000227D 8B0D[6C650000]                  mov     ecx, [picture.height]
  4681                                  putlbml2:
  4682 00002283 51                              push    ecx
  4683 00002284 B011                            mov     al, 11h
  4684                                  putlbml3:
  4685 00002286 50                              push    eax
  4686 00002287 57                              push    edi
  4687                                          ;out	dx, al
  4688 00002288 B401                    	mov	ah, 1 ; outb
  4689 0000228A CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  4690 0000228C 8B1D[68650000]                  mov     ebx, [picture.width]
  4691                                  putlbml4:
  4692 00002292 AC                              lodsb
  4693 00002293 84C0                            test    al, al
  4694 00002295 7C0A                            jl      short putlbmf3
  4695 00002297 0FB6C8                          movzx   ecx, al
  4696 0000229A 41                              inc     ecx
  4697 0000229B 29CB                            sub     ebx, ecx
  4698 0000229D F3A4                            rep     movsb
  4699 0000229F EB0B                            jmp     short putlbmc4
  4700                                  putlbmf3:
  4701 000022A1 F6D8                            neg     al
  4702 000022A3 0FB6C8                          movzx   ecx, al
  4703 000022A6 41                              inc     ecx
  4704 000022A7 29CB                            sub     ebx, ecx
  4705 000022A9 AC                              lodsb
  4706 000022AA F3AA                            rep     stosb
  4707                                  putlbmc4:
  4708 000022AC 85DB                            test    ebx, ebx
  4709 000022AE 7FE2                            jg      short putlbml4
  4710 000022B0 5F                              pop     edi
  4711 000022B1 58                              pop     eax
  4712 000022B2 00C0                            add     al, al
  4713 000022B4 73D0                            jnc     short putlbml3
  4714 000022B6 83C750                          add     edi, 80
  4715 000022B9 59                              pop     ecx
  4716 000022BA E2C7                            loop    putlbml2
  4717 000022BC 61                      	popad
  4718 000022BD E948FFFFFF                      jmp	putlbmc0
  4719                                  
  4720                                  ; EX1.C (Carlos Hasan, 21/06/1994)
  4721                                  ;------------------------------------------------------------------------------
  4722                                  ; loadlbm - load the IFF/ILBM image file ("LOGO.LBM") at memory
  4723                                  ;  ESI = IFF/ILBM image file address
  4724                                  ;------------------------------------------------------------------------------
  4725                                  
  4726                                  ;if ((Logo = loadlbm("LOGO.LBM")) == NULL) {
  4727                                  ;       printf("Error loading the IFF/ILBM logo picture\n");
  4728                                  ;       MODStopModule();
  4729                                  ;       MODFreeModule(Song);
  4730                                  ;       return;
  4731                                  ;   }
  4732                                  ;   setgraphmode();
  4733                                  ;   putlbm(Logo);
  4734                                  ;   while (!kbhit())
  4735                                  ;       drawscopes(Song->NumTracks);
  4736                                  ;   settextmode();
  4737                                  ;   free(Logo);
  4738                                  ;   MODStopModule();
  4739                                  ;   MODFreeModule(Song);
  4740                                  
  4741                                  ;loadlbm:
  4742                                  ;	; ebx = ASCIIZ file name address
  4743                                  ;	; ecx = open mode (0 = open for read)	
  4744                                  ;	sys	_open, LOGO_FILE_NAME, 0 ; open for reading
  4745                                  ;	jc	short loadlbm_retn
  4746                                  ;
  4747                                  ;	mov     [LBM_FileHandle], eax
  4748                                  ;
  4749                                  ;	; get file size by moving file pointer to the end of file
  4750                                  ;	; ebx = file handle/number
  4751                                  ;	; ecx : offset = 0
  4752                                  ;	; edx : switch = 2 (move fp to end of file + offset)
  4753                                  ;	sys	_seek, eax, 0, 2
  4754                                  ;	jc	short loadlbm_cf
  4755                                  ;
  4756                                  ;	mov	[LBM_FileSize], eax
  4757                                  ;
  4758                                  ;	; move file pointer to the beginning of the file
  4759                                  ;	; ecx = 0
  4760                                  ;	; edx = 0
  4761                                  ;	;xor	ecx, ecx
  4762                                  ; 	xor	dl, dl
  4763                                  ;	; ebx = [LBM_FileHandle]
  4764                                  ;	sys	_seek
  4765                                  ;	;jc	short loadlbm_cf
  4766                                  ;
  4767                                  ;	; ebx = File handle
  4768                                  ;	; ecx = Buffer address
  4769                                  ;	; edx = Byte count
  4770                                  ;	;sys	_read, [LBM_FileHandle], LOGO_ADDRESS, [LBM_FileSize]
  4771                                  ;	mov	ecx, LOGO_ADDRESS
  4772                                  ;	mov	edx, [LBM_FileSize]
  4773                                  ;	sys	_read
  4774                                  ;	jc	short loadlbm_cf
  4775                                  ;
  4776                                  ;	cmp	eax, edx  ; read count = file size ?
  4777                                  ;	;jb	short loadlbm_cf		 
  4778                                  ;loadlbm_cf:
  4779                                  ;	pushf
  4780                                  ;	sys	_close, [LBM_FileHandle]	
  4781                                  ;	popf
  4782                                  ;loadlbm_retn:
  4783                                  ;	retn	
  4784                                  ;
  4785                                  ;LOGO_FILE_NAME:
  4786                                  ;	db	"LOGO.LBM", 0
  4787                                  
  4788                                  LOGO_ERROR_MSG:
  4789 000022C2 4572726F72206C6F61-     	db	"Error loading the IFF/ILBM logo picture !", 0Dh, 0Ah, 0 
  4789 000022CB 64696E672074686520-
  4789 000022D4 4946462F494C424D20-
  4789 000022DD 6C6F676F2070696374-
  4789 000022E6 75726520210D0A00   
  4790                                  
  4791                                  align 2
  4792                                  ; 22/10/2017
  4793                                  LOGO_ADDRESS:
  4794                                  ;incbin "LOGO.LBM"	  	 
  4795                                  ; 27/10/2017
  4796 000022EE <bin 3FF0h>             incbin "TINYPLAY.LBM"
  4797                                  
  4798                                  ;=============================================================================
  4799                                  ;               preinitialized data
  4800                                  ;=============================================================================
  4801                                  	
  4802 000062DE 00                      	db	0
  4803                                  	; 23/08/2020
  4804                                  FileHandle:	
  4805 000062DF FFFFFFFF                	dd	-1
  4806 000062E3 00                      	db	0
  4807                                  Credits:
  4808                                  msg_usage:
  4809                                  	; 09/12/2023
  4810 000062E4 54696E792057415620-     	db	'Tiny WAV Player for TRDOS 386 by Erdogan Tan',10,13
  4810 000062ED 506C6179657220666F-
  4810 000062F6 72205452444F532033-
  4810 000062FF 383620627920457264-
  4810 00006308 6F67616E2054616E0A-
  4810 00006311 0D                 
  4811 00006312 666F7220496E74656C-     	db 	'for Intel AC97 (ICH) Audio Controller.',10,13
  4811 0000631B 204143393720284943-
  4811 00006324 482920417564696F20-
  4811 0000632D 436F6E74726F6C6C65-
  4811 00006336 722E0A0D           
  4812 0000633A 446563656D62657220-     	db	'December 2023.',10,13
  4812 00006343 323032332E0A0D     
  4813                                  credits_zero:
  4814 0000634A 0A0D                    	db	10,13
  4815 0000634C 75736167653A207477-     	db	'usage: twavplay filename.wav',10,13,0
  4815 00006355 6176706C6179206669-
  4815 0000635E 6C656E616D652E7761-
  4815 00006367 760A0D00           
  4816 0000636B 32342F30382F323032-     	db	'24/08/2020',10,13,0
  4816 00006374 300A0D00           
  4817 00006378 30392F31322F323032-     	db	'09/12/2023',10,13,0
  4817 00006381 330A0D00           
  4818                                  
  4819                                  noDevMsg:
  4820                                  	; 09/12/2023
  4821 00006385 4572726F723A20556E-     	db	'Error: Unable to find AC97 audio device!'
  4821 0000638E 61626C6520746F2066-
  4821 00006397 696E64204143393720-
  4821 000063A0 617564696F20646576-
  4821 000063A9 69636521           
  4822 000063AD 0A0D00                  	db	10,13,0
  4823                                  
  4824                                  noFileErrMsg:
  4825 000063B0 4572726F723A206669-     	db	'Error: file not found.',10,13,0
  4825 000063B9 6C65206E6F7420666F-
  4825 000063C2 756E642E0A0D00     
  4826                                  
  4827                                  trdos386_err_msg:
  4828 000063C9 5452444F5320333836-     	db	'TRDOS 386 System call error !',10,13,0
  4828 000063D2 2053797374656D2063-
  4828 000063DB 616C6C206572726F72-
  4828 000063E4 20210A0D00         
  4829                                  
  4830                                  ; 09/12/2023
  4831                                  msg_no_vra:
  4832 000063E9 0A0D                    	db	10,13
  4833 000063EB 4E6F20565241207375-     	db	"No VRA support ! Only 48 kHZ sample rate supported !"
  4833 000063F4 70706F72742021204F-
  4833 000063FD 6E6C79203438206B48-
  4833 00006406 5A2073616D706C6520-
  4833 0000640F 726174652073757070-
  4833 00006418 6F727465642021     
  4834 0000641F 0A0D00                  	db	10,13,0
  4835                                  
  4836                                  ; 13/11/2016
  4837 00006422 303132333435363738-     hex_chars:	db "0123456789ABCDEF", 0
  4837 0000642B 3941424344454600   
  4838                                  ;
  4839                                  msgAC97Info:	
  4840 00006433 0D0A                    		db 0Dh, 0Ah
  4841 00006435 414339372041756469-     		db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah 
  4841 0000643E 6F20436F6E74726F6C-
  4841 00006447 6C6572202620436F64-
  4841 00006450 656320496E666F0D0A 
  4842 00006459 56656E646F72204944-     		db "Vendor ID: "
  4842 00006462 3A20               
  4843 00006464 303030306820446576-     msgVendorId:	db "0000h Device ID: "
  4843 0000646D 6963652049443A20   
  4844 00006475 30303030680D0A          msgDevId:	db "0000h", 0Dh, 0Ah
  4845 0000647C 4275733A20              		db "Bus: "
  4846 00006481 303068204465766963-     msgBusNo	db "00h Device: "
  4846 0000648A 653A20             
  4847 0000648D 3030682046756E6374-     msgDevNo	db "00h Function: "
  4847 00006496 696F6E3A20         
  4848 0000649B 303068                  msgFncNo	db "00h"
  4849 0000649E 0D0A                    		db 0Dh, 0Ah
  4850                                  ; 09/12/2023
  4851 000064A0 4E414D4241523A20        		db "NAMBAR: "
  4852 000064A8 30303030682020          msgNamBar	db "0000h  "
  4853 000064AF 4E41424D4241523A20      		db "NABMBAR: "
  4854 000064B8 303030306820204952-     msgNabmBar	db "0000h  IRQ: "
  4854 000064C1 513A20             
  4855 000064C4 3030                    msgIRQ		dw 3030h
  4856 000064C6 0D0A00                  		db 0Dh, 0Ah, 0
  4857                                  
  4858 000064C9 0D0A5741562046696C-     msgWavFileName:	db 0Dh, 0Ah, "WAV File Name: ",0
  4858 000064D2 65204E616D653A2000 
  4859 000064DB 0D0A53616D706C6520-     msgSampleRate:	db 0Dh, 0Ah, "Sample Rate: "
  4859 000064E4 526174653A20       
  4860 000064EA 303030303020487A2C-     msgHertz:	db "00000 Hz, ", 0 
  4860 000064F3 2000               
  4861 000064F5 3820626974732C2000      msg8Bits:	db "8 bits, ", 0 
  4862 000064FE 4D6F6E6F0D0A00          msgMono:	db "Mono", 0Dh, 0Ah, 0
  4863 00006505 313620626974732C20-     msg16Bits:	db "16 bits, ", 0 
  4863 0000650E 00                 
  4864 0000650F 53746572656F            msgStereo:	db "Stereo"
  4865 00006515 0D0A00                  nextline:	db 0Dh, 0Ah, 0
  4866                                  
  4867                                  ; 09/12/2023
  4868 00006518 56524120737570706F-     msgVRAheader:	db "VRA support: "
  4868 00006521 72743A20           
  4869 00006525 00                      		db 0	
  4870 00006526 5945530D0A00            msgVRAyes:	db "YES", 0Dh, 0Ah, 0
  4871 0000652C 4E4F200D0A              msgVRAno:	db "NO ", 0Dh, 0Ah
  4872 00006531 28496E746572706F6C-     		db "(Interpolated sample rate playing method)"
  4872 0000653A 617465642073616D70-
  4872 00006543 6C6520726174652070-
  4872 0000654C 6C6179696E67206D65-
  4872 00006555 74686F6429         
  4873 0000655A 0D0A00                  		db 0Dh, 0Ah, 0
  4874                                  
  4875                                  ;=============================================================================
  4876                                  ;		uninitialized data
  4877                                  ;=============================================================================
  4878                                  
  4879                                  ; 23/08/2020
  4880                                  
  4881                                  ; BSS
  4882                                  
  4883                                  bss_start:
  4884                                  
  4885                                  ABSOLUTE bss_start
  4886                                  
  4887 0000655D ??????                  alignb 4
  4888                                  
  4889                                  ;------------------------------------------------------------------------------
  4890                                  ; IFF/ILBM DATA
  4891                                  ;------------------------------------------------------------------------------
  4892                                  
  4893 00006560 ????????                LBM_FileHandle:	resd 1
  4894 00006564 ????????                LBM_FileSize:	resd 1
  4895                                  ;
  4896 00006568 ????????                picture.width:	resd 1 		; current picture width and height
  4897 0000656C ????????                picture.height:	resd 1
  4898                                  
  4899                                  ;------------------------------------------------------------------------------
  4900                                  
  4901                                  ;alignb 4
  4902                                  
  4903 00006570 ??                      stmo:		resb 1 ; stereo or mono (1=stereo) 
  4904 00006571 ??                      bps:		resb 1 ; bits per sample (8,16)
  4905 00006572 ????                    sample_rate:	resw 1 ; Sample Frequency (Hz)
  4906                                  
  4907                                  ; 09/12/2023
  4908                                  ; 'playwav6.s' (27/11/2023)
  4909                                  ; .......
  4910                                  ; 25/11/2023
  4911 00006574 ????????                bufferSize:	resd 1
  4912                                  
  4913 00006578 <res 1Ch>               smpRBuff:	resw 14 
  4914                                  
  4915                                  wav_file_name:
  4916 00006594 <res 50h>               		resb 80 ; wave file, path name (<= 80 bytes)
  4917                                  ;alignb 4
  4918 000065E4 ????                    		resw 1
  4919                                  
  4920 000065E6 ??                      ac97_int_ln_reg: resb 1
  4921 000065E7 ??                      fbs_shift:	resb 1 ; 26/11/2023
  4922                                  
  4923 000065E8 ????????                dev_vendor:	resd 1
  4924 000065EC ????????                bus_dev_fn:	resd 1
  4925 000065F0 ????                    ac97_NamBar:	resw 1
  4926 000065F2 ????                    ac97_NabmBar:	resw 1
  4927                                  
  4928 000065F4 ??                      flags:		resb 1
  4929                                  ;half_buff:	resb 1
  4930 000065F5 ??                      srb:		resb 1
  4931                                  ; 23/08/2020
  4932 000065F6 ??                      counter:	resb 1
  4933                                  ; 18/08/2020
  4934 000065F7 ??                      volume_level:	resb 1
  4935                                  ; 25/11/2023
  4936 000065F8 ??                      VRA:		resb 1	; Variable Rate Audio Support Status
  4937                                  ; 09/12/2023
  4938 000065F9 ??                      pan_shift:	resb 1
  4939                                  ; .......
  4940                                  
  4941 000065FA ????????????            alignb 16
  4942                                  
  4943                                  ; PLAY.ASM
  4944                                  ;Scope:		resw 320
  4945 00006600 <res 200h>              RowOfs:		resw 256
  4946                                  
  4947                                  ; 23/10/2017
  4948 00006800 <res 200h>              NewScope_L:	resw 256
  4949 00006A00 <res 200h>              NewScope_R:	resw 256
  4950 00006C00 <res 200h>              OldScope_L:	resw 256
  4951 00006E00 <res 200h>              OldScope_R:	resw 256
  4952                                  
  4953                                  ; 20/10/2017 (modplay7.s, SB16)
  4954                                  ; 19/10/2017 (modplay6.s, AC97)
  4955                                  ;pan_shift:	resb 1
  4956                                  ;volume_level:	resb 1
  4957                                  
  4958                                  ; 09/12/2023
  4959 00007000 ????????                DMA_buffer_size: resd 1	
  4960                                  
  4961 00007004 <res FFCh>              alignb 4096
  4962                                  
  4963                                  ;audio_buffer:	resb BUFFERSIZE ; DMA Buffer Size / 2  (32768)
  4964                                  ; 09/12/2023
  4965 00008000 <res 10000h>            audio_buffer:	resb 65536
  4966                                  
  4967 00018000 <res 8000h>             alignb 65536
  4968                                  
  4969                                  ;DMA_Buffer:	resb 2*BUFFERSIZE  ; 65536 ; 09/10/2017
  4970                                  ; 09/12/2023
  4971 00020000 <res 20000h>            DMA_Buffer:	resb 2*65536
  4972                                   
  4973                                  ; 13/06/2017
  4974                                  ;temp_buffer:	resb BUFFERSIZE
  4975                                  ; 26/11/2023
  4976 00040000 <res 10000h>            temp_buffer:	resb 65536
  4977                                  
  4978                                  EOF:
