Google

Lesson 05

Onwards and Upwards

More PSP Programming methods including overclocking, colors, and graphics based text.

This is the second part of Lesson 05; if you haven't completed the first part, do that now.

So now that we have it all set up, we get to the meat of the program, the main() function.
int main(void) {
          scePowerSetClockFrequency(333, 333, 166);
This is the line that sets the clock frequency (as should be evident from the function name). You may be wondering why there are three parameters, though. I mean, there's only one processor, right? Wrong. The PSP actually has three processors. The first sets the CPU (the main processor); this is what most of your programs will be running on. The second parameter is the Media Engine. Last I checked, you could only run MIPS Assembly code on this processor. The Media Engine also runs at 333 MHz. The third parameter controls the Graphics Core. This is what people mean when they talk about using the "GPU." The GPU runs at 166 MHz. The default speeds (if you don't change them yourself) are "222, 222, 111."

Next, we'll set up the screen, this is just like what we did in the last tutorial:
          SetupCallbacks();
          initGraphics();
Then, since we're going to be accepting input, if you'll remember from Lesson 03, we need to define a variable of type SceCtrlData. For old time's sake, we'll name it "pad."
          SceCtrlData pad;
Then we'll set up two more variables and an array:
          int i;
          int selComponent = 0;
          char filler[10];
The integer, "i," will be used in one of our loops later on. The character array is what we will use as a string to ouput some information later in the program. And "selComponent" is what we will use to remember which color component the user is editting.

Next we will declare and initialize three variables that will store the information for our background. A color is composed of three components: Red, Green, and Blue. The maximum value of each in a 32 bit color is 255. Zero of each color is black, 255 of each is white, a combination is anywhere in between. You will sometimes see hex values representing colors. Hex is a base-16 counting system. It goes from 0 to F (F being 16). So, with a 32 bit system, FF would equal 255 (16*16, subtracting one because you start counting at zero). So, white would be "FFFFFF" (255 red, 255 blue, 255 green). Anyway, we'll use three variables to store the background color information:
          int bgR = 0;
          int bgG = 0;
          int bgB = 0;
Our background is now black. Remember, though, this is just storing the information so that we can manipulate it. We won't actually set the screen's background to black until we do something with these variables.

Now, since we are going to be displaying text through functions in the "graphics.h" file rather than by pspDebugScreenPrintf, we need to tell our program what colors we want to use for the text.
          Color highlightColor = RGB(200, 200, 200);
          Color dimmedColor = RGB(100, 100, 100);
          Color shadowColorH = RGB(55, 55, 55 );
          Color shadowColorD = RGB(55, 55, 55 );
First of all, I'll explain what exactly these lines are doing. They are using the RGB macro that was explained in Lesson 04 to turn color components into a single color. The "Color" datatype is defined in the "graphics.c" include file. You may also see a u32 (a 32 bit integer) used in some programs to hold a color.

The reason we have four variables is because we want to highlight the component that the user is currently changing. So, we have two main colors for that, one color for the text that is highlighted and one color for the text that is dimmed. Also, since we have a dynamic background (meaning that it can change), we are going to use a shadow. This will help make our text stand out from the background. I tried a few different colors and this is what I ended up with. Feel free to play around with the colors and see if you find anything that looks better.

Now we'll go into our game loop.
          while(1) {
                    sceCtrlReadBufferPositive(&pad, 1);
A standard, infinite while loop and a standard control pad read.

Go to the third part of this tutorial to continue your program.
Home | Lesson 01 | Lesson 02 | Lesson 03 | Lesson 04 | Lesson 05 [ 1, 2, 3, 4, 5 ] | Lesson 06