;       SCCSID = @(#)bvsfont.asm	6.1 90/11/16
;SCCSID = @(#)bvsfont.asm	6.6 90/02/12
	PAGE	58,132
	TITLE	BvsFont.Asm -- Base Video Subsystem Font Routines
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************

;/*********************** START OF SPECIFICATIONS ***********************/
;/*									*/
;/* SOURCE FILE NAME:	 BvsFont.Asm					*/
;/*									*/
;/* DESCRIPTIVE NAME:	 Base Video Subsystem Font Routines		*/
;/*									*/
;/* COPYRIGHT:	 na							*/
;/*									*/
;/* STATUS:	 na							*/
;/*									*/
;/* NOTES:	 Executes on level 3 - Protect Mode ONLY		*/
;/*									*/
;/*    DEPENDENCIES:	None						*/
;/*									*/
;/*    RESTRICTIONS:	None						*/
;/*									*/
;/*    PATCH LABEL:	na						*/
;/*									*/
;/* ENTRY POINTS: BvsGetFont, BvsSetFont				*/
;/*									*/
;/* EXTERNAL REFERENCES: None						*/
;/************************ END OF SPECIFICATIONS ************************/

	.xlist
	INCLUDE bvscb.inc		;BVS Data Structures
	INCLUDE bvsparms.inc		;BVS Parameter Equates
	INCLUDE bvsextrn.inc		;BVS external definitions	;@T52
	INCLUDE error2.inc		;Error Equates
	INCLUDE struc.inc		;Structured Macros
	.list

	.386p			;@D549

	extrn	DOSALLOCSEG:FAR 	;Dos Segment Allocation routine
	extrn	DOSREALLOCSEG:FAR	;Dos Segment Reallocation routine
	extrn	DOSFREESEG:FAR		;Dos Segment Deallocation routine ;@S26

	extrn	AllVDH:NEAR		;Common VDH call routine in BVSMAIN

BVS3SEG SEGMENT BYTE PUBLIC 'CODE' USE16        ;@D549
	ASSUME	CS:BVS3SEG

;/*********************** START OF SPECIFICATIONS ***********************/
;/*									*/
;/* SUBROUTINE NAME:  BvsGetFont					*/
;/*									*/
;/* DESCRIPTIVE NAME:  Base Video Subsystem Get Video Font		*/
;/*									*/
;/* FUNCTION:  Returns selected video font.  If a RAM font is to be	*/
;/*	       returned, a new segment will be allocated to hold the	*/
;/*	       font.							*/
;/*									*/
;/* NOTES:  Executes on Level 3 					*/
;/*									*/
;/* ENTRY POINT:  BvsGetFont						*/
;/*   LINKAGE:	Call BvsGetFont from BVSMAIN				*/
;/*									*/
;/* INPUT:  StackFrame and Registers (see BVSMAIN)			*/
;/*	parmn	= Offset of request block				*/
;/*	parmnm1 = Selector of request block				*/
;/*									*/
;/* EXIT-NORMAL:  AX = 0 ==> Operation completed successfully		*/
;/*									*/
;/* EXIT-ERROR:  AX = error code from DOSALLOCSEG			*/
;/*		      ERROR_VIO_INVALID_LENGTH				*/
;/*		      ERROR_VIO_INVALID_PARMS				*/
;/*									*/
;/* EFFECTS:  None							*/
;/*									*/
;/* INTERNAL REFERENCES:  BVSCBsg, PPBVSCB, BVSCPnn			*/
;/*   ROUTINES: FindFont						*/
;/*									*/
;/* EXTERNAL REFERENCES:  None						*/
;/*   ROUTINES: DosAllocSeg						*/
;/*									*/
;/************************ END OF SPECIFICATIONS ************************/

;Begin BvsGetFont
;    Preset return code to ERROR_VIO_LENGTH
;    If correct length of request block
;	 Preset return code to ERROR_VIO_PARMS
;	 If the request is for a specific font or the current font
;	     Call GetFont in the VDH
;	     If no error, but buffer not yet allocated
;		 If a buffer was provided by the user
;		     Call DosAllocSeg for the user's font buffer
;		     If no error
;			 Call GetFont in the VDH to fill the new buffer
;		     Endif
;		 Endif
;	     Endif
;	 Endif
;    Endif
;End BvsGetFont

BvsGetFont PROC NEAR
	PUBLIC	BvsGetFont

	mov	ax,ERROR_VIO_INVALID_LENGTH ;Preset error
	lds	si,dword ptr [bp].p_offset ;Get parm list ptr
	.if	<[si].fp_rblength eq <size fontparms>> near ;Valid length
	    mov     ax,ERROR_VIO_INVALID_PARMS ;Preset error
	    mov     dx,[si].fp_reqtype	;Get request type
	    .if     <dx be 1> near	;Valid request type
		push	dx		;@@B save request type
		add	dx,dx		;Shift request type to bit 1
		mov	[bp].vp_parmlength,14
		mov	[bp].vp_flags,dx ;Set the flags

		mov	ax,[si].fp_offset
		mov	[bp].vp_offset,ax
		mov	cx,[si].fp_selector ;@@A
		mov	[bp].vp_selector,cx ;Set the font data pointer ;@@A

		or	cx,ax		;@@A
		mov	ax,[si].fp_length ;Get requested length ;@@A
		mov	dx,ax		;Save requested length ;@S26
		.if	<z>		;NULL pointer specified ;@@A
		    sub     ax,ax	;Request length to allocate ;@@A
		.endif			;@@A
		mov	[bp].vp_fp_length,ax ;Set the font length ;@@A

		mov	ax,[si].fp_cols
		mov	[bp].vp_fp_cols,ax ;Set the pel columns
		mov	ax,[si].fp_rows
		mov	[bp].vp_fp_rows,ax ;Set the pel rows

		mov	di,fn_GetFont
		push	[bp].vp_flags	;@S26
		Call	AllVDH
		pop	[bp].vp_flags	;@S26

		.if	<cxz> and	;NULL pointer specified AND ;@@A
		.if	<zero ax>	;No error ;@@A
		    push    word ptr [bp].vp_fp_length ;Set length to allocate
		    push    ss
		    lea     ax,[bp].vp_selector
		    push    ax		;Set selector return addr
		    push    bx
		    Call    DOSALLOCSEG ;Allocate the buffer
		    .if     <zero ax>	;No error
			mov	[bp].vp_parmlength,14

			mov	[bp].vp_offset,bx
			mov	ax,[bp].vp_selector
			mov	[si].fp_selector,ax
			mov	[si].fp_offset,bx ;Return new addr to caller
			mov	ax,[bp].vp_fp_length
			mov	[si].fp_length,ax ;Return new length

			Call	AllVDH	;Call again with new buffer

			.if	<nonzero ax> ;@S26
			    push    ax	;@S26

			    push    [si].fp_selector ;@S26
			    Call    DOSFREESEG ;Free the new selector ;@S26

			    mov     [si].fp_selector,bx ;@S26
			    mov     [si].fp_offset,bx ;@S26
			    mov     [si].fp_length,dx ;Restore parmlist ;@S26

			    pop     ax	;@S26
			.endif		;@S26
		    .endif
		.endif

		pop	cx		;@@B get request type
		.if	<cxz> and	;@@B if get current font type
		.if	<zero ax>	;@@B and no error
		    mov     cx,[bp].vp_fp_length ;@@B set parmblock
		    mov     [si].fp_length,cx ;@@B font length
		    mov     cx,[bp].vp_fp_cols ;@@B pel columns
		    mov     [si].fp_cols,cx ;@@B
		    mov     cx,[bp].vp_fp_rows ;@@B pel rows
		    mov     [si].fp_rows,cx ;@@B
		.endif			;@@B
	    .endif
	.endif
	ret
BvsGetFont ENDP

;/*********************** START OF SPECIFICATIONS ***********************/
;/*									*/
;/* SUBROUTINE NAME:  BvsSetFont					*/
;/*									*/
;/* DESCRIPTIVE NAME:  Base Video Subsystem Set Video Font		*/
;/*									*/
;/* FUNCTION:  Loads the provided video font into the video hardware.	*/
;/*									*/
;/* NOTES:  Executes on Level 3 					*/
;/*									*/
;/* ENTRY POINT:  BvsSetFont						*/
;/*   LINKAGE:	Call BvsSetFont from BVSMAIN				*/
;/*									*/
;/* INPUT:  StackFrame and Registers (see BVSMAIN)			*/
;/*	parmn	= Offset of request block				*/
;/*	parmnm1 = Selector of request block				*/
;/*									*/
;/* EXIT-NORMAL:  AX = 0 ==> Operation completed successfully		*/
;/*									*/
;/* EXIT-ERROR:  AX = error code from DOSREALLOCSEG			*/
;/*									*/
;/* EFFECTS:  None							*/
;/*									*/
;/* INTERNAL REFERENCES:  BVSCBsg, PPBVSCB, BVSCPnn			*/
;/*   ROUTINES:  None							*/
;/*									*/
;/* EXTERNAL REFERENCES:  None						*/
;/*   ROUTINES:  DOSREALLOCSEG, SetFont in VDH				*/
;/*									*/
;/************************ END OF SPECIFICATIONS ************************/

;Begin BvsSetFont
;    Call SetFont in VDH to inform it of the new font
;    If successful
;	 If the font buffer in the BVSCB is too small
;	     Call DosReallocSeg to grow the BVSCB
;	 Endif
;	 Save a copy of the user font in the BVSCB
;    Endif
;End BvsSetFont

BvsSetFont PROC NEAR
	PUBLIC	BvsSetFont

	push	ds
	pop	es			;ES=BVSCB

	mov	ax,ERROR_VIO_INVALID_LENGTH ;Preset error
	lds	si,dword ptr [bp].p_offset ;Get parm list ptr
	.if	<[si].fp_rblength eq <size fontparms>> ;Valid length
	    mov     ax,ERROR_VIO_INVALID_PARMS ;Preset error
	    .if     <[si].fp_reqtype eq bx> ;Valid request type

		mov	[bp].vp_parmlength,14

		mov	ax,[si].fp_offset
		mov	[bp].vp_offset,ax
		mov	ax,[si].fp_selector
		mov	[bp].vp_selector,ax ;Set the font data pointer

		mov	ax,[si].fp_cols
		mov	[bp].vp_fp_cols,ax ;Set the pel columns
		mov	ax,[si].fp_rows
		mov	[bp].vp_fp_rows,ax ;Set the pel rows
		mov	ax,[si].fp_length ;PTM 2875
		mov	[bp].vp_fp_length,ax ;Set the font length

		mov	di,fn_SetFont
		Call	AllVDH
	    .endif
	.endif

	ret
BvsSetFont ENDP

BVS3SEG ENDS
	END

;@@A = 12/10/88 STJ, Use NULL ptr as indicator to allocate font buffer
;@@B = 12/16/88 CJJ, Return font info. in ParmBlock if get current_font
;@T31 = 05/18/89 TPL, PhilipL suggested changes for DCR 132, B783850
;@S26 = 08/22/89 STJ, Add unique code for CGA 8x8 fonts, B785343
;@D549 = 11/02/89 CJJ, Seltable changes due to rangeless sessions, DCR 549
;@T52 = 01/16/90 TPL, DCR 704 work
