Lesson 05
Onwards and Upwards
More PSP Programming methods including overclocking, colors, and graphics based text.
This is the third part of Lesson 05; if you haven't completed the first part or the
second part do that now.
Now we'll handle that control pad read. What we want to do is have the up and down arrows select which color component the user is editting. We want the left and right arrows to adjust that color.
The next code block is what controls the left and right arrows:
We're almost done with our program! Keep reading in the fourth part of this tutorial to add toyour program.
Now we'll handle that control pad read. What we want to do is have the up and down arrows select which color component the user is editting. We want the left and right arrows to adjust that color.
if(pad.Buttons & PSP_CTRL_UP) {
if(selComponent > 0) {
selComponent--;
}
for(i=0; i<10; i++) {
sceDisplayWaitVblankStart();
}
} else if(pad.Buttons & PSP_CTRL_DOWN) {
if(selComponent < 2) {
selComponent++;
}
for(i=0; i<10; i++) {
sceDisplayWaitVblankStart();
}
}
This chunk of code does the first half of that. It will decrement the variable if up is pressed (because we want to start from the top, 0 will be the top-most color, 1 will be the middle, and
2 will be the bottom). And it will increment the variable if the down arrow is pressed. The for loops are in there to pause the program for a second when one of the buttons is pressed. This
way, it makes it easier for the user to go through the options one at a time, rather than accidentally scrolling too far.if(selComponent > 0) {
selComponent--;
}
for(i=0; i<10; i++) {
sceDisplayWaitVblankStart();
}
} else if(pad.Buttons & PSP_CTRL_DOWN) {
if(selComponent < 2) {
selComponent++;
}
for(i=0; i<10; i++) {
sceDisplayWaitVblankStart();
}
}
The next code block is what controls the left and right arrows:
if(pad.Buttons & PSP_CTRL_RIGHT) {
switch(selComponent) {
case 0:
bgR++;
break;
case 1:
bgG++;
break;
case 2:
bgB++;
break;
default:
//SHOULD NEVER EXECUTE
break;
}
} else if(pad.Buttons & PSP_CTRL_LEFT) {
switch(selComponent) {
case 0:
bgR--;
break;
case 1:
bgG--;
break;
case 2:
bgB--;
break;
default:
//SHOULD NEVER EXECUTE
break;
}
}
As you look at this code, you're probably asking yourself, "What the *insert naughty word here* is this switch structure?" Well, it's fairly simple. Basically it's like an if/else structure all built
into one. It takes a variable, "switch(yourVariable)," and then compares it to several cases that it could be. If it doesn't match any of the cases, then it runs the default case. In our program, the
"selComponent" variable should only be 0, 1, or 2, since we limited it to that above. In the top switch structure, if "selComponent" equals 0, our variable "bgR" will be incremented by one. If it equals 1,
"bgG" will be incremented by one, and if it equals two, "bgB" will be incremented by one. The break statement exits out of the switch structure.switch(selComponent) {
case 0:
bgR++;
break;
case 1:
bgG++;
break;
case 2:
bgB++;
break;
default:
//SHOULD NEVER EXECUTE
break;
}
} else if(pad.Buttons & PSP_CTRL_LEFT) {
switch(selComponent) {
case 0:
bgR--;
break;
case 1:
bgG--;
break;
case 2:
bgB--;
break;
default:
//SHOULD NEVER EXECUTE
break;
}
}
We're almost done with our program! Keep reading in the fourth part of this tutorial to add toyour program.
