|
|
1.1 root 1: /*************************************************************************\
2: * Module Name: Lines.cxx
3: *
4: * C template for the ASM version of the line DDA calculator.
5: * contains the C code associated with the c++ code (c++ does not handle
6: * READ/WRITE_REGISTER to well
7: *
8: * Copyright (c) 1993 Microsoft Corporation
9: * Copyright (c) 1992 Digital Equipment Corporation
10: \**************************************************************************/
11:
12: #include "driver.h"
13: #include "lines.h"
14:
15: #define S3_MAX_INT_LINE 0x800
16: #define DEFAULT_DRAW_CMD DRAW_LINE | \
17: DRAW | \
18: DIR_TYPE_XY | \
19: MULTIPLE_PIXELS | \
20: WRITE | \
21: LAST_PIXEL_OFF
22:
23:
24: /******************************************************************************
25: * bIntegerLine
26: *
27: *
28: * This routine attempts to draw a line segment between two points. It
29: * will only draw if both end points are whole integers: it does not support
30: * fractional endpoints.
31: *
32: * Returns:
33: * TRUE if the line segment is drawn
34: * FALSE otherwise
35: *****************************************************************************/
36:
37: BOOL
38: bIntegerLine (
39: PPDEV ppdev,
40: ULONG X1,
41: ULONG Y1,
42: ULONG X2,
43: ULONG Y2
44: )
45: {
46: LONG Cmd;
47: LONG DeltaX, DeltaY;
48: LONG ErrorTerm;
49: LONG Major, Minor;
50:
51:
52:
53: X1 >>= 4;
54: Y1 >>= 4;
55: X2 >>= 4;
56: Y2 >>= 4;
57:
58: Cmd = DEFAULT_DRAW_CMD | PLUS_Y | PLUS_X | MAJOR_Y;
59:
60: DeltaX = X2 - X1;
61: if (DeltaX < 0) {
62: DeltaX = -DeltaX;
63: Cmd &= ~PLUS_X;
64: }
65: DeltaY = Y2 - Y1;
66: if (DeltaY < 0) {
67: DeltaY = -DeltaY;
68: Cmd &= ~PLUS_Y;
69: }
70:
71: // Compute the major drawing axis
72:
73: if (DeltaX > DeltaY) {
74: Cmd &= ~MAJOR_Y;
75: Major = DeltaX;
76: Minor = DeltaY;
77: } else {
78: Major = DeltaY;
79: Minor = DeltaX;
80: }
81:
82:
83: // Tell the S3 to draw the line
84:
85: FIFOWAIT (FIFO_7_EMPTY);
86: OUTPW (CUR_X, X1);
87: OUTPW (CUR_Y, Y1);
88: OUTPW (LINE_MAX, Major);
89: OUTPW (AXSTP, Minor * 2);
90: OUTPW (DIASTP, 2 * Minor - 2 * Major);
91:
92:
93: // Adjust the error term so that 1/2 always rounds down, to
94: // conform with GIQ.
95:
96: ErrorTerm = 2 * Minor - Major;
97: if (Cmd & MAJOR_Y) {
98: if (Cmd & PLUS_X) {
99: ErrorTerm--;
100: }
101: } else {
102: if (Cmd & PLUS_Y) {
103: ErrorTerm--;
104: }
105: }
106:
107: OUTPW (ERR_TERM, ErrorTerm);
108: OUTPW (CMD, Cmd);
109:
110:
111: // Wait until the S3 has finished drawing, and return success
112: // to the caller
113:
114: GPWAIT();
115: return TRUE;
116:
117: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.