Date: Tue, 19 Aug 1997 02:47:05 +0300 (EET DST) From: Samuli Takala To: Jesse Legg cc: djgpp AT delorie DOT com Subject: Re: inline asm putpixel routine using table In-Reply-To: <33F8B04B.AEC7D9AF@ecr.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk Hi Jesse, On Mon, 18 Aug 1997, Jesse Legg wrote: > Hi, I've been working with writing my own graphics routines in DJGPP > > using mostly inline asm. My only references are a couple of (old) Pascal [snipped and rearranged a bit] > Also, I initialize the 'int screen_y[199]' array like this: > void calc_screen_y(int width) > { > int i; > for (i =0; i < 200; i++) > screen_y[i] = i*width; > } That should be int screen_y[200], otherwise with y=199 you'll overrun the array. > void _setpixel(int x, int y, char col) { > __asm__ __volatile__ (" > movw %3, %%es > addl %0, %%edi > movl %1, %%ebx > addl %%ebx, %%ebx Problem here is that we are dealing with a 32-bit compiler so the size of 'int' is 32-bits. So to get the right offset to the screen_y array, you need to multiply y by 4, not by 2: shll $2, %%ebx > addl %%ds:_screen_y(%%ebx), %%edi > movb %%al, %%es:(%%edi)" > : /* no outputs */ > : "g" (x), "g" (y), "a" (col), "g" (_dos_ds), "D" (0xA0000) > : "eax", "ebx", "edi"); } Hope this helps, Samppa Samuli Takala Samuli DOT Takala AT hut DOT fi finger -l tax AT hut DOT fi for long version