home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name wnwrtty -- Write a character to current window TTY-style.
- *
- * Synopsis wnwrtty(ch,fore,back);
- *
- * char ch Character to write
- * int fore -1 if default foreground attribute is to
- * be used; a value between 0 and 15
- * specifies a new foreground attribute.
- * int back -1 if default background attribute is to
- * be used; a value between 0 and 15
- * specifies a new background attribute.
- *
- * Description This function writes a character to the window in the
- * manner of a teletype. It treats carriage return, line
- * feed, backspace, and bell as commands rather than as
- * printable characters. All output and scrolling are
- * confined to the window.
- *
- * The window's cursor is left after the displayed
- * character. The visible cursor is not moved unless this
- * window is currently selected (via WNCURSOR) to have this
- * page's active cursor.
- *
- * The window is scrolled if a line feed occurs on the last
- * line of the window or if the last line is overflowed.
- * The window's native attributes are used for the new
- * blank row.
- *
- * If the screen is in a text mode, specifying -1 for fore
- * or back uses the window's default foreground or
- * background attributes, respectively. If the screen is
- * in a graphics mode, then specifying -1 for fore will
- * cause color 1 to be used.
- *
- * Special Tab characters ('\t') are displayed literally.
- * characters
- * NUL ('\0') is a printable character (printed as a blank
- * space).
- *
- * Line feed ('\12') causes the cursor to move down one
- * row, unless it is already on the bottom row of the
- * window, in which case the window is scrolled.
- *
- * Carriage return ('\r') causes the cursor to move to the
- * leftmost column of the window.
- *
- * Backspace ('\b') causes the cursor to move one column to
- * the left (non-destructively), unless it is already at
- * the leftmost column of the window, in which case nothing
- * happens.
- *
- * The BEL character ('\7') causes the computer's bell to
- * sound if the current page is active.
- *
- * Returns (Function return type is void.)
- * b_wnerr Possible values:
- * (No change) Success.
- * WN_BAD_WIN No window designated
- * as current.
- * WN_ILL_DIM Internal error.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- * Version 3.02 March 23, 1987
- * Forced WNUPDATE before modifying screen.
- *
- **/
-
- #include <bwindow.h>
-
- #if MSC300
- #include <memory.h>
- #else
- #include <stdlib.h>
- #endif
-
- #define BEL '\7'
- #define BS '\b'
- #define CR '\r'
- #define LF '\12'
-
- void wnwrtty(ch,fore,back)
- char ch;
- int fore,back;
- {
- int row,col;
- int ax,bx,cx,dx,flags;
- int old_curpos;
- int scr_fore,scr_back;
- char scr_attr;
- int h,w,i;
- CELL *ptr;
-
- if (wnvalwin(b_pcurwin) == NIL)
- {
- wnerror(WN_BAD_WIN);
- return;
- }
-
- wncurpos(&row,&col);
-
- switch (ch)
- {
- case BEL:
- scttywrt(ch,0);
- break;
-
- case BS:
- if (col > 0) /* Don't back up past first */
- wncurmov(row,col - 1); /* column */
- break;
-
- case CR:
- wncurmov(row,0); /* Beginning of current line */
- break;
-
- default: /* Includes the case of LF. */
-
- scr_fore = utlonyb(b_pcurwin->attr);
- if (fore == -1)
- fore = scr_fore;
- scr_back = uthinyb(b_pcurwin->attr);
- if (back == -1)
- back = scr_back;
-
- h = b_pcurwin->img.dim.h;
- w = b_pcurwin->img.dim.w;
-
- /* Update the physical screen if possible. */
-
- if ( b_pcurwin->where_shown.dev != MONO
- && b_pcurwin->where_shown.dev != COLOR)
- { /* Not shown anywhere. */
- b_pcurwin->internals.dirty = 1;
- }
- else if (b_pcurwin->options.hidden)
- {
- /* Do nothing if hidden. */
- }
- else if ( b_pcurwin->options.delayed
- || b_pcurwin->internals.frozen)
- { /* Displayed, but can't */
- b_pcurwin->internals.dirty = 1; /* be written to. */
- }
- else
- { /* Update the screen */
-
- wnupdate(b_pcurwin); /* Flush pending output. */
-
- /* Get former cursor position. */
- ax = 0x0300;
- bx = utbyword(b_curpage,0);
- bios(16,&ax,&bx,&cx,&old_curpos,&flags);
-
- /* Move cursor for this window. */
- ax = 0x0200;
- bx = utbyword(b_curpage,0);
- dx = utbyword(b_pcurwin->where_shown.corner.row + row,
- b_pcurwin->where_shown.corner.col + col);
- bios(16,&ax,&bx,&cx,&dx,&flags);
-
- /* Write the character. */
- scttywin(b_pcurwin->where_shown.corner.row,
- b_pcurwin->where_shown.corner.col,
- b_pcurwin->where_shown.corner.row + h - 1,
- b_pcurwin->where_shown.corner.col + w - 1,
- ch,fore,back,scr_fore,scr_back);
-
- /* Restore cursor position. */
- ax = 0x0200;
- bx = utbyword(b_curpage,0);
- dx = old_curpos;
- bios(16,&ax,&bx,&cx,&dx,&flags);
- }
-
- /* Update the memory copy of the window's data area. */
-
- if (ch != LF)
- { /* Ordinary character */
- (b_pcurwin->img.pdata + (row * w) + col)->ch = ch;
- (b_pcurwin->img.pdata + (row * w) + col)->attr
- = (char) utnybbyt(back,fore);
-
- if (++col < w) /* Check for possible wrap */
- { /* This fits on current line */
- wncurmov(row,col);
- break;
- }
- col = 0; /* Wrap to next line */
- }
-
- if (++row >= h) /* Scroll the memory image up */
- { /* one line. */
- row = h - 1;
- memcpy((char *) b_pcurwin->img.pdata,
- (char *) (b_pcurwin->img.pdata + w),
- (unsigned int) (w * sizeof(CELL) * row));
-
- /* Fill last row of memory */
- /* image with blanks. */
- scr_attr = (char) b_pcurwin->attr;
- ptr = b_pcurwin->img.pdata + (row * w);
- for (i = 0; i < w; i++)
- {
- ptr[i].ch = ' ';
- ptr[i].attr = scr_attr;
- }
- }
-
- wncurmov(row,col); /* Move cursor to beginning of */
- /* new bottom line. */
- break;
- }
- }