home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name scwrite -- Writes copies of a character
- *
- * Synopsis iret = scwrite(ch,cnt);
- *
- * int iret Return value is always 0
- * char ch Character to write
- * unsigned cnt Number of copies of ch to write
- *
- * Description SCWRITE displays cnt copies of the character ch on the
- * current display screen without changing the
- * currently-set attribute. The characters are written on
- * the current page starting at the current cursor
- * position.
- *
- * This routine will not write more characters than will
- * fit on the screen, nor will it scroll the screen.
- *
- * SCATTRIB is preferable for graphics modes because it
- * allows control of the characters' color. SCWRITE uses
- * color 1 in graphics modes.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <bscreen.h>
-
- int scwrite(ch,cnt)
- char ch;
- unsigned cnt;
- {
- int ax,bx,cx,dx,flags;
- int mode,cols,act_page,last_row;
- int save_row,row,col;
- int cols_left,first_chunk,chunk;
-
- if (cnt == 0) /* BIOS treats 0 as 64K */
- return(0);
- else if (cnt == 1) /* Handle the usual case this way */
- { /* to save time */
- first_chunk = cnt;
- chunk = 0;
- }
- else
- { /* The general case */
- scmode(&mode,&cols,&act_page);
- last_row = scrows() - 1;
- sccurpos(&row,&col);
- save_row = row;
-
- cols_left = cols - col; /* Columns remaining in this row */
-
- /* Make sure we don't write beyond the end of this page */
-
- utuplim(cnt,cols_left + ((last_row - row) * cols));
-
- /* Divide the job into chunks: graphics mode can only write */
- /* one row at a time. */
-
- if ((mode < 3) || (mode == 7))
- { /* Text mode */
- first_chunk = cnt;
- chunk = 0;
- }
- else
- { /* Graphics mode */
- first_chunk = min(cnt,cols_left);
- chunk = cols;
- }
- }
-
- /* Write the first chunk: If text mode, this is the whole thing; */
- /* if graphics, this (at most) fills the current line. */
-
- ax = utbyword(10,ch);
- bx = utbyword(b_curpage,1); /* Use color 1 in case this is */
- /* graphics mode */
- cx = first_chunk;
- cnt -= first_chunk;
- bios(16,&ax,&bx,&cx,&dx,&flags);
-
- /* Write the remainder: if text mode, do nothing; if graphics, */
- /* write each of the remaining lines on the screen. */
-
- if (chunk != 0)
- {
- for (; cnt; cnt -= cx)
- {
- sccurset(++row,0);
- ax = utbyword(10,ch);
- cx = min(cnt,chunk);
- bios(16,&ax,&bx,&cx,&dx,&flags);
- }
- sccurset(save_row,col); /* Restore the original */
- /* cursor position */
- }
-
- return(0);
- }