Demo of using BGI driver in BGI format.

/*----------------------------------------------*/
/*   VGA256.BGI    Designer VGA BGI driver      */
/*   COLORTST.C    Color test program           */
/*                                              */
/*   Compile in:  Any model!!!!! (except tiny)  */
/*                                              */
/*    By:  Markham Thomas  Feb  3, 1989         */
/*----------------------------------------------*/

#include <graphics.h>
#include <alloc.h>
#include <stdlib.h>
#include "VGA256.H"                    /* pick up the main BGI defines */
#include "VGAEXTRA.H"                  /* pick up detect & misc. functions */

  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 hsv2rgb(float h,float s,float v,RGB *Color)
{
  float h1,f,a[7];
  int   i;
    h1 = h / 60;
    i  = h1;
    f  = h1 - i;
    a[1] = v;
    a[2] = v;
    a[3] = v * (1 - (s*f));
    a[4] = v * (1 - s);
    a[5] = a[4];
    a[6] = v * (1-(s*(1-f)));
    if (i>4) i = i - 4; else i = i + 2;
    Color->Red = a[i];
    if (i>4) i = i - 4; else i = i + 2;
    Color->Green = a[i];
    if (i>4) i = i - 4; else i = i + 2;
    Color->Blue  = a[i];
}

/*----------------- 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(255);
    for (x=0;x<256;x++) {
        setfillstyle(SOLID_FILL,x);
        bar(x1,y1,x2,y2);
        line(x1,y1,x2,y1);
        line(x2,y1,x2,y2);
        line(x2,y2,x1,y2);
        line(x1,y2,x1,y1);
        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;
    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);
    }
    hue = 0;
    sat = 1.0;
    val = 63.0;
    for (x=1;  x<255;  x++) {
        hsv2rgb(hue,sat,val,&ColorValue);
        Palette_Array[x][red] = ColorValue.Red;
        Palette_Array[x][grn] = ColorValue.Green;
        Palette_Array[x][blu] = ColorValue.Blue;
        hue = hue + 1.44;
    }
    Palette_Array[0][red]     = 1;     /* Set first DAC register to black */
    Palette_Array[0][grn]     = 2;
    Palette_Array[0][blu]     = 3;
    Palette_Array[255][red]   = 0x3f;  /* Set last DAC register to white */
    Palette_Array[255][grn]   = 0x3f;
    Palette_Array[255][blu]   = 0x3f;
/*  flashmodeon(); */                  /* put vram into hyperdrive... */
    setvgapalette(Palette_Array);      /* load DAC registers with new colors */
    Palette_List();                    /* display the 256 colors */
/*  flashmodeoff(); */                 /* slow down to reality..(wait states) */
    getch();
    restorecrtmode();
}
    /* Don't use flashmodes unless TSENG LABS based chip set in VGA */
