📜 ⬆️ ⬇️

We program for PSP: Part I, compiler setup

Let's agree right away: I follow the pattern of “learning by learning”, i.e. I study, at the same time studying, overtaking readers by 2-3 "steps" ahead. However, this does not mean that I do not know anything and everything I say is ordinary copy-paste: I try to sort out the topic before writing about it. Therefore, feel free to ask questions, with this you will benefit both yourself and me: for questions, the answer to which I do not know, I will look for him, become aware of and tell you.

So, in this topic there will be a small story about how to compile and run the first program on its console. Immediately a warning: the article is a mega technical plan, almost all the content is tedious but quick to set up the compiler, and as a result you will receive only a 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 spoken about how to reflash, and I will not dwell on this. We also assume that a flash drive is inserted into your brick, which has at least 50kb of free space, and you have access to them (for example, through the PSP itself).

I will say right away: I am almost sure that nothing bad will happen to your prefix if you are careful enough, but unfortunately I cannot give any guarantees.
')
The programming language used is C, I will use the free IDE Code :: Blocks under Windows XP. Users of other compilers or OS can try to configure IDE themselves, the benefit, the settings for all are similar; I used what I found the manual for;)

For starters, download a set of compilers, linkers and libraries for PSP called DevKitPSP . Unpack it somewhere, I unpacked it into the root of the E: drive (I now have the E: \ devkitpsp \ folder).

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

Search Directories → Compiler tab (delete everything that is there, and click Add to add each path):
E: \ devkitPSP \ include
E: \ devkitPSP \ psp \ include
E: \ devkitPSP \ psp \ sdk \ include
Linker:
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 ++. Exe
Linker for dynamic libs: psp-g ++. Exe
Linker for static libs: psp-ar.exe
I left three more fields empty.


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

Our project is pretty empty, we create a file (File → New → File ..., I don’t care for the name, I chose main.c) - don’t forget to choose C as the C language and tick the checkboxes “Add to current project”, “Debug "And" Release "(why they do not stand by default?).

Copy the code to the created file (access key - habrakhabr). I would throw it here if it weren’t for a hacker. I did not write the code, by the way: there is not enough experience yet, although I fully 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 are going to compile with, but we haven’t set up how and what should come out of us. Therefore, right-click on the project name on the right, select Properties, and there - Build targets. Uncheck the “Auto-generate filename extension” checkbox, and in the Output filename, edit the “exe” extension to “elf”. Perform the same for the Release configuration, click Ok.

Click the right button on the project name again, select Build Options and, on the Linker Options tab, enter in the 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 in a boring technical plan). Now we are building a project (Build → Build or the familiar Ctrl-F9) - if errors suddenly appear, then we think what we did wrong, and then ask in the comments (maybe I forgot what).

In order not to set up again afterwards, you should save the project as a template (File → Save Project as user-template ...).

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

"E: \ devkitPSP \ bin \ mksfo.exe"% 1 / bin / Debug /% 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 start by line, not forgetting to replace% 1 with the names or paths to the files. As a result, you will have the EBOOT.PBP file, you will need to drop it into the / PSP / GAME150 / HelloWorld (or other name) / folder, and you can safely delete everything else. Now check (exit - on the Home button).

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

PS I cut out all the “humor” that I first entered. Stupid jokes in such posts have always annoyed me the most, but I can't be sure that my jokes are stupid :)

Source: https://habr.com/ru/post/22977/


All Articles