diff --git a/defaults.h b/defaults.h index 6ffd885498..63e962c31a 100644 --- a/defaults.h +++ b/defaults.h @@ -18,6 +18,8 @@ #include +#include + #include #ifndef IS_SALAMANDER @@ -114,6 +116,8 @@ struct defaults #endif }; +bool dir_set_defaults(enum default_dirs dir_type, const char *dirpath); + /* Public data structures. */ extern struct defaults g_defaults; diff --git a/dirs.c b/dirs.c index 7ddecdff02..1b5212f4b9 100644 --- a/dirs.c +++ b/dirs.c @@ -285,6 +285,17 @@ void dir_set(enum rarch_dir_type type, const char *path) } } +bool dir_set_defaults(enum default_dirs dir_type, const char *dirpath) +{ + switch (dir_type) + { + case DEFAULT_DIR_PORT: + strlcpy(g_defaults.dirs[dir_type], dirpath, + sizeof(g_defaults.dirs[dir_type])); + break; + } +} + void dir_check_defaults(void) { unsigned i; diff --git a/frontend/drivers/platform_ctr.c b/frontend/drivers/platform_ctr.c index 6f6f3236a9..71c827c446 100644 --- a/frontend/drivers/platform_ctr.c +++ b/frontend/drivers/platform_ctr.c @@ -196,15 +196,16 @@ static void frontend_ctr_exec(const char* path, bool should_load_game) const char* arg_data[3]; errorConf error_dialog; char error_string[200 + PATH_MAX]; - int args = 0; - int error = 0; + int args = 0; + int error = 0; DEBUG_VAR(path); DEBUG_STR(path); - arg_data[0] = NULL; + game_path[0] = '\0'; + arg_data[0] = NULL; - arg_data[args] = elf_path_cst; + arg_data[args] = elf_path_cst; arg_data[args + 1] = NULL; args++; @@ -224,13 +225,14 @@ static void frontend_ctr_exec(const char* path, bool should_load_game) { #ifdef IS_SALAMANDER struct stat sbuff; - bool file_exists; + bool file_exists = stat(path, &sbuff) == 0; - file_exists = stat(path, &sbuff) == 0; if (!file_exists) { char core_path[PATH_MAX]; + core_path[0] = '\0'; + /* find first valid core and load it if the target core doesnt exist */ get_first_valid_core(&core_path[0]); @@ -245,9 +247,7 @@ static void frontend_ctr_exec(const char* path, bool should_load_game) #endif if (envIsHomebrew()) - { exec_3dsx_no_path_in_args(path, arg_data); - } else { RARCH_WARN("\n"); @@ -263,10 +263,12 @@ static void frontend_ctr_exec(const char* path, bool should_load_game) } errorInit(&error_dialog, ERROR_TEXT, CFG_LANGUAGE_EN); - snprintf(error_string, sizeof(error_string), "Cant launch core:%s", path); + snprintf(error_string, sizeof(error_string), + "Can't launch core:%s", path); errorText(&error_dialog, error_string); errorDisp(&error_dialog); - exit(0);//couldnt launch new core, but context is corrupt so we have to quit + exit(0); /* couldnt launch new core, but context + is corrupt so we have to quit */ } } @@ -330,30 +332,35 @@ static void ctr_check_dspfirm(void) fclose(dsp_fp); else { - size_t code_size; - uint32_t* code_buffer = NULL; - uint32_t* ptr = NULL; - const uint32_t dsp1_magic = 0x31505344; /* "DSP1" */ - FILE* code_fp = fopen("sdmc:/3ds/code.bin", "rb"); + FILE *code_fp = fopen("sdmc:/3ds/code.bin", "rb"); if (code_fp) { + size_t code_size; + uint32_t* code_buffer = NULL; + fseek(code_fp, 0, SEEK_END); code_size = ftell(code_fp); fseek(code_fp, 0, SEEK_SET); code_buffer = (uint32_t*) malloc(code_size); + if (code_buffer) { + uint32_t *ptr = NULL; + fread(code_buffer, 1, code_size, code_fp); - for (ptr = code_buffer + 0x40; ptr < (code_buffer + (code_size >> 2)); ptr++) + for (ptr = code_buffer + 0x40; + ptr < (code_buffer + (code_size >> 2)); ptr++) { + const uint32_t dsp1_magic = 0x31505344; /* "DSP1" */ if (*ptr == dsp1_magic) { size_t dspfirm_size = ptr[1]; ptr -= 0x40; - if ((ptr + (dspfirm_size >> 2)) > (code_buffer + (code_size >> 2))) + if ((ptr + (dspfirm_size >> 2)) > + (code_buffer + (code_size >> 2))) break; dsp_fp = fopen("sdmc:/3ds/dspfirm.cdc", "wb"); @@ -396,23 +403,23 @@ static void frontend_ctr_init(void* data) gfxInit(GSP_BGR8_OES, GSP_RGB565_OES, false); - u32 topSize = 400 * 240 * 3; - u32 bottomSize = 320 * 240 * 2; - linearFree(gfxTopLeftFramebuffers[0]); - linearFree(gfxTopLeftFramebuffers[1]); - linearFree(gfxBottomFramebuffers[0]); - linearFree(gfxBottomFramebuffers[1]); + u32 topSize = 400 * 240 * 3; + u32 bottomSize = 320 * 240 * 2; + linearFree(gfxTopLeftFramebuffers [0]); + linearFree(gfxTopLeftFramebuffers [1]); + linearFree(gfxBottomFramebuffers [0]); + linearFree(gfxBottomFramebuffers [1]); linearFree(gfxTopRightFramebuffers[0]); linearFree(gfxTopRightFramebuffers[1]); - gfxTopLeftFramebuffers[0] = linearAlloc(topSize * 2); + gfxTopLeftFramebuffers [0] = linearAlloc(topSize * 2); gfxTopRightFramebuffers[0] = gfxTopLeftFramebuffers[0] + topSize; - gfxTopLeftFramebuffers[1] = linearAlloc(topSize * 2); + gfxTopLeftFramebuffers [1] = linearAlloc(topSize * 2); gfxTopRightFramebuffers[1] = gfxTopLeftFramebuffers[1] + topSize; - gfxBottomFramebuffers[0] = linearAlloc(bottomSize); - gfxBottomFramebuffers[1] = linearAlloc(bottomSize); + gfxBottomFramebuffers [0] = linearAlloc(bottomSize); + gfxBottomFramebuffers [1] = linearAlloc(bottomSize); gfxSetFramebufferInfo(GFX_TOP, 0); gfxSetFramebufferInfo(GFX_BOTTOM, 0); @@ -442,7 +449,9 @@ static void frontend_ctr_init(void* data) static int frontend_ctr_get_rating(void) { u8 device_model = 0xFF; - CFGU_GetSystemModel(&device_model);/*(0 = O3DS, 1 = O3DSXL, 2 = N3DS, 3 = 2DS, 4 = N3DSXL, 5 = N2DSXL)*/ + + /*(0 = O3DS, 1 = O3DSXL, 2 = N3DS, 3 = 2DS, 4 = N3DSXL, 5 = N2DSXL)*/ + CFGU_GetSystemModel(&device_model); switch (device_model) { @@ -451,13 +460,11 @@ static int frontend_ctr_get_rating(void) case 3: /*Old 3/2DS*/ return 3; - case 2: case 4: case 5: /*New 3/2DS*/ return 6; - default: /*Unknown Device Or Check Failed*/ break; @@ -475,18 +482,19 @@ static int frontend_ctr_parse_drive_list(void* data, bool load_content) { #ifndef IS_SALAMANDER file_list_t* list = (file_list_t*)data; - enum msg_hash_enums enum_idx = load_content ? - MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR : - MSG_UNKNOWN; + enum msg_hash_enums enum_idx = load_content + ? MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR + : MSG_UNKNOWN; if (!list) return -1; menu_entries_append_enum(list, - "sdmc:/", - msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), - enum_idx, - FILE_TYPE_DIRECTORY, 0, 0); + "sdmc:/", + msg_hash_to_str( + MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), + enum_idx, + FILE_TYPE_DIRECTORY, 0, 0); #endif return 0; @@ -502,30 +510,28 @@ static uint64_t frontend_ctr_get_mem_used(void) return osGetMemRegionUsed(MEMREGION_ALL); } -static enum frontend_powerstate frontend_ctr_get_powerstate(int* seconds, int* percent) +static enum frontend_powerstate frontend_ctr_get_powerstate( + int* seconds, int* percent) { - u8 battery_percent = 0; - u8 charging = 0; - enum frontend_powerstate pwr_state = FRONTEND_POWERSTATE_NONE; + u8 battery_percent = 0; + u8 charging = 0; mcuHwcGetBatteryLevel(&battery_percent); - *percent = battery_percent; - /* 3ds does not support seconds of charge remaining */ - *seconds = -1; + *percent = battery_percent; + /* 3DS does not support seconds of charge remaining */ + *seconds = -1; PTMU_GetBatteryChargeState(&charging); + if (charging) { if (battery_percent == 100) - pwr_state = FRONTEND_POWERSTATE_CHARGED; - else - pwr_state = FRONTEND_POWERSTATE_CHARGING; + return FRONTEND_POWERSTATE_CHARGED; + return FRONTEND_POWERSTATE_CHARGING; } - else - pwr_state = FRONTEND_POWERSTATE_ON_POWER_SOURCE; - return pwr_state; + return FRONTEND_POWERSTATE_ON_POWER_SOURCE; } static void frontend_ctr_get_os(char* s, size_t len, int* major, int* minor) @@ -551,7 +557,9 @@ static void frontend_ctr_get_os(char* s, size_t len, int* major, int* minor) static void frontend_ctr_get_name(char* s, size_t len) { u8 device_model = 0xFF; - CFGU_GetSystemModel(&device_model);/*(0 = O3DS, 1 = O3DSXL, 2 = N3DS, 3 = 2DS, 4 = N3DSXL, 5 = N2DSXL)*/ + + /*(0 = O3DS, 1 = O3DSXL, 2 = N3DS, 3 = 2DS, 4 = N3DSXL, 5 = N2DSXL)*/ + CFGU_GetSystemModel(&device_model); switch (device_model) {