;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R31	02/03/99 PHI	Move sensor code to XGROUP.  
;			Please use define SENSOR_IN_XGROUP.
;R30	01/30/98 JMS	Added some define for custom request as below
;			SHOW_FAN_LIMIT_WARNING	
;			FAN_WARNING_CMOS	
;			FAN_WARNING_CMOS_BITS	
;R29	12/01/98 PAL	Fixed GL518SM_ID declare method
;R28	11/24/98 PAL	Fixed Vdd measure error in order to computing differenc
;			in distance
;R27	11/23/98 PAL	Fixed Get_GL518SM_Word ah is Fan2 and al is Fan1
;R26	11/16/98 PAL	Patch only use fan1 cause SMBus read hibyte and lowbyte
;			invert
;R25	10/09/98 PAL	Move all the SMbus of the chipset and use the chipset
;			standard I2C code in CHIPPOST.ASM
;R24	09/28/98 PAL	Fix coding error
;R23	09/18/98 PAL	Move VIA SMbus to sensor.asm
;R22	09/10/98 PAL	Move Sis SMbus to sensor.asm
;R21	09/03/98 LAW	Fixed GL518SM work with M1543/M1543C not well
;R20	09/03/98 TNY	Support structure for setup string moving to X-Group.
;R19	07/01/98 RIC	Add VIA SMBus Support.
;R18	05/20/98 LAW	fix M1543 show refresh too slow and add Vdd offset value
;			(SHOW_VDD_OFFSET EQU (byte ptr xx))
;R17	05/20/98 PAL	Disable Critical temp and Warning temp item when sensor
;			not exist
;R16	05/18/98 PAL	Fixed CPUFAN speed is owing to fill error
;R15	05/15/98 PAL	Change Critical temp range for fitting ACPI HCT testing
;R14	05/11/98 TNY	Add "Update_Sensor_in_CPUFEAT" option.
;R13	05/08/98 PAL	Added sensor chip auto detection function for ACPI
;R12	04/24/98 RAY	Add macro definition for supporting BIOS 6.0
;			"DEFINE_MENUITEM" is a dummy macro in BIOS 4.51 & 4.6
;R11	04/09/98 PAL	Add Special_Cpufan_for_Darter definition for fix temp.
;			and CpuFan speed read error
;R09A	03/26/98 TNY	Add fully support for new ver. 
;R10	03/26/98 ADS	Fixed defined error.
;R09	03/26/98 TNY	Add voltage show about new ver. 
;R08	03/05/98 TNY	Support SiS software I2C programming.(SiS5598,SiS5591)
;R07	02/04/98 TNY	Enable Temp-IRQ.
;R06	01/13/98 TNY	Add Ali-M1543 hook.
;R05	12/24/97 AVN	Change sensor show in IOFEAT.ASM
;			define 'Update_Sensor_in_IOFEAT'
;R04	12/22/97 TNY	Fix SMBus not ready if AMD/233 plugged.
;R03	12/11/97 TNY	Fix temperature show error.
;R02	12/08/97 DNL	Added ACPI Thermal Zone support
;R01B	12/08/97 RIC	Fixed that CPU FAN(GPIO4) control fail in Setup.
;R01A	12/04/97 RIC	Fixed that keyboard(GPIO0) have garbage in Setup.
;R01	11/28/97 RIC	Support VIA I2C.
;R00	08/21/97 TNY	Initial Ver.

ifdef	COMPILE_FOR_SENSOR_ASM
IF	COMPILE_FOR_SENSOR_ASM EQ 2
ifndef	SENSOR_IN_XGROUP			;R31

;R25 - start
ifndef	GL518SM_ID		;R29
GL518SM_ID	EQU	5Ah
endif;	GL518SM_ID		;R29
		public	Get_GL518SM_Byte
		public	Set_GL518SM_Byte
		public	Get_GL518SM_Word
		public	Set_GL518SM_Word
		extrn	Ct_I2CReadByte:near
		extrn	Ct_I2CWriteByte:near
		extrn	Ct_I2CReadWord:near
		extrn	Ct_I2CWriteWord:near
Get_GL518SM_Byte	Proc	Near
	mov	ch, GL518SM_ID
	call	Ct_I2CReadByte
			ret
Get_GL518SM_Byte	ENDP
Set_GL518SM_Byte	Proc	Near
	mov	ch, GL518SM_ID
	call	Ct_I2CWriteByte
			ret
Set_GL518SM_Byte	ENDP
Get_GL518SM_Word	Proc	Near
	mov	ch, GL518SM_ID
	call	Ct_I2CReadWord
			ret
Get_GL518SM_Word	ENDP

Set_GL518SM_Word	Proc	Near
	mov	ch, GL518SM_ID
	call	Ct_I2CWriteWord
			ret
Set_GL518SM_Word	ENDP
;R25 - end
comment	%				;R25
ifdef	PIIX_ID					;R01

GL518SM_ID	EQU	5Ah
;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_GL518SM_Byte
		public	Set_GL518SM_Byte
		public	Get_GL518SM_Word
		public	Set_GL518SM_Word
Get_GL518SM_Byte	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(GL518SM_ID + 1)
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY

		pop	cx
		mov	dl,03h
		mov	al,cl
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;read data
		NEWIODELAY
		NEWIODELAY

;R04		mov	cx,100h
		mov	cx,3000h		;R04
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
Get_GL518SM_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Byte	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,GL518SM_ID
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY

		pop	cx
		mov	dl,03h
		mov	al,cl
		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_GL518SM_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_GL518SM_Word	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(GL518SM_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_GL518SM_Word	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Word	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,GL518SM_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_GL518SM_Word	Endp
endif;	PIIX_ID					;R01

;R06 - start
ifdef	M1543
GL518SM_ID	EQU	5Ah
;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_GL518SM_Byte
		public	Set_GL518SM_Byte
		public	Get_GL518SM_Word
		public	Set_GL518SM_Word
Get_GL518SM_Byte	Proc	Near

		push	cx

		call	Wait_SMBUS_Idle_Status	;R21

		mov	dx,SMBus_Port +03h
		mov	al,(GL518SM_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

;R18		xor	cx,cx
		mov	cx, 0fffh		;R18
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY 

		mov	dl,04
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
Get_GL518SM_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Byte	Proc	Near

		push	ax
		push	cx

		call	Wait_SMBUS_Idle_Status	;R21

		mov	dx,SMBus_Port +03h
		mov	al,GL518SM_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

;R18		xor	cx,cx
		mov	cx, 0fffh		;R18
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		ret
Set_GL518SM_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_GL518SM_Word	Proc	Near

		push	cx

		call	Wait_SMBUS_Idle_Status	;R21

		mov	dx,SMBus_Port +03h
		mov	al,(GL518SM_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

;R18		xor	cx,cx
		mov	cx, 0fffh		;R18
	@@:
		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_GL518SM_Word	endp

;[]==============================================================[]
;Input : CL - register index
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Word	Proc	Near

		push	ax
		push	cx

		call	Wait_SMBUS_Idle_Status	;R21

		mov	dx,SMBus_Port +03h
		mov	al,GL518SM_ID		;GL518SM 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

;R18		xor	cx,cx
		mov	cx, 0fffh		;R18
	@@:				
		newiodelay			
		loop	short @B			

		call	Chk_SMBus_READY 

		ret
Set_GL518SM_Word	Endp
;R21 - start
		Public	Wait_SMBUS_Idle_Status
Wait_SMBUS_Idle_Status	Proc Near
		push	cx
		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:
		pop	cx
		ret
Wait_SMBUS_Idle_Status	EndP
;R21 - end

endif;	M1543
;R06 - end

;R01 - starts
ifdef   VT586_ACPI		; VIA Chipset
  IF		VIA_SMBus	EQ	0		;R19

;R23ifdef	SDA_In_GPIO1
;R23SDA             EQU     02	;GPIO1 Data
;R23SCL             EQU     04	;GPIO2 Clock
;R23else;	SDA_In_GPIO1
;R23SDA             EQU     04	;GPIO2 Data (Normal)
;R23SCL             EQU     02	;GPIO1 Clock
;R23endif;	SDA_In_GPIO1
GL518SM_ID	EQU	5Ah
;R23GPIO_Dir        EQU     ACPI_Port+40h
;R23GPIO_WPort      EQU     ACPI_Port+42h
;R23GPIO_RdPort     EQU     ACPI_Port+44h
;R23
;R23		extrn	Dir_Out:Near
;R23		extrn	Set_Start:Near
;R23		extrn	Wr_Byte:Near
;R23		extrn	Wait_ACK:Near
;R23		extrn	Set_Stop:Near
;R23		extrn	E000_Get_PMIO:near
;R23		extrn	E000_Set_PMIO:near
;R23		extrn	E000_Get_Set_PMIO:near
;R23		extrn	E000_Get_Set_PMIO_OR:near
;R23		extrn	E000_Get_Set_PMIO_AND:near
;R23;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R23;บ  Set_Pointer                                                             บ
;R23;บ  Input:  BX = pointer                                                    บ
;R23;บ  Output: CLC = PK                                                        บ
;R23;บ          STC = Fail                                                      บ
;R23;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R23Set_Pointer     proc
;R23		push    bx              ;Save Register Pointer
;R23		call    Dir_Out
;R23		call    Set_Start
;R23		mov     bl,GL518SM_ID
;R23		call    Wr_Byte
;R23		call    Wait_ACK
;R23		pop     bx
;R23		jc      ErrSet_Pointer
;R23		call    Wr_Byte         ;bx = pointer
;R23		call    Wait_ACK
;R23		jc      ErrSet_Pointer
;R23		clc
;R23		ret
;R23ErrSet_Pointer:
;R23		stc
;R23		ret
;R23Set_Pointer     endp
;R23
;R23;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R23;บ  Rd_Data                                                                 บ
;R23;บ                                                                          บ
;R23;บ  Input:  None                                                            บ
;R23;บ  Output: BL: return data                                                 บ
;R23;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R23Rd_Data proc
;R23		mov     cx,40h
;R23		mov     bl, NOT SDA
;R23		mov	bh, SCL
;R23		call    E000_Get_Set_PMIO
;R23
;R23		xor     bx, bx
;R23		xor     ax, ax
;R23ifdef	special_cpufan_for_Darter		;R11
;R23                xor     dx,dx   		;R11
;R23endif;	special_cpufan_for_Darter		;R11
;R23		mov     cx, 8
;R23Rd_byte:
;R23		push    cx
;R23		mov     cx, 8                           ;T(low) = 4.7 us
;R23@@:
;R23		out     0ebh, al
;R23		loop    short @B
;R23
;R23ifndef	special_cpufan_for_Darter		;R11
;R23		mov     dx,GPIO_WPort		;
;R23		in	al, dx			;R01B
;R23		or      al, SCL			;
;R23		out     dx, al                  ; SCL high, receiver will read data
;R23else;	special_cpufan_for_Darter		;R11
;R23                mov     cx,42h                  ;R11
;R23                mov     bl,SCL                  ;R11
;R23                call    E000_Get_Set_PMIO_OR    ;R11
;R23endif;	special_cpufan_for_Darter		;R11
;R23
;R23		mov     cx, 8                           ;T(high) = 4 us
;R23@@:
;R23		out     0ebh, al
;R23		loop    short @B
;R23
;R23
;R23		mov     cx,44h
;R23
;R23		call    E000_Get_PMIO
;R23
;R23		and     al, SDA
;R23ifdef	SDA_In_GPIO1
;R23		shr     al, 1		;;if SDA=02h, SCL=04h
;R23else;	SDA_In_GPIO1
;R23		shr     al, 2		;;if SDA=04h, SCL=02h
;R23endif;	SDA_In_GPIO1
;R23
;R23ifndef	special_cpufan_for_Darter	;R11
;R23		shl     bl, 1
;R23		or      bl, al
;R23else;	special_cpufan_for_Darter	;R11
;R23                shl     dl,1    	;R11
;R23                or      dl,al   	;R11
;R23endif;	special_cpufan_for_Darter	;R11
;R23
;R23;R01B		and     al, NOT SCL                     ;SCL low
;R23;R01B		mov     cx,42h
;R23;R01B		call    E000_Set_PMIO
;R23
;R23ifndef	special_cpufan_for_Darter		;R11
;R23		mov     dx, GPIO_WPort		;R01B
;R23		in	al, dx			;R01B
;R23		and     al, NOT SCL             ;R01B SCL low
;R23		out	dx, al			;R01B
;R23else;	special_cpufan_for_Darter		;R11
;R23                mov     cx,42h                  ;R11
;R23                and     bl,NOT SCL              ;R11
;R23                call    E000_Get_Set_PMIO_AND   ;R11
;R23endif;	special_cpufan_for_Darter		;R11
;R23
;R23		pop     cx
;R23		loop    Rd_byte
;R23
;R23		mov     cx, 8                           ;T(hd)
;R23@@:
;R23		out     0ebh, al
;R23		loop    short @B
;R23
;R23ifndef	special_cpufan_for_Darter		;R11
;R23		mov     dx,GPIO_Dir
;R23		in      al, dx
;R23		or      al, SDA
;R23		or      al, SCL
;R23		out     dx, al                  ; Set SCL O/P , SDA I/P
;R23else;	special_cpufan_for_Darter		;R11
;R23                mov     cx,40h                  ;R11
;R23                mov     bl,SDA                  ;R11
;R23                or      bl,SCL                  ;R11
;R23                call    E000_Get_Set_PMIO_OR    ;R11
;R23                mov     bl,dl                   ;R11
;R23endif;	special_cpufan_for_Darter		;R11
;R23
;R23		ret
;R23Rd_Data endp
;R23
;R23
;R23;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R23;บ  Set_NoACK                                                               บ
;R23;บ                                                                          บ
;R23;บ  Input:  None                                                            บ
;R23;บ  Output: None                                                            บ
;R23;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R23Set_NoACK       proc
;R23		mov     dx,GPIO_WPort
;R23		in      al, dx
;R23		and     al, NOT SCL
;R23		or      al, SDA
;R23		out     dx, al                  ; out No ACK
;R23
;R23		out     0ebh, al                ;T(setup) = 250 ns
;R23
;R23		or      al, SCL
;R23		out     dx, al                  ;SCL ,SDA = high
;R23		mov     cx, 8                   ;T(high) = 4 us
;R23@@:
;R23		out     0ebh, al
;R23		loop    short @B
;R23
;R23		and     al, NOT SCL
;R23		out     dx, al                  ;SCL = low
;R23		out     0ebh, al
;R23
;R23		and     al, NOT SDA
;R23		out     dx, al                  ;SDA = low
;R23		out     0ebh, al
;R23
;R23		ret
;R23Set_NoACK       endp
;R23
;R23;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R23;บ  Set_ACK                                                                 บ
;R23;บ                                                                          บ
;R23;บ  Input:  None                                                            บ
;R23;บ  Output: None                                                            บ
;R23;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R23Set_ACK proc
;R23		mov     cx,42h
;R23		mov     bl, NOT SCL
;R23		and	bl, NOT SDA
;R23		call    E000_Get_Set_PMIO_AND
;R23
;R23		out     0ebh, al                ;T(setup) = 250 ns
;R23
;R23		mov	dx,GPIO_WPort		;R01A
;R23		in	al, dx			;R01B
;R23		or      al, SCL
;R23		out     dx, al                  ;SCL ,SDA = high
;R23		mov     cx, 8                   ;T(high) = 4 us
;R23@@:
;R23		out     0ebh, al
;R23		loop    short @B
;R23		and     al, NOT SCL
;R23		out     dx, al                  ;SCL = low
;R23		out     0ebh, al
;R23
;R23		and     al, NOT SDA
;R23		out     dx, al                  ;SDA = low
;R23		out     0ebh, al
;R23		ret
;R23Set_ACK endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_GL518SM_Byte
		public	Set_GL518SM_Byte
		public	Get_GL518SM_Word
		public	Set_GL518SM_Word
Get_GL518SM_Byte	Proc	Near

		mov     ch,GL518SM_ID		;R23
		mov     bl,cl
		call    Set_Pointer
		NEWIODELAY
		NEWIODELAY
		call    Set_Start
		mov     bl,GL518SM_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_GL518SM_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Byte	Proc	Near

		push    ax
		mov     bl,cl
		cli
		mov	ch, GL518SM_ID		;R23
		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_GL518SM_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_GL518SM_Word	Proc	Near
		mov	ch, GL518SM_ID		;R23
		mov     bl,cl
		call    Set_Pointer
		NEWIODELAY
		NEWIODELAY
		call    Set_Start
		mov     bl,GL518SM_ID
		inc     bl              ;for read operation
		call    Wr_Byte
		call    Wait_ACK
		jc      Rd_2ByteReg_Fail
                call    Rd_Data
ifndef	special_cpufan_for_Darter		;R11
	        shl     ebx,16
else;	special_cpufan_for_Darter		;R11
                mov     al,bl   		;R11
                push    ax      		;R11
endif;	special_cpufan_for_Darter		;R11
		call    Set_ACK
		call    Rd_Data
ifndef	special_cpufan_for_Darter		;R11
		mov     bh,bl
		shl     ebx,8
else;	special_cpufan_for_Darter		;R11
                pop     ax      		;R11
                mov     ah,al   		;R11
                mov     al,bl   		;R11
                push    ax      		;R11
endif;	special_cpufan_for_Darter		;R11
		
		call    Set_NoACK
		call    Set_Stop
ifndef	special_cpufan_for_Darter		;R11
		shr     ebx,16
		mov     ax,bx
else;	special_cpufan_for_Darter		;R11
                pop     ax      		;R11
endif;	special_cpufan_for_Darter		;R11

		clc
		ret
Rd_2ByteReg_Fail:
		stc
		ret
Get_GL518SM_Word	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Word	Proc	Near
		push    ax
		mov     bx,cx
		push    bx
		call    Set_Start
		mov     bl,GL518SM_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_GL518SM_Word	Endp

  ENDIF;	VIA_SMBus	EQ	0		;R19
endif;	VT586_ACPI
;R01 - ends

;R19 - starts
if	VIA_SMBus
  IFNDEF	GL518SM_ID
GL518SM_ID	EQU	5Ah
  ENDIF;	GL518SM_ID
;[]==============================================================[]
;Input	: CL - register index
;Output : AL - Value read
;[]==============================================================[]
		public	Get_GL518SM_Byte
		public	Set_GL518SM_Byte
		public	Get_GL518SM_Word
		public	Set_GL518SM_Word
Get_GL518SM_Byte	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(GL518SM_ID + 1)
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY

		pop	cx
		mov	dl,03h
		mov	al,cl
		out	dx,al			;Index
		NEWIODELAY
		NEWIODELAY

		mov	dl,02h
		mov	al,48h
		out	dx,al			;read data
		NEWIODELAY
		NEWIODELAY

;R04		mov	cx,100h
		mov	cx,3000h		;R04
	@@:
		newiodelay
		loop	short @B

		call	Chk_SMBus_READY

		mov	dl,05
		in	al,dx			;Data0
		NEWIODELAY
		NEWIODELAY

		ret
Get_GL518SM_Byte	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AL - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Byte	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,GL518SM_ID
		out	dx,al
		NEWIODELAY
		NEWIODELAY

		call	Chk_SMBus_READY

		pop	cx
		mov	dl,03h
		mov	al,cl
		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_GL518SM_Byte	Endp

;[]==============================================================[]
;Input	: CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_GL518SM_Word	Proc	Near

		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,(GL518SM_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_GL518SM_Word	Endp

;[]==============================================================[]
;Input : CL - register index
;	 AX - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Word	Proc	Near

		push	ax
		push	cx

		mov	dx,SMBus_Port +04h
		mov	al,GL518SM_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_GL518SM_Word	Endp
endif;	VIA_SMBus
;R19 - ends

;R08 - start
;R22SIS_SMBus	=	0
;R22ifdef   SIS_5598_PCI_RESET		
;R22SIS_SMBus	=	1
;R22endif;  SIS_5598_PCI_RESET		
;R22ifdef   SIS5595_ID
;R22SIS_SMBus	=	1
;R22endif;  SIS5595_ID
;R22
;R08 - starts
if	SIS_SMBus		; SiS Chipset

GL518SM_ID	EQU	5Ah

;R22SDA             EQU     10h	;I2C Data 
;R22SCL             EQU     08h	;I2C Clock
;R22
;R22		extrn	F000_Get_CT:near
;R22		extrn	F000_Set_CT:near
;R22
;R22DelayIO:
;R22		push	cx
;R22		mov	cx,300h
;R22	@@:
;R22		newiodelay
;R22		loop	@B
;R22		pop	cx
;R22		ret
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Set_Start                                                               บ
;R22;บ  Input:  None                                                            บ
;R22;บ  Output: None                                                            บ
;R22;บ                                                                          บ
;R22;บ  SDA  ----\___                                                           บ
;R22;บ  SCL  -------\                                                           บ
;R22;บ       1   2                                                              บ
;R22;บ        4us 4us                                                           บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Set_Start       proc	Near
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22        	or	al, SCL
;R22        	call	F000_Set_Ct
;R22        
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22        	or	al, SDA
;R22        	call	F000_Set_Ct
;R22
;R22		call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al,NOT SDA
;R22        	call	F000_Set_Ct
;R22                NEWIODELAY      
;R22                NEWIODELAY      
;R22                NEWIODELAY      
;R22
;R22                call	DelayIO			
;R22        
;R22;For 1'st clock low time
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al,NOT SCL
;R22        	call	F000_Set_Ct
;R22
;R22                call	DelayIO			
;R22        
;R22                ret
;R22Set_Start       endp
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Wr_Byte                                                                 บ
;R22;บ                                                                          บ
;R22;บ  Input:   BL:Data to I2C Bus                                             บ
;R22;บ  Output: None                                                            บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Wr_Byte		proc	Near
;R22
;R22                pusha					
;R22        	mov	cx,086dh
;R22                call	F000_Get_Ct			
;R22                and     al,NOT SCL			
;R22                call	F000_Set_Ct			
;R22                popa					
;R22
;R22                mov     dx,bx
;R22                mov     cx ,8
;R22write_B:
;R22                push    cx
;R22                NEWIODELAY      
;R22                NEWIODELAY      
;R22                NEWIODELAY      
;R22
;R22                xor     dh,dh   
;R22                shl     dx,1    
;R22                shl     dh,4            ;;if SDA=10h, SCL=08h
;R22        	mov	bl,dh
;R22
;R22        	push	dx
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al,NOT SDA              
;R22                or      al,bl			;data                   
;R22        	call	F000_Set_Ct
;R22                NEWIODELAY      
;R22        
;R22                call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                or      al,SCL			
;R22        	call	F000_Set_Ct
;R22                call	DelayIO			
;R22                NEWIODELAY      
;R22                NEWIODELAY      
;R22                NEWIODELAY      
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al,NOT SCL		
;R22        	call	F000_Set_Ct
;R22                call	DelayIO			
;R22        
;R22        	pop	dx
;R22                pop     cx
;R22                loop    write_B
;R22                ret
;R22Wr_Byte endp
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Wait_ACK                                                                บ
;R22;บ                                                                          บ
;R22;บ  Input:  None                                                            บ
;R22;บ  Output: CLR :  Acknowledge                                              บ
;R22;บ          STC : !Acknowledge                                              บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Wait_ACK        proc	Near
;R22        	mov	cx,086dh
;R22                call	F000_Get_Ct		
;R22                and     al, not SCL		
;R22                call	F000_Set_Ct		
;R22                call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                or      al, SCL			
;R22        	call	F000_Set_Ct
;R22
;R22                call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22                call	F000_Get_Ct		
;R22                and	al,NOT SCL		
;R22                call	F000_Set_Ct		
;R22                call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                call	DelayIO			
;R22                mov     bl, al			
;R22        	and	al,NOT SCL
;R22        	call	F000_Set_Ct
;R22                call	DelayIO			
;R22        
;R22                test    bl, SDA
;R22                jnz     short ACK_Err_ret
;R22                clc
;R22                ret
;R22ACK_Err_ret:
;R22	        stc
;R22        	ret
;R22Wait_ACK        endp
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Set_Stop                                                                บ
;R22;บ                                                                          บ
;R22;บ  Input:  None                                                            บ
;R22;บ  Output: None                                                            บ
;R22;บ  SDA  ___/-----                                                          บ
;R22;บ  SCL  ---------                                                          บ
;R22;บ       1  2   3                                                           บ
;R22;บ        4us 4us                                                           บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Set_Stop        proc	Near
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al,not SCL
;R22        	call	F000_Set_Ct
;R22        	call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al,NOT SDA              
;R22        	call	F000_Set_Ct
;R22        	call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                or      al,SCL
;R22        	call	F000_Set_Ct
;R22        	call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                or      al,SDA
;R22        	call	F000_Set_Ct
;R22        	call	DelayIO			
;R22
;R22                ret
;R22Set_Stop        endp
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Set_Pointer                                                             บ
;R22;บ  Input:  BX = pointer                                                    บ
;R22;บ  Output: CLC = PK                                                        บ
;R22;บ          STC = Fail                                                      บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Set_Pointer     proc	near
;R22                push    bx              ;Save Register Pointer
;R22                call    Set_Start
;R22                mov     bl,GL518SM_ID
;R22                call    Wr_Byte
;R22                call    Wait_ACK
;R22                pop     bx
;R22                jc      ErrSet_Pointer
;R22                call    Wr_Byte         ;bx = pointer
;R22                call    Wait_ACK
;R22                jc      ErrSet_Pointer
;R22                clc
;R22                ret
;R22ErrSet_Pointer:
;R22                stc
;R22                ret
;R22Set_Pointer     endp
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Rd_Data                                                                 บ
;R22;บ                                                                          บ
;R22;บ  Input:  None                                                            บ
;R22;บ  Output: BL: return data                                                 บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Rd_Data 	proc
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22        	and	al, not SCL
;R22        	call	F000_Set_Ct
;R22        	call	DelayIO			
;R22        
;R22                xor     bx, bx
;R22                xor     ax, ax
;R22                mov     cx, 8
;R22Rd_byte:
;R22                push    cx
;R22                mov     cx, 8                           ;T(low) = 4.7 us
;R22@@:
;R22        	NEWIODELAY
;R22                loop    short @B
;R22
;R22        	mov	cx,086dh		
;R22        	call	F000_Get_Ct		
;R22        	or	al, SDA			
;R22        	call	F000_Set_Ct		
;R22        	call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22        	or	al, SCL
;R22        	call	F000_Set_Ct		;SCL high, receiver will read data
;R22        	call	DelayIO			
;R22
;R22                mov     cx, 8                   ;T(high) = 4 us
;R22	@@:
;R22        	NEWIODELAY
;R22                loop    short @B
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22
;R22        	push	ax
;R22                and     al, SDA 
;R22                shr     al, 4
;R22                shl     bl, 1           
;R22                or      bl, al
;R22        	pop	ax
;R22                and     al, NOT SCL                     ;SCL low
;R22        	mov	cx,086dh
;R22        	call	F000_Set_Ct
;R22        	call	DelayIO			
;R22
;R22                pop     cx
;R22                loop    short Rd_byte
;R22
;R22                mov     cx, 8                           ;T(hd)
;R22        @@:
;R22        	NEWIODELAY
;R22                loop    short @B
;R22
;R22                ret
;R22Rd_Data endp
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Set_NoACK                                                               บ
;R22;บ                                                                          บ
;R22;บ  Input:  None                                                            บ
;R22;บ  Output: None                                                            บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Set_NoACK       proc
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al, NOT SCL
;R22        	call	F000_Set_Ct		;out No ACK
;R22        	call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                or      al, SDA
;R22        	call	F000_Set_Ct		;out No ACK
;R22        	call	DelayIO			
;R22
;R22                NEWIODELAY                	;T(setup) = 250 ns
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                or      al, SCL
;R22        	call	F000_Set_Ct		;SCL ,SDA = high
;R22                call	DelayIO			
;R22
;R22                mov     cx, 8                   ;T(high) = 4 us
;R22        @@:
;R22                NEWIODELAY
;R22                loop    short @B
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al, not SCL
;R22        	call	F000_Set_Ct		;SCL = low
;R22
;R22        	call	DelayIO			
;R22
;R22                ret
;R22Set_NoACK       endp
;R22
;R22;ษออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออป
;R22;บ  Set_ACK                                                                 บ
;R22;บ                                                                          บ
;R22;บ  Input:  None                                                            บ
;R22;บ  Output: None                                                            บ
;R22;ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออผ
;R22Set_ACK 	proc
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al, NOT SCL
;R22                and     al, NOT SDA
;R22        	call	F000_Set_Ct		
;R22                NEWIODELAY                	;T(setup) = 250 ns
;R22        	call	DelayIO			
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                or      al, SCL
;R22        	call	F000_Set_Ct		;SCL = high
;R22        	call	DelayIO			
;R22
;R22                mov     cx, 8                   ;T(high) = 4 us
;R22        @@:
;R22                NEWIODELAY
;R22                loop    short @B
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al, NOT SCL
;R22        	call	F000_Set_Ct		;SCL = low
;R22        	call	DelayIO			
;R22                NEWIODELAY
;R22
;R22        	mov	cx,086dh
;R22        	call	F000_Get_Ct
;R22                and     al, NOT SDA
;R22        	call	F000_Set_Ct		;SDA = low
;R22        	call	DelayIO			
;R22                NEWIODELAY
;R22
;R22                ret
;R22Set_ACK endp

;[]==============================================================[]
;Input  : CL - register index
;Output : AL - Value read
;[]==============================================================[]
                public  Get_GL518SM_Byte
                public  Set_GL518SM_Byte
                public  Get_GL518SM_Word
                public  Set_GL518SM_Word
Get_GL518SM_Byte   Proc    Near
                mov     ch,GL518SM_ID		;R24
                mov     bl,cl
                call    Set_Pointer
                NEWIODELAY
                NEWIODELAY
                call    Set_Start
                mov     bl,GL518SM_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_GL518SM_Byte   Endp

;[]==============================================================[]
;Input : CL - register index
;        AL - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Byte   Proc    Near

                push    ax
                mov     ch,GL518SM_ID		;R24
                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_GL518SM_Byte   Endp

;[]==============================================================[]
;Input  : CL - register index
;Output : AX - Value read
;[]==============================================================[]
Get_GL518SM_Word   Proc    Near

                mov     ch,GL518SM_ID		;R24
                mov     bl,cl					
                call    Set_Pointer				
                NEWIODELAY					
                NEWIODELAY					
                call    Set_Start
                mov     bl,GL518SM_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_GL518SM_Word   endp

;[]==============================================================[]
;Input : CL - register index
;        AX - Value to write
;Output: none
;[]==============================================================[]
Set_GL518SM_Word   Proc    Near

                push    ax
                mov     bx,cx
                push    bx
                call    Set_Start
                mov     bl,GL518SM_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_GL518SM_Word   Endp

endif;	SIS_SMBus		
;R08 - end
%					;R25
;R02 - start
ifdef	ACPI_Support
		extrn	ACPI_Critical_Item:near
		extrn	TEMP1_HIGH:near
		extrn	SENSOR_FLAG:near		;R13
;[]========================================================================[]
;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
;R13 - start
		mov	di,offset DGROUP:SENSOR_FLAG
		test	word ptr es:[di],01h
		jz	short No_Sensor
;R13 - end
		mov	di,offset DGROUP:TEMP1_HIGH

		extrn	GL518SM_TEMP_ITEM:near
		mov	si,offset DGROUP:GL518SM_TEMP_ITEM
		call	E_GetItem_Value
		mov	si,offset GL518SM_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
		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:					;R13
		pop	es
		ret
Ct_FillTempPointer	Endp

Critical_Table:
;R15		dw	3932			;120c
;R15		dw	3532			;80c
;R15		dw	3582			;85c
;R15		dw	3632			;90c

		dw	3332			;60c		;R15
		dw	3382			;65c		;R15
		dw	3432			;70c		;R15
		dw	3482			;75c		;R15

endif	;ACPI_Support
;R02 - end
;***************************************************************************
;**** 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_GL518SM_Chip	;R20
Prg_GL518SM_Chip	Proc	Near

		extrn	GL518SM_TEMP_ITEM:near
		extrn	Current_CPU_Temp_Item:near
ifdef	SHOW_GL518SM_CPUFAN1
		extrn	Current_CPUFAN1_Item:near
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
		extrn	Current_CPUFAN2_Item:near
endif;	SHOW_GL518SM_CPUFAN2
		extrn	Current_Vdd_Item:near		;R09A
		extrn	Current_Vin1_Item:near		;R09A
		extrn	Current_Vin2_Item:near		;R09A
		extrn	Current_Vin3_Item:near

		extrn	F000_Shadow_W:near
		extrn	F000_Shadow_R:near
		extrn	F000_call_proc:near

ifdef	Special_GL518SM_Item_Patch	;R10
;R10 ifdef	Special_GL518SM_Item_Patch1

		mov	cl,00h
		call	Get_GL518SM_Byte
		jnc	short @F

		push	ds
		mov	ax,0f000h
		mov	ds,ax

		assume	ds:DGROUP
		f000_call	DGROUP:F000_Shadow_W

		or	word ptr ds:[GL518SM_TEMP_ITEM].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_CPU_Temp_Item].ITEMSTAT,ITEMDISABLE
ifdef	SHOW_GL518SM_CPUFAN1
		or	word ptr ds:[Current_CPUFAN1_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
		or	word ptr ds:[Current_CPUFAN2_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_GL518SM_CPUFAN2
		or	word ptr ds:[Current_Vin3_Item].ITEMSTAT,ITEMDISABLE
;R09A - start
		or	word ptr ds:[Current_Vin1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vdd_Item].ITEMSTAT,ITEMDISABLE
;R09A - end

;R17 - 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
;R17 - end

;R13 - start
ifdef	ACPI_SUPPORT
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT
;R13 - end
		f000_call	DGROUP:F000_Shadow_R
		pop	ds
		jmp	Prg_GL518SM_Chip_End
	@@:
endif;	Special_GL518SM_Item_Patch

;R09A - start
		mov	cl,01h
		call	Get_GL518SM_Byte
		cmp	al,80h
		je	short New_Ver_Sure

		push	ds
		mov	ax,0f000h
		mov	ds,ax

		assume	ds:DGROUP
		f000_call	DGROUP:F000_Shadow_W
		or	word ptr ds:[Current_Vin1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vdd_Item].ITEMSTAT,ITEMDISABLE
		f000_call	DGROUP:F000_Shadow_R
		pop	ds
New_Ver_Sure:
;R09A - end

		mov	cl,03h
		mov	al,80h
		call	Set_GL518SM_Byte			;Reset GL518SM

		extrn	GL518SM_TEMP_ITEM:near
		mov	si,offset DGROUP:GL518SM_TEMP_ITEM
		call	E_GetItem_Value
		or	al,al
		jz	short CPU_Temp_Disable

		mov	si,offset GL518SM_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]

		add	al,122			;Temp_Offset = 119

		push	ax
		xor	ah,ah
		mov	cl,05
		call	Set_GL518SM_Byte	;set Tos (High limit)

		pop	ax
		sub	al,5
		xor	ah,ah
		mov	cl,06
		call	Set_GL518SM_Byte	;set Thyst (Low limit)

		mov	cl,10h
		mov	al,10h
		call	Set_GL518SM_Byte	;Enable CPU_Temp alarm

		mov	cl,11h						;R07
		mov	al,10h						;R07
		call	Set_GL518SM_Byte	;Enable CPU_Temp IRQ	;R07

		jmp	short @F

CPU_Temp_Disable:

		mov	cl,03h
		mov	al,04h
		call	Set_GL518SM_Byte	;Disable IRQ# output

	@@:
		mov	cl,03h
		call	Get_GL518SM_Byte			
		or	al,40h
		mov	cl,03h
		call	Set_GL518SM_Byte	;Start GL518SM
;R30 -starts
ifdef  SHOW_FAN_LIMIT_WARNING
		extrn   FAN_WARNING_ITEM:Near
		push	bx
		mov	si,offset DGROUP:FAN_WARNING_ITEM
		call	E_GetItem_Value
		or	al,al			; item disable ?
		jz	short Skip_fan_init

		mov	si,offset FAN_LIMIT_WARNIN_TBL
		xor	ah,ah
		dec	al
		add	si,ax
		mov	bl,cs:[si]

		mov	cl,0fh
		call	Get_GL518SM_Byte	;get fan divisor
		shr	al,6

		cmp 	al,0	  	    			
		je	short Skip_fan_init 	;if divisor = 1 skip

		cmp 	al,1	  	    	; is divisor 2	
		jne 	short fan_divisor4
		shl	bl,2
		jmp	short fan_init_limit_data
		
fan_divisor4:
		cmp 	al,2	  	    	; is divisor 4	
		jne 	short fan_init_limit_data
		shl	bl,1
fan_init_limit_data:
		mov	cl,08h
		call	Get_GL518SM_Word
		mov 	bh,bl
		mov	ax,bx		        ;set fan limit data
		call	Set_GL518SM_Word

		mov	cl,10h
		call	Get_GL518SM_Byte
		or	al,01100000b    	;enable fan spk
		call	Set_GL518SM_Byte
		jmp 	short fan_init_finish
Skip_fan_init:
		mov	cl,10h
		call	Get_GL518SM_Byte
		and	al,NOT 01100000b        ;disable fan spk
		call	Set_GL518SM_Byte
fan_init_finish:
		pop	bx
endif ;SHOW_FAN_LIMIT_WARNING
;R30 -ends

Prg_GL518SM_Chip_End:

		ret

Prg_GL518SM_Chip	Endp
		ALIGN	4
GL518SM_TEMP_VAL:
		db	0120	;disabled
;R03		db	050	;50C
;R03		db	053	;53C
;R03		db	056	;56C
;R03		db	060	;60C
;R03		db	063	;63C
;R03		db	066	;66C
;R03		db	070	;70C
		db	051	;50C		;R03
		db	054	;53C		;R03
		db	057	;56C		;R03
		db	061	;60C		;R03
		db	065	;63C		;R03
		db	068	;66C		;R03
		db	072	;70C		;R03

;R30 -starts
; RPM = 480000/(Count * Divisor)
ifdef  SHOW_FAN_LIMIT_WARNING
FAN_LIMIT_WARNIN_TBL:
		db	03CH	; 1000 rpm divisor 8
		db	01EH	; 2000 rpm divisor 8
		db	014H	; 3000 rpm divisor 8
endif ;SHOW_FAN_LIMIT_WARNING
;R30 -ends

		assume	ds:EGROUP

endif	;SENSOR_IN_XGROUP		;R31
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
		dw	offset Current_CPU_Temp_Item, offset Show_Current_CPU_Temp
ifdef	SHOW_GL518SM_CPUFAN1
		dw	offset Current_CPUFAN1_Item, offset Show_Current_CPUFAN1
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
		dw	offset Current_CPUFAN2_Item, offset Show_Current_CPUFAN2
endif;	SHOW_GL518SM_CPUFAN2
		dw	offset Current_Vin3_Item, offset Show_Current_Vin3
;R09A - start
		dw	offset Current_Vin1_Item, offset Show_Current_Vin1
		dw	offset Current_Vin2_Item, offset Show_Current_Vin2
		dw	offset Current_Vdd_Item, offset Show_Current_Vdd
;R09A - 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_GL518SM_Item	;R20
First_GL518SM_Item	Label	Near		;R20

DEFINE_ITEM     GL518SM_TEMP_ITEM
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        menuitem <PMITEM,\
                  offset GL518SM_TEMP_Str,NOCT,GL518SM_CMOS_BITS,GL518SM_CMOS,GL518SM_CMOS_BITS,\
                  offset GL518SM_TEMP_Val,0,7,Xaxis,Yaxis ,   00000000b, 00000000b,offset Std_Help_Str>
DEFINE_ITEM	Current_CPU_Temp_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        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_GL518SM_CPUFAN1
DEFINE_ITEM	Current_CPUFAN1_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        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_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
DEFINE_ITEM	Current_CPUFAN2_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        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_GL518SM_CPUFAN2

DEFINE_ITEM	Current_Vin3_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        menuitem <SHOWONLY,\
                  offset Current_Vin3_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>

;R09A - start
DEFINE_ITEM	Current_Vin1_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        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				;R12
        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_Vdd_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        menuitem <SHOWONLY,\
                  offset Current_Vdd_Str,NOCT,0,KERNAL_CONTROL,00000001b,\
                  offset NullStr,0,0,Xaxis,Yaxis,0,0,offset Std_Help_Str>
;R09A - end

;R02 - start
ifdef	ACPI_SUPPORT
DEFINE_ITEM     ACPI_Critical_Item
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				;R12
        menuitem <PMITEM,\
                  offset ACPI_Critical_Str           ,NOCT,00011000b,SENSOR_ACPI_CMOS,SENSOR_ACPI_CMOS_BITS,\
                  offset Critical_str,0,3,Xaxis,Yaxis,00000000b,    00000000b,offset Std_Help_Str>
endif	;ACPI_SUPPORT
;R02 - end

;R30 -starts
ifdef  SHOW_FAN_LIMIT_WARNING
DEFINE_ITEM	FAN_WARNING_ITEM
DEFINE_MENUITEM	, GROUP_HEALTH, 0, 10				
	menuitem <PMITEM,\
        	 offset FAN_WARNING_STR,NOCT,FAN_WARNING_CMOS_BITS,FAN_WARNING_CMOS,FAN_WARNING_CMOS_BITS,\
	         offset FAN_WARNING_VAL,0,3,Xaxis,Yaxis ,   00000000b, 00000000b,offset Std_Help_Str>
endif ;SHOW_FAN_LIMIT_WARNING
;R30 -starts

		Public	Last_Gl518SM_Item	;R20
Last_Gl518SM_Item	Label	Near		;R20

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
;R02 - start
ifdef	ACPI_SUPPORT
ACPI_Critical_Str	db      'Shutdown Temperature'
			db	(COLLON_LOC - ($-(offset ACPI_Critical_Str))) dup (" ")
			db	': ',0
;R15Critical_str		db	'Disabled  ',0
;R15			db      '80๘C/176๘F',0
;R15			db      '85๘C/185๘F',0
;R15			db      '90๘C/194๘F',0

Critical_str		db      '60๘C/140๘F',0			;R15
			db      '65๘C/149๘F',0			;R15
			db      '70๘C/158๘F',0			;R15
			db	'75๘C/167๘F',0			;R15

endif	;ACPI_SUPPORT
;R02 - end
GL518SM_TEMP_Str	db      'CPU Warning Temperature'
			db	(COLLON_LOC - ($-(offset GL518SM_TEMP_Str))) dup (" ")
			db	': ',0
GL518SM_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

Current_CPU_Temp_Str	db	'Current CPU Temperature'
			db	(COLLON_LOC - ($-(offset Current_CPU_Temp_Str))) dup (" ")
			db	': ',0

ifdef	SHOW_GL518SM_CPUFAN1
Current_CPUFAN1_Str	db	'Current CPUFAN1 Speed'
			db	(COLLON_LOC - ($-(offset Current_CPUFAN1_Str))) dup (" ")
			db	': ',0
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
Current_CPUFAN2_Str	db	'Current CPUFAN2 Speed'
			db	(COLLON_LOC - ($-(offset Current_CPUFAN2_Str))) dup (" ")
			db	': ',0
endif;	SHOW_GL518SM_CPUFAN2
Current_Vin3_Str	db	'Current Vin3(V)'
			db	(COLLON_LOC - ($-(offset Current_Vin3_Str))) dup (" ")
			db	': ',0
;R09A - start
Current_Vin1_Str	db	'Current Vin1(V)'
			db	(COLLON_LOC - ($-(offset Current_Vin1_Str))) dup (" ")
			db	': ',0

Current_Vin2_Str	db	'Current Vin2(V)'
			db	(COLLON_LOC - ($-(offset Current_Vin2_Str))) dup (" ")
			db	': ',0

Current_Vdd_Str	db	'Current Vdd(V)'
			db	(COLLON_LOC - ($-(offset Current_Vdd_Str))) dup (" ")
			db	': ',0
;R09A - end

;R30 -starts
ifdef  SHOW_FAN_LIMIT_WARNING	
FAN_WARNING_STR:	db	'FAN Limit Warning'
			db	(COLLON_LOC - ($-(offset FAN_WARNING_STR))) dup (" ")
			db	': ',0
FAN_WARNING_VAL:
			db      'Disabled  ',0
			db      '1000 RPM  ',0
			db      '2000 RPM  ',0
			db      '3000 RPM  ',0
endif ;SHOW_FAN_LIMIT_WARNING	
;R30 -ends

;=====================

Show_Current_CPU_Temp	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R31
		Post_Func_Call E000_Show_Current_CPU_Temp
else	;SENSOR_IN_XGROUP					;R31
		Xcall X_Show_Current_CPU_Temp			;R31
endif	;SENSOR_IN_XGROUP					;R31
	@@:
		ret
Show_Current_CPU_Temp	Endp

ifdef	SHOW_GL518SM_CPUFAN1
Show_Current_CPUFAN1	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R31
		Post_Func_Call E000_Show_Current_CPUFAN1
else	;SENSOR_IN_XGROUP					;R31
		Xcall X_Show_Current_CPUFAN1			;R31
endif	;SENSOR_IN_XGROUP					;R31
	@@:
		ret
Show_Current_CPUFAN1	Endp
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
Show_Current_CPUFAN2	Proc	Near

		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R31
		Post_Func_Call E000_Show_Current_CPUFAN2
else	;SENSOR_IN_XGROUP					;R31
		Xcall X_Show_Current_CPUFAN2			;R31
endif	;SENSOR_IN_XGROUP					;R31
	@@:

		ret
Show_Current_CPUFAN2	Endp
endif;	SHOW_GL518SM_CPUFAN2

Show_Current_Vin3	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R31
		post_func_call	E000_Show_Current_Vin3
else	;SENSOR_IN_XGROUP					;R31
		Xcall	X_Show_Current_Vin3			;R31
endif	;SENSOR_IN_XGROUP					;R31
	@@:
		ret
Show_Current_Vin3	Endp

;R09A - start
Show_Current_Vin1	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R31
		post_func_call	E000_Show_Current_Vin1
else	;SENSOR_IN_XGROUP					;R31
		Xcall	X_Show_Current_Vin1			;R31
endif	;SENSOR_IN_XGROUP					;R31
	@@:
		ret
Show_Current_Vin1	Endp

Show_Current_Vin2	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R31
		post_func_call	E000_Show_Current_Vin2
else	;SENSOR_IN_XGROUP					;R31
		Xcall	X_Show_Current_Vin2			;R31
endif	;SENSOR_IN_XGROUP					;R31
	@@:
		ret
Show_Current_Vin2	Endp

Show_Current_Vdd	Proc	Near
		cmp	byte ptr CALLTYPE[bp],POST_CALL
		jne	short @F
ifndef	SENSOR_IN_XGROUP					;R31
		post_func_call	E000_Show_Current_Vdd
else	;SENSOR_IN_XGROUP					;R31
		Xcall	X_Show_Current_Vdd			;R31
endif	;SENSOR_IN_XGROUP					;R31
	@@:
		ret
Show_Current_Vdd	Endp
;R09A - 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		;R31

ifndef		Vin3_R1
Vin3_R1		equ	0
endif;		Vin3_R1
ifndef		Vin3_R2
Vin3_R2		equ	0
endif;		Vin3_R2

;R09A - start
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		Vdd_R1
Vdd_R1		equ	0
endif;		Vdd_R1
ifndef		Vdd_R2
Vdd_R2		equ	0
endif;		Vdd_R2

;R09A - end


E000_Show_Current_CPU_Temp	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,04h
		call	Get_GL518SM_Byte

;System Temp. = (Rx(04)+THERMO_OFFS)
;THERMO_OFFS = -119

;R03 - start
; ax = ax*0.9765625
                xor     ah, ah
                mov     bx, ax
                shl     ax, 7
                sub     ax, bx
                sub     ax, bx
                sub     ax, bx
                shr     ax, 7
;R03 - end

                sub     al,119

		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_GL518SM_CPUFAN1
E000_Show_Current_CPUFAN1	Proc	Near

		cmp	al, Special_Before
		je	short Skip_Show_Fan1
		mov	cl,7h
		call	Get_GL518SM_Word
;R27ifdef	SHOW_GL518SM_CPUFAN2			;R26
;R27		mov	al,ah			;ah is FAN1 counter
;R27endif;	SHOW_GL518SM_CPUFAN2			;R26
		or	al,al
		jne	short CPUFAN_WORKING1
		xor	ax,ax
		jmp	short SHOW_FAN1
	CPUFAN_WORKING1:
		xor	bh,bh
		mov	bl,al

;R09ifndef	FAN_Divisor
;R09     		mov	ax,0ea60h		;0ea60h=(480000/8)
;R09		mov	dx,0h			;Count=(480000/(RPM*8))
;R09else;
;R09	if	FAN_Divisor 	eq	1	;075300h=(480000/1)
;R09     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R09		mov	dx,05h
;R09	endif;	FAN_Divisor 	eq	1
;R09	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
;R09     		mov	ax,0a980h		;Count=(480000/(RPM*8))
;R09		mov	dx,03h
;R09	endif;	FAN_Divisor 	eq	2
;R09	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
;R09     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
;R09		mov	dx,01h
;R09	endif;	FAN_Divisor 	eq	4
;R09	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
;R09     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
;R09		mov	dx,0h
;R09	endif;	FAN_Divisor 	eq	8
;R09endif;	FAN_Divisor

;R09 - start
		push	bx
		mov	cl,01h
		call	Get_GL518SM_Byte
		mov	cl,al
		pop	bx

ifndef	FAN_Divisor
     		mov	ax,0ea60h		;0ea60h=(480000/8)
		mov	dx,0h			;Count=(480000/(RPM*8))
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)
;R16     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R16		mov	dx,05h

     		mov	ax,05300h		;Count=(480000/(RPM*1));R16
		mov	dx,07h					       ;R16

	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor

		cmp	cl,80h			;Is old Ver.
		jne	short @F		;Yes, skip
ifndef	FAN_Divisor
;R16     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R16		mov	dx,05h

     		mov	ax,05300h		;Count=(480000/(RPM*1));R16
		mov	dx,07h					       ;R16
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)
;R16     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R16		mov	dx,05h

     		mov	ax,05300h		;Count=(480000/(RPM*1));R16
		mov	dx,07h					       ;R16
	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
	@@:
;R09 - end

		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
	Skip_Show_Fan1:
		ret
E000_Show_Current_CPUFAN1	endp

endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2

E000_Show_Current_CPUFAN2	Proc	Near

		cmp	al, Special_Before
		je	short Skip_Show_Fan2
		mov	cl,7h
ifndef	Special_Cpufan_for_darter	 	;R11
		call	Get_GL518SM_Word
else;	Special_Cpufan_for_darter		;R11
		call	Get_GL518SM_Byte	;R11
endif;	Special_Cpufan_for_darter		;R11
		mov	al, ah			;R27
		or	al,al			;al is FAN2 counter
		jne	short CPUFAN_WORKING2
		xor	ax,ax
		jmp	short SHOW_FAN2
	CPUFAN_WORKING2:
		xor	bh,bh
		mov	bl,al
;R09ifndef	FAN_Divisor
;R09     		mov	ax,0ea60h		;0ea60h=(480000/8)
;R09		mov	dx,0h			;Count=(480000/(RPM*8))
;R09else;
;R09	if	FAN_Divisor 	eq	1	;075300h=(480000/1)
;R09     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R09		mov	dx,05h
;R09	endif;	FAN_Divisor 	eq	1
;R09	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
;R09     		mov	ax,0a980h		;Count=(480000/(RPM*8))
;R09		mov	dx,03h
;R09	endif;	FAN_Divisor 	eq	2
;R09	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
;R09     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
;R09		mov	dx,01h
;R09	endif;	FAN_Divisor 	eq	4
;R09	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
;R09     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
;R09		mov	dx,0h
;R09	endif;	FAN_Divisor 	eq	8
;R09endif;	FAN_Divisor

;R09 - start
		push	bx
		mov	cl,01h
		call	Get_GL518SM_Byte
		mov	cl,al
		pop	bx

ifndef	FAN_Divisor
     		mov	ax,0ea60h		;0ea60h=(480000/8)
		mov	dx,0h			;Count=(480000/(RPM*8))
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)
;R16     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R16		mov	dx,05h

     		mov	ax,05300h		;Count=(480000/(RPM*1));R16
		mov	dx,07h					       ;R16
	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor

		cmp	cl,80h			;Is old Ver.
		jne	short @F		;Yes, skip
ifndef	FAN_Divisor
;R16     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R16		mov	dx,05h

     		mov	ax,05300h		;Count=(480000/(RPM*1));R16
		mov	dx,07h					       ;R16
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)
;R16     		mov	ax,0265ch		;Count=(480000/(RPM*1))
;R16		mov	dx,05h

     		mov	ax,05300h		;Count=(480000/(RPM*1));R16
		mov	dx,07h					       ;R16
	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor
	@@:
;R09 - end

		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
	Skip_Show_Fan2:
		ret
E000_Show_Current_CPUFAN2	endp

endif;	SHOW_GL518SM_CPUFAN2

Display_Vin	Proc	Near

		cmp	al,0ffh
		jne	short Vin_WORKING
		xor	ax,ax
	Vin_WORKING:

		or	dx,dx			;Is above 4 Voltage
		jz	short Below4		;No, go to below 4V handler

		push	bx
		push	dx
		xor	ah,ah
		mov	bl,18			;(4800/255)
		mul	bl

		pop	bx			;(R1+R2)
		mul	bx

		pop	bx			;(R2)
		div	bx

		xor	dx,dx

		mov	bx,1000
		div	bx

		push	dx

		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9B
		call	E000_DISP_Byte_INT2
		jmp	short Above_9B
	Below_9B:
		call	E000_DISP_Byte_HEX2
	Above_9B:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret

	Below4:
                xor     ah,ah
                mov     bx,19                   ;(4800/256)
		mul	bx
		mov	bx,1000
		div	bx
                push    dx

		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9A
		call	E000_DISP_Byte_INT2
		jmp	short Above_9A
	Below_9A:
		call	E000_DISP_Byte_HEX2
	Above_9A:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret
Display_Vin	endp

Display_Vdd	Proc	Near

		cmp	al,0ffh
		jne	short Vdd_WORKING
		xor	ax,ax
	Vdd_WORKING:

		or	dx,dx			;Is above 4 Voltage
		jz	short Vdd_Below4	;No, go to below 4V handler

		push	bx
		push	dx
		xor	ah,ah
		mov	bl,27			;(2550/256)*2.5
		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 Vdd_Below_9B
		call	E000_DISP_Byte_INT2
		jmp	short Vdd_Above_9B
	Vdd_Below_9B:
		call	E000_DISP_Byte_HEX2
	Vdd_Above_9B:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret

	Vdd_Below4:
                xor     ah,ah
;R28		mov	bl,27			;(2550/256)*2.5	
		mov	bl,25			;(2550/256)*2.5	;R28
		mul	bx
		mov	bx,1000
		div	bx
                push    dx

		call	E000_DISP_Byte_INT2

		mov	al, '.'
		call	E000_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Vdd_Below_9A
		call	E000_DISP_Byte_INT2
		jmp	short Vdd_Above_9A
	Vdd_Below_9A:
		call	E000_DISP_Byte_HEX2
	Vdd_Above_9A:

		mov	al, ' '
		call	E000_Display_Char
		mov	al, 'V'
		call	E000_Display_Char

		ret
Display_Vdd	endp

E000_Show_Current_Vin3	Proc	Near

		cmp	al, Special_Before
		je	short Skip_V3_Show

		mov	cl,0dh
		call	Get_GL518SM_Byte

;R09A;Vin3=(Rx(0d)+(2))*(4.8/256)*(V3ratio)
;R09A;V3ratio = 1
;R09A		add	al,2

;R09A - start
;Old Ver:
;	Vin3=(Rx(0d)+(2))*(4.8/256)*(V3ratio)
;	V3ratio = 1
;New Ver:
;	Vin3=(Rx(0d)-(0.6))*(4.8/256)*(V3ratio)
;	V3ratio = 1
		push	ax
		mov	cl,01h
		call	Get_GL518SM_Byte
		mov	bl,al
		pop	ax
		add	al,2
		cmp	bl,80h			;Is old ver?
		jne	short @F		;Yes, skip !
		sub	al,3
	@@:
;R09A - end

		mov	dx,(Vin3_R1+Vin3_R2)
		mov	bx,Vin3_R2

		call	Display_Vin
Skip_V3_Show:
		ret

E000_Show_Current_Vin3	endp

;R09A - start
;New Ver:
;	Vin1=(Rx(14h)-(0.6))*(4.8/256)*(V1ratio)
;	V1ratio = 1
E000_Show_Current_Vin1	Proc	Near
		cmp	al, Special_Before
		je	short Skip_V1_Show

		mov	cl,14h
		call	Get_GL518SM_Byte
		sub	al,1
		mov	dx,(Vin1_R1+Vin1_R2)
		mov	bx,Vin1_R2
		call	Display_Vin

Skip_V1_Show:
		ret

E000_Show_Current_Vin1	endp

;New Ver:
;	Vin2=(Rx(13h)-(0.6))*(4.8/256)*(V2ratio)
;	V2ratio = 1
E000_Show_Current_Vin2	Proc	Near
		cmp	al, Special_Before
		je	short Skip_V2_Show

		mov	cl,13h
		call	Get_GL518SM_Byte
		sub	al,1
		mov	dx,(Vin2_R1+Vin2_R2)
		mov	bx,Vin2_R2
		call	Display_Vin

Skip_V2_Show:
		ret

E000_Show_Current_Vin2	endp

;New Ver:
;	Vdd=2.5*(Rx(15h)-4.5)*(2.55/256)
E000_Show_Current_Vdd	Proc	Near
		cmp	al, Special_Before
		je	short Skip_Vdd_Show

		mov	cl,15h
		call	Get_GL518SM_Byte
		sub	al,5
ifdef	SHOW_VDD_OFFSET					;R18
		add	al, byte ptr SHOW_VDD_OFFSET	;R18
endif;	SHOW_VDD_OFFSET					;R18
		mov	dx,(Vdd_R1+Vdd_R2)
		mov	bx,Vdd_R2
		call	Display_Vdd

Skip_Vdd_Show:
		ret

E000_Show_Current_Vdd	endp
;R09A - end

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

ifndef	BIOS60							;R12
		Public	Update_GL518SM_Screen
Update_GL518SM_Screen	Proc	near

		pusha

;R14 - start
ifdef	Update_Sensor_in_CPUFEAT				
		cmp	byte ptr CUR_PAGE[bp], PAGE_CPU
else;	Update_Sensor_in_CPUFEAT
;R14 - end
ifdef	Update_Sensor_in_IOFEAT					;R05
		cmp	byte ptr CUR_PAGE[bp], PAGE_IO		;R05
else;	Update_Sensor_in_IOFEAT					;R05
		cmp	byte ptr CUR_PAGE[bp], PAGE_CFEATURE
endif;	Update_Sensor_in_IOFEAT					;R05
endif;	Update_Sensor_in_CPUFEAT				;R14
		jne	short Update_GL518SM_end

	;----------------------------------------
		mov	si, offset GL518SM_Item_List

	Update_GL518SM_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_GL518SM_end
		push	si
		F000_call	Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_GL518SM_Start
	;----------------------------------------

	Update_GL518SM_end:

		popa
		ret

Update_GL518SM_Screen	Endp
endif	;BIOS60							;R12

ifdef	BIOS60							;R12
	db	'$SpeRT'					;R12
endif	;BIOS60							;R12

GL518SM_Item_List	Label	Word

ifdef	BIOS60							;R12
	dw	GL518SM_Runtime_No					;R12
endif	;BIOS60							;R12

	dw	offset Current_CPU_Temp_Item
ifdef	SHOW_GL518SM_CPUFAN1
	dw	offset Current_CPUFAN1_Item
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
	dw	offset Current_CPUFAN2_Item
endif;	SHOW_GL518SM_CPUFAN2
	dw	offset Current_Vin3_Item
	dw	offset Current_Vin1_Item		;R09A
	dw	offset Current_Vin2_Item		;R09A
	dw	offset Current_Vdd_Item			;R09A

GL518SM_Runtime_No	EQU	(($ - offset GL518SM_Item_List)-2)/2	;R12

	dw	-1

ENDIF	;SENSOR_IN_XGROUP			;R31
ENDIF	;COMPILE_FOR_SENSOR_MNU

;R20 - start
IF	COMPILE_FOR_SENSOR_MNU EQ 4
	dw	offset First_GL518SM_Item, offset Last_Gl518SM_Item
ifndef	SENSOR_IN_XGROUP						;R31
	dw	SEG Prg_GL518SM_Chip, offset Prg_GL518SM_Chip
else	;SENSOR_IN_XGROUP						;R31
	dw	SEG X_Prg_GL518SM_Chip, offset X_Prg_GL518SM_Chip	;R31
endif	;SENSOR_IN_XGROUP						;R31
ENDIF	;COMPILE_FOR_SENSOR_MNU

IF	COMPILE_FOR_SENSOR_MNU EQ 5
	extrn	First_GL518SM_Item:near
	extrn	Last_Gl518SM_Item:near
ifndef	SENSOR_IN_XGROUP						;R31
	extrn	Prg_GL518SM_Chip:near
else	;SENSOR_IN_XGROUP						;R31
	extrn	X_Prg_GL518SM_Chip:far					;R31
endif	;SENSOR_IN_XGROUP						;R31
ENDIF	;COMPILE_FOR_SENSOR_MNU
;R20 - end

endif	;COMPILE_FOR_SENSOR_MNU


;R31 - 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	GL518SM_ID		
GL518SM_ID	EQU	5Ah
endif;	GL518SM_ID		
		public	X_Get_GL518SM_Byte
		public	X_Set_GL518SM_Byte
		public	X_Get_GL518SM_Word
		public	X_Set_GL518SM_Word
		extrn	X_GetItem_Value:near

X_Get_GL518SM_Byte	Proc	Near
			mov	ch, GL518SM_ID
			call far ptr	EGROUP:fproc_Ct_I2CReadByte
			ret
X_Get_GL518SM_Byte	ENDP

X_Set_GL518SM_Byte	Proc	Near
			mov	ch, GL518SM_ID
			call far ptr	EGROUP:fproc_Ct_I2CWriteByte
			ret
X_Set_GL518SM_Byte	ENDP

X_Get_GL518SM_Word	Proc	Near
			mov	ch, GL518SM_ID
			call far ptr	EGROUP:fproc_Ct_I2CReadWord
			ret
X_Get_GL518SM_Word	ENDP

X_Set_GL518SM_Word	Proc	Near
			mov	ch, GL518SM_ID
			call far ptr	EGROUP:fproc_Ct_I2CWriteWord
			ret
X_Set_GL518SM_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
		test	word ptr es:[di],01h
		jz	short No_Sensor

		mov	di,offset DGROUP:TEMP1_HIGH

		extrn	GL518SM_TEMP_ITEM:near
		mov	si,offset DGROUP:GL518SM_TEMP_ITEM
		call	X_GetItem_Value
		mov	si,offset GL518SM_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]
		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_GL518SM_Chip
X_Prg_GL518SM_Chip	Proc	far

		extrn	GL518SM_TEMP_ITEM:near
		extrn	Current_CPU_Temp_Item:near
ifdef	SHOW_GL518SM_CPUFAN1
		extrn	Current_CPUFAN1_Item:near
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
		extrn	Current_CPUFAN2_Item:near
endif;	SHOW_GL518SM_CPUFAN2
		extrn	Current_Vdd_Item:near		
		extrn	Current_Vin1_Item:near		
		extrn	Current_Vin2_Item:near		
		extrn	Current_Vin3_Item:near

		extrn	X_F000_Shadow_W:near
		extrn	X_F000_Shadow_R:near

ifdef	Special_GL518SM_Item_Patch	

		mov	cl,00h
		call	X_Get_GL518SM_Byte
		jnc	short @F

		push	ds
		mov	ax,0f000h
		mov	ds,ax

		assume	ds:DGROUP
		call	X_F000_Shadow_W

		or	word ptr ds:[GL518SM_TEMP_ITEM].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_CPU_Temp_Item].ITEMSTAT,ITEMDISABLE
ifdef	SHOW_GL518SM_CPUFAN1
		or	word ptr ds:[Current_CPUFAN1_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
		or	word ptr ds:[Current_CPUFAN2_Item].ITEMSTAT,ITEMDISABLE
endif;	SHOW_GL518SM_CPUFAN2
		or	word ptr ds:[Current_Vin3_Item].ITEMSTAT,ITEMDISABLE

		or	word ptr ds:[Current_Vin1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vdd_Item].ITEMSTAT,ITEMDISABLE

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

ifdef	ACPI_SUPPORT
		and	word ptr ds:[SENSOR_FLAG],not 01h
endif	;ACPI_SUPPORT

		call	X_F000_Shadow_R
		pop	ds
		jmp	Prg_GL518SM_Chip_End
	@@:
endif;	Special_GL518SM_Item_Patch

		mov	cl,01h
		call	X_Get_GL518SM_Byte
		cmp	al,80h
		je	short New_Ver_Sure

		push	ds
		mov	ax,0f000h
		mov	ds,ax

		assume	ds:DGROUP
		call	X_F000_Shadow_W
		or	word ptr ds:[Current_Vin1_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vin2_Item].ITEMSTAT,ITEMDISABLE
		or	word ptr ds:[Current_Vdd_Item].ITEMSTAT,ITEMDISABLE
		call	X_F000_Shadow_R
		pop	ds
New_Ver_Sure:
		mov	cl,03h
		mov	al,80h
		call	X_Set_GL518SM_Byte			;Reset GL518SM

		extrn	GL518SM_TEMP_ITEM:near
		mov	si,offset DGROUP:GL518SM_TEMP_ITEM
		call	X_GetItem_Value
		or	al,al
		jz	short CPU_Temp_Disable

		mov	si,offset GL518SM_TEMP_VAL
		xor	ah,ah
		add	si,ax
		mov	al,cs:[si]

		add	al,122			;Temp_Offset = 119

		push	ax
		xor	ah,ah
		mov	cl,05
		call	X_Set_GL518SM_Byte	;set Tos (High limit)

		pop	ax
		sub	al,5
		xor	ah,ah
		mov	cl,06
		call	X_Set_GL518SM_Byte	;set Thyst (Low limit)

		mov	cl,10h
		mov	al,10h
		call	X_Set_GL518SM_Byte	;Enable CPU_Temp alarm

		mov	cl,11h						
		mov	al,10h						
		call	X_Set_GL518SM_Byte	;Enable CPU_Temp IRQ	

		jmp	short @F

CPU_Temp_Disable:

		mov	cl,03h
		mov	al,04h
		call	X_Set_GL518SM_Byte	;Disable IRQ# output

	@@:
		mov	cl,03h
		call	X_Get_GL518SM_Byte			
		or	al,40h
		mov	cl,03h
		call	X_Set_GL518SM_Byte	;Start GL518SM

ifdef  SHOW_FAN_LIMIT_WARNING
		extrn   FAN_WARNING_ITEM:Near
		push	bx
		mov	si,offset DGROUP:FAN_WARNING_ITEM
		call	X_GetItem_Value
		or	al,al			; item disable ?
		jz	short Skip_fan_init

		mov	si,offset FAN_LIMIT_WARNIN_TBL
		xor	ah,ah
		dec	al
		add	si,ax
		mov	bl,cs:[si]

		mov	cl,0fh
		call	X_Get_GL518SM_Byte	;get fan divisor
		shr	al,6

		cmp 	al,0	  	    			
		je	short Skip_fan_init 	;if divisor = 1 skip

		cmp 	al,1	  	    	; is divisor 2	
		jne 	short fan_divisor4
		shl	bl,2
		jmp	short fan_init_limit_data
		
fan_divisor4:
		cmp 	al,2	  	    	; is divisor 4	
		jne 	short fan_init_limit_data
		shl	bl,1
fan_init_limit_data:
		mov	cl,08h
		call	X_Get_GL518SM_Word
		mov 	bh,bl
		mov	ax,bx		        ;set fan limit data
		call	X_Set_GL518SM_Word

		mov	cl,10h
		call	X_Get_GL518SM_Byte
		or	al,01100000b    	;enable fan spk
		call	X_Set_GL518SM_Byte
		jmp 	short fan_init_finish
Skip_fan_init:
		mov	cl,10h
		call	X_Get_GL518SM_Byte
		and	al,NOT 01100000b        ;disable fan spk
		call	X_Set_GL518SM_Byte
fan_init_finish:
		pop	bx
endif ;SHOW_FAN_LIMIT_WARNING

Prg_GL518SM_Chip_End:

		retf

X_Prg_GL518SM_Chip	Endp
		ALIGN	4
GL518SM_TEMP_VAL:
		db	0120	;disabled
		db	051	;50C		
		db	054	;53C		
		db	057	;56C		
		db	061	;60C		
		db	065	;63C		
		db	068	;66C		
		db	072	;70C		

; RPM = 480000/(Count * Divisor)
ifdef  SHOW_FAN_LIMIT_WARNING
FAN_LIMIT_WARNIN_TBL:
		db	03CH	; 1000 rpm divisor 8
		db	01EH	; 2000 rpm divisor 8
		db	014H	; 3000 rpm divisor 8
endif ;SHOW_FAN_LIMIT_WARNING

		assume	ds:XGROUP

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		Vin3_R1
Vin3_R1		equ	0
endif;		Vin3_R1
ifndef		Vin3_R2
Vin3_R2		equ	0
endif;		Vin3_R2

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		Vdd_R1
Vdd_R1		equ	0
endif;		Vdd_R1
ifndef		Vdd_R2
Vdd_R2		equ	0
endif;		Vdd_R2


X_Show_Current_CPU_Temp	Proc	Near

		cmp	al, Special_Before
		je	short @F
		mov	cl,04h
		call	X_Get_GL518SM_Byte

;System Temp. = (Rx(04)+THERMO_OFFS)
;THERMO_OFFS = -119

; ax = ax*0.9765625
                xor     ah, ah
                mov     bx, ax
                shl     ax, 7
                sub     ax, bx
                sub     ax, bx
                sub     ax, bx
                shr     ax, 7

                sub     al,119

		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_GL518SM_CPUFAN1
X_Show_Current_CPUFAN1	Proc	Near

		cmp	al, Special_Before
		je	short Skip_Show_Fan1
		mov	cl,7h
		call	X_Get_GL518SM_Word
		or	al,al
		jne	short CPUFAN_WORKING1
		xor	ax,ax
		jmp	short SHOW_FAN1
	CPUFAN_WORKING1:
		xor	bh,bh
		mov	bl,al

		push	bx
		mov	cl,01h
		call	X_Get_GL518SM_Byte
		mov	cl,al
		pop	bx

ifndef	FAN_Divisor
     		mov	ax,0ea60h		;0ea60h=(480000/8)
		mov	dx,0h			;Count=(480000/(RPM*8))
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)

     		mov	ax,05300h		;Count=(480000/(RPM*1))
		mov	dx,07h					       

	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor

		cmp	cl,80h			;Is old Ver.
		jne	short @F		;Yes, skip
ifndef	FAN_Divisor

     		mov	ax,05300h		;Count=(480000/(RPM*1))
		mov	dx,07h					       
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)

     		mov	ax,05300h		;Count=(480000/(RPM*1))
		mov	dx,07h					       
	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	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
	Skip_Show_Fan1:
		ret
X_Show_Current_CPUFAN1	endp

endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2

X_Show_Current_CPUFAN2	Proc	Near

		cmp	al, Special_Before
		je	short Skip_Show_Fan2
		mov	cl,7h
ifndef	Special_Cpufan_for_darter	 	
		call	X_Get_GL518SM_Word
else;	Special_Cpufan_for_darter		
		call	X_Get_GL518SM_Byte	
endif;	Special_Cpufan_for_darter		
		mov	al, ah			
		or	al,al			;al is FAN2 counter
		jne	short CPUFAN_WORKING2
		xor	ax,ax
		jmp	short SHOW_FAN2
	CPUFAN_WORKING2:
		xor	bh,bh
		mov	bl,al

		push	bx
		mov	cl,01h
		call	X_Get_GL518SM_Byte
		mov	cl,al
		pop	bx

ifndef	FAN_Divisor
     		mov	ax,0ea60h		;0ea60h=(480000/8)
		mov	dx,0h			;Count=(480000/(RPM*8))
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)

     		mov	ax,05300h		;Count=(480000/(RPM*1))
		mov	dx,07h					       
	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	endif;	FAN_Divisor 	eq	8
endif;	FAN_Divisor

		cmp	cl,80h			;Is old Ver.
		jne	short @F		;Yes, skip
ifndef	FAN_Divisor

     		mov	ax,05300h		;Count=(480000/(RPM*1))
		mov	dx,07h					       
else;
	if	FAN_Divisor 	eq	1	;075300h=(480000/1)

     		mov	ax,05300h		;Count=(480000/(RPM*1))
		mov	dx,07h					       
	endif;	FAN_Divisor 	eq	1
	if	FAN_Divisor 	eq	2	;03a980h=(480000/2)
     		mov	ax,0a980h		;Count=(480000/(RPM*2))
		mov	dx,03h
	endif;	FAN_Divisor 	eq	2
	if	FAN_Divisor 	eq	4	;01d4c0h=(480000/4)
     		mov	ax,0d4c0h		;Count=(480000/(RPM*4))
		mov	dx,01h
	endif;	FAN_Divisor 	eq	4
	if	FAN_Divisor 	eq	8	;0ea60h=(480000/8)
     		mov	ax,0ea60h		;Count=(480000/(RPM*8))
		mov	dx,0h
	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
	Skip_Show_Fan2:
		ret
X_Show_Current_CPUFAN2	endp

endif;	SHOW_GL518SM_CPUFAN2

X_Display_Vin	Proc	Near

		cmp	al,0ffh
		jne	short Vin_WORKING
		xor	ax,ax
	Vin_WORKING:

		or	dx,dx			;Is above 4 Voltage
		jz	short Below4		;No, go to below 4V handler

		push	bx
		push	dx
		xor	ah,ah
		mov	bl,18			;(4800/255)
		mul	bl

		pop	bx			;(R1+R2)
		mul	bx

		pop	bx			;(R2)
		div	bx

		xor	dx,dx

		mov	bx,1000
		div	bx

		push	dx

		call far ptr	DGROUP:fproc_DISP_Byte_INT2

		mov	al, '.'
		call	X_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9B
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Above_9B
	Below_9B:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Above_9B:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret

	Below4:
                xor     ah,ah
                mov     bx,19                   ;(4800/256)
		mul	bx
		mov	bx,1000
		div	bx
                push    dx

		call far ptr	DGROUP:fproc_DISP_Byte_INT2

		mov	al, '.'
		call	X_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Below_9A
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Above_9A
	Below_9A:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Above_9A:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret
X_Display_Vin	endp

X_Display_Vdd	Proc	Near

		cmp	al,0ffh
		jne	short Vdd_WORKING
		xor	ax,ax
	Vdd_WORKING:

		or	dx,dx			;Is above 4 Voltage
		jz	short Vdd_Below4	;No, go to below 4V handler

		push	bx
		push	dx
		xor	ah,ah
		mov	bl,27			;(2550/256)*2.5
		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 Vdd_Below_9B
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Vdd_Above_9B
	Vdd_Below_9B:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Vdd_Above_9B:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret

	Vdd_Below4:
                xor     ah,ah
		mov	bl,25			;(2550/256)*2.5	
		mul	bx
		mov	bx,1000
		div	bx
                push    dx

		call far ptr	DGROUP:fproc_DISP_Byte_INT2

		mov	al, '.'
		call	X_Display_Char

		pop	ax
		mov	bl,10
		div	bl

		cmp	al,9
		jbe	short Vdd_Below_9A
		call far ptr	DGROUP:fproc_DISP_Byte_INT2
		jmp	short Vdd_Above_9A
	Vdd_Below_9A:
		call far ptr	DGROUP:fproc_DISP_Byte_HEX2
	Vdd_Above_9A:

		mov	al, ' '
		call	X_Display_Char
		mov	al, 'V'
		call	X_Display_Char

		ret
X_Display_Vdd	endp

X_Show_Current_Vin3	Proc	Near

		cmp	al, Special_Before
		je	short Skip_V3_Show

		mov	cl,0dh
		call	X_Get_GL518SM_Byte

;Old Ver:
;	Vin3=(Rx(0d)+(2))*(4.8/256)*(V3ratio)
;	V3ratio = 1
;New Ver:
;	Vin3=(Rx(0d)-(0.6))*(4.8/256)*(V3ratio)
;	V3ratio = 1
		push	ax
		mov	cl,01h
		call	X_Get_GL518SM_Byte
		mov	bl,al
		pop	ax
		add	al,2
		cmp	bl,80h			;Is old ver?
		jne	short @F		;Yes, skip !
		sub	al,3
	@@:

		mov	dx,(Vin3_R1+Vin3_R2)
		mov	bx,Vin3_R2

		call	X_Display_Vin
Skip_V3_Show:
		ret

X_Show_Current_Vin3	endp

;New Ver:
;	Vin1=(Rx(14h)-(0.6))*(4.8/256)*(V1ratio)
;	V1ratio = 1
X_Show_Current_Vin1	Proc	Near
		cmp	al, Special_Before
		je	short Skip_V1_Show

		mov	cl,14h
		call	X_Get_GL518SM_Byte
		sub	al,1
		mov	dx,(Vin1_R1+Vin1_R2)
		mov	bx,Vin1_R2
		call	X_Display_Vin

Skip_V1_Show:
		ret

X_Show_Current_Vin1	endp

;New Ver:
;	Vin2=(Rx(13h)-(0.6))*(4.8/256)*(V2ratio)
;	V2ratio = 1
X_Show_Current_Vin2	Proc	Near
		cmp	al, Special_Before
		je	short Skip_V2_Show

		mov	cl,13h
		call	X_Get_GL518SM_Byte
		sub	al,1
		mov	dx,(Vin2_R1+Vin2_R2)
		mov	bx,Vin2_R2
		call	X_Display_Vin

Skip_V2_Show:
		ret

X_Show_Current_Vin2	endp

;New Ver:
;	Vdd=2.5*(Rx(15h)-4.5)*(2.55/256)
X_Show_Current_Vdd	Proc	Near
		cmp	al, Special_Before
		je	short Skip_Vdd_Show

		mov	cl,15h
		call	X_Get_GL518SM_Byte
		sub	al,5
ifdef	SHOW_VDD_OFFSET					
		add	al, byte ptr SHOW_VDD_OFFSET	
endif;	SHOW_VDD_OFFSET					
		mov	dx,(Vdd_R1+Vdd_R2)
		mov	bx,Vdd_R2
		call	X_Display_Vdd

Skip_Vdd_Show:
		ret

X_Show_Current_Vdd	endp

ifndef	BIOS60							
		Public	X_Update_GL518SM_Screen
X_Update_GL518SM_Screen	Proc	far

		pusha

ifdef	Update_Sensor_in_CPUFEAT				
		cmp	byte ptr CUR_PAGE[bp], PAGE_CPU
else;	Update_Sensor_in_CPUFEAT

ifdef	Update_Sensor_in_IOFEAT					
		cmp	byte ptr CUR_PAGE[bp], PAGE_IO		
else;	Update_Sensor_in_IOFEAT					
		cmp	byte ptr CUR_PAGE[bp], PAGE_CFEATURE
endif;	Update_Sensor_in_IOFEAT					
endif;	Update_Sensor_in_CPUFEAT				
		jne	short Update_GL518SM_end

	;----------------------------------------
		mov	si, offset GL518SM_Item_List

	Update_GL518SM_Start:

		mov	bx, cs:[si]
		cmp	bx, -1
		je	short Update_GL518SM_end
		push	si
		call	X_Display_Whole_Item
		pop	si
		inc	si
		inc	si
		jmp	short Update_GL518SM_Start
	;----------------------------------------

	Update_GL518SM_end:

		popa
		retf

X_Update_GL518SM_Screen	Endp
endif	;BIOS60							

ifdef	BIOS60							
	db	'$SpeRT'					
endif	;BIOS60							

GL518SM_Item_List	Label	Word

ifdef	BIOS60							
	dw	GL518SM_Runtime_No					
endif	;BIOS60							

	dw	offset Current_CPU_Temp_Item
ifdef	SHOW_GL518SM_CPUFAN1
	dw	offset Current_CPUFAN1_Item
endif;	SHOW_GL518SM_CPUFAN1
ifdef	SHOW_GL518SM_CPUFAN2
	dw	offset Current_CPUFAN2_Item
endif;	SHOW_GL518SM_CPUFAN2
	dw	offset Current_Vin3_Item
	dw	offset Current_Vin1_Item		
	dw	offset Current_Vin2_Item		
	dw	offset Current_Vdd_Item			

GL518SM_Runtime_No	EQU	(($ - offset GL518SM_Item_List)-2)/2	

	dw	-1

ENDIF	;SENSOR_IN_XGROUP			
ENDIF	;COMPILE_FOR_SENSOR_MNU
ENDIF	;COMPILE_FOR_SENSOR_MNU

;R31 - end
