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

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

Zero redundant declarations.

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