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

  1. /**
  2. *
  3. * Name        viwrrect -- Write rectangular region directly to
  4. *                the current display page
  5. *
  6. * Synopsis    num_writ = viwrrect(u_row,u_col,l_row,l_col,
  7. *                    buffer,fore,back,option);
  8. *
  9. *        int  num_writ    Number of character cells actually
  10. *                written (0 if graphics mode)
  11. *        int  u_row    Top row to write (0 = top of screen)
  12. *        int  u_col    Leftmost column to write (0 = left edge)
  13. *        int  l_row    Bottom row to write
  14. *        int  l_col    Rightmost column to write
  15. *        char *buffer    Space containing the data to write
  16. *        int  fore    If CHARS_ONLY is specified, a value
  17. *                between 0 and 15 specifies a new
  18. *                foreground attribute,
  19. *                unless both fore and back are -1, in which
  20. *                case existing attributes are preserved.
  21. *        int  back    If CHARS_ONLY is specified, a value
  22. *                between 0 and 15 specifies a new
  23. *                background attribute,
  24. *                unless both fore and back are -1, in which
  25. *                case existing attributes are preserved.
  26. *        int  option    One bit in the option value tells VIWRRECT
  27. *                how the buffer is constructed.    The two
  28. *                possible values for this bit are:
  29. *
  30. *              Value        Meaning
  31. *              -----------   ------------------------------------
  32. *              CHARS_ONLY    Buffer contains characters only.
  33. *                    The values of fore and back are used
  34. *                    as attributes, unless they are both -1,
  35. *                    in which case the existing screen
  36. *                    attributes are left unchanged.
  37. *              CHAR_ATTR     Buffer contains (char,attr) pairs.
  38. *                    The values of fore and back are ignored.
  39. *
  40. * Description    This function fills a rectangular region on the current
  41. *        display page with characters from a buffer with or
  42. *        without their corresponding video attributes.  The data
  43. *        is written row by row.    The cursor is not moved.
  44. *
  45. *        This function works only for standard text modes (0, 1,
  46. *        2, 3, and 7).  Use SCWRRECT for other modes.
  47. *
  48. *        The upper left corner of the region is (u_row,u_col),
  49. *        where (0,0) represents the upper left corner of the
  50. *        entire screen.    The lower right corner of the region is
  51. *        (l_row,l_col), where (24,79) is the lower right corner
  52. *        of an 80-by-25 screen.
  53. *
  54. *        The returned value reports the number of "character
  55. *        cells" written, where "character cells" means the number
  56. *        of physical spaces on the screen.  (If CHAR_ATTR is
  57. *        specified, twice this number of bytes will be used from
  58. *        the buffer.)
  59. *
  60. *        Be aware that this function does NOT recognize NULs
  61. *        ('\0') or any other special characters.
  62. *
  63. * Returns    num_writ    Number of character cells written
  64. *
  65. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  66. *
  67. **/
  68.  
  69. #include <bquery.h>
  70. #include <bscreen.h>
  71. #include <bvideo.h>
  72.  
  73. int viwrrect(u_row,u_col,l_row,l_col,buffer,fore,back,option)
  74. int  u_row,u_col,l_row,l_col;
  75. char *buffer;
  76. int  fore,back,option;
  77. {
  78.     int device,mode,last_row,columns,act_page;
  79.     int height,width;
  80.     int command;
  81.     ADS buf_ads,scn_ads;
  82.  
  83.     device = scmode(&mode,&columns,&act_page);
  84.     if (mode > 3 && mode != 7)
  85.     return 0;
  86.     last_row = scrows() - 1;
  87.  
  88.     utbound(u_row,0,last_row)           /* Force reasonable values */
  89.     utbound(l_row,u_row,last_row)
  90.     utbound(u_col,0,columns - 1)
  91.     utbound(l_col,u_col,columns - 1)
  92.     height = l_row - u_row + 1;
  93.     width  = l_col - u_col + 1;
  94.  
  95.     utabsptr(buffer,&buf_ads);
  96.     viads(u_row,u_col,&scn_ads);
  97.  
  98.     if (option & CHAR_ATTR)
  99.     command = 1;              /* (char,attr) pairs          */
  100.     else
  101.     if (fore == -1 && back == -1)
  102.         command = 0;          /* Preserve attributes          */
  103.     else
  104.         command = 2;          /* Use fore and back as          */
  105.                       /* constant attributes.          */
  106.  
  107.     if (   mode      == 7
  108.     || scequip() == IBM_CV
  109.     || device    == b_ega)
  110.     command |= 0x8000;          /* Need not await retrace       */
  111.  
  112.     vidirect(&buf_ads,&scn_ads,height,width,columns * 2,
  113.           utnybbyt(back,fore),command);
  114.     return height * width;
  115. }
  116.