diff --git a/include/arm11/keyremix.h b/include/arm11/keyremix.h index 7e66864..64146e8 100644 --- a/include/arm11/keyremix.h +++ b/include/arm11/keyremix.h @@ -9,6 +9,8 @@ #define REMIX_TYPE_HOLD 3 #define REMIX_TYPE_COUNT 4 +#define KEYREMIX_OUTPUT_DIR "keymaps" + #include "arm11/drivers/hid.h" #define DEFAULT_CHEATKEY (KEY_DDOWN|KEY_L|KEY_R|KEY_SELECT) @@ -29,5 +31,7 @@ extern key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT]; uint16_t keyremix_cheatkey(); void keyremix_freeze(); void keyremix_update( uint16_t active_cheatkey ); +const char* keyremix_dump( const char* gbafile ); +const char* keyremix_load( const char* gbafile ); #endif//_KEY_REMIX_H_ diff --git a/source/arm11/filebrowser.c b/source/arm11/filebrowser.c index ecec765..c7a9edc 100644 --- a/source/arm11/filebrowser.c +++ b/source/arm11/filebrowser.c @@ -504,21 +504,30 @@ static inline void key_tips( key_remix_t *p, atp_boolean_t checking, atp_itemcfg } else { - cfg->extra_text = "自动蓄力"; + cfg->extra_text = "模拟长按"; cfg->extra_text_color = ATP_COLOR_GREEN; } } } } +#define KCP_OPTION_BASE 1000 static atp_error_t select_krp( atp_callerdata_t, atp_counter_t index, atp_itemcfg_t *cfg ) { static char name[20]; - ee_snprintf(name, sizeof(name), "键位配置项%ld", index+1); - cfg->text = name; - cfg->value = index; - key_remix_t *p = &g_keyremixConfig[index]; - key_tips(p, 1, cfg); + if( index < KEY_REMIX_LIMIT ) + { + ee_snprintf(name, sizeof(name), "键位配置项%ld", index+1); + cfg->text = name; + cfg->value = index; + key_remix_t *p = &g_keyremixConfig[index]; + key_tips(p, 1, cfg); + } + else + { + cfg->text = index == KEY_REMIX_LIMIT ? "保存当前配置到SD卡" : "从SD卡加载已保存的配置"; + cfg->value = KCP_OPTION_BASE + index-KEY_REMIX_LIMIT; + } return ATP_SUCCESS; } @@ -590,7 +599,7 @@ static atp_error_t select_remixtype( atp_callerdata_t, atp_counter_t index, atp_ if( index == REMIX_TYPE_NONE ) cfg->text = "停用设置"; else if( index == REMIX_TYPE_REMAP ) cfg->text = "键位映射"; else if( index == REMIX_TYPE_CHEAT ) cfg->text = "金手指键"; - else if( index == REMIX_TYPE_HOLD ) cfg->text = "自动蓄力"; + else if( index == REMIX_TYPE_HOLD ) cfg->text = "模拟长按"; cfg->value = index; return ATP_SUCCESS; } @@ -827,11 +836,30 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a { if ( status == DISP_KPOS) { - res = atp_select( "选择配置项后,按A进行键位配置", KEY_REMIX_LIMIT, select_krp, NULL, NULL, position, 0, &position ); + res = atp_select( "选择配置项后,按A进行键位配置", KEY_REMIX_LIMIT+2, select_krp, NULL, NULL, position, 0, &position ); if( res == ATP_SUCCESS ) { - status = DISP_SETK; - field = 0; + void* *dat = (void **)data; + DirList const *dList = (DirList*)dat[0]; + char *file = &dList->ptrs[index][1]; + + if( position < KEY_REMIX_LIMIT ) + { + status = DISP_SETK; + field = 0; + } + else if( position == KCP_OPTION_BASE ) + { + const char *err = keyremix_dump( file ); + if( !err ) status = DISP_DONE; + else atp_show( 1, disp_str, err ); + } + else + { + const char *err = keyremix_load( file ); + if( !err ) position = 0; + else atp_show( 1, disp_str, err ); + } } else break; } diff --git a/source/arm11/keyremix.c b/source/arm11/keyremix.c index dc9621b..ae8822d 100644 --- a/source/arm11/keyremix.c +++ b/source/arm11/keyremix.c @@ -1,4 +1,7 @@ #include +#include "fs.h" +#include "fsutil.h" +#include "drivers/lgy.h" #include "arm11/keyremix.h" key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT]; @@ -8,6 +11,8 @@ static phykey_t prev_status = 0; static conkey_t blind_conkey; static u16 flags_holding = 0; +#define DIR_SEPARATOR "/" +#define OUTPUT_DIR (KEYREMIX_OUTPUT_DIR##DIR_SEPARATOR) #define VKEY_HOME (1u<<21) #define now_release( now, prev, key ) ((~(now))&(prev)&(key)) #define CON_KEY_MASK (KEY_A|KEY_B|KEY_L|KEY_R|KEY_SELECT|KEY_START|KEY_DUP|KEY_DDOWN|KEY_DLEFT|KEY_DRIGHT) @@ -77,6 +82,10 @@ void keyremix_update( uint16_t active_cheatkey ) *hid_mode = active_cheatkey; *hid_set = ~active_cheatkey; } + else if( frozen_end == frozen_start )// 空白键位设置,走原来流程就好 + { + LGY_handleOverrides(); + } else { conkey_t res = now & CON_KEY_MASK; @@ -120,4 +129,47 @@ void keyremix_update( uint16_t active_cheatkey ) *hid_set = ~res; } prev_status = now; +} + +const char* keyremix_load( const char *file ) +{ + char output[512]; + int len = strlen( file ) + strlen(OUTPUT_DIR); + if( len+1 > 512 ) return "文件名太长,无法保存"; + strcpy( output, OUTPUT_DIR ); + strcpy( &output[strlen(OUTPUT_DIR)], file ); + output[len] = '\0'; + output[len-1] = 'm'; + output[len-2] = 'r'; + output[len-3] = 'k'; + + FILINFO fi; + const char *retval = NULL; + if( fStat(output, &fi) == RES_OK ) + { + u8 dat[sizeof(g_keyremixConfig)]; + if( RES_OK == fsQuickRead(output, dat, sizeof(dat) ) ) + memcpy( g_keyremixConfig, dat, sizeof(g_keyremixConfig) ); + else retval = "读文件失败"; + } + else retval = "文件不存在"; + return retval; +} + +const char* keyremix_dump( const char *file ) +{ + char output[512]; + int len = strlen( file ) + strlen(OUTPUT_DIR); + if( len+1 > 512 ) return "文件名太长,无法保存"; + strcpy( output, OUTPUT_DIR ); + strcpy( &output[strlen(OUTPUT_DIR)], file ); + output[len] = '\0'; + output[len-1] = 'm'; + output[len-2] = 'r'; + output[len-3] = 'k'; + + const char *retval = NULL; + if( RES_OK != fsQuickWrite(output, g_keyremixConfig, sizeof(g_keyremixConfig)) ) + retval = "保存失败"; + return retval; } \ No newline at end of file diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index b8e46ac..1719cd0 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -1041,6 +1041,7 @@ Result oafParseConfigEarly(void) // Create the saves folder. if((res = fMkdir(OAF_SAVE_DIR)) != RES_OK && res != RES_FR_EXIST) break; + if((res = fMkdir(KEYREMIX_OUTPUT_DIR)) != RES_OK && res != RES_FR_EXIST) break; if((res = acf_initialize("wqy11.fnt")) != RES_OK ) break; // Parse the config.