Xref: news2.mv.net comp.os.msdos.djgpp:5934 Newsgroups: comp.os.msdos.djgpp From: Nick Collier Subject: Help: General Protection Fault Content-Type: text/plain; charset=us-ascii Message-ID: <31E6BC58.6664@midway.uchicago.edu> Sender: news AT midway DOT uchicago DOT edu (News Administrator) Content-Transfer-Encoding: 7bit Organization: University of Chicago -- Academic Computing Services Mime-Version: 1.0 Date: Fri, 12 Jul 1996 20:58:00 GMT Lines: 77 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 chunk below is part of the routing DrawHorizontalLineList which 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. 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. movw _video_seg,%ax movw %ax,%es /*point ES to display memory for REP STOS */ movl ARG1,%esi /*point to the line list */ movl H_YSTART(%esi),%eax /*point to the start of the first scan */ imul $320, %eax /*line in which to draw */ movl %eax,%edx /*ES:DX points to first scan line to draw */ addl $0xa0000, %edx movl H_LPTR(%esi),%ebx /*point to the XStart/XEnd descriptor */ /*for the first (top) horizontal line */ movl H_LENGTH(%esi),%esi /*number of scan lines to draw */ andl %esi,%esi /*are there any lines to draw? */ jz fill_done /*no, so done */ movb ARG2,%al /*color with which to fill */ movb %al,%ah /*duplicate color for STOSW */ fill_loop: **** -> movl X_START(%ebx),%edi /*left edge of fill on this line */ <- movl X_END(%ebx),%ecx /*right edge of fill */ subl %edi,%ecx X_START refers 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. I figure the problem is either in seting up the offsets or with the asm code. Anyway I hope this is enough information for suggestions as to a solution. TIA Nick