From 72fdff8858f2f35b27c41bf862091f96edaab0cc Mon Sep 17 00:00:00 2001 From: anod <182859762@qq.com> Date: Thu, 4 May 2023 14:23:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E6=A8=A1=E6=8B=9F=E9=95=BF=E6=8C=89=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9A=20=E6=9D=A1=E4=BB=B6=EF=BC=9A=E4=BA=92?= =?UTF-8?q?=E6=8D=A2L/R=E7=9A=84=E6=98=A0=E5=B0=84=20+=20=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E9=95=BF=E6=8C=89=E7=BB=91=E5=AE=9A=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E5=86=85L=EF=BC=8C=E5=90=AF=E7=94=A8=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E6=8C=89L=E4=BC=9A=E6=BF=80=E5=8F=91=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AFR=EF=BC=8C=E4=BD=86=E6=98=AFL=E5=92=8CR=E4=BA=92?= =?UTF-8?q?=E6=8D=A2=E4=BA=86=EF=BC=8C=E5=BA=94=E8=AF=A5=E6=98=AFR?= =?UTF-8?q?=E6=BF=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/arm11/keyremix.c | 77 ++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/source/arm11/keyremix.c b/source/arm11/keyremix.c index 6212dd6..2ff00c3 100644 --- a/source/arm11/keyremix.c +++ b/source/arm11/keyremix.c @@ -7,7 +7,8 @@ key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT]; static key_remix_t *frozen_start, *frozen_end; -static phykey_t prev_status = 0; +static phykey_t prev_phykey = 0; +static conkey_t prev_conkey = 0; static conkey_t blind_conkey; static u16 flags_holding = 0; @@ -29,57 +30,79 @@ uint16_t keyremix_cheatkey() void keyremix_freeze() { - // 空白选项忽略,填充blind_conkey,金手指放首位 + // 空白选项忽略,填充blind_conkey,金手指放首位,REMAP紧跟金手指,HOLD在后面 key_remix_t temp[KEY_REMIX_LIMIT+1]; - int j=1, has_cheat=0; + + // 第一次循环:扫描得到各remix_type数量,用于定位在数组的位置 + int has_cheat=0, rem_count=0, valid_count=0; blind_conkey = 0; for( int i=0; i < KEY_REMIX_LIMIT; ++i ) { key_remix_t *p = &g_keyremixConfig[i]; - if( p->remix_type == REMIX_TYPE_CHEAT ) + if( p->remix_type == REMIX_TYPE_CHEAT ) { temp[0].remix_type = REMIX_TYPE_CHEAT; temp[0].device_keys = p->device_keys; temp[0].game_keys = p->game_keys; has_cheat = 1; } - else if( p->remix_type != REMIX_TYPE_NONE + else if( p->remix_type != REMIX_TYPE_NONE + && p->device_keys != 0 + && p->game_keys != 0 ) + { + valid_count++; + if( p->remix_type == REMIX_TYPE_REMAP ) rem_count++; + if( p->device_keys & CON_KEY_MASK ) + blind_conkey |= p->device_keys; + } + } + + // 第二次循环:根据remix_type放置到数组特定位置 + int j=has_cheat; + int k=j+rem_count; + for( int i=0; i < KEY_REMIX_LIMIT; ++i ) + { + key_remix_t *p = &g_keyremixConfig[i]; + if( p->remix_type == REMIX_TYPE_CHEAT ) + { + continue; + } + else if( p->remix_type == REMIX_TYPE_REMAP && p->device_keys != 0 && p->game_keys != 0 ) { temp[j].remix_type = p->remix_type; temp[j].device_keys = p->device_keys; temp[j].game_keys = p->game_keys; - if( p->device_keys & CON_KEY_MASK ) - blind_conkey |= p->device_keys; ++j; } + else if( p->remix_type == REMIX_TYPE_HOLD + && p->device_keys != 0 + && p->game_keys != 0 ) + { + temp[k].remix_type = p->remix_type; + temp[k].device_keys = p->device_keys; + temp[k].game_keys = p->game_keys; + ++k; + } } - memset( g_keyremixConfig, 0, sizeof(g_keyremixConfig) ); - if( has_cheat ) - { - memcpy( g_keyremixConfig, temp, sizeof(key_remix_t)*j ); - frozen_start = &g_keyremixConfig[1]; - frozen_end = &g_keyremixConfig[j]; - } - else - { - memcpy( g_keyremixConfig, &temp[1], sizeof(key_remix_t)*(j-1) ); - frozen_start = &g_keyremixConfig[0]; - frozen_end = &g_keyremixConfig[j-1]; - } + memcpy( g_keyremixConfig, temp, sizeof(g_keyremixConfig) ); + frozen_start = &g_keyremixConfig[has_cheat]; + frozen_end = &g_keyremixConfig[has_cheat+valid_count]; } void keyremix_update( uint16_t active_cheatkey ) { phykey_t now = hidKeysHeld(); + conkey_t cur = 0; + u8 init_cur = 0; vu16 *hid_set = (vu16*)0x10141112; vu16 *hid_mode = (vu16*)0x10141110; if( hidGetExtraKeys(0) & KEY_HOME ) now |= VKEY_HOME; - if( active_cheatkey && now_release(now, prev_status, VKEY_HOME) ) + if( active_cheatkey && now_release(now, prev_phykey, VKEY_HOME) ) { *hid_mode = active_cheatkey; *hid_set = ~active_cheatkey; @@ -111,15 +134,20 @@ void keyremix_update( uint16_t active_cheatkey ) } else if( p->remix_type == REMIX_TYPE_HOLD ) { + if( init_cur == 0 ) + { + init_cur = 1; + cur = res; + } uint16_t flag = 1<device_keys) ) + if( now_release(now, prev_phykey, p->device_keys) ) flags_holding ^= flag; if( flags_holding & flag ) { // exclude console keys is up - res |= now_release(now, prev_status, p->game_keys) ^ p->game_keys; + res |= now_release(cur, prev_conkey, p->game_keys) ^ p->game_keys; } else if( oldf != flags_holding )// release { @@ -130,7 +158,8 @@ void keyremix_update( uint16_t active_cheatkey ) *hid_mode = CON_KEY_MASK; *hid_set = ~res; } - prev_status = now; + prev_phykey = now; + prev_conkey = cur; } const char* keyremix_load( const char *file )