Remove Mac OS support
This commit is contained in:
parent
88160be520
commit
f37bcfbd49
13 changed files with 5 additions and 1537 deletions
|
@ -65,7 +65,6 @@ wxString towxstring(const std::string& str);
|
||||||
std::string tostdstring(const wxString& str);
|
std::string tostdstring(const wxString& str);
|
||||||
wxString towxstring(const std::u32string& str);
|
wxString towxstring(const std::u32string& str);
|
||||||
std::u32string tou32string(const wxString& str);
|
std::u32string tou32string(const wxString& str);
|
||||||
void bring_app_foreground();
|
|
||||||
std::string pick_archive_member(wxWindow* parent, const std::string& filename);
|
std::string pick_archive_member(wxWindow* parent, const std::string& filename);
|
||||||
void boot_emulator(emulator_instance& inst, loaded_rom& rom, moviefile& movie, bool fscreen);
|
void boot_emulator(emulator_instance& inst, loaded_rom& rom, moviefile& movie, bool fscreen);
|
||||||
void handle_wx_keyboard(emulator_instance& inst, wxKeyEvent& e, bool polarity);
|
void handle_wx_keyboard(emulator_instance& inst, wxKeyEvent& e, bool polarity);
|
||||||
|
|
|
@ -96,7 +96,6 @@ SOUND=PORTAUDIO
|
||||||
# - EVDEV: EVDEV (Linux only)
|
# - EVDEV: EVDEV (Linux only)
|
||||||
# - WIN32MM: Windows Multimedia (Win32 only).
|
# - WIN32MM: Windows Multimedia (Win32 only).
|
||||||
# - WXWIDGETS: wxWidgets (GRAPHICS=WXWIDGETS only)
|
# - WXWIDGETS: wxWidgets (GRAPHICS=WXWIDGETS only)
|
||||||
# - MACOSX: Mac OS X (Mac OS X only).
|
|
||||||
JOYSTICK=DUMMY
|
JOYSTICK=DUMMY
|
||||||
|
|
||||||
# Set to non-empty value (e.g. 'yes') to enable use of Secret Rabbit Code (a.k.a. libsamperate).
|
# Set to non-empty value (e.g. 'yes') to enable use of Secret Rabbit Code (a.k.a. libsamperate).
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
PLATFORMS=evdev portaudio wxwidgets win32mm libao macosx
|
PLATFORMS=evdev portaudio wxwidgets win32mm libao
|
||||||
ALLFILES=__all__.files
|
ALLFILES=__all__.files
|
||||||
ALLFLAGS=__all__.ldflags
|
ALLFLAGS=__all__.ldflags
|
||||||
PLATFORMS_FILES=$(patsubst %,%/$(ALLFILES),$(PLATFORMS))
|
PLATFORMS_FILES=$(patsubst %,%/$(ALLFILES),$(PLATFORMS))
|
||||||
|
@ -23,9 +23,6 @@ libao/$(ALLFILES): forcelook
|
||||||
wxwidgets/$(ALLFILES): forcelook
|
wxwidgets/$(ALLFILES): forcelook
|
||||||
$(MAKE) -C wxwidgets
|
$(MAKE) -C wxwidgets
|
||||||
|
|
||||||
macosx/$(ALLFILES): forcelook
|
|
||||||
$(MAKE) -C macosx
|
|
||||||
|
|
||||||
.PRECIOUS: %.$(OBJECT_SUFFIX) *.files
|
.PRECIOUS: %.$(OBJECT_SUFFIX) *.files
|
||||||
|
|
||||||
precheck:
|
precheck:
|
||||||
|
@ -34,7 +31,6 @@ precheck:
|
||||||
$(MAKE) -C portaudio precheck
|
$(MAKE) -C portaudio precheck
|
||||||
$(MAKE) -C libao precheck
|
$(MAKE) -C libao precheck
|
||||||
$(MAKE) -C wxwidgets precheck
|
$(MAKE) -C wxwidgets precheck
|
||||||
$(MAKE) -C macosx precheck
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.$(OBJECT_SUFFIX) __all__.ldflags __all__.files
|
rm -f *.$(OBJECT_SUFFIX) __all__.ldflags __all__.files
|
||||||
|
@ -43,7 +39,6 @@ clean:
|
||||||
$(MAKE) -C portaudio clean
|
$(MAKE) -C portaudio clean
|
||||||
$(MAKE) -C libao clean
|
$(MAKE) -C libao clean
|
||||||
$(MAKE) -C wxwidgets clean
|
$(MAKE) -C wxwidgets clean
|
||||||
$(MAKE) -C macosx clean
|
|
||||||
|
|
||||||
forcelook:
|
forcelook:
|
||||||
@true
|
@true
|
||||||
|
|
|
@ -1,458 +0,0 @@
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
Version 2.1, February 1999
|
|
||||||
|
|
||||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
|
||||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
[This is the first released version of the Lesser GPL. It also counts
|
|
||||||
as the successor of the GNU Library Public License, version 2, hence
|
|
||||||
the version number 2.1.]
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
Licenses are intended to guarantee your freedom to share and change
|
|
||||||
free software--to make sure the software is free for all its users.
|
|
||||||
|
|
||||||
This license, the Lesser General Public License, applies to some
|
|
||||||
specially designated software packages--typically libraries--of the
|
|
||||||
Free Software Foundation and other authors who decide to use it. You
|
|
||||||
can use it too, but we suggest you first think carefully about whether
|
|
||||||
this license or the ordinary General Public License is the better
|
|
||||||
strategy to use in any particular case, based on the explanations below.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom of use,
|
|
||||||
not price. Our General Public Licenses are designed to make sure that
|
|
||||||
you have the freedom to distribute copies of free software (and charge
|
|
||||||
for this service if you wish); that you receive source code or can get
|
|
||||||
it if you want it; that you can change the software and use pieces of
|
|
||||||
it in new free programs; and that you are informed that you can do
|
|
||||||
these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
distributors to deny you these rights or to ask you to surrender these
|
|
||||||
rights. These restrictions translate to certain responsibilities for
|
|
||||||
you if you distribute copies of the library or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of the library, whether gratis
|
|
||||||
or for a fee, you must give the recipients all the rights that we gave
|
|
||||||
you. You must make sure that they, too, receive or can get the source
|
|
||||||
code. If you link other code with the library, you must provide
|
|
||||||
complete object files to the recipients, so that they can relink them
|
|
||||||
with the library after making changes to the library and recompiling
|
|
||||||
it. And you must show them these terms so they know their rights.
|
|
||||||
|
|
||||||
We protect your rights with a two-step method: (1) we copyright the
|
|
||||||
library, and (2) we offer you this license, which gives you legal
|
|
||||||
permission to copy, distribute and/or modify the library.
|
|
||||||
|
|
||||||
To protect each distributor, we want to make it very clear that
|
|
||||||
there is no warranty for the free library. Also, if the library is
|
|
||||||
modified by someone else and passed on, the recipients should know
|
|
||||||
that what they have is not the original version, so that the original
|
|
||||||
author's reputation will not be affected by problems that might be
|
|
||||||
introduced by others.
|
|
||||||
|
|
||||||
Finally, software patents pose a constant threat to the existence of
|
|
||||||
any free program. We wish to make sure that a company cannot
|
|
||||||
effectively restrict the users of a free program by obtaining a
|
|
||||||
restrictive license from a patent holder. Therefore, we insist that
|
|
||||||
any patent license obtained for a version of the library must be
|
|
||||||
consistent with the full freedom of use specified in this license.
|
|
||||||
|
|
||||||
Most GNU software, including some libraries, is covered by the
|
|
||||||
ordinary GNU General Public License. This license, the GNU Lesser
|
|
||||||
General Public License, applies to certain designated libraries, and
|
|
||||||
is quite different from the ordinary General Public License. We use
|
|
||||||
this license for certain libraries in order to permit linking those
|
|
||||||
libraries into non-free programs.
|
|
||||||
|
|
||||||
When a program is linked with a library, whether statically or using
|
|
||||||
a shared library, the combination of the two is legally speaking a
|
|
||||||
combined work, a derivative of the original library. The ordinary
|
|
||||||
General Public License therefore permits such linking only if the
|
|
||||||
entire combination fits its criteria of freedom. The Lesser General
|
|
||||||
Public License permits more lax criteria for linking other code with
|
|
||||||
the library.
|
|
||||||
|
|
||||||
We call this license the "Lesser" General Public License because it
|
|
||||||
does Less to protect the user's freedom than the ordinary General
|
|
||||||
Public License. It also provides other free software developers Less
|
|
||||||
of an advantage over competing non-free programs. These disadvantages
|
|
||||||
are the reason we use the ordinary General Public License for many
|
|
||||||
libraries. However, the Lesser license provides advantages in certain
|
|
||||||
special circumstances.
|
|
||||||
|
|
||||||
For example, on rare occasions, there may be a special need to
|
|
||||||
encourage the widest possible use of a certain library, so that it becomes
|
|
||||||
a de-facto standard. To achieve this, non-free programs must be
|
|
||||||
allowed to use the library. A more frequent case is that a free
|
|
||||||
library does the same job as widely used non-free libraries. In this
|
|
||||||
case, there is little to gain by limiting the free library to free
|
|
||||||
software only, so we use the Lesser General Public License.
|
|
||||||
|
|
||||||
In other cases, permission to use a particular library in non-free
|
|
||||||
programs enables a greater number of people to use a large body of
|
|
||||||
free software. For example, permission to use the GNU C Library in
|
|
||||||
non-free programs enables many more people to use the whole GNU
|
|
||||||
operating system, as well as its variant, the GNU/Linux operating
|
|
||||||
system.
|
|
||||||
|
|
||||||
Although the Lesser General Public License is Less protective of the
|
|
||||||
users' freedom, it does ensure that the user of a program that is
|
|
||||||
linked with the Library has the freedom and the wherewithal to run
|
|
||||||
that program using a modified version of the Library.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow. Pay close attention to the difference between a
|
|
||||||
"work based on the library" and a "work that uses the library". The
|
|
||||||
former contains code derived from the library, whereas the latter must
|
|
||||||
be combined with the library in order to run.
|
|
||||||
|
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License Agreement applies to any software library or other
|
|
||||||
program which contains a notice placed by the copyright holder or
|
|
||||||
other authorized party saying it may be distributed under the terms of
|
|
||||||
this Lesser General Public License (also called "this License").
|
|
||||||
Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
A "library" means a collection of software functions and/or data
|
|
||||||
prepared so as to be conveniently linked with application programs
|
|
||||||
(which use some of those functions and data) to form executables.
|
|
||||||
|
|
||||||
The "Library", below, refers to any such software library or work
|
|
||||||
which has been distributed under these terms. A "work based on the
|
|
||||||
Library" means either the Library or any derivative work under
|
|
||||||
copyright law: that is to say, a work containing the Library or a
|
|
||||||
portion of it, either verbatim or with modifications and/or translated
|
|
||||||
straightforwardly into another language. (Hereinafter, translation is
|
|
||||||
included without limitation in the term "modification".)
|
|
||||||
|
|
||||||
"Source code" for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For a library, complete source code means
|
|
||||||
all the source code for all modules it contains, plus any associated
|
|
||||||
interface definition files, plus the scripts used to control compilation
|
|
||||||
and installation of the library.
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running a program using the Library is not restricted, and output from
|
|
||||||
such a program is covered only if its contents constitute a work based
|
|
||||||
on the Library (independent of the use of the Library in a tool for
|
|
||||||
writing it). Whether that is true depends on what the Library does
|
|
||||||
and what the program that uses the Library does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Library's
|
|
||||||
complete source code as you receive it, in any medium, provided that
|
|
||||||
you conspicuously and appropriately publish on each copy an
|
|
||||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
|
||||||
all the notices that refer to this License and to the absence of any
|
|
||||||
warranty; and distribute a copy of this License along with the
|
|
||||||
Library.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy,
|
|
||||||
and you may at your option offer warranty protection in exchange for a
|
|
||||||
fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Library or any portion
|
|
||||||
of it, thus forming a work based on the Library, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The modified work must itself be a software library.
|
|
||||||
|
|
||||||
b) You must cause the files modified to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
c) You must cause the whole of the work to be licensed at no
|
|
||||||
charge to all third parties under the terms of this License.
|
|
||||||
|
|
||||||
d) If a facility in the modified Library refers to a function or a
|
|
||||||
table of data to be supplied by an application program that uses
|
|
||||||
the facility, other than as an argument passed when the facility
|
|
||||||
is invoked, then you must make a good faith effort to ensure that,
|
|
||||||
in the event an application does not supply such function or
|
|
||||||
table, the facility still operates, and performs whatever part of
|
|
||||||
its purpose remains meaningful.
|
|
||||||
|
|
||||||
(For example, a function in a library to compute square roots has
|
|
||||||
a purpose that is entirely well-defined independent of the
|
|
||||||
application. Therefore, Subsection 2d requires that any
|
|
||||||
application-supplied function or table used by this function must
|
|
||||||
be optional: if the application does not supply it, the square
|
|
||||||
root function must still compute square roots.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Library,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Library, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote
|
|
||||||
it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Library.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Library
|
|
||||||
with the Library (or with a work based on the Library) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
|
||||||
License instead of this License to a given copy of the Library. To do
|
|
||||||
this, you must alter all the notices that refer to this License, so
|
|
||||||
that they refer to the ordinary GNU General Public License, version 2,
|
|
||||||
instead of to this License. (If a newer version than version 2 of the
|
|
||||||
ordinary GNU General Public License has appeared, then you can specify
|
|
||||||
that version instead if you wish.) Do not make any other change in
|
|
||||||
these notices.
|
|
||||||
|
|
||||||
Once this change is made in a given copy, it is irreversible for
|
|
||||||
that copy, so the ordinary GNU General Public License applies to all
|
|
||||||
subsequent copies and derivative works made from that copy.
|
|
||||||
|
|
||||||
This option is useful when you wish to copy part of the code of
|
|
||||||
the Library into a program that is not a library.
|
|
||||||
|
|
||||||
4. You may copy and distribute the Library (or a portion or
|
|
||||||
derivative of it, under Section 2) in object code or executable form
|
|
||||||
under the terms of Sections 1 and 2 above provided that you accompany
|
|
||||||
it with the complete corresponding machine-readable source code, which
|
|
||||||
must be distributed under the terms of Sections 1 and 2 above on a
|
|
||||||
medium customarily used for software interchange.
|
|
||||||
|
|
||||||
If distribution of object code is made by offering access to copy
|
|
||||||
from a designated place, then offering equivalent access to copy the
|
|
||||||
source code from the same place satisfies the requirement to
|
|
||||||
distribute the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
5. A program that contains no derivative of any portion of the
|
|
||||||
Library, but is designed to work with the Library by being compiled or
|
|
||||||
linked with it, is called a "work that uses the Library". Such a
|
|
||||||
work, in isolation, is not a derivative work of the Library, and
|
|
||||||
therefore falls outside the scope of this License.
|
|
||||||
|
|
||||||
However, linking a "work that uses the Library" with the Library
|
|
||||||
creates an executable that is a derivative of the Library (because it
|
|
||||||
contains portions of the Library), rather than a "work that uses the
|
|
||||||
library". The executable is therefore covered by this License.
|
|
||||||
Section 6 states terms for distribution of such executables.
|
|
||||||
|
|
||||||
When a "work that uses the Library" uses material from a header file
|
|
||||||
that is part of the Library, the object code for the work may be a
|
|
||||||
derivative work of the Library even though the source code is not.
|
|
||||||
Whether this is true is especially significant if the work can be
|
|
||||||
linked without the Library, or if the work is itself a library. The
|
|
||||||
threshold for this to be true is not precisely defined by law.
|
|
||||||
|
|
||||||
If such an object file uses only numerical parameters, data
|
|
||||||
structure layouts and accessors, and small macros and small inline
|
|
||||||
functions (ten lines or less in length), then the use of the object
|
|
||||||
file is unrestricted, regardless of whether it is legally a derivative
|
|
||||||
work. (Executables containing this object code plus portions of the
|
|
||||||
Library will still fall under Section 6.)
|
|
||||||
|
|
||||||
Otherwise, if the work is a derivative of the Library, you may
|
|
||||||
distribute the object code for the work under the terms of Section 6.
|
|
||||||
Any executables containing that work also fall under Section 6,
|
|
||||||
whether or not they are linked directly with the Library itself.
|
|
||||||
|
|
||||||
6. As an exception to the Sections above, you may also combine or
|
|
||||||
link a "work that uses the Library" with the Library to produce a
|
|
||||||
work containing portions of the Library, and distribute that work
|
|
||||||
under terms of your choice, provided that the terms permit
|
|
||||||
modification of the work for the customer's own use and reverse
|
|
||||||
engineering for debugging such modifications.
|
|
||||||
|
|
||||||
You must give prominent notice with each copy of the work that the
|
|
||||||
Library is used in it and that the Library and its use are covered by
|
|
||||||
this License. You must supply a copy of this License. If the work
|
|
||||||
during execution displays copyright notices, you must include the
|
|
||||||
copyright notice for the Library among them, as well as a reference
|
|
||||||
directing the user to the copy of this License. Also, you must do one
|
|
||||||
of these things:
|
|
||||||
|
|
||||||
a) Accompany the work with the complete corresponding
|
|
||||||
machine-readable source code for the Library including whatever
|
|
||||||
changes were used in the work (which must be distributed under
|
|
||||||
Sections 1 and 2 above); and, if the work is an executable linked
|
|
||||||
with the Library, with the complete machine-readable "work that
|
|
||||||
uses the Library", as object code and/or source code, so that the
|
|
||||||
user can modify the Library and then relink to produce a modified
|
|
||||||
executable containing the modified Library. (It is understood
|
|
||||||
that the user who changes the contents of definitions files in the
|
|
||||||
Library will not necessarily be able to recompile the application
|
|
||||||
to use the modified definitions.)
|
|
||||||
|
|
||||||
b) Use a suitable shared library mechanism for linking with the
|
|
||||||
Library. A suitable mechanism is one that (1) uses at run time a
|
|
||||||
copy of the library already present on the user's computer system,
|
|
||||||
rather than copying library functions into the executable, and (2)
|
|
||||||
will operate properly with a modified version of the library, if
|
|
||||||
the user installs one, as long as the modified version is
|
|
||||||
interface-compatible with the version that the work was made with.
|
|
||||||
|
|
||||||
c) Accompany the work with a written offer, valid for at
|
|
||||||
least three years, to give the same user the materials
|
|
||||||
specified in Subsection 6a, above, for a charge no more
|
|
||||||
than the cost of performing this distribution.
|
|
||||||
|
|
||||||
d) If distribution of the work is made by offering access to copy
|
|
||||||
from a designated place, offer equivalent access to copy the above
|
|
||||||
specified materials from the same place.
|
|
||||||
|
|
||||||
e) Verify that the user has already received a copy of these
|
|
||||||
materials or that you have already sent this user a copy.
|
|
||||||
|
|
||||||
For an executable, the required form of the "work that uses the
|
|
||||||
Library" must include any data and utility programs needed for
|
|
||||||
reproducing the executable from it. However, as a special exception,
|
|
||||||
the materials to be distributed need not include anything that is
|
|
||||||
normally distributed (in either source or binary form) with the major
|
|
||||||
components (compiler, kernel, and so on) of the operating system on
|
|
||||||
which the executable runs, unless that component itself accompanies
|
|
||||||
the executable.
|
|
||||||
|
|
||||||
It may happen that this requirement contradicts the license
|
|
||||||
restrictions of other proprietary libraries that do not normally
|
|
||||||
accompany the operating system. Such a contradiction means you cannot
|
|
||||||
use both them and the Library together in an executable that you
|
|
||||||
distribute.
|
|
||||||
|
|
||||||
7. You may place library facilities that are a work based on the
|
|
||||||
Library side-by-side in a single library together with other library
|
|
||||||
facilities not covered by this License, and distribute such a combined
|
|
||||||
library, provided that the separate distribution of the work based on
|
|
||||||
the Library and of the other library facilities is otherwise
|
|
||||||
permitted, and provided that you do these two things:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work
|
|
||||||
based on the Library, uncombined with any other library
|
|
||||||
facilities. This must be distributed under the terms of the
|
|
||||||
Sections above.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library of the fact
|
|
||||||
that part of it is a work based on the Library, and explaining
|
|
||||||
where to find the accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
8. You may not copy, modify, sublicense, link with, or distribute
|
|
||||||
the Library except as expressly provided under this License. Any
|
|
||||||
attempt otherwise to copy, modify, sublicense, link with, or
|
|
||||||
distribute the Library is void, and will automatically terminate your
|
|
||||||
rights under this License. However, parties who have received copies,
|
|
||||||
or rights, from you under this License will not have their licenses
|
|
||||||
terminated so long as such parties remain in full compliance.
|
|
||||||
|
|
||||||
9. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Library or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Library (or any work based on the
|
|
||||||
Library), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Library or works based on it.
|
|
||||||
|
|
||||||
10. Each time you redistribute the Library (or any work based on the
|
|
||||||
Library), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute, link with or modify the Library
|
|
||||||
subject to these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties with
|
|
||||||
this License.
|
|
||||||
|
|
||||||
11. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Library at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Library by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Library.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under any
|
|
||||||
particular circumstance, the balance of the section is intended to apply,
|
|
||||||
and the section as a whole is intended to apply in other circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
12. If the distribution and/or use of the Library is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Library under this License may add
|
|
||||||
an explicit geographical distribution limitation excluding those countries,
|
|
||||||
so that distribution is permitted only in or among countries not thus
|
|
||||||
excluded. In such case, this License incorporates the limitation as if
|
|
||||||
written in the body of this License.
|
|
||||||
|
|
||||||
13. The Free Software Foundation may publish revised and/or new
|
|
||||||
versions of the Lesser General Public License from time to time.
|
|
||||||
Such new versions will be similar in spirit to the present version,
|
|
||||||
but may differ in detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Library
|
|
||||||
specifies a version number of this License which applies to it and
|
|
||||||
"any later version", you have the option of following the terms and
|
|
||||||
conditions either of that version or of any later version published by
|
|
||||||
the Free Software Foundation. If the Library does not specify a
|
|
||||||
license version number, you may choose any version ever published by
|
|
||||||
the Free Software Foundation.
|
|
||||||
|
|
||||||
14. If you wish to incorporate parts of the Library into other free
|
|
||||||
programs whose distribution conditions are incompatible with these,
|
|
||||||
write to the author to ask for permission. For software which is
|
|
||||||
copyrighted by the Free Software Foundation, write to the Free
|
|
||||||
Software Foundation; we sometimes make exceptions for this. Our
|
|
||||||
decision will be guided by the two goals of preserving the free status
|
|
||||||
of all derivatives of our free software and of promoting the sharing
|
|
||||||
and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
|
||||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
|
||||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
|
||||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
|
||||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
|
||||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
|
||||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
|
||||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
|
||||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
|
||||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
|
||||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
|
||||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
|
||||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
|
||||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
|
||||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
||||||
DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
|
@ -1,27 +0,0 @@
|
||||||
ifeq ($(JOYSTICK), MACOSX)
|
|
||||||
OBJECTS=$(patsubst %.cpp,%.$(OBJECT_SUFFIX),$(wildcard *.cpp)) $(patsubst %.c,%.$(OBJECT_SUFFIX),$(wildcard *.c))
|
|
||||||
else
|
|
||||||
OBJECTS=
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PRECIOUS: %.$(OBJECT_SUFFIX) %.files
|
|
||||||
|
|
||||||
__all__.files: $(OBJECTS)
|
|
||||||
lua ../../genfilelist.lua $^ >$@
|
|
||||||
touch __all__.ldflags
|
|
||||||
|
|
||||||
%.$(OBJECT_SUFFIX): %.cpp %.cpp.dep
|
|
||||||
$(REALCC) -c -o $@ $< -I../../../include $(CFLAGS)
|
|
||||||
|
|
||||||
%.$(OBJECT_SUFFIX): %.c %.c.dep
|
|
||||||
$(REALCC) -DSDL_JOYSTICK_IOKIT -x c --std=gnu99 -c -o $@ $< $(CSTDFLAGS)
|
|
||||||
|
|
||||||
precheck:
|
|
||||||
../../../buildaux/mkdeps$(DOT_EXECUTABLE_SUFFIX) ../../../include -- *.cpp *.c
|
|
||||||
@true
|
|
||||||
|
|
||||||
forcelook:
|
|
||||||
@true
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.$(OBJECT_SUFFIX) __all__.ldflags __all__.files
|
|
|
@ -1,851 +0,0 @@
|
||||||
/*
|
|
||||||
SDL - Simple DirectMedia Layer
|
|
||||||
Copyright (C) 1997-2012 Sam Lantinga
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the Free
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Sam Lantinga
|
|
||||||
slouken@libsdl.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Modified 2013-07-04 by H. Ilari Liusvaara:
|
|
||||||
- Change user includes to point to one file in the same directory.
|
|
||||||
- Change one non-ASCII character to be UTF-8 -compatible.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "sdl-sysjoy-interface.h"
|
|
||||||
/*#include "SDL_config.h"*/
|
|
||||||
|
|
||||||
#ifdef SDL_JOYSTICK_IOKIT
|
|
||||||
|
|
||||||
/* SDL joystick driver for Darwin / Mac OS X, based on the IOKit HID API */
|
|
||||||
/* Written 2001 by Max Horn */
|
|
||||||
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <sysexits.h>
|
|
||||||
#include <mach/mach.h>
|
|
||||||
#include <mach/mach_error.h>
|
|
||||||
#include <IOKit/IOKitLib.h>
|
|
||||||
#include <IOKit/IOCFPlugIn.h>
|
|
||||||
#ifdef MACOS_10_0_4
|
|
||||||
#include <IOKit/hidsystem/IOHIDUsageTables.h>
|
|
||||||
#else
|
|
||||||
/* The header was moved here in Mac OS X 10.1 */
|
|
||||||
#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
|
|
||||||
#endif
|
|
||||||
#include <IOKit/hid/IOHIDLib.h>
|
|
||||||
#include <IOKit/hid/IOHIDKeys.h>
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
|
||||||
#include <Carbon/Carbon.h> /* for NewPtrClear, DisposePtr */
|
|
||||||
|
|
||||||
/*#include "SDL_joystick.h"*/
|
|
||||||
/*#include "../SDL_sysjoystick.h"*/
|
|
||||||
/*#include "../SDL_joystick_c.h"*/
|
|
||||||
|
|
||||||
|
|
||||||
struct recElement
|
|
||||||
{
|
|
||||||
IOHIDElementCookie cookie; /* unique value which identifies element, will NOT change */
|
|
||||||
long min; /* reported min value possible */
|
|
||||||
long max; /* reported max value possible */
|
|
||||||
#if 0
|
|
||||||
/* TODO: maybe should handle the following stuff somehow? */
|
|
||||||
|
|
||||||
long scaledMin; /* reported scaled min value possible */
|
|
||||||
long scaledMax; /* reported scaled max value possible */
|
|
||||||
long size; /* size in bits of data return from element */
|
|
||||||
Boolean relative; /* are reports relative to last report (deltas) */
|
|
||||||
Boolean wrapping; /* does element wrap around (one value higher than max is min) */
|
|
||||||
Boolean nonLinear; /* are the values reported non-linear relative to element movement */
|
|
||||||
Boolean preferredState; /* does element have a preferred state (such as a button) */
|
|
||||||
Boolean nullState; /* does element have null state */
|
|
||||||
#endif /* 0 */
|
|
||||||
|
|
||||||
/* runtime variables used for auto-calibration */
|
|
||||||
long minReport; /* min returned value */
|
|
||||||
long maxReport; /* max returned value */
|
|
||||||
|
|
||||||
struct recElement * pNext; /* next element in list */
|
|
||||||
};
|
|
||||||
typedef struct recElement recElement;
|
|
||||||
|
|
||||||
struct joystick_hwdata
|
|
||||||
{
|
|
||||||
IOHIDDeviceInterface ** interface; /* interface to device, NULL = no interface */
|
|
||||||
|
|
||||||
char product[256]; /* name of product */
|
|
||||||
long usage; /* usage page from IOUSBHID Parser.h which defines general usage */
|
|
||||||
long usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */
|
|
||||||
|
|
||||||
long axes; /* number of axis (calculated, not reported by device) */
|
|
||||||
long buttons; /* number of buttons (calculated, not reported by device) */
|
|
||||||
long hats; /* number of hat switches (calculated, not reported by device) */
|
|
||||||
long elements; /* number of total elements (shouldbe total of above) (calculated, not reported by device) */
|
|
||||||
|
|
||||||
recElement* firstAxis;
|
|
||||||
recElement* firstButton;
|
|
||||||
recElement* firstHat;
|
|
||||||
|
|
||||||
int removed;
|
|
||||||
int uncentered;
|
|
||||||
|
|
||||||
struct joystick_hwdata* pNext; /* next device */
|
|
||||||
};
|
|
||||||
typedef struct joystick_hwdata recDevice;
|
|
||||||
|
|
||||||
|
|
||||||
/* Linked list of all available devices */
|
|
||||||
static recDevice *gpDeviceList = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
static void HIDReportErrorNum (char * strError, long numError)
|
|
||||||
{
|
|
||||||
SDL_SetError(strError);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice);
|
|
||||||
|
|
||||||
/* returns current value for element, polling element
|
|
||||||
* will return 0 on error conditions which should be accounted for by application
|
|
||||||
*/
|
|
||||||
|
|
||||||
static SInt32 HIDGetElementValue (recDevice *pDevice, recElement *pElement)
|
|
||||||
{
|
|
||||||
IOReturn result = kIOReturnSuccess;
|
|
||||||
IOHIDEventStruct hidEvent;
|
|
||||||
hidEvent.value = 0;
|
|
||||||
|
|
||||||
if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface)
|
|
||||||
{
|
|
||||||
result = (*(pDevice->interface))->getElementValue(pDevice->interface, pElement->cookie, &hidEvent);
|
|
||||||
if (kIOReturnSuccess == result)
|
|
||||||
{
|
|
||||||
/* record min and max for auto calibration */
|
|
||||||
if (hidEvent.value < pElement->minReport)
|
|
||||||
pElement->minReport = hidEvent.value;
|
|
||||||
if (hidEvent.value > pElement->maxReport)
|
|
||||||
pElement->maxReport = hidEvent.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* auto user scale */
|
|
||||||
return hidEvent.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SInt32 HIDScaledCalibratedValue (recDevice *pDevice, recElement *pElement, long min, long max)
|
|
||||||
{
|
|
||||||
float deviceScale = max - min;
|
|
||||||
float readScale = pElement->maxReport - pElement->minReport;
|
|
||||||
SInt32 value = HIDGetElementValue(pDevice, pElement);
|
|
||||||
if (readScale == 0)
|
|
||||||
return value; /* no scaling at all */
|
|
||||||
else
|
|
||||||
return ((value - pElement->minReport) * deviceScale / readScale) + min;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void HIDRemovalCallback(void * target,
|
|
||||||
IOReturn result,
|
|
||||||
void * refcon,
|
|
||||||
void * sender)
|
|
||||||
{
|
|
||||||
recDevice *device = (recDevice *) refcon;
|
|
||||||
device->removed = 1;
|
|
||||||
device->uncentered = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Create and open an interface to device, required prior to extracting values or building queues.
|
|
||||||
* Note: appliction now owns the device and must close and release it prior to exiting
|
|
||||||
*/
|
|
||||||
|
|
||||||
static IOReturn HIDCreateOpenDeviceInterface (io_object_t hidDevice, recDevice *pDevice)
|
|
||||||
{
|
|
||||||
IOReturn result = kIOReturnSuccess;
|
|
||||||
HRESULT plugInResult = S_OK;
|
|
||||||
SInt32 score = 0;
|
|
||||||
IOCFPlugInInterface ** ppPlugInInterface = NULL;
|
|
||||||
|
|
||||||
if (NULL == pDevice->interface)
|
|
||||||
{
|
|
||||||
result = IOCreatePlugInInterfaceForService (hidDevice, kIOHIDDeviceUserClientTypeID,
|
|
||||||
kIOCFPlugInInterfaceID, &ppPlugInInterface, &score);
|
|
||||||
if (kIOReturnSuccess == result)
|
|
||||||
{
|
|
||||||
/* Call a method of the intermediate plug-in to create the device interface */
|
|
||||||
plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface,
|
|
||||||
CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void *) &(pDevice->interface));
|
|
||||||
if (S_OK != plugInResult)
|
|
||||||
HIDReportErrorNum ("Couldn't query HID class device interface from plugInInterface", plugInResult);
|
|
||||||
(*ppPlugInInterface)->Release (ppPlugInInterface);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
HIDReportErrorNum ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.", result);
|
|
||||||
}
|
|
||||||
if (NULL != pDevice->interface)
|
|
||||||
{
|
|
||||||
result = (*(pDevice->interface))->open (pDevice->interface, 0);
|
|
||||||
if (kIOReturnSuccess != result)
|
|
||||||
HIDReportErrorNum ("Failed to open pDevice->interface via open.", result);
|
|
||||||
else
|
|
||||||
(*(pDevice->interface))->setRemovalCallback (pDevice->interface, HIDRemovalCallback, pDevice, pDevice);
|
|
||||||
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Closes and releases interface to device, should be done prior to exting application
|
|
||||||
* Note: will have no affect if device or interface do not exist
|
|
||||||
* application will "own" the device if interface is not closed
|
|
||||||
* (device may have to be plug and re-plugged in different location to get it working again without a restart)
|
|
||||||
*/
|
|
||||||
|
|
||||||
static IOReturn HIDCloseReleaseInterface (recDevice *pDevice)
|
|
||||||
{
|
|
||||||
IOReturn result = kIOReturnSuccess;
|
|
||||||
|
|
||||||
if ((NULL != pDevice) && (NULL != pDevice->interface))
|
|
||||||
{
|
|
||||||
/* close the interface */
|
|
||||||
result = (*(pDevice->interface))->close (pDevice->interface);
|
|
||||||
if (kIOReturnNotOpen == result)
|
|
||||||
{
|
|
||||||
/* do nothing as device was not opened, thus can't be closed */
|
|
||||||
}
|
|
||||||
else if (kIOReturnSuccess != result)
|
|
||||||
HIDReportErrorNum ("Failed to close IOHIDDeviceInterface.", result);
|
|
||||||
/* release the interface */
|
|
||||||
result = (*(pDevice->interface))->Release (pDevice->interface);
|
|
||||||
if (kIOReturnSuccess != result)
|
|
||||||
HIDReportErrorNum ("Failed to release IOHIDDeviceInterface.", result);
|
|
||||||
pDevice->interface = NULL;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extracts actual specific element information from each element CF dictionary entry */
|
|
||||||
|
|
||||||
static void HIDGetElementInfo (CFTypeRef refElement, recElement *pElement)
|
|
||||||
{
|
|
||||||
long number;
|
|
||||||
CFTypeRef refType;
|
|
||||||
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementCookieKey));
|
|
||||||
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
|
|
||||||
pElement->cookie = (IOHIDElementCookie) number;
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMinKey));
|
|
||||||
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
|
|
||||||
pElement->minReport = pElement->min = number;
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMaxKey));
|
|
||||||
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
|
|
||||||
pElement->maxReport = pElement->max = number;
|
|
||||||
/*
|
|
||||||
TODO: maybe should handle the following stuff somehow?
|
|
||||||
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
|
|
||||||
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
|
|
||||||
pElement->scaledMin = number;
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
|
|
||||||
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
|
|
||||||
pElement->scaledMax = number;
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
|
|
||||||
if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
|
|
||||||
pElement->size = number;
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
|
|
||||||
if (refType)
|
|
||||||
pElement->relative = CFBooleanGetValue (refType);
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
|
|
||||||
if (refType)
|
|
||||||
pElement->wrapping = CFBooleanGetValue (refType);
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
|
|
||||||
if (refType)
|
|
||||||
pElement->nonLinear = CFBooleanGetValue (refType);
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
|
|
||||||
if (refType)
|
|
||||||
pElement->preferredState = CFBooleanGetValue (refType);
|
|
||||||
refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
|
|
||||||
if (refType)
|
|
||||||
pElement->nullState = CFBooleanGetValue (refType);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/* examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements
|
|
||||||
* if element of interest allocate storage, add to list and retrieve element specific info
|
|
||||||
* if collection then pass on to deconstruction collection into additional individual elements
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void HIDAddElement (CFTypeRef refElement, recDevice* pDevice)
|
|
||||||
{
|
|
||||||
recElement* element = NULL;
|
|
||||||
recElement** headElement = NULL;
|
|
||||||
long elementType, usagePage, usage;
|
|
||||||
CFTypeRef refElementType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementTypeKey));
|
|
||||||
CFTypeRef refUsagePage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsagePageKey));
|
|
||||||
CFTypeRef refUsage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsageKey));
|
|
||||||
|
|
||||||
|
|
||||||
if ((refElementType) && (CFNumberGetValue (refElementType, kCFNumberLongType, &elementType)))
|
|
||||||
{
|
|
||||||
/* look at types of interest */
|
|
||||||
if ((elementType == kIOHIDElementTypeInput_Misc) || (elementType == kIOHIDElementTypeInput_Button) ||
|
|
||||||
(elementType == kIOHIDElementTypeInput_Axis))
|
|
||||||
{
|
|
||||||
if (refUsagePage && CFNumberGetValue (refUsagePage, kCFNumberLongType, &usagePage) &&
|
|
||||||
refUsage && CFNumberGetValue (refUsage, kCFNumberLongType, &usage))
|
|
||||||
{
|
|
||||||
switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
|
|
||||||
{
|
|
||||||
case kHIDPage_GenericDesktop:
|
|
||||||
{
|
|
||||||
switch (usage) /* look at usage to determine function */
|
|
||||||
{
|
|
||||||
case kHIDUsage_GD_X:
|
|
||||||
case kHIDUsage_GD_Y:
|
|
||||||
case kHIDUsage_GD_Z:
|
|
||||||
case kHIDUsage_GD_Rx:
|
|
||||||
case kHIDUsage_GD_Ry:
|
|
||||||
case kHIDUsage_GD_Rz:
|
|
||||||
case kHIDUsage_GD_Slider:
|
|
||||||
case kHIDUsage_GD_Dial:
|
|
||||||
case kHIDUsage_GD_Wheel:
|
|
||||||
element = (recElement *) NewPtrClear (sizeof (recElement));
|
|
||||||
if (element)
|
|
||||||
{
|
|
||||||
pDevice->axes++;
|
|
||||||
headElement = &(pDevice->firstAxis);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kHIDUsage_GD_Hatswitch:
|
|
||||||
element = (recElement *) NewPtrClear (sizeof (recElement));
|
|
||||||
if (element)
|
|
||||||
{
|
|
||||||
pDevice->hats++;
|
|
||||||
headElement = &(pDevice->firstHat);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kHIDPage_Button:
|
|
||||||
element = (recElement *) NewPtrClear (sizeof (recElement));
|
|
||||||
if (element)
|
|
||||||
{
|
|
||||||
pDevice->buttons++;
|
|
||||||
headElement = &(pDevice->firstButton);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (kIOHIDElementTypeCollection == elementType)
|
|
||||||
HIDGetCollectionElements ((CFMutableDictionaryRef) refElement, pDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element && headElement) /* add to list */
|
|
||||||
{
|
|
||||||
pDevice->elements++;
|
|
||||||
if (NULL == *headElement)
|
|
||||||
*headElement = element;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
recElement *elementPrevious, *elementCurrent;
|
|
||||||
elementCurrent = *headElement;
|
|
||||||
while (elementCurrent)
|
|
||||||
{
|
|
||||||
elementPrevious = elementCurrent;
|
|
||||||
elementCurrent = elementPrevious->pNext;
|
|
||||||
}
|
|
||||||
elementPrevious->pNext = element;
|
|
||||||
}
|
|
||||||
element->pNext = NULL;
|
|
||||||
HIDGetElementInfo (refElement, element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* collects information from each array member in device element list (each array memeber = element) */
|
|
||||||
|
|
||||||
static void HIDGetElementsCFArrayHandler (const void * value, void * parameter)
|
|
||||||
{
|
|
||||||
if (CFGetTypeID (value) == CFDictionaryGetTypeID ())
|
|
||||||
HIDAddElement ((CFTypeRef) value, (recDevice *) parameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* handles retrieval of element information from arrays of elements in device IO registry information */
|
|
||||||
|
|
||||||
static void HIDGetElements (CFTypeRef refElementCurrent, recDevice *pDevice)
|
|
||||||
{
|
|
||||||
CFTypeID type = CFGetTypeID (refElementCurrent);
|
|
||||||
if (type == CFArrayGetTypeID()) /* if element is an array */
|
|
||||||
{
|
|
||||||
CFRange range = {0, CFArrayGetCount (refElementCurrent)};
|
|
||||||
/* CountElementsCFArrayHandler called for each array member */
|
|
||||||
CFArrayApplyFunction (refElementCurrent, range, HIDGetElementsCFArrayHandler, pDevice);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* handles extracting element information from element collection CF types
|
|
||||||
* used from top level element decoding and hierarchy deconstruction to flatten device element list
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice)
|
|
||||||
{
|
|
||||||
CFTypeRef refElementTop = CFDictionaryGetValue (deviceProperties, CFSTR(kIOHIDElementKey));
|
|
||||||
if (refElementTop)
|
|
||||||
HIDGetElements (refElementTop, pDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */
|
|
||||||
|
|
||||||
static void HIDTopLevelElementHandler (const void * value, void * parameter)
|
|
||||||
{
|
|
||||||
CFTypeRef refCF = 0;
|
|
||||||
if (CFGetTypeID (value) != CFDictionaryGetTypeID ())
|
|
||||||
return;
|
|
||||||
refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsagePageKey));
|
|
||||||
if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage))
|
|
||||||
SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage.");
|
|
||||||
refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsageKey));
|
|
||||||
if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage))
|
|
||||||
SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extracts device info from CF dictionary records in IO registry */
|
|
||||||
|
|
||||||
static void HIDGetDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, recDevice *pDevice)
|
|
||||||
{
|
|
||||||
CFMutableDictionaryRef usbProperties = 0;
|
|
||||||
io_registry_entry_t parent1, parent2;
|
|
||||||
|
|
||||||
/* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
|
|
||||||
* get dictionary for usb properties: step up two levels and get CF dictionary for USB properties
|
|
||||||
*/
|
|
||||||
if ((KERN_SUCCESS == IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) &&
|
|
||||||
(KERN_SUCCESS == IORegistryEntryGetParentEntry (parent1, kIOServicePlane, &parent2)) &&
|
|
||||||
(KERN_SUCCESS == IORegistryEntryCreateCFProperties (parent2, &usbProperties, kCFAllocatorDefault, kNilOptions)))
|
|
||||||
{
|
|
||||||
if (usbProperties)
|
|
||||||
{
|
|
||||||
CFTypeRef refCF = 0;
|
|
||||||
/* get device info
|
|
||||||
* try hid dictionary first, if fail then go to usb dictionary
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* get product name */
|
|
||||||
refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductKey));
|
|
||||||
if (!refCF)
|
|
||||||
refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Product Name"));
|
|
||||||
if (refCF)
|
|
||||||
{
|
|
||||||
if (!CFStringGetCString (refCF, pDevice->product, 256, CFStringGetSystemEncoding ()))
|
|
||||||
SDL_SetError ("CFStringGetCString error retrieving pDevice->product.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get usage page and usage */
|
|
||||||
refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey));
|
|
||||||
if (refCF)
|
|
||||||
{
|
|
||||||
if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage))
|
|
||||||
SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage.");
|
|
||||||
refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsageKey));
|
|
||||||
if (refCF)
|
|
||||||
if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage))
|
|
||||||
SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NULL == refCF) /* get top level element HID usage page or usage */
|
|
||||||
{
|
|
||||||
/* use top level element instead */
|
|
||||||
CFTypeRef refCFTopElement = 0;
|
|
||||||
refCFTopElement = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey));
|
|
||||||
{
|
|
||||||
/* refCFTopElement points to an array of element dictionaries */
|
|
||||||
CFRange range = {0, CFArrayGetCount (refCFTopElement)};
|
|
||||||
CFArrayApplyFunction (refCFTopElement, range, HIDTopLevelElementHandler, pDevice);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CFRelease (usbProperties);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SDL_SetError ("IORegistryEntryCreateCFProperties failed to create usbProperties.");
|
|
||||||
|
|
||||||
if (kIOReturnSuccess != IOObjectRelease (parent2))
|
|
||||||
SDL_SetError ("IOObjectRelease error with parent2.");
|
|
||||||
if (kIOReturnSuccess != IOObjectRelease (parent1))
|
|
||||||
SDL_SetError ("IOObjectRelease error with parent1.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static recDevice *HIDBuildDevice (io_object_t hidDevice)
|
|
||||||
{
|
|
||||||
recDevice *pDevice = (recDevice *) NewPtrClear (sizeof (recDevice));
|
|
||||||
if (pDevice)
|
|
||||||
{
|
|
||||||
/* get dictionary for HID properties */
|
|
||||||
CFMutableDictionaryRef hidProperties = 0;
|
|
||||||
kern_return_t result = IORegistryEntryCreateCFProperties (hidDevice, &hidProperties, kCFAllocatorDefault, kNilOptions);
|
|
||||||
if ((result == KERN_SUCCESS) && hidProperties)
|
|
||||||
{
|
|
||||||
/* create device interface */
|
|
||||||
result = HIDCreateOpenDeviceInterface (hidDevice, pDevice);
|
|
||||||
if (kIOReturnSuccess == result)
|
|
||||||
{
|
|
||||||
HIDGetDeviceInfo (hidDevice, hidProperties, pDevice); /* hidDevice used to find parents in registry tree */
|
|
||||||
HIDGetCollectionElements (hidProperties, pDevice);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DisposePtr((Ptr)pDevice);
|
|
||||||
pDevice = NULL;
|
|
||||||
}
|
|
||||||
CFRelease (hidProperties);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DisposePtr((Ptr)pDevice);
|
|
||||||
pDevice = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* disposes of the element list associated with a device and the memory associated with the list
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void HIDDisposeElementList (recElement **elementList)
|
|
||||||
{
|
|
||||||
recElement *pElement = *elementList;
|
|
||||||
while (pElement)
|
|
||||||
{
|
|
||||||
recElement *pElementNext = pElement->pNext;
|
|
||||||
DisposePtr ((Ptr) pElement);
|
|
||||||
pElement = pElementNext;
|
|
||||||
}
|
|
||||||
*elementList = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL
|
|
||||||
* all your device no longer belong to us... (i.e., you do not 'own' the device anymore)
|
|
||||||
*/
|
|
||||||
|
|
||||||
static recDevice *HIDDisposeDevice (recDevice **ppDevice)
|
|
||||||
{
|
|
||||||
kern_return_t result = KERN_SUCCESS;
|
|
||||||
recDevice *pDeviceNext = NULL;
|
|
||||||
if (*ppDevice)
|
|
||||||
{
|
|
||||||
/* save next device prior to disposing of this device */
|
|
||||||
pDeviceNext = (*ppDevice)->pNext;
|
|
||||||
|
|
||||||
/* free element lists */
|
|
||||||
HIDDisposeElementList (&(*ppDevice)->firstAxis);
|
|
||||||
HIDDisposeElementList (&(*ppDevice)->firstButton);
|
|
||||||
HIDDisposeElementList (&(*ppDevice)->firstHat);
|
|
||||||
|
|
||||||
result = HIDCloseReleaseInterface (*ppDevice); /* function sanity checks interface value (now application does not own device) */
|
|
||||||
if (kIOReturnSuccess != result)
|
|
||||||
HIDReportErrorNum ("HIDCloseReleaseInterface failed when trying to dipose device.", result);
|
|
||||||
DisposePtr ((Ptr)*ppDevice);
|
|
||||||
*ppDevice = NULL;
|
|
||||||
}
|
|
||||||
return pDeviceNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Function to scan the system for joysticks.
|
|
||||||
* Joystick 0 should be the system default joystick.
|
|
||||||
* This function should return the number of available joysticks, or -1
|
|
||||||
* on an unrecoverable fatal error.
|
|
||||||
*/
|
|
||||||
int SDL_SYS_JoystickInit(void)
|
|
||||||
{
|
|
||||||
IOReturn result = kIOReturnSuccess;
|
|
||||||
mach_port_t masterPort = 0;
|
|
||||||
io_iterator_t hidObjectIterator = 0;
|
|
||||||
CFMutableDictionaryRef hidMatchDictionary = NULL;
|
|
||||||
recDevice *device, *lastDevice;
|
|
||||||
io_object_t ioHIDDeviceObject = 0;
|
|
||||||
|
|
||||||
SDL_numjoysticks = 0;
|
|
||||||
|
|
||||||
if (gpDeviceList)
|
|
||||||
{
|
|
||||||
SDL_SetError("Joystick: Device list already inited.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = IOMasterPort (bootstrap_port, &masterPort);
|
|
||||||
if (kIOReturnSuccess != result)
|
|
||||||
{
|
|
||||||
SDL_SetError("Joystick: IOMasterPort error with bootstrap_port.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
|
|
||||||
hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey);
|
|
||||||
if (hidMatchDictionary)
|
|
||||||
{
|
|
||||||
/* Add key for device type (joystick, in this case) to refine the matching dictionary. */
|
|
||||||
|
|
||||||
/* NOTE: we now perform this filtering later
|
|
||||||
UInt32 usagePage = kHIDPage_GenericDesktop;
|
|
||||||
UInt32 usage = kHIDUsage_GD_Joystick;
|
|
||||||
CFNumberRef refUsage = NULL, refUsagePage = NULL;
|
|
||||||
|
|
||||||
refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
|
|
||||||
CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
|
|
||||||
refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
|
|
||||||
CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SDL_SetError("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*/ Now search I/O Registry for matching devices. */
|
|
||||||
result = IOServiceGetMatchingServices (masterPort, hidMatchDictionary, &hidObjectIterator);
|
|
||||||
/* Check for errors */
|
|
||||||
if (kIOReturnSuccess != result)
|
|
||||||
{
|
|
||||||
SDL_SetError("Joystick: Couldn't create a HID object iterator.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!hidObjectIterator) /* there are no joysticks */
|
|
||||||
{
|
|
||||||
gpDeviceList = NULL;
|
|
||||||
SDL_numjoysticks = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */
|
|
||||||
|
|
||||||
/* build flat linked list of devices from device iterator */
|
|
||||||
|
|
||||||
gpDeviceList = lastDevice = NULL;
|
|
||||||
|
|
||||||
while ((ioHIDDeviceObject = IOIteratorNext (hidObjectIterator)))
|
|
||||||
{
|
|
||||||
/* build a device record */
|
|
||||||
device = HIDBuildDevice (ioHIDDeviceObject);
|
|
||||||
if (!device)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* dump device object, it is no longer needed */
|
|
||||||
result = IOObjectRelease (ioHIDDeviceObject);
|
|
||||||
/* if (KERN_SUCCESS != result)
|
|
||||||
HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Filter device list to non-keyboard/mouse stuff */
|
|
||||||
if ( (device->usagePage != kHIDPage_GenericDesktop) ||
|
|
||||||
((device->usage != kHIDUsage_GD_Joystick &&
|
|
||||||
device->usage != kHIDUsage_GD_GamePad &&
|
|
||||||
device->usage != kHIDUsage_GD_MultiAxisController)) ) {
|
|
||||||
|
|
||||||
/* release memory for the device */
|
|
||||||
HIDDisposeDevice (&device);
|
|
||||||
DisposePtr((Ptr)device);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add device to the end of the list */
|
|
||||||
if (lastDevice)
|
|
||||||
lastDevice->pNext = device;
|
|
||||||
else
|
|
||||||
gpDeviceList = device;
|
|
||||||
lastDevice = device;
|
|
||||||
}
|
|
||||||
result = IOObjectRelease (hidObjectIterator); /* release the iterator */
|
|
||||||
|
|
||||||
/* Count the total number of devices we found */
|
|
||||||
device = gpDeviceList;
|
|
||||||
while (device)
|
|
||||||
{
|
|
||||||
SDL_numjoysticks++;
|
|
||||||
device = device->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SDL_numjoysticks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function to get the device-dependent name of a joystick */
|
|
||||||
const char *SDL_SYS_JoystickName(int index)
|
|
||||||
{
|
|
||||||
recDevice *device = gpDeviceList;
|
|
||||||
|
|
||||||
for (; index > 0; index--)
|
|
||||||
device = device->pNext;
|
|
||||||
|
|
||||||
return device->product;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function to open a joystick for use.
|
|
||||||
* The joystick to open is specified by the index field of the joystick.
|
|
||||||
* This should fill the nbuttons and naxes fields of the joystick structure.
|
|
||||||
* It returns 0, or -1 if there is an error.
|
|
||||||
*/
|
|
||||||
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
|
|
||||||
{
|
|
||||||
recDevice *device = gpDeviceList;
|
|
||||||
int index;
|
|
||||||
|
|
||||||
for (index = joystick->index; index > 0; index--)
|
|
||||||
device = device->pNext;
|
|
||||||
|
|
||||||
joystick->hwdata = device;
|
|
||||||
joystick->name = device->product;
|
|
||||||
|
|
||||||
joystick->naxes = device->axes;
|
|
||||||
joystick->nhats = device->hats;
|
|
||||||
joystick->nballs = 0;
|
|
||||||
joystick->nbuttons = device->buttons;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function to update the state of a joystick - called as a device poll.
|
|
||||||
* This function shouldn't update the joystick structure directly,
|
|
||||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
|
||||||
* and update joystick device state.
|
|
||||||
*/
|
|
||||||
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
|
|
||||||
{
|
|
||||||
recDevice *device = joystick->hwdata;
|
|
||||||
recElement *element;
|
|
||||||
SInt32 value, range;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (device->removed) /* device was unplugged; ignore it. */
|
|
||||||
{
|
|
||||||
if (device->uncentered)
|
|
||||||
{
|
|
||||||
device->uncentered = 0;
|
|
||||||
|
|
||||||
/* Tell the app that everything is centered/unpressed... */
|
|
||||||
for (i = 0; i < device->axes; i++)
|
|
||||||
SDL_PrivateJoystickAxis(joystick, i, 0);
|
|
||||||
|
|
||||||
for (i = 0; i < device->buttons; i++)
|
|
||||||
SDL_PrivateJoystickButton(joystick, i, 0);
|
|
||||||
|
|
||||||
for (i = 0; i < device->hats; i++)
|
|
||||||
SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
element = device->firstAxis;
|
|
||||||
i = 0;
|
|
||||||
while (element)
|
|
||||||
{
|
|
||||||
value = HIDScaledCalibratedValue(device, element, -32768, 32767);
|
|
||||||
if ( value != joystick->axes[i] )
|
|
||||||
SDL_PrivateJoystickAxis(joystick, i, value);
|
|
||||||
element = element->pNext;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
element = device->firstButton;
|
|
||||||
i = 0;
|
|
||||||
while (element)
|
|
||||||
{
|
|
||||||
value = HIDGetElementValue(device, element);
|
|
||||||
if (value > 1) /* handle pressure-sensitive buttons */
|
|
||||||
value = 1;
|
|
||||||
if ( value != joystick->buttons[i] )
|
|
||||||
SDL_PrivateJoystickButton(joystick, i, value);
|
|
||||||
element = element->pNext;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
element = device->firstHat;
|
|
||||||
i = 0;
|
|
||||||
while (element)
|
|
||||||
{
|
|
||||||
Uint8 pos = 0;
|
|
||||||
|
|
||||||
range = (element->max - element->min + 1);
|
|
||||||
value = HIDGetElementValue(device, element) - element->min;
|
|
||||||
if (range == 4) /* 4 position hatswitch - scale up value */
|
|
||||||
value *= 2;
|
|
||||||
else if (range != 8) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
|
|
||||||
value = -1;
|
|
||||||
switch(value)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
pos = SDL_HAT_UP;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
pos = SDL_HAT_RIGHTUP;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
pos = SDL_HAT_RIGHT;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
pos = SDL_HAT_RIGHTDOWN;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
pos = SDL_HAT_DOWN;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
pos = SDL_HAT_LEFTDOWN;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
pos = SDL_HAT_LEFT;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
pos = SDL_HAT_LEFTUP;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* Every other value is mapped to center. We do that because some
|
|
||||||
* joysticks use 8 and some 15 for this value, and apparently
|
|
||||||
* there are even more variants out there - so we try to be generous.
|
|
||||||
*/
|
|
||||||
pos = SDL_HAT_CENTERED;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( pos != joystick->hats[i] )
|
|
||||||
SDL_PrivateJoystickHat(joystick, i, pos);
|
|
||||||
element = element->pNext;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function to close a joystick after use */
|
|
||||||
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
|
|
||||||
{
|
|
||||||
/* Should we do anything here? */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function to perform any system-specific joystick related cleanup */
|
|
||||||
void SDL_SYS_JoystickQuit(void)
|
|
||||||
{
|
|
||||||
while (NULL != gpDeviceList)
|
|
||||||
gpDeviceList = HIDDisposeDevice (&gpDeviceList);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* SDL_JOYSTICK_IOKIT */
|
|
|
@ -1,112 +0,0 @@
|
||||||
#include "sdl-sysjoy-interface.h"
|
|
||||||
#include "core/keymapper.hpp"
|
|
||||||
#include "core/joystickapi.hpp"
|
|
||||||
#include "core/messages.hpp"
|
|
||||||
#include "core/misc.hpp"
|
|
||||||
#include "library/string.hpp"
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
volatile bool quit_signaled = false;
|
|
||||||
volatile bool quit_ack = false;
|
|
||||||
const unsigned POLL_WAIT = 20000;
|
|
||||||
std::map<uint8_t, SDL_Joystick*> joys;
|
|
||||||
std::map<uint8_t, unsigned> idx_to_jid;
|
|
||||||
|
|
||||||
void probe_joystick(int index)
|
|
||||||
{
|
|
||||||
SDL_Joystick* j = new SDL_Joystick;
|
|
||||||
memset(j, 0, sizeof(*j));
|
|
||||||
j->index = index;
|
|
||||||
if(SDL_SYS_JoystickOpen(j) < 0) {
|
|
||||||
delete j;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uint64_t joyid = reinterpret_cast<size_t>(j);
|
|
||||||
joys[index] = j;
|
|
||||||
idx_to_jid[index] = lsnes_gamepads.add(j->name);
|
|
||||||
gamepad::pad& ngp = lsnes_gamepads[idx_to_jid[index]];
|
|
||||||
|
|
||||||
for(int i = 0; i < j->nbuttons; i++)
|
|
||||||
ngp.add_button(i, (stringfmt() << "Button #" << i).str());
|
|
||||||
for(int i = 0; i < j->naxes; i++)
|
|
||||||
ngp.add_axis(i, -32768, 32767, false, (stringfmt() << "Axis #" << i).str());
|
|
||||||
for(int i = 0; i < j->nhats; i++)
|
|
||||||
ngp.add_hat(i, (stringfmt() << "Hat #" << i).str());
|
|
||||||
}
|
|
||||||
|
|
||||||
struct _joystick_driver drv = {
|
|
||||||
.init = []() -> void {
|
|
||||||
quit_signaled = false;
|
|
||||||
quit_ack = false;
|
|
||||||
int jcnt = SDL_SYS_JoystickInit();
|
|
||||||
if(jcnt < 0)
|
|
||||||
return;
|
|
||||||
for(int i = 0; i < jcnt; i++)
|
|
||||||
probe_joystick(i);
|
|
||||||
quit_ack = quit_signaled = false;
|
|
||||||
},
|
|
||||||
.quit = []() -> void {
|
|
||||||
quit_signaled = true;
|
|
||||||
while(!quit_ack);
|
|
||||||
for(auto i : joys) {
|
|
||||||
SDL_SYS_JoystickClose(i.second);
|
|
||||||
delete i.second;
|
|
||||||
}
|
|
||||||
SDL_SYS_JoystickQuit();
|
|
||||||
},
|
|
||||||
.thread_fn = []() -> void {
|
|
||||||
while(!quit_signaled) {
|
|
||||||
for(auto i : joys)
|
|
||||||
SDL_SYS_JoystickUpdate(i.second);
|
|
||||||
usleep(POLL_WAIT);
|
|
||||||
}
|
|
||||||
quit_ack = true;
|
|
||||||
},
|
|
||||||
.signal = []() -> void {
|
|
||||||
quit_signaled = true;
|
|
||||||
while(!quit_ack);
|
|
||||||
},
|
|
||||||
.name = []() -> const char* { return "Mac OS X joystick plugin"; }
|
|
||||||
};
|
|
||||||
struct joystick_driver _drv(drv);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t SDL_numjoysticks;
|
|
||||||
|
|
||||||
|
|
||||||
int SDL_PrivateJoystickAxis(SDL_Joystick* j, uint8_t axis, int16_t value)
|
|
||||||
{
|
|
||||||
lsnes_gamepads[j->index].report_axis(axis, value);
|
|
||||||
j->axes[axis] = value;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SDL_PrivateJoystickBall(SDL_Joystick* j, uint8_t ball, int16_t dx, int16_t dy)
|
|
||||||
{
|
|
||||||
//We don't support balls.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SDL_PrivateJoystickHat(SDL_Joystick* j, uint8_t hat, uint8_t val)
|
|
||||||
{
|
|
||||||
int angle = -1;
|
|
||||||
if(val > 0)
|
|
||||||
angle = 4500 * (val - 1);
|
|
||||||
lsnes_gamepads[j->index].report_hat(hat, angle);
|
|
||||||
j->hats[hat] = val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SDL_PrivateJoystickButton(SDL_Joystick* j, uint8_t button, uint8_t state)
|
|
||||||
{
|
|
||||||
lsnes_gamepads[j->index].report_button(button, state != 0);
|
|
||||||
j->buttons[button] = state;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDL_SetError(const char* err)
|
|
||||||
{
|
|
||||||
messages << "Joystick driver error: " << err << std::endl;
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
#ifndef _sdl__sysjoy__interface__included__
|
|
||||||
#define _sdl__sysjoy__interface__included__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct joystick_hwdata;
|
|
||||||
|
|
||||||
typedef struct _SDL_Joystick
|
|
||||||
{
|
|
||||||
int index;
|
|
||||||
const char* name;
|
|
||||||
int naxes;
|
|
||||||
int nhats;
|
|
||||||
int nballs;
|
|
||||||
int nbuttons;
|
|
||||||
struct joystick_hwdata* hwdata;
|
|
||||||
int16_t axes[256];
|
|
||||||
uint8_t hats[256];
|
|
||||||
uint8_t buttons[256];
|
|
||||||
} SDL_Joystick;
|
|
||||||
|
|
||||||
#define SDL_HAT_UP 1
|
|
||||||
#define SDL_HAT_RIGHTUP 2
|
|
||||||
#define SDL_HAT_RIGHT 3
|
|
||||||
#define SDL_HAT_RIGHTDOWN 4
|
|
||||||
#define SDL_HAT_DOWN 5
|
|
||||||
#define SDL_HAT_LEFTDOWN 6
|
|
||||||
#define SDL_HAT_LEFT 7
|
|
||||||
#define SDL_HAT_LEFTUP 8
|
|
||||||
#define SDL_HAT_CENTERED 0
|
|
||||||
|
|
||||||
typedef uint8_t Uint8;
|
|
||||||
|
|
||||||
//Driver -> Wrapper.
|
|
||||||
extern uint8_t SDL_numjoysticks;
|
|
||||||
int SDL_PrivateJoystickAxis(SDL_Joystick* j, uint8_t axis, int16_t value);
|
|
||||||
int SDL_PrivateJoystickBall(SDL_Joystick* j, uint8_t ball, int16_t dx, int16_t dy);
|
|
||||||
int SDL_PrivateJoystickHat(SDL_Joystick* j, uint8_t hat, uint8_t val);
|
|
||||||
int SDL_PrivateJoystickButton(SDL_Joystick* j, uint8_t button, uint8_t state);
|
|
||||||
void SDL_SetError(const char* err);
|
|
||||||
//Wrapper -> Driver.
|
|
||||||
int SDL_SYS_JoystickInit(void);
|
|
||||||
const char *SDL_SYS_JoystickName(int index);
|
|
||||||
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick);
|
|
||||||
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick);
|
|
||||||
void SDL_SYS_JoystickClose(SDL_Joystick *joystick);
|
|
||||||
void SDL_SYS_JoystickQuit(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -248,10 +248,6 @@ void wxeditor_autohold::update_controls()
|
||||||
d.panel->SetSizer(d.rtop);
|
d.panel->SetSizer(d.rtop);
|
||||||
d.box = new wxStaticBox(d.panel, wxID_ANY, towxstring(_controller_labels[i.logical]));
|
d.box = new wxStaticBox(d.panel, wxID_ANY, towxstring(_controller_labels[i.logical]));
|
||||||
d.top = new wxStaticBoxSizer(d.box, wxVERTICAL);
|
d.top = new wxStaticBoxSizer(d.box, wxVERTICAL);
|
||||||
#ifdef __WXMAC__
|
|
||||||
d.label = new wxStaticText(d.panel, wxID_ANY, towxstring(_controller_labels[i.logical]));
|
|
||||||
d.top->Add(d.label);
|
|
||||||
#endif
|
|
||||||
current = d.grid = new wxFlexGridSizer(0, 3, 0, 0);
|
current = d.grid = new wxFlexGridSizer(0, 3, 0, 0);
|
||||||
d.top->Add(d.grid);
|
d.top->Add(d.grid);
|
||||||
d.rtop->Add(d.top);
|
d.rtop->Add(d.top);
|
||||||
|
|
|
@ -514,10 +514,6 @@ void wxeditor_tasinput::update_controls()
|
||||||
d.panel->SetSizer(d.rtop);
|
d.panel->SetSizer(d.rtop);
|
||||||
d.box = new wxStaticBox(d.panel, wxID_ANY, towxstring(_controller_labels[i.logical]));
|
d.box = new wxStaticBox(d.panel, wxID_ANY, towxstring(_controller_labels[i.logical]));
|
||||||
current = d.top = new wxStaticBoxSizer(d.box, wxVERTICAL);
|
current = d.top = new wxStaticBoxSizer(d.box, wxVERTICAL);
|
||||||
#ifdef __WXMAC__
|
|
||||||
d.label = new wxStaticText(d.panel, wxID_ANY, towxstring(_controller_labels[i.logical]));
|
|
||||||
d.top->Add(d.label);
|
|
||||||
#endif
|
|
||||||
d.rtop->Add(d.top);
|
d.rtop->Add(d.top);
|
||||||
hsizer->Add(d.panel);
|
hsizer->Add(d.panel);
|
||||||
panels.push_back(d);
|
panels.push_back(d);
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#ifdef __WXMAC__
|
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void bring_app_foreground()
|
|
||||||
{
|
|
||||||
#ifdef __WXMAC__
|
|
||||||
//On Mac OS X, make the application foreground application.
|
|
||||||
ProcessSerialNumber PSN;
|
|
||||||
GetCurrentProcess(&PSN);
|
|
||||||
TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
|
|
||||||
#endif
|
|
||||||
}
|
|
|
@ -30,9 +30,6 @@ namespace
|
||||||
{ wxMOD_CONTROL, "ctrl", NULL },
|
{ wxMOD_CONTROL, "ctrl", NULL },
|
||||||
{ wxMOD_SHIFT, "shift", NULL },
|
{ wxMOD_SHIFT, "shift", NULL },
|
||||||
{ wxMOD_META, "meta", NULL },
|
{ wxMOD_META, "meta", NULL },
|
||||||
#ifdef __WXMAC__
|
|
||||||
{ wxMOD_CMD, "cmd", NULL },
|
|
||||||
#endif
|
|
||||||
{ 0, NULL, NULL }
|
{ 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,10 @@
|
||||||
#include <wx/cmdline.h>
|
#include <wx/cmdline.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifdef __WXMAC__
|
||||||
|
#error "Mac OS is not supported"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define UISERV_REFRESH_TITLE 9990
|
#define UISERV_REFRESH_TITLE 9990
|
||||||
#define UISERV_RESIZED 9991
|
#define UISERV_RESIZED 9991
|
||||||
#define UISERV_UIFUN 9992
|
#define UISERV_UIFUN 9992
|
||||||
|
@ -554,7 +558,6 @@ bool lsnes_app::OnInit()
|
||||||
|
|
||||||
reached_main();
|
reached_main();
|
||||||
set_random_seed();
|
set_random_seed();
|
||||||
bring_app_foreground();
|
|
||||||
|
|
||||||
if(pluginmanager_mode)
|
if(pluginmanager_mode)
|
||||||
if(!wxeditor_plugin_manager_display(NULL))
|
if(!wxeditor_plugin_manager_display(NULL))
|
||||||
|
|
Loading…
Add table
Reference in a new issue