PSP Programming/General/Hello World

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Hello World![edit | edit source]

Now that we've got a common folder for files which we're going to use often, and created our callbacks file we can begin creating a simple "Hello World!" program.

main.c[edit | edit source]

We'll start by including “pspkernel.h” which will allow us to exit the application, "pspdebug.h" so that we can get a simple debug screen started, "pspdisplay.h" for "sceDisplayWaitVblankStart" function, and "callback.h" of course so that the user can quit at any time by pressing 'home' and then 'exit'.

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>

#include "../common/callback.h"

Next, we will tell the PSP a little about our program. In "PSP_MODULE_INFO" we will tell it the name of our program, any attributes, and its major and minor version. You can ignore most of these attributes for now. Then to make things easier for ourselves (so that we don't have to type as much), we will replace "pspDebugScreenPrintf" with "printf" which will allow us to type text on the screen.

#define VERS 1 //Talk about this
#define REVS 0


#define printf pspDebugScreenPrintf

So, first we will initialize the debug screen, and setup our callbacks. Then inside a loop we place the position to write to at (0,0) (so that printing doesn't go to the next line) and print out our message, then to prevent “ripping” effects we call “sceDisplayWaitVblankStart”. Once the user quits and the loop is broken (remember we are using the "isRunning()" method), we do a last call to "sceKernelExitGame()" which will exit our application and return zero thus closing off the program.

int main(void) 

		pspDebugScreenSetXY(0, 0);
		printf("Hello World!");


	return 0;

Now if you are using an IDE that can also compile your PSP programs, you can hit compile and put the "EBOOT.PBP" in a folder on your PSP, and then run it. If on the other hand you choose to do things manually, then we will have to create the Makefile before compiling.

Makefile[edit | edit source]

So... create a "Makefile" file (no extension) in your project's directory and open it up in your favorite text editing application.

OBJS=main.o ../common/callback.o

CFLAGS=-G0 -Wall -O2
CXXFLAGS=$(CFLAGS) -fno-exceptions -fno-rtti




PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

Compile the program by using the word “make” and... sign it! :)

Signing your program (Linux)[edit | edit source]

Yes, with the release of Geohot's root signing keys, any PSP can run only signed applications. So, you must have a program which you will force sign your application. :)

I use PSCrypter. Download "PSCrypter Signed 2.0", extract it somewhere and make.

If you got error sort of "unknown command psp-config" then export pspdev path:

export PATH=<pspdev_root>/bin:$PATH

Next, copy entire PSCrypter folder (which you extracted) to <your_psp_root>/PSP/GAME/ and move your EBOOT.PBP to "sign" folder there. Go to "Memory Stick" on your PSP and run PSCRYPTER. Wait...

When PSP will reboot rename EBOOT_Signed.PBP in "sign" folder to EBOOT.PBP. Create any folder in <your_psp_root>/PSP/GAME/ (e.g. "hello_world") and move EBOOT.PBP there.

Now you can run own first PSP program! ;)

Once you're done with this you can proceed to the next tutorial.