Dec 092017
Graphing (plotting) routine for use with CGA (color graphics adapter).
File GRAPHPC.ZIP from The Programmer’s Corner in
Category Printer + Display Graphics
Graphing (plotting) routine for use with CGA (color graphics adapter).
File Name File Size Zip Size Zip Type
GRAPH.DOC 14812 5877 deflated
GRAPHPC.EXE 55808 31287 deflated

Download File GRAPHPC.ZIP Here

Contents of the GRAPH.DOC file

graph - plot a tabulated function

graph [file file file] [options]

Graph takes pairs of points (two numbers per line) from the given
file (or standard input) as x- and y- values and plots them on the
screen, connected by straight lines. A string surrounded by quotes
"..." may follow a pair of points, and will be displayed starting
at that point. The program draws axes with convenient labels
(integers times powers of 1000), plots the data, waits for a
keypress, then resets the screen parameters and clears the screen
before exiting. If data is taken from standard input (possibly
redirected) the key pressed must be a carriage return.

Blank lines and lines beginning with ';' are ignored.

More than one input file can be specified. All the data will
be read before scaling parameters are calculated. The plot
will be "broken" at the end of each file. That is, there will
be no line connecting the last point of the first file with the
first point of the second file. Similarly, if a line starts
with a null byte (that is, if a line feed is followed by a
null) the plot will be broken. Separate curves may also be
delimited with labels (see the -b switch).

The -m switch can be used to select the line style or marker
style for each curve. If both markers and connecting lines are
wanted, list the data file twice and specify different styles.
For example,

graph gamma gamma -m 1 -30

would give red squares connected by white solid lines.

If graph is interrupted with a control-C, it may leave the
display in a nonstandard mode. This can sometimes be fixed by
running graph a second time and letting it exit normally.

Graph is available in several versions for different hardware.
When necessary for configuration control, these versions are
given different file names (see FILES section below). It is
suggested that the "normal" version for a given computer be
renamed GRAPH for simplicity. Two measures are taken to ensure
no damage is done by inadvertently executing the wrong version.
First, any version of graph can be executed with a question
mark as the only parameter:


It will then print a help screen which indicates the hardware
it supports, and exit immediately. Second, graph tests that
the hardware it needs is present before using it (except for
the plotter and laser printer versions). The test is a
permissive one, so that "clones" are likely to work. However,
it can be fooled. For example, the Paradise EGA Autoswitch
video card can emulate the Hercules monochrome graphics card,
but only when connected to a monochrome monitor. If the
Hercules version of graph is used with this card and an EGA
color monitor, nothing is displayed.

The following modes are supported on the IBM CGA:
The mode is specified by setting the environment variable
GRAPHICS before running graph:

SET GRAPHICS=4; 320*200 color mode
SET GRAPHICS=5; 320*200 grey scale mode
SET GRAPHICS=6 ; 640*200 monochrome mode (the default)

The terminology above is IBM's, but note that a color monitor
connected to the 15 pin connector on the IBM color graphics
adaptor will display color even in graphics mode 5. A
composite color monitor connected to the RCA jack will display
color only in mode 4.

The IBM Enhanced Graphics Adaptor (EGA) is supported in modes
16 (640*350 color) and 15 (640*350 monochrome). Only one page is
used. At least 128K of memory is assumed, so that 16 colors are
supported. If only 64K is installed, graph should still work but
only 4 colors will be displayed.

The EGA version of GRAPH (starting with interface version 1.3) also
supports the IBM Video Graphics Array (VGA) in modes 17 (640*480
monochrome) and 18 (640*480*16 colors). The device controller
assumes a VGA is present if EGA support is present and it finds the
string "IBM" at address c800:0026. A VGA clone which lacks this
string may still be used by setting the environment as follows:

SET GRAPHICS=17 ; 640*480 monochrome
SET GRAPHICS=18 ; 640*480*16 colors

Conversely, a VGA may be used in an EGA mode (to permit a graphics
screen dump, for example) by setting the environment as follows:

SET GRAPHICS=15 ; 640*350 monochrome
SET GRAPHICS=16 ; 640*350*16 colors

The Hercules monochrome graphics card is supported in its
graphics mode (naturally). Only page 0 (memory addresses
b0000-b7fff) is used, so another video adaptor which is mapped
into memory above b8000 (such as an IBM CGA) can also be
present. The card is left in mode HALF (page 1 disabled).

Similarly, these modes are supported on the Z-100:

SET GRAPHICS=1 ; 640*225 mode (the default)
SET GRAPHICS=2 ; 640*400 mode

On many Z-100s, the video card has 32K memory chips. 64K chips are
required for the 640*400 mode. In addition, a monitor with a
slowly decaying phosphor is recommended.

For the Houstin Instruments plotter, HP plotter, or LIPS-10
laser printer versions, the output port may be specified by
setting an environment variable:

SET plot_port=COM1 (the default)
SET plot_port=COM2
SET plot_port=PRN

Alternately, the output can be saved in a file for later use:

SET plot_port=c:\path\filename

The device driver asks about several other options: pen speed,
margins (or pen displacement before plotting begins), width and
height of desired plotting area.

The HP plotter version assumes an RS-232 connection with
hardware flow control: The plotter pulls pin 20 (DTR) low to
stop data transmission. Other conditions are set to their
defaults. To implement this, HP recommends wiring a "null
modem" RS-232 cable which exchanges pins 2 and 3, and connects pin
20 on each end to pins 5 and 6 on the opposite end. A second
adaptor cable may be used to connect the null modem cable to the
9-pin connector on an IBM PC serial adaptor, or the two functions
may be combined in a single cable. The cable schematics are as

IBM plotter
9-pin 25-pin 25-pin DTE
chassis ground .. -------- 1 --------- 1 chassis ground
signal ground 5 -------- 7 --------- 7 signal ground
DTR 4 ------> 20 -----+--> 5 CTS
+--> 6 DSR
CTS 8 <------- 5 <--+---- 20 DTR
DSR 6 <------- 6 <--+
TxD 3 -------> 2 --------> 3 RxD
RxD 2 <------- 3 <-------- 2 TxD

The IBM BIOS serial port handler will stop transmitting data when
requested. However, it interprets the signal as an error, and
prompts the operator with the message

Not ready error writing to COM1:
Abort, Retry, Ignore?

Type "r" to continue plotting.

By default, the HP plotter is initialized with the character string

DF; .R

If necessary, a replacement string may be specified using the
environment variable "plot_setup". As with the PROMPT command
in MS-DOS, the device driver interprets the sequence "$e" to
represent an ASCII escape character. For example, the default
setup string could be specified using the following command:

SET plot_setup=DF; $e.R

The LIPS-10 version clears all macros and all fonts while
initializing to maximize the memory space available, with the
setup string


As with the HP plotter version, the environment variable
plot_setup can be set to a replacement string. For example,
"DAM;" or "DAF;" can be omitted to preserve the macros or
fonts, respectively.

Options can appear before, among, or after input file names
provided a file name cannot be mistaken for the parameter of an

-a [ []]
Automatically generate abscissas. The first argument,
if present, is the step between values (default 1).
The second argument, if present, is the starting value
(default 0, or first argument from -x switch).

-b break (disconnect) the plot after each label. (See
switch -m to plot the line segments with different
linestyles. To break the plot without printing labels,
use empty labels: "".) This option is set automatically
if more than one input file or more than one linestyle
is specified.

-c argument is default label for data points

-eequal vertical and horizontal scales (same number of
inches on the display per unit in problem space), so that
circles don't look like elipses

-f More parameters are in the script file . This
can be used for lists of parameters (filenames and/or
switches) that are too long for a command line. The
parameters in the script file have the same format as
those on the command line, but may be separated by
linefeeds as well as spaces or tabs. More than one -f
switch may appear on the command line, and script files
may refer to other script files to any depth. For
example, if the file "curves" contains the line
parabola elipse circle
and the file "options" contains the lines
-g -e
-m 20 30 40
then the command
A>graph -f curves -f options
is equivalent to
A>graph parabola elipse circle -g -e -m 20 30 40

-g-g with no arguments eliminates the grid.