Developing PSP Apps in Xcode

After much research and annoying shell script errors I have found a rather nice way of being able to develop and build my PSP apps all within Xcode. I also configured Xcode to automatically customise the EBOOT and place it in a folder ready to be copied straight to my PSP.

First create a new empty project in Xcode. For this explanation I'll call it pspProj. Now add a new empty file to the project and name it main.c and then add some code along with the standard other functions and code required for a PSP app. The next stage is to create a new target. From the window that appears choose Aggregate under Special Targets, and then name it pspProj and add it to our pspProj project. Now add a New Build Phase specifically New Run Script Build Phase. This will add a new item under the Target you created earlier called Run Script. Double click or Control click on it and select Get Info. A new window will appear allowing you to change the Shell, add a Script and specify Input and Output Files. We're only interested in the Shell and Script fields. For the Shell change it from /bin/sh to /bin/bash. For the Script copy and paste the one shown below.

export PSPSDK=/usr/local/pspdev/psp/sdk
export PSPDEV=/usr/local/pspdev
export PSPPATH=$PSPDEV/bin:$PSPDEV/psp/bin:$PSPSDK/bin
export PORTPATH=/opt/local/bin:/opt/local/sbin
export PATH=$PORTPATH:/bin:/sbin:/usr/bin:/usr/sbin:$PSPPATH

make
unpack-pbp EBOOT.PBP
pack-pbp EBOOT.PBP PARAM.SFO icon0.png NULL NULL pic1.png NULL DATA.PSP NULL

rm main.o pspProj.elf PARAM.SFO DATA.PSP
mkdir pspProj
mv EBOOT.PBP ./pspProj

This script above as you can see sets all the environment path variables that are required, calls make, unpacks the EBOOT, packs the EBOOT with a cusomt icon and background, removes the no longer needed files, makes a directory for the new EBOOT, and then finally moves the EBOOT into the directory ready to be copied straight to your PSP's GAME folder. All you have to change is where it says pspProj to whatever you named the TARGET as in your MakeFile. If you can't wait to do all that and just want to see if it works you can download a sample project below for Hello World.

Download Sample Xcode Project for Hello World (548KB)

While that's downloading I would like to point out that once you open the project in Xcode all you have to do is click on Build and your app is built for you so no messing around with the command line! Also you still need to have your MakeFile set up correctly for this to work. If you don't have any custom icons or backgrounds you want to set then you can remove the lines beginning with unpack-pbp, pack-pbp and rm. You can also remove the export for PORTPATH if you don't have MacPorts installed.

For the moment please send comments to comments@ragnaru.com.
I'll try and get the comments system back up and running as soon as I can.


PSP SDK / Toolchain Installation on Mac OS X

Phew. I finally got the PSP Toolchain script to run and install the PSP SDK.

Since there doesn't seem to be an in depth set of instructions on how to do it, especially for Mac OS X, I decided to write my own. It may seem similar to a lot of the others out there but I've tried to cover a lot of the problems people are getting and how to sort them that those other instrcutions miss out on telling you. So without further talk lets get started! First some prerequisites for the PSP Toolchain...

The listed packages below are required for the toolchain. Some of these may already be installed but I would recommend installing them again to get the latest versions. When I first did this I installed them all by hand including binutils and newlib. I already had gcc and friends from installing Xcode several years ago for programming, compiling and debugging C programs. Make sure your gcc is updated to 3.3.3 and you have version 4.0.1, which also allows you to compile 64 bit programs.

  • autoconf 2.59 (or greater)
  • automake 1.7 (or greater)
  • coreutils
  • diffutils
  • make
  • patch
  • patchutils
  • sed
  • subversion
  • wget
  • bash
  • gcc
  • gcc-core
  • gcc-g++
  • grep
  • gzip
  • tar

Optional, but recommended packages include: less and more. Some of these require other packages to be installed first, I can remember needing readline, texinfo and ncurses but there may be others. You can install these by hand as I did or use another app to do it for you and keep them all updated. If you install by hand some of these may already be installed, such as more and grep, but they may need updating.

I also used MacPorts (formerly DarwinPorts) after installing by hand since I couldn't get the toolchain to complete without errors. So if there were any missing packages MacPorts installed them. If you don't want to install all of them yourself go with MacPorts. Sounds better than Fink from what I've read. To install MacPorts and update it visit the MacPorts wiki. If you do use MacPorts here's the command to install all the required packages. This command has to be done as root, enter the root password when prompted to. Warning: only run as root if necessary and never leave yourself logged in as root.

> sudo port install autogen autoconf automake nano libtool libsdl patchutils subversion wget gmake

MacPorts will also install any dependencies they require. Although I did have to install texinfo manually, but that might be because it is not required by one of the other packages, I'm sure something uses it though.

The quickest and easiest way to set the environment variables for the PSPSDK is to use Terminal. Open up Terminal and make sure your in your home directory. We need to edit your bash profile with the relevant paths.

> nano .bash_profile

Paste into the Terminal the following paths.

export PSPDEV="/usr/local/pspdev"
export PSPSDK="$PSPDEV/psp/sdk"
export PSPPATH="$PSPDEV/bin:$PSPDEV/psp/bin:$PSPSDK/bin"
export PATH="/opt/local/bin:/opt/local/sbin:$PATH:$PSPPATH"

The paths above covers every directory you'll need as far as I know. The /opt/local/bin and /opt/local/sbin are required if you installed MacPorts. Now exit using Ctrl-X and type Y to save. You'll now be asked to provide a name for the file. Leave it as .bash_profile.

Now we can get the toolchain from svn, this means you'll get the most up to date toolchain and build scripts rather than using a pre packaged download of it. Getting the toolchain via svn has a major advantage over other methods, the main one being silent updates to the toolchain. The person who made the pre packaged toolchain won't know to update their download since a silent toolchain update won't be announced, thus leading to an out of date toolchain. Make sure you have svn and bzip2 installed for this to work. To see if you have them installed do a version check on each of them.

> svn --version
svn, version 1.4.4 (r25188)
compiled Jul 8 2007, 12:39:06
...

> bzip2 --version
bzip2, a block-sorting file compressor. Version 1.0.2, 30-Dec-2001.
...

Now that you've got all the required parts installed you can now get the toolchain via svn using the command below.

> svn co svn://svn.ps2dev.org/psp/trunk/psptoolchain

Once the toolchain has finished downloading you need to create and set the permissions for the directory the PSP SDK will be installed in. These next two commands have to be done as root, enter the root password when prompted to. Warning: only run them as root if necessary and never leave yourself logged in as root.

> sudo mkdir -p /usr/local/pspdev
> sudo chmod a+rwx /usr/local/pspdev

This next step will take a while to complete - somewhere around 30 minutes to 3 hours depending on your specs. To improve performance I recommend closing all open apps and any background apps as well before running the toolchain script. I've run it on my PowerBook which took a good 2 hours whereas my IBM ThinkPad was a lot quicker. The major difference between them is the IBM has double the amount of RAM as my PowerBook and a slightly faster processor. The main specs of each are listed below.

  • PowerBook G4 (Pre 1.67GHz)
  • Mac OS X 10.4.10
  • 1.5GHz G4 (PowerPC)
  • 1GB PC2700 RAM
  • 100GB 7200RPM HDD
vs.
  • IBM ThinkPad T40p
  • Windows XP Pro SP2 & Cygwin
  • 1.6GHz Intel Pentium M (Centrino)
  • 2GB PC2700 RAM
  • 60GB 7200RPM HDD

To run the toolchain script switch to its directory and then run the toolchain script.

> cd psptoolchain
> ./toolchain.sh

If the toolchain ends quickly or after a few minutes with a message stating it doesn't have permission to do something run the toolchain script as root. To do this you need to use the sudo command followed by the toolchain script. This will prompt you to enter the root password and allow the script to access what it couldn't before. Warning: only run the script as root if necessary and never leave yourself logged in as root.

> sudo ./toolchain.sh
Password:

If when you run the toolchain script you get an error stating it can't build binutils you have to modify the build script the toolchain uses. To get binutils to build successfully you need to make a small change to scripts/001-binutils-2.16.1.sh. These are shown below quoted from strmnnrmn's blog.

Secondly I had to make this change to scripts/001-binutils-2.16.1.sh. As urchin mentions on the ps2dev.org forum, ".m" is the extension for Objective C files in OSX. The '-r' tells make to ignore the built-in implicit rules, and everything works fine:

So:

## Compile and install.
make clean && make -j 2 && make install && make clean || { exit 1; }

became:

## Compile and install.
make clean && make -r -j 2 && make install && make clean || { exit 1; }

Thanks to strmnnrmn for blogging about modifying the toolchain's binutils build script for Mac OS X otherwise I would never of noticed it.

If you've read strmnnrmn's blog then you know he had to modify depends/check-ncurses.sh, whereas I didn't have to at all. I think between him downloading the toolchain (August 2nd) and me downloading it (August 17th) the check-ncurses.sh script was updated. In fact it was on August 16th! Another silent update just the day before I downloaded the toolchain again. It now looks like this.

## Check for the ncurses library.
ls /usr/include/ncurses.h 1> /dev/null || { echo "ERROR: Install ncurses before continuing."; exit 1; }

It checks only for the header file, ncurses.h in /usr/include, rather than libncurses.a or libncurses.dll.a in /usr/lib.

Once the toolchain script ends, hopefully without any errors, then you have just installed the PSP SDK for Mac OS X using the PSP Toolchain! To make sure everything went okay check out a couple of the PSP SDK's commands like psp-gcc etc. Sample out is shown below.

> psp-gcc --version
psp-gcc (GCC) 4.1.0 (PSPDEV 20060507)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> psp-config
Usage: psp-config [opts]
Options:
-p, --pspsdk-path : Print the base directory of PSPSDK
-d, --pspdev-path : Print the base install directory
-P, --psp-prefix : Print the prefix of PSP-hosted software

> pack-pbp
USAGE: pack-pbp <output.pbp> <param.sfo> <icon0.png> <icon1.pmf> <pic0.png> <pic1.png> <snd0.at3> <data.psp> <data.psar>

> unpack-pbp
USAGE: unpack-pbp <filename>

In my next post I'll explain how I got Xcode setup so I could write and compile my PSP apps directly within Xcode, and even customise the EBOOT automatically!
A sample Xcode project will also be up for download as well! Aren't I nice? ; )

For the moment please send comments to comments@ragnaru.com.
I'll try and get the comments system back up and running as soon as I can.


An update... At last!

Finally. An update that is longer than half a sentence. A reason for the lack of updates is due to a dying hard disk in my PowerBook G4. It ended with it being more viable to run OS X off my 300GB external LaCie hard disk than the 80GB internal Toshiba hard drive. Thankfully I now have a new hard drive and it runs a lot better, and faster, than the old one. The new hard disk is a 100GB Seagate Momentus. PowerBook hard disks aren't exactly the easiest thing to replace either. You have to take the whole keyboard off and shift around a few ribbon cables, but, it had to be done.

I be coding!

I would say this is a fair assumption of what I've been doing the last few months. As always not everything has gone to plan, as if it ever does, but this time it really does matter. Anyway enough of all that. I've got some new PHP scripts to test and install on the server and then after that prepare my custom Admin Panel and Installer to go with them. Then finally I can release the scripts I've been working on, and hopefully you'll find them useful and a refreshing change from similar scripts.


Coding...

I be coding!

A poor excuse for a post I know but it does sum up what I'm doing quite well. Anyway I've got to get back to my coding now, at least this turned into a nice break from it.


Advanced Poll Documentation

If your looking for the regular Ragnaru site it's not quite all here right now, but it will be back soon - hopefully.

On the other hand if your after a copy of a few pieces of documentation I wrote for proxy2.de's Advanced Poll (2.0.2) then here is the link.

Advanced Poll (2.0.2) Docs (296KB)

Edit: I guessed at what the date on this post should be so it may be later than April 24th but no earlier than August 5th. I also just had a look at the files contained in the zip file, they don't look too good in Word on my Mac. Hopefully they look better in WordPad and Word on Windows. Also the two installation manuals are the same but in .doc and .rtf formats. I may get around and redo the manual and guide for Advanced Poll 2.0.8 and make them more presentable across platforms and apps.

Ignore the e-mail addresses in the files as they are no longer active and or used by me. If you need to contact me about the documentation use this e-mail address comments@ragnaru.com.