     1                                  ; ****************************************************************************
     2                                  ; playwav7.s (for TRDOS 386)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; PLAYWAV7.PRG ! AC'97 (ICH) .WAV PLAYER program by Erdogan TAN
     5                                  ;
     6                                  ; 29/05/2024
     7                                  ;
     8                                  ; [ Last Modification: 02/02/2025 ]
     9                                  ;
    10                                  ; Modified from PLAYWAV6.PRG .wav player program by Erdogan Tan, 27/11/2023
    11                                  ; Modified from PLAYWAV4.COM .wav player program by Erdogan Tan, 19/05/2024
    12                                  ;
    13                                  ; Assembler: NASM version 2.15
    14                                  ;	     nasm playwav7.s -l playwav7.txt -o PLAYWAV7.PRG	
    15                                  ; ----------------------------------------------------------------------------
    16                                  ; Derived from '.wav file player for DOS' Jeff Leyda, Sep 02, 2002
    17                                  
    18                                  ; tuneloop (user mode) version (29/05/2024
    19                                  
    20                                  ; previous version: playwav6.s (27/11/2023)
    21                                  
    22                                  ; CODE
    23                                  
    24                                  ; 20/10/2024
    25                                  ; 20/08/2024 ; TRDOS 386 v2.0.9
    26                                  ; TRDOS 386 system calls
    27                                  _ver 	equ 0
    28                                  _exit 	equ 1
    29                                  _fork 	equ 2
    30                                  _read 	equ 3
    31                                  _write	equ 4
    32                                  _open	equ 5
    33                                  _close 	equ 6
    34                                  _wait 	equ 7
    35                                  _creat 	equ 8
    36                                  _rename equ 9
    37                                  _delete equ 10
    38                                  _exec	equ 11
    39                                  _chdir	equ 12
    40                                  _time 	equ 13
    41                                  _mkdir 	equ 14
    42                                  _chmod	equ 15
    43                                  _rmdir	equ 16
    44                                  _break	equ 17
    45                                  _drive	equ 18
    46                                  _seek	equ 19
    47                                  _tell 	equ 20
    48                                  _mem	equ 21
    49                                  _prompt	equ 22
    50                                  _path	equ 23
    51                                  _env	equ 24
    52                                  _stime	equ 25
    53                                  _quit	equ 26
    54                                  _intr	equ 27
    55                                  _dir	equ 28
    56                                  _emt 	equ 29
    57                                  _ldvrt 	equ 30
    58                                  _video 	equ 31
    59                                  _audio	equ 32
    60                                  _timer	equ 33
    61                                  _sleep	equ 34
    62                                  _msg    equ 35
    63                                  _geterr	equ 36
    64                                  _fpsave	equ 37
    65                                  _pri	equ 38
    66                                  _rele	equ 39
    67                                  _fff	equ 40
    68                                  _fnf	equ 41
    69                                  _alloc	equ 42
    70                                  _dalloc equ 43
    71                                  _calbac equ 44
    72                                  _dma	equ 45
    73                                  _stdio  equ 46	;  TRDOS 386 v2.0.9
    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                                  ;BUFFERSIZE	equ	32768	; audio buffer size 
    98                                  ENDOFFILE       equ     1	; flag for knowing end of file
    99                                  
   100                                  [BITS 32]
   101                                  
   102                                  [ORG 0]
   103                                  
   104                                  	; 29/05/2024
   105                                  	%include 'ac97.inc' ; 17/02/2017 
     1                              <1> ; 11/11/2023
     2                              <1> ; 05/11/2023
     3                              <1> ; 03/11/2023
     4                              <1> ; 17/02/2017 (Erdogan Tan, PLAYWAV.ASM)
     5                              <1> ; constant.inc & codec.inc (for ICH AC97 wav player, 'PLAYWAV.COM') 
     6                              <1> 
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; CONSTANT.INC
     9                              <1> ; ----------------------------------------------------------------------------
    10                              <1> 
    11                              <1> ;constants of stuff that seem hard to remember at times.
    12                              <1> 
    13                              <1> TRUE  EQU 1
    14                              <1> FALSE EQU 0
    15                              <1> 
    16                              <1> ENABLED  EQU 1
    17                              <1> DISABLED EQU 0
    18                              <1> 
    19                              <1> BIT0  EQU 1
    20                              <1> BIT1  EQU 2
    21                              <1> BIT2  EQU 4
    22                              <1> BIT3  EQU 8
    23                              <1> BIT4  EQU 10h
    24                              <1> BIT5  EQU 20h
    25                              <1> BIT6  EQU 40h
    26                              <1> BIT7  EQU 80h
    27                              <1> BIT8  EQU 100h
    28                              <1> BIT9  EQU 200h
    29                              <1> BIT10 EQU 400h
    30                              <1> BIT11 EQU 800h
    31                              <1> BIT12 EQU 1000h
    32                              <1> BIT13 EQU 2000h
    33                              <1> BIT14 EQU 4000h
    34                              <1> BIT15 EQU 8000h
    35                              <1> BIT16 EQU 10000h
    36                              <1> BIT17 EQU 20000h
    37                              <1> BIT18 EQU 40000h
    38                              <1> BIT19 EQU 80000h
    39                              <1> BIT20 EQU 100000h
    40                              <1> BIT21 EQU 200000h
    41                              <1> BIT22 EQU 400000h
    42                              <1> BIT23 EQU 800000h
    43                              <1> BIT24 EQU 1000000h
    44                              <1> BIT25 EQU 2000000h
    45                              <1> BIT26 EQU 4000000h
    46                              <1> BIT27 EQU 8000000h
    47                              <1> BIT28 EQU 10000000h
    48                              <1> BIT29 EQU 20000000h
    49                              <1> BIT30 EQU 40000000h
    50                              <1> BIT31 EQU 80000000h
    51                              <1> 
    52                              <1> ;special characters
    53                              <1> NUL     EQU 0
    54                              <1> NULL    EQU 0
    55                              <1> BELL    EQU 07
    56                              <1> BS      EQU 08
    57                              <1> TAB     EQU 09
    58                              <1> LF      EQU 10
    59                              <1> CR      EQU 13
    60                              <1> ESCAPE  EQU 27           ;ESC is a reserved word....
    61                              <1> 
    62                              <1> 
    63                              <1> ;file stuff
    64                              <1> READONLY  EQU   BIT0
    65                              <1> HIDDEN    EQU   BIT1
    66                              <1> SYSTEM    EQU   BIT2
    67                              <1> VOLUME    EQU   BIT3         ;ignored for file access
    68                              <1> DIRECTORY EQU   BIT4         ;must be 0 for file access
    69                              <1> ARCHIVE   EQU   BIT5
    70                              <1> SHAREABLE EQU   BIT7         ;for novell networks
    71                              <1> OPEN	EQU	2		; open existing file
    72                              <1> CREATE	EQU	1		; create new file
    73                              <1> 
    74                              <1> 
    75                              <1> ; PCI equates
    76                              <1> ; PCI function address (PFA)
    77                              <1> ; bit 31 = 1
    78                              <1> ; bit 23:16 = bus number     (0-255)
    79                              <1> ; bit 15:11 = device number  (0-31)
    80                              <1> ; bit 10:8 = function number (0-7)
    81                              <1> ; bit 7:0 = register number  (0-255)
    82                              <1> 
    83                              <1> IO_ADDR_MASK    EQU     0FFFEh          ; mask off bit 0 for reading BARs
    84                              <1> PCI_INDEX_PORT  EQU     0CF8h
    85                              <1> PCI_DATA_PORT   EQU     0CFCh
    86                              <1> PCI32           EQU     BIT31           ; bitflag to signal 32bit access
    87                              <1> PCI16           EQU     BIT30           ; bitflag for 16bit access
    88                              <1> 
    89                              <1> PCI_FN0         EQU     0 << 8
    90                              <1> PCI_FN1         EQU     1 << 8
    91                              <1> PCI_FN2         EQU     2 << 8
    92                              <1> PCI_FN3         EQU     3 << 8
    93                              <1> PCI_FN4         EQU     4 << 8
    94                              <1> PCI_FN5         EQU     5 << 8
    95                              <1> PCI_FN6         EQU     6 << 8
    96                              <1> PCI_FN7         EQU     7 << 8
    97                              <1> 
    98                              <1> PCI_CMD_REG		EQU	04h		; reg 04, command reg
    99                              <1>  IO_ENA			EQU	BIT0		; i/o decode enable
   100                              <1>  MEM_ENA		EQU	BIT1		; memory decode enable
   101                              <1>  BM_ENA                 EQU     BIT2		; bus master enable
   102                              <1> 
   103                              <1> ; ----------------------------------------------------------------------------
   104                              <1> ; CODEC.INC
   105                              <1> ; ----------------------------------------------------------------------------
   106                              <1> 
   107                              <1> ;Codec registers.
   108                              <1> ;
   109                              <1> ;Not all codecs are created equal. Refer to the spec for your specific codec.
   110                              <1> ;
   111                              <1> ;All registers are 16bits wide.  Access to codec registers over the AC97 link
   112                              <1> ;is defined by the OEM.  
   113                              <1> ;
   114                              <1> ;Secondary codec's are accessed by ORing in BIT7 of all register accesses.
   115                              <1> ;
   116                              <1> 
   117                              <1> ; each codec/mixer register is 16bits
   118                              <1> 
   119                              <1> CODEC_RESET_REG                 equ     00      ; reset codec
   120                              <1> CODEC_MASTER_VOL_REG            equ     02      ; master volume
   121                              <1> CODEC_HP_VOL_REG                equ     04      ; headphone volume
   122                              <1> CODEC_MASTER_MONO_VOL_REG       equ     06      ; master mono volume
   123                              <1> CODEC_MASTER_TONE_REG           equ     08      ; master tone (R+L)
   124                              <1> CODEC_PCBEEP_VOL_REG            equ     0ah     ; PC beep volume
   125                              <1> CODEC_PHONE_VOL_REG             equ     0bh     ; phone volume
   126                              <1> CODEC_MIC_VOL_REG               equ     0eh     ; MIC volume
   127                              <1> CODEC_LINE_IN_VOL_REG           equ     10h     ; line input volume
   128                              <1> CODEC_CD_VOL_REG                equ     12h     ; CD volume
   129                              <1> CODEC_VID_VOL_REG               equ     14h     ; video volume
   130                              <1> CODEC_AUX_VOL_REG               equ     16h     ; aux volume
   131                              <1> CODEC_PCM_OUT_REG               equ     18h     ; PCM output volume
   132                              <1> CODEC_RECORD_SELECT_REG         equ     1ah     ; record select input
   133                              <1> CODEC_RECORD_VOL_REG            equ     1ch     ; record volume
   134                              <1> CODEC_RECORD_MIC_VOL_REG        equ     1eh     ; record mic volume
   135                              <1> CODEC_GP_REG                    equ     20h     ; general purpose
   136                              <1> CODEC_3D_CONTROL_REG            equ     22h     ; 3D control
   137                              <1> ; 24h is reserved
   138                              <1> CODEC_POWER_CTRL_REG            equ     26h     ; powerdown control
   139                              <1> CODEC_EXT_AUDIO_REG             equ     28h     ; extended audio
   140                              <1> CODEC_EXT_AUDIO_CTRL_REG        equ     2ah     ; extended audio control
   141                              <1> CODEC_PCM_FRONT_DACRATE_REG     equ     2ch     ; PCM out sample rate
   142                              <1> CODEC_PCM_SURND_DACRATE_REG     equ     2eh     ; surround sound sample rate
   143                              <1> CODEC_PCM_LFE_DACRATE_REG       equ     30h     ; LFE sample rate
   144                              <1> CODEC_LR_ADCRATE_REG            equ     32h     ; PCM in sample rate
   145                              <1> CODEC_MIC_ADCRATE_REG           equ     34h     ; mic in sample rate
   146                              <1> 
   147                              <1> ; registers 36-7a are reserved on the ICH
   148                              <1> 
   149                              <1> CODEC_VENDORID1_REG             equ     7ch     ; codec vendor ID 1
   150                              <1> CODEC_VENDORID2_REG             equ     7eh     ; codec vendor ID 2
   151                              <1> 
   152                              <1> ; Mixer registers 0 through 51h reside in the ICH and are not forwarded over
   153                              <1> ; the AC97 link to the codec, which I think is a little weird.  Looks like
   154                              <1> ; the ICH makes it so you don't need a fully functional codec to play audio?
   155                              <1> ;
   156                              <1> ; whenever 2 codecs are present in the system, use BIT7 to access the 2nd
   157                              <1> ; set of registers, ie 80h-feh
   158                              <1> 
   159                              <1> PRIMARY_CODEC                   equ     0       ; 0-7F for primary codec
   160                              <1> SECONDARY_CODEC                 equ     BIT7    ; 80-8f registers for 2ndary
   161                              <1> 
   162                              <1> SAMPLE_RATE_441khz	equ     44100   ; 44.1Khz (cd quality) rate
   163                              <1> 
   164                              <1> ; ----------------------------------------------------------------------------
   165                              <1> ; 17/02/2017
   166                              <1> PCI_IO_BASE	equ 10h			; = NAMBAR register offset
   167                              <1> AC97_INT_LINE   equ 3Ch			; AC97 Interrupt Line register offset
   168                              <1> 
   169                              <1> ; ----------------------------------------------------------------------------
   170                              <1> ; ICH2AC97.INC
   171                              <1> ; ----------------------------------------------------------------------------
   172                              <1> 
   173                              <1> ; PCI stuff
   174                              <1> 
   175                              <1> ; Intel ICH2 equates. It is assumed that ICH0 and plain ole ICH are compatible.
   176                              <1> 
   177                              <1> INTEL_VID       equ     8086h           ; Intel's PCI vendor ID
   178                              <1> ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
   179                              <1> SIS_VID		equ	1039h
   180                              <1> NVIDIA_VID	equ	10DEh	 ; Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source c.
   181                              <1> AMD_VID		equ	1022h
   182                              <1> 
   183                              <1> ICH_DID         equ     2415h           ; ICH device ID
   184                              <1> ICH0_DID        equ     2425h           ; ICH0
   185                              <1> ICH2_DID        equ     2445h           ; ICH2 I think there are more ICHes.
   186                              <1>                                         ; they all should be compatible.
   187                              <1> 
   188                              <1> ; 17/02/2017 (Erdogan Tan, ref: ALSA Device IDs, ALSA project)
   189                              <1> ICH3_DID	equ     2485h           ; ICH3
   190                              <1> ICH4_DID        equ     24C5h           ; ICH4
   191                              <1> ICH5_DID	equ     24D5h           ; ICH5 
   192                              <1> ICH6_DID	equ     266Eh           ; ICH6
   193                              <1> ESB6300_DID	equ     25A6h           ; 6300ESB
   194                              <1> ESB631X_DID	equ     2698h           ; 631XESB
   195                              <1> ICH7_DID	equ	27DEh		; ICH7
   196                              <1> ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
   197                              <1> MX82440_DID	equ	7195h
   198                              <1> SI7012_DID	equ	7012h
   199                              <1> NFORCE_DID	equ	01B1h
   200                              <1> NFORCE2_DID	equ	006Ah
   201                              <1> AMD8111_DID	equ	746Dh
   202                              <1> AMD768_DID	equ	7445h
   203                              <1> ; 03/11/2023 - Erdogan Tan - Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source code
   204                              <1> CK804_DID	equ	0059h
   205                              <1> MCP04_DID	equ	003Ah
   206                              <1> CK8_DID		equ	008Ah
   207                              <1> NFORCE3_DID	equ	00DAh
   208                              <1> CK8S_DID	equ	00EAh
   209                              <1> 
   210                              <1> NAMBAR_REG      equ     10h             ; native audio mixer BAR
   211                              <1>  NAM_SIZE       equ     256             ; 256 bytes required.
   212                              <1> 
   213                              <1> NABMBAR_REG     equ     14h             ; native audio bus mastering BAR
   214                              <1>  NABM_SIZE      equ     64              ; 64 bytes
   215                              <1> 
   216                              <1> ; BUS master registers, accessed via NABMBAR+offset
   217                              <1> 
   218                              <1> ; ICH supports 3 different types of register sets for three types of things
   219                              <1> ; it can do, thus:
   220                              <1> ;
   221                              <1> ; PCM in (for recording) aka PI
   222                              <1> ; PCM out (for playback) aka PO
   223                              <1> ; MIC in (for recording) aka MC
   224                              <1> 
   225                              <1> PI_BDBAR_REG            equ     0       ; PCM in buffer descriptor BAR
   226                              <1> PO_BDBAR_REG            equ     10h     ; PCM out buffer descriptor BAR
   227                              <1> MC_BDBAR_REG            equ     20h     ; MIC in buffer descriptor BAR
   228                              <1> 
   229                              <1> ; each buffer descriptor BAR holds a pointer which has entries to the buffer
   230                              <1> ; contents of the .WAV file we're going to play. Each entry is 8 bytes long
   231                              <1> ; (more on that later) and can contain 32 entries total, so each BAR is
   232                              <1> ; 256 bytes in length, thus:
   233                              <1> 
   234                              <1> BDL_SIZE                equ     32*8    ; Buffer Descriptor List size
   235                              <1> INDEX_MASK              equ     31      ; indexes must be 0-31
   236                              <1> 
   237                              <1> 
   238                              <1> 
   239                              <1> PI_CIV_REG              equ     4       ; PCM in current Index value (RO)
   240                              <1> PO_CIV_REG              equ     14h     ; PCM out current Index value (RO)
   241                              <1> MC_CIV_REG              equ     24h     ; MIC in current Index value (RO)
   242                              <1> ;8bit read only
   243                              <1> ; each current index value is simply a pointer showing us which buffer
   244                              <1> ; (0-31) the codec is currently processing. Once this counter hits 31, it
   245                              <1> ; wraps back to 0.
   246                              <1> ; this can be handy to know, as once it hits 31, we're almost out of data to
   247                              <1> ; play back or room to record!
   248                              <1> 
   249                              <1> 
   250                              <1> PI_LVI_REG              equ     5       ; PCM in Last Valid Index
   251                              <1> PO_LVI_REG              equ     15h     ; PCM out Last Valid Index
   252                              <1> MC_LVI_REG              equ     25h     ; MIC in Last Valid Index
   253                              <1> ;8bit read/write
   254                              <1> ; The Last Valid Index is a number (0-31) to let the codec know what buffer
   255                              <1> ; number to stop on after processing. It could be very nasty to play audio
   256                              <1> ; from buffers that aren't filled with the audio we want to play.
   257                              <1> 
   258                              <1> 
   259                              <1> PI_SR_REG               equ     6       ; PCM in Status register
   260                              <1> PO_SR_REG               equ     16h     ; PCM out Status register
   261                              <1> MC_SR_REG               equ     26h     ; MIC in Status register
   262                              <1> ;16bit read/write
   263                              <1> ; status registers.  Bitfields follow:
   264                              <1> 
   265                              <1> FIFO_ERR                equ     BIT4    ; FIFO Over/Underrun W1TC.
   266                              <1> 
   267                              <1> BCIS                    equ     BIT3    ; buffer completion interrupt status.
   268                              <1>                                         ; Set whenever the last sample in ANY
   269                              <1>                                         ; buffer is finished.  Bit is only
   270                              <1>                                         ; set when the Interrupt on Complete
   271                              <1>                                         ; (BIT4 of control reg) is set.
   272                              <1> 
   273                              <1> LVBCI                   equ     BIT2    ; Set whenever the codec has processed
   274                              <1>                                         ; the last buffer in the buffer list.
   275                              <1>                                         ; Will fire an interrupt if IOC bit is
   276                              <1>                                         ; set. Probably set after the last
   277                              <1>                                         ; sample in the last buffer is
   278                              <1>                                         ; processed.  W1TC
   279                              <1> 
   280                              <1>                                         ; 
   281                              <1> CELV                    equ     BIT1    ; Current buffer == last valid.
   282                              <1>                                         ; Bit is RO and remains set until LVI is
   283                              <1>                                         ; cleared.  Probably set up the start
   284                              <1>                                         ; of processing for the last buffer.
   285                              <1> 
   286                              <1> 
   287                              <1> DCH                     equ     BIT0    ; DMA controller halted.
   288                              <1>                                         ; set whenever audio stream is stopped
   289                              <1>                                         ; or something else goes wrong.
   290                              <1> 
   291                              <1> 
   292                              <1> PI_PICB_REG             equ     8       ; PCM in position in current buffer(RO)
   293                              <1> PO_PICB_REG             equ     18h     ; PCM out position in current buffer(RO)
   294                              <1> MC_PICB_REG             equ     28h     ; MIC in position in current buffer (RO)
   295                              <1> ;16bit read only
   296                              <1> ; position in current buffer regs show the number of dwords left to be
   297                              <1> ; processed in the current buffer.
   298                              <1> ; 
   299                              <1> 
   300                              <1> PI_PIV_REG              equ     0ah     ; PCM in Prefected index value
   301                              <1> PO_PIV_REG              equ     1ah     ; PCM out Prefected index value
   302                              <1> MC_PIV_REG              equ     2ah     ; MIC in Prefected index value
   303                              <1> ;8bit, read only
   304                              <1> ; Prefetched index value register.
   305                              <1> ; tells which buffer number (0-31) has be prefetched. I'd imagine this
   306                              <1> ; value follows the current index value fairly closely. (CIV+1)
   307                              <1> ;
   308                              <1> 
   309                              <1> 
   310                              <1> PI_CR_REG               equ     0bh     ; PCM in Control Register
   311                              <1> PO_CR_REG               equ     1bh     ; PCM out Control Register
   312                              <1> MC_CR_REG               equ     2bh     ; MIC in Control Register
   313                              <1> ; 8bit
   314                              <1> ; Control register *MUST* only be accessed as an 8bit value.
   315                              <1> ; Control register. See bitfields below.
   316                              <1> ;
   317                              <1> 
   318                              <1> 
   319                              <1> IOCE                    equ     BIT4    ; interrupt on complete enable.
   320                              <1>                                         ; set this bit if you want an intrtpt
   321                              <1>                                         ; to fire whenever LVBCI is set.
   322                              <1> FEIFE                   equ     BIT3    ; set if you want an interrupt to fire
   323                              <1>                                         ; whenever there is a FIFO (over or
   324                              <1>                                         ; under) error.
   325                              <1> LVBIE                   equ     BIT2    ; last valid buffer interrupt enable.
   326                              <1>                                         ; set if you want an interrupt to fire
   327                              <1>                                         ; whenever the completion of the last
   328                              <1>                                         ; valid buffer.
   329                              <1> RR                      equ     BIT1    ; reset registers.  Nukes all regs
   330                              <1>                                         ; except bits 4:2 of this register.
   331                              <1>                                         ; Only set this bit if BIT 0 is 0
   332                              <1> RPBM                    equ     BIT0    ; Run/Pause
   333                              <1>                                         ; set this bit to start the codec!
   334                              <1> 
   335                              <1> 
   336                              <1> GLOB_CNT_REG            equ     2ch     ; Global control register
   337                              <1> SEC_RES_EN              equ     BIT5    ; secondary codec resume event 
   338                              <1>                                         ; interrupt enable.  Not used here.
   339                              <1> PRI_RES_EN              equ     BIT4    ; ditto for primary. Not used here.
   340                              <1> ACLINK_OFF              equ     BIT3    ; Turn off the AC97 link
   341                              <1> ACWARM_RESET            equ     BIT2    ; Awaken the AC97 link from sleep.
   342                              <1>                                         ; registers preserved, bit self clears
   343                              <1> ACCOLD_RESET            equ     BIT1    ; Reset everything in the AC97 and
   344                              <1>                                         ; reset all registers.  Not self clearing
   345                              <1> 
   346                              <1> GPIIE                   equ     BIT0    ; GPI Interrupt enable.
   347                              <1>                                         ; set if you want an interrupt to
   348                              <1>                                         ; fire upon ANY of the bits in the
   349                              <1>                                         ; GPI (general pursose inputs?) not used.
   350                              <1> 
   351                              <1> GLOB_STS_REG            equ     30h     ; Global Status register (RO)
   352                              <1> 
   353                              <1> MD3                     equ     BIT17   ; modem powerdown status (yawn)
   354                              <1> AD3                     equ     BIT16   ; Audio powerdown status (yawn)
   355                              <1> RD_COMPLETE_STS         equ     BIT15   ; Codec read timed out. 0=normal
   356                              <1> BIT3SLOT12              equ     BIT14   ; shadowed status of bit 3 in slot 12
   357                              <1> BIT2SLOT12              equ     BIT13   ; shadowed status of bit 2 in slot 12
   358                              <1> BIT1SLOT12              equ     BIT12   ; shadowed status of bit 1 in slot 12
   359                              <1> SEC_RESUME_STS          equ     BIT11   ; secondary codec has resumed (and irqed)
   360                              <1> PRI_RESUME_STS          equ     BIT10   ; primary codec has resumed (and irqed)
   361                              <1> SEC_CODEC_RDY           equ     BIT9    ; secondary codec is ready for action
   362                              <1> PRI_CODEC_RDY           equ     BIT8    ; Primary codec is ready for action
   363                              <1>                                         ; software must check these bits before
   364                              <1>                                         ; starting the codec!
   365                              <1> MIC_IN_IRQ              equ     BIT7    ; MIC in caused an interrupt
   366                              <1> PCM_OUT_IRQ             equ     BIT6    ; One of the PCM out channels IRQed
   367                              <1> PCM_IN_IRQ              equ     BIT5    ; One of the PCM in channels IRQed
   368                              <1> MODEM_OUT_IRQ           equ     BIT2    ; modem out channel IRQed
   369                              <1> MODEM_IN_IRQ            equ     BIT1    ; modem in channel IRQed
   370                              <1> GPI_STS_CHANGE          equ     BIT0    ; set whenever GPI's have changed.
   371                              <1>                                         ; BIT0 of slot 12 also reflects this.
   372                              <1> 
   373                              <1> ACC_SEMA_REG            equ     34h     ; Codec write semiphore register
   374                              <1> CODEC_BUSY              equ     BIT0    ; codec register I/O is happening
   375                              <1>                                         ; self clearing
   376                              <1> ;
   377                              <1> ; Buffer Descriptors List
   378                              <1> ; As stated earlier, each buffer descriptor list is a set of (up to) 32 
   379                              <1> ; descriptors, each 8 bytes in length. Bytes 0-3 of a descriptor entry point
   380                              <1> ; to a chunk of memory to either play from or record to. Bytes 4-7 of an
   381                              <1> ; entry describe various control things detailed below.
   382                              <1> ; 
   383                              <1> ; Buffer pointers must always be aligned on a Dword boundry.
   384                              <1> ;
   385                              <1> 
   386                              <1> IOC                     equ     BIT31   ; Fire an interrupt whenever this
   387                              <1>                                         ; buffer is complete.
   388                              <1> 
   389                              <1> BUP                     equ     BIT30   ; Buffer Underrun Policy.
   390                              <1>                                         ; if this buffer is the last buffer
   391                              <1>                                         ; in a playback, fill the remaining
   392                              <1>                                         ; samples with 0 (silence) or not.
   393                              <1>                                         ; It's a good idea to set this to 1
   394                              <1>                                         ; for the last buffer in playback,
   395                              <1>                                         ; otherwise you're likely to get a lot
   396                              <1>                                         ; of noise at the end of the sound.
   397                              <1> 
   398                              <1> ;
   399                              <1> ; Bits 15:0 contain the length of the buffer, in number of samples, which
   400                              <1> ; are 16 bits each, coupled in left and right pairs, or 32bits each.
   401                              <1> ; Luckily for us, that's the same format as .wav files.
   402                              <1> ;
   403                              <1> ; A value of FFFF is 65536 samples. Running at 44.1Khz, that's just about
   404                              <1> ; 1.5 seconds of sample time. FFFF * 32bits is 1FFFFh bytes or 128k of data.
   405                              <1> ;
   406                              <1> ; A value of 0 in these bits means play no samples.
   407                              <1> ;
   408                              <1> 
   409                              <1> ; 11/11/2023
   410                              <1> CTRL_ST_CREADY		equ	BIT8+BIT9+BIT28 ; Primary Codec Ready
   411                              <1> CODEC_REG_POWERDOWN	equ	26h
   106                                  
   107                                  _STARTUP:
   108                                  	; Prints the Credits Text.
   109                                  	sys	_msg, Credits, 255, 0Bh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000000 BB[83260000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000005 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000000A BA0B000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000000F B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000014 CD40                <1>  int 40h
   110                                  
   111                                  	; clear bss
   112 00000016 B9[4E2A0000]            	mov	ecx, bss_end
   113 0000001B BF[C2290000]            	mov	edi, bss_start
   114 00000020 29F9                    	sub	ecx, edi
   115 00000022 D1E9                    	shr	ecx, 1
   116 00000024 31C0                    	xor	eax, eax
   117 00000026 F366AB                  	rep	stosw
   118                                  
   119                                  	; Detect (& Enable) AC'97 Audio Device
   120 00000029 E855050000              	call	DetectAC97
   121 0000002E 731B                    	jnc     short GetFileName
   122                                  
   123                                  _dev_not_ready:
   124                                  	; couldn't find the audio device!
   125                                  	sys	_msg, noDevMsg, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000030 BB[65270000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000035 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000003A BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000003F B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000044 CD40                <1>  int 40h
   126 00000046 E9C1030000                      jmp     Exit
   127                                  
   128                                  GetFileName:  
   129 0000004B 89E6                    	mov	esi, esp
   130 0000004D AD                      	lodsd
   131 0000004E 83F802                  	cmp	eax, 2 ; two arguments 
   132                                  	       ; (program file name & mod file name)
   133 00000051 0F82C3030000            	jb	pmsg_usage ; nothing to do
   134                                  
   135 00000057 AD                      	lodsd ; program file name address 
   136 00000058 AD                      	lodsd ; mod file name address (file to be read)
   137 00000059 89C6                    	mov	esi, eax
   138 0000005B BF[E6290000]            	mov	edi, wav_file_name
   139                                  ScanName:       
   140 00000060 AC                      	lodsb
   141 00000061 84C0                    	test	al, al
   142 00000063 0F84B1030000            	je	pmsg_usage
   143 00000069 3C20                    	cmp	al, 20h
   144 0000006B 74F3                    	je	short ScanName	; scan start of name.
   145 0000006D AA                      	stosb
   146 0000006E B4FF                    	mov	ah, 0FFh
   147                                  a_0:	
   148 00000070 FEC4                    	inc	ah
   149                                  a_1:
   150 00000072 AC                      	lodsb
   151 00000073 AA                      	stosb
   152 00000074 3C2E                    	cmp	al, '.'
   153 00000076 74F8                    	je	short a_0	
   154 00000078 20C0                    	and	al, al
   155 0000007A 75F6                    	jnz	short a_1
   156                                  
   157 0000007C 08E4                    	or	ah, ah		; if period NOT found,
   158 0000007E 750B                    	jnz	short _1 	; then add a .WAV extension.
   159                                  SetExt:
   160 00000080 4F                      	dec	edi
   161 00000081 C7072E574156            	mov	dword [edi], '.WAV'
   162 00000087 C6470400                	mov	byte [edi+4], 0
   163                                  
   164                                  _1:
   165 0000008B E890060000              	call	write_audio_dev_info 
   166                                  
   167                                  ; open the file
   168                                          ; open existing file
   169 00000090 E83E050000                      call    openFile ; no error? ok.
   170 00000095 731B                            jnc     short _gsr
   171                                  
   172                                  ; file not found!
   173                                  	sys	_msg, noFileErrMsg, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000097 BB[90270000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000009C B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000000A1 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000000A6 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000000AB CD40                <1>  int 40h
   174                                  _exit_:
   175 000000AD E95A030000                      jmp     Exit
   176                                  
   177                                  _gsr:  
   178 000000B2 E856050000                     	call    getSampleRate		; read the sample rate
   179                                                                          ; pass it onto codec.
   180                                  	; 25/11/2023
   181 000000B7 72F4                    	jc	short _exit_		; nothing to do
   182                                  
   183 000000B9 66A3[C6290000]          	mov	[sample_rate], ax
   184 000000BF 880D[C4290000]          	mov	[stmo], cl
   185 000000C5 8815[C5290000]          	mov	[bps], dl
   186                                  
   187                                  	; 26/11/2023
   188 000000CB C605[392A0000]00        	mov	byte [fbs_shift], 0 ; 0 = stereo and 16 bit 
   189 000000D2 FEC9                    	dec	cl
   190 000000D4 7506                    	jnz	short _gsr_1 ; stereo
   191 000000D6 FE05[392A0000]          	inc	byte [fbs_shift] ; 1 = mono or 8 bit		
   192                                  _gsr_1:	
   193 000000DC 80FA08                  	cmp	dl, 8 
   194 000000DF 7706                    	ja	short _gsr_2 ; 16 bit samples
   195 000000E1 FE05[392A0000]          	inc	byte [fbs_shift] ; 2 = mono and 8 bit
   196                                  _gsr_2:	
   197                                  	; 29/05/2024
   198 000000E7 E816070000              	call	write_ac97_pci_dev_info
   199                                  
   200                                  	; 31/05/2024
   201                                  	; 30/05/2024
   202                                  	;call	check_vra
   203                                  
   204                                  	; 30/05/2024
   205 000000EC E8EB210000              	call	codecConfig		; unmute codec, set rates.
   206 000000F1 0F823B030000            	jc	init_err
   207                                  
   208                                  	; 25/11/2023
   209 000000F7 E8C6080000              	call	write_VRA_info
   210                                  
   211                                  	; 01/05/2017
   212 000000FC E836060000              	call	write_wav_file_info
   213                                  
   214                                  	; 25/11/2023
   215                                  	; ------------------------------------------
   216                                  
   217 00000101 803D[C9290000]01        	cmp	byte [VRA], 1
   218 00000108 7205                    	jb	short chk_sample_rate
   219                                  
   220                                  playwav_48_khz:	
   221                                  	;mov	dword [loadfromwavfile], loadFromFile
   222                                  	;mov	dword [buffersize], 65536
   223 0000010A E9B1020000              	jmp	PlayNow
   224                                  
   225                                  	; 02/02/2025
   226                                  chk_sample_rate:
   227                                  	; set conversion parameters
   228                                  	; (for 8, 11.025, 16, 22.050, 24, 32 kHZ)
   229 0000010F 66A1[C6290000]          	mov	ax, [sample_rate]
   230 00000115 663D80BB                	cmp	ax, 48000
   231 00000119 74EF                    	je	short playwav_48_khz
   232                                  chk_22khz:
   233 0000011B 663D2256                	cmp	ax, 22050
   234 0000011F 7545                    	jne	short chk_11khz
   235 00000121 803D[C5290000]08        	cmp	byte [bps], 8
   236 00000128 7615                    	jna	short chk_22khz_1
   237 0000012A BB[69160000]            	mov	ebx, load_22khz_stereo_16_bit
   238 0000012F 803D[C4290000]01        	cmp	byte [stmo], 1 
   239 00000136 751A                    	jne	short chk_22khz_2
   240 00000138 BB[DB150000]            	mov	ebx, load_22khz_mono_16_bit
   241 0000013D EB13                    	jmp	short chk_22khz_2
   242                                  chk_22khz_1:
   243 0000013F BB[53150000]            	mov	ebx, load_22khz_stereo_8_bit
   244 00000144 803D[C4290000]01        	cmp	byte [stmo], 1 
   245 0000014B 7505                    	jne	short chk_22khz_2
   246 0000014D BB[C9140000]            	mov	ebx, load_22khz_mono_8_bit
   247                                  chk_22khz_2:
   248 00000152 B85A1D0000              	mov	eax, 7514  ; (442*17)
   249 00000157 BA25000000              	mov	edx, 37
   250 0000015C B911000000              	mov	ecx, 17 
   251 00000161 E9BA010000              	jmp	set_sizes	
   252                                  chk_11khz:
   253 00000166 663D112B                	cmp	ax, 11025
   254 0000016A 7545                    	jne	short chk_44khz
   255 0000016C 803D[C5290000]08        	cmp	byte [bps], 8
   256 00000173 7615                    	jna	short chk_11khz_1
   257 00000175 BB[89180000]            	mov	ebx, load_11khz_stereo_16_bit
   258 0000017A 803D[C4290000]01        	cmp	byte [stmo], 1 
   259 00000181 751A                    	jne	short chk_11khz_2
   260 00000183 BB[0F180000]            	mov	ebx, load_11khz_mono_16_bit
   261 00000188 EB13                    	jmp	short chk_11khz_2
   262                                  chk_11khz_1:
   263 0000018A BB[94170000]            	mov	ebx, load_11khz_stereo_8_bit
   264 0000018F 803D[C4290000]01        	cmp	byte [stmo], 1 
   265 00000196 7505                    	jne	short chk_11khz_2
   266 00000198 BB[1B170000]            	mov	ebx, load_11khz_mono_8_bit
   267                                  chk_11khz_2:
   268 0000019D B8AD0E0000              	mov	eax, 3757  ; (221*17)
   269 000001A2 BA4A000000              	mov	edx, 74
   270 000001A7 B911000000              	mov	ecx, 17
   271 000001AC E96F010000              	jmp	set_sizes 
   272                                  chk_44khz:
   273 000001B1 663D44AC                	cmp	ax, 44100
   274 000001B5 7545                    	jne	short chk_16khz
   275 000001B7 803D[C5290000]08        	cmp	byte [bps], 8
   276 000001BE 7615                    	jna	short chk_44khz_1
   277 000001C0 BB[941A0000]            	mov	ebx, load_44khz_stereo_16_bit
   278 000001C5 803D[C4290000]01        	cmp	byte [stmo], 1 
   279 000001CC 751A                    	jne	short chk_44khz_2
   280 000001CE BB[1A1A0000]            	mov	ebx, load_44khz_mono_16_bit
   281 000001D3 EB13                    	jmp	short chk_44khz_2
   282                                  chk_44khz_1:
   283 000001D5 BB[9C190000]            	mov	ebx, load_44khz_stereo_8_bit
   284 000001DA 803D[C4290000]01        	cmp	byte [stmo], 1 
   285 000001E1 7505                    	jne	short chk_44khz_2
   286 000001E3 BB[1F190000]            	mov	ebx, load_44khz_mono_8_bit
   287                                  chk_44khz_2:
   288 000001E8 B8D93A0000              	mov	eax, 15065 ; (655*23)
   289 000001ED BA19000000              	mov	edx, 25
   290 000001F2 B917000000              	mov	ecx, 23
   291 000001F7 E924010000              	jmp	set_sizes 
   292                                  chk_16khz:
   293 000001FC 663D803E                	cmp	ax, 16000
   294 00000200 7545                    	jne	short chk_8khz
   295 00000202 803D[C5290000]08        	cmp	byte [bps], 8
   296 00000209 7615                    	jna	short chk_16khz_1
   297 0000020B BB[FF0F0000]            	mov	ebx, load_16khz_stereo_16_bit
   298 00000210 803D[C4290000]01        	cmp	byte [stmo], 1 
   299 00000217 751A                    	jne	short chk_16khz_2
   300 00000219 BB[7D0F0000]            	mov	ebx, load_16khz_mono_16_bit
   301 0000021E EB13                    	jmp	short chk_16khz_2
   302                                  chk_16khz_1:
   303 00000220 BB[C20E0000]            	mov	ebx, load_16khz_stereo_8_bit
   304 00000225 803D[C4290000]01        	cmp	byte [stmo], 1 
   305 0000022C 7505                    	jne	short chk_16khz_2
   306 0000022E BB[420E0000]            	mov	ebx, load_16khz_mono_8_bit
   307                                  chk_16khz_2:
   308 00000233 B855150000              	mov	eax, 5461
   309 00000238 BA03000000              	mov	edx, 3
   310 0000023D B901000000              	mov	ecx, 1
   311 00000242 E9D9000000              	jmp	set_sizes 
   312                                  chk_8khz:
   313 00000247 663D401F                	cmp	ax, 8000
   314 0000024B 7545                    	jne	short chk_24khz
   315 0000024D 803D[C5290000]08        	cmp	byte [bps], 8
   316 00000254 7615                    	jna	short chk_8khz_1
   317 00000256 BB[F60C0000]            	mov	ebx, load_8khz_stereo_16_bit
   318 0000025B 803D[C4290000]01        	cmp	byte [stmo], 1 
   319 00000262 751A                    	jne	short chk_8khz_2
   320 00000264 BB[250C0000]            	mov	ebx, load_8khz_mono_16_bit
   321 00000269 EB13                    	jmp	short chk_8khz_2
   322                                  chk_8khz_1:
   323 0000026B BB[F40A0000]            	mov	ebx, load_8khz_stereo_8_bit
   324 00000270 803D[C4290000]01        	cmp	byte [stmo], 1 
   325 00000277 7505                    	jne	short chk_8khz_2
   326 00000279 BB[0F0A0000]            	mov	ebx, load_8khz_mono_8_bit
   327                                  chk_8khz_2:
   328 0000027E B8AA0A0000              	mov	eax, 2730
   329 00000283 BA06000000              	mov	edx, 6
   330 00000288 B901000000              	mov	ecx, 1
   331 0000028D E98E000000              	jmp	set_sizes 
   332                                  chk_24khz:
   333 00000292 663DC05D                	cmp	ax, 24000
   334 00000296 7542                    	jne	short chk_32khz
   335 00000298 803D[C5290000]08        	cmp	byte [bps], 8
   336 0000029F 7615                    	jna	short chk_24khz_1
   337 000002A1 BB[30120000]            	mov	ebx, load_24khz_stereo_16_bit
   338 000002A6 803D[C4290000]01        	cmp	byte [stmo], 1 
   339 000002AD 751A                    	jne	short chk_24khz_2
   340 000002AF BB[C9110000]            	mov	ebx, load_24khz_mono_16_bit
   341 000002B4 EB13                    	jmp	short chk_24khz_2
   342                                  chk_24khz_1:
   343 000002B6 BB[3E110000]            	mov	ebx, load_24khz_stereo_8_bit
   344 000002BB 803D[C4290000]01        	cmp	byte [stmo], 1 
   345 000002C2 7505                    	jne	short chk_24khz_2
   346 000002C4 BB[D6100000]            	mov	ebx, load_24khz_mono_8_bit
   347                                  chk_24khz_2:
   348 000002C9 B800200000              	mov	eax, 8192
   349 000002CE BA02000000              	mov	edx, 2
   350 000002D3 B901000000              	mov	ecx, 1
   351 000002D8 EB46                    	jmp	short set_sizes 
   352                                  chk_32khz:
   353 000002DA 663D007D                	cmp	ax, 32000
   354                                  	;jne	short vra_needed
   355                                  	; 02/02/2025
   356 000002DE 7574                    	jne	short chk_12khz
   357 000002E0 803D[C5290000]08        	cmp	byte [bps], 8
   358 000002E7 7615                    	jna	short chk_32khz_1
   359 000002E9 BB[38140000]            	mov	ebx, load_32khz_stereo_16_bit
   360 000002EE 803D[C4290000]01        	cmp	byte [stmo], 1 
   361 000002F5 751A                    	jne	short chk_32khz_2
   362 000002F7 BB[CA130000]            	mov	ebx, load_32khz_mono_16_bit
   363 000002FC EB13                    	jmp	short chk_32khz_2
   364                                  chk_32khz_1:
   365 000002FE BB[2C130000]            	mov	ebx, load_32khz_stereo_8_bit
   366 00000303 803D[C4290000]01        	cmp	byte [stmo], 1 
   367 0000030A 7505                    	jne	short chk_32khz_2
   368 0000030C BB[B8120000]            	mov	ebx, load_32khz_mono_8_bit
   369                                  chk_32khz_2:
   370 00000311 B8AA2A0000              	mov	eax, 10922
   371 00000316 BA03000000              	mov	edx, 3
   372 0000031B B902000000              	mov	ecx, 2
   373                                  	;jmp	short set_sizes
   374                                  
   375                                  set_sizes:
   376 00000320 803D[C4290000]01        	cmp	byte [stmo], 1
   377 00000327 7402                    	je	short ss_1
   378 00000329 D1E0                    	shl	eax, 1
   379                                  ss_1:
   380 0000032B 803D[C5290000]08        	cmp	byte [bps], 8
   381 00000332 7602                    	jna	short ss_2
   382                                  	; 16 bit samples
   383 00000334 D1E0                    	shl	eax, 1
   384                                  ss_2:
   385 00000336 A3[B8030000]            	mov	[loadsize], eax
   386 0000033B F7E2                    	mul	edx
   387                                  	;cmp	ecx, 1
   388                                  	;je	short ss_3
   389                                  ;ss_3:
   390 0000033D F7F1                    	div	ecx
   391 0000033F 8A0D[392A0000]          	mov	cl, [fbs_shift]
   392 00000345 D3E0                    	shl	eax, cl
   393                                  	; 26/11/2023
   394                                  	;shr	eax, 1	; buffer size is 16 bit sample count
   395 00000347 A3[BC030000]            	mov	[buffersize], eax ; buffer size in bytes
   396 0000034C 891D[B4030000]          	mov	[loadfromwavfile], ebx
   397 00000352 EB6C                    	jmp	short PlayNow
   398                                  
   399                                  	;;;;
   400                                  	; 02/02/2025
   401                                  chk_12khz:
   402 00000354 663DE02E                	cmp	ax, 12000
   403 00000358 7542                    	jne	short vra_needed
   404 0000035A 803D[C5290000]08        	cmp	byte [bps], 8
   405 00000361 7615                    	jna	short chk_12khz_1
   406 00000363 BB[041C0000]            	mov	ebx, load_12khz_stereo_16_bit
   407 00000368 803D[C4290000]01        	cmp	byte [stmo], 1
   408 0000036F 751A                    	jne	short chk_12khz_2
   409 00000371 BB[B41B0000]            	mov	ebx, load_12khz_mono_16_bit
   410 00000376 EB13                    	jmp	short chk_12khz_2
   411                                  chk_12khz_1:
   412 00000378 BB[5D1B0000]            	mov	ebx, load_12khz_stereo_8_bit
   413 0000037D 803D[C4290000]01        	cmp	byte [stmo], 1
   414 00000384 7505                    	jne	short chk_12khz_2
   415 00000386 BB[141B0000]            	mov	ebx, load_12khz_mono_8_bit
   416                                  chk_12khz_2:
   417 0000038B B800100000              	mov	eax, 4096
   418 00000390 BA04000000              	mov	edx, 4
   419 00000395 B901000000              	mov	ecx, 1
   420 0000039A EB84                    	jmp	set_sizes
   421                                  	;;;;
   422                                  
   423                                  vra_needed:
   424                                  	sys	_msg, msg_no_vra, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000039C BB[FA270000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000003A1 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000003A6 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000003AB B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000003B0 CD40                <1>  int 40h
   425 000003B2 EB58                    	jmp	Exit
   426                                  
   427                                  	; 26/11/2023
   428                                  	; 13/11/2023
   429                                  loadfromwavfile:
   430 000003B4 [6B060000]              	dd	loadFromFile
   431                                  loadsize:	; read from wav file
   432 000003B8 00000000                	dd	0
   433                                  buffersize:	; write to DMA buffer
   434 000003BC 00000100                	dd	65536 ; bytes
   435                                  
   436                                  PlayNow: 
   437                                  
   438                                  ; 26/11/2023
   439                                  %if 0
   440                                  	; Allocate Audio Buffer (for user)
   441                                  	;sys	_audio, 0200h, BUFFERSIZE, audio_buffer
   442                                  	; 26/11/2023
   443                                  	sys	_audio, 0200h, [buffersize], audio_buffer
   444                                  	jnc	short _2
   445                                  
   446                                  	; 26/11/2023 - temporary
   447                                  	;sys	_msg, test_1, 255, 0Ch
   448                                  
   449                                  error_exit:
   450                                  	sys	_msg, trdos386_err_msg, 255, 0Eh
   451                                  	jmp	Exit
   452                                  _2:
   453                                  	; DIRECT CGA (TEXT MODE) MEMORY ACCESS
   454                                  	; bl = 0, bh = 4
   455                                  	; Direct access/map to CGA (Text) memory (0B8000h)
   456                                  
   457                                  	sys	_video, 0400h
   458                                  	cmp	eax, 0B8000h
   459                                  	jne	short error_exit
   460                                  
   461                                  	; Initialize Audio Device (bh = 3)
   462                                  	sys	_audio, 0301h, 0, audio_int_handler 
   463                                  ;	jc	short error_exit
   464                                  _3:
   465                                  
   466                                  %else
   467                                  	; 29/05/2024
   468                                  	; playwav4.asm
   469                                  _2:	
   470 000003C0 E813220000              	call	check4keyboardstop	; flush keyboard buffer
   471 000003C5 72F9                    	jc	short _2		; 07/11/2023
   472                                  
   473                                   	;call	codecConfig		; unmute codec, set rates.
   474                                  	; 11/11/2023
   475                                  	;jc	short init_err
   476                                  %endif
   477                                  
   478                                  ;
   479                                  ; position file pointer to start in actual wav data
   480                                  ; MUCH improvement should really be done here to check if sample size is
   481                                  ; supported, make sure there are 2 channels, etc.  
   482                                  ;
   483                                          ;mov     ah, 42h
   484                                          ;mov     al, 0	; from start of file
   485                                          ;mov     bx, [FileHandle]
   486                                          ;xor     cx, cx
   487                                          ;mov     dx, 44	; jump past .wav/riff header
   488                                          ;int     21h
   489                                  
   490                                  	sys	_seek, [FileHandle], 44, 0
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000003C7 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000003CD B92C000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000003D2 BA00000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000003D7 B813000000          <1>  mov eax, %1
    90                              <1> 
    91 000003DC CD40                <1>  int 40h
   491                                  
   492                                  	sys	_msg, nextline, 255, 07h ; 01/05/2017
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000003DE BB[D3280000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000003E3 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000003E8 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000003ED B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000003F2 CD40                <1>  int 40h
   493                                  
   494                                  	; 29/05/2024
   495                                  	; ----
   496                                  	; DIRECT CGA (TEXT MODE) MEMORY ACCESS
   497                                  	; bl = 0, bh = 4
   498                                  	; Direct access/map to CGA (Text) memory (0B8000h)
   499                                  
   500                                  	sys	_video, 0400h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000003F4 BB00040000          <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 000003F9 B81F000000          <1>  mov eax, %1
    90                              <1> 
    91 000003FE CD40                <1>  int 40h
   501 00000400 3D00800B00              	cmp	eax, 0B8000h
   502 00000405 7543                    	jne	short error_exit
   503                                  	; ----
   504                                  
   505                                  ; play the .wav file. Most of the good stuff is in here.
   506                                  
   507 00000407 E856000000              	call    PlayWav
   508                                  
   509                                  ; close the .wav file and exit.
   510                                  
   511                                  ; 29/05/2024
   512                                  %if 0
   513                                  StopPlaying:
   514                                  	; Stop Playing
   515                                  	sys	_audio, 0700h
   516                                  	; Cancel callback service (for user)
   517                                  	sys	_audio, 0900h
   518                                  	; Deallocate Audio Buffer (for user)
   519                                  	sys	_audio, 0A00h
   520                                  	; Disable Audio Device
   521                                  	sys	_audio, 0C00h
   522                                  %endif
   523                                  
   524                                  Exit:  
   525 0000040C E8DB010000                      call    closeFile
   526                                           
   527                                  	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 00000411 B801000000          <1>  mov eax, %1
    90                              <1> 
    91 00000416 CD40                <1>  int 40h
   528                                  here:
   529 00000418 EBFE                    	jmp	short here
   530                                  
   531                                  pmsg_usage:
   532                                  	sys	_msg, msg_usage, 255, 0Bh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000041A BB[46270000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000041F B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000424 BA0B000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000429 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 0000042E CD40                <1>  int 40h
   533 00000430 EBDA                    	jmp	short Exit
   534                                  
   535                                  	; 29/05/2024
   536                                  init_err:
   537                                  	sys	_msg, msg_init_err, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000432 BB[C9270000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000437 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000043C BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000441 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000446 CD40                <1>  int 40h
   538 00000448 EBC2                    	jmp	short Exit
   539                                  
   540                                  	; 29/05/2024
   541                                  error_exit:
   542                                  	sys	_msg, msg_error, 255, 0Eh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000044A BB[A9270000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000044F B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000454 BA0E000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000459 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 0000045E CD40                <1>  int 40h
   543 00000460 EBAA                    	jmp	short Exit
   544                                  
   545                                  	; --------------------------------------------
   546                                  	
   547                                  	; 29/05/2024 (TYRDOS 386, playwav7.s)
   548                                  	; ((Modified from playwav4.asm, ich_wav4.asm))
   549                                  	; ------------------
   550                                  ;playwav_vra:
   551                                  PlayWav:
   552                                  	; create Buffer Descriptor List
   553                                  
   554                                  	;  Generic Form of Buffer Descriptor
   555                                  	;  ---------------------------------
   556                                  	;  63   62    61-48    47-32   31-0
   557                                  	;  ---  ---  --------  ------- -----
   558                                  	;  IOC  BUP -reserved- Buffer  Buffer
   559                                  	;		      Length   Pointer
   560                                  	;		      [15:0]   [31:0]
   561                                  
   562                                  	; 29/05/2024
   563                                  	; Allocate memory block (33 pages)
   564                                  	sys	_alloc, BDL_BUFFER, 33*4096, 0 ; no upper limit
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000462 BB[00300000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000467 B900100200          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000046C BA00000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000471 B82A000000          <1>  mov eax, %1
    90                              <1> 
    91 00000476 CD40                <1>  int 40h
   565 00000478 72D0                    	jc	short error_exit
   566                                  	
   567                                  	;mov	esi, eax
   568                                  
   569 0000047A A3[4A2A0000]            	mov	[_bdl_buffer], eax ; BDL_BUFFER physical address 
   570                                  
   571 0000047F 0500100000              	add	eax, 4096	; WAVBUFFER_1 physical address
   572 00000484 89C3                    	mov	ebx, eax
   573                                  	;mov	[wav_buffer1], eax
   574                                  	;add	eax, 65536	; WAVBUFFER_2 physical address
   575                                  	;mov	[wav_buffer2], eax
   576                                  
   577 00000486 BF[00300000]            	mov	edi, BDL_BUFFER
   578 0000048B B910000000              	mov	ecx, 16
   579                                  _0:
   580                                  	;mov	eax, WAVBUFFER_1
   581 00000490 89D8                    	mov	eax, ebx	; WAVBUFFER_1 physical address
   582 00000492 AB                      	stosd
   583                                  
   584 00000493 A1[BC030000]            	mov	eax, [buffersize]
   585 00000498 D1E8                    	shr	eax, 1 ; buffer size in word
   586 0000049A 0D00000040              	or	eax, BUP	; tuneloop (without interrupt)
   587 0000049F AB                      	stosd
   588                                  
   589                                  	;mov	eax, WAVBUFFER_2
   590 000004A0 89D8                    	mov	eax, ebx
   591 000004A2 0500000100              	add	eax, 65536	; WAVBUFFER_2 physical address
   592 000004A7 AB                      	stosd
   593                                  
   594 000004A8 A1[BC030000]            	mov	eax, [buffersize]
   595 000004AD D1E8                    	shr	eax, 1 ; buffer size in word
   596 000004AF 0D00000040              	or	eax, BUP	; tuneloop (without interrupt)
   597 000004B4 AB                      	stosd
   598                                  
   599 000004B5 E2D9                    	loop	_0
   600                                  
   601                                  	;push	esi
   602                                  
   603                                  	; load 64k into buffer 1
   604 000004B7 C705[462A0000]-         	mov	dword [audio_buffer], WAVBUFFER_1
   604 000004BD [00400000]         
   605 000004C1 FF15[B4030000]          	call	dword [loadfromwavfile]
   606                                  
   607                                  	; and 64k into buffer 2
   608 000004C7 C705[462A0000]-         	mov	dword [audio_buffer], WAVBUFFER_2
   608 000004CD [00400100]         
   609 000004D1 FF15[B4030000]          	call	dword [loadfromwavfile]
   610                                  
   611                                  	;pop	esi
   612                                  	
   613                                  	; write NABMBAR+10h with offset of buffer descriptor list
   614                                  
   615                                         	;;mov	eax, BDL_BUFFER
   616                                          ;mov	eax, esi	; BDL_BUFFER physical address
   617                                  
   618 000004D7 A1[4A2A0000]            	mov	eax, [_bdl_buffer] ; BDL_BUFFER physical address
   619                                  
   620 000004DC 668B15[442A0000]        	mov	dx, [NABMBAR]
   621 000004E3 6683C210                        add     dx, PO_BDBAR_REG	; set pointer to BDL
   622                                  	;out	dx, eax 		; write to AC97 controller
   623                                  	; 29/05/2024
   624 000004E7 89C3                    	mov	ebx, eax ; data, dword
   625 000004E9 B405                    	mov	ah, 5	; write port dword
   626 000004EB CD34                    	int	34h
   627                                  
   628                                  	; 31/05/2024
   629                                  	; 19/05/2024
   630                                  	;call	delay1_4ms
   631                                  
   632 000004ED B01F                            mov	al, 31
   633 000004EF E879210000              	call	setLastValidIndex
   634                                  
   635                                  	; 31/05/2024
   636                                  	; 19/05/2024
   637                                  	;call	delay1_4ms
   638                                  
   639                                  	; 17/02/2017
   640 000004F4 668B15[442A0000]                mov	dx, [NABMBAR]
   641 000004FB 6683C21B                        add	dx, PO_CR_REG		; PCM out Control Register
   642                                          ;mov	al, IOCE + RPBM	; Enable 'Interrupt On Completion' + run
   643                                  	;			; (LVBI interrupt will not be enabled)
   644                                  	; 06/11/2023 (TUNELOOP version, without interrupt)
   645 000004FF B001                    	mov	al, RPBM
   646                                  	;out	dx, al			; Start bus master operation.
   647                                  	; 29/05/2024
   648                                  	; al = data, byte
   649 00000501 B401                    	mov	ah, 1 ; write port, byte
   650 00000503 CD34                    	int	34h
   651                                  
   652                                  	; 19/05/2024
   653                                  	; 06/11/2023
   654                                  	;call	delay1_4ms	; 31/05/2024
   655                                  	;call	delay1_4ms
   656                                  	;call	delay1_4ms
   657                                  	;call	delay1_4ms
   658                                  
   659                                  ; while DMA engine is running, examine current index and wait until it hits 1
   660                                  ; as soon as it's 1, we need to refresh the data in wavbuffer1 with another
   661                                  ; 64k. Likewise when it's playing buffer 2, refresh buffer 1 and repeat.
   662                                  
   663                                  ; 18/11/2023
   664                                  ; 08/11/2023
   665                                  ; 07/11/2023
   666                                  
   667                                  tuneLoop:
   668                                  	; 18/11/2023 (ich_wav4.asm)
   669                                  	; 08/11/2023
   670                                  	; 06/11/2023
   671 00000505 B031                    	mov	al, '1'
   672 00000507 E86C000000              	call	tL0
   673                                  tL1:
   674 0000050C E81F210000              	call	updateLVI	; /set LVI != CIV/
   675 00000511 7452                    	jz	short _exitt_	; 08/11/2023
   676 00000513 E8C0200000              	call	check4keyboardstop
   677 00000518 724B                    	jc	short _exitt_
   678 0000051A E801210000              	call	getCurrentIndex
   679 0000051F A801                    	test	al, BIT0
   680 00000521 74E9                    	jz	short tL1	; loop if buffer 2 is not playing
   681                                  
   682                                  	; 29/05/2024
   683                                  	; load buffer 1
   684 00000523 C705[462A0000]-         	mov	dword [audio_buffer], WAVBUFFER_1
   684 00000529 [00400000]         
   685 0000052D FF15[B4030000]          	call	dword [loadfromwavfile]
   686 00000533 7230                    	jc	short _exitt_	; end of file
   687                                  
   688 00000535 B032                    	mov	al, '2'
   689 00000537 E83C000000              	call	tL0
   690                                  tL2:
   691 0000053C E8EF200000              	call    updateLVI
   692 00000541 7422                    	jz	short _exitt_	; 08/11/2023
   693 00000543 E890200000              	call    check4keyboardstop
   694 00000548 721B                    	jc	short _exitt_
   695 0000054A E8D1200000              	call    getCurrentIndex
   696 0000054F A801                    	test	al, BIT0
   697 00000551 75E9                    	jnz	short tL2	; loop if buffer 1 is not playing
   698                                  
   699                                  	; 29/05/2024
   700                                  	; load buffer 2
   701 00000553 C705[462A0000]-         	mov	dword [audio_buffer], WAVBUFFER_2
   701 00000559 [00400100]         
   702 0000055D FF15[B4030000]          	call	dword [loadfromwavfile]
   703 00000563 73A0                    	jnc	short tuneLoop
   704                                  _exitt_:
   705 00000565 668B15[442A0000]        	mov	dx, [NABMBAR]		
   706 0000056C 6683C21B                	add	dx, PO_CR_REG	; PCM out Control Register
   707 00000570 B000                    	mov	al, 0
   708                                  	;out	dx, al		; stop player
   709                                  	; 29/05/2024
   710                                  	; al = data, byte
   711 00000572 B401                    	mov	ah, 1  ; write port, byte
   712 00000574 CD34                    	int	34h	
   713                                  
   714                                  	; 29/05/2024
   715 00000576 B030                    	mov	al, '0'
   716                                  
   717                                  	;add	al, '0'
   718                                  	;call	tL0
   719                                  	;
   720                                  	;retn
   721                                  	; 06/11/2023
   722                                  	;jmp	short tL0
   723                                  	;retn
   724                                  
   725                                  	; 06/11/2023
   726                                  tL0:
   727                                  	; 29/05/2024 (TRDOS 386)
   728                                  	; 08/11/2023
   729                                  	; 05/11/2023
   730                                  	; 17/02/2017 - Buffer switch test (temporary)
   731                                  	; 06/11/2023
   732                                  	; al = buffer indicator ('1', '2' or '0' -stop- )
   733                                  	
   734 00000578 BB00800B00              	mov	ebx, 0B8000h ; video display page address
   735 0000057D B44E                    	mov	ah, 4Eh
   736 0000057F 668903                  	mov	[ebx], ax ; show current play buffer (1, 2)
   737 00000582 C3                      	retn
   738                                  
   739                                  	; ------------------
   740                                  
   741                                  ; 29/05/2024
   742                                  %if 0
   743                                  	; 25/11/2023
   744                                  DetectAC97:
   745                                  	; Detect (BH=1) AC'97 (BL=2) Audio Device
   746                                          sys	_audio, 0102h
   747                                  	jc	short DetectAC97_retn
   748                                  
   749                                  	; 25/11/2023
   750                                  	; Get AC'97 Codec info
   751                                  	; (Function 14, sub function 1)
   752                                  	sys	_audio, 0E01h
   753                                  	; Save Variable Rate Audio support bit
   754                                  	and	al, 1
   755                                  	mov	[VRA], al
   756                                  
   757                                  DetectAC97_retn:
   758                                  	retn
   759                                  %else
   760                                  	; 29/05/2024
   761                                  DetectAC97:
   762                                  DetectICH:
   763                                  	; 22/11/2023
   764                                  	; 19/11/2023
   765                                  	; 01/11/2023 - TRDOS 386 Kernel v2.0.7
   766                                  	;; 10/06/2017
   767                                  	;; 05/06/2017
   768                                  	;; 29/05/2017
   769                                  	;; 28/05/2017
   770                                  
   771                                  	; 19/11/2023
   772 00000583 BE[33280000]            	mov	esi, valid_ids	; address of Valid ICH (AC97) Device IDs
   773 00000588 B915000000              	mov	ecx, valid_id_count
   774                                  pfd_1:
   775 0000058D AD                      	lodsd
   776 0000058E E81E1C0000              	call	pciFindDevice
   777 00000593 7303                    	jnc	short d_ac97_1
   778 00000595 E2F6                    	loop	pfd_1
   779                                  
   780                                  	;stc
   781 00000597 C3                      	retn
   782                                  
   783                                  d_ac97_1:
   784                                  	; eax = BUS/DEV/FN
   785                                  	;	00000000BBBBBBBBDDDDDFFF00000000
   786                                  	; edx = DEV/VENDOR
   787                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
   788                                  
   789                                  	; playwav4.asm - 19/05/2024
   790                                  
   791 00000598 A3[3E2A0000]            	mov	[bus_dev_fn], eax
   792 0000059D 8915[3A2A0000]          	mov	[dev_vendor], edx
   793                                  
   794                                  	; get ICH base address regs for mixer and bus master
   795                                  
   796 000005A3 B010                            mov     al, NAMBAR_REG
   797 000005A5 E8951C0000                      call    pciRegRead16			; read PCI registers 10-11
   798                                          ;and    dx, IO_ADDR_MASK 		; mask off BIT0
   799                                  	; 19/05/2024
   800 000005AA 80E2FE                  	and	dl, 0FEh
   801                                  
   802 000005AD 668915[422A0000]                mov     [NAMBAR], dx			; save audio mixer base addr
   803                                  
   804 000005B4 B014                    	mov     al, NABMBAR_REG
   805 000005B6 E8841C0000                      call    pciRegRead16
   806                                          ;and    dx, IO_ADDR_MASK
   807                                  	; 19/05/2024
   808 000005BB 80E2C0                  	and	dl, 0C0h
   809                                  
   810 000005BE 668915[442A0000]                mov     [NABMBAR], dx			; save bus master base addr
   811                                  
   812 000005C5 B03C                    	mov	al, AC97_INT_LINE ; Interrupt line register (3Ch)
   813 000005C7 E86C1C0000              	call	pciRegRead8 ; 17/02/2017
   814                                  
   815 000005CC 8815[382A0000]          	mov     [ac97_int_ln_reg], dl
   816                                  
   817                                  	;clc
   818                                  
   819 000005D2 C3                      	retn
   820                                  %endif
   821                                  
   822                                  ;open or create file
   823                                  ;
   824                                  ;input: ds:dx-->filename (asciiz)
   825                                  ;       al=file Mode (create or open)
   826                                  ;output: none  cs:[FileHandle] filled
   827                                  ;
   828                                  openFile:
   829                                  	;mov	ah, 3Bh	; start with a mode
   830                                  	;add	ah, al	; add in create or open mode
   831                                  	;xor	ecx, ecx
   832                                  	;int	21h
   833                                  	;jc	short _of1
   834                                  	;;mov	[cs:FileHandle], ax
   835                                  
   836                                  	sys	_open, wav_file_name, 0
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000005D3 BB[E6290000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000005D8 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 000005DD B805000000          <1>  mov eax, %1
    90                              <1> 
    91 000005E2 CD40                <1>  int 40h
   837 000005E4 7205                    	jc	short _of1
   838                                  
   839 000005E6 A3[7E260000]            	mov	[FileHandle], eax
   840                                  _of1:
   841 000005EB C3                      	retn
   842                                  
   843                                  ; close the currently open file
   844                                  ; input: none, uses cs:[FileHandle]
   845                                  closeFile:
   846 000005EC 833D[7E260000]FF        	cmp	dword [FileHandle], -1
   847 000005F3 7417                    	je	short _cf1
   848                                  	;mov    bx, [FileHandle]  
   849                                  	;mov    ax, 3E00h
   850                                          ;int    21h              ;close file
   851                                  
   852                                  	sys	_close, [FileHandle]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000005F5 8B1D[7E260000]      <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 000005FB B806000000          <1>  mov eax, %1
    90                              <1> 
    91 00000600 CD40                <1>  int 40h
   853 00000602 C705[7E260000]FFFF-     	mov 	dword [FileHandle], -1
   853 0000060A FFFF               
   854                                  _cf1:
   855 0000060C C3                      	retn
   856                                  
   857                                  getSampleRate:
   858                                  	
   859                                  ; reads the sample rate from the .wav file.
   860                                  ; entry: none - assumes file is already open
   861                                  ; exit: ax = sample rate (11025, 22050, 44100, 48000)
   862                                  ;	cx = number of channels (mono=1, stereo=2)
   863                                  ;	dx = bits per sample (8, 16)
   864                                  
   865 0000060D 53                      	push    ebx
   866                                  
   867                                          ;mov	ah, 42h
   868                                          ;mov	al, 0	; from start of file
   869                                          ;mov	bx, [FileHandle]
   870                                          ;xor	ecx, ecx
   871                                          ;mov	dx, 08h	; "WAVE"
   872                                          ;int	21h
   873                                  	
   874                                  	sys	_seek, [FileHandle], 8, 0
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000060E 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000614 B908000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000619 BA00000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000061E B813000000          <1>  mov eax, %1
    90                              <1> 
    91 00000623 CD40                <1>  int 40h
   875                                  
   876                                          ;mov	dx, smpRBuff
   877                                          ;mov	cx, 28	; 28 bytes
   878                                  	;mov	ah, 3fh
   879                                          ;int	21h
   880                                  
   881                                  	sys	_read, [FileHandle], smpRBuff, 28
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000625 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000062B B9[CA290000]        <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000630 BA1C000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000635 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000063A CD40                <1>  int 40h
   882                                  
   883 0000063C 813D[CA290000]5741-     	cmp	dword [smpRBuff], 'WAVE'
   883 00000644 5645               
   884 00000646 7520                    	jne	short gsr_stc
   885                                  
   886 00000648 66833D[D6290000]01      	cmp	word [smpRBuff+12], 1	; Offset 20, must be 1 (= PCM)
   887 00000650 7516                    	jne	short gsr_stc
   888                                  
   889 00000652 668B0D[D8290000]        	mov	cx, [smpRBuff+14]	; return num of channels in CX
   890 00000659 66A1[DA290000]                  mov     ax, [smpRBuff+16]	; return sample rate in AX
   891 0000065F 668B15[E4290000]        	mov	dx, [smpRBuff+26]	; return bits per sample value in DX
   892                                  gsr_retn:
   893 00000666 5B                              pop     ebx
   894 00000667 C3                              retn
   895                                  gsr_stc:
   896 00000668 F9                      	stc
   897 00000669 EBFB                    	jmp	short gsr_retn
   898                                  
   899                                  ; 29/05/2024
   900                                  %if 0
   901                                  audio_int_handler:
   902                                  	; 18/08/2020 (14/10/2020, 'wavplay2.s')
   903                                  
   904                                  	;mov	byte [srb], 1 ; interrupt (or signal response byte)
   905                                  	
   906                                  	;cmp	byte [cbs_busy], 1
   907                                  	;jnb	short _callback_bsy_retn
   908                                  	
   909                                  	;mov	byte [cbs_busy], 1
   910                                  
   911                                  	mov	al, [half_buff]
   912                                  
   913                                  	cmp	al, 1
   914                                  	jb	short _callback_retn
   915                                  
   916                                  	; 18/08/2020
   917                                  	mov	byte [srb], 1
   918                                  
   919                                  	xor	byte [half_buff], 3 ; 2->1, 1->2
   920                                  
   921                                  	add	al, '0'
   922                                  tL0:	; 26/11/2023
   923                                  	mov	ah, 4Eh
   924                                  	mov	ebx, 0B8000h ; video display page address
   925                                  	mov	[ebx], ax ; show playing buffer (1, 2)
   926                                  _callback_retn:
   927                                  	;mov	byte [cbs_busy], 0
   928                                  _callback_bsy_retn:
   929                                  	sys	_rele ; return from callback service 
   930                                  	; we must not come here !
   931                                  	sys	_exit
   932                                  %endif
   933                                  	
   934                                  loadFromFile:
   935                                  	; 26/11/2023
   936 0000066B F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
   937                                  					; last of the file?
   938 00000672 7402                    	jz	short lff_0		; no
   939 00000674 F9                      	stc
   940 00000675 C3                      	retn
   941                                  lff_0:
   942                                  	; 13/06/2017
   943                                  	;mov	edx, BUFFERSIZE
   944                                  	; 26/11/2023
   945                                  	;mov	edi, audio_buffer
   946                                  	; 29/05/2024
   947 00000676 8B3D[462A0000]          	mov	edi, [audio_buffer]
   948 0000067C 8B15[BC030000]          	mov	edx, [buffersize]	; bytes
   949 00000682 8A0D[392A0000]          	mov	cl, [fbs_shift]   
   950 00000688 20C9                    	and	cl, cl
   951 0000068A 7409                    	jz	short lff_1 ; stereo, 16 bit
   952                                  
   953                                  	; fbs_shift =
   954                                  	;	2 for mono and 8 bit sample (multiplier = 4)
   955                                  	;	1 for mono or 8 bit sample (multiplier = 2)
   956 0000068C D3EA                    	shr	edx, cl
   957                                  	;inc	edx
   958                                  
   959 0000068E BE[00400200]            	mov     esi, temp_buffer
   960 00000693 EB02                    	jmp	short lff_2
   961                                  lff_1:
   962                                  	;;mov	esi, audio_buffer
   963                                  	; 29/05/2024
   964                                  	;mov	esi, [audio_buffer]
   965 00000695 89FE                    	mov	esi, edi ; audio_buffer
   966                                  lff_2:
   967                                  	; 17/03/2017
   968                                  	; esi = buffer address
   969                                  	; edx = buffer size
   970                                   
   971                                  	; 26/11/2023
   972                                  	; load file into memory
   973                                  	sys 	_read, [FileHandle], esi
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000697 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000069D 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 0000069F B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000006A4 CD40                <1>  int 40h
   974 000006A6 8B0D[BC030000]          	mov	ecx, [buffersize]
   975                                  	;jc	short padfill ; error !
   976                                  	; 14/12/2024
   977 000006AC 7256                    	jc	short lff_10
   978                                  
   979 000006AE 21C0                    	and	eax, eax
   980 000006B0 7454                    	jz	short padfill
   981                                  lff_3:
   982                                  	; 26/11/2023
   983 000006B2 8A1D[392A0000]          	mov	bl, [fbs_shift]
   984 000006B8 20DB                    	and	bl, bl
   985 000006BA 7457                    	jz	short lff_11
   986                                  
   987                                  	; 14/12/2024
   988                                  	;sub	ecx, eax
   989                                  	;mov	ebp, ecx
   990                                  	; 14/12/2024
   991 000006BC 29C2                    	sub	edx, eax
   992                                  
   993                                  	;mov	esi, temp_buffer
   994                                  	;mov	edi, audio_buffer
   995 000006BE 89C1                    	mov	ecx, eax   ; byte count
   996                                  
   997 000006C0 803D[C5290000]08        	cmp	byte [bps], 8 ; bits per sample (8 or 16)
   998 000006C7 751E                    	jne	short lff_6 ; 16 bit samples
   999                                  	; 8 bit samples
  1000 000006C9 FECB                    	dec	bl  ; shift count, 1 = stereo, 2 = mono
  1001 000006CB 740E                    	jz	short lff_5 ; 8 bit, stereo
  1002                                  lff_4:
  1003                                  	; mono & 8 bit
  1004 000006CD AC                      	lodsb
  1005 000006CE 2C80                    	sub	al, 80h ; 08/11/2023
  1006 000006D0 C1E008                  	shl	eax, 8 ; convert 8 bit sample to 16 bit sample
  1007 000006D3 66AB                    	stosw	; left channel
  1008 000006D5 66AB                    	stosw	; right channel
  1009 000006D7 E2F4                    	loop	lff_4
  1010 000006D9 EB16                    	jmp	short lff_8
  1011                                  lff_5:
  1012                                  	; stereo & 8 bit
  1013 000006DB AC                      	lodsb
  1014 000006DC 2C80                    	sub	al, 80h ; 08/11/2023
  1015 000006DE C1E008                  	shl	eax, 8 ; convert 8 bit sample to 16 bit sample
  1016 000006E1 66AB                    	stosw
  1017 000006E3 E2F6                    	loop	lff_5
  1018 000006E5 EB0A                    	jmp	short lff_8
  1019                                  lff_6:
  1020 000006E7 D1E9                    	shr	ecx, 1 ; word count
  1021                                  lff_7:
  1022 000006E9 66AD                    	lodsw
  1023 000006EB 66AB                    	stosw	; left channel
  1024 000006ED 66AB                    	stosw	; right channel
  1025 000006EF E2F8                    	loop	lff_7
  1026                                  lff_8:
  1027                                  	; 27/11/2023
  1028 000006F1 F8                      	clc
  1029                                  	; 14/12/2024
  1030                                  	;mov	ecx, ebp
  1031                                  	;jecxz	endLFF_retn
  1032 000006F2 09D2                    	or	edx, edx
  1033 000006F4 741C                    	jz	short endLFF_retn
  1034                                  
  1035                                  	; 14/12/2024
  1036                                  	;mov	ecx, audio_buffer
  1037                                  	; 02/02/2025 (BugFix)
  1038 000006F6 8B0D[462A0000]          	mov	ecx, [audio_buffer]
  1039 000006FC 030D[BC030000]          	add	ecx, [buffersize]
  1040 00000702 29F9                    	sub	ecx, edi
  1041                                  
  1042                                  	; 14/12/2024
  1043                                  lff_10:
  1044 00000704 31C0                    	xor	eax, eax ; silence
  1045                                  padfill:
  1046 00000706 D1E9                    	shr	ecx, 1
  1047 00000708 F366AB                  	rep	stosw
  1048                                  lff_9:
  1049 0000070B 800D[C8290000]01                or	byte [flags], ENDOFFILE	; end of file flag
  1050                                  endLFF_retn:
  1051 00000712 C3                              retn
  1052                                  
  1053                                  lff_11:
  1054                                  	; 16 bit stereo
  1055                                  	; ecx = buffer size
  1056                                  	; eax = read count
  1057 00000713 29C1                    	sub	ecx, eax
  1058 00000715 76FB                    	jna	short endLFF_retn
  1059 00000717 01C7                    	add	edi, eax  ; audio_buffer + eax
  1060 00000719 EBE9                    	jmp	short lff_10 ; padfill
  1061                                  
  1062                                  error_exit_2:
  1063                                  	; 26/11/2023 - temporary
  1064                                  	;sys	_msg, test_2, 255, 0Ch
  1065 0000071B E92AFDFFFF              	jmp	error_exit
  1066                                  	
  1067                                  	; 26/11/2023 - temporary
  1068                                  ;test_1:
  1069                                  ;	db 13, 10, 'Test 1', 13,10, 0
  1070                                  ;test_2:
  1071                                  ;	db 13, 10, 'Test 2', 13,10, 0
  1072                                  	
  1073                                  ; 29/05/2024
  1074                                  %if 0
  1075                                  
  1076                                  PlayWav:
  1077                                  	; 26/11/2023
  1078                                  	; 18/08/2020 (27/07/2020, 'wavplay2.s')
  1079                                  	; 13/06/2017
  1080                                  	; Convert 8 bit samples to 16 bit samples
  1081                                  	; and convert mono samples to stereo samples
  1082                                  
  1083                                  	; 26/11/2023
  1084                                  	; load 32768 bytes into audio buffer
  1085                                  	;mov	edi, audio_buffer
  1086                                  	;;mov	edx, BUFFERSIZE
  1087                                  	; 26/11/2023
  1088                                  	;mov	edx, [buffersize]
  1089                                  	;call	loadFromFile
  1090                                  	; 26/11/2023
  1091                                  	call	dword [loadfromwavfile]
  1092                                  	jc	short error_exit_2
  1093                                  	mov	byte [half_buff], 1 ; (DMA) Buffer 1
  1094                                  
  1095                                  	; 18/08/2020 (27/07/2020, 'wavplay2.s')
  1096                                  	test    byte [flags], ENDOFFILE  ; end of file
  1097                                  	jnz	short _6 ; yes
  1098                                  			 ; bypass filling dma half buffer 2
  1099                                  
  1100                                  	; bh = 16 : update (current, first) dma half buffer
  1101                                  	; bl = 0  : then switch to the next (second) half buffer
  1102                                  	sys	_audio, 1000h
  1103                                  
  1104                                  	; 18/08/2020
  1105                                  	; [audio_flag] = 1 (in TRDOS 386 kernel)
  1106                                  
  1107                                  	; audio_buffer must be filled again after above system call 
  1108                                  	; (Because audio interrupt will be generated by AC97 hardware
  1109                                  	; at the end of the first half of dma buffer.. so, 
  1110                                  	; the second half must be ready. 'sound_play' will use it.)
  1111                                  
  1112                                  	; 26/11/2023
  1113                                  	;mov	edi, audio_buffer
  1114                                  	;;mov	edx, BUFFERSIZE
  1115                                  	; 26/11/2023
  1116                                  	;mov	edx, [buffersize]
  1117                                  	;call	loadFromFile
  1118                                  	; 26/11/2023
  1119                                  	call	dword [loadfromwavfile]
  1120                                  	;jc	short p_return
  1121                                  _6:
  1122                                  	; Set Master Volume Level (BL=0 or 80h)
  1123                                  	; 	for next playing (BL>=80h)
  1124                                  	;sys	_audio, 0B80h, 1D1Dh
  1125                                  	sys	_audio, 0B00h, 1D1Dh
  1126                                  
  1127                                  	; 18/08/2020
  1128                                  	;mov	byte [volume_level], 1Dh
  1129                                  	mov	[volume_level], cl
  1130                                  
  1131                                  	; Start	to play
  1132                                  	mov	al, [bps]
  1133                                  	shr	al, 4 ; 8 -> 0, 16 -> 1
  1134                                  	shl	al, 1 ; 16 -> 2, 8 -> 0
  1135                                  	mov	bl, [stmo]
  1136                                  	dec	bl
  1137                                  	or	bl, al
  1138                                  	mov	cx, [sample_rate] 
  1139                                  	mov	bh, 4 ; start to play	
  1140                                  	sys	_audio
  1141                                  
  1142                                  	;mov	ebx, 0B8000h ; video display page address
  1143                                  	;mov	ah, 4Eh
  1144                                  	;mov	al, [half_buffer]
  1145                                  	;mov	[ebx], ax ; show playing buffer (1, 2)
  1146                                  
  1147                                  	; 18/08/2020 (27/07/2020, 'wavplay2.s')
  1148                                  	; Here..
  1149                                  	; If byte [flags] <> ENDOFFILE ...
  1150                                  	; user's audio_buffer has been copied to dma half buffer 2
  1151                                  
  1152                                  	; [audio_flag] = 0 (in TRDOS 386 kernel)
  1153                                  
  1154                                  	; audio_buffer must be filled again after above system call 
  1155                                  	; (Because, audio interrupt will be generated by VT8237R
  1156                                  	; at the end of the first half of dma buffer.. so, 
  1157                                  	; the 2nd half of dma buffer is ready but the 1st half
  1158                                  	; must be filled again.)
  1159                                  
  1160                                  	; 18/08/2020
  1161                                  	test    byte [flags], ENDOFFILE  ; end of file
  1162                                  	jnz	short p_loop ; yes
  1163                                  
  1164                                  	; 18/08/2020
  1165                                  	; load 32768 bytes into audio buffer
  1166                                  	;; (for the second half of DMA buffer)
  1167                                  	; 27/11/2023
  1168                                  	; 20/05/2017
  1169                                  	;mov	edi, audio_buffer
  1170                                  	;mov	edx, BUFFERSIZE
  1171                                  	; 26/11/2023
  1172                                  	;mov	edx, [buffersize]
  1173                                  	;call	loadFromFile
  1174                                  	; 26/11/2023
  1175                                  	call	dword [loadfromwavfile]
  1176                                  	;jc	short p_return
  1177                                  	;mov	byte [half_buff], 2 ; (DMA) Buffer 2
  1178                                  
  1179                                  	; we need to wait for 'SRB' (audio interrupt)
  1180                                  	; (we can not return from 'PlayWav' here 
  1181                                  	;  even if we have got an error from file reading)
  1182                                  	; ((!!current audio data must be played!!))
  1183                                  
  1184                                  	; 18/08/2020
  1185                                  	;mov	byte [srb], 1
  1186                                  
  1187                                  p_loop:
  1188                                  	;mov	ah, 1		; any key pressed?
  1189                                  	;int	32h		; no, Loop.
  1190                                  	;jz	short q_loop
  1191                                  	;
  1192                                  	;mov	ah, 0		; flush key buffer...
  1193                                  	;int	32h
  1194                                  
  1195                                  	; 18/08/2020 (14/10/2017, 'wavplay2.s')
  1196                                  	cmp	byte [srb], 0
  1197                                  	jna	short q_loop
  1198                                  	mov	byte [srb], 0
  1199                                  	; 27/11/2023
  1200                                  	;mov	edi, audio_buffer
  1201                                  	;mov	edx, BUFFERSIZE
  1202                                  	; 26/11/2023
  1203                                  	;mov	edx, [buffersize]
  1204                                  	;call	loadFromFile
  1205                                  	; 26/11/2023
  1206                                  	call	dword [loadfromwavfile]
  1207                                  	jc	short p_return
  1208                                  q_loop:
  1209                                  	mov     ah, 1		; any key pressed?
  1210                                  	int     32h		; no, Loop.
  1211                                  	jz	short p_loop
  1212                                  
  1213                                  	mov     ah, 0		; flush key buffer...
  1214                                  	int     32h
  1215                                  	
  1216                                  	cmp	al, '+' ; increase sound volume
  1217                                  	je	short inc_volume_level
  1218                                  	cmp	al, '-'
  1219                                  	je	short dec_volume_level
  1220                                  
  1221                                  p_return:
  1222                                  	mov	byte [half_buff], 0
  1223                                  	retn
  1224                                  
  1225                                  	; 18/08/2020 (14/10/2017, 'wavplay2.s')
  1226                                  inc_volume_level:
  1227                                  	mov	cl, [volume_level]
  1228                                  	cmp	cl, 1Fh ; 31
  1229                                  	jnb	short q_loop
  1230                                  	inc	cl
  1231                                  change_volume_level:
  1232                                  	mov	[volume_level], cl
  1233                                  	mov	ch, cl
  1234                                  	; Set Master Volume Level
  1235                                  	sys	_audio, 0B00h
  1236                                  	jmp	short p_loop
  1237                                  dec_volume_level:
  1238                                  	mov	cl, [volume_level]
  1239                                  	cmp	cl, 1 ; 1
  1240                                  	;jna	short p_loop
  1241                                  	; 14/12/2024
  1242                                  	jna	short q_loop
  1243                                  	dec	cl
  1244                                  	jmp	short change_volume_level
  1245                                  %endif
  1246                                  
  1247                                  write_audio_dev_info:
  1248                                  	; EBX = Message address
  1249                                  	; ECX = Max. message length (or stop on ZERO character)
  1250                                  	;	(1 to 255)
  1251                                  	; DL  = Message color (07h = light gray, 0Fh = white) 
  1252                                       	sys 	_msg, msgAudioCardInfo, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000720 BB[1D270000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000725 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000072A BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000072F B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000734 CD40                <1>  int 40h
  1253 00000736 C3                      	retn
  1254                                  
  1255                                  write_wav_file_info:
  1256                                  	; 01/05/2017
  1257                                  	sys	_msg, msgWavFileName, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000737 BB[87280000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000073C B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000741 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000746 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 0000074B CD40                <1>  int 40h
  1258                                  	sys	_msg, wav_file_name, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000074D BB[E6290000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000752 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000757 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000075C B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000761 CD40                <1>  int 40h
  1259                                  
  1260                                  write_sample_rate:
  1261                                  	; 01/05/2017
  1262 00000763 66A1[C6290000]          	mov	ax, [sample_rate]
  1263                                  	; ax = sample rate (hertz)
  1264 00000769 31D2                    	xor	edx, edx
  1265 0000076B 66B90A00                	mov	cx, 10
  1266 0000076F 66F7F1                  	div	cx
  1267 00000772 0015[AC280000]          	add	[msgHertz+4], dl
  1268 00000778 29D2                    	sub	edx, edx
  1269 0000077A 66F7F1                  	div	cx
  1270 0000077D 0015[AB280000]          	add	[msgHertz+3], dl
  1271 00000783 29D2                    	sub	edx, edx
  1272 00000785 66F7F1                  	div	cx
  1273 00000788 0015[AA280000]          	add	[msgHertz+2], dl
  1274 0000078E 29D2                    	sub	edx, edx
  1275 00000790 66F7F1                  	div	cx
  1276 00000793 0015[A9280000]          	add	[msgHertz+1], dl
  1277 00000799 0005[A8280000]          	add	[msgHertz], al
  1278                                  	
  1279                                  	sys	_msg, msgSampleRate, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000079F BB[99280000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000007A4 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000007A9 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000007AE B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000007B3 CD40                <1>  int 40h
  1280                                  
  1281 000007B5 BE[C3280000]            	mov	esi, msg16Bits
  1282 000007BA 803D[C5290000]10        	cmp	byte [bps], 16
  1283 000007C1 7405                    	je	short wsr_1
  1284 000007C3 BE[B3280000]            	mov	esi, msg8Bits
  1285                                  wsr_1:
  1286                                  	sys	_msg, esi, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000007C8 89F3                <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000007CA B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000007CF BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000007D4 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000007D9 CD40                <1>  int 40h
  1287                                  
  1288 000007DB BE[BC280000]            	mov	esi, msgMono
  1289 000007E0 803D[C4290000]01        	cmp	byte [stmo], 1
  1290 000007E7 7405                    	je	short wsr_2
  1291 000007E9 BE[CD280000]            	mov	esi, msgStereo		
  1292                                  wsr_2:
  1293                                  	sys	_msg, esi, 255, 0Fh
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000007EE 89F3                <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000007F0 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000007F5 BA0F000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000007FA B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000007FF CD40                <1>  int 40h
  1294 00000801 C3                              retn
  1295                                  
  1296                                  write_ac97_pci_dev_info:
  1297                                  	; 06/06/2017
  1298                                  	; 03/06/2017
  1299                                  	; BUS/DEV/FN
  1300                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  1301                                  	; DEV/VENDOR
  1302                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  1303                                  
  1304                                  	;mov	esi, [dev_vendor]
  1305                                  	;mov	eax, esi
  1306                                  	; 31/05/2024
  1307 00000802 A1[3A2A0000]            	mov	eax, [dev_vendor]
  1308 00000807 0FB6D8                  	movzx	ebx, al
  1309 0000080A 88DA                    	mov	dl, bl
  1310 0000080C 80E30F                  	and	bl, 0Fh
  1311 0000080F 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1312 00000815 A2[1B290000]            	mov	[msgVendorId+3], al
  1313 0000081A 88D3                    	mov	bl, dl
  1314 0000081C C0EB04                  	shr	bl, 4
  1315 0000081F 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1316 00000825 A2[1A290000]            	mov	[msgVendorId+2], al
  1317 0000082A 88E3                    	mov	bl, ah
  1318 0000082C 88DA                    	mov	dl, bl
  1319 0000082E 80E30F                  	and	bl, 0Fh
  1320 00000831 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1321 00000837 A2[19290000]            	mov	[msgVendorId+1], al
  1322 0000083C 88D3                    	mov	bl, dl
  1323 0000083E C0EB04                  	shr	bl, 4
  1324 00000841 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1325 00000847 A2[18290000]            	mov	[msgVendorId], al
  1326 0000084C C1E810                  	shr	eax, 16
  1327 0000084F 88C3                    	mov	bl, al
  1328 00000851 88DA                    	mov	dl, bl
  1329 00000853 80E30F                  	and	bl, 0Fh
  1330 00000856 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1331 0000085C A2[2C290000]            	mov	[msgDevId+3], al
  1332 00000861 88D3                    	mov	bl, dl
  1333 00000863 C0EB04                  	shr	bl, 4
  1334 00000866 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1335 0000086C A2[2B290000]            	mov	[msgDevId+2], al
  1336 00000871 88E3                    	mov	bl, ah
  1337 00000873 88DA                    	mov	dl, bl
  1338 00000875 80E30F                  	and	bl, 0Fh
  1339 00000878 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1340 0000087E A2[2A290000]            	mov	[msgDevId+1], al
  1341 00000883 88D3                    	mov	bl, dl
  1342 00000885 C0EB04                  	shr	bl, 4
  1343 00000888 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1344 0000088E A2[29290000]            	mov	[msgDevId], al
  1345                                  
  1346                                  	;mov	esi, [bus_dev_fn]
  1347                                  	;shr	esi, 8
  1348                                  	;mov	ax, si
  1349                                  	; 31/05/2024
  1350 00000893 A1[3E2A0000]            	mov	eax, [bus_dev_fn]
  1351 00000898 C1E808                  	shr	eax, 8
  1352 0000089B 88C3                    	mov	bl, al
  1353 0000089D 88DA                    	mov	dl, bl
  1354 0000089F 80E307                  	and	bl, 7 ; bit 0,1,2
  1355 000008A2 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1356 000008A8 A2[50290000]            	mov	[msgFncNo+1], al
  1357 000008AD 88D3                    	mov	bl, dl
  1358 000008AF C0EB03                  	shr	bl, 3
  1359 000008B2 88DA                    	mov	dl, bl
  1360 000008B4 80E30F                  	and	bl, 0Fh
  1361 000008B7 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1362 000008BD A2[42290000]            	mov	[msgDevNo+1], al
  1363 000008C2 88D3                    	mov	bl, dl
  1364 000008C4 C0EB04                  	shr	bl, 4
  1365 000008C7 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1366 000008CD A2[41290000]            	mov	[msgDevNo], al
  1367 000008D2 88E3                    	mov	bl, ah
  1368 000008D4 88DA                    	mov	dl, bl
  1369 000008D6 80E30F                  	and	bl, 0Fh
  1370 000008D9 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1371 000008DF A2[36290000]            	mov	[msgBusNo+1], al
  1372 000008E4 88D3                    	mov	bl, dl
  1373 000008E6 C0EB04                  	shr	bl, 4
  1374 000008E9 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1375 000008EF A2[35290000]            	mov	[msgBusNo], al
  1376                                  
  1377                                  	;mov	ax, [ac97_NamBar]
  1378 000008F4 66A1[422A0000]          	mov	ax, [NAMBAR]	; 29/05/2024
  1379 000008FA 88C3                    	mov	bl, al
  1380 000008FC 88DA                    	mov	dl, bl
  1381 000008FE 80E30F                  	and	bl, 0Fh
  1382 00000901 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1383 00000907 A2[5F290000]            	mov	[msgNamBar+3], al
  1384 0000090C 88D3                    	mov	bl, dl
  1385 0000090E C0EB04                  	shr	bl, 4
  1386 00000911 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1387 00000917 A2[5E290000]            	mov	[msgNamBar+2], al
  1388 0000091C 88E3                    	mov	bl, ah
  1389 0000091E 88DA                    	mov	dl, bl
  1390 00000920 80E30F                  	and	bl, 0Fh
  1391 00000923 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1392 00000929 A2[5D290000]            	mov	[msgNamBar+1], al
  1393 0000092E 88D3                    	mov	bl, dl
  1394 00000930 C0EB04                  	shr	bl, 4
  1395 00000933 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1396 00000939 A2[5C290000]            	mov	[msgNamBar], al
  1397                                  
  1398                                  	;mov	ax, [ac97_NabmBar]
  1399 0000093E 66A1[442A0000]          	mov	ax, [NABMBAR]	; 29/05/2024
  1400 00000944 88C3                    	mov	bl, al
  1401 00000946 88DA                    	mov	dl, bl
  1402 00000948 80E30F                  	and	bl, 0Fh
  1403 0000094B 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1404 00000951 A2[6F290000]            	mov	[msgNabmBar+3], al
  1405 00000956 88D3                    	mov	bl, dl
  1406 00000958 C0EB04                  	shr	bl, 4
  1407 0000095B 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1408 00000961 A2[6E290000]            	mov	[msgNabmBar+2], al
  1409 00000966 88E3                    	mov	bl, ah
  1410 00000968 88DA                    	mov	dl, bl
  1411 0000096A 80E30F                  	and	bl, 0Fh
  1412 0000096D 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1413 00000973 A2[6D290000]            	mov	[msgNabmBar+1], al
  1414 00000978 88D3                    	mov	bl, dl
  1415 0000097A C0EB04                  	shr	bl, 4
  1416 0000097D 8A83[D6280000]          	mov	al, [ebx+hex_chars]
  1417 00000983 A2[6C290000]            	mov	[msgNabmBar], al
  1418                                  
  1419                                  	;xor	ah, ah
  1420 00000988 31C0                    	xor	eax, eax ; 31/05/2024
  1421 0000098A A0[382A0000]            	mov	al, [ac97_int_ln_reg]
  1422 0000098F B10A                    	mov	cl, 10
  1423 00000991 F6F1                    	div	cl
  1424 00000993 660105[78290000]        	add	[msgIRQ], ax
  1425 0000099A 20C0                    	and	al, al
  1426 0000099C 750D                    	jnz	short _w_ac97imsg_
  1427 0000099E A0[79290000]            	mov	al, [msgIRQ+1]
  1428 000009A3 B420                    	mov	ah, ' '
  1429 000009A5 66A3[78290000]          	mov	[msgIRQ], ax
  1430                                  _w_ac97imsg_:
  1431                                  	sys	_msg, msgAC97Info, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000009AB BB[E7280000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000009B0 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000009B5 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000009BA B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000009BF CD40                <1>  int 40h
  1432                                  
  1433 000009C1 C3                              retn
  1434                                  
  1435                                  write_VRA_info:
  1436                                  	; 25/11/2023
  1437                                  	sys	_msg, msgVRAheader, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000009C2 BB[7D290000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000009C7 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000009CC BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000009D1 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000009D6 CD40                <1>  int 40h
  1438 000009D8 803D[C9290000]00        	cmp	byte [VRA], 0
  1439 000009DF 7617                    	jna	short _w_VRAi_no
  1440                                  _w_VRAi_yes:
  1441                                  	sys	_msg, msgVRAyes, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000009E1 BB[8B290000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000009E6 B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000009EB BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000009F0 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 000009F5 CD40                <1>  int 40h
  1442 000009F7 C3                      	retn
  1443                                  _w_VRAi_no:
  1444                                  	sys	_msg, msgVRAno, 255, 07h
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000009F8 BB[91290000]        <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000009FD B9FF000000          <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000A02 BA07000000          <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000A07 B823000000          <1>  mov eax, %1
    90                              <1> 
    91 00000A0C CD40                <1>  int 40h
  1445 00000A0E C3                      	retn
  1446                                  
  1447                                  ; 02/02/2025
  1448                                  ; 08/12/2024
  1449                                  ; 29/05/2024 - playwav7.s
  1450                                  ; 26/11/2023
  1451                                  ; 25/11/2023 - playwav6.s (32 bit registers, TRDOS 386 adaption)
  1452                                  ; 15/11/2023 - PLAYWAV5.COM, ich_wav5.asm
  1453                                  ; 14/11/2023
  1454                                  ; 13/11/2023 - Erdogan Tan - (VRA, sample rate conversion)
  1455                                  ; --------------------------------------------------------
  1456                                  
  1457                                  ;;Note:	At the end of every buffer load,
  1458                                  ;;	during buffer switch/swap, there will be discontinuity
  1459                                  ;;	between the last converted sample and the 1st sample
  1460                                  ;;	of the next buffer.
  1461                                  ;;	(like as a dot noises vaguely between normal sound samples)
  1462                                  ;;	-To avoid this defect, the 1st sample of
  1463                                  ;;	the next buffer may be read from the wav file but
  1464                                  ;;	the file pointer would need to be set to 1 sample back
  1465                                  ;;	again via seek system call. Time comsumption problem! -
  1466                                  ;;
  1467                                  ;;	Erdogan Tan - 15/11/2023
  1468                                  ;;
  1469                                  ;;	((If entire wav data would be loaded at once.. conversion
  1470                                  ;;	defect/noise would disappear.. but for DOS, to keep
  1471                                  ;;	64KB buffer limit is important also it is important
  1472                                  ;;	for running under 1MB barrier without HIMEM.SYS or DPMI.
  1473                                  ;;	I have tested this program by using 2-30MB wav files.))
  1474                                  ;;
  1475                                  ;;	Test Computer:	ASUS desktop/mainboard, M2N4-SLI, 2010.
  1476                                  ;;			AMD Athlon 64 X2 2200 MHZ CPU.
  1477                                  ;;		       	NFORCE4 (CK804) AC97 audio hardware.
  1478                                  ;;			Realtek ALC850 codec.
  1479                                  ;;		       	Retro DOS v4.2 (MSDOS 6.22) operating system.
  1480                                  
  1481                                  load_8khz_mono_8_bit:
  1482                                  	; 02/02/2025
  1483                                  	; 15/11/2023
  1484                                  	; 14/11/2023
  1485                                  	; 13/11/2023
  1486 00000A0F F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1487                                  					; last of the file?
  1488 00000A16 7402                    	jz	short lff8m_0		; no
  1489 00000A18 F9                      	stc
  1490 00000A19 C3                      	retn
  1491                                  
  1492                                  lff8m_0:
  1493 00000A1A BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1494                                          ;mov	edx, [loadsize]
  1495                                  
  1496                                  	; esi = buffer address
  1497                                  	;; edx = buffer size
  1498                                  
  1499                                  	; load file into memory
  1500                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000A1F 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000A25 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000A27 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000A2D B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000A32 CD40                <1>  int 40h
  1501 00000A34 7305                    	jnc	short lff8m_6
  1502 00000A36 E9B0000000              	jmp	lff8m_5  ; error !
  1503                                  
  1504                                  lff8m_6:
  1505                                  	;mov	edi, audio_buffer
  1506                                  	; 29/05/2024
  1507 00000A3B 8B3D[462A0000]          	mov	edi, [audio_buffer]
  1508 00000A41 21C0                    	and	eax, eax
  1509 00000A43 0F8499000000            	jz	lff8_eof
  1510                                  
  1511 00000A49 89C1                    	mov	ecx, eax	; byte count
  1512                                  lff8m_1:
  1513 00000A4B AC                      	lodsb
  1514 00000A4C A2[A8210000]            	mov	[previous_val], al
  1515 00000A51 2C80                    	sub	al, 80h
  1516 00000A53 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1517 00000A57 66AB                    	stosw		; original sample (left channel)
  1518 00000A59 66AB                    	stosw		; original sample (right channel)
  1519                                  	; 02/02/2025
  1520                                  	;xor	eax, eax
  1521 00000A5B 8A06                    	mov	al, [esi]
  1522 00000A5D 49                      	dec	ecx
  1523 00000A5E 7502                    	jnz	short lff8m_2
  1524 00000A60 B080                    	mov	al, 80h
  1525                                  lff8m_2:
  1526                                  	;mov	[next_val], ax
  1527 00000A62 88C7                    	mov	bh, al	; [next_val]
  1528 00000A64 8A25[A8210000]          	mov	ah, [previous_val]
  1529 00000A6A 00E0                    	add	al, ah	; [previous_val]
  1530 00000A6C D0D8                    	rcr	al, 1
  1531 00000A6E 88C2                    	mov	dl, al	; this is interpolated middle (3th) sample
  1532 00000A70 00E0                    	add	al, ah	; [previous_val]
  1533 00000A72 D0D8                    	rcr	al, 1	
  1534 00000A74 88C3                    	mov	bl, al 	; this is temporary interpolation value
  1535 00000A76 00E0                    	add	al, ah	; [previous_val]
  1536 00000A78 D0D8                    	rcr	al, 1
  1537 00000A7A 2C80                    	sub	al, 80h
  1538 00000A7C 66C1E008                	shl	ax, 8
  1539 00000A80 66AB                    	stosw		; this is 1st interpolated sample (L)
  1540 00000A82 66AB                    	stosw		; this is 1st interpolated sample (R)
  1541 00000A84 88D8                    	mov	al, bl
  1542 00000A86 00D0                    	add	al, dl
  1543 00000A88 D0D8                    	rcr	al, 1
  1544 00000A8A 2C80                    	sub	al, 80h
  1545 00000A8C 66C1E008                	shl	ax, 8
  1546 00000A90 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1547 00000A92 66AB                    	stosw		; this is 2nd interpolated sample (R)
  1548 00000A94 88D0                    	mov	al, dl
  1549 00000A96 2C80                    	sub	al, 80h
  1550 00000A98 66C1E008                	shl	ax, 8
  1551 00000A9C 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1552 00000A9E 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1553                                  	;mov	al, [next_val]
  1554 00000AA0 88F8                    	mov	al, bh
  1555 00000AA2 00D0                    	add	al, dl
  1556 00000AA4 D0D8                    	rcr	al, 1
  1557 00000AA6 88C3                    	mov	bl, al	; this is temporary interpolation value
  1558 00000AA8 00D0                    	add	al, dl
  1559 00000AAA D0D8                    	rcr	al, 1
  1560 00000AAC 2C80                    	sub	al, 80h
  1561 00000AAE 66C1E008                	shl	ax, 8
  1562 00000AB2 66AB                    	stosw		; this is 4th interpolated sample (L)
  1563 00000AB4 66AB                    	stosw		; this is 4th interpolated sample (R)
  1564                                  	;mov	al, [next_val]
  1565 00000AB6 88F8                    	mov	al, bh
  1566 00000AB8 00D8                    	add	al, bl
  1567 00000ABA D0D8                    	rcr	al, 1
  1568 00000ABC 2C80                    	sub	al, 80h
  1569 00000ABE 66C1E008                	shl	ax, 8
  1570 00000AC2 66AB                    	stosw		; this is 5th interpolated sample (L)
  1571 00000AC4 66AB                    	stosw		; this is 5th interpolated sample (R)
  1572                                  	; 8 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1573 00000AC6 09C9                    	or	ecx, ecx
  1574 00000AC8 7581                    	jnz	short lff8m_1
  1575                                  
  1576                                  	; --------------
  1577                                  
  1578                                  lff8s_3:
  1579                                  lff8m_3:
  1580                                  lff8s2_3:
  1581                                  lff8m2_3:
  1582                                  lff16s_3:
  1583                                  lff16m_3:
  1584                                  lff16s2_3:
  1585                                  lff16m2_3:
  1586                                  lff24_3:
  1587                                  lff32_3:
  1588                                  lff44_3:
  1589                                  lff22_3:
  1590                                  lff11_3:
  1591                                  lff12_3:	; 02/02/2025
  1592                                  	; 08/12/2024 (BugFix)
  1593                                  	; 01/06/2024 (BugFix)
  1594 00000ACA 8B0D[BC030000]          	mov	ecx, [buffersize] ; 16 bit (48 kHZ, stereo) sample size
  1595                                  	;shl	ecx, 1	; byte count ; Bug !
  1596                                  	; 08/12/2024
  1597                                  	;add	ecx, audio_buffer
  1598 00000AD0 030D[462A0000]          	add	ecx, [audio_buffer] ; 02/02/2025
  1599 00000AD6 29F9                    	sub	ecx, edi
  1600 00000AD8 7607                    	jna	short lff8m_4
  1601                                  	;inc	ecx
  1602 00000ADA C1E902                  	shr	ecx, 2
  1603 00000ADD 31C0                    	xor	eax, eax ; fill (remain part of) buffer with zeros
  1604 00000ADF F3AB                    	rep	stosd
  1605                                  lff8m_4:
  1606                                  	; 01/06/2024 (BugFix)
  1607                                  	; cf=1 ; Bug !
  1608                                  	; 08/12/2024
  1609                                  	;clc
  1610 00000AE1 C3                      	retn
  1611                                  
  1612                                  lff8_eof:
  1613                                  lff16_eof:
  1614                                  lff24_eof:
  1615                                  lff32_eof:
  1616                                  lff44_eof:
  1617                                  lff22_eof:
  1618                                  lff11_eof:
  1619                                  lff12_eof:	; 02/02/2025
  1620                                  	; 15/11/2023
  1621 00000AE2 C605[C8290000]01        	mov	byte [flags], ENDOFFILE
  1622 00000AE9 EBDF                    	jmp	short lff8m_3
  1623                                  
  1624                                  lff8s_5:
  1625                                  lff8m_5:
  1626                                  lff8s2_5:
  1627                                  lff8m2_5:
  1628                                  lff16s_5:
  1629                                  lff16m_5:
  1630                                  lff16s2_5:
  1631                                  lff16m2_5:
  1632                                  lff24_5:
  1633                                  lff32_5:
  1634                                  lff44_5:
  1635                                  lff22_5:
  1636                                  lff11_5:
  1637                                  lff12_5:	; 02/02/2025
  1638 00000AEB B021                    	mov	al, '!'  ; error
  1639 00000AED E886FAFFFF              	call	tL0
  1640                                  	
  1641                                  	;jmp	short lff8m_3
  1642                                  	; 15/11/2023
  1643 00000AF2 EBEE                    	jmp	lff8_eof
  1644                                  
  1645                                  	; --------------
  1646                                  
  1647                                  load_8khz_stereo_8_bit:
  1648                                  	; 02/02/2025
  1649                                  	; 15/11/2023
  1650                                  	; 14/11/2023
  1651                                  	; 13/11/2023
  1652 00000AF4 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1653                                  					; last of the file?
  1654 00000AFB 7402                    	jz	short lff8s_0		; no
  1655 00000AFD F9                      	stc
  1656 00000AFE C3                      	retn
  1657                                  
  1658                                  lff8s_0:
  1659 00000AFF BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1660                                          ;mov	edx, [loadsize]
  1661                                  
  1662                                  	; esi = buffer address
  1663                                  	;; edx = buffer size
  1664                                  
  1665                                  	; load file into memory
  1666                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000B04 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000B0A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000B0C 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000B12 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000B17 CD40                <1>  int 40h
  1667 00000B19 72D0                    	jc	short lff8s_5 ; error !
  1668                                  
  1669                                  	;mov	edi, audio_buffer
  1670                                  	; 29/05/2024
  1671 00000B1B 8B3D[462A0000]          	mov	edi, [audio_buffer]
  1672                                  	
  1673 00000B21 D1E8                    	shr	eax, 1
  1674 00000B23 74BD                    	jz	short lff8_eof
  1675                                  
  1676 00000B25 89C1                    	mov	ecx, eax	; word count
  1677                                  lff8s_1:
  1678 00000B27 AC                      	lodsb
  1679 00000B28 A2[A8210000]            	mov	[previous_val_l], al
  1680 00000B2D 2C80                    	sub	al, 80h
  1681 00000B2F 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1682 00000B33 66AB                    	stosw		; original sample (L)
  1683 00000B35 AC                      	lodsb
  1684 00000B36 A2[AA210000]            	mov	[previous_val_r], al
  1685 00000B3B 2C80                    	sub	al, 80h
  1686 00000B3D 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  1687 00000B41 66AB                    	stosw		; original sample (R)
  1688                                  
  1689                                  	;xor	eax, eax
  1690                                  	; 02/02/2025
  1691 00000B43 668B06                  	mov	ax, [esi]
  1692 00000B46 49                      	dec	ecx
  1693 00000B47 7504                    	jnz	short lff8s_2
  1694                                  		; convert 8 bit sample to 16 bit sample
  1695 00000B49 66B88080                	mov	ax, 8080h
  1696                                  lff8s_2:
  1697 00000B4D A2[AC210000]            	mov	[next_val_l], al
  1698 00000B52 8825[AE210000]          	mov	[next_val_r], ah
  1699 00000B58 8A25[A8210000]          	mov	ah, [previous_val_l]
  1700 00000B5E 00E0                    	add	al, ah
  1701 00000B60 D0D8                    	rcr	al, 1
  1702 00000B62 88C2                    	mov	dl, al	; this is interpolated middle (3th) sample (L)
  1703 00000B64 00E0                    	add	al, ah
  1704 00000B66 D0D8                    	rcr	al, 1	
  1705 00000B68 88C3                    	mov	bl, al	; this is temporary interpolation value (L)
  1706 00000B6A 00E0                    	add	al, ah
  1707 00000B6C D0D8                    	rcr	al, 1
  1708 00000B6E 2C80                    	sub	al, 80h
  1709 00000B70 66C1E008                	shl	ax, 8
  1710 00000B74 66AB                    	stosw		; this is 1st interpolated sample (L)
  1711 00000B76 A0[AE210000]            	mov	al, [next_val_r]
  1712 00000B7B 8A25[AA210000]          	mov	ah, [previous_val_r]
  1713 00000B81 00E0                    	add	al, ah
  1714 00000B83 D0D8                    	rcr	al, 1
  1715 00000B85 88C6                    	mov	dh, al	; this is interpolated middle (3th) sample (R)
  1716 00000B87 00E0                    	add	al, ah
  1717 00000B89 D0D8                    	rcr	al, 1
  1718 00000B8B 88C7                    	mov	bh, al	; this is temporary interpolation value (R)
  1719 00000B8D 00E0                    	add	al, ah
  1720 00000B8F D0D8                    	rcr	al, 1
  1721 00000B91 2C80                    	sub	al, 80h
  1722 00000B93 66C1E008                	shl	ax, 8
  1723 00000B97 66AB                    	stosw		; this is 1st interpolated sample (R)
  1724 00000B99 88D8                    	mov	al, bl
  1725 00000B9B 00D0                    	add	al, dl
  1726 00000B9D D0D8                    	rcr	al, 1
  1727 00000B9F 2C80                    	sub	al, 80h
  1728 00000BA1 66C1E008                	shl	ax, 8
  1729 00000BA5 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1730 00000BA7 88F8                    	mov	al, bh
  1731 00000BA9 00F0                    	add	al, dh
  1732 00000BAB D0D8                    	rcr	al, 1
  1733 00000BAD 2C80                    	sub	al, 80h
  1734 00000BAF 66C1E008                	shl	ax, 8
  1735 00000BB3 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  1736 00000BB5 88D0                    	mov	al, dl
  1737 00000BB7 2C80                    	sub	al, 80h
  1738 00000BB9 66C1E008                	shl	ax, 8
  1739 00000BBD 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1740 00000BBF 88F0                    	mov	al, dh
  1741 00000BC1 2C80                    	sub	al, 80h
  1742 00000BC3 66C1E008                	shl	ax, 8
  1743 00000BC7 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1744 00000BC9 A0[AC210000]            	mov	al, [next_val_l]
  1745 00000BCE 00D0                    	add	al, dl
  1746 00000BD0 D0D8                    	rcr	al, 1
  1747 00000BD2 88C3                    	mov	bl, al	; this is temporary interpolation value (L)
  1748 00000BD4 00D0                    	add	al, dl
  1749 00000BD6 D0D8                    	rcr	al, 1
  1750 00000BD8 2C80                    	sub	al, 80h
  1751 00000BDA 66C1E008                	shl	ax, 8
  1752 00000BDE 66AB                    	stosw		; this is 4th interpolated sample (L)
  1753 00000BE0 A0[AE210000]            	mov	al, [next_val_r]
  1754 00000BE5 00F0                    	add	al, dh
  1755 00000BE7 D0D8                    	rcr	al, 1
  1756 00000BE9 88C7                    	mov	bh, al	; this is temporary interpolation value (R)
  1757 00000BEB 00F0                    	add	al, dh
  1758 00000BED D0D8                    	rcr	al, 1
  1759 00000BEF 2C80                    	sub	al, 80h
  1760 00000BF1 66C1E008                	shl	ax, 8
  1761 00000BF5 66AB                    	stosw		; this is 4th interpolated sample (R)
  1762 00000BF7 A0[AC210000]            	mov	al, [next_val_l]
  1763 00000BFC 00D8                    	add	al, bl
  1764 00000BFE D0D8                    	rcr	al, 1
  1765 00000C00 2C80                    	sub	al, 80h
  1766 00000C02 66C1E008                	shl	ax, 8
  1767 00000C06 66AB                    	stosw		; this is 5th interpolated sample (L)
  1768 00000C08 A0[AE210000]            	mov	al, [next_val_r]
  1769 00000C0D 00F8                    	add	al, bh
  1770 00000C0F D0D8                    	rcr	al, 1
  1771 00000C11 2C80                    	sub	al, 80h
  1772 00000C13 66C1E008                	shl	ax, 8
  1773 00000C17 66AB                    	stosw		; this is 5th interpolated sample (R)
  1774                                  	; 8 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  1775 00000C19 E305                    	jecxz	lff8s_6
  1776 00000C1B E907FFFFFF              	jmp	lff8s_1
  1777                                  lff8s_6:
  1778 00000C20 E9A5FEFFFF              	jmp	lff8s_3
  1779                                  
  1780                                  load_8khz_mono_16_bit:
  1781                                  	; 02/02/2025
  1782                                  	; 13/11/2023
  1783 00000C25 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1784                                  					; last of the file?
  1785 00000C2C 7402                    	jz	short lff8m2_0		; no
  1786 00000C2E F9                      	stc
  1787 00000C2F C3                      	retn
  1788                                  
  1789                                  lff8m2_0:
  1790 00000C30 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1791                                          ;mov	edx, [loadsize]
  1792                                  
  1793                                  	; esi = buffer address
  1794                                  	;; edx = buffer size
  1795                                  
  1796                                  	; load file into memory
  1797                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000C35 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000C3B 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000C3D 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000C43 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000C48 CD40                <1>  int 40h
  1798 00000C4A 0F82A1000000            	jc	lff8m2_7 ; error !
  1799                                  
  1800                                  	;mov	edi, audio_buffer
  1801                                  	; 29/05/2024
  1802 00000C50 8B3D[462A0000]          	mov	edi, [audio_buffer]
  1803                                  	
  1804 00000C56 D1E8                    	shr	eax, 1
  1805 00000C58 7505                    	jnz	short lff8m2_8
  1806 00000C5A E983FEFFFF              	jmp	lff8_eof
  1807                                  
  1808                                  lff8m2_8:
  1809 00000C5F 89C1                    	mov	ecx, eax	; word count
  1810                                  lff8m2_1:
  1811 00000C61 66AD                    	lodsw
  1812 00000C63 66AB                    	stosw		; original sample (left channel)
  1813 00000C65 66AB                    	stosw		; original sample (right channel)
  1814 00000C67 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1815 00000C6A 66A3[A8210000]          	mov	[previous_val], ax
  1816                                  	; 02/02/2025
  1817 00000C70 668B06                  	mov	ax, [esi]
  1818 00000C73 49                      	dec	ecx
  1819 00000C74 7502                    	jnz	short lff8m2_2
  1820 00000C76 31C0                    	xor	eax, eax
  1821                                  lff8m2_2:
  1822 00000C78 80C480                  	add	ah, 80h ; convert sound level to 0-65535 format
  1823 00000C7B 89C5                    	mov	ebp, eax ; [next_val]
  1824 00000C7D 660305[A8210000]        	add	ax, [previous_val]
  1825 00000C84 66D1D8                  	rcr	ax, 1
  1826 00000C87 89C2                    	mov	edx, eax ; this is interpolated middle (3th) sample
  1827 00000C89 660305[A8210000]        	add	ax, [previous_val]
  1828 00000C90 66D1D8                  	rcr	ax, 1	; this is temporary interpolation value
  1829 00000C93 89C3                    	mov	ebx, eax 		
  1830 00000C95 660305[A8210000]        	add	ax, [previous_val]
  1831 00000C9C 66D1D8                  	rcr	ax, 1
  1832 00000C9F 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1833 00000CA2 66AB                    	stosw		; this is 1st interpolated sample (L)
  1834 00000CA4 66AB                    	stosw		; this is 1st interpolated sample (R)
  1835 00000CA6 89D8                    	mov	eax, ebx
  1836 00000CA8 6601D0                  	add	ax, dx
  1837 00000CAB 66D1D8                  	rcr	ax, 1
  1838 00000CAE 80EC80                  	sub	ah, 80h
  1839 00000CB1 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1840 00000CB3 66AB                    	stosw		; this is 2nd interpolated sample (R)
  1841 00000CB5 89D0                    	mov	eax, edx
  1842 00000CB7 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1843 00000CBA 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1844 00000CBC 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1845 00000CBE 89E8                    	mov	eax, ebp
  1846 00000CC0 6601D0                  	add	ax, dx
  1847 00000CC3 66D1D8                  	rcr	ax, 1
  1848 00000CC6 89C3                    	mov	ebx, eax ; this is temporary interpolation value
  1849 00000CC8 6601D0                  	add	ax, dx
  1850 00000CCB 66D1D8                  	rcr	ax, 1
  1851 00000CCE 80EC80                  	sub	ah, 80h
  1852 00000CD1 66AB                    	stosw		; this is 4th interpolated sample (L)
  1853 00000CD3 66AB                    	stosw		; this is 4th interpolated sample (R)
  1854 00000CD5 89E8                    	mov	eax, ebp
  1855 00000CD7 6601D8                  	add	ax, bx
  1856 00000CDA 66D1D8                  	rcr	ax, 1
  1857 00000CDD 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1858 00000CE0 66AB                    	stosw		; this is 5th interpolated sample (L)
  1859 00000CE2 66AB                    	stosw		; this is 5th interpolated sample (R)
  1860                                  	; 8 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  1861 00000CE4 09C9                    	or	ecx, ecx
  1862 00000CE6 0F8575FFFFFF            	jnz	lff8m2_1
  1863 00000CEC E9D9FDFFFF              	jmp	lff8m2_3
  1864                                  
  1865                                  lff8m2_7:
  1866                                  lff8s2_7:
  1867 00000CF1 E9F5FDFFFF              	jmp	lff8m2_5  ; error
  1868                                  
  1869                                  load_8khz_stereo_16_bit:
  1870                                  	; 02/02/2025
  1871                                  	; 16/11/2023
  1872                                  	; 15/11/2023
  1873                                  	; 13/11/2023
  1874 00000CF6 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  1875                                  					; last of the file?
  1876 00000CFD 7402                    	jz	short lff8s2_0		; no
  1877 00000CFF F9                      	stc
  1878 00000D00 C3                      	retn
  1879                                  
  1880                                  lff8s2_0:
  1881 00000D01 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  1882                                          ;mov	edx, [loadsize]
  1883                                  
  1884                                  	; esi = buffer address
  1885                                  	;; edx = buffer size
  1886                                  
  1887                                  	; load file into memory
  1888                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000D06 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000D0C 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000D0E 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000D14 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000D19 CD40                <1>  int 40h
  1889 00000D1B 72D4                    	jc	short lff8s2_7 ; error !
  1890                                  
  1891                                  	;mov	edi, audio_buffer
  1892                                  	; 29/05/2024
  1893 00000D1D 8B3D[462A0000]          	mov	edi, [audio_buffer]
  1894                                  	
  1895 00000D23 C1E802                  	shr	eax, 2
  1896 00000D26 7505                    	jnz	short lff8s2_8
  1897 00000D28 E9B5FDFFFF              	jmp	lff8_eof
  1898                                  
  1899                                  lff8s2_8:
  1900 00000D2D 89C1                    	mov	ecx, eax ; dword count
  1901                                  lff8s2_1:
  1902 00000D2F 66AD                    	lodsw
  1903 00000D31 66AB                    	stosw		; original sample (L)
  1904                                  	; 15/11/2023
  1905 00000D33 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1906 00000D36 66A3[A8210000]          	mov	[previous_val_l], ax
  1907 00000D3C 66AD                    	lodsw
  1908 00000D3E 66AB                    	stosw		; original sample (R)
  1909 00000D40 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1910 00000D43 66A3[AA210000]          	mov	[previous_val_r], ax
  1911                                  	; 02/02/2025
  1912 00000D49 668B06                  	mov	ax, [esi]
  1913 00000D4C 668B5602                	mov	dx, [esi+2]
  1914                                  	; 16/11/2023
  1915 00000D50 49                      	dec	ecx
  1916 00000D51 7504                    	jnz	short lff8s2_2
  1917 00000D53 31D2                    	xor	edx, edx
  1918 00000D55 31C0                    	xor	eax, eax
  1919                                  lff8s2_2:
  1920 00000D57 80C480                  	add	ah, 80h	; convert sound level to 0-65535 format
  1921 00000D5A 66A3[AC210000]          	mov	[next_val_l], ax
  1922 00000D60 80C680                  	add	dh, 80h	; convert sound level to 0-65535 format
  1923 00000D63 668915[AE210000]        	mov	[next_val_r], dx
  1924 00000D6A 660305[A8210000]        	add	ax, [previous_val_l]
  1925 00000D71 66D1D8                  	rcr	ax, 1
  1926 00000D74 89C2                    	mov	edx, eax ; this is interpolated middle (3th) sample (L)
  1927 00000D76 660305[A8210000]        	add	ax, [previous_val_l]
  1928 00000D7D 66D1D8                  	rcr	ax, 1	
  1929 00000D80 89C3                    	mov	ebx, eax ; this is temporary interpolation value (L)
  1930 00000D82 660305[A8210000]        	add	ax, [previous_val_l]
  1931 00000D89 66D1D8                  	rcr	ax, 1
  1932 00000D8C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1933 00000D8F 66AB                    	stosw		; this is 1st interpolated sample (L)
  1934 00000D91 66A1[AE210000]          	mov	ax, [next_val_r]
  1935 00000D97 660305[AA210000]        	add	ax, [previous_val_r]
  1936 00000D9E 66D1D8                  	rcr	ax, 1
  1937 00000DA1 89C5                    	mov	ebp, eax ; this is interpolated middle (3th) sample (R)
  1938 00000DA3 660305[AA210000]        	add	ax, [previous_val_r]
  1939 00000DAA 66D1D8                  	rcr	ax, 1
  1940 00000DAD 50                      	push	eax ; *	; this is temporary interpolation value (R)
  1941 00000DAE 660305[AA210000]        	add	ax, [previous_val_r]
  1942 00000DB5 66D1D8                  	rcr	ax, 1
  1943 00000DB8 80EC80                  	sub	ah, 80h
  1944 00000DBB 66AB                    	stosw		; this is 1st interpolated sample (R)
  1945 00000DBD 89D8                    	mov	eax, ebx
  1946 00000DBF 6601D0                  	add	ax, dx
  1947 00000DC2 66D1D8                  	rcr	ax, 1
  1948 00000DC5 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1949 00000DC8 66AB                    	stosw		; this is 2nd interpolated sample (L)
  1950 00000DCA 58                      	pop	eax ; *
  1951 00000DCB 6601E8                  	add	ax, bp
  1952 00000DCE 66D1D8                  	rcr	ax, 1
  1953 00000DD1 80EC80                  	sub	ah, 80h
  1954 00000DD4 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  1955 00000DD6 89D0                    	mov	eax, edx
  1956 00000DD8 80EC80                  	sub	ah, 80h
  1957 00000DDB 66AB                    	stosw		; this is middle (3th) interpolated sample (L)
  1958 00000DDD 89E8                    	mov	eax, ebp
  1959 00000DDF 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1960 00000DE2 66AB                    	stosw		; this is middle (3th) interpolated sample (R)
  1961 00000DE4 66A1[AC210000]          	mov	ax, [next_val_l]
  1962 00000DEA 6601D0                  	add	ax, dx
  1963 00000DED 66D1D8                  	rcr	ax, 1
  1964 00000DF0 89C3                    	mov	ebx, eax ; this is temporary interpolation value (L)
  1965 00000DF2 6601D0                  	add	ax, dx
  1966 00000DF5 66D1D8                  	rcr	ax, 1
  1967 00000DF8 80EC80                  	sub	ah, 80h
  1968 00000DFB 66AB                    	stosw		; this is 4th interpolated sample (L)
  1969 00000DFD 66A1[AE210000]          	mov	ax, [next_val_r]
  1970 00000E03 6601E8                  	add	ax, bp
  1971 00000E06 66D1D8                  	rcr	ax, 1
  1972 00000E09 50                      	push	eax ; ** ; this is temporary interpolation value (R)
  1973 00000E0A 6601E8                  	add	ax, bp
  1974 00000E0D 66D1D8                  	rcr	ax, 1
  1975 00000E10 80EC80                  	sub	ah, 80h
  1976 00000E13 66AB                    	stosw		; this is 4th interpolated sample (R)
  1977 00000E15 66A1[AC210000]          	mov	ax, [next_val_l]
  1978 00000E1B 6601D8                  	add	ax, bx
  1979 00000E1E 66D1D8                  	rcr	ax, 1
  1980 00000E21 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  1981 00000E24 66AB                    	stosw		; this is 5th interpolated sample (L)
  1982 00000E26 58                      	pop	eax ; **
  1983 00000E27 660305[AE210000]        	add	ax, [next_val_r]
  1984 00000E2E 66D1D8                  	rcr	ax, 1
  1985 00000E31 80EC80                  	sub	ah, 80h
  1986 00000E34 66AB                    	stosw		; this is 5th interpolated sample (R)
  1987                                  	; 8 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  1988 00000E36 E305                    	jecxz	lff8_s2_9
  1989 00000E38 E9F2FEFFFF              	jmp	lff8s2_1
  1990                                  lff8_s2_9:
  1991 00000E3D E988FCFFFF              	jmp	lff8s2_3
  1992                                  
  1993                                  ; .....................
  1994                                  
  1995                                  load_16khz_mono_8_bit:
  1996                                  	; 02/02/2025
  1997                                  	; 14/11/2023
  1998                                  	; 13/11/2023
  1999 00000E42 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2000                                  					; last of the file?
  2001 00000E49 7402                    	jz	short lff16m_0		; no
  2002 00000E4B F9                      	stc
  2003 00000E4C C3                      	retn
  2004                                  
  2005                                  lff16m_0:
  2006 00000E4D BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2007                                          ;mov	edx, [loadsize]
  2008                                  
  2009                                  	; esi = buffer address
  2010                                  	;; edx = buffer size
  2011                                  
  2012                                  	; load file into memory
  2013                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000E52 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000E58 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000E5A 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000E60 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000E65 CD40                <1>  int 40h
  2014 00000E67 7254                    	jc	short lff16m_7 ; error !
  2015                                  
  2016                                  	;mov	edi, audio_buffer
  2017                                  	; 29/05/2024
  2018 00000E69 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2019                                  	
  2020 00000E6F 21C0                    	and	eax, eax
  2021 00000E71 7505                    	jnz	short lff16m_8
  2022 00000E73 E96AFCFFFF              	jmp	lff16_eof
  2023                                  
  2024                                  lff16m_8:
  2025 00000E78 89C1                    	mov	ecx, eax		; byte count
  2026                                  lff16m_1:
  2027 00000E7A AC                      	lodsb
  2028                                  	;mov	[previous_val], al
  2029 00000E7B 88C3                    	mov	bl, al
  2030 00000E7D 2C80                    	sub	al, 80h
  2031 00000E7F 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2032 00000E83 66AB                    	stosw		; original sample (left channel)
  2033 00000E85 66AB                    	stosw		; original sample (right channel)
  2034                                  	;xor	eax, eax
  2035                                  	; 02/02/2025
  2036 00000E87 8A06                    	mov	al, [esi]
  2037 00000E89 49                      	dec	ecx
  2038 00000E8A 7502                    	jnz	short lff16m_2
  2039                                  	; 14/11/2023
  2040 00000E8C B080                    	mov	al, 80h
  2041                                  lff16m_2:
  2042                                  	;mov	[next_val], al
  2043 00000E8E 88C7                    	mov	bh, al
  2044                                  	;add	al, [previous_val]
  2045 00000E90 00D8                    	add	al, bl
  2046 00000E92 D0D8                    	rcr	al, 1
  2047 00000E94 88C2                    	mov	dl, al	; this is interpolated middle (temp) sample
  2048                                  	;add	al, [previous_val]
  2049 00000E96 00D8                    	add	al, bl
  2050 00000E98 D0D8                    	rcr	al, 1
  2051 00000E9A 2C80                    	sub	al, 80h
  2052 00000E9C 66C1E008                	shl	ax, 8
  2053 00000EA0 66AB                    	stosw		; this is 1st interpolated sample (L)
  2054 00000EA2 66AB                    	stosw		; this is 1st interpolated sample (R)
  2055                                  	;mov	al, [next_val]
  2056 00000EA4 88F8                    	mov	al, bh
  2057 00000EA6 00D0                    	add	al, dl
  2058 00000EA8 D0D8                    	rcr	al, 1
  2059 00000EAA 2C80                    	sub	al, 80h
  2060 00000EAC 66C1E008                	shl	ax, 8
  2061 00000EB0 66AB                    	stosw		; this is 2nd interpolated sample (L)
  2062 00000EB2 66AB                    	stosw		; this is 2nd interpolated sample (R)
  2063                                  	
  2064                                  	; 16 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2065 00000EB4 09C9                    	or	ecx, ecx
  2066 00000EB6 75C2                    	jnz	short lff16m_1
  2067 00000EB8 E90DFCFFFF              	jmp	lff16m_3
  2068                                  
  2069                                  lff16m_7:
  2070                                  lff16s_7:
  2071 00000EBD E929FCFFFF              	jmp	lff16m_5  ; error
  2072                                  
  2073                                  load_16khz_stereo_8_bit:
  2074                                  	; 02/02/2025
  2075                                  	; 14/11/2023
  2076                                  	; 13/11/2023
  2077 00000EC2 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2078                                  					; last of the file?
  2079 00000EC9 7402                    	jz	short lff16s_0		; no
  2080 00000ECB F9                      	stc
  2081 00000ECC C3                      	retn
  2082                                  
  2083                                  lff16s_0:
  2084 00000ECD BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2085                                          ;mov	edx, [loadsize]
  2086                                  
  2087                                  	; esi = buffer address
  2088                                  	;; edx = buffer size
  2089                                  
  2090                                  	; load file into memory
  2091                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000ED2 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000ED8 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000EDA 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000EE0 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000EE5 CD40                <1>  int 40h
  2092 00000EE7 72D4                    	jc	short lff16s_7 ; error !
  2093                                  
  2094                                  	;mov	edi, audio_buffer
  2095                                  	; 29/05/2024
  2096 00000EE9 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2097                                  	
  2098 00000EEF D1E8                    	shr	eax, 1
  2099 00000EF1 7505                    	jnz	short lff16s_8
  2100 00000EF3 E9EAFBFFFF              	jmp	lff16_eof
  2101                                  
  2102                                  lff16s_8:
  2103 00000EF8 89C1                    	mov	ecx, eax	; word count
  2104                                  lff16s_1:
  2105 00000EFA AC                      	lodsb
  2106 00000EFB A2[A8210000]            	mov	[previous_val_l], al
  2107 00000F00 2C80                    	sub	al, 80h
  2108 00000F02 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2109 00000F06 66AB                    	stosw		; original sample (L)
  2110 00000F08 AC                      	lodsb
  2111 00000F09 A2[AA210000]            	mov	[previous_val_r], al
  2112 00000F0E 2C80                    	sub	al, 80h
  2113 00000F10 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2114 00000F14 66AB                    	stosw		; original sample (R)
  2115                                  
  2116                                  	;xor	eax, eax
  2117                                  	; 02/02/2025
  2118 00000F16 668B06                  	mov	ax, [esi]
  2119 00000F19 49                      	dec	ecx
  2120 00000F1A 7504                    	jnz	short lff16s_2
  2121                                  		; convert 8 bit sample to 16 bit sample
  2122                                  	; 14/11/2023
  2123 00000F1C 66B88080                	mov	ax, 8080h
  2124                                  lff16s_2:
  2125                                  	;mov	[next_val_l], al
  2126                                  	;mov	[next_val_r], ah
  2127 00000F20 89C3                    	mov	ebx, eax
  2128 00000F22 0205[A8210000]          	add	al, [previous_val_l]
  2129 00000F28 D0D8                    	rcr	al, 1
  2130 00000F2A 88C2                    	mov	dl, al	; this is temporary interpolation value (L)
  2131 00000F2C 0205[A8210000]          	add	al, [previous_val_l]
  2132 00000F32 D0D8                    	rcr	al, 1
  2133 00000F34 2C80                    	sub	al, 80h
  2134 00000F36 66C1E008                	shl	ax, 8
  2135 00000F3A 66AB                    	stosw		; this is 1st interpolated sample (L)
  2136 00000F3C 88F8                    	mov	al, bh	; [next_val_r]
  2137 00000F3E 0205[AA210000]          	add	al, [previous_val_r]
  2138 00000F44 D0D8                    	rcr	al, 1
  2139 00000F46 88C6                    	mov	dh, al	; this is temporary interpolation value (R)
  2140 00000F48 0205[AA210000]          	add	al, [previous_val_r]
  2141 00000F4E D0D8                    	rcr	al, 1
  2142 00000F50 2C80                    	sub	al, 80h
  2143 00000F52 66C1E008                	shl	ax, 8
  2144 00000F56 66AB                    	stosw		; this is 1st interpolated sample (R)
  2145 00000F58 88D0                    	mov	al, dl
  2146 00000F5A 00D8                    	add	al, bl	; [next_val_l]
  2147 00000F5C D0D8                    	rcr	al, 1
  2148 00000F5E 2C80                    	sub	al, 80h
  2149 00000F60 66C1E008                	shl	ax, 8
  2150 00000F64 66AB                    	stosw		; this is 2nd interpolated sample (L)
  2151 00000F66 88F0                    	mov	al, dh
  2152 00000F68 00F8                    	add	al, bh	; [next_val_r]
  2153 00000F6A D0D8                    	rcr	al, 1
  2154 00000F6C 2C80                    	sub	al, 80h
  2155 00000F6E 66C1E008                	shl	ax, 8
  2156 00000F72 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  2157                                  	
  2158                                  	; 16 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2159 00000F74 09C9                    	or	ecx, ecx
  2160 00000F76 7582                    	jnz	short lff16s_1
  2161 00000F78 E94DFBFFFF              	jmp	lff16s_3
  2162                                  
  2163                                  load_16khz_mono_16_bit:
  2164                                  	; 02/02/2025
  2165                                  	; 15/11/2023
  2166                                  	; 13/11/2023
  2167 00000F7D F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2168                                  					; last of the file?
  2169 00000F84 7402                    	jz	short lff16m2_0		; no
  2170 00000F86 F9                      	stc
  2171 00000F87 C3                      	retn
  2172                                  
  2173                                  lff16m2_0:
  2174 00000F88 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2175                                          ;mov	edx, [loadsize]
  2176                                  
  2177                                  	; esi = buffer address
  2178                                  	;; edx = buffer size
  2179                                  
  2180                                  	; load file into memory
  2181                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00000F8D 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00000F93 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00000F95 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00000F9B B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00000FA0 CD40                <1>  int 40h
  2182 00000FA2 7256                    	jc	short lff16m2_7 ; error !
  2183                                  
  2184                                  	;mov	edi, audio_buffer
  2185                                  	; 29/05/2024
  2186 00000FA4 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2187                                  	
  2188 00000FAA D1E8                    	shr	eax, 1
  2189 00000FAC 7505                    	jnz	short lff16m2_8
  2190 00000FAE E92FFBFFFF              	jmp	lff16_eof
  2191                                  
  2192                                  lff16m2_8:
  2193 00000FB3 89C1                    	mov	ecx, eax  ; word count
  2194                                  lff16m2_1:
  2195 00000FB5 66AD                    	lodsw
  2196 00000FB7 66AB                    	stosw		; original sample (left channel)
  2197 00000FB9 66AB                    	stosw		; original sample (right channel)
  2198 00000FBB 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2199                                  	;mov	[previous_val], ax
  2200 00000FBE 89C3                    	mov	ebx, eax
  2201                                  	; 02/02/2025
  2202 00000FC0 668B06                  	mov	ax, [esi]
  2203 00000FC3 49                      	dec	ecx
  2204 00000FC4 7502                    	jnz	short lff16m2_2
  2205 00000FC6 31C0                    	xor	eax, eax
  2206                                  lff16m2_2:
  2207 00000FC8 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2208 00000FCB 89C5                    	mov	ebp, eax ; [next_val]
  2209                                  	;add	ax, [previous_val]
  2210 00000FCD 6601D8                  	add	ax, bx
  2211 00000FD0 66D1D8                  	rcr	ax, 1
  2212 00000FD3 89C2                    	mov	edx, eax ; this is temporary interpolation value
  2213                                  	;add	ax, [previous_val]
  2214 00000FD5 6601D8                  	add	ax, bx
  2215 00000FD8 66D1D8                  	rcr	ax, 1
  2216 00000FDB 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2217 00000FDE 66AB                    	stosw		; this is 1st interpolated sample (L)
  2218 00000FE0 66AB                    	stosw		; this is 1st interpolated sample (R)
  2219 00000FE2 89E8                    	mov	eax, ebp 
  2220 00000FE4 6601D0                  	add	ax, dx
  2221 00000FE7 66D1D8                  	rcr	ax, 1
  2222 00000FEA 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2223 00000FED 66AB                    	stosw		; this is 2nd interpolated sample (L)
  2224 00000FEF 66AB                    	stosw		; this is 2nd interpolated sample (R)
  2225                                  	; 16 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2226 00000FF1 09C9                    	or	ecx, ecx
  2227 00000FF3 75C0                    	jnz	short lff16m2_1
  2228 00000FF5 E9D0FAFFFF              	jmp	lff16m2_3
  2229                                  
  2230                                  lff16m2_7:
  2231                                  lff16s2_7:
  2232 00000FFA E9ECFAFFFF              	jmp	lff16m2_5  ; error
  2233                                  
  2234                                  load_16khz_stereo_16_bit:
  2235                                  	; 02/02/2025
  2236                                  	; 16/11/2023
  2237                                  	; 15/11/2023
  2238                                  	; 13/11/2023
  2239 00000FFF F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2240                                  					; last of the file?
  2241 00001006 7402                    	jz	short lff16s2_0		; no
  2242 00001008 F9                      	stc
  2243 00001009 C3                      	retn
  2244                                  
  2245                                  lff16s2_0:
  2246 0000100A BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2247                                          ;mov	edx, [loadsize]
  2248                                  
  2249                                  	; esi = buffer address
  2250                                  	;; edx = buffer size
  2251                                  
  2252                                  	; load file into memory
  2253                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000100F 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001015 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001017 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000101D B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001022 CD40                <1>  int 40h
  2254 00001024 72D4                    	jc	short lff16s2_7 ; error !
  2255                                  
  2256                                  	;mov	edi, audio_buffer
  2257                                  	; 29/05/2024
  2258 00001026 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2259                                  	
  2260 0000102C C1E802                  	shr	eax, 2
  2261 0000102F 7505                    	jnz	short lff16s2_8
  2262 00001031 E9ACFAFFFF              	jmp	lff16_eof
  2263                                  
  2264                                  lff16s2_8:
  2265 00001036 89C1                    	mov	ecx, eax  ; dword count
  2266                                  lff16s2_1:
  2267 00001038 66AD                    	lodsw
  2268 0000103A 66AB                    	stosw		; original sample (L)
  2269 0000103C 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2270 0000103F 66A3[A8210000]          	mov	[previous_val_l], ax
  2271 00001045 66AD                    	lodsw
  2272 00001047 66AB                    	stosw		; original sample (R)
  2273 00001049 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2274 0000104C 66A3[AA210000]          	mov	[previous_val_r], ax
  2275                                  	; 02/02/2025
  2276 00001052 668B06                  	mov	ax, [esi]
  2277 00001055 668B5602                	mov	dx, [esi+2]
  2278                                  	; 16/11/2023
  2279 00001059 49                      	dec	ecx
  2280 0000105A 7504                    	jnz	short lff16s2_2
  2281 0000105C 31D2                    	xor	edx, edx
  2282 0000105E 31C0                    	xor	eax, eax
  2283                                  lff16s2_2:
  2284 00001060 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format 
  2285                                  	;mov	[next_val_l], ax
  2286 00001063 89C5                    	mov	ebp, eax
  2287 00001065 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format 
  2288 00001068 668915[AE210000]        	mov	[next_val_r], dx
  2289 0000106F 660305[A8210000]        	add	ax, [previous_val_l]
  2290 00001076 66D1D8                  	rcr	ax, 1
  2291 00001079 89C2                    	mov	edx, eax ; this is temporary interpolation value (L)
  2292 0000107B 660305[A8210000]        	add	ax, [previous_val_l]
  2293 00001082 66D1D8                  	rcr	ax, 1
  2294 00001085 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2295 00001088 66AB                    	stosw		; this is 1st interpolated sample (L)
  2296 0000108A 66A1[AE210000]          	mov	ax, [next_val_r]
  2297 00001090 660305[AA210000]        	add	ax, [previous_val_r]
  2298 00001097 66D1D8                  	rcr	ax, 1
  2299 0000109A 89C3                    	mov	ebx, eax ; this is temporary interpolation value (R)
  2300 0000109C 660305[AA210000]        	add	ax, [previous_val_r]
  2301 000010A3 66D1D8                  	rcr	ax, 1
  2302 000010A6 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2303 000010A9 66AB                    	stosw		; this is 1st interpolated sample (R)
  2304                                  	;mov	ax, [next_val_l]
  2305 000010AB 89E8                    	mov	eax, ebp
  2306 000010AD 6601D0                  	add	ax, dx
  2307 000010B0 66D1D8                  	rcr	ax, 1
  2308 000010B3 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2309 000010B6 66AB                    	stosw		; this is 2nd interpolated sample (L)
  2310 000010B8 66A1[AE210000]          	mov	ax, [next_val_r]
  2311 000010BE 6601D8                  	add	ax, bx
  2312 000010C1 66D1D8                  	rcr	ax, 1
  2313 000010C4 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2314 000010C7 66AB                    	stosw 		; this is 2nd interpolated sample (R)
  2315                                  	
  2316                                  	; 16 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2317 000010C9 09C9                    	or	ecx, ecx
  2318 000010CB 0F8567FFFFFF            	jnz	lff16s2_1
  2319 000010D1 E9F4F9FFFF              	jmp	lff16s2_3
  2320                                  
  2321                                  ; .....................
  2322                                  
  2323                                  load_24khz_mono_8_bit:
  2324                                  	; 02/02/2025
  2325                                  	; 15/11/2023
  2326 000010D6 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2327                                  					; last of the file?
  2328 000010DD 7402                    	jz	short lff24m_0		; no
  2329 000010DF F9                      	stc
  2330 000010E0 C3                      	retn
  2331                                  
  2332                                  lff24m_0:
  2333 000010E1 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2334                                          ;mov	edx, [loadsize]
  2335                                  
  2336                                  	; esi = buffer address
  2337                                  	;; edx = buffer size
  2338                                  
  2339                                  	; load file into memory
  2340                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000010E6 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000010EC 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000010EE 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000010F4 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000010F9 CD40                <1>  int 40h
  2341 000010FB 723C                    	jc	short lff24m_7 ; error !
  2342                                  
  2343                                  	;mov	edi, audio_buffer
  2344                                  	; 29/05/2024
  2345 000010FD 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2346                                  	
  2347 00001103 21C0                    	and	eax, eax
  2348 00001105 7505                    	jnz	short lff24m_8
  2349 00001107 E9D6F9FFFF              	jmp	lff24_eof
  2350                                  
  2351                                  lff24m_8:
  2352 0000110C 89C1                    	mov	ecx, eax	; byte count
  2353                                  lff24m_1:
  2354 0000110E AC                      	lodsb
  2355                                  	;mov	[previous_val], al
  2356 0000110F 88C3                    	mov	bl, al
  2357 00001111 2C80                    	sub	al, 80h
  2358 00001113 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2359 00001117 66AB                    	stosw		; original sample (left channel)
  2360 00001119 66AB                    	stosw		; original sample (right channel)
  2361                                  	;xor	eax, eax
  2362                                  	; 02/02/2025
  2363 0000111B 8A06                    	mov	al, [esi]
  2364 0000111D 49                      	dec	ecx
  2365 0000111E 7502                    	jnz	short lff24m_2
  2366 00001120 B080                    	mov	al, 80h
  2367                                  lff24m_2:
  2368                                  	;;mov	[next_val], al
  2369                                  	;mov	bh, al
  2370                                  	;add	al, [previous_val]
  2371 00001122 00D8                    	add	al, bl
  2372 00001124 D0D8                    	rcr	al, 1
  2373 00001126 2C80                    	sub	al, 80h
  2374 00001128 66C1E008                	shl	ax, 8
  2375 0000112C 66AB                    	stosw		; this is interpolated sample (L)
  2376 0000112E 66AB                    	stosw		; this is interpolated sample (R)
  2377                                  	
  2378                                  	; 24 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2379 00001130 09C9                    	or	ecx, ecx
  2380 00001132 75DA                    	jnz	short lff24m_1
  2381 00001134 E991F9FFFF              	jmp	lff24_3
  2382                                  
  2383                                  lff24m_7:
  2384                                  lff24s_7:
  2385 00001139 E9ADF9FFFF              	jmp	lff24_5  ; error
  2386                                  
  2387                                  load_24khz_stereo_8_bit:
  2388                                  	; 02/02/2025
  2389                                  	; 15/11/2023
  2390 0000113E F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2391                                  					; last of the file?
  2392 00001145 7402                    	jz	short lff24s_0		; no
  2393 00001147 F9                      	stc
  2394 00001148 C3                      	retn
  2395                                  
  2396                                  lff24s_0:
  2397 00001149 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2398                                          ;mov	edx, [loadsize]
  2399                                  
  2400                                  	; esi = buffer address
  2401                                  	;; edx = buffer size
  2402                                  
  2403                                  	; load file into memory
  2404                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000114E 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001154 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001156 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000115C B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001161 CD40                <1>  int 40h
  2405 00001163 72D4                    	jc	short lff24s_7 ; error !
  2406                                  
  2407                                  	;mov	edi, audio_buffer
  2408                                  	; 29/05/2024
  2409 00001165 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2410                                  
  2411 0000116B D1E8                    	shr	eax, 1
  2412 0000116D 7505                    	jnz	short lff24s_8
  2413 0000116F E96EF9FFFF              	jmp	lff24_eof
  2414                                  
  2415                                  lff24s_8:
  2416 00001174 89C1                    	mov	ecx, eax  ; word count
  2417                                  lff24s_1:
  2418 00001176 AC                      	lodsb
  2419 00001177 A2[A8210000]            	mov	[previous_val_l], al
  2420 0000117C 2C80                    	sub	al, 80h
  2421 0000117E 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2422 00001182 66AB                    	stosw		; original sample (L)
  2423 00001184 AC                      	lodsb
  2424 00001185 A2[AA210000]            	mov	[previous_val_r], al
  2425 0000118A 2C80                    	sub	al, 80h
  2426 0000118C 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2427 00001190 66AB                    	stosw		; original sample (R)
  2428                                  
  2429                                  	;xor	eax, eax
  2430                                  	; 02/02/2025
  2431 00001192 668B06                  	mov	ax, [esi]
  2432 00001195 49                      	dec	ecx
  2433 00001196 7504                    	jnz	short lff24s_2
  2434                                  		; convert 8 bit sample to 16 bit sample
  2435 00001198 66B88080                	mov	ax, 8080h
  2436                                  lff24s_2:
  2437                                  	;;mov	[next_val_l], al
  2438                                  	;;mov	[next_val_r], ah
  2439                                  	;mov	bx, ax
  2440 0000119C 88E7                    	mov	bh, ah
  2441 0000119E 0205[A8210000]          	add	al, [previous_val_l]
  2442 000011A4 D0D8                    	rcr	al, 1
  2443                                  	;mov	dl, al
  2444 000011A6 2C80                    	sub	al, 80h
  2445 000011A8 66C1E008                	shl	ax, 8
  2446 000011AC 66AB                    	stosw		; this is interpolated sample (L)
  2447 000011AE 88F8                    	mov	al, bh	; [next_val_r]
  2448 000011B0 0205[AA210000]          	add	al, [previous_val_r]
  2449 000011B6 D0D8                    	rcr	al, 1
  2450                                  	;mov	dh, al
  2451 000011B8 2C80                    	sub	al, 80h
  2452 000011BA 66C1E008                	shl	ax, 8
  2453 000011BE 66AB                    	stosw		; this is interpolated sample (R)
  2454                                  		
  2455                                  	; 24 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2456 000011C0 09C9                    	or	ecx, ecx
  2457 000011C2 75B2                    	jnz	short lff24s_1
  2458 000011C4 E901F9FFFF              	jmp	lff24_3
  2459                                  
  2460                                  load_24khz_mono_16_bit:
  2461                                  	; 02/02/2025
  2462                                  	; 15/11/2023
  2463 000011C9 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2464                                  					; last of the file?
  2465 000011D0 7402                    	jz	short lff24m2_0		; no
  2466 000011D2 F9                      	stc
  2467 000011D3 C3                      	retn
  2468                                  
  2469                                  lff24m2_0:
  2470 000011D4 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2471                                          ;mov	edx, [loadsize]
  2472                                  
  2473                                  	; esi = buffer address
  2474                                  	;; edx = buffer size
  2475                                  
  2476                                  	; load file into memory
  2477                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000011D9 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000011DF 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000011E1 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000011E7 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000011EC CD40                <1>  int 40h
  2478 000011EE 723B                    	jc	short lff24m2_7 ; error !
  2479                                  
  2480                                  	;mov	edi, audio_buffer
  2481                                  	; 29/05/2024
  2482 000011F0 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2483                                  	
  2484 000011F6 D1E8                    	shr	eax, 1
  2485 000011F8 7505                    	jnz	short lff24m2_8
  2486 000011FA E9E3F8FFFF              	jmp	lff24_eof
  2487                                  
  2488                                  lff24m2_8:
  2489 000011FF 89C1                    	mov	ecx, eax  ; word count
  2490                                  lff24m2_1:
  2491 00001201 66AD                    	lodsw
  2492 00001203 66AB                    	stosw		; original sample (left channel)
  2493 00001205 66AB                    	stosw		; original sample (right channel)
  2494 00001207 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2495                                  	;mov	[previous_val], ax
  2496                                  	;mov	ebx, eax
  2497                                  	; 02/02/2025
  2498 0000120A 668B1E                  	mov	bx, [esi]
  2499 0000120D 49                      	dec	ecx
  2500 0000120E 7502                    	jnz	short lff24m2_2
  2501                                  	;xor	eax, eax
  2502 00001210 31DB                    	xor	ebx, ebx
  2503                                  lff24m2_2:
  2504                                  	; 02/02/2025
  2505 00001212 80C780                  	add	bh, 80h ; convert sound level 0 to 65535 format
  2506                                  	;add	ah, 80h
  2507                                  	;mov	ebp, eax	; [next_val]
  2508                                  	;add	ax, [previous_val]
  2509                                  	; ax = [previous_val]
  2510                                  	; bx = [next_val]
  2511 00001215 6601D8                  	add	ax, bx
  2512 00001218 66D1D8                  	rcr	ax, 1
  2513 0000121B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2514 0000121E 66AB                    	stosw		; this is interpolated sample (L)
  2515 00001220 66AB                    	stosw		; this is interpolated sample (R)
  2516                                  	; 24 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2517 00001222 09C9                    	or	ecx, ecx
  2518 00001224 75DB                    	jnz	short lff24m2_1
  2519 00001226 E99FF8FFFF              	jmp	lff24_3
  2520                                  
  2521                                  lff24m2_7:
  2522                                  lff24s2_7:
  2523 0000122B E9BBF8FFFF              	jmp	lff24_5  ; error
  2524                                  
  2525                                  load_24khz_stereo_16_bit:
  2526                                  	; 02/02/2025
  2527                                  	; 16/11/2023
  2528                                  	; 15/11/2023
  2529 00001230 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2530                                  					; last of the file?
  2531 00001237 7402                    	jz	short lff24s2_0		; no
  2532 00001239 F9                      	stc
  2533 0000123A C3                      	retn
  2534                                  
  2535                                  lff24s2_0:
  2536 0000123B BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2537                                          ;mov	edx, [loadsize]
  2538                                  
  2539                                  	; esi = buffer address
  2540                                  	;; edx = buffer size
  2541                                  
  2542                                  	; load file into memory
  2543                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001240 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001246 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001248 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000124E B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001253 CD40                <1>  int 40h
  2544 00001255 72D4                    	jc	short lff24s2_7 ; error !
  2545                                  
  2546                                  	;mov	edi, audio_buffer
  2547                                  	; 29/05/2024
  2548 00001257 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2549                                  	
  2550 0000125D C1E802                  	shr	eax, 2
  2551 00001260 7505                    	jnz	short lff24s2_8
  2552 00001262 E97BF8FFFF              	jmp	lff24_eof
  2553                                  
  2554                                  lff24s2_8:
  2555 00001267 89C1                    	mov	ecx, eax  ; dword count
  2556                                  lff24s2_1:
  2557 00001269 66AD                    	lodsw
  2558 0000126B 66AB                    	stosw		; original sample (L)
  2559 0000126D 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2560 00001270 66A3[A8210000]          	mov	[previous_val_l], ax
  2561 00001276 66AD                    	lodsw
  2562 00001278 66AB                    	stosw		; original sample (R)
  2563 0000127A 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2564                                  	;mov	[previous_val_r], ax
  2565 0000127D 89C3                    	mov	ebx, eax
  2566                                  	; 02/02/2025
  2567 0000127F 668B06                  	mov	ax, [esi]
  2568 00001282 668B5602                	mov	dx, [esi+2]
  2569                                  	; 16/11/2023
  2570 00001286 49                      	dec	ecx
  2571 00001287 7504                    	jnz	short lff24s2_2
  2572 00001289 31D2                    	xor	edx, edx
  2573 0000128B 31C0                    	xor	eax, eax
  2574                                  lff24s2_2:
  2575 0000128D 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2576                                  	;;mov	[next_val_l], ax
  2577                                  	;mov	ebp, eax
  2578 00001290 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format
  2579                                  	;mov	[next_val_r], dx
  2580 00001293 660305[A8210000]        	add	ax, [previous_val_l]
  2581 0000129A 66D1D8                  	rcr	ax, 1
  2582 0000129D 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2583 000012A0 66AB                    	stosw		; this is interpolated sample (L)
  2584                                  	;mov	ax, [next_val_r]
  2585 000012A2 89D0                    	mov	eax, edx
  2586                                  	;add	ax, [previous_val_r]
  2587 000012A4 6601D8                  	add	ax, bx
  2588 000012A7 66D1D8                  	rcr	ax, 1
  2589 000012AA 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2590 000012AD 66AB                    	stosw		; this is interpolated sample (R)
  2591                                  
  2592                                  	; 24 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2593 000012AF 09C9                    	or	ecx, ecx
  2594 000012B1 75B6                    	jnz	short lff24s2_1
  2595 000012B3 E912F8FFFF              	jmp	lff24_3
  2596                                  
  2597                                  ; .....................
  2598                                  
  2599                                  load_32khz_mono_8_bit:
  2600                                  	; 02/02/2025
  2601                                  	; 15/11/2023
  2602 000012B8 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2603                                  					; last of the file?
  2604 000012BF 7402                    	jz	short lff32m_0		; no
  2605 000012C1 F9                      	stc
  2606 000012C2 C3                      	retn
  2607                                  
  2608                                  lff32m_0:
  2609 000012C3 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2610                                          ;mov	edx, [loadsize]
  2611                                  
  2612                                  	; esi = buffer address
  2613                                  	;; edx = buffer size
  2614                                  
  2615                                  	; load file into memory
  2616                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000012C8 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000012CE 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000012D0 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000012D6 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000012DB CD40                <1>  int 40h
  2617 000012DD 7248                    	jc	short lff32m_7 ; error !
  2618                                  
  2619                                  	;mov	edi, audio_buffer
  2620                                  	; 29/05/2024
  2621 000012DF 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2622                                  
  2623 000012E5 21C0                    	and	eax, eax
  2624 000012E7 7505                    	jnz	short lff32m_8
  2625 000012E9 E9F4F7FFFF              	jmp	lff32_eof
  2626                                  
  2627                                  lff32m_8:
  2628 000012EE 89C1                    	mov	ecx, eax	; byte count
  2629                                  lff32m_1:
  2630 000012F0 AC                      	lodsb
  2631                                  	;mov	[previous_val], al
  2632 000012F1 88C3                    	mov	bl, al
  2633 000012F3 2C80                    	sub	al, 80h
  2634 000012F5 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2635 000012F9 66AB                    	stosw		; original sample (left channel)
  2636 000012FB 66AB                    	stosw		; original sample (right channel)
  2637                                  	;xor	eax, eax
  2638                                  	; 02/02/2025
  2639 000012FD 8A06                    	mov	al, [esi]
  2640 000012FF 49                      	dec	ecx
  2641 00001300 7502                    	jnz	short lff32m_2
  2642 00001302 B080                    	mov	al, 80h
  2643                                  lff32m_2:
  2644                                  	;;mov	[next_val], al
  2645                                  	;mov	bh, al
  2646                                  	;add	al, [previous_val]
  2647 00001304 00D8                    	add	al, bl
  2648 00001306 D0D8                    	rcr	al, 1
  2649 00001308 2C80                    	sub	al, 80h
  2650 0000130A 66C1E008                	shl	ax, 8
  2651 0000130E 66AB                    	stosw		; this is interpolated sample (L)
  2652 00001310 66AB                    	stosw		; this is interpolated sample (R)
  2653                                  	
  2654                                  	; different than 8-16-24 kHZ !
  2655                                  	; 'original-interpolated-original' trio samples
  2656 00001312 E30E                    	jecxz	lff32m_3
  2657                                  
  2658 00001314 AC                      	lodsb
  2659 00001315 2C80                    	sub	al, 80h
  2660 00001317 66C1E008                	shl	ax, 8
  2661 0000131B 66AB                    	stosw		; original sample (left channel)
  2662 0000131D 66AB                    	stosw		; original sample (right channel)
  2663                                  
  2664                                  	; 32 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2665 0000131F 49                      	dec	ecx
  2666 00001320 75CE                    	jnz	short lff32m_1
  2667                                  lff32m_3:
  2668 00001322 E9A3F7FFFF              	jmp	lff32_3
  2669                                  
  2670                                  lff32m_7:
  2671                                  lff32s_7:
  2672 00001327 E9BFF7FFFF              	jmp	lff32_5  ; error
  2673                                  
  2674                                  load_32khz_stereo_8_bit:
  2675                                  	; 02/02/2025
  2676                                  	; 15/11/2023
  2677 0000132C F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2678                                  					; last of the file?
  2679 00001333 7402                    	jz	short lff32s_0		; no
  2680 00001335 F9                      	stc
  2681 00001336 C3                      	retn
  2682                                  
  2683                                  lff32s_0:
  2684 00001337 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2685                                          ;mov	edx, [loadsize]
  2686                                  
  2687                                  	; esi = buffer address
  2688                                  	;; edx = buffer size
  2689                                  
  2690                                  	; load file into memory
  2691                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000133C 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001342 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001344 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000134A B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000134F CD40                <1>  int 40h
  2692 00001351 72D4                    	jc	short lff32s_7 ; error !
  2693                                  
  2694                                  	;mov	edi, audio_buffer
  2695                                  	; 29/05/2024
  2696 00001353 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2697                                  	
  2698 00001359 D1E8                    	shr	eax, 1
  2699 0000135B 7505                    	jnz	short lff32s_8
  2700 0000135D E980F7FFFF              	jmp	lff32_eof
  2701                                  
  2702                                  lff32s_8:
  2703 00001362 89C1                    	mov	ecx, eax  ; word count
  2704                                  lff32s_1:
  2705 00001364 AC                      	lodsb
  2706 00001365 A2[A8210000]            	mov	[previous_val_l], al
  2707 0000136A 2C80                    	sub	al, 80h
  2708 0000136C 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2709 00001370 66AB                    	stosw		; original sample (L)
  2710 00001372 AC                      	lodsb
  2711 00001373 A2[AA210000]            	mov	[previous_val_r], al
  2712 00001378 2C80                    	sub	al, 80h
  2713 0000137A 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  2714 0000137E 66AB                    	stosw		; original sample (R)
  2715                                  
  2716                                  	;xor	eax, eax
  2717                                  	; 02/02/2025
  2718 00001380 668B06                  	mov	ax, [esi]
  2719 00001383 49                      	dec	ecx
  2720 00001384 7504                    	jnz	short lff32s_2
  2721                                  		; convert 8 bit sample to 16 bit sample
  2722 00001386 66B88080                	mov	ax, 8080h
  2723                                  lff32s_2:
  2724                                  	;;mov	[next_val_l], al
  2725                                  	;;mov	[next_val_r], ah
  2726                                  	;mov	bx, ax
  2727 0000138A 88E7                    	mov	bh, ah
  2728 0000138C 0205[A8210000]          	add	al, [previous_val_l]
  2729 00001392 D0D8                    	rcr	al, 1
  2730                                  	;mov	dl, al
  2731 00001394 2C80                    	sub	al, 80h
  2732 00001396 66C1E008                	shl	ax, 8
  2733 0000139A 66AB                    	stosw		; this is interpolated sample (L)
  2734 0000139C 88F8                    	mov	al, bh	; [next_val_r]
  2735 0000139E 0205[AA210000]          	add	al, [previous_val_r]
  2736 000013A4 D0D8                    	rcr	al, 1
  2737                                  	;mov	dh, al
  2738 000013A6 2C80                    	sub	al, 80h
  2739 000013A8 66C1E008                	shl	ax, 8
  2740 000013AC 66AB                    	stosw		; this is interpolated sample (R)
  2741                                  
  2742                                  	; different than 8-16-24 kHZ !
  2743                                  	; 'original-interpolated-original' trio samples
  2744 000013AE E315                    	jecxz	lff32s_3
  2745                                  
  2746 000013B0 AC                      	lodsb
  2747 000013B1 2C80                    	sub	al, 80h
  2748 000013B3 66C1E008                	shl	ax, 8
  2749 000013B7 66AB                    	stosw		; original sample (left channel)
  2750                                  
  2751 000013B9 AC                      	lodsb
  2752 000013BA 2C80                    	sub	al, 80h
  2753 000013BC 66C1E008                	shl	ax, 8
  2754 000013C0 66AB                    	stosw		; original sample (right channel)
  2755                                  
  2756                                  	; 32 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2757 000013C2 49                      	dec	ecx
  2758 000013C3 759F                    	jnz	short lff32s_1
  2759                                  lff32s_3:
  2760 000013C5 E900F7FFFF              	jmp	lff32_3
  2761                                  
  2762                                  load_32khz_mono_16_bit:
  2763                                  	; 02/02/2025
  2764                                  	; 15/11/2023
  2765 000013CA F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2766                                  					; last of the file?
  2767 000013D1 7402                    	jz	short lff32m2_0		; no
  2768 000013D3 F9                      	stc
  2769 000013D4 C3                      	retn
  2770                                  
  2771                                  lff32m2_0:
  2772 000013D5 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2773                                          ;mov	edx, [loadsize]
  2774                                  
  2775                                  	; esi = buffer address
  2776                                  	;; edx = buffer size
  2777                                  
  2778                                  	; load file into memory
  2779                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000013DA 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000013E0 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000013E2 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000013E8 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000013ED CD40                <1>  int 40h
  2780 000013EF 7242                    	jc	short lff32m2_7 ; error !
  2781                                  
  2782                                  	;mov	edi, audio_buffer
  2783                                  	; 29/05/2024
  2784 000013F1 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2785                                  	
  2786 000013F7 D1E8                    	shr	eax, 1
  2787 000013F9 7505                    	jnz	short lff32m2_8
  2788 000013FB E9E2F6FFFF              	jmp	lff32_eof
  2789                                  
  2790                                  lff32m2_8:
  2791 00001400 89C1                    	mov	ecx, eax  ; word count
  2792                                  lff32m2_1:
  2793 00001402 66AD                    	lodsw
  2794 00001404 66AB                    	stosw		; original sample (left channel)
  2795 00001406 66AB                    	stosw		; original sample (right channel)
  2796 00001408 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  2797                                  	;mov	[previous_val], ax
  2798                                  	;mov	ebx, eax
  2799                                  	;xor	eax, eax
  2800                                  	; 02/02/2025
  2801                                  	;mov	ax, [esi]
  2802 0000140B 668B1E                  	mov	bx, [esi]
  2803 0000140E 49                      	dec	ecx
  2804 0000140F 7502                    	jnz	short lff32m2_2
  2805 00001411 31DB                    	xor	ebx, ebx
  2806                                  lff32m2_2:
  2807                                  	; 02/02/2025
  2808 00001413 80C780                  	add	bh, 80h ; convert sound level 0 to 65535 format
  2809                                  	;add	ah, 80h
  2810                                  	;mov	ebp, eax ; [next_val]
  2811                                  	;add	ax, [previous_val]
  2812                                  	; ax = [previous_val]
  2813                                  	; bx = [next_val]
  2814 00001416 6601D8                  	add	ax, bx
  2815 00001419 66D1D8                  	rcr	ax, 1
  2816 0000141C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2817 0000141F 66AB                    	stosw		; this is interpolated sample (L)
  2818 00001421 66AB                    	stosw		; this is interpolated sample (R)
  2819                                  
  2820                                  	; different than 8-16-24 kHZ !
  2821                                  	; 'original-interpolated-original' trio samples
  2822 00001423 E309                    	jecxz	lff32m2_3
  2823                                  
  2824 00001425 66AD                    	lodsw
  2825 00001427 66AB                    	stosw		; original sample (left channel)
  2826 00001429 66AB                    	stosw		; original sample (right channel)
  2827                                  
  2828                                  	; 32 kHZ mono to 48 kHZ stereo conversion of the sample is OK
  2829 0000142B 49                      	dec	ecx
  2830 0000142C 75D4                    	jnz	short lff32m2_1
  2831                                  lff32m2_3:
  2832 0000142E E997F6FFFF              	jmp	lff32_3
  2833                                  
  2834                                  lff32m2_7:
  2835                                  lff32s2_7:
  2836 00001433 E9B3F6FFFF              	jmp	lff32_5  ; error
  2837                                  
  2838                                  load_32khz_stereo_16_bit:
  2839                                  	; 02/02/2025
  2840                                  	; 16/11/2023
  2841                                  	; 15/11/2023
  2842 00001438 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2843                                  					; last of the file?
  2844 0000143F 7402                    	jz	short lff32s2_0		; no
  2845 00001441 F9                      	stc
  2846 00001442 C3                      	retn
  2847                                  
  2848                                  lff32s2_0:
  2849 00001443 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2850                                          ;mov	edx, [loadsize]
  2851                                  
  2852                                  	; esi = buffer address
  2853                                  	;; edx = buffer size
  2854                                  
  2855                                  	; load file into memory
  2856                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001448 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000144E 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001450 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001456 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000145B CD40                <1>  int 40h
  2857 0000145D 72D4                    	jc	short lff32s2_7 ; error !
  2858                                  
  2859                                  	;mov	edi, audio_buffer
  2860                                  	; 29/05/2024
  2861 0000145F 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2862                                  	
  2863 00001465 C1E802                  	shr	eax, 2
  2864 00001468 7505                    	jnz	short lff32s2_8
  2865 0000146A E973F6FFFF              	jmp	lff32_eof
  2866                                  
  2867                                  lff32s2_8:
  2868 0000146F 89C1                    	mov	ecx, eax ; dword count
  2869                                  lff32s2_1:
  2870 00001471 66AD                    	lodsw
  2871 00001473 66AB                    	stosw		; original sample (L)
  2872 00001475 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2873 00001478 66A3[A8210000]          	mov	[previous_val_l], ax
  2874 0000147E 66AD                    	lodsw
  2875 00001480 66AB                    	stosw		; original sample (R)
  2876 00001482 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2877                                  	;mov	[previous_val_r], ax
  2878 00001485 89C3                    	mov	ebx, eax
  2879                                  	; 02/02/2025
  2880 00001487 668B06                  	mov	ax, [esi]
  2881 0000148A 668B5602                	mov	dx, [esi+2]
  2882                                  	; 16/11/2023
  2883 0000148E 49                      	dec	ecx
  2884 0000148F 7504                    	jnz	short lff32s2_2
  2885 00001491 31D2                    	xor	edx, edx
  2886 00001493 31C0                    	xor	eax, eax
  2887                                  lff32s2_2:
  2888 00001495 80C480                  	add	ah, 80h	; convert sound level 0 to 65535 format
  2889                                  	;;mov	[next_val_l], ax
  2890                                  	;mov	ebp, eax
  2891 00001498 80C680                  	add	dh, 80h	; convert sound level 0 to 65535 format
  2892                                  	;mov	[next_val_r], dx
  2893 0000149B 660305[A8210000]        	add	ax, [previous_val_l]
  2894 000014A2 66D1D8                  	rcr	ax, 1
  2895 000014A5 80EC80                  	sub	ah, 80h ; -32768 to +32767 format again
  2896 000014A8 66AB                    	stosw		; this is interpolated sample (L)
  2897                                  	;mov	ax, [next_val_r]
  2898 000014AA 89D0                    	mov	eax, edx
  2899                                  	;add	ax, [previous_val_r]
  2900 000014AC 6601D8                  	add	ax, bx
  2901 000014AF 66D1D8                  	rcr	ax, 1
  2902 000014B2 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  2903 000014B5 66AB                    	stosw		; this is interpolated sample (R)
  2904                                  
  2905                                  	; different than 8-16-24 kHZ !
  2906                                  	; 'original-interpolated-original' trio samples 
  2907 000014B7 E30B                    	jecxz	lff32s2_3
  2908                                  
  2909 000014B9 66AD                    	lodsw
  2910 000014BB 66AB                    	stosw	; original sample (L)
  2911 000014BD 66AD                    	lodsw
  2912 000014BF 66AB                    	stosw	; original sample (R)
  2913                                  
  2914                                  	; 32 kHZ stereo to 48 kHZ stereo conversion of the sample is OK
  2915 000014C1 49                      	dec	ecx
  2916 000014C2 75AD                    	jnz	short lff32s2_1
  2917                                  lff32s2_3:
  2918 000014C4 E901F6FFFF              	jmp	lff32_3
  2919                                  
  2920                                  ; .....................
  2921                                  
  2922                                  load_22khz_mono_8_bit:
  2923                                  	; 02/02/2025
  2924                                  	; 16/11/2023
  2925 000014C9 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  2926                                  					; last of the file?
  2927 000014D0 7402                    	jz	short lff22m_0		; no
  2928 000014D2 F9                      	stc
  2929 000014D3 C3                      	retn
  2930                                  
  2931                                  lff22m_0:
  2932 000014D4 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  2933                                          ;mov	edx, [loadsize]
  2934                                  
  2935                                  	; esi = buffer address
  2936                                  	;; edx = buffer size
  2937                                  
  2938                                  	; load file into memory
  2939                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000014D9 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000014DF 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000014E1 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000014E7 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000014EC CD40                <1>  int 40h
  2940 000014EE 725E                    	jc	short lff22m_7 ; error !
  2941                                  
  2942                                  	;mov	edi, audio_buffer
  2943                                  	; 29/05/2024
  2944 000014F0 8B3D[462A0000]          	mov	edi, [audio_buffer]
  2945                                  	
  2946 000014F6 21C0                    	and	eax, eax
  2947 000014F8 7505                    	jnz	short lff22m_8
  2948 000014FA E9E3F5FFFF              	jmp	lff22_eof
  2949                                  
  2950                                  lff22m_8:
  2951 000014FF 89C1                    	mov	ecx, eax	; byte count
  2952                                  lff22m_9:
  2953 00001501 BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  2954 00001506 C605[B0210000]03        	mov	byte [faz], 3  ; 3 steps/phases
  2955                                  lff22m_1:
  2956                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  2957 0000150D AC                      	lodsb
  2958                                  	; 02/02/2025
  2959 0000150E 8A16                    	mov	dl, [esi]
  2960 00001510 49                      	dec	ecx
  2961 00001511 7502                    	jnz	short lff22m_2_1
  2962 00001513 B280                    	mov	dl, 80h
  2963                                  lff22m_2_1:
  2964                                  	; al = [previous_val]
  2965                                  	; dl = [next_val]
  2966 00001515 E844070000              	call	interpolating_3_8bit_mono ; 1 of 17
  2967 0000151A E32D                    	jecxz	lff22m_3
  2968                                  lff22m_2_2:
  2969 0000151C AC                      	lodsb
  2970                                  	; 02/02/2025
  2971 0000151D 8A16                    	mov	dl, [esi]
  2972 0000151F 49                      	dec	ecx
  2973 00001520 7502                    	jnz	short lff22m_2_3
  2974 00001522 B280                    	mov	dl, 80h
  2975                                  lff22m_2_3:
  2976 00001524 E8BF070000               	call	interpolating_2_8bit_mono ; 2 of 17 .. 6 of 17
  2977 00001529 E31E                    	jecxz	lff22m_3
  2978 0000152B 4D                      	dec	ebp
  2979 0000152C 75EE                    	jnz	short lff22m_2_2
  2980                                  
  2981 0000152E A0[B0210000]            	mov	al, [faz]
  2982 00001533 FEC8                    	dec	al
  2983 00001535 74CA                    	jz	short lff22m_9
  2984 00001537 FE0D[B0210000]          	dec	byte [faz]
  2985 0000153D BD04000000              	mov	ebp, 4
  2986 00001542 FEC8                    	dec	al
  2987 00001544 75C7                    	jnz	short lff22m_1 ; 3:2:2:2:2 ; 7-11 of 17
  2988 00001546 45                      	inc	ebp ; 5
  2989 00001547 EBC4                    	jmp	short lff22m_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  2990                                  
  2991                                  lff22m_3:
  2992                                  lff22s_3:
  2993 00001549 E97CF5FFFF              	jmp	lff22_3	; padfill
  2994                                  		; (put zeros in the remain words of the buffer)
  2995                                  lff22m_7:
  2996                                  lff22s_7:
  2997 0000154E E998F5FFFF              	jmp	lff22_5  ; error
  2998                                  
  2999                                  load_22khz_stereo_8_bit:
  3000                                  	; 02/02/2025
  3001                                  	; 16/11/2023
  3002 00001553 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3003                                  					; last of the file?
  3004 0000155A 7402                    	jz	short lff22s_0		; no
  3005 0000155C F9                      	stc
  3006 0000155D C3                      	retn
  3007                                  
  3008                                  lff22s_0:
  3009 0000155E BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3010                                          ;mov	edx, [loadsize]
  3011                                  
  3012                                  	; esi = buffer address
  3013                                  	;; edx = buffer size
  3014                                  
  3015                                  	; load file into memory
  3016                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001563 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001569 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 0000156B 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001571 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001576 CD40                <1>  int 40h
  3017 00001578 72D4                    	jc	short lff22s_7 ; error !
  3018                                  
  3019                                  	;mov	edi, audio_buffer
  3020                                  	; 29/05/2024
  3021 0000157A 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3022                                  
  3023 00001580 D1E8                    	shr	eax, 1
  3024 00001582 7505                    	jnz	short lff22s_8
  3025 00001584 E959F5FFFF              	jmp	lff22_eof
  3026                                  
  3027                                  lff22s_8:
  3028 00001589 89C1                    	mov	ecx, eax	; word count
  3029                                  lff22s_9:
  3030 0000158B BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  3031 00001590 C605[B0210000]03        	mov	byte [faz], 3  ; 3 steps/phase
  3032                                  lff22s_1:
  3033                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  3034 00001597 66AD                    	lodsw
  3035                                  	; 02/02/2025
  3036 00001599 668B16                  	mov	dx, [esi]
  3037 0000159C 49                      	dec	ecx
  3038 0000159D 7504                    	jnz	short lff22s_2_1
  3039 0000159F 66BA8080                	mov	dx, 8080h
  3040                                  lff22s_2_1:
  3041                                  	; al = [previous_val_l]
  3042                                  	; ah = [previous_val_r]
  3043                                  	; dl = [next_val_l]
  3044                                  	; dh = [next_val_r]
  3045 000015A3 E8E9060000              	call	interpolating_3_8bit_stereo ; 1 of 17
  3046 000015A8 E39F                    	jecxz	lff22s_3
  3047                                  lff22s_2_2:
  3048 000015AA 66AD                    	lodsw
  3049                                  	; 02/02/2025
  3050 000015AC 668B16                  	mov	dx, [esi]
  3051 000015AF 49                      	dec	ecx
  3052 000015B0 7504                    	jnz	short lff22s_2_3
  3053 000015B2 66BA8080                	mov	dx, 8080h
  3054                                  lff22s_2_3:
  3055 000015B6 E84A070000               	call	interpolating_2_8bit_stereo ; 2 of 17 .. 6 of 17
  3056 000015BB E38C                    	jecxz	lff22s_3
  3057 000015BD 4D                      	dec	ebp
  3058 000015BE 75EA                    	jnz	short lff22s_2_2
  3059                                  
  3060 000015C0 A0[B0210000]            	mov	al, [faz]
  3061 000015C5 FEC8                    	dec	al
  3062 000015C7 74C2                    	jz	short lff22s_9
  3063 000015C9 FE0D[B0210000]          	dec	byte [faz]
  3064 000015CF BD04000000              	mov	ebp, 4
  3065 000015D4 FEC8                    	dec	al
  3066 000015D6 75BF                    	jnz	short lff22s_1 ; 3:2:2:2:2 ; 7-11 of 17
  3067 000015D8 45                      	inc	ebp ; 5
  3068 000015D9 EBBC                    	jmp	short lff22s_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  3069                                  
  3070                                  load_22khz_mono_16_bit:
  3071                                  	; 02/02/2025
  3072                                  	; 16/11/2023
  3073 000015DB F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3074                                  					; last of the file?
  3075 000015E2 7402                    	jz	short lff22m2_0		; no
  3076 000015E4 F9                      	stc
  3077 000015E5 C3                      	retn
  3078                                  
  3079                                  lff22m2_0:
  3080 000015E6 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3081                                          ;mov	edx, [loadsize]
  3082                                  
  3083                                  	; esi = buffer address
  3084                                  	;; edx = buffer size
  3085                                  
  3086                                  	; load file into memory
  3087                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000015EB 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000015F1 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000015F3 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000015F9 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000015FE CD40                <1>  int 40h
  3088 00001600 7262                    	jc	short lff22m2_7 ; error !
  3089                                  
  3090                                  	;mov	edi, audio_buffer
  3091                                  	; 29/05/2024
  3092 00001602 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3093                                  	
  3094 00001608 D1E8                    	shr	eax, 1
  3095 0000160A 7505                    	jnz	short lff22m2_8
  3096 0000160C E9D1F4FFFF              	jmp	lff22_eof
  3097                                  
  3098                                  lff22m2_8:
  3099 00001611 89C1                    	mov	ecx, eax	; word count
  3100                                  lff22m2_9:
  3101 00001613 BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  3102 00001618 C605[B0210000]03        	mov	byte [faz], 3  ; 3 steps/phases
  3103                                  lff22m2_1:
  3104                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  3105 0000161F 66AD                    	lodsw
  3106                                  	; 02/02/2025
  3107 00001621 668B16                  	mov	dx, [esi]
  3108 00001624 49                      	dec	ecx
  3109 00001625 7502                    	jnz	short lff22m2_2_1
  3110 00001627 31D2                    	xor	edx, edx
  3111                                  lff22m2_2_1:	
  3112                                  	; ax = [previous_val]
  3113                                  	; dx = [next_val]
  3114 00001629 E808070000              	call	interpolating_3_16bit_mono ; 1 of 17
  3115 0000162E E32F                    	jecxz	lff22m2_3
  3116                                  lff22m2_2_2:
  3117 00001630 66AD                    	lodsw
  3118                                  	; 02/02/2025
  3119 00001632 668B16                  	mov	dx, [esi]
  3120 00001635 49                      	dec	ecx
  3121 00001636 7502                    	jnz	short lff22m2_2_3
  3122 00001638 31D2                    	xor	edx, edx
  3123                                  lff22m2_2_3:
  3124 0000163A E88A070000               	call	interpolating_2_16bit_mono ; 2 of 17 .. 6 of 17
  3125 0000163F E31E                    	jecxz	lff22m2_3
  3126 00001641 4D                      	dec	ebp
  3127 00001642 75EC                    	jnz	short lff22m2_2_2
  3128                                  
  3129 00001644 A0[B0210000]            	mov	al, [faz]
  3130 00001649 FEC8                    	dec	al
  3131 0000164B 74C6                    	jz	short lff22m2_9
  3132 0000164D FE0D[B0210000]          	dec	byte [faz]
  3133 00001653 BD04000000              	mov	ebp, 4
  3134 00001658 FEC8                    	dec	al
  3135 0000165A 75C3                    	jnz	short lff22m2_1 ; 3:2:2:2:2 ; 7-11 of 17
  3136 0000165C 45                      	inc	ebp ; 5
  3137 0000165D EBC0                    	jmp	short lff22m2_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  3138                                  
  3139                                  lff22m2_3:
  3140                                  lff22s2_3:
  3141 0000165F E966F4FFFF              	jmp	lff22_3	; padfill
  3142                                  		; (put zeros in the remain words of the buffer)
  3143                                  lff22m2_7:
  3144                                  lff22s2_7:
  3145 00001664 E982F4FFFF              	jmp	lff22_5  ; error
  3146                                  
  3147                                  load_22khz_stereo_16_bit:
  3148                                  	; 16/11/2023
  3149 00001669 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3150                                  					; last of the file?
  3151 00001670 7402                    	jz	short lff22s2_0		; no
  3152 00001672 F9                      	stc
  3153 00001673 C3                      	retn
  3154                                  
  3155                                  lff22s2_0:
  3156 00001674 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3157                                          ;mov	edx, [loadsize]
  3158                                  
  3159                                  	; esi = buffer address
  3160                                  	;; edx = buffer size
  3161                                  
  3162                                  	; load file into memory
  3163                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001679 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000167F 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001681 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001687 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000168C CD40                <1>  int 40h
  3164 0000168E 72D4                    	jc	short lff22s2_7 ; error !
  3165                                  
  3166                                  	;mov	edi, audio_buffer
  3167                                  	; 29/05/2024
  3168 00001690 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3169                                  	
  3170 00001696 C1E802                  	shr	eax, 2	; dword (left chan word + right chan word)
  3171 00001699 7505                    	jnz	short lff22s2_8
  3172 0000169B E942F4FFFF              	jmp	lff22_eof
  3173                                  
  3174                                  lff22s2_8:
  3175 000016A0 89C1                    	mov	ecx, eax	; dword count
  3176                                  lff22s2_9:
  3177 000016A2 BD05000000              	mov	ebp, 5 ; interpolation (one step) loop count
  3178 000016A7 C605[B0210000]03        	mov	byte [faz], 3  ; 3 steps/phase
  3179                                  lff22s2_1:
  3180                                  	; 3:2:2:2:2:2::3:2:2:2:2::3:2:2:2:2:2  ; 37/17
  3181 000016AE 66AD                    	lodsw
  3182 000016B0 89C3                    	mov	ebx, eax
  3183 000016B2 66AD                    	lodsw
  3184 000016B4 8B16                    	mov	edx, [esi]
  3185 000016B6 668915[AC210000]        	mov	[next_val_l], dx
  3186                                  	; 26/11/2023
  3187 000016BD C1EA10                  	shr	edx, 16
  3188 000016C0 49                      	dec	ecx
  3189 000016C1 7509                    	jnz	short lff22s2_2_1
  3190 000016C3 31D2                    	xor	edx, edx ; 0
  3191 000016C5 668915[AC210000]        	mov	[next_val_l], dx
  3192                                  lff22s2_2_1:
  3193                                  	; bx = [previous_val_l]
  3194                                  	; ax = [previous_val_r]
  3195                                  	; [next_val_l]
  3196                                  	; dx = [next_val_r]
  3197 000016CC E895060000              	call	interpolating_3_16bit_stereo ; 1 of 17 
  3198 000016D1 E38C                    	jecxz	lff22s2_3
  3199                                  lff22s2_2_2:
  3200 000016D3 66AD                    	lodsw
  3201 000016D5 89C3                    	mov	ebx, eax
  3202 000016D7 66AD                    	lodsw
  3203 000016D9 8B16                    	mov	edx, [esi]
  3204 000016DB 668915[AC210000]        	mov	[next_val_l], dx
  3205                                  	; 26/11/2023
  3206 000016E2 C1EA10                  	shr	edx, 16
  3207 000016E5 49                      	dec	ecx
  3208 000016E6 7509                    	jnz	short lff22s2_2_3
  3209 000016E8 31D2                    	xor	edx, edx ; 0
  3210 000016EA 668915[AC210000]        	mov	[next_val_l], dx
  3211                                  lff22s2_2_3:
  3212 000016F1 E8EB060000               	call	interpolating_2_16bit_stereo ; 2 of 17 .. 6 of 17
  3213 000016F6 E31E                    	jecxz	lff22s2_2_4
  3214                                  
  3215 000016F8 4D                      	dec	ebp
  3216 000016F9 75D8                    	jnz	short lff22s2_2_2
  3217                                  
  3218 000016FB A0[B0210000]            	mov	al, [faz]
  3219 00001700 FEC8                    	dec	al
  3220 00001702 749E                    	jz	short lff22s2_9
  3221 00001704 FE0D[B0210000]          	dec	byte [faz]
  3222 0000170A BD04000000              	mov	ebp, 4
  3223 0000170F FEC8                    	dec	al
  3224 00001711 759B                    	jnz	short lff22s2_1 ; 3:2:2:2:2 ; 7-11 of 17
  3225 00001713 45                      	inc	ebp ; 5
  3226 00001714 EB98                    	jmp	short lff22s2_1 ; 3:2:2:2:2:2 ; 12-17 of 17
  3227                                  
  3228                                  lff22s2_2_4:
  3229                                  	; 26/11/2023
  3230 00001716 E9AFF3FFFF              	jmp	lff22_3	; padfill
  3231                                  
  3232                                  ; .....................
  3233                                  
  3234                                  load_11khz_mono_8_bit:
  3235                                  	; 02/02/2025
  3236                                  	; 18/11/2023
  3237 0000171B F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3238                                  					; last of the file?
  3239 00001722 7402                    	jz	short lff11m_0		; no
  3240 00001724 F9                      	stc
  3241 00001725 C3                      	retn
  3242                                  
  3243                                  lff11m_0:
  3244 00001726 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3245                                          ;mov	edx, [loadsize]
  3246                                  
  3247                                  	; esi = buffer address
  3248                                  	;; edx = buffer size
  3249                                  
  3250                                  	; load file into memory
  3251                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000172B 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001731 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001733 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001739 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 0000173E CD40                <1>  int 40h
  3252 00001740 7248                    	jc	short lff11m_7 ; error !
  3253                                  
  3254                                  	;mov	edi, audio_buffer
  3255                                  	; 29/05/2024
  3256 00001742 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3257                                  	
  3258 00001748 21C0                    	and	eax, eax
  3259 0000174A 7505                    	jnz	short lff11m_8
  3260 0000174C E991F3FFFF              	jmp	lff11_eof
  3261                                  
  3262                                  lff11m_8:
  3263 00001751 89C1                    	mov	ecx, eax	; byte count
  3264                                  lff11m_9:
  3265 00001753 BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3266                                  lff11m_1:
  3267                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3268 00001758 AC                      	lodsb
  3269                                  	; 02/02/2025
  3270 00001759 8A16                    	mov	dl, [esi]
  3271 0000175B 49                      	dec	ecx
  3272 0000175C 7502                    	jnz	short lff11m_2_1
  3273 0000175E B280                    	mov	dl, 80h
  3274                                  lff11m_2_1:	
  3275                                  	; al = [previous_val]
  3276                                  	; dl = [next_val]
  3277 00001760 E8AB060000              	call	interpolating_5_8bit_mono
  3278 00001765 E328                    	jecxz	lff11m_3
  3279                                  lff11m_2_2:
  3280 00001767 AC                      	lodsb
  3281                                  	; 02/02/2025
  3282 00001768 8A16                    	mov	dl, [esi]
  3283 0000176A 49                      	dec	ecx
  3284 0000176B 7502                    	jnz	short lff11m_2_3
  3285 0000176D B280                    	mov	dl, 80h
  3286                                  lff11m_2_3:
  3287 0000176F E8A8070000               	call	interpolating_4_8bit_mono
  3288 00001774 E319                    	jecxz	lff11m_3
  3289                                  
  3290 00001776 4D                      	dec	ebp
  3291 00001777 74DA                    	jz	short lff11m_9
  3292                                  
  3293 00001779 AC                      	lodsb
  3294                                  	; 02/02/2025
  3295 0000177A 8A16                    	mov	dl, [esi]
  3296 0000177C 49                      	dec	ecx
  3297 0000177D 7502                    	jnz	short lff11m_2_4
  3298 0000177F B280                    	mov	dl, 80h
  3299                                  lff11m_2_4:
  3300 00001781 E896070000              	call	interpolating_4_8bit_mono
  3301 00001786 E307                    	jecxz	lff11m_3
  3302 00001788 EBCE                    	jmp	short lff11m_1
  3303                                  
  3304                                  lff11m_7:
  3305                                  lff11s_7:
  3306 0000178A E95CF3FFFF              	jmp	lff11_5  ; error
  3307                                  
  3308                                  lff11m_3:
  3309                                  lff11s_3:
  3310 0000178F E936F3FFFF              	jmp	lff11_3	; padfill
  3311                                  		; (put zeros in the remain words of the buffer)
  3312                                  
  3313                                  load_11khz_stereo_8_bit:
  3314                                  	; 02/02/2025
  3315                                  	; 18/11/2023
  3316 00001794 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3317                                  					; last of the file?
  3318 0000179B 7402                    	jz	short lff11s_0		; no
  3319 0000179D F9                      	stc
  3320 0000179E C3                      	retn
  3321                                  
  3322                                  lff11s_0:
  3323 0000179F BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3324                                          ;mov	edx, [loadsize]
  3325                                  
  3326                                  	; esi = buffer address
  3327                                  	;; edx = buffer size
  3328                                  
  3329                                  	; load file into memory
  3330                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000017A4 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000017AA 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000017AC 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000017B2 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000017B7 CD40                <1>  int 40h
  3331 000017B9 72CF                    	jc	short lff11s_7 ; error !
  3332                                  
  3333                                  	;mov	edi, audio_buffer
  3334                                  	; 29/05/2024
  3335 000017BB 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3336                                  
  3337 000017C1 D1E8                    	shr	eax, 1
  3338 000017C3 7505                    	jnz	short lff11s_8
  3339 000017C5 E918F3FFFF              	jmp	lff11_eof
  3340                                  
  3341                                  lff11s_8:
  3342 000017CA 89C1                    	mov	ecx, eax	; word count
  3343                                  lff11s_9:
  3344 000017CC BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3345                                  lff11s_1:
  3346                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3347 000017D1 66AD                    	lodsw
  3348                                  	; 02/02/2025
  3349 000017D3 668B16                  	mov	dx, [esi]
  3350 000017D6 49                      	dec	ecx
  3351 000017D7 7504                    	jnz	short lff11s_2_1
  3352 000017D9 66BA8080                	mov	dx, 8080h
  3353                                  lff11s_2_1:
  3354                                  	; al = [previous_val_l]
  3355                                  	; ah = [previous_val_r]
  3356                                  	; dl = [next_val_l]
  3357                                  	; dh = [next_val_r]
  3358 000017DD E88D060000              	call	interpolating_5_8bit_stereo
  3359 000017E2 E3AB                    	jecxz	lff11s_3
  3360                                  lff11s_2_2:
  3361 000017E4 66AD                    	lodsw
  3362                                  	; 02/02/2025
  3363 000017E6 668B16                  	mov	dx, [esi]
  3364 000017E9 49                      	dec	ecx
  3365 000017EA 7504                    	jnz	short lff11s_2_3
  3366 000017EC 66BA8080                	mov	dx, 8080h
  3367                                  lff11s_2_3:
  3368 000017F0 E866070000               	call	interpolating_4_8bit_stereo
  3369 000017F5 E398                    	jecxz	lff11s_3
  3370                                  	
  3371 000017F7 4D                      	dec	ebp
  3372 000017F8 74D2                    	jz	short lff11s_9
  3373                                  
  3374 000017FA 66AD                    	lodsw
  3375                                  	; 02/02/2025
  3376 000017FC 668B16                  	mov	dx, [esi]
  3377 000017FF 49                      	dec	ecx
  3378 00001800 7504                    	jnz	short lff11s_2_4
  3379 00001802 66BA8080                	mov	dx, 8080h
  3380                                  lff11s_2_4:
  3381 00001806 E850070000              	call	interpolating_4_8bit_stereo
  3382 0000180B E382                    	jecxz	lff11s_3
  3383 0000180D EBC2                    	jmp	short lff11s_1
  3384                                  
  3385                                  load_11khz_mono_16_bit:
  3386                                  	; 02/02/2025
  3387                                  	; 18/11/2023
  3388 0000180F F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3389                                  					; last of the file?
  3390 00001816 7402                    	jz	short lff11m2_0		; no
  3391 00001818 F9                      	stc
  3392 00001819 C3                      	retn
  3393                                  
  3394                                  lff11m2_0:
  3395 0000181A BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3396                                          ;mov	edx, [loadsize]
  3397                                  
  3398                                  	; esi = buffer address
  3399                                  	;; edx = buffer size
  3400                                  
  3401                                  	; load file into memory
  3402                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000181F 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001825 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001827 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000182D B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001832 CD40                <1>  int 40h
  3403 00001834 724E                    	jc	short lff11m2_7 ; error !
  3404                                  
  3405                                  	;mov	edi, audio_buffer
  3406                                  	; 29/05/2024
  3407 00001836 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3408                                  	
  3409 0000183C D1E8                    	shr	eax, 1
  3410 0000183E 7505                    	jnz	short lff11m2_8
  3411 00001840 E99DF2FFFF              	jmp	lff11_eof
  3412                                  
  3413                                  lff11m2_8:
  3414 00001845 89C1                    	mov	ecx, eax	; word count
  3415                                  lff11m2_9:
  3416 00001847 BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3417                                  lff11m2_1:
  3418                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3419 0000184C 66AD                    	lodsw
  3420                                  	; 02/02/2025
  3421 0000184E 668B16                  	mov	dx, [esi]
  3422 00001851 49                      	dec	ecx
  3423 00001852 7502                    	jnz	short lff11m2_2_1
  3424 00001854 31D2                    	xor	edx, edx
  3425                                  lff11m2_2_1:	
  3426                                  	; ax = [previous_val]
  3427                                  	; dx = [next_val]
  3428 00001856 E86D070000              	call	interpolating_5_16bit_mono
  3429 0000185B E363                    	jecxz	lff11m2_3
  3430                                  lff11m2_2_2:
  3431 0000185D 66AD                    	lodsw
  3432                                  	; 02/02/2025
  3433 0000185F 668B16                  	mov	dx, [esi]
  3434 00001862 49                      	dec	ecx
  3435 00001863 7502                    	jnz	short lff11m2_2_3
  3436 00001865 31D2                    	xor	edx, edx
  3437                                  lff11m2_2_3:
  3438 00001867 E886080000               	call	interpolating_4_16bit_mono
  3439 0000186C E352                    	jecxz	lff11m2_3
  3440                                  
  3441 0000186E 4D                      	dec	ebp
  3442 0000186F 74D6                    	jz	short lff11m2_9
  3443                                  
  3444 00001871 66AD                    	lodsw
  3445                                  	; 02/02/2025
  3446 00001873 668B16                  	mov	dx, [esi]
  3447 00001876 49                      	dec	ecx
  3448 00001877 7502                    	jnz	short lff11m2_2_4
  3449 00001879 31D2                    	xor	edx, edx
  3450                                  lff11m2_2_4:
  3451 0000187B E872080000               	call	interpolating_4_16bit_mono
  3452 00001880 E33E                    	jecxz	lff11m2_3
  3453 00001882 EBC8                    	jmp	short lff11m2_1
  3454                                  
  3455                                  lff11m2_7:
  3456                                  lff11s2_7:
  3457 00001884 E962F2FFFF              	jmp	lff11_5  ; error
  3458                                  
  3459                                  load_11khz_stereo_16_bit:
  3460                                  	; 17/01/2025
  3461                                  	; 18/11/2023
  3462 00001889 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3463                                  					; last of the file?
  3464 00001890 7402                    	jz	short lff11s2_0		; no
  3465 00001892 F9                      	stc
  3466 00001893 C3                      	retn
  3467                                  
  3468                                  lff11s2_0:
  3469 00001894 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3470                                          ;mov	edx, [loadsize]
  3471                                  
  3472                                  	; esi = buffer address
  3473                                  	;; edx = buffer size
  3474                                  
  3475                                  	; load file into memory
  3476                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001899 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 0000189F 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000018A1 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000018A7 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000018AC CD40                <1>  int 40h
  3477 000018AE 72D4                    	jc	short lff11s2_7 ; error !
  3478                                  
  3479                                  	;mov	edi, audio_buffer
  3480                                  	; 29/05/2024
  3481 000018B0 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3482                                  	
  3483 000018B6 C1E802                  	shr	eax, 2	; dword (left chan word + right chan word)
  3484 000018B9 750A                    	jnz	short lff11s2_8
  3485 000018BB E922F2FFFF              	jmp	lff11_eof
  3486                                  
  3487                                  lff11m2_3:
  3488                                  lff11s2_3:
  3489 000018C0 E905F2FFFF              	jmp	lff11_3	; padfill
  3490                                  		; (put zeros in the remain words of the buffer)
  3491                                  
  3492                                  lff11s2_8:
  3493 000018C5 89C1                    	mov	ecx, eax	; dword count
  3494                                  lff11s2_9:
  3495 000018C7 BD06000000              	mov	ebp, 6 ; interpolation (one step) loop count
  3496                                  lff11s2_1:
  3497                                  	; 5:4:4::5:4:4::5:4:4::5:4:4::5:4:4::5:4  ; 74/17
  3498 000018CC 66AD                    	lodsw
  3499 000018CE 89C3                    	mov	ebx, eax
  3500 000018D0 66AD                    	lodsw
  3501 000018D2 8B16                    	mov	edx, [esi]
  3502                                  	; 17/01/2025
  3503                                  	;mov	[next_val_l], edx
  3504                                  	; 26/11/2023
  3505                                  	;shr	edx, 16
  3506                                  	;mov	[next_val_r], dx
  3507 000018D4 49                      	dec	ecx
  3508 000018D5 7502                    	jnz	short lff11s2_2_1
  3509 000018D7 31D2                    	xor	edx, edx ; 0
  3510                                  	;mov	[next_val_l], dx
  3511                                  	;mov	[next_val_r], dx
  3512                                  lff11s2_2_1:
  3513                                  	; bx = [previous_val_l]
  3514                                  	; ax = [previous_val_r]
  3515                                  	; [next_val_l]
  3516                                  	; dx = [next_val_r]
  3517                                  	;;;
  3518                                  	; 17/01/2025 (BugFix)
  3519 000018D9 8915[AC210000]          	mov	[next_val_l], edx
  3520                                  	;;;
  3521 000018DF E83F070000              	call	interpolating_5_16bit_stereo
  3522 000018E4 E3DA                    	jecxz	lff11s2_3
  3523                                  lff11s2_2_2:
  3524 000018E6 66AD                    	lodsw
  3525 000018E8 89C3                    	mov	ebx, eax
  3526 000018EA 66AD                    	lodsw
  3527 000018EC 8B16                    	mov	edx, [esi]
  3528                                  	; 17/01/2025
  3529                                  	;mov	[next_val_l], dx
  3530                                  	; 26/11/2023
  3531                                  	;shr	edx, 16
  3532                                  	;mov	[next_val_r], dx
  3533 000018EE 49                      	dec	ecx
  3534 000018EF 7502                    	jnz	short lff11s2_2_3
  3535 000018F1 31D2                    	xor	edx, edx ; 0
  3536                                  	;mov	[next_val_l], dx
  3537                                  	;mov	[next_val_r], dx
  3538                                  lff11s2_2_3:
  3539                                  	;;;
  3540                                  	; 17/01/2025 (BugFix)
  3541 000018F3 8915[AC210000]          	mov	[next_val_l], edx
  3542                                  	;;;
  3543 000018F9 E82D080000              	call	interpolating_4_16bit_stereo
  3544 000018FE E3C0                    	jecxz	lff11s2_3
  3545                                  	
  3546 00001900 4D                      	dec	ebp
  3547 00001901 74C4                    	jz	short lff11s2_9
  3548                                  
  3549 00001903 66AD                    	lodsw
  3550 00001905 89C3                    	mov	ebx, eax
  3551 00001907 66AD                    	lodsw
  3552 00001909 8B16                    	mov	edx, [esi]
  3553                                  	; 17/01/2025
  3554                                  	;mov	[next_val_l], dx
  3555                                  	; 26/11/2023
  3556                                  	;shr	edx, 16
  3557                                  	;mov	[next_val_r], dx
  3558 0000190B 49                      	dec	ecx
  3559 0000190C 7502                    	jnz	short lff11s2_2_4
  3560 0000190E 31D2                    	xor	edx, edx ; 0
  3561                                  	;mov	[next_val_l], dx
  3562                                  	;mov	[next_val_r], dx
  3563                                  lff11s2_2_4:
  3564                                  	;;;
  3565                                  	; 17/01/2025 (BugFix)
  3566 00001910 8915[AC210000]          	mov	[next_val_l], edx
  3567                                  	;;;
  3568 00001916 E810080000               	call	interpolating_4_16bit_stereo
  3569 0000191B E3A3                    	jecxz	lff11s2_3
  3570 0000191D EBAD                    	jmp	short lff11s2_1
  3571                                  
  3572                                  ; .....................
  3573                                  
  3574                                  load_44khz_mono_8_bit:
  3575                                  	; 02/02/2025
  3576                                  	; 18/11/2023
  3577 0000191F F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3578                                  					; last of the file?
  3579 00001926 7402                    	jz	short lff44m_0		; no
  3580 00001928 F9                      	stc
  3581 00001929 C3                      	retn
  3582                                  
  3583                                  lff44m_0:
  3584 0000192A BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3585                                          ;mov	edx, [loadsize]
  3586                                  
  3587                                  	; esi = buffer address
  3588                                  	;; edx = buffer size
  3589                                  
  3590                                  	; load file into memory
  3591                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 0000192F 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001935 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001937 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 0000193D B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001942 CD40                <1>  int 40h
  3592 00001944 7251                    	jc	short lff44m_7 ; error !
  3593                                  
  3594                                  	;mov	edi, audio_buffer
  3595                                  	; 29/05/2024
  3596 00001946 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3597                                  
  3598 0000194C 21C0                    	and	eax, eax
  3599 0000194E 7505                    	jnz	short lff44m_8
  3600 00001950 E98DF1FFFF              	jmp	lff44_eof
  3601                                  
  3602                                  lff44m_8:
  3603 00001955 89C1                    	mov	ecx, eax	; byte count
  3604                                  lff44m_9:
  3605 00001957 BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3606 0000195C C605[B0210000]02        	mov	byte [faz], 2  ; 2 steps/phases
  3607                                  lff44m_1:
  3608                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3609                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3610 00001963 AC                      	lodsb
  3611                                  	; 02/02/2025
  3612 00001964 8A16                    	mov	dl, [esi]
  3613 00001966 49                      	dec	ecx
  3614 00001967 7502                    	jnz	short lff44m_2_1
  3615 00001969 B280                    	mov	dl, 80h
  3616                                  lff44m_2_1:
  3617                                  	; al = [previous_val]
  3618                                  	; dl = [next_val]
  3619 0000196B E878030000              	call	interpolating_2_8bit_mono
  3620 00001970 E320                    	jecxz	lff44m_3
  3621                                  lff44m_2_2:
  3622 00001972 AC                      	lodsb
  3623 00001973 2C80                    	sub	al, 80h
  3624 00001975 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3625 00001979 66AB                    	stosw		; (L)
  3626 0000197B 66AB                    	stosw		; (R)
  3627                                  
  3628 0000197D 49                      	dec	ecx
  3629 0000197E 7412                    	jz	short lff44m_3
  3630 00001980 4D                      	dec	ebp
  3631 00001981 75EF                    	jnz	short lff44m_2_2
  3632                                  	
  3633 00001983 FE0D[B0210000]          	dec	byte [faz]
  3634 00001989 74CC                    	jz	short lff44m_9
  3635 0000198B BD0B000000              	mov	ebp, 11
  3636 00001990 EBD1                    	jmp	short lff44m_1
  3637                                  
  3638                                  lff44m_3:
  3639                                  lff44s_3:
  3640 00001992 E933F1FFFF              	jmp	lff44_3	; padfill
  3641                                  		; (put zeros in the remain words of the buffer)
  3642                                  lff44m_7:
  3643                                  lff44s_7:
  3644 00001997 E94FF1FFFF              	jmp	lff44_5  ; error
  3645                                  
  3646                                  load_44khz_stereo_8_bit:
  3647                                  	; 02/02/2025
  3648                                  	; 16/11/2023
  3649 0000199C F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3650                                  					; last of the file?
  3651 000019A3 7402                    	jz	short lff44s_0		; no
  3652 000019A5 F9                      	stc
  3653 000019A6 C3                      	retn
  3654                                  
  3655                                  lff44s_0:
  3656 000019A7 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3657                                          ;mov	edx, [loadsize]
  3658                                  
  3659                                  	; esi = buffer address
  3660                                  	;; edx = buffer size
  3661                                  
  3662                                  	; load file into memory
  3663                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 000019AC 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 000019B2 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 000019B4 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 000019BA B803000000          <1>  mov eax, %1
    90                              <1> 
    91 000019BF CD40                <1>  int 40h
  3664 000019C1 72D4                    	jc	short lff44s_7 ; error !
  3665                                  
  3666                                  	;mov	edi, audio_buffer
  3667                                  	; 29/05/2024
  3668 000019C3 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3669                                  
  3670 000019C9 D1E8                    	shr	eax, 1
  3671 000019CB 7505                    	jnz	short lff44s_8
  3672 000019CD E910F1FFFF              	jmp	lff44_eof
  3673                                  
  3674                                  lff44s_8:
  3675 000019D2 89C1                    	mov	ecx, eax	; word count
  3676                                  lff44s_9:
  3677 000019D4 BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3678 000019D9 C605[B0210000]02        	mov	byte [faz], 2  ; 2 steps/phase
  3679                                  lff44s_1:
  3680                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3681                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3682 000019E0 66AD                    	lodsw
  3683                                  	; 02/02/2025
  3684 000019E2 668B16                  	mov	dx, [esi]
  3685 000019E5 49                      	dec	ecx
  3686 000019E6 7504                    	jnz	short lff44s_2_1
  3687 000019E8 66BA8080                	mov	dx, 8080h
  3688                                  lff44s_2_1:	
  3689                                  	; al = [previous_val_l]
  3690                                  	; ah = [previous_val_r]
  3691                                  	; dl = [next_val_l]
  3692                                  	; dh = [next_val_r]
  3693 000019EC E814030000              	call	interpolating_2_8bit_stereo
  3694 000019F1 E39F                    	jecxz	lff44s_3
  3695                                  lff44s_2_2:
  3696 000019F3 AC                      	lodsb
  3697 000019F4 2C80                    	sub	al, 80h
  3698 000019F6 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3699 000019FA 66AB                    	stosw		; (L)
  3700 000019FC AC                      	lodsb
  3701 000019FD 2C80                    	sub	al, 80h
  3702 000019FF 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  3703 00001A03 66AB                    	stosw		; (R)
  3704                                  
  3705 00001A05 49                      	dec	ecx
  3706 00001A06 748A                    	jz	short lff44s_3
  3707 00001A08 4D                      	dec	ebp
  3708 00001A09 75E8                    	jnz	short lff44s_2_2
  3709                                  	
  3710 00001A0B FE0D[B0210000]          	dec	byte [faz]
  3711 00001A11 74C1                    	jz	short lff44s_9
  3712 00001A13 BD0B000000              	mov	ebp, 11
  3713 00001A18 EBC6                    	jmp	short lff44s_1
  3714                                  
  3715                                  load_44khz_mono_16_bit:
  3716                                  	; 02/02/2025
  3717                                  	; 18/11/2023
  3718 00001A1A F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3719                                  					; last of the file?
  3720 00001A21 7402                    	jz	short lff44m2_0		; no
  3721 00001A23 F9                      	stc
  3722 00001A24 C3                      	retn
  3723                                  
  3724                                  lff44m2_0:
  3725 00001A25 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3726                                          ;mov	edx, [loadsize]
  3727                                  
  3728                                  	; esi = buffer address
  3729                                  	;; edx = buffer size
  3730                                  
  3731                                  	; load file into memory
  3732                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001A2A 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001A30 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001A32 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001A38 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001A3D CD40                <1>  int 40h
  3733 00001A3F 724E                    	jc	short lff44m2_7 ; error !
  3734                                  
  3735                                  	;mov	edi, audio_buffer
  3736                                  	; 29/05/2024
  3737 00001A41 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3738                                  	
  3739 00001A47 D1E8                    	shr	eax, 1
  3740 00001A49 7505                    	jnz	short lff44m2_8
  3741 00001A4B E992F0FFFF              	jmp	lff44_eof
  3742                                  
  3743                                  lff44m2_8:
  3744 00001A50 89C1                    	mov	ecx, eax	; word count
  3745                                  lff44m2_9:
  3746 00001A52 BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3747 00001A57 C605[B0210000]02        	mov	byte [faz], 2  ; 2 steps/phases
  3748                                  lff44m2_1:
  3749                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3750                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3751 00001A5E 66AD                    	lodsw
  3752                                  	; 02/02/2025
  3753 00001A60 668B16                  	mov	dx, [esi]
  3754 00001A63 49                      	dec	ecx
  3755 00001A64 7502                    	jnz	short lff44m2_2_1
  3756 00001A66 31D2                    	xor	edx, edx
  3757                                  lff44m2_2_1:	
  3758                                  	; ax = [previous_val]
  3759                                  	; dx = [next_val]
  3760 00001A68 E85C030000              	call	interpolating_2_16bit_mono
  3761 00001A6D E31B                    	jecxz	lff44m2_3
  3762                                  lff44m2_2_2:
  3763 00001A6F 66AD                    	lodsw
  3764 00001A71 66AB                    	stosw		; (L)eft Channel
  3765 00001A73 66AB                    	stosw		; (R)ight Channel
  3766                                  
  3767 00001A75 49                      	dec	ecx
  3768 00001A76 7412                    	jz	short lff44m2_3	
  3769 00001A78 4D                      	dec	ebp
  3770 00001A79 75F4                    	jnz	short lff44m2_2_2
  3771                                  
  3772 00001A7B FE0D[B0210000]          	dec	byte [faz]
  3773 00001A81 74CF                    	jz	short lff44m2_9 
  3774 00001A83 BD0B000000              	mov	ebp, 11
  3775 00001A88 EBD4                    	jmp	short lff44m2_1
  3776                                  
  3777                                  lff44m2_3:
  3778                                  lff44s2_3:
  3779 00001A8A E93BF0FFFF              	jmp	lff44_3	; padfill
  3780                                  		; (put zeros in the remain words of the buffer)
  3781                                  lff44m2_7:
  3782                                  lff44s2_7:
  3783 00001A8F E957F0FFFF              	jmp	lff44_5  ; error
  3784                                  
  3785                                  load_44khz_stereo_16_bit:
  3786                                  	; 18/11/2023
  3787 00001A94 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3788                                  					; last of the file?
  3789 00001A9B 7402                    	jz	short lff44s2_0		; no
  3790 00001A9D F9                      	stc
  3791 00001A9E C3                      	retn
  3792                                  
  3793                                  lff44s2_0:
  3794 00001A9F BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3795                                          ;mov	edx, [loadsize]
  3796                                  
  3797                                  	; esi = buffer address
  3798                                  	;; edx = buffer size
  3799                                  
  3800                                  	; load file into memory
  3801                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001AA4 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001AAA 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001AAC 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001AB2 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001AB7 CD40                <1>  int 40h
  3802 00001AB9 72D4                    	jc	short lff44s2_7 ; error !
  3803                                  
  3804                                  	;mov	edi, audio_buffer
  3805                                  	; 29/05/2024
  3806 00001ABB 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3807                                  
  3808 00001AC1 C1E802                  	shr	eax, 2	; dword (left chan word + right chan word)
  3809 00001AC4 7505                    	jnz	short lff44s2_8
  3810 00001AC6 E917F0FFFF              	jmp	lff44_eof
  3811                                  
  3812                                  lff44s2_8:
  3813 00001ACB 89C1                    	mov	ecx, eax	; dword count
  3814                                  lff44s2_9:
  3815 00001ACD BD0A000000              	mov	ebp, 10 ; interpolation (one step) loop count
  3816 00001AD2 C605[B0210000]02        	mov	byte [faz], 2  ; 2 steps/phase
  3817                                  lff44s2_1:
  3818                                  	; 2:1:1:1:1:1:1:1:1:1:1::	; 25/23
  3819                                  	; 2:1:1:1:1:1:1:1:1:1:1:1
  3820 00001AD9 66AD                    	lodsw
  3821 00001ADB 89C3                    	mov	ebx, eax
  3822 00001ADD 66AD                    	lodsw
  3823                                  	;mov	dx, [esi]
  3824                                  	;mov	[next_val_l], dx
  3825                                  	;mov	dx, [esi+2]
  3826                                  	; 26/11/2023
  3827 00001ADF 8B16                    	mov	edx, [esi]
  3828 00001AE1 668915[AC210000]        	mov	[next_val_l], dx
  3829 00001AE8 C1EA10                  	shr	edx, 16
  3830 00001AEB 49                      	dec	ecx
  3831 00001AEC 7509                    	jnz	short lff44s2_2_1
  3832 00001AEE 31D2                    	xor	edx, edx ; 0
  3833 00001AF0 668915[AC210000]        	mov	[next_val_l], dx
  3834                                  lff44s2_2_1:
  3835                                  	; bx = [previous_val_l]
  3836                                  	; ax = [previous_val_r]
  3837                                  	; [next_val_l]
  3838                                  	; dx = [next_val_r]
  3839 00001AF7 E8E5020000              	call	interpolating_2_16bit_stereo
  3840 00001AFC E38C                    	jecxz	lff44s2_3
  3841                                  lff44s2_2_2:
  3842                                  	;movsw		; (L)eft Channel
  3843                                  	;movsw		; (R)ight Channel
  3844 00001AFE A5                      	movsd
  3845                                  
  3846 00001AFF 49                      	dec	ecx
  3847 00001B00 7488                    	jz	short lff44s2_3	
  3848 00001B02 4D                      	dec	ebp
  3849 00001B03 75F9                    	jnz	short lff44s2_2_2
  3850                                  	
  3851 00001B05 FE0D[B0210000]          	dec	byte [faz]
  3852 00001B0B 74C0                    	jz	short lff44s2_9 
  3853 00001B0D BD0B000000              	mov	ebp, 11
  3854 00001B12 EBC5                    	jmp	short lff44s2_1
  3855                                  
  3856                                  ; .....................
  3857                                  
  3858                                  	; 02/02/2025
  3859                                  load_12khz_mono_8_bit:
  3860 00001B14 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3861                                  					; last of the file?
  3862 00001B1B 7402                    	jz	short lff12m_0		; no
  3863 00001B1D F9                      	stc
  3864 00001B1E C3                      	retn
  3865                                  
  3866                                  lff12m_0:
  3867 00001B1F BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3868                                  
  3869                                  	; load file into memory
  3870                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001B24 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001B2A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001B2C 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001B32 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001B37 CD40                <1>  int 40h
  3871 00001B39 7258                    	jc	short lff12m_7 ; error !
  3872                                  
  3873                                  	;mov	edi, audio_buffer
  3874                                  	; 29/05/2024
  3875 00001B3B 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3876                                  	
  3877 00001B41 21C0                    	and	eax, eax
  3878 00001B43 7505                    	jnz	short lff12m_8
  3879 00001B45 E998EFFFFF              	jmp	lff12_eof
  3880                                  
  3881                                  lff12m_8:
  3882 00001B4A 89C1                    	mov	ecx, eax	; byte count
  3883                                  lff12m_1:
  3884                                  	; original-interpolated-interpolated-interpolated
  3885 00001B4C AC                      	lodsb
  3886                                  	; 02/02/2025
  3887 00001B4D 8A16                    	mov	dl, [esi]
  3888 00001B4F 49                      	dec	ecx
  3889 00001B50 7502                    	jnz	short lff12m_2
  3890 00001B52 B280                    	mov	dl, 80h
  3891                                  lff12m_2:	
  3892                                  	; al = [previous_val]
  3893                                  	; dl = [next_val]
  3894 00001B54 E8C3030000               	call	interpolating_4_8bit_mono
  3895 00001B59 E354                    	jecxz	lff12m_3
  3896 00001B5B EBEF                    	jmp	short lff12m_1
  3897                                  
  3898                                  	; 02/02/2025
  3899                                  load_12khz_stereo_8_bit:
  3900 00001B5D F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3901                                  					; last of the file?
  3902 00001B64 7402                    	jz	short lff12s_0		; no
  3903 00001B66 F9                      	stc
  3904 00001B67 C3                      	retn
  3905                                  
  3906                                  lff12s_0:
  3907 00001B68 BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3908                                  
  3909                                  	; load file into memory
  3910                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001B6D 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001B73 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001B75 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001B7B B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001B80 CD40                <1>  int 40h
  3911 00001B82 720F                    	jc	short lff12s_7 ; error !
  3912                                  
  3913                                  	;mov	edi, audio_buffer
  3914                                  	; 29/05/2024
  3915 00001B84 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3916                                  	
  3917 00001B8A D1E8                    	shr	eax, 1
  3918 00001B8C 750A                    	jnz	short lff12s_8
  3919 00001B8E E94FEFFFFF              	jmp	lff12_eof
  3920                                  
  3921                                  lff12m_7:
  3922                                  lff12s_7:
  3923 00001B93 E953EFFFFF              	jmp	lff12_5  ; error
  3924                                  
  3925                                  lff12s_8:
  3926 00001B98 89C1                    	mov	ecx, eax	; word count
  3927                                  lff12s_1:
  3928                                  	; original-interpolated-interpolated-interpolated
  3929 00001B9A 66AD                    	lodsw
  3930                                  	; 02/02/2025
  3931 00001B9C 668B16                  	mov	dx, [esi]
  3932 00001B9F 49                      	dec	ecx
  3933 00001BA0 7504                    	jnz	short lff12s_2
  3934 00001BA2 66BA8080                	mov	dx, 8080h
  3935                                  lff12s_2:	
  3936                                  	; al = [previous_val_l]
  3937                                  	; ah = [previous_val_r]
  3938                                  	; dl = [next_val_l]
  3939                                  	; dh = [next_val_r]
  3940 00001BA6 E8B0030000              	call	interpolating_4_8bit_stereo
  3941 00001BAB E302                    	jecxz	lff12s_3
  3942 00001BAD EBEB                    	jmp	short lff12s_1
  3943                                  
  3944                                  lff12m_3:
  3945                                  lff12s_3:
  3946 00001BAF E916EFFFFF              	jmp	lff12_3	; padfill
  3947                                  		; (put zeros in the remain words of the buffer)
  3948                                  
  3949                                  	; 02/02/2025
  3950                                  load_12khz_mono_16_bit:
  3951 00001BB4 F605[C8290000]01        	test    byte [flags], ENDOFFILE	; have we already read the
  3952                                  					; last of the file?
  3953 00001BBB 7402                    	jz	short lff12m2_0		; no
  3954 00001BBD F9                      	stc
  3955 00001BBE C3                      	retn
  3956                                  
  3957                                  lff12m2_0:
  3958 00001BBF BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  3959                                  
  3960                                  	; load file into memory
  3961                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001BC4 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001BCA 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001BCC 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001BD2 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001BD7 CD40                <1>  int 40h
  3962 00001BD9 7224                    	jc	short lff12m2_7 ; error !
  3963                                  
  3964                                  	;mov	edi, audio_buffer
  3965                                  	; 29/05/2024
  3966 00001BDB 8B3D[462A0000]          	mov	edi, [audio_buffer]
  3967                                  	
  3968 00001BE1 D1E8                    	shr	eax, 1
  3969 00001BE3 7505                    	jnz	short lff12m2_8
  3970 00001BE5 E9F8EEFFFF              	jmp	lff12_eof
  3971                                  
  3972                                  lff12m2_8:
  3973 00001BEA 89C1                    	mov	ecx, eax	; word count
  3974                                  lff12m2_1:
  3975                                  	; original-interpolated-interpolated-interpolated
  3976 00001BEC 66AD                    	lodsw
  3977                                  	; 02/02/2025
  3978 00001BEE 668B16                  	mov	dx, [esi]
  3979 00001BF1 49                      	dec	ecx
  3980 00001BF2 7502                    	jnz	short lff12m2_2
  3981 00001BF4 31D2                    	xor	edx, edx
  3982                                  lff12m2_2:	
  3983                                  	; ax = [previous_val]
  3984                                  	; dx = [next_val]
  3985 00001BF6 E8F7040000               	call	interpolating_4_16bit_mono
  3986 00001BFB E3B2                    	jecxz	lff12m_3
  3987 00001BFD EBED                    	jmp	short lff12m2_1
  3988                                  
  3989                                  lff12m2_7:
  3990                                  lff12s2_7:
  3991 00001BFF E9E7EEFFFF              	jmp	lff12_5  ; error
  3992                                  
  3993                                  	; 02/02/2025
  3994                                  load_12khz_stereo_16_bit:
  3995 00001C04 F605[C8290000]01                test    byte [flags], ENDOFFILE	; have we already read the
  3996                                  					; last of the file?
  3997 00001C0B 7402                    	jz	short lff12s2_0		; no
  3998 00001C0D F9                      	stc
  3999 00001C0E C3                      	retn
  4000                                  
  4001                                  lff12s2_0:
  4002 00001C0F BE[00400200]            	mov	esi, temp_buffer ; temporary buffer for wav data
  4003                                  
  4004                                  	; load file into memory
  4005                                  	sys 	_read, [FileHandle], esi, [loadsize]
    76                              <1> 
    77                              <1> 
    78                              <1> 
    79                              <1> 
    80                              <1>  %if %0 >= 2
    81 00001C14 8B1D[7E260000]      <1>  mov ebx, %2
    82                              <1>  %if %0 >= 3
    83 00001C1A 89F1                <1>  mov ecx, %3
    84                              <1>  %if %0 = 4
    85 00001C1C 8B15[B8030000]      <1>  mov edx, %4
    86                              <1>  %endif
    87                              <1>  %endif
    88                              <1>  %endif
    89 00001C22 B803000000          <1>  mov eax, %1
    90                              <1> 
    91 00001C27 CD40                <1>  int 40h
  4006 00001C29 72D4                    	jc	short lff12s2_7 ; error !
  4007                                  
  4008                                  	;mov	edi, audio_buffer
  4009                                  	; 29/05/2024
  4010 00001C2B 8B3D[462A0000]          	mov	edi, [audio_buffer]
  4011                                  	
  4012 00001C31 C1E802                  	shr	eax, 2	; dword (left chan word + right chan word)
  4013 00001C34 750A                    	jnz	short lff12s2_8
  4014 00001C36 E9A7EEFFFF              	jmp	lff12_eof
  4015                                  
  4016                                  lff12m2_3:
  4017                                  lff12s2_3:
  4018 00001C3B E98AEEFFFF              	jmp	lff12_3	; padfill
  4019                                  		; (put zeros in the remain words of the buffer)
  4020                                  
  4021                                  lff12s2_8:
  4022 00001C40 89C1                    	mov	ecx, eax	; dword count
  4023                                  lff12s2_1:
  4024                                  	; original-interpolated-interpolated-interpolated
  4025 00001C42 66AD                    	lodsw
  4026 00001C44 89C3                    	mov	ebx, eax
  4027 00001C46 66AD                    	lodsw
  4028 00001C48 8B16                    	mov	edx, [esi]
  4029 00001C4A 49                      	dec	ecx
  4030 00001C4B 7502                    	jnz	short lff12s2_2
  4031 00001C4D 31D2                    	xor	edx, edx ; 0
  4032                                  lff12s2_2:
  4033                                  	;mov	[next_val_l], dx
  4034                                  	;shr	edx, 16
  4035                                  	;mov	[next_val_r], dx
  4036                                  	; 02/02/2025
  4037 00001C4F 8915[AC210000]          	mov	[next_val_l], edx
  4038                                  
  4039                                  	; bx = [previous_val_l]
  4040                                  	; ax = [previous_val_r]
  4041                                  	; [next_val_l]
  4042                                  	; [next_val_r]
  4043 00001C55 E8D1040000              	call	interpolating_4_16bit_stereo
  4044 00001C5A E3DF                    	jecxz	lff12s2_3
  4045 00001C5C EBE4                    	jmp	short lff12s2_1
  4046                                  
  4047                                  ; .....................
  4048                                  
  4049                                  interpolating_3_8bit_mono:
  4050                                  	; 02/02/2025
  4051                                  	; 16/11/2023
  4052                                  	; al = [previous_val]
  4053                                  	; dl = [next_val]
  4054                                  	; original-interpolated-interpolated
  4055 00001C5E 88C3                    	mov	bl, al
  4056 00001C60 2C80                    	sub	al, 80h
  4057 00001C62 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4058 00001C66 66AB                    	stosw		; original sample (L)
  4059 00001C68 66AB                    	stosw		; original sample (R)
  4060 00001C6A 88D8                    	mov	al, bl
  4061 00001C6C 00D0                    	add	al, dl
  4062 00001C6E D0D8                    	rcr	al, 1
  4063 00001C70 88C7                    	mov	bh, al	; interpolated middle (temporary)
  4064 00001C72 00D8                    	add	al, bl
  4065 00001C74 D0D8                    	rcr	al, 1
  4066 00001C76 2C80                    	sub	al, 80h
  4067 00001C78 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4068 00001C7C 66AB                    	stosw		; interpolated sample 1 (L)
  4069 00001C7E 66AB                    	stosw		; interpolated sample 1 (R)
  4070 00001C80 88F8                    	mov	al, bh
  4071 00001C82 00D0                    	add	al, dl	; [next_val]
  4072 00001C84 D0D8                    	rcr	al, 1
  4073                                  	; 02/02/2025
  4074 00001C86 2C80                    	sub	al, 80h
  4075 00001C88 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4076 00001C8C 66AB                    	stosw		; interpolated sample 2 (L)
  4077 00001C8E 66AB                    	stosw		; interpolated sample 2 (R)
  4078 00001C90 C3                      	retn
  4079                                  
  4080                                  interpolating_3_8bit_stereo:
  4081                                  	; 02/02/2025
  4082                                  	; 16/11/2023
  4083                                  	; al = [previous_val_l]
  4084                                  	; ah = [previous_val_r]
  4085                                  	; dl = [next_val_l]
  4086                                  	; dh = [next_val_r]	
  4087                                  	; original-interpolated-interpolated
  4088 00001C91 89C3                    	mov	ebx, eax
  4089 00001C93 2C80                    	sub	al, 80h
  4090 00001C95 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4091 00001C99 66AB                    	stosw		; original sample (L)
  4092 00001C9B 88F8                    	mov	al, bh
  4093 00001C9D 2C80                    	sub	al, 80h
  4094 00001C9F 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4095 00001CA3 66AB                    	stosw		; original sample (R)
  4096 00001CA5 88D8                    	mov	al, bl
  4097 00001CA7 00D0                    	add	al, dl	; [next_val_l]
  4098 00001CA9 D0D8                    	rcr	al, 1
  4099 00001CAB 50                      	push	eax ; *	; al = interpolated middle (L) (temporary)
  4100 00001CAC 00D8                    	add	al, bl	; [previous_val_l]
  4101 00001CAE D0D8                    	rcr	al, 1
  4102 00001CB0 2C80                    	sub	al, 80h
  4103 00001CB2 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4104 00001CB6 66AB                    	stosw		; interpolated sample 1 (L)
  4105 00001CB8 88F8                    	mov	al, bh
  4106 00001CBA 00F0                    	add	al, dh	; [next_val_r]
  4107 00001CBC D0D8                    	rcr	al, 1
  4108 00001CBE 50                      	push	eax ; ** ; al = interpolated middle (R) (temporary)
  4109 00001CBF 00F8                    	add	al, bh	; [previous_val_r]
  4110 00001CC1 D0D8                    	rcr	al, 1
  4111 00001CC3 2C80                    	sub	al, 80h
  4112 00001CC5 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4113 00001CC9 66AB                    	stosw		; interpolated sample 1 (R)
  4114 00001CCB 5B                      	pop	ebx ; **
  4115 00001CCC 58                      	pop	eax ; *
  4116 00001CCD 00D0                    	add	al, dl	; [next_val_l]
  4117 00001CCF D0D8                    	rcr	al, 1
  4118                                  	; 02/02/2025
  4119 00001CD1 2C80                    	sub	al, 80h
  4120 00001CD3 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4121 00001CD7 66AB                    	stosw		; interpolated sample 2 (L)
  4122 00001CD9 88D8                    	mov	al, bl
  4123 00001CDB 00F0                    	add	al, dh	; [next_val_r]
  4124 00001CDD D0D8                    	rcr	al, 1
  4125                                  	; 02/02/2025
  4126 00001CDF 2C80                    	sub	al, 80h
  4127 00001CE1 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4128 00001CE5 66AB                    	stosw		; interpolated sample 2 (R)
  4129 00001CE7 C3                      	retn
  4130                                  
  4131                                  interpolating_2_8bit_mono:
  4132                                  	; 16/11/2023
  4133                                  	; al = [previous_val]
  4134                                  	; dl = [next_val]
  4135                                  	; original-interpolated
  4136 00001CE8 88C3                    	mov	bl, al
  4137 00001CEA 2C80                    	sub	al, 80h
  4138 00001CEC 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4139 00001CF0 66AB                    	stosw		; original sample (L)
  4140 00001CF2 66AB                    	stosw		; original sample (R)
  4141 00001CF4 88D8                    	mov	al, bl
  4142 00001CF6 00D0                    	add	al, dl
  4143 00001CF8 D0D8                    	rcr	al, 1
  4144 00001CFA 2C80                    	sub	al, 80h
  4145 00001CFC 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4146 00001D00 66AB                    	stosw		; interpolated sample (L)
  4147 00001D02 66AB                    	stosw		; interpolated sample (R)
  4148 00001D04 C3                      	retn
  4149                                  
  4150                                  interpolating_2_8bit_stereo:
  4151                                  	; 16/11/2023
  4152                                  	; al = [previous_val_l]
  4153                                  	; ah = [previous_val_r]
  4154                                  	; dl = [next_val_l]
  4155                                  	; dh = [next_val_r]
  4156                                  	; original-interpolated
  4157 00001D05 89C3                    	mov	ebx, eax
  4158 00001D07 2C80                    	sub	al, 80h
  4159 00001D09 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4160 00001D0D 66AB                    	stosw		; original sample (L)
  4161 00001D0F 88F8                    	mov	al, bh
  4162 00001D11 2C80                    	sub	al, 80h
  4163 00001D13 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4164 00001D17 66AB                    	stosw		; original sample (R)
  4165 00001D19 88D8                    	mov	al, bl	; [previous_val_l]
  4166 00001D1B 00D0                    	add	al, dl	; [next_val_l]
  4167 00001D1D D0D8                    	rcr	al, 1
  4168 00001D1F 2C80                    	sub	al, 80h
  4169 00001D21 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4170 00001D25 66AB                    	stosw		; interpolated sample (L)
  4171 00001D27 88F8                    	mov	al, bh
  4172 00001D29 00F0                    	add	al, dh	; [next_val_r]
  4173 00001D2B D0D8                    	rcr	al, 1
  4174 00001D2D 2C80                    	sub	al, 80h
  4175 00001D2F 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4176 00001D33 66AB                    	stosw		; interpolated sample (R)
  4177 00001D35 C3                      	retn
  4178                                  
  4179                                  interpolating_3_16bit_mono:
  4180                                  	; 16/11/2023
  4181                                  	; ax = [previous_val]
  4182                                  	; dx = [next_val]
  4183                                  	; original-interpolated-interpolated
  4184                                  
  4185 00001D36 66AB                    	stosw		; original sample (L)
  4186 00001D38 66AB                    	stosw		; original sample (R)
  4187 00001D3A 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4188 00001D3D 50                      	push	eax ; *	; [previous_val]
  4189 00001D3E 80C680                  	add	dh, 80h
  4190 00001D41 6601D0                  	add	ax, dx
  4191 00001D44 66D1D8                  	rcr	ax, 1
  4192 00001D47 5B                      	pop	ebx ; *
  4193 00001D48 93                      	xchg	ebx, eax ; bx  = interpolated middle (temporary)
  4194 00001D49 6601D8                  	add	ax, bx	; [previous_val] + interpolated middle
  4195 00001D4C 66D1D8                  	rcr	ax, 1
  4196 00001D4F 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4197 00001D52 66AB                    	stosw 		; interpolated sample 1 (L)
  4198 00001D54 66AB                    	stosw		; interpolated sample 1 (R)
  4199 00001D56 89D8                    	mov	eax, ebx
  4200 00001D58 6601D0                  	add	ax, dx	; interpolated middle + [next_val]
  4201 00001D5B 66D1D8                  	rcr	ax, 1
  4202 00001D5E 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4203 00001D61 66AB                    	stosw		; interpolated sample 2 (L)
  4204 00001D63 66AB                    	stosw		; interpolated sample 2 (R)
  4205 00001D65 C3                      	retn
  4206                                  
  4207                                  interpolating_3_16bit_stereo:
  4208                                  	; 16/11/2023
  4209                                  	; bx = [previous_val_l]
  4210                                  	; ax = [previous_val_r]
  4211                                  	; [next_val_l]
  4212                                  	; dx = [next_val_r]
  4213                                  	; original-interpolated-interpolated
  4214                                  
  4215 00001D66 93                      	xchg	eax, ebx
  4216 00001D67 66AB                    	stosw		; original sample (L)
  4217 00001D69 93                      	xchg	eax, ebx
  4218 00001D6A 66AB                    	stosw		; original sample (R)
  4219 00001D6C 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4220 00001D6F 50                      	push	eax ; *	; [previous_val_r]
  4221 00001D70 80C780                  	add	bh, 80h
  4222 00001D73 8005[AD210000]80        	add	byte [next_val_l+1], 80h
  4223 00001D7A 66A1[AC210000]          	mov	ax, [next_val_l]
  4224 00001D80 6601D8                  	add	ax, bx	; [previous_val_l]
  4225 00001D83 66D1D8                  	rcr	ax, 1
  4226 00001D86 93                      	xchg	eax, ebx ; ax = [previous_val_l]
  4227 00001D87 6601D8                  	add	ax, bx	; bx = interpolated middle (L)
  4228 00001D8A 66D1D8                  	rcr	ax, 1
  4229 00001D8D 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4230 00001D90 66AB                    	stosw 		; interpolated sample 1 (L)
  4231 00001D92 58                      	pop	eax  ; *
  4232 00001D93 80C680                  	add	dh, 80h ; convert sound level 0 to 65535 format
  4233 00001D96 52                      	push	edx  ; * ; [next_val_r]
  4234 00001D97 92                      	xchg	eax, edx
  4235 00001D98 6601D0                  	add	ax, dx	; [next_val_r] + [previous_val_r]
  4236 00001D9B 66D1D8                  	rcr	ax, 1	; / 2
  4237 00001D9E 50                      	push	eax ; ** ; interpolated middle (R)
  4238 00001D9F 6601D0                  	add	ax, dx	; + [previous_val_r]
  4239 00001DA2 66D1D8                  	rcr	ax, 1
  4240 00001DA5 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4241 00001DA8 66AB                    	stosw 		; interpolated sample 1 (R)
  4242 00001DAA 66A1[AC210000]          	mov	ax, [next_val_l]
  4243 00001DB0 6601D8                  	add	ax, bx	; + interpolated middle (L)
  4244 00001DB3 66D1D8                  	rcr	ax, 1
  4245 00001DB6 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4246 00001DB9 66AB                    	stosw 		; interpolated sample 2 (L)
  4247 00001DBB 58                      	pop	eax ; **
  4248 00001DBC 5A                      	pop	edx ; *
  4249 00001DBD 6601D0                  	add	ax, dx	; interpolated middle + [next_val_r]
  4250 00001DC0 66D1D8                  	rcr	ax, 1	; / 2
  4251 00001DC3 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4252 00001DC6 66AB                    	stosw 		; interpolated sample 2 (L)
  4253 00001DC8 C3                      	retn
  4254                                  
  4255                                  interpolating_2_16bit_mono:
  4256                                  	; 16/11/2023
  4257                                  	; ax = [previous_val]
  4258                                  	; dx = [next_val]
  4259                                  	; original-interpolated
  4260                                  
  4261 00001DC9 66AB                    	stosw		; original sample (L)
  4262 00001DCB 66AB                    	stosw		; original sample (R)
  4263 00001DCD 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4264 00001DD0 80C680                  	add	dh, 80h
  4265 00001DD3 6601D0                  	add	ax, dx
  4266 00001DD6 66D1D8                  	rcr	ax, 1
  4267 00001DD9 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4268 00001DDC 66AB                    	stosw		; interpolated sample (L)
  4269 00001DDE 66AB                    	stosw		; interpolated sample (R)
  4270 00001DE0 C3                      	retn
  4271                                  
  4272                                  interpolating_2_16bit_stereo:
  4273                                  	; 17/01/2025
  4274                                  	; 16/11/2023
  4275                                  	; bx = [previous_val_l]
  4276                                  	; ax = [previous_val_r]
  4277                                  	; [next_val_l]
  4278                                  	; dx = [next_val_r]
  4279                                  	; original-interpolated
  4280                                  
  4281 00001DE1 93                      	xchg	eax, ebx
  4282 00001DE2 66AB                    	stosw		; original sample (L)
  4283 00001DE4 93                      	xchg	eax, ebx
  4284 00001DE5 66AB                    	stosw		; original sample (R)
  4285 00001DE7 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4286 00001DEA 80C680                  	add	dh, 80h
  4287 00001DED 6601D0                  	add	ax, dx	; [previous_val_r] + [next_val_r]
  4288 00001DF0 66D1D8                  	rcr	ax, 1	; / 2
  4289                                  	; 17/01/2025
  4290 00001DF3 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4291                                  	;push	eax ; *	; interpolated sample (R)
  4292                                  	; 17/01/2025
  4293 00001DF6 C1E010                  	shl	eax, 16
  4294 00001DF9 66A1[AC210000]          	mov	ax, [next_val_l]
  4295 00001DFF 80C480                  	add	ah, 80h
  4296 00001E02 80C780                  	add	bh, 80h
  4297 00001E05 6601D8                  	add	ax, bx	; [next_val_l] + [previous_val_l]
  4298 00001E08 66D1D8                  	rcr	ax, 1	; / 2
  4299 00001E0B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4300                                  	; 17/01/2025
  4301                                  	;stosw 		; interpolated sample (L)
  4302                                  	;pop	eax ; *
  4303                                  	;sub	ah, 80h	; -32768 to +32767 format again
  4304                                  	;stosw 		; interpolated sample (R)
  4305                                  	; 17/01/2025
  4306 00001E0E AB                      	stosd
  4307 00001E0F C3                      	retn
  4308                                  
  4309                                  interpolating_5_8bit_mono:
  4310                                  	; 17/11/2023
  4311                                  	; al = [previous_val]
  4312                                  	; dl = [next_val]
  4313                                  	; original-interpltd-interpltd-interpltd-interpltd
  4314 00001E10 88C3                    	mov	bl, al
  4315 00001E12 2C80                    	sub	al, 80h
  4316 00001E14 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4317 00001E18 66AB                    	stosw		; original sample (L)
  4318 00001E1A 66AB                    	stosw		; original sample (R)
  4319 00001E1C 88D8                    	mov	al, bl
  4320 00001E1E 00D0                    	add	al, dl
  4321 00001E20 D0D8                    	rcr	al, 1
  4322 00001E22 88C7                    	mov	bh, al	; interpolated middle (temporary)
  4323 00001E24 00D8                    	add	al, bl  ; [previous_val]
  4324 00001E26 D0D8                    	rcr	al, 1 	
  4325 00001E28 88C6                    	mov	dh, al	; interpolated 1st quarter (temporary)
  4326 00001E2A 00D8                    	add	al, bl
  4327 00001E2C D0D8                    	rcr	al, 1
  4328 00001E2E 2C80                    	sub	al, 80h
  4329 00001E30 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4330 00001E34 66AB                    	stosw		; interpolated sample 1 (L)
  4331 00001E36 66AB                    	stosw		; interpolated sample 1 (R)
  4332 00001E38 88F8                    	mov	al, bh
  4333 00001E3A 00F0                    	add	al, dh
  4334 00001E3C D0D8                    	rcr	al, 1
  4335 00001E3E 2C80                    	sub	al, 80h
  4336 00001E40 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4337 00001E44 66AB                    	stosw		; interpolated sample 2 (L)
  4338 00001E46 66AB                    	stosw		; interpolated sample 2 (R)
  4339 00001E48 88F8                    	mov	al, bh
  4340 00001E4A 00D0                    	add	al, dl	; [next_val]
  4341 00001E4C D0D8                    	rcr	al, 1
  4342 00001E4E 88C6                    	mov	dh, al	; interpolated 3rd quarter (temporary)
  4343 00001E50 00F8                    	add	al, bh
  4344 00001E52 D0D8                    	rcr	al, 1
  4345 00001E54 2C80                    	sub	al, 80h
  4346 00001E56 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4347 00001E5A 66AB                    	stosw		; interpolated sample 3 (L)
  4348 00001E5C 66AB                    	stosw		; interpolated sample 3 (R)
  4349 00001E5E 88F0                    	mov	al, dh
  4350 00001E60 00D0                    	add	al, dl
  4351 00001E62 D0D8                    	rcr	al, 1
  4352 00001E64 2C80                    	sub	al, 80h
  4353 00001E66 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4354 00001E6A 66AB                    	stosw		; interpolated sample 4 (L)
  4355 00001E6C 66AB                    	stosw		; interpolated sample 4 (R)
  4356 00001E6E C3                      	retn
  4357                                  
  4358                                  interpolating_5_8bit_stereo:
  4359                                  	; 17/11/2023
  4360                                  	; al = [previous_val_l]
  4361                                  	; ah = [previous_val_r]
  4362                                  	; dl = [next_val_l]
  4363                                  	; dh = [next_val_r]
  4364                                  	; original-interpltd-interpltd-interpltd-interpltd
  4365 00001E6F 89C3                    	mov	ebx, eax
  4366 00001E71 2C80                    	sub	al, 80h
  4367 00001E73 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4368 00001E77 66AB                    	stosw		; original sample (L)
  4369 00001E79 88F8                    	mov	al, bh
  4370 00001E7B 2C80                    	sub	al, 80h
  4371 00001E7D 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4372 00001E81 66AB                    	stosw		; original sample (R)
  4373 00001E83 52                      	push	edx ; *
  4374 00001E84 88D8                    	mov	al, bl
  4375 00001E86 00D0                    	add	al, dl	; [next_val_l]
  4376 00001E88 D0D8                    	rcr	al, 1
  4377 00001E8A 50                      	push	eax ; ** ; al = interpolated middle (L) (temporary)
  4378 00001E8B 00D8                    	add	al, bl	; [previous_val_l]
  4379 00001E8D D0D8                    	rcr	al, 1
  4380 00001E8F 86D8                    	xchg	al, bl
  4381 00001E91 00D8                    	add	al, bl	; bl = interpolated 1st quarter (L) (temp)
  4382 00001E93 D0D8                    	rcr	al, 1
  4383 00001E95 2C80                    	sub	al, 80h
  4384 00001E97 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4385 00001E9B 66AB                    	stosw		; interpolated sample 1 (L)
  4386 00001E9D 88F8                    	mov	al, bh
  4387 00001E9F 00F0                    	add	al, dh	; [next_val_r]
  4388 00001EA1 D0D8                    	rcr	al, 1
  4389 00001EA3 50                      	push	eax ; *** ; al = interpolated middle (R) (temporary)
  4390 00001EA4 00F8                    	add	al, bh	; [previous_val_r]
  4391 00001EA6 D0D8                    	rcr	al, 1
  4392 00001EA8 86F8                    	xchg	al, bh
  4393 00001EAA 00F8                    	add	al, bh	; bh = interpolated 1st quarter (R) (temp)
  4394 00001EAC D0D8                    	rcr	al, 1
  4395 00001EAE 2C80                    	sub	al, 80h
  4396 00001EB0 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4397 00001EB4 66AB                    	stosw		; interpolated sample 1 (R)
  4398 00001EB6 5A                      	pop	edx ; ***
  4399 00001EB7 58                      	pop	eax ; ** ; al = interpolated middle (L) (temporary)
  4400 00001EB8 86D8                    	xchg	al, bl	; al = interpolated 1st quarter (L) (temp)
  4401 00001EBA 00D8                    	add	al, bl	; bl = interpolated middle (L) (temporary)
  4402 00001EBC D0D8                    	rcr	al, 1
  4403 00001EBE 2C80                    	sub	al, 80h
  4404 00001EC0 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4405 00001EC4 66AB                    	stosw		; interpolated sample 2 (L)	
  4406 00001EC6 88D0                    	mov	al, dl 	; interpolated middle (R) (temporary)
  4407 00001EC8 86F8                    	xchg	al, bh	; al = interpolated 1st quarter (R) (temp)
  4408 00001ECA 00F8                    	add	al, bh	; bh = interpolated middle (R) (temporary)
  4409 00001ECC D0D8                    	rcr	al, 1
  4410 00001ECE 2C80                    	sub	al, 80h
  4411 00001ED0 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4412 00001ED4 66AB                    	stosw		; interpolated sample 2 (R)
  4413 00001ED6 5A                      	pop	edx ; *
  4414 00001ED7 88D8                    	mov	al, bl	; interpolated middle (L) (temporary)
  4415 00001ED9 00D0                    	add	al, dl	; [next_val_l]
  4416 00001EDB D0D8                    	rcr	al, 1
  4417 00001EDD 86D8                    	xchg	al, bl	; al = interpolated middle (R) (temporary)
  4418 00001EDF 00D8                    	add	al, bl	; bl = interpolated 3rd quarter (L) (temp)
  4419 00001EE1 D0D8                    	rcr	al, 1
  4420 00001EE3 2C80                    	sub	al, 80h
  4421 00001EE5 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4422 00001EE9 66AB                    	stosw		; interpolated sample 3 (L)
  4423 00001EEB 88F8                    	mov	al, bh	
  4424 00001EED 00F0                    	add	al, dh	; interpolated middle (R) + [next_val_r]
  4425 00001EEF D0D8                    	rcr	al, 1
  4426 00001EF1 86F8                    	xchg	al, bh	; al = interpolated middle (R)
  4427 00001EF3 00F8                    	add	al, bh	; bh = interpolated 3rd quarter (R) (temp)
  4428 00001EF5 D0D8                    	rcr	al, 1
  4429 00001EF7 2C80                    	sub	al, 80h
  4430 00001EF9 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4431 00001EFD 66AB                    	stosw		; interpolated sample 3 (R)
  4432 00001EFF 88D8                    	mov	al, bl
  4433 00001F01 00D0                    	add	al, dl	; [next_val_l]
  4434 00001F03 D0D8                    	rcr	al, 1
  4435 00001F05 2C80                    	sub	al, 80h
  4436 00001F07 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4437 00001F0B 66AB                    	stosw		; interpolated sample 4 (L)
  4438 00001F0D 88F8                    	mov	al, bh
  4439 00001F0F 00F0                    	add	al, dh	; [next_val_r]
  4440 00001F11 D0D8                    	rcr	al, 1
  4441 00001F13 2C80                    	sub	al, 80h
  4442 00001F15 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4443 00001F19 66AB                    	stosw		; interpolated sample 4 (R)
  4444 00001F1B C3                      	retn
  4445                                  
  4446                                  interpolating_4_8bit_mono:
  4447                                  	; 17/11/2023
  4448                                  	; al = [previous_val]
  4449                                  	; dl = [next_val]
  4450                                  	; original-interpolated-interpolated-interpolated
  4451 00001F1C 88C3                    	mov	bl, al
  4452 00001F1E 2C80                    	sub	al, 80h
  4453 00001F20 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4454 00001F24 66AB                    	stosw		; original sample (L)
  4455 00001F26 66AB                    	stosw		; original sample (R)
  4456 00001F28 88D8                    	mov	al, bl
  4457 00001F2A 00D0                    	add	al, dl
  4458 00001F2C D0D8                    	rcr	al, 1
  4459 00001F2E 86D8                    	xchg	al, bl  ; al = [previous_val]
  4460 00001F30 00D8                    	add	al, bl	; bl = interpolated middle (sample 2)
  4461 00001F32 D0D8                    	rcr	al, 1
  4462 00001F34 2C80                    	sub	al, 80h
  4463 00001F36 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4464 00001F3A 66AB                    	stosw		; interpolated sample 1 (L)
  4465 00001F3C 66AB                    	stosw		; interpolated sample 1 (R)
  4466 00001F3E 88D8                    	mov	al, bl	; interpolated middle (sample 2)
  4467 00001F40 2C80                    	sub	al, 80h
  4468 00001F42 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4469 00001F46 66AB                    	stosw		; interpolated sample 2 (L)
  4470 00001F48 66AB                    	stosw		; interpolated sample 2 (R)
  4471 00001F4A 88D8                    	mov	al, bl
  4472 00001F4C 00D0                    	add	al, dl	; [next_val]
  4473 00001F4E D0D8                    	rcr	al, 1
  4474 00001F50 2C80                    	sub	al, 80h
  4475 00001F52 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4476 00001F56 66AB                    	stosw		; interpolated sample 3 (L)
  4477 00001F58 66AB                    	stosw		; interpolated sample 3 (R)
  4478 00001F5A C3                      	retn
  4479                                  
  4480                                  interpolating_4_8bit_stereo:
  4481                                  	; 17/11/2023
  4482                                  	; al = [previous_val_l]
  4483                                  	; ah = [previous_val_r]
  4484                                  	; dl = [next_val_l]
  4485                                  	; dh = [next_val_r]
  4486                                  	; original-interpolated-interpolated-interpolated
  4487 00001F5B 89C3                    	mov	ebx, eax
  4488 00001F5D 2C80                    	sub	al, 80h
  4489 00001F5F 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4490 00001F63 66AB                    	stosw		; original sample (L)
  4491 00001F65 88F8                    	mov	al, bh
  4492 00001F67 2C80                    	sub	al, 80h
  4493 00001F69 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4494 00001F6D 66AB                    	stosw		; original sample (R)
  4495 00001F6F 88D8                    	mov	al, bl
  4496 00001F71 00D0                    	add	al, dl	; [next_val_l]
  4497 00001F73 D0D8                    	rcr	al, 1
  4498 00001F75 86D8                    	xchg	al, bl	; al = [previous_val_l]
  4499 00001F77 00D8                    	add	al, bl	; bl = interpolated middle (L) (sample 2)
  4500 00001F79 D0D8                    	rcr	al, 1
  4501 00001F7B 2C80                    	sub	al, 80h
  4502 00001F7D 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4503 00001F81 66AB                    	stosw		; interpolated sample 1 (L)
  4504 00001F83 88F8                    	mov	al, bh
  4505 00001F85 00F0                    	add	al, dh	; [next_val_r]
  4506 00001F87 D0D8                    	rcr	al, 1
  4507 00001F89 86F8                    	xchg	al, bh	; al = [previous_val_h]
  4508 00001F8B 00F8                    	add	al, bh	; bh = interpolated middle (R) (sample 2)
  4509 00001F8D D0D8                    	rcr	al, 1
  4510 00001F8F 2C80                    	sub	al, 80h
  4511 00001F91 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4512 00001F95 66AB                    	stosw		; interpolated sample 1 (R)
  4513 00001F97 88D8                    	mov	al, bl	; interpolated middle (L) (sample 2)
  4514 00001F99 2C80                    	sub	al, 80h
  4515 00001F9B 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4516 00001F9F 66AB                    	stosw		; interpolated sample 2 (L)
  4517 00001FA1 88F8                    	mov	al, bh	; interpolated middle (L) (sample 2)
  4518 00001FA3 2C80                    	sub	al, 80h
  4519 00001FA5 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4520 00001FA9 66AB                    	stosw		; interpolated sample 2 (L)
  4521 00001FAB 88D8                    	mov	al, bl
  4522 00001FAD 00D0                    	add	al, dl	; [next_val_l]
  4523 00001FAF D0D8                    	rcr	al, 1
  4524 00001FB1 2C80                    	sub	al, 80h
  4525 00001FB3 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4526 00001FB7 66AB                    	stosw		; interpolated sample 3 (L)
  4527 00001FB9 88F8                    	mov	al, bh
  4528 00001FBB 00F0                    	add	al, dh	; [next_val_r]
  4529 00001FBD D0D8                    	rcr	al, 1
  4530 00001FBF 2C80                    	sub	al, 80h
  4531 00001FC1 66C1E008                	shl	ax, 8	; convert 8 bit sample to 16 bit sample
  4532 00001FC5 66AB                    	stosw		; interpolated sample 3 (R)
  4533 00001FC7 C3                      	retn
  4534                                  
  4535                                  interpolating_5_16bit_mono:
  4536                                  	; 18/11/2023
  4537                                  	; ax = [previous_val]
  4538                                  	; dx = [next_val]
  4539                                  	; original-interpltd-interpltd-interpltd-interpltd
  4540 00001FC8 66AB                    	stosw		; original sample (L)
  4541 00001FCA 66AB                    	stosw		; original sample (R)
  4542 00001FCC 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4543 00001FCF 89C3                    	mov	ebx, eax ; [previous_val]
  4544 00001FD1 80C680                  	add	dh, 80h
  4545 00001FD4 6601D0                  	add	ax, dx
  4546 00001FD7 66D1D8                  	rcr	ax, 1
  4547 00001FDA 50                      	push	eax ; *	; interpolated middle (temporary)
  4548 00001FDB 6601D8                  	add	ax, bx	; interpolated middle + [previous_val]
  4549 00001FDE 66D1D8                  	rcr	ax, 1
  4550 00001FE1 50                      	push	eax ; **	; interpolated 1st quarter (temporary)
  4551 00001FE2 6601D8                  	add	ax, bx	; 1st quarter + [previous_val]
  4552 00001FE5 66D1D8                  	rcr	ax, 1	
  4553 00001FE8 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4554 00001FEB 66AB                    	stosw 		; interpolated sample 1 (L)
  4555 00001FED 66AB                    	stosw		; interpolated sample 1 (R)
  4556 00001FEF 58                      	pop	eax ; **
  4557 00001FF0 5B                      	pop	ebx ; *
  4558 00001FF1 6601D8                  	add	ax, bx	; 1st quarter + middle
  4559 00001FF4 66D1D8                  	rcr	ax, 1	; / 2
  4560 00001FF7 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again	
  4561 00001FFA 66AB                    	stosw		; interpolated sample 2 (L)
  4562 00001FFC 66AB                    	stosw		; interpolated sample 2 (R)
  4563 00001FFE 89D8                    	mov	eax, ebx
  4564 00002000 6601D0                  	add	ax, dx	; interpolated middle + [next_val]
  4565 00002003 66D1D8                  	rcr	ax, 1
  4566 00002006 50                      	push	eax ; *	; interpolated 3rd quarter (temporary)
  4567 00002007 6601D8                  	add	ax, bx	; + interpolated middle
  4568 0000200A 66D1D8                  	rcr	ax, 1
  4569 0000200D 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4570 00002010 66AB                    	stosw		; interpolated sample 3 (L)
  4571 00002012 66AB                    	stosw		; interpolated sample 3 (R)
  4572 00002014 58                      	pop	eax ; *	
  4573 00002015 6601D0                  	add	ax, dx	; 3rd quarter + [next_val]
  4574 00002018 66D1D8                  	rcr	ax, 1	; / 2
  4575 0000201B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4576 0000201E 66AB                    	stosw		; interpolated sample 4 (L)
  4577 00002020 66AB                    	stosw		; interpolated sample 4 (R)
  4578 00002022 C3                      	retn
  4579                                  
  4580                                  interpolating_5_16bit_stereo:
  4581                                  	; 18/11/2023
  4582                                  	; bx = [previous_val_l]
  4583                                  	; ax = [previous_val_r]
  4584                                  	; [next_val_l]
  4585                                  	; [next_val_r]
  4586                                  	; original-interpltd-interpltd-interpltd-interpltd
  4587 00002023 51                      	push	ecx ; !
  4588 00002024 93                      	xchg	eax, ebx
  4589 00002025 66AB                    	stosw		; original sample (L)
  4590 00002027 93                      	xchg	eax, ebx
  4591 00002028 66AB                    	stosw		; original sample (R)
  4592 0000202A 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4593 0000202D 50                      	push	eax ; *	; [previous_val_r]
  4594 0000202E 80C780                  	add	bh, 80h
  4595 00002031 8005[AD210000]80        	add	byte [next_val_l+1], 80h
  4596 00002038 66A1[AC210000]          	mov	ax, [next_val_l]
  4597 0000203E 6601D8                  	add	ax, bx	; [previous_val_l]
  4598 00002041 66D1D8                  	rcr	ax, 1
  4599 00002044 89C1                    	mov	ecx, eax ; interpolated middle (L)
  4600 00002046 6601D8                  	add	ax, bx	
  4601 00002049 66D1D8                  	rcr	ax, 1
  4602 0000204C 89C2                    	mov	edx, eax ; interpolated 1st quarter (L)
  4603 0000204E 6601D8                  	add	ax, bx	; [previous_val_l]
  4604 00002051 66D1D8                  	rcr	ax, 1
  4605 00002054 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4606 00002057 66AB                    	stosw 		; interpolated sample 1 (L)
  4607 00002059 89C8                    	mov	eax, ecx
  4608 0000205B 6601D0                  	add	ax, dx	; middle (L) + 1st quarter (L)
  4609 0000205E 66D1D8                  	rcr	ax, 1	; / 2
  4610 00002061 89C3                    	mov	ebx, eax  ; interpolated sample 2 (L)
  4611 00002063 5A                      	pop	edx ; *	; [previous_val_r]
  4612 00002064 89D0                    	mov	eax, edx
  4613 00002066 8005[AF210000]80        	add	byte [next_val_r+1], 80h
  4614 0000206D 660305[AE210000]        	add	ax, [next_val_r]
  4615 00002074 66D1D8                  	rcr	ax, 1
  4616 00002077 50                      	push	eax ; *	; interpolated middle (R)
  4617 00002078 6601D0                  	add	ax, dx
  4618 0000207B 66D1D8                  	rcr	ax, 1
  4619 0000207E 50                      	push	eax ; ** ; interpolated 1st quarter (R)
  4620 0000207F 6601D0                  	add	ax, dx	; [previous_val_r]
  4621 00002082 66D1D8                  	rcr	ax, 1
  4622 00002085 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4623 00002088 66AB                    	stosw 		; interpolated sample 1 (R)
  4624 0000208A 89D8                    	mov	eax, ebx
  4625 0000208C 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4626 0000208F 66AB                    	stosw 		; interpolated sample 2 (L)
  4627 00002091 58                      	pop	eax ; **
  4628 00002092 5A                      	pop	edx ; *
  4629 00002093 6601D0                  	add	ax, dx	; 1st quarter (R) + middle (R)
  4630 00002096 66D1D8                  	rcr	ax, 1	; / 2
  4631 00002099 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4632 0000209C 66AB                    	stosw 		; interpolated sample 2 (R)
  4633 0000209E 89C8                    	mov	eax, ecx
  4634 000020A0 660305[AC210000]        	add	ax, [next_val_l]
  4635 000020A7 66D1D8                  	rcr	ax, 1
  4636 000020AA 50                      	push	eax ; * ; interpolated 3rd quarter (L)
  4637 000020AB 6601C8                  	add	ax, cx	; interpolated middle (L)
  4638 000020AE 66D1D8                  	rcr	ax, 1
  4639 000020B1 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4640 000020B4 66AB                    	stosw 		; interpolated sample 3 (L)
  4641 000020B6 89D0                    	mov	eax, edx
  4642 000020B8 660305[AE210000]        	add	ax, [next_val_r]
  4643 000020BF 66D1D8                  	rcr	ax, 1
  4644 000020C2 50                      	push	eax ; ** ; interpolated 3rd quarter (R)
  4645 000020C3 6601D0                  	add	ax, dx	; interpolated middle (R)
  4646 000020C6 66D1D8                  	rcr	ax, 1
  4647 000020C9 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4648 000020CC 66AB                    	stosw 		; interpolated sample 3 (R)
  4649 000020CE 5B                      	pop	ebx ; **
  4650 000020CF 58                      	pop	eax ; *
  4651 000020D0 660305[AC210000]        	add	ax, [next_val_l]
  4652 000020D7 66D1D8                  	rcr	ax, 1
  4653 000020DA 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4654 000020DD 66AB                    	stosw 		; interpolated sample 4 (L)
  4655 000020DF 89D8                    	mov	eax, ebx	
  4656 000020E1 660305[AE210000]        	add	ax, [next_val_r]
  4657 000020E8 66D1D8                  	rcr	ax, 1
  4658 000020EB 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4659 000020EE 66AB                    	stosw 		; interpolated sample 4 (R)
  4660 000020F0 59                      	pop	ecx ; !
  4661 000020F1 C3                      	retn
  4662                                  
  4663                                  interpolating_4_16bit_mono:
  4664                                  	; 18/11/2023
  4665                                  	; ax = [previous_val]
  4666                                  	; dx = [next_val]
  4667                                  	; 02/02/2025
  4668                                  	; original-interpolated-interpolated-interpolated
  4669                                  
  4670 000020F2 66AB                    	stosw		; original sample (L)
  4671 000020F4 66AB                    	stosw		; original sample (R)
  4672 000020F6 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4673 000020F9 89C3                    	mov	ebx, eax ; [previous_val]
  4674 000020FB 80C680                  	add	dh, 80h
  4675 000020FE 6601D0                  	add	ax, dx	; [previous_val] + [next_val]
  4676 00002101 66D1D8                  	rcr	ax, 1
  4677 00002104 93                      	xchg	eax, ebx
  4678 00002105 6601D8                  	add	ax, bx	; [previous_val] + interpolated middle
  4679 00002108 66D1D8                  	rcr	ax, 1
  4680 0000210B 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4681 0000210E 66AB                    	stosw 		; interpolated sample 1 (L)
  4682 00002110 66AB                    	stosw		; interpolated sample 1 (R)
  4683 00002112 89D8                    	mov	eax, ebx ; interpolated middle
  4684 00002114 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4685 00002117 66AB                    	stosw 		; interpolated sample 2 (L)
  4686 00002119 66AB                    	stosw		; interpolated sample 2 (R)
  4687 0000211B 89D8                    	mov	eax, ebx
  4688 0000211D 6601D0                  	add	ax, dx	; interpolated middle + [next_val]
  4689 00002120 66D1D8                  	rcr	ax, 1
  4690 00002123 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4691 00002126 66AB                    	stosw		; interpolated sample 3 (L)
  4692 00002128 66AB                    	stosw		; interpolated sample 3 (R)
  4693 0000212A C3                      	retn
  4694                                  
  4695                                  interpolating_4_16bit_stereo:
  4696                                  	; 18/11/2023
  4697                                  	; bx = [previous_val_l]
  4698                                  	; ax = [previous_val_r]
  4699                                  	; [next_val_l]
  4700                                  	; [next_val_r]
  4701                                  	; original-interpolated-interpolated-interpolated
  4702 0000212B 93                      	xchg	eax, ebx
  4703 0000212C 66AB                    	stosw		; original sample (L)
  4704 0000212E 93                      	xchg	eax, ebx
  4705 0000212F 66AB                    	stosw		; original sample (R)
  4706 00002131 80C480                  	add	ah, 80h ; convert sound level 0 to 65535 format
  4707 00002134 89C2                    	mov	edx, eax ; [previous_val_r]
  4708 00002136 80C780                  	add	bh, 80h
  4709 00002139 8005[AD210000]80        	add	byte [next_val_l+1], 80h
  4710 00002140 66A1[AC210000]          	mov	ax, [next_val_l]
  4711 00002146 6601D8                  	add	ax, bx	; [previous_val_l]
  4712 00002149 66D1D8                  	rcr	ax, 1
  4713 0000214C 93                      	xchg	eax, ebx	
  4714 0000214D 6601D8                  	add	ax, bx	; bx = interpolated middle (L)
  4715 00002150 66D1D8                  	rcr	ax, 1
  4716 00002153 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4717 00002156 66AB                    	stosw 		; interpolated sample 1 (L)
  4718 00002158 8005[AF210000]80        	add	byte [next_val_r+1], 80h
  4719 0000215F 89D0                    	mov	eax, edx ; [previous_val_r]
  4720 00002161 660305[AE210000]        	add	ax, [next_val_r]
  4721 00002168 66D1D8                  	rcr	ax, 1
  4722 0000216B 92                      	xchg	eax, edx	
  4723 0000216C 6601D0                  	add	ax, dx	; dx = interpolated middle (R)
  4724 0000216F 66D1D8                  	rcr	ax, 1
  4725 00002172 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4726 00002175 66AB                    	stosw 		; interpolated sample 1 (R)
  4727 00002177 89D8                    	mov	eax, ebx
  4728 00002179 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4729 0000217C 66AB                    	stosw 		; interpolated sample 2 (L)
  4730 0000217E 89D0                    	mov	eax, edx
  4731 00002180 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4732 00002183 66AB                    	stosw 		; interpolated sample 2 (R)
  4733 00002185 89D8                    	mov	eax, ebx
  4734 00002187 660305[AC210000]        	add	ax, [next_val_l]
  4735 0000218E 66D1D8                  	rcr	ax, 1
  4736 00002191 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4737 00002194 66AB                    	stosw 		; interpolated sample 3 (L)
  4738 00002196 89D0                    	mov	eax, edx
  4739 00002198 660305[AE210000]        	add	ax, [next_val_r]
  4740 0000219F 66D1D8                  	rcr	ax, 1
  4741 000021A2 80EC80                  	sub	ah, 80h	; -32768 to +32767 format again
  4742 000021A5 66AB                    	stosw 		; interpolated sample 3 (R)
  4743 000021A7 C3                      	retn
  4744                                  
  4745                                  ; 13/11/2023
  4746                                  previous_val:
  4747 000021A8 0000                    previous_val_l: dw 0
  4748 000021AA 0000                    previous_val_r: dw 0
  4749                                  next_val:
  4750 000021AC 0000                    next_val_l: dw 0
  4751 000021AE 0000                    next_val_r: dw 0
  4752                                  
  4753                                  ; 16/11/2023
  4754 000021B0 00                      faz:	db 0
  4755                                  	
  4756                                  ; --------------------------------------------------------
  4757                                  ; 27/05/2024 - (TRDOS 386 Kernel) audio.s
  4758                                  ; --------------------------------------------------------
  4759                                  
  4760                                  NOT_PCI32_PCI16	EQU 03FFFFFFFh ; NOT BIT31+BIT30 ; 19/03/2017
  4761                                  NOT_BIT31 EQU 7FFFFFFFh
  4762                                  
  4763                                  pciFindDevice:
  4764                                  	; 19/11/2023
  4765                                  	; 03/04/2017 ('pci.asm', 20/03/2017)
  4766                                  	;
  4767                                  	; scan through PCI space looking for a device+vendor ID
  4768                                  	;
  4769                                  	; Entry: EAX=Device+Vendor ID
  4770                                  	;
  4771                                  	; Exit: EAX=PCI address if device found
  4772                                  	;	EDX=Device+Vendor ID
  4773                                  	;       CY clear if found, set if not found. EAX invalid if CY set.
  4774                                  	;
  4775                                  	; Destroys: ebx, edi ; 19/11/2023
  4776                                  
  4777                                          ; 19/11/2023
  4778 000021B1 89C3                    	mov	ebx, eax
  4779 000021B3 BF00000080              	mov	edi, 80000000h
  4780                                  nextPCIdevice:
  4781 000021B8 89F8                    	mov 	eax, edi		; read PCI registers
  4782 000021BA E88C000000              	call	pciRegRead32
  4783                                  	; 19/11/2023
  4784 000021BF 39DA                    	cmp	edx, ebx
  4785 000021C1 7412                    	je	short PCIScanExit	; found
  4786                                  	; 19/11/2023
  4787 000021C3 81FF00F8FF80            	cmp	edi, 80FFF800h
  4788 000021C9 7308                    	jnb	short pfd_nf		; not found
  4789 000021CB 81C700010000            	add	edi, 100h
  4790 000021D1 EBE5                    	jmp	short nextPCIdevice
  4791                                  pfd_nf:
  4792 000021D3 F9                      	stc
  4793 000021D4 C3                      	retn
  4794                                  PCIScanExit:
  4795                                  	;pushf
  4796 000021D5 B8FFFFFF7F              	mov	eax, NOT_BIT31 	; 19/03/2017
  4797 000021DA 21F8                    	and	eax, edi	; return only bus/dev/fn #
  4798 000021DC C3                      	retn
  4799                                  
  4800                                  pciRegRead:
  4801                                  	; 03/04/2017 ('pci.asm', 20/03/2017)
  4802                                  	;
  4803                                  	; 8/16/32bit PCI reader
  4804                                  	;
  4805                                  	; Entry: EAX=PCI Bus/Device/fn/register number
  4806                                  	;           BIT30 set if 32 bit access requested
  4807                                  	;           BIT29 set if 16 bit access requested
  4808                                  	;           otherwise defaults to 8 bit read
  4809                                  	;
  4810                                  	; Exit:  DL,DX,EDX register data depending on requested read size
  4811                                  	;
  4812                                  	; Note1: this routine is meant to be called via pciRegRead8,
  4813                                  	;	 pciRegread16 or pciRegRead32, listed below.
  4814                                  	;
  4815                                  	; Note2: don't attempt to read 32 bits of data from a non dword
  4816                                  	;	 aligned reg number. Likewise, don't do 16 bit reads from
  4817                                  	;	 non word aligned reg #
  4818                                  	
  4819 000021DD 53                      	push	ebx
  4820 000021DE 51                      	push	ecx
  4821 000021DF 89C3                            mov     ebx, eax		; save eax, dh
  4822 000021E1 88F1                            mov     cl, dh
  4823                                  
  4824 000021E3 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; clear out data size request
  4825 000021E8 0D00000080                      or      eax, BIT31		; make a PCI access request
  4826 000021ED 24FC                            and     al, ~3 ; NOT 3		; force index to be dword
  4827                                  
  4828 000021EF 66BAF80C                        mov     dx, PCI_INDEX_PORT
  4829                                          ;out	dx, eax			; write PCI selector
  4830                                  	; 29/05/2024
  4831 000021F3 53                      	push	ebx
  4832 000021F4 89C3                    	mov	ebx, eax ; data, dword
  4833 000021F6 B405                    	mov	ah, 5 ; write port, dword
  4834                                  	; dx = port number
  4835 000021F8 CD34                    	int	34h
  4836 000021FA 5B                      	pop	ebx
  4837                                  	
  4838 000021FB 66BAFC0C                        mov     dx, PCI_DATA_PORT
  4839 000021FF 88D8                            mov     al, bl
  4840 00002201 2403                            and     al, 3			; figure out which port to
  4841 00002203 00C2                            add     dl, al			; read to
  4842                                  
  4843 00002205 F7C3000000C0            	test    ebx, PCI32+PCI16
  4844 0000220B 750A                            jnz     short _pregr0
  4845                                  
  4846                                  	;in	al, dx			; return 8 bits of data
  4847                                  	; 29/05/2024
  4848 0000220D B400                    	mov	ah, 0 ; read port, byte
  4849                                  	; dx = port number
  4850 0000220F CD34                    	int	34h
  4851                                          
  4852 00002211 88C2                    	mov	dl, al
  4853 00002213 88CE                    	mov     dh, cl			; restore dh for 8 bit read
  4854 00002215 EB17                    	jmp	short _pregr2
  4855                                  _pregr0:	
  4856 00002217 F7C300000080            	test    ebx, PCI32
  4857 0000221D 7509                            jnz	short _pregr1
  4858                                  
  4859                                  	;in	ax, dx
  4860                                  	; 29/05/2024
  4861 0000221F B402                    	mov	ah, 2 ; read port, word
  4862                                  	; dx = port number
  4863 00002221 CD34                    	int	34h	        
  4864                                  
  4865 00002223 6689C2                  	mov     dx, ax			; return 16 bits of data
  4866 00002226 EB06                    	jmp	short _pregr2
  4867                                  _pregr1:
  4868                                  	;in	eax, dx			; return 32 bits of data
  4869                                  	; 29/05/2024
  4870 00002228 B404                    	mov	ah, 4 ; read port, dword
  4871                                  	; dx = port number
  4872 0000222A CD34                    	int	34h
  4873                                  
  4874 0000222C 89C2                    	mov	edx, eax
  4875                                  _pregr2:
  4876 0000222E 89D8                    	mov     eax, ebx		; restore eax
  4877 00002230 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; clear out data size request
  4878 00002235 59                      	pop	ecx
  4879 00002236 5B                      	pop	ebx
  4880 00002237 C3                      	retn
  4881                                  
  4882                                  pciRegRead8:
  4883 00002238 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; set up 8 bit read size
  4884 0000223D EB9E                            jmp     short pciRegRead	; call generic PCI access
  4885                                  
  4886                                  pciRegRead16:
  4887 0000223F 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; set up 16 bit read size
  4888 00002244 0D00000040                      or      eax, PCI16		; call generic PCI access
  4889 00002249 EB92                            jmp     short pciRegRead
  4890                                  
  4891                                  pciRegRead32:
  4892 0000224B 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; set up 32 bit read size
  4893 00002250 0D00000080                      or      eax, PCI32		; call generic PCI access
  4894 00002255 EB86                            jmp     pciRegRead
  4895                                  
  4896                                  pciRegWrite:
  4897                                  	; 03/04/2017 ('pci.asm', 29/11/2016)
  4898                                  	;
  4899                                  	; 8/16/32bit PCI writer
  4900                                  	;
  4901                                  	; Entry: EAX=PCI Bus/Device/fn/register number
  4902                                  	;           BIT31 set if 32 bit access requested
  4903                                  	;           BIT30 set if 16 bit access requested
  4904                                  	;           otherwise defaults to 8bit read
  4905                                  	;        DL/DX/EDX data to write depending on size
  4906                                  	;
  4907                                  	; Note1: this routine is meant to be called via pciRegWrite8, 
  4908                                  	;	 pciRegWrite16 or pciRegWrite32 as detailed below.
  4909                                  	;
  4910                                  	; Note2: don't attempt to write 32bits of data from a non dword
  4911                                  	;	 aligned reg number. Likewise, don't do 16 bit writes from
  4912                                  	;	 non word aligned reg #
  4913                                  
  4914 00002257 53                      	push	ebx
  4915 00002258 51                      	push	ecx
  4916 00002259 89C3                            mov     ebx, eax		; save eax, edx
  4917 0000225B 89D1                            mov     ecx, edx
  4918 0000225D 25FFFFFF3F              	and     eax, NOT_PCI32_PCI16	; clear out data size request
  4919 00002262 0D00000080                      or      eax, BIT31		; make a PCI access request
  4920 00002267 24FC                            and     al, ~3 ; NOT 3		; force index to be dword
  4921                                  
  4922 00002269 66BAF80C                        mov     dx, PCI_INDEX_PORT
  4923                                  	;out	dx, eax			; write PCI selector
  4924                                  	; 29/05/2024
  4925 0000226D 53                      	push	ebx
  4926 0000226E 89C3                    	mov	ebx, eax ; data, dword
  4927 00002270 B405                    	mov	ah, 5 ; write port, dword
  4928                                  	; dx = port number
  4929 00002272 CD34                    	int	34h
  4930 00002274 5B                      	pop	ebx
  4931                                  	
  4932 00002275 66BAFC0C                        mov     dx, PCI_DATA_PORT
  4933 00002279 88D8                            mov     al, bl
  4934 0000227B 2403                            and     al, 3			; figure out which port to
  4935 0000227D 00C2                            add     dl, al			; write to
  4936                                  
  4937 0000227F F7C3000000C0            	test    ebx, PCI32+PCI16
  4938 00002285 7508                            jnz     short _pregw0
  4939 00002287 88C8                    	mov	al, cl 			; put data into al
  4940                                  	;out	dx, al
  4941                                  	; 29/05/2024
  4942                                  	; al = data, byte
  4943 00002289 B401                    	mov	ah, 1 ; write port, byte
  4944                                  	; dx = port number
  4945 0000228B CD34                    	int	34h
  4946                                  
  4947 0000228D EB1F                    	jmp	short _pregw2
  4948                                  _pregw0:
  4949 0000228F F7C300000080            	test    ebx, PCI32
  4950 00002295 750D                            jnz     short _pregw1
  4951 00002297 6689C8                  	mov	ax, cx			; put data into ax
  4952                                  	;out	dx, ax
  4953                                  	; 29/05/2024
  4954 0000229A 53                      	push	ebx
  4955 0000229B 89C3                    	mov	ebx, eax ; data, word
  4956 0000229D B403                    	mov	ah, 3 ; write port, word
  4957                                  	; dx = port number
  4958 0000229F CD34                    	int	34h
  4959 000022A1 5B                      	pop	ebx
  4960                                  
  4961 000022A2 EB0A                    	jmp	short _pregw2
  4962                                  _pregw1:
  4963 000022A4 89C8                    	mov	eax, ecx		; put data into eax
  4964                                  	;out	dx, eax
  4965                                  	; 29/05/2024
  4966 000022A6 53                      	push	ebx
  4967 000022A7 89C3                    	mov	ebx, eax ; data, dword
  4968 000022A9 B405                    	mov	ah, 5 ; write port, dword
  4969                                  	; dx = port number
  4970 000022AB CD34                    	int	34h
  4971 000022AD 5B                      	pop	ebx
  4972                                  _pregw2:
  4973 000022AE 89D8                            mov     eax, ebx		; restore eax
  4974 000022B0 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; clear out data size request
  4975 000022B5 89CA                            mov     edx, ecx		; restore dx
  4976 000022B7 59                      	pop	ecx
  4977 000022B8 5B                      	pop	ebx
  4978 000022B9 C3                      	retn
  4979                                  
  4980                                  pciRegWrite8:
  4981 000022BA 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; set up 8 bit write size
  4982 000022BF EB96                            jmp	short pciRegWrite	; call generic PCI access
  4983                                  
  4984                                  pciRegWrite16:
  4985 000022C1 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; set up 16 bit write size
  4986 000022C6 0D00000040                      or      eax, PCI16		; call generic PCI access
  4987 000022CB EB8A                            jmp	short pciRegWrite
  4988                                  
  4989                                  pciRegWrite32:
  4990 000022CD 25FFFFFF3F                      and     eax, NOT_PCI32_PCI16	; set up 32 bit write size
  4991 000022D2 0D00000080                      or      eax, PCI32		; call generic PCI access
  4992 000022D7 E97BFFFFFF                      jmp	pciRegWrite
  4993                                  
  4994                                  ; --------------------------------------------------------
  4995                                  ; 19/05/2024 - (playwav4.asm) ac97_vra.asm
  4996                                  ; --------------------------------------------------------
  4997                                  
  4998                                  	; 13/11/2023
  4999                                  
  5000                                  ;VRA:	db 1
  5001                                  
  5002                                  codecConfig:
  5003                                  	; 29/05/2024 (playwav7.s modification)
  5004                                  	; 19/05/2024
  5005                                  	; 19/11/2023
  5006                                  	; 15/11/2023
  5007                                  	; 04/11/2023
  5008                                  	; 17/02/2017 
  5009                                  	; 07/11/2016 (Erdogan Tan)
  5010                                  
  5011                                  	;AC97_EA_VRA equ 1
  5012                                  	AC97_EA_VRA equ BIT0
  5013                                  
  5014                                  	; 04/11/2023
  5015                                  init_ac97_controller:
  5016 000022DC A1[3E2A0000]            	mov	eax, [bus_dev_fn]
  5017 000022E1 B004                    	mov	al, PCI_CMD_REG
  5018 000022E3 E857FFFFFF              	call	pciRegRead16		; read PCI command register
  5019 000022E8 80CA05                  	or      dl, IO_ENA+BM_ENA	; enable IO and bus master
  5020 000022EB E8D1FFFFFF              	call	pciRegWrite16
  5021                                  
  5022                                  	;call	delay_100ms
  5023                                  
  5024                                  	; 19/05/2024
  5025                                  	; ('PLAYMOD3.ASM', Erdogan Tan, 18/05/2024)
  5026                                  
  5027                                  init_ac97_codec:
  5028                                  	; 18/11/2023
  5029 000022F0 BD28000000              	mov	ebp, 40
  5030                                  	; 29/05/2024
  5031                                  	;mov	ebp, 1000
  5032                                  _initc_1:
  5033                                  	; 29/05/2024
  5034 000022F5 66BA3000                	mov	dx, GLOB_STS_REG ; 30h
  5035 000022F9 660315[442A0000]        	add	dx, [NABMBAR]
  5036                                  	;in	eax, dx
  5037 00002300 B404                    	mov	ah, 4	; read port, dword
  5038 00002302 CD34                    	int	34h
  5039                                  
  5040                                  	; 19/05/2024
  5041                                  	;call	delay1_4ms
  5042                                  
  5043 00002304 83F8FF                  	cmp	eax, 0FFFFFFFFh ; -1
  5044 00002307 750A                    	jne	short _initc_3
  5045                                  _initc_2:
  5046 00002309 4D                      	dec	ebp
  5047 0000230A 7425                    	jz	short _ac97_codec_ready
  5048                                  
  5049                                  	; 31/05/2024
  5050 0000230C E886020000              	call	delay_100ms
  5051 00002311 EBE2                    	jmp	short _initc_1
  5052                                  _initc_3:
  5053 00002313 A900030010              	test	eax, CTRL_ST_CREADY
  5054 00002318 7517                    	jnz	short _ac97_codec_ready
  5055                                  
  5056                                  	; 30/05/2024
  5057 0000231A 803D[82260000]01        	cmp	byte [reset], 1
  5058 00002321 73E6                    	jnb	short _initc_2
  5059                                  
  5060 00002323 E893010000              	call	reset_ac97_codec
  5061                                  	; 30/05/2024
  5062 00002328 C605[82260000]01        	mov	byte [reset], 1
  5063                                  	; 19/05/2024
  5064 0000232F EBD8                    	jmp	short _initc_2
  5065                                  
  5066                                  _ac97_codec_ready:
  5067 00002331 668B15[422A0000]        	mov	dx, [NAMBAR]
  5068                                  	;add	dx, 0 ; ac_reg_0 ; reset register
  5069                                  	;out	dx, ax
  5070                                  	; 29/05/2024
  5071 00002338 53                      	push	ebx
  5072 00002339 89C3                    	mov	ebx, eax ; bx = data, word
  5073 0000233B B403                    	mov	ah, 3	; write port, word
  5074 0000233D CD34                    	int	34h
  5075 0000233F 5B                      	pop	ebx
  5076                                  
  5077                                  	; 31/05/2024
  5078                                  	; 29/05/2024
  5079                                  	;call	delay_100ms
  5080                                  
  5081                                  	; 19/11/2023
  5082 00002340 09ED                    	or	ebp, ebp
  5083 00002342 7539                    	jnz	short _ac97_codec_init_ok
  5084                                  
  5085 00002344 31C0                    	xor	eax, eax ; 0
  5086 00002346 668B15[422A0000]        	mov	dx, [NAMBAR]
  5087 0000234D 6683C226                	add	dx, CODEC_REG_POWERDOWN
  5088                                  	;out	dx, ax
  5089                                  	; 29/05/2024
  5090 00002351 53                      	push	ebx
  5091 00002352 89C3                    	mov	ebx, eax
  5092 00002354 B403                    	mov	ah, 3	; write port, word
  5093 00002356 CD34                    	int	34h
  5094 00002358 5B                      	pop	ebx
  5095                                  	
  5096                                  	; 19/11/2023
  5097                                  	; wait for 1 second
  5098                                  	; 19/05/2024
  5099 00002359 B9E8030000              	mov	ecx, 1000 ; 1000*4*0.25ms = 1s
  5100                                  	;;mov	ecx, 10
  5101                                  	; 30/05/2024
  5102                                  	;mov	ecx, 40
  5103                                  _ac97_codec_rloop:
  5104                                  	;call	delay_100ms
  5105                                  	; 31/05/2024
  5106 0000235E E843020000              	call	delay1_4ms
  5107                                  
  5108                                  	;mov	dx, [NAMBAR]
  5109                                  	;add	dx, CODEC_REG_POWERDOWN
  5110                                  	;in	ax, dx
  5111                                  	; 29/05/2024
  5112 00002363 668B15[422A0000]        	mov	dx, [NAMBAR]
  5113 0000236A 6683C226                	add	dx, CODEC_REG_POWERDOWN
  5114                                  	; 31/05/2024
  5115 0000236E B402                    	mov	ah, 2	; read port, word
  5116 00002370 CD34                    	int	34h
  5117                                  
  5118                                  	; 31/05/2024
  5119                                  	;call	delay1_4ms
  5120                                  	
  5121 00002372 6683E00F                	and	ax, 0Fh
  5122 00002376 3C0F                    	cmp	al, 0Fh
  5123 00002378 7403                    	je	short _ac97_codec_init_ok
  5124 0000237A E2E2                    	loop	_ac97_codec_rloop 
  5125                                  
  5126                                  init_ac97_codec_err1:
  5127                                  	;stc	; cf = 1 ; 19/05/2024
  5128                                  init_ac97_codec_err2:
  5129 0000237C C3                      	retn
  5130                                  
  5131                                  _ac97_codec_init_ok:
  5132 0000237D E8DA000000              	call 	reset_ac97_controller
  5133                                  
  5134                                  	; 31/05/2024
  5135                                  	; 30/05/2024
  5136                                  	; 19/05/2024
  5137                                  	;call	delay_100ms
  5138                                  
  5139                                  	; 30/05/2024
  5140                                  	;call	delay1_4ms
  5141                                  	;call	delay1_4ms
  5142                                  	;call	delay1_4ms
  5143                                  	;call	delay1_4ms
  5144                                  
  5145                                  setup_ac97_codec:
  5146                                  	; 12/11/2023
  5147 00002382 66813D[C6290000]80-     	cmp	word [sample_rate], 48000
  5147 0000238A BB                 
  5148 0000238B 0F849C000000            	je	skip_rate
  5149                                  	
  5150                                  	; 31/05/2024
  5151                                  	; 30/05/2024
  5152                                  	; 29/05/2024
  5153                                  	;cmp	byte [VRA], 0
  5154                                  	;jna	short skip_rate
  5155                                  
  5156                                  	; 11/11/2023
  5157 00002391 668B15[422A0000]        	mov	dx, [NAMBAR]
  5158 00002398 6683C22A                	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5159                                  	;in	ax, dx
  5160                                  	; 29/05/2024
  5161 0000239C B402                    	mov	ah, 2 ; read port, word
  5162 0000239E CD34                    	int	34h
  5163                                  
  5164                                  	; 30/05/2024
  5165                                  	; 19/05/2024
  5166 000023A0 E801020000              	call	delay1_4ms
  5167                                  
  5168                                  	;and	al, ~BIT1 ; Clear DRA
  5169                                  	;;;
  5170                                  	; 30/05/2024
  5171 000023A5 24FC                    	and	al, ~(BIT1+BIT0) ; Clear DRA+VRA
  5172                                  	;out	dx, ax
  5173                                  	; 31/05/2024
  5174 000023A7 53                      	push	ebx
  5175 000023A8 89C3                    	mov	ebx, eax
  5176 000023AA 668B15[422A0000]        	mov	dx, [NAMBAR]
  5177 000023B1 6683C22A                	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5178 000023B5 B403                    	mov	ah, 3 ; write port, word
  5179 000023B7 CD34                    	int	34h
  5180 000023B9 5B                      	pop	ebx
  5181                                  
  5182                                  	; 31/05/2024
  5183 000023BA E8B1010000              	call	check_vra
  5184                                  
  5185                                  	; 31/05/2024 - temporary (interpolated sample rate test)
  5186                                  	;mov	byte [VRA], 0
  5187                                  
  5188                                  	; 31/05/2024
  5189 000023BF 803D[C9290000]00        	cmp	byte [VRA], 0
  5190 000023C6 7665                    	jna	short skip_rate
  5191                                  
  5192 000023C8 668B15[422A0000]        	mov	dx, [NAMBAR]
  5193 000023CF 6683C22A                	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5194                                  	;in	ax, dx
  5195                                  	; 31/05/2024
  5196 000023D3 B402                    	mov	ah, 2 ; read port, word
  5197 000023D5 CD34                    	int	34h
  5198                                  
  5199                                  	;and	al, ~BIT1 ; Clear DRA
  5200                                  	;;;
  5201                                  
  5202 000023D7 0C01                    	or	al, AC97_EA_VRA ; 1 ; 04/11/2023
  5203                                  	;out	dx, ax			; Enable variable rate audio
  5204                                  	; 29/05/2024
  5205 000023D9 53                      	push	ebx
  5206 000023DA 89C3                    	mov	ebx, eax
  5207                                  	;
  5208                                  	; 30/05/2024
  5209 000023DC 668B15[422A0000]        	mov	dx, [NAMBAR]
  5210 000023E3 6683C22A                	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5211                                  	;
  5212 000023E7 B403                    	mov	ah, 3 ; write port, word
  5213 000023E9 CD34                    	int	34h
  5214 000023EB 5B                      	pop	ebx
  5215                                  
  5216                                  	;mov	cx, 10
  5217 000023EC B90A000000              	mov	ecx, 10 ; 30/05/2024
  5218                                  check_vra_loop:
  5219                                  	; 31/05/2024
  5220                                  	;call	delay_100ms
  5221                                  	; 30/05/2024
  5222 000023F1 E8B0010000              	call	delay1_4ms
  5223                                  
  5224                                  	; 11/11/2023
  5225                                  	;in	ax, dx
  5226                                  	; 29/05/2024
  5227 000023F6 668B15[422A0000]        	mov	dx, [NAMBAR]
  5228 000023FD 6683C22A                	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  5229 00002401 B402                    	mov	ah, 2 ; read port, word
  5230 00002403 CD34                    	int	34h
  5231                                  
  5232 00002405 A801                    	test	al, AC97_EA_VRA ; 1
  5233 00002407 750B                    	jnz	short set_rate
  5234                                  
  5235                                  	; 11/11/2023
  5236 00002409 E2E6                    	loop	check_vra_loop
  5237                                  
  5238                                  ;vra_not_supported:	; 19/05/2024
  5239 0000240B C605[C9290000]00        	mov	byte [VRA], 0
  5240 00002412 EB19                    	jmp	short skip_rate
  5241                                  
  5242                                  set_rate:
  5243 00002414 66A1[C6290000]          	mov	ax, [sample_rate] ; 17/02/2017 (Erdogan Tan)
  5244                                  
  5245 0000241A 668B15[422A0000]        	mov    	dx, [NAMBAR]               	
  5246 00002421 6683C22C                	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch  	  
  5247                                  	;out	dx, ax 			; PCM Front/Center Output Sample Rate
  5248                                  	; 29/05/2024
  5249 00002425 53                      	push	ebx
  5250 00002426 89C3                    	mov	ebx, eax  ; bx = data, word
  5251 00002428 B403                    	mov	ah, 3 ; write port, word
  5252 0000242A CD34                    	int	34h
  5253 0000242C 5B                      	pop	ebx
  5254                                  
  5255                                  	; 29/05/2024
  5256                                  	;call	delay_100ms
  5257                                  	; 30/05/2024
  5258                                  	;call	delay1_4ms
  5259                                  
  5260                                  	; 12/11/2023
  5261                                  skip_rate:
  5262 0000242D 66B80202                	mov	ax, 0202h
  5263 00002431 668B15[422A0000]          	mov	dx, [NAMBAR]
  5264 00002438 6683C202                  	add	dx, CODEC_MASTER_VOL_REG	;02h 
  5265                                  	;out	dx, ax
  5266                                  	; 29/05/2024
  5267 0000243C 53                      	push	ebx
  5268 0000243D 89C3                    	mov	ebx, eax  ; bx = data, word
  5269 0000243F B403                    	mov	ah, 3 ; write port, word
  5270 00002441 CD34                    	int	34h
  5271 00002443 5B                      	pop	ebx
  5272                                  
  5273                                  	; 29/05/2024
  5274                                  	;call	delay1_4ms
  5275                                  	;call	delay1_4ms
  5276                                  	;call	delay1_4ms
  5277                                  	;call	delay1_4ms
  5278                                  
  5279 00002444 66B80202                	mov	ax, 0202h
  5280 00002448 668B15[422A0000]          	mov	dx, [NAMBAR]
  5281 0000244F 6683C218                  	add	dx, CODEC_PCM_OUT_REG		;18h 
  5282                                    	;out	dx, ax
  5283                                  	; 29/05/2024
  5284 00002453 53                      	push	ebx
  5285 00002454 89C3                    	mov	ebx, eax  ; bx = data, word
  5286 00002456 B403                    	mov	ah, 3 ; write port, word
  5287 00002458 CD34                    	int	34h
  5288 0000245A 5B                      	pop	ebx
  5289                                  
  5290                                   	; 29/05/2024
  5291                                  	;call	delay1_4ms
  5292                                  	;call	delay1_4ms
  5293                                  	;call	delay1_4ms
  5294                                  	;call	delay1_4ms
  5295                                  
  5296                                  	; 19/05/2024
  5297                                  	;clc
  5298                                  
  5299 0000245B C3                              retn
  5300                                  
  5301                                  reset_ac97_controller:
  5302                                  	; 29/05/2024 (TRDOS 386)
  5303                                  	; 19/05/2024
  5304                                  	; 11/11/2023
  5305                                  	; 10/06/2017
  5306                                  	; 29/05/2017
  5307                                  	; 28/05/2017
  5308                                  	; reset AC97 audio controller registers
  5309 0000245C 31C0                    	xor	eax, eax
  5310 0000245E 66BA0B00                        mov	dx, PI_CR_REG
  5311 00002462 660315[442A0000]        	add	dx, [NABMBAR]
  5312                                  	;out	dx, al
  5313                                  	; 29/05/2024
  5314                                  	; al = data, byte
  5315 00002469 B401                    	mov	ah, 1 ; write port, byte
  5316 0000246B CD34                    	int	34h
  5317                                  
  5318                                  	; 19/05/2024
  5319                                  	;call	delay1_4ms
  5320                                  
  5321 0000246D 66BA1B00                        mov     dx, PO_CR_REG
  5322 00002471 660315[442A0000]        	add	dx, [NABMBAR]
  5323                                  	;out	dx, al
  5324                                  	; 29/05/2024
  5325                                  	; al = data, byte
  5326 00002478 B401                    	mov	ah, 1 ; write port, byte
  5327 0000247A CD34                    	int	34h
  5328                                  
  5329                                  	; 19/05/2024
  5330                                  	;call	delay1_4ms
  5331                                  
  5332 0000247C 66BA2B00                        mov     dx, MC_CR_REG
  5333 00002480 660315[442A0000]        	add	dx, [NABMBAR]
  5334                                  	;out	dx, al
  5335                                  	; 29/05/2024
  5336                                  	; al = data, byte
  5337 00002487 B401                    	mov	ah, 1 ; write port, byte
  5338 00002489 CD34                    	int	34h
  5339                                  
  5340                                  	; 19/05/2024
  5341                                  	;call	delay1_4ms
  5342                                  
  5343 0000248B B002                            mov	al, RR
  5344 0000248D 66BA0B00                        mov	dx, PI_CR_REG
  5345 00002491 660315[442A0000]        	add	dx, [NABMBAR]
  5346                                  	;out	dx, al
  5347                                  	; 29/05/2024
  5348                                  	; al = data, byte
  5349 00002498 B401                    	mov	ah, 1 ; write port, byte
  5350 0000249A CD34                    	int	34h
  5351                                  
  5352                                  	; 19/05/2024
  5353                                  	;call	delay1_4ms
  5354                                  
  5355 0000249C 66BA1B00                        mov	dx, PO_CR_REG
  5356 000024A0 660315[442A0000]        	add	dx, [NABMBAR]
  5357                                  	;out	dx, al
  5358                                  	; 29/05/2024
  5359                                  	; al = data, byte
  5360 000024A7 B401                    	mov	ah, 1 ; write port, byte
  5361 000024A9 CD34                    	int	34h
  5362                                  
  5363                                  	; 19/05/2024
  5364                                  	;call	delay1_4ms
  5365                                  
  5366 000024AB 66BA2B00                        mov	dx, MC_CR_REG
  5367 000024AF 660315[442A0000]        	add	dx, [NABMBAR]
  5368                                  	;out	dx, al
  5369                                  	; 29/05/2024
  5370                                  	; al = data, byte
  5371 000024B6 B401                    	mov	ah, 1 ; write port, byte
  5372 000024B8 CD34                    	int	34h
  5373                                  
  5374                                  	; 19/05/2024
  5375                                  	;call	delay1_4ms
  5376                                  
  5377 000024BA C3                      	retn
  5378                                  
  5379                                  reset_ac97_codec:
  5380                                  	; 29/05/2024 (TRDOS 386)
  5381                                  	; 11/11/2023
  5382                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  5383 000024BB 66BA2C00                	mov	dx, GLOB_CNT_REG ; 2Ch
  5384 000024BF 660315[442A0000]        	add	dx, [NABMBAR]
  5385                                  	;in	eax, dx
  5386                                  	; 29/05/2024
  5387 000024C6 B404                    	mov	ah, 4 ; read port, dword
  5388 000024C8 CD34                    	int	34h
  5389                                  
  5390                                  	;test	eax, 2
  5391                                  	; 06/08/2022
  5392 000024CA A802                    	test	al, 2
  5393 000024CC 7407                    	jz	short _r_ac97codec_cold	
  5394                                  
  5395 000024CE E80F000000              	call	warm_ac97codec_reset
  5396 000024D3 7308                    	jnc	short _r_ac97codec_ok
  5397                                  _r_ac97codec_cold:
  5398 000024D5 E845000000                      call	cold_ac97codec_reset
  5399 000024DA 7301                            jnc	short _r_ac97codec_ok
  5400                                  	
  5401                                  	; 16/04/2017
  5402                                          ;xor	eax, eax	; timeout error
  5403                                         	;stc
  5404 000024DC C3                      	retn
  5405                                  
  5406                                  _r_ac97codec_ok:
  5407 000024DD 31C0                            xor     eax, eax
  5408                                          ;mov	al, VIA_ACLINK_C00_READY ; 1
  5409 000024DF FEC0                            inc	al
  5410 000024E1 C3                      	retn
  5411                                  
  5412                                  warm_ac97codec_reset:
  5413                                  	; 29/05/2024 (TRDOS 386)
  5414                                  	; 11/11/2023
  5415                                  	; 06/08/2022 - TRDOS 386 v2.0.5
  5416                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  5417 000024E2 B806000000              	mov	eax, 6
  5418 000024E7 66BA2C00                	mov	dx, GLOB_CNT_REG ; 2Ch
  5419 000024EB 660315[442A0000]        	add	dx, [NABMBAR]
  5420                                  	;out	dx, eax
  5421                                  	; 29/05/2024
  5422 000024F2 53                      	push	ebx
  5423 000024F3 89C3                    	mov	ebx, eax  ; ebx = data, dword
  5424 000024F5 B405                    	mov	ah, 5 ; write port, dword
  5425 000024F7 CD34                    	int	34h
  5426 000024F9 5B                      	pop	ebx
  5427                                  
  5428                                  	; 30/05/2024
  5429 000024FA B90A000000              	mov	ecx, 10	; total 1s
  5430                                  	; 29/05/2024
  5431                                  	;mov	ecx, 4000
  5432                                  _warm_ac97c_rst_wait:
  5433                                  	; 30/05/2024
  5434 000024FF E893000000              	call	delay_100ms
  5435                                  
  5436 00002504 66BA3000                	mov	dx, GLOB_STS_REG ; 30h
  5437 00002508 660315[442A0000]        	add	dx, [NABMBAR]
  5438                                  	;in	eax, dx
  5439                                  	; 29/05/2024
  5440 0000250F B404                    	mov	ah, 4 ; read port, dword
  5441 00002511 CD34                    	int	34h
  5442                                  
  5443 00002513 A900030010              	test	eax, CTRL_ST_CREADY
  5444 00002518 7504                    	jnz	short _warm_ac97c_rst_ok
  5445                                  
  5446 0000251A 49                      	dec	ecx
  5447 0000251B 75E2                    	jnz	short _warm_ac97c_rst_wait
  5448                                  
  5449                                  _warm_ac97c_rst_fail:
  5450 0000251D F9                              stc
  5451                                  _warm_ac97c_rst_ok:
  5452 0000251E C3                      	retn
  5453                                  
  5454                                  cold_ac97codec_reset:
  5455                                  	; 11/11/2023
  5456                                  	; 06/08/2022 - TRDOS 386 v2.0.5
  5457                                  	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  5458 0000251F B802000000                      mov	eax, 2
  5459 00002524 66BA2C00                	mov	dx, GLOB_CNT_REG ; 2Ch
  5460 00002528 660315[442A0000]        	add	dx, [NABMBAR]
  5461                                  	;out	dx, eax
  5462                                  	; 29/05/2024
  5463 0000252F 53                      	push	ebx
  5464 00002530 89C3                    	mov	ebx, eax  ; ebx = data, dword
  5465 00002532 B405                    	mov	ah, 5 ; write port, dword
  5466 00002534 CD34                    	int	34h
  5467 00002536 5B                      	pop	ebx
  5468                                  
  5469                                  	; 30/05/2024
  5470 00002537 E85B000000              	call	delay_100ms 	; wait 100 ms
  5471 0000253C E856000000              	call	delay_100ms 	; wait 100 ms
  5472 00002541 E851000000              	call	delay_100ms 	; wait 100 ms
  5473 00002546 E84C000000              	call	delay_100ms 	; wait 100 ms
  5474                                  
  5475                                  	; 30/05/2024
  5476 0000254B B910000000              	mov	ecx, 16	; total 20*100 ms = 2s
  5477                                  	; 29/05/2024
  5478                                  	;mov	ecx, 16000
  5479                                  _cold_ac97c_rst_wait:
  5480 00002550 66BA3000                	mov	dx, GLOB_STS_REG ; 30h
  5481 00002554 660315[442A0000]        	add	dx, [NABMBAR]
  5482                                  	;in	eax, dx
  5483                                  	; 29/05/2024
  5484 0000255B B404                    	mov	ah, 4 ; read port, dword
  5485 0000255D CD34                    	int	34h
  5486                                  
  5487 0000255F A900030010              	test	eax, CTRL_ST_CREADY
  5488 00002564 7509                    	jnz	short _cold_ac97c_rst_ok
  5489                                  
  5490                                  	; 30/05/2024
  5491                                  	; 29/05/2024
  5492 00002566 E82C000000              	call	delay_100ms
  5493                                  
  5494 0000256B 49                      	dec	ecx
  5495 0000256C 75E2                    	jnz	short _cold_ac97c_rst_wait
  5496                                  
  5497                                  _cold_ac97c_rst_fail:
  5498 0000256E F9                              stc
  5499                                  _cold_ac97c_rst_ok:
  5500 0000256F C3                      	retn
  5501                                  
  5502                                  ; 30/05/2024
  5503                                  %if 1
  5504                                  check_vra:
  5505                                  	; 29/05/2024
  5506 00002570 C605[C9290000]01        	mov	byte [VRA], 1
  5507                                  
  5508                                  	; 29/05/2024 - audio.s (TRDOS 386 Kernel) - 27/05/2024
  5509                                  	; 24/05/2024
  5510                                  	; 23/05/2024
  5511 00002577 668B15[422A0000]        	mov	dx, [NAMBAR]
  5512 0000257E 6683C228                	add	dx, CODEC_EXT_AUDIO_REG	; 28h
  5513                                  	;in	ax, dx
  5514                                  	; 29/05/2024
  5515 00002582 B402                    	mov	ah, 2 ; read port, word
  5516 00002584 CD34                    	int	34h
  5517                                  
  5518                                  	; 30/05/2024
  5519                                  	; 23/05/2024
  5520 00002586 E81B000000              	call	delay1_4ms
  5521                                  
  5522                                  	; 29/05/2024
  5523 0000258B A801                    	test	al, BIT0
  5524                                  	;test	al, 1 ; BIT0 ; Variable Rate Audio bit
  5525 0000258D 7507                    	jnz	short check_vra_ok
  5526                                  
  5527                                  vra_not_supported:
  5528                                  	; 13/11/2023
  5529 0000258F C605[C9290000]00        	mov	byte [VRA], 0
  5530                                  check_vra_ok:
  5531 00002596 C3                      	retn
  5532                                  %endif
  5533                                  
  5534                                  ; --------------------------------------------------------
  5535                                  
  5536                                  PORTB		EQU 061h
  5537                                  REFRESH_STATUS	EQU 010h	; Refresh signal status
  5538                                  
  5539                                  delay_100ms:
  5540 00002597 51                      	push	ecx
  5541 00002598 B990010000              	mov	ecx, 400  ; 400*0.25ms
  5542                                  _delay_x_ms:
  5543 0000259D E804000000              	call	delay1_4ms
  5544 000025A2 E2F9                            loop	_delay_x_ms
  5545 000025A4 59                      	pop	ecx
  5546 000025A5 C3                      	retn
  5547                                  
  5548                                  delay1_4ms:
  5549                                  	; 30/05/2024 (TRDOS 386)
  5550 000025A6 50                              push    eax 
  5551 000025A7 51                              push    ecx
  5552 000025A8 53                      	push	ebx
  5553 000025A9 52                      	push	edx
  5554 000025AA B910000000                      mov     ecx, 16			; close enough.
  5555                                  	;in	al, PORTB
  5556                                  	; 30/05/2024
  5557 000025AF 66BA6100                	mov	dx, PORTB
  5558 000025B3 B400                    	mov	ah, 0  ; read port, byte
  5559 000025B5 CD34                    	int	34h
  5560                                  
  5561 000025B7 2410                    	and	al, REFRESH_STATUS
  5562                                  	;mov	ah, al			; Start toggle state
  5563 000025B9 88C3                    	mov	bl, al
  5564 000025BB 09C9                    	or	ecx, ecx
  5565 000025BD 7401                    	jz	short _d4ms1
  5566 000025BF 41                      	inc	ecx			; Throwaway first toggle
  5567                                  _d4ms1:	
  5568                                  	;in	al, PORTB		; Read system control port
  5569                                  	; 30/05/2024
  5570 000025C0 66BA6100                	mov	dx, PORTB
  5571 000025C4 B400                    	mov	ah, 0  ; read port, byte
  5572 000025C6 CD34                    	int	34h
  5573                                  
  5574 000025C8 2410                    	and	al, REFRESH_STATUS	; Refresh toggles 15.085 microseconds
  5575                                  	;cmp	ah, al
  5576 000025CA 38C3                    	cmp	bl, al
  5577 000025CC 74F2                    	je	short _d4ms1		; Wait for state change
  5578                                  
  5579                                  	;mov	ah, al			; Update with new state
  5580 000025CE 88C3                    	mov	bl, al
  5581 000025D0 49                      	dec	ecx
  5582 000025D1 75ED                    	jnz	short _d4ms1
  5583                                  
  5584 000025D3 5A                      	pop	edx
  5585 000025D4 5B                              pop	ebx
  5586 000025D5 59                      	pop	ecx
  5587 000025D6 58                              pop	eax
  5588 000025D7 C3                              retn
  5589                                  
  5590                                  ; --------------------------------------------------------
  5591                                  ; 19/05/2024 - (playwav4.asm) ich_wav4.asm
  5592                                  ; --------------------------------------------------------
  5593                                  
  5594                                  check4keyboardstop:
  5595                                  	; 29/05/2024 (TRDOS 386)
  5596                                  	; 19/05/2024
  5597                                  	; 08/11/2023
  5598                                  	; 06/11/2023
  5599                                  	; 04/11/2023
  5600 000025D8 B401                    	mov	ah, 1
  5601                                  	;int	16h
  5602 000025DA CD32                    	int	32h	; TRDOS 386
  5603                                  	;clc
  5604 000025DC 743E                    	jz	short _cksr
  5605                                  
  5606 000025DE 30E4                    	xor	ah, ah
  5607                                  	;int	16h
  5608 000025E0 CD32                    	int	32h	; TRDOS 386
  5609                                  
  5610                                  	;;;
  5611                                  	; 19/05/2024 (change PCM out volume)
  5612 000025E2 3C2B                    	cmp	al, '+'
  5613 000025E4 750D                    	jne	short p_1
  5614                                  	
  5615 000025E6 A0[7D260000]            	mov	al, [volume]
  5616 000025EB 3C00                    	cmp	al, 0
  5617 000025ED 762E                    	jna	short p_3
  5618 000025EF FEC8                    	dec	al
  5619 000025F1 EB0F                    	jmp	short p_2
  5620                                  p_1:
  5621 000025F3 3C2D                    	cmp	al, '-'
  5622 000025F5 7527                    	jne	short p_4
  5623                                  
  5624 000025F7 A0[7D260000]            	mov	al, [volume]
  5625 000025FC 3C1F                    	cmp	al, 31
  5626 000025FE 731D                    	jnb	short p_3
  5627 00002600 FEC0                    	inc	al
  5628                                  p_2:
  5629 00002602 A2[7D260000]            	mov	[volume], al
  5630 00002607 88C4                    	mov	ah, al
  5631 00002609 668B15[422A0000]        	mov     dx, [NAMBAR]
  5632                                    	;add    dx, CODEC_MASTER_VOL_REG
  5633 00002610 6683C218                	add	dx, CODEC_PCM_OUT_REG
  5634                                  	;out	dx, ax
  5635                                  	; 29/05/2024
  5636 00002614 53                      	push	ebx
  5637 00002615 89C3                    	mov	ebx, eax ; bx = data, word
  5638 00002617 B403                    	mov	ah, 3 ; write port, word
  5639 00002619 CD34                    	int	34h
  5640 0000261B 5B                      	pop	ebx
  5641                                  
  5642                                  	;call	delay1_4ms
  5643                                          ;call	delay1_4ms
  5644                                          ;call	delay1_4ms
  5645                                          ;call	delay1_4ms
  5646                                  _cksr:		; 19/05/2024
  5647 0000261C F8                      	clc
  5648                                  p_3:
  5649 0000261D C3                      	retn
  5650                                  p_4:
  5651                                  	;;;
  5652                                  ;_cskr:	
  5653 0000261E F9                      	stc
  5654 0000261F C3                      	retn
  5655                                  
  5656                                  ; returns AL = current index value
  5657                                  getCurrentIndex:
  5658                                  	; 29/05/2024 (TRDOS 386)
  5659                                  	; 08/11/2023
  5660 00002620 668B15[442A0000]        	mov	dx, [NABMBAR]
  5661 00002627 6683C214                	add	dx, PO_CIV_REG
  5662                                  	;in	al, dx
  5663                                  	; 29/05/2024
  5664 0000262B B400                    	mov	ah, 0 ; read port, byte
  5665 0000262D CD34                    	int	34h
  5666                                  uLVI2:	;	06/11/2023
  5667 0000262F C3                      	retn
  5668                                  
  5669                                  updateLVI:
  5670                                  	; 29/05/2024 (TRDOS 386)
  5671                                  	; 08/11/2023
  5672                                  	; 07/11/2023
  5673                                  	; 06/11/2023
  5674 00002630 668B15[442A0000]        	mov	dx, [NABMBAR]
  5675 00002637 6683C214                	add	dx, PO_CIV_REG
  5676                                  	; (Current Index Value and Last Valid Index value)
  5677                                  	;in	ax, dx
  5678                                  	; 29/05/2024
  5679 0000263B B402                    	mov	ah, 2 ; read port, word
  5680 0000263D CD34                    	int	34h
  5681                                  
  5682 0000263F 38E0                    	cmp	al, ah ; is current index = last index ?
  5683 00002641 75EC                    	jne	short uLVI2
  5684                                  
  5685                                  	; 08/11/2023	
  5686 00002643 E8D8FFFFFF              	call	getCurrentIndex
  5687                                   
  5688 00002648 F605[C8290000]01        	test	byte [flags], ENDOFFILE
  5689                                  	;jnz	short uLVI1
  5690 0000264F 7418                    	jz	short uLVI0  ; 08/11/2023
  5691                                  
  5692                                  	; 08/11/2023
  5693 00002651 50                      	push	eax	; 29/05/2024 (32 bit)
  5694 00002652 668B15[442A0000]        	mov	dx, [NABMBAR]
  5695 00002659 6683C216                	add	dx, PO_SR_REG  ; PCM out status register
  5696                                  	;in	ax, dx
  5697                                  	; 29/05/2024
  5698 0000265D B402                    	mov	ah, 2 ; read port, word
  5699 0000265F CD34                    	int	34h
  5700                                  
  5701 00002661 A803                    	test	al, 3 ; bit 1 = Current Equals Last Valid (CELV)
  5702                                  		      ; (has been processed)
  5703                                  		      ; bit 0 = 1 -> DMA Controller Halted (DCH)
  5704 00002663 58                      	pop	eax
  5705 00002664 7407                    	jz	short uLVI1
  5706                                  uLVI3:
  5707 00002666 31C0                    	xor	eax, eax
  5708                                  	; zf = 1
  5709 00002668 C3                      	retn
  5710                                  uLVI0:
  5711                                          ; not at the end of the file yet.
  5712 00002669 FEC8                    	dec	al
  5713 0000266B 241F                    	and	al, 1Fh
  5714                                  uLVI1:
  5715                                  	;call	setLastValidIndex
  5716                                  ;uLVI2:
  5717                                  	;retn
  5718                                  
  5719                                  ;input AL = index # to stop on
  5720                                  setLastValidIndex:
  5721                                  	; 29/05/2024 (TRDOS 386)
  5722                                  	; 08/11/2023
  5723 0000266D 668B15[442A0000]        	mov	dx, [NABMBAR]
  5724 00002674 6683C215                	add	dx, PO_LVI_REG
  5725                                          ;out	dx, al
  5726                                  	; 29/05/2024
  5727                                  	; al = data, byte
  5728 00002678 B401                    	mov	ah, 1 ; write port, byte
  5729 0000267A CD34                    	int	34h
  5730 0000267C C3                      	retn
  5731                                  
  5732                                  ; 29/05/2024
  5733                                  ; 19/05/2024
  5734 0000267D 02                      volume: db	02h
  5735                                  	
  5736                                  ; --------------------------------------------------------
  5737                                  
  5738                                  ; DATA
  5739                                  
  5740                                  FileHandle:	
  5741 0000267E FFFFFFFF                	dd	-1
  5742                                  
  5743                                  ; 30/05/2024
  5744 00002682 00                      reset:	db	0
  5745                                  
  5746                                  Credits:
  5747 00002683 54696E792057415620-     	db	'Tiny WAV Player for TRDOS 386 by Erdogan Tan. '
  5747 0000268C 506C6179657220666F-
  5747 00002695 72205452444F532033-
  5747 0000269E 383620627920457264-
  5747 000026A7 6F67616E2054616E2E-
  5747 000026B0 20                 
  5748                                  	;;;;db	'August 2020.',10,13,0
  5749                                  	;;;db	'May 2024.',10,13,0
  5750                                  	;;db	'December 2024.', 10,13,0
  5751                                  	;db	'January 2025.', 10,13,0
  5752 000026B1 466562727561727920-     	db	'February 2025.', 10,13,0
  5752 000026BA 323032352E0A0D00   
  5753 000026C2 31372F30362F323031-     	db	'17/06/2017', 10,13,0
  5753 000026CB 370A0D00           
  5754 000026CF 31382F30382F323032-     	db	'18/08/2020', 10,13,0
  5754 000026D8 300A0D00           
  5755 000026DC 32372F31312F323032-     	db	'27/11/2023', 10,13,0
  5755 000026E5 330A0D00           
  5756 000026E9 32392F30352F323032-     	db	'29/05/2024', 10,13,0
  5756 000026F2 340A0D00           
  5757 000026F6 31342F31322F323032-     	db	'14/12/2024', 10,13,0
  5757 000026FF 340A0D00           
  5758 00002703 31372F30312F323032-     	db	'17/01/2025', 10,13,0
  5758 0000270C 350A0D00           
  5759 00002710 30322F30322F323032-     	db	'02/02/2025', 10,13,0
  5759 00002719 350A0D00           
  5760                                  
  5761                                  msgAudioCardInfo:
  5762 0000271D 666F7220496E74656C-     	db 	'for Intel AC97 (ICH) Audio Controller.', 10,13,0
  5762 00002726 204143393720284943-
  5762 0000272F 482920417564696F20-
  5762 00002738 436F6E74726F6C6C65-
  5762 00002741 722E0A0D00         
  5763                                  
  5764                                  msg_usage:
  5765 00002746 75736167653A20706C-     	db	'usage: playwav7 filename.wav',10,13,0 ; 29/05/2024
  5765 0000274F 617977617637206669-
  5765 00002758 6C656E616D652E7761-
  5765 00002761 760A0D00           
  5766                                  
  5767                                  noDevMsg:
  5768 00002765 4572726F723A20556E-     	db	'Error: Unable to find AC97 audio device!'
  5768 0000276E 61626C6520746F2066-
  5768 00002777 696E64204143393720-
  5768 00002780 617564696F20646576-
  5768 00002789 69636521           
  5769 0000278D 0A0D00                  	db	10,13,0
  5770                                  
  5771                                  noFileErrMsg:
  5772 00002790 4572726F723A206669-     	db	'Error: file not found.',10,13,0
  5772 00002799 6C65206E6F7420666F-
  5772 000027A2 756E642E0A0D00     
  5773                                  
  5774                                  msg_error:	; 29/05/2024
  5775                                  trdos386_err_msg:
  5776 000027A9 5452444F5320333836-     	db	'TRDOS 386 System call error !',10,13,0
  5776 000027B2 2053797374656D2063-
  5776 000027BB 616C6C206572726F72-
  5776 000027C4 20210A0D00         
  5777                                  
  5778                                  ; 29/05/2024
  5779                                  ; 11/11/2023
  5780                                  msg_init_err:
  5781 000027C9 0A0D                    	db	10,13
  5782 000027CB 4143393720436F6E74-     	db	"AC97 Controller/Codec initialization error !"
  5782 000027D4 726F6C6C65722F436F-
  5782 000027DD 64656320696E697469-
  5782 000027E6 616C697A6174696F6E-
  5782 000027EF 206572726F722021   
  5783 000027F7 0A0D00                  	db	10,13,0 ; 01/06/2024
  5784                                  
  5785                                  ; 25/11/2023
  5786                                  msg_no_vra:
  5787 000027FA 0A0D                    	db	10,13
  5788 000027FC 4E6F20565241207375-     	db	"No VRA support ! Only 48 kHZ sample rate supported !"
  5788 00002805 70706F72742021204F-
  5788 0000280E 6E6C79203438206B48-
  5788 00002817 5A2073616D706C6520-
  5788 00002820 726174652073757070-
  5788 00002829 6F727465642021     
  5789 00002830 0A0D00                  	db	10,13,0
  5790                                  
  5791                                  ; 29/05/2024 (TRDOS 386)
  5792                                  ; 17/02/2017
  5793                                  ; Valid ICH device IDs
  5794                                  
  5795                                  valid_ids:
  5796 00002833 86801524                dd	(ICH_DID << 16) + INTEL_VID  	 ; 8086h:2415h
  5797 00002837 86802524                dd	(ICH0_DID << 16) + INTEL_VID 	 ; 8086h:2425h
  5798 0000283B 86804524                dd	(ICH2_DID << 16) + INTEL_VID 	 ; 8086h:2445h
  5799 0000283F 86808524                dd	(ICH3_DID << 16) + INTEL_VID 	 ; 8086h:2485h
  5800 00002843 8680C524                dd	(ICH4_DID << 16) + INTEL_VID 	 ; 8086h:24C5h
  5801 00002847 8680D524                dd	(ICH5_DID << 16) + INTEL_VID 	 ; 8086h:24D5h
  5802 0000284B 86806E26                dd	(ICH6_DID << 16) + INTEL_VID 	 ; 8086h:266Eh
  5803 0000284F 8680A625                dd	(ESB6300_DID << 16) + INTEL_VID  ; 8086h:25A6h
  5804 00002853 86809826                dd	(ESB631X_DID << 16) + INTEL_VID  ; 8086h:2698h
  5805 00002857 8680DE27                dd	(ICH7_DID << 16) + INTEL_VID 	 ; 8086h:27DEh
  5806                                  ; 03/11/2023 - Erdogan Tan
  5807 0000285B 86809571                dd	(MX82440_DID << 16) + INTEL_VID  ; 8086h:7195h
  5808 0000285F 39101270                dd	(SI7012_DID << 16)  + SIS_VID	 ; 1039h:7012h
  5809 00002863 DE10B101                dd 	(NFORCE_DID << 16)  + NVIDIA_VID ; 10DEh:01B1h
  5810 00002867 DE106A00                dd 	(NFORCE2_DID << 16) + NVIDIA_VID ; 10DEh:006Ah
  5811 0000286B 22106D74                dd 	(AMD8111_DID << 16) + AMD_VID 	 ; 1022h:746Dh
  5812 0000286F 22104574                dd 	(AMD768_DID << 16)  + AMD_VID 	 ; 1022h:7445h
  5813 00002873 DE105900                dd 	(CK804_DID << 16) + NVIDIA_VID	 ; 10DEh:0059h
  5814 00002877 DE103A00                dd 	(MCP04_DID << 16) + NVIDIA_VID	 ; 10DEh:003Ah
  5815 0000287B DE108A00                dd 	(CK8_DID << 16) + NVIDIA_VID	 ; 1022h:008Ah
  5816 0000287F DE10DA00                dd 	(NFORCE3_DID << 16) + NVIDIA_VID ; 10DEh:00DAh
  5817 00002883 DE10EA00                dd 	(CK8S_DID << 16) + NVIDIA_VID	 ; 10DEh:00EAh
  5818                                  
  5819                                  valid_id_count:	equ ($ - valid_ids)>>2 ; 05/11/2023
  5820                                  
  5821 00002887 0D0A5741562046696C-     msgWavFileName:	db 0Dh, 0Ah, "WAV File Name: ",0
  5821 00002890 65204E616D653A2000 
  5822 00002899 0D0A53616D706C6520-     msgSampleRate:	db 0Dh, 0Ah, "Sample Rate: "
  5822 000028A2 526174653A20       
  5823 000028A8 303030303020487A2C-     msgHertz:	db "00000 Hz, ", 0 
  5823 000028B1 2000               
  5824 000028B3 3820626974732C2000      msg8Bits:	db "8 bits, ", 0 
  5825 000028BC 4D6F6E6F0D0A00          msgMono:	db "Mono", 0Dh, 0Ah, 0
  5826 000028C3 313620626974732C20-     msg16Bits:	db "16 bits, ", 0 
  5826 000028CC 00                 
  5827 000028CD 53746572656F            msgStereo:	db "Stereo"
  5828 000028D3 0D0A00                  nextline:	db 0Dh, 0Ah, 0
  5829                                  
  5830                                  ; 03/06/2017
  5831 000028D6 303132333435363738-     hex_chars	db "0123456789ABCDEF", 0
  5831 000028DF 3941424344454600   
  5832 000028E7 0D0A                    msgAC97Info	db 0Dh, 0Ah
  5833 000028E9 414339372041756469-     		db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah 
  5833 000028F2 6F20436F6E74726F6C-
  5833 000028FB 6C6572202620436F64-
  5833 00002904 656320496E666F0D0A 
  5834 0000290D 56656E646F72204944-     		db "Vendor ID: "
  5834 00002916 3A20               
  5835 00002918 303030306820446576-     msgVendorId	db "0000h Device ID: "
  5835 00002921 6963652049443A20   
  5836 00002929 30303030680D0A          msgDevId	db "0000h", 0Dh, 0Ah
  5837 00002930 4275733A20              		db "Bus: "
  5838 00002935 303068204465766963-     msgBusNo	db "00h Device: "
  5838 0000293E 653A20             
  5839 00002941 3030682046756E6374-     msgDevNo	db "00h Function: "
  5839 0000294A 696F6E3A20         
  5840 0000294F 303068                  msgFncNo	db "00h"
  5841 00002952 0D0A                    		db 0Dh, 0Ah
  5842 00002954 4E414D4241523A20        		db "NAMBAR: "
  5843 0000295C 30303030682020          msgNamBar	db "0000h  "
  5844 00002963 4E41424D4241523A20      		db "NABMBAR: "
  5845 0000296C 303030306820204952-     msgNabmBar	db "0000h  IRQ: "
  5845 00002975 513A20             
  5846 00002978 3030                    msgIRQ		dw 3030h
  5847 0000297A 0D0A00                  		db 0Dh, 0Ah, 0
  5848                                  ; 25/11/2023
  5849 0000297D 56524120737570706F-     msgVRAheader:	db "VRA support: "
  5849 00002986 72743A20           
  5850 0000298A 00                      		db 0	
  5851 0000298B 5945530D0A00            msgVRAyes:	db "YES", 0Dh, 0Ah, 0
  5852 00002991 4E4F200D0A              msgVRAno:	db "NO ", 0Dh, 0Ah
  5853 00002996 28496E746572706F6C-     		db "(Interpolated sample rate playing method)"
  5853 0000299F 617465642073616D70-
  5853 000029A8 6C6520726174652070-
  5853 000029B1 6C6179696E67206D65-
  5853 000029BA 74686F6429         
  5854 000029BF 0D0A00                  		db 0Dh, 0Ah, 0
  5855                                  EOF: 
  5856                                  
  5857                                  ; BSS
  5858                                  
  5859                                  bss_start:
  5860                                  
  5861                                  ABSOLUTE bss_start
  5862                                  
  5863 000029C2 ????                    alignb 4
  5864                                  
  5865 000029C4 ??                      stmo:		resb 1 ; stereo or mono (1=stereo) 
  5866 000029C5 ??                      bps:		resb 1 ; bits per sample (8,16)
  5867 000029C6 ????                    sample_rate:	resw 1 ; Sample Frequency (Hz)
  5868                                  
  5869                                  ; 31/05/2024
  5870                                  ; 25/11/2023
  5871                                  ;bufferSize:	resd 1
  5872                                  
  5873 000029C8 ??                      flags:		resb 1
  5874                                  
  5875                                  ; 29/05/2024
  5876                                  ;;cbs_busy:	resb 1
  5877                                  ;half_buff:	resb 1
  5878                                  ;srb:		resb 1
  5879                                  
  5880                                  ; 30/05/2024
  5881                                  ; 18/08/2020
  5882                                  ;volume_level:	resb 1
  5883                                  ; 25/11/2023
  5884 000029C9 ??                      VRA:		resb 1	; Variable Rate Audio Support Status
  5885                                  
  5886 000029CA <res 1Ch>               smpRBuff:	resw 14 
  5887                                  
  5888                                  wav_file_name:
  5889 000029E6 <res 50h>               		resb 80 ; wave file, path name (<= 80 bytes)
  5890                                  
  5891 00002A36 ????                    		resw 1
  5892 00002A38 ??                      ac97_int_ln_reg: resb 1
  5893 00002A39 ??                      fbs_shift:	resb 1 ; 26/11/2023
  5894 00002A3A ????????                dev_vendor:	resd 1
  5895 00002A3E ????????                bus_dev_fn:	resd 1
  5896                                  ;ac97_NamBar:	resw 1
  5897                                  ;ac97_NabmBar:	resw 1
  5898                                  
  5899                                  ; 29/05/2024
  5900                                  ; 17/02/2017
  5901                                  ; NAMBAR:  Native Audio Mixer Base Address Register
  5902                                  ;    (ICH, Audio D31:F5, PCI Config Space) Address offset: 10h-13h
  5903                                  ; NABMBAR: Native Audio Bus Mastering Base Address register
  5904                                  ;    (ICH, Audio D31:F5, PCI Config Space) Address offset: 14h-17h
  5905 00002A42 ????                    NAMBAR:		resw 1			; BAR for mixer
  5906 00002A44 ????                    NABMBAR:	resw 1			; BAR for bus master regs
  5907                                  
  5908                                  ; 29/05/2024
  5909 00002A46 ????????                audio_buffer:	resd 1
  5910                                  ; 29/05/2024
  5911 00002A4A ????????                _bdl_buffer:	resd 1
  5912                                  ;wav_buffer1:	resd 1
  5913                                  ;wav_buffer2:	resd 1
  5914                                  
  5915                                  bss_end:
  5916                                  
  5917 00002A4E <res 5B2h>              alignb 4096
  5918                                  		; 256 byte buffer for descriptor list
  5919 00003000 <res 100h>              BDL_BUFFER:	resb 256
  5920                                  
  5921 00003100 <res F00h>              alignb 4096
  5922                                  
  5923                                  ;audio_buffer:	resb BUFFERSIZE ; DMA Buffer Size / 2 (32768)
  5924                                  ; 29/05/2024
  5925                                  ; 26/11/2023
  5926                                  ;audio_buffer:	resb 65536
  5927                                  ; 29/05/2024
  5928 00004000 <res 10000h>            WAVBUFFER_1:	resb 65536
  5929 00014000 <res 10000h>            WAVBUFFER_2:	resb 65536
  5930                                  ; 13/06/2017
  5931                                  ;temp_buffer:	resb BUFFERSIZE
  5932                                  ; 26/11/2023
  5933 00024000 <res 10000h>            temp_buffer:	resb 65536
