148522Sbostic /*-
2*61403Sbostic * Copyright (c) 1983, 1993
3*61403Sbostic * The Regents of the University of California. All rights reserved.
448522Sbostic *
548522Sbostic * %sccs.include.proprietary.c%
648522Sbostic */
748522Sbostic
813339Ssam #ifndef lint
9*61403Sbostic static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 06/04/93";
1048522Sbostic #endif /* not lint */
1113339Ssam
1213339Ssam #include <stdio.h>
1313339Ssam #include "con.h"
abval(q)1413339Ssam abval(q)
1513339Ssam {
1613339Ssam return (q>=0 ? q : -q);
1713339Ssam }
1813339Ssam
xconv(xp)1913339Ssam xconv (xp)
2013339Ssam {
2113339Ssam /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */
2213339Ssam xp += 2048;
2313339Ssam /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
2413339Ssam return (xoffset + xp /xscale);
2513339Ssam }
2613339Ssam
yconv(yp)2713339Ssam yconv (yp)
2813339Ssam {
2913339Ssam /* see description of xconv */
3013339Ssam yp += 2048;
3113339Ssam return (yp / yscale);
3213339Ssam }
3313339Ssam
inplot()3413339Ssam inplot()
3513339Ssam {
3613339Ssam stty(OUTF, &PTTY);
3713339Ssam spew(ESC);
3813339Ssam spew (INPLOT);
3913339Ssam }
4013339Ssam
outplot()4113339Ssam outplot()
4213339Ssam {
4313339Ssam spew(ESC);
4413339Ssam spew(ACK);
4513339Ssam spew(ESC);
4613339Ssam spew(ACK);
4713339Ssam fflush(stdout);
4813339Ssam stty (OUTF, &ITTY);
4913339Ssam }
5013339Ssam
spew(ch)5113339Ssam spew(ch)
5213339Ssam {
5313339Ssam putc(ch, stdout);
5413339Ssam }
5513339Ssam
tobotleft()5613339Ssam tobotleft ()
5713339Ssam {
5813339Ssam move(-2048,-2048);
5913339Ssam }
reset()6013339Ssam reset()
6113339Ssam {
6213339Ssam outplot();
6313339Ssam exit();
6413339Ssam }
6513339Ssam
6657886Storek double
dist2(x1,y1,x2,y2)6713339Ssam dist2 (x1, y1, x2, y2)
6813339Ssam {
6913339Ssam float t,v;
7013339Ssam t = x2-x1;
7113339Ssam v = y1-y2;
7213339Ssam return (t*t+v*v);
7313339Ssam }
7413339Ssam
swap(pa,pb)7513339Ssam swap (pa, pb)
7613339Ssam int *pa, *pb;
7713339Ssam {
7813339Ssam int t;
7913339Ssam t = *pa;
8013339Ssam *pa = *pb;
8113339Ssam *pb = t;
8213339Ssam }
8313339Ssam
8413339Ssam #define DOUBLE 010
8513339Ssam #define ADDR 0100
8613339Ssam #define COM 060
8713339Ssam #define MAXX 070
8813339Ssam #define MAXY 07
8913339Ssam extern xnow,ynow;
9013339Ssam #define SPACES 7
movep(ix,iy)9113339Ssam movep(ix,iy){
9213339Ssam int dx,dy,remx,remy,pts,i;
9313339Ssam int xd,yd;
9413339Ssam int addr,command;
9513339Ssam char c;
9613339Ssam if(xnow == ix && ynow == iy)return;
9713339Ssam inplot();
9813339Ssam dx = ix-xnow;
9913339Ssam dy = iy-ynow;
10013339Ssam command = COM|PENUP|((dx<0)<<1)|(dy<0);
10113339Ssam dx = abval(dx);
10213339Ssam dy = abval(dy);
10313339Ssam xd = dx/(SPACES*2);
10413339Ssam yd = dy/(SPACES*2);
10513339Ssam pts = xd<yd?xd:yd;
10613339Ssam if((i=pts)>0){
10713339Ssam c=command|DOUBLE;
10813339Ssam addr=ADDR;
10913339Ssam if(xd>0)addr|=MAXX;
11013339Ssam if(yd>0)addr|=MAXY;
11113339Ssam spew(c);
11213339Ssam while(i--){
11313339Ssam spew(addr);
11413339Ssam }
11513339Ssam }
11613339Ssam if(xd!=yd){
11713339Ssam if(xd>pts){
11813339Ssam i=xd-pts;
11913339Ssam addr=ADDR|MAXX;
12013339Ssam }
12113339Ssam else{
12213339Ssam i=yd-pts;
12313339Ssam addr=ADDR|MAXY;
12413339Ssam }
12513339Ssam c=command|DOUBLE;
12613339Ssam spew(c);
12713339Ssam while(i--){
12813339Ssam spew(addr);
12913339Ssam }
13013339Ssam }
13113339Ssam remx=dx-xd*SPACES*2;
13213339Ssam remy=dy-yd*SPACES*2;
13313339Ssam addr=ADDR;
13413339Ssam i = 0;
13513339Ssam if(remx>7){
13613339Ssam i=1;
13713339Ssam addr|=MAXX;
13813339Ssam remx -= 7;
13913339Ssam }
14013339Ssam if(remy>7){
14113339Ssam i=1;
14213339Ssam addr|=MAXY;
14313339Ssam remy -= 7;
14413339Ssam }
14513339Ssam while(i--){
14613339Ssam spew(command);
14713339Ssam spew(addr);
14813339Ssam }
14913339Ssam if(remx>0||remy>0){
15013339Ssam spew(command);
15113339Ssam spew(ADDR|remx<<3|remy);
15213339Ssam }
15313339Ssam xnow=ix;
15413339Ssam ynow=iy;
15513339Ssam outplot();
15613339Ssam return;
15713339Ssam }
xsc(xi)15813339Ssam xsc(xi){
15913339Ssam int xa;
16013339Ssam xa = (xi - obotx) * scalex + botx;
16113339Ssam return(xa);
16213339Ssam }
ysc(yi)16313339Ssam ysc(yi){
16413339Ssam int ya;
16513339Ssam ya = (yi - oboty) *scaley +boty;
16613339Ssam return(ya);
16713339Ssam }
168