1 /* $Id: 2dsline.c,v 1.12 2005-07-30 01:51:42 chris 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.
38 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
40 #if !defined(NO_ASM) && defined(__WATCOMC__)
42 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
43 #pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
46 "gld_loop: mov bl, [edi] " \
47 " mov al, [ebx+edx] " \
53 #elif !defined(NO_ASM) && defined(__GNUC__)
55 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
57 __asm__ __volatile__ (
60 "0: movb (%%edi), %%bl;"
61 " movb (%%ebx, %%edx), %%al;"
62 " movb %%al, (%%edi);"
66 : "=D" (dummy[0]), "=a" (dummy[1]), "=c" (dummy[2]), "=d" (dummy[3])
67 : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
71 #elif !defined(NO_ASM) && defined(_MSC_VER)
73 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
77 mov eax,[darkening_level]
92 #else // Unknown compiler, or no assembler. So we use C.
94 void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
99 *dest = fade_table[(*dest)+(darkening_level*256)];
106 #ifdef NO_ASM // No Assembler. So we use C.
108 void gr_linear_stosd( ubyte * dest, ubyte color, unsigned short count )
113 while ((int)(dest) & 0x3) { *dest++ = color; count--; };
115 x = (color << 24) | (color << 16) | (color << 8) | color;
116 while (count > 4) { *(int *)dest = x; dest += 4; count -= 4; };
118 while (count > 0) { *dest++ = color; count--; };
120 for (i=0; i<count; i++ )
125 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
126 memset(dest,color,nbytes);
131 void gr_uscanline( int x1, int x2, int y )
133 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
140 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
144 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
147 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
158 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
162 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
167 ubyte * vram = (ubyte *)0xA0000;
168 int VideoLocation,page,offset1, offset2;
170 VideoLocation = (ROWSIZE * y) + x1;
171 page = VideoLocation >> 16;
172 offset1 = VideoLocation & 0xFFFF;
173 offset2 = offset1 + (x2-x1+1);
175 gr_vesa_setpage( page );
176 if ( offset2 <= 0xFFFF ) {
177 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
179 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
181 gr_vesa_setpage(page);
182 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
186 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
194 void gr_scanline( int x1, int x2, int y )
196 if ((y<0)||(y>MAXY)) return;
198 if (x2 < x1 ) x2 ^= x1 ^= x2;
200 if (x1 > MAXX) return;
201 if (x2 < MINX) return;
203 if (x1 < MINX) x1 = MINX;
204 if (x2 > MAXX) x2 = MAXX;
206 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
213 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
217 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
220 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
231 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
235 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
240 ubyte * vram = (ubyte *)0xA0000;
241 int VideoLocation,page,offset1, offset2;
243 VideoLocation = (ROWSIZE * y) + x1;
244 page = VideoLocation >> 16;
245 offset1 = VideoLocation & 0xFFFF;
246 offset2 = offset1 + (x2-x1+1);
248 gr_vesa_setpage( page );
249 if ( offset2 <= 0xFFFF ) {
250 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
252 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
254 gr_vesa_setpage(page);
255 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
259 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );