BUT WHILE I MAKE THEM, HERE GO THE FIRST 7!!
THEY WILL COVER SOME THINGS SUCH AS:
-DEBUG TEXT-
-GRAPHIC TEXT-
-IMAGES-
-MATHEMATIC FUNCTIONS-
-VLF-
-VIDEOS-
-MUSIC-
AS I DON'T HAVE MUCH TIME TO WRITE ALL OF THESE TUTORIALS IN TIME, I WOULD APPRECIATE IT MUCH IF YOU COULD PM ME YOUR TUTORIALS!
THAT WOULD HELP ME MUCH !!!
[TUTORIAL #1] SETUP PSPSDK
[spoiler]first of all, download and install these files:
http://dl.qj.net/dl.php?fid=110027&new=1
http://sourceforge.net/projects/minpspw ... ror=freefr
http://download.tuxfamily.org/notepadpl ... taller.exe
http://subversion.tigris.org/files/docu ... -setup.exe
http://www.mediafire.com/?doaimyfqytm <--install this both on c:/pspsdk & c:/pspdev
http://www.megaupload.com/?d=CQG0XQ9Q <--that goes on c:/pspsdk/psp/sdk/include
then go to c:/pspdev.bat, right click it and press edit. erase everything it writes and paste this and save it
Code: Select all
set path=%path%;C:\pspdev\bin
set PSPSDK=C:\pspdev\psp\sdk
cmd
and type these commands:
Code: Select all
mkdir projects
cd projects
mkdir programming_tutorials
c:/pspdev/projects/programming_tutorials
we will put all of these tutorials in there[/spoiler]
[TUTORIAL #2] HELLO WORLD
[spoiler]create this directory:
c:/pspdev/projects/programming_tutorials/TUT_1_HELLO_WORLD
create these three files in the above dir:
1)main.c
2)makefile
3)build.bat
1)right click main.c and choose edit with notepad++
paste this code and save it:
Code: Select all
//Hello World Program.
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>
PSP_MODULE_INFO("Hello World",0,1,1);
int main() {
pspDebugScreenInit();
pspDebugScreenClear();
SetupCallbacks();
pspDebugScreenprintf("Hello World");
sceKernelSleepThread();
return 0;
}
Code: Select all
//Hello world Program.
then this line is just a comment line and it doesn't affect our programme
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>
they contain pre-written code that we
don't need to write it ourselves.
these command #include makes
the pre-processor copy their code
and paste it into our programme.
pspkernel code is about the main
psp functions. pspdebug has got
some simple debug text functions.
pspcallbacks has functions about
the "grey screen" that exits our programme
when the HOME button is pressed.
Code: Select all
PSP_MODULE_INFO("Hello World",0,1,1);
"hello world" is the name of our project
(NOT THE NAME OF THE EBOOT!!!)
"0,1" is the version
and the final "1" is the programme's mode(user mode)
Code: Select all
int main() {
pspDebugScreenInit();
pspDebugScreenClear();
SetupCallbacks();
pspDebugScreenPrintf("Hello World");
sceKernelSleepThread();
return 0;
}
every C programme. int means integer
and it must return an integer number
at the end of it, in our case 0.
the main function starts with an
{ and ends with an }. inside these symbols
there is the code that our programme will execute.
pspDebugScreenInit initializes the debug
screen and it is pre-defined in pspdebug.h.
pspDebugScreenClear clears the debug screen.
setupcallbacks initializes the "gre" exit
screen. pspDebugScreenPrintf prints a message to the screen.
the message must be inside the ("").
sceKernelSleepThread "freezes" our programme so that
it won't exit. return 0 is there because of the -->int main<--
some functions have got arguements inside the parenthesis, some of them not,
because they just don't need them.
all of the functions end with a ";"
C language is case-sensitive, so watch out
for the "Caps Lock mistakes"
2)edit with notepad++ the makefile and paste this:
Code: Select all
#one-line comment
TARGET = hello
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
#EXTRA_TARGETS is the output file
#PSP_EBOOT_TITLE is the EBOOT's name
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Code: Select all
make
an EBOOT.PBP will be created in this directory
copy it at X:/PSP/GAME/XXX[/spoiler]
[TUTORIAL #3] VARIABLES
[spoiler]if you have successfully compiled
and run the hello world programme, now it's
time to do something more fun
we will create a programme that will
handle variables. ok!!! no more talks!!!
let's start programming!!!
create the following directory:
c:/pspdev/projects/programming_tutorials/TUT_2_VARIABLES
then, create main.c, makefile and build.bat in there.
build.bat and the makefile are the same with the previous tutorial,
but change only this line at the makefile:
Code: Select all
PSP_EBOOT_TITLE = Variables
paste this code:
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>
PSP_MODULE_INFO("Variables",0,1,1);
int var1 = 100;
float var2 = 5.2525;
char var3[7] = "Hello!";
int main() {
pspDebugScreenInit();
pspDebugScreenClear();
SetupCallbacks();
pspDebugScreenPrintf("%d\n", var1);
pspDebugScreenPrintf("%f\n", var2);
pspDebugScreenPrintf("%s\n", var3);
pspDebugScreenPrintf("All of them together: %d %f %s", var1, var2, var3);
sceKernelSleepThread();
return 0;
}
Code: Select all
int var1 = 100;
float var2 = 5.2525;
char var3[7] = "Hello!";
the first one is an integer,
its name is var1 and its value is 100.
the second one is a decimal,
its name is var2 and its value is 5,2525.
the third one is a string.
its value ("hello!") has got 6 characters,
so we must create them. but we must always use one
more, because it is used by a terminal.
so, we create a string with 7 characters.
(one char = one char
many chars = one string)
in C, there is no type of variable named string, so
we must use multiple characters in order to
manually create a string .
Code: Select all
pspDebugScreenPrintf("%d\n", var1);
pspDebugScreenPrintf("%f\n", var2);
pspDebugScreenPrintf("%s\n", var3);
pspDebugScreenPrintf("All of them together: %d %f %s!!!", var1, var2, var3);
%f is for float
%s is for string [/spoiler]
[TUTORIAL #4] CALCULATIONS
[spoiler]create this directory:
c:/pspdev/projects/programming_tutorials/TUT_3_CALCULATIONS
let's create a simple calculator
makefile is the same with the previous tuts, except the eboot name and build.bat is also the same.
now open main.c and paste the following code:
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>
PSP_MODULE_INFO("Calculations",0,1,1);
int x = 100;
int y = 100;
int result;
int main() {
pspDebugScreenInit();
pspDebugScreenClear();
SetupCallbacks();
pspDebugScreenPrintf("x = %d\n", x);
pspDebugScreenPrintf("y = %d\n", y);
pspDebugScreenPrintf("Please wait...\n");
sceKernelDelayThread(5*1000*1000);
result = x + y;
pspDebugScreenPrintf("result = %d", result);
sceKernelSleepThread();
return 0;
}
Code: Select all
pspDebugScreenPrintf("x = %d\n", x);
pspDebugScreenPrintf("y = %d\n", y);
pspDebugScreenPrintf("Please wait...\n");
sceKernelDelayThread(5*1000*1000);
result = x + y;
pspDebugScreenPrintf("result = %d", result);
The value of x is printed.
The value of y is printed below of the value x.
A "please wait" message is printed in order to make
our programme look like more professional xD
The programme freezes for 5 seconds(5.000.000 ms)
the result value gets equivalent to the value of x + y
the result value is printed below "please wait..."
You can also do these calculations:
result = x - y;
result = x * y;
result = x / y;
try them all and compile different eboots, each one ofr each calculation !!![/spoiler]
[TUTORIAL #5] BUTTON INPUT
[spoiler]first, create this directory:
c:/pspdev/projects/programming_tutorials/TUT_4_BUTTON_INPUT
makefile and build.bat are the same with previous tuts, except the eboot name
Code: Select all
#include <pspdebug.h>
#include <pspkernel.h>
#include <pspcallbacks.h>
#include <pspctrl.h>
PSP_MODULE_INFO("Button Input",0,1,1);
int main() {
pspDebugScreenInit();
pspDebugScreenClear();
SetupCallbacks();
SceCtrlData pad;
pspDebugScreenPrintf("Press X or O or /\ or []!!! :D");
while(1) {
pspDebugScreenSetXY(0, 0);
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CIRCLE)
{pspDebugScreenPrintf("Circle pressed\n"); }
if (pad.Buttons & PSP_CTRL_CROSS)
{pspDebugScreenPrintf("Cross pressed\n"); }
if (pad.Buttons & PSP_CTRL_SQUARE)
{pspDebugScreenPrintf("Square pressed\n"); }
if (pad.Buttons & PSP_CTRL_TRIANGLE)
{pspDebugScreenPrintf("Triangle pressed\n"); }
}
return 0;
}
Code: Select all
#include <pspctrl.h>
Code: Select all
SceCtrlData pad;
Code: Select all
while(1) {...}
it repeates itself over and over again
Code: Select all
pspDebugScreenSetXY(0, 0);
sceCtrlReadBufferPositive(&pad, 1);
the second one is always used when we call controller functions inside a loop.
Code: Select all
if (pad.Buttons & PSP_CTRL_CIRCLE)
{pspDebugScreenPrintf("Circle pressed\n"); }
If you want to use other PSP buttons, here are they:
Code: Select all
RTRIGGER
LTRIGGER
HOME
SELECT
NOTE
START
[TUTORIAL #6] IMAGE LOADING
[spoiler]IN THIS TUTORIAL, WE WILL LOAD AN IMAGE!
WE WILL USE THE CODE FROM http://www.psp-programming.com
first open c:/pspdev/pspdev.bat and type in these commands:
Code: Select all
svn checkout http://psp.jim.sh/svn/psp/trunk/zlib
cd zlib
make
make install
cd
rm -Rf zlib
cd ..
svn checkout http://psp.jim.sh/svn/psp/trunk/libpng
cd libpng
make
make install
cd
rm -Rf libpng
congrats!!! you have successfully installed zlib and libpng!!!
now exit the pspdev.bat and create this directory:
c:/pspdev/projects/programming_tutorials/TUT_5_IMAGE_LOADING
inside this dir, create an image called "image.png"
and draw at it whatever you want. then, save it!
it's size must be 480x272.(just like the psp screen )
then download this archieve:
http://www.psp-programming.com/tutorials/c/lesson04.zip
and extract everything
inside this dir, except for ourimage.png.
then create main.c and paste there this code:
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspcallbacks.h>
#include "graphics.h"
PSP_MODULE_INFO("Image Example",0,1,1);
int main() {
SetupCallbacks();
initGraphics();
Image* background = loadImage("Background.png");
blitAlphaImageToScreen(0,0,480,272,background,0,0);
flipScreen();
sceKernelSleepThread();
return 0;
}
Code: Select all
#include "graphics.h"
the same directory with the EBOOT. this header
files has got functions about image
processing.
Code: Select all
initGraphics();
Code: Select all
Image* ourimage = loadImage("image.png");
point to a specific memory address. In this line we load an image
called ourimage and it is named "image.png".
Code: Select all
blitAlphaImageToScreen(0,0,480,272,ourimage,0,0);
the first two zeroes are the starting x and y of
the image. the next two numbers are the length and the width.
then is is the image variable and the final zeroes indicate where
do we want to put the image start position.
Code: Select all
flipScreen();
here goes the makefile:
Code: Select all
TARGET = image
OBJS = main.o graphics.o framebuffer.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBS = -lpspgu -lpng -lz -lm
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Image
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
now, build it and put the image and the eboot at:
X:/PSP/GAME/XXX[/spoiler]
[TUTORIAL #7] PLAYER MOVEMENT
[spoiler]Now, let's create a moving player...
Open up pspdev.bet and type in:
c:/pspdev/projects/programming_tutorials/TUT_6_PLAYER_MOVEMENT
exctract the archieve from the previous tut in there and delete ourimage.png
create main.c , makefile and build.bat
paste this at build.bat:
Code: Select all
make
open main.c and paste this code:
Code: Select all
#include <pspkernel.h>
#include <pspcallbaks.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include "graphics.h"
#define prints printTextScreen
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
PSP_MODULE_INFO("Movement Example",0,1,1);
int main() {
initGraphics();
SetupCallbacks();
SceCtrlData pad;
int x = 100;
int y = 100;
Image* player = loadImage("Player.png");
Image* background = loadImage("Background.png");
Color white = RGB(255,255,255);
while(1) {
sceCtrlPeekBufferPositive(&pad, 1);
clearScreen(white);
blitAlphaImageToScreen(0,0,480,272,background,0,0);
blitAlphaImageToScreen(0,0,32,32,player,x,y);
if(pad.Buttons & PSP_CTRL_UP) {
y--;
}
if(pad.Buttons & PSP_CTRL_DOWN) {
y++;
}
if(pad.Buttons & PSP_CTRL_RIGHT) {
x++;
}
if(pad.Buttons & PSP_CTRL_LEFT) {
x--;
}
prints(0,0,"This shows you how to print text",white);
flipScreen();
}
return 0;
}
Code: Select all
#define prints printTextScreen
printTextScreen is a function in graphics.h
Code: Select all
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
Code: Select all
Color white = RGB(255,255,255);
Code: Select all
clearScreen(white);
Code: Select all
blitAlphaImageToScreen(0,0,32,32,player,x,y);
REMEMBER! movement
Code: Select all
if(pad.Buttons & PSP_CTRL_UP) {
y--;
}
if(pad.Buttons & PSP_CTRL_DOWN) {
y++;
}
if(pad.Buttons & PSP_CTRL_RIGHT) {
x++;
}
if(pad.Buttons & PSP_CTRL_LEFT) {
x--;
}
Code: Select all
prints(0,0,"This shows you how to print text",white);
print to screen(at position x=0, y=0, "the text i want to print", desired color);
easy, ain't it???
COMPILE IT AND RUN IT ON UR PSP [/spoiler]