;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R00	04/19/98 JSN	Initial revision.

;[]=======================================================================[]
;AliM5879_Support   	 	:Ali AliM5879 sensor support
;NO_SHOW_AliM5879_CPUFAN1 	:No AliM5879 Fan1 support.
;NO_SHOW_AliM5879_CPUFAN2 	:No AliM5879 Fan2 support.
;AliM5879_CMOS	     		:AliM5879 cmos location
;AliM5879_CMOS_Bits    	 	:AliM5879 cmos 3 bits location
;W83783S_ACPI_CMOS		:AliM5879 ACPI cmos location
;W83783S_ACPI_CMOS_BITS		:AliM5879 ACPI cmos 3 bits location
;[]=======================================================================[]

ifdef	COMPILE_FOR_SENSOR_ASM
IF	COMPILE_FOR_SENSOR_ASM EQ 2
ifndef	SENSOR_IN_XGROUP

		public	Get_AliM5879_Byte
		public	Set_AliM5879_Byte
		public	Get_AliM5879_Word
		public	Set_AliM5879_Word
		extrn	Ct_I2CReadByte:near
		extrn	Ct_I2CWriteByte:near
		extrn	Ct_I2CReadWord:near
		extrn	Ct_I2CWriteWord:near

Get_AliM5879_Byte	Proc	Near
		call	Ct_I2CReadByte
		ret
Get_AliM5879_Byte	ENDP

Set_AliM5879_Byte	Proc	Near
		call	Ct_I2CWriteByte
		ret
Set_AliM5879_Byte	ENDP

Get_AliM5879_Word	Proc	Near
		call	Ct_I2CReadWord
		ret
Get_AliM5879_Word	ENDP

Set_AliM5879_Word	Proc	Near
		call	Ct_I2CWriteWord
		ret
Set_AliM5879_Word	ENDP

		public	Get_AliM5879
		public	Set_AliM5879
Get_AliM5879	Proc	Near
		pushf
		push	dx

		mov	ch, 5ah
		Call	Get_AliM5879_Byte

		pop	dx
		popf
		ret
Get_AliM5879	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_AliM5879	Proc	Near
		pushf
		push	dx

		mov	ch, 5ah
		Call	Set_AliM5879_Byte

		pop	dx
		popf
		ret
Set_AliM5879	Endp

ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		extrn	TEMP1_HIGH:near		
		extrn	SENSOR_FLAG:near
;[]========================================================================[]
;Procedure:	Ct_FillTempPointer
;
;Function :	Return Thermal Zone Temperature pointer 
;
;Input	  :	F segment shadow RAM is writeable 
;
;Output   :	none
;	
;[]========================================================================[]
		Public	Ct_FillTempPointer
Ct_FillTempPointer	Proc	Near

		push	es
		
		mov	ax,0f000h
		mov	es,ax
		mov	di,offset DGROUP:SENSOR_FLAG
		test	word ptr es:[di],01h
		jz	short No_Sensor
		mov	di,offset DGROUP:TEMP1_HIGH

		extrn	CPU_TEMP_ITEM:near
		mov	si,offset DGROUP:CPU_TEMP_ITEM
		call	E_GetItem_Value

		push	ax
		mov	si,offset DGROUP:ACPI_Critical_Item
		call	E_GetItem_Value
		xor	ah,ah
		shl	ax,1
		mov	si,offset Critical_Table
		add	si,ax
		mov	ax,word ptr cs:[si]
		mov	word ptr es:[di+8],ax	;Critical trip point
		sub	ax, 2732
		mov	bl, 10
		div	bl
		pop	bx

ifdef	No_CPU_Temp_Selectable
		mov	si,offset CPU_TEMP_Tbl	
		xor	bh,bh			
		add	si,bx			
		mov	bl,cs:[si]		
endif;	No_CPU_Temp_Selectable

		cmp	bl,al 			;al is shutdown temp.
		jbe	short	@F
		mov	bl, al
	@@:
		mov	al, bl
		mov	cl,10
		mul	cl
		add	ax,2732

		mov	word ptr es:[di],ax	; Trip point 1 high
		mov	word ptr es:[di+4],ax	; Trip point 2 high
		sub	ax,30
		mov	word ptr es:[di+2],ax	; Trip point 1 low
		mov	word ptr es:[di+6],ax	; Trip point 2 low

No_Sensor:					
		pop	es
		ret
Ct_FillTempPointer	Endp

Critical_Table:

		dw	3332			;60c		
		dw	3382			;65c		
		dw	3432			;70c		
		dw	3482			;75c		

endif	;ACPI_Support

;***************************************************************************
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;***************************************************************************

;[]==============================================================[]
;[]==============================================================[]
		Public	Prg_AliM5879_Chip
Prg_AliM5879_Chip	Proc	Near

 	;Hide AliM5879's display items if it is not mounted on M/B.
		mov	cl, 48h
		call	Get_AliM5879
		cmp	al, 2dh
		je	short @F

		push	ds
		mov	ax,0f000h
		mov	ds,ax

		extrn	CPU_Temp_Item:near
		extrn	Temp1_Item:near
		extrn	Temp2_Item:near
ifndef	NO_SHOW_AliM5879_CPUFAN1
		extrn	Current_CPUFAN1_Item:near
endif;	NO_SHOW_AliM5879_CPUFAN1
ifndef	NO_SHOW_AliM5879_CPUFAN2
		extrn	Current_CPUFAN2_Item:near
endif;	NO_SHOW_AliM5879_CPUFAN2
		extrn	Current_IN0_Item:near
		extrn	Current_IN2_Item:near
		extrn	Current_IN3_Item:near
		extrn	Current_IN4_Item:near
		extrn	F000_Shadow_W:near
		extrn	F000_Shadow_R:near
		extrn	F000_call_proc:near
		assume	ds:DGROUP
		f000_call	DGROUP:F000_Shadow_W
		or	word ptr ds:[CPU_Temp_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Temp1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Temp2_Item].ITEMSTAT,ITEMDISABLE
ifndef	NO_SHOW_AliM5879_CPUFAN1
		or	word ptr ds:[Current_CPUFAN1_Item].ITEMSTAT,ITEMDISABLE
endif;	NO_SHOW_AliM5879_CPUFAN1
ifndef	NO_SHOW_AliM5879_CPUFAN2
		or	word ptr ds:[Current_CPUFAN2_Item].ITEMSTAT,ITEMDISABLE
endif;	NO_SHOW_AliM5879_CPUFAN2
		or	word ptr ds:[Current_IN0_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_IN2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_IN3_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_IN4_Item].ITEMSTAT,ITEMDISABLE
ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		or	word ptr ds:[ACPI_Critical_Item].ITEMSTAT,ITEMDISABLE
endif;	ACPI_Support

ifdef	ACPI_SUPPORT
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT
		f000_call	DGROUP:F000_Shadow_R
		pop	ds
		jmp	Prg_AliM5879_Chip_End
	@@:

		mov	cx,10
	Clear_AliM5879:
		push	cx
		mov	cl,41h
		call	Get_AliM5879
		mov	cl,42h
		call	Get_AliM5879
		pop	cx
		loop	short Clear_AliM5879

		mov	si,offset EGROUP:Prg_AliM5879_Tbl
	Init_Start:
		mov	cl,cs:[si]
		call	Get_AliM5879

		mov	cl,cs:[si]
		and	al,cs:[si+1]
		or	al,cs:[si+2]
		call	Set_AliM5879
		add	si,3

		cmp	si,offset EGROUP:Prg_AliM5879_Tbl_End
		jne	short Init_Start

		mov	si,offset DGROUP:CPU_Temp_Item
		call	E_GetItem_Value
		push	ax
ifdef	ACPI_Support
		mov	si,offset DGROUP:ACPI_Critical_Item
		call	E_GetItem_Value
		xor	ah,ah
		shl	ax,1
		mov	si,offset Critical_Table
		add	si,ax
		mov	ax,word ptr cs:[si]
		sub	ax, 2732
		mov	bl, 10
		div	bl
else;	ACPI_Support
		mov	al, 80			;max. Warning temp.
endif;	ACPI_Support
		pop	bx

ifdef	No_CPU_Temp_Selectable			
		mov	si,offset CPU_TEMP_Tbl	
		xor	bh,bh			
		add	si,bx			
		mov	bl,cs:[si]		
endif;	No_CPU_Temp_Selectable
		push	bx
		cmp	bl,al 			;al is shutdown temp.
		jbe	short	@F

		mov	cl,4ch
		call	Get_AliM5879
		or	al,00001000b		;Disable OVT Pin
		mov	cl,4ch
		call	Set_AliM5879

		mov	cl,40h
		call	Get_AliM5879
		and	al,not 00000010b	;Disable SMI Pin
		mov	cl,40h
		call	Set_AliM5879

		mov	cl,56h
		call	Get_AliM5879
		and	al,not 00100000b	;disable CPU temp. beep
		mov	cl,56h
		call	Set_AliM5879
	@@:
		pop	ax

		push	ax
		push	ax

	;Program CPU1 (sensor2)
		pop	ax
		mov	cx,9203h
		call	Set_AliM5879_Word	;set Tos (High limit)

		pop	ax
		sub	al,5
		mov	cx,9202h
		call	Set_AliM5879_Word	;set Thyst (Low limit)

ifdef	Thermal_Enable_Use_SMI
		mov	al,02h			;interrupt mode
else;	Thermal_Enable_Use_SMI
		mov	al,0			;comparator mode
endif;	Thermal_Enable_Use_SMI
		mov	cx,9201h
		call	Set_AliM5879_Byte

		mov	cl,56h
		call	Get_AliM5879
		or	al,00100000b		;enable CPU temp. beep
		mov	cl,56h
		call	Set_AliM5879

Prg_AliM5879_Chip_End:

		ret

Prg_AliM5879_Chip	Endp

		assume	ds:EGROUP
ifdef	No_CPU_Temp_Selectable
CPU_TEMP_Tbl:
		db	0120	;disabled
		db	032h	;50C
		db	035h	;53C
		db	038h	;56C
		db	03ch	;60C
		db	03fh	;63C
		db	042h	;66C
		db	046h	;70C
ifdef INTEL_M2_CPU_Temprature_Rang
		db	04Bh	;75C
		db	050h	;80C
		db	055h	;85C
		db	05Ah	;90C
		db	05Fh	;95C
endif; INTEL_M2_CPU_Temprature_Rang
endif;	No_CPU_Temp_Selectable

		ALIGN	4
		;---------------------------
		;      index  	and	or
		;---------------------------
Prg_AliM5879_Tbl:
		db	40h,	00h,	080h
		db	43h,	00h,	0FFh
		db	47h,	0Fh,	050h
		db	40h,	00h,	001h
		db	4Ah,	00h,	008h
		db	4Ch,	00h,	0FFh

Prg_AliM5879_Tbl_End:

endif	;SENSOR_IN_XGROUP		
ENDIF	;COMPILE_FOR_SENSOR_ASM EQ 2
endif	;COMPILE_FOR_SENSOR_ASM

ifdef	COMPILE_FOR_SENSOR_MNU
;***************************************************************************
;***** Special_Show Special_Show Special_Show Special_Show Special_Show ****
;***** Special_Show Special_Show Special_Show Special_Show Special_Show ****
;***** Special_Show Special_Show Special_Show Special_Show Special_Show ****
;***************************************************************************
IF	COMPILE_FOR_SENSOR_MNU EQ 2
ifndef	No_CPU_Temp_Selectable
		dw	offset CPU_Temp_Item, offset Show_Scale
endif;	No_CPU_Temp_Selectable
		dw	offset Temp1_Item, offset Show_Temp1
		dw	offset Temp2_Item, offset Show_Temp2
ifndef	NO_SHOW_AliM5879_CPUFAN1
		dw	offset Current_CPUFAN1_Item, offset Show_Current_CPUFAN1
endif;	NO_SHOW_AliM5879_CPUFAN1
ifndef	NO_SHOW_AliM5879_CPUFAN2
		dw	offset Current_CPUFAN2_Item, offset Show_Current_CPUFAN2
endif;	NO_SHOW_AliM5879_CPUFAN2
		dw	offset Current_IN0_Item, offset Show_Current_IN0 
		dw	offset Current_IN2_Item, offset Show_Current_IN2 
		dw	offset Current_IN3_Item, offset Show_Current_IN3 
		dw	offset Current_IN4_Item, offset Show_Current_IN4 
ENDIF	;COMPILE_FOR_SENSOR_MNU 

;***************************************************************************
;**** SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU ****
;**** SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU ****
;**** SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU ****
;**** SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU SENSOR.MNU ****
;***************************************************************************
IF	COMPILE_FOR_SENSOR_MNU EQ 1

		Public	First_AliM5879_Item	
First_AliM5879_Item	Label	Near		

ifndef	No_CPU_Temp_Selectable
DEFINE_ITEM	CPU_Temp_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
	menuitem <NOMODBIN+SHOWNUM+DIGIT3,\
		  offset CPU_Temp_Str,NOCT,00000000b,AliM5879_CMOS,01111111b,\
		  offset Nullstr,55,75,Xaxis,Yaxis,40,40,offset Nullstr>
else;	No_CPU_Temp_Selectable

ifndef INTEL_M2_CPU_Temprature_Rang
DEFINE_ITEM	CPU_Temp_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <PMITEM,\
                  offset CPU_Temp_Str,NOCT,AliM5879_CMOS_Bits,AliM5879_CMOS,AliM5879_CMOS_Bits,\
                  offset CPU_Temp_Val,0,7,Xaxis,Yaxis,0,0,offset Std_Help_Str>
else;  INTEL_M2_CPU_Temprature_Rang
DEFINE_ITEM	CPU_Temp_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <PMITEM,\
                  offset CPU_Temp_Str,NOCT,AliM5879_CMOS_Bits,AliM5879_CMOS,AliM5879_CMOS_Bits,\
                  offset CPU_Temp_Val,0,12,Xaxis,Yaxis,0,0,offset Std_Help_Str>
endif; INTEL_M2_CPU_Temprature_Rang

endif;	No_CPU_Temp_Selectable
DEFINE_ITEM	Temp1_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Temp1_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>
DEFINE_ITEM	Temp2_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Temp2_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>
ifndef	NO_SHOW_AliM5879_CPUFAN1
DEFINE_ITEM	Current_CPUFAN1_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_CPUFAN1_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>
endif;	NO_SHOW_AliM5879_CPUFAN1

ifndef	NO_SHOW_AliM5879_CPUFAN2
DEFINE_ITEM	Current_CPUFAN2_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_CPUFAN2_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>
endif;	NO_SHOW_AliM5879_CPUFAN2

DEFINE_ITEM	Current_IN0_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_IN0_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

Xaxis = Xaxis + 18
Yaxis = Yaxis - 1

IN2=1
IN3=0
IN4=1
IN5=0

DEFINE_ITEM	Current_IN2_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_IN2_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

IF	IN2	 EQ	1
Xaxis = Xaxis - 18
ELSE;	IN2	 EQ	1
Xaxis = Xaxis + 18
Yaxis = Yaxis - 1
ENDIF;	IN2	 EQ	1

DEFINE_ITEM	Current_IN3_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_IN3_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

IF	IN3	 EQ	1
Xaxis = Xaxis - 18
ELSE;	IN3	 EQ	1
Xaxis = Xaxis + 18
Yaxis = Yaxis - 1
ENDIF;	IN3	 EQ	1

DEFINE_ITEM	Current_IN4_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_IN4_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

IF	IN4	 EQ	1
Xaxis = Xaxis - 18
ELSE;	IN4	 EQ	1
Xaxis = Xaxis + 18
Yaxis = Yaxis - 1
ENDIF;	IN4	 EQ	1

ifdef	ACPI_SUPPORT
DEFINE_ITEM     ACPI_Critical_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <PMITEM,\
                  offset ACPI_Critical_Str      ,NOCT,00000011b,AliM5879_ACPI_CMOS,AliM5879_ACPI_CMOS_BITS,\
                  offset Critical_str,0,3,Xaxis,Yaxis,00000011b,AliM5879_ACPI_CMOS_BITS-1,offset Std_Help_Str>
endif	;ACPI_SUPPORT

		Public	Last_AliM5879_Item	
Last_AliM5879_Item	Label	Near		

ENDIF	;COMPILE_FOR_SENSOR_MNU 

;***************************************************************************
;**** SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR ****
;**** SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR ****
;**** SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR ****
;**** SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR SENSOR.STR ****
;***************************************************************************
IF	COMPILE_FOR_SENSOR_MNU EQ 0
ifdef	ACPI_SUPPORT
ACPI_Critical_Str	db      'Shutdown Temperature'
			db	(COLLON_LOC - ($-(offset ACPI_Critical_Str))) dup (" ")
			db	': ',0

Critical_str		db      '60øC/140øF',0
			db      '65øC/149øF',0
			db      '70øC/158øF',0
			db	'75øC/167øF',0

endif	;ACPI_SUPPORT

CPU_Temp_Str	db	'CPU Warning Temperature'
		db	(COLLON_LOC - ($-(offset CPU_Temp_Str))) dup (" ")
ifndef	No_CPU_Temp_Selectable
		db	':',0
else;	No_CPU_Temp_Selectable  
		db	': ',0
endif;	No_CPU_Temp_Selectable
ifdef	No_CPU_Temp_Selectable
CPU_Temp_Val    db      'Disabled  ',0
	    	db      '50øC/122øF',0
	    	db      '53øC/127øF',0
	    	db      '56øC/133øF',0
	    	db      '60øC/140øF',0
	    	db      '63øC/145øF',0
	    	db      '66øC/151øF',0
	    	db      '70øC/158øF',0
ifdef INTEL_M2_CPU_Temprature_Rang	
		db      '75øC/167øF',0		
		db      '80øC/176øF',0
		db      '85øC/185øF',0
		db      '90øC/194øF',0
	    	db      '95øC/205øF',0	
endif; INTEL_M2_CPU_Temprature_Rang	
endif;	No_CPU_Temp_Selectable		

Temp1_Str	db	'Current System Temp.'
		db	(COLLON_LOC - ($-(offset Temp1_Str))) dup (" ")
		db	': ',0

Temp2_Str	db	'Current CPU1 Temperature'
		db	(COLLON_LOC - ($-(offset Temp2_Str))) dup (" ")
		db	': ',0

ifndef	NO_SHOW_AliM5879_CPUFAN1
Current_CPUFAN1_Str	db	'Current CPUFAN1 Speed'
			db	(COLLON_LOC - ($-(offset Current_CPUFAN1_Str))) dup (" ")
			db	': ',0
endif;	NO_SHOW_AliM5879_CPUFAN1

ifndef	NO_SHOW_AliM5879_CPUFAN2
Current_CPUFAN2_Str	db	'Current CPUFAN2 Speed'
			db	(COLLON_LOC - ($-(offset Current_CPUFAN2_Str))) dup (" ")
			db	': ',0
endif;	NO_SHOW_AliM5879_CPUFAN2

Current_IN0_Str		db	'Vcore  : ',0
Current_IN2_Str		db	'+3.3V  : ',0
Current_IN3_Str		db	'+ 5 V  : ',0
Current_IN4_Str		db	'+12 V  : ',0

;=====================

ifndef	No_CPU_Temp_Selectable
Show_Scale	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP				
		Post_Func_Call E000_Show_Scale
else	;SENSOR_IN_XGROUP				
		Xcall X_Show_Scale			
endif	;SENSOR_IN_XGROUP				
	@@:
		ret
Show_Scale	Endp
endif;	No_CPU_Temp_Selectable

Show_Temp1	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP				
		Post_Func_Call E000_Show_Temp1
else	;SENSOR_IN_XGROUP				
		Xcall 	X_Show_Temp1			
endif	;SENSOR_IN_XGROUP				
	@@:
		ret
Show_Temp1	Endp

Show_Temp2	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP
		Post_Func_Call E000_Show_Temp2
else	;SENSOR_IN_XGROUP
		Xcall 	X_Show_Temp2
endif	;SENSOR_IN_XGROUP
	@@:
		ret
Show_Temp2	Endp

ifndef	NO_SHOW_AliM5879_CPUFAN1
Show_Current_CPUFAN1	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP
		Post_Func_Call E000_Show_Current_CPUFAN1
else	;SENSOR_IN_XGROUP
		Xcall 	X_Show_Current_CPUFAN1
endif	;SENSOR_IN_XGROUP
	@@:
		
		ret
Show_Current_CPUFAN1	Endp
endif;	NO_SHOW_AliM5879_CPUFAN1

ifndef	NO_SHOW_AliM5879_CPUFAN2
Show_Current_CPUFAN2	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL		
		jne	short @F			       
ifndef	SENSOR_IN_XGROUP
		Post_Func_Call E000_Show_Current_CPUFAN2
else	;SENSOR_IN_XGROUP
		Xcall 	X_Show_Current_CPUFAN2
endif	;SENSOR_IN_XGROUP
	@@:							
		
		ret
Show_Current_CPUFAN2	Endp
endif;	NO_SHOW_AliM5879_CPUFAN2

Show_Current_IN0	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL		
		jne	short @F			       
ifndef	SENSOR_IN_XGROUP
		post_func_call	E000_Show_Current_IN0	
else	;SENSOR_IN_XGROUP
		Xcall	X_Show_Current_IN0
endif	;SENSOR_IN_XGROUP
	@@:							
		ret
Show_Current_IN0	Endp

Show_Current_IN2	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL		
		jne	short @F			       
ifndef	SENSOR_IN_XGROUP
		post_func_call	E000_Show_Current_IN2	
else	;SENSOR_IN_XGROUP
		Xcall	X_Show_Current_IN2
endif	;SENSOR_IN_XGROUP
	@@:							
		ret
Show_Current_IN2	Endp

Show_Current_IN3	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL		
		jne	short @F			       
ifndef	SENSOR_IN_XGROUP
		post_func_call	E000_Show_Current_IN3	
else	;SENSOR_IN_XGROUP
		Xcall	X_Show_Current_IN3
endif	;SENSOR_IN_XGROUP
	@@:							
		ret
Show_Current_IN3	Endp

Show_Current_IN4	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL		
		jne	short @F			       
ifndef	SENSOR_IN_XGROUP
		post_func_call	E000_Show_Current_IN4	
else	;SENSOR_IN_XGROUP
		Xcall	X_Show_Current_IN4
endif	;SENSOR_IN_XGROUP
	@@:							
		ret
Show_Current_IN4	Endp

ENDIF	;COMPILE_FOR_SENSOR_MNU

;***************************************************************************
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;***************************************************************************
IF	COMPILE_FOR_SENSOR_MNU EQ 3
IFNDEF	SENSOR_IN_XGROUP
Vin0_R1		equ	0
Vin0_R2		equ	0
Vin2_R1		equ	0
Vin2_R2		equ	0
Vin3_R1		equ	10
Vin3_R2		equ	30
Vin4_R1		equ	28
Vin4_R2		equ	10

ifndef	No_CPU_Temp_Selectable
E000_Show_Scale	Proc	Near
	     	extrn	E_GetItem_Value:near
		mov	si,offset DGROUP:CPU_TEMP_ITEM
		Post_func_Call	E_GetItem_Value

		mov	bl, al
		call	E000_DISP_WORD_INT3
		mov	al, 'ø'
		call	E000_Display_Char
		mov	al, 'C'
		call	E000_Display_Char
		mov	al, '/'
		call	E000_Display_Char

;øC transed to øF --> C = 5/9*(F-32)
		mov	al, bl
		mov	bl,9
		mul	bl
		mov	bl,5
		div	bl
		add	al,32
		xor	ah,ah
		call	E000_DISP_WORD_INT3
		mov	al, 'ø'
		call	E000_Display_Char
		mov	al, 'F'
		call	E000_Display_Char
  		sub 	al, -1			;set overflow flag for display error
		ret
E000_Show_Scale	Endp
endif;	No_CPU_Temp_Selectable

E000_Show_Temp1	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl, 4Eh
		call	E000_Get_AliM5879

		cmp	al,100
		jbe	short OK_78Temp1
		mov	al,0
	OK_78Temp1:

		mov	bl,al
		call	E000_DISP_Byte_INT2
		mov	al, 'ø'
		call	E000_Display_Char
		mov	al, 'C'
		call	E000_Display_Char
		mov	al, '/'
		call	E000_Display_Char

;øC transed to øF --> C = 5/9*(F-32)

		mov	al,bl
		mov	bl,9
		mul	bl
		mov	bl,5
		div	bl
		add	al,32
		xor	ah,ah
		call	E000_DISP_WORD_INT3
		mov	al, 'ø'
		call	E000_Display_Char
		mov	al, 'F'
		call	E000_Display_Char
	@@:
		ret
E000_Show_Temp1	Endp

E000_Show_Temp2	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl, 27h
		call	E000_Get_AliM5879

		cmp	al,100
		jbe	short OK_78Temp2
		mov	al,0
	OK_78Temp2:

		mov	bl,al
		call	E000_DISP_Byte_INT2
		mov	al, 'ø'
		call	E000_Display_Char
		mov	al, 'C'
		call	E000_Display_Char
		mov	al, '/'
		call	E000_Display_Char

;øC transed to øF --> C = 5/9*(F-32)

		mov	al,bl
		mov	bl,9
		mul	bl
		mov	bl,5
		div	bl
		add	al,32
		xor	ah,ah
		call	E000_DISP_WORD_INT3
		mov	al, 'ø'
		call	E000_Display_Char
		mov	al, 'F'
		call	E000_Display_Char
	@@:
		ret
E000_Show_Temp2	Endp

ifndef	NO_SHOW_AliM5879_CPUFAN1
E000_Show_Current_CPUFAN1	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,28h
		call	E000_Get_AliM5879
		cmp	al,0ffh
		jne	short CPUFAN_WORKING1
		xor	ax,ax
		jmp	short SHOW_FAN1
	CPUFAN_WORKING1:
		xor	bh,bh
		mov	bl,al
ifndef	FAN_Divisor				
     		mov	ax,5300h		;075300 = (960000/2)
		mov	dx,07h			;Count= (960000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,0A980h		;03A980 = (960000/4)
		mov	dx,03h			;Count = (960000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,0D4C0h		;01D4C0 = (960000/8)
		mov	dx,01h			;Count = (960000/(RPM*8))
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
		div	bx
   	SHOW_FAN1:
		call	E000_DISP_WORD_INT4
		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'R'
		call	E000_Display_Char
		mov	al, 'P'
		call	E000_Display_Char
		mov	al, 'M'
		call	E000_Display_Char
	@@:
		ret
E000_Show_Current_CPUFAN1	endp
endif;	NO_SHOW_AliM5879_CPUFAN1

ifndef	NO_SHOW_AliM5879_CPUFAN2
E000_Show_Current_CPUFAN2	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,29h
		call	E000_Get_AliM5879
		cmp	al,0ffh
		jne	short CPUFAN_WORKING2
		xor	ax,ax
		jmp	short SHOW_FAN2
	CPUFAN_WORKING2:
		xor	bh,bh
		mov	bl,al
ifndef	FAN_Divisor				
     		mov	ax,5300h		;075300 = (960000/2)
		mov	dx,07h			;Count= (960000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,0A980h		;03A980 = (960000/4)
		mov	dx,03h			;Count = (960000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,0D4C0h		;01D4C0 = (960000/8)
		mov	dx,01h			;Count = (960000/(RPM*8))
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
		div	bx
   	SHOW_FAN2:
		call	E000_DISP_WORD_INT4
		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'R'
		call	E000_Display_Char
		mov	al, 'P'
		call	E000_Display_Char
		mov	al, 'M'
		call	E000_Display_Char
	@@:
		ret
E000_Show_Current_CPUFAN2	endp
endif;	NO_SHOW_AliM5879_CPUFAN2

Display_Vin	Proc	Near

		cmp	al,0ffh			
		jne	short Vin_WORKING	
		xor	ax,ax			
	Vin_WORKING:				

		or	dx,dx			;Is above 4 Voltage
		jz	short Below4		;No, go to below 4V handler

		push	bx
		push	dx
		xor	ah,ah
		mov	bl,16			;(4080/255)
		mul	bl
	
		pop	bx			;(R1+R2)
		mul	bx

		pop	bx			;(R2)
		div	bx

		xor	dx,dx

		mov	bx,1000
		div	bx

		push	dx

		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9B
		call	E000_DISP_Byte_INT2
		jmp	short Above_9B
	Below_9B:
		call	E000_DISP_Byte_HEX2
	Above_9B:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret	

	Below4:
		xor	ah,ah
		mov	bx,16			;(4080/255)
		mul	bx
		mov	bx,1000
		div	bx
		push	dx

		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9A
		call	E000_DISP_Byte_INT2
		jmp	short Above_9A
	Below_9A:
		call	E000_DISP_Byte_HEX2
	Above_9A:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret
Display_Vin	endp

Display_NVin	Proc	Near

		cmp	al,0ffh			
		jne	short NVin_WORKING	
		xor	ax,ax			
	NVin_WORKING:				

		or	dx,dx			;Is above 4 Voltage
		jz	short NBelow4		;No, go to below 4V handler
		push	bx
		push	dx
		xor	ah,ah
		mov	bl,16			;(4080/255)
		mul	bl
		mov	bx, 3600
		sub	bx, ax
		mov	ax, bx
		pop	bx			;(R1+R2)
		mul	bx
		pop	bx			;(R2)
		div	bx
		sub	ax, 3600
		xor	dx,dx
		mov	bx,1000
		div	bx

		push	dx

		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short NBelow_9B
		call	E000_DISP_Byte_INT2
		jmp	short NAbove_9B
	NBelow_9B:
		call	E000_DISP_Byte_HEX2
	NAbove_9B:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret	

	NBelow4:
		xor	ah,ah
		mov	bx,16			;(4080/255)
		mul	bx
		mov	bx,1000
		div	bx
		push	dx

		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short NBelow_9A
		call	E000_DISP_Byte_INT2
		jmp	short NAbove_9A
	NBelow_9A:
		call	E000_DISP_Byte_HEX2
	NAbove_9A:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret
Display_NVin	endp

E000_Show_Current_IN0	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl, 22h			;IN0 VcoreA
		call	E000_Get_AliM5879
		add	al,2	

		mov	dx,(Vin0_R1+Vin0_R2)
		mov	bx,Vin0_R2

		call	Display_Vin
	@@:
		ret

E000_Show_Current_IN0	endp

E000_Show_Current_IN2	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl, 20h			;IN2 3.3Vin
		call	E000_Get_AliM5879
		add	al,2	

		mov	dx,(Vin2_R1+Vin2_R2)
		mov	bx,Vin2_R2

		call	Display_Vin
	@@:
		ret

E000_Show_Current_IN2	endp

E000_Show_Current_IN3	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl, 23h			;IN3 5Vin
		call	E000_Get_AliM5879
		add	al,2	

		mov	dx,(Vin3_R1+Vin3_R2)
		mov	bx,Vin3_R2

		call	Display_Vin
	@@:
		ret

E000_Show_Current_IN3	endp

E000_Show_Current_IN4	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl, 21h			;IN4 +12Vin
		call	E000_Get_AliM5879
		add	al,2	

		mov	dx,(Vin4_R1+Vin4_R2)
		mov	bx,Vin4_R2

		call	Display_Vin
	@@:
		ret

E000_Show_Current_IN4	endp

E000_DISP_WORD_INT4	proc	near
		F000_call	DISP_WORD_INT4
		ret
E000_DISP_WORD_INT4	endp

E000_DISP_WORD_INT3	proc	near
		F000_call	DISP_WORD_INT3
		ret
E000_DISP_WORD_INT3	endp

E000_DISP_BYTE_INT2	proc	near
		F000_call	DISP_BYTE_INT2
		ret
E000_DISP_BYTE_INT2	endp

E000_DISP_BYTE_HEX2	proc	near
		F000_call	DISP_BYTE_HEX2
		ret
E000_DISP_BYTE_HEX2	endp

E000_Get_AliM5879	proc	near
		call	Get_AliM5879
		ret
E000_Get_AliM5879	endp

E000_Set_AliM5879	proc	near
		call	Set_AliM5879
		ret
E000_Set_AliM5879	endp

E000_Display_Char	proc	near
		F000_call	Display_Char
		ret
E000_Display_Char	endp

ifndef	BIOS60	
		Public	Update_AliM5879_Screen
Update_AliM5879_Screen	Proc	near

		pusha

ifdef	Update_Sensor_in_CPUFEAT				
		cmp	byte ptr CUR_PAGE[bp], PAGE_CPU
else;	Update_Sensor_in_CPUFEAT
ifdef	Update_Sensor_in_IOFEAT					
		cmp	byte ptr CUR_PAGE[bp], PAGE_IO
else;	Update_Sensor_in_IOFEAT	
		cmp	byte ptr CUR_PAGE[bp], PAGE_CFEATURE
endif;	Update_Sensor_in_IOFEAT
endif;	Update_Sensor_in_CPUFEAT
		jne	short Update_AliM5879_end

	;----------------------------------------
		mov	si, offset AliM5879_Item_List

	Update_AliM5879_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_AliM5879_end
		push	si
		F000_call	Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_AliM5879_Start
	;----------------------------------------

	Update_AliM5879_end:

		popa
		ret

Update_AliM5879_Screen	Endp
endif	;BIOS60	

ifdef	BIOS60 
	db	'$SpeRT'
endif	;BIOS60

AliM5879_Item_List	Label	Word

ifdef	BIOS60 
	dw	AliM5879_Runtime_No
endif	;BIOS60

	dw	offset Temp1_Item
	dw	offset Temp2_Item
ifdef	SHOW_AliM5879_CPUFAN1
	dw	offset Current_CPUFAN1_Item
endif;	SHOW_AliM5879_CPUFAN1
ifdef	SHOW_AliM5879_CPUFAN2
	dw	offset Current_CPUFAN2_Item
endif;	SHOW_AliM5879_CPUFAN2
	dw	offset Current_IN0_Item
	dw	offset Current_IN2_Item
	dw	offset Current_IN3_Item
	dw	offset Current_IN4_Item

AliM5879_Runtime_No	EQU	(($ - offset AliM5879_Item_List)-2)/2	

	dw	-1

ENDIF	;SENSOR_IN_XGROUP			;R11
ENDIF	;COMPILE_FOR_SENSOR_MNU

IF	COMPILE_FOR_SENSOR_MNU EQ 4
	dw	offset First_AliM5879_Item, offset Last_AliM5879_Item
ifndef	SENSOR_IN_XGROUP
	dw	SEG Prg_AliM5879_Chip, offset Prg_AliM5879_Chip
else	;SENSOR_IN_XGROUP
	dw	SEG X_Prg_AliM5879_Chip, offset X_Prg_AliM5879_Chip
endif	;SENSOR_IN_XGROUP
ENDIF	;COMPILE_FOR_SENSOR_MNU

IF	COMPILE_FOR_SENSOR_MNU EQ 5
	extrn	First_AliM5879_Item:near
	extrn	Last_AliM5879_Item:near
ifndef	SENSOR_IN_XGROUP
	extrn	Prg_AliM5879_Chip:near
else	;SENSOR_IN_XGROUP
	extrn	X_Prg_AliM5879_Chip:far
endif	;SENSOR_IN_XGROUP
ENDIF	;COMPILE_FOR_SENSOR_MNU

endif	;COMPILE_FOR_SENSOR_MNU 


;==================================================================
;======================== SENSOR IN XGROUP ========================
;======================== SENSOR IN XGROUP ========================
;======================== SENSOR IN XGROUP ========================
;======================== SENSOR IN XGROUP ========================
;==================================================================

ifdef	COMPILE_FOR_SENSOR_ASM
IF	COMPILE_FOR_SENSOR_ASM EQ 2
ifdef	SENSOR_IN_XGROUP			

		public	X_Get_AliM5879_Byte
		public	X_Set_AliM5879_Byte
		public	X_Get_AliM5879_Word
		public	X_Set_AliM5879_Word
		extrn	X_GetItem_Value:near

X_Get_AliM5879_Byte	Proc	Near
			call far ptr	EGROUP:fproc_Ct_I2CReadByte
			ret
X_Get_AliM5879_Byte	ENDP

X_Set_AliM5879_Byte	Proc	Near
			call far ptr	EGROUP:fproc_Ct_I2CWriteByte
			ret
X_Set_AliM5879_Byte	ENDP

X_Get_AliM5879_Word	Proc	Near
			call far ptr	EGROUP:fproc_Ct_I2CReadWord
			ret
X_Get_AliM5879_Word	ENDP

X_Set_AliM5879_Word	Proc	Near
			call far ptr	EGROUP:fproc_Ct_I2CWriteWord
			ret
X_Set_AliM5879_Word	ENDP

		public	X_Get_AliM5879
		public	X_Set_AliM5879
X_Get_AliM5879	Proc	Near

		pushf
		push	dx
		mov	ch, 5ah			
		Call	X_Get_AliM5879_Byte	
		pop	dx
		popf

		ret
X_Get_AliM5879	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
X_Set_AliM5879	Proc	Near

		pushf
		push	dx
		mov	ch, 5ah			
		Call	X_Set_AliM5879_Byte	
		pop	dx
		popf

		ret
X_Set_AliM5879	Endp

ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		extrn	TEMP1_HIGH:near		
		extrn	SENSOR_FLAG:near
;[]========================================================================[]
;Procedure:	X_Ct_FillTempPointer
;
;Function :	Return Thermal Zone Temperature pointer 
;
;Input	  :	F segment shadow RAM is writeable 
;
;Output   :	none
;	
;[]========================================================================[]
		Public	X_Ct_FillTempPointer
X_Ct_FillTempPointer	Proc	far

		push	es
		
		mov	ax,0f000h
		mov	es,ax
		mov	di,offset DGROUP:SENSOR_FLAG
		test	word ptr es:[di],01h
		jz	short No_Sensor
		mov	di,offset DGROUP:TEMP1_HIGH

		extrn	CPU_TEMP_ITEM:near
		mov	si,offset DGROUP:CPU_TEMP_ITEM
		call	X_GetItem_Value
		push	ax
		mov	si,offset DGROUP:ACPI_Critical_Item
		call	X_GetItem_Value
		xor	ah,ah
		shl	ax,1
		mov	si,offset Critical_Table
		add	si,ax
		mov	ax,word ptr cs:[si]
		mov	word ptr es:[di+8],ax	;Critical trip point
		sub	ax, 2732
		mov	bl, 10
		div	bl
		pop	bx
ifdef	No_CPU_Temp_Selectable
		mov	si,offset CPU_TEMP_Tbl	
		xor	bh,bh			
		add	si,bx			
		mov	bl,cs:[si]		
endif;	No_CPU_Temp_Selectable
		cmp	bl,al 			;al is shutdown temp.
		jbe	short	@F
		mov	bl, al
	@@:
		mov	al, bl
		mov	cl,10
		mul	cl
		add	ax,2732

		mov	word ptr es:[di],ax	; Trip point 1 high
		mov	word ptr es:[di+4],ax	; Trip point 2 high
		sub	ax,30
		mov	word ptr es:[di+2],ax	; Trip point 1 low
		mov	word ptr es:[di+6],ax	; Trip point 2 low


No_Sensor:					
		pop	es
		retf
X_Ct_FillTempPointer	Endp

Critical_Table:

		dw	3332			;60c		
		dw	3382			;65c		
		dw	3432			;70c		
		dw	3482			;75c		

endif	;ACPI_Support

;***************************************************************************
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;**** SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM SENSOR.ASM ****
;***************************************************************************

;[]==============================================================[]
;[]==============================================================[]
		Public	X_Prg_AliM5879_Chip	
X_Prg_AliM5879_Chip	Proc	far

 	;Hide AliM5879's display items if it is not mounted on M/B.
		mov	cl,48h
		call	X_Get_AliM5879
		cmp	al,2dh
		je	short @F

		push	ds
		mov	ax,0f000h
		mov	ds,ax

		extrn	CPU_Temp_Item:near
		extrn	Temp1_Item:near
		extrn	Temp2_Item:near
ifdef	SHOW_AliM5879_CPUFAN1
		extrn	Current_CPUFAN1_Item:near
endif;	SHOW_AliM5879_CPUFAN1
ifdef	SHOW_AliM5879_CPUFAN2
		extrn	Current_CPUFAN2_Item:near
endif;	SHOW_AliM5879_CPUFAN2
		extrn	Current_IN0_Item:near
		extrn	Current_IN2_Item:near
		extrn	Current_IN3_Item:near
		extrn	Current_IN4_Item:near
		extrn	X_F000_Shadow_W:near
		extrn	X_F000_Shadow_R:near
		assume	ds:DGROUP
		call	X_F000_Shadow_W
		or	word ptr ds:[CPU_Temp_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Temp1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Temp2_Item].ITEMSTAT,ITEMDISABLE
ifdef	SHOW_AliM5879_CPUFAN1
		or	word ptr ds:[Current_CPUFAN1_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_AliM5879_CPUFAN1
ifdef	SHOW_AliM5879_CPUFAN2
		or	word ptr ds:[Current_CPUFAN2_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_AliM5879_CPUFAN2
		or	word ptr ds:[Current_IN0_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_IN2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_IN3_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_IN4_Item].ITEMSTAT,ITEMDISABLE
ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		or	word ptr ds:[ACPI_Critical_Item].ITEMSTAT,ITEMDISABLE
endif;	ACPI_Support

ifdef	ACPI_SUPPORT
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT
		call	X_F000_Shadow_R
		pop	ds
		jmp	Prg_AliM5879_Chip_End
	@@:

		mov	cx,10
	Clear_AliM5879:
		push	cx
		mov	cl,41h
		call	X_Get_AliM5879
		mov	cl,42h
		call	X_Get_AliM5879
		pop	cx
		loop	short Clear_AliM5879

		mov	si,offset XGROUP:Prg_AliM5879_Tbl
	Init_Start:
		mov	cl,cs:[si]
		call	X_Get_AliM5879

		mov	cl,cs:[si]
		and	al,cs:[si+1]
		or	al,cs:[si+2]
		call	X_Set_AliM5879
		add	si,3

		cmp	si,offset XGROUP:Prg_AliM5879_Tbl_End
		jne	short Init_Start

		mov	si,offset DGROUP:CPU_Temp_Item
		call	X_GetItem_Value
		push	ax
ifdef	ACPI_Support
		mov	si,offset DGROUP:ACPI_Critical_Item
		call	X_GetItem_Value
		xor	ah,ah
		shl	ax,1
		mov	si,offset Critical_Table
		add	si,ax
		mov	ax,word ptr cs:[si]
		sub	ax, 2732
		mov	bl, 10
		div	bl
else;	ACPI_Support
		mov	al, 80			;max. Warning temp.
endif;	ACPI_Support
		pop	bx
ifdef	No_CPU_Temp_Selectable			
		mov	si,offset CPU_TEMP_Tbl	
		xor	bh,bh			
		add	si,bx			
		mov	bl,cs:[si]		
endif;	No_CPU_Temp_Selectable
		push	bx
		cmp	bl,al 			;al is shutdown temp.
		jbe	short	@F

		mov	cl,4ch
		call	X_Get_AliM5879
		or	al,00001000b		;Disable OVT Pin
		mov	cl,4ch
		call	X_Set_AliM5879

		mov	cl,40h
		call	X_Get_AliM5879
		and	al,not 00000010b	;Disable SMI Pin
		mov	cl,40h
		call	X_Set_AliM5879

		mov	cl,56h
		call	X_Get_AliM5879
		and	al,not 00100000b	;disable CPU temp. beep
		mov	cl,56h
		call	X_Set_AliM5879
	@@:
		pop	ax

		push	ax
		push	ax

	;Program CPU1 (sensor2)
		pop	ax
		mov	cx,9203h
		call	X_Set_AliM5879_Word	;set Tos (High limit)

		pop	ax
		sub	al,5
		mov	cx,9202h
		call	X_Set_AliM5879_Word	;set Thyst (Low limit)

ifdef	Thermal_Enable_Use_SMI
		mov	al,02h			;interrupt mode
else;	Thermal_Enable_Use_SMI
		mov	al,0			;comparator mode
endif;	Thermal_Enable_Use_SMI
		mov	cx,9201h
		call	X_Set_AliM5879_Byte

		mov	cl,56h
		call	X_Get_AliM5879
		or	al,00100000b		;enable CPU temp. beep
		mov	cl,56h
		call	X_Set_AliM5879

Prg_AliM5879_Chip_End:

		retf

X_Prg_AliM5879_Chip	Endp

		assume	ds:XGROUP
ifdef	No_CPU_Temp_Selectable
CPU_TEMP_Tbl:
		db	0120	;disabled
		db	032h	;50C
		db	035h	;53C
		db	038h	;56C
		db	03ch	;60C
		db	03fh	;63C
		db	042h	;66C
		db	046h	;70C
ifdef INTEL_M2_CPU_Temprature_Rang
		db	04Bh	;75C
		db	050h	;80C
		db	055h	;85C
		db	05Ah	;90C
		db	05Fh	;95C
endif; INTEL_M2_CPU_Temprature_Rang
endif;	No_CPU_Temp_Selectable

		ALIGN	4
		;---------------------------
		;      index  	and	or
		;---------------------------
Prg_AliM5879_Tbl:
		db	40h,	00h,	080h
		db	43h,	00h,	0FFh
		db	47h,	0Fh,	050h
		db	40h,	00h,	001h
		db	4ch,	00h,	0FFh
		db	4Ah,	00h,	008h
Prg_AliM5879_Tbl_End:

endif	;SENSOR_IN_XGROUP		
ENDIF	;COMPILE_FOR_SENSOR_ASM EQ 2
endif	;COMPILE_FOR_SENSOR_ASM

;***************************************************************************
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;**** SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  SENSOR.E8  ****
;***************************************************************************
IFDEF	COMPILE_FOR_SENSOR_MNU 
IF	COMPILE_FOR_SENSOR_MNU EQ 3
IFDEF	SENSOR_IN_XGROUP	
Vin0_R1		equ	0
Vin0_R2		equ	0
Vin2_R1		equ	0
Vin2_R2		equ	0
Vin3_R1		equ	68
Vin3_R2		equ	100
Vin4_R1		equ	28
Vin4_R2		equ	10

ifndef	No_CPU_Temp_Selectable
X_Show_Scale	Proc	Near
	     	extrn	X_GetItem_Value:near
		mov	si,offset DGROUP:CPU_TEMP_ITEM
		call	X_GetItem_Value

		mov	bl, al
		call far ptr	DGROUP:fproc_DISP_WORD_INT3
		mov	al, 'ø'
		call	X_Display_Char
		mov	al, 'C'
		call	X_Display_Char
		mov	al, '/'
		call	X_Display_Char

;øC transed to øF --> C = 5/9*(F-32)
		mov	al, bl
		mov	bl,9
		mul	bl
		mov	bl,5
		div	bl
		add	al,32
		xor	ah,ah
		call far ptr	DGROUP:fproc_DISP_WORD_INT3
		mov	al, 'ø'
		call	X_Display_Char
		mov	al, 'F'
		call	X_Display_Char
  		sub 	al, -1			;set overflow flag for display error
		ret
X_Show_Scale	Endp
endif;	No_CPU_Temp_Selectable

X_Show_Temp1	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl, 4Eh
		call	X_Get_AliM5879

		cmp	al,100
		jbe	short OK_78Temp1
		mov	al,0
	OK_78Temp1:

		mov	bl,al
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		mov	al, 'ø'
		call	X_Display_Char
		mov	al, 'C'
		call	X_Display_Char
		mov	al, '/'
		call	X_Display_Char

;øC transed to øF --> C = 5/9*(F-32)

		mov	al,bl
		mov	bl,9
		mul	bl
		mov	bl,5
		div	bl
		add	al,32
		xor	ah,ah
		call far ptr	DGROUP:fproc_DISP_WORD_INT3
		mov	al, 'ø'
		call	X_Display_Char
		mov	al, 'F'
		call	X_Display_Char
	@@:
		ret
X_Show_Temp1	Endp

X_Show_Temp2	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl, 27h
		call	X_Get_AliM5879

		cmp	al,100
		jbe	short OK_78Temp2
		mov	al,0
	OK_78Temp2:

		mov	bl,al
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		mov	al, 'ø'
		call	X_Display_Char
		mov	al, 'C'
		call	X_Display_Char
		mov	al, '/'
		call	X_Display_Char

;øC transed to øF --> C = 5/9*(F-32)

		mov	al,bl
		mov	bl,9
		mul	bl
		mov	bl,5
		div	bl
		add	al,32
		xor	ah,ah
		call far ptr	DGROUP:fproc_DISP_WORD_INT3
		mov	al, 'ø'
		call	X_Display_Char
		mov	al, 'F'
		call	X_Display_Char
	@@:
		ret
X_Show_Temp2	Endp

ifndef	NO_SHOW_AliM5879_CPUFAN1
X_Show_Current_CPUFAN1	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,28h
		call	X_Get_AliM5879
		cmp	al,0ffh
		jne	short CPUFAN_WORKING1
		xor	ax,ax
		jmp	short SHOW_FAN1
	CPUFAN_WORKING1:
		xor	bh,bh
		mov	bl,al
ifndef	FAN_Divisor				
     		mov	ax,5300h		;075300 = (960000/2)
		mov	dx,07h			;Count= (960000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,0A980h		;03A980 = (960000/4)
		mov	dx,03h			;Count = (960000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,0D4C0h		;01D4C0 = (960000/8)
		mov	dx,01h			;Count = (960000/(RPM*8))
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
		div	bx
   	SHOW_FAN1:
		call far ptr	DGROUP:fproc_DISP_WORD_INT4
		mov	al, ' '
		call	X_Display_Char
		mov	al, 'R'
		call	X_Display_Char
		mov	al, 'P'
		call	X_Display_Char
		mov	al, 'M'
		call	X_Display_Char
	@@:
		ret
X_Show_Current_CPUFAN1	endp
endif;	NO_SHOW_AliM5879_CPUFAN1

ifndef	NO_SHOW_AliM5879_CPUFAN2
X_Show_Current_CPUFAN2	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,29h
		call	X_Get_AliM5879
		cmp	al,0ffh
		jne	short CPUFAN_WORKING2
		xor	ax,ax
		jmp	short SHOW_FAN2
	CPUFAN_WORKING2:
		xor	bh,bh
		mov	bl,al
ifndef	FAN_Divisor				
     		mov	ax,5300h		;075300 = (960000/2)
		mov	dx,07h			;Count= (960000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,0A980h		;03A980 = (960000/4)
		mov	dx,03h			;Count = (960000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,0D4C0h		;01D4C0 = (960000/8)
		mov	dx,01h			;Count = (960000/(RPM*8))
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
		div	bx
   	SHOW_FAN2:
		call far ptr	DGROUP:fproc_DISP_WORD_INT4
		mov	al, ' '
		call	X_Display_Char
		mov	al, 'R'
		call	X_Display_Char
		mov	al, 'P'
		call	X_Display_Char
		mov	al, 'M'
		call	X_Display_Char
	@@:
		ret
X_Show_Current_CPUFAN2	endp
endif;	NO_SHOW_AliM5879_CPUFAN2

X_Display_Vin	Proc	Near

		cmp	al,0ffh			
		jne	short Vin_WORKING	
		xor	ax,ax			
	Vin_WORKING:				

		or	dx,dx			;Is above 4 Voltage
		jz	short Below4		;No, go to below 4V handler

		push	bx
		push	dx
		xor	ah,ah
		mov	bl,16			;(4080/255)
		mul	bl
	
		pop	bx			;(R1+R2)
		mul	bx

		pop	bx			;(R2)
		div	bx

		xor	dx,dx

		mov	bx,1000
		div	bx

		push	dx

		call far ptr	DGROUP:fproc_DISP_Byte_INT2

		mov	al, '.'
		call	X_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9B
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Above_9B
	Below_9B:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Above_9B:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret	

	Below4:
		xor	ah,ah
		mov	bx,16			;(4080/255)
		mul	bx
		mov	bx,1000
		div	bx
		push	dx

		call far ptr	DGROUP:fproc_DISP_Byte_INT2

		mov	al, '.'
		call	X_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9A
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Above_9A
	Below_9A:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Above_9A:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret
X_Display_Vin	endp

X_Display_NVin	Proc	Near

		cmp	al,0ffh			
		jne	short NVin_WORKING	
		xor	ax,ax			
	NVin_WORKING:				

		or	dx,dx			;Is above 4 Voltage
		jz	short NBelow4		;No, go to below 4V handler
		push	bx
		push	dx
		xor	ah,ah
		mov	bl,16			;(4080/255)
		mul	bl
		mov	bx, 3600
		sub	bx, ax
		mov	ax, bx
		pop	bx			;(R1+R2)
		mul	bx
		pop	bx			;(R2)
		div	bx
		sub	ax, 3600
		xor	dx,dx
		mov	bx,1000
		div	bx

		push	dx

		call far ptr	DGROUP:fproc_DISP_Byte_INT2

		mov	al, '.'
		call	X_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short NBelow_9B
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short NAbove_9B
	NBelow_9B:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	NAbove_9B:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret	

	NBelow4:
		xor	ah,ah
		mov	bx,16			;(4080/255)
		mul	bx
		mov	bx,1000
		div	bx
		push	dx

		call far ptr	DGROUP:fproc_DISP_Byte_INT2

		mov	al, '.'
		call	X_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short NBelow_9A
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short NAbove_9A
	NBelow_9A:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	NAbove_9A:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret
X_Display_NVin	endp

X_Show_Current_IN0	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,20h			;IN0 VcoreA
		call	X_Get_AliM5879
		add	al,2	

		mov	dx,(Vin0_R1+Vin0_R2)
		mov	bx,Vin0_R2

		call	X_Display_Vin
	@@:
		ret

X_Show_Current_IN0	endp

X_Show_Current_IN2	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,22h			;IN2 3.3Vin
		call	X_Get_AliM5879
		add	al,2	

		mov	dx,(Vin2_R1+Vin2_R2)
		mov	bx,Vin2_R2

		call	X_Display_Vin
	@@:
		ret

X_Show_Current_IN2	endp

X_Show_Current_IN3	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,23h			;IN3 5Vin
		call	X_Get_AliM5879
		add	al,2	

		mov	dx,(Vin3_R1+Vin3_R2)
		mov	bx,Vin3_R2

		call	X_Display_Vin
	@@:
		ret

X_Show_Current_IN3	endp

X_Show_Current_IN4	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,24h			;IN4 +12Vin
		call	X_Get_AliM5879
		add	al,2	

		mov	dx,(Vin4_R1+Vin4_R2)
		mov	bx,Vin4_R2

		call	X_Display_Vin
	@@:
		ret

X_Show_Current_IN4	endp

ifndef	BIOS60	
		Public	X_Update_AliM5879_Screen
X_Update_AliM5879_Screen	Proc	far

		pusha

ifdef	Update_Sensor_in_CPUFEAT				
		cmp	byte ptr CUR_PAGE[bp], PAGE_CPU
else;	Update_Sensor_in_CPUFEAT
ifdef	Update_Sensor_in_IOFEAT					
		cmp	byte ptr CUR_PAGE[bp], PAGE_IO
else;	Update_Sensor_in_IOFEAT	
		cmp	byte ptr CUR_PAGE[bp], PAGE_CFEATURE
endif;	Update_Sensor_in_IOFEAT
endif;	Update_Sensor_in_CPUFEAT
		jne	short Update_AliM5879_end

	;----------------------------------------
		mov	si, offset AliM5879_Item_List

	Update_AliM5879_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_AliM5879_end
		push	si
		call	X_Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_AliM5879_Start
	;----------------------------------------

	Update_AliM5879_end:

		popa
		retf

X_Update_AliM5879_Screen	Endp
endif	;BIOS60	

ifdef	BIOS60 
	db	'$SpeRT'
endif	;BIOS60

AliM5879_Item_List	Label	Word

ifdef	BIOS60 
	dw	AliM5879_Runtime_No
endif	;BIOS60

	dw	offset Temp1_Item
	dw	offset Temp2_Item
ifdef	SHOW_AliM5879_CPUFAN1
	dw	offset Current_CPUFAN1_Item
endif;	SHOW_AliM5879_CPUFAN1
ifdef	SHOW_AliM5879_CPUFAN2
	dw	offset Current_CPUFAN2_Item
endif;	SHOW_AliM5879_CPUFAN2
	dw	offset Current_IN0_Item
	dw	offset Current_IN2_Item
	dw	offset Current_IN3_Item
	dw	offset Current_IN4_Item

AliM5879_Runtime_No	EQU	(($ - offset AliM5879_Item_List)-2)/2	

	dw	-1

ENDIF	;SENSOR_IN_XGROUP			
ENDIF	;COMPILE_FOR_SENSOR_MNU
ENDIF	;COMPILE_FOR_SENSOR_MNU

