2016-03-17 00:08:13 +01:00
|
|
|
#include "types.h"
|
|
|
|
#include "buttons.h"
|
2016-03-08 15:13:55 +01:00
|
|
|
#include "fatfs/ff.h"
|
|
|
|
|
|
|
|
#define PAYLOAD_ADDRESS 0x23F00000
|
2016-04-17 18:57:25 +02:00
|
|
|
#define LOAD_PAYLOAD(a) loadPayload(a "_*.bin")
|
2016-04-16 18:21:42 +02:00
|
|
|
|
2016-04-17 18:57:25 +02:00
|
|
|
static u32 loadPayload(const char *pattern)
|
2016-04-02 17:58:06 +02:00
|
|
|
{
|
2016-04-23 01:43:11 +02:00
|
|
|
char path[30] = "/luma/payloads";
|
2016-04-17 18:57:25 +02:00
|
|
|
|
|
|
|
DIR dir;
|
2016-04-18 04:47:53 +02:00
|
|
|
FILINFO info;
|
2016-04-17 18:57:25 +02:00
|
|
|
|
|
|
|
FRESULT result = f_findfirst(&dir, &info, path, pattern);
|
|
|
|
|
|
|
|
f_closedir(&dir);
|
|
|
|
|
|
|
|
if(result != FR_OK || !info.fname[0])
|
|
|
|
return 0;
|
|
|
|
|
2016-04-23 01:43:11 +02:00
|
|
|
path[14] = '/';
|
2016-04-17 18:57:25 +02:00
|
|
|
u32 i;
|
|
|
|
for(i = 0; info.fname[i]; i++)
|
2016-04-23 01:43:11 +02:00
|
|
|
path[15 + i] = info.fname[i];
|
|
|
|
path[15 + i] = '\0';
|
2016-04-17 18:57:25 +02:00
|
|
|
|
2016-03-08 15:13:55 +01:00
|
|
|
FIL payload;
|
|
|
|
unsigned int br;
|
2016-04-02 17:58:06 +02:00
|
|
|
|
2016-04-17 18:57:25 +02:00
|
|
|
f_open(&payload, path, FA_READ);
|
|
|
|
f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br);
|
|
|
|
f_close(&payload);
|
2016-03-17 00:08:13 +01:00
|
|
|
|
2016-04-17 18:57:25 +02:00
|
|
|
return 1;
|
2016-03-17 00:08:13 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void main(void)
|
|
|
|
{
|
2016-03-17 00:08:13 +01:00
|
|
|
FATFS fs;
|
2016-04-03 17:56:09 +02:00
|
|
|
|
2016-03-17 00:08:13 +01:00
|
|
|
f_mount(&fs, "0:", 1);
|
|
|
|
|
|
|
|
//Get pressed buttons
|
2016-04-02 22:02:08 +02:00
|
|
|
u32 pressed = HID_PAD;
|
2016-03-17 00:08:13 +01:00
|
|
|
|
2016-04-17 18:57:25 +02:00
|
|
|
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")) ||
|
2016-04-24 19:23:40 +02:00
|
|
|
((pressed & BUTTON_A) && LOAD_PAYLOAD("a")) ||
|
2016-04-18 02:55:54 +02:00
|
|
|
((pressed & BUTTON_SELECT) && LOAD_PAYLOAD("sel")) ||
|
2016-04-17 18:57:25 +02:00
|
|
|
LOAD_PAYLOAD("def"))
|
2016-03-08 15:13:55 +01:00
|
|
|
((void (*)())PAYLOAD_ADDRESS)();
|
2016-04-18 02:55:54 +02:00
|
|
|
}
|