home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / SCPSCROL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  4.0 KB  |  131 lines

  1. /**
  2. *
  3. * Name        scpscrol -- Vertically scroll lines of text on the current
  4. *                display page via the BIOS
  5. *
  6. * Synopsis    iret = scpscrol(num_lines,attrib,u_row,u_col,l_row,l_col,
  7. *               dir);
  8. *
  9. *        int iret      Number of lines actually scrolled.
  10. *        int num_lines      Number of lines to scroll.  A value of
  11. *                  0 specifies that all lines within the
  12. *                  rectangle should be scrolled (thus
  13. *                  clearing the window)
  14. *        int attrib      If the screen is in text mode, this
  15. *                  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. *                  If the screen is in graphics mode and
  21. *                  the current page is not active, this
  22. *                  is the color to use for the scrolled text.
  23. *                  If the screen is in graphics mode and
  24. *                  the current page is active, this is
  25. *                  ignored.
  26. *        int u_row,u_col   Upper left corner of area to scroll.
  27. *        int l_row,l_col   Lower right corner of area to scroll.
  28. *        int dir       Scrolling direction (SCR_UP or SCR_DOWN).
  29. *
  30. * Description    This function moves lines of characters (with their
  31. *        attributes) up or down within a rectangular area of the
  32. *        current display page.  The vacant lines are filled with
  33. *        blanks and a specified attribute.
  34. *
  35. *        Use VISCROLL for greater speed in text modes on inactive
  36. *        pages.
  37. *
  38. * Returns    iret          Number of lines actually scrolled.
  39. *
  40. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  41. *
  42. **/
  43.  
  44. #include <bscreen.h>
  45.  
  46. int scpscrol(num_lines,attrib,u_row,u_col,l_row,l_col,dir)
  47. int num_lines,attrib,u_row,u_col,l_row,l_col,dir;
  48. {
  49.     int mode,columns,apage;           /* Values returned by scmode    */
  50.     int graphics,last_row;
  51.     char buffer[PC_COLS * 2],*pbuffer;
  52.     int from_row,to_row,step,height,width,i,j;
  53.     int fore,back;
  54.     int save_row,save_col,cursor_was_on,top_scan,bot_scan;
  55.  
  56.     scmode(&mode,&columns,&apage);
  57.     graphics = (mode > 3 && mode != 7);
  58.     last_row = scrows() - 1;
  59.  
  60.     utbound(u_row,0,last_row)          /* Force reasonable values      */
  61.     utbound(u_row,u_row,last_row)
  62.     height = l_row - u_row + 1;
  63.     if (num_lines <= 0 || num_lines > height)
  64.     num_lines = height;           /* Do not scroll more lines     */
  65.                        /* than there are in the window.*/
  66.     if (apage == b_curpage)
  67.     {                       /* SCSCROLL is faster           */
  68.     scscroll(num_lines,attrib,u_row,u_col,l_row,l_col,dir);
  69.     return num_lines;
  70.     }
  71.  
  72.     utbound(u_col,0,columns - 1)
  73.     utbound(l_col,u_col,columns - 1)
  74.     width  = l_col - u_col + 1;
  75.     if (graphics)              /* Force attribute for graphics */
  76.     {
  77.     utbound(attrib,0,3)
  78.     }
  79.  
  80.     if (dir == SCR_DOWN)
  81.     {                      /* Downward              */
  82.     to_row     = l_row;
  83.     from_row = l_row - num_lines;
  84.     step     = -1;
  85.     }
  86.     else
  87.     {                      /* Upward               */
  88.     to_row     = u_row;
  89.     from_row = u_row + num_lines;
  90.     step     = 1;
  91.     }
  92.  
  93.     /* Move the lines of text                          */
  94.  
  95.                       /* Save cursor size & position. */
  96.     if (cursor_was_on = !sccurst(&save_row,&save_col,&top_scan,&bot_scan))
  97.                       /* Turn the cursor off          */
  98.     scpgcur(1,top_scan,bot_scan,CUR_NO_ADJUST);
  99.  
  100.     for (i = height - num_lines; i; i--)
  101.     {
  102.     scrdbuf(from_row,u_col,width,buffer,CHAR_ATTR);
  103.     if (graphics)
  104.         for (j = 0,pbuffer = buffer + 1; j < width; j++)
  105.         {
  106.         *pbuffer = (char) attrib;    /* Set attributes of     */
  107.         pbuffer += 2;             /* scrolled text          */
  108.         }
  109.     scwrbuf(to_row,u_col,width,buffer,0,0,CHAR_ATTR);
  110.     from_row += step;
  111.     to_row     += step;
  112.     }
  113.  
  114.     /* Fill the blank lines in                          */
  115.  
  116.     fore = utlonyb(attrib);
  117.     back = uthinyb(attrib);
  118.     for (i = num_lines; i; i--)
  119.     {
  120.     sccurset(to_row,u_col);
  121.     scattrib(fore,back,(char) ' ',width);
  122.     to_row += step;
  123.     }
  124.  
  125.     sccurset(save_row,save_col);      /* Restore cursor position      */
  126.     if (cursor_was_on)              /* Restore cursor size.          */
  127.     scpgcur(0,top_scan,bot_scan,CUR_NO_ADJUST);
  128.  
  129.     return num_lines;
  130. }
  131.