On previous entries, we got our work environment ready.
It is time to step up and start with the coding. For that, we are following their advice "start by cloning the samples and by reading and understanding them".
Note: in the samples' readme page, there is a brief description of what each sample does.
Note 2: if you want to go straight to the next step (compiling and building the vpk), you can go to that step here.
When needed, we will copy the name of the folders/files the sample has, and explain their use. To make it simple, we will only explain the first appearance of the folder/file (unless it has significant changes). After that, we are going deep on the main file you have to work on.
To do that in an orderly manner, we will proceed to tackle (normally) one sample per blog entry.
The current entry, is about the one thing you always do when starting with a programming language, the "hello_world".
Note: there is a similar sample for c++, "hello_cpp_world", that do the same in a different programming language. We will skip this cpp sample, because it is practically the same as the one we are describing now.
SAMPLE "hello_world"
hello_world
: A minimal hello world sample.
It has:
sce_sys -> Here you can find the bubble images (png files) and the information showed in the ps vita screen (template.xml).
[Remember to follow the "notes on images", and "notes on supporting files and folders" when you try to use your own. If you don't follow those rules, the vpk will most probably crash during the installation proccess.]
src -> Here, we will have the files with actual code (the ".c" and ".h" files).
CMakeLists.txt -> As they say, "This file is a quick tutorial on writing CMakeLists for targeting the Vita". It has the toolchain and the basic text info of the project (this includes among others: project name, app name, app version...).
[Here we write the project info, and any other project files needed.]
Makefile - > a file containing a set of directives, used by the make build automation tool, to generate a target/goal.
[We won't need to read this file, because it will be modified by the CMakeLists.txt]
And last but not least, the .c file:
"main.c"
// headers and other required files which need to be linked for the homebrew to work.#include <psp2/kernel/threadmgr.h> #include <psp2/kernel/processmgr.h> #include <stdio.h> #include "debugScreen.h"// definition of some future used functions#define printf psvDebugScreenPrintf// main programint main(int argc, char *argv[]) {
psvDebugScreenInit(); // needed for the prints to show on the vita screen.
printf("Hello, world!\n"); sceKernelDelayThread(3*1000000); // Wait for 3 seconds
sceKernelExitProcess(0); //close the vita proccess running, usually close the app
return 0; }
And that's all for this sample. |