	
;	[]===========================================================[]
;
;	NOTICE: THIS PROGRAM BELONGS TO AWARD SOFTWARE INTERNATIONAL(R)
;	        INC. IT IS CONSIDERED A TRADE SECRET AND IS NOT TO BE
;	        DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED
;	        WRITTEN AUTHORIZATION FROM THE OWNER.
;
; 	[]===========================================================[]
;
  	  										
;----------------------------------------------------------------------------
;Rev	Date	 Name	Description
;----------------------------------------------------------------------------
;R23	10/22/98 RCH	Fixed compliation error for BIOS part No. - 2A433A19
;R21A	10/12/98 KGN	Fix NMA2 save2ram will fail
;R22	10/02/98 JDN	Added codes for ES1878 suspend/resume
;R21	09/08/98 KGN	Add Neomagic NMA2 sound chip support. as YMF715.
;R20	08/19/98 RAX	Added CS4235  and MPU401 select support.
;R19	06/01/98 JDN	Added codes for YMF715 suspend/resume
;R18	03/20/98 RAY	Move AUDIO_KERNEL definitions to AUDIO.DEF which
;			will be included in COMMON.EQU
;R17	01/08/98 JKY	Suspend ZV before turn on sound chip for ES1879
;R16	11/14/97 DNL	Rename all audio file as audio.aio
;R15	11/13/97 JKY	Suspend ZV before turn on sound chip for CREATIVE 2510
;R14	10/27/97 JDN	Add code for YMF715	
;R13	10/27/97 JKY	When Sound chip = ES1869, Suspend ZV before need active
;			ES1869 , because sound chip drive will inactive sound
;			before APM_16_SUSPEND .
;R12	07/23/97 MIL    Added GPIO 15 to En/Dis OnBoard CMI8330 Audio chip,
;			to call SMC93X.SIO (Program_CMI8330_Audio).
;R11	04/19/97 MIL	added GX86.AIO support.
;R10	04/15/97 JKY	added audio chip zv-suspend save function by audio chip
;R09	04/15/97 JKY	auto detect sound blaster register IO port 224,234,...
;			for suspend to disk save sound
;R08	02/03/97 DNL	Added codes for zero-volts suspend/resume function
;R07	11/27/96 RIC	Add YMF715 support.
;R06	10/17/96 RIC	Add CS423x Enable/Disable Sound Chip function.
;			(Define "Crystal_Item_Cmos_Bit")
;R05	10/14/96 RIC	Add CS4237B support.
;R04	10/08/96 RCH	The WIN/95 driver for YMF701 still have problem and
;			no body use this chip, kill it.
;R03	09/24/96 RIC	Add Crystal CS4236 sound chip support. as YMF711.
;R02A	09/24/96 RIC	Move YMF711 Special Code to YMF711.AIO
;R02	09/06/96 RIC	Add Special_PNP_Audio_Init hook for some Onboard
;			sound chips. Ex : YAHAMA YMF711 PnP sound chip.
;			Because it can design for No EEPROM
;R01	10/27/95 RAX	Add support Creative CT2504 sound chip
;R00	10/20/95 AVN	Buliding Onboard Audio I/O Code.

.386p
		PAGE	56,132
		TITLE	AUDIO.ASM
.XLIST
		INCLUDE	BIOS.CFG
		INCLUDE	COMMON.EQU		;R18
		INCLUDE	COMMON.MAC
;R23		INCLUDE POST.EQU

		extrn	F000_call_proc:near
		extrn	F000_GetItem_Value:near
		extrn	F000_VECT:near
		extrn	RET_E_SEG:near

;R18 	AUDIO_KERNEL	=	0
;R18 
;R18 ifdef	ES1788F
;R18 	AUDIO_KERNEL	=	1
;R18 endif	;ES1788F
;R18 
;R18 ifdef	CT2504						;R01
;R18 	AUDIO_KERNEL	=	1			;R01
;R18 endif	;CT2504						;R01
;R18 
;R18 ifdef	ES1888F
;R18 	AUDIO_KERNEL	=	1
;R18 endif	;ES1888F
;R18 
;R18 ifdef	ES1878
;R18 	AUDIO_KERNEL	=	1
;R18 endif	;ES1878

;R04 ifdef	YMF701
;R04 	AUDIO_KERNEL	=	1
;R04 endif	;YMF701

;R18 ifdef	VSA_AUDIO					;R11
;R18 	AUDIO_KERNEL	=	1			;R11
;R18 endif	;VSA_AUDIO					;R11


IF	AUDIO_KERNEL

		COMPILE_FOR_AUDIO_ASM	=	1

;R16	ifdef	ES1788F
;R16		include	ES1788.AIO
;R16	endif	;ES1788F
;R16
;R16	ifdef	CT2504					;R01
;R16		include	CT2504.AIO			;R01
;R16	endif	;CT2504					;R01
;R16
;R16	ifdef	ES1888F
;R16		include	ES1888.AIO
;R16	endif	;ES1888F
;R16
;R16	ifdef	ES1878
;R16		include	ES1878.AIO
;R16	endif	;ES1878
;R16
;R16;R04 	ifdef	YMF701
;R16;R04 		include	YMF701.AIO
;R16;R04 	endif	;YMF701
;R16
;R16	ifdef	VSA_AUDIO				;R11
;R16		include	GX86.AIO			;R11
;R16	endif	;VSA_AUDIO				;R11
;R16 - start
		include	AUDIO.AIO
;R16 - end

ENDIF	;AUDIO_KERNEL

	ifdef Crystal_Item_Cmos_Bit			;R06
		extrn	Crystal_Item:near		;R06
	endif ;Crystal_Item_Cmos_Bit			;R06
;R20 start
ifdef	MPU401_Selectable
		extrn	MPU401_item:near
endif	;MPU401_Selectable
;R20 end

G_RAM		SEGMENT	USE16 AT 0

		ORG	04H*4
		INCLUDE	SEG_0.INC

		ORG	400H
		INCLUDE	G_RAM.INC

G_RAM		ENDS

;R08 - start
ifdef	Notebook_Power_Management
SM_RAM		SEGMENT	USE16 AT 0
		INCLUDE	SM_RAM.INC
SM_RAM		ENDS
endif	;Notebook_Power_Management
;R08 - end

.LIST

DGROUP		GROUP	FCODE
FCODE           SEGMENT PARA PUBLIC 'CODE'
                ASSUME  CS:DGROUP
FCODE           ENDS

EGROUP		GROUP	ECODE
ECODE		SEGMENT	USE16 PARA PUBLIC 'ECODE'
		ASSUME	CS:EGROUP,DS:G_RAM,ES:EGROUP

;[]======================================================================[]
;[]======================================================================[]
		Public	Init_Onboard_AUDIO
Init_Onboard_AUDIO	Proc	Near

IF	AUDIO_KERNEL

		pushad
		push	ds
		push	es
		pushf
		cli

		call	Prg_Audio_Chip

		popf
		pop	es
		pop	ds
		popad

ENDIF	;AUDIO_KERNEL

		ret

Init_Onboard_AUDIO	Endp

;[]======================================================================[]
;[]======================================================================[]

IF	AUDIO_KERNEL

		COMPILE_FOR_AUDIO_ASM	=	2

;R16	ifdef	ES1788F
;R16		include	ES1788.AIO
;R16	endif	;ES1788F
;R16
;R16	ifdef	CT2504				;R01
;R16		include	CT2504.AIO		;R01
;R16	endif	;CT2504				;R01
;R16
;R16	ifdef	ES1888F
;R16		include	ES1888.AIO
;R16	endif	;ES1888F
;R16
;R16	ifdef	ES1878
;R16		include	ES1878.AIO
;R16	endif	;ES1878
;R16
;R16;R04 	ifdef	YMF701
;R16;R04 		include	YMF701.AIO
;R16;R04 	endif	;YMF701
;R16
;R16	ifdef	VSA_AUDIO				;R11
;R16		include	GX86.AIO			;R11
;R16	endif	;VSA_AUDIO				;R11
;R16 - start
		Public	Prg_Audio_Chip		;R18
		include	AUDIO.AIO
;R16 - end

ENDIF	;AUDIO_KERNEL

;[]======================================================================[]
;[]======================================================================[]
;;;		Public	E_GetItem_Value
E_GetItem_Value	Proc	Near
		jmp	F000_GetItem_Value
		ret
E_GetItem_Value	Endp

;R02-starts
ifdef CS4237B		;R05 - starts
CS4236	EQU	1
endif ;CS4237B

ifdef CS4236B
CS4236	EQU	1
endif ;CS4236B		;R05 - ends

;R20 start
ifdef CS4235
CS4236	EQU	1
endif ;CS4235
;R20 end

;[]======================================================================[]
;Special_PNP_Audio_Init
;	Initialize Some Special PNP Audio
;Save  : all but flags
;Input : None
;Output: None
;Note  :
;[]======================================================================[]
		Public	Special_PNP_Audio_Init
Special_PNP_Audio_Init	Proc	Near

	ifdef	YMF711
     		call	Program_YMF711_Audio_Resource_Data
	endif	;YMF711

	ifdef	YMF715						;R07
     		call	Program_YMF715_Audio_Resource_Data	;R07
	endif	;YMF715						;R07

	ifdef	CS4236						;R03
     		call	Program_CS4236_Audio_Resource_Data	;R03
	endif	;CS4236						;R03


	ifdef	CMI8330_Audio_Support                           ;R12
		extrn	Program_CMI8330_Audio:near              ;R12
     		call	Program_CMI8330_Audio                   ;R12
	endif	;CMI8330_Audio_Support                          ;R12

	ifdef	NMA2						;R21
     		call	Program_NMA2_Audio_Resource_Data	;R21
	endif	;NMA2						;R21

		ret
Special_PNP_Audio_Init	Endp



;R02A add follow define for moving code to YMF711.AIO, CS4236.AIO, .....

;R16ifdef	YMF711
;R16	include	YMF711.AIO
;R16endif	;YMF711
;R16
;R16ifdef	YMF715
;R16	include	YMF715.AIO
;R16endif	;YMF715
;R16
;R16ifdef	CS4236			;R03
;R16	include	CS4236.AIO	;R03
;R16endif	;CS4236			;R03
;R16 - start
		include	BIOSPNP.AIO
;R16 - end

;R02-ends

;R08 - start
ifdef	Notebook_Power_Management
		Public	Save_Sound
Save_Sound	proc	near

		push	es
		push	ds
		push	ebx

		xor	ax,ax
		mov	es,ax
;R14 - start		 		
ifdef	YMF715				
		call	Getlogdev
		call	Get_Index		;R19
		call	Save_WssMixer
endif	;YMF715
;R14 - end
;R21A - Start
ifdef	NMA2
		call	Getlogdev
		call	Get_Index
		call	Save_WssMixer
endif	;NMA2
;R21A - End
 		call	Save_SbMixer
ifdef	ES1878					;R22
		Call	Suspend_PNP_Device  	;R22	
endif	;ES1878					;R22
		call	Suspend_Save_Audio	;R10

		pop	ebx
		pop	ds
		pop	es


		ret
Save_Sound	Endp

Save_SbMixer	proc	near
		push 	ebx	
		mov	edi,ebx
		add	edi,offset Sound_State_Save

;R09 - start
		mov	si,offset Mix_addr_tbl
		mov	cx,((offset Mix_addr_end)-(offset Mix_addr_tbl))/2

	@@:
		mov	dx,cs:[si]
		mov	al,04h		;Save original Voice val
		call	Get_Mix_Val
		push	ax

		mov	ax,5504h	;Set Voice val = 55h
		call	Set_Mix_val
		IODELAY
		mov	al,04h		;Get Voice val
		call	Get_Mix_Val
		cmp	al,55h
		pop	ax
		jz	short @f

		add	si,2
		loop	@B

	    	jmp	short No_Find_Sound_S
	@@:
		mov	ah,al
		mov	al,04h		;Restore original Voice val
		call	Set_Mix_val
;R09 - end
		Call	SAVE_BEFORE_TURN_ON_AUDIO	;R15
	  		
		mov	cx,((offset Mix_tbl_end)-(offset Mix_tbl))
		mov	si,offset Mix_tbl
	@@:
		mov	al,byte ptr cs:[si]
		call	Get_Mix_Val
		stos	byte ptr es:[edi]
		inc	si
		loop	short @B

No_Find_Sound_S:	;R09
		pop   	ebx
		ret
Save_SbMixer	ENDP

;R15 - start
SAVE_BEFORE_TURN_ON_AUDIO	Proc Near
ifdef	CT2510_AUDIO_SAVE
		mov	al,7ch
		call	Get_Mix_Val
		and	al,11101111b
		or	al,11000000b
		xchg	al,ah
		mov	al,7ch
		call	Set_Mix_val
endif	;CT2510_AUDIO_SAVE
;R17 - start
ifdef	ES1879_Suspend_patch
		push	dx
		mov	al,40h
		out	dx,al
		inc	dx
		in	al,dx
		in	al,dx
		in	al,dx
		mov	ah,al
		in	al,dx
		mov	dx,ax
		mov	al,2dh
		out	dx,al
		inc	dx
		in	al,dx
		or	al,00000011b
		out	dx,al
		pop	dx
endif	;ES1879_Suspend_patch
;R17 - end
		ret
SAVE_BEFORE_TURN_ON_AUDIO	Endp
;R15 - end

		Public	Restore_Sound
Restore_Sound	proc	near

		push	es
		push	ds
		push	ebx

		xor	ax,ax
		mov	ds,ax
;R14 - start
ifdef	YMF715
		call	SetLogdev   	
		call    Restore_WssMixer
endif	;YMF715
;R14 - end

;R21A - Start
ifdef	NMA2
		call	SetLogdev   	
		call    Restore_WssMixer
endif	;NMA2
;R21A - End

ifdef	ES1878						;R22
		Call	Resume_PNP_Device		;R22	
endif	;ES1878						;R22
		call	Restore_SbMixer
		call	Suspend_Restore_Audio		;R10
		pop	ebx
		pop	ds
		pop	es
		ret
Restore_Sound	Endp

Restore_SbMixer	Proc	near
		push    ebx
;R09 - start
		mov	si,offset Mix_addr_tbl
		mov	cx,((offset Mix_addr_end)-(offset Mix_addr_tbl))/2
	@@:
		mov	dx,cs:[si]
		mov	ax,5504h	;Set Voice val = 55h
		call	Set_Mix_val
		IODELAY
		mov	al,04h		;Get Voice val
		call	Get_Mix_Val
		cmp	al,55h
		jz	short @f

		add	si,2
		loop	@B
	    	jmp	short No_Find_Sound_R
	@@:
;R09 - end

		mov	cx,((offset Mix_tbl_end)-(offset Mix_tbl))
		mov	esi,ebx
		add	esi,offset Sound_State_Save
		mov	di,offset Mix_tbl
	@@:
		mov	ah, byte ptr ds:[esi]
		mov	al, byte ptr cs:[di]
		call	Set_Mix_Val
		inc	esi
		inc	di
		loop	short @B

No_Find_Sound_R:		;R09
		pop 	ebx
		ret
Restore_SbMixer	ENDP

Get_Mix_val	proc	near
;R09		mov	dx,224h
		out	dx,al
		IODELAY
		inc	dx
		in	al,dx
		IODELAY
		dec	dx	;R09
		ret
Get_Mix_val	ENDP

Set_Mix_val	proc	near
;R09		mov	dx,224h
		out	dx,al
		IODELAY
		inc	dx
		mov	al,ah
		out	dx,al
		IODELAY
		dec	dx	;R09
		ret
Set_Mix_val	ENDP

Mix_tbl:
	db	04h
	db	0ah
	db	0ch
	db	0eh  
	db	22h
	db	26h
	db	28h
	db	2eh
ifndef	YMF715	
	db	30h
	db	31h
	db	32h
	db	33h
	db	34h
	db	35h
	db	36h
	db	37h
	db	38h
        db	39h
	db	3ah
	db	3bh
	db	3ch
	db	3dh
	db	3eh
endif	;YMF715
;R21A - Start
ifndef	NMA2
	db	30h
	db	31h
	db	32h
	db	33h
	db	34h
	db	35h
	db	36h
	db	37h
	db	38h
        db	39h
	db	3ah
	db	3bh
	db	3ch
	db	3dh
	db	3eh
endif	;NMA2
;R21A - End
Mix_tbl_end:

;R09 - start
Mix_addr_tbl:
	dw	224h
	dw	234h
	dw	244h
	dw	254h
	dw	264h
	dw	274h
	dw	284h
Mix_addr_end:
;R09 - end

;R10 - start
IF	AUDIO_KERNEL	EQ	0
Suspend_Save_Audio	Proc	near
;R13 - start
ifdef	ES1869_Suspend_patch
			;Sound chip use ES1869
			;issue reset signal : sound chip wakeup
			mov	dx,226h		;Audio_Base + 6 = 1
			mov	al,1		
			out	dx,al		
			in	al,dx		

			mov	al,0		;Audio_Base + 6 = 0
			out	dx,al		
			xor	cx,cx		
			loop	$		

			mov	dx,22eh		;if Audio_Base+E bit 7 = 1
			in	al,dx		;   then reset ok
			test	al,10000000b	
			jz	short Reset_ok	
			mov	dx,22ah		;else read Audio_Base+A
		retry:				
			in	al,dx		
			cmp	al,0aah		;if Audio_Base+A != 0aah
			jne	short retry	;   then retry
		Reset_ok:			

			xor	cx,cx		
			loop	short $		
endif	;ES1869_Suspend_patch
;R13 - end

;R14 - start
ifdef	YMF715
		call	Save_Wss
endif	;YMF715
;R14 - end
;R21A - Start
ifdef	NMA2
		call	Save_Wss
endif	;NMA2
;R21A - End
		ret
Suspend_Save_Audio	endp

Suspend_Restore_Audio	Proc	near
;R14 - start
ifdef	YMF715
		call    Restore_Wss
		call	Set_Index		;R19					
endif	;YMF715				
;R14 - end
;R21A - Start
ifdef	NMA2
		call    Restore_Wss
		call	Set_Index
endif	;NMA2
;R21A - End
		ret
Suspend_Restore_Audio	endp

;R08 - end

ENDIF	;AUDIO_KERNEL	EQ	0
;R10 - end
endif	;Notebook_Power_Management

ECODE		ENDS
		END
