<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>More pies</title>
	<atom:link href="http://blog.evildro.me.uk/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.evildro.me.uk</link>
	<description></description>
	<lastBuildDate>Sun, 06 Jun 2010 15:30:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Low stack usage mod replacement</title>
		<link>http://blog.evildro.me.uk/?p=28</link>
		<comments>http://blog.evildro.me.uk/?p=28#comments</comments>
		<pubDate>Fri, 04 Jun 2010 22:42:49 +0000</pubDate>
		<dc:creator>eaterofpies</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Microcontroller]]></category>

		<guid isPermaLink="false">http://blog.evildro.me.uk/?p=28</guid>
		<description><![CDATA[I was using an ATTiny2313 (128 bytes of ram) and started to run out of ram right at the end of a project and I was in a rush to finish (and didn&#8217;t want to buy more parts) so I thought I&#8217;s have a go at reducing ram usage. First I tried building with O3, [...]]]></description>
			<content:encoded><![CDATA[<p>I was using an ATTiny2313 (128 bytes of ram) and started to run out of ram right at the end of a project and I was in a rush to finish (and didn&#8217;t want to buy more parts) so I thought I&#8217;s have a go at reducing ram usage.</p>
<p>First I tried building with O3, inline functions and packed structures. This didn&#8217;t gain me enough ram so I had a look at what nm said was going on in the binary. The one chunk of the output which stood out was the following.</p>
<p><code><br />
0000072a T __divmodhi4<br />
0000072a T _div<br />
0000073e t __divmodhi4_neg2<br />
00000744 t __divmodhi4_exit<br />
00000746 t __divmodhi4_neg1<br />
00000750 T __udivmodhi4<br />
00000758 t __udivmodhi4_loop<br />
00000766 t __udivmodhi4_ep<br />
</code></p>
<p>GCC was inserting a load of division routines into the code as the chip doesn&#8217;t have the hardware to do division. I wasn&#8217;t doing any division in my code as such but I was using the mod operator for calculations in a ring buffer implementation. These routines which were causing registers to be pushed onto the stack along with return addresses. One ISR was pushing 14 registers onto the stack (partly because of this) along with the return addresses for the division functions.</p>
<p>To reduce stack usage I created a replacement macro for doing mod operations to avoid having to use the built in functions. All values used are unsigned values. This would need to be adapted to work on signed values and only works in my implementation because a is guaranteed to be less than 2b.</p>
<p><code><br />
#ifdef LSMOD<br />
#define MOD(a,b) \<br />
	((a>=b) ? a-b : a)<br />
#else<br />
#define MOD(a,b) \<br />
	(a % b)<br />
#endif<br />
</code></p>
<p>The resulting binary was a few bytes bigger (as it was output in multiple places unlike the function which was just called in multiple places) but only caused the ISR mentioned before to push 9 bytes onto the stack and it doesn&#8217;t call any other functions so no return addresses need to be stored. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.evildro.me.uk/?feed=rss2&amp;p=28</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GameBoyAdvance Multiboot Cable</title>
		<link>http://blog.evildro.me.uk/?p=21</link>
		<comments>http://blog.evildro.me.uk/?p=21#comments</comments>
		<pubDate>Wed, 17 Mar 2010 20:46:19 +0000</pubDate>
		<dc:creator>eaterofpies</dc:creator>
				<category><![CDATA[GameBoyAdvance]]></category>

		<guid isPermaLink="false">http://blog.evildro.me.uk/?p=21</guid>
		<description><![CDATA[I was looking at arm dev boards and thought they were a bit expensive then noticed that a GameBoyAdvance was arm based, £5 and supported uploading programs over a strange 16 bit serial connection referred to as multiboot (the GBA used this for multiplayer games). After spending a lot of time trying to find somewhere [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at arm dev boards and thought they were a bit expensive then noticed that a GameBoyAdvance was arm based, £5 and supported uploading programs over a strange 16 bit serial connection referred to as multiboot (the GBA used this for multiplayer games).</p>
<p>After spending a lot of time trying to find somewhere that either still sells a multiboot cable or good diagrams / documentation on the multiboot protocol or even code for making a multiboot cable which doesn&#8217;t require dos / a parallel port to upload data I stumbled across Matt&#8217;s Multiboot Serial Cable (http://www.axio.ms/projects/GBA/) which was one of the few sites which wasnt full of dead links.</p>
<p>The MSMC implements a smart serial cable (serial &lt;-&gt; microcontroller &lt;-&gt; GBA) to convert between standard 8 bit serial and the the GBA&#8217;s strange 16 bit serial format. The only slight problem being that it was written in asm for the 8051 and I didn&#8217;t have anything 8051 based. I did however have an arduino and several bare ATMega168 ICs in my parts box (the microcontroller code is ~ 1.5k so this overkill to a silly extent).</p>
<p>To cut a long story short I ported his microcontroller code (mainly using the comments) to my Arduino prototype board and now have it running on a bare atmega168 using the internal oscillator. I have also made a few tweaks to the upload tool.</p>
<p>Download the microcontroller code and upload tool <a href="http://www.evildro.me.uk/files/blogfiles/gba/MSMCcable-1.01.tar.bz2">here</a></p>
<p>To upload a GBA multiboot image using an arduino</p>
<ul>
<li> wire the GBA pins up to the arduino (instructions at the top of the source in the arduinocable directory)</li>
<li> flash the code in the arduinocable directory onto an arduino / atmega168</li>
<li> compile the upload tool and run gbl -p/dev/ttyUSB0 -d1 ./image.gba</li>
</ul>
<p>(Note: I haven&#8217;t tried it on anything other than an x86 box running ubuntu 9.10 but it works for me)</p>
<p>I&#8217;m thinking about adding a way upload code directly from the microcontroller to the GBA without the PC getting in the way. It should have enough spare flash for at least a 10k gba binary / I could read it from an SD card and is a shedload easier to get hold of than a writable GBA cart.</p>
<p>A big thanks to Matt Evans (<a href="http://axio.ms">http://axio.ms</a>) for writing the original and keeping the source on his website for nearly 8 years.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.evildro.me.uk/?feed=rss2&amp;p=21</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Additional resolutions available in mw3</title>
		<link>http://blog.evildro.me.uk/?p=16</link>
		<comments>http://blog.evildro.me.uk/?p=16#comments</comments>
		<pubDate>Wed, 19 Aug 2009 20:54:32 +0000</pubDate>
		<dc:creator>eaterofpies</dc:creator>
				<category><![CDATA[Mechwarrior]]></category>

		<guid isPermaLink="false">http://blog.evildro.me.uk/?p=16</guid>
		<description><![CDATA[While I was doing some hacking on Mechwarrior 3 I realised that MW3 supports resolutions over the standard maximum of 1024&#215;768. These aren&#8217;t accessible from the menu but can be enabled by running (start->run) regedit and setting HKEY_CURRENT_USER\Software\MicroProse\Mechwarrior 3\1.0\InGameVMode to the following values 7 for 1024&#215;768 8 for 1152&#215;864 9 for 1280&#215;1024 a for 1600&#215;1200 [...]]]></description>
			<content:encoded><![CDATA[<p>While I was doing some hacking on Mechwarrior 3 I realised that MW3 supports resolutions over the standard maximum of 1024&#215;768. These aren&#8217;t accessible from the menu but can be enabled by running (start->run) regedit and setting  HKEY_CURRENT_USER\Software\MicroProse\Mechwarrior 3\1.0\InGameVMode to the following values</p>
<p>7 for 1024&#215;768<br />
8 for 1152&#215;864<br />
9 for 1280&#215;1024<br />
a for 1600&#215;1200</p>
<p>These do make the targeting bug I posted a fix for much worse and the game will crash if you press escape during a mission.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.evildro.me.uk/?feed=rss2&amp;p=16</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MW3 Targeting fix</title>
		<link>http://blog.evildro.me.uk/?p=3</link>
		<comments>http://blog.evildro.me.uk/?p=3#comments</comments>
		<pubDate>Wed, 05 Aug 2009 22:01:34 +0000</pubDate>
		<dc:creator>eaterofpies</dc:creator>
				<category><![CDATA[Mechwarrior]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Mechwarrior 3]]></category>

		<guid isPermaLink="false">http://blog.evildro.me.uk/?p=3</guid>
		<description><![CDATA[A while ago I created a patched EXE for Mechwarrior 3 which worked around a bug in the game where it would try and draw a targeting box off the edge of the screen and crash the game. This was completely unmaintainable and didn&#8217;t work for some people so I went back to the drawing [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I created a patched EXE for Mechwarrior 3 which worked around a bug in the game where it would try and draw a targeting box off the edge of the screen and crash the game.</p>
<p>This was completely unmaintainable and didn&#8217;t work for some people so I went back to the drawing board and created a loader which injects a DLL into the EXE and replaces the dodgy bit of code.</p>
<p>Sadly the loader still doesnt appear to work for everyone so heres the fixed exe, loader+dll and source code for the loader+dll. The code is fairly horrific so if anyone wants to have a play and fix it please do.<br />
<a href="http://www.evildro.me.uk/files/blogfiles/mechwarrior/mw3Loader0.06.zip"><br />
Loader + src</a></p>
<p><a href="http://www.evildro.me.uk/files/blogfiles/mechwarrior/mw31.2fix1.5.zip">Fixed exe</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.evildro.me.uk/?feed=rss2&amp;p=3</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
