PSP Programming/General/Hello World

Hello World!Edit

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.cEdit

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
 
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) (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()
{       
	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.

MakefileEdit

So... 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”, place the eboot.pbp in a folder on your PSP (no other files needed) and run it. Once you're done with this you can proceed to the next tutorial.

Last modified on 7 November 2013, at 05:35