     1                                  ; ****************************************************************************
     2                                  ; PLAYWAV.ASM - ICH AC97 .wav player for DOS.			   PLAYWAV.COM
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 12/11/2023 (Previous: 08/11/2023)
     5                                  ; ----------------------------------------------------------------------------
     6                                  ; Beginning: 17/02/2017
     7                                  ; ----------------------------------------------------------------------------
     8                                  ; Assembler: NASM version 2.11 (2.15)
     9                                  ;	     nasm playwav.asm -l playwav.lst -o PLAYWAV.COM	
    10                                  ; ----------------------------------------------------------------------------
    11                                  ; Derived from '.wav file player for DOS' Jeff Leyda, Sep 02, 2002 
    12                                  ; ****************************************************************************
    13                                  ; Modidified from 'PLAYER.COM' for VIA VT8233 wav player source code by
    14                                  ; (PLAYER.ASM) by Erdogan Tan (07/11/2016 - 08/12/2016)
    15                                  
    16                                  ; AC97 interrupt version - 09/11/2023 - Erdogan Tan
    17                                  
    18                                  [BITS 16]
    19                                  
    20                                  [ORG 100h] 
    21                                  
    22                                  	%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
    23                                  
    24                                  _STARTUP:
    25                                  
    26                                  ; memory allocation
    27                                  
    28 00000000 E85D01                          call    setFree				; deallocate unused DOS mem
    29                                  
    30                                  	; 17/02/2017
    31                                  	; Clear BSS (uninitialized data) area
    32 00000003 31C0                    	xor	ax, ax ; 0
    33 00000005 B92240                  	mov	cx, (EOF - bss_start)/2
    34 00000008 BF[BA0A]                	mov	di, bss_start
    35 0000000B F3AB                    	rep	stosw
    36                                  
    37                                  ; allocate 256 bytes of data for DCM_OUT Buffer Descriptor List. (BDL)
    38                                  
    39 0000000D B81000                          mov     ax, BDL_SIZE / 16
    40 00000010 E85501                          call    memAlloc
    41 00000013 A3[E60A]                        mov     [BDL_BUFFER], ax		; segment 
    42                                  
    43                                  ; allocate 2 buffers, 64k each for now.
    44                                  
    45 00000016 B80010                          mov     ax, BUFFERSIZE / 16		; 64k for .WAV file
    46 00000019 E84C01                          call    memAlloc
    47 0000001C A3[E80A]                        mov     [WAV_BUFFER1], ax		; segment
    48                                  
    49 0000001F B80010                  	mov	ax, BUFFERSIZE / 16
    50 00000022 E84301                  	call	memAlloc
    51 00000025 A3[EA0A]                	mov	[WAV_BUFFER2], ax
    52                                  
    53                                  ; Detect/reset AC97 
    54                                  
    55 00000028 E8B002                          call    pciFindDevice
    56 0000002B 7342                            jnc     short _1
    57                                  
    58                                  ; couldn't find the audio device!
    59                                  
    60 0000002D 0E                      	push	cs
    61 0000002E 1F                      	pop	ds
    62 0000002F BA[3900]                        mov     dx, noDevMsg
    63 00000032 B409                            mov     ah, 9
    64 00000034 CD21                            int     21h
    65 00000036 E91701                          jmp     exit
    66                                  
    67                                  ; 17/02/2017
    68 00000039 4572726F723A20556E-     noDevMsg: db "Error: Unable to find intel ICH based audio device!",CR,LF,"$"
    68 00000042 61626C6520746F2066-
    68 0000004B 696E6420696E74656C-
    68 00000054 204943482062617365-
    68 0000005D 6420617564696F2064-
    68 00000066 6576696365210D0A24 
    69                                  
    70                                  _1:
    71                                  	; eax = BUS/DEV/FN
    72                                  	;	00000000BBBBBBBBDDDDDFFF00000000
    73                                  	; edx = DEV/VENDOR
    74                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
    75                                  
    76 0000006F 66A3[EC0A]              	mov	[bus_dev_fn], eax
    77 00000073 668916[F00A]            	mov	[dev_vendor], edx
    78                                  
    79                                  	; get ICH base address regs for mixer and bus master
    80                                  
    81 00000078 B010                            mov     al, NAMBAR_REG
    82 0000007A E8D001                          call    pciRegRead16			; read PCI registers 10-11
    83 0000007D 83E2FE                          and     dx, IO_ADDR_MASK 		; mask off BIT0
    84                                  
    85 00000080 8916[E20A]                      mov     [NAMBAR], dx			; save audio mixer base addy
    86                                  
    87 00000084 B014                    	mov     al, NABMBAR_REG
    88 00000086 E8C401                          call    pciRegRead16
    89 00000089 83E2FE                          and     dx, IO_ADDR_MASK
    90                                  
    91 0000008C 8916[E40A]                      mov     [NABMBAR], dx			; save bus master base addy
    92                                  
    93                                  	; 06/11/2023
    94                                  	;; init controller
    95                                  	;; 17/02/2017
    96                                  	;mov	al, PCI_CMD_REG ; command register (04h)
    97                                  	;call	pciRegRead16 ; pciRegRead8
    98                                  	;
    99                                  	;; eax = BUS/DEV/FN/REG
   100                                  	;;  dx = PCI Command Register Content ; 17/02/2017
   101                                  	;; 	00000000CCCCCCCC
   102                                  	;mov	[stats_cmd], dx
   103                                  	;
   104                                  	; 06/11/2023
   105                                  	;mov	al, PCI_IO_BASE ; IO base address register (10h)
   106                                  	;call	pciRegRead32
   107                                  	;
   108                                  	;and	dx, 0FFC0h	; IO_ADDR_MASK (0FFFE) ?
   109                                          ;mov	[ac97_io_base], dx
   110                                  
   111 00000090 B03C                    	mov	al, AC97_INT_LINE ; Interrupt line register (3Ch)
   112 00000092 E8B001                  	call	pciRegRead8 ; 17/02/2017
   113                                  
   114 00000095 8816[D90A]              	mov     [ac97_int_ln_reg], dl
   115                                  
   116                                  ; 09/11/2023
   117                                  ; 05/11/2023
   118                                  %if 1
   119                                  	; 28/11/2016
   120 00000099 BB0100                  	mov	bx, 1
   121 0000009C 30F6                    	xor	dh, dh 	 ; 17/02/2017
   122                                  	; 10/11/2023
   123                                  	;mov	cx, dx
   124                                  	;shl	bx, cl
   125                                  
   126                                  	; 04/11/2023
   127 0000009E FA                      	cli
   128                                  
   129                                  	;not	bx
   130 0000009F E4A1                    	in	al, 0A1h ; irq 8-15
   131 000000A1 88C4                            mov	ah, al
   132 000000A3 E421                            in	al, 21h  ; irq 0-7 
   133                                  
   134                                  	; 04/11/2023
   135                                  	; save IRQ status
   136 000000A5 A3[DC0A]                	mov	[IRQ_status], ax
   137                                  
   138                                  	;and	ax, bx   ; unmask
   139 000000A8 0FB3D0                   	btr	ax, dx	 ; unmask
   140 000000AB E621                    	out	21h, al  ; enable interrupt (if irq <= 7)
   141 000000AD 88E0                    	mov	al, ah
   142 000000AF E6A1                    	out	0A1h, al ; enable interrupt (if irq > 7)
   143                                  	;not	bx
   144                                  
   145                                  	; 04/11/2023
   146                                  	;mov	dx, 4D1h			;8259 ELCR1
   147                                          ;in	al, dx
   148                                  	;mov	ah, al
   149                                  	;mov	dx, 4D0h 
   150                                          ;in	al, dx
   151                                  	;;or	ax, bx        
   152                                  	;bts	ax, cx
   153                                  	;mov	dx, 4D0h
   154                                  	;out	dx, al                          ;set level-triggered mode
   155                                  	;mov	al, ah
   156                                  	;mov	dx, 4D1h
   157                                  	;out	dx, al                          ;set level-triggered mode
   158                                  
   159                                  	; 24/11/2016 - Erdogan Tan
   160                                  	;mov	bx, cx
   161                                  	; 10/11/2023
   162 000000B1 89D3                    	mov	bx, dx
   163 000000B3 8A9F[0509]              	mov	bl, [bx+irq_int]
   164 000000B7 C1E302                  	shl	bx, 2 ; * 4
   165                                  
   166                                  	; set up interrupt vector
   167                                  	; 30/11/2016
   168 000000BA 06                      	push	es
   169 000000BB 31C0                    	xor	ax, ax
   170 000000BD 8EC0                    	mov	es, ax
   171                                  	; 04/11/2023
   172                                  	; save interrupt vector
   173 000000BF 268B07                  	mov	ax, [es:bx]
   174 000000C2 A3[DE0A]                	mov	[IRQ_vector], ax
   175 000000C5 268B4702                	mov	ax, [es:bx+2]
   176 000000C9 A3[E00A]                	mov	[IRQ_vector+2], ax
   177                                  
   178 000000CC 26C707[5408]            	mov	word [es:bx], ac97_int_handler
   179 000000D1 8CC8                    	mov	ax, cs
   180 000000D3 26894702                	mov	[es:bx+2], ax
   181 000000D7 07                      	pop	es
   182                                  
   183                                  	; 04/11/2023
   184 000000D8 FB                      	sti
   185                                  
   186                                  %endif
   187 000000D9 E8C505                  	call	write_ac97_dev_info 
   188                                  
   189                                  ; check the command line for a file to play
   190                                  
   191                                          ;push	ds
   192 000000DC E89200                          call    processCmdline			; get the filename
   193                                  
   194                                  ; open the file
   195 000000DF B002                            mov     al, OPEN                        ; open existing file
   196 000000E1 E8AD00                          call    openFile                        ; no error? ok.
   197                                          ;pop	ds
   198 000000E4 7322                            jnc     short _gsr
   199                                  
   200                                  ; file not found!
   201                                  
   202                                          ;push   cs
   203                                          ;pop    ds
   204 000000E6 BA[EF00]                        mov	dx, noFileErrMsg
   205 000000E9 B409                            mov     ah, 9
   206 000000EB CD21                            int     21h
   207 000000ED EB61                            jmp     exit
   208                                  
   209                                  noFileErrMsg:
   210 000000EF 4572726F723A206669-     	db "Error: file not found.",CR,LF,"$"
   210 000000F8 6C65206E6F7420666F-
   210 00000101 756E642E0D0A24     
   211                                  
   212                                  _gsr:
   213 00000108 E8AD00                          call    getSampleRate                   ; read the sample rate
   214                                                                                  ; pass it onto codec.
   215 0000010B 7243                    	jc	short exit ; 19/11/2016 - nothing to do
   216                                  
   217 0000010D A3[F40A]                	mov	[sample_rate], ax
   218                                  	
   219                                  	; 19/11/2016
   220 00000110 880E[F60A]              	mov	[stmo], cl
   221 00000114 8816[F80A]              	mov	[bps], dl
   222                                  	
   223                                  	; 17/02/2017
   224 00000118 C606[FA0A]00            	mov	byte [fbs_shift], 0 ; 0 = stereo and 16 bit 
   225 0000011D FEC9                    	dec	cl
   226 0000011F 7504                    	jnz	short _gsr_1 ; stereo
   227 00000121 FE06[FA0A]              	inc	byte [fbs_shift] ; 1 = mono or 8 bit		
   228                                  _gsr_1:	
   229 00000125 80FA08                  	cmp	dl, 8 
   230 00000128 7704                    	ja	short _gsr_2 ; 16 bit samples
   231 0000012A FE06[FA0A]              	inc	byte [fbs_shift] ; 2 = mono and 8 bit
   232                                  _gsr_2:	
   233 0000012E E8D206                  	call	write_sample_rate
   234                                  
   235                                  	; 05/11/2023
   236                                  _2:
   237 00000131 E84005                  	call	check4keyboardstop  ; flush keyboard buffer
   238 00000134 72FB                    	jc	short _2 	; 07/11/2023
   239                                  
   240                                  	; 09/11/2023
   241                                  	;; 05/11/2023
   242                                  	;mov	eax, [bus_dev_fn]
   243                                  	;mov	al, PCI_CMD_REG
   244                                  	;call	pciRegRead16			; read PCI command register
   245                                  	;; 17/02/2017
   246                                  	;;mov	dx, [stats_cmd]
   247                                          ;or	dl, IO_ENA+BM_ENA               ; enable IO and bus master
   248                                  	;call	pciRegWrite16 ; pciRegWrite8
   249                                  
   250                                  	;; 06/11/2023
   251                                  	;;mov	eax, [bus_dev_fn]
   252                                  	;;mov	al, PCI_CMD_REG
   253                                  	;;call	pciRegRead8                     ; read PCI command register
   254                                  	;;or	dl, IO_ENA+BM_ENA               ; enable IO and bus master
   255                                  	;;call	pciRegWrite8
   256                                  
   257                                  ; setup the Codec (actually mixer registers) 
   258 00000136 E8E501                          call    codecConfig                     ; unmute codec, set rates.
   259                                  	; 11/11/2023
   260 00000139 721C                    	jc	short init_err
   261                                  ;
   262                                  ; position file pointer to start in actual wav data
   263                                  ; MUCH improvement should really be done here to check if sample size is
   264                                  ; supported, make sure there are 2 channels, etc.  
   265                                  ;
   266 0000013B B442                            mov     ah, 42h
   267 0000013D B000                            mov     al, 0                           ; from start of file
   268 0000013F 8B1E[D60A]                      mov     bx, [filehandle]
   269 00000143 31C9                            xor     cx, cx
   270 00000145 BA2C00                          mov     dx, 44                          ; jump past .wav/riff header
   271 00000148 CD21                            int     21h
   272                                  
   273                                  ; play the .wav file. Most of the good stuff is in here.
   274                                  
   275 0000014A E83703                          call    playWav
   276                                  
   277                                  ; close the .wav file and exit.
   278                                  
   279                                  close_exit:			; 11/11/2023
   280 0000014D E85300                          call    closeFile
   281                                  
   282                                  exit:
   283 00000150 B8004C                          mov     ax, 4c00h
   284 00000153 CD21                    	int 	21h
   285                                  
   286                                  here:
   287 00000155 EBFE                    	jmp	short here
   288                                  
   289                                  	; 11/11/2023
   290                                  init_err:
   291 00000157 BA[500A]                	mov	dx, msg_init_err
   292                                  vra_err: ; 12/11/2023
   293 0000015A B409                            mov	ah, 9
   294 0000015C CD21                            int	21h
   295 0000015E EBED                    	jmp	short close_exit
   296                                  
   297                                  ; MEMALLOC.ASM
   298                                  ;-- SETFREE: Release memory not used  ----------------
   299                                  ;-- Input    : ES = address of PSP
   300                                  ;-- Output   : none
   301                                  ;-- Register : AX, BX, CL and FLAGS are changed 
   302                                  ;-- Info     : Since the stack-segment is always the last segment in an 
   303                                  ;              EXE-file, ES:0000 points to the beginning and SS:SP
   304                                  ;              to the end of the program in memory. Through this the
   305                                  ;              length of the program can be calculated 
   306                                  ; call this routine once at the beginning of the program to free up memory
   307                                  ; assigned to it by DOS.
   308                                  
   309                                  setFree:
   310 00000160 BB0010                  	  mov	bx, 65536/16	; 4K paragraphs ; 17/02/2017 (Erdogan Tan)		
   311                                  
   312 00000163 B44A                              mov	ah, 4ah		; pass new length to DOS
   313 00000165 CD21                              int	21h
   314                                  
   315 00000167 C3                                retn			; back to caller 
   316                                  				; new size (allocated memory) = 64KB
   317                                  
   318                                  memAlloc:
   319                                  ; input: AX = # of paragraphs required
   320                                  ; output: AX = segment of block to use
   321                                  
   322 00000168 53                      	push	bx
   323 00000169 89C3                    	mov	bx, ax
   324 0000016B B448                    	mov	ah, 48h
   325 0000016D CD21                    	int	21h
   326 0000016F 5B                      	pop	bx
   327 00000170 C3                      	retn
   328                                  
   329                                  ; CMDLINE.ASM
   330                                  ; parse the command line
   331                                  ; entry: none
   332                                  ; exit: DS:DX to the 1st supplied item on the command line 
   333                                  
   334                                  processCmdline:
   335 00000171 53                              push    bx
   336 00000172 56                              push    si
   337                                  
   338                                          ;mov    ah, 51h
   339                                          ;int    21h
   340                                          ;mov    ds, bx
   341                                  
   342 00000173 BE8000                          mov     si, 80h
   343 00000176 0FB61C                          movzx   bx, byte [si]
   344 00000179 01DE                            add     si, bx
   345 0000017B 46                              inc     si
   346                                  
   347 0000017C C60400                          mov     byte [si], NULL         ; zero terminate
   348                                  
   349 0000017F BE8100                          mov     si, 81h
   350                                  
   351                                  cmdlineloop:
   352 00000182 AC                              lodsb
   353                                  
   354 00000183 3C00                            cmp     al, NULL                ; found end of line?
   355 00000185 7404                            je      short exitpc
   356 00000187 3C20                            cmp     al, ' '                 ; found a space?
   357 00000189 74F7                            je      short cmdlineloop
   358                                  
   359                                          ; must be the filename here.
   360                                  exitpc:
   361 0000018B 4E                              dec     si                      ; point to start of filename
   362 0000018C 89F2                            mov     dx, si
   363 0000018E 5E                              pop     si
   364 0000018F 5B                              pop     bx
   365 00000190 C3                      	retn
   366                                  
   367                                  ; FILE.ASM
   368                                  ;open or create file
   369                                  ;
   370                                  ;input: ds:dx-->filename (asciiz)
   371                                  ;       al=file Mode (create or open)
   372                                  ;output: none  cs:[filehandle] filled
   373                                  ;
   374                                  openFile:
   375 00000191 50                      	push	ax
   376 00000192 51                      	push	cx
   377 00000193 B43B                    	mov	ah, 3bh			; start with a mode
   378 00000195 00C4                    	add	ah, al			; add in create or open mode
   379 00000197 31C9                    	xor	cx, cx
   380 00000199 CD21                    	int	21h
   381 0000019B 7203                    	jc	short _of1
   382                                  	;mov	[cs:filehandle], ax
   383 0000019D A3[D60A]                	mov	[filehandle], ax
   384                                  _of1:
   385 000001A0 59                      	pop	cx
   386 000001A1 58                      	pop	ax
   387 000001A2 C3                      	retn
   388                                  
   389                                  ; close the currently open file
   390                                  ; input: none, uses cs:[filehandle]
   391                                  closeFile:
   392 000001A3 50                      	push	ax
   393 000001A4 53                      	push	bx
   394 000001A5 833E[D60A]FF            	cmp	word [filehandle], -1
   395 000001AA 7409                    	jz	short _cf1
   396 000001AC 8B1E[D60A]              	mov     bx, [filehandle]  
   397 000001B0 B8003E                  	mov     ax,3e00h
   398 000001B3 CD21                            int     21h              ;close file
   399                                  _cf1:
   400 000001B5 5B                      	pop	bx
   401 000001B6 58                      	pop	ax
   402 000001B7 C3                      	retn
   403                                  
   404                                  getSampleRate:
   405                                  	; 08/12/2016
   406                                  ; reads the sample rate from the .wav file.
   407                                  ; entry: none - assumes file is already open
   408                                  	; 19/11/2016 - Erdogan Tan
   409                                  ; exit: ax = sample rate (11025, 22050, 44100, 48000)
   410                                  ;	cx = number of channels (mono=1, stereo=2)
   411                                  ;	dx = bits per sample (8, 16)
   412                                  
   413 000001B8 53                      	push    bx
   414                                  
   415 000001B9 B442                            mov     ah, 42h
   416 000001BB B000                            mov     al, 0				; from start of file
   417 000001BD 8B1E[D60A]                      mov     bx, [filehandle]
   418 000001C1 31C9                            xor     cx, cx
   419 000001C3 BA0800                          mov     dx, 08h				; "WAVE"
   420 000001C6 CD21                            int     21h
   421                                  
   422 000001C8 BA[BA0A]                        mov     dx, smpRBuff
   423 000001CB B91C00                          mov     cx, 28				; 28 bytes
   424 000001CE B43F                    	mov	ah, 3fh
   425 000001D0 CD21                            int     21h
   426                                  
   427 000001D2 813E[BA0A]5741          	cmp	word [smpRBuff], 'WA'
   428 000001D8 751C                    	jne	short gsr_stc
   429                                  
   430 000001DA 813E[BC0A]5645          	cmp	word [smpRBuff+2], 'VE'
   431 000001E0 7514                    	jne	short gsr_stc
   432                                  
   433 000001E2 833E[C60A]01            	cmp	word [smpRBuff+12], 1	; Offset 20, must be 1 (= PCM)
   434 000001E7 750D                    	jne	short gsr_stc
   435                                  
   436                                  
   437 000001E9 8B0E[C80A]              	mov	cx, [smpRBuff+14]	; return num of channels in CX
   438 000001ED A1[CA0A]                        mov     ax, [smpRBuff+16]	; return sample rate in AX
   439 000001F0 8B16[D40A]              	mov	dx, [smpRBuff+26]	; return bits per sample value in DX
   440                                  gsr_retn:
   441 000001F4 5B                              pop     bx
   442 000001F5 C3                              retn
   443                                  
   444                                  gsr_stc:
   445 000001F6 F9                      	stc
   446 000001F7 EBFB                    	jmp	short gsr_retn
   447                                  
   448                                  %include 'ac97.asm' ; 29/11/2016 (AC97 codec configuration)
     1                              <1> ; 12/11/2023
     2                              <1> ; 11/11/2023
     3                              <1> ; 06/11/2023
     4                              <1> ; 05/11/2023
     5                              <1> ; 04/11/2023
     6                              <1> ; 03/11/2023
     7                              <1> ; PCI and AC97 codec functions for wav player
     8                              <1> ; Erdogan Tan (17/02/2017)
     9                              <1> 
    10                              <1> ; ----------------------------------------------------------------------------
    11                              <1> ; PCI.ASM
    12                              <1> ; ----------------------------------------------------------------------------
    13                              <1> 
    14                              <1> ; PCI device register reader/writers.
    15                              <1> ; NASM version: Erdogan Tan (29/11/2016)
    16                              <1> ; 		Last Update: 17/02/2017
    17                              <1> 
    18                              <1> ;===============================================================
    19                              <1> ; 8/16/32bit PCI reader
    20                              <1> ;
    21                              <1> ; Entry: EAX=PCI Bus/Device/fn/register number
    22                              <1> ;           BIT30 set if 32 bit access requested
    23                              <1> ;           BIT29 set if 16 bit access requested
    24                              <1> ;           otherwise defaults to 8 bit read
    25                              <1> ;
    26                              <1> ; Exit:  DL,DX,EDX register data depending on requested read size
    27                              <1> ;
    28                              <1> ; Note: this routine is meant to be called via pciRegRead8, pciRegread16,
    29                              <1> ;	or pciRegRead32, listed below.
    30                              <1> ;
    31                              <1> ; Note2: don't attempt to read 32bits of data from a non dword aligned reg
    32                              <1> ;	 number. Likewise, don't do 16bit reads from non word aligned reg #
    33                              <1> ; 
    34                              <1> pciRegRead:
    35 000001F9 6653                <1> 	push	ebx
    36 000001FB 51                  <1> 	push	cx
    37 000001FC 6689C3              <1>         mov     ebx, eax                        ; save eax, dh
    38 000001FF 88F1                <1>         mov     cl, dh
    39 00000201 6625FFFFFFBF        <1>         and     eax, (~PCI32)+PCI16             ; clear out data size request
    40 00000207 660D00000080        <1>         or      eax, BIT31                      ; make a PCI access request
    41 0000020D 24FC                <1>         and     al, ~3 ; NOT 3                  ; force index to be dword
    42                              <1> 
    43 0000020F BAF80C              <1>         mov     dx, PCI_INDEX_PORT
    44 00000212 66EF                <1>         out     dx, eax                         ; write PCI selector
    45                              <1> 
    46 00000214 BAFC0C              <1>         mov     dx, PCI_DATA_PORT
    47 00000217 88D8                <1>         mov     al, bl
    48 00000219 2403                <1>         and     al, 3                           ; figure out which port to
    49 0000021B 00C2                <1>         add     dl, al                          ; read to
    50                              <1> 
    51 0000021D 66ED                <1> 	in      eax, dx                         ; do 32bit read
    52 0000021F 66F7C300000080      <1>         test    ebx, PCI32
    53 00000226 7403                <1>         jz      short _pregr1
    54                              <1> 
    55 00000228 6689C2              <1>         mov     edx, eax                        ; return 32bits of data
    56                              <1> _pregr1:
    57 0000022B 89C2                <1> 	mov     dx, ax                          ; return 16bits of data
    58 0000022D 66F7C3000000C0      <1>         test    ebx, PCI32+PCI16
    59 00000234 7502                <1>         jnz     short _pregr2
    60 00000236 88CE                <1>         mov     dh, cl                          ; restore dh for 8 bit read
    61                              <1> _pregr2:
    62 00000238 6689D8              <1>         mov     eax, ebx                        ; restore eax
    63 0000023B 6625FFFFFFBF        <1>         and     eax, (~PCI32)+PCI16             ; clear out data size request
    64 00000241 59                  <1> 	pop	cx
    65 00000242 665B                <1> 	pop	ebx
    66 00000244 C3                  <1> 	retn
    67                              <1> 
    68                              <1> pciRegRead8:
    69 00000245 6625FFFFFF3F        <1>         and     eax, (~PCI16)+PCI32             ; set up 8 bit read size
    70 0000024B EBAC                <1>         jmp     short pciRegRead		; call generic PCI access
    71                              <1> 
    72                              <1> pciRegRead16:
    73 0000024D 6625FFFFFF3F        <1>         and     eax, (~PCI16)+PCI32		; set up 16 bit read size
    74 00000253 660D00000040        <1>         or      eax, PCI16			; call generic PCI access
    75 00000259 EB9E                <1>         jmp     short pciRegRead
    76                              <1> 
    77                              <1> pciRegRead32:
    78 0000025B 6625FFFFFF3F        <1>         and     eax, (~PCI16)+PCI32		; set up 32 bit read size
    79 00000261 660D00000080        <1>         or      eax, PCI32			; call generic PCI access
    80 00000267 EB90                <1>         jmp     short pciRegRead
    81                              <1> 
    82                              <1> ;===============================================================
    83                              <1> ; 8/16/32bit PCI writer
    84                              <1> ;
    85                              <1> ; Entry: EAX=PCI Bus/Device/fn/register number
    86                              <1> ;           BIT31 set if 32 bit access requested
    87                              <1> ;           BIT30 set if 16 bit access requested
    88                              <1> ;           otherwise defaults to 8bit read
    89                              <1> ;        DL/DX/EDX data to write depending on size
    90                              <1> ;
    91                              <1> ;
    92                              <1> ; note: this routine is meant to be called via pciRegWrite8, pciRegWrite16,
    93                              <1> ; 	or pciRegWrite32 as detailed below.
    94                              <1> ;
    95                              <1> ; Note2: don't attempt to write 32bits of data from a non dword aligned reg
    96                              <1> ;	 number. Likewise, don't do 16bit writes from non word aligned reg #
    97                              <1> ;
    98                              <1> pciRegWrite:
    99 00000269 6653                <1> 	push	ebx
   100 0000026B 51                  <1> 	push	cx
   101 0000026C 6689C3              <1>         mov     ebx, eax                        ; save eax, dx
   102 0000026F 89D1                <1>         mov     cx, dx
   103 00000271 660D00000080        <1>         or      eax, BIT31                      ; make a PCI access request
   104 00000277 6625FFFFFFBF        <1>         and     eax, ~PCI16 ; NOT PCI16         ; clear out data size request
   105 0000027D 24FC                <1>         and     al, ~3 ; NOT 3                  ; force index to be dword
   106                              <1> 
   107 0000027F BAF80C              <1>         mov     dx, PCI_INDEX_PORT
   108 00000282 66EF                <1>         out     dx, eax                         ; write PCI selector
   109                              <1> 
   110 00000284 BAFC0C              <1>         mov     dx, PCI_DATA_PORT
   111 00000287 88D8                <1>         mov     al, bl
   112 00000289 2403                <1>         and     al, 3                           ; figure out which port to
   113 0000028B 00C2                <1>         add     dl, al                          ; write to
   114                              <1> 
   115 0000028D 6689D0              <1>         mov     eax, edx                        ; put data into eax
   116 00000290 89C8                <1>         mov     ax, cx
   117                              <1> 
   118 00000292 EE                  <1>         out     dx, al
   119 00000293 66F7C3000000C0      <1>         test    ebx, PCI16+PCI32                ; only 8bit access? bail
   120 0000029A 740C                <1>         jz      short _pregw1
   121                              <1> 
   122 0000029C EF                  <1>         out     dx, ax                          ; write 16 bit value
   123 0000029D 66F7C300000040      <1>         test    ebx, PCI16                      ; 16bit requested?  bail
   124 000002A4 7502                <1>         jnz     short _pregw1
   125                              <1> 
   126 000002A6 66EF                <1>         out     dx, eax                         ; write full 32bit
   127                              <1> _pregw1:
   128 000002A8 6689D8              <1>         mov     eax, ebx                        ; restore eax
   129 000002AB 6625FFFFFFBF        <1>         and     eax, (~PCI32)+PCI16             ; clear out data size request
   130 000002B1 89CA                <1>         mov     dx, cx                          ; restore dx
   131 000002B3 59                  <1> 	pop	cx
   132 000002B4 665B                <1> 	pop	ebx
   133 000002B6 C3                  <1> 	ret
   134                              <1> 
   135                              <1> pciRegWrite8:
   136 000002B7 6625FFFFFF3F        <1>         and     eax, (~PCI16)+PCI32		; set up 8 bit write size
   137 000002BD EBAA                <1>         jmp     short pciRegWrite		; call generic PCI access
   138                              <1> 
   139                              <1> pciRegWrite16:
   140 000002BF 6625FFFFFF3F        <1>         and     eax, (~PCI16)+PCI32		; set up 16 bit write size
   141 000002C5 660D00000040        <1>         or      eax, PCI16			; call generic PCI access
   142 000002CB EB9C                <1>         jmp     short pciRegWrite
   143                              <1> 
   144                              <1> pciRegWrite32:
   145 000002CD 6625FFFFFF3F        <1>         and     eax, (~PCI16)+PCI32		; set up 32 bit write size
   146 000002D3 660D00000080        <1>         or      eax, PCI32			; call generic PCI access
   147 000002D9 EB8E                <1>         jmp     short pciRegWrite
   148                              <1> 
   149                              <1> ; 17/02/2017 (Modifed by Erdogan Tan for various ICH device IDs)
   150                              <1> ;===============================================================
   151                              <1> ; PCIFindDevice: scan through PCI space looking for a device+vendor ID
   152                              <1> ;
   153                              <1> ;  ENTRY: none
   154                              <1> ;; Entry: EAX=Device+Vendor ID
   155                              <1> ;
   156                              <1> ;  Exit: EAX=PCI address if device found
   157                              <1> ;	 EDX=Device+Vendor ID
   158                              <1> ;        CY clear if found, set if not found. EAX invalid if CY set.
   159                              <1> ;
   160                              <1> ; [old stackless] Destroys: ebx, esi, edi, cl
   161                              <1> ;
   162                              <1> pciFindDevice:
   163                              <1> 	;push	cx
   164                              <1> 	;push	eax ; *
   165                              <1> 	;push	esi
   166                              <1> 	;push	edi
   167                              <1> 
   168                              <1>  	;mov     esi, eax                ; save off vend+device ID
   169                              <1> 
   170                              <1> 	; 17/02/2017
   171 000002DB BE[1509]            <1> 	mov	si, valid_ids	; address of Valid ICH (AC97) Device IDs
   172 000002DE B91500              <1> 	mov	cx, valid_id_count
   173                              <1> pfd_0:
   174 000002E1 66BF00FFFF7F        <1>        	mov     edi, (80000000h - 100h) ; start with bus 0, dev 0 func 0
   175                              <1> nextPCIdevice:
   176 000002E7 6681C700010000      <1>         add     edi, 100h
   177 000002EE 6681FF00F8FF80      <1>         cmp     edi, 80FFF800h		; scanned all devices?
   178                              <1>         ;stc
   179                              <1>         ;je 	short PCIScanExit       ; not found
   180 000002F5 720D                <1> 	jb	short pfd_1
   181 000002F7 66BF00000080        <1> 	mov     edi, 80000000h
   182 000002FD 83C604              <1> 	add	si, 4 ; scan for next device ID
   183 00000300 E202                <1> 	loop	pfd_1	 
   184 00000302 F9                  <1> 	stc	
   185                              <1> 	;jmp 	short PCIScanExit
   186 00000303 C3                  <1> 	retn
   187                              <1> pfd_1:
   188 00000304 6689F8              <1>         mov     eax, edi                ; read PCI registers
   189 00000307 E851FF              <1>         call    pciRegRead32
   190                              <1>         ;cmp    edx, esi                ; found device?
   191 0000030A 663B14              <1>         cmp	edx, dword [si]
   192 0000030D 75D8                <1> 	jne     short nextPCIdevice
   193                              <1>         ;clc
   194                              <1> PCIScanExit:
   195                              <1> 	;pushf
   196 0000030F 66B800000080        <1> 	mov	eax, BIT31
   197 00000315 66F7D0              <1> 	not	eax
   198 00000318 6621F8              <1> 	and	eax, edi		; return only bus/dev/fn #
   199                              <1> 	;popf
   200                              <1> 
   201                              <1> 	;pop	edi
   202                              <1> 	;pop	esi
   203                              <1> 	;pop	edx ; *
   204                              <1> 	;pop	cx
   205 0000031B C3                  <1> 	retn
   206                              <1> 
   207                              <1> ; ----------------------------------------------------------------------------
   208                              <1> ; CODEC.ASM
   209                              <1> ; ----------------------------------------------------------------------------
   210                              <1> 
   211                              <1> ; codec configuration code. Not much here really.
   212                              <1> ; NASM version: Erdogan Tan (29/11/2016)
   213                              <1> 
   214                              <1> ; enable codec, unmute stuff, set output rate to 44.1
   215                              <1> ; entry: ax = desired sample rate
   216                              <1> 
   217                              <1> ; 11/11/2023
   218                              <1> ; 06/11/2023
   219                              <1> %if 1
   220                              <1> 
   221                              <1> 	; 11/11/2023
   222                              <1> init_ac97_codec_err1:
   223 0000031C F9                  <1> 	stc
   224                              <1> init_ac97_codec_err2:
   225 0000031D C3                  <1> 	retn
   226                              <1> 
   227                              <1> codecConfig:
   228                              <1> 	; 04/11/2023
   229                              <1> 	; 17/02/2017 
   230                              <1> 	; 07/11/2016 (Erdogan Tan)
   231                              <1> 	;PORT_NABM_GLB_CTRL_STAT equ 60h
   232                              <1> 
   233                              <1> 	; 03/11/2023 (MPXPLAY, 'SC_ICH.C', ac97_init)
   234                              <1>  	; 'AC97_DEF.H'
   235                              <1> 	;AC97_EXTENDED_STATUS equ 002Ah
   236                              <1> 	AC97_EA_SPDIF	equ 0002h
   237                              <1> 	AC97_EA_VRA	equ 0001h
   238                              <1> 	; 04/11/2023
   239                              <1> 	ICH_PO_CR_RESET equ 0002h  ; reset codec
   240                              <1> 	ICH_PCM_20BIT	equ 400000h ; 20-bit samples (ICH4)
   241                              <1> 	ICH_PCM_246_MASK equ 300000h ; 6 channels
   242                              <1> 
   243                              <1> 	; 04/11/2023
   244                              <1> init_ac97_controller:
   245 0000031E 66A1[EC0A]          <1> 	mov	eax, [bus_dev_fn]
   246 00000322 B004                <1> 	mov	al, PCI_CMD_REG
   247 00000324 E826FF              <1> 	call	pciRegRead16		; read PCI command register
   248 00000327 80CA05              <1> 	or      dl, IO_ENA+BM_ENA	; enable IO and bus master
   249 0000032A E892FF              <1> 	call	pciRegWrite16
   250                              <1> 
   251 0000032D E84901              <1> 	call	delay_100ms
   252                              <1> 
   253                              <1> init_ac97_codec:
   254                              <1> 	; 11/11/2023
   255                              <1> 	; (TRDOS 386 v2.0.5, 'audio.s')
   256 00000330 BA2C00              <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
   257 00000333 0316[E40A]          <1> 	add	dx, [NABMBAR]
   258 00000337 66ED                <1> 	in	eax, dx
   259                              <1> 	; ?
   260 00000339 BA3000              <1> 	mov	dx, GLOB_STS_REG ; 30h
   261 0000033C 0316[E40A]          <1> 	add	dx, [NABMBAR]
   262 00000340 66ED                <1> 	in	eax, dx
   263                              <1> 
   264 00000342 6683F8FF            <1> 	cmp	eax, 0FFFFFFFFh ; -1
   265 00000346 74D4                <1> 	je	short init_ac97_codec_err1
   266                              <1> 
   267 00000348 66A900030010        <1> 	test	eax, CTRL_ST_CREADY
   268 0000034E 7503                <1> 	jnz	short _ac97_codec_ready
   269                              <1> 
   270 00000350 E8A600              <1> 	call	reset_ac97_codec
   271                              <1> 	; 11/11/2023
   272                              <1> 	;jc	short init_ac97_codec_err2
   273                              <1> 
   274                              <1> _ac97_codec_ready:
   275 00000353 8B16[E20A]          <1> 	mov	dx, [NAMBAR]
   276                              <1> 	;add	dx, 0 ; ac_reg_0 ; reset register
   277 00000357 EF                  <1> 	out	dx, ax
   278                              <1> 
   279 00000358 E81E01              <1> 	call	delay_100ms
   280                              <1> 
   281                              <1> ;	xor	eax, eax ; 0
   282                              <1> ;	mov	dx, [NAMBAR]
   283                              <1> ;	add	dx, CODEC_REG_POWERDOWN
   284                              <1> ;	out	dx, ax
   285                              <1> ;
   286                              <1> ;	; wait for 1 second
   287                              <1> ;	mov	ecx, 1000 ; 1000*0.25ms = 1s
   288                              <1> ;_ac97_codec_rloop:
   289                              <1> ;	call	delay1_4ms
   290                              <1> ;	call	delay1_4ms
   291                              <1> ;	call	delay1_4ms
   292                              <1> ;	call	delay1_4ms
   293                              <1> ;	;mov	dx, [NAMBAR]
   294                              <1> ;	;add	dx, CODEC_REG_POWERDOWN
   295                              <1> ;	in	ax, dx	
   296                              <1> ;	and	ax, 0Fh
   297                              <1> ;	cmp	al, 0Fh
   298                              <1> ;	je	short _ac97_codec_init_ok
   299                              <1> ;	loop	_ac97_codec_rloop 
   300                              <1> ;
   301                              <1> ;init_ac97_codec_err1:
   302                              <1> ;	stc
   303                              <1> ;
   304                              <1> ;init_ac97_codec_err2:
   305                              <1> ;	retn
   306                              <1> 
   307                              <1> _ac97_codec_init_ok:
   308                              <1>         ; 11/11/2023
   309                              <1> 	;mov	al, 2 ; force set 16-bit 2-channel PCM
   310                              <1> 	;mov	dx, GLOB_CNT_REG ; 2Ch
   311                              <1> 	;add	dx, [NABMBAR]
   312                              <1> 	;out	dx, eax
   313                              <1> 
   314                              <1> 	;;call	delay1_4ms
   315                              <1> 
   316 0000035B E86600              <1> 	call 	reset_ac97_controller
   317                              <1> 
   318                              <1> 	; 11/11/2023
   319 0000035E E82003              <1> 	call	delay1_4ms
   320                              <1> 
   321                              <1> 	;call 	setup_ac97_codec
   322                              <1> 
   323                              <1> setup_ac97_codec:
   324                              <1> 	; 12/11/2023
   325 00000361 813E[F40A]80BB      <1> 	cmp	word [sample_rate], 48000
   326 00000367 742F                <1> 	je	short skip_rate
   327                              <1> 
   328                              <1> ; 11/11/2023
   329                              <1> ; 05/11/2023
   330                              <1> ;%if 1
   331                              <1> 	AC97_EA_VRA equ BIT0 ; 11/11/2023
   332                              <1> 
   333                              <1> 	; 11/11/2023
   334 00000369 8B16[E20A]          <1> 	mov    	dx, [NAMBAR]               	
   335 0000036D 83C22A              <1> 	add    	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah  	  
   336 00000370 ED                  <1> 	in     	ax, dx
   337 00000371 24FD                <1> 	and	al, ~BIT1 ; Clear DRA
   338 00000373 0C01                <1> 	or	al, AC97_EA_VRA ; 1 ; 04/11/2023
   339 00000375 EF                  <1> 	out	dx, ax			; Enable variable rate audio
   340                              <1> 	
   341 00000376 B90A00              <1> 	mov	cx, 10
   342                              <1> check_vra:
   343 00000379 E8FD00              <1> 	call	delay_100ms
   344                              <1> 
   345                              <1> 	; 11/11/2023
   346 0000037C ED                  <1> 	in	ax, dx
   347 0000037D A801                <1> 	test	al, AC97_EA_VRA ; 1
   348 0000037F 7509                <1> 	jnz	short set_rate
   349                              <1> 
   350                              <1> 	; 11/11/2023
   351 00000381 E2F6                <1> 	loop	check_vra
   352                              <1> 
   353                              <1> 	; 12/11/2023
   354 00000383 58                  <1> 	pop	ax ; discard return address to the caller
   355 00000384 BA[810A]            <1> 	mov	dx, msg_no_vra
   356 00000387 E9D0FD              <1> 	jmp	vra_err
   357                              <1> 
   358                              <1> set_rate:
   359 0000038A A1[F40A]            <1> 	mov	ax, [sample_rate] ; 17/02/2017 (Erdogan Tan)
   360                              <1> 
   361 0000038D 8B16[E20A]          <1> 	mov    	dx, [NAMBAR]               	
   362 00000391 83C22C              <1> 	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch  	  
   363 00000394 EF                  <1> 	out	dx, ax 			; PCM Front/Center Output Sample Rate
   364                              <1> 
   365 00000395 E8E100              <1> 	call	delay_100ms
   366                              <1> 
   367                              <1> 	; 12/11/2023
   368                              <1> skip_rate:
   369                              <1> 	; 11/11/2023 (temporary)
   370                              <1> 
   371                              <1> 	;mov   	dx, [NAMBAR]               	
   372                              <1> 	;add   	dx, CODEC_PCM_SURND_DACRATE_REG	; 2Eh  	  
   373                              <1> 	;out	dx, ax 			; PCM Surround Output Sample Rate
   374                              <1> 
   375                              <1> 	;call	delay_100ms
   376                              <1> 
   377                              <1> 	;mov   	dx, [NAMBAR]               	
   378                              <1> 	;add   	dx, CODEC_PCM_LFE_DACRATE_REG	; 30h  	  
   379                              <1> 	;out	dx, ax 			; PCM LFE Output Sample Rate
   380                              <1> 
   381                              <1> 	;call	delay_100ms
   382                              <1> 
   383                              <1> 	; 05/11/2023 (temporary)
   384                              <1> 	;mov	dx, [NAMBAR]               	
   385                              <1> 	;add	dx, CODEC_LR_ADCRATE_REG 	; 32h  	  
   386                              <1> 	;out	dx, ax 			; PCM Input Sample Rate
   387                              <1> 	;
   388                              <1> 	;call	delay_100ms
   389                              <1> 
   390 00000398 B80202              <1> 	mov	ax, 0202h
   391 0000039B 8B16[E20A]          <1>   	mov     dx, [NAMBAR]
   392 0000039F 83C202              <1>   	add     dx, CODEC_MASTER_VOL_REG	;02h 
   393 000003A2 EF                  <1> 	out     dx, ax
   394                              <1> 
   395                              <1> 	; 11/11/2023
   396                              <1>         ;call	delay1_4ms
   397                              <1>         ;call	delay1_4ms
   398                              <1>         ;call	delay1_4ms
   399                              <1>         ;call	delay1_4ms
   400                              <1>  	;
   401                              <1>   	;mov	dx, [NAMBAR]
   402                              <1>   	;add	dx, CODEC_MASTER_MONO_VOL_REG	;06h 
   403                              <1>   	;out	dx, ax
   404                              <1> 
   405                              <1> 	; 11/11/2023
   406                              <1>         ;call	delay1_4ms
   407                              <1>         ;call	delay1_4ms
   408                              <1>         ;call	delay1_4ms
   409                              <1>         ;call	delay1_4ms
   410                              <1> 	;
   411                              <1> 	;mov	ax, 02h
   412                              <1>   	;mov	dx, [NAMBAR]
   413                              <1>   	;add	dx, CODEC_PCBEEP_VOL_REG	;0Ah 
   414                              <1>   	;out	dx, ax
   415                              <1> 
   416 000003A3 E8DB02              <1>         call    delay1_4ms
   417 000003A6 E8D802              <1>         call    delay1_4ms
   418 000003A9 E8D502              <1>         call    delay1_4ms
   419 000003AC E8D202              <1>         call    delay1_4ms
   420                              <1> 
   421                              <1> 	;mov	ax, 0202h
   422 000003AF 8B16[E20A]          <1>   	mov     dx, [NAMBAR]
   423 000003B3 83C218              <1>   	add     dx, CODEC_PCM_OUT_REG		;18h 
   424 000003B6 EF                  <1>   	out     dx, ax
   425                              <1> 
   426 000003B7 E8C702              <1>         call    delay1_4ms
   427 000003BA E8C402              <1>         call    delay1_4ms
   428 000003BD E8C102              <1>         call    delay1_4ms
   429 000003C0 E8BE02              <1>         call    delay1_4ms
   430                              <1> 
   431                              <1> 	; 11/11/2023
   432                              <1> 	;mov	ax, 8008h ; Mute
   433                              <1>   	;mov	dx, [NAMBAR]
   434                              <1> 	;add	dx, CODEC_PHONE_VOL_REG		;0Ch
   435                              <1> 	;			 ; AC97_PHONE_VOL ; TAD Input (Mono)
   436                              <1>   	;out	dx, ax
   437                              <1> 	;
   438                              <1>         ;call	delay1_4ms
   439                              <1>         ;call	delay1_4ms
   440                              <1>         ;call	delay1_4ms
   441                              <1> 	;call	delay1_4ms
   442                              <1> 
   443                              <1> 	;mov	ax, 0808h
   444                              <1> 	;mov	dx, [NAMBAR]
   445                              <1> 	;add	dx, CODEC_LINE_IN_VOL_REG ;10h ; Line Input (Stereo)
   446                              <1> 	;out	dx, ax
   447                              <1> 	;
   448                              <1>         ;call	delay1_4ms
   449                              <1>         ;call	delay1_4ms
   450                              <1>         ;call	delay1_4ms
   451                              <1> 	;call	delay1_4ms
   452                              <1> 
   453                              <1>   	;mov	dx, [NAMBAR]
   454                              <1>         ;add	dx, CODEC_CD_VOL_REG ;12h ; CD Input (Stereo)
   455                              <1>   	;out	dx, ax
   456                              <1> 	;
   457                              <1>   	;mov	dx, [NAMBAR]
   458                              <1>         ;add	dx, CODEC_AUX_VOL_REG ;16h ; Aux Input (Stereo)
   459                              <1>   	;out	dx, ax
   460                              <1> 	;
   461                              <1>         ;call	delay1_4ms
   462                              <1>         ;call	delay1_4ms
   463                              <1>         ;call	delay1_4ms
   464                              <1> 	;call	delay1_4ms
   465                              <1> 
   466                              <1> ;detect_ac97_codec:
   467 000003C3 C3                  <1>         retn
   468                              <1> 
   469                              <1> reset_ac97_controller:
   470                              <1> 	; 11/11/2023
   471                              <1> 	; 10/06/2017
   472                              <1> 	; 29/05/2017
   473                              <1> 	; 28/05/2017
   474                              <1> 	; reset AC97 audio controller registers
   475 000003C4 31C0                <1> 	xor     ax, ax
   476 000003C6 BA0B00              <1>         mov	dx, PI_CR_REG
   477 000003C9 0316[E40A]          <1> 	add	dx, [NABMBAR]
   478 000003CD EE                  <1> 	out     dx, al
   479                              <1> 
   480 000003CE BA1B00              <1>         mov     dx, PO_CR_REG
   481 000003D1 0316[E40A]          <1> 	add	dx, [NABMBAR]
   482 000003D5 EE                  <1> 	out     dx, al
   483                              <1> 
   484 000003D6 BA2B00              <1>         mov     dx, MC_CR_REG
   485 000003D9 0316[E40A]          <1> 	add	dx, [NABMBAR]
   486 000003DD EE                  <1> 	out     dx, al
   487                              <1> 
   488 000003DE B002                <1>         mov     al, RR
   489 000003E0 BA0B00              <1>         mov     dx, PI_CR_REG
   490 000003E3 0316[E40A]          <1> 	add	dx, [NABMBAR]
   491 000003E7 EE                  <1> 	out     dx, al
   492                              <1> 
   493 000003E8 BA1B00              <1>         mov     dx, PO_CR_REG
   494 000003EB 0316[E40A]          <1> 	add	dx, [NABMBAR]
   495 000003EF EE                  <1> 	out     dx, al
   496                              <1> 
   497 000003F0 BA2B00              <1>         mov     dx, MC_CR_REG
   498 000003F3 0316[E40A]          <1> 	add	dx, [NABMBAR]
   499 000003F7 EE                  <1> 	out     dx, al
   500                              <1> 
   501 000003F8 C3                  <1> 	retn
   502                              <1> 
   503                              <1> reset_ac97_codec:
   504                              <1> 	; 11/11/2023
   505                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
   506 000003F9 BA2C00              <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
   507 000003FC 0316[E40A]          <1> 	add	dx, [NABMBAR]
   508 00000400 66ED                <1> 	in	eax, dx
   509                              <1> 
   510                              <1> 	;test	eax, 2
   511                              <1> 	; 06/08/2022
   512 00000402 A802                <1> 	test	al, 2
   513 00000404 7405                <1> 	jz	short _r_ac97codec_cold	
   514                              <1> 
   515 00000406 E80E00              <1> 	call	warm_ac97codec_reset
   516 00000409 7306                <1> 	jnc	short _r_ac97codec_ok
   517                              <1> _r_ac97codec_cold:
   518 0000040B E83400              <1>         call    cold_ac97codec_reset
   519 0000040E 7301                <1>         jnc     short _r_ac97codec_ok
   520                              <1> 	
   521                              <1> 	; 16/04/2017
   522                              <1>         ;xor	eax, eax	; timeout error
   523                              <1>        	;stc
   524 00000410 C3                  <1> 	retn
   525                              <1> 
   526                              <1> _r_ac97codec_ok:
   527 00000411 6631C0              <1>         xor     eax, eax
   528                              <1>         ;mov	al, VIA_ACLINK_C00_READY ; 1
   529 00000414 FEC0                <1>         inc	al
   530 00000416 C3                  <1> 	retn
   531                              <1> 
   532                              <1> warm_ac97codec_reset:
   533                              <1> 	; 11/11/2023
   534                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
   535                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
   536 00000417 66B806000000        <1> 	mov	eax, 6
   537 0000041D BA2C00              <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
   538 00000420 0316[E40A]          <1> 	add	dx, [NABMBAR]
   539 00000424 66EF                <1> 	out	dx, eax
   540                              <1> 
   541 00000426 B90A00              <1> 	mov	cx, 10	; total 1s
   542                              <1> _warm_ac97c_rst_wait:
   543 00000429 E84D00              <1> 	call	delay_100ms
   544                              <1> 
   545 0000042C BA3000              <1> 	mov	dx, GLOB_STS_REG ; 30h
   546 0000042F 0316[E40A]          <1> 	add	dx, [NABMBAR]
   547 00000433 66ED                <1> 	in	eax, dx
   548                              <1> 
   549 00000435 66A900030010        <1> 	test	eax, CTRL_ST_CREADY
   550 0000043B 7504                <1> 	jnz	short _warm_ac97c_rst_ok
   551                              <1> 
   552 0000043D 49                  <1>         dec     cx
   553 0000043E 75E9                <1>         jnz     short _warm_ac97c_rst_wait
   554                              <1> 
   555                              <1> _warm_ac97c_rst_fail:
   556 00000440 F9                  <1>         stc
   557                              <1> _warm_ac97c_rst_ok:
   558 00000441 C3                  <1> 	retn
   559                              <1> 
   560                              <1> cold_ac97codec_reset:
   561                              <1> 	; 11/11/2023
   562                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
   563                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
   564 00000442 66B802000000        <1>         mov	eax, 2
   565 00000448 BA2C00              <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
   566 0000044B 0316[E40A]          <1> 	add	dx, [NABMBAR]
   567 0000044F 66EF                <1> 	out	dx, eax
   568                              <1> 
   569 00000451 E82500              <1> 	call	delay_100ms 	; wait 100 ms
   570 00000454 E82200              <1> 	call	delay_100ms 	; wait 100 ms
   571 00000457 E81F00              <1> 	call	delay_100ms 	; wait 100 ms
   572 0000045A E81C00              <1> 	call	delay_100ms 	; wait 100 ms
   573                              <1> 
   574 0000045D B91000              <1> 	mov	cx, 16	; total 20*100 ms = 2s
   575                              <1> 
   576                              <1> _cold_ac97c_rst_wait:
   577 00000460 BA3000              <1> 	mov	dx, GLOB_STS_REG ; 30h
   578 00000463 0316[E40A]          <1> 	add	dx, [NABMBAR]
   579 00000467 66ED                <1> 	in	eax, dx
   580                              <1> 
   581 00000469 66A900030010        <1> 	test	eax, CTRL_ST_CREADY
   582 0000046F 7507                <1> 	jnz	short _cold_ac97c_rst_ok
   583                              <1> 
   584 00000471 E80500              <1> 	call	delay_100ms
   585                              <1> 
   586 00000474 49                  <1>         dec     cx
   587 00000475 75E9                <1>         jnz     short _cold_ac97c_rst_wait
   588                              <1> 
   589                              <1> _cold_ac97c_rst_fail:
   590 00000477 F9                  <1>         stc
   591                              <1> _cold_ac97c_rst_ok:
   592 00000478 C3                  <1> 	retn
   593                              <1> 
   594                              <1> delay_100ms:
   595                              <1> 	; 11/11/2023
   596                              <1> 	; 29/05/2017
   597                              <1> 	; 24/03/2017 ('codec.asm')
   598                              <1> 	; wait 100 ms
   599 00000479 51                  <1> 	push	cx
   600 0000047A B99001              <1> 	mov	cx, 400  ; 400*0.25ms
   601                              <1> _delay_x_ms:
   602 0000047D E80102              <1> 	call	delay1_4ms
   603 00000480 E2FB                <1>         loop	_delay_x_ms
   604 00000482 59                  <1> 	pop	cx
   605 00000483 C3                  <1> 	retn
   606                              <1> 
   607                              <1> %endif
   608                              <1> 
   609                              <1> ; 11/11/2023
   610                              <1> %if 0
   611                              <1> 
   612                              <1> codecConfig:
   613                              <1> 	; 06/11/2023
   614                              <1> 	; TUNELOOP version (playing without interrupt)
   615                              <1> 	; 04/11/2023
   616                              <1> 	; 17/02/2017 
   617                              <1> 	; 07/11/2016 (Erdogan Tan)
   618                              <1> 
   619                              <1> 	mov	ax, [sample_rate] ; 17/02/2017 (Erdogan Tan)
   620                              <1> 
   621                              <1> 	mov    	dx, [NAMBAR]               	
   622                              <1> 	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch  	  
   623                              <1> 	out	dx, ax 				; out sample rate
   624                              <1> 		
   625                              <1> 	; 05/11/2023 temp
   626                              <1> 	;mov	dx, [NAMBAR]               	
   627                              <1> 	;add	dx, CODEC_LR_ADCRATE_REG 	; 32h  	  
   628                              <1> 	;out	dx, ax 
   629                              <1> 
   630                              <1>         call    delay1_4ms
   631                              <1>         call    delay1_4ms
   632                              <1>         call    delay1_4ms
   633                              <1>         call    delay1_4ms
   634                              <1> 
   635                              <1> 	mov	eax, [dev_vendor]
   636                              <1>         cmp	eax, (SI7012_DID<<16)+SIS_VID
   637                              <1>         jne	short cConfig1
   638                              <1> 
   639                              <1> 	; Unmute quirk specifically for the SiS7012
   640                              <1> 
   641                              <1> 	CUSTOM_SIS_7012_REG equ 4Ch ; SiS7012-specific register
   642                              <1> 	
   643                              <1>         mov     dx, [NABMBAR]
   644                              <1>         add     dx, CUSTOM_SIS_7012_REG
   645                              <1>         in      ax, dx
   646                              <1>         or	al, 1
   647                              <1>         out     dx, ax
   648                              <1> 
   649                              <1> cConfig1:
   650                              <1> 	; 03/11/2023 (MPXPLAY, 'SC_ICH.C', ac97_init)
   651                              <1> 	; initial ac97 volumes (and clear mute flag)
   652                              <1> 		
   653                              <1>   	mov     dx, [NAMBAR]
   654                              <1>   	add     dx, CODEC_MASTER_VOL_REG        ;02h ; STEREO
   655                              <1>   	;xor	ax, ax ; volume attenuation = 0 (max. volume)
   656                              <1>   	; 03/11/2023
   657                              <1> 	mov	ax, 0202h
   658                              <1> 	out     dx, ax
   659                              <1> 
   660                              <1>         call    delay1_4ms	; delays because codecs are slow
   661                              <1>         call    delay1_4ms
   662                              <1>         call    delay1_4ms
   663                              <1>         call    delay1_4ms
   664                              <1>  
   665                              <1>   	mov     dx, [NAMBAR]
   666                              <1>   	add     dx, CODEC_PCM_OUT_REG		;18h
   667                              <1>   	;;xor	ax, ax
   668                              <1> 	;mov	ax, 0202h
   669                              <1>   	out     dx, ax
   670                              <1> 
   671                              <1>         call    delay1_4ms
   672                              <1>         call    delay1_4ms
   673                              <1>         call    delay1_4ms
   674                              <1>         call    delay1_4ms
   675                              <1>  
   676                              <1> 	retn
   677                              <1> 
   678                              <1> %endif
   449                                  ;%include 'ich_wav.asm' ; 17/02/2017 (ICH AC97 wav playing functions)
   450                                  %include 'ich_wave.asm' ; 11/11/2023 (ICH AC97 wav playing functions)
     1                              <1> ; 11/11/2023
     2                              <1> ; 10/11/2023
     3                              <1> ; 09/11/2023
     4                              <1> ; 03/11/2023 - 08/11/2023
     5                              <1> ; DOS based .WAV player using AC'97 and codec interface.
     6                              <1> ; ---------------------------------------------------------------
     7                              <1> ; NASM version: Erdogan Tan (29/11/2016)
     8                              <1> ; Last Update: 17/02/2017 (by Erdogan Tan)
     9                              <1> 
    10                              <1> ; AC97 interrupt version - 09/11/2023 - Erdogan Tan
    11                              <1> 
    12                              <1> ; ICHWAV.ASM
    13                              <1> 
    14                              <1> ; player internal variables and other equates.
    15                              <1> BUFFERSIZE      equ     64 * 1024       ; 64k file buffer size.
    16                              <1> ENDOFFILE       equ     BIT0            ; flag for knowing end of file
    17                              <1> 
    18                              <1> ;===========================================================================
    19                              <1> ; entry: none. File is already open and [filehandle] filled.
    20                              <1> ; exit:  not until the song is finished or the user aborts.
    21                              <1> ;
    22                              <1> playWav:
    23                              <1> 	; 07/11/2023
    24                              <1> 	; clear buffer 2
    25                              <1>         ;push	es
    26                              <1> 	;mov	ax, [WAV_BUFFER2]
    27                              <1> 	;mov	es, ax
    28                              <1> 	;sub	ax, ax
    29                              <1> 	;mov	di, ax ; 17/02/2017
    30                              <1> 	;mov	cx, (BUFFERSIZE/2)
    31                              <1> 	;rep	stosw
    32                              <1> 	;pop	es	     
    33                              <1> 	
    34                              <1> 	; load 64k into buffer 1
    35 00000484 A1[E80A]            <1>         mov     ax, [WAV_BUFFER1]
    36 00000487 E81401              <1>         call    loadFromFile
    37                              <1> 
    38                              <1> 	; and 64k into buffer 2
    39 0000048A A1[EA0A]            <1> 	mov     ax, [WAV_BUFFER2]
    40 0000048D E80E01              <1>        	call    loadFromFile
    41                              <1> 
    42                              <1> ; register reset the DMA engine. This may cause a pop noise on the output
    43                              <1> ; lines when the device is reset. Prolly a better idea to mute output, then
    44                              <1> ; reset.
    45                              <1> 
    46                              <1> 	; 11/11/2023
    47                              <1>         ;mov	dx, [NABMBAR]
    48                              <1>         ;add	dx, PO_CR_REG		; set pointer to Ctrl reg
    49                              <1>         ;mov	al, RR			; set reset
    50                              <1> 	;out	dx, al			; self clearing bit
    51                              <1> 
    52                              <1> ; write last valid index to 31 to start with.
    53                              <1> ; The Last Valid Index register tells the DMA engine when to stop playing.
    54                              <1> ; 
    55                              <1> ; As we progress through the song we change the last valid index to always be
    56                              <1> ; something other than the index we're currently playing.  
    57                              <1> ;
    58                              <1> 	; 08/11/2023
    59                              <1> 	;; 07/11/2023
    60                              <1> 	;mov	al, 1
    61                              <1>         ;;mov	al, 31
    62                              <1> 	;call	setLastValidIndex
    63                              <1> 
    64                              <1> ; create Buffer Descriptor List
    65                              <1> ;
    66                              <1> ; A buffer descriptor list is a list of pointers and control bits that the
    67                              <1> ; DMA engine uses to know where to get the .wav data and how to play it.
    68                              <1> ;
    69                              <1> ; I set it up to use only 2 buffers of .wav data, and whenever 1 buffer is
    70                              <1> ; playing, I refresh the other one with good data.
    71                              <1> ;
    72                              <1> ;
    73                              <1> ; For the control bits, you can specify that the DMA engine fire an interrupt
    74                              <1> ; after a buffer has been processed, but I poll the current index register
    75                              <1> ; to know when it's safe to update the other buffer.
    76                              <1> ;
    77                              <1> ; I set the BUP bit, which tells the DMA engine to just play 0's (silence)
    78                              <1> ; if it ever runs out of data to play. Good for safety.
    79                              <1> ;
    80 00000490 06                  <1>         push    es
    81 00000491 A1[E60A]            <1>         mov     ax, [BDL_BUFFER]		; get segment # for BDL
    82 00000494 8EC0                <1>         mov     es, ax
    83                              <1> 
    84 00000496 B91000              <1>         mov     cx, 32 / 2                      ; make 32 entries in BDL
    85 00000499 31FF                <1>         xor     di, di                          
    86                              <1> _0:
    87                              <1> 
    88                              <1> ; set buffer descriptor 0 to start of data file in memory
    89 0000049B 660FB706[E80A]      <1>         movzx   eax, word [WAV_BUFFER1]
    90 000004A1 66C1E004            <1>         shl     eax, 4                          ; convert seg:off ->0:offset
    91 000004A5 66AB                <1>         stosd                                   ; store pointer to wavbuffer1
    92                              <1> 
    93                              <1> ;
    94                              <1> ; set length to 32k samples. 1 sample is 16bits or 2bytes.
    95                              <1> ; Set control (bits 31:16) to BUP, bits 15:0=number of samples.
    96                              <1> ; 
    97                              <1> 
    98                              <1> ; 17/02/2017 (Erdogan Tan)
    99                              <1> ; Intel® 82801AA (ICH) & Intel® 82801AB (ICH0) I/O Controller Hub AC’97
   100                              <1> ; Programmer’s Reference Manual
   101                              <1> 
   102                              <1> ; 2.2.1 Buffer Descriptor List  (on Page 13)
   103                              <1> 	;
   104                              <1> 	;  Generic Form of Buffer Descriptor
   105                              <1> 	;  ---------------------------------
   106                              <1> 	;  63   62    61-48    47-32   31-0
   107                              <1> 	;  ---  ---  --------  ------- -----
   108                              <1> 	;  IOC  BUP -reserved- Buffer  Buffer
   109                              <1> 	;		      Length   Pointer
   110                              <1> 	;		      [15:0]   [31:0]
   111                              <1> 	;
   112                              <1> 	;  IOC:	Interrupt On Completion. 
   113                              <1> 	;	1 = Enabled. 
   114                              <1> 	;	    When this is set, it means that the controller should
   115                              <1> 	;	    issue an interrupt upon completion of this buffer.
   116                              <1> 	;	    It should also set the IOC bit in the status register
   117                              <1> 	;	0 = Disabled	
   118                              <1> 	;
   119                              <1> 	;  BUP: Buffer Underrun Policy.
   120                              <1> 	;       0 = When this buffer is complete,
   121                              <1> 	;	    if the next buffer is not yet ready 
   122                              <1> 	;	    (i.e., the last valid buffer has been processed),
   123                              <1> 	;	    then continue to transmit the last valid sample.
   124                              <1> 	;	1 = When this buffer is complete,
   125                              <1> 	;     	    if this is the last valid buffer, transmit zeros after
   126                              <1> 	;	    this buffer has been processed completely.
   127                              <1> 	;	    This bit typically is set only if this is the last 
   128                              <1> 	;	    buffer in the current stream.
   129                              <1> 	;
   130                              <1> 	; [31:0]: Buffer pointer. This field points to the location of
   131                              <1> 	;	  the data buffer. Since samples can be as wide as one
   132                              <1> 	;	  word, the buffer must be aligned with word boundaries,
   133                              <1> 	;	  to prevent samples from straddling DWord boundaries.
   134                              <1> 	;
   135                              <1> 	; [15:0]: Buffer Length: This is the length of the data buffer,
   136                              <1> 	;	  in number of samples. The controller uses this data
   137                              <1> 	;	  to determine the length of the buffer, in bytes.
   138                              <1> 	;	  "0" indicates no sample to process.
   139                              <1> 
   140                              <1> ; ICH2AC97.INC
   141                              <1> 
   142                              <1> ;	IOC	equ     BIT31   ; Fire an interrupt whenever this
   143                              <1> 				; buffer is complete.
   144                              <1> 
   145                              <1> ;	BUP	equ     BIT30   ; Buffer Underrun Policy.
   146                              <1> 				; if this buffer is the last buffer
   147                              <1> 				; in a playback, fill the remaining
   148                              <1> 				; samples with 0 (silence) or not.
   149                              <1> 				; It's a good idea to set this to 1
   150                              <1> 				; for the last buffer in playback,
   151                              <1> 				; otherwise you're likely to get a lot
   152                              <1> 				; of noise at the end of the sound.
   153                              <1> ;
   154                              <1> ; Bits 15:0 contain the length of the buffer, in number of samples, which
   155                              <1> ; are 16 bits each, coupled in left and right pairs, or 32bits each.
   156                              <1> ; Luckily for us, that's the same format as .wav files.
   157                              <1> ;
   158                              <1> ; A value of FFFF is 65536 samples. Running at 44.1Khz, that's just about
   159                              <1> ; 1.5 seconds of sample time. FFFF * 32bits is 1FFFFh bytes or 128k of data.
   160                              <1> ;
   161                              <1> ; A value of 0 in these bits means play no samples.
   162                              <1> ;
   163                              <1> 
   164                              <1> ; ICHWAV.ASM
   165                              <1> 
   166 000004A7 66B800800000        <1> 	mov	eax, BUFFERSIZE / 2 ; size of half buffer (32K)
   167                              <1> 	; 09/11/2023
   168 000004AD 660D000000C0        <1> 	or	eax, IOC + BUP
   169                              <1> 	; 06/11/2023
   170                              <1> 	;or	eax, BUP
   171 000004B3 66AB                <1> 	stosd
   172                              <1> 
   173                              <1> ; 2nd buffer:
   174                              <1> 
   175 000004B5 660FB706[EA0A]      <1>         movzx   eax, word [WAV_BUFFER2]
   176 000004BB 66C1E004            <1>         shl     eax, 4                          ; convert seg:off ->0:offset
   177 000004BF 66AB                <1>         stosd                                   ; store pointer to wavbuffer2
   178                              <1> 
   179                              <1> ; set length to 64k (32k of two 16 bit samples)
   180                              <1> ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
   181                              <1> ; 
   182 000004C1 66B800800000        <1> 	mov	eax, BUFFERSIZE / 2
   183                              <1> 	; 09/11/2023
   184 000004C7 660D000000C0        <1> 	or	eax, IOC + BUP
   185                              <1> 	; 06/11/2023
   186                              <1> 	;or	eax, BUP
   187 000004CD 66AB                <1> 	stosd
   188                              <1> 
   189 000004CF E2CA                <1>         loop    _0
   190 000004D1 07                  <1>         pop     es
   191                              <1> 
   192                              <1> ;
   193                              <1> ; tell the DMA engine where to find our list of Buffer Descriptors.
   194                              <1> ; this 32bit value is a flat mode memory offset (ie no segment:offset)
   195                              <1> ;
   196                              <1> ; write NABMBAR+10h with offset of buffer descriptor list
   197                              <1> ;
   198 000004D2 660FB706[E60A]      <1>         movzx   eax, word [BDL_BUFFER]
   199 000004D8 66C1E004            <1> 	shl     eax, 4                          ; convert seg:off to 0:off
   200 000004DC 8B16[E40A]          <1>         mov     dx, [NABMBAR]
   201 000004E0 83C210              <1>         add     dx, PO_BDBAR_REG                ; set pointer to BDL
   202 000004E3 66EF                <1>         out     dx, eax                         ; write to AC97 controller
   203                              <1> 
   204                              <1> ;
   205                              <1> ; All set. Let's play some music.
   206                              <1> ;
   207                              <1> 
   208                              <1> 	; 10/11/2023
   209                              <1> 	; 08/11/2023
   210                              <1> 	; 07/11/2023
   211                              <1> 	; 08/12/2016
   212                              <1> 	; 07/10/2016
   213                              <1> 	;mov	al, 1
   214 000004E5 B01F                <1> 	mov	al, 31
   215 000004E7 A2[FC0A]            <1> 	mov	[LVI], al ; 10/11/2023
   216 000004EA E87E01              <1> 	call	setLastValidIndex
   217                              <1> 
   218                              <1> 	; 06/11/2023 (not neccessary)
   219                              <1> 	;; 05/11/2023
   220                              <1> 	;; reset current index
   221                              <1> 	;mov	al, 0
   222                              <1> 	;call	setCurrentIndex
   223                              <1> 
   224                              <1> 	; 06/11/2023
   225                              <1> 	;mov	byte [tLoop], 1 ; 30/11/2016
   226                              <1> 
   227                              <1> 	; 17/02/2017
   228 000004ED 8B16[E40A]          <1>         mov     dx, [NABMBAR]
   229 000004F1 83C21B              <1>         add     dx, PO_CR_REG                   ; PCM out Control Register
   230                              <1>         ; 09/11/2023
   231 000004F4 B011                <1> 	mov	al, IOCE + RPBM	; Enable 'Interrupt On Completion' + run
   232                              <1> 	;			; (LVBI interrupt will not be enabled)
   233                              <1> 	; 06/11/2023 (TUNELOOP version, without interrupt)
   234                              <1> 	;mov	al, RPBM
   235 000004F6 EE                  <1> 	out     dx, al                          ; Start bus master operation.
   236                              <1> 
   237                              <1> 	; 09/11/2023
   238 000004F7 C606[FB0A]3F        <1> 	mov	byte [b_indicator], '?'	
   239                              <1> 
   240                              <1> 	; 06/11/2023
   241                              <1> 	;call	delay1_4ms
   242                              <1> 	;call	delay1_4ms
   243                              <1> 	;call	delay1_4ms
   244                              <1> 	;call	delay1_4ms
   245                              <1> 
   246                              <1> 	; 10/11/2023
   247                              <1> 	;mov	byte [tloop], 1
   248                              <1> 
   249                              <1> ; while DMA engine is running, examine current index and wait until it hits 1
   250                              <1> ; as soon as it's 1, we need to refresh the data in wavbuffer1 with another
   251                              <1> ; 64k. Likewise when it's playing buffer 2, refresh buffer 1 and repeat.
   252                              <1> 
   253                              <1> ; 09/11/2023   
   254                              <1> ; 06/11/2023
   255                              <1> %if 1
   256                              <1> 	; 08/12/2016
   257                              <1> 	; 28/11/2016
   258                              <1> p_loop:
   259 000004FC E87501              <1> 	call    check4keyboardstop ; keyboard halt?
   260 000004FF 732A                <1>         jnc	short r_loop 	   ; no ; 09/11/2023
   261                              <1> 
   262                              <1> 	; 09/11/2023
   263                              <1> 	;or	byte [flags], ENDOFFILE
   264                              <1> 	;mov	byte [b_indicator], '0'
   265                              <1> q_loop:
   266                              <1> 	;mov	al, '0'
   267 00000501 E88C00              <1> 	call	tL0
   268                              <1> 
   269                              <1> 	; 04/11/2023
   270                              <1> 	; finished with song, stop everything
   271 00000504 E89803              <1> 	call	ac97_stop
   272                              <1> 
   273                              <1> 	; 11/11/2023
   274                              <1> irq_restore:	
   275                              <1> 	; restore previous interrupt vector and interrupt_status
   276 00000507 FA                  <1> 	cli
   277 00000508 E4A1                <1> 	in	al, 0A1h ; irq 8-15
   278 0000050A A0[DD0A]            <1> 	mov	al, [IRQ_status+1]
   279 0000050D E6A1                <1> 	out	0A1h, al 
   280 0000050F E421                <1> 	in	al, 021h ; irq 0-7
   281 00000511 A0[DC0A]            <1> 	mov	al, [IRQ_status]
   282 00000514 E621                <1> 	out	21h, al 
   283                              <1> 	; ...
   284 00000516 06                  <1> 	push	es
   285 00000517 31C0                <1> 	xor	ax, ax
   286 00000519 8EC0                <1> 	mov	es, ax
   287 0000051B A1[DE0A]            <1> 	mov	ax, [IRQ_vector]
   288 0000051E 268907              <1> 	mov	[es:bx], ax
   289 00000521 A1[E00A]            <1> 	mov	ax, [IRQ_vector+2]
   290 00000524 26894702            <1> 	mov	[es:bx+2], ax
   291 00000528 07                  <1> 	pop	es
   292 00000529 FB                  <1> 	sti
   293 0000052A C3                  <1> 	retn
   294                              <1> 
   295                              <1> r_loop:
   296                              <1> 	; 10/11/2023
   297                              <1> 	;nop
   298                              <1> 	;nop
   299                              <1> 	;nop
   300                              <1> 
   301                              <1> 	; 11/11/2023	
   302 0000052B B030                <1> 	mov	al, '0'
   303 0000052D 803E[DB0A]00        <1> 	cmp	byte [tloop], 0
   304 00000532 74C8                <1> 	je	short p_loop
   305 00000534 7CCB                <1> 	jl	short q_loop
   306                              <1> 
   307 00000536 FE0E[DB0A]          <1> 	dec	byte [tloop] ; 0
   308                              <1> 
   309 0000053A 803E[FB0A]31        <1> 	cmp	byte [b_indicator], '1'
   310 0000053F 7514                <1> 	jne	short s_loop
   311                              <1> 
   312                              <1> 	; load buffer 1
   313 00000541 A1[E80A]            <1> 	mov	ax, [WAV_BUFFER1]
   314                              <1> u_loop:
   315 00000544 E85700              <1> 	call	loadFromFile
   316 00000547 7304                <1> 	jnc	short v_loop
   317 00000549 B030                <1> 	mov	al, '0'
   318 0000054B EBB4                <1> 	jmp	short q_loop
   319                              <1> v_loop:
   320                              <1> 	; 09/11/2023 - Erdogan Tan
   321                              <1> 	; (print buffer number on top left of the screen)
   322 0000054D A0[FB0A]            <1> 	mov	al, [b_indicator]
   323 00000550 E83D00              <1> 	call	tL0
   324 00000553 EBA7                <1> 	jmp	short p_loop
   325                              <1> s_loop:
   326                              <1> 	; load buffer 2
   327 00000555 A1[EA0A]            <1> 	mov	ax, [WAV_BUFFER2]
   328 00000558 EBEA                <1> 	jmp	short u_loop
   329                              <1> 
   330                              <1> %endif
   331                              <1> 
   332                              <1> ; while DMA engine is running, examine current index and wait until it hits 1
   333                              <1> ; as soon as it's 1, we need to refresh the data in wavbuffer1 with another
   334                              <1> ; 64k. Likewise when it's playing buffer 2, refresh buffer 1 and repeat.
   335                              <1> 
   336                              <1> ; 11/11/2023
   337                              <1> ; 10/11/2023
   338                              <1> ; 09/11/2023
   339                              <1> ; 08/11/2023
   340                              <1> ; 07/11/2023
   341                              <1> %if 1
   342                              <1> 
   343                              <1> tuneLoop:
   344                              <1> 	; 11/11/2023
   345                              <1> 	; 10/11/2023
   346                              <1> 	; 09/11/2023
   347                              <1> 	; 08/11/2023
   348                              <1> 	; 06/11/2023
   349                              <1> 	;mov	al, '1'
   350                              <1> 	;call	tL0
   351                              <1> tL1:
   352                              <1> 	; 10/11/2023
   353                              <1> 	;mov	byte [tloop], 1
   354                              <1> 
   355                              <1> 	; 11/11/2023
   356                              <1> 	;call    updateLVI	; set LVI != CIV
   357                              <1> 	;jz	short tL4	
   358                              <1> 
   359                              <1> 	; 11/11/2023
   360 0000055A C606[DB0A]01        <1> 	mov	byte [tloop], 1
   361                              <1> 
   362 0000055F E80001              <1> 	call    getCurrentIndex
   363                              <1> 
   364                              <1> 	; 10/11/2023
   365 00000562 3A06[FC0A]          <1> 	cmp	al, [LVI]
   366 00000566 7511                <1> 	jne	short tL2
   367                              <1> 
   368 00000568 F606[D80A]01        <1> 	test	byte [flags], ENDOFFILE
   369                              <1> 	;jnz	short tL2
   370 0000056D 751A                <1> 	jnz	short tL4
   371                              <1> 
   372 0000056F 48                  <1> 	dec	ax
   373 00000570 241F                <1> 	and	al, 1Fh 
   374 00000572 E8F600              <1> 	call	setLastValidIndex	
   375 00000575 8606[FC0A]          <1> 	xchg	al, [LVI]
   376                              <1> 
   377                              <1> tL2:
   378 00000579 A801                <1> 	test	al, BIT0
   379 0000057B 7406                <1> 	jz	short tL3
   380                              <1> 
   381 0000057D C606[FB0A]31        <1> 	mov	byte [b_indicator], '1'
   382 00000582 C3                  <1> 	retn
   383                              <1> tL3:	
   384 00000583 C606[FB0A]32        <1> 	mov	byte [b_indicator], '2'
   385 00000588 C3                  <1> 	retn
   386                              <1> tL4:
   387                              <1> 	; 11/11/2023
   388 00000589 C606[DB0A]FF        <1> 	mov	byte [tloop], -1
   389 0000058E F9                  <1> 	stc
   390 0000058F C3                  <1> 	retn
   391                              <1> 
   392                              <1> 
   393                              <1> 	; 06/11/2023
   394                              <1> tL0:
   395                              <1> 	; 08/11/2023
   396                              <1> 	; 05/11/2023
   397                              <1> 	; 17/02/2017 - Buffer switch test (temporary)
   398                              <1> 	; 06/11/2023
   399                              <1> 	; al = buffer indicator ('1', '2' or '0' -stop- )
   400 00000590 1E                  <1> 	push	ds
   401                              <1> 	;push	bx 
   402 00000591 BB00B8              <1> 	mov	bx, 0B800h ; video display page segment
   403 00000594 8EDB                <1> 	mov	ds, bx
   404 00000596 29DB                <1> 	sub	bx, bx ; 0
   405 00000598 B44E                <1> 	mov	ah, 4Eh
   406 0000059A 8907                <1> 	mov	[bx], ax ; show current play buffer (1, 2)
   407                              <1> 	;pop	bx
   408 0000059C 1F                  <1> 	pop	ds
   409 0000059D C3                  <1> 	retn
   410                              <1> 
   411                              <1> %endif
   412                              <1> 
   413                              <1> ; 08/11/2023
   414                              <1> ; 07/11/2023
   415                              <1> %if 0
   416                              <1> 
   417                              <1> tuneLoop:
   418                              <1> 	; 07/11/2023
   419                              <1> 	;mov	dx, NABMBAR
   420                              <1> 	;add	dx, PO_CIV_REG ; 14h
   421                              <1> tL1:
   422                              <1> 	call    updateLVI	; set LVI != CIV
   423                              <1> 	call    check4keyboardstop
   424                              <1> 	jc	short _exit_
   425                              <1> 	call    getCurrentIndex
   426                              <1> 	test	al, BIT0
   427                              <1> 	jz	short tL1	; loop if buffer 2 is not playing
   428                              <1> 
   429                              <1> 	; load buffer 1
   430                              <1> 	mov     ax, [WAV_BUFFER1]
   431                              <1> 	call	loadFromFile
   432                              <1> 	jc	short _exit_	; end of file
   433                              <1> tL2:
   434                              <1> 	call    updateLVI
   435                              <1> 	call    check4keyboardstop
   436                              <1> 	jc	short _exit_
   437                              <1> 	call    getCurrentIndex
   438                              <1> 	test	al, BIT0
   439                              <1> 	jnz	short tL2	; loop if buffer 1 is not playing
   440                              <1> 
   441                              <1> 	; load buffer 2
   442                              <1> 	mov     ax, [WAV_BUFFER2]
   443                              <1> 	call	loadFromFile
   444                              <1> 	jnc	short tuneLoop
   445                              <1> _exit_:
   446                              <1> 	mov	dx, [NABMBAR]		
   447                              <1> 	add	dx, PO_CR_REG	; PCM out Control Register
   448                              <1> 	mov	al, 0
   449                              <1> 	out	dx, al		; stop player
   450                              <1> 	retn
   451                              <1> 
   452                              <1> %endif
   453                              <1> 
   454                              <1> ; load data from file in 32k chunks. Would be nice to load 1 64k chunk,
   455                              <1> ; but in DOS you can only load FFFF bytes at a time.
   456                              <1> ;
   457                              <1> ; entry: ax = segment to load data to
   458                              <1> ; exit: CY set if end of file reached.
   459                              <1> ; note: last file buffer is padded with 0's to avoid pops at the end of song.
   460                              <1> ; assumes file is already open. uses [filehandle]
   461                              <1> 
   462                              <1> ; 07/11/2023
   463                              <1> %if 0
   464                              <1> 
   465                              <1> loadFromFile:
   466                              <1> 	; 07/11/2023
   467                              <1> 	; 06/11/2023
   468                              <1> 	; 17/02/2017
   469                              <1> 	;push	ax
   470                              <1> 	;push	cx
   471                              <1> 	;push	dx
   472                              <1> 	;push	bx
   473                              <1> 
   474                              <1> 	;push	es
   475                              <1> 	;push	ds
   476                              <1> 	
   477                              <1>         test    byte [flags], ENDOFFILE	; have we already read the
   478                              <1> 	;stc				; last of the file?
   479                              <1> 	; 05/11/2023
   480                              <1> 	;jnz	endLFF
   481                              <1> 	jz	short lff_12	; 06/11/2023
   482                              <1> 	; 06/11/2023
   483                              <1> 	;;mov	byte [tLoop], 0
   484                              <1> 	;jmp	endLFF
   485                              <1> 	stc
   486                              <1> 	retn
   487                              <1> 
   488                              <1> lff_12:	; 06/11/2023    
   489                              <1> 	mov	[fbs_seg], ax ; save buffer segment
   490                              <1> 	xor	dx, dx
   491                              <1> lff_0:
   492                              <1> 	mov	[fbs_off], dx ; buffer offset
   493                              <1> 
   494                              <1> 	mov     bx, (BUFFERSIZE / 2)	; 32k chunk
   495                              <1> 	mov	cl, [fbs_shift]   
   496                              <1> 	and	cl, cl
   497                              <1> 	jz	short lff_1 ; stereo, 16 bit	
   498                              <1> 
   499                              <1> 	; fbs_shift =
   500                              <1> 	;	2 for mono and 8 bit sample (multiplier = 4)
   501                              <1> 	;	1 for mono or 8 bit sample (multiplier = 2)
   502                              <1> 	shr	bx, cl ; 32K / multiplier
   503                              <1> 
   504                              <1> 	mov	ax, cs
   505                              <1> 	mov	dx, temp_buffer ; temporary buffer for wav data
   506                              <1> lff_1:
   507                              <1> 	; 17/02/2017 (stereo/mono, 8bit/16bit corrections)
   508                              <1> 	; load file into memory
   509                              <1>         mov	cx, bx                         
   510                              <1> 	mov	bx, [filehandle]
   511                              <1> 	mov     ds, ax
   512                              <1>        	mov	ah, 3fh
   513                              <1> 	int	21h
   514                              <1> 
   515                              <1> 	mov	bx, cs
   516                              <1> 	mov	ds, bx
   517                              <1> 
   518                              <1> 	jc	short lff_9 ; error !
   519                              <1> 
   520                              <1> 	and	ax, ax
   521                              <1> 	jz	short lff_10
   522                              <1> 	
   523                              <1> 	mov	bl, [fbs_shift] ; shift count  
   524                              <1> 	or	bl, bl
   525                              <1> 	jz	short lff_7 ; 16 bit stereo samples
   526                              <1> 
   527                              <1> 	push	es
   528                              <1> 	; 06/11/2023
   529                              <1> 	;push	di
   530                              <1> 	;push	si
   531                              <1> 	mov	di, [fbs_off]
   532                              <1> 	mov	si, [fbs_seg] ; buffer segment
   533                              <1> 	mov	es, si
   534                              <1> 	mov	si, temp_buffer ; temporary buffer address
   535                              <1> 	mov	cl, [bps] ; bits per sample (8 or 16)
   536                              <1> 	cmp	cl, 8
   537                              <1> 	jne	short lff_4 ; 16 bit samples
   538                              <1> 	; 8 bit samples
   539                              <1> 	mov	cx, ax ; byte count
   540                              <1> 	dec	bl  ; shift count, 1 = stereo, 2 = mono
   541                              <1> 	jz	short lff_3 ; 8 bit, stereo
   542                              <1> lff_2:
   543                              <1> 	; mono & 8 bit
   544                              <1> 	lodsb
   545                              <1> 	shl	ax, 8 ; convert 8 bit sample to 16 bit sample
   546                              <1> 	stosw	; left channel
   547                              <1> 	stosw	; right channel
   548                              <1> 	loop	lff_2
   549                              <1> 	jmp	short lff_6	
   550                              <1> lff_3:
   551                              <1> 	; stereo & 8 bit
   552                              <1> 	lodsb
   553                              <1> 	shl	ax, 8 ; convert 8 bit sample to 16 bit sample
   554                              <1> 	stosw
   555                              <1> 	loop	lff_3			
   556                              <1> 	jmp	short lff_6
   557                              <1> lff_4:
   558                              <1> 	; 16 bit mono samples
   559                              <1> 	mov	cx, ax ; word count
   560                              <1> lff_5:	
   561                              <1> 	lodsw
   562                              <1> 	stosw	; left channel
   563                              <1> 	stosw	; right channel
   564                              <1> 	loop	lff_5
   565                              <1> lff_6:
   566                              <1> 	mov	ax, di ; save next buffer offset/position
   567                              <1> 	; 06/11/2023
   568                              <1> 	;pop	si
   569                              <1> 	;pop	di
   570                              <1> 	pop	es
   571                              <1> ;lff_7:        
   572                              <1> 	; 06/11/2023
   573                              <1> 	and	ax, ax
   574                              <1> 	jz	short endLFF ; end of 2nd half
   575                              <1> 	mov	cx, (BUFFERSIZE / 2)
   576                              <1> lff_7:
   577                              <1> 	cmp	ax, cx
   578                              <1> 	je	short endLFF	 ; 06/11/2023
   579                              <1> 	;jb	short lff_11
   580                              <1> 	;xor	cx, cx
   581                              <1> 	;sub	cx, ax
   582                              <1> 	;neg	cx
   583                              <1> 	jmp	short lff_11
   584                              <1> lff_8:
   585                              <1> 	; 07/11/2023
   586                              <1> 	cmp	word [fbs_off], (BUFFERSIZE / 2) ; 32768
   587                              <1> 	jnb	short endLFF
   588                              <1> 	
   589                              <1> 	mov	dx, ax ; buffer offset
   590                              <1> 	mov	ax, [fbs_seg] ; buffer segment
   591                              <1> 	jmp	lff_0
   592                              <1> lff_9:  
   593                              <1> 	; 07/11/2023
   594                              <1> 	;; 06/11/2023 (temporary)
   595                              <1> 	;mov	al, '!'  ; error
   596                              <1> 	;call	tL0
   597                              <1> 
   598                              <1> 	xor	ax, ax
   599                              <1> lff_10:
   600                              <1> 	; 07/11/2023
   601                              <1> 	;mov	cx, (BUFFERSIZE / 2)  
   602                              <1> lff_11:
   603                              <1> 	call    padfill				; blank pad the remainder
   604                              <1>         ;clc					; don't exit with CY yet.
   605                              <1>         or	byte [flags], ENDOFFILE		; end of file flag
   606                              <1> endLFF:
   607                              <1>         ;pop	ds
   608                              <1> 	;pop	es
   609                              <1> 	; 06/11/2023
   610                              <1> 	;pop	bx
   611                              <1> 	;pop	dx
   612                              <1>         ;pop	cx
   613                              <1>         ;pop	ax
   614                              <1>         retn
   615                              <1> 
   616                              <1> %endif
   617                              <1> 
   618                              <1> ; 08/11/2023
   619                              <1> ; 07/11/2023
   620                              <1> %if 1
   621                              <1> 
   622                              <1> loadFromFile:
   623                              <1> 	; 07/11/2023
   624                              <1> 
   625 0000059E F606[D80A]01        <1>         test    byte [flags], ENDOFFILE	; have we already read the
   626                              <1> 					; last of the file?
   627 000005A3 7402                <1> 	jz	short lff_0		; no
   628 000005A5 F9                  <1> 	stc
   629 000005A6 C3                  <1> 	retn
   630                              <1> 
   631                              <1> lff_0:
   632                              <1> 	; 08/11/2023
   633 000005A7 89C5                <1> 	mov	bp, ax ; save buffer segment	
   634                              <1> 
   635 000005A9 8A0E[FA0A]          <1> 	mov	cl, [fbs_shift]   
   636 000005AD 20C9                <1> 	and	cl, cl
   637 000005AF 7470                <1> 	jz	short lff_1 ; stereo, 16 bit	
   638                              <1> 
   639 000005B1 BFFFFF              <1> 	mov	di, BUFFERSIZE - 1 ; 65535
   640                              <1> 
   641                              <1> 	; fbs_shift =
   642                              <1> 	;	2 for mono and 8 bit sample (multiplier = 4)
   643                              <1> 	;	1 for mono or 8 bit sample (multiplier = 2)
   644 000005B4 D3EF                <1> 	shr	di, cl
   645 000005B6 47                  <1> 	inc	di ; 16384 for 8 bit and mono	
   646                              <1> 		   ; 32768 for 8 bit or mono	
   647                              <1> 
   648 000005B7 8CC8                <1> 	mov	ax, cs
   649 000005B9 BA[FE0A]            <1> 	mov	dx, temp_buffer ; temporary buffer for wav data
   650                              <1> 
   651                              <1> 	; 17/02/2017 (stereo/mono, 8bit/16bit corrections)
   652                              <1> 	; load file into memory
   653 000005BC 89F9                <1>         mov	cx, di                       
   654 000005BE 8B1E[D60A]          <1> 	mov	bx, [filehandle]
   655 000005C2 8ED8                <1> 	mov     ds, ax
   656 000005C4 B43F                <1>        	mov	ah, 3Fh
   657 000005C6 CD21                <1> 	int	21h
   658                              <1> 
   659 000005C8 8CCB                <1> 	mov	bx, cs
   660 000005CA 8EDB                <1> 	mov	ds, bx
   661                              <1> 
   662 000005CC 724A                <1> 	jc	short lff_4 ; error !
   663                              <1> 
   664                              <1> 	; 08/11/2023
   665 000005CE 31D2                <1> 	xor	dx, dx ; 0
   666                              <1> 
   667 000005D0 21C0                <1> 	and	ax, ax
   668 000005D2 7476                <1> 	jz	short lff_3
   669                              <1> 
   670 000005D4 8A1E[FA0A]          <1> 	mov	bl, [fbs_shift]
   671                              <1> 
   672 000005D8 06                  <1> 	push	es
   673 000005D9 89D7                <1> 	mov	di, dx ; 0 ; [fbs_off]
   674                              <1> 	;mov	bp, [fbs_seg] ; buffer segment
   675 000005DB 8EC5                <1> 	mov	es, bp
   676 000005DD BE[FE0A]            <1> 	mov	si, temp_buffer ; temporary buffer address
   677 000005E0 89C1                <1> 	mov	cx, ax ; byte count
   678 000005E2 803E[F80A]08        <1> 	cmp	byte [bps], 8 ; bits per sample (8 or 16)
   679 000005E7 751B                <1> 	jne	short lff_7 ; 16 bit samples
   680                              <1> 	; 8 bit samples
   681 000005E9 FECB                <1> 	dec	bl  ; shift count, 1 = stereo, 2 = mono
   682 000005EB 740C                <1> 	jz	short lff_6 ; 8 bit, stereo
   683                              <1> lff_5:
   684                              <1> 	; mono & 8 bit
   685 000005ED AC                  <1> 	lodsb
   686 000005EE 2C80                <1> 	sub	al, 80h ; 08/11/2023
   687 000005F0 C1E008              <1> 	shl	ax, 8 ; convert 8 bit sample to 16 bit sample
   688 000005F3 AB                  <1> 	stosw	; left channel
   689 000005F4 AB                  <1> 	stosw	; right channel
   690 000005F5 E2F6                <1> 	loop	lff_5
   691 000005F7 EB12                <1> 	jmp	short lff_9	
   692                              <1> lff_6:
   693                              <1> 	; stereo & 8 bit
   694 000005F9 AC                  <1> 	lodsb
   695 000005FA 2C80                <1> 	sub	al, 80h ; 08/11/2023
   696 000005FC C1E008              <1> 	shl	ax, 8 ; convert 8 bit sample to 16 bit sample
   697 000005FF AB                  <1> 	stosw
   698 00000600 E2F7                <1> 	loop	lff_6			
   699 00000602 EB07                <1> 	jmp	short lff_9
   700                              <1> lff_7:
   701 00000604 D1E9                <1> 	shr	cx, 1 ; word count
   702                              <1> lff_8:
   703 00000606 AD                  <1> 	lodsw
   704 00000607 AB                  <1> 	stosw	; left channel
   705 00000608 AB                  <1> 	stosw	; right channel
   706 00000609 E2FB                <1> 	loop	lff_8
   707                              <1> lff_9:
   708 0000060B 07                  <1> 	pop	es
   709 0000060C 09FF                <1> 	or	di, di
   710 0000060E 7442                <1> 	jz	short endLFF ; 64KB ok 
   711                              <1> 	
   712 00000610 89F8                <1> 	mov	ax, di ; [fbs_off]
   713 00000612 48                  <1> 	dec	ax
   714 00000613 B9FFFF              <1> 	mov	cx, BUFFERSIZE - 1 ; 65535
   715 00000616 EB32                <1> 	jmp	short lff_3
   716                              <1> 
   717                              <1> lff_4:
   718                              <1> 	; 08/11/2023
   719 00000618 B021                <1> 	mov	al, '!'  ; error
   720 0000061A E873FF              <1> 	call	tL0
   721                              <1> 
   722 0000061D 31C0                <1> 	xor	ax, ax
   723 0000061F EB29                <1> 	jmp	short lff_3
   724                              <1> 	
   725                              <1> lff_1:  
   726                              <1> 	;mov	bp, ax ; save buffer segment
   727 00000621 31D2                <1> 	xor	dx, dx
   728                              <1> 	; load file into memory
   729 00000623 B90080              <1>         mov	cx, (BUFFERSIZE / 2)	; 32k chunk
   730 00000626 8B1E[D60A]          <1> 	mov	bx, [filehandle]
   731 0000062A 8ED8                <1> 	mov     ds, ax
   732 0000062C B43F                <1>        	mov	ah, 3Fh
   733 0000062E CD21                <1> 	int	21h
   734                              <1> 
   735 00000630 8CCF                <1> 	mov	di, cs
   736 00000632 8EDF                <1> 	mov	ds, di
   737                              <1> 
   738                              <1> 	; 07/11/2023
   739 00000634 72E2                <1> 	jc	short lff_4 ; error !
   740                              <1> 	
   741 00000636 39C8                <1> 	cmp	ax, cx
   742 00000638 7510                <1> 	jne	short lff_3
   743                              <1> lff_2:
   744                              <1> 	; 08/11/2023
   745 0000063A 01C2                <1> 	add	dx, ax
   746                              <1> 	;mov	cx, (BUFFERSIZE / 2)	; 32k chunk
   747                              <1> 	;mov	bx, [filehandle]
   748 0000063C 8EDD                <1> 	mov     ds, bp
   749 0000063E B43F                <1>        	mov	ah, 3Fh
   750 00000640 CD21                <1> 	int	21h
   751                              <1> 
   752                              <1> 	;mov	di, cs
   753 00000642 8EDF                <1> 	mov	ds, di
   754                              <1> 
   755 00000644 72D2                <1> 	jc	short lff_4 ; error !
   756                              <1> 
   757 00000646 39C8                <1> 	cmp	ax, cx
   758 00000648 7408                <1> 	je	short endLFF
   759                              <1> lff_3:
   760 0000064A E80600              <1> 	call    padfill			; blank pad the remainder
   761                              <1>         ;clc				; don't exit with CY yet.
   762 0000064D 800E[D80A]01        <1>         or	byte [flags], ENDOFFILE	; end of file flag
   763                              <1> endLFF:
   764 00000652 C3                  <1>         retn
   765                              <1> 
   766                              <1> %endif
   767                              <1> 
   768                              <1> ; entry ds:ax points to last byte in file
   769                              <1> ; cx=target size
   770                              <1> ; note: must do byte size fill
   771                              <1> ; destroys bx, cx
   772                              <1> ;
   773                              <1> padfill:
   774                              <1> 	; 07/11/2023
   775                              <1> 	; 06/11/2023
   776                              <1> 	; 17/02/2017
   777 00000653 06                  <1> 	push	es
   778                              <1>         ;push	di
   779                              <1> 	;mov	di, [fbs_seg]
   780                              <1> 	;mov	es, di
   781 00000654 8EC5                <1>         mov	es, bp
   782 00000656 29C1                <1> 	sub	cx, ax
   783                              <1> 	; 08/11/2023
   784                              <1> 	;mov	di, ax ; (wrong)
   785 00000658 89D7                <1> 	mov	di, dx ; buffer offset
   786 0000065A 01C7                <1> 	add	di, ax       	
   787                              <1> 	; 07/11/2023
   788                              <1> 	;add	di, [fbs_off]
   789 0000065C 30C0                <1>         xor	al, al
   790 0000065E F3AA                <1> 	rep	stosb
   791                              <1> 	;mov	[fbs_off], di
   792                              <1> 	;pop	di
   793 00000660 07                  <1>         pop	es
   794 00000661 C3                  <1> 	retn
   795                              <1> 
   796                              <1> ; returns AL = current index value
   797                              <1> getCurrentIndex:
   798                              <1> 	; 08/11/2023
   799                              <1> 	;push	dx
   800 00000662 8B16[E40A]          <1> 	mov	dx, [NABMBAR]      		
   801 00000666 83C214              <1> 	add	dx, PO_CIV_REG
   802 00000669 EC                  <1> 	in	al, dx
   803                              <1> 	;pop	dx
   804                              <1> uLVI2:	;	06/11/2023
   805 0000066A C3                  <1> 	retn
   806                              <1> 
   807                              <1> ; examines the CIV and the LVI. When they're the same, we set LVI <> CIV
   808                              <1> ; that way, we never run out of buffers to play
   809                              <1> 
   810                              <1> ; 08/11/2023
   811                              <1> %if 0
   812                              <1> 	; 07/11/2023
   813                              <1> updateLVI:
   814                              <1> 	push	ax
   815                              <1> 	push	dx
   816                              <1> 	; 06/11/2023
   817                              <1> 	mov	dx, [NABMBAR]
   818                              <1> 	add	dx, PO_CIV_REG
   819                              <1> 	; (Current Index Value and Last Valid Index value)
   820                              <1> 	in	ax, dx
   821                              <1> 
   822                              <1> 	cmp	al, ah ; is current index = last index ?
   823                              <1> 	jne	short uLVI1
   824                              <1> 
   825                              <1> 	call	setNewIndex
   826                              <1> uLVI1:
   827                              <1> 	pop	dx
   828                              <1> 	pop	ax
   829                              <1> 	retn
   830                              <1> 
   831                              <1> setNewIndex:
   832                              <1> 	; 07/11/2023
   833                              <1> 	push	ax
   834                              <1>         call    getCurrentIndex                 ; get CIV
   835                              <1>         test    byte [flags], ENDOFFILE
   836                              <1>         jnz     short sni_1
   837                              <1>         ; not at the end of the file yet.
   838                              <1>         dec     al                              ; make new index <> current
   839                              <1>         and     al, INDEX_MASK                  ; make sure new value is 0-31
   840                              <1> sni_1:
   841                              <1>         call    setLastValidIndex               ; write new value
   842                              <1>         clc
   843                              <1>         pop	ax
   844                              <1> 	retn
   845                              <1> 
   846                              <1> %endif	
   847                              <1> 
   848                              <1> ; 08/11/2023
   849                              <1> ; 07/11/2023
   850                              <1> %if 0
   851                              <1> updateLVI:
   852                              <1> 	; 06/11/2023
   853                              <1> 	mov	dx, [NABMBAR]      		
   854                              <1> 	add	dx, PO_CIV_REG
   855                              <1> 	; (Current Index Value and Last Valid Index value)
   856                              <1> 	in	ax, dx
   857                              <1> 
   858                              <1> 	cmp	al, ah ; is current index = last index ?
   859                              <1> 	jne	short uLVI2
   860                              <1> 
   861                              <1> 	; 10/11/2023
   862                              <1> 	; 08/11/2023	
   863                              <1> 	call	getCurrentIndex
   864                              <1>  
   865                              <1> 	test	byte [flags], ENDOFFILE
   866                              <1> 	;jnz	short uLVI1
   867                              <1> 	jz	short uLVI0  ; 08/11/2023
   868                              <1> 
   869                              <1> 	; 08/11/2023
   870                              <1> 	push	ax
   871                              <1> 	mov	dx, [NABMBAR]
   872                              <1> 	add	dx, PO_SR_REG  ; PCM out status register
   873                              <1> 	in	ax, dx
   874                              <1> 
   875                              <1> 	;test	al, 2
   876                              <1> 	test	al, 3 ; bit 1 = Current Equals Last Valid (CELV)
   877                              <1> 		      ; (has been processed)
   878                              <1> 		      ; bit 0 = 1 -> DMA Controller Halted (DCH)
   879                              <1> 	pop	ax
   880                              <1> 	jz	short uLVI1
   881                              <1> uLVI3:
   882                              <1> 	xor	ax, ax
   883                              <1> 	; zf = 1
   884                              <1> 	retn
   885                              <1> uLVI0:
   886                              <1>         ; not at the end of the file yet.
   887                              <1> 	dec	al
   888                              <1> 	and	al, 1Fh
   889                              <1> uLVI1:
   890                              <1> 	;call	setLastValidIndex
   891                              <1> ;uLVI2:
   892                              <1> 	;retn
   893                              <1> 
   894                              <1> %endif
   895                              <1> 	
   896                              <1> ;input AL = index # to stop on
   897                              <1> setLastValidIndex:
   898                              <1> 	; 08/11/2023
   899                              <1> 	;push	dx
   900 0000066B 8B16[E40A]          <1> 	mov	dx, [NABMBAR]
   901 0000066F 83C215              <1> 	add	dx, PO_LVI_REG
   902 00000672 EE                  <1>         out     dx, al
   903                              <1> 	;pop	dx
   904 00000673 C3                  <1> 	retn
   905                              <1> 
   906                              <1> ; 06/11/2023
   907                              <1> ;	; 05/11/2023
   908                              <1> ;setCurrentIndex:
   909                              <1> ;	;push	dx
   910                              <1> ;	mov	dx, [NABMBAR]
   911                              <1> ;	add	dx, PO_CIV_REG
   912                              <1> ;	out	dx, al
   913                              <1> ;	;pop	dx
   914                              <1> ;	retn
   915                              <1> 
   916                              <1> ; checks if either shift key has been pressed. Exits with CY if so.
   917                              <1> ; 
   918                              <1> check4keyboardstop:
   919                              <1> 
   920                              <1> ; 06/11/2023
   921                              <1> %if 1
   922                              <1> 	; 08/11/2023
   923                              <1> 	; 04/11/2023
   924 00000674 B401                <1> 	mov	ah, 1
   925 00000676 CD16                <1> 	int	16h
   926 00000678 F8                  <1> 	clc
   927 00000679 7405                <1> 	jz	short _cksr
   928 0000067B 30E4                <1> 	xor	ah, ah
   929 0000067D CD16                <1> 	int	16h
   930 0000067F F9                  <1> 	stc
   931                              <1> _cksr:
   932 00000680 C3                  <1> 	retn
   933                              <1> %endif
   934                              <1> 
   935                              <1> ; 06/11/2023
   936                              <1> ; 04/11/2023
   937                              <1> %if 0	
   938                              <1>         push    ds
   939                              <1>         push    0
   940                              <1>         pop     ds		       ; examine BDA for keyboard flags
   941                              <1>         test    byte [417h], (BIT0 | BIT1)
   942                              <1>         pop     ds
   943                              <1>         stc
   944                              <1>         jnz	short _cksr ; 07/11/2023
   945                              <1> 	;jz	short _cksr ; 06/11/2023
   946                              <1>         clc
   947                              <1> _cksr:
   948                              <1>         retn
   949                              <1> %endif
   451                                  
   452                                  ; UTILS.ASM
   453                                  ;----------------------------------------------------------------------------
   454                                  ;       delay1_4ms - Delay for 1/4 millisecond.
   455                                  ;		    1mS = 1000us
   456                                  ;       Entry:
   457                                  ;         None
   458                                  ;       Exit:
   459                                  ;	  None
   460                                  ;
   461                                  ;       Modified:
   462                                  ;         None
   463                                  ;
   464                                  PORTB			EQU	061h
   465                                    REFRESH_STATUS	EQU	010h		; Refresh signal status
   466                                  
   467                                  delay1_4ms:
   468 00000681 50                              push    ax 
   469 00000682 51                              push    cx
   470 00000683 B91000                          mov     cx, 16			; close enough.
   471 00000686 E461                    	in	al,PORTB
   472 00000688 2410                    	and	al,REFRESH_STATUS
   473 0000068A 88C4                    	mov	ah,al			; Start toggle state
   474 0000068C 09C9                    	or	cx, cx
   475 0000068E 7401                    	jz	short _d4ms1
   476 00000690 41                      	inc	cx			; Throwaway first toggle
   477                                  _d4ms1:	
   478 00000691 E461                    	in	al,PORTB		; Read system control port
   479 00000693 2410                    	and	al,REFRESH_STATUS	; Refresh toggles 15.085 microseconds
   480 00000695 38C4                    	cmp	ah,al
   481 00000697 74F8                    	je	short _d4ms1		; Wait for state change
   482                                  
   483 00000699 88C4                    	mov	ah,al			; Update with new state
   484 0000069B 49                      	dec	cx
   485 0000069C 75F3                    	jnz	short _d4ms1
   486                                  
   487 0000069E 59                              pop     cx
   488 0000069F 58                              pop     ax
   489 000006A0 C3                              retn
   490                                  
   491                                  	; 13/11/2016 - Erdogan Tan
   492                                  write_ac97_dev_info:
   493                                  	; BUS/DEV/FN
   494                                  	;	00000000BBBBBBBBDDDDDFFF00000000
   495                                  	; DEV/VENDOR
   496                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
   497                                  
   498 000006A1 30FF                    	xor	bh, bh
   499 000006A3 668B36[F00A]            	mov	esi, [dev_vendor]
   500 000006A8 89F0                    	mov	ax, si
   501 000006AA 88C3                    	mov	bl, al
   502 000006AC 88DA                    	mov	dl, bl
   503 000006AE 80E30F                  	and	bl, 0Fh
   504 000006B1 8A87[6909]              	mov	al, [bx+hex_chars]
   505 000006B5 A2[AC09]                	mov	[msgVendorId+3], al
   506 000006B8 88D3                    	mov	bl, dl
   507 000006BA C0EB04                  	shr	bl, 4
   508 000006BD 8A87[6909]              	mov	al, [bx+hex_chars]
   509 000006C1 A2[AB09]                	mov	[msgVendorId+2], al
   510 000006C4 88E3                    	mov	bl, ah
   511 000006C6 88DA                    	mov	dl, bl
   512 000006C8 80E30F                  	and	bl, 0Fh
   513 000006CB 8A87[6909]              	mov	al, [bx+hex_chars]
   514 000006CF A2[AA09]                	mov	[msgVendorId+1], al
   515 000006D2 88D3                    	mov	bl, dl
   516 000006D4 C0EB04                  	shr	bl, 4
   517 000006D7 8A87[6909]              	mov	al, [bx+hex_chars]
   518 000006DB A2[A909]                	mov	[msgVendorId], al
   519 000006DE 66C1EE10                	shr	esi, 16
   520 000006E2 89F0                    	mov	ax, si
   521 000006E4 88C3                    	mov	bl, al
   522 000006E6 88DA                    	mov	dl, bl
   523 000006E8 80E30F                  	and	bl, 0Fh
   524 000006EB 8A87[6909]              	mov	al, [bx+hex_chars]
   525 000006EF A2[BD09]                	mov	[msgDevId+3], al
   526 000006F2 88D3                    	mov	bl, dl
   527 000006F4 C0EB04                  	shr	bl, 4
   528 000006F7 8A87[6909]              	mov	al, [bx+hex_chars]
   529 000006FB A2[BC09]                	mov	[msgDevId+2], al
   530 000006FE 88E3                    	mov	bl, ah
   531 00000700 88DA                    	mov	dl, bl
   532 00000702 80E30F                  	and	bl, 0Fh
   533 00000705 8A87[6909]              	mov	al, [bx+hex_chars]
   534 00000709 A2[BB09]                	mov	[msgDevId+1], al
   535 0000070C 88D3                    	mov	bl, dl
   536 0000070E C0EB04                  	shr	bl, 4
   537 00000711 8A87[6909]              	mov	al, [bx+hex_chars]
   538 00000715 A2[BA09]                	mov	[msgDevId], al
   539                                  
   540 00000718 668B36[EC0A]            	mov	esi, [bus_dev_fn]
   541 0000071D 66C1EE08                	shr	esi, 8
   542 00000721 89F0                    	mov	ax, si
   543 00000723 88C3                    	mov	bl, al
   544 00000725 88DA                    	mov	dl, bl
   545 00000727 80E307                  	and	bl, 7 ; bit 0,1,2
   546 0000072A 8A87[6909]              	mov	al, [bx+hex_chars]
   547 0000072E A2[E109]                	mov	[msgFncNo+1], al
   548 00000731 88D3                    	mov	bl, dl
   549 00000733 C0EB03                  	shr	bl, 3
   550 00000736 88DA                    	mov	dl, bl
   551 00000738 80E30F                  	and	bl, 0Fh
   552 0000073B 8A87[6909]              	mov	al, [bx+hex_chars]
   553 0000073F A2[D309]                	mov	[msgDevNo+1], al
   554 00000742 88D3                    	mov	bl, dl
   555 00000744 C0EB04                  	shr	bl, 4
   556 00000747 8A87[6909]              	mov	al, [bx+hex_chars]
   557 0000074B A2[D209]                	mov	[msgDevNo], al
   558 0000074E 88E3                    	mov	bl, ah
   559 00000750 88DA                    	mov	dl, bl
   560 00000752 80E30F                  	and	bl, 0Fh
   561 00000755 8A87[6909]              	mov	al, [bx+hex_chars]
   562 00000759 A2[C709]                	mov	[msgBusNo+1], al
   563 0000075C 88D3                    	mov	bl, dl
   564 0000075E C0EB04                  	shr	bl, 4
   565 00000761 8A87[6909]              	mov	al, [bx+hex_chars]
   566 00000765 A2[C609]                	mov	[msgBusNo], al
   567                                  
   568 00000768 A1[E20A]                	mov	ax, [NAMBAR]
   569 0000076B 88C3                    	mov	bl, al
   570 0000076D 88DA                    	mov	dl, bl
   571 0000076F 80E30F                  	and	bl, 0Fh
   572 00000772 8A87[6909]              	mov	al, [bx+hex_chars]
   573 00000776 A2[F009]                	mov	[msgNamBar+3], al
   574 00000779 88D3                    	mov	bl, dl
   575 0000077B C0EB04                  	shr	bl, 4
   576 0000077E 8A87[6909]              	mov	al, [bx+hex_chars]
   577 00000782 A2[EF09]                	mov	[msgNamBar+2], al
   578 00000785 88E3                    	mov	bl, ah
   579 00000787 88DA                    	mov	dl, bl
   580 00000789 80E30F                  	and	bl, 0Fh
   581 0000078C 8A87[6909]              	mov	al, [bx+hex_chars]
   582 00000790 A2[EE09]                	mov	[msgNamBar+1], al
   583 00000793 88D3                    	mov	bl, dl
   584 00000795 C0EB04                  	shr	bl, 4
   585 00000798 8A87[6909]              	mov	al, [bx+hex_chars]
   586 0000079C A2[ED09]                	mov	[msgNamBar], al
   587                                  
   588                                  	; 05/11/2023
   589 0000079F A1[E40A]                	mov	ax, [NABMBAR]
   590 000007A2 88C3                    	mov	bl, al
   591 000007A4 88DA                    	mov	dl, bl
   592 000007A6 80E30F                  	and	bl, 0Fh
   593 000007A9 678A83[69090000]        	mov	al, [ebx+hex_chars]
   594 000007B0 A2[FF09]                	mov	[msgNabmBar+3], al
   595 000007B3 88D3                    	mov	bl, dl
   596 000007B5 C0EB04                  	shr	bl, 4
   597 000007B8 678A83[69090000]        	mov	al, [ebx+hex_chars]
   598 000007BF A2[FE09]                	mov	[msgNabmBar+2], al
   599 000007C2 88E3                    	mov	bl, ah
   600 000007C4 88DA                    	mov	dl, bl
   601 000007C6 80E30F                  	and	bl, 0Fh
   602 000007C9 678A83[69090000]        	mov	al, [ebx+hex_chars]
   603 000007D0 A2[FD09]                	mov	[msgNabmBar+1], al
   604 000007D3 88D3                    	mov	bl, dl
   605 000007D5 C0EB04                  	shr	bl, 4
   606 000007D8 678A83[69090000]        	mov	al, [ebx+hex_chars]
   607 000007DF A2[FC09]                	mov	[msgNabmBar], al
   608                                  
   609                                  	; 24/11/2016
   610 000007E2 30E4                    	xor	ah, ah
   611 000007E4 A0[D90A]                	mov	al, [ac97_int_ln_reg]
   612 000007E7 B10A                    	mov	cl, 10
   613 000007E9 F6F1                    	div	cl
   614 000007EB 0106[070A]              	add	[msgIRQ], ax
   615 000007EF 20C0                    	and	al, al
   616 000007F1 7508                    	jnz	short _pmi
   617 000007F3 A0[080A]                	mov	al, [msgIRQ+1]
   618 000007F6 B420                    	mov	ah, ' '
   619 000007F8 A3[070A]                	mov	[msgIRQ], ax
   620                                  _pmi:
   621 000007FB BA[7A09]                        mov	dx, msgAC97Info
   622 000007FE B409                            mov     ah, 9
   623 00000800 CD21                            int     21h
   624 00000802 C3                              retn
   625                                  
   626                                  write_sample_rate:
   627                                  	; ax = sample rate (hertz)
   628                                  
   629 00000803 31D2                    	xor	dx, dx
   630 00000805 B90A00                  	mov	cx, 10
   631 00000808 F7F1                    	div	cx
   632 0000080A 0016[1D0A]              	add	[msgHertz+4], dl
   633 0000080E 29D2                    	sub	dx, dx
   634 00000810 F7F1                    	div	cx
   635 00000812 0016[1C0A]              	add	[msgHertz+3], dl
   636 00000816 29D2                    	sub	dx, dx
   637 00000818 F7F1                    	div	cx
   638 0000081A 0016[1B0A]              	add	[msgHertz+2], dl
   639 0000081E 29D2                    	sub	dx, dx
   640 00000820 F7F1                    	div	cx
   641 00000822 0016[1A0A]              	add	[msgHertz+1], dl
   642 00000826 0006[190A]              	add	[msgHertz], al
   643                                  	
   644 0000082A BA[0C0A]                        mov     dx, msgSampleRate
   645 0000082D B409                            mov     ah, 9
   646 0000082F CD21                            int     21h
   647                                  
   648                                  	; 19/11/2016
   649 00000831 BA[320A]                	mov	dx, msg16Bits
   650 00000834 803E[F80A]10            	cmp	byte [bps], 16
   651 00000839 7403                    	je	short wsr_1
   652 0000083B BA[230A]                	mov	dx, msg8Bits
   653                                  wsr_1:
   654 0000083E B409                            mov     ah, 9
   655 00000840 CD21                            int     21h
   656                                  
   657 00000842 BA[2B0A]                	mov	dx, msgMono
   658 00000845 803E[F60A]01            	cmp	byte [stmo], 1
   659 0000084A 7403                    	je	short wsr_2
   660 0000084C BA[3B0A]                	mov	dx, msgStereo		
   661                                  wsr_2:
   662 0000084F B409                            mov     ah, 9
   663 00000851 CD21                            int     21h
   664                                  
   665 00000853 C3                              retn
   666                                  
   667                                  ;detect_codec:
   668                                  ;	; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
   669                                  ;	mov	eax, 7Ch
   670                                  ;	call	codec_read
   671                                  ;       shl     eax, 16
   672                                  ;       mov     [codec_id], eax
   673                                  ;
   674                                  ;	mov	eax, 7Eh
   675                                  ;       call	codec_read
   676                                  ;       or      eax, [codec_id]
   677                                  ;       mov     [codec_chip_id], eax
   678                                  ;       and     eax, 0FFFFFF00h
   679                                  ;
   680                                  ;       mov     edi, codecs
   681                                  ;_dcb:
   682                                  ;       mov     ebx, [di]
   683                                  ;       test    ebx, ebx
   684                                  ;       jz      short _dco_unknown
   685                                  ;
   686                                  ;       cmp     eax, ebx
   687                                  ;       jne     short _dco_next
   688                                  ;       mov     ax, [di+4]
   689                                  ;       mov     [codec_vendor_ids], ax
   690                                  ;       movzx   esi, ax
   691                                  ;       call	print_msg
   692                                  ;       
   693                                  ;	mov	ax, [di+6]
   694                                  ;	call	detect_chip
   695                                  ;       retn
   696                                  ;
   697                                  ;_dco_next:
   698                                  ;       add     di, 8
   699                                  ;       jmp     short _dcb
   700                                  ;
   701                                  ;_dco_unknown:
   702                                  ;       mov    word [codec_vendor_ids], ac_unknown
   703                                  ;       mov    word [codec_chip_ids], chip_unknown
   704                                  ;       mov     esi, chip_unknown
   705                                  ;	call	print_msg
   706                                  ;       mov     eax, [codec_chip_id]
   707                                  ;       call    dword2str
   708                                  ;       call	print_msg
   709                                  ;       retn
   710                                  
   711                                  ;detect_chip:
   712                                  ;	; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
   713                                  ;	mov	di, ax ; chip_tab
   714                                  ;       mov     eax, [codec_chip_id]
   715                                  ;       and     ax, 0FFh
   716                                  ;_dch1:
   717                                  ;       mov     bx, [di]
   718                                  ;       cmp     bx, 0FFh
   719                                  ;       je      short _dch_unknown
   720                                  ;
   721                                  ;       cmp     ax, bx
   722                                  ;       jne     short _dch_next
   723                                  ;       mov     ax, [di+2]
   724                                  ;       mov     [codec_chip_ids], ax
   725                                  ;       mov     si, ax
   726                                  ;       call	print_msg
   727                                  ;       retn
   728                                  
   729                                  ;_dch_next:
   730                                  ;       add     di, 4
   731                                  ;       jmp     short _dch1
   732                                  ;
   733                                  ;_dch_unknown:
   734                                  ;       mov    word [codec_chip_ids], chip_unknown
   735                                  ;       mov     si, chip_unknown
   736                                  ;       call	print_msg
   737                                  ;       mov     eax, [codec_chip_id]
   738                                  ;       call    dword2str
   739                                  ;       call	print_msg
   740                                  ;       retn
   741                                  
   742                                  ; 10/11/2023
   743                                  ; 09/11/2023
   744                                  ; 06/11/2023
   745                                  %if 1
   746                                  
   747                                  ac97_int_handler:
   748                                  	; 11/11/2023
   749                                  	; 10/11/2023
   750                                  	; 17/02/2016
   751 00000854 6650                    	push	eax	; 11/11/2023
   752 00000856 52                      	push	dx
   753                                  	; 05/11/2023	
   754                                  	;push	cx
   755                                  	;push	bx
   756                                  	;push	si
   757                                  	;push	di
   758                                  
   759                                  	; 10/11/2023
   760                                  	; EOI at first
   761 00000857 B020                    	mov	al, 20h
   762 00000859 F606[D90A]08            	test	byte [ac97_int_ln_reg], 8
   763 0000085E 7402                    	jz	short _ih_0
   764 00000860 E6A0                    	out 	0A0h, al ; 20h	; EOI
   765                                  _ih_0:
   766 00000862 E620                    	out	20h, al  ; 20h	; EOI
   767                                  
   768                                  	; 11/11/2023
   769                                  	; 09/11/2023
   770 00000864 BA3000                  	mov	dx, GLOB_STS_REG
   771 00000867 0316[E40A]                      add	dx, [NABMBAR]
   772 0000086B 66ED                    	in	eax, dx
   773                                  	
   774                                  	; 09/11/2023,
   775 0000086D 6683F8FF                        cmp	eax, 0FFFFFFFFh ; -1
   776 00000871 741D                    	je	short _ih_2
   777                                  	
   778 00000873 A840                    	test	al, 40h		; PCM Out Interrupt
   779 00000875 7509                    	jnz	short _ih_1
   780                                  
   781 00000877 6685C0                  	test	eax, eax
   782 0000087A 7414                    	jz	short _ih_2
   783                                  
   784                                   	;mov	dx, GLOB_STS_REG
   785                                          ;add	dx, [NABMBAR]
   786 0000087C 66EF                    	out	dx, eax
   787 0000087E EB10                    	jmp	short _ih_2
   788                                  
   789                                  	; .....
   790                                  	;mov	al, 1
   791                                  	; 10/11/2023
   792                                  	;mov	[tloop], al  ; 1
   793                                  
   794                                  	;cmp	[inside], al ; 1
   795                                  	;jnb	short _ih_3	; busy
   796                                  
   797                                  	;mov	[inside], al ; 1
   798                                  	;
   799                                  	;; 09/11/2023
   800                                          ;mov	dx, [NABMBAR]
   801                                          ;add	dx, PO_SR_REG	; set pointer to Status reg
   802                                  	;in	al, dx
   803                                  	;; 10/11/2023
   804                                  	;;;out	dx, eax
   805                                  	;;out	dx, al		; clear interrupt event
   806                                  	;			; (by writing 1 to same bits)
   807                                  	;
   808                                  	;;mov	[pcm_irq_status], al ; 05/11/2023
   809                                  	;test	al, BCIS ; Buffer Completion Interrupt Status (Bit 3)
   810                                  	;jz	short _ih_2
   811                                  	; .....
   812                                  
   813                                  _ih_1:
   814                                  	; 11/11/2023
   815 00000880 6650                    	push	eax
   816                                  
   817                                  	;mov	ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
   818                                  	;mov	dx, PO_SR_REG
   819                                          ;add	dx, [NABMBAR]
   820                                  	;out	dx, ax
   821                                  
   822                                  	; 10/11/2023
   823                                  	; 28/11/2016 - Erdogan Tan
   824 00000882 E8D5FC                  	call	tuneLoop
   825                                  
   826                                  	; 11/11/2023
   827 00000885 6658                    	pop	eax
   828 00000887 BA3000                  	mov	dx, GLOB_STS_REG
   829 0000088A 0316[E40A]                      add	dx, [NABMBAR]
   830 0000088E 66EF                    	out	dx, eax
   831                                  _ih_2:
   832                                  	; 11/11/2023
   833 00000890 8B16[E40A]              	mov	dx, [NABMBAR]
   834 00000894 83C216                  	add	dx, PO_SR_REG	; set pointer to Status reg
   835 00000897 B81C00                  	mov	ax, 1Ch
   836 0000089A EF                      	out	dx, ax
   837                                  
   838                                  ;	; 10/11/2023
   839                                  ;	mov	al, 20h
   840                                  ;	test	byte [ac97_int_ln_reg], 8
   841                                  ;	jz	short _ih_3
   842                                  ;	out 	0A0h, al ; 20h	; EOI
   843                                  ;_ih_3:
   844                                  ;	out	20h, al  ; 20h	; EOI
   845                                  ;_ih_4:
   846                                  	;mov	byte [inside], 0
   847                                  	;pop	di
   848                                  	;pop	si
   849                                  	;pop	bx
   850                                  	;pop	cx
   851 0000089B 5A                      	pop	dx
   852 0000089C 6658                    	pop	eax ; 11/11/2023
   853 0000089E CF                      	iret
   854                                  
   855                                  %endif
   856                                  
   857                                  ; 10/11/2023
   858                                  ; 09/11/2023
   859                                  ; 06/11/2023
   860                                  %if 0
   861                                  
   862                                  ac97_int_handler:
   863                                  	; 10/11/2023
   864                                  	; 17/02/2016
   865                                  	push	ax	; 09/11/2023
   866                                  	push	dx
   867                                  	; 05/11/2023
   868                                  	;push	cx
   869                                  	;push	bx
   870                                  	;push	si
   871                                  	;push	di
   872                                  
   873                                  	; 10/11/2023
   874                                  	; EOI at first
   875                                  	mov	al, 20h
   876                                  	test	byte [ac97_int_ln_reg], 8
   877                                  	jz	short _ih_0
   878                                  	out 	0A0h, al ; 20h	; EOI
   879                                  _ih_0:
   880                                  	out	20h, al  ; 20h	; EOI
   881                                  
   882                                  	mov	al, 1
   883                                  
   884                                  	; 10/11/2023
   885                                  	;mov	[tloop], al  ; 1
   886                                  
   887                                  	cmp	[inside], al ; 1
   888                                  	jnb	short _ih_3	; busy
   889                                  
   890                                  	mov	[inside], al ; 1
   891                                  
   892                                  	; 09/11/2023
   893                                          mov	dx, [NABMBAR]
   894                                          add	dx, PO_SR_REG	; set pointer to Status reg
   895                                  	in	al, dx
   896                                  	; 10/11/2023
   897                                  	;out	dx, eax
   898                                  	out	dx, al		; clear interrupt event
   899                                  				; (by writing 1 to same bits)
   900                                  
   901                                  	;mov	[pcm_irq_status], al ; 05/11/2023
   902                                  	test	al, BCIS ; Buffer Completion Interrupt Status (Bit 3)
   903                                  	jz	short _ih_2
   904                                  	
   905                                  	; 09/11/2023
   906                                  	;mov	dx, GLOB_STS_REG
   907                                          ;add	dx, [NABMBAR]
   908                                  	;in	eax, dx
   909                                  	
   910                                  	; 09/11/2023,
   911                                          ;cmp	eax, 0FFFFFFFFh ; -1
   912                                  	;je	short _ih_2
   913                                  	
   914                                  	;test	al, 40h		; PCM Out Interrupt
   915                                  	;jz	short _ih_2
   916                                  _ih_1:
   917                                  	; 10/11/2023
   918                                  	; 28/11/2016 - Erdogan Tan
   919                                  	call	tuneLoop
   920                                  	;jnc	short _ih_2
   921                                  	;dec	byte [tloop] ; [tloop] = 0
   922                                  _ih_2:
   923                                  	mov	byte [inside], 0
   924                                  _ih_3:
   925                                  	;pop	di
   926                                  	;pop	si
   927                                  	;pop	bx
   928                                  	;pop	cx
   929                                  	pop	dx
   930                                  	pop	ax ; 09/11/2023
   931                                  	iret
   932                                  
   933                                  %endif
   934                                  
   935                                  
   936                                  ac97_stop:
   937                                  	; 11/11/2023
   938                                  	; 09/11/2023
   939                                  	; 05/11/2023
   940                                  	; 04/11/2023 
   941                                  	; 28/05/2017 (TRDOS 386 v2, 'audio.s')
   942                                  	;mov	byte [tLoop], 0 ; stop ! ; 05/11/2023
   943                                  ;_ac97_stop:
   944                                  
   945                                  	; 11/11/2023
   946 0000089F 8B16[E20A]              	mov	dx, [NAMBAR]
   947                                  	;add	dx, 0 ; ac_reg_0 ; reset register
   948 000008A3 EF                      	out	dx, ax
   949                                  
   950                                  	; 04/11/2023
   951                                  	; 09/10/2017 (TRDOS 386 v2, 'audio.s')
   952                                  	; 11/06/2017
   953 000008A4 30C0                    	xor	al, al ; 0
   954 000008A6 E80D00                  	call	ac97_po_cmd
   955                                  
   956                                  	; (Ref: KolibriOS, intelac97.asm, 'stop:')
   957                                  	; Clear FIFOE, BCIS, LVBCI (Ref: Intel ICH hub manual)
   958 000008A9 B81C00                  	mov     ax, 1Ch
   959 000008AC 8B16[E40A]              	mov     dx, [NABMBAR]
   960 000008B0 83C216                  	add     dx, PO_SR_REG
   961 000008B3 EF                      	out     dx, ax
   962                                  
   963                                  	; 11/06/2017
   964 000008B4 B002                    	mov     al, RR
   965                                  ac97_po_cmd:
   966                                  	; 11/06/2017
   967                                  	; 29/05/2017
   968 000008B6 8B16[E40A]              	mov     dx, [NABMBAR]
   969 000008BA 83C21B                          add     dx, PO_CR_REG		; PCM out control register
   970 000008BD EE                      	out	dx, al
   971 000008BE C3                      	retn
   972                                  
   973                                  print_msg:
   974                                  	; 13/11/2016 - Erdogan Tan 
   975                                  	; esi = ASCIIZ text address
   976                                  	;
   977 000008BF BB0700                  	mov	bx, 7h
   978 000008C2 B40E                    	mov	ah, 0Eh 
   979                                  pm_next_char:
   980 000008C4 AC                      	lodsb
   981 000008C5 20C0                    	and	al, al
   982 000008C7 7404                    	jz	short pm_retn
   983 000008C9 CD10                    	int	10h
   984 000008CB EBF7                    	jmp	short pm_next_char
   985                                  pm_retn:
   986 000008CD C3                      	retn
   987                                  
   988                                  ; 06/11/2023
   989                                  ;dword2str:
   990                                  ;	; 13/11/2016 - Erdogan Tan 
   991                                  ;	; eax = dword value
   992                                  ;	;
   993                                  ;	call	dwordtohex
   994                                  ;	mov	[dword_str], edx
   995                                  ;	mov	[dword_str+4], eax
   996                                  ;	mov	si, dword_str
   997                                  ;	retn
   998                                  
   999                                  	; trdos386.s (unix386.s) - 10/05/2015
  1000                                  	; Convert binary number to hexadecimal string
  1001                                  
  1002                                  bytetohex:
  1003                                  	; INPUT ->
  1004                                  	; 	AL = byte (binary number)
  1005                                  	; OUTPUT ->
  1006                                  	;	AX = hexadecimal string
  1007                                  	;
  1008 000008CE 53                      	push	bx
  1009 000008CF 30FF                    	xor	bh, bh
  1010 000008D1 88C3                    	mov	bl, al
  1011 000008D3 C0EB04                  	shr	bl, 4
  1012 000008D6 8A9F[6909]              	mov	bl, [bx+hex_chars] 	 	
  1013 000008DA 86D8                    	xchg	bl, al
  1014 000008DC 80E30F                  	and	bl, 0Fh
  1015 000008DF 8AA7[6909]              	mov	ah, [bx+hex_chars] 
  1016 000008E3 5B                      	pop	bx	
  1017 000008E4 C3                      	retn
  1018                                  
  1019                                  wordtohex:
  1020                                  	; INPUT ->
  1021                                  	; 	AX = word (binary number)
  1022                                  	; OUTPUT ->
  1023                                  	;	EAX = hexadecimal string
  1024                                  	;
  1025 000008E5 53                      	push	bx
  1026 000008E6 30FF                    	xor	bh, bh
  1027 000008E8 86E0                    	xchg	ah, al
  1028 000008EA 50                      	push	ax
  1029 000008EB 88E3                    	mov	bl, ah
  1030 000008ED C0EB04                  	shr	bl, 4
  1031 000008F0 8A87[6909]              	mov	al, [bx+hex_chars] 	 	
  1032 000008F4 88E3                    	mov	bl, ah
  1033 000008F6 80E30F                  	and	bl, 0Fh
  1034 000008F9 8AA7[6909]              	mov	ah, [bx+hex_chars]
  1035 000008FD 66C1E010                	shl	eax, 16
  1036 00000901 58                      	pop	ax
  1037 00000902 5B                      	pop	bx
  1038 00000903 EBC9                    	jmp	short bytetohex
  1039                                  
  1040                                  ; 06/11/2023
  1041                                  ;dwordtohex:
  1042                                  ;	; INPUT ->
  1043                                  ;	; 	EAX = dword (binary number)
  1044                                  ;	; OUTPUT ->
  1045                                  ;	;	EDX:EAX = hexadecimal string
  1046                                  ;	;
  1047                                  ;	push	eax
  1048                                  ;	shr	eax, 16
  1049                                  ;	call	wordtohex
  1050                                  ;	mov	edx, eax
  1051                                  ;	pop	eax
  1052                                  ;	call	wordtohex
  1053                                  ;	retn
  1054                                  
  1055                                  _DATA:
  1056                                  
  1057                                  ; 24/11/2016
  1058                                  ;	IRQ  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15 
  1059 00000905 08090A0B0C0D0E0F70-     irq_int	 db 08h,09h,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh,70h,71h,72h,73h,74h,75h,76h,77h
  1059 0000090E 71727374757677     
  1060                                  
  1061                                  ; 17/02/2017
  1062                                  ; Valid ICH device IDs
  1063                                  
  1064                                  valid_ids:
  1065 00000915 86801524                dd	(ICH_DID << 16) + INTEL_VID  	 ; 8086h:2415h 
  1066 00000919 86802524                dd	(ICH0_DID << 16) + INTEL_VID 	 ; 8086h:2425h 
  1067 0000091D 86804524                dd	(ICH2_DID << 16) + INTEL_VID 	 ; 8086h:2445h 
  1068 00000921 86808524                dd	(ICH3_DID << 16) + INTEL_VID 	 ; 8086h:2485h 
  1069 00000925 8680C524                dd	(ICH4_DID << 16) + INTEL_VID 	 ; 8086h:24C5h
  1070 00000929 8680D524                dd	(ICH5_DID << 16) + INTEL_VID 	 ; 8086h:24D5h
  1071 0000092D 86806E26                dd	(ICH6_DID << 16) + INTEL_VID 	 ; 8086h:266Eh
  1072 00000931 8680A625                dd	(ESB6300_DID << 16) + INTEL_VID  ; 8086h:25A6h
  1073 00000935 86809826                dd	(ESB631X_DID << 16) + INTEL_VID  ; 8086h:2698h
  1074 00000939 8680DE27                dd	(ICH7_DID << 16) + INTEL_VID 	 ; 8086h:27DEh
  1075                                  ; 03/11/2023 - Erdogan Tan
  1076 0000093D 86809571                dd	(MX82440_DID << 16) + INTEL_VID  ; 8086h:7195h
  1077 00000941 39101270                dd	(SI7012_DID << 16)  + SIS_VID	 ; 1039h:7012h
  1078 00000945 DE10B101                dd 	(NFORCE_DID << 16)  + NVIDIA_VID ; 10DEh:01B1h
  1079 00000949 DE106A00                dd 	(NFORCE2_DID << 16) + NVIDIA_VID ; 10DEh:006Ah
  1080 0000094D 22106D74                dd 	(AMD8111_DID << 16) + AMD_VID 	 ; 1022h:746Dh
  1081 00000951 22104574                dd 	(AMD768_DID << 16)  + AMD_VID 	 ; 1022h:7445h
  1082 00000955 DE105900                dd 	(CK804_DID << 16) + NVIDIA_VID	 ; 10DEh:0059h
  1083 00000959 DE103A00                dd 	(MCP04_DID << 16) + NVIDIA_VID	 ; 10DEh:003Ah
  1084 0000095D DE108A00                dd 	(CK8_DID << 16) + NVIDIA_VID	 ; 1022h:008Ah
  1085 00000961 DE10DA00                dd 	(NFORCE3_DID << 16) + NVIDIA_VID ; 10DEh:00DAh
  1086 00000965 DE10EA00                dd 	(CK8S_DID << 16) + NVIDIA_VID	 ; 10DEh:00EAh
  1087                                  
  1088                                  valid_id_count:	equ ($ - valid_ids)>>2 ; 05/11/2023
  1089                                  
  1090                                  ; 13/11/2016
  1091 00000969 303132333435363738-     hex_chars	db "0123456789ABCDEF", 0
  1091 00000972 3941424344454600   
  1092 0000097A 414339372041756469-     msgAC97Info	db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah 
  1092 00000983 6F20436F6E74726F6C-
  1092 0000098C 6C6572202620436F64-
  1092 00000995 656320496E666F0D0A 
  1093 0000099E 56656E646F72204944-     		db "Vendor ID: "
  1093 000009A7 3A20               
  1094 000009A9 303030306820446576-     msgVendorId	db "0000h Device ID: "
  1094 000009B2 6963652049443A20   
  1095 000009BA 30303030680D0A          msgDevId	db "0000h", 0Dh, 0Ah
  1096 000009C1 4275733A20              		db "Bus: "
  1097 000009C6 303068204465766963-     msgBusNo	db "00h Device: "
  1097 000009CF 653A20             
  1098 000009D2 3030682046756E6374-     msgDevNo	db "00h Function: "
  1098 000009DB 696F6E3A20         
  1099 000009E0 303068                  msgFncNo	db "00h"
  1100 000009E3 0D0A                    		db 0Dh, 0Ah
  1101                                  ; 05/11/2023	
  1102 000009E5 4E414D4241523A20        		db "NAMBAR: "
  1103 000009ED 303030306820            msgNamBar	db "0000h "
  1104 000009F3 4E41424D4241523A20      		db "NABMBAR: "
  1105 000009FC 303030306820495251-     msgNabmBar	db "0000h IRQ: "
  1105 00000A05 3A20               
  1106 00000A07 3030                    msgIRQ		dw 3030h
  1107 00000A09 0D0A24                  		db 0Dh, 0Ah, "$"
  1108 00000A0C 53616D706C65205261-     msgSampleRate	db "Sample Rate: "
  1108 00000A15 74653A20           
  1109 00000A19 303030303020487A20-     msgHertz	db "00000 Hz ", "$" 
  1109 00000A22 24                 
  1110 00000A23 3820626974732024        msg8Bits	db "8 bits ", "$" 
  1111 00000A2B 4D6F6E6F0D0A24          msgMono		db "Mono", 0Dh, 0Ah, "$"
  1112 00000A32 313620626974732024      msg16Bits	db "16 bits ", "$" 
  1113 00000A3B 53746572656F0D0A24      msgStereo	db "Stereo", 0Dh, 0Ah, "$"
  1114                                  
  1115                                  ;; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
  1116                                  ;codec_id	dd 0
  1117                                  ;codec_chip_id	dd 0
  1118                                  ;codec_vendor_ids dw 0
  1119                                  ;codec_chip_ids	dw 0
  1120                                  
  1121 00000A44 3030303030303030        dword_str	 dd 30303030h, 30303030h
  1122 00000A4C 680D0A00                		 db 'h', 0Dh, 0Ah, 0
  1123                                  
  1124                                  ;ac_unknown     db 'unknown manufacturer',13,10,0
  1125                                  ;ac_Realtek     db 'Realtek Semiconductor',13,10,0
  1126                                  ;ac_Analog      db 'Analog Devices',13,10,0
  1127                                  ;ac_CMedia      db 'C-Media Electronics',13,10,0
  1128                                  ;ac_Cirrus      db 'Cirrus Logic',13,10,0
  1129                                  ;ac_Wolfson     db 'Wolfson Microelectronics',13,10,0
  1130                                  ;ac_VIA         db 'VIA Technologies',13,10,0
  1131                                  ;ac_SigmaTel    db 'SigmaTel',13,10,0
  1132                                  ;ac_eMicro      db 'eMicro',13,10,0
  1133                                  ;
  1134                                  ;chip_unknown   db 'unknown codec id ', 0
  1135                                  
  1136                                  ;CHIP_REALTEK   equ 414C4700h
  1137                                  ;CHIP_CMEDIA    equ 434D4900h
  1138                                  ;CHIP_VIA       equ 56494100h
  1139                                  
  1140                                  ;codecs        dd CHIP_CMEDIA
  1141                                  ;	       dw ac_CMedia, chips_CMedia
  1142                                  ;              dd CHIP_REALTEK
  1143                                  ;	       dw ac_Realtek, chips_Realtek
  1144                                  ;              dd CHIP_VIA
  1145                                  ;	       dw ac_VIA, chips_VIA
  1146                                  ;              dd 0
  1147                                  
  1148                                  ;chips_Realtek dw 10h, chip_ALC201a
  1149                                  ;              dw 20h, chip_ALC650
  1150                                  ;              dw 21h, chip_ALC650D
  1151                                  ;              dw 22h, chip_ALC650E
  1152                                  ;              dw 23h, chip_ALC650F
  1153                                  ;              dw 60h, chip_ALC655
  1154                                  ;              dw 80h, chip_ALC658
  1155                                  ;              dw 81h, chip_ALC658D
  1156                                  ;              dw 90h, chip_ALC850
  1157                                  ;              dw 0FFh
  1158                                  
  1159                                  ;chips_CMedia  dw 41h, chip_CM9738
  1160                                  ;              dw 61h, chip_CM9739
  1161                                  ;              dw 69h, chip_CM9780
  1162                                  ;              dw 78h, chip_CM9761
  1163                                  ;              dw 82h, chip_CM9761
  1164                                  ;              dw 83h, chip_CM9761
  1165                                  ;              dw 0FFh
  1166                                  
  1167                                  ;chips_VIA     dw 61h, chip_VIA1612A
  1168                                  ;              dw 0FFh
  1169                                  
  1170                                  ;Realtek
  1171                                  ;chip_ALC201a    db 'ALC201a',0dh,0ah,00h
  1172                                  ;chip_ALC650     db 'ALC650 ',0dh,0ah,00h
  1173                                  ;chip_ALC650D    db 'ALC650D',0dh,0ah,00h
  1174                                  ;chip_ALC650E    db 'ALC650E',0dh,0ah,00h
  1175                                  ;chip_ALC650F    db 'ALC650F',0dh,0ah,00h
  1176                                  ;chip_ALC655     db 'ALC655 ',0dh,0ah,00h
  1177                                  ;chip_ALC658     db 'ALC658 ',0dh,0ah,00h
  1178                                  ;chip_ALC658D    db 'ALC658D',0dh,0ah,00h
  1179                                  ;chip_ALC850     db 'ALC850 ',0dh,0ah,00h
  1180                                  
  1181                                  ;CMedia
  1182                                  ;chip_CM9738     db 'CMI9738', 0dh,0ah,0
  1183                                  ;chip_CM9739     db 'CMI9739', 0dh,0ah,0
  1184                                  ;chip_CM9780     db 'CMI9780', 0dh,0ah,0
  1185                                  ;chip_CM9761     db 'CMI9761', 0dh,0ah,0
  1186                                  
  1187                                  ;VIA
  1188                                  ;chip_VIA1612A   db 'VIA1612A',13,10,0
  1189                                  
  1190                                  ; 11/11/2023
  1191                                  msg_init_err:
  1192 00000A50 0D0A                    	db	CR, LF
  1193 00000A52 4143393720436F6E74-     	db	"AC97 Controller/Codec initialization error !"
  1193 00000A5B 726F6C6C65722F436F-
  1193 00000A64 64656320696E697469-
  1193 00000A6D 616C697A6174696F6E-
  1193 00000A76 206572726F722021   
  1194 00000A7E 0D0A24                  	db	CR, LF, "$"
  1195                                  
  1196                                  ; 12/11/2023
  1197                                  msg_no_vra:
  1198 00000A81 0D0A                    	db	CR, LF
  1199 00000A83 4E6F20565241207375-     	db	"No VRA support ! Only 48 kHZ sample rate supported !"
  1199 00000A8C 70706F72742021204F-
  1199 00000A95 6E6C79203438206B48-
  1199 00000A9E 5A2073616D706C6520-
  1199 00000AA7 726174652073757070-
  1199 00000AB0 6F727465642021     
  1200 00000AB7 0D0A24                  	db	CR, LF, "$"
  1201                                  
  1202                                  ; 17/02/2017
  1203                                  bss_start:
  1204                                  
  1205                                  ABSOLUTE bss_start
  1206                                  
  1207                                  alignb 2
  1208                                  
  1209                                  ; 28/11/2016
  1210                                  
  1211 00000ABA <res 1Ch>               smpRBuff:	resw 14 ; 19/11/2016 - Erdogan Tan
  1212                                  
  1213 00000AD6 ????                    filehandle:	resw 1
  1214                                  
  1215 00000AD8 ??                      flags:		resb 1
  1216                                  ; 06/11/2023
  1217 00000AD9 ??                      ac97_int_ln_reg: resb 1
  1218                                  
  1219                                  ; 09/11/2023
  1220                                  ; 06/11/2023
  1221                                  ;pcm_irq_status: resb 1	; 05/11/2023
  1222 00000ADA ??                      inside:		resb 1
  1223 00000ADB ??                      tloop:		resb 1	; 10/11/2023
  1224                                  
  1225                                  ; 09/11/2023
  1226                                  ; 04/11/2023 - 06/11/2023
  1227 00000ADC ????                    IRQ_status:	resw 1	; IRQ status before enabling audio interrupt
  1228 00000ADE ????????                IRQ_vector:	resd 1  ; Previous interrupt handler address	
  1229                                  
  1230                                  ; 17/02/2017
  1231                                  ; NAMBAR:  Native Audio Mixer Base Address Register
  1232                                  ;    (ICH, Audio D31:F5, PCI Config Space) Address offset: 10h-13h
  1233                                  ; NABMBAR: Native Audio Bus Mastering Base Address register
  1234                                  ;    (ICH, Audio D31:F5, PCI Config Space) Address offset: 14h-17h
  1235 00000AE2 ????                    NAMBAR:		resw 1			; BAR for mixer
  1236 00000AE4 ????                    NABMBAR:	resw 1			; BAR for bus master regs
  1237                                  
  1238                                  ; 256 byte buffer for descriptor list
  1239 00000AE6 ????                    BDL_BUFFER:	resw 1			; segment of our 256byte BDL buffer
  1240 00000AE8 ????                    WAV_BUFFER1:	resw 1			; segment of our WAV storage
  1241                                  ; 64k buffers for wav file storage
  1242 00000AEA ????                    WAV_BUFFER2:	resw 1			; segment of 2nd wav buffer
  1243                                  
  1244                                  ; 06/11/2023
  1245                                  ;tBuff:		resb 1
  1246                                  ;ac97_int_ln_reg: resb 1
  1247                                  
  1248                                  ; 12/11/2016 - Erdogan Tan
  1249                                  
  1250 00000AEC ????????                bus_dev_fn:	resd 1
  1251 00000AF0 ????????                dev_vendor:	resd 1
  1252                                  ; 06/11/2023
  1253                                  ;stats_cmd:	resw 1 ; 17/02/2017
  1254                                  ; 05/11/2023
  1255                                  ;ac97_io_base:	resw 1
  1256 00000AF4 ????                    sample_rate:	resw 1
  1257                                  
  1258                                  ; 19/11/2016
  1259 00000AF6 ????                    stmo:		resw 1 
  1260 00000AF8 ????                    bps:		resw 1
  1261                                  
  1262                                  ; 08/11/2023
  1263                                  ; 07/11/2023
  1264 00000AFA ??                      fbs_shift:	resb 1
  1265                                  ; 09/11/2023
  1266 00000AFB ??                      b_indicator:	resb 1
  1267                                  ; 10/11/2023
  1268 00000AFC ??                      LVI:		resb 1
  1269 00000AFD ??                      		resb 1 ; 10/11/2023 
  1270                                  
  1271                                  ;fbs_seg:	resw 1
  1272                                  ;fbs_off:	resw 1
  1273                                  
  1274                                  ;alignb 2
  1275                                  
  1276                                  ; 32 kilo bytes for temporay buffer
  1277                                  ; (for stereo-mono, 8bit/16bit corrections)
  1278 00000AFE <res 8000h>             temp_buffer:	resb 32768
  1279                                  
  1280                                  ;alignb 16
  1281                                  EOF:
