diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b7a669a..0a96fe7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,6 +244,7 @@ extern/adpcm/ymz_codec.c extern/Nuked-OPN2/ym3438.c extern/opm/opm.c +extern/Nuked-OPLL/opll.c src/engine/platform/sound/sn76496.cpp src/engine/platform/sound/ay8910.cpp src/engine/platform/sound/saa1099.cpp @@ -304,6 +305,7 @@ src/engine/platform/abstract.cpp src/engine/platform/genesis.cpp src/engine/platform/genesisext.cpp src/engine/platform/sms.cpp +src/engine/platform/opll.cpp src/engine/platform/gb.cpp src/engine/platform/pce.cpp src/engine/platform/nes.cpp diff --git a/extern/Nuked-OPLL/.github/FUNDING.yml b/extern/Nuked-OPLL/.github/FUNDING.yml new file mode 100644 index 00000000..e778d684 --- /dev/null +++ b/extern/Nuked-OPLL/.github/FUNDING.yml @@ -0,0 +1,12 @@ + # These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: nukeykt # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: ['https://www.buymeacoffee.com/nukeykt', 'https://paypal.me/nukeykt'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/extern/Nuked-OPLL/LICENSE b/extern/Nuked-OPLL/LICENSE new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/extern/Nuked-OPLL/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE 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. + + 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 +convey 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 2 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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. diff --git a/extern/Nuked-OPLL/opll.c b/extern/Nuked-OPLL/opll.c new file mode 100644 index 00000000..fd2aa239 --- /dev/null +++ b/extern/Nuked-OPLL/opll.c @@ -0,0 +1,1107 @@ +/* + * Copyright (C) 2019 Nuke.YKT + * + * 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 2 + * 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. + * + * + * Yamaha YM2413 emulator + * Thanks: + * siliconpr0n.org(digshadow, John McMaster): + * VRC VII decap and die shot. + * + * version: 1.0.1 + */ + +#include +#include "opll.h" + +enum { + eg_num_attack = 0, + eg_num_decay = 1, + eg_num_sustain = 2, + eg_num_release = 3 +}; + +enum { + rm_num_bd0 = 0, + rm_num_hh = 1, + rm_num_tom = 2, + rm_num_bd1 = 3, + rm_num_sd = 4, + rm_num_tc = 5 +}; + +/* logsin table */ +static const uint16_t logsinrom[256] = { + 0x859, 0x6c3, 0x607, 0x58b, 0x52e, 0x4e4, 0x4a6, 0x471, + 0x443, 0x41a, 0x3f5, 0x3d3, 0x3b5, 0x398, 0x37e, 0x365, + 0x34e, 0x339, 0x324, 0x311, 0x2ff, 0x2ed, 0x2dc, 0x2cd, + 0x2bd, 0x2af, 0x2a0, 0x293, 0x286, 0x279, 0x26d, 0x261, + 0x256, 0x24b, 0x240, 0x236, 0x22c, 0x222, 0x218, 0x20f, + 0x206, 0x1fd, 0x1f5, 0x1ec, 0x1e4, 0x1dc, 0x1d4, 0x1cd, + 0x1c5, 0x1be, 0x1b7, 0x1b0, 0x1a9, 0x1a2, 0x19b, 0x195, + 0x18f, 0x188, 0x182, 0x17c, 0x177, 0x171, 0x16b, 0x166, + 0x160, 0x15b, 0x155, 0x150, 0x14b, 0x146, 0x141, 0x13c, + 0x137, 0x133, 0x12e, 0x129, 0x125, 0x121, 0x11c, 0x118, + 0x114, 0x10f, 0x10b, 0x107, 0x103, 0x0ff, 0x0fb, 0x0f8, + 0x0f4, 0x0f0, 0x0ec, 0x0e9, 0x0e5, 0x0e2, 0x0de, 0x0db, + 0x0d7, 0x0d4, 0x0d1, 0x0cd, 0x0ca, 0x0c7, 0x0c4, 0x0c1, + 0x0be, 0x0bb, 0x0b8, 0x0b5, 0x0b2, 0x0af, 0x0ac, 0x0a9, + 0x0a7, 0x0a4, 0x0a1, 0x09f, 0x09c, 0x099, 0x097, 0x094, + 0x092, 0x08f, 0x08d, 0x08a, 0x088, 0x086, 0x083, 0x081, + 0x07f, 0x07d, 0x07a, 0x078, 0x076, 0x074, 0x072, 0x070, + 0x06e, 0x06c, 0x06a, 0x068, 0x066, 0x064, 0x062, 0x060, + 0x05e, 0x05c, 0x05b, 0x059, 0x057, 0x055, 0x053, 0x052, + 0x050, 0x04e, 0x04d, 0x04b, 0x04a, 0x048, 0x046, 0x045, + 0x043, 0x042, 0x040, 0x03f, 0x03e, 0x03c, 0x03b, 0x039, + 0x038, 0x037, 0x035, 0x034, 0x033, 0x031, 0x030, 0x02f, + 0x02e, 0x02d, 0x02b, 0x02a, 0x029, 0x028, 0x027, 0x026, + 0x025, 0x024, 0x023, 0x022, 0x021, 0x020, 0x01f, 0x01e, + 0x01d, 0x01c, 0x01b, 0x01a, 0x019, 0x018, 0x017, 0x017, + 0x016, 0x015, 0x014, 0x014, 0x013, 0x012, 0x011, 0x011, + 0x010, 0x00f, 0x00f, 0x00e, 0x00d, 0x00d, 0x00c, 0x00c, + 0x00b, 0x00a, 0x00a, 0x009, 0x009, 0x008, 0x008, 0x007, + 0x007, 0x007, 0x006, 0x006, 0x005, 0x005, 0x005, 0x004, + 0x004, 0x004, 0x003, 0x003, 0x003, 0x002, 0x002, 0x002, + 0x002, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 +}; + +/* exp table */ +static const uint16_t exprom[256] = { + 0x7fa, 0x7f5, 0x7ef, 0x7ea, 0x7e4, 0x7df, 0x7da, 0x7d4, + 0x7cf, 0x7c9, 0x7c4, 0x7bf, 0x7b9, 0x7b4, 0x7ae, 0x7a9, + 0x7a4, 0x79f, 0x799, 0x794, 0x78f, 0x78a, 0x784, 0x77f, + 0x77a, 0x775, 0x770, 0x76a, 0x765, 0x760, 0x75b, 0x756, + 0x751, 0x74c, 0x747, 0x742, 0x73d, 0x738, 0x733, 0x72e, + 0x729, 0x724, 0x71f, 0x71a, 0x715, 0x710, 0x70b, 0x706, + 0x702, 0x6fd, 0x6f8, 0x6f3, 0x6ee, 0x6e9, 0x6e5, 0x6e0, + 0x6db, 0x6d6, 0x6d2, 0x6cd, 0x6c8, 0x6c4, 0x6bf, 0x6ba, + 0x6b5, 0x6b1, 0x6ac, 0x6a8, 0x6a3, 0x69e, 0x69a, 0x695, + 0x691, 0x68c, 0x688, 0x683, 0x67f, 0x67a, 0x676, 0x671, + 0x66d, 0x668, 0x664, 0x65f, 0x65b, 0x657, 0x652, 0x64e, + 0x649, 0x645, 0x641, 0x63c, 0x638, 0x634, 0x630, 0x62b, + 0x627, 0x623, 0x61e, 0x61a, 0x616, 0x612, 0x60e, 0x609, + 0x605, 0x601, 0x5fd, 0x5f9, 0x5f5, 0x5f0, 0x5ec, 0x5e8, + 0x5e4, 0x5e0, 0x5dc, 0x5d8, 0x5d4, 0x5d0, 0x5cc, 0x5c8, + 0x5c4, 0x5c0, 0x5bc, 0x5b8, 0x5b4, 0x5b0, 0x5ac, 0x5a8, + 0x5a4, 0x5a0, 0x59c, 0x599, 0x595, 0x591, 0x58d, 0x589, + 0x585, 0x581, 0x57e, 0x57a, 0x576, 0x572, 0x56f, 0x56b, + 0x567, 0x563, 0x560, 0x55c, 0x558, 0x554, 0x551, 0x54d, + 0x549, 0x546, 0x542, 0x53e, 0x53b, 0x537, 0x534, 0x530, + 0x52c, 0x529, 0x525, 0x522, 0x51e, 0x51b, 0x517, 0x514, + 0x510, 0x50c, 0x509, 0x506, 0x502, 0x4ff, 0x4fb, 0x4f8, + 0x4f4, 0x4f1, 0x4ed, 0x4ea, 0x4e7, 0x4e3, 0x4e0, 0x4dc, + 0x4d9, 0x4d6, 0x4d2, 0x4cf, 0x4cc, 0x4c8, 0x4c5, 0x4c2, + 0x4be, 0x4bb, 0x4b8, 0x4b5, 0x4b1, 0x4ae, 0x4ab, 0x4a8, + 0x4a4, 0x4a1, 0x49e, 0x49b, 0x498, 0x494, 0x491, 0x48e, + 0x48b, 0x488, 0x485, 0x482, 0x47e, 0x47b, 0x478, 0x475, + 0x472, 0x46f, 0x46c, 0x469, 0x466, 0x463, 0x460, 0x45d, + 0x45a, 0x457, 0x454, 0x451, 0x44e, 0x44b, 0x448, 0x445, + 0x442, 0x43f, 0x43c, 0x439, 0x436, 0x433, 0x430, 0x42d, + 0x42a, 0x428, 0x425, 0x422, 0x41f, 0x41c, 0x419, 0x416, + 0x414, 0x411, 0x40e, 0x40b, 0x408, 0x406, 0x403, 0x400 +}; + +static const opll_patch_t patch_ds1001[opll_patch_max] = { + { 0x05, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x03, 0x01 },{ 0x00, 0x00 },{ 0x0e, 0x08 },{ 0x08, 0x01 },{ 0x04, 0x02 },{ 0x02, 0x07 } }, + { 0x14, 0x00, 0x01, 0x05,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x03, 0x01 },{ 0x00, 0x00 },{ 0x0d, 0x0f },{ 0x08, 0x06 },{ 0x02, 0x01 },{ 0x03, 0x02 } }, + { 0x08, 0x00, 0x01, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0f, 0x0b },{ 0x0a, 0x02 },{ 0x02, 0x01 },{ 0x00, 0x02 } }, + { 0x0c, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x06 },{ 0x08, 0x04 },{ 0x06, 0x02 },{ 0x01, 0x07 } }, + { 0x1e, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x02, 0x01 },{ 0x00, 0x00 },{ 0x0e, 0x07 },{ 0x01, 0x06 },{ 0x00, 0x02 },{ 0x01, 0x08 } }, + { 0x06, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x02, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x0e },{ 0x03, 0x02 },{ 0x0f, 0x0f },{ 0x04, 0x04 } }, + { 0x1d, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x08, 0x08 },{ 0x02, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x07 } }, + { 0x22, 0x01, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x03, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x07 },{ 0x02, 0x02 },{ 0x00, 0x01 },{ 0x01, 0x07 } }, + { 0x25, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x05, 0x01 },{ 0x00, 0x00 },{ 0x04, 0x07 },{ 0x00, 0x03 },{ 0x07, 0x00 },{ 0x02, 0x01 } }, + { 0x0f, 0x00, 0x01, 0x07,{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x00 },{ 0x05, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x0a },{ 0x08, 0x05 },{ 0x05, 0x00 },{ 0x01, 0x02 } }, + { 0x24, 0x00, 0x00, 0x07,{ 0x00, 0x01 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x07, 0x01 },{ 0x00, 0x00 },{ 0x0f, 0x0f },{ 0x08, 0x08 },{ 0x02, 0x01 },{ 0x02, 0x02 } }, + { 0x11, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x03 },{ 0x00, 0x00 },{ 0x06, 0x07 },{ 0x05, 0x04 },{ 0x01, 0x01 },{ 0x08, 0x06 } }, + { 0x13, 0x00, 0x00, 0x05,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x02 },{ 0x03, 0x00 },{ 0x0c, 0x09 },{ 0x09, 0x05 },{ 0x00, 0x00 },{ 0x03, 0x02 } }, + { 0x0c, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x03 },{ 0x00, 0x00 },{ 0x09, 0x0c },{ 0x04, 0x00 },{ 0x03, 0x0f },{ 0x03, 0x06 } }, + { 0x0d, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x01 },{ 0x01, 0x02 },{ 0x00, 0x00 },{ 0x0c, 0x0d },{ 0x01, 0x05 },{ 0x05, 0x00 },{ 0x06, 0x06 } }, + + { 0x18, 0x00, 0x01, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0d, 0x00 },{ 0x0f, 0x00 },{ 0x06, 0x00 },{ 0x0a, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0c, 0x00 },{ 0x08, 0x00 },{ 0x0a, 0x00 },{ 0x07, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x05, 0x00 },{ 0x00, 0x00 },{ 0x0f, 0x00 },{ 0x08, 0x00 },{ 0x05, 0x00 },{ 0x09, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0f },{ 0x00, 0x08 },{ 0x00, 0x06 },{ 0x00, 0x0d } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0d },{ 0x00, 0x08 },{ 0x00, 0x06 },{ 0x00, 0x08 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0a },{ 0x00, 0x0a },{ 0x00, 0x05 },{ 0x00, 0x05 } } +}; + +static const opll_patch_t patch_ym2413[opll_patch_max] = { + { 0x1e, 0x01, 0x00, 0x07,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0d, 0x07 },{ 0x00, 0x08 },{ 0x00, 0x01 },{ 0x00, 0x07 } }, + { 0x1a, 0x00, 0x01, 0x05,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x03, 0x01 },{ 0x00, 0x00 },{ 0x0d, 0x0f },{ 0x08, 0x07 },{ 0x02, 0x01 },{ 0x03, 0x03 } }, + { 0x19, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x03, 0x01 },{ 0x02, 0x00 },{ 0x0f, 0x0c },{ 0x02, 0x04 },{ 0x01, 0x02 },{ 0x01, 0x03 } }, + { 0x0e, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x06 },{ 0x08, 0x04 },{ 0x07, 0x02 },{ 0x00, 0x07 } }, + { 0x1e, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x02, 0x01 },{ 0x00, 0x00 },{ 0x0e, 0x07 },{ 0x00, 0x06 },{ 0x00, 0x02 },{ 0x00, 0x08 } }, + { 0x16, 0x00, 0x00, 0x05,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x02 },{ 0x00, 0x00 },{ 0x0e, 0x07 },{ 0x00, 0x01 },{ 0x00, 0x01 },{ 0x00, 0x08 } }, + { 0x1d, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x08, 0x08 },{ 0x02, 0x01 },{ 0x01, 0x00 },{ 0x00, 0x07 } }, + { 0x2d, 0x01, 0x00, 0x04,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x03, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x07 },{ 0x02, 0x02 },{ 0x00, 0x00 },{ 0x00, 0x07 } }, + { 0x1b, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x06, 0x06 },{ 0x04, 0x05 },{ 0x01, 0x01 },{ 0x00, 0x07 } }, + { 0x0b, 0x01, 0x01, 0x00,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x08, 0x0f },{ 0x05, 0x07 },{ 0x07, 0x00 },{ 0x01, 0x07 } }, + { 0x03, 0x01, 0x00, 0x01,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x03, 0x01 },{ 0x02, 0x00 },{ 0x0f, 0x0e },{ 0x0a, 0x04 },{ 0x01, 0x00 },{ 0x00, 0x04 } }, + { 0x24, 0x00, 0x00, 0x07,{ 0x00, 0x01 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x07, 0x01 },{ 0x00, 0x00 },{ 0x0f, 0x0f },{ 0x08, 0x08 },{ 0x02, 0x01 },{ 0x02, 0x02 } }, + { 0x0c, 0x00, 0x00, 0x05,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0c, 0x0f },{ 0x02, 0x05 },{ 0x02, 0x04 },{ 0x00, 0x02 } }, + { 0x15, 0x00, 0x00, 0x03,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x0c, 0x09 },{ 0x09, 0x05 },{ 0x00, 0x00 },{ 0x03, 0x02 } }, + { 0x09, 0x00, 0x00, 0x03,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x02, 0x00 },{ 0x0f, 0x0e },{ 0x01, 0x04 },{ 0x04, 0x01 },{ 0x00, 0x03 } }, + + { 0x18, 0x00, 0x01, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0d, 0x00 },{ 0x0f, 0x00 },{ 0x06, 0x00 },{ 0x0a, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0c, 0x00 },{ 0x08, 0x00 },{ 0x0a, 0x00 },{ 0x07, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x05, 0x00 },{ 0x00, 0x00 },{ 0x0f, 0x00 },{ 0x08, 0x00 },{ 0x05, 0x00 },{ 0x09, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0f },{ 0x00, 0x08 },{ 0x00, 0x06 },{ 0x00, 0x0d } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0d },{ 0x00, 0x08 },{ 0x00, 0x04 },{ 0x00, 0x08 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0a },{ 0x00, 0x0a },{ 0x00, 0x05 },{ 0x00, 0x05 } } +}; + +static const opll_patch_t patch_ymf281[opll_patch_max] = { + { 0x1a, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x02, 0x01 },{ 0x00, 0x00 },{ 0x0f, 0x06 },{ 0x0f, 0x07 },{ 0x00, 0x01 },{ 0x00, 0x06 } }, + { 0x05, 0x00, 0x00, 0x01,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x0f, 0x08 },{ 0x06, 0x03 },{ 0x08, 0x00 },{ 0x00, 0x03 } }, + { 0x16, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x03, 0x01 },{ 0x02, 0x00 },{ 0x0f, 0x0d },{ 0x02, 0x03 },{ 0x01, 0x00 },{ 0x01, 0x03 } }, + { 0x0b, 0x00, 0x01, 0x07,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x06 },{ 0x08, 0x04 },{ 0x07, 0x01 },{ 0x00, 0x07 } }, + { 0x1e, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x02, 0x01 },{ 0x00, 0x00 },{ 0x0e, 0x07 },{ 0x01, 0x06 },{ 0x00, 0x02 },{ 0x00, 0x08 } }, + { 0x02, 0x00, 0x01, 0x06,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x02, 0x00 },{ 0x09, 0x06 },{ 0x0a, 0x01 },{ 0x02, 0x02 },{ 0x00, 0x07 } }, + { 0x1b, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x08, 0x08 },{ 0x04, 0x03 },{ 0x01, 0x00 },{ 0x00, 0x07 } }, + { 0x0a, 0x00, 0x00, 0x02,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x07, 0x02 },{ 0x03, 0x00 },{ 0x06, 0x06 },{ 0x06, 0x04 },{ 0x04, 0x02 },{ 0x00, 0x07 } }, + { 0x07, 0x00, 0x00, 0x03,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0c, 0x07 },{ 0x05, 0x07 },{ 0x05, 0x00 },{ 0x01, 0x07 } }, + { 0x1e, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x00 },{ 0x06, 0x01 },{ 0x01, 0x00 },{ 0x0f, 0x0f },{ 0x02, 0x03 },{ 0x0f, 0x0f },{ 0x00, 0x03 } }, + { 0x18, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x0f, 0x0e },{ 0x05, 0x03 },{ 0x02, 0x01 },{ 0x00, 0x03 } }, + { 0x24, 0x00, 0x00, 0x07,{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x07, 0x01 },{ 0x00, 0x00 },{ 0x0f, 0x0f },{ 0x08, 0x08 },{ 0x02, 0x00 },{ 0x02, 0x03 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x00 },{ 0x05, 0x04 },{ 0x00, 0x00 },{ 0x0f, 0x0f },{ 0x0f, 0x03 },{ 0x07, 0x0f },{ 0x00, 0x05 } }, + { 0x03, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x01 },{ 0x0f, 0x01 },{ 0x00, 0x00 },{ 0x0f, 0x0e },{ 0x0c, 0x03 },{ 0x03, 0x0f },{ 0x0f, 0x0c } }, + { 0x00, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0a, 0x01 },{ 0x00, 0x00 },{ 0x0b, 0x08 },{ 0x0f, 0x04 },{ 0x00, 0x0f },{ 0x00, 0x05 } }, + + { 0x18, 0x00, 0x01, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0d, 0x00 },{ 0x0f, 0x00 },{ 0x06, 0x00 },{ 0x0a, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0c, 0x00 },{ 0x08, 0x00 },{ 0x0a, 0x00 },{ 0x07, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x05, 0x00 },{ 0x00, 0x00 },{ 0x0f, 0x00 },{ 0x08, 0x00 },{ 0x05, 0x00 },{ 0x09, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0f },{ 0x00, 0x08 },{ 0x00, 0x06 },{ 0x00, 0x0d } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0d },{ 0x00, 0x08 },{ 0x00, 0x04 },{ 0x00, 0x08 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0a },{ 0x00, 0x0a },{ 0x00, 0x05 },{ 0x00, 0x05 } } +}; + +static const opll_patch_t patch_ym2423[opll_patch_max] = { + { 0x1b, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x09, 0x05 },{ 0x04, 0x04 },{ 0x01, 0x00 },{ 0x00, 0x05 } }, + { 0x12, 0x00, 0x00, 0x04,{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x03, 0x01 },{ 0x01, 0x00 },{ 0x0f, 0x0f },{ 0x03, 0x02 },{ 0x0a, 0x0e },{ 0x00, 0x09 } }, + { 0x11, 0x00, 0x00, 0x05,{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x02 },{ 0x0f, 0x0f },{ 0x02, 0x02 },{ 0x05, 0x07 },{ 0x00, 0x05 } }, + { 0x28, 0x00, 0x00, 0x07,{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x03, 0x02 },{ 0x00, 0x00 },{ 0x0f, 0x0f },{ 0x03, 0x02 },{ 0x09, 0x0b },{ 0x00, 0x04 } }, + { 0x17, 0x00, 0x00, 0x05,{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x02, 0x01 },{ 0x02, 0x00 },{ 0x05, 0x06 },{ 0x01, 0x0f },{ 0x07, 0x00 },{ 0x00, 0x09 } }, + { 0x18, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x03, 0x00 },{ 0x00, 0x00 },{ 0x0f, 0x0f },{ 0x07, 0x04 },{ 0x05, 0x08 },{ 0x00, 0x05 } }, + { 0x1c, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x05, 0x07 },{ 0x01, 0x01 },{ 0x02, 0x02 },{ 0x00, 0x06 } }, + { 0x1b, 0x00, 0x00, 0x07,{ 0x00, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x04 },{ 0x00, 0x00 },{ 0x07, 0x03 },{ 0x03, 0x0f },{ 0x00, 0x00 },{ 0x00, 0x06 } }, + { 0x0d, 0x00, 0x00, 0x03,{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x04, 0x06 },{ 0x02, 0x0f },{ 0x02, 0x00 },{ 0x00, 0x06 } }, + { 0x10, 0x00, 0x00, 0x05,{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x02 },{ 0x0f, 0x0f },{ 0x03, 0x03 },{ 0x02, 0x00 },{ 0x00, 0x04 } }, + { 0x1b, 0x00, 0x00, 0x07,{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x0c, 0x09 },{ 0x05, 0x06 },{ 0x0f, 0x0f },{ 0x00, 0x06 } }, + { 0x1b, 0x00, 0x00, 0x00,{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x09, 0x01 },{ 0x03, 0x00 },{ 0x0f, 0x0f },{ 0x05, 0x03 },{ 0x07, 0x0f },{ 0x00, 0x02 } }, + { 0x11, 0x00, 0x00, 0x03,{ 0x00, 0x01 },{ 0x01, 0x00 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x02 },{ 0x02, 0x00 },{ 0x09, 0x0b },{ 0x04, 0x01 },{ 0x0e, 0x0f },{ 0x00, 0x07 } }, + { 0x17, 0x00, 0x00, 0x06,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x0d, 0x0e },{ 0x03, 0x01 },{ 0x0b, 0x0e },{ 0x00, 0x0b } }, + { 0x0d, 0x00, 0x00, 0x05,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x01 },{ 0x01, 0x01 },{ 0x01, 0x06 },{ 0x00, 0x00 },{ 0x0f, 0x0f },{ 0x02, 0x04 },{ 0x02, 0x09 },{ 0x00, 0x09 } }, + + { 0x18, 0x00, 0x01, 0x07,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0d, 0x00 },{ 0x0f, 0x00 },{ 0x06, 0x00 },{ 0x0a, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0c, 0x00 },{ 0x08, 0x00 },{ 0x0a, 0x00 },{ 0x07, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x05, 0x00 },{ 0x00, 0x00 },{ 0x0f, 0x00 },{ 0x08, 0x00 },{ 0x05, 0x00 },{ 0x09, 0x00 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0f },{ 0x00, 0x08 },{ 0x00, 0x06 },{ 0x00, 0x0d } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0d },{ 0x00, 0x08 },{ 0x00, 0x04 },{ 0x00, 0x08 } }, + { 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0a },{ 0x00, 0x0a },{ 0x00, 0x05 },{ 0x00, 0x05 } } +}; + +static const uint32_t ch_offset[18] = { + 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 0 +}; + +static const uint32_t pg_multi[16] = { + 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 20, 24, 24, 30, 30 +}; + +static const uint32_t eg_stephi[4][4] = { + { 0, 0, 0, 0 }, + { 1, 0, 0, 0 }, + { 1, 0, 1, 0 }, + { 1, 1, 1, 0 } +}; + +static const uint32_t eg_ksltable[16] = { + 0, 32, 40, 45, 48, 51, 53, 55, 56, 58, 59, 60, 61, 62, 63, 64 +}; + +static void OPLL_DoIO(opll_t *chip) { + /* Write signal check */ + chip->write_a_en = (chip->write_a & 0x03) == 0x01; + chip->write_d_en = (chip->write_d & 0x03) == 0x01; + chip->write_a <<= 1; + chip->write_d <<= 1; +} + +static void OPLL_DoModeWrite(opll_t *chip) { + if ((chip->write_mode_address & 0x10) && chip->write_d_en) { + uint8_t slot = chip->write_mode_address & 0x01; + switch (chip->write_mode_address & 0x0f) { + case 0x00: + case 0x01: + chip->patch.multi[slot] = chip->write_data & 0x0f; + chip->patch.ksr[slot] = (chip->write_data >> 4) & 0x01; + chip->patch.et[slot] = (chip->write_data >> 5) & 0x01; + chip->patch.vib[slot] = (chip->write_data >> 6) & 0x01; + chip->patch.am[slot] = (chip->write_data >> 7) & 0x01; + break; + + case 0x02: + chip->patch.ksl[0] = (chip->write_data >> 6) & 0x03; + chip->patch.tl = chip->write_data & 0x3f; + break; + + case 0x03: + chip->patch.ksl[1] = (chip->write_data >> 6) & 0x03; + chip->patch.dc = (chip->write_data >> 4) & 0x01; + chip->patch.dm = (chip->write_data >> 3) & 0x01; + chip->patch.fb = chip->write_data & 0x07; + break; + + case 0x04: + case 0x05: + chip->patch.dr[slot] = chip->write_data & 0x0f; + chip->patch.ar[slot] = (chip->write_data >> 4) & 0x0f; + break; + + case 0x06: + case 0x07: + chip->patch.rr[slot] = chip->write_data & 0x0f; + chip->patch.sl[slot] = (chip->write_data >> 4) & 0x0f; + break; + + case 0x0e: + chip->rhythm = chip->write_data & 0x3f; + if (chip->chip_type == opll_type_ds1001) { + chip->rhythm |= 0x20; + } + chip->rm_enable = (chip->rm_enable & 0x7f) | ((chip->rhythm << 2) & 0x80); + break; + + case 0x0f: + chip->testmode = chip->write_data & 0x0f; + break; + } + } +} + +void OPLL_Reset(opll_t *chip, uint32_t chip_type) { + uint32_t i; + memset(chip, 0, sizeof(opll_t)); + chip->chip_type = chip_type; + if (chip_type == opll_type_ds1001) { + /* Rhythm mode is always on */ + chip->rhythm = 0x20; + chip->rm_enable = (int8_t)0x80; + } + switch (chip_type) { + case opll_type_ds1001: + chip->patchrom = patch_ds1001; + break; + case opll_type_ymf281: + case opll_type_ymf281b: + chip->patchrom = patch_ymf281; + break; + case opll_type_ym2423: + chip->patchrom = patch_ym2423; + break; + case opll_type_ym2413: + case opll_type_ym2413b: + case opll_type_ym2420: + default: + chip->patchrom = patch_ym2413; + break; + } + for (i = 0; i < 18; i++) { + chip->eg_state[i] = eg_num_release; + chip->eg_level[i] = 0x7f; + chip->eg_out = 0x7f; + } + chip->rm_select = rm_num_tc + 1; +} + +static void OPLL_DoRegWrite(opll_t *chip) { + /* Address */ + if (chip->write_a_en) { + if ((chip->write_data & 0xc0) == 0x00) { + /* FM Write */ + chip->write_fm_address = 1; + chip->address = chip->write_data; + } else { + chip->write_fm_address = 0; + } + } + /* Data */ + if (chip->write_fm_address && chip->write_d_en) { + chip->data = chip->write_data; + } + + /* Update registers */ + if (chip->write_fm_data && !chip->write_a_en) { + if ((chip->address & 0x0f) == chip->cycles && chip->cycles < 16) { + uint32_t channel = chip->cycles % 9; + switch (chip->address & 0xf0) { + case 0x10: + if (chip->chip_type == opll_type_ym2420) + { + chip->fnum[channel] = (chip->fnum[channel] & 0x0f) | ((chip->data & 0x1f) << 4); + chip->block[channel] = (chip->data >> 5) & 0x07; + } + else + chip->fnum[channel] = (chip->fnum[channel] & 0x100) | chip->data; + break; + case 0x20: + if (chip->chip_type == opll_type_ym2420) + chip->fnum[channel] = (chip->fnum[channel] & 0x1f0) | (chip->data & 0x0f); + else + { + chip->fnum[channel] = (chip->fnum[channel] & 0xff) | ((chip->data & 0x01) << 8); + chip->block[channel] = (chip->data >> 1) & 0x07; + } + chip->kon[channel] = (chip->data >> 4) & 0x01; + chip->son[channel] = (chip->data >> 5) & 0x01; + break; + case 0x30: + chip->vol[channel] = chip->data & 0x0f; + chip->inst[channel] = (chip->data >> 4) & 0x0f; + break; + } + } + } + + + if (chip->write_a_en) { + chip->write_fm_data = 0; + } + if (chip->write_fm_address && chip->write_d_en) { + chip->write_fm_data = 1; + } + if (chip->write_a_en) { + if (((chip->write_data & 0xf0) == 0x00)) { + chip->write_mode_address = 0x10 | (chip->write_data & 0x0f); + } else { + chip->write_mode_address = 0x00; + } + } + +} + +static void OPLL_PreparePatch1(opll_t *chip) { + uint8_t instr; + uint32_t mcsel = ((chip->cycles + 1) / 3) & 0x01; + uint32_t instr_index; + uint32_t ch = ch_offset[chip->cycles]; + const opll_patch_t *patch; + instr = chip->inst[ch]; + if (instr > 0) { + instr_index = opll_patch_1 + instr - 1; + } + if (chip->rm_select <= rm_num_tc) { + instr_index = opll_patch_drum_0 + chip->rm_select; + } + if (chip->rm_select <= rm_num_tc || instr > 0) { + patch = &chip->patchrom[instr_index]; + } else { + patch = &chip->patch; + } + if (chip->rm_select == rm_num_hh || chip->rm_select == rm_num_tom) { + chip->c_tl = chip->inst[ch] << 2; + } else if (mcsel == 1) { + chip->c_tl = chip->vol[ch] << 2; + } else { + chip->c_tl = patch->tl; + } + + chip->c_adrr[0] = patch->ar[mcsel]; + chip->c_adrr[1] = patch->dr[mcsel]; + chip->c_adrr[2] = patch->rr[mcsel]; + chip->c_et = patch->et[mcsel]; + chip->c_ksr = patch->ksr[mcsel]; + chip->c_ksl = patch->ksl[mcsel]; + chip->c_ksr_freq = (chip->block[ch] << 1) | (chip->fnum[ch] >> 8); + chip->c_ksl_freq = (chip->fnum[ch]>>5); + chip->c_ksl_block = (chip->block[ch]); +} + +static void OPLL_PreparePatch2(opll_t *chip) { + uint8_t instr; + uint32_t mcsel = ((chip->cycles + 1) / 3) & 0x01; + uint32_t instr_index; + const opll_patch_t *patch; + instr = chip->inst[ch_offset[chip->cycles]]; + if (instr > 0) { + instr_index = opll_patch_1 + instr - 1; + } + if (chip->rm_select <= rm_num_tc) { + instr_index = opll_patch_drum_0 + chip->rm_select; + } + if (chip->rm_select <= rm_num_tc || instr > 0) { + patch = &chip->patchrom[instr_index]; + } else { + patch = &chip->patch; + } + + chip->c_fnum = chip->fnum[ch_offset[chip->cycles]]; + chip->c_block = chip->block[ch_offset[chip->cycles]]; + + chip->c_multi = patch->multi[mcsel]; + chip->c_sl = patch->sl[mcsel]; + chip->c_fb = patch->fb; + chip->c_vib = patch->vib[mcsel]; + chip->c_am = patch->am[mcsel]; + chip->c_dc <<= 1; + chip->c_dm <<= 1; + chip->c_dc |= patch->dc; + chip->c_dm |= patch->dm; +} + +static void OPLL_PhaseGenerate(opll_t *chip) { + uint32_t ismod; + uint32_t phase; + uint16_t pg_out; + + chip->pg_phase[(chip->cycles + 17) % 18] = chip->pg_phase_next + chip->pg_inc; + + if ((chip->rm_enable & 0x40) && (chip->cycles == 13 || chip->cycles == 14)) { + ismod = 0; + } else { + ismod = ((chip->cycles + 3) / 3) & 1; + } + phase = chip->pg_phase[chip->cycles]; + /* KeyOn event check */ + if ((chip->testmode & 0x04) + || (ismod && (chip->eg_dokon & 0x8000)) || (!ismod && (chip->eg_dokon & 0x01))) { + chip->pg_phase_next = 0; + } else { + chip->pg_phase_next = phase; + } + /* Rhythm mode */ + if (chip->cycles == 13) { + chip->rm_hh_bit2 = (phase >> (2 + 9)) & 1; + chip->rm_hh_bit3 = (phase >> (3 + 9)) & 1; + chip->rm_hh_bit7 = (phase >> (7 + 9)) & 1; + chip->rm_hh_bit8 = (phase >> (8 + 9)) & 1; + } else if (chip->cycles == 17 && (chip->rm_enable & 0x80)) { + chip->rm_tc_bit3 = (phase >> (3 + 9)) & 1; + chip->rm_tc_bit5 = (phase >> (5 + 9)) & 1; + } + if ((chip->rm_enable & 0x80)) { + uint8_t rm_bit; + switch (chip->cycles) { + case 13: + /* HH */ + rm_bit = (chip->rm_hh_bit2 ^ chip->rm_hh_bit7) + | (chip->rm_hh_bit3 ^ chip->rm_tc_bit5) + | (chip->rm_tc_bit3 ^ chip->rm_tc_bit5); + pg_out = rm_bit << 9; + if (rm_bit ^ (chip->rm_noise & 1)) { + pg_out |= 0xd0; + } else { + pg_out |= 0x34; + } + break; + case 16: + /* SD */ + pg_out = (chip->rm_hh_bit8 << 9) + | ((chip->rm_hh_bit8 ^ (chip->rm_noise & 1)) << 8); + break; + case 17: + /* TC */ + rm_bit = (chip->rm_hh_bit2 ^ chip->rm_hh_bit7) + | (chip->rm_hh_bit3 ^ chip->rm_tc_bit5) + | (chip->rm_tc_bit3 ^ chip->rm_tc_bit5); + pg_out = (rm_bit << 9) | 0x100; + break; + default: + pg_out = phase >> 9; + } + } else { + pg_out = phase >> 9; + } + chip->pg_out = pg_out; +} + +static void OPLL_PhaseCalcIncrement(opll_t *chip) { + uint32_t freq; + uint16_t block; + freq = chip->c_fnum << 1; + block = chip->c_block; + /* Apply vibrato */ + if (chip->c_vib) { + switch (chip->lfo_vib_counter) { + case 0: + case 4: + break; + case 1: + case 3: + freq += freq >> 8; + break; + case 2: + freq += freq >> 7; + break; + case 5: + case 7: + freq -= freq >> 8; + break; + case 6: + freq -= freq >> 7; + break; + } + } + /* Apply block */ + freq = (freq << block) >> 1; + + chip->pg_inc = (freq * pg_multi[chip->c_multi]) >> 1; +} + +static void OPLL_EnvelopeKSLTL(opll_t *chip) { + int32_t ksl; + + ksl = eg_ksltable[chip->c_ksl_freq]-((8-chip->c_ksl_block)<<3); + if (ksl < 0) { + ksl = 0; + } + + ksl <<= 1; + + if (chip->c_ksl) { + ksl = ksl >> (3-chip->c_ksl); + } else { + ksl = 0; + } + + chip->eg_ksltl = ksl + (chip->c_tl<<1); +} + +static void OPLL_EnvelopeOutput(opll_t *chip) { + int32_t level = chip->eg_level[(chip->cycles+17)%18]; + + level += chip->eg_ksltl; + + if (chip->c_am) { + level += chip->lfo_am_out; + } + + if (level >= 128) { + level = 127; + } + + if (chip->testmode & 0x01) { + level = 0; + } + + chip->eg_out = level; +} + +static void OPLL_EnvelopeGenerate(opll_t *chip) { + uint8_t timer_inc; + uint8_t timer_bit; + uint8_t timer_low; + uint8_t rate; + uint8_t state_rate; + uint8_t ksr; + uint8_t sum; + uint8_t rate_hi; + uint8_t rate_lo; + int32_t level; + int32_t next_level; + uint8_t zero; + uint8_t state; + uint8_t next_state; + int32_t step; + int32_t sl; + uint32_t mcsel = ((chip->cycles + 1) / 3) & 0x01; + + + /* EG timer */ + if ((chip->eg_counter_state & 3) != 3) { + timer_inc = 0; + } else if (chip->cycles == 0) { + timer_inc = 1; + } else { + timer_inc = chip->eg_timer_carry; + } + timer_low = chip->eg_timer & 3; + timer_bit = chip->eg_timer & 1; + timer_bit += timer_inc; + chip->eg_timer_carry = timer_bit >> 1; + chip->eg_timer = ((timer_bit & 1) << 17) | (chip->eg_timer >> 1); + if (chip->testmode & 0x08) { + chip->eg_timer &= 0x2ffff; + chip->eg_timer |= (chip->write_data << (16 - 2)) & 0x10000; + } + if (!chip->eg_timer_shift_stop && ((chip->eg_timer >> 16) & 1)) { + chip->eg_timer_shift = chip->cycles; + } + if (chip->cycles == 0 && (chip->eg_counter_state_prev & 1) == 1) { + chip->eg_timer_low_lock = timer_low; + chip->eg_timer_shift_lock = chip->eg_timer_shift; + if (chip->eg_timer_shift_lock > 13) + chip->eg_timer_shift_lock = 0; + + chip->eg_timer_shift = 0; + } + chip->eg_timer_shift_stop |= (chip->eg_timer >> 16) & 1; + if (chip->cycles == 0) { + chip->eg_timer_shift_stop = 0; + } + chip->eg_counter_state_prev = chip->eg_counter_state; + if (chip->cycles == 17) { + chip->eg_counter_state++; + } + + level = chip->eg_level[(chip->cycles+16)%18]; + next_level = level; + zero = level == 0; + chip->eg_silent = level == 0x7f; + + if (chip->eg_state[(chip->cycles+16)%18] != eg_num_attack && (chip->eg_off&2) && !(chip->eg_dokon&2)) { + next_level = 0x7f; + } + + if (chip->eg_maxrate && (chip->eg_dokon&2)) { + next_level = 0x00; + } + + + state = chip->eg_state[(chip->cycles+16)%18]; + next_state = eg_num_attack; + + step = 0; + sl = chip->eg_sl; + + switch (state) { + case eg_num_attack: + if (!chip->eg_maxrate && (chip->eg_kon & 2) && !zero) { + int32_t shift = (chip->eg_rate_hi < 12) ? chip->eg_inc_lo : (chip->eg_rate_hi - 11 + chip->eg_inc_hi); + if (shift > 0) { + step = ~level >> (5 - shift); + } + } + if (zero) { + next_state = eg_num_decay; + } else { + next_state = eg_num_attack; + } + break; + case eg_num_decay: + if (!(chip->eg_off & 2) && !(chip->eg_dokon & 2) && (level >> 3) != sl) + { + uint8_t i0 = chip->eg_rate_hi == 15 || (chip->eg_rate_hi == 14 && chip->eg_inc_hi); + uint8_t i1 = (chip->eg_rate_hi == 14 && !chip->eg_inc_hi) || (chip->eg_rate_hi == 13 && chip->eg_inc_hi) || + (chip->eg_rate_hi == 13 && !chip->eg_inc_hi && (chip->eg_counter_state_prev & 1)) + || (chip->eg_rate_hi == 12 && chip->eg_inc_hi && (chip->eg_counter_state_prev & 1)) + || (chip->eg_rate_hi == 12 && !chip->eg_inc_hi && ((chip->eg_counter_state_prev & 3) == 3)) + || (chip->eg_inc_lo && ((chip->eg_counter_state_prev & 3) == 3)); + step = (i0<<1) | i1; + } + if ((level >> 3) == sl) { + next_state = eg_num_sustain; + } else { + next_state = eg_num_decay; + } + break; + case eg_num_sustain: + case eg_num_release: + if (!(chip->eg_off & 2) && !(chip->eg_dokon & 2)) + { + uint8_t i0 = chip->eg_rate_hi == 15 || (chip->eg_rate_hi == 14 && chip->eg_inc_hi); + uint8_t i1 = (chip->eg_rate_hi == 14 && !chip->eg_inc_hi) || (chip->eg_rate_hi == 13 && chip->eg_inc_hi) || + (chip->eg_rate_hi == 13 && !chip->eg_inc_hi && (chip->eg_counter_state_prev & 1)) + || (chip->eg_rate_hi == 12 && chip->eg_inc_hi && (chip->eg_counter_state_prev & 1)) + || (chip->eg_rate_hi == 12 && !chip->eg_inc_hi && ((chip->eg_counter_state_prev & 3) == 3)) + || (chip->eg_inc_lo && ((chip->eg_counter_state_prev & 3) == 3)); + step = (i0<<1) | i1; + } + next_state = state; + break; + } + + if (!(chip->eg_kon & 2)) { + next_state = eg_num_release; + } + if (chip->eg_dokon & 2) { + next_state = eg_num_attack; + } + + chip->eg_level[(chip->cycles+16)%18] = next_level+step; + chip->eg_state[(chip->cycles+16)%18] = next_state; + + rate_hi = chip->eg_rate >> 2; + rate_lo = chip->eg_rate & 3; + chip->eg_inc_hi = eg_stephi[rate_lo][chip->eg_timer_low_lock]; + sum = (chip->eg_timer_shift_lock + rate_hi) & 0x0f; + chip->eg_inc_lo = 0; + if (rate_hi < 12 && !chip->eg_zerorate) { + switch (sum) { + case 12: + chip->eg_inc_lo = 1; + break; + case 13: + chip->eg_inc_lo = (rate_lo >> 1) & 1; + break; + case 14: + chip->eg_inc_lo = rate_lo & 1; + break; + } + } + chip->eg_maxrate = rate_hi == 0x0f; + + chip->eg_rate_hi = rate_hi; + + chip->eg_kon <<= 1; + chip->eg_kon |= chip->kon[ch_offset[chip->cycles]]; + chip->eg_off <<= 1; + chip->eg_off |= (chip->eg_level[chip->cycles] >> 2) == 0x1f; + switch (chip->rm_select) { + case rm_num_bd0: + case rm_num_bd1: + chip->eg_kon |= (chip->rhythm >> 4) & 1; + break; + case rm_num_sd: + chip->eg_kon |= (chip->rhythm >> 3) & 1; + break; + case rm_num_tom: + chip->eg_kon |= (chip->rhythm >> 2) & 1; + break; + case rm_num_tc: + chip->eg_kon |= (chip->rhythm >> 1) & 1; + break; + case rm_num_hh: + chip->eg_kon |= chip->rhythm & 1; + break; + } + + /* Calculate rate */ + rate = 0; + chip->eg_dokon <<= 1; + state_rate = chip->eg_state[chip->cycles]; + if (state_rate == eg_num_release && (chip->eg_kon&1) && (chip->eg_off&1)) { + state_rate = eg_num_attack; + chip->eg_dokon |= 1; + } + switch (state_rate) { + case eg_num_attack: + rate = chip->c_adrr[0]; + break; + case eg_num_decay: + rate = chip->c_adrr[1]; + break; + case eg_num_sustain: + if (!chip->c_et) { + rate = chip->c_adrr[2]; + } + break; + case eg_num_release: + if (chip->son[ch_offset[chip->cycles]]) { + rate = 5; + } else { + rate = chip->c_adrr[2]; + } + break; + } + if (!(chip->eg_kon&1) && !mcsel && chip->rm_select != rm_num_tom && chip->rm_select != rm_num_hh) { + rate = 0; + } + if ((chip->eg_kon&1) && chip->eg_state[chip->cycles] == eg_num_release && !(chip->eg_off&1)) { + rate = 12; + } + if (!(chip->eg_kon&1) && !chip->son[ch_offset[chip->cycles]] && mcsel == 1 && !chip->c_et) { + rate = 7; + } + chip->eg_zerorate = rate == 0; + ksr = chip->c_ksr_freq; + if (!chip->c_ksr) + ksr >>= 2; + chip->eg_rate = (rate << 2) + ksr; + if (chip->eg_rate & 0x40) { + chip->eg_rate = 0x3c | (ksr & 3); + } + chip->eg_sl = chip->c_sl; +} + +static void OPLL_Channel(opll_t *chip) { + int16_t ch_out = chip->ch_out; + uint8_t ismod = (chip->cycles / 3) & 1; + uint8_t mute_m = ismod || ((chip->rm_enable&0x40) && (chip->cycles+15)%18 >= 12); + if (chip->chip_type == opll_type_ds1001) { + chip->output_m = ch_out; + if (chip->output_m >= 0) { + chip->output_m++; + } + if (mute_m) { + chip->output_m = 0; + } + chip->output_r = 0; + return; + } else { + uint8_t mute_r = 1; + /* TODO: This might be incorrect */ + if ((chip->rm_enable & 0x40)) { + switch (chip->cycles) { + case 16: /* HH */ + case 17: /* TOM */ + case 0: /* BD */ + case 1: /* SD */ + case 2: /* TC */ + case 3: /* HH */ + case 4: /* TOM */ + case 5: /* BD */ + case 9: /* TOM */ + case 10: /* TOM */ + mute_r = 0; + break; + } + } + if (chip->chip_type == opll_type_ym2413b || chip->chip_type == opll_type_ymf281b) { + if (mute_m) + chip->output_m = 0; + else + chip->output_m = ch_out; + if (mute_r) + chip->output_r = 0; + else + chip->output_r = ch_out; + } else { + int16_t sign = ch_out >> 8; + if (ch_out >= 0) { + ch_out++; + sign++; + } + if (mute_m) + chip->output_m = sign; + else + chip->output_m = ch_out; + if (mute_r) + chip->output_r = sign; + else + chip->output_r = ch_out; + } + } +} + +static void OPLL_Operator(opll_t *chip) { + uint8_t ismod1, ismod2, ismod3; + uint32_t op_mod; + uint16_t exp_shift; + int16_t output; + uint32_t level; + uint32_t phase; + int16_t routput; + if ((chip->rm_enable & 0x80) && (chip->cycles == 15 || chip->cycles == 16)) { + ismod1 = 0; + } else { + ismod1 = ((chip->cycles + 1) / 3) & 1; + } + if ((chip->rm_enable & 0x40) && (chip->cycles == 13 || chip->cycles == 14)) { + ismod2 = 0; + } else { + ismod2 = ((chip->cycles + 3) / 3) & 1; + } + if ((chip->rm_enable & 0x40) && (chip->cycles == 16 || chip->cycles == 17)) { + ismod3 = 0; + } else { + ismod3 = (chip->cycles / 3) & 1; + } + + op_mod = 0; + + if (ismod3) { + op_mod |= chip->op_mod << 1; + } + + if (ismod2 && chip->c_fb) { + op_mod |= chip->op_fbsum >> (7 - chip->c_fb); + } + + exp_shift = chip->op_exp_s; + if (chip->eg_silent || ((chip->op_neg&2) && (ismod1 ? (chip->c_dm&4) : (chip->c_dc&4)))) { + exp_shift |= 12; + } + + output = chip->op_exp_m>>exp_shift; + if (!chip->eg_silent && (chip->op_neg&2)) { + output = ~output; + } + + level = chip->op_logsin+(chip->eg_out<<4); + if (level >= 4096) { + level = 4095; + } + + chip->op_exp_m = exprom[level & 0xff]; + chip->op_exp_s = level >> 8; + + phase = (op_mod + chip->pg_out) & 0x3ff; + if (phase & 0x100) { + phase ^= 0xff; + } + chip->op_logsin = logsinrom[phase & 0xff]; + chip->op_neg <<= 1; + chip->op_neg |= phase >> 9; + chip->op_fbsum = (chip->op_fb1[(chip->cycles + 3) % 9] + chip->op_fb2[(chip->cycles + 3) % 9]) >> 1; + + if (ismod1) { + chip->op_fb2[chip->cycles%9] = chip->op_fb1[chip->cycles%9]; + chip->op_fb1[chip->cycles%9] = output; + } + chip->op_mod = output&0x1ff; + + if (chip->chip_type == opll_type_ds1001) { + routput = 0; + } else { + switch (chip->cycles) { + case 2: + routput = chip->ch_out_hh; + break; + case 3: + routput = chip->ch_out_tm; + break; + case 4: + routput = chip->ch_out_bd; + break; + case 8: + routput = chip->ch_out_sd; + break; + case 9: + routput = chip->ch_out_tc; + break; + default: + routput = 0; /* TODO: Not quite true */ + break; + } + switch (chip->cycles) { + case 15: + chip->ch_out_hh = output>>3; + break; + case 16: + chip->ch_out_tm = output>>3; + break; + case 17: + chip->ch_out_bd = output>>3; + break; + case 0: + chip->ch_out_sd = output>>3; + break; + case 1: + chip->ch_out_tc = output>>3; + break; + default: + break; + } + } + + chip->ch_out = ismod1 ? routput : (output>>3); +} + +static void OPLL_DoRhythm(opll_t *chip) { + uint8_t nbit; + + /* Noise */ + nbit = (chip->rm_noise ^ (chip->rm_noise >> 14)) & 0x01; + nbit |= (chip->rm_noise == 0x00) | ((chip->testmode >> 1) & 0x01); + chip->rm_noise = (nbit << 22) | (chip->rm_noise >> 1); +} + +static void OPLL_DoLFO(opll_t *chip) { + uint8_t am_inc = 0; + uint8_t am_bit; + + /* Update counter */ + if (chip->cycles == 17) { + uint8_t vib_step = ((chip->lfo_counter & 0x3ff) + 1) >> 10; + chip->lfo_am_step = ((chip->lfo_counter & 0x3f) + 1) >> 6; + vib_step |= (chip->testmode >> 3) & 0x01; + chip->lfo_vib_counter += vib_step; + chip->lfo_vib_counter &= 0x07; + chip->lfo_counter++; + } + + /* LFO AM */ + if ((chip->lfo_am_step || (chip->testmode & 0x08)) && chip->cycles < 9) { + am_inc = chip->lfo_am_dir | (chip->cycles == 0); + } + + if (chip->cycles >= 9) { + chip->lfo_am_car = 0; + } + + if (chip->cycles == 0) { + if (chip->lfo_am_dir && (chip->lfo_am_counter & 0x7f) == 0) { + chip->lfo_am_dir = 0; + } else if (!chip->lfo_am_dir && (chip->lfo_am_counter & 0x69) == 0x69) { + chip->lfo_am_dir = 1; + } + } + + am_bit = chip->lfo_am_counter & 0x01; + am_bit += am_inc + chip->lfo_am_car; + chip->lfo_am_car = am_bit >> 1; + am_bit &= 0x01; + chip->lfo_am_counter = (am_bit << 8) | (chip->lfo_am_counter >> 1); + + + /* Reset LFO */ + if (chip->testmode & 0x02) { + chip->lfo_vib_counter = 0; + chip->lfo_counter = 0; + chip->lfo_am_dir = 0; + chip->lfo_am_counter &= 0xff; + } +} + + +void OPLL_Clock(opll_t *chip, int32_t *buffer) { + buffer[0] = chip->output_m; + buffer[1] = chip->output_r; + if (chip->cycles == 0) { + chip->lfo_am_out = (chip->lfo_am_counter >> 3) & 0x0f; + } + chip->rm_enable >>= 1; + OPLL_DoModeWrite(chip); + chip->rm_select++; + if (chip->rm_select > rm_num_tc) { + chip->rm_select = rm_num_tc + 1; + } + if (chip->cycles == 11 && (chip->rm_enable & 0x80) == 0x80) { + chip->rm_select = rm_num_bd0; + } + OPLL_PreparePatch1(chip); + + OPLL_Channel(chip); + + OPLL_PhaseGenerate(chip); + + OPLL_Operator(chip); + + OPLL_PhaseCalcIncrement(chip); + + OPLL_EnvelopeOutput(chip); + OPLL_EnvelopeKSLTL(chip); + OPLL_EnvelopeGenerate(chip); + + OPLL_DoLFO(chip); + OPLL_DoRhythm(chip); + OPLL_PreparePatch2(chip); + OPLL_DoRegWrite(chip); + OPLL_DoIO(chip); + chip->cycles = (chip->cycles + 1) % 18; + +} + + +void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data) { + chip->write_data = data; + if (port & 1) { + /* Data */ + chip->write_d |= 1; + } else { + /* Address */ + chip->write_a |= 1; + } +} diff --git a/extern/Nuked-OPLL/opll.h b/extern/Nuked-OPLL/opll.h new file mode 100644 index 00000000..706eb9f3 --- /dev/null +++ b/extern/Nuked-OPLL/opll.h @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2019 Nuke.YKT + * + * 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 2 + * 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. + * + * + * Yamaha YM2413 emulator + * Thanks: + * siliconpr0n.org(digshadow, John McMaster): + * VRC VII decap and die shot. + * + * version: 1.0.1 + */ + +#ifndef OPLL_H +#define OPLL_H + +#include + +enum { + opll_type_ym2413 = 0x00, /* Yamaha YM2413 */ + opll_type_ds1001, /* Konami VRC VII */ + opll_type_ym2413b, /* Yamaha YM2413B */ + opll_type_ymf281, /* Yamaha YMF281 */ + opll_type_ymf281b, /* Yamaha YMF281B */ + opll_type_ym2420, /* Yamaha YM2420 */ + opll_type_ym2423, /* Yamaha YM2423 */ +}; + +enum { + opll_patch_1 = 0x00, + opll_patch_2, + opll_patch_3, + opll_patch_4, + opll_patch_5, + opll_patch_6, + opll_patch_7, + opll_patch_8, + opll_patch_9, + opll_patch_10, + opll_patch_11, + opll_patch_12, + opll_patch_13, + opll_patch_14, + opll_patch_15, + opll_patch_drum_0, + opll_patch_drum_1, + opll_patch_drum_2, + opll_patch_drum_3, + opll_patch_drum_4, + opll_patch_drum_5, + opll_patch_max +}; + +typedef struct { + uint8_t tl; + uint8_t dc; + uint8_t dm; + uint8_t fb; + uint8_t am[2]; + uint8_t vib[2]; + uint8_t et[2]; + uint8_t ksr[2]; + uint8_t multi[2]; + uint8_t ksl[2]; + uint8_t ar[2]; + uint8_t dr[2]; + uint8_t sl[2]; + uint8_t rr[2]; +} opll_patch_t; + +typedef struct { + uint32_t chip_type; + uint32_t cycles; + uint32_t slot; + const opll_patch_t *patchrom; + /* IO */ + uint8_t write_data; + uint8_t write_a; + uint8_t write_d; + uint8_t write_a_en; + uint8_t write_d_en; + uint8_t write_fm_address; + uint8_t write_fm_data; + uint8_t write_mode_address; + uint8_t address; + uint8_t data; + /* Envelope generator */ + uint8_t eg_counter_state; + uint8_t eg_counter_state_prev; + uint32_t eg_timer; + uint8_t eg_timer_low_lock; + uint8_t eg_timer_carry; + uint8_t eg_timer_shift; + uint8_t eg_timer_shift_lock; + uint8_t eg_timer_shift_stop; + uint8_t eg_state[18]; + uint8_t eg_level[18]; + uint8_t eg_kon; + uint32_t eg_dokon; + uint8_t eg_off; + uint8_t eg_rate; + uint8_t eg_maxrate; + uint8_t eg_zerorate; + uint8_t eg_inc_lo; + uint8_t eg_inc_hi; + uint8_t eg_rate_hi; + uint16_t eg_sl; + uint16_t eg_ksltl; + uint8_t eg_out; + uint8_t eg_silent; + /* Phase generator */ + uint16_t pg_fnum; + uint8_t pg_block; + uint16_t pg_out; + uint32_t pg_inc; + uint32_t pg_phase[18]; + uint32_t pg_phase_next; + /* Operator */ + int16_t op_fb1[9]; + int16_t op_fb2[9]; + int16_t op_fbsum; + int16_t op_mod; + uint8_t op_neg; + uint16_t op_logsin; + uint16_t op_exp_m; + uint16_t op_exp_s; + /* Channel */ + int16_t ch_out; + int16_t ch_out_hh; + int16_t ch_out_tm; + int16_t ch_out_bd; + int16_t ch_out_sd; + int16_t ch_out_tc; + /* LFO */ + uint16_t lfo_counter; + uint8_t lfo_vib_counter; + uint16_t lfo_am_counter; + uint8_t lfo_am_step; + uint8_t lfo_am_dir; + uint8_t lfo_am_car; + uint8_t lfo_am_out; + /* Register set */ + uint16_t fnum[9]; + uint8_t block[9]; + uint8_t kon[9]; + uint8_t son[9]; + uint8_t vol[9]; + uint8_t inst[9]; + uint8_t rhythm; + uint8_t testmode; + opll_patch_t patch; + uint8_t c_instr; + uint8_t c_op; + uint8_t c_tl; + uint8_t c_dc; + uint8_t c_dm; + uint8_t c_fb; + uint8_t c_am; + uint8_t c_vib; + uint8_t c_et; + uint8_t c_ksr; + uint8_t c_ksr_freq; + uint8_t c_ksl_freq; + uint8_t c_ksl_block; + uint8_t c_multi; + uint8_t c_ksl; + uint8_t c_adrr[3]; + uint8_t c_sl; + uint16_t c_fnum; + uint16_t c_block; + /* Rhythm mode */ + int8_t rm_enable; + uint32_t rm_noise; + uint32_t rm_select; + uint8_t rm_hh_bit2; + uint8_t rm_hh_bit3; + uint8_t rm_hh_bit7; + uint8_t rm_hh_bit8; + uint8_t rm_tc_bit3; + uint8_t rm_tc_bit5; + + int16_t output_m; + int16_t output_r; + +} opll_t; + +void OPLL_Reset(opll_t *chip, uint32_t chip_type); +void OPLL_Clock(opll_t *chip, int32_t *buffer); +void OPLL_Write(opll_t *chip, uint32_t port, uint8_t data); +#endif diff --git a/papers/doc/3-pattern/effects.md b/papers/doc/3-pattern/effects.md index e940a4aa..ce47e484 100644 --- a/papers/doc/3-pattern/effects.md +++ b/papers/doc/3-pattern/effects.md @@ -48,4 +48,4 @@ however, effects are continuous, which means you only need to type it once and t - `80` is center. - `FFxx`: end of song/stop playback. -additionally each system has its own effects. more details in another section of the manual. +additionally each system has its own effects. [click here for more details](../7-systems/README.md). diff --git a/papers/format.md b/papers/format.md index 1f44f9ac..882efa7b 100644 --- a/papers/format.md +++ b/papers/format.md @@ -4,8 +4,12 @@ while Furnace works directly with the .dmf format, I had to create a new format this document has the goal of detailing the format. +**notice:** GitHub's Markdown formatter may break on this file as it doesn't seem to treat tables correctly. + # information +files may be zlib-compressed, but Furnace accepts uncompressed files as well. + all numbers are little-endian. the following fields may be found in "size": @@ -25,10 +29,12 @@ furthermore, an `or reserved` indicates this field is always present, but is res the format versions are: +- 60: Furnace dev60 - 59: Furnace dev59 - 58: Furnace dev58 - 57: Furnace dev57 +- 54: Furnace 0.5.8 - 53: Furnace 0.5.7 - 52: Furnace 0.5.7pre4 - 51: Furnace 0.5.7pre3 @@ -69,6 +75,7 @@ the format versions are: the header is 32 bytes long. +``` size | description -----|------------------------------------ 16 | "-Furnace module-" format magic @@ -76,9 +83,11 @@ size | description 2 | reserved 4 | song info pointer 8 | reserved +``` # song info +``` size | description -----|------------------------------------ 4 | "INFO" block ID @@ -189,9 +198,9 @@ size | description 4?? | pointers to samples 4?? | pointers to patterns ??? | orders - | - a table of shorts + | - a table of bytes | - size=channels*ordLen - | - read orders than channels + | - read orders then channels ??? | effect columns | - size=channels 1?? | channel hide status @@ -205,9 +214,11 @@ size | description STR | song comment 4f | master volume, 1.0f=100% (>=59) | this is 2.0f for modules before 59 +``` # instrument +``` size | description -----|------------------------------------ 4 | "INST" block ID @@ -227,7 +238,11 @@ size | description 1 | fms 1 | ams 1 | operator count (always 4) - 3 | reserved + 1 | OPLL preset (>=60) or reserved + | - 0: custom + | - 1-15: pre-defined patches + | - 16: drums (compatibility only!) + 2 | reserved --- | **FM operator data** × 4 1 | am 1 | ar @@ -411,9 +426,11 @@ size | description 4 | DT macro release 4 | D2R macro release 4 | SSG-EG macro release +``` # wavetable +``` size | description -----|------------------------------------ 4 | "WAVE" block ID @@ -423,9 +440,11 @@ size | description 4 | wavetable min 4 | wavetable max 4?? | wavetable data +``` # sample +``` size | description -----|------------------------------------ 4 | "SMPL" block ID @@ -453,9 +472,11 @@ size | description ??? | sample data | - version<58 size is length*2 | - version>=58 size is length +``` # pattern +``` size | description -----|------------------------------------ 4 | "PATR" block ID @@ -472,11 +493,13 @@ size | description | - volume | - effect and effect data... STR | pattern name (>=51) +``` # the Furnace instrument format (.fui) the instrument format is pretty similar to the file format, but it also stores wavetables and samples used by the instrument. +``` size | description -----|------------------------------------ 16 | "-Furnace instr.-" format magic @@ -488,6 +511,7 @@ size | description 4 | reserved 4?? | pointers to wavetables 4?? | pointers to samples +``` instrument data follows. @@ -495,10 +519,12 @@ instrument data follows. similar to the instrument format... +``` size | description -----|------------------------------------ 16 | "-Furnace waveta-" format magic 2 | format version 2 | reserved +``` wavetable data follows. diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 801a3d84..0ff7b8e1 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -22,6 +22,7 @@ #include "platform/genesis.h" #include "platform/genesisext.h" #include "platform/sms.h" +#include "platform/opll.h" #include "platform/gb.h" #include "platform/pce.h" #include "platform/nes.h" @@ -193,6 +194,13 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do case DIV_SYSTEM_TIA: dispatch=new DivPlatformTIA; break; + case DIV_SYSTEM_OPLL: + case DIV_SYSTEM_OPLL_DRUMS: + case DIV_SYSTEM_VRC7: + dispatch=new DivPlatformOPLL; + ((DivPlatformOPLL*)dispatch)->setVRC7(sys==DIV_SYSTEM_VRC7); + ((DivPlatformOPLL*)dispatch)->setProperDrums(sys==DIV_SYSTEM_OPLL_DRUMS); + break; case DIV_SYSTEM_SAA1099: { int saaCore=eng->getConfInt("saaCore",0); if (saaCore<0 || saaCore>2) saaCore=0; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 29c293e8..87fac32d 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -460,12 +460,12 @@ void DivEngine::renderSamples() { memPos=(memPos+0xfffff)&0xf00000; } if (memPos>=16777216) { - logW("out of ADPCM memory for sample %d!\n",i); + logW("out of ADPCM-A memory for sample %d!\n",i); break; } if (memPos+paddedLen>=16777216) { memcpy(adpcmAMem+memPos,s->dataA,16777216-memPos); - logW("out of ADPCM memory for sample %d!\n",i); + logW("out of ADPCM-A memory for sample %d!\n",i); } else { memcpy(adpcmAMem+memPos,s->dataA,paddedLen); } @@ -474,6 +474,31 @@ void DivEngine::renderSamples() { } adpcmAMemLen=memPos+256; + // step 2: allocate ADPCM-B samples + if (adpcmBMem==NULL) adpcmBMem=new unsigned char[16777216]; + + memPos=0; + for (int i=0; ilengthB+255)&(~0xff); + if ((memPos&0xf00000)!=((memPos+paddedLen)&0xf00000)) { + memPos=(memPos+0xfffff)&0xf00000; + } + if (memPos>=16777216) { + logW("out of ADPCM-B memory for sample %d!\n",i); + break; + } + if (memPos+paddedLen>=16777216) { + memcpy(adpcmBMem+memPos,s->dataB,16777216-memPos); + logW("out of ADPCM-B memory for sample %d!\n",i); + } else { + memcpy(adpcmBMem+memPos,s->dataB,paddedLen); + } + s->offB=memPos; + memPos+=paddedLen; + } + adpcmBMemLen=memPos+256; + // step 4: allocate qsound pcm samples if (qsoundMem==NULL) qsoundMem=new unsigned char[16777216]; @@ -623,6 +648,11 @@ DivWavetable* DivEngine::getWave(int index) { return song.wave[index]; } +DivSample* DivEngine::getSample(int index) { + if (index<0 || index>=song.sampleLen) return &song.nullSample; + return song.sample[index]; +} + void DivEngine::setLoops(int loops) { remainingLoops=loops; } @@ -1121,15 +1151,24 @@ enum DivInsFormats { DIV_INSFORMAT_BTI }; -bool DivEngine::addInstrumentFromFile(const char *path) { +bool DivEngine::addInstrumentFromFile(const char* path) { warnings=""; const char* pathRedux=strrchr(path,DIR_SEPARATOR); if (pathRedux==NULL) { - pathRedux="Instrument"; + pathRedux=path; } else { pathRedux++; } + String stripPath; + const char* pathReduxEnd=strrchr(pathRedux,'.'); + if (pathReduxEnd==NULL) { + stripPath=pathRedux; + } else { + for (const char* i=pathRedux; i!=pathReduxEnd && (*i); i++) { + stripPath+=*i; + } + } FILE* f=ps_fopen(path,"rb"); if (f==NULL) { @@ -1254,7 +1293,7 @@ bool DivEngine::addInstrumentFromFile(const char *path) { return false; } - ins->name=pathRedux; + ins->name=stripPath; if (version>=11) { // 1.0 try { @@ -1487,7 +1526,7 @@ bool DivEngine::addInstrumentFromFile(const char *path) { reader.seek(0,SEEK_SET); ins->type=DIV_INS_FM; - ins->name=pathRedux; + ins->name=stripPath; ins->fm.alg=reader.readC(); ins->fm.fb=reader.readC(); @@ -1519,7 +1558,7 @@ bool DivEngine::addInstrumentFromFile(const char *path) { reader.seek(0,SEEK_SET); ins->type=DIV_INS_FM; - ins->name=pathRedux; + ins->name=stripPath; ins->fm.alg=reader.readC(); ins->fm.fb=reader.readC(); @@ -1788,7 +1827,7 @@ bool DivEngine::addSampleFromFile(const char* path) { } averaged/=si.channels; if (((si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_U8)) { - sample->data8[index++]=averaged; + sample->data8[index++]=averaged>>8; } else { sample->data16[index++]=averaged; } diff --git a/src/engine/engine.h b/src/engine/engine.h index f4324fb6..f0ef1833 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -37,8 +37,8 @@ warnings+=(String("\n")+x); \ } -#define DIV_VERSION "dev59" -#define DIV_ENGINE_VERSION 59 +#define DIV_VERSION "dev60" +#define DIV_ENGINE_VERSION 60 enum DivStatusView { DIV_STATUS_NOTHING=0, @@ -260,6 +260,7 @@ class DivEngine { void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size); DivInstrument* getIns(int index); DivWavetable* getWave(int index); + DivSample* getSample(int index); // start fresh void createNew(); // load a file. diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index b8c57c5b..7bb53c40 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -221,14 +221,6 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { addWarning("Yamaha YMU759 emulation is not currently possible!"); } - if (ds.system[0]==DIV_SYSTEM_SMS_OPLL) { - addWarning("Master System FM expansion is not emulated yet. wait for 0.6!"); - } - - if (ds.system[0]==DIV_SYSTEM_NES_VRC7) { - addWarning("Konami VRC7 is not emulated yet. wait for 0.6!"); - } - logI("reading pattern matrix (%d)...\n",ds.ordersLen); for (int i=0; ifm.ops; j++) { ins->fm.op[j].am=reader.readC(); ins->fm.op[j].ar=reader.readC(); + if (ds.system[0]==DIV_SYSTEM_SMS_OPLL || ds.system[0]==DIV_SYSTEM_NES_VRC7) { + ins->fm.op[j].ar&=15; + } if (ds.version<0x13) { ins->fm.op[j].dam=reader.readC(); } ins->fm.op[j].dr=reader.readC(); + if (ds.system[0]==DIV_SYSTEM_SMS_OPLL || ds.system[0]==DIV_SYSTEM_NES_VRC7) { + ins->fm.op[j].dr&=15; + } if (ds.version<0x13) { ins->fm.op[j].dvb=reader.readC(); ins->fm.op[j].egt=reader.readC(); diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index 57e9cbf4..fa5564c9 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -40,9 +40,9 @@ void DivInstrument::putInsData(SafeWriter* w) { w->writeC(fm.fms); w->writeC(fm.ams); w->writeC(4); // operator count; always 4 + w->writeC(fm.opllPreset); w->writeC(0); // reserved w->writeC(0); - w->writeC(0); for (int j=0; j<4; j++) { DivInstrumentFM::Operator& op=fm.op[j]; @@ -325,7 +325,11 @@ DivDataErrors DivInstrument::readInsData(SafeReader& reader, short version) { fm.fms=reader.readC(); fm.ams=reader.readC(); fm.ops=reader.readC(); - reader.readC(); + if (version>=60) { + fm.opllPreset=reader.readC(); + } else { + reader.readC(); + } reader.readC(); reader.readC(); diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 2d02a4bf..d5dbc8a6 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -54,7 +54,7 @@ struct DivInstrumentFM { unsigned char alg, fb, fms, ams, ops, opllPreset; struct Operator { unsigned char am, ar, dr, mult, rr, sl, tl, dt2, rs, dt, d2r, ssgEnv; - unsigned char dam, dvb, egt, ksl, sus, vib, ws, ksr; // YMU759 + unsigned char dam, dvb, egt, ksl, sus, vib, ws, ksr; // YMU759/OPL Operator(): am(0), ar(0), @@ -82,7 +82,8 @@ struct DivInstrumentFM { fb(0), fms(0), ams(0), - ops(4) { + ops(4), + opllPreset(0) { // default instrument fb=4; op[0].tl=42; @@ -160,31 +161,55 @@ struct DivInstrumentSTD { unsigned char dtMacro[256]; unsigned char d2rMacro[256]; unsigned char ssgMacro[256]; + unsigned char damMacro[256]; + unsigned char dvbMacro[256]; + unsigned char egtMacro[256]; + unsigned char kslMacro[256]; + unsigned char susMacro[256]; + unsigned char vibMacro[256]; + unsigned char wsMacro[256]; + unsigned char ksrMacro[256]; bool amMacroOpen, arMacroOpen, drMacroOpen, multMacroOpen; bool rrMacroOpen, slMacroOpen, tlMacroOpen, dt2MacroOpen; bool rsMacroOpen, dtMacroOpen, d2rMacroOpen, ssgMacroOpen; + bool damMacroOpen, dvbMacroOpen, egtMacroOpen, kslMacroOpen; + bool susMacroOpen, vibMacroOpen, wsMacroOpen, ksrMacroOpen; unsigned char amMacroLen, arMacroLen, drMacroLen, multMacroLen; unsigned char rrMacroLen, slMacroLen, tlMacroLen, dt2MacroLen; unsigned char rsMacroLen, dtMacroLen, d2rMacroLen, ssgMacroLen; + unsigned char damMacroLen, dvbMacroLen, egtMacroLen, kslMacroLen; + unsigned char susMacroLen, vibMacroLen, wsMacroLen, ksrMacroLen; signed char amMacroLoop, arMacroLoop, drMacroLoop, multMacroLoop; signed char rrMacroLoop, slMacroLoop, tlMacroLoop, dt2MacroLoop; signed char rsMacroLoop, dtMacroLoop, d2rMacroLoop, ssgMacroLoop; + signed char damMacroLoop, dvbMacroLoop, egtMacroLoop, kslMacroLoop; + signed char susMacroLoop, vibMacroLoop, wsMacroLoop, ksrMacroLoop; signed char amMacroRel, arMacroRel, drMacroRel, multMacroRel; signed char rrMacroRel, slMacroRel, tlMacroRel, dt2MacroRel; signed char rsMacroRel, dtMacroRel, d2rMacroRel, ssgMacroRel; + signed char damMacroRel, dvbMacroRel, egtMacroRel, kslMacroRel; + signed char susMacroRel, vibMacroRel, wsMacroRel, ksrMacroRel; OpMacro(): amMacroOpen(false), arMacroOpen(false), drMacroOpen(false), multMacroOpen(false), rrMacroOpen(false), slMacroOpen(false), tlMacroOpen(true), dt2MacroOpen(false), rsMacroOpen(false), dtMacroOpen(false), d2rMacroOpen(false), ssgMacroOpen(false), + damMacroOpen(false), dvbMacroOpen(false), egtMacroOpen(false), kslMacroOpen(false), + susMacroOpen(false), vibMacroOpen(false), wsMacroOpen(false), ksrMacroOpen(false), amMacroLen(0), arMacroLen(0), drMacroLen(0), multMacroLen(0), rrMacroLen(0), slMacroLen(0), tlMacroLen(0), dt2MacroLen(0), rsMacroLen(0), dtMacroLen(0), d2rMacroLen(0), ssgMacroLen(0), + damMacroLen(0), dvbMacroLen(0), egtMacroLen(0), kslMacroLen(0), + susMacroLen(0), vibMacroLen(0), wsMacroLen(0), ksrMacroLen(0), amMacroLoop(-1), arMacroLoop(-1), drMacroLoop(-1), multMacroLoop(-1), rrMacroLoop(-1), slMacroLoop(-1), tlMacroLoop(-1), dt2MacroLoop(-1), rsMacroLoop(-1), dtMacroLoop(-1), d2rMacroLoop(-1), ssgMacroLoop(-1), + damMacroLoop(-1), dvbMacroLoop(-1), egtMacroLoop(-1), kslMacroLoop(-1), + susMacroLoop(-1), vibMacroLoop(-1), wsMacroLoop(-1), ksrMacroLoop(-1), amMacroRel(-1), arMacroRel(-1), drMacroRel(-1), multMacroRel(-1), rrMacroRel(-1), slMacroRel(-1), tlMacroRel(-1), dt2MacroRel(-1), - rsMacroRel(-1), dtMacroRel(-1), d2rMacroRel(-1), ssgMacroRel(-1) { + rsMacroRel(-1), dtMacroRel(-1), d2rMacroRel(-1), ssgMacroRel(-1), + damMacroRel(-1), dvbMacroRel(-1), egtMacroRel(-1), kslMacroRel(-1), + susMacroRel(-1), vibMacroRel(-1), wsMacroRel(-1), ksrMacroRel(-1) { memset(amMacro,0,256); memset(arMacro,0,256); memset(drMacro,0,256); @@ -197,6 +222,14 @@ struct DivInstrumentSTD { memset(dtMacro,0,256); memset(d2rMacro,0,256); memset(ssgMacro,0,256); + memset(damMacro,0,256); + memset(dvbMacro,0,256); + memset(egtMacro,0,256); + memset(kslMacro,0,256); + memset(susMacro,0,256); + memset(vibMacro,0,256); + memset(wsMacro,0,256); + memset(ksrMacro,0,256); } } opMacros[4]; DivInstrumentSTD(): diff --git a/src/engine/platform/amiga.cpp b/src/engine/platform/amiga.cpp index 98a95a33..3ee2fd39 100644 --- a/src/engine/platform/amiga.cpp +++ b/src/engine/platform/amiga.cpp @@ -71,7 +71,7 @@ void DivPlatformAmiga::acquire(short* bufL, short* bufR, size_t start, size_t le if (chan[i].sample>=0 && chan[i].samplesong.sampleLen) { chan[i].audSub-=AMIGA_DIVIDER; if (chan[i].audSub<0) { - DivSample* s=parent->song.sample[chan[i].sample]; + DivSample* s=parent->getSample(chan[i].sample); if (s->samples>0) { chan[i].audDat=s->data8[chan[i].audPos++]; if (chan[i].audPos>=s->samples || chan[i].audPos>=131071) { @@ -117,7 +117,7 @@ void DivPlatformAmiga::tick() { } double off=1.0; if (chan[i].sample>=0 && chan[i].samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[i].sample]; + DivSample* s=parent->getSample(chan[i].sample); if (s->centerRate<1) { off=1.0; } else { @@ -171,7 +171,7 @@ int DivPlatformAmiga::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.initSample; double off=1.0; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[c.chan].sample]; + DivSample* s=parent->getSample(chan[c.chan].sample); if (s->centerRate<1) { off=1.0; } else { @@ -258,7 +258,7 @@ int DivPlatformAmiga::dispatch(DivCommand c) { case DIV_CMD_LEGATO: { double off=1.0; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[c.chan].sample]; + DivSample* s=parent->getSample(chan[c.chan].sample); if (s->centerRate<1) { off=1.0; } else { diff --git a/src/engine/platform/gb.cpp b/src/engine/platform/gb.cpp index 3944f67a..f02ea197 100644 --- a/src/engine/platform/gb.cpp +++ b/src/engine/platform/gb.cpp @@ -216,7 +216,6 @@ void DivPlatformGB::tick() { chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].freq>2047) chan[i].freq=2047; } - if (chan[i].note>0x5d) chan[i].freq=0x01; if (chan[i].keyOn) { if (i==2) { // wave if (chan[i].wave<0) { diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 9314c7b6..6f666306 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -89,7 +89,7 @@ void DivPlatformGenesis::acquire_nuked(short* bufL, short* bufR, size_t start, s if (dacMode && dacSample!=-1) { dacPeriod-=6; if (dacPeriod<1) { - DivSample* s=parent->song.sample[dacSample]; + DivSample* s=parent->getSample(dacSample); if (s->samples>0) { if (!isMuted[5]) { immWrite(0x2a,(unsigned char)s->data8[dacPos]+0x80); @@ -159,7 +159,7 @@ void DivPlatformGenesis::acquire_ymfm(short* bufL, short* bufR, size_t start, si if (dacMode && dacSample!=-1) { dacPeriod-=24; if (dacPeriod<1) { - DivSample* s=parent->song.sample[dacSample]; + DivSample* s=parent->getSample(dacSample); if (s->samples>0) { if (!isMuted[5]) { immWrite(0x2a,(unsigned char)s->data8[dacPos]+0x80); @@ -373,7 +373,7 @@ void DivPlatformGenesis::tick() { if (chan[i].furnaceDac && dacMode) { double off=1.0; if (dacSample>=0 && dacSamplesong.sampleLen) { - DivSample* s=parent->song.sample[dacSample]; + DivSample* s=parent->getSample(dacSample); if (s->centerRate<1) { off=1.0; } else { @@ -510,8 +510,8 @@ int DivPlatformGenesis::dispatch(DivCommand c) { } dacPos=0; dacPeriod=0; - dacRate=1280000/MAX(1,parent->song.sample[dacSample]->rate); - if (dumpWrites) addWrite(0xffff0001,parent->song.sample[dacSample]->rate); + dacRate=1280000/MAX(1,parent->getSample(dacSample)->rate); + if (dumpWrites) addWrite(0xffff0001,parent->getSample(dacSample)->rate); chan[c.chan].furnaceDac=false; } break; diff --git a/src/engine/platform/lynx.cpp b/src/engine/platform/lynx.cpp index 856950f9..2783ba5d 100644 --- a/src/engine/platform/lynx.cpp +++ b/src/engine/platform/lynx.cpp @@ -273,6 +273,7 @@ void DivPlatformLynx::forceIns() { chan[i].insChanged=true; chan[i].freqChanged=true; } + WRITE_ATTEN(i,chan[i].pan); } } diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index 10bb38fe..897d8e84 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -75,7 +75,7 @@ void DivPlatformNES::acquire(short* bufL, short* bufR, size_t start, size_t len) if (dacSample!=-1) { dacPeriod+=dacRate; if (dacPeriod>=rate) { - DivSample* s=parent->song.sample[dacSample]; + DivSample* s=parent->getSample(dacSample); if (s->samples>0) { if (!isMuted[4]) { rWrite(0x4011,((unsigned char)s->data8[dacPos]+0x80)>>1); @@ -238,7 +238,7 @@ void DivPlatformNES::tick() { if (chan[4].furnaceDac) { double off=1.0; if (dacSample>=0 && dacSamplesong.sampleLen) { - DivSample* s=parent->song.sample[dacSample]; + DivSample* s=parent->getSample(dacSample); off=(double)s->centerRate/8363.0; } dacRate=MIN(chan[4].freq*off,32000); @@ -286,7 +286,7 @@ int DivPlatformNES::dispatch(DivCommand c) { } dacPos=0; dacPeriod=0; - dacRate=parent->song.sample[dacSample]->rate; + dacRate=parent->getSample(dacSample)->rate; if (dumpWrites) addWrite(0xffff0001,dacRate); chan[c.chan].furnaceDac=false; } diff --git a/src/engine/platform/opll.cpp b/src/engine/platform/opll.cpp new file mode 100644 index 00000000..0ca5a6c2 --- /dev/null +++ b/src/engine/platform/opll.cpp @@ -0,0 +1,716 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * 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 2 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "opll.h" +#include "../engine.h" +#include +#include + +#define rWrite(a,v) if (!skipRegisterWrites) {pendingWrites[a]=v;} +#define immWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} } + +#define CHIP_FREQBASE 295017 + +const char* DivPlatformOPLL::getEffectName(unsigned char effect) { + switch (effect) { + case 0x10: + return "10xy: Setup LFO (x: enable; y: speed)"; + break; + case 0x11: + return "11xx: Set feedback (0 to 7)"; + break; + case 0x12: + return "12xx: Set level of operator 1 (0 highest, 7F lowest)"; + break; + case 0x13: + return "13xx: Set level of operator 2 (0 highest, 7F lowest)"; + break; + case 0x14: + return "14xx: Set level of operator 3 (0 highest, 7F lowest)"; + break; + case 0x15: + return "15xx: Set level of operator 4 (0 highest, 7F lowest)"; + break; + case 0x16: + return "16xy: Set operator multiplier (x: operator from 1 to 4; y: multiplier)"; + break; + case 0x17: + return "17xx: Enable channel 6 DAC"; + break; + case 0x18: + return "18xx: Toggle extended channel 3 mode"; + break; + case 0x19: + return "19xx: Set attack of all operators (0 to 1F)"; + break; + case 0x1a: + return "1Axx: Set attack of operator 1 (0 to 1F)"; + break; + case 0x1b: + return "1Bxx: Set attack of operator 2 (0 to 1F)"; + break; + case 0x1c: + return "1Cxx: Set attack of operator 3 (0 to 1F)"; + break; + case 0x1d: + return "1Dxx: Set attack of operator 4 (0 to 1F)"; + break; + } + return NULL; +} + +const unsigned char cycleMapOPLL[18]={ + 1, 2, 0, 1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 6, 7, 8, 0 +}; + +void DivPlatformOPLL::acquire_nuked(short* bufL, short* bufR, size_t start, size_t len) { + static int o[2]; + static int os; + + for (size_t h=start; h32767) os=32767; + bufL[h]=os; + } +} + +void DivPlatformOPLL::acquire_ymfm(short* bufL, short* bufR, size_t start, size_t len) { +} + +void DivPlatformOPLL::acquire(short* bufL, short* bufR, size_t start, size_t len) { + acquire_nuked(bufL,bufR,start,len); +} + +void DivPlatformOPLL::tick() { + for (int i=0; i<9; i++) { + chan[i].std.next(); + + if (chan[i].std.hadVol) { + chan[i].outVol=(chan[i].vol*MIN(127,chan[i].std.vol))/127; + rWrite(0x30+i,(15-(chan[i].outVol*(15-chan[i].state.op[1].tl))/15)|(chan[i].state.opllPreset<<4)); + } + + if (chan[i].std.hadArp) { + if (!chan[i].inPorta) { + if (chan[i].std.arpMode) { + chan[i].baseFreq=NOTE_FREQUENCY(chan[i].std.arp); + } else { + chan[i].baseFreq=NOTE_FREQUENCY(chan[i].note+(signed char)chan[i].std.arp); + } + } + chan[i].freqChanged=true; + } else { + if (chan[i].std.arpMode && chan[i].std.finishedArp) { + chan[i].baseFreq=NOTE_FREQUENCY(chan[i].note); + chan[i].freqChanged=true; + } + } +/* + if (chan[i].std.hadAlg) { + chan[i].state.alg=chan[i].std.alg; + rWrite(chanOffs[i]+ADDR_FB_ALG,(chan[i].state.alg&7)|(chan[i].state.fb<<3)); + } + if (chan[i].std.hadFb) { + chan[i].state.fb=chan[i].std.fb; + } + if (chan[i].std.hadFms) { + chan[i].state.fms=chan[i].std.fms; + } + if (chan[i].std.hadAms) { + chan[i].state.ams=chan[i].std.ams; + } + for (int j=0; j<2; j++) { + unsigned short baseAddr=chanOffs[i]|opOffs[j]; + DivInstrumentFM::Operator& op=chan[i].state.op[j]; + DivMacroInt::IntOp& m=chan[i].std.op[j]; + if (m.hadAm) { + op.am=m.am; + rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7)); + } + if (m.hadAr) { + op.ar=m.ar; + rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6)); + } + if (m.hadDr) { + op.dr=m.dr; + rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7)); + } + if (m.hadMult) { + op.mult=m.mult; + rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4)); + } + if (m.hadRr) { + op.rr=m.rr; + rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4)); + } + if (m.hadSl) { + op.sl=m.sl; + rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4)); + } + if (m.hadTl) { + op.tl=127-m.tl; + if (isMuted[i]) { + rWrite(baseAddr+ADDR_TL,127); + } else { + if (isOutput[chan[i].state.alg][j]) { + rWrite(baseAddr+ADDR_TL,127-(((127-op.tl)*(chan[i].outVol&0x7f))/127)); + } else { + rWrite(baseAddr+ADDR_TL,op.tl); + } + } + } + if (m.hadRs) { + op.rs=m.rs; + rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6)); + } + if (m.hadDt) { + op.dt=m.dt; + rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4)); + } + if (m.hadD2r) { + op.d2r=m.d2r; + rWrite(baseAddr+ADDR_DT2_D2R,op.d2r&31); + } + if (m.hadSsg) { + op.ssgEnv=m.ssg; + rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15); + } + }*/ + + if (chan[i].keyOn || chan[i].keyOff) { + if (i>=6 && drums) { + drumState&=~(0x10>>(chan[i].note%12)); + immWrite(0x0e,0x20|drumState); + } else { + immWrite(0x20+i,(chan[i].freqH)/*|(chan[i].state.alg?0x20:0)*/); + } + //chan[i].keyOn=false; + chan[i].keyOff=false; + } + } + + for (int i=0; i<256; i++) { + if (pendingWrites[i]!=oldWrites[i]) { + immWrite(i,pendingWrites[i]&0xff); + oldWrites[i]=pendingWrites[i]; + } + } + + for (int i=0; i<9; i++) { + if (chan[i].freqChanged) { + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,false,octave(chan[i].baseFreq)); + if (chan[i].freq>262143) chan[i].freq=262143; + int freqt=toFreq(chan[i].freq); + chan[i].freqH=freqt>>8; + chan[i].freqL=freqt&0xff; + if (i<6 || !drums) { + immWrite(0x10+i,freqt&0xff); + } + } + if (chan[i].keyOn && i>=6 && drums) { + //printf("%d\n",chan[i].note%12); + drumState|=(0x10>>(chan[i].note%12)); + immWrite(0x0e,0x20|drumState); + chan[i].keyOn=false; + } else if (chan[i].keyOn || chan[i].freqChanged) { + //immWrite(0x28,0xf0|konOffs[i]); + immWrite(0x20+i,(chan[i].freqH)|(chan[i].active<<4)|(chan[i].state.alg?0x20:0)); + chan[i].keyOn=false; + } + chan[i].freqChanged=false; + } +} + +#define OPLL_C_NUM 343 + +int DivPlatformOPLL::octave(int freq) { + if (freq>=OPLL_C_NUM*64) { + return 128; + } else if (freq>=OPLL_C_NUM*32) { + return 64; + } else if (freq>=OPLL_C_NUM*16) { + return 32; + } else if (freq>=OPLL_C_NUM*8) { + return 16; + } else if (freq>=OPLL_C_NUM*4) { + return 8; + } else if (freq>=OPLL_C_NUM*2) { + return 4; + } else if (freq>=OPLL_C_NUM) { + return 2; + } else { + return 1; + } + return 1; +} + +int DivPlatformOPLL::toFreq(int freq) { + if (freq>=OPLL_C_NUM*64) { + return 0xe00|((freq>>7)&0x1ff); + } else if (freq>=OPLL_C_NUM*32) { + return 0xc00|((freq>>6)&0x1ff); + } else if (freq>=OPLL_C_NUM*16) { + return 0xa00|((freq>>5)&0x1ff); + } else if (freq>=OPLL_C_NUM*8) { + return 0x800|((freq>>4)&0x1ff); + } else if (freq>=OPLL_C_NUM*4) { + return 0x600|((freq>>3)&0x1ff); + } else if (freq>=OPLL_C_NUM*2) { + return 0x400|((freq>>2)&0x1ff); + } else if (freq>=OPLL_C_NUM) { + return 0x200|((freq>>1)&0x1ff); + } else { + return freq&0x1ff; + } +} + +void DivPlatformOPLL::muteChannel(int ch, bool mute) { + isMuted[ch]=mute; + /* + for (int j=0; j<4; j++) { + unsigned short baseAddr=chanOffs[ch]|opOffs[j]; + DivInstrumentFM::Operator& op=chan[ch].state.op[j]; + if (isMuted[ch]) { + rWrite(baseAddr+ADDR_TL,127); + } else { + if (isOutput[chan[ch].state.alg][j]) { + rWrite(baseAddr+ADDR_TL,127-(((127-op.tl)*(chan[ch].outVol&0x7f))/127)); + } else { + rWrite(baseAddr+ADDR_TL,op.tl); + } + } + } + rWrite(chanOffs[ch]+ADDR_LRAF,(isMuted[ch]?0:(chan[ch].pan<<6))|(chan[ch].state.fms&7)|((chan[ch].state.ams&3)<<4));*/ +} + +int DivPlatformOPLL::dispatch(DivCommand c) { + switch (c.cmd) { + case DIV_CMD_NOTE_ON: { + DivInstrument* ins=parent->getIns(chan[c.chan].ins); + if (chan[c.chan].insChanged) { + chan[c.chan].state=ins->fm; + } + + chan[c.chan].std.init(ins); + if (!chan[c.chan].std.willVol) { + chan[c.chan].outVol=chan[c.chan].vol; + } + + if (chan[c.chan].insChanged) { + // update custom preset + if (chan[c.chan].state.opllPreset==0) { + DivInstrumentFM::Operator& mod=chan[c.chan].state.op[0]; + DivInstrumentFM::Operator& car=chan[c.chan].state.op[1]; + rWrite(0x00,(mod.am<<7)|(mod.vib<<6)|((mod.ssgEnv&8)<<2)|(mod.ksr<<4)|(mod.mult)); + rWrite(0x01,(car.am<<7)|(car.vib<<6)|((car.ssgEnv&8)<<2)|(car.ksr<<4)|(car.mult)); + rWrite(0x02,(car.ksl<<6)|(mod.tl&63)); + rWrite(0x03,(mod.ksl<<6)|((chan[c.chan].state.fms&1)<<4)|((chan[c.chan].state.ams&1)<<3)|chan[c.chan].state.fb); + rWrite(0x04,(mod.ar<<4)|(mod.dr)); + rWrite(0x05,(car.ar<<4)|(car.dr)); + rWrite(0x06,(mod.sl<<4)|(mod.rr)); + rWrite(0x07,(car.sl<<4)|(car.rr)); + } + if (chan[c.chan].state.opllPreset==16) { // compatible drums mode + if (c.chan>=6) { + drums=true; + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x18,0xC0); + immWrite(0x28,0x01); + } + } else { + if (c.chan>=6) { + drums=false; + immWrite(0x0e,0); + } + rWrite(0x30+c.chan,(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15)|(chan[c.chan].state.opllPreset<<4)); + } + } + + chan[c.chan].insChanged=false; + + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value); + chan[c.chan].note=c.value; + + if (c.chan>=6 && drums) { + switch (chan[c.chan].note%12) { + case 0: // kick + drumVol[0]=(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15); + break; + case 1: // snare + drumVol[1]=(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15); + break; + case 2: // tom + drumVol[2]=(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15); + break; + case 3: // top + drumVol[3]=(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15); + break; + default: // hi-hat + drumVol[4]=(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15); + break; + } + rWrite(0x36,drumVol[0]); + rWrite(0x37,drumVol[1]|(drumVol[4]<<4)); + rWrite(0x38,drumVol[3]|(drumVol[2]<<4)); + } + chan[c.chan].freqChanged=true; + } + chan[c.chan].keyOn=true; + chan[c.chan].active=true; + break; + } + case DIV_CMD_NOTE_OFF: + chan[c.chan].keyOff=true; + chan[c.chan].keyOn=false; + chan[c.chan].active=false; + break; + case DIV_CMD_NOTE_OFF_ENV: + chan[c.chan].keyOff=true; + chan[c.chan].keyOn=false; + chan[c.chan].active=false; + chan[c.chan].std.release(); + break; + case DIV_CMD_ENV_RELEASE: + chan[c.chan].std.release(); + break; + case DIV_CMD_VOLUME: { + chan[c.chan].vol=c.value; + if (!chan[c.chan].std.hasVol) { + chan[c.chan].outVol=c.value; + } + if (c.chan<6 || !drums) { + rWrite(0x30+c.chan,(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15)|(chan[c.chan].state.opllPreset<<4)); + } + break; + } + case DIV_CMD_GET_VOLUME: { + return chan[c.chan].vol; + break; + } + case DIV_CMD_INSTRUMENT: + if (chan[c.chan].ins!=c.value || c.value2==1) { + chan[c.chan].insChanged=true; + } + chan[c.chan].ins=c.value; + break; + case DIV_CMD_PITCH: { + chan[c.chan].pitch=c.value; + chan[c.chan].freqChanged=true; + break; + } + case DIV_CMD_NOTE_PORTA: { + int destFreq=NOTE_FREQUENCY(c.value2); + int newFreq; + bool return2=false; + if (destFreq>chan[c.chan].baseFreq) { + newFreq=chan[c.chan].baseFreq+c.value*octave(chan[c.chan].baseFreq); + if (newFreq>=destFreq) { + newFreq=destFreq; + return2=true; + } + } else { + newFreq=chan[c.chan].baseFreq-c.value*octave(chan[c.chan].baseFreq); + if (newFreq<=destFreq) { + newFreq=destFreq; + return2=true; + } + } + /*if (!chan[c.chan].portaPause) { + if (octave(chan[c.chan].baseFreq)!=octave(newFreq)) { + chan[c.chan].portaPause=true; + break; + } + }*/ + chan[c.chan].baseFreq=newFreq; + chan[c.chan].portaPause=false; + chan[c.chan].freqChanged=true; + if (return2) { + chan[c.chan].inPorta=false; + return 2; + } + break; + } + case DIV_CMD_LEGATO: { + chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value); + chan[c.chan].note=c.value; + chan[c.chan].freqChanged=true; + break; + } + case DIV_CMD_FM_FB: { + DivInstrumentFM::Operator& mod=chan[c.chan].state.op[0]; + //DivInstrumentFM::Operator& car=chan[c.chan].state.op[1]; + chan[c.chan].state.fb=c.value&7; + rWrite(0x03,(mod.ksl<<6)|((chan[c.chan].state.fms&1)<<4)|((chan[c.chan].state.ams&1)<<3)|chan[c.chan].state.fb); + break; + } + + case DIV_CMD_FM_MULT: { + if (c.value==0) { + DivInstrumentFM::Operator& mod=chan[c.chan].state.op[0]; + mod.mult=c.value2&15; + rWrite(0x00,(mod.am<<7)|(mod.vib<<6)|((mod.ssgEnv&8)<<2)|(mod.ksr<<4)|(mod.mult)); + } else { + DivInstrumentFM::Operator& car=chan[c.chan].state.op[1]; + car.mult=c.value2&15; + rWrite(0x30+c.chan,(15-(chan[c.chan].outVol*(15-chan[c.chan].state.op[1].tl))/15)|(chan[c.chan].state.opllPreset<<4)); + } + break; + } + case DIV_CMD_FM_TL: { + if (c.value==0) { + DivInstrumentFM::Operator& mod=chan[c.chan].state.op[0]; + DivInstrumentFM::Operator& car=chan[c.chan].state.op[1]; + mod.tl=c.value2&63; + rWrite(0x02,(car.ksl<<6)|(mod.tl&63)); + } else { + DivInstrumentFM::Operator& car=chan[c.chan].state.op[1]; + car.tl=c.value2&15; + rWrite(0x01,(car.am<<7)|(car.vib<<6)|((car.ssgEnv&8)<<2)|(car.ksr<<4)|(car.mult)); + } + break; + } + case DIV_CMD_FM_AR: { + DivInstrumentFM::Operator& mod=chan[c.chan].state.op[0]; + DivInstrumentFM::Operator& car=chan[c.chan].state.op[1]; + if (c.value<0) { + mod.ar=c.value2&15; + car.ar=c.value2&15; + } else { + if (c.value==0) { + mod.ar=c.value2&15; + } else { + car.ar=c.value2&15; + } + } + rWrite(0x04,(mod.ar<<4)|(mod.dr)); + rWrite(0x05,(car.ar<<4)|(car.dr)); + break; + } + case DIV_ALWAYS_SET_VOLUME: + return 0; + break; + case DIV_CMD_GET_VOLMAX: + return 15; + break; + case DIV_CMD_PRE_PORTA: + chan[c.chan].inPorta=c.value; + break; + case DIV_CMD_PRE_NOTE: + break; + default: + //printf("WARNING: unimplemented command %d\n",c.cmd); + break; + } + return 1; +} + +void DivPlatformOPLL::forceIns() { + for (int i=0; i<9; i++) { + // update custom preset + if (chan[i].state.opllPreset==0) { + DivInstrumentFM::Operator& mod=chan[i].state.op[0]; + DivInstrumentFM::Operator& car=chan[i].state.op[1]; + rWrite(0x00,(mod.am<<7)|(mod.vib<<6)|((mod.ssgEnv&8)<<2)|(mod.ksr<<4)|(mod.mult)); + rWrite(0x01,(car.am<<7)|(car.vib<<6)|((car.ssgEnv&8)<<2)|(car.ksr<<4)|(car.mult)); + rWrite(0x02,(car.ksl<<6)|(mod.tl&63)); + rWrite(0x03,(mod.ksl<<6)|((chan[i].state.fms&1)<<4)|((chan[i].state.ams&1)<<3)|chan[i].state.fb); + rWrite(0x04,(mod.ar<<4)|(mod.dr)); + rWrite(0x05,(car.ar<<4)|(car.dr)); + rWrite(0x06,(mod.sl<<4)|(mod.rr)); + rWrite(0x07,(car.sl<<4)|(car.rr)); + } + rWrite(0x30+i,(15-(chan[i].outVol*(15-chan[i].state.op[1].tl))/15)|(chan[i].state.opllPreset<<4)); + if (chan[i].active) { + chan[i].keyOn=true; + chan[i].freqChanged=true; + } + } + if (drums) { + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x16,0x20); + immWrite(0x26,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x17,0x50); + immWrite(0x27,0x05); + immWrite(0x18,0xC0); + immWrite(0x28,0x01); + } +} + +void DivPlatformOPLL::toggleRegisterDump(bool enable) { + DivDispatch::toggleRegisterDump(enable); +} + +void DivPlatformOPLL::setVRC7(bool vrc) { + vrc7=vrc; +} + +void DivPlatformOPLL::setProperDrums(bool pd) { + properDrums=pd; +} + + +void* DivPlatformOPLL::getChanState(int ch) { + return &chan[ch]; +} + +unsigned char* DivPlatformOPLL::getRegisterPool() { + return regPool; +} + +int DivPlatformOPLL::getRegisterPoolSize() { + return 64; +} + +void DivPlatformOPLL::reset() { + while (!writes.empty()) writes.pop(); + memset(regPool,0,256); + if (vrc7) { + OPLL_Reset(&fm,opll_type_ds1001); + } else { + OPLL_Reset(&fm,opll_type_ym2413); + } + if (dumpWrites) { + addWrite(0xffffffff,0); + } + for (int i=0; i<9; i++) { + chan[i]=DivPlatformOPLL::Channel(); + chan[i].vol=15; + chan[i].outVol=15; + } + + for (int i=0; i<256; i++) { + oldWrites[i]=-1; + pendingWrites[i]=-1; + } + + lastBusy=60; + drumState=0; + + drumVol[0]=0; + drumVol[1]=0; + drumVol[2]=0; + drumVol[3]=0; + drumVol[4]=0; + + delay=0; +} + +bool DivPlatformOPLL::keyOffAffectsArp(int ch) { + return false; +} + +bool DivPlatformOPLL::keyOffAffectsPorta(int ch) { + return false; +} + +void DivPlatformOPLL::notifyInsChange(int ins) { + for (int i=0; i<9; i++) { + if (chan[i].ins==ins) { + chan[i].insChanged=true; + } + } +} + +void DivPlatformOPLL::notifyInsDeletion(void* ins) { +} + +void DivPlatformOPLL::poke(unsigned int addr, unsigned short val) { + immWrite(addr,val); +} + +void DivPlatformOPLL::poke(std::vector& wlist) { + for (DivRegWrite& i: wlist) immWrite(i.addr,i.val); +} + +int DivPlatformOPLL::getPortaFloor(int ch) { + return (ch>5)?12:0; +} + +void DivPlatformOPLL::setYMFM(bool use) { + useYMFM=use; +} + +void DivPlatformOPLL::setFlags(unsigned int flags) { + if (flags==3) { + chipClock=COLOR_NTSC; + } else if (flags==2) { + chipClock=8000000.0; + } else if (flags==1) { + chipClock=COLOR_PAL*1.0/5.0; + } else { + chipClock=COLOR_NTSC/4.0; + } + rate=chipClock/9; +} + +int DivPlatformOPLL::init(DivEngine* p, int channels, int sugRate, unsigned int flags) { + parent=p; + dumpWrites=false; + skipRegisterWrites=false; + for (int i=0; i<9; i++) { + isMuted[i]=false; + } + setFlags(flags); + + reset(); + return 10; +} + +void DivPlatformOPLL::quit() { +} + +DivPlatformOPLL::~DivPlatformOPLL() { +} diff --git a/src/engine/platform/opll.h b/src/engine/platform/opll.h new file mode 100644 index 00000000..87e97057 --- /dev/null +++ b/src/engine/platform/opll.h @@ -0,0 +1,120 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * 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 2 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _OPLL_H +#define _OPLL_H +#include "../dispatch.h" +#include "../macroInt.h" +#include + +extern "C" { +#include "../../../extern/Nuked-OPLL/opll.h" +} + +class DivPlatformOPLL: public DivDispatch { + protected: + struct Channel { + DivInstrumentFM state; + DivMacroInt std; + unsigned char freqH, freqL; + int freq, baseFreq, pitch, note; + unsigned char ins; + bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnaceDac, inPorta; + int vol, outVol; + unsigned char pan; + Channel(): + freqH(0), + freqL(0), + freq(0), + baseFreq(0), + pitch(0), + note(0), + ins(-1), + active(false), + insChanged(true), + freqChanged(false), + keyOn(false), + keyOff(false), + portaPause(false), + furnaceDac(false), + inPorta(false), + vol(0), + pan(3) {} + }; + Channel chan[11]; + bool isMuted[11]; + struct QueuedWrite { + unsigned short addr; + unsigned char val; + bool addrOrVal; + QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {} + }; + std::queue writes; + opll_t fm; + int delay; + unsigned char lastBusy; + unsigned char drumState; + unsigned char drumVol[5]; + + unsigned char regPool[256]; + + bool useYMFM; + bool drums; + bool properDrums; + bool vrc7; + + short oldWrites[256]; + short pendingWrites[256]; + + int octave(int freq); + int toFreq(int freq); + + friend void putDispatchChan(void*,int,int); + + void acquire_nuked(short* bufL, short* bufR, size_t start, size_t len); + void acquire_ymfm(short* bufL, short* bufR, size_t start, size_t len); + + public: + void acquire(short* bufL, short* bufR, size_t start, size_t len); + int dispatch(DivCommand c); + void* getChanState(int chan); + unsigned char* getRegisterPool(); + int getRegisterPoolSize(); + void reset(); + void forceIns(); + void tick(); + void muteChannel(int ch, bool mute); + void setYMFM(bool use); + bool keyOffAffectsArp(int ch); + bool keyOffAffectsPorta(int ch); + void toggleRegisterDump(bool enable); + void setVRC7(bool vrc); + void setProperDrums(bool pd); + void setFlags(unsigned int flags); + void notifyInsChange(int ins); + void notifyInsDeletion(void* ins); + int getPortaFloor(int ch); + void poke(unsigned int addr, unsigned short val); + void poke(std::vector& wlist); + const char* getEffectName(unsigned char effect); + int init(DivEngine* parent, int channels, int sugRate, unsigned int flags); + void quit(); + ~DivPlatformOPLL(); +}; +#endif diff --git a/src/engine/platform/pce.cpp b/src/engine/platform/pce.cpp index 0ffe5043..7b45dfa7 100644 --- a/src/engine/platform/pce.cpp +++ b/src/engine/platform/pce.cpp @@ -81,7 +81,7 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len) if (chan[i].pcm && chan[i].dacSample!=-1) { chan[i].dacPeriod+=chan[i].dacRate; if (chan[i].dacPeriod>rate) { - DivSample* s=parent->song.sample[chan[i].dacSample]; + DivSample* s=parent->getSample(chan[i].dacSample); if (s->samples<=0) { chan[i].dacSample=-1; continue; @@ -200,7 +200,7 @@ void DivPlatformPCE::tick() { if (chan[i].furnaceDac) { double off=1.0; if (chan[i].dacSample>=0 && chan[i].dacSamplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[i].dacSample]; + DivSample* s=parent->getSample(chan[i].dacSample); if (s->centerRate<1) { off=1.0; } else { @@ -211,7 +211,6 @@ void DivPlatformPCE::tick() { if (dumpWrites) addWrite(0xffff0001+(i<<8),chan[i].dacRate); } if (chan[i].freq>4095) chan[i].freq=4095; - if (chan[i].note>0x5d) chan[i].freq=0x01; chWrite(i,0x02,chan[i].freq&0xff); chWrite(i,0x03,chan[i].freq>>8); if (chan[i].keyOn) { @@ -280,7 +279,7 @@ int DivPlatformPCE::dispatch(DivCommand c) { } chan[c.chan].dacPos=0; chan[c.chan].dacPeriod=0; - chan[c.chan].dacRate=parent->song.sample[chan[c.chan].dacSample]->rate; + chan[c.chan].dacRate=parent->getSample(chan[c.chan].dacSample)->rate; if (dumpWrites) { chWrite(c.chan,0x04,0xdf); addWrite(0xffff0001+(c.chan<<8),chan[c.chan].dacRate); diff --git a/src/engine/platform/qsound.cpp b/src/engine/platform/qsound.cpp index 3364e476..0e0637d8 100644 --- a/src/engine/platform/qsound.cpp +++ b/src/engine/platform/qsound.cpp @@ -290,7 +290,7 @@ void DivPlatformQSound::tick() { uint16_t qsound_end = 0; double off=1.0; if (chan[i].sample>=0 && chan[i].samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[i].sample]; + DivSample* s=parent->getSample(chan[i].sample); if (s->centerRate<1) { off=1.0; } else { @@ -364,7 +364,7 @@ int DivPlatformQSound::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.initSample; double off=1.0; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[c.chan].sample]; + DivSample* s=parent->getSample(chan[c.chan].sample); if (s->centerRate<1) { off=1.0; } else { @@ -438,7 +438,7 @@ int DivPlatformQSound::dispatch(DivCommand c) { case DIV_CMD_NOTE_PORTA: { double off=1.0; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[c.chan].sample]; + DivSample* s=parent->getSample(chan[c.chan].sample); if (s->centerRate<1) { off=1.0; } else { @@ -470,7 +470,7 @@ int DivPlatformQSound::dispatch(DivCommand c) { case DIV_CMD_LEGATO: { double off=1.0; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[c.chan].sample]; + DivSample* s=parent->getSample(chan[c.chan].sample); if (s->centerRate<1) { off=1.0; } else { diff --git a/src/engine/platform/segapcm.cpp b/src/engine/platform/segapcm.cpp index ba04c099..7872e0b6 100644 --- a/src/engine/platform/segapcm.cpp +++ b/src/engine/platform/segapcm.cpp @@ -43,7 +43,7 @@ void DivPlatformSegaPCM::acquire(short* bufL, short* bufR, size_t start, size_t pcmL=0; pcmR=0; for (int i=0; i<16; i++) { if (chan[i].pcm.sample>=0 && chan[i].pcm.samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[i].pcm.sample]; + DivSample* s=parent->getSample(chan[i].pcm.sample); if (s->samples<=0) { chan[i].pcm.sample=-1; continue; @@ -110,7 +110,7 @@ void DivPlatformSegaPCM::tick() { if (chan[i].furnacePCM) { double off=1.0; if (chan[i].pcm.sample>=0 && chan[i].pcm.samplesong.sampleLen) { - DivSample* s=parent->song.sample[chan[i].pcm.sample]; + DivSample* s=parent->getSample(chan[i].pcm.sample); off=(double)s->centerRate/8363.0; } chan[i].pcm.freq=MIN(255,((off*parent->song.tuning*pow(2.0,double(chan[i].freq+256)/(64.0*12.0)))*255)/31250); @@ -146,7 +146,7 @@ int DivPlatformSegaPCM::dispatch(DivCommand c) { chan[c.chan].freqChanged=true; chan[c.chan].furnacePCM=true; if (dumpWrites) { // Sega PCM writes - DivSample* s=parent->song.sample[chan[c.chan].pcm.sample]; + DivSample* s=parent->getSample(chan[c.chan].pcm.sample); addWrite(0x10086+(c.chan<<3),3+((s->offSegaPCM>>16)<<3)); addWrite(0x10084+(c.chan<<3),(s->offSegaPCM)&0xff); addWrite(0x10085+(c.chan<<3),(s->offSegaPCM>>8)&0xff); @@ -173,10 +173,10 @@ int DivPlatformSegaPCM::dispatch(DivCommand c) { break; } chan[c.chan].pcm.pos=0; - chan[c.chan].pcm.freq=MIN(255,(parent->song.sample[chan[c.chan].pcm.sample]->rate*255)/31250); + chan[c.chan].pcm.freq=MIN(255,(parent->getSample(chan[c.chan].pcm.sample)->rate*255)/31250); chan[c.chan].furnacePCM=false; if (dumpWrites) { // Sega PCM writes - DivSample* s=parent->song.sample[chan[c.chan].pcm.sample]; + DivSample* s=parent->getSample(chan[c.chan].pcm.sample); addWrite(0x10086+(c.chan<<3),3+((s->offSegaPCM>>16)<<3)); addWrite(0x10084+(c.chan<<3),(s->offSegaPCM)&0xff); addWrite(0x10085+(c.chan<<3),(s->offSegaPCM>>8)&0xff); diff --git a/src/engine/platform/sound/qsound.c b/src/engine/platform/sound/qsound.c index b52475b3..8e4d6fa9 100644 --- a/src/engine/platform/sound/qsound.c +++ b/src/engine/platform/sound/qsound.c @@ -601,8 +601,8 @@ static void state_normal_update(struct qsound_chip *chip) { // Echo is output on the unfiltered component of the left channel and // the filtered component of the right channel. - int32_t wet = (ch == 1) ? echo_output<<16 : 0; - int32_t dry = (ch == 0) ? echo_output<<16 : 0; + int32_t wet = (ch == 1) ? echo_output<<14 : 0; + int32_t dry = (ch == 0) ? echo_output<<14 : 0; int32_t output = 0; for(int v=0; v<19; v++) diff --git a/src/engine/platform/ym2610.cpp b/src/engine/platform/ym2610.cpp index eb2b43f9..e9e77d81 100644 --- a/src/engine/platform/ym2610.cpp +++ b/src/engine/platform/ym2610.cpp @@ -101,6 +101,13 @@ const char* DivPlatformYM2610::getEffectName(unsigned char effect) { return NULL; } +double DivPlatformYM2610::NOTE_ADPCMB(int note) { + DivInstrument* ins=parent->getIns(chan[13].ins); + if (ins->type!=DIV_INS_AMIGA) return 0; + double off=(double)(parent->getSample(ins->amiga.initSample)->centerRate)/8363.0; + return off*parent->calcBaseFreq((double)chipClock/144,65535,note,false); +} + void DivPlatformYM2610::acquire(short* bufL, short* bufR, size_t start, size_t len) { static int os[2]; @@ -358,6 +365,38 @@ void DivPlatformYM2610::tick() { } } + // ADPCM-B + if (chan[13].furnacePCM) { + chan[13].std.next(); + + if (chan[13].std.hadVol) { + chan[13].outVol=(chan[13].vol*MIN(64,chan[13].std.vol))/64; + immWrite(0x1b,chan[13].outVol); + } + + if (chan[13].std.hadArp) { + if (!chan[13].inPorta) { + if (chan[13].std.arpMode) { + chan[13].baseFreq=NOTE_ADPCMB(chan[13].std.arp); + } else { + chan[13].baseFreq=NOTE_ADPCMB(chan[13].note+(signed char)chan[13].std.arp); + } + } + chan[13].freqChanged=true; + } else { + if (chan[13].std.arpMode && chan[13].std.finishedArp) { + chan[13].baseFreq=NOTE_ADPCMB(chan[13].note); + chan[13].freqChanged=true; + } + } + } + if (chan[13].freqChanged) { + chan[13].freq=parent->calcFreq(chan[13].baseFreq,chan[13].pitch,false,4); + immWrite(0x19,chan[13].freq&0xff); + immWrite(0x1a,(chan[13].freq>>8)&0xff); + chan[13].freqChanged=false; + } + for (int i=0; i<512; i++) { if (pendingWrites[i]!=oldWrites[i]) { immWrite(i,pendingWrites[i]&0xff); @@ -426,7 +465,60 @@ int DivPlatformYM2610::toFreq(int freq) { int DivPlatformYM2610::dispatch(DivCommand c) { switch (c.cmd) { case DIV_CMD_NOTE_ON: { - if (c.chan>6) { // ADPCM + if (c.chan>12) { // ADPCM-B + DivInstrument* ins=parent->getIns(chan[c.chan].ins); + if (ins->type==DIV_INS_AMIGA) { + chan[c.chan].furnacePCM=true; + } else { + chan[c.chan].furnacePCM=false; + } + if (skipRegisterWrites) break; + if (chan[c.chan].furnacePCM) { + chan[c.chan].std.init(ins); + if (!chan[c.chan].std.willVol) { + chan[c.chan].outVol=chan[c.chan].vol; + immWrite(0x1b,chan[c.chan].outVol); + } + DivSample* s=parent->getSample(ins->amiga.initSample); + immWrite(0x12,(s->offB>>8)&0xff); + immWrite(0x13,s->offB>>16); + int end=s->offB+s->lengthB-1; + immWrite(0x14,(end>>8)&0xff); + immWrite(0x15,end>>16); + immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); + immWrite(0x10,0x80); // start + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].note=c.value; + chan[c.chan].baseFreq=NOTE_ADPCMB(chan[c.chan].note); + chan[c.chan].freqChanged=true; + } + chan[c.chan].active=true; + chan[c.chan].keyOn=true; + } else { + chan[c.chan].std.init(NULL); + chan[c.chan].outVol=chan[c.chan].vol; + if ((12*sampleBank+c.value%12)>=parent->song.sampleLen) { + immWrite(0x10,0x01); // reset + immWrite(0x12,0); + immWrite(0x13,0); + immWrite(0x14,0); + immWrite(0x15,0); + break; + } + DivSample* s=parent->getSample(12*sampleBank+c.value%12); + immWrite(0x12,(s->offB>>8)&0xff); + immWrite(0x13,s->offB>>16); + int end=s->offB+s->lengthB-1; + immWrite(0x14,(end>>8)&0xff); + immWrite(0x15,end>>16); + immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); + immWrite(0x10,0x80); // start + chan[c.chan].baseFreq=(((unsigned int)s->rate)<<16)/(chipClock/144); + chan[c.chan].freqChanged=true; + } + break; + } + if (c.chan>6) { // ADPCM-A if (skipRegisterWrites) break; if ((12*sampleBank+c.value%12)>=parent->song.sampleLen) { immWrite(0x100,0x80|(1<<(c.chan-7))); @@ -436,7 +528,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) { immWrite(0x128+c.chan-7,0); break; } - DivSample* s=parent->song.sample[12*sampleBank+c.value%12]; + DivSample* s=parent->getSample(12*sampleBank+c.value%12); immWrite(0x110+c.chan-7,(s->offA>>8)&0xff); immWrite(0x118+c.chan-7,s->offA>>16); int end=s->offA+s->lengthA-1; @@ -511,6 +603,10 @@ int DivPlatformYM2610::dispatch(DivCommand c) { break; } case DIV_CMD_NOTE_OFF: + if (c.chan>12) { + immWrite(0x10,0x01); // reset + break; + } if (c.chan>6) { immWrite(0x100,0x80|(1<<(c.chan-7))); break; @@ -521,6 +617,10 @@ int DivPlatformYM2610::dispatch(DivCommand c) { chan[c.chan].std.init(NULL); break; case DIV_CMD_NOTE_OFF_ENV: + if (c.chan>12) { + immWrite(0x10,0x01); // reset + break; + } if (c.chan>6) { immWrite(0x100,0x80|(1<<(c.chan-7))); break; @@ -542,7 +642,11 @@ int DivPlatformYM2610::dispatch(DivCommand c) { if (!chan[c.chan].std.hasVol) { chan[c.chan].outVol=c.value; } - if (c.chan>6) { // ADPCM + if (c.chan>12) { // ADPCM-B + immWrite(0x1b,chan[c.chan].outVol); + break; + } + if (c.chan>6) { // ADPCM-A immWrite(0x108+(c.chan-7),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol)); break; } @@ -587,6 +691,10 @@ int DivPlatformYM2610::dispatch(DivCommand c) { chan[c.chan].pan=3; break; } + if (c.chan>12) { + immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); + break; + } if (c.chan>6) { immWrite(0x108+(c.chan-7),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol)); break; @@ -773,7 +881,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) { return 0; break; case DIV_CMD_GET_VOLMAX: - if (c.chan>12) return 127; + if (c.chan>12) return 255; if (c.chan>6) return 31; if (c.chan>3) return 15; return 127; @@ -797,7 +905,10 @@ int DivPlatformYM2610::dispatch(DivCommand c) { void DivPlatformYM2610::muteChannel(int ch, bool mute) { isMuted[ch]=mute; - if (ch>6) { // ADPCM + if (ch>12) { // ADPCM-B + immWrite(0x11,isMuted[ch]?0:(chan[ch].pan<<6)); + } + if (ch>6) { // ADPCM-A immWrite(0x108+(ch-7),isMuted[ch]?0:((chan[ch].pan<<6)|chan[ch].vol)); return; } @@ -885,7 +996,7 @@ void DivPlatformYM2610::reset() { for (int i=7; i<13; i++) { chan[i].vol=0x1f; } - chan[13].vol=0x7f; + chan[13].vol=0xff; for (int i=0; i<512; i++) { oldWrites[i]=-1; @@ -916,7 +1027,8 @@ void DivPlatformYM2610::reset() { immWrite(0x22,0x08); // PCM volume - immWrite(0x101,0x3f); + immWrite(0x101,0x3f); // A + immWrite(0x1b,0xff); // B } bool DivPlatformYM2610::isStereo() { diff --git a/src/engine/platform/ym2610.h b/src/engine/platform/ym2610.h index 593e5668..317870f6 100644 --- a/src/engine/platform/ym2610.h +++ b/src/engine/platform/ym2610.h @@ -41,11 +41,32 @@ class DivPlatformYM2610: public DivDispatch { int freq, baseFreq, pitch, note; unsigned char ins, psgMode, autoEnvNum, autoEnvDen; signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta; + bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM; int vol, outVol; unsigned char pan; DivMacroInt std; - Channel(): freqH(0), freqL(0), freq(0), baseFreq(0), pitch(0), note(0), ins(-1), psgMode(1), autoEnvNum(0), autoEnvDen(0), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), portaPause(false), inPorta(false), vol(0), outVol(15), pan(3) {} + Channel(): + freqH(0), + freqL(0), + freq(0), + baseFreq(0), + pitch(0), + note(0), + ins(-1), + psgMode(1), + autoEnvNum(0), + autoEnvDen(0), + active(false), + insChanged(true), + freqChanged(false), + keyOn(false), + keyOff(false), + portaPause(false), + inPorta(false), + furnacePCM(false), + vol(0), + outVol(15), + pan(3) {} }; Channel chan[14]; bool isMuted[14]; @@ -83,6 +104,7 @@ class DivPlatformYM2610: public DivDispatch { int octave(int freq); int toFreq(int freq); + double NOTE_ADPCMB(int note); friend void putDispatchChan(void*,int,int); public: diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 5fb0c4e8..656bc35c 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -255,6 +255,8 @@ bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effe return true; } +#define IS_YM2610 (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT || sysOfChan[ch]==DIV_SYSTEM_YM2610_FULL || sysOfChan[ch]==DIV_SYSTEM_YM2610_FULL_EXT) + bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal) { switch (sysOfChan[ch]) { case DIV_SYSTEM_YM2612: @@ -262,6 +264,8 @@ bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char case DIV_SYSTEM_YM2151: case DIV_SYSTEM_YM2610: case DIV_SYSTEM_YM2610_EXT: + case DIV_SYSTEM_YM2610_FULL: + case DIV_SYSTEM_YM2610_FULL_EXT: switch (effect) { case 0x10: // LFO or noise mode if (sysOfChan[ch]==DIV_SYSTEM_YM2151) { @@ -324,42 +328,42 @@ bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char dispatchCmd(DivCommand(DIV_CMD_FM_PM_DEPTH,ch,effectVal&127)); break; case 0x20: // Neo Geo PSG mode - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal)); } break; case 0x21: // Neo Geo PSG noise freq - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_FREQ,ch,effectVal)); } break; case 0x22: // UNOFFICIAL: Neo Geo PSG envelope enable - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SET,ch,effectVal)); } break; case 0x23: // UNOFFICIAL: Neo Geo PSG envelope period low - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_LOW,ch,effectVal)); } break; case 0x24: // UNOFFICIAL: Neo Geo PSG envelope period high - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_HIGH,ch,effectVal)); } break; case 0x25: // UNOFFICIAL: Neo Geo PSG envelope slide up - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SLIDE,ch,-effectVal)); } break; case 0x26: // UNOFFICIAL: Neo Geo PSG envelope slide down - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SLIDE,ch,effectVal)); } break; case 0x29: // auto-envelope - if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) { + if (IS_YM2610) { dispatchCmd(DivCommand(DIV_CMD_AY_AUTO_ENVELOPE,ch,effectVal)); } break; @@ -367,6 +371,39 @@ bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char return false; } break; + case DIV_SYSTEM_OPLL: + case DIV_SYSTEM_OPLL_DRUMS: + case DIV_SYSTEM_VRC7: + switch (effect) { + case 0x11: // FB + dispatchCmd(DivCommand(DIV_CMD_FM_FB,ch,effectVal&7)); + break; + case 0x12: // TL op1 + dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,0,effectVal&0x3f)); + break; + case 0x13: // TL op2 + dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,1,effectVal&0x0f)); + break; + case 0x16: // MULT + if ((effectVal>>4)>0 && (effectVal>>4)<3) { + dispatchCmd(DivCommand(DIV_CMD_FM_MULT,ch,(effectVal>>4)-1,effectVal&15)); + } + break; + case 0x18: // drum mode toggle + break; + case 0x19: // AR global + dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,-1,effectVal&31)); + break; + case 0x1a: // AR op1 + dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,0,effectVal&31)); + break; + case 0x1b: // AR op2 + dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,1,effectVal&31)); + break; + default: + return false; + } + break; case DIV_SYSTEM_C64_6581: case DIV_SYSTEM_C64_8580: switch (effect) { case 0x10: // select waveform @@ -1137,7 +1174,6 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi } else { samp_temp=s->data16[sPreview.pos++]; } - if (s->depth==8) samp_temp<<=8; blip_add_delta(samp_bb,i,samp_temp-samp_prevSample); samp_prevSample=samp_temp; diff --git a/src/engine/song.h b/src/engine/song.h index c80bb6ca..85752288 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -275,6 +275,7 @@ struct DivSong { DivInstrument nullIns; DivWavetable nullWave; + DivSample nullSample; void unload(); diff --git a/src/engine/vgmOps.cpp b/src/engine/vgmOps.cpp index e51217dc..9424325c 100644 --- a/src/engine/vgmOps.cpp +++ b/src/engine/vgmOps.cpp @@ -20,15 +20,15 @@ #include "engine.h" #include "../ta-log.h" #include "../utfutils.h" +#include "song.h" constexpr int MASTER_CLOCK_PREC=(sizeof(void*)==8)?8:0; void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write, int streamOff, double* loopTimer, double* loopFreq, int* loopSample, bool isSecond) { if (write.addr==0xffffffff) { // Furnace fake reset switch (sys) { - case DIV_SYSTEM_GENESIS: - case DIV_SYSTEM_GENESIS_EXT: case DIV_SYSTEM_YM2612: + case DIV_SYSTEM_YM2612_EXT: for (int i=0; i<3; i++) { // set SL and RR to highest w->writeC(isSecond?0xa2:0x52); w->writeC(0x80+i); @@ -67,12 +67,6 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write w->writeC(isSecond?0xa2:0x52); // disable DAC w->writeC(0x2b); w->writeC(0); - if (sys!=DIV_SYSTEM_YM2612) { - for (int i=0; i<4; i++) { - w->writeC(isSecond?0x30:0x50); - w->writeC(0x90|(i<<5)|15); - } - } break; case DIV_SYSTEM_SMS: for (int i=0; i<4; i++) { @@ -128,7 +122,6 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write w->writeC(isSecond?0x95:0x15); w->writeC(0); break; - case DIV_SYSTEM_ARCADE: case DIV_SYSTEM_YM2151: for (int i=0; i<8; i++) { w->writeC(isSecond?0xa4:0x54); @@ -148,12 +141,13 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write w->writeC(0x08); w->writeC(i); } - if (sys==DIV_SYSTEM_ARCADE) { - for (int i=0; i<5; i++) { - w->writeC(0xc0); - w->writeS((isSecond?0x8086:0x86)+(i<<3)); - w->writeC(3); - } + break; + case DIV_SYSTEM_SEGAPCM: + case DIV_SYSTEM_SEGAPCM_COMPAT: + for (int i=0; i<16; i++) { + w->writeC(0xc0); + w->writeS((isSecond?0x8086:0x86)+(i<<3)); + w->writeC(3); } break; case DIV_SYSTEM_YM2610: @@ -301,6 +295,7 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write } if (write.addr>=0xffff0000) { // Furnace special command unsigned char streamID=streamOff+((write.addr&0xff00)>>8); + logD("writing stream command %x:%x with stream ID %d\n",write.addr,write.val,streamID); switch (write.addr&0xff) { case 0: // play sample if (write.val>8) { case 0: // port 0 w->writeC(isSecond?0xa2:0x52); @@ -369,20 +363,16 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write w->writeC((isSecond?0x80:0)|(write.addr&0xff)); w->writeC(write.val); break; - case DIV_SYSTEM_ARCADE: case DIV_SYSTEM_YM2151: - switch (write.addr>>16) { - case 0: // YM2151 - w->writeC(isSecond?0xa4:0x54); - w->writeC(write.addr&0xff); - w->writeC(write.val); - break; - case 1: // SegaPCM - w->writeC(0xc0); - w->writeS((isSecond?0x8000:0)|(write.addr&0xffff)); - w->writeC(write.val); - break; - } + w->writeC(isSecond?0xa4:0x54); + w->writeC(write.addr&0xff); + w->writeC(write.val); + break; + case DIV_SYSTEM_SEGAPCM: + case DIV_SYSTEM_SEGAPCM_COMPAT: + w->writeC(0xc0); + w->writeS((isSecond?0x8000:0)|(write.addr&0xffff)); + w->writeC(write.val); break; case DIV_SYSTEM_YM2610: case DIV_SYSTEM_YM2610_FULL: @@ -546,30 +536,6 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) { if (!sysToExport[i]) continue; } switch (song.system[i]) { - case DIV_SYSTEM_GENESIS: - case DIV_SYSTEM_GENESIS_EXT: - writeDACSamples=true; - if (!hasOPN2) { - hasOPN2=disCont[i].dispatch->chipClock; - willExport[i]=true; - } else if (!(hasOPN2&0x40000000)) { - isSecond[i]=true; - willExport[i]=true; - hasOPN2|=0x40000000; - howManyChips++; - addWarning("adding a compound system two times is experimental!"); - } - if (!hasSN) { - hasSN=3579545; - willExport[i]=true; - } else if (!(hasSN&0x40000000)) { - isSecond[i]=true; - willExport[i]=true; - hasSN|=0x40000000; - howManyChips++; - addWarning("adding a compound system two times is experimental!"); - } - break; case DIV_SYSTEM_SMS: if (!hasSN) { hasSN=disCont[i].dispatch->chipClock; @@ -630,17 +596,8 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) { howManyChips++; } break; - case DIV_SYSTEM_ARCADE: - if (!hasOPM) { - hasOPM=disCont[i].dispatch->chipClock; - willExport[i]=true; - } else if (!(hasOPM&0x40000000)) { - isSecond[i]=true; - willExport[i]=true; - hasOPM|=0x40000000; - howManyChips++; - addWarning("adding a compound system two times is experimental!"); - } + case DIV_SYSTEM_SEGAPCM: + case DIV_SYSTEM_SEGAPCM_COMPAT: if (!hasSegaPCM) { hasSegaPCM=4000000; willExport[i]=true; @@ -650,7 +607,6 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) { willExport[i]=true; hasSegaPCM|=0x40000000; howManyChips++; - addWarning("adding a compound system two times is experimental!"); } break; case DIV_SYSTEM_YM2610: @@ -694,6 +650,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) { } break; case DIV_SYSTEM_YM2612: + case DIV_SYSTEM_YM2612_EXT: if (!hasOPN2) { hasOPN2=disCont[i].dispatch->chipClock; willExport[i]=true; @@ -959,8 +916,8 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) { if (!willExport[i]) continue; streamIDs[i]=streamID; switch (song.system[i]) { - case DIV_SYSTEM_GENESIS: - case DIV_SYSTEM_GENESIS_EXT: + case DIV_SYSTEM_YM2612: + case DIV_SYSTEM_YM2612_EXT: w->writeC(0x90); w->writeC(streamID); w->writeC(0x02); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 1a5a13f4..ee0c0237 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -1355,13 +1355,17 @@ void FurnaceGUI::drawMixer() { signed char vol=e->song.systemVol[i]&127; ImGui::PushID(id); ImGui::Text("%d. %s",i+1,getSystemName(e->song.system[i])); - if (ImGui::SliderScalar("Volume",ImGuiDataType_S8,&vol,&_ZERO,&_ONE_HUNDRED_TWENTY_SEVEN)) { - e->song.systemVol[i]=(e->song.systemVol[i]&128)|vol; - } - ImGui::SliderScalar("Panning",ImGuiDataType_S8,&e->song.systemPan[i],&_MINUS_ONE_HUNDRED_TWENTY_SEVEN,&_ONE_HUNDRED_TWENTY_SEVEN); + ImGui::SameLine(ImGui::GetWindowWidth()-(82.0f*dpiScale)); if (ImGui::Checkbox("Invert",&doInvert)) { e->song.systemVol[i]^=128; } + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x-(50.0f*dpiScale)); + if (ImGui::SliderScalar("Volume",ImGuiDataType_S8,&vol,&_ZERO,&_ONE_HUNDRED_TWENTY_SEVEN)) { + e->song.systemVol[i]=(e->song.systemVol[i]&128)|vol; + } + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x-(50.0f*dpiScale)); + ImGui::SliderScalar("Panning",ImGuiDataType_S8,&e->song.systemPan[i],&_MINUS_ONE_HUNDRED_TWENTY_SEVEN,&_ONE_HUNDRED_TWENTY_SEVEN); + ImGui::PopID(); } } @@ -4491,6 +4495,8 @@ bool FurnaceGUI::loop() { sysAddOption(DIV_SYSTEM_YM2610_FULL_EXT); sysAddOption(DIV_SYSTEM_AY8910); sysAddOption(DIV_SYSTEM_AMIGA); + sysAddOption(DIV_SYSTEM_OPLL); + sysAddOption(DIV_SYSTEM_VRC7); sysAddOption(DIV_SYSTEM_TIA); sysAddOption(DIV_SYSTEM_SAA1099); sysAddOption(DIV_SYSTEM_AY8930); @@ -4603,11 +4609,11 @@ bool FurnaceGUI::loop() { case DIV_SYSTEM_AY8910: case DIV_SYSTEM_AY8930: { ImGui::Text("Clock rate:"); - if (ImGui::RadioButton("1.79MHz (ZX Spectrum/MSX NTSC)",(flags&15)==0)) { + if (ImGui::RadioButton("1.79MHz (ZX Spectrum NTSC/MSX)",(flags&15)==0)) { e->setSysFlags(i,(flags&(~15))|0,restart); updateWindowTitle(); } - if (ImGui::RadioButton("1.77MHz (ZX Spectrum/MSX PAL)",(flags&15)==1)) { + if (ImGui::RadioButton("1.77MHz (ZX Spectrum)",(flags&15)==1)) { e->setSysFlags(i,(flags&(~15))|1,restart); updateWindowTitle(); } @@ -4759,6 +4765,8 @@ bool FurnaceGUI::loop() { sysChangeOption(i,DIV_SYSTEM_YM2610_FULL_EXT); sysChangeOption(i,DIV_SYSTEM_AY8910); sysChangeOption(i,DIV_SYSTEM_AMIGA); + sysChangeOption(i,DIV_SYSTEM_OPLL); + sysChangeOption(i,DIV_SYSTEM_VRC7); sysChangeOption(i,DIV_SYSTEM_TIA); sysChangeOption(i,DIV_SYSTEM_SAA1099); sysChangeOption(i,DIV_SYSTEM_AY8930); @@ -4956,6 +4964,9 @@ bool FurnaceGUI::loop() { checkExtension(".dmf"); } } + if (curFileDialog==GUI_FILE_SAVE_DMF_LEGACY) { + checkExtension(".dmf"); + } if (curFileDialog==GUI_FILE_SAMPLE_SAVE || curFileDialog==GUI_FILE_EXPORT_AUDIO_ONE || curFileDialog==GUI_FILE_EXPORT_AUDIO_PER_SYS || diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 33ce458b..4790d61c 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -58,13 +58,13 @@ const char* ssgEnvTypes[8]={ "Down Down Down", "Down.", "Down Up Down Up", "Down UP", "Up Up Up", "Up.", "Up Down Up Down", "Up DOWN" }; -const char* fmParamNames[3][16]={ - {"Algorithm", "Feedback", "LFO > Freq", "LFO > Amp", "Attack", "Decay", "Decay 2", "Release", "Sustain", "Level", "EnvScale", "Multiplier", "Detune", "Detune 2", "SSG-EG", "AM"}, - {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "SR", "RR", "SL", "TL", "KS", "MULT", "DT", "DT2", "SSG-EG", "AM"}, - {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "D2R", "RR", "SL", "TL", "RS", "MULT", "DT", "DT2", "SSG-EG", "AM"} +const char* fmParamNames[3][27]={ + {"Algorithm", "Feedback", "LFO > Freq", "LFO > Amp", "Attack", "Decay", "Decay 2", "Release", "Sustain", "Level", "EnvScale", "Multiplier", "Detune", "Detune 2", "SSG-EG", "AM", "AM Depth", "Vibrato Depth", "EnvAlternate", "EnvAlternate", "LevelScale/key", "Sustain", "Vibrato", "Waveform", "EnvScale/key", "OP2 HalfSine", "OP1 HalfSine"}, + {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "SR", "RR", "SL", "TL", "KS", "MULT", "DT", "DT2", "SSG-EG", "AM", "AMD", "FMD", "EGT", "EGT", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM"}, + {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "D2R", "RR", "SL", "TL", "RS", "MULT", "DT", "DT2", "SSG-EG", "AM", "DAM", "DVB", "EGT", "EGS", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM"} }; -const char* opllInsNames[18]={ +const char* opllInsNames[17]={ "User", "Violin", "Guitar", @@ -100,7 +100,18 @@ enum FMParams { FM_DT=12, FM_DT2=13, FM_SSG=14, - FM_AM=15 + FM_AM=15, + FM_DAM=16, + FM_DVB=17, + FM_EGT=18, + FM_EGS=19, + FM_KSL=20, + FM_SUS=21, + FM_VIB=22, + FM_WS=23, + FM_KSR=24, + FM_DC=25, + FM_DM=26 }; #define FM_NAME(x) fmParamNames[settings.fmNames][x] @@ -429,6 +440,41 @@ void FurnaceGUI::drawAlgorithm(unsigned char alg, FurnaceGUIFMAlgs algType, cons } } break; + case FM_ALGS_2OP_OPL: + switch (alg) { + case 0: { // 1 > 2 + ImVec2 pos1=ImLerp(rect.Min,rect.Max,ImVec2(0.33,0.5)); + ImVec2 pos2=ImLerp(rect.Min,rect.Max,ImVec2(0.67,0.5)); + dl->AddCircleFilled(pos1,4.0f*dpiScale+1.0f,color); + dl->AddCircle(pos1,6.0f*dpiScale+1.0f,color); + dl->AddLine(pos1,pos2,colorL); + dl->AddCircleFilled(pos2,4.0f*dpiScale+1.0f,color); + + pos1.x-=ImGui::CalcTextSize("2").x+circleRadius+3.0*dpiScale; + pos2.x+=circleRadius+3.0*dpiScale; + pos1.y-=ImGui::CalcTextSize("1").y*0.5; + pos2.y-=ImGui::CalcTextSize("2").y*0.5; + dl->AddText(pos1,color,"1"); + dl->AddText(pos2,color,"2"); + break; + } + case 1: { // 1 + 2 + ImVec2 pos1=ImLerp(rect.Min,rect.Max,ImVec2(0.33,0.5)); + ImVec2 pos2=ImLerp(rect.Min,rect.Max,ImVec2(0.67,0.5)); + dl->AddCircleFilled(pos1,4.0f*dpiScale+1.0f,color); + dl->AddCircle(pos1,6.0f*dpiScale+1.0f,color); + dl->AddCircleFilled(pos2,4.0f*dpiScale+1.0f,color); + + pos1.x-=ImGui::CalcTextSize("2").x+circleRadius+3.0*dpiScale; + pos2.x+=circleRadius+3.0*dpiScale; + pos1.y-=ImGui::CalcTextSize("1").y*0.5; + pos2.y-=ImGui::CalcTextSize("2").y*0.5; + dl->AddText(pos1,color,"1"); + dl->AddText(pos2,color,"2"); + break; + } + } + break; default: break; } @@ -730,35 +776,89 @@ void FurnaceGUI::drawInsEdit() { ImGui::InputText("Name",&ins->name); if (ins->type<0 || ins->type>23) ins->type=DIV_INS_FM; int insType=ins->type; - if (ImGui::Combo("Type",&insType,insTypes,24)) { + if (ImGui::Combo("Type",&insType,insTypes,24,24)) { ins->type=(DivInstrumentType)insType; } if (ImGui::BeginTabBar("insEditTab")) { - if (ins->type==DIV_INS_FM) { + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPZ) { char label[32]; float asFloat[256]; int asInt[256]; float loopIndicator[256]; + int opCount=4; + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPLL) opCount=2; + if (ImGui::BeginTabItem("FM")) { if (ImGui::BeginTable("fmDetails",3,ImGuiTableFlags_SizingStretchSame)) { ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.0); ImGui::TableNextRow(); - ImGui::TableNextColumn(); - P(ImGui::SliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); - P(ImGui::SliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); - ImGui::TableNextColumn(); - P(ImGui::SliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); - P(ImGui::SliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); - ImGui::TableNextColumn(); - drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + switch (ins->type) { + case DIV_INS_FM: + case DIV_INS_OPZ: + ImGui::TableNextColumn(); + P(ImGui::SliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); + P(ImGui::SliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); + ImGui::TableNextColumn(); + P(ImGui::SliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); + P(ImGui::SliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); + ImGui::TableNextColumn(); + drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + break; + case DIV_INS_OPL: + case DIV_INS_OPLL: { + bool dc=ins->fm.fms; + bool dm=ins->fm.ams; + bool sus=ins->fm.alg; + ImGui::TableNextColumn(); + ImGui::BeginDisabled(ins->fm.opllPreset!=0); + P(ImGui::SliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); + if (ImGui::Checkbox(FM_NAME(FM_DC),&dc)) { PARAMETER + ins->fm.fms=dc; + } + ImGui::EndDisabled(); + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_NAME(FM_SUS),&sus)) { PARAMETER + ins->fm.alg=sus; + } + ImGui::BeginDisabled(ins->fm.opllPreset!=0); + if (ImGui::Checkbox(FM_NAME(FM_DM),&dm)) { PARAMETER + ins->fm.ams=dm; + } + ImGui::EndDisabled(); + ImGui::TableNextColumn(); + drawAlgorithm(0,FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::BeginCombo("##LLPreset",opllInsNames[ins->fm.opllPreset])) { + for (int i=0; i<17; i++) { + if (ImGui::Selectable(opllInsNames[i])) { + ins->fm.opllPreset=i; + } + } + ImGui::EndCombo(); + } + break; + } + default: + break; + } ImGui::EndTable(); } - if (ImGui::BeginTable("FMOperators",2,ImGuiTableFlags_SizingStretchSame)) { - for (int i=0; i<4; i++) { - DivInstrumentFM::Operator& op=ins->fm.op[opOrder[i]]; + + if (ins->type==DIV_INS_OPLL && ins->fm.opllPreset==16) { + ImGui::Text("the Drums patch is only there for compatibility.\nit is highly encouraged you use the OPLL (drums) system instead!"); + } + + bool willDisplayOps=true; + if (ins->type==DIV_INS_OPLL && ins->fm.opllPreset!=0) willDisplayOps=false; + if (!willDisplayOps && ins->type==DIV_INS_OPLL) { + P(ImGui::SliderScalar("Volume##TL",ImGuiDataType_U8,&ins->fm.op[1].tl,&_FIFTEEN,&_ZERO)); + } + if (willDisplayOps) if (ImGui::BeginTable("FMOperators",2,ImGuiTableFlags_SizingStretchSame)) { + for (int i=0; ifm.op[(opCount==4)?opOrder[i]:i]; if ((i+1)&1) ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Separator(); @@ -775,17 +875,31 @@ void FurnaceGUI::drawInsEdit() { ImGui::SameLine(); + int maxTl=127; + if (ins->type==DIV_INS_OPLL) { + if (i==1) { + maxTl=15; + } else { + maxTl=63; + } + } + int maxArDr=(ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ)?31:15; + bool ssgOn=op.ssgEnv&8; + bool ksrOn=op.ksr; + bool vibOn=op.vib; unsigned char ssgEnv=op.ssgEnv&7; - if (ImGui::Checkbox("SSG On",&ssgOn)) { PARAMETER + if (ImGui::Checkbox((ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPLL)?FM_NAME(FM_EGS):"SSG On",&ssgOn)) { PARAMETER op.ssgEnv=(op.ssgEnv&7)|(ssgOn<<3); } - if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("Only for Genesis and Neo Geo systems"); + if (ins->type==DIV_INS_FM) { + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Only for Genesis and Neo Geo systems"); + } } - //56.0 controls vert scaling; default 96 - drawFMEnv(op.tl,op.ar,op.dr,op.d2r,op.rr,op.sl,ImVec2(ImGui::GetContentRegionAvail().x,56.0*dpiScale)); + //52.0 controls vert scaling; default 96 + drawFMEnv(op.tl,op.ar,op.dr,op.d2r,op.rr,op.sl,ImVec2(ImGui::GetContentRegionAvail().x,52.0*dpiScale)); //P(ImGui::SliderScalar(FM_NAME(FM_AR),ImGuiDataType_U8,&op.ar,&_ZERO,&_THIRTY_ONE)); if (ImGui::BeginTable("opParams",2,ImGuiTableFlags_SizingStretchProp)) { ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); \ @@ -794,14 +908,14 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(ImGui::SliderScalar("##AR",ImGuiDataType_U8,&op.ar,&_THIRTY_ONE,&_ZERO)); + P(ImGui::SliderScalar("##AR",ImGuiDataType_U8,&op.ar,&maxArDr,&_ZERO)); ImGui::TableNextColumn(); ImGui::Text("%s",FM_NAME(FM_AR)); ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(ImGui::SliderScalar("##DR",ImGuiDataType_U8,&op.dr,&_THIRTY_ONE,&_ZERO)); + P(ImGui::SliderScalar("##DR",ImGuiDataType_U8,&op.dr,&maxArDr,&_ZERO)); ImGui::TableNextColumn(); ImGui::Text("%s",FM_NAME(FM_DR)); @@ -812,12 +926,14 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); ImGui::Text("%s",FM_NAME(FM_SL)); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(ImGui::SliderScalar("##D2R",ImGuiDataType_U8,&op.d2r,&_THIRTY_ONE,&_ZERO)); - ImGui::TableNextColumn(); - ImGui::Text("%s",FM_NAME(FM_D2R)); + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(ImGui::SliderScalar("##D2R",ImGuiDataType_U8,&op.d2r,&_THIRTY_ONE,&_ZERO)); + ImGui::TableNextColumn(); + ImGui::Text("%s",FM_NAME(FM_D2R)); + } ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -829,7 +945,7 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(ImGui::SliderScalar("##TL",ImGuiDataType_U8,&op.tl,&_ONE_HUNDRED_TWENTY_SEVEN,&_ZERO)); + P(ImGui::SliderScalar("##TL",ImGuiDataType_U8,&op.tl,&maxTl,&_ZERO)); ImGui::TableNextColumn(); ImGui::Text("%s",FM_NAME(FM_TL)); @@ -842,9 +958,15 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(ImGui::SliderScalar("##RS",ImGuiDataType_U8,&op.rs,&_ZERO,&_THREE)); - ImGui::TableNextColumn(); - ImGui::Text("%s",FM_NAME(FM_RS)); + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ) { + P(ImGui::SliderScalar("##RS",ImGuiDataType_U8,&op.rs,&_ZERO,&_THREE)); + ImGui::TableNextColumn(); + ImGui::Text("%s",FM_NAME(FM_RS)); + } else { + P(ImGui::SliderScalar("##KSL",ImGuiDataType_U8,&op.ksl,&_ZERO,&_THREE)); + ImGui::TableNextColumn(); + ImGui::Text("%s",FM_NAME(FM_KSL)); + } ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -853,37 +975,50 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); ImGui::Text("%s",FM_NAME(FM_MULT)); - int detune=(op.dt&7)-3; - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - if (ImGui::SliderInt("##DT",&detune,-3,3)) { PARAMETER - op.dt=detune+3; - } - ImGui::TableNextColumn(); - ImGui::Text("%s",FM_NAME(FM_DT)); + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ) { + int detune=(op.dt&7)-3; + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::SliderInt("##DT",&detune,-3,3)) { PARAMETER + op.dt=detune+3; + } + ImGui::TableNextColumn(); + ImGui::Text("%s",FM_NAME(FM_DT)); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(ImGui::SliderScalar("##DT2",ImGuiDataType_U8,&op.dt2,&_ZERO,&_THREE)); - if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("Only for Arcade system"); - } - ImGui::TableNextColumn(); - ImGui::Text("%s",FM_NAME(FM_DT2)); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(ImGui::SliderScalar("##DT2",ImGuiDataType_U8,&op.dt2,&_ZERO,&_THREE)); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Only for Arcade system"); + } + ImGui::TableNextColumn(); + ImGui::Text("%s",FM_NAME(FM_DT2)); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - if (ImGui::SliderScalar("##SSG",ImGuiDataType_U8,&ssgEnv,&_ZERO,&_SEVEN,ssgEnvTypes[ssgEnv])) { PARAMETER - op.ssgEnv=(op.ssgEnv&8)|(ssgEnv&7); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::SliderScalar("##SSG",ImGuiDataType_U8,&ssgEnv,&_ZERO,&_SEVEN,ssgEnvTypes[ssgEnv])) { PARAMETER + op.ssgEnv=(op.ssgEnv&8)|(ssgEnv&7); + } + ImGui::TableNextColumn(); + ImGui::Text("%s",FM_NAME(FM_SSG)); } - ImGui::TableNextColumn(); - ImGui::Text("%s",FM_NAME(FM_SSG)); ImGui::EndTable(); } + + if (ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPL) { + if (ImGui::Checkbox(FM_NAME(FM_VIB),&vibOn)) { PARAMETER + op.vib=vibOn; + } + ImGui::SameLine(); + if (ImGui::Checkbox(FM_NAME(FM_KSR),&ksrOn)) { PARAMETER + op.ksr=ksrOn; + } + } + ImGui::PopID(); } ImGui::EndTable(); @@ -904,15 +1039,25 @@ void FurnaceGUI::drawInsEdit() { MACRO_END; ImGui::EndTabItem(); } - for (int i=0; i<4; i++) { + for (int i=0; istd.opMacros[ordi].tlMacro,ins->std.opMacros[ordi].tlMacroLen,ins->std.opMacros[ordi].tlMacroLoop,ins->std.opMacros[ordi].tlMacroRel,127,ordi,"tl",FM_NAME(FM_TL),128,ins->std.opMacros[ordi].tlMacroOpen,false,NULL,mmlString[0]); - OP_MACRO(ins->std.opMacros[ordi].arMacro,ins->std.opMacros[ordi].arMacroLen,ins->std.opMacros[ordi].arMacroLoop,ins->std.opMacros[ordi].arMacroRel,31,ordi,"ar",FM_NAME(FM_AR),64,ins->std.opMacros[ordi].arMacroOpen,false,NULL,mmlString[1]); - OP_MACRO(ins->std.opMacros[ordi].drMacro,ins->std.opMacros[ordi].drMacroLen,ins->std.opMacros[ordi].drMacroLoop,ins->std.opMacros[ordi].drMacroRel,31,ordi,"dr",FM_NAME(FM_DR),64,ins->std.opMacros[ordi].drMacroOpen,false,NULL,mmlString[2]); + int ordi=(opCount==4)?orderedOps[i]:i; + int maxTl=127; + if (ins->type==DIV_INS_OPLL) { + if (i==1) { + maxTl=15; + } else { + maxTl=63; + } + } + int maxArDr=(ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ)?31:15; + + OP_MACRO(ins->std.opMacros[ordi].tlMacro,ins->std.opMacros[ordi].tlMacroLen,ins->std.opMacros[ordi].tlMacroLoop,ins->std.opMacros[ordi].tlMacroRel,maxTl,ordi,"tl",FM_NAME(FM_TL),128,ins->std.opMacros[ordi].tlMacroOpen,false,NULL,mmlString[0]); + OP_MACRO(ins->std.opMacros[ordi].arMacro,ins->std.opMacros[ordi].arMacroLen,ins->std.opMacros[ordi].arMacroLoop,ins->std.opMacros[ordi].arMacroRel,maxArDr,ordi,"ar",FM_NAME(FM_AR),64,ins->std.opMacros[ordi].arMacroOpen,false,NULL,mmlString[1]); + OP_MACRO(ins->std.opMacros[ordi].drMacro,ins->std.opMacros[ordi].drMacroLen,ins->std.opMacros[ordi].drMacroLoop,ins->std.opMacros[ordi].drMacroRel,maxArDr,ordi,"dr",FM_NAME(FM_DR),64,ins->std.opMacros[ordi].drMacroOpen,false,NULL,mmlString[2]); OP_MACRO(ins->std.opMacros[ordi].d2rMacro,ins->std.opMacros[ordi].d2rMacroLen,ins->std.opMacros[ordi].d2rMacroLoop,ins->std.opMacros[ordi].d2rMacroRel,31,ordi,"d2r",FM_NAME(FM_D2R),64,ins->std.opMacros[ordi].d2rMacroOpen,false,NULL,mmlString[3]); OP_MACRO(ins->std.opMacros[ordi].rrMacro,ins->std.opMacros[ordi].rrMacroLen,ins->std.opMacros[ordi].rrMacroLoop,ins->std.opMacros[ordi].rrMacroRel,15,ordi,"rr",FM_NAME(FM_RR),64,ins->std.opMacros[ordi].rrMacroOpen,false,NULL,mmlString[4]); OP_MACRO(ins->std.opMacros[ordi].slMacro,ins->std.opMacros[ordi].slMacroLen,ins->std.opMacros[ordi].slMacroLoop,ins->std.opMacros[ordi].slMacroRel,15,ordi,"sl",FM_NAME(FM_SL),64,ins->std.opMacros[ordi].slMacroOpen,false,NULL,mmlString[5]); @@ -1546,7 +1691,7 @@ void FurnaceGUI::drawWaveEdit() { wavePreview[i]=wave->data[i]; } if (wave->len>0) wavePreview[wave->len]=wave->data[wave->len-1]; - + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); //wavetable text input size found here if (ImGui::InputText("##MMLWave",&mmlStringW)) { decodeMMLStrW(mmlStringW,wave->data,wave->len,wave->max); } @@ -1555,7 +1700,11 @@ void FurnaceGUI::drawWaveEdit() { } ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,ImVec2(0.0f,0.0f)); - ImVec2 contentRegion=ImGui::GetContentRegionAvail(); + + ImVec2 contentRegion=ImGui::GetContentRegionAvail(); //wavetable graph size determined here + if (ImGui::GetContentRegionAvail().y > (ImGui::GetContentRegionAvail().x / 2.0f)) { + contentRegion=ImVec2(ImGui::GetContentRegionAvail().x,ImGui::GetContentRegionAvail().x / 2.0f); + } PlotNoLerp("##Waveform",wavePreview,wave->len+1,0,NULL,0,wave->max,contentRegion); if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) { waveDragStart=ImGui::GetItemRectMin();