home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / SCTTYWRT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  3.5 KB  |  125 lines

  1. /**
  2. *
  3. * Name        scttywrt -- Write to screen using TTY format
  4. *
  5. * Synopsis    iret = scttywrt(ch,fore);
  6. *
  7. *        int  iret      Return value is always 0
  8. *        char ch       Character to display
  9. *        int  fore      Foreground attribute to use if
  10. *                  screen mode is a graphics mode
  11. *
  12. * Description    This function writes a character to the current page in
  13. *        the usual TTY format.  The active page need not be set
  14. *        to the current page while writing.
  15. *
  16. *        If the screen is in graphics mode, fore is used to set
  17. *        the color of the characters written.  Further, if the
  18. *        current page is not active and the screen is scrolled,
  19. *        fore is used as the color of the scrolled text.  Fore is
  20. *        ignored in text mode.
  21. *
  22. *        If the screen is scrolled in text mode due to a line
  23. *        feed character, the attribute for the new blank line is
  24. *        taken from the character position last occupied before
  25. *        the scroll.  If the scroll is caused by overflowing the
  26. *        last line of the screen, the attribute is taken from the
  27. *        former attribute at column 0 of the last line.
  28. *
  29. * Special    Line feed ('\012') causes the cursor to move down one
  30. * characters    line, unless it is already on the bottom line of the
  31. *        screen, in which case the screen is scrolled.
  32. *
  33. *        Carriage return ('\015') causes the cursor to move to
  34. *        column 0.
  35. *
  36. *        Backspace ('\010') causes the cursor to move one column
  37. *        to the left (non-destructively), unless it is already at
  38. *        column 0, in which case nothing happens.
  39. *
  40. *        The BEL character ('\007') causes the computer's bell to
  41. *        sound if the current page is active.
  42. *
  43. * Returns    iret          Return value is always 0
  44. *
  45. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  46. *
  47. **/
  48.  
  49. #include <bgenvid.h>              /* This routine doesn't care    */
  50.                       /* whether direct or BIOS       */
  51.                       /* version of BGENVID.H is used.*/
  52. #include <bscreen.h>
  53.  
  54. #define  BEL        '\7'
  55. #define  BS        '\8'
  56. #define  LF        '\12'
  57. #define  CR        '\15'
  58.  
  59. int scttywrt(ch,fore)
  60. char ch;
  61. int  fore;
  62. {
  63.     int ax,bx,cx,dx,flags;
  64.     int mode,columns,act_page,last_row;
  65.     int row,col,back,graphics;
  66.  
  67.     scmode(&mode,&columns,&act_page);
  68.  
  69.     if (b_curpage == act_page)
  70.     {
  71.     ax = utbyword(14,ch);
  72.     bx = utbyword(b_curpage,fore);
  73.     bios(16,&ax,&bx,&cx,&dx,&flags);
  74.     }
  75.     else
  76.     {
  77.     sccurpos(&row,&col);
  78.     graphics = (mode > 3 && mode != 7);
  79.  
  80.     switch (ch)
  81.     {
  82.         case BEL:
  83.         break;              /* Don't beep on nonactive page */
  84.  
  85.         case BS:
  86.         if (col)          /* Don't back up past column 0  */
  87.             sccurset(row,col - 1);
  88.         break;
  89.  
  90.         case CR:
  91.         sccurset(row,0);      /* Beginning of current line    */
  92.         break;
  93.  
  94.         default:              /* First write the character    */
  95.         if (graphics)
  96.             scattrib(fore,0,ch,1);
  97.         else
  98.             scwrite(ch,1);
  99.         if (++col < columns)  /* Check for possible wrap      */
  100.         {              /* This fits on current line    */
  101.             sccurset(row,col);
  102.             break;
  103.         }
  104.                       /* Wrap to next line          */
  105.         sccurset(row,col = 0);
  106.         case LF:
  107.         if (row < (last_row = scrows() - 1))
  108.         {              /* No need to scroll          */
  109.             sccurset(row + 1,col);
  110.             break;
  111.         }
  112.                       /* Obtain attribute with which  */
  113.                       /* to fill new bottom line.     */
  114.         if (!graphics)
  115.             scread(&fore,&back);  /* Use attribute from       */
  116.                       /* previous cursor position */
  117.  
  118.         scpscrol(1,utnybbyt(back,fore),  /* Scroll the screen */
  119.                  0,0,last_row,columns - 1,SCR_UP);
  120.         break;
  121.     }
  122.     }
  123.     return(0);
  124. }
  125.