source: buchla-68k/vlib/lseg.c@ f40d52b

Last change on this file since f40d52b was 109c83b, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Compiled full ROM in Hatari.

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[109c83b]1/*
2 ===========================================================================
3 LSEG.C -- Generalized line drawing function (Integer DDA algorithm)
4 Version 6 -- 1987-08-04 -- D.N. Lynx Crowe
5 Copyright 1985, 1986, 1987 -- D.N. Lynx Crowe
6 ===========================================================================
7*/
8
9short (*point)();
10
11#define ABS(x) ((x) < 0 ? (-(x)) : (x))
12#define SIGN(x) ((x) < 0 ? (-1) : ((x) ? 1 : 0))
13
14#define LE <=
15
16/*
17 =============================================================================
18 lseg(x1, y1, x2, y2, t) -- draw a line from ('x1', 'y1') to ('x2', 'y2')
19 in drawing mode 't'.
20
21 All coordinates are short integers in whatever plotting units the
22 'point' function expects. No clipping or scaling is done, as this is
23 the lowest level 'line' primitive in the drawing code, and coordinates
24 are expected to have already been checked and found to be on screen.
25
26 The 'point' variable must be initialized to point at the
27 pixel plotting function before this function is called. The pixel
28 plotting function is passed 3 arguments: the x coordinate, the y
29 coordinate, and the plotting mode. It is declared here as type 'short',
30 but any value it returns will be ignored.
31
32 The register variable assignments were chosen based on the Alcyon C
33 compiler for the Atari 1040ST and reflect the capabilities of that
34 compiler. Other compilers may require different optimizations based
35 on their use of register variables.
36 =============================================================================
37*/
38
39/*
40
41*/
42
43lseg(x1, y1, x2, y2, t)
44short x1, y1, x2, y2, t;
45{
46 register short dx, dy, ptx, pty, p;
47 short i, px, py;
48
49 p = x2 - (ptx = x1);
50 dx = SIGN(p);
51 py = ABS(p);
52
53 p = y2 - (pty = y1);
54 dy = SIGN(p);
55 px = ABS(p);
56
57 (*point)(ptx, pty, t);
58
59 if (py > px) {
60
61 p = py >> 1;
62
63 for (i = 1; i < py; i++) {
64
65 ptx += dx;
66
67 if ( (p -= px) < 0) {
68
69 pty += dy;
70 p += py;
71 }
72
73 (*point)(ptx, pty, t);
74 }
75
76 } else {
77
78 p = px >> 1;
79
80 for (i = 1; i LE px; i++) {
81
82 pty += dy;
83
84 if ( (p -= py) < 0) {
85
86 ptx += dx;
87 p += px;
88 }
89
90 (*point)(ptx, pty, t);
91 }
92 }
93}
Note: See TracBrowser for help on using the repository browser.