<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>optimizing code with Assemmbly</title>
		<link>http://www.allegro.cc/forums/view/588383</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 06 Nov 2006 19:16:30 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi y&#39;all.<br />i have noticed tht in quite a lot of languages the <br />getpixel()//get color of pixel at x,y<br />and the<br />putpixel()//draws pixel of certain color at x y<br />functions are really slow. i am working with game maker and importing some allegro functions unto a dll bu i dont know how to add the assembly function to a dll. i dont even know assembly to be honest but i have seen a few scattered codes on the topics so i plan on using if only i can cross compile it.</p><p>i dont know if i am making sense cos i am sleepy from staying up all nite.</p><p>if someone could be of litte assistance i would be most greatful
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (av0k23)</author>
		<pubDate>Sun, 05 Nov 2006 11:38:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, don&#39;t use assembler, you are likely to make things worse. Either use direct bitmap access, through the bitmap array (search allegro.txt for that), or use the optimized versions:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/_getpixel" target="_blank"><span class="a">_getpixel</span></a>, <a href="http://www.allegro.cc/manual/_getpixel15" target="_blank"><span class="a">_getpixel15</span></a>, <a href="http://www.allegro.cc/manual/_getpixel16" target="_blank"><span class="a">_getpixel16</span></a>, <a href="http://www.allegro.cc/manual/_getpixel24" target="_blank"><span class="a">_getpixel24</span></a>, <a href="http://www.allegro.cc/manual/_getpixel32" target="_blank"><span class="a">_getpixel32</span></a>
<a href="http://www.allegro.cc/manual/_putpixel" target="_blank"><span class="a">_putpixel</span></a>, <a href="http://www.allegro.cc/manual/_putpixel15" target="_blank"><span class="a">_putpixel15</span></a>, <a href="http://www.allegro.cc/manual/_putpixel16" target="_blank"><span class="a">_putpixel16</span></a>, <a href="http://www.allegro.cc/manual/_putpixel24" target="_blank"><span class="a">_putpixel24</span></a>, <a href="http://www.allegro.cc/manual/_putpixel32" target="_blank"><span class="a">_putpixel32</span></a>
</pre></div></div><p>

If you are using 8bpp, use the ones without number. If you are at other resolution, change accordingly. Finally, note that these functions (as far as I remember) don&#39;t check for clipping: in other words, if you use the common <i>getpixel</i> function with coordenates (10000,10000), nothing will happen. If you use such coordenates with any of these functions, your program will crash.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sun, 05 Nov 2006 11:43:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>i never heard of optimized getpixel?<br />well i am amazed to say the lest. will try soon.</p><p>hope i works on this</p><p>for(i=0; i&lt;sprite_width; i++)<br />{<br />  for(j=0; j&lt;sprite_height; j++)<br />  {<br />    color= getPixel(x,y);</p><p>    //_pallete[] contains color codes<br />   for(v=0; v&lt;old_pallette_array_width; v++)<br />   {<br />    if(color==old_pallete[v])<br />    {<br />      putPixel(x,y,new_pallete[v]);<br />    }<br />   }<br />  }<br />}
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (av0k23)</author>
		<pubDate>Sun, 05 Nov 2006 23:04:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can also use the <span class="source-code"><a href="http://www.allegro.cc/manual/hline" target="_blank"><span class="a">hline</span></a></span> function instead of the <span class="source-code"><a href="http://www.allegro.cc/manual/putpixel" target="_blank"><span class="a">putpixel</span></a></span> because it is a lot faster when drawing on to a <b>video bitmap</b>, but only with the <b>hardware acceleration</b>. At least it works faster for me. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tomasz Grajewski)</author>
		<pubDate>Mon, 06 Nov 2006 04:10:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>this is all great help but the problem is i am not implementing this directly into allegro. i was half-way into a projecct in game maker before i saw allegro and i cant begin to think of starting again (my comrades cant c++/c). <br />so i guess you have answered the allegro part so the new part is...how do i use the allegro dll in other programs like gamemaker? do i just run the functions as i would normally use it? i tried exporting some functions into a dll but there was a clash with the &lt;windows.h&gt; api as bitmap means different things in both. thts why i was asking for assembly just incase asking for allegro sounded stupid. me so confused.</p><p>if only i understood pascal/assembly</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>.PROCEDURE HLine<span class="k2">(</span>X1, Y, X2 <span class="k2">:</span> INTEGER<span class="k2">;</span> Color <span class="k2">:</span> BYTE<span class="k2">)</span><span class="k2">;</span> ASSEMBLER<span class="k2">;</span></td></tr><tr><td class="number">2</td><td>ASM</td></tr><tr><td class="number">3</td><td>  les DI, Screen  <span class="k2">{</span> Only load ES <span class="k1">and</span> DI at the start <span class="k2">}</span></td></tr><tr><td class="number">4</td><td>  add DI, X1</td></tr><tr><td class="number">5</td><td>  mov BX, Y       <span class="k2">{</span> Y is an <a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a> into the ScreenY array        <span class="k2">}</span></td></tr><tr><td class="number">6</td><td>  add BX, BX      <span class="k2">{</span> Multipy by two because each entry is a word <span class="k2">}</span></td></tr><tr><td class="number">7</td><td>  add DI, DS:<span class="k2">[</span>BX<span class="k3">+</span>OFFSET ScreenY<span class="k2">]</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>  <span class="k2">{</span> At <span class="k1">this</span> point, DI points to the first pixel in the line.  <span class="k2">}</span></td></tr><tr><td class="number">10</td><td>  <span class="k2">{</span> Now we will calculate how many <a href="http://www.delorie.com/djgpp/doc/libc/libc_822.html" target="_blank">times</a> to loop <span class="k2">(</span>X2-X1<span class="k3">+</span><span class="n">1</span><span class="k2">)</span>... <span class="k2">}</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>  mov CX, X2</td></tr><tr><td class="number">13</td><td>  mov AL, Color   <span class="k2">{</span> Load the color <span class="k2">}</span></td></tr><tr><td class="number">14</td><td>  sub CX, X1</td></tr><tr><td class="number">15</td><td>  inc CX</td></tr><tr><td class="number">16</td><td>&#160;</td></tr><tr><td class="number">17</td><td>  test DI, <span class="n">1</span>      <span class="k2">{</span> Are we on an odd address?  <span class="k2">}</span></td></tr><tr><td class="number">18</td><td>  jz @Even</td></tr><tr><td class="number">19</td><td>  stosb           <span class="k2">{</span> Store the first byte       <span class="k2">}</span></td></tr><tr><td class="number">20</td><td>  dec CX          <span class="k2">{</span> Decrement the counter one  <span class="k2">}</span></td></tr><tr><td class="number">21</td><td>@Even:            <span class="k2">{</span> Even address               <span class="k2">}</span></td></tr><tr><td class="number">22</td><td>&#160;</td></tr><tr><td class="number">23</td><td>  shr CX, <span class="n">1</span>       <span class="k2">{</span> Do half as many transfers  <span class="k2">}</span></td></tr><tr><td class="number">24</td><td>  rep stosw       <span class="k2">{</span> Copy all of the even words <span class="k2">}</span> </td></tr><tr><td class="number">25</td><td>  adc CX, <span class="n">0</span>       <span class="k2">{</span> If there is a pixel left over, set CX to <span class="n">1</span> <span class="k2">}</span></td></tr><tr><td class="number">26</td><td>  rep stosb       <span class="k2">{</span> If there is a pixel left over, fill it<span class="k3">!</span>    <span class="k2">}</span></td></tr><tr><td class="number">27</td><td>END<span class="k2">;</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (av0k23)</author>
		<pubDate>Mon, 06 Nov 2006 04:55:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
there was a clash with the &lt;windows.h&gt; api as bitmap means different things in both.
</p></div></div><p>
Include winalleg.h. See the Windows-specifics section of the manual.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
thts why i was asking for assembly just incase asking for allegro sounded stupid.
</p></div></div><p>
It&#39;s an Allegro forum. Of course it isn&#39;t stupid to ask questions about Allegro! <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
if only i understood pascal/assembly
</p></div></div><p>
Why?<br />By the way, that code you posted is 16 bit, probably real-mode DOS code. It won&#39;t be of much use to you. It&#39;s ok to start with if you want to learn about assembler, but for your case I think this is clearly overkill.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 06 Nov 2006 13:58:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I almost see no reason to use assembly anymore for any but embedded and extremely low-level tasks. Using any modern c-compiler an intelligent user can produce almost exactly the assembly they want without losing any cross-platform and readability. Even vector processing can be easily handled without leaving c/c++ nowadays.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Goalie Ca)</author>
		<pubDate>Mon, 06 Nov 2006 15:36:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
No, don&#39;t use assembler, you are likely to make things worse. Either use direct bitmap access, through the bitmap array (search allegro.txt for that), or use the optimized versions:
</p></div></div><p>

Very true. Get/putpixel are damn slow compared to something like <i>bitmap-&gt;line[y][x] = color</i>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Sirocco)</author>
		<pubDate>Mon, 06 Nov 2006 19:16:30 +0000</pubDate>
	</item>
</rss>
