<?xml version='1.0' encoding='utf-8' ?>
<!--  If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/  -->
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
<channel>
  <title>Luke&apos;s Weblog</title>
  <link>http://lukego.livejournal.com/</link>
  <description>Luke&apos;s Weblog - LiveJournal.com</description>
  <lastBuildDate>Wed, 16 Apr 2008 05:09:59 GMT</lastBuildDate>
  <generator>LiveJournal / LiveJournal.com</generator>
  <lj:journal>lukego</lj:journal>
  <lj:journaltype>personal</lj:journaltype>
  <image>
    <url>http://p-userpic.livejournal.com/56458137/11934870</url>
    <title>Luke&apos;s Weblog</title>
    <link>http://lukego.livejournal.com/</link>
    <width>100</width>
    <height>100</height>
  </image>

<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/13147.html</guid>
  <pubDate>Wed, 16 Apr 2008 05:09:59 GMT</pubDate>
  <title>Couchsurfing</title>
  <link>http://lukego.livejournal.com/13147.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001h3xz/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001h3xz/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Dear European friends!
&lt;p&gt;
I&apos;m starting a spring European hacking tour with my &lt;a href=&quot;http://weitz.de/eclm2008/&quot;&gt;favourite Lisp conference&lt;/a&gt; in Amsterdam this weekend. My master plan is to bounce around the continent for a month or two visiting the kind friends who offer me their couch or spare room for a week or so at a time.
&lt;p&gt;
So! If you&apos;re a kind old friend and you&apos;d care to catch up on old times then do drop me an email :-) I&apos;ll be hacking away on my circuit board all the while.
&lt;p&gt;
I&apos;d particularly appreciate a couch within striking distance of Slussen next week!</description>
  <comments>http://lukego.livejournal.com/13147.html</comments>
  <category>travel</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/12890.html</guid>
  <pubDate>Tue, 08 Apr 2008 12:58:38 GMT</pubDate>
  <title>Interrupts</title>
  <link>http://lukego.livejournal.com/12890.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001gc2s/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001gc2s/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Today I got interrupt-driven network I/O working.
&lt;p&gt;There&apos;s actually a
little more to interrupts than I&apos;d realised. We have two separate bits
of hardware dealing with them: the CAN network controller sets
interrupt signals based on the CAN bus status (data to receive? ready
to transmit?) and the Vectored Interrupt Controller (VIC)
decides how these signals should affect the CPU&apos;s execution. &lt;p&gt;I&apos;m using the CAN interrupts to track the bus status
and using the VIC to temporarily disable interrupts when they&apos;re inconvenient, i.e. when I&apos;m accessing a data structure that&apos;s shared between ISR (Interrupt Service Routine) and non-ISR code. These data structures are FIFO queues based on the ring code that I posted before.
&lt;p&gt;
The tricky part was figuring out exactly when the CAN controller sets and clears interrupt status. Looks like it&apos;s based on discrete events (e.g. CAN frame successfully sent on the bus) rather than just conditions (CAN transmit buffer is empty).
&lt;p&gt; Here&apos;s the code for receiving
data from the CAN bus:

&lt;pre&gt;
\ Is there a CAN frame ready to receive?
: can-rx? ( -- flag )
    CAN-GSR can@ $1 and  0 &amp;lt;&amp;gt;
;

\ Return the number of bytes of data in incoming CAN frame. 
: can-dlen ( -- n )
    CAN-RFS can@
    16 rshift $F and
    8 min
;

\ Free CAN Rx hardware buffers
: can-ack-rx ( -- ) $4 ( RRB ) CAN-CMR can! ;

\ Receive a CAN frame (blocking)
: can-rx ( -- dB dA len id )
    BEGIN can-rx? UNTIL
    CAN-RDB can@  CAN-RDA can@  can-dlen  CAN-RID can@
    can-ack-rx
;
&lt;/pre&gt;

And here&apos;s the interrupt service routine that wakes up when a frame
becomes available on the bus and puts it onto the RX queue for
application-level processing:

&lt;pre&gt;
\ Read a CAN frame from the controller and put it on the RX queue.
: can-rx-isr ( -- )
    can-rx-ring ring-full? IF
        can-disable-rx-interrupt
    ELSE
        can-rx can-rx-ring &amp;gt;ring
    THEN
;
&lt;/pre&gt;

Here&apos;re the words that non-interrupt code uses to temporarily mask out
CAN interrupts to safely access the RX queue:

&lt;pre&gt;
$4100000 ( CAN1-RX CAN1-TX ) CONSTANT CAN-interrupts
: mask-can{ ( -- ) CAN-interrupts disable-interrupts ;
: }mask-can ( -- ) CAN-interrupts enable-interrupts ;
&lt;/pre&gt;

And here&apos;s the non-interrupt code that reads frames from the queue:

&lt;pre&gt;
: can-dequeue? ( -- flag )
    mask-can{  can-rx-ring ring-empty? not  }mask-can
;

: can-dequeue ( -- dB dA len id )
    BEGIN can-dequeue? UNTIL
    mask-can{
        can-rx-ring ring&amp;gt;
    }mask-can
    can-enable-rx-interrupt
;
&lt;/pre&gt;

How do other people&apos;s Forth-based interrupt handlers look?</description>
  <comments>http://lukego.livejournal.com/12890.html</comments>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/12774.html</guid>
  <pubDate>Wed, 02 Apr 2008 06:57:22 GMT</pubDate>
  <title>Jones Forth</title>
  <link>http://lukego.livejournal.com/12774.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001fcp4/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001fcp4/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.annexia.org/&quot;&gt;Jones Forth&lt;/a&gt; is the best program I&apos;ve read in a long time. It&apos;s a complete Forth system written as a literate program by Rich Jones. There are two source files: &lt;a href=&quot;http://www.annexia.org/_file/jonesforth.s.txt&quot;&gt;jonesforth.s&lt;/a&gt;, the kernel written in GNU i386 assembler, and &lt;a href=&quot;http://www.annexia.org/_file/jonesforth.f.txt&quot;&gt;jonesforth.f&lt;/a&gt;, the higher-level parts of Forth written in itself. Recommended reading! See also the &lt;a href=&quot;http://lambda-the-ultimate.org/node/2452&quot;&gt;coverage on LtU&lt;/a&gt;.
&lt;p&gt;
I&apos;ve truly wasted my life up to now by not programming in the one true
language &lt;strike&gt;BASIC&lt;/strike&gt; &lt;strike&gt;assembler&lt;/strike&gt;
&lt;strike&gt;C&lt;/strike&gt; &lt;strike&gt;Java&lt;/strike&gt; &lt;strike&gt;Scheme&lt;/strike&gt;
&lt;strike&gt;Erlang&lt;/strike&gt; &lt;strike&gt;Emacs Lisp&lt;/strike&gt; &lt;strike&gt;Common
Lisp&lt;/strike&gt; &lt;strike&gt;Smalltalk&lt;/strike&gt; Forth!</description>
  <comments>http://lukego.livejournal.com/12774.html</comments>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/12528.html</guid>
  <pubDate>Sat, 29 Mar 2008 13:57:31 GMT</pubDate>
  <title>Interrupts</title>
  <link>http://lukego.livejournal.com/12528.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001e4kx/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001e4kx/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Been writing Forth from the hammock for a while now.
&lt;p&gt;
I&apos;m reasonably happy with my little interrupt dispatcher which has an interface like this:
&lt;pre&gt;
\ interrupt service routine for TIMER1 interrupt
: ticker .&quot; tick &quot; TIMER1 clear-timer-interrupt ;

[&apos;] ticker int$TIMER1 isr!
int$TIMER1 enable-interrupt
&lt;/pre&gt;

and the machinery looks like this:

&lt;pre&gt;
\
\ VIC: Vectored Interrupt Controller
\

VARIABLE isr-table 32 cells ALLOT

: isr-entry ( n -- ) cells isr-table + ;
: isr! ( cfa int# -- ) isr-entry ! ;
: isr@ ( int# -- cfa ) isr-entry @ ;

: service-interrupt ( n -- )
    dup isr@   ( n isr|0 )
    ?dup 0&amp;lt;&amp;gt; IF
        execute
        drop
    ELSE
        .&quot; Unhandled interrupt #&quot; . cr
    THEN
;

: ack-IRQs ( -- ) $0 VICVectAddr ! ;

\ Call the ISR for each enabled and asserted IRQ.
: isr-dispatch ( -- )
    VICIRQStatus @
    32 0 DO ( IRQs )
        dup i bit-set? IF
            i service-interrupt
        THEN
    LOOP
    drop
    ack-IRQs
    EXIT-ISR
;

\ Setup generic interrupt dispatching.
: init-VIC
    32 0 DO  0 i isr!  LOOP
    [&apos;] isr-dispatch forth-isr !
    c-isr @ VICDefVectAddr !  \ default non-vectored IRQ handler
;

\ Utilities for ISRs

: clear-timer-interrupt ( TIMER -- )
    $FF swap T-IR + !   ( clear all interrupt flags )
;

: enable-interrupt ( int# -- ) bit VICIntEnable ! ;
&lt;/pre&gt;

For now there&apos;s some C glue code to catch the interrupt and call back into Forth and I&apos;m doing the vectoring in Forth instead of the hardware. One step at a time.
&lt;p&gt;
To communicate between I/O interrupt handlers and &quot;normal&quot; code I
spent most of the day writing a simple ring (bounded buffer) data
structure. I&apos;m not thrilled at how much stack-munging code this turned
out to be. I reckon that either I didn&apos;t write it very well, or I
could have taken a much simpler approach in general, or both.
&lt;pre&gt;
\ Ring data structure to use as a bounded-buffer.
\ The ring is initialized with two parameters:
\   MAX: The most items that the ring can contain.
\   ITEM-SIZE: The number of words per item in the ring.
\ The basic operations are RING-EMPTY? RING-FULL? &amp;gt;RING RING@ RING&amp;gt;
\ Each add/remove from the queue moves ITEM-SIZE words between the
\ queue and the stack.
\ 
\ For example if ITEM-SIZE is 3 then the stack effect of
\ &amp;gt;RING is ( a b c ring -- ) and RING@ or RING&amp;gt; is ( ring -- a b c ).
\
\ The idea is to have an interrupt handler like:
\ : can-send   ( dB dA len id ) can-tx-ring &amp;gt;ring ;
\ : can-tx-ISR ( -- ) can-tx-ring ring&amp;gt; ( dB dA len id ) can-tx
\ where this ring has four words per item.

\ Data structure layout:
\ MAX is the most items that the ring can hold.
: ring-max          ( ring -- addr ) ;
\ FIRST is the index (0..MAX-1) of the first item i.e. next to be taken.
: ring-first        ( ring -- addr ) cell+ ;
\ LENGTH is the number of items currently in the ring.
: ring-length       ( ring -- addr ) 2 cells + ;
\ ITEM-SIZE is the number of words per item.
: ring-item-size    ( ring -- addr ) 3 cells + ;
\ DATA is the start address of the real data area.
: ring-data         ( ring -- addr ) 4 cells + ;
\ See the example down below for how to initialize a ring.

: ring-empty? ( ring -- flag )
    ring-length @ 0=
;

: ring-full? ( ring -- flag )
    dup ring-length @ ( ring len )
    swap ring-max @   ( len max )
    =
;

\ Return the address of the first (next) data element.
: ring-first-addr ( ring -- addr )
    dup ring-first @          ( ring n )
    over ring-item-size @ cells ( ring n size )
    *                         ( ring offset )
    swap ring-data +          ( element-addr )
;

\ Return the address of the last data element. 
: ring-last-addr ( ring -- addr )
    dup ring-first @          ( ring n )
    over ring-length @ +      ( ring n )
    over ring-max @ mod       ( ring n )
    over ring-item-size @ cells ( ring n size )
    *                         ( ring offset )
    swap ring-data +          ( element-addr )
;

\ Copy the elements of the next data element onto the stack.
: ring@ ( ring -- ... )
    dup ring-first-addr swap ( addr ring )
    ring-item-size @         ( addr size )
    0 DO                     ( addr )
        dup @ swap           ( ... v addr )
\        .&quot; fetched &quot; over . .&quot; from &quot; dup . cr
        cell+
    LOOP                     ( v1 .. vn addr )
    drop                     ( v1 .. vn )
;

\ Drop the next element from the ring.
: ring-drop ( ring -- )
    dup ring-length --
    dup ring-first @ 1+  ( ring first&apos; )
    over ring-max @ mod  ( ring first&apos;&apos; )
    swap ring-first !
;

\ Move the next element of the ring onto the stack.
: ring&amp;gt; ( ring -- ... )
    dup &amp;gt;r
    ring@
    r&amp;gt; ring-drop
;

\ Move a data element from the stack onto the ring.
: &amp;gt;ring ( v1 .. vn ring -- )
    dup ring-last-addr            ( ... ring addr )
    over ring-length ++           ( ... ring addr )
    \ insert the elements backwards so that they&apos;ll be taken out forwards
    over ring-item-size @         ( ... ring addr elem-size )
    1- cells +                    ( ... ring addr )
    swap ring-item-size @ 0 DO    ( ... addr )
\        cr .&quot; store &quot; over . .&quot; at &quot; dup .
        swap over                 ( v1 ... addr vn addr )
        !                         ( v1 ... vn-1 addr )
        cell-
    LOOP
    drop
;

: .ring ( ring -- )
    cr
    .&quot; max:    &quot; dup ring-max @ . cr
    .&quot; first:  &quot; dup ring-first @ . cr
    .&quot; length: &quot; dup ring-length @ . cr
    .&quot; esize:  &quot; ring-item-size @ .
;

\
\ Test/example code
\

\ Ring for testing
VARIABLE r 4 3 * ( four 3-word items ) 4 + ( and 4 words of header ) cells ALLOT

: init-r ( ) 
    \ Configure the ring
    4 r ring-max !
    0 r ring-first !
    0 r ring-length !
    3 r ring-item-size !
    \ Then you can do e.g.
    \ 1 2 3 r &amp;gt;ring   s:
    \ 4 5 6 r &amp;gt;ring   s:
    \ r ring&amp;gt;         s: 1 2 3
    \ r ring&amp;gt;         s: 1 2 3 4 5 6
    \ etc..
;
&lt;/pre&gt;</description>
  <comments>http://lukego.livejournal.com/12528.html</comments>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/12236.html</guid>
  <pubDate>Sat, 22 Mar 2008 03:13:56 GMT</pubDate>
  <title>Forth is bliss</title>
  <link>http://lukego.livejournal.com/12236.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001dhac/&quot;&gt;&lt;a href=&quot;http://picasaweb.google.co.uk/lukego/Thailand&quot;&gt;
&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001dhac&quot; width=&quot;144&quot; height=&quot;108&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
I&apos;m programming in Forth on an exotic island and life is just fine.
I&apos;ve done two weeks of serious hacking now: the first to bring up
Forth on the Keil MCB2100 board and the second to write drivers
and make some extensions to Forth. Serious fun!
&lt;p&gt;
Forth is amazing. There&apos;s hardly any compiler or runtime system and
yet it has all the sophistication of Lisp. This feels like discovering
Gödel, Escher, Bach faithfully expressed in a few dozen cave
paintings.
&lt;p&gt;
The best part about embedded programming is starting from scratch
without using a single line of code that we didn&apos;t write outselves.
Right now we don&apos;t have memory protection, dynamic memory allocation,
concurrency, garbage collection, etc. So we&apos;re going to rediscover
first-hand at what point it&apos;s worth developing these fancy features.
Truly we&apos;re retreading some giant steps :-)
&lt;p&gt;
Here&apos;s some Forth I wrote that may be clever or stupid, I&apos;m not sure
which yet:
&lt;pre&gt;
\ Running time profiling: t( ... )t
: t(
    r&amp;gt; tick      ( r t1 )
    &amp;gt;r &amp;gt;r        ( r: t1 r )
;
: )t
    tick r&amp;gt; r&amp;gt;   ( t2 r t1 )
    swap &amp;gt;r      ( t2 t1 )
    -            ( tdelta )
    . .&quot; ms&quot; cr
;
&lt;/pre&gt;
Ah the rapture of learning a new programming language :-)&lt;/a&gt;</description>
  <comments>http://lukego.livejournal.com/12236.html</comments>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/11850.html</guid>
  <pubDate>Thu, 06 Mar 2008 05:45:33 GMT</pubDate>
  <title>MCB2100</title>
  <link>http://lukego.livejournal.com/11850.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001cq0t/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001cq0t/s320x240&quot; width=&quot;133&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
I&apos;ve traded in my boring old OLPC XO (everybody has one of those these days) for an exciting new &lt;a href=&quot;http://www.keil.com/mcb2100/&quot;&gt;MCB2100 Evaluation Board&lt;/a&gt;. This is a 60Mhz &lt;a href=&quot;http://www.arm.com/products/CPUs/families/ARM7Family.html&quot;&gt;ARM7&lt;/a&gt; microcontroller with 16kB of RAM, 256kB of flash ROM, and some fun add-on connectors. The plan is to use my friend Tony&apos;s homebrew Forth system and the two &lt;a href=&quot;http://en.wikipedia.org/wiki/Controller_Area_Network&quot;&gt;Controller Area Network (CAN)&lt;/a&gt; interfaces to achieve world domination.
&lt;p&gt;
Resistance is futile :-)</description>
  <comments>http://lukego.livejournal.com/11850.html</comments>
  <category>embedded</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/11563.html</guid>
  <pubDate>Sun, 17 Feb 2008 07:23:51 GMT</pubDate>
  <title>The end of act one</title>
  <link>http://lukego.livejournal.com/11563.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001bf5p/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001bf5p&quot; width=&quot;100&quot; height=&quot;99&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Enough with the OLPC for now! I&apos;m off to have some simple fun and let &lt;a href=&quot;http://olenepal.org/about.html&quot;&gt;the guys&lt;/a&gt; and my most
excellent new successor &lt;a href=&quot;http://www.fallenfrukt.com/&quot;&gt;Ties&lt;/a&gt;
continue the work of bringing green laptops to Nepal. Glory be to
all :-)
&lt;p&gt;
It&apos;s been an experience!</description>
  <comments>http://lukego.livejournal.com/11563.html</comments>
  <category>olpc</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/11418.html</guid>
  <pubDate>Thu, 27 Dec 2007 05:48:41 GMT</pubDate>
  <title>So that was 2007</title>
  <link>http://lukego.livejournal.com/11418.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001appa/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001appa/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;

I&apos;m having christmas in Australia now. My next stop is the &lt;a href=&quot;http://www.cm.is.ritsumei.ac.jp/c5-08/&quot;&gt;C5 conference&lt;/a&gt; and
talking at the colocated &lt;a href=&quot;http://community.ofset.org/index.php/C5_2008_Squeak_Party&quot;&gt;Squeak
Party&lt;/a&gt; in France (see you there!) Then it&apos;s back home to
Kathmandu.
&lt;p&gt;
Here&apos;s a roundup of the later part of my 2007:
&lt;p&gt;
I&apos;ve been a full-time unofficial/unauthorised/unpaid volunteer for One Laptop
Per Child since september when I moved to Nepal to help the local
effort there. I reckon OLPC &lt;i&gt;will&lt;/i&gt; cause a real revolution in
education: it&apos;ll create the environment in which knowledge spreads
naturally between humans (kids, adults, experts) and we&apos;ll marvel at
the results. With hindsight we&apos;ll think that tens of thousands of
hours of rigid and sterile instruction is a bit of an insult to human
dignity.
&lt;p&gt;
But enough about that for now. It&apos;s fun to be able to play a tiny part.
&lt;p&gt;
&lt;a href=&quot;http://olenepal.org/&quot;&gt;We&lt;/a&gt;&apos;ve &lt;a href=&quot;http://nepal.ole.org/home/?q=blog&quot;&gt;done a lot&lt;/a&gt; while I&apos;ve
been in Nepal. We &lt;a href=&quot;http://nepal.ole.org/home/?q=node/67&quot;&gt;learned Squeak&lt;/a&gt; and
found a practical way of working, wrote our &lt;a href=&quot;http://nepal.ole.org/home/?q=node/73&quot;&gt;initial demo software&lt;/a&gt;,
found &lt;a href=&quot;http://nepal.ole.org/home/?q=node/81&quot;&gt;kids to work
with&lt;/a&gt;, cultivated &lt;a href=&quot;http://nepal.ole.org/home/?q=node/102&quot;&gt;ties with local
schools&lt;/a&gt;, created &lt;a href=&quot;http://nepal.ole.org/home/?q=node/90&quot;&gt;excellent jobs&lt;/a&gt; for
Nepali programmers, &lt;a href=&quot;http://nepal.ole.org/home/?q=node/97&quot;&gt;recruited really inspiring
people&lt;/a&gt;, found help from &lt;a href=&quot;http://www.vpri.org/&quot;&gt;really
generous experts&lt;/a&gt; (&lt;a href=&quot;http://croquetweak.blogspot.com/&quot;&gt;one of whom&lt;/a&gt; even came all the
way over to visit us), and started &lt;a href=&quot;http://nepal.ole.org/home/?q=node/107&quot;&gt;sewing the seeds&lt;/a&gt; of really
interesting skills that can grow in Kathmandu and then spread out from
here. The project continues at a pretty rapid pace.
&lt;p&gt;
But there&apos;s a lot left to do and lots of things to think about! In
particular we need to work on our relationship with the OLPC
mothership in Boston. If you&apos;re one of them and you&apos;re reading this
then please get in touch with me and let&apos;s find a way to drink beer
and talk shop!</description>
  <comments>http://lukego.livejournal.com/11418.html</comments>
  <category>olpc</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/11010.html</guid>
  <pubDate>Thu, 06 Dec 2007 13:29:58 GMT</pubDate>
  <title>Been busy</title>
  <link>http://lukego.livejournal.com/11010.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/00019ykz/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/00019ykz/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Jumped down a 160m gorge on both &lt;a href=&quot;http://www.thelastresort.com.np/bungy.htm&quot;&gt;bungee&lt;/a&gt; and &lt;a href=&quot;http://www.thelastresort.com.np/swing.htm&quot;&gt;swing&lt;/a&gt;.
&lt;p&gt;
Adapted to an incredibly comfortable &lt;a href=&quot;http://en.wikipedia.org/wiki/Newar_people&quot;&gt;Newari&lt;/a&gt; lifestyle: boiled eggs and
homemade jam on hot roti for breakfast (with a fresh guava from the tree),
excellent family for company, a great pair of dogs to fight with,
and a rich and varied feast for dinner every night.
&lt;p&gt;
Trekked to remote Rara lake with a highly amusing bunch of people.
&lt;p&gt;
Got &lt;a href=&quot;http://ole.org/?p=48&quot;&gt;photographed&lt;/a&gt; with my post-trek novelty musketeer mustache (what else to do with 10 days&apos; growth?) and our friends at the department of education.
&lt;p&gt;
Did a &lt;a href=&quot;http://aponarch.com/hhhh/trash/trash_1501-1525/trash_1515/trash_1515.html&quot;&gt;ferocious Haka&lt;/a&gt; at the hash and followed it up with a fairly
unhinged expat party.
&lt;p&gt;
&lt;a href=&quot;http://nepal.ole.org/home/?q=node/102&quot;&gt;Took laptops to a
school&lt;/a&gt; and saw real live kids actually enjoying doing schoolwork!
It&apos;s SO satisfying to get out of the office and have fun with the kids
and teachers.
&lt;p&gt;
The whole project is pretty intense: I flow smoothly up to crests (My
God this will be fantastic!) and down through troughs (My God this will
never work we&apos;re doing it all wrong!) and on the whole I love it. This
is exactly the kind of hard and miserable fun that I&apos;d missed from
startup life. :-)
&lt;p&gt;
Next week we&apos;ve lured the illustrious &lt;a href=&quot;http://croquetweak.blogspot.com/&quot;&gt;Bert Freudenberg&lt;/a&gt; to visit
us and show off some Squeak hacking tricks. We&apos;ll also be &lt;a href=&quot;http://nepal.ole.org/home/?q=node/101&quot;&gt;teaching a one-day
workshop&lt;/a&gt; of 30 people (programmers, teachers, students, kids) how to
develop educational software with Etoys.
&lt;p&gt;
Haven&apos;t been taking photos!</description>
  <comments>http://lukego.livejournal.com/11010.html</comments>
  <category>kathmandu</category>
  <category>olpc</category>
  <category>nepal</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/10847.html</guid>
  <pubDate>Thu, 15 Nov 2007 14:11:11 GMT</pubDate>
  <title>A Farewell to Pong</title>
  <link>http://lukego.livejournal.com/10847.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/00018ff9/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/00018ff9/s320x240&quot; width=&quot;160&quot; height=&quot;115&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
I recently tried to rewrite the &lt;a href=&quot;http://members.aol.com/plforth/ofpong/&quot;&gt;MacHack PONG&lt;/a&gt; in the XO firmware. I&apos;d just read Thinking Forth so I didn&apos;t like the code in &lt;a href=&quot;http://members.aol.com/plforth/ofpong/20020313/ofpong.txt&quot;&gt;PONG.FTH&lt;/a&gt;: I wanted there to be one screenful of code for each important section (showing the score, taking keyboard input, etc). Then I&apos;d be comfortable with writing the two-line feature that Mitch Bradley had suggested adding.
&lt;p&gt;
What really happened is that I had a lot of fun, learned a lot of Forth, didn&apos;t finish the game, and made absolutely no useful contribution to the PONG on the XO. Not too bad as far as failures go. :-)
&lt;p&gt;
Anyway I&apos;m an old Amiga guy so I wanted the game logic to execute in lock-step with the screen refresh, and since the vertical blanking period is very short I used double-buffering to avoid flicker:

&lt;pre&gt;
\ PONGDBUF.FTH: Simple double-buffer support.

: db-fill-rectangle ( col x y w h -- )
   rot screen-height + -rot  ( col x y&apos; w h -- )
   fill-rectangle
;
: wait-vblank ( -- )
   gp-wait-ready
   0 0 wh!  0 0 dst!  0 0 src!
   h# 6000.00cc ropmode!
   h# 400 blt!
;
: db-blit ( -- )
   wait-vblank
   0 screen-height  0 0  screen-width screen-height 20 - gp-move
;
&lt;/pre&gt;

And with lots of effort I did eventually manage to draw the score
using only a screen of code, though I reckon it should have been
simpler and more direct:

&lt;pre&gt;
\ PONGSCOR.FTH: Text drawing
decimal
h# ffff constant fg
h# 0000 constant bg

&quot; ****.   *.****.****.*  *.****.*   .****.****.****.&quot;
&quot; *  *.   *.   *.   *.*  *.*   .*   .   *.*  *.*  *.&quot; $cat2
&quot; *  *.   *.   *.   *.*  *.*   .*   .   *.*  *.*  *.&quot; $cat2
&quot; *  *.   *.****.****.****.****.****.   *.****.****.&quot; $cat2
&quot; *  *.   *.*   .   *.   *.   *.*  *.   *.*  *.   *.&quot; $cat2
&quot; *  *.   *.*   .   *.   *.   *.*  *.   *.*  *.   *.&quot; $cat2
&quot; ****.   *.****.****.   *.****.****.   *.****.   *.&quot; $cat2
&quot; --------------------------------------------------&quot; $cat2 drop
   constant drawing-instructions

variable ip variable xloc variable yloc

: fill-box ( color -- ) xloc @ yloc @ 10 10 db-fill-rectangle ;
: draw-digit ( x y digit )
   10 mod  5 *  drawing-instructions +  ip !
   yloc !   xloc !
   begin   ( Empty )
      ip @ c@ dup case
         ascii * of  1 ip +!  fg fill-box  10 xloc +!  endof
         bl      of  1 ip +!  bg fill-box  10 xloc +!  endof
         ascii . of 46 ip +!  -40 xloc +!  10 yloc +!  endof
      endcase
   ascii - =  until
;
: draw-score ( x y score )
   &amp;gt;r 2dup swap 50 + swap       ( x y x&apos; y r: score )
   r@      draw-digit           ( x y      r: score )
   r&amp;gt; 10 / draw-digit
;
hex
&lt;/pre&gt;

Drawing the board, bats, and ball was no problem at all:

&lt;pre&gt;
\ PONGDRAW.FTH: Drawing non-text graphics
decimal

: units ( n -- n ) 20 * ;
: unit  ( n -- n ) units ;

: draw-ball ( x y -- ) fg -rot 1 unit 1 unit  db-fill-rectangle ;
: draw-bat  ( x y -- ) fg -rot 1 unit 6 units db-fill-rectangle ;
: draw-bat1 ( y -- )                 1 unit swap draw-bat ;
: draw-bat2 ( y -- ) screen-width 2 units - swap draw-bat ;
: draw-score1 ( score -- )                100 40 rot draw-score ;
: draw-score2 ( score -- ) screen-width 200 - 40 rot draw-score ;
: draw-centerline ( -- )
   fg  screen-width 10 - 2 /  40  10 screen-height 80 -  db-fill-rectangle
;
: draw-boundary ( y -- ) &amp;gt;r  fg 0 r&amp;gt; screen-width 20 db-fill-rectangle ;
: draw-boundaries ( -- ) 0 draw-boundary  screen-height 20 - draw-boundary ;

: fill-screen ( color -- ) 0 0 screen-width screen-height db-fill-rectangle ;
: draw-screen ( bat1-y bat2-y ball-x ball-y score1 score2 -- )
   bg fill-screen  draw-boundaries  draw-centerline
   draw-score2 draw-score1
   draw-ball draw-bat2 draw-bat1
;
: test-draw-screen ( -- ) 200 500 800 500 72 48 draw-screen ;

hex
&lt;/pre&gt;

The keyboard code fits in one screen but it&apos;s the one part I mostly borrowed from the original:

&lt;pre&gt;
\ PONGKDB.FTH: Keyboard input
decimal
0 value key_esc        0 value key_off
0 value key_left_down  0 value key_left_up
0 value key_right_down 0 value key_right_up

: initkeys    ( -- ) &quot; stdin @ iselect  &apos; get-scan  0 alarm  iunselect&quot; eval ;
: restorekeys ( -- ) &quot; stdin @ iselect  &apos; get-scan 10 alarm  iunselect&quot; eval ;
: clear-key-states ( -- )
   false to key_esc         false to key_off
   false to key_left_down   false to key_left_up
   false to key_right_down  false to key_right_up
;
0 value e0-seen?
: set-key-states ( down? station )
   dup . dup 1 = if abort&quot; quit&quot; then  case
      h# 65 of  e0-seen? if to key_right_up   else to key_left_up   then  endof
      h# 66 of  e0-seen? if to key_right_down else to key_left_down then  endof
      h# 69 of  to key_esc        endof   \ lower left game button
      h# 2a of  to key_left_up    endof   \ shift-left
      h# 5b of  to key_left_down  endof   \ hand-left
      h# 36 of  to key_right_up   endof   \ shift-right
      h# 5c of  to key_right_down endof   \ hand-right
      h# 5d of  to key_esc        endof   \ square
      h#  1 of  to key_off        endof   \ ESC scancode
   endcase
;
: scan-keyboard ( -- )
   clear-key-states
   begin &quot; get-data?&quot; stdin @ $call-method  while   ( scancode )
      dup h# e0 =  if
         drop  true to e0-seen?
      else
         set-key-states  0 to e0-seen?
      then
   repeat
;
hex
&lt;/pre&gt;

And then the game logic itself -- well, that&apos;s where I stopped,
because I got stuck chasing a bug that somehow locked up the keyboard
soon after the game starts:
&lt;pre&gt;
\ PONGGAME.FTH: Game state
decimal

variable bat1-y variable bat2-y variable ball-x variable ball-y
variable ball-dx variable ball-dy
42 value score1 0 value score2
: step-ball ( -- ) ball-dx @ ball-x +!  ball-dy @ ball-y +! ;

: game-draw ( -- )
   bat1-y @ bat2-y @ ball-x @ ball-y @ score1 score2 draw-screen
;
: game-loop ( -- )
   begin
      scan-keyboard
      key_left_up    if -10 bat1-y +! then
      key_left_down  if  10 bat1-y +! then
      key_right_up   if -10 bat2-y +! then
      key_right_down if  10 bat2-y +!  ascii x emit then
\      3 ball-x +!  1 ball-y +!
      game-draw  db-blit
      random d# 10000 mod 0= if 1 to key_off then
   key_off  until
;

: pong-display-test ( -- )
   d# 100 0 do  test-draw-screen db-blit  loop
;
: pong-game ( -- )
   initkeys  game-loop  restorekeys
;

hex
&lt;/pre&gt;
There it ends, and I&apos;ll never finish it now that I&apos;m having more fun programming in Etoys. So it goes!</description>
  <comments>http://lukego.livejournal.com/10847.html</comments>
  <category>olpc</category>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/10680.html</guid>
  <pubDate>Wed, 17 Oct 2007 13:07:58 GMT</pubDate>
  <title>Gone trekkin&apos;</title>
  <link>http://lukego.livejournal.com/10680.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/00017r4t/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/00017r4t&quot; width=&quot;76&quot; height=&quot;73&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;We&apos;ve been &lt;a href=&quot;http://nepal.ole.org/&quot;&gt;hacking&lt;/a&gt; but now it&apos;s time for a &lt;a href=&quot;http://www.rara-lake.com/&quot;&gt;trekking&lt;/a&gt; holiday!&lt;br /&gt;&lt;br /&gt;Freedom is overrated: now I&apos;m on board to hack for the OLPC effort in Nepal for a whole year. Oh the plans I had.. but this will be amazing stuff! Since the guys in Boston produced enough miracles to build this lovely little green machine I reckon it&apos;s the least we travel-loving programmers can do to jump on a plane and help put it to use.</description>
  <comments>http://lukego.livejournal.com/10680.html</comments>
  <category>olpc</category>
  <category>nepal</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/10312.html</guid>
  <pubDate>Fri, 21 Sep 2007 03:05:49 GMT</pubDate>
  <title>Etoys</title>
  <link>http://lukego.livejournal.com/10312.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/000163sp/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/000163sp/s320x240&quot; width=&quot;160&quot; height=&quot;107&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
I&apos;ve been learning more &lt;a href=&quot;http://www.squeakland.org/&quot;&gt;Etoys&lt;/a&gt; lately and it&apos;s extremely cool. I didn&apos;t understand it at all the first few times I played with it but now I can teach it to somebody else in an hour. The demos involve a lot of smiling and laughing :-)
&lt;p&gt;
The downside is that I don&apos;t know a good way to &quot;get&quot; it all by yourself. There really needs to be a cool demo and ideally someone you can play along with to get started. This would seem to limit how well it can spread, but on the upside it means I can travel around the world giving cool and surprising demos to people. :-)
&lt;p&gt;
I&apos;ve started digging a little bit into the implementation. I hate to say it but even after quite some exposure I still find Smalltalk/Squeak/Morphic code by far the hardest to understand. As a Lisp/Erlang/C/etc programmer I expect to be able to print out the listing for some major concept (viewer, player, etc), read it form start to finish, and basically understand it. But Squeak code is a complex graph (twisty maze). My friend &lt;a href=&quot;http://jsnell.iki.fi/blog/&quot;&gt;Juho&lt;/a&gt; rightly pointed out over beer that since I know basically how I want the program linearised (depth-first into subroutines) I should probably stop whining and write a custom Smalltalk browser. I wonder if this has been done, or if a little more mastery of the cross-reference features will make the idea seem silly. We&apos;ll see.
&lt;p&gt;
We&apos;re recruiting an Etoys programming and design team here in Kathmandu to write Squeak-based educational software. Should be fun :-)</description>
  <comments>http://lukego.livejournal.com/10312.html</comments>
  <category>squeak</category>
  <category>etoys</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/10122.html</guid>
  <pubDate>Fri, 21 Sep 2007 02:56:56 GMT</pubDate>
  <title>Etoys</title>
  <link>http://lukego.livejournal.com/10122.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/000163sp/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/000163sp/s320x240&quot; width=&quot;160&quot; height=&quot;107&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
I&apos;ve been learning more &lt;a href=&quot;http://www.squeakland.org/&quot;&gt;Etoys&lt;/a&gt; lately. It&apos;s extremely cool: I didn&apos;t understand it at all the first few times I played with it but now I can demo and teach it to somebody else in an hour. The demos involve a lot of smiling and laughing :-)
&lt;p&gt;
The downside is that I don&apos;t know a good way to &quot;get&quot; it all by yourself. There really needs to be a cool demo and ideally someone you can play along with to get started. This would seem to limit how well it can spread, but on the upside it means I can travel around the world giving cool and surprising demos to peoople. :-)</description>
  <comments>http://lukego.livejournal.com/10122.html</comments>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/9738.html</guid>
  <pubDate>Sun, 16 Sep 2007 07:53:06 GMT</pubDate>
  <title>Kathmandu</title>
  <link>http://lukego.livejournal.com/9738.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/00014t78/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/00014t78/s320x240&quot; width=&quot;160&quot; height=&quot;104&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Kathmandu is great!
&lt;p&gt;
In the few days since I landed I&apos;ve done productive work at the
newly-forming &lt;a href=&quot;http://www.ole.org/&quot;&gt;OLE Nepal&lt;/a&gt;, explored
Thamel, been introduced to the nightlife (good), &lt;a href=&quot;http://aponarch.com/hhhh/&quot;&gt;Hashed&lt;/a&gt; around the edge of
Kathmandu valley, and now I&apos;m having a relaxing sunday breakfast with
good coffee and wifi at the Himalayan Java Cafe.
&lt;p&gt;
Kathmandu is great value. You can find a clean room in Thamel for
$2/night and a good all-you-can-eat meal of &lt;a href=&quot;http://en.wikipedia.org/wiki/Dahl_baht&quot;&gt;Dahl Baht&lt;/a&gt; for about
$0.50. Best of all is that you can eat with your hands. :-)
&lt;p&gt;
&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/00015zpg/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/00015zpg/s320x240&quot; width=&quot;160&quot; height=&quot;114&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;
&lt;/a&gt;
There was one day of productive work so far: I was introduced to &lt;a href=&quot;http://www.nepalitimes.com/issue/324/Leisure/12869&quot;&gt;Christine&lt;/a&gt;
the teacher-trainer and found out how she&apos;d like to computerise a
couple of simple maths/english textbooks that she wrote. I tried
prototyping the first bit (a grade #1 adding exercise) with Etoys and
this was really pleasant. Just by dragging and dropping some stock
objects and pictures from the internet I easily made a simple
authoring environment for creating a book of adding exercises.
There&apos;re only three lines of drag&apos;n&apos;drop code to indicate whether the
answer is correct, see screenshot!
&lt;p&gt;
A little polish is needed and then it&apos;ll be fun to see how it&apos;s received. I&apos;m glad there&apos;s productive work to be done from day one.</description>
  <comments>http://lukego.livejournal.com/9738.html</comments>
  <category>travel</category>
  <category>kathmandu</category>
  <category>olpc</category>
  <category>ole</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/9693.html</guid>
  <pubDate>Mon, 10 Sep 2007 06:32:44 GMT</pubDate>
  <title>The adventure continues..</title>
  <link>http://lukego.livejournal.com/9693.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001287q/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001287q/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
I&apos;ve now spent six weeks taking it easy and kicking around in the
middle east. &quot;Real life&quot; is a fairly distant memory by now. :-)
&lt;p&gt;
The focal point has been visiting my friend and history tutor :-)
Denis Mashkevich, the philosopher and Lisp programmer of Jerusalem. I
also caught up with the west-coast Lisp scene (Michael Livshin) and
even the illustrious Ehud Lamm! I hadn&apos;t met Ehud before and it was
great to find we have so much in common.
&lt;p&gt;
I also made some new Hollywood friends along the way who I&apos;m looking
forward to meeting up with once my eastward trajectory lands me in
California. :-)
&lt;p&gt;
Now I&apos;m exploring around Petra (again) and rediscovering the wonderful
truth that the whole world smiles back at the guy on the unicycle. :-)
Yesterday I rode from Wadi Musa down through the Beduin village to Little
Petra and spent some hours hiking in the mountains. It was all smiles
and jokes for the whole day and lots of people waved me down to offer
tea while they tried their luck at riding. So, so, so much fun :-)
&lt;p&gt;
The unicycle is an excellent instrument for measuring the overall
societal whimsy level. The Jordanians score very well: right up there
with the Russians!
&lt;p&gt;
Photos: around &lt;a href=&quot;http://picasaweb.google.com/lukego/Israel&quot;&gt;Israel&lt;/a&gt;, brilliant scuba diving holiday to &lt;a href=&quot;http://picasaweb.google.com/lukego/Dahab&quot;&gt;Dahab&lt;/a&gt;, around &lt;a href=&quot;http://picasaweb.google.com/lukego/Jordan&quot;&gt;Petra&lt;/a&gt;.
&lt;p&gt;
Tonight I&apos;ll fly from Amman towards Kathmandu to start on some real
work!</description>
  <comments>http://lukego.livejournal.com/9693.html</comments>
  <category>travel</category>
  <category>jordan</category>
  <category>petra</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/9355.html</guid>
  <pubDate>Tue, 04 Sep 2007 08:40:00 GMT</pubDate>
  <title>Leisurely XO&apos;ing</title>
  <link>http://lukego.livejournal.com/9355.html</link>
  <description>I&apos;m lurking around the middle east: hacking Forth, diving the red sea, taking up space in comfy cafes, etc. For weeks now the XO has been my primary computer and I&apos;m writing this blog entry on it. I do love this little machine but it&apos;ll take some more time before I can set productivity records using it :-)&lt;br /&gt;&lt;br /&gt;For hacking I mostly live in Open Firmware without booting the operating system, but by now it&apos;s a bit lonely hacking away in there when nobody around me has another XO to hack alongside. Hopefully we can start an Open Firmware hackers club in Kathmandu! I&apos;ll be there in a week and I hope to meet as many local hackers as possible over the autumn.&lt;br /&gt;&lt;br /&gt;For other computer usage I&apos;ve converted the XO into a basic Fedora box simply by editing /etc/inittab to start at runlevel 3 (i.e. not start Sugar) and doing &apos;yum install&apos; of some essentials (ratpoison, firefox, gv, etc). Squeak runs reasonably well too, I&apos;ve installed the standard &quot;dev&quot; image. I&apos;m using tiny shell scripts to fiddle /sys for things like switching the screen into black-and-white reflective mode.&lt;br /&gt;&lt;br /&gt;The screen is really beautiful in greyscale mode with reflected sunlight, even here in the shade near some open windows. I&apos;m disappointed each time the sun sets and I have to switch into backlit-mode. Picture it: the next generation of hackers habitually rising with the sun to hack fiendishly in open, airy places until sunset.</description>
  <comments>http://lukego.livejournal.com/9355.html</comments>
  <category>olpc</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/8987.html</guid>
  <pubDate>Tue, 14 Aug 2007 07:58:06 GMT</pubDate>
  <title>boing boing boing</title>
  <link>http://lukego.livejournal.com/8987.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0001112r/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0001112r/s320x240&quot; width=&quot;90&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Today&apos;s XO firmware graphics hack makes the screen bounce up and down! To run it you first install a recent firmware (one having graphics processor words) and then type:&lt;pre&gt;25 bouncing&lt;/pre&gt; after you&apos;ve loaded this code of &lt;code&gt;bounce.fth&lt;/code&gt;:

&lt;pre&gt;
screen-ih iselect     \ open display device

: wait-vblank ( -- )  \ wait until the next screen refresh
   gp-wait-ready  0 0 wh!  h# 6000.00cc ropmode!   \ setup NOP
   b# 10000000000 blt!                             \ execute on next vblank
;
: origin-xy ( -- x y ) 0 0 ;
: screen-wh ( -- w h ) screen-width screen-height ;
: bounce-setup ( -- )
   gp-setup
   origin-xy  0 screen-height      screen-wh  gp-move
   ffff       0 screen-height 2 *  screen-wh  gp-fill
;
: bounce-step ( speed pos -- speed&apos; pos&apos; )
   over +         ( speed  pos&apos; )
   swap 1- swap   ( speed&apos; pos&apos; )
;
: bounce-draw ( pos -- )
   screen-height +  0 swap  ( src-x,y )
   origin-xy screen-wh      ( src-x,y dst-x,y w,h )
   gp-move
;
: bounce ( init-speed -- )
   bounce-setup
   0 begin
      wait-vblank  bounce-step  dup bounce-draw    ( speed pos )
   dup 0= until  2drop
;      
: bouncing ( init-speed -- )
   recursive  dup 0&amp;gt; if  dup bounce  2 / bouncing  then
;
&lt;/pre&gt;</description>
  <comments>http://lukego.livejournal.com/8987.html</comments>
  <category>olpc</category>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/8760.html</guid>
  <pubDate>Fri, 10 Aug 2007 15:03:27 GMT</pubDate>
  <title>ed, man!</title>
  <link>http://lukego.livejournal.com/8760.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/00010qw9/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/00010qw9/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Yesterday I built an OLPC firmware image for the first time. It&apos;s easy and rumoured to be fairly safe, all you have to do is type this line from the top of the svn tree:
&lt;pre&gt;
cd ./cpu/x86/pc/olpc/build; make clean; make
&lt;/pre&gt;
The scrolling speed is gratifyingly fast now that
Mitch Bradley committed my Geode accelleration patch! (He rewrote it
before doing so, but I&apos;m a newbie so that&apos;s to be expected :-))
&lt;p&gt;
Now I&apos;m trying to setup a self-sufficient Forth development
environment on the XO. I&apos;m quite well adjusted to the keyboard by now
so there&apos;s no good reason to lug this Macbook around from cafe to cafe just
to run Emacs.
&lt;p&gt;
The first thing I need is a convenient and persistent way to edit
Forth programs on the XO. The programs should be stored on the
2GB SD-memory card that I added so that they&apos;re not overwritten when I
install a new OLPC software image on the 1GB internal NAND flash.
Mitch Bradley already sent me a lot
of pointers to get started with file system access (I&apos;ve put these on
the OLPC Wiki as draft &lt;a href=&quot;http://wiki.laptop.org/go/Forth_Lesson_13&quot;&gt;Forth Lesson #13&lt;/a&gt;) so it&apos;s only a matter of
building some convenient &quot;editing words&quot; on top.
&lt;p&gt;
So I&apos;ve hacked together something that I&apos;m pretty happy with. Now I
write &lt;code&gt;ed foo&lt;/code&gt; and the openfirmware text editor (which is
minimal but comfortably Emacsish) pops up with the contents of
&lt;code&gt;sd:\foo.fth&lt;/code&gt;. I edit and then press ^C to finish and
optionally save the changes. If I want to evaluate the most recently
edited source file I just type &lt;code&gt;ev&lt;/code&gt;.
&lt;p&gt;
Here&apos;s the code:

&lt;pre&gt;
0 0   2value   ed-file      \ filename being edited
10000 constant ed-maxsize   \ buffer size (max)
0     value    ed-size      \ amount of text in buffer
      create   ed-buf  ed-maxsize allot

: read-content ( adr len name$ -- sz )
   r/o open-file  if  0  else  dup &amp;gt;r  fgets  r&amp;gt; fclose  then
;
: write-content ( content$ name$ -- )
   2dup $delete-all  $create-file &amp;gt;r  &quot; write&quot; r@ $call-method  r&amp;gt; close-dev
;

: name&amp;gt;file ( $n -- $fn ) &quot; sd:\&quot; 2swap &quot; .fth&quot;  $cat2 $cat2 ;
: edit-string [ also hidden ] edit-file [ previous ] ;

: ed$   ( -- s$ ) ed-buf ed-size ;
: ed-read  ( -- ) ed-buf ed-maxsize ed-file read-content  is ed-size ;
: ed-write ( -- ) ed$ ed-file write-content ;
: ed-save? ( -- ) &quot; Save?&quot; confirmed? if ed-write then ;
: ed-edit  ( -- ) ed$ ed-maxsize edit-string is ed-size ;
: ed \ name ( -- )
   safe-parse-word name&amp;gt;file is ed-file
   ed-read ed-edit ed-save?
;
: re-ed ( -- ) ed-edit ed-save? ;
: ev    ( -- ) ed$ eval ;
&lt;/pre&gt;

This feels pretty good so far. I would like to know a way so that I
could re-evaluate this source file to pick up new definitions without
reallocating all the variables, so that I could preserve the existing
state (like &lt;code&gt;DEFVAR&lt;/code&gt; vs &lt;code&gt;DEFPARAMETER&lt;/code&gt;
in Lisp). I don&apos;t really understand how Forth people do interactive
redefinition of functions yet.
&lt;p&gt;
Next target: reading and referencing openfirmware sources without the Macbook.</description>
  <comments>http://lukego.livejournal.com/8760.html</comments>
  <category>olpc</category>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/8640.html</guid>
  <pubDate>Tue, 07 Aug 2007 16:49:36 GMT</pubDate>
  <title>Forth: baby steps with Geode</title>
  <link>http://lukego.livejournal.com/8640.html</link>
  <description>I did my first little odd job on OLPC: making the firmware&apos;s &lt;a href=&quot;http://www.openbios.org/viewvc/ofw/termemu/fb16.fth?view=markup&amp;amp;root=OpenFirmware&quot;&gt;console&lt;/a&gt; snappier by scrolling the screen using the &lt;a href=&quot;http://www.amd.com/files/connectivitysolutions/geode/geode_lx/33234E_LX_databook.pdf&quot;&gt;Geode&lt;/a&gt; graphics processor instead of the CPU. This turns out to be really simple using the &lt;a href=&quot;http://www.openbios.org/viewvc/dev/geode/display/gp.fth?view=markup&amp;amp;root=OpenFirmware&quot;&gt;tiny library&lt;/a&gt; for accessing the graphics processor registers:

&lt;pre&gt;
: ypos ( line# -- y ) char-height *  window-top + ;

: fbgeode-delete-lines ( delta-#lines -- )
   line# + ypos  window-left  swap ( src-x,y )
   window-left  line# ypos         ( src-x,y dst-x,y )
   screen-width screen-height      ( src-x,y dst-x,y w,h )
   gp-move
;

\ Patch geode acceleration into an installed (fb16) framebuffer
: fbgeode-accelerate  ( -- )
   gp-setup
   [&apos;] fbgeode-delete-lines is delete-lines
;   
&lt;/pre&gt;

This improves the speed of inserting a new line of text into the framebuffer from 58ms to 4.5ms.</description>
  <comments>http://lukego.livejournal.com/8640.html</comments>
  <category>olpc</category>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/8427.html</guid>
  <pubDate>Thu, 26 Jul 2007 20:44:56 GMT</pubDate>
  <title>XO: demo machine extraordinaire!</title>
  <link>http://lukego.livejournal.com/8427.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0000z3a2/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0000z3a2/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
Here&apos;s my first tiny graphics hack for the XO. If you have one, try this:

&lt;ol&gt;
&lt;li&gt;Power on the machine while holding down one of the game buttons (next to the screen). Release the game button when instructed.&lt;/li&gt;
&lt;li&gt;Press escape (top-left key) to skip the normal boot sequence and go directly to the Forth &lt;code&gt;ok&lt;/code&gt; prompt.&lt;/li&gt;
&lt;li&gt;Enter this line:
&lt;pre&gt;
screen-ih iselect  ff000000 20f580 0 do  dup dup c@ invert swap c!  1 +  loop
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
Wow! Fantastic! The colours on the screen all became inverted! Yeeaaah!

&lt;hr width=&quot;40%&quot;&gt;

Okay, not so amazing, and the snippet is confusing for a few reasons:
&lt;ol&gt;
&lt;li&gt;It&apos;s optimized to be as few characters as possible so that you kids can type it.&lt;/li&gt;
&lt;li&gt;It uses constants for video memory location and screen size. My God, after all these years, a moment of freedom from slavery to portability!&lt;/li&gt;
&lt;li&gt;I&apos;m a Forth newbie and I&apos;m probably fumbling around with my stack manipulation.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
To be clearer about what&apos;s going on, let&apos;s rewrite that program by
using OFW&apos;s macro assembler to convert it into machine code:

&lt;pre&gt;
code inverse-screen ( -- )
  frame-buffer-adr #  eax mov                \ eax is the increasing memory address
  screen-height /scanline * 4 / #  ecx mov   \ ecx is the loop counter (down to zero)
  begin                                      \ ebx is a temporary
    0 [eax] ebx mov
    ebx not
    ebx 0 [eax] mov
    4 # eax add
    ecx dec
  0= until
c;
&lt;/pre&gt;

Clear now? Good!
&lt;p&gt;
.. and now that we have standard hardware we can also once again talk
plainly about timings. The Forth version takes around 1284ms to run
whereas the assembler one takes around 89ms. Plain and simple!</description>
  <comments>http://lukego.livejournal.com/8427.html</comments>
  <category>olpc</category>
  <category>asm</category>
  <category>forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/8023.html</guid>
  <pubDate>Sun, 22 Jul 2007 20:16:57 GMT</pubDate>
  <title>World Roller Tour #1: Moscow</title>
  <link>http://lukego.livejournal.com/8023.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0000yfa3/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0000yfa3/s320x240&quot; width=&quot;90&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;

Finally I have my footnote in the history books! I&apos;m the guy who introduced the unicycle to Moscow at the Friday Night Skate a couple of weeks ago following a drunken train trip from Helsinki with a lot of crazy finns. Extreme fun for far, far, far too many kilometers :-)
&lt;p&gt;
Photos &lt;a href=&quot;http://orangeudav.livejournal.com/120449.html&quot;&gt;here&lt;/a&gt;, &lt;a href=&quot;http://photofile.ru/users/s1d1/2853730/&quot;&gt;here&lt;/a&gt;, and &lt;a href=&quot;http://inline.konstantinkrylov.com/gallery/v/nk/20070706/&quot;&gt;here&lt;/a&gt;.
&lt;p&gt;
Russians are crazy! And it&apos;s extremely interesting to study the reactions of various cultures to unicycles. In Moscow everybody wanted to try it themselves :-)</description>
  <comments>http://lukego.livejournal.com/8023.html</comments>
  <category>wrt unicycle</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/7806.html</guid>
  <pubDate>Sun, 22 Jul 2007 08:50:22 GMT</pubDate>
  <title>Forth Machine</title>
  <link>http://lukego.livejournal.com/7806.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0000wczt/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0000wczt/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
This XO is one hell of a machine :-)
&lt;p&gt;
If you press the appropriate key during boot you drop into a &lt;a href=&quot;http://www.firmworks.com/QuickRef.html&quot;&gt;Forth shell&lt;/a&gt; within the Open Firmware boot loader. The Forth system is &lt;a href=&quot;http://wiki.laptop.org/go/Forth_Lessons&quot;&gt;easy to learn&lt;/a&gt; enough to poke around with.
&lt;p&gt;
The coolest demo is &lt;code&gt;test-all&lt;/code&gt; to put the hardware through its paces. Here you see the video camera in action, talk into the microphone and hear it playback, scan all wireless access points in the area, and more.. all done with a tiny-winy bit of Forth code and no operating system!
&lt;p&gt;
How can it be so? Well you can find out with introspection: &lt;code&gt;see test-all&lt;/code&gt; beautifully decompiles and pretty-prints the function. You can chase your way around the whole machine finding what hardware is inside and oogling its self-test routines to see how to tickle it. If you crash the machine you can be rebooted to the prompt in about five seconds and ready for more trouble.
&lt;p&gt;
This reminds me vividly of the good old days from 5-years-old when my C=64 would boot directly to a BASIC prompt (L..O..A..D...) up through hacking the Amiga in ASMONE as a teenager. That was really all I needed to be productive in life and the XO seems &lt;i&gt;way&lt;/i&gt; cooler, even before booting the operating system :-)
&lt;p&gt;
What lucky kids :-)</description>
  <comments>http://lukego.livejournal.com/7806.html</comments>
  <category>olpc forth</category>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/7575.html</guid>
  <pubDate>Sat, 21 Jul 2007 16:59:17 GMT</pubDate>
  <title>First impressions of the OLPC XO</title>
  <link>http://lukego.livejournal.com/7575.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0000t55p/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0000t55p/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
The friendly people at &lt;a href=&quot;http://laptop.org/&quot;&gt;One Laptop Per Child&lt;/a&gt; sent me a &lt;a href=&quot;http://wiki.laptop.org/go/Developers_Program&quot;&gt;little green
laptop&lt;/a&gt; to call my own last week. I&apos;m having quite a bit of fun with it :-)
&lt;p&gt;
Random observations:
&lt;ul&gt;
&lt;li&gt;The screen really does work well in direct sunlight! Today I passed
some time pleasantly reading from the screen in the park.&lt;/li&gt;

&lt;li&gt;The small keyboard and touchpad will require some adjustment.&lt;/li&gt;

&lt;li&gt;The speakers, microphone, and video camera all work fine. That&apos;s the
best hardware support of any Linux machine I&apos;ve ever had :-)&lt;/li&gt;

&lt;li&gt;Squeak runs really nicely. There&apos;s also Turtle Art, a graphical
Logo/&lt;a href=&quot;http://scratch.mit.edu/&quot;&gt;Scratch&lt;/a&gt; dialect written in
Python by &lt;a href=&quot;http://llk.media.mit.edu/people.php?id=bss&quot;&gt;Brian
Silverman&lt;/a&gt; of MIT&apos;s Logo group. I&apos;m impressed that he&apos;s rolling up his sleeves and hacking
Python to bring his ideas to OLPC.&lt;/li&gt;

&lt;li&gt;Forth in the &lt;a href=&quot;http://lwn.net/Articles/209301/&quot;&gt;boot loader&lt;/a&gt; is cool. I was easily able to type a forth command to bypass the &quot;do I want to install this software image from USB?&quot; logic that refused to do what I expected.&lt;/li&gt;
&lt;/ul&gt;

I&apos;m studying &lt;a href=&quot;http://www.amazon.com/Turtle-Geometry-Mathematics-Artificial-Intelligence/dp/0262510375&quot;&gt;Turtle Geometry&lt;/a&gt; on my XO. I find Logo programming more
comfortable in Etoys than in Turtle Art so far.
&lt;p&gt;
The next step is to setup a Fedora Core 7 build machine. I&apos;m really
looking forward to having a stable base for activity hacking because
&lt;a href=&quot;http://wiki.laptop.org/go/Sugar_with_sugar-jhbuild&quot;&gt;sugar-jhbuild&lt;/a&gt;
is &lt;i&gt;extremely&lt;/i&gt; little fun.</description>
  <comments>http://lukego.livejournal.com/7575.html</comments>
  <category>olpc squeak</category>
  <lj:mood>happy as a pig in shit</lj:mood>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/7309.html</guid>
  <pubDate>Fri, 20 Jul 2007 13:58:39 GMT</pubDate>
  <title>Freedom</title>
  <link>http://lukego.livejournal.com/7309.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0000s1q3/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0000s1q3/s320x240&quot; width=&quot;160&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;&lt;br /&gt;That&apos;s it!&lt;br /&gt;&lt;p&gt;&lt;br /&gt;I&apos;m as free as a bird: no home, no job, just a lot of interesting computers, projects, and plane tickets. The future looks big and exciting :-)</description>
  <lj:security>public</lj:security>
</item>
<item>
  <guid isPermaLink='true'>http://lukego.livejournal.com/7029.html</guid>
  <pubDate>Mon, 18 Jun 2007 15:41:36 GMT</pubDate>
  <title>Pisa</title>
  <link>http://lukego.livejournal.com/7029.html</link>
  <description>&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0000qwa6/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0000qwa6/s320x240&quot; width=&quot;120&quot; height=&quot;120&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;
I just had a very pleasant weekend in Pisa. I succeeded in briefly meeting Alan Kay as he received an honor from the University
of Pisa and in sneaking a first peek at &quot;the little green laptop&quot;.
Then I was really happy to be invited to
&lt;a href=&quot;http://citeseer.ist.psu.edu/attardi95embeddable.html&quot;&gt;Guiseppe Attardi&lt;/a&gt;&apos;s very classy home for a delicious dinner in honour
of &lt;a href=&quot;http://www.pisaonline.it/PISA/eventi/e-luminara.htm&quot;&gt;St. Ranieri&lt;/a&gt; and the distinguished visitor!
&lt;p&gt;
Europe is truly a wonderful place to live, and the aeroplane is surely
the most practical tool in the world of computer science. :-)
&lt;p&gt;
The net result of this trip is that I&apos;m excited about &lt;a href=&quot;http://wiki.laptop.org/go/Etoys&quot;&gt;Etoys&lt;/a&gt;. Here&apos;s a
picture of my first &quot;junior scientist&quot; project :-) which simulates
stumbling out of a forest by walking randomly north/south and
east/west. I was curious to see how long this would take and what it would look like after reading
an interesting prediction in Hamming&apos;s &lt;a href=&quot;http://www.amazon.com/Art-Probability-R-W-Hamming/dp/0201406861&quot;&gt;probability book&lt;/a&gt;.
&lt;a href=&quot;http://pics.livejournal.com/lukego/pic/0000rc0c/&quot;&gt;&lt;img src=&quot;http://pics.livejournal.com/lukego/pic/0000rc0c/s320x240&quot; width=&quot;160&quot; height=&quot;100&quot; border=&quot;0&quot; align=&quot;right&quot; /&gt;&lt;/a&gt;&lt;p&gt;
I&apos;d like to have a neater way to express &quot;random between X and Y&quot; and
to have square roots, but I haven&apos;t looked closely at how to extend
the Etoys vocabulary yet.
&lt;p&gt;
I had decided the project was too trivial to post until I saw Peter
Norvig &lt;a href=&quot;http://norvig.com/experiment-design.html&quot;&gt;suggest&lt;/a&gt; that other people also need to train their intuitions about what randomness looks like!</description>
  <comments>http://lukego.livejournal.com/7029.html</comments>
  <category>olpc</category>
  <category>general</category>
  <category>hacking</category>
  <lj:security>public</lj:security>
</item>
</channel>
</rss>
