Building SDL
From wikiPodLinux
A working implementation of SDL (http://www.libsdl.org/) on the iPod would open up the way to a whole load of application porting fun.
This is (hopefully) a howto. This port works, but don't get to the end and start wondering where all the games are—it's not a simple recompile. Any ported apps need to be modified to work with the smaller screen and restricted input, but the port should hopefully be much easier with this library available.
Prerequisites:
- Linux (Cygwin should work)
- GCC, Autoconf, Automake, and the
arm-uclinux-elf-gcctoolchain - An iPod running Linux
- Generally knowing your way around compilation
| Table of contents |
Initial setup
Download SDL-1.2.8.tar.gz (http://www.libsdl.org/release/SDL-1.2.8.tar.gz) somewhere, plus this patch and SDL_ipodvideo.c (http://opensvn.csie.org/courtc/tools/SDL/src/video/ipod/SDL_ipodvideo.c) . These instructions assume you have the downloaded everything to ~/src, if this is not the case, adapt the commands appropriately.
% cd ~/src % tar xzf SDL-1.2.8.tar.gz % cd SDL-1.2.8 % patch -p1 < ../SDL-1.2.8-ipod.diff patching file configure.in patching file src/video/SDL_cursor.c patching file src/video/SDL_sysvideo.h patching file src/video/SDL_video.c patching file src/video/ipod/Makefile.am patching file src/video/ipod/SDL_ipodvideo.c patching file src/video/ipod/SDL_ipodvideo.h
Desktop build
This SDL port uses the iPod as just an additional video driver; you can use the patched source to build a normal desktop SDL build. In fact, if you haven't built SDL 1.2.8 before, you need to; the iPod port requires a complete set of headers to compile.
% cd ~/src/SDL-1.2.8 % ./configure --prefix=/usr # add any other options you want % make
In Linux:
% sudo make install
In Cygwin:
% make install
iPod build
The patch provides SDL, among its many other backends, one to directly access the iPod LCD. This turns out to be a good thing to use. You need some special configure options, but otherwise the build should be straightforward.
For various reasons involving good patching procedures, the patch does not directly update configure or the various Makefile.ins. You need to regenerate these with this command:
% ./autogen.sh
Now we can go ahead and build.
% ./configure CFLAGS="-D__unix__" --host=arm-elf LDFLAGS=-Wl,-elf2flt --enable-ipod --disable-joystick \ --disable-cdrom --disable-video-opengl --disable-threads --disable-audio
% cp ../SDL_ipodvideo.c src/video/ipod
% make # NOT make install
Most of the above options passed to configure should be self-explanatory; we need -D__unix__ to prevent the preprocessor from blatting out the contents of audio/SDL_audiodev.c and leaving a load of undefined references. Unless we disable threads, the timer code will use them, creating some nasty and hard-to-track freezes in SDL_Quit(). Audio won't work with threads, and we need a better COP-using solution anyway. I don't think the lack of joystick, OpenGL, or CD-ROM support will be a problem...
The library will be created in src/.libs/libSDL.a in the SDL source tree; copy this somewhere convenient.
Test program
To test SDL, try this quick program. Put it in a file called SDL_Rects.c.
#include <SDL.h> #define LCD_WIDTH 176 // Replace these LCD size values with those of your build target #define LCD_HEIGHT 132 // See screen sizes for a comprehensive list #define LCD_BPP 16 // The iPod port of SDL treats the 2bpp LCD displays as 8bpp; see below for more information Uint32 colors[3]; int main() { SDL_Rect r; SDL_Surface *screen; SDL_Event ev; int i; r.y = 0; r.w = LCD_WIDTH/4; r.h = LCD_HEIGHT; SDL_Init (SDL_INIT_VIDEO); screen = SDL_SetVideoMode (LCD_WIDTH, LCD_HEIGHT, LCD_BPP, SDL_SWSURFACE); if (!screen) { SDL_Quit(); printf ("Could not set LCD_WIDTHxLCD_HEIGHTxLCD_BPP video mode: %s\n", SDL_GetError()); return 1; } colors[0]=SDL_MapRGB(screen->format,0,0,0); colors[1]=SDL_MapRGB(screen->format,255,0,0); colors[2]=SDL_MapRGB(screen->format,0,255,0); colors[3]=SDL_MapRGB(screen->format,0,0,255); SDL_ShowCursor (SDL_DISABLE); for (i = 1; i <= 4; i++) { r.x = i * r.w; SDL_FillRect (screen, &r, colors[i]); } SDL_Flip (screen); for (i = 0; i < 10; i++) { SDL_WaitEvent (&ev); } SDL_Quit(); return 0; }
Place the libSDL.a from above in the same directory as this file, compile it with
arm-elf-gcc -Wl,-elf2flt -o rect SDLrects.c -I/usr/include/SDL libSDL.a -lpthread
and place rect in the /bin directory on your iPod's Linux partition.
Testing
It isn't a good idea to run the program from Podzilla (because then the framebuffer is in use; the SDL app will run fine but will not correctly switch back to podzilla). However, if you can launch it from podzilla, just reset after you quit. Another possibility is to use getLoader2Args to launch the application instead of podzilla, or even make a start file that runs it before podzilla.
Why not NanoX?
An earlier attempt at building SDL for the iPod used the preexisting NanoX backend (the same library that Podzilla uses) and had a lot of problems getting apps to run. This is mainly caused by the fact that SDL does not natively support 2-bit graphics, and NanoX does not lie about the graphics capability of the iPod. To get around this problem, my iPod driver "lies" by claiming an 8-bit palletized graphics mode; however, the palette is set to {White LtGrey DkGrey Black White LtGrey ...} and cannot be changed. In fact, this fact means that one might very well be able to SDL_BlitSurface() some colored image onto the iPod screen and get an automatically adjusted result.
What now?
Go on and port some applications! See the Wiki page on SDL Programming for the iPod.
You can download a prebuilt libSDL.a here (http://zacaj.com/libSDL.a)
