home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / SCWRRECT.C next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  6.0 KB  |  178 lines

  1. /**
  2. *
  3. * Name        scwrrect -- Write rectangular region on
  4. *                the current display page via BIOS
  5. *
  6. * Synopsis    num_writ = scwrrect(u_row,u_col,l_row,l_col,
  7. *                    buffer,fore,back,option);
  8. *
  9. *        int  num_writ    Number of character cells actually written
  10. *        int  u_row    Top row to write (0 = top of screen)
  11. *        int  u_col    Leftmost column to write (0 = left edge)
  12. *        int  l_row    Bottom row to write
  13. *        int  l_col    Rightmost column to write
  14. *        char *buffer    Space containing the data to write
  15. *        int  fore    -1 if existing foreground is to be
  16. *                preserved;
  17. *                if CHARS_ONLY is specified, a value
  18. *                between 0 and 15 specifies a new
  19. *                foreground attribute.
  20. *        int  back    -1 if existing background is to be
  21. *                preserved;
  22. *                if CHARS_ONLY is specified, a value
  23. *                between 0 and 15 specifies a new
  24. *                background attribute.
  25. *        int  option    One bit in the option value tells SCWRRECT
  26. *                how the buffer is constructed.    The two
  27. *                possible values for this bit are:
  28. *
  29. *              Value        Meaning
  30. *              -----------   ------------------------------------
  31. *              CHARS_ONLY    Buffer contains characters only.
  32. *                    The values of fore and back are used
  33. *                    as attributes.
  34. *              CHAR_ATTR     Buffer contains (char,attr) pairs.
  35. *                    The values of fore and back are
  36. *                    ignored unless they are -1.
  37. *
  38. * Description    This function fills a rectangular region on the current
  39. *        display page with characters from a buffer with or
  40. *        without their corresponding video attributes.  The data
  41. *        is written row by row.    The cursor is not moved.
  42. *
  43. *        The upper left corner of the region is (u_row,u_col),
  44. *        where (0,0) represents the upper left corner of the
  45. *        entire screen.    The lower right corner of the region is
  46. *        (l_row,l_col), where (24,79) is the lower right corner
  47. *        of an 80-by-25 screen.
  48. *
  49. *        The returned value reports the number of "character
  50. *        cells" written, where "character cells" means the number
  51. *        of physical spaces on the screen.  (If option CHAR_ATTR
  52. *        is specified, twice this number of bytes will be used
  53. *        from the buffer.)
  54. *
  55. *        If the screen is in a text mode, specifying -1 for fore
  56. *        or back preserves the existing foreground or background
  57. *        attributes, respectively.  This will occur regardless of
  58. *        the value of option.  If the screen is in a graphics
  59. *        mode and CHAR_ATTR is specified, then specifying -1 for
  60. *        fore will cause color 1 to be used.
  61. *
  62. *        Be aware that this function does NOT recognize NULs
  63. *        ('\0') or any other special characters.
  64. *
  65. *        Use VIWRRECT for greater speed in text modes.
  66. *
  67. * Returns    num_writ    Number of character cells written
  68. *
  69. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  70. *
  71. **/
  72.  
  73. #include <bscreen.h>
  74.  
  75. int scwrrect(u_row,u_col,l_row,l_col,buffer,fore,back,option)
  76. int  u_row,u_col,l_row,l_col;
  77. char *buffer;
  78. int  fore,back,option;
  79. {
  80.     int ax,bx,cx,dx,flags;
  81.     int mode,columns,act_page,last_row;
  82.     int row,col,save_row,save_col;
  83.     int want_attr,oldmask,newmask,old_attr,new_attr;
  84.     int cursor_was_on,top_scan,bot_scan;
  85.  
  86.     scmode(&mode,&columns,&act_page);
  87.     last_row = scrows() - 1;
  88.  
  89.     utbound(u_row,0,    last_row)     /* Force reasonable values      */
  90.     utbound(l_row,u_row,last_row)
  91.     utbound(u_col,0,    columns - 1)
  92.     utbound(l_col,u_col,columns - 1)
  93.  
  94.     /* Set various flags which will remain constant through the main  */
  95.     /* loop.                                  */
  96.  
  97.     if (mode > 3 && mode != 7)          /* Graphics mode:           */
  98.     {                      /* Ignore previous attributes   */
  99.     if (fore == -1)           /* since we can't read them.    */
  100.         fore = 1;
  101.     back     = 0;              /* Nonzero background causes    */
  102.                       /* trouble.              */
  103.     oldmask  = 0x00;          /* Ignore previous attributes.  */
  104.  
  105.     }
  106.     else                  /* Text mode:              */
  107.     {
  108.     if (fore == -1)           /* "oldmask" will help us       */
  109.         oldmask  = 0x0f;          /* extract the portion(s) of    */
  110.     else                  /* the previous attributes      */
  111.         oldmask  = 0x00;          /* which must be preserved.     */
  112.     if (back == -1)
  113.         oldmask |= 0xf0;
  114.     }
  115.  
  116.     newmask = 0xff & ~oldmask;          /* "newmask" will help us       */
  117.                       /* extract the relevant          */
  118.                       /* portion(s) of the new          */
  119.                       /* attributes              */
  120.  
  121.     new_attr = utnybbyt(back,fore) & newmask;
  122.     if (oldmask == 0x00)
  123.     old_attr = 0;
  124.     want_attr = ((option & CHAR_ATTR) != 0);
  125.     bx = utbyword(b_curpage,0);
  126.     cx = 1;
  127.  
  128.     /* Main loop                              */
  129.  
  130.                       /* Save cursor size & position. */
  131.     if (cursor_was_on = !sccurst(&save_row,&save_col,&top_scan,&bot_scan))
  132.                       /* Turn the cursor off          */
  133.     scpgcur(1,top_scan,bot_scan,CUR_NO_ADJUST);
  134.     for (row = u_row; row <= l_row; row++)
  135.     for (col = u_col; col <= l_col; col++)
  136.     {
  137.         ax = utbyword(2,0);       /* Move cursor to (row,col)     */
  138.         dx = utbyword(row,col);
  139.         bios(16,&ax,&bx,&cx,&dx,&flags);
  140.  
  141.         if (oldmask == 0xff)
  142.         {                  /* Ignoring old attribute       */
  143.         ax = utbyword(10,*buffer++);
  144.         if (want_attr)
  145.             buffer++;
  146.         bx = utbyword(b_curpage,0);
  147.         bios(16,&ax,&bx,&cx,&dx,&flags);
  148.         }
  149.         else
  150.         {                  /* Write character with          */
  151.                       /* attributes              */
  152.         if (oldmask)
  153.         {              /* Retrieve previous attributes */
  154.             ax = utbyword(8,0);
  155.             bios(16,&ax,&bx,&cx,&dx,&flags);
  156.             old_attr = uthibyte(ax) & oldmask;
  157.         }
  158.                       /* Now old_attr holds the       */
  159.                       /* portion of the previous      */
  160.                       /* attributes which we must     */
  161.                       /* preserve.              */
  162.  
  163.         ax = utbyword(9,*buffer++); /* Write char & attribute */
  164.         if (want_attr)
  165.             bx=utbyword(b_curpage,old_attr|((int)*buffer++&newmask));
  166.         else
  167.             bx=utbyword(b_curpage,old_attr|new_attr);
  168.  
  169.         bios(16,&ax,&bx,&cx,&dx,&flags);
  170.         }
  171.     }
  172.  
  173.     sccurset(save_row,save_col);
  174.     if (cursor_was_on)              /* Restore cursor size.          */
  175.     scpgcur(0,top_scan,bot_scan,CUR_NO_ADJUST);
  176.     return (l_row - u_row + 1) * (l_col - u_col + 1);
  177. }
  178.