<?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>dave&#039;s blog of art and programming &#187; fluxus hacking</title>
	<atom:link href="http://www.pawfal.org/dave/blog/category/fluxus-hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pawfal.org/dave/blog</link>
	<description>missing acceptable use policy</description>
	<lastBuildDate>Fri, 10 Feb 2012 18:20:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Missile Command machinima in São Paulo</title>
		<link>http://www.pawfal.org/dave/blog/2011/08/missile-command-machinima-in-sao-paulo/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/08/missile-command-machinima-in-sao-paulo/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 12:15:42 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[livecoding]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=2225</guid>
		<description><![CDATA[Some images of the Machinima exhibition at FILE 2011 in São Paulo, featuring a movie of a livecoded abstractification of a Missile Command game written/performed/destroyed/recorded in Fluxus.
 
]]></description>
			<content:encoded><![CDATA[<p>Some images of the Machinima exhibition at <a href="http://filefestival.org">FILE 2011</a> in São Paulo, featuring a movie of a livecoded abstractification of a <a href="http://www.pawfal.org/dave/index.cgi?Projects/Missile%20Command">Missile Command game</a> written/performed/destroyed/recorded in Fluxus.</p>
<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/machinima-003.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/machinima-003-300x200.jpg" alt="" title="machinima-003" width="300" height="200" class="alignnone size-medium wp-image-2226" /></a> <a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/machinima-044.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/machinima-044-300x200.jpg" alt="" title="machinima-044" width="300" height="200" class="alignnone size-medium wp-image-2227" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/08/missile-command-machinima-in-sao-paulo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PS2 vu1 rendering</title>
		<link>http://www.pawfal.org/dave/blog/2011/08/ps2-vu1-rendering/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/08/ps2-vu1-rendering/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 14:03:47 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=2174</guid>
		<description><![CDATA[Some more work on upcycling second hand PS2's into cheap fluxus machines. The next step is to embrace the vector units - strange little processors for doing things with points lines and colours extremely fast.
 
This is quite a daunting task for various reasons, not only can you run floating point and integer calculations in [...]]]></description>
			<content:encoded><![CDATA[<p>Some more work on <a href="http://en.wikipedia.org/wiki/Upcycling">upcycling</a> second hand PS2's into cheap fluxus machines. The next step is to embrace the vector units - strange little processors for doing things with points lines and colours extremely fast.</p>
<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0399.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0399-300x179.jpg" alt="" title="IMAG0399" width="300" height="179" class="alignnone size-medium wp-image-2175" /></a> <a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0400.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0400-300x179.jpg" alt="" title="IMAG0400" width="300" height="179" class="alignnone size-medium wp-image-2178" /></a></p>
<p>This is quite a daunting task for various reasons, not only can you run floating point and integer calculations in parallel, the VU's also have <a href="http://en.wikipedia.org/wiki/Instruction_pipeline">instruction pipelining</a> where a calculation can take a number of instructions to finish. The advantage of this is that you can interleave work that you are doing while you wait for things to complete, and make extremely fast programs - but it takes some time to get your head around. </p>
<p>Luckily it's made a whole lot easier by a free software tool called <a href="https://github.com/jsvennevid/openvcl">OpenVCL</a>. This lets you write fairly straight forward assembler and it at least makes sure it should run correctly by spacing it out for you - future versions may also start optimising the code automatically.</p>
<p>This is my first very basic renderer, which simply applies the world->screen transform to each vertex in an object. It's job is to load data put in it's memory by the CPU, process and send it to the "graphics synthesizer" to draw the gouraud shaded triangles. It's not only much faster than doing the same job on the CPU, but it leaves it free for other processing (such as running a Scheme interpreter).</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#808030; '>        .</span>syntax new
        <span style='color:#808030; '>.</span><span style='color:#004a43; '>name</span> vu1_unlit
        <span style='color:#808030; '>.</span>vu
        <span style='color:#808030; '>.</span>init_vf_all
        <span style='color:#808030; '>.</span>init_vi_all
        <span style='color:#808030; '>-</span><span style='color:#808030; '>-</span><span style='color:#800000; font-weight:bold; '>enter</span>
        <span style='color:#808030; '>-</span><span style='color:#808030; '>-</span>endenter
        <span style='color:#696969; '>; load the matrix row by row</span>
        lq      world_screen_row0<span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>(</span>vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span>
        lq      world_screen_row1<span style='color:#808030; '>,</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>(</span>vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span>
        lq      world_screen_row2<span style='color:#808030; '>,</span> <span style='color:#008c00; '>2</span><span style='color:#808030; '>(</span>vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span>
        lq      world_screen_row3<span style='color:#808030; '>,</span> <span style='color:#008c00; '>3</span><span style='color:#808030; '>(</span>vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span>
        <span style='color:#696969; '>; load the params and set the addresses for</span>
        <span style='color:#696969; '>; the giftag and vertex data</span>
        lq      params<span style='color:#808030; '>,</span> <span style='color:#008c00; '>4</span><span style='color:#808030; '>(</span>vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span>
        iaddiu  giftag_addr<span style='color:#808030; '>,</span> vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>5</span>
        iaddiu  vertex_data<span style='color:#808030; '>,</span> vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> <span style='color:#008c00; '>6</span>
        <span style='color:#696969; '>; move the vertex count to an integer </span>
        <span style='color:#696969; '>; register so we can loop over it</span>
        mtir    vertex_index<span style='color:#808030; '>,</span> params<span style='color:#808030; '>[</span>x<span style='color:#808030; '>]</span>
<span style='color:#e34adc; '>vertex_loop:</span>
        <span style='color:#696969; '>; load the colour (just increments vertex_data)</span>
        lqi     colour<span style='color:#808030; '>,</span> <span style='color:#808030; '>(</span>vertex_data<span style='color:#808030; '>+</span><span style='color:#808030; '>+</span><span style='color:#808030; '>)</span>
        <span style='color:#696969; '>; load vertex position</span>
        lq      vertex<span style='color:#808030; '>,</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>(</span>vertex_data<span style='color:#808030; '>)</span>
        <span style='color:#696969; '>; apply the transformation</span>
        <span style='color:#800000; font-weight:bold; '>mul</span>     acc<span style='color:#808030; '>,</span> world_screen_row0<span style='color:#808030; '>,</span> vertex<span style='color:#808030; '>[</span>x<span style='color:#808030; '>]</span>
        madd    acc<span style='color:#808030; '>,</span> world_screen_row1<span style='color:#808030; '>,</span> vertex<span style='color:#808030; '>[</span>y<span style='color:#808030; '>]</span>
        madd    acc<span style='color:#808030; '>,</span> world_screen_row2<span style='color:#808030; '>,</span> vertex<span style='color:#808030; '>[</span>z<span style='color:#808030; '>]</span>
        madd    vertex<span style='color:#808030; '>,</span> world_screen_row3<span style='color:#808030; '>,</span> vertex<span style='color:#808030; '>[</span>w<span style='color:#808030; '>]</span>
        <span style='color:#800000; font-weight:bold; '>div</span>     q<span style='color:#808030; '>,</span> vf0<span style='color:#008c00; '>0</span><span style='color:#808030; '>[</span>w<span style='color:#808030; '>]</span><span style='color:#808030; '>,</span> vertex<span style='color:#808030; '>[</span>w<span style='color:#808030; '>]</span>
        <span style='color:#800000; font-weight:bold; '>mul</span><span style='color:#808030; '>.</span>xyz vertex<span style='color:#808030; '>,</span> vertex<span style='color:#808030; '>,</span> q
        <span style='color:#696969; '>; convert to fixed point</span>
        ftoi4   vertex<span style='color:#808030; '>,</span> vertex
        <span style='color:#696969; '>; overwrite the old vertex with the transformed one</span>
        sqi     vertex<span style='color:#808030; '>,</span> <span style='color:#808030; '>(</span>vertex_data<span style='color:#808030; '>+</span><span style='color:#808030; '>+</span><span style='color:#808030; '>)</span>
        <span style='color:#696969; '>; decrement and loop</span>
        iaddi   vertex_index<span style='color:#808030; '>,</span> vertex_index<span style='color:#808030; '>,</span> <span style='color:#008c00; '>-1</span>
        ibne    vertex_index<span style='color:#808030; '>,</span> vi0<span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> vertex_loop
        <span style='color:#696969; '>; send to gs</span>
        xgkick  giftag_addr
        <span style='color:#808030; '>-</span><span style='color:#808030; '>-</span>exit
        <span style='color:#808030; '>-</span><span style='color:#808030; '>-</span>endexit
</pre>
<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0401.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0401-300x179.jpg" alt="" title="IMAG0401" width="300" height="179" class="alignnone size-medium wp-image-2180" /></a> <a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0403.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/08/IMAG0403-300x179.jpg" alt="" title="IMAG0403" width="300" height="179" class="alignnone size-medium wp-image-2181" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/08/ps2-vu1-rendering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualising Elastic Versailles</title>
		<link>http://www.pawfal.org/dave/blog/2011/07/visualising-elastic-versailles/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/07/visualising-elastic-versailles/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 13:57:54 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[naked on pluto]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=2107</guid>
		<description><![CDATA[
Naked on Pluto is a text adventure game, it's world is comprised of descriptions, populated by bits and pieces of text from your facebook profile while the space is largely left to your interpretation and imagination. There are some ways of visualising it though.
We have been archiving versions of the game world every hour for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/07/port2.png"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/07/port2-266x300.png" alt="" title="port2" width="266" height="300" class="alignright size-medium wp-image-2106" /></a></p>
<p><a href="http://naked-on-pluto.net">Naked on Pluto</a> is a text adventure game, it's world is comprised of descriptions, populated by bits and pieces of text from your facebook profile while the space is largely left to your interpretation and imagination. There are some ways of visualising it though.</p>
<p>We have been archiving versions of the game world every hour for the last year in a <a href="https://gitorious.org/naked-on-pluto/tertius">git repo</a>. In these files the only facebook profile information we have stored are names, which are considered public information in the agreement with facebook. We are interested in using this data to see how we built the game and potentially how people have been playing it (although one snapshot per hour isn't really enough for that).</p>
<p>I started out experimenting with <a href="http://www.graphviz.org/">GraphViz</a> and <a href="http://gephi.org/">Gephi</a> but I ended up switching to fluxus and adapting the <a href="http://www.pawfal.org/dave/blog/2010/02/exquisite-code-2/">exquisite code visualiser</a> to read through thousands of dot files to make a dynamically changing graph. This animation shows the process from us building the world to the introduction of the first playtesters over the course of a few months:</p>
<p><iframe src="http://player.vimeo.com/video/26468881" width="600" height="338" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/07/visualising-elastic-versailles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pink polygons &amp; multitouch</title>
		<link>http://www.pawfal.org/dave/blog/2011/05/pink-polygons-multitouch/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/05/pink-polygons-multitouch/#comments</comments>
		<pubDate>Thu, 12 May 2011 12:13:27 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[fluxus hacking]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=1982</guid>
		<description><![CDATA[A new version of android fluxus, with pdata, multitouch capability, scene inspection and a very pink test script included (see code below) fluxus-0.0.2.apk &#038; source. Press the trackball button to edit the scheme code.
 
(clear)

(define twirl-shape
  (with-state
   (hint-unlit)
   (build-polygons 40 triangle-strip)))

(define finger-shapes
  (with-state
   (hint-none)
   (hint-unlit)
 [...]]]></description>
			<content:encoded><![CDATA[<p>A new version of android fluxus, with pdata, multitouch capability, scene inspection and a very pink test script included (see code below) <a href="http://www.pawfal.org/dave/files/android/fluxus-0.0.2.apk">fluxus-0.0.2.apk</a> & <a href="https://gitorious.org/flotsam/flotsam/trees/master/android/fluxus">source</a>. Press the trackball button to edit the scheme code.</p>
<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/snap20110512_143618.png"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/snap20110512_143618.png" alt="" title="snap20110512_143618" width="480" height="800" class="alignnone size-full wp-image-1983" /></a> <a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/snap20110512_144209.png"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/snap20110512_144209.png" alt="" title="snap20110512_144209" width="480" height="800" class="alignnone size-full wp-image-1984" /></a></p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>clear</span><span style='color:#808030; '>)</span>

<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>define</span> twirl-shape
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-state</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>hint-unlit</span><span style='color:#808030; '>)</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>build-polygons</span> <span style='color:#008c00; '>40</span> triangle-strip<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>define</span> finger-shapes
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-state</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>hint-none</span><span style='color:#808030; '>)</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>hint-unlit</span><span style='color:#808030; '>)</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>hint-wire</span><span style='color:#808030; '>)</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>list</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>build-polygons</span> <span style='color:#008c00; '>30</span> triangle-strip<span style='color:#808030; '>)</span>
         <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>build-polygons</span> <span style='color:#008c00; '>30</span> triangle-strip<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>define</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>spiral</span><span style='color:#808030; '>)</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>line-width</span> <span style='color:#008c00; '>5</span><span style='color:#808030; '>)</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pdata-map!</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>c</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>1</span> <span style='color:#008000; '>0.29</span> <span style='color:#008000; '>0.42</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#0000e6; '>"c"</span><span style='color:#808030; '>)</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pdata-index-map!</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>i</span> p<span style='color:#808030; '>)</span>
     <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>let</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>i</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> i <span style='color:#008000; '>0.8</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vmul</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>sin</span> i<span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>cos</span> i<span style='color:#808030; '>)</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> <span style='color:#008000; '>0.02</span> i i<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
   <span style='color:#0000e6; '>"p"</span><span style='color:#808030; '>)</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pdata-copy</span> <span style='color:#0000e6; '>"p"</span> <span style='color:#0000e6; '>"pref"</span><span style='color:#808030; '>)</span> <span style='color:#696969; '>; only really needed for animation</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pdata-map!</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>p</span> pref<span style='color:#808030; '>)</span>
     <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vadd</span> pref <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vmul</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>crndvec</span><span style='color:#808030; '>)</span> <span style='color:#008000; '>0.2</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
   <span style='color:#0000e6; '>"p"</span> <span style='color:#0000e6; '>"pref"</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>for-each</span>
 <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>finger-shape</span><span style='color:#808030; '>)</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-primitive</span> finger-shape <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>spiral</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
 finger-shapes<span style='color:#808030; '>)</span>

<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-primitive</span>
 twirl-shape
 <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pdata-map!</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>c</span><span style='color:#808030; '>)</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>1</span> <span style='color:#008000; '>0.29</span> <span style='color:#008000; '>0.42</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
  <span style='color:#0000e6; '>"c"</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

<span style='color:#696969; '>; using with-primitive is really slow, so directly use grab</span>
<span style='color:#696969; '>; returns the distance between the objects</span>
<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>define</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>get-pinch</span><span style='color:#808030; '>)</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>grab</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>car</span> finger-shapes<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>let</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>a</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vtransform</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>0</span> <span style='color:#008c00; '>0</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>get-transform</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ungrab</span><span style='color:#808030; '>)</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>grab</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>cadr</span> finger-shapes<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>let</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>b</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vtransform</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>0</span> <span style='color:#008c00; '>0</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>get-transform</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
      <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ungrab</span><span style='color:#808030; '>)</span>
      <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vdist</span> a b<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

<span style='color:#696969; '>; store pinch as it's slow to calculate</span>
<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>define</span> pinch <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span>

<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>every-frame</span>
 <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>begin</span>
   <span style='color:#696969; '>; do the twirling</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-primitive</span>
    twirl-shape
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pdata-index-map!</span>
     <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>i</span> p<span style='color:#808030; '>)</span>
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>let</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>i</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> i <span style='color:#008000; '>0.5</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
         <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vmul</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>sin</span> i<span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>cos</span> i<span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> <span style='color:#008c00; '>2</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>cos</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> i <span style='color:#008000; '>10.43</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
               <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> <span style='color:#008c00; '>5</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>sin</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> pinch <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>+</span> i <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> <span style='color:#008000; '>0.1</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>time</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#008000; '>0.1</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
     <span style='color:#0000e6; '>"p"</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
   <span style='color:#696969; '>; check for touch events</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>for-each</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>touch-id</span><span style='color:#808030; '>)</span>
      <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>let</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>finger-shape</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>list-ref</span> finger-shapes touch-id<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
        <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-primitive</span>
         finger-shape
         <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>identity</span><span style='color:#808030; '>)</span>
         <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>translate</span>
          <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>get-point-from-touch</span> touch-id<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
         <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>rotate</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>0</span> <span style='color:#008c00; '>0</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>*</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>time</span><span style='color:#808030; '>)</span> <span style='color:#008c00; '>10</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
      <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>set!</span> pinch <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>get-pinch</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>get-touch-ids</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/05/pink-polygons-multitouch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PS2 homebrew #5</title>
		<link>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-5/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-5/#comments</comments>
		<pubDate>Wed, 11 May 2011 06:53:23 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[accidental art]]></category>
		<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=1974</guid>
		<description><![CDATA[Getting stuff to work on PS2 wasn't quite as easy as I probably made it sound in the last homebrew post. The problem with loading code from usb stick is that there is no way to debug anything, no remote debugging, no stdout - not even any way to render text unless you write your [...]]]></description>
			<content:encoded><![CDATA[<p>Getting stuff to work on PS2 wasn't quite as easy as I probably made it sound in the last homebrew post. The problem with loading code from usb stick is that there is no way to debug anything, no remote debugging, no stdout - not even any way to render text unless you write your own program to do that.</p>
<p>The trick is to use the fact that we are rendering a CRT TV signal and that you can control what gets rendered in the overscan area (think 8bit loading screens). There is a register which directly sets the background colour of the scanline - this macro is all you need:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#004a43; '>#</span><span style='color:#004a43; '>define</span><span style='color:#004a43; '> gs_p_bgcolor        0x120000e0    </span><span style='color:#696969; '>// Set CRTC background color</span>

<span style='color:#004a43; '>#</span><span style='color:#004a43; '>define</span><span style='color:#004a43; '> GS_SET_BGCOLOR</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>r</span><span style='color:#808030; '>,</span><span style='color:#004a43; '>g</span><span style='color:#808030; '>,</span><span style='color:#004a43; '>b</span><span style='color:#808030; '>)</span><span style='color:#004a43; '> \</span>
<span style='color:#004a43; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;</span><span style='color:#808030; '>*</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>volatile unsigned long </span><span style='color:#808030; '>*</span><span style='color:#808030; '>)</span><span style='color:#004a43; '>gs_p_bgcolor </span><span style='color:#808030; '>=</span><span style='color:#004a43; '>    \</span>
<span style='color:#004a43; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>unsigned long</span><span style='color:#808030; '>)</span><span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>r</span><span style='color:#808030; '>)</span><span style='color:#004a43; '> </span><span style='color:#808030; '>&amp;</span><span style='color:#004a43; '> 0x000000FF</span><span style='color:#808030; '>)</span><span style='color:#004a43; '> </span><span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span><span style='color:#004a43; '>  0 </span><span style='color:#808030; '>|</span><span style='color:#004a43; '> \</span>
<span style='color:#004a43; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>unsigned long</span><span style='color:#808030; '>)</span><span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>g</span><span style='color:#808030; '>)</span><span style='color:#004a43; '> </span><span style='color:#808030; '>&amp;</span><span style='color:#004a43; '> 0x000000FF</span><span style='color:#808030; '>)</span><span style='color:#004a43; '> </span><span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span><span style='color:#004a43; '>  8 </span><span style='color:#808030; '>|</span><span style='color:#004a43; '> \</span>
<span style='color:#004a43; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>unsigned long</span><span style='color:#808030; '>)</span><span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#004a43; '>b</span><span style='color:#808030; '>)</span><span style='color:#004a43; '> </span><span style='color:#808030; '>&amp;</span><span style='color:#004a43; '> 0x000000FF</span><span style='color:#808030; '>)</span><span style='color:#004a43; '> </span><span style='color:#808030; '>&lt;</span><span style='color:#808030; '>&lt;</span><span style='color:#004a43; '> 16</span>
</pre>
<p>Which you can use to set the background to green for example:</p>
<pre style='color:#000000;background:#ffffff;'>GS_SET_BGCOLOR<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>0,255,0</span><span style='color:#808030; '>)</span><span style='color:#696969; '>;</span>
</pre>
<p>Its a good idea to change this at different points in your program. When you get a crash the border colour it's frozen with will tell you what area it was last in, allowing you to track down errors. </p>
<p>There is also a nice side effect that this provides a visual profile of your code at the same time. Rendering is synced to the vertical blank - when the CRT laser shoots back to the top of the screen a new frame is started and you have a 50th of a second (PAL) to get everything done. In the screenshot below you can see how the frame time breaks down rendering 9 animated primitives - and why it might be a good idea to use some of these other processors:</p>
<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/debug.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/debug-1024x768.jpg" alt="" title="debug" width="1024" height="768" class="alignnone size-large wp-image-1975" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PS2 homebrew #4</title>
		<link>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-4/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-4/#comments</comments>
		<pubDate>Tue, 10 May 2011 07:58:29 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=1959</guid>
		<description><![CDATA[
Getting things to render on the PS2 is a little more complicated than using OpenGL and it's also a very different system to a PC. On the right you can see a block diagram of the Emotion Engine - it consists of the EE core, the CPU on the left and the GS - Graphics [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/ps2_block_diagram.gif"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/ps2_block_diagram.gif" alt="" title="ps2_block_diagram" width="437" height="334" class="alignright size-full wp-image-1961" /></a></p>
<p>Getting things to render on the PS2 is a little more complicated than using OpenGL and it's also a very different system to a PC. On the right you can see a block diagram of the Emotion Engine - it consists of the EE core, the CPU on the left and the GS - Graphics Synthesiser, on the right. In between are 2 other processors called Vector Units - very fast processors designed to do things to vectors - points, colours etc.</p>
<p>All the Graphics Synthesiser can do is rasterise 2D shapes with points given in screen space and do your texturing & gouraud shading for you. It can draw points, lines, triangles or quads in various configurations (similar to OpenGL). However all the 3D transformations and lighting calculations have to happen elsewhere - in one, or both of the Vector Units or the CPU.</p>
<p>So how do we get the GS to render something? Well you send it chunks of data, called GS Packets, that look a little like this:</p>
<p>GIF Tag 1<br />
Primitive data<br />
GIF Tag 2<br />
Primitive data<br />
...</p>
<p>The GIF Tags contain information on what sort of primitive it should draw and how the primitive data is laid out. The primitive data is the same as the primitive data in fluxus - vertex positions, colours, texture coordinates, texture data etc.</p>
<p>Once I had tinyscheme and the basic scenegraph working that the minimal fluxus build uses, I wrote a <a href="https://gitorious.org/flotsam/flotsam/blobs/master/android/fluxus/jni/engine/ps2-renderer.h">very simple renderer</a> running on the EE core to apply the transformation matrices to the primitives (with similar push and pop to OpenGL). It doesn't calculate lighting at the moment, so it's just setting the vertex colours to the normal's values for debugging. This is a literal photographic screen shot of my PS2 running exactly the same <a href="http://www.pawfal.org/dave/blog/2011/04/more-android-tinkering/">test fluxus script as the android was running</a>:</p>
<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/DSC00759.jpg"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/05/DSC00759-1024x768.jpg" alt="" title="DSC00759" width="1024" height="768" class="alignnone size-large wp-image-1960" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PS2 homebrew #3</title>
		<link>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-3/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-3/#comments</comments>
		<pubDate>Mon, 09 May 2011 08:23:47 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=1954</guid>
		<description><![CDATA[The next thing I wanted to do was see if I could compile the minimal android version of fluxus for the PS2. All the PS2SDK examples are written in C, and when I tried the C++ compiler at link time I got a bunch of these odd errors:
ps2-main.cpp: undefined reference to `__gxx_personality_v0'
It turns out the [...]]]></description>
			<content:encoded><![CDATA[<p>The next thing I wanted to do was see if I could compile the minimal android version of fluxus for the PS2. All the PS2SDK examples are written in C, and when I tried the C++ compiler at link time I got a bunch of these odd errors:</p>
<p>ps2-main.cpp: undefined reference to `__gxx_personality_v0'</p>
<p>It turns out the C++ compiler does not support exceptions so you need to add this line to the makefile: </p>
<p>EE_CXXFLAGS += -fno-exceptions</p>
<p>The other thing to get used to is one of the side effects of a machine with so many processors is that you need send lots of data around between them using DMA transfer, or direct memory access. DMA works on chunks of memory at a time, so your data needs to be aligned on particular byte boundaries. This sounds a lot more complicated than it is in practice (although it does lead to really obscure bugs if you get it wrong).</p>
<p>For instance, when making arrays on the heap you can do this:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#800000; font-weight:bold; '>struct</span> my_struct
<span style='color:#800080; '>{</span>
    <span style='color:#800000; font-weight:bold; '>int</span> an_int<span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>float</span> my_array<span style='color:#808030; '>[</span><span style='color:#008c00; '>8</span><span style='color:#808030; '>]</span> __attribute__<span style='color:#808030; '>(</span><span style='color:#808030; '>(</span>__aligned__<span style='color:#808030; '>(</span><span style='color:#008c00; '>16</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>float</span> a_float<span style='color:#800080; '>;</span>
<span style='color:#800080; '>}</span><span style='color:#800080; '>;</span>
</pre>
<p>Which tells gcc to sort it out for you by forcing the pointer to my_array to fall on a 16 byte boundary.</p>
<p>When allocating from the heap the EE kernel provides you with a memalign version of malloc:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#800000; font-weight:bold; '>float</span> <span style='color:#808030; '>*</span>some_floats<span style='color:#808030; '>=</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>float</span><span style='color:#808030; '>*</span><span style='color:#808030; '>)</span>memalign<span style='color:#808030; '>(</span><span style='color:#008c00; '>128</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>sizeof</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>float</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>*</span> <span style='color:#008c00; '>100</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
</pre>
<p>The pointer some_floats will be aligned to a 128 byte boundary. This works as normal with free().</p>
<p>At this point, other than a few changes to tinyscheme for string functions that don't exist on the PS2 libraries, most of the fluxus code was building. The only problem was the OpenGL ES code, as although the PS2 has some attempts at libraries that work a bit like OpenGL, the real point of playing with this machine is to write your own realtime renderer. a bit more on that next...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/05/ps2-homebrew-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More android tinkering</title>
		<link>http://www.pawfal.org/dave/blog/2011/04/more-android-tinkering/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/04/more-android-tinkering/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 13:35:07 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[fluxus hacking]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=1900</guid>
		<description><![CDATA[
In order to figure out the source of the crashes I was getting I quickly wrote a linux wrapper around the android code so it could run in a simpler-to-debug environment. This of course was running without any problems, so not much help, but it'll come in useful anyway.
Next step, try it in the emulator [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/snap20110421_153330.png"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/snap20110421_153330.png" alt="" title="snap20110421_153330" width="480" height="800" class="alignright size-full wp-image-1899" /></a></p>
<p>In order to figure out the source of the crashes I was getting I quickly wrote a linux wrapper around the android code so it could run in a simpler-to-debug environment. This of course was running without any problems, so not much help, but it'll come in useful anyway.</p>
<p>Next step, try it in the emulator - this exhibited the crash, but I couldn't get a good stack trace from gdb. While investigating this I decided I could use a simpler method with the hardware, which is much faster than the emulator. addr2line is a program you can use for making sense out of crash reports, you take the address reported in the crash log (using adb logcat to read them from the android device), feed it to addr2line with the library and it tells you the corresponding line number in the source. </p>
<p>It turned out the crashes were down to something more fundamental as they were happening all over the place in the scheme interpreter - so I had a bit of a wider search and it came down to threads, I hadn't noticed that Android's GLSurfaceView uses a separate thread for rendering, so I was calling the scheme interpreter in the midst of other evaluations, not too great. A simple fix using java locks around the evaluations and rendering calls.</p>
<p>The next thing was implementing more fluxus features. One major improvement is using with-state to wrap push and pop so they are implicitly scoped. This means you can't miss (or add extra) a pops or pushes to your state stack manipulations, so something like:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>push</span><span style='color:#808030; '>)</span>
<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>translate</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>1</span> <span style='color:#008c00; '>2</span> <span style='color:#008c00; '>3</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>build-cube</span><span style='color:#808030; '>)</span>
<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pop</span><span style='color:#808030; '>)</span>
</pre>
<p>becomes:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-state</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>translate</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>1</span> <span style='color:#008c00; '>2</span> <span style='color:#008c00; '>3</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>build-cube</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
</pre>
<p>To do this I had to learn TinyScheme's macro language which is different to Racket's, but this isn't too complex a task:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>define-macro</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-state</span> <span style='color:#808030; '>.</span> args<span style='color:#808030; '>)</span>
  `<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>begin</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>push</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>let</span> <span style='color:#808030; '>(</span><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>r</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>begin</span> <span style='color:#666616; '>,@args</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>pop</span><span style='color:#808030; '>)</span> r<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
</pre>
<p>Here we call push then basically "paste" the code given to the with-state function into a begin block, and record it's return before calling pop. Then we return the value. There is a very similar macro for with-primitive.</p>
<p>There are now quite a few commands ported - there is a new version <a href="http://www.pawfal.org/dave/files/fluxus-0.0.1.apk">packaged here</a>, and this is the test script that I'm using:</p>
<pre style='color:#000000;background:#ffffff;'><span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>clear</span><span style='color:#808030; '>)</span>
<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>colour</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>0</span> <span style='color:#008000; '>0.5</span> <span style='color:#008c00; '>1</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>define</span> cubes
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>map</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>p</span><span style='color:#808030; '>)</span>
     <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-primitive</span> p
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>apply-transform</span><span style='color:#808030; '>)</span>
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>translate</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> -<span style='color:#008000; '>2.5</span> <span style='color:#008c00; '>2</span> <span style='color:#008c00; '>5</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>rotate</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008c00; '>45</span> <span style='color:#008c00; '>0</span> <span style='color:#008c00; '>0</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>translate</span>
        <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span>
         <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>quotient</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>-</span> p <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span> <span style='color:#008c00; '>6</span><span style='color:#808030; '>)</span>
         <span style='color:#008c00; '>0</span>
         <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>modulo</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>-</span> p <span style='color:#008c00; '>1</span><span style='color:#808030; '>)</span> <span style='color:#008c00; '>6</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
       p<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
   <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>build-list</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>n</span><span style='color:#808030; '>)</span>
      <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-state</span>
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>scale</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#008000; '>0.5</span> <span style='color:#008000; '>0.05</span> <span style='color:#008000; '>0.5</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
       <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>build-cube</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
    <span style='color:#008c00; '>36</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>every-frame</span>
 <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>for-each</span>
  <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>lambda</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>p</span><span style='color:#808030; '>)</span>
    <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>with-primitive</span>
     p
     <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>rotate</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vmul</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>vector</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>sin</span> p<span style='color:#808030; '>)</span> <span style='color:#008c00; '>0</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>cos</span> p<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span> <span style='color:#008c00; '>5</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
  cubes<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/04/more-android-tinkering/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shaving yaks on android</title>
		<link>http://www.pawfal.org/dave/blog/2011/04/shaving-yaks-on-android/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/04/shaving-yaks-on-android/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 07:22:24 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[complaint]]></category>
		<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[fluxus]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=1887</guid>
		<description><![CDATA[Mostly my android experience has been good so far, it's been very quick to get things running and be fairly productive. It doesn't come without it's share of yak shaving though. I've spent quite a lot of time trying to get remote debugging of native code working with my phone (a HTC desire) with little [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_1890" class="wp-caption alignnone" style="width: 708px"><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/emulator.png"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/emulator.png" alt="" title="emulator" width="698" height="406" class="size-full wp-image-1890" /></a><p class="wp-caption-text">fluxus installed on the emulator</p></div>
<p>Mostly my android experience has been good so far, it's been very quick to get things running and be fairly productive. It doesn't come without it's share of <a href="http://www.catb.org/jargon/html/Y/yak-shaving.html">yak shaving</a> though. I've spent quite a lot of time trying to get remote debugging of native code working with my phone (a HTC desire) with little success.  This seems to be a <a href="https://groups.google.com/forum/#!topic/android-ndk/cubyLmLNTXQ">fairly well documented problem</a>, the symptoms are messages like this when running ndk-gdb:</p>
<p><span style="color: #008000;">ERROR: Could not setup network redirection to gdbserver?<br />
Maybe using --port=<br />
to use a different TCP port might help?</span></p>
<p>When run with --verbose it seems something a little different is wrong:</p>
<p><span style="color: #008000;">run-as: Package 'am.fo.nebogeo.fluxus' has corrupt installation </span></p>
<p>Which looks like some result of having a rooted phone (which I do) as ndk-debug is a possible attack vector for doing nasty things and is therefore very critical of the permissions of the directories on the system. In order to fix this I installed <a href="https://market.android.com/details?id=com.koushikdutta.rommanager&amp;hl=en">ROM Manager</a> from the market which contains a script to fix permissions. This didn't work at first by pressing the button in the app so after some poking around I found the shell script in: <span style="color: #008000;">/data/data/com.koushikdutta.rommanager/files/fix_permissions</span></p>
<p>It turned out that this script depended on an interesting utility called <a href="http://www.busybox.net/">busybox</a>, which provides tiny versions of GNU programs for phones. The easiest way to install this was to install <a href="https://market.android.com/details?id=com.keramidas.TitaniumBackup">TitaniumBackup</a> and click on it's "Problems" button which would download it, then copy it from <span style="color: #008000;">/data/data/com.keramidas.TitaniumBackup/files</span> into <span style="color: #008000;">/system/bin/</span> and run <span style="color: #008000;">busybox --install -s /system/bin/</span></p>
<p>Then the script could run, and additionally I needed to run <span style="color: #008000;">chmod 774 /data/data/*</span> to get make sure everything was in the correct state, but still no luck with gdb. At this point I decided my time would be better spent on making a linux version of the android app for debugging purposes and get it running in the software emulator. More on this soon.</p>
<p>I'm also documenting bits and pieces of my android development notes on FoAM's wiki <a href="http://libarynth.org/android_dev_notes">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/04/shaving-yaks-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fluxus on Android</title>
		<link>http://www.pawfal.org/dave/blog/2011/04/fluxus-on-android/</link>
		<comments>http://www.pawfal.org/dave/blog/2011/04/fluxus-on-android/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 10:12:22 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[fluxus hacking]]></category>
		<category><![CDATA[livecoding]]></category>

		<guid isPermaLink="false">http://www.pawfal.org/dave/blog/?p=1874</guid>
		<description><![CDATA[I recently took a long train journey and had an idea to use my android phone for taking timelapse photos for Miska Knapek. I had no laptop with me, and realised there was no way I could script anything on the phone itself to do this, or anything more complex. This was the kernel of [...]]]></description>
			<content:encoded><![CDATA[<p>I recently took a long train journey and had an idea to use my android phone for taking timelapse photos for <a href="http://knapek.org/">Miska Knapek</a>. I had no laptop with me, and realised there was no way I could script anything on the phone itself to do this, or anything more complex. This was the kernel of an idea that ended up as two intense days of hacking fluxus into android. </p>
<p>It's running as native code (underneath the JVM), and as it's got the same type of processor as the NDS it shares some code with <a href="http://www.pawfal.org/dave/index.cgi?Projects/BetablockerDS">Betablocker DS</a> which has similar restrictions. There is only a tiny amount of fluxus code ported at the moment, but the scenegraph and core maths is pretty much the same (with some changes to fixed point). I've used <a href="http://tinyscheme.sourceforge.net/">TinyScheme</a> for the interpreter (the same one <a href="http://impromptu.moso.com.au/">Impromptu</a> is based on) which gives you an impressively complete language with a very small footprint. </p>
<p>This is just a quick proof of concept (how far I got is testament to the excellent documentation and ease of portability using C++ with the NDK more than my abilities). It would be nice to expose all the sensors to the script (motion, compass, GPS, camera, wifi) and make it quite general purpose. Writing code with the touch screen is do-able but not very usable - but I have some ideas in this area also...</p>
<p>Get the <a href="https://gitorious.org/flotsam/flotsam/trees/master/android/fluxus">source</a> and, of course the <a href="http://www.pawfal.org/dave/files/fluxus.apk">package</a>. Touch the screen when it's started up to view and eval the source.</p>
<p><a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/snap20110415_122536.png"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/snap20110415_122536.png" alt="" title="snap20110415_122536" width="480" height="800" class="alignnone size-full wp-image-1875" /></a> <a href="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/snap20110415_122553.png"><img src="http://www.pawfal.org/dave/blog/wp-content/uploads/2011/04/snap20110415_122553.png" alt="" title="snap20110415_122553" width="480" height="800" class="alignnone size-full wp-image-1876" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawfal.org/dave/blog/2011/04/fluxus-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

