Message-ID: <3246D282.27AE@megabaud.fi> Date: Mon, 23 Sep 1996 21:10:10 +0300 From: Antti Sinkman Reply-To: sinkman AT megabaud DOT fi MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Possible bug in gcc Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, everybody! I was coding my gouraud-filler, when I got an strange error-message from GCC. It was like this: gpoly.c: In function 'FillGPoly3': gpoly.c:144: fixed or forbidden register was spilled. This may be due to a compiler bug or to impossible asm statements or clauses. I looked through my source, but I didn't find any bugs in it. I don't include any files I was told to include in DJGPPFAQ.TXT, because I think those (autoexec, config, etc.) don't matter here. Of course I'm using DJGPP v2. Here's the source: #include #include typedef unsigned char byte; typedef struct { unsigned short x, y; byte color; } gpoint2d; void FillGPoly3( gpoint2d *A, gpoint2d *B, gpoint2d *C ); void PrepPal( void ); void SetMode( byte mode ); void getch( void ); void main( void ) { short i; gpoint2d A, B, C; A.x = 0; A.y = 0; A.color = 0; B.x = 319; B.y = 0; B.color = 255; C.x = 0; C.y = 199; C.color = 90; SetMode( 0x13 ); PrepPal(); FillGPoly3( &A, &B, &C ); getch(); SetMode( 0x03 ); } void FillGPoly3( gpoint2d *A, gpoint2d *B, gpoint2d *C ) { gpoint2d *top, *bottom, *middle; int x, xinc; int color, cinc; unsigned short *LeftEdge, *RightEdge, LeftEdgeArray[200], RightEdgeArray[200], i, j; byte *LeftColor, *RightColor, LeftColorArray[200], RightColorArray[200]; LeftEdge = LeftEdgeArray; RightEdge = RightEdgeArray; LeftColor = LeftColorArray; RightColor = RightColorArray; top = A; if( B->y < top->y ) top = B; if( C->y < top->y ) top = C; bottom = A; if( B->y > bottom->y ) bottom = B; if( C->y > bottom->y ) bottom = C; if( ((top == A) && (bottom == B)) || ((top == B) && (bottom == A)) ) middle = C; if( ((top == B) && (bottom == C)) || ((top == C) && (bottom == B)) ) middle = A; if( ((top == A) && (bottom == C)) || ((top == C) && (bottom == A)) ) middle = B; if( (bottom->y - top->y) > 0 ) { xinc = (int) ((bottom->x - top->x) << 8) / (bottom->y - top->y); x = (int) top->x << 8; cinc = (int) ((bottom->color - top->color) << 8) / (bottom->y - top->y); color = (int) top->color << 8; for( i = top->y; i <= bottom->y; i++ ) { LeftEdge[i] = (unsigned short) (x >> 8); LeftColor[i] = color >> 8; x += xinc; color += cinc; } } if( (middle->y - top->y) > 0 ) { xinc = (int) ((middle->x - top->x) << 8) / (middle->y - top->y); x = (int) top->x << 8; cinc = (int) ((middle->color - (int)top->color) << 8) / (middle->y - top->y); color = (int) top->color << 8; for( i = top->y; i <= middle->y; i++ ) { RightEdge[i] = (unsigned short) (x >> 8); RightColor[i] = color >> 8; x += xinc; color += cinc; } } if( (bottom->y - middle->y) > 0 ) { xinc = (int) ((bottom->x - middle->x) << 8) / (bottom->y - middle->y); x = (int) middle->x << 8; cinc = (int) ((bottom->color - (int)middle->color)<< 8)/ (bottom->y - middle->y); color = (int) middle->color << 8; for( i = middle->y; i <= bottom->y; i++ ) { RightEdge[i] = (unsigned short) (x >> 8); RightColor[i] = color >> 8; x += xinc; color += cinc; } } if( RightEdge[middle->y] < LeftEdge[middle->y] ) { RightEdge = LeftEdgeArray; LeftEdge = RightEdgeArray; RightColor = LeftColorArray; LeftColor = RightColorArray; } for( i = top->y; i <= bottom->y; i++ ) asm ( " movw %%ax,%%fs movl $0xA0000,%%edi movw %2,%%di movw %%di,%%ax shlw $8,%%di shlw $6,%%ax addw %%ax,%%di addw %0,%%di # edi = display memory start movzwl %1,%%ecx subw %0,%%cx # cx = x2 - x1 movw %4,%%ah subw %3,%%ah xorb %%al,%%al xorw %%dx,%dx idivw %%cx movw %%ax,%%dx # dx = fixed point colorinc ghloop: movb %%ah,%%fs:(%%edi) addw %%dx,%%ax incl %%edi decl %%ecx jnz ghloop " : : "g" (LeftEdge[i]), "g" (RightEdge[i]), "g" (i), "g" (LeftColor[i]), "g" (RightColor[i]), "a" (_dos_ds) : "ax", "cx", "dx", "di" ); } void PrepPal( void ) { short i; for( i = 0; i <= 255; i++ ) { outportb( 0x3c8, (byte) i ); outportb( 0x3c9, 0 ); outportb( 0x3c9, 0 ); outportb( 0x3c9, i / 4 ); } } void SetMode( byte mode ) { asm ( "int $0x10" : : "a" (mode) ); } void getch( void ) { asm ( " mov $1,%ah int $0x21 "); } Antti Sinkman, sinkman AT walrus DOT megabaud DOT fi