PSP Eclipse
PSP Eclipse
Paulo Lopes
[email protected]
Contents i
1 Getting Started 1
1.1 Required Software . . . . . . . . . . . . . . . . . . . . . . . . . . 1
3 C programming 13
3.1 Not an Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Debug your Game . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
i
1
Getting Started
During this small book you will learn to setup the development environment
for your PlayStation Portable using Microsoft Windows as your host operat-
ing System. Although the book will only focus on Microsoft Windows you
can easily re use the same knowledge to your favorite operating system as
long as you manage to cross compile the PSPSDK. At the moment of writing
of this book the SDK can be cross compiled to Microsoft Windows (native and
emulated Cygwin), Linux, BSD and MacOS.
You will learn how to setup a working IDE with full debugging support
and then create a minimalist game engine with a blender exporter for your 3D
assets. This book will not teach the reader to program and assumes that the
reader is already familiar with the C programming language. This does not
mean that C is the only supported language in the SDK, you can use C, C++,
Objective-C or Objective-C++ for your native development or even Lua as a
scripting language (again not covered in this book).
Are you ready? Let’s get started!
MinPSPW
Before starting developing for your PSP you need machine code tools. The
minimal toolset you will need is a compiler and linker for the PSP CPU. The
PSP CPU is known as the MIPS Allegrex. Basically is a modified MIPS 3000 +
FPU (Floating Point Unit) + VFPU (Vector FPU) all in one. Although originally
prepared to run at reduced CPU clock speed (200MHz) the usage of all these
CPUs make the PSP a powerful machine and still up to date (4 years after it’s
initial release).
The compiler and linker for this CPU is not publically available, actu-
ally Sony has never released it, however a huge base of fans understood the
1
2 CHAPTER 1. GETTING STARTED
full power of the machine and started to dig into the hardware and binaries
that you can run on the device. The findings allowed us to create a simple
toolchain based on the popular GNU GCC compiler.
This modified compiler is available to all under a GPL/BSD license mak-
ing it free for everyone. Under Microsoft Windows there were two options,
either use a posix emulator (Cygwin) or a native build (devKitPro) which is
not updated very often.
In the beginning of 2008 a new project started to port the SDK and keep
it up to date without any kind of emulation for windows (MinPSPW). Users
could just download a simple installer and once the installation was finished,
games could be compiled from the standard dos console window, the same
way the linux/bsd variant can compile from the shell.
Eclipse
PSP development forums are full of posts regarding people trying to get an
unified development environment. There are reports about using Visual Stu-
dio, CodeBlocks, Vi, Eclipse, etc... but it was always tricky to get it work-
ing.Eclipse is a Java-based, extensible open source development platform. By
itself, it is simply a framework and a set of services for building applications
from plug-in components. Fortunately, Eclipse comes with a standard set of
plug-ins, including the well-known Java Development Tools (JDT).
Eclipse is an open source community whose projects are focused on build-
ing an open development platform comprised of extensible frameworks, tools,
and runtimes for building, deploying, and managing software across the life
cycle. The Eclipse Foundation is a not for-profit member-supported corpora-
tion that hosts the Eclipse projects and helps cultivate an open source commu-
nity and an ecosystem of complementary products and services.
Blender3D
Blender was first conceived in December 1993 and born as a usable product in
August 1994 as an integrated application that enables the creation of a broad
range of 2D and 3D content. Blender provides a broad spectrum of model-
ing, texturing, lighting, animation and video post-processing functionality in
one package. Through it’s open architecture, Blender provides cross-platform
interoperability, extensibility, an incredibly small footprint, and a tightly inte-
grated workflow. Blender is one of the most popular Open Source 3D graphics
application in the world.
Aimed world-wide at media professionals and artists, Blender can be used
to create 3D visualizations, stills as well as broadcast and cinema quality videos,
while the incorporation of a real-time 3D engine allows for the creation of 3D
interactive content for stand-alone playback.
2
Install & Setup the Environment
During this step You will learn how to install your environment and set it up
in order to be productive. This step involves download of open source soft-
ware from the internet (during all this book, only open source software will be
used, regardless of the license as long as it is OSI approved). Again the only
required component is the MinPSPW, however for the course of this book, you
will need some extra components: Java Runtime, Eclipse IDE, Python 2.5 and
Blender3D.
2.1 MinPSPW
The MinPSPW toolchain is available at: http://minpspw.sf.net. At the
moment of the writing of this book the current version is 0.8.10. Once you
download it to your PC, start the installation and follow the wizard:
The installer will ask you to agree with the license, which basically is a
collection of open source licenses for all the components inside the SDK. BSD
license for the SDK itself, GPL for the MinPSPW and some of the included libs
and LGPL for some of the included libs. There are no closed source compo-
nents included.
Once you are done with the license you can choose which components to
install, If you are not sure, just select everything unless you don’t have around
150Mb of disk space.
3
4 CHAPTER 2. INSTALL & SETUP THE ENVIRONMENT
At this moment you have a working compiler that allows you to unleash
the power of your PSP. To make sure that everything works lets make a simple
test. Let’s check the version of a couple of components that were just installed.
Open a DOS console prompt and type:
If you don’t know what those commands are, I’ll explain: The first one is
the build tool, that will automate your build process of compiling and package
your code into a PBP file that can run on your PSP. The second is the PSP
compiler and linker.
question: “can I code in java for the PSP?” Well the answer is yes and no; yes you
can if you use something like pspkvm; and no because the native compilers
do not support gcj (yet).
I assume that you already have the java runtime installed, so the next step
is to install Eclipse. As said before get it from http://www.eclipse.org
and select the “Eclipse for C/C++ Developers”. You can choose any of the
other options as you make sure that later you install the CDT (C Development
Tools) plug-in. For now just download the Eclipse for C/C++ Developers.
Once you download the zip file, unzip it to a simple directory in your PC.
I assume you unzip to C:\. In order to make it easier make a shortcut to your
desktop to the executable file on C:\eclipse\.exe.
Once you have decided where to store your work you are shown the wel-
come page. This page exists inside the workbench (see 2.5). As an Eclipse user,
you’ll be given a few options of going to an overview page, which I recom-
mend. See what’s new, explore some samples, or go through some tutorials.
The Eclipse workbench consists of several panels known as views, such
as the navigator or outline views. A collection of these views is called a per-
spective. One of the most common perspectives is the Resource perspective,
which is a basic set of views for managing projects and viewing and editing
files in a project.
I recommend most novice users start with the Overview page featured in
Figure 2.5 and learn about Eclipse. The workbench basics section contains a
lot of good starter information about the various pieces of Eclipse and how
they interact.
2.3 Blender3D
Blender3D relies heavily on Python scripting language. In order to get the full
potential from this package you should install Python (version 2.5 for binary
compatibility) into your PC. Install Python is easy as it was to install the Java
Runtime. Python can be downloaded from the project website http://www.
6 CHAPTER 2. INSTALL & SETUP THE ENVIRONMENT
python.org, go to the download page and download the latest 2.5.x installer.
Do not install the latest version since Blender3D might have some trouble
using it. Get the release MSI and install it. Follow the wizard and again try to
use the default installation path C:\Python25.
Once you PC has Python installed download and install Blender3D. By
the time of writing this book, Blender 2.48a is the current release, download
it from: http://www.blender.org and install it. Again I advice you to
install to the default path.
Starting Blender3D
Blender3D user interface is not easy for the beginner 2.6. Just explore the
menus and if you really interested there are some nice tutorials and books
that can help you getting into shape with Blender.
External Tools
The MinPSPW SDK is an open source SDK for the PlaySation Portable, it does
not contain hardware debugging facilities as the official Sony SDK. To debug
a Homebrew application you would usually code your game, compile, link,
plug the PSP usb cable, transfer the PBP file to the memory stick, unplug the
cable, start the game and on error you would either be lost or you would have
some text file in your memory stick with your printf debug statements.
This approach can become impractical for real projects, that is when PSPLink
8 CHAPTER 2. INSTALL & SETUP THE ENVIRONMENT
comes into place. We will cover PSPLink later during the debug chapter, for
now just be aware that the PSPLink is composed of 4 parts:
• PSPLink PBP - A PSP application that will be the bridge between your
application and all the debugging facilities.
• USB Driver - A special USB block device driver that does the low level
communication between the PSP and your PC.
The first 2 features that need to be configured into Eclipse. In the main
Eclipse window, locate the “External Tools button” This is a simple green run
button with a red toolbox under. Note that there is a drop-down option in the
button, activate it and select “External Tools Configurations...”.
Create a new tool under “Program” called “usbhostfs 2.9. On the location
find the folder where you installed the PSPSDK and under the bin folder you
will find an executable named: “usbhostfs_pc.exe”. Apply your changes. On
the working directory use the variable “project_loc”. Apply your changes and
close.
Still in the same configuration window, create a new tool under “Pro-
gram” called “pspsh 2.10. On the location find the folder where you installed
2.4. SETUP THE ENVIRONMENT 9
the PSPSDK and under the bin folder you will find an executable named:
“pspsh.exe”.
1. Connect your PSP to the USB cable and make sure that the USB link is
disabled, in other words you should not be able to see the memory stick
contents from your PC.
3. A New Hardware Wizard will popup asking for the correct driver. The
driver is in the MinPSPW “bin” folder. Locate it and point to the “driver”
folder.
2.4. SETUP THE ENVIRONMENT 11
At this moment your USB driver should be installed and ready for use. To
try out and see if everything when right, go back to your eclipse and start the
USBHostFS external application, once you have done it, the console window
in the bottom should show something like this 2.11.
In this chapter you will learn how to code your first game. You will learn how
to setup your project under eclipse and use the features that it gives to you
such as code complete. You will also learn some of the internal differences of
coding for the PSP and coding for a normal PC.
Create a Project
Open Eclipse and create a new C project. Select File > New > Project and fi-
nally select C project. From the project type tree pick Makefile Project > Empty
Project. This will be your standard project type for most of the PSP develop-
ment with Eclipse. Selected this project for –Other Toolchain– and then enter
“Spinning Cube” in the project name and point the location to “C:\pspsdk \psp
\sdk \samples \gu \cube” after checking out the default location checkbox. Fi-
nally click Finish 3.1.
Next, we’ll take a look at the C/C++ perspective (if you aren’t already
there). Depending on how you like to manage your screen, you can change
the perspective in the current window by selecting Window > Open Perspective
> C/C++ or you can open a new window by selecting Window > New Window
and selecting the new perspective.
The C/C++ perspective, as you might expect, has a set of views that are
better suited for C/C++ development. One of these includes, as the top-left
view, a hierarchy containing various C/C++ namespaces, classes, includes,
libs and miscellaneous files. This view is the called the Package Explorer.
Also notice that the main menu has expanded to include two new menu items:
Source and Refactor.
If you have not noticed yet, you just compiled your first PSP application.
This is because Eclipse build your project automatically. Now that you are fa-
miliar with the workbench you can see in the project explorer that a file named
EBOOT.PBP is present. Before running and putting this file in your PSP lets
13
14 CHAPTER 3. C PROGRAMMING
look a bit closer to the workbench. Double click on the cube.c file. Eclipse will
highlight the C language keywords and even bold out your function names
3.2.
Eclipse will allow you to navigate through the code by “Ctrl + Click” a
function name or include file. This will open the definition of the method or
open the file. While typing “Ctrl + Space” will start the code complete feature
like visual studio’s Intellisense. Hovering over a function will trigger Eclipse
to parse any documentation in the source code written in a Doxygen/Javadoc
compatible way. These are just some of the features you can have with Eclipse,
feel free to explore the menus and the internet for more productive tips.
add “-g” to the CFLAGS variable. Also to build a PRX you should just the
BUILD_PRX = 1 line to the Makefile. Now clean your project using the Project
> Clean menu and you have a debuggable game.
The debugging process is a bit tricky and can be described as the following
steps:
• Start the USBHostFS application by selecting the project and using the
external tools button
• Start the PSPSh external tool by selecting the project and using the ex-
ternal tools button
• On the PSPSh type: debug cube.prx where cube.prx is your project PRX
file
If you are debugging for the first time you need to configure the debugger
for the project. This is a project specific configuration that is the reason it was
not included in the previous chapter. Select the drop down from the debug
button and pick “Debug Configurations...” A new window pops up and you
should select C/C++ Local Application. The project should be filled in be default
16 CHAPTER 3. C PROGRAMMING
with your working project and in the C/C++ Application your application ELF
should be entered, for out example it should be cube.elf 3.3.
This is the first step, the second step is to inform Eclipse that we are run-
ning a remote debugger, so switch to the debugger tab and the GDB debugger
should be replaced from gdb to psp-gdb 3.4, once this is done on the connection
sub tab, the type should be TCP and the port 10001 3.5.
Your debugger is now ready and should allow you to debug your code.
Once the debugger starts you are asked to switch to the debug perspective,
do it and inspect your code 3.6.
18 CHAPTER 3. C PROGRAMMING