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

  1. /*! wputcabs()
  2.  *    Put char, attr at screen position x,y (screen physical co-ords)
  3.  *    Works in text or graphics mode. In either mode, co-ords are text-mode
  4.  *     co-ords (not pixel co-ords). Putmode is ignored in text mode.
  5.  *    In graphics mode, putmode can be: WGOVERWRITE, WGOR, WGXOR, WGAND
  6.  */
  7.  
  8.  
  9. #include  "wscreen.h"
  10. #include  "wsys.h"
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. void wputcabs ( int x, int y, unsigned char c, unsigned char a,
  19.     unsigned char putmode )
  20.     {
  21.     register unsigned char far *p;
  22.  
  23. #ifndef TEXTONLY
  24.  
  25.     /* declarations for graphics mode
  26.      */
  27.     unsigned int     hn;
  28.     int         row;    /* 0-7, which row of bits in the bitmap */
  29.  
  30.  
  31.     unsigned char foreground, background;    /* attributes */
  32.  
  33.     unsigned char far *font;      /* bit map of current row in font */
  34.  
  35.     unsigned char far *base;
  36.     unsigned char      mask;     /* EGA register mask and latch byte*/
  37.     unsigned char        latch;
  38.  
  39.  
  40.  
  41.     unsigned char hmask;
  42.  
  43. #endif /* end declarations for graphics mode */
  44.  
  45.  
  46.  
  47.  
  48.     if ( wmode == 'T' )
  49.         {
  50.         p = wpage_ram + 2*80*y + 2* x;
  51.         *p = c;
  52.         *(++p) = a;
  53.  
  54.         return;
  55.         }
  56.  
  57.  
  58. #ifndef TEXTONLY
  59.     /* graphics mode wputcabs */
  60.  
  61.  
  62.  
  63.     if  ( x < 0 || y< 0 || x > wxabsmax || y > wyabsmax )
  64.         {
  65.         return;
  66.         }
  67.  
  68.     #if wpychar == 8
  69.  
  70.     if  ( c > 127 )
  71.         {
  72.         font = (unsigned char far *) whifont +
  73.             ( ((int)(c) - 128)<<3 );
  74.         }
  75.     else
  76.     if ( c < 32 )
  77.         {
  78.         font = (unsigned char far *) wlofont +
  79.             ( c<<3 );
  80.         }
  81.     else     {
  82.         font = ROM_FONT + ( ((int) c) <<3) ;
  83.         }
  84.     #else
  85.         #error("Need 16-bit hi font tables ");
  86.     #endif    /* wpychar */
  87.  
  88.  
  89.     foreground =   a & 0x0f;    /* separate attribute byte */
  90.     background = ( a & 0xf0 ) >> 4;
  91.  
  92.     switch ( wmonitor )
  93.         {
  94.     case ( 'H' ):
  95.         /* NOTE addressing hercules graphics ram:
  96.          *    x, y are 'text-mode' addresses.
  97.          *    720 pixels/row, wpxchar pixels per 'x' increment
  98.          *        so 1st factor = wxabsmax = chars per row
  99.          *    divide wpychar by 4(=# herc banks) =
  100.          *        gives #of sets of banks (4 pixel rows each)
  101.          *    wpxchar/8 =1 always, included only for clarity.
  102.          */
  103.         base    =  wpage_ram
  104.             + ( (720/wpxchar)*(wpychar/4)*y ) + x ;
  105.  
  106.         /* in hercules, 'dither' blue & green bits */
  107.         foreground = (foreground & 0x03) ? 0xff : 0x00;
  108.         background = (background & 0x03) ? 0xff : 0x00;
  109.  
  110.         for (     row = hn = 0;
  111.             row < wpychar;
  112.             ++row, ++font, hn +=0x2000 )
  113.             {
  114.             if ( hn == 0x8000 )
  115.                 {
  116.                 /* finished one set of 4 banks,
  117.                  * move up to next tier.
  118.                  */
  119.                 hn = 0;
  120.                 base += 90;
  121.                 }
  122.  
  123.             hmask  = ( (  *font ) & foreground )
  124.                      | ( (~ *font ) & background )  ;
  125.  
  126.             switch (putmode)
  127.                 {
  128.             case (WGOVERWRITE):
  129.                 *(base+hn) = hmask;
  130.                 break;
  131.             case (WGXOR):
  132.                 *(base+hn) ^= hmask;
  133.                 break;
  134.             case (WGOR):
  135.                 *(base+hn) |= hmask;
  136.                 break;
  137.             case (WGAND):
  138.                 *(base+hn) &= hmask;
  139.                 break;
  140.  
  141.                 }/* end switch ( putmode ) */
  142.  
  143.             }/* end loop for hercules rows */
  144.         break;       /* end case (hercules) */
  145.  
  146.     case ( 'E' ):
  147.     case ( 'V' ):
  148.  
  149.  
  150.         base = wpage_ram + ( wegarowsize * wpychar * y ) + x;
  151.  
  152.  
  153.  
  154.         EGA_OUT (1, EGA_ENABLE);
  155.         EGA_BITPLANE (0x0f);
  156.         EGA_OUT (3, putmode);    /* OVERWRITE, OR, AND, etc.. */
  157.  
  158.         for (     row = 0;
  159.             row < wpychar;
  160.              ++row, base += 640/wpxchar, ++font )
  161.             {
  162.  
  163.             /* write foregraound */
  164.             mask   = *font;
  165.             latch  = *base;         /* latch data to EGA regs */
  166.             EGA_OUT (0, foreground);/* color */
  167.             EGA_OUT (8, mask);    /* mask ON bits from font map */
  168.             *base  = 0xff;        /* change as governed by mask */
  169.  
  170.             /* write background */
  171.             mask   =  ~mask;    /* invert mask */
  172.             latch  = *base;         /* latch data  */
  173.             EGA_OUT (0, background);
  174.             EGA_OUT (8, mask);
  175.             *base = 0xff;
  176.  
  177.             }
  178.  
  179.         /* reset EGA */
  180.         EGA_OUT (0,0);            /* BLACK    */
  181.         EGA_OUT (3, 0x0);            /* OVERWRITE*/
  182.         EGA_OUT (8, 0xff);              /* all bits */
  183.  
  184.  
  185.         break;
  186.         }     /* end switch (wgdriver) */
  187.  
  188.  
  189. #endif    /*TEXTONLY - end of graphics mode wputcabs */
  190.  
  191.  
  192.  
  193.  
  194.  
  195.     return; /* wputcabs */
  196.  
  197.  
  198.     }
  199. /*--------------------- end of WPUTCABS.C -------------------------*/
  200.