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

  1. /* wpalette.c
  2.  *        contains EGA/VGA routines wsetpalette() and wgetpalette()
  3.  *
  4.  *                    @ David Blum, 1990
  5.  */
  6. #include "wsys.h"
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. void wgetpalette ( unsigned char palette[17] )
  14.     {
  15.         #ifdef __TURBOC__
  16.         /* this structure and union allow
  17.          * breaking an address into seg:offset components
  18.          * in any memory model
  19.          */
  20.         struct p_struct
  21.             {
  22.             unsigned int off;
  23.             unsigned int seg;
  24.             };
  25.         union   far_ptr
  26.             {
  27.             void   far      *addr;
  28.             struct p_struct p;
  29.             }
  30.             fp;
  31.         /* set all 16 colors and overscan at once
  32.          *
  33.          * first get addr. of palette save area
  34.          *     in small or medium model, could
  35.          *     just assign _ES = _DS; _DX= save_palette;
  36.          *     but wouldn't work in compact or large model
  37.          *
  38.          */
  39.         fp.addr = (void far *) palette;
  40.         _ES     = fp.p.seg;
  41.         _DX     = fp.p.off;
  42.         _AH     = 0x10;
  43.         _AL     = 0x09;
  44.         INTERRUPT (0x10);
  45.             
  46.  
  47.     #else
  48.  
  49.         /* not turboc - save current palette one color at a time*/
  50.         char temp;
  51.         int n;
  52.         PSEUDOREGS
  53.         for ( n= 0; n <16; ++n )
  54.             {
  55.             _BL = n;
  56.             _AH = 0x10;
  57.             _AL = 7;    /* get one palette color */
  58.             INTERRUPT (0x10);
  59.             temp = _BH;                /* safety precaution */
  60.  
  61.             palette[n] = temp;
  62.  
  63.             }
  64.         /* save overscan */
  65.  
  66.         _AH = 0x10;
  67.         _AL = 8;            /* read overscan color */
  68.         INTERRUPT (0x10);
  69.         temp = _BH;
  70.         palette[16] = temp;
  71.  
  72.  
  73.     #endif /* TURBOC */
  74.  
  75.         return;        /* wgetpalette() */
  76.         }
  77.         
  78.  
  79.  
  80.  
  81. void wsetpalette ( unsigned char palette [17] )
  82.     {
  83.         
  84.     #ifdef __TURBOC__
  85.  
  86.         /* this structure and union allow
  87.          * breaking an address into seg:offset components
  88.          * in any memory model
  89.          */
  90.         struct p_struct
  91.             {
  92.             unsigned int off;
  93.             unsigned int seg;
  94.             };
  95.         union   far_ptr
  96.             {
  97.             void   far      *addr;
  98.             struct p_struct p;
  99.             }
  100.             fp;
  101.  
  102.  
  103.             /* set palette 
  104.              */
  105.             fp.addr = (void far *) palette;
  106.             _ES     = fp.p.seg;
  107.             _DX     = fp.p.off;
  108.             _AH     = 0x10;
  109.             _AL     = 0x02;
  110.             INTERRUPT (0x10);
  111.     
  112.     #else
  113.     /* NOT turbo C so do it one step at a time.
  114.      */
  115.     int n;
  116.     char temp;
  117.     PSEUDOREGS
  118.     
  119.         /* Not TurboC 
  120.          */
  121.         for ( n= 0; n <16; ++n )
  122.             {
  123.             
  124.             _BH = palette [n];
  125.             _BL = n;
  126.             _AH = 0x10;
  127.             _AL = 0;
  128.             INTERRUPT (0x10);
  129.             }
  130.         _AH = 0x10;
  131.         _BH = palette[16];        /* set overscan color */
  132.         _AL = 1;
  133.         INTERRUPT (0x10);
  134.         
  135.     #endif
  136.     
  137.     return;        /* wgetpalette () */
  138.     
  139.     }
  140.     
  141.     
  142.     /*----------------- end of wpalette.c ----------------------*/
  143.  
  144.  
  145.  
  146.