Changed the chainloader to load payloads named "BUTTON_NAME.bin", to remember which payload is which. Original idea and code by @habbbe (many thanks!)
This commit is contained in:
parent
0f64fd73ec
commit
06060c67b5
@ -382,8 +382,8 @@ void patchCode(u64 progId, u8 *code, u32 size)
|
|||||||
patchMemory(code, size,
|
patchMemory(code, size,
|
||||||
verPattern,
|
verPattern,
|
||||||
sizeof(verPattern) - sizeof(u16), 0,
|
sizeof(verPattern) - sizeof(u16), 0,
|
||||||
!currentNand ? ((matchingFirm) ? u" Sys" : u"SysA") :
|
!currentNand ? ((matchingFirm) ? u" Sys" : u"SysE") :
|
||||||
((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuA") : ((matchingFirm) ? u"Emu2" : u"Em2A")),
|
((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuS") : ((matchingFirm) ? u"Emu2" : u"Em2S")),
|
||||||
sizeof(verPattern) - sizeof(u16), 1
|
sizeof(verPattern) - sizeof(u16), 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF)
|
#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF)
|
||||||
#define BUTTON_X (1 << 10)
|
#define BUTTON_RIGHT (1 << 4)
|
||||||
#define BUTTON_Y (1 << 11)
|
#define BUTTON_LEFT (1 << 5)
|
||||||
#define BUTTON_R1 (1 << 8)
|
#define BUTTON_UP (1 << 6)
|
||||||
#define BUTTON_SELECT (1 << 2)
|
#define BUTTON_DOWN (1 << 7)
|
||||||
#define BUTTON_RIGHT (1 << 4)
|
#define BUTTON_X (1 << 10)
|
||||||
#define BUTTON_LEFT (1 << 5)
|
#define BUTTON_Y (1 << 11)
|
||||||
#define BUTTON_UP (1 << 6)
|
#define BUTTON_R1 (1 << 8)
|
||||||
#define BUTTON_DOWN (1 << 7)
|
|
@ -15,7 +15,7 @@
|
|||||||
/ and optional writing functions as well. */
|
/ and optional writing functions as well. */
|
||||||
|
|
||||||
|
|
||||||
#define _FS_MINIMIZE 3
|
#define _FS_MINIMIZE 1
|
||||||
/* This option defines minimization level to remove some basic API functions.
|
/* This option defines minimization level to remove some basic API functions.
|
||||||
/
|
/
|
||||||
/ 0: All basic functions are enabled.
|
/ 0: All basic functions are enabled.
|
||||||
@ -34,7 +34,7 @@
|
|||||||
/ 2: Enable with LF-CRLF conversion. */
|
/ 2: Enable with LF-CRLF conversion. */
|
||||||
|
|
||||||
|
|
||||||
#define _USE_FIND 0
|
#define _USE_FIND 1
|
||||||
/* This option switches filtered directory read feature and related functions,
|
/* This option switches filtered directory read feature and related functions,
|
||||||
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
|
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
@ -3,23 +3,36 @@
|
|||||||
#include "fatfs/ff.h"
|
#include "fatfs/ff.h"
|
||||||
|
|
||||||
#define PAYLOAD_ADDRESS 0x23F00000
|
#define PAYLOAD_ADDRESS 0x23F00000
|
||||||
#define PAYLOADS_FOLDER "/aurei/payloads/"
|
#define LOAD_PAYLOAD(a) loadPayload(a "_*.bin")
|
||||||
#define PAYLOAD_PATH(a) PAYLOADS_FOLDER a ".bin"
|
|
||||||
|
|
||||||
static u32 loadPayload(const char *path)
|
static u32 loadPayload(const char *pattern)
|
||||||
{
|
{
|
||||||
|
char path[30] = "/aurei/payloads";
|
||||||
|
|
||||||
|
DIR dir;
|
||||||
|
FILINFO info = { .lfname = NULL };
|
||||||
|
|
||||||
|
FRESULT result = f_findfirst(&dir, &info, path, pattern);
|
||||||
|
|
||||||
|
f_closedir(&dir);
|
||||||
|
|
||||||
|
if(result != FR_OK || !info.fname[0])
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
path[15] = '/';
|
||||||
|
u32 i;
|
||||||
|
for(i = 0; info.fname[i]; i++)
|
||||||
|
path[16 + i] = info.fname[i];
|
||||||
|
path[16 + i] = '\0';
|
||||||
|
|
||||||
FIL payload;
|
FIL payload;
|
||||||
unsigned int br;
|
unsigned int br;
|
||||||
|
|
||||||
if(f_open(&payload, path, FA_READ) == FR_OK)
|
f_open(&payload, path, FA_READ);
|
||||||
{
|
f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br);
|
||||||
f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br);
|
f_close(&payload);
|
||||||
f_close(&payload);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
@ -31,14 +44,13 @@ void main(void)
|
|||||||
//Get pressed buttons
|
//Get pressed buttons
|
||||||
u32 pressed = HID_PAD;
|
u32 pressed = HID_PAD;
|
||||||
|
|
||||||
if(((pressed & BUTTON_RIGHT) && loadPayload(PAYLOAD_PATH("right"))) ||
|
if(((pressed & BUTTON_RIGHT) && LOAD_PAYLOAD("right")) ||
|
||||||
((pressed & BUTTON_LEFT) && loadPayload(PAYLOAD_PATH("left"))) ||
|
((pressed & BUTTON_LEFT) && LOAD_PAYLOAD("left")) ||
|
||||||
((pressed & BUTTON_UP) && loadPayload(PAYLOAD_PATH("up"))) ||
|
((pressed & BUTTON_UP) && LOAD_PAYLOAD("up")) ||
|
||||||
((pressed & BUTTON_DOWN) && loadPayload(PAYLOAD_PATH("down"))) ||
|
((pressed & BUTTON_DOWN) && LOAD_PAYLOAD("down")) ||
|
||||||
((pressed & BUTTON_X) && loadPayload(PAYLOAD_PATH("x"))) ||
|
((pressed & BUTTON_X) && LOAD_PAYLOAD("x")) ||
|
||||||
((pressed & BUTTON_Y) && loadPayload(PAYLOAD_PATH("y"))) ||
|
((pressed & BUTTON_Y) && LOAD_PAYLOAD("y")) ||
|
||||||
((pressed & BUTTON_SELECT) && loadPayload(PAYLOAD_PATH("select"))) ||
|
((pressed & BUTTON_R1) && LOAD_PAYLOAD("r")) ||
|
||||||
((pressed & BUTTON_R1) && loadPayload(PAYLOAD_PATH("r"))) ||
|
LOAD_PAYLOAD("def"))
|
||||||
loadPayload(PAYLOAD_PATH("default")))
|
|
||||||
((void (*)())PAYLOAD_ADDRESS)();
|
((void (*)())PAYLOAD_ADDRESS)();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
/ 2: Enable with LF-CRLF conversion. */
|
/ 2: Enable with LF-CRLF conversion. */
|
||||||
|
|
||||||
|
|
||||||
#define _USE_FIND 0
|
#define _USE_FIND 1
|
||||||
/* This option switches filtered directory read feature and related functions,
|
/* This option switches filtered directory read feature and related functions,
|
||||||
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
|
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
12
source/fs.c
12
source/fs.c
@ -64,16 +64,16 @@ u32 fileSize(const char *path)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 fileExists(const char *path)
|
u32 defPayloadExists(void)
|
||||||
{
|
{
|
||||||
FIL fp;
|
DIR dir;
|
||||||
u32 exists = 0;
|
FILINFO info = { .lfname = NULL };
|
||||||
|
|
||||||
if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1;
|
FRESULT result = f_findfirst(&dir, &info, "/aurei/payloads", "def_*.bin");
|
||||||
|
|
||||||
f_close(&fp);
|
f_closedir(&dir);
|
||||||
|
|
||||||
return exists;
|
return (result == FR_OK && info.fname[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void firmRead(void *dest, const char *firmFolder)
|
void firmRead(void *dest, const char *firmFolder)
|
||||||
|
@ -12,5 +12,5 @@ u32 mountFs(void);
|
|||||||
u32 fileRead(void *dest, const char *path, u32 size);
|
u32 fileRead(void *dest, const char *path, u32 size);
|
||||||
u32 fileWrite(const void *buffer, const char *path, u32 size);
|
u32 fileWrite(const void *buffer, const char *path, u32 size);
|
||||||
u32 fileSize(const char *path);
|
u32 fileSize(const char *path);
|
||||||
u32 fileExists(const char *path);
|
u32 defPayloadExists(void);
|
||||||
void firmRead(void *dest, const char *firmFolder);
|
void firmRead(void *dest, const char *firmFolder);
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
void loadPayload(void)
|
void loadPayload(void)
|
||||||
{
|
{
|
||||||
if(fileExists("aurei/payloads/default.bin"))
|
if(defPayloadExists())
|
||||||
{
|
{
|
||||||
initScreens();
|
initScreens();
|
||||||
memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);
|
memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);
|
||||||
|
Reference in New Issue
Block a user