;       SCCSID = @(#)bvfscrol.asm	6.1 90/11/16
;SCCSID = @(#)bvfscrol.asm	6.3 90/01/23
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
	PAGE	58,132
	TITLE	BvsScrol.Asm -- Base Video Subsystem Scrolling Routines

;/********************** START OF SPECIFICATIONS ************************/
;/*									*/
;/* SOURCE FILE NAME:	BvsScrol.Asm					*/
;/*									*/
;/* DESCRIPTIVE NAME:	BVS Scroll Routines				*/
;/*									*/
;/* COPYRIGHT:	na							*/
;/*									*/
;/* STATUS:	na							*/
;/*									*/
;/* NOTES:	Executes on level 3 - Protect Mode ONLY 		*/
;/*									*/
;/*    DEPENDENCIES:	None						*/
;/*									*/
;/*    RESTRICTIONS:	None						*/
;/*									*/
;/*    PATCH LABEL:	na						*/
;/*									*/
;/* ENTRY POINTS: BvsScrollUp, BvsScrollDn,				*/
;/*		  BvsScrollLf, BvsScrollRt				*/
;/*									*/
;/* EXTERNAL REFERENCES: None						*/
;/************************ END OF SPECIFICATIONS ************************/

	.xlist
	INCLUDE bvfcb.inc		;BVS Data Structures
	INCLUDE error2.inc		;Error Equates
	INCLUDE struc.inc		;Structured Macros
	.list

	extrn	BVSROUT:NEAR

BVS3SEG SEGMENT BYTE PUBLIC 'CODE'
	ASSUME	CS:BVS3SEG

VIOSCROLLUP proc far
	public	VIOSCROLLUP
	pushi	<offset CS:BvsScrollUp>
	Call	BVSROUT
	ret	16			;7 words + VioHandle
VIOSCROLLUP endp

;Set equates used by the Scrolling routines

s_celloff equ	parmn			;Offset of fill Cell
s_cellsel equ	parmnm1 		;Selector of fill Cell
s_times equ	parmnm2 		;Number of times to scroll
s_rightcol equ	parmnm3 		;Rightmost column of window
s_botrow equ	parmnm4 		;Bottom row of window
s_leftcol equ	parmnm5 		;Leftmost column of window
s_toprow equ	parmnm6 		;Top row of window

s_cell	equ	s_celloff		;Cell passed from ptr to Cell
s_linelen equ	s_rightcol		;Number of cells per line
s_skiplen equ	s_leftcol		;Number of bytes per line to skip

;/*********************** START OF SPECIFICATIONS ***********************/
;/*									*/
;/* SUBROUTINE NAME:  BvsScrollUp					*/
;/*									*/
;/* DESCRIPTIVE NAME:  Base Video Subsystem Scroll Up			*/
;/*									*/
;/* FUNCTION:  Scrolls a portion of the video buffer up a specified	*/
;/*	       number of times. 					*/
;/*									*/
;/* NOTES:  Executes on Level 3 					*/
;/*									*/
;/* ENTRY POINT:  BvsScrollUp						*/
;/*   LINKAGE:	Call BvsScrollUp from BVSMAIN				*/
;/*									*/
;/* INPUT:  StackFrame and Registers (see BVSMAIN) with:		*/
;/*	parmn	= s_celloff	Offset of fill Cell			*/
;/*	parmnm1 = s_cellsel	Selector of fill Cell			*/
;/*	parmnm2 = s_times	Number of times to scroll		*/
;/*	parmnm3 = s_rightcol	Rightmost column of window		*/
;/*		= s_linelen	Number of cells per line		*/
;/*	parmnm4 = s_botrow	Bottom row of window			*/
;/*	parmnm5 = s_leftcol	Leftmost column of window		*/
;/*		= s_skiplen	Number of bytes per line to skip	*/
;/*	parmnm6 = s_toprow	Top row of window			*/
;/*									*/
;/* EXIT-NORMAL:  AX = 0						*/
;/*									*/
;/* EXIT-ERROR: Invalid TopRow value					*/
;/*		Invalid LeftCol value					*/
;/*									*/
;/* EFFECTS:  None							*/
;/*									*/
;/* INTERNAL REFERENCES:  BVSCBsg					*/
;/*   ROUTINES:  CheckScrollParms					*/
;/*									*/
;/* EXTERNAL REFERENCES:  None						*/
;/*   ROUTINES:  None							*/
;/*									*/
;/************************ END OF SPECIFICATIONS ************************/

;Bgnsub BvsScrollUp
;: Validate TopRow, BotRow, LeftCol, RightCol, Times, and Cell
;: If Error
;: : Indicate error in AX
;: Else
;: : Scroll the area using bios
;: : If fill character not blank
;: : : Write the fill character to the fill area
;: : Endif
;: : Set good return code
;: Endif
;Endsub

BvsScrollUp PROC NEAR			;Define subroutine
;	PUBLIC	BvsScrollUp

	Call	CheckScrlParms
	.if	z near			;Valid parameters, compute pointers
	    mov     ax,[bp].s_botrow
	    sub     ax,[bp].s_toprow
	    inc     ax
	    .if     <[bp].s_times a ax>
		mov	[bp].s_times,ax ;Limit times to window size
	    .endif

	    mov     al,byte ptr [bp].s_times
	    mov     ch,byte ptr [bp].s_toprow
	    mov     cl,byte ptr [bp].s_leftcol
	    mov     dh,byte ptr [bp].s_botrow
	    mov     dl,byte ptr [bp].s_rightcol
	    mov     bh,byte ptr [bp].s_celloff+1
	    mov     ah,6
	    int     10h 		;BIOS scroll up
	    sub     di,di

	    mov     ax,[bp].s_celloff	;AL <-- fill char
	    .if     <al ne 20h> 	;if non-blank fill char
		mov	bl,ah		;BL <-- fill attr
		mov	dx,40h
		mov	es,dx
		push	es:[di].real_cursorposn ;save current curpos

		mov	dh,byte ptr [bp].s_botrow
		sub	dh,byte ptr [bp].s_times
		inc	dh		;DH <-- fill row
		mov	dl,byte ptr [bp].s_leftcol ;DL <-- fill column
		mov	bh,0		;display page=0

		.if	<[bp].s_leftcol eq di> and
		mov	ax,[di].bvs_cols
		dec	ax
		.if	<[bp].s_rightcol eq ax>
		    mov     es:[di].real_cursorposn,dx ;set curpos
		    mov     ax,[bp].s_times
		    mul     byte ptr [di].bvs_cols
		    mov     cx,ax	;Compute fill amount
		    mov     al,byte ptr [bp].s_celloff ;Get the character
		    mov     ah,9	;AH=9 ==> BIOS WrtNcell
		    int     10H
		.else
		    mov     cx,[bp].s_rightcol
		    sub     cx,[bp].s_leftcol
		    inc     cx		;CX <- Line length
		    mov     al,byte ptr [bp].s_celloff ;Get the character

		    mov     si,[bp].s_times
		    .repeat
			mov	es:[di].real_cursorposn,dx ;set curpos
			mov	ah,9	;AH=9 ==> BIOS WrtNcell
			int	10H
			inc	dh
			dec	si
		    .until  z

		.endif

		pop	es:[di].real_cursorposn ;restore curpos
	    .endif

	    sub     ax,ax
	.endif
	sub	bx,bx
	RET				;Return to caller
BvsScrollUp ENDP

CheckScrlParms PROC NEAR
	public	CheckScrlParms

	les	si,dword ptr [bp].s_celloff
	mov	ax,es:[si]
	.if	<BIT [bx].bvs_type AND mode_f_graphics> ;@S2
	    mov     ah,0		;Alternate graphics attribute ;@S2
	.endif				;@S2
	mov	[bp].s_celloff,ax	;Save cell at celloff

	mov	ax,[bx].bvs_rows	;Range checking for row values
	dec	ax
	.if	<[bp].s_toprow a ax>
	    mov     [bp].s_toprow,ax
	.endif
	.if	<[bp].s_botrow a ax>
	    mov     [bp].s_botrow,ax
	.endif

	mov	ax,[bx].bvs_cols	;Range checking for column values
	dec	ax
	.if	<[bp].s_leftcol a ax>
	    mov     [bp].s_leftcol,ax
	.endif
	.if	<[bp].s_rightcol a ax>
	    mov     [bp].s_rightcol,ax
	.endif

	mov	ax,[bp].s_botrow
	cmp	ax,[bp].s_toprow
	.if	B			;BotRow < TopRow
	    mov     ax,error_vio_row	;Invalid Top Row return code ;1
	.else
	    mov     ax,[bp].s_rightcol
	    cmp     ax,[bp].s_leftcol
	    .if     B			;RightCol < LeftCol
		mov	ax,error_vio_col ;Invalid Left Column rc ;1
	    .else
		sub	ax,ax		;No error, set rc=0
	    .endif
	.endif

	and	ax,ax			;Set Zero flag to reflect AX
	.if	z
	    sub     cx,cx
	    .if     <[bp].s_times ne cx>
		inc	cx		;Make CX=1 when Times > 0
	    .endif
	    dec     cx			;NZ ==> Times=0, do nothing
	.endif
	RET
CheckScrlParms ENDP

BVS3SEG ENDS
	END

;@S2   = 04/13/89 STJ, Use correct attribute for graphics scrolling, B701002
