Thursday, January 27, 2011

Building on and for Knoppix II

Updated with some corrections from last time.


The Knoppix Live CD (http://knopper.net/knoppix/) is an excellent way to try out Linux on any PC with a CD-ROM drive. It won't store anything on your PC (unless you ask it to) and doesn't mess up any existing installations of Linux or Windows.

In this article, I'm going to describe how to build ROLF to run on Linux assuming a PC booted from an unmodified Knoppix 6.2 CD.

When done, you should have a working ROLF desktop being displayed in a window, able to run a few native ROLF programs and even some RISC OS programs, in a limited way. Simply by copying the directory into which you've installed ROLF to some permanent storage (a hard disc or a memory stick, for example), you can use the build again without having to go through the steps I describe.

Set up a build environment

Knoppix, unfortunately, doesn't include all the tools needed to build ROLF, so we have to get them from Debian first. (If your Linux system already includes these tools, you can obviously skip this step.)

First, get the full list of packages that are available:

sudo apt-get update

Then update the compiler to include the C++ compiler, needed to build the Server part of ROLF (the libraries are all plain C, but to build them, you need libtool).

sudo apt-get install build-essentials
sudo apt-get install subversion
sudo apt-get install libtool
sudo apt-get install pkg-config

After that has been done, the compiler will still refuse to compile C++ programs because it can't find cc1plus, for some reason. The simplest way to fix that is to add the path to the (just installed) cc1plus file installed to the PATH environment variable.

export PATH=$PATH:$(dirname $(find /usr/ -name cc1plus 2>/dev/null | head -n 1))

Now, to get the source code:

svn co https://ro-lf.svn.sourceforge.net/svnroot/ro-lf/ROLF/rolf

(If you don't expect to make any changes to the code, you can instead use:
svn export https://ro-lf.svn.sourceforge.net/svnroot/ro-lf/ROLF/rolf)

Change directory into the downloaded code and run configure (not as complicated as a normal configure script):

cd rolf
./configure --appsdir=$(pwd)/Apps --prefix=$(pwd) --tarballs=$(pwd)/tarballs/

Knoppix (or Debian) have all their shared libraries taged by their version number; to make the files linkable, we need to do this:

mkdir lib
ln -s /usr/lib/libz.so.1 lib/libz.so
ln -s /usr/lib/libjpeg.so.62 lib/libjpeg.so
ln -s /usr/lib/libpng12.so.0 lib/libpng.so
ln -s /usr/lib/libfreetype.so.6 lib/libfreetype.so
ln -s /usr/lib/libstdc++.so.6 lib/libstdc++.so
ln -s /usr/lib/libmagic.so.1 lib/libmagic.so


Similarly, the build requires a set of include files [This bit needs an update!]

Specifically, the files needed are:

From zlib:
zlib.h, zconf.h

From libpng:
png.h, pngconf.h

From file:
magic.h

From libjpeg
jpeglib.h, jmorecfg.h, jconfig.h

From freetype 2:
./ft2build.h
./freetype/internal/internal.h
./freetype/fttypes.h
./freetype/ftsystem.h
./freetype/ftmoderr.h
./freetype/ftimage.h
./freetype/fterrors.h
./freetype/fterrdef.h
./freetype/freetype.h
./freetype/config
./freetype/config/ftheader.h
./freetype/config/ftconfig.h
./freetype/config/ftstdlib.h
./freetype/config/ftoption.h

Update the config.mak file created by configure to point at the libraries and includes:

sed -i 's/CFLAGS.*$/& -L$(CFGDIR)\/lib/' config.mak
sed -i 's/CFLAGS.*$/& -I$(CFGDIR)\/my_includes/' config.mak


Now you should be able to build ROLF:

make

Assuming all goes well with the build, the next step is to collect the resources needed in one place.

You will need:
  • Fonts (at least FreeSerif.ttf; the default font)
  • Tool and Icon sprites (I use Chris Wraight's Steel theme, from here: http://www.lym.iconbar.com/downloads/steel.zip)
  • A mimemap.txt file (if you're going to use RISC OS software)
  • and a !Boot file, to load them all (like the one below)
Create a resources directory with subdirectories:
mkdir -p Resources/fonts/{FreeSerif,FreeSans,FreeMono}
ln -s /usr/share/file/ Resources/ 
cd Resources/fonts 
for i in *; do for f in $( find /KNOPPIX/ -name $i*.ttf ); do ln -s $f $i/ ; done ; done 2>/dev/null
# This one is needed for the Terminal application: 
cp `find /KNOPPIX/ -name default8x16.psf* 2> /dev/null` .
cd .. # Resources
unzip steel.zip
cd ..
cat > \!Boot <<"EOF"
IconSprites $ROLF_RESOURCES/Steel/Tools 
IconSprites $ROLF_RESOURCES/Steel/Icons 
LoadPointer $ROLF_RESOURCES/Steel/Icons ptr_default 0 21
LoadPointer $ROLF_RESOURCES/Steel/Icons ptr_double 0 21
# Match up icons with the appropriate mime types 
if [ -f $ROLF_RESOURCES/mimemap.txt ] ; then ( grep -v ^# $ROLF_RESOURCES/mimemap.txt | tr -s '\t' | cut -f 1,3 | sort -k 2 | sed 's/\(.*\)\t\(.*\)$/IconSprite file_\2 "file_\1"/' | sh ) ; fi 
# Load applications 
IconBar 
Filer Icon $(dirname $0)/Apps 50 romapps Apps
Filer Icon /tmp 40 ramfs ramfs 
Filer Icon $HOME 45 homedisc Home
EOF

Now, we just have to run it!
 
export LD_LIBRARY_PATH=`pwd`/lib
export PATH=$PATH:`pwd`/bin
#Uncomment the next line if you need a log of what's happened (useful for debugging) 
# ROLF_WIMP_LOG=/tmp/rolf_wimp_log \
ROLF_RESOURCES=`pwd`/Resources \
ROLF_VNC=800x600:2008 \
Wimp

That should have the effect of printing:
VNC Server waiting for connections on port 2008.
New file descriptor 3
New Opaque bitmap VNCFrameBuffer, 800x600

In another terminal window, type:
 
vncviewer localhost:2008

... and a colourful window with an icon bar and a couple of drive icons should appear!

Wednesday, January 26, 2011

Progress, with a Video!

A couple of bugs have been chased down, so, just for fun, I thought I'd try and make a screen capture video of the state of the emulator.

At first I tried to use recordmydesktop, but that doesn't seem to play nice with the compiz window manager.  So, I found a nice, uncomplicated, picture format (TGA) and modified the user interface to write a screenshot to a file ten times a second (albeit upside down).  The user interface, incidentally, is a separate process from the emulator and accesses the files that contain the memory of the emulated RPC directly, much like a real VIDC chip.

Using mencoder, I produced the following video; it's probably best to watch it in fast-forward since it takes 40 seconds to get to the desktop and I'm not the fastest typer, either!

The upload to Blogger seems to have scaled it down 50% and reduced the quality considerably, though. The screen looks a lot better than that in use.

video


The command line I used to generate the movie was this:
mencoder mf://*.tga -mf w=640:h=480:fps=10:type=tga -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -o /tmp/screen_cap.mpg -flip

Monday, January 24, 2011

I don't much like C++

Tuesday, January 18, 2011

Programs are running, for a while at least.

The stand-alone RPC emulator has taken a couple of steps forward in the last few days.

Still some problems!


The TEQP implementation was wrongly checking the future processor mode rather than the current one, to see which flags should be affected.

Once that was fixed, the next problem was dealing with pre-fetch aborts, where the ARM code scanner caused a segmentation violation reading the memory where code would be mapped in by the OS's lazy address decoding.

There are still problems with caching (see picture); I've missed something that should be clearing the instruction cache between task swaps...

In addition to stability, I need to:

  • Write a module to handle the mouse input (I've done a hack to intercept OS_Mouse calls, but the RO pointer doesn't move with it, just changes shape while staying motionless).  The X interface passes on absolute coordinates, like a tablet, rather than relative movement, like a mouse.
  • Sort out keyboard input (it's a bit hit and miss if a keypress appears when you're typing quickly); I think RISC OS is debouncing the input, so modifying the timing of keyboard events might sort that out.
  • Intercept more SWIs; networking ones might be a good start.
  • More graphics modes (limited currently to 640x480x256), maybe change the RISC OS mode when resizing the X window.
What ROLF gets from all this

When it works, ROLF should gain:
  • a bit of publicity
  • a test platform for running RISC OS programs under ROLF (I'll be able to examine the behaviour of SWIs under RISC OS when implementing them in the compatibility layer
  • an X windows front end for a variation on the ROLF Wimp server which will make use of the work done on graphic card acceleration to display the frame buffer (while still remaining compatible with simple frame buffer implementations)