View Single Post
Old 03-20-2012, 11:37 PM   #31
kaminkatze
Member
kaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with otherskaminkatze plays well with others
 
Posts: 17
Karma: 2600
Join Date: Mar 2012
Device: Kindle 3
Quote:
Originally Posted by geekmaster View Post
The easiest is to ASSUME that the kindle has 300 byte-wide pixels per line, with values "dd if=$DZ of=$DF ..." or "echo -e '\xff'|dd of=$DF ...".
Something like this:

Spoiler:

Code:
#!/bin/sh

#===========================
# cleanup - delete tmp files
#---------------------------
trap 'cleanup ; exit' SIGINT SIGTERM
cleanup() {
  rm $DL $BF
}

#===========================
# initvar - init global vars
#---------------------------
initvar() {
  XF=140 XL=160 YF=190 YL=210
  DN=/dev/null DF=/dev/fb0 BF=$(mktemp "/tmp/tempXXXXXX") LL=300
  D='0' L='F' DD=/dev/zero DL=$(mktemp "/tmp/tempXXXXXX")
  echo -ne "\xFF" >$DL
  eips -c
  for x in $(seq $((XF-2)) $((XL+2))); do
    setpix $x $((YF-2)); setpix $x $((YL+2))
  done
  for y in $(seq $((YF-2)) $((YL+2))); do
    setpix $((XF-2)) $y; setpix $((XL+2)) $y
  done
}

#===========================
# usage: load x y name
#---------------------------
load() {
  local x=$((XF+$1)) y=$((YF+$2)) name=$3
  case "$name" in
  glider)
    setpix $((x+1)) $y
    setpix $((x+2)) $((y+1))
    setpix $x $((y+2))
    setpix $((x+1)) $((y+2))
    setpix $((x+2)) $((y+2)) ;;
  esac; eips ''
}

#===================================
# usage: setpix x y
#-----------------------------------
setpix() {
  local x=$1 y=$(($2*2))
  dd if=$DL of=$DF bs=1 count=1 seek=$((y*LL+x)) 2>$DN
  dd if=$DL of=$DF bs=1 count=1 seek=$(((y+1)*LL+x)) 2>$DN
}

#===================================
# update - update field
#-----------------------------------
update() {
  local b m t c v
  cat $DF > $BF
  for x in $(seq $XF $XL); do
  for y in $((YF-1)) $YF; do y=$((y*2))
    m=$b b=$(hexdump -v -s $((y*LL+x-1)) -n 3 -e '/1 "%X"' $BF)
  done
  for y in $(seq $YF $YL); do y=$((y*2))
    t=$m m=$b b=$(hexdump -v -s $(((y+2)*LL+x-1)) -n 3 -e '/1 "%X"' $BF)
    c=$(expr length "$b$m$t")
    v=$(hexdump -s $((y*LL+x)) -n 1 -e '"%X"' $BF)
    if [[ $v == $D ]]; then
      [[ $c -eq 12 ]] && v=$DL || v=$DD
    else
      [[ $c -lt 12 -o $c -gt 13 ]] && v=$DD || v=$DL
    fi
    dd if=$v of=$DF bs=1 count=1 seek=$((y*LL+x)) 2>$DN
    dd if=$v of=$DF bs=1 count=1 seek=$(((y+1)*LL+x)) 2>$DN
  done; done; eips ''
}

#===================================
# loop - update loop
# usage: loop steps
#-----------------------------------
loop() {
  local c=$1 p=0 t0=$(date +%s) t1
  eips "Generation: 0"
  while [[ $p -lt $c ]]; do
    update; p=$((p+1))
    t1=$(date +%s)
    eips "Generation: $p ($((t1-t0))s)"
    t0=$t1
  done
}

initvar
load 2 2 glider
loop 100
cleanup


Quote:
Originally Posted by geekmaster View Post
Another option I thought of was to use a 600-byte wide /tmp/buffer (to hold a scan line for both touch/k4 8-bit pixels or the k3/dx 4-bit pixels) and then for the k3/dx draw 4 different pixel pair bytes to the framebuffer based on the values (\x00 \xf0 \x0f \xff).
Any hints on how to condense the line? I tried some things with awk but had problems with \x00 in the input. (Never used awk before so this could be entirely my fault.)
kaminkatze is offline   Reply With Quote