Index:
Fixing jjffe source build
Emerging virtualbox-ose
Technika MP-709
Pleomax PWC-4000 Webcam on Linux
vnstat
Bash Cheat Sheet
perl raytracer
Hidden files in the Gtk2 File Selector
Recovering Gentoo from a broken python
A perl print failure case
Dell E551 Monitor 1024x768 Scan Rates
Adding an NE2000 card on an ISA bus
Adding sbl-xbl protection to postfix

[Back to the Front Page]

Fixing jjffe source build on Linux

JJFFE is a program that lets you play the classic space sim "Frontier:First Encounters" on modern machines. The latest source available is 2.8a7. Make a working directory called "jjffe", change into that directory, and unzip the download. However building it throws lots of errors:
$ make -f ffelnxsdl.mak 
gcc -I. -Wall -D__FFELNXSDL__ -I/usr/include/SDL -D_GNU_SOURCE=1
-D_REENTRANT -Wl,-Map,map.log -o linux/lnxconv linux/lnxconv.c
linux/lnxconv ffe.asm linux/ffelnx.asm
Reading file ffe.asm...
Writing file linux/ffelnx.asm...
numfuncs = 84, numcheck = 17733, numreplace = 503
nasm -f elf -i. -o linux/ffelnx.o linux/ffelnx.asm
linux/ffelnx.asm:36497: error: invalid operand size specification
linux/ffelnx.asm:36497: error: expression syntax error
linux/ffelnx.asm:36502: error: invalid operand size specification
linux/ffelnx.asm:36502: error: expression syntax error
linux/ffelnx.asm:36507: error: invalid operand size specification
linux/ffelnx.asm:36507: error: expression syntax error
linux/ffelnx.asm:36894: error: invalid operand size specification
linux/ffelnx.asm:36894: error: expression syntax error
linux/ffelnx.asm:36899: error: invalid operand size specification
linux/ffelnx.asm:36899: error: expression syntax error
linux/ffelnx.asm:36904: error: invalid operand size specification
linux/ffelnx.asm:36904: error: expression syntax error
( ... SNIP ... There are lots more of these )
linux/ffelnx.asm:131307: error: invalid operand size specification
linux/ffelnx.asm:131307: error: expression syntax error
linux/ffelnx.asm:131312: error: invalid operand size specification
linux/ffelnx.asm:131312: error: expression syntax error
make: *** [linux/ffelnx.o] Error 1
Each line corresponds to a "call abs" line in ffelnx.asm. It seems as though at some point "abs" became a reserved word in nasm. There is documentation for this here: http://www.nasm.us/doc/nasmdoc3.html#section-3.3". To fix this, I wrote a small wrapper that put abs into a call called ffeabs. I then did a search/replace on 'abs' to 'ffeabs' in ffelnx.asm.
You can download the files here: Copy both of these into the work directory, and apply the patch with "patch -p0 <ffelnxsdl.mak.patch". You should now be able to make a jjffe executable. You will need to follow the rest of the instructions on the JJFFE webpage to explain how to set up the rest of the files you need to play this Elite sequel.

Added 20091230

Emerging virtualbox-ose

Recently when trying to emerge virtualbox, I got this message:
$ emerge -uvpDN virtualbox-ose

These are the packages that would be merged, in order:

Calculating dependencies... done!

!!! All ebuilds that could satisfy "~app-emulation/virtualbox-ose-additions-3.1.0" have been masked.
!!! One of the following masked packages is required to complete your request:
- app-emulation/virtualbox-ose-additions-3.1.0 (masked by: PUEL license(s))
A copy of the 'PUEL' license is located at '/usr/portage/licenses/PUEL'.


(dependency required by "app-emulation/virtualbox-ose-3.1.0" [ebuild])
(dependency required by "virtualbox-ose" [argument])

For more information, see the MASKED PACKAGES section in the emerge
man page or refer to the Gentoo Handbook.
To fix this you need to add the PUEL licence to the portage.licenses file:
echo "app-emulation/virtualbox-ose-additions PUEL" >> /etc/portage/package.licenses
Now it will emerge. Except it won't due to this bug.

Added 20091230

Technika MP-709

Adding to my collection of bargain bin hardware is this video mp3 player from Tescos. Here's what you need to get files on to it, and to convert video into a format it can play.

Connecting

This device doesn't appear as a USB Flash Drive. Instead its a silly MTP device. There is a project to let you use these on linux: libmtp. However the current version (1.0.1) doesn't have built in support for the MP-709. It is fairly easy to add though. Just download the source and add the line:
 { "Technika", 0x13d1, "MP-709", 0x7017, DEVICE_FLAG_UNLOAD_DRIVER },

to the src/music-players.h file, then build it.

Converting Video

The player users the amv format. To convert you need a patched copy of ffmpeg from google. To get the source you will need to download it from subversion:

svn checkout http://amv-codec-tools.googlecode.com/svn/trunk/ amv-codec-tools-read-only
cd amv-codec-tools-read-only/AMVMuxer/ffmpeg
./configure --enable-libfaac --enable-liba52 --enable-libmp3lame --enable-gpl --enable-libfaad --enable-shared
make -j3

The player has a resolution of 120x160, in portrait. As most films are in landscape its good to rotate the film before converting to amv:

mencoder -vf rotate=1 -ovc lavc -oac pcm source_film.mov -o rotated_film.avi
Finally use the ffmpeg you built to convert the film, and upload to your MP-709:
LD_LIBRARY_PATH="./libavformat:./libavcodec:./libavutil" ./ffmpeg -i rotated_film.avi -f amv -s 120x160 -r 16 -ac 1 -ar 22050 -qmin 3 -qmax 3  film.amv
mtp-sendfile film.amv film.amv

Pleomax PWC-4000 Webcam on Linux

I bought a Pleomax PWC-4000 webcam cheap from Sainsbury's, which needed a bit of tinkering to get going. The usb line for it is: Bus 002 Device 003: ID 093a:262a Pixart Imaging, Inc.. This is supported by the GSPCA-7311 driver in recent linux kernels. However, despite being a v4l2 driver, gstreamer-properties would complain that it couldn't find the device due to Error running pipeline 'Video for Linux 2 (v4l2)': Could not negotiate format. This was with gst-plugins-v4l2 emerged. It seems that the webcam outputs in a strange format, for which libv4l provides a converter. Emerging libv4l didn't immediately fix things though - gst-plugins-v4l2 needed re-emerging afterwards to pick it up. Then finally I can take a picture. More here

Oh, rebuilding mplayer doesn't work so you have to fudge it with LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0

vnstat

For some time I've had vnstat email me weekly reports of my network usage. Its been pointed out that it can also draw pretty graphs for the same, which I update hourly. I think this is rather cool.

Bash Cheat Sheet

There are a lot of useful shortcuts on the bash command line. This site is a thorough overview of some common and more obscure ones. What I really need to learn them though is a cheat sheet to stick up next to my monitor - so I made one.

Added 20080826

perl raytracer

Having seen a rather nice looking raytracer written in C#, I thought I'd look at the code to learn some raytracing, and play around with getting it working in perl. As it turns out perl is a comfortable language for this. Sprinkle with a touch of SDL, and you get a perfect reproduction of the original render.

Code here

Added 20080826

Hidden files in the Gtk2 File Selector

For whatever reason, Gentoo or Gnome or some other djamfool have suddenly decided to take it upon themselves to show hidden files in the Gtk2 file browser. This means you get tonnes of .dot directories cluttering up the view. The fix is to change the ~/.config/gtk-2.0/gtkfilechooser file from:

<gtkfilechooser>
    <location mode="filename-entry"/>
    <show_hidden value="true"/>
    <expand_folders value="true"/>
</gtkfilechooser>

To:

<gtkfilechooser>
    <location mode="filename-entry"/>
    <show_hidden value="false"/>
    <expand_folders value="true"/>
</gtkfilechooser>

Update: Now you can right-click over the list of files, and tick/untick the "Show Hidden Files" box.

Added 20070514

Recovering Gentoo from a broken python

This may be a life saver. I noticed that I have two version of python installed on my Gentoo box. So I thought I'd try uninstalling the old one. This actually uninstalls the latest version libraries leaving me with a warning such as "ImportError: no such module time". This is bad as you cannot use emerge at all not even to emerge python to fix things. To fix, as root:
cd /root
wget http://distfiles.gentoo.org/distfiles/Python-2.4.3.tar.bz2
tar jxvf Python-2.4.3.tar.bz2
cd Python-2.4.3
./configure
make
./python emerge python
cd /root
rm -rf Python-2.4.3*
You are now fixed.

Added: 20060912

A perl print failure case

print can, of course, fail. Most perl programs don't check this, however for obscure and paranoid reasons I wanted to have a reproducible test case for a normal failure. Disk full is one such event, but I didn't want to fill up my laptop to test this. So thanks to the wonders of the loopback, here's how you can. This is a bit convuluted, but you get the idea:
dd if=/dev/zero of=test_fs bs=1024 count=10240
mkfs -t ext3 -q test_fs
mkdir ~/mnt/test_fs
sudo modprobe loop ext3
sudo mount -o loop ./test_fs ~/mnt/test_fs
dd if=/dev/zero of=~/mnt/test_fs/abc bs=1024 count=8243

You now have a 10Mb ext3 partition-in-a-file mounted on mnt/test_fs, with a large file "abc" pretty much filling it. Here is some perl that will fail on a print:
#!/usr/bin/perl
#

open (my $file, ">$ENV{HOME}/mnt/test_fs/def") or die "Can't open file: $!";
my $i = 0;
while (print $file "hello\n") {
	print $i++, "\n";
}
print "print failed: $!";
It gets to 681 on my box before reporting:
print failed: No space left on device

Added: 20060912

Dell E551 Monitor 1024x768 Scan Rates

I'm used to monitors just working with a wide range of scan rates - not this one. Tracking down the correct values was quite tricky (some guys ebay auction listed them). So here are the details you need in your xorg.conf.
Section "Monitor"
    Identifier  "Dell"
    HorizSync   31-54
    VertRefresh 50-120
EndSection
This finally lets you raise the screen resolution to 1024x768 from the default (and tiny) 800x600. This works for me - but please try at your own risk. Changing scan rates can permenantly damage your monitor. I am not responsible for any damage done.

Adding an NE2000 card on an ISA bus

Well, this was a fun one. I have a salvaged HP Brio 71xx machine which does duty as a gentoo http-replicator and portage mirror for my home network (see what a good netizen I am). This machine has 2 PCI slots and an ISA slot. It did have a soundcard in one PCI slot and a nice 3Com NIC in the other PCI slot. However the machine also sometimes doubles up as a spare desktop in the server room. It is quite unsubstantial for this as the max screen resolution I can get is 800x640. For Galeon it means half the screen is filled with buttons and bookmarks and what not, with precious little space for b3ta or popbitch or whatever drivel I am browsing. So when an ISA NE2000 card was on its way to the scrap-pile I rescued it, hoping to get a PCI graphics card down from the loft to improve the desktop capabilities.

ISA is a strange world of mystery, one which plunged me into a DOS-like world of IRQs and IO addresses that it has been over ten years into which I last delved. Most cards I slap into Linux these days Just-Work(tm) This generic NE2000 card didn't. What to do?

Well it turns out the secret to this is the isapnp package. emerge isapnptools, and then run pnpdump. The card was found as the last in the list, described as (NAME "ATIf430/4107577382[0]{ATI AT-2000 PnP Ethernet Network Adapter}"). pnpdump -c >/etc/isapnp.conf sets up your configuration. According to this command my card was on IO 0x240 and IRQ 3. Fancy!

Make sure your card is seated properly, without a wodge of dust in the slot - this stops it working. Then add isapnp to your start up: rc-update add isapnp default.

You now need to add NE2000 support to the kernel (You did already enable ISA bus support in "Bus Options"? Yeah, you did. Right?). This is a quick trip down the device drivers section. This should do it:

Device Drivers->Network Device Support->Ethernet (10 or 100Mbit)->[*] Other ISA cards-><M> NE2000/NE1000 support

Make, and install your new kernel. You now have a kernel modules called "ne" that supports this card.

Now you have to tell the kernel about the inner details. Create a file called (this is Gentoo specific) /etc/modules.d/net It should contain what you learned about the card earlier. Mine says this:

alias eth0 ne
options ne io=0x240 irq=3

Now, as I was replacing a PCI ethernet card I already had my network configured. So you'd think you just need to reboot. Right? WRONG Gentoo gets itself in a twist because by default it loads net.eth0 and then isapnp. Which means the ISA bus layer isn't ready, and net.eth0 fails Oh dear. The solution is simple. Edit net.eth0 and change the lines that say:

# For pcmcia users. note that pcmcia must be added to the same
# runlevel as the net.* script that needs it.
depend() {
use coldplug hotplug pcmcia usb isdn wlan

To add isapnp

# For pcmcia users. note that pcmcia must be added to the same
# runlevel as the net.* script that needs it.
depend() {
use coldplug hotplug pcmcia usb isdn wlan isapnp

And, and this bit is very important, run modules-update. Now reboot. There should be great joy as your card works. And hey! Nice man that I am, I've even opened a Gentoo bug to get net.eth0 fixed proper like.

But the bad news is, I never did find that PCI graphics card in the loft. Must have thrown it away. So its a trip to PC World for me to complete this project.

Added: 20050204

Adding sbl-xbl protection to postfix

This is a quick way to add sbl-xbl dnsbl protection to postfix to reduce the amount of spam you receive. Add the following line to your main.cf file:

smtpd_client_restrictions = reject_rbl_client sbl-xbl.spamhaus.org, permit

You can monitor this by grepping your mail log for NOQUEUE. Hopefully you'll see lots there.

Update: There's lots more good information about spam prevent with postfix in this article by Kirk Stauser.

[Back to the Front Page]

(c) Jon Mitchell