;	[]===========================================================[]
;
;	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
;----------------------------------------------------------------------------
;R14	01/25/99 PHI	Add Public routines:	
;			  fProc_Disp_Word_Int4 - far procedure
;			  fProc_Disp_Byte_HEX2 - far procedure
;R13	09/29/98 RAY	Mask out some unused externals.
;R12A	09/11/98 MIL	Remove R12 code. Because it just a partial solution.
;R12	09/10/98 MIL	Fixed Show incorrect value at (STANDARD CMOS SETUP)
;			Other Memory Item, because Cyrix MediaGxi project
;			use 128k as a base memory unit.
;R11	05/20/97 RCH	Modify codes to display memory size up to 1GB
;R10	12/07/96 RAY	Add Public routines:
;			  fProc_Disp_Byte_Int2 - far procedure
;			  fProc_Disp_Word_Int3 - far procedure
;			  Disp_Word_Int3       - near procedure
;R09	04/19/96 HTR	Disp_Byte_Int2 routine added
;R08	10/06/94 KVN	Modify screen windows for support 4 ide
;R07	09/14/94 RAY	Fix bug of enabling cursor of monochrom display
;R06	12/01/93 DNL	SETUP utility under DOS prompt, Memory size error

;+---------------------------------------+
;+  USERINT - Common user interface rtns +
;+      Third revision 05-Apr-90	 +
;+				 	 +
;+---------------------------------------+

.386P

.XLIST
		INCLUDE	BIOS.CFG

		INCLUDE	COMMON.MAC
		INCLUDE	POST.MAC

		INCLUDE	POST.EQU

		extrn	Display_String:near
		extrn	Display_Char:near
		extrn	Vreverse:near

		extrn	COLOR_SETTING:byte
		extrn	POST_COLOR:byte
		extrn	Get_Color_Off:near
		extrn	hddc_item:near
		extrn	hddd_item:near
;R13		extrn	ReShow_HDD:near
		extrn	POST_func_end:Near	;128k
		extrn	POST_VECT:Near		;128k
.LIST

;
;  Equates for locations on stack where to store important variables...
;
;  These variables should never be accessed from outside the user-interface
;  module. The space should be reserved on the stack before USER_BEGIN is
;  called.

;
;  Display information. These contain the normal, hilighted and reversed
;attributes for both monochrome and color monitors.
;


;
;   Here begins the actual code. Routines are listed in alphabetical order.
;


FCODE		SEGMENT	DWORD USE16 Public 'CODE'
		ASSUME CS:FCODE

;[]==============================================================[]
;
;  BCD_TO_BINARY:
;
;	Convert BCD to binary.
;
;Saves:	NONE
;
;Entry:	AL 	= BCD value
; Exit:	AL 	= Binary converted
;
;[]==============================================================[]

 		Public	BCD_TO_BINARY
BCD_TO_BINARY	PROC	NEAR
		push	cx
		push	bx
		push	ax				; R13
		xor	ah,ah				; R13

		ror	ax,4				; ax = l00h
		shr	ah,4				; ax = 0l0h
		mov	bh,ah				; bh = 0l
		mov	bl,10
		mul	bl				; al = 10 * h
		add	al,bh				; al = 10 * h + l

		pop	bx				; R13
		mov	ah,bh				; R13
		pop	bx
		pop	cx
		ret
BCD_TO_BINARY	ENDP


DISP_VAL	PROC	NEAR

;R09 - Start
;[]==============================================================[]
;
;	Display a 2 character word unsigned integer
;
;ENTRY:		AL	Value to display
;EXIT:		NONE
;
;DESTROYS:	AX,CX,DX,SI
;SAVES:		DI
;[]==============================================================[]
;R10 - starts
		Public	fProc_Disp_Byte_Int2
fProc_Disp_Byte_Int2	Proc	Far
		call	Disp_Byte_Int2
		retf
fProc_Disp_Byte_Int2	Endp
;R10 - ends
		Public	DISP_Byte_INT2
DISP_Byte_INT2	LABEL	NEAR

		push	di
		extrn	AX_To_DEC2:near
		xor	ah, ah
		mov	di,offset AX_To_DEC2
		jmp	Show_Dig

;R09 - End
;[]==============================================================[]
;
;	Display a 4 character byte unsigned integer
;
;ENTRY:		AL	Value to display
;EXIT:		NONE
;
;DESTROYS:	AX,CX,DX,SI
;SAVES:		DI
;[]==============================================================[]
		Public	DISP_BYTE_INT4
DISP_BYTE_INT4	LABEL	NEAR

		xor	ah,ah

;	***FALL THROUGH TO NEXT ROUTINE***

;R10 - starts
;[]==============================================================[]
;
;	Display a 3 character word unsigned integer
;
;ENTRY:		AX	Value to display
;EXIT:		NONE
;
;DESTROYS:	AX,CX,DX,SI
;SAVES:		DI
;[]==============================================================[]
		Public	fProc_Disp_Word_Int3
fProc_Disp_Word_Int3	Proc	Far
		call	Disp_Word_Int3
		retf
fProc_Disp_Word_Int3	Endp
		Public	DISP_WORD_INT3
DISP_WORD_INT3	LABEL	NEAR

		push	di
		extrn	AX_To_DEC3:near
		mov	di,offset AX_To_DEC3
		jmp	Show_Dig
;R10 - ends

;[]==============================================================[]
;
;	Display a 4 character word unsigned integer
;
;ENTRY:		AX	Value to display
;EXIT:		NONE
;
;DESTROYS:	AX,CX,DX,SI
;SAVES:		DI
;[]==============================================================[]
;R14 - start
		Public	fProc_Disp_Word_Int4
fProc_Disp_Word_Int4	Proc	Far
		call	Disp_Word_Int4
		retf
fProc_Disp_Word_Int4	Endp
;R14 - end

		Public	DISP_WORD_INT4
DISP_WORD_INT4	LABEL	NEAR

		push	di
		extrn	AX_To_DEC4:near
		mov	di,offset AX_To_DEC4
		jmp	Show_Dig

;[]==============================================================[]
;
;	Display a 5 character word unsigned integer
;
;ENTRY:		AX	Value to display
;EXIT:		NONE
;
;DESTROYS:	AX,CX,DX,SI
;SAVES:		BX,DI
;[]==============================================================[]
		Public	DISP_WORD_INT5
DISP_WORD_INT5	LABEL	NEAR

		push	di
		extrn	AX_To_DEC5:near
		mov	di,offset AX_To_DEC5
Show_Dig:
		call	di
		extrn	Show_SIX_DIGIT:near
		call	Show_SIX_DIGIT
		pop	di
		ret

;[]========================================================================[]
;Function :	Read memory information...
;
;Input	:	CL = 0 Read Total Memory
;		CL = 1 Read Base Memory
;		CL = 2 Read Extended Memory
;		CL = 3 Read Expanded Memory
;		CL = 4 Read Other Memory
;
;Output	:	EAX = Memory Size
;
;Registers :	FLAG, AX   - Destroyed
;		Others	   - Preserved
;[]========================================================================[]
		Public	Read_Memory
Read_Memory	PROC	NEAR
rm_1:					;cl=0 --> Total memory
		or	cl,cl
		jnz	short rm_10

		mov	eax,EXT_MEM_SIZE[bp]	;Extend memory
		add	ax,CMOS15[bp]	;BASE_MEMORY[bp]

		cmp	byte ptr CALLTYPE[bp],post_call	;R06
		je	short rm_100			;R06

		xor	eax,eax				;R06
		mov	ax,EXT_MEM_FOUND[bp]		;R06
		add	ax,CMOS15[bp]			;R06
rm_100:
		push	edx
		mov	edx,eax
Sub_512k:
		sub	eax,512
		jz	short Right_Size
		jnc	short Sub_512k

;R12A ifndef	VSA_VGA                                 ;R12
		neg	eax			;get 2's complement
		add	edx,eax
;R12Aendif	;VSA_VGA                                ;R12

Right_Size:

;R12Aifdef	VSA_VGA					;R12
;R12A		add	edx,384                         ;R12
;R12Aendif	;VSA_VGA                                ;R12

		mov	eax,edx
		cmp	eax,15872
		jne	short @F
		add	eax,512
@@:
		pop	edx
		jmp	short rm_8
;----------------------------------------------------------------
rm_10:	;cl=1 --> BASE memory
		loop	rm_11				; if cl != 1, branch...
		xor	eax,eax
		mov	ax,CMOS15[bp]	;BASE_MEMORY[bp]
		jmp	short rm_8

;----------------------------------------------------------------
rm_11:	;cl=2 --> EXT memory
		loop	rm_12				; if cl != 2, branch
		mov	eax,EXT_MEM_SIZE[bp]		; extended memory
		cmp	byte ptr CALLTYPE[bp],post_call		;R06
		je	short @F				;R06
		xor	eax,eax					;R06
		mov	ax,EXT_MEM_FOUND[bp]	;Extend memory	;R06
@@:								;R06
		jmp	short rm_8

;----------------------------------------------------------------
rm_12:	;cl=3 --> EMS memory
		loop	rm_13				; if cl != 3, branch
		xor	eax,eax				; set total to 0
		jmp	short rm_8			; then use previous method of computing...

;----------------------------------------------------------------
rm_13:	;cl=4 --> Other memory
      		loop	rm_9				; if cl > 4, error
Right_Size1:
		push	edx

		mov	cl,3			;get EMS memory
		call	Read_Memory

		push	eax
		xor	cl,cl			;get total memory
		call	Read_Memory
		pop	edx

		sub	eax,edx			;ax = Total - EMS
		xor	edx,edx
		mov	dx,CMOS15[bp]
		sub	eax,edx
		cmp	byte ptr CALLTYPE[bp],post_call	;R06
		jne	short @F			;R06
		sub	eax,EXT_MEM_SIZE[bp]	;ax = Total - EMS - Base - EXT
		jmp	short Sub_ok			;R06
@@:							;R06
		xor	dx,dx				;R06
		mov	dx,EXT_MEM_FOUND[bp]		;R06
		sub	eax,edx				;R06
Sub_ok:							;R06
		pop	edx
rm_8:
rm_9:
		ret
Read_Memory	ENDP

Factor_7_Dig	dd	1000000			;R11
Factor_Ten_Thu1:
		dd	100000
		dd	10000
		dd	1000
		dd	100
		dd	10

;[]========================================================================[]
;Function :	Convert three byte integer to 6 DEC ASCII
;
;Input	:	EAX - word to be converted
;		SI - point to stack SIX_DIGIT
;Output	:	ss:[bp+SIX_DIGIT]
;[]========================================================================[]
		Public	Convert_6_Digit
Convert_6_Digit	proc	near
		pushad
;R11		mov	cx,5		;5 iterations
		mov	byte ptr [bp+si],30h	;leading space
;R11		mov	di,offset Factor_Ten_Thu1
		mov	cx,6		;6 iterations		;R11
		mov	di,offset Factor_7_Dig			;R11
		xor	dl,dl		;for leading space judge
Sub_Again1:
		inc	byte ptr [bp+si]
		sub	eax,cs:[di]
		je	short Next_Digit1
		jnc	short Sub_Again1
Add_Back1:
		add	eax,cs:[di]
		dec	byte ptr [bp+si]
Next_Digit1:
		cmp	byte ptr [bp+si],30h
		jne	short Non_Zero1
		or	dl,dl
		jnz	short Non_Zero1
		mov	byte ptr [bp+si],20h	;leading space
		jmp	short Zero_Space1
Non_Zero1:
		inc	dl
Zero_Space1:
		add	di,4
		inc	si
		mov	byte ptr [bp+si],30h
		loop	short Sub_Again1

		add	[bp+si],al
		mov	byte ptr [bp+si+1],0	;ending string
		popad
		ret
Convert_6_Digit	endp

;[]========================================================================[]
;
;	Display a 6 character word unsigned integer
;
;ENTRY:		EAX	Value to display
;EXIT:		NONE
;
;DESTROYS:	AX,CX,DX,SI
;SAVES:		BX,DI
;[]========================================================================[]
		Public	DISP_DWORD_INT6
DISP_DWORD_INT6	LABEL	NEAR

		extrn	BLAX_To_DEC6:near
		call	BLAX_To_DEC6
		jmp	Show_SIX_DIGIT

;[]==============================================================[]
;
;DISP_WORD_HEX4:
;
;	Display a word value in 4 hexadecimal characters.
;
;Saves:	NONE
;
;Entry:	AX	Word to display in hexadecimal...
;Exit:	NONE
;
;[]==============================================================[]
		ALIGN	4
		Public	DISP_WORD_HEX4
DISP_WORD_HEX4	PROC	NEAR

		xchg	al,ah			; display hex in reg. ax
		call	Disp_Byte_Hex2
		xchg	al,ah

;[]==============================================================[]
;
;DISP_BYTE_HEX2:
;
;	Display a byte value in 2 hexadecimal characters.
;
;Saves:	BX,CX,DX
;
;Entry:	AL	Byte to display in hexadecimal...
;Exit:	NONE
;
;[]==============================================================[]
		Public	DISP_BYTE_HEX2
DISP_BYTE_HEX2	LABEL	NEAR


		ror	al,4
		push	ax
		call	Disp_Byte_Hex1
		pop	ax
		ror	al,4

		Public	DISP_BYTE_HEX1
DISP_BYTE_HEX1	LABEL	NEAR

		push	ax
		and	al,0fh
		add	al,90h
		daa
		adc	al,40h
		daa

		push	cx
		extrn	Display_Char:near
		call	Display_Char
		pop	cx
		pop	ax
		ret

DISP_WORD_HEX4	ENDP
DISP_VAL	ENDP
;R14 - start
		Public	fProc_Disp_Byte_HEX2
fProc_Disp_Byte_HEX2	Proc	Far
		call	Disp_Byte_HEX2
		retf
fProc_Disp_Byte_HEX2	Endp
;R14 - end

;[]==============================================================[]
;
;	Get the current cursor position.
;
;ENTRY:		NONE
;EXIT:		DH	Row position
;		DL	Column position
;
;DESTROYS:	NONE
;[]==============================================================[]
		ALIGN	4
		Public	CURSOR_GET
CURSOR_GET	PROC	near
		mov	dx,cursor_x[bp]
		ret
CURSOR_GET	ENDP


;[]==============================================================[]
;
;	Turn the cursor off by <int 10h (ah=1)>.
;
;ENTRY:		NONE
;EXIT:		C	Set if cursor outside clip rectangle.
;
;DESTROYS:	DX
;[]==============================================================[]
		ALIGN	4
		Public	CURSOR_OFF
CURSOR_OFF	PROC	near

		mov	ah,1				;disable cursor
		mov	cx,0ff00h
		int	10h
		ret

CURSOR_OFF	ENDP

;[]==============================================================[]
;
;	Turn on cursor at current location
;
;ENTRY:		NONE
;EXIT:		C	Set if cursor outside clip rectangle.
;
;DESTROYS:	DX
;[]==============================================================[]
		ALIGN	4
		Public	CURSOR_ON
CURSOR_ON	LABEL	near

		inc	word ptr CURSOR_STAT[bp]

con_1:
;R07		mov	dx,word ptr CURSOR_X[bp]
;R07		mov	ah,1				;disable cursor
		mov	ch,14
		mov	al,EQUIPMENT[bp]
		and	al,DISPLAY_TYPE
		or	al,al				;is EGA/VGA?
		jz	short @F			;Yes,jump
;R07		sub	ch,2
		sub	ch,3				;R07
		cmp	al,DISPLAY_TYPE			;is monochrome?
		je	short @F			;Yes,jump
		mov	ch,6				;is CGA
@@:
		mov	cl,ch
		inc	cl
		mov	ah,1				;R07
		int	10h

		mov	dx,word ptr CURSOR_X[bp]	;R07
		jmp	short cursor_1

;[]==============================================================[]
;
;	Move cursor to certain location
;
;ENTRY:		DH		row
;		DL		column
;EXIT:		C	Set if cursor outside clip rectangle.
;
;NOTE:		1.	All cursor position changes come through this
;			routine.
;[]==============================================================[]
		ALIGN	4
		Public	CURSOR_SET
CURSOR_SET	LABEL	near

		mov	word ptr CURSOR_X[bp],dx

		cmp	word ptr CURSOR_STAT[bp],0
		jne	short con_1
		ret

cursor_1:
; Made cursor routines use visible area
;ver4.6		cmp	dl,VIS_LEFT[bp]
;ver4.6		jb	short cursor_2
;ver4.6
;ver4.6		cmp	dl,VIS_RIGHT[bp]
;ver4.6		ja	short cursor_2
;ver4.6
;ver4.6		cmp	dh,VIS_TOP[bp]
;ver4.6		jb	short cursor_2
;ver4.6
;ver4.6		cmp	dh,VIS_BTM[bp]
;ver4.6		ja	short cursor_2

; Made cursor routines use visible area

cursor_11:
		xor	bh,bh			; position cursor
		mov	ah,02h
		int	10h			; in clip rectangle

		clc
		ret

;ver4.6cursor_2:
;ver4.6		stc				; out of clip rectangle
;ver4.6		ret

;[]==============================================================[]
;
;	Displays a character a certain number to times, using the
;	visible area to clip.
;
;ENTRY:		AL		Character to print.
;		CX		Count of characters to print.
;
;EXIT:	    	NONE
;
;DESTROYS:	AX,CX
;SAVES:		BX,DX
;
;[]==============================================================[]
		ALIGN	4
		Public	DISP_CHARS
DISP_CHARS	PROC	NEAR

;ver4.6		push	cx
;ver4.6		extrn	Display_Char:near
;ver4.6Show_OneChar:
;ver4.6		call	Display_Char
;ver4.6		loop	short Show_OneChar
;ver4.6		pop	cx

	     	ret

DISP_CHARS	ENDP


;[]==============================================================[]
;
; get current attribute
;
;ENTRY:		NONE
;EXIT:		AL = ATTRIBUTE[BP]
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	GET_ATTR
GET_ATTR	PROC	near

		mov	al,byte ptr ATTRIBUTE[bp]
		ret

GET_ATTR	ENDP

;[]==============================================================[]
;
;	Get clip area
;
;ENTRY:		CL	Left edge of clip area
;		CH	Top edge of clip area
;		DL	Right edge of clip area
;		DH	Bottom edge of clip area
;EXIT:		NONE
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	GET_CLIP
GET_CLIP	PROC	near

		mov	cx,CLIP_LEFT[bp]
		mov	dx,CLIP_RIGHT[bp]
		ret

GET_CLIP	ENDP

;[]==============================================================[]
;
;	Gets the last key that was pressed.
;
;ENTRY:		NONE
;EXIT:		C	Set
;		AX	Last key pressed.
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	GET_LAST_KEY
GET_LAST_KEY	PROC	near
		mov	ax,LAST_KEY[bp]
		stc
		ret
GET_LAST_KEY	ENDP

;[]==============================================================[]
;
;	Get VIS area
;
;ENTRY:		CL	Left edge of VIS area
;		CH	Top edge of VIS area
;		DL	Right edge of VIS area
;		DH	Bottom edge of VIS area
;EXIT:		NONE
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	GET_VIS
GET_VIS		PROC	near

;ver4.6		mov	cx,VIS_LEFT[bp]
;ver4.6		mov	dx,VIS_RIGHT[bp]
		ret

GET_VIS		ENDP

		Public	NULL
NULL		PROC	near
		RET
NULL		ENDP

;[]==============================================================[]
;
;	Reset clip boundaries to full screen...
;
;ENTRY:		NONE
;EXIT:		NONE
;
;SAVES:		AX,Flags
;[]==============================================================[]
		Public	RESET_CLIP
RESET_CLIP	PROC	near

		mov	word ptr CLIP_LEFT[bp],0
		mov	word ptr VIS_LEFT[bp],0
		mov	word ptr CLIP_RIGHT[bp],144fh
		mov	word ptr VIS_RIGHT[bp],144fh
		ret

RESET_CLIP	ENDP

;[]==============================================================[]
;
;	Reset VIS boundaries to full screen...
;
;ENTRY:		NONE
;EXIT:		NONE
;
;DESTROYS:	AX
;[]==============================================================[]
		Public	RESET_VIS
RESET_VIS	PROC	near

;ver4.6		mov	ax, CLIP_LEFT[bp]
;ver4.6		mov	VIS_LEFT[bp],ax
;ver4.6
;ver4.6		mov	ax, CLIP_RIGHT[bp]
;ver4.6		mov	VIS_RIGHT[bp],ax

		ret
RESET_VIS	ENDP

;[]==============================================================[]
;	Scroll down up by one line
;
;ENTRY:	NONE
;EXIT:	NONE
;
;SAVES: BX,CX,DX
;DESTROYS: AX
;[]==============================================================[]
		Public	SCROLL_DOWN
SCROLL_DOWN	LABEL	near
		mov	ax,0701h
		jmp	short scroll

;[]==============================================================[]
;
;	Scroll screen up by one line
;
;ENTRY:	NONE
;EXIT:	NONE
;
;SAVES: BX,CX,DX
;DESTROYS: AX
;[]==============================================================[]
		Public	SCROLL_UP
SCROLL_UP	PROC	near

		mov	ax,0601h

scroll:
		push	bx
		push	cx
		push	dx

		mov	bh,ATTRIBUTE[bp]
		mov	cx,VIS_LEFT[bp]
		mov	dx,VIS_RIGHT[bp]
		int	10h

		pop	dx
		pop	cx
		pop	bx
		ret

SCROLL_UP	ENDP

;[]==============================================================[]
;
; set current attribute, (used after GET_ATTR to restore)
;
;ENTRY:		AL = attribute to set
;EXIT:		ATTRIBUTE[BP] = AL
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	SET_ATTR
SET_ATTR	PROC	near

		mov	byte ptr ATTRIBUTE[bp],al
		ret

SET_ATTR	ENDP

;[]==============================================================[]
;
;	Set clip area
;
;ENTRY:		CL	Left edge of clip area
;		CH	Top edge of clip area
;		DL	Right edge of clip area
;		DH	Bottom edge of clip area
;EXIT:		NONE
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	SET_CLIP
SET_CLIP	PROC	near

		mov	CLIP_LEFT[bp],cx
		mov	VIS_LEFT[bp],cx
		mov	CLIP_RIGHT[bp],dx
		mov	VIS_RIGHT[bp],dx
		ret

SET_CLIP	ENDP

;[]==============================================================[]
;
;	Set VIS area
;
;ENTRY:		CL	Left edge of VIS area
;		CH	Top edge of VIS area
;		DL	Right edge of VIS area
;		DH	Bottom edge of VIS area
;EXIT:		NONE
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	SET_VIS
SET_VIS		PROC	near

;ver4.6		mov	VIS_LEFT[bp],cx
;ver4.6		mov	VIS_RIGHT[bp],dx
		ret

SET_VIS		ENDP

;[]==============================================================[]
;
;	Set up user interface information
;
;ENTRY:		BP	Points to beginning of stack area.
;EXIT:		NONE
;
;[]==============================================================[]
		Public	USER_BEGIN
USER_BEGIN	PROC	near

; set monitor type flag

		mov	byte ptr MONOCHROME[bp],0	; assume monochrome

;Ver4.6IFNDEF	FORCE_MONO_IN_SETUP

		int	11h
		and	al,00110000b		; video mode...
		cmp	al,00110000b		; monochrome?
		je	short ub_1		; yes...

;Ver4.6  IFDEF	MONO_LCD_COLOR_CRT
;Ver4.6		call	Ct_Chk_LCD_CRT
;Ver4.6		or	al,al
;Ver4.6		jz	short ub_0 		; is LCD, keep mono
;Ver4.6  ENDIF	;MONO_LCD_COLOR_CRT

		inc	byte ptr MONOCHROME[bp]	; CRT, set to color

;Ver4.6ub_0:
;Ver4.6ENDIF	;FORCE_MONO_IN_SETUP

UB_1:
;Ver4.6		mov	al,cs:COLOR_SETTING
;Ver4.6		test	byte ptr cs:[POST_COLOR],01h
;Ver4.6		jz	short @F
;Ver4.6		mov	al,CMOS3B[bp]
;Ver4.6	@@:
		mov	al,0E0h
		call	Get_Color_Off

		extrn	vnormal:near
		call	vnormal			; set the normal attribut

		mov	word ptr LAST_KEY[bp],0
		mov	word ptr CURSOR_STAT[bp],0

		mov	ah,03h
		xor	bh,bh
		int	10h
		xor	dl,dl
		add	dh,1
		call	Cursor_Set

		call	Reset_Clip
		call	Cursor_Off		; cursor is invisible

;Ver4.6		jmp	near ptr VCls		; clear screen, reset clip, set cursor to top-left

		ret			;Ver4.6

USER_BEGIN	ENDP


		Public	VCLIP
VCLIP		PROC	near
;[]==============================================================[]
;
;	Set clip area to a specific area on the screen
;
;ENTRY:		DS:SI	Points to four bytes: left, top, right, bottom edge
;EXIT:		DS:SI	Points right after four bytes.
;
;DESTROYS:	CX
;
;SAVES:		DX
;[]==============================================================[]

;Ver4.6		lodsw
;Ver4.6		mov	CLIP_LEFT[bp],ax
;Ver4.6		mov	VIS_LEFT[bp],ax
;Ver4.6		lodsw
;Ver4.6		mov	CLIP_RIGHT[bp],ax
;Ver4.6		mov	VIS_RIGHT[bp],ax
		ret
VCLIP		ENDP

;[]==============================================================[]
;
;	Clears the entire screen, resets clip rectangle
;
;ENTRY:		NONE
;EXIT:		NONE
;
;DESTROYS:	AX
;[]==============================================================[]
		Public	VCLS
VCLS		PROC	near

;Ver4.6		push	bx
;Ver4.6		push	cx
;Ver4.6		push	dx
;Ver4.6
;Ver4.6		mov	bh,ATTRIBUTE[bp]
;Ver4.6		mov	cx,CLIP_LEFT[bp]
;Ver4.6		mov	dx,CLIP_RIGHT[bp]
;Ver4.6		mov	ax,0600h
;Ver4.6		int	10h
;Ver4.6
;Ver4.6		mov	ax,CLIP_LEFT[bp]
;Ver4.6		mov	word ptr CURSOR_X[bp],ax
;Ver4.6		mov	byte ptr BLOCK_LEFT_EDGE[bp],al
;Ver4.6
;Ver4.6		pop	dx
;Ver4.6		pop	cx
;Ver4.6		pop	bx
;Ver4.6
		ret
VCLS		ENDP

;[]==============================================================[]
;
;	Move cursor relative to clip area
;
;ENTRY:		DS:SI	Points to two bytes: column, row
;EXIT:		DS:SI	Points after two bytes
;
;DESTROYS:	AX
;
;[]==============================================================[]
		Public	VCPOS
VCPOS		PROC	near

;Ver4.6		lodsw
;Ver4.6		add	ax,CLIP_LEFT[bp]
;Ver4.6		mov	CURSOR_X[bp],ax
		ret

VCPOS		ENDP

;[]==============================================================[]
;
; 	Move the beginning of the next line.
;
;ENTRY:		NONE
;EXIT:		NONE
;
;DESTROYS:	NONE
;
;[]==============================================================[]
		ALIGN	4
		Public	VCRLF
VCRLF		PROC	near

		call	VLF
		call	VCR
		ret

VCRLF		ENDP

;[]==============================================================[]
;
;	Do a line feed, scrolling if necessary
;
;ENTRY:		NONE
;EXIT:		NONE
;
;DESTROYS:	AX
;[]==============================================================[]
		Public	VLF
VLF		Proc	Near

		push	ax
		mov	al, byte ptr CURSOR_Y[bp]

		cmp	al, byte ptr CLIP_BTM[bp] ; at bottom of screen?
		pop	ax
		jb	short vlf_1			  ; no...

		jmp 	near ptr Scroll_Up	  ; scroll up one line...

vlf_1:
		inc	byte ptr CURSOR_Y[bp]
		ret

VLF		Endp

;[]==============================================================[]
;
;	Move to beginning of this line
;
;ENTRY:		NONE
;EXIT:		NONE
;
;DESTROYS:	NONE
;
;[]==============================================================[]
		ALIGN	4
		Public	VCR
VCR		Proc	Near

		push	ax
		mov	al,byte ptr CLIP_LEFT[bp]
		mov	byte ptr CURSOR_X[bp],al
		pop	ax
		ret

VCR		Endp

;[]==============================================================[]
;
;	Move the cursor position to temporary left margin created by VEdge.
;
;ENTRY:	NONE
;EXIT:	NONE
;[]==============================================================[]
		Public	VECR
VECR		PROC	near

;Ver4.6		mov	al,BLOCK_LEFT_EDGE[bp]
;Ver4.6		mov	CURSOR_X[bp],al

		jmp	VLf
VECR		ENDP

;[]==============================================================[]
;
;	We make a temporary left margin at the current cursor position which
;	will be moved to every time we use an ECR. This allows us to place
;	a block of data which is not flush left without using the CLIP command.
;	This temporary margin is cleared by VCls.
;
;ENTRY:		NONE
;EXIT:		NONE
;[]==============================================================[]
		Public	VEDGE
VEDGE		PROC	near

;Ver4.6		mov	al,CURSOR_X[bp]
;Ver4.6		mov	BLOCK_LEFT_EDGE[bp],al

		ret
VEDGE		ENDP

;[]==============================================================[]
;
;	Move right by one space.
;
;ENTRY:		NONE
;EXIT:		NONE
;
;DESTROYS:	NONE
;
;[]==============================================================[]
		Public	VSPACE
VSPACE		PROC	near

;Ver4.6		inc	byte ptr cursor_x[bp]
		ret

VSPACE		ENDP

;[]==============================================================[]
;
;	Move right to the next tab (every eight characters)
;
;
;ENTRY:		NONE
;EXIT:		NONE
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	VTAB
VTAB		PROC	near

;Ver4.6		push	ax
;Ver4.6		mov	al,byte ptr cursor_x[bp]
;Ver4.6		add	al,08h
;Ver4.6		and	al,11111000b
;Ver4.6		mov	byte ptr cursor_x[bp],al
;Ver4.6		pop	ax
		ret
VTAB		ENDP

;[]==============================================================[]
;
;	Set visible area to a specific area on the screen
;
;ENTRY:		DS:SI	Points to four bytes: left, top, right, bottom edge
;EXIT:		DS:SI	Points right after four bytes.
;
;DESTROYS:	NONE
;[]==============================================================[]
		Public	VVIS
VVIS		PROC	near

;Ver4.6		lodsw
;Ver4.6		mov	VIS_LEFT[bp],ax
;Ver4.6		lodsw
;Ver4.6		mov	VIS_RIGHT[bp],ax
		ret
VVIS		ENDP

FCODE		ENDS

		END

