diff --git a/loader/source/buttons.h b/loader/source/buttons.h deleted file mode 100644 index 336eaf5..0000000 --- a/loader/source/buttons.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "types.h" - -#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF) -#define BUTTON_RIGHT (1 << 4) -#define BUTTON_LEFT (1 << 5) -#define BUTTON_UP (1 << 6) -#define BUTTON_DOWN (1 << 7) -#define BUTTON_A 1 -#define BUTTON_X (1 << 10) -#define BUTTON_Y (1 << 11) -#define BUTTON_R1 (1 << 8) -#define BUTTON_SELECT (1 << 2) \ No newline at end of file diff --git a/loader/source/fatfs/ffconf.h b/loader/source/fatfs/ffconf.h index fd24664..64183db 100644 --- a/loader/source/fatfs/ffconf.h +++ b/loader/source/fatfs/ffconf.h @@ -15,7 +15,7 @@ / and optional writing functions as well. */ -#define _FS_MINIMIZE 1 +#define _FS_MINIMIZE 3 /* This option defines minimization level to remove some basic API functions. / / 0: All basic functions are enabled. @@ -34,7 +34,7 @@ / 2: Enable with LF-CRLF conversion. */ -#define _USE_FIND 1 +#define _USE_FIND 0 /* This option switches filtered directory read functions, f_findfirst() and / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ diff --git a/loader/source/fatfs/sdmmc/common.h b/loader/source/fatfs/sdmmc/common.h index 90a327e..f2427e6 100644 --- a/loader/source/fatfs/sdmmc/common.h +++ b/loader/source/fatfs/sdmmc/common.h @@ -1,4 +1,15 @@ #pragma once #include -#include "../../types.h" \ No newline at end of file +#include +#include + +//Common data types +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; +typedef volatile u8 vu8; +typedef volatile u16 vu16; +typedef volatile u32 vu32; +typedef volatile u64 vu64; \ No newline at end of file diff --git a/loader/source/main.c b/loader/source/main.c index 21f16ec..926835c 100644 --- a/loader/source/main.c +++ b/loader/source/main.c @@ -1,39 +1,6 @@ -#include "types.h" -#include "buttons.h" #include "fatfs/ff.h" #define PAYLOAD_ADDRESS 0x23F00000 -#define LOAD_PAYLOAD(a) loadPayload(a "_*.bin") - -static u32 loadPayload(const char *pattern) -{ - char path[29] = "/luma/payloads"; - - DIR dir; - FILINFO info; - - FRESULT result = f_findfirst(&dir, &info, path, pattern); - - f_closedir(&dir); - - if(result != FR_OK || !info.fname[0]) - return 0; - - path[14] = '/'; - u32 i; - for(i = 0; info.fname[i]; i++) - path[15 + i] = info.fname[i]; - path[15 + i] = '\0'; - - FIL payload; - unsigned int read; - - f_open(&payload, path, FA_READ); - f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &read); - f_close(&payload); - - return 1; -} void main(void) { @@ -41,18 +8,12 @@ void main(void) f_mount(&fs, "0:", 1); - //Get pressed buttons - u32 pressed = HID_PAD; + FIL payload; + unsigned int read; - if(((pressed & BUTTON_RIGHT) && LOAD_PAYLOAD("right")) || - ((pressed & BUTTON_LEFT) && LOAD_PAYLOAD("left")) || - ((pressed & BUTTON_UP) && LOAD_PAYLOAD("up")) || - ((pressed & BUTTON_DOWN) && LOAD_PAYLOAD("down")) || - ((pressed & BUTTON_X) && LOAD_PAYLOAD("x")) || - ((pressed & BUTTON_Y) && LOAD_PAYLOAD("y")) || - ((pressed & BUTTON_R1) && LOAD_PAYLOAD("r")) || - ((pressed & BUTTON_A) && LOAD_PAYLOAD("a")) || - ((pressed & BUTTON_SELECT) && LOAD_PAYLOAD("sel")) || - LOAD_PAYLOAD("def")) - ((void (*)())PAYLOAD_ADDRESS)(); + f_open(&payload, (char *)0x24F02000, FA_READ); + f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &read); + f_close(&payload); + + ((void (*)())PAYLOAD_ADDRESS)(); } \ No newline at end of file diff --git a/loader/source/types.h b/loader/source/types.h deleted file mode 100644 index 8ac964b..0000000 --- a/loader/source/types.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -//Common data types -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef volatile u8 vu8; -typedef volatile u16 vu16; -typedef volatile u32 vu32; -typedef volatile u64 vu64; \ No newline at end of file diff --git a/source/firm.c b/source/firm.c index 598e818..45a669b 100755 --- a/source/firm.c +++ b/source/firm.c @@ -129,7 +129,7 @@ void main(void) the Safe Mode combo is not pressed, chainload an external payload */ if(((pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS))) && pressed != SAFE_MODE) - loadPayload(); + loadPayload(pressed); //If no configuration file exists or SELECT is held, load configuration menu if(needConfig == 2 || (pressed & BUTTON_SELECT)) diff --git a/source/fs.c b/source/fs.c index 84be110..77248d0 100644 --- a/source/fs.c +++ b/source/fs.c @@ -4,8 +4,11 @@ #include "fs.h" #include "memory.h" +#include "buttons.h" #include "fatfs/ff.h" +#define PATTERN(a) a "_*.bin" + static FATFS sdFs, nandFs; @@ -52,16 +55,39 @@ u32 fileWrite(const void *buffer, const char *path, u32 size) return result; } -u32 defPayloadExists(void) +u32 payloadExists(u32 pressed) { + const char *pattern; + + if(pressed & BUTTON_RIGHT) pattern = PATTERN("right"); + else if(pressed & BUTTON_LEFT) pattern = PATTERN("left"); + else if(pressed & BUTTON_UP) pattern = PATTERN("up"); + else if(pressed & BUTTON_DOWN) pattern = PATTERN("down"); + else if(pressed & BUTTON_X) pattern = PATTERN("x"); + else if(pressed & BUTTON_Y) pattern = PATTERN("y"); + else if(pressed & BUTTON_R1) pattern = PATTERN("r"); + else if(pressed & BUTTON_A) pattern = PATTERN("a"); + else if(pressed & BUTTON_START) pattern = PATTERN("start"); + else pattern = PATTERN("select"); + DIR dir; FILINFO info; + char path[] = "/luma/payloads"; - FRESULT result = f_findfirst(&dir, &info, "/luma/payloads", "def_*.bin"); + FRESULT result = f_findfirst(&dir, &info, path, pattern); f_closedir(&dir); - return (result == FR_OK && info.fname[0]); + if(result == FR_OK && info.fname[0]) + { + path[sizeof(path) - 1] = '/'; + memcpy((void *)0x24F02000, path, sizeof(path)); + memcpy((void *)(0x24F02000 + sizeof(path)), info.altname, 13); + + return 1; + } + + return 0; } void firmRead(void *dest, const char *firmFolder) diff --git a/source/fs.h b/source/fs.h index 4620204..a856c42 100644 --- a/source/fs.h +++ b/source/fs.h @@ -9,5 +9,5 @@ u32 mountFs(void); u32 fileRead(void *dest, const char *path, u32 size); u32 fileWrite(const void *buffer, const char *path, u32 size); -u32 defPayloadExists(void); +u32 payloadExists(u32 pressed); void firmRead(void *dest, const char *firmFolder); \ No newline at end of file diff --git a/source/loader.c b/source/loader.c index d226031..c48184a 100644 --- a/source/loader.c +++ b/source/loader.c @@ -10,9 +10,9 @@ #define PAYLOAD_ADDRESS 0x24F00000 -void loadPayload(void) +void loadPayload(u32 pressed) { - if(defPayloadExists()) + if(payloadExists(pressed)) { initScreens(); memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size); diff --git a/source/loader.h b/source/loader.h index 300de99..3fba42e 100644 --- a/source/loader.h +++ b/source/loader.h @@ -6,4 +6,4 @@ #include "types.h" -void loadPayload(void); \ No newline at end of file +void loadPayload(u32 pressed); \ No newline at end of file