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

  1. /**
  2. *
  3. * Name        scwrite -- Writes copies of a character
  4. *
  5. * Synopsis    iret = scwrite(ch,cnt);
  6. *
  7. *        int  iret      Return value is always 0
  8. *        char ch       Character to write
  9. *        unsigned cnt      Number of copies of ch to write
  10. *
  11. * Description    SCWRITE displays cnt copies of the character ch on the
  12. *        current display screen without changing the
  13. *        currently-set attribute.  The characters are written on
  14. *        the current page starting at the current cursor
  15. *        position.
  16. *
  17. *        This routine will not write more characters than will
  18. *        fit on the screen, nor will it scroll the screen.
  19. *
  20. *        SCATTRIB is preferable for graphics modes because it
  21. *        allows control of the characters' color.  SCWRITE uses
  22. *        color 1 in graphics modes.
  23. *
  24. * Version    3.0  (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
  25. *
  26. **/
  27.  
  28. #include <bscreen.h>
  29.  
  30. int scwrite(ch,cnt)
  31. char     ch;
  32. unsigned cnt;
  33. {
  34.     int ax,bx,cx,dx,flags;
  35.     int mode,cols,act_page,last_row;
  36.     int save_row,row,col;
  37.     int cols_left,first_chunk,chunk;
  38.  
  39.     if (cnt == 0)          /* BIOS treats 0 as 64K              */
  40.     return(0);
  41.     else if (cnt == 1)          /* Handle the usual case this way       */
  42.     {                  /* to save time                  */
  43.     first_chunk = cnt;
  44.     chunk        = 0;
  45.     }
  46.     else
  47.     {                     /* The general case          */
  48.     scmode(&mode,&cols,&act_page);
  49.     last_row = scrows() - 1;
  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 + ((last_row - 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(10,ch);
  78.     bx     = utbyword(b_curpage,1);     /* Use color 1 in case this is  */
  79.                       /* graphics mode              */
  80.     cx     = first_chunk;
  81.     cnt -= first_chunk;
  82.     bios(16,&ax,&bx,&cx,&dx,&flags);
  83.  
  84.     /* Write the remainder:  if text mode, do nothing; if graphics,   */
  85.     /* write each of the remaining lines on the screen.           */
  86.  
  87.     if (chunk != 0)
  88.     {
  89.     for (; cnt; cnt -= cx)
  90.     {
  91.         sccurset(++row,0);
  92.         ax = utbyword(10,ch);
  93.         cx = min(cnt,chunk);
  94.         bios(16,&ax,&bx,&cx,&dx,&flags);
  95.     }
  96.     sccurset(save_row,col);     /* Restore the original       */
  97.                     /* cursor position          */
  98.     }
  99.  
  100.     return(0);
  101. }
  102.