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

  1. /**
  2. *
  3. * Name        virdrect -- Read contents of rectangular region directly
  4. *                from the current display page
  5. *
  6. * Synopsis    num_read = virdrect(u_row,u_col,l_row,l_col,buffer,option);
  7. *
  8. *        int  num_read    Number of spaces actually read,
  9. *                or 0 if error.
  10. *        int  u_row    Top row to read (0 = top of screen)
  11. *        int  u_col    Leftmost column to read (0 = left edge)
  12. *        int  l_row    Bottom row to read
  13. *        int  l_col    Rightmost column to read
  14. *        char *buffer    Space in which to put the data
  15. *        int  option    One bit in the option value tells
  16. *                VIRDRECT how the buffer is constructed.
  17. *                The two possible values for this bit are:
  18. *
  19. *              Value        Meaning
  20. *              -----------   ------------------------------------
  21. *              CHARS_ONLY    Buffer contains characters only.
  22. *              CHAR_ATTR     Buffer contains (char,attr) pairs.
  23. *
  24. * Description    This function reads the contents of a rectangular region
  25. *        directly from the current display page with or without
  26. *        the corresponding video attributes.  The cursor is not
  27. *        moved.    The data is read row by row.
  28. *
  29. *        This function works only for standard text modes (0, 1,
  30. *        2, 3, and 7).  Use SCRDRECT for other modes.
  31. *
  32. *        The upper left corner of the region is (u_row,u_col),
  33. *        where (0,0) represents the upper left corner of the
  34. *        entire screen.    The lower right corner of the region is
  35. *        (l_row,l_col), where (24,79) is the lower right corner
  36. *        of an 80-by-25 screen.
  37. *
  38. *        Be aware that this function does NOT add a trailing NUL
  39. *        ('\0') at the end of the buffer, and that any 8-bit
  40. *        character may be present in the buffer, depending on
  41. *        what is in video memory.
  42. *
  43. * Returns    num_read    Number of character cells read,
  44. *                or 0 if error.
  45. *        *buffer     Characters read from the display page
  46. *                (perhaps with their attributes)
  47. *
  48. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  49. *
  50. **/
  51.  
  52. #include <bquery.h>
  53. #include <bscreen.h>
  54. #include <bvideo.h>
  55.  
  56. int virdrect(u_row,u_col,l_row,l_col,buffer,option)
  57. int  u_row,u_col,l_row,l_col;
  58. char *buffer;
  59. int  option;
  60. {
  61.     int device,mode,last_row,columns,act_page;
  62.     int height,width;
  63.     int command;
  64.     ADS buf_ads,scn_ads;
  65.  
  66.     device = scmode(&mode,&columns,&act_page);
  67.     if (mode > 3 && mode != 7)
  68.     return 0;
  69.     last_row = scrows() - 1;
  70.  
  71.     utbound(u_row,0,last_row)           /* Force reasonable values */
  72.     utbound(l_row,u_row,last_row)
  73.     utbound(u_col,0,columns - 1)
  74.     utbound(l_col,u_col,columns - 1)
  75.     height = l_row - u_row + 1;
  76.     width  = l_col - u_col + 1;
  77.  
  78.     utabsptr(buffer,&buf_ads);
  79.     viads(u_row,u_col,&scn_ads);
  80.  
  81.     command = ((option & CHAR_ATTR) ? 6 : 5);
  82.     if (   mode      == 7
  83.     || scequip() == IBM_CV
  84.     || device    == b_ega)
  85.     command |= 0x8000;          /* Need not await retrace       */
  86.  
  87.     vidirect(&scn_ads,&buf_ads,height,width,columns * 2,
  88.           0,command);
  89.     return height * width;
  90. }
  91.