VOGONS


An attempt to fix the analog gameport issue

Topic actions

First post, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

The attached sdl.dll has the joystick polling frequency changed from insane 1kHz to 50Hz.
My assumption: Querying the joystick position is very time consuming on old gameports (the time it takes to charge a capacitor through the variable resistor in the joystick - real A/D-Converters were expensive back then), it can take more than 1 millisecond according to some tech document, depending on stick position. So SDL tries to run a function, which takes more than 1 ms, every ms. The result would be messed up timing...
Anyone interested and having the issue please test if this is any good. It seems to have reduced the CPU load on one of my computers.

Edit: Now it should really do what it promises. File updated.

Last edited by h-a-l-9000 on 2006-05-24, 18:45. Edited 1 time in total.

Reply 2 of 39, by Marauder

User metadata
Rank Newbie
Rank
Newbie

I tried this to see if it would fix the calibration issue with Strike Commander. It didn't, still gives failure with gameport joystick(Thrustmaster F-22/TQS)

Reply 3 of 39, by HunterZ

User metadata
Rank l33t++
Rank
l33t++

Rewiring a DB-15 bracket for my motherboard's analog joystick/MIDI pin header is still on my to-do list...

Reply 4 of 39, by kilo_echo

User metadata
Rank Newbie
Rank
Newbie

Hi guys,
I tried the dll on my PC for DosBox 0.65 under Win ME. It doesn't improve the gameport issue there. As soon as I define a 2axis Joystick in the .conf and connect the Joystick, CPU load is rising to 100% as soon as I start DosBox - I do not even need to load a game...
CPU is a AMD Sempron 2200+.

Reply 5 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

I just reviewed that thing and found out it is completely wrong... update soon.

1+1=10

Reply 6 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Ok, this time it has some effect 😉 (file is in first post)

1+1=10

Reply 7 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

It can be fixed from Dosbox side.
The patch reduces SDL_PollEvent to being called 50 times a second which should be more than sufficient - humans are awfully slow devices 😁.
This even frees up a little bit of CPU time.

Reply 8 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Cool, thanks.
Any idea why the polling is that high by default?

Reply 9 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Ok, i was assuming that you modified something that has
an effect on the polling inside SDL_PollEvent, so my
question is pointless.
Anyways the SDL_ACTIVEEVENT should be handled as soon as
possible in certain cases, maybe the input events can be
separated from the rest in some way.

Reply 10 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Hmm which cases would that be? Mouse? It will only be delayed up to 20 milliseconds.

1+1=10

Reply 11 of 39, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

the SDL_ACTIVEEVENT deals (for example) with mode switches caused by the OS (alt-tab)
it must be handled fast else the video graphics will render in an invalid buffer and it will crash.

Water flows down the stream
How to ask questions the smart way!

Reply 12 of 39, by kilo_echo

User metadata
Rank Newbie
Rank
Newbie

That is it!
Gameport joystick (Wingman Extreme) works perfectly now on all games, that I tested so far.
I didn't see a crash, but I usually don't Alt-Tab my game away, while I'm smoking a Mig down the sky...

Thanks very much!

Reply 13 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

> but I usually don't Alt-Tab my game away

Need not be user-forced, can happen especially when some program
forces the focus while dosbox is in fullscreen mode (popup messages,
messenger programs etc.)

Reply 14 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

If you use the sdl.dll from up there you are safe anyway as it only limits the joystick.

1+1=10

Reply 15 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Maybe you can put up the patch for sdl as well, imho it's the better solution to the problem.

Reply 16 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

That would be in SDL_events.c:

/* Run the system dependent event loops */
static int SDL_joy_skip2=0;

void SDL_PumpEvents(void)
{
int now;
if ( !SDL_EventThread ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;

/* Get events from the video subsystem */
if ( video ) {
video->PumpEvents(this);
}

/* Queue pending key-repeat events */
SDL_CheckKeyRepeat();

#ifndef DISABLE_JOYSTICK
/* Check for joystick state change */
now=SDL_GetTicks();
if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) &&
((now-SDL_joy_skip2)>50) ) {
SDL_JoystickUpdate();
SDL_joy_skip2=now;
}

/*if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
SDL_JoystickUpdate();
}*/
#endif
}
}

(here it is set to 20 Hz)

It's just that you can increase the cycles noticeable (2000 cycles or so with dyncore on my xp2400) with the Dosbox patch.
Edit: even without joystick.

Reply 17 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Thanks for the diff!

> It's just that you can increase the cycles noticeable (2000 cycles or so
> with dyncore on my xp2400) with the Dosbox patch.

Yes i know, i don't like it being called that often, too, but it was hard to
avoid the crashing when alt-tabbing away from a fullscreen dosbox
(and it still is not really bulletproof), so it should be handled with care
as far as possible.

Reply 18 of 39, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Maybe the joystick-polling interval can be reduced (from the
dosbox side) without affecting the rest, something like this:

void GFX_Events() {
int time=SDL_GetTicks();
if (time-poll_delay>20) {
poll_delay=time;
SDL_EventState(SDL_JOYEVENTMASK,SDL_ENABLE);
} else SDL_EventState(SDL_JOYEVENTMASK,SDL_IGNORE);

Reply 19 of 39, by h-a-l-9000

User metadata
Rank DOSBox Author
Rank
DOSBox Author

I have no idea why but this code makes the keyboard freak out and doesn't help smoothing CPU usage.

1+1=10