VOGONS


First post, by Hidden Asbestos

User metadata
Rank Newbie
Rank
Newbie

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.

Reply 1 of 7, by Graekynn

User metadata
Rank Newbie
Rank
Newbie

Hi! This is exactly what I need. Unfortauntely Im a bit new to this and not sure where the files are that you are referring to. Im using DOSBOX 0.74 GUI through DOG.

Im wondering if this could be used with my dosbox version, and if so how do I enter it? Im hoping its not too much to ask to compile this into a patch I can download and run.

I am grateful for any assistance you can provide. I just hope you see this message! 😀

cheers!

Reply 2 of 7, by Hidden Asbestos

User metadata
Rank Newbie
Rank
Newbie

Hey, I compiled you a dosbox 0.74 exe with my patch applied. Get it here: http://www.hiddenasbestos.com/share/dosbox-0.74-deadzone.zip (~1Mb)

The required DLLs are included too in case they differ from the official release, so feel free to ignore them if you don't get any missing dll errors.

Hope it works for you - I just gave it a quick test on TIE Fighter and it seems to behave correctly still, but obviously I disclaim any responsibility if it does something wrong for you 😉 I'm not an expert at compiling dosbox, but it seems to work okay and at a good speed, etc.

Regards,
David

Reply 4 of 7, by nitro322

User metadata
Rank Newbie
Rank
Newbie

Thanks, David. This is a handy patch. Would you mind also providing just the patch file? It would make it a bit easier for non-Windows users, and hopefully encourage the upstream developers to include this in the next version. I think that'd be a much better long-term solution, as it'd be much easier for all dosbox users to benefit from your work.

Reply 5 of 7, by Hidden Asbestos

User metadata
Rank Newbie
Rank
Newbie

You're welcome. If you're just looking for the deadzone patch it's the same as in my original post, otherwise the full download is only a 1.2Mb ZIP file to get at the patch file for both new features.

Reply 6 of 7, by wuanche

User metadata
Rank Newbie
Rank
Newbie

Hi, first of all i am sorry about my english it is very bad...

Thanks for your patch it looks great. I was looking for this feature long time. I have some problems with few games at DOSBox because my joystick pad needs a deadzone, it is very sensible. GREAT WORK. but...

I still need you help dear dear Hidden Asbestos 😀

I am very bad as programmer and i am not a Windows user...

I think the first part of your code (dosbox.cpp, DOSBOX_Init, line 605) is clear enough for dummy like me 😀

But i have some problems compiling joystick.cpp:

g++ -DHAVE_CONFIG_H -I. -I../..  -I../../include -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT  -g -O2  -MT joystick.o -MD -MP -MF .deps/joystick.Tpo -c -o joystick.o joystick.cpp
joystick.cpp: In function ‘void JOYSTICK_Move_X(Bitu, float)’:
joystick.cpp:78: error: ‘stick’ was not declared in this scope
joystick.cpp: In function ‘void JOYSTICK_Move_Y(Bitu, float)’:
joystick.cpp:84: error: ‘stick’ was not declared in this scope
joystick.cpp: At global scope:
joystick.cpp:90: error: expected constructor, destructor, or type conversion before ‘=’ token

Could you link a patched version of dosbox.cpp and joystick.cpp ? Thank you in advance.

In other way, i think you did a great work and you added a great feature to DOSBox. Have you ever thought to submit this feature to Sourceforge to SVN ?

Reply 7 of 7, by Jekhar

User metadata
Rank Newbie
Rank
Newbie

I just registered to say thank you! I was really bummed out DOSBox didn't provide any deadzone settings out of the box, but now i can finally use my Xbox Pad for games requiring analogue input. I hope this fix finds it way into the next DOSBox release, it's too useful not to.