OK, so it seems like most people here want a simple and basic tutorial on how to create their own homebrew. I will now start giving out lessons here using OSlib on how to begin creating homebrew. I will start with just the basics on displaying "hello World" on your PSP and then move up to more advanced homebrew. All of these lessons will use the library OSlib so make sure you have that library installed (check my first post in this thread). Using this library will make creating homebrew a LOT more simplier then using just the standard PSPSDK.
Lesson 1: Displaying HelloWorld on your PSP.
First of all, create a new directory. It will contain the files of your project. In this directory, we will create a
makefile (it's a text file describing our project, in order to know which compiler to use, which files to compile, which libraries to use, and which file to produce in the end).
The Makefile is a file named Makefile (without extension). Here is the Makefile we will use for our first lesson:
Code:
TARGET = Donkey_Lesson1
OBJS = main.o
INCDIR =
CFLAGS = -G4 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
STDLIBS= -losl -lpng -lz \
-lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
LIBS=$(STDLIBS)$(YOURLIBS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Donkey_Lesson1
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Ok, lets talk about the Makefile.
Look at the first line
TARGET = Donkey_Lesson1. That is the name of our project. You can change it to whatever you would like.
Then, there is
OBJS = main.o. That tells what object files are to be created, that mean files to be compiled. Files that will be created have the extension .o (it is the result of the compilation of .c or .cpp files), that's why I wrote main.o and not main.c.
The line
YOURLIBS = defines your own libraries to be added to the project.
PSP_EBOOT_TITLE is the name which will appear to the PSP game selection menu.
For the other lines in the makefile, you do not need to worry or change them, except when you want to use another library.
If you simply want to add OSLib to an already existing project, you just have to add
-losl to your libraries list. However you have to make sure that all the system libraries on which OSLib depends are included, and placed in this order (otherwise you will get errors at linking stage):
Quote:
|
-losl -lpng -lz -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
|
Now, here is the source file for our first lesson:
Code:
//OSlib header file
#include <oslib/oslib.h>
//callbacks
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int main()
{
//Initialization of the Oslib library
oslInit(0);
//Initialization of the graphics mode
oslInitGfx(OSL_PF_8888, 0);
//Initialization of the text console
oslInitConsole();
//Print on the screen this text
oslPrintf("Hello World");
//Wait for a button to be pressed
oslWaitKey();
//terminate the program
oslEndGfx();
oslQuit();
return 0;
}
Source code Explanation:
1) #include <oslib/oslib.h>
You must include this in all of your programs that use OSlib.
2) PSP_MODULE_INFO (“OSLib Sample”, 0, 1, 1);
PSP_MAIN_THREAD_ATTR (THREAD_ATTR_USER | THREAD_ATTR_VFPU);
This code is necessary for the PSPSDK to run the EBOOT that will be made by our program.
3) oslInit (0);
void oslInit(int useOwnCallbacks);
This line of code takes care of all your PSP callbacks. Normally, without this library, you would have to setup and initialize your callbacks with every single PSP program. With this line of code, you don't need to worry about the callback initialization, as long as the value 0 is between the parenthesis
(). If you want to use your own callbacks (if you do not know what that is, do not change it, of course), type 1 in the parenthesis.
4) oslInitGfx (OSL_PF_8888, 0);
void oslInitGfx(int pixelFormat, int bDoubleBuffer);
This is used to initialize the graphic part, by specifying which
pixelformat you want to use on the screen, as well as if you want to use double buffering. Default 0 is used for single buffereing and 1 for double buffereing. We will talk about later what are pixelFormats, for the time being simply use
OSL_PF_8888 for a 32-bit screen (2^32 = 16,777,216 colors) or
OSL_PF_5650 for a 16-bit screen (2^16 = 65,536 colors) as an argument for
pixelFormat.
5) oslInitConsole ();
This initialize the text part of the PSP, to be able to draw some text (the standard Sony font is loaded at this moment).
6) oslPrintf (“Hello World”);
This prints on the screen like the good old code
printf, with the same use (
oslPrintf (“%i”, variable) to post the contents of an integer variable for example)
You can decide where you would like your text to be placed on the screen with a
oslPrintf_xy (X, y, “text”) with
X and
Y as the coordinates in pixels.
7) void oslEndGfx();
This ends the graphics part of the library. You can also reset it with other parameters.
8) oslQuit ();
Quits the game immediately. You'll go back to the PSP game menu.
9) return 0;
Always used at the end of
main()
So that is the basics of creating your first homebrew displaying helloworld. I tried to keep it as simple and basic as possible. Try changing the text and try placing your text in different areas of your screen to learn more about this lesson.
In the next lesson, "lesson 2" (awesome name, eh? :P), I will talk about controller inputs and how to use the PSP buttons.