home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mega CD-ROM 1
/
megacd_rom_1.zip
/
megacd_rom_1
/
MAGAZINE
/
MSJOURNA
/
MSJV25.ZIP
/
MSC5.ALL
< prev
next >
Wrap
Text File
|
1987-12-27
|
5KB
|
207 lines
Microsoft Systems Journal
Volume 2; Issue 5; November, 1987
Code Listings For:
GDEMO
pp. 67-76
Author(s): Augie Hansen
Title: Microsoft C Optimizing Compiler 5.0 Offers Improved Speed and
Code Size
Figure 5
========
/********************************************************************
* NAME: gdemo
*
* DESCRIPTION: This is a simple graphics demonstration program. Its
* purpose it to show how to select a graphics mode, do some simple
* graphics work, and then return to DOS after restoring the user's
* previous video environment.
********************************************************************/
#include <graph.h>
#include <math.h>
#define RHEIGHT 160
#define RWIDTH 300
#define MSG_ROW 25
#define MSG_COL 8
#define M_NOWAIT 0
#define M_WAIT 1
/*
* Macro to plot points with the normal sense of the y axis. The
* graphics library default is inverted (y increases in value moving
* down the screen).
*/
#define PLOT(x_, y_) _setpixel((x_), -(y_))
extern void Message(short, short, char *, short);
int
main()
{
struct videoconfig config; /* video configuration data */
short x_org, y_org; /* coordinates of the origin */
short x_ul, y_ul; /* upper-left corner */
short x_lr, y_lr; /* lower-right corner */
short x, y;
static char prompt[] = { "Press a key to continue..." };
/*
* Set up the medium-resloution graphics screen and set
* the logical origin to the center of the screen.
*/
_setvideomode(_MRES16COLOR);
_getvideoconfig(&config);
x_org = config.numxpixels / 2 - 1;
y_org = config.numypixels / 2 - 1;
_setlogorg(x_org, y_org);
/*
* Draw a border rectangle and coordinate system.
*/
x_ul = -RWIDTH / 2;
y_ul = RHEIGHT / 2;
x_lr = RWIDTH / 2;
y_lr = -RHEIGHT / 2;
_rectangle(_GBORDER, x_ul, y_ul, x_lr, y_lr);
_moveto(x_ul, 0);
_lineto(x_lr, 0);
_moveto(0, y_ul);
_lineto(0, y_lr);
/*
* Plot some curves.
*/
for (x = -100; x <= 100; ++x) {
y = x / 2;
PLOT(x, y);
}
Message(11, 27, "y = x / 2", M_NOWAIT);
for (x = -20; x <= 20; ++x) {
y = (x * x / 3) - 75;
PLOT(x, y);
}
Message(22, 3, "y = x**2 / 3 - 75", M_NOWAIT);
/*
* Wait for the user's command to continue.
*/
Message(MSG_ROW, MSG_COL, prompt, M_WAIT);
/*
* Restore the original video mode.
*/
_setvideomode(_DEFAULTMODE);
return (0);
}
Figure 6
========
/***************************************************************
* Message
*
* DESCRIPTION: Display the message text at the specified
* screen location (row, col). If wait has a non-zero value,
* wait for the user to press a key. When the user complies,
* grab the character from the keyboard buffer so it won't
* interfere with the calling program following the return.
***************************************************************/
#include <conio.h>
#include <graph.h>
void
Message(row, col, text, wait)
short row, col; /* text position */
char *text; /* text pointer */
short wait; /* wait flag */
/* (wait != 0 means wait for a keypress) */
{
int k; /* key code */
/*
* Write the prompt text at the specified location.
*/
_settextposition(row, col);
_outtext(text);
/*
* If the wait flag is set, wait for a key to be pressed,
* then remove the code from the keyboard buffer. Handle
* extended codes by grabbing two bytes if the first is NUL.
*/
if (wait) {
while (!kbhit())
;
k = getch(); /* read the character */
if (k == '\0')
/* extended code -- get next byte */
getch();
}
}
Figure 7
========
#
# Program: Gdemo
#
.c.obj:
qcl -c -W2 -Ze -AM $*.c
gdemo.obj : gdemo.c
message.obj : message.c
Gdemo.exe : gdemo.obj message.obj
del Gdemo.lnk
echo gdemo.obj+ >>Gdemo.lnk
echo message.obj >>Gdemo.lnk
echo Gdemo.exe >>Gdemo.lnk
echo Gdemo.map >>Gdemo.lnk
link @Gdemo.lnk $(LDFLAGS);
Figure 8
========
# makefile for the GDEMO program
.c.obj:
cl -c -W2 -Ze -AL $*.c
gdemo.obj: gdemo.c
message.obj: message.c
gdemo.exe: gdemo.obj message.obj
link gdemo message, gdemo, nul, graphics;