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

  1. /**
  2. *
  3. * Name        scattrib -- Write copies of a character on the current
  4. *            display page with the specified display attribute.
  5. *
  6. * Synopsis    iret = scattrib(fore,back,ch,cnt);
  7. *
  8. *        int iret      Return value is always 0
  9. *        int fore      Foreground display attribute
  10. *        int back      Background display attribute
  11. *        char ch       Character to be displayed
  12. *        unsigned cnt      Number of copies of ch to be
  13. *                  displayed.
  14. *
  15. * Description    This function displays cnt copies of the character ch
  16. *        starting at the current cursor position.  The cursor is
  17. *        not moved.  The copies are displayed with attributes
  18. *        (fore, back) on the current page (b_curpage).
  19. *
  20. *        This routine will not write more characters than will
  21. *        fit on the screen, nor will it scroll the screen.
  22. *
  23. * Version    3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
  24. *
  25. **/
  26.  
  27. #include <bscreen.h>
  28.  
  29. int scattrib(fore,back,ch,cnt)
  30. int     fore;
  31. int     back;
  32. char     ch;
  33. unsigned cnt;
  34. {
  35.     int ax,bx,cx,dx,flags;        /* General registers        */
  36.     int mode,cols,act_page;
  37.     int save_row,row,col;
  38.     int cols_left,first_chunk,chunk;
  39.  
  40.     if (cnt == 0)          /* BIOS treats 0 as 64K              */
  41.     return(0);
  42.     else if (cnt == 1)          /* Handle the usual case this way       */
  43.     {                  /* to save time                  */
  44.     first_chunk = cnt;
  45.     chunk        = 0;
  46.     }
  47.     else
  48.     {                     /* The general case          */
  49.     scmode(&mode,&cols,&act_page);
  50.     sccurpos(&row,&col);
  51.     save_row = row;
  52.  
  53.     cols_left = cols - col;      /* Columns remaining in this row */
  54.  
  55.     /* Make sure we don't write beyond the end of this page           */
  56.  
  57.     utuplim(cnt,cols_left + ((scrows() - 1 - row) * cols));
  58.  
  59.     /* Divide the job into chunks:  graphics mode can only write      */
  60.     /* one row at a time.                          */
  61.  
  62.     if ((mode < 3) || (mode == 7))
  63.     {                    /* Text mode          */
  64.         first_chunk = cnt;
  65.         chunk    = 0;
  66.     }
  67.     else
  68.     {                    /* Graphics mode          */
  69.         first_chunk = min(cnt,cols_left);
  70.         chunk    = cols;
  71.     }
  72.     }
  73.  
  74.     /* Write the first chunk:  If text mode, this is the whole thing; */
  75.     /* if graphics, this (at most) fills the current line.          */
  76.  
  77.     ax     = utbyword(9,ch);
  78.     bx     = utbyword(b_curpage,utnybbyt(back,fore));
  79.     cx     = first_chunk;
  80.     cnt -= first_chunk;
  81.     bios(16,&ax,&bx,&cx,&dx,&flags);
  82.  
  83.     /* Write the remainder:  if text mode, do nothing; if graphics,   */
  84.     /* write each of the remaining lines on the screen.           */
  85.  
  86.     if (chunk != 0)
  87.     {
  88.     for (; cnt; cnt -= cx)
  89.     {
  90.         sccurset(++row,0);
  91.         ax = utbyword(9,ch);
  92.         cx = min(cnt,chunk);
  93.         bios(16,&ax,&bx,&cx,&dx,&flags);
  94.     }
  95.     sccurset(save_row,col);     /* Restore the original       */
  96.                     /* cursor position          */
  97.     }
  98.  
  99.     return(0);
  100. }
  101.