diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-30 13:16:18 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-30 13:16:18 +0100 |
| commit | a64aa9dfa8abd7934f7969eaa2ee1086d4189eeb (patch) | |
| tree | 213a19870aa851510efd0349298d825f6bb6efa0 | |
| parent | 4bfe4900b80c17702d9e2c02b1740c790537d5bd (diff) | |
Fix Build for PS Vita Port
I forgot to commit the makefile configuration, and also added some
other small improvements to help with the poor performance (still
only around 20 FPS).
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | port/vita/config.mk | 5 | ||||
| -rw-r--r-- | port/vita/rules.mk | 12 | ||||
| -rw-r--r-- | port/vita/src/vita.c | 12 | ||||
| -rw-r--r-- | src/wasmrt.h | 8 |
6 files changed, 43 insertions, 6 deletions
@@ -1,2 +1,2 @@ -build/ -config.mk +/build/ +/config.mk @@ -57,15 +57,15 @@ $(SYSTEM)/system.tar.gz: $(SYS) @ echo "TAR\t$@" @ $(TAR) -czf $@ -C $(SYSTEM) $(^:$(SYSTEM)/%=%) -$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c $(SYSTEM)/wasm-rt.h: $(SYSTEM)/.pico8 ; -$(SYSTEM)/.pico8: $(SYSTEM)/pico8.wasm +$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c $(SYSTEM)/wasm-rt.h: $(SYSTEM)/pico8.stamp ; +$(SYSTEM)/pico8.stamp: $(SYSTEM)/pico8.wasm @ echo "WASM2C\t$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c" @ $(WASM2C) $(W2CFLAGS) $< -o $(SYSTEM)/pico8.c @ echo '#include "wasmrt.h"' > $(SYSTEM)/wasm-rt.h @ touch $@ -$(SYSTEM)/sysroot.h $(SYSTEM)/sysroot.c: $(SYSTEM)/.sysroot ; -$(SYSTEM)/.sysroot: $(TOOLS)/generate-sysroot \ +$(SYSTEM)/sysroot.h $(SYSTEM)/sysroot.c: $(SYSTEM)/sysroot.stamp ; +$(SYSTEM)/sysroot.stamp: $(TOOLS)/generate-sysroot \ $(SYSTEM)/pico8.data.pod \ $(SYSTEM)/unknown.p8.png \ $(SYSTEM)/font.png diff --git a/port/vita/config.mk b/port/vita/config.mk new file mode 100644 index 0000000..3cb4d20 --- /dev/null +++ b/port/vita/config.mk @@ -0,0 +1,5 @@ +CC := arm-vita-eabi-gcc + +PKGCONFIG := arm-vita-eabi-pkg-config +ARCH := arm32 +LDFLAGS := $(shell $(PKGCONFIG) sdl3 --static --libs) -lm diff --git a/port/vita/rules.mk b/port/vita/rules.mk index 6ac47c7..a914195 100644 --- a/port/vita/rules.mk +++ b/port/vita/rules.mk @@ -1,6 +1,18 @@ TITLE := picow TITLEID := PICO00008 +# Some magic flags: +# - `-mcpu=cortext-a9`: specifically target the PS Vita CPU which may +# help with some optimizations (instead of generic `armv7`). +# - `-Wl,-q`: make the ELF file relocatable which is required for the +# executable to run (otherwise it crashes on startup). +# - `-Wl,--defsym=__sce_headroom=0x10000`: add some extra space for +# the code segment, otherwise linking fails sporadically. +# - `-lScePower_stub`: link in the power management library to allow us +# to overclock the PS Vita for performance +CFLAGS += -mcpu=cortex-a9 +LDFLAGS += -Wl,-q -Wl,--defsym=__sce_headroom=0x10000 -lScePower_stub + port: $(TARGET)/picow.vpk $(TARGET)/picow.vpk: $(TARGET)/eboot.bin $(TARGET)/param.sfo diff --git a/port/vita/src/vita.c b/port/vita/src/vita.c index bc5ca60..0f4814b 100644 --- a/port/vita/src/vita.c +++ b/port/vita/src/vita.c @@ -1,4 +1,16 @@ +#include <psp2/power.h> + // By default the VitaSDK only allocates a small stack for the main thread // which is not enough for the PICO-8 engine. Specify a larter stack, 1 MiB // should be more than enough, and we can grow it if needed. unsigned int sceUserMainThreadStackSize = 1024 * 1024; + +// The Vita runs applications at 333 MHz by default, bump up our clock +// speed to get some more performance. Failing to change the clocks isn't +// fatal, we just runs slower. +__attribute__((constructor)) static void vita_set_clocks(void) { + scePowerSetArmClockFrequency(444); + scePowerSetBusClockFrequency(222); + scePowerSetGpuClockFrequency(222); + scePowerSetGpuXbarClockFrequency(166); +} diff --git a/src/wasmrt.h b/src/wasmrt.h index e56d17e..543a029 100644 --- a/src/wasmrt.h +++ b/src/wasmrt.h @@ -32,12 +32,20 @@ * overflows on systems with a small stack space. We should consider turning * this on in case we ever observe this issue. That being said, if we do get * into a situation where we observe a stack overflow, the game crashed anyway. + * + * We also set `WASM_RT_USE_MMAP`, even though we don't `mmap` anything: the + * generated code only uses it to decide whether it may cache the memory base + * pointer and size in local variables instead of reloading them after every + * store. This is safe as long as the memory never moves while an instance is + * running (there is no `memory.grow` and we refuse `emscripten_resize_heap`). + * Caching makes the PICO-8 run noticeably faster. */ #define WASM_RT_MEMCHECK_GUARD_PAGES 0 #define WASM_RT_MEMCHECK_BOUNDS_CHECK 1 #define WASM_RT_STACK_DEPTH_COUNT 0 #define WASM_RT_USE_SEGUE 0 +#define WASM_RT_USE_MMAP 1 #if SDL_BYTEORDER == SDL_LIL_ENDIAN #define WABT_BIG_ENDIAN 0 |
