home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / SCTTYWIN.C < prev    next >
Encoding:
Text File  |  1989-03-31  |  7.5 KB  |  242 lines

  1. /**
  2. *
  3. * Name        scttywin -- Write a character to a rectangular region
  4. *                on the current display page via BIOS,
  5. *                TTY-style.
  6. *
  7. * Synopsis    scttywin(u_row,u_col,l_row,l_col,
  8. *              ch,fore,back,scr_fore,scr_back);
  9. *
  10. *        int  u_row    Top row of region (0 = top of screen)
  11. *        int  u_col    Leftmost column of region (0 = left edge)
  12. *        int  l_row    Bottom row of region
  13. *        int  l_col    Rightmost column of region
  14. *        char ch     Character to write
  15. *        int  fore    -1 if existing foreground is to be
  16. *                preserved; a value between 0 and 15
  17. *                specifies a new foreground attribute.
  18. *        int  back    -1 if existing background is to be
  19. *                preserved; a value between 0 and 15
  20. *                specifies a new background attribute.
  21. *        int  scr_fore    Foreground attribute of blank lines
  22. *                added when scrolling (-1 to use
  23. *                foreground attribute of character
  24. *                position before scroll).
  25. *        int  scr_back    Background attribute of blank lines
  26. *                added when scrolling (-1 to use
  27. *                background attribute of character
  28. *                position before scroll).
  29. *
  30. * Description    This function writes a character to a rectangular region
  31. *        on the current display page in the manner of a teletype.
  32. *        It treats carriage return, line feed, backspace, and
  33. *        bell as commands rather than as printable characters.
  34. *        All output and scrolling are confined to the region.
  35. *
  36. *        If the cursor is currently within the region, the
  37. *        character is written at that point.  If the cursor is
  38. *        not within the region, the character is written at the
  39. *        upper left corner of the region.  The cursor is left
  40. *        after the displayed character.
  41. *
  42. *        If the screen is in a text mode, specifying -1 for fore
  43. *        or back preserves the existing foreground or background
  44. *        attributes, respectively.  This will occur regardless of
  45. *        the value of option.  If the screen is in a graphics
  46. *        mode, then specifying -1 for fore will cause color 1 to
  47. *        be used.
  48. *
  49. *        The region is scrolled if a line feed occurs on the last
  50. *        row of the region or if the last row is overflowed,
  51. *        except that scrolling will not take place on an inactive
  52. *        page in graphics mode.
  53. *
  54. *        If the screen is scrolled in text mode due to a line
  55. *        feed character and scr_fore or scr_back is -1, then the
  56. *        foreground or background attribute(s) (respectively) for
  57. *        the new blank row are taken from the character position
  58. *        last occupied before the scroll.  If the scroll is
  59. *        caused by overflowing the last row of the region and
  60. *        scr_fore or scr_back is -1, the respective attribute(s)
  61. *        are taken from the former attribute at the leftmost
  62. *        column of the bottom row.  Otherwise the value of
  63. *        scr_fore or scr_back is used.  (When scr_fore and
  64. *        scr_back are both -1, this uses the same convention as
  65. *        SCTTYWRT.)
  66. *
  67. *        If the screen is scrolled in a graphics mode, the
  68. *        scrolled text is given the color specified by scr_fore,
  69. *        unless scr_fore is -1, in which case color 1 is used.
  70. *
  71. * Limitation    This function will not scroll the region in graphics
  72. *        mode if the current page is not active.
  73. *
  74. * Example    This statement:
  75. *
  76. *            scttywrt(ch,fore);
  77. *
  78. *        is equivalent to the following in text modes:
  79. *
  80. *            scttywin(0,0,PC_BIG_ROWS,PC_COLS,
  81. *                 ch,-1,-1,-1,-1);
  82. *
  83. *        and to the following in graphics modes (if the current
  84. *        page is active):
  85. *
  86. *            scttywin(0,0,PC_BIG_ROWS,PC_COLS,
  87. *                 ch,fore,-1,fore,-1);
  88. *
  89. *        provided that fore is not -1.
  90. *
  91. * Special    Tab characters ('\t') are displayed literally.
  92. * characters
  93. *        NUL ('\0') is a printable character (printed as a blank
  94. *        space).
  95. *
  96. *        Line feed ('\12') causes the cursor to move down one
  97. *        row, unless it is already on the bottom row of the
  98. *        region, in which case the screen is scrolled.
  99. *
  100. *        Carriage return ('\r') causes the cursor to move to the
  101. *        leftmost column of the region.
  102. *
  103. *        Backspace ('\b') causes the cursor to move one column to
  104. *        the left (non-destructively), unless it is already at
  105. *        the leftmost column of the region, in which case nothing
  106. *        happens.
  107. *
  108. *        The BEL character ('\7') causes the computer's bell to
  109. *        sound if the current page is active.
  110. *
  111. * Returns    (None.    Function return type is void.)
  112. *
  113. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986-1989
  114. *
  115. **/
  116.  
  117. #include <dos.h>
  118.  
  119. #include <bscreens.h>
  120. #include <bvideo.h>
  121.  
  122. #define  BEL     '\7'
  123. #define  BS     '\b'
  124. #define  CR     '\r'
  125. #define  LF     '\12'
  126.  
  127. void scttywin(u_row,u_col,l_row,l_col,ch,fore,back,scr_fore,scr_back)
  128. int  u_row,u_col,l_row,l_col;
  129. char ch;
  130. int  fore,back,scr_fore,scr_back;
  131. {
  132.     union REGS inregs,outregs;          /* Registers for BIOS calls     */
  133.     int  mode,act_page,columns,last_row;
  134.     int  oldmask,old_attr;
  135.     int  high,low,row,col;
  136.  
  137.     scmode(&mode,&columns,&act_page);
  138.     last_row = scrows() - 1;
  139.     last_row--;
  140.  
  141.     utbound(u_row,0,last_row)          /* Force reasonable values      */
  142.     utbound(u_col,0,columns - 1)
  143.     utbound(l_row,u_row,last_row)
  144.     utbound(l_col,u_col,columns - 1)
  145.  
  146.     sccurst(&row,&col,&high,&low);
  147.     if (utrange(row,u_row,l_row) || utrange(col,u_col,l_col))
  148.     sccurset((row = u_row),(col = u_col));
  149.  
  150.     switch (ch)
  151.     {
  152.     case BEL:
  153.         if (b_curpage == act_page)
  154.         scttywrt(ch,0);       /* Don't beep on inactive page  */
  155.         break;
  156.  
  157.     case BS:
  158.         if (col > u_col)          /* Don't back up past first     */
  159.         sccurset(row,col - 1);          /* column          */
  160.         break;
  161.  
  162.     case CR:
  163.         sccurset(row,u_col);      /* Beginning of current line    */
  164.         break;
  165.  
  166.     default:              /* First write the character    */
  167.  
  168.         if (fore == -1)          /* "oldmask" will help us       */
  169.         oldmask  = 0x0f;      /* extract the portion(s) of    */
  170.         else              /* the previous attributes      */
  171.         oldmask  = 0x00;      /* which must be preserved.     */
  172.         if (back == -1)
  173.         oldmask |= 0xf0;
  174.  
  175.         if (oldmask == 0xff)
  176.         {                  /* Write character only          */
  177.         inregs.h.ah = 10;
  178.         inregs.h.al = ch;
  179.         inregs.h.bh = (unsigned char) b_curpage;
  180.         }
  181.         else
  182.         {                  /* Write character with          */
  183.                       /* attributes              */
  184.         if (oldmask != 0x00)
  185.         {
  186.             inregs.h.ah = 8;
  187.             inregs.h.bh = (unsigned char) b_curpage;
  188.             int86(16,&inregs,&outregs);
  189.             old_attr = outregs.h.ah & oldmask;
  190.         }
  191.         else
  192.             old_attr = 0;
  193.  
  194.         inregs.h.ah = 9;
  195.         inregs.h.al = ch;
  196.         inregs.h.bh = (unsigned char) b_curpage;
  197.         inregs.h.bl = (unsigned char) (old_attr |
  198.                   (utnybbyt(back,fore) & ~oldmask));
  199.         }
  200.         inregs.x.cx = 1;
  201.         int86(16,&inregs,&outregs);  /* Actually write it          */
  202.  
  203.         inregs.h.ah = 2;
  204.         inregs.h.bh = (unsigned char) b_curpage;
  205.         if (++col <= l_col)       /* Check for possible wrap      */
  206.         {                  /* This fits on current line    */
  207.         inregs.h.dh = (unsigned char) row;
  208.         inregs.h.dl = (unsigned char) col;
  209.         int86(16,&inregs,&outregs);
  210.         break;
  211.         }
  212.                       /* Wrap to next line          */
  213.         col = u_col;
  214.         inregs.h.dh = (unsigned char) row;
  215.         inregs.h.dl = (unsigned char) col;
  216.         int86(16,&inregs,&outregs);
  217.     case LF:
  218.         if (row < l_row)
  219.         {                  /* No need to scroll          */
  220.         sccurset(row + 1,col);
  221.         break;
  222.         }
  223.                       /* Obtain attribute with which  */
  224.                       /* to fill new bottom line.     */
  225.  
  226.         scread(&fore,&back);      /* Obtain attribute from    */
  227.                       /* previous cursor position */
  228.         if (scr_fore == -1)
  229.         scr_fore = fore;
  230.         if (scr_back == -1)
  231.         scr_back = back;
  232.  
  233.                       /* Scroll up.              */
  234.         viscroll(1,
  235.              utnybbyt(scr_back,scr_fore),
  236.              u_row,u_col,
  237.              l_row,l_col,
  238.              SCR_UP);
  239.         break;
  240.     }
  241. }
  242.