CPLOT, a Graphics Package for Tektronix terminals.
by Graeme Elsworthy, Adrian Freed and Richard Grevis.
CPLOT contains a set of C procedures, designed to make interactive
graphics programs easy to write and fast to run.
1. Reference Manual
This manual describes the "cplot" graphics library which was
designed with Tektronics terminals and the C language in mind. It is
now firmly based on the standard i/o library and uses it internally.
1.1 Co‐ordinate Systems
Locations on the screen can be addressed absolutely or relatively in one
of two co‐ordinate systems; screen and user.
Screen co‐ordinates are those required by the Tektronix terminals
themselves. i.e.
0 <= x <= 1023,
0 <= y <= 780,
x and y integers.
User co‐ordinates are chosen by the user’s program itself, by calling
UWINDOW. UWINDOW, requires the upper and lower bounds of x and y, as floating
variables. Most calls consist of their base name prefixed by a ’u’ or an ’s’
(which indicate which co‐ordinate frame is to be used) and a suffix of an ’a’
or an ’r’ to indicate absolute or relative plotting mode respectively.
Arguments are float’s for calls to user co‐ordinate routines and int’s for
calls to screen routines.
1.2 Basic calls
INIT( OUTFILE ) required as first call to CPLOT to initialize terminal for
graphics. OUTFILE is a standard i/o file pointer where the plotting output is
to be put. Normally it would be "stdout". The screen is not erased.
FINISH() required as last call to CPLOT to set terminal for normal use.
ERASE() clears terminal screen.
HOME() puts the graphics cursor at top left of screen.
1.3 Defining the windows
SWINDOW( XLO, XHI, YLO, YHI ) defines the area of the screen to be used for
graphics.
0 <= XLO < XHI <= 1023,
0 <= YLO < YHI <= 780,
XLO, XHI, YLO, YHI integers.
‐1 is returned on error and 0 if the window is valid.
UWINDOW( XLO, XHI, YLO, YHI ) defines user co‐ordinate system, which is a
window mapped onto the screen window.
XLO != XHI,
YLO != YHI,
XLO, XHI, YLO, YHI floating.
‐1 is returned if these conditions are not met, 0 if they are.
1.4 Graphics calls
[US]MOVE[AR]( X, Y ) moves cursor to X, Y.
[US]DRAW[AR]( X, Y ) draws a vector from current cursor position to X, Y,
leaving cursor at X, Y.
[US]DASH[AR]( X, Y, TYPE ) draws a dashed vector of the required type.
[US]POINT[AR]( X, Y ) puts a point at X, Y, leaving cursor at X, Y
1.5 Cursor Position
The following calls find the position of the virtual cursor in either
screen or user space. This is not necessarily the cursor’s physical position
on the screen, as the last vector may have been off the screen.
[US]WHERE( &X, &Y ) puts the user cursor position in float’s whose addresses
are given.
1.6 Cross‐hair Cursors
The following calls are available for use on terminals with cross‐hair
cursors.
[US]CURSOR( &X, &Y ) puts cross‐hair cursors on screen and returns its co‐
ordinates, when a character is recieved.
The value of the function is the character that was typed. CURSOR() puts the
cross‐hair cursors on the terminal screen, but does not perform any read.
1.7 Status Enquiry
The following calls continuously return terminal status and current
cursor position without waiting for a user response.
[US]ENQ( &X, &Y ) enquiry. Returns the current cursor position and the
terminal status if the terminal supports the option.
1.8 Alpha‐numerics
The following calls can be used to conveniently intermix alphanumerics
and graphics.
ALPHA() puts terminal in alphanumeric mode. Only required if non‐CPLOT
alphanumerics is wanted.
[US]XPUTS[AR]( X, Y, &STRING ) prints STRING horizontally, starting at the
point X, Y. The graphics cursor is unchanged. [US]YPUTS[AR]( X, Y, &STRING )
prints STRING vertically downwards from X, Y.
1.9 Linking to the Library
CPLOT consists of a set of user calls for the functions described above,
which themselves call routines to do the basic terminal manipulation.
Although these support routines are available, it is strongly recommended that
they not be used.
Programs using the library must include the file "cplot.h" as some
routines are implemented as macros. This file also includes the standard i/o
library include file "stdio.h".
CPLOT is available as an object code library (the linker knows it
as ‐lt), which is linked to the users program in the usual way.
e.g cc prog.c ‐lt ‐lS
1.10 Library Modifications
This document and a source code listing of the library are available, but
the authors of the library would like to be advised of any modifications and
improvements that individual users might make, so that it can be continually
improved, for the benefit of all users.
A separate library of additional functions is being maintained, which
initially contains routines to draw circles, rectangles, triangles and arcs.
#include <stdio.h>
FILE *debf;
/* CPLOT, A graphics package for Tektronix terminals.
By Adrian Freed, Richard Grevis, and Graeme Elsworthy.
*/
#define FF 12
#define NUM_DASHES 10
#define GS 29 /* Graphics mode */
#define SYNC 026
#define US 31 /* Alpha mode */
#define MASK 037 /* 00011111 */
#define ESC 033 /* Control code preamble */
#define BELL 07
#define ENQUIRE "\033\005"
#define BOTTOM 2,1
#define CURSORS "\033\032"
#define CURSREAD "\033\032"
#define ALPHA 1
#define ONSCREEN 2
#define USER 4
#define SCREEN 010
#define DASHMOVE 010000
#define HIY 0040 /* 100000 */
#define LOY 0140 /* 1100000 */
#define HIX 0040 /* 100000 */
#define LOX 0100 /* 1000000 */
#define CURSBUFSIZE 8
#define HOMEX 0
#define HOMEY 767 /* Home Co-ordinates */
#define SXMAX 1023
#define SYMAX 780 /* Max. Screen positions */
#define YCHSZ 22 /* Character height */
#define XCHSZ 14 /* Character width */
/* TTY masks */
#define MAPCASE 04
#define ECHO 010
#define LFCR 020
#define RAWMODE 040
#define NLDELAY 01400
#define FF1 040000
#define DEGTORAD 0.01745329
float g_xlo, g_ylo, g_xhi, g_yhi; /* User space descriptors */
int g_sxlo, g_sylo, g_sxhi, g_syhi; /* Screen descriptors */
float g_sxtrans, g_sytrans, g_uxtrans, g_uytrans;
int g_spx, g_spy; /* Current screen position */
int g_sax, g_say;
float g_px, g_py; /* Current user Co-ord. position */
int g_sqx1, g_sqy1; /* First solved point */
int g_sqx2, g_sqy2; /* Second solved point */
int g_b1, g_b2, g_b3, g_b4; /* Bytes to be drawn */
int g_nekmod;
int g_term;
/*
** The global variables used with the dash line routines
*/
int g_scan;
float g_dashbit ;
float g_xpos, g_ypos;
extern g_dashtable[NUM_DASHES][4];
float g_xold, g_yold;
FILE *g_out;
struct g_ttystruct
{
char ispeed, ospeed;
char e, k;
int mode;
} g_ttybuf, g_ttyb, g_outbuf;
int g_syncs;
int g_positioned;
/* SCALE AND ROTATION ON RELATIVE MOVES AND DRAWS */
float g_xsin, g_ysin, g_xcos, g_ycos;
float g_xscale, g_yscale;
int g_status,g_last;
/*
** This structure allocates the bit representation
** of a data word in the software character set.
*/
struct schar
{
int vstat :1;
int deltax :6;
int deltay :6;
};
#define erase() ( g_put(ESC), g_put(FF),g_status =| ALPHA, g_status =& ~ONSCREEN )
#define bell() ( g_alpha(), g_put( BELL ) )
#define smovea(x,y) ( g_spx = (x), g_spy = (y), g_status =& ~(USER|ONSCREEN) )
#define home() smovea(HOMEX, HOMEY )
#define syncs(x) ( g_syncs = (x) )
#define sdrawr(x,y) sdrawa( g_spx + (x), g_spy + (y) )
#define sdashr(x,y,t) sdasha( g_spx + (x), g_spy + (y) , (t))
#define spointr(x,y) spointa( g_spx + (x), g_spy + (y) )
#define upointr( x,y ) ( g_status & USER ) ?0: g_chtusr( g_spx, g_spy ), upointa( g_px+x, g_py+y )
#define umovea(x,y) ( g_chtscr( g_px = (x), g_py = (y) ), g_status =| (USER), g_status =& ~ONSCREEN )
#define udrawr(x,y) ( ( g_status & USER ) ?0: g_chtusr( g_spx, g_spy ), udrawa(g_px + (x),g_py + (y)) )
#define udashr(x,y,t) ( ( g_status & USER ) ?0: g_chtusr( g_spx, g_spy ), udasha(g_px + (x),g_py + (y), (t)) )
#define cursor() ( g_alpha(), fputs( CURSORS, stderr) )
#define swhere(x,y) ( *(x) = g_spx, *(y) = g_spy )
#define uwhere(x,y) ( (g_status & USER ) ?0: g_chtusr( g_spx, g_spy ), *(x) = g_px, *(y) = g_py )
#define sxputsr(x,y,s) sxputsa( g_spx + (x), g_spy + (y), s )
#define uxputsr(x,y,s) uxputsa( g_spx + (x), g_spy + (y), s )
#define syputsr(x,y,s) syputsa( g_spx + (x), g_spy + (y), s )
#define uyputsr(x,y,s) uyputsa( g_spx + (x), g_spy + (y), s )
|