1 /* $Id: 2dsline.c,v 1.9 2002-10-12 03:09:23 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
85 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
87 #if !defined(NO_ASM) && defined(__WATCOMC__)
89 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
90 #pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
93 "gld_loop: mov bl, [edi] " \
94 " mov al, [ebx+edx] " \
100 #elif !defined(NO_ASM) && defined(__GNUC__)
102 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
104 __asm__ __volatile__ (
105 " xorl %%ebx, %%ebx;"
107 "0: movb (%%edi), %%bl;"
108 " movb (%%ebx, %%edx), %%al;"
109 " movb %%al, (%%edi);"
113 : "=D" (dummy[0]), "=a" (dummy[1]), "=c" (dummy[2]), "=d" (dummy[3])
114 : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
118 #elif !defined(NO_ASM) && defined(_MSC_VER)
120 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
124 mov eax,[darkening_level]
139 #else // Unknown compiler, or no assembler. So we use C.
141 void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
144 for (i=0;i<count;i++)
145 *dest=fade_table[(*dest++)+(darkening_level*256)];
150 #ifdef NO_ASM // No Assembler. So we use C.
152 void gr_linear_stosd( ubyte * dest, ubyte color, unsigned short count )
157 while ((int)(dest) & 0x3) { *dest++ = color; count--; };
159 x = (color << 24) | (color << 16) | (color << 8) | color;
160 while (count > 4) { *(int *)dest = x; dest += 4; count -= 4; };
162 while (count > 0) { *dest++ = color; count--; };
164 for (i=0; i<count; i++ )
169 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
170 memset(dest,color,nbytes);
175 #if defined(POLY_ACC)
176 //$$ Note that this code WAS a virtual clone of the mac code and any changes to mac should be reflected here.
177 void gr_linear15_darken( short * dest, int darkening_level, int count, ubyte * fade_table )
179 //$$ this routine is a prime candidate for using the alpha blender.
181 unsigned short rt[32], gt[32], bt[32];
182 unsigned long level, int_level, dlevel;
184 dlevel = (darkening_level << 16) / GR_FADE_LEVELS;
185 level = int_level = 0;
186 for(i = 0; i != 32; ++i)
188 rt[i] = int_level << 10;
189 gt[i] = int_level << 5;
193 int_level = level >> 16;
197 for (i=0; i<count; i++ ) {
200 rt[((*dest >> 10) & 0x1f)] |
201 gt[((*dest >> 5) & 0x1f)] |
202 bt[((*dest >> 0) & 0x1f)] |
208 void gr_linear15_stosd( short * dest, ubyte color, unsigned short count )
210 //$$ this routine is a prime candidate for using the alpha blender.
211 short c = pa_clut[color];
218 void gr_uscanline( int x1, int x2, int y )
220 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 );
237 #if defined(POLY_ACC)
239 gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
250 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
254 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
259 ubyte * vram = (ubyte *)0xA0000;
260 int VideoLocation,page,offset1, offset2;
262 VideoLocation = (ROWSIZE * y) + x1;
263 page = VideoLocation >> 16;
264 offset1 = VideoLocation & 0xFFFF;
265 offset2 = offset1 + (x2-x1+1);
267 gr_vesa_setpage( page );
268 if ( offset2 <= 0xFFFF ) {
269 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
271 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
273 gr_vesa_setpage(page);
274 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
278 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
282 #if defined(POLY_ACC)
284 gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
291 void gr_scanline( int x1, int x2, int y )
293 if ((y<0)||(y>MAXY)) return;
295 if (x2 < x1 ) x2 ^= x1 ^= x2;
297 if (x1 > MAXX) return;
298 if (x2 < MINX) return;
300 if (x1 < MINX) x1 = MINX;
301 if (x2 > MAXX) x2 = MAXX;
303 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
310 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
314 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
317 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
320 #if defined(POLY_ACC)
322 gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
333 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
337 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
342 ubyte * vram = (ubyte *)0xA0000;
343 int VideoLocation,page,offset1, offset2;
345 VideoLocation = (ROWSIZE * y) + x1;
346 page = VideoLocation >> 16;
347 offset1 = VideoLocation & 0xFFFF;
348 offset2 = offset1 + (x2-x1+1);
350 gr_vesa_setpage( page );
351 if ( offset2 <= 0xFFFF ) {
352 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
354 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
356 gr_vesa_setpage(page);
357 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
361 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
365 #if defined(POLY_ACC)
367 gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);