Lesson 02
Setting up the Development Environment
The setup, creation, and execution or a "Hello World"
Here comes the third part of Lesson 02. Parts one and two
are prerequisites, so go back and hit those first before you come back and complete this part. Here it goes.
We now need to add two lines to set up the screen and to use those functions that we put in earlier (which you didn't need to know how they worked). Even though you don't need to know how those functions worked, it is important to grasp the concept of how to call functions. It is actually very simply. You just put the function name with parenthesis at the end (and if it takes any parameters, you put those in the parenthesis, but we'll cover that later).
Every line in your program will need a semicolon at the
end. The reason for this is because the compiler does not see any white space. Between lines, you could have 100 empty lines, and
the compiler wouldn't care. This is useful because it allows you to format your code how you want, in a way that you can understand.
You can group lines together, or do whatever you want with your white space. But, in turn, to end a line, you need a semicolon. So
add these two lines to your program to set it up:
Put the following in your Makefile:
Now open up a CYGWIN Bash Shell and "cd" into your "projects/helloworld" directory. Type "make" and your shell should output some stuff to you. It will tell you if your source code had any errors that made it uncompilable. Generally, if it gives you a few warnings, it's not a big deal. Errors are what you want to watch out for, warnings are just possible points that could cause bugs. Note: if you have Firmware Version 1.50, you can automatically generate your two folders by typing "make kxploit" instead of "make."
If you didn't have any errors, congratulations! You have successfully created and compiled your first application for the PSP. I'll bet you're dying to test it out. So, put "C:/cygwin/home/yourUserName/projects/helloworld/EBOOT.PBP" on your PSP just like you would any other homebrew application, and try it out for yourself!
Check out Lesson 03 to learn more about programming for the PSP, such as if/then statements, variables, loops, and button input.
Be sure to add the feed to your RSS Aggregator (or Google Homepage, or Firefox Live Bookmark) to stay updated with the latest tutorials.
If you have enjoyed this tutorial and have a spare buck or two, please consider donating to the author. Or, if you have a website, link to this tutorial series (helping spread the word means more homebrew for all!).
If there's a calling, I will consider making more tutorials. Please contact me with your feedback on the tutorials and on what you'd like to see in the next lessons. My AIM is Yeldarb2k3, and my e-mail is Yeldarb [at] Barbdwyer [dot] com. Also, if you are looking for someone to design you a website, please contact me through my site, Barbdwyer Web Design.
We now need to add two lines to set up the screen and to use those functions that we put in earlier (which you didn't need to know how they worked). Even though you don't need to know how those functions worked, it is important to grasp the concept of how to call functions. It is actually very simply. You just put the function name with parenthesis at the end (and if it takes any parameters, you put those in the parenthesis, but we'll cover that later).
pspDebugScreenInit();
SetupCallbacks();
Now it's time to write some code that we will actually be able to see the results of. Remember when we defined "pspDebugScreenPrintf"
as "printf?" Well, now it's time to use that function. The way that we will print text to the screen is by calling the "printf"
function with a parameter (I told you we'd cover it later.) A parameter is a variable that you can pass to a function for it to use.
These will come in handy later when you're writing your own functions. So, for "printf" to output to the screen, we need to pass a
string to it. We will output "Hello World" by passing that string to the function. "Printf" is a powerful function because you can
also use it to output other variables to the screen. We would pass these as other parameters, but that will all come in due time.
For now, we will just print out "Hello World" to the screen, like so:
SetupCallbacks();
printf("Hello World");
And there it is, you have told "printf" to output to the screen. Now we just need to finish some things up and then our source code
will be ready to build. We need to pause our program so that we can see the output. If we don't, it will just either freeze, or
return you to the PSP Menu. You will never even get to see your beautiful phrase outputted to the screen because it will be erased
so fast. So, add this line to pause the program until the "Home" button is pushed and the user is sent back to the PSP Operating
System.
sceKernelSleepThread();
Now we need to give our function a return value, since when we defined it ("int main()"), we told the compiler that it would
return an integer. So just return a '0' (that's a zero, not a capital 'o') by doing this:
return 0;
And finally, end the function by putting in a closing bracket:
}
And that's it for the program! Now we just have to tell the compiler how we want this project compiled by creating a Makefile. So
create a new file called "Makefile" with no extention (ie, no .txt). Once you've done this, open it up in your text editor.Put the following in your Makefile:
TARGET = hello
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
You can use this Makefile as a basis for all of your simple projects. Sometimes you will need to add libraries or whatnot to
this file, but for now it is fairly simple. It basically just tells your compiler to take "main.c" and build it using the
PSPSDK into a .pbp file that your PSP can read. What you will need to change if you use this Makefile in other projects is
where it says "PSP_EBOOT_TITLE = Hello World." You can change where it says "Hello World" to the title of your program, this
is the name that will appear on the PSP Game Menu when you select the file.OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Now open up a CYGWIN Bash Shell and "cd" into your "projects/helloworld" directory. Type "make" and your shell should output some stuff to you. It will tell you if your source code had any errors that made it uncompilable. Generally, if it gives you a few warnings, it's not a big deal. Errors are what you want to watch out for, warnings are just possible points that could cause bugs. Note: if you have Firmware Version 1.50, you can automatically generate your two folders by typing "make kxploit" instead of "make."
If you didn't have any errors, congratulations! You have successfully created and compiled your first application for the PSP. I'll bet you're dying to test it out. So, put "C:/cygwin/home/yourUserName/projects/helloworld/EBOOT.PBP" on your PSP just like you would any other homebrew application, and try it out for yourself!
Check out Lesson 03 to learn more about programming for the PSP, such as if/then statements, variables, loops, and button input.
Be sure to add the feed to your RSS Aggregator (or Google Homepage, or Firefox Live Bookmark) to stay updated with the latest tutorials.
If you have enjoyed this tutorial and have a spare buck or two, please consider donating to the author. Or, if you have a website, link to this tutorial series (helping spread the word means more homebrew for all!).
If there's a calling, I will consider making more tutorials. Please contact me with your feedback on the tutorials and on what you'd like to see in the next lessons. My AIM is Yeldarb2k3, and my e-mail is Yeldarb [at] Barbdwyer [dot] com. Also, if you are looking for someone to design you a website, please contact me through my site, Barbdwyer Web Design.
