From a4d765cc82b33f40795cae67c47375303b26ed6a Mon Sep 17 00:00:00 2001 From: anod <182859762@qq.com> Date: Fri, 28 Apr 2023 07:33:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E9=94=AE=E4=BD=8D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BF=9D=E5=AD=98=E5=92=8C=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arm11/keyremix.h | 2 ++ source/arm11/filebrowser.c | 44 +++++++++++++++++++++++++++++++------- source/arm11/keyremix.c | 44 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/include/arm11/keyremix.h b/include/arm11/keyremix.h index 7e66864..f1712a6 100644 --- a/include/arm11/keyremix.h +++ b/include/arm11/keyremix.h @@ -29,5 +29,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( char* gbafile ); +const char* keyremix_load( char* gbafile ); #endif//_KEY_REMIX_H_ diff --git a/source/arm11/filebrowser.c b/source/arm11/filebrowser.c index 97769ef..0c3fe02 100644 --- a/source/arm11/filebrowser.c +++ b/source/arm11/filebrowser.c @@ -511,14 +511,23 @@ static inline void key_tips( key_remix_t *p, atp_boolean_t checking, atp_itemcfg } } +#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卡" : "读取已保存的配置"; + cfg->value = KCP_OPTION_BASE + index-KEY_REMIX_LIMIT; + } 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..b308c3f 100644 --- a/source/arm11/keyremix.c +++ b/source/arm11/keyremix.c @@ -1,4 +1,6 @@ #include +#include "fs.h" +#include "drivers/lgy.h" #include "arm11/keyremix.h" key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT]; @@ -77,6 +79,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 +126,42 @@ void keyremix_update( uint16_t active_cheatkey ) *hid_set = ~res; } prev_status = now; +} + +const char* keyremix_load( char *file ) +{ + FILINFO fi; + int len = strlen( file ); + file[len-1] = 'm'; + file[len-2] = 'r'; + file[len-3] = 'k'; + const char *retval = NULL; + if( fStat(file, &fi) == RES_OK ) + { + u8 dat[sizeof(g_keyremixConfig)]; + if( RES_OK == fsQuickRead(file, dat, 8 ) ) + memcpy( g_keyremixConfig, dat, sizeof(g_keyremixConfig) ); + else retval = "读文件失败"; + } + else retval = "文件不存在"; + file[len-1] = 'a'; + file[len-2] = 'b'; + file[len-3] = 'g'; + return retval; +} + +const char* keyremix_dump( char *file ) +{ + FILINFO fi; + int len = strlen( file ); + file[len-1] = 'm'; + file[len-2] = 'r'; + file[len-3] = 'k'; + const char *retval = NULL; + if( RES_OK != fsQuickWrite(file, g_keyremixConfig, sizeof(g_keyremixConfig) ) ) + retval = "保存失败"; + file[len-1] = 'a'; + file[len-2] = 'b'; + file[len-3] = 'g'; + return retval; } \ No newline at end of file