;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R04	10/27/98 RAX	Added define to monitor other wakeup source patch if
;			WIN98 schedule task turn on then system can't wakeup
;			by other source except IRQ or timer time-out.
;R03A	03/25/97 RAY	Should not use F000_Get_Cmos for run time code
;R03	03/24/97 RAX	Add "V_ALARM_IN_E000" define
;R02	10/07/96 RAY	Add "ASSUME DS:PM_RAM"
;R01	07/18/96 RIC	Get RTC timer twice for some RTC auto-resume.
;R00	05/23/96 RAY	Initial Reviosn to Support APM1.2

;[]========================================================================[]
;Input	:	None
;Output	:	CF : Resume timer not enabled
;		NC : System enter suspend & then wake up by Virtual Resume Timer
;[]========================================================================[]
		ASSUME	DS:PM_RAM			;R02
Virtual_Resume_Timer	Proc	Near

		test	[EXTEND_APM_STATUS], RESUME_TIMER_ENABLED
		jnz	short @F
		stc
		ret
	@@:
		pusha

		call	Low_Power_Throttling

	Wait_For_WakeUp_Source:

ifdef	Chk_more_V_Alarm_wakeup_source			;R04
		call	Chkwakeup_source		;R04
		jnz	Wake_Up_By_IRQ			;R04
endif	;Chk_more_V_Alarm_wakeup_source			;R04

		mov	al, 0ah
		out	0a0h, al
		NEWIODELAY
		in	al, 0a0h
		NEWIODELAY
		mov	ah, al

		mov	al, 0ah
		out	020h, al
		NEWIODELAY
		in	al, 20h
		NEWIODELAY

		and	al, not 05h
		test	[DEASSERT_STPCLK_IRQS], ax
		jnz	Wake_Up_By_IRQ

	;read RTC Sec/Min/Hr/Day/Mon/Yr into 
	;CL/CH/DL/DH/CL,CH respectively for later use

		mov	al, RTC_SECONDS
		call	Get_Rtc
		jc	short Wait_For_WakeUp_Source
		mov	cl, al

		mov	al, RTC_MINUTES
		call	Get_Rtc
		mov	ch, al
		jc	short Wait_For_WakeUp_Source

		mov	al, RTC_HOURS
		call	Get_Rtc
		jc	short Wait_For_WakeUp_Source
		mov	dl, al

		mov	al, DAY_OF_MONTH
		call	Get_Rtc
		jc	short Wait_For_WakeUp_Source
		mov	dh, al

		mov	al, MONTH
		call	Get_Rtc
		jc	short Wait_For_WakeUp_Source
		mov	bl, al

		mov	al, YEAR
		call	Get_Rtc
		jc	short Wait_For_WakeUp_Source
		mov	bh, al

	;----------- check if wake up by century ------------

		cmp	bh, 95h
		jae	short In_19xx
	In_20xx:
		cmp	[RESUME_CENTURY], 20h
		jne	short Wake_Up_By_Resume_Timer
		jmp	short Not_WakeUp_By_Century
	In_19xx:
		cmp	[RESUME_CENTURY], 20h
		je	short Wait_For_WakeUp_Source

	Not_WakeUp_By_Century:

	;now, century reach, check if wake up by year

		cmp	bh, [RESUME_YEAR]
		ja	short Wake_Up_By_Resume_Timer
		jb	short Wait_For_WakeUp_Source

	;now, century/year reach, check if wake up by month

		cmp	bl, [RESUME_MONTH]
		ja	short Wake_Up_By_Resume_Timer
ifndef	Chk_more_V_Alarm_wakeup_source				;R04
		jb	short Wait_For_WakeUp_Source
else	;Chk_more_V_Alarm_wakeup_source				;R04
		jb	Wait_For_WakeUp_Source			;R04
endif	;Chk_more_V_Alarm_wakeup_source				;R04

	;now, century/year/month reach, check if wake up by day

		cmp	dh, [RESUME_DAY]
		ja	short Wake_Up_By_Resume_Timer
		jb	Wait_For_WakeUp_Source

	;now, century/year/month/day reach, check if wake up by hour

		cmp	dl, [RESUME_HOUR]
		ja	short Wake_Up_By_Resume_Timer
		jb	Wait_For_WakeUp_Source

	;now, century/year/month/day/hour reach, check if wake up by minute

		cmp	ch, [RESUME_MINUTE]
		ja	short Wake_Up_By_Resume_Timer
		jb	Wait_For_WakeUp_Source

	;now, century/year/month/day/hour/minute reach, check if wake up by second

		cmp	cl, [RESUME_SECOND]
		ja	short Wake_Up_By_Resume_Timer
		jb	Wait_For_WakeUp_Source

	Wake_Up_By_Resume_Timer:

		and	[EXTEND_APM_STATUS], not RESUME_TIMER_ENABLED

	Wake_Up_By_IRQ:

		popa
		clc
		ret

Virtual_Resume_Timer	Endp

Get_Rtc		Proc	Near

;R01-starts
		mov	ah,al		;Save RTC Index
		call	Get_Rtc_	;Get RTC once Timer value
		xchg	ah,al		;Save to buffer AH, restore RTC Index

Get_Rtc_:
;R01-ends				;Get RTC twice Timer value to AL
ifndef	NO_CHECK_UPDATE_BIT
		push	cx
		push	ax
		xor	cx,cx
	@@:
		mov	al,0ah NMI_OFF
;R03Aifndef	V_ALARM_IN_E000			;R03
;R03A		call	Get_Cmos
;R03Aelse	;V_ALARM_IN_E000			;R03
;R03A		extrn	F000_Get_Cmos:near	;R03
;R03A		call	F000_Get_Cmos		;R03
;R03A - starts
		OUT	CMOS,AL
		jcxz	short $+2
		jcxz	short $+2
		ALIGN	4
		IN	AL,CMOS+1
		jcxz	short $+2
		jcxz	short $+2
;R03A - ends
;R03Aendif	;V_ALARM_IN_E000			;R03
		test	al,80h		;in update?
		jz	short @F
		loop	short @B
		pop	ax
		pop	cx
		stc
		ret
	@@:
		pop	ax
		pop	cx
endif	;NO_CHECK_UPDATE_BIT
			
;R03Aifndef	V_ALARM_IN_E000			;R03
;R03A		call	Get_Cmos
;R03Aelse	;V_ALARM_IN_E000			;R03
;R03A		extrn	F000_Get_Cmos:near	;R03
;R03A		call	F000_Get_Cmos		;R03
;R03A - starts
		OUT	CMOS,AL
		jcxz	short $+2
		jcxz	short $+2
		ALIGN	4
		IN	AL,CMOS+1
		jcxz	short $+2
		jcxz	short $+2
;R03A - ends
;R03Aendif	;V_ALARM_IN_E000			;R03
;R01-starts
		cmp	ah,al		;Compare Timer once and twicw value
		jz	short @f	;if AL = AH, jmp (set valid)
		stc			;set invalid
		ret
@@:
;R01-ends				;set vaild
		clc
		ret

Get_Rtc		Endp

