home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_01 / wclear.c < prev    next >
C/C++ Source or Header  |  1991-04-02  |  4KB  |  199 lines

  1. /*! wclear
  2.  *    clear an area of screen to current background
  3.  *
  4.  */
  5. #include  "wscreen.h"
  6. #include  "wsys.h"
  7.  
  8.  
  9.  
  10. void wclear  ( void )
  11.     {
  12.     wclearabs (     w0->winleft,             w0->wintop,
  13.             w0->winleft + w0->winxmax,  w0->wintop + w0->winymax
  14.           );
  15.     wgoto ( 0,0 );
  16.     return;
  17.     }
  18.  
  19. void wclearline  ( void )
  20.     {
  21.     wclearabs (     w0->winleft + w0->winx,     w0->wintop + w0->winy,
  22.             w0->winleft + w0->winxmax,  w0->wintop + w0->winy
  23.           );
  24.     return;
  25.     }
  26.  
  27.  
  28.  
  29. void wclearabs ( int l, int t, int r, int b )
  30.     {
  31.     unsigned char far *p, far *s;    /* to video ram */
  32.     int      col;            /* column counter */
  33.  
  34.  
  35.     struct _CHATTR
  36.         {
  37.         unsigned char c;
  38.         unsigned char a;
  39.         }
  40.         chattr;
  41.     typedef struct _CHATTR far *CHATTR;    /*ptr to a far ch/attr pair*/
  42.  
  43.  
  44.  
  45.  
  46.  
  47.     #ifndef TEXTONLY
  48.  
  49.     unsigned char a;        /* background attribute */
  50.     unsigned int     hn;             /* hercules bank offset */
  51.     unsigned char far *base;    /* base of each row */
  52.     unsigned char far *colptr;    /* pointer to column */
  53.  
  54.     unsigned char latch;
  55.     #endif    /* TEXTONLY - end graphics-mode declarations */
  56.  
  57.  
  58.  
  59.     if  ( l < 0 ||  r > wxabsmax ||  t < 0 || b > wyabsmax )
  60.         {
  61.         return;
  62.         }
  63.  
  64.  
  65.  
  66.  
  67.     if ( wmode == 'T' )
  68.         {
  69.         s = wpage_ram + 2*80*t + 2*l;
  70.  
  71.         chattr.c =' ';
  72.         chattr.a = wgetattr();
  73.  
  74.  
  75.  
  76.         for ( ; t <= b; ++t, s += 2*80 )
  77.             /* s pts to start of each line */
  78.             {
  79.             for ( col = l, p = s; col <= r; ++col )
  80.                 {
  81.                 *((CHATTR) p) = chattr;
  82.                 p += 2;
  83.                 }
  84.             }
  85.         /* end text mode absolute clear */
  86.  
  87.         return;
  88.         }    /* end text mode */
  89.  
  90.  
  91. #ifndef TEXTONLY
  92.     /* graphics mode wclearabs */
  93.  
  94.  
  95.  
  96.     a = ( wgetattr() ) >> 4;    /* background color */
  97.  
  98.  
  99.  
  100.     switch ( wmonitor )
  101.         {
  102.     case ( 'H'):
  103.         /* NOTE addressing hercules graphics ram:
  104.          *    l, t are 'text-mode' addresses.
  105.          *    720 pixels/row, wpxchar pixels per 'x' increment
  106.          *        so 1st factor = wxabsmax = chars per row
  107.          *    divide wpychar by 4(=# herc banks) =
  108.          *        gives #of sets of banks (4 pixel rows each)
  109.          *    wpxchar/8 =1 always, included only for clarity.
  110.          *
  111.          *    because charsizes are mults of 4, whbank starts at 0;
  112.          */
  113.         base    =  wpage_ram
  114.             + ( (720/wpxchar)*(wpychar/4)*t ) + l;
  115.  
  116.         /* in hercules, 'dither' blue and green bits
  117.          * note this line changes 'a' from attr to bitmask.
  118.          * and sets 8 adjacent bits on screen
  119.          */
  120.         a = (a & 0x03) ? 0xff : 0x00;
  121.  
  122.         /* convert to pixel co-ords only for counting rows */
  123.         t *= wpychar;
  124.         b  = (b+1) * wpychar;  /* includes last pixel row */
  125.  
  126.  
  127.         for ( hn = 0; t < b;  ++t, hn += 0x2000 )
  128.             {
  129.             /* loop iterates once per row
  130.              */
  131.             if ( hn == 0x8000 )
  132.                 {
  133.                 /* finished one set of 4 banks,
  134.                  * move up to next tier.
  135.                  */
  136.                 hn = 0;
  137.                 base += 90;
  138.                 }
  139.             for (     col = l, colptr = base;
  140.                 col <=r;
  141.                 ++col, ++colptr)
  142.                 {
  143.                 /* once per column within each row */
  144.                 *( colptr + hn )  = a;
  145.                 }
  146.             }
  147.         break;       /* end hercules mode */
  148.  
  149.     case ( 'E' ):
  150.     case ( 'V' ):
  151.  
  152.         base = wpage_ram + ( wegarowsize * wpychar * t ) + l;
  153.  
  154.         /* convert to pixel co-ords to count rows
  155.          */
  156.         t *= wpychar;
  157.         b  = (b+1)* wpychar; /* last pixel row in last char row*/
  158.  
  159.         EGA_OUT (1, EGA_ENABLE);
  160.         EGA_BITPLANE (0x0f);
  161.  
  162.  
  163.         EGA_OUT (3, 0x00);    /* OVERWRITE */
  164.         /* write attribute to 8 bits */
  165.         EGA_OUT (0, a);
  166.         EGA_OUT (8, 0xFF);
  167.  
  168.  
  169.         for (     ;    /* loop once per row */
  170.             t < b;
  171.             ++t, base += 640/wpxchar )
  172.             {
  173.                 for (    col = l, colptr =base ;
  174.                     col <= r;
  175.                     ++col, ++colptr)
  176.                     {
  177.  
  178.                     *(colptr) = 0xff;
  179.  
  180.                     }
  181.             }    /* end for each rows */
  182.  
  183.         /* reset EGA */
  184.         EGA_OUT (0,0);            /* BLACK */
  185.  
  186.  
  187.         break;
  188.         }     /* end switch (wgdriver) */
  189.  
  190. #endif    /* TEXTONLY - end graphics mode wclearabs */
  191.     return; /* wclearabs */
  192.  
  193.  
  194.     }
  195.  
  196.  
  197. /*---------------------- end of WCLEAR.C -----------------------------*/
  198.  
  199.