Skip to content

Commit

Permalink
add option to change between hold and toggle turbo mode
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Sep 19, 2015
1 parent ed75dd7 commit 4e9f297
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 21 deletions.
6 changes: 5 additions & 1 deletion ControllerInput.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef NO_XBOX
#include "ControllerInput.h"
#include "EmulatorSettings.h"

namespace VBA10
{
Expand All @@ -25,7 +26,10 @@ namespace VBA10
{
XINPUT_STATE state = this->xboxPad->GetState();

this->state.TurboTogglePressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
if (EmulatorSettings::Current->TurboBehavior == 0)
this->state.TurboTogglePressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
else
this->state.TurboPressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);

this->state.LeftPressed = ((state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (state.Gamepad.sThumbLX < (-XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)));
this->state.RightPressed = ((state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) || (state.Gamepad.sThumbLX > (XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)));
Expand Down
14 changes: 14 additions & 0 deletions EmulatorSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ namespace VBA10
}
}

property int TurboBehavior
{
int get()
{
return GetValueOrDefault<int>(TurboBehaviorKey, TurboBehaviorDefault);
}
void set(int value)
{
AddOrUpdateValue(TurboBehaviorKey, value);
}
}


#pragma region Button positions

Expand Down Expand Up @@ -607,6 +619,7 @@ namespace VBA10
Platform::String^ ThemeKey = "ThemeKey";
Platform::String^ SmoothButtonKey = "SmoothButtonKey";
Platform::String^ HideHamburgerKey = "HideHamburgerKey";
Platform::String^ TurboBehaviorKey = "TurboBehaviorKey";

#pragma region button positions
Platform::String^ PadLeftPKey = "PadLeftPKey";
Expand Down Expand Up @@ -660,6 +673,7 @@ namespace VBA10
const int ThemeDefault = 0;
const int SmoothButtonDefault = 3;
const bool HideHamburgerDefault = false;
const int TurboBehaviorDefault = 0;



Expand Down
19 changes: 14 additions & 5 deletions HIDControllerInput.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "HIDControllerInput.h"
#include "EmulatorSettings.h"

using namespace Windows::Devices::HumanInterfaceDevice;
using namespace Platform::Collections;
Expand Down Expand Up @@ -107,6 +108,8 @@ namespace VBA10
if (this->shouldUpdate == false)
return;

bool turboButtonPressed = false;

//check buttons
auto bcontrols = inputReport->ActivatedBooleanControls;

Expand All @@ -118,7 +121,7 @@ namespace VBA10

if (booleanControlMapping->HasKey(id))
GetMapping(booleanControlMapping->Lookup(id), &state.LeftPressed, &state.RightPressed, &state.UpPressed, &state.DownPressed,
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &state.TurboTogglePressed);
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &turboButtonPressed);
}

//check numeric control
Expand All @@ -135,29 +138,35 @@ namespace VBA10
{
if (controlExt->Mapping->HasKey(1))
GetMapping(controlExt->Mapping->Lookup(1), &state.LeftPressed, &state.RightPressed, &state.UpPressed, &state.DownPressed,
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &state.TurboTogglePressed);
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &turboButtonPressed);
}
else if (controlExt->Type == 1 && control->Value - controlExt->DefaultValue < -0.25 * controlExt->DefaultValue) //axis-
{
if (controlExt->Mapping->HasKey(-1))
GetMapping(controlExt->Mapping->Lookup(-1), &state.LeftPressed, &state.RightPressed, &state.UpPressed, &state.DownPressed,
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &state.TurboTogglePressed);
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &turboButtonPressed);
}
else if (controlExt->Type == 1 && control->Value - controlExt->DefaultValue > 0.25 * controlExt->DefaultValue) //axis+
{
if (controlExt->Mapping->HasKey(1))
GetMapping(controlExt->Mapping->Lookup(1), &state.LeftPressed, &state.RightPressed, &state.UpPressed, &state.DownPressed,
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &state.TurboTogglePressed);
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &turboButtonPressed);
}
else if (controlExt->Type == 2 && control->Value != controlExt->DefaultValue) //hat d-pad
{
if (controlExt->Mapping->HasKey(control->Value))
GetMapping(controlExt->Mapping->Lookup(control->Value), &state.LeftPressed, &state.RightPressed, &state.UpPressed, &state.DownPressed,
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &state.TurboTogglePressed);
&state.APressed, &state.BPressed, &state.LPressed, &state.RPressed, &state.SelectPressed, &state.StartPressed, &turboButtonPressed);
}
}


//transfer turbo button press to appropriate turbo behavior
if (EmulatorSettings::Current->TurboBehavior == 0)
state.TurboTogglePressed = turboButtonPressed;
else
state.TurboPressed = turboButtonPressed;

}

void HIDControllerInput::Update(bool shouldUpdate)
Expand Down
5 changes: 4 additions & 1 deletion KeyboardInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ namespace VBA10
{
ZeroMemory(&state, sizeof(ControllerState));

this->state.TurboTogglePressed = (bool)(window->GetKeyState(GetTurboKeyBinding()) & CoreVirtualKeyStates::Down);
if (EmulatorSettings::Current->TurboBehavior == 0)
this->state.TurboTogglePressed = (bool)(window->GetKeyState(GetTurboKeyBinding()) & CoreVirtualKeyStates::Down);
else
this->state.TurboPressed = (bool)(window->GetKeyState(GetTurboKeyBinding()) & CoreVirtualKeyStates::Down);

this->state.StartPressed = (bool)(window->GetKeyState(GetStartKeyBinding()) & CoreVirtualKeyStates::Down);
this->state.SelectPressed = (bool)(window->GetKeyState(GetSelectKeyBinding()) & CoreVirtualKeyStates::Down);
Expand Down
2 changes: 1 addition & 1 deletion Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="16994Sparksoft.VBA10" Publisher="CN=9289A21E-3389-49E2-A9E0-46AA1289C3CB" Version="1.12.162.0" />
<Identity Name="16994Sparksoft.VBA10" Publisher="CN=9289A21E-3389-49E2-A9E0-46AA1289C3CB" Version="1.13.165.0" />
<mp:PhoneIdentity PhoneProductId="2b9558e5-6253-426c-8989-3284f508e743" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>VBA10</DisplayName>
Expand Down
15 changes: 13 additions & 2 deletions SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,19 @@
Header="D-Pad Style"
Margin =" 0, 0, 0, 12">
<ComboBoxItem>8-way</ComboBoxItem>
<ComboBoxItem>fixed analogue stick</ComboBoxItem>
<ComboBoxItem>dynamic analogue stick</ComboBoxItem>
<ComboBoxItem>Fixed analogue stick</ComboBoxItem>
<ComboBoxItem>Dynamic analogue stick</ComboBoxItem>
</ComboBox>

<ComboBox Name="cboTurboBehavior"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
SelectedIndex="0"
Header="Turbo Button Behavior"
Margin =" 0, 0, 0, 12"
SelectionChanged="cboTurboBehavior_SelectionChanged">
<ComboBoxItem>Toggle turbo on/off</ComboBoxItem>
<ComboBoxItem>Hold to activate</ComboBoxItem>
</ComboBox>

<Button x:Name="editButonLayoutBtn"
Expand Down
10 changes: 10 additions & 0 deletions SettingsPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ SettingsPage::SettingsPage()
this->controllerOpacitySlider->Value = (double)GetControllerOpacity();
this->deadzoneSlider->Value = (double)GetDeadzone();
this->dpadComboBox->SelectedIndex = EmulatorSettings::Current->DPadStyle;
this->cboTurboBehavior->SelectedIndex = EmulatorSettings::Current->TurboBehavior;

//change the settings that depend on enabletouchcontrol
touchToggle_Toggled(nullptr, nullptr);
Expand Down Expand Up @@ -715,3 +716,12 @@ void SettingsPage::hideHamburgerToggle_Toggled(Platform::Object^ sender, Windows
EmulatorSettings::Current->HideHamburger = this->hideHamburgerToggle->IsOn;
}
}


void SettingsPage::cboTurboBehavior_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
{
if (initdone)
{
EmulatorSettings::Current->TurboBehavior = this->cboTurboBehavior->SelectedIndex;
}
}
1 change: 1 addition & 0 deletions SettingsPage.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ namespace VBA10
void cboTheme_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void editButonLayoutBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void hideHamburgerToggle_Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void cboTurboBehavior_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
};
}
5 changes: 4 additions & 1 deletion VirtualControllerInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ namespace VBA10
}
if (this->turboRect.Contains(point))
{
this->state.TurboTogglePressed = true;
if (EmulatorSettings::Current->TurboBehavior == 0)
this->state.TurboTogglePressed = true;
else
this->state.TurboPressed = true;
}
if (this->comboRect.Contains(point))
{
Expand Down
26 changes: 16 additions & 10 deletions vbaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,22 @@ u32 systemReadJoypad(int gamepad)
}
}

if(EmulatorSettings::Current->EnableTurbo &&
(oldKeyboardState.TurboPressed && !keyboardState->TurboPressed) ||
(oldControllerState.TurboPressed && !controllerState->TurboPressed) ||
(oldvControllerState.TurboPressed && !vControllerState->TurboPressed) ||
(oldHidState.TurboPressed && !hidState->TurboPressed))
{
EmulatorSettings::Current->EnableTurbo = false;
}

if(EmulatorSettings::Current->EnableTurbo || keyboardState->TurboPressed || controllerState->TurboPressed || vControllerState->TurboPressed || hidState->TurboPressed)
//if(EmulatorSettings::Current->EnableTurbo &&
// (oldKeyboardState.TurboPressed && !keyboardState->TurboPressed) ||
// (oldControllerState.TurboPressed && !controllerState->TurboPressed) ||
// (oldvControllerState.TurboPressed && !vControllerState->TurboPressed) ||
// (oldHidState.TurboPressed && !hidState->TurboPressed))
//{
// EmulatorSettings::Current->EnableTurbo = false;
//}

bool useTurbo = EmulatorSettings::Current->EnableTurbo;

//reverse function if turbopressed
if (keyboardState->TurboPressed || controllerState->TurboPressed || vControllerState->TurboPressed || hidState->TurboPressed)
useTurbo = !useTurbo;

if(useTurbo )
res |= 1024;

oldControllerState = *controllerState;
Expand Down

0 comments on commit 4e9f297

Please sign in to comment.