home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name scrdrect -- Read contents of rectangular window
- * from the current display page via BIOS
- *
- * Synopsis num_read = scrdrect(u_row,u_col,l_row,l_col,buffer,option);
- *
- * int num_read Number of character cells actually read
- * int u_row Top row to read (0 = top of screen)
- * int u_col Leftmost column to read (0 = left edge)
- * int l_row Bottom row to read
- * int l_col Rightmost column to read
- * char *buffer Space in which to put the data
- * int option One bit in the option value tells
- * SCRDRECT how the buffer is constructed.
- * The two possible values for this bit are:
- *
- * Value Meaning
- * ----------- ------------------------------------
- * CHARS_ONLY Buffer contains characters only.
- * CHAR_ATTR Buffer contains (char,attr) pairs.
- *
- * Description This function reads the contents of a rectangular window
- * on the current display page with or without the
- * corresponding video attributes. The cursor is not
- * moved. The data is read row by row.
- *
- * The upper left corner of the window is (u_row,u_col),
- * where (0,0) represents the upper left corner of the
- * entire screen. The lower right corner of the window is
- * (l_row,l_col), where (24,79) is the lower right corner
- * of an 80-by-25 screen.
- *
- * The returned value reports the number of "character
- * cells" read, where "character cells" means the number of
- * physical spaces on the screen. (If CHAR_ATTR is
- * specified, twice this number of bytes will be returned
- * in the buffer.)
- *
- * If CHAR_ATTR is specified and the screen is in a
- * graphics mode, then 1 will be returned as the attribute
- * value regardless of the colors of the displayed
- * characters.
- *
- * Be aware that this function does NOT add a trailing NUL
- * ('\0') at the end of the buffer, and that any 8-bit
- * character may be present in the buffer, depending on
- * what is in video memory.
- *
- * Use VIRDRECT for greater speed in text modes.
- *
- * Returns num_read Number of character cells read
- * *buffer Characters read from the display page
- * (perhaps with their attributes)
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <bscreen.h>
-
- int scrdrect(u_row,u_col,l_row,l_col,buffer,option)
- int u_row,u_col,l_row,l_col;
- char *buffer;
- int option;
- {
- int mode,last_row,columns,act_page;
- int want_attr,graphics;
- int row,col,save_row,save_col;
- int ax,bx,cx,dx,flags; /* Registers for BIOS call */
- int cursor_was_on,top_scan,bot_scan;
-
- scmode(&mode,&columns,&act_page);
- last_row = scrows() - 1;
-
- utbound(u_row,0,last_row) /* Force reasonable values */
- utbound(l_row,u_row,last_row)
- utbound(u_col,0,columns - 1)
- utbound(l_col,u_col,columns - 1)
-
- if (want_attr = ((option & CHAR_ATTR) != 0))
- graphics = (mode > 3 && mode != 7);
-
- /* Save cursor size & position. */
- if (cursor_was_on = !sccurst(&save_row,&save_col,&top_scan,&bot_scan))
- /* Turn the cursor off */
- scpgcur(1,top_scan,bot_scan,CUR_NO_ADJUST);
- bx = utbyword(b_curpage,0);
- for (row = u_row; row <= l_row; row++)
- for (col = u_col; col <= l_col; col++)
- {
- ax = utbyword(2,0); /* Move cursor */
- dx = utbyword(row,col);
- bios(16,&ax,&bx,&cx,&dx,&flags);
-
- ax = utbyword(8,0); /* Read character & attribute */
- bios(16,&ax,&bx,&cx,&dx,&flags);
- *buffer++ = (char) utlobyte(ax);
- if (want_attr)
- *buffer++ = (char) (graphics ? 1 : uthibyte(ax));
- }
-
- sccurset(save_row,save_col);
- if (cursor_was_on) /* Restore cursor size. */
- scpgcur(0,top_scan,bot_scan,CUR_NO_ADJUST);
- return (l_row - u_row + 1) * (l_col - u_col + 1);
- }