/xenix: The SCO Computer Graphics Interface
©1988 - Richard A. Bilancia - All Rights Reserved
to be published first in the April 1988 issue of UNIX&reg/World

Many years ago, before I got very involved with small computer !!unix!!, I helped a small California based company port their graphics package to the Radio Shack TRS-80 Model II. Their software, originally written for the Radio Shack TRS-80 Model I, took output from a Visicalc spreadsheet (stored in DIF format) and created an extensive array of line, bar and pie charts. The resulting very high detail graphs could be printed on a fairly large number of different dot matrix printers, but could not be displayed on the very limited capabilities of the Model I and II monitors.

This application, as was common of many programs of the day, was written in a combination of BASIC and Z80 assembly code. Let me assure you, that without the variety of !!unix!! tools that I’ve long since become accustomed to using, porting this application was not a trivial exercise! Additionally, every time a line or circle had to be drawn (or any area had to filled with a different pattern) the program had to handle such operations without the help from any set of utilities or functions.

By today’s standards, this was the Dark Ages of computer graphics.

The early !!unix!! days

The original versions of !!unix!! were not much better suited than those early Radio Shack computers for handling graphics, as most of the terminals connected to a !!unix!! computer system had block graphics capability at best. Of course some Tektronics tools, like Version 7 !!unix!! **graph**, **plot**, and **spline**, as well as the **plot(3)** C functions were available, but these were not the truly interactive, user friendly tools that !!DOS!! users have come to love and enjoy.

Enter the AT&T !!unix!!/PC 7300, a computer that was technologically ahead of its time. Among its many and varied features, the AT&T !!unix!!/PC 7300 came with a bit mapped monitor managed by AT&T’s Virtual Device Interface. The heart of this interface was a package of graphic standards from Graphic Software Systems, Inc. (GSS). This same GSS software is now available to !!xenix!! users from the Santa Cruz Operation (SCO, Santa Cruz, CA).

Several months ago, SCO began shipping the SCO Computer Graphics Interface (CGI) with every copy of the SCO !!xenix!! System V/286 and 386 Development Systems. What is SCO CGI? It is really GSS*CGI, an improved and updated version of the same software from GSS that ran on the AT&T !!unix!!/PC 7300. It is a set of extremely powerful tools to aid software developers build applications that create graphic images. The resulting images can then be shown on a variety of standard display devices or printed on a variety of hard copy devices, at the developer’s or user’s choice.

What you get with SCO CGI

As I mentioned above, you automatically get SCO CGI when you purchase a copy of the SCO !!xenix!! System V/286 or 386 Development System. A complete SCO CGI manual is included that is divided into a Programmer’s Guide, a Device Driver Supplement, and a C Language Reference Guide.

In addition to the tools (C language functions) for developers to create graphic applications, SCO CGI includes seven separate graphics device drivers for the following equipment: the Apple Laser Writer printer, Enhanced Graphic Adapter (EGA) monitors, Computer Graphic Adapter (CGA) monitors, Epson MX/FX-80/100 printers, HP Plotters, the HP LaserJet printers, and the HP ThinkJet printer. Additionally, drivers are included for the GSS Metafile and GSS Grafstation standards. Early versions of the software did not include the EGA driver.

SCO CGI is only distributed with the !!xenix!! System V Development System. No drivers or tools are included in the basic !!xenix!! System V runtime package. If you develop a commercial application with SCO CGI, and would like to allow you customers to run the application on their !!xenix!! systems without requiring them to purchase a full Development System license, SCO offers a separate SCO Graphics Run Time Package.

An example on using SCO CGI

In order to better understand how to develop applications with SCO CGI, you will find an example C program in Listing 1. This program is a stripped down (to save space) version of a program originally developed for the AT&T !!unix!!/PC 7300 called **rose**. The original program, including source code, was distributed through AT&T’s unique software distribution method for the 7300 called "The STORE!" Only very minor modifications were require to get the program to compile and run under !!xenix!!.

If you’d like to try running the program, after using **custom** to install the two diskettes comprising SCO CGI on your !!xenix!! system, followed by keying in the **roce.c** source code, you can compile **rose.c** with the following command:

**cc -s -i -o rose rose.c -lccgi -lm**

Before executing **rose** you must inform SCO CGI about the certain graphic display and print devices attached to your !!xenix!! system. This is accomplished with **sh** environment variables. Since I have a color graphics adapter (CGA) monitor and an HP LaserJet Plus printer on my !!xenix!! system, I accomplish this environment variable setting by including the lines shown in Listing 2 in my **$HOME/.profile**. You may need to modify these lines slightly to satisfy the requirements of your installation.

Finally to execute **rose** simply type the program name **rose**, and the image shown in Figure 1 will be drawn on your CGA monitor. If you want the image to be printed instead, simply comment line 7 and uncomment line 8 of **rose.c** and recompile the program. You can also experiment with changing the values for the number of loops and the delta, lines 14 and 15, to get other interesting images.

Since I did not originally write **rose.c**, and commented code was not available to me, I’ll leave the understanding of the code and the use of the SCO CGI functions as an exercise for the reader. If you’d like a copy of the C source code in machine readable form, and have access to the UUCP system **mail** network, send me a note with your return electronic **mail** address and I’ll send you a copy.

The future of 386 !!xenix!! and graphics

One of the more recent historical strengths of the !!unix!! marketplace has been the prevalence of graphic workstations from companies like Sun Microsystems, Inc. When Graphic Software Systems, Inc. releases their !!xenix!! version of X-Windows, the evolving !!unix!! based graphic workstation interface standard, we may all be able to witness yet another significant phase in the ongoing evolution towards !!xenix!! on 386 systems.

Besides, now that you know how to start using SCO CGI perhaps you’ll write a graphics application for !!xenix!! that will make you rich and famous!

Listing 1

1

#include <stdio.h>
2

#include <math.h>
3

#define ldtor(x) ((float)(((((float)x)/360.0)*2.0)*3.1416))

4

5

short echo_xy[2] = { 0 , 0 };
6

short work_in[19] =
7

{0,1,2,1,1,1,1,1,1,0,1,’D’,’I’,’S’,’P’,’L’,’A’,’Y’,’ ’,};
8

/* {2,1,2,1,1,1,1,1,1,0,1,’P’,’R’,’I’,’N’,’T’,’E’,’R’,’ ’,}; */

9

10

main()

11

{
12

float r, oldx, oldy, newx, newy, offx, offy;
13

float vx,vy, mxy;
14

int lp = 45; /* loops */
15

int dt = 90; /* delta */
16

int t, tt, tl, x, x_pref,y_pref;
17

short rv, rc, dev_handle, work_out[66];
18

short pa[4], lobox[4], attrib[10];
19

char c[2];
20
21

rv = v_opnwk(work_in,&dev_handle,work_out);
22

if (rv != 0) {
23

fprintf(stderr,"vq_error=%d0,vq_error());
24

exit(-1);
25

}
26

vqt_attributes(dev_handle,attrib);
27

lobox[0] = lobox[1] = 0;
28

lobox[2] = work_out[51];
29

lobox[3] = attrib[9];
30

v_clrwk(dev_handle);
31

vx = work_out[51];
32

vy = work_out[52];
33

if (vx<vy) {
34

mxy = vx;
35

x_pref = 0;
36

y_pref = (vy-vx)/2;
37

}
38

else {
39

mxy = vy;
40

y_pref = 0;
41

x_pref = (vx-vy)/2;
42

}
43

if (x_pref < 0)
44

x_pref = 0;
45

if (y_pref < 0)
46

y_pref = 0;
47

v_clrwk(dev_handle);
48

rc = vsm_string(dev_handle,(short)1,(short)0,echo_xy,c);
49

while (rc > 0) {
50

rc = vsm_string(dev_handle,(short)1,(short)0,echo_xy,c);
51

}
52

t = tt = tl = 0;
53

oldx = offx = mxy/2;
54

oldy = offy = mxy/2;
55

while (tl < 360.0) {
56

t = tt;
57

do {
58

tl++;
59

t=(t+dt)%360;
60

x=(lp*t)%360;
61

r = sin(ldtor(x))*mxy;
62

newx = offx + ((r*cos(ldtor(t)))/2.0);
63

newy = offy + ((r*sin(ldtor(t)))/2.0);
64

pa[0] = oldx + x_pref;

65

pa[1] = oldy + y_pref;
66

pa[2] = newx + x_pref;
67

pa[3] = newy + y_pref;
68

v_pline(dev_handle,2,pa);
69

oldx=newx;
70

oldy=newy;
71

} while ( t != tt ) ;
72

tt++;
73

x=(lp*tt)%360;
74

r = sin(ldtor(x))*mxy;
75

oldx = offx + ((r*cos(ldtor(tt)))/2.0);
76

oldy = offy + ((r*sin(ldtor(tt)))/2.0);
77

}
78

sleep (5);
79

v_clswk(dev_handle);
80

}

Listing 2

1 :
2 #
3 # The following lines are required in your $HOME/.profile
4 # for the CGI Graphics Interface
5 #
6 if test "$TERM" = "ansi"
7 then
8 VDIPATH=/usr/lib/cgi
9 DISPLAY=’cgaco’
10 cgaco=‘tty‘
11 PRINTER=laserjet
12 laserjet=’| Laser’
13 export VDIPATH DISPLAY cgaco PRINTER laserjet
14 fi