1 /*
2 
3     3DKIT   version   1.3
4     High speed 3D graphics and rendering library for Linux.
5 
6     Copyright (C) 1996, 1997  Paul Sheer   psheer@icon.co.za
7 
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Library General Public
10     License as published by the Free Software Foundation; either
11     version 2 of the License, or (at your option) any later version.
12 
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16     Library General Public License for more details.
17 
18     You should have received a copy of the GNU Library General Public
19     License along with this library; if not, write to the Free
20     Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21     MA 02111-1307, USA
22 
23 */
24 
25 #ifdef lookup
26 #undef lookup
27 #endif
28 
29 #if (TRI_BPP==8) || !defined(INTERP)
30 #define lookup(x) x
31 #else
32 #define lookup(x) _color_lookup[x]
33 #endif
34 
35 
36 #ifdef assignvp
37 #undef declarevp
38 #undef assignvp
39 #undef assignvpoffset
40 #undef incvp
41 #undef incvpoffset
42 #undef decvp
43 #undef decvpoffset
44 #endif
45 
46 
47 #if TRI_BPP==8
48 #define declarevp declarevp8
49 #define assignvp assignvp8
50 #define assignvpoffset assignvpoffset8
51 #define incvp incvp8
52 #define incvpoffset incvpoffset8
53 #define decvp decvp8
54 #define decvpoffset decvpoffset8
55 #endif
56 #if TRI_BPP==16
57 #define declarevp declarevp16
58 #define assignvp assignvp16
59 #define assignvpoffset assignvpoffset16
60 #define incvp incvp16
61 #define incvpoffset incvpoffset16
62 #define decvp decvp16
63 #define decvpoffset decvpoffset16
64 #endif
65 #if TRI_BPP==24
66 #define declarevp declarevp24
67 #define assignvp assignvp24
68 #define assignvpoffset assignvpoffset24
69 #define incvp incvp24
70 #define incvpoffset incvpoffset24
71 #define decvp decvp24
72 #define decvpoffset decvpoffset24
73 #endif
74 #if TRI_BPP==32
75 #define declarevp declarevp32
76 #define assignvp assignvp32
77 #define assignvpoffset assignvpoffset32
78 #define incvp incvp32
79 #define incvpoffset incvpoffset32
80 #define decvp decvp32
81 #define decvpoffset decvpoffset32
82 #endif
83 
84 
85 #ifdef color
86 #undef color
87 #endif
88 
89 #ifdef WRAP
90 #ifdef INTERP
91 #define color \
92     (dat[(xd >> SHLB) + (yd & S_MASK)] + (c >> (SHLB + SHC)))
93 #else
94 #define color \
95     (dat[(xd >> SHLB) + (yd & S_MASK)] + c)
96 #endif
97 #else
98 #ifdef INTERP
99 #define color \
100     (c >> (SHLB + SHC))
101 #else
102 #define color \
103     c
104 #endif
105 #endif
106 
107 
108 /* these are actually all the same except for 8 */
109 #if TRI_BPP==8
colhline_neg_setpixel8(void)110 static void colhline_neg_setpixel8 (void)
111 #endif
112 #if TRI_BPP==16
113 static void colhline_neg_setpixel16 (void)
114 #endif
115 #if TRI_BPP==24
116 static void colhline_neg_setpixel24 (void)
117 #endif
118 #if TRI_BPP==32
119 static void colhline_neg_setpixel32 (void)
120 #endif
121 {
122     int count, y = py + dy0, x1 = px1 + dx0, x2 = px2 + dx0;
123     if (__clip) {
124 	if (y < __clipy1 || y > __clipy2)
125 	    return;
126 	if (x1 > __clipx2 + 1) {
127 #ifdef WRAP
128 	    xd -= (x1 - __clipx2 - 1) * xd_x;
129 	    yd -= (x1 - __clipx2 - 1) * yd_x;
130 #endif
131 #ifdef INTERP
132 	    c -= (x1 - __clipx2 - 1) * c_x;
133 #endif
134 	    x1 = __clipx2 + 1;
135 	}
136 	if (x2 < __clipx1) {
137 	    x2 = __clipx1;
138 	}
139     }
140     count = x1 - x2;
141     if (count > 0) {
142 	do {
143 	    _tri_drawpoint (--x1, y, lookup(color));
144 #ifdef WRAP
145 	    yd -= yd_x;
146 	    xd -= xd_x;
147 #endif
148 #ifdef INTERP
149 	    c -= c_x;
150 #endif
151 	} while (--count);
152     }
153 }
154 
155 
156 #if TRI_BPP==8
colhline_pos_setpixel8(void)157 static void colhline_pos_setpixel8 (void)
158 #endif
159 #if TRI_BPP==16
160 static void colhline_pos_setpixel16 (void)
161 #endif
162 #if TRI_BPP==24
163 static void colhline_pos_setpixel24 (void)
164 #endif
165 #if TRI_BPP==32
166 static void colhline_pos_setpixel32 (void)
167 #endif
168 {
169     int count, y = py + dy0, x1 = px1 + dx0, x2 = px2 + dx0;
170     if (__clip) {
171 	if (y < __clipy1 || y > __clipy2)
172 	    return;
173 	if (x1 < __clipx1) {
174 #ifdef WRAP
175 	    xd += (__clipx1 - x1) * xd_x;
176 	    yd += (__clipx1 - x1) * yd_x;
177 #endif
178 #ifdef INTERP
179 	    c += (__clipx1 - x1) * c_x;
180 #endif
181 	    x1 = __clipx1;
182 	}
183 	if (x2 > __clipx2 + 1) {
184 	    x2 = __clipx2 + 1;
185 	}
186     }
187     count = x2 - x1;
188     if (count > 0) {
189 	do {
190 	    _tri_drawpoint (x1++, y, lookup(color));
191 #ifdef WRAP
192 	    yd += yd_x;
193 	    xd += xd_x;
194 #endif
195 #ifdef INTERP
196 	    c += c_x;
197 #endif
198 	} while (--count);
199     }
200 }
201 
202 #ifndef DO_NOT_USE_VGALIB
203 /*draw to 64k vga buffer setting vga page appropriately: */
204 
205 #if TRI_BPP==8
colhline_neg_paged8(void)206 static void colhline_neg_paged8 (void)
207 #endif
208 #if TRI_BPP==16
209 static void colhline_neg_paged16 (void)
210 #endif
211 #if TRI_BPP==24
212 static void colhline_neg_paged24 (void)
213 #endif
214 #if TRI_BPP==32
215 static void colhline_neg_paged32 (void)
216 #endif
217 {
218     int count, y = py + dy0, x1 = px1 + dx0, x2 = px2 + dx0;
219     unsigned short offst;
220     int pg;
221     declarevp;
222     long vp = 0;
223     if (__clip) {
224 	if (y < __clipy1 || y > __clipy2)
225 	    return;
226 
227 	if (x1 > __clipx2 + 1) {
228 #ifdef WRAP
229 	    xd -= (x1 - __clipx2 - 1) * xd_x;
230 	    yd -= (x1 - __clipx2 - 1) * yd_x;
231 #endif
232 #ifdef INTERP
233 	    c -= (x1 - __clipx2 - 1) * c_x;
234 #endif
235 	    x1 = __clipx2 + 1;
236 	}
237 	if (x2 < __clipx1) {
238 	    x2 = __clipx1;
239 	}
240     }
241     count = x1 - x2;
242     assignvpoffset (x1, y, vp);
243     pg = vp >> 16;
244     vga_setpage (pg);
245     offst = vp;
246     if (count > 0) {
247 	do {
248 	    decvpoffset;
249 #ifdef WRAP
250 	    yd -= yd_x;
251 	    xd -= xd_x;
252 #endif
253 #ifdef INTERP
254 	    c -= c_x;
255 #endif
256 	} while (--count);
257     }
258 }
259 
260 
261 #if TRI_BPP==8
colhline_pos_paged8(void)262 static void colhline_pos_paged8 (void)
263 #endif
264 #if TRI_BPP==16
265 static void colhline_pos_paged16 (void)
266 #endif
267 #if TRI_BPP==24
268 static void colhline_pos_paged24 (void)
269 #endif
270 #if TRI_BPP==32
271 static void colhline_pos_paged32 (void)
272 #endif
273 {
274     int count, y = py + dy0, x1 = px1 + dx0, x2 = px2 + dx0;
275     unsigned short offst;
276     int pg;
277     declarevp;
278     long vp = 0;
279     if (__clip) {
280 	if (y < __clipy1 || y > __clipy2)
281 	    return;
282 
283 	if (x1 < __clipx1) {
284 #ifdef WRAP
285 	    xd += (__clipx1 - x1) * xd_x;
286 	    yd += (__clipx1 - x1) * yd_x;
287 #endif
288 #ifdef INTERP
289 	    c += (__clipx1 - x1) * c_x;
290 #endif
291 	    x1 = __clipx1;
292 	}
293 	if (x2 > __clipx2 + 1) {
294 	    x2 = __clipx2 + 1;
295 	}
296     }
297     count = x2 - x1;
298     assignvpoffset (x1, y, vp);
299     pg = vp >> 16;
300     vga_setpage (pg);
301     offst = vp;
302     if (count > 0) {
303 	do {
304 	    incvpoffset;
305 #ifdef WRAP
306 	    yd += yd_x;
307 	    xd += xd_x;
308 #endif
309 #ifdef INTERP
310 	    c += c_x;
311 #endif
312 	} while (--count);
313     }
314 }
315 
316 
317 #else
318 
319 
320 /*draw to 64k vga buffer setting vga page appropriately: */
321 
322 #if TRI_BPP==8
colhline_neg_paged8(void)323 static void colhline_neg_paged8 (void)
324 #endif
325 #if TRI_BPP==16
326 static void colhline_neg_paged16 (void)
327 #endif
328 #if TRI_BPP==24
329 static void colhline_neg_paged24 (void)
330 #endif
331 #if TRI_BPP==32
332 static void colhline_neg_paged32 (void)
333 #endif
334 {
335 }
336 
337 
338 #if TRI_BPP==8
colhline_pos_paged8(void)339 static void colhline_pos_paged8 (void)
340 #endif
341 #if TRI_BPP==16
342 static void colhline_pos_paged16 (void)
343 #endif
344 #if TRI_BPP==24
345 static void colhline_pos_paged24 (void)
346 #endif
347 #if TRI_BPP==32
348 static void colhline_pos_paged32 (void)
349 #endif
350 {
351 }
352 
353 
354 #endif
355 
356 /*draw to a linear address space (320x200 or virtual screen): */
357 #if TRI_BPP==8
colhline_neg_direct8(void)358 static void colhline_neg_direct8 (void)
359 #endif
360 #if TRI_BPP==16
361 static void colhline_neg_direct16 (void)
362 #endif
363 #if TRI_BPP==24
364 static void colhline_neg_direct24 (void)
365 #endif
366 #if TRI_BPP==32
367 static void colhline_neg_direct32 (void)
368 #endif
369 {
370     int count, y = py + dy0, x1 = px1 + dx0, x2 = px2 + dx0;
371     declarevp;
372     if (__clip) {
373 	if (y < __clipy1 || y > __clipy2)
374 	    return;
375 	if (x1 > __clipx2 + 1) {
376 #ifdef WRAP
377 	    xd -= (x1 - __clipx2 - 1) * xd_x;
378 	    yd -= (x1 - __clipx2 - 1) * yd_x;
379 #endif
380 #ifdef INTERP
381 	    c -= (x1 - __clipx2 - 1) * c_x;
382 #endif
383 	    x1 = __clipx2 + 1;
384 	}
385 	if (x2 < __clipx1)
386 	    x2 = __clipx1;
387     }
388     count = x1 - x2;
389     assignvp (x1, y, vp);
390     if (count > 0) {
391 	do {
392 	    decvp;
393 #ifdef WRAP
394 	    yd -= yd_x;
395 	    xd -= xd_x;
396 #endif
397 #ifdef INTERP
398 	    c -= c_x;
399 #endif
400 	} while (--count);
401     }
402 }
403 
404 
405 #if TRI_BPP==8
colhline_pos_direct8(void)406 static void colhline_pos_direct8 (void)
407 #endif
408 #if TRI_BPP==16
409 static void colhline_pos_direct16 (void)
410 #endif
411 #if TRI_BPP==24
412 static void colhline_pos_direct24 (void)
413 #endif
414 #if TRI_BPP==32
415 static void colhline_pos_direct32 (void)
416 #endif
417 {
418     int count, y = py + dy0, x1 = px1 + dx0, x2 = px2 + dx0;
419     declarevp;
420     if (__clip) {
421 	if (y < __clipy1 || y > __clipy2)
422 	    return;
423 	if (x1 < __clipx1) {
424 #ifdef WRAP
425 	    xd += (__clipx1 - x1) * xd_x;
426 	    yd += (__clipx1 - x1) * yd_x;
427 #endif
428 #ifdef INTERP
429 	    c += (__clipx1 - x1) * c_x;
430 #endif
431 	    x1 = __clipx1;
432 	}
433 	if (x2 > __clipx2 + 1)
434 	    x2 = __clipx2 + 1;
435     }
436     count = x2 - x1;
437     assignvp (x1, y, vp);
438     if (count > 0) {
439 	do {
440 	    incvp;
441 #ifdef WRAP
442 	    yd += yd_x;
443 	    xd += xd_x;
444 #endif
445 #ifdef INTERP
446 	    c += c_x;
447 #endif
448 	} while (--count);
449     }
450 }
451 
452 /*The following have not yet been implemented */
453 
454 /* Draws to planar 256 (these could be complicated) */
455 /*static void colhline_neg_planar (void);
456 static void colhline_pos_planar (void);*/
457 
458 /* Draws using accelerated */
459 /*static void colhline_neg_accel (void);
460 static void colhline_pos_accel (void);*/
461 
462 
463