1. Welcome to the eXophase.com forums!

    It looks like you're enjoying our site but haven't created an account yet. Why not take a minute to register for your own free account now?

    By joining, you will have access to post topics, browse threads ad-free, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

C Header Files

Discussion in 'Division by Zero' started by Revenger, Dec 26, 2010.

  1. Revenger

    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
  2. Hellcat

    Hellcat Staff Member Staff 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 :)
  3. Revenger

    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
    but I don't know what to include there :(
    And do I need the ,,lib" folder for that?

    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
  4. Hellcat

    Hellcat Staff Member Staff Member

    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)
  5. Revenger

    Revenger New Member

    Alright, thanks Hellcat :)

    Yeah, I allready have a C Book, but C for PSP is a little bit different.

    Revenger
  6. slicer4ever

    slicer4ever Coding random shit

    Last played:
    GTA V on Xbox 360
    no it isn't, your just now dealing with the psp api implementation
  7. Revenger

    Revenger New Member

    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:

    So that's everything new and weird to me.

    Revenger
  8. slicer4ever

    slicer4ever Coding random shit

    Last played:
    GTA V on Xbox 360
    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
  9. yanmoyiie

    yanmoyiie New Member



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

    MenaceInc Staff Member Staff Member

    Last played:
    DARK SOULS on Xbox 360
    ...not sure if subtle spam bot or troll... removed links either way.
  11. slicer4ever

    slicer4ever Coding random shit

    Last played:
    GTA V on Xbox 360
    defiantly spam bot.

Share This Page

Style eXophase Default