;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R26	02/10/99 GAR	Added LPC47U33X
;R25	02/09/99 GAR	Fix compile bug.
;R24	02/01/99 GAR	Add No_Use_Parallel_Port
;R23	02/01/99 GAR	Add IRQ10, IRQ11 for auto
;R22	11/16/98 GAR	Report Secondary IO nodes
;R08B	09/16/98 GAR	Fix error. When define "Use_16bit_Decode" and
;			"NO_IR_selectable", the option of "Auto" of COM will
;			not release IRQ3 and IRQ4.
;	
;R08A	08/19/97 TNY	Fix coding error.(AUTO COM port is error if "NO_IR_selectable"
;			defined.
;R21	08/18/98 GAR	Add "Lpt_Has_Auto"
;R20B	08/04/98 GAR	Fixed bug. If we don't define NO_USE_COM2
;R20A 	08/03/98 KVN	Fixed coding mistake by R20 that will cause system
;			hang on any where of POST.Because it will destroy BIOS
;			code in Auto_Cfg_SuperIO subroutine.
;R20 	07/31/98 DRS	Fixed compiler bug. If we use SMC37M60X definition
;R19	07/17/98 RCH	Added a switch to support only one COM port
;R18B	07/08/98 LAW	fix auto setting 3e8h error
;R18A	06/22/98 LAW	For product announcement for Change Default Value of
;			IRQ3/4 and auto ALgorithm
;R18	05/26/98 LAW	add "AUTO_CHECK_IRQ3_IRQ4" for when UART1/2 selected
;			AUTO
;R17	12/24/97 LAW	added "Secondary_IO_Use" for Program Secondary IO after
;			check Com port conflict 
;R16	11/26/97 LAW	added ITE8661_WITH_UMC8670 "NO_AUTO_COM_LPT"
;R15	10/13/97 LAW	remove Init_PS2Mouse_Proc to E0post.asm after MS_Install
;R14	09/17/97 PAL	Added SMC37C669_ITE8661 "NO_AUTO_COM_LPT"
;R13	09/15/97 LAW	added PS2Mouse Init for Use Mouse button power on
;R12	09/08/97 LAW	Use MASM6.11 Compiler
;R11	09/04/97 LAW	Added 513x5113 "NO_AUTO_COM_LPT"
;			and added "Set_Not_Available_IRQ_For_4COM_NO_PNP_NODE"
;R10	09/02/97 LAW	fixed serial port auto no set IRQ3 /4 not available
;R09	08/19/97 LAW	added Public E_WRITE_ITEM_VALUE for Winbond 83977TF
;			"Password_ON_NOW_SUPPORT" 
;R08	06/13/97 LAW	modfify code for define "NO_IR_selectable" and "Use_16bit_Decode"
;			COMPILE error
;R07	04/17/97 LAW	Added W9775119 "NO_AUTO_COM_LPT"
;R06	04/17/97 LAW	Added S93x8669 "NO_AUTO_COM_LPT"
;R05	03/12/97 LAW	Added I8680663 "NO_AUTO_COM_LPT"
;R04	12/04/96 LAW	Added some superio.sio no support AUTO_COM_LPT ,so must
;			define "NO_AUTO_COM_LPT"
;R03	12/03/96 RAY	should preserve DS before we call Prg_Super_IO_Chip
;R02	10/04/96 RAY	Clear the "no. of LPT", "no. of COM" & "Game port"
;			flag after auto configuring the onboard COM ports in
;			the 40:0 BIOS area to maintain compatibility.
;			If this is not done, the FINDIRQ.COM utility will
;			show up with COM1 & COM3 using the same IRQ line.
;R01	08/13/96 RAY	Temporarily remove the Lpt port auto-config
;			functionality because it will cause DMA resource
;			conflict when ISA PnP device is plugged & Lpt port
;			is set to ECP mode.
;R00	08/09/96 RAY	Initial Revision

ifdef	MASM611		;R12
.MODEL  SMALL,BASIC	;R12
OPTION	PROC: PRIVATE	;R12
endif	;MASM611	;R12

.386p
		PAGE	56,132
		TITLE	SUPERIO.ASM
.XLIST
		INCLUDE	BIOS.CFG
		include	common.equ
		INCLUDE	COMMON.MAC
		INCLUDE POST.EQU

		include	PnP.equ

		extrn	Out_8042:near
		extrn	Buffer_8042_Full:near
		extrn	F000_call_proc:near
		extrn	F000_GetItem_Value:near
		extrn	F000_Buffer_8042_Full:near
		extrn	F000_Out_8042:near

ifdef	Secondary_IO_Use				;R17
		extrn	Secondary_Prg_Super_IO_Chip:near;R17
endif;	Secondary_IO_Use				;R17

;R26 - start
	ifdef	LPC47U33X
		NO_USE_COM2	=	1
	endif	;LPC47U33X
;R26 - end

	ifdef	W83787F
		Diff_COM1_COM2_CMOS_Value	EQU	1
	endif	;W83787F
	ifdef	SMC37C665
		Diff_COM1_COM2_CMOS_Value	EQU	1
	endif	;SMC37C665
	ifdef	SMC_92X
		Diff_COM1_COM2_CMOS_Value	EQU	1
	endif	;SMC_92X
	ifdef	Protech_special
		NO_AUTO_COM_LPT			EQU	1
	endif	;Protech_special

;R04 - start
	ifdef	HMC83755
		NO_AUTO_COM_LPT			EQU	1
	endif	;HMC83755
	ifdef	SMC665_N_UMC8663
		NO_AUTO_COM_LPT			EQU	1
	endif	;SMC665_N_UMC8663
	ifdef	DUAL_ALi5113
		NO_AUTO_COM_LPT			EQU	1
	endif	;DUAL_ALi5113
;R04 - end
;R05 - start
	ifdef	I8680663
		NO_AUTO_COM_LPT			EQU	1
	endif	;I8680663
;R05 - end

;R06 - start
	ifdef	S93X8669
		NO_AUTO_COM_LPT			EQU	1
	endif	;S93X8669
;R06 - end

;R07 - start
	ifdef	W83977_N_ALi5119
		NO_AUTO_COM_LPT			EQU	1
	endif;	W83977_N_ALi5119
;R07 - end

;R11 - start
	ifdef	ALi513x_5113
		NO_AUTO_COM_LPT			EQU	1
	endif;	ALi513x_5113
;R11 - end

;R14 - start
	ifdef 	SMC37C669_ITE8661
		NO_AUTO_COM_LPT			EQU	1
	endif;	SMC37C669_ITE8661
;R14 - end	
ifdef	ITE8661_WITH_UMC8670					;R16
		NO_AUTO_COM_LPT			EQU	1	;R16
endif;	ITE8661_WITH_UMC8670					;R16

;R20 -start
ifdef	SMC37M60X
SMC37C67X					EQU	1
endif	;SMC37M60X
;R20 -end

;R08 - start
ifdef	SMC37C67X
NO_USE_COM2	=	0
ifdef	Use_16bit_Decode
ifdef	NO_IR_selectable		;R08B
NO_USE_COM2	=	1
endif	;NO_IR_selectable		;R08B
endif;	Use_16bit_Decode
ifdef	NON_SERIRQ_MODE
NO_USE_COM2	=	1
endif;	NON_SERIRQ_MODE

Com2_Item_Enable	= 	1

;R08Aif	NO_USE_COM2
;R08Aifdef	NO_IR_SELECTABLE
;R08A		NO_AUTO_COM_LPT			EQU	1
;R08Aendif;	NO_IR_SELECTABLE
;R08Aendif;	NO_USE_COM2
endif;	SMC37C67X
;R08 - end

ifdef	NO_COM2_SUPPORT				;R20B
NO_USE_COM2	=	1			;R20B
endif	;NO_COM2_SUPPORT			;R20B

ifdef	NEW_SUPERIO_KERNEL
ifndef	NO_AUTO_COM_LPT
		extrn	PRG_SUPER_IO_CHIP:Near
ifndef	No_Use_Parallel_Port		;R24
		extrn	LPT_ITEM:Near
endif	;No_Use_Parallel_Port		;R24
		extrn	COM1_ITEM:Near
;R20 ifndef	NO_COM2_SUPPORT					;R19
ifdef	NO_USE_COM2						;R20
ife	NO_USE_COM2						;R20
		extrn	COM2_ITEM:Near
endif	;NO_USE_COM2						;R20
;R20Bendif	;NO_USE_COM2						;R20
;R20B - start
else	;NO_USE_COM2
		extrn	COM2_ITEM:Near
endif	;NO_USE_COM2
;R20B - end
;R20 endif;	NO_COM2_SUPPORT					;R19
;R25		extrn	WRITE_ITEM_VALUE:Near
		extrn	F000_Shadow_W:Near
		extrn	F000_Shadow_R:Near
;R21 - start
ifdef	Lpt_Has_Auto
		extrn	LPT_NONE_CMOS_VAL:ABS
		extrn	LPT_378_CMOS_VAL:ABS
		extrn	LPT_278_CMOS_VAL:ABS
		extrn	LPT_AUTO_CMOS_VAL:ABS
endif	;Lpt_Has_Auto
;R21 - end
		extrn	COM1_NONE_CMOS_VAL:ABS
		extrn	COM1_3F8_CMOS_VAL:ABS
		extrn	COM1_2F8_CMOS_VAL:ABS
		extrn	COM1_3E8_CMOS_VAL:ABS
		extrn	COM1_2E8_CMOS_VAL:ABS
		extrn	COM1_AUTO_CMOS_VAL:ABS
;R23 - start
ifdef	Special_Auto_For_MSI
		extrn	COM1_3F81_CMOS_VAL:ABS
		extrn	COM1_2F81_CMOS_VAL:ABS
		extrn	COM1_3E81_CMOS_VAL:ABS
		extrn	COM1_2E81_CMOS_VAL:ABS
endif	;Special_Auto_For_MSI
;R23 - end
ifdef	Diff_COM1_COM2_CMOS_Value
		extrn	COM2_NONE_CMOS_VAL:ABS
		extrn	Com2_3F8_Cmos_Val:ABS
		extrn	Com2_2F8_Cmos_Val:ABS
		extrn	Com2_3E8_Cmos_Val:ABS
		extrn	Com2_2E8_Cmos_Val:ABS
		extrn	COM2_AUTO_CMOS_VAL:ABS
endif	;Diff_COM1_COM2_CMOS_Value
;R01 		extrn	LPT_NONE_CMOS_VAL:ABS
;R01 		extrn	LPT_3BC_CMOS_VAL:ABS
;R01 		extrn	LPT_278_CMOS_VAL:ABS
;R01 		extrn	LPT_378_CMOS_VAL:ABS
;R01 		extrn	LPT_AUTO_CMOS_VAL:ABS
		extrn	Cp_Install:near
	ifdef	PNP_BIOS
		extrn	Proc_Post_Node:near
	endif	;PNP_BIOS
endif	;NO_AUTO_COM_LPT
ifdef	Set_Not_Available_IRQ_For_4COM_NO_PNP_NODE	;R11
		extrn	Set_Not_Available_IRQ:near	;R11
endif;	Set_Not_Available_IRQ_For_4COM_NO_PNP_NODE	;R11
;R15ifdef	Password_ON_NOW_SUPPORT				;R13
;R15ifdef	MOUSE_BUTTON_ON_SUPPORT				;R13
;R15		extrn	Init_Ps2Mouse_Proc:near		;R13
;R15endif;	MOUSE_BUTTON_ON_SUPPORT				;R13
;R15endif;	Password_ON_NOW_SUPPORT				;R13
		extrn	WRITE_ITEM_VALUE:Near		;R25
endif	;NEW_SUPERIO_KERNEL

G_RAM		SEGMENT	USE16 AT 0

		ORG	04H*4
		INCLUDE	SEG_0.INC

		ORG	400H
		INCLUDE	G_RAM.INC

		ORG	2000h
		INCLUDE PNPDATA.INC

G_RAM		ENDS

.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

;[]===========================================================[]
;Name	:	Auto_Cfg_SuperIO
;
;Procedure :	To Auto-Cfg the COM/LPT/FDD ports if they are
;		set to 'Auto' in the CMOS setup utility.
;
;Input	:	None
;
;Output	:	None
;
;Note	:	This routine is called after PNP devices are
;		configured & before CP_Instal is invoked.
;
;[]===========================================================[]
		Public	Auto_Cfg_SuperIO
Auto_Cfg_SuperIO	Proc	Near

ifdef	NEW_SUPERIO_KERNEL
ifndef	NO_AUTO_COM_LPT

		pushad
		push	ds
		push	es
		pushf
		cli

		call	Clear_G_RAM_Port_Area

;----------------------------------------------------------------
;Save all the settings of menuitems which may have a chance
;to be set to 'Auto' by the user
;----------------------------------------------------------------

		push	0F000h
		pop	ds
		mov	di, offset PortItems
		mov	cx, TOTAL_AUTO_ITEMS
	@@:
		mov	si, cs:[di]
		call	E_GetItem_Value
		push	ax
		push	word ptr ds:[si].ITEMSTAT
		add	di, AUTO_ITEM_DATA_COUNT
		loop	@B

;====================================================================
;Auto-Cfg individual IO ports only if they are set to 'Auto' in setup
;====================================================================

		mov	di, offset PortItems
		mov	cx, TOTAL_AUTO_ITEMS

	Next_Auto_Port:

		pusha

		mov	si, cs:[di]			;auto item offset
		call	E_GetItem_Value
		cmp	ax, cs:[di+2]			;set to 'auto' ?
		jne	short This_Port_Not_Auto	;no !

		call	cs:[di+4]			;get available port
							; in AX
		jc	short No_Port_Available		;no port availabe !

	;----- Search for proper CMOS value -----

		mov	si, cs:[di+6]			;Cmos value list

	Find_Next_Available:

		mov	cx, cs:[si]			;port addr. to cmp
		cmp	cl, -1				;end of list ?
		je	short No_Port_Available		;yes !

		xor	dh, dh				;Clear DH
		mov	dl, cs:[si+2]			;CMOS value in DL
		cmp	ax, cx				;found CMOS value ?
		je	short Port_Found		;yes !
		add	si, 3				;point to next value
		jmp	short Find_Next_Available	;no, continue

	Port_Found:

	;------------------------------------------------
	; 1. unmask the ITEMDISABLE flag in case the item
	;    is hiddened and thus cause GetItem_Value to
	;    retrieve BIOS default
	; 2. Write this value into CMOS Stack
	; 3. call routine to program Super IO chip
	;------------------------------------------------

		push	ds			;save DS	;R03
		pusha
		call	E_F000_Shadow_W
		mov	si, cs:[di]
		and	word ptr ds:[si].ITEMSTAT, not ITEMDISABLE
		call	E_F000_Shadow_R
		popa

		mov	bx, cs:[di]
		call	E_Write_Item_Value

		call	Prg_Super_IO_Chip
		pop	ds			;restore DS	;R03

	No_Port_Available:
	This_Port_Not_Auto:

		popa
		add	di, AUTO_ITEM_DATA_COUNT
		loop	Next_Auto_Port

;====================================================================

;----------------------------------------------------------------
;Restore all the CMOS settings of menuitems which may have a chance
;to be set to 'Auto' by the user
;----------------------------------------------------------------

		call	E_F000_Shadow_W
;R01		mov	di, (offset PortItems)+2*(AUTO_ITEM_DATA_COUNT)
		mov	di, (offset End_PortItems)-(AUTO_ITEM_DATA_COUNT);R01
		mov	cx, TOTAL_AUTO_ITEMS
	@@:
		mov	bx, cs:[di]
		pop	ax
		mov	ds:[bx].ITEMSTAT, ax
		pop	dx
		call	E_Write_Item_Value
		sub	di, AUTO_ITEM_DATA_COUNT
		loop	@B
		call	E_F000_Shadow_R

		call	Clear_G_RAM_Port_Area

;--------------------------------------
;rebuild the devnodes
;--------------------------------------

	ifdef	PNP_BIOS
		call	Proc_Post_Node
	endif	;PNP_BIOS

		popf
		pop	es
		pop	ds
		popad

endif	;NO_AUTO_COM_LPT

ifdef	Secondary_IO_Use				;R17
		pushf					;R17
		pushad					;R17
		call	Secondary_Prg_Super_IO_Chip	;R17
;R22 - start
ifdef	Report_Secondio_Nodes
	ifdef	PNP_BIOS
		call	Proc_Post_Node
	endif	;PNP_BIOS
endif	;Report_Secondio_Nodes
;R22 - end
		popad					;R17
		popf					;R17
endif;	Secondary_IO_Use				;R17
ifdef	Set_Not_Available_IRQ_For_4COM_NO_PNP_NODE	;R11
		call	Set_Not_Available_IRQ		;R11
endif;	Set_Not_Available_IRQ_For_4COM_NO_PNP_NODE	;R11

endif	;NEW_SUPERIO_KERNEL
;R15ifdef	Password_ON_NOW_SUPPORT				;R13
;R15ifdef	MOUSE_BUTTON_ON_SUPPORT				;R13
;R15		call	Init_Ps2Mouse_Proc		;R13
;R15endif;	MOUSE_BUTTON_ON_SUPPORT				;R13
;R15endif;	Password_ON_NOW_SUPPORT				;R13

		ret

Auto_Cfg_SuperIO	Endp

ifdef	NEW_SUPERIO_KERNEL
ifndef	NO_AUTO_COM_LPT
PortItems:

	dw	offset Com1_Item
	dw	COM1_AUTO_CMOS_VAL
	dw	offset Available_COM_Addr
	dw	offset Com1_Cmos_Value_List

AUTO_ITEM_DATA_COUNT	EQU	($-(offset PortItems))

;R20 ifndef	NO_COM2_SUPPORT					;R19
ifdef	NO_USE_COM2						;R20
ife	NO_USE_COM2						;R20
	dw	offset Com2_Item
;R20Aendif	;NO_USE_COM2						;R20
;R20Aendif	;NO_USE_COM2						;R20
;R20 endif;	NO_COM2_SUPPORT					;R19
ifdef	Diff_COM1_COM2_CMOS_Value
	dw	COM2_AUTO_CMOS_VAL
else	;Diff_COM1_COM2_CMOS_Value
	dw	COM1_AUTO_CMOS_VAL
endif	;Diff_COM1_COM2_CMOS_Value
	dw	offset Available_COM_Addr
	dw	offset Com2_Cmos_Value_List
endif	;NO_USE_COM2						;R20A
;R20Bendif	;NO_USE_COM2						;R20A
;R20B - start
else	;NO_USE_COM2
	dw	offset Com2_Item
ifdef	Diff_COM1_COM2_CMOS_Value
	dw	COM2_AUTO_CMOS_VAL
else	;Diff_COM1_COM2_CMOS_Value
	dw	COM1_AUTO_CMOS_VAL
endif	;Diff_COM1_COM2_CMOS_Value
	dw	offset Available_COM_Addr
	dw	offset Com2_Cmos_Value_List
endif	;NO_USE_COM2
;R20B - end

;R01 	dw	offset Lpt_Item
;R01 	dw	LPT_AUTO_CMOS_VAL
;R01 	dw	offset Available_Lpt_Addr
;R01 	dw	offset Lpt_Cmos_Value_List

;R21 - start
ifdef	LPT_Has_Auto
	dw	offset Lpt_Item
	dw	LPT_AUTO_CMOS_VAL
	dw	offset Available_LPT_Addr
	dw	offset LPT_Cmos_Value_List
endif	;LPT_Has_Auto
;R21 - end
End_PortItems:					;R01

TOTAL_AUTO_ITEMS	EQU	($-(offset PortItems))/AUTO_ITEM_DATA_COUNT

Com2_Cmos_Value_List:

ifdef	Diff_COM1_COM2_CMOS_Value
	dw	3F8h
	db	Com2_3F8_Cmos_Val
	dw	2F8h
	db	Com2_2F8_Cmos_Val
	dw	3E8h
	db	Com2_3E8_Cmos_Val
	dw	2E8h
	db	Com2_2E8_Cmos_Val
	db	-1
endif	;Diff_COM1_COM2_CMOS_Value

Com1_Cmos_Value_List:

	dw	3F8h
	db	Com1_3F8_Cmos_Val
	dw	2F8h
	db	Com1_2F8_Cmos_Val
	dw	3E8h
	db	Com1_3E8_Cmos_Val
	dw	2E8h
	db	Com1_2E8_Cmos_Val
;R23 - start
ifdef	Special_Auto_For_MSI
	dw	83F8h
	db	Com1_3F81_Cmos_Val
	dw	82F8h
	db	Com1_2F81_Cmos_Val
	dw	83E8h
	db	Com1_3E81_Cmos_Val
	dw	82E8h
	db	Com1_2E81_Cmos_Val
endif	;Special_Auto_For_MSI
;R23 - end
	db	-1

;R21 - start
ifdef	Lpt_Has_Auto
Lpt_Cmos_Value_List:

	dw	378h
	db	Lpt_378_Cmos_Val
	dw	278h
	db	Lpt_278_Cmos_Val
	db	-1
endif	;Lpt_Has_Auto
;R21 - end

;R01 Lpt_Cmos_Value_List:
;R01 
;R01 	dw	3BCh
;R01 	db	Lpt_3BC_Cmos_Val
;R01 	dw	278h
;R01 	db	Lpt_278_Cmos_Val
;R01 	dw	378h
;R01 	db	Lpt_378_Cmos_Val
;R01 	db	-1

;[]=============================================================[]
;[]=============================================================[]
Clear_G_RAM_Port_Area	Proc	Near

		mov	ax, G_RAM
		mov	es, ax
		assume	ES:G_RAM

		mov	di, offset COMM_PORT_ADDRS
		mov	cx, 7
		xor	ax, ax
		cld
		rep	stosw			;clear port address

;R02 - starts
	;Clear the "no. of LPT", "no. of COM" & "Game port installed"
	;flag in the 40:0 BIOS area

		and	word ptr es:[HARDWARE], 21FFh
;R02 - ends

		ret

Clear_G_RAM_Port_Area	Endp

;[]=============================================================[]
;[]=============================================================[]
Available_Com_Addr	Proc	Near

		push	di

		call	Clear_G_RAM_Port_Area
		call	Cp_Install

	;check if 3F8h/3E8h available

;R18Aifdef	AUTO_CHECK_IRQ3_IRQ4				;R18
	ifdef	PNP_BIOS					;R18
		test	byte ptr ES:[IRQ_MAP], 00010000b	;R18;IRQ 4 avail?
		jz	short @F				;R18
	endif	;PNP_BIOS					;R18
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18

		mov	ax, 3F8h
		call	Scan_Port
;R18Aifdef	AUTO_CHECK_IRQ3_IRQ4				;R18
		mov	ax, 3F8h				;R18
		jnc	short USE_3f8	;CF = 3F8 not available	;R18
;R18Aelse;	AUTO_CHECK_IRQ3_IRQ4				;R18
;R18A		jc	short @F	;CF = 3F8 not available
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18
		mov	ax, 3E8h
		call	Scan_Port
		jc	short @F	;CF = 3E8 not available
;R18Aifdef	AUTO_CHECK_IRQ3_IRQ4				;R18
		mov	ax, 3E8h				;R23
;R23		mov	ax, 3F8h				;R18B
;R18B		mov	ax, 3F8h				;R18
	USE_3f8:						;R18
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18
	ifdef	PNP_BIOS					;R10
		and	word ptr es:IRQ_MAP, not 00010000b	;R10
	endif;	PNP_BIOS					;R10
;R18Aifndef	AUTO_CHECK_IRQ3_IRQ4				;R18
;R18A		mov	ax, 3F8h
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18
		pop	di			
		ret
	@@:

;R18Aifndef	AUTO_CHECK_IRQ3_IRQ4				;R18
;R18A		stc
;R18Aelse;	AUTO_CHECK_IRQ3_IRQ4				;R18
	ifdef	PNP_BIOS					;R18
		test	byte ptr ES:[IRQ_MAP], 00001000b	;R18;IRQ 3 avail?
		jz	short @F				;R18
	endif	;PNP_BIOS					;R18
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18

		mov	ax, 2F8h
		call	Scan_Port
;R18Aifdef	AUTO_CHECK_IRQ3_IRQ4				;R18
		mov	ax, 2F8h				;R18
		jnc	short USE_2f8	;CF = 2F8 not available	;R18
;R18Aelse;	AUTO_CHECK_IRQ3_IRQ4				;R18
;R18A		jc	short @F	;CF = 2F8 not available
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18

		mov	ax, 2E8h
		call	Scan_Port
		jc	short @F	;CF = 2E8 not available
;R18Aifdef	AUTO_CHECK_IRQ3_IRQ4				;R18
		mov	ax, 2E8h				;R18
	USE_2f8:						;R18
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18
	ifdef	PNP_BIOS					;R10
		and	word ptr es:IRQ_MAP, not 00001000b	;R10
	endif;	PNP_BIOS					;R10
;R18Aifndef	AUTO_CHECK_IRQ3_IRQ4				;R18
;R18A		mov	ax, 2F8h
;R18Aelse;	AUTO_CHECK_IRQ3_IRQ4				;R18
		pop	di					;R18
		ret						;R18
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18
;R23 - start
ifdef	Special_Auto_For_MSI
	@@:
	ifdef	PNP_BIOS
		test	word ptr ES:[IRQ_MAP], 0000010000000000b;IRQ 10 avail?
		jz	short @F				
	endif	;PNP_BIOS					

		mov	ax, 3F8h
		call	Scan_Port
		mov	ax, 83F8h				
		jnc	short USE_3f81	;CF = 3F8 not available	
		mov	ax, 3E8h
		call	Scan_Port
		jc	short @F	;CF = 3E8 not available
		mov	ax, 83E8h
	USE_3f81:
	ifdef	PNP_BIOS					
		and	word ptr es:IRQ_MAP, not 0000010000000000b
	endif;	PNP_BIOS					
		pop	di			
		ret
	@@:

	ifdef	PNP_BIOS					
		test	word ptr ES:[IRQ_MAP], 0000100000000000b;IRQ 3 avail?
		jz	short @F				
	endif	;PNP_BIOS					

		mov	ax, 2F8h
		call	Scan_Port
		mov	ax, 82F8h
		jnc	short USE_2f81	;CF = 2F8 not available	

		mov	ax, 2E8h
		call	Scan_Port
		jc	short @F	;CF = 2E8 not available
		mov	ax, 82E8h				
	USE_2f81:						
	ifdef	PNP_BIOS					
		and	word ptr es:IRQ_MAP, not 0000100000000000b
	endif;	PNP_BIOS					
		pop	di			
		ret
endif	;Special_Auto_For_MSI
;R23 - end
	@@:
;R18Aifdef	AUTO_CHECK_IRQ3_IRQ4				;R18
		stc						;R18
;R18Aendif;	AUTO_CHECK_IRQ3_IRQ4				;R18
		pop	di
		ret

Available_Com_Addr	Endp

;R21 - start
ifdef	Lpt_Has_Auto
Available_Lpt_Addr	Proc	Near
	push	di
	call	Clear_G_RAM_Port_Area
	call	Cp_Install

;check for 378/IRQ7
ifdef	PNP_BIOS				
	test	byte ptr ES:[IRQ_MAP], 10000000b
	jz	short @F			
endif	;PNP_BIOS				
	mov	ax, 378h
	call	Scan_Port
	jc	short @F

ifdef	PNP_BIOS			     
	and	word ptr es:IRQ_MAP, not 10000000b	
endif;	PNP_BIOS					
	pop	di			
	ret

@@:
;check for 278/IRQ5
ifdef	PNP_BIOS				 
	test	byte ptr ES:[IRQ_MAP], 00100000b 
	jz	short @F			 
endif	;PNP_BIOS				 

	mov	ax, 278h
	call	Scan_Port
	jc	short @F 

ifdef	PNP_BIOS					
	and	word ptr es:IRQ_MAP, not 00100000b	
endif;	PNP_BIOS					
	pop	di					;R18
	ret						;R18

;Not Available Port
@@:
	stc						;R18
	pop	di
	ret

Available_Lpt_Addr	Endp
endif	;Lpt_Has_Auto
;R21 - end

;R01 ;[]=============================================================[]
;R01 ;[]=============================================================[]
;R01 Available_Lpt_Addr	Proc	Near
;R01 
;R01 		push	di
;R01 
;R01 		call	Clear_G_RAM_Port_Area
;R01 		call	Cp_Install
;R01 
;R01 		mov	ax, 378h
;R01 		call	Scan_Port
;R01 		jnc	short @F
;R01 
;R01 		mov	ax, 278h
;R01 		call	Scan_Port
;R01 		jnc	short @F
;R01 
;R01 		mov	ax, 3BCh
;R01 		call	Scan_Port
;R01 	@@:
;R01 		pop	di
;R01 		ret
;R01 
;R01 Available_Lpt_Addr	Endp

;------------------------
;Input	:	ES = 40h
;------------------------
Scan_Port	Proc	Near

		mov	di, G_RAM
		mov	es, di
		assume	ES:G_RAM
		mov	di, offset COMM_PORT_ADDRS

		mov	cx, 7
	@@:
		cmp	es:[di], ax
		je	short @F
		inc	di
		inc	di
		loop	short @B
		clc
		ret
	@@:
		stc
		ret

Scan_Port	Endp

;[]----------------------------------------------------------------[]
;[]----------------------------------------------------------------[]
E_GetItem_Value	Proc	Near

		jmp	F000_GetItem_Value
		ret
E_GetItem_Value	Endp

E_F000_SHADOW_W	Proc	Near
		F000_Call F000_SHADOW_W
		ret
E_F000_SHADOW_W	Endp

E_F000_SHADOW_R	Proc	Near
		F000_Call F000_SHADOW_R
		ret
E_F000_SHADOW_R	Endp

		Public	E_WRITE_ITEM_VALUE	;R09
E_WRITE_ITEM_VALUE	Proc	Near
		F000_Call WRITE_ITEM_VALUE
		ret
E_WRITE_ITEM_VALUE	Endp

endif	;NO_AUTO_COM_LPT
endif	;NEW_SUPERIO_KERNEL

ECODE		ENDS
		END
