Luke Gorrie (lukego) wrote,
Luke Gorrie
lukego

boing boing boing

Today'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:
25 bouncing
after you've loaded this code of bounce.fth:
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' pos' )
   over +         ( speed  pos' )
   swap 1- swap   ( speed' pos' )
;
: 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> if  dup bounce  2 / bouncing  then
;
Tags: forth, olpc
Subscribe

  • Code snippet of the day

    A Forth assembler word that happened to cross my path today: code expand-rect ( src dst w h --- ) dx pop \ Height of source image in pixels 4 [sp]…

  • Magic numbers

    Today I wrote some device driver code of precisely the sort I'm always complaining about -- containing seemingly opaque magic numbers that have no…

  • Brickproofing

    I bricked my OLPC XO the other week by flashing bad stuff onto the SPI FLASH. That's the 1MB flash chip that the XO boots from -- it's supposed…

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments