home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / 64COLORS.ZIP / 64COLORS.C next >
Encoding:
C/C++ Source or Header  |  1990-06-04  |  2.0 KB  |  65 lines

  1. /* Path: hplabs!hpcc01!azarian
  2.    From: azarian@hpcc01.HP.COM (Randy Azarian)
  3.    Newsgroups: comp.sys.ibm.pc.programmer
  4.    Subject: Re: ATI Wonder VGA and 256 colors - a summary
  5.    Message-ID: <13300001@hpcc01.HP.COM>
  6.    Date: 4 May 90 18:35:45 GMT
  7.    Organization: HP Corporate Computing & Services */
  8.  
  9. #define xsize 27
  10. #define ysize 14
  11.  
  12. #include <graph.h>                        /* link with GRAPHICS.LIB */
  13. #include <dos.h>
  14.  
  15. /**********************************************/
  16. /* Display all 64 EGA colors on a VGA display */
  17. /**********************************************/
  18. main()
  19. {
  20.   int i, R,G,B;
  21.  
  22.   _setvideomode(0x13);                  /* set 256-color mode */
  23.  
  24.  
  25.   for (i=0; i<=64; i++) {               /* assign EGA colors to VGA registers */
  26.       if ((i & 32) == 32) R=21; else R=0;
  27.       if ((i & 16) == 16) G=21; else G=0;
  28.       if ((i &  8) ==  8) B=21; else B=0;
  29.       if ((i &  4) ==  4) R+=42;
  30.       if ((i &  2) ==  2) G+=42;
  31.       if ((i &  1) ==  1) B+=42;
  32.  
  33.       vgacolor(i,R,G,B);
  34.   }
  35.  
  36.   showcolor(); /* draw 64 boxes, each with a different color */
  37.   getche();    /* pause for user to press a key              */
  38.  
  39.   _setvideomode(0x3); /* reset video mode for text mode */
  40. }
  41.  
  42. vgacolor(registr,red,green,blue)
  43. int registr, red, green, blue;
  44. {
  45.   union REGS inreg, outreg;     /*********************************/
  46.   inreg.x.ax = 0x1010;          /* BIOS function number          */
  47.   inreg.x.bx = registr;         /* color register number 1-256   */
  48.   inreg.h.dh = red;             /* red value 0-63                */
  49.   inreg.h.ch = green;           /* green value 0-63              */
  50.   inreg.h.cl = blue;            /* blue value 0-63               */
  51.   int86(0x10, &inreg, &outreg); /*********************************/
  52. }
  53.  
  54. showcolor()
  55. {
  56.   int o, color, x,y;
  57.  
  58.   for (o=0, y=-4, color=0; o < 8; o++)
  59.     for (x=4, y+=(ysize+7); x < 320; x+=(xsize+13)) {
  60.      _setcolor(247);     _rectangle(_GFILLINTERIOR,x+3,y+3,x+xsize+3,y+ysize+3);
  61.      _setcolor(color++); _rectangle(_GFILLINTERIOR,x,y,x+xsize,y+ysize);
  62.   }
  63. }
  64.  
  65.