给键位配置添加保存和加载的功能

This commit is contained in:
anod 2023-04-28 07:33:13 +08:00
parent 806eb0de41
commit a4d765cc82
3 changed files with 82 additions and 8 deletions

View File

@ -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_

View File

@ -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;
}

View File

@ -1,4 +1,6 @@
#include <string.h>
#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;
}