home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / VISCROLL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  4.2 KB  |  140 lines

  1. /**
  2. *
  3. * Name        viscroll -- Vertically scroll lines of text on the current
  4. *                display page by fastest available method.
  5. *
  6. * Synopsis    iret = viscroll(num_lines,attr,u_row,u_col,l_row,l_col,
  7. *               dir);
  8. *
  9. *        int iret      Number of lines actually scrolled
  10. *                  (0 if inactive page in graphics mode).
  11. *        int num_lines      Number of lines to scroll.  A value of 0
  12. *                  specifies that all lines within the
  13. *                  region should be scrolled (thus clearing
  14. *                  the region)
  15. *        int attr      This is the attribute to be used on the
  16. *                  vacant lines.  It has the background
  17. *                  attribute in the high order four bits
  18. *                  of the low order byte, and the
  19. *                  foreground in the low order nybble.
  20. *        int u_row,u_col   Upper left corner of region.
  21. *        int l_row,l_col   Lower right corner of region.
  22. *        int dir       Scrolling direction (SCR_UP or SCR_DOWN).
  23. *
  24. * Description    This function moves lines of characters (with their
  25. *        attributes) up or down within a defined rectangular
  26. *        region.  The vacant lines are filled with blanks and a
  27. *        specified attribute.
  28. *
  29. * Limitation    This function cannot perform a scroll on an inactive
  30. *        page in a graphics mode.
  31. *
  32. * Returns    iret          Number of lines actually scrolled
  33. *                  (0 if inactive page in graphics mode).
  34. *
  35. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986,1987,1989
  36. *
  37. **/
  38.  
  39. #include <dos.h>
  40.  
  41. #include <bscreens.h>
  42. #include <bvideo.h>
  43.  
  44. int viscroll(num_lines,attr,u_row,u_col,l_row,l_col,dir)
  45. int num_lines,attr,u_row,u_col,l_row,l_col,dir;
  46. {
  47.     int  device,mode,act_page,last_row,columns;
  48.     int  height,width;
  49.     union REGS inregs,outregs;
  50.     int  command;
  51.     char far *pfrom;
  52.     char far *pto;
  53.     const char            blank = ' ';
  54.     const char far * const pblank = ␣
  55.     int  fast_mask;
  56.  
  57.     device   = scmode(&mode,&columns,&act_page);
  58.     last_row = scrows() - 1;
  59.  
  60.     utbound(u_row,0,last_row)           /* Force reasonable values */
  61.     utbound(l_row,u_row,last_row)
  62.     utbound(u_col,0,columns - 1)
  63.     utbound(l_col,u_col,columns - 1)
  64.     height = l_row - u_row + 1;
  65.     if (num_lines <= 0 || num_lines > height)
  66.     num_lines = height;          /* Do not scroll more lines     */
  67.                       /* than there are in the region.*/
  68.  
  69.     if (b_curpage == act_page)          /* If active page           */
  70.     {
  71.     inregs.h.ah = (unsigned char) (dir == SCR_UP ? 6 : 7);
  72.     inregs.h.al = (unsigned char) (num_lines == height ? 0 : num_lines);
  73.     inregs.h.bh = (unsigned char) attr;
  74.     inregs.h.ch = (unsigned char) u_row;
  75.     inregs.h.cl = (unsigned char) u_col;
  76.     inregs.h.dh = (unsigned char) l_row;
  77.     inregs.h.dl = (unsigned char) l_col;
  78.     int86 (16,&inregs,&outregs);  /* Use BIOS scroll          */
  79.     }
  80.     else if (mode <= 3 || mode == 7)  /* If text mode              */
  81.     {                      /* do direct video access.      */
  82.     width  = l_col - u_col + 1;
  83.  
  84.     if (   b_vifast  != 0
  85.         || mode     == 7
  86.         || scequip() == IBM_CV
  87.         || device     == b_ega
  88.         || device     == b_vga
  89.         || device     == b_mcga)
  90.         fast_mask = (int) 0x8000;    /* Need not await retrace     */
  91.     else
  92.         fast_mask = 0x0000;
  93.  
  94.     if (num_lines < height)
  95.     {                  /* We're not blanking the whole */
  96.                       /* region.              */
  97.         if (dir == SCR_DOWN)
  98.         {                  /* Downward              */
  99.         command = 9;
  100.         pfrom    = viptr(u_row,          u_col);
  101.         pto    = viptr(u_row + num_lines,u_col);
  102.         }
  103.         else
  104.         {                  /* Upward               */
  105.         command = 7;
  106.         pfrom    = viptr(u_row + num_lines,u_col);
  107.         pto    = viptr(u_row,          u_col);
  108.         }
  109.  
  110.         vidirect(&pfrom,&pto,height - num_lines,width,
  111.               columns * 2,0,command | fast_mask);
  112.     }
  113.     else
  114.         dir = SCR_UP;          /* Shortcut to force          */
  115.                       /* computation of pto.          */
  116.  
  117.     /* Now blank out the new lines in the region.             */
  118.  
  119.     if (dir == SCR_DOWN)
  120.     {
  121.         pto = pfrom;          /* pfrom already points to      */
  122.                       /* first line to blank          */
  123.     }
  124.     else
  125.     {
  126.                       /* Address of first line to     */
  127.         pto = viptr(u_row + height - num_lines,u_col);   /* blank */
  128.     }
  129.     vidirect(&pblank,&pto,num_lines,width,
  130.               columns * 2,attr,
  131.               3 | fast_mask);
  132.     }
  133.     else
  134.     num_lines = 0;              /* Can't handle scrolling on    */
  135.                       /* inactive page in graphics    */
  136.                       /* mode.                  */
  137.  
  138.     return num_lines;
  139. }
  140.