Programming for PSP: Part I, compiler setup

    Let's agree right away: I follow the pattern of “learning by learning”, i.e. I teach, while simultaneously studying, overtaking readers by 2-3 "steps" forward. However, this does not mean that I do not know anything and all that I say is ordinary copy-paste: I try to understand the topic before writing about it. Therefore, feel free to ask questions, this will benefit both yourself and me: for questions for which I do not know the answer, I will look for it, recognize it and tell you.

    So, in this topic there will be a short story about how to compile and run the first program on your console. Just a warning: an article on the mega-technical plan, almost all of the content concerns the tedious, but quick setup of the compiler, and as a result you get only the banal “Hello World”. However, without it in any way.

    We will assume for granted that you have a Sony PSP prefix, flashed to the latest version - 3.90 M33-3 (the so-called custom firmware, unofficial firmware). Many have already talked about how to reflash, and I will not dwell on this. We will also assume that a flash drive is inserted in your brick, on which there is at least 50kb of free space, and you have access to them (for example, through the PSP itself).

    I will say right away: I’m almost sure that nothing bad will happen to your prefix if you are careful enough, but, unfortunately, I can’t give any guarantees.

    The programming language used is C, I will use the free IDE Code :: Blocksunder Windows XP. Users of other compilers or the OS can try to configure the IDE themselves, fortunately, the settings are similar for everyone; I used what I found the manual for;)

    First, download a set of compilers, linkers and libraries for PSP called DevKitPSP . Unzip it somewhere, I unzipped it to the root of the E: drive (now I have the E: \ devkitpsp \ folder).

    Now open Code :: Blocks. In the menu, select Settings → Compiler and Debugger, as Selected Compiler in the window that opens, select GNU GCC (it should be by default), copy it, calling, for example, DevKitPSP, and configure it:

    Search Directories → Compiler tab (delete everything that is there there, and click Add to add each of the paths):
    E: \ devkitPSP \ include
    E: \ devkitPSP \ psp \ include
    E: \ devkitPSP \ psp \ sdk \ include
    E: \ devkitPSP \ lib
    E: \ devkitPSP \ psp \ lib
    E: \ devkitPSP \ psp \ sdk \ lib

    Toolchain Executables Tab:
    Compiler's installation directory: E: \ devkitPSP. There is a note that there should be a bin subfolder in this folder, check.
    C-compiler: psp-gcc.exe
    C ++ - compiler: psp-g ++.
    Linker for static libs: psp- g ++. Exe Linker for static libs: psp-ar.exe
    I left three more fields empty.

    Now you can press OK, and proceed to creating a new project (File → New → Project ..., on the left in the window click Projects and select Empty). We fill in the Project Title (it does not matter, let it be PSPHelloWorld), do not forget to put a folder to save the project (I forgot the first time, and got a bunch of glitches and errors); We, of course, put the compiler freshly created by us.

    Our project is virgin empty, create a file (File → New → File ..., I don’t give a damn about the name, I selected main.c) - do not forget to select the C language in the file creation wizard and check “Add to current project”, “Debug "And" Release "(why they are not by default?).

    Copy the code to the created file(the access key is habrahabr). I would have thrown it here if it weren’t for the habraparser. I didn’t write the code, by the way: experience is still not enough, although I understand what is happening there and how - in any case, I will not dwell on this topic.

    Now the final touches to customize. We have already set up what we will compile with, but we have not set up how and what should work out with us. Therefore, right-click on the project name on the right, select Properties, and there - Build targets. Uncheck the box "Auto-generate filename extension", and in the Output filename, edit the extension "exe" to "elf". We do the same for the Release configuration, click Ok.

    Right-click on the project name again, select Build Options and, on the Linker Options tab, type in Other linker options:
    -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpsplibc -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel
    . Repeat for Release.

    Like everything (I hope this is the last article of a boring technical plan). Now we are building a project (Build → Build or Ctrl-F9, familiar to everyone) - if errors suddenly appear, we think what did wrong, and then ask in the comments (maybe I forgot what).

    In order not to configure it again later, it is worth saving the project as a template (File → Save Project as user-template ...).

    So, we have an elf-file of our program. Before you throw it on the PSP, you need to convert it to EBOOT.PBP (the name was not invented by me, honestly). For this, I have such a bat-nickname:

    "E: \ devkitPSP \ bin \ mksfo.exe"% 1 / bin / Debug /% 1% 1 / bin / Debug /% 1.sfo
    "E: \ devkitPSP \ bin \ psp-fixup-imports.exe"% 1 /bin/Debug/%1.elf
    "E: \ devkitPSP \ bin \ psp-strip.exe"% 1 / bin / Debug /% 1.elf -o% 1 / bin / Debug / stripped.elf
    "E: \ devkitPSP \ bin \ pack-pbp.exe »% 1 / bin / Debug / EBOOT.PBP% 1 / bin / Debug /% 1.sfo NULL NULL NULL NULL NULL% 1 / bin / Debug / stripped.elf NULL

    It is located in my pspprj directory, in which I create a folder for each project. It is used like this: make_eboot.bat HelloWorld. If you have a different folder organization, or you just want to rewrite it or run each program manually, just run it one line at a time, remembering to replace% 1 with the names or paths to the files. As a result, you will get the EBOOT.PBP file, you will need to drop it into the / PSP / GAME150 / HelloWorld (or other name) / folder, and everything else can be safely deleted. Now check (exit - by pressing the Home button).

    As a “homework” - make sure that all the “worldwords” are from a new line. See you!

    PS I cut out all the "humor" that I first wrote. Always stupid jokes in such posts annoyed me, and I can’t be sure that my jokes are not stupid :)

    Also popular now: