Skip to content

Instantly share code, notes, and snippets.

@kassane
Last active February 16, 2024 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kassane/5e2499dfe5b532597ff7770eabfa30b1 to your computer and use it in GitHub Desktop.
Save kassane/5e2499dfe5b532597ff7770eabfa30b1 to your computer and use it in GitHub Desktop.
zig build to PSVita target
// replacing https://github.com/vitasdk/samples/blob/master/hello_world/src/main.c
const c = @cImport({
@cInclude("psp2/kernel/processmgr.h");
@cInclude("psp2/kernel/threadmgr.h");
@cInclude("stdio.h");
@cInclude("debugScreen.h");
@cDefine("printf", "psvDebugScreenPrintf");
});
pub export fn main() c_int {
_ = c.psvDebugScreenInit();
_ = c.printf("[Zig] Hello, world!\n");
_ = c.sceKernelDelayThread(3 * 1000000); // Wait for 3 seconds
return 0;
}
#!/usr/bin/env bash
VITASDK=$HOME/Downloads/vita3k-emu/vitasdk
PATH=$VITASDK/bin:$PATH
PROJECT_TITLEID=VSDK00007
# remove old build
rm -fr build
mkdir -p build
zig build-obj -fstrip -fcompiler-rt -lc \
-cflags -fshort-enums -- src/main.zig ../common/debugScreen.c \
-femit-bin=build/hello_world.o -fno-sanitize-c \
-target arm-freestanding-eabihf -mcpu=cortex_a9 \
-isystem $HOME/Downloads/vita3k-emu/vitasdk/include \
-isystem $HOME/Downloads/vita3k-emu/vitasdk/arm-vita-eabi/include \
-I../common
# add .vitalink section on binary
arm-vita-eabi-gcc -Wl,-q -Wall -O3 -DNDEBUG -Wl,-z,nocopyreloc \
$PWD/build/hello_world.o -o $PWD/build/hello_world \
-lSceLibKernel_stub -lSceDisplay_stub
rm $PWD/build/hello_world.o
vita-elf-create $PWD/build/hello_world $PWD/build/hello_world.velf
vita-make-fself -c -s $PWD/build/hello_world.velf $PWD/build/hello_world.self
vita-mksfoex -d PARENTAL_LEVEL=1 -s APP_VER=01.00 -s \
TITLE_ID=$PROJECT_TITLEID "Hello World" \
$PWD/build/hello_world.vpk_param.sfo
vita-pack-vpk -a $PWD/sce_sys/icon0.png=sce_sys/icon0.png \
-a $PWD/sce_sys/livearea/contents/bg.png=sce_sys/livearea/contents/bg.png \
-a $PWD/sce_sys/livearea/contents/startup.png=sce_sys/livearea/contents/startup.png \
-a $PWD/sce_sys/livearea/contents/template.xml=sce_sys/livearea/contents/template.xml \
-s $PWD/build/hello_world.vpk_param.sfo \
-b $PWD/build/hello_world.self \
$PWD/build/hello_world.vpk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment