I am not sure why he was lying in my bed thinking of good games I played. Then I remembered several video games that I had, then came to my head: “Raphael your PSP is in the box. Let’s play a game!”
By the time I turned on my PSP, I realized that most of my games I never bought any them. Do not get me wrong, but when you’re a kid in school it’s a kind of a dream. Then I wondered if I could create something, since the PSP firmware lost the war.
Requirements
You also need to have acquired some knowledge of general programming in the ‘C’ language and a have PSP.
Install tools to develop it in: PSP Toolchain.
Developing
Create a folder named “common”. This folder will contain several files which will often be used in our programs.
callback.h
Create a new file with the name “callback.h”. This header file will declare some info needed.
#ifndef COMMON_CALLBACK_H
#define COMMON_CALLBACK_H
int isRunning();
int setupExitCallback();
#endif
callback.c
Create a new file with the name “callback.c”. Include the file “pspkernel.h” which gives us access to several kernel methods.
#include < pspkernel.h >
Next we create a boolean. Executing the method “isRunning()” will tell us whether a request to exit the application was created by the user. We will use this function in our program so that we can clean up any leftover memory, and exit gracefully.
static int exitRequest = 0;
int isRunning() {
return !exitRequest;
}
Create a new thread, which will create an exit callback. The callback will then make “exitRequest” equal to true if the user presses the “home” or “exit” button on the PSP.
#include < pspkernel.h >
static int exitRequest = 0;
int isRunning() {
return !exitRequest;
}
int exitCallback(int arg1, int arg2, void *common) {
exitRequest = 1;
return 0;
}
int isRunning() {
return !exitRequest;
}
int callbackThread(SceSize args, void *argp) {
int callbackID;
callbackID = sceKernelCreateCallback("Exit Callback", exitCallback, NULL);
sceKernelRegisterExitCallback(callbackID);
sceKernelSleepThreadCB();
return 0;
}
int setupExitCallback() {
int threadID = 0;
threadID = sceKernelCreateThread("Callback Update Thread",
callbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0);
if(threadID >= 0) {
sceKernelStartThread(threadID, 0, 0);
}
return threadID;
}
Hello World!
Let’s create a simple “Hello World!” program.
main.c
Include “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”.
#include < pspkernel.h >
#include < pspdebug.h >
#include < pspdisplay.h >
#include "../common/callback.h"
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. Define “pspDebugScreenPrintf” as “printf” which will allow us to type text on the screen.
#define VERS 1 //Talk about this
#define REVS 0
PSP_MODULE_INFO("Hello World", PSP_MODULE_USER, VERS, REVS);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
PSP_HEAP_SIZE_MAX();
#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). 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.
int main() {
pspDebugScreenInit();
setupExitCallback();
while(isRunning()) {
pspDebugScreenSetXY(0, 0);
printf("Hello World!");
sceDisplayWaitVblankStart();
}
sceKernelExitGame();
return 0;
}
Now if you are using an IDE that can also compile your PSP programs and get the “EBOOT.PBP”. If chose do it manually, then we will have to create the Makefile before compiling.
Makefile
Create a “Makefile” in your project directory.
TARGET = hello_world
OBJS = main.o ../common/callback.o
INCDIR =
CFLAGS = -G0 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lm
BUILD_PRX = 1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE= Hello World
PSPSDK = $(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Run “make”, place the eboot.pbp in a folder on your PSP (no other files needed) and run it.