;	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
;----------------------------------------------------------------------------
;R08	01/29/99 PHI	Move sensor code to XGROUP.  
;			Please use define SENSOR_IN_XGROUP.
;R07	10/09/98 PAL	Move all the SMbus of the chipset and use the chipset
;			standard I2C code in CHIPPOST.ASM
;R06	09/28/98 PAL	Fix coding error
;R05	09/17/98 PAL	Move VIA SMbus to sensor.asm
;R04	09/10/98 PAL	Move Sis SMbus to sensor.asm
;R03	09/03/98 LAW	Fixed ADM9240 work with M1543/M1543C not well
;R02	09/03/98 TNY	Support structure for setup string moving to X-Group.
;R01	07/01/98 RIC	Add VIA SMBus Support.
;R00	06/17/98 PAL	Initial Ver.

;[]=======================================================================[]
;Example:
;	ADM9240_Support		equ	1
;	ADM9240_CMOS		equ	60h
;	ADM9240_CMOS_BITS	equ	11100000b
;	SHOW_ADM9240_CPUFAN1	equ	1
;	SHOW_ADM9240_CPUFAN2	equ	1
;	Thermal_Enable		equ	1
;	ADM9240_ID		equ	58h
;	Show_Current_Vd2	equ	1
;	Vdd2_Use_Negative_Input	equ	1
;[]=======================================================================[]

ifdef	COMPILE_FOR_SENSOR_ASM
IF	COMPILE_FOR_SENSOR_ASM EQ 2
ifndef	SENSOR_IN_XGROUP			;R08
;R07 - start
ifndef	ADM9240_ID
ADM9240_ID	EQU	58h
endif;	ADM9240_ID
		public	Get_ADM9240_Byte
		public	Set_ADM9240_Byte
		public	Get_ADM9240_Word
		public	Set_ADM9240_Word
		extrn	Ct_I2CReadByte:near
		extrn	Ct_I2CWriteByte:near
		extrn	Ct_I2CReadWord:near
		extrn	Ct_I2CWriteWord:near
Get_ADM9240_Byte	Proc	Near
	mov	ch, ADM9240_ID
	call	Ct_I2CReadByte
			ret
Get_ADM9240_Byte	ENDP
Set_ADM9240_Byte	Proc	Near
	mov	ch, ADM9240_ID
	call	Ct_I2CWriteByte
			ret
Set_ADM9240_Byte	ENDP
Get_ADM9240_Word	Proc	Near
	mov	ch, ADM9240_ID
	call	Ct_I2CReadWord
			ret
Get_ADM9240_Word	ENDP

Set_ADM9240_Word	Proc	Near
	mov	ch, ADM9240_ID
	call	Ct_I2CWriteWord
			ret
Set_ADM9240_Word	ENDP
;R07 - end
comment %				;R07
ifdef	PIIX_ID
ifndef	ADM9240_ID
ADM9240_ID	EQU	58h
endif;	ADM9240_ID
;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_ADM9240_Byte
		public	Set_ADM9240_Byte
		public	Get_ADM9240_Word
		public	Set_ADM9240_Word
		
Get_ADM9240_Byte	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(ADM9240_ID + 1)	;ADM9240 read cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Byte	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,ADM9240_ID		;ADM9240 write cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY
		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,05
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY
		call	Chk_SMBus_READY 

		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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_ADM9240_Word	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(ADM9240_ID + 1)
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY

		mov	dl,03h
		pop	ax
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,4ch
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY

		mov	dl,06
		in	al,dx			;Data1
		NEWIODELAY
		NEWIODELAY

		mov	ah,al

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret

Get_ADM9240_Word	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Word	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,ADM9240_ID
		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,06
		mov	al,ah
		out	dx,al			;Data1
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,4ch
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY

		ret

Set_ADM9240_Word	Endp
endif;	PIIX_ID

ifdef	M1543
ifndef	ADM9240_ID
ADM9240_ID	EQU	58h
endif;	ADM9240_ID
;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_ADM9240_Byte
		public	Set_ADM9240_Byte
		public	Get_ADM9240_Word
		public	Set_ADM9240_Word
Get_ADM9240_Byte	Proc	Near

		push	cx

		call	Wait_SMBUS_Idle_Status	;R03

		mov	dx,SMBus_Port +03h
		mov	al,(ADM9240_ID + 1)	;LM78 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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Byte	Proc	Near

		push	ax
		push	cx

		call	Wait_SMBUS_Idle_Status	;R03

		mov	dx,SMBus_Port +03h
		mov	al,ADM9240_ID		;LM78 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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_ADM9240_Word	Proc	Near

		push	cx

		call	Wait_SMBUS_Idle_Status	;R03

		mov	dx,SMBus_Port +03h
		mov	al,(ADM9240_ID + 1)	;LM78 read cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		mov	dl,01h
		mov	al,30h
		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,05h
		in	al,dx			;Data1
		NEWIODELAY
		NEWIODELAY

		mov	ah,al

		mov	dl,04h
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
Get_ADM9240_Word	endp

;[]==============================================================[]
;Input : CL - register index
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Word	Proc	Near

		push	ax
		push	cx

		call	Wait_SMBUS_Idle_Status	;R03

		mov	dx,SMBus_Port +03h
		mov	al,ADM9240_ID		;ADM9240 write cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		mov	dl,01h
		mov	al,30h
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,07h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		pop	ax
		mov	dl,04
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY

		mov	dl,05
		mov	al,ah
		out	dx,al			;Data1
		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_ADM9240_Word	Endp

;R03 - 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
;R03 - end
endif;	M1543

ifdef   VT586_ACPI		; VIA Chipset
  IF		VIA_SMBus	EQ	0		;R01
;R05
;R05ifdef	SDA_In_GPIO1
;R05SDA             EQU     02	;GPIO1 Data
;R05SCL             EQU     04	;GPIO2 Clock
;R05else;	SDA_In_GPIO1
;R05SDA             EQU     04	;GPIO2 Data (Normal)
;R05SCL             EQU     02	;GPIO1 Clock
;R05endif;	SDA_In_GPIO1
;R05
;R05ifndef	ADM9240_ID
;R05ADM9240_ID	EQU	58h
;R05endif;	ADM9240_ID
;R05GPIO_Dir        EQU     ACPI_Port+40h
;R05GPIO_WPort      EQU     ACPI_Port+42h
;R05GPIO_RdPort     EQU     ACPI_Port+44h
;R05
;R05		extrn	Dir_Out:Near
;R05		extrn	Set_Start:Near
;R05		extrn	Wr_Byte:Near
;R05		extrn	Wait_ACK:Near
;R05		extrn	Set_Stop:Near
;R05		extrn	E000_Get_PMIO:near
;R05		extrn	E000_Set_PMIO:near
;R05		extrn	E000_Get_Set_PMIO:near
;R05		extrn	E000_Get_Set_PMIO_OR:near
;R05		extrn	E000_Get_Set_PMIO_AND:near
;R05;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R05;บ  Set_Pointer                                                             บ
;R05;บ  Input:  BX = pointer                                                    บ
;R05;บ  Output: CLC = PK                                                        บ
;R05;บ          STC = Fail                                                      บ
;R05;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R05Set_Pointer     proc
;R05		push    bx              ;Save Register Pointer
;R05		call    Dir_Out
;R05		call    Set_Start
;R05		mov     bl,ADM9240_ID
;R05		call    Wr_Byte
;R05		call    Wait_ACK
;R05		pop     bx
;R05		jc      ErrSet_Pointer
;R05		call    Wr_Byte         ;bx = pointer
;R05		call    Wait_ACK
;R05		jc      ErrSet_Pointer
;R05		clc
;R05		ret
;R05ErrSet_Pointer:
;R05		stc
;R05		ret
;R05Set_Pointer     endp
;R05
;R05;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R05;บ  Rd_Data                                                                 บ
;R05;บ                                                                          บ
;R05;บ  Input:  None                                                            บ
;R05;บ  Output: BL: return data                                                 บ
;R05;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R05Rd_Data proc
;R05		mov     cx,40h
;R05		mov     bl, NOT SDA
;R05		mov	bh, SCL
;R05		call    E000_Get_Set_PMIO
;R05
;R05		xor     bx, bx
;R05		xor     ax, ax
;R05		mov     cx, 8
;R05Rd_byte:
;R05		push    cx
;R05		mov     cx, 8                           ;T(low) = 4.7 us
;R05@@:
;R05		out     0ebh, al
;R05		loop    short @B
;R05		mov     dx,GPIO_WPort		;
;R05		in	al, dx			
;R05		or      al, SCL			;
;R05		out     dx, al                  ; SCL high, receiver will read data
;R05		mov     cx, 8                           ;T(high) = 4 us
;R05@@:
;R05		out     0ebh, al
;R05		loop    short @B
;R05
;R05		mov     cx,44h
;R05
;R05		call    E000_Get_PMIO
;R05
;R05		and     al, SDA
;R05ifdef	SDA_In_GPIO1
;R05		shr     al, 1		;;if SDA=02h, SCL=04h
;R05else;	SDA_In_GPIO1
;R05		shr     al, 2		;;if SDA=04h, SCL=02h
;R05endif;	SDA_In_GPIO1
;R05		shl     bl, 1
;R05		or      bl, al
;R05
;R05		mov     dx, GPIO_WPort		;
;R05		in	al, dx			;
;R05		and     al, NOT SCL             ; SCL low
;R05		out	dx, al			;
;R05
;R05		pop     cx
;R05		loop    Rd_byte
;R05
;R05		mov     cx, 8                           ;T(hd)
;R05@@:
;R05		out     0ebh, al
;R05		loop    short @B
;R05
;R05		mov     dx,GPIO_Dir
;R05		in      al, dx
;R05		or      al, SDA
;R05		or      al, SCL
;R05		out     dx, al                  ; Set SCL O/P , SDA I/P
;R05
;R05		ret
;R05Rd_Data endp
;R05
;R05
;R05;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R05;บ  Set_NoACK                                                               บ
;R05;บ                                                                          บ
;R05;บ  Input:  None                                                            บ
;R05;บ  Output: None                                                            บ
;R05;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R05Set_NoACK       proc
;R05		mov     dx,GPIO_WPort
;R05		in      al, dx
;R05		and     al, NOT SCL
;R05		or      al, SDA
;R05		out     dx, al                  ; out No ACK
;R05
;R05		out     0ebh, al                ;T(setup) = 250 ns
;R05
;R05		or      al, SCL
;R05		out     dx, al                  ;SCL ,SDA = high
;R05		mov     cx, 8                   ;T(high) = 4 us
;R05@@:
;R05		out     0ebh, al
;R05		loop    short @B
;R05
;R05		and     al, NOT SCL
;R05		out     dx, al                  ;SCL = low
;R05		out     0ebh, al
;R05
;R05		and     al, NOT SDA
;R05		out     dx, al                  ;SDA = low
;R05		out     0ebh, al
;R05
;R05		ret
;R05Set_NoACK       endp
;R05
;R05;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R05;บ  Set_ACK                                                                 บ
;R05;บ                                                                          บ
;R05;บ  Input:  None                                                            บ
;R05;บ  Output: None                                                            บ
;R05;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R05Set_ACK proc
;R05		mov     cx,42h
;R05		mov     bl, NOT SCL
;R05		and	bl, NOT SDA
;R05		call    E000_Get_Set_PMIO_AND
;R05
;R05		out     0ebh, al                ;T(setup) = 250 ns
;R05
;R05		mov	dx,GPIO_WPort		
;R05		in	al, dx			
;R05		or      al, SCL
;R05		out     dx, al                  ;SCL ,SDA = high
;R05		mov     cx, 8                   ;T(high) = 4 us
;R05@@:
;R05		out     0ebh, al
;R05		loop    short @B
;R05		and     al, NOT SCL
;R05		out     dx, al                  ;SCL = low
;R05		out     0ebh, al
;R05
;R05		and     al, NOT SDA
;R05		out     dx, al                  ;SDA = low
;R05		out     0ebh, al
;R05		ret
;R05Set_ACK endp

;[]==============================================================[]
;Input	: CL - register index
;	  CH - Device ID
;Output : AL - Value read
;[]==============================================================[]
		public	Get_ADM9240_Byte
		public	Set_ADM9240_Byte
		public	Get_ADM9240_Word
		public	Set_ADM9240_Word
Get_ADM9240_Byte	Proc	Near
		mov	ch, ADM9240_ID	;R05
		mov     bl,cl
		call    Set_Pointer
		NEWIODELAY
		NEWIODELAY
		call    Set_Start
		mov     bl,ADM9240_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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Byte	Proc	Near

		push    ax
		mov     bl,cl
		cli
		mov	ch, ADM9240_ID	;R05
		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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;	  CH - Device ID
;Output : AX - Value read
;[]==============================================================[]
Get_ADM9240_Word	Proc	Near
		mov	ch,ADM9240_ID	;R05
		mov     bl,cl
		call    Set_Pointer
		NEWIODELAY
		NEWIODELAY
		call    Set_Start
		mov     bl,ADM9240_ID
		inc     bl              ;for read operation
		call    Wr_Byte
		call    Wait_ACK
		jc      Rd_2ByteReg_Fail
                call    Rd_Data
		shl     ebx,16
		call    Set_ACK
		call    Rd_Data
		mov     bh,bl
		shl     ebx,8
		call    Set_NoACK
		call    Set_Stop
		shr     ebx,16
		mov     ax,bx
		clc
		ret
Rd_2ByteReg_Fail:
		stc
		ret
Get_ADM9240_Word	Endp

;[]==============================================================[]
;Input : CL - register index
;	 CH - Device ID
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Word	Proc	Near
		push    ax
		mov     bx,cx
		push    bx
		call    Set_Start
		mov     bl,ADM9240_ID
		call    Wr_Byte
		call    Wait_ACK
		jc      Wr_2ByteReg_Fail
		pop     bx
		call    Wr_Byte                 ;bx = TempPoint
		call    Wait_ACK
		jc      Wr_2ByteReg_Fail
		pop     ax
		push    ax
		mov     bl,al
		call    Wr_Byte
		call    Wait_ACK
		jc      Wr_2ByteReg_Fail
		pop     ax
		shr     ax,8
		mov     bl,al
		call    Wr_Byte
		call    Wait_ACK
		jc      Wr_2ByteReg_Fail
		call    Set_Stop
		clc
		ret
Wr_2ByteReg_Fail:
		stc
		ret
Set_ADM9240_Word	Endp

  ENDIF;	VIA_SMBus	EQ	0		;R01
endif;	VT586_ACPI

;R01 - starts
if	VIA_SMBus
  IFNDEF	ADM9240_ID
ADM9240_ID	EQU	58h
  ENDIF;	ADM9240_ID
;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_ADM9240_Byte
		public	Set_ADM9240_Byte
		public	Get_ADM9240_Word
		public	Set_ADM9240_Word
		
Get_ADM9240_Byte	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(ADM9240_ID + 1)	;ADM9240 read cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Byte	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,ADM9240_ID		;ADM9240 write cmd
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,03h
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY
		call	Chk_SMBus_READY 

		pop	ax
		mov	dl,05
		out	dx,al			;Data0
		NEWIODELAY
		NEWIODELAY
		call	Chk_SMBus_READY 

		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_ADM9240_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_ADM9240_Word	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(ADM9240_ID + 1)
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY

		mov	dl,03h
		pop	ax
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,4ch
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY

		mov	dl,06
		in	al,dx			;Data1
		NEWIODELAY
		NEWIODELAY

		mov	ah,al

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret

Get_ADM9240_Word	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Word	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,ADM9240_ID
		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,06
		mov	al,ah
		out	dx,al			;Data1
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,4ch
		out	dx,al			;write data
		NEWIODELAY
		NEWIODELAY

		xor	cx,cx
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY

		ret

Set_ADM9240_Word	Endp
endif;	VIA_SMBus
;R01 - ends

;R04SIS_SMBus	=	0
;R04ifdef   SIS_5598_PCI_RESET		
;R04SIS_SMBus	=	1
;R04endif;  SIS_5598_PCI_RESET		
;R04ifdef   SIS5595_ID
;R04SIS_SMBus	=	1
;R04endif;  SIS5595_ID

if	SIS_SMBus		; SiS Chipset

ifndef	ADM9240_ID
ADM9240_ID	EQU	58h
endif;	ADM9240_ID

;R04SDA             EQU     10h	;I2C Data 
;R04SCL             EQU     08h	;I2C Clock
;R04
;R04		extrn	F000_Get_CT:near
;R04		extrn	F000_Set_CT:near
;R04
;R04DelayIO:
;R04		push	cx
;R04		mov	cx,300h
;R04	@@:
;R04		newiodelay
;R04		loop	@B
;R04		pop	cx
;R04		ret
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Set_Start                                                               บ
;R04;บ  Input:  None                                                            บ
;R04;บ  Output: None                                                            บ
;R04;บ                                                                          บ
;R04;บ  SDA  ----\___                                                           บ
;R04;บ  SCL  -------\                                                           บ
;R04;บ       1   2                                                              บ
;R04;บ        4us 4us                                                           บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Set_Start       proc	Near
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04        	or	al, SCL
;R04        	call	F000_Set_Ct
;R04        
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04        	or	al, SDA
;R04        	call	F000_Set_Ct
;R04
;R04		call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al,NOT SDA
;R04        	call	F000_Set_Ct
;R04                NEWIODELAY      
;R04                NEWIODELAY      
;R04                NEWIODELAY      
;R04
;R04                call	DelayIO			
;R04        
;R04;For 1'st clock low time
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al,NOT SCL
;R04        	call	F000_Set_Ct
;R04
;R04                call	DelayIO			
;R04        
;R04                ret
;R04Set_Start       endp
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Wr_Byte                                                                 บ
;R04;บ                                                                          บ
;R04;บ  Input:   BL:Data to I2C Bus                                             บ
;R04;บ  Output: None                                                            บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Wr_Byte		proc	Near
;R04
;R04                pusha					
;R04        	mov	cx,086dh
;R04                call	F000_Get_Ct			
;R04                and     al,NOT SCL			
;R04                call	F000_Set_Ct			
;R04                popa					
;R04
;R04                mov     dx,bx
;R04                mov     cx ,8
;R04write_B:
;R04                push    cx
;R04                NEWIODELAY      
;R04                NEWIODELAY      
;R04                NEWIODELAY      
;R04
;R04                xor     dh,dh   
;R04                shl     dx,1    
;R04                shl     dh,4            ;;if SDA=10h, SCL=08h
;R04        	mov	bl,dh
;R04
;R04        	push	dx
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al,NOT SDA              
;R04                or      al,bl			;data                   
;R04        	call	F000_Set_Ct
;R04                NEWIODELAY      
;R04        
;R04                call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                or      al,SCL			
;R04        	call	F000_Set_Ct
;R04                call	DelayIO			
;R04                NEWIODELAY      
;R04                NEWIODELAY      
;R04                NEWIODELAY      
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al,NOT SCL		
;R04        	call	F000_Set_Ct
;R04                call	DelayIO			
;R04        
;R04        	pop	dx
;R04                pop     cx
;R04                loop    write_B
;R04                ret
;R04Wr_Byte endp
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Wait_ACK                                                                บ
;R04;บ                                                                          บ
;R04;บ  Input:  None                                                            บ
;R04;บ  Output: CLR :  Acknowledge                                              บ
;R04;บ          STC : !Acknowledge                                              บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Wait_ACK        proc	Near
;R04        	mov	cx,086dh
;R04                call	F000_Get_Ct		
;R04                and     al, not SCL		
;R04                call	F000_Set_Ct		
;R04                call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                or      al, SCL			
;R04        	call	F000_Set_Ct
;R04
;R04                call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04                call	F000_Get_Ct		
;R04                and	al,NOT SCL		
;R04                call	F000_Set_Ct		
;R04                call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                call	DelayIO			
;R04                mov     bl, al			
;R04        	and	al,NOT SCL
;R04        	call	F000_Set_Ct
;R04                call	DelayIO			
;R04        
;R04                test    bl, SDA
;R04                jnz     short ACK_Err_ret
;R04                clc
;R04                ret
;R04ACK_Err_ret:
;R04	        stc
;R04        	ret
;R04Wait_ACK        endp
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Set_Stop                                                                บ
;R04;บ                                                                          บ
;R04;บ  Input:  None                                                            บ
;R04;บ  Output: None                                                            บ
;R04;บ  SDA  ___/-----                                                          บ
;R04;บ  SCL  ---------                                                          บ
;R04;บ       1  2   3                                                           บ
;R04;บ        4us 4us                                                           บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Set_Stop        proc	Near
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al,not SCL
;R04        	call	F000_Set_Ct
;R04        	call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al,NOT SDA
;R04        	call	F000_Set_Ct
;R04        	call	DelayIO
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                or      al,SCL
;R04        	call	F000_Set_Ct
;R04        	call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                or      al,SDA
;R04        	call	F000_Set_Ct
;R04        	call	DelayIO			
;R04
;R04                ret
;R04Set_Stop        endp
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Set_Pointer                                                             บ
;R04;บ  Input:  BX = pointer                                                    บ
;R04;บ  Output: CLC = PK                                                        บ
;R04;บ          STC = Fail                                                      บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Set_Pointer     proc	near
;R04                push    bx              ;Save Register Pointer
;R04                call    Set_Start
;R04                mov     bl,ADM9240_ID
;R04                call    Wr_Byte
;R04                call    Wait_ACK
;R04                pop     bx
;R04                jc      ErrSet_Pointer
;R04                call    Wr_Byte         ;bx = pointer
;R04                call    Wait_ACK
;R04                jc      ErrSet_Pointer
;R04                clc
;R04                ret
;R04ErrSet_Pointer:
;R04                stc
;R04                ret
;R04Set_Pointer     endp
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Rd_Data                                                                 บ
;R04;บ                                                                          บ
;R04;บ  Input:  None                                                            บ
;R04;บ  Output: BL: return data                                                 บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Rd_Data 	proc
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04        	and	al, not SCL
;R04        	call	F000_Set_Ct
;R04        	call	DelayIO			
;R04        
;R04                xor     bx, bx
;R04                xor     ax, ax
;R04                mov     cx, 8
;R04Rd_byte:
;R04                push    cx
;R04                mov     cx, 8                           ;T(low) = 4.7 us
;R04@@:
;R04        	NEWIODELAY
;R04                loop    short @B
;R04
;R04        	mov	cx,086dh		
;R04        	call	F000_Get_Ct		
;R04        	or	al, SDA			
;R04        	call	F000_Set_Ct		
;R04        	call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04        	or	al, SCL
;R04        	call	F000_Set_Ct		;SCL high, receiver will read data
;R04        	call	DelayIO			
;R04
;R04                mov     cx, 8                   ;T(high) = 4 us
;R04	@@:
;R04        	NEWIODELAY
;R04                loop    short @B
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04
;R04        	push	ax
;R04                and     al, SDA 
;R04                shr     al, 4
;R04                shl     bl, 1           
;R04                or      bl, al
;R04        	pop	ax
;R04                and     al, NOT SCL                     ;SCL low
;R04        	mov	cx,086dh
;R04        	call	F000_Set_Ct
;R04        	call	DelayIO			
;R04
;R04                pop     cx
;R04                loop    short Rd_byte
;R04
;R04                mov     cx, 8                           ;T(hd)
;R04        @@:
;R04        	NEWIODELAY
;R04                loop    short @B
;R04
;R04                ret
;R04Rd_Data endp
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Set_NoACK                                                               บ
;R04;บ                                                                          บ
;R04;บ  Input:  None                                                            บ
;R04;บ  Output: None                                                            บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Set_NoACK       proc
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al, NOT SCL
;R04        	call	F000_Set_Ct		;out No ACK
;R04        	call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                or      al, SDA
;R04        	call	F000_Set_Ct		;out No ACK
;R04        	call	DelayIO			
;R04
;R04                NEWIODELAY                	;T(setup) = 250 ns
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                or      al, SCL
;R04        	call	F000_Set_Ct		;SCL ,SDA = high
;R04                call	DelayIO			
;R04
;R04                mov     cx, 8                   ;T(high) = 4 us
;R04        @@:
;R04                NEWIODELAY
;R04                loop    short @B
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al, not SCL
;R04        	call	F000_Set_Ct		;SCL = low
;R04
;R04        	call	DelayIO			
;R04
;R04                ret
;R04Set_NoACK       endp
;R04
;R04;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R04;บ  Set_ACK                                                                 บ
;R04;บ                                                                          บ
;R04;บ  Input:  None                                                            บ
;R04;บ  Output: None                                                            บ
;R04;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R04Set_ACK 	proc
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al, NOT SCL
;R04                and     al, NOT SDA
;R04        	call	F000_Set_Ct		
;R04                NEWIODELAY                	;T(setup) = 250 ns
;R04        	call	DelayIO			
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                or      al, SCL
;R04        	call	F000_Set_Ct		;SCL = high
;R04        	call	DelayIO			
;R04
;R04                mov     cx, 8                   ;T(high) = 4 us
;R04        @@:
;R04                NEWIODELAY
;R04                loop    short @B
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al, NOT SCL
;R04        	call	F000_Set_Ct		;SCL = low
;R04        	call	DelayIO			
;R04                NEWIODELAY
;R04
;R04        	mov	cx,086dh
;R04        	call	F000_Get_Ct
;R04                and     al, NOT SDA
;R04        	call	F000_Set_Ct		;SDA = low
;R04        	call	DelayIO			
;R04                NEWIODELAY
;R04
;R04                ret
;R04Set_ACK endp

;[]==============================================================[]
;Input  : CL - register index
;Output : AL - Value read
;[]==============================================================[]
                public  Get_ADM9240_Byte
                public  Set_ADM9240_Byte
                public  Get_ADM9240_Word
                public  Set_ADM9240_Word
Get_ADM9240_Byte   Proc    Near
                mov     ch,ADM9240_ID		;R06
                mov     bl,cl
                call    Set_Pointer
                NEWIODELAY
                NEWIODELAY
                call    Set_Start
                mov     bl,ADM9240_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_ADM9240_Byte   Endp

;[]==============================================================[]
;Input : CL - register index
;        AL - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Byte   Proc    Near

                push    ax      
                mov     ch,ADM9240_ID		;R06
                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_ADM9240_Byte   Endp

;[]==============================================================[]
;Input  : CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_ADM9240_Word   Proc    Near

                mov     ch,ADM9240_ID		;R06
                mov     bl,cl					
                call    Set_Pointer				
                NEWIODELAY					
                NEWIODELAY					
                call    Set_Start
                mov     bl,ADM9240_ID
                inc     bl              ;for read operation
                call    Wr_Byte
                call    Wait_ACK
                jc      Rd_2ByteReg_Fail
                call    Rd_Data 
                shl     ebx,16
                call    Set_ACK
                call    Rd_Data 
                mov     bh,bl
                shl     ebx,8
                call    Set_NoACK
                call    Set_Stop
                shr     ebx,16
                mov     ax,bx
                clc
                ret
Rd_2ByteReg_Fail:
                stc
                ret
Get_ADM9240_Word   endp

;[]==============================================================[]
;Input : CL - register index
;        AX - Value to write
;Output: none
;[]==============================================================[]
Set_ADM9240_Word   Proc    Near

                push    ax
                mov     bx,cx
                push    bx
                call    Set_Start
                mov     bl,ADM9240_ID
                call    Wr_Byte
                call    Wait_ACK
                jc      Wr_2ByteReg_Fail
                pop     bx
                call    Wr_Byte                 ;bx = TempPoint
                call    Wait_ACK
                jc      Wr_2ByteReg_Fail
                pop     ax      
                push    ax     			
                mov     bl,al
                call    Wr_Byte
                call    Wait_ACK
                jc      Wr_2ByteReg_Fail
                pop     ax      		
                shr     ax,8    
                mov     bl,al
                call    Wr_Byte
                call    Wait_ACK
                jc      Wr_2ByteReg_Fail
                call    Set_Stop
                clc
                ret
Wr_2ByteReg_Fail:
                stc
                ret
Set_ADM9240_Word   Endp
endif;	SIS_SMBus		
%							;R07
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	;detect sensor
		test	word ptr es:[di],01h
		jz	short No_Sensor

		mov	di,offset DGROUP:TEMP1_HIGH
		extrn	ADM9240_CPUTEMP_ITEM:near
		mov	si,offset DGROUP:ADM9240_CPUTEMP_ITEM
		call	E_GetItem_Value
ifdef	No_CPU_Temp_Selectable
		mov	si,offset ADM9240_CPUTEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	No_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:
		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_ADM9240_Chip	;R02
Prg_ADM9240_Chip	Proc	Near

		mov	cl, 48h
		mov	al, 2ch
		call	Set_ADM9240_Byte

		mov	cl,48h
		call	Get_ADM9240_Byte
		jnc	short	@f
	;Disable items by change item's status
		push	ds
		mov	ax,0f000h
		mov	ds,ax

		extrn	Current_CPU_Temp_Item:near
		extrn	ADM9240_CPUTEMP_ITEM:near

ifdef	SHOW_ADM9240_CPUFAN1
		extrn	Current_CPUFAN1_Item:near
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
		extrn	Current_CPUFAN2_Item:near
endif;	SHOW_ADM9240_CPUFAN2
		extrn	Current_Vdd_Item:near
ifdef	Show_Current_Vd2
		extrn	Current_Vdd2_Item:near
endif;	Show_Current_Vd2
		extrn	Current_Vin1_Item:near
		extrn	Current_Vin2_Item:near
		extrn	Current_Vin3_Item:near
		extrn	Current_Vin4_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:[ADM9240_CPUTEMP_ITEM].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_CPU_Temp_Item].ITEMSTAT,ITEMDISABLE

ifdef	SHOW_ADM9240_CPUFAN1
		or	word ptr ds:[Current_CPUFAN1_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
		or	word ptr ds:[Current_CPUFAN2_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_ADM9240_CPUFAN2
		or	word ptr ds:[Current_Vdd_Item].ITEMSTAT,ITEMDISABLE
ifdef	Show_Current_Vd2
		or	word ptr ds:[Current_Vdd2_Item].ITEMSTAT,ITEMDISABLE
endif;	Show_Current_Vd2
		or	word ptr ds:[Current_Vin1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin3_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin4_Item].ITEMSTAT,ITEMDISABLE

ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		or	word ptr ds:[ACPI_Critical_Item].ITEMSTAT,ITEMDISABLE
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT
		f000_call	DGROUP:F000_Shadow_R
		pop	ds
		jmp	Prg_ADM9240_Chip_End

@@:
		mov	cx,5
	Clear_ADM9240:
		push	cx
		mov	cl,41h
		call	Get_ADM9240_Byte
		mov	cl,42h
		call	Get_ADM9240_Byte
		pop	cx
		loop	short	Clear_ADM9240

		mov	si,offset EGROUP:Prg_ADM9240_Tbl
	Init_Start:
		mov	cl,cs:[si]
		call	Get_ADM9240_Byte
		mov	cl,cs:[si]	   
		and	al,cs:[si+1]
		or	al,cs:[si+2]
		call	Set_ADM9240_Byte

		add	si,3
		cmp	si,offset EGROUP:Prg_ADM9240_Tbl_End
		jne	short Init_Start

		mov	si,offset DGROUP:ADM9240_CPUTEMP_ITEM
		call	E_GetItem_Value
ifdef	No_CPU_Temp_Selectable
		or	al,al
		jz	short CPU_Temp_Disable
		mov	si,offset EGROUP:ADM9240_CPUTEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	No_CPU_Temp_Selectable
		push	ax
		xor	ah,ah
		mov	cl,39h
		call	Set_ADM9240_Byte		;set Tos (High limit)

		pop	ax

		sub	al,5
		xor	ah,ah
		mov	cl,3ah
		call	Set_ADM9240_Byte		;set Thyst (Low limit)

CPU_Temp_Disable:
		mov	cl,40h
		call	Get_ADM9240_Byte
		mov	al, 03h
		mov	cl,40h
		call	Set_ADM9240_Byte		;Start ADM9240

Prg_ADM9240_Chip_End:

		ret

Prg_ADM9240_Chip	Endp

		assume	ds:EGROUP
ifdef	No_CPU_Temp_Selectable
		ALIGN	4
ADM9240_CPUTEMP_VAL:
		db	0120	;disabled
		db	051	;50C		51=(50/0.9874)
		db	054	;53C		
		db	057	;56C		
		db	061	;60C		
		db	064	;63C		
		db	067	;66C		
		db	071	;70C		
endif;	No_CPU_Temp_Selectable

		ALIGN	4
		;---------------------------
		;      index  	and	or
		;---------------------------
Prg_ADM9240_Tbl:
		db	40h,	000h,	080h
		db	43h,	000h,	0ffh
		db	44h,	000h,	0efh		
		db	46h,	000h,	080h		
ifndef	FAN_Divisor				
		db	47h,	00fh,	050h		
else;
	if	FAN_Divisor 	eq	4
		db	47h,	00fh,	0a0h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
		db	47h,	00fh,	0f0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
ifdef	One_Time_Mode
		db	4Bh,	080h,	001h		
endif;	One_Time_Mode
ifdef	Comparator_mode
		db	4Bh,	080h,	002h		
endif;	Comparator_mode

Prg_ADM9240_Tbl_End:

endif	;SENSOR_IN_XGROUP			;R08
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 ADM9240_CPUTEMP_ITEM, offset Show_Scale		
endif;	No_CPU_Temp_Selectable
		dw	offset Current_CPU_Temp_Item, offset Show_Current_CPU_Temp
ifdef	SHOW_ADM9240_CPUFAN1
		dw	offset Current_CPUFAN1_Item, offset Show_Current_CPUFAN1
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
		dw	offset Current_CPUFAN2_Item, offset Show_Current_CPUFAN2
endif;	SHOW_ADM9240_CPUFAN2
		dw	offset Current_Vdd_Item, offset Show_Current_Vdd
ifdef	Show_Current_Vd2
		dw	offset Current_Vdd2_Item, offset Show_Current_Vdd2
endif;	Show_Current_Vd2
		dw	offset Current_Vin1_Item, offset Show_Current_Vin1
		dw	offset Current_Vin2_Item, offset Show_Current_Vin2
		dw	offset Current_Vin3_Item, offset Show_Current_Vin3
		dw	offset Current_Vin4_Item, offset Show_Current_Vin4

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_ADM9240_Item	;R02
First_ADM9240_Item	Label	Near		;R02

ifdef	No_CPU_Temp_Selectable
DEFINE_ITEM     ADM9240_CPUTEMP_ITEM
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <PMITEM,\
                  offset ADM9240_CPUTEMP_Str,NOCT,ADM9240_CMOS_BITS,ADM9240_CMOS,ADM9240_CMOS_BITS,\
                  offset CPU_TEMP_STR,0,7,Xaxis,Yaxis ,   00000000b, 00000000b,offset Std_Help_Str>

else;	No_CPU_Temp_Selectable
DEFINE_ITEM     ADM9240_CPUTEMP_ITEM
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
	menuitem <NOMODBIN+SHOWNUM+DIGIT3,\
		  offset ADM9240_CPUTEMP_Str,NOCT,00000000b,ADM9240_CMOS,01111111b,\
		  offset Nullstr,30,120,Xaxis,Yaxis,120,30,offset Nullstr>
endif;	No_CPU_Temp_Selectable

DEFINE_ITEM	Current_CPU_Temp_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_CPU_Temp_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

ifdef	SHOW_ADM9240_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;	SHOW_ADM9240_CPUFAN1

ifdef	SHOW_ADM9240_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;	SHOW_ADM9240_CPUFAN2

DEFINE_ITEM	Current_Vdd_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_Vdd_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

ifdef	Show_Current_Vd2
DEFINE_ITEM	Current_Vdd2_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_Vdd2_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>
endif;	Show_Current_Vd2

DEFINE_ITEM	Current_Vin1_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_Vin1_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

DEFINE_ITEM	Current_Vin2_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_Vin2_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

DEFINE_ITEM	Current_Vin3_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_Vin3_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

DEFINE_ITEM	Current_Vin4_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <SHOWONLY,\
                  offset Current_Vin4_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

ifdef	ACPI_SUPPORT
DEFINE_ITEM     ACPI_Critical_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10
        menuitem <PMITEM,\
                  offset ACPI_Critical_Str           ,NOCT,00011000b,ADM9240_ACPI_CMOS,ADM9240_ACPI_CMOS_BITS,\
                  offset Critical_str,0,3,Xaxis,Yaxis,00000000b,    00000000b,offset Std_Help_Str>
endif	;ACPI_SUPPORT

		Public	Last_ADM9240_Item	;R02
Last_ADM9240_Item	Label	Near		;R02

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
ADM9240_CPUTEMP_Str	db      'CPU Warning Temperature'
			db	(COLLON_LOC - ($-(offset ADM9240_CPUTEMP_Str))) dup (" ")
ifdef	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_Str		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
endif;	No_CPU_Temp_Selectable

Current_CPU_Temp_Str	db	'Current CPU Temperature'
			db	(COLLON_LOC - ($-(offset Current_CPU_Temp_Str))) dup (" ")
			db	': ',0

ifdef	SHOW_ADM9240_CPUFAN1
Current_CPUFAN1_Str	db	'Current CPUFAN1 Speed'
			db	(COLLON_LOC - ($-(offset Current_CPUFAN1_Str))) dup (" ")
			db	': ',0
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
Current_CPUFAN2_Str	db	'Current CPUFAN2 Speed'
			db	(COLLON_LOC - ($-(offset Current_CPUFAN2_Str))) dup (" ")
			db	': ',0
endif;	SHOW_ADM9240_CPUFAN2

Current_Vdd_Str		db	'Current Vcpp1(V)'
			db	(COLLON_LOC - ($-(offset Current_Vdd_Str))) dup (" ")
			db	': ',0

ifdef	Show_Current_Vd2
Current_Vdd2_Str	db	'Current Vcpp2(V)'
			db	(COLLON_LOC - ($-(offset Current_Vdd2_Str))) dup (" ")
			db	': ',0
endif;	Show_Current_Vd2

Current_Vin1_Str	db	'Current Vin12(V)'
			db	(COLLON_LOC - ($-(offset Current_Vin1_Str))) dup (" ")
			db	': ',0

Current_Vin2_Str	db	'Current Vin5(V)'
			db	(COLLON_LOC - ($-(offset Current_Vin2_Str))) dup (" ")
			db	': ',0		

Current_Vin3_Str	db	'Current Vin3.3(V)'
			db	(COLLON_LOC - ($-(offset Current_Vin3_Str))) dup (" ")
			db	': ',0

Current_Vin4_Str	db	'Current Vin2.5(V)'
			db	(COLLON_LOC - ($-(offset Current_Vin4_Str))) dup (" ")
			db	': ',0

;===============================================================
ifndef	No_CPU_Temp_Selectable
Show_Scale	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP				;R08
		Post_Func_Call E000_Show_Scale
else	;SENSOR_IN_XGROUP				;R08
		Xcall X_Show_Scale			;R08
endif	;SENSOR_IN_XGROUP				;R08
	@@:
		ret
Show_Scale	Endp
endif;	No_CPU_Temp_Selectable

Show_Current_CPU_Temp	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		Post_Func_Call E000_Show_Current_CPU_Temp
else	;SENSOR_IN_XGROUP					;R08
		Xcall X_Show_Current_CPU_Temp			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_CPU_Temp	Endp

ifdef	SHOW_ADM9240_CPUFAN1
Show_Current_CPUFAN1	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		Post_Func_Call E000_Show_Current_CPUFAN1
else	;SENSOR_IN_XGROUP					;R08
		Xcall X_Show_Current_CPUFAN1			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_CPUFAN1	Endp
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
Show_Current_CPUFAN2	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		Post_Func_Call E000_Show_Current_CPUFAN2
else	;SENSOR_IN_XGROUP					;R08
		Xcall X_Show_Current_CPUFAN2			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_CPUFAN2	Endp
endif;	SHOW_ADM9240_CPUFAN2

Show_Current_Vdd	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		post_func_call	E000_Show_Current_Vdd
else	;SENSOR_IN_XGROUP					;R08
		Xcall	X_Show_Current_Vdd			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_Vdd	Endp

ifdef	Show_Current_Vd2
Show_Current_Vdd2	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		post_func_call	E000_Show_Current_Vdd2
else	;SENSOR_IN_XGROUP					;R08
		Xcall	X_Show_Current_Vdd2			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_Vdd2	Endp
endif;	Show_Current_Vd2

Show_Current_Vin1	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		post_func_call	E000_Show_Current_Vin1
else	;SENSOR_IN_XGROUP					;R08
		Xcall	X_Show_Current_Vin1			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_Vin1	Endp

Show_Current_Vin2	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		post_func_call	E000_Show_Current_Vin2
else	;SENSOR_IN_XGROUP					;R08
		Xcall	X_Show_Current_Vin2			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_Vin2	Endp


Show_Current_Vin3	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		post_func_call	E000_Show_Current_Vin3
else	;SENSOR_IN_XGROUP					;R08
		Xcall	X_Show_Current_Vin3			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_Vin3	Endp

Show_Current_Vin4	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R08
		post_func_call	E000_Show_Current_Vin4
else	;SENSOR_IN_XGROUP					;R08
		Xcall	X_Show_Current_Vin4			;R08
endif	;SENSOR_IN_XGROUP					;R08
	@@:
		ret
Show_Current_Vin4	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		;R08

ifndef		Vdd_R1
Vdd_R1		equ	0
endif;		Vdd_R1
ifndef		Vdd_R2
Vdd_R2		equ	0
endif;		Vdd_R2

ifdef	Show_Current_Vd2
ifdef	Vdd2_Use_Negative_Input
ifndef		Vdd2_R1
Vdd2_R1		equ	27
endif;		Vdd2_R1
ifndef		Vdd2_R2
Vdd2_R2		equ	10
endif;		Vdd2_R2

else;	Vdd2_Use_Negative_Input
ifndef		Vdd2_R1
Vdd2_R1		equ	0
endif;		Vdd2_R1
ifndef		Vdd2_R2
Vdd2_R2		equ	0	
endif;		Vdd2_R2
endif;	Vdd2_Use_Negative_Input
endif;	Show_Current_Vd2

ifndef		Vin1_R1
Vin1_R1		equ	0
endif;		Vin1_R1
ifndef		Vin1_R2
Vin1_R2		equ	0
endif;		Vin1_R2

ifndef		Vin2_R1
Vin2_R1		equ	0
endif;		Vin2_R1
ifndef		Vin2_R2
Vin2_R2		equ	0
endif;		Vin2_R2

ifndef		Vin3_R1
Vin3_R1		equ	0
endif;		Vin3_R1
ifndef		Vin3_R2
Vin3_R2		equ	0
endif;		Vin3_R2

ifndef		Vin4_R1
Vin4_R1		equ	0
endif;		Vin4_R1
ifndef		Vin4_R2
Vin4_R2		equ	0
endif;		Vin4_R2

ifndef	No_CPU_Temp_Selectable
E000_Show_Scale	Proc	Near
	     	extrn	E_GetItem_Value:near
		mov	si,offset DGROUP:ADM9240_CPUTEMP_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_Current_CPU_Temp	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl, 27h
		call	E000_Get_ADM9240_Byte
		cmp	al,100
		jbe	short OK_Temp
		mov	al,0
	OK_Temp:

		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_Current_CPU_Temp	Endp

ifdef	SHOW_ADM9240_CPUFAN1
E000_Show_Current_CPUFAN1	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,28h
		call 	E000_Get_ADM9240_Byte
		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,4cb8h		;0a4cb8h=(1350000/2)
		mov	dx,0ah			;Count=(1350000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,265ch		;05265ch=(1350000/4)
		mov	dx,05h			;Count=(1350000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,932eh		;02932eh=(1350000/8)
		mov	dx,02h			;Count=(1350000/(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;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2

E000_Show_Current_CPUFAN2	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,29h
		call 	E000_Get_ADM9240_Byte
		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,4cb8h		;0a4cb8h=(1350000/2)
		mov	dx,0ah			;Count=(1350000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,265ch		;05265ch=(1350000/4)
		mov	dx,05h			;Count=(1350000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,932eh		;02932eh=(1350000/8)
		mov	dx,02h			;Count=(1350000/(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;	SHOW_ADM9240_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			;R2
		push	dx			;R1+R2
		push	ax
		mov	ax, cx			;max range
		mov	bl, 192			;(Vmax/192)
		div	bl
		mov	bl, al			;al=ratio 
		pop	ax
		xor	ah,ah
		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:

		push	ax
		mov	ax, cx			;max range
		mov	bl, 192			;(Vmax/192)
		div	bl
		mov	bl, al
		pop	ax
		xor	ah,ah
		mul	bl

		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_Vdd	Proc	Near

		cmp	al,0ffh
		jne	short Vdd_WORKING
		xor	ax,ax
	Vdd_WORKING:

		or	dx,dx			;Is above 4 Voltage
		jz	short Below4dd		;No, go to below 4V handler

		push	bx			;(R2)
		push	dx			;(R1)
		xor	ah,ah
		mov	bl,14			;(3586/255)
		mul	bl
	

		pop	bx			;(R1)
		mul	bx
		pop	bx			;(R2)
		div	bx
		mov	bx, 13500
		sub	bx, ax
		mov	ax, bx


		xor	dx,dx
		mov	bx,1000			;recover to source value
		div	bx
		push	dx

		push	ax
		mov	al, '-'
		call	E000_Display_Char
		pop	ax
		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9Bdd
		call	E000_DISP_Byte_INT2
		jmp	short Above_9Bdd
	Below_9Bdd:
		call	E000_DISP_Byte_HEX2
	Above_9Bdd:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret

	Below4dd:
                xor     ah,ah

                mov     bl, 14                   ;(3586/255)
		mul	bl

		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_9Add
		call	E000_DISP_Byte_INT2
		jmp	short Above_9Add
	Below_9Add:
		call	E000_DISP_Byte_HEX2
	Above_9Add:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret
Display_Vdd	endp


E000_Show_Current_Vdd	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,21h
		call 	E000_Get_ADM9240_Byte

;Vdd=(V(rd))*(3.586/256)*((R1+R2)/R2)

		mov	dx,(Vdd_R1+Vdd_R2)
		mov	bx, Vdd_R2

		call	Display_Vdd
	@@:
		ret

E000_Show_Current_Vdd	endp

ifdef	Show_Current_Vd2
E000_Show_Current_Vdd2	Proc	Near
		cmp	al, Special_Before
		je	short @F

		mov	cl,25h
		call	E000_Get_ADM9240_Byte
		out	90h, al
;Vdd=(V(rd))*(3.586/256)*((R1+R2)/R2)

ifdef	Vdd2_Use_Negative_Input
		mov	dx, Vdd2_R1
else;	Vdd2_Use_Negative_Input
		mov	dx,(Vdd2_R1+Vdd2_R2)
endif;	Vdd2_Use_Negative_Input
		mov	bx, Vdd2_R2
		call	Display_Vdd
	@@:
		ret
E000_Show_Current_Vdd2	endp
endif;	Show_Current_Vd2

E000_Show_Current_Vin1	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,24h
		call	E000_Get_ADM9240_Byte
;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)

		mov	dx,(Vin1_R1+Vin1_R2)
		mov	bx,Vin1_R2
		mov	cx, 12063			;Maximum Vin1
		call	Display_Vin
	@@:
		ret

E000_Show_Current_Vin1	endp


E000_Show_Current_Vin2	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,23h
		call	E000_Get_ADM9240_Byte

;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)
		mov	dx,(Vin2_R1+Vin2_R2)
		mov	bx,Vin2_R2
		mov	cx, 5026
		call	Display_Vin
	@@:
		ret

E000_Show_Current_Vin2	endp

E000_Show_Current_Vin3	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,22h
		call	E000_Get_ADM9240_Byte

;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)

		mov	dx,(Vin3_R1+Vin3_R2)
		mov	bx,Vin3_R2
		mov	cx, 3317
		call	Display_Vin
	@@:
		ret

E000_Show_Current_Vin3	endp

E000_Show_Current_Vin4	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,20h
		call	E000_Get_ADM9240_Byte

;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)

		mov	dx,(Vin4_R1+Vin4_R2)
		mov	bx,Vin4_R2
		mov	cx, 2513
		call	Display_Vin
	@@:
		ret

E000_Show_Current_Vin4	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_Display_Char	proc	near
		F000_call	Display_Char
		ret
E000_Display_Char	endp

E000_Get_ADM9240_Byte	proc	near
		post_func_call	Get_ADM9240_Byte
		ret
E000_Get_ADM9240_Byte	endp

ifndef	BIOS60
		Public	Update_ADM9240_Screen
Update_ADM9240_Screen	Proc	near

		pusha

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					
		jne	short Update_ADM9240_end

	;----------------------------------------
		mov	si, offset ADM9240_Item_List

	Update_ADM9240_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_ADM9240_end
		push	si
		F000_call	Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_ADM9240_Start
	;----------------------------------------

	Update_ADM9240_end:

		popa
		ret
Update_ADM9240_Screen	Endp
endif	;BIOS60	

ifdef	BIOS60
	db	'$SpeRT'
endif	;BIOS60		

ADM9240_Item_List	Label	Word

ifdef	BIOS60 
	dw	ADM9240_Runtime_No
endif	;BIOS60
	dw	offset ADM9240_CPUTemp_Item
	dw	offset Current_CPU_Temp_Item
ifdef	SHOW_ADM9240_CPUFAN1
	dw	offset Current_CPUFAN1_Item
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
	dw	offset Current_CPUFAN2_Item
endif;	SHOW_ADM9240_CPUFAN2
	dw	offset Current_Vin1_Item
	dw	offset Current_Vin2_Item
	dw	offset Current_Vin3_Item
	dw	offset Current_Vin4_Item

ADM9240_Runtime_No	EQU	(($ - offset ADM9240_Item_List)-2)/2

	dw	-1

ENDIF	;SENSOR_IN_XGROUP			;R08
ENDIF	;COMPILE_FOR_SENSOR_MNU

;R02 - start
IF	COMPILE_FOR_SENSOR_MNU EQ 4
	dw	offset First_ADM9240_Item, offset Last_ADM9240_Item
ifndef	SENSOR_IN_XGROUP						;R08
	dw	SEG Prg_ADM9240_Chip, offset Prg_ADM9240_Chip
else	;SENSOR_IN_XGROUP						;R08
	dw	SEG X_Prg_ADM9240_Chip, offset X_Prg_ADM9240_Chip	;R08
endif	;SENSOR_IN_XGROUP						;R08
ENDIF	;COMPILE_FOR_SENSOR_MNU

IF	COMPILE_FOR_SENSOR_MNU EQ 5
	extrn	First_ADM9240_Item:near
	extrn	Last_ADM9240_Item:near
ifndef	SENSOR_IN_XGROUP						;R08
	extrn	Prg_ADM9240_Chip:near
else	;SENSOR_IN_XGROUP						;R08
	extrn	X_Prg_ADM9240_Chip:far					;R08
endif	;SENSOR_IN_XGROUP						;R08
ENDIF	;COMPILE_FOR_SENSOR_MNU
;R02 - end

endif	;COMPILE_FOR_SENSOR_MNU


;R08 - 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	ADM9240_ID
ADM9240_ID	EQU	58h
endif;	ADM9240_ID
		public	X_Get_ADM9240_Byte
		public	X_Set_ADM9240_Byte
		public	X_Get_ADM9240_Word
		public	X_Set_ADM9240_Word

X_Get_ADM9240_Byte	Proc	Near
			mov	ch, ADM9240_ID
			call far ptr	EGROUP:fproc_Ct_I2CReadByte
			ret
X_Get_ADM9240_Byte	ENDP

X_Set_ADM9240_Byte	Proc	Near
			mov	ch, ADM9240_ID
			call far ptr	EGROUP:fproc_Ct_I2CWriteByte
			ret
X_Set_ADM9240_Byte	ENDP

X_Get_ADM9240_Word	Proc	Near
			mov	ch, ADM9240_ID
			call far ptr	EGROUP:fproc_Ct_I2CReadWord
			ret
X_Get_ADM9240_Word	ENDP

X_Set_ADM9240_Word	Proc	Near
			mov	ch, ADM9240_ID
			call far ptr	EGROUP:fproc_Ct_I2CWriteWord
			ret
X_Set_ADM9240_Word	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	;detect sensor
		test	word ptr es:[di],01h
		jz	short No_Sensor

		mov	di,offset DGROUP:TEMP1_HIGH
		extrn	ADM9240_CPUTEMP_ITEM:near
		mov	si,offset DGROUP:ADM9240_CPUTEMP_ITEM
		call	X_GetItem_Value
ifdef	No_CPU_Temp_Selectable
		mov	si,offset ADM9240_CPUTEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	No_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:
		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_ADM9240_Chip	
X_Prg_ADM9240_Chip	Proc	far

		mov	cl, 48h
		mov	al, 2ch
		call	X_Set_ADM9240_Byte

		mov	cl,48h
		call	X_Get_ADM9240_Byte
		jnc	short	@f
	;Disable items by change item's status
		push	ds
		mov	ax,0f000h
		mov	ds,ax

		extrn	Current_CPU_Temp_Item:near
		extrn	ADM9240_CPUTEMP_ITEM:near

ifdef	SHOW_ADM9240_CPUFAN1
		extrn	Current_CPUFAN1_Item:near
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
		extrn	Current_CPUFAN2_Item:near
endif;	SHOW_ADM9240_CPUFAN2
		extrn	Current_Vdd_Item:near
ifdef	Show_Current_Vd2
		extrn	Current_Vdd2_Item:near
endif;	Show_Current_Vd2
		extrn	Current_Vin1_Item:near
		extrn	Current_Vin2_Item:near
		extrn	Current_Vin3_Item:near
		extrn	Current_Vin4_Item:near

		extrn	X_F000_Shadow_W:near
		extrn	X_F000_Shadow_R:near
		extrn	X_GetItem_Value:near
		assume	ds:DGROUP
		call	X_F000_Shadow_W
		or	word ptr ds:[ADM9240_CPUTEMP_ITEM].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_CPU_Temp_Item].ITEMSTAT,ITEMDISABLE

ifdef	SHOW_ADM9240_CPUFAN1
		or	word ptr ds:[Current_CPUFAN1_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
		or	word ptr ds:[Current_CPUFAN2_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_ADM9240_CPUFAN2
		or	word ptr ds:[Current_Vdd_Item].ITEMSTAT,ITEMDISABLE
ifdef	Show_Current_Vd2
		or	word ptr ds:[Current_Vdd2_Item].ITEMSTAT,ITEMDISABLE
endif;	Show_Current_Vd2
		or	word ptr ds:[Current_Vin1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin3_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin4_Item].ITEMSTAT,ITEMDISABLE

ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		or	word ptr ds:[ACPI_Critical_Item].ITEMSTAT,ITEMDISABLE
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT
		call	X_F000_Shadow_R
		pop	ds
		jmp	Prg_ADM9240_Chip_End

@@:
		mov	cx,5
	Clear_ADM9240:
		push	cx
		mov	cl,41h
		call	X_Get_ADM9240_Byte
		mov	cl,42h
		call	X_Get_ADM9240_Byte
		pop	cx
		loop	short	Clear_ADM9240

		mov	si,offset XGROUP:Prg_ADM9240_Tbl
	Init_Start:
		mov	cl,cs:[si]
		call	X_Get_ADM9240_Byte
		mov	cl,cs:[si]	   
		and	al,cs:[si+1]
		or	al,cs:[si+2]
		call	X_Set_ADM9240_Byte

		add	si,3
		cmp	si,offset XGROUP:Prg_ADM9240_Tbl_End
		jne	short Init_Start

		mov	si,offset DGROUP:ADM9240_CPUTEMP_ITEM
		call	X_GetItem_Value
ifdef	No_CPU_Temp_Selectable
		or	al,al
		jz	short CPU_Temp_Disable
		mov	si,offset XGROUP:ADM9240_CPUTEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
endif;	No_CPU_Temp_Selectable
		push	ax
		xor	ah,ah
		mov	cl,39h
		call	X_Set_ADM9240_Byte		;set Tos (High limit)

		pop	ax

		sub	al,5
		xor	ah,ah
		mov	cl,3ah
		call	X_Set_ADM9240_Byte		;set Thyst (Low limit)

CPU_Temp_Disable:
		mov	cl,40h
		call	X_Get_ADM9240_Byte
		mov	al, 03h
		mov	cl,40h
		call	X_Set_ADM9240_Byte		;Start ADM9240

Prg_ADM9240_Chip_End:

		retf

X_Prg_ADM9240_Chip	Endp

		assume	ds:XGROUP
ifdef	No_CPU_Temp_Selectable
		ALIGN	4
ADM9240_CPUTEMP_VAL:
		db	0120	;disabled
		db	051	;50C		51=(50/0.9874)
		db	054	;53C		
		db	057	;56C		
		db	061	;60C		
		db	064	;63C		
		db	067	;66C		
		db	071	;70C		
endif;	No_CPU_Temp_Selectable

		ALIGN	4
		;---------------------------
		;      index  	and	or
		;---------------------------
Prg_ADM9240_Tbl:
		db	40h,	000h,	080h
		db	43h,	000h,	0ffh
		db	44h,	000h,	0efh		
		db	46h,	000h,	080h		
ifndef	FAN_Divisor				
		db	47h,	00fh,	050h		
else;
	if	FAN_Divisor 	eq	4
		db	47h,	00fh,	0a0h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
		db	47h,	00fh,	0f0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
ifdef	One_Time_Mode
		db	4Bh,	080h,	001h		
endif;	One_Time_Mode
ifdef	Comparator_mode
		db	4Bh,	080h,	002h		
endif;	Comparator_mode

Prg_ADM9240_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   


ifndef		Vdd_R1
Vdd_R1		equ	0
endif;		Vdd_R1
ifndef		Vdd_R2
Vdd_R2		equ	0
endif;		Vdd_R2

ifdef	Show_Current_Vd2
ifdef	Vdd2_Use_Negative_Input
ifndef		Vdd2_R1
Vdd2_R1		equ	27
endif;		Vdd2_R1
ifndef		Vdd2_R2
Vdd2_R2		equ	10
endif;		Vdd2_R2

else;	Vdd2_Use_Negative_Input
ifndef		Vdd2_R1
Vdd2_R1		equ	0
endif;		Vdd2_R1
ifndef		Vdd2_R2
Vdd2_R2		equ	0	
endif;		Vdd2_R2
endif;	Vdd2_Use_Negative_Input
endif;	Show_Current_Vd2

ifndef		Vin1_R1
Vin1_R1		equ	0
endif;		Vin1_R1
ifndef		Vin1_R2
Vin1_R2		equ	0
endif;		Vin1_R2

ifndef		Vin2_R1
Vin2_R1		equ	0
endif;		Vin2_R1
ifndef		Vin2_R2
Vin2_R2		equ	0
endif;		Vin2_R2

ifndef		Vin3_R1
Vin3_R1		equ	0
endif;		Vin3_R1
ifndef		Vin3_R2
Vin3_R2		equ	0
endif;		Vin3_R2

ifndef		Vin4_R1
Vin4_R1		equ	0
endif;		Vin4_R1
ifndef		Vin4_R2
Vin4_R2		equ	0
endif;		Vin4_R2

ifndef	No_CPU_Temp_Selectable
X_Show_Scale	Proc	Near
	     	extrn	X_GetItem_Value:near
		mov	si,offset DGROUP:ADM9240_CPUTEMP_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_Current_CPU_Temp	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl, 27h
		call	X_Get_ADM9240_Byte
		cmp	al,100
		jbe	short OK_Temp
		mov	al,0
	OK_Temp:

		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_CPU_Temp	Endp

ifdef	SHOW_ADM9240_CPUFAN1
X_Show_Current_CPUFAN1	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,28h
		call 	X_Get_ADM9240_Byte
		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,4cb8h		;0a4cb8h=(1350000/2)
		mov	dx,0ah			;Count=(1350000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,265ch		;05265ch=(1350000/4)
		mov	dx,05h			;Count=(1350000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,932eh		;02932eh=(1350000/8)
		mov	dx,02h			;Count=(1350000/(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;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2

X_Show_Current_CPUFAN2	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,29h
		call 	X_Get_ADM9240_Byte
		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,4cb8h		;0a4cb8h=(1350000/2)
		mov	dx,0ah			;Count=(1350000/(RPM*2))
else;
	if	FAN_Divisor 	eq	4
     		mov	ax,265ch		;05265ch=(1350000/4)
		mov	dx,05h			;Count=(1350000/(RPM*4))
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8
     		mov	ax,932eh		;02932eh=(1350000/8)
		mov	dx,02h			;Count=(1350000/(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;	SHOW_ADM9240_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			;R2
		push	dx			;R1+R2
		push	ax
		mov	ax, cx			;max range
		mov	bl, 192			;(Vmax/192)
		div	bl
		mov	bl, al			;al=ratio 
		pop	ax
		xor	ah,ah
		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:

		push	ax
		mov	ax, cx			;max range
		mov	bl, 192			;(Vmax/192)
		div	bl
		mov	bl, al
		pop	ax
		xor	ah,ah
		mul	bl

		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_Vdd	Proc	Near

		cmp	al,0ffh
		jne	short Vdd_WORKING
		xor	ax,ax
	Vdd_WORKING:

		or	dx,dx			;Is above 4 Voltage
		jz	short Below4dd		;No, go to below 4V handler

		push	bx			;(R2)
		push	dx			;(R1)
		xor	ah,ah
		mov	bl,14			;(3586/255)
		mul	bl
	

		pop	bx			;(R1)
		mul	bx
		pop	bx			;(R2)
		div	bx
		mov	bx, 13500
		sub	bx, ax
		mov	ax, bx


		xor	dx,dx
		mov	bx,1000			;recover to source value
		div	bx
		push	dx

		push	ax
		mov	al, '-'
		call	X_Display_Char
		pop	ax
		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_9Bdd
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Above_9Bdd
	Below_9Bdd:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Above_9Bdd:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret

	Below4dd:
                xor     ah,ah

                mov     bl, 14                   ;(3586/255)
		mul	bl

		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_9Add
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Above_9Add
	Below_9Add:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Above_9Add:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret
X_Display_Vdd	endp


X_Show_Current_Vdd	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,21h
		call 	X_Get_ADM9240_Byte

;Vdd=(V(rd))*(3.586/256)*((R1+R2)/R2)

		mov	dx,(Vdd_R1+Vdd_R2)
		mov	bx, Vdd_R2

		call	X_Display_Vdd
	@@:
		ret

X_Show_Current_Vdd	endp

ifdef	Show_Current_Vd2
X_Show_Current_Vdd2	Proc	Near
		cmp	al, Special_Before
		je	short @F

		mov	cl,25h
		call	X_Get_ADM9240_Byte
		out	90h, al
;Vdd=(V(rd))*(3.586/256)*((R1+R2)/R2)

ifdef	Vdd2_Use_Negative_Input
		mov	dx, Vdd2_R1
else;	Vdd2_Use_Negative_Input
		mov	dx,(Vdd2_R1+Vdd2_R2)
endif;	Vdd2_Use_Negative_Input
		mov	bx, Vdd2_R2
		call	X_Display_Vdd
	@@:
		ret
X_Show_Current_Vdd2	endp
endif;	Show_Current_Vd2

X_Show_Current_Vin1	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,24h
		call	X_Get_ADM9240_Byte
;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)

		mov	dx,(Vin1_R1+Vin1_R2)
		mov	bx,Vin1_R2
		mov	cx, 12063			;Maximum Vin1
		call	X_Display_Vin
	@@:
		ret

X_Show_Current_Vin1	endp


X_Show_Current_Vin2	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,23h
		call	X_Get_ADM9240_Byte

;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)
		mov	dx,(Vin2_R1+Vin2_R2)
		mov	bx,Vin2_R2
		mov	cx, 5026
		call	X_Display_Vin
	@@:
		ret

X_Show_Current_Vin2	endp

X_Show_Current_Vin3	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,22h
		call	X_Get_ADM9240_Byte

;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)

		mov	dx,(Vin3_R1+Vin3_R2)
		mov	bx,Vin3_R2
		mov	cx, 3317
		call	X_Display_Vin
	@@:
		ret

X_Show_Current_Vin3	endp

X_Show_Current_Vin4	Proc	Near

		cmp	al, Special_Before
		je	short @F

		mov	cl,20h
		call	X_Get_ADM9240_Byte

;Vdd=(V(rd))*((2.5*(4/3))/256)*((R1+R2)/R2)

		mov	dx,(Vin4_R1+Vin4_R2)
		mov	bx,Vin4_R2
		mov	cx, 2513
		call	X_Display_Vin
	@@:
		ret

X_Show_Current_Vin4	endp


ifndef	BIOS60
		Public	X_Update_ADM9240_Screen
X_Update_ADM9240_Screen	Proc	far

		pusha

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					
		jne	short Update_ADM9240_end

	;----------------------------------------
		mov	si, offset ADM9240_Item_List

	Update_ADM9240_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_ADM9240_end
		push	si
		call	X_Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_ADM9240_Start
	;----------------------------------------

	Update_ADM9240_end:

		popa
		retf
X_Update_ADM9240_Screen	Endp
endif	;BIOS60	

ifdef	BIOS60
	db	'$SpeRT'
endif	;BIOS60		

ADM9240_Item_List	Label	Word

ifdef	BIOS60 
	dw	ADM9240_Runtime_No
endif	;BIOS60
	dw	offset ADM9240_CPUTemp_Item
	dw	offset Current_CPU_Temp_Item
ifdef	SHOW_ADM9240_CPUFAN1
	dw	offset Current_CPUFAN1_Item
endif;	SHOW_ADM9240_CPUFAN1
ifdef	SHOW_ADM9240_CPUFAN2
	dw	offset Current_CPUFAN2_Item
endif;	SHOW_ADM9240_CPUFAN2
	dw	offset Current_Vin1_Item
	dw	offset Current_Vin2_Item
	dw	offset Current_Vin3_Item
	dw	offset Current_Vin4_Item

ADM9240_Runtime_No	EQU	(($ - offset ADM9240_Item_List)-2)/2

	dw	-1

endif	;SENSOR_IN_XGROUP   
ENDIF	;COMPILE_FOR_SENSOR_MNU
ENDIF	;COMPILE_FOR_SENSOR_MNU

;R08
