home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name scttywrt -- Write to screen using TTY format
- *
- * Synopsis iret = scttywrt(ch,fore);
- *
- * int iret Return value is always 0
- * char ch Character to display
- * int fore Foreground attribute to use if
- * screen mode is a graphics mode
- *
- * Description This function writes a character to the current page in
- * the usual TTY format. The active page need not be set
- * to the current page while writing.
- *
- * If the screen is in graphics mode, fore is used to set
- * the color of the characters written. Further, if the
- * current page is not active and the screen is scrolled,
- * fore is used as the color of the scrolled text. Fore is
- * ignored in text mode.
- *
- * If the screen is scrolled in text mode due to a line
- * feed character, the attribute for the new blank line is
- * taken from the character position last occupied before
- * the scroll. If the scroll is caused by overflowing the
- * last line of the screen, the attribute is taken from the
- * former attribute at column 0 of the last line.
- *
- * Special Line feed ('\012') causes the cursor to move down one
- * characters line, unless it is already on the bottom line of the
- * screen, in which case the screen is scrolled.
- *
- * Carriage return ('\015') causes the cursor to move to
- * column 0.
- *
- * Backspace ('\010') causes the cursor to move one column
- * to the left (non-destructively), unless it is already at
- * column 0, in which case nothing happens.
- *
- * The BEL character ('\007') causes the computer's bell to
- * sound if the current page is active.
- *
- * Returns iret Return value is always 0
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <bgenvid.h> /* This routine doesn't care */
- /* whether direct or BIOS */
- /* version of BGENVID.H is used.*/
- #include <bscreen.h>
-
- #define BEL '\7'
- #define BS '\8'
- #define LF '\12'
- #define CR '\15'
-
- int scttywrt(ch,fore)
- char ch;
- int fore;
- {
- int ax,bx,cx,dx,flags;
- int mode,columns,act_page,last_row;
- int row,col,back,graphics;
-
- scmode(&mode,&columns,&act_page);
-
- if (b_curpage == act_page)
- {
- ax = utbyword(14,ch);
- bx = utbyword(b_curpage,fore);
- bios(16,&ax,&bx,&cx,&dx,&flags);
- }
- else
- {
- sccurpos(&row,&col);
- graphics = (mode > 3 && mode != 7);
-
- switch (ch)
- {
- case BEL:
- break; /* Don't beep on nonactive page */
-
- case BS:
- if (col) /* Don't back up past column 0 */
- sccurset(row,col - 1);
- break;
-
- case CR:
- sccurset(row,0); /* Beginning of current line */
- break;
-
- default: /* First write the character */
- if (graphics)
- scattrib(fore,0,ch,1);
- else
- scwrite(ch,1);
- if (++col < columns) /* Check for possible wrap */
- { /* This fits on current line */
- sccurset(row,col);
- break;
- }
- /* Wrap to next line */
- sccurset(row,col = 0);
- case LF:
- if (row < (last_row = scrows() - 1))
- { /* No need to scroll */
- sccurset(row + 1,col);
- break;
- }
- /* Obtain attribute with which */
- /* to fill new bottom line. */
- if (!graphics)
- scread(&fore,&back); /* Use attribute from */
- /* previous cursor position */
-
- scpscrol(1,utnybbyt(back,fore), /* Scroll the screen */
- 0,0,last_row,columns - 1,SCR_UP);
- break;
- }
- }
- return(0);
- }