;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R16	02/03/99 PHI	Move sensor code to XGROUP.  
;			Please use define SENSOR_IN_XGROUP.
;R15	10/09/98 PAL	Move all the SMbus of the chipset and use the chipset
;			standard I2C code in CHIPPOST.ASM
;R14	09/28/98 PAL	Fix coding error
;R13	09/18/98 PAL	Move VIA SMbus to sensor.asm
;R12	09/10/98 PAL	Move Sis SMbus to sensor.asm
;R11	09/03/98 LAW	Fixed MAX1617 work with M1543/M1543C not well
;R10	09/03/98 TNY	Support structure for setup string moving to X-Group.
;R09	08/04/98 PAL	Added Dual Max1617 
;R08	07/03/98 RIC	Fixed that CPU Temperature always was showed Zero in
;			VIA VT596 chipset.
;R07	07/01/98 RIC	Add VIA SMBus Support.
;R06	05/20/98 PAL	Disable Critical temp and Warning temp item when sensor
;			not exist
;R05	05/15/98 PAL	Change Critical temp range for fitting ACPI HCT testing
;R04	05/11/98 TNY	Add "Update_Sensor_in_CPUFEAT" option.
;R03	05/08/98 PAL	Added sensor chip auto detection function for ACPI
;R02	04/28/98 PAL	Fixed fill error
;R01	04/24/98 RAY	Add macro definition for supporting BIOS 6.0
;			"DEFINE_MENUITEM" is a dummy macro in BIOS 4.51 & 4.6
;R00	04/21/98 PAL	Initial version
;[]==============================================================[]
;MAX1617_Support	: Max1617 sensor support
;MAX1617_CMOS		: Max1617 cmos location
;MAX1617_ID		: Max1617 device ID for SMBus
;CPU_Temp_Selectable	: Select CPU Warning Temp by per scale
;MAX1617_ACPI_CMOS	: Use ACPI Shutdown temp cmos location
;MAX1617_ACPI_CMOS_Bits	: Use ACPI cmos 3 bits
;Thermal_Enable		: Slow down speed
;[]==============================================================[]
ifdef	COMPILE_FOR_SENSOR_ASM
IF	COMPILE_FOR_SENSOR_ASM EQ 2
ifndef	SENSOR_IN_XGROUP			;R16

;R15 - start
ifndef		MAX1617_ID				
MAX1617_ID         EQU     30H
endif;		MAX1617_ID
		public	Get_MAX1617_Byte
		public	Set_MAX1617_Byte
		public	Get_MAX1617_Word
		public	Set_MAX1617_Word
		extrn	Ct_I2CReadByte:near
		extrn	Ct_I2CWriteByte:near
		extrn	Ct_I2CReadWord:near
		extrn	Ct_I2CWriteWord:near
Get_MAX1617_Byte	Proc	Near
	mov	ch, MAX1617_ID
	call	Ct_I2CReadByte
			ret
Get_MAX1617_Byte	ENDP
Set_MAX1617_Byte	Proc	Near
	mov	ch, MAX1617_ID
	call	Ct_I2CWriteByte
			ret
Set_MAX1617_Byte	ENDP
Get_MAX1617_Word	Proc	Near
	mov	ch, MAX1617_ID
	call	Ct_I2CReadWord
			ret
Get_MAX1617_Word	ENDP

Set_MAX1617_Word	Proc	Near
	mov	ch, MAX1617_ID
	call	Ct_I2CWriteWord
			ret
Set_MAX1617_Word	ENDP
;R15 - end
comment	%				;R15
ifdef	PIIX_ID					

;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_MAX1617_Byte
		public	Set_MAX1617_Byte
Get_MAX1617_Byte	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(MAX1617_ID + 1)	;MAX1617 read cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;read data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
Get_MAX1617_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_MAX1617_Byte	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,MAX1617_ID		;MAX1617 write cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,05
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		ret
Set_MAX1617_Byte	Endp

endif;	PIIX_ID
ifdef	M1543
;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_MAX1617_Byte
		public	Set_MAX1617_Byte
Get_MAX1617_Byte	Proc	Near

		push	cx

		call	Wait_SMBUS_Idle_Status	;R11

		mov	dx,SMBus_Port +03h
		mov	al,(MAX1617_ID + 1)	;MAX1617 read cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		mov	dl,01h
		mov	al,20h
		out	dx,al			;read data
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,07h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,0ffh
		out	dx,al			;starting access
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY 

		mov	dl,04
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
Get_MAX1617_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_MAX1617_Byte	Proc	Near

		push	ax
		push	cx

		call	Wait_SMBUS_Idle_Status	;R11

		mov	dx,SMBus_Port +03h
		mov	al,MAX1617_ID		;MAX1617 write cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		mov	dl,01h
		mov	al,20h
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,07h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,04h
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,0ffh
		out	dx,al			;starting access
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		ret
Set_MAX1617_Byte	Endp

;R11 - start
		Public	Wait_SMBUS_Idle_Status
Wait_SMBUS_Idle_Status	Proc Near
		mov	cx, 01000h
	Wait_SMBus_Idle_Status_loop:
		mov	dx, SMBus_Port + 0
		mov	al, 0ffh
		out	dx, al

		in	al, dx			;get status
		test	al, 04h
		jnz	short Clear_final
		loop	short Wait_SMBus_Idle_Status_Loop
	Clear_final:
		ret
Wait_SMBUS_Idle_Status	EndP
;R11 - end
endif;	M1543

ifdef   VT586_ACPI		; VIA Chipset
  IF		VIA_SMBus	EQ	0		;R07

;R13ifdef	SDA_In_GPIO1
;R13SDA             EQU     02	;GPIO1 Data
;R13SCL             EQU     04	;GPIO2 Clock
;R13else;	SDA_In_GPIO1
;R13SDA             EQU     04	;GPIO2 Data (Normal)
;R13SCL             EQU     02	;GPIO1 Clock
;R13endif;	SDA_In_GPIO1

ifndef		MAX1617_ID				
MAX1617_ID         EQU     30H
endif;		MAX1617_ID				

;R13GPIO_Dir        EQU     ACPI_Port+40h
;R13GPIO_WPort      EQU     ACPI_Port+42h
;R13GPIO_RdPort     EQU     ACPI_Port+44h
;R13
;R13		extrn	Dir_Out:Near
;R13		extrn	Set_Start:Near
;R13		extrn	Wr_Byte:Near
;R13		extrn	Wait_ACK:Near
;R13		extrn	Set_Stop:Near
;R13		extrn	E000_Get_PMIO:near		
;R13		extrn	E000_Set_PMIO:near		
;R13		extrn	E000_Get_Set_PMIO:near		
;R13		extrn	E000_Get_Set_PMIO_OR:near	
;R13		extrn	E000_Get_Set_PMIO_AND:near	
;R13;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R13;º  Set_Pointer                                                             º
;R13;º  Input:  BX = pointer                                                    º
;R13;º  Output: CLC = PK                                                        º
;R13;º          STC = Fail                                                      º
;R13;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R13Set_Pointer     proc
;R13        push    bx              ;Save Register Pointer
;R13        call    Dir_Out
;R13        call    Set_Start
;R13        mov     bl,MAX1617_ID
;R13        call    Wr_Byte
;R13        call    Wait_ACK
;R13        pop     bx
;R13        jc      ErrSet_Pointer
;R13        call    Wr_Byte         ;bx = pointer
;R13        call    Wait_ACK
;R13;Frank  call    Wait_ACK0
;R13        jc      ErrSet_Pointer
;R13        clc
;R13        ret
;R13ErrSet_Pointer:
;R13        stc
;R13        ret
;R13Set_Pointer     endp
;R13
;R13;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R13;º  Rd_Data                                                                 º
;R13;º                                                                          º
;R13;º  Input:  None                                                            º
;R13;º  Output: BL: return data                                                 º
;R13;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R13Rd_Data proc
;R13        mov     cx,40h           
;R13        mov     bl, NOT SDA	 
;R13	mov	bh, SCL		 
;R13        call    E000_Get_Set_PMIO
;R13
;R13        xor     bx, bx          ;Frank
;R13        xor     ax, ax
;R13        mov     cx, 8
;R13Rd_byte:
;R13        push    cx
;R13        mov     cx, 8                           ;T(low) = 4.7 us
;R13@@:
;R13        out     0ebh, al
;R13        loop    short @B
;R13
;R13
;R13
;R13
;R13
;R13
;R13        mov     dx,GPIO_WPort		
;R13	in	al, dx			
;R13        or      al, SCL			
;R13        out     dx, al                  ;SCL high, receiver will read data
;R13        mov     cx, 8                   ;T(high) = 4 us
;R13@@:
;R13        out     0ebh, al
;R13        loop    short @B
;R13
;R13        mov     cx,44h	     
;R13        call    E000_Get_PMIO
;R13
;R13        and     al, SDA 
;R13ifdef	SDA_In_GPIO1
;R13        shr     al, 1		;;if SDA=02h, SCL=04h
;R13else;	SDA_In_GPIO1
;R13        shr     al, 2		;;if SDA=04h, SCL=02h
;R13endif;	SDA_In_GPIO1
;R13        shl     bl, 1           
;R13        or      bl, al
;R13
;R13		mov     dx, GPIO_WPort
;R13		in	al, dx	      
;R13		and     al, NOT SCL   	;SCL low
;R13		out	dx, al	      
;R13
;R13        pop     cx
;R13        loop    Rd_byte
;R13
;R13        mov     cx, 8                           ;T(hd)
;R13@@:
;R13        out     0ebh, al
;R13        loop    short @B
;R13
;R13        mov     dx,GPIO_Dir
;R13        in      al, dx	   
;R13        or      al, SDA	   
;R13        or      al, SCL	   
;R13        out     dx, al     			;Set SCL O/P , SDA I/P
;R13
;R13        ret
;R13Rd_Data endp
;R13
;R13
;R13;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R13;º  Set_NoACK                                                               º
;R13;º                                                                          º
;R13;º  Input:  None                                                            º
;R13;º  Output: None                                                            º
;R13;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R13Set_NoACK       proc
;R13        mov     dx,GPIO_WPort
;R13        in      al, dx	     
;R13        and     al, NOT SCL  
;R13        or      al, SDA	     
;R13        out     dx, al       		;out No ACK
;R13
;R13        out     0ebh, al                ;T(setup) = 250 ns
;R13
;R13        or      al, SCL
;R13        out     dx, al                  ;SCL ,SDA = high
;R13        mov     cx, 8                   ;T(high) = 4 us
;R13@@:
;R13        out     0ebh, al
;R13        loop    short @B
;R13
;R13        and     al, NOT SCL
;R13        out     dx, al                  ;SCL = low
;R13        out     0ebh, al
;R13
;R13        and     al, NOT SDA
;R13        out     dx, al                  ;SDA = low
;R13        out     0ebh, al
;R13
;R13        ret
;R13Set_NoACK       endp
;R13
;R13;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R13;º  Set_ACK                                                                 º
;R13;º                                                                          º
;R13;º  Input:  None                                                            º
;R13;º  Output: None                                                            º
;R13;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R13Set_ACK proc
;R13        mov     cx,42h               
;R13	in	al, dx		     
;R13        mov     bl, NOT SCL          
;R13        and	bl, NOT SDA	     
;R13        call    E000_Get_Set_PMIO_AND
;R13
;R13        out     0ebh, al                ;T(setup) = 250 ns
;R13
;R13	mov	dx,GPIO_WPort		
;R13        or      al, SCL
;R13        out     dx, al                  ;SCL ,SDA = high
;R13        mov     cx, 8                   ;T(high) = 4 us
;R13@@:
;R13        out     0ebh, al
;R13        loop    short @B
;R13        and     al, NOT SCL
;R13        out     dx, al                  ;SCL = low
;R13        out     0ebh, al
;R13
;R13        and     al, NOT SDA
;R13        out     dx, al                  ;SDA = low
;R13        out     0ebh, al
;R13        ret
;R13Set_ACK endp


;[]==============================================================[]
;Input  : CL - register index
;Output : AL - Value read
;[]==============================================================[]
                public  Get_MAX1617_Byte
                public  Set_MAX1617_Byte
                public  Get_MAX1617_Word
                public  Set_MAX1617_Word
Get_MAX1617_Byte   Proc    Near
        mov     ch,MAX1617_ID		;R13
        mov     bl,cl
        call    Set_Pointer
        NEWIODELAY
        NEWIODELAY
        call    Set_Start
        mov     bl,MAX1617_ID
        inc     bl              ;for read operation
        call    Wr_Byte
        call    Wait_ACK
        jc      Rd_1ByteReg_Fail
        call    Rd_Data         ;bl = data
        shl     ebx,16
        call    Set_NoACK
        call    Set_Stop
        shr     ebx,16
        xor     bh,bh   ;BL = value
        mov     al,bl
        clc
        ret
Rd_1ByteReg_Fail:
        stc
        ret

Get_MAX1617_Byte   Endp

;[]==============================================================[]
;Input : CL - register index
;        AL - Value to write
;Output: none
;[]==============================================================[]
Set_MAX1617_Byte   Proc    Near
        push    ax      
        mov     bl,cl
        cli
	mov	ch, MAX1617_ID		;R13
        call    Set_Pointer
        newiodelay
        newiodelay
        pop     ax      
        mov     bl,al
        call    Wr_Byte
        call    Wait_ACK
        jc      Wr_1ByteReg_Fail
        call    Set_Stop
        clc
        sti
        ret
Wr_1ByteReg_Fail:
        stc
        sti
        ret
Set_MAX1617_Byte   Endp

  ENDIF;	VIA_SMBus	EQ	0		;R07
endif;	VT586_ACPI

;R07 - starts
if	VIA_SMBus

;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_MAX1617_Byte
		public	Set_MAX1617_Byte
Get_MAX1617_Byte	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(MAX1617_ID + 1)	;MAX1617 read cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;read data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
Get_MAX1617_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_MAX1617_Byte	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,MAX1617_ID		;MAX1617 write cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,05
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		ret
Set_MAX1617_Byte	Endp

endif;	VIA_SMBus
;R07 - ends
;R12 - start
;R12SIS_SMBus	=	0
;R12ifdef   SIS_5598_PCI_RESET		
;R12SIS_SMBus	=	1
;R12endif;  SIS_5598_PCI_RESET		
;R12ifdef   SIS5595_ID
;R12SIS_SMBus	=	1
;R12endif;  SIS5595_ID
;R12
if	SIS_SMBus		; SiS Chipset
;R12
;R12SDA             EQU     10h	;I2C Data 
;R12SCL             EQU     08h	;I2C Clock
;R12
;R12		extrn	F000_Get_CT:near
;R12		extrn	F000_Set_CT:near
;R12
;R12DelayIO:
;R12		push	cx
;R12		mov	cx,300h
;R12	@@:
;R12		newiodelay
;R12		loop	@B
;R12		pop	cx
;R12		ret
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Set_Start                                                               º
;R12;º  Input:  None                                                            º
;R12;º  Output: None                                                            º
;R12;º                                                                          º
;R12;º  SDA  ----\___                                                           º
;R12;º  SCL  -------\                                                           º
;R12;º       1   2                                                              º
;R12;º        4us 4us                                                           º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Set_Start       proc	Near
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12        	or	al, SCL
;R12        	call	F000_Set_Ct
;R12        
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12        	or	al, SDA
;R12        	call	F000_Set_Ct
;R12
;R12		call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al,NOT SDA
;R12        	call	F000_Set_Ct
;R12                NEWIODELAY      
;R12                NEWIODELAY      
;R12                NEWIODELAY      
;R12
;R12                call	DelayIO			
;R12        
;R12;For 1'st clock low time
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al,NOT SCL
;R12        	call	F000_Set_Ct
;R12
;R12                call	DelayIO			
;R12        
;R12                ret
;R12Set_Start       endp
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Wr_Byte                                                                 º
;R12;º                                                                          º
;R12;º  Input:   BL:Data to I2C Bus                                             º
;R12;º  Output: None                                                            º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Wr_Byte		proc	Near
;R12
;R12                pusha					
;R12        	mov	cx,086dh
;R12                call	F000_Get_Ct			
;R12                and     al,NOT SCL			
;R12                call	F000_Set_Ct			
;R12                popa					
;R12
;R12                mov     dx,bx
;R12                mov     cx ,8
;R12write_B:
;R12                push    cx
;R12                NEWIODELAY      
;R12                NEWIODELAY      
;R12                NEWIODELAY      
;R12
;R12                xor     dh,dh   
;R12                shl     dx,1    
;R12                shl     dh,4            ;;if SDA=10h, SCL=08h
;R12        	mov	bl,dh
;R12
;R12        	push	dx
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al,NOT SDA              
;R12                or      al,bl			;data                   
;R12        	call	F000_Set_Ct
;R12                NEWIODELAY      
;R12        
;R12                call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                or      al,SCL			
;R12        	call	F000_Set_Ct
;R12                call	DelayIO			
;R12                NEWIODELAY      
;R12                NEWIODELAY      
;R12                NEWIODELAY      
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al,NOT SCL		
;R12        	call	F000_Set_Ct
;R12                call	DelayIO			
;R12        
;R12        	pop	dx
;R12                pop     cx
;R12                loop    write_B
;R12                ret
;R12Wr_Byte endp
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Wait_ACK                                                                º
;R12;º                                                                          º
;R12;º  Input:  None                                                            º
;R12;º  Output: CLR :  Acknowledge                                              º
;R12;º          STC : !Acknowledge                                              º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Wait_ACK        proc	Near
;R12        	mov	cx,086dh
;R12                call	F000_Get_Ct		
;R12                and     al, not SCL		
;R12                call	F000_Set_Ct		
;R12                call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                or      al, SCL			
;R12        	call	F000_Set_Ct
;R12
;R12                call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12                call	F000_Get_Ct		
;R12                and	al,NOT SCL		
;R12                call	F000_Set_Ct		
;R12                call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                call	DelayIO			
;R12                mov     bl, al			
;R12        	and	al,NOT SCL
;R12        	call	F000_Set_Ct
;R12                call	DelayIO			
;R12        
;R12                test    bl, SDA
;R12                jnz     short ACK_Err_ret
;R12                clc
;R12                ret
;R12ACK_Err_ret:
;R12	        stc
;R12        	ret
;R12Wait_ACK        endp
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Set_Stop                                                                º
;R12;º                                                                          º
;R12;º  Input:  None                                                            º
;R12;º  Output: None                                                            º
;R12;º  SDA  ___/-----                                                          º
;R12;º  SCL  ---------                                                          º
;R12;º       1  2   3                                                           º
;R12;º        4us 4us                                                           º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Set_Stop        proc	Near
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al,not SCL
;R12        	call	F000_Set_Ct
;R12        	call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al,NOT SDA              
;R12        	call	F000_Set_Ct
;R12        	call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                or      al,SCL
;R12        	call	F000_Set_Ct
;R12        	call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                or      al,SDA
;R12        	call	F000_Set_Ct
;R12        	call	DelayIO			
;R12
;R12                ret
;R12Set_Stop        endp
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Set_Pointer                                                             º
;R12;º  Input:  BX = pointer                                                    º
;R12;º  Output: CLC = PK                                                        º
;R12;º          STC = Fail                                                      º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Set_Pointer     proc
;R12                push    bx              ;Save Register Pointer
;R12                call    Set_Start
;R12                mov     bl,MAX1617_ID
;R12                call    Wr_Byte
;R12                call    Wait_ACK
;R12                pop     bx
;R12                jc      ErrSet_Pointer
;R12                call    Wr_Byte         ;bx = pointer
;R12                call    Wait_ACK
;R12                jc      ErrSet_Pointer
;R12                clc
;R12                ret
;R12ErrSet_Pointer:
;R12                stc
;R12                ret
;R12Set_Pointer     endp
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Rd_Data                                                                 º
;R12;º                                                                          º
;R12;º  Input:  None                                                            º
;R12;º  Output: BL: return data                                                 º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Rd_Data 	proc
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12        	and	al, not SCL
;R12        	call	F000_Set_Ct
;R12        	call	DelayIO			
;R12        
;R12                xor     bx, bx
;R12                xor     ax, ax
;R12                mov     cx, 8
;R12Rd_byte:
;R12                push    cx
;R12                mov     cx, 8                           ;T(low) = 4.7 us
;R12@@:
;R12        	NEWIODELAY
;R12                loop    short @B
;R12
;R12        	mov	cx,086dh		
;R12        	call	F000_Get_Ct		
;R12        	or	al, SDA			
;R12        	call	F000_Set_Ct		
;R12        	call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12        	or	al, SCL
;R12        	call	F000_Set_Ct		;SCL high, receiver will read data
;R12        	call	DelayIO			
;R12
;R12                mov     cx, 8                   ;T(high) = 4 us
;R12	@@:
;R12        	NEWIODELAY
;R12                loop    short @B
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12
;R12        	push	ax
;R12                and     al, SDA 
;R12                shr     al, 4
;R12                shl     bl, 1           
;R12                or      bl, al
;R12        	pop	ax
;R12                and     al, NOT SCL                     ;SCL low
;R12        	mov	cx,086dh
;R12        	call	F000_Set_Ct
;R12        	call	DelayIO			
;R12
;R12                pop     cx
;R12                loop    short Rd_byte
;R12
;R12                mov     cx, 8                           ;T(hd)
;R12        @@:
;R12        	NEWIODELAY
;R12                loop    short @B
;R12
;R12                ret
;R12Rd_Data endp
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Set_NoACK                                                               º
;R12;º                                                                          º
;R12;º  Input:  None                                                            º
;R12;º  Output: None                                                            º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Set_NoACK       proc
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al, NOT SCL
;R12        	call	F000_Set_Ct		;out No ACK
;R12        	call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                or      al, SDA
;R12        	call	F000_Set_Ct		;out No ACK
;R12        	call	DelayIO			
;R12
;R12                NEWIODELAY                	;T(setup) = 250 ns
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                or      al, SCL
;R12        	call	F000_Set_Ct		;SCL ,SDA = high
;R12                call	DelayIO			
;R12
;R12                mov     cx, 8                   ;T(high) = 4 us
;R12        @@:
;R12                NEWIODELAY
;R12                loop    short @B
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al, not SCL
;R12        	call	F000_Set_Ct		;SCL = low
;R12
;R12        	call	DelayIO			
;R12
;R12                ret
;R12Set_NoACK       endp
;R12
;R12;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;R12;º  Set_ACK                                                                 º
;R12;º                                                                          º
;R12;º  Input:  None                                                            º
;R12;º  Output: None                                                            º
;R12;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
;R12Set_ACK 	proc
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al, NOT SCL
;R12                and     al, NOT SDA
;R12        	call	F000_Set_Ct		
;R12                NEWIODELAY                	;T(setup) = 250 ns
;R12        	call	DelayIO			
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                or      al, SCL
;R12        	call	F000_Set_Ct		;SCL = high
;R12        	call	DelayIO			
;R12
;R12                mov     cx, 8                   ;T(high) = 4 us
;R12        @@:
;R12                NEWIODELAY
;R12                loop    short @B
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al, NOT SCL
;R12        	call	F000_Set_Ct		;SCL = low
;R12        	call	DelayIO			
;R12                NEWIODELAY
;R12
;R12        	mov	cx,086dh
;R12        	call	F000_Get_Ct
;R12                and     al, NOT SDA
;R12        	call	F000_Set_Ct		;SDA = low
;R12        	call	DelayIO			
;R12                NEWIODELAY
;R12
;R12                ret
;R12Set_ACK endp

;[]==============================================================[]
;Input  : CL - register index
;Output : AL - Value read
;[]==============================================================[]
                public  Get_MAX1617_Byte
                public  Set_MAX1617_Byte
Get_MAX1617_Byte   Proc    Near
                mov     ch,MAX1617_ID		;R14
                mov     bl,cl
                call    Set_Pointer
                NEWIODELAY
                NEWIODELAY
                call    Set_Start
                mov     bl,MAX1617_ID
                inc     bl              ;for read operation
                call    Wr_Byte
                call    Wait_ACK
        	jc      Rd_1ByteReg_Fail
                call    Rd_Data         ;bl = data
                shl     ebx,16
                call    Set_NoACK
                call    Set_Stop
                shr     ebx,16
                xor     bh,bh   ;BL = value
                mov     al,bl
                clc
                ret
Rd_1ByteReg_Fail:

                stc
                ret

Get_MAX1617_Byte   Endp

;[]==============================================================[]
;Input : CL - register index
;        AL - Value to write
;Output: none
;[]==============================================================[]
Set_MAX1617_Byte   Proc    Near

                push    ax      
                mov     ch,MAX1617_ID		;R14
                mov     bl,cl
                cli
                call    Set_Pointer
                newiodelay
                newiodelay
                pop     ax      
                mov     bl,al
                call    Wr_Byte
                call    Wait_ACK
                jc      Wr_1ByteReg_Fail
                call    Set_Stop
                clc
                sti
                ret
Wr_1ByteReg_Fail:
                stc
                sti
                ret
Set_MAX1617_Byte   Endp

endif;	SIS_SMBus		
%					;R15
;R09 - start
ifdef	Dual_Max1617_Support
;[]==============================================================[]
;Input	: CL - register index
;	  CH - Address ID
;Output : AL - Value read
;[]==============================================================[]
		public	Get_Max1617
		public	Set_Max1617
Get_Max1617	Proc	Near
	call	Ct_I2CReadByte		;R15
comment	%				;R15
		push	cx

		mov	dx,SMBus_Port +04h
		inc	ch
		mov	al, ch
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;read data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY
%					;R15
		ret
Get_Max1617	Endp

;[]==============================================================[]
;Input : CL - register index
;	 CH - Address ID
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_Max1617	Proc	Near

	call	Ct_I2CWriteByte		;R15
comment	%				;R15

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al, ch			;MAX1617 write cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,05
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 
%					;R15
		ret
Set_Max1617	Endp
endif;	Dual_Max1617_Support
;R09 - end

ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		extrn	TEMP1_HIGH:near		
		extrn	SENSOR_FLAG:near		;R03
;[]========================================================================[]
;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
;R03 - start
		mov	di,offset DGROUP:SENSOR_FLAG
		test	word ptr es:[di],01h
		jz	short No_Sensor
;R03 - end
		mov	di,offset DGROUP:TEMP1_HIGH

		extrn	MAX1617_TEMP_ITEM:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM
		call	E_GetItem_Value
ifndef	CPU_Temp_Selectable
		xor	ah,ah
		mov	si,offset CPU_TEMP_VAL
		add	si,ax
		mov	al,byte ptr cs:[si]
endif;	CPU_Temp_Selectable
		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

		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
No_Sensor:					;R03
		pop	es
		ret
Ct_FillTempPointer	Endp

Critical_Table:
;R05		dw	3932			;120c
;R05		dw	3532			;80c
;R05		dw	3582			;85c
;R05		dw	3632			;90c

		dw	3332			;60c		;R05
		dw	3382			;65c		;R05
		dw	3432			;70c		;R05
		dw	3482			;75c		;R05

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_MAX1617_Chip	;R10
Prg_MAX1617_Chip	Proc	Near

	;Mask MAX1617's display items if it is not mounted on M/B

		mov	cl,0
		call	Get_MAX1617_Byte
		jnc	short @F		;MAX1617 not found	

	;Disable items by change item's status
		push	ds
		mov	ax,0f000h
		mov	ds,ax
		extrn	Current_Temp_Item:near
		extrn	MAX1617_TEMP_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:[MAX1617_TEMP_ITEM].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Temp_Item].ITEMSTAT,ITEMDISABLE

;R06 - start
ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		or	word ptr ds:[ACPI_Critical_Item].ITEMSTAT,ITEMDISABLE
ifdef	CPU_Fan_Turn_on_in_Win98
		extrn	CPU_Fan_in_WIN98_ITEM:near
		or	word ptr ds:[CPU_Fan_in_WIN98_ITEM].ITEMSTAT,ITEMDISABLE
endif;	CPU_Fan_Turn_on_in_Win98
endif;	ACPI_Support
;R06 - end

;R03 - start
ifdef	ACPI_SUPPORT
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT
;R03 - end
		f000_call	DGROUP:F000_Shadow_R
		pop	ds
		jmp	short Prg_MAX1617_Chip_End
	@@:
		mov	cl,09
		mov	al,00h				;MAX1617 Restart
		call	Set_MAX1617_Byte

		mov	cl,09
;R02		mov	al,0C0h				;MAX1617 start
		mov	al,080h				;MAX1617 start;R02
		call	Set_MAX1617_Byte

		xor	cx,cx
      @@:
	      	newiodelay
		loop	short @B

		mov	cl,02
		call	Get_MAX1617_Byte		;Get status for reset

		extrn	MAX1617_TEMP_ITEM:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM
		call	E_GetItem_Value
ifndef	CPU_Temp_Selectable
		mov	si,offset CPU_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	CPU_Temp_Selectable

		push	ax
		xor	ah,ah
		mov	cl,0bh
		call	Set_MAX1617_Byte		;set Tos (High limit)
		pop	ax

ifdef	MAX1617_LoLimit_Difference		      
		sub	al,MAX1617_LoLimit_Difference 
else;	MAX1617_LoLimit_Difference		      
		sub	al,5
endif;	MAX1617_LoLimit_Difference		      

		xor	ah,ah
		mov	cl,0ch
		call	Set_MAX1617_Byte	;set Thyst (Low limit)

		mov	al, 07
		mov	cl, 0ah
		call	Set_MAX1617_Byte	;set conversion rate

	Prg_MAX1617_Chip_End:
;R09 - start
ifdef	Dual_Max1617_Support

	;Mask MAX1617's display items if it is not mounted on M/B

		mov	ch, Max1617_ID2
		mov	cl,0
		call	Get_Max1617
		jnc	short @F		;MAX1617 not found	

	;Disable items by change item's status
		push	ds
		mov	ax,0f000h
		mov	ds,ax
		extrn	Current_Temp_Item2:near
		extrn	MAX1617_TEMP_ITEM2:near
		extrn	F000_call_proc:near
		assume	ds:DGROUP
		f000_call	DGROUP:F000_Shadow_W
		or	word ptr ds:[MAX1617_TEMP_ITEM2].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Temp_Item2].ITEMSTAT,ITEMDISABLE

		f000_call	DGROUP:F000_Shadow_R
		pop	ds
		jmp	short Prg_MAX1617_Chip_End2
	@@:
		mov	ch, Max1617_ID2
		mov	cl,09
		mov	al,00h				;MAX1617 Restart
		call	Set_Max1617

		mov	ch, Max1617_ID2
		mov	cl,09
		mov	al,080h				;MAX1617 start
		call	Set_Max1617

		xor	cx,cx
      @@:
	      	newiodelay
		loop	short @B

		mov	ch, Max1617_ID2
		mov	cl,02
		call	Get_Max1617		;Get status for reset

		extrn	MAX1617_TEMP_ITEM2:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM2
		call	E_GetItem_Value

ifndef	CPU_Temp_Selectable
		mov	si,offset CPU_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	CPU_Temp_Selectable

		push	ax
		xor	ah,ah
		mov	ch, Max1617_ID2
		mov	cl,0bh
		call	Set_Max1617		;set Tos (High limit)
		pop	ax

ifdef	MAX1617_LoLimit_Difference		      
		sub	al,MAX1617_LoLimit_Difference 
else;	MAX1617_LoLimit_Difference
		sub	al,5
endif;	MAX1617_LoLimit_Difference		      

		xor	ah,ah
		mov	ch, Max1617_ID2
		mov	cl,0ch
		call	Set_Max1617	;set Thyst (Low limit)

		mov	al, 07
		mov	ch, Max1617_ID2
		mov	cl, 0ah
		call	Set_Max1617	;set conversion rate

	Prg_MAX1617_Chip_End2:
endif;	Dual_Max1617_Support
;R09 - end
		ret

Prg_MAX1617_Chip	Endp

		assume	ds:EGROUP
ifndef	CPU_Temp_Selectable
ifndef	MAX1617_SCALE_60_TO_90		 
	ifndef	MAX1617_SCALE_40_TO_70
		ALIGN	4
CPU_TEMP_VAL:
		db	0120	;disabled
		db	032h	;50C
		db	035h	;53C
		db	038h	;56C
		db	03ch	;60C
		db	03fh	;63C
		db	042h	;66C
		db	046h	;70C
	else;	MAX1617_SCALE_40_TO_70
		ALIGN	4
CPU_TEMP_VAL:		 
		db	0120	;disabled
		db	028h	;40C
		db	02dh	;45C
		db	032h	;50C
		db	037h	;55C
		db	03ch	;60C
		db	041h	;65C
		db	046h	;70C
	endif;	MAX1617_SCALE_40_TO_70
else;	MAX1617_SCALE_60_TO_90		 
		ALIGN	4		 
CPU_TEMP_VAL:				 
		db	0120	;disabled
		db	03ch	;60C	 
		db	041h	;65C	 
		db	046h	;70C	 
		db	04bh	;75C	 
		db	050h	;80C	 
		db	055h	;85C	 
		db	05ah	;90C	 
endif;	MAX1617_SCALE_60_TO_90		 
endif;	CPU_Temp_Selectable

endif	;SENSOR_IN_XGROUP		;R16
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

ifdef	CPU_Temp_Selectable						
		dw	offset MAX1617_Temp_Item, offset Show_Scale
endif;	CPU_Temp_Selectable
		dw	offset Current_Temp_Item, offset Show_Current_Temp
;R09 - start
ifdef	Dual_Max1617_Support
ifdef	CPU_Temp_Selectable						
		dw	offset MAX1617_Temp_Item2, offset Show_Scale2
endif;	CPU_Temp_Selectable
		dw	offset Current_Temp_Item2, offset Show_Current_Temp2
endif;	Dual_Max1617_Support
;R09 - end

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_MAX1617_Item	;R10
First_MAX1617_Item	Label	Near		;R10

ifndef	MAX1617_CMOS_Bits
MAX1617_CMOS_Bits = 00000111b
endif;	MAX1617_CMOS_Bits
ifdef	CPU_Temp_Selectable		
DEFINE_ITEM	MAX1617_Temp_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R01
	menuitem <NOMODBIN+SHOWNUM+DIGIT3,\
		  offset MAX1617_Temp_Str,NOCT,01111111b,MAX1617_CMOS,01111111b,\
		  offset Nullstr,30,120,Xaxis,Yaxis,120,30,offset Nullstr>
else;	CPU_Temp_Selectable
DEFINE_ITEM     MAX1617_TEMP_ITEM
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R01
        menuitem <PMITEM,\
                  offset MAX1617_TEMP_Str,NOCT,MAX1617_CMOS_Bits,MAX1617_CMOS,MAX1617_CMOS_Bits,\
                  offset MAX1617_TEMP_Val,0,7,Xaxis,Yaxis ,   00000000b, 00000000b,offset Std_Help_Str>
endif;	CPU_Temp_Selectable

DEFINE_ITEM	Current_Temp_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R01
        menuitem <SHOWONLY,\
                  offset Current_Temp_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

;R09 - start
ifdef	Dual_Max1617_Support
ifndef	MAX1617_CMOS_Bits2
MAX1617_CMOS_Bits2 = 00000111b
endif;	MAX1617_CMOS_Bits2
ifdef	CPU_Temp_Selectable		
DEFINE_ITEM	MAX1617_Temp_Item2
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R01
	menuitem <NOMODBIN+SHOWNUM+DIGIT3,\
		  offset MAX1617_Temp_Str2,NOCT,01111111b,MAX1617_CMOS2,01111111b,\
		  offset Nullstr,30,120,Xaxis,Yaxis,120,30,offset Nullstr>
else;	CPU_Temp_Selectable
DEFINE_ITEM     MAX1617_TEMP_ITEM2
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R01
        menuitem <PMITEM,\
                  offset MAX1617_TEMP_Str2,NOCT,MAX1617_CMOS_Bits2,MAX1617_CMOS2,MAX1617_CMOS_Bits2,\
                  offset MAX1617_TEMP_Val2,0,7,Xaxis,Yaxis ,   00000000b, 00000000b,offset Std_Help_Str>
endif;	CPU_Temp_Selectable

DEFINE_ITEM	Current_Temp_Item2
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R01
        menuitem <SHOWONLY,\
                  offset Current_Temp_Str2,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

endif;	Dual_Max1617_Support
;R09 - end
								
ifdef	ACPI_SUPPORT
DEFINE_ITEM     ACPI_Critical_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R01
        menuitem <PMITEM,\
                  offset ACPI_Critical_Str           ,NOCT,00011000b,MAX1617_ACPI_CMOS,MAX1617_ACPI_CMOS_BITS,\
                  offset Critical_str,0,3,Xaxis,Yaxis,00000000b,    00000000b,offset Std_Help_Str>
endif	;ACPI_SUPPORT											   					

		Public	Last_MAX1617_Item	;R10
Last_MAX1617_Item	Label	Near		;R10

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
;R05Critical_str		db	'Disabled  ',0
;R05			db      '80øC/176øF',0
;R05			db      '85øC/185øF',0
;R05			db      '90øC/194øF',0

Critical_str		db      '60øC/140øF',0		;R05
			db      '65øC/149øF',0		;R05
			db      '70øC/158øF',0		;R05
			db	'75øC/167øF',0		;R05

endif	;ACPI_SUPPORT
Current_Temp_Str	db	'Current CPU Temperature'
			db	(COLLON_LOC - ($-(offset Current_Temp_Str))) dup (" ")
			db	': ',0
MAX1617_TEMP_Str        db      'CPU Warning Temperature'
			db	(COLLON_LOC - ($-(offset MAX1617_TEMP_Str))) dup (" ")
ifdef	CPU_Temp_Selectable
		db	':',0
else;	CPU_Temp_Selectable
		db	': ',0				
endif;	CPU_Temp_Selectable

ifndef	CPU_Temp_Selectable
ifndef	MAX1617_SCALE_60_TO_90
	ifndef	MAX1617_SCALE_40_TO_70
MAX1617_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
	else;	MAX1617_SCALE_40_TO_70
MAX1617_TEMP_Val           db      'Disabled  ',0
			db      '40øC/104øF',0
			db      '45øC/113øF',0
			db      '50øC/122øF',0
			db      '55øC/131øF',0
			db      '60øC/140øF',0
			db      '65øC/149øF',0
			db      '70øC/158øF',0
	endif;	MAX1617_SCALE_40_TO_70	      
else;	MAX1617_SCALE_60_TO_90					
MAX1617_TEMP_Val	db      'Disabled  ',0
			db      '60øC/140øF',0
			db      '65øC/149øF',0
			db      '70øC/158øF',0
			db      '75øC/167øF',0
			db      '80øC/176øF',0
			db      '85øC/185øF',0
			db      '90øC/194øF',0
endif;	MAX1617_SCALE_60_TO_90
endif;	CPU_Temp_Selectable

;R09 - start
ifdef	Dual_Max1617_Support
Current_Temp_Str2	db	'Current CPU2 Temperature'
			db	(COLLON_LOC - ($-(offset Current_Temp_Str2))) dup (" ")
			db	': ',0
MAX1617_TEMP_Str2        db      'CPU2 Warning Temperature'
			db	(COLLON_LOC - ($-(offset MAX1617_TEMP_Str2))) dup (" ")
ifdef	CPU_Temp_Selectable
		db	':',0
else;	CPU_Temp_Selectable
		db	': ',0				
endif;	CPU_Temp_Selectable
ifndef	CPU_Temp_Selectable
ifndef	MAX1617_SCALE_60_TO_90
	ifndef	MAX1617_SCALE_40_TO_70
MAX1617_TEMP_Val2	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
	else;	MAX1617_SCALE_40_TO_70
MAX1617_TEMP_Val2	db      'Disabled  ',0
			db      '40øC/104øF',0
			db      '45øC/113øF',0
			db      '50øC/122øF',0
			db      '55øC/131øF',0
			db      '60øC/140øF',0
			db      '65øC/149øF',0
			db      '70øC/158øF',0
	endif;	MAX1617_SCALE_40_TO_70	      
else;	MAX1617_SCALE_60_TO_90					
MAX1617_TEMP_Val2	db      'Disabled  ',0
			db      '60øC/140øF',0
			db      '65øC/149øF',0
			db      '70øC/158øF',0
			db      '75øC/167øF',0
			db      '80øC/176øF',0
			db      '85øC/185øF',0
			db      '90øC/194øF',0
endif;	MAX1617_SCALE_60_TO_90
endif;	CPU_Temp_Selectable
endif;	Dual_Max1617_Support
;R09 - end
;=====================

ifdef	CPU_Temp_Selectable
Show_Scale	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP				;R16
		Post_Func_Call E000_Show_Scale
else	;SENSOR_IN_XGROUP				;R16
		Xcall X_Show_Scale			;R16
endif	;SENSOR_IN_XGROUP				;R16
	@@:
		ret
Show_Scale	Endp
endif;	CPU_Temp_Selectable

Show_Current_Temp	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F	
ifndef	SENSOR_IN_XGROUP				;R16
		Post_Func_Call E000_Show_Current_Temp
else	;SENSOR_IN_XGROUP				;R16
		Xcall X_Show_Current_Temp		;R16
endif	;SENSOR_IN_XGROUP				;R16
	@@:					       
		ret
Show_Current_Temp	endp
;R09 - start
ifdef	Dual_Max1617_Support
ifdef	CPU_Temp_Selectable
Show_Scale2	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP				;R16
		Post_Func_Call E000_Show_Scale2
else	;SENSOR_IN_XGROUP				;R16
		Xcall X_Show_Scale2			;R16
endif	;SENSOR_IN_XGROUP				;R16
	@@:
		ret
Show_Scale2	Endp
endif;	CPU_Temp_Selectable

Show_Current_Temp2	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F	
ifndef	SENSOR_IN_XGROUP				;R16
		Post_Func_Call E000_Show_Current_Temp2
else	;SENSOR_IN_XGROUP				;R16
		Xcall X_Show_Current_Temp2		;R16 
endif	;SENSOR_IN_XGROUP				;R16
	@@:					       
		ret
Show_Current_Temp2	endp
endif;	Dual_Max1617_Support
;R09 - end

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			;R16

SIS_SMBus	=	0
ifdef   SIS_5598_PCI_RESET		
SIS_SMBus	=	1
endif;  SIS_5598_PCI_RESET		
ifdef   SIS5595_ID
SIS_SMBus	=	1
endif;  SIS5595_ID

ifdef	CPU_Temp_Selectable
E000_Show_Scale	Proc	Near
	     	extrn	E_GetItem_Value:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM
		Post_func_Call	E_GetItem_Value

		mov	bl, al				;save temp scale

		F000_call	DISP_WORD_INT3
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'C'
		F000_call	Display_Char
		mov	al, '/'
		F000_call	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
		F000_call	DISP_WORD_INT3
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'F'
		F000_call	Display_Char
  		sub 	al, -1			;set overflow flag for display error
		ret
E000_Show_Scale	Endp
endif;	CPU_Temp_Selectable

E000_Show_Current_Temp	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,0
		call	Get_MAX1617_Byte

		out	80h, al			;debug
ifdef	Software_I2C				;R08
ifdef	VT586_ACPI	       
                shr     ax,8                    ; get bit7 - bit15
ifdef	ADD_5C
                add     al,5			; add : increase 5øC
endif;	ADD_5C
endif;	VT586_ACPI
endif;  Software_I2C				;R08

if	SIS_SMBus		; SiS Chipset
                shr     ax,8                    ; get bit7 - bit15
endif;	SIS_SMBus		; SiS Chipset
		cmp	al,100
		jbe	short OK_75Temp
		mov	al,0
	OK_75Temp:
ifdef	Temp_Always_Add_20C  
		add	al,20
endif;	Temp_Always_Add_20C  
		mov	bl,al
		F000_call	DISP_Byte_INT2
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'C'
		F000_call	Display_Char
		mov	al, '/'
		F000_call	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
		F000_call	DISP_WORD_INT3
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'F'
		F000_call	Display_Char
	@@:
		ret

E000_Show_Current_Temp	endp

;R09 - start
ifdef	Dual_Max1617_Support
ifdef	CPU_Temp_Selectable
E000_Show_Scale2	Proc	Near
	     	extrn	E_GetItem_Value:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM2
		Post_func_Call	E_GetItem_Value

		mov	bl, al				;save temp scale

		F000_call	DISP_WORD_INT3
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'C'
		F000_call	Display_Char
		mov	al, '/'
		F000_call	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
		F000_call	DISP_WORD_INT3
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'F'
		F000_call	Display_Char
  		sub 	al, -1			;set overflow flag for display error
		ret
E000_Show_Scale2	Endp
endif;	CPU_Temp_Selectable

E000_Show_Current_Temp2	Proc	Near
		extrn	Get_MAX1617:near
		cmp	al, Special_Before
		je	short @F
		mov	ch, Max1617_ID2
		mov	cl,0
		call	Get_MAX1617

ifdef	Software_I2C				;R08
ifdef	VT586_ACPI	       
                shr     ax,8                    ; get bit7 - bit15
ifdef	ADD_5C
                add     al,5			; add : increase 5øC
endif;	ADD_5C
endif;	VT586_ACPI
endif;  Software_I2C				;R08

if	SIS_SMBus		; SiS Chipset
                shr     ax,8                    ; get bit7 - bit15
endif;	SIS_SMBus		; SiS Chipset
		cmp	al,100
		jbe	short OK_75Temp2
		mov	al,0
	OK_75Temp2:
ifdef	Temp_Always_Add_20C  
		add	al,20
endif;	Temp_Always_Add_20C  
		mov	bl,al
		F000_call	DISP_Byte_INT2
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'C'
		F000_call	Display_Char
		mov	al, '/'
		F000_call	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
		F000_call	DISP_WORD_INT3
		mov	al, 'ø'
		F000_call	Display_Char
		mov	al, 'F'
		F000_call	Display_Char
	@@:
		ret

E000_Show_Current_Temp2	endp
endif;	Dual_Max1617_Support
;R09 - end

ifndef	BIOS60							;R01
		Public	Update_MAX1617_Screen
Update_MAX1617_Screen	Proc	near

		pusha

;R04 - start
ifdef	Update_Sensor_in_CPUFEAT				
		cmp	byte ptr CUR_PAGE[bp], PAGE_CPU
else;	Update_Sensor_in_CPUFEAT
;R04 - end
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				;R04

		jne	short Update_MAX1617_End

	;----------------------------------------
		mov	si, offset MAX1617_Item_List

	Update_MAX1617_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_MAX1617_End
		push	si
		F000_call	Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_MAX1617_Start
	;----------------------------------------

	Update_MAX1617_End:

		popa
		ret

Update_MAX1617_Screen	Endp
endif	;BIOS60							;R01

ifdef	BIOS60							;R01
	db	'$SpeRT'					;R01
endif	;BIOS60							;R01

MAX1617_Item_List	Label	Word

ifdef	BIOS60							;R01
	dw	MAX1617_Runtime_No				;R01
endif	;BIOS60							;R01

	dw	offset Current_Temp_Item
	dw	offset MAX1617_TEMP_ITEM
;R09 - start
ifdef	Dual_Max1617_Support
	dw	offset Current_Temp_Item2			
	dw	offset MAX1617_TEMP_ITEM2	
endif;	Dual_Max1617_Support
;R09 - end

MAX1617_Runtime_No	EQU	(($ - offset MAX1617_Item_List)-2)/2	;R01

	dw	-1

endif	;SENSOR_IN_XGROUP				;R16
ENDIF	;COMPILE_FOR_SENSOR_MNU

;R10 - start
IF	COMPILE_FOR_SENSOR_MNU EQ 4
	dw	offset First_MAX1617_Item, offset Last_MAX1617_Item
ifndef	SENSOR_IN_XGROUP						;R16
	dw	SEG Prg_MAX1617_Chip, offset Prg_MAX1617_Chip
else	;SENSOR_IN_XGROUP						;R16
	dw	SEG X_Prg_MAX1617_Chip, offset X_Prg_MAX1617_Chip	;R16
endif	;SENSOR_IN_XGROUP						;R16
ENDIF	;COMPILE_FOR_SENSOR_MNU

IF	COMPILE_FOR_SENSOR_MNU EQ 5
	extrn	First_MAX1617_Item:near
	extrn	Last_MAX1617_Item:near
ifndef	SENSOR_IN_XGROUP						;R16
	extrn	Prg_MAX1617_Chip:near
else	;SENSOR_IN_XGROUP						;R16
	extrn	X_Prg_MAX1617_Chip:far					;R16
endif	;SENSOR_IN_XGROUP						;R16
ENDIF	;COMPILE_FOR_SENSOR_MNU
;R10 - end

endif	;COMPILE_FOR_SENSOR_MNU 

;R16 - start
;==================================================================
;======================== 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			

ifndef		MAX1617_ID				
MAX1617_ID         EQU     30H
endif;		MAX1617_ID

		public	X_Get_MAX1617_Byte
		public	X_Set_MAX1617_Byte
		public	X_Get_MAX1617_Word
		public	X_Set_MAX1617_Word
		extrn	X_GetItem_Value:near

X_Get_MAX1617_Byte	Proc	Near
			mov	ch, MAX1617_ID
			call far ptr	EGROUP:fproc_Ct_I2CReadByte
			ret
X_Get_MAX1617_Byte	ENDP

X_Set_MAX1617_Byte	Proc	Near
			mov	ch, MAX1617_ID
			call far ptr	EGROUP:fproc_Ct_I2CWriteByte
			ret
X_Set_MAX1617_Byte	ENDP

X_Get_MAX1617_Word	Proc	Near
			mov	ch, MAX1617_ID
			call far ptr	EGROUP:fproc_Ct_I2CReadWord
			ret
X_Get_MAX1617_Word	ENDP

X_Set_MAX1617_Word	Proc	Near
			mov	ch, MAX1617_ID
			call far ptr	EGROUP:fproc_Ct_I2CWriteWord
			ret
X_Set_MAX1617_Word	ENDP

ifdef	Dual_Max1617_Support
;[]==============================================================[]
;Input	: CL - register index
;	  CH - Address ID
;Output : AL - Value read
;[]==============================================================[]
		public	X_Get_Max1617
		public	X_Set_Max1617

X_Get_Max1617	Proc	Near
		call far ptr	EGROUP:fproc_Ct_I2CReadByte
		ret
X_Get_Max1617	Endp

;[]==============================================================[]
;Input : CL - register index
;	 CH - Address ID
;	 AL - Value to write
;Output: none
;[]==============================================================[]
X_Set_Max1617	Proc	Near
		call far ptr	EGROUP:fproc_Ct_I2CWriteByte		
		ret
X_Set_Max1617	Endp
endif;	Dual_Max1617_Support

ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		extrn	TEMP1_HIGH:near		
		extrn	SENSOR_FLAG:near		;R03
;[]========================================================================[]
;Procedure:	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	MAX1617_TEMP_ITEM:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM
		call	X_GetItem_Value
ifndef	CPU_Temp_Selectable
		xor	ah,ah
		mov	si,offset CPU_TEMP_VAL
		add	si,ax
		mov	al,byte ptr cs:[si]
endif;	CPU_Temp_Selectable
		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

		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
No_Sensor:					;R03
		pop	es
		retf
X_Ct_FillTempPointer	Endp

Critical_Table:

		dw	3332			;60c		;R05
		dw	3382			;65c		;R05
		dw	3432			;70c		;R05
		dw	3482			;75c		;R05

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_MAX1617_Chip	;R10
X_Prg_MAX1617_Chip	Proc	far

	;Mask MAX1617's display items if it is not mounted on M/B

		mov	cl,0
		call	X_Get_MAX1617_Byte
		jnc	short @F		;MAX1617 not found	

	;Disable items by change item's status
		push	ds
		mov	ax,0f000h
		mov	ds,ax
		extrn	Current_Temp_Item:near
		extrn	MAX1617_TEMP_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:[MAX1617_TEMP_ITEM].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Temp_Item].ITEMSTAT,ITEMDISABLE

;R06 - start
ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		or	word ptr ds:[ACPI_Critical_Item].ITEMSTAT,ITEMDISABLE
ifdef	CPU_Fan_Turn_on_in_Win98
		extrn	CPU_Fan_in_WIN98_ITEM:near
		or	word ptr ds:[CPU_Fan_in_WIN98_ITEM].ITEMSTAT,ITEMDISABLE
endif;	CPU_Fan_Turn_on_in_Win98
endif;	ACPI_Support
;R06 - end

;R03 - start
ifdef	ACPI_SUPPORT
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT
;R03 - end
		call	X_F000_Shadow_R
		pop	ds
		jmp	short Prg_MAX1617_Chip_End
	@@:
		mov	cl,09
		mov	al,00h				;MAX1617 Restart
		call	X_Set_MAX1617_Byte

		mov	cl,09
		mov	al,080h				;MAX1617 start;R02
		call	X_Set_MAX1617_Byte

		xor	cx,cx
      @@:
	      	newiodelay
		loop	short @B

		mov	cl,02
		call	X_Get_MAX1617_Byte		;Get status for reset

		extrn	MAX1617_TEMP_ITEM:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM
		call	X_GetItem_Value
ifndef	CPU_Temp_Selectable
		mov	si,offset CPU_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	CPU_Temp_Selectable

		push	ax
		xor	ah,ah
		mov	cl,0bh
		call	X_Set_MAX1617_Byte		;set Tos (High limit)
		pop	ax

ifdef	MAX1617_LoLimit_Difference		      
		sub	al,MAX1617_LoLimit_Difference 
else;	MAX1617_LoLimit_Difference		      
		sub	al,5
endif;	MAX1617_LoLimit_Difference		      

		xor	ah,ah
		mov	cl,0ch
		call	X_Set_MAX1617_Byte	;set Thyst (Low limit)

		mov	al, 07
		mov	cl, 0ah
		call	X_Set_MAX1617_Byte	;set conversion rate

	Prg_MAX1617_Chip_End:
;R09 - start
ifdef	Dual_Max1617_Support

	;Mask MAX1617's display items if it is not mounted on M/B

		mov	ch, Max1617_ID2
		mov	cl,0
		call	X_Get_Max1617
		jnc	short @F		;MAX1617 not found	

	;Disable items by change item's status
		push	ds
		mov	ax,0f000h
		mov	ds,ax
		extrn	Current_Temp_Item2:near
		extrn	MAX1617_TEMP_ITEM2:near
		assume	ds:DGROUP
		call	X_F000_Shadow_W
		or	word ptr ds:[MAX1617_TEMP_ITEM2].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Temp_Item2].ITEMSTAT,ITEMDISABLE

		call	X_F000_Shadow_R
		pop	ds
		jmp	short Prg_MAX1617_Chip_End2
	@@:
		mov	ch, Max1617_ID2
		mov	cl,09
		mov	al,00h				;MAX1617 Restart
		call	X_Set_Max1617

		mov	ch, Max1617_ID2
		mov	cl,09
		mov	al,080h				;MAX1617 start
		call	X_Set_Max1617

		xor	cx,cx
      @@:
	      	newiodelay
		loop	short @B

		mov	ch, Max1617_ID2
		mov	cl,02
		call	X_Get_Max1617		;Get status for reset

		extrn	MAX1617_TEMP_ITEM2:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM2
		call	X_GetItem_Value

ifndef	CPU_Temp_Selectable
		mov	si,offset CPU_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	CPU_Temp_Selectable

		push	ax
		xor	ah,ah
		mov	ch, Max1617_ID2
		mov	cl,0bh
		call	X_Set_Max1617		;set Tos (High limit)
		pop	ax

ifdef	MAX1617_LoLimit_Difference		      
		sub	al,MAX1617_LoLimit_Difference 
else;	MAX1617_LoLimit_Difference
		sub	al,5
endif;	MAX1617_LoLimit_Difference		      

		xor	ah,ah
		mov	ch, Max1617_ID2
		mov	cl,0ch
		call	X_Set_Max1617	;set Thyst (Low limit)

		mov	al, 07
		mov	ch, Max1617_ID2
		mov	cl, 0ah
		call	X_Set_Max1617	;set conversion rate

	Prg_MAX1617_Chip_End2:
endif;	Dual_Max1617_Support
;R09 - end
		retf

X_Prg_MAX1617_Chip	Endp

		assume	ds:XGROUP
ifndef	CPU_Temp_Selectable
ifndef	MAX1617_SCALE_60_TO_90		 
	ifndef	MAX1617_SCALE_40_TO_70
		ALIGN	4
CPU_TEMP_VAL:
		db	0120	;disabled
		db	032h	;50C
		db	035h	;53C
		db	038h	;56C
		db	03ch	;60C
		db	03fh	;63C
		db	042h	;66C
		db	046h	;70C
	else;	MAX1617_SCALE_40_TO_70
		ALIGN	4
CPU_TEMP_VAL:		 
		db	0120	;disabled
		db	028h	;40C
		db	02dh	;45C
		db	032h	;50C
		db	037h	;55C
		db	03ch	;60C
		db	041h	;65C
		db	046h	;70C
	endif;	MAX1617_SCALE_40_TO_70
else;	MAX1617_SCALE_60_TO_90		 
		ALIGN	4		 
CPU_TEMP_VAL:				 
		db	0120	;disabled
		db	03ch	;60C	 
		db	041h	;65C	 
		db	046h	;70C	 
		db	04bh	;75C	 
		db	050h	;80C	 
		db	055h	;85C	 
		db	05ah	;90C	 
endif;	MAX1617_SCALE_60_TO_90		 
endif;	CPU_Temp_Selectable

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		

SIS_SMBus	=	0
ifdef   SIS_5598_PCI_RESET		
SIS_SMBus	=	1
endif;  SIS_5598_PCI_RESET		
ifdef   SIS5595_ID
SIS_SMBus	=	1
endif;  SIS5595_ID

ifdef	CPU_Temp_Selectable
X_Show_Scale	Proc	Near
	     	extrn	X_GetItem_Value:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM
		Call	X_GetItem_Value

		mov	bl, al				;save temp scale

		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;	CPU_Temp_Selectable

X_Show_Current_Temp	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,0
		call	X_Get_MAX1617_Byte

ifdef	Software_I2C				;R08
ifdef	VT586_ACPI	       
                shr     ax,8                    ; get bit7 - bit15
ifdef	ADD_5C
                add     al,5			; add : increase 5øC
endif;	ADD_5C
endif;	VT586_ACPI
endif;  Software_I2C				;R08

if	SIS_SMBus		; SiS Chipset
                shr     ax,8                    ; get bit7 - bit15
endif;	SIS_SMBus		; SiS Chipset
		cmp	al,100
		jbe	short OK_75Temp
		mov	al,0
	OK_75Temp:
ifdef	Temp_Always_Add_20C  
		add	al,20
endif;	Temp_Always_Add_20C  
		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_Current_Temp	endp

;R09 - start
ifdef	Dual_Max1617_Support
ifdef	CPU_Temp_Selectable
X_Show_Scale2	Proc	Near
	     	extrn	X_GetItem_Value:near
		mov	si,offset DGROUP:MAX1617_TEMP_ITEM2
		Call	X_GetItem_Value

		mov	bl, al				;save temp scale

		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_Scale2	Endp
endif;	CPU_Temp_Selectable

X_Show_Current_Temp2	Proc	Near
			extrn	X_Get_MAX1617:near
			cmp	al, Special_Before
			je	short @F
			mov	ch, Max1617_ID2
			mov	cl,0
			call	X_Get_MAX1617

ifdef	Software_I2C				;R08
ifdef	VT586_ACPI	       
	                shr     ax,8                    ; get bit7 - bit15
ifdef	ADD_5C
        	        add     al,5			; add : increase 5øC
endif;	ADD_5C
endif;	VT586_ACPI
endif;  Software_I2C				;R08

if	SIS_SMBus		; SiS Chipset
            	        shr     ax,8                    ; get bit7 - bit15
endif;	SIS_SMBus		; SiS Chipset
			cmp	al,100
			jbe	short OK_75Temp2
			mov	al,0
	OK_75Temp2:
ifdef	Temp_Always_Add_20C  
			add	al,20
endif;	Temp_Always_Add_20C  
			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_Current_Temp2	endp
endif;	Dual_Max1617_Support
;R09 - end

ifndef	BIOS60							;R01
			Public	X_Update_MAX1617_Screen
X_Update_MAX1617_Screen	Proc	far

		pusha

;R04 - start
ifdef	Update_Sensor_in_CPUFEAT				
		cmp	byte ptr CUR_PAGE[bp], PAGE_CPU
else;	Update_Sensor_in_CPUFEAT
;R04 - end
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				;R04

		jne	short Update_MAX1617_End

	;----------------------------------------
		mov	si, offset MAX1617_Item_List

	Update_MAX1617_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_MAX1617_End
		push	si
		call	X_Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_MAX1617_Start
	;----------------------------------------

	Update_MAX1617_End:

		popa
		retf

X_Update_MAX1617_Screen	Endp
endif	;BIOS60							;R01

ifdef	BIOS60							;R01
	db	'$SpeRT'					;R01
endif	;BIOS60							;R01

MAX1617_Item_List	Label	Word

ifdef	BIOS60							;R01
	dw	MAX1617_Runtime_No				;R01
endif	;BIOS60							;R01

	dw	offset Current_Temp_Item
	dw	offset MAX1617_TEMP_ITEM
;R09 - start
ifdef	Dual_Max1617_Support
	dw	offset Current_Temp_Item2			
	dw	offset MAX1617_TEMP_ITEM2	
endif;	Dual_Max1617_Support
;R09 - end

MAX1617_Runtime_No	EQU	(($ - offset MAX1617_Item_List)-2)/2	;R01

	dw	-1

endif	;SENSOR_IN_XGROUP		
ENDIF	;COMPILE_FOR_SENSOR_MNU
ENDIF	;COMPILE_FOR_SENSOR_MNU

;R16 - end
