Add support for autohold buttons.

We implement this in the same way it is being done on `vba-rr`.

- Fix #414.
This commit is contained in:
Edênis Freindorfer Azevedo 2019-08-20 16:59:27 -03:00 committed by Rafael Kitover
parent e87213e369
commit 03121c69c0
5 changed files with 173 additions and 3 deletions

View File

@ -1426,6 +1426,116 @@ EVT_HANDLER(JoypadAutofireR, "Autofire R (toggle)")
GetMenuOptionInt("JoypadAutofireR", autofire, KEYM_R);
}
EVT_HANDLER(JoypadAutoholdUp, "Autohold Up (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdUp";
int keym = KEYM_UP;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdDown, "Autohold Down (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdDown";
int keym = KEYM_DOWN;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdLeft, "Autohold Left (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdLeft";
int keym = KEYM_LEFT;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdRight, "Autohold Right (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdRight";
int keym = KEYM_RIGHT;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdA, "Autohold A (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdA";
int keym = KEYM_A;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdB, "Autohold B (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdB";
int keym = KEYM_B;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdL, "Autohold L (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdL";
int keym = KEYM_L;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdR, "Autohold R (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdR";
int keym = KEYM_R;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdSelect, "Autohold Select (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdSelect";
int keym = KEYM_SELECT;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER(JoypadAutoholdStart, "Autohold Start (toggle)")
{
bool menuPress;
char keyName[] = "JoypadAutoholdStart";
int keym = KEYM_START;
GetMenuOptionBool(keyName, menuPress);
toggleBitVar(&menuPress, &autohold, keym);
SetMenuOption(keyName, menuPress ? 1 : 0);
GetMenuOptionInt(keyName, autohold, keym);
}
EVT_HANDLER_MASK(LoadGameRecent, "Load most recent save", CMDEN_SAVST)
{
panel->LoadState();

View File

@ -2948,6 +2948,16 @@ bool MainFrame::BindControls()
MenuOptionIntMask("JoypadAutofireB", autofire, KEYM_B);
MenuOptionIntMask("JoypadAutofireL", autofire, KEYM_L);
MenuOptionIntMask("JoypadAutofireR", autofire, KEYM_R);
MenuOptionIntMask("JoypadAutoholdUp", autohold, KEYM_UP);
MenuOptionIntMask("JoypadAutoholdDown", autohold, KEYM_DOWN);
MenuOptionIntMask("JoypadAutoholdLeft", autohold, KEYM_LEFT);
MenuOptionIntMask("JoypadAutoholdRight", autohold, KEYM_RIGHT);
MenuOptionIntMask("JoypadAutoholdA", autohold, KEYM_A);
MenuOptionIntMask("JoypadAutoholdB", autohold, KEYM_B);
MenuOptionIntMask("JoypadAutoholdL", autohold, KEYM_L);
MenuOptionIntMask("JoypadAutoholdR", autohold, KEYM_R);
MenuOptionIntMask("JoypadAutoholdSelect", autohold, KEYM_SELECT);
MenuOptionIntMask("JoypadAutoholdStart", autohold, KEYM_START);
MenuOptionBool("EmulatorSpeedupToggle", turbo);
MenuOptionIntRadioValue("LinkType0Nothing", gopts.gba_link_type, 0);
MenuOptionIntRadioValue("LinkType1Cable", gopts.gba_link_type, 1);

View File

@ -29,7 +29,7 @@ uint16_t systemGbPalette[24] = {
int RGB_LOW_BITS_MASK;
// these are local, though.
int joypress[4], autofire;
int joypress[4], autofire, autohold;
static int sensorx[4], sensory[4], sensorz[4];
bool pause_next;
bool turbo;
@ -261,6 +261,13 @@ uint32_t systemReadJoypad(int joy)
af |= KEYM_B;
}
uint32_t ah = autohold;
uint32_t ah_but = ah | ret;
if (ah_but)
{
ret ^= ah;
}
static int autofire_trigger = 1;
static bool autofire_state = true;
uint32_t af_but = af & ret;

View File

@ -779,7 +779,7 @@ void systemStopGamePlayback();
extern bool turbo;
// mask of key press flags; see below
extern int joypress[4], autofire;
extern int joypress[4], autofire, autohold;
// FIXME: these defines should be global to project and used instead of raw numbers
#define KEYM_A (1 << 0)

View File

@ -363,7 +363,7 @@
<label>_Decrease volume</label>
<enabled>0</enabled>
</object>
<object class="wxMenuItem" name="ToggleSound">
<object class="wxMenuItem" name="ToggleSound">
<label>_Toggle sound</label>
<checkable>0</checkable>
</object>
@ -411,6 +411,49 @@
<checkable>1</checkable>
</object>
</object>
<object class="wxMenu">
<label>_Autohold</label>
<object class="wxMenuItem" name="JoypadAutoholdUp">
<label>_Up</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdDown">
<label>_Down</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdLeft">
<label>_Left</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdRight">
<label>_Right</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdA">
<label>_A</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdB">
<label>_B</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdL">
<label>_L</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdR">
<label>_R</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdSelect">
<label>_Select</label>
<checkable>1</checkable>
</object>
<object class="wxMenuItem" name="JoypadAutoholdStart">
<label>_Start</label>
<checkable>1</checkable>
</object>
</object>
</object>
<object class="wxMenu">
<label>_Game Boy Advance</label>