home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name scrdbuf -- Read series of adjacent characters
- * from the current display page via BIOS
- *
- * Synopsis num_read = scrdbuf(row,col,num_spaces,buffer,option);
- *
- * int num_read Number of character cells actually read
- * int row,col Row and column at which to begin reading
- * int num_spaces Number of character cells to read.
- * char *buffer Space in which to put the data
- * int option The option value tells SCRDBUF how the
- * buffer is constructed and where to
- * position the cursor after the string has
- * been read. Three bits are relevant:
- *
- * Value Meaning
- * ----------- ------------------------------------
- * CUR_BEG Leave cursor at (row,col).
- * CUR_AFTER Leave cursor after end of string.
- *
- * CHARS_ONLY Buffer contains characters only.
- * CHAR_ATTR Buffer contains (char,attr) pairs.
- *
- * MOVE_CUR Leave cursor according to
- * CUR_BEG/CUR_AFTER bit.
- * NO_MOVE_CUR Preserve cursor location.
- *
- * Description This function reads adjacent characters from the current
- * display page with or without their corresponding video
- * attributes. It can leave the cursor at the beginning or
- * end of the space read or leave the cursor unmoved.
- *
- * The num_spaces argument specifies the number of
- * "character cells" to 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 num_spaces exceeds the
- * number of characters to the end of the line, the read
- * will continue on the following line, and so on to the
- * end of the screen. The read will stop at the end of the
- * screen, hence the number of cells actually read may be
- * less than num_spaces. The actual number is returned as
- * the value of the function.
- *
- * If the read includes the lower right corner of the
- * screen, then the cursor is left at the lower right
- * corner if both MOVE_CUR and CUR_AFTER are specified.
- *
- * If CHAR_ATTR is specified and the screen is in a
- * graphics mode, then 1 will be returned as the attribute
- * values 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.
- *
- * 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 scrdbuf(row,col,num_spaces,buffer,option)
- register int row,col;
- int num_spaces;
- char *buffer;
- int option;
- {
- int ax,bx,cx,dx,flags;
- int mode,last_row,columns,act_page;
- int want_attr,graphics;
- int save_row,save_col,save_num;
- int cursor_was_on,top_scan,bot_scan;
-
- scmode(&mode,&columns,&act_page);
- last_row = scrows() - 1;
-
- /* Force reasonable values */
-
- utbound(row,0,last_row)
- utbound(col,0,columns - 1)
- utuplim(num_spaces,columns - col + ((last_row - row) * columns))
- save_num = num_spaces;
-
- /* 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);
-
- if (0 == (option & NO_MOVE_CUR))
- {
- save_row = row; /* Beginning of string. */
- save_col = col;
- }
-
- sccurset(row,col);
- if (want_attr = ((option & CHAR_ATTR) != 0))
- graphics = (mode > 3 && mode != 7);
-
- bx = utbyword(b_curpage,0); /* This remains stable. */
-
- while (num_spaces--)
- {
- ax = utbyword(8,0); /* Read char & attribute */
- bios(16,&ax,&bx,&cx,&dx,&flags);
- *buffer++ = (char) utlobyte(ax); /* The data byte */
- if (want_attr) /* The attribute */
- *buffer++ = (char) (graphics ? 1
- : uthibyte(ax));
- if (++col >= columns)
- {
- col = 0;
- row++;
- }
- ax = utbyword(2,0); /* Set cursor position */
- dx = utbyword(row,col);
- bios(16,&ax,&bx,&cx,&dx,&flags);
- /* Cursor is left after each */
- /* character read. */
- }
-
- if ((option & NO_MOVE_CUR) || !(option & CUR_AFTER))
- sccurset(save_row,save_col); /* Restore cursor position */
- /* (either to previous location */
- /* or to beginning of string). */
-
- if (cursor_was_on) /* Restore cursor size. */
- scpgcur(0,top_scan,bot_scan,CUR_NO_ADJUST);
-
- return save_num;
- }