• Steam recently changed the default privacy settings for all users. This may impact tracking. Ensure your profile has the correct settings by following the guide on our forums.

Header Files

Revenger

New Member
Hey guys :)

I have a question to PSP Programming.
How do I know which Header File I have to include?
For example if I have functions that try to read out which PSP Model I have:

Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <some other headers for sceKernelGetModel() and kuKernelGetModel().h>

#define printf pspDebugScreenPrintf
PSP_MODULE_INFO("Homebrew", 0, 1, 1);

PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

int main(int argc, char *argv[])
{
   pspDebugScreenInit();

   int kuKernelGetModel(void);

   if(kuKernelGetModel() == 0)
   {
      printf("It's a Classic");
   }
   else if(kuKernelGetModel() == 1)
   {
      printf("It's a Slim");
   }
   else if {kuKernelGetModel() == 2)
   {
      printf("It's a Brite");
   }
   else if (kuKernelGetModel() == 4)
   {
      printf("It's a PSPgo");
   }
   else
   {
      printf("Unknown PSP type");
   }
}

   return 0;
}

Which Header File do I need besides pspkernel.h and pspdebug.h?
And how do I have to edit the makefile then?

Hope you understood my question and can help me :)

Revenger
 

Hellcat

Contributor
Usually the documentation of the function(s) you're using also (should) tell you what header file to include.
In cases like on PSP dev, where you feel uber lucky if you have ANY documentation at all ;) it's looking through everything you got and hunt for it - a tool that searches for a phrase in multiple files/folders becomes really handy here.

In case of the ku*() func's it's sysctrl.h IIRC.
Definitaly one from the M33 SDK, scan through those.

(The M33 SDK "bundled" in one of the earlier M33 releases IIRC....)


Semi-OT sidenote:
I (and this is only my personal opinion, not some written rule or something :)) find it to be "good practice" to not use/depend on functions specific to a certain CFW version / release / whatever but rather try to do all that with own code.
Makes your apps more compatible with HENs and any other future ways that might be found to run your app.

Just my 2ct :)
 

Revenger

New Member
Hey Hellcat,
first of all thanks for your answer :)

But I have to say: I began recently to program for the PSP and there are many things I didn't really understand, so I hope you don't mind if I have some questions for you :(

I just downloaded the 4.01 M33 SDK and there are the folders ,,include" and ,,lib" (there are two more folders, but I don't think I'll need them ,,psp-packer" and ,,samples"). In the include folder there is the kubridge.h and also the systemctrl.h. But my question is, where do I have to copy these two files? Do I have to copy them to my project folder? Or do I have to copy the whole ,,include"-folder to my project folder? And do I need the ,,libs"-folder?

Is that how my source code shoud look like then:

Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <systemctrl.h>
#include <kubridge.h>

#define printf pspDebugScreenPrintf
PSP_MODULE_INFO("Homebrew", 0, 1, 1);

PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

int main(int argc, char *argv[])
{
   pspDebugScreenInit();

   int kuKernelGetModel(void);

   if(kuKernelGetModel() == 0)
   {
      printf("It's a Classic");
   }
   else if(kuKernelGetModel() == 1)
   {
      printf("It's a Slim");
   }
   else if {kuKernelGetModel() == 2)
   {
      printf("It's a Brite");
   }
   else if (kuKernelGetModel() == 4)
   {
      printf("It's a PSPgo");
   }
   else
   {
      printf("Unknown PSP type");
   }
}

   return 0;
}

And how do I have to change my makefile then?

Code:
TARGET = Homebrew
OBJS = main.o

INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)


LIBDIR =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Homebrew

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

I know that in the makefiles there is a line called
LIBS = -....
but I don't know what to include there :(
And do I need the ,,lib" folder for that?

I (and this is only my personal opinion, not some written rule or something ) find it to be "good practice" to not use/depend on functions specific to a certain CFW version / release / whatever but rather try to do all that with own code.
Makes your apps more compatible with HENs and any other future ways that might be found to run your app.

So you mean the kubridge function is only for a certain CFW and not for all CFW's?
And you say that I should do it with my own code, but how can I write the kubridge function in my own code?

I hope you aren't angry because of those many questions but I really googled hard, but couldn't find really helpful sites that explain those things good.

Revenger
 

Hellcat

Contributor
Hm, you should get a book on basic C/C++ programming.

To make a long story short, basically you can put the .h files wherever you want, just refer to the proper path in the #include statement.
Usually those are copied into the project folder, yes, and the referenced with a simple #include "whatever.h" (notice the filename is enclosed with quotes (") not those arrory-brackets (< and >) so the complier looks relative to the project dir and not the global include dir.
Then again you could also place them into your global include dir.... choices, choices.... ;)

The libs you need.... well, when linking them into your final binary, and yes, to do so list them in the "LIBS =" line in the makefile.

Which brings us to the most important folder of them all, the one you totally underestimated:
SAMPLES

In there you can see how everything is used (incl. the MakeFile for libs and w/e else)
 

Revenger

New Member
no it isn't, your just now dealing with the psp api implementation

I don't know what api implementation is, but I mean there are other Header Files and you have to learn what they mean. And when you program with the PC you just include the headerfiles and can then begin with int main() but in PSP Programming you have to write also things like that:

// 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;
}

So that's everything new and weird to me.

Revenger
 

slicer4ever

Coding random shit
api = application programming interface

also, technically, you don't have to do any of that, your only registering the callbacks so you can use the home button

if this is already weird to you, then you probably shouldn't be diving into psp programming just yet, while being new to using the psp's sdk is fine and dandy, if your beginning to think this is a "different" c, then you need to go back to learning some of the basics of c

in short, c is the same, the function's your using are different is all
 

yanmoyiie

New Member
Usually the documentation of the function(s) you're using also (should) tell you what header file to include.
In cases like on PSP dev, where you feel uber lucky if you have ANY documentation at all ;) it's looking through everything you got and hunt for it - a tool that searches for a phrase in multiple files/folders becomes really handy here.

In case of the ku*() func's it's sysctrl.h IIRC.
Definitaly one from the M33 SDK, scan through those.

(The M33 SDK "bundled" in one of the earlier M33 releases IIRC....)


Semi-OT sidenote:
I (and this is only my personal opinion, not some written rule or something :)) find it to be "good practice" to not use/depend on functions specific to a certain CFW version / release / whatever but rather try to do all that with own code.
Makes your apps more compatible with HENs and any other future ways that might be found to run your app.

Just my 2ct :)



Which Header File do I need besides pspkernel.h and pspdebug.h?
 
Top