Category : C Source Code
Archive   : CGRAFDDJ.ZIP
Filename : VID.C

 
Output of file : VID.C contained in archive : CGRAFDDJ.ZIP

/* VID.C: Demos video functions */
/* From Dr. Dobbs Journal, Nov 87, page 85 */

/* TURBO C INCLUDES */

#include
#include
#include

/* USER-WRITTEN INCLUDES */

#include
#include
#include
#include /*------------> this included here, but not in the */
/* magazine listing, so that these */
/* LOCAL FUNCTION PROTOTYPES */ /* listings could be compiled without */
/* creating the video.lib. */
int vidIdent (int *vidmode);
void wait (void);
void stairsteps (void);
int isEGA (void);
void label (void);
void bigX (int adap, int vmode);
void hourglass (int adap, int vmode);

/* GLOBALS */

enum vidTypes {mda, cga, ega, compaq, other};

main()
{
int adaptor, mode, cols;

cls(); /* clear screen */
adaptor = vidIdent (&mode); /* identify video adaptor */
if (adaptor != other)
{
stairsteps(); /* cursor positioning demo */
bigX (adaptor, mode); /* graphics demo 1 */
hourglass (adaptor, mode); /* graphics demo 2 */
label();
gotoxy (36, 12, 0);
puts ("All done!");
}
} /* --------------------------------------------------- */
int vidIdent (int *vidmode) /* identify video adaptor */
{
int flag, adap, width;

label(); /* label display */
puts ("\n\nDISPLAY INFORMATION:");
*vidmode = videomode (&width); /* get video mode */
flag = (biosequip () & 0x18) >> 4; /* get video equip flag */
if (isEGA ())
{
adap = ega;
puts("\n\n Enhanced Graphics Adaptor");
}
else
switch (flag)
{
case 0:
if (*vidmode == 2)
{
adap = compaq;
puts ("\n\n Compaq Adaptor");
}
else
{
adap = cga;
puts ("\n\n Color Graphics Adaptor");
}
break;
case 3:
adap = mda;
puts ("\n\n Monochrome Display Adaptor");
break;
default:
adap = other;
puts ("\n\n Adaptor not usable in this demo. Sorry.");
} /* end switch */
printf ("\n Text screen size is %d columns x 25 rows\n", width);
if ((*vidmode < 4) || (*vidmode == 7))
puts ("\n Text mode currently active");
else
puts ("\n Graphics mode currently active");
wait ();
return (adap);
} /* --------------------------------------------------- */
int isEGA (void) /* determine if EGA attached */
{ /* return TRUE if so, FALSE if not */
return (peekb (0x40, 0x87)); /* check EGA info byte */
} /* --------------------------------------------------- */
void wait (void) /* prompt to continue, wait for keypress */
{
int tab, width;

videomode (&width); /* get width in columns */
tab = (width - 33) / 2; /* starting column for text */
gotoxy (tab, 24, 0);
wrtstr ("Press any key to continue demo...", WHITE, 0);
getch ();
cls ();
} /* --------------------------------------------------- */
void label (void) /* label the screen at top center */
{
gotoxy (30, 0, 0);
wrtstra ("Video demonstration", chattr (YELLOW, BLUE), 0);
} /* --------------------------------------------------- */
void stairsteps (void)
{
int color = 1;

label ();
gotoxy (31, 2, 0);
wrtstr ("Cursor positioning", LIGHTGRAY, 0);
gotoxy (10, 4, 0);
wrtstr ("Stair", color++, 0);
gotoxy (20, 10, 0);
wrtstr ("steps", color++, 0);
gotoxy (30, 16, 0);
wrtstr ("going", color++, 0);
gotoxy (40, 22, 0);
wrtstr ("down", color++, 0);
gotoxy (50, 16, 0);
wrtstr ("and", color++, 0);
gotoxy (60, 10, 0);
wrtstr ("back", color++, 0);
gotoxy (70, 4, 0);
wrtstr ("up", color, 0);
wait ();
} /* --------------------------------------------------- */
void bigX (int vidAdap, int vmode) /* APA graphics demo 1 */
{ /* draws full-screen border and X, */
/* adjusting for EGA or CGA as indicated */
int x1 = 0, x2 = 639;
int y1 = 15, y2;

if ((vidAdap == mda) || (vidAdap == other)) /* can't do it */
return; /* so return with no action */

if (vidAdap == ega) /* EGA demo: 640 x 350 (mode 0Fh) */
{
y2 = 349 - 15; /* set to bottom of graphics screen */
setmode (0x0F); /* go to EGA mono graphics mode */
}
else /* CGA|Compaq demo: 630 x 200 (mode 06h) */
{
y2 = 199 - 15;
setmode (0x06);
}
label (); /* label the screen */
hdraw (x1, x2, y1, 1); /* draw line across the top */
hdraw (x1, x2, y2, 1); /* then bottom */
vdraw (y1, y2, x1, 1); /* down left side */
vdraw (y1, y2, x2, 1); /* down right side */
draw (x1, y1, x2, y2, 1); /* main diagonal */
draw (x1, y2, x2, y1, 1); /* cross diagonal */
wait ();
setmode (vmode);
} /* --------------------------------------------------- */
void hourglass (int vidAdap, int vmode) /* graphics demo 2 */
{ /* operates in 320 x 200 four-color (CGA) mode */
int y, x1 = 60, x2 = 260, pixval = 1;

if ((vidAdap == mda) || (vidAdap == other)) /* can't do it */
return; /* so go back */
setmode (4); /* go to CGA graphics mode */
gotoxy (8, 0, 0);
puts ("320 x 200 color graphics"); /* show mode */
palette (0);
for (y = 50; y < 151; y++) /* draw figure */
{
hdraw (x1, x2, y, pixval);
x1 += 2; /* change x's */
x2 -= 2;
if (y == 84) pixval = 2;
if (y == 117) pixval = 3;
}
wait ();
setmode (vmode);
} /* --------------------------------------------------- */
/* THE END */