home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / VGATOOLS.ZIP / VGA_BGI.COM / VGA256T.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-08  |  4.1 KB  |  155 lines

  1. #include <dos.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <graphics.h>
  6. #include <mouse.inc>
  7. #include "vga256.h"
  8. #include "vgaextra.h"
  9.  
  10.  
  11. #define SETXORMODE  outport(0x3CE, 0x1803)       /* set XOR mode */
  12. #define SETORMODE   outport(0x3CE, 0x1003)       /* set OR mode  */
  13. #define SETANDMODE  outport(0x3CE, 0x0803)       /* set AND mode */
  14. #define SETNORMMODE outport(0x3CE, 0x0003) /* set overwrite mode */
  15. #define SWAP(i, j) {int temp; temp = i; i = j; j = temp;}
  16.  
  17.  
  18.   locRec *Now, *Current;
  19.   resetRec  *MOUSE;
  20.   int    g_driver,  g_mode, g_error;
  21.  
  22. /*----------------- Array for RGB color info ------------------------*/
  23.  
  24.   DACarray Palette_Array;              /* create array to hold DAC values */
  25.  
  26. /*----------------- RGB colors from HSV model ---------------------------*/
  27. /* hue    =  pure color of the light
  28.    sat    =  how much white light is mixed in
  29.    value  =  max component of RGB */
  30.  
  31. void read_dacs( unsigned palSeg, unsigned palOfs)
  32. {
  33.     union REGS reg, outreg;
  34.         struct SREGS seg;
  35.  
  36.     reg.x.ax = 0x1017;
  37.     reg.x.bx = 0x0000;
  38.     reg.x.cx =0xff;
  39.         reg.x.dx = palOfs;
  40.         seg.es     = palSeg;
  41.         int86x (0x10, ®, &outreg, &seg);
  42. }
  43.  
  44. void write_dacs( unsigned palSeg, unsigned palOfs)
  45. {
  46.   /* write a pallate array of 256 colors in dac registers */
  47.     union REGS reg, outreg;
  48.         struct SREGS seg;
  49.  
  50.     reg.x.ax = 0x1012;
  51.     reg.x.bx = 0x0000;
  52.     reg.x.cx =0xff;
  53.         reg.x.dx = palOfs;
  54.         seg.es     = palSeg;
  55.         int86x (0x10, ®, &outreg, &seg);
  56. }
  57.  
  58. void read_dac( int color_reg)
  59. {
  60.     union REGS reg;
  61.  
  62.     reg.x.ax = 0x1015;
  63.     reg.x.bx = color_reg;
  64.     int86(0x10,®,®);
  65.     VGApallete[color_reg][grn] = reg.h.ch;
  66.     VGApallete[color_reg][blu] = reg.h.cl;
  67.     VGApallete[color_reg][red] = reg.h.dh;
  68. }
  69.  
  70. void write_dac(int color_reg)
  71. {
  72.  
  73.     union REGS reg;
  74.  
  75.     reg.x.ax = 0x1010;
  76.     reg.x.bx = color_reg;
  77.     reg.h.ch = VGApallete[color_reg][grn];
  78.     reg.h.cl = VGApallete[color_reg][blu];
  79.     reg.h.dh = VGApallete[color_reg][red];
  80.     int86(0x10,®,®);
  81. }
  82.  
  83. /*----------------- Draw all 256 colors on screen ------------------------*/
  84. void Palette_List()
  85. {
  86.   int x,y,xw,yh,xinc,yinc,count;
  87.   int x1,y1,x2,y2;
  88.     xw = (getmaxx() / 16) - 5;
  89.     yh = (getmaxy() / 16) - 5;
  90.     xinc = xw + 5;
  91.     yinc = yh + 5;
  92.     x1 = 0;
  93.     y1 = 0;
  94.     x2 = xw;
  95.     y2 = yh;
  96.     count = 0;
  97.     setcolor(7);
  98.     for (x=0;x<256;x++) {
  99.     setfillstyle(SOLID_FILL, x);
  100.     bar3d(x1,y1,x2,y2,0,0);
  101.         x1 = x1 + xinc;
  102.         x2 = x2 + xinc;
  103.         count = ++count;
  104.         if (count == 16) {
  105.            x1 = 0;
  106.            y1 = y1 + yinc;
  107.            x2 = xw;
  108.            y2 = y2 + yinc;
  109.            count = 0;
  110.         }
  111.     }
  112. }
  113.  
  114. /*----------------- Main Program -----------------------------------------*/
  115. void main()
  116. {
  117.   int x,y;
  118.   RGB ColorValue;
  119.   int count;
  120.   float hue,sat,val;
  121.   DACarray  REVpallete;                 /* will hold reversed pallete record */
  122.  
  123.     installuserdriver("VGA256",DetectVGA256);   /* install my BGI driver */
  124.     g_driver = DETECT;                          /* AutoDetect Designer VGA */
  125.     initgraph(&g_driver,&g_mode,"");
  126.     g_error = graphresult();
  127.     if (g_error != 0) {
  128.        printf("%s \n",grapherrormsg(g_error));
  129.        exit(1);
  130.     }
  131.      /* get the current default DAC colors */
  132.  
  133.     read_dacs(FP_SEG (VGApallete), FP_OFF (VGApallete));
  134.  
  135.  /*   flashmodeon();   */                 /* put vram into hyperdrive... */
  136.     setvgapalette(VGApallete);         /* load DAC registers with new colors */
  137.     Palette_List();                    /* display the 256 colors */
  138.     getch();
  139.     x=255;
  140.     for(y=0;y<256;y++)
  141.      {
  142.       REVpallete[x][red]=VGApallete[y][red];
  143.       REVpallete[x][blu]=VGApallete[y][blu];
  144.       REVpallete[x][grn]=VGApallete[y][grn];
  145.       x=x-1;
  146.      } 
  147.     write_dacs(FP_SEG (REVpallete), FP_OFF (REVpallete));
  148.     getch();
  149.     write_dacs(FP_SEG (VGApallete), FP_OFF (VGApallete));
  150.  /*   flashmodeoff();    */               /* slow down to reality..(wait states) */
  151.     getch();
  152.     restorecrtmode();
  153. }
  154.     /* Don't use flashmodes unless TSENG LABS based chip set in VGA */
  155.