diff --git a/arm9/source/main.cpp b/arm9/source/main.cpp index 8dbfe27..c9afdd4 100644 --- a/arm9/source/main.cpp +++ b/arm9/source/main.cpp @@ -167,6 +167,11 @@ int main(int argc, char* argv[]) rtc_init(); + if (argc >= 1) + { + pload_setLauncherPath(argv[0]); + } + memset(&gFatFs, 0, sizeof(gFatFs)); if (dldi_init()) { diff --git a/arm9/source/picoLoaderBootstrap.cpp b/arm9/source/picoLoaderBootstrap.cpp index 9cf8d7d..4bcaffe 100644 --- a/arm9/source/picoLoaderBootstrap.cpp +++ b/arm9/source/picoLoaderBootstrap.cpp @@ -10,6 +10,7 @@ #include #include "ipcChannels.h" #include "fat/File.h" +#include "core/StringUtil.h" #include "picoLoaderBootstrap.h" #define PICO_LOADER_9_PATH "/_pico/picoLoader9.bin" @@ -18,6 +19,7 @@ typedef void (*pico_loader_9_func_t)(void); static pload_params_t sLoadParams; +static char sLauncherPath[256] alignas(32); static PicoLoaderBootDrive sBootDrive; pload_params_t* pload_getLoadParams() @@ -30,6 +32,11 @@ void pload_setBootDrive(PicoLoaderBootDrive bootDrive) sBootDrive = bootDrive; } +void pload_setLauncherPath(const char* launcherPath) +{ + StringUtil::Copy(sLauncherPath, launcherPath, sizeof(sLauncherPath)); +} + void pload_start() { mem_setVramAMapping(MEM_VRAM_AB_LCDC); @@ -78,8 +85,13 @@ void pload_start() DC_InvalidateAll(); IC_InvalidateAll(); - ((pload_header7_t*)0x06840000)->bootDrive = sBootDrive; - dma_ntrCopy16(3, &sLoadParams, &((pload_header7_t*)0x06840000)->loadParams, sizeof(pload_params_t)); + auto header = (pload_header7_t*)0x06840000; + header->bootDrive = sBootDrive; + dma_ntrCopy16(3, &sLoadParams, &header->loadParams, sizeof(pload_params_t)); + if (header->apiVersion >= 2) + { + dma_ntrCopy16(3, &sLauncherPath, &header->v2.launcherPath, sizeof(header->v2.launcherPath)); + } mem_setVramCMapping(MEM_VRAM_C_ARM7_00000); mem_setVramDMapping(MEM_VRAM_D_ARM7_20000); ipc_sendFifoMessage(IPC_CHANNEL_LOADER, 1); diff --git a/arm9/source/picoLoaderBootstrap.h b/arm9/source/picoLoaderBootstrap.h index 1bbb659..75b6d88 100644 --- a/arm9/source/picoLoaderBootstrap.h +++ b/arm9/source/picoLoaderBootstrap.h @@ -3,4 +3,5 @@ pload_params_t* pload_getLoadParams(); void pload_setBootDrive(PicoLoaderBootDrive bootDrive); +void pload_setLauncherPath(const char* launcherPath); void pload_start(); diff --git a/common/picoLoader7.h b/common/picoLoader7.h index 375975f..859e3fc 100644 --- a/common/picoLoader7.h +++ b/common/picoLoader7.h @@ -1,7 +1,7 @@ #pragma once /// @brief The Pico Loader API version supported by this header file. -#define PICO_LOADER_API_VERSION 1 +#define PICO_LOADER_API_VERSION 2 /// @brief Enum to specify the drive to boot from. typedef enum @@ -35,6 +35,14 @@ typedef struct char arguments[256]; } pload_params_t; +/// @brief Struct representing the API version 2 part of the header of picoLoader7.bin. +typedef struct +{ + /// @brief The path of the rom to return to when exiting an application. + /// When this path is not set, no bootstub will be patched into homebrew applications. + char launcherPath[256]; +} pload_header7_v2_t; + /// @brief Struct representing the header of picoLoader7.bin. typedef struct { @@ -52,4 +60,7 @@ typedef struct /// @brief The load params, see \see pload_params_t. pload_params_t loadParams; + + /// @brief The API version 2 part of the header. Only access this when \see apiVersion >= 2. + pload_header7_v2_t v2; } pload_header7_t;