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

  1. /**
  2. *
  3. * Name        virdsect -- Read contents of rectangular region directly
  4. *                from the current display page
  5. *
  6. * Synopsis    num_read = virdsect(u_row,u_col,l_row,l_col,buffer,gap,
  7. *                    option);
  8. *
  9. *        int  num_read    Number of spaces actually read,
  10. *                or 0 if error.
  11. *        int  u_row    Top row to read (0 = top of screen)
  12. *        int  u_col    Leftmost column to read (0 = left edge)
  13. *        int  l_row    Bottom row to read
  14. *        int  l_col    Rightmost column to read
  15. *        char *buffer    Space in which to put the data
  16. *        unsigned gap    Gap (expressed in character cells)
  17. *                between successive rows in the buffer.
  18. *        int  option    One bit in the option value tells
  19. *                VIRDSECT how the buffer is constructed.
  20. *                The two possible values for this bit are:
  21. *
  22. *              Value        Meaning
  23. *              -----------   ------------------------------------
  24. *              CHARS_ONLY    Buffer contains characters only.
  25. *              CHAR_ATTR     Buffer contains (char,attr) pairs.
  26. *
  27. * Description    This function reads the contents of a rectangular region
  28. *        directly from the current display page with or without
  29. *        the corresponding video attributes.  The cursor is not
  30. *        moved.    The data is read row by row.
  31. *
  32. *        In contrast to VIRDRECT, this function can handle a
  33. *        section of a buffer that represents a larger rectangular
  34. *        region.  For example, you can represent a rectangular
  35. *        region of characters by a contiguous buffer of bytes;
  36. *        this function can read a rectangular subsection of the
  37. *        buffer from the screen.  The "gap" argument indicates
  38. *        the number of character cells in the buffer to skip
  39. *        between rows read from the screen.
  40. *
  41. *        This function works only for standard text modes (0, 1,
  42. *        2, 3, and 7).
  43. *
  44. *        The upper left corner of the region is (u_row,u_col),
  45. *        where (0,0) represents the upper left corner of the
  46. *        entire screen.    The lower right corner of the region is
  47. *        (l_row,l_col), where (24,79) is the lower right corner
  48. *        of an 80-by-25 screen.
  49. *
  50. *        Be aware that this function does NOT add a trailing NUL
  51. *        ('\0') at the end of the buffer, and that any 8-bit
  52. *        character may be present in the buffer, depending on
  53. *        what is in video memory.
  54. *
  55. * Returns    num_read    Number of character cells read,
  56. *                or 0 if error.
  57. *        *buffer     Characters read from the display page
  58. *                (perhaps with their attributes)
  59. *
  60. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986,1987,1989
  61. *
  62. **/
  63.  
  64. #include <bscreens.h>
  65. #include <bvideo.h>
  66.  
  67. int virdsect(u_row,u_col,l_row,l_col,buffer,gap,option)
  68. int  u_row,u_col,l_row,l_col;
  69. char *buffer;
  70. unsigned gap;
  71. int  option;
  72. {
  73.     int device,mode,act_page,last_row,columns;
  74.     int height,width;
  75.     int command;
  76.     char far *pbuf;
  77.     const char far *pscreen;
  78.  
  79.     device = scmode(&mode,&columns,&act_page);
  80.     if (mode > 3 && mode != 7)
  81.     return 0;
  82.     last_row = scrows() - 1;
  83.  
  84.     utbound(u_row,0,last_row)           /* Force reasonable values */
  85.     utbound(l_row,u_row,last_row)
  86.     utbound(u_col,0,columns - 1)
  87.     utbound(l_col,u_col,columns - 1)
  88.     height = l_row - u_row + 1;
  89.     width  = l_col - u_col + 1;
  90.  
  91.     pbuf    = buffer;
  92.     pscreen = viptr(u_row,u_col);
  93.  
  94.     command = ((option & CHAR_ATTR) ? 17 : 16);
  95.     if (   b_vifast  != 0
  96.     || mode      == 7
  97.     || scequip() == IBM_CV
  98.     || device    == b_ega
  99.     || device    == b_vga
  100.     || device    == b_mcga)
  101.     command |= 0x8000;          /* Need not await retrace       */
  102.  
  103.     vidirec0(&pscreen,&pbuf,height,width,columns * 2,
  104.           0,command,gap);
  105.     return height * width;
  106. }
  107.