1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
32 /*LINTLIBRARY*/
33
34 #include <stdlib.h>
35 #include <math.h>
36 #include "con.h"
37
38 int ynow = 0;
39
40 static void
iline(int cx0,int cy0,int cx1,int cy1)41 iline(int cx0, int cy0, int cx1, int cy1) {
42 int maxp, tt;
43 char chx, chy, command;
44 float xd, yd;
45 movep(cx0, cy0);
46 maxp = (int)(sqrt(dist2(cx0, cy0, cx1, cy1)) / 2.);
47 xd = cx1 - cx0;
48 yd = cy1 - cy0;
49 command = COM|((xd < 0) << 1)|(yd < 0);
50 if (maxp == 0) {
51 xd = 0;
52 yd = 0;
53 } else {
54 xd /= maxp;
55 yd /= maxp;
56 }
57 inplot();
58 spew(command);
59 for (tt = 0; tt <= maxp; tt++) {
60 chx = (char)(cx0 + xd * tt - xnow);
61 xnow += chx;
62 chx = abs(chx);
63 chy = (char)(cy0 + yd * tt - ynow);
64 ynow += chy;
65 chy = abs(chy);
66 spew(ADDR|chx<<3|chy);
67 }
68 outplot();
69 }
70
71 void
line(short x0,short y0,short x1,short y1)72 line(short x0, short y0, short x1, short y1) {
73 iline(xconv(xsc(x0)), yconv(ysc(y0)), xconv(xsc(x1)), yconv(ysc(y1)));
74 }
75
76 void
cont(short x0,short y0)77 cont(short x0, short y0) {
78 iline(xnow, ynow, xconv(xsc(x0)), yconv(ysc(y0)));
79 }
80