Demo Program

From wiki.gp2x.org

Contents

Before You Begin

Before you begin compiling and installing a demo program, you need a few other things first.

  • Find extra batteries or have a power supply. This will save frustration.
  • Install the SDL library files on your GP2X. See page 13 of the [GP2X User Guide] for instructions. This will involve copying some files to your SD card, running a program on the GP2X, and then deleting those files off your SD card. (While this isn't necessary for the example below, which uses libraries bundled into a single executable, this will come in handy later.)
  • Install the SDL and the MinSys for your development environment. See Getting started with GP2X development

Replacing Demo.C

The demo.c file that came with the development environment is specific to the SDL, but not the GP2X. Look at Source code to a Demo Program for a better version. Copy this new demo.c over your previous devkitGP2x/demo/demo.c version.

Find an image file

You will need an image file, named image.bmp, for the program to display. You may take this one (but it needs converting to bmp and renaming).

http://wiki.gp2x.org/images/d/db/GP2X_320_240.jpg

Todo: Check if possible to link BMP. Add some detail as to how big the image should be - maybe 320 x 240?.

This is how my directory now looks:

C:\devkitGP2X\demo>dir
 Volume in drive C has no label.
 Volume Serial Number is 23B3-EBFB

 Directory of C:\devkitGP2X\demo

01/25/2006  06:01 PM    <DIR>          .
01/25/2006  06:01 PM    <DIR>          ..
01/25/2006  05:05 PM             5,909 demo.c
01/24/2006  02:01 PM            30,054 image.bmp
11/30/2005  02:52 PM               588 Makefile
               3 File(s)         36,551 bytes
               2 Dir(s)  30,098,501,632 bytes free

Make the demo.gpe file

Time to compile. Go to the demo directory, and type make.

You should see something like this:

C:\devkitGP2X\demo>make
C:/devkitGP2X/bin/arm-linux-gcc `C:/devkitGP2X/bin/arm-linux-sdl-config --cflags
` -O2 -Wall -Werror   -c -o demo.o demo.c
C:/devkitGP2X/bin/arm-linux-g++ -static -o demo.gpe demo.o `C:/devkitGP2X/bin/ar
m-linux-sdl-config --libs`
C:/devkitGP2X/bin/arm-linux-strip demo.gpe

C:\devkitGP2X\demo>

On my system, the make command is the GNU version hiding in C:\devkitGP2X\MinSys\bin. The .gpe extension means that this will be under the 'games' menu when on the SD card.

Copy and run

Copy demo.gpe and image.bmp to the root directory of the SD card. The image.bmp file must be in root directory because the source code explictly opens /mnt/sd/image.bmp.

Run this by booting your GP2X, selecting Games, and then selecting demo.gpe.

Now, go back and read the source code line by line. Tweak until you understand.

Personal tools