1*13339Ssam #ifndef lint 2*13339Ssam static char sccsid[] = "@(#)subr.c 4.1 (Berkeley) 06/27/83"; 3*13339Ssam #endif 4*13339Ssam 5*13339Ssam #include <stdio.h> 6*13339Ssam #include "con.h" 7*13339Ssam abval(q) 8*13339Ssam { 9*13339Ssam return (q>=0 ? q : -q); 10*13339Ssam } 11*13339Ssam 12*13339Ssam xconv (xp) 13*13339Ssam { 14*13339Ssam /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */ 15*13339Ssam xp += 2048; 16*13339Ssam /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */ 17*13339Ssam return (xoffset + xp /xscale); 18*13339Ssam } 19*13339Ssam 20*13339Ssam yconv (yp) 21*13339Ssam { 22*13339Ssam /* see description of xconv */ 23*13339Ssam yp += 2048; 24*13339Ssam return (yp / yscale); 25*13339Ssam } 26*13339Ssam 27*13339Ssam inplot() 28*13339Ssam { 29*13339Ssam stty(OUTF, &PTTY); 30*13339Ssam spew(ESC); 31*13339Ssam spew (INPLOT); 32*13339Ssam } 33*13339Ssam 34*13339Ssam outplot() 35*13339Ssam { 36*13339Ssam spew(ESC); 37*13339Ssam spew(ACK); 38*13339Ssam spew(ESC); 39*13339Ssam spew(ACK); 40*13339Ssam fflush(stdout); 41*13339Ssam stty (OUTF, &ITTY); 42*13339Ssam } 43*13339Ssam 44*13339Ssam spew(ch) 45*13339Ssam { 46*13339Ssam putc(ch, stdout); 47*13339Ssam } 48*13339Ssam 49*13339Ssam tobotleft () 50*13339Ssam { 51*13339Ssam move(-2048,-2048); 52*13339Ssam } 53*13339Ssam reset() 54*13339Ssam { 55*13339Ssam outplot(); 56*13339Ssam exit(); 57*13339Ssam } 58*13339Ssam 59*13339Ssam float 60*13339Ssam dist2 (x1, y1, x2, y2) 61*13339Ssam { 62*13339Ssam float t,v; 63*13339Ssam t = x2-x1; 64*13339Ssam v = y1-y2; 65*13339Ssam return (t*t+v*v); 66*13339Ssam } 67*13339Ssam 68*13339Ssam swap (pa, pb) 69*13339Ssam int *pa, *pb; 70*13339Ssam { 71*13339Ssam int t; 72*13339Ssam t = *pa; 73*13339Ssam *pa = *pb; 74*13339Ssam *pb = t; 75*13339Ssam } 76*13339Ssam 77*13339Ssam #define DOUBLE 010 78*13339Ssam #define ADDR 0100 79*13339Ssam #define COM 060 80*13339Ssam #define MAXX 070 81*13339Ssam #define MAXY 07 82*13339Ssam extern xnow,ynow; 83*13339Ssam #define SPACES 7 84*13339Ssam movep(ix,iy){ 85*13339Ssam int dx,dy,remx,remy,pts,i; 86*13339Ssam int xd,yd; 87*13339Ssam int addr,command; 88*13339Ssam char c; 89*13339Ssam if(xnow == ix && ynow == iy)return; 90*13339Ssam inplot(); 91*13339Ssam dx = ix-xnow; 92*13339Ssam dy = iy-ynow; 93*13339Ssam command = COM|PENUP|((dx<0)<<1)|(dy<0); 94*13339Ssam dx = abval(dx); 95*13339Ssam dy = abval(dy); 96*13339Ssam xd = dx/(SPACES*2); 97*13339Ssam yd = dy/(SPACES*2); 98*13339Ssam pts = xd<yd?xd:yd; 99*13339Ssam if((i=pts)>0){ 100*13339Ssam c=command|DOUBLE; 101*13339Ssam addr=ADDR; 102*13339Ssam if(xd>0)addr|=MAXX; 103*13339Ssam if(yd>0)addr|=MAXY; 104*13339Ssam spew(c); 105*13339Ssam while(i--){ 106*13339Ssam spew(addr); 107*13339Ssam } 108*13339Ssam } 109*13339Ssam if(xd!=yd){ 110*13339Ssam if(xd>pts){ 111*13339Ssam i=xd-pts; 112*13339Ssam addr=ADDR|MAXX; 113*13339Ssam } 114*13339Ssam else{ 115*13339Ssam i=yd-pts; 116*13339Ssam addr=ADDR|MAXY; 117*13339Ssam } 118*13339Ssam c=command|DOUBLE; 119*13339Ssam spew(c); 120*13339Ssam while(i--){ 121*13339Ssam spew(addr); 122*13339Ssam } 123*13339Ssam } 124*13339Ssam remx=dx-xd*SPACES*2; 125*13339Ssam remy=dy-yd*SPACES*2; 126*13339Ssam addr=ADDR; 127*13339Ssam i = 0; 128*13339Ssam if(remx>7){ 129*13339Ssam i=1; 130*13339Ssam addr|=MAXX; 131*13339Ssam remx -= 7; 132*13339Ssam } 133*13339Ssam if(remy>7){ 134*13339Ssam i=1; 135*13339Ssam addr|=MAXY; 136*13339Ssam remy -= 7; 137*13339Ssam } 138*13339Ssam while(i--){ 139*13339Ssam spew(command); 140*13339Ssam spew(addr); 141*13339Ssam } 142*13339Ssam if(remx>0||remy>0){ 143*13339Ssam spew(command); 144*13339Ssam spew(ADDR|remx<<3|remy); 145*13339Ssam } 146*13339Ssam xnow=ix; 147*13339Ssam ynow=iy; 148*13339Ssam outplot(); 149*13339Ssam return; 150*13339Ssam } 151*13339Ssam xsc(xi){ 152*13339Ssam int xa; 153*13339Ssam xa = (xi - obotx) * scalex + botx; 154*13339Ssam return(xa); 155*13339Ssam } 156*13339Ssam ysc(yi){ 157*13339Ssam int ya; 158*13339Ssam ya = (yi - oboty) *scaley +boty; 159*13339Ssam return(ya); 160*13339Ssam } 161