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

  1. /**
  2. *
  3. * Name        scrdrect -- Read contents of rectangular window
  4. *                from the current display page via BIOS
  5. *
  6. * Synopsis    num_read = scrdrect(u_row,u_col,l_row,l_col,buffer,option);
  7. *
  8. *        int  num_read    Number of character cells actually read
  9. *        int  u_row    Top row to read (0 = top of screen)
  10. *        int  u_col    Leftmost column to read (0 = left edge)
  11. *        int  l_row    Bottom row to read
  12. *        int  l_col    Rightmost column to read
  13. *        char *buffer    Space in which to put the data
  14. *        int  option    One bit in the option value tells
  15. *                SCRDRECT how the buffer is constructed.
  16. *                The two possible values for this bit are:
  17. *
  18. *              Value        Meaning
  19. *              -----------   ------------------------------------
  20. *              CHARS_ONLY    Buffer contains characters only.
  21. *              CHAR_ATTR     Buffer contains (char,attr) pairs.
  22. *
  23. * Description    This function reads the contents of a rectangular window
  24. *        on the current display page with or without the
  25. *        corresponding video attributes.  The cursor is not
  26. *        moved.    The data is read row by row.
  27. *
  28. *        The upper left corner of the window is (u_row,u_col),
  29. *        where (0,0) represents the upper left corner of the
  30. *        entire screen.    The lower right corner of the window is
  31. *        (l_row,l_col), where (24,79) is the lower right corner
  32. *        of an 80-by-25 screen.
  33. *
  34. *        The returned value reports the number of "character
  35. *        cells" read, where "character cells" means the number of
  36. *        physical spaces on the screen.    (If CHAR_ATTR is
  37. *        specified, twice this number of bytes will be returned
  38. *        in the buffer.)
  39. *
  40. *        If CHAR_ATTR is specified and the screen is in a
  41. *        graphics mode, then 1 will be returned as the attribute
  42. *        value regardless of the colors of the displayed
  43. *        characters.
  44. *
  45. *        Be aware that this function does NOT add a trailing NUL
  46. *        ('\0') at the end of the buffer, and that any 8-bit
  47. *        character may be present in the buffer, depending on
  48. *        what is in video memory.
  49. *
  50. *        Use VIRDRECT for greater speed in text modes.
  51. *
  52. * Returns    num_read    Number of character cells read
  53. *        *buffer     Characters read from the display page
  54. *                (perhaps with their attributes)
  55. *
  56. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  57. *
  58. **/
  59.  
  60. #include <bscreen.h>
  61.  
  62. int scrdrect(u_row,u_col,l_row,l_col,buffer,option)
  63. int  u_row,u_col,l_row,l_col;
  64. char *buffer;
  65. int  option;
  66. {
  67.     int mode,last_row,columns,act_page;
  68.     int want_attr,graphics;
  69.     int row,col,save_row,save_col;
  70.     int ax,bx,cx,dx,flags;          /* Registers for BIOS call      */
  71.     int cursor_was_on,top_scan,bot_scan;
  72.  
  73.     scmode(&mode,&columns,&act_page);
  74.     last_row = scrows() - 1;
  75.  
  76.     utbound(u_row,0,last_row)           /* Force reasonable values */
  77.     utbound(l_row,u_row,last_row)
  78.     utbound(u_col,0,columns - 1)
  79.     utbound(l_col,u_col,columns - 1)
  80.  
  81.     if (want_attr = ((option & CHAR_ATTR) != 0))
  82.     graphics = (mode > 3 && mode != 7);
  83.  
  84.                       /* Save cursor size & position. */
  85.     if (cursor_was_on = !sccurst(&save_row,&save_col,&top_scan,&bot_scan))
  86.                       /* Turn the cursor off          */
  87.     scpgcur(1,top_scan,bot_scan,CUR_NO_ADJUST);
  88.     bx = utbyword(b_curpage,0);
  89.     for (row = u_row; row <= l_row; row++)
  90.     for (col = u_col; col <= l_col; col++)
  91.     {
  92.         ax = utbyword(2,0);       /* Move cursor              */
  93.         dx = utbyword(row,col);
  94.         bios(16,&ax,&bx,&cx,&dx,&flags);
  95.  
  96.         ax = utbyword(8,0);       /* Read character & attribute   */
  97.         bios(16,&ax,&bx,&cx,&dx,&flags);
  98.         *buffer++ = (char) utlobyte(ax);
  99.         if (want_attr)
  100.         *buffer++ = (char) (graphics ? 1 : uthibyte(ax));
  101.     }
  102.  
  103.     sccurset(save_row,save_col);
  104.     if (cursor_was_on)              /* Restore cursor size.          */
  105.     scpgcur(0,top_scan,bot_scan,CUR_NO_ADJUST);
  106.     return (l_row - u_row + 1) * (l_col - u_col + 1);
  107. }
  108.