;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R18A	12/04/98 KGN	Add code to patch save SMI VGA VRAM will have garbage
;			in screen
;R19A	11/20/98 KGN	Change compile key for it
;R19	11/18/98 KGN	Add define for compile LCD_CRT_OPTION
;R18	06/22/98 JKY	Added SMI811_VGA support.
;R17	05/11/98 RAX	Modify VIDEO_BUFFER from 4K to 8K for some of new VGA
;			chip buffer use larger than 4K made restore V
;R16	03/23/98 RAX	Added ATI 3D Rage LP pro AGP SUPPORT.
;R15	11/14/97 DNL	Rename all VGA file as supervga.vga
;R14	11/13/97 JKY	Add routing in before into suspend zv . because some
;			VGA chip need turn-on on suspend-0v before .
;R13	11/11/97 JKY	Add Trident Cyber 9397 PCI VGA support
;R12	10/27/97 KGN	move defin LCD_CRT_OPTION to common.equ
;R11	10/13/97 JKY	Add S3 86C260 PCI VGA support
;R10 	07/08/97 KGN	Add CT65555 int15_5f func call for TV control set
;			CHIP_VGA = 3
;R09 	05/29/97 DNL	Added VESA VGA support
;R08	05/23/97 KGN	Add C&T65555 PCI VGA Support
;R02A	05/08/97 JKY	Add hook call for S3 86CM65
;R05A	05/07/97 DNL	Added code for more VGA chip support
;R07	03/31/97 KGN	Add ATI Mach64GT PCI VGA Support
;R06	03/21/97 KGN	Add Cirrus 5446 PCI VGA Support
;R05	03/20/97 RAX	Add code for VGA OEM BIOS when define "NEW_SUPERVGA_KERNEL"
;R04	03/11/97 KGN	Add Neomagic VGA Support
;R03	02/18/97 DNL	Fixed coding mistake
;R01A	01/29/97 DNL	Added VESA BIOS 1.X support
;R02	12/30/96 DNL	Added S3 86CM65 support
;R01	12/30/96 DNL	Added VESA BIOS 1.X support
;R00	11/01/96 DNL	Initial revision


.MODEL  SMALL,BASIC     

.386p
		PAGE	56,132
		TITLE	SUPERVGA.ASM
.XLIST
		INCLUDE	BIOS.CFG
		INCLUDE	COMMON.MAC
		INCLUDE POST.EQU
		INCLUDE	POST.MAC
		INCLUDE	COMMON.EQU		;R12

;R12ifdef	Notebook_Power_Management	
;R12	ifndef	NO_LCD_DISPLAY
;R12		LCD_CRT_OPTION		EQU	1
;R12	endif	;NO_LCD_DISPLAY
;R12endif	;Notebook_Power_Management	

ifdef	NEW_SUPERVGA_KERNEL
;---------------------------
; VGA chip type
;---------------------------
STANDARD_IBM_VGA	=	1
VESA_BIOS_VGA		=	0		;R01A
VGA_BIOS_HOOK		=	0		;R05A
VGA_ON_BEFORE_ZV_SUS 	=	0	;R14

;R01A  - start
ifdef	VESA_VGA
VESA_BIOS_VGA		=	1	
endif	;VESA_VGA
;R01A  - end
;-----------------------------------------------------------
; SMI Logic	VGA chip:SMI8XX
;-----------------------------------------------------------
SMI_VGA			=	0		;R18
ifdef	SMI811_VGA				;R18
SMI_VGA			=	1		;R18
STANDARD_IBM_VGA	=	0		;R18
VESA_BIOS_VGA		=	1
endif	;SMI811_VGA				;R18

;-----------------------------------------------------------
; Cirrus Logic	VGA chip:754X
;-----------------------------------------------------------
CIRRUS_VGA		=	0
ifdef	CL_GD754X
CIRRUS_VGA		=	1
STANDARD_IBM_VGA	=	0
endif	;CL_GD754X

;R06 - Start
ifdef	CL_GD5446
CIRRUS_VGA		=	1
STANDARD_IBM_VGA	=	0
VESA_BIOS_VGA		=	1
endif	;CL_GD5446
;R06 - End

;-----------------------------------------------------------
; Chips and Technologies	VGA chip: 65545,65548,65550,65555
;-----------------------------------------------------------
CHIP_VGA		=	0
ifdef	CHIP_655XX
CHIP_VGA		=	2
;R05A CHIP_Hook		=	1		;R05
VGA_BIOS_HOOK		=	1		;R05A
STANDARD_IBM_VGA	=	0
ifdef	CHIP_65548
CHIP_VGA		=	1
endif	;CHIP_65548
ifdef	CHIP_65555				;R08
CHIP_VGA		=	3		;R10
VGA_BIOS_HOOK		=	1		;R08
VESA_BIOS_VGA		=	1		;R08
endif	;CHIP_65555				;R08
endif	;CHIP_655XX

;-----------------------------------------------------------
; Trident   	VGA chip:968X,9385
;-----------------------------------------------------------
TRIDENT_VGA		=	0
ifdef	TC968X_VGA
TRIDENT_VGA		=	1
STANDARD_IBM_VGA	=	0
endif	;TC968X_VGA

ifdef	TRIDENT_9385
TRIDENT_VGA		=	1
;R05A TRIDENT_Hook		=	1		;R05
VGA_BIOS_HOOK		=	1		;R05A
STANDARD_IBM_VGA	=	0
endif	;TRIDENT_9385

;R13 - start
ifdef	TRIDENT_9397
TRIDENT_VGA		=	1
VGA_BIOS_HOOK		=	1
STANDARD_IBM_VGA	=	0
VGA_ON_BEFORE_ZV_SUS	=	1	;R14
endif	;TRIDENT_9397
;R13 - end
;-----------------------------------------------------------
; ATI 		VGA chip: match 64
;-----------------------------------------------------------
ATI_VGA			=	0
ifdef	ATI_MACH64VT	
ATI_VGA			=	1
STANDARD_IBM_VGA	=	0
endif	;ATI_MACH64VT	

;R07 - Start
ifdef	ATI_MACH64GT
ATI_VGA			=	1
STANDARD_IBM_VGA	=	0
VESA_BIOS_VGA		=	1
endif	;ATI_MACH64GT	
;R07 - End

;R16 start
ifdef	ATI_3DRAGE_PRO_AGP
ATI_VGA			=	1
STANDARD_IBM_VGA	=	0
VESA_BIOS_VGA		=	1
endif	;ATI_3DRAGE_PRO_AGP
;R16 end
;-----------------------------------------------------------
; SiS 		VGA chip:6205
;-----------------------------------------------------------
SIS_VGA			=	0
ifdef	SHARE_SiS6205
SIS_VGA			=	1
STANDARD_IBM_VGA	=	0
endif	;SHARE_SiS6205

;R02 - start
;-----------------------------------------------------------
; S3 		VGA chip:6205
;-----------------------------------------------------------
S3_VGA			=	0
ifdef	S3_86CM65
S3_VGA			=	1
STANDARD_IBM_VGA	=	0
VESA_BIOS_VGA		=	1			;R03
VGA_BIOS_HOOK		=	1		;R02A
endif	;S3_86CM65
;R02 - end

;R11 - start
ifdef	S3_86C260
S3_VGA			=	2
STANDARD_IBM_VGA	=	0
VESA_BIOS_VGA		=	1
VGA_BIOS_HOOK		=	1
endif	;S3_86C260
;R11 - end

;R04 - Start
;-----------------------------------------------------------
; NeoMagic 		VGA chip:NM2093AB
;-----------------------------------------------------------
NeoMagic		=	0
ifdef	NeoMagic_2093AB
NeoMagic		=	1
;R05A NeoMagic_Hook		=	1		;R05
VGA_BIOS_HOOK		=	1		;R05A
STANDARD_IBM_VGA	=	0
	ifdef	Notebook_Power_Management		;R05
VESA_BIOS_VGA		=	1
	endif	;Notebook_Power_Management		;R05
endif	;NeoMagic_2093AB
;R04 - End

	ifdef	Notebook_Power_Management		;R03
		extrn	VIDEO_FUNC:near
		extrn	Get_ZV_HDD_Loc:near
		extrn	HDD_Transfer:near
                extrn   Video_State:near		;R03
	endif	;Notebook_Power_Management		;R03
	ifdef	PM_Support				;R12
		extrn	F000_Open_PM_RAM:near
		extrn	F000_Close_PM_RAM:near
		extrn	F000_Get_PM_RAM_Seg:near
	endif	;PM_Support				;R12
		extrn	F000_GetItem_Value:near
                extrn   F000_call_proc:near
;R03		extrn   Video_State:near

	COMPILE_FOR_SUPERVGA_ASM	= 1

;R15	if	CIRRUS_VGA	NE	0
;R15		include	Cirrus.vga
;R15	endif	;CIRRUS_VGA
;R15		
;R15	if	CHIP_VGA	NE	0
;R15		include	Chip.vga
;R15	endif	;CHIP_VGA
;R15
;R15	if	TRIDENT_VGA	NE	0
;R15		include	Trident.vga
;R15	endif	;TRIDENT_VGA
;R15
;R15	if	ATI_VGA		NE	0
;R15		include	ATI.vga
;R15	endif	;ATI_VGA		
;R15
;R15	if	SIS_VGA		NE	0
;R15		include	SIS.vga
;R15	endif	;SIS_VGA
;R15
;R15	if	S3_VGA		NE	0		;R02
;R15		include	S3.vga				;R02
;R15	endif	;S3_VGA					;R02
;R15
;R15	if	NeoMagic	NE	0		;R04
;R15		include	neomagic.vga			;R04
;R15	endif	;NeoMagic				;R04
;R15 - start
		include	SUPERVGA.VGA
;R15 - end

endif	;NEW_SUPERVGA_KERNEL

G_RAM		SEGMENT	USE16 AT 0

		ORG	04H*4
		INCLUDE	SEG_0.INC

		ORG	400H
		INCLUDE	G_RAM.INC

G_RAM		ENDS

ifdef	Notebook_Power_Management
SM_RAM		SEGMENT	USE16 AT 0
		INCLUDE	SM_RAM.INC
SM_RAM		ENDS

ZV_Temp_Stack	SEGMENT	USE16 AT 0
		org	1000h
VIDEO_BUFFER	LABEL	WORD
		org	0FFF0h
ZV_STACK_TOP	LABEL	DWORD
ZV_Temp_Stack	ENDS
endif	;Notebook_Power_Management

PM_RAM		SEGMENT	USE16 AT 0 	; define PM RAM segment

		ORG	0
		INCLUDE	PM_RAM.INC

PM_RAM		ENDS

.LIST

DGROUP		GROUP	FCODE
FCODE		SEGMENT	PUBLIC 'CODE'
		ASSUME	CS:DGROUP
;R05 - start
ifdef	NEW_SUPERVGA_KERNEL
	COMPILE_FOR_SUPERVGA_ASM	= 2

;R15	if	CIRRUS_VGA	NE	0
;R15		include	Cirrus.vga
;R15	endif	;CIRRUS_VGA
;R15		
;R15	if	CHIP_VGA	NE	0
;R15		include	Chip.vga
;R15	endif	;CHIP_VGA
;R15
;R15	if	TRIDENT_VGA	NE	0
;R15		include	Trident.vga
;R15	endif	;TRIDENT_VGA
;R15
;R15	if	ATI_VGA		NE	0
;R15		include	ATI.vga
;R15	endif	;ATI_VGA		
;R15
;R15	if	SIS_VGA		NE	0
;R15		include	SIS.vga
;R15	endif	;SIS_VGA
;R15
;R15	if	S3_VGA		NE	0
;R15		include	S3.vga
;R15	endif	;S3_VGA
;R15
;R15	if	NeoMagic	NE	0
;R15		include	neomagic.vga
;R15	endif	;NeoMagic
;R15 - start
		include	SUPERVGA.VGA
;R15 - end

endif	;NEW_SUPERVGA_KERNEL
;R05 - end
FCODE		ENDS

EGROUP		GROUP	ECODE
ECODE		SEGMENT	PUBLIC 'ECODE'
		ASSUME	CS:EGROUP,DS:G_RAM,ES:EGROUP

ifdef	NEW_SUPERVGA_KERNEL
;R19Aif	Desktop_Power_Management	EQ	2	;R19
if	Compile_for_LCDCRTOption	NE	0	;R19A
;[]==================================================================[]
;
; Subroutine for read VGA register
;
; Entry:
;	AH = Index
;	DX = VGA port
;
; Exit:
;	AL = Read value 
;
;[]==================================================================[]
		public	Get_VGA_Reg	
Get_VGA_Reg	proc	near
		xchg	ah,al
		out	dx,al
		inc	dl
		xchg	ah,al
		in	al,dx
		dec	dl
		ret
Get_VGA_Reg	endp

;[]==================================================================[]
;
; Subroutine for write VGA register
;
; Entry:
;	AH = index
;	DX = VGA port
;
; Exit:
;
;[]==================================================================[]
		Public	Set_VGA_Reg	
Set_VGA_Reg	proc	near
		xchg	ah,al
		out	dx,al
		inc	dl
		xchg	ah,al
		out	dx,al
		dec	dl
		ret
Set_VGA_Reg	endp

;[]==================================================================[]
;[]==================================================================[]
		Public	Rep_Save_VGA
Rep_Save_VGA	proc	near

	@@:
		call	Get_VGA_Reg
		stos	byte ptr es:[edi]
		inc	ah
		loop	short @B

		ret
Rep_Save_VGA	endp

;[]==================================================================[]
;[]==================================================================[]
		Public	Rep_Restore_VGA
Rep_Restore_VGA	proc	near

	@@:
		lods	byte ptr ds:[esi]
		call	Set_VGA_Reg
		inc	ah
		loop	short @B

		ret
Rep_Restore_VGA	endp

;[]==================================================================[]
;[]==================================================================[]
		Public	Get_VGA_Att	
Get_VGA_Att	proc	near

		push	dx
		mov	dx,3C0h
		in	al,dx
		push	ax			; Save PAS status

		call	Reset_VGA_FF

		mov	al,ah
		out	dx,al
		inc	dl
		in	al,dx
		dec	dl
		mov	bl,al

		call	Reset_VGA_FF

		pop	ax			; Restore PAS status
		out	dx,al
		mov	al,bl
		pop	dx

		ret
Get_VGA_Att	endp

;[]==================================================================[]
;[]==================================================================[]
		Public	Set_VGA_Att
Set_VGA_Att	proc	near

		mov	dx,3C0h
		in	al,dx
		push	ax			; Save PAS status

		call	Reset_VGA_FF
		mov	ax,cx
		mov	dx,3C0h
		xchg	ah,al
		out	dx,al
		xchg	ah,al
		out	dx,al
		call	Reset_VGA_FF

		pop	ax
		out	dx,al			; Restore PAS status

		ret
Set_VGA_Att	endp

;[]==================================================================[]
;
; Routine for reset VGA attribute register access Flip/Flop
;
;[]==================================================================[]
		Public	Reset_VGA_FF
Reset_VGA_FF	proc	near
		push	ax
		push	dx
		mov	dx,3BAh
		in	al,dx
		mov	dl,0DAh
		in	al,dx
		pop	dx
		pop	ax
		ret
Reset_VGA_FF	endp

;[]==================================================================[]
;
; Routine for get CRTC register address 3D4H or 3B4H
;
;[]==================================================================[]
		Public	Get_CRTC_Addr
Get_CRTC_Addr	proc	near
		push	ax
		mov	dx,3cch
		in	al,dx
		mov	dx,3d4h
		test	al,1
		jnz	short @F
		mov	dx,3b4h
	@@:
		pop	ax
		ret
Get_CRTC_Addr	endp

;[]==================================================================[]
;
; Routine to wait for CRT vertical retrace
;
;[]==================================================================[]
		Public	Wait_VRetrace
Wait_VRetrace	proc    near

		push	cx
		push    dx
		call	Get_CRTC_Addr
		add     dx,06h
		xor	cx,cx
	@@:
		in      al,dx
		test    al,08h
		jz	short @F
		loop	short @B
	@@:
		xor	cx,cx
	@@:
		in      al,dx
		test    al,08h
		jnz	short @F
		loop	short @B
	@@:
		pop     dx
		pop	cx

		ret

Wait_VRetrace	endp
endif	;Desktop_Power_Management	EQ	2	;R19

	COMPILE_FOR_SUPERVGA_ASM	= 3

if	STANDARD_IBM_VGA	NE	0
;R19Aif	Desktop_Power_Management	EQ	2	;R19
if	Compile_for_LCDCRTOption	NE	0	;R19A
;[]===============================================================[]
;
; Suspend_VGA:
;
;	Subroutine for save VGA status .
;
; Entry:
;
;	ES = Segment for save buffer.
;
; Exit:
;
; Note:
;	The following is standard VGA status save offset in buffer.
;
;		00H	    : sequencr index
;		01H,02H	    : CRTC address
;		03H	    : CRTC index
;		04H	    : graphic index
;		05H	    : attributes index
;		06H	    : Feature control
;		07H - 0AH   : sequencr reg 1 - 4
;		0BH	    : VGA Misc. Register
;		0CH - 24H   : CRTC 0 - 18h
;		25H - 38H   : attribute  0 - 13h
;		39H - 41H   : VGA graphic control register 0 - 8
;		42H	    : VGA DAC register R/W status
;		43H	    : VGA pel address
;		44H	    : VGA pel mask
;		45H	    : VGA (Attribute index 14h) color select register
;		46H - 0146H : VGA DAC register
;
;[]==================================================================[]
		Public	Suspend_VGA
Suspend_VGA	PROC	NEAR

;
; Save standard VGA registers
;
		push	ebx			
		mov	edi,ebx			
		add	edi,offset VGA_State_Save

		mov	dx,3C4h			; VGA sequencr index
		in	al,dx			
		stos	byte ptr es:[edi]	;[00]: sequencr index

		call	Get_CRTC_Addr		; VGA CRTC index
		mov	ax,dx
		stos	word ptr es:[edi]	;[01,02]: CRTC address

		in	al,dx			
		stos	byte ptr es:[edi]	;[03]: CRTC index

		mov	dx,3CEh			; VGA graphic index
		in	al,dx
		stos	byte ptr es:[edi]	;[04]: graphic index

		mov	dx,3C0h			; VGA attributes index
		in	al,dx
		stos	byte ptr es:[edi]	;[05]: attributes index

		mov	dx,3CAh			; Feature control read register
		in	al,dx
		stos	byte ptr es:[edi]	;[06]: Feature control

		mov	cx,4
		mov	ah,1
		mov	dx,3C4h
		call	Rep_Save_VGA		;[07 - 0A]: sequencr reg 1 - 4

		mov	dx,3CCh			; VGA Misc. Register read
		in	al,dx
		stos	byte ptr es:[edi]	;[0B]: VGA Misc. Register

		mov	cx,19h
		xor	ah,ah
		call	Get_CRTC_Addr
		call	Rep_Save_VGA		;[0C - 24]: CRTC 0 - 18h

		mov	cx,14h
		xor	ah,ah
	@@:
		call	Get_VGA_Att
		stos	byte ptr es:[edi]	;[25 - 38]: attribute  0 - 13h
		inc	ah
		loop	short @B

		mov	cx,9
		xor	ah,ah
		mov	dx,3CEh
		call	Rep_Save_VGA		;[39 - 41]: VGA graphic 0 - 8

		mov	dx,3C7h
		in	al,dx			; VGA DAC state reg
		inc	dx
		and	al,1
		stos	byte ptr es:[edi]	;[42]: VGA DAC reg R/W status
		in	al,dx			; VGA pel address
		jz	short @F
		dec	al
	@@:
		stos	byte ptr es:[edi]	;[43]: VGA pel address

		mov	dl,0C6h
		in	al,dx
		stos	byte ptr es:[edi]	;[44]: VGA pel mask

		mov	ah,14h
		call	Get_VGA_Att
		stos	byte ptr es:[edi]	;[45]: VGA Att 14 color select

		call	Wait_VRetrace
		mov	cx,100h
		xor	al,al
		mov	dx,3C7h
		out	dx,al			; VGA pel address
		inc	dx
		inc	dx
	@@:
		in	al,dx
		stos	byte ptr es:[edi]
		in	al,dx
		stos	byte ptr es:[edi]
		in	al,dx
		stos	byte ptr es:[edi]
		loop	short @B		;[46 - 146] VGA DAC register

		pop	ebx			

		ret

Suspend_VGA	ENDP

;[]===============================================================[]
;
; Resume_VGA:
;
;	Subroutine for restore VGA status .
;
; Entry:
;
;	ES = Segment of VGA state save buffer.
;
; Exit:
;
; Note:
;	The following is standard VGA status save offset in buffer.
;
;		00H	    : sequencr index
;		01H,02H	    : CRTC address
;		03H	    : CRTC index
;		04H	    : graphic index
;		05H	    : attributes index
;		06H	    : Feature control
;		07H - 0AH   : sequencr reg 1 - 4
;		0BH	    : VGA Misc. Register
;		0CH - 24H   : CRTC 0 - 18h
;		25H - 38H   : attribute  0 - 13h
;		39H - 41H   : VGA graphic control register 0 - 8
;		42H	    : VGA DAC register R/W status
;		43H	    : VGA pel address
;		44H	    : VGA pel mask
;		45H	    : VGA (Attribute index 14h) color select register
;		46H - 0146H : VGA DAC register
;
;[]==================================================================[]
		Public	Resume_VGA
Resume_VGA	PROC	NEAR

		push	ds

		push	es
		pop	ds

		mov	esi,ebx
		add	esi,offset VGA_State_Save

;
; Restore standard VGA register
;
		mov	dx,3C4h
		mov	esi,ebx
		add	esi,offset TSR_Save
		mov	cx,4
		mov	ah,1
		call	Rep_Restore_VGA		; Restore Sequencer Register

		mov	dx,3C2h
		mov	al,es:[ebx+VGA_Misc_Save]
		out	dx,al			; 3C2h, VGA misc out reg

		mov	dx,es:[ebx+CRTC_Address_Save]
		mov	ax,1100h		; Disable CRTC 0-7 lock
		call	Set_VGA_Reg

		mov	esi,ebx
		add	esi,offset CRTC_Save
		mov	cx,19h
		xor	ah,ah
		call	Rep_Restore_VGA		; Restore CRTC registers 0 - 18h

		mov	dx,3CEh
		mov	esi,ebx
		add	esi,offset GDC_Save
		mov	cx,9
		xor	ah,ah
		call	Rep_Restore_VGA		; Restore GDC 0 - 8

		mov	esi,ebx
		add	esi,offset ATC_Save
		xor	ah,ah
		mov	cx,14h
		call	Reset_VGA_FF
		mov	dx,3C0h
	@@:
		mov	al,ah
		out	dx,al
		lods	byte ptr ds:[esi]
		out	dx,al			; Restore ATC 0 - 13h
		inc	ah
		loop	short @B

		mov	dx,es:[ebx+CRTC_Address_Save]
		add	dl,6
		mov	al,es:[ebx+Feature_Control_Save]
		out	dx,al			; Restore Feature control
		push	dx

		mov	dx,3C4h
		mov	al,es:[ebx+TSR_Index_Save]
		out	dx,al			; Restore TSR index

		mov	dx,es:[ebx+CRTC_Address_Save]
		mov	al,es:[ebx+CRTC_Index_Save]
		out	dx,al			; Restore CRTC index

		mov	dx,3CEh
		mov	al,es:[ebx+GDC_Index_Save]
		out	dx,al			; Restore GDC index

		pop	dx
		in	al,dx
		mov	dx,3C0h
		mov	al,es:[ebx+ATC_Index_Save]
		out	dx,al			; Restore ATC index

		mov	ch,14h
		mov	cl,es:[ebx+Color_Select_Save]
		call	Set_VGA_Att		; Restore color select

		mov	al,es:[ebx+PEL_Mask_Save]
		mov	dx,03C6h
		out	dx,al			; Restore PEL Mask

		call	Wait_VRetrace
		mov	esi,ebx
		add	esi,offset DAC_Save
		mov	dx,3C8h
		xor	al,al
		out	dx,al			; port 3C8h, VGA pel address
		inc	dx
		mov	cx,100h
	@@:
		lods	byte ptr ds:[esi]	
		out	dx,al			; Restore DAC
		lods	byte ptr ds:[esi]	
		out	dx,al			; Restore DAC
		lods	byte ptr ds:[esi]
		out	dx,al			; Restore DAC
		loop	short @B

		mov	dx,3C7h
		mov	al,es:[ebx+DAC_State_Save]
		test	al,1
		mov	al,es:[ebx+PEL_Address_Save]
		jnz	short @F
		inc	dx
	@@:
		out	dx,al			; Restore PEL R/W State

		pop	ds
		ret

Resume_VGA	ENDP

;[]========================================================================[]
;Procedure:	Save_VRAM
;
;Function :	Save Video RAM for Zero-Volt-Suspend.
;
;Input	  :	None
;
;Output   :	None
;
;Preserve :	ES,DS
;
;Note	  :	1. Called by Suspend_0V
;		2. The stack is in segment 0000h
;		3. Save location = start location + 1056KB
;[]========================================================================[]
		Public	Save_VRAM	
Save_VRAM	PROC	NEAR

;R01A - start
if	VESA_BIOS_VGA		NE	0
		Call	VESA_SAVE_VRAM
else	;VESA_BIOS_VGA		NE	0
;R01A - end
		push	ebx			
		push	ds		  

	; Disable CRT display

		call	Reset_VGA_FF
		mov     dx,03c0h
		xor	al,al
		out     dx,al

;
; Save Video RAM
;
		mov     dx,03c4h
		mov     ax,0406h	; Enable chain four mode
		call	Set_VGA_Reg

		mov     dx,03ceh
		mov     ax,0500h
		call	Set_VGA_Reg
		mov     ax,0601h        ; memory mapping select to a000h,128k.
		call	Set_VGA_Reg

		push	es

		mov     dx,03ceh
		mov	ax,0400h		; Set plane 0
		call	Set_VGA_Reg

		call	Get_ZV_HDD_Loc
		add	ebx,ZV_HDD_VRAM_Sector
	@@:
		mov	ax,0A000h		
		mov	ds,ax			
		xor	esi,esi			
		mov	ah,30h			; Write command
		mov	al,(64*1024)/512	; Sector Count
		call	HDD_Transfer
		mov	ax,0B000h		
		mov	ds,ax			
		xor	esi,esi			
		add	ebx,(64*1024)/512	
		mov	ah,30h			; Write command
		mov	al,(64*1024)/512	; Sector Count
		call	HDD_Transfer		

		mov     dx,03ceh
		mov	ah,04h
		call	Get_VGA_Reg
		and	al,3
		cmp	al,3			; Is plane 3 ?
		jae	short @F
		inc	al			; Next plane ..
		call	Set_VGA_Reg
		add	ebx,(64*1024)/512	; Next start sector ..
		jmp	short @B
	@@:

		pop	es
Save_VRAM_ok:
		pop	ds
		pop	ebx			
endif	;VESA_BIOS_VGA		NE	0		;R01A

		ret
Save_VRAM	ENDP

;[]========================================================================[]
;Procedure:	Restore_VRAM
;
;Function :	Restore Video RAM for resume from Zero-Volt-Suspend.
;
;Input	  :	None
;
;Output   :	None
;
;Preserve :	ES,DS
;
;Note	  :	1. Called by Resume_0V
;		2. The stack is in segment 0000h
;		3. Save location = start location + 1088KB
;[]========================================================================[]
		public	Restore_VRAM
Restore_VRAM	PROC	NEAR

;R01A - start
if	VESA_BIOS_VGA		NE	0
		Call	VESA_RESTORE_VRAM
else	;VESA_BIOS_VGA		NE	0
;R01A - end

		push	ebx			
		push	ds			

	; Disable CRT display

		call	Reset_VGA_FF
		mov     dx,03c0h
		xor	al,al
		out     dx,al
		
;
; Restore Video RAM
;
		mov     dx,03c4h
		mov     ax,0406h		; Enable chain four mode
		call	Set_VGA_Reg

		mov     dx,03ceh
		mov     ax,0500h
		call	Set_VGA_Reg

		mov     ax,0601h        	; memory mapping select to a000h,128k.
		call	Set_VGA_Reg

		push	es

		mov     dx,03c4h
		mov     ax,0201h		; Start plane 0
		call	Set_VGA_Reg

		call	Get_ZV_HDD_Loc		; Start sector
		add	ebx,ZV_HDD_VRAM_Sector
	@@:
		xor	edi,edi			
		mov	ax,0A000h		
		mov	es,ax			
		mov	ah,20h			; Read command
		mov	al,(64*1024)/512	; Sector Count
		call	HDD_Transfer
		mov	ax,0B000h		
		mov	es,ax			
		xor	edi,edi			
		add	ebx,(64*1024)/512	; Next start sector ..
		mov	ah,20h			; Read command
		mov	al,(64*1024)/512	; Sector Count
		call	HDD_Transfer		

		mov     dx,03c4h
		mov	ah,02h
		call	Get_VGA_Reg
		and	al,0fh
		cmp	al,8			; Is plane 3 ?
		je	short @F
		shl	al,1			; Next plane ..
		call	Set_VGA_Reg
		add	ebx,(64*1024)/512	; Next start sector ..
		jmp	short @B
	@@:

		pop	es
Restore_VRAM_ok:					
		pop	ds
		pop	ebx				
endif	;VESA_BIOS_VGA		NE	0		;R01A

		ret
Restore_VRAM	ENDP
endif	;Desktop_Power_Management	EQ	2	;R19

;R09 - start
		Public	Alternate_INT10_for_SMI
Alternate_INT10_for_SMI	Proc	Near
		ret
Alternate_INT10_for_SMI	Endp
;R09 - end

endif	;STANDARD_IBM_VGA

;R01 - start
if	VESA_BIOS_VGA		EQ	1		;R03
;R19Aif	Desktop_Power_Management	EQ	2	;R19
if	Compile_for_LCDCRTOption	NE	0	;R19A
;[]==================================================================[]
;
; Procedure Name: VESA_SAVE_VRAM
;
;	This routine use VESA BIOS function call to save Video RAM
;
; Saves: All
; Input: 
;	none
;
; Output: 
;	none
;
; [Note]:
;	1. This routine is VESA BIOS dependent.
;
; Author: Daniel Huang
; Date: December, 30, 1996
;
; Name	| Date		| Description
; -----------------------------------------------------------------
; DNL	| 12/30/96	| Initial version for VESA BIOS 1.X
;[]==================================================================[]
		Public	VESA_Save_VRAM
VESA_Save_VRAM	Proc	near

		push	ds
		push	es
		push	ebx

 ;-----------------------------------------------------------------------
 ;
 ; save the state of the video subsystem
 ;                    
 ;-----------------------------------------------------------------------
 
 		mov	al,01h
		Call	video_state
 
 		call	Get_ZV_HDD_Loc
 		add	ebx,ZV_HDD_VBUFFER_Sector
 
 		mov	ax,ZV_Temp_Stack
 		mov	ds,ax
 		mov	esi,offset VIDEO_BUFFER
 
 		mov	ah,30h
;R18 		mov	al,(4*1024)/512
 		mov	al,(8*1024)/512			;R18
 		Call	HDD_Transfer

 ;-----------------------------------------------------------------------
 ;
 ; save the video RAM use VESA function call
 ;                    
 ;-----------------------------------------------------------------------

	;;;; Step 1 :  set mode 101h

		mov	ax,4F02h
		mov	bx,8101h		;Set Mode 101h
		Call	F000_Video_Func

	;;;; Step 2 : Disable display output 

                call    Reset_VGA_FF
                mov     dx,03c0h
                xor     al,al
                out     dx,al

	;;;; Step 3 : Get mode 101h information

                mov     ax,ZV_Temp_Stack
                mov     es,ax
                mov     di,offset VIDEO_BUFFER + 100h
                mov     ax,4F01h
		mov	cx,101h
		Call	F000_Video_Func

	;;;; Step 4 : Get VRAM size

                mov     di,offset VIDEO_BUFFER
                mov     ax,4F00h
		Call	F000_Video_Func

                mov     ax,es:[di+12h]

	;;;; Step 5 : Get windows segment

		mov	dx,es:[di+108h]
		xor	bx,bx
		test	byte ptr es:[di+102h],2
		jnz	short @F

		mov	bl,01h
		mov	dx,es:[di+10Ah]
	@@:
		mov	ds,dx
		push	bx

	;;;; Step 6 : Calculate the number of pages

		shl	ax,6
		mov	cx,es:[di+106h]
		xor	dx,dx
		div	cx
		push	ax
		
	;;;; Step 7 : Calculate the number of Granularity units per page

		mov	ax,es:[di+106h]
		mov	cx,es:[di+104h]
		xor	dx,dx
		div	cx

		mov	di,ax
		pop	cx

	;;;; Step 8 : Save VRAM

                call    Get_ZV_HDD_Loc
                add     ebx,ZV_HDD_VRAM_Sector

		xor	dx,dx
		pop	ax
Vesa_Save_RAM:
;R18A - Start
if	SMI_VGA		EQ	1
		pushad
		mov	dx, 3c4h
		mov	al, 1
		out	dx, al
		inc	dx
		in	al, dx
		or	al, 20h
		xchg	ah, al
		dec	dx
		mov	al, 1
		out	dx, ax
		popad
endif	;SMI_VGA		EQ	1
;R18A - End
		push	ax
		push	dx
		push	di
		push	ebx
		push	ds

		mov	bx,ax
		mov	ax,4F05h
		Call	F000_Video_Func

		pop	ds
		pop	ebx
                mov     ah,30h                  ;Write Command
                mov     al,(64*1024)/512
                xor     esi,esi
                Call    HDD_Transfer
                add     ebx,(64*1024)/512

		pop	di
		pop	dx
		add	dx,di
		pop	ax
                loop    Vesa_Save_RAM

		pop	ebx
		pop	es
		pop	ds

		clc				
		ret				
VESA_Save_VRAM	endp

;[]==================================================================[]
;
; Procedure Name: VESA_RESTORE_VRAM
;
;	This routine use VESA BIOS function call to restore Video RAM
;
; Saves: All
; Input: 
;	none
;
; Output: 
;	none
;
; [Note]:
;	1. This routine is VESA BIOS dependent.
;
; Author: Daniel Huang
; Date: December, 30, 1996
;
; Name	| Date		| Description
; -----------------------------------------------------------------
; DNL	| 12/30/96	| Initial version for VESA BIOS 1.X
;[]==================================================================[]
		Public	VESA_Restore_VRAM	
VESA_Restore_VRAM	Proc	near

		push	ds
		push	es
		push	ebx

 ;-----------------------------------------------------------------------
 ;
 ; restore the video RAM use VESA function call
 ;                    
 ;-----------------------------------------------------------------------

	;;;; Step 1 :  set mode 101h

		mov	ax,4F02h
		mov	bx,0101h		;Set Mode 101h
		Call	F000_Video_Func

	;;;; Step 2 : Disable display output 

                call    Reset_VGA_FF
                mov     dx,03c0h
                xor     al,al
                out     dx,al

	;;;; Step 3 : Get mode 101h information

                mov     ax,ZV_Temp_Stack
                mov     es,ax
                mov     di,offset VIDEO_BUFFER + 100h
                mov     ax,4F01h
		mov	cx,101h
		Call	F000_Video_Func

	;;;; Step 4 : Get VRAM size

                mov     di,offset VIDEO_BUFFER
                mov     ax,4F00h
		Call	F000_Video_Func

                mov     ax,es:[di+12h]

	;;;; Step 5 : Get windows segment

		mov	dx,es:[di+108h]
		xor	bx,bx
		test	byte ptr es:[di+102h],4
		jnz	short @F

		mov	bl,01h
		mov	dx,es:[di+10Ah]
	@@:
		mov	ds,dx
		push	bx

	;;;; Step 6 : Calculate the number of pages

		shl	ax,6
		mov	cx,es:[di+106h]
		xor	dx,dx
		div	cx
		push	ax
		
	;;;; Step 7 : Calculate the number of Granularity units per page

		mov	ax,es:[di+106h]
		mov	cx,es:[di+104h]
		xor	dx,dx
		div	cx

		mov	di,ax
		pop	cx

	;;;; Step 8 : Save VRAM

                call    Get_ZV_HDD_Loc
                add     ebx,ZV_HDD_VRAM_Sector

		xor	dx,dx
		push	ds
		pop	es
		pop	ax
VEsa_Restore_RAM:
;R18A - Start
if	SMI_VGA		EQ	1
		pushad
		mov	dx, 3c4h
		mov	al, 1
		out	dx, al
		inc	dx
		in	al, dx
		or	al, 20h
		xchg	ah, al
		dec	dx
		mov	al, 1
		out	dx, ax
		popad
endif	;SMI_VGA		EQ	1
;R18A - End
		push	ax
		push	dx
		push	di
		push	ebx
		push	es

		mov	bx,ax
		mov	ax,4F05h
		Call	F000_Video_Func

		pop	es
		pop	ebx
                mov     ah,20h                  ;Read Command
                mov     al,(64*1024)/512
                xor     edi,edi
                Call    HDD_Transfer
                add     ebx,(64*1024)/512

		pop	di
		pop	dx
		add	dx,di
		pop	ax
                loop    Vesa_Restore_RAM

;-----------------------------------------------------------------------
;
; restore the state of the video subsystem
;                    
;-----------------------------------------------------------------------

		call	Get_ZV_HDD_Loc
		add	ebx,ZV_HDD_VBUFFER_Sector

		mov	ax,ZV_Temp_Stack
		mov	es,ax
		mov	edi,offset VIDEO_BUFFER

		mov	ah,20h
;R17		mov	al,(4*1024)/512
		mov	al,(8*1024)/512			;R17
		Call	HDD_Transfer

		mov	al,02h
		Call	video_state

		pop	ebx
		pop	es
		pop	ds

		clc				
		ret				
VESA_Restore_VRAM	endp

F000_Video_Func:
		F000_Call	Video_Func
		ret
endif	;Desktop_Power_Management	EQ	2	;R19
endif	;VESA_BIOS_VGA		EQ	1		;R03
;R01 - end

;R15	if	CIRRUS_VGA	NE	0
;R15		include	Cirrus.vga
;R15	endif	;CIRRUS_VGA
;R15		
;R15	if	CHIP_VGA	NE	0
;R15		include	Chip.vga
;R15	endif	;CHIP_VGA
;R15
;R15	if	TRIDENT_VGA	NE	0
;R15		include	Trident.vga
;R15	endif	;TRIDENT_VGA
;R15
;R15	if	ATI_VGA		NE	0
;R15		include	ATI.vga
;R15	endif	;ATI_VGA		
;R15
;R15	if	SIS_VGA		NE	0
;R15		include	SIS.vga
;R15	endif	;SIS_VGA
;R15
;R15	if	S3_VGA		NE	0		;R02
;R15		include	S3.vga				;R02
;R15	endif	;S3_VGA					;R02
;R15
;R15	if	NeoMagic	NE	0		;R04
;R15		include	neomagic.vga			;R04
;R15	endif	;NeoMagic				;R04
;R15 - start
		include	SUPERVGA.VGA
;R15 - end

;R14 - start
		public	VGA_ON_BEFORE_SAVE
VGA_ON_BEFORE_SAVE	Proc	near
if	VGA_ON_BEFORE_ZV_SUS	NE	0
		F000_Call	Enable_CRT
endif	;VGA_ON_BEFORE_ZV_SUS
 		ret
VGA_ON_BEFORE_SAVE	Endp
;R14 - end

endif	;NEW_SUPERVGA_KERNEL

ECODE		ENDS
		END
