1 /* $Id: 2dsline.c,v 1.6 2002-09-04 21:58:11 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Graphical routines for drawing solid scanlines.
20 * Revision 1.6 1995/09/14 14:24:03 allender
21 * fixed MW compile error
23 * Revision 1.5 1995/09/14 13:45:17 allender
24 * quick optimization for scanline
26 * Revision 1.4 1995/04/27 07:36:05 allender
27 * remove some memsets since all old is here now
29 * Revision 1.3 1995/04/19 14:35:33 allender
30 * *** empty log message ***
32 * Revision 1.2 1995/04/18 12:03:40 allender
33 * *** empty log message ***
35 * Revision 1.1 1995/03/09 09:24:06 allender
39 * --- PC RCS information ---
40 * Revision 1.7 1994/11/18 22:50:48 john
41 * Changed a bunch of shorts to ints in calls.
43 * Revision 1.6 1994/09/02 11:40:32 john
44 * fixed bug with urect scanline drakening still
45 * only using 16 levels of fade.
47 * Revision 1.5 1994/04/08 16:59:12 john
48 * Add fading poly's; Made palette fade 32 instead of 16.
50 * Revision 1.4 1994/03/22 18:36:27 john
51 * Added darkening scanlines
53 * Revision 1.3 1993/10/15 16:22:52 john
56 * Revision 1.2 1993/09/08 11:56:29 john
59 * Revision 1.1 1993/09/08 11:44:27 john
80 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
82 #if !defined(NO_ASM) && defined(__WATCOMC__)
84 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
85 #pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
88 "gld_loop: mov bl, [edi] " \
89 " mov al, [ebx+edx] " \
95 #elif !defined(NO_ASM) && defined(__GNUC__)
97 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
99 __asm__ __volatile__ (
100 " xorl %%ebx, %%ebx;"
102 "0: movb (%%edi), %%bl;"
103 " movb (%%ebx, %%edx), %%al;"
104 " movb %%al, (%%edi);"
108 : "=D" (dummy[0]), "=a" (dummy[1]), "=c" (dummy[2]), "=d" (dummy[3])
109 : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
113 #elif !defined(NO_ASM) && defined(_MSC_VER)
115 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
119 mov eax,[darkening_level]
134 #else // Unknown compiler, or no assembler. So we use C.
136 void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
139 for (i=0;i<count;i++)
140 *dest=fade_table[(*dest++)+(darkening_level*256)];
145 #ifdef NO_ASM // No Assembler. So we use C.
147 void gr_linear_stosd( ubyte * dest, ubyte color, unsigned short count )
152 while ((int)(dest) & 0x3) { *dest++ = color; count--; };
154 x = (color << 24) | (color << 16) | (color << 8) | color;
155 while (count > 4) { *(int *)dest = x; dest += 4; count -= 4; };
157 while (count > 0) { *dest++ = color; count--; };
159 for (i=0; i<count; i++ )
164 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
165 memset(dest,color,nbytes);
170 void gr_uscanline( int x1, int x2, int y )
172 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
178 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
182 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
185 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
195 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
199 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
202 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
209 void gr_scanline( int x1, int x2, int y )
211 if ((y<0)||(y>MAXY)) return;
213 if (x2 < x1 ) x2 ^= x1 ^= x2;
215 if (x1 > MAXX) return;
216 if (x2 < MINX) return;
218 if (x1 < MINX) x1 = MINX;
219 if (x2 > MAXX) x2 = MAXX;
221 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
227 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
231 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
234 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
244 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
248 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
251 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );