PSP Programming/General/Hello World
Hello World!
editNow 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
editWe'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
PSP_MODULE_INFO("Hello World", PSP_MODULE_USER, VERS, REVS);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
PSP_HEAP_THRESHOLD_SIZE_KB(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)
{
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, 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
editSo... create a "Makefile" file (no extension) in your project's directory and open it up in your favorite text editing application.
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
Compile the program by using the word “make” and... sign it! :)
Signing your program (Linux)
editYes, 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.