Initial commit
This commit is contained in:
commit
6498401a16
674
LICENSE
Normal file
674
LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, 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
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
218
Makefile
Normal file
218
Makefile
Normal file
@ -0,0 +1,218 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
# Clear the implicit built in rules
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(DEVKITPPC)),)
|
||||
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
|
||||
endif
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
|
||||
endif
|
||||
export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH)
|
||||
export LIBOGC_INC := $(DEVKITPRO)/libogc/include
|
||||
export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
|
||||
export PORTLIBS := $(DEVKITPRO)/portlibs/ppc
|
||||
|
||||
PREFIX := powerpc-eabi-
|
||||
|
||||
export AS := $(PREFIX)as
|
||||
export CC := $(PREFIX)gcc
|
||||
export CXX := $(PREFIX)g++
|
||||
export AR := $(PREFIX)ar
|
||||
export OBJCOPY := $(PREFIX)objcopy
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# INCLUDES is a list of directories containing extra header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := tcpgecko
|
||||
BUILD := build
|
||||
BUILD_DBG := $(TARGET)_dbg
|
||||
SOURCES := src \
|
||||
src/dynamic_libs \
|
||||
src/game \
|
||||
src/fs \
|
||||
src/kernel \
|
||||
src/patcher \
|
||||
src/system \
|
||||
src/utils
|
||||
DATA :=
|
||||
|
||||
INCLUDES := src
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||
CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||
ASFLAGS := -mregnames
|
||||
LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
Q := @
|
||||
MAKEFLAGS += --no-print-directory
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lz
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(CURDIR) \
|
||||
$(DEVKITPPC)/lib \
|
||||
$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 \
|
||||
$(PORTLIBS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
export PROJECTDIR := $(CURDIR)
|
||||
export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET)
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# automatically build a list of object files for our project
|
||||
#---------------------------------------------------------------------------------
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf)))
|
||||
PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
export LD := $(CC)
|
||||
else
|
||||
export LD := $(CXX)
|
||||
endif
|
||||
|
||||
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||
$(sFILES:.s=.o) $(SFILES:.S=.o) \
|
||||
$(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of include paths
|
||||
#---------------------------------------------------------------------------------
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) \
|
||||
-I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of library paths
|
||||
#---------------------------------------------------------------------------------
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
|
||||
-L$(LIBOGC_LIB) -L$(PORTLIBS)/lib
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
.PHONY: $(BUILD) clean install
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT).elf: $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .jpg extension
|
||||
#---------------------------------------------------------------------------------
|
||||
%.elf: link.ld $(OFILES)
|
||||
@echo "linking ... $(TARGET).elf"
|
||||
$(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS)
|
||||
$(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@
|
||||
|
||||
../data/loader.bin:
|
||||
$(MAKE) -C ../loader clean
|
||||
$(MAKE) -C ../loader
|
||||
#---------------------------------------------------------------------------------
|
||||
%.a:
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $@)
|
||||
@rm -f $@
|
||||
@$(AR) -rc $@ $^
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.o: %.cpp
|
||||
@echo $(notdir $<)
|
||||
@$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.o: %.c
|
||||
@echo $(notdir $<)
|
||||
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.o: %.S
|
||||
@echo $(notdir $<)
|
||||
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.png.o : %.png
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.jpg.o : %.jpg
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.ttf.o : %.ttf
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.wav.o : %.wav
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.mp3.o : %.mp3
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.ogg.o : %.ogg
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# What is this?
|
||||
This is the official TCP Gecko Installer of the [JGecko U](https://github.com/BullyWiiPlaza/JGeckoU) client. You will only receive support if you use the latest versions of both.
|
||||
|
||||
# How do I use this?
|
||||
This is an app for the [Homebrew Launcher](https://github.com/dimok789/homebrew_launcher). Make sure to read the [setup guide](https://gbatemp.net/threads/jgecko-u-setup-guide.426292/).
|
||||
|
||||
# Can I use TCP Gecko.NET?
|
||||
No, you will run into incompatibility problems. It's not supported anymore but for what do you still need it? Submit a feature request and it might happen.
|
||||
|
||||
# Does this support [DiiBugger](https://github.com/Kinnay/DiiBugger)?
|
||||
No. Both projects are fundamentally different.
|
||||
|
||||
# How do I compile?
|
||||
Just like described [here](https://github.com/dimok789/homebrew_launcher/blob/master/README.md#building-the-homebrew-launcher).
|
||||
|
||||
# Credits
|
||||
**dimok** for Homebrew Launcher project engine/base
|
||||
**BullyWiiPlaza** for further development of advanced/efficient features
|
||||
**wj44** for porting [`pyGecko`](https://github.com/wiiudev/pyGecko) to the Homebrew Launcher and some development
|
||||
**Marionumber1** for exploit development and TCP Gecko Installer contributions
|
||||
**NWPlayer123** for the `pyGecko` client library
|
||||
**Chadderz** for the original `TCP Gecko Installer`
|
||||
**Kinnay** for some `DiiBugger` code this project made use of
|
BIN
codehandler.bin
Normal file
BIN
codehandler.bin
Normal file
Binary file not shown.
BIN
meta/icon.png
Normal file
BIN
meta/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
14
meta/meta.xml
Normal file
14
meta/meta.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<app version="1">
|
||||
<name>TCPgecko</name>
|
||||
<coder>Wj44</coder>
|
||||
<version>1.1</version>
|
||||
<release_date>20160503120400</release_date>
|
||||
<short_description>WiiU RAM Hacking</short_description>
|
||||
<long_description>A memory editor that does magical things to your games. In order to apply Cafe Codes (real-time cheats) use JGecko U.
|
||||
Special Thanks to:
|
||||
Chadderz, Marionumber1 - TCPGecko codehandler
|
||||
pwsincd - icon and xml
|
||||
CosmoCortney - codehandler for cheat codes, xml
|
||||
</long_description>
|
||||
</app>
|
74
src/common/common.h
Normal file
74
src/common/common.h
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os_defs.h"
|
||||
|
||||
#define CODE_HANDLER_INSTALL_ADDRESS 0x010F4000
|
||||
|
||||
#define CAFE_OS_SD_PATH "/vol/external01"
|
||||
#define SD_PATH "sd:"
|
||||
#define WIIU_PATH "/wiiu"
|
||||
|
||||
/* Macros for libs */
|
||||
#define LIB_CORE_INIT 0
|
||||
#define LIB_NSYSNET 1
|
||||
#define LIB_GX2 2
|
||||
#define LIB_AOC 3
|
||||
#define LIB_AX 4
|
||||
#define LIB_FS 5
|
||||
#define LIB_OS 6
|
||||
#define LIB_PADSCORE 7
|
||||
#define LIB_SOCKET 8
|
||||
#define LIB_SYS 9
|
||||
#define LIB_VPAD 10
|
||||
#define LIB_NN_ACP 11
|
||||
#define LIB_SYSHID 12
|
||||
#define LIB_VPADBASE 13
|
||||
|
||||
// functions types
|
||||
#define STATIC_FUNCTION 0
|
||||
#define DYNAMIC_FUNCTION 1
|
||||
|
||||
// none dynamic libs
|
||||
#define LIB_LOADER 0x1001
|
||||
|
||||
|
||||
#ifndef MEM_BASE
|
||||
#define MEM_BASE (0x00800000)
|
||||
#endif
|
||||
|
||||
#define ELF_DATA_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x00))
|
||||
#define ELF_DATA_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x04))
|
||||
#define MAIN_ENTRY_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x00))
|
||||
#define OS_FIRMWARE (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x04))
|
||||
|
||||
#define OS_SPECIFICS ((OsSpecifics*)(MEM_BASE + 0x1500))
|
||||
|
||||
#ifndef EXIT_SUCCESS
|
||||
#define EXIT_SUCCESS 0
|
||||
#endif
|
||||
#define EXIT_HBL_EXIT 0xFFFFFFFE
|
||||
#define EXIT_RELAUNCH_ON_LOAD 0xFFFFFFFD
|
||||
|
||||
#define RESTORE_INSTR_MAGIC 0xC001C0DE
|
||||
#define RESTORE_INSTR_ADDR ((restore_instructions_t*)(MEM_BASE + 0x1600))
|
||||
|
||||
typedef struct _restore_instructions_t {
|
||||
unsigned int magic;
|
||||
unsigned int instr_count;
|
||||
struct {
|
||||
unsigned int addr;
|
||||
unsigned int instr;
|
||||
} data[0];
|
||||
} restore_instructions_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_H */
|
||||
|
69
src/common/fs_defs.h
Normal file
69
src/common/fs_defs.h
Normal file
@ -0,0 +1,69 @@
|
||||
#ifndef FS_DEFS_H
|
||||
#define FS_DEFS_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* FS defines and types */
|
||||
#define FS_MAX_LOCALPATH_SIZE 511
|
||||
#define FS_MAX_MOUNTPATH_SIZE 128
|
||||
#define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE)
|
||||
#define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE
|
||||
|
||||
#define FS_STATUS_OK 0
|
||||
#define FS_STATUS_EXISTS -5
|
||||
#define FS_STATUS_STORAGE_FULL -12
|
||||
#define FS_STATUS_JOURNAL_FULL -13
|
||||
|
||||
#define FS_RET_UNSUPPORTED_CMD 0x0400
|
||||
#define FS_RET_NO_ERROR 0x0000
|
||||
#define FS_RET_ALL_ERROR (unsigned int)(-1)
|
||||
|
||||
|
||||
#define FS_STAT_FLAG_IS_DIRECTORY 0x80000000
|
||||
|
||||
/* max length of file/dir name */
|
||||
#define FS_MAX_ENTNAME_SIZE 256
|
||||
|
||||
#define FS_SOURCETYPE_EXTERNAL 0
|
||||
#define FS_SOURCETYPE_HFIO 1
|
||||
#define FS_SOURCETYPE_HFIO 1
|
||||
/* FS data buffer alignment */
|
||||
#define FS_IO_BUFFER_ALIGN 64
|
||||
|
||||
#define FS_MOUNT_SOURCE_SIZE 0x300
|
||||
#define FS_CLIENT_SIZE 0x1700
|
||||
#define FS_CMD_BLOCK_SIZE 0xA80
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flag;
|
||||
uint32_t permission;
|
||||
uint32_t owner_id;
|
||||
uint32_t group_id;
|
||||
uint32_t size;
|
||||
uint32_t alloc_size;
|
||||
uint64_t quota_size;
|
||||
uint32_t ent_id;
|
||||
uint64_t ctime;
|
||||
uint64_t mtime;
|
||||
uint8_t attributes[48];
|
||||
} __attribute__((packed)) FSStat;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FSStat stat;
|
||||
char name[FS_MAX_ENTNAME_SIZE];
|
||||
} FSDirEntry;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FS_DEFS_H */
|
||||
|
116
src/common/kernel_defs.h
Normal file
116
src/common/kernel_defs.h
Normal file
@ -0,0 +1,116 @@
|
||||
#ifndef __KERNEL_DEFS_H_
|
||||
#define __KERNEL_DEFS_H_
|
||||
|
||||
#include "types.h"
|
||||
#include "fs_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// original structure in the kernel that is originally 0x1270 long
|
||||
typedef struct
|
||||
{
|
||||
uint32_t version_cos_xml; // version tag from cos.xml
|
||||
uint64_t os_version; // os_version from app.xml
|
||||
uint64_t title_id; // title_id tag from app.xml
|
||||
uint32_t app_type; // app_type tag from app.xml
|
||||
uint32_t cmdFlags; // unknown tag as it is always 0 (might be cmdFlags from cos.xml but i am not sure)
|
||||
char rpx_name[0x1000]; // rpx name from cos.xml
|
||||
uint32_t unknown2; // 0x050B8304 in mii maker and system menu (looks a bit like permissions complex that got masked!?)
|
||||
uint32_t unknown3[63]; // those were all zeros, but its probably connected with unknown2
|
||||
uint32_t max_size; // max_size in cos.xml which defines the maximum amount of memory reserved for the app
|
||||
uint32_t avail_size; // avail_size or codegen_size in cos.xml (seems to mostly be 0?)
|
||||
uint32_t codegen_size; // codegen_size or avail_size in cos.xml (seems to mostly be 0?)
|
||||
uint32_t codegen_core; // codegen_core in cos.xml (seems to mostly be 1?)
|
||||
uint32_t max_codesize; // max_codesize in cos.xml
|
||||
uint32_t overlay_arena; // overlay_arena in cos.xml
|
||||
uint32_t unknown4[59]; // all zeros it seems
|
||||
uint32_t default_stack0_size; // not sure because always 0 but very likely
|
||||
uint32_t default_stack1_size; // not sure because always 0 but very likely
|
||||
uint32_t default_stack2_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone0_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone1_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone2_size; // not sure because always 0 but very likely
|
||||
uint32_t exception_stack0_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t exception_stack1_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t exception_stack2_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t sdk_version; // from app.xml, 20909 (0x51AD) on mii maker
|
||||
uint32_t title_version; // from app.xml, 0x32 on mii maker
|
||||
/*
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// the next part might be changing from title to title?! I don't think its important but nice to know maybe....
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char mlc[4]; // string "mlc" on mii maker and sysmenu
|
||||
uint32_t unknown5[7]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown6_one; // 0x01 on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char ACP[4]; // string "ACP" on mii maker and sysmenu
|
||||
uint32_t unknown7[15]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown8_5; // 0x05 on mii maker and sysmenu
|
||||
uint32_t unknown9_zero; // 0x00 on mii maker and sysmenu
|
||||
uint32_t unknown10_ptr; // 0xFF23DD0C pointer on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char UVD[4]; // string "UVD" on mii maker and sysmenu
|
||||
uint32_t unknown11[15]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown12_5; // 0x05 on mii maker and sysmenu
|
||||
uint32_t unknown13_zero; // 0x00 on mii maker and sysmenu
|
||||
uint32_t unknown14_ptr; // 0xFF23EFC8 pointer on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char SND[4]; // string "SND" on mii maker and sysmenu
|
||||
uint32_t unknown15[15]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown16_5; // 0x05 on mii maker and sysmenu
|
||||
uint32_t unknown17_zero; // 0x00 on mii maker and sysmenu
|
||||
uint32_t unknown18_ptr; // 0xFF23F014 pointer on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint32_t unknown19; // 0x02 on miimaker, 0x0F on system menu
|
||||
*/
|
||||
// after that only zeros follow
|
||||
} __attribute__((packed)) CosAppXmlInfo;
|
||||
|
||||
|
||||
// Our own cos/app.xml struct which uses only uses as much memory as really needed, since many things are just zeros in the above structure
|
||||
// This structure is only 0x64 bytes long + RPX name length (dynamic up to 0x1000 theoretically)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t version_cos_xml; // version tag from cos.xml
|
||||
uint64_t os_version; // os_version from app.xml
|
||||
uint64_t title_id; // title_id tag from app.xml
|
||||
uint32_t app_type; // app_type tag from app.xml
|
||||
uint32_t cmdFlags; // unknown tag as it is always 0 (might be cmdFlags from cos.xml but i am not sure)
|
||||
uint32_t max_size; // max_size in cos.xml which defines the maximum amount of memory reserved for the app
|
||||
uint32_t avail_size; // avail_size or codegen_size in cos.xml (seems to mostly be 0?)
|
||||
uint32_t codegen_size; // codegen_size or avail_size in cos.xml (seems to mostly be 0?)
|
||||
uint32_t codegen_core; // codegen_core in cos.xml (seems to mostly be 1?)
|
||||
uint32_t max_codesize; // max_codesize in cos.xml
|
||||
uint32_t overlay_arena; // overlay_arena in cos.xml
|
||||
uint32_t default_stack0_size; // not sure because always 0 but very likely
|
||||
uint32_t default_stack1_size; // not sure because always 0 but very likely
|
||||
uint32_t default_stack2_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone0_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone1_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone2_size; // not sure because always 0 but very likely
|
||||
uint32_t exception_stack0_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t exception_stack1_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t exception_stack2_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t sdk_version; // from app.xml, 20909 (0x51AD) on mii maker
|
||||
uint32_t title_version; // from app.xml, 0x32 on mii maker
|
||||
char rpx_name[FS_MAX_ENTNAME_SIZE]; // rpx name from cos.xml, length 256 as it can't get bigger from FS anyway
|
||||
} __attribute__((packed)) ReducedCosAppXmlInfo;
|
||||
|
||||
typedef struct _bat_t
|
||||
{
|
||||
u32 h;
|
||||
u32 l;
|
||||
} bat_t;
|
||||
|
||||
typedef struct _bat_table_t
|
||||
{
|
||||
bat_t bat[8];
|
||||
} bat_table_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __KERNEL_DEFS_H_
|
40
src/common/loader_defs.h
Normal file
40
src/common/loader_defs.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __LOADER_DEFS_H_
|
||||
#define __LOADER_DEFS_H_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// struct holding the globals of the loader (there are actually more but we don't need others)
|
||||
typedef struct _loader_globals_t
|
||||
{
|
||||
int sgIsLoadingBuffer;
|
||||
int sgFileType;
|
||||
int sgProcId;
|
||||
int sgGotBytes;
|
||||
int sgFileOffset;
|
||||
int sgBufferNumber;
|
||||
int sgBounceError;
|
||||
char sgLoadName[0x1000];
|
||||
} __attribute__((packed)) loader_globals_t;
|
||||
|
||||
typedef struct _loader_globals_550_t
|
||||
{
|
||||
int sgFinishedLoadingBuffer;
|
||||
int sgFileType;
|
||||
int sgProcId;
|
||||
int sgGotBytes;
|
||||
int sgTotalBytes;
|
||||
int sgFileOffset;
|
||||
int sgBufferNumber;
|
||||
int sgBounceError;
|
||||
char sgLoadName[0x1000];
|
||||
} __attribute__((packed)) loader_globals_550_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __LOADER_DEFS_H_
|
125
src/common/os_defs.h
Normal file
125
src/common/os_defs.h
Normal file
@ -0,0 +1,125 @@
|
||||
#ifndef __OS_DEFS_H_
|
||||
#define __OS_DEFS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*struct OSThread;
|
||||
|
||||
struct OSThreadLink {
|
||||
OSThread *next;
|
||||
OSThread *prev;
|
||||
};
|
||||
|
||||
struct OSThreadQueue {
|
||||
OSThread *head;
|
||||
OSThread *tail;
|
||||
void *parentStruct;
|
||||
u32 reserved;
|
||||
};
|
||||
|
||||
struct OSMessage {
|
||||
u32 message;
|
||||
u32 data0;
|
||||
u32 data1;
|
||||
u32 data2;
|
||||
};
|
||||
|
||||
struct OSMessageQueue {
|
||||
u32 tag;
|
||||
char *name;
|
||||
u32 reserved;
|
||||
|
||||
OSThreadQueue sendQueue;
|
||||
OSThreadQueue recvQueue;
|
||||
OSMessage *messages;
|
||||
int msgCount;
|
||||
int firstIndex;
|
||||
int usedCount;
|
||||
};
|
||||
|
||||
struct OSContext {
|
||||
char tag[8];
|
||||
|
||||
u32 gpr[32];
|
||||
|
||||
u32 cr;
|
||||
u32 lr;
|
||||
u32 ctr;
|
||||
u32 xer;
|
||||
|
||||
u32 srr0;
|
||||
u32 srr1;
|
||||
|
||||
u32 ex0;
|
||||
u32 ex1;
|
||||
|
||||
u32 exception_type;
|
||||
u32 reserved;
|
||||
|
||||
double fpscr;
|
||||
double fpr[32];
|
||||
|
||||
u16 spinLockCount;
|
||||
u16 state;
|
||||
|
||||
u32 gqr[8];
|
||||
u32 pir;
|
||||
double psf[32];
|
||||
|
||||
u64 coretime[3];
|
||||
u64 starttime;
|
||||
|
||||
u32 error;
|
||||
u32 attributes;
|
||||
|
||||
u32 pmc1;
|
||||
u32 pmc2;
|
||||
u32 pmc3;
|
||||
u32 pmc4;
|
||||
u32 mmcr0;
|
||||
u32 mmcr1;
|
||||
};
|
||||
|
||||
typedef int (*ThreadFunc)(int argc, void *argv);
|
||||
|
||||
struct OSThread {
|
||||
OSContext context;
|
||||
|
||||
u32 txtTag;
|
||||
u8 state;
|
||||
u8 attr;
|
||||
|
||||
short threadId;
|
||||
int suspend;
|
||||
int priority;
|
||||
|
||||
char _[0x394 - 0x330];
|
||||
|
||||
void *stackBase;
|
||||
void *stackEnd;
|
||||
|
||||
ThreadFunc entryPoint;
|
||||
|
||||
char _3A0[0x6A0 - 0x3A0];
|
||||
};*/
|
||||
|
||||
typedef struct _OsSpecifics
|
||||
{
|
||||
unsigned int addr_OSDynLoad_Acquire;
|
||||
unsigned int addr_OSDynLoad_FindExport;
|
||||
unsigned int addr_OSTitle_main_entry;
|
||||
|
||||
unsigned int addr_KernSyscallTbl1;
|
||||
unsigned int addr_KernSyscallTbl2;
|
||||
unsigned int addr_KernSyscallTbl3;
|
||||
unsigned int addr_KernSyscallTbl4;
|
||||
unsigned int addr_KernSyscallTbl5;
|
||||
} OsSpecifics;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __OS_DEFS_H_
|
11
src/common/retain_vars.c
Normal file
11
src/common/retain_vars.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <gctypes.h>
|
||||
u8 gSettingLaunchPyGecko __attribute__((section(".data"))) = 0;
|
||||
u8 gSettingUseUpdatepath __attribute__((section(".data"))) = 0;
|
||||
u8 gSettingPadconMode __attribute__((section(".data"))) = 0;
|
||||
u8 gCursorInitDone __attribute__((section(".data"))) = 0;
|
||||
u8 gPatchSDKDone __attribute__((section(".data"))) = 0;
|
||||
u8 gHIDPADEnabled __attribute__((section(".data"))) = 0;
|
||||
u8 gEnableDLC __attribute__((section(".data"))) = 0;
|
||||
u32 gLoaderPhysicalBufferAddr __attribute__((section(".data"))) = 0;
|
||||
u32 gLogUDP __attribute__((section(".data"))) = 0;
|
||||
char gServerIP[16] __attribute__((section(".data")));
|
15
src/common/retain_vars.h
Normal file
15
src/common/retain_vars.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef RETAINS_VARS_H_
|
||||
#define RETAINS_VARS_H_
|
||||
#include <gctypes.h>
|
||||
|
||||
extern u8 gSettingLaunchPyGecko;
|
||||
extern u8 gSettingUseUpdatepath;
|
||||
extern u8 gSettingPadconMode;
|
||||
extern u8 gCursorInitDone;
|
||||
extern u8 gPatchSDKDone;
|
||||
extern u8 gHIDPADEnabled;
|
||||
extern u8 gEnableDLC;
|
||||
extern u32 gLoaderPhysicalBufferAddr;
|
||||
extern char gServerIP[16];
|
||||
|
||||
#endif // RETAINS_VARS_H_
|
7
src/common/types.h
Normal file
7
src/common/types.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
#endif /* TYPES_H */
|
||||
|
49
src/dynamic_libs/aoc_functions.c
Normal file
49
src/dynamic_libs/aoc_functions.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "os_functions.h"
|
||||
|
||||
EXPORT_DECL(s32, AOC_Initialize, void);
|
||||
EXPORT_DECL(s32, AOC_Finalize, void);
|
||||
EXPORT_DECL(u32, AOC_CalculateWorkBufferSize, u32 num_titles);
|
||||
EXPORT_DECL(s32, AOC_ListTitle, u32 * num_titles, void * titles, u32 max_titles, void * buffer, u32 buffer_size);
|
||||
EXPORT_DECL(s32, AOC_OpenTitle, char* aoc_path, void * title, void * buffer, u32 buffer_size);
|
||||
EXPORT_DECL(s32, AOC_CloseTitle, void * title);
|
||||
|
||||
void InitAocFunctionPointers(void)
|
||||
{
|
||||
unsigned int aoc_handle = 0;
|
||||
OSDynLoad_Acquire("nn_aoc.rpl", &aoc_handle);
|
||||
|
||||
if(aoc_handle == 0)
|
||||
return;
|
||||
|
||||
//! assigning those is not mandatory and it does not always work to load them
|
||||
OSDynLoad_FindExport(aoc_handle, 0, "AOC_Initialize", &AOC_Initialize);
|
||||
OSDynLoad_FindExport(aoc_handle, 0, "AOC_Finalize", &AOC_Finalize);
|
||||
OSDynLoad_FindExport(aoc_handle, 0, "AOC_CalculateWorkBufferSize", &AOC_CalculateWorkBufferSize);
|
||||
OSDynLoad_FindExport(aoc_handle, 0, "AOC_ListTitle", &AOC_ListTitle);
|
||||
OSDynLoad_FindExport(aoc_handle, 0, "AOC_OpenTitle", &AOC_OpenTitle);
|
||||
OSDynLoad_FindExport(aoc_handle, 0, "AOC_CloseTitle", &AOC_CloseTitle);
|
||||
}
|
||||
|
46
src/dynamic_libs/aoc_functions.h
Normal file
46
src/dynamic_libs/aoc_functions.h
Normal file
@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __AOC_FUNCTIONS_H_
|
||||
#define __AOC_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AOC_TITLE_SIZE 104
|
||||
|
||||
void InitAocFunctionPointers(void);
|
||||
|
||||
extern s32 (* AOC_Initialize)(void);
|
||||
extern s32 (* AOC_Finalize)(void);
|
||||
extern u32 (* AOC_CalculateWorkBufferSize)(u32 num_titles);
|
||||
extern s32 (* AOC_ListTitle)(u32 * num_titles, void * titles, u32 max_titles, void * buffer, u32 buffer_size);
|
||||
extern s32 (* AOC_OpenTitle)(char* aoc_path, void * title, void * buffer, u32 buffer_size);
|
||||
extern s32 (* AOC_CloseTitle)(void * title);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __SYS_FUNCTIONS_H_
|
74
src/dynamic_libs/ax_functions.c
Normal file
74
src/dynamic_libs/ax_functions.c
Normal file
@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "os_functions.h"
|
||||
#include "ax_functions.h"
|
||||
|
||||
EXPORT_DECL(void, AXInitWithParams, u32 * params);
|
||||
EXPORT_DECL(void, AXQuit, void);
|
||||
EXPORT_DECL(u32, AXGetInputSamplesPerSec, void);
|
||||
EXPORT_DECL(u32, AXGetInputSamplesPerFrame, void);
|
||||
EXPORT_DECL(s32, AXVoiceBegin, void *v);
|
||||
EXPORT_DECL(s32, AXVoiceEnd, void *v);
|
||||
EXPORT_DECL(void, AXSetVoiceType, void *v, u16 type);
|
||||
EXPORT_DECL(void, AXSetVoiceOffsets, void *v, const void *buf);
|
||||
EXPORT_DECL(void, AXSetVoiceSrcType, void *v, u32 type);
|
||||
EXPORT_DECL(void, AXSetVoiceVe, void *v, const void *vol);
|
||||
EXPORT_DECL(s32, AXSetVoiceDeviceMix, void *v, s32 device, u32 id, void *mix);
|
||||
EXPORT_DECL(void, AXSetVoiceState, void *v, u16 state);
|
||||
EXPORT_DECL(void, AXSetVoiceSrc, void *v, const void *src);
|
||||
EXPORT_DECL(s32, AXSetVoiceSrcRatio, void *v,f32 ratio)
|
||||
EXPORT_DECL(void *, AXAcquireVoice, u32 prio, void * callback, u32 arg);
|
||||
EXPORT_DECL(void, AXFreeVoice, void *v);
|
||||
EXPORT_DECL(void, AXRegisterFrameCallback, void * callback);
|
||||
EXPORT_DECL(u32, AXGetVoiceLoopCount, void *v);
|
||||
EXPORT_DECL(void, AXSetVoiceEndOffset, void *v, u32 offset);
|
||||
EXPORT_DECL(void, AXSetVoiceLoopOffset, void *v, u32 offset);
|
||||
|
||||
void InitAXFunctionPointers(void)
|
||||
{
|
||||
unsigned int *funcPointer = 0;
|
||||
unsigned int sound_handle;
|
||||
OSDynLoad_Acquire("sndcore2.rpl", &sound_handle);
|
||||
|
||||
OS_FIND_EXPORT(sound_handle, AXInitWithParams);
|
||||
OS_FIND_EXPORT(sound_handle, AXQuit);
|
||||
OS_FIND_EXPORT(sound_handle, AXGetInputSamplesPerSec);
|
||||
OS_FIND_EXPORT(sound_handle, AXVoiceBegin);
|
||||
OS_FIND_EXPORT(sound_handle, AXVoiceEnd);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceType);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceOffsets);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceSrcType);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceVe);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceDeviceMix);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceState);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceSrc);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceSrcRatio);
|
||||
OS_FIND_EXPORT(sound_handle, AXAcquireVoice);
|
||||
OS_FIND_EXPORT(sound_handle, AXFreeVoice);
|
||||
OS_FIND_EXPORT(sound_handle, AXRegisterFrameCallback);
|
||||
OS_FIND_EXPORT(sound_handle, AXGetVoiceLoopCount);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceEndOffset);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceLoopOffset);
|
||||
}
|
||||
|
59
src/dynamic_libs/ax_functions.h
Normal file
59
src/dynamic_libs/ax_functions.h
Normal file
@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __AX_FUNCTIONS_H_
|
||||
#define __AX_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
void InitAXFunctionPointers(void);
|
||||
|
||||
extern void (* AXInitWithParams)(u32 * params);
|
||||
extern void (* AXQuit)(void);
|
||||
extern u32 (* AXGetInputSamplesPerSec)(void);
|
||||
extern s32 (* AXVoiceBegin)(void *v);
|
||||
extern s32 (* AXVoiceEnd)(void *v);
|
||||
extern void (* AXSetVoiceType)(void *v, u16 type);
|
||||
extern void (* AXSetVoiceOffsets)(void *v, const void *buf);
|
||||
extern void (* AXSetVoiceSrcType)(void *v, u32 type);
|
||||
extern void (* AXSetVoiceVe)(void *v, const void *vol);
|
||||
extern s32 (* AXSetVoiceDeviceMix)(void *v, s32 device, u32 id, void *mix);
|
||||
extern void (* AXSetVoiceState)(void *v, u16 state);
|
||||
extern void (* AXSetVoiceSrc)(void *v, const void *src);
|
||||
extern s32 (* AXSetVoiceSrcRatio)(void *v, f32 ratio);
|
||||
extern void * (* AXAcquireVoice)(u32 prio, void * callback, u32 arg);
|
||||
extern void (* AXFreeVoice)(void *v);
|
||||
extern void (* AXRegisterFrameCallback)(void * callback);
|
||||
extern u32 (* AXGetVoiceLoopCount)(void * v);
|
||||
extern void (* AXSetVoiceEndOffset)(void * v, u32 offset);
|
||||
extern void (* AXSetVoiceLoopOffset)(void * v, u32 offset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __VPAD_FUNCTIONS_H_
|
167
src/dynamic_libs/fs_functions.c
Normal file
167
src/dynamic_libs/fs_functions.c
Normal file
@ -0,0 +1,167 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "fs_functions.h"
|
||||
#include "os_functions.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
EXPORT_DECL(int, FSInit, void);
|
||||
|
||||
EXPORT_DECL(int, FSShutdown, void);
|
||||
|
||||
EXPORT_DECL(int, FSAddClientEx, void *pClient, int unk_zero_param, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSDelClient, void *pClient);
|
||||
|
||||
EXPORT_DECL(void, FSInitCmdBlock, void *pCmd);
|
||||
|
||||
EXPORT_DECL(int, FSGetMountSource, void *pClient, void *pCmd, int type, void *source, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSMount, void *pClient, void *pCmd, void *source, char *target, uint32_t
|
||||
bytes, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSUnmount, void *pClient, void *pCmd, const char *target, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSGetStat, void *pClient, void *pCmd, const char *path, FSStat * stats, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSGetStatAsync, void *pClient, void *pCmd, const char *path, void *stats, int error,
|
||||
void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSRename, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error);
|
||||
|
||||
EXPORT_DECL(int, FSRenameAsync, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error,
|
||||
void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSRemove, void *pClient, void *pCmd, const char *path, int error);
|
||||
|
||||
EXPORT_DECL(int, FSRemoveAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSFlushQuota, void *pClient, void *pCmd, const char *path, int error);
|
||||
|
||||
EXPORT_DECL(int, FSFlushQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSGetFreeSpaceSize, void *pClient, void *pCmd, const char *path, uint64_t * returnedFreeSize,
|
||||
int error);
|
||||
|
||||
EXPORT_DECL(int, FSGetFreeSpaceSizeAsync, void *pClient, void *pCmd, const char *path, uint64_t * returnedFreeSize,
|
||||
int error, void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSRollbackQuota, void *pClient, void *pCmd, const char *path, int error);
|
||||
|
||||
EXPORT_DECL(int, FSRollbackQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSOpenDir, void *pClient, void *pCmd, const char *path, int *dh, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSOpenDirAsync, void *pClient, void *pCmd, const char *path, int *handle, int error,
|
||||
void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSReadDir, void *pClient, void *pCmd, int dh, FSDirEntry * dir_entry, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSRewindDir, void *pClient, void *pCmd, int dh, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSCloseDir, void *pClient, void *pCmd, int dh, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSChangeDir, void *pClient, void *pCmd, const char *path, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSChangeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSMakeDir, void *pClient, void *pCmd, const char *path, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSMakeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSOpenFileAsync, void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error,
|
||||
const void *asyncParams);
|
||||
|
||||
EXPORT_DECL(int, FSReadFile, void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag,
|
||||
int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSCloseFile, void *pClient, void *pCmd, int fd, int errHandling);
|
||||
|
||||
EXPORT_DECL(int, FSFlushFile, void *pClient, void *pCmd, int fd, int error);
|
||||
|
||||
EXPORT_DECL(int, FSTruncateFile, void *pClient, void *pCmd, int fd, int error);
|
||||
|
||||
EXPORT_DECL(int, FSGetStatFile, void *pClient, void *pCmd, int fd, void *buffer, int error);
|
||||
|
||||
EXPORT_DECL(int, FSSetPosFile, void *pClient, void *pCmd, int fd, int pos, int error);
|
||||
|
||||
EXPORT_DECL(int, FSWriteFile, void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd,
|
||||
int flag, int error);
|
||||
|
||||
EXPORT_DECL(int, FSBindMount, void *pClient, void *pCmd, char *source, char *target, int error);
|
||||
|
||||
EXPORT_DECL(int, FSBindUnmount, void *pClient, void *pCmd, char *target, int error);
|
||||
|
||||
void InitFSFunctionPointers(void) {
|
||||
unsigned int *funcPointer = 0;
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, FSInit);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSShutdown);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSAddClientEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSDelClient);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSInitCmdBlock);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSGetMountSource);
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, FSMount);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSUnmount);
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, FSGetStat);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSGetStatAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSRename);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSRenameAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSRemove);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSRemoveAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSFlushQuota);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSFlushQuotaAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSize);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSizeAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSRollbackQuota);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSRollbackQuotaAsync);
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, FSOpenDir);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSOpenDirAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSReadDir);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSRewindDir);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSCloseDir);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSChangeDir);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSChangeDirAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSMakeDir);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSMakeDirAsync);
|
||||
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, FSOpenFile);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSOpenFileAsync);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSReadFile);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSCloseFile);
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, FSFlushFile);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSTruncateFile);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSGetStatFile);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSSetPosFile);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSWriteFile);
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, FSBindMount);
|
||||
OS_FIND_EXPORT(coreinit_handle, FSBindUnmount);
|
||||
}
|
135
src/dynamic_libs/fs_functions.h
Normal file
135
src/dynamic_libs/fs_functions.h
Normal file
@ -0,0 +1,135 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __FS_FUNCTIONS_H_
|
||||
#define __FS_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common/fs_defs.h"
|
||||
|
||||
void InitFSFunctionPointers(void);
|
||||
|
||||
extern int (*FSInit)(void);
|
||||
|
||||
extern int (*FSShutdown)(void);
|
||||
|
||||
extern int (*FSAddClientEx)(void *pClient, int unk_zero_param, int errHandling);
|
||||
|
||||
extern int (*FSDelClient)(void *pClient);
|
||||
|
||||
extern void (*FSInitCmdBlock)(void *pCmd);
|
||||
|
||||
extern int (*FSGetMountSource)(void *pClient, void *pCmd, int type, void *source, int errHandling);
|
||||
|
||||
extern int (*FSMount)(void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int errHandling);
|
||||
|
||||
extern int (*FSUnmount)(void *pClient, void *pCmd, const char *target, int errHandling);
|
||||
|
||||
extern int (*FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error);
|
||||
|
||||
extern int
|
||||
(*FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSRemove)(void *pClient, void *pCmd, const char *path, int error);
|
||||
|
||||
extern int (*FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSGetStat)(void *pClient, void *pCmd, const char *path, FSStat *stats, int errHandling);
|
||||
|
||||
extern int (*FSGetStatAsync)(void *pClient, void *pCmd, const char *path, void *stats, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error);
|
||||
|
||||
extern int
|
||||
(*FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSRemove)(void *pClient, void *pCmd, const char *path, int error);
|
||||
|
||||
extern int (*FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSFlushQuota)(void *pClient, void *pCmd, const char *path, int error);
|
||||
|
||||
extern int (*FSFlushQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSGetFreeSpaceSize)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error);
|
||||
|
||||
extern int
|
||||
(*FSGetFreeSpaceSizeAsync)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error,
|
||||
void *asyncParams);
|
||||
|
||||
extern int (*FSRollbackQuota)(void *pClient, void *pCmd, const char *path, int error);
|
||||
|
||||
extern int (*FSRollbackQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSOpenDir)(void *pClient, void *pCmd, const char *path, int *dh, int errHandling);
|
||||
|
||||
extern int (*FSOpenDirAsync)(void *pClient, void *pCmd, const char *path, int *handle, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSReadDir)(void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling);
|
||||
|
||||
extern int (*FSRewindDir)(void *pClient, void *pCmd, int dh, int errHandling);
|
||||
|
||||
extern int (*FSCloseDir)(void *pClient, void *pCmd, int dh, int errHandling);
|
||||
|
||||
extern int (*FSChangeDir)(void *pClient, void *pCmd, const char *path, int errHandling);
|
||||
|
||||
extern int (*FSChangeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSMakeDir)(void *pClient, void *pCmd, const char *path, int errHandling);
|
||||
|
||||
extern int (*FSMakeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||
|
||||
extern int (*FSOpenFile)(void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling);
|
||||
|
||||
extern int (*FSOpenFileAsync)(void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error,
|
||||
const void *asyncParams);
|
||||
|
||||
extern int
|
||||
(*FSReadFile)(void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling);
|
||||
|
||||
extern int (*FSCloseFile)(void *pClient, void *pCmd, int fd, int errHandling);
|
||||
|
||||
extern int (*FSFlushFile)(void *pClient, void *pCmd, int fd, int error);
|
||||
|
||||
extern int (*FSTruncateFile)(void *pClient, void *pCmd, int fd, int error);
|
||||
|
||||
extern int (*FSGetStatFile)(void *pClient, void *pCmd, int fd, void *buffer, int error);
|
||||
|
||||
extern int (*FSSetPosFile)(void *pClient, void *pCmd, int fd, int pos, int error);
|
||||
|
||||
extern int
|
||||
(*FSWriteFile)(void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag,
|
||||
int error);
|
||||
|
||||
extern int (*FSBindMount)(void *pClient, void *pCmd, char *source, char *target, int error);
|
||||
|
||||
extern int (*FSBindUnmount)(void *pClient, void *pCmd, char *target, int error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __FS_FUNCTIONS_H_
|
162
src/dynamic_libs/gx2_functions.c
Normal file
162
src/dynamic_libs/gx2_functions.c
Normal file
@ -0,0 +1,162 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "os_functions.h"
|
||||
#include "gx2_types.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
EXPORT_DECL(void, GX2Init, u32 * init_attribs);
|
||||
EXPORT_DECL(void, GX2Shutdown, void);
|
||||
EXPORT_DECL(void, GX2Flush, void);
|
||||
EXPORT_DECL(s32, GX2GetMainCoreId, void) ;
|
||||
EXPORT_DECL(s32, GX2DrawDone, void);
|
||||
EXPORT_DECL(void, GX2ClearColor, GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a);
|
||||
EXPORT_DECL(void, GX2SetViewport, f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ);
|
||||
EXPORT_DECL(void, GX2SetScissor, u32 x_orig, u32 y_orig, u32 wd, u32 ht);
|
||||
EXPORT_DECL(void, GX2SetContextState, const GX2ContextState* state);
|
||||
EXPORT_DECL(void, GX2DrawEx, s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count);
|
||||
EXPORT_DECL(void, GX2DrawIndexedEx, s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count);
|
||||
EXPORT_DECL(void, GX2ClearDepthStencilEx, GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode);
|
||||
EXPORT_DECL(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer, s32 scan_target);
|
||||
EXPORT_DECL(void, GX2SwapScanBuffers, void);
|
||||
EXPORT_DECL(void, GX2SetTVEnable, s32 enable);
|
||||
EXPORT_DECL(void, GX2SetSwapInterval, u32 swap_interval);
|
||||
EXPORT_DECL(u32, GX2GetSwapInterval, void);
|
||||
EXPORT_DECL(void, GX2WaitForVsync, void);
|
||||
EXPORT_DECL(void, GX2CalcTVSize, s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed);
|
||||
EXPORT_DECL(void, GX2Invalidate, s32 invalidate_type, void * ptr, u32 buffer_size);
|
||||
EXPORT_DECL(void, GX2SetTVBuffer, void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode);
|
||||
EXPORT_DECL(void, GX2CalcSurfaceSizeAndAlignment, GX2Surface *surface);
|
||||
EXPORT_DECL(void, GX2InitDepthBufferRegs, GX2DepthBuffer *depthBuffer);
|
||||
EXPORT_DECL(void, GX2InitColorBufferRegs, GX2ColorBuffer *colorBuffer);
|
||||
EXPORT_DECL(void, GX2CalcColorBufferAuxInfo, GX2ColorBuffer *colorBuffer, u32 *size, u32 *align);
|
||||
EXPORT_DECL(void, GX2CalcDepthBufferHiZInfo, GX2DepthBuffer *depthBuffer, u32 *size, u32 *align);
|
||||
EXPORT_DECL(void, GX2InitDepthBufferHiZEnable, GX2DepthBuffer *depthBuffer, s32 hiZ_enable);
|
||||
EXPORT_DECL(void, GX2SetupContextStateEx, GX2ContextState* state, s32 enable_profiling);
|
||||
EXPORT_DECL(void, GX2SetColorBuffer, const GX2ColorBuffer *colorBuffer, s32 target);
|
||||
EXPORT_DECL(void, GX2SetDepthBuffer, const GX2DepthBuffer *depthBuffer);
|
||||
EXPORT_DECL(void, GX2SetAttribBuffer, u32 attr_index, u32 attr_size, u32 stride, const void* attr);
|
||||
EXPORT_DECL(void, GX2InitTextureRegs, GX2Texture *texture);
|
||||
EXPORT_DECL(void, GX2InitSampler, GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter);
|
||||
EXPORT_DECL(u32, GX2CalcFetchShaderSizeEx, u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode);
|
||||
EXPORT_DECL(void, GX2InitFetchShaderEx, GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode);
|
||||
EXPORT_DECL(void, GX2SetFetchShader, const GX2FetchShader* fs);
|
||||
EXPORT_DECL(void, GX2SetVertexUniformReg, u32 offset, u32 count, const void *values);
|
||||
EXPORT_DECL(void, GX2SetPixelUniformReg, u32 offset, u32 count, const void *values);
|
||||
EXPORT_DECL(void, GX2SetPixelTexture, const GX2Texture *texture, u32 texture_hw_location);
|
||||
EXPORT_DECL(void, GX2SetVertexTexture, const GX2Texture *texture, u32 texture_hw_location);
|
||||
EXPORT_DECL(void, GX2SetPixelSampler, const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||
EXPORT_DECL(void, GX2SetVertexSampler, const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||
EXPORT_DECL(void, GX2SetPixelShader, const GX2PixelShader* pixelShader);
|
||||
EXPORT_DECL(void, GX2SetVertexShader, const GX2VertexShader* vertexShader);
|
||||
EXPORT_DECL(void, GX2InitSamplerZMFilter, GX2Sampler *sampler, s32 z_filter, s32 mip_filter);
|
||||
EXPORT_DECL(void, GX2SetColorControl, s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer);
|
||||
EXPORT_DECL(void, GX2SetDepthOnlyControl, s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function);
|
||||
EXPORT_DECL(void, GX2SetBlendControl, s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine);
|
||||
EXPORT_DECL(void, GX2CalcDRCSize, s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed);
|
||||
EXPORT_DECL(void, GX2SetDRCBuffer, void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode);
|
||||
EXPORT_DECL(void, GX2SetDRCScale, u32 width, u32 height);
|
||||
EXPORT_DECL(void, GX2SetDRCEnable, s32 enable);
|
||||
EXPORT_DECL(void, GX2SetPolygonControl, s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset);
|
||||
EXPORT_DECL(void, GX2SetCullOnlyControl, s32 front_face_mode, s32 cull_front, s32 cull_back);
|
||||
EXPORT_DECL(void, GX2SetDepthStencilControl, s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable,
|
||||
s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail,
|
||||
s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail);
|
||||
EXPORT_DECL(void, GX2SetStencilMask, u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back);
|
||||
EXPORT_DECL(void, GX2SetLineWidth, f32 width);
|
||||
EXPORT_DECL(void, GX2SetTVGamma, f32 val);
|
||||
EXPORT_DECL(void, GX2SetDRCGamma, f32 gam);
|
||||
EXPORT_DECL(s32, GX2GetSystemTVScanMode, void);
|
||||
EXPORT_DECL(s32, GX2GetSystemDRCScanMode, void);
|
||||
EXPORT_DECL(void, GX2RSetAllocator, void * (* allocFunc)(u32, u32, u32), void (* freeFunc)(u32, void*));
|
||||
|
||||
|
||||
void InitGX2FunctionPointers(void)
|
||||
{
|
||||
unsigned int *funcPointer = 0;
|
||||
unsigned int gx2_handle;
|
||||
OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
|
||||
|
||||
OS_FIND_EXPORT(gx2_handle, GX2Init);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2Shutdown);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2Flush);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2GetMainCoreId);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2DrawDone);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2ClearColor);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetViewport);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetScissor);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetContextState);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2DrawEx);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2DrawIndexedEx);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2ClearDepthStencilEx);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2CopyColorBufferToScanBuffer);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SwapScanBuffers);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetTVEnable);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetSwapInterval);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2GetSwapInterval);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2WaitForVsync);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2CalcTVSize);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2Invalidate);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetTVBuffer);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2CalcSurfaceSizeAndAlignment);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferRegs);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2InitColorBufferRegs);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2CalcColorBufferAuxInfo);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2CalcDepthBufferHiZInfo);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferHiZEnable);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetupContextStateEx);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetColorBuffer);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetDepthBuffer);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetAttribBuffer);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2InitTextureRegs);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2InitSampler);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2CalcFetchShaderSizeEx);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2InitFetchShaderEx);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetFetchShader);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetVertexUniformReg);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetPixelUniformReg);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetPixelTexture);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetVertexTexture);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetPixelSampler);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetVertexSampler);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetPixelShader);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetVertexShader);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2InitSamplerZMFilter);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetColorControl);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetDepthOnlyControl);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetBlendControl);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2CalcDRCSize);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetDRCBuffer);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetDRCScale);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetDRCEnable);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetPolygonControl);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetCullOnlyControl);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetDepthStencilControl);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetStencilMask);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetLineWidth);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetDRCGamma);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2SetTVGamma);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2GetSystemTVScanMode);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2GetSystemDRCScanMode);
|
||||
OS_FIND_EXPORT(gx2_handle, GX2RSetAllocator);
|
||||
}
|
205
src/dynamic_libs/gx2_functions.h
Normal file
205
src/dynamic_libs/gx2_functions.h
Normal file
@ -0,0 +1,205 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __GX2_FUNCTIONS_H_
|
||||
#define __GX2_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "gx2_types.h"
|
||||
|
||||
void InitGX2FunctionPointers(void);
|
||||
|
||||
extern void (* GX2Init)(u32 * init_attribs);
|
||||
extern void (* GX2Shutdown)(void);
|
||||
extern void (* GX2Flush)(void);
|
||||
extern s32 (* GX2GetMainCoreId)(void) ;
|
||||
extern s32 (* GX2DrawDone)(void);
|
||||
extern void (* GX2ClearColor)(GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a);
|
||||
extern void (* GX2SetViewport)(f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ);
|
||||
extern void (* GX2SetScissor)(u32 x_orig, u32 y_orig, u32 wd, u32 ht);
|
||||
extern void (* GX2SetContextState)(const GX2ContextState* state);
|
||||
extern void (* GX2DrawEx)(s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count);
|
||||
extern void (* GX2DrawIndexedEx)(s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count);
|
||||
extern void (* GX2ClearDepthStencilEx)(GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode);
|
||||
extern void (* GX2CopyColorBufferToScanBuffer)(const GX2ColorBuffer *colorBuffer, s32 scan_target);
|
||||
extern void (* GX2SwapScanBuffers)(void);
|
||||
extern void (* GX2SetTVEnable)(s32 enable);
|
||||
extern void (* GX2SetSwapInterval)(u32 swap_interval);
|
||||
extern u32 (* GX2GetSwapInterval)(void);
|
||||
extern void (* GX2WaitForVsync)(void);
|
||||
extern void (* GX2CalcTVSize)(s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed);
|
||||
extern void (* GX2Invalidate)(s32 invalidate_type, void * ptr, u32 buffer_size);
|
||||
extern void (* GX2SetTVBuffer)(void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode);
|
||||
extern void (* GX2CalcSurfaceSizeAndAlignment)(GX2Surface *surface);
|
||||
extern void (* GX2InitDepthBufferRegs)(GX2DepthBuffer *depthBuffer);
|
||||
extern void (* GX2InitColorBufferRegs)(GX2ColorBuffer *colorBuffer);
|
||||
extern void (* GX2CalcColorBufferAuxInfo)(GX2ColorBuffer *colorBuffer, u32 *size, u32 *align);
|
||||
extern void (* GX2CalcDepthBufferHiZInfo)(GX2DepthBuffer *depthBuffer, u32 *size, u32 *align);
|
||||
extern void (* GX2InitDepthBufferHiZEnable)(GX2DepthBuffer *depthBuffer, s32 hiZ_enable);
|
||||
extern void (* GX2SetupContextStateEx)(GX2ContextState* state, s32 enable_profiling);
|
||||
extern void (* GX2SetColorBuffer)(const GX2ColorBuffer *colorBuffer, s32 target);
|
||||
extern void (* GX2SetDepthBuffer)(const GX2DepthBuffer *depthBuffer);
|
||||
extern void (* GX2SetAttribBuffer)(u32 attr_index, u32 attr_size, u32 stride, const void* attr);
|
||||
extern void (* GX2InitTextureRegs)(GX2Texture *texture);
|
||||
extern void (* GX2InitSampler)(GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter);
|
||||
extern u32 (* GX2CalcFetchShaderSizeEx)(u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode);
|
||||
extern void (* GX2InitFetchShaderEx)(GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode);
|
||||
extern void (* GX2SetFetchShader)(const GX2FetchShader* fs);
|
||||
extern void (* GX2SetVertexUniformReg)(u32 offset, u32 count, const void *values);
|
||||
extern void (* GX2SetPixelUniformReg)(u32 offset, u32 count, const void *values);
|
||||
extern void (* GX2SetPixelTexture)(const GX2Texture *texture, u32 texture_hw_location);
|
||||
extern void (* GX2SetVertexTexture)(const GX2Texture *texture, u32 texture_hw_location);
|
||||
extern void (* GX2SetPixelSampler)(const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||
extern void (* GX2SetVertexSampler)(const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||
extern void (* GX2SetPixelShader)(const GX2PixelShader* pixelShader);
|
||||
extern void (* GX2SetVertexShader)(const GX2VertexShader* vertexShader);
|
||||
extern void (* GX2InitSamplerZMFilter)(GX2Sampler *sampler, s32 z_filter, s32 mip_filter);
|
||||
extern void (* GX2SetColorControl)(s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer);
|
||||
extern void (* GX2SetDepthOnlyControl)(s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function);
|
||||
extern void (* GX2SetBlendControl)(s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine);
|
||||
extern void (* GX2CalcDRCSize)(s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed);
|
||||
extern void (* GX2SetDRCBuffer)(void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode);
|
||||
extern void (* GX2SetDRCScale)(u32 width, u32 height);
|
||||
extern void (* GX2SetDRCEnable)(s32 enable);
|
||||
extern void (* GX2SetPolygonControl)(s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset);
|
||||
extern void (* GX2SetCullOnlyControl)(s32 front_face_mode, s32 cull_front, s32 cull_back);
|
||||
extern void (* GX2SetDepthStencilControl)(s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable,
|
||||
s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail,
|
||||
s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail);
|
||||
extern void (* GX2SetStencilMask)(u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back);
|
||||
extern void (* GX2SetLineWidth)(f32 width);
|
||||
extern void (* GX2SetTVGamma)(f32 val);
|
||||
extern void (* GX2SetDRCGamma)(f32 val);
|
||||
extern s32 (* GX2GetSystemTVScanMode)(void);
|
||||
extern s32 (* GX2GetSystemDRCScanMode)(void);
|
||||
extern void (* GX2RSetAllocator)(void * (*allocFunc)(u32, u32, u32), void (*freeFunc)(u32, void*));
|
||||
|
||||
static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa)
|
||||
{
|
||||
depthBuffer->surface.dimension = dimension;
|
||||
depthBuffer->surface.width = width;
|
||||
depthBuffer->surface.height = height;
|
||||
depthBuffer->surface.depth = depth;
|
||||
depthBuffer->surface.num_mips = 1;
|
||||
depthBuffer->surface.format = format;
|
||||
depthBuffer->surface.aa = aa;
|
||||
depthBuffer->surface.use = ((format==GX2_SURFACE_FORMAT_D_D24_S8_UNORM) || (format==GX2_SURFACE_FORMAT_D_D24_S8_FLOAT)) ? GX2_SURFACE_USE_DEPTH_BUFFER : GX2_SURFACE_USE_DEPTH_BUFFER_TEXTURE;
|
||||
depthBuffer->surface.tile = GX2_TILE_MODE_DEFAULT;
|
||||
depthBuffer->surface.swizzle = 0;
|
||||
depthBuffer->view_mip = 0;
|
||||
depthBuffer->view_first_slice = 0;
|
||||
depthBuffer->view_slices_count = depth;
|
||||
depthBuffer->clear_depth = 1.0f;
|
||||
depthBuffer->clear_stencil = 0;
|
||||
depthBuffer->hiZ_data = NULL;
|
||||
depthBuffer->hiZ_size = 0;
|
||||
GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface);
|
||||
GX2InitDepthBufferRegs(depthBuffer);
|
||||
}
|
||||
|
||||
static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa)
|
||||
{
|
||||
colorBuffer->surface.dimension = dimension;
|
||||
colorBuffer->surface.width = width;
|
||||
colorBuffer->surface.height = height;
|
||||
colorBuffer->surface.depth = depth;
|
||||
colorBuffer->surface.num_mips = 1;
|
||||
colorBuffer->surface.format = format;
|
||||
colorBuffer->surface.aa = aa;
|
||||
colorBuffer->surface.use = GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE_FTV;
|
||||
colorBuffer->surface.image_size = 0;
|
||||
colorBuffer->surface.image_data = NULL;
|
||||
colorBuffer->surface.mip_size = 0;
|
||||
colorBuffer->surface.mip_data = NULL;
|
||||
colorBuffer->surface.tile = GX2_TILE_MODE_DEFAULT;
|
||||
colorBuffer->surface.swizzle = 0;
|
||||
colorBuffer->surface.align = 0;
|
||||
colorBuffer->surface.pitch = 0;
|
||||
u32 i;
|
||||
for(i = 0; i < 13; i++)
|
||||
colorBuffer->surface.mip_offset[i] = 0;
|
||||
colorBuffer->view_mip = 0;
|
||||
colorBuffer->view_first_slice = 0;
|
||||
colorBuffer->view_slices_count = depth;
|
||||
colorBuffer->aux_data = NULL;
|
||||
colorBuffer->aux_size = 0;
|
||||
for(i = 0; i < 5; i++)
|
||||
colorBuffer->regs[i] = 0;
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface);
|
||||
GX2InitColorBufferRegs(colorBuffer);
|
||||
}
|
||||
|
||||
static inline void GX2InitAttribStream(GX2AttribStream* attr, u32 location, u32 buffer, u32 offset, s32 format)
|
||||
{
|
||||
attr->location = location;
|
||||
attr->buffer = buffer;
|
||||
attr->offset = offset;
|
||||
attr->format = format;
|
||||
attr->index_type = 0;
|
||||
attr->divisor = 0;
|
||||
attr->destination_selector = attribute_dest_comp_selector[format & 0xff];
|
||||
attr->endian_swap = GX2_ENDIANSWAP_DEFAULT;
|
||||
}
|
||||
|
||||
static inline void GX2InitTexture(GX2Texture *tex, u32 width, u32 height, u32 depth, u32 num_mips, s32 format, s32 dimension, s32 tile)
|
||||
{
|
||||
tex->surface.dimension = dimension;
|
||||
tex->surface.width = width;
|
||||
tex->surface.height = height;
|
||||
tex->surface.depth = depth;
|
||||
tex->surface.num_mips = num_mips;
|
||||
tex->surface.format = format;
|
||||
tex->surface.aa = GX2_AA_MODE_1X;
|
||||
tex->surface.use = GX2_SURFACE_USE_TEXTURE;
|
||||
tex->surface.image_size = 0;
|
||||
tex->surface.image_data = NULL;
|
||||
tex->surface.mip_size = 0;
|
||||
tex->surface.mip_data = NULL;
|
||||
tex->surface.tile = tile;
|
||||
tex->surface.swizzle = 0;
|
||||
tex->surface.align = 0;
|
||||
tex->surface.pitch = 0;
|
||||
u32 i;
|
||||
for(i = 0; i < 13; i++)
|
||||
tex->surface.mip_offset[i] = 0;
|
||||
tex->view_first_mip = 0;
|
||||
tex->view_mips_count = num_mips;
|
||||
tex->view_first_slice = 0;
|
||||
tex->view_slices_count = depth;
|
||||
tex->component_selector = texture_comp_selector[format & 0x3f];
|
||||
for(i = 0; i < 5; i++)
|
||||
tex->regs[i] = 0;
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&tex->surface);
|
||||
GX2InitTextureRegs(tex);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __GX2_FUNCTIONS_H_
|
699
src/dynamic_libs/gx2_types.h
Normal file
699
src/dynamic_libs/gx2_types.h
Normal file
@ -0,0 +1,699 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef _GX2_TYPES_H_
|
||||
#define _GX2_TYPES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! Constants
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_COMMAND_BUFFER_SIZE 0x400000
|
||||
#define GX2_SCAN_BUFFER_ALIGNMENT 0x1000
|
||||
#define GX2_SHADER_ALIGNMENT 0x100
|
||||
#define GX2_CONTEXT_STATE_ALIGNMENT 0x100
|
||||
#define GX2_DISPLAY_LIST_ALIGNMENT 0x20
|
||||
#define GX2_VERTEX_BUFFER_ALIGNMENT 0x40
|
||||
#define GX2_INDEX_BUFFER_ALIGNMENT 0x20
|
||||
|
||||
#define GX2_CONTEXT_STATE_SIZE 0xA100
|
||||
|
||||
#define GX2_AUX_BUFFER_CLEAR_VALUE 0xCC
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! Common
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_FALSE 0
|
||||
#define GX2_TRUE 1
|
||||
#define GX2_DISABLE 0
|
||||
#define GX2_ENABLE 1
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2InitAttrib
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_INIT_ATTRIB_NULL 0
|
||||
#define GX2_INIT_ATTRIB_CB_BASE 1
|
||||
#define GX2_INIT_ATTRIB_CB_SIZE 2
|
||||
#define GX2_INIT_ATTRIB_ARGC 7
|
||||
#define GX2_INIT_ATTRIB_ARGV 8
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 compare functions
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_COMPARE_NEVER 0
|
||||
#define GX2_COMPARE_LESS 1
|
||||
#define GX2_COMPARE_EQUAL 2
|
||||
#define GX2_COMPARE_LEQUAL 3
|
||||
#define GX2_COMPARE_GREATER 4
|
||||
#define GX2_COMPARE_NOTEQUAL 5
|
||||
#define GX2_COMPARE_GEQUAL 6
|
||||
#define GX2_COMPARE_ALWAYS 7
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 stencil functions
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_STENCIL_KEEP 0
|
||||
#define GX2_STENCIL_ZERO 1
|
||||
#define GX2_STENCIL_REPLACE 2
|
||||
#define GX2_STENCIL_INCR 3
|
||||
#define GX2_STENCIL_DECR 4
|
||||
#define GX2_STENCIL_INVERT 5
|
||||
#define GX2_STENCIL_INCR_WRAP 6
|
||||
#define GX2_STENCIL_DECR_WRAP 7
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 logic op functions
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_LOGIC_OP_CLEAR 0x00
|
||||
#define GX2_LOGIC_OP_NOR 0x11
|
||||
#define GX2_LOGIC_OP_INVAND 0x22
|
||||
#define GX2_LOGIC_OP_INVCOPY 0x33
|
||||
#define GX2_LOGIC_OP_REVAND 0x44
|
||||
#define GX2_LOGIC_OP_INV 0x55
|
||||
#define GX2_LOGIC_OP_XOR 0x66
|
||||
#define GX2_LOGIC_OP_NAND 0x77
|
||||
#define GX2_LOGIC_OP_AND 0x88
|
||||
#define GX2_LOGIC_OP_EQUIV 0x99
|
||||
#define GX2_LOGIC_OP_NOOP 0xAA
|
||||
#define GX2_LOGIC_OP_INVOR 0xBB
|
||||
#define GX2_LOGIC_OP_COPY 0xCC
|
||||
#define GX2_LOGIC_OP_REVOR 0xDD
|
||||
#define GX2_LOGIC_OP_OR 0xEE
|
||||
#define GX2_LOGIC_OP_SET 0xFF
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 blend combination functions
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_BLEND_COMBINE_ADD 0x00
|
||||
#define GX2_BLEND_COMBINE_SRC_MINUS_DST 0x01
|
||||
#define GX2_BLEND_COMBINE_MIN 0x02
|
||||
#define GX2_BLEND_COMBINE_MAX 0x03
|
||||
#define GX2_BLEND_COMBINE_DST_MINUS_SRC 0x04
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 blend functions
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_BLEND_ZERO 0x00
|
||||
#define GX2_BLEND_ONE 0x01
|
||||
#define GX2_BLEND_SRC_ALPHA 0x04
|
||||
#define GX2_BLEND_ONE_MINUS_SRC_ALPHA 0x05
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 render targets
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_RENDER_TARGET_0 0
|
||||
#define GX2_RENDER_TARGET_1 1
|
||||
#define GX2_RENDER_TARGET_2 2
|
||||
#define GX2_RENDER_TARGET_3 3
|
||||
#define GX2_RENDER_TARGET_4 4
|
||||
#define GX2_RENDER_TARGET_5 5
|
||||
#define GX2_RENDER_TARGET_6 6
|
||||
#define GX2_RENDER_TARGET_7 7
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 cull modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_FRONT_FACE_CCW 0
|
||||
#define GX2_FRONT_FACE_CW 1
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 polygon modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_POLYGON_MODE_POINT 0
|
||||
#define GX2_POLYGON_MODE_LINE 1
|
||||
#define GX2_POLYGON_MODE_TRIANGLE 2
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 special states
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_SPECIAL_STATE_CLEAR 0
|
||||
#define GX2_SPECIAL_STATE_CLEAR_HIZ 1
|
||||
#define GX2_SPECIAL_STATE_COPY 2
|
||||
#define GX2_SPECIAL_STATE_EXPAND_COLOR 3
|
||||
#define GX2_SPECIAL_STATE_EXPAND_DEPTH 4
|
||||
#define GX2_SPECIAL_STATE_CONVERT_DEPTH 5
|
||||
#define GX2_SPECIAL_STATE_CONVERT_AADEPTH 6
|
||||
#define GX2_SPECIAL_STATE_RESOLVE_COLOR 7
|
||||
#define GX2_SPECIAL_STATE_CLEAR_COLOR_AS_DEPTH 8
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 attribute formats
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_ATTRIB_FORMAT_8_UNORM 0x00000000
|
||||
#define GX2_ATTRIB_FORMAT_4_4_UNORM 0x00000001
|
||||
#define GX2_ATTRIB_FORMAT_16_UNORM 0x00000002
|
||||
#define GX2_ATTRIB_FORMAT_8_8_UNORM 0x00000004
|
||||
#define GX2_ATTRIB_FORMAT_16_16_UNORM 0x00000007
|
||||
#define GX2_ATTRIB_FORMAT_8_8_8_8_UNORM 0x0000000A
|
||||
#define GX2_ATTRIB_FORMAT_10_10_10_2_UNORM 0x0000000B
|
||||
#define GX2_ATTRIB_FORMAT_16_16_16_16_UNORM 0x0000000E
|
||||
|
||||
#define GX2_ATTRIB_FORMAT_8_UINT 0x00000100
|
||||
#define GX2_ATTRIB_FORMAT_16_UINT 0x00000102
|
||||
#define GX2_ATTRIB_FORMAT_8_8_UINT 0x00000104
|
||||
#define GX2_ATTRIB_FORMAT_32_UINT 0x00000105
|
||||
#define GX2_ATTRIB_FORMAT_16_16_UINT 0x00000107
|
||||
#define GX2_ATTRIB_FORMAT_8_8_8_8_UINT 0x0000010A
|
||||
#define GX2_ATTRIB_FORMAT_10_10_10_2_UINT 0x0000010B
|
||||
#define GX2_ATTRIB_FORMAT_32_32_UINT 0x0000010C
|
||||
#define GX2_ATTRIB_FORMAT_16_16_16_16_UINT 0x0000010E
|
||||
#define GX2_ATTRIB_FORMAT_32_32_32_UINT 0x00000110
|
||||
#define GX2_ATTRIB_FORMAT_32_32_32_32_UINT 0x00000112
|
||||
|
||||
#define GX2_ATTRIB_FORMAT_8_SNORM 0x00000200
|
||||
#define GX2_ATTRIB_FORMAT_16_SNORM 0x00000202
|
||||
#define GX2_ATTRIB_FORMAT_8_8_SNORM 0x00000204
|
||||
#define GX2_ATTRIB_FORMAT_16_16_SNORM 0x00000207
|
||||
#define GX2_ATTRIB_FORMAT_8_8_8_8_SNORM 0x0000020A
|
||||
#define GX2_ATTRIB_FORMAT_10_10_10_2_SNORM 0x0000020B
|
||||
#define GX2_ATTRIB_FORMAT_16_16_16_16_SNORM 0x0000020E
|
||||
|
||||
#define GX2_ATTRIB_FORMAT_8_SINT 0x00000300
|
||||
#define GX2_ATTRIB_FORMAT_16_SINT 0x00000303
|
||||
#define GX2_ATTRIB_FORMAT_8_8_SINT 0x00000304
|
||||
#define GX2_ATTRIB_FORMAT_32_SINT 0x00000305
|
||||
#define GX2_ATTRIB_FORMAT_16_16_SINT 0x00000307
|
||||
#define GX2_ATTRIB_FORMAT_8_8_8_8_SINT 0x0000030A
|
||||
#define GX2_ATTRIB_FORMAT_10_10_10_2_SINT 0x0000030B
|
||||
#define GX2_ATTRIB_FORMAT_32_32_SINT 0x0000030C
|
||||
#define GX2_ATTRIB_FORMAT_16_16_16_16_SINT 0x0000030E
|
||||
#define GX2_ATTRIB_FORMAT_32_32_32_SINT 0x00000310
|
||||
#define GX2_ATTRIB_FORMAT_32_32_32_32_SINT 0x00000312
|
||||
|
||||
#define GX2_ATTRIB_FORMAT_8_UINT_TO_FLOAT 0x00000800
|
||||
#define GX2_ATTRIB_FORMAT_16_UINT_TO_FLOAT 0x00000802
|
||||
#define GX2_ATTRIB_FORMAT_16_FLOAT 0x00000803
|
||||
#define GX2_ATTRIB_FORMAT_8_8_UINT_TO_FLOAT 0x00000804
|
||||
#define GX2_ATTRIB_FORMAT_32_FLOAT 0x00000806
|
||||
#define GX2_ATTRIB_FORMAT_16_16_UINT_TO_FLOAT 0x00000807
|
||||
#define GX2_ATTRIB_FORMAT_16_16_FLOAT 0x00000808
|
||||
#define GX2_ATTRIB_FORMAT_10_11_11_FLOAT 0x00000809
|
||||
#define GX2_ATTRIB_FORMAT_8_8_8_8_UINT_TO_FLOAT 0x0000080A
|
||||
#define GX2_ATTRIB_FORMAT_32_32_FLOAT 0x0000080D
|
||||
#define GX2_ATTRIB_FORMAT_16_16_16_16_UINT_TO_FLOAT 0x0000080E
|
||||
#define GX2_ATTRIB_FORMAT_16_16_16_16_FLOAT 0x0000080F
|
||||
#define GX2_ATTRIB_FORMAT_32_32_32_FLOAT 0x00000811
|
||||
#define GX2_ATTRIB_FORMAT_32_32_32_32_FLOAT 0x00000813
|
||||
|
||||
#define GX2_ATTRIB_FORMAT_8_SINT_TO_FLOAT 0x00000A00
|
||||
#define GX2_ATTRIB_FORMAT_16_SINT_TO_FLOAT 0x00000A02
|
||||
#define GX2_ATTRIB_FORMAT_8_8_SINT_TO_FLOAT 0x00000A04
|
||||
#define GX2_ATTRIB_FORMAT_16_16_SINT_TO_FLOAT 0x00000A07
|
||||
#define GX2_ATTRIB_FORMAT_8_8_8_8_SINT_TO_FLOAT 0x00000A0A
|
||||
#define GX2_ATTRIB_FORMAT_16_16_16_16_SINT_TO_FLOAT 0x00000A0E
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 shader modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_SHADER_MODE_UNIFORM_REGISTER 0
|
||||
#define GX2_SHADER_MODE_UNIFORM_BLOCK 1
|
||||
#define GX2_SHADER_MODE_GEOMETRY_SHADER 2
|
||||
#define GX2_SHADER_MODE_COMPUTE_SHADER 3
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 shader modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_COMP_SEL_NONE 0x04040405
|
||||
#define GX2_COMP_SEL_X001 0x00040405
|
||||
#define GX2_COMP_SEL_XY01 0x00010405
|
||||
#define GX2_COMP_SEL_XYZ1 0x00010205
|
||||
#define GX2_COMP_SEL_XYZW 0x00010203
|
||||
#define GX2_COMP_SEL_XXXX 0x00000000
|
||||
#define GX2_COMP_SEL_YYYY 0x01010101
|
||||
#define GX2_COMP_SEL_ZZZZ 0x02020202
|
||||
#define GX2_COMP_SEL_WWWW 0x03030303
|
||||
#define GX2_COMP_SEL_WZYX 0x03020100
|
||||
#define GX2_COMP_SEL_WXYZ 0x03000102
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 variable types
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_VAR_TYPE_VOID 0
|
||||
#define GX2_VAR_TYPE_BOOL 1
|
||||
#define GX2_VAR_TYPE_INT 2
|
||||
#define GX2_VAR_TYPE_UINT 3
|
||||
#define GX2_VAR_TYPE_FLOAT 4
|
||||
#define GX2_VAR_TYPE_DOUBLE 5
|
||||
#define GX2_VAR_TYPE_VEC2 9
|
||||
#define GX2_VAR_TYPE_VEC3 10
|
||||
#define GX2_VAR_TYPE_VEC4 11
|
||||
#define GX2_VAR_TYPE_MAT2 21
|
||||
#define GX2_VAR_TYPE_MAT3 25
|
||||
#define GX2_VAR_TYPE_MAT4 29
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 sample types
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_SAMPLER_TYPE_2D 1
|
||||
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 index formats
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_INDEX_FORMAT_U16 4
|
||||
#define GX2_INDEX_FORMAT_U32 9
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 primitive types
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_PRIMITIVE_POINTS 0x01
|
||||
#define GX2_PRIMITIVE_LINES 0x02
|
||||
#define GX2_PRIMITIVE_LINE_STRIP 0x03
|
||||
#define GX2_PRIMITIVE_TRIANGLES 0x04
|
||||
#define GX2_PRIMITIVE_TRIANGLE_FAN 0x05
|
||||
#define GX2_PRIMITIVE_TRIANGLE_STRIP 0x06
|
||||
#define GX2_PRIMITIVE_RECTS 0x11
|
||||
#define GX2_PRIMITIVE_QUADS 0x13
|
||||
#define GX2_PRIMITIVE_QUAD_STRIP 0x14
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 clear modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_CLEAR_DEPTH 0x01
|
||||
#define GX2_CLEAR_STENCIL 0x02
|
||||
#define GX2_CLEAR_BOTH (GX2_CLEAR_DEPTH | GX2_CLEAR_STENCIL)
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 surface formats
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_UNORM 0x00000001
|
||||
#define GX2_SURFACE_FORMAT_T_R4_G4_UNORM 0x00000002
|
||||
#define GX2_SURFACE_FORMAT_TCD_R16_UNORM 0x00000005
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_G8_UNORM 0x00000007
|
||||
#define GX2_SURFACE_FORMAT_TCS_R5_G6_B5_UNORM 0x00000008
|
||||
#define GX2_SURFACE_FORMAT_TC_R5_G5_B5_A1_UNORM 0x0000000a
|
||||
#define GX2_SURFACE_FORMAT_TC_R4_G4_B4_A4_UNORM 0x0000000b
|
||||
#define GX2_SURFACE_FORMAT_TC_A1_B5_G5_R5_UNORM 0x0000000c
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_UNORM 0x0000000f
|
||||
#define GX2_SURFACE_FORMAT_D_D24_S8_UNORM 0x00000011
|
||||
#define GX2_SURFACE_FORMAT_T_R24_UNORM_X8 0x00000011
|
||||
#define GX2_SURFACE_FORMAT_TCS_R10_G10_B10_A2_UNORM 0x00000019
|
||||
#define GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM 0x0000001a
|
||||
#define GX2_SURFACE_FORMAT_TCS_A2_B10_G10_R10_UNORM 0x0000001b
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_UNORM 0x0000001f
|
||||
#define GX2_SURFACE_FORMAT_T_BC1_UNORM 0x00000031
|
||||
#define GX2_SURFACE_FORMAT_T_BC2_UNORM 0x00000032
|
||||
#define GX2_SURFACE_FORMAT_T_BC3_UNORM 0x00000033
|
||||
#define GX2_SURFACE_FORMAT_T_BC4_UNORM 0x00000034
|
||||
#define GX2_SURFACE_FORMAT_T_BC5_UNORM 0x00000035
|
||||
#define GX2_SURFACE_FORMAT_T_NV12_UNORM 0x00000081
|
||||
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_UINT 0x00000101
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_UINT 0x00000105
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_G8_UINT 0x00000107
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_UINT 0x0000010d
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_UINT 0x0000010f
|
||||
#define GX2_SURFACE_FORMAT_T_X24_G8_UINT 0x00000111
|
||||
#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_UINT 0x00000119
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_UINT 0x0000011a
|
||||
#define GX2_SURFACE_FORMAT_TC_A2_B10_G10_R10_UINT 0x0000011b
|
||||
#define GX2_SURFACE_FORMAT_T_X32_G8_UINT_X24 0x0000011c
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_G32_UINT 0x0000011d
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_UINT 0x0000011f
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_UINT 0x00000122
|
||||
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_SNORM 0x00000201
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_SNORM 0x00000205
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_G8_SNORM 0x00000207
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_SNORM 0x0000020f
|
||||
#define GX2_SURFACE_FORMAT_T_R10_G10_B10_A2_SNORM 0x00000219
|
||||
#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_SNORM 0x00000219
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SNORM 0x0000021a
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_SNORM 0x0000021f
|
||||
#define GX2_SURFACE_FORMAT_T_BC4_SNORM 0x00000234
|
||||
#define GX2_SURFACE_FORMAT_T_BC5_SNORM 0x00000235
|
||||
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_SINT 0x00000301
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_SINT 0x00000305
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_G8_SINT 0x00000307
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_SINT 0x0000030d
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_SINT 0x0000030f
|
||||
#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_SINT 0x00000319
|
||||
#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SINT 0x0000031a
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_G32_SINT 0x0000031d
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_SINT 0x0000031f
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_SINT 0x00000322
|
||||
|
||||
#define GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_SRGB 0x0000041a
|
||||
#define GX2_SURFACE_FORMAT_T_BC1_SRGB 0x00000431
|
||||
#define GX2_SURFACE_FORMAT_T_BC2_SRGB 0x00000432
|
||||
#define GX2_SURFACE_FORMAT_T_BC3_SRGB 0x00000433
|
||||
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_FLOAT 0x00000806
|
||||
#define GX2_SURFACE_FORMAT_TCD_R32_FLOAT 0x0000080e
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_FLOAT 0x00000810
|
||||
#define GX2_SURFACE_FORMAT_D_D24_S8_FLOAT 0x00000811
|
||||
#define GX2_SURFACE_FORMAT_TC_R11_G11_B10_FLOAT 0x00000816
|
||||
#define GX2_SURFACE_FORMAT_D_D32_FLOAT_S8_UINT_X24 0x0000081c
|
||||
#define GX2_SURFACE_FORMAT_T_R32_FLOAT_X8_X24 0x0000081c
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_G32_FLOAT 0x0000081e
|
||||
#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_FLOAT 0x00000820
|
||||
#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_FLOAT 0x00000823
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 tile modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_TILE_MODE_DEFAULT 0x00000000
|
||||
#define GX2_TILE_MODE_LINEAR_ALIGNED 0x00000001
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 surface use
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_SURFACE_USE_TEXTURE 0x00000001
|
||||
#define GX2_SURFACE_USE_COLOR_BUFFER 0x00000002
|
||||
#define GX2_SURFACE_USE_DEPTH_BUFFER 0x00000004
|
||||
#define GX2_SURFACE_USE_SCAN_BUFFER 0x00000008
|
||||
#define GX2_SURFACE_USE_FTV 0x80000000
|
||||
#define GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE (GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_TEXTURE)
|
||||
#define GX2_SURFACE_USE_DEPTH_BUFFER_TEXTURE (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE)
|
||||
#define GX2_SURFACE_USE_COLOR_BUFFER_FTV (GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_FTV)
|
||||
#define GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE_FTV (GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE | GX2_SURFACE_USE_FTV)
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 surface dim
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_SURFACE_DIM_1D 0x00000000
|
||||
#define GX2_SURFACE_DIM_2D 0x00000001
|
||||
#define GX2_SURFACE_DIM_3D 0x00000002
|
||||
#define GX2_SURFACE_DIM_CUBE 0x00000003
|
||||
#define GX2_SURFACE_DIM_1D_ARRAY 0x00000004
|
||||
#define GX2_SURFACE_DIM_2D_ARRAY 0x00000005
|
||||
#define GX2_SURFACE_DIM_2D_MSAA 0x00000006
|
||||
#define GX2_SURFACE_DIM_2D_MSAA_ARRAY 0x00000007
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 AA modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_AA_MODE_1X 0x00000000
|
||||
#define GX2_AA_MODE_2X 0x00000001
|
||||
#define GX2_AA_MODE_4X 0x00000002
|
||||
#define GX2_AA_MODE_8X 0x00000003
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 texture clamp
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_TEX_CLAMP_WRAP 0x00000000
|
||||
#define GX2_TEX_CLAMP_MIRROR 0x00000001
|
||||
#define GX2_TEX_CLAMP_CLAMP 0x00000002
|
||||
#define GX2_TEX_CLAMP_MIRROR_ONCE 0x00000003
|
||||
#define GX2_TEX_CLAMP_CLAMP_HALF_BORDER 0x00000004
|
||||
#define GX2_TEX_CLAMP_MIRROR_ONCE_HALF_BORDER 0x00000005
|
||||
#define GX2_TEX_CLAMP_CLAMP_BORDER 0x00000006
|
||||
#define GX2_TEX_CLAMP_MIRROR_ONCE_BORDER 0x00000007
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 texture filter
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_TEX_XY_FILTER_POINT 0x00000000
|
||||
#define GX2_TEX_XY_FILTER_BILINEAR 0x00000001
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 TV scan modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_TV_SCAN_MODE_NONE 0x00000000
|
||||
#define GX2_TV_SCAN_MODE_576I 0x00000001
|
||||
#define GX2_TV_SCAN_MODE_480I 0x00000002
|
||||
#define GX2_TV_SCAN_MODE_480P 0x00000003
|
||||
#define GX2_TV_SCAN_MODE_720P 0x00000004
|
||||
#define GX2_TV_SCAN_MODE_1080I 0x00000006
|
||||
#define GX2_TV_SCAN_MODE_1080P 0x00000007
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 TV render modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_TV_RENDER_480_NARROW 0x00000001
|
||||
#define GX2_TV_RENDER_480_WIDE 0x00000002
|
||||
#define GX2_TV_RENDER_720 0x00000003
|
||||
#define GX2_TV_RENDER_1080 0x00000005
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 DRC render modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_DRC_NONE 0x00000000
|
||||
#define GX2_DRC_SINGLE 0x00000001
|
||||
#define GX2_DRC_DOUBLE 0x00000002
|
||||
#define GX2_DRC_SINGLE_30HZ 0x00000004
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 buffering mode
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_BUFFERING_SINGLE 0x00000001
|
||||
#define GX2_BUFFERING_DOUBLE 0x00000002
|
||||
#define GX2_BUFFERING_TRIPLE 0x00000003
|
||||
#define GX2_BUFFERING_QUAD
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 scan targets
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_SCAN_TARGET_TV 0x00000001
|
||||
#define GX2_SCAN_TARGET_DRC_FIRST 0x00000004
|
||||
#define GX2_SCAN_TARGET_DRC_SECOND 0x00000008
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 invalidate types
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_INVALIDATE_ATTRIB_BUFFER 0x00000001
|
||||
#define GX2_INVALIDATE_TEXTURE 0x00000002
|
||||
#define GX2_INVALIDATE_UNIFORM_BLOCK 0x00000004
|
||||
#define GX2_INVALIDATE_SHADER 0x00000008
|
||||
#define GX2_INVALIDATE_COLOR_BUFFER 0x00000010
|
||||
#define GX2_INVALIDATE_DEPTH_BUFFER 0x00000020
|
||||
#define GX2_INVALIDATE_CPU 0x00000040
|
||||
#define GX2_INVALIDATE_CPU_ATTRIB_BUFFER (GX2_INVALIDATE_CPU | GX2_INVALIDATE_ATTRIB_BUFFER)
|
||||
#define GX2_INVALIDATE_CPU_TEXTURE (GX2_INVALIDATE_CPU | GX2_INVALIDATE_TEXTURE)
|
||||
#define GX2_INVALIDATE_CPU_UNIFORM_BLOCK (GX2_INVALIDATE_CPU | GX2_INVALIDATE_UNIFORM_BLOCK)
|
||||
#define GX2_INVALIDATE_CPU_SHADER (GX2_INVALIDATE_CPU | GX2_INVALIDATE_SHADER)
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 swap modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_ENDIANSWAP_DEFAULT 0x00000003
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 tessellation modes
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_TESSELLATION_MODE_DISCRETE 0x00000000
|
||||
#define GX2_TESSELLATION_MODE_CONTINUOUS 0x00000001
|
||||
#define GX2_TESSELLATION_MODE_ADAPTIVE 0x00000002
|
||||
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
//! GX2 fetch shader types
|
||||
//!-----------------------------------------------------------------------------------------------------------------------
|
||||
#define GX2_FETCH_SHADER_TESSELATION_NONE 0x00000000
|
||||
#define GX2_FETCH_SHADER_TESSELATION_LINES 0x00000001
|
||||
#define GX2_FETCH_SHADER_TESSELATION_TRIANGLES 0x00000002
|
||||
#define GX2_FETCH_SHADER_TESSELATION_QUADS 0x00000003
|
||||
|
||||
|
||||
typedef struct _GX2ContextState {
|
||||
u8 data[GX2_CONTEXT_STATE_SIZE];
|
||||
} GX2ContextState;
|
||||
|
||||
typedef struct _GX2Surface {
|
||||
s32 dimension;
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 depth;
|
||||
u32 num_mips;
|
||||
s32 format;
|
||||
s32 aa;
|
||||
s32 use;
|
||||
u32 image_size;
|
||||
void *image_data;
|
||||
u32 mip_size;
|
||||
void *mip_data;
|
||||
s32 tile;
|
||||
u32 swizzle;
|
||||
u32 align;
|
||||
u32 pitch;
|
||||
u32 mip_offset[13];
|
||||
} GX2Surface;
|
||||
|
||||
typedef struct _GX2ColorBuffer {
|
||||
GX2Surface surface;
|
||||
u32 view_mip;
|
||||
u32 view_first_slice;
|
||||
u32 view_slices_count;
|
||||
void *aux_data;
|
||||
u32 aux_size;
|
||||
u32 regs[5];
|
||||
} GX2ColorBuffer;
|
||||
|
||||
typedef struct _GX2DepthBuffer {
|
||||
GX2Surface surface;
|
||||
u32 view_mip;
|
||||
u32 view_first_slice;
|
||||
u32 view_slices_count;
|
||||
void *hiZ_data;
|
||||
u32 hiZ_size;
|
||||
f32 clear_depth;
|
||||
u32 clear_stencil;
|
||||
u32 regs[7];
|
||||
} GX2DepthBuffer;
|
||||
|
||||
|
||||
typedef struct _GX2Texture {
|
||||
GX2Surface surface;
|
||||
u32 view_first_mip;
|
||||
u32 view_mips_count;
|
||||
u32 view_first_slice;
|
||||
u32 view_slices_count;
|
||||
u32 component_selector;
|
||||
u32 regs[5];
|
||||
} GX2Texture;
|
||||
|
||||
|
||||
typedef struct _GX2Sampler {
|
||||
u32 regs[3];
|
||||
} GX2Sampler;
|
||||
|
||||
typedef struct _GX2AttribStream {
|
||||
u32 location;
|
||||
u32 buffer;
|
||||
u32 offset;
|
||||
s32 format;
|
||||
s32 index_type;
|
||||
u32 divisor;
|
||||
u32 destination_selector;
|
||||
s32 endian_swap;
|
||||
} GX2AttribStream;
|
||||
|
||||
typedef struct _GX2FetchShader {
|
||||
s32 type;
|
||||
u32 reg;
|
||||
u32 shader_size;
|
||||
void *shader_program;
|
||||
u32 attributes_count;
|
||||
u32 divisor[3];
|
||||
} GX2FetchShader;
|
||||
|
||||
typedef struct _GX2AttribVar
|
||||
{
|
||||
const char *name;
|
||||
s32 var_type;
|
||||
u32 array_count;
|
||||
u32 location;
|
||||
} GX2AttribVar;
|
||||
|
||||
|
||||
typedef struct _GX2UniformBlock {
|
||||
const char *name;
|
||||
u32 location;
|
||||
u32 block_size;
|
||||
} GX2UniformBlock;
|
||||
|
||||
typedef struct _GX2UniformInitialValue {
|
||||
f32 value[4];
|
||||
u32 offset;
|
||||
} GX2UniformInitialValue;
|
||||
|
||||
typedef struct _GX2SamplerVar
|
||||
{
|
||||
const char *name;
|
||||
s32 sampler_type;
|
||||
u32 location;
|
||||
} GX2SamplerVar;
|
||||
|
||||
typedef struct _GX2UniformVar
|
||||
{
|
||||
const char *name;
|
||||
s32 var_type;
|
||||
u32 array_count;
|
||||
u32 offset;
|
||||
u32 block_index;
|
||||
} GX2UniformVar;
|
||||
|
||||
typedef struct _GX2VertexShader {
|
||||
u32 regs[52];
|
||||
u32 shader_size;
|
||||
void *shader_data;
|
||||
s32 shader_mode;
|
||||
u32 uniform_blocks_count;
|
||||
GX2UniformBlock *uniform_block;
|
||||
u32 uniform_vars_count;
|
||||
GX2UniformVar *uniform_var;
|
||||
u32 initial_values_count;
|
||||
GX2UniformInitialValue *initial_value;
|
||||
u32 loops_count;
|
||||
void *loops_data;
|
||||
u32 sampler_vars_count;
|
||||
GX2SamplerVar *sampler_var;
|
||||
u32 attribute_vars_count;
|
||||
GX2AttribVar *attribute_var;
|
||||
u32 data[6];
|
||||
u32 shader_program_buffer[16];
|
||||
} GX2VertexShader;
|
||||
|
||||
typedef struct _GX2PixelShader {
|
||||
u32 regs[41];
|
||||
u32 shader_size;
|
||||
void *shader_data;
|
||||
s32 shader_mode;
|
||||
u32 uniform_blocks_count;
|
||||
GX2UniformBlock *uniform_block;
|
||||
u32 uniform_vars_count;
|
||||
GX2UniformVar *uniform_var;
|
||||
u32 initial_values_count;
|
||||
GX2UniformInitialValue *initial_value;
|
||||
u32 loops_count;
|
||||
void *loops_data;
|
||||
u32 sampler_vars_count;
|
||||
GX2SamplerVar *sampler_var;
|
||||
u32 shader_program_buffer[16];
|
||||
} GX2PixelShader;
|
||||
|
||||
static const u32 attribute_dest_comp_selector[20] = {
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1,
|
||||
GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW
|
||||
};
|
||||
|
||||
static const u32 texture_comp_selector[54] = {
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1,
|
||||
GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01
|
||||
};
|
||||
|
||||
typedef struct _GX2Color {
|
||||
u8 r, g, b, a;
|
||||
} GX2Color;
|
||||
|
||||
typedef struct _GX2ColorF32 {
|
||||
f32 r, g, b, a;
|
||||
} GX2ColorF32;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
383
src/dynamic_libs/os_functions.c
Normal file
383
src/dynamic_libs/os_functions.c
Normal file
@ -0,0 +1,383 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "common/common.h"
|
||||
#include "os_functions.h"
|
||||
|
||||
unsigned int coreinit_handle = 0;
|
||||
// unsigned int zlib_handle = 0;
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Lib handle functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(int, OSDynLoad_Acquire, const char *rpl, u32 * handle);
|
||||
|
||||
EXPORT_DECL(int, OSDynLoad_FindExport, u32
|
||||
handle, int isdata, const char *symbol, void *address);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Security functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(int, OSGetSecurityLevel, void);
|
||||
|
||||
EXPORT_DECL(void, __OSSetCoreTrace, int core);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Thread functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(int, OSCreateThread, void *thread, s32(*callback)(s32, void * ), s32
|
||||
argc, void *args, u32
|
||||
stack, u32
|
||||
stack_size, s32
|
||||
priority, u32
|
||||
attr);
|
||||
|
||||
EXPORT_DECL(int, OSGetCurrentThread, void);
|
||||
|
||||
EXPORT_DECL(int, OSResumeThread, void *thread);
|
||||
|
||||
EXPORT_DECL(int, OSSleepThread, void *thread);
|
||||
|
||||
EXPORT_DECL(int, OSGetDefaultThread, int core);
|
||||
|
||||
EXPORT_DECL(int, OSWakeupThread, void *thread);
|
||||
|
||||
EXPORT_DECL(int, OSYieldThread, void);
|
||||
|
||||
EXPORT_DECL(void, OSSetThreadName, void *thread, const char *name);
|
||||
|
||||
EXPORT_DECL(int, OSSuspendThread, void *thread);
|
||||
|
||||
EXPORT_DECL(int, OSIsThreadTerminated, void *thread);
|
||||
|
||||
EXPORT_DECL(int, OSIsThreadSuspended, void *thread);
|
||||
|
||||
EXPORT_DECL(int, OSSetThreadPriority, void *thread, int priority);
|
||||
|
||||
EXPORT_DECL(int, OSJoinThread, void *thread, int *ret_val);
|
||||
|
||||
EXPORT_DECL(void, OSDetachThread, void *thread);
|
||||
|
||||
EXPORT_DECL(void, OSSleepTicks, u64
|
||||
ticks);
|
||||
|
||||
EXPORT_DECL(u64, OSGetTick, void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Mutex functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(void, OSInitMutex, void *mutex);
|
||||
|
||||
EXPORT_DECL(void, OSLockMutex, void *mutex);
|
||||
|
||||
EXPORT_DECL(void, OSUnlockMutex, void *mutex);
|
||||
|
||||
EXPORT_DECL(int, OSTryLockMutex, void *mutex);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! System functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(u64, OSGetTitleID, void);
|
||||
|
||||
EXPORT_DECL(void, __Exit, void);
|
||||
|
||||
EXPORT_DECL(void, OSFatal, const char *msg);
|
||||
|
||||
EXPORT_DECL(void, OSSetExceptionCallback, u8
|
||||
exceptionType, exception_callback newCallback);
|
||||
|
||||
EXPORT_DECL(void, DCFlushRange, const void *addr, u32
|
||||
length);
|
||||
|
||||
EXPORT_DECL(void, ICInvalidateRange, const void *addr, u32
|
||||
length);
|
||||
|
||||
EXPORT_DECL(void*, OSEffectiveToPhysical, const void*);
|
||||
|
||||
EXPORT_DECL(int, OSIsAddressValid, const void*);
|
||||
|
||||
EXPORT_DECL(int, __OSValidateAddressSpaceRange, int, void*, int);
|
||||
|
||||
EXPORT_DECL(int, __os_snprintf, char *s, int n, const char *format, ...);
|
||||
|
||||
EXPORT_DECL(int *, __gh_errno_ptr, void);
|
||||
|
||||
EXPORT_DECL(void, OSScreenInit, void);
|
||||
|
||||
EXPORT_DECL(void, OSScreenShutdown, void);
|
||||
|
||||
EXPORT_DECL(unsigned
|
||||
int, OSScreenGetBufferSizeEx, unsigned int bufferNum);
|
||||
|
||||
EXPORT_DECL(int, OSScreenSetBufferEx, unsigned int bufferNum, void *addr);
|
||||
|
||||
EXPORT_DECL(int, OSScreenClearBufferEx, unsigned int bufferNum, unsigned int temp);
|
||||
|
||||
EXPORT_DECL(int, OSScreenFlipBuffersEx, unsigned int bufferNum);
|
||||
|
||||
EXPORT_DECL(int, OSScreenPutFontEx, unsigned int bufferNum, unsigned int posX, unsigned int posY, const char *buffer);
|
||||
|
||||
EXPORT_DECL(int, OSScreenEnableEx, unsigned int bufferNum, int enable);
|
||||
|
||||
EXPORT_DECL(int, OSAllocFromSystem, unsigned int size, unsigned int align);
|
||||
|
||||
EXPORT_DECL(int, OSFreeToSystem, void* ptr);
|
||||
|
||||
EXPORT_DECL(void, DisassemblePPCRange, void *, void *, DisasmReport, DisasmGetSym, u32);
|
||||
|
||||
EXPORT_DECL(bool, DisassemblePPCOpcode, u32 *, char *, u32, DisasmGetSym, u32);
|
||||
|
||||
EXPORT_DECL(void*, OSGetSymbolName, u32, u8*, u32);
|
||||
|
||||
EXPORT_DECL(int, OSIsDebuggerInitialized, void);
|
||||
|
||||
// EXPORT_DECL(int, compress2, char *, int*, const char *, int, int);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Memory functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeapEx);
|
||||
EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeap);
|
||||
EXPORT_VAR(unsigned int *, pMEMFreeToDefaultHeap);
|
||||
|
||||
EXPORT_DECL(int, MEMGetBaseHeapHandle, int mem_arena);
|
||||
|
||||
EXPORT_DECL(unsigned int, MEMGetAllocatableSizeForFrmHeapEx, int heap, int align);
|
||||
|
||||
EXPORT_DECL(void *, MEMAllocFromFrmHeapEx, int heap, unsigned int size, int align);
|
||||
|
||||
EXPORT_DECL(void, MEMFreeToFrmHeap, int heap, int mode);
|
||||
|
||||
EXPORT_DECL(void *, MEMAllocFromExpHeapEx, int heap, unsigned int size, int align);
|
||||
|
||||
EXPORT_DECL(int, MEMCreateExpHeapEx, void *address, unsigned int size, unsigned short flags);
|
||||
|
||||
EXPORT_DECL(void *, MEMDestroyExpHeap, int heap);
|
||||
|
||||
EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void *ptr);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! MCP functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(int, MCP_Open, void);
|
||||
|
||||
EXPORT_DECL(int, MCP_Close, int handle);
|
||||
|
||||
EXPORT_DECL(int, MCP_GetOwnTitleInfo, int handle, void *data);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Loader functions (not real rpl)
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(int, LiWaitIopComplete, int unknown_syscall_arg_r3, int *remaining_bytes);
|
||||
|
||||
EXPORT_DECL(int, LiWaitIopCompleteWithInterrupts, int unknown_syscall_arg_r3, int *remaining_bytes);
|
||||
|
||||
EXPORT_DECL(void, addr_LiWaitOneChunk, void);
|
||||
|
||||
EXPORT_DECL(void, addr_sgIsLoadingBuffer, void);
|
||||
|
||||
EXPORT_DECL(void, addr_gDynloadInitialized, void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Kernel function addresses
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(void, addr_PrepareTitle_hook, void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Other function addresses
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_DECL(void, DCInvalidateRange, void *buffer, uint32_t
|
||||
length);
|
||||
|
||||
void InitAcquireOS(void) {
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Lib handle functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (int (*)(const char *, unsigned *)) OS_SPECIFICS->addr_OSDynLoad_Acquire);
|
||||
EXPORT_FUNC_WRITE(OSDynLoad_FindExport,
|
||||
(int (*)(u32, int, const char *, void *)) OS_SPECIFICS->addr_OSDynLoad_FindExport);
|
||||
|
||||
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
|
||||
// OSDynLoad_Acquire("zlib125.rpl", &zlib_handle);
|
||||
}
|
||||
|
||||
void InitOSFunctionPointers(void) {
|
||||
unsigned int *funcPointer = 0;
|
||||
|
||||
InitAcquireOS();
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Security functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
OS_FIND_EXPORT(coreinit_handle, OSGetSecurityLevel);
|
||||
OS_FIND_EXPORT(coreinit_handle, __OSSetCoreTrace);
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! System functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
OS_FIND_EXPORT(coreinit_handle, OSFatal);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSGetTitleID);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSSetExceptionCallback);
|
||||
OS_FIND_EXPORT(coreinit_handle, DCFlushRange);
|
||||
OS_FIND_EXPORT(coreinit_handle, ICInvalidateRange);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSEffectiveToPhysical);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSIsAddressValid);
|
||||
OS_FIND_EXPORT(coreinit_handle, __OSValidateAddressSpaceRange);
|
||||
// OS_FIND_EXPORT(coreinit_handle, );
|
||||
OS_FIND_EXPORT(coreinit_handle, __os_snprintf);
|
||||
OS_FIND_EXPORT(coreinit_handle, __gh_errno_ptr);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSAllocFromSystem);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSFreeToSystem);
|
||||
OS_FIND_EXPORT(coreinit_handle, DisassemblePPCRange);
|
||||
OS_FIND_EXPORT(coreinit_handle, DisassemblePPCOpcode);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSGetSymbolName);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSIsDebuggerInitialized);
|
||||
// OS_FIND_EXPORT(zlib_handle, compress2);
|
||||
|
||||
OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &__Exit);
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenInit);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenShutdown);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenGetBufferSizeEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenSetBufferEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenClearBufferEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenFlipBuffersEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenPutFontEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSScreenEnableEx);
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Thread functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
OS_FIND_EXPORT(coreinit_handle, OSGetCurrentThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSCreateThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSResumeThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSSleepThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSGetDefaultThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSWakeupThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSSetThreadName);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSYieldThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSSuspendThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSIsThreadTerminated);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSIsThreadSuspended);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSJoinThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSSetThreadPriority);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSDetachThread);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSSleepTicks);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSGetTick);
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Mutex functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
OS_FIND_EXPORT(coreinit_handle, OSInitMutex);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSLockMutex);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex);
|
||||
OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex);
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! MCP functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
OS_FIND_EXPORT(coreinit_handle, MCP_Open);
|
||||
OS_FIND_EXPORT(coreinit_handle, MCP_Close);
|
||||
OS_FIND_EXPORT(coreinit_handle, MCP_GetOwnTitleInfo);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Memory functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx);
|
||||
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
|
||||
OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
|
||||
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMGetBaseHeapHandle);
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMGetAllocatableSizeForFrmHeapEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMAllocFromFrmHeapEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMFreeToFrmHeap);
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMAllocFromExpHeapEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx);
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap);
|
||||
OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Other function addresses
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
OS_FIND_EXPORT(coreinit_handle, DCInvalidateRange);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Special non library functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
if (OS_FIRMWARE == 532 || OS_FIRMWARE == 540) {
|
||||
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *)) 0x0100FFA4); // loader.elf
|
||||
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *)) 0x0100FE90); // loader.elf
|
||||
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *)) 0x010007EC); // loader.elf
|
||||
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *)) 0xFFF18558); // kernel.elf
|
||||
|
||||
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *)) 0xEFE19D00); // loader.elf
|
||||
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *)) 0xEFE13C3C); // loader.elf
|
||||
} else if (OS_FIRMWARE == 500 || OS_FIRMWARE == 510) {
|
||||
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *)) 0x0100FBC4);
|
||||
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *)) 0x0100FAB0);
|
||||
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *)) 0x010007EC);
|
||||
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *)) 0xFFF18534);
|
||||
|
||||
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *)) 0xEFE19D00);
|
||||
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *)) 0xEFE13C3C);
|
||||
} else if (OS_FIRMWARE == 410) {
|
||||
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *)) 0x0100F78C);
|
||||
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *)) 0x0100F678);
|
||||
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *)) 0x010007F8);
|
||||
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *)) 0xFFF166DC);
|
||||
|
||||
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *)) 0xEFE19CC0);
|
||||
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *)) 0xEFE13BFC);
|
||||
} else if (OS_FIRMWARE == 400) //same for 402 and 403
|
||||
{
|
||||
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *)) 0x0100F78C);
|
||||
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *)) 0x0100F678);
|
||||
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *)) 0x010007F8);
|
||||
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *)) 0xFFF15E70);
|
||||
|
||||
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *)) 0xEFE19CC0);
|
||||
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *)) 0xEFE13BFC);
|
||||
} else if (OS_FIRMWARE == 550) {
|
||||
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *)) 0x01010180);
|
||||
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *)) 0x0101006C);
|
||||
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *)) 0x0100080C);
|
||||
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *)) 0xFFF184E4);
|
||||
|
||||
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *)) 0xEFE19E80);
|
||||
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *)) 0xEFE13DBC);
|
||||
} else if (OS_FIRMWARE == 310) {
|
||||
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *)) 0x0100C4E4);
|
||||
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *)) 0x0100C3D4);
|
||||
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *)) 0x010004D8);
|
||||
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *)) 0xFFF15A0C);
|
||||
|
||||
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *)) 0xEFE19340);
|
||||
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *)) 0xEFE1329C);
|
||||
} else if (OS_FIRMWARE == 300) {
|
||||
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *)) 0x0100C4E4);
|
||||
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *)) 0x0100C3D4);
|
||||
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *)) 0x010004D8);
|
||||
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *)) 0xFFF15974);
|
||||
|
||||
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *)) 0xEFE19340);
|
||||
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *)) 0xEFE1329C);
|
||||
} else {
|
||||
OSFatal("Missing all OS specific addresses.");
|
||||
}
|
||||
}
|
275
src/dynamic_libs/os_functions.h
Normal file
275
src/dynamic_libs/os_functions.h
Normal file
@ -0,0 +1,275 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __OS_FUNCTIONS_H_
|
||||
#define __OS_FUNCTIONS_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
#include "common/os_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Disassembler */
|
||||
typedef void (*DisasmReport)(char *outputBuffer, ...);
|
||||
|
||||
typedef void *(*DisasmGetSym)(u32 addr, u8 *symbolName, u32 nameBufSize);
|
||||
|
||||
#define PPC_DISASM_MAX_BUFFER 64
|
||||
|
||||
#define PPC_DISASM_DEFAULT 0x00000000 // use defaults
|
||||
#define PPC_DISASM_SIMPLIFY 0x00000001 // use simplified mnemonics
|
||||
#define PPC_DISASM_REG_SPACES 0x00000020 // emit spaces between registers
|
||||
#define PPC_DISASM_EMIT_DISASM 0x00000040 // emit only disassembly
|
||||
#define PPC_DISASM_EMIT_ADDR 0x00000080 // emit only addresses + disassembly
|
||||
#define PPC_DISASM_EMIT_FUNCS 0x00000100 // emit function names before and during disassembly
|
||||
|
||||
/* zlib */
|
||||
|
||||
/*#define Z_NO_COMPRESSION 0
|
||||
#define Z_BEST_SPEED 1
|
||||
#define Z_BEST_COMPRESSION 9
|
||||
#define Z_DEFAULT_COMPRESSION (-1)
|
||||
|
||||
#define Z_OK 0
|
||||
#define Z_STREAM_END 1
|
||||
#define Z_NEED_DICT 2
|
||||
#define Z_ERRNO (-1)
|
||||
#define Z_STREAM_ERROR (-2)
|
||||
#define Z_DATA_ERROR (-3)
|
||||
#define Z_MEM_ERROR (-4)
|
||||
#define Z_BUF_ERROR (-5)
|
||||
#define Z_VERSION_ERROR (-6)*/
|
||||
|
||||
#define BUS_SPEED 248625000
|
||||
#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4))
|
||||
#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000)
|
||||
#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000)
|
||||
|
||||
#define usleep(usecs) OSSleepTicks(MICROSECS_TO_TICKS(usecs))
|
||||
#define sleep(secs) OSSleepTicks(SECS_TO_TICKS(secs))
|
||||
|
||||
#define FLUSH_DATA_BLOCK(addr) asm volatile("dcbf 0, %0; sync" : : "r"(((addr) & ~31)))
|
||||
#define INVAL_DATA_BLOCK(addr) asm volatile("dcbi 0, %0; sync" : : "r"(((addr) & ~31)))
|
||||
|
||||
#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__) __attribute__((section(".data"))) = 0;
|
||||
#define EXPORT_VAR(type, var) type var __attribute__((section(".data")));
|
||||
|
||||
|
||||
#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val
|
||||
|
||||
#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \
|
||||
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
|
||||
if(!funcPointer) \
|
||||
OSFatal("Function " # func " is NULL"); \
|
||||
EXPORT_FUNC_WRITE(func, funcPointer);
|
||||
|
||||
#define OS_FIND_EXPORT_EX(handle, func, func_p) \
|
||||
funcPointer = 0; \
|
||||
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
|
||||
if(!funcPointer) \
|
||||
OSFatal("Function " # func " is NULL"); \
|
||||
EXPORT_FUNC_WRITE(func_p, funcPointer);
|
||||
|
||||
#define OS_MUTEX_SIZE 44
|
||||
|
||||
/* Handle for coreinit */
|
||||
extern unsigned int coreinit_handle;
|
||||
|
||||
void InitOSFunctionPointers(void);
|
||||
|
||||
void InitAcquireOS(void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Lib handle functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern int (*OSDynLoad_Acquire)(const char *rpl, u32 *handle);
|
||||
|
||||
extern int (*OSDynLoad_FindExport)(u32 handle, int isdata, const char *symbol, void *address);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Security functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern int (*OSGetSecurityLevel)(void);
|
||||
|
||||
extern void (*__OSSetCoreTrace)(int core);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Thread functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// Thread attributes
|
||||
//
|
||||
// Threads lacking an affinity bit are affinitized to the
|
||||
// core on which they are created
|
||||
//
|
||||
|
||||
#define OS_THREAD_ATTR_AFFINITY_NONE 0x0007u // affinity to run on every core
|
||||
#define OS_THREAD_ATTR_AFFINITY_CORE0 0x0001u // run only on core0
|
||||
#define OS_THREAD_ATTR_AFFINITY_CORE1 0x0002u // run only on core1
|
||||
#define OS_THREAD_ATTR_AFFINITY_CORE2 0x0004u // run only on core2
|
||||
#define OS_THREAD_ATTR_DETACH 0x0008u // detached
|
||||
#define OS_THREAD_ATTR_PINNED_AFFINITY 0x0010u // pinned (affinitized) to a single core
|
||||
#define OS_THREAD_ATTR_CHECK_STACK_USE 0x0040u // check for stack usage
|
||||
#define OS_THREAD_ATTR_NAME_SENT 0x0080u // debugger has seen the name
|
||||
#define OS_THREAD_ATTR_LAST (OS_THREAD_ATTR_DETACH | OS_THREAD_ATTR_PINNED_AFFINITY | OS_THREAD_ATTR_AFFINITY_NONE)
|
||||
|
||||
extern int
|
||||
(*OSCreateThread)(void *thread, s32 (*callback)(s32, void *), s32 argc, void *args, u32 stack, u32 stack_size,
|
||||
s32 priority, u32 attr);
|
||||
|
||||
extern int (*OSGetCurrentThread)(void);
|
||||
|
||||
extern int (*OSResumeThread)(void *thread);
|
||||
|
||||
extern int (*OSSleepThread)(void *thread);
|
||||
|
||||
extern int (*OSWakeupThread)(void *thread);
|
||||
|
||||
extern void (*OSSetThreadName)(void *thread, const char *name);
|
||||
|
||||
extern int (*OSSuspendThread)(void *thread);
|
||||
|
||||
extern int (*OSIsThreadTerminated)(void *thread);
|
||||
|
||||
extern int (*OSIsThreadSuspended)(void *thread);
|
||||
|
||||
extern int (*OSJoinThread)(void *thread, int *ret_val);
|
||||
|
||||
extern int (*OSSetThreadPriority)(void *thread, int priority);
|
||||
|
||||
extern void (*OSDetachThread)(void *thread);
|
||||
|
||||
extern void (*OSSleepTicks)(u64 ticks);
|
||||
|
||||
extern u64 (*OSGetTick)(void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Mutex functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern void (*OSInitMutex)(void *mutex);
|
||||
|
||||
extern void (*OSLockMutex)(void *mutex);
|
||||
|
||||
extern void (*OSUnlockMutex)(void *mutex);
|
||||
|
||||
extern int (*OSTryLockMutex)(void *mutex);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! System functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern u64 (*OSGetTitleID)(void);
|
||||
|
||||
extern void (*__Exit)(void);
|
||||
|
||||
extern void (*OSFatal)(const char *msg);
|
||||
|
||||
extern void (*DCFlushRange)(const void *addr, u32 length);
|
||||
|
||||
extern void (*ICInvalidateRange)(const void *addr, u32 length);
|
||||
|
||||
extern void *(*OSEffectiveToPhysical)(const void *);
|
||||
|
||||
extern int (*OSIsAddressValid)(const void *);
|
||||
|
||||
extern int (*__OSValidateAddressSpaceRange)(int dummyTrue, void *address, int size);
|
||||
|
||||
extern int (*__os_snprintf)(char *buffer, int length, const char *format, ...);
|
||||
|
||||
extern int *(*__gh_errno_ptr)(void);
|
||||
|
||||
extern void (*OSScreenInit)(void);
|
||||
|
||||
extern unsigned int (*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
|
||||
|
||||
extern int (*OSScreenSetBufferEx)(unsigned int bufferNum, void *addr);
|
||||
|
||||
extern int (*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp);
|
||||
|
||||
extern int (*OSScreenFlipBuffersEx)(unsigned int bufferNum);
|
||||
|
||||
extern int (*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int posY, const char *buffer);
|
||||
|
||||
extern int (*OSScreenEnableEx)(unsigned int bufferNum, int enable);
|
||||
|
||||
typedef unsigned char (*exception_callback)(void *interruptedContext);
|
||||
|
||||
extern void (*OSSetExceptionCallback)(u8 exceptionType, exception_callback newCallback);
|
||||
|
||||
extern int (*OSAllocFromSystem)(unsigned int size, unsigned int align);
|
||||
|
||||
extern int (*OSFreeToSystem)(void *aPtr);
|
||||
|
||||
extern void
|
||||
(*DisassemblePPCRange)(void *rangeStart, void *rangeEnd, DisasmReport disasmReport, DisasmGetSym disasmGetSym,
|
||||
u32 disasmOptions);
|
||||
|
||||
extern bool
|
||||
(*DisassemblePPCOpcode)(u32 *opcode, char *outputBuffer, u32 bufferSize, DisasmGetSym disasmGetSym, u32 disasmOptions);
|
||||
|
||||
extern void *(*OSGetSymbolName)(u32 addr, u8 *symbolName, u32 nameBufSize);
|
||||
|
||||
extern int (*OSIsDebuggerInitialized)(void);
|
||||
|
||||
// extern int (*compress2)(char *dest, int *destLen, const char *source, int sourceLen, int level);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! MCP functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern int (*MCP_Open)(void);
|
||||
|
||||
extern int (*MCP_Close)(int handle);
|
||||
|
||||
extern int (*MCP_GetOwnTitleInfo)(int handle, void *data);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! LOADER functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern int (*LiWaitIopComplete)(int unknown_syscall_arg_r3, int *remaining_bytes);
|
||||
|
||||
extern int (*LiWaitIopCompleteWithInterrupts)(int unknown_syscall_arg_r3, int *remaining_bytes);
|
||||
|
||||
extern void (*addr_LiWaitOneChunk)(void);
|
||||
|
||||
extern void (*addr_sgIsLoadingBuffer)(void);
|
||||
|
||||
extern void (*addr_gDynloadInitialized)(void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Kernel function addresses
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern void (*addr_PrepareTitle_hook)(void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Other function addresses
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern void (*DCInvalidateRange)(void *buffer, uint32_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __OS_FUNCTIONS_H_
|
||||
|
50
src/dynamic_libs/padscore_functions.c
Normal file
50
src/dynamic_libs/padscore_functions.c
Normal file
@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "os_functions.h"
|
||||
#include "padscore_functions.h"
|
||||
|
||||
EXPORT_DECL(void, KPADInit, void);
|
||||
EXPORT_DECL(s32, WPADProbe, s32 chan, u32 * pad_type);
|
||||
EXPORT_DECL(s32, WPADSetDataFormat, s32 chan, s32 format);
|
||||
EXPORT_DECL(void, WPADEnableURCC, s32 enable);
|
||||
EXPORT_DECL(void, WPADRead, s32 chan, void * data);
|
||||
EXPORT_DECL(s32, KPADRead, s32 chan, void * data, u32 size);
|
||||
|
||||
void InitPadScoreFunctionPointers(void)
|
||||
{
|
||||
unsigned int *funcPointer = 0;
|
||||
unsigned int padscore_handle;
|
||||
OSDynLoad_Acquire("padscore.rpl", &padscore_handle);
|
||||
|
||||
OS_FIND_EXPORT(padscore_handle, KPADInit);
|
||||
OS_FIND_EXPORT(padscore_handle, WPADProbe);
|
||||
OS_FIND_EXPORT(padscore_handle, WPADSetDataFormat);
|
||||
OS_FIND_EXPORT(padscore_handle, WPADEnableURCC);
|
||||
OS_FIND_EXPORT(padscore_handle, WPADRead);
|
||||
OS_FIND_EXPORT(padscore_handle, KPADRead);
|
||||
|
||||
KPADInit();
|
||||
WPADEnableURCC(1);
|
||||
}
|
||||
|
122
src/dynamic_libs/padscore_functions.h
Normal file
122
src/dynamic_libs/padscore_functions.h
Normal file
@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __PAD_SCORE_FUNCTIONS_H_
|
||||
#define __PAD_SCORE_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
#define WPAD_BUTTON_LEFT 0x0001
|
||||
#define WPAD_BUTTON_RIGHT 0x0002
|
||||
#define WPAD_BUTTON_DOWN 0x0004
|
||||
#define WPAD_BUTTON_UP 0x0008
|
||||
#define WPAD_BUTTON_PLUS 0x0010
|
||||
#define WPAD_BUTTON_2 0x0100
|
||||
#define WPAD_BUTTON_1 0x0200
|
||||
#define WPAD_BUTTON_B 0x0400
|
||||
#define WPAD_BUTTON_A 0x0800
|
||||
#define WPAD_BUTTON_MINUS 0x1000
|
||||
#define WPAD_BUTTON_Z 0x2000
|
||||
#define WPAD_BUTTON_C 0x4000
|
||||
#define WPAD_BUTTON_HOME 0x8000
|
||||
|
||||
#define WPAD_CLASSIC_BUTTON_UP 0x0001
|
||||
#define WPAD_CLASSIC_BUTTON_LEFT 0x0002
|
||||
#define WPAD_CLASSIC_BUTTON_ZR 0x0004
|
||||
#define WPAD_CLASSIC_BUTTON_X 0x0008
|
||||
#define WPAD_CLASSIC_BUTTON_A 0x0010
|
||||
#define WPAD_CLASSIC_BUTTON_Y 0x0020
|
||||
#define WPAD_CLASSIC_BUTTON_B 0x0040
|
||||
#define WPAD_CLASSIC_BUTTON_ZL 0x0080
|
||||
#define WPAD_CLASSIC_BUTTON_R 0x0200
|
||||
#define WPAD_CLASSIC_BUTTON_PLUS 0x0400
|
||||
#define WPAD_CLASSIC_BUTTON_HOME 0x0800
|
||||
#define WPAD_CLASSIC_BUTTON_MINUS 0x1000
|
||||
#define WPAD_CLASSIC_BUTTON_L 0x2000
|
||||
#define WPAD_CLASSIC_BUTTON_DOWN 0x4000
|
||||
#define WPAD_CLASSIC_BUTTON_RIGHT 0x8000
|
||||
|
||||
void InitPadScoreFunctionPointers(void);
|
||||
|
||||
|
||||
typedef struct _KPADData
|
||||
{
|
||||
u32 btns_h;
|
||||
u32 btns_d;
|
||||
u32 btns_r;
|
||||
u32 unused_1[5];
|
||||
f32 pos_x;
|
||||
f32 pos_y;
|
||||
u32 unused_2[3];
|
||||
f32 angle_x;
|
||||
f32 angle_y;
|
||||
u32 unused_3[8];
|
||||
u8 device_type;
|
||||
u8 wpad_error;
|
||||
u8 pos_valid;
|
||||
u8 unused_4[1];
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
f32 stick_x;
|
||||
f32 stick_y;
|
||||
} nunchuck;
|
||||
|
||||
struct
|
||||
{
|
||||
u32 btns_h;
|
||||
u32 btns_d;
|
||||
u32 btns_r;
|
||||
f32 lstick_x;
|
||||
f32 lstick_y;
|
||||
f32 rstick_x;
|
||||
f32 rstick_y;
|
||||
f32 ltrigger;
|
||||
f32 rtrigger;
|
||||
} classic;
|
||||
|
||||
u32 unused_6[20];
|
||||
};
|
||||
u32 unused_7[16];
|
||||
} KPADData;
|
||||
|
||||
typedef void (* wpad_connect_callback_t)(s32 chan, s32 status);
|
||||
|
||||
extern void (* KPADInit)(void);
|
||||
extern s32 (* WPADProbe)(s32 chan, u32 * pad_type);
|
||||
extern s32 (* WPADSetDataFormat)(s32 chan, s32 format);
|
||||
extern void (* WPADEnableURCC)(s32 enable);
|
||||
extern void (* WPADRead)(s32 chan, void * data);
|
||||
extern s32 (* KPADRead)(s32 chan, void * data, u32 size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __PAD_SCORE_FUNCTIONS_H_
|
84
src/dynamic_libs/socket_functions.c
Normal file
84
src/dynamic_libs/socket_functions.c
Normal file
@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "os_functions.h"
|
||||
#include "socket_functions.h"
|
||||
|
||||
u32 hostIpAddress = 0;
|
||||
|
||||
EXPORT_DECL(int, socket_lib_init, void);
|
||||
EXPORT_DECL(int, socket_lib_finish, void);
|
||||
EXPORT_DECL(int, socket, int domain, int type, int protocol);
|
||||
EXPORT_DECL(int, socketclose, int s);
|
||||
EXPORT_DECL(int, connect, int s, void *addr, int addrlen);
|
||||
EXPORT_DECL(int, bind, s32 s,struct sockaddr *name,s32 namelen);
|
||||
EXPORT_DECL(int, listen, s32 s,u32 backlog);
|
||||
EXPORT_DECL(int, accept, s32 s,struct sockaddr *addr,s32 *addrlen);
|
||||
EXPORT_DECL(int, send, int s, const void *buffer, int size, int flags);
|
||||
EXPORT_DECL(int, recv, int s, void *buffer, int size, int flags);
|
||||
EXPORT_DECL(int, sendto, int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len);
|
||||
EXPORT_DECL(int, setsockopt, int s, int level, int optname, void *optval, int optlen);
|
||||
EXPORT_DECL(char *, inet_ntoa, struct in_addr in);
|
||||
EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp);
|
||||
|
||||
void InitSocketFunctionPointers(void)
|
||||
{
|
||||
unsigned int nsysnet_handle;
|
||||
unsigned int *funcPointer = 0;
|
||||
OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);
|
||||
|
||||
unsigned int nn_ac_handle;
|
||||
int(*ACInitialize)();
|
||||
int(*ACGetStartupId) (unsigned int *id);
|
||||
int(*ACConnectWithConfigId) (unsigned int id);
|
||||
int(*ACGetAssignedAddress) (u32 * ip);
|
||||
OSDynLoad_Acquire("nn_ac.rpl", &nn_ac_handle);
|
||||
OSDynLoad_FindExport(nn_ac_handle, 0, "ACInitialize", &ACInitialize);
|
||||
OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetStartupId", &ACGetStartupId);
|
||||
OSDynLoad_FindExport(nn_ac_handle, 0, "ACConnectWithConfigId",&ACConnectWithConfigId);
|
||||
OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetAssignedAddress",&ACGetAssignedAddress);
|
||||
|
||||
OS_FIND_EXPORT(nsysnet_handle, socket_lib_init);
|
||||
OS_FIND_EXPORT(nsysnet_handle, socket_lib_finish);
|
||||
OS_FIND_EXPORT(nsysnet_handle, socket);
|
||||
OS_FIND_EXPORT(nsysnet_handle, socketclose);
|
||||
OS_FIND_EXPORT(nsysnet_handle, connect);
|
||||
OS_FIND_EXPORT(nsysnet_handle, bind);
|
||||
OS_FIND_EXPORT(nsysnet_handle, listen);
|
||||
OS_FIND_EXPORT(nsysnet_handle, accept);
|
||||
OS_FIND_EXPORT(nsysnet_handle, send);
|
||||
OS_FIND_EXPORT(nsysnet_handle, recv);
|
||||
OS_FIND_EXPORT(nsysnet_handle, sendto);
|
||||
OS_FIND_EXPORT(nsysnet_handle, setsockopt);
|
||||
OS_FIND_EXPORT(nsysnet_handle, inet_ntoa);
|
||||
OS_FIND_EXPORT(nsysnet_handle, inet_aton);
|
||||
|
||||
unsigned int nn_startupid;
|
||||
ACInitialize();
|
||||
ACGetStartupId(&nn_startupid);
|
||||
ACConnectWithConfigId(nn_startupid);
|
||||
ACGetAssignedAddress(&hostIpAddress);
|
||||
|
||||
socket_lib_init();
|
||||
}
|
||||
|
96
src/dynamic_libs/socket_functions.h
Normal file
96
src/dynamic_libs/socket_functions.h
Normal file
@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __SOCKET_FUNCTIONS_H_
|
||||
#define __SOCKET_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
#define INADDR_ANY 0
|
||||
|
||||
#define AF_INET 2
|
||||
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
|
||||
#define TCP_NODELAY 0x2004
|
||||
|
||||
#define SOL_SOCKET -1
|
||||
#define SO_REUSEADDR 0x0004
|
||||
#define SO_NONBLOCK 0x1016
|
||||
#define SO_MYADDR 0x1013
|
||||
|
||||
#define htonl(x) x
|
||||
#define htons(x) x
|
||||
#define ntohl(x) x
|
||||
#define ntohs(x) x
|
||||
|
||||
|
||||
struct in_addr {
|
||||
unsigned int s_addr;
|
||||
};
|
||||
struct sockaddr_in {
|
||||
short sin_family;
|
||||
unsigned short sin_port;
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
};
|
||||
|
||||
struct sockaddr
|
||||
{
|
||||
unsigned short sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
|
||||
void InitSocketFunctionPointers(void);
|
||||
|
||||
extern int (*socket_lib_init)(void);
|
||||
extern int (*socket_lib_finish)(void);
|
||||
extern int (*socket)(int domain, int type, int protocol);
|
||||
extern int (*socketclose)(int s);
|
||||
extern int (*connect)(int s, void *addr, int addrlen);
|
||||
extern int (*bind)(s32 s,struct sockaddr *name,s32 namelen);
|
||||
extern int (*listen)(s32 s,u32 backlog);
|
||||
extern int (*accept)(s32 s,struct sockaddr *addr,s32 *addrlen);
|
||||
extern int (*send)(int s, const void *buffer, int size, int flags);
|
||||
extern int (*recv)(int s, void *buffer, int size, int flags);
|
||||
extern int (*sendto)(int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len);
|
||||
extern int (*setsockopt)(int s, int level, int optname, void *optval, int optlen);
|
||||
|
||||
extern char * (*inet_ntoa)(struct in_addr in);
|
||||
extern int (*inet_aton)(const char *cp, struct in_addr *inp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __SOCKET_FUNCTIONS_H_
|
42
src/dynamic_libs/sys_functions.c
Normal file
42
src/dynamic_libs/sys_functions.c
Normal file
@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "os_functions.h"
|
||||
|
||||
EXPORT_DECL(void, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero);
|
||||
EXPORT_DECL(int, SYSRelaunchTitle, int argc, char* argv);
|
||||
EXPORT_DECL(int, SYSLaunchMenu, void);
|
||||
EXPORT_DECL(int, SYSCheckTitleExists, u64 titleId);
|
||||
|
||||
void InitSysFunctionPointers(void)
|
||||
{
|
||||
unsigned int *funcPointer = 0;
|
||||
unsigned int sysapp_handle;
|
||||
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
|
||||
|
||||
OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher);
|
||||
OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle);
|
||||
OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu);
|
||||
OS_FIND_EXPORT(sysapp_handle, SYSCheckTitleExists);
|
||||
}
|
||||
|
43
src/dynamic_libs/sys_functions.h
Normal file
43
src/dynamic_libs/sys_functions.h
Normal file
@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __SYS_FUNCTIONS_H_
|
||||
#define __SYS_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void InitSysFunctionPointers(void);
|
||||
|
||||
extern void(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero);
|
||||
extern int (* SYSRelaunchTitle)(int argc, char* argv);
|
||||
extern int (* SYSLaunchMenu)(void);
|
||||
extern int (* SYSCheckTitleExists)(u64 titleId);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __SYS_FUNCTIONS_H_
|
39
src/dynamic_libs/vpad_functions.c
Normal file
39
src/dynamic_libs/vpad_functions.c
Normal file
@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "os_functions.h"
|
||||
#include "vpad_functions.h"
|
||||
|
||||
EXPORT_DECL(void, VPADInit, void);
|
||||
EXPORT_DECL(void, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error);
|
||||
|
||||
void InitVPadFunctionPointers(void)
|
||||
{
|
||||
unsigned int *funcPointer = 0;
|
||||
unsigned int vpad_handle;
|
||||
OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
|
||||
|
||||
OS_FIND_EXPORT(vpad_handle, VPADInit);
|
||||
OS_FIND_EXPORT(vpad_handle, VPADRead);
|
||||
}
|
||||
|
102
src/dynamic_libs/vpad_functions.h
Normal file
102
src/dynamic_libs/vpad_functions.h
Normal file
@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __VPAD_FUNCTIONS_H_
|
||||
#define __VPAD_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
#define VPAD_BUTTON_A 0x8000
|
||||
#define VPAD_BUTTON_B 0x4000
|
||||
#define VPAD_BUTTON_X 0x2000
|
||||
#define VPAD_BUTTON_Y 0x1000
|
||||
#define VPAD_BUTTON_LEFT 0x0800
|
||||
#define VPAD_BUTTON_RIGHT 0x0400
|
||||
#define VPAD_BUTTON_UP 0x0200
|
||||
#define VPAD_BUTTON_DOWN 0x0100
|
||||
#define VPAD_BUTTON_ZL 0x0080
|
||||
#define VPAD_BUTTON_ZR 0x0040
|
||||
#define VPAD_BUTTON_L 0x0020
|
||||
#define VPAD_BUTTON_R 0x0010
|
||||
#define VPAD_BUTTON_PLUS 0x0008
|
||||
#define VPAD_BUTTON_MINUS 0x0004
|
||||
#define VPAD_BUTTON_HOME 0x0002
|
||||
#define VPAD_BUTTON_SYNC 0x0001
|
||||
#define VPAD_BUTTON_STICK_R 0x00020000
|
||||
#define VPAD_BUTTON_STICK_L 0x00040000
|
||||
#define VPAD_BUTTON_TV 0x00010000
|
||||
|
||||
#define VPAD_STICK_R_EMULATION_LEFT 0x04000000
|
||||
#define VPAD_STICK_R_EMULATION_RIGHT 0x02000000
|
||||
#define VPAD_STICK_R_EMULATION_UP 0x01000000
|
||||
#define VPAD_STICK_R_EMULATION_DOWN 0x00800000
|
||||
|
||||
#define VPAD_STICK_L_EMULATION_LEFT 0x40000000
|
||||
#define VPAD_STICK_L_EMULATION_RIGHT 0x20000000
|
||||
#define VPAD_STICK_L_EMULATION_UP 0x10000000
|
||||
#define VPAD_STICK_L_EMULATION_DOWN 0x08000000
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
f32 x,y;
|
||||
} Vec2D;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u16 x, y; /* Touch coordinates */
|
||||
u16 touched; /* 1 = Touched, 0 = Not touched */
|
||||
u16 invalid; /* 0 = All valid, 1 = X invalid, 2 = Y invalid, 3 = Both invalid? */
|
||||
} VPADTPData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 btns_h; /* Held buttons */
|
||||
u32 btns_d; /* Buttons that are pressed at that instant */
|
||||
u32 btns_r; /* Released buttons */
|
||||
Vec2D lstick, rstick; /* Each contains 4-byte X and Y components */
|
||||
char unknown1c[0x52 - 0x1c]; /* Contains accelerometer and gyroscope data somewhere */
|
||||
VPADTPData tpdata; /* Normal touchscreen data */
|
||||
VPADTPData tpdata1; /* Modified touchscreen data 1 */
|
||||
VPADTPData tpdata2; /* Modified touchscreen data 2 */
|
||||
char unknown6a[0xa0 - 0x6a];
|
||||
uint8_t volume;
|
||||
uint8_t battery; /* 0 to 6 */
|
||||
uint8_t unk_volume; /* One less than volume */
|
||||
char unknowna4[0xac - 0xa4];
|
||||
} VPADData;
|
||||
|
||||
void InitVPadFunctionPointers(void);
|
||||
|
||||
extern void (* VPADInit)(void);
|
||||
extern void (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __VPAD_FUNCTIONS_H_
|
27
src/entry.c
Normal file
27
src/entry.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <string.h>
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "dynamic_libs/gx2_functions.h"
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "common/common.h"
|
||||
#include "pygecko.h"
|
||||
#include "main.h"
|
||||
|
||||
int __entry_menu(int argc, char **argv) {
|
||||
if (OSGetTitleID != 0 &&
|
||||
OSGetTitleID() != 0x000500101004A200 && // mii maker eur
|
||||
OSGetTitleID() != 0x000500101004A100 && // mii maker usa
|
||||
OSGetTitleID() != 0x000500101004A000) // mii maker jpn)
|
||||
{
|
||||
InitOSFunctionPointers();
|
||||
InitSocketFunctionPointers();
|
||||
InitGX2FunctionPointers();
|
||||
|
||||
start_pygecko();
|
||||
return EXIT_RELAUNCH_ON_LOAD;
|
||||
}
|
||||
|
||||
//! *******************************************************************
|
||||
//! * Jump to our application *
|
||||
//! *******************************************************************
|
||||
return Menu_Main();
|
||||
}
|
197
src/fs/CFile.cpp
Normal file
197
src/fs/CFile.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include "CFile.hpp"
|
||||
|
||||
CFile::CFile()
|
||||
{
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
CFile::CFile(const std::string & filepath, eOpenTypes mode)
|
||||
{
|
||||
iFd = -1;
|
||||
this->open(filepath, mode);
|
||||
}
|
||||
|
||||
CFile::CFile(const u8 * mem, int size)
|
||||
{
|
||||
iFd = -1;
|
||||
this->open(mem, size);
|
||||
}
|
||||
|
||||
CFile::~CFile()
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
|
||||
int CFile::open(const std::string & filepath, eOpenTypes mode)
|
||||
{
|
||||
this->close();
|
||||
|
||||
s32 openMode = 0;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
default:
|
||||
case ReadOnly:
|
||||
openMode = O_RDONLY;
|
||||
break;
|
||||
case WriteOnly:
|
||||
openMode = O_WRONLY;
|
||||
break;
|
||||
case ReadWrite:
|
||||
openMode = O_RDWR;
|
||||
break;
|
||||
case Append:
|
||||
openMode = O_APPEND | O_WRONLY;
|
||||
break;
|
||||
}
|
||||
|
||||
//! Using fopen works only on the first launch as expected
|
||||
//! on the second launch it causes issues because we don't overwrite
|
||||
//! the .data sections which is needed for a normal application to re-init
|
||||
//! this will be added with launching as RPX
|
||||
iFd = ::open(filepath.c_str(), openMode);
|
||||
if(iFd < 0)
|
||||
return iFd;
|
||||
|
||||
|
||||
filesize = ::lseek(iFd, 0, SEEK_END);
|
||||
::lseek(iFd, 0, SEEK_SET);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CFile::open(const u8 * mem, int size)
|
||||
{
|
||||
this->close();
|
||||
|
||||
mem_file = mem;
|
||||
filesize = size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CFile::close()
|
||||
{
|
||||
if(iFd >= 0)
|
||||
::close(iFd);
|
||||
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
int CFile::read(u8 * ptr, size_t size)
|
||||
{
|
||||
if(iFd >= 0)
|
||||
{
|
||||
int ret = ::read(iFd, ptr,size);
|
||||
if(ret > 0)
|
||||
pos += ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int readsize = size;
|
||||
|
||||
if(readsize > (s64) (filesize-pos))
|
||||
readsize = filesize-pos;
|
||||
|
||||
if(readsize <= 0)
|
||||
return readsize;
|
||||
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
memcpy(ptr, mem_file+pos, readsize);
|
||||
pos += readsize;
|
||||
return readsize;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CFile::write(const u8 * ptr, size_t size)
|
||||
{
|
||||
if(iFd >= 0)
|
||||
{
|
||||
size_t done = 0;
|
||||
while(done < size)
|
||||
{
|
||||
int ret = ::write(iFd, ptr, size - done);
|
||||
if(ret <= 0)
|
||||
return ret;
|
||||
|
||||
ptr += ret;
|
||||
done += ret;
|
||||
pos += ret;
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CFile::seek(long int offset, int origin)
|
||||
{
|
||||
int ret = 0;
|
||||
s64 newPos = pos;
|
||||
|
||||
if(origin == SEEK_SET)
|
||||
{
|
||||
newPos = offset;
|
||||
}
|
||||
else if(origin == SEEK_CUR)
|
||||
{
|
||||
newPos += offset;
|
||||
}
|
||||
else if(origin == SEEK_END)
|
||||
{
|
||||
newPos = filesize+offset;
|
||||
}
|
||||
|
||||
if(newPos < 0)
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
else {
|
||||
pos = newPos;
|
||||
}
|
||||
|
||||
if(iFd >= 0)
|
||||
ret = ::lseek(iFd, pos, SEEK_SET);
|
||||
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
if(pos > filesize)
|
||||
{
|
||||
pos = filesize;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CFile::fwrite(const char *format, ...)
|
||||
{
|
||||
int result = -1;
|
||||
char * tmp = NULL;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
result = this->write((u8 *)tmp, strlen(tmp));
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
57
src/fs/CFile.hpp
Normal file
57
src/fs/CFile.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef CFILE_HPP_
|
||||
#define CFILE_HPP_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <gctypes.h>
|
||||
|
||||
class CFile
|
||||
{
|
||||
public:
|
||||
enum eOpenTypes
|
||||
{
|
||||
ReadOnly,
|
||||
WriteOnly,
|
||||
ReadWrite,
|
||||
Append
|
||||
};
|
||||
|
||||
CFile();
|
||||
CFile(const std::string & filepath, eOpenTypes mode);
|
||||
CFile(const u8 * memory, int memsize);
|
||||
virtual ~CFile();
|
||||
|
||||
int open(const std::string & filepath, eOpenTypes mode);
|
||||
int open(const u8 * memory, int memsize);
|
||||
|
||||
bool isOpen() const {
|
||||
if(iFd >= 0)
|
||||
return true;
|
||||
|
||||
if(mem_file)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void close();
|
||||
|
||||
int read(u8 * ptr, size_t size);
|
||||
int write(const u8 * ptr, size_t size);
|
||||
int fwrite(const char *format, ...);
|
||||
int seek(long int offset, int origin);
|
||||
u64 tell() { return pos; };
|
||||
u64 size() { return filesize; };
|
||||
void rewind() { this->seek(0, SEEK_SET); };
|
||||
|
||||
protected:
|
||||
int iFd;
|
||||
const u8 * mem_file;
|
||||
u64 filesize;
|
||||
u64 pos;
|
||||
};
|
||||
|
||||
#endif
|
224
src/fs/DirList.cpp
Normal file
224
src/fs/DirList.cpp
Normal file
@ -0,0 +1,224 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* DirList Class
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/dirent.h>
|
||||
|
||||
#include "DirList.h"
|
||||
#include "utils/StringTools.h"
|
||||
|
||||
DirList::DirList()
|
||||
{
|
||||
Flags = 0;
|
||||
Filter = 0;
|
||||
}
|
||||
|
||||
DirList::DirList(const std::string & path, const char *filter, u32 flags)
|
||||
{
|
||||
this->LoadPath(path, filter, flags);
|
||||
this->SortList();
|
||||
}
|
||||
|
||||
DirList::~DirList()
|
||||
{
|
||||
ClearList();
|
||||
}
|
||||
|
||||
bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags)
|
||||
{
|
||||
if(folder.empty()) return false;
|
||||
|
||||
Flags = flags;
|
||||
Filter = filter;
|
||||
|
||||
std::string folderpath(folder);
|
||||
u32 length = folderpath.size();
|
||||
|
||||
//! clear path of double slashes
|
||||
RemoveDoubleSlashs(folderpath);
|
||||
|
||||
//! remove last slash if exists
|
||||
if(length > 0 && folderpath[length-1] == '/')
|
||||
folderpath.erase(length-1);
|
||||
|
||||
return InternalLoadPath(folderpath);
|
||||
}
|
||||
|
||||
bool DirList::InternalLoadPath(std::string &folderpath)
|
||||
{
|
||||
if(folderpath.size() < 3)
|
||||
return false;
|
||||
|
||||
struct dirent *dirent = NULL;
|
||||
DIR *dir = NULL;
|
||||
|
||||
dir = opendir(folderpath.c_str());
|
||||
if (dir == NULL)
|
||||
return false;
|
||||
|
||||
while ((dirent = readdir(dir)) != 0)
|
||||
{
|
||||
bool isDir = dirent->d_type & DT_DIR;
|
||||
const char *filename = dirent->d_name;
|
||||
|
||||
if(isDir)
|
||||
{
|
||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||
continue;
|
||||
|
||||
if(Flags & CheckSubfolders)
|
||||
{
|
||||
int length = folderpath.size();
|
||||
if(length > 2 && folderpath[length-1] != '/')
|
||||
folderpath += '/';
|
||||
folderpath += filename;
|
||||
InternalLoadPath(folderpath);
|
||||
folderpath.erase(length);
|
||||
}
|
||||
|
||||
if(!(Flags & Dirs))
|
||||
continue;
|
||||
}
|
||||
else if(!(Flags & Files))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(Filter)
|
||||
{
|
||||
char * fileext = strrchr(filename, '.');
|
||||
if(!fileext)
|
||||
continue;
|
||||
|
||||
if(strtokcmp(fileext, Filter, ",") == 0)
|
||||
AddEntrie(folderpath, filename, isDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddEntrie(folderpath, filename, isDir);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirList::AddEntrie(const std::string &filepath, const char * filename, bool isDir)
|
||||
{
|
||||
if(!filename)
|
||||
return;
|
||||
|
||||
// Don't list hidden OS X files
|
||||
if(filename[0] == '.' && filename[1] == '_')
|
||||
return;
|
||||
|
||||
int pos = FileInfo.size();
|
||||
|
||||
FileInfo.resize(pos+1);
|
||||
|
||||
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2);
|
||||
if(!FileInfo[pos].FilePath)
|
||||
{
|
||||
FileInfo.resize(pos);
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(FileInfo[pos].FilePath, "%s/%s", filepath.c_str(), filename);
|
||||
FileInfo[pos].isDir = isDir;
|
||||
}
|
||||
|
||||
void DirList::ClearList()
|
||||
{
|
||||
for(u32 i = 0; i < FileInfo.size(); ++i)
|
||||
{
|
||||
if(FileInfo[i].FilePath)
|
||||
free(FileInfo[i].FilePath);
|
||||
}
|
||||
|
||||
FileInfo.clear();
|
||||
std::vector<DirEntry>().swap(FileInfo);
|
||||
}
|
||||
|
||||
const char * DirList::GetFilename(int ind) const
|
||||
{
|
||||
if (!valid(ind))
|
||||
return "";
|
||||
|
||||
return FullpathToFilename(FileInfo[ind].FilePath);
|
||||
}
|
||||
|
||||
static bool SortCallback(const DirEntry & f1, const DirEntry & f2)
|
||||
{
|
||||
if(f1.isDir && !(f2.isDir)) return true;
|
||||
if(!(f1.isDir) && f2.isDir) return false;
|
||||
|
||||
if(f1.FilePath && !f2.FilePath) return true;
|
||||
if(!f1.FilePath) return false;
|
||||
|
||||
return strcasecmp(f1.FilePath, f2.FilePath) <= 0;
|
||||
}
|
||||
|
||||
void DirList::SortList()
|
||||
{
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||
}
|
||||
|
||||
void DirList::SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b))
|
||||
{
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||
}
|
||||
|
||||
u64 DirList::GetFilesize(int index) const
|
||||
{
|
||||
struct stat st;
|
||||
const char *path = GetFilepath(index);
|
||||
|
||||
if(!path || stat(path, &st) != 0)
|
||||
return 0;
|
||||
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
int DirList::GetFileIndex(const char *filename) const
|
||||
{
|
||||
if(!filename)
|
||||
return -1;
|
||||
|
||||
for (u32 i = 0; i < FileInfo.size(); ++i)
|
||||
{
|
||||
if (strcasecmp(GetFilename(i), filename) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
95
src/fs/DirList.h
Normal file
95
src/fs/DirList.h
Normal file
@ -0,0 +1,95 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* DirList Class
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef ___DIRLIST_H_
|
||||
#define ___DIRLIST_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <gctypes.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * FilePath;
|
||||
bool isDir;
|
||||
} DirEntry;
|
||||
|
||||
class DirList
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
DirList(void);
|
||||
//!\param path Path from where to load the filelist of all files
|
||||
//!\param filter A fileext that needs to be filtered
|
||||
//!\param flags search/filter flags from the enum
|
||||
DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
//!Destructor
|
||||
virtual ~DirList();
|
||||
//! Load all the files from a directory
|
||||
bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||
//! Get a filename of the list
|
||||
//!\param list index
|
||||
const char * GetFilename(int index) const;
|
||||
//! Get the a filepath of the list
|
||||
//!\param list index
|
||||
const char *GetFilepath(int index) const { if (!valid(index)) return ""; else return FileInfo[index].FilePath; }
|
||||
//! Get the a filesize of the list
|
||||
//!\param list index
|
||||
u64 GetFilesize(int index) const;
|
||||
//! Is index a dir or a file
|
||||
//!\param list index
|
||||
bool IsDir(int index) const { if(!valid(index)) return false; return FileInfo[index].isDir; };
|
||||
//! Get the filecount of the whole list
|
||||
int GetFilecount() const { return FileInfo.size(); };
|
||||
//! Sort list by filepath
|
||||
void SortList();
|
||||
//! Custom sort command for custom sort functions definitions
|
||||
void SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b));
|
||||
//! Get the index of the specified filename
|
||||
int GetFileIndex(const char *filename) const;
|
||||
//! Enum for search/filter flags
|
||||
enum
|
||||
{
|
||||
Files = 0x01,
|
||||
Dirs = 0x02,
|
||||
CheckSubfolders = 0x08,
|
||||
};
|
||||
protected:
|
||||
// Internal parser
|
||||
bool InternalLoadPath(std::string &path);
|
||||
//!Add a list entrie
|
||||
void AddEntrie(const std::string &filepath, const char * filename, bool isDir);
|
||||
//! Clear the list
|
||||
void ClearList();
|
||||
//! Check if valid pos is requested
|
||||
inline bool valid(u32 pos) const { return (pos < FileInfo.size()); };
|
||||
|
||||
u32 Flags;
|
||||
const char *Filter;
|
||||
std::vector<DirEntry> FileInfo;
|
||||
};
|
||||
|
||||
#endif
|
182
src/fs/fs_utils.c
Normal file
182
src/fs/fs_utils.c
Normal file
@ -0,0 +1,182 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "common/fs_defs.h"
|
||||
#include "dynamic_libs/fs_functions.h"
|
||||
|
||||
|
||||
int MountFS(void *pClient, void *pCmd, char **mount_path)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
void *mountSrc = malloc(FS_MOUNT_SOURCE_SIZE);
|
||||
if(!mountSrc)
|
||||
return -3;
|
||||
|
||||
char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE);
|
||||
if(!mountPath) {
|
||||
free(mountSrc);
|
||||
return -4;
|
||||
}
|
||||
|
||||
memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE);
|
||||
memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE);
|
||||
|
||||
// Mount sdcard
|
||||
if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0)
|
||||
{
|
||||
result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
|
||||
if((result == 0) && mount_path) {
|
||||
*mount_path = (char*)malloc(strlen(mountPath) + 1);
|
||||
if(*mount_path)
|
||||
strcpy(*mount_path, mountPath);
|
||||
}
|
||||
}
|
||||
|
||||
free(mountPath);
|
||||
free(mountSrc);
|
||||
return result;
|
||||
}
|
||||
|
||||
int UmountFS(void *pClient, void *pCmd, const char *mountPath)
|
||||
{
|
||||
int result = -1;
|
||||
result = FSUnmount(pClient, pCmd, mountPath, -1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
|
||||
{
|
||||
//! always initialze input
|
||||
*inbuffer = NULL;
|
||||
if(size)
|
||||
*size = 0;
|
||||
|
||||
int iFd = open(filepath, O_RDONLY);
|
||||
if (iFd < 0)
|
||||
return -1;
|
||||
|
||||
u32 filesize = lseek(iFd, 0, SEEK_END);
|
||||
lseek(iFd, 0, SEEK_SET);
|
||||
|
||||
u8 *buffer = (u8 *) malloc(filesize);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
close(iFd);
|
||||
return -2;
|
||||
}
|
||||
|
||||
u32 blocksize = 0x4000;
|
||||
u32 done = 0;
|
||||
int readBytes = 0;
|
||||
|
||||
while(done < filesize)
|
||||
{
|
||||
if(done + blocksize > filesize) {
|
||||
blocksize = filesize - done;
|
||||
}
|
||||
readBytes = read(iFd, buffer + done, blocksize);
|
||||
if(readBytes <= 0)
|
||||
break;
|
||||
done += readBytes;
|
||||
}
|
||||
|
||||
close(iFd);
|
||||
|
||||
if (done != filesize)
|
||||
{
|
||||
free(buffer);
|
||||
return -3;
|
||||
}
|
||||
|
||||
*inbuffer = buffer;
|
||||
|
||||
//! sign is optional input
|
||||
if(size)
|
||||
*size = filesize;
|
||||
|
||||
return filesize;
|
||||
}
|
||||
|
||||
int CheckFile(const char * filepath)
|
||||
{
|
||||
if(!filepath)
|
||||
return 0;
|
||||
|
||||
struct stat filestat;
|
||||
|
||||
char dirnoslash[strlen(filepath)+2];
|
||||
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
||||
|
||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
||||
|
||||
char * notRoot = strrchr(dirnoslash, '/');
|
||||
if(!notRoot)
|
||||
{
|
||||
strcat(dirnoslash, "/");
|
||||
}
|
||||
|
||||
if (stat(dirnoslash, &filestat) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CreateSubfolder(const char * fullpath)
|
||||
{
|
||||
if(!fullpath)
|
||||
return 0;
|
||||
|
||||
int result = 0;
|
||||
|
||||
char dirnoslash[strlen(fullpath)+1];
|
||||
strcpy(dirnoslash, fullpath);
|
||||
|
||||
int pos = strlen(dirnoslash)-1;
|
||||
while(dirnoslash[pos] == '/')
|
||||
{
|
||||
dirnoslash[pos] = '\0';
|
||||
pos--;
|
||||
}
|
||||
|
||||
if(CheckFile(dirnoslash))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
char parentpath[strlen(dirnoslash)+2];
|
||||
strcpy(parentpath, dirnoslash);
|
||||
char * ptr = strrchr(parentpath, '/');
|
||||
|
||||
if(!ptr)
|
||||
{
|
||||
//!Device root directory (must be with '/')
|
||||
strcat(parentpath, "/");
|
||||
struct stat filestat;
|
||||
if (stat(parentpath, &filestat) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
ptr[0] = '\0';
|
||||
|
||||
result = CreateSubfolder(parentpath);
|
||||
}
|
||||
|
||||
if(!result)
|
||||
return 0;
|
||||
|
||||
if (mkdir(dirnoslash, 0777) == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
23
src/fs/fs_utils.h
Normal file
23
src/fs/fs_utils.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __FS_UTILS_H_
|
||||
#define __FS_UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
int MountFS(void *pClient, void *pCmd, char **mount_path);
|
||||
int UmountFS(void *pClient, void *pCmd, const char *mountPath);
|
||||
|
||||
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size);
|
||||
|
||||
//! todo: C++ class
|
||||
int CreateSubfolder(const char * fullpath);
|
||||
int CheckFile(const char * filepath);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __FS_UTILS_H_
|
1019
src/fs/sd_fat_devoptab.c
Normal file
1019
src/fs/sd_fat_devoptab.c
Normal file
File diff suppressed because it is too large
Load Diff
38
src/fs/sd_fat_devoptab.h
Normal file
38
src/fs/sd_fat_devoptab.h
Normal file
@ -0,0 +1,38 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __SD_FAT_DEVOPTAB_H_
|
||||
#define __SD_FAT_DEVOPTAB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int mount_sd_fat(const char *path);
|
||||
int unmount_sd_fat(const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __SD_FAT_DEVOPTAB_H_
|
1729
src/game/memory_area_table.c
Normal file
1729
src/game/memory_area_table.c
Normal file
File diff suppressed because it is too large
Load Diff
40
src/game/memory_area_table.h
Normal file
40
src/game/memory_area_table.h
Normal file
@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef _MEMORY_AREA_TABLE_H_
|
||||
#define _MEMORY_AREA_TABLE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Struct used to organize empty memory areas */
|
||||
typedef struct _s_mem_area
|
||||
{
|
||||
unsigned int address;
|
||||
unsigned int size;
|
||||
struct _s_mem_area* next;
|
||||
} s_mem_area;
|
||||
|
||||
void memoryInitAreaTable();
|
||||
s_mem_area * memoryGetAreaTable(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _MEMORY_AREA_TABLE_H_
|
210
src/game/rpx_rpl_table.c
Normal file
210
src/game/rpx_rpl_table.c
Normal file
@ -0,0 +1,210 @@
|
||||
#include <string.h>
|
||||
#include "rpx_rpl_table.h"
|
||||
#include "kernel/kernel_functions.h"
|
||||
#include "common/common.h"
|
||||
|
||||
//! static container holding our retain data
|
||||
static unsigned char ucRpxData[0xffff];
|
||||
static int iRpxRplCount = 0;
|
||||
|
||||
void rpxRplTableInit(void)
|
||||
{
|
||||
s_rpx_rpl *pRpxData = (s_rpx_rpl*)ucRpxData;
|
||||
//! initialize the RPL/RPX table first entry to zero + 1 byte for name zero termination
|
||||
//! just in case no RPL/RPX are found, though it wont boot then anyway
|
||||
memset(pRpxData, 0, sizeof(s_rpx_rpl) + 1);
|
||||
iRpxRplCount = 0;
|
||||
}
|
||||
|
||||
s_rpx_rpl * rpxRplTableAddEntry(const char *name, int offset, int size, int is_rpx, int entry_index, s_mem_area* area)
|
||||
{
|
||||
// fill rpx/rpl entry
|
||||
s_rpx_rpl * rpx_rpl_data = (s_rpx_rpl *)(ucRpxData);
|
||||
// get to last entry
|
||||
while(rpx_rpl_data->next) {
|
||||
rpx_rpl_data = rpx_rpl_data->next;
|
||||
}
|
||||
|
||||
// setup next entry on the previous one (only if it is not the first entry)
|
||||
if(entry_index > 0) {
|
||||
rpx_rpl_data->next = (s_rpx_rpl *)( ((u32)rpx_rpl_data) + sizeof(s_rpx_rpl) + strlen(rpx_rpl_data->name) + 1 );
|
||||
rpx_rpl_data = rpx_rpl_data->next;
|
||||
}
|
||||
|
||||
// setup current entry
|
||||
rpx_rpl_data->area = area;
|
||||
rpx_rpl_data->size = size;
|
||||
rpx_rpl_data->offset = offset;
|
||||
rpx_rpl_data->is_rpx = is_rpx;
|
||||
rpx_rpl_data->next = 0;
|
||||
strcpy(rpx_rpl_data->name, name);
|
||||
|
||||
iRpxRplCount++;
|
||||
|
||||
return rpx_rpl_data;
|
||||
}
|
||||
|
||||
s_rpx_rpl* rpxRplTableGet(void)
|
||||
{
|
||||
return (s_rpx_rpl*)ucRpxData;
|
||||
}
|
||||
|
||||
int rpxRplTableGetCount(void)
|
||||
{
|
||||
return iRpxRplCount;
|
||||
}
|
||||
|
||||
s_mem_area *rpxRplTableGetNextFreeMemArea(u32 * mem_area_addr_start, u32 * mem_area_addr_end, u32 * mem_area_offset)
|
||||
{
|
||||
s_mem_area * mem_area = memoryGetAreaTable();
|
||||
s_rpx_rpl *rpl_struct = rpxRplTableGet();
|
||||
while(rpl_struct != 0)
|
||||
{
|
||||
// check if this entry was loaded into memory
|
||||
if(rpl_struct->size == 0) {
|
||||
// see if we find entries behind this one that was pre-loaded
|
||||
rpl_struct = rpl_struct->next;
|
||||
// entry was not loaded into memory -> skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
// this entry has been loaded to memory, remember it's area
|
||||
mem_area = rpl_struct->area;
|
||||
|
||||
int rpl_size = rpl_struct->size;
|
||||
int rpl_offset = rpl_struct->offset;
|
||||
// find the end of the entry and switch between areas if needed
|
||||
while(mem_area && (u32)(rpl_offset + rpl_size) >= mem_area->size)
|
||||
{
|
||||
rpl_size -= mem_area->size - rpl_offset;
|
||||
rpl_offset = 0;
|
||||
mem_area = mem_area->next;
|
||||
}
|
||||
|
||||
if(!mem_area)
|
||||
return NULL;
|
||||
|
||||
// set new start, end and memory area offset
|
||||
*mem_area_addr_start = mem_area->address;
|
||||
*mem_area_addr_end = mem_area->address + mem_area->size;
|
||||
*mem_area_offset = rpl_offset + rpl_size;
|
||||
|
||||
// see if we find entries behind this one that was pre-loaded
|
||||
rpl_struct = rpl_struct->next;
|
||||
}
|
||||
return mem_area;
|
||||
}
|
||||
|
||||
int rpxRplCopyDataToMem(s_rpx_rpl *rpx_rpl_struct, u32 fileOffset, const u8 *data, u32 dataSize)
|
||||
{
|
||||
s_mem_area *mem_area = rpx_rpl_struct->area;
|
||||
u32 mem_area_addr_start = mem_area->address;
|
||||
u32 mem_area_addr_end = mem_area_addr_start + mem_area->size;
|
||||
u32 mem_area_offset = rpx_rpl_struct->offset;
|
||||
|
||||
// add to offset
|
||||
mem_area_offset += fileOffset;
|
||||
|
||||
// skip position to the end of the fill
|
||||
while ((mem_area_addr_start + mem_area_offset) >= mem_area_addr_end) // TODO: maybe >, not >=
|
||||
{
|
||||
// subtract what was in the offset left from last memory block
|
||||
mem_area_offset = (mem_area_addr_start + mem_area_offset) - mem_area_addr_end;
|
||||
mem_area = mem_area->next;
|
||||
if(!mem_area)
|
||||
return 0;
|
||||
|
||||
mem_area_addr_start = mem_area->address;
|
||||
mem_area_addr_end = mem_area_addr_start + mem_area->size;
|
||||
}
|
||||
|
||||
// copy to memory
|
||||
u32 copiedBytes = 0;
|
||||
while(copiedBytes < dataSize)
|
||||
{
|
||||
u32 blockSize = dataSize - copiedBytes;
|
||||
u32 mem_area_addr_dest = mem_area_addr_start + mem_area_offset;
|
||||
|
||||
if((mem_area_addr_dest + blockSize) > mem_area_addr_end)
|
||||
blockSize = mem_area_addr_end - mem_area_addr_dest;
|
||||
|
||||
if(blockSize == 0)
|
||||
{
|
||||
// Set next memory area
|
||||
mem_area = mem_area->next;
|
||||
if(!mem_area)
|
||||
return 0;
|
||||
|
||||
mem_area_addr_start = mem_area->address;
|
||||
mem_area_addr_end = mem_area->address + mem_area->size;
|
||||
mem_area_offset = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
SC0x25_KernelCopyData(mem_area_addr_dest, (u32)&data[copiedBytes], blockSize);
|
||||
mem_area_offset += blockSize;
|
||||
copiedBytes += blockSize;
|
||||
}
|
||||
|
||||
return copiedBytes;
|
||||
}
|
||||
|
||||
int rpxRplCopyDataFromMem(s_rpx_rpl *rpx_rpl_struct, u32 fileOffset, u8 *data, u32 dataSize)
|
||||
{
|
||||
s_mem_area *mem_area = rpx_rpl_struct->area;
|
||||
u32 mem_area_addr_start = mem_area->address;
|
||||
u32 mem_area_addr_end = mem_area_addr_start + mem_area->size;
|
||||
u32 mem_area_offset = rpx_rpl_struct->offset;
|
||||
|
||||
if(fileOffset > rpx_rpl_struct->size)
|
||||
return 0;
|
||||
|
||||
if((fileOffset + dataSize) > rpx_rpl_struct->size)
|
||||
dataSize = rpx_rpl_struct->size - fileOffset;
|
||||
|
||||
// add to offset
|
||||
mem_area_offset += fileOffset;
|
||||
|
||||
// skip position to the end of the fill
|
||||
while ((mem_area_addr_start + mem_area_offset) >= mem_area_addr_end) // TODO: maybe >, not >=
|
||||
{
|
||||
// subtract what was in the offset left from last memory block
|
||||
mem_area_offset = (mem_area_addr_start + mem_area_offset) - mem_area_addr_end;
|
||||
mem_area = mem_area->next;
|
||||
if(!mem_area)
|
||||
return 0;
|
||||
|
||||
mem_area_addr_start = mem_area->address;
|
||||
mem_area_addr_end = mem_area_addr_start + mem_area->size;
|
||||
}
|
||||
|
||||
// copy to memory
|
||||
u32 copiedBytes = 0;
|
||||
while(copiedBytes < dataSize)
|
||||
{
|
||||
u32 blockSize = dataSize - copiedBytes;
|
||||
u32 mem_area_addr_dest = mem_area_addr_start + mem_area_offset;
|
||||
|
||||
if((mem_area_addr_dest + blockSize) > mem_area_addr_end)
|
||||
blockSize = mem_area_addr_end - mem_area_addr_dest;
|
||||
|
||||
if(blockSize == 0)
|
||||
{
|
||||
// Set next memory area
|
||||
mem_area = mem_area->next;
|
||||
if(!mem_area)
|
||||
return 0;
|
||||
|
||||
mem_area_addr_start = mem_area->address;
|
||||
mem_area_addr_end = mem_area->address + mem_area->size;
|
||||
mem_area_offset = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
SC0x25_KernelCopyData((u32)&data[copiedBytes], mem_area_addr_dest, blockSize);
|
||||
mem_area_offset += blockSize;
|
||||
copiedBytes += blockSize;
|
||||
}
|
||||
|
||||
return copiedBytes;
|
||||
}
|
37
src/game/rpx_rpl_table.h
Normal file
37
src/game/rpx_rpl_table.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef __RPX_ARRAY_H_
|
||||
#define __RPX_ARRAY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
#include "common/common.h"
|
||||
#include "memory_area_table.h"
|
||||
|
||||
/* Struct used to organize rpx/rpl data in memory */
|
||||
typedef struct _s_rpx_rpl
|
||||
{
|
||||
struct _s_rpx_rpl* next;
|
||||
s_mem_area* area;
|
||||
unsigned int offset;
|
||||
unsigned int size;
|
||||
unsigned char is_rpx;
|
||||
char name[0];
|
||||
} s_rpx_rpl;
|
||||
|
||||
void rpxRplTableInit(void);
|
||||
s_rpx_rpl* rpxRplTableAddEntry(const char *name, int offset, int size, int is_rpx, int entry_index, s_mem_area* area);
|
||||
s_rpx_rpl* rpxRplTableGet(void);
|
||||
int rpxRplTableGetCount(void);
|
||||
|
||||
s_mem_area *rpxRplTableGetNextFreeMemArea(u32 * mem_area_addr_start, u32 * mem_area_addr_end, u32 * mem_area_offset);
|
||||
int rpxRplCopyDataToMem(s_rpx_rpl *rpx_rpl_struct, u32 fileOffset, const u8 *data, u32 dataSize);
|
||||
int rpxRplCopyDataFromMem(s_rpx_rpl *rpx_rpl_struct, u32 fileOffset, u8 *data, u32 dataSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
81
src/kernel/kernel_functions.c
Normal file
81
src/kernel/kernel_functions.c
Normal file
@ -0,0 +1,81 @@
|
||||
#include <string.h>
|
||||
#include "common/common.h"
|
||||
#include "common/kernel_defs.h"
|
||||
#include "kernel/kernel_functions.h"
|
||||
#include "kernel/syscalls.h"
|
||||
#include "pygecko.h"
|
||||
|
||||
/* our retain data */
|
||||
ReducedCosAppXmlInfo cosAppXmlInfoStruct;
|
||||
/*
|
||||
* This function is a kernel hook function. It is called directly from kernel code at position 0xFFF18558.
|
||||
*/
|
||||
void my_PrepareTitle(CosAppXmlInfo *xmlKernelInfo)
|
||||
{
|
||||
/**
|
||||
* DBAT for access to our data region is setup at this point for the 0xC0000000 area.
|
||||
*/
|
||||
|
||||
//! Copy all data from the XML info
|
||||
strncpy(cosAppXmlInfoStruct.rpx_name, xmlKernelInfo->rpx_name, FS_MAX_ENTNAME_SIZE);
|
||||
|
||||
cosAppXmlInfoStruct.version_cos_xml = xmlKernelInfo->version_cos_xml;
|
||||
cosAppXmlInfoStruct.os_version = xmlKernelInfo->os_version;
|
||||
cosAppXmlInfoStruct.title_id = xmlKernelInfo->title_id;
|
||||
cosAppXmlInfoStruct.app_type = xmlKernelInfo->app_type;
|
||||
cosAppXmlInfoStruct.cmdFlags = xmlKernelInfo->cmdFlags;
|
||||
cosAppXmlInfoStruct.max_size = xmlKernelInfo->max_size;
|
||||
cosAppXmlInfoStruct.avail_size = xmlKernelInfo->avail_size;
|
||||
cosAppXmlInfoStruct.codegen_size = xmlKernelInfo->codegen_size;
|
||||
cosAppXmlInfoStruct.codegen_core = xmlKernelInfo->codegen_core;
|
||||
cosAppXmlInfoStruct.max_codesize = xmlKernelInfo->max_codesize;
|
||||
cosAppXmlInfoStruct.overlay_arena = xmlKernelInfo->overlay_arena;
|
||||
cosAppXmlInfoStruct.default_stack0_size = xmlKernelInfo->default_stack0_size;
|
||||
cosAppXmlInfoStruct.default_stack1_size = xmlKernelInfo->default_stack1_size;
|
||||
cosAppXmlInfoStruct.default_stack2_size = xmlKernelInfo->default_stack2_size;
|
||||
cosAppXmlInfoStruct.default_redzone0_size = xmlKernelInfo->default_redzone0_size;
|
||||
cosAppXmlInfoStruct.default_redzone1_size = xmlKernelInfo->default_redzone1_size;
|
||||
cosAppXmlInfoStruct.default_redzone2_size = xmlKernelInfo->default_redzone2_size;
|
||||
cosAppXmlInfoStruct.exception_stack0_size = xmlKernelInfo->exception_stack0_size;
|
||||
cosAppXmlInfoStruct.exception_stack1_size = xmlKernelInfo->exception_stack1_size;
|
||||
cosAppXmlInfoStruct.exception_stack2_size = xmlKernelInfo->exception_stack2_size;
|
||||
cosAppXmlInfoStruct.sdk_version = xmlKernelInfo->sdk_version;
|
||||
cosAppXmlInfoStruct.title_version = xmlKernelInfo->title_version;
|
||||
|
||||
// on title switch reset the dumper
|
||||
//ResetDumper();
|
||||
}
|
||||
|
||||
void SetupKernelCallback(void)
|
||||
{
|
||||
KernelSetupSyscalls();
|
||||
}
|
||||
|
||||
void KernelSetDBATs(bat_table_t * table)
|
||||
{
|
||||
SC0x36_KernelReadDBATs(table);
|
||||
bat_table_t bat_table_copy = *table;
|
||||
|
||||
// try to use a free slot
|
||||
int iUse;
|
||||
for(iUse = 0; iUse < 7; iUse++)
|
||||
{
|
||||
// skip position 5 as it is our main DBAT for our code data
|
||||
if(iUse == 5)
|
||||
continue;
|
||||
|
||||
if(bat_table_copy.bat[iUse].h == 0 || bat_table_copy.bat[iUse].l == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bat_table_copy.bat[iUse].h = 0xC0001FFF;
|
||||
bat_table_copy.bat[iUse].l = 0x30000012;
|
||||
SC0x37_KernelWriteDBATs(&bat_table_copy);
|
||||
}
|
||||
|
||||
void KernelRestoreDBATs(bat_table_t * table)
|
||||
{
|
||||
SC0x37_KernelWriteDBATs(table);
|
||||
}
|
22
src/kernel/kernel_functions.h
Normal file
22
src/kernel/kernel_functions.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef __KERNEL_FUNCTIONS_H_
|
||||
#define __KERNEL_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common/kernel_defs.h"
|
||||
#include "syscalls.h"
|
||||
|
||||
extern ReducedCosAppXmlInfo cosAppXmlInfoStruct;
|
||||
|
||||
void SetupKernelCallback(void);
|
||||
|
||||
void KernelSetDBATs(bat_table_t * table);
|
||||
void KernelRestoreDBATs(bat_table_t * table);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __KERNEL_FUNCTIONS_H_
|
174
src/kernel/kernel_hooks.S
Normal file
174
src/kernel/kernel_hooks.S
Normal file
@ -0,0 +1,174 @@
|
||||
# This stuff may need a change in different kernel versions
|
||||
# This is only needed when launched directly through browser and not SD card.
|
||||
|
||||
.section ".kernel_code"
|
||||
.globl SaveAndResetDataBATs_And_SRs_hook
|
||||
SaveAndResetDataBATs_And_SRs_hook:
|
||||
# setup CTR to the position we need to return to
|
||||
mflr r5
|
||||
mtctr r5
|
||||
# set link register to its original value
|
||||
mtlr r7
|
||||
# setup us a nice DBAT for our code data with same region as our code
|
||||
mfspr r5, 560
|
||||
mtspr 570, r5
|
||||
mfspr r5, 561
|
||||
mtspr 571, r5
|
||||
# restore the original kernel instructions that we replaced
|
||||
lwz r5, 0x34(r3)
|
||||
lwz r6, 0x38(r3)
|
||||
lwz r7, 0x3C(r3)
|
||||
lwz r8, 0x40(r3)
|
||||
lwz r9, 0x44(r3)
|
||||
lwz r10, 0x48(r3)
|
||||
lwz r11, 0x4C(r3)
|
||||
lwz r3, 0x50(r3)
|
||||
isync
|
||||
mtsr 7, r5
|
||||
# jump back to the position in kernel after our patch (from LR)
|
||||
bctr
|
||||
|
||||
.extern my_PrepareTitle
|
||||
.globl my_PrepareTitle_hook
|
||||
my_PrepareTitle_hook:
|
||||
# store all registers on stack to avoid issues with the call to C functions
|
||||
stwu r1, -0x90(r1)
|
||||
# registers for our own usage
|
||||
# only need r31 and rest is from tests before, just leaving it for later tests
|
||||
stw r28, 0x20(r1)
|
||||
stw r29, 0x24(r1)
|
||||
stw r30, 0x28(r1)
|
||||
stw r31, 0x2C(r1)
|
||||
|
||||
stw r3, 0x30(r1)
|
||||
stw r4, 0x34(r1)
|
||||
stw r5, 0x38(r1)
|
||||
stw r6, 0x3C(r1)
|
||||
stw r7, 0x40(r1)
|
||||
stw r8, 0x44(r1)
|
||||
stw r9, 0x48(r1)
|
||||
stw r10, 0x4C(r1)
|
||||
stw r11, 0x50(r1)
|
||||
stw r12, 0x54(r1)
|
||||
stw r13, 0x58(r1)
|
||||
stw r14, 0x5C(r1)
|
||||
stw r15, 0x60(r1)
|
||||
stw r16, 0x64(r1)
|
||||
stw r17, 0x68(r1)
|
||||
stw r18, 0x6C(r1)
|
||||
stw r19, 0x70(r1)
|
||||
stw r20, 0x74(r1)
|
||||
stw r21, 0x78(r1)
|
||||
stw r22, 0x7C(r1)
|
||||
|
||||
# save original DBAT registers
|
||||
mfdbatu r28, 0
|
||||
mfdbatl r29, 0
|
||||
|
||||
# setup access to our data memory range
|
||||
lis r3, 0xC000
|
||||
ori r3, r3, 0x1FFF
|
||||
mtdbatu 0, r3
|
||||
lis r3, 0x3000
|
||||
ori r3, r3, 0x0012
|
||||
mtdbatl 0, r3
|
||||
|
||||
# memory barrier
|
||||
eieio
|
||||
isync
|
||||
|
||||
# save the LR from where we came
|
||||
mflr r31
|
||||
|
||||
# the cos.xml/app.xml structure is at the location 0x68 of r11
|
||||
# there are actually many places that can be hooked for it
|
||||
# e.g. 0xFFF16130 and r27 points to this structure
|
||||
addi r3, r11, 0x68
|
||||
|
||||
bl my_PrepareTitle
|
||||
|
||||
# restore original DBAT registers
|
||||
mtdbatu 0, r28
|
||||
mtdbatl 0, r29
|
||||
|
||||
# memory barrier
|
||||
eieio
|
||||
isync
|
||||
|
||||
# setup LR to jump back to kernel code
|
||||
mtlr r31
|
||||
|
||||
# restore all original values of registers from stack
|
||||
lwz r28, 0x20(r1)
|
||||
lwz r29, 0x24(r1)
|
||||
lwz r30, 0x28(r1)
|
||||
lwz r31, 0x2C(r1)
|
||||
|
||||
lwz r3, 0x30(r1)
|
||||
lwz r4, 0x34(r1)
|
||||
lwz r5, 0x38(r1)
|
||||
lwz r6, 0x3C(r1)
|
||||
lwz r7, 0x40(r1)
|
||||
lwz r8, 0x44(r1)
|
||||
lwz r9, 0x48(r1)
|
||||
lwz r10, 0x4C(r1)
|
||||
lwz r11, 0x50(r1)
|
||||
lwz r12, 0x54(r1)
|
||||
lwz r13, 0x58(r1)
|
||||
lwz r14, 0x5C(r1)
|
||||
lwz r15, 0x60(r1)
|
||||
lwz r16, 0x64(r1)
|
||||
lwz r17, 0x68(r1)
|
||||
lwz r18, 0x6C(r1)
|
||||
lwz r19, 0x70(r1)
|
||||
lwz r20, 0x74(r1)
|
||||
lwz r21, 0x78(r1)
|
||||
lwz r22, 0x7C(r1)
|
||||
|
||||
# restore the stack
|
||||
addi r1, r1, 0x90
|
||||
|
||||
# restore original instruction that we replaced in the kernel
|
||||
clrlwi r7, r12, 0
|
||||
|
||||
# jump back
|
||||
blr
|
||||
|
||||
.globl injectBAT
|
||||
injectBAT:
|
||||
#Set dbat6u
|
||||
#lis r3, 0x000000FF@h
|
||||
#ori r3, r3, 0x000000FF@l
|
||||
#mtspr 1, r3
|
||||
#set dbat6l
|
||||
#lis r3, 0x30000012@h
|
||||
#ori r3, r3, 0x30000012@l
|
||||
#mtspr 2, r3
|
||||
#Set ibat6u
|
||||
#lis r3, 0x000000FF@h
|
||||
#ori r3, r3, 0x000000FF@l
|
||||
#mtspr 3, r3
|
||||
#set ibat6l
|
||||
lis r3, 0x2ff09C00@h
|
||||
ori r3, r3, 0x2ff09C00@l
|
||||
mtspr 4, r3
|
||||
rfi
|
||||
|
||||
.globl RunSyscall36
|
||||
RunSyscall36:
|
||||
mflr r0
|
||||
stwu r1, -0x10(r1)
|
||||
stw r30, 0x4(r1)
|
||||
stw r31, 0x8(r1)
|
||||
mr r5, r0
|
||||
mr r6, r1
|
||||
li r0, 0x3600
|
||||
sc
|
||||
nop
|
||||
mr r0, r5
|
||||
mr r1, r6
|
||||
lwz r30, 0x04(r1)
|
||||
lwz r31, 0x08(r1)
|
||||
addi r1, r1, 0x10
|
||||
mtlr r0
|
||||
blr
|
255
src/kernel/syscalls.c
Normal file
255
src/kernel/syscalls.c
Normal file
@ -0,0 +1,255 @@
|
||||
#include "common/os_defs.h"
|
||||
#include "common/kernel_defs.h"
|
||||
#include "common/common.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "utils/utils.h"
|
||||
#include "syscalls.h"
|
||||
|
||||
extern void my_PrepareTitle_hook(void);
|
||||
|
||||
static unsigned int origPrepareTitleInstr = 0;
|
||||
|
||||
static void KernelCopyData(unsigned int addr, unsigned int src, unsigned int len)
|
||||
{
|
||||
/*
|
||||
* Setup a DBAT access with cache inhibited to write through and read directly from memory
|
||||
*/
|
||||
unsigned int dbatu0, dbatl0, dbatu1, dbatl1;
|
||||
// save the original DBAT value
|
||||
asm volatile("mfdbatu %0, 0" : "=r" (dbatu0));
|
||||
asm volatile("mfdbatl %0, 0" : "=r" (dbatl0));
|
||||
asm volatile("mfdbatu %0, 1" : "=r" (dbatu1));
|
||||
asm volatile("mfdbatl %0, 1" : "=r" (dbatl1));
|
||||
|
||||
unsigned int target_dbatu0 = 0;
|
||||
unsigned int target_dbatl0 = 0;
|
||||
unsigned int target_dbatu1 = 0;
|
||||
unsigned int target_dbatl1 = 0;
|
||||
|
||||
unsigned char *dst_p = (unsigned char*)addr;
|
||||
unsigned char *src_p = (unsigned char*)src;
|
||||
|
||||
// we only need DBAT modification for addresses out of our own DBAT range
|
||||
// as our own DBAT is available everywhere for user and supervisor
|
||||
// since our own DBAT is on DBAT5 position we don't collide here
|
||||
if(addr < 0x00800000 || addr >= 0x01000000)
|
||||
{
|
||||
target_dbatu0 = (addr & 0x00F00000) | 0xC0000000 | 0x1F;
|
||||
target_dbatl0 = (addr & 0xFFF00000) | 0x32;
|
||||
asm volatile("mtdbatu 0, %0" : : "r" (target_dbatu0));
|
||||
asm volatile("mtdbatl 0, %0" : : "r" (target_dbatl0));
|
||||
dst_p = (unsigned char*)((addr & 0xFFFFFF) | 0xC0000000);
|
||||
}
|
||||
if(src < 0x00800000 || src >= 0x01000000)
|
||||
{
|
||||
target_dbatu1 = (src & 0x00F00000) | 0xB0000000 | 0x1F;
|
||||
target_dbatl1 = (src & 0xFFF00000) | 0x32;
|
||||
|
||||
asm volatile("mtdbatu 1, %0" : : "r" (target_dbatu1));
|
||||
asm volatile("mtdbatl 1, %0" : : "r" (target_dbatl1));
|
||||
src_p = (unsigned char*)((src & 0xFFFFFF) | 0xB0000000);
|
||||
}
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
|
||||
unsigned int i;
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
// if we are on the edge to next chunk
|
||||
if((target_dbatu0 != 0) && (((unsigned int)dst_p & 0x00F00000) != (target_dbatu0 & 0x00F00000)))
|
||||
{
|
||||
target_dbatu0 = ((addr + i) & 0x00F00000) | 0xC0000000 | 0x1F;
|
||||
target_dbatl0 = ((addr + i) & 0xFFF00000) | 0x32;
|
||||
dst_p = (unsigned char*)(((addr + i) & 0xFFFFFF) | 0xC0000000);
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
asm volatile("mtdbatu 0, %0" : : "r" (target_dbatu0));
|
||||
asm volatile("mtdbatl 0, %0" : : "r" (target_dbatl0));
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
if((target_dbatu1 != 0) && (((unsigned int)src_p & 0x00F00000) != (target_dbatu1 & 0x00F00000)))
|
||||
{
|
||||
target_dbatu1 = ((src + i) & 0x00F00000) | 0xB0000000 | 0x1F;
|
||||
target_dbatl1 = ((src + i) & 0xFFF00000) | 0x32;
|
||||
src_p = (unsigned char*)(((src + i) & 0xFFFFFF) | 0xB0000000);
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
asm volatile("mtdbatu 1, %0" : : "r" (target_dbatu1));
|
||||
asm volatile("mtdbatl 1, %0" : : "r" (target_dbatl1));
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
|
||||
*dst_p = *src_p;
|
||||
|
||||
++dst_p;
|
||||
++src_p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore original DBAT value
|
||||
*/
|
||||
asm volatile("eieio; isync");
|
||||
asm volatile("mtdbatu 0, %0" : : "r" (dbatu0));
|
||||
asm volatile("mtdbatl 0, %0" : : "r" (dbatl0));
|
||||
asm volatile("mtdbatu 1, %0" : : "r" (dbatu1));
|
||||
asm volatile("mtdbatl 1, %0" : : "r" (dbatl1));
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
|
||||
static void KernelReadDBATs(bat_table_t * table)
|
||||
{
|
||||
u32 i = 0;
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
|
||||
asm volatile("mfspr %0, 536" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 537" : "=r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mfspr %0, 538" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 539" : "=r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mfspr %0, 540" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 541" : "=r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mfspr %0, 542" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 543" : "=r" (table->bat[i].l));
|
||||
i++;
|
||||
|
||||
asm volatile("mfspr %0, 568" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 569" : "=r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mfspr %0, 570" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 571" : "=r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mfspr %0, 572" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 573" : "=r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mfspr %0, 574" : "=r" (table->bat[i].h));
|
||||
asm volatile("mfspr %0, 575" : "=r" (table->bat[i].l));
|
||||
}
|
||||
|
||||
static void KernelWriteDBATs(bat_table_t * table)
|
||||
{
|
||||
u32 i = 0;
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
|
||||
asm volatile("mtspr 536, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 537, %0" : : "r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mtspr 538, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 539, %0" : : "r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mtspr 540, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 541, %0" : : "r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mtspr 542, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 543, %0" : : "r" (table->bat[i].l));
|
||||
i++;
|
||||
|
||||
asm volatile("mtspr 568, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 569, %0" : : "r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mtspr 570, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 571, %0" : : "r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mtspr 572, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 573, %0" : : "r" (table->bat[i].l));
|
||||
i++;
|
||||
asm volatile("mtspr 574, %0" : : "r" (table->bat[i].h));
|
||||
asm volatile("mtspr 575, %0" : : "r" (table->bat[i].l));
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
|
||||
/* Read a 32-bit word with kernel permissions */
|
||||
uint32_t __attribute__ ((noinline)) kern_read(const void *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
asm volatile (
|
||||
"li 3,1\n"
|
||||
"li 4,0\n"
|
||||
"li 5,0\n"
|
||||
"li 6,0\n"
|
||||
"li 7,0\n"
|
||||
"lis 8,1\n"
|
||||
"mr 9,%1\n"
|
||||
"li 0,0x3400\n"
|
||||
"mr %0,1\n"
|
||||
"sc\n"
|
||||
"nop\n"
|
||||
"mr 1,%0\n"
|
||||
"mr %0,3\n"
|
||||
: "=r"(result)
|
||||
: "b"(addr)
|
||||
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||
"11", "12"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Write a 32-bit word with kernel permissions */
|
||||
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value)
|
||||
{
|
||||
asm volatile (
|
||||
"li 3,1\n"
|
||||
"li 4,0\n"
|
||||
"mr 5,%1\n"
|
||||
"li 6,0\n"
|
||||
"li 7,0\n"
|
||||
"lis 8,1\n"
|
||||
"mr 9,%0\n"
|
||||
"mr %1,1\n"
|
||||
"li 0,0x3500\n"
|
||||
"sc\n"
|
||||
"nop\n"
|
||||
"mr 1,%1\n"
|
||||
:
|
||||
: "r"(addr), "r"(value)
|
||||
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||
"11", "12"
|
||||
);
|
||||
}
|
||||
|
||||
void KernelSetupSyscalls(void)
|
||||
{
|
||||
//! assign 1 so that this variable gets into the retained .data section
|
||||
static uint8_t ucSyscallsSetupRequired = 1;
|
||||
if(!ucSyscallsSetupRequired)
|
||||
return;
|
||||
|
||||
ucSyscallsSetupRequired = 0;
|
||||
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl1 + (0x36 * 4)), (unsigned int)KernelReadDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl2 + (0x36 * 4)), (unsigned int)KernelReadDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl3 + (0x36 * 4)), (unsigned int)KernelReadDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl4 + (0x36 * 4)), (unsigned int)KernelReadDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl5 + (0x36 * 4)), (unsigned int)KernelReadDBATs);
|
||||
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl1 + (0x37 * 4)), (unsigned int)KernelWriteDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl2 + (0x37 * 4)), (unsigned int)KernelWriteDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl3 + (0x37 * 4)), (unsigned int)KernelWriteDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl4 + (0x37 * 4)), (unsigned int)KernelWriteDBATs);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl5 + (0x37 * 4)), (unsigned int)KernelWriteDBATs);
|
||||
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl1 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl2 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl3 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl4 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl5 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
|
||||
//! write our hook to the
|
||||
u32 addr_my_PrepareTitle_hook = ((u32)my_PrepareTitle_hook) | 0x48000003;
|
||||
DCFlushRange(&addr_my_PrepareTitle_hook, sizeof(addr_my_PrepareTitle_hook));
|
||||
|
||||
SC0x25_KernelCopyData((u32)&origPrepareTitleInstr, (u32)addr_PrepareTitle_hook, 4);
|
||||
SC0x25_KernelCopyData((u32)addr_PrepareTitle_hook, (u32)OSEffectiveToPhysical(&addr_my_PrepareTitle_hook), 4);
|
||||
}
|
||||
|
||||
|
||||
void KernelRestoreInstructions(void)
|
||||
{
|
||||
if(origPrepareTitleInstr != 0)
|
||||
SC0x25_KernelCopyData((u32)addr_PrepareTitle_hook, (u32)&origPrepareTitleInstr, 4);
|
||||
}
|
25
src/kernel/syscalls.h
Normal file
25
src/kernel/syscalls.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __SYSCALLS_H_
|
||||
#define __SYSCALLS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
#include "common/kernel_defs.h"
|
||||
|
||||
void KernelSetupSyscalls(void);
|
||||
void KernelRestoreInstructions(void);
|
||||
|
||||
void SC0x25_KernelCopyData(unsigned int addr, unsigned int src, unsigned int len);
|
||||
void SC0x36_KernelReadDBATs(bat_table_t * table);
|
||||
void SC0x37_KernelWriteDBATs(bat_table_t * table);
|
||||
|
||||
uint32_t __attribute__ ((noinline)) kern_read(const void *addr);
|
||||
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __KERNEL_FUNCTIONS_H_
|
19
src/kernel/syscalls_asm.S
Normal file
19
src/kernel/syscalls_asm.S
Normal file
@ -0,0 +1,19 @@
|
||||
# Syscalls for kernel that we use
|
||||
|
||||
.globl SC0x36_KernelReadDBATs
|
||||
SC0x36_KernelReadDBATs:
|
||||
li r0, 0x3600
|
||||
sc
|
||||
blr
|
||||
|
||||
.globl SC0x37_KernelWriteDBATs
|
||||
SC0x37_KernelWriteDBATs:
|
||||
li r0, 0x3700
|
||||
sc
|
||||
blr
|
||||
|
||||
.globl SC0x25_KernelCopyData
|
||||
SC0x25_KernelCopyData:
|
||||
li r0, 0x2500
|
||||
sc
|
||||
blr
|
43
src/link.ld
Normal file
43
src/link.ld
Normal file
@ -0,0 +1,43 @@
|
||||
OUTPUT(tcpgecko.elf);
|
||||
|
||||
/* Tell linker where our application entry is so the garbage collect can work correct */
|
||||
ENTRY(__entry_menu);
|
||||
|
||||
SECTIONS {
|
||||
. = 0x00802000;
|
||||
.text : {
|
||||
*(.kernel_code*);
|
||||
*(.text*);
|
||||
/* Tell linker to not garbage collect this section as it is not referenced anywhere */
|
||||
KEEP(*(.kernel_code*));
|
||||
}
|
||||
.rodata : {
|
||||
*(.rodata*);
|
||||
}
|
||||
.data : {
|
||||
*(.data*);
|
||||
|
||||
__sdata_start = .;
|
||||
*(.sdata*);
|
||||
__sdata_end = .;
|
||||
|
||||
__sdata2_start = .;
|
||||
*(.sdata2*);
|
||||
__sdata2_end = .;
|
||||
}
|
||||
.bss : {
|
||||
__bss_start = .;
|
||||
*(.bss*);
|
||||
*(.sbss*);
|
||||
*(COMMON);
|
||||
__bss_end = .;
|
||||
}
|
||||
__CODE_END = .;
|
||||
|
||||
/DISCARD/ : {
|
||||
*(*);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************** FS ********************************************************/
|
||||
/* coreinit.rpl difference in addresses 0xFE3C00 */
|
222
src/main.c
Normal file
222
src/main.c
Normal file
@ -0,0 +1,222 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "dynamic_libs/fs_functions.h"
|
||||
#include "dynamic_libs/sys_functions.h"
|
||||
#include "dynamic_libs/vpad_functions.h"
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "patcher/function_hooks.h"
|
||||
#include "fs/fs_utils.h"
|
||||
#include "fs/sd_fat_devoptab.h"
|
||||
#include "kernel/kernel_functions.h"
|
||||
#include "system/memory.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/utils.h"
|
||||
#include "common/common.h"
|
||||
|
||||
#define FS_BUFFER_SIZE 40000
|
||||
|
||||
int CCHandler;
|
||||
|
||||
void startMiiMaker() {
|
||||
char buf_vol_odd[20];
|
||||
snprintf(buf_vol_odd, sizeof(buf_vol_odd), "%s", "/vol/storage_odd03");
|
||||
_SYSLaunchTitleByPathFromLauncher(buf_vol_odd, 18, 0);
|
||||
}
|
||||
|
||||
char *buffer[FS_BUFFER_SIZE];
|
||||
|
||||
#define PRINT_TEXT2(x, y, ...) { snprintf(msg, 80, __VA_ARGS__); OSScreenPutFontEx(0, x, y, msg); OSScreenPutFontEx(1, x, y, msg); }
|
||||
|
||||
/* Entry point */
|
||||
int Menu_Main(void) {
|
||||
//!*******************************************************************
|
||||
//! Initialize function pointers *
|
||||
//!*******************************************************************
|
||||
//! do OS (for acquire) and sockets first so we got logging
|
||||
InitOSFunctionPointers();
|
||||
InitSocketFunctionPointers();
|
||||
InitFSFunctionPointers();
|
||||
InitVPadFunctionPointers();
|
||||
InitSysFunctionPointers();
|
||||
|
||||
const char ip_address[100] = "192.168.178.49";
|
||||
log_init(ip_address);
|
||||
log_deinit();
|
||||
log_init(ip_address);
|
||||
log_printf("Started %s\n", cosAppXmlInfoStruct.rpx_name);
|
||||
|
||||
if (strcasecmp("men.rpx", cosAppXmlInfoStruct.rpx_name) == 0) {
|
||||
return EXIT_RELAUNCH_ON_LOAD;
|
||||
} else if (strlen(cosAppXmlInfoStruct.rpx_name) > 0 &&
|
||||
strcasecmp("ffl_app.rpx", cosAppXmlInfoStruct.rpx_name) != 0) {
|
||||
|
||||
return EXIT_RELAUNCH_ON_LOAD;
|
||||
}
|
||||
|
||||
//! *******************************************************************
|
||||
//! * Setup EABI registers *
|
||||
//! *******************************************************************
|
||||
register int old_sdata_start, old_sdata2_start;
|
||||
asm volatile (
|
||||
"mr %0, 13\n"
|
||||
"mr %1, 2\n"
|
||||
"lis 2, __sdata2_start@h\n"
|
||||
"ori 2, 2,__sdata2_start@l\n" // Set the Small Data 2 (Read Only) base register.
|
||||
"lis 13, __sdata_start@h\n"
|
||||
"ori 13, 13, __sdata_start@l\n"// # Set the Small Data (Read\Write) base register.
|
||||
: "=r" (old_sdata_start), "=r" (old_sdata2_start)
|
||||
);
|
||||
|
||||
//!*******************************************************************
|
||||
//! Initialize BSS sections *
|
||||
//!*******************************************************************
|
||||
asm volatile (
|
||||
"lis 3, __bss_start@h\n"
|
||||
"ori 3, 3,__bss_start@l\n"
|
||||
"lis 5, __bss_end@h\n"
|
||||
"ori 5, 5, __bss_end@l\n"
|
||||
"subf 5, 3, 5\n"
|
||||
"li 4, 0\n"
|
||||
"bl memset\n"
|
||||
);
|
||||
|
||||
SetupKernelCallback();
|
||||
PatchMethodHooks();
|
||||
|
||||
memoryInitialize();
|
||||
|
||||
VPADInit();
|
||||
|
||||
// Prepare screen
|
||||
int screen_buf0_size = 0;
|
||||
int screen_buf1_size = 0;
|
||||
|
||||
// Init screen and screen buffers
|
||||
OSScreenInit();
|
||||
screen_buf0_size = OSScreenGetBufferSizeEx(0);
|
||||
screen_buf1_size = OSScreenGetBufferSizeEx(1);
|
||||
|
||||
unsigned char *screenBuffer = MEM1_alloc(screen_buf0_size + screen_buf1_size, 0x40);
|
||||
|
||||
OSScreenSetBufferEx(0, screenBuffer);
|
||||
OSScreenSetBufferEx(1, (screenBuffer + screen_buf0_size));
|
||||
|
||||
OSScreenEnableEx(0, 1);
|
||||
OSScreenEnableEx(1, 1);
|
||||
|
||||
char msg[80];
|
||||
int launchMethod = 0;
|
||||
int update_screen = 1;
|
||||
int vpadError = -1;
|
||||
VPADData vpad_data;
|
||||
|
||||
while (1) {
|
||||
// Read vpad
|
||||
VPADRead(0, &vpad_data, 1, &vpadError);
|
||||
|
||||
if (update_screen) {
|
||||
OSScreenClearBufferEx(0, 0);
|
||||
OSScreenClearBufferEx(1, 0);
|
||||
|
||||
// Print message
|
||||
PRINT_TEXT2(14, 1, "-- TCPGecko Installer --");
|
||||
PRINT_TEXT2(0, 5, "Press A to install TCPGecko.");
|
||||
PRINT_TEXT2(0, 6, "Press X to install TCPGecko with CosmoCortney's codehandler...");
|
||||
|
||||
|
||||
PRINT_TEXT2(0, 17, "Press home button to exit ...");
|
||||
|
||||
|
||||
OSScreenFlipBuffersEx(0);
|
||||
OSScreenFlipBuffersEx(1);
|
||||
}
|
||||
|
||||
u32 pressedButtons = vpad_data.btns_d | vpad_data.btns_h;
|
||||
|
||||
// Home Button
|
||||
if (pressedButtons & VPAD_BUTTON_HOME) {
|
||||
launchMethod = 0;
|
||||
break;
|
||||
}
|
||||
// A Button
|
||||
if (pressedButtons & VPAD_BUTTON_A) {
|
||||
launchMethod = 2;
|
||||
break;
|
||||
}
|
||||
// X Button
|
||||
if (pressedButtons & VPAD_BUTTON_X) {
|
||||
mount_sd_fat("sd");
|
||||
|
||||
unsigned char *Badbuffer = 0;
|
||||
unsigned int filesize = 0;
|
||||
int ret = LoadFileToMem("sd:/wiiu/apps/TCPGecko/codehandler.bin", &Badbuffer, &filesize);
|
||||
if (ret == -1) {
|
||||
OSScreenClearBufferEx(0, 0);
|
||||
OSScreenClearBufferEx(1, 0);
|
||||
PRINT_TEXT2(14, 5, "Codehandler.bin not found");
|
||||
OSScreenFlipBuffersEx(0);
|
||||
OSScreenFlipBuffersEx(1);
|
||||
launchMethod = 0;
|
||||
sleep(2);
|
||||
break;
|
||||
}
|
||||
if (filesize > FS_BUFFER_SIZE) {
|
||||
OSScreenClearBufferEx(0, 0);
|
||||
OSScreenClearBufferEx(1, 0);
|
||||
PRINT_TEXT2(14, 5, "Codehandler.bin is too big");
|
||||
OSScreenFlipBuffersEx(0);
|
||||
OSScreenFlipBuffersEx(1);
|
||||
launchMethod = 0;
|
||||
sleep(2);
|
||||
break;
|
||||
}
|
||||
memcpy(buffer, Badbuffer, filesize);
|
||||
free(Badbuffer);
|
||||
|
||||
unsigned int phys_cafe_codehandler_loc = (unsigned int) OSEffectiveToPhysical((void *) CODE_HANDLER_INSTALL_ADDRESS);
|
||||
|
||||
DCFlushRange(&buffer, filesize);
|
||||
SC0x25_KernelCopyData((u32) phys_cafe_codehandler_loc, (int) buffer, filesize);
|
||||
m_DCInvalidateRange((u32) phys_cafe_codehandler_loc, filesize);
|
||||
|
||||
unmount_sd_fat("sd");
|
||||
CCHandler = 1;
|
||||
|
||||
launchMethod = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// Button pressed ?
|
||||
update_screen = (pressedButtons & (VPAD_BUTTON_LEFT | VPAD_BUTTON_RIGHT | VPAD_BUTTON_UP | VPAD_BUTTON_DOWN))
|
||||
? 1 : 0;
|
||||
usleep(20 * 1000);
|
||||
}
|
||||
|
||||
asm volatile ("mr 13, %0" : : "r" (old_sdata_start));
|
||||
asm volatile ("mr 2, %0" : : "r" (old_sdata2_start));
|
||||
|
||||
MEM1_free(screenBuffer);
|
||||
screenBuffer = NULL;
|
||||
|
||||
log_deinit();
|
||||
|
||||
memoryRelease();
|
||||
|
||||
if (launchMethod == 0) {
|
||||
RestoreInstructions();
|
||||
return EXIT_SUCCESS;
|
||||
} else if (launchMethod == 1) {
|
||||
startMiiMaker();
|
||||
} else {
|
||||
SYSLaunchMenu();
|
||||
}
|
||||
|
||||
return EXIT_RELAUNCH_ON_LOAD;
|
||||
}
|
22
src/main.h
Normal file
22
src/main.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef _MAIN_H_
|
||||
#define _MAIN_H_
|
||||
|
||||
#include "common/types.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
|
||||
/* Main */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! C wrapper for our C++ functions
|
||||
int Menu_Main(void);
|
||||
|
||||
extern int pygecko;
|
||||
extern int CCHandler;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
154
src/patcher/fs_logger.c
Normal file
154
src/patcher/fs_logger.c
Normal file
@ -0,0 +1,154 @@
|
||||
#include <malloc.h>
|
||||
#include "common/common.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "function_hooks.h"
|
||||
#include "fs_logger.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#define CHECK_ERROR(cond) if (cond) { goto error; }
|
||||
|
||||
#define bss_ptr (*(struct bss_t **)0x100000e4)
|
||||
#define MAX_CLIENT 32
|
||||
#define MASK_FD 0x0fff00ff
|
||||
|
||||
struct bss_t {
|
||||
int global_sock;
|
||||
int socket_fs[MAX_CLIENT];
|
||||
void *pClient_fs[MAX_CLIENT];
|
||||
volatile int lock;
|
||||
char mount_base[255];
|
||||
char save_base[255];
|
||||
void* file_replacer;
|
||||
char update_path[50];
|
||||
char save_dir_common[7];
|
||||
char save_dir_user[9];
|
||||
};
|
||||
|
||||
#define bss (*bss_ptr)
|
||||
|
||||
|
||||
static int sendwait(int sock, const unsigned char *buffer, int len) {
|
||||
while (bss.lock)
|
||||
usleep(5000);
|
||||
bss.lock = 1;
|
||||
|
||||
int ret;
|
||||
while (len > 0) {
|
||||
ret = send(sock, buffer, len, 0);
|
||||
if(ret < 0)
|
||||
{
|
||||
len = ret;
|
||||
break;
|
||||
}
|
||||
|
||||
len -= ret;
|
||||
buffer += ret;
|
||||
}
|
||||
bss.lock = 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int fs_logger_connect(int *psock) {
|
||||
struct sockaddr_in addr;
|
||||
int sock, ret;
|
||||
socket_lib_init();
|
||||
|
||||
//if (OSGetTitleID() == 0x000500001010ED00)
|
||||
//OSFatal("hi");
|
||||
|
||||
// No ip means that we don't have any server running, so no logs
|
||||
if (0 == 0) {
|
||||
*psock = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = 7332;
|
||||
addr.sin_addr.s_addr = 0;
|
||||
|
||||
ret = connect(sock, (void *)&addr, sizeof(addr));
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
int enable = 1;
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&enable, sizeof(enable));
|
||||
|
||||
unsigned char buffer[2];
|
||||
ret = recv(sock, buffer, 1, 0);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
*psock = sock;
|
||||
|
||||
bss.lock = 0;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (sock != -1)
|
||||
socketclose(sock);
|
||||
|
||||
*psock = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void fs_logger_disconnect(int sock) {
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
unsigned char buffer[2];
|
||||
buffer[0] = BYTE_DISCONNECT;
|
||||
buffer[1] = 0;
|
||||
sendwait(sock, buffer, 1);
|
||||
|
||||
socketclose(sock);
|
||||
error:
|
||||
return;
|
||||
}
|
||||
|
||||
void fs_log_string(int sock, const char* str, unsigned char flag_byte) {
|
||||
if(sock == -1) {
|
||||
return;
|
||||
}
|
||||
int i;
|
||||
int len_str = 0;
|
||||
while (str[len_str])
|
||||
len_str++;
|
||||
|
||||
//
|
||||
{
|
||||
unsigned char *buffer = memalign(0x40, ROUNDUP((1 + 4 + len_str + 1), 0x40));
|
||||
if(!buffer)
|
||||
return;
|
||||
|
||||
buffer[0] = flag_byte;
|
||||
*(int *)(buffer + 1) = len_str + 1;
|
||||
for (i = 0; i < len_str; i++)
|
||||
buffer[5 + i] = str[i];
|
||||
|
||||
buffer[5 + i] = 0;
|
||||
|
||||
sendwait(sock, buffer, 1 + 4 + len_str + 1);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void fs_log_byte(int sock, unsigned char byte) {
|
||||
if(sock != -1) {
|
||||
unsigned char *buffer = memalign(0x40, 0x40);
|
||||
if(!buffer)
|
||||
return;
|
||||
|
||||
buffer[0] = byte;
|
||||
buffer[1] = 0;
|
||||
|
||||
sendwait(sock, buffer, 1);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
}
|
75
src/patcher/fs_logger.h
Normal file
75
src/patcher/fs_logger.h
Normal file
@ -0,0 +1,75 @@
|
||||
#ifndef FS_LOGGER_H_
|
||||
#define FS_LOGGER_H_
|
||||
|
||||
/* Communication bytes with the server */
|
||||
// Com
|
||||
#define BYTE_NORMAL 0xff
|
||||
#define BYTE_SPECIAL 0xfe
|
||||
#define BYTE_OK 0xfd
|
||||
#define BYTE_PING 0xfc
|
||||
#define BYTE_LOG_STR 0xfb
|
||||
#define BYTE_DISCONNECT 0xfa
|
||||
|
||||
// SD
|
||||
#define BYTE_MOUNT_SD 0xe0
|
||||
#define BYTE_MOUNT_SD_OK 0xe1
|
||||
#define BYTE_MOUNT_SD_BAD 0xe2
|
||||
|
||||
// Replacement
|
||||
#define BYTE_STAT 0x00
|
||||
#define BYTE_STAT_ASYNC 0x01
|
||||
#define BYTE_OPEN_FILE 0x02
|
||||
#define BYTE_OPEN_FILE_ASYNC 0x03
|
||||
#define BYTE_OPEN_DIR 0x04
|
||||
#define BYTE_OPEN_DIR_ASYNC 0x05
|
||||
#define BYTE_CHANGE_DIR 0x06
|
||||
#define BYTE_CHANGE_DIR_ASYNC 0x07
|
||||
#define BYTE_MAKE_DIR 0x08
|
||||
#define BYTE_MAKE_DIR_ASYNC 0x09
|
||||
#define BYTE_RENAME 0x0A
|
||||
#define BYTE_RENAME_ASYNC 0x0B
|
||||
#define BYTE_REMOVE 0x0C
|
||||
#define BYTE_REMOVE_ASYNC 0x0D
|
||||
|
||||
// Log
|
||||
#define BYTE_CLOSE_FILE 0x40
|
||||
#define BYTE_CLOSE_FILE_ASYNC 0x41
|
||||
#define BYTE_CLOSE_DIR 0x42
|
||||
#define BYTE_CLOSE_DIR_ASYNC 0x43
|
||||
#define BYTE_FLUSH_FILE 0x44
|
||||
#define BYTE_GET_ERROR_CODE_FOR_VIEWER 0x45
|
||||
#define BYTE_GET_LAST_ERROR 0x46
|
||||
#define BYTE_GET_MOUNT_SOURCE 0x47
|
||||
#define BYTE_GET_MOUNT_SOURCE_NEXT 0x48
|
||||
#define BYTE_GET_POS_FILE 0x49
|
||||
#define BYTE_SET_POS_FILE 0x4A
|
||||
#define BYTE_GET_STAT_FILE 0x4B
|
||||
#define BYTE_EOF 0x4C
|
||||
#define BYTE_READ_FILE 0x4D
|
||||
#define BYTE_READ_FILE_ASYNC 0x4E
|
||||
#define BYTE_READ_FILE_WITH_POS 0x4F
|
||||
#define BYTE_READ_DIR 0x50
|
||||
#define BYTE_READ_DIR_ASYNC 0x51
|
||||
#define BYTE_GET_CWD 0x52
|
||||
#define BYTE_SET_STATE_CHG_NOTIF 0x53
|
||||
#define BYTE_TRUNCATE_FILE 0x54
|
||||
#define BYTE_WRITE_FILE 0x55
|
||||
#define BYTE_WRITE_FILE_WITH_POS 0x56
|
||||
|
||||
#define BYTE_SAVE_INIT 0x57
|
||||
#define BYTE_SAVE_SHUTDOWN 0x58
|
||||
#define BYTE_SAVE_INIT_SAVE_DIR 0x59
|
||||
#define BYTE_SAVE_FLUSH_QUOTA 0x5A
|
||||
#define BYTE_SAVE_OPEN_DIR 0x5B
|
||||
#define BYTE_SAVE_REMOVE 0x5C
|
||||
|
||||
#define BYTE_CREATE_THREAD 0x60
|
||||
|
||||
|
||||
int fs_logger_connect(int *socket);
|
||||
void fs_logger_disconnect(int socket);
|
||||
void fs_log_string(int sock, const char* str, unsigned char byte);
|
||||
void fs_log_byte(int sock, unsigned char byte);
|
||||
|
||||
|
||||
#endif
|
141
src/patcher/function_hooks.c
Normal file
141
src/patcher/function_hooks.c
Normal file
@ -0,0 +1,141 @@
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "../common/common.h"
|
||||
#include "../dynamic_libs/os_functions.h"
|
||||
#include "../kernel/kernel_functions.h"
|
||||
#include "function_hooks.h"
|
||||
#include "../dynamic_libs/gx2_types.h"
|
||||
|
||||
#define LIB_CODE_RW_BASE_OFFSET 0xC1000000
|
||||
#define CODE_RW_BASE_OFFSET 0x00000000
|
||||
|
||||
#define DECL(res, name, ...) \
|
||||
res (* real_ ## name)(__VA_ARGS__); \
|
||||
res my_ ## name(__VA_ARGS__)
|
||||
|
||||
/* *****************************************************************************
|
||||
* Creates function pointer array
|
||||
* ****************************************************************************/
|
||||
// #define MAKE_MAGIC(x, lib) { (unsigned int) my_ ## x, (unsigned int) &real_ ## x, lib, # x }
|
||||
|
||||
#define MAKE_MAGIC(x, lib, functionType) { (unsigned int) my_ ## x, (unsigned int) &real_ ## x, lib, # x,0,0,functionType,0}
|
||||
|
||||
DECL(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer,
|
||||
s32 scan_target) {
|
||||
// TODO Does not execute
|
||||
GX2Surface surface = colorBuffer->surface;
|
||||
u32 image_size = surface.image_size;
|
||||
char buffer[100] = {0};
|
||||
__os_snprintf(buffer, 100, "Image size: %i", image_size);
|
||||
OSFatal(buffer);
|
||||
|
||||
real_GX2CopyColorBufferToScanBuffer(colorBuffer, scan_target);
|
||||
}
|
||||
|
||||
DECL(int, FSInit, void) {
|
||||
return real_FSInit();
|
||||
}
|
||||
|
||||
DECL(int, socket_lib_finish, void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct hooks_magic_t {
|
||||
const unsigned int replaceAddr;
|
||||
const unsigned int replaceCall;
|
||||
const unsigned int library;
|
||||
const char functionName[50];
|
||||
unsigned int realAddr;
|
||||
unsigned int restoreInstruction;
|
||||
unsigned char functionType;
|
||||
unsigned char alreadyPatched;
|
||||
} method_hooks[] = {
|
||||
MAKE_MAGIC(FSInit, LIB_CORE_INIT, STATIC_FUNCTION),
|
||||
MAKE_MAGIC(socket_lib_finish, LIB_CORE_INIT, STATIC_FUNCTION),
|
||||
MAKE_MAGIC(GX2CopyColorBufferToScanBuffer, LIB_GX2, DYNAMIC_FUNCTION),
|
||||
};
|
||||
|
||||
//! buffer to store our 2 instructions needed for our replacements
|
||||
//! the code will be placed in the address of that buffer - CODE_RW_BASE_OFFSET
|
||||
//! avoid this buffer to be placed in BSS and reset on start up
|
||||
volatile unsigned int fs_method_calls[sizeof(method_hooks) / sizeof(struct hooks_magic_t) * 2];
|
||||
|
||||
void PatchMethodHooks(void) {
|
||||
restore_instructions_t *restore = RESTORE_INSTR_ADDR;
|
||||
//! check if it is already patched
|
||||
if (restore->magic == RESTORE_INSTR_MAGIC)
|
||||
return;
|
||||
|
||||
restore->magic = RESTORE_INSTR_MAGIC;
|
||||
restore->instr_count = 0;
|
||||
|
||||
bat_table_t table;
|
||||
KernelSetDBATs(&table);
|
||||
|
||||
/* Patch branches to it. */
|
||||
volatile unsigned int *space = &fs_method_calls[0];
|
||||
|
||||
int method_hooks_count = sizeof(method_hooks) / sizeof(struct hooks_magic_t);
|
||||
|
||||
for (int i = 0; i < method_hooks_count; i++) {
|
||||
unsigned int repl_addr = method_hooks[i].replaceAddr;
|
||||
unsigned int call_addr = method_hooks[i].replaceCall;
|
||||
|
||||
unsigned int real_addr = 0;
|
||||
|
||||
if (strcmp(method_hooks[i].functionName, "OSDynLoad_Acquire") == 0) {
|
||||
memcpy(&real_addr, &OSDynLoad_Acquire, 4);
|
||||
} else {
|
||||
OSDynLoad_FindExport(coreinit_handle, 0, method_hooks[i].functionName, &real_addr);
|
||||
}
|
||||
|
||||
// fill the restore instruction section
|
||||
restore->data[restore->instr_count].addr = real_addr;
|
||||
restore->data[restore->instr_count].instr = *(volatile unsigned int *) (LIB_CODE_RW_BASE_OFFSET + real_addr);
|
||||
restore->instr_count++;
|
||||
|
||||
// set pointer to the real function
|
||||
*(volatile unsigned int *) (call_addr) = (unsigned int) (space) - CODE_RW_BASE_OFFSET;
|
||||
DCFlushRange((void *) (call_addr), 4);
|
||||
|
||||
// fill the instruction of the real function
|
||||
*space = *(volatile unsigned int *) (LIB_CODE_RW_BASE_OFFSET + real_addr);
|
||||
space++;
|
||||
|
||||
// jump to real function skipping the first/replaced instruction
|
||||
*space = 0x48000002 | ((real_addr + 4) & 0x03fffffc);
|
||||
space++;
|
||||
DCFlushRange((void *) (space - 2), 8);
|
||||
ICInvalidateRange((unsigned char *) (space - 2) - CODE_RW_BASE_OFFSET, 8);
|
||||
|
||||
unsigned int replace_instr = 0x48000002 | (repl_addr & 0x03fffffc);
|
||||
*(volatile unsigned int *) (LIB_CODE_RW_BASE_OFFSET + real_addr) = replace_instr;
|
||||
DCFlushRange((void *) (LIB_CODE_RW_BASE_OFFSET + real_addr), 4);
|
||||
ICInvalidateRange((void *) (real_addr), 4);
|
||||
}
|
||||
|
||||
KernelRestoreDBATs(&table);
|
||||
}
|
||||
|
||||
/* ****************************************************************** */
|
||||
/* RESTORE ORIGINAL INSTRUCTIONS */
|
||||
/* ****************************************************************** */
|
||||
void RestoreInstructions(void) {
|
||||
bat_table_t table;
|
||||
KernelSetDBATs(&table);
|
||||
|
||||
restore_instructions_t *restore = RESTORE_INSTR_ADDR;
|
||||
if (restore->magic == RESTORE_INSTR_MAGIC) {
|
||||
for (unsigned int i = 0; i < restore->instr_count; i++) {
|
||||
*(volatile unsigned int *) (LIB_CODE_RW_BASE_OFFSET + restore->data[i].addr) = restore->data[i].instr;
|
||||
DCFlushRange((void *) (LIB_CODE_RW_BASE_OFFSET + restore->data[i].addr), (u32) 4);
|
||||
ICInvalidateRange((void *) restore->data[i].addr, (u32) 4);
|
||||
}
|
||||
}
|
||||
restore->magic = 0;
|
||||
restore->instr_count = 0;
|
||||
|
||||
KernelRestoreDBATs(&table);
|
||||
KernelRestoreInstructions();
|
||||
}
|
15
src/patcher/function_hooks.h
Normal file
15
src/patcher/function_hooks.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef _FUNCTION_HOOKS_H_
|
||||
#define _FUNCTION_HOOKS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void PatchMethodHooks(void);
|
||||
void RestoreInstructions(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FS_H */
|
1333
src/pygecko.c
Normal file
1333
src/pygecko.c
Normal file
File diff suppressed because it is too large
Load Diff
19
src/pygecko.h
Normal file
19
src/pygecko.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef _PYGECKO_H_
|
||||
#define _PYGECKO_H_
|
||||
|
||||
#include "common/types.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
|
||||
/* Main */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! C wrapper for our C++ functions
|
||||
void start_pygecko(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
169
src/system/exception_handler.c
Normal file
169
src/system/exception_handler.c
Normal file
@ -0,0 +1,169 @@
|
||||
#include <stdio.h>
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "utils/logger.h"
|
||||
#include "exception_handler.h"
|
||||
|
||||
#define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES 4
|
||||
|
||||
#define OS_EXCEPTION_DSI 2
|
||||
#define OS_EXCEPTION_ISI 3
|
||||
#define OS_EXCEPTION_PROGRAM 6
|
||||
|
||||
/* Exceptions */
|
||||
typedef struct OSContext
|
||||
{
|
||||
/* OSContext identifier */
|
||||
uint32_t tag1;
|
||||
uint32_t tag2;
|
||||
|
||||
/* GPRs */
|
||||
uint32_t gpr[32];
|
||||
|
||||
/* Special registers */
|
||||
uint32_t cr;
|
||||
uint32_t lr;
|
||||
uint32_t ctr;
|
||||
uint32_t xer;
|
||||
|
||||
/* Initial PC and MSR */
|
||||
uint32_t srr0;
|
||||
uint32_t srr1;
|
||||
|
||||
/* Only valid during DSI exception */
|
||||
uint32_t exception_specific0;
|
||||
uint32_t exception_specific1;
|
||||
|
||||
/* There is actually a lot more here but we don't need the rest*/
|
||||
} OSContext;
|
||||
|
||||
#define CPU_STACK_TRACE_DEPTH 10
|
||||
#define __stringify(rn) #rn
|
||||
|
||||
#define mfspr(_rn) \
|
||||
({ register uint32_t _rval = 0; \
|
||||
asm volatile("mfspr %0," __stringify(_rn) \
|
||||
: "=r" (_rval));\
|
||||
_rval; \
|
||||
})
|
||||
|
||||
typedef struct _framerec {
|
||||
struct _framerec *up;
|
||||
void *lr;
|
||||
} frame_rec, *frame_rec_t;
|
||||
|
||||
static const char *exception_names[] = {
|
||||
"DSI",
|
||||
"ISI",
|
||||
"PROGRAM"
|
||||
};
|
||||
|
||||
static const char exception_print_formats[18][45] = {
|
||||
"Exception type %s occurred!\n", // 0
|
||||
"GPR00 %08X GPR08 %08X GPR16 %08X GPR24 %08X\n", // 1
|
||||
"GPR01 %08X GPR09 %08X GPR17 %08X GPR25 %08X\n", // 2
|
||||
"GPR02 %08X GPR10 %08X GPR18 %08X GPR26 %08X\n", // 3
|
||||
"GPR03 %08X GPR11 %08X GPR19 %08X GPR27 %08X\n", // 4
|
||||
"GPR04 %08X GPR12 %08X GPR20 %08X GPR28 %08X\n", // 5
|
||||
"GPR05 %08X GPR13 %08X GPR21 %08X GPR29 %08X\n", // 6
|
||||
"GPR06 %08X GPR14 %08X GPR22 %08X GPR30 %08X\n", // 7
|
||||
"GPR07 %08X GPR15 %08X GPR23 %08X GPR31 %08X\n", // 8
|
||||
"LR %08X SRR0 %08x SRR1 %08x\n", // 9
|
||||
"DAR %08X DSISR %08X\n", // 10
|
||||
"\nSTACK DUMP:", // 11
|
||||
" --> ", // 12
|
||||
" -->\n", // 13
|
||||
"\n", // 14
|
||||
"%p", // 15
|
||||
"\nCODE DUMP:\n", // 16
|
||||
"%p: %08X %08X %08X %08X\n", // 17
|
||||
};
|
||||
|
||||
static unsigned char exception_cb(void * c, unsigned char exception_type) {
|
||||
char buf[850];
|
||||
int pos = 0;
|
||||
|
||||
OSContext *context = (OSContext *) c;
|
||||
/*
|
||||
* This part is mostly from libogc. Thanks to the devs over there.
|
||||
*/
|
||||
pos += sprintf(buf + pos, exception_print_formats[0], exception_names[exception_type]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[1], context->gpr[0], context->gpr[8], context->gpr[16], context->gpr[24]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[2], context->gpr[1], context->gpr[9], context->gpr[17], context->gpr[25]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[3], context->gpr[2], context->gpr[10], context->gpr[18], context->gpr[26]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[4], context->gpr[3], context->gpr[11], context->gpr[19], context->gpr[27]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[5], context->gpr[4], context->gpr[12], context->gpr[20], context->gpr[28]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[6], context->gpr[5], context->gpr[13], context->gpr[21], context->gpr[29]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[7], context->gpr[6], context->gpr[14], context->gpr[22], context->gpr[30]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[8], context->gpr[7], context->gpr[15], context->gpr[23], context->gpr[31]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[9], context->lr, context->srr0, context->srr1);
|
||||
|
||||
//if(exception_type == OS_EXCEPTION_DSI) {
|
||||
pos += sprintf(buf + pos, exception_print_formats[10], context->exception_specific1, context->exception_specific0); // this freezes
|
||||
//}
|
||||
|
||||
void *pc = (void*)context->srr0;
|
||||
void *lr = (void*)context->lr;
|
||||
void *r1 = (void*)context->gpr[1];
|
||||
register uint32_t i = 0;
|
||||
register frame_rec_t l,p = (frame_rec_t)lr;
|
||||
|
||||
l = p;
|
||||
p = r1;
|
||||
if(!p)
|
||||
asm volatile("mr %0,%%r1" : "=r"(p));
|
||||
|
||||
pos += sprintf(buf + pos, exception_print_formats[11]);
|
||||
|
||||
for(i = 0; i < CPU_STACK_TRACE_DEPTH-1 && p->up; p = p->up, i++) {
|
||||
if(i % 4)
|
||||
pos += sprintf(buf + pos, exception_print_formats[12]);
|
||||
else {
|
||||
if(i > 0)
|
||||
pos += sprintf(buf + pos, exception_print_formats[13]);
|
||||
else
|
||||
pos += sprintf(buf + pos, exception_print_formats[14]);
|
||||
}
|
||||
|
||||
switch(i) {
|
||||
case 0:
|
||||
if(pc)
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],pc);
|
||||
break;
|
||||
case 1:
|
||||
if(!l)
|
||||
l = (frame_rec_t)mfspr(8);
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],(void*)l);
|
||||
break;
|
||||
default:
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],(void*)(p->up->lr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//if(exception_type == OS_EXCEPTION_DSI) {
|
||||
uint32_t *pAdd = (uint32_t*)context->srr0;
|
||||
pos += sprintf(buf + pos, exception_print_formats[16]);
|
||||
// TODO by Dimok: this was actually be 3 instead of 2 lines in libogc .... but there is just no more space anymore on the screen
|
||||
for (i = 0; i < 8; i += 4)
|
||||
pos += sprintf(buf + pos, exception_print_formats[17], &(pAdd[i]),pAdd[i], pAdd[i+1], pAdd[i+2], pAdd[i+3]);
|
||||
//}
|
||||
log_print(buf);
|
||||
OSFatal(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static unsigned char dsi_exception_cb(void * context) {
|
||||
return exception_cb(context, 0);
|
||||
}
|
||||
static unsigned char isi_exception_cb(void * context) {
|
||||
return exception_cb(context, 1);
|
||||
}
|
||||
static unsigned char program_exception_cb(void * context) {
|
||||
return exception_cb(context, 2);
|
||||
}
|
||||
|
||||
void setup_os_exceptions(void) {
|
||||
OSSetExceptionCallback(OS_EXCEPTION_DSI, &dsi_exception_cb);
|
||||
OSSetExceptionCallback(OS_EXCEPTION_ISI, &isi_exception_cb);
|
||||
OSSetExceptionCallback(OS_EXCEPTION_PROGRAM, &program_exception_cb);
|
||||
}
|
14
src/system/exception_handler.h
Normal file
14
src/system/exception_handler.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __EXCEPTION_HANDLER_H_
|
||||
#define __EXCEPTION_HANDLER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void setup_os_exceptions(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
198
src/system/memory.c
Normal file
198
src/system/memory.c
Normal file
@ -0,0 +1,198 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "common/common.h"
|
||||
#include "memory.h"
|
||||
|
||||
#define MEMORY_ARENA_1 0
|
||||
#define MEMORY_ARENA_2 1
|
||||
#define MEMORY_ARENA_3 2
|
||||
#define MEMORY_ARENA_4 3
|
||||
#define MEMORY_ARENA_5 4
|
||||
#define MEMORY_ARENA_6 5
|
||||
#define MEMORY_ARENA_7 6
|
||||
#define MEMORY_ARENA_8 7
|
||||
#define MEMORY_ARENA_FG_BUCKET 8
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Memory functions
|
||||
//! This is the only place where those are needed so lets keep them more or less private
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern unsigned int * pMEMAllocFromDefaultHeapEx;
|
||||
extern unsigned int * pMEMAllocFromDefaultHeap;
|
||||
extern unsigned int * pMEMFreeToDefaultHeap;
|
||||
|
||||
extern int (* MEMGetBaseHeapHandle)(int mem_arena);
|
||||
extern unsigned int (* MEMGetAllocatableSizeForFrmHeapEx)(int heap, int align);
|
||||
extern void *(* MEMAllocFromFrmHeapEx)(int heap, unsigned int size, int align);
|
||||
extern void (* MEMFreeToFrmHeap)(int heap, int mode);
|
||||
extern void *(* MEMAllocFromExpHeapEx)(int heap, unsigned int size, int align);
|
||||
extern int (* MEMCreateExpHeapEx)(void* address, unsigned int size, unsigned short flags);
|
||||
extern void *(* MEMDestroyExpHeap)(int heap);
|
||||
extern void (* MEMFreeToExpHeap)(int heap, void* ptr);
|
||||
|
||||
static int mem1_heap = -1;
|
||||
static int bucket_heap = -1;
|
||||
|
||||
void memoryInitialize(void)
|
||||
{
|
||||
int mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1);
|
||||
unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4);
|
||||
void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4);
|
||||
if(mem1_memory)
|
||||
mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0);
|
||||
|
||||
int bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET);
|
||||
unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4);
|
||||
void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4);
|
||||
if(bucket_memory)
|
||||
bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0);
|
||||
}
|
||||
|
||||
void memoryRelease(void)
|
||||
{
|
||||
MEMDestroyExpHeap(mem1_heap);
|
||||
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3);
|
||||
mem1_heap = -1;
|
||||
|
||||
MEMDestroyExpHeap(bucket_heap);
|
||||
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3);
|
||||
bucket_heap = -1;
|
||||
}
|
||||
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
//! wraps
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
void *__wrap_malloc(size_t size)
|
||||
{
|
||||
// pointer to a function resolve
|
||||
return ((void * (*)(size_t))(*pMEMAllocFromDefaultHeap))(size);
|
||||
}
|
||||
|
||||
void *__wrap_memalign(size_t align, size_t size)
|
||||
{
|
||||
if (align < 4)
|
||||
align = 4;
|
||||
|
||||
// pointer to a function resolve
|
||||
return ((void * (*)(size_t, size_t))(*pMEMAllocFromDefaultHeapEx))(size, align);
|
||||
}
|
||||
|
||||
void __wrap_free(void *p)
|
||||
{
|
||||
// pointer to a function resolve
|
||||
if(p != 0)
|
||||
((void (*)(void *))(*pMEMFreeToDefaultHeap))(p);
|
||||
}
|
||||
|
||||
void *__wrap_calloc(size_t n, size_t size)
|
||||
{
|
||||
void *p = __wrap_malloc(n * size);
|
||||
if (p != 0) {
|
||||
memset(p, 0, n * size);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
size_t __wrap_malloc_usable_size(void *p)
|
||||
{
|
||||
//! TODO: this is totally wrong and needs to be addressed
|
||||
return 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
void *__wrap_realloc(void *p, size_t size)
|
||||
{
|
||||
void *new_ptr = __wrap_malloc(size);
|
||||
if (new_ptr != 0)
|
||||
{
|
||||
memcpy(new_ptr, p, __wrap_malloc_usable_size(p) < size ? __wrap_malloc_usable_size(p) : size);
|
||||
__wrap_free(p);
|
||||
}
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
//! reent versions
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
void *__wrap__malloc_r(struct _reent *r, size_t size)
|
||||
{
|
||||
return __wrap_malloc(size);
|
||||
}
|
||||
|
||||
void *__wrap__calloc_r(struct _reent *r, size_t n, size_t size)
|
||||
{
|
||||
return __wrap_calloc(n, size);
|
||||
}
|
||||
|
||||
void *__wrap__memalign_r(struct _reent *r, size_t align, size_t size)
|
||||
{
|
||||
return __wrap_memalign(align, size);
|
||||
}
|
||||
|
||||
void __wrap__free_r(struct _reent *r, void *p)
|
||||
{
|
||||
__wrap_free(p);
|
||||
}
|
||||
|
||||
size_t __wrap__malloc_usable_size_r(struct _reent *r, void *p)
|
||||
{
|
||||
return __wrap_malloc_usable_size(p);
|
||||
}
|
||||
|
||||
void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
|
||||
{
|
||||
return __wrap_realloc(p, size);
|
||||
}
|
||||
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
//! some wrappers
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
void * MEM2_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
return __wrap_memalign(align, size);
|
||||
}
|
||||
|
||||
void MEM2_free(void *ptr)
|
||||
{
|
||||
__wrap_free(ptr);
|
||||
}
|
||||
|
||||
void * MEM1_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
if (align < 4)
|
||||
align = 4;
|
||||
return MEMAllocFromExpHeapEx(mem1_heap, size, align);
|
||||
}
|
||||
|
||||
void MEM1_free(void *ptr)
|
||||
{
|
||||
MEMFreeToExpHeap(mem1_heap, ptr);
|
||||
}
|
||||
|
||||
void * MEMBucket_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
if (align < 4)
|
||||
align = 4;
|
||||
return MEMAllocFromExpHeapEx(bucket_heap, size, align);
|
||||
}
|
||||
|
||||
void MEMBucket_free(void *ptr)
|
||||
{
|
||||
MEMFreeToExpHeap(bucket_heap, ptr);
|
||||
}
|
42
src/system/memory.h
Normal file
42
src/system/memory.h
Normal file
@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef __MEMORY_H_
|
||||
#define __MEMORY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
void memoryInitialize(void);
|
||||
void memoryRelease(void);
|
||||
|
||||
void * MEM2_alloc(unsigned int size, unsigned int align);
|
||||
void MEM2_free(void *ptr);
|
||||
|
||||
void * MEM1_alloc(unsigned int size, unsigned int align);
|
||||
void MEM1_free(void *ptr);
|
||||
|
||||
void * MEMBucket_alloc(unsigned int size, unsigned int align);
|
||||
void MEMBucket_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __MEMORY_H_
|
207
src/utils/StringTools.cpp
Normal file
207
src/utils/StringTools.cpp
Normal file
@ -0,0 +1,207 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <gctypes.h>
|
||||
|
||||
const char * fmt(const char * format, ...)
|
||||
{
|
||||
static char strChar[512];
|
||||
strChar[0] = 0;
|
||||
char * tmp = NULL;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
snprintf(strChar, sizeof(strChar), tmp);
|
||||
free(tmp);
|
||||
va_end(va);
|
||||
return (const char *) strChar;
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const wchar_t * wfmt(const char * format, ...)
|
||||
{
|
||||
static wchar_t strWChar[512];
|
||||
strWChar[0] = 0;
|
||||
|
||||
if(!format)
|
||||
return (const wchar_t *) strWChar;
|
||||
|
||||
if(strcmp(format, "") == 0)
|
||||
return (const wchar_t *) strWChar;
|
||||
|
||||
char * tmp = NULL;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
int bt;
|
||||
int strlength = strlen(tmp);
|
||||
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512 );
|
||||
free(tmp);
|
||||
tmp = 0;
|
||||
|
||||
if(bt > 0)
|
||||
{
|
||||
strWChar[bt] = 0;
|
||||
return (const wchar_t *) strWChar;
|
||||
}
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int strprintf(std::string &str, const char * format, ...)
|
||||
{
|
||||
int result = 0;
|
||||
char * tmp = NULL;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
str = tmp;
|
||||
result = str.size();
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string strfmt(const char * format, ...)
|
||||
{
|
||||
std::string str;
|
||||
char * tmp = NULL;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
str = tmp;
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
bool char2wchar_t(const char * strChar, wchar_t * dest)
|
||||
{
|
||||
if(!strChar || !dest)
|
||||
return false;
|
||||
|
||||
int bt;
|
||||
bt = mbstowcs(dest, strChar, strlen(strChar));
|
||||
if (bt > 0) {
|
||||
dest[bt] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int strtokcmp(const char * string, const char * compare, const char * separator)
|
||||
{
|
||||
if(!string || !compare)
|
||||
return -1;
|
||||
|
||||
char TokCopy[512];
|
||||
strncpy(TokCopy, compare, sizeof(TokCopy));
|
||||
TokCopy[511] = '\0';
|
||||
|
||||
char * strTok = strtok(TokCopy, separator);
|
||||
|
||||
while (strTok != NULL)
|
||||
{
|
||||
if (strcasecmp(string, strTok) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strTok = strtok(NULL,separator);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int strextcmp(const char * string, const char * extension, char seperator)
|
||||
{
|
||||
if(!string || !extension)
|
||||
return -1;
|
||||
|
||||
char *ptr = strrchr(string, seperator);
|
||||
if(!ptr)
|
||||
return -1;
|
||||
|
||||
return strcasecmp(ptr + 1, extension);
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> stringSplit(const std::string & inValue, const std::string & splitter)
|
||||
{
|
||||
std::string value = inValue;
|
||||
std::vector<std::string> result;
|
||||
while (true) {
|
||||
unsigned int index = value.find(splitter);
|
||||
if (index == std::string::npos) {
|
||||
result.push_back(value);
|
||||
break;
|
||||
}
|
||||
std::string first = value.substr(0, index);
|
||||
result.push_back(first);
|
||||
if (index + splitter.size() == value.length()) {
|
||||
result.push_back("");
|
||||
break;
|
||||
}
|
||||
if(index + splitter.size() > value.length()) {
|
||||
break;
|
||||
}
|
||||
value = value.substr(index + splitter.size(), value.length());
|
||||
}
|
||||
return result;
|
||||
}
|
78
src/utils/StringTools.h
Normal file
78
src/utils/StringTools.h
Normal file
@ -0,0 +1,78 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef __STRING_TOOLS_H
|
||||
#define __STRING_TOOLS_H
|
||||
|
||||
#include <gctypes.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
const char * fmt(const char * format, ...);
|
||||
const wchar_t * wfmt(const char * format, ...);
|
||||
int strprintf(std::string &str, const char * format, ...);
|
||||
std::string strfmt(const char * format, ...);
|
||||
bool char2wchar_t(const char * src, wchar_t * dest);
|
||||
int strtokcmp(const char * string, const char * compare, const char * separator);
|
||||
int strextcmp(const char * string, const char * extension, char seperator);
|
||||
|
||||
inline const char * FullpathToFilename(const char *path)
|
||||
{
|
||||
if(!path) return path;
|
||||
|
||||
const char * ptr = path;
|
||||
const char * Filename = ptr;
|
||||
|
||||
while(*ptr != '\0')
|
||||
{
|
||||
if(ptr[0] == '/' && ptr[1] != '\0')
|
||||
Filename = ptr+1;
|
||||
|
||||
++ptr;
|
||||
}
|
||||
|
||||
return Filename;
|
||||
}
|
||||
|
||||
inline void RemoveDoubleSlashs(std::string &str)
|
||||
{
|
||||
u32 length = str.size();
|
||||
|
||||
//! clear path of double slashes
|
||||
for(u32 i = 1; i < length; ++i)
|
||||
{
|
||||
if(str[i-1] == '/' && str[i] == '/')
|
||||
{
|
||||
str.erase(i, 1);
|
||||
i--;
|
||||
length--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> stringSplit(const std::string & value, const std::string & splitter);
|
||||
|
||||
#endif /* __STRING_TOOLS_H */
|
||||
|
88
src/utils/logger.c
Normal file
88
src/utils/logger.c
Normal file
@ -0,0 +1,88 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "common/common.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "logger.h"
|
||||
|
||||
static int log_socket = 0;
|
||||
static volatile int log_lock = 0;
|
||||
|
||||
|
||||
void log_init(const char * ipString)
|
||||
{
|
||||
log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (log_socket < 0)
|
||||
return;
|
||||
|
||||
struct sockaddr_in connect_addr;
|
||||
memset(&connect_addr, 0, sizeof(connect_addr));
|
||||
connect_addr.sin_family = AF_INET;
|
||||
connect_addr.sin_port = 4405;
|
||||
inet_aton(ipString, &connect_addr.sin_addr);
|
||||
|
||||
if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0)
|
||||
{
|
||||
socketclose(log_socket);
|
||||
log_socket = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void log_deinit(void)
|
||||
{
|
||||
if(log_socket > 0)
|
||||
{
|
||||
socketclose(log_socket);
|
||||
log_socket = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void log_print(const char *str)
|
||||
{
|
||||
// socket is always 0 initially as it is in the BSS
|
||||
if(log_socket <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while(log_lock)
|
||||
usleep(1000);
|
||||
log_lock = 1;
|
||||
|
||||
int len = strlen(str);
|
||||
int ret;
|
||||
while (len > 0) {
|
||||
int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet
|
||||
ret = send(log_socket, str, block, 0);
|
||||
if(ret < 0)
|
||||
break;
|
||||
|
||||
len -= ret;
|
||||
str += ret;
|
||||
}
|
||||
|
||||
log_lock = 0;
|
||||
}
|
||||
|
||||
void log_printf(const char *format, ...)
|
||||
{
|
||||
if(log_socket <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
char * tmp = NULL;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
log_print(tmp);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
}
|
||||
|
89
src/utils/logger.h
Normal file
89
src/utils/logger.h
Normal file
@ -0,0 +1,89 @@
|
||||
#ifndef __LOGGER_H_
|
||||
#define __LOGGER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Communication bytes with the server */
|
||||
// Com
|
||||
#define BYTE_NORMAL 0xff
|
||||
#define BYTE_SPECIAL 0xfe
|
||||
#define BYTE_OK 0xfd
|
||||
#define BYTE_PING 0xfc
|
||||
#define BYTE_LOG_STR 0xfb
|
||||
#define BYTE_DISCONNECT 0xfa
|
||||
|
||||
// SD
|
||||
#define BYTE_MOUNT_SD 0xe0
|
||||
#define BYTE_MOUNT_SD_OK 0xe1
|
||||
#define BYTE_MOUNT_SD_BAD 0xe2
|
||||
|
||||
// Replacement
|
||||
#define BYTE_STAT 0x00
|
||||
#define BYTE_STAT_ASYNC 0x01
|
||||
#define BYTE_OPEN_FILE 0x02
|
||||
#define BYTE_OPEN_FILE_ASYNC 0x03
|
||||
#define BYTE_OPEN_DIR 0x04
|
||||
#define BYTE_OPEN_DIR_ASYNC 0x05
|
||||
#define BYTE_CHANGE_DIR 0x06
|
||||
#define BYTE_CHANGE_DIR_ASYNC 0x07
|
||||
#define BYTE_MAKE_DIR 0x08
|
||||
#define BYTE_MAKE_DIR_ASYNC 0x09
|
||||
#define BYTE_RENAME 0x0A
|
||||
#define BYTE_RENAME_ASYNC 0x0B
|
||||
#define BYTE_REMOVE 0x0C
|
||||
#define BYTE_REMOVE_ASYNC 0x0D
|
||||
|
||||
// Log
|
||||
#define BYTE_CLOSE_FILE 0x40
|
||||
#define BYTE_CLOSE_FILE_ASYNC 0x41
|
||||
#define BYTE_CLOSE_DIR 0x42
|
||||
#define BYTE_CLOSE_DIR_ASYNC 0x43
|
||||
#define BYTE_FLUSH_FILE 0x44
|
||||
#define BYTE_GET_ERROR_CODE_FOR_VIEWER 0x45
|
||||
#define BYTE_GET_LAST_ERROR 0x46
|
||||
#define BYTE_GET_MOUNT_SOURCE 0x47
|
||||
#define BYTE_GET_MOUNT_SOURCE_NEXT 0x48
|
||||
#define BYTE_GET_POS_FILE 0x49
|
||||
#define BYTE_SET_POS_FILE 0x4A
|
||||
#define BYTE_GET_STAT_FILE 0x4B
|
||||
#define BYTE_EOF 0x4C
|
||||
#define BYTE_READ_FILE 0x4D
|
||||
#define BYTE_READ_FILE_ASYNC 0x4E
|
||||
#define BYTE_READ_FILE_WITH_POS 0x4F
|
||||
#define BYTE_READ_DIR 0x50
|
||||
#define BYTE_READ_DIR_ASYNC 0x51
|
||||
#define BYTE_GET_CWD 0x52
|
||||
#define BYTE_SET_STATE_CHG_NOTIF 0x53
|
||||
#define BYTE_TRUNCATE_FILE 0x54
|
||||
#define BYTE_WRITE_FILE 0x55
|
||||
#define BYTE_WRITE_FILE_WITH_POS 0x56
|
||||
|
||||
#define BYTE_SAVE_INIT 0x57
|
||||
#define BYTE_SAVE_SHUTDOWN 0x58
|
||||
#define BYTE_SAVE_INIT_SAVE_DIR 0x59
|
||||
#define BYTE_SAVE_FLUSH_QUOTA 0x5A
|
||||
#define BYTE_SAVE_OPEN_DIR 0x5B
|
||||
#define BYTE_SAVE_REMOVE 0x5C
|
||||
|
||||
#define BYTE_CREATE_THREAD 0x60
|
||||
|
||||
#define LOADIINE_LOGGER_IP "192.168.178.3"
|
||||
|
||||
int logger_connect(int *socket);
|
||||
void logger_disconnect(int socket);
|
||||
void log_string(int sock, const char* str, char byte);
|
||||
void log_byte(int sock, char byte);
|
||||
|
||||
void log_init(const char * ip);
|
||||
void log_deinit(void);
|
||||
void log_print(const char *str);
|
||||
void log_printf(const char *format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
561
src/utils/net.c
Normal file
561
src/utils/net.c
Normal file
@ -0,0 +1,561 @@
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include "common/common.h"
|
||||
#include "dynamic_libs/os_functions.h"
|
||||
#include "dynamic_libs/socket_functions.h"
|
||||
#include "net.h"
|
||||
|
||||
static volatile int iLock = 0;
|
||||
|
||||
#define CHECK_ERROR(cond) if (cond) { goto error; }
|
||||
|
||||
void cafiine_connect(int *psock,u32 server_ip) {
|
||||
struct sockaddr_in addr;
|
||||
int sock, ret;
|
||||
|
||||
socket_lib_init();
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = 7332;
|
||||
addr.sin_addr.s_addr = server_ip;
|
||||
|
||||
ret = connect(sock, (void *)&addr, sizeof(addr));
|
||||
CHECK_ERROR(ret < 0);
|
||||
ret = cafiine_handshake(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret == BYTE_NORMAL);
|
||||
|
||||
*psock = sock;
|
||||
return;
|
||||
error:
|
||||
if (sock != -1)
|
||||
socketclose(sock);
|
||||
*psock = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
void cafiine_disconnect(int sock) {
|
||||
CHECK_ERROR(sock == -1);
|
||||
socketclose(sock);
|
||||
error:
|
||||
return;
|
||||
}
|
||||
|
||||
int cafiine_handshake(int sock) {
|
||||
int ret;
|
||||
|
||||
unsigned char buffer[16];
|
||||
|
||||
u64 title_id = OSGetTitleID();
|
||||
memcpy(buffer, &title_id, 16);
|
||||
|
||||
ret = sendwait(sock, buffer, sizeof(buffer));
|
||||
CHECK_ERROR(ret < 0);
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
return ret;
|
||||
error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getMode(int sock,int * result)
|
||||
{
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
int ret = 0;
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
// create and send buffer with : [cmd id][fd][size][buffer data ...]
|
||||
{
|
||||
ret = sendbyte(sock, BYTE_G_MODE);
|
||||
|
||||
// wait reply
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
if(ret == BYTE_MODE_D) *result = BYTE_MODE_D;
|
||||
if(ret == BYTE_MODE_I) *result = BYTE_MODE_I;
|
||||
ret = 1;
|
||||
}
|
||||
error:
|
||||
iLock = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cafiine_fsetpos(int sock, int *result, int fd, int set) {
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
int ret;
|
||||
char buffer[1 + 8];
|
||||
buffer[0] = BYTE_SETPOS;
|
||||
*(int *)(buffer + 1) = fd;
|
||||
*(int *)(buffer + 5) = set;
|
||||
ret = sendwait(sock, buffer, 1 + 8);
|
||||
CHECK_ERROR(ret < 0);
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret == BYTE_NORMAL);
|
||||
ret = recvwait(sock, result, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
iLock = 0;
|
||||
return 0;
|
||||
error:
|
||||
iLock = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int cafiine_send_handle(int sock, const char *path, int handle)
|
||||
{
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
// create and send buffer with : [cmd id][handle][path length][path data ...]
|
||||
{
|
||||
int ret;
|
||||
int len_path = 0;
|
||||
while (path[len_path++]);
|
||||
char buffer[1 + 4 + 4 + len_path];
|
||||
|
||||
buffer[0] = BYTE_HANDLE;
|
||||
*(int *)(buffer + 1) = handle;
|
||||
*(int *)(buffer + 5) = len_path;
|
||||
for (ret = 0; ret < len_path; ret++)
|
||||
buffer[9 + ret] = path[ret];
|
||||
|
||||
// send buffer, wait for reply
|
||||
ret = sendwait(sock, buffer, 1 + 4 + 4 + len_path);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
// wait reply
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret == BYTE_SPECIAL);
|
||||
if(ret == BYTE_REQUEST){
|
||||
ret = 1;
|
||||
}else{
|
||||
ret = 2;
|
||||
}
|
||||
// wait reply
|
||||
int special_ret = recvbyte(sock);
|
||||
CHECK_ERROR(special_ret < 0);
|
||||
CHECK_ERROR(special_ret != BYTE_SPECIAL);
|
||||
iLock = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
error:
|
||||
iLock = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int cafiine_fopen(int sock, int *result, const char *path, const char *mode, int *handle) {
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int final_result = -1;
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
int ret;
|
||||
int len_path = 0;
|
||||
while (path[len_path++]);
|
||||
int len_mode = 0;
|
||||
while (mode[len_mode++]);
|
||||
|
||||
//
|
||||
{
|
||||
char buffer[1 + 8 + len_path + len_mode];
|
||||
buffer[0] = BYTE_OPEN;
|
||||
*(int *)(buffer + 1) = len_path;
|
||||
*(int *)(buffer + 5) = len_mode;
|
||||
for (ret = 0; ret < len_path; ret++)
|
||||
buffer[9 + ret] = path[ret];
|
||||
for (ret = 0; ret < len_mode; ret++)
|
||||
buffer[9 + len_path + ret] = mode[ret];
|
||||
|
||||
ret = sendwait(sock, buffer, 1 + 8 + len_path + len_mode);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret == BYTE_NORMAL);
|
||||
|
||||
ret = recvwait(sock, result, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
ret = recvwait(sock, handle, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
}
|
||||
final_result = 0;
|
||||
|
||||
|
||||
error:
|
||||
iLock = 0;
|
||||
return final_result;
|
||||
}
|
||||
|
||||
void cafiine_send_file(int sock, char *file, int size, int fd) {
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
int ret;
|
||||
|
||||
// create and send buffer with : [cmd id][fd][size][buffer data ...]
|
||||
{
|
||||
char buffer[1 + 4 + 4 + size];
|
||||
|
||||
buffer[0] = BYTE_DUMP;
|
||||
*(int *)(buffer + 1) = fd;
|
||||
*(int *)(buffer + 5) = size;
|
||||
for (ret = 0; ret < size; ret++)
|
||||
buffer[9 + ret] = file[ret];
|
||||
|
||||
// send buffer, wait for reply
|
||||
ret = sendwait(sock, buffer, 1 + 4 + 4 + size);
|
||||
CHECK_ERROR(ret < 0);
|
||||
// wait reply
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret != BYTE_SPECIAL);
|
||||
}
|
||||
|
||||
error:
|
||||
iLock = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int cafiine_fread(int sock, int *result, void *ptr, int size, int fd) {
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
int ret;
|
||||
char buffer[1 + 8];
|
||||
buffer[0] = BYTE_READ;
|
||||
*(int *)(buffer + 1) = size;
|
||||
*(int *)(buffer + 5) = fd;
|
||||
ret = sendwait(sock, buffer, 1 + 8);
|
||||
CHECK_ERROR(ret < 0);
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret == BYTE_NORMAL);
|
||||
int sz;
|
||||
ret = recvwait(sock, &sz, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
ret = recvwaitlen(sock, ptr, sz);
|
||||
*result = sz - ret;
|
||||
ret = sendbyte(sock, BYTE_OK);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
iLock = 0;
|
||||
return 0;
|
||||
error:
|
||||
iLock = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int cafiine_fclose(int sock, int *result, int fd,int dumpclose) {
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
CHECK_ERROR(sock == -1);
|
||||
|
||||
int ret;
|
||||
char buffer[1 + 4];
|
||||
buffer[0] = BYTE_CLOSE;
|
||||
if(dumpclose)buffer[0] = BYTE_CLOSE_DUMP;
|
||||
*(int *)(buffer + 1) = fd;
|
||||
ret = sendwait(sock, buffer, 1 + 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret == BYTE_NORMAL);
|
||||
ret = recvwait(sock, result, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
iLock = 0;
|
||||
return 0;
|
||||
error:
|
||||
iLock = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int saviine_start_injection(int sock, long persistentID,int * mask){
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int result = 0;
|
||||
CHECK_ERROR(sock == -1);
|
||||
int ret;
|
||||
{
|
||||
char buffer[1+4];
|
||||
|
||||
buffer[0] = BYTE_INJECTSTART;
|
||||
*(long *)(buffer + 1) = persistentID;
|
||||
ret = sendwait(sock, buffer, 1 + 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret != BYTE_SPECIAL);
|
||||
|
||||
ret = recvwait(sock, mask, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR((*mask & MASK_NORMAL) != MASK_NORMAL);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret != BYTE_SPECIAL);
|
||||
result = 1;
|
||||
}
|
||||
error:
|
||||
iLock = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
int saviine_end_injection(int sock){
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int result = 0;
|
||||
CHECK_ERROR(sock == -1);
|
||||
int ret;
|
||||
{
|
||||
ret = sendbyte(sock, BYTE_INJECTEND);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret != BYTE_OK);
|
||||
result = 1;
|
||||
}
|
||||
error:
|
||||
iLock = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
int saviine_start_dump(int sock, long persistentID,int * mask){
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int result = 0;
|
||||
CHECK_ERROR(sock == -1);
|
||||
int ret;
|
||||
{
|
||||
char buffer[1+4];
|
||||
|
||||
buffer[0] = BYTE_DUMPSTART;
|
||||
*(long *)(buffer + 1) = persistentID;
|
||||
ret = sendwait(sock, buffer, 1 + 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret != BYTE_SPECIAL);
|
||||
|
||||
ret = recvwait(sock, mask, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR((*mask & MASK_NORMAL) != MASK_NORMAL);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret != BYTE_SPECIAL);
|
||||
result = 1;
|
||||
}
|
||||
error:
|
||||
iLock = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
int saviine_end_dump(int sock){
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int result = 0;
|
||||
CHECK_ERROR(sock == -1);
|
||||
int ret;
|
||||
{
|
||||
ret = sendbyte(sock, BYTE_DUMPEND);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret != BYTE_OK);
|
||||
result = 1;
|
||||
}
|
||||
error:
|
||||
iLock = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
int saviine_readdir(int sock, char * path,char * resultname, int * resulttype, int * filesize){
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int result = 0;
|
||||
CHECK_ERROR(sock == -1);
|
||||
int ret;
|
||||
// create and send buffer with : [cmd id][len_path][path][filesize]
|
||||
{
|
||||
int size = 0;
|
||||
while (path[size++]);
|
||||
char buffer[1+4+size];
|
||||
|
||||
buffer[0] = BYTE_READ_DIR;
|
||||
*(int *)(buffer + 1) = size;
|
||||
for (ret = 0; ret < size; ret++)
|
||||
buffer[5 + ret] = path[ret];
|
||||
|
||||
// send buffer, wait for reply
|
||||
ret = sendwait(sock, buffer, 1+4+size);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
// wait reply
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret != BYTE_OK);
|
||||
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret != BYTE_FILE && ret != BYTE_FOLDER);
|
||||
*resulttype = ret;
|
||||
size = 0;
|
||||
ret = recvwait(sock, &size, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
ret = recvwait(sock, resultname, size+1);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
size = 0;
|
||||
ret = recvwait(sock, &size, 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
*filesize = size;
|
||||
ret = recvbyte(sock);
|
||||
CHECK_ERROR(ret < 0);
|
||||
CHECK_ERROR(ret != BYTE_SPECIAL);
|
||||
result = 1;
|
||||
|
||||
}
|
||||
error:
|
||||
iLock = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
void cafiine_send_ping(int sock, int val1, int val2) {
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int ret;
|
||||
char buffer[1 + 4 + 4];
|
||||
buffer[0] = BYTE_PING;
|
||||
*(int *)(buffer + 1) = val1;
|
||||
*(int *)(buffer + 5) = val2;
|
||||
|
||||
ret = sendwait(sock, buffer, 1 + 4 + 4);
|
||||
CHECK_ERROR(ret < 0);
|
||||
|
||||
error:
|
||||
iLock = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int recvwait(int sock, void *buffer, int len) {
|
||||
int ret;
|
||||
while (len > 0) {
|
||||
ret = recv(sock, buffer, len, 0);
|
||||
CHECK_ERROR(ret < 0);
|
||||
len -= ret;
|
||||
buffer += ret;
|
||||
}
|
||||
return 0;
|
||||
error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int recvwaitlen(int sock, void *buffer, int len) {
|
||||
int ret;
|
||||
while (len > 0) {
|
||||
ret = recv(sock, buffer, len, 0);
|
||||
CHECK_ERROR(ret < 0);
|
||||
len -= ret;
|
||||
buffer += ret;
|
||||
}
|
||||
return 0;
|
||||
error:
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int recvbyte(int sock) {
|
||||
unsigned char buffer[1];
|
||||
int ret;
|
||||
|
||||
ret = recvwait(sock, buffer, 1);
|
||||
if (ret < 0) return ret;
|
||||
return buffer[0];
|
||||
}
|
||||
|
||||
int sendwait(int sock, const void *buffer, int len) {
|
||||
int ret;
|
||||
while (len > 0) {
|
||||
ret = send(sock, buffer, len, 0);
|
||||
CHECK_ERROR(ret < 0);
|
||||
len -= ret;
|
||||
buffer += ret;
|
||||
}
|
||||
return 0;
|
||||
error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void log_string(int sock, const char* str, char flag_byte) {
|
||||
if(sock == -1) {
|
||||
return;
|
||||
}
|
||||
while (iLock)
|
||||
usleep(5000);
|
||||
iLock = 1;
|
||||
|
||||
int i;
|
||||
int len_str = 0;
|
||||
while (str[len_str++]);
|
||||
|
||||
//
|
||||
{
|
||||
char buffer[1 + 4 + len_str];
|
||||
buffer[0] = flag_byte;
|
||||
*(int *)(buffer + 1) = len_str;
|
||||
for (i = 0; i < len_str; i++)
|
||||
buffer[5 + i] = str[i];
|
||||
|
||||
buffer[5 + i] = 0;
|
||||
|
||||
sendwait(sock, buffer, 1 + 4 + len_str);
|
||||
}
|
||||
|
||||
iLock = 0;
|
||||
}
|
||||
|
||||
int sendbyte(int sock, unsigned char byte) {
|
||||
unsigned char buffer[1];
|
||||
|
||||
buffer[0] = byte;
|
||||
return sendwait(sock, buffer, 1);
|
||||
}
|
63
src/utils/net.h
Normal file
63
src/utils/net.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef NETWORK_H_
|
||||
#define NETWORK_H_
|
||||
|
||||
|
||||
#define BYTE_NORMAL 0xff
|
||||
#define BYTE_SPECIAL 0xfe
|
||||
#define BYTE_OPEN 0x00
|
||||
#define BYTE_READ 0x01
|
||||
#define BYTE_CLOSE 0x02
|
||||
#define BYTE_OK 0x03
|
||||
#define BYTE_SETPOS 0x04
|
||||
#define BYTE_STATFILE 0x05
|
||||
#define BYTE_EOF 0x06
|
||||
#define BYTE_GETPOS 0x07
|
||||
#define BYTE_REQUEST 0x08
|
||||
#define BYTE_REQUEST_SLOW 0x09
|
||||
#define BYTE_HANDLE 0x0A
|
||||
#define BYTE_DUMP 0x0B
|
||||
#define BYTE_PING 0x0C
|
||||
#define BYTE_G_MODE 0x0D
|
||||
#define BYTE_MODE_D 0x0E
|
||||
#define BYTE_MODE_I 0x0F
|
||||
#define BYTE_CLOSE_DUMP 0x10
|
||||
#define BYTE_LOG_STR 0xfb
|
||||
#define BYTE_FILE 0xC0
|
||||
#define BYTE_FOLDER 0xC1
|
||||
#define BYTE_READ_DIR 0xCC
|
||||
#define BYTE_INJECTSTART 0x40
|
||||
#define BYTE_INJECTEND 0x41
|
||||
#define BYTE_DUMPSTART 0x42
|
||||
#define BYTE_DUMPEND 0x43
|
||||
#define BYTE_END 0xfd
|
||||
|
||||
#define MASK_NORMAL 0x8000
|
||||
#define MASK_USER 0x0100
|
||||
#define MASK_COMMON 0x0200
|
||||
#define MASK_COMMON_CLEAN 0x0400
|
||||
|
||||
void cafiine_connect(int *psock,u32 ip);
|
||||
void cafiine_disconnect(int sock);
|
||||
int cafiine_handshake(int sock);
|
||||
int getMode(int sock,int * result);
|
||||
int cafiine_fsetpos(int sock, int *result, int fd, int set);
|
||||
int cafiine_send_handle(int sock, const char *path, int handle);
|
||||
int cafiine_fopen(int sock, int *result, const char *path, const char *mode, int *handle);
|
||||
void cafiine_send_file(int sock, char *file, int size, int fd);
|
||||
int cafiine_fread(int sock, int *result, void *ptr, int size, int fd);
|
||||
int cafiine_fclose(int sock, int *result, int fd,int dumpclose);
|
||||
int saviine_start_injection(int sock, long persistentID,int * mask);
|
||||
int saviine_end_injection(int sock);
|
||||
int saviine_start_dump(int sock, long persistentID,int * mask);
|
||||
int saviine_end_dump(int sock);
|
||||
int saviine_readdir(int sock, char * path,char * resultname, int * resulttype, int * filesize);
|
||||
void cafiine_send_ping(int sock, int val1, int val2);
|
||||
int recvwait(int sock, void *buffer, int len);
|
||||
int recvwaitlen(int sock, void *buffer, int len);
|
||||
int recvbyte(int sock);
|
||||
int sendwait(int sock, const void *buffer, int len);
|
||||
void log_string(int sock, const char* str, char flag_byte);
|
||||
int sendbyte(int sock, unsigned char byte);
|
||||
|
||||
|
||||
#endif
|
27
src/utils/utils.c
Normal file
27
src/utils/utils.c
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
void m_DCFlushRange(unsigned int startAddr, unsigned int size)
|
||||
{
|
||||
register unsigned int addr = startAddr & ~0x1F;
|
||||
register unsigned int end_addr = startAddr + size;
|
||||
|
||||
while(addr < end_addr)
|
||||
{
|
||||
asm volatile("dcbf 0, %0" : : "r"(addr));
|
||||
addr += 0x20;
|
||||
}
|
||||
asm volatile("sync; eieio");
|
||||
}
|
||||
|
||||
|
||||
void m_DCInvalidateRange(unsigned int startAddr, unsigned int size)
|
||||
{
|
||||
register unsigned int addr = startAddr & ~0x1F;
|
||||
register unsigned int end_addr = startAddr + size;
|
||||
|
||||
while(addr < end_addr)
|
||||
{
|
||||
asm volatile("dcbi 0, %0" : : "r"(addr));
|
||||
addr += 0x20;
|
||||
}
|
||||
}
|
49
src/utils/utils.h
Normal file
49
src/utils/utils.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef __UTILS_H_
|
||||
#define __UTILS_H_
|
||||
|
||||
#include <malloc.h>
|
||||
#include "../common/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void m_DCInvalidateRange(unsigned int startAddr, unsigned int size);
|
||||
|
||||
#define FlushBlock(addr) asm volatile("dcbf %0, %1\n" \
|
||||
"icbi %0, %1\n" \
|
||||
"sync\n" \
|
||||
"eieio\n" \
|
||||
"isync\n" \
|
||||
: \
|
||||
:"r"(0), "r"(((addr) & ~31)) \
|
||||
:"memory", "ctr", "lr", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" \
|
||||
);
|
||||
|
||||
#define LIMIT(x, min, max) \
|
||||
({ \
|
||||
typeof( x ) _x = x; \
|
||||
typeof( min ) _min = min; \
|
||||
typeof( max ) _max = max; \
|
||||
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
|
||||
})
|
||||
|
||||
#define DegToRad(a) ( (a) * 0.01745329252f )
|
||||
#define RadToDeg(a) ( (a) * 57.29577951f )
|
||||
|
||||
#define ALIGN4(x) (((x) + 3) & ~3)
|
||||
#define ALIGN32(x) (((x) + 31) & ~31)
|
||||
|
||||
// those work only in powers of 2
|
||||
#define ROUNDDOWN(val, align) ((val) & ~(align-1))
|
||||
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align)
|
||||
|
||||
#define le16(i) ((((u16) ((i) & 0xFF)) << 8) | ((u16) (((i) & 0xFF00) >> 8)))
|
||||
#define le32(i) ((((u32)le16((i) & 0xFFFF)) << 16) | ((u32)le16(((i) & 0xFFFF0000) >> 16)))
|
||||
#define le64(i) ((((u64)le32((i) & 0xFFFFFFFFLL)) << 32) | ((u64)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __UTILS_H_
|
BIN
tcpgecko.elf
Normal file
BIN
tcpgecko.elf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user