home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / VISCROLL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  3.6 KB  |  123 lines

  1. /**
  2. *
  3. * Name        viscroll -- Vertically scroll lines of text on the current
  4. *                display page by direct memory access.
  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 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. *        This function works only for standard text modes (0, 1,
  30. *        2, 3, and 7).  Use SCPSCROL for other modes or when BIOS
  31. *        compatibility is desirable.
  32. *
  33. * Returns    iret          Number of lines actually scrolled
  34. *                  (0 if graphics mode).
  35. *
  36. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  37. *
  38. * Version    3.02 March 20, 1987
  39. *        Corrected handling of SCR_DOWN case to force computation
  40. *            of to_ads.
  41. *
  42. **/
  43.  
  44. #include <bquery.h>
  45. #include <bscreen.h>
  46. #include <bvideo.h>
  47.  
  48. int viscroll(num_lines,attr,u_row,u_col,l_row,l_col,dir)
  49. int num_lines,attr,u_row,u_col,l_row,l_col,dir;
  50. {
  51.     int  device,mode,last_row,columns,act_page;
  52.     int  height,width;
  53.     int  command;
  54.     ADS  from_ads,to_ads;
  55.     char blank;
  56.     int  fast_mask;
  57.  
  58.     device = scmode(&mode,&columns,&act_page);
  59.     if (mode > 3 && mode != 7)
  60.     return 0;
  61.     last_row = scrows() - 1;
  62.  
  63.     utbound(u_row,0,last_row)           /* Force reasonable values */
  64.     utbound(l_row,u_row,last_row)
  65.     utbound(u_col,0,columns - 1)
  66.     utbound(l_col,u_col,columns - 1)
  67.     height = l_row - u_row + 1;
  68.     width  = l_col - u_col + 1;
  69.     if (num_lines <= 0 || num_lines > height)
  70.     num_lines = height;          /* Do not scroll more lines     */
  71.                       /* than there are in the region.*/
  72.  
  73.     if (   mode      == 7
  74.     || scequip() == IBM_CV
  75.     || device    == b_ega)
  76.     fast_mask = (int) 0x8000;     /* Need not await retrace       */
  77.     else
  78.     fast_mask = 0x0000;
  79.  
  80.     if (num_lines < height)
  81.     {                      /* We're not blanking the whole */
  82.                       /* region.              */
  83.     if (dir == SCR_DOWN)
  84.     {                  /* Downward              */
  85.         command = 9;
  86.         viads(u_row,        u_col,&from_ads);
  87.         viads(u_row + num_lines,u_col,&to_ads);
  88.     }
  89.     else
  90.     {                  /* Upward               */
  91.         command = 7;
  92.         viads(u_row + num_lines,u_col,&from_ads);
  93.         viads(u_row,        u_col,&to_ads);
  94.     }
  95.  
  96.     vidirect(&from_ads,&to_ads,height - num_lines,width,
  97.               columns * 2,0,command | fast_mask);
  98.     }
  99.     else
  100.     dir = SCR_UP;              /* Shortcut to force          */
  101.                       /* computation of to_ads.       */
  102.  
  103.     /* Now blank out the new lines in the region.              */
  104.  
  105.     if (dir == SCR_DOWN)
  106.     {
  107.     to_ads.r = from_ads.r;          /* from_ads already points to   */
  108.     to_ads.s = from_ads.s;          /* first line to blank          */
  109.     }
  110.     else
  111.     {
  112.                       /* Address of first line to     */
  113.     viads(u_row + height - num_lines,u_col,&to_ads);  /* blank    */
  114.     }
  115.     blank = ' ';
  116.     utabsptr(&blank,&from_ads);
  117.     vidirect(&from_ads,&to_ads,num_lines,width,
  118.               columns * 2,attr,
  119.               3 | fast_mask);
  120.  
  121.     return num_lines;
  122. }
  123.