Games PSP GameDev With Eclipse
Games PSP GameDev With Eclipse
PSP
Homebrew
GameDev
with Eclipse
By Paulo Lopes
www.jetcube.com
Getting Started
During this small book you will learn to
setup the development environment for your
PlayStation Portable using either Microsoft Windows
or Linux as your host operating System. Although the
book will only focus on these two operating systems
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, OpenSolaris 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!
Required Software
Getting started is easy and only requires
one package, however this book will help you to be
productive, therefore besides MinPSPW (the minimal
required software to compile your game to the PSP)
You will install a C/C++ IDE (Eclipse) and a open
source 3D modeling tool (Blender3D) to create a full
pipeline of game development.
You will get more information on what are
these components and are free to replace them with
others you like more after you understand their role
in the full pipeline.
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
publicly available, actually Sony has never released
it as an open source tool, however a huge base of
fans understood the full power of the machine and
started to dig into the hardware and binaries that you
Eclipse
PSP development forums are full of posts
regarding people trying to get an unified
development environment. There are reports about
using Visual Studio, Code::Blocks, vi, Eclipse, etc...
but it was always tricky to get it working.
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 building 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 corporation that hosts the Eclipse
projects and helps cultivate an open source
community 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 modeling, 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 integrated work flow. 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 or animations, 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.
Prepare 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 software 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.6 and Blender3D.
MinPSPW
The MinPSPW tool-chain is available at:
http://www.sourceforge.net/projects/minpspw. At the
moment of the writing of this book the current version
is 0.9.6. Once you download it to your PC, start the
installation and follow the wizard:
Eclipse
Eclipse IDE can be downloaded from the
project web site at: http://www.eclipse.org. This book
covers Eclipse >=3.5. In order to get eclipse running
you need to have an updated Java Runtime. So
before starting looking for the right Eclipse for you
download the Java Runtime from
http://www.java.com/getjava. The Java page is quite
good explaining on how to download and install the
runtime. At this moment you might be asking the
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
Blender3D
Blender3D relies heavily on Python scripting
language. In order to get the full potential from this
package you should install Python (version 2.6 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.python.org, go to the download page and
download the latest 2.6.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:\Python26.
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. 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.
Makefile Options
Open your Eclipse and go to the Window >
Preferences menu. Once you are there navigate to
the C/C++ > New CDT Project Wizard > Makefile
Project on the navigation tree. This panel will allow
you to configure a compiler which is not the host
system GCC. Since we are using a cross compiler
(not a native compiler) we need to change some
parameters to get the full power of Eclipse.
On the first tab, Binary Parsers, enable the
ELF parser. PSP runs binary files in ELF format.
Allowing this configuration to parse them will show
you once you compile which functions are available
in your object files. This might seem not important
but can help to identify bugs later on. As a rule of
thumb enable it even if you don't really think you
need it since there are no side effects either in code
size or performance of your system.
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. Usually most of the development
environments provide a source level debugger, the
C programming
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 finally 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 development 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\
name
wait1second
wait2seconds
main
SetupCallbacks
loops_10_times
nested
gprof_cleanup
v1:0x000000FF
a3:0x4400BF54
t3:0x00000001
t7:0xDEADBEEF
s3:0x0BBBFEE0
s7:0xDEADBEEF
k1:0x00000000
ra:0x08804CC0
$zr, 0($v0)
Minimalist Game
Engine
In this chapter I will show how you can
create a very simplistic game engine. It will not be
suited for real life games but is just a follow up on
how to use a modeling tool to create your 3D assets
and import them into the rendering pipeline of the
PSP.
Blender Exporter
I am going to write a simple exporter to a
binary format that we can pick up later and render on
the PSP with minimal effort. For the sake of the
demonstration, the code is simple and not designed
for optimal performance. It is an academic exercise
to demonstrate how easy is to use Blender and the
PSP.
Blender3D is a powerful 3D modeling and
animation package that is powerful but at the same
time simple to script using Python as its internal
language. All Blender objects are exported to Python
giving us the full power of this tool to fit our needs.
Although Blender has its own code editor, I
feel more comfortable using a generic text editor or
Eclipse. Adding a simple exporter is as simple as
creating a text file and copying it to a specific folder
under your Windows user profile.
Register your exporter with Blender is as
simple as writing the following line:
Blender.Window.FileSelector(do_export, "Export",
sys.makename(ext='.jc'))
if mesh.faceUV:
u,v=face.uv[vert_i]
print "(u,v)=(%f,%f)"%(u,v)
else:
u,v=0,0
if mesh.vertexColors:
r = face.col[vert_i].r
g = face.col[vert_i].g
b = face.col[vert_i].b
a = face.col[vert_i].a
else:
r,g,b,a=255,255,255,255
# find matching vertex
for i in vertex_map[co]:
match = True
if vertex_list[i]["no"] != no:
match = False
if "uv" in vertex_list[i]:
if vertex_list[i]["uv"] != (u,v):
match = False
if "col" in vertex_list[i]:
if vertex_list[i]["col"] != (r,g,b,a):
match = False
if match:
break
if match:
matching_vertex = vertex_list[i]
matching_vertex["uv"] = (u,v)
matching_vertex["col"] = (r,g,b,a)
matching_index = i
else:
matching_vertex = {
"co":co,
"no":no,
"uv":(u,v),
"col":(r,g,b,a)
}
vertex_list.append(matching_vertex)
matching_index = len(vertex_list)-1
vertex_map[co].append(matching_index)
index_list.append(matching_index)
# print matching_index
print "end face"
# write header
file.write("jcMD")
file.write(
struct.pack("<III",
flags,
len(vertex_list),
len(mesh.faces)))
...
file.close()
}
if(!jcTexLoad(&(model->texture), uid)) {
sceIoClose(uid);
return -1;
}
sceIoClose(uid);
return 0;
}
}