home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name viscroll -- Vertically scroll lines of text on the current
- * display page by fastest available method.
- *
- * Synopsis iret = viscroll(num_lines,attr,u_row,u_col,l_row,l_col,
- * dir);
- *
- * int iret Number of lines actually scrolled
- * (0 if inactive page in graphics mode).
- * int num_lines Number of lines to scroll. A value of 0
- * specifies that all lines within the
- * region should be scrolled (thus clearing
- * the region)
- * int attr This is the attribute to be used on the
- * vacant lines. It has the background
- * attribute in the high order four bits
- * of the low order byte, and the
- * foreground in the low order nybble.
- * int u_row,u_col Upper left corner of region.
- * int l_row,l_col Lower right corner of region.
- * int dir Scrolling direction (SCR_UP or SCR_DOWN).
- *
- * Description This function moves lines of characters (with their
- * attributes) up or down within a defined rectangular
- * region. The vacant lines are filled with blanks and a
- * specified attribute.
- *
- * Limitation This function cannot perform a scroll on an inactive
- * page in a graphics mode.
- *
- * Returns iret Number of lines actually scrolled
- * (0 if inactive page in graphics mode).
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1986,1987,1989
- *
- **/
-
- #include <dos.h>
-
- #include <bscreens.h>
- #include <bvideo.h>
-
- int viscroll(num_lines,attr,u_row,u_col,l_row,l_col,dir)
- int num_lines,attr,u_row,u_col,l_row,l_col,dir;
- {
- int device,mode,act_page,last_row,columns;
- int height,width;
- union REGS inregs,outregs;
- int command;
- char far *pfrom;
- char far *pto;
- const char blank = ' ';
- const char far * const pblank = ␣
- int fast_mask;
-
- device = scmode(&mode,&columns,&act_page);
- last_row = scrows() - 1;
-
- utbound(u_row,0,last_row) /* Force reasonable values */
- utbound(l_row,u_row,last_row)
- utbound(u_col,0,columns - 1)
- utbound(l_col,u_col,columns - 1)
- height = l_row - u_row + 1;
- if (num_lines <= 0 || num_lines > height)
- num_lines = height; /* Do not scroll more lines */
- /* than there are in the region.*/
-
- if (b_curpage == act_page) /* If active page */
- {
- inregs.h.ah = (unsigned char) (dir == SCR_UP ? 6 : 7);
- inregs.h.al = (unsigned char) (num_lines == height ? 0 : num_lines);
- inregs.h.bh = (unsigned char) attr;
- inregs.h.ch = (unsigned char) u_row;
- inregs.h.cl = (unsigned char) u_col;
- inregs.h.dh = (unsigned char) l_row;
- inregs.h.dl = (unsigned char) l_col;
- int86 (16,&inregs,&outregs); /* Use BIOS scroll */
- }
- else if (mode <= 3 || mode == 7) /* If text mode */
- { /* do direct video access. */
- width = l_col - u_col + 1;
-
- if ( b_vifast != 0
- || mode == 7
- || scequip() == IBM_CV
- || device == b_ega
- || device == b_vga
- || device == b_mcga)
- fast_mask = (int) 0x8000; /* Need not await retrace */
- else
- fast_mask = 0x0000;
-
- if (num_lines < height)
- { /* We're not blanking the whole */
- /* region. */
- if (dir == SCR_DOWN)
- { /* Downward */
- command = 9;
- pfrom = viptr(u_row, u_col);
- pto = viptr(u_row + num_lines,u_col);
- }
- else
- { /* Upward */
- command = 7;
- pfrom = viptr(u_row + num_lines,u_col);
- pto = viptr(u_row, u_col);
- }
-
- vidirect(&pfrom,&pto,height - num_lines,width,
- columns * 2,0,command | fast_mask);
- }
- else
- dir = SCR_UP; /* Shortcut to force */
- /* computation of pto. */
-
- /* Now blank out the new lines in the region. */
-
- if (dir == SCR_DOWN)
- {
- pto = pfrom; /* pfrom already points to */
- /* first line to blank */
- }
- else
- {
- /* Address of first line to */
- pto = viptr(u_row + height - num_lines,u_col); /* blank */
- }
- vidirect(&pblank,&pto,num_lines,width,
- columns * 2,attr,
- 3 | fast_mask);
- }
- else
- num_lines = 0; /* Can't handle scrolling on */
- /* inactive page in graphics */
- /* mode. */
-
- return num_lines;
- }