First post, by Hidden Asbestos
Hi all, sorry this is probably the wrong way to submit a patch but it's not a big one so I hope you can forgive me. 😅
I added "deadzone" support to DOSBox 0.74 after finding my Xbox360's thumbstick was a little noisy in the centre.
Here are the changes I made to add this feature:
dosbox.cpp, DOSBOX_Init, line 605
Pbool->Set_help("enable button wrapping at the number of emulated buttons.");
Pint = secprop->Add_int("deadzone",Property::Changeable::WhenIdle,0);
Pint->Set_help("specify the percentage of motion to ignore. Use 100 for a fake digital effect.");
secprop=control->AddSection_prop("serial",&SERIAL_Init,true);
joystick.cpp
static float deadzone = 0;
static float ApplyDeadZone( const float v )
{
if ( deadzone >= 1.0f )
{
if ( v < -0.5f ) {
return -1.0f;
} else if ( v > 0.5f ) {
return +1.0f;
} else {
return 0;
}
}
else
{
float r;
if ( v < 0 )
{
r = ( -v - deadzone ) / ( 1.0f - deadzone );
return ( r < 0 ) ? 0 : -r;
}
else
{
r = ( +v - deadzone ) / ( 1.0f - deadzone );
return ( r < 0 ) ? 0 : +r;
}
}
}
void JOYSTICK_Move_X(Bitu which,float x) {
if (which<2) {
stick[which].xpos=ApplyDeadZone( x );
}
}
void JOYSTICK_Move_Y(Bitu which,float y) {
if (which<2) {
stick[which].ypos=ApplyDeadZone( y );
}
}
swap34 = section->Get_bool("swap34");
button_wrapping_enabled = section->Get_bool("buttonwrap");
deadzone = ((float)section->Get_int("deadzone"))/100.0f;
if ( deadzone < 0 ) {
deadzone = 0;
}
stick[0].enabled = false;
stick[1].enabled = false;
Simple as that. Feel free to include, modify or ignore this patch - I submit it freely.
To use the deadzone feature add:
deadzone=%value%
into your dosbox.conf file, where %value% is a number from 0 to 99 (my 360 pad works well with ~15). Also a bonus feature - If you set it to 100 or more then it switches into a kind of fake d-pad mode where any movement over half way counts as 100%, otherwise zero.