comment %
 codec configuration code.  Not much here really.

 improvements to be made:  Adjustable volume control for output.  Code
 below just maxes everything out (I commented it out so you don't blame me
 for blowing up your speakers)

 The delay1_4ms routines are just wait loops to let the codec handle the request.
 I think there's a status bit somewhere you can poll to know when it's safe
 to talk to the mixer registers, but a little waiting never hurt anyone.
 
%
       	.DOSSEG
        .MODEL  small, c, os_dos

.386

        .CODE

        extern  NAMBAR:word
	extern  NABMBAR:word
        extern  delay1_4ms:NEAR

        include codec.inc

; enable codec, unmute stuff, set output rate to 44.1
; entry: ax = desired sample rate
;
codecConfig proc public

	; 07/11/2016 (Erdogan Tan)
	PORT_NABM_GLB_CTRL_STAT equ 60h

	push	ax 				; sample rate
	
	;mov    dx, ds:[NAMBAR]               	; mixer base address
	;add	dx, CODEC_EXT_AUDIO_REG	       	; 28h  	  
	;in	ax, dx
	;and	ax, 1
	;jnz	short _ssr
	;pop	ax
	;jmp	short _1

_ssr:
	mov    	dx, ds:[NAMBAR]               	
	add    	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah  	  
	in     	ax, dx
	or	ax, 1
	out	dx, ax 				; Enable variable rate audio

        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms

	pop	ax				; sample rate

	mov    	dx, ds:[NAMBAR]               	
	add    	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch  	  
	out	dx, ax 				; out sample rate
		
	;mov    dx, ds:[NAMBAR]               	
	;add    dx, CODEC_LR_ADCRATE_REG 	; 32h  	  
	;out	dx, ax 

        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms

_1:
	mov     dx, ds:[NAMBAR]			; mixer base address
        add     dx, CODEC_RESET_REG  		; reset register
        mov	ax, 42
	out     dx, ax                          ; reset

	mov     dx, ds:[NABMBAR]		; bus master base address
        add     dx, PORT_NABM_GLB_CTRL_STAT
        mov	ax, 2
	out     dx, ax                         

	mov	cx, 7
_100ms:
	push	cx
        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms
	pop	cx
	loop	_100ms	
	
  	mov     dx, ds:[NAMBAR]
  	add     dx, CODEC_MASTER_VOL_REG        ;02h 
  	xor     ax, ax ; ; volume attenuation = 0 (max. volume)
  	out     dx, ax
 
  	mov     dx, ds:[NAMBAR]
  	add     dx, CODEC_MASTER_MONO_VOL_REG   ;06h 
  	;xor    ax, ax
  	out     dx, ax

  	mov     dx, ds:[NAMBAR]
  	add     dx, CODEC_PCBEEP_VOL_REG        ;0Ah 
  	;xor    ax, ax
  	out     dx, ax

  	mov     dx, ds:[NAMBAR]
  	add     dx, CODEC_PCM_OUT_REG		;18h 
  	;xor    ax, ax
  	out     dx, ax

        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms
        call    delay1_4ms

        retn

codecConfig endp

end