PSPlayground Forum Index PSPlayground
Welcome to PSPlayground
 

Hello World:

 
       PSPlayground Forum Index -> PSP tutorials
Author Message
2.6,CRACKED!



Sun Apr 02, 2006 8:22 pm   Hello World:  

Hello World:

Probably all languages in the world, start with a simple hello world script. Here's mine.

First of all we could do with some comments; if you want them (for source codes mainly)

/*

* Author:

* Date:

* Program made:

*/

We need to use some 'include files' so that the psp can do it stuff!

#include <pspkernel.h>
#include <pspdebug.h>

This displays the version numbers (this is optional)

PSP_MODULE_INFO("Hello World", 0, 1, 1);

We now define what printf means, hard to explain the rest.

#define printf pspDebugScreenPrintf
We now exit the callback
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}

We now Callback the thread

int CallbackThread(SceSize args, void *argp) {
int cbid;

cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);

sceKernelSleepThreadCB();

return 0;
}

Sets up the callback thread and returns its thread id

int SetupCallbacks(void) {
int thid = 0;

thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}

return thid;
}

Now we have made all the other functions we now say create main function, include a pspDebugScreen, include the made Callbacks and print to the PSP screen via printf, (you can change the Hello World part to whatever).

int main() {
pspDebugScreenInit();
SetupCallbacks();
printf("Hello World");

sceKernelSleepThread();
return 0;
}

Now this is what it looks like;

/*

* Author:

* Date:

* Program made:

*/

#include <pspkernel.h>
#include <pspdebug.h>

PSP_MODULE_INFO("Hello World", 0, 1, 1);

#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;

cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);

sceKernelSleepThreadCB();

return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;

thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}

return thid;
}

int main() {
pspDebugScreenInit();
SetupCallbacks();
printf("Hello World");

sceKernelSleepThread();
return 0;
}

DOWNLOAD HERE:


http://www.freewebs.com/psp_homebrew/helloworld.c
 
Admin



Sun Apr 02, 2006 8:40 pm    

Again very usefull thread :wink:
 
 
       PSPlayground Forum Index -> PSP tutorials
Page 1 of 1


This page is a free forum hosting archive page from a ForumWise free forum.
Powered by phpBB ©