From 5de0598c845e3ea31a905937cd791d62aea83855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= Date: Thu, 30 Sep 2021 20:49:37 +0800 Subject: [PATCH] First commit. --- .gitmodules | 6 + COPYING | 674 +++++++++++++++++ Makefile | 158 ++++ Makefile.common | 173 +++++ build.scm | 79 ++ deps/config/freetype/ftmodule.h | 6 + deps/config/freetype/ftoption.h | 998 +++++++++++++++++++++++++ deps/config/libjpeg-turbo/jconfig.h | 67 ++ deps/config/libjpeg-turbo/jconfigint.h | 11 + deps/config/libogg/os_types.h | 34 + deps/config/sdl/SDL_config.h | 27 + deps/libretro-common | 1 + deps/tinycoroutine | 1 + libretro.cpp | 212 ++++++ link.T | 5 + sdl-libretro/SDL_libretro.h | 21 + sdl-libretro/audio.c | 106 +++ sdl-libretro/events.c | 60 ++ sdl-libretro/thread.c | 94 +++ sdl-libretro/timer.c | 49 ++ sdl-libretro/video.c | 192 +++++ 21 files changed, 2974 insertions(+) create mode 100644 .gitmodules create mode 100644 COPYING create mode 100644 Makefile create mode 100644 Makefile.common create mode 100644 build.scm create mode 100644 deps/config/freetype/ftmodule.h create mode 100644 deps/config/freetype/ftoption.h create mode 100644 deps/config/libjpeg-turbo/jconfig.h create mode 100644 deps/config/libjpeg-turbo/jconfigint.h create mode 100644 deps/config/libogg/os_types.h create mode 100644 deps/config/sdl/SDL_config.h create mode 160000 deps/libretro-common create mode 160000 deps/tinycoroutine create mode 100644 libretro.cpp create mode 100644 link.T create mode 100644 sdl-libretro/SDL_libretro.h create mode 100644 sdl-libretro/audio.c create mode 100644 sdl-libretro/events.c create mode 100644 sdl-libretro/thread.c create mode 100644 sdl-libretro/timer.c create mode 100644 sdl-libretro/video.c diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..adc3daa --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "deps/tinycoroutine"] + path = deps/tinycoroutine + url = https://github.com/soundsrc/tinycoroutine.git +[submodule "deps/libretro-common"] + path = deps/libretro-common + url = https://github.com/libretro/libretro-common.git diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . + +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: + + Copyright (C) + 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 +. + + 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 +. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..692d8e5 --- /dev/null +++ b/Makefile @@ -0,0 +1,158 @@ +STATIC_LINKING := 0 +AR := ar + +ifneq ($(V),1) + Q := @ +endif + +ifneq ($(SANITIZER),) + CFLAGS := -fsanitize=$(SANITIZER) $(CFLAGS) + CXXFLAGS := -fsanitize=$(SANITIZER) $(CXXFLAGS) + LDFLAGS := -fsanitize=$(SANITIZER) $(LDFLAGS) +endif + +ifeq ($(platform),) +platform = unix +ifeq ($(shell uname -a),) + platform = win +else ifneq ($(findstring MINGW,$(shell uname -a)),) + platform = win +else ifneq ($(findstring Darwin,$(shell uname -a)),) + platform = osx +else ifneq ($(findstring win,$(shell uname -a)),) + platform = win +endif +endif + +# system platform +system_platform = unix +ifeq ($(shell uname -a),) + EXE_EXT = .exe + system_platform = win +else ifneq ($(findstring Darwin,$(shell uname -a)),) + system_platform = osx + arch = intel +ifeq ($(shell uname -p),powerpc) + arch = ppc +endif +else ifneq ($(findstring MINGW,$(shell uname -a)),) + system_platform = win +endif + +CORE_DIR += . +TARGET_NAME := onscripter +LIBM = -lm + +ifeq ($(ARCHFLAGS),) +ifeq ($(archs),ppc) + ARCHFLAGS = -arch ppc -arch ppc64 +else + ARCHFLAGS = -arch i386 -arch x86_64 +endif +endif + +ifeq ($(platform), osx) +ifndef ($(NOUNIVERSAL)) + CXXFLAGS += $(ARCHFLAGS) + LFLAGS += $(ARCHFLAGS) +endif +endif + +ifeq ($(STATIC_LINKING), 1) +EXT := a +endif + +ifeq ($(platform), unix) + EXT ?= so + TARGET := $(TARGET_NAME)_libretro.$(EXT) + fpic := -fPIC + SHARED := -shared -Wl,--version-script=$(CORE_DIR)/link.T -Wl,--no-undefined +else ifeq ($(platform), linux-portable) + TARGET := $(TARGET_NAME)_libretro.$(EXT) + fpic := -fPIC -nostdlib + SHARED := -shared -Wl,--version-script=$(CORE_DIR)/link.T + LIBM := +else ifneq (,$(findstring osx,$(platform))) + TARGET := $(TARGET_NAME)_libretro.dylib + fpic := -fPIC + SHARED := -dynamiclib +else ifneq (,$(findstring ios,$(platform))) + TARGET := $(TARGET_NAME)_libretro_ios.dylib + fpic := -fPIC + SHARED := -dynamiclib + +ifeq ($(IOSSDK),) + IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path) +endif + + DEFINES := -DIOS + CC = cc -arch armv7 -isysroot $(IOSSDK) +ifeq ($(platform),ios9) +CC += -miphoneos-version-min=8.0 +CXXFLAGS += -miphoneos-version-min=8.0 +else +CC += -miphoneos-version-min=5.0 +CXXFLAGS += -miphoneos-version-min=5.0 +endif +else ifneq (,$(findstring qnx,$(platform))) + TARGET := $(TARGET_NAME)_libretro_qnx.so + fpic := -fPIC + SHARED := -shared -Wl,--version-script=$(CORE_DIR)/link.T -Wl,--no-undefined +else ifeq ($(platform), emscripten) + TARGET := $(TARGET_NAME)_libretro_emscripten.bc + fpic := -fPIC + SHARED := -shared -Wl,--version-script=$(CORE_DIR)/link.T -Wl,--no-undefined +else ifeq ($(platform), vita) + TARGET := $(TARGET_NAME)_vita.a + CC = arm-vita-eabi-gcc + AR = arm-vita-eabi-ar + CXXFLAGS += -Wl,-q -Wall -O3 + STATIC_LINKING = 1 +else + CC = gcc + TARGET := $(TARGET_NAME)_libretro.dll + SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=$(CORE_DIR)/link.T -Wl,--no-undefined +endif + +LDFLAGS += $(LIBM) + +ifeq ($(DEBUG), 1) + CFLAGS += -O0 -g -DDEBUG + CXXFLAGS += -O0 -g -DDEBUG +else + CFLAGS += -O3 + CXXFLAGS += -O3 +endif + +include Makefile.common + +OBJECTS := $(SOURCES_C:.c=.o) $(SOURCES_CXX:.cpp=.o) + +CFLAGS += -Wall -D__LIBRETRO__ $(fpic) +CXXFLAGS += -Wall -D__LIBRETRO__ $(fpic) + +all: $(TARGET) + +$(TARGET): $(OBJECTS) +ifeq ($(STATIC_LINKING), 1) + $(AR) rcs $@ $(OBJECTS) +else + @$(if $(Q), $(shell echo echo LD $@),) + $(Q)$(CXX) $(fpic) $(SHARED) $(INCLUDES) -o $@ $(OBJECTS) $(LDFLAGS) +endif + +%.o: %.c + @$(if $(Q), $(shell echo echo CC $<),) + $(Q)$(CC) $(CFLAGS) $(fpic) -c -o $@ $< + +%.o: %.cpp + @$(if $(Q), $(shell echo echo CXX $<),) + $(Q)$(CXX) $(CXXFLAGS) $(fpic) -c -o $@ $< + +clean: + rm -f $(OBJECTS) $(TARGET) + +.PHONY: clean + +print-%: + @echo '$*=$($*)' diff --git a/Makefile.common b/Makefile.common new file mode 100644 index 0000000..c8f5d4d --- /dev/null +++ b/Makefile.common @@ -0,0 +1,173 @@ +# -*- mode: makefile -*- +DEPS_DIR = $(CORE_DIR)/deps +LIBRETRO_COMM_DIR = $(DEPS_DIR)/libretro-common +SDL_LIBRETRO_DIR = $(CORE_DIR)/sdl-libretro + +INCFLAGS := \ + -I$(LIBRETRO_COMM_DIR)/include \ + -I$(DEPS_DIR)/bzip2 \ + -I$(DEPS_DIR)/freetype/include \ + -I$(DEPS_DIR)/libjpeg-turbo \ + -I$(DEPS_DIR)/libogg/include \ + -I$(DEPS_DIR)/libvorbis/include \ + -I$(SDL_LIBRETRO_DIR) \ + -I$(DEPS_DIR)/sdl/include \ + -I$(DEPS_DIR)/sdl-image \ + -I$(DEPS_DIR)/sdl-mixer \ + -I$(DEPS_DIR)/sdl-ttf \ + -I$(DEPS_DIR)/tinycoroutine \ + -I$(CORE_DIR) \ + -I$(DEPS_DIR) + + +CFLAGS += $(INCFLAGS) +CXXFLAGS += $(INCFLAGS) + +# bzip2 +CFLAGS += -D_FILE_OFFSET_BITS=64 +SOURCES_C += \ + $(DEPS_DIR)/bzip2/blocksort.c \ + $(DEPS_DIR)/bzip2/huffman.c \ + $(DEPS_DIR)/bzip2/crctable.c \ + $(DEPS_DIR)/bzip2/randtable.c \ + $(DEPS_DIR)/bzip2/compress.c \ + $(DEPS_DIR)/bzip2/decompress.c \ + $(DEPS_DIR)/bzip2/bzlib.c + +# freetype +CFLAGS += -DFT2_BUILD_LIBRARY=1 +SOURCES_C += $(addprefix $(DEPS_DIR)/freetype/src/,\ + base/ftbase.c \ + base/ftdebug.c \ + base/ftinit.c \ + base/ftsystem.c \ + base/ftbitmap.c \ + base/ftglyph.c \ + base/ftstroke.c \ + autofit/autofit.c \ + psnames/psnames.c \ + sfnt/sfnt.c \ + truetype/truetype.c \ + raster/raster.c \ + smooth/smooth.c \ +) + +# libjpeg-turbo +SOURCES_C += $(addprefix $(DEPS_DIR)/libjpeg-turbo/,\ + jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \ + jcicc.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \ + jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c \ + jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdicc.c jdinput.c \ + jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c \ + jdtrans.c jerror.c jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c \ + jidctint.c jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c \ + jaricom.c jcarith.c jdarith.c \ + jsimd_none.c \ +) + +# libogg +SOURCES_C += $(addprefix $(DEPS_DIR)/libogg/src/,\ + bitwise.c framing.c \ +) + +# libvorbis +SOURCES_C += $(addprefix $(DEPS_DIR)/libvorbis/lib/,\ + mdct.c smallft.c block.c envelope.c window.c lsp.c \ + lpc.c analysis.c synthesis.c psy.c info.c \ + floor1.c floor0.c \ + res0.c mapping0.c registry.c codebook.c sharedbook.c \ + lookup.c bitrate.c vorbisfile.c \ +) + +# sdl +SOURCES_C += $(addprefix $(DEPS_DIR)/sdl/src/,\ + SDL.c SDL_error.c SDL_fatal.c \ + audio/SDL_audio.c audio/SDL_audiocvt.c audio/SDL_audiodev.c \ + audio/SDL_mixer.c audio/SDL_mixer_m68k.c audio/SDL_wave.c \ + cdrom/SDL_cdrom.c cpuinfo/SDL_cpuinfo.c \ + events/SDL_active.c events/SDL_events.c events/SDL_expose.c \ + events/SDL_keyboard.c events/SDL_mouse.c events/SDL_quit.c \ + events/SDL_resize.c \ + file/SDL_rwops.c \ + joystick/SDL_joystick.c \ + stdlib/SDL_getenv.c stdlib/SDL_iconv.c \ + stdlib/SDL_malloc.c stdlib/SDL_qsort.c \ + stdlib/SDL_stdlib.c stdlib/SDL_string.c \ + thread/SDL_thread.c timer/SDL_timer.c \ + video/SDL_blit_0.c video/SDL_blit_1.c video/SDL_blit_A.c \ + video/SDL_blit.c video/SDL_blit_N.c video/SDL_bmp.c video/SDL_cursor.c \ + video/SDL_gamma.c video/SDL_pixels.c video/SDL_RLEaccel.c \ + video/SDL_stretch.c video/SDL_surface.c video/SDL_video.c \ + video/SDL_yuv.c video/SDL_yuv_mmx.c video/SDL_yuv_sw.c \ + cdrom/dummy/SDL_syscdrom.c \ + joystick/dummy/SDL_sysjoystick.c \ + loadso/dummy/SDL_sysloadso.c \ +) +SOURCES_C += $(addprefix $(SDL_LIBRETRO_DIR)/, \ + audio.c events.c video.c thread.c timer.c \ +) +LDFLAGS += -lpthread + +# sdl-image +CFLAGS += -DSIZEOF_SIZE_T=__SIZEOF_SIZE_T__ -DLOAD_JPG +SOURCES_C += $(filter-out %/showimage.c, $(wildcard $(DEPS_DIR)/sdl-image/*.c)) + +# sdl-mixer +CFLAGS += -DOGG_MUSIC +SOURCES_C += $(addprefix $(DEPS_DIR)/sdl-mixer/,\ + mixer.c \ + music.c \ + effects_internal.c \ + effect_position.c \ + load_voc.c \ + load_aiff.c \ + load_ogg.c \ + music_ogg.c \ + dynamic_ogg.c \ +) + +# sdl-ttf +SOURCES_C += $(DEPS_DIR)/sdl-ttf/SDL_ttf.c + +# libretro-common +SOURCES_C += $(addprefix $(LIBRETRO_COMM_DIR)/,\ + compat/compat_strl.c \ + encodings/encoding_utf.c \ + string/stdstring.c \ + time/rtime.c \ + file/file_path.c \ +) + +# tinycoroutine +SOURCES_C += $(DEPS_DIR)/tinycoroutine/tinycoroutine.c + +# onscripter +SOURCES_CXX := $(CORE_DIR)/libretro.cpp +SOURCES_CXX += $(addprefix $(DEPS_DIR)/onscripter/,\ + ONScripter.cpp \ + ONScripter_animation.cpp \ + ONScripter_command.cpp \ + ONScripter_effect.cpp \ + ONScripter_effect_breakup.cpp \ + ONScripter_effect_cascade.cpp \ + ONScripter_event.cpp \ + ONScripter_file.cpp \ + ONScripter_file2.cpp \ + ONScripter_image.cpp \ + ONScripter_lut.cpp \ + ONScripter_rmenu.cpp \ + ONScripter_sound.cpp \ + ONScripter_text.cpp \ + resize_image.cpp \ + sjis2utf16.cpp \ + Encoding.cpp \ + DirectReader.cpp \ + SarReader.cpp \ + NsaReader.cpp \ + ScriptHandler.cpp \ + ScriptParser.cpp \ + ScriptParser_command.cpp \ + FontInfo.cpp \ + AnimationInfo.cpp \ + DirtyRect.cpp \ +) diff --git a/build.scm b/build.scm new file mode 100644 index 0000000..d99cbbb --- /dev/null +++ b/build.scm @@ -0,0 +1,79 @@ +(use-modules + (gnu packages compression) + (gnu packages fontutils) + (gnu packages image) + (gnu packages sdl) + (gnu packages xiph) + (guix build-system gnu) + (guix download) + (guix gexp) + (guix git) + ((guix licenses) #:prefix license:) + (guix packages) + (guix utils)) + +(package + (name "libretro-onscripter") + (version "0.0") + (source (local-file (dirname (current-filename)) + #:recursive? #t + #:select? + (lambda (file stat) + (not (string=? (basename file) ".git"))))) + (build-system gnu-build-system) + (arguments + `(#:tests? #f + #:make-flags (list (string-append "CC=" ,(cc-for-target)) + (string-append "CXX=" ,(cxx-for-target))) + #:phases + (modify-phases %standard-phases + (replace 'configure + (lambda* (#:key inputs #:allow-other-keys) + (copy-recursively (assoc-ref inputs "sdl-ttf") + "deps/sdl-ttf") + (for-each + (lambda (dep) + (define destdir (string-append "deps/" dep)) + (mkdir-p destdir) + (invoke "tar" "-C" destdir + "--strip-components=1" "-xvf" + (assoc-ref inputs dep))) + '("bzip2" "freetype" "libogg" "libvorbis" "libjpeg-turbo" + "sdl" "sdl-image" "sdl-mixer" "onscripter")) + (copy-recursively "deps/config/freetype" + "deps/freetype/include/freetype/config") + (copy-recursively "deps/config/libjpeg-turbo" + "deps/libjpeg-turbo") + (copy-recursively "deps/config/libogg" + "deps/libogg/include/ogg") + (copy-recursively "deps/config/sdl" + "deps/sdl/include"))) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (libretrodir (string-append out "/lib/libretro"))) + (install-file "onscripter_libretro.so" + libretrodir))))))) + (inputs + `(("bzip2" ,(package-source bzip2)) + ("freetype" ,(package-source freetype)) + ("libogg" ,(package-source libogg)) + ("libvorbis" ,(package-source libvorbis)) + ("libjpeg-turbo" ,(package-source libjpeg-turbo)) + ("sdl" ,(package-source sdl)) + ("sdl-image" ,(package-source sdl-image)) + ("sdl-mixer" ,(package-source sdl-mixer)) + ("onscripter" ,(origin + (method url-fetch) + (uri "http://onscripter.osdn.jp/onscripter-20200722.tar.gz") + (sha256 + (base32 + "0pnkki59k26pqxv1lh0rdcryc2w477ag2vqnpx3dmqva6fng9r8j")))) + ("sdl-ttf" ,(git-checkout + ;; XXX: Fixed TTF_RenderGlyph_Shaded + (url "https://github.com/libsdl-org/SDL_ttf") + (commit "e31d11a692e5b55e8e624ad766e4e44d655422c8"))))) + (home-page "") + (synopsis "Libretro core for ONScripter") + (description "") + (license license:gpl3+)) diff --git a/deps/config/freetype/ftmodule.h b/deps/config/freetype/ftmodule.h new file mode 100644 index 0000000..7b972f0 --- /dev/null +++ b/deps/config/freetype/ftmodule.h @@ -0,0 +1,6 @@ +FT_USE_MODULE( FT_Module_Class, psnames_module_class ) +FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) +FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) +FT_USE_MODULE( FT_Module_Class, autofit_module_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) diff --git a/deps/config/freetype/ftoption.h b/deps/config/freetype/ftoption.h new file mode 100644 index 0000000..25e01fe --- /dev/null +++ b/deps/config/freetype/ftoption.h @@ -0,0 +1,998 @@ +/**************************************************************************** + * + * ftoption.h + * + * User-selectable configuration macros (specification only). + * + * Copyright (C) 1996-2020 by + * David Turner, Robert Wilhelm, and Werner Lemberg. + * + * This file is part of the FreeType project, and may only be used, + * modified, and distributed under the terms of the FreeType project + * license, LICENSE.TXT. By continuing to use, modify, or distribute + * this file you indicate that you have read the license and + * understand and accept it fully. + * + */ + + +#ifndef FTOPTION_H_ +#define FTOPTION_H_ + + +#include + + +FT_BEGIN_HEADER + + /************************************************************************** + * + * USER-SELECTABLE CONFIGURATION MACROS + * + * This file contains the default configuration macro definitions for a + * standard build of the FreeType library. There are three ways to use + * this file to build project-specific versions of the library: + * + * - You can modify this file by hand, but this is not recommended in + * cases where you would like to build several versions of the library + * from a single source directory. + * + * - You can put a copy of this file in your build directory, more + * precisely in `$BUILD/freetype/config/ftoption.h`, where `$BUILD` is + * the name of a directory that is included _before_ the FreeType include + * path during compilation. + * + * The default FreeType Makefiles use the build directory + * `builds/` by default, but you can easily change that for your + * own projects. + * + * - Copy the file to `$BUILD/ft2build.h` and modify it + * slightly to pre-define the macro `FT_CONFIG_OPTIONS_H` used to locate + * this file during the build. For example, + * + * ``` + * #define FT_CONFIG_OPTIONS_H + * #include + * ``` + * + * will use `$BUILD/myftoptions.h` instead of this file for macro + * definitions. + * + * Note also that you can similarly pre-define the macro + * `FT_CONFIG_MODULES_H` used to locate the file listing of the modules + * that are statically linked to the library at compile time. By + * default, this file is ``. + * + * We highly recommend using the third method whenever possible. + * + */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** G E N E R A L F R E E T Y P E 2 C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /*#************************************************************************ + * + * If you enable this configuration option, FreeType recognizes an + * environment variable called `FREETYPE_PROPERTIES`, which can be used to + * control the various font drivers and modules. The controllable + * properties are listed in the section @properties. + * + * You have to undefine this configuration option on platforms that lack + * the concept of environment variables (and thus don't have the `getenv` + * function), for example Windows CE. + * + * `FREETYPE_PROPERTIES` has the following syntax form (broken here into + * multiple lines for better readability). + * + * ``` + * + * ':' + * '=' + * + * ':' + * '=' + * ... + * ``` + * + * Example: + * + * ``` + * FREETYPE_PROPERTIES=truetype:interpreter-version=35 \ + * cff:no-stem-darkening=1 \ + * autofitter:warping=1 + * ``` + * + */ +#define FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES + + + /************************************************************************** + * + * Uncomment the line below if you want to activate LCD rendering + * technology similar to ClearType in this build of the library. This + * technology triples the resolution in the direction color subpixels. To + * mitigate color fringes inherent to this technology, you also need to + * explicitly set up LCD filtering. + * + * When this macro is not defined, FreeType offers alternative LCD + * rendering technology that produces excellent output. + */ +/* #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ + + + /************************************************************************** + * + * Many compilers provide a non-ANSI 64-bit data type that can be used by + * FreeType to speed up some computations. However, this will create some + * problems when compiling the library in strict ANSI mode. + * + * For this reason, the use of 64-bit integers is normally disabled when + * the `__STDC__` macro is defined. You can however disable this by + * defining the macro `FT_CONFIG_OPTION_FORCE_INT64` here. + * + * For most compilers, this will only create compilation warnings when + * building the library. + * + * ObNote: The compiler-specific 64-bit integers are detected in the + * file `ftconfig.h` either statically or through the `configure` + * script on supported platforms. + */ +#undef FT_CONFIG_OPTION_FORCE_INT64 + + + /************************************************************************** + * + * If this macro is defined, do not try to use an assembler version of + * performance-critical functions (e.g., @FT_MulFix). You should only do + * that to verify that the assembler function works properly, or to execute + * benchmark tests of the various implementations. + */ +/* #define FT_CONFIG_OPTION_NO_ASSEMBLER */ + + + /************************************************************************** + * + * If this macro is defined, try to use an inlined assembler version of the + * @FT_MulFix function, which is a 'hotspot' when loading and hinting + * glyphs, and which should be executed as fast as possible. + * + * Note that if your compiler or CPU is not supported, this will default to + * the standard and portable implementation found in `ftcalc.c`. + */ +#define FT_CONFIG_OPTION_INLINE_MULFIX + + + /************************************************************************** + * + * LZW-compressed file support. + * + * FreeType now handles font files that have been compressed with the + * `compress` program. This is mostly used to parse many of the PCF + * files that come with various X11 distributions. The implementation + * uses NetBSD's `zopen` to partially uncompress the file on the fly (see + * `src/lzw/ftgzip.c`). + * + * Define this macro if you want to enable this 'feature'. + */ +/* #define FT_CONFIG_OPTION_USE_LZW */ + + + /************************************************************************** + * + * Gzip-compressed file support. + * + * FreeType now handles font files that have been compressed with the + * `gzip` program. This is mostly used to parse many of the PCF files + * that come with XFree86. The implementation uses 'zlib' to partially + * uncompress the file on the fly (see `src/gzip/ftgzip.c`). + * + * Define this macro if you want to enable this 'feature'. See also the + * macro `FT_CONFIG_OPTION_SYSTEM_ZLIB` below. + */ +/* #define FT_CONFIG_OPTION_USE_ZLIB */ + + + /************************************************************************** + * + * ZLib library selection + * + * This macro is only used when `FT_CONFIG_OPTION_USE_ZLIB` is defined. + * It allows FreeType's 'ftgzip' component to link to the system's + * installation of the ZLib library. This is useful on systems like + * Unix or VMS where it generally is already available. + * + * If you let it undefined, the component will use its own copy of the + * zlib sources instead. These have been modified to be included + * directly within the component and **not** export external function + * names. This allows you to link any program with FreeType _and_ ZLib + * without linking conflicts. + * + * Do not `#undef` this macro here since the build system might define + * it for certain configurations only. + * + * If you use a build system like cmake or the `configure` script, + * options set by those programs have precedence, overwriting the value + * here with the configured one. + */ +/* #define FT_CONFIG_OPTION_SYSTEM_ZLIB */ + + + /************************************************************************** + * + * Bzip2-compressed file support. + * + * FreeType now handles font files that have been compressed with the + * `bzip2` program. This is mostly used to parse many of the PCF files + * that come with XFree86. The implementation uses `libbz2` to partially + * uncompress the file on the fly (see `src/bzip2/ftbzip2.c`). Contrary + * to gzip, bzip2 currently is not included and need to use the system + * available bzip2 implementation. + * + * Define this macro if you want to enable this 'feature'. + * + * If you use a build system like cmake or the `configure` script, + * options set by those programs have precedence, overwriting the value + * here with the configured one. + */ +/* #define FT_CONFIG_OPTION_USE_BZIP2 */ + + + /************************************************************************** + * + * Define to disable the use of file stream functions and types, `FILE`, + * `fopen`, etc. Enables the use of smaller system libraries on embedded + * systems that have multiple system libraries, some with or without file + * stream support, in the cases where file stream support is not necessary + * such as memory loading of font files. + */ +/* #define FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT */ + + + /************************************************************************** + * + * PNG bitmap support. + * + * FreeType now handles loading color bitmap glyphs in the PNG format. + * This requires help from the external libpng library. Uncompressed + * color bitmaps do not need any external libraries and will be supported + * regardless of this configuration. + * + * Define this macro if you want to enable this 'feature'. + * + * If you use a build system like cmake or the `configure` script, + * options set by those programs have precedence, overwriting the value + * here with the configured one. + */ +/* #define FT_CONFIG_OPTION_USE_PNG */ + + + /************************************************************************** + * + * HarfBuzz support. + * + * FreeType uses the HarfBuzz library to improve auto-hinting of OpenType + * fonts. If available, many glyphs not directly addressable by a font's + * character map will be hinted also. + * + * Define this macro if you want to enable this 'feature'. + * + * If you use a build system like cmake or the `configure` script, + * options set by those programs have precedence, overwriting the value + * here with the configured one. + */ +/* #define FT_CONFIG_OPTION_USE_HARFBUZZ */ + + + /************************************************************************** + * + * Brotli support. + * + * FreeType uses the Brotli library to provide support for decompressing + * WOFF2 streams. + * + * Define this macro if you want to enable this 'feature'. + * + * If you use a build system like cmake or the `configure` script, + * options set by those programs have precedence, overwriting the value + * here with the configured one. + */ +/* #define FT_CONFIG_OPTION_USE_BROTLI */ + + + /************************************************************************** + * + * Glyph Postscript Names handling + * + * By default, FreeType 2 is compiled with the 'psnames' module. This + * module is in charge of converting a glyph name string into a Unicode + * value, or return a Macintosh standard glyph name for the use with the + * TrueType 'post' table. + * + * Undefine this macro if you do not want 'psnames' compiled in your + * build of FreeType. This has the following effects: + * + * - The TrueType driver will provide its own set of glyph names, if you + * build it to support postscript names in the TrueType 'post' table, + * but will not synthesize a missing Unicode charmap. + * + * - The Type~1 driver will not be able to synthesize a Unicode charmap + * out of the glyphs found in the fonts. + * + * You would normally undefine this configuration macro when building a + * version of FreeType that doesn't contain a Type~1 or CFF driver. + */ +/* #define FT_CONFIG_OPTION_POSTSCRIPT_NAMES */ + + + /************************************************************************** + * + * Postscript Names to Unicode Values support + * + * By default, FreeType~2 is built with the 'psnames' module compiled in. + * Among other things, the module is used to convert a glyph name into a + * Unicode value. This is especially useful in order to synthesize on + * the fly a Unicode charmap from the CFF/Type~1 driver through a big + * table named the 'Adobe Glyph List' (AGL). + * + * Undefine this macro if you do not want the Adobe Glyph List compiled + * in your 'psnames' module. The Type~1 driver will not be able to + * synthesize a Unicode charmap out of the glyphs found in the fonts. + */ +/* #define FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */ + + + /************************************************************************** + * + * Support for Mac fonts + * + * Define this macro if you want support for outline fonts in Mac format + * (mac dfont, mac resource, macbinary containing a mac resource) on + * non-Mac platforms. + * + * Note that the 'FOND' resource isn't checked. + */ +/* #define FT_CONFIG_OPTION_MAC_FONTS */ + + + /************************************************************************** + * + * Guessing methods to access embedded resource forks + * + * Enable extra Mac fonts support on non-Mac platforms (e.g., GNU/Linux). + * + * Resource forks which include fonts data are stored sometimes in + * locations which users or developers don't expected. In some cases, + * resource forks start with some offset from the head of a file. In + * other cases, the actual resource fork is stored in file different from + * what the user specifies. If this option is activated, FreeType tries + * to guess whether such offsets or different file names must be used. + * + * Note that normal, direct access of resource forks is controlled via + * the `FT_CONFIG_OPTION_MAC_FONTS` option. + */ +#ifdef FT_CONFIG_OPTION_MAC_FONTS +#define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK +#endif + + + /************************************************************************** + * + * Allow the use of `FT_Incremental_Interface` to load typefaces that + * contain no glyph data, but supply it via a callback function. This is + * required by clients supporting document formats which supply font data + * incrementally as the document is parsed, such as the Ghostscript + * interpreter for the PostScript language. + */ +#define FT_CONFIG_OPTION_INCREMENTAL + + + /************************************************************************** + * + * The size in bytes of the render pool used by the scan-line converter to + * do all of its work. + */ +#define FT_RENDER_POOL_SIZE 16384L + + + /************************************************************************** + * + * FT_MAX_MODULES + * + * The maximum number of modules that can be registered in a single + * FreeType library object. 32~is the default. + */ +#define FT_MAX_MODULES 32 + + + /************************************************************************** + * + * Debug level + * + * FreeType can be compiled in debug or trace mode. In debug mode, + * errors are reported through the 'ftdebug' component. In trace mode, + * additional messages are sent to the standard output during execution. + * + * Define `FT_DEBUG_LEVEL_ERROR` to build the library in debug mode. + * Define `FT_DEBUG_LEVEL_TRACE` to build it in trace mode. + * + * Don't define any of these macros to compile in 'release' mode! + * + * Do not `#undef` these macros here since the build system might define + * them for certain configurations only. + */ +/* #define FT_DEBUG_LEVEL_ERROR */ +/* #define FT_DEBUG_LEVEL_TRACE */ + + + /************************************************************************** + * + * Autofitter debugging + * + * If `FT_DEBUG_AUTOFIT` is defined, FreeType provides some means to + * control the autofitter behaviour for debugging purposes with global + * boolean variables (consequently, you should **never** enable this + * while compiling in 'release' mode): + * + * ``` + * _af_debug_disable_horz_hints + * _af_debug_disable_vert_hints + * _af_debug_disable_blue_hints + * ``` + * + * Additionally, the following functions provide dumps of various + * internal autofit structures to stdout (using `printf`): + * + * ``` + * af_glyph_hints_dump_points + * af_glyph_hints_dump_segments + * af_glyph_hints_dump_edges + * af_glyph_hints_get_num_segments + * af_glyph_hints_get_segment_offset + * ``` + * + * As an argument, they use another global variable: + * + * ``` + * _af_debug_hints + * ``` + * + * Please have a look at the `ftgrid` demo program to see how those + * variables and macros should be used. + * + * Do not `#undef` these macros here since the build system might define + * them for certain configurations only. + */ +/* #define FT_DEBUG_AUTOFIT */ + + + /************************************************************************** + * + * Memory Debugging + * + * FreeType now comes with an integrated memory debugger that is capable + * of detecting simple errors like memory leaks or double deletes. To + * compile it within your build of the library, you should define + * `FT_DEBUG_MEMORY` here. + * + * Note that the memory debugger is only activated at runtime when when + * the _environment_ variable `FT2_DEBUG_MEMORY` is defined also! + * + * Do not `#undef` this macro here since the build system might define it + * for certain configurations only. + */ +/* #define FT_DEBUG_MEMORY */ + + + /************************************************************************** + * + * Module errors + * + * If this macro is set (which is _not_ the default), the higher byte of + * an error code gives the module in which the error has occurred, while + * the lower byte is the real error code. + * + * Setting this macro makes sense for debugging purposes only, since it + * would break source compatibility of certain programs that use + * FreeType~2. + * + * More details can be found in the files `ftmoderr.h` and `fterrors.h`. + */ +#undef FT_CONFIG_OPTION_USE_MODULE_ERRORS + + + /************************************************************************** + * + * Error Strings + * + * If this macro is set, `FT_Error_String` will return meaningful + * descriptions. This is not enabled by default to reduce the overall + * size of FreeType. + * + * More details can be found in the file `fterrors.h`. + */ +/* #define FT_CONFIG_OPTION_ERROR_STRINGS */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** S F N T D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_EMBEDDED_BITMAPS` if you want to support + * embedded bitmaps in all formats using the 'sfnt' module (namely + * TrueType~& OpenType). + */ +/* #define TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_COLOR_LAYERS` if you want to support colored + * outlines (from the 'COLR'/'CPAL' tables) in all formats using the 'sfnt' + * module (namely TrueType~& OpenType). + */ +#define TT_CONFIG_OPTION_COLOR_LAYERS + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_POSTSCRIPT_NAMES` if you want to be able to + * load and enumerate the glyph Postscript names in a TrueType or OpenType + * file. + * + * Note that when you do not compile the 'psnames' module by undefining the + * above `FT_CONFIG_OPTION_POSTSCRIPT_NAMES`, the 'sfnt' module will + * contain additional code used to read the PS Names table from a font. + * + * (By default, the module uses 'psnames' to extract glyph names.) + */ +/* #define TT_CONFIG_OPTION_POSTSCRIPT_NAMES */ + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_SFNT_NAMES` if your applications need to access + * the internal name table in a SFNT-based format like TrueType or + * OpenType. The name table contains various strings used to describe the + * font, like family name, copyright, version, etc. It does not contain + * any glyph name though. + * + * Accessing SFNT names is done through the functions declared in + * `ftsnames.h`. + */ +#define TT_CONFIG_OPTION_SFNT_NAMES + + + /************************************************************************** + * + * TrueType CMap support + * + * Here you can fine-tune which TrueType CMap table format shall be + * supported. + */ +#define TT_CONFIG_CMAP_FORMAT_0 +#define TT_CONFIG_CMAP_FORMAT_2 +#define TT_CONFIG_CMAP_FORMAT_4 +#define TT_CONFIG_CMAP_FORMAT_6 +#define TT_CONFIG_CMAP_FORMAT_8 +#define TT_CONFIG_CMAP_FORMAT_10 +#define TT_CONFIG_CMAP_FORMAT_12 +#define TT_CONFIG_CMAP_FORMAT_13 +#define TT_CONFIG_CMAP_FORMAT_14 + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** T R U E T Y P E D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_BYTECODE_INTERPRETER` if you want to compile a + * bytecode interpreter in the TrueType driver. + * + * By undefining this, you will only compile the code necessary to load + * TrueType glyphs without hinting. + * + * Do not `#undef` this macro here, since the build system might define it + * for certain configurations only. + */ +#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_SUBPIXEL_HINTING` if you want to compile + * subpixel hinting support into the TrueType driver. This modifies the + * TrueType hinting mechanism when anything but `FT_RENDER_MODE_MONO` is + * requested. + * + * In particular, it modifies the bytecode interpreter to interpret (or + * not) instructions in a certain way so that all TrueType fonts look like + * they do in a Windows ClearType (DirectWrite) environment. See [1] for a + * technical overview on what this means. See `ttinterp.h` for more + * details on the LEAN option. + * + * There are three possible values. + * + * Value 1: + * This value is associated with the 'Infinality' moniker, contributed by + * an individual nicknamed Infinality with the goal of making TrueType + * fonts render better than on Windows. A high amount of configurability + * and flexibility, down to rules for single glyphs in fonts, but also + * very slow. Its experimental and slow nature and the original + * developer losing interest meant that this option was never enabled in + * default builds. + * + * The corresponding interpreter version is v38. + * + * Value 2: + * The new default mode for the TrueType driver. The Infinality code + * base was stripped to the bare minimum and all configurability removed + * in the name of speed and simplicity. The configurability was mainly + * aimed at legacy fonts like 'Arial', 'Times New Roman', or 'Courier'. + * Legacy fonts are fonts that modify vertical stems to achieve clean + * black-and-white bitmaps. The new mode focuses on applying a minimal + * set of rules to all fonts indiscriminately so that modern and web + * fonts render well while legacy fonts render okay. + * + * The corresponding interpreter version is v40. + * + * Value 3: + * Compile both, making both v38 and v40 available (the latter is the + * default). + * + * By undefining these, you get rendering behavior like on Windows without + * ClearType, i.e., Windows XP without ClearType enabled and Win9x + * (interpreter version v35). Or not, depending on how much hinting blood + * and testing tears the font designer put into a given font. If you + * define one or both subpixel hinting options, you can switch between + * between v35 and the ones you define (using `FT_Property_Set`). + * + * This option requires `TT_CONFIG_OPTION_BYTECODE_INTERPRETER` to be + * defined. + * + * [1] + * https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx + */ +/* #define TT_CONFIG_OPTION_SUBPIXEL_HINTING 1 */ +#define TT_CONFIG_OPTION_SUBPIXEL_HINTING 2 +/* #define TT_CONFIG_OPTION_SUBPIXEL_HINTING ( 1 | 2 ) */ + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED` to compile the + * TrueType glyph loader to use Apple's definition of how to handle + * component offsets in composite glyphs. + * + * Apple and MS disagree on the default behavior of component offsets in + * composites. Apple says that they should be scaled by the scaling + * factors in the transformation matrix (roughly, it's more complex) while + * MS says they should not. OpenType defines two bits in the composite + * flags array which can be used to disambiguate, but old fonts will not + * have them. + * + * https://www.microsoft.com/typography/otspec/glyf.htm + * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html + */ +#undef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_GX_VAR_SUPPORT` if you want to include support + * for Apple's distortable font technology ('fvar', 'gvar', 'cvar', and + * 'avar' tables). Tagged 'Font Variations', this is now part of OpenType + * also. This has many similarities to Type~1 Multiple Masters support. + */ +#define TT_CONFIG_OPTION_GX_VAR_SUPPORT + + + /************************************************************************** + * + * Define `TT_CONFIG_OPTION_BDF` if you want to include support for an + * embedded 'BDF~' table within SFNT-based bitmap formats. + */ +/* #define TT_CONFIG_OPTION_BDF */ + + + /************************************************************************** + * + * Option `TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES` controls the maximum + * number of bytecode instructions executed for a single run of the + * bytecode interpreter, needed to prevent infinite loops. You don't want + * to change this except for very special situations (e.g., making a + * library fuzzer spend less time to handle broken fonts). + * + * It is not expected that this value is ever modified by a configuring + * script; instead, it gets surrounded with `#ifndef ... #endif` so that + * the value can be set as a preprocessor option on the compiler's command + * line. + */ +#ifndef TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES +#define TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES 1000000L +#endif + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** T Y P E 1 D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************** + * + * `T1_MAX_DICT_DEPTH` is the maximum depth of nest dictionaries and arrays + * in the Type~1 stream (see `t1load.c`). A minimum of~4 is required. + */ +#define T1_MAX_DICT_DEPTH 5 + + + /************************************************************************** + * + * `T1_MAX_SUBRS_CALLS` details the maximum number of nested sub-routine + * calls during glyph loading. + */ +#define T1_MAX_SUBRS_CALLS 16 + + + /************************************************************************** + * + * `T1_MAX_CHARSTRING_OPERANDS` is the charstring stack's capacity. A + * minimum of~16 is required. + * + * The Chinese font 'MingTiEG-Medium' (covering the CNS 11643 character + * set) needs 256. + */ +#define T1_MAX_CHARSTRINGS_OPERANDS 256 + + + /************************************************************************** + * + * Define this configuration macro if you want to prevent the compilation + * of the 't1afm' module, which is in charge of reading Type~1 AFM files + * into an existing face. Note that if set, the Type~1 driver will be + * unable to produce kerning distances. + */ +#undef T1_CONFIG_OPTION_NO_AFM + + + /************************************************************************** + * + * Define this configuration macro if you want to prevent the compilation + * of the Multiple Masters font support in the Type~1 driver. + */ +#undef T1_CONFIG_OPTION_NO_MM_SUPPORT + + + /************************************************************************** + * + * `T1_CONFIG_OPTION_OLD_ENGINE` controls whether the pre-Adobe Type~1 + * engine gets compiled into FreeType. If defined, it is possible to + * switch between the two engines using the `hinting-engine` property of + * the 'type1' driver module. + */ +/* #define T1_CONFIG_OPTION_OLD_ENGINE */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** C F F D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************** + * + * Using `CFF_CONFIG_OPTION_DARKENING_PARAMETER_{X,Y}{1,2,3,4}` it is + * possible to set up the default values of the four control points that + * define the stem darkening behaviour of the (new) CFF engine. For more + * details please read the documentation of the `darkening-parameters` + * property (file `ftdriver.h`), which allows the control at run-time. + * + * Do **not** undefine these macros! + */ +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 500 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 400 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 1000 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 275 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 1667 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 275 + +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 2333 +#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 0 + + + /************************************************************************** + * + * `CFF_CONFIG_OPTION_OLD_ENGINE` controls whether the pre-Adobe CFF engine + * gets compiled into FreeType. If defined, it is possible to switch + * between the two engines using the `hinting-engine` property of the 'cff' + * driver module. + */ +/* #define CFF_CONFIG_OPTION_OLD_ENGINE */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** P C F D R I V E R C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************** + * + * There are many PCF fonts just called 'Fixed' which look completely + * different, and which have nothing to do with each other. When selecting + * 'Fixed' in KDE or Gnome one gets results that appear rather random, the + * style changes often if one changes the size and one cannot select some + * fonts at all. This option makes the 'pcf' module prepend the foundry + * name (plus a space) to the family name. + * + * We also check whether we have 'wide' characters; all put together, we + * get family names like 'Sony Fixed' or 'Misc Fixed Wide'. + * + * If this option is activated, it can be controlled with the + * `no-long-family-names` property of the 'pcf' driver module. + */ +/* #define PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */ + + + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** A U T O F I T M O D U L E C O N F I G U R A T I O N ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************** + * + * Compile 'autofit' module with CJK (Chinese, Japanese, Korean) script + * support. + */ +#define AF_CONFIG_OPTION_CJK + + + /************************************************************************** + * + * Compile 'autofit' module with fallback Indic script support, covering + * some scripts that the 'latin' submodule of the 'autofit' module doesn't + * (yet) handle. Currently, this needs option `AF_CONFIG_OPTION_CJK`. + */ +#ifdef AF_CONFIG_OPTION_CJK +#define AF_CONFIG_OPTION_INDIC +#endif + + + /************************************************************************** + * + * Compile 'autofit' module with warp hinting. The idea of the warping + * code is to slightly scale and shift a glyph within a single dimension so + * that as much of its segments are aligned (more or less) on the grid. To + * find out the optimal scaling and shifting value, various parameter + * combinations are tried and scored. + * + * You can switch warping on and off with the `warping` property of the + * auto-hinter (see file `ftdriver.h` for more information; by default it + * is switched off). + * + * This experimental option is not active if the rendering mode is + * `FT_RENDER_MODE_LIGHT`. + */ +#define AF_CONFIG_OPTION_USE_WARPER + + + /************************************************************************** + * + * Use TrueType-like size metrics for 'light' auto-hinting. + * + * It is strongly recommended to avoid this option, which exists only to + * help some legacy applications retain its appearance and behaviour with + * respect to auto-hinted TrueType fonts. + * + * The very reason this option exists at all are GNU/Linux distributions + * like Fedora that did not un-patch the following change (which was + * present in FreeType between versions 2.4.6 and 2.7.1, inclusive). + * + * ``` + * 2011-07-16 Steven Chu + * + * [truetype] Fix metrics on size request for scalable fonts. + * ``` + * + * This problematic commit is now reverted (more or less). + */ +/* #define AF_CONFIG_OPTION_TT_SIZE_METRICS */ + + /* */ + + + /* + * This macro is obsolete. Support has been removed in FreeType version + * 2.5. + */ +/* #define FT_CONFIG_OPTION_OLD_INTERNALS */ + + + /* + * The next three macros are defined if native TrueType hinting is + * requested by the definitions above. Don't change this. + */ +#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER +#define TT_USE_BYTECODE_INTERPRETER + +#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING +#if TT_CONFIG_OPTION_SUBPIXEL_HINTING & 1 +#define TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY +#endif + +#if TT_CONFIG_OPTION_SUBPIXEL_HINTING & 2 +#define TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL +#endif +#endif +#endif + + + /* + * Check CFF darkening parameters. The checks are the same as in function + * `cff_property_set` in file `cffdrivr.c`. + */ +#if CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 < 0 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 < 0 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 < 0 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 > \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 || \ + \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 > 500 || \ + CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 > 500 +#error "Invalid CFF darkening parameters!" +#endif + +FT_END_HEADER + + +#endif /* FTOPTION_H_ */ + + +/* END */ diff --git a/deps/config/libjpeg-turbo/jconfig.h b/deps/config/libjpeg-turbo/jconfig.h new file mode 100644 index 0000000..264ef22 --- /dev/null +++ b/deps/config/libjpeg-turbo/jconfig.h @@ -0,0 +1,67 @@ +/* Version ID for the JPEG library. + * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". + */ +#define JPEG_LIB_VERSION 80 /* Version 6b */ + +/* libjpeg-turbo version */ +#define LIBJPEG_TURBO_VERSION 0 + +/* libjpeg-turbo version in integer form */ +#define LIBJPEG_TURBO_VERSION_NUMBER 0 + +/* Support arithmetic encoding */ +#define C_ARITH_CODING_SUPPORTED 1 + +/* Support arithmetic decoding */ +#define D_ARITH_CODING_SUPPORTED 1 + +/* + * Define BITS_IN_JSAMPLE as either + * 8 for 8-bit sample values (the usual setting) + * 12 for 12-bit sample values + * Only 8 and 12 are legal data precisions for lossy JPEG according to the + * JPEG standard, and the IJG code does not support anything else! + * We do not support run-time selection of data precision, sorry. + */ + +#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_LOCALE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDDEF_H + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if the system has the type `unsigned char'. */ +#define HAVE_UNSIGNED_CHAR 1 + +/* Define to 1 if the system has the type `unsigned short'. */ +#define HAVE_UNSIGNED_SHORT 1 + +/* Compiler does not support pointers to undefined structures. */ +#undef INCOMPLETE_TYPES_BROKEN + +/* Support in-memory source/destination managers */ +#undef MEM_SRCDST_SUPPORTED + +/* Define if you have BSD-like bzero and bcopy in rather than + memset/memcpy in . */ +#undef NEED_BSD_STRINGS + +/* Define if you need to include to get size_t. */ +#undef NEED_SYS_TYPES_H + +/* Define if your (broken) compiler shifts signed values as if they were + unsigned. */ +#undef RIGHT_SHIFT_IS_UNSIGNED + +/* Use accelerated SIMD routines. */ +#undef WITH_SIMD + +/* Define to 1 if type `char' is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +# undef __CHAR_UNSIGNED__ +#endif diff --git a/deps/config/libjpeg-turbo/jconfigint.h b/deps/config/libjpeg-turbo/jconfigint.h new file mode 100644 index 0000000..8655aec --- /dev/null +++ b/deps/config/libjpeg-turbo/jconfigint.h @@ -0,0 +1,11 @@ +/* libjpeg-turbo build number */ +#define BUILD "0" + +/* Compiler's inline keyword */ +#include + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "jpeg-turbo" + +/* Version number of package */ +#define VERSION "80" diff --git a/deps/config/libogg/os_types.h b/deps/config/libogg/os_types.h new file mode 100644 index 0000000..b3fb0f2 --- /dev/null +++ b/deps/config/libogg/os_types.h @@ -0,0 +1,34 @@ +/******************************************************************** + * * + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * + * * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * + * by the Xiph.Org Foundation http://www.xiph.org/ * + * * + ******************************************************************** + + function: Define a consistent set of types on each platform. + + ********************************************************************/ +#ifndef _OS_TYPES_H +#define _OS_TYPES_H + +/* make it easy on the folks that want to compile the libs with a + different malloc than stdlib */ +#define _ogg_malloc malloc +#define _ogg_calloc calloc +#define _ogg_realloc realloc +#define _ogg_free free + +#include +typedef int16_t ogg_int16_t; +typedef uint16_t ogg_uint16_t; +typedef int32_t ogg_int32_t; +typedef uint32_t ogg_uint32_t; +typedef int64_t ogg_int64_t; +typedef uint64_t ogg_uint64_t; + +#endif /* _OS_TYPES_H */ diff --git a/deps/config/sdl/SDL_config.h b/deps/config/sdl/SDL_config.h new file mode 100644 index 0000000..3613159 --- /dev/null +++ b/deps/config/sdl/SDL_config.h @@ -0,0 +1,27 @@ +#ifndef _SDL_config_h +#define _SDL_config_h +#include "SDL_platform.h" + +/* C datatypes */ +#define SDL_HAS_64BIT_TYPE 1 + +/* Endianness */ +#define SDL_BYTEORDER 1234 + +/* Useful headers */ +#define HAVE_STDIO_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STDARG_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STDINT_H 1 + +/* Enable various drivers */ +#define SDL_AUDIO_DRIVER_DUMMY 1 +#define SDL_CDROM_DISABLED 1 +#define SDL_JOYSTICK_DISABLED 1 +#define SDL_LOADSO_DISABLED 1 +#define SDL_THREAD_PTHREAD 1 +#define SDL_TIMER_DUMMY 1 +#define SDL_VIDEO_DRIVER_DUMMY 1 + +#endif /* _SDL_config_h */ diff --git a/deps/libretro-common b/deps/libretro-common new file mode 160000 index 0000000..e1afa1c --- /dev/null +++ b/deps/libretro-common @@ -0,0 +1 @@ +Subproject commit e1afa1c975f72787e6075897c66839614e8f1fdc diff --git a/deps/tinycoroutine b/deps/tinycoroutine new file mode 160000 index 0000000..2f8b69f --- /dev/null +++ b/deps/tinycoroutine @@ -0,0 +1 @@ +Subproject commit 2f8b69f3b078b53316facf8f3cd659f2b2744ee9 diff --git a/libretro.cpp b/libretro.cpp new file mode 100644 index 0000000..2434c04 --- /dev/null +++ b/libretro.cpp @@ -0,0 +1,212 @@ +#include +#include +#include +#include +#include + +retro_usec_t SDL_libretro_now = 0; +retro_audio_sample_batch_t SDL_libretro_audio_batch_cb; +retro_input_state_t SDL_libretro_input_state_cb; + +static void fallback_log(enum retro_log_level level, const char *fmt, ...); +static retro_video_refresh_t video_cb; +static retro_input_poll_t input_poll_cb; + +static retro_log_printf_t log_cb = fallback_log; +static retro_environment_t environ_cb; +static struct tinyco_t tinyco; +static ONScripter ons; +static uint8_t ons_stack[64*1024]; + + +void SDL_libretro_co_spawn(void (*fn)(void *), void *data, void *stack, size_t stack_size) +{ + tinyco_spawn(&tinyco, fn, data, stack, stack_size); +} + +void SDL_libretro_co_yield(void) +{ + tinyco_yield(&tinyco); +} + +void SDL_libretro_video_refresh() +{ + static SDL_Surface *screen = SDL_GetVideoSurface(); + video_cb(screen->pixels, screen->w, screen->h, screen->pitch); + SDL_libretro_co_yield(); +} + +static void fallback_log(enum retro_log_level level, const char *fmt, ...) +{ + (void)level; + va_list va; + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); +} + +unsigned retro_api_version(void) +{ + return RETRO_API_VERSION; +} + +static void on_frame_time(retro_usec_t usec) +{ + SDL_libretro_now += usec; +} + +void retro_set_environment(retro_environment_t cb) +{ + static struct retro_log_callback log; + environ_cb = cb; + if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) + log_cb = log.log; + + static struct retro_frame_time_callback frame_time = { + .callback = on_frame_time, + .reference = 1000000 / 60, + }; + environ_cb(RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK, &frame_time); +} + +void retro_set_video_refresh(retro_video_refresh_t cb) +{ + video_cb = cb; +} + +void retro_set_audio_sample(retro_audio_sample_t cb) +{ +} + +void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) +{ + SDL_libretro_audio_batch_cb = cb; +} + +void retro_set_input_poll(retro_input_poll_t cb) +{ + input_poll_cb = cb; +} + +void retro_set_input_state(retro_input_state_t cb) +{ + SDL_libretro_input_state_cb = cb; +} + +void retro_get_system_info(struct retro_system_info *info) +{ + info->need_fullpath = true; + info->valid_extensions = "txt|dat|___"; + info->library_version = "0.1"; + info->library_name = "onscripter"; + info->block_extract = false; +} + +void retro_get_system_av_info(struct retro_system_av_info *info) +{ + int width = ons.getWidth(); + int height = ons.getHeight(); + info->geometry.base_width = width; + info->geometry.base_height = height; + info->geometry.max_width = width; + info->geometry.max_height = height; + info->timing.fps = 60.0; + info->timing.sample_rate = 44100.0; +} + +void retro_init(void) +{ + enum retro_pixel_format pixfmt = RETRO_PIXEL_FORMAT_XRGB8888; + environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &pixfmt); + + tinyco_init(&tinyco, NULL, NULL); +} + +static void ons_main(void *unused) +{ + if (ons.init()) { + log_cb(RETRO_LOG_ERROR, "Failed to initialize ONScripter\n"); + return; + } + ons.executeLabel(); +} + +bool retro_load_game(const struct retro_game_info *game) +{ + if (!game) + return false; + + char archive_path[PATH_MAX_LENGTH]; + fill_pathname_basedir(archive_path, game->path, sizeof(archive_path)); + ons.setArchivePath(archive_path); + + if (ons.openScript() != 0) { + return false; + } + + SDL_libretro_co_spawn(ons_main, NULL, ons_stack, sizeof(ons_stack)); + return true; +} + +void retro_set_controller_port_device(unsigned port, unsigned device) +{ +} + +void retro_deinit(void) +{ +} + +void retro_reset(void) +{ + ons.resetCommand(); +} + +void retro_run(void) +{ + input_poll_cb(); + for (int i = 0; i < tinyco.context_count; ++i) { + SDL_libretro_co_yield(); + } +} + +size_t retro_serialize_size(void) +{ + return 0; +} + +bool retro_serialize(void *data, size_t size) +{ + return false; +} + +bool retro_unserialize(const void *data, size_t size) +{ + return false; +} + +void retro_cheat_reset(void) {} +void retro_cheat_set(unsigned index, bool enabled, const char *code) {} + +bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) +{ + return false; +} + +void retro_unload_game(void) +{ +} + +unsigned retro_get_region(void) +{ + return RETRO_REGION_NTSC; +} + +void *retro_get_memory_data(unsigned id) +{ + return 0; +} + +size_t retro_get_memory_size(unsigned id) +{ + return 0; +} diff --git a/link.T b/link.T new file mode 100644 index 0000000..b0c262d --- /dev/null +++ b/link.T @@ -0,0 +1,5 @@ +{ + global: retro_*; + local: *; +}; + diff --git a/sdl-libretro/SDL_libretro.h b/sdl-libretro/SDL_libretro.h new file mode 100644 index 0000000..cfeb5cc --- /dev/null +++ b/sdl-libretro/SDL_libretro.h @@ -0,0 +1,21 @@ +#ifndef _SDL_LIBRETRO_H +#define _SDL_LIBRETRO_H +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void SDL_libretro_co_spawn(void (*fn)(void *), void *data, void *stack, size_t stack_size); +void SDL_libretro_co_yield(void); +void SDL_libretro_video_refresh(); + +extern retro_usec_t SDL_libretro_now; +extern retro_audio_sample_batch_t SDL_libretro_audio_batch_cb; +extern retro_input_state_t SDL_libretro_input_state_cb; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/sdl-libretro/audio.c b/sdl-libretro/audio.c new file mode 100644 index 0000000..5c1e01d --- /dev/null +++ b/sdl-libretro/audio.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include + +/* The tag name used by DUMMY audio */ +#define DUMMYAUD_DRIVER_NAME "dummy" + +/* Audio driver functions */ +static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec); +static void DUMMYAUD_WaitAudio(_THIS); +static void DUMMYAUD_PlayAudio(_THIS); +static Uint8 *DUMMYAUD_GetAudioBuf(_THIS); +static void DUMMYAUD_CloseAudio(_THIS); + +/* Audio driver bootstrap functions */ +static int DUMMYAUD_Available(void) +{ + return 1; +} + +static void DUMMYAUD_DeleteDevice(SDL_AudioDevice *device) +{ + SDL_free(device->hidden); + SDL_free(device); +} + +static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex) +{ + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); + if (this) { + SDL_memset(this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + SDL_malloc((sizeof *this->hidden)); + } + if (this == NULL || this->hidden == NULL) { + SDL_OutOfMemory(); + if (this) { + SDL_free(this); + } + return 0; + } + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = DUMMYAUD_OpenAudio; + this->WaitAudio = DUMMYAUD_WaitAudio; + this->PlayAudio = DUMMYAUD_PlayAudio; + this->GetAudioBuf = DUMMYAUD_GetAudioBuf; + this->CloseAudio = DUMMYAUD_CloseAudio; + + this->free = DUMMYAUD_DeleteDevice; + + return this; +} + +AudioBootStrap DUMMYAUD_bootstrap = { + DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver", + DUMMYAUD_Available, DUMMYAUD_CreateDevice +}; + + +static void DUMMYAUD_WaitAudio(_THIS) +{ +} + +static void DUMMYAUD_PlayAudio(_THIS) +{ + SDL_AudioSpec *spec = &this->spec; + Sint16 *ptr=(Sint16*)this->hidden->mixbuf; + SDL_libretro_audio_batch_cb(ptr, spec->samples); + SDL_libretro_video_refresh(); +} + +static Uint8 *DUMMYAUD_GetAudioBuf(_THIS) +{ + return(this->hidden->mixbuf); +} + +static void DUMMYAUD_CloseAudio(_THIS) +{ + if (this->hidden->mixbuf != NULL) { + SDL_FreeAudioMem(this->hidden->mixbuf); + this->hidden->mixbuf = NULL; + } +} + + +static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) +{ + spec->samples = 44100 / 60; + SDL_CalculateAudioSpec(spec); + this->hidden->mixlen = spec->size; + this->hidden->mixbuf = (Uint8 *)SDL_AllocAudioMem(this->hidden->mixlen); + if (this->hidden->mixbuf == NULL) { + return -1; + } + SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); + + /* We're ready to rock and roll. :-) */ + return 0; +} diff --git a/sdl-libretro/events.c b/sdl-libretro/events.c new file mode 100644 index 0000000..b275421 --- /dev/null +++ b/sdl-libretro/events.c @@ -0,0 +1,60 @@ +#include +#include +#include + + +static void PumpKeyboardEvents(void) +{ + static int16_t keys[RETROK_LAST] = {0}; + static SDL_keysym sym; + for (int i = 0; i < RETROK_LAST; ++i) { + int16_t state = SDL_libretro_input_state_cb(0, RETRO_DEVICE_KEYBOARD, 0, i); + if (keys[i] != state) { + keys[i] = state; + sym.scancode = i; + sym.sym = i; + SDL_PrivateKeyboard(state ? SDL_PRESSED : SDL_RELEASED, &sym); + } + } +} + +static void PumpMouseEvents(void) +{ + int16_t x = SDL_libretro_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + int16_t y = SDL_libretro_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); + if (x != 0 || y != 0) + SDL_PrivateMouseMotion(0, 1, x, y); + + static uint16_t btn_left = 0; + static uint16_t btn_middle = 0; + static uint16_t btn_right = 0; + uint16_t state; + + state = SDL_libretro_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT); + if (state != btn_left) { + btn_left = state; + SDL_PrivateMouseButton(state ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); + } + + state = SDL_libretro_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE); + if (state != btn_middle) { + btn_middle = state; + SDL_PrivateMouseButton(state ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); + } + + state = SDL_libretro_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT); + if (state != btn_right) { + btn_right = state; + SDL_PrivateMouseButton(state ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); + } +} + +void DUMMY_PumpEvents(_THIS) +{ + PumpKeyboardEvents(); + PumpMouseEvents(); +} + +void DUMMY_InitOSKeymap(_THIS) +{ +} diff --git a/sdl-libretro/thread.c b/sdl-libretro/thread.c new file mode 100644 index 0000000..df08271 --- /dev/null +++ b/sdl-libretro/thread.c @@ -0,0 +1,94 @@ +#include +#include +#include + + +extern void SDL_RunThread(void *data); + +struct SDL_semaphore { + Uint32 value; +}; + + +SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) +{ + SDL_sem *sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); + if (sem) { + sem->value = initial_value; + } else { + SDL_OutOfMemory(); + } + return sem; +} + +void SDL_DestroySemaphore(SDL_sem *sem) +{ + if (sem) { + SDL_free(sem); + } +} + +int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) +{ + Uint32 x = SDL_GetTicks(); + do { + if (sem->value) { + sem->value -= 1; + return 0; + } + SDL_libretro_co_yield(); + } while (SDL_GetTicks() - x < timeout); + + return SDL_MUTEX_TIMEDOUT; +} + +int SDL_SemTryWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, 0); +} + +int SDL_SemWait(SDL_sem *sem) +{ + return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); +} + +Uint32 SDL_SemValue(SDL_sem *sem) +{ + return sem->value; +} + +int SDL_SemPost(SDL_sem *sem) +{ + sem->value += 1; + return 0; +} + +int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) +{ + size_t stack_size = 64*1024; + void *stack = SDL_malloc(stack_size); + if (stack == NULL) { + SDL_OutOfMemory(); + return -1; + } + SDL_libretro_co_spawn(SDL_RunThread, args, stack, stack_size); + return 0; +} + +void SDL_SYS_SetupThread(void) +{ +} + +Uint32 SDL_ThreadID(void) +{ + return 0; +} + +void SDL_SYS_WaitThread(SDL_Thread *thread) +{ +} + +void SDL_SYS_KillThread(SDL_Thread *thread) +{ + return; +} diff --git a/sdl-libretro/timer.c b/sdl-libretro/timer.c new file mode 100644 index 0000000..5b112c4 --- /dev/null +++ b/sdl-libretro/timer.c @@ -0,0 +1,49 @@ +#include +#include + +static uint8_t timer_stack[4*1024]; + +void SDL_StartTicks(void) +{ +} + +Uint32 SDL_GetTicks(void) +{ + return SDL_libretro_now / 1000; +} + +void SDL_Delay(Uint32 ms) +{ + Uint32 x = SDL_GetTicks(); + do { + SDL_libretro_co_yield(); + } while (SDL_GetTicks() - x < ms); +} + +void RunTimer(void *unsued) +{ + while (true) { + SDL_ThreadedTimerCheck(); + SDL_libretro_co_yield(); + } +} + +int SDL_SYS_TimerInit(void) +{ + SDL_libretro_co_spawn(RunTimer, NULL, &timer_stack, sizeof(timer_stack)); + return SDL_SetTimerThreaded(1); +} + +void SDL_SYS_TimerQuit(void) +{ +} + +int SDL_SYS_StartTimer(void) +{ + SDL_SetError("Internal logic error: threaded timer in use"); + return -1; +} + +void SDL_SYS_StopTimer(void) +{ +} diff --git a/sdl-libretro/video.c b/sdl-libretro/video.c new file mode 100644 index 0000000..8f8dba9 --- /dev/null +++ b/sdl-libretro/video.c @@ -0,0 +1,192 @@ +#include +#include +#include +#include +#include + + +#define DUMMYVID_DRIVER_NAME "dummy" + +/* Initialization/Query functions */ +static int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat); +static SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); +static SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); +static int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); +static void DUMMY_VideoQuit(_THIS); + +/* Hardware surface functions */ +static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface); +static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface); +static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface); +static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface); + +/* etc. */ +static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects); + +/* DUMMY driver bootstrap functions */ + +static int DUMMY_Available(void) +{ + return 1; +} + +static void DUMMY_DeleteDevice(SDL_VideoDevice *device) +{ + SDL_free(device->hidden); + SDL_free(device); +} + +static SDL_VideoDevice *DUMMY_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); + if (device) { + SDL_memset(device, 0, (sizeof *device)); + device->hidden = (struct SDL_PrivateVideoData *) + SDL_malloc(sizeof(*device->hidden)); + } + if (device == NULL || device->hidden == NULL) { + SDL_OutOfMemory(); + if (device) { + SDL_free(device); + } + return 0; + } + SDL_memset(device->hidden, 0, sizeof(*device->hidden)); + + /* Set the function pointers */ + device->VideoInit = DUMMY_VideoInit; + device->ListModes = DUMMY_ListModes; + device->SetVideoMode = DUMMY_SetVideoMode; + device->CreateYUVOverlay = NULL; + device->SetColors = DUMMY_SetColors; + device->UpdateRects = DUMMY_UpdateRects; + device->VideoQuit = DUMMY_VideoQuit; + device->AllocHWSurface = DUMMY_AllocHWSurface; + device->CheckHWBlit = NULL; + device->FillHWRect = NULL; + device->SetHWColorKey = NULL; + device->SetHWAlpha = NULL; + device->LockHWSurface = DUMMY_LockHWSurface; + device->UnlockHWSurface = DUMMY_UnlockHWSurface; + device->FlipHWSurface = NULL; + device->FreeHWSurface = DUMMY_FreeHWSurface; + device->SetCaption = NULL; + device->SetIcon = NULL; + device->IconifyWindow = NULL; + device->GrabInput = NULL; + device->GetWMInfo = NULL; + device->InitOSKeymap = DUMMY_InitOSKeymap; + device->PumpEvents = DUMMY_PumpEvents; + + device->free = DUMMY_DeleteDevice; + + return device; +} + +VideoBootStrap DUMMY_bootstrap = { + DUMMYVID_DRIVER_NAME, "SDL dummy video driver", + DUMMY_Available, DUMMY_CreateDevice +}; + + +int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat) +{ + /* + fprintf(stderr, "WARNING: You are using the SDL dummy video driver!\n"); + */ + + /* Determine the screen depth (use default 8-bit depth) */ + /* we change this during the SDL_SetVideoMode implementation... */ + vformat->BitsPerPixel = 8; + vformat->BytesPerPixel = 1; + + /* We're done! */ + return 0; +} + +SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) +{ + return (SDL_Rect **) -1; +} + +SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, + int width, int height, int bpp, Uint32 flags) +{ + if (this->hidden->buffer) { + SDL_free(this->hidden->buffer); + } + + this->hidden->buffer = SDL_malloc(width * height * (bpp / 8)); + if (!this->hidden->buffer) { + SDL_SetError("Couldn't allocate buffer for requested mode"); + return(NULL); + } + + /* printf("Setting mode %dx%d\n", width, height); */ + + SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8)); + + /* Allocate the new pixel format for the screen */ + if (!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) { + SDL_free(this->hidden->buffer); + this->hidden->buffer = NULL; + SDL_SetError("Couldn't allocate new pixel format for requested mode"); + return(NULL); + } + + /* Set up the new mode framebuffer */ + current->flags = flags & SDL_FULLSCREEN; + this->hidden->w = current->w = width; + this->hidden->h = current->h = height; + current->pitch = current->w * (bpp / 8); + current->pixels = this->hidden->buffer; + + /* We're done */ + return current; +} + +/* We don't actually allow hardware surfaces other than the main one */ +static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface) +{ + return -1; +} +static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface) +{ + return; +} + +/* We need to wait for vertical retrace on page flipped displays */ +static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface) +{ + return 0; +} + +static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface) +{ + return; +} + +static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects) +{ + SDL_libretro_co_yield(); +} + +int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) +{ + /* do nothing of note. */ + return 1; +} + +/* Note: If we are terminated, this could be called in the middle of + another SDL video routine -- notably UpdateRects. +*/ +void DUMMY_VideoQuit(_THIS) +{ + if (this->screen->pixels != NULL) { + SDL_free(this->screen->pixels); + this->screen->pixels = NULL; + } +}