;	[]===========================================================[]
;
;	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	DALLAS_NVM

;****************************************************************
;*								*
;*	SUBROUTINES TO SUPPORT DALLAS CMOS RAM FOR ESCD		*
;*								*
;****************************************************************

;[]========================================================================[]
;Procedure:	Ct_ESCD_Info
;Function :
;Input    :	SS:EBP = index structure
;			DWORD PTR [EBP+2] = pointer for MinESCDWriteSize(word)
;			DWORD PTR [EBP+6] = pointer for ESCDSize(word)
;			DWORD PTR [EBP+10] = pointer for NVStorageBase(dword)
;Output   :	CF = 0 successful
;		CF = 1 fail
;Registers:
;Note	  :
;[]========================================================================[]
		public	Ct_ESCD_Info
Ct_ESCD_Info	proc	near

;Minimum write storage size

		mov	di, [ebp+4]
		mov	es, di
		mov	di, [ebp+2]
		mov	word ptr es:[di], ESCD_SIZE

;Maximum storage size

		mov	di, [ebp+8]
		mov	es, di
		mov	di, [ebp+6]
		mov	word ptr es:[di], ESCD_SIZE

;Non-volatile storage 32-bit physical base address

		mov	di, [ebp+12]
		mov	es, di
		mov	di, [ebp+10]
		mov	dword ptr es:[di], 0	;zero for I/O NVM

		clc
		ret

Ct_ESCD_Info	endp

;[]========================================================================[]
;Procedure:	Ct_Get_ESCD
;Function :
;Input    :	DS = ESCD storage selector/segment (reported by Ct_ESCD_Info)
;		ES:DI = pointer for caller's ESCD buffer
;Output   :	CF = 0 successful
;		CF = 1 fail
;Registers:
;Note	  :
;[]========================================================================[]
		public	Ct_Get_ESCD
Ct_Get_ESCD	proc	near

		pushad
		mov	al, 0Ah
		call	Get_CMOS
		push	ax			;Save CMOS 0Ah Value
		or	al, 10h			;Enable NVM BANK 1
		mov	ah, al
		mov	al, 0Ah
		call	Set_CMOS

		mov	cx, 4
		mov	si, ESCD_ADDR+2
		xor	edx, edx
	@@:
		shl	edx, 8
		push	cx
		mov	cx, si
		call	Get_NVM
		pop	cx
		mov	dl, al
		inc	si
		loop	short @b

		cmp	edx, "ACFG"
		jne	short Ct_Get_ESCD_Fail

		mov	cx, ESCD_ADDR
		call	Get_NVM
		mov	dl, al
		mov	cx, ESCD_ADDR+1
		call	Get_NVM
		mov	dh, al
		mov	cx, dx
		cmp	cx, ESCD_SIZE
		ja	short Ct_Get_ESCD_Fail
		jcxz	short Ct_Get_ESCD_Fail

		mov	si, ESCD_ADDR
	@@:
		push	cx
		mov	cx, si
		call	Get_NVM
		stosb
		inc	si
		pop	cx
		loop	short @b

		pop	ax			;Load CMOS 0Ah Value
		mov	ah, al
		mov	al, 0Ah
		call	Set_CMOS
		popad
		clc
		ret

	Ct_Get_ESCD_Fail:

		pop	ax			;Load CMOS 0Ah Value
		mov	ah, al
		mov	al, 0Ah
		call	Set_CMOS
		popad
		stc
		ret

Ct_Get_ESCD	endp

;[]========================================================================[]
;Procedure:	Ct_Set_ESCD
;Function :
;Input    :	DS:SI = pointer for caller's ESCD buffer
;		ES = ESCD storage selector/segment (reported by Ct_ESCD_Info)
;		CX = length
;Output   :	CF = 0 successful
;		CF = 1 fail
;Registers:
;Note	  :
;[]========================================================================[]
		public	Ct_Set_ESCD
Ct_Set_ESCD	proc	near

		cmp	cx, ESCD_SIZE
		ja	short Ct_Set_ESCD_Fail
		jcxz	short Ct_Set_ESCD_Fail

		pusha
		mov	al, 0Ah
		call	Get_CMOS
		push	ax			;Save CMOS 0Ah Value
		or	al, 10h			;Enable NVM BANK 1
		mov	ah, al
		mov	al, 0Ah
		call	Set_CMOS

		mov	di, ESCD_ADDR
	@@:
		push	cx
		lodsb
		mov	cx, di
		call	Set_NVM
		pop	cx
		inc	di
		loop	short @b

		pop	ax			;Load CMOS 0Ah Value
		mov	ah, al
		mov	al, 0Ah
		call	Set_CMOS
		popa
		clc
		ret

	Ct_Set_ESCD_Fail:

		stc
		ret

Ct_Set_ESCD	endp

;[]========================================================================[]
;Procedure:	Get_NVM
;Function :	Get one byte NVM
;Input    :	CX = index
;Output   :	AL = value
;Registers:
;Note	  :
;[]========================================================================[]

Get_NVM		proc	near
		push	bx
		push	dx
		mov	dx, cx			;Save Address

		mov	al, 50h
		mov	ah, dl			;Set Low Address
		call	Set_CMOS
		mov	al, 51h
		mov	ah, dh			;Set High Address
		call	Set_CMOS

		mov	al, 53h
		call	Get_CMOS		;Read NVM RAM Data

		pop	dx
		pop	bx
		ret
Get_NVM		endp

;[]========================================================================[]
;Procedure:	Set_NVM
;Function :	Set one byte NVM
;Input    :	CX = index
;		AL = value
;Output   :	none
;Registers:
;Note	  :
;[]========================================================================[]

Set_NVM		proc	near
		push	bx
		push	dx
		mov	dx, cx			;Save Address
		mov	bl, al			;Save Data

		mov	al, 50h
		mov	ah, dl			;Set Low Address
		call	Set_CMOS
		mov	al, 51h
		mov	ah, dh			;Set High Address
		call	Set_CMOS

		mov	al, 53h
		mov	ah, bl			;Write Data
		call	Set_CMOS

		pop	dx
		pop	bx
		ret
Set_NVM		endp

Get_CMOS	Proc	Near
		out	70h, al
		NEWIODELAY
		in	al, 71h
		NEWIODELAY
		ret
Get_CMOS	Endp

Set_CMOS	Proc	Near
		out	70h, al
		NEWIODELAY
		mov	al, ah
		out	71h, al
		NEWIODELAY
		ret
Set_CMOS	Endp

endif	;DALLAS_NVM

