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

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

Prototypes for global function pointers. Consistent global types.

  • Property mode set to 100644
File size: 2.1 KB
Line 
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
9void (*point)(short x, short y, short pen);
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
43void lseg(short x1, short y1, short x2, short y2, short t)
44{
45 register short dx, dy, ptx, pty, p;
46 short i, px, py;
47
48 p = x2 - (ptx = x1);
49 dx = SIGN(p);
50 py = ABS(p);
51
52 p = y2 - (pty = y1);
53 dy = SIGN(p);
54 px = ABS(p);
55
56 (*point)(ptx, pty, t);
57
58 if (py > px) {
59
60 p = py >> 1;
61
62 for (i = 1; i < py; i++) {
63
64 ptx += dx;
65
66 if ( (p -= px) < 0) {
67
68 pty += dy;
69 p += py;
70 }
71
72 (*point)(ptx, pty, t);
73 }
74
75 } else {
76
77 p = px >> 1;
78
79 for (i = 1; i LE px; i++) {
80
81 pty += dy;
82
83 if ( (p -= py) < 0) {
84
85 ptx += dx;
86 p += px;
87 }
88
89 (*point)(ptx, pty, t);
90 }
91 }
92}
Note: See TracBrowser for help on using the repository browser.