More than half a year ago, I had a Sony Playstation Portable gaming console (or just a PSP). I must say that the games on it are excellent, the console can be taken on any trip and it is pleasant to pass the time on the road. As a developer, I was always interested in how to write applications for PSP, I saw many free applications such as PSP WiFile Transfer, Bookr and even ports of OpenSource games, such as OpenTTD, and recently I had some free time to tackle the issue of development for PSP in more detail, so I looked for information on this issue and, as it turned out, programming for the PSP is not so difficult.
So, in this article we will look at setting up the development environment for PSP in the C and C ++ programming languages ​​and writing the simplest classical program Hello world.
What we initially have:
')
1. Ubuntu 9.04 distribution
2. Internet access (you will have to download the source codes of the libraries necessary for the development of PSP programs)
3. free time of about 3 to 4 hours (libraries are compiled from source codes, so compilation takes several hours)
The first thing we need is to install subversion:
sudo aptitude install subversionNow you can get the latest source code psptoolchain (crosscompiler for PSP)
svn co svn: //svn.ps2dev.org/psp/trunk/psptoolchainIn the resulting folder there is a readme file for everyone and especially for the Ubuntu distribution (I note that psptoolchain can be compiled in any linux distribution, as well as cygwin-e). The readme file for the Ubuntu distribution says that to build psptoolchain, you must satisfy the dependencies with the following command:
sudo apt-get install build-essential autoconf automake bison flex \
libncurses5-dev libreadline-dev libusb-dev texinfo libgmp3-dev \
libmpfr-dev subversion gcc-4.2which we will do. After that, we need to define several environment variables. Add the following lines to the ~ / .bashrc file:
export PSPDEV = "/ usr / local / pspdev"
export PSPSDK = "$ PSPDEV / psp / sdk"
export PATH = "$ PATH: $ PSPDEV / bin: $ PSPSDK / bin"and execute the command:
source ~ / .bashrcNow you can proceed directly to building the development environment:
cd psptoolchain
sudo ./toolchain-sudo.shAfter that, you need to get additional libraries for development (zlib, SDL, etc.). To do this, we first obtain a set of scripts from SVN using the following command:
svn co svn: //svn.ps2dev.org/psp/trunk/psplibraries psplibrariesUnfortunately, there is an error in the installation scripts of additional libraries, in order to fix it you need to do the following: open the psplibraries / scripts / 003-freetype.sh file and replace its contents with the following text:
#! / bin / sh
# freetype.sh by Dan Peori (danpeori@oopo.net)
## Download the latest source code.
if test! -d "freetype"; then
svn checkout svn: //svn.ps2dev.org/psp/trunk/freetype || {exit 1; }
else
svn update freetype || {exit 1; }
fi
## Enter the source directory.
cd freetype || {exit 1; }
cd builds / unix
automake --add-missing
cd ../…
## Bootstrap the source.
sh autogen.sh || {exit 1; }
## Configure the build.
LDFLAGS = "- L $ (psp-config --pspsdk-path) / lib -lc -lpspuser" ./configure --host psp --prefix = $ (psp-config --psp-prefix) || {exit 1; }
## Compile and install.
make clean && make -j2 && make install && make clean || {exit 1; }After that, we establish one dependency:
sudo aptitude install libtooland start compiling libraries:
sudo ./libraries-sudo.shAfter these scams, we have a crosscompiler and a set of libraries for developing programs for PSP in C and C ++. Let's write our first program.
#include <pspkernel.h>
#include <pspdebug.h>
PSP_MODULE_INFO ("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
/ * Exit callback * /
int exit_callback (int arg1, int arg2, void * common) {
sceKernelExitGame ();
return 0;
}
/ * Callback thread * /
int CallbackThread (SceSize args, void * argp) {
int cbid;
cbid = sceKernelCreateCallback ("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback (cbid);
sceKernelSleepThreadCB ();
return 0;
}
/ * Sets up the callback thread * /
int SetupCallbacks (void) {
int thid = 0;
thid = sceKernelCreateThread ("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if (thid> = 0) {
sceKernelStartThread (thid, 0, 0);
}
return thid;
}
int main () {
pspDebugScreenInit ();
SetupCallbacks ();
printf ("Hello World");
sceKernelSleepThread ();
return 0;
}
So, using the PSP_MODULE_INFO macro, we define set information about our program and its version, then we define several standard callbacks and, accordingly, the main function of our main program — which sets the callback we set and prints the coveted “Hello world” on the screen.
Now we will write a Makefile to collect our code.
TARGET = hello
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $ (CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $ (CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello world
PSPSDK = $ (shell psp-config --pspsdk-path)
include $ (PSPSDK) /lib/build.makLet's compile our program with the make command. The resulting EBOOT.PBP file is placed on the console in the psp / game / hello folder. That's all. In the next article we will look at how to control keystrokes.
Original of my article:
linux.vsevteme.ru/posts/show?id=9059