The attached patch enhances the joystick emulation in
DOSBox by adding emulation for four axis/four button
joysticks, Thrustmaster FCS, CH Flightstick Pro, and no
joystick. It also allows the user to specify which
joystick to use if more than one is recognized by SDL.
It also incorporates patch #1094216 (fix two joystick
support).
All of this is handled by old-style joystick code--i.e.
the buttons and axes are hard-coded, not run through
the mapper interface. Since it appears the new code has
not been worked on for some time I chose to implement
this functionality first.
These changes do require additions to the config file.
I realize this is to be avoided but this does represent
a choice between distinctly different emulated
hardware, analagous to the machine type choice. Two
fields have been added in a new joystick section (no
other section made sense, and the joystick
initialization could be split off from the CPU section
without changing the order of initialization):
number: Which joystick to use--the first joystick
detected by SDL is 0. Provides some limited flexibility
(this addition is not critical to the other
functionality and can be removed)
type: type of joystick to emulate.
If "type" is "2axis", a pair of two-axis, two-button
joysticks is emulated (current DOSBox code). The second
joystick is number+1--i.e. you can only specify which
joystick is the first. If there is only one joystick
detected by SDL, only one is emulated.
"none": no joystick emulation. Emulated joysticks are
disabled and no joysticks are opened. Useful for using
joy2key or similar in conjunction with dosbox
"4axis": single four-axis, four-button joystick. One
SDL joystick is opened and as many axes and buttons as
it has, up to four, are used. Nonexistent axes are
emulated as centred. (e.g. for a three-axis joystick, a
DOS program will see the last axis as centred).
"fcs": emulate a Thrustmaster FCS joystick, with two
analog axes, four buttons, and a 4-way hat. Some
applications support a system of FCS plus one
additional axis, and this is supported--i.e. if there
is a third axis on the real joystick it is passed
through to the emulator. As far as I can tell the
analog-based FCS does not support 8-way hats, but if a
diagonal event is processed it is handled
intelligently. For example a move from UP to UPLEFT
will be emulated as LEFT, assuming the user wanted to
change hat states and was a little sloppy with the hat,
but a move from LEFT to UPLEFT will be emulated as UP
for the same reason. Note that if the real joystick has
multiple hats, you can use any one of them to access
the emulated hat.
"ch": emulate a CH flightstick pro. There are two
versions of the CH flightstick protocol: four
buttons+one hat and six buttons+two hats. This code
emulates the latter. Because of the way the protocol
works only one event can be handled at a time (pressing
two buttons at once shows up as one button). This code
replicates the behaviour of the hardware accurately in
such cases (there is a priority scheme for which button
of a "chord" is signalled). I understand that the
single hat version may allow chording but I don't have
access to hardware or specs for it. Some applications
support third and fourth axes for the CH Flightstick
and this code will pass the third and fourth axes of
the real joystick through to the emulated machine.
This code has been tested under Linux by both examining
the state of the emulated gameport within the emulated
machine and by running Wing Commander III.
patch against 2 Jan 2005 CVS
Logged In: YES
user_id=120905
I'd very much like to see this joystick code added :)
I added it to my own build using Mingw/Msys on Windows. On
/src/hardware/joystic.cpp I was not sure if I added it
correctly since I'm not a programmer. It compiles and works,
only if there is no physical joystick plugged in, Dosbox
will crash on me if type is not set to none.
Logged In: YES
user_id=535630
I've updated the patch to 6jun 2005.
Could you see if it works for you now Dominus and/or give a
backtrace ?
updated to 6 june cvs
Logged In: YES
user_id=120905
I'm not sure how to set up a backtrace. Patching worked but
Dosbox now crashes when there is no joystick attached to the
PC. Even setting "type=none" doesn't prevent this crash.
The crash message:
Assertion failed!
Program: C:\Programme\Div\Curios\Dosbox\dosbox.exe
File: sdl_mapper.cpp
Line: 339
Expression: sdl_joystick
Hope this helps. I'm availlable for more testing or if you
want to set me up to do a backtrace, best pm me on Vogons.
Logged In: YES
user_id=735408
I'll take a look tonight (EDT), update to the current CVS,
do some testing, and submit a new patch. I must admit I
never tested it with no joysticks :)
(incidentally, dominus, the way to add the code is with the
patch program, not manually, but the CVS has probably
drifted a fair bit in 6 months).
Logged In: YES
user_id=535630
Jon,
The best would be to use my patch as starting point.
I took the liberty to update it so that it merges with the
current cvs.
I disabled the joyno stuff as I don't like it very much.
(not worth an option).
I moved the stuff towards bios init function so it gets a
nice place in the configuration file.
Peter
Logged In: YES
user_id=120905
Now that I know to set things up in the bios section
(proofs, you should always run config -writeconf after not
running dosbox cvs fro some time :)), it runs without
joystick attached, when "joysticktype=none". when set to
anything else it crashes.
(Patch: Back when I first added this patch to my checkout
something need to be added manualy, so I couldn't fully use
patch...)
Logged In: YES
user_id=535630
uhm try the new one.
Added a small check to see wether there are joysticks before
creating an event structure for them.
Logged In: YES
user_id=735408
Peter, your "newone.diff" looks fine to me. I read it
through and did some testing and it behaves as expected.
Good fix with the none-attached problem; can't believe I
didn't test that.
Given that we'll always be reading from SDL stick 0 (or 1,
for the second 2-axis case), it would be possible to
simplify/streamline the code to make that assumption. I
almost made a patch for that, but it would remove a lot of
the framework put in for the "new" joystick code so I'm
inclined to let it be.
Here's my suggestion for a change to the config file help:
" fcs (Thrustmaster), ch (CH Flightstick).\n"
" none disables joystick emulation\n"
" 2axis is the default and supports two joysticks.\n"
(since the joysticks aren't disabled if the emulation is)
Logged In: YES
user_id=535630
Updated it a bit.
This version has now some basic support for timeouts.
Some games do one write to the joystick port and idle a
while and do one read and assume the joystick has timed out.
(for example loderunner)
It feels like it helps a bit with the joystick recognition
in Privateer. (be sure to throw joya.dat away before you
start it).
If this version is allright by the 2 of you I will commit
it. The timeout code can be wrong (or the timeout can have
the wrong value. Be sure to test a few games with it (on
different cycles)
Peter
has some timeout support