mirror of
https://gitee.com/anod/open_agb_firm.git
synced 2025-05-06 22:04:10 +08:00
104 lines
2.9 KiB
C
104 lines
2.9 KiB
C
#include "arm11/keyremix.h"
|
|
|
|
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()
|
|
{
|
|
for(int i=0; i < KEY_REMIX_LIMIT; ++i)
|
|
{
|
|
if( g_keyremixConfig[i].remix_type == REMIX_TYPE_CHEAT )
|
|
return g_keyremixConfig[i].game_keys;
|
|
}
|
|
return DEFAULT_CHEATKEY;
|
|
}
|
|
|
|
void keyremix_freeze()
|
|
{
|
|
//
|
|
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].game_keys = p->game_keys;
|
|
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( uint16_t active_cheatkey )
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
*hid_mode = CON_KEY_MASK;
|
|
*hid_set = ~res;
|
|
}
|
|
prev_status = now;
|
|
} |