From b9ba17a4d6d52c3e0174117f9a6dc06c0a848146 Mon Sep 17 00:00:00 2001 From: Gregory Heskett Date: Fri, 2 Feb 2024 22:08:34 -0500 Subject: [PATCH] Add libpl submodule (#753) * Add libpl submodule * Clone libpl submodule automatically while building (if enabled) --- .gitmodules | 3 +++ .vscode/c_cpp_properties.json | 1 + Makefile | 24 ++++++++++++++++++++++++ lib/libpl | 1 + sm64.ld | 12 ++++++++++++ src/game/emutest.c | 9 ++++++++- src/game/emutest.h | 5 +++++ 7 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 lib/libpl diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..9fd99fb9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/libpl"] + path = lib/libpl + url = https://gitlab.com/parallel-launcher/libpl.git diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 3ff5fdae..226d6bef 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -27,6 +27,7 @@ "F3DEX_GBI_2=1", "F3DZEX_NON_GBI_2=1", "F3DEX_GBI_SHARED=1" + "LIBPL=1", ], "compilerPath": "/usr/bin/mips-linux-gnu-gcc", "cStandard": "gnu17", diff --git a/Makefile b/Makefile index 35fb2a12..5d779159 100644 --- a/Makefile +++ b/Makefile @@ -253,6 +253,18 @@ ifeq ($(HVQM),1) SRC_DIRS += src/hvqm endif +# LIBPL - whether to include libpl library for interfacing with Parallel Launcher +# (library will be pulled into repo after building with this enabled for the first time) +# 1 - includes code in ROM +# 0 - does not +LIBPL ?= 0 +LIBPL_DIR := lib/libpl +$(eval $(call validate-option,LIBPL,0 1)) +ifeq ($(LIBPL),1) + DEFINES += LIBPL=1 + SRC_DIRS += $(LIBPL_DIR) +endif + BUILD_DIR_BASE := build # BUILD_DIR is the location where all build artifacts are placed BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_$(CONSOLE) @@ -335,6 +347,18 @@ ifeq ($(filter clean distclean print-%,$(MAKECMDGOALS)),) ifeq ($(DUMMY),FAIL) $(error Failed to build tools) endif + + # Clone any needed submodules + ifeq ($(LIBPL),1) + ifeq ($(wildcard $(LIBPL_DIR)),) + $(info Cloning libpl submodule...) + DUMMY != git submodule update --init $(LIBPL_DIR) > /dev/null || echo FAIL + ifeq ($(DUMMY),FAIL) + $(error Failed to clone libpl submodule) + endif + endif + endif + $(info Building ROM...) endif diff --git a/lib/libpl b/lib/libpl new file mode 160000 index 00000000..d6b3a90d --- /dev/null +++ b/lib/libpl @@ -0,0 +1 @@ +Subproject commit d6b3a90d096183df54d2c69a4d64e0ced8dda811 diff --git a/sm64.ld b/sm64.ld index ebb6af13..186b4d4e 100755 --- a/sm64.ld +++ b/sm64.ld @@ -171,6 +171,9 @@ SECTIONS BUILD_DIR/src/audio*.o(.text*); #ifdef S2DEX_TEXT_ENGINE BUILD_DIR/src/s2d_engine*.o(.text*); +#endif +#ifdef LIBPL + BUILD_DIR/lib/libpl*.o(.text*); #endif */ULTRALIB.a:*.o(.text*); */libnustd.a:*.o(.text*); @@ -191,6 +194,9 @@ SECTIONS BUILD_DIR/src/audio*.o(.*data*); #ifdef S2DEX_TEXT_ENGINE BUILD_DIR/src/s2d_engine*.o(.*data*); +#endif +#ifdef LIBPL + BUILD_DIR/lib/libpl*.o(.*data*); #endif */ULTRALIB.a:*.o(.data*); */libhvqm2.a:*.o(.data*); @@ -207,6 +213,9 @@ SECTIONS BUILD_DIR/src/audio*.o(.rodata*); #ifdef S2DEX_TEXT_ENGINE BUILD_DIR/src/s2d_engine*.o(.rodata*); +#endif +#ifdef LIBPL + BUILD_DIR/lib/libpl*.o(.rodata*); #endif */ULTRALIB.a:*.o(.rodata*); */libgcc.a:*.o(.rodata*); @@ -224,6 +233,9 @@ SECTIONS BUILD_DIR/src/audio*.o(.*bss*); #ifdef S2DEX_TEXT_ENGINE BUILD_DIR/src/s2d_engine*.o(.*bss*); +#endif +#ifdef LIBPL + BUILD_DIR/lib/libpl*.o(.*bss*); #endif */ULTRALIB.a:*.o(COMMON); */ULTRALIB.a:*.o(.scommon); diff --git a/src/game/emutest.c b/src/game/emutest.c index ef2b912c..872e51de 100644 --- a/src/game/emutest.c +++ b/src/game/emutest.c @@ -9,7 +9,10 @@ #include #include "emutest_vc.h" #include "float.h" -#include "types.h" + +#ifdef LIBPL +#include "lib/libpl/libpl-emu.h" +#endif extern OSMesgQueue gSIEventMesgQueue; extern u8 __osContPifRam[]; @@ -20,6 +23,7 @@ extern void __osPiGetAccess(void); extern void __osPiRelAccess(void); enum Emulator gEmulator = EMU_CONSOLE; +u8 gSupportsLibpl = FALSE; u32 pj64_get_count_factor_asm(void); // defined in asm/pj64_get_count_factor_asm.s u32 emux_detect(void); // defined in asm/emux.s @@ -140,6 +144,9 @@ void detect_emulator() { if (magic == 0x00500000u) { // libpl is supported. Must be ParallelN64 gEmulator = EMU_PARALLELN64; +#ifdef LIBPL + gSupportsLibpl = libpl_is_supported(LPL_ABI_VERSION_CURRENT); +#endif return; } diff --git a/src/game/emutest.h b/src/game/emutest.h index 8ffb2f5d..7afd57d4 100644 --- a/src/game/emutest.h +++ b/src/game/emutest.h @@ -1,6 +1,8 @@ #ifndef EMUTEST_H #define EMUTEST_H +#include "types.h" + enum Emulator { EMU_WIIVC = 0x0001, EMU_PROJECT64_ANY = 0x001E, @@ -37,6 +39,9 @@ extern void detect_emulator(); */ extern enum Emulator gEmulator; +// determines whether libpl is safe to use +extern u8 gSupportsLibpl; + // Included for backwards compatibility when upgrading from HackerSM64 2.0 #define gIsConsole ((gEmulator & EMU_CONSOLE) != 0)