delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/17/21:32:05

Xref: news2.mv.net comp.os.msdos.djgpp:6095
Newsgroups: comp.os.msdos.djgpp
From: Nick Collier <ntcollie AT midway DOT uchicago DOT edu>
Subject: Help: ASM prompted General Proctection Fault
Message-ID: <31EBFEDF.563D@midway.uchicago.edu>
Sender: news AT midway DOT uchicago DOT edu (News Administrator)
Organization: University of Chicago -- Academic Computing Services
Mime-Version: 1.0
Date: Tue, 16 Jul 1996 20:43:11 GMT
Lines: 140
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello all,

I'm trying to convert the polygon drawing code from M.Abrash's Zen 
of Graphics programming to work with djggp. The asm code below "DrawHorizontalLineList" does 
the drawing to the screen. It receives the line list structure:

struct HLineList {
   int Length;                /* # of horizontal lines */
   int YStart;                /* Y coordinate of topmost line */
   struct HLine * HLinePtr;   /* pointer to list of horz lines */
};

which contains:

struct HLine {
   int XStart; /* X coordinate of leftmost pixel in line */
   int XEnd;   /* X coordinate of rightmost pixel in line */
}; 


The members of the structure are referenced through offsets H_YSTART
etc. These offsets (and the problem one X_START in particular) refer to the embedded 
HLine structure in the HLinelist. It is defined through the following code:

	fprintf(f, "#define H_LENGTH        %ld\n",  offsetof(struct HLineList, Length));
	fprintf(f, "#define H_YSTART       %ld\n",  offsetof(struct HLineList, YStart));
	fprintf(f, "#define H_LPTR      %ld\n",  offsetof(struct HLineList, HLinePtr));
	fprintf(f, "#define X_START        %ld\n",  offsetof(struct HLine, XStart));
	fprintf(f, "#define X_END        %ld\n",  offsetof(struct HLine, XEnd));
	fprintf(f, "#define HL_SIZE        %ld\n",  sizeof(struct HLine));

(Thanks to the author of Allegro (Shawn Hargreaves?) for this code). The
file that this generates is then included. 

The problem:


When I run the program it crashes with the following:

General Protection Fault at eip=00001c08
eax=00000303 ebx=28474348 ecx=00000000 edx=000a0140 esi=000000c7 edi=000a0140
ebp=0004ddd8 esp=0004ddbe cs=00a7 ds=00af es=00c7 fs=0087 gs=00c7 ss=00af
Call frame traceback EIPs:
  0x00001c08
  0x00001a12
  0x00001584
  0x00002177


0x00001c08 refers to the line marked below.

If I try to run it immediately after this, one screen size polygon is
displayed and then everything crashes.

Given that ebx=28474348, this is clearly the problem. Why is ebx
misbehaving? The C version works perfectly.

pdraw.S:

..text

	.globl _DrawHorizontalLineList
	.extern _video_seg
	.align 4

_DrawHorizontalLineList:
	pushl   %ebp
	movl    %esp, %ebp
	pushl   %esi
	pushl   %edi
	pushl   %eax
	pushl   %ebx
	pushl   %ecx
	pushl   %edx
	pushw   %es
	cld									

	movw	_video_seg,%ax
	movw	%ax,%es						

	movl	ARG1,%esi					
	movl	H_YSTART(%esi),%eax		
	imul	$320, %eax					
	movl	%eax,%edx					
	addl	$0xa0000, %edx
	movl	$0,%ebx
	movl	H_LPTR(%esi),%ebx			
	movl	H_LENGTH(%esi),%esi		
	andl	%esi,%esi					
	movb	ARG2,%al						
	movb	%al,%ah						
fill_loop:		

**************** 1c08 refers to the next line **********************

-->**	movl	X_START(%ebx),%edi		

	movl	X_END(%ebx),%ecx			
	subl	%edi,%ecx
	js	line_fill_done				
	incl	%ecx							
	addl	%edx,%edi					
	testl	$1,%edi						
	jz	main_fill					
	stosb									
										
	decl	%ecx						
	jz	line_fill_done				
main_fill:		
	shrl	$1,%ecx						
	rep	
	stosw									
	adcl	%ecx,%ecx					
											
	rep	
	stosb						
line_fill_done:		
	addl	HL_SIZE,%ebx				
	addl	$320,%edx					
	decl	%esi							
	jnz	fill_loop
fill_done:		
	popw    %es
	popl    %edx
	popl    %ecx
	popl    %ebx
	popl    %eax
	popl    %edi
	popl    %esi
	popl    %ebp
	ret


	
I figure the problem with ebx is either in seting up the offsets or with the asm
code in general (I'm an asm neophyte). Anyway I hope this is enough information for
suggestions as to asolution.

TIA
Nick

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019