home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MS DOS Archives 1
/
MS-DOS_Archives_Volume_One_Walnut_Creek.iso
/
msdos
/
graphics
/
hgrph101.arc
/
HGRAPH.ASC
< prev
next >
Wrap
Text File
|
1989-02-25
|
54KB
|
2,245 lines
HGRAPH.LIB V1.01
HGRAPH.LIB is a collection of subroutines to give Hercules
graphics capability to MSC and QuickC and are better than MSC's &
QuickC's in that they just have to be linked in. They do not
require a driver to be loaded like with MSC & QC.
This is version 1.01 release of these routines. They have
been compiled and tested only on a Leading Edge Model "D" which
has a hercules clone card in it. The only known difference
between this clone card and a real Hercules card is that this
clone fakes the light pen port (if you try to read its lightpen
port for the graphics state it always returns text mode).
INTRODUCTION
The lib includes clearing and non-clearing subroutines to
switch between text and graphics modes. A clear page and show
page for clearing and switching between the two graphics pages.
A pixel routine to read, write, and toggle a pixel. Two line
subroutines one to draw a line in either white or black and one
to toggle a line. And three string writing functions, one that
treats the graphics screen as 43 rows and 90 columns while the
other two let you define the upper left corner of where the
string is to be written. There are also a save screen and a
restore screen, similar to BASIC's BSAVE & BLOAD and a print
screen routine for Epson printers. All the routines that write
to the graphics screen are written in MSC MASM 5.1 for greater
speed. The screen dump routines do their own buffering also for
this reason.
USAGE
There is now a XHGRAPH.LIB library for each memory model,
where X is the model (S, M, C, L). So you must link with the
library of the same type model as the program was compiled with.
The only restriction in using the libraries is that You must call
hgraph_init() before using any of the other routines.
i
HGRAPH.LIB V1.01
The rest of the documentation is a list of library routines
and what they do. The appendix holds a couple of examples and a
few programing tips. The libraries are release into the public
domain with the following restrictions:
1) That they only be transmitted from one person to
the next in a complete and unmodified form.
2) That the libraries, documentation, and algorithms
remain copy righted to me, Steven P. Murphy.
3) No warranties are expressed or implied. I am not
responsible for the use, misuse, or abuse of these
libraries.
Any comments, suggestions, or bugs should be reported to:
Steven P. Murphy
6581 Bing St.
San Diego, CA 92115-6715
or
murphys@cod.nosc.mil (USENET)
And for those you who really like HGRAPH donations will not
be refused.
ii
HGRAPH.LIB V1.01
All the routines treat the graphics screen as a grid of dots
except hwrite and hstr which treat it as a set of rows and
columns. For all the routines except hwrite and hstr the screen
dimension are as follows:
0 719
0 -----------------------------------------------
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
347 -----------------------------------------------
for hwrite and hstr the screen is:
0 89
0 -----------------------------------------------
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
42 -----------------------------------------------
The conversion from rows & columns to dots is each row is eight
dots height and each column is eight dots wide.
iii
HGRAPH.LIB V1.01
TABLE OF CONTENTS
h_get_scrn . . . . . . . . . . . . . . . . . . 1
h_sav_scrn . . . . . . . . . . . . . . . . . . 2
hbox . . . . . . . . . . . . . . . . . . 3
hchar . . . . . . . . . . . . . . . . . . 4
hchar2 . . . . . . . . . . . . . . . . . . 5
hclearpg . . . . . . . . . . . . . . . . . . 6
hellipse . . . . . . . . . . . . . . . . . . 7
herc_there . . . . . . . . . . . . . . . . . . 8
hgmode . . . . . . . . . . . . . . . . . . 9
hgmode_nc . . . . . . . . . . . . . . . . . . 10
hgraph_init . . . . . . . . . . . . . . . . . . 11
hline . . . . . . . . . . . . . . . . . . 12
hpixel . . . . . . . . . . . . . . . . . . 13
hscdump . . . . . . . . . . . . . . . . . . 14
hscdump2 . . . . . . . . . . . . . . . . . . 15
hshowpg . . . . . . . . . . . . . . . . . . 16
hstr . . . . . . . . . . . . . . . . . . 17
htmode . . . . . . . . . . . . . . . . . . 18
htmode_nc . . . . . . . . . . . . . . . . . . 19
hwrite . . . . . . . . . . . . . . . . . . 20
hxchar . . . . . . . . . . . . . . . . . . 21
hxchar2 . . . . . . . . . . . . . . . . . . 22
hxline . . . . . . . . . . . . . . . . . . 23
hxstr . . . . . . . . . . . . . . . . . . 24
Appendix A . . . . . . . . . . . . . . . . . . 25
cornucopia.c . . . . . . . . . . . . . . . . 26
demo1.c . . . . . . . . . . . . . . . . 27
Appendix B . . . . . . . . . . . . . . . . . . 28
programing ideas . . . . . . . . . . . . . . 29
iv
HGRAPH.LIB V1.01
H_GET_SCRN
Summary
#include <hgraph.h> Contains function prototypes
int h_get_scrn(file_name);
char *file_name /* name of file to get the */
/* image from */
Description
Opens file_name for reading in binary mode and copies
32K bytes from file_name to graphics page 0 or 1
according to the current value of HGPAGE (see
hgraph_init).
Return Value
H_get_scrn returns a -1 if it could not successfully
open file_name other wise it will return a 0.
See Also
h_sav_scrn
1
HGRAPH.LIB V1.01
H_SAV_SCRN
Summary
#include <hgraph.h> Contains function prototypes
int h_sav_scrn(file_name);
char *file_name /* name of file to store */
/* image in */
Description
Opens file_name for writing in binary mode and copies
32K bytes from graphics page 0 or 1 according to the
current value of HGPAGE (see hgraph_init).
Return Value
H_sav_scrn returns a -1 if it could not successfully
open file_name other wise it will return a 0.
See Also
h_get_scrn
2
HGRAPH.LIB V1.01
HBOX
Summary
#include <hgraph.h> Contains function prototypes
void hbox(color, trow, lcol, brow, rcol);
int color; /* should only be a 1 or 0 */
int trow; /* toprow 0 through 347 */
int lcol; /* left column 0 through 718 */
int brow; /* bottom row 1 through 348 */
int rcol; /* right column 1 through 719 */
Description
Draws a box on page 0 or 1 according to the current
value of HGPAGE (see hgraph_init). Hbox calls hline
four time arranging the arguments each time so that a
box is drawn where (trow, lcol) defines the upper left
corner and (brow, rcol) is the lower right. Hbox does
no bounds checking so bad ranges will produce weird
results.
Return Value
There is no return value.
See Also
hline
3
HGRAPH.LIB V1.01
HCHAR
Summary
#include <hgraph.h> Contains function prototypes
void hchar(x, y, string, attrib, count);
int x; /* 0 through 719 */
int y; /* 0 through 347 */
char *string; /* ASCII 0 through 127 */
char attrib; /* HGNORM or HGINVS */
int count; /* number of chars in string */
Description
Writes the upper left most corner of the string pointed
to by string at the coordinates given after each
character has been XORed with attrib. Hchar writes to
the graphics page according to the current value of
HGPAGE (see hgraph_init). There is no bounds checking
done on x and y so numbers outside of range will give
unknown results (probably not good). Hchar uses the
IBM PC/XT/AT ROM character table. This table only has
ASCII characters 0 through 127, values outside this
range will give garbage. The attrib is xor with the
character's bits on each scan line, values other than
HGNORM (normal) and HGINVS (inverse) will just produce
odd patterns. Count tells hchar how many of string's
characters to plot. MSC regular run-time LIB has a
functions strlen() and gcvt(), strlen() will produce a
correct count and gcvt() will convert numbers to a
string.
Return Value
There is no return value.
See Also
hchar2, hstr, hwrite, hxchar, hxchar2, hxstr
MSC's or QuickC's strlen() and gcvt()
4
HGRAPH.LIB V1.01
HCHAR2
Summary
#include <hgraph.h> Contains function prototypes
void hchar2(x, y, string, attrib, count);
int x; /* 0 through 719 */
int y; /* 0 through 347 */
char *string; /* ASCII 0 through 127 */
char attrib; /* HGNORM or HGINVS */
int count; /* number of chars in string */
Description
Writes the upper left most corner of the string pointed
to by string at the coordinates given after each
character has been XORed with attrib. Hchar2 writes to
the graphics page according to the current value of
HGPAGE (see hgraph_init). There is no bounds checking
done on x and y so numbers outside of range will give
unknown results (probably not good). Hchar2's
character table only has ASCII characters 0 through
127, values outside this range will give garbage. The
attrib is xor with the character's bits on each scan
line, values other than HGNORM (normal) and HGINVS
(inverse) will just produce odd patterns. Count tells
hchar2 how many of string's characters to plot. MSC
regular run-time LIB has a functions strlen() and
gcvt(), strlen() will produce a correct count and
gcvt() will convert numbers to a string.
Return Value
There is no return value.
See Also
hchar, hstr, hwrite, hxchar, hxchar2, hxstr
MSC's or QuickC's strlen() and gcvt()
5
HGRAPH.LIB V1.01
HCLEARPG
Summary
#include <hgraph.h> Contains function prototypes
void hclearpg(void);
Description
Clears graphics page 0 or 1 according to the current
value of HGPAGE (see hgraph_init).
Return Value
There is no return value.
See Also
hgmode, hgmode_nc
6
HGRAPH.LIB V1.01
HELLIPSE
Summary
#include <hgraph.h> Contains function prototypes
void hellipse(color, x, y, r);
Description
Draws and ellipse on graphics page 0 or 1 according to
the current value of HGPAGE (see hgraph_init) centered
at (x, y) with a radius of r. the ellipse will have an
aspect ratio of the current value of (int) HGRATIO. If
the ratio is < 2 the major axis will be vertical, if it
is > 2 the major axis will be horizontal, and if
HGRATIO = 2 hellipse will produces the closes it can to
a circle. no bounds checking is done if any part of
the ellipse is off the screen weird things may happen.
Return Value
There is no return value
See Also
7
HGRAPH.LIB V1.01
HERC_THERE
Summary
#include <hgraph.h> Contains function prototypes
int herc_there(void);
Description
First it tests for a mono display adapter, if there is
one it then watches port 3BA (hex) for a fixed time to
see if bit 7 goes high. If bit 7 does go high it then
pushes a 3 out port 3BF (hex) to turn on the second
page of the herc card. Now it checks for memory in the
second page. If this check is good it's a herc other
wise it's just a funny mono card. Before it returns it
pushes a 0 out port 3BF to return a herc card to
diagonal mode.
Return Value
Herc_there returns a one if both of the above test are
true and a zero if either is false. (I have tested
this with my clone card, an EGA, a CGA, and a mono
adapter, it worked correctly in all cases.)
See Also
8
HGRAPH.LIB V1.01
HGMODE
Summary
#include <hgraph.h> Contains function prototypes
void hgmode(void);
Description
Sets graphics mode, clears graphic pages 0 and 1 then
switches to graphics page 0.
Return Value
There is no return value.
See Also
hgmode_nc
9
HGRAPH.LIB V1.01
HGMODE_NC
Summary
#include <hgraph.h> Contains function prototypes
void hgmode_nc(void);
Description
Sets graphics mode, does not clears graphic pages 0 and
1 then switches to graphics page 0.
Return Value
There is no return value.
See Also
hgmode
10
HGRAPH.LIB V1.01
HGRAPH_INIT
Summary
#include <hgraph.h> Contains function prototypes
void hgraph_init(void);
Description
Initializes the necessary global variables for
HGRAPH.LIB. These variables are:
int HGPAGE; /* current graphics page, used by all */
/* the library routines */
char HGATRB; /* character attribute for hwrite */
int HGRATIO; /* aspect ratio for hellipse */
The initial values for are HGPAGE = 1, HGATRB = 0x00,
and HGRATIO = 2. HGPAGE should only be 1 or 0 if it is
set to some value other than these two all the routine
will default it to 1. HGATRB should only be HGNORM or
HGINVS (defined in hgraph.h) other values will just
cause the print to look funny. HGRATIO should be a
positive int, 0 will cause it to draw a horizontal
line, and a negative will hellipse to crash.
Return Value
There is no return value.
See Also
11
HGRAPH.LIB V1.01
HLINE
Summary
#include <hgraph.h> Contains function prototypes
void hline(function, x0, y0, x1, y1);
int function; /* 0 - write pixels in black */
/* 1 - write pixels in white */
int x0; /* 0 through 719 */
int y0; /* 0 through 347 */
int x1; /* 0 through 719 */
int y1; /* 0 through 347 */
Description
The default for function is 1, so if hline is called
with function not equal to those listed you get
function 1. The graphics page is set according to the
current value of HGPAGE (see hgraph_init). There is no
bounds checking done on x0, x1, y0, or y1 so numbers
outside of range will give unknown results (probably
not good).
Return Value
There is no return value.
See Also
hxline
12
HGRAPH.LIB V1.01
HPIXEL
Summary
#include <hgraph.h> Contains function prototypes
void hpixel(function, x, y);
int function; /* 0 - write pixel in black */
/* 1 - write pixel in white */
/* 2 - toggle pixel */
/* 3 - read pixel */
int x; /* 0 through 719 */
int y; /* 0 through 347 */
Description
The default for function is 2, so if hpixel is called
with function not equal to those listed you get
function 2. The pixel is plotted on the graphics page
according to the current value of HGPAGE (see
hgraph_init). There is no bounds checking done on x
and y so numbers outside of range will give unknown
results (probably not good).
Return Value
The return value is the status the pixel was set to by
any of the four functions. So hpixel while always
return a 0 (for black) or a 1 (for white).
See Also
13
HGRAPH.LIB V1.01
HSCDUMP
Summary
#include <hgraph.h> Contains function prototypes
void hscdump(void);
Description
Dumps graphics page 0 or 1, according to the current
value of HGPAGE (see hgraph_init), to an Epson or
compatible printer. Each line is double struck to
improve the clarity.
Return Value
There is no return value.
See Also
hscdump2
14
HGRAPH.LIB V1.01
HSCDUMP2
Summary
#include <hgraph.h> Contains function prototypes
void hscdump2(void);
Description
Dumps graphics page 0 or 1, according to the current
value of HGPAGE (see hgraph_init), to an Epson or
compatible printer. Each line is only single struck to
improve the speed.
Return Value
There is no return value.
See Also
hscdump
15
HGRAPH.LIB V1.01
HSHOWPG
Summary
#include <hgraph.h> Contains function prototypes
void hshowpg(void);
Description
Set graphics page 0 or 1, according to the current
value of HGPAGE (see hgraph_init), to the currently
displayed page.
Return Value
There is no return value.
See Also
hgmode, hgmode_nc
16
HGRAPH.LIB V1.01
HSTR
Summary
#include <hgraph.h> Contains function prototypes
void hstr(column, row, string, attrib, count);
int column; /* 0 through 89 */
int row; /* 0 through 42 */
char *string; /* pointer to the string */
char attrib; /* HGNORM or HGINVS */
int count; /* number of chars in string */
Description
Writes the string pointed to by string at the row and
column given after each character has been XORed with
attrib. The graphics page written to is set according
to the current value of HGPAGE (see hgraph_init).
There is no bounds checking done on column and row so
numbers outside of range will give unknown results
(probably not good). Hstr's character table only has
ASCII characters 0 through 127, values outside this
range will give garbage. The attrib is xor with the
character's bits on each scan line, values other than
HGNORM (normal) and HGINVS (inverse) will just produce
odd patterns. Count tells hstr how many of string's
characters to plot. MSC regular run-time LIB has a
functions strlen() and gcvt(), strlen() will produce a
correct count and gcvt() will convert numbers to a
string so they can be printed.
Return Value
There is no return value.
See Also
hchar, hchar2, hwrite, hxchar, hxchar2, hxstr
MSC's or QuickC's strlen() and gcvt()
Note:
This is the fastest of hstr, hchar, and hchar2 for
writing strings because it operates on byte boundaries.
Only if you really need to write at a particular pixel
location should hchar or hchar2 be used and of these
two hchar2 is the better (only because its character
table is internal, the same as hstr, so it is
guaranteed to work on all machines).
17
HGRAPH.LIB V1.01
HTMODE
Summary
#include <hgraph.h> Contains function prototypes
void htmode(void);
Description
Sets text mode, clears graphic pages 0 and 1 then
switches to text page.
Return Value
There is no return value.
See Also
htmode_nc
18
HGRAPH.LIB V1.01
HTMODE_NC
Summary
#include <hgraph.h> Contains function prototypes
void htmode_nc(void);
Description
Sets text mode, does not clears graphic pages 0 and 1
then switches to text page.
Return Value
There is no return value.
See Also
htmode
19
HGRAPH.LIB V1.01
HWRITE
Summary
#include <hgraph.h> Contains function prototypes
int hwrite(row, col, string);
int row; /* 0 through 42 */
int col; /* 0 through 89 */
char *string; /* pointer to the string */
Description
Write string starting at (row, col) using the attribute
value of HGATRB (see hgraph_init). The string is
written to the graphics page set according to the
current value of HGPAGE (see hgraph_init). Hwrite
checks for bounds on both row and col, if the start of
the string is not on the screen the string will not be
written. If the string runs off the right edge it will
just be truncated to avoid errors. MSC regular run-
time LIB has a function gcvt() which will convert
numbers to a string so they can be printed.
Return Value
Hwrite will return a 1 if it wrote any thing on the
screen (truncated or not) or a 0 if (row, col) was off
the screen (nothing written).
See Also
hchar, hchar2, hstr, hxchar, hxchar2, hxstr
MSC's or QuickC's gcvt()
20
HGRAPH.LIB V1.01
HXCHAR
Summary
#include <hgraph.h> Contains function prototypes
void hxchar(x, y, string, attrib, count);
int x; /* 0 through 719 */
int y; /* 0 through 347 */
char *string; /* ASCII 0 through 127 */
char attrib; /* HGNORM or HGINVS */
int count; /* number of chars in string */
Description
XORs string starting at the upper left most corner of
the string pointed to by string at the coordinates
given after each character has been XORed with attrib.
Hxchar writes to the graphics page set by the current
value of HGPAGE (see hgraph_init). There is no bounds
checking done on x and y so numbers outside of range
will give unknown results (probably not good). Hxchar
uses the IBM PC/XT/AT ROM character table. This table
only has ASCII characters 0 through 127, values outside
this range will give garbage. The attrib is xor with
the character's bits before it is xored to the screen,
values other than HGNORM (normal) and HGINVS (inverse)
for attrib will just produce odd patterns. Count tells
hchar how many of string's characters to plot. MSC
regular run-time LIB has a functions strlen() and
gcvt(), strlen() will produce a correct count and
gcvt() will convert numbers to a string.
Return Value
There is no return value.
See Also
hchar, hchar2, hstr, hwrite, hxchar2, hxstr
MSC's or QuickC's strlen() and gcvt()
21
HGRAPH.LIB V1.01
HXCHAR2
Summary
#include <hgraph.h> Contains function prototypes
void hxchar2(x, y, string, attrib, count);
int x; /* 0 through 719 */
int y; /* 0 through 347 */
char *string; /* ASCII 0 through 127 */
char attrib; /* HGNORM or HGINVS */
int count; /* number of chars in string */
Description
XORs string starting at the upper left most corner of
the string pointed to by string at the coordinates
given after each character has been XORed with attrib.
Hxchar2 writes to the graphics page according to the
current value of HGPAGE (see hgraph_init). There is no
bounds checking done on x and y so numbers outside of
range will give unknown results (probably not good).
Hxchar2's character table only has ASCII characters 0
through 127, values outside this range will give
garbage. The attrib is xor with the character's bits
before it is xored to the screen, values other than
HGNORM (normal) and HGINVS (inverse) for attrib will
just produce odd patterns. Count tells hxchar2 how
many of string's characters to plot. MSC regular run-
time LIB has a functions strlen() and gcvt(), strlen()
will produce a correct count and gcvt() will convert
numbers to a string.
Return Value
There is no return value.
See Also
hchar, hchar2, hstr, hwrite, hxchar, hxstr
MSC's or QuickC's strlen() and gcvt()
22
HGRAPH.LIB V1.01
HXLINE
Summary
#include <hgraph.h> Contains function prototypes
void hxline(x0, y0, x1, y1);
int x0; /* 0 through 719 */
int y0; /* 0 through 347 */
int x1; /* 0 through 719 */
int y1; /* 0 through 347 */
Description
Toggles the status of all the pixels along the given
line. The graphics page is set according to the
current value of HGPAGE (see hgraph_init). There is no
bounds checking done on x0, x1, y0, or y1 so numbers
outside of range will give unknown results (probably
not good).
Return Value
There is no return value.
See Also
hline
23
HGRAPH.LIB V1.01
HXSTR
Summary
#include <hgraph.h> Contains function prototypes
void hxstr(column, row, string, attrib, count);
int column; /* 0 through 89 */
int row; /* 0 through 42 */
char *string; /* pointer to the string */
char attrib; /* HGNORM or HGINVS */
int count; /* number of chars in string */
Description
XORs the string pointed to by string at the row and
column given after each character has been XORed with
attrib. The graphics page written to is set according
to the current value of HGPAGE (see hgraph_init).
There is no bounds checking done on column and row so
numbers outside of range will give unknown results
(probably not good). Hstr's character table only has
ASCII characters 0 through 127, values outside this
range will give garbage. The attrib is xor with the
character's bits before it is xored to the screen,
values other than HGNORM (normal) and HGINVS (inverse)
will just produce odd patterns. Count tells hstr how
many of string's characters to plot. MSC regular run-
time LIB has a functions strlen() and gcvt(), strlen()
will produce a correct count and gcvt() will convert
numbers to a string so they can be printed.
Return Value
There is no return value.
See Also
hchar, hchar2, hstr, hwrite, hxchar, hxchar2
MSC's or QuickC's strlen() and gcvt()
Note:
This is the fastest of hxstr, hxchar, and hxchar2 for
writing strings because it operates on byte boundaries.
Only if you really need to write at a particular pixel
location should hxchar or hxchar2 be used and of these
two hxchar2 is the better (only because its character
table is internal, the same as hxstr, so it is
guaranteed to work on all machines).
24
HGRAPH.LIB V1.01
Appendix A
(examples)
25
HGRAPH.LIB V1.01
/* CORNUCOPIA -- see article on "pseudo-hidden line removal" */
/* IBM-PC Exchange, May-June 1986 */
#include <math.h>
#include <conio.h>
#include <hgraph.h>
main()
{
int d, a0, b0, a1, b1, a, b;
double r, rada, radb;
hgraph_init();
hgmode_nc();
hclearpg();
hshowpg();
hstr(40, 1, " CORNUCOPIA ", 0xff, 12);
for (d = 1; d <= 100; ++d)
{
rada = (float)d;
radb = 0.65 * rada;
a0 = 20 + 4 * d;
b0 = 20 + 2 * d + (int)(radb * 0.6 * sin(d/10.0));
hline(0, a0, b0, a1 = a0, b1 = b0 + (int)radb);
for (r = 0.0; r < 6.3; r += 6.28/40.0)
{
a = a0 + (int)(rada * sin(r));
b = b0 + (int)(radb * cos(r));
hline(1, a1, b1, a, b);
hline(0, a0, b0, a1 = a, b1 = b);
}
}
/* This next section flips back and forth from
* text to graphics three time to show the use of the
* non-clearing hgmode_nc & htmode_nc the user must hit a
* key to cause the flip
*/
hstr(10, 40, "Press any key to continue ... ", 0x00, 30);
getch();
htmode_nc();
puts("Press any key to continue ... ");
getch();
hgmode_nc(); hshowpg();
getch();
htmode_nc();
getch();
hgmode_nc(); hshowpg();
getch();
htmode(); /* this will clear the text screen */
}
26
HGRAPH.LIB V1.01
/* DEMO.C - a demo of hgraph.lib's string writing routines */
#include <string.h>
#include <conio.h>
#include <hgraph.h>
char string[40] = "HGRAPH.LIB";
main()
{
int ct;
char c;
ct = strlen(string);
hgraph_init();
hgmode_nc();
hclearpg();
hshowpg();
hstr(40, 1, string, HGINVS, ct);
hstr(20, 10,
"This is a demo of hstr, hchar, and hchar2", HGNORM, 41);
hstr(10, 20,
"This is a sample of hstr with normal attrib", HGNORM,43);
hstr(10, 21,
"This is a sample of hstr with inverse attrib", HGINVS,44);
hchar(80, 200,
"This is a sample of hchar with normal attrib", HGNORM,44);
hchar(80, 209,
"This is a sample of hchar with inverse attrib",HGINVS,45);
hchar2(80, 240,
"This is a sample of hchar2 with normal attrib",HGNORM,45);
hchar2(80, 249,
"This is a sample of hchar2 with inverse attrib",HGINVS,46);
hstr(10, 40,
"Press any key to continue ...", HGNORM, 29);
getch();
htmode_nc();
}
27
HGRAPH.LIB V1.01
Appendix B
(programing ideas)
28
HGRAPH.LIB V1.01
There are three ways to do screen swapping with these
libraries to make it appear that you have a a full screen type
window package. I will start with the easiest and work up to
what I would consider the best. There is one thing to keep in
mind, the text screen uses the same memory as the first half of
graphics page 0. This fact must be consider when using
hgmode_nc() and htmode_nc() because if you have written stuff to
the text screen and then go to graphics page 0 there will be
garbage on the top half of the monitor. The same is true if you
do graphics on page 0 and switch to text with out clearing there
will be trash all over the text screen.
1) If you do all your graphics on page 1 (the
default) you could use C's standard functions (i.e
printf, puts, ...) to write to the text screen
(you don't have to leave graphics mode to do
this). This way you could have graphics displayed
and a help screen written to the text screen so if
the user hit F1 you could call htmode_nc() and the
help screen would appear, and then another key
would call hgmode_nc() and the graphics would
reappear. The only problem with this is a half to
three quarters of a second delay built into both
htmode_nc() and hgmode_nc() this will cause
approximately a one second delay in switching form
one screen to another.
2) There are two undocumented routines in hgraph.lib.
void h_scrn_in( unsigned char *)
void h_scrn_out( unsigned char *)
where unsigned char * is a pointer to a
buffer of at least 32768 bytes.
The first, h_scrn_in reads the screen defined by
HGPAGE and stores it into the buffer it was passed
as an argument. The second, h_scrn_out copies the
first 32767 bytes from the buffer it was passed as
an argument to the screen defined by HGPAGE. So
in the middle of doing graphics the user hits a
key for help, the program would use h_scrn_in to
save a copy of the current screen. Then it would
call hclearpg followed by hwrite to display help
messages. When the user wanted to switch back
just call h_scrn_out and rewrite the image back.
29
HGRAPH.LIB V1.01
3) What I feel is the best is to use one graphics
page for graphics and one graphics page for help.
All that would have to be done is to reset HGPAGE
and then call hshowpg to swap between the two.
The code in the library to figure out which page
and to set it is only ten lines in assembly.
30