home *** CD-ROM | disk | FTP | other *** search
- #include <dos.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <graphics.h>
- #include <mouse.inc>
- #include "vga256.h"
- #include "vgaextra.h"
-
-
- #define SETXORMODE outport(0x3CE, 0x1803) /* set XOR mode */
- #define SETORMODE outport(0x3CE, 0x1003) /* set OR mode */
- #define SETANDMODE outport(0x3CE, 0x0803) /* set AND mode */
- #define SETNORMMODE outport(0x3CE, 0x0003) /* set overwrite mode */
- #define SWAP(i, j) {int temp; temp = i; i = j; j = temp;}
-
-
- locRec *Now, *Current;
- resetRec *MOUSE;
- int g_driver, g_mode, g_error;
-
- /*----------------- Array for RGB color info ------------------------*/
-
- DACarray Palette_Array; /* create array to hold DAC values */
-
- /*----------------- RGB colors from HSV model ---------------------------*/
- /* hue = pure color of the light
- sat = how much white light is mixed in
- value = max component of RGB */
-
- void read_dacs( unsigned palSeg, unsigned palOfs)
- {
- union REGS reg, outreg;
- struct SREGS seg;
-
- reg.x.ax = 0x1017;
- reg.x.bx = 0x0000;
- reg.x.cx =0xff;
- reg.x.dx = palOfs;
- seg.es = palSeg;
- int86x (0x10, ®, &outreg, &seg);
- }
-
- void write_dacs( unsigned palSeg, unsigned palOfs)
- {
- /* write a pallate array of 256 colors in dac registers */
- union REGS reg, outreg;
- struct SREGS seg;
-
- reg.x.ax = 0x1012;
- reg.x.bx = 0x0000;
- reg.x.cx =0xff;
- reg.x.dx = palOfs;
- seg.es = palSeg;
- int86x (0x10, ®, &outreg, &seg);
- }
-
- void read_dac( int color_reg)
- {
- union REGS reg;
-
- reg.x.ax = 0x1015;
- reg.x.bx = color_reg;
- int86(0x10,®,®);
- VGApallete[color_reg][grn] = reg.h.ch;
- VGApallete[color_reg][blu] = reg.h.cl;
- VGApallete[color_reg][red] = reg.h.dh;
- }
-
- void write_dac(int color_reg)
- {
-
- union REGS reg;
-
- reg.x.ax = 0x1010;
- reg.x.bx = color_reg;
- reg.h.ch = VGApallete[color_reg][grn];
- reg.h.cl = VGApallete[color_reg][blu];
- reg.h.dh = VGApallete[color_reg][red];
- int86(0x10,®,®);
- }
-
- /*----------------- Draw all 256 colors on screen ------------------------*/
- void Palette_List()
- {
- int x,y,xw,yh,xinc,yinc,count;
- int x1,y1,x2,y2;
- xw = (getmaxx() / 16) - 5;
- yh = (getmaxy() / 16) - 5;
- xinc = xw + 5;
- yinc = yh + 5;
- x1 = 0;
- y1 = 0;
- x2 = xw;
- y2 = yh;
- count = 0;
- setcolor(7);
- for (x=0;x<256;x++) {
- setfillstyle(SOLID_FILL, x);
- bar3d(x1,y1,x2,y2,0,0);
- x1 = x1 + xinc;
- x2 = x2 + xinc;
- count = ++count;
- if (count == 16) {
- x1 = 0;
- y1 = y1 + yinc;
- x2 = xw;
- y2 = y2 + yinc;
- count = 0;
- }
- }
- }
-
- /*----------------- Main Program -----------------------------------------*/
- void main()
- {
- int x,y;
- RGB ColorValue;
- int count;
- float hue,sat,val;
- DACarray REVpallete; /* will hold reversed pallete record */
-
- installuserdriver("VGA256",DetectVGA256); /* install my BGI driver */
- g_driver = DETECT; /* AutoDetect Designer VGA */
- initgraph(&g_driver,&g_mode,"");
- g_error = graphresult();
- if (g_error != 0) {
- printf("%s \n",grapherrormsg(g_error));
- exit(1);
- }
- /* get the current default DAC colors */
-
- read_dacs(FP_SEG (VGApallete), FP_OFF (VGApallete));
-
- /* flashmodeon(); */ /* put vram into hyperdrive... */
- setvgapalette(VGApallete); /* load DAC registers with new colors */
- Palette_List(); /* display the 256 colors */
- getch();
- x=255;
- for(y=0;y<256;y++)
- {
- REVpallete[x][red]=VGApallete[y][red];
- REVpallete[x][blu]=VGApallete[y][blu];
- REVpallete[x][grn]=VGApallete[y][grn];
- x=x-1;
- }
- write_dacs(FP_SEG (REVpallete), FP_OFF (REVpallete));
- getch();
- write_dacs(FP_SEG (VGApallete), FP_OFF (VGApallete));
- /* flashmodeoff(); */ /* slow down to reality..(wait states) */
- getch();
- restorecrtmode();
- }
- /* Don't use flashmodes unless TSENG LABS based chip set in VGA */