处理了键位映射的代码

This commit is contained in:
anod 2023-04-27 09:13:53 +08:00
parent 23533fdb1b
commit 7c6d8690e8
4 changed files with 94 additions and 45 deletions

View File

@ -1,14 +1,16 @@
#ifndef _KEY_REMIX_H_ #ifndef _KEY_REMIX_H_
#define _KEY_REMIX_H_ #define _KEY_REMIX_H_
#define KEY_REMIX_LIMIT 4 #define KEY_REMIX_LIMIT 8
#define REMIX_TYPE_NONE 0 #define REMIX_TYPE_NONE 0
#define REMIX_TYPE_REMAP 1 #define REMIX_TYPE_REMAP 1
#define REMIX_TYPE_CHEAT 2 #define REMIX_TYPE_CHEAT 2
#define REMIX_TYPE_UNLINK 3 #define REMIX_TYPE_HOLD 3
#define REMIX_TYPE_HOLD 4 #define REMIX_TYPE_COUNT 3
#define REMIX_TYPE_COUNT 4
#include "arm11/drivers/hid.h"
#define DEFAULT_CHEATKEY (KEY_DOWN|KEY_L|KEY_R|KEY_SELECT)
#include <stdint.h> #include <stdint.h>
@ -26,6 +28,6 @@ extern key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT];
uint16_t keyremix_cheatkey(); uint16_t keyremix_cheatkey();
void keyremix_freeze(); void keyremix_freeze();
void keyremix_update(); void keyremix_update( uint16_t active_cheatkey );
#endif//_KEY_REMIX_H_ #endif//_KEY_REMIX_H_

View File

@ -494,19 +494,6 @@ static inline void key_tips( key_remix_t *p, atp_boolean_t checking, atp_itemcfg
cfg->extra_text_color = ATP_COLOR_GREEN; cfg->extra_text_color = ATP_COLOR_GREEN;
} }
} }
else if( p->remix_type == REMIX_TYPE_UNLINK )
{
if( checking && p->game_keys == 0 )
{
cfg->extra_text = "配置不齐";
cfg->extra_text_color = ATP_COLOR_RED;
}
else
{
cfg->extra_text = "禁用原键位";
cfg->extra_text_color = ATP_COLOR_GREEN;
}
}
else if( p->remix_type == REMIX_TYPE_HOLD ) else if( p->remix_type == REMIX_TYPE_HOLD )
{ {
if( checking && (p->game_keys==0 || p->device_keys==0) ) if( checking && (p->game_keys==0 || p->device_keys==0) )
@ -573,11 +560,6 @@ static atp_error_t select_kcf( atp_callerdata_t p, atp_counter_t index, atp_item
cfg->extra_text = "HOME"; cfg->extra_text = "HOME";
cfg->extra_text_color = ATP_COLOR_GREEN; cfg->extra_text_color = ATP_COLOR_GREEN;
} }
else if( kcfg->remix_type == REMIX_TYPE_UNLINK )
{
cfg->extra_text = "";
cfg->extra_text_color = ATP_COLOR_GREEN;
}
else else
{ {
cfg->extra_text = "未设置"; cfg->extra_text = "未设置";
@ -608,7 +590,6 @@ static atp_error_t select_remixtype( atp_callerdata_t, atp_counter_t index, atp_
else if( index == REMIX_TYPE_REMAP ) cfg->text = "键位映射"; else if( index == REMIX_TYPE_REMAP ) cfg->text = "键位映射";
else if( index == REMIX_TYPE_CHEAT ) 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 = "自动蓄力";
else if( index == REMIX_TYPE_UNLINK ) cfg->text = "禁用原键位";
cfg->value = index; cfg->value = index;
return ATP_SUCCESS; return ATP_SUCCESS;
} }
@ -877,7 +858,8 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a
} }
} }
} }
if( fault ) atp_show(1, display_conflictkey, NULL); if( fault && cur->remix_type != REMIX_TYPE_NONE )
atp_show(1, display_conflictkey, NULL);
else status = DISP_KPOS; else status = DISP_KPOS;
} }
else break; else break;
@ -892,7 +874,7 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a
{ {
cur->remix_type = value; cur->remix_type = value;
cur->game_keys = 0; cur->game_keys = 0;
cur->device_keys = 0; cur->device_keys = value == REMIX_TYPE_CHEAT ? DEFAULT_CHEATKEY : 0;
} }
status = DISP_SETK; status = DISP_SETK;
} }
@ -913,11 +895,6 @@ static atp_pageopt_t serve_on_key( atp_callerdata_t data, atp_counter_t index, a
keys_count = 1; keys_count = 1;
text = "HOME"; text = "HOME";
} }
else if( cur->remix_type == REMIX_TYPE_UNLINK )
{
keys_count = 1;
text = "";
}
else if( host > 1 & host != 3 ) // N3DS/N3DSLL/N2DSLL else if( host > 1 & host != 3 ) // N3DS/N3DSLL/N2DSLL
{ {
keys_count = 14; keys_count = 14;

View File

@ -1,8 +1,16 @@
#include "arm11/keyremix.h" #include "arm11/keyremix.h"
#include "arm11/drivers/hid.h"
key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT]; key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT];
static key_remix_t *frozen_start, *frozen_end;
static phykey_t prev_status = 0;
static conkey_t blind_conkey;
static u16 flags_holding = 0;
#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)
uint16_t keyremix_cheatkey() uint16_t keyremix_cheatkey()
{ {
for(int i=0; i < KEY_REMIX_LIMIT; ++i) for(int i=0; i < KEY_REMIX_LIMIT; ++i)
@ -10,15 +18,85 @@ uint16_t keyremix_cheatkey()
if( g_keyremixConfig[i].remix_type == REMIX_TYPE_CHEAT ) if( g_keyremixConfig[i].remix_type == REMIX_TYPE_CHEAT )
return g_keyremixConfig[i].game_keys; return g_keyremixConfig[i].game_keys;
} }
return KEY_DOWN|KEY_L|KEY_R|KEY_SELECT; return DEFAULT_CHEATKEY;
} }
void keyremix_freeze() void keyremix_freeze()
{ {
//TODO //
key_remix_t temp[KEY_REMIX_LIMIT+1];
int j=1, has_cheat=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 )
{
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 )
{
temp[j].remix_type = p->remix_type;
temp[j].device_keys = p->device_keys;
temp[j].remix_type = p->remix_type;
if( p->device_keys & CON_KEY_MASK )
blind_conkey |= p->device_keys;
++j;
}
}
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];
}
} }
void keyremix_update() void keyremix_update( uint16_t active_cheatkey )
{ {
//TODO phykey_t now = hidKeysHeld();
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) )
{
*hid_mode = active_cheatkey;
*hid_set = ~active_cheatkey;
}
else
{
conkey_t res = now & CON_KEY_MASK;
// LGY_handleOverrides
if(now & KEY_CPAD_MASK)
res |= (now>>24) & KEY_DPAD_MASK;
// unlink the blind console keys
res &= ~blind_conkey;
for( key_remix_t *p=frozen_start; p !=frozen_end; ++p )
{
if( p->remix_type == REMIX_TYPE_REMAP )
{
if( now & p->device_keys )
{
res |= p->game_keys;
}
}
}
prev_status = now;
}
} }

View File

@ -1135,15 +1135,7 @@ Result oafInitAndRun(void)
void oafUpdate(void) void oafUpdate(void)
{ {
keyremix_update(); keyremix_update( detect_cheatKey );
if( detect_cheatKey && (hidGetExtraKeys(0) & KEY_HOME) ) // press home as cheat keys
{
vu16 *hid_set = (vu16*)0x10141112;
vu16 *hid_mode = (vu16*)0x10141110;
*hid_mode = detect_cheatKey;
*hid_set = ~detect_cheatKey;
}
else LGY_handleOverrides();
waitForEvent(g_frameReadyEvent); waitForEvent(g_frameReadyEvent);
} }