From 03121c69c0f5267cffd9a88112fcc088272b3f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ed=C3=AAnis=20Freindorfer=20Azevedo?= Date: Tue, 20 Aug 2019 16:59:27 -0300 Subject: [PATCH] Add support for autohold buttons. We implement this in the same way it is being done on `vba-rr`. - Fix #414. --- src/wx/cmdevents.cpp | 110 ++++++++++++++++++++++++++++++++++++++++ src/wx/guiinit.cpp | 10 ++++ src/wx/sys.cpp | 9 +++- src/wx/wxvbam.h | 2 +- src/wx/xrc/MainMenu.xrc | 45 +++++++++++++++- 5 files changed, 173 insertions(+), 3 deletions(-) diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index a187c55d..0b3a1000 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -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(); diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index 67419a9b..13e0860c 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -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); diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index af397a93..19bbdf02 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -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; diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index c5ec820e..31747ab3 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -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) diff --git a/src/wx/xrc/MainMenu.xrc b/src/wx/xrc/MainMenu.xrc index c9b9b12d..fe953910 100644 --- a/src/wx/xrc/MainMenu.xrc +++ b/src/wx/xrc/MainMenu.xrc @@ -363,7 +363,7 @@ 0 - + 0 @@ -411,6 +411,49 @@ 1 + + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + +