Skip to content

Commit

Permalink
SNES/PCE/SMS: Added missing "allow invalid input" option (and prevent…
Browse files Browse the repository at this point in the history
… invalid inputs by default)
  • Loading branch information
SourMesen committed Dec 20, 2024
1 parent 32ab5cf commit 88210b3
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 124 deletions.
12 changes: 12 additions & 0 deletions Core/PCE/Input/PceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ class PceController : public BaseControlDevice
ClearBit(Buttons::Run);
ClearBit(Buttons::Select);
}

if(!_emu->GetSettings()->GetPcEngineConfig().AllowInvalidInput) {
//If both U+D or L+R are pressed at the same time, act as if neither is pressed
if(IsPressed(Buttons::Up) && IsPressed(Buttons::Down)) {
ClearBit(Buttons::Down);
ClearBit(Buttons::Up);
}
if(IsPressed(Buttons::Left) && IsPressed(Buttons::Right)) {
ClearBit(Buttons::Left);
ClearBit(Buttons::Right);
}
}
}

void RefreshStateBuffer() override
Expand Down
12 changes: 12 additions & 0 deletions Core/SMS/Input/SmsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ class SmsController : public BaseControlDevice
SetPressedState(Buttons::A, keyMapping.TurboA);
SetPressedState(Buttons::B, keyMapping.TurboB);
}

if(!_emu->GetSettings()->GetSmsConfig().AllowInvalidInput) {
//If both U+D or L+R are pressed at the same time, act as if neither is pressed
if(IsPressed(Buttons::Up) && IsPressed(Buttons::Down)) {
ClearBit(Buttons::Down);
ClearBit(Buttons::Up);
}
if(IsPressed(Buttons::Left) && IsPressed(Buttons::Right)) {
ClearBit(Buttons::Left);
ClearBit(Buttons::Right);
}
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions Core/SNES/Input/SnesController.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch.h"
#include "SNES/Input/SnesController.h"
#include "Shared/Emulator.h"
#include "Shared/EmuSettings.h"
#include "Shared/InputHud.h"

SnesController::SnesController(Emulator* emu, uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(emu, ControllerType::SnesController, port, keyMappings)
Expand Down Expand Up @@ -39,6 +40,19 @@ void SnesController::InternalSetStateFromInput()
SetPressedState(Buttons::L, keyMapping.TurboL);
SetPressedState(Buttons::R, keyMapping.TurboR);
}

bool allowInvalidInput = _emu->GetConsoleType() == ConsoleType::Nes ? _emu->GetSettings()->GetNesConfig().AllowInvalidInput : _emu->GetSettings()->GetSnesConfig().AllowInvalidInput;
if(!allowInvalidInput) {
//If both U+D or L+R are pressed at the same time, act as if neither is pressed
if(IsPressed(Buttons::Up) && IsPressed(Buttons::Down)) {
ClearBit(Buttons::Down);
ClearBit(Buttons::Up);
}
if(IsPressed(Buttons::Left) && IsPressed(Buttons::Right)) {
ClearBit(Buttons::Left);
ClearBit(Buttons::Right);
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Core/Shared/SettingTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ struct PcEngineConfig
ControllerConfig Port1;
ControllerConfig Port1SubPorts[5];

bool AllowInvalidInput = false;
bool PreventSelectRunReset = false;

PceConsoleType ConsoleType = PceConsoleType::Auto;
Expand Down Expand Up @@ -542,6 +543,7 @@ struct SnesConfig

ConsoleRegion Region = ConsoleRegion::Auto;

bool AllowInvalidInput = false;
bool BlendHighResolutionModes = false;
bool HideBgLayer1 = false;
bool HideBgLayer2 = false;
Expand Down Expand Up @@ -693,6 +695,7 @@ struct SmsConfig

SmsRevision Revision = SmsRevision::Compatibility;

bool AllowInvalidInput = false;
bool UseSgPalette = false;
bool GgBlendFrames = true;
bool RemoveSpriteLimit = false;
Expand Down
3 changes: 3 additions & 0 deletions UI/Config/PcEngineConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class PcEngineConfig : BaseConfig<PcEngineConfig>
[Reactive] public ControllerConfig Port1D { get; set; } = new();
[Reactive] public ControllerConfig Port1E { get; set; } = new();

[Reactive] public bool AllowInvalidInput { get; set; } = false;
[Reactive] public bool PreventSelectRunReset { get; set; } = true;

[Reactive] public PceConsoleType ConsoleType { get; set; } = PceConsoleType.Auto;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void ApplyConfig()
Port1D = Port1D.ToInterop(),
Port1E = Port1E.ToInterop(),

AllowInvalidInput = this.AllowInvalidInput,
PreventSelectRunReset = PreventSelectRunReset,

ConsoleType = ConsoleType,
Expand Down Expand Up @@ -119,6 +121,7 @@ public struct InteropPcEngineConfig
public InteropControllerConfig Port1D;
public InteropControllerConfig Port1E;

[MarshalAs(UnmanagedType.I1)] public bool AllowInvalidInput;
[MarshalAs(UnmanagedType.I1)] public bool PreventSelectRunReset;

public PceConsoleType ConsoleType;
Expand Down
4 changes: 4 additions & 0 deletions UI/Config/SmsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class SmsConfig : BaseConfig<SmsConfig>
[Reactive] public SmsControllerConfig Port1 { get; set; } = new();
[Reactive] public SmsControllerConfig Port2 { get; set; } = new();

[Reactive] public bool AllowInvalidInput { get; set; } = false;

[ValidValues(ConsoleRegion.Auto, ConsoleRegion.Ntsc, ConsoleRegion.Pal)]
[Reactive] public ConsoleRegion Region { get; set; } = ConsoleRegion.Auto;

Expand Down Expand Up @@ -59,6 +61,7 @@ public void ApplyConfig()
RamPowerOnState = RamPowerOnState,
Revision = Revision,

AllowInvalidInput = this.AllowInvalidInput,
UseSgPalette = UseSgPalette,
GgBlendFrames = GgBlendFrames,
RemoveSpriteLimit = RemoveSpriteLimit,
Expand Down Expand Up @@ -95,6 +98,7 @@ public struct InteropSmsConfig
public RamState RamPowerOnState;
public SmsRevision Revision;

[MarshalAs(UnmanagedType.I1)] public bool AllowInvalidInput;
[MarshalAs(UnmanagedType.I1)] public bool UseSgPalette;
[MarshalAs(UnmanagedType.I1)] public bool GgBlendFrames;
[MarshalAs(UnmanagedType.I1)] public bool RemoveSpriteLimit;
Expand Down
5 changes: 5 additions & 0 deletions UI/Config/SnesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class SnesConfig : BaseConfig<SnesConfig>
[Reactive] public SnesControllerConfig Port2C { get; set; } = new SnesControllerConfig();
[Reactive] public SnesControllerConfig Port2D { get; set; } = new SnesControllerConfig();

[Reactive] public bool AllowInvalidInput { get; set; } = false;

[ValidValues(ConsoleRegion.Auto, ConsoleRegion.Ntsc, ConsoleRegion.Pal)]
[Reactive] public ConsoleRegion Region { get; set; } = ConsoleRegion.Auto;

Expand Down Expand Up @@ -88,6 +90,8 @@ public void ApplyConfig()

Region = this.Region,

AllowInvalidInput = this.AllowInvalidInput,

BlendHighResolutionModes = this.BlendHighResolutionModes,
HideBgLayer1 = this.HideBgLayer1,
HideBgLayer2 = this.HideBgLayer2,
Expand Down Expand Up @@ -146,6 +150,7 @@ public struct InteropSnesConfig

public ConsoleRegion Region;

[MarshalAs(UnmanagedType.I1)] public bool AllowInvalidInput;
[MarshalAs(UnmanagedType.I1)] public bool BlendHighResolutionModes;
[MarshalAs(UnmanagedType.I1)] public bool HideBgLayer1;
[MarshalAs(UnmanagedType.I1)] public bool HideBgLayer2;
Expand Down
14 changes: 12 additions & 2 deletions UI/Localization/resources.en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Control ID="grpControllers">Controllers</Control>
<Control ID="grpGeneral">General</Control>
<Control ID="chkAutoConfigureInput">Automatically configure controllers when loading a game</Control>
<Control ID="chkAllowInvalidInput">Allow invalid input (e.g Down + Up or Left + Right at the same time)</Control>
<Control ID="lblLightDetectionRadius">Light detection radius for light guns:</Control>
<Control ID="lblSmall">Small</Control>
<Control ID="lblLarge">Large</Control>
Expand Down Expand Up @@ -88,6 +89,10 @@
<Control ID="lblMultitap2D">Port 4:</Control>
<Control ID="grpMultitap">Multitap Configuration</Control>
<Control ID="lblKeyBinding">Warning: Your current configuration contains conflicting key bindings - some physical buttons on your keyboard or gamepad are mapped to multiple buttons on the NES controller. If this is not intentional, please review and correct your key bindings.</Control>

<Control ID="grpControllers">Controllers</Control>
<Control ID="grpGeneral">General</Control>
<Control ID="chkAllowInvalidInput">Allow invalid input (e.g Down + Up or Left + Right at the same time)</Control>
</Form>
<Form ID="InputConfigView">
<Control ID="tpgGeneral">General</Control>
Expand Down Expand Up @@ -352,7 +357,6 @@
<Control ID="chkEnableDmcSampleDuplicationGlitch">Enable DMC sample duplication glitch (late-G &amp; H CPU behavior)</Control>
<Control ID="chkEnableCpuTestMode">Enable CPU test mode registers</Control>
<Control ID="lblConsoleType">Console model:</Control>
<Control ID="chkAllowInvalidInput">Allow invalid input (e.g Down + Up or Left + Right at the same time)</Control>
</Form>

<Form ID="GameboyConfigView">
Expand All @@ -362,6 +366,7 @@

<Control ID="tpgEmulation">Emulation</Control>
<Control ID="lblRamPowerOnState">Default power on state for RAM: </Control>
<Control ID="grpGeneral">General</Control>
<Control ID="chkAllowInvalidInput">Allow invalid input (e.g Down + Up or Left + Right at the same time)</Control>

<Control ID="tpgVideo">Video</Control>
Expand Down Expand Up @@ -406,6 +411,7 @@
<Control ID="lblSaveType">Save Type:</Control>
<Control ID="lblRtcType">Real-Time Clock:</Control>
<Control ID="lblRamPowerOnState">Default power on state for RAM: </Control>
<Control ID="grpGeneral">General</Control>
<Control ID="chkAllowInvalidInput">Allow invalid input (e.g Down + Up or Left + Right at the same time)</Control>
<Control ID="chkEnableMgbaLogApi">Enable mGBA log API</Control>

Expand Down Expand Up @@ -502,7 +508,8 @@
<Control ID="lblPort1D">Port 4:</Control>
<Control ID="lblPort1E">Port 5:</Control>

<Control ID="grpInputSettings">Input settings</Control>
<Control ID="grpGeneral">General</Control>
<Control ID="chkAllowInvalidInput">Allow invalid input (e.g Down + Up or Left + Right at the same time)</Control>
<Control ID="chkPreventSelectRunReset">Disable Run+Select combination (to avoid resets in games)</Control>
</Form>

Expand Down Expand Up @@ -559,6 +566,9 @@
<Control ID="lblController2">Port 2:</Control>

<Control ID="grpGeneral">General</Control>

<Control ID="grpGeneral">General</Control>
<Control ID="chkAllowInvalidInput">Allow invalid input (e.g Down + Up or Left + Right at the same time)</Control>
</Form>

<Form ID="OtherConsolesConfigView">
Expand Down
28 changes: 16 additions & 12 deletions UI/Views/GameboyConfigView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,27 @@
<TextBlock Text="{l:Translate lblRamPowerOnState}" />
<c:EnumComboBox SelectedItem="{Binding Config.RamPowerOnState}" Width="200" />
</StackPanel>
<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="{l:Translate tpgInput}">
<ScrollViewer AllowAutoHide="False" HorizontalScrollBarVisibility="Auto" Padding="0 0 2 0">
<c:OptionSection Header="{l:Translate grpControllers}" Margin="0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Translate lblPlayer1}" />
<Button
Margin="10 0 0 0"
Command="{Binding SetupPlayer}"
CommandParameter="{Binding $self}"
Content="{l:Translate btnSetup}"
/>
</StackPanel>
</c:OptionSection>
<StackPanel>
<c:OptionSection Header="{l:Translate grpControllers}" Margin="0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Translate lblPlayer1}" />
<Button
Margin="10 0 0 0"
Command="{Binding SetupPlayer}"
CommandParameter="{Binding $self}"
Content="{l:Translate btnSetup}"
/>
</StackPanel>
</c:OptionSection>
<c:OptionSection Header="{l:Translate grpGeneral}">
<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />
</c:OptionSection>
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="{l:Translate tpgVideo}">
Expand Down
26 changes: 15 additions & 11 deletions UI/Views/GbaConfigView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,28 @@
<TextBlock Text="{l:Translate lblRtcType}" Grid.Row="1" />
<c:EnumComboBox SelectedItem="{Binding Config.RtcType}" MinWidth="150" Grid.Row="1" Grid.Column="1" />
</Grid>
<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />
<c:CheckBoxWarning IsChecked="{Binding Config.EnableMgbaLogApi}" Text="{l:Translate chkEnableMgbaLogApi}" />
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="{l:Translate tpgInput}">
<ScrollViewer AllowAutoHide="False" HorizontalScrollBarVisibility="Auto" Padding="0 0 2 0">
<c:OptionSection Header="{l:Translate grpControllers}" Margin="0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Translate lblPlayer1}" />
<Button
Margin="10 0 0 0"
Command="{Binding SetupPlayer}"
CommandParameter="{Binding $self}"
Content="{l:Translate btnSetup}"
<StackPanel>
<c:OptionSection Header="{l:Translate grpControllers}" Margin="0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Translate lblPlayer1}" />
<Button
Margin="10 0 0 0"
Command="{Binding SetupPlayer}"
CommandParameter="{Binding $self}"
Content="{l:Translate btnSetup}"
/>
</StackPanel>
</c:OptionSection>
</StackPanel>
</c:OptionSection>
<c:OptionSection Header="{l:Translate grpGeneral}">
<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />
</c:OptionSection>
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="{l:Translate tpgVideo}">
Expand Down
2 changes: 0 additions & 2 deletions UI/Views/NesConfigView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@
<c:CheckBoxWarning IsChecked="{Binding Config.EnableDmcSampleDuplicationGlitch}" Text="{l:Translate chkEnableDmcSampleDuplicationGlitch}" />
<c:CheckBoxWarning IsChecked="{Binding Config.DisableGameGenieBusConflicts}" Text="{l:Translate chkDisableGameGenieBusConflicts}" />
<c:CheckBoxWarning IsChecked="{Binding Config.DisableFlashSaves}" Text="{l:Translate chkDisableFlashSaves}" />

<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />
</c:OptionSection>
</StackPanel>
</ScrollViewer>
Expand Down
1 change: 1 addition & 0 deletions UI/Views/NesInputConfigView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
</c:OptionSection>
<c:OptionSection Header="{l:Translate grpGeneral}">
<CheckBox IsChecked="{Binding Config.AutoConfigureInput}" Content="{l:Translate chkAutoConfigureInput}" />
<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />

<Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto">
<TextBlock Grid.Row="0" Text="{l:Translate lblLightDetectionRadius}" VerticalAlignment="Top" Margin="0 15 5 0" />
Expand Down
3 changes: 2 additions & 1 deletion UI/Views/PceInputConfigView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@
</Grid>
</c:OptionSection>

<c:OptionSection Header="{l:Translate grpInputSettings}">
<c:OptionSection Header="{l:Translate grpGeneral}">
<StackPanel>
<CheckBox IsChecked="{Binding Config.PreventSelectRunReset}" Content="{l:Translate chkPreventSelectRunReset}" />
<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />
</StackPanel>
</c:OptionSection>
</StackPanel>
Expand Down
6 changes: 6 additions & 0 deletions UI/Views/SmsInputConfigView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
/>
</Grid>
</c:OptionSection>

<c:OptionSection Header="{l:Translate grpGeneral}">
<StackPanel>
<c:CheckBoxWarning IsChecked="{Binding Config.AllowInvalidInput}" Text="{l:Translate chkAllowInvalidInput}" />
</StackPanel>
</c:OptionSection>
</StackPanel>
</ScrollViewer>
</UserControl>
Loading

0 comments on commit 88210b3

Please sign in to comment.