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

  1. /**
  2. *
  3. * Name        viwrsect -- Write rectangular region directly to
  4. *                the current display page
  5. *
  6. * Synopsis    num_writ = viwrsect(u_row,u_col,l_row,l_col,
  7. *                    buffer,gap,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. *        const char *buffer
  16. *                Space containing the data to write
  17. *        unsigned gap    Gap (expressed in character cells)
  18. *                between successive rows in the buffer.
  19. *        int  fore    If CHARS_ONLY is specified, a value
  20. *                between 0 and 15 specifies a new
  21. *                foreground attribute,
  22. *                unless both fore and back are -1, in which
  23. *                case existing attributes are preserved.
  24. *        int  back    If CHARS_ONLY is specified, a value
  25. *                between 0 and 15 specifies a new
  26. *                background attribute,
  27. *                unless both fore and back are -1, in which
  28. *                case existing attributes are preserved.
  29. *        int  option    One bit in the option value tells VIWRSECT
  30. *                how the buffer is constructed.    The two
  31. *                possible values for this bit are:
  32. *
  33. *              Value        Meaning
  34. *              -----------   ------------------------------------
  35. *              CHARS_ONLY    Buffer contains characters only.
  36. *                    The values of fore and back are used
  37. *                    as attributes, unless they are both -1,
  38. *                    in which case the existing screen
  39. *                    attributes are left unchanged.
  40. *              CHAR_ATTR     Buffer contains (char,attr) pairs.
  41. *                    The values of fore and back are ignored.
  42. *
  43. * Description    This function fills a rectangular region on the current
  44. *        display page with characters from a buffer with or
  45. *        without their corresponding video attributes.  The data
  46. *        is written row by row.    The cursor is not moved.
  47. *
  48. *        In contrast to VIWRRECT, this function can handle a
  49. *        section of a buffer that represents a larger rectangular
  50. *        region.  For example, you can represent a rectangular
  51. *        region of characters by a contiguous buffer of bytes;
  52. *        this function can write a rectangular subsection of the
  53. *        buffer to the screen.  The "gap" argument indicates the
  54. *        number of character cells in the buffer to skip between
  55. *        rows written to the screen.
  56. *
  57. *        This function works only for standard text modes (0, 1,
  58. *        2, 3, and 7).
  59. *
  60. *        The upper left corner of the region is (u_row,u_col),
  61. *        where (0,0) represents the upper left corner of the
  62. *        entire screen.    The lower right corner of the region is
  63. *        (l_row,l_col), where (24,79) is the lower right corner
  64. *        of an 80-by-25 screen.
  65. *
  66. *        The returned value reports the number of "character
  67. *        cells" written, where "character cells" means the number
  68. *        of physical spaces on the screen.  (If CHAR_ATTR is
  69. *        specified, twice this number of bytes will be used from
  70. *        the buffer.)
  71. *
  72. *        Be aware that this function does NOT recognize NULs
  73. *        ('\0') or any other special characters.
  74. *
  75. * Returns    num_writ    Number of character cells written
  76. *
  77. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986,1987,1989
  78. *
  79. **/
  80.  
  81. #include <bscreens.h>
  82. #include <bvideo.h>
  83.  
  84. int viwrsect(u_row,u_col,l_row,l_col,buffer,gap,fore,back,option)
  85. int  u_row,u_col,l_row,l_col;
  86. const char *buffer;
  87. unsigned    gap;
  88. int  fore,back,option;
  89. {
  90.     int device,mode,act_page,last_row,columns;
  91.     int height,width;
  92.     int command;
  93.     const char far *pbuf;
  94.     char far *pscreen;
  95.  
  96.     device = scmode(&mode,&columns,&act_page);
  97.     if (mode > 3 && mode != 7)
  98.     return 0;
  99.     last_row = scrows() - 1;
  100.  
  101.     utbound(u_row,0,last_row)           /* Force reasonable values */
  102.     utbound(l_row,u_row,last_row)
  103.     utbound(u_col,0,columns - 1)
  104.     utbound(l_col,u_col,columns - 1)
  105.     height = l_row - u_row + 1;
  106.     width  = l_col - u_col + 1;
  107.  
  108.     pbuf    = buffer;
  109.     pscreen = viptr(u_row,u_col);
  110.  
  111.     if (option & CHAR_ATTR)
  112.     command = 14;              /* (char,attr) pairs          */
  113.     else
  114.     if (fore == -1 && back == -1)
  115.         command = 13;          /* Preserve attributes          */
  116.     else
  117.         command = 15;          /* Use fore and back as          */
  118.                       /* constant attributes.          */
  119.  
  120.     if (   b_vifast  != 0
  121.     || mode      == 7
  122.     || scequip() == IBM_CV
  123.     || device    == b_ega
  124.     || device    == b_vga
  125.     || device    == b_mcga)
  126.     command |= 0x8000;          /* Need not await retrace       */
  127.  
  128.     vidirec0(&pbuf,&pscreen,height,width,columns * 2,
  129.           utnybbyt(back,fore),command,gap);
  130.     return height * width;
  131. }
  132.