Wednesday, December 23, 2009

Emulate rightclick on OpenTTD

In the original version of OTTD the right click is emulated by holding the ctrl key. Rightclick emulation can be enabled in the openttd.cfg file, by setting under the [misc] section,

rightclick_emulate = true
But the ctrl key is already mapped to othe things in the game (shared orderes for example). A very small modification to the code changes the key to shift. In /src/video/sdl_v.cpp change (line 387):


if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) {
to
if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_SHIFT) {

or apply this patch file, by issuing,
patch -p1 -i right_click_emulate.diff
Then follow this post, or this one to compile. I've compiled ottd both with my shift patch and the original version.

Saturday, October 24, 2009

deb for OpenTTD

I'd like to create a proper package for OpenTTD. So I've followed the ottd compilation wiki. At the end of the wiki page it is explained how to create a deb package.
I first had to install the following packages:

apt-get install build-essential fakeroot libfontconfig1-dev
then, from the root directory of the source code,
mv os/debian .
and
dpkg-buildpackage -rfakeroot -uc -us
to build the package (ge75bb64).

I had some problems with openttd sound stuttering, to solve it I found that (thanks Rubidium in the #openttd channel) running with -s sdl:hz=22000 solves the problem. This can be also set to be the default in the openttd.cfg file, just set:
sounddriver = "sdl:hz=22000"

Sunday, September 27, 2009

Emulating and Compiling for zubuntu

Emulating Zaurus
Since compiling natively on the Zaurus was slow, I decide looking for other options. Cross-compilation seems to complicated for me to setup (though probably it's not) - for that Poky seemed the easiest way. A compromise I found was to setup an arm system under Qemu. I found some of the solution on this post in the OmegaMoon blog.
First I needed the arm flavour of Qemu, Next, I used the Qemu Manager to setup the virtual machine (it can also create virtual disks).
Qemu needs a kernel to boot, I use this one.
Then I created two empty image disks (one for the operating system and one for swap). The tricky part is to setup the virtual disks. I did it on a linux machine (I use VMware to run a linux machine).
Format the disks,

mke2fs -F -m 0 -b 1024 virtual.disk

then mount it 

sudo mount -t ext2 -o loop virtual.disk mount_point
then extract the Zubuntu rootfs to this virtual disk (this is exactly the same process as setting up zubuntu for the Zaurus). I guess this can be done using one of the prepared virtual machines.
Now I put everything in the Qemu folder and use the following script to start the virutial machine,
qemu-system-arm -kernel zImage-versatile-2.6.24-rc7.armv5tel -append "console=ttyS0,115200n8 console=tty1 noinitrd fbcon=rotate:1 dyntick=enable debug psplash=false root=/dev/sda ip=bootp" -boot c -m 256 -hda virtual.disk -hdb swap.disk -net nic,vlan=0 -net user,vlan=0 -usbdevice tablet -localtime -M versatilepb
Alternatively, I use this virtual machine in the Qemu Manager.
The last is to create the swap partition, after Qemu boot into zubuntu,
mkswap /dev/sdb
and  enable it,
swapon /dev/sdb
For zubuntu to automatically start swap when booting, add to /etc/fstab,
/dev/sdb/        /none       swap       sw       0   0

Now this virtual machine can be used to compile "natively" for the zaurus. From the few tests I made compiling here is about twice as fast as compiling on the zaurus.


OpenTTD

OpenTTD is similar to simutrans, it is less sofisticated, but the performance here is much better than in simutrans (see this post).


OpenTTD with CargDist running on my Zaurus

To compile latest OpenTTD including the CargoDist patch (wikipage, forum thread), I did the following,
First install the prerequisites,
apt-get install git-core
For CargoDest libboost-graph-dev was also required (not sure if it is required by Cargodist)
then, to get the source code,
git clone http://fickzoo.com/fonsinchen/openttd.git
git checkout origin/cargodist

configure,
./configure --enable-debug=0 --prefix-dir=/usr

That (supposedly) disables debug, the prefix dir will set the installation dir to match that of the debian package (binaries under /usr/games and data under /usr/share/games/openttd).
Now compile
make
And with a little luck OpenTTD is compiled. To configure it follow the instruction in OpenTTD's wikipage.

Tuesday, September 22, 2009

Compiling simutrans

Installing prerequisites,

apt-get install zlib1g-dev libpng12-dev libSDL1.2-dev libsdl-mixer1.2-dev subversion make g++
Get the source code,
svn co svn://tron.homeunix.org/simutrans/simutrans/trunk
Username is anon with empty password.
Setup,
Add #include "stdlib.h" to dataobj/koord.h.
Copy config.template to config.default.
Add at the end of config.default,
FLAGS += -DBIG_ENDIAN
FLAGS += -DUSE_C
and set,
BACKEND = sdl
COLOUR_DEPTH = 16
OSTYPE = linux
DEBUG = 0
OPTIMISE = 1
PROFILE=0
SDL_CONFIG = sdl-config
now,
make
On my zaurus the compilation takes about 3 hours. To run simutrans I first install the 102 version from the sid repositories and its dependencies (simutrans-pak64, simutrans-data and simutrans), then I copied the compiled binary (called sim) to /usr/share/games/simutrans and ran it from there, otherwise simutrans doesn't find the data files.
The downside is that apparently the Zaurus is too weak to run simutrans. I got 7fps at most and usually 4fps. I also tried to change to pakHAJO, but it didn't improve the situation much. I also tried pak32, which showed a little better performance.

Friday, September 4, 2009

Setup GPS on Zubuntu

First, to setup the bluetooth connection I need to install bluez,

apt-get install bluez
Next, gpsd,
apt-get install gpsd
And last tangoGPS, to present a moving map using the OpenStreetMap project (or other sources...)
apt-get install tangogps

Next setup the bluetooth connection. I'll be using rfcomm, the configuration file can be found under /etc/bluetooth/rfcomm.conf. I'm using this one. To find the bluetooth address of the device I use (after I turn on the gps, obviously),
hcitool scan
The hcid.conf is missing in Zubuntu for some reason, so I create it (under /etc/bluetooth/hcid.conf). I'm using this hcid.conf.
The pin code is saved under /etc/bluetooth/pin, and can be generated by
echo "0000" > /etc/bluetooth/pin
or any other pin code.
I also need to create the /bin/bluepincat.sh script for hcid, which contains,
#!/bin/sh
echo -n "PIN:"
cat /etc/bluetooth/pin
To bind rfcomm0 with the gps I do
rfcomm bind /dev/rfcomm0

The configuration for gpsd is under /etc/default/gpsd, there START_DAEMON should be set to "true" and DEVICES should point to "/dev/rfcomm0". To start the gpsd daemon,
/etc/init.d/gpsd start

Now I can start using tangoGPS and connect to my bluetooth GPS device.

Saturday, August 15, 2009

VLC & Mplayer

VLC
vlc is in the zubuntu repository, on the desktop it is very reliable player. It is part of the zubuntu repository and can be installed easily. Running it might be a little more complicated, because vlc does not allowed to be run by the root user (which is the default user in zubuntu). After
searching in google a little, I found out that either vlc has to be recompiled with the "--enable-run-as-root" switch or using the vlc-wrapper. In the later case, I used the following command,

SUDO_UID=4212 vlc-wrapper as root
The problem with this method is that vlc does not have permissions to change the configuration file (~/.config/vlc/vlcrc).
Searching a little more I found this post which describe how the vlc binary (/usr/bin/vlc) can be modified to be able to run as root. This method is (not so) elegant, but it beats recompiling. To summarize, using a hex-editor (I used hexedit from the zubuntu repositories), line 630, change geteuid to getppid.

The video playback though, is very disappointing, even when using vlc-sdl-plugin (also from the repositories)...

MPlayer
For some reason mplayer is not included the jaunty arm repositry. But it can be found in the Debian one. The easiest way I found it could be installed was simply to add the Sid repository to /etc/apt/sources.list. To install mplayer, add at the end of the file,
deb http://ftp.de.debian.org/debian sid main
then update the package cache by,
apt-get update
then install mplayer,
apt-get install mplayer
and that's that. It may be advisable to remove the line from sources.list. mplayer shows better performance than vlc, but still not enough to watch movies (to my taste).

Wednesday, August 12, 2009

Chess & Comics

QComicBook
Browsing the internet I stumbled upon this comicbook reader (which is in the repository). Supposedly it can read cbr files (rar compressed files), but I didn't manage to use it like that. But It's ok I can unrar the comics to a folder and read it there.
After install there wasn't a launcher in the icewm menu, so I have to start it from the terminal (until I'll manage to manually putting a launcher there...)

Crafty, XBoard
I got armel version of crafty from the maemo repository. xboard is in the default repository.
xboard can be started by issuing the following command:

xboard -font -*-fixed-bold-r-normal--*-*-*-*-*-*-*-* -clockFont -*-fixed-bold-r-normal--*-*-*-*-*-*-*-* -coordFont -*-fixed-bold-r-normal--*-*-*-*-*-*-*-* -fcp crafty
The default fonts have to be overridden because xboard uses by default helvetica font which is not installed (I couldn't find it anyway...).
The fonts and engine can be set as default in the ~/.Xdefaults file, at the end of the file add,
xboard*font:*-*-fixed-medium-r-normal--*-130-*-*-*-*-iso8859-1
xboard*clockFont:*-*-fixed-medium-r-normal--*-130-*-*-*-*-iso8859-1
xboard*coordFont:*-*-fixed-medium-r-normal--*-130-*-*-*-*-iso8859-1
xboard*firstChessProgram:crafty
then xboard can be started simply by,
xboard
Additional settings can be found in the xboard manpage.

Saturday, August 8, 2009

Power button & Wifi scripts

Power Button
There is a little bug, where when pressing the "power" button, the window list opens. I guess it can also be fixed through the IceWM settings, but I chose to fix it by mapping the power button to Control_L using xmodmap. In the ~/.xinintrc file, I added after the xbattbar command the following line:

xmodmap -e "keycode 8 = Control_L"

Wifi Scripts
I added an osd message when turning on and of the wifi via the "Mail" button. The script /usb/bin/pci is responsible for turning on the wifi and /usb/bin/pce for turning it off. So I added:
osd.sh "Wifi On" &
to /usb/bin/pci and
osd.sh "Wifi Off" &
to /usb/bin/pce

By default, after waking up from standby, the zaurus tries to turn on the wifi. I prefer the wifi to be be off by default. So i change, in /etc/apm/scripts.d/wifi
pci
to:
pce

Thursday, August 6, 2009

Conky

I've found Conky, first for my desktop, and then I installed it on the Z. This utility can present a lot of information to the desktop, such as CPU usage, disk usage, battery levels, wifi signal strength etc. It uses a config file in the home directory (~/.conkyrc). Here's my conkyrc file.

I also wrote this script (/bin/apmStat.sh) to report the battery status.

Tuesday, August 4, 2009

Some more tweaks to Zubuntu

/bin/bl
For some reason in the /bin/bl script the line setting the highest brightness is marked out and the MAX_BRIGHTNESS is set to 15. So I unmarked the following line:

#MAX_BRIGHTNESS=`cat /sys/class/backlight/$DRIVER/max_brightness`
Next, to restore the original brightness value after suspend/lid closed (according the original script the brightness is set to the maximum value). I added after
elif [ "$1" = "on" ]; then
the following lines:
if [ -a /tmp/BrightnessBeforeOff ]; then
echo `cat /tmp/BrightnessBeforeOff` >> $BRIGHTNESS_FILE
rm /tmp/BrightnessBeforeOff
else
echo $MAX_BRIGHTNESS >> $BRIGHTNESS_FILE
fi
which reads the brightness level from /tmp/BrightnessBeforeOff. After
elif [ "$1" = "off" ]; then
I added the following:
echo $BRIGHTNESS > /tmp/BrightnessBeforeOff
which saves the brightenss level to /tmp/BrightnessBeforeOff.

Last, I added a third case, "low", to the if, before the else statement, I added,
elif [ "$1" = "low" ]; then
echo 5 >> $BRIGHTNESS_FILE
which sets a low level brightness.
Then I use Xbindkeys to to bind Fn-5,6 and 7 to /bin/bl on, low and off respectively.
The whole thing can be downloaded from here.

OSD
Next, I installed osd_cat for some nice on-screen-display:
apt-get install xosd-bin
and I created the following script /bin/osd.sh
#!/bin/bash
OSDFONT="-*-*-medium-r-normal-*-16-*-*-*-*-*-*-*"
DELAY=3

killall osd_cat -q
if [ "$2" = "" ]; then
echo "$1" | osd_cat -d $DELAY -P 5 -p bottom -c yellow -O 8 -A right --font=$OSDFONT -o -110&
else
osd_cat -d $DELAY -T "$1" -b percentage -P $2 -p middle -c $3 -O 8 --font=$OSDFONT
fi
which can be used to display messages or percentage bar (for the brightness or battery level) and can be downloaded from here.

/bin/dispaly-brightness.sh
here too the MAX_BRIGHTNESS is marked out, so I unmarked it. I also added calls to osd.sh (see above) to display the brightness level. It can be found here.
I linked Fn-3 and 4 to /bin/display-brightness.sh down and up using xbindkeys.

/etc/zaurusd/scripts/zaurus-hinge
IIRC the values in the zaurus-hinge script are switched, which breaks the automatic rotation. The values should be for landscape:
STATE = 0
and for portrait:
STATE = 2

I also added a call to osd.sh here too, to report the rotation. In the landscape section, After bl on I added:
osd.sh "Landscape mode"&
and in the portrait section, after /usr/bin/xrandr -o right I added:
osd.sh "Landscape mode"&
/bin/batStat.sh
I created /bin/batStat.sh to report the battery status to the screen.
#!/bin/bash

TIMEOUT=3
HIGH=95
MED=50


bat=`apm`
stat=${bat:0:3}
bat=${bat:(-4)}
bat=${bat:0:`expr length "$bat"`-1}
bat=$((bat))


color=green
if [ "$stat" = "Off" ]; then
stat="Off-line"
if [ $bat -lt "$HIGH" ]; then
color=yellow
fi
if [ $bat -lt "$MED" ]; then
color=red
fi
else
stat="On-line"
if [ $bat -lt "$HIGH" ]; then
color=yellow
fi
if [ $bat -lt "$MED" ]; then
color=red
fi
fi
killall osd_cat -q
osd.sh "Battery: $stat ($bat%)" $bat $color
This script, when runs prints the battery status to the screen. And changes the color according to the charge level of the battery. It also indicate if he battery is charging. The script can be downloaded from here.

I linked the script to Fn-8 (saving 9 and 0 for the volume control).

HDD led
Last, a nice tweak is to connect the green (mail) led to the sd access. This can be done by,
echo mmc0 > /sys/class/leds/corgi\:green\:mail/trigger
This can be permanently changed by adding the line to ~/.xinitrc. to see the avalabe triggers and the active one type,
cat /sys/class/leds/corgi\:green\:mail/trigger


Saturday, July 11, 2009

Ångstrom touchscreen

Okay, I managed to get the touchscreen to work, with the kind help of bluelighting from the #opie irc channel, To fix the problem I had to change /dev/input/event0 to /dev/input/event1 in /etc/profile.d/tslib.sh and in /etc/zaurusd/mach-config-vars

Tuesday, June 30, 2009

A new revelation (Zubuntu RC1)

After a hint speculatrix gave me, I followed this post to install Zubuntu RC1 (8.04) on my Zaurus. I first reflashed the zaurus with a rom including kexec.
This little nifty app enables the zaurus to boot from the SD/CF card.
I got me a 4GB SDHC card. On a desktop (actually a virtual machine) I repartitioned it using gparted (one ext2 and one swap partition). and extracted the rootfs to the SD,

# tar zxvf zubuntu-desktop-rc1.tar.gz -C /media/disk
and the kernel modules for my boxer,
# tar zxvf c7x0-root-addition.tar.gz -C /media/disk
and voila, I have ubuntu on my zaurus. I needed to fix the touchscreen by changing in ~/.profile:
export TSLIB_TSDEVICE=/dev/input/event2
to
export TSLIB_TSDEVICE=/dev/input/event1
alternatively the following command will change it:
sed -i "s#export TSLIB_TSDEVICE=/dev/input/event2#export TSLIB_TSDEVICE=/dev/input/event1#" root/.profile
And also removed from ~/.xinitrc
xrandr -o right
or
sed -i "s/xrandr -o right/#xrandr -o right/" root/.xinitrc
to keep the screen in portrait mode when starting.

To enable usb networking , i edited /etc/network/interfaces as I did before. I also had to add to /etc/resolve.conf:
nameserver 192.168.1.1
to have access to the internet.

The only major problem I have now is that the CF slot is dead so I cant use the bluetooth or wifi cards.

eventually I found this link (in german) after
# modprobe pxa2xx_cs
the port came back to life. I added g_ether (USB networking), pxa2xx_cs (CF slot) and snd-soc-corgi (Sound card) to /etc/modules.
this can be done by,
grep snd-soc-corgi etc/modules || echo "snd-soc-corgi">>etc/modules
grep pxa2xx_cs etc/modules || echo "pxa2xx_cs">>etc/modules
grep g_ether etc/modules || echo "g_ether">>etc/modules


Wednesday, April 29, 2009

Ångström is dead long live (dead)OpenZaurus

After a long time my boxer slept in the corner, I decided to wake it up... looking around I've found the Ångström online image builder. The builder creates compressed rootfs - not knowing how to continue from here, and being disappointed from the 2007 and 2008 releases I decided to revert to OpenZaurus.
Alas, I found out that the OpenZaurus.org domain was dead... after searching around I've found the hentges mirror. I've downloaded the the GPE flavour and I was up and running it in no time. Actually, I'm surprised by the smoothness of this version with respect to the Ångström one.