;	[]===========================================================[]
;
;	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.
;
; 	[]===========================================================[]
;

ifdef	W83977TF
;----------------------------------------------------------------------------
;Rev	  Date	 Name	Description
;----------------------------------------------------------------------------
;R01	02/01/99 GAR	Add No_Use_Parallel_Port
;R00	02/01/99 GAR	Move from superio.sio For dual i/o node

;***************************************************************************
;******* PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM *******
;******* PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM *******
;******* PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM *******
;******* PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM PNPIO.ASM *******
;***************************************************************************
ifdef	COMPILE_FOR_PNPIO_ASM
ifdef	Report_Secondio_Nodes
IF	COMPILE_FOR_PNPIO_ASM	EQ	1
ifdef	USE_370h
; Create M/B device node for super I/O access port reporting
DEV_NODE	41D0H, 0C02H, 088000H, 00000011B, SIO_NODE
	IO_DSP 	 1, 370h, 370h, 0, 2		;access port
	END_DSP
	END_DSP
	END_DSP
DEV_NODE_END
endif;	USE_370h

ifndef	NO_USE_FDD
;==============================================================
;Floppy controller device node
;==============================================================
W83977TF_FDD_Node:
DEV_NODE	41D0H, 0700H, 010200H, 0000000000000011B, FDD_NODE
	DMA_DSP 	00000000B, 0
	IO_DSP 		0, 000h, 000h, 0, 0
	IRQ_DSP 	0000000000000000b
	END_DSP

FDD_Node_Table:
 START_DF
	DMA_DSP 	00000100B, 0
	IO_DSP 		1, 3F2h, 3F2h, 0, 4
	IRQ_DSP 	0000000001000000b	;IRQ 6
Fdd_Node_Length equ	$ - Fdd_Node_Table
 END_DF

	END_DSP
	END_DSP
DEV_NODE_END
endif	;NO_USE_FDD

;==============================================================
;Serial port 1 device node
;==============================================================
W83977TF_Com1_Node:
DEV_NODE	41D0H, 0501H, 070002H, 0000000110000000B, COM1_NODE

W83977TF_Com1_IRQ	EQU	$ - offset dgroup:W83977TF_Com1_Node
	IRQ_DSP 	0000000000000000b	;node disabled
	IO_DSP 		0, 000h, 000h, 0, 0 	;node disabled
	END_DSP

_COM1_IRQ_LOCATION:
	IRQ_DSP 	_IRQ_Byte
COM1_IRQ_DISTANCE	EQU	($ - offset dgroup : _COM1_IRQ_LOCATION )

Com1_Node_Table:
 START_DF
	IO_DSP 		1, 3F8h, 3F8h, 0, 8 		;I/O port 3F8h-3FFh
Com_Node_Length equ	($ - Com1_Node_Table)
 START_DF
	IO_DSP 		1, 2F8h, 2F8h, 0, 8 		;I/O port 2F8h-2FFh
 START_DF
	IO_DSP 		1, 3E8h, 3E8h, 0, 8 		;I/O port 3E8h-3EFh
 START_DF
	IO_DSP 		1, 2E8h, 2E8h, 0, 8 		;I/O port 2E8h-2EFh
Total_Possible_COM	EQU	( $ - ( offset dgroup:Com1_Node_Table )) / ( Com_Node_Length )
 END_DF
	END_DSP
	END_DSP

DEV_NODE_END

;==============================================================
;Serial port 2 device node
;==============================================================
W83977TF_Com2_Node:
DEV_NODE	41D0H, 0501H, 070002H, 0000000110000000B, COM2_NODE
W83977TF_Com2_IRQ	EQU	$ - offset dgroup:W83977TF_Com2_Node
	IRQ_DSP 	0000000000000000b
	IO_DSP 		0, 000h, 000h, 0, 0 	;node disabled
	END_DSP

	IRQ_DSP 	_IRQ_Byte

Com2_Node_Table:
 START_DF
	IO_DSP 		1, 3F8h, 3F8h, 0, 8		;I/O port 3F8h-3FFh
 START_DF
	IO_DSP 		1, 2F8h, 2F8h, 0, 8		;I/O port 2F8h-2FFh
 START_DF
	IO_DSP 		1, 3E8h, 3E8h, 0, 8		;I/O port 3E8h-3EFh
 START_DF
	IO_DSP 		1, 2E8h, 2E8h, 0, 8		;I/O port 2E8h-2EFh
 END_DF
	END_DSP
	END_DSP

DEV_NODE_END

ifndef	Not_Report_IR
;==============================================================
;Infra Red port  device node
;==============================================================
W83977TF_IR_Node:
DEV_NODE	41D0H, 0510H, 070002H, 0000000110000000B, IR_NODE
W83977TF_IR_IRQ		EQU	$ - offset dgroup : W83977TF_IR_Node
	IRQ_DSP 	0000000000000000b
	IO_DSP 		0, 000h, 000h, 0, 0 	;node disabled
	END_DSP

	IRQ_DSP 	_IRQ_Byte

IR_Node_Table:
 START_DF
	IO_DSP 		1, 3F8h, 3F8h, 0, 8		;I/O port 3F8h-3FFh
 START_DF
	IO_DSP 		1, 2F8h, 2F8h, 0, 8		;I/O port 2F8h-2FFh
 START_DF
	IO_DSP 		1, 3E8h, 3E8h, 0, 8		;I/O port 3E8h-3EFh
 START_DF
	IO_DSP 		1, 2E8h, 2E8h, 0, 8		;I/O port 2E8h-2EFh
 END_DF
	END_DSP
	END_DSP

DEV_NODE_END
endif;	Not_Report_IR

ifndef	No_Use_Parallel_Port		;R02
;==============================================================
;Printer port device node
;==============================================================
W83977TF_Lpt_Node:
DEV_NODE	41D0H, 0400H, 070100H, 0000000110000000B, LPT_NODE
W83977TF_Lpt_IRQ		EQU	$ - offset dgroup:W83977TF_Lpt_Node
	IRQ_DSP 	0000000000000000b	;IRQ ?
	IO_DSP 		0, 000h, 000h, 0, 0 	;I/O port ???
	END_DSP

_Lpt_IRQ_LOCATION:
	IRQ_DSP 	_IRQ_Byte
Lpt_IRQ_DISTANCE	EQU	($ - offset dgroup : _Lpt_IRQ_LOCATION )

Normal_Lpt_Tbl:
Lpt_378_Tbl:
 START_DF
	IO_DSP 		1, 378h, 378h, 0, 8 		;I/O port 378h-37Bh
Lpt_Node_Length equ	$ - offset dgroup:Lpt_378_Tbl

Lpt_278_Tbl:
 START_DF
	IO_DSP 		1, 278h, 278h, 0, 8 		;I/O port 278h-27Bh

ifndef	No_LPT_3BC
Lpt_3BC_Tbl:
 START_DF
	IO_DSP 		1, 3BCh, 3BCh, 0, 4 		;I/O port 3BCh-3BFh
endif	;No_LPT_3BC

TOTAL_POSSIBLE_LPT	EQU	($ - offset dgroup:Normal_Lpt_Tbl)/(Lpt_Node_Length)

 END_DF

	END_DSP
	END_DSP

DEV_NODE_END

;==============================================================
;Printer port device node
;==============================================================
W83977TF_Ecp_Node:
DEV_NODE	41D0H, 0401H, 070102H, 0000000110000000B, ECP_NODE
W83977TF_ECP_DMA		EQU	$ - offset dgroup : W83977TF_Ecp_Node
	DMA_DSP 	00000000b, 0		;DMA ??
W83977TF_ECP_IRQ		EQU	$ - offset dgroup : W83977TF_Ecp_Node
	IRQ_DSP 	0000000000000000b	;IRQ ?
	IO_DSP 		0, 000h, 000h, 0, 0 	;I/O port ???
	IO_DSP		0, 000h, 000h, 0, 0
	END_DSP

_Ecp_Dma_LOCATION:
ifndef	Use_DMA_012_Routing					
	DMA_DSP 	00001010b, 0		;DMA 1,3
else;	Use_DMA_012_Routing					
	DMA_DSP 	00000011b, 0		;DMA 0,1	
endif;	Use_DMA_012_Routing					

	IRQ_DSP 	_IRQ_Byte
Ecp_DISTANCE	EQU	($ - offset dgroup : _Ecp_Dma_LOCATION )

Ecp_Node_Table:

Ecp_378_Tbl:
 START_DF
	IO_DSP 		1, 378h, 378h, 0, 8 	;I/O port 378h-37Fh
	IO_DSP		1, 778h, 778h, 0, 3
Ecp_Node_Length equ	$ - offset dgroup:Ecp_378_Tbl

Ecp_278_Tbl:
 START_DF
	IO_DSP 		1, 278h, 278h, 0, 8 	;I/O port 278h-27Fh
	IO_DSP		1, 678h, 678h, 0, 3

ifndef	No_LPT_3BC
Ecp_3BC_Tbl:
 START_DF
	IO_DSP 		1, 3BCh, 3BCh, 0, 4 	;I/O port 3BCh-3BFh
	IO_DSP		1, 7BCh, 7BCh, 0, 3
endif	;No_LPT_3BC

TOTAL_POSSIBLE_ECP	EQU	($ - offset dgroup:Ecp_Node_Table)/(Ecp_Node_Length)

 END_DF

	END_DSP
	END_DSP

DEV_NODE_END
endif	;No_Use_Parallel_Port		;R02
ENDIF	;COMPILE_FOR_PNPIO_ASM	EQ	1

IF	COMPILE_FOR_PNPIO_ASM	EQ	2
ifdef	Use_370h				
	SET_NODE_INDEX	SIO_NODE, 00001000B	
endif;	Use_370h				
	SET_NODE_INDEX	COM1_NODE, <NEED_SET_DYNM+NEED_GET_NODE+NEED_POST_NODE>
ifndef	NO_USE_FDD
	SET_NODE_INDEX	FDD_NODE,  <NEED_GET_NODE+NEED_POST_NODE>
endif	;NO_USE_FDD
ifndef	No_Use_Parallel_Port		;R02
	SET_NODE_INDEX	LPT_NODE,  <NEED_SET_DYNM+NEED_GET_NODE+NEED_POST_NODE>
	SET_NODE_INDEX	ECP_NODE,  <NEED_SET_DYNM+NEED_GET_NODE+NEED_POST_NODE>
endif	;No_Use_Parallel_Port		;R02
	SET_NODE_INDEX	COM2_NODE, <NEED_SET_DYNM+NEED_GET_NODE+NEED_POST_NODE>
ifndef	Not_Report_IR
	SET_NODE_INDEX	IR_NODE, <NEED_SET_DYNM+NEED_GET_NODE+NEED_POST_NODE>
endif;	Not_Report_IR
ENDIF	;COMPILE_FOR_PNPIO_ASM	EQ	2

IF	COMPILE_FOR_PNPIO_ASM	EQ	3
ifdef	Use_370h				
	NODE_PROC	SIO_NODE, Dummy_Set_Node, Dummy_Set_Node, IO_AccessNode	
endif;	Use_370h				
	NODE_PROC 	COM1_NODE ,Ct_Get_Com1_Node ,Ct_Set_Com1_Node ,Ct_Post_Com1
ifndef	NO_USE_FDD
	NODE_PROC	FDD_NODE  ,Ct_Get_Fdd_Node  ,Ct_Set_Fdd_Node  ,Ct_Post_Fdd
endif	;NO_USE_FDD
ifndef	No_Use_Parallel_Port		;R02
	NODE_PROC	LPT_NODE  ,Ct_Get_Lpt_Node  ,Ct_Set_Lpt_Node  ,Ct_Post_Lpt
	NODE_PROC 	ECP_NODE  ,Ct_Get_Ecp_Node  ,Ct_Set_Ecp_Node  ,Ct_Post_Ecp
endif	;No_Use_Parallel_Port		;R02
	NODE_PROC 	COM2_NODE ,Ct_Get_Com2_Node ,Ct_Set_Com2_Node ,Ct_Post_Com2
ifndef	Not_Report_IR
	NODE_PROC 	IR_NODE   ,Ct_Get_IR_Node   ,Ct_Set_IR_Node   ,Ct_Post_IR
endif;	Not_Report_IR
ENDIF	;COMPILE_FOR_PNPIO_ASM	EQ	3

IF	COMPILE_FOR_PNPIO_ASM	EQ	4
;****************************************************************
;*								*
;*	ONBOARD DEVICE NODES PROCESS ROUTINES			*
;*								*
;****************************************************************

ifdef	Use_370h
;[]========================================================================[]
; Input:	ES:DI = Device node structure pointer
; Output:	CF = 0 Device node structure modified successful
;		CF = 1 Device disabled
;[]========================================================================[]
IO_AccessNode	proc	near
		clc			;dummy
		ret
IO_AccessNode	endp
endif;	Use_370h
ifndef	NO_USE_FDD
;[]=======================================================================[]
;Procedure :	Ct_Get_Fdd_Node
;
;Input	:	ES:DI --> FDD devnode starting address
;		CL : 01h - Get current setting
;		     02h - Get next boot setting
;
;Note	:	This routine should copy the correct FDD devnode
;		into ES:[DI+12] while 12 means the header length
;		of the devnode
;
;Regs	:	Do not destroy ES
;[]=======================================================================[]
Ct_Get_Fdd_Node Proc	Near

		call	Unlock_977
		xor	cl,cl			;device 0 for FDD
		call	Set_Logic_Device

		call	Get_Dev_Active	 	;FDD enable ?
		jc	short Fdd_Disabled	;no !

	Report_Fdd:
		mov	si, offset dgroup: Fdd_Node_Table
		mov	cx, Fdd_Node_Length-1
		call	Rep_Movsb

	Fdd_Disabled:
		call	 Lock_977
		ret

Ct_Get_Fdd_Node Endp

;[]=======================================================================[]
;Input	:	ES = DevNode Buffer SEGMENT
;		DI = DevNode Buffer OFFSET
;		CL : bit 0 - Set Dynamically
;		     bit 1 - Set Statically
;[]=======================================================================[]
		Public	Ct_Set_Fdd_Node
Ct_Set_Fdd_Node	Proc	Near
		ret
Ct_Set_Fdd_Node	Endp

;[]=======================================================================[]
; Input:	ES:DI = point to devnode address
; Output:	CF = 0 device enabled
;		CF = 1 device disabled
;[]=======================================================================[]
Ct_Post_Fdd	Proc	Near
		call	Unlock_977
		xor	cl,cl			;device 0 for FDD
		call	Set_Logic_Device
		call	Get_Dev_Active
@@:
		call	Lock_977
		ret
Ct_Post_Fdd	Endp
endif	;NO_USE_FDD

;[]=======================================================================[]
;Procedure :	Ct_Get_Com1_Node
;
;Input	:	ES:DI --> COM1 devnode starting address
;		CL : 01h - Get current setting
;		     02h - Get next boot setting
;
;Note	:	This routine should copy the correct COM1 devnode
;		into ES:[DI+12] while 12 means the header length
;		of the devnode
;
;Regs	:	Do not destroy ES
;[]=======================================================================[]
Ct_Get_Com1_Node	Proc	Near

		call	Unlock_977
		mov	cl,2			;device 2 for UARTA
		call	Set_Logic_Device

		call	Get_Dev_Active
		jc	short Com1_Disabled

		mov	si, offset dgroup:Com1_Node_Table
;report IRQ
		call	Get_Irq
		mov	word ptr es:[di+W83977TF_Com1_IRQ+1], ax

	Report_Com:
		add	di, COM1_IRQ_DISTANCE
		xor	al, al
		call	Get_IOPort
		cmp	bx,3f8h			;COM1 is 3f8 ?
		je	short @f
		inc	al
		cmp	bx,2f8h			;COM1 is 2f8 ?
		je	short @f
		inc	al
		cmp	bx,3e8h			;COM1 is 3e8 ?
		je	short @f
		inc	al
	@@:
	Report_Coma:
		mov	ah, Com_Node_Length
		mul	ah
		add	si, ax
		mov	cx, Com_Node_Length-1
		call	Rep_Movsb

	Com1_Disabled:

		call	Lock_977
		ret

Ct_Get_Com1_Node	Endp

;[]=======================================================================[]
;Input	:	ES = DevNode Buffer SEGMENT
;		DI = DevNode Buffer OFFSET
;		CL : bit 0 - Set Dynamically
;		     bit 1 - Set Statically
;[]=======================================================================[]
Ct_Set_Com1_Node	Proc	Near
		call	Unlock_977
		mov	cl,2			;device 2 for UARTA
		call	Set_Logic_Device

		mov	si, offset dgroup:W83977TF_Com1_Node

		call	Set_Com_Proc
	      	jc	short Set_Com1_Fail

		mov	ax, word ptr es:[di+W83977TF_Com1_IRQ+1]
Set_Com_Irq:
		xor	ch, ch
		or	ax, ax
		jz	short Set_COM1_IRQ
		shr	ax, 1
	@@:
		shr	ax, 1
		inc	ch
		jnc	short @b

		mov	al, ch
	Set_COM1_IRQ:
		call	Set_IrqPort

		mov	si, offset dgroup: COM1_Data_Tbl
	Set_Register:
		mov	di, offset dgroup: Index_Tbl
		mov	bh, NO_OF_REG
		call	Set_from_tbl

		clc

	Set_Com1_Fail:

		call	Lock_977
		ret

Ct_Set_Com1_Node	Endp
Index_Tbl:
	db	30h,      60h,      61h
	db	11111110b,11111100b,00000011b
NO_OF_REG	EQU	(($-(offset dgroup: Index_Tbl))/2)

COM1_Data_Tbl:
	db	00000001b,00000011b,11111000b	;3F8
	db	00000001b,00000010b,11111000b	;2F8
	db	00000001b,00000011b,11101000b	;3E8
	db	00000001b,00000010b,11101000b	;2E8
	db	00000000b,00000000b,00000000b	;Disable

;[]=======================================================================[]
; Input:	ES:DI = point to devnode address
; Output:	CF = 0 device enabled
;		CF = 1 device disabled
;[]=======================================================================[]

Ct_Post_Com1	proc	near
		call	Unlock_977
		mov	cl,2			;device 2 for UARTA
		call	Set_Logic_Device
		call	Get_Dev_Active
		call	Lock_977
		ret
Ct_Post_Com1	endp

;[]=======================================================================[]
;Procedure :	Ct_Get_Com2_Node
;
;input	:	ES:DI --> COM2 devnode starting address
;
;output :	CF = Serial port 2 not exist
;		NC = Serial port 2 exist
;
;Note	:	This routine should copy the correct COM2 devnode
;		into ES:[DI+12] while 12 means the header length
;		of the devnode
;
;Regs	:	Do not destroy ES
;[]=======================================================================[]
Ct_Get_Com2_Node	Proc	Near

		call	Unlock_977
		mov	cl,3			;device 3 for UARTB
		call	Set_Logic_Device

ifndef	NO_IR_selectable			
		call	Check_IR_Active		;check IrDA Setting?
		cmc
		jc	short Com1_Disabled	;Yes,It is IR Setting
endif	;NO_IR_selectable			

		call	Get_Dev_Active
		jc	short Com1_Disabled
		mov	si, offset dgroup:Com2_Node_Table
;report IRQ
		call	Get_Irq
		mov	word ptr es:[di+W83977TF_Com2_IRQ+1],ax
		jmp	Report_Com

Ct_Get_Com2_Node	Endp

;[]=======================================================================[]
;Input	:	ES = DevNode Buffer SEGMENT
;		DI = DevNode Buffer OFFSET
;		CL : bit 0 - Set Dynamically
;		     bit 1 - Set Statically
;[]=======================================================================[]
Ct_Set_Com2_Node	Proc	Near

		call	Unlock_977
		mov	cl,3			;device 3 for UARTB
		call	Set_Logic_Device

		mov	si, offset dgroup:W83977TF_com2_Node
		call	Set_Com_Proc
      		jc	short Set_Com1_Fail
;report IRQ
		mov	ax, word ptr es:[di+W83977TF_Com2_IRQ+1]
		jmp	Set_Com_Irq

Ct_Set_Com2_Node	Endp

Set_Com_PROC:
		mov	cx, (Com_Node_Length)-1
		mov	bh, TOTAL_POSSIBLE_COM
		mov	dx, COM1_IRQ_DISTANCE
		call	Chk_Set_Which_Cfg
		jc	short @F
		cmp	bh, -1			;set disable ?
		clc
		jne	short @f		;go set disable !
		mov	bl, TOTAL_POSSIBLE_COM
	@@:
	     	ret

;[]=======================================================================[]
; Input:	ES:DI = point to devnode address
; Output:	CF = 0 device enabled
;		CF = 1 device disabled
;[]=======================================================================[]

Ct_Post_Com2	proc	near
		call	Unlock_977
		mov	cl,3			;device 3 for UARTB
		call	Set_Logic_Device

ifndef	NO_IR_selectable			
		call	Check_IR_Active		;check IrDA Setting?
		cmc
		jc	short @F		;Yes,IT is IR Setting
endif	;NO_IR_selectable			

		call	Get_Dev_Active
	@@:
		call	Lock_977
		ret
Ct_Post_Com2	endp

ifndef	Not_Report_IR
;[]=======================================================================[]
;Procedure :	Ct_Get_IR_Node
;
;input	:	ES:DI --> IR devnode starting address
;
;output :	CF = Serial port 2 not exist
;		NC = Serial port 2 exist
;
;Note	:	This routine should copy the correct IR devnode
;		into ES:[DI+12] while 12 means the header length
;		of the devnode
;
;Regs	:	Do not destroy ES
;[]=======================================================================[]
Ct_Get_IR_Node	Proc	Near

		call	Unlock_977
		call	Check_9771_9773		;check 9771 or 9773 ?
		call	Set_Logic_Device

		call	Check_IR_Active		;check IrDA Setting?
		jc	Com1_Disabled

		call	Get_Dev_Active
		jc	Com1_Disabled

		mov	si, offset dgroup:IR_Node_Table
;report IRQ
		call	Get_Irq
		mov	word ptr es:[di+W83977TF_IR_IRQ+1],ax
		jmp	Report_Com
Ct_Get_IR_Node	Endp

;[]=======================================================================[]
;Input	:	ES = DevNode Buffer SEGMENT
;		DI = DevNode Buffer OFFSET
;		CL : bit 0 - Set Dynamically
;		     bit 1 - Set Statically
;[]=======================================================================[]
Ct_Set_IR_Node	Proc	Near

		call	Unlock_977
		call	Check_9771_9773		;check 9771 or 9773 ?
		call	Set_Logic_Device

		mov	si, offset dgroup:W83977TF_IR_Node
		call	Set_Com_Proc
      		jc	Set_Com1_Fail

		mov	ax, word ptr es:[di+W83977TF_IR_IRQ+1]
		jmp	Set_Com_Irq
Ct_Set_IR_Node	Endp

;[]=======================================================================[]
; Input:	ES:DI = point to devnode address
; Output:	CF = 0 device enabled
;		CF = 1 device disabled
;[]=======================================================================[]

Ct_Post_IR	proc	near
		call	Unlock_977
		call	Check_9771_9773		;check 9771 or 9773 ?
		call	Set_Logic_Device

		call	Check_IR_Active		;check IrDA Setting?
		jc	short No_Report_IR	;
		call	Get_Dev_Active
	No_Report_IR:
		call	Lock_977
		ret
Ct_Post_IR	endp

Check_9771_9773:
ifdef AUTO_CHECK_W83977AW			
		mov	cl, 20h
		call	Get_977
		mov	ah, al

		mov	cl, 21h
		call	Get_977
		mov	cl, 6			;IR at device 6
		cmp	ax, 9773h		;Check 9773?
		jne	short @f
endif ;AUTO_CHECK_W83977AW			
		mov	cl, 3			;IR at device 3 UART2
	@@:
		ret

ifdef	Special_Show_not_move_E000		
ifdef	Password_ON_NOW_SUPPORT
ifdef AUTO_CHECK_W83977AW			
		public	For_Check_AW_Chipset
For_Check_AW_Chipset	Proc	Near
		call	Unlock_977
		mov	cl, 0ah
		call	Set_Logic_Device
		mov	cl, 60h
		call	Get_977
		not	al
		push	ax
		call	Lock_977
		pop	ax
		ret
For_Check_AW_Chipset	Endp
endif ;AUTO_CHECK_W83977AW			
endif;	Password_ON_NOW_SUPPORT
endif;	Special_Show_not_move_E000		

;--------------------------------------
;Input : CL : 6 - W83977TF ID is 9771
;	      3	- W83977TF ID is 9773
;Output: carry clear - IR enabled
;	 carry set   - No IR enabled
;--------------------------------------
Check_IR_Active:
		cmp	cl, 6
		je	short Is_IR_Setting
		mov	cl, 0f1h		;IR function selection
		call	Get_977
		cmp	al, 0ffh
		je	short Not_IR_Setting
		and	al, 00111000b
		cmp	al, 00011000b
		je	short Is_IR_Setting
	Not_IR_Setting:
		stc				;return C flag not IR function
		ret
	Is_IR_Setting:
		clc				;return none C flag,is IR function
		ret

endif;	Not_Report_IR

ifndef	No_Use_Parallel_Port		;R02
;--------------------------------------
;Input : None
;Output: carry clear - ECP enabled
;	 carry set   - No ECP enabled
;--------------------------------------
Chk_Lpt_Ecp:					;NC ECP , CF no ECP
		mov	cl, 0f0h
		call	Get_977
		test	al, 00000010b
		jnz	short @f
		stc				;normal
	@@:
		ret

;[]=======================================================================[]
;Procedure :	Ct_Get_Lpt_Node
;
;input	:	ES:DI --> LPT devnode starting address
;		CL : 01h - Get current setting
;		     02h - Get next boot setting
;
;output :	CF = LPT port not exist
;		NC = LPT port exist
;
;Note	:	This routine should copy the correct LPT devnode
;		into ES:[DI+12] while 12 means the header length
;		of the devnode
;
;Regs	:	Do not destroy ES
;[]=======================================================================[]
Ct_Get_Lpt_Node Proc	Near

	call	Unlock_977
	mov	cl,1			;device 1 for LPT
	call	Set_Logic_Device

	call	Get_Dev_Active
	jc	short LPT_None		;disabled !

	call	Chk_Lpt_Ecp
	jnc	short LPT_None

;report IRQ
	call	short Get_Irq
	mov	word ptr es:[di+W83977TF_Lpt_IRQ+1], ax
	add	di, LPT_IRQ_DISTANCE
	call	Get_IOPort

ifndef	No_LPT_3BC
	mov	si, offset dgroup:Lpt_3BC_Tbl
	cmp	bx,3bch			;3BC ?
	je	short @F		;yes !
endif	;No_LPT_3BC

	mov	si, offset dgroup:Lpt_378_Tbl
	cmp	bx,378h			;378 ?
	je	short @F		;yes !

	mov	si, offset dgroup:Lpt_278_Tbl
@@:
Report_Lpt:

	mov	cx, Lpt_Node_Length-1
	call	Rep_Movsb

LPT_None:

	call	Lock_977
	ret

Ct_Get_Lpt_Node Endp

;[]=======================================================================[]
;Input	:	ES = DevNode Buffer SEGMENT
;		DI = DevNode Buffer OFFSET
;		CL : bit 0 - Set Dynamically
;		     bit 1 - Set Statically
;[]=======================================================================[]
Ct_Set_Lpt_Node Proc	Near

		call	Unlock_977
		mov	cl,1			;device 1 for LPT
		call	Set_Logic_Device

		mov	si, offset dgroup:W83977TF_Lpt_Node
		mov	cx, (LPT_Node_Length)-1
		mov	bh, TOTAL_POSSIBLE_LPT
		mov	dx, LPt_IRQ_DISTANCE
		call	Chk_Set_Which_Cfg
		jc	short Set_LPT_Fail
		cmp	bh, -1			;set disable ?
		jne	short @f		;go set disable !
		mov	bl, TOTAL_POSSIBLE_LPT
@@:
;report IRQ
		mov	ax, word ptr es:[di+W83977TF_LPT_IRQ+1]
SET_LPT_ECP_IRQ:
		push	bx
		xor	ch, ch
		or	ax, ax
		jz	short Set_LPT_IRQ
		shr	ax, 1
@@:
		shr	ax, 1
		inc	ch
		jnc	short @b

		mov	al, ch
Set_LPT_IRQ:
		call	Set_IrqPort
		pop	bx
	@@:
		mov	si, offset dgroup:Lpt_Data_Tbl
		jmp	Set_register

	Set_Lpt_Fail:

		call	Lock_977
		ret

Ct_Set_Lpt_Node Endp

Lpt_Data_Tbl:
	db	00000001b,00000011b,01111000b ;378
	db	00000001b,00000010b,01111000b ;278
	db	00000001b,00000011b,10111100b ;3BC
	db	00000000b,00000000b,00000000b ;disabled

;[]=======================================================================[]
; Input:	ES:DI = point to devnode address
; Output:	CF = 0 device enabled
;		CF = 1 device disabled
;[]=======================================================================[]
Ct_Post_Lpt	proc	near
		call	Unlock_977
		mov	cl,1			;device 1 for LPT
		call	Set_Logic_Device

		call	Get_Dev_Active
		jc	short @f

		call	Chk_Lpt_Ecp
		cmc
	@@:
		call	Lock_977
		ret
Ct_Post_Lpt	endp

;[]=======================================================================[]
;Procedure :	Ct_Get_ECP_Node
;
;input	:	ES:DI --> ECP devnode starting address
;		CL : 01h - Get current setting
;		     02h - Get next boot setting
;
;output :	CF = ECP port not exist
;		NC = ECP port exist
;
;Note	:	This routine should copy the correct ECP devnode
;		into ES:[DI+12] while 12 means the header length
;		of the devnode
;
;Regs	:	Do not destroy ES
;[]=======================================================================[]
Ct_Get_ECP_Node Proc	Near

		call	Unlock_977
		mov	cl,1			;device 1 for LPT
		call	Set_Logic_Device

		call	Get_Dev_Active
		jc	short ECP_None		;disabled !

		call	Chk_Lpt_ECP
		jc	short ECP_None

		call	Get_DMA			;check LPT use DMA ?
		mov	byte ptr es:[di+W83977TF_ECP_DMA+1], al	;set DMA

		call	short Get_Irq
		mov	word ptr es:[di+W83977TF_ECP_IRQ+1], ax

		add	di, ECP_DISTANCE

		call	Get_IOPort

		mov	si, offset dgroup:ECP_3BC_Tbl
		cmp	bx,3BCh			;3BC ?
		je	short @F		;yes !

		mov	si, offset dgroup:ECP_378_Tbl
		cmp	bx,378h			;378 ?
		je	short @F		;yes !

		mov	si, offset dgroup:ECP_278_Tbl
@@:

		mov	cx, ECP_Node_Length-1
		call	Rep_Movsb

ECP_None:
		call	Lock_977
		ret

Ct_Get_ECP_Node Endp

;[]=======================================================================[]
;Input	:	ES = DevNode Buffer SEGMENT
;		DI = DevNode Buffer OFFSET
;		CL : bit 0 - Set Dynamically
;		     bit 1 - Set Statically
;[]=======================================================================[]
Ct_Set_ECP_Node Proc	Near

		call	Unlock_977
		mov	cl,1			;device 1 for ECP
		call	Set_Logic_Device

		mov	si, offset dgroup:W83977TF_ECP_Node
		mov	bh, TOTAL_POSSIBLE_ECP
		mov	cx, (ECP_Node_Length)-1	;possible resource len
		mov	dx, ECP_DISTANCE
		call	Chk_Set_Which_Cfg
		jc	short Set_ECP_Fail

		cmp	bh, -1
		jne	short @F
		mov	bl, TOTAL_POSSIBLE_ECP
@@:
		mov	al, es:[di+W83977TF_ECP_DMA+1]
		mov	bh, 4			
		or	al, al			;if no setting
		jz	short Set_Ecp_Dma	;error
		mov	bh, -1
@@:
		shr	al, 1
		inc	bh
		jnc	short @b
Set_Ecp_Dma:
		mov	al, bh
ifdef	Use_DMA_012_Routing			
		inc	al			
endif;	Use_DMA_012_Routing			
		mov	cl, 74h
		call	Set_977

		mov	ax, word ptr es:[di+W83977TF_ECP_IRQ+1]
		jmp	Set_Lpt_Ecp_Irq

Set_ECP_Fail:

		call	Lock_977
		ret

Ct_Set_ECP_Node Endp

;[]=======================================================================[]
; Input:	ES:DI = point to devnode address
; Output:	CF = 0 device enabled
;		CF = 1 device disabled
;[]=======================================================================[]
Ct_Post_ECP	proc	near

		call	Unlock_977
		mov	cl,1			;device 1 for LPT
		call	Set_Logic_Device

		call	Get_Dev_Active
		jc	short @f

		call	Chk_Lpt_Ecp
	@@:
		call	Lock_977
		ret
Ct_Post_ECP	endp
endif	;No_Use_Parallel_Port		;R02

;[]==============================================================[]
;input	:	BH =  of register to program
;		BL = prg. IO chip according to #BL tbl
;		DI : Index Table
;		SI : Data Table
;[]==============================================================[]
Set_From_Tbl	Proc	Near

		push	bx
		movzx	cx, bh
		mov	al, bh
		mul	bl
		add	si, ax
		mov	bx, cx
@@:
		push	cx
		mov	cl, cs:[di]
		call	Get_977
		and	al, cs:[di+bx]
		or	al, cs:[si]
		call	Set_977
		pop	cx
		inc	si
		inc	di
		loop	short @B
		pop	bx
		ret
Set_From_Tbl	Endp

;[]==============================================================[]
;Output	: AL - DMA Node to get
;[]==============================================================[]
Get_DMA		proc	near
		mov	cl,74H			;DMA register
	 	call	Get_977
ifdef	Use_DMA_012_Routing			
		cmp	al, 4			
		je	short NO_DEC_AL		
		dec	al			
	NO_DEC_AL:				
endif;	Use_DMA_012_Routing			
		mov	cl, al
		mov	al, 1
		shl	al, cl
		ret
Get_DMA		endp

;[]==============================================================[]
;Output	: AL - IRQ port to get
;[]==============================================================[]
Get_IrqPort	proc	near

		mov	cl,70H			;IRQ register
	 	call	Get_977
		ret
Get_IrqPort	endp

;[]==============================================================[]
;Output	: AX - IRQ Node to get
;[]==============================================================[]
Get_Irq		proc	near
		call	Get_IrqPort
		mov	cl, al
		mov	ax, 1
		shl	ax, cl
		ret
Get_Irq		endp

;[]==============================================================[]
;Input	: CH - which IRQ port to set
;[]==============================================================[]
Set_IrqPort	proc	near
		mov	al,ch
		mov	cl,70H			;IRQ register
	 	call	Set_977
		ret
Set_IrqPort	endp
;[]==============================================================[]
;Output	: BX - I/O port to get
;[]==============================================================[]
Get_IoPort	proc	near

		push	ax

	;assign I/O high byte
		mov	cl,60H			;I/O register
	 	call	Get_977
		mov	bh,al			;high byte

	;assign I/O low byte
		mov	cl,61H			;I/O register
	 	call	Get_977
		mov	bl,al			;low byte

		pop	ax
		ret
Get_IoPort	endp

;[]==============================================================[]
;Output	: NC active , CF non Active
;	  CF : 0 Enable
;	  CF : 1 Disable
;[]==============================================================[]
Get_Dev_Active	proc	near

		mov	cl, 30H
	 	call	Get_977
		test	al, 1
		jnz	short @F
		stc
	@@:
		ret
Get_Dev_Active	endp

;[]==============================================================[]
;Input	: CL - logic device to set
;[]==============================================================[]
		public	Set_Logic_Device
Set_Logic_Device	proc	near
		push	ax
		push	cx
		xchg	al,cl
		mov	cl,07H		;index for logic device register
	 	call	Set_977
		pop	cx
		pop	ax
		ret
Set_Logic_Device	endp

;[]==============================================================[]
;Input	: CL - register index
;Output	: AL - Value read
;[]==============================================================[]
		public	Get_977
		public	Set_977
		public  Unlock_977
		public	Lock_977
Get_977	proc	Near

		mov	al,cl
		mov	dx,W83977TF_PORT
		out	dx,al
		NEWIODELAY
		inc	dx
		in	al,dx
		NEWIODELAY

		ret
Get_977	endp


;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;[]==============================================================[]
Set_977	proc	near

		push	ax
		mov	dx,W83977TF_PORT
		mov	al,cl
		out	dx,al
		NEWIODELAY
		pop	ax
		inc	dx
		out	dx,al
		NEWIODELAY

		ret
Set_977	endp

Unlock_977	proc	Near

		mov	dx,W83977TF_port
		mov	al,087H			;unlock pattern
		out	dx,al			;need 2 continuous write
		out	dx,al
		ret

Unlock_977	endp

Lock_977	proc	near
		mov	dx,W83977TF_port
		mov	al,0AAH			;lock pattern
		out	dx,al
		ret
Lock_977	endp

;[]==============================================================[]
;Input	: CH - which IRQ port to set
;[]==============================================================[]
Set_Irq		proc	near

		pusha
		mov	cl,70H			;IRQ register
		mov	al,ch
	 	call	Set_977
		popa
		ret

Set_Irq		endp
ifndef	NO_USE_KB				
;[]==============================================================[]
;Function : Enable/Disable IRQ 12 for PS2 mouse by run-time
;Input    : AH = 04H - enable IRQ 12
;Output   :    = 00H - disable IRQ 12
;[]==============================================================[]
		public	Irq12_Control
Irq12_Control	proc	near

		pusha

		mov	bh,ah		;save register

		call	Unlock_977

		mov	cl,5		       	;device 5 for KBC mouse
		call	Set_Logic_Device

		xor	al,al			;Set release IRQ
		test	bh,04H			;enable IRQ 12 ?
		jz	short @f		

Set_Irq12:

		mov	al, 12			;Set IRQ 12
@@:
		mov	cl,072h			;Set to 072h for PS2 mouse IRQ
		call	Set_977			;Set Irq

		call	Lock_977

		popa

		ret
Irq12_Control	endp
endif;	NO_USE_KB				

ifdef	APC_POWER_SWITCH_SUPPORT
		public	APC_POWER_OFF
APC_POWER_OFF	proc	near

ifdef	POFIRQ_USE				
		jmp	short Set_CMOS_Bank0	
else;	POFIRQ_USE				
		pusha
		call	Unlock_977

		mov	cl,4		       	;device 4 for RTC
		call	Set_Logic_Device

		mov	cl,0F0h			;Set to 0F0h for select blank
		call	Get_977
		and	al, 00111111b
		or	al, 10000000b
		call	Set_977			;Set blank
endif;	POFIRQ_USE				

		mov	al, 49h
		out	70h, al
		nop
		nop
		in	al, 71h

		or	al, 00100000b		;software power-off command
		push	ax
		mov	al, 49h
		out	70h, al
		nop
		nop
		pop	ax
		out	71h, al

ifdef	POFIRQ_USE				
		jmp	short Set_CMOS_Bank0	
else;	POFIRQ_USE				

		mov	cl,0F0h			;Set to 0F0h for select blank
		call	Get_977
		and	al, 00111111b
		call	Set_977			;Set blank

		call	Lock_977
		popa

		ret
endif;	POFIRQ_USE				

APC_POWER_OFF	endp

ifdef	POFIRQ_USE
		public	STOP_POST
STOP_POST	proc	near

		call	Set_CMOS_Bank2
		mov	al, 4bh
		out	70h, al
		nop
		nop
		mov	al, 60h
		out	71h, al
		nop
		nop

		mov	al, 4bh
		out	70h, al
		nop
		nop
		in	al, 71h
		nop
		nop

		mov	al, 49h
		out	70h, al
		nop
		nop

		mov	al, 0d9h			;stop panel-switch-off-save time
		out	71h, al
		nop
		nop

		jmp	short Set_CMOS_Bank0
STOP_POST	endp

		public	ENABLE_BUTTON
ENABLE_BUTTON	Proc	Near

		call	Set_CMOS_Bank2
		mov	al, 49h
		out	70h, al
		nop
		nop

		mov	al, 080h			;stop panel-switch-off-save time
		out	71h, al
		jmp	short Set_CMOS_Bank0
ENABLE_BUTTON	endp

Set_CMOS_Bank2:
		call	Unlock_977

		mov	cl,4			;device 4 for RTC
		call	Set_Logic_Device

		mov	cl, 0f0h		;CR f0h
		call	Get_977
		or	al, 80h			;set RTC to bank 2
	 	call	Set_977
		ret

Set_CMOS_Bank0:
		mov	cl, 0f0h
	 	call	Get_977
		and	al, 00111111b		;set RTC to bank 0
		call	Set_977			;Set blank

		call	Lock_977
		ret

endif;	POFIRQ_USE

endif;	APC_POWER_SWITCH_SUPPORT

ifdef	PM_LED_USE_GPIO
		public	SET_PM_LED
SET_PM_LED	proc	near

		pusha
		push	ax
		call	Unlock_977
PM_LED_USE_GPIO_DEVICE	=	PM_LED_USE_GPIO and 008h
if	PM_LED_USE_GPIO_DEVICE
PM_LED_USE_GPIO_DEVICE	=	8
else;	PM_LED_USE_GPIO_DEVICE
PM_LED_USE_GPIO_DEVICE	=	7
endif;	PM_LED_USE_GPIO_DEVICE
		mov	cl, byte ptr PM_LED_USE_GPIO_DEVICE	;device 8 for GPIO
		call	Set_Logic_Device

		mov	cl, byte ptr (PM_LED_USE_GPIO and 0ffh)	;set CREBh
		pop	ax
		call	Set_977			;Set blank
		call	Lock_977
		popa

		ret

SET_PM_LED	endp
endif;	PM_LED_USE_GPIO

ifdef	POWER_LED_USE
		public	SET_POWER_LED
SET_POWER_LED	proc	near

		push	ax
		call	Unlock_977
ifdef	Special_for_SOLTEK
		call	Get_SuperIO_Chip_ID
		and	ax, 0FFF0h
		cmp	ax, W977EF_AW_ID
		jz	short @f
		pop	ax
		jmp	SET_POWER_LED_Exit
@@:
endif	;Special_for_SOLTEK
if	Power_Led_Use EQ 1
		pop	ax
		push	ax

		call	Set_Pin103	;program Pin 103 for GPIO or PLED
endif;	Power_Led_Use
		mov	cl,8			;device 8 for GPIO
		call	Set_Logic_Device

		mov	cl, 0f4h	 	;set WDT DOG Ctrl bit 1
		call	Get_977			;get WDT_CTRL
		and	al, 11111101b
		pop	bx
		or	al, bl
		call	Set_977			;Set WDT_CTRL
SET_POWER_LED_Exit:				
		call	Lock_977
		ret

SET_POWER_LED	endp

if	Power_Led_Use EQ 1
;Function : Program Pin 103 as GPIO or PLED
;Input    : AL = 2 - set pin 103 for PLED
;                other for GPIO
;Output   : none
Set_Pin103	proc	near
		mov	bl, 00000010b	;set power LED and flash
		cmp	al, 02h		;for power LED ?
		je	short Set_Pin103_As_LED
		mov	cl, 02ch
		call	Get_977
		and	al, 11111100b
		or	al, 00000001b
		call	Set_977

		mov	cl, 7
		call	Set_Logic_Device
		mov	cl, 0E4h
ifdef	POWER_LED_LOW_ACTIVE			
		xor	al, al
else	;POWER_LED_LOW_ACTIVE			
		mov	al,2
endif	;POWER_LED_LOW_ACTIVE			
		call	Set_977
		ret

Set_Pin103_As_LED:
		mov	cl, 02ch
		call	Get_977
		and	al, 11111100b
		or	al, bl 	
		call	Set_977
		ret
Set_Pin103	endp
endif;	Power_Led_Use EQ 1

endif;	POWER_LED_USE

ifdef Power_Led_Selection
		extrn	Power_Led_Item:Near
		public	SET_POWER_LED
SET_POWER_LED	proc	near
		or	al,al
		jnz	short Power_Led_Suppend

;Normal State, Set Pin 103 as GP14 and output high
		call	Unlock_977
		mov	cl,2Ch
		mov	al, 1
		call	Set_977
		mov	cl, 7
		call	Set_Logic_Device
		mov	cl, 0E4h
ifdef	POWER_LED_LOW_ACTIVE
		mov	al,2
else	;POWER_LED_LOW_ACTIVE			
		xor	al, al
endif	;POWER_LED_LOW_ACTIVE			
		call	Set_977
		call	Lock_977
		jmp	Power_Led_Done

Power_Led_Suppend:
		mov	al, Power_Led_Cmos
		out	70h, al
		in	al, 71h
		mov	ah, Power_Led_Cmos_Bits
		and	al, ah
		
shift_right:
		shr	ah,1
		jc	short shift_OK
		shr	al,1   
		jmp	shift_right
shift_OK:

		or	al,al
		jz	short Power_Led_Done

		cmp	al, 1
		jne	short Power_Led_Blinking

;Dual color, set P103 as GP14 high
		call	Unlock_977
		mov	cl, 7
		call	Set_Logic_Device
		mov	cl, 0E4h
ifdef	POWER_LED_LOW_ACTIVE
		xor	al, al
else	;POWER_LED_LOW_ACTIVE			
		mov	al,2
endif	;POWER_LED_LOW_ACTIVE			
		call	Set_977
		call	Lock_977
		jmp	Power_Led_Done

;Blinking, set P103 as Power Led
Power_Led_Blinking:
		call	Unlock_977
		mov	cl, 2Ch
		mov	al, 2
		call	Set_977
		mov	cl, 8
		call	Set_Logic_Device
		mov	cl, 0F4h
		mov	al, 2
		call	Set_977
		call	Lock_977

Power_Led_Done:
		ret
SET_POWER_LED	endp
endif ;Power_Led_Selection

ifdef	AGP_Freq_Use_Superio_GPIO
	OUTPUT_FROM_GPIO	EQU	1
endif	;AGP_Freq_Use_Superio_GPIO

ifdef	CPU_FAN_POWER_BY_GPIO
	OUTPUT_FROM_GPIO	EQU	1
endif;	CPU_FAN_POWER_BY_GPIO

ifdef	Flash_W_By_GPIO_Low
	OUTPUT_FROM_GPIO	EQU	1
endif;	Flash_W_By_GPIO_Low

ifdef	OUTPUT_FROM_GPIO
;[]==============================================================[]
;Function : Output GPI/O by run-time
;Input    : AL = 00h - OUTPUT GPI/O LOW
;		 02h - OUTPUT GPI/O HIGH
;	    CH = Logical Device
;	    CL = Index Address
;[]==============================================================[]

		public	GPIO_OUTPUT
GPIO_OUTPUT	proc	near
		push	ax
		push	cx
		call	Unlock_977
		mov	cl,ch			;device GPIO
		call	Set_Logic_Device
		pop	cx
		pop	ax
		call	Set_977			;OUTPUT high/low to GPIO
		call	Lock_977
		ret
GPIO_OUTPUT	endp
endif;	OUTPUT_FROM_GPIO

ifdef	Special_for_SOLTEK
Get_SuperIO_Chip_ID	Proc	Near
		mov	cl, 20h
		call	Get_977
		mov	ah,al
		mov	cl, 21h
		call	Get_977
		ret
Get_SuperIO_Chip_ID	Endp
endif	;Special_for_SOLTEK
ENDIF	;COMPILE_FOR_PNPIO_ASM	EQ	4
endif	;Report_Secondio_Nodes
endif	;COMPILE_FOR_PNPIO_ASM
endif	;W83977TF

