;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R17	04/29/99 BAR	Add READCOM.INC in XGROUP.
;			For post run AutoLoad awdflash.exe used.
;R16	03/26/99 RAY	Add ADCM_SUPPORT
;R15	12/11/98 KEN	For USB_MOUSE_SUPPORT.
;			Fixed bug that if pressing DEL key frequently and
;			successively to enter SETUP, the PS/2 keyboard
;			occasionally can't work after entering SETUP unless
;			re-plugging it.
;R14	08/31/98 RCH	Added specific POST message customerization
;R13	07/14/98 PAL	Add Support_1_FDD definition to reduce code space
;R12	06/26/98 DRS	Add No_Automatic_Load_Awdflash_InPOST definition
;			Some customers want to use automatic load awdflash.exe,
;			but they don't want this function during POST
;R11	06/17/98 RAY	Support device power management for Function 0Dh & 0Fh
;
;			1. Invalidate variable OPTION_ROM_ID in PM_RAM.INC
;			2. Define DEVICE_PM_STATUS in the same location to
;			   store the device PM status
;
;R10	05/12/98 RAX	Add code for Cyrix VSA save to disk support.
;R09	04/22/98 KGN	Add code For HPM resume from disk post information
;R08	04/01/98 RCH	Fixed compliation error
;R07	03/10/98 DNL	Reduce ACPI S4/BIOS code size to save more space
;R06B	02/06/98 DRS	Fixed bug
;R06A	01/21/98 DRS	Fixed difficult size of awdflash.exe header
;R06	01/19/98 DRS	Support run awdflash.exe during POST 
;R05	12/19/97 RAX	Add define for move APM code to SMBASE.
;R04	12/18/97 LAW	change "EPA_LOGO_Use_Graphics" with "FULL_SCREEN_LOGO"
;			switch to "Graphics_post"
;R03	05/15/97 RAX	Add hook "SMBHOST_INIT" for more SMBus host support
;R02	10/11/96 RAX	Add Notebook Smart Battery support
;R01	05/28/96 RCH	Move in "APM_INIT" from APM.ASM
;Note : This file is used to contain codes that should be in F-segment but
;	is not run-time codes.

		PAGE	63,132
		TITLE	MISC  -- Miscellous Code
.386P
ENABLE_288_SUPPORT	EQU	1
ENABLE_FDC_FIFO		EQU	1	; (2.88 needs FIFO to avoid slow DMA errors)
FDC_FIFO_THRES		EQU	0dh	; (FIFO threshold set to mid value)

CMOS_FD_288		EQU	5	; (CMOS value for 2.88, can be changed)


;R08SEG_0		SEGMENT	USE16 AT 1
;R08		INCLUDE	SEG_0.INC
;R08SEG_0		ENDS

G_RAM		SEGMENT	USE16 AT 40H
		INCLUDE	G_RAM.INC
G_RAM		ENDS

;R07 ;R01 - start
;R07 PM_RAM		SEGMENT	USE16 AT 0 	; define PM RAM segment
;R07 
;R07 		ORG	0
;R07 		INCLUDE	PM_RAM.INC
;R07 
;R07 PM_RAM		ENDS
;R07 ;R01 - end

.XLIST
		INCLUDE BIOS.CFG

		INCLUDE CMOS.EQU
;R08		INCLUDE 82077.EQU
;R08		INCLUDE	ADISK.EQU
;R08		INCLUDE COMMON.EQU				
		INCLUDE COMMON.MAC

		INCLUDE	BTROMSEG.EQU			;R06
		INCLUDE	BSETUP.INC			;R06

		extrn	Buffer_8042_Full:near		;R15;akbrd.asm
	;R06 -start
	ifdef	Bootblock_16K_Support			
	ifdef	Automatic_Load_Awdflash				
	ifNdef	No_Automatic_Load_Awdflash_InPOST     	;R12
		extrn	DRIVE_A_ITEM:near   		
ifndef	Support_1_Fdd					;R13
		extrn	DRIVE_B_ITEM:near   		
endif;	Support_1_Fdd					;R13
		extrn	X_GetItem_Value:near		
		extrn	Disp_Str_In_BIOS1:near		
		extrn	F000_Call_Proc:near		

		extrn 	TO_ENTER_Awdflash:near
		extrn	Load_Awdflash_FromAB:near
		extrn	TO_ENTER_Awdflash_Empty:near
		extrn	Error_Mess1A:near
	        extrn	Error_Mess2A:near
	        extrn	Error_Mess3A:near

		extrn	Ct_Special_REG_Save:near	;R06B

	ifdef	Graphics_Post
		extrn 	TO_ENTER_Awdflash1:near
		extrn	Load_Awdflash_FromAB1:near
		extrn	TO_ENTER_Awdflash_Empty1:near
		extrn	Error_Mess1B:near
	        extrn	Error_Mess2B:near
	        extrn	Error_Mess3B:near
	endif	;Graphics_Post
	endif	;No_Automatic_Load_Awdflash_InPOST     	;R12
	endif	;Automatic_Load_Awdflash				
	endif	;Bootblock_16K_Support			
	;R06 -end

		extrn	GET_CMOS_VALUE:near
		extrn	SEND_COMMAND:near
		extrn	RESULTS:near

		extrn	Ct_Before_Setup:near
		extrn	Int_Kb_Enable:near
		extrn	Cp_Install:near
		extrn	UPDATE_LED:near
		extrn	SETUP:near
		extrn	REDO:near
		extrn	Post_call_proc:near

		extrn	Get_Cmos:near
		extrn	A20_Off:near
		extrn	REAL_IDT_LOC:near

ifdef	SMBIOS_INTERFACE				;R03
		extrn	SMBHOST_INIT:near		;R03
endif	;SMBIOS_INTERFACE				;R03

ifdef	HPM_Support				;R09
		extrn	Check_HPM_Resume:Near	;R09
endif	;HPM_Support				;R09

.LIST

;R07 - start
PM_RAM		SEGMENT	USE16 AT 0 	; define PM RAM segment

		ORG	0
		INCLUDE	PM_RAM.INC

PM_RAM		ENDS
;R07 - end

;R06 -start
EGROUP		GROUP	ECODE
ECODE		SEGMENT PARA PUBLIC 'ECODE'
		ASSUME	CS:EGROUP,DS:EGROUP

ECODE		ENDS
;R06 -end

DGROUP		GROUP	FCODE
FCODE		SEGMENT	USE16 PARA PUBLIC 'CODE'      
		ASSUME	CS:DGROUP

;Codes from ADISK.ASM
;;-----------------------------------------------------------------------
IFDEF	ENABLE_288_SUPPORT

		PUBLIC	FD_PERP_MODE
		align	4			
FD_PERP_MODE	PROC	NEAR

		PUSHA				; save regs
		PUSH	DS
		PUSH	ES

		PUSH	CS			; set addressibility
		POP	DS
		ASSUME	DS:DGROUP
		MOV	AX,G_RAM
		MOV	ES,AX
		ASSUME	ES:G_RAM


IFDEF	FORCE_PERP_MODE
		MOV	AL,10000100B		; set perp mode for first drive
		JMP	SHORT FPM_FINISH	; get to common finish mode

ELSE	;not FORCE_PERP_MODE
		MOV	BL,080H			; set for all drives non perp mode

		xor	al,al			; check drive zero for 2.88
		CALL	GET_CMOS_VALUE		; get CMOS drive type
		CMP	AH,CMOS_FD_288		; check 2.88 drive
		JNE	short PERP_1		; skip if NOT 2.88 (or bad cmos)
		OR	BL,004H			; else drive 0 is setup as perp

PERP_1:
		MOV	AL,1			; check drive one for 2.88
		CALL	GET_CMOS_VALUE		; get CMOS drive type
		CMP	AH,CMOS_FD_288		; check 2.88 drive
		JNE	short PERP_2	 	; skip if NOT 2.88 (or bad cmos)
		OR	BL,008H			; else drive 1 is setup as perp

PERP_2:
		XCHG	AX,BX			; parm into al
ENDIF	;FORCE_PERP_MODE

FPM_FINISH:
		PUSH	AX			; parameters on stack
		MOV	SI,SP			; pointer to parameters
		MOV	AH,012H			; perpendicular command
		MOV	BL,2			; 2 bytes in perp command
		CALL	SEND_COMMAND		; output perp command
		ADD	SP,2			; clear parameters off stack.
		OR	AH,AH			; error?
		JNZ	SHORT FPM_BAD		; skip if error

		CLC				; signal no error
		JMP	SHORT FPM_RET		; get to common return

FPM_BAD:
		STC				; signal error

FPM_RET:
		POP	ES
		POP	DS
		POPA
		RET

FD_PERP_MODE	ENDP

ENDIF	;ENABLE_288_SUPPORT



IFDEF	ENABLE_FDC_FIFO

		PUBLIC	FD_FIFO_MODE
		align	4			
FD_FIFO_MODE	PROC	NEAR

		PUSHA				; save regs
		PUSH	DS
		PUSH	ES

		PUSH	CS			; set addressibility
		POP	DS
		ASSUME	DS:DGROUP
		MOV	AX,G_RAM
		MOV	ES,AX
		ASSUME	ES:G_RAM

		MOV	AL,00h			; set PRETRK for configure command
		PUSH	AX			; parameters on stack
		MOV	AL,00h			; set first parm byte for configure command
		MOV	AH,00h+FDC_FIFO_THRES	; set FIFO on and set threshold
		PUSH	AX			; parameters on stack
		MOV	SI,SP			; pointer to parameters
		MOV	AH,013H			; configure command
		MOV	BL,4			; 4 bytes in configure command
		CALL	SEND_COMMAND		; output configure command
		ADD	SP,4			; clear parameters off stack.
		OR	AH,AH			; error?
		JNZ	SHORT FFM_BAD		; skip if error to quit

		MOV	AH,094H			;;;XXXX lock command
		MOV	BL,1			; 1 byte in lock command
		CALL	SEND_COMMAND		; output lock command
		OR	AH,AH			; error?
		JNZ	SHORT FFM_BAD		; skip if error to quit
		CALL	RESULTS			; read results
		OR	AH,AH			; see if error
		JNZ	SHORT FFM_BAD		; skip if error to quit

		CLC				; signal no error
		JMP	SHORT FFM_RET		; get to common return

FFM_BAD:
		STC				; signal error

FFM_RET:
		POP	ES
		POP	DS
		POPA
		RET

FD_FIFO_MODE	ENDP

ENDIF	;ENABLE_FDC_FIFO
;;-----------------------------------------------------------------------

;Codes from AKBRD.ASM
;R04ifndef FULL_SCREEN_LOGO					
ifndef	Graphics_Post					;R04
;;-----------------------------------------------------------------------
;
;	Here we allow the user to enter SETUP while in POST. We must
;	allow keyboard interrupts again, restore BP (which the POST
;	user interface routines and Setup use), call Setup then
;	reboot.
;
		assume	ds:G_RAM
		public	Go_Cmos_Setup
Go_Cmos_Setup:

		call	Int_Kb_Enable

		mov	sp,bp				; restore stack
		popa					; restore all registers
		mov	bp,ds:[Temp_BP]			; get POST BP		
		pop	ds				; restore DS

		jmp	Enter_Setup
;;-----------------------------------------------------------------------

		public	Enter_Setup_Check
Enter_Setup_Check	proc	near
		push	ds
		mov	ax,G_RAM
		mov	ds,ax
		ASSUME	DS:G_RAM
		test	byte ptr POST_FLAG,SETUP_ON
		pop	ds
		jz	short Not_To_Setup

;R12 - Begin
IFDEF	NoteBook_Power_Management
		extrn	Check_0V_Resume:near
		call	Check_0V_Resume
		jnz	short Not_To_Setup
ENDIF	;NoteBook_Power_Management
;R12 - End

;R10 start
ifdef	VSA_VGA
ifdef	S2D_SUPPORT
		extrn	Check_VSA_resume:near
		call	Check_VSA_resume
		jnz	short Not_To_Setup
endif	;S2D_SUPPORT
endif	;VSA_VGA
;R10 end

ifdef	HPM_Support					;R09
		Post_Func_Call	Check_HPM_Resume	;R09
		jnz	short Not_To_Setup		;R09
endif	;HPM_Support					;R09

Enter_Setup:
		push	ds
		mov	ax,G_RAM
		mov	ds,ax
		ASSUME	DS:G_RAM
		mov	word ptr ds:USER_REBOOT, 0	;reset warm boot flag
		and	INIT_ERR_FLG,NOT IEF_SETUP_OK	; prevent further

;R14 - start
 ifdef	CUSTOM_POST_MSG_SUPPORT
	;restore INT 10H for clearing screen to boot
		mov	esi,dword ptr ds:[TEMP_BP+2]	;get original vector
		xor	ax, ax
		mov	es,ax
		mov	es:[10H*4],esi			;restore INT 10H
 endif;	CUSTOM_POST_MSG_SUPPORT
;R14 - end

		call	Ct_Before_Setup

		pop	ds

PRINTER_0_INIT	EQU	15H
PRN_S_AF_IP_SI	EQU	37AH			;port to talk to strobe,
						; auto feed, initialize
						; printer, and select input
						; pins of parrallel adapter
INITIALIZE_PORT EQU	0100H
		POST_func_call	Cp_Install
		push	ax
		push	dx
		mov	al, PRINTER_0_INIT
		mov	dx, PRN_S_AF_IP_SI
		out	dx, al
		mov	ax, INITIALIZE_PORT
		xor	dx, dx
		int	17H			;init printer port #0
		pop	dx
		pop	ax

;R15 - start
ifdef	USB_SUPPORT
		call	Buffer_8042_Full	;wait IBF cleared
		mov	al, 0FFh		;reset keyboard
		out	60h, al
else	;USB_SUPPORT
;R15 - end
		mov	ax,g_ram			;R11
		mov	ds,ax				;R11
		assume	ds:g_ram			;R11
		or	byte ptr KB_FLAG_2,7		;R11
		call	UPDATE_LED			;R11
endif	;USB_SUPPORT				;R15

		mov	al,0AAh
		CALL	SETUP

		JMP	REDO
Not_To_Setup:
		ret
Enter_Setup_Check	endp
endif;	Graphics_Post					;R04
;R04endif ;FULL_SCREEN_LOGO					;R14

;Codes from MULTISER.ASM
;;-----------------------------------------------------------------------
;[]==================================================================[]
;
; EXC9HDLR:
;
;	Come here on type 9 shutdown. This was used when
;	resetting the system on a 286. Applications also use
;	this to come out of protected mode.
;
;ENTRY:	NONE
; EXIT: NONE
;
;Author: Award
;  Date: 11/27/90
;
;[]==================================================================[]

		ALIGN	4
		PUBLIC	EXC9HDLR			; *
EXC9HDLR:
		cli
		lidt	fword ptr cs:[REAL_IDT_LOC]	; dummy load to clear

		mov	ax,G_RAM
		mov	ds,ax
		assume	ds:G_RAM
		mov	ss,ds:[ROM_MODULE_SEG]
		mov	sp,ds:[ROM_MODULE_OFFSET]

		call	A20_Off

		mov	al,0fh NMI_ON		; enable NMI, as shut down
		call	Get_CMOS

		pop	ds			; recover regs
		pop	es
		popa

		mov	ah,al			; save al
		in	al,80h

		or	al,al			; set zero flag
		je	short exc_9

		stc

exc_9:		
		xchg	ah,al			; swap regs and exit
		sti
		retf	2


;;-----------------------------------------------------------------------


;Codes from PCI1A.ASM
;;-----------------------------------------------------------------------
ifdef	PCI_BUS
		extrn	AGet_CfgSpace_Byte:near
		extrn	AGet_CfgSpace_word:near
		extrn	AGet_CfgSpace_Dword:near
		extrn	Aset_CfgSpace_Byte:near
		extrn	Aset_CfgSpace_word:near
		extrn	Aset_CfgSpace_Dword:near

		public	Get_CfgSpace_Byte
		public	Get_CfgSpace_word
		public	Get_CfgSpace_Dword
		public	set_CfgSpace_Byte
		public	set_CfgSpace_word
		public	set_CfgSpace_Dword
Get_CfgSpace_Byte:
		push	bx
		xor	bh,bh			;reset BUS no. for POST
		call	Aget_CfgSpace_Byte
		pop	bx
		ret
Get_CfgSpace_word:
		push	bx
		xor	bh,bh			;reset BUS no. for POST
		call	Aget_CfgSpace_Word
		pop	bx
		ret
Get_CfgSpace_Dword:
		push	bx
		xor	bh,bh			;reset BUS no. for POST
		call	Aget_CfgSpace_DWord
		pop	bx
		ret
	
Set_CfgSpace_Byte:
		push	bx
		xor	bh,bh			;reset BUS no. for POST
		call	ASet_CfgSpace_Byte
		pop	bx
		ret
Set_CfgSpace_word:
		push	bx
		xor	bh,bh			;reset BUS no. for POST
		call	ASet_CfgSpace_Word
		pop	bx
		ret
Set_CfgSpace_Dword:
		push	bx
		xor	bh,bh			;reset BUS no. for POST
		call	ASet_CfgSpace_Dword
		pop	bx
		ret
endif;	PCI_BUS
;;-----------------------------------------------------------------------

;R01 - start
;Codes from PCI1A.ASM
;;-----------------------------------------------------------------------
ifdef	ADVANCE_POWER_MANAGEMENT
;[]=================================================================[]
;Procedure:	APM_INIT
;
;Function :	Initialize the APM low level interface.
;
;Input    :	ES = PM_RAM
;		AL = 0 ---> call from POST when PM is disabled
;		AL = 1 ---> call from POST when PM is enabled
;
;Output   :	None
;
;[Note]	  :	Called from PM_INIT of POST 79
;[]==================================================================[]
		Public	APM_INIT
APM_INIT	Proc	Near
		push	ds				;save data segment
		push	es
		pop	ds
		ASSUME	DS:PM_RAM

		or	[APM_STATUS],IS_32BIT_SUPPORTED\
				     +IS_16BIT_SUPPORTED\
				     +IS_PM_ENABLED\
				     +IS_APM_SUPPORTED
		or	al, al
		jnz	short @F
		and	[APM_STATUS],not IS_PM_ENABLED
	@@:

		or	[EXTEND_APM_STATUS],IS_PM_ENGAGED+PM_ALLOWED_BY_APM
;R11 - starts
		mov	[DEVICE_PM_STATUS], ALL_DEVICES_PM_ENABLED+ALL_DEVICES_PM_ENGAGED
;R11 - ends

	ifndef	NO_SUPPORT_APM12
		or	al, al
		jz	short @F
		extrn	Ct_PMU_Timer_Status:near
		call	Ct_PMU_Timer_Status
		and	al, PMU_TIMER_ENABLED
		or	[EXTEND_APM_STATUS], al
	@@:
		extrn	Ct_Ring_WakeUp_Status:near
		call	Ct_Ring_WakeUp_Status
		and	al, RING_WAKEUP_ENABLED
		or	[EXTEND_APM_STATUS], al
	endif	;NO_SUPPORT_APM12

;R02 - start
Ifdef SMBIOS_INTERFACE

		mov	[SMB_STATUS],0		;for SMBus use
		mov	[SMB_EXTEND_STATUS],0	;

;R03 		mov	al,0b7h				;Enable Smart Battery Host
;R03 			extrn	SMB_Write_Command:near	
;R03 		call	SMB_Write_Command		;
;R03 		mov	al,01h				;
;R03 			extrn SMB_Write_Data:near	;
;R03 		call	SMB_Write_Data			;

		call	SMBHOST_INIT		;R03

endif; SMBIOS_INTERFACE		
;R02 - end

IFNDEF	APM_IN_SMBASE				;R05
		extrn	Clear_Events:near
		call	Clear_Events
;R05 start
ELSE	;APM_IN_SMBASE
		mov	[APMEventSave],NO_EVENTS
		mov	[APM_EVENT_POST],0
ENDIF	;APM_IN_SMBASE
;R05 end

		pop	ds				;Restore data segment
		ret
APM_INIT	Endp
endif;	ADVANCE_POWER_MANAGEMENT
;;-----------------------------------------------------------------------
;R01 - end

;R16 - starts
ifdef	ADCM_SUPPORT

		ADCM_SSR	=	0000000b

	ifdef	W83781D_Support
		ADCM_SSR	=	0000010b
		ADCM_SSR	=	ADCM_SSR + (295h shl 8)
	ifdef	W83781D_Use_SMbus
		ADCM_SSR	=	ADCM_SSR + (5ah shl 24)
	endif;	W83781D_Use_SMbus
	endif	;W83781D_Support

	ifdef	LM75_Support
		ADCM_SSR	=	0000011b
		ADCM_SSR	=	ADCM_SSR + (LM75_ID shl 24)
	  ifdef	LM78_Support
		ADCM_SSR	=	0000110b
		ADCM_SSR	=	ADCM_SSR + (295h shl 8)
	  endif	;LM78_Support
	endif	;LM75_Support

	ifndef	LM75_Support
	ifdef	LM78_Support
		ADCM_SSR	=	0000100b
		ADCM_SSR	=	ADCM_SSR + (295h shl 8)
	endif	;LM78_Support
	endif	;LM75_Support

	ifdef	LM80_Support
		ADCM_SSR	=	0000101b
		ADCM_SSR	=	ADCM_SSR + (LM80_ID shl 24)
	endif	;LM80_Support

	ifdef	GL520SM_Support
	    ifdef	PIIX_IDE
		ADCM_SSR	=	0000001b
	    endif	;PIIX_IDE
	    ifdef	VT586
		ADCM_SSR	=	0000111b
	    endif	;VT586
	    ifdef	VT596
		ADCM_SSR	=	0001010b
	    endif	;VT596
	    ifdef	M1541
		ADCM_SSR	=	0001000b
	    endif	;M1541
	    ifdef	GL520SM_ID_Use_58h
	    ADCM_SSR	=	0000001b + (58h shl 24)
	    else;	GL520SM_ID_Use_58h
	    ADCM_SSR	=	0000001b + (5ah shl 24)
	    endif;	GL520SM_ID_Use_58h
	endif	;GL520SM_Support

	ifdef	HT82791_Support
	endif	;HT82791_Support

	ifdef	SIS5595_Support
		ADCM_SSR	=	0001011b
	  IF	BIOS_SUPPORT_686
		ADCM_SSR	=	0001001b
	  ENDIF	;BIOS_SUPPORT_686
		ADCM_SSR	=	ADCM_SSR + (295h shl 8)
	endif	;SIS5595_Support

	ifdef	VIA686HM_Support
		ADCM_SSR	=	0001100b
		ADCM_SSR	=	ADCM_SSR + (295h shl 8)
	endif	;VIA686HM_Support

	ifndef	MP_Support
		ADCM_SSR	=	ADCM_SSR + 10000000b
	endif;	MP_Support

		db	"$PCPROLM"
		PUBLIC	ADCM_SSR_BYTE
	ADCM_SSR_BYTE	LABEL	BYTE

		dd	ADCM_SSR		

endif	;ADCM_SUPPORT
;R16 - ends

FCODE		ENDS

;R06 -start
XGROUP		GROUP	XCODE
XCODE		SEGMENT USE16 PARA PUBLIC 'XCODE'
		ASSUME	CS:XGROUP,ES:XGROUP

ifdef	Bootblock_16K_Support			
ifdef	Automatic_Load_Awdflash				
ifNdef	No_Automatic_Load_Awdflash_InPOST		;R12
;[]=================================================================[]
;Procedure:	Int_Awdflash_Check
;Input    :	
;Output   :	None
;[Note]	  :	Called by INT09 (KBD_INT) after POST_65S
;[]==================================================================[]

		public	INT_Awdflash_Check
 		public	POST_Awdflash_Check
		
INT_Awdflash_Check	proc	near

		push	ds				; ***** DS

		mov	ax,G_RAM
		mov	ds,ax
		ASSUME 	DS:G_RAM

		; process flag
		or	byte ptr POST_FLAG,Awdflash_ON

		F000_call	Int_Kb_Enable

		test	INIT_ERR_FLG,IEF_AWDFLASH_OK	; enable Awdflash ?
		jz	short NOT_Awdflash		; NO

		call	Clear_Line
		call	Load_Awdflash
		pop	ds				; ***** DS
		iret

Not_Awdflash:
		test	POST_FLAG,AWD_Str_Show		;Show ?
		jz	short INT_Awdflash_Exit		;NO

		and	POST_FLAG,not AWD_Str_Show	 ;R06B
		call	Clear_Line
		call	Show_Load_Awdflash

INT_Awdflash_Exit:

		pop	ds				; ***** DS
		iret

INT_Awdflash_Check	endp

;[]=================================================================[]
;Procedure:	POST_Awdflash_Check
;Input    :	
;Output   :	None
;[Note]	  :	Called by POST_66S 
;[]==================================================================[]

POST_Awdflash_Check	proc	near

		push	ds				; ***** DS

		mov	ax,G_RAM
		mov	ds,ax
		ASSUME 	DS:G_RAM

		test	byte ptr POST_FLAG,Awdflash_ON	; F2 key enter ?
		jz	short Go_Return			; NO

		and	POST_FLAG,not AWD_Str_Show	 ;R06B
		call	Clear_Line
		call	Load_Awdflash

	Go_Return:

		pop	ds				; ***** DS
		ret

POST_Awdflash_Check	endp

;[]=================================================================[]
;Procedure:	Load_Awdflash
;Input    :	
;Output   :	None
;[Note]	  :	Called by INT_Awdflash_Check / POST_Awdflash_Check
;[]==================================================================[]

		include	READCOM.EQU
		include	READCOM.inc	;R17

;R17 Target_PROC_DISP	EQU	6+21
;R17 BOOTBLOCK_HEAD	db	'*BBSS*'

FDD_State	db	0
	FDD_A_None	EQU	00000001b
	FDD_A_AWD_None	EQU	00000010b
	FDD_B_None	EQU	00010000b
	FDD_B_AWD_None	EQU	00100000b
Target_FDD	db	0
	FDD_A		EQU	00000000b
	FDD_B		EQU	00000001b


Load_Awdflash	proc	near

		; Clear flag
		and	INIT_ERR_FLG,not IEF_AWDFLASH_OK ;R06B ;Disable Awdflash ?

		call	FDD_State_Check	
		mov	byte ptr cs:Target_FDD,FDD_A	 ;;;;;;
		cmp	byte ptr cs:FDD_State,(FDD_A_None+FDD_B_None)
		je	Show_Error_Mess1

Chk_FDD_AB_Again:
		test	byte ptr cs:FDD_State,FDD_A_None ;FDD A Exist?
		jnz	short @f			 ;No
		test	byte ptr cs:FDD_State,FDD_A_AWD_None ;FDD A None Awdflash.exe ?
		jz	short Init_FDD_AB		 ;No

	@@:
		mov	byte ptr cs:Target_FDD,FDD_B	 ;;;;;;
		test	byte ptr cs:FDD_State,(FDD_B_None+FDD_B_AWD_None)
		jz	short Init_FDD_AB

	Show_Error_Mess:
		test	byte ptr cs:FDD_State,FDD_A_AWD_None ;FDD A None Awdflash.exe ?
		jnz	Show_Error_Mess2		     ;yes	
		jmp	Show_Error_Mess3

		;-------------------------------------
	Init_FDD_AB:
;R17		mov	ax,3000h			;ES:BX
		mov	ax,Awd_Source_Value	;ES:BX	;R17
		mov	es,ax
		xor	bx,bx
		mov	ax,0201h
		mov	cx,0001h
		movzx	dx,byte ptr cs:Target_FDD
		int	13h
		jnc	Load_Awdflash_Start		; 1

		cmp	ah,80h				; (80h) ?
		jne	Load_Awdflash_Start			

		cmp	byte ptr cs:Target_FDD,FDD_B
		je	short Show_Error_Mess
		
		mov	byte ptr cs:Target_FDD,FDD_B
		jmp	short Init_FDD_AB

		;-------------------------------------
		;-------- Fdd A and B invalid --------
		;-------------------------------------
	Show_Error_Mess1:

		call	Clear_Kb_Buffer			
		call	Clear_Line

		push	ss:ATTRIBUTE[bp]
		mov	byte ptr ATTRIBUTE[bp],0Ch
	ifdef	Graphics_Post
		mov	si, offset Error_Mess1B
		test	byte ptr EQUIPMENT[bp],DT_MONO
		jnz	short @f
		cmp	byte ptr EPALOGO_FLAG[bp], 055h
		je	short @f
	endif;	Graphics_Post
		mov	si, offset Error_Mess1A
	@@:
		post_func_call	Disp_Str_In_BIOS1
		pop	ss:ATTRIBUTE[bp]

	Wait_ESC_KEY:
		xor	ax,ax
		int	16h
		cmp	al,1Bh				; ESC key ?
		jne	short Wait_ESC_KEY

	ESC_Awdflash:

		call	Clear_Line
		or	INIT_ERR_FLG,IEF_IN_POST	; Enable process F2 key
		ret

		;-------------------------------------
		;-------- AWDFLASH.EXE Invalid -------
		;-------------------------------------
	Show_Error_Mess2:

		mov	ax,G_RAM
		mov	ds,ax
		assume	ds:G_RAM

		call	Clear_Kb_Buffer			;;;;;;
		call	Clear_Line

		push	ss:ATTRIBUTE[bp]
		mov	byte ptr ATTRIBUTE[bp],0Ch
	ifdef	Graphics_Post
		mov	si, offset Error_Mess2B
		test	byte ptr EQUIPMENT[bp],DT_MONO
		jnz	short @f
		cmp	byte ptr EPALOGO_FLAG[bp], 055h
		je	short @f
	endif;	Graphics_Post
		mov	si, offset Error_Mess2A
	@@:
		post_func_call	Disp_Str_In_BIOS1
		pop	ss:ATTRIBUTE[bp]
		jmp	short WAIT_ESC_Key

		;-------------------------------------
		;-------- FDD A/B DISK Invalid -------
		;-------------------------------------
	Show_Error_Mess3:

		call	Clear_Kb_Buffer			;;;;;;
		call	Clear_Line

		push	ss:ATTRIBUTE[bp]
		mov	byte ptr ATTRIBUTE[bp],0Ch
	ifdef	Graphics_Post
		mov	si, offset Error_Mess3B
		test	byte ptr EQUIPMENT[bp],DT_MONO
		jnz	short @f
		cmp	byte ptr EPALOGO_FLAG[bp], 055h
		je	short @f
	endif;	Graphics_Post
		mov	si, offset Error_Mess3A
	@@:
		post_func_call	Disp_Str_In_BIOS1
		pop	ss:ATTRIBUTE[bp]

	Wait_ESC_Enter_KEY:
		xor	ax,ax
		int	16h
		cmp	al,1Bh			; ESC key ?
		je	ESC_Awdflash		; yes
		cmp	al,0Dh			; Enter key ?
		jne	short Wait_ESC_Enter_KEY

		mov	byte ptr cs:Target_FDD,FDD_A	 
		and	byte ptr cs:FDD_State,not (FDD_A_AWD_None+FDD_B_AWD_None)
		jmp	Chk_FDD_AB_Again

		;лллллллллллллллллллллллллллллллллллллллллл Load AWDFLASH.EXE

Load_Awdflash_Start:
		
		call	Clear_Line
		call	Show_Load_Awdflash
		
		;-------------------------------------

		push	sp				;******
		push	bp				;******

		sub	sp,STACKSIZE
		mov	bp,sp

		;------------------------------------------
		;Find *BBSS* String address

		mov	ax,2000h
		mov	es,ax
;R17 		mov	di,4000h 		; ES:DI = 2000H:4000H start

		mov	ax,cs			; DS
		mov	ds,ax
;R17 		mov	cx,48*1024 		; 64K-16K
;R17 
;R17 Find_BBSS_Loop:
;R17 
;R17 		cld
;R17 		push	cx
;R17 		push	di
;R17 		mov	cx,6
;R17 		mov	si,offset cs:BOOTBLOCK_HEAD	;DS:SI
;R17 		repe	cmpsb
;R17 		pop	di
;R17 		pop	cx
;R17 
;R17 		je	short Find_BBSS_OK
;R17 		inc	di
;R17 		loop	short Find_BBSS_Loop
;R17 
;R17 Find_BBSS_NG:
;R17 		add	sp,STACKSIZE
;R17 		pop	bp				;******
;R17 		pop	sp				;******
;R17 		jmp	Show_Error_Mess2
;R17 
;R17 Find_BBSS_OK:
;R17 
;R17 		add	di,Target_PROC_DISP
;R17 		mov	ax,word ptr es:[di]
;R17 		mov	ss:Target_HEAD_Offset,ax
;R17 		mov	ss:Target_HEAD_Segment,2000h
;R17 
;R17 		;------------------------------------------
;R17 		;During POST .....
;R17 		;Run Read_Fdd_File_To_Memory proc will load awdflash.exe in 3000h
;R17 
		mov	al,byte ptr cs:Target_FDD
		mov	Readcom_Valid_Drive,al		
		mov	Run_Path,POST
;R17		mov	ss:Cluster_Data_Buffer_Seg,3F00h
;R17		mov	ss:Assign_1_Cluster_Segment,3000h
;R17		mov	ss:Assign_FAT1_Segment,3000h
;R17		mov	ss:Assign_COM_Buf_Segment,3000h
;R17
;R17 		push	Xgroup_Segment
;R17 		push	offset cs:Return_Place1
;R17 
;R17 		; call Read_Fdd_File_To_Memory [bootrom.asm]
;R17 		push	ss:Target_HEAD_Segment		; High address
;R17 		push	ss:Target_HEAD_Offset
;R17 		retf					
;R17 
;R17 	Return_Place1:
;R17 - starts
		mov	ss:Cluster_Data_Buffer_Seg, Cluster_Buffer_Value	
		mov	ss:Assign_1_Cluster_Segment, Assign_1_Cluster_Value
		mov	ss:Assign_FAT1_Segment, Assign_FAT1_Value 	
		mov	ss:Assign_COM_Buf_Segment, Assign_COM_Buf_Value 	
		call	Read_Fdd_File_To_Memory	
;R17 - ends
		jnc	short Load_Awdflash_OK
		add	sp,STACKSIZE
		pop	bp				;******
		pop	sp				;******

		cmp	byte ptr cs:Target_FDD,FDD_B	;
		je	short @f
		or	byte ptr cs:FDD_State,FDD_A_AWD_None
		mov	byte ptr cs:Target_FDD,FDD_B
		jmp	Chk_FDD_AB_Again
	@@:

		jmp	Show_Error_Mess2

	Load_Awdflash_OK:
		add	sp,STACKSIZE
		pop	bp				;******
		pop	sp				;******

		;лллллллллллллллллллллллллллллллллллллллллл RUN AWDFLASH.EXE

		;------------------------------------------
		; Disable Chipset SMI

	;R06B -start
		push	Xgroup_Segment
		push	offset cs:Return_Place2

		push	0F000h			; High address
		push	offset Ct_Special_REG_Save
		retf	       

	Return_Place2:

	;R06B -end

		;------------------------------------------
		;Modify SS/SP/BP for run awdflash.exe
			   
;R17		mov	ax,3000h 			; SS:SP
		mov	ax,Awd_Source_Value	;R17 ; SS:SP
		mov	ss,ax
		mov	sp,0FFFFh

		sub	sp,AWD_STACKSIZE		; BP
		mov	bp,sp

		;------------------------------------------
		;Transfer BIOS_ID and some parameter to awdflash.exe

		push	ds
		push	es

		mov	ax,2000h			;DS:SI
		mov	ds,ax
		mov	si,0FFE8h

		mov	ax,ss				;ES:DI
		mov	es,ax
		mov	di,bp
		add	di,BIOS_ID_String
		mov	cx,8				; 8 bytes
		rep	movsb

		pop	es
		pop	ds

		mov	al,byte ptr cs:Target_FDD
		mov	byte ptr ss:Valid_Drive[bp],al
;R17		mov	word ptr ss:Awdflash_Seg[bp],3000h
;R17		mov	word ptr ss:Source_Segment[bp],4000h 	;256K
;R17		mov	word ptr ss:Bios_Segment[bp],2000h	; 64K
;R17		mov	word ptr ss:Decompress_Segment[bp],8000h
;R17		mov	word ptr ss:Buffer1_Segment[bp],8000h	
;R17		mov	word ptr ss:Buffer2_Segment[bp],6000h
;R17 - starts
		mov	word ptr ss:Awdflash_Seg[bp],Awd_Source_Value
		mov	word ptr ss:Source_Segment[bp],Source_Seg_Value	
		mov	word ptr ss:Bios_Segment[bp],Bios_Seg_Value	
		mov	word ptr ss:Decompress_Segment[bp],Decompress_Seg_Value
		mov	word ptr ss:Buffer1_Segment[bp],Buffer1_Seg_Value	
		mov	word ptr ss:Buffer2_Segment[bp],Buffer2_Seg_Value	
;R17 - ends
		; call AWDFLASH.EXE and don't come back forever
		mov	ax,word ptr ss:Awdflash_Seg[bp]
		mov	ds,ax			;R06A
		add	al,byte ptr ds:[08h]	;R06A ;Size of awdflash.exe header
;R06A		add	ax,20h
		push	ax			; High address
		push	word ptr 0
		retf					

Load_AWDFLASH	endp

;[]------------------------------------------------------[]
;Procedure:	FDD_State_Check
;Input    :	None
;Output   :	FDD A Driver None - cs:FDD_State = FDD_A_None 
;		FDD B Driver None - cs:FDD_State = FDD_B_None 
;[]------------------------------------------------------[]
FDD_State_Check	proc	near

		mov	si,offset DGROUP:DRIVE_A_ITEM
		call	X_GetItem_Value
		cmp	al,0			; Floppy A None ?
		jne	short @f		; NO
		or	byte ptr cs:FDD_State,FDD_A_None
	@@:
ifndef	Support_1_Fdd				;R13
		mov	si,offset DGROUP:DRIVE_B_ITEM
		call	X_GetItem_Value
		cmp	al,0			; Floppy B None ?
		jne	short @f		; NO
endif;	Support_1_Fdd				;R13
		or	byte ptr cs:FDD_State,FDD_B_None
	@@:
		;-------------------------------------

		mov	byte ptr cs:Target_FDD,FDD_A

	Check_Drive_B:
				
;R17		mov	ax,3000h		; ES:BX
		mov	ax,Awd_Source_Value	;R17 ; ES:BX
		mov	es,ax
		xor	bx,bx

		mov	ax,0201h
		mov	cx,0001h
		movzx	dx,byte ptr cs:Target_FDD
		int	13h
		jnc	short Point_Drive_B

		cmp	ah,40h				; FDD None (40h) ?
		jne	short Point_Drive_B		; yes
		mov	al,FDD_A_None
		cmp	byte ptr cs:Target_FDD,FDD_A	; FDD A ?
		je	short @f			; yes
		mov	al,FDD_B_None
	@@:
		or	byte ptr cs:FDD_State,al

	Point_Drive_B:
		cmp	byte ptr cs:Target_FDD,FDD_B	; FDD B ?
		je	short Go_End			; yes
		mov	byte ptr cs:Target_FDD,FDD_B
		jmp	short Check_Drive_B
	Go_End:
		ret

FDD_State_Check	endp


;[]------------------------------------------------------[]
;Procedure:	Clear_Kb_Buffer		
;Input    :	None
;Output   :	None
;[]------------------------------------------------------[]
Clear_Kb_Buffer	proc	near

Continue_Clear:	
		mov	ax,0100h
		int	16h				; None Char ?
		jz	short Clear_Kb_OK		; yes

		xor	ax,ax 				; Get Invalid Char
		int	16h
		jmp	short Continue_Clear
Clear_Kb_OK:
		ret

Clear_Kb_Buffer	endp
;[]------------------------------------------------------[]
;Procedure:	Show_Load_Awdflash
;Input    :	None
;Output   :	None
;[]------------------------------------------------------[]
Show_Load_Awdflash	proc	near

ifdef	Graphics_Post
		mov	si, offset Load_Awdflash_FromAB1
		test	byte ptr EQUIPMENT[bp],DT_MONO
		jnz	short @f
		cmp	byte ptr EPALOGO_FLAG[bp], 055h
		je	short @f
endif;	Graphics_Post
		mov	si, offset Load_Awdflash_FromAB
	@@:
		post_func_call	Disp_Str_In_BIOS1
		ret

Show_Load_Awdflash	endp

;[]------------------------------------------------------[]
;Procedure:	Clear_Line
;Input    :	None
;Output   :	None
;[]------------------------------------------------------[]
Clear_Line	proc	near

ifdef	Graphics_Post
		mov	si, offset TO_ENTER_Awdflash_Empty1
		test	byte ptr EQUIPMENT[bp],DT_MONO
		jnz	short @f
		cmp	byte ptr EPALOGO_FLAG[bp], 055h
		je	short @f
endif;	Graphics_Post
		mov	si, offset TO_ENTER_Awdflash_Empty
	@@:
		post_func_call	Disp_Str_In_BIOS1
		ret

Clear_Line	endp

endif	;No_Automatic_Load_Awdflash_InPOST		;R12
endif	;Automatic_Load_Awdflash				
endif	;Bootblock_16K_Support			

XCODE		ENDS
;R06 -end

		END
