VOGONS


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.

Attachments

  • Filename
    SDL.zip
    File size
    101.15 KiB
    Downloads
    215 downloads
    File license
    Fair use/fair dealing exception
Last edited by h-a-l-9000 on 2006-05-24, 18:45. Edited 1 time in total.

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 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.

Attachments

  • Filename
    polling_reduction.diff
    File size
    3.61 KiB
    Downloads
    223 downloads
    File license
    Fair use/fair dealing exception

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 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 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);