Added support for Pico Loader API v2. This makes it possible to return to Pico Launcher from homebrew.

This commit is contained in:
Gericom
2026-01-10 17:08:06 +01:00
parent e4c2fafa74
commit d76d46ea73
4 changed files with 32 additions and 3 deletions

View File

@@ -167,6 +167,11 @@ int main(int argc, char* argv[])
rtc_init(); rtc_init();
if (argc >= 1)
{
pload_setLauncherPath(argv[0]);
}
memset(&gFatFs, 0, sizeof(gFatFs)); memset(&gFatFs, 0, sizeof(gFatFs));
if (dldi_init()) if (dldi_init())
{ {

View File

@@ -10,6 +10,7 @@
#include <libtwl/ipc/ipcFifoSystem.h> #include <libtwl/ipc/ipcFifoSystem.h>
#include "ipcChannels.h" #include "ipcChannels.h"
#include "fat/File.h" #include "fat/File.h"
#include "core/StringUtil.h"
#include "picoLoaderBootstrap.h" #include "picoLoaderBootstrap.h"
#define PICO_LOADER_9_PATH "/_pico/picoLoader9.bin" #define PICO_LOADER_9_PATH "/_pico/picoLoader9.bin"
@@ -18,6 +19,7 @@
typedef void (*pico_loader_9_func_t)(void); typedef void (*pico_loader_9_func_t)(void);
static pload_params_t sLoadParams; static pload_params_t sLoadParams;
static char sLauncherPath[256] alignas(32);
static PicoLoaderBootDrive sBootDrive; static PicoLoaderBootDrive sBootDrive;
pload_params_t* pload_getLoadParams() pload_params_t* pload_getLoadParams()
@@ -30,6 +32,11 @@ void pload_setBootDrive(PicoLoaderBootDrive bootDrive)
sBootDrive = bootDrive; sBootDrive = bootDrive;
} }
void pload_setLauncherPath(const char* launcherPath)
{
StringUtil::Copy(sLauncherPath, launcherPath, sizeof(sLauncherPath));
}
void pload_start() void pload_start()
{ {
mem_setVramAMapping(MEM_VRAM_AB_LCDC); mem_setVramAMapping(MEM_VRAM_AB_LCDC);
@@ -78,8 +85,13 @@ void pload_start()
DC_InvalidateAll(); DC_InvalidateAll();
IC_InvalidateAll(); IC_InvalidateAll();
((pload_header7_t*)0x06840000)->bootDrive = sBootDrive; auto header = (pload_header7_t*)0x06840000;
dma_ntrCopy16(3, &sLoadParams, &((pload_header7_t*)0x06840000)->loadParams, sizeof(pload_params_t)); 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_setVramCMapping(MEM_VRAM_C_ARM7_00000);
mem_setVramDMapping(MEM_VRAM_D_ARM7_20000); mem_setVramDMapping(MEM_VRAM_D_ARM7_20000);
ipc_sendFifoMessage(IPC_CHANNEL_LOADER, 1); ipc_sendFifoMessage(IPC_CHANNEL_LOADER, 1);

View File

@@ -3,4 +3,5 @@
pload_params_t* pload_getLoadParams(); pload_params_t* pload_getLoadParams();
void pload_setBootDrive(PicoLoaderBootDrive bootDrive); void pload_setBootDrive(PicoLoaderBootDrive bootDrive);
void pload_setLauncherPath(const char* launcherPath);
void pload_start(); void pload_start();

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
/// @brief The Pico Loader API version supported by this header file. /// @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. /// @brief Enum to specify the drive to boot from.
typedef enum typedef enum
@@ -35,6 +35,14 @@ typedef struct
char arguments[256]; char arguments[256];
} pload_params_t; } 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. /// @brief Struct representing the header of picoLoader7.bin.
typedef struct typedef struct
{ {
@@ -52,4 +60,7 @@ typedef struct
/// @brief The load params, see \see pload_params_t. /// @brief The load params, see \see pload_params_t.
pload_params_t loadParams; 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; } pload_header7_t;