diff --git a/branches/fceux-2.2.2/Authors b/branches/fceux-2.2.2/Authors new file mode 100644 index 00000000..799599be --- /dev/null +++ b/branches/fceux-2.2.2/Authors @@ -0,0 +1,72 @@ +Authors +======= + +A list of people who have contributed code to FCE Ultra, or have had their code +placed in FCE Ultra by others. + +Pre-2.0 FCE / FCE Ultra Contributors +------------------------------------ +_These authors contributed exclusively to pre-2.0 versions, +but much of their code remains in 2.0 builds_ + +* BERO - bero at geocities.co.jp - Base FCE code. + +* Xodnizel - Most of the base FCE Ultra code + +* Aaron Oneal - http://www.morphgear.com - Many changes to compile with MSVC and first frame skipping code + +* Joe Nahmias - Man pages + +* Paul Kuliniewicz - kuliniew at purdue.edu - Various code for the original SDL port. + +* Quietust - quietust at ircN dot org - VRC7 "translation" code. + +* Ben Parnell - Windows debugging tools + +* Parasyte & bbitmaster - Enhanced Windows debugging tools + +* blip & nitsuja - Rerecording support + +FCEUX >= 2.0 Contributors +------------------------- +* SP - document thyself (sf:rheiny) - Enhanced Windows debugging tools + +* zeromus - mgambrell at gmail dot com (sf:zeromus) - Core architecture refactoring and merging - Windows driver maintenance + +* adelikat - document thyself (sf:adelikat) - UI cleanup, project management, Win32 features & maintenance, TAS tools, documentation + +* CaH4e3 - CaH4e3 at mail dot ru (sf: cah4e3) - Mappers + +* Luke Gustafson - (sf:???) - Windows TAS and movie recording enhancements + +* qfox - (sf:qfox) - lua scripting fucntions, luabot, basicbot (no longer implemented), various lua scripts + +* _mz - document thyself (mauzus) - Windows driver maintenance and cleanup + +* UncombedCoconut - UncombedCoconut at gmail dot com (sf:jeblanchard) - Build system and cross-compilation support - Driver maintenance and refactoring + +* DWEdit - Debugger additions + +* AnS - ansstuff at yandex dot ru (sf:ansstuff) - Win32 features & maintenance, TAS Editor, debugging tools, documentation + +FCEUX (>=2.0) Linux/SDL Developers +---------------------------------- +_These guys concentrated on keeping fceux the premiere linux/portable nes emu._ + +* Lukas Sabota - ltsmooth42 at gmail dot com (sf:punkrockguy318) - Head FceuX-SDL developer - GTK GUI, complete overhaul of SDL port, build scripts; maintainence; docs + +* Shinydoofy - sf:shinydoofy - SDL maintenence + +* Soules - gimmedonutnow at gmail dot com (sf:gimmedonutnow) - Linux SDL driver maintenance + +* radsaq - radsaq at gmail dot com (sf:radsaq) - Build system, testing, and random cleanups + +* Bryan Cain - sf:plombo - Patch to embed SDL in the GTK+ GUI, miscellaneous other SDL and GTK+ contributions + +Included components: +-------------------- +* Mitsutaka Okazaki - YM2413 emulator. + +* Andrea Mazzoleni - Scale2x/Scale3x scalers + +* Gilles Vollant - unzip.c PKZIP fileio diff --git a/branches/fceux-2.2.2/COPYING b/branches/fceux-2.2.2/COPYING new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/branches/fceux-2.2.2/COPYING @@ -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/branches/fceux-2.2.2/INSTALL b/branches/fceux-2.2.2/INSTALL new file mode 100644 index 00000000..f1f2a562 --- /dev/null +++ b/branches/fceux-2.2.2/INSTALL @@ -0,0 +1,7 @@ +To compile and install FCEUX for SDL, follow the instructions in the README-SDL.md file. + +Users of Microsoft Visual Studio can use the solution files within the vc directory. +These solution files will compile FCEUX and some included libraries for full functionality. + +CMake has been depreciated in favor of scons. However, if you wish to use it you can find the old cmake build files in the attic. + diff --git a/branches/fceux-2.2.2/NewPPUtests.txt b/branches/fceux-2.2.2/NewPPUtests.txt new file mode 100644 index 00000000..6c74c119 --- /dev/null +++ b/branches/fceux-2.2.2/NewPPUtests.txt @@ -0,0 +1,69 @@ +NewPPU tests + +Bad +Nightshade (U) - flickering + +Good +3-D Battles of World Runner, The (U) +8 Eyes +10 Yard fight +Advanced Dungeons and Dragons - Pool of Radiance +Adventures of Bayou Billy +Adventures of Lolo 1 +Adventures of Lolo 2 +Advenutres of Lolo 3 +Akira +Akumajou secial - Boku Dracula-kun +Archon +Astyanax +Barbie +Bart vs the Space Mutants +Baseball +Batman - Return of the Joker +Battletoads +Battletoads & Double Dragon +Bee 52 +Bible Adventures +Castlevania +Castlevania II: Simon's Quest +Castlevania III: Dracula's Curse +Championship Pool +Chessmaster +Circus Charlie +Contra (U) +Contra (J) +Dragon Warrior +Dragon Warrior III +Dragon Warrior IV +Double Dragon +Double Dragon 2 +Double Dragon 3 +Donky Kong Classics +Doki Doki panic +Dragon's Lair - [FIXED] Black screen for level 1 (music plays) +Duck Tales +Duck Tales +Earthworm Jim 2 +Excitebike +Eggerland +Final Fantasy +Friday the 13th +Gauntlet +Gauntlet II +Legend of Zelda +Metroid +Mike Tyson's Punch-out!!/Punch-out!! +Power Blade +RBI Baseball +Rygar +Super C +Super Mario Bros 2 JPN +Super Mario Bros 2 USA +Super Mario Bros 3 +Tecmobowl +Tecmo NBA Basketball (U) +Tecmo Super Bowl (U) [!] - [FIXED] Intro screen messed up, menus out of whack, Team selection screen bad, pre game screen, field is messed up. +TMNT +Transformers +Zanac +Zelda II: The Adventure of Link diff --git a/branches/fceux-2.2.2/README-SDL b/branches/fceux-2.2.2/README-SDL new file mode 100644 index 00000000..92dbac5b --- /dev/null +++ b/branches/fceux-2.2.2/README-SDL @@ -0,0 +1,116 @@ +FCEUX SDL 2.2.1 SDL README +========================== +By Lukas Sabota (sf: punkrockguy318) + +http://www.fceux.com + +Last Modified: March 10, 2013 + +Table of Contents +----------------- + +1. Requirements +2. Installation +3. Compile-time options +4. GUI +5. LUA Scripting +5. FAQ +6. Contact + +1 - Requirements +---------------- +* libsdl1.2 - It is strongly recommended that you upgrade to the latest + version of sdl (1.2.15 at the time of writing). +* scons - Required to build fceux. +* libgtk2.0 (optional) - version >= 2.24 recommended +* libgtk3.0 (optional) - this compiles as of fceux 2.2.0 +* liblua5.1 (optional) +* minizip (optional) - you may chose to use the version of minizip on your system by enabling SYSTEM_MINIZIP in the SConstruct +* c++ compiler -- you may use g++ from gcc or clang++ from llvm. + +2 - Installation +---------------- +Fceux can be compiled and built using the scons build system. To compile, run: + + scons + +After a sucessful compilation, the fceux binary will be generated to +./src/fceux . You can install fceux to your system with the following command: + + scons install + +You can optionally define a prefix: + + scons --prefix=/usr/local install + +You can choose to install the lua scripts (located in output/luaScripts) to a directory of your choosing: + + cp -R output/luaScripts /usr/local/some/directory/that/i/will/find/later + +If you would like to clean the temporary scons files to perform a 'make clean' like function, you can do the following: + + scons -c && rm -rf .scon* + +3 - Compile-time options +------------------------ +You can enable and disable certain features of fceux at build time. +To edit these options, edit the "BoolOptions" following the "opts.AddVariables" method +at the head of the "SConstruct" file in this source directory. The +default options will be fine for most users, but power users may want to +tweak some of these options. + +4 - GUI +------- +You can enable the GTK GUI by setting GTK to 1 in the SConstruct build file. +GfceuX is deprecatiated in favor of the new GTK GUI. You can disable the GTK GUI at +run-time by passing the --nogui option, or disable it at build-time by setting +GTK to 0 in the SConstruct file. If you prefer GTK3 to GTK2, you can set the +GTK3 BoolVariable to 1 in the SConstruct. + +5 - LUA Scripting +----------------- +FCEUX provides a LUA 5.1 engine that allows for in-game scripting capabilities. LUA can be enabled or disabled at build time by adjusting the "LUA" BoolVariable in the SConstruct file. + +A collection of LUA scripts are provided with the source distribuition in the output directory: + + $source_directory/output/luaScripts + +You should be able to run most of the scripts in this directory out of the box. However, some of the the lua scripts require functionality from the "auxlib.lua" library. This file can be copied from "./bin/auxlib.lua" or "./src/auxlib.lua". You will need to place this file in the LUA library search path if a script bombs out looking for auxlib.lua. If the script bombs out, the console output will let you know what the search path are (/usr/local/lib/lua/5.1/ on my particular system). You can simply copy the auxlib to a preferred location to utilize the functions in the auxiliary lua library. + +In addition, some of the lua scripts require functionality from the "iup" GUI library. You can obtain binaries and source for "iup" upstream (http://www.tecgraf.puc-rio.br/iup/), but I would recommend obtaining packages from your Linux distribution if you are able, as it can be difficult to compile or get the binaries working correctly on a given system. + +You will need to add the location that the libiup*.so files to the LUA_CPATH. This can be done with the following command (please note that the location where iup is installed with vary based on how you installed iup): + + export LUA_CPATH="/path/to/iup/lib/lib?51.so;" + +For example, if libiuplua51.so is located in '/usr/lib', you can run the following command before executing fceux to place the library in the search path: + + export LUA_CPATH="/usr/lib/lib?51.so;" + +Finally, if any scripts complaints about "attempt to index global 'iup' (a nil value)", this means that "iup" needs to be explicitly loaded into the script. You can add the following line to the head of script to manually load "iup": + + require("iuplua") + +The latest version of iup (3.5 at the time of writing) is recomended. + +6 - FAQ +------- + +* Q. Im having issues with my sound! +* A. First of all, for the best sound quality be sure you are using SDL 1.2.14 or later. Versions 1.2.13 and earlier are known to have problems with fceux! Next, try different SDL audio drivers to see if this makes any difference. You can do this by using this command before running fceux: + + export SDL_AUDIODRIVER=driver + +where driver is either: 'pulse' for pulseaudio;' alsa' for ALSA; 'dsp' for OSS; 'esd' for ESD; see SDL documentation for details (http://www.libsdl.org/docs/html/sdlenvvars.html) + +There are sound options that you can tweak at runtime through command line switches: + +* -soundq x internal sound quality hack value (0 off) +* -soundrate x sound rate (sane values: 28000 48000 +* -soundbuffersize x (in ms) sane values (30, 50, 100, 120) + +Running fceux through esddsp is known to fix some audio issues with pulseaudio on some older Ubuntu versions. + +7 - Contact +----------- +If you have an issue with fceux, report it in the sourceforge bug tracker (see fceux.com). If you would like to contact the author of this readme personally, e-mail LTsmooth42 gmail com. You can also check us out at #fceu on irc.freenode.net. diff --git a/branches/fceux-2.2.2/SConstruct b/branches/fceux-2.2.2/SConstruct new file mode 100644 index 00000000..cb513e33 --- /dev/null +++ b/branches/fceux-2.2.2/SConstruct @@ -0,0 +1,241 @@ +# +# SConstruct - build script for the SDL port of fceux +# +# You can adjust the BoolVariables below to include/exclude features +# at compile-time. You may also use arguments to specify the parameters. +# ie: scons RELEASE=1 GTK3=1 +# +# Use "scons" to compile and "scons install" to install. +# + +import os +import sys +import platform + +opts = Variables(None, ARGUMENTS) +opts.AddVariables( + BoolVariable('DEBUG', 'Build with debugging symbols', 1), + BoolVariable('RELEASE', 'Set to 1 to build for release', 0), + BoolVariable('FRAMESKIP', 'Enable frameskipping', 1), + BoolVariable('OPENGL', 'Enable OpenGL support', 1), + BoolVariable('LUA', 'Enable Lua support', 1), + BoolVariable('GTK', 'Enable GTK2 GUI (SDL only)', 1), + BoolVariable('GTK3', 'Enable GTK3 GUI (SDL only)', 0), + BoolVariable('NEWPPU', 'Enable new PPU core', 1), + BoolVariable('CREATE_AVI', 'Enable avi creation support (SDL only)', 1), + BoolVariable('LOGO', 'Enable a logoscreen when creating avis (SDL only)', 1), + BoolVariable('SYSTEM_LUA','Use system lua instead of static lua provided with fceux', 1), + BoolVariable('SYSTEM_MINIZIP', 'Use system minizip instead of static minizip provided with fceux', 0), + BoolVariable('LSB_FIRST', 'Least signficant byte first (non-PPC)', 1), + BoolVariable('CLANG', 'Compile with llvm-clang instead of gcc', 0), + BoolVariable('SDL2', 'Compile using SDL2 instead of SDL 1.2 (experimental/non-functional)', 0) +) +AddOption('--prefix', dest='prefix', type='string', nargs=1, action='store', metavar='DIR', help='installation prefix') + +prefix = GetOption('prefix') +env = Environment(options = opts) + +if env['RELEASE']: + env.Append(CPPDEFINES=["PUBLIC_RELEASE"]) + env['DEBUG'] = 0 + +# LSB_FIRST must be off for PPC to compile +if platform.system == "ppc": + env['LSB_FIRST'] = 0 + +# Default compiler flags: +env.Append(CCFLAGS = ['-Wall', '-Wno-write-strings', '-Wno-sign-compare']) + +if os.environ.has_key('PLATFORM'): + env.Replace(PLATFORM = os.environ['PLATFORM']) +if os.environ.has_key('CC'): + env.Replace(CC = os.environ['CC']) +if os.environ.has_key('CXX'): + env.Replace(CXX = os.environ['CXX']) +if os.environ.has_key('WINDRES'): + env.Replace(WINDRES = os.environ['WINDRES']) +if os.environ.has_key('CFLAGS'): + env.Append(CCFLAGS = os.environ['CFLAGS'].split()) +if os.environ.has_key('CXXFLAGS'): + env.Append(CXXFLAGS = os.environ['CXXFLAGS'].split()) +if os.environ.has_key('CPPFLAGS'): + env.Append(CPPFLAGS = os.environ['CPPFLAGS'].split()) +if os.environ.has_key('LDFLAGS'): + env.Append(LINKFLAGS = os.environ['LDFLAGS'].split()) + +print "platform: ", env['PLATFORM'] + +# compile with clang +if env['CLANG']: + env.Replace(CC='clang') + env.Replace(CXX='clang++') + +# special flags for cygwin +# we have to do this here so that the function and lib checks will go through mingw +if env['PLATFORM'] == 'cygwin': + env.Append(CCFLAGS = " -mno-cygwin") + env.Append(LINKFLAGS = " -mno-cygwin") + env['LIBS'] = ['wsock32']; + +if env['PLATFORM'] == 'win32': + env.Append(CPPPATH = [".", "drivers/win/", "drivers/common/", "drivers/", "drivers/win/zlib", "drivers/win/directx", "drivers/win/lua/include"]) + env.Append(CPPDEFINES = ["PSS_STYLE=2", "WIN32", "_USE_SHARED_MEMORY_", "NETWORK", "FCEUDEF_DEBUGGER", "NOMINMAX", "NEED_MINGW_HACKS", "_WIN32_IE=0x0600"]) + env.Append(LIBS = ["rpcrt4", "comctl32", "vfw32", "winmm", "ws2_32", "comdlg32", "ole32", "gdi32", "htmlhelp"]) +else: + conf = Configure(env) + # If libdw is available, compile in backward-cpp support + if conf.CheckLib('dw'): + conf.env.Append(CCFLAGS = "-DBACKWARD_HAS_DW=1") + conf.env.Append(LINKFLAGS = "-ldw") + if conf.CheckFunc('asprintf'): + conf.env.Append(CCFLAGS = "-DHAVE_ASPRINTF") + if env['SYSTEM_MINIZIP']: + assert conf.CheckLibWithHeader('minizip', 'minizip/unzip.h', 'C', 'unzOpen;', 1), "please install: libminizip" + assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib" + env.Append(CPPDEFINES=["_SYSTEM_MINIZIP"]) + else: + assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib" + if env['SDL2']: + if not conf.CheckLib('SDL2'): + print 'Did not find libSDL2 or SDL2.lib, exiting!' + Exit(1) + env.Append(CPPDEFINES=["_SDL2"]) + env.ParseConfig('pkg-config sdl2 --cflags --libs') + else: + if not conf.CheckLib('SDL'): + print 'Did not find libSDL or SDL.lib, exiting!' + Exit(1) + env.ParseConfig('sdl-config --cflags --libs') + if env['GTK']: + if not conf.CheckLib('gtk-x11-2.0'): + print 'Could not find libgtk-2.0, exiting!' + Exit(1) + # Add compiler and linker flags from pkg-config + config_string = 'pkg-config --cflags --libs gtk+-2.0' + if env['PLATFORM'] == 'darwin': + config_string = 'PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ ' + config_string + env.ParseConfig(config_string) + env.Append(CPPDEFINES=["_GTK2"]) + env.Append(CCFLAGS = ["-D_GTK"]) + if env['GTK3']: + # Add compiler and linker flags from pkg-config + config_string = 'pkg-config --cflags --libs gtk+-3.0' + if env['PLATFORM'] == 'darwin': + config_string = 'PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ ' + config_string + env.ParseConfig(config_string) + env.Append(CPPDEFINES=["_GTK3"]) + env.Append(CCFLAGS = ["-D_GTK"]) + + ### Lua platform defines + ### Applies to all files even though only lua needs it, but should be ok + if env['LUA']: + env.Append(CPPDEFINES=["_S9XLUA_H"]) + if env['PLATFORM'] == 'darwin': + # Define LUA_USE_MACOSX otherwise we can't bind external libs from lua + env.Append(CCFLAGS = ["-DLUA_USE_MACOSX"]) + if env['PLATFORM'] == 'posix': + # If we're POSIX, we use LUA_USE_LINUX since that combines usual lua posix defines with dlfcn calls for dynamic library loading. + # Should work on any *nix + env.Append(CCFLAGS = ["-DLUA_USE_LINUX"]) + lua_available = False + if conf.CheckLib('lua5.1'): + env.Append(LINKFLAGS = ["-ldl", "-llua5.1"]) + env.Append(CCFLAGS = ["-I/usr/include/lua5.1"]) + lua_available = True + elif conf.CheckLib('lua'): + env.Append(LINKFLAGS = ["-ldl", "-llua"]) + env.Append(CCFLAGS = ["-I/usr/include/lua"]) + lua_available = True + if lua_available == False: + print 'Could not find liblua, exiting!' + Exit(1) + # "--as-needed" no longer available on OSX (probably BSD as well? TODO: test) + if env['PLATFORM'] != 'darwin': + env.Append(LINKFLAGS=['-Wl,--as-needed']) + + ### Search for gd if we're not in Windows + if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI'] and env['LOGO']: + gd = conf.CheckLib('gd', autoadd=1) + if gd == 0: + env['LOGO'] = 0 + print 'Did not find libgd, you won\'t be able to create a logo screen for your avis.' + + if env['OPENGL'] and conf.CheckLibWithHeader('GL', 'GL/gl.h', 'c', autoadd=1): + conf.env.Append(CCFLAGS = "-DOPENGL") + conf.env.Append(CPPDEFINES = ['PSS_STYLE=1']) + + env = conf.Finish() + +if sys.byteorder == 'little' or env['PLATFORM'] == 'win32': + env.Append(CPPDEFINES = ['LSB_FIRST']) + +if env['FRAMESKIP']: + env.Append(CPPDEFINES = ['FRAMESKIP']) + +print "base CPPDEFINES:",env['CPPDEFINES'] +print "base CCFLAGS:",env['CCFLAGS'] + +if env['DEBUG']: + env.Append(CPPDEFINES=["_DEBUG"], CCFLAGS = ['-g', '-O0']) +else: + env.Append(CCFLAGS = ['-O2']) + +if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI']: + env.Append(CPPDEFINES=["CREATE_AVI"]) +else: + env['CREATE_AVI']=0; + +Export('env') +fceux = SConscript('src/SConscript') +env.Program(target="fceux-net-server", source=["fceux-server/server.cpp", "fceux-server/md5.cpp", "fceux-server/throttle.cpp"]) + +# Installation rules +if prefix == None: + prefix = "/usr/local" + +exe_suffix = '' +if env['PLATFORM'] == 'win32': + exe_suffix = '.exe' + +fceux_src = 'src/fceux' + exe_suffix +fceux_dst = 'bin/fceux' + exe_suffix + +fceux_net_server_src = 'fceux-net-server' + exe_suffix +fceux_net_server_dst = 'bin/fceux-net-server' + exe_suffix + +auxlib_src = 'src/auxlib.lua' +auxlib_dst = 'bin/auxlib.lua' +auxlib_inst_dst = prefix + '/share/fceux/auxlib.lua' + +fceux_h_src = 'output/fceux.chm' +fceux_h_dst = 'bin/fceux.chm' + +env.Command(fceux_h_dst, fceux_h_src, [Copy(fceux_h_dst, fceux_h_src)]) +env.Command(fceux_dst, fceux_src, [Copy(fceux_dst, fceux_src)]) +env.Command(fceux_net_server_dst, fceux_net_server_src, [Copy(fceux_net_server_dst, fceux_net_server_src)]) +env.Command(auxlib_dst, auxlib_src, [Copy(auxlib_dst, auxlib_src)]) + +man_src = 'documentation/fceux.6' +man_net_src = 'documentation/fceux-net-server.6' +man_dst = prefix + '/share/man/man6/fceux.6' +man_net_dst = prefix + '/share/man/man6/fceux-net-server.6' + +share_src = 'output/' +share_dst = prefix + '/share/fceux/' + +image_src = 'fceux.png' +image_dst = prefix + '/share/pixmaps' + +desktop_src = 'fceux.desktop' +desktop_dst = prefix + '/share/applications/' + +env.Install(prefix + "/bin/", fceux) +env.Install(prefix + "/bin/", "fceux-net-server") +# TODO: Where to put auxlib on "scons install?" +env.Alias('install', env.Command(auxlib_inst_dst, auxlib_src, [Copy(auxlib_inst_dst, auxlib_src)])) +env.Alias('install', env.Command(share_dst, share_src, [Copy(share_dst, share_src)])) +env.Alias('install', env.Command(man_dst, man_src, [Copy(man_dst, man_src)])) +env.Alias('install', env.Command(man_net_dst, man_net_src, [Copy(man_net_dst, man_net_src)])) +env.Alias('install', env.Command(image_dst, image_src, [Copy(image_dst, image_src)])) +env.Alias('install', env.Command(desktop_dst, desktop_src, [Copy(desktop_dst, desktop_src)])) +env.Alias('install', (prefix + "/bin/")) diff --git a/branches/fceux-2.2.2/STYLE-GUIDELINES-SDL b/branches/fceux-2.2.2/STYLE-GUIDELINES-SDL new file mode 100644 index 00000000..0ea3db6f --- /dev/null +++ b/branches/fceux-2.2.2/STYLE-GUIDELINES-SDL @@ -0,0 +1,14 @@ +FceuX-SDL Style Guidelines +========================= +Background +---------- +While having style guidelines specific to a directory in a sourcetree is slightly riddiculous, fceuX has a unique elaborate history of the code. I (prg318) have ressurected the majority of the SDL port code and tried to keep some aspects of the style consistant (although not many aspects were that consistent to begin with due to the amount of different people who have contributed to this codebase). Much of the SDL code is compliant to these guidelines so please use this guidelines when going forth and making contributions in src/drivers/sdl. + +Tabs +---- +Hard tabs only! Please! src/drivers/sdl/* entirely consists of hard tabbed code. Please continue to use this convention. Consult the documentation of your text editor documentation for instructions on how to this with your editor. + +Return Statements +----------------- +Please use the "return 0;" style return statements instead of the "return(0);" style return statements. + diff --git a/branches/fceux-2.2.2/TODO-SDL b/branches/fceux-2.2.2/TODO-SDL new file mode 100644 index 00000000..95defb4b --- /dev/null +++ b/branches/fceux-2.2.2/TODO-SDL @@ -0,0 +1,47 @@ +Priorities +========== + * SDL 2.0 RC is released - SDL2.0 compatibility is a goal + * Backwards-cpp still has an issue with clang++; look into this + * Users are reporting crashing issues with hotkey dialog (probably because its a mess!). A huge chunk of the hotkey code should be rewritten (GUI and hotkey structs - or lack there-of) + * GTK File menu quit element has "CTRL-Q" accelerator. This causes confusion with there being another SDL Hotkey for quit. This should be addressed. + * Quit was mapped to '0' to prevent users from accidently quitting. Perhaps a default quit combo could be used. + +Features +======== + * SDL.Vsync + * lets wait on this -- theres no simple way to use the OS default in SDL unless we just dont touch it, which might be the best thing to do here. + +GTK +=== + * Better on-the-fly video resizing with window resize / video config + * Smarter video config (disable widgets that are not used when openGL is enabled) + * Options to investigate: + * bpp + * scanlines + * GUI Cheat editor + +SDL 2.0 +======= + * segfaults when opening a second game + * segfaults on fullscreen entry + * has not been tested in a while + +BUGS +==== + * F1 from terminal-less gui fceux process hangs fceux (since input is required from console in cheat editor) + +OS X +==== + * Single window mode does not work (the XWINDOWID hack does not work in Apples X11 server, so this may never get fixed). + * It is possible to use GTK to build native OS X menus: http://developer.gnome.org/gtk3/3.4/GtkApplication.html . It would be awesome to do this and hide the main GTK window if the top bar is available + * Zapper input is taken from GTK window instead of X11 window (a workaround could be implemented to resolve with with some #ifdef APPLE etc) + * Not an "official" target, but testing should be done before release on OS X + * DMG Static binary download for Intel OS X + * Include needful libaries + * Adjust scons to produce static binary/libraries with an option + * http://www.scons.org/wiki/StaticallyLink + +DOCS +==== + * Be sure to include details about new scons features for package maintainers so that the manpage, luascripts, and auxlib will be included in future packages + * Docs REALLY need a cleanup/rewrite diff --git a/branches/fceux-2.2.2/attic/.gitignore b/branches/fceux-2.2.2/attic/.gitignore new file mode 100644 index 00000000..674deb69 --- /dev/null +++ b/branches/fceux-2.2.2/attic/.gitignore @@ -0,0 +1,17 @@ +# A simulation of Subversion default ignores, generated by reposurgeon. +*.o +*.lo +*.la +*.al +*.libs +*.so +*.so.[0-9]* +*.a +*.pyc +*.pyo +*.rej +*~ +*.#* +.*.swp +.DS_store +# Simulated Subversion default ignores end here diff --git a/branches/fceux-2.2.2/attic/BUGS b/branches/fceux-2.2.2/attic/BUGS new file mode 100644 index 00000000..cd938cf8 --- /dev/null +++ b/branches/fceux-2.2.2/attic/BUGS @@ -0,0 +1,12 @@ +BUILD SYSTEM BUGS: +Date - Person - Details + + + + +CLOSED * July 30, 2006 - Luke - I'm getting build errors about: +sh: illegal option -l +Started happening when the build system was edited to be more robust. +I'll check it out when i get the chance, or soules if you could take a look at it, that would be grand. +- July 31, 2006 - Luke - checked out to latest revision, all is well. + diff --git a/branches/fceux-2.2.2/attic/ChangeLog.older b/branches/fceux-2.2.2/attic/ChangeLog.older new file mode 100644 index 00000000..027420b3 --- /dev/null +++ b/branches/fceux-2.2.2/attic/ChangeLog.older @@ -0,0 +1,2183 @@ +0.98.12: + + Win32: Fixed the behavior of the sound logging function. + + Fixed a bug that was causing 2xscale/3xscale to be broken + when clipping the leftmost and rightmost 8 columns. + + Added an iNES header correction entry for JustBreed. + + Modified the MMC5 "ELROM" board emulation to not emulate WRAM. + + Corrected various pieces of code that were causing compiler warnings. + + Win32: Scaling settings(x, y, stretch to fill screen) are now respected while + using a special scaler in full screen mode, though if x or y scale is + less than what is needed for a particular scaler, it will be + adjusted. + + Win32: The window will be reblitted when it becomes invalidated while + a game is loaded(such as when you're resizing the window). + + When the PPU is in a "dead" state after starting up, the graphics + buffer is now cleared. Previously, particularly in the Windows port, when + a game was closed, and a new game was loaded, the last image from + the previous game would be displayed for a short time. + + Win32: Blit skipping will now occur when sound is disabled and FCE Ultra is + running behind the desired frame rate. + + Win32: Blit-skipping behavior can now be configured to some extent in the "Timing" configuration + window. + + Win32: Added a "Recent Directories" submenu to the "File" menu. + + Removed some debugging code that shouldn't have been enabled in 0.98.11. + +0.98.11: + + Win32: Special scalers are now also supported in windowed mode. For Scale2x/Scale3x, + the fastest "desktop" bit depth is 16bpp. For hq2x/hq3x, it is 32bpp. + + The shared video blitting code(drivers/common/vidblit.c) can now blit using Scale2x + and Scale3x to any target bit depth(8bpp, 16bpp, 24bpp, and 32bpp) instead of just + 8bpp, as it was before. + HQ2x and HQ3x can now blit to 16bpp, 24bpp(untested), and 32bpp. The 16bpp and + 24bpp targets are done doing post-processing conversion, after HQ2x/HQ3x, which + really does hurt speed. + + Changed a few names in the credits section of the documentation to their + aliases. Names you didn't get to pick to have are so troublesome. :b + I also made various fixes/updates to the documentation. + + Updated the FAQ with some information regard video mode bit depths and speed. + + SDL: Disabled the fast-forward-key speed-limiting code. I thought I had + done this before... + + Fixed a major bug in the movie recording code, and added some code to automatically detect + and fix playback of broken movies from earlier versions. + + Did a little swapping thing with mapper 90 and 209. I moved back Mortal Kombat 3 + to mapper 90, and moved Shin Samurai Spirits 2 to mapper 209. Sorry for any confusion. + Mapper 90 should be considered as having the fancy nametable select mode disabled, with + mapper 209 having it enabled. + + Added support for mapper 160, which turns out to be the same hardware as mapper + 90. Joy. + + Improved mapper 90 emulation. This mapper really needs low-level + emulation for IRQs to work right, though. :/ + + Win32: Fixed the "hide left/right 8 video columns" feature. + + Since FCE Ultra is ending(or has already exceeded? :b) its actively-updated life, + I've gone ahead and added per-game hacks for "Kick Master" and the PAL version + of "Star Wars". See the documentation for more details. + + Minor optimizations to the high-quality sound emulation code. The FIR filter + code is the bottleneck, though, so these changes won't have much of an effect + on overall speed. + + Altered MMC3 IRQ emulation(and the hooks in ppu.c for it). + + Fixed a rather major typo in the VRC7-emulation code. + +0.98.10: + + Reimplemented network play. It now requires a standalone network play server, which + will be released as a later time. For fun, "starmen.net" is running this server, + which is publicly accessible. + I also made various code fixes/improvements to allow for network play, particularly + with the command handling code. + + Reworked much of the VS Unisystem emulation code, partially based on information from + MAME. The following games are now supported: + + Battle City + Castlevania + Clu Clu Land + Dr. Mario + Duck Hunt + Excitebike + Excitebike (Japanese) + Freedom Force + Goonies, The + Gradius + Gumshoe + Hogan's Alley + Ice Climber + Ladies Golf + Mach Rider + Mach Rider (Japanese) + Mighty Bomb Jack (Japanese) + Ninja Jajamaru Kun (Japanese) + Pinball + Pinball (Japanese) + Platoon + RBI Baseball + Slalom + Soccer + Star Luster + Stroke and Match Golf + Stroke and Match Golf - Ladies + Stroke and Match Golf (Japanese) + Super Mario Bros. + Super Sky Kid + Super Xevious + Tetris + TKO Boxing + Top Gun + + Win32-native: Fixed a bug in the debugger's breakpoint list that appeared when + one tried to delete a breakpoint(the control accidentally had auto-sort enabled, + causing a discrepancy between what was displayed and what was contained in internal + data structures). + + The current disk image XOR original disk image is now stored in save states. This + should greatly increase compressability(important for network play), and make + it a little more legal to distribute such save states now. + + Modified the save state format to allow for more precise and larger version numbers. + + Various minor code changes. + + Fixed initialization of the FCEUGameInfo structure, which previously led + to problems with sound output on the SexyAL-using ports(Linux). + + Apparently I added support for mapper 255 a while back. Documentation updated. + + Added iNES header correction information for Armored Scrum Object and Alpha Mission. + + Merged banksw.h into ines.c, fixed some of its prototypes in ines.h. + +0.98.9: + + Win32-native: Fixed the speed throttling used when sound is disabled. In previous + 0.98.x Win32-native releases, emulation was running at 1/2 the speed it should + have been when sound was disabled. + + Win32-native: Moved settings in the "Miscellaneous" configuration window + to where they should have been in the first place, and added "GUI" and "Timing" + configuration windows to accommodate some. + + Win32-native: Fixed the handling of the "Scroll Lock" key used to disable and + enable Family BASIC Keyboard input. + + Updated documentation to handle some slight differences in the Win32-native + port("Win32-native" is what the Win32 port using native APIs, as opposed to something + like GTK+ and SDL, will be referred to in documentation now). I also made + some other minor wording adjustments to the documentation. + + Added an iNES header correction for Dragonball. + +0.98.8: + + Fixed a typo in sound.c that caused only part of the sound registers + to be saved in save states. + + Win32: Switched over to the DirectDraw7 interface, from DirectDraw4's. + The surface Flip() method will now block, which results in somewhat + smoother animation/scrolling, especially when combined with the + auto blit-skip implemented in 0.98.6 when sound is enabled. + + Win32: Undid a change made in the last release that limited the + speed of fast-forwarding when using the tilde key. I really do + need to implement some sort of unified timing/blit skip system... + + Win32: Added an option, disabled by default, to ask for confirmation + before exiting FCE Ultra. + + Win32: Added an option, enabled by default, to disable the system + screen saver while a game is loaded. + + Win32: Added a new video synchronization mode, a "lazy" wait for + vblank/vertical retrace. It calls Sleep(0) in its wait loop. This + still uses all available cpu cycles, but it is much more friendly + to other processes than the old-style wait for vblank. + + Win32: Added support for joystick POV hats. + +0.98.7: + + Fixed a bug in the debugger's disassembler when disassembling + opcode 0xBC. + + Fixed the behavior of the right mouse button with zapper emulation, to + correspond with what it is documented as doing. + + Win32: Added proper support for maximizing the window. + + Win32: Rewrote most of the input and input configuration code. + + Win32: Changed the configurable aspect ratio to something sensical, the current + display's pixel aspect ratio, default of 1:1(square pixels). + + Win32: Made the default full-screen video mode the custom video mode. I should have + done this a long time ago to make custom video mode configuration more straighforward + for users... + + Added some JACK audio code to be used by the SDL build. I'll test it and complete + it later. + +0.98.6: Made several code modifications to work with older versions of gcc. + + Fixed more header file network play #ifdef-age. + + Fixed a typo in cart.h. + + Fixed some funky code in FCEU_memmove(). + + Fixed some source code causing compiler warnings. + + Fixed SexyAL's format conversion code to not rely on deprecated casting semantics. + + Readded the native Win32 code, and made many improvements. The major thing + that needs to be done now with it is to rewrite the input handling code and input + configuration code. + +0.98.5: + Added LL to the 64-bit integer constants in ines.c + + Fixed OpenGL support under Mac OS X. + + Added the ability to hide background and/or sprites with the F4 key. + +0.98.4: + Moved NETWORK #ifdef's to netplay.c to simplify things. + + Fixed gzip file loading code(I think). I'm still a bit unsure about the semantics + of dup() and close(), though. + + Corrected FDS code to try loading the FDS image before loading the BIOS. + + Readded "native" SDL sound code, used for Mac OS X(and maybe BeOS). + +0.98.3: + Removed the wxWindows GUI code. GTK+ 2 code will take its place, + once it is ready. + + Added reset and power commands to the movie format. More commands(such as insert + disk, eject disk, flip dip switch, etc.) will be added simultaneously as work + on network play continues. + + Modified SexyAL OSS code to not adjust the number of fragments to a power of 2. + It works fine on my card, allowing finer-grained buffer size control, + but I'm not sure it will work with all chips. + + Fixed parsing of the "-specialfs" command-line argument. + + Added the hq3x scaler. + + Updated to the latest Scale2x code. I also added the Scale3x scaler. + + Changed the keyboard assignments for toggling full screen to "Alt" + "Enter". + + FCEUI_SaveState() and FCEUI_LoadState() changed. Porters should read + driver.h. + + Miscellaneous changes to accommodate new network play plan. It's not close + to being finished. + + Altered RTI emulation. In Paris Dakar Rally's NMI handler, it does "CLI ; RTI". + Previously, FCE Ultra would generate an interrupt right after RTI occured, due to the + presumed latency that RTI had with the I flag. I changed it so there is no latency, so + no interrupt will occur in this case(interrupts kill this game). The interrupt source + is the "frame IRQ", which it never disables, if anyone cares. + This change does break the "Stars SE" demo, though. Hmm. + + "FCEUGameInfo" is now a pointer, rather than just a statically-allocated structure. + This may cause some null-dereferencing-related crashes, but it should help keep + code a little cleaner(maybe?). + + Played around with the FDS FM code some more. It's still not right. Bah. + + Hacked in support for entering Datach/Barcode World barcodes without a GUI, using the + F8 key and the numeric keys. + + Added code to save/load movies. Movie support will only record/play back the + states of the four emulated gamepads. + + Modified the sound code to use timestamp/timestampbase differently. In addition, + timestampbase is now saved in save states("timestamp" doesn't need to be saved, since + it's reset to 0 at the end of each emulated frame). + +0.98.2: + Fixed a few problems with the SDL command-line build code + for Win32. Also, SDL 1.2.7 seems to have a bug that breaks FCE Ultra's + full-screen/windowed switching capabilities(at least under Win32). + Stupid everything. + + Minor SexyAL changes. + + Updated documentation. + +0.98.1: + + Increased the volume of the FME07 sound channels. + + Fixed a bug in the SexyAL endian conversion code. + + Made the SexyAL chunk conversion loop work. + + Replaced the old OPL2 emulator with a modified version of + Mitsutaka Okazaki's YM2413 emulator for the VRC7 sound emulation. + + Decreased the pitch of the FME 07 expansion sound channels by one octave. + + Decreased volume of output of $5011 in MMC5 emulation code. + + +0.98.0: Some changes I made aren't listed below. Ah well. The magnitude + of the changes was too great... + + + Default sound volume is 100(%), which makes a lot more sense than 75%, but not much. + It's multiplied by 3/4 internally now. + + Added support for the Datach barcode reader(GUI interface only). The emulation code + was adapted from the VirtuaNES source code. + + Reassigned the Datach games to mapper 157, from 16, with CRC32 checks. + + Increased the maximum number of screen snapshots in the snapshots directory + to 99999(from 999). + + Reassigned the following games to mapper 210, using CRC32 checks: + Chibi Maruko Chan + Dream Master + Family Circuit '91 + Famista '92 + Famista '93 + Famista '94 + Heisei Tensai Bakabon + Top Striker + Wagyan Land 2 + Wagyan Land 3 + If you use a hack/translation of one or more of these games, you will of course + need to manually change the mapper number in the header for it to work properly in + FCE Ultra. Family Circuit '91 still may not fit in with the rest of these games, + but it's definitely not a "stock" mapper 19 setup. + + Fixed an OpenGL palette bug when using scanlines(previously, I think it was + setting the palette of the scanlines overlay texture instead of the actual image + texture in some instances). The bug showed up on games that make use of the color + deemphasis bits. + + Rewrote a lot of the PPU background rendering code to be more accurate(and + obfuscated!). This eliminates the X-offset hack I made earlier. + + Removed some of the NSF visualization code, and altered the look of the NSF + display slightly. The NSF waveform visualization code will now take into + account the current volume setting. + + Changed the default key bindings for the standard emulated gamepad + to something more compatible with window managers. I may change it back, but probably + not, since it is easily configurable now. + + Updated the MMC5, VRC6, and FME07 low-quality sound emulation code + with the compatible parts of the high-quality sound emulation code for those chips. + + Adjusted timing of horizontal scroll update(near the beginning of hblank. I made + it occur sooner). I also added a hack to allow X-offset(fine X scroll) changes mid + scanline, however, it is extremely ugly, and may not work correctly for everything + (doing it correctly would probably kill speed). + I mainly did it to fix games like F-1 Race and Mach Rider, and other racing + games that are extremely sensitive to horizontal scrolling timing. + + Some FDS IRQ emulation changes to fix some screen corruption problems + in "Kaettekita Mario Bros". + + Removed zlib(the code, not support). + I also removed support for compiling without zlib(it's small, simple, provides + very useful functions, and may provide critical features for fceu in the future). + + *undone, breaks debugger, FIXME.* Replaced some inline functions with macros in x6502.c. + + Increased the speed of Namco 106 sound emulation in HQ sound mode. + + Many many sound emulation changes and adjustments based on blargg's tests. + The default sound volume is about 150% what it was before, because the sound range + has changed(now -soundvol 100 is like -soundvol 200 on older builds), and the + default "soundvol" setting is 75. 100 clips on some Namco games, and 200 clips + on many games, so I'll probably have the configurable volume range as [0:125]. + What exactly is "%" supposed to mean in this case.... 100% of what?! + + When using low-quality sound emulation mode, total emulation speed is about 10% + less than previous builds. The change in speed for high-quality sound emulation + mode is significantly less. + + Added beginnings of SexyAL to source code tree, removed SDL sound support, and + old OSS code. + + Copied over some autoconf/automake stuff from phamicom. It stills needs a bit + of work... + + Fixed DMC IRQ emulation. Fixes many CodeMasters games. Finally. ^_^ + + Restructured a lot of files, changed the interface between driver and + emulator code slightly. + + * Insert stuff here * + +November 28, 2003 - Snapshot + + Removed the DOS, Linux SVGAlib, and Win32 targets. *GASP* + Win32 support will return(eventually), using SDL + wxWindows. + SDL can use svgalib or GGI anyway, so it shouldn't be a huge loss. + DOS support will only return if someone ports SDL to DOS. ^_^ + It would be nice if SDL could accept modelines. Maybe in SDL 2.0... + + Merged fce.c and svga.c into fceu.c, and fce.h and svga.h into fceu.h. + + Reassigned "Mortal Kombat 3 - Special 56 Peoples" to mapper 209. + + Added emulation of the "Oeka Kids" tablet. + + Added emulation of the Family Trainer. + + Added emulation of the "Ultimate Quiz King" buzzers. + + Added emulation of the Mahjong controller. + + Added emulation of HyperShot controllers. + + Fixed loading of NSFs with load addresses below $8000. + + Cleaned and simplified some of the NES APU code. + + Altered mapper 65 emulation. Fixes Kaiketsu Yanchamaru 3. Does it break anything? + + Wrote a small FAQ file. + + Fixed displaying of garbage and other unpleasantness on the first scanline. I need + to clean up that code, though. + + Fixed color deemphasis emulation when all bits are set. For some + reason, I had commented out the code. Bleh. + + NSF player now writes $C0 to $4017 if the FDS is being used(the FDS + BIOS writes $C0 to $4017). $40 for all other NSFs. + + Added support for iNES mapper 58(nnnesterj). + + Added support for iNES mapper 208. + + Reassigned "Fudou Myouou Den" to mapper 207(CRC32 checks). + + Reassigned "Karnov" to mapper 206(CRC32 checks). + + Fixed the mapper 95 code, which was horribly broken. + + Differentiated between mappers 33 and 48. Added CRC checks to assign + some games to mapper 48. "Flintstones 2" and "Don Doko Don 2" are + the games that need to be assigned to 48. Are there others? + + Replaced usage of TriggerIRQ to X6502_IRQBegin/X6502_IRQEnd combos in + various mapper emulation files. 67, 33/48, 40, 73, 42, 65, 6, 182 + Removed function TriggerIRQ() from x6502.c + + Fixed the sound volume of the VRC7 emulation in high-quality sound mode. + Decreased(slightly) the volume of VRC7 emulation in both high-quality sound modes. + + Decreased the volume of the MMC5 expansion sound channels. + + Decreased the volume of the FME-7/mapper 69 expansion sound channels. + + Added FCEU_gmalloc(), which will call exit() if memory allocation fails, + otherwise it is guaranteed to return a memory block. + This will be used in the mapper code mainly. It should only + be used for small memory chunks. The reasoning is that if 64 some like KB of + RAM or less can't be allocated, for example, it'd probably be best to + exit the emulator ASAP. It also helps to simplify code logic, and + help (me) with modularization. + The behavior of this may change in the future. I still need to think about it. + I should probably save the configuration file regularly(or much better, + use the registry) on the Windows port, though. + + Cleaned up the save-state saving/loading code a bit, and added + support for linked save state structures for better modularity and + less code duplication. + + Merged the iNES and UNIF MMC1, MMC3, and MMC5 code more completely. + I may need to sanify CHR RAM and WRAM allocation for pedanticness, + though. Also worked on Tengen RAMBO-1 emulation, and mapper 90 emulation. + ***THIS MAKES SAVE STATES FOR GAMES THAT USE THESE EXPANSION CHIPS INCOMPATIBLE + WITH PREVIOUS VERSIONS*** + I plan on doing the same thing with other mappers/boards in the future, though. + Always on the quest for 1.0... + +November 12, 2003 - 0.97.5 Release + + Windows: Added limited support for arguments that change configuration + to be passed to FCE Ultra. Example: fceu -pal 1 c:\streetgangs.nes + It may be useful in frontends. + + Fixed filename generation for automatic IPS patching when a file + with no extension is loaded. Before this change, FCEU would + look for "game..ips" with a file named "game". + + Converted and updated the cheat guide in(to) HTML. + + Added support for iNES mappers 202,203,231 from info from cah4e3. + Fixed support for mappers 60, 200. + + Fixed various major bugs in the breakpoint deletion code. + + UN*X: Added support for OSS(/dev/dsp) devices that don't support mono + sound. + + Increased PPU startup idle time to 2 frames. Fixes that + unlicensed "Earthworm Jim 3" game. Does it break anything? + +November 9, 2003 - 0.97.4 Release + + Fixed another obscure PPU emulation screen corruption bug. + + Added support for Game Genie cheats in the cheat interface. + + Windows: Reworked the cheat interface, merging the cheat search + and cheat list windows into one. + + Windows: Greatly improved the CPU debugger. + The code still needs a lot of cleaning, though. + + Readjusted VRC6 IRQ emulation timing. + + Added support for the UNIF MMC3 board TEROM. The maximum PRG/CHR sizes + may not be correct in this implementation, though. + +November 8, 2003 - 0.97.3 Release + + Added a control to set the highest quality sound mode in Windows. + This change requires that any users who previously set + "high quality sound" to set it again. + + Fixed the volume of high-quality sound mode again. The changes + I made earlier didn't affect all the filter coefficients. + +November 8, 2003 - 0.97.2 Release + + Made a minor optimization to writes to palette memory. + + Altered VRC6 IRQ emulation timing slightly. + + Fixed a weirdo PPU emulation bug that could cause garbage on the right + side of the screen in certain situations. Thanks to FrenziedPanda for + bugging me enough to make me look into the problem and fix it. + I should be on the lookout to see if the fix breaks anything, though. + + Fixed the volume of high-quality sound mode(-soundq 1). It was + at 1/4 the volume it should have been. I compensated by increasing + the precision of the filter coefficients, which increased the sound + quality of that mode slightly without hurting performance. + +November 7, 2003 - 0.97.1 Release + + Fixed mapper 105 emulation. I had begun merging it into the + rest of the MMC1 code for 0.97, but I hadn't finished it. + + Changed things like RdMem(_PC++); to RdMem(_PC); _PC++; + Darn evil global variables. I need to fix them. Screw speed. + + Expanded checks for the global variable "fceuindbg"(used in debug + mode to prevent reads in the debugger from altering any registers). + +November 6, 2003 - 0.97 Release + * Note: I still had much more I had wanted to get done for 0.97, + but I lost even more interest. The Windows port still doesn't + have a way to enable the "highest" sound emulation mode, nor the + low pass filter code, not to mention that the lowpass filter code + isn't complete(I would need to design a high-order FIR filter from an IIR + filter to work properly-have the correct rolloff, among other + things-at finite playback rates). + + Fixed a bug in the IPS patcher. The recorded size wasn't being updated + after a successful realloc() was made, which could lead to corrupted patch + data from some patches. + + Added support for mappers 200, 201 from submitted code. + + Rewrote mapper 15 support to make more sense(well, depending + on your point of view...). + + Fixed 256KB CHR select support for mapper 115. + + Added support for mapper 12 from code from cah4e3. + +October 16, 2003 - Snapshot + + Fixed support for mapper 245(for nonencrypted/non-smynes-screwed up + ROM images only. Fixes "Yong Zhe Dou E Long [...] Dragon Quest 7". + + Added support for mappers 60, 62, 230, 244 from submitted code. + + Modified mapper 90 emulation to allow game-select on reset + for "Final Fight 3". + + Modified mapper 45 emulation to allow "Super 8-in-1" to work. + + Added a low-pass filter, and an option to enable it(CLI ports). + + 0x00 is now written to $4011 in the NSF player code instead of 0x40. + Fixed some other similar sound register init problems that I had fixed + in Festalon but forgot to fix in FCEU. Grrr. + + Removed some unnecessary 64-bit integer usage from FIR sound filtering + code. + + Added a new sound quality mode. Higher than high, it's highest(in + FCE Ultra, for now). Still need to fix the interface to allow + enabling it in the Windows port. + + Added some code for lower-level MMC3 IRQ emulation. It isn't completed + , and will not work properly as-is. I'm still playing around with + it occasionally. + + Fixed the sprite overflow flag(I think I fixed it), that was broken in an earlier + pre-0.97 release. + + Fixed support for iNES mapper 193. + + Command line arguments "-pal" and "-gg" now take extra arguments(1/0) + and are remembered in the configuration file. + +September 27, 2003 - Snapshot + + Added support for iNES mapper 50. + + Modified the UNIF board initialization code. Hopefully, this + new interface will eventually be used with the iNES code. + + Miscellaneous code cleanups. + + /dev/dsp is now set to 8(previously 9) buffers of 128 samples in length + in the SDL code. + + Tried to make the save state code more expandable and modular. + + Moved a lot of the PPU code into ppu.c. + + Added more extensive debugging code to the 6502 emulator, to allow + for memory read/write hooks(including zero page addressing modes). + + Readadjusted DMC timings when PAL emulation is enabled. It looks + like it was correct before I had made the August 2 change. Thanks + to Bananmos for the information. I think. :/ + + Added support for iNES mapper 193 from information from virtuanes. + I think my dump of it is "bad", though. PRG and CHR pages look + like they are in the wrong order(logical vs physical? Who's to say + what's physical?). + +September 1, 2003 - Snapshot + + Fixed some minor initialization issues with iNES mappers 7 and 34. + + Added support for UNIF board NES-GNROM. + + Removed support for save states created with versions of FCE Ultra + less than 0.56. + + Replaced SDL sound buffering code with a lock-free FIFO implementation + written by David Olofson, with a few modifications by myself. + + Fixed a VRC7 NSF bug(it showed up under the reworked driver/file + loading order in the cli code). + + The board in "Rolling Thunder" has "RAMBO 1" on it, not "RAMBO-1". + +August 9, 2003 - Snapshot + + Removed the old plain text documentation and replaced it with + a new document in HTML. It is not completed yet, though. + + Rewrote the SDL-native audio code to be less wacky and more + thread-safe(hopefully). I'm still waiting for a new SDL audio + API... + + Altered the MMC5 IRQ timing. Fixes minor graphical glitches + in Castlevania 3. Does it break anything? + + Removed some debugging code that got into the last snapshot. + +August 5, 2003 - Snapshot + + Added some code in the IPS patcher to allow for expanding the size of files. + + Fixed a double free() bug with a mapper 51 game(in ines.c). + + Added support for "Alien Syndrome" (US release) as iNES mapper 158. + It looks like a derivative of the normal RAMBO-1 board(or is that + the name of the chip?), similar to TKSROM/TLSROM(mapper 118). + + Improved the "native" SDL sound code. It will now call SDL_Delay(), + among other nice things. The code could probably be improved more, + though. + + Added support for decimal components in xscale/yscale in the SDL + port. Set the default xscale for windowed mode to 2.40(to get a + more correct aspect ratio, assuming the display is currently at + a 4:3 aspect ratio). + + Modified args.c to handle floating-point numbers. + +August 2, 2003 - Snapshot. + + Disabled texture wrapping with OpenGL(there were problems at the edges + of the screen with linear interpolation). Bah. Now the edges + are too bright... + + Improved the accuracy of the DMC timing when PAL emulation is enabled. + I still don't think it's totally correct, though. + + Changed the default settings for the SDL code. Full screen + is now 640x480x8bpp by default, xscale and yscale are 2 for both full + screen and windowed, opengl support is enabled, linear interpolation + for OpenGL is enabled, and X-axis stretching is + enabled(in full screen). + + "Scanlines" were enabled in 8bpp to 8bpp blits in + drivers/common/vidblit.c when they shouldn't have been. Fixed. + + Fixed OpenGL code under big-endian platforms. + +August 1, 2003 - Snapshot. + + Various code clean-ups. + + Played around with adding a GTK+ GUI to the SDL code. + + Rewrote part of the hq sound rectangle wave code. + + Replaced the high-quality sound inline assembly filter code with + slightly faster C code. + + Hacked around with GP32 support. I don't know if the GP32 would + be fast enough, though. + + Skipped frames will now have D5 of $2002 set at the beginning + of the frame. Fixes "Bee 52". I must see if it breaks anything. + + Added OpenGL support to the SDL code. + + Removed the PPU drawing inline assembly code, replacing it with a faster + algorithm written in C. + + "Disabling" the 8-sprite limitation will no longer cause + "Bee 52" to break. However, the "Solstice" wizard will still + have the weird thing growing out of his face in the introduction, + since it depends on no more sprites to be rendered. + + Added entry for that Black Bass game for header corrections in + ines.c + + Strip color burst bit(D0 of $2001) is only "emulated" if bg or + sprite rendering are turned on, at the end of the scanline. + Doing it with pixel/tile granularity would require modifying + the sprite graphics data copying routine, which I don't + feel like doing. Fixes that crazy Sayoonara demo by Chris Covell. + I also modified the NES RAM initialization code. + + Adjusted VRC7 IRQ emulation for better Lagrange Point goodness. + + Added support for iNES mapper 91. (VirtuaNES) + +0.96: + Improved RAMBO-1(mapper 64) emulation. "Skull and Crossbones" is + now playable. + +0.95: + + timestamp and timestampbase are no longer saved/loaded to/from + save states. They were causing too many problems I didn't + want to fix, and I never intended them to be saved in save states + when I wrote the code that uses them. + I think the reason they were being saved was that I wanted to make it + possible to add movie support and network play save state loading + (distributing the save state over the network). So if someone in + the future wants to add these features, the issues(primarily with + zapper emulation and sound emulation) with saving the time stamp will + need to be resolved. + + Fixed some crashing bugs when save states are loaded when + high-quality sound emulation is enabled. It is like patching + holes in a swiss-cheese boat. All the holes may be patched, but + it looks ugly. At least it tastes good... + TODO: Look into saving more data in the save states, especially + data that is based off of "timestamp" and "timestampbase". Also + look into validating this data. Right now, corrupt save state data + might cause memory corruption in FCE Ultra. + + Fixed some bugs in the NSF player. + + Cleaned up more code. + + Reduced the usage of TriggerIRQ(). + + Split the palette code into a new file, palette.c, from svga.c + + Low-G-Man(NTSC and PAL versions) are now recognized by CRC32 value, + and WRAM will be disabled if they are loaded. A warning/status message + will also be printed regarding this issue. + + Decreased the volume of the DMC/PCM channel in low-quality sound + emulation. + + Low-quality sound emulation now uses 32-bit integers for much + better speed. + + FCEUI_CRC32() wasn't returning anything. D'oh. Fixed. + + Added somewhat crude support for games that switch background CHR data + mid-scanline (this is needed in games such as Mother, Pirates!, + Business Wars, and Marble Madness). + + Altered NMI, IRQ, and BRK emulation again. Fixes some games, + like Bases Loaded 2 and Dynamite Bowling, and maybe some others. + I had to increase the size of the IRQlow variable for delayed + NMI execution... I also had to add a delay between PPU reset + and the PPU actually doing anything, to fix "Knight Rider". + + Fixed a mapper 90 save state bug. + + /dev/dsp code now searches for /dev/dsp before /dev/dspX (where X is + a non-negative integer). + + SDL joystick axes configuration is now done from the joystick. + + Tweaked various Konami mappers' IRQ counter emulation. + + Added custom SDL throttle code that gives up time slices instead of + using 100% cpu. + + Fixed an issue with sprite priorities on MSB-first platforms. + + Modified powerpad.c to avoid a symbol conflict when compiling on the + Power PC architecture. + +0.94r3: + sound.c: + Fixed a divide-by-zero bug that occurred when a virtual + reset(like by pressing F10) occurred when sound emulation was + disabled. + +0.94r2: + drivers/common/vidblit.c: + Fixed code for 32bpp blur effect. + + drivers/cli/sdl-video.c: + Added error message for unsupported bit depths. + + mappers/simple.c, ines.c: + Used this bug fix pseudo-release as an excuse to add + support for mapper 107. Information taken from virtuanes. + +0.94(fixed release) +--- + Fixed call to InitUNIXDSPSound in svgalib.c + + Added man pages. + +0.94 +--- + Added support for rapid fire A/B buttons on physical joysticks + in SDL/svgalib/DOS code. + + Implemented "high-quality" Namco 106 emulation(used for hq sound mode). + In this case, "high-quality" means sounding more like it should, + not necessarily cleaner. I'm not certain that it's totally correct, + but it's in the right direction. + + RAM cheats should no longer affect Game Genie emulation. I still + need to completely verify this. There may be some sort of race + condition. + + Removed various minor speed hacks in the name of style and + correctness(and to make maintaining FCE Ultra easier for those + people who are not me). :) + + Removed NSF cpu hacks, as I changed code to make them unnecessary. + + Fixed another FDS IRQ emulation bug. "Famicom Grand Prix II" works + now. + + Fixed a memory leak and a heap corruption bug in "file.c". + + Added support for on-the-fly IPS patching. + Place the IPS file in the same directory as the file to load, + and name it filename.ips. + + Examples: Boat.nes - Boat.nes.ips + Boat.zip - Boat.zip.ips + Boat.nes.gz - Boat.nes.gz.ips + Boat - Boat.ips + + Some operating systems and environments will hide file extensions. + Keep this in mind if you are having trouble. + + Patching is supported for all supported formats(iNES, FDS, UNIF, and + NSF), but it will probably only be useful for the iNES format. It + can be used with the FDS format, but be warned that it will permanently + patch your disk image, as the disk image is written back to disk + when the game is unloaded(unless the disk image is in a zip file, in + which case it isn't written back to disk). UNIF files can't be + patched well with the IPS format because they are chunk-based with no + fixed offsets. Support for a UNIF patching format may be added + in the future(probably by someone else.). + + Added more games to the list in ines.c for having battery-backed + WRAM, for header corrections. + + Copied over the 96KHz filter coefficients from Festalon that I forgot + to do in 0.92. Oops. + + +0.93 +--- + + Reduced the volume of the FDS sound channel. + + Fixed a bug in the FDS IRQ emulation code that caused "Lutter" to not work. + + Fixed a bug in unif.c that would cause a crash if a unif file were + loaded without a board name being specified(as could happen + with a corrupted nsf). + + Fixed a bug in general.c relating to relative filenames(running + fce ultra like "./fceu ../big.nes" would work, but "./fceu ../big" + would not work- it crashed). + + + +0.92r2 +--- + Fixed dpcm irq bug that broke Cobra Triangle. + +.92 +--- + + Removed NSF player background, and added some special effects goodies. + + Changed the NSF player to use the emulated gamepad as input instead + of having special NSF-player-only keys. + + Added support for mapper 249(using nonencrypted games), thanks to SARO + for info. SMYNES sucks. + + Updated video blitting library-thing(vidblit.c) with more special + effects, and removed 24bpp support. + + SDL cleanupification. + + Added support for mapper 61. + + nnnesterj: Added support for mapper 57. + + Fixed mapper number for "Golden Game 150 in 1". Changed it to 235 + from 43. + + DDraw back buffer surfaces are now created in system memory if the + hardware blitter can't do stretching. + + Restructured file wrapping code. + + Added new cheat search methods. + + Fixed a major cheat unloading memory bug(and memory leak). + + Emulated that funky nonlinear DAC effect for hi-quality sound. + + More fixes/cleanups to FDS emulation code. + + Tweaked PPU timing a bit. + + Improved network play. + + Holding the enter key down will no longer do fun stuff to the nsf + player. + + Improved NSF player. It should support streaming pcm nsfs now... + + Changed FDS keyboard keys around a bit. F6 is the disk select key, + and F8 is the disk insert/eject key. + F8 to insert VS Unisystem coin, F6 to view/toggle dip switches. + Hopefully people won't complain after blindly hitting the save state + buttons. :) + + Many fixes and improvements to the Windows port. No more cpu-consuming + wait loops(specifically, sound). Added a message window. + + FDS sound emulation improvements. + + FDS disks are now auto-inserted on power on(or was it loading a new + game...). + + Changed the default last rendered scanline to 231. + + ines header corrections are now printed as status messages, not errors. + + Rearranged input updating code. + + Fixed a sprite transfer bug. Fixes PAL version of Rainbow Islands. + + Debugger hooks added. + + Small optimizations in Refreshline and FetchSpriteData to hopefully + offset the slight slowdown in the cpu core. + + MapperHBIRQHook is now called differently(depending on hi/low bg/spr + addresses). + + Added support for unif board UNL-8237. + + Added support for mapper 144(death race). + + Added partial support for mapper 74. + + Fixed a cpu emulation bug in GETIYWR. It would sometimes set "target" + to 0x10000, which was a BAD THING(overflow; now it wraps). + + Tried to add support for mapper 241. Needs special keyboard emulation. + I think. + + Internal RAM is now initialized to something other than 0. Fixes + Minna no Taabou no Nakayoshi Dai Sakusen. + + Reassigned "The Money Game" to mapper 155. It doesn't seem to + respect the WRAM enable/disable bits. Silly game. And + Tatakae!! Rahmen Man. + + Added support for mapper 115(still needs 256KB CHR select), 241, 114,88. + + Attempted to add support for mappers 91, 187. + + Modified frame IRQ to not break so many damn games. + + Fixed sprite hit detection loop. + + Improved support for mappers 80, 90,117,154, 189. + nnnester and virtuanes. + + Reassigned "Devil Man" to mapper 154. + + Removed bogus Trojan header fix in ines.c. + + + +.81-post: +---- + Fixed/Worked around(?) compilation problems on gcc 3.2.x. + +.81: +---- + + More SDL goodies. + + Renamed "Makefile.olinuxsdl" to "Makefile.unixsdl" + + More SDL fixes and cleanups. + + BeOS port is now compiled with the "-no-fpic" flag, which allows + me to use my inline assembly. The executable work fine as far as + I can tell. + + Added "Makefile.beos". gcc doesn't like my inline assembly + used in RefreshLine(),so this port will likely be slightly slower than + other x86 ports. + + Added a check to make sure SIGBUS is not equal to SIGSEGV in + drivers/cli/main.c. Needed for compiling under BeOS. + + Renamed the "PI" member of the X6502 structure due to conflicts with + a defined symbol with some math header files. + + Merged fcelineasm.h into fceline.h + + Fixed(possibly) a possible problem in fcelineasm.h with input register + clobbering. + + More SDL changes. + + Added speed throttling code to the CLI code, and added a command + line switch "-nothrottle". + + Lots of restructuring/rewriting/merging of the MMC3 code. + + Updated DOS code to use the generic CLI wrapper. + + Reads from $4090 and $4092 now return the current envelope setting + in FDS sound emulation. I'm not sure if this is correct... Affects + "Ai Senshi Nicole" and "Bio Miracle Bokutte Upa". + + Added native SDL sound support to the SDL code. the "olinuxsdl" + now uses this code by default instead of the unixdsp sound code. + + Modified MMC3 IRQ counter emulation. I'll need to watch out to see + if it breaks any games. Fixes: MegaMan 3, Gun Nac, Klax(Japanese). + + Changed a few memory reads in x6502.c to use RdRAM instead of RdMem, + resulting in a slight speed increase. + + Cleaned up mapper 250 emulation code. + + Added support for iNES mapper 51(thanks to Kevin Horton for the + information). + + Merged some iNES mappers corresponding to bootleg multicarts + based on MMC3s with mbshare/mmc3.c. + + Added support for iNES mapper 52(thanks to Kevin Horton for the + information). + + Made some hacks to the MMC3 emulation code so that I can add support + for pirate MMC3 multicarts more easily. I should clean it up later. + Moved mapper 44 emulation code to mbshare/mmc3.c. + + Saving screen snapshots will no longer corrupt the frame buffer + for one frame(unless memory couldn't be allocated). + + Fixed screen snapshot saving(it was sort of broken due to the + changes made to the driver<->emulator interface code; status + messages were being saved to the image). FCEUI_SaveSnapshot() + no longer returns a value(the request to save a screen snapshot is + serviced before status information would be written in the next frame). + + nosprites is now set to 0 before RefreshSprite() returns, to prevent + problems if a game turns off the bg and sprites when FetchSpriteData() + for the next scanline is called but then turns on sprites when + the actual scanline is drawn. + + PPU_hook() is now called more often if PPU_hook is non-null. + Made changes to mappers 118, 95, 9, and 10 to compensate. + No games seem to be broken, and I added support for mapper 96 + (though the games aren't very playable because the special controller + isn't emulated). + + Romance of the 3 Kingdoms is now recognized to use 16KB ex-WRAM. + + Added support for mapper 185...sort of. I think this is another + instance of incompatible hardware being lumped onto one mapper number. + Sigh. + + Added support for "Famicom Jump 2" as iNES mapper 153. + If a good(as far as I can tell) dump is loaded, FCE Ultra will + automatically fix the mapper number. + I also made some changes to the mapper 16 IRQ emulation code. + + BRK now sets the I flag. + + Reads from $4015 no longer reset DPCM IRQ. + + Changed emulation of RTI instruction slightly. + + X.IRQlow is now set to 0 in PowerNES(). + + The VS Unisystem bit in the iNES header is no longer looked at( + I was having too many problems with this bit being set when it + shouldn't have been). Now, VS Unisystem emulation is enabled + when a known VS Unisystem game is loaded. I also rewrote the VS + Unisystem detection function. + + iNES mapper 1 now supports pageable CHR RAM if no CHR ROM is present. + Fixes "Family School". + + Mapper 70 no longer has a mirroring control emulated, and I extended + the number of 8KB CHR pages supported to 16. + + Cleaned up iNES MMC5 save RAM loading/saving code and added + support for MMC1 games with 16KB of RAM(the second 8KB are saved), + via CRC32s(currently only Genghis Khan(USA) and Nobunaga's Ambition( + USA and Japan) are recognized). + + Added support for the MMC5 Koei game "Ishin no Arashi", in the iNES + format(I added an entry with its CRC32 value and the number of 8KB + WRAM banks it needs). + + Better iNES mapper 33/48 IRQ counter emulation. + + Added the game "Uchuusen - Cosmo Carrier" to this list. I'm + beginning to hate the iNES format more and more...or maybe + just Fanwen. :) + + Added the mapper 32 game "Major League" to the list of games + that usually need iNES header correction...but in this case, the + iNES header cannot specify that this game needs to have one-screen + mirroring. + + iNES header information is now printed before any header corrections + are made based on a database. + + Fixed a bug in mapper 32 emulation. "Ai Sensei no Oshiete" + works now. + + Tried to add support for iNES mappers 245 and 249. + + Fixed the MMC5 read handler to return the data last on the data + bus instead of 0xFF when a read was made to an unmapped address. + This seems to fix the lockup problems in "Bandit Kings of Ancient + China". + + Reversed "Modified the time at which the "y scroll" register is updated + during hblank." The changes broke Klax. + + Added an unsigned 64-bit base timestamp variable "timestampbase". + Adding this to the 32-bit variable "timestamp" will return + the number of cycles executed since emulation started(in the future + I'll probably change it to since reset or power toggle). + This allowed me to replace "lastn" hack in the MMC1 code with + something better. + + Changed my mind and undid the removal of support for old save states. + + Removed support for old save states and in general I won't + try to support save states made with previous versions. + + MMC1: Writes to $8000-$FFFF with D7 set will now cause + the first MMC1 register to be OR'ed with 0x0C. I'm not sure + if this is correct, but it doesn't seem to break anything + and it fixes Robocop 3. I'll see if anyone reports games + not working in .81 that worked in .80. + + Worked on a generic driver interface wrapper very similar + to the driver interface FCE Ultra used to use(I'm getting + tired of all of the duplicated driver code). Eventually, + the DOS, SVGAlib, and SDL ports will use this wrapper. + + Similar change to the argument parsing code. + + Changed configuration file saving-loading routines and the + configuration structure to allow for linking config structures + to each other). + + Small fix to the emulation of the MMC5 split screen mode. + + Made Linux SDL code compilable again. + + Changes to MMC5 EXRAM emulation(read/write). + + Fixes to the emulation of the MMC5's split screen mode, based on + observations while using CastleVania 3 and a Game Genie(on a real + NES). + + Fixed a bug in ines.c that caused any calls to AddExState() from + a mapper initialization function to be effectively "erased"(ResetExState() + was called after the mapper was initialized). Fixes the VRC7 sound + state saving/loading stuff. + + Finished adding support for the MMC5's split screen mode(this does + not mean that the support is complete, but at least the intro in + "Uchuu Keibitai SDF" works correctly now). + + Worked on adding support for the MMC5's split screen mode. Not + completed. + + Reverted to .80's FDS sound code. + + Modified the time at which the "y scroll" register is updated + during hblank. + + NSF playing code will now disable FDS sound output on song init + (fixes some problems with the Zelda no Densetsu NSF rip). + + Increased the emulated clock speed of the FDS sound emulation code + to give better quality output. + + Modified NMI to occur a few cycles later. Fixes BattleToads...but + it may have broken other games. Also modified the way NMI's are + handled in x6502.c. + + Modified ines.c to memset() GameMemBlock to 0 on virtual power toggle. + Also, trainers are now loaded into their own buffer instead of + directly into emulated WRAM and copied into emulated WRAM on + power toggle; I've been meaning to do this for quite some time. + + Changes to the way the zapper cursor is drawn on the screen. + + FCEUD_WriteSoundData(), FCEUD_BlitScreen(), and FCEUD_UpdateInput() + have been combined into one function: FCEUD_Update(). + + More fixes to the network play code, and a fix to the Windows network + play driver code that fixes(hopefully) a rather evil bug that caused + lockups when the remote stopped network play. + + Added code to set the battery-backed bit in RAM if a game needs it, + based on CRC32. + + Added more games to the list of games that commonly have bad iNES + headers, in ines.c + + Updated docs and usage.h for DOS and Linux regarding the new video + mode and the new refresh rates. + + Linux: Fixed a bug with video mode 6(a few upper scanlines were being + cut off). Increased the refresh rate of video mode 3 to 120hz. + + Increased the refresh rate of video mode 2 to 65 hz in the Linux port. + + Screen snapshots can now be taken while playing an NSF. + + Added a new sexy tweaked vga mode that I created to the Linux svgalib + port. It's 256x224 at a refresh rate of 103hz. Hopefully it won't + blow up anyone's monitor. ;) + DOS port will follow eventually. + + Modified Makefile.base to produce an executable named "fceu" instead + of "fce". + + The plans(cycle-accurate ppu emulation) for .90 were a bit ambitious, + and I still need to make other fixes before then. + + Fixed some minor(usually) bugs with setting 256x240 tweaked VGA mode + in DOS and Linux ports. + +.80: +---- + + Cleaned/fixed a few things in the mapper 19 emulation code. + Family Circuit '91 still doesn't work quite right... I wonder if + it's a bad dump. + + Added input override code to Windows port. + + Added code to fix iNES header information in RAM and suggest + changes to the user. + + Added support for iNES mapper 152(to be used with games set to + mapper 70, that use one-screen mirroring instead of h/v mirroring). + + Blits using the DirectX blitting function(method?) to the primary + surface are now done with the asynchronous flag set(if that + fails, a "normal" blit is tried). + + The DirectX blit buffer(secondary surface that FCE Ultra writes to + directly and then uses the DirectDraw blit function on to blit + to the primary buffer) is now created without specifying it + should be in system memory or video memory, except in the case + when no hardware blitting is available, and then DDraw is explicitly + told to create the surface in system memory. + + Added Family Keyboard support to the DOS port. + + Cleaned up the VRC7 sound emulation code. I need to find a way + to save the current sound state in a save state. + + Found out the real name of the "Space Shadow" gun; it's + called the "Hyper Shot". I'm still not sure who made it, though. + Possibly Bandai did. The interesting thing is that Konami + also made a Famicom accessory(dual square boxy things with two buttons + on each) with the same name(though there might not be a space in the + name). + + Only the upper two bits read from $4016/$4017 are undefined. + Bit5 is always 0, though. Fixed the bug in "input.c". + Silly kevtris' old documents. New kevtris' brain is always good. + + Family Keyboard support for the Windows port. + + Added support for the Family Basic Keyboard to the Linux port, other + ports todo. + Might want to add support for the tape recorder at some time. + Also mapped the "Scroll Lock" key to disable/enable command keys + so that the FBK is more useable. It doesn't disable CTRL C, + though... + + Changed a lot of inlined functions in x6502.c to macros so that + I could test out some optimization ideas. + + DOS code updates for game input override support. + + Small optimzation to opcode $4c, and relative jumps. + + Added some code to ines.c to set controller information in + FCEUGameInfo(returned by FCEUI_LoadGame()) based on crc32 values. + + Updated user documentation and usage.h for DOS and SVGAlib input + command-line changes. + + Added an option to disable the four-score(to Windows and Linux ports + so far). + + Updated Windows interface to support the new Famicom expansion + devices. + + (Re)Added support for the Famicom 4-player device. + + Improved Zapper emulation...sort of. It still needs a lot of work. :/ + + Added *partial* support for the "Space Shadow" gun. + + Added support for the Arkanoid controller(both NES and Famicom style). + + Added code to support the extension Famicom input devices. + + Added PAL scanline start/end drawing settings to Windows port. + + Added pause emulation key(F2) to Windows port. + + In the process of rewriting/fixing up input code stuff. + + Minor bug fix to Power Pad emulation code. + + VS Hogan's Alley and VS Duck Hunt automatically select the zapper + now(though it only works on the SVGAlib port). + + Undid some FDS sound code changes introduced in 0.76 that totally + screwed up sound. Oops. + + Added code to allow different settings for first/last scanline + drawn while in PAL emulation mode, to the Linux and DOS ports. + + Added convenience(it's not necessary, but it reduces redundant and + confusing code in the driver code) function + FCEUI_GetCurrentVidSystem(int *slstart, int *slend). + + Updated file "TODO". + + Changed #include to #include "zlib/unzip.h" + in file.c. + + NSF 6502 player now initialized the stack pointer on reset. + + Worked on de-emphasis emulation code quite a bit. + The deemphasized palette calculated at the end of the frame is now + based on what deemphasis bits were set for the longest during + the screen(sampling interval is a scanline) update loop. + Added a "static" deemphasized palette at $40-$7F in the palette table. + This corresponds to the colors when all of the deemphasis bits are set. + I did this to fix the PAL game "Noah's Ark", without breaking + anything else. The only downside is a slight speed loss(~2% on + my system when sound is disabled), but this is acceptable to me, + at least. + Maybe it's time to write hi/true-color ppu drawing code... + + + Fixed an out of bounds array access in svga.c in SetNESDeemph(). + The variable "lastd" in svga.c was being initialized to the wrong value. + Thanks to "Jarod CANAL" for pointing this out. + + Removed FCEUI_SetFirstRenderedLine or whatever it was called and + the function to set the last line. Replaced with: + void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); + + Changed SetVidSys(int w) to ResetVidSys() in fce.c. Reenabled + PAL/NTSC emulation overrides based on game loaded(really only useful + for NSFs and UNIFs now). + + UNIF loading code now recognizes the chunk "CTRL" and tries + to use it. Only the svgalib code supports overriding of input + settings based on game loaded, now, though... + The user is still going to have to configure powerpad settings + on his/her own. + + Fixed return values of FCEU_fseek() and fixed a problem in unif.c + related to it. + + Changed mechanism for how FCE Ultra tells the driver + code what type of system is being emulated. A structure of + type "FCEUGI" is returned from FCEUI_LoadGame(). + + Fixed a major mapper 64 emulation bug introduced in 0.76. + + Modified BlitVidHi() in drivers/win/video.c to speed it up. + + Added support for loading the iNES-format Game Genie ROM image. + + Removed ggrom.h and added code to load the Game Genie ROM + image from a file. + + Added Windows netplay.c. (new: the user exiting the emulator + while stuck in a blocking recv() or send() loop now works.) + + Fixed a vram address register bug in fce.c that I created when I got + rid of the pair/dpair data types. + + Added new mappers/92.c + + Removed mappers/92.c until I can contact LULU or rewrite it. + + drivers/win changes. Removed netplay.c until I can rewrite it. + + Got rid of pair/dpair data types. + + Got rid of silly "TempArray" thing. + + Began adding GPL headers to files. FCE Ultra is going to be in + a state of legal limbo for the next few days... + + Replaced crc32.c and crc32.h, and added some #ifdef's and #defines + to use the crc32 code in zlib instead if zlib is linked with + FCE Ultra. + + More fixes to sb.c. + + Cleaned up drawing.h and ggrom.h(even though ggrom.h will *probably* + be removed before the next release). + + Redid frameskip code. + + Rewrote necessary pieces of sb.c and sb.h and fixed quite a few + bugs. I still need to test it on various other sound cards, though. + + Rewrote(more like "recreated in my own image") DOS keyboard driver. + Removed unused "keyscan.h" from drivers/svgalib + + Rewrote part of(the parts that Marat wrote - the connection and + closing parts) the Linux TCP/IP network play code. I guess it works, + but I haven't tested it very much. In any case, it's still dangerous + to use network play in FCE Ultra with SVGAlib, since recv() or send() + might block and since the keyboard is in raw mode, you have a problem. + Maybe a future SVGAlib will fix the general problem of lockups if + keyboard_update() isn't called, though it is only partly SVGAlib's + problem... + + Fixed FCEU_fseek() when used with a compressed file in the PKZIP + format that has been loaded. Fixes a UNIF loading problem. + Also added a check to the return value of FCEU_fseek() in unif.c. + + Replaced Marat's 6502 emulation core with my own. + It should be fully functional, but as always, I don't know if + I implemented the undocumented instructions correctly. + Several things are correct in this new core that were not in + Marat's(D flag is no longer cleared by interrupts, for example). + + Altered mapper 16 irq counter emulation slightly. + + Fixed the behavior of the SXA, SYA, and XAS opcodes based on the + documentation I have. I'm not sure what happens when page crossing + occurs with those instructions on a real NES, though. + Also CHANGED(not fixed) emulation of opcode $8B("XAA"). + + Changed some of the M* functions(absolute indexed and maybe some others) + to perform dummy reads. + + Changed some of the macros in m6502.c to inlined functions so + that I can modify and examine them more easily. + +.77: +---- + + Fixed a silly network play bug(in the global network play code) + that caused excessive lag. + + Added a "niceness" setting to the sound configuration dialog. + Removed obsolete information from the dialog. + + Fixed speed throttling code in Windows port when PAL emulation is + disabled/enabled and a new game hasn't been loaded yet. + + Commented out a printf() to debug stuff in fds.c(oops). + + Applied PK's joystick patch to the osdl code. It allows the user + to map axes and it fixes a joystick button mapping configuration saving + bug. + + Added two command line options new to Linux port to DOS port. + Just need to test them... + + Added some stuff to unif.c to allow for boards that can support + CHR RAM instead of CHR ROM(darn Sachen boards...). Fixes UNIF + version of "Q-Boy". + + Added command line option "-snapname" to Linux port. I'll add it + to the Windows port as well, but probably not to the DOS port. + + Added clip option to Linux port. + + Fixed sound logging(in Windows port) so that multiple recording + sessions now work. + + Added an option to clip the leftmost and rightmost 8 columns + of graphics in the Windows port. + + Added a submenu that lists recently opened files, in the Windows + port. + +.76: +---- + + Updated porting.txt. + + Added speed throttling code to Windows port that's used when sound is + disabled(and an option in the "Miscellaneous" + configuration window to disable it). + + Added cheat interface to DOS build. + + A few tweaks to the text cheat interface code in the cheat listing code. + Added a command to quickly toggle the status of the cheat(though a + cheat can still be disabled/enabled by (M)odifying the cheat). + + Support for UNIF UNL-TC-U01-1.5M board added. Same credits as below. + + Rewrote mapper 228 code just for the heck of it(actually, I couldn't + figure out why some(about two) of the games in the Action 52 cart + weren't working in .75(and .76). I traced it back to .71, where an apparent bug in + the undocumented 6502 opcode emulation allowed it to work, which + was later fixed for the .72 release(opcode 0x7C)). I'm thinking + that the dump is bad... + + Added a few crc32 checks to ines.c to check for and report when + a known(by me) bad(hacked or bad dump) game is loaded. + + Added support for the following UNIF boards. Thanks to Quietust + and Kevin Horton for the information. Some problems still exist + with a few games that use these boards, though... + + UNL-Sachen-8259B + UNL-Sachen-8259A + UNL-Sachen-74LS374N + UNL-SA-016-1M + UNL-SA-72007 + UNL-SA-72008 + UNL-SA-0036 + UNL-SA-0037 + + Fixes to some stuff in cart.c(for example, calling setprg32() when + only 16kb of prg data is present now works). + + Added support for iNES mapper 189. + + Tried to add support for the UNIF board "UNL-H2288". Failed. + + Updated "cheat.txt" to fix a few typos and added an example of finding + and adding a cheat using the Linux port's text interface. The actual + section on the Linux cheat interface still needs to be written, however. + + Changed network play code in the Windows port and fixed a bug. + Fixed a similar bug in the Linux netplay code....sort of. + + A few cosmetic changes to the dialogs in the Windows port. + + Fixed sound initialization on the Windows port(it was being initialized + when FCE Ultra started even if it was disabled by the user. Oops.). + + Joystick button configuration code in Windows port changed slightly + to be more useable. + + Changed reference to video mode 5 in the linux port to "1 per 4". + It may not be very meaningful, but it is certainly better + than "TV Emulation". I'll change the Windows port reference later. + + Documented video mode 7(320x240) for the Linux port. Also added + a check for the FBDev driver in order to use this mode instead + of a tweaked vga mode if that driver is being used. + + Added/Fixed cheat interface for Linux port. It's still not perfect, + though. The code is ugly... + + Callback function for FCEUI_ListCheats() now receives + status information(enabled/disabled). + + Callback functions for cheat functions now must return 0 to + stop listing cheats or 1 to continue. + + Fixed a problem(the cheat code was reading in cheats + for address $0000 from cheat files if any blank lines were present). + + SDL port zlib changes(linked dynamically to zlib now). + + More changes to envelope decay + looping on code. No longer + depends on value @ $4017. It now sounds correct based on some + tests I did with SMB3 and a GG, but Goonies 2 doesn't sound right( + based on a sound file sent to me by another person). + + Added support for iNES mapper 140. Thanks to Quietust for the + information. + + I need to figure out how to deal with the problem of so many + bad NSFs that most people consider good... + + Changed envelope decays a bit. Their behavior now depends on bit + 7 of $4017. I don't know if this is right... + + Addition of debug.c for some debugging stuff. + + Updated zlib to 1.1.4. + + Modified code in various files to allow UNIF games to override + current selected video system emulation(NTSC or PAL). Need to + make sure this really works. + + Changed sound.c to prevent desynchronization during network play. + This might slow down sound emulation slightly, especially when + sound emulation is disabled. I really don't care... + + Updating network play code. More info later... + + Moved the sound/video/etc output code in EmLoop() to the top of the + for(;;) loop so that initialization prior to calling EmLoop() will + be the same as initialization done during a call to a FCEUD_* function. + + A few very small changes to sound emulation in fds.c. + + Changed unlink() to remove() in cheat.c and removed the including + of the header file unistd.h. + + Split up the cc=... statement in RefreshLine() to make it easier + to read and not ambiguous(to Borland's C compiler). + + Changed a lot of the function declarations in cheat.c. I'll need + to verify that cheat searching still works ok and that cheats still work + ok. I'll also need to update the Windows(and Linux console) cheat code + to prevent compiler warnings. + + Fixed various minor code problems(not minor if you want to use a + compiler besides gcc). This is an ongoing process... + + Removed bit fields after reading about and thinking about possible + portability problems, though I kept some optimizations in fceline.h + + Minor code simplification in drivers/win/joystick.c(replaced + "case 200 ... 207" and "case 208 ... 215". + + Modified some code to use bit-fields in the graphics rendering code + in fce.c and fceline.h. gcc seems to be able to optimize the new + code to run faster. + + Fixed m6502.c and fce.c to initialize variables on virtual power + toggle. This should fix network play on the Windows port. + I'm also in the process of cleaning up fce.c. + +.75: +---- + Fixed directories configuration stuff in Windows port(corresponds + to .75r2). + + More changes to square wave channel envelope/volume emulation... + Changes described in the large paragraph some lines down have been + abandoned. + + Added a command line switch to set the volume in the dos port. + + Changed Windows sound configuration dialog. Now buffer length is + specified in time, not samples. I also added a volume control. + + Reduced the volume on 8-bit sound output on all ports by 1/2. + + Added a function FCEUI_SetSoundVolume(). Added support for setting + the volume via the command line in the Linux port, other ports coming + soon. + + Changed FCEUD_WriteSoundData() again. No longer has a "Check" + argument. All clipping(ugh) is done internally now. + + Added a directories configuration dialog to the Windows port. I worked + on it too long and I became a zombie, so it might have a few bugs. + That's what guine...err...users are for. ;) Don't expect me to do + anything like this for any other port, though. I don't feel like + doing it on the DOS port, and the Linux and other UNIXy ports shouldn't + really need it. + + Made some changes to the rectangle/square wave channel emulation to + fix the pops in SMB. I have no idea if what I did is correct. To + be honest, I'm not sure I know EXACTLY what I did, but it's something + like this: Writes to $4003/$4007 now reset the duty cycle count + and reload the cycle counter with the current wavelength. Writes to + $4003/$4007 now do not update the amplitude output of the channels; they + will be updated after the cycle counter hits 0(or below). + + More information in iNES informational output. + + Minor changes to mappers/16.c. + + Increased the volume of the VRC6's sawtooth wave channel. + + Added more information to the RAM cheat guide. + + Changed the triangle wave generation code slightly. I decided + to remove support for the higher-frequency triangle waves, as they + are too cpu-costly to create and are probably not very audible on a + real NES anyway. + + Major changes to how sound is mixed. This necessitated a high pass + DC-offset removing filter, and a low-pass filter just to make things + sound better. ^_^ + Note: FCEUD_WriteSoundData() no longer needs to clear the waveform + data referenced by the passed pointer; it's done internally now. + + Fixed JMP ($xxxx) - now handles wrapping like it occurs on a real 6502 + (hopefully; I'm assuming that the same holds true for the NES' cpu). + + Added the ability to load a custom global palette in the DOS port. + + Fixed bug in drivers/common/unixdsp.c(wrong return value if sample + rate was out of range). + + Many sound fixes... - Frequency sweeps, length counter stuff,... + + Changed Windows port to use IDirectInput7 and IDirectInputDevice7 + interfaces. + + Fixed a Game Genie bug in the core emulation code. It only appeared + in the Windows port, though. (Enabling gg emulation, loading a game, + and then disabling gg emulation and loading a new game while in the + gg code entry screen would cause the new loaded game to not work + correctly). + + Modified windows port to use the config saving/loading stuff in + drivers/common/config.c + + Mapper 45 cleanups/fixes. + + Added the ability to load a custom global palette in the Linux port. + Yay. + + Fixed a large number of overcomplicated code and silly bugs in + drivers/common/config.c. This changes the format of the configuration + structure, too. Also added support for saving/loading strings with + automatic memory allocation when strings are loaded. + + Minor change in InitNetplay(). + + Fixed bad type conversions for pointers to functions and fixed + some bad declarations of functions. + + Reenabled zlib support for the sdl build. I need to pay attention + to patches that modify lines than don't fit on my screen. + + Fixed vidblit.c to not emit so many warnings when compiling. + +.74: +---- + + Stop sound in Windows port when user clicks l/m/r mouse buttons + in the non-client area of the window. + + Added "Drag and drop" file open support to Windows port. + + Various code cleanups. + + mappers/33.c optimization. + + Rewrote the function "FCEU_MakeFName()". + + Removed crc32.h from mappers directory. + + Modified some of the window resizing code in the Windows port. + + Added support for waiting for vblank/double buffering to the Windows + port. + + Added/Fixed support for iNES mapper 248. + + After an NSF file is loaded, information about its header is now + displayed. + + Fixed a typo in the Namco 106 extra ram handling code. + + Improved the quality of the Namco 106's extra sound channels. + - Thank Mamiya and Applepie(real name?) for info. + + When an NSF file is being played, FCE Ultra will no longer go through + its scanline rendering loop. This speeds up NSF playback considerably. + + Updated "porting.txt". + + Moved some stuff from DriverInterface() to their own functions. + + Fixed some iNES mapper 18 IRQ counter emulation bugs. "Ninja Jajamaru - + Ginga Dai Sakusen" now works. + + Rewrote large pieces of the mapper 64 code. "Skull and Crossbones" + still doesn't work, though. + + Changed format of iNES header information output, added "ROM CRC32" info. + + Modified the way cycle timing is done slightly. No change + for NTSC emulation, but PAL emulation is a little more accurate. + + Changed the behavior of indirect indexed(I hope I got that right ;)) + instructions to behave more like a real 6502(junk reads are now + performed). + + A few optimizations/cleanups in m6502.c. + +0.73 +---- + + * Fixed several bugs with sprite emulation. Several games(such + as "Trojan" and "VS Duck Hunt") that were broken in .71 and .72 now + work ok. + * Added support for iNES mapper 82. Thanks to those who work on + "unofficial nester". + * Added support for iNES mapper 250(used by "Time Diver Avenger"). + * Fixed the documentation to show that iNES mappers 48, 83, and 232 + are supported. + * Removed various pieces of stale code and fixed a few minor bugs. + * Fixed a triangle wave channel bug(the channel was sometimes enabled + when it shouldn't have been). + * Writing to $4010 with the upper bit clear now acknowledges the DPCM + IRQ. This appears to fix "Stunt Buggies". + * Rewrote pieces of the Zapper emulation code to be cleaner and more + accurate. + * Rewrote the VS Unisystem dip switch drawing code. + * Simplified the setting of VS Unisystem dip switches. The "V" key + now toggles viewing AND editing of dip switches. + +0.72 +---- + + * Various minor bug fixes. + * Various code cleanups and size and speed optimizations. + * Removed some (apparently) unused MMC5 sound emulation code. + * Changed the behavior of $2003 and $4014 to better simulate what occurs + in a real NES. + * Fixed a few bugs in the undocumented 6502 opcode emulation code. + The Game Genie code "NUTANT" for SMB 3 works correctly now, at + least(previously it caused the game to lock up at the end of levels). + * Rewrote large pieces of the 6502 memory fetching code, resulting + in a slight slowdown in the speed of emulation. Benefits include: + Game Genie emulation now works(again) and 6502 emulation is more + accurate. + * Added support for iNES mapper 72. Thanks to rinao for the information. + * Fixed support for iNES mapper 77(used by Napoleon Senki). + * Fixed/Added support for iNES mapper 226. Apparently I made a mistake + in the documentation. Thanks to Mark K. for the information. + * Added support for iNES mapper 227. Thanks to Mark K. for the + information. + * Added support for iNES mapper 234(used by the Maxi-15). Thanks + to Mark K. for the information. Note that many of the Maxi-15 + ROM images on the Internet have corrupt CHR data(graphics), or the + mapper number is set incorrectly(usually to 11). Use a utility to + fix the mapper number. + * Added support for the following UNIF boards(prefixes omitted): + - EKROM (and fixed the reference to "Gemfire" in the documentation). + - HKROM + * Added the ability to enable and disable individual RAM cheats. + * Fixed some problems with the cheat search code(the NES' internal + RAM was being searched differently than any external RAM, which + was being search incorrectly). + +0.71 +---- + + * Fixed a 6502 emulation bug that was causing some Koei games + (ex: Nobunaga's Ambition, Genghis Khan) to not work. + * Extensive PPU/CPU timing adjustments. + * Fixed support for iNES mapper 40. + * Added support for the following UNIF boards(prefixes omitted): + - ETROM + - ELROM + - EWROM + * Fixed a few bugs in the UNIF code. + * Added support for loading and saving cheat files and an interface + to search for/add/delete/list cheats(no interface yet on Linux/DOS). + * Fixed a few minor bugs in the Windows DX code. + * Command line options to control the number of sound fragments + and the fragment size have been added(Linux). + +0.70 +---- + + * Adjusted PPU/CPU timing. + * Removed(until I understand the problem) a hack to get one of the + games in the Caltron 6-in-1 to work. + * Fixed an MMC3 IRQ emulation bug("Project Q" works better now). + * Fixed a problem/misunderstanding regarding the upper scanline. + It can now be displayed again. + * More accurate sprite hit emulation(fixes the title screen of + "Ultimate Stuntman"). + * VRAM bank switching for iNES mapper 4 is now possible(and enabled + for all mapper 4 games without CHR ROM). Fixes "Tenchi o Kurau 2". + * Added support for the Famicom's four-player adapter and the ability + to enable it(it is disabled by default to prevent compatibility + problems). + * Added an option(under miscellaneous configuration) to automatically + open the "File Open" dialog box when FCE Ultra is started. + * Sound sampling rate is now configurable. + * Fixed some bugs in the DirectSound code. + * Joystick button configuration is a little more user friendly(and + stable, hopefully) (Linux). + +0.62 +---- + + * Added support for the Famicom Disk System's extra sound channel. + * Updated the version of Tatsuyuki Satoh's OPL2 emulator used in + FCE Ultra from .36f to .37a. The sound quality in "Lagrange Point" + seems to have improved. + * Added support for iNES mapper 242(used by "Wai Xing Zhan Shi"). + * Fixed a network play bug that could cause desynchronizations + if more than one network play session occured since FCE Ultra + was started. This bug only showed up on the Windows port, though. + * Increased the volume of the noise and triangle sound channels. + * Fixed a save state loading bug. + * Fixed a small memory leak that was being caused by the VRC7 + state loading code. + * Fixed a bug that could cause FCE Ultra to crash if a virtual disk + was being read and the user ejected the virtual disk. + * Various minor bug fixes/code cleanups. + * NTSC color "emulation" can now be enabled again(the code to + enable it was broken in the last version). (Linux) + +0.61 +---- + + * Speed optimizations in sprite rendering code. + * Screen snapshots are now saved in the PNG format instead of the PCX + format. + * Fixed Game Genie emulation(it wasn't working in the last release). + Also added support for Game Genie emulation to the UNIF code. + * Rewrote command line option parsing code. + * Fixed a problem(if FCE Ultra was configured to connect to a remote + host and the remote host was given as an IP address, and the IP + address couldn't be reverse resolved, which is commonly the case + on home LANs, the connection attempt would fail) in the network + play code. I had misinterpreted the Winsock API documentation + when I wrote the code. (Windows) + +0.60 +---- + + * Various speed optimizations. + * Sound is no longer messed up when a JAM/KIL opcode is emulated. + * Fixed an overflow bug that occured when $4014 was written to + during certain(rare) conditions. + * Fixed a few save state bugs. + * Fixed a MMC1 CHR bank switching bug. + * Added emulation of the MMC5's WRAM write-enable/disable registers. + * Fixed a sound frame IRQ emulation bug. "Qix" works now. + * Added UNIF support. Some of the board emulation is still a bit + buggy, though. Look at the documentation for a list of supported + boards. + * Updated the "Palette Notes" section of the documentation. Also + fixed a few other problems with the documentation. + * Added support for loading files in the PKZIP and gzip + compressed file formats via zlib. + * Added the ability to configure the first scanline and the last + scanline to draw to the screen. Enabling PAL emulation no longer + will cause all 239 scanlines to be displayed, though an option + to override these settings for when PAL emulation is enabled may + be in the next version. + * Fixed a bug that would cause the emulated D-pad of virtual gamepads + emulated through the keyboard to be duplicated through "higher" + virtual gamepads(gamepad 1 would affect 2,3,4; gamepad 2 would + affect 3,4; etc.). (Windows) + +0.55 +---- + * Rewrote window resizing code. The window will now resize itself + to a multiple of the NES' screen dimensions nearest to the user + selected dimensions. (Windows) + * Added an option to use buttons instead of axes on physical joysticks + for the emulated D-Pad. This is useful for some digital joysticks. (Windows) + * Fixed a bug that would cause FCE Ultra to crash if sound were + disabled during emulation. (Windows) + * Added the ability to "fast forward" emulation. + * Added an option to allow more than 8 sprites per scanline to be + displayed. + * Added an option to save all extra non-volatile game data + (such as battery-backed RAM) in a directory under FCE Ultra's + base directory(as opposed to the directory the game is located in). + * Added an option to allow the emulator to change to a full screen + video mode once a new game is loaded. (Windows) + * Rewrote pieces of DirectInput joystick handling code. Hopefully + it should increase compatibility. (Windows) + * Added the ability to automatically obtain button numbers when + configuring joysticks, by pressing buttons on the joystick. + * Added the ability to close the current game(decreases CPU usage). (windows) + * Increased the speed of various function calls by passing + arguments to functions through registers instead of through the + stack. + * Added emulation of the MMC5's raw PCM register. + * Added the ability to save/load save states while network play + is occuring. + * Having PAL emulation enabled will no longer override the + NTSC/PAL settings in NSF headers. + * Fixed a bug that got into the .54 release. Extraneous data was + being returned on reads from $2002, which caused problems + with some games(such as "Choujin Sentai Jetman"). + +0.54 +---- + * Fixed a bug that would cause a wrong battery-backed WRAM file + name to be produced if FCE Ultra was passed a file name without + any directory component(such as "fceu SuperBlah.nes"). + * Fixed an iNES mapper 118 emulation bug that got into the code + in a recent code cleanup. "Armadillo" is playable again. + * Fixed a typo(and bug) in the MMC5 emulation code. + * Data returned from emulated reads to "unmapped" areas or + memory locations where bits are undefined should now be correct. + * Fixed emulation of the sprite memory transfer register $4014. + It now takes into account the last value written to $2003 and + starts the transfer to that location in sprite memory(like on + a real NES). + * Added a video configuration dialog box. (Windows) + * Added the ability to configure a custom video mode. Aspects + that are configurable include width, height, bits per pixel, + and size transforming(stretching and scaling). (Windows) + +0.53 +---- + + * Fixed a bug with joysticks that occured on systems with multiple + joysticks. (Windows) + * Added support for iNES mappers 77 and 92(thanks to LULU for the code for both). + * Added partial(timer is non-configurable) support for iNES mapper 105. + * Changed save state format again. Save states made with previous + versions should still be compatible, though this may change in + future versions. + * Small optimization to sprite emulation code. + * Rewrote color-deemphasis code to use integer math instead of + floating-point math. + * Rewrote and restructured input code. (Linux) + * Added command line option "-f8bit" to force 8-bit sound. (Linux) + * Rewrote and restructured input code. Among other new features, + keyboard keys are now somewhat configurable. (Windows) + * Writes to $4003/$4007 will now reset the emulated square wave + duty cycle generator. + * Added emulation of the Power Pad. + * Rewrote joystick device reading code to use the event-driven + interface. This should fix various problems regarding support + for joysticks with many buttons. (linux) + +0.52 +---- + + * Fixed a PCM emulation bug(digitized voices in "Ikari Warriors 2" + and "The Immortal", among others, work now). + * Fixed noise channel's LSFR update frequencies(hopefully). + * Various minor bug fixes. + +0.51 +---- + + * Added support for iNES mappers 86 and 89. + * Reduced byte size of the NSF player's background. + * Adjusted CPU/PPU timing. + * Fixed sound channel frequency calculations for when PAL emulation is enabled. + * Rewrote large pieces of the sound code and got rid of the sound queue. Sound quality should be slightly better now. + * Various minor bug fixes. + + Windows: + + * Fixed an FDS side reset bug when a new game is loaded. + * Screen width/depth/height changes while FCE Ultra is in windowed mode are handled now. + * Changed the configuration file format. + * Added a palette configuration dialog. + * Added the ability to load a custom NES palette. + * Added an option to double 16-bit sound volume. + * Added an option to force 8-bit sound. + * Added an option to use a secondary sound buffer(versus the primary). + * Added an option to wait for vertical blank if sound is disabled. + * Added an option to run while focus is lost. + +0.50 +---- + + * Many bug fixes. + * Sound code partially rewritten to improve quality(near-perfect + raw PCM now) and eliminate the need for a separate thread. + This created a small problem with network play, though, so read + the network play notes section. Also, synchronizing to + vertical blank has been removed. + * Rewrote other pieces of sound code. No more "buzzing" in MegaMan 2, + Codemasters games' intros, etc. + * Added support for the NES Zapper and the VS Unisystem's light + gun. Be sure to read "Light Gun Notes". + * Changed save state format. Save states should now be much + smaller for most games. Most(not all) save states created with + an older version should work. + * Added support for VS Duck Hunt and VS Hogan's Alley. + diff --git a/branches/fceux-2.2.2/attic/Makefile.am b/branches/fceux-2.2.2/attic/Makefile.am new file mode 100644 index 00000000..d397280d --- /dev/null +++ b/branches/fceux-2.2.2/attic/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/branches/fceux-2.2.2/attic/SConstruct.pre1.0 b/branches/fceux-2.2.2/attic/SConstruct.pre1.0 new file mode 100644 index 00000000..bac63f3d --- /dev/null +++ b/branches/fceux-2.2.2/attic/SConstruct.pre1.0 @@ -0,0 +1,147 @@ +# Use this SConstruct if you are using scons < 1.x +# Just replace the SConstruct file with this one +# cp SConstruct.pre1.0 SConstruct +# +# or just updated scons already + +import os +import sys +import platform + +opts = Options() +opts.AddOptions( + BoolOption('FRAMESKIP', 'Enable frameskipping', 1), + BoolOption('OPENGL', 'Enable OpenGL support', 1), + BoolOption('LSB_FIRST', 'Least signficant byte first (non-PPC)', 1), + BoolOption('DEBUG', 'Build with debugging symbols', 1), + BoolOption('LUA', 'Enable Lua support', 1), + BoolOption('NEWPPU', 'Enable new PPU core', 1), + BoolOption('CREATE_AVI', 'Enable avi creation support (SDL only)', 0), + BoolOption('LOGO', 'Enable a logoscreen when creating avis (SDL only)', '1'), + BoolOption('GTK', 'Enable GTK2 GUI (SDL only)', 1), + BoolOption('GTK_LITE', 'Enable GTK2 for dialogs only', 0) +) + +env = Environment(options = opts) + +# LSB_FIRST must be off for PPC to compile +if platform.system == "ppc": + env['LSB_FIRST'] = 0 + +# Default compiler flags: +env.Append(CCFLAGS = ['-Wall', '-Wno-write-strings', '-Wno-sign-compare', '-O2', '-Isrc/lua/src']) + +if os.environ.has_key('PLATFORM'): + env.Replace(PLATFORM = os.environ['PLATFORM']) +if os.environ.has_key('CC'): + env.Replace(CC = os.environ['CC']) +if os.environ.has_key('CXX'): + env.Replace(CXX = os.environ['CXX']) +if os.environ.has_key('WINDRES'): + env.Replace(WINDRES = os.environ['WINDRES']) +if os.environ.has_key('CFLAGS'): + env.Append(CCFLAGS = os.environ['CFLAGS'].split()) +if os.environ.has_key('LDFLAGS'): + env.Append(LINKFLAGS = os.environ['LDFLAGS'].split()) + +print "platform: ", env['PLATFORM'] + +# special flags for cygwin +# we have to do this here so that the function and lib checks will go through mingw +if env['PLATFORM'] == 'cygwin': + env.Append(CCFLAGS = " -mno-cygwin") + env.Append(LINKFLAGS = " -mno-cygwin") + env['LIBS'] = ['wsock32']; + +if env['PLATFORM'] == 'win32': + env.Append(CPPPATH = [".", "drivers/win/", "drivers/common/", "drivers/", "drivers/win/zlib", "drivers/win/directx", "drivers/win/lua/include"]) + env.Append(CPPDEFINES = ["PSS_STYLE=2", "WIN32", "_USE_SHARED_MEMORY_", "NETWORK", "FCEUDEF_DEBUGGER", "NOMINMAX", "NEED_MINGW_HACKS", "_WIN32_IE=0x0600"]) + env.Append(LIBS = ["rpcrt4", "comctl32", "vfw32", "winmm", "ws2_32", "comdlg32", "ole32", "gdi32", "htmlhelp"]) +else: + conf = Configure(env) + if not conf.CheckLib('SDL'): + print 'Did not find libSDL or SDL.lib, exiting!' + Exit(1) + if not conf.CheckLib('z', autoadd=1): + print 'Did not find libz or z.lib, exiting!' + Exit(1) + if env['GTK'] or env['GTK_LITE']: + # Add compiler and linker flags from pkg-config + env.ParseConfig('pkg-config --cflags --libs gtk+-2.0') + env.Append(CPPDEFINES=["_GTK2"]) + if env['GTK']: + env.Append(CCFLAGS = ["-D_GTK"]) + env.Append(CCFLAGS =["-D_GTK_LITE"]) + if env['GTK_LITE']: + env.Append(CCFLAGS =["-D_GTK_LITE"]) + + ### Lua platform defines + ### Applies to all files even though only lua needs it, but should be ok + if env['LUA']: + if env['PLATFORM'] == 'darwin': + # Define LUA_USE_MACOSX otherwise we can't bind external libs from lua + env.Append(CCFLAGS = ["-DLUA_USE_MACOSX"]) + if env['PLATFORM'] == 'posix': + # If we're POSIX, we use LUA_USE_LINUX since that combines usual lua posix defines with dlfcn calls for dynamic library loading. + # Should work on any *nix + env.Append(CCFLAGS = ["-DLUA_USE_LINUX"]) + + ### Search for gd if we're not in Windows + if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI'] and env['LOGO']: + gd = conf.CheckLib('gd', autoadd=1) + if gd == 0: + env['LOGO'] = 0 + print 'Did not find libgd, you won\'t be able to create a logo screen for your avis.' + + if conf.CheckFunc('asprintf'): + conf.env.Append(CCFLAGS = " -DHAVE_ASPRINTF") + if env['OPENGL'] and conf.CheckLibWithHeader('GL', 'GL/gl.h', 'c++', autoadd=1): + conf.env.Append(CCFLAGS = " -DOPENGL") + conf.env.Append(CPPDEFINES = ['PSS_STYLE=1']) + # parse SDL cflags/libs + env.ParseConfig('sdl-config --cflags --libs') + + env.Append(CPPDEFINES=["_S9XLUA_H"]) + env = conf.Finish() + +if sys.byteorder == 'little' or env['PLATFORM'] == 'win32': + env.Append(CPPDEFINES = ['LSB_FIRST']) + +if env['FRAMESKIP']: + env.Append(CPPDEFINES = ['FRAMESKIP']) + +print "base CPPDEFINES:",env['CPPDEFINES'] +print "base CCFLAGS:",env['CCFLAGS'] + +if env['DEBUG']: + env.Append(CPPDEFINES=["_DEBUG"], CCFLAGS = ['-g']) + +if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI']: + env.Append(CPPDEFINES=["CREATE_AVI"]) +else: + env['CREATE_AVI']=0; + +Export('env') +SConscript('src/SConscript') + +# Install rules +exe_suffix = '' +if env['PLATFORM'] == 'win32': + exe_suffix = '.exe' + +fceux_src = 'src/fceux' + exe_suffix +fceux_dst = 'bin/fceux' + exe_suffix + +auxlib_src = 'src/auxlib.lua' +auxlib_dst = 'bin/auxlib.lua' + +fceux_h_src = 'src/drivers/win/help/fceux.chm' +fceux_h_dst = 'bin/fceux.chm' + +env.Command(fceux_h_dst, fceux_h_src, [Copy(fceux_h_dst, fceux_h_src)]) +env.Command(fceux_dst, fceux_src, [Copy(fceux_dst, fceux_src)]) +env.Command(auxlib_dst, auxlib_src, [Copy(auxlib_dst, auxlib_src)]) + +# TODO: Fix this build script to gracefully install auxlib and the man page +#env.Alias(target="install", source=env.Install(dir="/usr/local/bin/", source=("bin/fceux", "bin/auxlib.lua"))) +env.Alias(target="install", source=env.Install(dir="/usr/local/bin/", source="bin/fceux")) diff --git a/branches/fceux-2.2.2/attic/TODO-SDL-2.1.6.md b/branches/fceux-2.2.2/attic/TODO-SDL-2.1.6.md new file mode 100644 index 00000000..83f6576e --- /dev/null +++ b/branches/fceux-2.2.2/attic/TODO-SDL-2.1.6.md @@ -0,0 +1,118 @@ +BUGS +==== +Save/Load State Console Print Bug +--------------------------------- +* ie: + -select state- + State -777722344 saved + +* If the root of the bug cannot be determined by release time, just #ifdef the print statement for win32 + +Clip sides bug in BOTH WINDOWED AND FULLSCREEN mode +--------------------------------------------------- +* Go to game genie with clip sides enabled or save a state to see +* Ensure no clip sides is only being enabled during fullscreen + +DONE! Gamepad dialog and others segfault on Ubuntu 10.04 (and older GTK versions) +--------------------------------------------------------------------------------- +* Not planning on using legacy code here (especially with Ubuntu 12.04 on its way) but perhaps +a messagebox can be displayed recommending the user to upgrade their GTK version to prevent +the frustrating segfault. Segfaults need to be avoided like the plague. + +* This is fixed in r2447. FceuX will print a warning to the console that the GTK version is old, and +provide instructions on how to configure the gamepad. +* Maybe we should also provide a GTK MessageBox with this info? + +FEATURES +======== +XDG Standardization of Config +----------------------------- +* fceux currently stores stuff to ~/.fceux by default +* FD.O/XDG recommends default to be ~/.config/fceux (and to check $XDG_whatever) +* If the XDG folder exists, use it. If NO folder exists, use the XDG folder. +* If .fceux exists, display a warning message but use .fceux +* Don't move around people's config files without asking (or at all in this case) + +input.cpp +========= +* This code is a fscking mess! However, now is not the time to clean it. Perhaps set a goal to clean this file up for +2.1.7, but cleaning this for 2.1.6 is not realistic (and would break too many things and require more testing time) + +DISTRO TESTING +============== +Summary +------- +* Out of box working distros: + * Arch Linux + * Ubuntu 10.04 + * Ubuntu 12.04 +* Works, but needs patching: + * Fedora Core 16 +* Couldn't get working + * openSUSE +* Untested: + * Linux Mint + * Debian + + +Arch Linux 64 bit +----------------- +* Flawless installation from fceux-svn in [aur]. No issues other than the ones already noted. +* Dpendencies: sdl, gtk2, scons libz + +Ubuntu 10.04 +------------ +* Compiles/builds without issue. +* Build deps: libsdl1.2-dev, scons, libgtk2.0-dev, zlib-dev, build-essentials +* No issues found in gameplay. +* DONE Some dialogs with segfault FCEUX due to an older version of GTK. Perhaps we can detect the old version of GTK and just prevent the dialog from being opened so the segfault doesnt occur? (bug added). + * DONE Wrote CheckGTKVersion(), which will be used like CheckGTKVersion(2, 24) to check the GTK version before segfaulting on dialogs + * DONE Implement a check for the dialogs that would bomb -- (a hook in init; makes all items under Options inacessible besides fullscreen if under 2.24) + +Ubuntu 12.04 Beta +----------------- +* Compiles/builds without issue. +* GTK3 preferred for Unity +* Build deps: libsdl1.2-dev, scons, libgtk-3-dev, zlib-dev, build-essentials +* No issues AFAICS + +Fedora Core 16 +-------------- +* Dependencies: subversion, scons, SDL-devel, gtk2-devel/gtk3-devel, gcc, [glib-devel?] +* You also need to install the "Development Tools" group: + + yum groupinstall "Development Tools" + +* scons bombs out (another missing dependency? + + /usr/bin/ld: src/lua/src/loadlib.o: undefined reference to symbol 'dlclose@@GLIBC_2.2.5' + /usr/bin/ld: note: 'dlclose@@GLIBC_2.2.5' is defined in DSO /lib64/libdl.so.2 so try adding it to the linker command line + /lib64/libdl.so.2: could not read symbols: Invalid operation + collect2: ld returned 1 exit status + scons: *** [src/fceux] Error 1 + scons: building terminated because of errors. + + * This was fixed by forcing "-ldl" to the linker command line. This can be done by adding the following + to line 92 of the SConstruct: + + env.Append(LINKFLAGS = ["-ldl"]) + + * TODO Answer some questions: + 1. Is -ldl necessary everywhere? + 2. Should we always use it? If not what can we test for for when to use it? + + * Check the code circa line 92 in SConstruct for a Fedora resolution. + + * Tested with GTK2, runs smoothly in VirtualBox. + +openSUSE 12.1 +------------- +* scons bombs out because can't find libgtk; I can't find gtk headers package + +PROJECT STUFF +============= +* Contact debian package management about inclusion +* Create a sane release procedure script that generates a release ready tarball +* DONE - Create markdown file of README +* Locate important features/changes new to 2.1.6 and summarize them. + diff --git a/branches/fceux-2.2.2/attic/acinclude.m4 b/branches/fceux-2.2.2/attic/acinclude.m4 new file mode 100644 index 00000000..a2d04875 --- /dev/null +++ b/branches/fceux-2.2.2/attic/acinclude.m4 @@ -0,0 +1,357 @@ +# Configure paths for SDL +# Sam Lantinga 9/21/99 +# stolen from Manish Singh +# stolen back from Frank Belew +# stolen from Manish Singh +# Shamelessly stolen from Owen Taylor + +dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) +dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS +dnl +AC_DEFUN(AM_PATH_SDL, +[dnl +dnl Get the cflags and libraries from the sdl-config script +dnl +AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], + sdl_prefix="$withval", sdl_prefix="") +AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)], + sdl_exec_prefix="$withval", sdl_exec_prefix="") +AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], + , enable_sdltest=yes) + + if test x$sdl_exec_prefix != x ; then + sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix" + if test x${SDL_CONFIG+set} != xset ; then + SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config + fi + fi + if test x$sdl_prefix != x ; then + sdl_args="$sdl_args --prefix=$sdl_prefix" + if test x${SDL_CONFIG+set} != xset ; then + SDL_CONFIG=$sdl_prefix/bin/sdl-config + fi + fi + + AC_PATH_PROG(SDL_CONFIG, sdl-config, no) + min_sdl_version=ifelse([$1], ,0.11.0,$1) + AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) + no_sdl="" + if test "$SDL_CONFIG" = "no" ; then + no_sdl=yes + else + SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags` + SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs` + + sdl_major_version=`$SDL_CONFIG $sdl_args --version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` + sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` + sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` + if test "x$enable_sdltest" = "xyes" ; then + ac_save_CFLAGS="$CFLAGS" + ac_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" +dnl +dnl Now check if the installed SDL is sufficiently new. (Also sanity +dnl checks the results of sdl-config to some extent +dnl + rm -f conf.sdltest + AC_TRY_RUN([ +#include +#include +#include +#include + +char* +my_strdup (char *str) +{ + char *new_str; + + if (str) + { + new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); + strcpy (new_str, str); + } + else + new_str = NULL; + + return new_str; +} + +int main (int argc, char *argv[]) +{ + int major, minor, micro; + char *tmp_version; + + /* This hangs on some systems (?) + system ("touch conf.sdltest"); + */ + { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); } + + /* HP/UX 9 (%@#!) writes to sscanf strings */ + tmp_version = my_strdup("$min_sdl_version"); + if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + printf("%s, bad version string\n", "$min_sdl_version"); + exit(1); + } + + if (($sdl_major_version > major) || + (($sdl_major_version == major) && ($sdl_minor_version > minor)) || + (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) + { + return 0; + } + else + { + printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); + printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); + printf("*** best to upgrade to the required version.\n"); + printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); + printf("*** to point to the correct copy of sdl-config, and remove the file\n"); + printf("*** config.cache before re-running configure\n"); + return 1; + } +} + +],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) + CFLAGS="$ac_save_CFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + if test "x$no_sdl" = x ; then + AC_MSG_RESULT(yes) + ifelse([$2], , :, [$2]) + else + AC_MSG_RESULT(no) + if test "$SDL_CONFIG" = "no" ; then + echo "*** The sdl-config script installed by SDL could not be found" + echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" + echo "*** your path, or set the SDL_CONFIG environment variable to the" + echo "*** full path to sdl-config." + else + if test -f conf.sdltest ; then + : + else + echo "*** Could not run SDL test program, checking why..." + CFLAGS="$CFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + AC_TRY_LINK([ +#include +#include +], [ return 0; ], + [ echo "*** The test program compiled, but did not run. This usually means" + echo "*** that the run-time linker is not finding SDL or finding the wrong" + echo "*** version of SDL. If it is not finding SDL, you'll need to set your" + echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" + echo "*** to the installed location Also, make sure you have run ldconfig if that" + echo "*** is required on your system" + echo "***" + echo "*** If you have an old version installed, it is best to remove it, although" + echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], + [ echo "*** The test program failed to compile or link. See the file config.log for the" + echo "*** exact error that occured. This usually means SDL was incorrectly installed" + echo "*** or that you have moved SDL since it was installed. In the latter case, you" + echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ]) + CFLAGS="$ac_save_CFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + SDL_CFLAGS="" + SDL_LIBS="" + ifelse([$3], , :, [$3]) + fi + AC_SUBST(SDL_CFLAGS) + AC_SUBST(SDL_LIBS) + rm -f conf.sdltest +]) + +/* Steven G. Johnson and Alejandro Forero Cuervo */ +AC_DEFUN([ACX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_SAVE +AC_LANG_C +acx_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) + AC_MSG_RESULT($acx_pthread_ok) + if test x"$acx_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all. + +acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# pthread: Linux, etcetera +# --thread-safe: KAI C++ + +case "${host_cpu}-${host_os}" in + *solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthread or + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags" + ;; +esac + +if test x"$acx_pthread_ok" = xno; then +for flag in $acx_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [acx_pthread_ok=yes]) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($acx_pthread_ok) + if test "x$acx_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$acx_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: threads are created detached by default + # and the JOINABLE attribute has a nonstandard name (UNDETACHED). + AC_MSG_CHECKING([for joinable pthread attribute]) + AC_TRY_LINK([#include ], + [int attr=PTHREAD_CREATE_JOINABLE;], + ok=PTHREAD_CREATE_JOINABLE, ok=unknown) + if test x"$ok" = xunknown; then + AC_TRY_LINK([#include ], + [int attr=PTHREAD_CREATE_UNDETACHED;], + ok=PTHREAD_CREATE_UNDETACHED, ok=unknown) + fi + if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then + AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok, + [Define to the necessary symbol if this constant + uses a non-standard name on your system.]) + fi + AC_MSG_RESULT(${ok}) + if test x"$ok" = xunknown; then + AC_MSG_WARN([we do not know how to create joinable pthreads]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case "${host_cpu}-${host_os}" in + *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";; + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + # More AIX lossage: must compile with cc_r + AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + acx_pthread_ok=no + $2 +fi +AC_LANG_RESTORE +])dnl ACX_PTHREAD diff --git a/branches/fceux-2.2.2/attic/aclocal.m4 b/branches/fceux-2.2.2/attic/aclocal.m4 new file mode 100644 index 00000000..42e071f0 --- /dev/null +++ b/branches/fceux-2.2.2/attic/aclocal.m4 @@ -0,0 +1,879 @@ +# generated automatically by aclocal 1.9.5 -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_AUTOMAKE_VERSION(VERSION) +# ---------------------------- +# Automake X.Y traces this macro to ensure aclocal.m4 has been +# generated from the m4 files accompanying Automake X.Y. +AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version="1.9"]) + +# AM_SET_CURRENT_AUTOMAKE_VERSION +# ------------------------------- +# Call AM_AUTOMAKE_VERSION so it can be traced. +# This function is AC_REQUIREd by AC_INIT_AUTOMAKE. +AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], + [AM_AUTOMAKE_VERSION([1.9.5])]) + +# AM_AUX_DIR_EXPAND -*- Autoconf -*- + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets +# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to +# `$srcdir', `$srcdir/..', or `$srcdir/../..'. +# +# Of course, Automake must honor this variable whenever it calls a +# tool from the auxiliary directory. The problem is that $srcdir (and +# therefore $ac_aux_dir as well) can be either absolute or relative, +# depending on how configure is run. This is pretty annoying, since +# it makes $ac_aux_dir quite unusable in subdirectories: in the top +# source directory, any form will work fine, but in subdirectories a +# relative path needs to be adjusted first. +# +# $ac_aux_dir/missing +# fails when called from a subdirectory if $ac_aux_dir is relative +# $top_srcdir/$ac_aux_dir/missing +# fails if $ac_aux_dir is absolute, +# fails when called from a subdirectory in a VPATH build with +# a relative $ac_aux_dir +# +# The reason of the latter failure is that $top_srcdir and $ac_aux_dir +# are both prefixed by $srcdir. In an in-source build this is usually +# harmless because $srcdir is `.', but things will broke when you +# start a VPATH build or use an absolute $srcdir. +# +# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, +# iff we strip the leading $srcdir from $ac_aux_dir. That would be: +# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` +# and then we would define $MISSING as +# MISSING="\${SHELL} $am_aux_dir/missing" +# This will work as long as MISSING is not called from configure, because +# unfortunately $(top_srcdir) has no meaning in configure. +# However there are other variables, like CC, which are often used in +# configure, and could therefore not use this "fixed" $ac_aux_dir. +# +# Another solution, used here, is to always expand $ac_aux_dir to an +# absolute PATH. The drawback is that using absolute paths prevent a +# configured tree to be moved without reconfiguration. + +AC_DEFUN([AM_AUX_DIR_EXPAND], +[dnl Rely on autoconf to set up CDPATH properly. +AC_PREREQ([2.50])dnl +# expand $ac_aux_dir to an absolute path +am_aux_dir=`cd $ac_aux_dir && pwd` +]) + +# AM_CONDITIONAL -*- Autoconf -*- + +# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 7 + +# AM_CONDITIONAL(NAME, SHELL-CONDITION) +# ------------------------------------- +# Define a conditional. +AC_DEFUN([AM_CONDITIONAL], +[AC_PREREQ(2.52)dnl + ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE]) +AC_SUBST([$1_FALSE]) +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) + + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 8 + +# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be +# written in clear, in which case automake, when reading aclocal.m4, +# will think it sees a *use*, and therefore will trigger all it's +# C support machinery. Also note that it means that autoscan, seeing +# CC etc. in the Makefile, will ask for an AC_PROG_CC use... + + +# _AM_DEPENDENCIES(NAME) +# ---------------------- +# See how the compiler implements dependency checking. +# NAME is "CC", "CXX", "GCJ", or "OBJC". +# We try a few techniques and use that to set a single cache variable. +# +# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was +# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular +# dependency, and given that the user is not expected to run this macro, +# just rely on AC_PROG_CC. +AC_DEFUN([_AM_DEPENDENCIES], +[AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +ifelse([$1], CC, [depcc="$CC" am_compiler_list=], + [$1], CXX, [depcc="$CXX" am_compiler_list=], + [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named `D' -- because `-MD' means `put the output + # in D'. + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with + # Solaris 8's {/usr,}/bin/sh. + touch sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + case $depmode in + nosideeffect) + # after this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + none) break ;; + esac + # We check with `-c' and `-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle `-M -o', and we need to detect this. + if depmode=$depmode \ + source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) + + +# AM_SET_DEPDIR +# ------------- +# Choose a directory name for dependency files. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES +AC_DEFUN([AM_SET_DEPDIR], +[AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) + + +# AM_DEP_TRACK +# ------------ +AC_DEFUN([AM_DEP_TRACK], +[AC_ARG_ENABLE(dependency-tracking, +[ --disable-dependency-tracking speeds up one-time build + --enable-dependency-tracking do not reject slow dependency extractors]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH]) +]) + +# Generate code to set up dependency tracking. -*- Autoconf -*- + +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +#serial 3 + +# _AM_OUTPUT_DEPENDENCY_COMMANDS +# ------------------------------ +AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], +[for mf in $CONFIG_FILES; do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named `Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # So let's grep whole file. + if grep '^#.*generated by automake' $mf > /dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running `make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # When using ansi2knr, U may be empty or an underscore; expand it + U=`sed -n 's/^U = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done +done +])# _AM_OUTPUT_DEPENDENCY_COMMANDS + + +# AM_OUTPUT_DEPENDENCY_COMMANDS +# ----------------------------- +# This macro should only be invoked once -- use via AC_REQUIRE. +# +# This code is only required when automatic dependency tracking +# is enabled. FIXME. This creates each `.P' file that we will +# need in order to bootstrap the dependency handling code. +AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], +[AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) + +# Do all the work for Automake. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 12 + +# This macro actually does too much. Some checks are only needed if +# your package does certain things. But this isn't really a big deal. + +# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) +# AM_INIT_AUTOMAKE([OPTIONS]) +# ----------------------------------------------- +# The call with PACKAGE and VERSION arguments is the old style +# call (pre autoconf-2.50), which is being phased out. PACKAGE +# and VERSION should now be passed to AC_INIT and removed from +# the call to AM_INIT_AUTOMAKE. +# We support both call styles for the transition. After +# the next Automake release, Autoconf can make the AC_INIT +# arguments mandatory, and then we can depend on a new Autoconf +# release and drop the old call support. +AC_DEFUN([AM_INIT_AUTOMAKE], +[AC_PREREQ([2.58])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +# test to see if srcdir already configured +if test "`cd $srcdir && pwd`" != "`pwd`" && + test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) + AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) +AM_MISSING_PROG(AUTOCONF, autoconf) +AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) +AM_MISSING_PROG(AUTOHEADER, autoheader) +AM_MISSING_PROG(MAKEINFO, makeinfo) +AM_PROG_INSTALL_SH +AM_PROG_INSTALL_STRIP +AC_REQUIRE([AM_PROG_MKDIR_P])dnl +# We need awk for the "check" target. The system "awk" is bad on +# some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES(CC)], + [define([AC_PROG_CC], + defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES(CXX)], + [define([AC_PROG_CXX], + defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl +]) +]) + + +# When config.status generates a header, we must update the stamp-h file. +# This file resides in the same directory as the config header +# that is generated. The stamp files are numbered to have different names. + +# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the +# loop where config.status creates the headers, so we can generate +# our stamp files there. +AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], +[# Compute $1's index in $config_headers. +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $1 | $1:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_SH +# ------------------ +# Define $install_sh. +AC_DEFUN([AM_PROG_INSTALL_SH], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +install_sh=${install_sh-"$am_aux_dir/install-sh"} +AC_SUBST(install_sh)]) + +# Copyright (C) 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# Check whether the underlying file-system supports filenames +# with a leading dot. For instance MS-DOS doesn't. +AC_DEFUN([AM_SET_LEADING_DOT], +[rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) + +# Check to see how 'make' treats includes. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 3 + +# AM_MAKE_INCLUDE() +# ----------------- +# Check to see how make treats includes. +AC_DEFUN([AM_MAKE_INCLUDE], +[am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo done +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# We grep out `Entering directory' and `Leaving directory' +# messages which can occur if `w' ends up in MAKEFLAGS. +# In particular we don't look at `^make:' because GNU make might +# be invoked under some other name (usually "gmake"), in which +# case it prints its new name instead of `make'. +if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then + am__include=include + am__quote= + _am_result=GNU +fi +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then + am__include=.include + am__quote="\"" + _am_result=BSD + fi +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) + +# Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 3 + +# AM_PROG_CC_C_O +# -------------- +# Like AC_PROG_CC_C_O, but changed for automake. +AC_DEFUN([AM_PROG_CC_C_O], +[AC_REQUIRE([AC_PROG_CC_C_O])dnl +AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +# FIXME: we rely on the cache variable name because +# there is no other way. +set dummy $CC +ac_cc=`echo $[2] | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']` +if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" != yes"; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +]) + +# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- + +# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# AM_MISSING_PROG(NAME, PROGRAM) +# ------------------------------ +AC_DEFUN([AM_MISSING_PROG], +[AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) + + +# AM_MISSING_HAS_RUN +# ------------------ +# Define MISSING if not defined so far and test if it supports --run. +# If it does, set am_missing_run to use it, otherwise, to nothing. +AC_DEFUN([AM_MISSING_HAS_RUN], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" +# Use eval to expand $SHELL +if eval "$MISSING --run true"; then + am_missing_run="$MISSING --run " +else + am_missing_run= + AC_MSG_WARN([`missing' script is too old or missing]) +fi +]) + +# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_MKDIR_P +# --------------- +# Check whether `mkdir -p' is supported, fallback to mkinstalldirs otherwise. +# +# Automake 1.8 used `mkdir -m 0755 -p --' to ensure that directories +# created by `make install' are always world readable, even if the +# installer happens to have an overly restrictive umask (e.g. 077). +# This was a mistake. There are at least two reasons why we must not +# use `-m 0755': +# - it causes special bits like SGID to be ignored, +# - it may be too restrictive (some setups expect 775 directories). +# +# Do not use -m 0755 and let people choose whatever they expect by +# setting umask. +# +# We cannot accept any implementation of `mkdir' that recognizes `-p'. +# Some implementations (such as Solaris 8's) are not thread-safe: if a +# parallel make tries to run `mkdir -p a/b' and `mkdir -p a/c' +# concurrently, both version can detect that a/ is missing, but only +# one can create it and the other will error out. Consequently we +# restrict ourselves to GNU make (using the --version option ensures +# this.) +AC_DEFUN([AM_PROG_MKDIR_P], +[if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then + # We used to keeping the `.' as first argument, in order to + # allow $(mkdir_p) to be used without argument. As in + # $(mkdir_p) $(somedir) + # where $(somedir) is conditionally defined. However this is wrong + # for two reasons: + # 1. if the package is installed by a user who cannot write `.' + # make install will fail, + # 2. the above comment should most certainly read + # $(mkdir_p) $(DESTDIR)$(somedir) + # so it does not work when $(somedir) is undefined and + # $(DESTDIR) is not. + # To support the latter case, we have to write + # test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir), + # so the `.' trick is pointless. + mkdir_p='mkdir -p --' +else + # On NextStep and OpenStep, the `mkdir' command does not + # recognize any option. It will interpret all options as + # directories to create, and then abort because `.' already + # exists. + for d in ./-p ./--version; + do + test -d $d && rmdir $d + done + # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists. + if test -f "$ac_aux_dir/mkinstalldirs"; then + mkdir_p='$(mkinstalldirs)' + else + mkdir_p='$(install_sh) -d' + fi +fi +AC_SUBST([mkdir_p])]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 3 + +# _AM_MANGLE_OPTION(NAME) +# ----------------------- +AC_DEFUN([_AM_MANGLE_OPTION], +[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) + +# _AM_SET_OPTION(NAME) +# ------------------------------ +# Set option NAME. Presently that only means defining a flag for this option. +AC_DEFUN([_AM_SET_OPTION], +[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) + +# _AM_SET_OPTIONS(OPTIONS) +# ---------------------------------- +# OPTIONS is a space-separated list of Automake options. +AC_DEFUN([_AM_SET_OPTIONS], +[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) + +# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) +# ------------------------------------------- +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +AC_DEFUN([_AM_IF_OPTION], +[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) + +# Check to make sure that the build environment is sane. -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 +# Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 4 + +# AM_SANITY_CHECK +# --------------- +AC_DEFUN([AM_SANITY_CHECK], +[AC_MSG_CHECKING([whether build environment is sane]) +# Just in case +sleep 1 +echo timestamp > conftest.file +# Do `set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t $srcdir/configure conftest.file` + fi + rm -f conftest.file + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken +alias in your environment]) + fi + + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT(yes)]) + +# Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_STRIP +# --------------------- +# One issue with vendor `install' (even GNU) is that you can't +# specify the program used to strip binaries. This is especially +# annoying in cross-compiling environments, where the build's strip +# is unlikely to handle the host's binaries. +# Fortunately install-sh will honor a STRIPPROG variable, so we +# always use install-sh in `make install-strip', and initialize +# STRIPPROG with the value of the STRIP variable (set by the user). +AC_DEFUN([AM_PROG_INSTALL_STRIP], +[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using `strip' when the user +# run `make install-strip'. However `strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the `STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be `maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) + +# Check how to create a tarball. -*- Autoconf -*- + +# Copyright (C) 2004, 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# serial 2 + +# _AM_PROG_TAR(FORMAT) +# -------------------- +# Check how to create a tarball in format FORMAT. +# FORMAT should be one of `v7', `ustar', or `pax'. +# +# Substitute a variable $(am__tar) that is a command +# writing to stdout a FORMAT-tarball containing the directory +# $tardir. +# tardir=directory && $(am__tar) > result.tar +# +# Substitute a variable $(am__untar) that extract such +# a tarball read from stdin. +# $(am__untar) < result.tar +AC_DEFUN([_AM_PROG_TAR], +[# Always define AMTAR for backward compatibility. +AM_MISSING_PROG([AMTAR], [tar]) +m4_if([$1], [v7], + [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'], + [m4_case([$1], [ustar],, [pax],, + [m4_fatal([Unknown tar format])]) +AC_MSG_CHECKING([how to create a $1 tar archive]) +# Loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' +_am_tools=${am_cv_prog_tar_$1-$_am_tools} +# Do not fold the above two line into one, because Tru64 sh and +# Solaris sh will not grok spaces in the rhs of `-'. +for _am_tool in $_am_tools +do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; + do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi +done +rm -rf conftest.dir + +AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) +AC_MSG_RESULT([$am_cv_prog_tar_$1])]) +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) # _AM_PROG_TAR + +m4_include([acinclude.m4]) diff --git a/branches/fceux-2.2.2/attic/authors b/branches/fceux-2.2.2/attic/authors new file mode 100644 index 00000000..f4220e5a --- /dev/null +++ b/branches/fceux-2.2.2/attic/authors @@ -0,0 +1,30 @@ +A list of people who have contributed code to FCE Ultra follows. +Please note that the "Code Contributions" field may not be all inclusive; +the coder may have done more than what is listed. + +Name/Alias Code Contributions Contact Information +------------------------------------------------------------------------------ +Aaron Oneal Many changes to compile http://www.morphgear.com + with MSVC and first frame + skipping code. + +BERO Base FCE code. bero@geocities.co.jp + +CaH4e3 Some mapper code. CaH4e3 at mail dot ru + +\Firebug\ VGA register setting code. ?? + +Joe Nahmias man pages. + +LULU SDL network play code. ?? + +Paul Various code for the official kuliniew@purdue.edu + Kuliniewicz SDL port. + +Quietust VRC7 "translation" code. quietust@ircN.org + +Tatsuyuki OPL2 emulator. ?? + Satoh + +Xodnizel Most of the FCE Ultra code. http://xodnizel.net/ + diff --git a/branches/fceux-2.2.2/attic/changelog b/branches/fceux-2.2.2/attic/changelog new file mode 100644 index 00000000..359eee9a --- /dev/null +++ b/branches/fceux-2.2.2/attic/changelog @@ -0,0 +1,1674 @@ +November 12, 2003 - 0.97.5 Release + + Windows: Added limited support for arguments that change configuration + to be passed to FCE Ultra. Example: fceu -pal 1 c:\streetgangs.nes + It may be useful in frontends. + + Fixed filename generation for automatic IPS patching when a file + with no extension is loaded. Before this change, FCEU would + look for "game..ips" with a file named "game". + + Converted and updated the cheat guide in(to) HTML. + + Added support for iNES mappers 202,203,231 from info from cah4e3. + Fixed support for mappers 60, 200. + + Fixed various major bugs in the breakpoint deletion code. + + UN*X: Added support for OSS(/dev/dsp) devices that don't support mono + sound. + + Increased PPU startup idle time to 2 frames. Fixes that + unlicensed "Earthworm Jim 3" game. Does it break anything? + +November 9, 2003 - 0.97.4 Release + + Fixed another obscure PPU emulation screen corruption bug. + + Added support for Game Genie cheats in the cheat interface. + + Windows: Reworked the cheat interface, merging the cheat search + and cheat list windows into one. + + Windows: Greatly improved the CPU debugger. + The code still needs a lot of cleaning, though. + + Readjusted VRC6 IRQ emulation timing. + + Added support for the UNIF MMC3 board TEROM. The maximum PRG/CHR sizes + may not be correct in this implementation, though. + +November 8, 2003 - 0.97.3 Release + + Added a control to set the highest quality sound mode in Windows. + This change requires that any users who previously set + "high quality sound" to set it again. + + Fixed the volume of high-quality sound mode again. The changes + I made earlier didn't affect all the filter coefficients. + +November 8, 2003 - 0.97.2 Release + + Made a minor optimization to writes to palette memory. + + Altered VRC6 IRQ emulation timing slightly. + + Fixed a weirdo PPU emulation bug that could cause garbage on the right + side of the screen in certain situations. Thanks to FrenziedPanda for + bugging me enough to make me look into the problem and fix it. + I should be on the lookout to see if the fix breaks anything, though. + + Fixed the volume of high-quality sound mode(-soundq 1). It was + at 1/4 the volume it should have been. I compensated by increasing + the precision of the filter coefficients, which increased the sound + quality of that mode slightly without hurting performance. + +November 7, 2003 - 0.97.1 Release + + Fixed mapper 105 emulation. I had begun merging it into the + rest of the MMC1 code for 0.97, but I hadn't finished it. + + Changed things like RdMem(_PC++); to RdMem(_PC); _PC++; + Darn evil global variables. I need to fix them. Screw speed. + + Expanded checks for the global variable "fceuindbg"(used in debug + mode to prevent reads in the debugger from altering any registers). + +November 6, 2003 - 0.97 Release + * Note: I still had much more I had wanted to get done for 0.97, + but I lost even more interest. The Windows port still doesn't + have a way to enable the "highest" sound emulation mode, nor the + low pass filter code, not to mention that the lowpass filter code + isn't complete(I would need to design a high-order FIR filter from an IIR + filter to work properly-have the correct rolloff, among other + things-at finite playback rates). + + Fixed a bug in the IPS patcher. The recorded size wasn't being updated + after a successful realloc() was made, which could lead to corrupted patch + data from some patches. + + Added support for mappers 200, 201 from submitted code. + + Rewrote mapper 15 support to make more sense(well, depending + on your point of view...). + + Fixed 256KB CHR select support for mapper 115. + + Added support for mapper 12 from code from cah4e3. + +October 16, 2003 - Snapshot + + Fixed support for mapper 245(for nonencrypted/non-smynes-screwed up + ROM images only. Fixes "Yong Zhe Dou E Long [...] Dragon Quest 7". + + Added support for mappers 60, 62, 230, 244 from submitted code. + + Modified mapper 90 emulation to allow game-select on reset + for "Final Fight 3". + + Modified mapper 45 emulation to allow "Super 8-in-1" to work. + + Added a low-pass filter, and an option to enable it(CLI ports). + + 0x00 is now written to $4011 in the NSF player code instead of 0x40. + Fixed some other similar sound register init problems that I had fixed + in Festalon but forgot to fix in FCEU. Grrr. + + Removed some unnecessary 64-bit integer usage from FIR sound filtering + code. + + Added a new sound quality mode. Higher than high, it's highest(in + FCE Ultra, for now). Still need to fix the interface to allow + enabling it in the Windows port. + + Added some code for lower-level MMC3 IRQ emulation. It isn't completed + , and will not work properly as-is. I'm still playing around with + it occasionally. + + Fixed the sprite overflow flag(I think I fixed it), that was broken in an earlier + pre-0.97 release. + + Fixed support for iNES mapper 193. + + Command line arguments "-pal" and "-gg" now take extra arguments(1/0) + and are remembered in the configuration file. + +September 27, 2003 - Snapshot + + Added support for iNES mapper 50. + + Modified the UNIF board initialization code. Hopefully, this + new interface will eventually be used with the iNES code. + + Miscellaneous code cleanups. + + /dev/dsp is now set to 8(previously 9) buffers of 128 samples in length + in the SDL code. + + Tried to make the save state code more expandable and modular. + + Moved a lot of the PPU code into ppu.c. + + Added more extensive debugging code to the 6502 emulator, to allow + for memory read/write hooks(including zero page addressing modes). + + Readadjusted DMC timings when PAL emulation is enabled. It looks + like it was correct before I had made the August 2 change. Thanks + to Bananmos for the information. I think. :/ + + Added support for iNES mapper 193 from information from virtuanes. + I think my dump of it is "bad", though. PRG and CHR pages look + like they are in the wrong order(logical vs physical? Who's to say + what's physical?). + +September 1, 2003 - Snapshot + + Fixed some minor initialization issues with iNES mappers 7 and 34. + + Added support for UNIF board NES-GNROM. + + Removed support for save states created with versions of FCE Ultra + less than 0.56. + + Replaced SDL sound buffering code with a lock-free FIFO implementation + written by David Olofson, with a few modifications by myself. + + Fixed a VRC7 NSF bug(it showed up under the reworked driver/file + loading order in the cli code). + + The board in "Rolling Thunder" has "RAMBO 1" on it, not "RAMBO-1". + +August 9, 2003 - Snapshot + + Removed the old plain text documentation and replaced it with + a new document in HTML. It is not completed yet, though. + + Rewrote the SDL-native audio code to be less wacky and more + thread-safe(hopefully). I'm still waiting for a new SDL audio + API... + + Altered the MMC5 IRQ timing. Fixes minor graphical glitches + in Castlevania 3. Does it break anything? + + Removed some debugging code that got into the last snapshot. + +August 5, 2003 - Snapshot + + Added some code in the IPS patcher to allow for expanding the size of files. + + Fixed a double free() bug with a mapper 51 game(in ines.c). + + Added support for "Alien Syndrome" (US release) as iNES mapper 158. + It looks like a derivative of the normal RAMBO-1 board(or is that + the name of the chip?), similar to TKSROM/TLSROM(mapper 118). + + Improved the "native" SDL sound code. It will now call SDL_Delay(), + among other nice things. The code could probably be improved more, + though. + + Added support for decimal components in xscale/yscale in the SDL + port. Set the default xscale for windowed mode to 2.40(to get a + more correct aspect ratio, assuming the display is currently at + a 4:3 aspect ratio). + + Modified args.c to handle floating-point numbers. + +August 2, 2003 - Snapshot. + + Disabled texture wrapping with OpenGL(there were problems at the edges + of the screen with linear interpolation). Bah. Now the edges + are too bright... + + Improved the accuracy of the DMC timing when PAL emulation is enabled. + I still don't think it's totally correct, though. + + Changed the default settings for the SDL code. Full screen + is now 640x480x8bpp by default, xscale and yscale are 2 for both full + screen and windowed, opengl support is enabled, linear interpolation + for OpenGL is enabled, and X-axis stretching is + enabled(in full screen). + + "Scanlines" were enabled in 8bpp to 8bpp blits in + drivers/common/vidblit.c when they shouldn't have been. Fixed. + + Fixed OpenGL code under big-endian platforms. + +August 1, 2003 - Snapshot. + + Various code clean-ups. + + Played around with adding a GTK+ GUI to the SDL code. + + Rewrote part of the hq sound rectangle wave code. + + Replaced the high-quality sound inline assembly filter code with + slightly faster C code. + + Hacked around with GP32 support. I don't know if the GP32 would + be fast enough, though. + + Skipped frames will now have D5 of $2002 set at the beginning + of the frame. Fixes "Bee 52". I must see if it breaks anything. + + Added OpenGL support to the SDL code. + + Removed the PPU drawing inline assembly code, replacing it with a faster + algorithm written in C. + + "Disabling" the 8-sprite limitation will no longer cause + "Bee 52" to break. However, the "Solstice" wizard will still + have the weird thing growing out of his face in the introduction, + since it depends on no more sprites to be rendered. + + Added entry for that Black Bass game for header corrections in + ines.c + + Strip color burst bit(D0 of $2001) is only "emulated" if bg or + sprite rendering are turned on, at the end of the scanline. + Doing it with pixel/tile granularity would require modifying + the sprite graphics data copying routine, which I don't + feel like doing. Fixes that crazy Sayoonara demo by Chris Covell. + I also modified the NES RAM initialization code. + + Adjusted VRC7 IRQ emulation for better Lagrange Point goodness. + + Added support for iNES mapper 91. (VirtuaNES) + +0.96: + Improved RAMBO-1(mapper 64) emulation. "Skull and Crossbones" is + now playable. + +0.95: + + timestamp and timestampbase are no longer saved/loaded to/from + save states. They were causing too many problems I didn't + want to fix, and I never intended them to be saved in save states + when I wrote the code that uses them. + I think the reason they were being saved was that I wanted to make it + possible to add movie support and network play save state loading + (distributing the save state over the network). So if someone in + the future wants to add these features, the issues(primarily with + zapper emulation and sound emulation) with saving the time stamp will + need to be resolved. + + Fixed some crashing bugs when save states are loaded when + high-quality sound emulation is enabled. It is like patching + holes in a swiss-cheese boat. All the holes may be patched, but + it looks ugly. At least it tastes good... + TODO: Look into saving more data in the save states, especially + data that is based off of "timestamp" and "timestampbase". Also + look into validating this data. Right now, corrupt save state data + might cause memory corruption in FCE Ultra. + + Fixed some bugs in the NSF player. + + Cleaned up more code. + + Reduced the usage of TriggerIRQ(). + + Split the palette code into a new file, palette.c, from svga.c + + Low-G-Man(NTSC and PAL versions) are now recognized by CRC32 value, + and WRAM will be disabled if they are loaded. A warning/status message + will also be printed regarding this issue. + + Decreased the volume of the DMC/PCM channel in low-quality sound + emulation. + + Low-quality sound emulation now uses 32-bit integers for much + better speed. + + FCEUI_CRC32() wasn't returning anything. D'oh. Fixed. + + Added somewhat crude support for games that switch background CHR data + mid-scanline (this is needed in games such as Mother, Pirates!, + Business Wars, and Marble Madness). + + Altered NMI, IRQ, and BRK emulation again. Fixes some games, + like Bases Loaded 2 and Dynamite Bowling, and maybe some others. + I had to increase the size of the IRQlow variable for delayed + NMI execution... I also had to add a delay between PPU reset + and the PPU actually doing anything, to fix "Knight Rider". + + Fixed a mapper 90 save state bug. + + /dev/dsp code now searches for /dev/dsp before /dev/dspX (where X is + a non-negative integer). + + SDL joystick axes configuration is now done from the joystick. + + Tweaked various Konami mappers' IRQ counter emulation. + + Added custom SDL throttle code that gives up time slices instead of + using 100% cpu. + + Fixed an issue with sprite priorities on MSB-first platforms. + + Modified powerpad.c to avoid a symbol conflict when compiling on the + Power PC architecture. + +0.94r3: + sound.c: + Fixed a divide-by-zero bug that occurred when a virtual + reset(like by pressing F10) occurred when sound emulation was + disabled. + +0.94r2: + drivers/common/vidblit.c: + Fixed code for 32bpp blur effect. + + drivers/cli/sdl-video.c: + Added error message for unsupported bit depths. + + mappers/simple.c, ines.c: + Used this bug fix pseudo-release as an excuse to add + support for mapper 107. Information taken from virtuanes. + +0.94(fixed release) +--- + Fixed call to InitUNIXDSPSound in svgalib.c + + Added man pages. + +0.94 +--- + Added support for rapid fire A/B buttons on physical joysticks + in SDL/svgalib/DOS code. + + Implemented "high-quality" Namco 106 emulation(used for hq sound mode). + In this case, "high-quality" means sounding more like it should, + not necessarily cleaner. I'm not certain that it's totally correct, + but it's in the right direction. + + RAM cheats should no longer affect Game Genie emulation. I still + need to completely verify this. There may be some sort of race + condition. + + Removed various minor speed hacks in the name of style and + correctness(and to make maintaining FCE Ultra easier for those + people who are not me). :) + + Removed NSF cpu hacks, as I changed code to make them unnecessary. + + Fixed another FDS IRQ emulation bug. "Famicom Grand Prix II" works + now. + + Fixed a memory leak and a heap corruption bug in "file.c". + + Added support for on-the-fly IPS patching. + Place the IPS file in the same directory as the file to load, + and name it filename.ips. + + Examples: Boat.nes - Boat.nes.ips + Boat.zip - Boat.zip.ips + Boat.nes.gz - Boat.nes.gz.ips + Boat - Boat.ips + + Some operating systems and environments will hide file extensions. + Keep this in mind if you are having trouble. + + Patching is supported for all supported formats(iNES, FDS, UNIF, and + NSF), but it will probably only be useful for the iNES format. It + can be used with the FDS format, but be warned that it will permanently + patch your disk image, as the disk image is written back to disk + when the game is unloaded(unless the disk image is in a zip file, in + which case it isn't written back to disk). UNIF files can't be + patched well with the IPS format because they are chunk-based with no + fixed offsets. Support for a UNIF patching format may be added + in the future(probably by someone else.). + + Added more games to the list in ines.c for having battery-backed + WRAM, for header corrections. + + Copied over the 96KHz filter coefficients from Festalon that I forgot + to do in 0.92. Oops. + + +0.93 +--- + + Reduced the volume of the FDS sound channel. + + Fixed a bug in the FDS IRQ emulation code that caused "Lutter" to not work. + + Fixed a bug in unif.c that would cause a crash if a unif file were + loaded without a board name being specified(as could happen + with a corrupted nsf). + + Fixed a bug in general.c relating to relative filenames(running + fce ultra like "./fceu ../big.nes" would work, but "./fceu ../big" + would not work- it crashed). + + + +0.92r2 +--- + Fixed dpcm irq bug that broke Cobra Triangle. + +.92 +--- + + Removed NSF player background, and added some special effects goodies. + + Changed the NSF player to use the emulated gamepad as input instead + of having special NSF-player-only keys. + + Added support for mapper 249(using nonencrypted games), thanks to SARO + for info. SMYNES sucks. + + Updated video blitting library-thing(vidblit.c) with more special + effects, and removed 24bpp support. + + SDL cleanupification. + + Added support for mapper 61. + + nnnesterj: Added support for mapper 57. + + Fixed mapper number for "Golden Game 150 in 1". Changed it to 235 + from 43. + + DDraw back buffer surfaces are now created in system memory if the + hardware blitter can't do stretching. + + Restructured file wrapping code. + + Added new cheat search methods. + + Fixed a major cheat unloading memory bug(and memory leak). + + Emulated that funky nonlinear DAC effect for hi-quality sound. + + More fixes/cleanups to FDS emulation code. + + Tweaked PPU timing a bit. + + Improved network play. + + Holding the enter key down will no longer do fun stuff to the nsf + player. + + Improved NSF player. It should support streaming pcm nsfs now... + + Changed FDS keyboard keys around a bit. F6 is the disk select key, + and F8 is the disk insert/eject key. + F8 to insert VS Unisystem coin, F6 to view/toggle dip switches. + Hopefully people won't complain after blindly hitting the save state + buttons. :) + + Many fixes and improvements to the Windows port. No more cpu-consuming + wait loops(specifically, sound). Added a message window. + + FDS sound emulation improvements. + + FDS disks are now auto-inserted on power on(or was it loading a new + game...). + + Changed the default last rendered scanline to 231. + + ines header corrections are now printed as status messages, not errors. + + Rearranged input updating code. + + Fixed a sprite transfer bug. Fixes PAL version of Rainbow Islands. + + Debugger hooks added. + + Small optimizations in Refreshline and FetchSpriteData to hopefully + offset the slight slowdown in the cpu core. + + MapperHBIRQHook is now called differently(depending on hi/low bg/spr + addresses). + + Added support for unif board UNL-8237. + + Added support for mapper 144(death race). + + Added partial support for mapper 74. + + Fixed a cpu emulation bug in GETIYWR. It would sometimes set "target" + to 0x10000, which was a BAD THING(overflow; now it wraps). + + Tried to add support for mapper 241. Needs special keyboard emulation. + I think. + + Internal RAM is now initialized to something other than 0. Fixes + Minna no Taabou no Nakayoshi Dai Sakusen. + + Reassigned "The Money Game" to mapper 155. It doesn't seem to + respect the WRAM enable/disable bits. Silly game. And + Tatakae!! Rahmen Man. + + Added support for mapper 115(still needs 256KB CHR select), 241, 114,88. + + Attempted to add support for mappers 91, 187. + + Modified frame IRQ to not break so many damn games. + + Fixed sprite hit detection loop. + + Improved support for mappers 80, 90,117,154, 189. + nnnester and virtuanes. + + Reassigned "Devil Man" to mapper 154. + + Removed bogus Trojan header fix in ines.c. + + + +.81-post: +---- + Fixed/Worked around(?) compilation problems on gcc 3.2.x. + +.81: +---- + + More SDL goodies. + + Renamed "Makefile.olinuxsdl" to "Makefile.unixsdl" + + More SDL fixes and cleanups. + + BeOS port is now compiled with the "-no-fpic" flag, which allows + me to use my inline assembly. The executable work fine as far as + I can tell. + + Added "Makefile.beos". gcc doesn't like my inline assembly + used in RefreshLine(),so this port will likely be slightly slower than + other x86 ports. + + Added a check to make sure SIGBUS is not equal to SIGSEGV in + drivers/cli/main.c. Needed for compiling under BeOS. + + Renamed the "PI" member of the X6502 structure due to conflicts with + a defined symbol with some math header files. + + Merged fcelineasm.h into fceline.h + + Fixed(possibly) a possible problem in fcelineasm.h with input register + clobbering. + + More SDL changes. + + Added speed throttling code to the CLI code, and added a command + line switch "-nothrottle". + + Lots of restructuring/rewriting/merging of the MMC3 code. + + Updated DOS code to use the generic CLI wrapper. + + Reads from $4090 and $4092 now return the current envelope setting + in FDS sound emulation. I'm not sure if this is correct... Affects + "Ai Senshi Nicole" and "Bio Miracle Bokutte Upa". + + Added native SDL sound support to the SDL code. the "olinuxsdl" + now uses this code by default instead of the unixdsp sound code. + + Modified MMC3 IRQ counter emulation. I'll need to watch out to see + if it breaks any games. Fixes: MegaMan 3, Gun Nac, Klax(Japanese). + + Changed a few memory reads in x6502.c to use RdRAM instead of RdMem, + resulting in a slight speed increase. + + Cleaned up mapper 250 emulation code. + + Added support for iNES mapper 51(thanks to Kevin Horton for the + information). + + Merged some iNES mappers corresponding to bootleg multicarts + based on MMC3s with mbshare/mmc3.c. + + Added support for iNES mapper 52(thanks to Kevin Horton for the + information). + + Made some hacks to the MMC3 emulation code so that I can add support + for pirate MMC3 multicarts more easily. I should clean it up later. + Moved mapper 44 emulation code to mbshare/mmc3.c. + + Saving screen snapshots will no longer corrupt the frame buffer + for one frame(unless memory couldn't be allocated). + + Fixed screen snapshot saving(it was sort of broken due to the + changes made to the driver<->emulator interface code; status + messages were being saved to the image). FCEUI_SaveSnapshot() + no longer returns a value(the request to save a screen snapshot is + serviced before status information would be written in the next frame). + + nosprites is now set to 0 before RefreshSprite() returns, to prevent + problems if a game turns off the bg and sprites when FetchSpriteData() + for the next scanline is called but then turns on sprites when + the actual scanline is drawn. + + PPU_hook() is now called more often if PPU_hook is non-null. + Made changes to mappers 118, 95, 9, and 10 to compensate. + No games seem to be broken, and I added support for mapper 96 + (though the games aren't very playable because the special controller + isn't emulated). + + Romance of the 3 Kingdoms is now recognized to use 16KB ex-WRAM. + + Added support for mapper 185...sort of. I think this is another + instance of incompatible hardware being lumped onto one mapper number. + Sigh. + + Added support for "Famicom Jump 2" as iNES mapper 153. + If a good(as far as I can tell) dump is loaded, FCE Ultra will + automatically fix the mapper number. + I also made some changes to the mapper 16 IRQ emulation code. + + BRK now sets the I flag. + + Reads from $4015 no longer reset DPCM IRQ. + + Changed emulation of RTI instruction slightly. + + X.IRQlow is now set to 0 in PowerNES(). + + The VS Unisystem bit in the iNES header is no longer looked at( + I was having too many problems with this bit being set when it + shouldn't have been). Now, VS Unisystem emulation is enabled + when a known VS Unisystem game is loaded. I also rewrote the VS + Unisystem detection function. + + iNES mapper 1 now supports pageable CHR RAM if no CHR ROM is present. + Fixes "Family School". + + Mapper 70 no longer has a mirroring control emulated, and I extended + the number of 8KB CHR pages supported to 16. + + Cleaned up iNES MMC5 save RAM loading/saving code and added + support for MMC1 games with 16KB of RAM(the second 8KB are saved), + via CRC32s(currently only Genghis Khan(USA) and Nobunaga's Ambition( + USA and Japan) are recognized). + + Added support for the MMC5 Koei game "Ishin no Arashi", in the iNES + format(I added an entry with its CRC32 value and the number of 8KB + WRAM banks it needs). + + Better iNES mapper 33/48 IRQ counter emulation. + + Added the game "Uchuusen - Cosmo Carrier" to this list. I'm + beginning to hate the iNES format more and more...or maybe + just Fanwen. :) + + Added the mapper 32 game "Major League" to the list of games + that usually need iNES header correction...but in this case, the + iNES header cannot specify that this game needs to have one-screen + mirroring. + + iNES header information is now printed before any header corrections + are made based on a database. + + Fixed a bug in mapper 32 emulation. "Ai Sensei no Oshiete" + works now. + + Tried to add support for iNES mappers 245 and 249. + + Fixed the MMC5 read handler to return the data last on the data + bus instead of 0xFF when a read was made to an unmapped address. + This seems to fix the lockup problems in "Bandit Kings of Ancient + China". + + Reversed "Modified the time at which the "y scroll" register is updated + during hblank." The changes broke Klax. + + Added an unsigned 64-bit base timestamp variable "timestampbase". + Adding this to the 32-bit variable "timestamp" will return + the number of cycles executed since emulation started(in the future + I'll probably change it to since reset or power toggle). + This allowed me to replace "lastn" hack in the MMC1 code with + something better. + + Changed my mind and undid the removal of support for old save states. + + Removed support for old save states and in general I won't + try to support save states made with previous versions. + + MMC1: Writes to $8000-$FFFF with D7 set will now cause + the first MMC1 register to be OR'ed with 0x0C. I'm not sure + if this is correct, but it doesn't seem to break anything + and it fixes Robocop 3. I'll see if anyone reports games + not working in .81 that worked in .80. + + Worked on a generic driver interface wrapper very similar + to the driver interface FCE Ultra used to use(I'm getting + tired of all of the duplicated driver code). Eventually, + the DOS, SVGAlib, and SDL ports will use this wrapper. + + Similar change to the argument parsing code. + + Changed configuration file saving-loading routines and the + configuration structure to allow for linking config structures + to each other). + + Small fix to the emulation of the MMC5 split screen mode. + + Made Linux SDL code compilable again. + + Changes to MMC5 EXRAM emulation(read/write). + + Fixes to the emulation of the MMC5's split screen mode, based on + observations while using CastleVania 3 and a Game Genie(on a real + NES). + + Fixed a bug in ines.c that caused any calls to AddExState() from + a mapper initialization function to be effectively "erased"(ResetExState() + was called after the mapper was initialized). Fixes the VRC7 sound + state saving/loading stuff. + + Finished adding support for the MMC5's split screen mode(this does + not mean that the support is complete, but at least the intro in + "Uchuu Keibitai SDF" works correctly now). + + Worked on adding support for the MMC5's split screen mode. Not + completed. + + Reverted to .80's FDS sound code. + + Modified the time at which the "y scroll" register is updated + during hblank. + + NSF playing code will now disable FDS sound output on song init + (fixes some problems with the Zelda no Densetsu NSF rip). + + Increased the emulated clock speed of the FDS sound emulation code + to give better quality output. + + Modified NMI to occur a few cycles later. Fixes BattleToads...but + it may have broken other games. Also modified the way NMI's are + handled in x6502.c. + + Modified ines.c to memset() GameMemBlock to 0 on virtual power toggle. + Also, trainers are now loaded into their own buffer instead of + directly into emulated WRAM and copied into emulated WRAM on + power toggle; I've been meaning to do this for quite some time. + + Changes to the way the zapper cursor is drawn on the screen. + + FCEUD_WriteSoundData(), FCEUD_BlitScreen(), and FCEUD_UpdateInput() + have been combined into one function: FCEUD_Update(). + + More fixes to the network play code, and a fix to the Windows network + play driver code that fixes(hopefully) a rather evil bug that caused + lockups when the remote stopped network play. + + Added code to set the battery-backed bit in RAM if a game needs it, + based on CRC32. + + Added more games to the list of games that commonly have bad iNES + headers, in ines.c + + Updated docs and usage.h for DOS and Linux regarding the new video + mode and the new refresh rates. + + Linux: Fixed a bug with video mode 6(a few upper scanlines were being + cut off). Increased the refresh rate of video mode 3 to 120hz. + + Increased the refresh rate of video mode 2 to 65 hz in the Linux port. + + Screen snapshots can now be taken while playing an NSF. + + Added a new sexy tweaked vga mode that I created to the Linux svgalib + port. It's 256x224 at a refresh rate of 103hz. Hopefully it won't + blow up anyone's monitor. ;) + DOS port will follow eventually. + + Modified Makefile.base to produce an executable named "fceu" instead + of "fce". + + The plans(cycle-accurate ppu emulation) for .90 were a bit ambitious, + and I still need to make other fixes before then. + + Fixed some minor(usually) bugs with setting 256x240 tweaked VGA mode + in DOS and Linux ports. + +.80: +---- + + Cleaned/fixed a few things in the mapper 19 emulation code. + Family Circuit '91 still doesn't work quite right... I wonder if + it's a bad dump. + + Added input override code to Windows port. + + Added code to fix iNES header information in RAM and suggest + changes to the user. + + Added support for iNES mapper 152(to be used with games set to + mapper 70, that use one-screen mirroring instead of h/v mirroring). + + Blits using the DirectX blitting function(method?) to the primary + surface are now done with the asynchronous flag set(if that + fails, a "normal" blit is tried). + + The DirectX blit buffer(secondary surface that FCE Ultra writes to + directly and then uses the DirectDraw blit function on to blit + to the primary buffer) is now created without specifying it + should be in system memory or video memory, except in the case + when no hardware blitting is available, and then DDraw is explicitly + told to create the surface in system memory. + + Added Family Keyboard support to the DOS port. + + Cleaned up the VRC7 sound emulation code. I need to find a way + to save the current sound state in a save state. + + Found out the real name of the "Space Shadow" gun; it's + called the "Hyper Shot". I'm still not sure who made it, though. + Possibly Bandai did. The interesting thing is that Konami + also made a Famicom accessory(dual square boxy things with two buttons + on each) with the same name(though there might not be a space in the + name). + + Only the upper two bits read from $4016/$4017 are undefined. + Bit5 is always 0, though. Fixed the bug in "input.c". + Silly kevtris' old documents. New kevtris' brain is always good. + + Family Keyboard support for the Windows port. + + Added support for the Family Basic Keyboard to the Linux port, other + ports todo. + Might want to add support for the tape recorder at some time. + Also mapped the "Scroll Lock" key to disable/enable command keys + so that the FBK is more useable. It doesn't disable CTRL C, + though... + + Changed a lot of inlined functions in x6502.c to macros so that + I could test out some optimization ideas. + + DOS code updates for game input override support. + + Small optimzation to opcode $4c, and relative jumps. + + Added some code to ines.c to set controller information in + FCEUGameInfo(returned by FCEUI_LoadGame()) based on crc32 values. + + Updated user documentation and usage.h for DOS and SVGAlib input + command-line changes. + + Added an option to disable the four-score(to Windows and Linux ports + so far). + + Updated Windows interface to support the new Famicom expansion + devices. + + (Re)Added support for the Famicom 4-player device. + + Improved Zapper emulation...sort of. It still needs a lot of work. :/ + + Added *partial* support for the "Space Shadow" gun. + + Added support for the Arkanoid controller(both NES and Famicom style). + + Added code to support the extension Famicom input devices. + + Added PAL scanline start/end drawing settings to Windows port. + + Added pause emulation key(F2) to Windows port. + + In the process of rewriting/fixing up input code stuff. + + Minor bug fix to Power Pad emulation code. + + VS Hogan's Alley and VS Duck Hunt automatically select the zapper + now(though it only works on the SVGAlib port). + + Undid some FDS sound code changes introduced in 0.76 that totally + screwed up sound. Oops. + + Added code to allow different settings for first/last scanline + drawn while in PAL emulation mode, to the Linux and DOS ports. + + Added convenience(it's not necessary, but it reduces redundant and + confusing code in the driver code) function + FCEUI_GetCurrentVidSystem(int *slstart, int *slend). + + Updated file "TODO". + + Changed #include to #include "zlib/unzip.h" + in file.c. + + NSF 6502 player now initialized the stack pointer on reset. + + Worked on de-emphasis emulation code quite a bit. + The deemphasized palette calculated at the end of the frame is now + based on what deemphasis bits were set for the longest during + the screen(sampling interval is a scanline) update loop. + Added a "static" deemphasized palette at $40-$7F in the palette table. + This corresponds to the colors when all of the deemphasis bits are set. + I did this to fix the PAL game "Noah's Ark", without breaking + anything else. The only downside is a slight speed loss(~2% on + my system when sound is disabled), but this is acceptable to me, + at least. + Maybe it's time to write hi/true-color ppu drawing code... + + + Fixed an out of bounds array access in svga.c in SetNESDeemph(). + The variable "lastd" in svga.c was being initialized to the wrong value. + Thanks to "Jarod CANAL" for pointing this out. + + Removed FCEUI_SetFirstRenderedLine or whatever it was called and + the function to set the last line. Replaced with: + void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); + + Changed SetVidSys(int w) to ResetVidSys() in fce.c. Reenabled + PAL/NTSC emulation overrides based on game loaded(really only useful + for NSFs and UNIFs now). + + UNIF loading code now recognizes the chunk "CTRL" and tries + to use it. Only the svgalib code supports overriding of input + settings based on game loaded, now, though... + The user is still going to have to configure powerpad settings + on his/her own. + + Fixed return values of FCEU_fseek() and fixed a problem in unif.c + related to it. + + Changed mechanism for how FCE Ultra tells the driver + code what type of system is being emulated. A structure of + type "FCEUGI" is returned from FCEUI_LoadGame(). + + Fixed a major mapper 64 emulation bug introduced in 0.76. + + Modified BlitVidHi() in drivers/win/video.c to speed it up. + + Added support for loading the iNES-format Game Genie ROM image. + + Removed ggrom.h and added code to load the Game Genie ROM + image from a file. + + Added Windows netplay.c. (new: the user exiting the emulator + while stuck in a blocking recv() or send() loop now works.) + + Fixed a vram address register bug in fce.c that I created when I got + rid of the pair/dpair data types. + + Added new mappers/92.c + + Removed mappers/92.c until I can contact LULU or rewrite it. + + drivers/win changes. Removed netplay.c until I can rewrite it. + + Got rid of pair/dpair data types. + + Got rid of silly "TempArray" thing. + + Began adding GPL headers to files. FCE Ultra is going to be in + a state of legal limbo for the next few days... + + Replaced crc32.c and crc32.h, and added some #ifdef's and #defines + to use the crc32 code in zlib instead if zlib is linked with + FCE Ultra. + + More fixes to sb.c. + + Cleaned up drawing.h and ggrom.h(even though ggrom.h will *probably* + be removed before the next release). + + Redid frameskip code. + + Rewrote necessary pieces of sb.c and sb.h and fixed quite a few + bugs. I still need to test it on various other sound cards, though. + + Rewrote(more like "recreated in my own image") DOS keyboard driver. + Removed unused "keyscan.h" from drivers/svgalib + + Rewrote part of(the parts that Marat wrote - the connection and + closing parts) the Linux TCP/IP network play code. I guess it works, + but I haven't tested it very much. In any case, it's still dangerous + to use network play in FCE Ultra with SVGAlib, since recv() or send() + might block and since the keyboard is in raw mode, you have a problem. + Maybe a future SVGAlib will fix the general problem of lockups if + keyboard_update() isn't called, though it is only partly SVGAlib's + problem... + + Fixed FCEU_fseek() when used with a compressed file in the PKZIP + format that has been loaded. Fixes a UNIF loading problem. + Also added a check to the return value of FCEU_fseek() in unif.c. + + Replaced Marat's 6502 emulation core with my own. + It should be fully functional, but as always, I don't know if + I implemented the undocumented instructions correctly. + Several things are correct in this new core that were not in + Marat's(D flag is no longer cleared by interrupts, for example). + + Altered mapper 16 irq counter emulation slightly. + + Fixed the behavior of the SXA, SYA, and XAS opcodes based on the + documentation I have. I'm not sure what happens when page crossing + occurs with those instructions on a real NES, though. + Also CHANGED(not fixed) emulation of opcode $8B("XAA"). + + Changed some of the M* functions(absolute indexed and maybe some others) + to perform dummy reads. + + Changed some of the macros in m6502.c to inlined functions so + that I can modify and examine them more easily. + +.77: +---- + + Fixed a silly network play bug(in the global network play code) + that caused excessive lag. + + Added a "niceness" setting to the sound configuration dialog. + Removed obsolete information from the dialog. + + Fixed speed throttling code in Windows port when PAL emulation is + disabled/enabled and a new game hasn't been loaded yet. + + Commented out a printf() to debug stuff in fds.c(oops). + + Applied PK's joystick patch to the osdl code. It allows the user + to map axes and it fixes a joystick button mapping configuration saving + bug. + + Added two command line options new to Linux port to DOS port. + Just need to test them... + + Added some stuff to unif.c to allow for boards that can support + CHR RAM instead of CHR ROM(darn Sachen boards...). Fixes UNIF + version of "Q-Boy". + + Added command line option "-snapname" to Linux port. I'll add it + to the Windows port as well, but probably not to the DOS port. + + Added clip option to Linux port. + + Fixed sound logging(in Windows port) so that multiple recording + sessions now work. + + Added an option to clip the leftmost and rightmost 8 columns + of graphics in the Windows port. + + Added a submenu that lists recently opened files, in the Windows + port. + +.76: +---- + + Updated porting.txt. + + Added speed throttling code to Windows port that's used when sound is + disabled(and an option in the "Miscellaneous" + configuration window to disable it). + + Added cheat interface to DOS build. + + A few tweaks to the text cheat interface code in the cheat listing code. + Added a command to quickly toggle the status of the cheat(though a + cheat can still be disabled/enabled by (M)odifying the cheat). + + Support for UNIF UNL-TC-U01-1.5M board added. Same credits as below. + + Rewrote mapper 228 code just for the heck of it(actually, I couldn't + figure out why some(about two) of the games in the Action 52 cart + weren't working in .75(and .76). I traced it back to .71, where an apparent bug in + the undocumented 6502 opcode emulation allowed it to work, which + was later fixed for the .72 release(opcode 0x7C)). I'm thinking + that the dump is bad... + + Added a few crc32 checks to ines.c to check for and report when + a known(by me) bad(hacked or bad dump) game is loaded. + + Added support for the following UNIF boards. Thanks to Quietust + and Kevin Horton for the information. Some problems still exist + with a few games that use these boards, though... + + UNL-Sachen-8259B + UNL-Sachen-8259A + UNL-Sachen-74LS374N + UNL-SA-016-1M + UNL-SA-72007 + UNL-SA-72008 + UNL-SA-0036 + UNL-SA-0037 + + Fixes to some stuff in cart.c(for example, calling setprg32() when + only 16kb of prg data is present now works). + + Added support for iNES mapper 189. + + Tried to add support for the UNIF board "UNL-H2288". Failed. + + Updated "cheat.txt" to fix a few typos and added an example of finding + and adding a cheat using the Linux port's text interface. The actual + section on the Linux cheat interface still needs to be written, however. + + Changed network play code in the Windows port and fixed a bug. + Fixed a similar bug in the Linux netplay code....sort of. + + A few cosmetic changes to the dialogs in the Windows port. + + Fixed sound initialization on the Windows port(it was being initialized + when FCE Ultra started even if it was disabled by the user. Oops.). + + Joystick button configuration code in Windows port changed slightly + to be more useable. + + Changed reference to video mode 5 in the linux port to "1 per 4". + It may not be very meaningful, but it is certainly better + than "TV Emulation". I'll change the Windows port reference later. + + Documented video mode 7(320x240) for the Linux port. Also added + a check for the FBDev driver in order to use this mode instead + of a tweaked vga mode if that driver is being used. + + Added/Fixed cheat interface for Linux port. It's still not perfect, + though. The code is ugly... + + Callback function for FCEUI_ListCheats() now receives + status information(enabled/disabled). + + Callback functions for cheat functions now must return 0 to + stop listing cheats or 1 to continue. + + Fixed a problem(the cheat code was reading in cheats + for address $0000 from cheat files if any blank lines were present). + + SDL port zlib changes(linked dynamically to zlib now). + + More changes to envelope decay + looping on code. No longer + depends on value @ $4017. It now sounds correct based on some + tests I did with SMB3 and a GG, but Goonies 2 doesn't sound right( + based on a sound file sent to me by another person). + + Added support for iNES mapper 140. Thanks to Quietust for the + information. + + I need to figure out how to deal with the problem of so many + bad NSFs that most people consider good... + + Changed envelope decays a bit. Their behavior now depends on bit + 7 of $4017. I don't know if this is right... + + Addition of debug.c for some debugging stuff. + + Updated zlib to 1.1.4. + + Modified code in various files to allow UNIF games to override + current selected video system emulation(NTSC or PAL). Need to + make sure this really works. + + Changed sound.c to prevent desynchronization during network play. + This might slow down sound emulation slightly, especially when + sound emulation is disabled. I really don't care... + + Updating network play code. More info later... + + Moved the sound/video/etc output code in EmLoop() to the top of the + for(;;) loop so that initialization prior to calling EmLoop() will + be the same as initialization done during a call to a FCEUD_* function. + + A few very small changes to sound emulation in fds.c. + + Changed unlink() to remove() in cheat.c and removed the including + of the header file unistd.h. + + Split up the cc=... statement in RefreshLine() to make it easier + to read and not ambiguous(to Borland's C compiler). + + Changed a lot of the function declarations in cheat.c. I'll need + to verify that cheat searching still works ok and that cheats still work + ok. I'll also need to update the Windows(and Linux console) cheat code + to prevent compiler warnings. + + Fixed various minor code problems(not minor if you want to use a + compiler besides gcc). This is an ongoing process... + + Removed bit fields after reading about and thinking about possible + portability problems, though I kept some optimizations in fceline.h + + Minor code simplification in drivers/win/joystick.c(replaced + "case 200 ... 207" and "case 208 ... 215". + + Modified some code to use bit-fields in the graphics rendering code + in fce.c and fceline.h. gcc seems to be able to optimize the new + code to run faster. + + Fixed m6502.c and fce.c to initialize variables on virtual power + toggle. This should fix network play on the Windows port. + I'm also in the process of cleaning up fce.c. + +.75: +---- + Fixed directories configuration stuff in Windows port(corresponds + to .75r2). + + More changes to square wave channel envelope/volume emulation... + Changes described in the large paragraph some lines down have been + abandoned. + + Added a command line switch to set the volume in the dos port. + + Changed Windows sound configuration dialog. Now buffer length is + specified in time, not samples. I also added a volume control. + + Reduced the volume on 8-bit sound output on all ports by 1/2. + + Added a function FCEUI_SetSoundVolume(). Added support for setting + the volume via the command line in the Linux port, other ports coming + soon. + + Changed FCEUD_WriteSoundData() again. No longer has a "Check" + argument. All clipping(ugh) is done internally now. + + Added a directories configuration dialog to the Windows port. I worked + on it too long and I became a zombie, so it might have a few bugs. + That's what guine...err...users are for. ;) Don't expect me to do + anything like this for any other port, though. I don't feel like + doing it on the DOS port, and the Linux and other UNIXy ports shouldn't + really need it. + + Made some changes to the rectangle/square wave channel emulation to + fix the pops in SMB. I have no idea if what I did is correct. To + be honest, I'm not sure I know EXACTLY what I did, but it's something + like this: Writes to $4003/$4007 now reset the duty cycle count + and reload the cycle counter with the current wavelength. Writes to + $4003/$4007 now do not update the amplitude output of the channels; they + will be updated after the cycle counter hits 0(or below). + + More information in iNES informational output. + + Minor changes to mappers/16.c. + + Increased the volume of the VRC6's sawtooth wave channel. + + Added more information to the RAM cheat guide. + + Changed the triangle wave generation code slightly. I decided + to remove support for the higher-frequency triangle waves, as they + are too cpu-costly to create and are probably not very audible on a + real NES anyway. + + Major changes to how sound is mixed. This necessitated a high pass + DC-offset removing filter, and a low-pass filter just to make things + sound better. ^_^ + Note: FCEUD_WriteSoundData() no longer needs to clear the waveform + data referenced by the passed pointer; it's done internally now. + + Fixed JMP ($xxxx) - now handles wrapping like it occurs on a real 6502 + (hopefully; I'm assuming that the same holds true for the NES' cpu). + + Added the ability to load a custom global palette in the DOS port. + + Fixed bug in drivers/common/unixdsp.c(wrong return value if sample + rate was out of range). + + Many sound fixes... - Frequency sweeps, length counter stuff,... + + Changed Windows port to use IDirectInput7 and IDirectInputDevice7 + interfaces. + + Fixed a Game Genie bug in the core emulation code. It only appeared + in the Windows port, though. (Enabling gg emulation, loading a game, + and then disabling gg emulation and loading a new game while in the + gg code entry screen would cause the new loaded game to not work + correctly). + + Modified windows port to use the config saving/loading stuff in + drivers/common/config.c + + Mapper 45 cleanups/fixes. + + Added the ability to load a custom global palette in the Linux port. + Yay. + + Fixed a large number of overcomplicated code and silly bugs in + drivers/common/config.c. This changes the format of the configuration + structure, too. Also added support for saving/loading strings with + automatic memory allocation when strings are loaded. + + Minor change in InitNetplay(). + + Fixed bad type conversions for pointers to functions and fixed + some bad declarations of functions. + + Reenabled zlib support for the sdl build. I need to pay attention + to patches that modify lines than don't fit on my screen. + + Fixed vidblit.c to not emit so many warnings when compiling. + +.74: +---- + + Stop sound in Windows port when user clicks l/m/r mouse buttons + in the non-client area of the window. + + Added "Drag and drop" file open support to Windows port. + + Various code cleanups. + + mappers/33.c optimization. + + Rewrote the function "FCEU_MakeFName()". + + Removed crc32.h from mappers directory. + + Modified some of the window resizing code in the Windows port. + + Added support for waiting for vblank/double buffering to the Windows + port. + + Added/Fixed support for iNES mapper 248. + + After an NSF file is loaded, information about its header is now + displayed. + + Fixed a typo in the Namco 106 extra ram handling code. + + Improved the quality of the Namco 106's extra sound channels. + - Thank Mamiya and Applepie(real name?) for info. + + When an NSF file is being played, FCE Ultra will no longer go through + its scanline rendering loop. This speeds up NSF playback considerably. + + Updated "porting.txt". + + Moved some stuff from DriverInterface() to their own functions. + + Fixed some iNES mapper 18 IRQ counter emulation bugs. "Ninja Jajamaru - + Ginga Dai Sakusen" now works. + + Rewrote large pieces of the mapper 64 code. "Skull and Crossbones" + still doesn't work, though. + + Changed format of iNES header information output, added "ROM CRC32" info. + + Modified the way cycle timing is done slightly. No change + for NTSC emulation, but PAL emulation is a little more accurate. + + Changed the behavior of indirect indexed(I hope I got that right ;)) + instructions to behave more like a real 6502(junk reads are now + performed). + + A few optimizations/cleanups in m6502.c. + +0.73 +---- + + * Fixed several bugs with sprite emulation. Several games(such + as "Trojan" and "VS Duck Hunt") that were broken in .71 and .72 now + work ok. + * Added support for iNES mapper 82. Thanks to those who work on + "unofficial nester". + * Added support for iNES mapper 250(used by "Time Diver Avenger"). + * Fixed the documentation to show that iNES mappers 48, 83, and 232 + are supported. + * Removed various pieces of stale code and fixed a few minor bugs. + * Fixed a triangle wave channel bug(the channel was sometimes enabled + when it shouldn't have been). + * Writing to $4010 with the upper bit clear now acknowledges the DPCM + IRQ. This appears to fix "Stunt Buggies". + * Rewrote pieces of the Zapper emulation code to be cleaner and more + accurate. + * Rewrote the VS Unisystem dip switch drawing code. + * Simplified the setting of VS Unisystem dip switches. The "V" key + now toggles viewing AND editing of dip switches. + +0.72 +---- + + * Various minor bug fixes. + * Various code cleanups and size and speed optimizations. + * Removed some (apparently) unused MMC5 sound emulation code. + * Changed the behavior of $2003 and $4014 to better simulate what occurs + in a real NES. + * Fixed a few bugs in the undocumented 6502 opcode emulation code. + The Game Genie code "NUTANT" for SMB 3 works correctly now, at + least(previously it caused the game to lock up at the end of levels). + * Rewrote large pieces of the 6502 memory fetching code, resulting + in a slight slowdown in the speed of emulation. Benefits include: + Game Genie emulation now works(again) and 6502 emulation is more + accurate. + * Added support for iNES mapper 72. Thanks to rinao for the information. + * Fixed support for iNES mapper 77(used by Napoleon Senki). + * Fixed/Added support for iNES mapper 226. Apparently I made a mistake + in the documentation. Thanks to Mark K. for the information. + * Added support for iNES mapper 227. Thanks to Mark K. for the + information. + * Added support for iNES mapper 234(used by the Maxi-15). Thanks + to Mark K. for the information. Note that many of the Maxi-15 + ROM images on the Internet have corrupt CHR data(graphics), or the + mapper number is set incorrectly(usually to 11). Use a utility to + fix the mapper number. + * Added support for the following UNIF boards(prefixes omitted): + - EKROM (and fixed the reference to "Gemfire" in the documentation). + - HKROM + * Added the ability to enable and disable individual RAM cheats. + * Fixed some problems with the cheat search code(the NES' internal + RAM was being searched differently than any external RAM, which + was being search incorrectly). + +0.71 +---- + + * Fixed a 6502 emulation bug that was causing some Koei games + (ex: Nobunaga's Ambition, Genghis Khan) to not work. + * Extensive PPU/CPU timing adjustments. + * Fixed support for iNES mapper 40. + * Added support for the following UNIF boards(prefixes omitted): + - ETROM + - ELROM + - EWROM + * Fixed a few bugs in the UNIF code. + * Added support for loading and saving cheat files and an interface + to search for/add/delete/list cheats(no interface yet on Linux/DOS). + * Fixed a few minor bugs in the Windows DX code. + * Command line options to control the number of sound fragments + and the fragment size have been added(Linux). + +0.70 +---- + + * Adjusted PPU/CPU timing. + * Removed(until I understand the problem) a hack to get one of the + games in the Caltron 6-in-1 to work. + * Fixed an MMC3 IRQ emulation bug("Project Q" works better now). + * Fixed a problem/misunderstanding regarding the upper scanline. + It can now be displayed again. + * More accurate sprite hit emulation(fixes the title screen of + "Ultimate Stuntman"). + * VRAM bank switching for iNES mapper 4 is now possible(and enabled + for all mapper 4 games without CHR ROM). Fixes "Tenchi o Kurau 2". + * Added support for the Famicom's four-player adapter and the ability + to enable it(it is disabled by default to prevent compatibility + problems). + * Added an option(under miscellaneous configuration) to automatically + open the "File Open" dialog box when FCE Ultra is started. + * Sound sampling rate is now configurable. + * Fixed some bugs in the DirectSound code. + * Joystick button configuration is a little more user friendly(and + stable, hopefully) (Linux). + +0.62 +---- + + * Added support for the Famicom Disk System's extra sound channel. + * Updated the version of Tatsuyuki Satoh's OPL2 emulator used in + FCE Ultra from .36f to .37a. The sound quality in "Lagrange Point" + seems to have improved. + * Added support for iNES mapper 242(used by "Wai Xing Zhan Shi"). + * Fixed a network play bug that could cause desynchronizations + if more than one network play session occured since FCE Ultra + was started. This bug only showed up on the Windows port, though. + * Increased the volume of the noise and triangle sound channels. + * Fixed a save state loading bug. + * Fixed a small memory leak that was being caused by the VRC7 + state loading code. + * Fixed a bug that could cause FCE Ultra to crash if a virtual disk + was being read and the user ejected the virtual disk. + * Various minor bug fixes/code cleanups. + * NTSC color "emulation" can now be enabled again(the code to + enable it was broken in the last version). (Linux) + +0.61 +---- + + * Speed optimizations in sprite rendering code. + * Screen snapshots are now saved in the PNG format instead of the PCX + format. + * Fixed Game Genie emulation(it wasn't working in the last release). + Also added support for Game Genie emulation to the UNIF code. + * Rewrote command line option parsing code. + * Fixed a problem(if FCE Ultra was configured to connect to a remote + host and the remote host was given as an IP address, and the IP + address couldn't be reverse resolved, which is commonly the case + on home LANs, the connection attempt would fail) in the network + play code. I had misinterpreted the Winsock API documentation + when I wrote the code. (Windows) + +0.60 +---- + + * Various speed optimizations. + * Sound is no longer messed up when a JAM/KIL opcode is emulated. + * Fixed an overflow bug that occured when $4014 was written to + during certain(rare) conditions. + * Fixed a few save state bugs. + * Fixed a MMC1 CHR bank switching bug. + * Added emulation of the MMC5's WRAM write-enable/disable registers. + * Fixed a sound frame IRQ emulation bug. "Qix" works now. + * Added UNIF support. Some of the board emulation is still a bit + buggy, though. Look at the documentation for a list of supported + boards. + * Updated the "Palette Notes" section of the documentation. Also + fixed a few other problems with the documentation. + * Added support for loading files in the PKZIP and gzip + compressed file formats via zlib. + * Added the ability to configure the first scanline and the last + scanline to draw to the screen. Enabling PAL emulation no longer + will cause all 239 scanlines to be displayed, though an option + to override these settings for when PAL emulation is enabled may + be in the next version. + * Fixed a bug that would cause the emulated D-pad of virtual gamepads + emulated through the keyboard to be duplicated through "higher" + virtual gamepads(gamepad 1 would affect 2,3,4; gamepad 2 would + affect 3,4; etc.). (Windows) + +0.55 +---- + * Rewrote window resizing code. The window will now resize itself + to a multiple of the NES' screen dimensions nearest to the user + selected dimensions. (Windows) + * Added an option to use buttons instead of axes on physical joysticks + for the emulated D-Pad. This is useful for some digital joysticks. (Windows) + * Fixed a bug that would cause FCE Ultra to crash if sound were + disabled during emulation. (Windows) + * Added the ability to "fast forward" emulation. + * Added an option to allow more than 8 sprites per scanline to be + displayed. + * Added an option to save all extra non-volatile game data + (such as battery-backed RAM) in a directory under FCE Ultra's + base directory(as opposed to the directory the game is located in). + * Added an option to allow the emulator to change to a full screen + video mode once a new game is loaded. (Windows) + * Rewrote pieces of DirectInput joystick handling code. Hopefully + it should increase compatibility. (Windows) + * Added the ability to automatically obtain button numbers when + configuring joysticks, by pressing buttons on the joystick. + * Added the ability to close the current game(decreases CPU usage). (windows) + * Increased the speed of various function calls by passing + arguments to functions through registers instead of through the + stack. + * Added emulation of the MMC5's raw PCM register. + * Added the ability to save/load save states while network play + is occuring. + * Having PAL emulation enabled will no longer override the + NTSC/PAL settings in NSF headers. + * Fixed a bug that got into the .54 release. Extraneous data was + being returned on reads from $2002, which caused problems + with some games(such as "Choujin Sentai Jetman"). + +0.54 +---- + * Fixed a bug that would cause a wrong battery-backed WRAM file + name to be produced if FCE Ultra was passed a file name without + any directory component(such as "fceu SuperBlah.nes"). + * Fixed an iNES mapper 118 emulation bug that got into the code + in a recent code cleanup. "Armadillo" is playable again. + * Fixed a typo(and bug) in the MMC5 emulation code. + * Data returned from emulated reads to "unmapped" areas or + memory locations where bits are undefined should now be correct. + * Fixed emulation of the sprite memory transfer register $4014. + It now takes into account the last value written to $2003 and + starts the transfer to that location in sprite memory(like on + a real NES). + * Added a video configuration dialog box. (Windows) + * Added the ability to configure a custom video mode. Aspects + that are configurable include width, height, bits per pixel, + and size transforming(stretching and scaling). (Windows) + +0.53 +---- + + * Fixed a bug with joysticks that occured on systems with multiple + joysticks. (Windows) + * Added support for iNES mappers 77 and 92(thanks to LULU for the code for both). + * Added partial(timer is non-configurable) support for iNES mapper 105. + * Changed save state format again. Save states made with previous + versions should still be compatible, though this may change in + future versions. + * Small optimization to sprite emulation code. + * Rewrote color-deemphasis code to use integer math instead of + floating-point math. + * Rewrote and restructured input code. (Linux) + * Added command line option "-f8bit" to force 8-bit sound. (Linux) + * Rewrote and restructured input code. Among other new features, + keyboard keys are now somewhat configurable. (Windows) + * Writes to $4003/$4007 will now reset the emulated square wave + duty cycle generator. + * Added emulation of the Power Pad. + * Rewrote joystick device reading code to use the event-driven + interface. This should fix various problems regarding support + for joysticks with many buttons. (linux) + +0.52 +---- + + * Fixed a PCM emulation bug(digitized voices in "Ikari Warriors 2" + and "The Immortal", among others, work now). + * Fixed noise channel's LSFR update frequencies(hopefully). + * Various minor bug fixes. + +0.51 +---- + + * Added support for iNES mappers 86 and 89. + * Reduced byte size of the NSF player's background. + * Adjusted CPU/PPU timing. + * Fixed sound channel frequency calculations for when PAL emulation is enabled. + * Rewrote large pieces of the sound code and got rid of the sound queue. Sound quality should be slightly better now. + * Various minor bug fixes. + + Windows: + + * Fixed an FDS side reset bug when a new game is loaded. + * Screen width/depth/height changes while FCE Ultra is in windowed mode are handled now. + * Changed the configuration file format. + * Added a palette configuration dialog. + * Added the ability to load a custom NES palette. + * Added an option to double 16-bit sound volume. + * Added an option to force 8-bit sound. + * Added an option to use a secondary sound buffer(versus the primary). + * Added an option to wait for vertical blank if sound is disabled. + * Added an option to run while focus is lost. + +0.50 +---- + + * Many bug fixes. + * Sound code partially rewritten to improve quality(near-perfect + raw PCM now) and eliminate the need for a separate thread. + This created a small problem with network play, though, so read + the network play notes section. Also, synchronizing to + vertical blank has been removed. + * Rewrote other pieces of sound code. No more "buzzing" in MegaMan 2, + Codemasters games' intros, etc. + * Added support for the NES Zapper and the VS Unisystem's light + gun. Be sure to read "Light Gun Notes". + * Changed save state format. Save states should now be much + smaller for most games. Most(not all) save states created with + an older version should work. + * Added support for VS Duck Hunt and VS Hogan's Alley. + diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/CMakeLists.txt b/branches/fceux-2.2.2/attic/cmake-stuff/CMakeLists.txt new file mode 100644 index 00000000..49277b50 --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.6) +project(fceux) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) +add_subdirectory(cmake/native) +if(UNIX) + add_subdirectory(cmake/cross-mingw32) +endif(UNIX) + +add_custom_command( + OUTPUT ${EXECUTABLE_OUTPUT_PATH}/fceux.chm + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/src/drivers/win/help/fceux.chm ${EXECUTABLE_OUTPUT_PATH}/fceux.chm + DEPENDS ${CMAKE_SOURCE_DIR}/src/drivers/win/help/fceux.chm + VERBATIM +) +add_custom_target( + InstallHelpFile + ALL + DEPENDS ${EXECUTABLE_OUTPUT_PATH}/fceux.chm +) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/CMakeLists.txt b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/CMakeLists.txt new file mode 100644 index 00000000..9d36cf4b --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(release) +add_subdirectory(debug) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/debug/CMakeLists.txt b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/debug/CMakeLists.txt new file mode 100644 index 00000000..4ed85291 --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/debug/CMakeLists.txt @@ -0,0 +1,4 @@ +project("fceux: cross-mingw32 debug") +set(CMAKE_BUILD_TYPE debug) +set(FCEUX_EXE_NAME fceuxDBG.exe) +include(${CMAKE_SOURCE_DIR}/cmake/cross-mingw32/fceux_cross-mingw32.cmake) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/fceux_cross-mingw32.cmake b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/fceux_cross-mingw32.cmake new file mode 100644 index 00000000..cb9c34db --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/fceux_cross-mingw32.cmake @@ -0,0 +1,50 @@ +include(CheckIncludeFile) + +# Find mingw by looking for windows.h; set HOST accordingly. +find_path(PATH_TO_WINDOWS_H windows.h + /usr/i386-mingw32msvc/mingw/include + /usr/i586-mingw32msvc/mingw/include + /usr/i686-mingw32msvc/mingw/include + /usr/i386-mingw32/mingw/include + /usr/i586-mingw32/mingw/include + /usr/i686-mingw32/mingw/include +) +string(REGEX MATCH "i.86-[^/]*" HOST ${PATH_TO_WINDOWS_H}) + +set(CMAKE_CROSSCOMPILING TRUE) +set(MINGW TRUE) +set(WIN32 TRUE) +set(APPLE FALSE) +set(UNIX FALSE) +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_C_COMPILER "${HOST}-gcc") +set(CMAKE_CXX_COMPILER "${HOST}-g++") +set(CMAKE_RC_COMPILER "${HOST}-windres") + +set(CMAKE_FIND_ROOT_PATH "/usr/${HOST}") +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +include(${CMAKE_SOURCE_DIR}/cmake/fceux.cmake) +# I cannot fucking believe that I need to do this: +#don't: ENABLE_LANGUAGE(RC) # above +#do: (for cmake-2.6.0 at least) +set(OUTPUT_RES_RC_O CMakeFiles/${FCEUX_EXE_NAME}.dir/__/__/__/src/drivers/win/res.rc.o) +add_custom_command( + OUTPUT ${OUTPUT_RES_RC_O} + COMMAND ${HOST}-windres -Isrc/drivers/win -DLVS_OWNERDATA=0x1000 -o ${OUTPUT_RES_RC_O} ${CMAKE_SOURCE_DIR}/src/drivers/win/res.rc + DEPENDS ${CMAKE_SOURCE_DIR}/src/drivers/win/res.rc + VERBATIM +) +add_custom_target( + BuildResourceFileFor${FCEUX_EXE_NAME} + DEPENDS ${OUTPUT_RES_RC_O} +) +set(DEFINED_BUILD_RESOURCE_FILE TRUE CACHE GLOBAL "This is a hack to get CMake to build the .rc file") + +add_dependencies( ${FCEUX_EXE_NAME} BuildResourceFileFor${FCEUX_EXE_NAME} ) +set_property( + TARGET ${FCEUX_EXE_NAME} + PROPERTY LINK_FLAGS ${OUTPUT_RES_RC_O} +) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/release/CMakeLists.txt b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/release/CMakeLists.txt new file mode 100644 index 00000000..0e32033f --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/cross-mingw32/release/CMakeLists.txt @@ -0,0 +1,4 @@ +project("fceux: cross-mingw32 release") +set(CMAKE_BUILD_TYPE release) +set(FCEUX_EXE_NAME fceuxREL.exe) +include(${CMAKE_SOURCE_DIR}/cmake/cross-mingw32/fceux_cross-mingw32.cmake) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/fceux.cmake b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/fceux.cmake new file mode 100644 index 00000000..6d1a5191 --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/fceux.cmake @@ -0,0 +1,476 @@ +#TODO: install generated exe's, appropriately named, in bin/ +include(CheckFunctionExists) +include(TestBigEndian) + +option(FCEUX_FORCE_LE "Build for a little-endian target" OFF) +option(FCEUX_FORCE_BE "Build for a big-endian target" OFF) +option(FCEUX_FRAMESKIP "Build legacy frameskip code" OFF) + +if(WIN32) + OPTION (NOWIN32 "Replace Win32 support with SDL" OFF) + if (NOWIN32) + set(WIN32 OFF) + endif(NOWIN32) +endif(WIN32) + +if (NOT WIN32) + option(FCEUX_SDL_OPENGL "Build with OpenGL support" ON) + find_package(SDL REQUIRED) + find_package(ZLIB REQUIRED) + if(FCEUX_SDL_OPENGL) + find_package(OpenGL REQUIRED) + endif(FCEUX_SDL_OPENGL) +endif(NOT WIN32) + +set(SRC_CORE + ${CMAKE_SOURCE_DIR}/src/asm.cpp + ${CMAKE_SOURCE_DIR}/src/cart.cpp + ${CMAKE_SOURCE_DIR}/src/cheat.cpp + ${CMAKE_SOURCE_DIR}/src/conddebug.cpp + ${CMAKE_SOURCE_DIR}/src/config.cpp + ${CMAKE_SOURCE_DIR}/src/debug.cpp + ${CMAKE_SOURCE_DIR}/src/drawing.cpp + ${CMAKE_SOURCE_DIR}/src/fceu.cpp + ${CMAKE_SOURCE_DIR}/src/fds.cpp + ${CMAKE_SOURCE_DIR}/src/file.cpp + ${CMAKE_SOURCE_DIR}/src/emufile.cpp + ${CMAKE_SOURCE_DIR}/src/filter.cpp + ${CMAKE_SOURCE_DIR}/src/ines.cpp + ${CMAKE_SOURCE_DIR}/src/input.cpp + ${CMAKE_SOURCE_DIR}/src/movie.cpp + ${CMAKE_SOURCE_DIR}/src/netplay.cpp + ${CMAKE_SOURCE_DIR}/src/nsf.cpp + ${CMAKE_SOURCE_DIR}/src/oldmovie.cpp + ${CMAKE_SOURCE_DIR}/src/palette.cpp + ${CMAKE_SOURCE_DIR}/src/ppu.cpp + ${CMAKE_SOURCE_DIR}/src/sound.cpp + ${CMAKE_SOURCE_DIR}/src/state.cpp + ${CMAKE_SOURCE_DIR}/src/unif.cpp + ${CMAKE_SOURCE_DIR}/src/video.cpp + ${CMAKE_SOURCE_DIR}/src/vsuni.cpp + ${CMAKE_SOURCE_DIR}/src/wave.cpp + ${CMAKE_SOURCE_DIR}/src/x6502.cpp + ${CMAKE_SOURCE_DIR}/src/boards/01-222.cpp + ${CMAKE_SOURCE_DIR}/src/boards/103.cpp + ${CMAKE_SOURCE_DIR}/src/boards/106.cpp + ${CMAKE_SOURCE_DIR}/src/boards/108.cpp + ${CMAKE_SOURCE_DIR}/src/boards/112.cpp + ${CMAKE_SOURCE_DIR}/src/boards/117.cpp + ${CMAKE_SOURCE_DIR}/src/boards/120.cpp + ${CMAKE_SOURCE_DIR}/src/boards/121.cpp + ${CMAKE_SOURCE_DIR}/src/boards/15.cpp + ${CMAKE_SOURCE_DIR}/src/boards/164.cpp + ${CMAKE_SOURCE_DIR}/src/boards/175.cpp + ${CMAKE_SOURCE_DIR}/src/boards/176.cpp + ${CMAKE_SOURCE_DIR}/src/boards/177.cpp + ${CMAKE_SOURCE_DIR}/src/boards/178.cpp + ${CMAKE_SOURCE_DIR}/src/boards/179.cpp + ${CMAKE_SOURCE_DIR}/src/boards/183.cpp + ${CMAKE_SOURCE_DIR}/src/boards/185.cpp + ${CMAKE_SOURCE_DIR}/src/boards/186.cpp + ${CMAKE_SOURCE_DIR}/src/boards/187.cpp + ${CMAKE_SOURCE_DIR}/src/boards/189.cpp + ${CMAKE_SOURCE_DIR}/src/boards/199.cpp + ${CMAKE_SOURCE_DIR}/src/boards/208.cpp + ${CMAKE_SOURCE_DIR}/src/boards/222.cpp + ${CMAKE_SOURCE_DIR}/src/boards/23.cpp + ${CMAKE_SOURCE_DIR}/src/boards/235.cpp + ${CMAKE_SOURCE_DIR}/src/boards/253.cpp + ${CMAKE_SOURCE_DIR}/src/boards/3d-block.cpp + ${CMAKE_SOURCE_DIR}/src/boards/411120-c.cpp + ${CMAKE_SOURCE_DIR}/src/boards/43.cpp + ${CMAKE_SOURCE_DIR}/src/boards/57.cpp + ${CMAKE_SOURCE_DIR}/src/boards/603-5052.cpp + ${CMAKE_SOURCE_DIR}/src/boards/68.cpp + ${CMAKE_SOURCE_DIR}/src/boards/8157.cpp + ${CMAKE_SOURCE_DIR}/src/boards/8237.cpp + ${CMAKE_SOURCE_DIR}/src/boards/830118C.cpp + ${CMAKE_SOURCE_DIR}/src/boards/88.cpp + ${CMAKE_SOURCE_DIR}/src/boards/90.cpp + ${CMAKE_SOURCE_DIR}/src/boards/95.cpp + ${CMAKE_SOURCE_DIR}/src/boards/__dummy_mapper.cpp + ${CMAKE_SOURCE_DIR}/src/boards/a9711.cpp + ${CMAKE_SOURCE_DIR}/src/boards/a9746.cpp + ${CMAKE_SOURCE_DIR}/src/boards/addrlatch.cpp + ${CMAKE_SOURCE_DIR}/src/boards/ax5705.cpp + ${CMAKE_SOURCE_DIR}/src/boards/bandai.cpp + ${CMAKE_SOURCE_DIR}/src/boards/bmc13in1jy110.cpp + ${CMAKE_SOURCE_DIR}/src/boards/bmc42in1r.cpp + ${CMAKE_SOURCE_DIR}/src/boards/bmc64in1nr.cpp + ${CMAKE_SOURCE_DIR}/src/boards/bmc70in1.cpp + ${CMAKE_SOURCE_DIR}/src/boards/bonza.cpp + ${CMAKE_SOURCE_DIR}/src/boards/bs-5.cpp + ${CMAKE_SOURCE_DIR}/src/boards/onebus.cpp + ${CMAKE_SOURCE_DIR}/src/boards/datalatch.cpp + ${CMAKE_SOURCE_DIR}/src/boards/deirom.cpp + ${CMAKE_SOURCE_DIR}/src/boards/dream.cpp + ${CMAKE_SOURCE_DIR}/src/boards/edu2000.cpp + ${CMAKE_SOURCE_DIR}/src/boards/fk23c.cpp + ${CMAKE_SOURCE_DIR}/src/boards/ghostbusters63in1.cpp + ${CMAKE_SOURCE_DIR}/src/boards/gs-2004.cpp + ${CMAKE_SOURCE_DIR}/src/boards/gs-2013.cpp + ${CMAKE_SOURCE_DIR}/src/boards/h2288.cpp + ${CMAKE_SOURCE_DIR}/src/boards/karaoke.cpp + ${CMAKE_SOURCE_DIR}/src/boards/kof97.cpp + ${CMAKE_SOURCE_DIR}/src/boards/vrc5.cpp + ${CMAKE_SOURCE_DIR}/src/boards/ks7032.cpp + ${CMAKE_SOURCE_DIR}/src/boards/malee.cpp + ${CMAKE_SOURCE_DIR}/src/boards/mmc1.cpp + ${CMAKE_SOURCE_DIR}/src/boards/mmc3.cpp + ${CMAKE_SOURCE_DIR}/src/boards/mmc5.cpp + ${CMAKE_SOURCE_DIR}/src/boards/n-c22m.cpp + ${CMAKE_SOURCE_DIR}/src/boards/n106.cpp + ${CMAKE_SOURCE_DIR}/src/boards/n625092.cpp + ${CMAKE_SOURCE_DIR}/src/boards/novel.cpp + ${CMAKE_SOURCE_DIR}/src/boards/sachen.cpp + ${CMAKE_SOURCE_DIR}/src/boards/sc-127.cpp + ${CMAKE_SOURCE_DIR}/src/boards/sheroes.cpp + ${CMAKE_SOURCE_DIR}/src/boards/sl1632.cpp + ${CMAKE_SOURCE_DIR}/src/boards/smb2j.cpp + ${CMAKE_SOURCE_DIR}/src/boards/subor.cpp + ${CMAKE_SOURCE_DIR}/src/boards/super24.cpp + ${CMAKE_SOURCE_DIR}/src/boards/supervision.cpp + ${CMAKE_SOURCE_DIR}/src/boards/t-227-1.cpp + ${CMAKE_SOURCE_DIR}/src/boards/t-262.cpp + ${CMAKE_SOURCE_DIR}/src/boards/tengen.cpp + ${CMAKE_SOURCE_DIR}/src/boards/tf-1201.cpp + ${CMAKE_SOURCE_DIR}/src/input/arkanoid.cpp + ${CMAKE_SOURCE_DIR}/src/input/bworld.cpp + ${CMAKE_SOURCE_DIR}/src/input/cursor.cpp + ${CMAKE_SOURCE_DIR}/src/input/fkb.cpp + ${CMAKE_SOURCE_DIR}/src/input/ftrainer.cpp + ${CMAKE_SOURCE_DIR}/src/input/hypershot.cpp + ${CMAKE_SOURCE_DIR}/src/input/mahjong.cpp + ${CMAKE_SOURCE_DIR}/src/input/mouse.cpp + ${CMAKE_SOURCE_DIR}/src/input/oekakids.cpp + ${CMAKE_SOURCE_DIR}/src/input/powerpad.cpp + ${CMAKE_SOURCE_DIR}/src/input/quiz.cpp + ${CMAKE_SOURCE_DIR}/src/input/shadow.cpp + ${CMAKE_SOURCE_DIR}/src/input/suborkb.cpp + ${CMAKE_SOURCE_DIR}/src/input/toprider.cpp + ${CMAKE_SOURCE_DIR}/src/input/zapper.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/151.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/16.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/17.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/18.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/193.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/201.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/202.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/203.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/204.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/21.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/212.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/213.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/214.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/215.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/217.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/22.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/225.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/227.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/228.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/229.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/230.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/231.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/232.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/234.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/241.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/242.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/244.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/246.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/24and26.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/25.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/255.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/27.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/32.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/33.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/40.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/41.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/42.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/46.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/50.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/51.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/59.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/6.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/60.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/61.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/62.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/65.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/67.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/69.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/71.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/72.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/73.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/75.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/76.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/77.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/79.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/8.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/80.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/82.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/83.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/85.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/86.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/89.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/91.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/92.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/97.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/99.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/emu2413.c + ${CMAKE_SOURCE_DIR}/src/mappers/mmc2and4.cpp + ${CMAKE_SOURCE_DIR}/src/mappers/simple.cpp + ${CMAKE_SOURCE_DIR}/src/utils/ConvertUTF.c + ${CMAKE_SOURCE_DIR}/src/utils/crc32.cpp + ${CMAKE_SOURCE_DIR}/src/utils/endian.cpp + ${CMAKE_SOURCE_DIR}/src/utils/general.cpp + ${CMAKE_SOURCE_DIR}/src/utils/guid.cpp + ${CMAKE_SOURCE_DIR}/src/utils/md5.cpp + ${CMAKE_SOURCE_DIR}/src/utils/memory.cpp + ${CMAKE_SOURCE_DIR}/src/utils/unzip.cpp + ${CMAKE_SOURCE_DIR}/src/utils/xstring.cpp +) + +set(SRC_DRIVERS_COMMON + ${CMAKE_SOURCE_DIR}/src/drivers/common/args.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/cheat.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/config.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/configSys.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/hq2x.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/hq3x.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/scale2x.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/scale3x.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/scalebit.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/vidblit.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/common/nes_ntsc.c +) + +set(SRC_DRIVERS_SDL + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/config.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/input.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/sdl.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/sdl-joystick.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/sdl-sound.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/sdl-throttle.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/sdl-video.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/sdl/unix-netplay.cpp +) + +if(FCEUX_SDL_OPENGL) + set(SRC_DRIVERS_SDL ${SRC_DRIVERS_SDL} ${CMAKE_SOURCE_DIR}/src/drivers/sdl/sdl-opengl.cpp) +endif(FCEUX_SDL_OPENGL) + +set(SRC_DRIVERS_WIN + ${CMAKE_SOURCE_DIR}/src/lua-engine.cpp + ${CMAKE_SOURCE_DIR}/src/lua/src/lapi.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lauxlib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lbaselib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lcode.c + ${CMAKE_SOURCE_DIR}/src/lua/src/ldblib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/ldebug.c + ${CMAKE_SOURCE_DIR}/src/lua/src/ldo.c + ${CMAKE_SOURCE_DIR}/src/lua/src/ldump.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lfunc.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lgc.c + ${CMAKE_SOURCE_DIR}/src/lua/src/linit.c + ${CMAKE_SOURCE_DIR}/src/lua/src/liolib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/llex.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lmathlib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lmem.c + ${CMAKE_SOURCE_DIR}/src/lua/src/loadlib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lobject.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lopcodes.c + ${CMAKE_SOURCE_DIR}/src/lua/src/loslib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lparser.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lstate.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lstring.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lstrlib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/ltable.c + ${CMAKE_SOURCE_DIR}/src/lua/src/ltablib.c + ${CMAKE_SOURCE_DIR}/src/lua/src/ltm.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lundump.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lvm.c + ${CMAKE_SOURCE_DIR}/src/lua/src/lzio.c + ${CMAKE_SOURCE_DIR}/src/lua/src/print.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/archive.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/args.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/aviout.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/cdlogger.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/cheat.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/common.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/config.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/debugger.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/debuggersp.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/directories.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/gui.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/guiconfig.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/help.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/input.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/joystick.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/keyboard.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/log.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/luaconsole.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/main.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/mapinput.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/memview.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/memviewsp.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/memwatch.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/movieoptions.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/monitor.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/netplay.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/ntview.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/OutputDS.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/palette.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/ppuview.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/pref.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/ram_search.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/ramwatch.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/replay.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/res.rc + ${CMAKE_SOURCE_DIR}/src/drivers/win/sound.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/state.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/tasedit.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/taseditproj.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/greenzone.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/bookmark.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/bookmarks.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/inputhistory.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/inputsnapshot.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/playback.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/taseditlib/markers.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/texthook.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/throttle.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/timing.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/tracer.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/video.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/wave.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/window.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/Win32InputBox.cpp + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/adler32.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/compress.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/crc32.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/deflate.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/gzio.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/infblock.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/infcodes.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/inffast.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/inflate.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/inftrees.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/infutil.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/trees.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/uncompr.c + ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib/zutil.c + # ${CMAKE_SOURCE_DIR}/src/drivers/res.rc +) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +include_directories( ${CMAKE_SOURCE_DIR}/src ) +add_definitions( -DNETWORK ) + +if(WIN32) + set(SOURCES ${SRC_CORE} ${SRC_DRIVERS_COMMON} ${SRC_DRIVERS_WIN}) + include_directories( ${CMAKE_SOURCE_DIR}/src/drivers/win/directx ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib ) + add_definitions( + -DWIN32 + -DFCEUDEF_DEBUGGER + -D_USE_SHARED_MEMORY_ + -DPSS_STYLE=2 + -DNOMINMAX + -D_S9XLUA_H + ) + link_directories( ${CMAKE_SOURCE_DIR}/src/drivers/win/directx ) +else(WIN32) + set(SOURCES ${SRC_CORE} ${SRC_DRIVERS_COMMON} ${SRC_DRIVERS_SDL}) + include_directories( ${SDL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) + add_definitions( ${SDL_DEFINITIONS} ${ZLIB_DEFINITIONS} ) + if(FCEUX_SDL_OPENGL) + add_definitions( -DOPENGL ) + include_directories( ${OPENGL_INCLUDE_DIR} ) + endif(FCEUX_SDL_OPENGL) +endif(WIN32) + +if(APPLE) + add_definitions( -DPSS_STYLE=4 ) +else(APPLE) + if(UNIX) + add_definitions( -DPSS_STYLE=1 ) + endif(UNIX) +endif(APPLE) + +if(MINGW) + add_definitions( -DNEED_MINGW_HACKS -D_WIN32_IE=0x0600 ) +endif(MINGW) +if(CMAKE_BUILD_TYPE STREQUAL "debug") + add_definitions( -D_DEBUG ) +endif(CMAKE_BUILD_TYPE STREQUAL "debug") +if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall -Wno-write-strings -Wno-sign-compare") +endif(CMAKE_COMPILER_IS_GNUCXX) + +if(FCEUX_FRAMESKIP) + add_definitions( -DFRAMESKIP ) +endif(FCEUX_FRAMESKIP) + +if(NOT FCEUX_FORCE_BE) + if(FCEUX_FORCE_LE) + add_definitions( -DLSB_FIRST ) + else(FCEUX_FORCE_LE) + test_big_endian(SYS_IS_BE) + if(NOT SYS_IS_BE) + add_definitions( -DLSB_FIRST ) + endif(NOT SYS_IS_BE) + endif(FCEUX_FORCE_LE) +endif(NOT FCEUX_FORCE_BE) + +check_function_exists(asprintf HAVE_ASPRINTF) +# HACK: cmake seems to cache HAVE_ASPRINTF and I don't know how to ask it +# to forget--even if your compiler changes. So tell it mingw=>no. +if(HAVE_ASPRINTF AND NOT MINGW) + add_definitions( -DHAVE_ASPRINTF ) +endif(HAVE_ASPRINTF AND NOT MINGW) + +add_executable( ${FCEUX_EXE_NAME} ${SOURCES} ) + +if(WIN32) + add_dependencies( ${FCEUX_EXE_NAME} InstallHelpFile ) + #add_dependencies( ${FCEUX_EXE_NAME} res.o) + #add_custom_command( + # OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/res.o + # COMMAND windres + # ARGS ${CMAKE_SOURCE_DIR}/src/drivers/win/res.rc ${CMAKE_CURRENT_BINARY_DIR}/res.o --use-temp-file -D_WIN_IE=0x300 + # MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/src/drivers/win/res.rc + #) + set(OUTPUT_RES_RC_O CMakeFiles/${FCEUX_EXE_NAME}.dir/__/__/__/src/drivers/win/res.rc.o) + add_custom_command( + OUTPUT ${OUTPUT_RES_RC_O} + COMMAND windres -o ${OUTPUT_RES_RC_O} ${CMAKE_SOURCE_DIR}/src/drivers/win/res.rc + DEPENDS ${CMAKE_SOURCE_DIR}/src/drivers/win/res.rc + VERBATIM + ) + add_custom_target( + BuildResourceFileFor${FCEUX_EXE_NAME} + DEPENDS ${OUTPUT_RES_RC_O} + ) + set(DEFINED_BUILD_RESOURCE_FILE TRUE CACHE GLOBAL "This is a hack to get CMake to build the .rc file") + + add_dependencies( ${FCEUX_EXE_NAME} BuildResourceFileFor${FCEUX_EXE_NAME} ) + set_property( + TARGET ${FCEUX_EXE_NAME} + PROPERTY LINK_FLAGS "${OUTPUT_RES_RC_O} -mwindows" + ) + + target_link_libraries( ${FCEUX_EXE_NAME} rpcrt4 comctl32 vfw32 winmm ws2_32 + comdlg32 ole32 gdi32 + dsound dxguid ddraw dinput + ) + if(MINGW) + include_directories(${CMAKE_SOURCE_DIR}/src/drivers/win/lua/include/) + else(MINGW) + target_link_libraries( ${FCEUX_EXE_NAME} htmlhelp) + endif(MINGW) +else(WIN32) + target_link_libraries( ${FCEUX_EXE_NAME} ${SDL_LIBRARY} ${ZLIB_LIBRARIES} ) + if(FCEUX_SDL_OPENGL) + target_link_libraries( ${FCEUX_EXE_NAME} ${OPENGL_gl_LIBRARY} ) + endif(FCEUX_SDL_OPENGL) +endif(WIN32) + + diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/CMakeLists.txt b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/CMakeLists.txt new file mode 100644 index 00000000..9d36cf4b --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(release) +add_subdirectory(debug) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/debug/CMakeLists.txt b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/debug/CMakeLists.txt new file mode 100644 index 00000000..d21d1f2b --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/debug/CMakeLists.txt @@ -0,0 +1,4 @@ +project("fceux: native debug") +set(CMAKE_BUILD_TYPE debug) +set(FCEUX_EXE_NAME fceuxDBG) +include(${CMAKE_SOURCE_DIR}/cmake/native/fceux_native.cmake) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/fceux_native.cmake b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/fceux_native.cmake new file mode 100644 index 00000000..474a4288 --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/fceux_native.cmake @@ -0,0 +1 @@ +include(${CMAKE_SOURCE_DIR}/cmake/fceux.cmake) diff --git a/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/release/CMakeLists.txt b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/release/CMakeLists.txt new file mode 100644 index 00000000..4f78c90a --- /dev/null +++ b/branches/fceux-2.2.2/attic/cmake-stuff/cmake/native/release/CMakeLists.txt @@ -0,0 +1,4 @@ +project("fceux: native release") +set(CMAKE_BUILD_TYPE release) +set(FCEUX_EXE_NAME fceuxREL) +include(${CMAKE_SOURCE_DIR}/cmake/native/fceux_native.cmake) diff --git a/branches/fceux-2.2.2/attic/compile b/branches/fceux-2.2.2/attic/compile new file mode 100755 index 00000000..9bb997a6 --- /dev/null +++ b/branches/fceux-2.2.2/attic/compile @@ -0,0 +1,99 @@ +#! /bin/sh + +# Wrapper for compilers which do not understand `-c -o'. + +# Copyright 1999, 2000 Free Software Foundation, Inc. +# Written by Tom Tromey . +# +# 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Usage: +# compile PROGRAM [ARGS]... +# `-o FOO.o' is removed from the args passed to the actual compile. + +prog=$1 +shift + +ofile= +cfile= +args= +while test $# -gt 0; do + case "$1" in + -o) + # configure might choose to run compile as `compile cc -o foo foo.c'. + # So we do something ugly here. + ofile=$2 + shift + case "$ofile" in + *.o | *.obj) + ;; + *) + args="$args -o $ofile" + ofile= + ;; + esac + ;; + *.c) + cfile=$1 + args="$args $1" + ;; + *) + args="$args $1" + ;; + esac + shift +done + +if test -z "$ofile" || test -z "$cfile"; then + # If no `-o' option was seen then we might have been invoked from a + # pattern rule where we don't need one. That is ok -- this is a + # normal compilation that the losing compiler can handle. If no + # `.c' file was seen then we are probably linking. That is also + # ok. + exec "$prog" $args +fi + +# Name of file we expect compiler to create. +cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'` + +# Create the lock directory. +# Note: use `[/.-]' here to ensure that we don't use the same name +# that we are using for the .o file. Also, base the name on the expected +# object file name, since that is what matters with a parallel build. +lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d +while true; do + if mkdir $lockdir > /dev/null 2>&1; then + break + fi + sleep 1 +done +# FIXME: race condition here if user kills between mkdir and trap. +trap "rmdir $lockdir; exit 1" 1 2 15 + +# Run the compile. +"$prog" $args +status=$? + +if test -f "$cofile"; then + mv "$cofile" "$ofile" +fi + +rmdir $lockdir +exit $status diff --git a/branches/fceux-2.2.2/attic/config.guess b/branches/fceux-2.2.2/attic/config.guess new file mode 100755 index 00000000..dff9e481 --- /dev/null +++ b/branches/fceux-2.2.2/attic/config.guess @@ -0,0 +1,1317 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. + +timestamp='2001-09-04' + +# This file 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Written by Per Bothner . +# Please send patches to . +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + + +dummy=dummy-$$ +trap 'rm -f $dummy.c $dummy.o $dummy.rel $dummy; exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +set_cc_for_build='case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int dummy(){}" > $dummy.c ; + for c in cc gcc c89 ; do + ($c $dummy.c -c -o $dummy.o) >/dev/null 2>&1 ; + if test $? = 0 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + rm -f $dummy.c $dummy.o $dummy.rel ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # Netbsd (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # Determine the machine/vendor (is the vendor relevant). + case "${UNAME_MACHINE}" in + amiga) machine=m68k-unknown ;; + arm32) machine=arm-unknown ;; + atari*) machine=m68k-atari ;; + sun3*) machine=m68k-sun ;; + mac68k) machine=m68k-apple ;; + macppc) machine=powerpc-apple ;; + hp3[0-9][05]) machine=m68k-hp ;; + ibmrt|romp-ibm) machine=romp-ibm ;; + *) machine=${UNAME_MACHINE}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE}" in + i386|sparc|amiga|arm*|hp300|mvme68k|vax|atari|luna68k|mac68k|news68k|next68k|pc532|sun3*|x68k) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit 0 ;; + alpha:OSF1:*:*) + if test $UNAME_RELEASE = "V4.0"; then + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + fi + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + cat <$dummy.s + .data +\$Lformat: + .byte 37,100,45,37,120,10,0 # "%d-%x\n" + + .text + .globl main + .align 4 + .ent main +main: + .frame \$30,16,\$26,0 + ldgp \$29,0(\$27) + .prologue 1 + .long 0x47e03d80 # implver \$0 + lda \$2,-1 + .long 0x47e20c21 # amask \$2,\$1 + lda \$16,\$Lformat + mov \$0,\$17 + not \$1,\$18 + jsr \$26,printf + ldgp \$29,0(\$26) + mov 0,\$16 + jsr \$26,exit + .end main +EOF + eval $set_cc_for_build + $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null + if test "$?" = 0 ; then + case `./$dummy` in + 0-0) + UNAME_MACHINE="alpha" + ;; + 1-0) + UNAME_MACHINE="alphaev5" + ;; + 1-1) + UNAME_MACHINE="alphaev56" + ;; + 1-101) + UNAME_MACHINE="alphapca56" + ;; + 2-303) + UNAME_MACHINE="alphaev6" + ;; + 2-307) + UNAME_MACHINE="alphaev67" + ;; + 2-1307) + UNAME_MACHINE="alphaev68" + ;; + esac + fi + rm -f $dummy.s $dummy + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit 0 ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit 0 ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit 0 ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit 0;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit 0 ;; + arc64:OpenBSD:*:*) + echo mips64el-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hkmips:OpenBSD:*:*) + echo mips-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mips-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit 0 ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit 0;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit 0;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit 0 ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit 0 ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + i86pc:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit 0 ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit 0 ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit 0 ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit 0 ;; + sparc*:NetBSD:*) + echo `uname -p`-unknown-netbsd${UNAME_RELEASE} + exit 0 ;; + atari*:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit 0 ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit 0 ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit 0 ;; + sun3*:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit 0 ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit 0 ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit 0 ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD $dummy.c -o $dummy \ + && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo mips-mips-riscos${UNAME_RELEASE} + exit 0 ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit 0 ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit 0 ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit 0 ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit 0 ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit 0 ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit 0 ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit 0 ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit 0 ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit 0 ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit 0 ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit 0 ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit 0 ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo rs6000-ibm-aix3.2.5 + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit 0 ;; + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit 0 ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit 0 ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit 0 ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit 0 ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit 0 ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit 0 ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit 0 ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + case "${HPUX_REV}" in + 11.[0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + esac ;; + esac + fi ;; + esac + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null ) && HP_ARCH=`./$dummy` + if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi + rm -f $dummy.c $dummy + fi ;; + esac + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit 0 ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit 0 ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo unknown-hitachi-hiuxwe2 + exit 0 ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit 0 ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit 0 ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit 0 ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit 0 ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit 0 ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit 0 ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit 0 ;; + hppa*:OpenBSD:*:*) + echo hppa-unknown-openbsd + exit 0 ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit 0 ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit 0 ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit 0 ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit 0 ;; + CRAY*X-MP:*:*:*) + echo xmp-cray-unicos + exit 0 ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*T3D:*:*:*) + echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY-2:*:*:*) + echo cray2-cray-unicos + exit 0 ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit 0 ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:FreeBSD:*:*) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit 0 ;; + *:OpenBSD:*:*) + echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + exit 0 ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit 0 ;; + i*:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit 0 ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit 0 ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i386-pc-interix + exit 0 ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit 0 ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit 0 ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + *:GNU:*:*) + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit 0 ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit 0 ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux + exit 0 ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + mips:Linux:*:*) + case `sed -n '/^byte/s/^.*: \(.*\) endian/\1/p' < /proc/cpuinfo` in + big) echo mips-unknown-linux-gnu && exit 0 ;; + little) echo mipsel-unknown-linux-gnu && exit 0 ;; + esac + ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit 0 ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit 0 ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit 0 ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit 0 ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit 0 ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit 0 ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit 0 ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + ld_supported_targets=`cd /; ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit 0 ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit 0 ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit 0 ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + cat >$dummy.c < +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif +#ifdef __ELF__ +# ifdef __GLIBC__ +# if __GLIBC__ >= 2 + printf ("%s-pc-linux-gnu\n", argv[1]); +# else + printf ("%s-pc-linux-gnulibc1\n", argv[1]); +# endif +# else + printf ("%s-pc-linux-gnulibc1\n", argv[1]); +# endif +#else + printf ("%s-pc-linux-gnuaout\n", argv[1]); +#endif + return 0; +} +EOF + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit 0 ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit 0 ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit 0 ;; + i*86:*:5:[78]*) + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit 0 ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')` + (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit 0 ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit 0 ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit 0 ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit 0 ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit 0 ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit 0 ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit 0 ;; + M68*:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4.3${OS_REL} && exit 0 + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4 && exit 0 ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit 0 ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit 0 ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit 0 ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit 0 ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit 0 ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit 0 ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit 0 ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit 0 ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit 0 ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit 0 ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit 0 ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit 0 ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit 0 ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit 0 ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit 0 ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Darwin:*:*) + echo `uname -p`-apple-darwin${UNAME_RELEASE} + exit 0 ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + if test "${UNAME_MACHINE}" = "x86pc"; then + UNAME_MACHINE=pc + fi + echo `uname -p`-${UNAME_MACHINE}-nto-qnx + exit 0 ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit 0 ;; + NSR-[KW]:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit 0 ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit 0 ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit 0 ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit 0 ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit 0 ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit 0 ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit 0 ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit 0 ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit 0 ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit 0 ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit 0 ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit 0 ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit 0 ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit 0 ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm -f $dummy.c $dummy && exit 0 +rm -f $dummy.c $dummy + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit 0 ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + c34*) + echo c34-convex-bsd + exit 0 ;; + c38*) + echo c38-convex-bsd + exit 0 ;; + c4*) + echo c4-convex-bsd + exit 0 ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/branches/fceux-2.2.2/attic/config.sub b/branches/fceux-2.2.2/attic/config.sub new file mode 100755 index 00000000..393f13d3 --- /dev/null +++ b/branches/fceux-2.2.2/attic/config.sub @@ -0,0 +1,1411 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. + +timestamp='2001-09-07' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file 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., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Please send patches to . +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit 0;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | storm-chaos* | os2-emx* | windows32-*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ + | c4x | clipper \ + | d10v | d30v | dsp16xx \ + | fr30 \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | m32r | m68000 | m68k | m88k | mcore \ + | mips16 | mips64 | mips64el | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el | mips64vr4300 \ + | mips64vr4300el | mips64vr5000 | mips64vr5000el \ + | mipsbe | mipseb | mipsel | mipsle | mipstx39 | mipstx39el \ + | mipsisa32 \ + | mn10200 | mn10300 \ + | ns16k | ns32k \ + | openrisc \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | s390 | s390x \ + | sh | sh[34] | sh[34]eb | shbe | shle \ + | sparc | sparc64 | sparclet | sparclite | sparcv9 | sparcv9b \ + | stormy16 | strongarm \ + | tahoe | thumb | tic80 | tron \ + | v850 \ + | we32k \ + | x86 | xscale \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alphapca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armv*-* \ + | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c54x-* \ + | clipper-* | cray2-* | cydra-* \ + | d10v-* | d30v-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fr30-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | m32r-* \ + | m68000-* | m680[01234]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | mcore-* \ + | mips-* | mips16-* | mips64-* | mips64el-* | mips64orion-* \ + | mips64orionel-* | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* | mipsbe-* | mipseb-* \ + | mipsle-* | mipsel-* | mipstx39-* | mipstx39el-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | s390-* | s390x-* \ + | sh-* | sh[34]-* | sh[34]eb-* | shbe-* | shle-* \ + | sparc-* | sparc64-* | sparc86x-* | sparclite-* \ + | sparcv9-* | sparcv9b-* | stormy16-* | strongarm-* | sv1-* \ + | t3e-* | tahoe-* | thumb-* | tic30-* | tic54x-* | tic80-* | tron-* \ + | v850-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xmp-* | xps100-* | xscale-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | ymp) + basic_machine=ymp-cray + os=-unicos + ;; + cray2) + basic_machine=cray2-cray + os=-unicos + ;; + [cjt]90) + basic_machine=${basic_machine}-cray + os=-unicos + ;; + crds | unos) + basic_machine=m68k-crds + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mipsel*-linux*) + basic_machine=mipsel-unknown + os=-linux-gnu + ;; + mips*-linux*) + basic_machine=mips-unknown + os=-linux-gnu + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + mmix*) + basic_machine=mmix-knuth + os=-mmixware + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pentium | p5 | k5 | k6 | nexgen) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon) + basic_machine=i686-pc + ;; + pentiumii | pentium2) + basic_machine=i686-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sparclite-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=t3e-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + windows32) + basic_machine=i386-pc + os=-windows32-msvcrt + ;; + xmp) + basic_machine=xmp-cray + os=-unicos + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + mips) + if [ x$os = x-linux-gnu ]; then + basic_machine=mips-unknown + else + basic_machine=mips-mips + fi + ;; + romp) + basic_machine=romp-ibm + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh3 | sh4 | sh3eb | sh4eb) + basic_machine=sh-unknown + ;; + sparc | sparcv9 | sparcv9b) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + c4x*) + basic_machine=c4x-none + os=-coff + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto*) + os=-nto-qnx + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-ibm) + os=-aix + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -vxsim* | -vxworks*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/branches/fceux-2.2.2/attic/configure-mingw32 b/branches/fceux-2.2.2/attic/configure-mingw32 new file mode 100644 index 00000000..faf8fb03 --- /dev/null +++ b/branches/fceux-2.2.2/attic/configure-mingw32 @@ -0,0 +1 @@ +CFLAGS="-mno-cygwin" CXXFLAGS="-mno-cygwin" LDFLAGS="-mno-cygwin" ./configure --host=mingw32 \ No newline at end of file diff --git a/branches/fceux-2.2.2/attic/configure.ac b/branches/fceux-2.2.2/attic/configure.ac new file mode 100644 index 00000000..a788deae --- /dev/null +++ b/branches/fceux-2.2.2/attic/configure.ac @@ -0,0 +1,101 @@ +AC_INIT([src/fceu.cpp]) + +AC_CANONICAL_HOST +AC_CANONICAL_TARGET +AM_INIT_AUTOMAKE([fceu], $FCEU_VERSION) + +AC_PROG_CC +AC_PROG_CPP +AM_PROG_CC_C_O +AC_PROG_CXX +AC_PROG_CXXCPP +AC_PROG_INSTALL + +AC_DEFINE(_GNU_SOURCE) +AC_CHECK_FUNC(asprintf, AC_DEFINE([HAVE_ASPRINTF]), []) +AC_CHECK_FUNC(alloca, AC_DEFINE([HAVE_ALLOCA]), []) + +dnl Check for zlib +AC_CHECK_LIB([z], [zlibVersion],[], AC_MSG_ERROR([*** zlib not found!])) +LIBS="$LIBS -lz" + +AM_CONDITIONAL(WIN32, false) +AM_CONDITIONAL(UNIX, false) +AM_CONDITIONAL(USE_SEXYAL, false) +AM_CONDITIONAL(OPENGL, false) +AM_CONDITIONAL(HAVE_GTK, false) +AC_DEFINE([NETWORK],[1]) + +if expr x"$target" : 'x.*beos' > /dev/null; then +CFLAGS="-no-fpic $CFLAGS" +CPPFLAGS="-no-fpic $CPPFLAGS" +AC_DEFINE([PSS_STYLE],[1]) +elif expr x"$target" : 'x.*mingw' > /dev/null; then +AC_DEFINE([PSS_STYLE],[2]) +AC_DEFINE([WIN32]) +AM_CONDITIONAL(WIN32, true) + +else +AM_CONDITIONAL(UNIX, true) +AC_DEFINE([UNIX]) +AC_DEFINE([PSS_STYLE],[1]) +AC_DEFINE([NETWORK],[1]) + +dnl AC_CHECK_HEADER([sys/soundcard.h], +dnl AM_CONDITIONAL(USE_SEXYAL, true) +dnl AC_DEFINE([USE_SEXYAL]),[]) +fi + +dnl if expr x"$target" : 'x.*darwin' > /dev/null; then +dnl AC_DEFINE([MACOSX]) +dnl fi + +if test x$use_nativewin32 = xno; then + dnl Check for SDL + SDL_VERSION=1.2.0 + AM_PATH_SDL($SDL_VERSION, [:], + AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])) + + AC_LANG_CPLUSPLUS + LIBS="$LIBS $SDL_LIBS" + CFLAGS="-Wall -fomit-frame-pointer $CFLAGS $SDL_CFLAGS" + CPPFLAGS="-Wall -fomit-frame-pointer $CPPFLAGS $SDL_CFLAGS" + + dnl Check for SDL_net for net play + HAS_SDL_NET=no + dnl AC_CHECK_LIB([SDL_net], [SDLNet_Init],[HAS_SDL_NET=yes]) + dnl if test x$HAS_SDL_NET = xyes; then + dnl AC_DEFINE([NETWORK]) + dnl LIBS="$LIBS -lSDL_net" + dnl fi + + AC_ARG_WITH(opengl, + [AC_HELP_STRING([--with-opengl], + [use OpenGL])], + use_opengl=$withval, + use_opengl="no") + + if [[ "$use_opengl" = "yes" ]] ; then + dnl Check for OpenGL + + AC_CHECK_HEADER([GL/gl.h],[AC_DEFINE([OPENGL]) AM_CONDITIONAL(OPENGL, true)], + [ + AC_CHECK_HEADER([OpenGL/gl.h],[AC_DEFINE([OPENGL]) AM_CONDITIONAL(OPENGL, true)],[]) + AC_DEFINE([APPLEOPENGL]) + ]) + fi + AC_DEFINE([SDL],[1]) +fi + + +if expr match "$target_cpu" 'i.86' > /dev/null; then + AC_DEFINE([C80x86]) +fi + +AC_C_BIGENDIAN([], [AC_DEFINE([LSB_FIRST])]) + + +AC_DEFINE(FRAMESKIP) + +dnl Output Makefiles +AC_OUTPUT([Makefile src/Makefile]) diff --git a/branches/fceux-2.2.2/attic/depcomp b/branches/fceux-2.2.2/attic/depcomp new file mode 100755 index 00000000..807b991f --- /dev/null +++ b/branches/fceux-2.2.2/attic/depcomp @@ -0,0 +1,423 @@ +#! /bin/sh + +# depcomp - compile a program generating dependencies as side-effects +# Copyright 1999, 2000 Free Software Foundation, Inc. + +# 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, 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., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Alexandre Oliva . + +if test -z "$depmode" || test -z "$source" || test -z "$object"; then + echo "depcomp: Variables source, object and depmode must be set" 1>&2 + exit 1 +fi +# `libtool' can also be set to `yes' or `no'. + +if test -z "$depfile"; then + base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'` + dir=`echo "$object" | sed 's,/.*$,/,'` + if test "$dir" = "$object"; then + dir= + fi + # FIXME: should be _deps on DOS. + depfile="$dir.deps/$base" +fi + +tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} + +rm -f "$tmpdepfile" + +# Some modes work just like other modes, but use different flags. We +# parameterize here, but still list the modes in the big case below, +# to make depend.m4 easier to write. Note that we *cannot* use a case +# here, because this file can only contain one case statement. +if test "$depmode" = hp; then + # HP compiler uses -M and no extra arg. + gccflag=-M + depmode=gcc +fi + +if test "$depmode" = dashXmstdout; then + # This is just like dashmstdout with a different argument. + dashmflag=-xM + depmode=dashmstdout +fi + +case "$depmode" in +gcc3) +## gcc 3 implements dependency tracking that does exactly what +## we want. Yay! Note: for some reason libtool 1.4 doesn't like +## it if -MD -MP comes after the -MF stuff. Hmm. + "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + mv "$tmpdepfile" "$depfile" + ;; + +gcc) +## There are various ways to get dependency output from gcc. Here's +## why we pick this rather obscure method: +## - Don't want to use -MD because we'd like the dependencies to end +## up in a subdir. Having to rename by hand is ugly. +## (We might end up doing this anyway to support other compilers.) +## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like +## -MM, not -M (despite what the docs say). +## - Using -M directly means running the compiler twice (even worse +## than renaming). + if test -z "$gccflag"; then + gccflag=-MD, + fi + "$@" -Wp,"$gccflag$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +## The second -e expression handles DOS-style file names with drive letters. + sed -e 's/^[^:]*: / /' \ + -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" +## This next piece of magic avoids the `deleted header file' problem. +## The problem is that when a header file which appears in a .P file +## is deleted, the dependency causes make to die (because there is +## typically no way to rebuild the header). We avoid this by adding +## dummy dependencies for each header file. Too bad gcc doesn't do +## this for us directly. + tr ' ' ' +' < "$tmpdepfile" | +## Some versions of gcc put a space before the `:'. On the theory +## that the space means something, we add a space to the output as +## well. +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +sgi) + if test "$libtool" = yes; then + "$@" "-Wp,-MDupdate,$tmpdepfile" + else + "$@" -MDupdate "$tmpdepfile" + fi + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + + if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files + echo "$object : \\" > "$depfile" + + # Clip off the initial element (the dependent). Don't try to be + # clever and replace this with sed code, as IRIX sed won't handle + # lines with more than a fixed number of characters (4096 in + # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; + # the IRIX cc adds comments like `#:fec' to the end of the + # dependency line. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ + tr ' +' ' ' >> $depfile + echo >> $depfile + + # The second pass generates a dummy entry for each header file. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ + >> $depfile + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +aix) + # The C for AIX Compiler uses -M and outputs the dependencies + # in a .u file. This file always lives in the current directory. + # Also, the AIX compiler puts `$object:' at the start of each line; + # $object doesn't have directory information. + stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` + tmpdepfile="$stripped.u" + outname="$stripped.o" + if test "$libtool" = yes; then + "$@" -Wc,-M + else + "$@" -M + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + + if test -f "$tmpdepfile"; then + # Each line is of the form `foo.o: dependent.h'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" + sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +tru64) + # The Tru64 compiler uses -MD to generate dependencies as a side + # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. + # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put + # dependencies in `foo.d' instead, so we check for that too. + # Subdirectories are respected. + dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` + test "x$dir" = "x$object" && dir= + base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` + + if test "$libtool" = yes; then + tmpdepfile1="$dir.libs/$base.lo.d" + tmpdepfile2="$dir.libs/$base.d" + "$@" -Wc,-MD + else + tmpdepfile1="$dir$base.o.d" + tmpdepfile2="$dir$base.d" + "$@" -MD + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile1" "$tmpdepfile2" + exit $stat + fi + + if test -f "$tmpdepfile1"; then + tmpdepfile="$tmpdepfile1" + else + tmpdepfile="$tmpdepfile2" + fi + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" + # That's a space and a tab in the []. + sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" + else + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +#nosideeffect) + # This comment above is used by automake to tell side-effect + # dependency tracking mechanisms from slower ones. + +dashmstdout) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test $1 != '--mode=compile'; do + shift + done + shift + fi + + # Remove `-o $object'. We will use -o /dev/null later, + # however we can't do the remplacement now because + # `-o $object' might simply not be used + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + test -z "$dashmflag" && dashmflag=-M + "$@" -o /dev/null $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + tr ' ' ' +' < "$tmpdepfile" | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +dashXmstdout) + # This case only exists to satisfy depend.m4. It is never actually + # run, as this mode is specially recognized in the preamble. + exit 1 + ;; + +makedepend) + "$@" || exit $? + # X makedepend + shift + cleared=no + for arg in "$@"; do + case $cleared in + no) + set ""; shift + cleared=yes ;; + esac + case "$arg" in + -D*|-I*) + set fnord "$@" "$arg"; shift ;; + -*) + ;; + *) + set fnord "$@" "$arg"; shift ;; + esac + done + obj_suffix="`echo $object | sed 's/^.*\././'`" + touch "$tmpdepfile" + ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + sed '1,2d' "$tmpdepfile" | tr ' ' ' +' | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" "$tmpdepfile".bak + ;; + +cpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test $1 != '--mode=compile'; do + shift + done + shift + fi + + # Remove `-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + "$@" -E | + sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | + sed '$ s: \\$::' > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + cat < "$tmpdepfile" >> "$depfile" + sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvisualcpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + "$@" || exit $? + IFS=" " + for arg + do + case "$arg" in + "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") + set fnord "$@" + shift + shift + ;; + *) + set fnord "$@" "$arg" + shift + shift + ;; + esac + done + "$@" -E | + sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" + echo " " >> "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +none) + exec "$@" + ;; + +*) + echo "Unknown depmode $depmode" 1>&2 + exit 1 + ;; +esac + +exit 0 diff --git a/branches/fceux-2.2.2/attic/fceu-svga.6 b/branches/fceux-2.2.2/attic/fceu-svga.6 new file mode 100644 index 00000000..a2f7e503 --- /dev/null +++ b/branches/fceux-2.2.2/attic/fceu-svga.6 @@ -0,0 +1,135 @@ +.\" t Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH FCEU-SVGA 6 "March 27, 2003" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +fceu-svga \- An emulator for the original (8-bit) Nintendo game console. +.SH SYNOPSIS +.B fceu-svga +.RI [ options ] +"filename" +.SH DESCRIPTION +.B FCE Ultra +is an emulator for the original (8-bit) Nintendo Entertainment System (NES). +It has a robust color palette rendering engine that is fully customizable, +along with excellent sound and joystick support, and even includes TCP/IP based +network playing for head-to-head gaming with your friends! +.PP +The emulator is available in two versions for Linux (there are also versions +for DOS and Windows): an SDL-based version, and one based on SVGALIB. The two +versions are essentially the same \-\- use the SVGALIB version for the Linux +console, and the SDL version for playing in X. +.SH OPTIONS +These are some of the more frequently used options in FCE Ultra SVGALIB. Run +fceu-svga without any options for a larger list, or see the README for the full +list. +.TP +.BI \-gg +Enable Game Genie emulation support. +.TP +.BI "\-cpalette " +Use the custom palette in . +.TP +.BI "\-soundvol " +Sets the sound volume to the given percentage. +.TP +.BI "\-sound " +Set the sound playback sample rate (0 == off). +.TP +.BI "\-connect " +Connect as a client (player 2) to for TCP/IP network play. +.TP +.BI \-server +Be a host server (player 1) for a TCP/IP network game. +.TP +.BI "\-netport " +Use for TCP/IP network play. +.SH KEYBOARD COMMANDS +.B FCE Ultra +has a number of commands available within the emulator. +It also includes default keyboard bindings when emulating game pads or power pads. +.SS Gamepad Keyboard Bindings +.TS +center box; +cb | cb, c | ci. +NES Gamepad Keyboard += +Arrows Cursor Arrows +A Left ALT +B Left CTRL +Select TAB +Start ENTER +.TE +.SS Other Commands +.PP +.TP 15 +.BI +Activate cheat interface. +.TP 15 +.BI +Lock virtual console. +.TP 15 +.BI +Unlock virtual console. +.TP 15 +.BI +Save game state into current slot (set using number keys). +.TP 15 +.BI +Restore game state from current slot (set using number keys). +.TP 15 +.BI +Save screen snapshot. +.TP 15 +.BI +Reset NES. +.TP 15 +.BI +Toggle power to NES. +.TP 15 +.BR ", " +Quit +.B FCE Ultra. +.SH NOTES +This program needs permisison to the video hardware, this normally requires +root access. One way to accomplish this is by making +.BI "fceu-svga " suid-root. +An easy way to do this is using the +.BR dpkg-statoverride +command. For example, as root on a +.I Debian +system run: +.PP +.B dpkg-statoverride --update --add root games 04755 /usr/games/fceu-svga +.PP +This will ensure that the setuid bit is preserved across package upgrades. +.SH SEE ALSO +.BR dpkg-statoverride "(8), " fceu-sdl (6) +.TP +.I /usr/share/doc/fceu-doc/readme-linux.txt.gz +The +.B FCE Ultra README +for linux, available from the +.I fceu-doc +Debian package. +.TP +.I http://fceultra.sourceforge.net/ +The +.B FCE Ultra +project homepage. +.SH AUTHOR +This manual page was written by Joe Nahmias , +for the Debian GNU/Linux system (but may be used by others). diff --git a/branches/fceux-2.2.2/attic/install-sh b/branches/fceux-2.2.2/attic/install-sh new file mode 100755 index 00000000..11870f1b --- /dev/null +++ b/branches/fceux-2.2.2/attic/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + : +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=$mkdirprog + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f "$src" ] || [ -d "$src" ] + then + : + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + : + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + : + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' + ' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + : + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + : + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/branches/fceux-2.2.2/attic/missing b/branches/fceux-2.2.2/attic/missing new file mode 100755 index 00000000..6a37006e --- /dev/null +++ b/branches/fceux-2.2.2/attic/missing @@ -0,0 +1,336 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. +# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. +# Originally by Fran,cois Pinard , 1996. + +# 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, 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., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch]" + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing 0.4 - GNU automake" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. + You can get \`$1Help2man' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` + test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then + # We have makeinfo, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar "$@" && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar "$@" && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" "$@" && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequirements for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 diff --git a/branches/fceux-2.2.2/attic/mkinstalldirs b/branches/fceux-2.2.2/attic/mkinstalldirs new file mode 100755 index 00000000..8ab885ec --- /dev/null +++ b/branches/fceux-2.2.2/attic/mkinstalldirs @@ -0,0 +1,99 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman +# Created: 1993-05-16 +# Public domain + +errstatus=0 +dirmode="" + +usage="\ +Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." + +# process command line arguments +while test $# -gt 0 ; do + case "${1}" in + -h | --help | --h* ) # -h for help + echo "${usage}" 1>&2; exit 0 ;; + -m ) # -m PERM arg + shift + test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; } + dirmode="${1}" + shift ;; + -- ) shift; break ;; # stop option processing + -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option + * ) break ;; # first non-opt arg + esac +done + +for file +do + if test -d "$file"; then + shift + else + break + fi +done + +case $# in +0) exit 0 ;; +esac + +case $dirmode in +'') + if mkdir -p -- . 2>/dev/null; then + echo "mkdir -p -- $*" + exec mkdir -p -- "$@" + fi ;; +*) + if mkdir -m "$dirmode" -p -- . 2>/dev/null; then + echo "mkdir -m $dirmode -p -- $*" + exec mkdir -m "$dirmode" -p -- "$@" + fi ;; +esac + +for file +do + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` + shift + + pathcomp= + for d + do + pathcomp="$pathcomp$d" + case "$pathcomp" in + -* ) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + else + if test ! -z "$dirmode"; then + echo "chmod $dirmode $pathcomp" + + lasterr="" + chmod "$dirmode" "$pathcomp" || lasterr=$? + + if test ! -z "$lasterr"; then + errstatus=$lasterr + fi + fi + fi + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# Local Variables: +# mode: shell-script +# sh-indentation: 3 +# End: +# mkinstalldirs ends here diff --git a/branches/fceux-2.2.2/attic/readme b/branches/fceux-2.2.2/attic/readme new file mode 100644 index 00000000..ca3c2e5b --- /dev/null +++ b/branches/fceux-2.2.2/attic/readme @@ -0,0 +1,32 @@ +FCE Ultra was developed with gcc and GNU make in mind. MSVC will probably +compile the Windows source code with a few modifications, but you'll still +need to make a project file. + +Several pre-made makefiles are provided: + Makefile.beos - BeOS(with SDL and SDL_net) + Makefile.unixsdl - UN*X(FreeBSD/Linux/etc, with SDL) + Makefile.linuxvga - Linux(with svgalib) + Makefile.dos - (MS/PC/DR) DOS + Makefile.win - MS Windows 9x/Me/Xp/2000/etc.(with DirectX). + Makefile.macosx - Mac OS X(with SDL) + +If you want to use Makefile.beos or Makefile.unixsdl for a cpu type other +than 80x86, you will need to remove "-DC80x86" from the defines line +and also remove "-DLSB_FIRST" if your target cpu uses MSB first ordering. +You'll also need to remove/change "-mcpu=xxx". + +For the Windows port, I use MINGW32. http://www.mingw.org + +To compile the DOS port, you'll need to download the DJGPP package. +Any version of gcc >=2.95.3 should compile the code without changes, BUT +the DJGPP versions of gcc have some problems: + gcc 2.95.3 sometimes breaks when compiling the code. gcc 3.0.2 seems to + produce bad code for sound.c. So, I recommend using gcc 3.0.4 for + compiling the DOS version. + +Modifying the "-mcpu=i686" string in the makefiles, to optimize more effectively +for your cpu type, is a good idea. + +Always do a "make -f Makefile. clean" before compiling for a +different platform or if you update via cvs and if you have stale object +files lying around. diff --git a/branches/fceux-2.2.2/changelog.txt b/branches/fceux-2.2.2/changelog.txt new file mode 100644 index 00000000..4eebbd5d --- /dev/null +++ b/branches/fceux-2.2.2/changelog.txt @@ -0,0 +1,817 @@ + +23-Sep-2013 - AnS - Tracer: do not clear window log when stopping the logging +22-Sep-2013 - AnS - Tracer: the dialog window can be resized +21-Sep-2013 - AnS - Debugger: newly created Bookmarks inherit existing symbolic name by default +20-Sep-2013 - AnS - Debugger, Tracer: clicking on Symbolic names works as well as clicking on addresses +17-Sep-2013 - zeromus - fixed "Single Instance Mode" +16-Sep-2013 - AnS - PPU Viewer: added "Mask unused graphics" and "Invert the mask" checkboxes; fixed window layout when using big fonts +15-Sep-2013 - feos - Lua: added tobitstring(), memory.readword(int address1 [, int address2]), memory.readwordsigned(int address1 [, int address2]) functions +15-Sep-2013 - CaH4e3 - mapper 002 - workaround for "Top Gun" issue #621, needs testing if this broke something else; mapper 012 - added hardware dip for language select; UNIF PEC-586 - fixed render finally, added 512K cartridges suppport, TODO: PEC keyboard +13-Sep-2013 - AnS - debuggerFontSize and hexeditorFontSize can be specified in fceux.cfg +13-Sep-2013 - AnS - Debugger: "Symbolic Debug" state is now saved in global fceux.cfg instead of different .deb files +12-Sep-2013 - AnS - Tracer: added mouse wheel support +12-Sep-2013 - AnS - Tracer: clicking any address select the address; double-clicking any address brings Debugger at the address +12-Sep-2013 - AnS - Tracer: added Symbolic Debug naming by right-clicking any address +10-Sep-2013 - feos - Hexeditor: Symbolic Debug naming by right-clicking address +10-Sep-2013 - AnS - Debugger: added Symbolic Debug naming by right-clicking any address +05-Sep-2013 - AnS - Debugger: fixed Cycles counter reset when loading an earlier savestate +15-Aug-2013 - CaH4e3 - fixed bandai mapper emulation +04-Aug-2013 - AnS - Hexeditor: added "Highlighting" submenu and "Highlight Activity" feature +04-Aug-2013 - AnS - Taseditor: an experiment with somewhat different colors for HotChanges +04-Aug-2013 - AnS - Auto-disable "Game Genie ROM" feature when no "gg.rom" file is found +16-Jul-2013 - AnS - Debugger: highlight PC pointer line when a breakpoint is hit +05-Jul-2013 - AnS - RAM Search: added "Hex Editor" button and right-click +04-Jul-2013 - AnS - Debugger: added CDL data column in place of left panel. It helps to distinguish executed branches of code from not logged code +04-Jul-2013 - AnS - Debugger: clever autoscrolling when stepping/seeking to PC. It maintains relative position of the ">" pointer inside the Disassembly window +03-Jul-2013 - AnS - RAM Watch: fixed epic bug when contents of old .wch file mixed with the newly saved data because of "r+b" mode (changed it to "w+b") +03-Jul-2013 - AnS - Taseditor: Greenzone: always keep Greenzone.lagLog in touch with history.currentSnapshot.laglog (fixes workflow with "Auto-adjust" disabled) +03-Jul-2013 - AnS - Tracer: only output "from $XXXX" when the subroutine was called by JSR (fixes possible errors in those cases when the subroutine was called using stack magic) +03-Jul-2013 - AnS - Debugger: do not reload ram.nl every time automatically +21-Jun-2013 - CaH4e3 - PPU Viewer: when CDLogger is on, display unused graphics in a dim palette +15-Jun-2013 - AnS - Movie recording: fixed bug when emulator allowed recording commands outside the range of FM2 specs +15-Jun-2013 - AnS - Movie recording: added ability to record "Insert coin" command (for VS games) +15-Jun-2013 - AnS - Movie recording: remember last Author name when creating a new movie +08-Jun-2013 - AnS - A couple of fixes which deal with "multiple ROMs in a single archive" case. The loading procedure now takes into account actual ROM name when loading ROM from an archive containing multiple files. This affects PAL/NTSC detection (in case there were ROMs of different regions inside a single zip). Also, "auto-resume play" now loads actual ROM on startup (instead of prompting a list of archived files to choose). Also, NL files (symbolic debug) are named correctly when debugging a ROM from such an archive, etc. +08-Jun-2013 - AnS - Hexeditor: fixed bugs when saving files while working with ROMs in archives +27-May-2013 - AnS - Hexeditor: specify Data bank condition when adding a Breakpoint by context menu +26-May-2013 - AnS - Debugger: added 'T' condition (checks the bank of the data accessed) +26-May-2013 - AnS - Win32: fixed storing and loading .deb files when working with archived ROMs +26-May-2013 - AnS - new Lua functions: debugger.hitbreakpoint(), debugger.getcyclescount(), debugger.getinstructionscount(), debugger.resetcyclescount(), debugger.resetinstructionscount() +26-May-2013 - AnS - Win32: when no script is currently running, Shift+L loads the most recent Lua script +26-May-2013 - CaH4e3 - fixed mapper 183 +14-May-2013 - CaH4e3 - fixed mapper 253 +13-May-2013 - CaH4e3 - mapper 43 +09-May-2013 - AnS - Video config: changed "Disable hardware acceleration" option to a drop-down list with 3 options: a) No hardware acceleration; b) Create surface in RAM; c) Hardware acceleration. Because it appears that some video cards still blur textures even when stored in RAM. +29-Apr-2013 - AnS - added checking if archive file has any files in it, because new 7z.dll confuses FDS files with archives (it recognizes the first "F" as a signature of an archive) +19-Apr-2013 - AnS - Video config: added "Square pixels" option +19-Apr-2013 - AnS - Video config: added aspect ratio fields for customizing "TV Aspect" ratio, by default it's 4:3 +17-Apr-2013 - AnS - "Auto-resume old play session" now also works with NSFs +17-Apr-2013 - zeromus - properly savestate NSF +17-Apr-2013 - zeromus - add missing mmc5 savestate variables +16-Apr-2013 - AnS - Tracer: added "Log Cycles count" and "Log Instructions count" options +13-Apr-2013 - AnS - Debugger: scrolling up/down by whole instructions +12-Apr-2013 - gocha - Lua: fix wrong frequency calculation in sound.get() +07-Apr-2013 - AnS - Taseditor: comply with Lua movie.rerecordcounting() setting +01-Apr-2013 - CaH4e3 - mapper 154 - fixed +26-Mar-2013 - CaH4e3 - mapper 53 - supported ines format of SUPERVISION UNIF board; UNIF 8157 - fix according to hw; UNIF T-262 - fix according to hw +24-Mar-2013 - CaH4e3 - UNIF DANCE2000 - now emulated properly +20-Mar-2013 - gocha - link to lua51.dll instead of static linking +19-Mar-2013 - zeromus - bring some improvements to newppu from bizhawk, and fix vtoggle5/6 back to vtoggle +19-Mar-2013 - zeromus - fix mapper 28 +17-Mar-2013 - AnS - Replay: removed redundant window update when using "Browse" (fixes #585) +17-Mar-2013 - CaH4e3 - UNIF DSOUNDV1 - removed due to duplicate of 178 mapper; mapper 178 - added more features of 8/16M carts with 32K SRAM; UNIF 09-034A - added support for a new SMB2j Lite version +14-Mar-2013 - AnS - Debugger: ported "smart scrolling" from an obscure version of FCEUXD 1.1 +14-Mar-2013 - CaH4e3 - palette ram reading fix for old ppu + +---r2869 - FCEUX 2.2.1 Released--- +---March 10 2013--- + +10-Mar-2013 - prg - SDL: added option to use system minizip +10-Mar-2013 - prg - updated to use minizip v1.2.7 +10-Mar-2013 - CaH4e3 - CDLogger: improved CHR logging, now it also logs the data when using Old PPU +02-Mar-2013 - AnS - Hexeditor: fixed ROM coloring when using CDLogger data +28-Feb-2013 - AnS - PPU/PAL/Input type changing is now disabled when a movie is playing +28-Feb-2013 - AnS - Cheats: update the window when ROM is changed +28-Feb-2013 - AnS - show the number of active cheats when a ROM is loaded +27-Feb-2013 - CaH4e3 - CDLogger: added "Auto-load .CDL when opening the window" option +27-Feb-2013 - CaH4e3 - MMC5 refixed +24-Feb-2013 - AnS - CDLogger: added "Auto-save .CDL when closing ROMs" and "Auto-resume logging when loading ROMs" options +23-Feb-2013 - AnS - Hexeditor: show symbolic names in the window caption +18-Feb-2013 - CaH4e3 - various mapper improvements; UNIF MALISB - Mali Splash Bomb dump; mapper 19 - Dream Master mirror fix +18-Feb-2013 - CaH4e3 - fixed mapper 69 low quality sound issue +11-Feb-2013 - AnS - fixed possible crash when saving the ROM in Hex Editor +11-Feb-2013 - AnS - Moved "Config->Game Genie" to "Config->Enable->Game Genie ROM" +03-Feb-2013 - AnS - win32: speed up screen blitting +02-Feb-2013 - AnS - Added "TV Aspect (4:3)" to Video Config +21-Jan-2013 - AnS - Taseditor: fixed Bookmarks List height on Windows 7 +21-Jan-2013 - AnS - Taseditor: fixed bug with adding new item to History Log +20-Jan-2013 - AnS - Taseditor: changed the logic by which the Piano Roll follows Playback cursor, now it doesn't follow it while seeking +15-Jan-2013 - AnS - Lua: removed "shadow pixels" from gui.text(), made gui.parsecolor() function available for users +10-Jan-2013 - AnS - Taseditor: Config->Project file saving options +01-Jan-2013 - zeromus - NameTableViewer: do something reasonable if a 4-screen, table2, table3 mirror mode is chosen when the corresponding nametable ram is not available on the cart (instead of crashing) +31-Dec-2012 - CaH4e3 - fixed mappers 24, 26, 115 +29-Dec-2012 - AnS - Taseditor: Changed "Compact save" dialog, added 4 options of Greenzone saving +29-Dec-2012 - AnS - Cheats: added "Add from CHT file..." button +29-Dec-2012 - AnS - win32: force the entire client area to be invalidated at the beginning of WM_PAINT; this fixes the rare bug with DIRECTDRAWCLIPPER sometimes calculating wrong region (was noticed on some video cards) +27-Dec-2012 - AnS - Play movie dialog shows New PPU in red if the required setting does not match +27-Dec-2012 - thezlomus - RAM Search: added "Search ROM" checkbox +19-Dec-2012 - AnS - win32: remodel "Video config" dialog +19-Dec-2012 - AnS - win32: fixed restoring maximized window after switching from fullscreen +18-Dec-2012 - CaH4e3 - fixed mapper 018 and 198 +15-Dec-2012 - AnS - win32: added Config->Enable->Auto-resume old play session +13-Dec-2012 - AnS - win32: added Emulation Speed->Set custom speed for FrameAdvance +13-Dec-2012 - AnS - win32: added NES->Emulation Speed->Set FrameAdvance Delay +13-Dec-2012 - AnS - win32: added NES->Emulation Speed->Set Custom Speed +12-Dec-2012 - CaH4e3 - finish with mapper to boards conversion +07-Dec-2012 - CaH4e3 - Tracer: fixed RAM-located code logging when CDLogger options are enabled +05-Dec-2012 - AnS - fixed zapper and mouse positioning in fullscreen +04-Dec-2012 - AnS - speed up HUD text drawing +04-Dec-2012 - AnS - Taseditor: speed up consecutive Recordings (when combining) +03-Dec-2012 - AnS - Taseditor: fixed accelerators when editing Notes +03-Dec-2012 - AnS - fixed "X" button in the "Enter New Input" dialog (Hotkey Mapping); changed "Cancel" button to "OK" +03-Dec-2012 - CaH4e3 - fixed mapper 99 +29-Nov-2012 - zeromus - fix "you ling xing dong" by assigning to mapper 192 + +---r2768 - FCEUX 2.2.0 Released--- +---November 27 2012--- + +24-Nov-2012 - AnS - when the New PPU is on, it displays "(NewPPU)" in the window caption +20-Nov-2012 - AnS - Taseditor: added "Ungreenzone" item to context menu; added "Config->Enable Greenzoning" +13-Nov-2012 - AnS - Taseditor: changed fm3 format to version 3 +10-Nov-2012 - AnS - win32 hotkeys mapping: added the condition that both commands must have the same EMUCMDFLAG_TASEDITOR, or else they are not considered conflicting +10-Nov-2012 - AnS - win32 hotkeys: disallow unwanted hits of e.g. F1 after pressing Shift+F1 and quickly releasing Shift +05-Nov-2012 - zeromus - support mapper 028 +05-Nov-2012 - AnS - Taseditor: fixed lag adjustments when dealing with previously unknown lag state +30-Oct-2012 - zeromus - default stack pointer to $FD instead of $FF +29-Oct-2012 - CaH4e3 - mapper 252 added +29-Oct-2012 - AnS - Taseditor: update RAM Search and RAM Watch when jumping causes game state to change +21-Oct-2012 - CaH4e3 - sync mappers with fceu-mm +30-Sep-2012 - AnS - added "(Europe)" and "(PAL)" strings to region detection +28-Sep-2012 - AnS - Hexeditor: Ctrl+F opens Find dialog +28-Sep-2012 - AnS - Hexeditor: display 0x5000-0x5FFF contents +28-Sep-2012 - AnS - Tracer: fixed crash when logging undefined opcodes +26-Sep-2012 - AnS - Debugger: "Name" button in Bookmarks, total revamp of Bookmarks +26-Sep-2012 - AnS - Debugger: single click on any address copies this address to the "Seek To" field and "Bookmark Add" field +26-Sep-2012 - AnS - Fixed replay engine bug that doubles the last input of the movie +26-Sep-2012 - AnS - Tracer: "RTS" instructions now output the subroutine address/name +23-Sep-2012 - AnS - Lua: clear previous frame drawings at the beginning of every frame +23-Sep-2012 - AnS - Debugger: fixed mouseover when using Symbolic debug; mouseover works for the disassembly window too +23-Sep-2012 - CaH4e3 - CDLogger: Now can log VROM access (CHR banks of the ROM) when NewPPU is enabled +22-Sep-2012 - AnS - Tracer: added "Symbolic trace", "Log current Frame number", "Log emulator messages", "Log breakpoint hits" options +11-Sep-2012 - AnS - new Lua function: emu.setlagflag() +11-Sep-2012 - AnS - Debugger: deleting a breakpoint leaves selection in the Breakpoints list +06-Sep-2012 - AnS - added "Use Custom Palette" checkbox to Palette config +06-Sep-2012 - AnS - Debugger: special strings (NMI/IRQ/etc) can be also used in "Seek To" field and Bookmarks +01-Sep-2012 - AnS - fixed movie savestates logic, loading post-movie savestates is not allowed in read-only +31-Aug-2012 - zeromus - update mapper 156 from fceu-mm sources +30-Aug-2012 - AnS - fixed savestates filenaming bug when working with a movie +29-Aug-2012 - AnS - added "Force Grayscale" checkbox to Palette config +26-Aug-2012 - AnS - Taseditor: History Log highlights items related to current item +25-Aug-2012 - AnS - Taseditor: fixed AdjustLag feature and changed fm3 version to v2 +22-Aug-2012 - AnS - added "Clear" button to Message Log +20-Aug-2012 - AnS - "Switch fullscreen by double-click" option in GUI config +20-Aug-2012 - AnS - "Hide mouse cursor" and "Use console BG color for empty areas" options +20-Aug-2012 - AnS - total revamp of Video config stuff, Best Fit also works for fullscreen mode +19-Aug-2012 - AnS - win32: "Maintain aspect ratio (best fit)" option in Video config +12-Aug-2012 - AnS - Debugger: "Display ROM offsets" option +12-Aug-2012 - AnS - Debugger: double-click breakpoint also adds current bank number to breakpoint condition +12-Aug-2012 - AnS - Added FPS display to Win32 port (Config->Display->FPS) +10-Aug-2012 - prg - gtk: reset video on video dialog close +10-Aug-2012 - prg - gtk: add gui option for showfps +10-Aug-2012 - prg - sdl: add runtime option for controling drawing fps (SDL.ShowFPS) +10-Aug-2012 - prg - core: move showfps from build option to runtime option +10-Aug-2012 - prg - sdl: fix and enable SHOWFPS build option (TODO: make runtime option) +10-Aug-2012 - AnS - Debugger: "Address Bookmark Add" field follows disassembly window scrolling position +08-Aug-2012 - AnS - Taseditor: frame counter display is auto-on when Taseditor launches +08-Aug-2012 - AnS - Debugger: improved stack display +08-Aug-2012 - AnS - Debugger: doubleclick on the disassembly prompts "Add Execute breakpoint" dialog +08-Aug-2012 - AnS - Debugger: fixed RAM peek by a rightclick on left pane +08-Aug-2012 - AnS - Debugger: ">" points at current line in disassembly +08-Aug-2012 - AnS - Debugger: show the number of breakpoints (enabled and total) above the breakpoints list +06-Aug-2012 - CaH4e3 - fixed bug when loading UNF games (#525 ) +06-Aug-2012 - AnS - Tracer also updates its window when user pauses the game, not just when Debugger snaps +06-Aug-2012 - AnS - Tracer: added "Use Stack Pointer for code tabbing" option and added "To the left from disassembly text" option +05-Aug-2012 - AnS - Debugger: .DEB file now also stores the state of "Break on Bad Opcode" and "Break when exceed" checkboxes/editfields +05-Aug-2012 - AnS - Debugger: added "CPU cycles" and "Instructions" counters (request #527) and added "Break when exceed" breakpoints +05-Aug-2012 - AnS - Debugger: window layout cleanup +06-Aug-2012 - prg - gtk: added hotkey gui config +04-Aug-2012 - prg - all: updated FSF address +04-Aug-2012 - prg - sdl: added SDL.Input.EnableOppositeDirectional option. allows/disallows simultaneous right+left / up+down. +03-Aug-2012 - AnS - Debugger: highlighting breakpoint item in BPs list when it's triggered +03-Aug-2012 - AnS - Debugger: allow Frame Advancing when Debugger is in breakpoint state +03-Aug-2012 - AnS - Debugger: don't update Debugger window at the beginning of Step command (it will update at at the end of Step) - fixes #528 +25-Jul-2012 - AnS - Taseditor: auto-starting Note editing when creating Marker by double-click +19-Jul-2012 - AnS - Taseditor: Lua registermanual allows changing the "Run function" button caption; Markers are always restored when deploying Bookmarks +01-Jul-2012 - AnS - new hotkey "Run Manual Lua function" +24-Jun-2012 - AnS - Taseditor: drawing selected_slot border in Branches Tree +24-Jun-2012 - zeromus - add ability for CNROM games to choose whether they have bus conflicts (fixes Colorful Dragon (Unl) (Sachen), since it flakes out if bus conflicts are emulated) +23-Jun-2012 - zeromus - add m116 from fceu-mm; fix mapper 178 big PRG support +20-Jun-2012 - zeromus - fix savestate engine to throw errors when a buggy SFORMAT is passed to AddExState, and fix those errors in m015 and m253 +19-Jun-2012 - AnS - added TASEDITOR type of hotkeys +19-Jun-2012 - AnS - Taseditor: 2 new hotkeys: "Switch Auto-restoring" (Ctrl+Spacebar), "Switch current Multitracking mode" (W) +16-Jun-2012 - AnS - Taseditor: drawing patterns with Alt held; no more row_last_clicked +15-Jun-2012 - AnS - Taseditor: added "rewatch from Selection to Playback" feature for Ctrl+middle click action +14-Jun-2012 - AnS - Taseditor: combining consecutive AdjustLag operations +13-Jun-2012 - AnS - Taseditor: truncated Greenzone is drawn by pale colors, not just white +12-Jun-2012 - AnS - Taseditor: "Auto-adjust Input due to lag" checkbox +11-Jun-2012 - AnS - Taseditor: green arrow doesn't disappear when Playback cursor goes through it +11-Jun-2012 - AnS - Taseditor: changed icons column in Piano Roll, now can show both Bookmark and arrow +09-Jun-2012 - zeromus - win32-support funny languages for opening roms, through drag&drop, at least +06-Jun-2012 - AnS - Taseditor: small fix for Branches Tree - among bookmarks with equal jump_frame the cursor must be pointing at current branch +06-Jun-2012 - zeromus - support mapper 176. mapper 176 no longer maps to BMCFK23C. BMCFK23C is still accessible through crc or unif? test case would be welcome. it is unclear to me why mapper 176 control was removed from 176.cpp and given to BMCFK23C +06-Jun-2012 - AnS - Taseditor: autosave works only when project has a filename +26-May-2012 - AnS - Taseditor: Ctrl+Space accelerator = toggle "Auto-restore last position" checkbox; remapped "Restore Playback" hotkey to Spacebar; "Restore Playback" also pauses seeking; mid-click = "Restore Playback" when possible +08-May-2012 - AnS - Taseditor: changed "lost_position" logic +01-May-2012 - AnS - Lua functions emu.pause() and emu.unpause() don't yield and don't reset emulator speed anymore +30-Apr-2012 - AnS - Taseditor: Ctrl + mid click = run to Selection cursor; Shift + mid click = run to nearest Marker +26-Apr-2012 - AnS - Taseditor: fixed filename logic when user creates project from an fm2 or a corrupted fm3 +23-Apr-2012 - AnS - Taseditor: menus overhaul +19-Apr-2012 - AnS - RAM Watch: fixed loading Data Size and Data Type from a .wch, now corrupted .wch won't crash +17-Apr-2012 - zeromus - fix bug in mapper 164 savestates which caused wram to be lost, also make mapper 164 sram work +17-Apr-2012 - AnS - Taseditor: gradual History Log autocompression when idle +14-Apr-2012 - zeromus - add hash database entry for Rasaaru Ishii no Childs Quest (J), whose extant roms specify both the wrong mapper and the wrong mirroring +14-Apr-2012 - zeromus - change mapper 12 (mmc3 variant) to specify MMC3A chip version +14-Apr-2012 - AnS - Taseditor: rightclicks in Branches Tree +14-Apr-2012 - AnS - "Play Movie" dialog doesn't search in fceux root folder anymore +10-Apr-2012 - AnS - bold items in some context menus +10-Apr-2012 - zeromus - fix mapper 115 (actually to fix mapper 248 for Bao Qing Tian) +09-Apr-2012 - zeromus - remove vram protection from mapper 227 +09-Apr-2012 - AnS - Taseditor: all GUI buttons fire off at mousedown; disabled Spacebar and enabled Middle mouse button on GUI buttons +09-Apr-2012 - AnS - Taseditor: clicks in Branches Tree +07-Apr-2012 - AnS - Taseditor: version data in fm3 +07-Apr-2012 - AnS - Taseditor: much better way of calculating Branches Tree; hinting full timelines; miniarrow showing current Playback cursor position in Branches Tree; "Bookmark#" modtype, undo/redo works for Bookmarks +07-Apr-2012 - AnS - Taseditor: applying PAL and PPU flags when loading projects +05-Apr-2012 - zeromus - fix mapper 242 (dragon quest 8 UNL) +26-Mar-2012 - AnS - Taseditor: Alt+Wheel = jump across gaps in Input/Markers +25-Mar-2012 - AnS - returned default mapping of Frame Advance hotkey to Backslash +25-Mar-2012 - AnS - Taseditor: BookmarksList clicks apply on buttonup only +22-Mar-2012 - AnS - Config->Combine consecutive Recordings/Draws +18-Mar-2012 - AnS - new hotkey "Cancel Seeking (TAS Editor)" (Esc) +18-Mar-2012 - AnS - Taseditor: Config->Autopause at the end of Movie +17-Mar-2012 - CaH4e3 - varous bugfixes, xstring trimming functions logic bugs, etc +17-Mar-2012 - AnS - Taseditor: showing row_last_clicked when Shift or Alt is held +17-Mar-2012 - AnS - Taseditor: no more "allow keys in Piano Roll"; new accelerators: Ctrl + arrows, Shift + arrows, Home/End/Page Up/Page Down, Ctrl + Home/End, Shift + Home/End +17-Mar-2012 - AnS - Taseditor: selection by dragging from Frame# +17-Mar-2012 - AnS - Taseditor: set/pick Markers by doubleclick, throw Markers away +14-Mar-2012 - AnS - Taseditor: drawing input; holding Shift when drawing +14-Mar-2012 - AnS - Taseditor: fixed known WinXP bug with scrollbar arrows +14-Mar-2012 - AnS - Taseditor: moving Markers by drag'n'drop, "Marker Drag" and "Marker Swap" operations +14-Mar-2012 - AnS - Taseditor: dragging blue arrow (moving Playback cursor) +14-Mar-2012 - AnS - Taseditor: observing Piano Roll by dragging cursor outside +11-Mar-2012 - AnS - Taseditor: double-tapping Shift/Ctrl scrolls Piano Roll to respective cursor +09-Mar-2012 - AnS - Taseditor: Config->Deselect on doubleclick +09-Mar-2012 - AnS - Taseditor: checking ROM checksum when saving/loading projects +09-Mar-2012 - AnS - Taseditor: TAS Editor can have mouse wheel input even when keyboard focus is on FCEUX window +09-Mar-2012 - AnS - disabled FCEUX context menu when TAS Editor is engaged +06-mar-2012 - prg - fceux no longer segfaults when opening gamepadconfig with GTK < 2.24 - a message is printed to the console +06-mar-2012 - prg - supports loading of configuration files in $FCEUXDIR/cfg.d/* +01-Mar-2012 - AnS - Taseditor: changing history size doesn't reset history +28-feb-2012 - AnS - Taseditor: "Deselect" option in menus +26-feb-2012 - AnS - Small save/load state speedup, noticeable only in TAS Editor or lua bots +21-feb-2012 - AnS - Taseditor: header lights on mouseover +21-feb-2012 - AnS - Taseditor: registering click at buttondown; Alt+click on input = set pattern +20-feb-2012 - AnS - Taseditor: Right button + wheel = Playback rewind/forward; Shift/Ctrl + wheel = jump via Markers with Playback/Selection cursor +20-feb-2012 - AnS - Taseditor: middle button pauses/unpauses emulation +18-feb-2012 - AnS - PATTERNS menu, loading data from "tools\taseditor_patterns.txt" +18-feb-2012 - AnS - "Use pattern" checkbox in Recorder; Config->ColumnSet Pattern skips Lag +18-feb-2012 - AnS - Taseditor: "Frame#" lights when Alt key is being held, not entering menu by Alt +18-feb-2012 - AnS - Changed some checkboxes to radiobuttons in FCEUX menu +13-feb-2012 - AnS - Taseditor: when clicking text fields, Piano Roll scrolls to corresponding Marker, not to cursor +13-feb-2012 - AnS - Replay dialog speedup, now movie is not loaded into memory when checking md5 +06-feb-2012 - AnS - new Lua scripts: SoundDisplay.lua, TrackNoise.lua +06-feb-2012 - AnS - refined Recording, now can safely record commands (Power, Reset, Insert, Switch) +02-feb-2012 - AnS - uploaded HelpNDoc3 project file +02-feb-2012 - AnS - added Lua scripts demonstrating some TAS Editor library functions +02-feb-2012 - AnS - new Lua function in TAS Editor library: getsuperimpose() +02-feb-2012 - AnS - new Lua function in Joypad library: getimmediate() +30-jan-2012 - AnS - Taseditor: 9 new Lua functions in TAS Editor library +30-jan-2012 - AnS - Taseditor: Added "Restore Playback (TAS Editor)" hotkey (Enter by default) +30-jan-2012 - AnS - Taseditor: Help->Show Tooltips +30-jan-2012 - AnS - Taseditor: quicksave/quickload hotkeys save/load current branch +23-jan-2012 - prg - sdl: pause will now show/ungrab cursor in fullscreen. this can be disabled with the SDL.NoFullscreenCursor option +12-jan-2012 - AnS - Tasedit: File->New Project, INPUT_TYPE_1P +12-jan-2012 - AnS - Tasedit: resizing TAS Editor window +08-jan-2012 - prg - sdl: switched advance one frame key from "\" to "`" +08-jan-2012 - AnS - changed default mapping of Frame Advance to Tilde +08-jan-2012 - AnS - fixed recording bug where "length" tag appeared in fm2s +08-jan-2012 - AnS - Tasedit: Lua panel; 5 new Lua functions +08-jan-2012 - AnS - Tasedit: refactoring; Config->Silent autosave +04-jan-2012 - AnS - Tasedit: colored marker captions; pale yellow and bright yellow when "Bind Markers" is off/on +27-dec-2011 - AnS - Tasedit: "About" window +27-dec-2011 - AnS - Tasedit: searching Markers with similar Notes ("Similar" and "More" buttons) +26-dec-2011 - AnS - Tasedit: Find Note dialog (Ctrl-F) +26-dec-2011 - AnS - new Lua functions (TAS Editor library) +19-dec-2011 - AnS - Tasedit: listview header lights +19-dec-2011 - AnS - Tasedit: Recording checkbox instead of radiobutton; Config->Use Input keys for ColumnSet +19-dec-2011 - AnS - Tasedit: Export dialog: "Convert Marker Notes to Movie Subtitles" +16-dec-2011 - AnS - Tasedit: new accelerators: Ctrl-PgUp/Ctrl-PgDn/Shift-PgUp/Shift-PgDn; Config->Allow keyboard controls in Listview +16-dec-2011 - AnS - Tasedit: View->Display Branch Tooltips +16-dec-2011 - AnS - Tasedit: Markers notes; View->Follow Marker Note context +16-dec-2011 - AnS - changed ".tas" extension to ".fm3" +10-dec-2011 - AnS - loading TAS Editor projects by drag-n-drop +10-dec-2011 - AnS - Tasedit: File->Save Compact dialog +09-dec-2011 - AnS - Replaying TAS Editor project files in FCEUX (win32 and SDL) +07-dec-2011 - AnS - disabled changing PPU/PAL/input_type when Taseditor is engaged +07-dec-2011 - AnS - Tasedit: File->Recent projects +07-dec-2011 - AnS - enhanced Reload hotkey (Ctrl-F1), now it loads last ROM or last TAS Editor project +05-dec-2011 - AnS - Tasedit: Import input, Export to FM2 +04-dec-2011 - AnS - Tasedit: branches autofind best parent, "Set Marker"/"Remove marker" in context menu, checking clipboard at selection.init() and retrieving info +29-nov-2011 - AnS - Tasedit: MsgBox about not working with movies starting from savestate +26-nov-2011 - aquanull - win32: fixed graphic-tearing WITH vertical sync enabled in windowed mode. It used to wait for V-Blank too early so that the V-Blank would end too soon before the blitting could be finished. +26-nov-2011 - AnS - Fixed crash when using machine with no sound card +26-nov-2011 - zeromus - Fixed wrong default palette entry +25-nov-2011 - zeromus - add nestopia palette files +25-nov-2011 - AnS - Tasedit: selection << and >>, Turbo Seek checkbox, PasteInsert, Config->Superimpose affects copy/paste, Editing info texts +23-nov-2011 - zeromus - fix [3441099] printf bug in SwapSaveState() +21-nov-2011 - AnS - Tasedit: multitrack recording, "Superimpose" checkbox, Config->Use 1P keys for all single recordings, Config->Combine consecutive Recordings +19-nov-2011 - AnS - Tasedit: selection strobe, soft reset and power switch messages, messages when saving/loading Branches +17-nov-2011 - AnS - Tasedit: selection history, undo/redo, Reselect Clipboard, saving/loading selection history to .tas +17-nov-2011 - AnS - Tasedit: input hotchanges +14-nov-2011 - zeromus - straighten out bandai m159/m016 handling and add valid null-EEPROM emulation to get those games booting. +12-nov-2011 - adelikat - win32 - cheat search - slight GUI tweak +12-nov-2011 - AnS - Tasedit: project autosaving +10-nov-2011 - AnS - Tasedit: Branches show saved screenshot on mouseover (alpha-fade popup window) +7-nov-2011 - AnS - Tasedit: Drawing Branches Tree (using GDI), animations, transitions, mouseover +04-nov-2011 - prg318 - gtk: added option for frameskipping and made label case consistent in gui +1-nov-2011 - zeromus - debugger - fix mysterious out of bounds condition while editing breakpoints +31-oct-2011 - zeromus - add winapi lua library +31-oct-2011 - zeromus - fix newppu bug; chr ram was not getting initialized to anything +28-oct-2011 - AnS - Switching Tasedit Bg input on/off when Tasedit gets/loses focus +27-oct-2011 - AnS - "Toggle Rerecord Display" hotkey (M), "Play Movie From Beginning" hotkey also works in Tasedit +27-oct-2011 - AnS - Tasedit: Bookmarks/Branches +23-oct-2011 - prg318 - sdl: fix a bug where alt key would get "stuck" when alt tabbing to window +21-oct-2011 - AnS - Tasedit: gradual greenzone cleaning +19-oct-2011 - prg318 - scons: "scons install" now installs auxlib and manpage +19-oct-2011 - prg318 - scons: added --prefix option to build system and improved "install" target +18-oct-2011 - prg318 - sdl: new hotkeys added - statestatenext savestateprev - useful for scrolling through savestates on a gamepad. mapped to pgup and pgdown by default +18-oct-2011 - prg318 - gtk: new video option for double buffering and ClipSides +18-oct-2011 - prg318 - sdl: GTK3 support is now functional. Set GTK3 to 1 in the SConstruct to try it out. +18-oct-2011 - prg318 - no longer use depreciated gtk2 functions +18-oct-2011 - prg318 - getSDLKey tool added to assist in remapping hotkeys +17-oct-2011 - prg318 - some segfaults fixed, also fixed some build errors +17-oct-2011 - prg318 - sdl netplay fixed +15-oct-2011 - zeromus - don't lose cheat compare value when toggle cheat enables through UI +14-oct-2011 - AnS - added rewind hotkey (~), works only in Taseditor +14-oct-2011 - AnS - Tasedit: execute lua functions when jumping inside greenzone +13-oct-2011 - AnS - Tasedit: major refactoring +9-oct-2011 - AnS - Tasedit: input history, undo, redo; greenzone reduces only from the point where actual differences were found +07-oct-2011 - prg318 - sdl: fixed some issues with --nogui . "--nogui" no longer requires an argument and can be used like this "$ fceux --nogui rom.nes" +07-oct-2011 - prg318 - gtk: support mouseclicks (ie zapper) +03-oct-2011 - AnS - Tasedit: Clone Frame(s) +02-oct-2011 - AnS - Tasedit: Markers +30-sept-2011 - AnS - logging all display messages to Message Log +30-sept-2011 - AnS - Tasedit: special method of inserting frames; progressbar updating when loading/saving large projects; moved "Follow cursor" checkbox from View menu to main TASEdit window +30-sept-2011 - AnS - Tasedit: View->Show dot in empty cells; ClearFrames (Del), Cut operation clears frames instead of deleting; checking unsaved project on Exit and Open project +28-sept-2011 - CaH4e3 - resetexstate crash fix +27-sept-2011 - AnS - Fixed old bug with "Play Movie From Beginning" +26-sept-2011 - AnS - added support for "Enable HUD recording" option to SDL version +25-sept-2011 - AnS - Tasedit: progressbar; holding "<" and ">" buttons +25-sept-2011 - zeromus - newppu-fix bug in scroll reg logic causing mis-scrolls in p'radikus conflict +24-sept-2011 - CaH4e3 - latest mapper changes; code/data logger now can log data access from the RAM code; the new button to save unused data to the code/data logger +24-sept-2011 - AnS - Tasedit: changed control scheme to single click instead of double click +23-sept-2011 - AnS - File->AVI/Wav->Enable HUD recording +23-sept-2011 - AnS - moved "Display movie status icon" from Config->Movie options to Config->Display +23-sept-2011 - AnS - Config->Display->Rerecord counter; no more TweakCount +23-sept-2011 - AnS - Config->Movie options->Always suggest Read-Only replay (for Replay dialog) +22-sept-2011 - AnS - deleted "Lag Counter Reset" hotkey; added "Open TAS Edit" hotkey +22-sept-2011 - AnS - fixed long "savestate" messages containing path +22-sept-2011 - AnS - Tasedit: auto clear "Disable speed throttling" and "Run in background", auto set "Set high-priority thread" when entering TASEdit; FCEUX runs in bg when TASEdit has focus; Config->"Mute Turbo" check +19-sept-2011 - AnS - Tasedit: accelerator table; Config->"Set greenzone capacity"; pauseframe is shown by flashing color +18-sept-2011 - zeromus - datalatch mapper-fix bug where wramless games would be able to do something mysterious to unmapped host emulator memory +17-sept-2011 - AnS - Tasedit: forced read-only behaviour when seeking or holding turbo +17-sept-2011 - AnS - Tasedit: "Auto-restore last position" checkbox in playback controls +17-sept-2011 - AnS - Tasedit: fixed item drawing method, no more flicker and slowdowns +12-sept-2011 - prg318 - sdl: rename InputType to CurInputType due to variable of same name in src/movie.h +12-sept-2011 - AnS - Tasedit: rewrote project save/load functions, various bugfixes +6-sept-2011 - AnS - Tasedit: red lines for lag frames +6-sept-2011 - AnS - fixed bug when trying to open Replay dialog without having ROM loaded +3-sept-2011 - AnS - Tasedit: tweaks and bugfixes +3-sept-2011 - CaH4e3 - fixed bus conflict emulation, no kage no densetsu bug anymore +31-Aug-2011 - AnS - Tasedit: Added 4 pads support; also now current frame is shown by blue line; minor cleanups +30-Aug-2011 - mart0258 - Ram Search updates list when emulator is paused (on Power, or when resetting search) +25-Aug-2011 - zeromus - win32: fix context menus to use rightclicks in context menus correctly +19-Aug-2011 - CaH4e3 - PAL/NTSC noise fixed +18-Jul-2011 - zeromus - slightly improve hud text rendering wrapping +16-Jul-2011 - adelikat - Add Button Count lua script written by Brandon Evans +15-Jul-2011 - prg318 - sdl: patch to resolve 'XKeysymToString' complication errors on debian sid and osx (thanks antonio ospite!) +6-Jul-2011 - plombo - sdl: fixed --nogui option and removed SDL.NoGUI from fceux.cfg +5-Jul-2011 - FatRatKnight - Lua console now gets the proper file path when selecting a file from the recent menu. + +---r2206 - FCEUX 2.1.5 Released--- +---June 21 2011--- + +16-Jun-2011 - zeromus - win32: poll hotkeys while no rom is loaded +1-jun-2011 - prg318 - sdl - print usage when --help is passed even if SDL fails +plombo - added stock icons to menu items +plombo - added new gamepad configuration dialog +19-mar-2011 - prg318 - gtk - added hard reset option (renamed reset->soft reset) +18-mar-2011 - prg318 - sdl - removed GTK_LITE; --nogui made it obsolete +12-feb-2010 - mart0258 - Fix input selection for Famicom Expansion port +25-jan-2010 - prg318 - gtk - filechooser now remembers last file opened +25-jan-2010 - prg318 - gtk - fixed xscale/yscale spinbuttons not changing config +24-jan-2010 - prg318 - gtk - game window integrated into sdl window (thanks bryan!) +11-nov-2010 - mart0258 - TasEdit - Invalidate greenzone when re-recording earlier portions of a movie. +09-oct-2010 - zeromus - fix bug in new ppu that made some intensify bits not get applied to output (fixes flashing siren screen in werefolf +09-oct-2010 - gocha - win32 - Ram Watch - fix the multiple selection of watches +09-oct-2010 - gocha - Win32 - Ram Search - multiple selection of addresses, fix restoration of the selection range +09-oct-2010 - gocha - Win32 - Ram Search - fix restoration of the selection range +01-oct-2010 - qeed - Fix many segfaults related to file handling +22-sept-2010 - adelikat - win32 - Hex Editor - ask before removing all bookmarks +04-sept-2010 - adelikat - Win32 - Ramwatch - fix displaying of 2 byte values +26-aug-2010 - mart0258 - Win32 - fix crash when re-opening debugging window +20-aug-2010 - adelikat - Win32 - Display movie name at the top of the main window +09-july-2010 - mart0258 - TasEdit - cleanup; prevent crash when truncating while turbo +13-june-2010 - adelikat - Win32 - avi capture commandline argument and related parameters +12-june-2010 - adelikat - Save Turbo frame skip amount to config so that it can be customized by user +12-june-2010 - adelikat - Lua - fix speed.mode() so that normal turns off turbo +12-june-2010 - CaH4e3 - Fix Young Indiana Jones Chronicals +10-june-2010 - Deign - Fix Ram Search to only display valid RAM addresses (0000-07FF and 6000-7FFF) +10-june-2010 - zeromus - add luasocket to built in lua library +09-june-2010 - adelikat - Movies - Fixed read-only loadstate error logic & messages +07-june-2010 - mart0258 - Movie loading now faster - TAS savestates moved from class MovieRecord to class MovieData +07-june-2010 - adelikat - Lua - new function: gui.screenshotas() +07-june-2010 - Deign/adelikat - Win32 - Added a SavestateAs Menu item +06-june-2010 - FatRatKnight - Added a return value to gui.text: The X position where the function would paint the next character. +02-june-2010 - adelikat - Win32 - Movie Options Dialog - Fix so Full Savestate Load checkbox is updated on load + +---r1984 - FCEUX 2.1.4a Released--- +---June 1 2010--- + +01-june-2010 - zeromus - fix crash bug in fcm convert +01-june-2010 - adelikat - fix logic error in read-only loadstate of movies, should not improperly report savestate after movie errors + +---r1977 - FCEUX 2.1.4 Released--- +---May 31 2010--- + +29-may-2010 - Cah4e3 - Added zapper autodetection for Gotcha! +28-may-2010 - adelikat - Added lua function movie.getfilename() which returns the current movie filename without the path included +27-may-2010 - ugetab - Win32 - Debugger - Made debugger able to break on and distinguish Stack reads/writes +24-may-2010 - adelikat - Win32 - Memwatch - ignore spaces at the beginnign of an address in the address boxes +24-may-2010 - mart0258 - Disable auto-savestates during turbo +24-may-2010 - mart0258 - Prevent .zip files containing no recognized files from causing crash +23-may-2010 - adelikat - Win32 - Replay dialog - fix bug that was causing it to always report savestate movies as soft-reset +23-may-2010 - adelikat - Fix PlayMovieFromBeginning when using a movie that starts from savestate +23-may-2010 - cah4e3 - mapper 19 savestate fix mirroring for "Dream Master (J)" corrected to "four-screen" by CRC check +23-may-2010 - ugetab - Win32 - Fixed bug involving pausing emulation outside of the debugger, then trying to use the debugger commands, and having teh CPU registers become corrupted. +22-may-2010 - ugetab - Win32 - Made cheat menu's Pause When Active effect immediate. +22-may-2010 - ugetab - Win32 - Enabled multi-select for Cheat menu to allow multiple toggles and deletes. +20-may-2010 - ugetab - Added NTSC 2x scalar option with some CFG config options of it's own +20-may-2010 - Cah4e3 - Win32 - CDLogger - fixed bug preventing correct interrupt vectors from logging +19-may-2010 - ugetab/adelikat - Win32 - Added single-instance mode, which makes starting a second copy of FCEUX load the file into the first, then exit.Mode off by default, togglable under Config -> GUI +18-may-2010 - adelikat - Movie + loadstate errors are handled more gracefully now, more informative error messages and the movie doesn't have to stop +18-may-2010 - adelikat - Implemented a "full savestate-movie load" mode similar to the implementation in VBA-rr & SNES9x-rr. In this mode loading a savestate in read+write doesn't truncate the movie to its frame count immediately. Instead it waits until input is recording into the movie (next frame). For win32 this feature is togglable in movie options and the context menu. For SDL this is off by default and a toggle will need to be added. +17-may-2010 - adelikat - Made gamepad 2 off by default. +17-may-2010 - adelikat - Movies - fully implemented "bulletproof" read-only +17-may-2010 - zeromus - Movie loading (& movie-savestate saving/loading) should now be faster due to the use of a emufile class instead of std::ostream for dumping +16-may-2010 - ugetab - Added player 3 and 4 to autohold notification window. Made FCEU_DispMessage able to display to different screen locations to do it. Made sure to update SDL with the change. Hope SDL still compiles ok. +15-may-2010 - ugetab - Win32 - Added option for palette selection as color for LUA colors. Included an LUA script to display all choices with the value used to pick displayed color. +14-may-2010 - adelikat - Win32 - Replay dialog, when selecting a movie in a relative path (.\movies for example), the recent movies list stores an absolute path instead. +14-may-2010 - adelikat - Win32 - When recording a movie, add it to recent movies +14-may-2010 - adelikat - Win32 - Replay dialog shows PAL flag & New PPU flag +14-may-2010 - adelikat - New PPU flag in movie headers (doesn't change an emulators PPU state when loading a movie) +13-may-2010 - adelikat - input display overhaul - a more desmume style system which shows both keys held the previous frame and immiately held keys that will be put in on the next frame +12-may-2010 - ugetab - Win32 - Added rudamentry Between-Frames input display code for adelikat to customize. +12-may-2010 - adelikat - Input Display - displays a silver color when input is from a movie rather than the user +12-may-2010 - ugetab - Win32 - With special scaler in window mode, it's possible to resize to anything above the minimum. +12-may-2010 - adelikat - Movies now have a "finished" option. If a playback stops the movie isn't cleared from memory, and can be replayed or a state loaded. Similar functionality as DeSmuME and GENS rerecording +11-may-2010 - adelikat - Loadstate updates input display +11-may-2010 - ugetab - Win32 - Added Ram Search hotkeys for the first 6 search types in the list. +10-may-2010 - ugetab - Added gui.getpixel() which gets any gui.pixel() set pixel colors, and possibly other functions. Added emu.getscreenpixel() which gets the RGB and Palette of any pixel on the screen. +08-may-2010 - ugetab - Added savestate.object() which is savestate.create() with intuitive numbering under windows +08-may-2010 - ugetab - Added emu.addgamegenie() and emu.delgamegenie() LUA functions. +07-may-2010 - ugetab - Win32 - Added context menu to Cheat Dialog Cheat Listbox, populated list with Toggle Cheat, Poke Cheat Value, and Goto In Hex Editor +07-may-2010 - ugetab - Win32 - Made enabling/disabling cheats no longer deselect the selected cheat. +06-may-2010 - ugetab - win32 - Add Cheat buttons for Ram Search and Ram Watch +06-may-2010 - ugetab - win32 - Hex editor - Made the Hex Editor display the Frozen, Bookmarked, etc. status of the selected address, and made the Frozen color override the Bookmarked color. +04-may-2010 - ugetab - Win32 - Added "Goto" command for hex editor. +28-april-2010 - ugetab - Added microphone support option. When enabled, Port 2 Start activates the Microphone. Movies also support this. +25-april-2010 - FatRatKnight - Fixed a potential desync that plays out an extra frame without an update to the frame count involving heavy lua use, joypad.get, and a loadstate. +23-april-2010 - ugetab - Win32 - Added Tools>GUI option to partially disable visual themes, so the emulator can be made to look like it did in 2.1.1 and earlier releases. +20-april-2010 - adelikat - New lua functions movie.ispoweron() and movie.isfromsavestate() +20-april-2010 - adelikat - Win32 - Drag & Drop - if dropping a .fcm with no ROM loaded, prompt for one (same functionality that was added to .fm2 files) +08-april-2010 - ugetab - Win32 - Added conditional debugging option 'K', for bank PC is on +07-april-2010 - adelikat - fix bug that caused zapper.read() to crash when movie playback ends + +---r1767 - FCEUX 2.1.3 Released--- +---April 7 2010--- + +07-april-2010 - sgrunt - Lua - gui.text now has out of bounds checking +07-april-2010 - adelikat - Win32 - Lua console - filename updates when lua scripts are dragged to emulator or recent filenames invoked +07-april-2010 - adelikat - Lua no longer unpauses the emulator when a script is loaded +30-march-2010 - ugetab - Win32 - Closing minimized windows no longer moves them the next time they get opened +28-march-2010 - adelikat - lua - fixed zapper.read() to read movie data if a movie is playing. Also changed the struct values to x,y,fire. This breaks lua scripts that used it previous, sorry. +04-march-2010 - prockguy - added menu buttons for loading nsf files +03-march-2010 - adelikat - Win32 - If .fm2 drag & dropped with no ROM load, the open ROM dialog will appear +03-march-2010 - prockguy - fceux - now prints the name of the mapper on rom load +03-march-2010 - prockguy - SDL - VS unisystem keys now configable +03-march-2010 - prcokguy - SDL - changed default hotkeys and keys to match w32 +03-march-2010 - prockguy - SDL - fixed dpad/joyhat support +01-march-2010 - adelikat - Movie file format header now has a FDS flag +01-march-2010 - adelikat - win32 - cheats dialog - toggling a cheat in the cheats list now updates the active cheats count +01-march-2010 - adelikat - win32 - a disable movie messages menu item +25-feb-2010 - prockguy - unix netplay is now functional; gtk network gui created +24-feb-2010 - prockguy - GTK - added basic movie controls +24-feb-2010 - prockguy - GTK - added file filters; added Load FDS function +24-feb-2010 - prockguy - GTK - added palette config dialog +23-feb-2010 - prockguy - GTK - added UI elemnts for x/y scale; added lowpass UI option +23-feb-2010 - prockguy - GTK - added GUI for color/tint/hue +23-feb-2010 - prockguy - GTK - implemented sound mixer dialog (for square1, 2, triangle, etc) +22-feb-2010 - prockguy - SDL - ported to SDL 1.3; compatibility maintained with 1.2 +18-feb-2010 - prockguy - GTK - a lot of options added to GTK gui; relatively stable; added GUI for gamepad config and sound config. +02-feb-2010 - ugetab - Win32 - Added window positions bounds checks. Accounts for -32000 positions & less out-of-range too +08-jan-2010 - rheiny - Win32 - Trace Logger - Trace logger now logs the values of the stack pointer register +31-dec-2009 - prg318 - added gtk gui +08-dec-2009 - Zeromus - Fix Name Table Viewer - Fix for use with New PPU +08-dec-2009 - - mart0258 - FDS - show name of missing bios file in error message +07-dec-2009 - qeed - NewPPU - fixed sprite hit before 255 and for non transparent hits only, thanks to dwedit for providing the fix +06-dec-2009 - Zeromus - SDL - disallow --inputcfg gamepad0 and gamepad5 +??-???-2009 - CaH4e3 - fixed mappers 82, 25, 21, and 18. Games such as SD Kiji Blader, Ganbare Goemon Gaiden, and Ganbare Goemon Gaiden 2, Jajamaru Gekimadden are now playable +17-nov-2009 - adelikat - Win32 - Cheats - Pause while active checkbox installed +17-nov-2009 - adelikat - Win32 - Fix debug window so it doesn't crash if unminimized with no game loaded. +13-nov-2009 - mart0258 - Win32 - TASEdit - Added interface functionality (save/load, running TASEdit mid-movie, etc.) +13-nov-2009 - adelikat - made savestate compression togglable +13-nov-2009 - adelikat - made savestate backups togglable +08-nov-2009 - gocha - Win32 - Lua console - added a menu +08-nov-2009 - gocha - change gui.line, gui.box, joypad.get to function like GENS rerecording +08-nov-2009 - gocha - New lua functions: gui.parsecolor, joypad.getup, joypad.getdown, emu.emulating. +08-nov-2009 - CaH4e3 - Fixes for mappers 253 & 226 - fixes games such as Fire Emblem (J) and Fire Emblem Gaiden (J) +08-nov-2009 - CaH4e3 - Fix crashing on game loading for any battery backed roms with mappers from MapInitTab (fixes Esper Dream 2 - Aratanaru Tatakai (J) +04-nov-2009 - adelikat - win32 - debugger - added an auto-load feature + +---r1527 - FCEUX 2.1.2 Released--- +---November 3, 2009--- + +02-nov-2009 - qeed - fixed mapper 226, 76-in-1 seems to work now, also super 42 also seems to work with this fix, but people with save states with this game should make a new one. Since the the save state format for this game was changed a little. +31-oct-2009 - adelikat - win32 - Memwatch - Save Changes prompt - Selecting yes will do quicksave first, save as 2nd (instead of always defaulting to save as) +19-oct-2009 - qeed - Mapper 253 mostly implemented, known game [ES-1064] Qi Long Zhu (C) is mostly playable (some minor graphic glitches). Thanks to VirtualNESEX for reverse engineering this, gil for giving me the mapper src for implementation reference, and Dead_Body for figuring out this game had to use chr-ram +10-oct-2009 - qeed - fixed dragon's lair the mapper 4 europe version in new PPU +10-oct-2009 - zeromus - fixed Tecmo Super Bowl in new PPU +08-oct-2009 - ugetab - win32 - fixed a debugger crash error, Unif/FDS filename issue, and enabled debugger bank display +01-oct-2009 - gocha - win32 - movie play dialog displays movie time based on ~60.1 (~50.1 PAL) instead of 60 & 50 +26-sept-2009 - qeed - fixed action 52 game that was broken in fceux >2.0.3 +16-sept-2009 - ugetab - win32 - Restored DPCM Logging when Code/Data Logger is active +sept-2009 - FatRatKnight - Finally got in that "invert" value for joypad.set. This value simply inverts the player input. Actually, any string will invert it, since we have not used strings for anything else in joypad.set. +15-sept-2009 - FatRatKnight - Reworked how input is taken from lua, and generally everything related to joypad.set and what it affects. Now setting stuff to false will: Prevent user control for exactly one frame, and allow more than one false button as a time. Yeah, bug fixes. Hopefully runs a little faster now. +22-aug-2009 - adelikat - Win32 - Map Hotkeys Dialog - Fixed but where "X" and Alt+F4 would not close dialog +22-aug-2009 - adelikat - Win32 - Added a Save Config File menu item +12-aug-2009 - adelikat - Win32 - Added a menu item to toggle to New PPU +10-aug-2009 - adelikat - fixed bug that caused new movies be created in /movie instead of /movies +08-aug-2009 - qeed - mappers - fixed mapper irq count, dragon ball z 3 +should be playable again. +07-aug-2009 - ugetab - win32 - imported NSF features from FCEU-XDSP-NSF +05-aug-2009 - adelikat - win32 - fixed an erroneous assumption made in 2.1.1 that caused the recent roms menu to be grayed out even when there were recent roms (however, it uncovered an underlying bug in the recent menu saving that needs to be fixed at some point). + +---r1375 - FCEUX 2.1.1--- +---July 29, 2009--- + +01-july-2009 - adelikat - win32 - texthooker - drag & drop for table files +01-july-2009 - adelikat - win32 - drag & drop for cheat (.cht) files +25-jun-2009 - qeed - sound/ppu - fixed the noise value, it seems that the noise logic was shifting the values to the left by 1 when reloading, but this doesnt work for PAL since one of the PAL reload value is odd, so fix the logic and used the old tables. Revert a stupid CPU ignore logic in PPU. Sorry about that. +25-jun-2009 - adelikat - Win32 - CD Logger - Drag and Drop for .cdl files +24-jun-2009 - qeed - sound/ppu - reverted to old noise table value since this seems to get correct sound for double +dragon 2. Also added experimental $2004 reading support to play micro machines with (little) shakes, and fixed some +timing in the new PPU. +24-jun-2009 - adelikat - win32 - memory watch - option to bind to main window, if checked it gives GENS dialog style control, where there is no extra task bar item, and it minimizes when FCEUX is minimized +24-jun-2009 - adelikat - win32 - palette commandline options +24-jun-2009 - adelikat - win32 - Sound Dialog - cleanup, when sound is off, all controls are grayed out +24-jun-2009 - adelikat - win32 - Hex Editor - Drag & Drop for .tbl files +24-jun-2009 - adelikat - win32 - Drag & Drop for .fcm, it converts and then loads the converted movie automatically +24-jun-2009 - adelikat - win32 - Drag & Drop support for palette files +23-jun-2009 - adelikat - win32 - Drag & Drop support for savestates +22-jun-2009 - qeed - Revert IRQ inhibit fix, since this seems to break Dragon + Warrior 4, added palette reading cases for the new PPU. +21-jun-2009 - adelikat - win32 - memwatch - save menu item is grayed if file hasn't changed +20-jun-2009 - adelikat - win32 - memwatch - fixed a regression I made in 2.0.1 that broke the Save As menu item +17-jun-2009 - qeed - Sound core fix, updated with the correct values for the noise and DMC table, + and also fixed the IRQ inhibit behavior for register $4017. Also fixed the CPU + unofficial opcode ATX, ORing with correct constant $FF instead of $EE, as tested + by blargg's. These fixes passes the IRQ flags test from blargg, and also one more + opcode test from blargg's cpu.nes test. +16-jun-2009 - adelikat - sound core fix - square 1 & square 2 volume controls no longer backwards +11-jun-2009 - zeromus - sound core fix, length counters for APU now correct variables +11-jun-2009 - adelikat - Win32 - Hex Editor - changed ROM values again dsiplay as red, saved in the config as RomFreezeColor +06-jun-2009 - rheiny - Fixed reported issue 2746924 (md5_asciistr() doesn't produce correct string) +23-may-2009 - adelikat - win32 - hex editor - freeze/unfreeze ram addresses now causes the colors to update immediately, but only with groups of addresses highlighted at once (single ones still don't yet update) +23-may-2009 - adelikat - win32 - context menu - Save Movie As... menu item (for when a movie is loaded in read+write mode) +23-may-2009 - adelikat - win32 - added opton to remove a recent item to the roms, lua, and movie recent menus +23-may-2009 - adelikat - win32 - Added a remove recent item function and hooked it up to memwatch recent menu, now if a bad recent item is clicked, the user has a choice to remove it from the list +23-may-2009 - adelikat - win32 - Load Last Movie context menu item added +23-may-2009 - adelikat - win32 - Recent Movie Menu added +22-may-2009 - adelikat - win32 - "Disable screen saver" gui option now also diables the monitor powersave +22-may-2009 - adelikat - win32 - Debugger - Step type functions now update other dialogs such as ppu, nametable, code/data, trace logger, etc. +22-may-2009 - adelikat - win32 - Hex Editor - Save Rom As... menu option enabled and implemented +22-may-2009 - adelikat - win32 - Window caption shows the name of the ROM loaded +22-may-2009 - adelikat - win32 - Hex Editor - allowed the user to customize the color scheme by use of RGB values stored in the .cfg file +21-may-2009 - adelikat - win32 - reverted fixedFontHeight to 13 instead of 14. Gave the option of adjusting the height by modifying RowHeightBorder in the .cfg file +21-may-2009 - adelikat - win32 - made fullscreen toggle (Alt+Enter) remappable +15-may-2009 - shinydoofy - sdl - added --subtitles +10-may-2009 - shinydoofy - sdl - fixed Four Score movie playback +02-may-2009 - adelikat - win32 - stop movie at frame x feature - fixed off by 1 error +23-apr-2009 - shinydoofy - sdl - added --ripsubs for converting fm2 movie subtitles to an srt file +15-apr-2009 - shinydoofy - sdl - Lua is optional again, fixed the real issue +14-apr-2009 - punkrockguy - sdl - LUA is NO longer optional, so the SConscripts have been updated to reflect that change. This fixes the mysterious non-working input issue. +12-apr-2009 - shinydoofy - sdl - implemented saving/loading a savestate from a specific file on Alt+S/L +11-apr-2009 - shinydoofy - sdl - implemented starting an FM2 movie on Alt+R +11-apr-2009 - adelikat - made default save slot 0 instead of 1, Win32 - remember last slot used +11-apr-2009 - shinydoofy - sdl - added --pauseframe to pause movie playback on frame x +11-apr-2009 - shinydoofy - sdl - dropped UTFConverter.c from SDL build and added hotkey Q for toggling read-only/read+write movie playback + +--version 2.1.0a released---- +04-apr-2009 - shinydoofy - fixed fcm->fm2 code once again (this time for good, hopefully). Thanks to Bisqwit! +04-apr-2009 - shinydoofy - Reverted UTF8<->UTF32 code changes to fix up the win32 build for now + +---version 2.1.0 released--- +29-mar-2009 - adelikat - Win32 - reverted acmlm's /dll folder change +28-mar-2009 - shinydoofy - sdl - added hotkey Del to toggle mute avi capturing +28-mar-2009 - shinydoofy - sdl - fix fm2 playback and fcm->fm2 conversion crash at the cost of ugly 0x00 bytes behind the author's comment line +28-mar-2009 - adelikat - Lua - added FCEU.poweron() and FCEU.softreset() +27-mar-2009 - shinydoofy - sdl - added --no-config +23-mar-2009 - adelikat - Win32 - blocked "hotkey explosion" by rshift on some laptops +22-mar-2009 - shinydoofy - sdl - added hotkey I and --inputdisplay {0|1|2|4} for toggling input display. +22-mar-2009 - shinydoofy - sdl - added commandline options for sound channels' volumes +22-mar-2009 - shinydoofy - sdl - updated window title +19-mar-2009 - adelikat - Win32 - make Video - windowed mode - disable hardware accel the default setting. Made high quality sound the default setting. +16-mar-2009 - adelikat - Win32 - GUI Dialog - added an option to disable the context menu +15-mar-2009 - adelikat - Lua - added movie.rerecordcount(), movie.length(), movie.getname(), movie.playbeginning(), FCEU.getreadonly(), FCEU.setreadonly() +14-mar-2009 - adelikat - Lua - added movie.active() - returns a bool value based on whether a movie is currently loaded +14-mar-2009 - adelikat - Fixed Joypad.set, it uses 3 values instead of 2 now. True will take control of a button and make it on, False will take control and make it off, and Nil will not take control (allowing the user to press the button) +14-mar-2009 - adelikat - Fix major crash issue where NROM game savestates were writing erroneous information if a non NROM game was loaded prior +13-mar-2009 - adelikat - Closing game / Opening new game resets the frame counter +13-mar-2009 - adelikat - Win32 - Debugger - Scanlines and PPU Pixels are displayed even in vblank (lines 240-261) +12-mar-2009 - shinydoofy - sdl - fixed compilation error and reactivated the mouse pointer in the SDL window +12-mar-2009 - adelikat - Win32 - Trace Logger - fixed bug where user can't scroll the log window while it is auto-updating +11-mar-2009 - adelikat - Win32 - Trace Logger - changed message about F2 pause (left over from FCEUXDSP) to display the current hotkey mapping +11-mar-2009 - adelikat - Added frame counter to savestates +08-mar-2009 - adelikat - Lua - added input.get() function +08-mar-2009 - adelikat - Lua - memory.readbyte will recognize frozen addresses +08-mar-2009 - adelikat - Lua - added FCEU.lagged() function +08-mar-2009 - adelikat - Lua - added zapper.read() function +07-mar-2009 - adelikat - Lua - added FCEU.lagcount() function +04-mar-2009 - adelikat - win32 - Fix bug so that Escape can now be assigned as a hotkey +03-mar-2009 - adelikat - win32 - Fix Directory Overrides so to allow users to have no override. Also fixes directory override reset bug +02-mar-2009 - adelikat - win32 - Drag & Drop for Memwatch dialog (.txt files) +01-mar-2009 - adelikat - win32 - Drag & Drop Lua files +25-feb-2009 - adelikat - win32 - Memwatch - added cancel to save changes? message box +22-feb-2009 - adelikat - win32 - Lua - made speedmode("turbo") turn on turbo (which employs frameskipping) rather than max speed +22-feb-2009 - adelikat - Increased lua gui.text height (and DrawTextTransWH() height) +21-feb-2009 - adelikat - win32 - Lua - Added -lua commandline argment, loads a lua script on startup +21-feb-2009 - adelikat - win32 - Debugger - Added pixel display after scanline display - Thanks to DWEdit for this patch +21-feb-2009 - adelikat - win32 - Debugger - Added Run Line, Run 128 Lines buttons - Thanks to DWEdit for this patch +21-feb-2009 - adelikat - win32 - Message Log - remembers X,Y position +19-feb-2009 - adelikat - win32 - Memory Watch - fixed recent file menu - no longer crashes when attempting to load a non existent recent file +07-feb-2009 - adelikat - win32 - Fix bug in screenshot numbering that caused numbering to not reset when changing ROMs +06-feb-2009 - adelikat - win32 - Hex editor - remembers window size +06-feb-2009 - adelikat - Win32 - sound config dialog - added sliders for individual sound channel volume control +06-feb-2009 - zeromus - Force processor affinity, fixes throttling problem on AMD dualcore machines +06-feb-2009 - adelikat - Sound channels now have individual volume control +01-jan-2009 - adelikat - Win32 - Timing - "disable throttling when sound is off" now only affects FCEUX when sound is off +26-dec-2008 - adelikat - Metadata - remember window position +24-dec-2008 - adelikat - auto-save fixes, prevent loading an auto-save from previous session. Win32 - added flags for enabling auto-save menu item. +24-dec-2008 - adelikat - added undo/redo savestate hotkey. Win32 - made undo/redo default key mapping Ctrl+Z +24-dec-2008 - adelikat - win32 - added Last ROM used context menu item when no game loaded +24-dec-2008 - shinydoofy - sdl - added option to mute FCEUX for avi capturing, check the docs for more detail +23-dec-2008 - adelikat - Win32 - Undo/redo loadstate and Undo/redo savestate context menu items added +23-dec-2008 - adelikat - undo/redo loadstate and undo/redo savestate implemented +22-dec-2008 - adelikat - backupSavestate system added. +22-dec-2008 - shinydoofy - sdl - added Shift+M for toggling automatic movie backups for SDL +22-dec-2008 - adelikat - Movie auto-backup feature implemented +22-dec-2008 - adelikat - win32 - moved movie related menu items to a movie options dialog box +22-dec-2008 - adelikat - Win32 - context menu item "create backup" for backing up movie files +21-dec-2008 - adelikat - Win32 - Name Table Viewer - Refresh value default to 15, Refresh value stored in config file +21-dec-2008 - adelikat - Win32 - PPU Viewer - Refresh value default to 15, Refresh value stored in config file +19-dec-2008 - adelikat - Loadbackup function added, Win32 - Undo Loadstate context menu item +19-dec-2008 - adelikat - Backup savestate is made before loading a state +18-dec-2008 - adelikat - win32 - turbo bypasses sound better if muteturbo is checked +18-dec-2008 - shinydoofy - sdl - fixed compiling errors for SDL due to r1037 +18-dec-2008 - adelikat - win32 - fullscreen mode fixed (both enters and returns to fullscreen just fine) +16-dec-2008 - adelikat - win32 - debugger - added "Restore original window size" button +16-dec-2008 - adelikat - win32 - debugger - fixed SF2073113 - Debugger now has a minimum valid size +15-dec-2008 - adelikat - win32 - cheats - number of active cheats listed, freezing ram addresses in hex editor automatically updates cheats dialog +15-dec-2008 - adelikat - win32 - hexeditor - added minimize & maximize buttons +14-dec-2008 - adelikat - win32 - memwatch - frozen addresses will display as blue +14-dec-2008 - adelikat - win32 - hexeditor - prevent the user from freezing more than 256 addresses at once +14-dec-2008 - adelikat - win32 - memwatch - collapsable to 1 column +08-dec-2008 - adelikat - win32 - stop lua menu item gray if no lua script is running +08-dec-2008 - adelikat - win32 - fix bug where no sound + mute turbo caused chirps when toggling +08-dec-2008 - adelikat - win32 - sound dialog - disabling sound disabled sound options +08-dec-2008 - adelikat - win32 - opening a rom runs closerom first, fixes bug where new sav file was not getting loaded +07-dec-2008 - adelikat - win32 - turbo now employs frame skip +30-nov-2008 - punkrockguy - commit 1000 +30-nov-2008 - punkrockguy - fixed gcc compile error +30-nov-2008 - punkrockguy - moved around some hotkeys to be consistent with docs +30-nov-2008 - punkrockguy - major update to sdl documentation +24-nov-2008 - qfox - win32 - fixed two position checks for memwatch and debugger that could cause these windows to "disappear" (moved far out of reach). +24-nov-2008 - adelikat - win32 - right click context menus installed +24-nov-2008 - adelikat - win32 - added lots of mappable hotkey items as Menu items +23-nov-2008 - adelikat - Win32 - fixed some errors in my AVI directory override code +23-nov-2008 - shinydoofy - movie subs now have a toggle button in the SDL build (F10 by default) +23-nov-2008 - adelikat - movie subtitle system installed +22-nov-2008 - adelikat - Win32 - added help menu item to TASEdit and Hex Editor, Minor TASEdit clean up +22-nov-2008 - adelikat - Win32 - fixed so that turbo works with VBlank sync settings +21-nov-2008 - qfox - Lua - added joypad.write and joypad.get for naming consistency. Added plane display toggle for lua: FCEU.fceu_setrenderplanes(sprites, background) which accepts two boolean args and toggles the drawing of those planes from Lua. Changed movie.framecount() to always return a number, even when no movie is playing. Should return the same number as in view; the number of frames since last reset, if no movie is playing. +17-nov-2008 - adelikat - added Open Cheats hotkey (currently a windows only function) +16-nov-2008 - adelikat - Win32 - menu items that are hotkey mappable show the current hotkey mapping +15-nov-2008 - adelikat - Win32 - memwatch - implemented RamChange() - monitors the behavior of ram addresses +15-nov-2008 - adelikat - Win32 - re-enabled sound buffer time +15-nov-2008 - adelikat - Clip Left and Right sides taken into account when drawing on screen (record/play/pause, lag & frame counters, messages, etc) +15-nov-2008 - adelikat - win32 - Implemented Drap & Drop for movie files +14-nov-2008 - adelikat - win32 Hex Editor - Dump Rom & Dump PPU to file Dialog - uses ROM to build default filename +14-nov-2008 - adelikat - Win32 Memwatch - Save as dialog - uses ROM name to build default memwatch filename if there is no last used memwatch filename +14-nov-2008 - adelikat - Win32 Text Hooker fixes - Init error checking reinstated, save .tht file no longer crashes, Dialog updates as ROM plays, Remembers window position, fix bug where canceling save as produces an error message, Save As produces default filename based on loaded ROM +14-nov-2008 - adelikat - fixed but when aspect correction and special scaling 3x are set, video was getting resized incorrectly +14-nov-2008 - adelikat - fixed a bug introduced in previous commit, frame display toggle now works when no movie is present +12-nov-2008 - adelikat - allowed frame counter to display even with no movie present +11-nov-2008 - punkrockguy - sdl - savestate slots now mappable [2175167] +10-nov-2008 - adelikat - win32 - removed accel keys from main window +10-nov-2008 - adelikat - Win32 - added Open & Close ROM mappable hotkeys, removed accel functions +10-nov-2008 - punkrockguy - improved the sdl sound code; drasticaly improves quality of sound. +09-nov-2008 - adelikat - minor memory watch menu clean up, removed Ctrl+W hotkey for close (and placed Alt+F4 on the menu name) +08-nov-2008 - zeromus - big endian wasnt compiling. fix issues. +02-nov-2008 - shinydoofy - added --fcmconvert for SDL +02-nov-2008 - zeromus - emulua - add rom.readbyte and rom.readbytesigned + + +---version 2.0.3 released--- + +02-nov-2008 - zeromus - fix fcm conversion, recording, and playback of reset and power commands +25-oct-2008 - shinydoofy - added support for AVI creation for SDL, see documentation/Videolog.txt for more +19-oct-2008 - shinydoofy - toggle lag frame counter for SDL, default hotkey F8 +19-oct-2008 - shinydoofy - toggle skipping of lag frames for SDL, default hotkey F6 +19-oct-2008 - shinydoofy - [ 2179829 ] user ability to toggle "bind savestates to movie" added for SDL, default hotkey F2 +19-oct-2008 - adelikat - win32 - added a toggle for binding savestates to movies +18-oct-2008 - adelikat - win32 - added -cfg (config file) command line argument +08-oct-2008 - zeromus - SF [ 2073113 ] Child windows inside debugging window get invalid sizes +08-oct-2008 - zeromus - SF [ 2153843 ] Lua ignores second joypad.set() +24-sep-2008 - punkrockguy318 - made the input config window more usable +24-sep-2008 - punkrockguy318 - --inputcfg can now be used without a filename +24-sep-2008 - punkrockguy318 - [ 2085437 ] should fix issues with missing author field crashing fceux +24-sep-2008 - punkrockguy318 - [ 2047057 ] added uninstall script for gfceux +24-sep-2008 - punkrockguy318 - [ 2062823 ] fixed ppc build errors and added LSB_FIRST option to build scripts +24-sep-2008 - punkrockguy318 - [ 2057006 ] --newppu option added to sdl, disabled by default +24-sep-2008 - punkrockguy318 - [ 2057008 ] lua is now optional, thanks shinydoofy for a patch. also fixed some build issues. +22-sep-2008 - punkrockguy318 - [ 2008437 ] fixed an issue where flawed movie would crash fceux on every startup +21-aug-2008 - punkrockguy318 - sdl - fixed issue where windowed mode would always be set to 32 bpp +18-aug-2008 - zeromus - windows - SF [ 2058942 ] Load state as... does not use the savestate override dir (fixed; now, it does) +18-aug-2008 - zeromus - windows - permit user optionally to proceed through the movie savestate mismatch error condition, in case he knows what he is doing. +18-aug-2008 - zeromus - fix a bug in the savestate recovery code which prevent aborted savestate loads from recovering emulator state correctly. +18-aug-2008 - zeromus - windows - bind a menu option for display framecounter +17-aug-2008 - zeromus - windows - fix problem where replay dialog couldnt work when the process current directory had changed to something other than emulator base directory +17-aug-2008 - zeromus - windows - autoload the only useful rom or movie from an archive, in cases where there is only one +17-aug-2008 - zeromus - gracefully handle non-convertible broken utf-8 text without crashing +17-aug-2008 - zeromus - windows - don't read every archive file when scanning for replay dialog. scan them, and only look for *.fm2 +17-aug-2008 - zeromus - debugger - fix issue where keyboard keys get stuck when switching between debugger window and main window +15-aug-2008 - adelikat - fixed an oversight on my part. Sound config dialog will now look to see if Mute Turbo should be checked + +---version 2.0.2 released--- + +14-aug-2008 - punkrockguy318 - SDL: prevent frame advance from crashing emulator +14-aug-2008 - punkrockguy318 - SDL build scripts now look for lua5.1 and lua (distributions package lua differently) +14-aug-2008 - zeromus - restore savestate error recovery functionality. This should have the side effect of guaranteeing that ( SF [ 2040761 ] Wrong savestate bug - crashes FCEUX) is resolved. +14-aug-2008 - zeromus - SF [ 2047001 ] Low speeds crash FCEUX +14-aug-2008 - zeromus - SF [ 2050371 ] FCM>FM2 converter should release file handle +13-aug-2008 - zeromus - restore ungzipping (and unzipping in sdl) capability which was lost when archive support was added +13-aug-2008 - zeromus - add FORBID breakpoints - regions which block breakpoints from happening if they contain the PC +13-aug-2008 - punkrockguy318 - SDL: fixed --input(1-4) options. input1 and 2 are regular inputs, input3 and 4 are famicom expansion inputs +12-aug-2008 - zeromus - fix SDL configfile woes. configfile now goes to ~/.fceux/fceux.cfg +12-aug-2008 - zeromus - SF [ 2047986 ] palflag 1 in .fm2 files crashes fceux +12-aug-2008 - adelikat - movie replay dialog displays fractions of a second +12-aug-2008 - punkrockguy318 - SDL: fixed segfault when opening .fcm files +12-aug-2008 - punkrockguy318 - SDL: Saner sound defaults for less choppy sound +12-aug-2008 - punkrockguy318 - SF [ 2047050 ] SDL: "--special" option fixed for special video scaling filters +12-aug-2008 - zeromus - SF [ 2046984 ] Player 3 inputs when not used +12-aug-2008 - zeromus - print a special message when trying to open an FCM reminding user to convert. (finishes SF [ 2011832 ] Opening non movie file crashes FCEUX) +12-aug-2008 - zeromus - SF [ 2046985 ] SRAM not wiped on power cycle (during movies) +11-aug-2008 - zeromus - restore IPS patching capability which was lost when archive support was added +11-aug-2008 - zeromus - SF [ 2011550 ] Buffer overflow (change vsprintf to vsnprintf) +11-aug-2008 - zeromus - SF [ 2047004 ] Moviefilenames without extension don't automatically get fm2 +10-aug-2008 - zeromus - upgrade to cah4e3's latest mapper 163&164 code to fix a crash in a game +10-aug-2008 - zeromus - remove cnrom chr rom size limit for homebrew roms +10-aug-2008 - punkrockguy318 - SDL: cleaned up the SConsruct +10-aug-2008 - punkrockguy318 - SDL: fixed issue where fceu would lock up when file dialogs were opened during fullscreen +10-aug-2008 - punkrockguy318 - SDL: fixed bug where fceux would close when file dialogs were closed +10-aug-2008 - punkrockguy318 - SDL: File open dialog is now used to movie playback +10-aug-2008 - punkrockguy318 - SDL: File open wrapper now takes a titlebar argument +10-aug-2008 - punkrockguy318 - SDL: Cleanup of usage +10-aug-2008 - punkrockguy318 - SDL: rename options --no8lim -> --nospritelim and --color -> --ntsccolor +10-aug-2008 - punkrockguy318 - SDL: Screenshots now always prepend the game name. +10-aug-2008 - punkrockguy318 - SDL: Changed default A/B from numpad 2 and 3 to j and k. +10-aug-2008 - punkrockguy318 - SDL: Enable frameskip by default +10-aug-2008 - punkrockguy318 - SDL: Fixed a bug that would crash fceux if the emulation speed was overincreased +10-aug-2008 - punkrockguy318 - SDL: New default hotkeys to more closely match win32 defaults +10-aug-2008 - punkrockguy318 - SDL: Added lua script loading hotkey (f3). Non win32 SDL requires zenity for this to function. +10-aug-2008 - punkrockguy318 - SDL: Build script cleanup; also added option for DEBUG builds. +10-aug-2008 - zeromus - SF [ 2030405 ] Avi recording: no sound b0rks format +10-aug-2008 - zeromus - SF [ 2037878 ] Convert .fcm doesn't do special characters +09-aug-2008 - zeromus - SF [ 2040463 ] Add an "author" text field in the record movie dialog +09-aug-2008 - zeromus - re-enable support for old-format savestates. +09-aug-2008 - zeromus - SF [ 2041944 ] Savestates remember Lua painting +09-aug-2008 - zeromus - support loading movies from archives +08-aug-2008 - adelikat - added input display to the FCEUX main menu +08-aug-2008 - adelikat - fixed the (null) in the default lua directory listing +08-aug-2008 - adelikat - added shift+L as default hotkey for reload lua script +08-aug-2008 - adelikat - removed accel ctrl+x (prevented cut from working in accel dialogs) +08-aug-2008 - zeromus - fiddle with nametable viewer to display correct NT,CHR,ATTR data in more cases (specifically, including some exotic mmc5 cases). +08-aug-2008 - zeromus - fix a new bug in windows build which caused fourscore emulation to fail in some cases +07-aug-2008 - zeromus - add an option to pick a constant color to draw in place of BG when BG rendering is disabled (look for gNoBGFillColor in config; 255 means to use palette[0]) +07-aug-2008 - adelikat - added a mute turbo option in sound config +07-aug-2008 - adelikat - new toggle - frame adv. - lag skip (menu item + hotkey mapping + saved in config) +07-aug-2008 - adelikat - put in -32000 protection on all dialogs that remember x,y +06-aug-2008 - adelikat - change config filename from fceu98.cfg to fceux.cfg +06-aug-2008 - zeromus - add lagcounter and lagflag to savestate +06-aug-2008 - zeromus - SF [ 2040448 ] View Slots bug - does not include new savestate naming +06-aug-2008 - zeromus - restore the debugger snap functionality +06-aug-2008 - zeromus - add memory.readbyterange to emulua +06-aug-2008 - zeromus - auto-fill .fcs extension in save state as dialog +06-aug-2008 - zeromus - mmc5 - 64KB WRAM games now work correctly +06-aug-2008 - zeromus - mmc5 - use of chr A regs for BG in sprite 8x8 mode is fixed +06-aug-2008 - zeromus - debugger - debugger window is now resizeable + +---version 2.0.1 released--- + +04-aug-2008 - reorganize display toggle options in the menu +04-aug-2008 - adelikat - autofire fix +04-aug-2008 - zeromus - homebrew mmc5 games now have 64KB of exwram instead of only 8KB +04-aug-2008 - zeromus - fix crash related to player2 in lua scripts +03-aug-2008 - qfox - fixed player2 in lua scripts + +---version 2.0.0 released--- diff --git a/branches/fceux-2.2.2/debian-crossbuild.sh b/branches/fceux-2.2.2/debian-crossbuild.sh new file mode 100755 index 00000000..f0623563 --- /dev/null +++ b/branches/fceux-2.2.2/debian-crossbuild.sh @@ -0,0 +1,5 @@ +#!/bin/sh +if [ -f /usr/bin/i586-mingw32msvc-windres ]; then HOST=i586-mingw32msvc +else HOST=i586-mingw32 +fi +PLATFORM=win32 CC=${HOST}-gcc CXX=${HOST}-g++ WRC=${HOST}-windres WINDRES=${HOST}-windres scons $@ diff --git a/branches/fceux-2.2.2/documentation/.gitignore b/branches/fceux-2.2.2/documentation/.gitignore new file mode 100644 index 00000000..674deb69 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/.gitignore @@ -0,0 +1,17 @@ +# A simulation of Subversion default ignores, generated by reposurgeon. +*.o +*.lo +*.la +*.al +*.libs +*.so +*.so.[0-9]* +*.a +*.pyc +*.pyo +*.rej +*~ +*.#* +.*.swp +.DS_store +# Simulated Subversion default ignores end here diff --git a/branches/fceux-2.2.2/documentation/TODO-PROJECT b/branches/fceux-2.2.2/documentation/TODO-PROJECT new file mode 100644 index 00000000..6354d36d --- /dev/null +++ b/branches/fceux-2.2.2/documentation/TODO-PROJECT @@ -0,0 +1,61 @@ +Items to be completed before 2.0 release + +FASTAPASS / FP_FASTAPASS / Are these archaic? They suck - ?? + +Separate frameskip/pause from EmulationPaused - zeromus + +Make ALL Debugging code conditional - zeromus + +Doxygen integration - DONE + * website integration + +Linux build - soules + * clean-up of input device code + +Windows build - zeromus + * verify rerecording + * verify debugging + * verify avi writing + +Commandline parsing - lukas + * verify in windows - zeromus + +Configfile parsing - lukas + * verify in windows - zeromus + +Do we really need vc7 project? Cah4e3? - zeromus +Source code docs cleaning - zeromus +Homepage docs - zeromus + +What is the proper gnu way to do CREDITS from the homepage? e.g. Marat Fayzullin - General NES information + +Freenode registration - lukas + * homepage update + +Default hotkey philosophy (there are different philosophies from XD and TAS) - ALL + +Netplay - FUTURE STUFF + Move server code into tree - DONE + Ensure netplay compiles + verify netplay + +----done----- + +Investigate OSX build [ http://www.lamer0.com/ ] - zeromus [posted on blog...] + +Move to scons - DONE + +Merge garnet and sf repos - DONE + * Ensure gnome frontend is in repo - DONE + * Move to sourceforge SVN - DONE + +--strategic-- + +Politics: + * aboutbox credits + * AUTHORS + +Release: + * Press Release - ?? + * Homepage updates + - eliminate old news, add new links diff --git a/branches/fceux-2.2.2/documentation/Videolog.txt b/branches/fceux-2.2.2/documentation/Videolog.txt new file mode 100644 index 00000000..15c349b1 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/Videolog.txt @@ -0,0 +1,48 @@ +Since SVN revision 931, FCEUX features a new option to create avi files from a recorded movie and it is relatively easy to use if you know the bare basics of mencoder. +Call "scons CREATE_AVI=1" to activate it. You will, however, most likely need mencoder to use it. + +You get the raw video data via stdin and the audio data from a fifo file. Let's say you want the video to be in the best quality available, no matter how long it takes or how big the avi file might get. In order to get the NES's original video resolution and a good sound quality, you might need to set some settings beforehand or just pass them along while calling mencoder. + + +Here's an example: +./fceux \ + --xscale 1 --yscale 1 --special 0 \ + --pal 0 \ + --sound 1 --soundq 1 --soundrate 48000 --mute 1 \ + --nospritelim 1 \ + --no-config 1 \ + --videolog "mencoder - -o myfirstencodedrun.avi \ + -ovc x264 -x264encopts qp=0 \ + -oac pcm \ + -noskip -nocache -mc 0 -aspect 4/3 + NESVSETTINGS" \ + --playmov mymovie.fm2 myROM.nes + +Now let's see what is done and why we did it: +First of all, we started fceux with "./fceux" and gave it some options: + "--xscale" and "--yscale" determine how much bigger the video in comparison to its regular size. It's no point to use anything other than 1 here because you can always see your video on fullscreen or at least scale it, can't you? As a nice addon, it saves time to create the avi file and also saves valuable space on your hard disk. + "--special" would usually do something fancy to your picture when you're playing a ROM, but again, it's mostly pointless to use for an avi. + "--pal 0" lets the game run at ~60Hz. Set this so 1 if you are using a PAL ROM. + "--sound 1" activates sound. + "--soundq 1" activates high quality sound. + "--soundrate 48000" sets the sound rate to 48kHz. + "--mute 1" mutes FCEUX while still passing the sound to mencoder. This way you can capture a movie and still listen to your music without having the NES sounds in the background. + "--nospritelim" deactivates the NES's 8 sprites per scanlines limit. + "--no-config 1" is used not to destroy your settings when creating an avi movie. + "--videolog" calls mencoder: + "-" states that we're getting the video stream from stdin. + "-o" determines the name of the produced avi file. + "-ovc x264" sets the video codec to be x264 and is highly recommended for quality reasons. However, if you using a version of x264 from Sep 28th 2008 or newer, mplayer will not be able to decode this again properly. Until this is fixed this mplayer, you might want to replace "-ovc x264 -x264encopts qp=0" with "-ovc lavc -lavcopts vcodec=ffv1:format=bgr32:coder=1:vstrict=-1". Watch out, though, as this needs *way* more space than x264 does. + "-x264encopts qp=0" tells the x264 codec to use a quantizer of 0, which results in lossless video quality. + "-oac pcm" saves the audio data uncompressed (this might turn out really big). + "-noskip" makes sure that no frame is dropped during capturing. + "-nocache" is responsible for immediate encoding and not using any cache. + "-mc 0" makes sure that the sound does not go out of sync. + "-aspect 4/3" sets the avi's aspect ratio so you can see it in fullscreen and have no borders to the left and right. + "NESVSETTINGS" takes care of proper recognition of the audio and video data from FCEUX. + "&> mencoder.log" lets mencoders log its output into a file called "mencoder.log" in your current working directory. + "--playmov" reads which movie file we want to load (here it's mymovie.fm2). + Lastly, we load our desired ROM (in this case it's "myROM.nes"). + +To go for faster encoding and thus less quality, change "-ovc x264 -x264encopts qp=0" to "-ovc xvid -xvidencopts bitrate=200" and "-oac pcm" to "-oac mp3lame -lameopts mode=3:preset=60" to create a 200 kbps xvid video with 60 kbps of mono mp3 audio. +Good luck! :) diff --git a/branches/fceux-2.2.2/documentation/cheat.html b/branches/fceux-2.2.2/documentation/cheat.html new file mode 100644 index 00000000..a0eac597 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/cheat.html @@ -0,0 +1,313 @@ + + + FCE Ultra Cheat Guide + + +

FCE Ultra Cheat Guide

+
Last updated November 12, 2003
Valid as of FCE Ultra 0.97.4
+

+ Table of Contents: +

+
+

Introduction

+

+ FCE Ultra allows cheating by the periodic "patching" of arbitrary addresses + in the 6502's memory space with arbitrary values, as well as read substitution. + "Read substitution" is the method that would be used on a real NES/Famicom, + such as done by the Game Genie and Pro Action Replay. It is required + to support GG and PAR codes, but since it is relatively slow when done + in emulation, it is not the preferred method when a RAM patch will + suffice. Also, in FCE Ultra, read substitution will not work properly with + zero-page addressing modes(instructions that operate on RAM at $0000 through + $00FF). +

+

+ The RAM patches are all applied a short time before the emulated + vertical blanking period. This detail shouldn't concern most people, though. + However, this does mean that cheating with games that use + bank-switched RAM may be problematic. Fortunately, such games are not very + common(in relation to the total number of NES and Famicom games). +

+

Cheat Files

+

+ Cheats are stored in the "cheats" subdirectory under the base FCE Ultra + directory. The files are in a simple plain-text format. Each line represents + a one-byte memory patch. The format is as follows(text in brackets [] + represents optional parameters): +

+

+

+ [S][C][:]Address(hex):Value(hex):[Compare value:]Description +
+ Example: + +
040e:05:Infinite super power.
+

+

+ A colon(:) near the beginning of the line is used to disable the cheat. + "S" denotes a cheat that is a read-substitute-style cheat(such as with Game + Genie cheats), and a "C" denotes that the cheat has a compare value. +

+ +
+

The Windows Interface

+

+ All addresses listed in the cheats window are in unsigned + 16-bit hexadecimal format and all values in these windows are in an + unsigned 8-bit decimal format(the range for values is 0 through 255). +

+

+ The cheats window contains the list of cheats for the currently loaded game + on the right side. Existing cheats can be selected, edited, and updated + using the "Update" button. +

+

Cheat Search Interface

+

+ The cheat search interface consists of several components: a list of + addresses and associated data for a search, several command buttons, + and the search parameters. +

+

+ Each entry in the list is in the format of: +

Address:Original Value:Current Value
+

+

+ The address is the location in the 6502's address space, the original + value is the value that was stored at this address when the search was + reset, and the current value is the value that is currently stored at + that address. Selecting an item in this list will automatically cause + the "Address" field in the cheat information box on the right side of the + window to be updated with the selected address. +

+

+ The "Reset Search" button resets the search process; all valid addresses + are displayed in the cheat list and the data values at those addresses noted. +

+

+ The "Do Search" buttons performs a search based on the search parameters + and removes any non-matching addresses from the address list. +

+

+ The "Set Original to Current" button sets the remembered original values + to the current values. It is like the "Reset Search" button, but it does + not affect which addresses are shown in the address list. This command is + especially useful when used in conjunction with the "O!=C" search filter. +

+

+ The "Unhide Excluded" button shows all addresses that are excluded as a + result of any previous searches. It is like the "Reset Search" button + except that it does not affect the remembered original values. +

+

+ The numbers assigned the names "V1" and "V2" have different meanings based + on which filter is selected. A list of the names of the filters and detailed + information on what they do follows("original value" corresponds to the value + remembered for a given addres and "current value" is the value currently + at that address. Also, if a value is not explicitly said to be shown + under a certain condition, then it is obviously excluded.): +

+ "O==V1 && C==V2": +

+ Show the address if the original value is equal to "V1" AND + the current value is equal to "V2". +
+

+

+ "O==V1 && |O-C|==V2": +

+ Show the address if the original value is equal to "V1" AND + the difference between the current value and the original + value is equal to "V2". +
+

+

+ "|O-C|==V2": +

+ Show the address if the difference between the current value + and the original value is equal to "V2". +
+

+

+ "O!=C": +

+ Show the address if the original value does not equal the + current value. +
+

+

+ The following cheat methods/filters automatically perform the function + of the "Set Original to Current" button after "Do Search" is pressed. +

+

+ "Value decreased." +

+ Show the address if the value has decreased. +
+

+

+ "Value increased." +

+ Show the address if the value has increased. +
+

+ +
+

Examples

+

"Mega Man 3" Windows Example

+

+ This example will give Mega Man unlimited energy. + Immediately after entering the Top Man stage, make your way to the + "Add Cheat" window. Push "Reset Search". + Go back to playing and move right until the first enemy appears. Allow + yourself to be hit twice. Each hit does "2" damage, so you've lost 4 energy + bars. Go to the "Add Cheat" window again and select the third filter + ("|O-C|==V2") and enter the value 4 next to "V2". Then push "Do Search". +

+

+ Several addresses will appear in the address list. You can try to find + the address you want through trial and error, or you can narrow the results + down further. We will do the latter. +

+

+ Go back to playing MM3 and get hit one more time and make your way back + to the "Add Cheat" window. Your damage is now "6". You can probably + see which address that contains your life(it is 00A2). If not, change + V2 to 6 and push "Do Search" again. This should leave only 00A2. +

+

+ Select that entry in the address list. Shift your attention to the "Add + Cheat" box to the right. Type in a meaningful name and the desired value(156; + it was the value when you had no damage, so it's safe to assume it's the + maximum value you can use). Push the "Add" button and a new entry will + appear in the cheats list. The cheat has been added. +

+

"Over Horizon" Text Interface Example

+

+ This example will give you infinite lives in the NTSC(Japanese) version + of "Over Horizon". +

+

+ Start a new game. Notice that when you press "Start" during gameplay, + the number of lives you have left is indicated. With no cheating, you + start with 3 lives(2 lives left). +

+

+ Activate the cheat interface immediately after starting a new game. + Select the "New Cheats" menu and "Reset Search". +

+

+ I'll assume that the number of lives left shown in the game is the same number + that's stored in RAM. Now, "Do Search". You're going to use the first search + filter. For V1, enter the value 2. For V2, enter the same value. This, + coupled with the fact that you just reset the search, will allow you to search + for a value "absolutely"(as opposed to changes in the value). +

+

+ Now, "Show Results". When I did it, I received 11 results: +

+
+	 1) $0000:002:002
+	 2) $001c:002:002
+	 3) $001e:002:002
+	 4) $009d:002:002
+	 5) $00b9:002:002
+	 6) $00e3:002:002
+	 7) $0405:002:002
+	 8) $0406:002:002
+	 9) $0695:002:002
+	10) $07d5:002:002	
+	11) $07f8:002:002
+
+

+ You really can't do much yet(unless you want to spend time doing trial + and error cheat additions). Return to the game. +

+

+ After losing a life, go back to the cheat interface, to the "New Cheats" + menu, and "Show Results". Here are my results: +

+
+	 1) $0000:002:002
+	 2) $001c:002:002
+	 3) $001e:002:002
+	 4) $009d:002:002
+	 5) $00b9:002:041
+	 6) $00e3:002:002
+	 7) $0405:002:001
+	 8) $0406:002:002
+	 9) $0695:002:002
+	10) $07d5:002:001
+	11) $07f8:002:002
+
+

+ Notice that two addresses seem to hold the number of lives($0405 and + $07d5). You can lose another life and go "Show Results" again, and you + should see that $07d5 is the address that holds the number of lives. +

+

+ Now that you know the address that holds the number of lives, you can + add a cheat. You can either type in the number from the cheat results list + corresponding to the address you want to add a cheat for, or you can + remember the address and select "Add Cheat" from the "New Cheats" menu. + Do the former. +

+

+ Now you will need to enter a name for the cheat. I suggest something short, + but descriptive. "Infinite lives" will work fine. Next, a prompt for + the address will show up. Since you selected an item from the list, you + can press enter to use the associated address($07d5). Next, you will + need to enter a value. It doesn't need to be large(in fact, it probably + shouldn't be; abnormally high numbers can cause some games to misbehave). + I suggest a value of 2. After this, you should get a prompt that looks like + this: +

+
+   Add cheat "Infinite lives" for address $07d5 with value 002?(Y/N)[N]:
+
+

+ Answer "Y". You now have infinite lives. +

+
+

Tips

+

+ Games store player information in many different ways. For example, + if you have "3" lives in Super Wacky Dodgeball 1989, the game might store + it in memory as 2, 3, or 4, or perhaps a different number all together. + Also, say that you have 69 life points out of 200 in Mole Mashers. The + game might store how many life points you have, or how much damage you have + taken. Relative value searches are very valuable because you probably + don't know the way that the game stores its player data. +

+

+ Some games, especially RPGs, deal with individual numbers greater than + 8-bits in size. Most that I've seen seem to store the multiple-byte data + least significant byte(lower byte of number) first in memory, though + conceivably, it could be stored most significant byte first, or the component + bytes of the number could be non-contiguous, though the latter is very unlikely. + For example, say I have 5304 experience points in Boring Quest for the + Overused Plot Device. To split the number into two eight bit decimal numbers, + take 5304 %(modulus) 256. This will give a number that is the lower 8 bits. + Next, take 5304 / 256. The integral component of your answer will be the + upper 8 bits(or the next 8 bits, if the number is or can be larger than 16 + bits) of 5304. Now you will need to search for these numbers. Fortunately, + most(all?) RPGs seem to store large numbers exactly as they are shown in the + game. +

+ + diff --git a/branches/fceux-2.2.2/documentation/faq b/branches/fceux-2.2.2/documentation/faq new file mode 100644 index 00000000..69b2914e --- /dev/null +++ b/branches/fceux-2.2.2/documentation/faq @@ -0,0 +1,67 @@ +FCE Ultra General User's FAQ + preliminary version + Last updated on: Friday 13th, 2003 +------------------ + + +Q: Why do some games make a popping sound(Rad Racer 2, Final Fantasy 3)? +A: These games do a very crude drum imitation by causing a large jump in + the output level for a short period of time via the register at $4011. + The analog filters on a real NES and Famicom make it sound rather decent. + I have not completely emulated these filters. Enabling high-quality + sound emulation will also make these pseudo-drums sound better. See + the next question for more information. + +Q: Why do some games' digitized sounds sound too loud? + Why do the drums in Crystalis and other games sound fuzzy? + +A: The NES' digital to analog converter is faulty, in that it does not output + sound linearly. This effect is most noteable when a games messes with + register $4011, which is added with the triangle wave channel and the noise + channel outputs. When $4011 is set to a large value, the volume + of the triangle wave channel and the noise channel drop significantly. More + Importantly, when digitized sounds are being played and the digitized sample + stream is at a high value, less changes will be noticeable. In other words, + the byte sequence "00 01 00" would be much more audible than the sequence + "7e 7f 7e". This non-linearity is only emulated when high-quality sound + emulation is enabled. + +Q: Why doesn't the NSF work(correctly) on FCE Ultra? +A: Some NSF rips are bad. Some read from addresses that are not specified + in the NSF specifications, expecting certain values to be returned. + Others execute undocumented instructions that have no affect on + less-accurate software NSF players, but will cause problems on NSF players + that emulate these instructions. Also, the playback rate specified + in the NSF header is currently ignored, though I haven't encountered + any problems in doing this. + +Q: Why doesn't the game work(correctly) on FCE Ultra? +A: Many factors can make a game not work on FCE Ultra: + + - If the ROM image is in the iNES format(typically files that have + the extension "nes"), its header may be incorrect. This + incorrectness may also be because of garbage in the + header. Certain utilities used to put text in the reserved + bytes of the iNES header, then those reserved bytes were + later assigned functions. FCE Ultra recognizes and + automatically removes(from the ROM image in RAM, not on the + storage medium) SOME header junk. + + If the game has graphical errors while scrolling, chances are + the mirroring is set incorrectly in the header. + + You can try to edit the header with a utility(in the NES + utilities section at http://zophar.net ) or a hex editor. + + - The on-cart hardware the game uses may not be emulated + correctly. + + - Limitations of the ROM image format may prevent a game from + being emulated correctly without special code to recognize that + game. This occurs quite often with many Koei MMC5(iNES mapper 5) + and MMC1(iNES mapper 1) games in the iNES format. FCE Ultra identifies + and emulates some of these games based on the ROM CRC32 value. + + - The ROM image may be encrypted. The author of SMYNES seems to + have done this intentionally to block other emulators from + playing "SMYNES only" games. diff --git a/branches/fceux-2.2.2/documentation/fceux-net-server.6 b/branches/fceux-2.2.2/documentation/fceux-net-server.6 new file mode 100644 index 00000000..a3cf7fd2 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/fceux-net-server.6 @@ -0,0 +1,74 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" (C) Copyright 2012 Joe Nahmias +.\" +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH FCEUX-NET-SERVER 6 "October 12, 2012" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +fceux-net-server \- FCE Ultra game server +.SH SYNOPSIS +.B fceux-net-server +.RI [ options ] +.SH DESCRIPTION +This manual page documents briefly the +.B fceux-net-server +command. +.PP +\fBfceux-net-server\fP is the game server for multiplayer use of the FCE Ultra +family of NES emulators. This server will first look in +\fI/etc/fceux-server.conf\fP for options. If that file does not exist, it will +use the defaults given here. Any argument given directly will override any +default values. +.SH OPTIONS +These programs follow the usual GNU command line syntax, with long +options starting with two dashes (`-'). +A summary of options is included below. +.TP +.B \-h, \-\-help +Displays a help message. +.TP +.B \-v, \-\-version +Displays the version number and quits. +.TP +.B \-p, \-\-port +Starts server on given port (default = \fI4046\fP). +.TP +.B \-w, \-\-password +Specifies a password for entry. +.TP +.B \-m, \-\-maxclients +Specifies the maximum number of clients allowed to access the +server (default = \fI100\fP). +.TP +.B \-t, \-\-timeout +Specifies the number of seconds before the server times out (default = \fI5\fP). +.TP +.B \-f, \-\-framedivisor +Specifies frame divisor, which controls the number of updates sent to client; +calculated as: 60 / framedivisor = updates per second (default = \fI1\fP). +.TP +.B \-c, \-\-configfile +Loads the given configuration file (default = \fI/etc/fceux\-server.conf\fP). +.SH SEE ALSO +.BR fceux (6), +The +.B FCEUX +project homepage +.RI < http://fceux.com/ >. +.SH AUTHOR +This manual page was written by Joe Nahmias +for the Debian GNU/Linux system (but may be used by others). + diff --git a/branches/fceux-2.2.2/documentation/fceux.6 b/branches/fceux-2.2.2/documentation/fceux.6 new file mode 100644 index 00000000..98c4182c --- /dev/null +++ b/branches/fceux-2.2.2/documentation/fceux.6 @@ -0,0 +1,353 @@ +.\" t Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH FCEUX 6 "June 24, 2012" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +fceux \- An emulator for the original (8-bit) Nintendo / Famicom game console. +.SH SYNOPSIS +.B fceux +.RI [ options ] +"filename" +.SH DESCRIPTION +.B FCEUX +is an emulator for the original (8-bit) Nintendo Entertainment System (NES). +It has a robust color palette rendering engine that is fully customizable, +along with excellent sound and joystick support, and even supports movie +recording and playback. +.SH OPTIONS +.SS Misc. Options +.TP +.B \--no-config {0|1} +Use default config file and do not save to it, when enabled. +.TP +.B \-g {0|1}, \--gamegenie {0|1} +Enable or disable emulated Game Genie. +.TP +.B \--nogui {0|1} +Enable or disable the GTK GUI. +.TP +.B \--loadlua FILE +Loads lua script from filename FILE. +.SS Emulation Options +.TP +.B \--pal {0|1} +Enable or disable PAL mode. +.SS Input Options +.TP +.B \-i DEV, \--inputcfg DEV +Configures input device DEV on startup. +Devices: gamepad powerpad hypershot quizking +.TP +.B \--input{1|2} DEV +Set which input device to emulate for input 1 or 2. +Devices: gamepad zapper powerpad.0 powerpad.1 arkanoid +.TP +.B \--input{3|4} DEV +Set the famicom expansion device to emulate for input 3 or 4. +Devices: quizking hypershot mahjong toprider ftrainer familykeyboard +oekakids arkanoid shadow bworld 4player +.TP +.B \--inputdisplay {0|1} +Enable or disable input display. +.TP +.B \--fourscore {0|1} +Enable or disable fourscore emulation. +.SS Graphics Options +.TP +.B \--newppu {0|1} +Enable or disable the new PPU core. (WARNING: May break savestates) +.TP +.B \--frameskip NUM +Set NUM of frames to skip per emulated frame. +.TP +.B \--clipsides {0|1} +Enable or disable clipping of the leftmost and rightmost 8 columns of +the video output. +.TP +.B \--slstart SCANLINE +Set the first scanline to be rendered. +.TP +.B \--slend SCANLINE +Set the last scanline to be rendered. +.TP +.B \--nospritelim {0|1} +When set to 0, this disables the normal 8 sprites per scanline limitation. +When set to 1, this enables the normal 8 sprites per scanline limitation. +NOTE: Yes, this option is 'backwards'. +.TP +.B \-x XRES, \--xres XRES +Set horizontal resolution for full screen mode. +.TP +.B \-y YRES, \--yres YRES +Set vertical resolution for full screen mode. +.TP +.B \--doublebuf {0|1} +Enable or disable double buffering. +.TP +.B \--autoscale {0|1} +Enable or disable autoscaling in fullscreen. +.TP +.B \--keepratio {0|1} +Keep native NES aspect ratio when autoscaling. +.TP +.B \--{x|y}scale VAL +Multiply width/height by VAL. +(Real numbers > 0 with OpenGL, otherwise integers > 0). +.TP +.B \--{x|y}stretch {0|1} +Stretch to fill surface on x/y axis (OpenGL only). +.TP +.B \-b {8|16|24|32}, \--bpp {8|16|24|32} +Set bits per pixel. +.TP +.B \--opengl {0|1} +Enable or disable OpenGL support. +.TP +.B \--openglip {0|1} +Enable or disable OpenGL linear interpolation. +.TP +.B \-f {0|1}, \--fullscreen {0|1} +Enable or disable full-screen mode. +.TP +.B \--noframe {0|1} +Hide title bar and window decorations. +.TP +.B \--special {1-4} +Use special video scaling filters. +(1 = hq2x 2 = Scale2x 3 = NTSC 2x 4 = hq3x 5 = Scale3x) +.TP +.B \-p FILE, \--palette FILE +Use the custom palette in FILE. +.TP +.B \--ntsccolor {0|1} +Enable or disable NTSC NES colors. +.TP +.B \--tint VAL +Set the NTSC tint. +.TP +.B \--hue VAL +Set the NTSC hue. +.SS Sound Options +.TP +.B \-s {0|1}, \--sound {0|1} +Enable or disable sound. +.TP +.B \--soundrate RATE +Set the sound playback sample rate (0 == off?). +.TP +.B \--soundq {0|1|2} +Set sound quality. (0 = Low 1 = High 2 = Very High) +.TP +.B \--soundbufsize MS +Set sound buffer size to MS milliseconds. +.TP +.B \--volume {0-256} +Sets the sound volume to the given value, where 256 is max volume. +.TP +.B \--trianglevol {0-256} +Sets the sound volume of the triangle wave to the given value, where 256 is max volume. +.TP +.B \--square1vol {0-256} +Sets the sound volume of square wave 1 to the given value, where 256 is max volume. +.TP +.B \--square2vol {0-256} +Sets the sound volume of square wave 2 to the given value, where 256 is max volume. +.TP +.B \--noisevol {0-256} +Sets the sound volume of the noise generator to the given value, where 256 is max volume. +.TP +.B \--lowpass {0|1} +Enables or disables lowpass filtering of the sound. +.TP +.B \--soundrecord FILE +Record sound to file FILE. +.SS Movie Options +.TP +.B \--playmov FILE +Play back a recorded FCM/FM2 movie from filename FILE. +.TP +.B \--pauseframe FRAME +Pause movie playback at frame FRAME. +.TP +.B \--moviemsg {0|1} +Enable or disable movie messages. +.TP +.B \--fcmconvert FILE +Convert fcm movie file FILE to fm2. +.TP +.B \--ripsubs FILE +Convert movie's subtitles to srt. +.TP +.B \--subtitles {0|1} +Enable or disable subtitle display. +.SS Networking Options +.TP +.B \-n SRV, \--net SRV +Connect to server SRV for TCP/IP network play. +.TP +.B \--port PORT +Use TCP/IP port PORT for network play. +.TP +.B \-u NICK, \--user NICK +Set the nickname to use in network play. +.TP +.B \-w PASS, \--pass PASS +Set password to use for connecting to the server. +.TP +.B \-k NETKEY, \--netkey NETKEY +Use string NETKEY to create a unique session for the game loaded. +.TP +.B \--players NUM +Set the number of local players. +.TP +.B \--rp2mic {0|1} +If enabled, replace Port 2 Start with microphone (Famicom). +.TP +.B \--videolog c +Calls mencoder to grab the video and audio streams to encode them. Check the documentation for more on this.? +.TP +.B \--mute {0|1} +Mutes FCEUX while still passing the audio stream to mencoder. +.TP +.SH KEYBOARD COMMANDS +.B FCEUX +has a number of commands available within the emulator. +It also includes default keyboard bindings when emulating game pads or power pads. +.SS Gamepad Keyboard Bindings +.TS +center box; +cb | cb, c | ci. +NES Gamepad Keyboard += +Up Keypad Up +Down Keypad Down +Left Keypad Left +Right Keypad Right +A F +B D +Select S +Start Enter +.TE +.SS Other Commands +.PP +.TP 15 +.BI +Toggle full-screen mode. +.TP 15 +.BI +Cheat menu (command-line only). +.TP 15 +.BI +Toggle savestate binding to movies. +.TP 15 +.BI +Load LUA script. +.TP 15 +.BI +Toggles background rendering. +.TP 15 +.BI +Save game state into current slot (set using number keys). +.TP 15 +.BI +Restore game state from current slot (set using number keys). +.TP 15 +.BI +Toggle movie subtitles. +.TP 15 +.BI +Reset NES. +.TP 15 +.BI +Save screen snapshot. +.TP 15 +.BI Shift + +Beging recording video. +.TP 15 +.BI Shift + +Load recorded video. +.TP 15 +.BI 0-9 +Select save state slot. +.TP 15 +.BI Page Up/Page Down +Select next/previous state. +.TP 15 +.BI \- +Decrease emulation speed. +.TP 15 +.BI = +Increase emulation speed. +.TP 15 +.BI Tab +Hold for turbo emulation speed. +.TP 15 +.BI Pause +Pause emulation. +.TP 15 +.BI \e +Advance a single frame. +.TP 15 +.BI . +Toggle movie frame counter. +.TP 15 +.BI , +Toggle input display. +.TP 15 +.BI q +Toggle movie read-only. +.TP 15 +.BI ' +Advance a single frame. +.TP 15 +.BI / +Lag counter display. +.TP 15 +.BI Delete +Frame advance lag skip display. +.TP 15 +.BR +Quit +.B FCEUX. +.SS VS Unisystem Commands +.PP +.TP 15 +.BI +Insert coin. +.TP 15 +.BI +Show/Hide dip switches. +.TP 15 +.BI 1-8 +Toggle dip switches (when dip switches are shown). +.SS Famicom Disk System Commands +.PP +.TP 15 +.BI +Select disk and disk side. +.TP 15 +.BI +Eject or insert disk. +.TP +.I http://fceux.com/ +The +.B FCEUX +project homepage. +.SH AUTHOR +This manual page was written by Joe Nahmias , +Lukas Sabota and Alexander Toresson + for the Debian GNU/Linux system +(but may be used by others). diff --git a/branches/fceux-2.2.2/documentation/fcs.txt b/branches/fceux-2.2.2/documentation/fcs.txt new file mode 100644 index 00000000..dbaeec53 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/fcs.txt @@ -0,0 +1,153 @@ +FCE Ultra Save State Format + Updated: Mar 9, 2003 +--------------------------------------- + +FCE Ultra's save state format is now designed to be as forward and backwards +compatible as possible. This is achieved through the (over)use of chunks. +All multiple-byte variables are stored LSB(least significant byte)-first. +Data types: + + (u)int8 - (un)signed 8 bit variable(also referred to as "byte") + (u)int16 - (un)signed 16 bit variable + (u)int32 - (un)signed 32 bit variable + +-- Main File Header: + +The main file header is 16-bytes in length. The first three bytes contain +the string "FCS". The next byte contains the version of FCE Ultra that saved +this save state. This document only applies to version "53"(.53) and higher. +After the version byte, the size of the entire file in bytes(minus the 16 byte +main file header) is stored. The rest of the header is currently unused +and should be nulled out. Example of relevant parts: + + FCS + +-- Section Chunks: + +Sections chunk headers are 5-bytes in length. The first byte defines what +section it is, the next four bytes define the total size of the section +(including the section chunk header). + + + +Section definitions: + + 1 - "CPU" + 2 - "CPUC" + 3 - "PPU" + 4 - "CTLR" + 5 - "SND" + 16 - "EXTRA" + +-- Subsection Chunks + +Subsection chunks are stored within section chunks. They contain the actual +state data. Each subsection chunk is composed of an 8-byte header and the data. +The header contains a description(a name) and the size of the data contained +in the chunk: + + +The name is a four-byte string. It does not need to be null-terminated. +If the string is less than four bytes in length, the remaining unused bytes +must be null. + +-- Subsection Chunk Description Definitions + +Note that not all subsection chunk description definitions listed below +are guaranteed to be in the section chunk. It's just a list of what CAN +be in a section chunk. This especially applies to the "EXTRA" subsection. + +---- Section "CPU" + + Name: Type: Description: + + PC uint16 Program Counter + A uint8 Accumulator + P uint8 Processor status register + X uint8 X register + Y uint8 Y register + S uint8 Stack pointer + RAM uint8[0x800] 2KB work RAM + +---- Section "CPUC" (emulator specific) + + Name: Type: Description: + + JAMM uint8 Non-zero value if CPU in a "jammed" state + IRQL uint8 Non-zero value if IRQs are to be generated constantly + ICoa int32 Temporary cycle counter + ICou int32 Cycle counter + +---- Section "PPU" + + Name: Type: Description: + + NTAR uint8[0x800] 2 KB of name/attribute table RAM + PRAM uint8[32] 32 bytes of palette index RAM + SPRA uint8[0x100] 256 bytes of sprite RAM + PPU uint8[4] Last values written to $2000 and $2001, the PPU + status register, and the last value written to + $2003. + XOFF uint8 Tile X-offset. + VTOG uint8 Toggle used by $2005 and $2006. + RADD uint16 PPU Address Register(address written to/read from + when $2007 is accessed). + TADD uint16 PPU Address Register + VBUF uint8 VRAM Read Buffer + PGEN uint8 PPU "general" latch. See Ki's document. + +---- Section "CTLR" (somewhat emulator specific) + + Name: Type: Description: + + J1RB uint8 Bit to be returned when first joystick is read. + J2RB uint8 Bit to be returned when second joystick is read. + +---- Section "SND" (somewhat emulator specific) + + NREG uint16 Noise LFSR. + P17 uint8 Last byte written to $4017. + PBIN uint8 DMC bit index. + PAIN uint32 DMC address index(from $8000). + PSIN uint32 DMC length counter(how many bytes left + to fetch). + + + +---- Section "EXTRA" (varying emulator specificness) + + For iNES-format games(incomplete, and doesn't apply to every game): + + Name: Type: Description: + + WRAM uint8[0x2000] 8KB of WRAM at $6000-$7fff + MEXR uint8[0x8000] (very emulator specific) + CHRR uint8[0x2000] 8KB of CHR RAM at $0000-$1fff(in PPU address space). + EXNR uint8[0x800] Extra 2KB of name/attribute table RAM. + MPBY uint8[32] (very emulator specific) + MIRR uint8 Current mirroring: + 0 = "Horizontal" + 1 = "Vertical" + $10 = Mirror from $2000 + $11 = Mirror from $2400 + IRQC uint32 Generic IRQ counter + IQL1 uint32 Generic IRQ latch + IQL2 uint32 Generic IRQ latch + IRQA uint8 Generic IRQ on/off register. + PBL uint8[4] List of 4 8KB ROM banks paged in at $8000-$FFFF + CBL uint8[8] List of 8 1KB VROM banks page in at $0000-$1FFF(PPU). + + For FDS games(incomplete): + + Name: Type: Description: + + DDT uint8[65500] Disk data for side x(0-3). + FDSR uint8[0x8000] 32 KB of work RAM + CHRR uint8[0x2000] 8 KB of CHR RAM + IRQC uint32 IRQ counter + IQL1 uint32 IRQ latch + IRQA uint8 IRQ on/off. + + WAVE uint8[64] Carrier waveform data. + MWAV uint8[32] Modulator waveform data. + AMPL uint8[2] Amplitude data. diff --git a/branches/fceux-2.2.2/documentation/fm2.txt b/branches/fceux-2.2.2/documentation/fm2.txt new file mode 100644 index 00000000..37ec4969 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/fm2.txt @@ -0,0 +1,79 @@ +FM2 is ascii plain text. +It consists of several key-value pairs followed by an inputlog section. +The inputlog section can be identified by its starting with a | (pipe). +The inputlog section terminates at eof. +Newlines may be \r\n or \n + +Key-value pairs consist of a key identifier, followed by a space separator, followed by the value text. +Value text is always terminated by a newline, which the value text will not include. +The value text is parsed differently depending on the type of the key. +The key-value pairs may be in any order, except that the first key must be version. + +Integer keys (also used for booleans, with a 1 or 0) will have a value that is a simple integer not to exceed 32bits + - version (required) - the version of the movie file format; for now it is always 3 + - emuVersion (required) - the version of the emulator used to produce the movie + - rerecordCount (optional) - the rerecord count + - palFlag (bool) (optional) - true if the movie uses pal timing + - fourscore (bool) (*note C) - true if a fourscore was used + - port0, port1 (*note C) - indicates the types of input devices. Supported values are: + SI_GAMEPAD = 1, + SI_ZAPPER = 2 + - port2 (required) - indicates the type of the FCExp port device which was attached. Supported values are: + SIFC_NONE = 0 + +String keys have values that consist of the remainder of the key-value pair line. As a consequence, string values cannot contain newlines. + - romFilename (required) - the name of the file used to record the movie + - comment (optional) - simply a memo. + by convention, the first token in the comment value is the subject of the comment. + by convention, subsequent comments with the same subject will have their ordering preserved and may be used to approximate multiline comments. + by convention, the author of the movie should be stored in comment(s) with a subject of: author + +Hex string keys (used for binary blobs) will have a value that is like 0x0123456789ABCDEF... + - romChecksum (required) - the MD5 hash of the rom which was used to record the movie + - savestate (optional) - a fcs savestate blob, in case a movie was recorded from savestate + +GUID keys have a value which is in the standard guid format: 452DE2C3-EF43-2FA9-77AC-0677FC51543B + - guid (required) a unique identifier for a movie, generated when the movie is created, which is used when loading a savestate to make sure it belongs to the current movie. + +The inputlog section consists of lines beginning and ending with a | (pipe). +The fields are as follows, except as noted in note C. +|c|port0|port1|port2| + +field c is a variable length decimal integer which is a bitfield corresponding to miscellaneous input states which are valid at the start of the frame. +Current values for this are +MOVIECMD_RESET = 1 + +the format of port0, port1, port2 depends on which types of devices were attached. +SI_GAMEPAD: + the field consists of eight characters which constitute a bitfield. + any character other than ' ' or '.' means that the button was pressed. + by convention, the following mnemonics will be used in a column to remind us of which button corresponds to which column: + RLDUTSBA (Right,Left,Down,Up,sTart,Select,B,A) + This seemingly arbitrary ordering is actually the reverse of the originally-desired order, which was screwed up in the first release of FCEUX. So we have preserved it for compatibility's sake. +SI_ZAPPER: + XXX YYY B Q Z + XXX: %03d, the x position of the mouse + YYY: %03d, the y position of the mouse + B: %1d, 1 if the mouse button is pressed; 0 if not + Q: %1d, an internal value used by the emulator's zapper code (this is most unfortunate..) + Z: %d, a variable-length decimal integer; an internal value used by the emulator's zapper code (this is even more unfortunate..) +SIFC_NONE: + this field must always be empty. + +* Notes * +A. There is no key-value pair that indicates the length of the movie. This must be read by scanning the inputlog and counting the number of lines. + +B. All movies start from power-on, unless a savestate key-value is present. + +C. +If a fourscore is used, then port0 and port1 are irrelevant and ignored. +The input types must all be gamepads, and the inputlog will be in the following format: + {player1 player2 player3 player4} +|c|RLDUTSBA|RLDUTSBA|RLDUTSBA|RLDUTSBA|port2| +If a fourscore is not used, then port0 and port1 are required. + +D. The emulator uses these framerate constants + - NTSC: 1008307711 /256/65536 = 60.099822938442230224609375 + - PAL : 838977920 /256/65536 = 50.00698089599609375 + +E. The author of this format is curious about what people think of it. Please let him know! \ No newline at end of file diff --git a/branches/fceux-2.2.2/documentation/porting.txt b/branches/fceux-2.2.2/documentation/porting.txt new file mode 100644 index 00000000..63d2b4fc --- /dev/null +++ b/branches/fceux-2.2.2/documentation/porting.txt @@ -0,0 +1,289 @@ +FCE Ultra Porting Guide + Updated: October 4, 2003 + +*Incomplete* + + +***Driver-supplied functions: + These functions will only be called after the driver code calls + FCEUI_LoadGame() or FCEUI_Emulate(). + +void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); + Called by FCE Ultra on every emulated frame. This function should + perform the following three things(in any order): + + 1. + Update the data pointed to by the pointers passed to + FCEUI_SetInput() and FCEUI_SetInputFC(). + 2. + Copy contents of XBuf over to video memory(or whatever needs to be + done to make the contents of XBuf visible on screen). + Each line is 256 pixels(and bytes) in width, and there can be 240 + lines. The pitch for each line is 272 bytes. + XBuf will be 0 if the symbol FRAMESKIP is defined and this frame + was skipped. + 3. + Write the contents of "Buffer" to the sound device. "Count" is the + number of samples to write. Only the lower 16-bits of each + sample are used, so each 32-bit sample in "Buffer" can be converted to + signed 16-bit by dropping the upper 16 bits. + When sound was disabled for the frame, "Count" will be 0. + +void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b); + Set palette entry "index" to specified RGB values(value: min=0, max=255). + +void FCEUD_GetPalette(uint8 index, uint8 *r, uint8 *g, uint8 *b); + Get palette entry "index" data. + +void FCEUD_PrintError(char *s); + Print/Display an error message string pointed to by "s". + +void FCEUD_Message(char *s); + Display a status message string. + + +int FCEUD_NetworkConnect(void); + Initialize a network connection. Return 0 if an error occurs. + +int FCEUD_GetDataFromClients(uint8 *data); + +/* Sends 5 bytes of data to all clients. */ +int FCEUD_SendDataToClients(uint8 *data); + +/* Sends 1 byte of data to server, and maybe a command. */ +int FCEUD_SendDataToServer(uint8 v, uint8 cmd); + +/* Gets 5 bytes of data from the server. This function must block. */ +int FCEUD_GetDataFromServer(uint8 *data); + +void FCEUD_NetworkClose(void); + Close the network connection. + + +***FCE Ultra functions(called by the driver code): + The FCEUI_* functions may only be called before FCEUI_Emulate() is + called or after it returns and before it is called again, or after the + following functions are called and before they return: + FCEUD_Update(); + Calling the FCEUI_* functions at any other time may result in + undefined behavior. + +void FCEUI_SetInput(int port, int type, void *ptr, int attrib); + "port" can be either 0 or 1, and corresponds to the physical + ports on the front of a NES. + + "type" may be: + SI_NONE - No input on this port. + SI_GAMEPAD - Standard NES gamepad + SI_ZAPPER - "Zapper" light gun. + SI_POWERPAD - Power-pad mat. + SI_ARKANOID - Arkanoid controller. + +void FCEUI_SetInputFC(int type, void *ptr, int attrib); + Special Famicom devices. + "type" may be: + SIFC_NONE - No input here. + SIFC_ARKANOID - Arkanoid controller. + SIFC_SHADOW - "Space Shadow" gun. + SIFC_4PLAYER - Famicom 4-player adapter + SIFC_FKB - Family Keyboard + +void FCEUI_DisableFourScore(int s); + Disables four-score emulation if s is nonzero. + +void FCEUI_SetSnapName(int a); + 0 to order screen snapshots numerically(0.png), 1 to order them file + base-numerically(smb3-0.png). + +void FCEUI_DisableSpriteLimitation(int a); + Disables the 8-sprite-per-scanline limitation of the NES if "a" + is nonzero. The default behavior is the limitation is enabled. + +void FCEUI_SaveExtraDataUnderBase(int a); + If "a" is nonzero, save extra non-volatile game data(battery-backed + RAM) under FCE Ultra's base directory. Otherwise, the behavior is + to save it under the same directory the game is located in(this is + the default behavior). + +FCEUGI *FCEUI_LoadGame(char *name); + Loads a new file. "name" is the full path of the file to load. + Returns 0 on failure, or a pointer to data type "FCEUGI": + See file "git.h" for more details on this structure. + +int FCEUI_Initialize(void); + Allocates and initializes memory. Should only be called once, before + any calls to other FCEU functions. + +void FCEUI_SetBaseDirectory(void); + Specifies the base FCE Ultra directory. This should be called + immediately after FCEUI_Initialize() and any time afterwards. + +void FCEUI_SetDirOverride(int which, char *n); + + FCEUIOD_CHEATS - Cheats + FCEUIOD_MISC - Miscellaneous stuff(custom game palettes) + FCEUIOD_NV - Non-volatile game data(battery backed RAM) + FCEUIOD_SNAPS - Screen snapshots + FCEUIOD_STATE - Save states + +void FCEUI_Emulate(void); + Enters the emulation loop. This loop will be exited when FCEUI_CloseGame() + is called. This function obviously shouldn't be called if FCEUI_LoadGame() + wasn't called or FCEUI_CloseGame() was called after FCEUI_LoadGame(). + +void FCEUI_CloseGame(void); + Closes the loaded game and frees all memory used to load it. + Also causes FCEUI_Emulate() to return. + +void FCEUI_ResetNES(void); +void FCEUI_PowerNES(void); + +void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); + Sets the first(minimum is 0) and last(NOT the last scanline plus one; + maximum is 239) scanlines of background data to draw, for both NTSC + emulation mode and PAL emulation mode. + + Defaults are as if this function were called with the variables set + up as follows: + ntscf=8, ntscl=231, palf=0, pall=239 + +void FCEUI_SetNetworkPlay(int type); + Sets status of network play according to "type". If type is 0, + then network play is disabled. If type is 1, then we are server. + If type is 2, then we are a client. + +void FCEUI_SelectState(int w); + Selects the state "slot" to save to and load from. + +void FCEUI_SaveState(void); + Saves the current virtual NES state from the "slot" selected by + FCEUI_SelectState(). + +void FCEUI_LoadState(void); + Loads the current virtual NES state from the "slot" selected by + FCEUI_SelectState(). + +void FCEUI_SaveSnapshot(void); + Saves a screen snapshot. + +void FCEUI_DispMessage(char *msg); + Displays a short, one-line message using FCE Ultra's built-in + functions and ASCII font data. + +int32 FCEUI_GetDesiredFPS(void); + Returns the desired FPS based on whether NTSC or PAL emulation is + enabled, shifted left by 24 bits(this is necessary because the real + FPS value is not a whole integer). This function should only be + necessary if sound emulation is disabled. + +int FCEUI_GetCurrentVidSystem(int *slstart, int *slend); + Convenience function(not strictly necessary, but reduces excessive code + duplication); returns currently emulated video system + (0=NTSC, 1=PAL). It will also set the variables pointed to by slstart + and slend to the first and last scanlines to be rendered, respectively, + if slstart and slend are not 0. + +void FCEUI_GetNTSCTH(int *tint, int *hue); +void FCEUI_SetNTSCTH(int n, int tint, int hue); + +int FCEUI_AddCheat(char *name, uint16 addr, uint8 val); + Adds a RAM cheat with the specified name to patch the address "addr" + with the value "val". + +int FCEUI_DelCheat(uint32 which); + Deletes the specified(by number) cheat. + +void FCEUI_ListCheats(void (*callb)(char *name, uint16 a, uint8 v)); + Causes FCE Ultra to go through the list of all cheats loaded for + the current game and call callb() for each cheat with the cheat + information. + +int FCEUI_GetCheat(uint32 which, char **name, int32 *a, int32 *v, int *s); + Gets information on the cheat referenced by "which". + +int FCEUI_SetCheat(uint32 which, char *name, int32 a, int32 v, int s); + Sets information for the cheat referenced by "which". + +void FCEUI_CheatSearchBegin(void); + Begins the cheat search process. Current RAM values are copied + to a buffer to later be processed by the other cheat search functions. + +void FCEUI_CheatSearchEnd(int type, int v1, int v2); + Searches the buffer using the search method specified by "type" + and the parameters "v1" and "v2". + +int32 FCEUI_CheatSearchGetCount(void); + Returns the number of matches from the cheat search. + +void FCEUI_CheatSearchGet(void (*callb)(uint16 a, int last, int current)); + +void FCEUI_CheatSearchGetRange(int first, int last, void (*callb)(uint16 a, int last, int current)); + Like FCEUI_CheatSearchGet(), but you can specify the first and last + matches to get. + +void FCEUI_CheatSearchShowExcluded(void); + Undos any exclusions of valid addresses done by FCEUI_CheatSearchEnd(). + +void FCEUI_CheatSearchSetCurrentAsOriginal(void); + Copies the current values in RAM into the cheat search buffer. + +void FCEUI_MemDump(uint16 a, int32 len, void (*callb)(uint16 a, uint8 v)); + Callback to dump memory. + +void FCEUI_DumpMem(char *fname, uint32 start, uint32 end); + Dump memory to filename fname. + +void FCEUI_MemPoke(uint16 a, uint8 v, int hl); + Write a byte to specified address. Set hl to 1 to attempt to store + it to ROM("high-level" write). + +void FCEUI_NMI(void); + Triggers(queues) an NMI. + +void FCEUI_IRQ(void); + Triggers(queues) an IRQ. + +void FCEUI_Disassemble(uint16 a, int (*callb)(uint16 a, char *s)); + Text disassembly. + +void FCEUI_GetIVectors(uint16 *reset, uint16 *irq, uint16 *nmi); + Get current interrupt vectors. + + +***Recognized defined symbols: + +The following defined symbols affect the way FCE Ultra is compiled: + + C80x86 + - Include 80x86 inline assembly in AT&T syntax, if available. Also + use special 80x86-specific C constructs if the compiler is compatible. + + FRAMESKIP + - Include frame skipping code. + + NETWORK + - Include network play code. + + FPS + - Compile code that prints out a number when FCE Ultra exits + that represents the average fps. + + ZLIB + - Compile support for compressed PKZIP-style files AND gzip compressed + files. "unzip.c" will need to be compiled and linked in by you if + this is defined(it's in the zlib subdirectory). + + LSB_FIRST + - Compile code to expect that variables that are greater than 8 bits + in size are stored Least Significant Byte First in memory. + + PSS_STYLE x + - Sets the path separator style to the integer 'x'. Valid styles are: + 1: Only "/" - For UNIX platforms. + 2: Both "/" and "\" - For Windows and MSDOS platforms. + 3: Only "\" - For ???. + 4: Only ":" - For Apple IIs ^_^. + + + + diff --git a/branches/fceux-2.2.2/documentation/protocol.txt b/branches/fceux-2.2.2/documentation/protocol.txt new file mode 100644 index 00000000..0122e498 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/protocol.txt @@ -0,0 +1,90 @@ +FCE Ultra 0.91+ network play protocol. +Description v 0.0.1 +-------------------------------------- + +In FCE Ultra, all data is sent to the server, and then the server +distributes, every emulated frame(60hz on NTSC), the collated data to the +clients. + +The server should not block when it is receiving UDP data from the clients. +If no UDP data is available, then just go on. + +The clients MUST block until the input data packet comes on every emulated +frame. + +Packets from the server to the client are sent out over both TCP and UDP. +Duplicate packets should be discarded. Out-of-order packets can either +be cached, or discarded(what I recommend, as caching code gets a little +complex and wouldn't yield any benefit from what I've observed). +In the case of client->server UDP communications, the server should just use +the data from the UDP packet that has the highest packet number count, and +the server should then set its internal incoming packet counter to that +number(to prevent out-of-order packets from totally screwing up user input). + +The "magic number"(used with UDP packets) is meant to reduce the chance of a hostile remote host +from disrupting the network play, without resorting to using extreme amounts +of network bandwidth. The server generates the magic number, and it is best +if the magic number is as random as possible. +UDP packets received with an incorrect magic number should be discarded, of +course. + +Initialization, server->client: + +uint32 Local UDP port(what the server is listening on). +uint32 Player number(0-3) for client. +uint32 Magic number(for UDP). + + +Initialization, client->server + +uint32 Local UDP port(that the client is listening on). + + +Structure of UDP packet data: + +uint32 CRC32 - Includes magic number, packet counter, and + data. For reference, CRC32 is calculated + with the zlib function crc32(). +uint32 Magic number +uint32 Packet counter(linear, starts at 0). +uint8[variable] Data. + +Structure of tcp packet data: + +uint32 Packet counter(" "). +uint8[variable] Data. + + + +Data format of server->client communications: + + uint8[4] Controller data + uint8 Command byte. 0 if no command. Otherwise(in decimal): + + 1 Select FDS disk side. + 2 Insert/eject FDS disk. + 10 Toggle VS Unisystem dip switch editing. + 11 ... 18 Toggle VS Unisystem dip switches. + 19 Insert VS Unisystem coin. + 30 Reset NES. + 31 Power toggle NES. + 40 Save state(not implemented correctly). + 41 Load state(not implemented correctly). + 42 ... 50 Select save state slot(minus 42). + + Special message communications occurs if the "Packet counter" is + 0xFFFFFFFF(only with TCP): + + uint32 Length of text data, minus the null character(the null + character is sent, though). + uint8[variable] Text data. Convert all characters <32 to space, and + then display the text message(it's one line) as is. + +Structure of client->server communication: + + uint8 Controller data(for this client). + + Over tcp channel, a text message can be sent. It is one line, + null terminated(remember the data and parse it and display it and + distribute it to the clients once the null byte is received). + Maximum size of message(including the null byte) should be 256 bytes. diff --git a/branches/fceux-2.2.2/documentation/snes9x-lua.html b/branches/fceux-2.2.2/documentation/snes9x-lua.html new file mode 100644 index 00000000..13ab2bb5 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/snes9x-lua.html @@ -0,0 +1,417 @@ + +Snes9x Lua Library +This is the API from DeHackEd's version of Lua in ZSnes. At the time of writing, FCUE's Lua was based on this API.

+ +

Basics

+Your code will be run alongside the emulator's main loop. You code should +probably look roughly like this: +
+
-- initialization goes here
+while condition do
+   -- Code executed once per frame
+ 
+   snes9x.frameadvance()
+
+
+end
+
+-- Cleanup goes here
+

+ +When Lua execution starts, the emulator will be automatically unpaused if it +is currently paused. If so, it will automatically be paused when the script +exits, voluntarily or otherwise. This allows you to have a script execute +some work on your behalf and then when it exits the emulator will be paused, +ready for the player to continue use. + +
+

Base library

+Handy little things that are not put into a class. Mostly binary operations right now. +
+ +
int AND(int arg1, int arg2, ..., int argn)
+Since Lua lacks binary operators and since binary will come up with memory manipulation, +I offer this function. Output is the binary AND of all its parameters together. +Minimum 1 argument, all integers. +

+At a binary level, the AND of two binary bits is 1 if both inputs are 1, and the output +is 0 in any other case. Commonly used to test if a bit is set by ANDing with a number +with only the desired position set to 1. +


+ +
int OR(int arg1, int arg2, ..., int argn)
+The OR of two bits is 1 if either of the inputs is 1, and 0 if both inputs are 0. +Typically used to force a single bit to 1, regardless of its current state. +
+ +
int XOR(int arg1, int arg2, ..., int argn)
+XOR flips bits. An even number of 1s yields a zero and an odd number of 1s yields a 1. +Commonly used to toggle a bit by XORing. +
+ +
int BIT(int which)
+Returns a number with only the given bit set. which is in the range from 0 to 15 since the +SNES is a 16 bit system. BIT(15) == 32768 +

+... Actually this system will accept a range of 0 to 30, but none of the memory access functions will +accept it, so you're on your own for those. 31 is not allowed for now due to signedness risking wreaking havoc. +

snes9x

+ +Basic master emulator control. +
+ +
snes9x.speedmode(string mode)
+Selects the speed mode snes9x should run at while Lua is in control of frame advance. It must be set to one of the following: + +In modes other than normal, pause will have no effect. + +
+ +
snes9x.frameadvance()
+Snes9x executes one frame. This function pauses until the execution finishes. General system slowdown +when running at normal speed (ie. sleeping for 1/60 seconds) also occurs here when not in high speed mode. +

+Warning: Due to the way the code is written, the times this function may be called is restricted. Norably, +it must not be called within a coroutine or under a [x]pcall(). You can use coroutines for +your own purposes, but they must not call this function themselves. Furthermore, this function cannot be called from any +"registered" callback function. An error will occur if you do. +

+


+ +
snes9x.message(string msg)
+Displays the indicated string on the user's screen. snes9x.speedmode("normal") is probably the only way this is of any use, +lest the message not be displayed at all +
+ +
snes9x.pause()
+v0.05+ only
+Pauses the emulator. This function blocks until the user unpauses. +

+This function is allowed to be called from outside a frame boundary (ie. when it is not allowed to call +snes9x.frameadvance). In this case, the function does not wait for the pause because you can't pause +midway through a frame. Your code will continue to execute and the emulator will be paused at the end +of the current frame. If you are at a frame boundary, this function acts a lot like snes9x.frameadvance() +plus the whole pause thing. +

+It might be smart to reset the speed mode to "normal" if it is not already so. +


+ +
snes9x.wait()
+v0.06+ only
+Skips emulation of the next frame. If your script needs to wait for something to happen before proceeding (eg. +input from another application) then you should call this. Otherwise the GUI might jam up and your +application will not appear to be responding and need termination. It is expected that this function +will pause the script for 1/60 of a second without actually running the emulator itself, though it tends to be +OS-dependent right now. +

+If you're not sufficiently confused yet, think of this as pausing for one frame. +

+If you need to do a large amount of calculations -- so much that you risk setting off the rampant script +warning, just call this function every once in a while. +

+Might want to avoid using this if you don't need to. If the emulator is running at normal speed, paused +and the user presses frame-advance, they might be confused when nothing happens. +

+

memory

+ +Memory access and manipulation. + +
int memory.readbyte(int address)
+int memory.readword(int address)
+Reads a number of bits (8 or 16) and returns the memory contents. The address must be a fully qualified +memory address. The RAM range is 0x7e0000 through 0x7fffff, but you may use any memory address, including +the ROM data itself. +
+
int memory.readbytesigned(int address)
+int memory.readwordsigned(int address)
v0.04+ only
+ +Same as its counterparts, except numbers will be treated as signed. Numbers larger than 127 for bytes and +32767 for words will be translated into the correct negative numbers. For reference, an alternate formula +is to subtract 256 for bytes and 65536 for words from any number equal to or larger than half that number. +For example, a byte at 250 becomes 250-256 = -6. +

+ +
memory.writebyte(int address, int value)
+memory.writebyte(int address, int value)
+ +Writes a number of bits (8 or 16) to the indicated memory address. The address MUST be in the range of +0x7e0000 through 0x7fffff. + +
+
memory.register(int address, function func)
+When the given memory address is written to (range must be 0x7e0000 to 0x7fffff), the given function will be +called. The execution of the CPU will be paused mid-frame to call the given function. +

+Only one function can be registered with a memory address. 16 bit writes will only trigger the lower address +listener. There is no distinction between 8 and 16 bit writes. func may be nil in order to +delete a function from listening. +

+Code called may not call snes9x.frameadvance() or any savestate save/load functions, and any button +manipulation results are undefined. Those actions are only meaningful at frame boundaries. + + +

+

joypad

+ +Access to the gamepads. Note that Lua makes some joysticks do strange things. +Setting joypad inputs causes the user input for that frame to be ignored, but +only for that one frame. +

+Joypads are numbered 1 to 5. +

+Joypad buttons are selected by use of a table with special keys. The table +has keys start, select, up, down, left, right, A, B, X, Y, L, R. Note the +case is sensetive. Buttons that are pressed are set to a non-nil value +(use of the integer 1 is just a convention). Note that "false" is valid, +but discouraged as testing for logical true will fail. +

+Currently reading input from a movie file is not possible, but +a movie will record button presses from Lua. +

table joypad.read(int which)
+Returns a table indicating which buttons are pressed by the user. +This is probably the only way to get input to the script by the user. +This is always user input, even if the joypads have been set by joypad.set. +
+
joypad.set(int which, table buttons)
+Sets the buttons to be pressed. These choices will be made in place of +what the user is pressing during the next frame advance; they are then +discarded, so this must be called once every frame, even if you just want to +keep the same buttons pressed for several frames. + +

+

savestate

+Control over the savestate process. Savestate objects are opaque structures +that represent non-player accessible states (except for the functions that +return "official" savesates). Such an object is garbage collectable, in which +case the savestate is no longer usable. Recycling of existing savestate objects +is highly recommended for disk space concerns lest the garbage collector +grow lazy.

+Each object is basically a savestate file. Anonymous savestates are saved to +your temp directory. + +


+
object savestate.create(int userslot=nil)
+Creates a savestate object for use. If the userslot argument +is given, the state will be accessible via the associated +F-key (F1 through F12 are 1 through 12). If not specified or +nil, an anonymous savestate is created that only Lua can access. +

+Each call to savestate.create() (without parameters) returns +a unique savestate. As such, if you discard the contents of a variable +containing an important savestate, you've just shot yourself in the foot. +

+An object may be used freely once created, saved over and loaded whenever. +

+It is an error to load an anonymous (non-player accessbile) state that +has not been saved yet, since it's empty. +

+Each savestate uses about 120 KB of disk space and the random filename generator +has its limits with regards to how many filenames it can generate. Don't go too +overboard. If you need more than 1000 savestates, maybe you should rethink +your tehcnique. (The actual windows limit is about 32768, Linux is higher). +


savestate.save(object state)
+Saves the current state to the given object. Causes an error if something goes horribly +wrong, or if called within any "registered" callback function. +
savestate.load(object state)
+Loads the given state. Throws an error for all the same bad things that might happen. + +
+
function savestate.registersave(function save)
+v0.06+ only
+Registers a function to be called on a savestate event. This includes both calls to +savestate.save() and users pressing buttons. The function will be called without +parameters. +

+The function called is permitted to return any number of string and number values. +Lua lets you do this by simply writing return 1, 2, 3, "four and five", 6.2, integerVar +

+These variables must be numeric or string. They will be saved into the savestate itself +and returned back to the application via savestate.registerload() should the state ever be loaded +again later. +

+Only one function can be registered. Registering a second function will cause the first function +to be returned back by savestate.registersave() before being discarded. +

+Savestates created with this mechanism are likely to break some savestate features in other emulators. +Don't be surprised if savestates from this version don't work on others if you enable all those +fancy features. Compatible savestates are created if there is no registered save function, or if +the save function returns no parameters at all. +


+
function savestate.registerload(function load)
+v0.06+ only
+The companion to savestate.registersave, this function registers a function to be called during +a load. The function will be passed parameters -- exactly those returned by the function +registered for a save. If the savestate contains no saved data for your script, the function +will be called without parameters. +

+Concept code: + +

function saveState() .... end
+function loadState(arg1, arg2, ...)  ... end
+
+savestate.registersave(saveState)
+savestate.registerload(loadState)
+
+
+-- Behind the scenes
+local saved_variables 
+
+
+
+-- User presses savestate
+saved_variables = { saveState() } -- All return values saved
+
+
+-- Time passes
+-- ...
+
+
+-- User presses loadstate
+loadState(unpack(saved_variables))
+
+
+

Recommendations for registered savestates

+ +

+

movie

+Access to movie information. +
+

+
int movie.framecount()
+Returns the current frame count, or nil if no movie is running. +
+
string movie.mode()
+Returns "record", "playback", or nil, depending on the current movie. +
+
movie.rerecordcounting(boolean counting)
+Select whether rerecording should be counted. If set to false, you can do +all the brute force work you want without inflating the rerecord count. +

+This will automatically be set to true after a script finishes running, so +don't worry about messing up the rerecord count for the player. +


+
movie.stop()
+Stops movie recording/playback. I'm not sure why you'd want to do that, but you can. +
+ +

gui

+0.03+ only
+The ability to draw on the surface of the screen is a long sought feature. The surface is 256x239 pixels +(256x224 most of the time though) with (0,0) being in the top-left corner of the screen. +

+The SNES uses a 16 bit colour system. Red and blue both use 5 bits (0 through 31) while green uses +6 bits (0 through 63), in place of the usual 0 to 255 range. If you want to construct your own exact colours, +multiply your red value by 2048, your green value by 32 and leave your blue value untouched. Add these all +together to get a valid colour. Bright red would be 31*2048 = 63488, for example. +

+Some strings are accepted. HTML style encoding such as "#00ff00" for green is accepted. Some simple strings such +as "red", "green", "blue", "white" and "black" are also accepted. +

+The transparent colour is 1 (a VERY dark blue, which is probably not worth using in place of black) or the string +"clear". Remove drawn elements using this colour. +

+Output is delayed by a frame. The graphics are drawn on a separate buffer and then overlayed on the image +during the next refresh, which means allowing for a frame to execute. Also, the buffer is cleared after drawing, +so if you want to keep something on screen, you must keep drawing it on each frame. +

+It is an error to draw outside the drawing area. gdoverlay is the only exception to this rule - images will +be clipped to the visible area. +


+
r,g,b = gui.getpixel(int x, int y)
+Returns the pixel on the indicated coordinate. (0,0) is the top-left corner and (255, 223) is the typical bottom-right corner, +though (255,238) is allowed. The return value range is (0,0,0) to (31,63,31). You get the actual screen surface before +any damage is done by your drawing. Well, unless you call snes9x.wait() in which case your damage is applied and the SNES +hardware doesn't get a chance to draw a new frame. :) +
+
gui.drawpixel(int x, int y, type colour)
+Draw a single pixel on the screen. +
+
gui.drawline(int x1, int y1, int x2, int y2, type colour)
+Draw a line between the two indicated positions. +
+
gui.drawbox(int x1, int y1, int x2, int y2, type colour)
+Draw a box going through the indicated opposite corners. +
+
gui.text(int x, int y, string message)
+Write text on the screen at the indicated position. +

+The coordinates determine the top-left corner of the box that the text fits in. +The font is the same one as the snes9x messages, and you can't control colours or anything. :( +

+The minimum y value is 9 for the font's height and each letter will take around 8 pixels of width. +Text that exceeds the viewing area will be cut short, so ensuring your text will fit would be wise. + +


+
string gui.gdscreenshot()
+0.04+ only
+Takes a screen shot of the image and returns it in the form of a string which can be imported by +the
gd library using the gd.createFromGdStr() function. +

+This function is provided so as to allow snes9x to not carry a copy of the gd library itself. If you +want raw RGB32 access, skip the first 11 bytes (header) and then read pixels as Alpha (always 0), Red, +Green, Blue, left to right then top to bottom, range is 0-255 for all colours. +

+Warning: Storing screen shots in memory is not recommended. Memory usage will blow up pretty quick. +One screen shot string eats around 230 KB of RAM. + +


+
gui.gdoverlay(int x=0, int y=0, string gdimage)
+0.04+ only
+Overlays the given image on top of the screen with the top-left corner in the given screen location. +Transparency is not fully supported -- a pixel must be 100% transparent to actually leave +a hole in the overlayed image or else it will be treated as opaque.

+Naturally, the format for input is the gd file format, version 1. The image MUST be truecolour. + +

+The image will be clipped to fit into the screen area. +


+
gui.transparency(int strength)
+0.04+ only
+Transparency mode. A value of 0 means opaque; a value of 4 means invisible (useful option that one). +As for 1 through 3, I'll let you figure those out.

+All image drawing (including gui.gdoverlay) will have the given transparency level applied from that point +on. Note that drawing on the same point over and over will NOT build up to a higher opacity level. +


+
function gui.register(function func)
+0.04+ only
+Register a function to be called between a frame being prepared for displaying on your screen and +it actually happening. Used when that 1 frame delay for rendering is a pain in the butt. +

This function is not necessarily complicated to use, but it's not recommended to users +new to the whole scripting thing. +

+You may pass nil as the parameter to kill off a registered function. The old function (if any) will be +returned. +


+
string function gui.popup(string message, [string type = "ok"])
+v0.05+ only
+Pops up a dialog to the user with a message, and returns after the user acknowledges the dialog. +type may be any of "ok", "yesno", "yesnocancel". The return value will be "yes", "no" or "cancel" +as the case may be. "ok" is a waste of effort. +

+Linux users might want to install xmessage to perform the work. Otherwise the dialog will +appear on the shell and that's less noticable. +

\ No newline at end of file diff --git a/branches/fceux-2.2.2/documentation/tech/cpu/4017.txt b/branches/fceux-2.2.2/documentation/tech/cpu/4017.txt new file mode 100644 index 00000000..25cb8393 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/cpu/4017.txt @@ -0,0 +1,97 @@ +This is an email posted to nesdev by Ki a while back. I have removed one +line at the end regarding the B flag of the cpu(the information was +incorrect, which Ki noted in a later email). + +-------------------------------------------------------------------------------- + + By reading Brad's NESSOUND document, we know that there is a +"frame counter" in the NES/FC APU. I would like to post +some more on this. + + The frame counter is reset upon any write to $4017. It is +reset at system power-on as well, but is NOT reset upon +system reset. + + Thanks to Samus Aran, we now know the exact period of the +PPU's single frame. In another words, we are now sure that +the NMI occurs on every 29780 2/3 CPU cycles. + + However, the APU's single frame is NOT 29780 2/3 CPU cycles. +What I mean by "APU's single frame" here is that it is the +number of CPU cycles taken between the frame IRQs. + + The APU's single frame seems to be: + + 1789772.727... / 60 = 29829 6/11 [CPU CYCLE] + + Below is a simple diagram which shows the difference +in periods of the PPU's single frame and the APU's. + + + RESET 29780 2/3 CPU CYCLES NMI +PPU |------------------------------------------| + | 29829 6/11 CPU CYCLES IRQ +APU |----------|----------|----------|----------| + + + Note that if you write $00 to $4017 on every NMI, the frame +IRQ would NEVER go off even if it is enabled. This is because +the the period of NMI is slightly shorter than the period of +the frame IRQ. This causes the frame counter to be reset +before the frame IRQ goes off. + +When you write zero to bit 7 of $4017, the frame counter will +be reset, and the first sound update will be done after 7457 CPU +cycles (i.e. 29829/4). 2nd update will be done 7457 after that, +same goes for 3rd update and 4th update, but the frame IRQ occurs +on 4th update, resetting the frame counter as well. + +When you write 1 to bit 7 of $4017, the frame counter will be +reset, but the first sound update will occur at the same time. +2nd, 3rd, and 4th update will be done after 7457, 14914, 22371 +CPU cycles after the first update respectively, but the 5th +update will be 14914 cycles after the 4th update. This causes +sound output to last 1.25 times longer than that of bit 7 = 0. + + +$4017W: + +o when the MSB of $4017 is 0: + +bit7=0 + |---------|---------|---------|---------|---------|---------|---- + 1st 2nd 3rd 4th 5th(1st) 6th(2nd) + + +o when the MSB of $4017 is 1: + +bit7=1 + |---------|---------|---------|-------------------|---------|---- + 1st 2nd 3rd 4th 5th(1st) 6th(2nd) + + +On 1st, 3rd, 5th, ... updates, the envelope decay and the +linear counter are updated. + +On 2nd, 4th, 6th, ... updates, the envelope decay, the +linear counter, the length counter, and the frequency sweep +are updated. +---- + + The original info was provided by goroh, and verified by me. +However, it could still be wrong. Please tell me if you +find anything wrong. +---- + +(Correction from my last posting) + + I have checked once again and it turned out that the frame IRQ +was NOT disabled upon system reset. What actually prevented the +frame IRQ to occur after system reset was, in fact, the I flag. +I checked this flag shortly after system reset (right after stack +pointer was initialized), and the flag was 1, although I never +executed "sei" after reset. Therefore the I flag of the PR2A03G +is 1 on system reset. + + Thanks Matthew Conte and Samus Aran for pointing out the +inaccuracy. diff --git a/branches/fceux-2.2.2/documentation/tech/cpu/dmc.txt b/branches/fceux-2.2.2/documentation/tech/cpu/dmc.txt new file mode 100644 index 00000000..c33f4de8 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/cpu/dmc.txt @@ -0,0 +1,235 @@ +Delta modulation channel tutorial 1.0 +Written by Brad Taylor + +Last updated: August 20th, 2000. + +All results were obtained by studying prior information available (from +nestech 1.00, and postings on NESDev from miscellanious people), and through +a series of experiments conducted by me. Results aquired by individuals +prior to my reverse-engineering have been double checked, and final results +have been confirmed. Credit is due to those individual(s) who contributed +any information in regards to the DMC. + +Description +----------- + +The delta modulation channel (DMC) is a complex digital network of counters +and registers used to produce analog sound. It's primary function is to play +"samples" from memory, and have an internal counter connected to a digital +to analog converter (DAC) updated accordingly. The channel is able to be +assigned a pointer to a chunk of memory to be played. At timed intervals, +the DMC will halt the 2A03 (NES's CPU) for 1 clock cycle to retrieve the +sample to pe played. This method of playback will be refered to here on as +direct memory access (DMA). Another method of playback known as pulse code +modulation (PCM) is available by the channel, which requires the constant +updating of one of the DMC's memory-mapped registers. + +Registers +--------- + +The DMC has 5 registers assigned to it. They are as follows: + +$4010: play mode and DMA frequency +$4011: delta counter +$4012: play code's starting address +$4013: length of play code +$4015: DMC/IRQ status + +Note that $4015 is the only R/W register. All others are write only (attempt +to read them will most likely result in a returned 040H, due to heavy +capacitance on the NES's data bus). + +$4010 - Play mode and DMA frequency +----------------------------------- +This register is used to control the frequency of the DMA fetches, and to +control the playback mode. + +Bits +---- +6-7 this is the playback mode. + + 00 - play DMC sample until length counter reaches 0 (see $4013) + x1 - loop the DMC sample (x = immaterial) + 10 - play DMC sample until length counter reaches 0, then generate a CPU +IRQ + +Looping (playback mode "x1") will have the chunk of memory played over and +over, until the channel is disabled (via $4015). In this case, after the +length counter reaches 0, it will be reloaded with the calculated length +value of $4013. + +If playback mode "10" is chosen, an interrupt will be dispached when the +length counter reaches 0 (after the sample is done playing). There are 2 +ways to acknowledge the DMC's interrupt request upon recieving it. The first +is a write to this register ($4010), with the MSB (bit 7) cleared (0). The +second is any write to $4015 (see the $4015 register description for more +details). + +If playback mode "00" is chosen, the sample plays until the length counter +reaches 0. No interrupt is generated. + +5-4 appear to be unused + +3-0 this is the DMC frequency control. Valid values are from 0 - F. The +value of this register determines how many CPU clocks to wait before the DMA +will fetch another byte from memory. The # of clocks to wait -1 is initially +loaded into an internal 12-bit down counter. The down counter is then +decremented at the frequency of the CPU (1.79MHz). The channel fetches the +next DMC sample byte when the count reaches 0, and then reloads the count. +This process repeats until the channel is disabled by $4015, or when the +length counter has reached 0 (if not in the looping playback mode). The +exact number of CPU clock cycles is as follows: + +value CPU +written clocks octave scale +------- ------ ------ ----- +F 1B0 8 C +E 240 7 G +D 2A0 7 E +C 350 7 C +B 400 6 A +A 470 6 G +9 500 6 F +8 5F0 6 D +7 6B0 6 C +6 710 5 B +5 7F0 5 A +4 8F0 5 G +3 A00 5 F +2 AA0 5 E +1 BE0 5 D +0 D60 5 C + +The octave and scale values shown represent the DMC DMA clock cycle rate +equivelant. These values are merely shown for the music enthusiast +programmer, who is more familiar with notes than clock cycles. + +Every fetched byte is loaded into a internal 8-bit shift register. The shift +register is then clocked at 8x the DMA frequency (which means that the CPU +clock count would be 1/8th that of the DMA clock count), or shifted at +3 +the octave of the DMA (same scale). The data shifted out of the register is +in serial form, and the least significant bit (LSB, or bit 0) of the fetched +byte is the first one to be shifted out (then bit 1, bit 2, etc.). + +The bits shifted out are then fed to the UP/DOWN control pin of the internal +delta counter, which will effectively have the counter increment it's +retained value by one on "1" bit samples, and decrement it's value by one on +"0" bit samples. This counter is clocked at the same frequency of the shift +register's. + +The counter is only 6 bits in size, and has it's 6 outputs tied to the 6 MSB +inputs of a 7 bit DAC. The analog output of the DAC is then what you hear +being played by the DMC. + +Wrap around counting is not allowed on this counter. Instead, a "clipping" +behaviour is exhibited. If the internal value of the counter has reached 0, +and the next bit sample is a 0 (instructing a decrement), the counter will +take no action. Likewise, if the counter's value is currently at -1 +(111111B, or 03FH), and the bit sample to be played is a 1, the counter will +not increment. + + +$4011 - Delta counter load register +----------------------------------- + +bits +---- +7 appears to be unused +1-6 the load inputs of the internal delta counter +0 LSB of the DAC + +A write to this register effectively loads the internal delta counter with a +6 bit value, but can be used for 7 bit PCM playback. Bit 0 is connected +directly to the LSB (bit 0) of the DAC, and has no effect on the internal +delta counter. Bit 7 appears to be unused. + +This register can be used to output direct 7-bit digital PCM data to the +DMC's audio output. To use this register for PCM playback, the programmer +would be responsible for making sure that this register is updated at a +constant rate. The rate is completely user-definable. For the regular CD +quality 44100 Hz playback sample rate, this register would have to be +written to approximately every 40 CPU cycles (assuming the 2A03 is running @ +1.79 MHz). + + +$4012 - DMA address load register +---------------------------- + +This register contains the initial address where the DMC is to fetch samples +from memory for playback. The effective address value is $4012 shl 6 or +0C000H. This register is connected to the load pins of the internal DMA +address pointer register (counter). The counter is incremented after every +DMA byte fetch. The counter is 15 bits in size, and has addresses wrap +around from $FFFF to $8000 (not $C000, as you might have guessed). The DMA +address pointer register is reloaded with the initial calculated address, +when the DMC is activated from an inactive state, or when the length counter +has arrived at terminal count (count=0), if in the looping playback mode. + + +$4013 - DMA length register +--------------------------- + +This register contains the length of the chunk of memory to be played by the +DMC, and it's size is measured in bytes. The value of $4013 shl 4 is loaded +into a 12 bit internal down counter, dubbed the length counter. The length +counter is decremented after every DMA fetch, and when it arrives at 0, the +DMC will take action(s) based on the 2 MSB of $4010. This counter will be +loaded with the current calculated address value of $4013 when the DMC is +activated from an inactive state. Because the value that is loaded by the +length counter is $4013 shl 4, this effectively produces a calculated byte +sample length of $4013 shl 4 + 1 (i.e. if $4013=0, sample length is 1 byte +long; if $4013=FF, sample length is $FF1 bytes long). + + +$4015 - DMC status +------------------ + +This contains the current status of the DMC channel. There are 2 read bits, +and 1 write bit. + +bits +---- +7(R) DMC's IRQ status (1=CPU IRQ being caused by DMC) +4(R) DMC is currently enabled (playing a stream of samples) +4(W) enable/disable DMC (1=start/continue playing a sample;0=stop playing) + +When an IRQ goes off inside the 2A03, Bit 7 of $4015 can tell the interrupt +handler if it was caused by the DMC hardware or not. This bit will be set +(1) if the DMC is responsible for the IRQ. Of course, if your program has no +other IRQ-generating hardware going while it's using the DMC, then reading +this register is not neccessary upon IRQ generation. Note that reading this +register will NOT clear bit 7 (meaning that the DMC's IRQ will still NOT be +acknowledged). Also note that if the 2 MSB of $4010 were set to 10, no IRQ +will be generated, and bit 7 will always be 0. + +Upon generation of a IRQ, to let the DMC know that the software has +acknowledged the /IRQ (and to reset the DMC's internal IRQ flag), any write +out to $4015 will reset the flag, or a write out to $4010 with the MSB set +to 0 will do. These practices should be performed inside the IRQ handler +routine. To replay the same sample that just finished, all you need to do is +just write a 1 out to bit 4 of $4015. + +Bit 4 of $4015 reports the real-time status of the DMC. A returned value of +1 denotes that the channel is currently playing a stream of samples. A +returned value of 0 indicates that the channel is inactive. If the +programmer needed to know when a stream of samples was finished playing, but +didn't want to use the IRQ generation feature of the DMC, then polling this +bit would be a valid option. + +Writing a value to $4015's 4th bit has the effect of enabling the channel +(start, or continue playing a stream of samples), or disabling the channel +(stop all DMC activity). Note that writing a 1 to this bit while the channel +is currently enabled, will have no effect on counters or registers internal +to the DMC. + +The conditions that control the time the DMC will stay enabled are +determined by the 2 MSB of $4010, and register $4013 (if applicable). + + +System Reset +------------ + +On system reset, all 7 used bits of $4011 are reset to 0, the IRQ flag is +cleared (disabled), and the channel is disabled. All other registers will +remain unmodified. + diff --git a/branches/fceux-2.2.2/documentation/tech/cpu/nessound-4th.txt b/branches/fceux-2.2.2/documentation/tech/cpu/nessound-4th.txt new file mode 100644 index 00000000..c592d2ed --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/cpu/nessound-4th.txt @@ -0,0 +1,551 @@ +******************************************* +*2A03 sound channel hardware documentation* +******************************************* +Brad Taylor (big_time_software@hotmail.com) + + 4th release: February 19th, 2K3 + + + All results were obtained by studying prior information available (from nestech 1.00, and postings on NESDev from miscellanious people), and through a series of experiments conducted by me. Results acquired by individuals prior to my reverse-engineering have been double checked, and final results have been confirmed. Credit is due to those individual(s) who contributed miscellanious information in regards to NES sound channel hardware. Such individuals are: + + Goroh + Memblers + FluBBa + Izumi + Chibi-Tech + Quietust + SnowBro + + Kentaro Ishihara (Ki) is responsible for posting (on the NESdev mailing list) differrences in the 2 square wave channels, including the operation of 2A03 hardware publically undocumented (until now) such as the frame IRQ counter, and it's ties with sound hardware. Goroh had originally discovered some of this information, and Ki confirmed it. + + A special thanks goes out to Matthew Conte, for his expertise on pseudo-random number generation (amoung other things), which allowed for the full reverse engineering of the NES's noise channel to take place. Without his help, I would still be trying to find a needle in a haystack, as far as the noise's method of pseudo-random number generation goes. Additionally, his previous findings / reverse engineering work on the NES's sound hardware really got the ball of NES sound emulation rolling. If it weren't for Matt's original work, this document wouldn't exist. + + +**************** +* Introduction * +**************** + The 2A03 (NES's integrated CPU) has 4 internal channels to it that have the ability to generate semi-analog sound, for musical playback purposes. These channels are 2 square wave channels, one triangle wave channel, and a noise generation channel. This document will go into full detail on every aspect of the operation and timing of the mentioned sound channels. + + +******************* +* Channel details * +******************* + Each channel has different characteristics to it that make up it's operation. + + The square channel(s) have the ability to generate a square wave frequency in the range of 54.6 Hz to 12.4 KHz. It's key features are frequency sweep abilities, and output duty cycle adjustment. + + The triangle wave channel has the ability to generate an output triangle wave with a resolution of 4-bits (16 steps), in the range of 27.3 Hz to 55.9 KHz. The key features this channel has is it's analog triangle wave output, and it's linear counter, which can be set to automatically disable the channel's sound after a certain period of time has gone by. + + The noise channel is used for producing random frequencys, which results in a "noisey" sounding output. Output frequencys can range anywhere from 29.3 Hz to 447 KHz. It's key feature is it's pseudo- random number generator, which generates the random output frequencys heard by the channel. + + +***************** +* Frame counter * +***************** + The 2A03 has an internal frame counter. The purpose of it is to generate the various low frequency signals (60, 120, 240 Hz, and 48, 96, 192 Hz) required to clock several of the sound hardware's counters. It also has the ability to generate IRQ's. + + The smallest unit of timing the frame counter operates around is 240Hz; all other frequencies are generated by multiples of this base frequency. A clock divider of 14915 (clocked at twice the CPU speed) is used to get 240Hz (this was the actual measured ratio). + + ++---------------+ +|$4017 operation| ++---------------+ + Writes to register $4017 control operation of both the clock divider, and the frame counter. + + - Any write to $4017 resets both the frame counter, and the clock divider. Sometimes, games will write to this register in order to synchronize the sound hardware's internal timing, to the sound routine's timing (usually tied into the NMI code). The frame IRQ is slightly longer than the PPU's, so you can see why games would desire this syncronization. + + - bit 7 of $4017 controls the frame counter's divide rate. Every time the counter cycles (reaches terminal count (0)), a frame IRQ will be generated, if enabled by clearing bit 6 of $4017. $4015.6 holds the status of the frame counter IRQ; it will be set if the frame counter is responsible for the interrupt. + +$4017.7 divider frame IRQ freq. +------- ------- --------------- +0 4 60 +1 5 48 + + On 2A03 reset, both bits of $4017 (6 & 7) will be cleared, enabling frame IRQ's off the hop. The reason why the existence of frame IRQ's are generally unknown is because the 6502's maskable interrupt is disabled on reset, and this blocks out the frame IRQ's. Most games don't use any IRQ-generating hardware in general, therefore they don't bother enabling maskable interrupts. + + Note that the IRQ line will be held down by the frame counter until it is acknowledged (by reading $4015). Before this, the 6502 will generate an IRQ *every* time interrupts are enabled (either by CLI or RTI), since the IRQ design on the 6502 is level-triggered, and not edge. If you've written a program that does not read $4015 in the IRQ handler, and you execute CLI, the processor will immediately go into a infinite IRQ call-return loop. + + ++-----------------------+ +|Frame counter operation| ++-----------------------+ + Depending on the status of $4017.7, the frame counter will follow 2 different count sequences. These sequences determine when sound hardware counters will be clocked. The sequences are initialized immediately following any write to $4017. + +$4017.7 sequence +------- -------- +0 4, 0,1,2,3, 0,1,2,3,..., etc. +1 0,1,2,3,4, 0,1,2,3,4,..., etc. + + During count sequences 0..3, the linear (triangle) and envelope decay (square & noise) counters recieve a clock for each count. This means that both these counters are clocked once immediately after $4017.7 is written with a value of 1. + + Count sequences 1 & 3 clock (update) the frequency sweep (square), and length (all channels) counters. Even though the length counter's smallest unit of time counting is a frame, it seems that it is actually being clocked twice per frame. That said, you can consider the length counters to contain an extra stage to divide this clock signal by 2. + + No aforementioned sound hardware counters are clocked on count sequence #4. You should now see how this causes the 96, and 192 Hz signals to be generated when $4017.7=1. + + The rest of the document will describe the operation of the sound channels using the $4017.7=0 frequencies (60, 120, and 240 Hz). For $4017.7=1 operation, replace those frequencies with 48, 96, and 192 Hz (respectively). + + +************************ +* Sound hardware delay * +************************ + After resetting the 2A03, the first time any sound channel(s) length counter contains a non-zero value (channel is enabled), there will be a 2048 CPU clock cycle delay before any of the sound hardware is clocked. After the 2K clock cycles go by, the NES sound hardware will be clocked normally. This phenomenon only occurs prior to a system reset, and only occurs during the first 2048 CPU clocks after the activation of any of the 4 basic sound channels. + + The information in regards to this delay is only provided to keep this document accurate with all information that is currently known about the 2A03's sound hardware. I haven't done much tests on the behaviour of this delay (mainly because I don't care, as I view it as a inconvenience anyway), so this information should be taken with a grain of salt. + + +************************ +* Register Assignments * +************************ + The sound hardware internal to the 2A03 has been designated these special memory addresses in the CPU's memory map. + +$4000-$4003 Square wave 1 +$4004-$4007 Square wave 2 (identical to the first, except for upward frequency sweeps (see "sweep unit" section)) +$4008-$400B Triangle +$400C-$400F Noise +$4015 Channel enable / length/frame counter status +$4017 frame counter control + + Note that $4015 (and $4017, but is unrelated to sound hardware) are the only R/W registers. All others are write only (attempt to read them will most likely return the last byte on the bus (usually 040H), due to heavy capacitance on the NES's data bus). Reading a "write only" register, will have no effect on the specific register, or channel. + + Every sound channel has 4 registers affiliated with it. The description of the register sets are as follows: + ++----------------+ +| Register set 1 | ++----------------+ + +$4000(sq1)/$4004(sq2)/$400C(noise) bits +--------------------------------------- +0-3 volume / envelope decay rate +4 envelope decay disable +5 length counter clock disable / envelope decay looping enable +6-7 duty cycle type (unused on noise channel) + +$4008(tri) bits +--------------- +0-6 linear counter load register +7 length counter clock disable / linear counter start + + ++----------------+ +| Register set 2 | ++----------------+ + +$4001(sq1)/$4005(sq2) bits +-------------------------- +0-2 right shift amount +3 decrease / increase (1/0) wavelength +4-6 sweep update rate +7 sweep enable + +$4009(tri)/$400D(noise) bits +---------------------------- +0-7 unused + + ++----------------+ +| Register set 3 | ++----------------+ + +$4002(sq1)/$4006(sq2)/$400A(Tri) bits +------------------------------------- +0-7 8 LSB of wavelength + +$400E(noise) bits +----------------- +0-3 playback sample rate +4-6 unused +7 random number type generation + + ++----------------+ +| Register set 4 | ++----------------+ + +$4003(sq1)/$4007(sq2)/$400B(tri)/$400F(noise) bits +-------------------------------------------------- +0-2 3 MS bits of wavelength (unused on noise channel) +3-7 length counter load register + + ++--------------------------------+ +| length counter status register | ++--------------------------------+ + +$4015(read) +----------- +0 square wave channel 1 +1 square wave channel 2 +2 triangle wave channel +3 noise channel +4 DMC (see "DMC.TXT" for details) +5-6 unused +7 IRQ status of DMC (see "DMC.TXT" for details) + + ++-------------------------+ +| channel enable register | ++-------------------------+ + +$4015(write) +------------ +0 square wave channel 1 +1 square wave channel 2 +2 triangle wave channel +3 noise channel +4 DMC channel (see "DMC.TXT" for details) +5-7 unused + + +************************ +* Channel architecture * +************************ + This section will describe the internal components making up each individual channel. Each component will then be described in full detail. + +Device Triangle Noise Square +------ -------- ------ ------ +triangle step generator X +linear counter X +programmable timer X X X +length counter X X X +4-bit DAC X X X +volume/envelope decay unit X X +sweep unit X +duty cycle generator X +wavelength converter X +random number generator X + + ++-------------------------+ +| Triangle step generator | ++-------------------------+ + This is a 5-bit, single direction counter, and it is only used in the triangle channel. Each of the 4 LSB outputs of the counter lead to one input on a corresponding mutually exclusive XNOR gate. The 4 XNOR gates have been strobed together, which results in the inverted representation of the 4 LSB of the counter appearing on the outputs of the gates when the strobe is 0, and a non-inverting action taking place when the strobe is 1. The strobe is naturally connected to the MSB of the counter, which effectively produces on the output of the XNOR gates a count sequence which reflects the scenario of a near- ideal triangle step generator (D,E,F,F,E,D,...,2,1,0,0,1,2,...). At this point, the outputs of the XNOR gates will be fed into the input of a 4-bit DAC. + + This 5-bit counter will be halted whenever the Triangle channel's length or linear counter contains a count of 0. This results in a "latching" behaviour; the counter will NOT be reset to any definite state. + + On system reset, this counter is loaded with 0. + + The counter's clock input is connected directly to the terminal count output pin of the 11-bit programmable timer in the triangle channel. As a result of the 5-bit triangle step generator, the output triangle wave frequency will be 32 times less than the frequency of the triangle channel's programmable timer is set to generate. + + ++----------------+ +| Linear counter | ++----------------+ + The linear counter is only found in the triangle channel. It is a 7-bit presettable down counter, with a decoded output condition of 0 available (not exactly the same as terminal count). Here's the bit assignments: + +$4008 bits +---------- +0-6 bits 0-6 of the linear counter load register (NOT the linear counter itself) +7 linear counter start + + The counter is clocked at 240 Hz (1/4 framerate), and the calculated length in frames is 0.25*N, where N is the 7-bit loaded value. The counter is always being clocked, except when 0 appears on the output of the counter. At this point, the linear counter & triangle step counter clocks signals are disabled, which results in both counters latching their current state (the linear counter will stay at 0, and the triangle step counter will stop, and the channel will be silenced due to this). + + The linear counter has 2 modes: load, and count. When the linear counter is in load mode, it essentially becomes transparent (i.e. whatever value is currently in, or being written to $4008, will appear on the output of the counter). Because of this, no count action can occur in load mode. When the mode changes from load to count, the counter will now latch the value currently in it, and start counting down from there. In the count mode, the current value of $4008 is ignored by the counter (but still retained in $4008). Described below is how the mode of the linear counter is set: + + +Writes to $400B +--------------- +cur mode +--- ---- +1 load +0 load (on next linear counter clock), count + + Cur is the current state of the MSB of $4008. + + +Writes to $4008 +--------------- +old new mode +--- --- ---- +0 X count +1 0 no change (during the CPU write cycle), count +1 1 no change + + Old and new represent the state(s) of the MSB of $4008. Old is the value being replaced in the MSB of $4008 on the write, and new is the value replacing the old one. + + "no change" indicates that the mode of the linear counter will not change from the last. + + Note that writes to $400B when $4008.7=0 only loads the linear counter with the value in $4008 on the next *linear* counter clock (and NOT at the end of the CPU write cycle). This is a correction from older versions of this doc. + + ++--------------------+ +| Programmable timer | ++--------------------+ + The programmable timer is a 11-bit presettable down counter, and is found in the square, triangle, and noise channel(s). The bit assignments are as follows: + +$4002(sq1)/$4006(sq2)/$400A(Tri) bits +------------------------------------- +0-7 represent bits 0-7 of the 11-bit wavelength + +$4003(sq1)/$4007(sq2)/$400B(Tri) bits +------------------------------------- +0-2 represent bits 8-A of the 11-bit wavelength + + Note that on the noise channel, the 11 bits are not available directly. See the wavelength converter section, for more details. + + The counter has automatic syncronous reloading upon terminal count (count=0), therefore the counter will count for N+1 (N is the 11-bit loaded value) clock cycles before arriving at terminal count, and reloading. This counter will typically be clocked at the 2A03's internal 6502 speed (1.79 MHz), and produces an output frequency of 1.79 MHz/(N+1). The terminal count's output spike length is typically no longer than half a CPU clock. The TC signal will then be fed to the appropriate device for the particular sound channel (for square, this terminal count spike will lead to the duty cycle generator. For the triangle, the spike will be fed to the triangle step generator. For noise, this signal will go to the random number generator unit). + + ++----------------+ +| Length counter | ++----------------+ + The length counter is found in all sound channels. It is essentially a 7-bit down counter, and is conditionally clocked at a frequency of 60 Hz. + + When the length counter arrives at a count of 0, the counter will be stopped (stay on 0), and the appropriate channel will be silenced. + + The length counter clock disable bit, found in all the channels, can also be used to halt the count sequence of the length counter for the appropriate channel, by writing a 1 out to it. A 0 condition will permit counting (unless of course, the counter's current count = 0). Location(s) of the length counter clock disable bit: + +$4000(sq1)/$4004(sq2)/$400C(noise) bits +--------------------------------------- +5 length counter clock disable + +$4008(tri) bits +--------------- +7 length counter clock disable + + To load the length counter with a specified count, a write must be made out to the length register. Location(s) of the length register: + +$4003(sq1)/$4007(sq2)/$400B(tri)/$400F(noise) bits +-------------------------------------------------- +3-7 length + + The 5-bit length value written, determines what 7-bit value the length counter will start counting from. A conversion table here will show how the values are translated. + + +-----------------------+ + | bit3=0 | + +-------+---------------+ + | |frames | + |bits +-------+-------+ + |4-6 |bit7=0 |bit7=1 | + +-------+-------+-------+ + |0 |05 |06 | + |1 |0A |0C | + |2 |14 |18 | + |3 |28 |30 | + |4 |50 |60 | + |5 |1E |24 | + |6 |07 |08 | + |7 |0D |10 | + +-------+-------+-------+ + + +---------------+ + | bit3=1 | + +-------+-------+ + |bits | | + |4-7 |frames | + +-------+-------+ + |0 |7F | + |1 |01 | + |2 |02 | + |3 |03 | + |4 |04 | + |5 |05 | + |6 |06 | + |7 |07 | + |8 |08 | + |9 |09 | + |A |0A | + |B |0B | + |C |0C | + |D |0D | + |E |0E | + |F |0F | + +-------+-------+ + + The length counter's real-time status for each channel can be attained. A 0 is returned for a zero count status in the length counter (channel's sound is disabled), and 1 for a non-zero status. Here's the bit description of the length counter status register: + +$4015(read) +----------- +0 length counter status of square wave channel 1 +1 length counter status of square wave channel 2 +2 length counter status of triangle wave channel +3 length counter status of noise channel +4 length counter status of DMC (see "DMC.TXT" for details) +5 unknown +6 frame IRQ status +7 IRQ status of DMC (see "DMC.TXT" for details) + + Writing a 0 to the channel enable register will force the length counters to always contain a count equal to 0, which renders that specific channel disabled (as if it doesn't exist). Writing a 1 to the channel enable register disables the forced length counter value of 0, but will not change the count itself (it will still be whatever it was prior to the writing of 1). + + Bit description of the channel enable register: + +$4015(write) +------------ +0 enable square wave channel 1 +1 enable square wave channel 2 +2 enable triangle wave channel +3 enable noise channel +4 enable DMC channel (see "DMC.TXT" for details) +5-7 unknown + + Note that all 5 used bits in this register will be set to 0 upon system reset. + + ++-----------+ +| 4-bit DAC | ++-----------+ + This is just a standard 4-bit DAC with 16 steps of output voltage resolution, and is used by all 4 sound channels. On the 2A03, square wave 1 & 2 are mixed together, and are available via pin 1. Triangle & noise are available on pin 2. + + These analog outputs require a negative current source, to attain linear symmetry on the various output voltage levels generated by the channel(s) (moreover, to get the sound to be audible). Instead of current sources, the NES uses external 100 ohm pull-down resistors. This results in the output waveforms having some linear asymmetry (i.e., as the desired output voltage increases on a linear scale, the actual outputted voltage increases less and less each step). + + The side effect of this is that the DMC's 7-bit DAC port ($4011) is able to indirectly control the volume (somewhat) of both triangle & noise channels. While I have not measured the voltage asymmetery, others on the NESdev messageboards have posted their findings. The conclusion is that when $4011 is 0, triangle & noise volume outputs are at maximum. When $4011 = 7F, the triangle & noise channel outputs operate at only 57% total volume. + + The odd thing is that a few games actually take advantage of this "volume" feature, and write values to $4011 in order to regulate the amplitude of the triangle wave channel's output. + + ++------------------------------+ +| Volume / envelope decay unit | ++------------------------------+ + The volume / envelope decay hardware is found only in the square wave and noise channels. + +$4000(sq1)/$4004(sq2)/$400C(noise) +---------------------------------- +0-3 volume / envelope decay rate +4 envelope decay disable +5 envelope decay looping enable + + When the envelope decay disable bit (bit 4) is set (1), the current volume value (bits 0-3) is sent directly to the channel's DAC. However, depending on certain conditions, this 4-bit volume value will be ignored, and a value of 0 will be sent to the DAC instead. This means that while the channel is enabled (producing sound), the output of the channel (what you'll hear from the DAC) will either be the 4-bit volume value, or 0. This also means that a 4-bit volume value of 0 will result in no audible sound. These conditions are as follows: + + - When hardware in the channel wants to disable it's sound output (like the length counter, or sweep unit (square channels only)). + + - On the negative portion of the output frequency signal coming from the duty cycle / random number generator hardware (square wave channel / noise channel). + + When the envelope decay disable bit is cleared, bits 0-3 now control the envelope decay rate, and an internal 4-bit down counter (hereon the envelope decay counter) now controls the channel's volume level. "Envelope decay" is used to describe the action of the channel's audio output volume starting from a certain value, and decreasing by 1 at a fixed (linear) rate (which produces a "fade-out" sounding effect). This fixed decrement rate is controlled by the envelope decay rate (bits 0-3). The calculated decrement rate is 240Hz/(N+1), where N is any value between $0-$F. + + When the channel's envelope decay counter reaches a value of 0, depending on the status of the envelope decay looping enable bit (bit 5, which is shared with the length counter's clock disable bit), 2 different things will happen: + +bit 5 action +----- ------ +0 The envelope decay count will stay at 0 (channel silenced). +1 The envelope decay count will wrap-around to $F (upon the next clock cycle). The envelope decay counter will then continue to count down normally. + + Only a write out to $4003/$4007/$400F will reset the current envelope decay counter to a known state (to $F, the maximum volume level) for the appropriate channel's envelope decay hardware. Otherwise, the envelope decay counter is always counting down (by 1) at the frequency currently contained in the volume / envelope decay rate bits (even when envelope decays are disabled (setting bit 4)), except when the envelope decay counter contains a value of 0, and envelope decay looping (bit 5) is disabled (0). + + ++------------+ +| Sweep unit | ++------------+ + The sweep unit is only found in the square wave channels. The controls for the sweep unit have been mapped in at $4001 for square 1, and $4005 for square 2. + + The controls + ------------ + Bit 7 when this bit is set (1), sweeping is active. This results in real-time increasing or decreasing of the the current wavelength value (the audible frequency will decrease or increase, respectively). The wavelength value in $4002/3 ($4006/7) is constantly read & updated by the sweep. Modifying the contents of $4002/3 will be immediately audible, and will result in the sweep now starting from this new wavelength value. + + Bits 6-4 These 3 bits represent the sweep refresh rate, or the frequency at which $4002/3 is updated with the new calculated wavelength. The refresh rate frequency is 120Hz/(N+1), where N is the value written, between 0 and 7. + + Bit 3 This bit controls the sweep mode. When this bit is set (1), sweeps will decrease the current wavelength value, as a 0 will increase the current wavelength. + + Bits 2-0 These bits control the right shift amount of the new calculated sweep update wavelength. Code that shows how the sweep unit calculates a new sweep wavelength is as follows: + +bit 3 +----- +0 New = Wavelength + (Wavelength >> N) +1 New = Wavelength - (Wavelength >> N) (minus an additional 1, if using square wave channel 1) + + where N is the the shift right value, between 0-7. + + Note that in decrease mode, for subtracting the 2 values: + 1's compliment (NOT) is being used for square wave channel 1 + 2's compliment (NEG) is being used for square wave channel 2 + + This information is currently the only known difference between the 2 square wave channels. + + On each sweep refresh clock, the Wavelength register will be updated with the New value, but only if all 3 of these conditions are met: + + - bit 7 is set (sweeping enabled) + - the shift value (which is N in the formula) does not equal to 0 + - the channel's length counter contains a non-zero value + + Notes + ----- + There are certain conditions that will cause the sweep unit to silence the channel, and halt the sweep refresh clock (which effectively stops sweep action, if any). Note that these conditions pertain regardless of any sweep refresh rate values, or if sweeping is enabled/disabled (via bit 7). + + - an 11-bit wavelength value less than $008 will cause this condition + - if the sweep unit is currently set to increase mode, the New calculated wavelength value will always be tested to see if a carry (bit $B) was generated or not (if sweeping is enabled, this carry will be examined before the Wavelength register is updated) from the shift addition calculation. If carry equals 1, the channel is silenced, and sweep action is halted. + + ++----------------------+ +| Duty cycle generator | ++----------------------+ + The duty cycle generator takes the fequency produced from the 11-bit programmable timer, and uses a 4 bit counter to produce 4 types of duty cycles. The output frequency is then 1/16 that of the programmable timer. The duty cycle hardware is only found in the square wave channels. The bit assignments are as follows: + +$4000(sq1)/$4004(sq2) +--------------------- +6-7 Duty cycle type + + duty (positive/negative) +val in clock cycles +--- --------------- +00 2/14 +01 4/12 +10 8/ 8 +11 12/ 4 + + Where val represents bits 6-7 of $4000/$4004. + + This counter is reset when the length counter of the same channel is written to (via $4003/$4007). + + The output frequency at this point will now be fed to the volume/envelope decay hardware. + + ++----------------------+ +| Wavelength converter | ++----------------------+ + The wavelength converter is only used in the noise channel. It is used to convert a given 4-bit value to an 11-bit wavelength, which then is sent to the noise's own programmable timer. Here is the bit descriptions: + +$400E bits +---------- +0-3 The 4-bit value to be converted + + Below is a conversion chart that shows what 4-bit value will represent the 11-bit wavelength to be fed to the channel's programmable timer: + +value octave scale CPU clock cycles (11-bit wavelength+1) +----- ------ ----- -------------------------------------- +0 15 A 002 +1 14 A 004 +2 13 A 008 +3 12 A 010 +4 11 A 020 +5 11 D 030 +6 10 A 040 +7 10 F 050 +8 10 C 065 +9 9 A 07F +A 9 D 0BE +B 8 A 0FE +C 8 D 17D +D 7 A 1FC +E 6 A 3F9 +F 5 A 7F2 + + Octave and scale information is provided for the music enthusiast programmer who is more familiar with notes than clock cycles. + + ++-------------------------+ +| Random number generator | ++-------------------------+ + The noise channel has a 1-bit pseudo-random number generator. It's based on a 15-bit shift register, and an exclusive or gate. The generator can produce two types of random number sequences: long, and short. The long sequence generates 32,767-bit long number patterns. The short sequence generates 93-bit long number patterns. The 93-bit mode will generally produce higher sounding playback frequencys on the channel. Here is the bit that controls the mode: + +$400E bits +---------- +7 mode + + If mode=0, then 32,767-bit long number sequences will be produced (32K mode), otherwise 93-bit long number sequences will be produced (93-bit mode). + + The following diagram shows where the XOR taps are taken off the shift register to produce the 1-bit pseudo-random number sequences for each mode. + +mode <----- +---- EDCBA9876543210 +32K ** +93-bit * * + + The current result of the XOR will be transferred into bit position 0 of the SR, upon the next shift cycle. The 1-bit random number output is taken from pin E, is inverted, then is sent to the volume/envelope decay hardware for the noise channel. The shift register is shifted upon recieving 2 clock pulses from the programmable timer (the shift frequency will be half that of the frequency from the programmable timer (one octave lower)). + + On system reset, this shift register is loaded with a value of 1. + + +RP2A03E quirk +------------- + I have been informed that revisions of the 2A03 before "F" actually lacked support for the 93-bit looped noise playback mode. While the Famicom's 2A03 went through 4 revisions (E..H), I think that only one was ever used for the front loading NES: "G". Other differences between 2A03 revisions are unknown. + + +EOF \ No newline at end of file diff --git a/branches/fceux-2.2.2/documentation/tech/cpu/nessound.txt b/branches/fceux-2.2.2/documentation/tech/cpu/nessound.txt new file mode 100644 index 00000000..bb6d0598 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/cpu/nessound.txt @@ -0,0 +1,697 @@ +The NES sound channel guide 1.8 +Written by Brad Taylor. +btmine@hotmail.com + +Last updated: July 27th, 2000. + +All results were obtained by studying prior information available (from +nestech 1.00, and postings on NESDev from miscellanious people), and through +a series of experiments conducted by me. Results acquired by individuals +prior to my reverse-engineering have been double checked, and final results +have been confirmed. Credit is due to those individual(s) who contributed +any information in regards to the the miscellanious sound channels wihtin +the NES. + +A special thanks goes out to Matthew Conte, for his expertise on +pseudo-random number generation (amoung other things), which allowed for the +full reverse engineering of the NES's noise channel to take place. Without +his help, I would still be trying to find a needle in a haystack, as far as +the noise's method of pseudo-random number generation goes. Additionally, +his previous findings / reverse engineering work on the NES's sound hardware +really got the ball of NES sound emulation rolling. If it weren't for Matt's +original work, this document wouldn't exist. + +Thanks to Kentaro Ishihara, for his excellent work on finding the difference +in upward frequency sweep between the 2 square wave channels. + +**************** +* Introduction * +**************** + +The 2A03 (NES's integrated CPU) has 4 internal channels to it that have the +ability to generate semi-analog sound, for musical playback purposes. These +channels are 2 square wave channels, one triangle wave channel, and a noise +generation channel. This document will go into full detail on every aspect +of the operation and timing of the mentioned sound channels. + + +******************* +* Channel details * +******************* + +Each channel has different characteristics to it that make up it's +operation. + +The square channel(s) have the ability to generate a square wave frequency +in the range of 54.6 Hz to 12.4 KHz. It's key features are frequency sweep +abilities, and output duty cycle adjustment. + +The triangle wave channel has the ability to generate an output triangle +wave with a resolution of 4-bits (16 steps), in the range of 27.3 Hz to 55.9 +KHz. The key features this channel has is it's analog triangle wave output, +and it's linear counter, which can be set to automatically disable the +channel's sound after a certain period of time has gone by. + +The noise channel is used for producing random frequencys, which results in +a "noisey" sounding output. Output frequencys can range anywhere from 29.3 +Hz to 447 KHz. It's key feature is it's pseudo- random number generator, +which generates the random output frequencys heard by the channel. + + +***************** +* Frame counter * +***************** + +The 2A03 has an internal frame counter. It has the ability to generate 60 Hz +(1/1 framerate), 120 Hz (1/2 framerate), and 240 Hz (1/4 framerate) signals, +used by some of the sound hardware. The 1/4 framerate is calculated by +taking twice the CPU clock speed (3579545.454545 Hz), and dividing it by +14915 (i.e., the divide-by-14915 counter is decremented on the rising AND +falling edge of the CPU's clock signal). + + +************************ +* Sound hardware delay * +************************ + +After resetting the 2A03, the first time any sound channel(s) length counter +contains a non-zero value (channel is enabled), there will be a 2048 CPU +clock cycle delay before any of the sound hardware is clocked. After the 2K +clock cycles go by, the NES sound hardware will be clocked normally. This +phenomenon only occurs prior to a system reset, and only occurs during the +first 2048 CPU clocks for any sound channel prior to a sound channel being +enabled. + +The information in regards to this delay is only provided to keep this +entire document persistently accurate on the 2A03's sound hardware, but may +not be 100% accurate in itself. I haven't done much tests on the behaviour +of this delay (mainly because I don't care, as I view it as a inconvenience +anyway), so that's why I believe there could be some inaccuracies. + + +************************ +* Register Assignments * +************************ + +The sound hardware internal to the 2A03 has been designated these special +memory addresses in the CPU's memory map. + +$4000-$4003 Square wave 1 +$4004-$4007 Square wave 2 (identical to the first, except for upward +frequency sweeps (see "sweep unit" section)) +$4008-$400B Triangle +$400C-$400F Noise +$4015 Channel enable / length counter status + +Note that $4015 is the only R/W register. All others are write only (attempt +to read them will most likely result in a returned 040H, due to heavy +capacitance on the NES's data bus). Reading a "write only" register, will +have no effect on the specific register, or channel. + +Every sound channel has 4 registers affiliated with it. The description of +the register sets are as follows: + ++----------------+ +| Register set 1 | ++----------------+ + +$4000(sq1)/$4004(sq2)/$400C(noise) bits +--------------------------------------- +0-3 volume / envelope decay rate +4 envelope decay disable +5 length counter clock disable / envelope decay looping enable +6-7 duty cycle type (unused on noise channel) + +$4008(tri) bits +--------------- +0-6 linear counter load register +7 length counter clock disable / linear counter start + + ++----------------+ +| Register set 2 | ++----------------+ + +$4001(sq1)/$4005(sq2) bits +-------------------------- +0-2 right shift amount +3 decrease / increase (1/0) wavelength +4-6 sweep update rate +7 sweep enable + +$4009(tri)/$400D(noise) bits +---------------------------- +0-7 unused + + ++----------------+ +| Register set 3 | ++----------------+ + +$4002(sq1)/$4006(sq2)/$400A(Tri) bits +------------------------------------- +0-7 8 LSB of wavelength + +$400E(noise) bits +----------------- +0-3 playback sample rate +4-6 unused +7 random number type generation + + ++----------------+ +| Register set 4 | ++----------------+ + +$4003(sq1)/$4007(sq2)/$400B(tri)/$400F(noise) bits +-------------------------------------------------- +0-2 3 MS bits of wavelength (unused on noise channel) +3-7 length counter load register + + ++--------------------------------+ +| length counter status register | ++--------------------------------+ + +$4015(read) +----------- +0 square wave channel 1 +1 square wave channel 2 +2 triangle wave channel +3 noise channel +4 DMC (see "DMC.TXT" for details) +5-6 unused +7 IRQ status of DMC (see "DMC.TXT" for details) + + ++-------------------------+ +| channel enable register | ++-------------------------+ + +$4015(write) +------------ +0 square wave channel 1 +1 square wave channel 2 +2 triangle wave channel +3 noise channel +4 DMC channel (see "DMC.TXT" for details) +5-7 unused + + +************************ +* Channel architecture * +************************ + +This section will describe the internal components making up each individual +channel. Each component will then be described in full detail. + +Device Triangle Noise Square +------ -------- ------ ------ +triangle step generator X +linear counter X +programmable timer X X X +length counter X X X +4-bit DAC X X X +volume/envelope decay unit X X +sweep unit X +duty cycle generator X +wavelength converter X +random number generator X + + ++-------------------------+ +| Triangle step generator | ++-------------------------+ + +This is a 5-bit, single direction counter, and it is only used in the +triangle channel. Each of the 4 LSB outputs of the counter lead to one input +on a corresponding mutually exclusive XNOR gate. The 4 XNOR gates have been +strobed together, which results in the inverted representation of the 4 LSB +of the counter appearing on the outputs of the gates when the strobe is 0, +and a non-inverting action taking place when the strobe is 1. The strobe is +naturally connected to the MSB of the counter, which effectively produces on +the output of the XNOR gates a count sequence which reflects the scenario of +a near- ideal triangle step generator (D,E,F,F,E,D,...,2,1,0,0,1,2,...). At +this point, the outputs of the XNOR gates will be fed into the input of a +4-bit DAC. + +This 5-bit counter will be halted whenever the Triangle channel's length or +linear counter contains a count of 0. This results in a "latching" +behaviour; the counter will NOT be reset to any definite state. + +On system reset, this counter is loaded with 0. + +The counter's clock input is connected directly to the terminal count output +pin of the 11-bit programmable timer in the triangle channel. As a result of +the 5-bit triangle step generator, the output triangle wave frequency will +be 32 times less than the frequency of the triangle channel's programmable +timer is set to generate. + + ++----------------+ +| Linear counter | ++----------------+ + +The linear counter is only found in the triangle channel. It is a 7-bit +presettable down counter, with a decoded output condition of 0 available +(not exactly the same as terminal count). Here's the bit assignments: + +$4008 bits +---------- +0-6 bits 0-6 of the linear counter load register (NOT the linear counter +itself) +7 linear counter start + +The counter is clocked at 240 Hz (1/4 framerate), and the calculated length +in frames is 0.25*N, where N is the 7-bit loaded value. The counter is +always being clocked, except when 0 appears on the output of the counter. At +this point, the linear counter & triangle step counter clocks signals are +disabled, which results in both counters latching their current state (the +linear counter will stay at 0, and the triangle step counter will stop, and +the channel will be silenced due to this). + +The linear counter has 2 modes: load, and count. When the linear counter is +in load mode, it essentially becomes transparent (i.e. whatever value is +currently in, or being written to $4008, will appear on the output of the +counter). Because of this, no count action can occur in load mode. When the +mode changes from load to count, the counter will now latch the value +currently in it, and start counting down from there. In the count mode, the +current value of $4008 is ignored by the counter (but still retained in +$4008). Described below is how the mode of the linear counter is set: + +Writes to $400B +--------------- +cur mode +--- ---- +1 load +0 load (during the write cycle), count + +Cur is the current state of the MSB of $4008. + +Writes to $4008 +--------------- +old new mode +--- --- ---- +0 X count +1 0 no change (during the write cycle), count +1 1 no change + +Old and new represent the state(s) of the MSB of $4008. Old is the value +being replaced in the MSB of $4008 on the write, and new is the value +replacing the old one. + +"no change" indicates that the mode of the linear counter will not change +from the last. + + ++--------------------+ +| Programmable timer | ++--------------------+ + +The programmable timer is a 11-bit presettable down counter, and is found in +the square, triangle, and noise channel(s). The bit assignments are as +follows: + +$4002(sq1)/$4006(sq2)/$400A(Tri) bits +------------------------------------- +0-7 represent bits 0-7 of the 11-bit wavelength + +$4003(sq1)/$4007(sq2)/$400B(Tri) bits +------------------------------------- +0-2 represent bits 8-A of the 11-bit wavelength + +Note that on the noise channel, the 11 bits are not available directly. See +the wavelength converter section, for more details. + +The counter has automatic syncronous reloading upon terminal count +(count=0), therefore the counter will count for N+1 (N is the 11-bit loaded +value) clock cycles before arriving at terminal count, and reloading. This +counter will typically be clocked at the 2A03's internal 6502 speed (1.79 +MHz), and produces an output frequency of 1.79 MHz/(N+1). The terminal +count's output spike length is typically no longer than half a CPU clock. +The TC signal will then be fed to the appropriate device for the particular +sound channel (for square, this terminal count spike will lead to the duty +cycle generator. For the triangle, the spike will be fed to the triangle +step generator. For noise, this signal will go to the random number +generator unit). + + ++----------------+ +| Length counter | ++----------------+ + +The length counter is found in all sound channels. It is essentially a 7-bit +down counter, and is conditionally clocked at a frequency of 60 Hz. + +When the length counter arrives at a count of 0, the counter will be stopped +(stay on 0), and the appropriate channel will be silenced. + +The length counter clock disable bit, found in all the channels, can also be +used to halt the count sequence of the length counter for the appropriate +channel, by writing a 1 out to it. A 0 condition will permit counting +(unless of course, the counter's current count = 0). Location(s) of the +length counter clock disable bit: + +$4000(sq1)/$4004(sq2)/$400C(noise) bits +--------------------------------------- +5 length counter clock disable + +$4008(tri) bits +--------------- +7 length counter clock disable + +To load the length counter with a specified count, a write must be made out +to the length register. Location(s) of the length register: + +$4003(sq1)/$4007(sq2)/$400B(tri)/$400F(noise) bits +-------------------------------------------------- +3-7 length + +The 5-bit length value written, determines what 7-bit value the length +counter will start counting from. A conversion table here will show how the +values are translated. + + +-----------------------+ + | bit3=0 | + +-------+---------------+ + | |frames | + |bits +-------+-------+ + |4-6 |bit7=0 |bit7=1 | + +-------+-------+-------+ + |0 |05 |06 | + |1 |0A |0C | + |2 |14 |18 | + |3 |28 |30 | + |4 |50 |60 | + |5 |1E |24 | + |6 |07 |08 | + |7 |0E |10 | + +-------+-------+-------+ + + +---------------+ + | bit3=1 | + +-------+-------+ + |bits | | + |4-7 |frames | + +-------+-------+ + |0 |7F | + |1 |01 | + |2 |02 | + |3 |03 | + |4 |04 | + |5 |05 | + |6 |06 | + |7 |07 | + |8 |08 | + |9 |09 | + |A |0A | + |B |0B | + |C |0C | + |D |0D | + |E |0E | + |F |0F | + +-------+-------+ + +The length counter's real-time status for each channel can be attained. A 0 +is returned for a zero count status in the length counter (channel's sound +is disabled), and 1 for a non-zero status. Here's the bit description of the +length counter status register: + +$4015(read) +----------- +0 length counter status of square wave channel 1 +1 length counter status of square wave channel 2 +2 length counter status of triangle wave channel +3 length counter status of noise channel +4 length counter status of DMC (see "DMC.TXT" for details) +5-6 unused +7 IRQ status of DMC (see "DMC.TXT" for details) + +Writing a 0 to the channel enable register will force the length counters to +always contain a count equal to 0, which renders that specific channel +disabled (as if it doesn't exist). Writing a 1 to the channel enable +register disables the forced length counter value of 0, but will not change +the count itself (it will still be whatever it was prior to the writing of +1). + +Bit description of the channel enable register: + +$4015(write) +------------ +0 enable square wave channel 1 +1 enable square wave channel 2 +2 enable triangle wave channel +3 enable noise channel +4 enable DMC channel (see "DMC.TXT" for details) +5-7 unused + +Note that all 5 used bits in this register will be set to 0 upon system +reset. + + ++-----------+ +| 4-bit DAC | ++-----------+ + +This is just a standard 4-bit DAC with 16 steps of output voltage +resolution, and is used by all 4 sound channels. + +On the 2A03, square wave 1 & 2 are mixed together, and are available via pin +1. Triangle & noise are available on pin 2. These analog outputs require a +negative current source, to attain linear symmetry on the various output +voltage levels generated by the channel(s) (moreover, to get the sound to be +audible). Since the NES just uses external 100 ohm pull-down resistors, this +results in the output waveforms being of very small amplitude, but with +minimal linearity asymmetry. + + ++------------------------------+ +| Volume / envelope decay unit | ++------------------------------+ + +The volume / envelope decay hardware is found only in the square wave and +noise channels. + +$4000(sq1)/$4004(sq2)/$400C(noise) +---------------------------------- +0-3 volume / envelope decay rate +4 envelope decay disable +5 envelope decay looping enable + +When the envelope decay disable bit (bit 4) is set (1), the current volume +value (bits 0-3) is sent directly to the channel's DAC. However, depending +on certain conditions, this 4-bit volume value will be ignored, and a value +of 0 will be sent to the DAC instead. This means that while the channel is +enabled (producing sound), the output of the channel (what you'll hear from +the DAC) will either be the 4-bit volume value, or 0. This also means that a +4-bit volume value of 0 will result in no audible sound. These conditions +are as follows: + +- When hardware in the channel wants to disable it's sound output (like the +length counter, or sweep unit (square channels only)). + +- On the negative portion of the output frequency signal coming from the +duty cycle / random number generator hardware (square wave channel / noise +channel). + +When the envelope decay disable bit is cleared, bits 0-3 now control the +envelope decay rate, and an internal 4-bit down counter (hereon the envelope +decay counter) now controls the channel's volume level. "Envelope decay" is +used to describe the action of the channel's audio output volume starting +from a certain value, and decreasing by 1 at a fixed (linear) rate (which +produces a "fade-out" sounding effect). This fixed decrement rate is +controlled by the envelope decay rate (bits 0-3). The calculated decrement +rate is 240Hz/(N+1), where N is any value between $0-$F. + +When the channel's envelope decay counter reaches a value of 0, depending on +the status of the envelope decay looping enable bit (bit 5, which is shared +with the length counter's clock disable bit), 2 different things will +happen: + +bit 5 action +----- ------ +0 The envelope decay count will stay at 0 (channel silenced). +1 The envelope decay count will wrap-around to $F (upon the next clock +cycle). The envelope decay counter will then continue to count down +normally. + +Only a write out to $4003/$4007/$400F will reset the current envelope decay +counter to a known state (to $F, the maximum volume level) for the +appropriate channel's envelope decay hardware. Otherwise, the envelope decay +counter is always counting down (by 1) at the frequency currently contained +in the volume / envelope decay rate bits (even when envelope decays are +disabled (setting bit 4)), except when the envelope decay counter contains a +value of 0, and envelope decay looping (bit 5) is disabled (0). + + ++------------+ +| Sweep unit | ++------------+ + +The sweep unit is only found in the square wave channels. The controls for +the sweep unit have been mapped in at $4001 for square 1, and $4005 for +square 2. + +The controls +------------ +Bit 7 when this bit is set (1), sweeping is active. This results in +real-time increasing or decreasing of the the current wavelength value (the +audible frequency will decrease or increase, respectively). The wavelength +value in $4002/3 ($4006/7) is constantly read & updated by the sweep. +Modifying the contents of $4002/3 will be immediately audible, and will +result in the sweep now starting from this new wavelength value. + +Bits 6-4 These 3 bits represent the sweep refresh rate, or the frequency at +which $4002/3 is updated with the new calculated wavelength. The refresh +rate frequency is 120Hz/(N+1), where N is the value written, between 0 and +7. + +Bit 3 This bit controls the sweep mode. When this bit is set (1), sweeps +will decrease the current wavelength value, as a 0 will increase the current +wavelength. + +Bits 2-0 These bits control the right shift amount of the new calculated +sweep update wavelength. Code that shows how the sweep unit calculates a new +sweep wavelength is as follows: + +bit 3 +----- +0 New = Wavelength + (Wavelength >> N) +1 New = Wavelength - (Wavelength >> N) (minus an additional 1, if using +square wave channel 1) + +where N is the the shift right value, between 0-7. + +Note that in decrease mode, for subtracting the 2 values: +1's compliment (NOT) is being used for square wave channel 1 +2's compliment (NEG) is being used for square wave channel 2 + +This information is currently the only known difference between the 2 square +wave channels. + +On each sweep refresh clock, the Wavelength register will be updated with +the New value, but only if all 3 of these conditions are met: + +- bit 7 is set (sweeping enabled) +- the shift value (which is N in the formula) does not equal to 0 +- the channel's length counter contains a non-zero value + +Notes +----- +There are certain conditions that will cause the sweep unit to silence the +channel, and halt the sweep refresh clock (which effectively stops sweep +action, if any). Note that these conditions pertain regardless of any sweep +refresh rate values, or if sweeping is enabled/disabled (via bit 7). + +- an 11-bit wavelength value less than $008 will cause this condition +- if the sweep unit is currently set to increase mode, the New calculated +wavelength value will always be tested to see if a carry (bit $B) was +generated or not (if sweeping is enabled, this carry will be examined before +the Wavelength register is updated) from the shift addition calculation. If +carry equals 1, the channel is silenced, and sweep action is halted. + + ++----------------------+ +| Duty cycle generator | ++----------------------+ + +The duty cycle generator takes the fequency produced from the 11-bit +programmable timer, and uses a 4 bit counter to produce 4 types of duty +cycles. The output frequency is then 1/16 that of the programmable timer. +The duty cycle hardware is only found in the square wave channels. The bit +assignments are as follows: + +$4000(sq1)/$4004(sq2) +--------------------- +6-7 Duty cycle type + + duty (positive/negative) +val in clock cycles +--- --------------- +00 2/14 +01 4/12 +10 8/ 8 +11 12/ 4 + +Where val represents bits 6-7 of $4000/$4004. + +The output frequency at this point will now be fed to the volume/envelope +decay hardware. + + ++----------------------+ +| Wavelength converter | ++----------------------+ + +The wavelength converter is only used in the noise channel. It is used to +convert a given 4-bit value to an 11-bit wavelength, which then is sent to +the noise's own programmable timer. Here is the bit descriptions: + +$400E bits +---------- +0-3 The 4-bit value to be converted + +Below is a conversion chart that shows what 4-bit value will represent the +11-bit wavelength to be fed to the channel's programmable timer: + +value octave scale CPU clock cycles (11-bit wavelength+1) +----- ------ ----- -------------------------------------- +0 15 A 002 +1 14 A 004 +2 13 A 008 +3 12 A 010 +4 11 A 020 +5 11 D 030 +6 10 A 040 +7 10 F 050 +8 10 C 065 +9 9 A 07F +A 9 D 0BE +B 8 A 0FE +C 8 D 17D +D 7 A 1FC +E 6 A 3F9 +F 5 A 7F2 + +Octave and scale information is provided for the music enthusiast programmer +who is more familiar with notes than clock cycles. + + ++-------------------------+ +| Random number generator | ++-------------------------+ + +The noise channel has a 1-bit pseudo-random number generator. It's based on +a 15-bit shift register, and an exclusive or gate. The generator can produce +two types of random number sequences: long, and short. The long sequence +generates 32,767-bit long number patterns. The short sequence generates +93-bit long number patterns. The 93-bit mode will generally produce higher +sounding playback frequencys on the channel. Here is the bit that controls +the mode: + +$400E bits +---------- +7 mode + +If mode=0, then 32,767-bit long number sequences will be produced (32K +mode), otherwise 93-bit long number sequences will be produced (93-bit +mode). + +The following diagram shows where the XOR taps are taken off the shift +register to produce the 1-bit pseudo-random number sequences for each mode. + +mode <----- +---- EDCBA9876543210 +32K ** +93-bit * * + +The current result of the XOR will be transferred into bit position 0 of the +SR, upon the next shift cycle. The 1-bit random number output is taken from +pin E, is inverted, then is sent to the volume/envelope decay hardware for +the noise channel. The shift register is shifted upon recieving 2 clock +pulses from the programmable timer (the shift frequency will be half that of +the frequency from the programmable timer (one octave lower)). + +On system reset, this shift register is loaded with a value of 1. + + diff --git a/branches/fceux-2.2.2/documentation/tech/exp/mmc5-e.txt b/branches/fceux-2.2.2/documentation/tech/exp/mmc5-e.txt new file mode 100644 index 00000000..eab191af --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/exp/mmc5-e.txt @@ -0,0 +1,250 @@ +========= mmc5 infomation ========== +date 1998/05/31 +by goroh +translated May 31, 1998 by Sgt. Bowhack +mail goroh_kun@geocities.co.jp + +5000,5004 ch1,ch2 Pulse Control + bit CCwevvvv + CC Duty Cycle (Positive vs. Negative) + #0:87.5% #1:75.0% #2:50.0% #3:25.0% + w Waveform Hold (e.g. Looping) + 0: Off 1: On + e Envelope Select + 0: Varied 1: Fixed + < e=0 > + vvvv Playback Rate + #0<-fast<--->-slow--> #15 + < e=1 > + vvvv Output Volume + +5002,5006 ch1,ch2 frequency L + bit ffffffff +5003,5007 ch1,ch2 frequency H + bit tttttfff + ttttt sound occurence time + +Objective is to remove the continuous changing of frequency for +square wave setup and do the same to the main part of the square wave +of studying the main part of the famicom. (?- Sgt. Bowhack) + +5010 ch3 synthetic voice business channel + bit -------O + O wave output 0:Off 1:On + +5011 ch4 synthetic voice business channel 2 + bit vvvvvvvv + vvvvvvvv wave size + +5015 sound output channel + bit ------BA + A: ch1 output 1:enable 0:disable + B: ch2 output 1:enable 0:disable + +5100 PRG-page size Setting + bit ------SS + SS PRG-page size + 0: 32k 1:16k 2,3:8k +* Reset is misled the first times for about 8k (?- SB) + +5101 CHR-page size Setting + bit ------SS + SS CHR-page size + 0:8k 1:4k 2:2k 3:1k + +5102 W BBR-RAM Write Protect 1 + bit ------AA +5103 W BBR-RAM Write Protect 2 + bit ------BB + (AA,BB) = (2,1) permitted to write to BBR-RAM only when crowded +*Reset write around becomes prohibited when crowded + +5104 Grafix Mode Setting + $5c00-$5fff decides how it should be used + bit ------MM + #00:Enable only Split Mode + #01:Enable Split Mode & ExGrafix Mode + #02:ExRAM Mode + #03:ExRAM Mode & Write Protect + +Consideration + MMC5 has 2 graphic mode extensions that allow more than 256 characters +on one standard game screen. It uses Split Mode so it can display the +specified CHR-page and scroll position seperate from ExGrafix Mode to +be able to choose a palette, and the other divides it vertically. + +5105 W NameTable Setting + bit ddccbbaa + aa: Select VRAM at 0x2000-0x23ff + bb: Select VRAM at 0x2400-0x27ff + cc: Select VRAM at 0x2800-0x2bff + dd: Select VRAM at 0x2c00-0x2fff + #0:use VRAM 0x000-0x3ff + #1:use VRAM 0x400-0x7ff + #2:use ExVRAM 0x000-0x3ff + #3:use ExNameTable(Fill Mode) + +Consideration + The name table can designate 4 kinds of this resister and be a useful +special quality for this because painting and smashing it with a +character that there is 1 sheet for the remaining sheets can generally +be used. (?-SB) + +5106 W Fill Mode Setting 1 + bit vvvvvvvv + Fill chr-table + For whether it paints or smashes it at any non-designated character + +5107 W Fill Mode Setting 2 + bit ------pp + Whether or not it uses any non-designated palettes + +5113 RAM-page for $6000-$7FFF + bit -----p-- + +5114-5117 Program Bank switch + < page_size=32k > + $5117 [8]-[F] bit pppppp-- + + < page_size=16k > + $5115 [8]-[B] bit ppppppp- + $5117 [C]-[F] bit ppppppp- + + < page_size=8k > + $5114 [8][9] bit pppppppp + $5115 [A][B] bit pppppppp + $5116 [C][D] bit pppppppp + $5117* [E][F] bit pppppppp + +*Reset is around early, Last Page misled + +5120-512b Charactor Bank switch + < page_size=8k > + $5120-$5127 switch to mode A + $5128-$512b switch to mode B + $5127 [0]-[7] modeA + $512b [0]-[7] modeB + + < page_size=4k > + $5120-$5127 switch to mode A + $5128-$512b switch to mode B + $5123 [0]-[3] modeA + $5127 [4]-[7] modeA + $512b [0]-[3],[4]-[7] modeB + + < page_size=2k > + $5120-$5127 switch to mode A + $5128-$512b switch to mode B + $5121 [0]-[1] modeA + $5123 [2]-[3] modeA + $5125 [4]-[5] modeA + $5127 [6]-[7] modeA + $5129 [0]-[1],[4]-[5] modeB + $512b [2]-[3],[6]-[7] modeB + + < page_size=1k > + $5120-$5127 switch to mode A + $5128-$512b switch to mode B + $5120 [0] modeA + $5121 [1] modeA + $5122 [2] modeA + $5123 [3] modeA + $5124 [4] modeA + $5125 [5] modeA + $5126 [6] modeA + $5127 [7] modeA + $5128 [0],[4] modeB + $5129 [1],[5] modeB + $512a [2],[6] modeB + $512b [3],[7] modeB + +Consideration + MMC5 has mode A ,mode B and 2 kinds of CHR-page memory resistors. +They can be used for refreshing it. (?-SB) + +5130 ??? +analyzing it... + +5200 W Split Mode Control 1 + bit Ec-vvvvv + For the E function 0:don't use 1:use + c boundary's side is for using Split Mode extension of graphics + 0: left side 1: right side + vvvvv left boundary is designated with the char. # to count places + +Sample. + 5200 <- #00 + (not?) used yet + 5200 <- #82 + Used for SplitMode GFX extension from left 1-2 character + 5200 <- #c2 + Used for SplitMode GFX extension from the right side 3 chars. + 5200 <- #c0 + Used for SplitMode GFX extension on the whole screen + 5200 <- #d0 + Used for SplitMode GFX extension on the right side of the screen + 5200 <- #90 + Used for SplitMode GFX extension on the left side of the screen + +5201 W SplitMode setup for SplitMode Ext. GFX use 1 + $2005 determines the vertical movement; it can also delay ext. gfx's + vert. movement if necessary. It's written 2 times in bulk in the same + way as it would slip off a grade in $2005 (??-SB) + +5202 W SplitMode setup for SplitMode Ext. GFX use 2 + bit --pppppp + uses vertical division of ext. gfx CHR-page designation + index_size=4k(0x1000byte) +In case it uses a character 0x4000-0x4fff for the ext. gfx in question + $5202 <- 4 + +5203 W scanline break point + For scanline # that it splits and wants to make it designate it in bulk + +5204 WR IRQ enable/disable + W bit I------- + I 1:IRQ Enable 0:IRQ Disable + R bit I------- + I 1:Scanline Hit 0:Scanline not Hit + $5203 is designated as scanline when arrived. + +5205 WR mult input/output +5206 WR mult input/output +($5205in)*($5206in) = $5205,$5206out + +5c00-5fbf ext. gfx business VRAM + shows an attribute of every position character + + + bit PPpppppp + PP: use character palette number + pppppp: use background CHR-PAGE number index=4k + #0-#3F are designations, $0000-$3FFF is CHR-data's range + Use for extension gfx + + + SplitMode uses a Name Table for extension gfx use. + bit pppppppp + pppppppp: use for background char. number designation + + + Used for Extension RAM + +5fc0-5fff + + (not?) used yet + + + SplitMode uses gfx's Attribute Table extension. + PPU uses $23c0-$23ff in the same way as the Attribute Table + + + Used for Extension RAM + +Consideration + 5c00-5fff has 3 uses. + Split Mode and ExGrafix Mode's VBlank is written so as to become + crowded, it writes a 0 and becomes crowded. + Every mode tries to go around ExRAM mode including reading but it + writes it, is effective in bulk and #5c-#5f is the output at times + where it is effective. \ No newline at end of file diff --git a/branches/fceux-2.2.2/documentation/tech/exp/smb2j.txt b/branches/fceux-2.2.2/documentation/tech/exp/smb2j.txt new file mode 100644 index 00000000..074b1d3d --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/exp/smb2j.txt @@ -0,0 +1,112 @@ + SMB2j Revision "A". Mapper #50 Info + ----------------------------------- + + +12.09.2000 +V2.00 + +Mapper info by The Mad Dumper +--- + + +This mapper has been assigned the number 50. (that's 50 decimal) + + +Wow, another SMB2j cart! This one is alot different than the last one I +worked on. It has a single 128K PRG ROM and VRAM. The other SMB2j had +64K PRG and 8K CHR. Not much more to say other than this has one very +fucked up mapper circuit on it! + +--- + + +The hardware: + + +It consists of 6 TTL chips (74163, 74157, 74139, 7400, 7474, and a 4020), +1 8K RAM chip for the VRAM, and 1 128K 28 pin ROM. There is some +"M^2L" logic on the board (Mickey-Mouse Logic). It is a 3 input OR gate +made out of 3 diodes and a resistor. + +Also, they swapped D3 and D6, as well as A1 and A3. Why this was done, I +have no idea. It sure mussed up my REing efforts! I desoldered and read +the ROM out through the EPROM programmer as a check and was not happy to +find the data seemingly corrupt! + +After converting the ROM image over via some QBasic, it matched up great. +You do not have to swap the addresses or data bytes; I have done this +already in the released .NES ROM. + +--- + +There are two registers on this cartridge. They are located in the 4000h- +5FFFh block. + +Funny addresses are decoded for the register selection; presumably so they +did not interfere with the FDS or NES registers. + + +A15 ... A0 +------------------- +010x xxxQ x01x xxxx + + +x = Don't Care +0 = must be 0 +1 = must be 1 +Q = register selection bit. 0 = ROM Page; 1 = IRQ Timer Enable + +- + +ROM Page Register: +------------------ + +Accessed when the address lines are in the above state. An example address +would be 4020h. 4021h, 4022h, ... 403Fh, 40A0h, 40A1h, ... are all mirrors +of this register. Writing here stores the desired bank #. + +7 bit 0 +--------- +xxxx DCBA + +These 4 bits are shown below in the ROM memory map. Note that they are +somewhat "scrambled". The value of this register is unknown at powerup. + +- + +IRQ Timer. + +7 bit 0 +--------- +xxxx xxxI + +The IRQ Timer register controls the state of the IRQ timer. Writing here +will turn it on or off. Turning the IRQ timer off resets it to 0. Writing +a 1 here will turn the timer on, while writing a 0 will turn it off. + +The timer is composed of a binary ripple counter. After 4096 M2 cycles, +/IRQ is pulled low. This is about 36 scanlines. The idea behind the timer +is to split the screen for the score bar at the top. You start it at the +beginning of the VBI routine, and then after 36 scanlines, it sends the IRQ +which clears the timer, and resets the scroll registers. The value of this +register is unknown at powerup. + +--- + +ROM Memory Map: + + +Address Range | Bank bits: 3210 +------------------------------- + 6000h-7FFFh 1111 + 8000h-9FFFh 1000 + A000h-BFFFh 1001 + C000h-DFFFh DACB -- Selectable page + E000h-FFFFh 1011 + + +The ROM is composed of 16 8K banks. The 4 bank bits are shown above. Bit 3 +is the MSB while bit 0 is the LSB. 6000h-7FFFh is set to 1111b, or bank 0fh. +All banks are FIXED except the bank at C000h-DFFFh. Only it can be changed. + + diff --git a/branches/fceux-2.2.2/documentation/tech/exp/tengen.txt b/branches/fceux-2.2.2/documentation/tech/exp/tengen.txt new file mode 100644 index 00000000..cc84d596 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/exp/tengen.txt @@ -0,0 +1,18 @@ +Unknown: + +Alien Syndrome 128KiB/128KiB +Super Sprint + +MIMIC 1: + +Fantasy Zone 64KiB/64KiB +Toobin' 128KiB/64KiB +Vindicators 64KiB/32KiB + + +RAMBO 1(board looks like it can take 256KiB PRG/256KiB CHR max): + +Klax 64KiB PRG/64KiB CHR +Road Runner 64KiB PRG/128KiB CHR +Rolling Thunder 128KiB PRG/128KiB CHR +Skull and Crossbones 128KiB PRG/64KiB CHR diff --git a/branches/fceux-2.2.2/documentation/tech/exp/vrcvi.txt b/branches/fceux-2.2.2/documentation/tech/exp/vrcvi.txt new file mode 100644 index 00000000..52023577 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/exp/vrcvi.txt @@ -0,0 +1,388 @@ + VRCVI CHIP INFO + ----- ---- ---- + + By: + + + Kevin Horton + khorton@iquest.net + + + + + The RENES Project: + Reverse-engineering + the world. + + + + +V1.01 08/31/99 teeny fix +V1.00 08/31/99 Complete Version + + + +VRCVI (VRC6) (48 pin standard 600mil wide DIP) +------------ +This chip is used in such games as Konami's CV3j and Madara. It's unique +because it has some extra sound channels on it that get piped through the +Famicom (note this is a fami-only chip and you will not find one in any +NES game). "VI" of "VRCVI" is "6" for the roman numeral challenged. + + +This chip generates its audio via a 6 bit R2R ladder. This is contained +inside a 9 pin resistor network like so: + + + 3K 3K 3K 3K 3K 2K + /------*-\/\/-*-\/\/-*-\/\/-*-\/\/-*-\/\/-*------*-\/\/-\ + | | | | | | | | | + \ \ \ \ \ \ \ | | + / / / / / / / | | + \ 6K \ 6K \ 6K \ 6K \ 6K \ 6K \ 6K | | + / / / / / / / | | + | | | | | | | | | + O O O O O O O O O + + GND D0 D1 D2 D3 D4 D5 Aud In Aud Out + + +Legend: +------- + +(s) means this pin connects to the System +(r) this only connects to the ROM +(w) this is a SRAM/WRAM connection only +AUD : these pass to the resistor network +CHR : these connect to the CHR ROM and/or fami's CHR pins +PRG : these connect to the PRG ROM and/or fami's PRG pins +WRAM : this hooks to the WRAM +CIRAM : the RAM chip which is on the fami board + + .----\/----. + GND - |01 48| - +5V + AUD D1 - |02 47| - AUD D0 + AUD D3 - |03 46| - AUD D2 + AUD D5 - |04 45| - AUD D4 + (s) PRG A12 - |05 44| - PRG A16 (r) + (s) PRG A14 - |06 43| - PRG A13 (s) + (s) M2 - |07 42| - PRG A17 (r) + (r) PRG A14 - |08 41| - PRG A15 (r) + *1 (s) PRG A1 - |09 40| - PRG A13 (r) + *1 (s) PRG A0 - |10 39| - PRG D7 (s) + (s) PRG D0 - |11 38| - PRG D6 (s) + (s) PRG D1 - |12 37| - PRG D5 (s) + (s) PRG D2 - |13 36| - PRG D4 (s) + (r) PRG /CE - |14 35| - PRG D3 (s) + (s) R/W - |15 34| - PRG /CE (s) + *2 (w) WRAM /CE - |16 33| - /IRQ (s) + (r) CHR /CE - |17 32| - CIRAM /CE (s) + (s) CHR /RD - |18 31| - CHR A10 (s) + (s) CHR /A13 - |19 30| - CHR A11 (s) + (r) CHR A16 - |20 29| - CHR A12 (s) + (r) CHR A15 - |21 28| - CHR A17 (r) + (r) CHR A12 - |22 27| - CHR A14 (r) + (r) CHR A11 - |23 26| - CHR A13 (r) + GND - |24 25| - CHR A10 (r) + | | + `----------' + + VRCVI + + +*1: On some VRCVI carts, these are reversed. This affects some registers. + +*2: This passes through a small pulse shaping network consisting of a + resistor, diode, and cap. + + +Registers: (sound related only) +---------- + +regs 9000-9002 are for pulse channel #1 +regs a000-a002 are for pulse channel #2 +regs b000-b002 are for the phase accumulator channel (sawtooth) + +(bits listed 7 through 0) + +9000h: GDDDVVVV + + D - Duty Cycle bits: + + 000 - 1/16th ( 6.25%) + 001 - 2/16ths (12.50%) + 010 - 3/16ths (18.75%) + 011 - 4/16ths (25.00%) + 100 - 5/16ths (31.25%) + 101 - 6/16ths (37.50%) + 110 - 7/16ths (43.75%) + 111 - 8/16ths (50.00%) + + V - Volume bits. 0000b is silence, 1111b is loudest. Volume is + linear. When in "normal" mode (see G bit), this acts as a general + volume control register. When in "digitized" mode, these act as a + 4 bit sample input. + + G - Gate bit. 0=normal operation, 1=digitized. In digi operation, + registers 9001h and 9002h are totally disabled. Only bits 0-3 of + 9000h are used. Whatever binary word is present here is passed on + as a 4 bit digitized output. + + +9002h: FFFFFFFF + + F - Lower 8 bits of frequency data + + +9003h: X---FFFF + + X - Channel disable. 0=channel disabled, 1=channel enabled. + + F - Upper 4 bits of frequency data + + +A000h-A002h are identical in operation to 9000h-9002h. One note: this chip +will mix both digitized outputs (if the G bits are both set) into one +added output. (see in-depth chip operation below) + +B000h: --PPPPPP + + P - Phase accumulator input bits + +B001h: FFFFFFFF + + F - Lower 8 bits of frequency data + +B002h: X---FFFF + + X - Channel disable. 0=channel disabled, 1=channel enabled. + + F - Upper 4 bits of frequency data + + + +How the sounds are formed: +-------------------------- + +This chip is pretty cool. It outputs a 6 bit binary word for the sound +which is passed through a DAC and finally to the NES/Fami. Because of this, +the sound can be emulated *very* close to the original. + + +I used my scope to figure all this out as well as my meter and logic probe +so it should be 100% accurate. + + + +Block diagrams of the VRCVI: (as reverse engineered by me) +---------------------------- + + + | F bits | | D bits| | V bits | + | (12) | | (3) | | (4) | + \___________/ \_______/ \________/ ++-----+ +----------------+ +-----------+ +------------+ +| | | | | | | |--\ +| OSC |-->|Divider (12 bit)|-->| Duty Cycle|-->| AND array |(4)> chan out +|(M2) | | | | Generator | | |--/ ++-----+ +----------------+ +-----------+ +------------+ + ^ ^ + | | + | | + G X + + One Pulse channel (both are identical) + -------------------------------------- + + +How it works: The oscillator (in the NES, the clock arrives on the M2 line +and is about 1.78Mhz) generates our starting frequency. This is passed +first into a divide by 1 to 4096 divider to generate a base frequency. +This is then passed to the duty cycle generator. The duty cycle generator +generates the desired duty cycle for the output waveform. The "D" input +controls the duty cycle generator's duty cycle. If the "G" bit is +a "1", it forces the output of the duty cycle generator to a "1" also. If +the "X" bit is "0", it forces the output of the duty cycle generator to "0", +which effectively disables the channel. Note that this input has precidence +over the "G" bit. + +The AND array is just that- an array of 4 AND gates. If the output of +the duty cycle generator is a "0", then the "chan out" outputs will all be +forced to "0". If the output of the duty cycle generator is a "1", then +the chan out outputs will follow the V bit inputs. + +Note that the output of this generator is a 4 bit binary word. + + +--- + + + | F bits | | P bits| + | (12) | | (6) | + \___________/ \_______/ ++-----+ +----------------+ +-----------+ +| | | | | |--\ +| OSC |-->|Divider (12 bit)|-->| Phase |(5)> chan out +|(M2) | | | |Accumulator|--/ ++-----+ +----------------+ +-----------+ + ^ + | + | + X + + The Sawtooth (ramp) channel + --------------------------- + + +This one is pretty similar to the above when it comes to frequency selection. +The output frequency will be the same relative to the square wave channels. +OK, the tough part will be explaining the phase accumulator. :-) What it is +is just an adder tied to a latch. Every clock it adds a constant to the +latch. In the case of the VRCVI, what you do is this: + +The ramp is generated over the course of 7 evenly spaced cycles, generated +from the divider. Every clock from the divider causes the phase accumulator +to add once. So... let's say we have 03h in the P bits. Every 7 cycles +the phase accumulator (which is 8 bits) is reset to 00h. + + +cycle: accumulator: chan out: notes: +----------------------------------------- +0 00h 00h On the first cycle, the acc. is reset to 0 +1 03h 00h We add 3 to 0 to get 3 +2 06h 00h We add 3 to 3 to get 6 +3 09h 01h +4 0ch 01h +5 0fh 01h +6 12h 02h +7 00h 00h Reset the acc. back to 0 and do it again + + +This will look like so: (as viewed on an oscilloscope) + + + + - - - 2 + --- --- --- 1 +--- --- --- 0 + | +012345601234560123456-+ + + + +Note: if you enter a value that is too large (i.e. 30h) the accumulator +*WILL WRAP*. Yes, this doesn't sound very good at all and you no longer +have a sawtooth. ;-) + + +The upper 5 bits of said accumulator are run to the "chan out" outputs. +The lower 3 bits are not run anywhere. + +"X" disables the phase accumulator and forces all outputs to "0". +Note that the output of this generator is a 5 bit word. + + +--- + +Now that the actual sound generation is out of the way, here's how the +channels are combined into the final 6 bit binary output: + + ++---------+ +| Pulse | +|Generator| +| #1 | Final 6 Bit ++---------+ Output + | (4) | / \ + \ / | (6) | ++---------+ +---------+ +---------+ +| 4 Bit |--\ | 5 Bit | /--|Sawtooth | +| Binary |(5)>| Binary |<(5)|Generator| +| Adder |--/ | Adder | \--| | ++---------+ +---------+ +---------+ + / \ + | (4) | ++---------+ +| Pulse | +|Generator| +| #2 | ++---------+ + + Channel Combining + ----------------- + + +The three channels are finally added together through a series of adders +to produce the final output word. The two pulse chans are most likely added +first since they are 4 bit words, and that 5 bit result is most likely +added to the sawtooth's output. (The actual adding order is not known, +but I can make a *very* good guess. The above illustrated way uses the least +amount of transistors). In the end it does not matter the order in which +the words are added; the final word will always be the same. + +The final 6 bit output word is run through an "R2R" resistor ladder which +turns the digital bits into a 64 level analog representation. The ladder +is binarally weighted and works like the DAC on your soundcard. :-) +(so take heart emulator authours: just run the finished 6 bit word to +your soundcard and it will sound right ;-). + + + +Frequency Generation: +--------------------- + +The chip generates all its output frequencies based on M2, which is +colourburst divided by two (1789772.7272Hz). This signal is passed +directly into the programmable dividers (the 12 bit frequency regs). + +Squares: +-------- + +These take the output of the programmable divider and then run it through +the duty cycle generator, which in the process of generating the duty cycle, +divides the frequency by 16. + + +To calculate output frequency: + + 1789772.7272 +Fout = ---------------- + (freq_in+1) * 16 + + +This will tell you the exact frequency in Hz. (note that the * 16 is to +compensate for the divide by 16 duty cycle generator.) + +Saw: +---- + +This is similar to the above, however the duty cycle generator is replaced +with a phase accumulator which divides the output frequency by 14. + + +To calculate output frequency: + + 1789772.7272 +Fout = ---------------- + (freq_in+1) * 14 + + +This will tell you the exact frequency in Hz. (note that the * 14 is to +compensate for the phase accumulator.) + + + +So how accurate is this info, anyways? +-------------------------------------- + +I believe the info to be 100% accurate. I have extensively tested the +output of the actual VRCVI chip to this spec and everything fits perfectly. +I did this by using a register dump and a QBASIC program I wrote which +takes the register dump and produces a WAV file. All frequency and +duty cycle measurements were taken with a Fluke 83 multimeter, and all +waveform data was culled from my oscilloscope measuring the real chip. + + + + +---EOF--- diff --git a/branches/fceux-2.2.2/documentation/tech/exp/vrcvii.txt b/branches/fceux-2.2.2/documentation/tech/exp/vrcvii.txt new file mode 100644 index 00000000..fc07d05e --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/exp/vrcvii.txt @@ -0,0 +1,321 @@ + VRCVII CHIP INFO + ------ ---- ---- + + By: + + + Kevin Horton + khorton@iquest.net + + + + + The RENES Project: + Reverse-engineering + the world. + + + +V0.10 11/05/99 Document started, pinned out chip and audio thingy +V0.20 11/10/99 Added very, very, very preliminary register findings +v1.00 11/14/99 First release version of this doc + +VRCVII (VRC7) (48 pin standard 600mil wide DIP) +------------- + +This chip is used in only one Konami game that I know of- Lagrange Point. +I heard rumours it was used in another game, so if someone could provide +info and/or a ROM image, that would help immensely. It handles ROM +bankswitching as well as sound generation. The sound generation is done +using FM synthesis, so the music sounds like "Adlib" OPL2 music. Due to +extra sound, this is a Famicom-only chip like its cousin the +VRCVI. (See the VRCVI doc for more info) + +"VII" of "VRCVII" is "7" for the roman numeral challenged. + + +This chip appears to generate all of its audio internally, which is then +fed to a small hybrid (aka "black blob") that does the audio interfacing +to the Famicom proper. It is physically a small ceramic substrate with +an 8 pin SMD chip on it (probably an op-amp), and what appears to be three +0805 sized SMD chip parts (capacitors most likely, since resistors can be +formed on the substrate). The whole works is then coated with a black +dipped epoxy coating, and the smooth side (opposite the parts) is then +marked with an identifying part number and the pin 1 dot. + + +Here's the pinout for it: + + Front Side (parts facing away) + + +-----------------+ 1- Audio in from Famicom + | 054002 | 2- Audio out to Famicom + |@ | 3,7 - Ground + +-----------------+ 4-6 - NC + | | | | | | | | | 8- Audio from VRCVII + 1 2 3 4 5 6 7 8 9 9- +5V + + + + + +Legend: +------- + +(s) means this pin connects to the System +(r) this only connects to the ROM +(w) this is a SRAM/WRAM connection only +PRG : these connect to the PRG ROM and/or fami's PRG pins +WRAM : this hooks to the WRAM + +Note: There is a 3.58Mhz ceramic resonator connected to the "X1" and "X2" +pins. it is the three-pin style with internal caps tied to the third pin +which is grounded. + +Chip is physically marked: "VRV VII 053982" + + .----\/----. + *1 (RAM&s) CHR /OE - |01 48| - NC + *1 (RAM&s) CHR /CE - |02 47| - M2 (s) + GND - |03 46| - /CE WRAM (w) + (s) R/W - |04 45| - PRG /A15 (s) (aka /CE) + (s) /IRQ - |05 44| - PRG ROM /CE (r) + (s) CIRAM A11 - |06 43| - Audio Out + (s) PD0 - |07 42| - +5V + (s) PD1 - |08 41| - NC + (s) PD2 - |09 40| - NC + (s) PD3 - |10 39| - NC + (s) PD4 - |11 38| - NC + (s) PD5 - |12 37| - NC + (s) PD6 - |13 36| - CHR RAM A12 + (s) PD7 - |14 35| - CHR RAM A11 + +5V - |15 34| - CHR RAM A10 + (s) PRG A5 - |16 33| - CHR A12 (s) + Crystal X2 - |17 32| - CHR A11 (s) + Crystal X1 - |18 31| - CHR A10 (s) + (s) PRG A4 - |19 30| - +5V + (r) PRG ROM A13 - |20 29| - PRG A14 (s) + (r) PRG ROM A14 - |21 28| - PRG A13 (s) + (r) PRG ROM A15 - |22 27| - PRG A12 (s) + (r) PRG ROM A16 - |23 26| - PRG ROM A18 (r) + GND - |24 25| - PRG ROM A17 (r) + | | + `----------' + + VRCVII + + +*1: these connect to both the CHR RAM's pins and the card edge. + +Note: the NC pins 37-41 most likely for CHR ROM bankswitching. Since this +cart uses CHR RAM these obviously weren't used ;-) + +Registers: (sound related only) +---------- + +All sound registers are accessed through only two physical registers. + +9010: +----- + +This is the index register. You write the desired register number here. + +9030: +----- + +This is the data register. Data written here is stored in the register +pointed to by the above index register. + +There are 6 channels, each containing three registers, and 8 custom +instrument control registers. + + +Sound Registers: +---------------- + +00h - 07h : Custom instrument registers. See below for info. + +--- + +10h - 15h : ffffffff + +f: Lower 8 bits of frequency + +--- + +20h - 25h : ???tooof + +f: Upper bit of frequency +o: Octave Select +t: Channel trigger. +?: Dunno what these do yet (No audible effect) + +--- + +30h - 35h : iiiivvvv + +i: Instrument number +v: Volume + +Instrument numbers 01h-0fh are fixed and cannot be changed. + +Instrument number 00h is the "programmable" one. + +To program the custom instrument, you load registers 00h-07h with the +desired parameters for it. All channels set to instrument 00h will +then use this instrument. Note that you can only program one custom +instrument at a time. + + + +How do the frequency registers work? +------------------------------------ + +To generate a tone, you must select an octave and a frequency value. The +frequency values stay the same for say, the note "C", while the octave +bits determine which octave "C" lies in. This makes your note lookup table +quite small. + +o = 000 is octave 0 +o = 001 is octave 1 +. +. +. +o = 111 is octave 7 + + + 49722*freqval +F = ------------- + 2^(19-octave) + + +Where: + +F = output frequency in Hz +freqval = frequency register value +octave = desired octave (starting at 0) + + +Custom Instrument Registers (00-07) +----------------------------------- + +Note: I will not provide too extensive documentation of the instrument +registers since their functions are identical to those of the OPL2 chip, +commonly found on Adlib/Soundblaster/compatible cards, and there is alot +of information out on how to program these. I will use terminology +similar to that found in said documents. My VRC7 "emulator" test program +I wrote simply re-arranged and tweaked the register writes to correspond +with the OPL2 registers. + +Here's a link to a good document about this chip: + +http://www.ccms.net/~aomit/oplx/ + +The tremolo depth is set to 4.3db and the vibrato depth is set to 14 cent +(in reguards to OPL2 settings; to achieve this you would write 0C0h to +OPL register 0BDh). All operator connections are fixed in FM mode. (Where +Modulator modulates the Carrier). + +--- + + +00 (Modulator) - tvskmmmm +01 (Carrier) + +t: Tremolo Enable +v: Vibrato Enable +s: Sustain Enable +k: KSR +m: Multiplier + +--- + +02 - kkoooooo + +k: Key Scale Level +o: Output Level + +--- + +03 - ---qweee + +-: Not used: Write 0's +q: Carrier Waveform +w: Modulator Waveform + +Note: There are only two waveforms available. Sine and rectified sine (only + the positive cycle of the sine; negative cycle "chopped off".) + +e: Feedback Control + +--- + +04 (Modulator) - aaaadddd +05 (Carrier) + +a: Attack +d: Decay + +--- + +06 (Modulator) - ssssrrrr +07 (Carrier) + +s: Sustain +r: Release + + + +Register Settings for the 15 fixed instruments. +----------------------------------------------- + +*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION* +C C +A These instruments are not 100% correct! There is no way to extract A +U the register settings from the chip short of an electron microscope. U +T I have "tuned" these instruments best I could, though I know a couple T +I are not exactly right. Use them at your own perl! If someone wants I +O to waste all day tuning a new set, please let me know what you get. O +N N +*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION*CAUTION* + + + Register + -------- + + 00 01 02 03 04 05 06 07 + ----------------------- + 0 | -- -- -- -- -- -- -- -- + 1 | 05 03 10 06 74 A1 13 F4 + 2 | 05 01 16 00 F9 A2 15 F5 + 3 | 01 41 11 00 A0 A0 83 95 + 4 | 01 41 17 00 60 F0 83 95 + 5 | 24 41 1F 00 50 B0 94 94 + 6 | 05 01 0B 04 65 A0 54 95 + 7 | 11 41 0E 04 70 C7 13 10 + Instrument 8 | 02 44 16 06 E0 E0 31 35 + ---------- 9 | 48 22 22 07 50 A1 A5 F4 + A | 05 A1 18 00 A2 A2 F5 F5 + B | 07 81 2B 05 A5 A5 03 03 + C | 01 41 08 08 A0 A0 83 95 + D | 21 61 12 00 93 92 74 75 + E | 21 62 21 00 84 85 34 15 + F | 21 62 0E 00 A1 A0 34 15 + + + + +So how accurate is this info, anyways? +-------------------------------------- + +I believe the info to be 100% accurate. The pinout was generated with the +help of a multimeter and my Super-8 with both an NES cart and the Fami cart +plugged in. (this allows me to measure between my known "control" board +with the unknown "experimental" board to generate the connections). +Register info was gleaned via writing test code and listening and capturing +the resultant audio stream for analysis. + + + + +---EOF--- diff --git a/branches/fceux-2.2.2/documentation/tech/nsfspec.txt b/branches/fceux-2.2.2/documentation/tech/nsfspec.txt new file mode 100644 index 00000000..2ef526d2 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/nsfspec.txt @@ -0,0 +1,336 @@ + NES Music Format Spec + --------------------- + + +By: Kevin Horton khorton@iquest.net + + +NOTE: +----- + + +Remember that I am very willing to add stuff and update this spec. If +you find a new sound chip or other change let me know and I will get back +with you. E-mail to the above address. + + +V1.61 - 06/27/2000 Updated spec a bit +V1.60 - 06/01/2000 Updated Sunsoft, MMC5, and Namco chip information +V1.50 - 05/28/2000 Updated FDS, added Sunsoft and Namco chips +V1.32 - 11/27/1999 Added MMC5 register locations +V1.30 - 11/14/1999 Added MMC5 audio bit, added some register info +V1.20 - 09/12/1999 VRC and FDS prelim sound info added +V1.00 - 05/11/1999 First official NSF specification file + + + +This file encompasses a way to transfer NES music data in a small, easy to +use format. + +The basic idea is one rips the music/sound code from an NES game and prepends +a small header to the data. + +A program of some form (6502/sound emulator) then takes the data and loads +it into the proper place into the 6502's address space, then inits and plays +the tune. + +Here's an overview of the header: + +offset # of bytes Function +---------------------------- + +0000 5 STRING "NESM",01Ah ; denotes an NES sound format file +0005 1 BYTE Version number (currently 01h) +0006 1 BYTE Total songs (1=1 song, 2=2 songs, etc) +0007 1 BYTE Starting song (1= 1st song, 2=2nd song, etc) +0008 2 WORD (lo/hi) load address of data (8000-FFFF) +000a 2 WORD (lo/hi) init address of data (8000-FFFF) +000c 2 WORD (lo/hi) play address of data (8000-FFFF) +000e 32 STRING The name of the song, null terminated +002e 32 STRING The artist, if known, null terminated +004e 32 STRING The Copyright holder, null terminated +006e 2 WORD (lo/hi) speed, in 1/1000000th sec ticks, NTSC (see text) +0070 8 BYTE Bankswitch Init Values (see text, and FDS section) +0078 2 WORD (lo/hi) speed, in 1/1000000th sec ticks, PAL (see text) +007a 1 BYTE PAL/NTSC bits: + bit 0: if clear, this is an NTSC tune + bit 0: if set, this is a PAL tune + bit 1: if set, this is a dual PAL/NTSC tune + bits 2-7: not used. they *must* be 0 +007b 1 BYTE Extra Sound Chip Support + bit 0: if set, this song uses VRCVI + bit 1: if set, this song uses VRCVII + bit 2: if set, this song uses FDS Sound + bit 3: if set, this song uses MMC5 audio + bit 4: if set, this song uses Namco 106 + bit 5: if set, this song uses Sunsoft FME-07 + bits 6,7: future expansion: they *must* be 0 +007c 4 ---- 4 extra bytes for expansion (must be 00h) +0080 nnn ---- The music program/data follows + +This may look somewhat familiar; if so that's because this is somewhat +sorta of based on the PSID file format for C64 music/sound. + + +Loading a tune into RAM +----------------------- + +If offsets 0070h to 0077h have 00h in them, then bankswitching is *not* +used. If one or more bytes are something other than 00h then bankswitching +is used. If bankswitching is used then the load address is still used, +but you now use (ADDRESS AND 0FFFh) to determine where on the first bank +to load the data. + + +Each bank is 4K in size, and that means there are 8 of them for the +entire 08000h-0ffffh range in the 6502's address space. You determine where +in memory the data goes by setting bytes 070h thru 077h in the file. +These determine the inital bank values that will be used, and hence where +the data will be loaded into the address space. + +Here's an example: + +METROID.NSF will be used for the following explaination. + +The file is set up like so: (starting at 070h in the file) + + +0070: 05 05 05 05 05 05 05 05 - 00 00 00 00 00 00 00 00 +0080: ... music data goes here... + +Since 0070h-0077h are something other than 00h, then we know that this +tune uses bankswitching. The load address for the data is specified as +08000h. We take this AND 0fffh and get 0000h, so we will load data in +at byte 0 of bank 0, since data is loaded into the banks sequentially +starting from bank 0 up until the music data is fully loaded. + +Metroid has 6 4K banks in it, numbered 0 through 5. The 6502's address +space has 8 4K bankswitchable blocks on it, starting at 08000h-08fffh, +09000h-09fffh, 0a000h-0afffh ... 0f000h-0ffffh. Each one of these is 4K in +size, and the current bank is controlled by writes to 05ff8h thru 05fffh, +one byte per bank. So, 05ff8h controls the 08000h-08fffh range, 05ff9h +controls the 09000h-09fffh range, etc. up to 05fffh which controls the +0f000h-0ffffh range. When the song is loaded into RAM, it is loaded into +the banks and not the 6502's address space. Once this is done, then the +bank control registers are written to set up the inital bank values. +To do this, the value at 0070h in the file is written to 05ff8h, 0071h +is written to 05ff9h, etc. all the way to 0077h is written to 05fffh. +This is should be done before every call to the init routine. + +If the tune was not bankswitched, then it is simply loaded in at the +specified load address, until EOF + + +Initalizing a tune +------------------ + +This is pretty simple. Load the desired song # into the accumulator, +minus 1 and set the X register to specify PAL (X=1) or NTSC (X=0). +If this is a single standard tune (i.e. PAL *or* NTSC but not both) +then the X register contents should not matter. Once the song # and +optional PAL/NTSC standard are loaded, simply call the INIT address. +Once init is done, it should perform an RTS. + + +Playing a tune +-------------- + +Once the tune has been initalized, it can now be played. To do this, +simply call the play address several times a second. How many times +per second is determined by offsets 006eh and 006fh in the file. +These bytes denote the speed of playback in 1/1000000ths of a second. +For the "usual" 60Hz playback rate, set this to 411ah. + +To generate a differing playback rate, use this formula: + + + 1000000 +PBRATE= --------- + speed + +Where PBRATE is the value you stick into 006e/006fh in the file, and +speed is the desired speed in hertz. + + +"Proper" way to load the tune +----------------------------- + +1) If the tune is bankswitched, go to #3. + +2) Load the data into the 6502's address space starting at the specified + load address. Go to #4. + +3) Load the data into a RAM area, starting at (start_address AND 0fffh). + +4) Tune load is done. + + +"Proper" way to init a tune +--------------------------- + +1) Clear all RAM at 0000h-07ffh. + +2) Clear all RAM at 6000h-7fffh. + +3) Init the sound registers by writing 00h to 04000-0400Fh, 10h to 4010h, + and 00h to 4011h-4013h. + +4) Set volume register 04015h to 00fh. + +5) If this is a banked tune, load the bank values from the header into + 5ff8-5fffh. + +6) Set the accumulator and X registers for the desired song. + +7) Call the music init routine. + + +"Proper" way to play a tune +--------------------------- + +1) Call the play address of the music at periodic intervals determined + by the speed words. Which word to use is determined by which mode + you are in- PAL or NTSC. + + +Sound Chip Support +------------------ + +Byte 007bh of the file stores the sound chip flags. If a particular flag +is set, those sound registers should be enabled. If the flag is clear, +then those registers should be disabled. + +* VRCVI Uses registers 9000-9002, A000-A002, and B000-B002, write only. + +Caveats: 1) The above registers are *write only* and must not disrupt music + code that happens to be stored there. + + 2) Major caveat: The A0 and A1 lines are flipped on a few games!! + If you rip the music and it sounds all funny, flip around + the xxx1 and xxx2 register pairs. (i.e. 9001 and 9002) 9000 + and 9003 can be left untouched. I decided to do this since it + would make things easier all around, and this means you only + will have to change the music code in a very few places (6). + Esper2 and Madara will need this change, while Castlevania 3j + will not for instance. + + 3) See my VRCVI.TXT doc for a complete register description. + +* VRCVII Uses registers 9010 and 9030, write only. + +Caveats: 1) Same caveat as #1, above. + + 2) See my VRCVII.TXT doc for a complete register description. + +* FDS Sound uses registers from 4040 through 4092. + +Caveats: 1) 6000-DFFF is assumed to be RAM, since 6000-DFFF is RAM on the + FDS. E000-FFFF is usually not included in FDS games because + it is the BIOS ROM. However, it can be used on FDS rips to help + the ripper (for modified play/init addresses). + + 2) Bankswitching operates slightly different on FDS tunes. + 5FF6 and 5FF7 control the banks 6000-6FFF and 7000-7FFF + respectively. NSF header offsets 76h and 77h correspond to + *both* 6000-7FFF *AND* E000-FFFF. Keep this in mind! + +* MMC5 Sound Uses registers 5000-5015, write only as well as 5205 and 5206, + and 5C00-5FF5 + +Caveats: 1) Generating a proper doc file. Be patient. + + 2) 5205 and 5206 are a hardware 8*8 multiplier. The idea being + you write your two bytes to be multiplied into 5205 and 5206 + and after doing so, you read the result back out. Still working + on what exactly triggers it (I think a write to either 5205 + or 5206 triggers the multiply). + + 3) 5C00-5FF5 should be RAM to emulate EXRAM while in MMC5 mode. + +Note: Thanks to Mamiya for the EXRAM info. + + +* Namco 106 Sound Uses registers 4800 and F800. + + This works similar to VRC7. 4800 is the "data" port which is + readable and writable, while F800 is the "address" port and is + writable only. + + The address is 7 bits plus a "mode" bit. Bit 7 controls + address auto-incrementing. If bit 7 is set, the address will + auto-increment after a byte of data is read or written from/to + 4800. + + $40 ffffffff f:frequency L + $42 ffffffff f:frequency M + $44 ---sssff f:frequency H s:tone length (8-s)*4 in 4bit-samples + $46 tttttttt t:tone address(4bit-address,$41 means high-4bits of $20) + $47 -cccvvvv v:linear volume 1+c:number of channels in use($7F only) + $40-47:ch1 $48-4F:ch2 ... $78-7F:ch8 + ch2-ch8 same to ch1 + + $00-3F(8ch)...77(1ch) hhhhllll tone data + h:odd address data(signed 4bit) + l:even address data(signed 4bit) + + real frequency = (f * NES_BASECYCLES) / (40000h * (c+1) * (8-s)*4 * 45) + NES_BASECYCLES 21477270(Hz) + +Note: Very Special thanks to Mamiya for this information! + + +* Sunsoft FME-07 Sound uses registers C000 and E000 + + This is similar to the common AY 3-8910 sound chip that is + used on tons of arcade machines, and in the Intellivision. + + C000 is the address port + E000 is the data port + + Both are write-only, and behave like the AY 3-8910. + +Note: Special thanks to Mamiya for this information as well + + +Caveats +------- + +1) The starting song number and maximum song numbers start counting at + 1, while the init address of the tune starts counting at 0. To + "fix", simply pass the desired song number minus 1 to the init + routine. + +2) The NTSC speed word is used *only* for NTSC tunes, or dual PAL/NTSC tunes. + The PAL speed word is used *only* for PAL tunes, or dual PAL/NTSC tunes. + +3) The length of the text in the name, artist, and copyright fields must + be 31 characters or less! There has to be at least a single NULL byte + (00h) after the text, between fields. + +4) If a field is not known (name, artist, copyright) then the field must + contain the string "" (without quotes). + +5) There should be 8K of RAM present at 6000-7FFFh. MMC5 tunes need RAM at + 5C00-5FF7 to emulate its EXRAM. 8000-FFFF Should be read-only (not + writable) after a tune has loaded. The only time this area should be + writable is if an FDS tune is being played. + +6) Do not assume the state of *anything* on entry to the init routine + except A and X. Y can be anything, as can the flags. + +7) Do not assume the state of *anything* on entry to the play routine either. + Flags, X, A, and Y could be at any state. I've fixed about 10 tunes + because of this problem and the problem, above. + +8) The stack sits at 1FFh and grows down. Make sure the tune does not + attempt to use 1F0h-1FFh for variables. (Armed Dragon Villigust did and + I had to relocate its RAM usage to 2xx) + +9) Variables should sit in the 0000h-07FFh area *only*. If the tune writes + outside this range, say 1400h this is bad and should be relocated. + (Terminator 3 did this and I relocated it to 04xx). + +That's it! + + + diff --git a/branches/fceux-2.2.2/documentation/tech/ppu/2c02 technical operation.txt b/branches/fceux-2.2.2/documentation/tech/ppu/2c02 technical operation.txt new file mode 100644 index 00000000..3a79008b --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/ppu/2c02 technical operation.txt @@ -0,0 +1,296 @@ +******************************* +*NTSC 2C02 technical operation* +******************************* +Brad Taylor (big_time_software@hotmail.com) + +1st release: Sept 25th, Y2K +2nd release: Jan 27th, 2K3 +3rd release: Feb 4th, 2K3 +4th release: Feb 19th, 2K3 + + + This document describes the low-level operation and technical details of the 2C02, the NES's PPU. In general, it contains important information in regards to PPU timing, which no NES coder/emulator author should be without. This document assumes that you already understand the basics of how the PPU works, like how the playfield/object images are generated, and the behaviour of scroll/address counters during playfield rendering. + + Alot of the concepts behind how the PPU works described here have been extracted from Nintendo's patent documentation (U.S.#4,824,106). With block diagrams of the PPU's architecture (and even some schematics), these papers will definetely aid in the comprehension of this complex device. + + Since the first release, this document has been given a major overhaul. Most sections of the document have been reworked, and new information has been added just about everywhere. If you've read the old version of this document before, I recommend that you read this new one in it's entirity; there's new information even in sections which may look like they haven't changed much. + + Topics discussed hereon are as follows. + + - Video signal generation + - PPU base timing + - Miscellanious PPU info + - PPU memory access cycles + - Frame rendering details + - Scanline rendering details + - In-range object evaluation + - Details of playfield render pipeline + - Details of object pattern fetch & render + - Extra cycle frames + - The MMC3's scanline counter + - PPU pixel priority quirk + - Graphical enhancements + + ++-------+ +|History| ++-------+ + On the weekend of Sept. 25th, Y2K, I setup an experiment with my NTSC NES MB & my PC so's I could RE the PPU's timing. What I did was (using a PC interface) analyse the changes that occur on the PPU's address and data pins on every rising & falling edge of the PPU's clock. I was not planning on removing the PPU from the motherboard (yet), so basically I just kept everything intact (minus the stuff I added onto the MB so I could monitor the PPU's signals), and popped in a game, so that it would initialize the PPU for me (I used DK classics, since it was only taking somthing like 4 frames before it was turning on the background/sprites). + + The only change I made was taking out the 21 MHz clock generator circuitry. To replace the clock signal, I connected a port controlled latch to the NES's main clock line instead. Now, by writing a 0 or a 1 out to an PC ISA port of my choice (I was using $104), I was able to control the 21 MHz clockline of the NES. After I would create a rise or a fall on the NES's clock line, I would then read in the data that appeared on the PPU's address and data pins, which included monitoring what PPU registers the game read/wrote to (& the data that was read/written). + + ++-----------------------+ +|Video signal generation| ++-----------------------+ + A 21.48 MHz clock signal is fed into the PPU. This is the NES's main clock line, which is shared by the CPU. + + Inside the PPU, the 21.48 MHz signal is used to clock a three-stage Johnson counter. The complimentery outputs of both master and slave portions of each stage are used to form 12 mutually exclusive output phases- all 3.58 MHz each (the NTSC colorburst). These 12 different phases form the basis of all color generation for the PPU's composite video output. + + Naturally, when the user programs the lower 4-bits of a palette register, they are essentially selecting any 1 of 12 phases to be routed to the PPU's video out pin (this corresponds to chrominance (tint/hue) video information) when the appropriate pixel indexes it. Other chrominance combinations (0 & 13) are simply hardwired to a 1 or 0 to generate grayscale pixels. + + Bits 4 & 5 of a palette entry selects 1 of 4 linear DC voltage offsets to apply to the selected chrominance signal (this corresponds to luminance (brightness) video information) for a pixel. + + Chrominance values 14 & 15 yield a black pixel color, regardless of any luminance value setting. + + Luminance value 0, mixed with chrominance value 13 yield a "blacker than black" pixel color. This super black pixel has an output voltage level close to the vertical/horizontal syncronization pulses. Because of this, some video monitors will display warped/distorted screens for games which use this color for black (Game Genie is the best example of this). Essentially what is happening is the video monitor's horizontal timing is compromised by what it thinks are extra syncronization pulses in the scanline. This is not damaging to the monitors which are effected by it, but use of the super black color should be avoided, due to the graphical distortion it causes. + + The amplitude of the selected chrominance signal (via the 4 lower bits of a palette register) remain constant regardless of bits 4 or 5. Thus it is not possible to adjust the saturation level of a particular color. + + ++---------------+ +|PPU base timing| ++---------------+ + Other than the 3-stage Johnson counter, the 21.48 MHz signal is not used directly by any other PPU hardware. Instead, the signal is divided by 4 to get 5.37 MHz, and is used as the smallest unit of timing in the PPU. All following references to PPU clock cycle (abbr. "cc") timing in this document will be in respect to this timing base, unless otherwise indicated. + + - Pixels are rendered at the same rate as the base PPU clock. In other words, 1 clock cycle= 1 pixel. + + - 341 PPU cc's make up the time of a typical scanline (or 341/3 CPU cc's). + + - One frame consists of 262 scanlines. This equals 341*262 PPU cc's per frame (divide by 3 for # of CPU cc's). + + ++------------------------+ +|PPU memory access cycles| ++------------------------+ + All PPU memory access cycles are 2 clocks long, and can be made back-to-back (typically done during rendering). Here's how the access breaks down: + + At the beginning of the access cycle, PPU address lines 8..13 are updated with the target address. This data remains here until the next time an access cycle occurs. + + The lower 8-bits of the PPU address lines are multiplexed with the data bus, to reduce the PPU's pin count. On the first clock cycle of the access, A0..A7 are put on the PPU's data bus, and the ALE (address latch enable) line is activated for the first half of the cycle. This loads the lower 8-bit address into an external 8-bit transparent latch strobed by ALE (74LS373 is used). + + On the second clock cycle, the /RD (or /WR) line is activated, and stays active for the entire cycle. Appropriate data is driven onto the bus during this time. + + ++----------------------+ +|Miscellanious PPU info| ++----------------------+ + - Sprite DMA is 1536 clock cycles long (512 CPU cc's). 256 individual transfers are made from CPU memory to a temp register inside the CPU, then from the CPU's temp reg, to $2004. + + - The PPU makes NO external access to the PPU bus, unless the playfield or objects are enabled during a scanline outside vblank. This means that the PPU's address and data busses are dead while in this state. + + - palette RAM is accessed internally during playfield rendering (i.e., the palette address/data is never put on the PPU bus during this time). Additionally, when the programmer accesses palette RAM via $2006/7, the palette address accessed actually does show up on the PPU address bus, but the PPU's /RD & /WR flags are not activated. This is required; to prevent writing over name table data falling under the approprite mirrored area (since the name table RAM's address decoder simply consists of an inverter connected to the A13 line- effectively decoding all addresses in $2000-$3FFF). + + - the VINT impulse (NMI) and bit $2002.7 are set simultaniously. Reading $2002 will reset bit 7, but it seems that the VINT flag goes down on it's own. Because of this, when the PPU generates a VINT, it doesn't require any acknowledgement whatsoever; it will continue firing off VINTs, regardless of inservice to $2002. The only way to stop VINTs is to clear $2000.7. + + - Because the PPU cannot make a read from PPU memory immediately upon request (via $2007), there is an internal buffer, which acts as a 1-stage data pipeline. As a read is requested, the contents of the read buffer are returned to the NES's CPU. After this, at the PPU's earliest convience (according to PPU read cycle timings), the PPU will fetch the requested data from the PPU memory, and throw it in the read buffer. Writes to PPU mem via $2007 are pipelined as well, but it is unknown to me if the PPU uses this same buffer (this could be easily tested by writing somthing to $2007, and seeing if the same value is returned immediately after reading). + + ++-----------------------+ +|Frame rendering details| ++-----------------------+ + The following describes the PPU's status during all 262 scanlines of a frame. Any scanlines where work is done (like image rendering), consists of the steps which will be described in the next section. + + 0..19: Starting at the instant the VINT flag is pulled down (when a NMI is generated), 20 scanlines make up the period of time on the PPU which I like to call the VINT period. During this time, the PPU makes no access to it's external memory (i.e. name / pattern tables, etc.). + + 20: After 20 scanlines worth of time go by (since the VINT flag was set), the PPU starts to render scanlines. This first scanline is a dummy one; although it will access it's external memory in the same sequence it would for drawing a valid scanline, no on-screen pixels are rendered during this time, making the fetched background data immaterial. Both horizontal *and* vertical scroll counters are updated (presumably) at cc offset 256 in this scanline. Other than that, the operation of this scanline is identical to any other. The primary reason this scanline exists is to start the object render pipeline, since it takes 256 cc's worth of time to determine which objects are in range or not for any particular scanline. + + 21..260: after rendering 1 dummy scanline, the PPU starts to render the actual data to be displayed on the screen. This is done for 240 scanlines, of course. + + 261: after the very last rendered scanline finishes, the PPU does nothing for 1 scanline (i.e. the programmer gets screwed out of perfectly good VINT time). When this scanline finishes, the VINT flag is set, and the process of drawing lines starts all over again. + + ++--------------------------+ +|Scanline rendering details| ++--------------------------+ + Naturally, the PPU will fetch data from name, attribute, and pattern tables during a scanline to produce an image on the screen. This section details the PPU's doings during this time. + + As explained before, external PPU memory can be accessed every 2 cc's. With 341 cc's per scanline, this gives the PPU enough time to make 170 memory accesses per scanline (and it uses all of them!). After the 170th fetch, the PPU does nothing for 1 clock cycle. Remember that a single pixel is rendered every clock cycle. + + + Memory fetch phase 1 thru 128 + ----------------------------- + 1. Name table byte + 2. Attribute table byte + 3. Pattern table bitmap #0 + 4. Pattern table bitmap #1 + + This process is repeated 32 times (32 tiles in a scanline). + + + This is when the PPU retrieves the appropriate data from PPU memory for rendering the playfield. The first playfield tile fetched here is actually the 3rd to be drawn on the screen (the playfield data for the first 2 tiles to be rendered on this scanline are fetched at the end of the scanline prior to this one). + + All valid on-screen pixel data arrives at the PPU's video out pin during this time (256 clocks). For determining the precise delay between when a tile's bitmap fetch phase starts (the whole 4 memory fetches), and when the first pixel of that tile's bitmap data hits the video out pin, the formula is (16-n) clock cycles, where n is the fine horizontal scroll offset (0..7 pixels). This information is relivant for understanding the exact timing operation of the "object 0 collision" flag. + + Note that the PPU fetches an attribute table byte for every 8 sequential horizontal pixels it draws. This essentially limits the PPU's color area (the area of pixels which are forced to use the same 3-color palette) to only 8 horizontally sequential pixels. + + It is also during this time that the PPU evaluates the "Y coordinate" entries of all 64 objects in object attribute RAM (OAM), to see if the objects are within range (to be drawn on the screen) for the *next* scanline (this is why Y-coordinate entries in the OAM must be programmed to a value 1 less than the scanline the object is to appear on). Each evaluation (presumably) takes 4 clock cycles, for a total of 256 (which is why it's done during on-screen pixel rendering). + + + In-range object evaluation + -------------------------- + An 8-bit comparator is used to calculate the 9-bit difference between the current scanline (minus 21), and each Y-coordinate (plus 1) of every object entry in the OAM. Objects are considered in range if the comparator produces a difference in the range of 0..7 (if $2000.5 currently = 0), or 0..15 (if $2000.5 currently = 1). + + (Note that a 9-bit comparison result is generated. This means that setting object scanline coordinates for ranges -1..-15 are actually interpreted as ranges 241..255. For this reason, objects with these ranges will never be considered to be part of any on-screen scanline range, and will not allow smooth object scrolling off the top of the screen.) + + Tile index (8 bits), X-coordinate (8 bits), & attribute information (4 bits; vertical inversion is excluded) from the in-range OAM element, plus the associated 4-bit result of the range comparison accumulate in a part of the PPU called the "sprite temporary memory". Logical inversion is applied to the loaded 4-bit range comparison result, if the object's vertical inversion attribute bit is set. + + Since object range evaluations occur sequentially through the OAM (starting from entry 0 to 63), the sprite temporary memory always fills in order from the highest priority in-range object, to lower ones. A 4-bit "in-range" counter is used to determine the number of found objects on the scanline (from 0 up to 8), and serves as an index pointer for placement of found object data into the 8-element sprite temporary memory. The counter is reset at the beginning of the object evaluation phase, and is post-incremented everytime an object is found in-range. This occurs until the counter equals 8, when found object data after this is discarded, and a flag (bit 5 of $2002) is raised, indicating that it is going to be dropping objects for the next scanline. + + An additional memory bit associated with the sprite temporary memory is used to indicate that the primary object (#0) was found to be in range. This will be used later on to detect primary object-to-playfield pixel collisions. + + + Playfield render pipeline details + --------------------------------- + As pattern table & palette select data is fetched, it is loaded into internal latches (the palette select data is selected from the fetched byte via a 2-bit 1-of-4 selector). + + At the start of a new tile fetch phase (every 8 cc's), both latched pattern table bitmaps are loaded into the upper 8-bits of 2- 16-bit shift registers (which both shift right every clock cycle). The palette select data is also transfered into another latch during this time (which feeds the serial inputs of 2 8-bit right shift registers shifted every clock). The pixel data is fed into these extra shift registers in order to implement fine horizontal scrolling, since the periods when the PPU fetch tile data is fixed. + + A single bit from each shift register is selected, to form the valid 4-bit playfield pixel for the current clock cycle. The bit selection offset is based on the fine horizontal scroll value (this selects bit positions 0..7 for all 4 shift registers). The selected 4-bit pixel data will then be fed into the multiplexer (described later) to be mixed with object data. + + + Memory fetch phase 129 thru 160 + ------------------------------- + 1. Garbage name table byte + 2. Garbage name table byte + 3. Pattern table bitmap #0 for applicable object (for next scanline) + 4. Pattern table bitmap #1 for applicable object (for next scanline) + + This process is repeated 8 times. + + + This is the period of time when the PPU retrieves the appropriate pattern table data for the objects to be drawn on the *next* scanline. When less than 8 objects exist on the next scanline (as the in-range object evaluation counter indicates), dummy pattern table fetches take place for the remaining fetches. Internally, the fetched dummy-data is discarded, and replaced with completely transparent bitmap patterns). + + Although the fetched name table data is thrown away, and the name table address is somewhat unpredictable, the address does seem to relate to the first name table tile to be fetched for the next scanline. This would seem to imply that PPU cc #256 is when the PPU's scroll/address counters have their horizontal scroll values automatically updated. + + It should also be noted that because this fetch is required for objects on the next scanline, it is neccessary for a garbage scanline to exist prior to the very first scanline to be actually rendered, so that object attribute RAM entries can be evaluated, and the appropriate bitmap data retrieved. + + As far as the wasted fetch phases here, well, what can I say. Either Nintendo's engineers were VERY lazy, and didn't want to add the small amount of extra circuitry to the PPU so that 16 object fetches could take place per scanline, or Nintendo couldn't spot the extra memory required to implement 16 object scanlines. Thing is though- between the object attribute mem, sprite temporary & buffer mem, and palette mem, that's already 2406 bits of RAM; I don't think it would've killed them to just add the 408 bits it would've took for an extra 8 objects, which would've made games with horrible OAM cycling (Double Dragon 2 w/ 2 players) look half-decent (hell, with 16 object scanlines, games would hardly even need OAM cycling). + + + Details of object pattern fetch & render + ---------------------------------------- + Where the PPU fetches pattern table data for an individual object is conditioned on the contents of the sprite temporary memory element, and $2000.5. If $2000.5 = 0, the tile index data is used as usual, and $2000.3 selects the pattern table to use. If $2000.5 = 1, the MSB of the range result value become the LSB of the indexed tile, and the LSB of the tile index value determines pattern table selection. The lower 3 bits of the range result value are always used as the fine vertical offset into the selected pattern. + + Horizontal inversion (bit order reversing) is applied to fetched bitmaps, if indicated in the sprite temporary memory element. + + The fetched pattern table data (which is 2 bytes), plus the associated 3 attribute bits (palette select & priority), and the x coordinate byte in sprite temporary memory are then loaded into a part of the PPU called the "sprite buffer memory" (the primary object present bit is also copied). This memory area again, is large enough to hold the contents for 8 sprites. + + The composition of one sprite buffer element here is: 2 8-bit shift registers (the fetched pattern table data is loaded in here, where it will be serialized at the appropriate time), a 3-bit latch (which holds the color & priority data for an object), and an 8-bit down counter (this is where the x coordinate is loaded). + + The counter is decremented every time the PPU renders a pixel (the first 256 cc's of a scanline; see "Memory fetch phase 1 thru 128" above). When the counter equals 0, the pattern table data in the shift registers will start to serialize (1 shift per clock). Before this time, or 8 clocks after, consider the outputs of the serializers for each stage to be 0 (transparency). + + The streams of all 8 object serializers are prioritized, and ultimately only one stream (with palette select & priority information) is selected for output to the multiplexer (where object & playfield pixels are prioritized). + + The data for the first sprite buffer entry (including the primary object present flag) has the first chance to enter the multiplexer, if it's output pixel is non-transparent (non-zero). Otherwise, priority is passed to the next serializer in the sprite buffer memory, and the test for non-transparency is made again (the primary object present status will always be passed to the multiplexer as false in this case). This is done until the last (8th) stage is reached, when the object data is passed through unconditionally. Keep in mind that this whole process occurs every clock cycle (hardware is used to determine priority instantly). + + The multiplexer does 2 things: determines primary object collisions, and decides which pixel data to pass through to index the palette RAM- either the playfield's or the object's. + + Primary object collisions occur when a non-transparent playfield pixel coincides with a non-transparent object pixel, while the primary object present status entering the multiplexer for the current clock cycle is true. This causes a flip-flop ($2002.6) to be set, and remains set (presumably) some time after the VINT occurence (prehaps up until scanline 20?). + + The decision for selecting the data to pass through to the palette index is made rather easilly. The condition to use object (opposed to playfield) data is: + + (OBJpri=foreground OR PFpixel=xparent) AND OBJpixel<>xparent + + Since the PPU has 2 palettes; one for objects, and one for playfield, the appropriate palette will be selected depending on which pixel data is passed through. + + After the palette look-up, the operation of events follows the aforementioned steps in the "video signal generation" section. + + + Memory fetch phase 161 thru 168 + ------------------------------- + 1. Name table byte + 2. Attribute table byte + 3. Pattern table bitmap #0 (for next scanline) + 4. Pattern table bitmap #1 (for next scanline) + + This process is repeated 2 times. + + + It is during this time that the PPU fetches the appliciable playfield data for the first and second tiles to be rendered on the screen for the *next* scanline. These fetches initialize the internal playfield pixel pipelines (2- 16-bit shift registers) with valid bitmap data. The rest of tiles (3..32) are fetched at the beginning of the following scanline. + + + Memory fetch phase 169 thru 170 + ------------------------------- + 1. Name table byte + 2. Name table byte + + + I'm unclear of the reason why this particular access to memory is made. The name table address that is accessed 2 times in a row here, is also the same nametable address that points to the 3rd tile to be rendered on the screen (or basically, the first name table address that will be accessed when the PPU is fetching playfield data on the next scanline). + + + After memory access 170 + ----------------------- + The PPU simply rests for 1 cycle here (or the equivelant of half a memory access cycle) before repeating the whole pixel/scanline rendering process. + + ++------------------+ +|Extra cycle frames| ++------------------+ + Scanline 20 is the only scanline that has variable length. On every odd frame, this scanline is only 340 cycles (the dead cycle at the end is removed). This is done to cause a shift in the NTSC colorburst phase. + + You see, a 3.58 MHz signal, the NTSC colorburst, is required to be modulated into a luminance carrying signal in order for color to be generated on an NTSC monitor. Since the PPU's video out consists of basically square waves (as opposed to sine waves, which would be preferred), it takes an entire colorburst cycle (1/3.58 MHz) for an NTSC monitor to identify the color of a PPU pixel accurately. + + But now you remember that the PPU renders pixels at 5.37 MHz- 1.5x the rate of the colorburst. This means that if a single pixel resides on a scanline with a color different to those surrounding it, the pixel will probably be misrepresented on the screen, sometimes appearing faintly. + + Well, to somewhat fix this problem, they added this extra pixel into every odd frame (shifting the colorburst phase over a bit), and changing the way the monitor interprets isolated colored pixels each frame. This is why when you play games with detailed background graphics, the background seems to flicker a bit. Once you start scrolling the screen however, it seems as if some pixels become invisible; this is how stationary PPU images would look without this cycle removed from odd frames. + + Certain scroll rates expose this NTSC PPU color caveat regardless of the toggling phase shift. Some of Zelda 2's dungeon backgrounds are a good place to see this effect. + + ++---------------------------+ +|The MMC3's scanline counter| ++---------------------------+ + As most people know, the MMC3 bases it's scanline counter on PPU address line A13 (which is why IRQ's can be fired off manually by toggling A13 a bunch of times via $2006). What's not common knowledge is the number of times A13 is expected to toggle in a scanline (although if you've been paying close attention to the doc here, you should already know ;) + + A13 was probably used for the IRQ counter (as opposed to using the PPU's /READ line) because this address line already needed to be connected to the MMC for bankswitching purposes (so in other words, to reduce the MMC3's pin count by 1). They also probably used this method of counting (as opposed to a CPU cycle counter) since A13 cycles (0 -> 1) exactly 42 times per scanline, whereas the CPU count of cycles per scanline is not an exact integer (113.67). Having said that, I guess Nintendo wanted to provide an "easy-to-use" method of generating special image effects, without making programmers have to figure out how many clock cycles to program an IRQ counter with (a pretty lame excuse for not providing an IRQ counter with CPU clock cycle precision (which would have been more useful and versatile)). + + Regardless of any values PPU registers are programmed with, A13 will operate in a predictable fashion during image rendering (and if you understand how PPU addressing works, you should understand that A13 is the *only* address line with fixed behaviour during image rendering). + + ++------------------------+ +|PPU pixel priority quirk| ++------------------------+ + Object data is prioritized between itself, then prioritized between the playfield. There are some odd side effects to this scheme of rendering, however. For instance, imagine a low priority object pixel with foreground priority, a high priority object pixel with background priority, and a playfield pixel all coinciding (all non-transparent). + + Ideally, the playfield is considered to be the middle layer between background and foreground priority objects. This means that the playfield pixel should hide the background priority object pixel (regardless of object priority), and the foreground priority object should appear atop the PF pixel. + + However, because of the way the PPU renders (as just described), OBJ priority is evaluated first, and therefore the background object pixel wins, which means that you'll only be seeing the PF pixel after this mess. + + A good game to demonstrate this behaviour is Megaman 2. Go into airman's stage. First, jump into the energy bar, just to confirm that megaman's sprite is of a higher priority than the energy bar's. Now, get to the second half of the stage, where the clouds cover the energy bar. The energy bar will be ontop of the clouds, but megaman will be behind them. Now, look what happens when you jump into the energy bar here... you see the clouds where megaman underlaps the energy bar. + + ++----------------------+ +|Graphical enhancements| ++----------------------+ + Since an NES cartridge has access to the PPU bus, any number of on-cart hardware schemes can be used to enhance the graphic capabilities of the NES. After all, the PPU's playfield pipeline is very simple: it fetches 272 playfield pixels per scanline (as 34*2 byte fetches, in real-time), and outputs 256 of them to the screen (with the 0..7 pixel offset determined by the fine X scroll register), along with object data combined with it. + + Essentially, you can bypass the PPU's simple scrolling system, implement a custom one on your cart (fetching bitmap data in your own fashion), and feed the PPU bitmap data in your own order. + + The possibilities of this are endless (like sporting multiple playfields, or even playfield rotation/scaling), but of course what it comes down to is the amount of cartridge hardware required. + + Generally, playfield rotation/scaling can be done quite easily- it only requires a few sets of 16-bit registers and adders (the 16 bits are broken up into 8.8 fixed point values). But this kind of implementation is more suited for an integrated circuit, since this would require dozens of discrete logic chips. + + Multiple playfields are another thing which could be easily done. The caveat here is that pixel pipelines (i.e., shift registers) and a multiplexer would have to be implemented on the cart (not to mention exclusive name table RAM) in order to process the playfield bitmaps from multiple sources. The access to the CHR-ROM/RAM would also have to increased- but as it stands, the CHR-ROM/RAM bandwidth is 1.34 MHz, a rather low frequency. With a memory device capable of a 10.74 MHz bandwith, you could have 8 playfields to work with. Generally, this would be very useful for displaying multiple huge objects on the screen- without ever having to worry about annoying flicker. + + The only restriction to doing any of this is that: + + - every 8 sequential horizontal pixels sent to the PPU must share the same palette select value. Because of this, hardware would have to be implemented to decide which palette select value to feed the PPU between 8 horizontally sequential pixels, if they do not all share the same palette select value. The on-screen results of this may not be too flattering sometimes, but this is a small price to pay to do some neat graphical tricks on the NES. + + -only the playfield palette can be used. As usual, this pretty much limits your randomly accessable colors to about 12+1. + + It's a damn shame that Nintendo never created a MMC which would enhance graphics on the NES in useful ways as mentioned above. The MMC5 was the only device that came close, and it's only selling features were the single-tile color area, and the vertical split screen mode (which I don't think any game ever used). Considering the amount of pins (100) the MMC5 had, and number of gates they put in it just for the EXRAM (which was 1K bytes), they could've put some really useful graphics hardware inside there instead. + + Prehaps the infamous Color Dreams "Hellraiser" cart was the closest the NES ever came to seeing such sophisticated graphics. The cart was never released, but from what I've read, it was going to use some sort of frame buffer, and a Z80 CPU to do the graphical rendering. It had been rumored that the game had 3D graphics (or at least 2.5D) in it. If so (and the game was actually good), prehaps it would have raised a few eyebrows in the industry, and inspired Nintendo to develop a new MMC chip with similar capabilities, in order to keep the NES in it's profit margin for another few years (and allow it to compete somewhat with the more advanced systems of the time). + +EOF \ No newline at end of file diff --git a/branches/fceux-2.2.2/documentation/tech/ppu/loopy1.txt b/branches/fceux-2.2.2/documentation/tech/ppu/loopy1.txt new file mode 100644 index 00000000..bda6d852 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/ppu/loopy1.txt @@ -0,0 +1,63 @@ +Subject: [nesdev] the skinny on nes scrolling +Date: Tue, 13 Apr 1999 16:42:00 -0600 +From: loopy +Reply-To: nesdev@onelist.com +To: nesdev@onelist.com + +From: loopy + +--------- +the current information on background scrolling is sufficient for most games; +however, there are a few that require a more complete understanding. + +here are the related registers: + (v) vram address, a.k.a. 2006 which we all know and love. (16 bits) + (t) another temp vram address (16 bits) + (you can really call them 15 bits, the last isn't used) + (x) tile X offset (3 bits) + +the ppu uses the vram address for both reading/writing to vram thru 2007, +and for fetching nametable data to draw the background. as it's drawing the +background, it updates the address to point to the nametable data currently +being drawn. bits 0-11 hold the nametable address (-$2000). bits 12-14 are +the tile Y offset. + +--------- +stuff that affects register contents: +(sorry for the shorthand logic but i think it's easier to see this way) + +2000 write: + t:0000110000000000=d:00000011 +2005 first write: + t:0000000000011111=d:11111000 + x=d:00000111 +2005 second write: + t:0000001111100000=d:11111000 + t:0111000000000000=d:00000111 +2006 first write: + t:0011111100000000=d:00111111 + t:1100000000000000=0 +2006 second write: + t:0000000011111111=d:11111111 + v=t +scanline start (if background and sprites are enabled): + v:0000010000011111=t:0000010000011111 +frame start (line 0) (if background and sprites are enabled): + v=t + +note! 2005 and 2006 share the toggle that selects between first/second +writes. reading 2002 will clear it. + +note! all of this info agrees with the tests i've run on a real nes. BUT +if there's something you don't agree with, please let me know so i can verify +it. + +________________________________________________________ +NetZero - We believe in a FREE Internet. Shouldn't you? +Get your FREE Internet Access and Email at +http://www.netzero.net/download.html + +------------------------------------------------------------------------ +New hobbies? New curiosities? New enthusiasms? +http://www.ONElist.com +Sign up for a new e-mail list today! diff --git a/branches/fceux-2.2.2/documentation/tech/ppu/loopy2.txt b/branches/fceux-2.2.2/documentation/tech/ppu/loopy2.txt new file mode 100644 index 00000000..7a4585e1 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/ppu/loopy2.txt @@ -0,0 +1,33 @@ +Subject: [nesdev] Re: the skinny on nes scrolling +Date: Tue, 13 Apr 1999 17:48:54 -0600 +From: loopy +Reply-To: nesdev@onelist.com +To: nesdev@onelist.com + +From: loopy + +(more notes on ppu logic) + +you can think of bits 0,1,2,3,4 of the vram address as the "x scroll"(*8) +that the ppu increments as it draws. as it wraps from 31 to 0, bit 10 is +switched. you should see how this causes horizontal wrapping between name +tables (0,1) and (2,3). + +you can think of bits 5,6,7,8,9 as the "y scroll"(*8). this functions +slightly different from the X. it wraps to 0 and bit 11 is switched when +it's incremented from _29_ instead of 31. there are some odd side effects +from this.. if you manually set the value above 29 (from either 2005 or +2006), the wrapping from 29 obviously won't happen, and attrib data will be +used as name table data. the "y scroll" still wraps to 0 from 31, but +without switching bit 11. this explains why writing 240+ to 'Y' in 2005 +appeared as a negative scroll value. + +________________________________________________________ +NetZero - We believe in a FREE Internet. Shouldn't you? +Get your FREE Internet Access and Email at +http://www.netzero.net/download.html + +------------------------------------------------------------------------ +Looking for a new hobby? Want to make a new friend? +http://www.ONElist.com +Come join one of the 115,000 e-mail communities at ONElist! diff --git a/branches/fceux-2.2.2/documentation/tech/readme.now b/branches/fceux-2.2.2/documentation/tech/readme.now new file mode 100644 index 00000000..4575e0c6 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/readme.now @@ -0,0 +1,6 @@ +Many(possibly all) of these documents contain flaws or are incomplete, so +don't pull out your hair if there are inconsistencies between the documents, +what's in FCE Ultra, and what you observe. That's not to say that FCE Ultra +doesn't have its share of (emulation) flaws, though... + +For many more NES-related documents, try http://nesdev.parodius.com diff --git a/branches/fceux-2.2.2/documentation/tech/readme.sound b/branches/fceux-2.2.2/documentation/tech/readme.sound new file mode 100644 index 00000000..cce95040 --- /dev/null +++ b/branches/fceux-2.2.2/documentation/tech/readme.sound @@ -0,0 +1,2 @@ +Sound information is in the "cpu" subdirectory, due to the intimate +relationship between the sound circuitry and the cpu. diff --git a/branches/fceux-2.2.2/documentation/todo b/branches/fceux-2.2.2/documentation/todo new file mode 100644 index 00000000..5a1131dd --- /dev/null +++ b/branches/fceux-2.2.2/documentation/todo @@ -0,0 +1,70 @@ +The following games are broken to some extent: + +Crystalis: Mostly working, but the screen jumps around during + dialogue. It apparently resets the MMC3 IRQ counter + mid-scanline. It'll require low-level PPU and MMC3 + IRQ counter emulation to function properly. +Kyoro Chan Land: Expects a sprite hit to happen, but it has sprite 0 over + transparent background. + +*** First, things that are not on the TODO list(Don't bug me about these + things if you're an idiot. I don't like listening to idiots. + If you are not an idiot, and you can make decent arguments for why + these should be on the TODO list, then you can bug me.). + +*** General Features: + + Remappable command keys(to multiple keys on the keyboard and a joystick). + + Fix possible UNIF crashes(if no PRGx or CHRx chunks exist, it may crash, + due to changes made in 0.92). + + Windows Port: + Support for command-line options(so that one crazy guy will quit bugging + me). + + SDL Port: + Hotkey remap GUI + + Figure out a good way to add "turbo" button support and then do it. + + Make default svgalib video mode a non-tweaked VGA mode. + + Finish the software video blitting "library", add support for 2xsai, eagle, + interpolation, etc. effects. + + +*** Emulation: + + + ***IMPORTANT*** + If anyone ever cares to implement movie recording/playback, we must figure + out what to do with some unsaved variables, like timestamp and timestampbase. + These variables are abused in the sound emulation code, and modifying them + in certain ways elsewhere can cause crashes. + ***IMPORTANT*** + + Implement cart-based expansion devices, and interfaces for them(dip switches + and that Datach barcode reader, and maybe others). + + Fix DPCM playback and IRQ at end of playback. + + Fix some 6502 emulation bugs(undocumented opcodes might not be implemented + correctly and I'm not sure if the IRQ flag latency is implemented correctly). + + Implement more dummy CPU reads when in debug mode. + + Fix MMC3 IRQ emulation. + + Figure out correct timing for when the PPU refresh address register is + updated by the PPU(for the next scanline). + + Sound frame count stuff on PAL games(is it correct?). + + Fix FDS sound emulation. + + Fix NMI timing and D7 of 2002 setting timing. Fixing this might require + a small hack. Also be aware that this might break Battletoads, particularly + during the second level. + + Fix Zapper emulation(Chiller still doesn't always work correctly). diff --git a/branches/fceux-2.2.2/doxygen b/branches/fceux-2.2.2/doxygen new file mode 100644 index 00000000..580671e2 --- /dev/null +++ b/branches/fceux-2.2.2/doxygen @@ -0,0 +1,1237 @@ +# Doxyfile 1.4.6 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = docs + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = src src/boards src/drivers/common src/drivers/win src/drivers/sdl src/input src/utils + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = *.cpp *.h *.c *.inc + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = YES + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/branches/fceux-2.2.2/fceux-server/.gitignore b/branches/fceux-2.2.2/fceux-server/.gitignore new file mode 100644 index 00000000..674deb69 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/.gitignore @@ -0,0 +1,17 @@ +# A simulation of Subversion default ignores, generated by reposurgeon. +*.o +*.lo +*.la +*.al +*.libs +*.so +*.so.[0-9]* +*.a +*.pyc +*.pyo +*.rej +*~ +*.#* +.*.swp +.DS_store +# Simulated Subversion default ignores end here diff --git a/branches/fceux-2.2.2/fceux-server/AUTHORS b/branches/fceux-2.2.2/fceux-server/AUTHORS new file mode 100644 index 00000000..0888cb48 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/AUTHORS @@ -0,0 +1,2 @@ +Major developer: Xodnizel +Interface changes and all releases past 0.0.3: Lukas Sabota diff --git a/branches/fceux-2.2.2/fceux-server/COPYING b/branches/fceux-2.2.2/fceux-server/COPYING new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/COPYING @@ -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/branches/fceux-2.2.2/fceux-server/ChangeLog b/branches/fceux-2.2.2/fceux-server/ChangeLog new file mode 100644 index 00000000..89dde3c4 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/ChangeLog @@ -0,0 +1,30 @@ +0.0.5: + Interface received massive overhaul. Now takes command line + options. This will allow the server to communicate with + other front-ends. Integration can now occur in gfceu. + +0.0.4: + Renamed from "server" to "fceu-server". + Renamed standard.conf -> fceu-standard.conf + If no configuration file is specified, look in /etc and ./ + Added a --help option. + Added GPL headers + +0.0.3: + Error messages during server startup are more verbose(slightly). + + Fixed initialization of the sockaddr_in structure, sin_family + member. It's now initialized to AF_INET before calling bind(). + While not initializing that member seemed to work ok on + Linux 2.4, it won't work on Linux 2.2 and under Cygwin, + and possibly other environments. + +0.0.2: + Switched to using fcntl() to set the socket to nonblocking, + so I don't need to use MSG_NOWAIT in send() anymore, which is + undefined under Cygwin. + + Added a "clean" Makefile target. + +0.0.1: + First Release diff --git a/branches/fceux-2.2.2/fceux-server/Makefile b/branches/fceux-2.2.2/fceux-server/Makefile new file mode 100644 index 00000000..02d07f07 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/Makefile @@ -0,0 +1,20 @@ +PREFIX = /usr +OUTFILE = fceux-net-server + +CC = g++ +OBJS = server.o md5.o throttle.o + + +all: ${OBJS} + ${CC} -o ${OUTFILE} ${OBJS} + +clean: + rm -f ${OUTFILE} ${OBJS} + +install: + install -m 755 -D fceux-net-server ${PREFIX}/bin/fceux-server + install -m 644 -D fceux-server.conf /etc/fceux-server.conf + +server.o: server.cpp +md5.o: md5.cpp +throttle.o: throttle.cpp diff --git a/branches/fceux-2.2.2/fceux-server/README b/branches/fceux-2.2.2/fceux-server/README new file mode 100644 index 00000000..d32988e5 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/README @@ -0,0 +1,53 @@ +FCE Ultra Network Play Server v0.0.5 +------------------------------------ + +To compile, type this in the shell: +$ make +To install, type this in this shell: +$ sudo make install +To run, type this in shell: +$ ./fceu-server + +To compile under MS Windows, you should use Cygwin. I'm not +going to change this server to use Win-old-dirty-smelly-sock natively. + +There are known issues with running fceux-server in mac OSX. As a (somewhat extensive) workaround, you can run the server inside a Linux VM in bridged network mode. + +If it doesn't compile, sell your to the +. + +Most beings can run it like "./fceu-server >logfile &". +Windows users can run it some other way. A batch file with absolute paths, perhaps? + snuggums.bat: + C:\somethingdirectory\server.exe c:\somethingdirectory\standard.conf + +With the default settings, each client should use about 65-70Kbps, excluding any +data transferred during chat, state loads, etc(which should be negligible, but limits +will be placed on these types of transfers in the future). + +Clients connecting with high-latency or slow links may use more bandwidth, or they +may use less bandwidth. I'm really not quite sure. If it concerns you, test it. + +Any client connecting over VERY high latency links, such as bidirectional satellite connections, +may find that attempting network play will lock up his/her connection for +several minutes. Right, Disch. ;) + +The server probably won't scale well to a huge number of clients connected at the same time. + +Bumping up the server's priority and running it on a low-latency kernel(preferably with +1 ms or smaller timeslices) should help make network play more usable if you're running the +network play server on an otherwise non-idle physical server. + + + +TODO: + +Implement a more flexible timing system, so that PAL games will be playable. + +Change the protocol to allow the client to specify the size of input update information, +so devices like the powerpad or zapper can work over network play. + +Send emulation info, such as NTSC/PAL, input devices, and Game Genie emulation at connect +time, to make it easier on end users. + + diff --git a/branches/fceux-2.2.2/fceux-server/cygwin1.dll b/branches/fceux-2.2.2/fceux-server/cygwin1.dll new file mode 100644 index 00000000..116037f1 Binary files /dev/null and b/branches/fceux-2.2.2/fceux-server/cygwin1.dll differ diff --git a/branches/fceux-2.2.2/fceux-server/dist/fceu-server-0.0.4.tar.gz b/branches/fceux-2.2.2/fceux-server/dist/fceu-server-0.0.4.tar.gz new file mode 100644 index 00000000..a7850742 Binary files /dev/null and b/branches/fceux-2.2.2/fceux-server/dist/fceu-server-0.0.4.tar.gz differ diff --git a/branches/fceux-2.2.2/fceux-server/dist/fceu-server-0.0.5.tar.gz b/branches/fceux-2.2.2/fceux-server/dist/fceu-server-0.0.5.tar.gz new file mode 100644 index 00000000..95269b77 Binary files /dev/null and b/branches/fceux-2.2.2/fceux-server/dist/fceu-server-0.0.5.tar.gz differ diff --git a/branches/fceux-2.2.2/fceux-server/dist/fceunetserver-0.0.3.tar.bz2 b/branches/fceux-2.2.2/fceux-server/dist/fceunetserver-0.0.3.tar.bz2 new file mode 100644 index 00000000..8d108224 Binary files /dev/null and b/branches/fceux-2.2.2/fceux-server/dist/fceunetserver-0.0.3.tar.bz2 differ diff --git a/branches/fceux-2.2.2/fceux-server/fceux-net-server.exe b/branches/fceux-2.2.2/fceux-server/fceux-net-server.exe new file mode 100644 index 00000000..780f6a47 Binary files /dev/null and b/branches/fceux-2.2.2/fceux-server/fceux-net-server.exe differ diff --git a/branches/fceux-2.2.2/fceux-server/fceux-server.conf b/branches/fceux-2.2.2/fceux-server/fceux-server.conf new file mode 100644 index 00000000..9c71a224 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/fceux-server.conf @@ -0,0 +1,5 @@ +maxclients 100 ; Maximum number of clients +connecttimeout 5 ; Connection(login) timeout +framedivisor 1 ; Frame divisor(eg: 60 / framedivisor updates per second) +port 4046 ; Port to listen on +;password sexybeef diff --git a/branches/fceux-2.2.2/fceux-server/md5.cpp b/branches/fceux-2.2.2/fceux-server/md5.cpp new file mode 100644 index 00000000..e00f8269 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/md5.cpp @@ -0,0 +1,266 @@ +/* FCE Ultra Network Play Server + * + * 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. + * */ + +/* + * RFC 1321 compliant MD5 implementation, + * by Christophe Devine ; + * this program is licensed under the GPL. + */ + +/* Modified October 3, 2003, to remove testing code, and add + include of "types.h". + + Added simple MD5 to ASCII string conversion function. + -Xodnizel +*/ + + + + +#include +#include "types.h" +#include "md5.h" + +#define GET_UINT32(n,b,i) \ +{ \ + (n) = ( (uint32) (b)[(i) + 3] << 24 ) \ + | ( (uint32) (b)[(i) + 2] << 16 ) \ + | ( (uint32) (b)[(i) + 1] << 8 ) \ + | ( (uint32) (b)[(i) ] ); \ +} + +#define PUT_UINT32(n,b,i) \ +{ \ + (b)[(i) ] = (uint8) ( (n) ); \ + (b)[(i) + 1] = (uint8) ( (n) >> 8 ); \ + (b)[(i) + 2] = (uint8) ( (n) >> 16 ); \ + (b)[(i) + 3] = (uint8) ( (n) >> 24 ); \ +} + +void md5_starts( struct md5_context *ctx ) +{ + ctx->total[0] = 0; + ctx->total[1] = 0; + ctx->state[0] = 0x67452301; + ctx->state[1] = 0xEFCDAB89; + ctx->state[2] = 0x98BADCFE; + ctx->state[3] = 0x10325476; +} + +void md5_process( struct md5_context *ctx, uint8 data[64] ) +{ + uint32 A, B, C, D, X[16]; + + GET_UINT32( X[0], data, 0 ); + GET_UINT32( X[1], data, 4 ); + GET_UINT32( X[2], data, 8 ); + GET_UINT32( X[3], data, 12 ); + GET_UINT32( X[4], data, 16 ); + GET_UINT32( X[5], data, 20 ); + GET_UINT32( X[6], data, 24 ); + GET_UINT32( X[7], data, 28 ); + GET_UINT32( X[8], data, 32 ); + GET_UINT32( X[9], data, 36 ); + GET_UINT32( X[10], data, 40 ); + GET_UINT32( X[11], data, 44 ); + GET_UINT32( X[12], data, 48 ); + GET_UINT32( X[13], data, 52 ); + GET_UINT32( X[14], data, 56 ); + GET_UINT32( X[15], data, 60 ); + +#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) + +#define P(a,b,c,d,k,s,t) \ +{ \ + a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \ +} + + A = ctx->state[0]; + B = ctx->state[1]; + C = ctx->state[2]; + D = ctx->state[3]; + +#define F(x,y,z) (z ^ (x & (y ^ z))) + + P( A, B, C, D, 0, 7, 0xD76AA478 ); + P( D, A, B, C, 1, 12, 0xE8C7B756 ); + P( C, D, A, B, 2, 17, 0x242070DB ); + P( B, C, D, A, 3, 22, 0xC1BDCEEE ); + P( A, B, C, D, 4, 7, 0xF57C0FAF ); + P( D, A, B, C, 5, 12, 0x4787C62A ); + P( C, D, A, B, 6, 17, 0xA8304613 ); + P( B, C, D, A, 7, 22, 0xFD469501 ); + P( A, B, C, D, 8, 7, 0x698098D8 ); + P( D, A, B, C, 9, 12, 0x8B44F7AF ); + P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); + P( B, C, D, A, 11, 22, 0x895CD7BE ); + P( A, B, C, D, 12, 7, 0x6B901122 ); + P( D, A, B, C, 13, 12, 0xFD987193 ); + P( C, D, A, B, 14, 17, 0xA679438E ); + P( B, C, D, A, 15, 22, 0x49B40821 ); + +#undef F + +#define F(x,y,z) (y ^ (z & (x ^ y))) + + P( A, B, C, D, 1, 5, 0xF61E2562 ); + P( D, A, B, C, 6, 9, 0xC040B340 ); + P( C, D, A, B, 11, 14, 0x265E5A51 ); + P( B, C, D, A, 0, 20, 0xE9B6C7AA ); + P( A, B, C, D, 5, 5, 0xD62F105D ); + P( D, A, B, C, 10, 9, 0x02441453 ); + P( C, D, A, B, 15, 14, 0xD8A1E681 ); + P( B, C, D, A, 4, 20, 0xE7D3FBC8 ); + P( A, B, C, D, 9, 5, 0x21E1CDE6 ); + P( D, A, B, C, 14, 9, 0xC33707D6 ); + P( C, D, A, B, 3, 14, 0xF4D50D87 ); + P( B, C, D, A, 8, 20, 0x455A14ED ); + P( A, B, C, D, 13, 5, 0xA9E3E905 ); + P( D, A, B, C, 2, 9, 0xFCEFA3F8 ); + P( C, D, A, B, 7, 14, 0x676F02D9 ); + P( B, C, D, A, 12, 20, 0x8D2A4C8A ); + +#undef F + +#define F(x,y,z) (x ^ y ^ z) + + P( A, B, C, D, 5, 4, 0xFFFA3942 ); + P( D, A, B, C, 8, 11, 0x8771F681 ); + P( C, D, A, B, 11, 16, 0x6D9D6122 ); + P( B, C, D, A, 14, 23, 0xFDE5380C ); + P( A, B, C, D, 1, 4, 0xA4BEEA44 ); + P( D, A, B, C, 4, 11, 0x4BDECFA9 ); + P( C, D, A, B, 7, 16, 0xF6BB4B60 ); + P( B, C, D, A, 10, 23, 0xBEBFBC70 ); + P( A, B, C, D, 13, 4, 0x289B7EC6 ); + P( D, A, B, C, 0, 11, 0xEAA127FA ); + P( C, D, A, B, 3, 16, 0xD4EF3085 ); + P( B, C, D, A, 6, 23, 0x04881D05 ); + P( A, B, C, D, 9, 4, 0xD9D4D039 ); + P( D, A, B, C, 12, 11, 0xE6DB99E5 ); + P( C, D, A, B, 15, 16, 0x1FA27CF8 ); + P( B, C, D, A, 2, 23, 0xC4AC5665 ); + +#undef F + +#define F(x,y,z) (y ^ (x | ~z)) + + P( A, B, C, D, 0, 6, 0xF4292244 ); + P( D, A, B, C, 7, 10, 0x432AFF97 ); + P( C, D, A, B, 14, 15, 0xAB9423A7 ); + P( B, C, D, A, 5, 21, 0xFC93A039 ); + P( A, B, C, D, 12, 6, 0x655B59C3 ); + P( D, A, B, C, 3, 10, 0x8F0CCC92 ); + P( C, D, A, B, 10, 15, 0xFFEFF47D ); + P( B, C, D, A, 1, 21, 0x85845DD1 ); + P( A, B, C, D, 8, 6, 0x6FA87E4F ); + P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); + P( C, D, A, B, 6, 15, 0xA3014314 ); + P( B, C, D, A, 13, 21, 0x4E0811A1 ); + P( A, B, C, D, 4, 6, 0xF7537E82 ); + P( D, A, B, C, 11, 10, 0xBD3AF235 ); + P( C, D, A, B, 2, 15, 0x2AD7D2BB ); + P( B, C, D, A, 9, 21, 0xEB86D391 ); + +#undef F + + ctx->state[0] += A; + ctx->state[1] += B; + ctx->state[2] += C; + ctx->state[3] += D; +} + +void md5_update( struct md5_context *ctx, uint8 *input, uint32 length ) +{ + uint32 left, fill; + + if( ! length ) return; + + left = ( ctx->total[0] >> 3 ) & 0x3F; + fill = 64 - left; + + ctx->total[0] += length << 3; + ctx->total[1] += length >> 29; + + ctx->total[0] &= 0xFFFFFFFF; + ctx->total[1] += ctx->total[0] < ( length << 3 ); + + if( left && length >= fill ) + { + memcpy( (void *) (ctx->buffer + left), (void *) input, fill ); + md5_process( ctx, ctx->buffer ); + length -= fill; + input += fill; + left = 0; + } + + while( length >= 64 ) + { + md5_process( ctx, input ); + length -= 64; + input += 64; + } + + if( length ) + { + memcpy( (void *) (ctx->buffer + left), (void *) input, length ); + } +} + +static uint8 md5_padding[64] = +{ + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +void md5_finish( struct md5_context *ctx, uint8 digest[16] ) +{ + uint32 last, padn; + uint8 msglen[8]; + + PUT_UINT32( ctx->total[0], msglen, 0 ); + PUT_UINT32( ctx->total[1], msglen, 4 ); + + last = ( ctx->total[0] >> 3 ) & 0x3F; + padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); + + md5_update( ctx, md5_padding, padn ); + md5_update( ctx, msglen, 8 ); + + PUT_UINT32( ctx->state[0], digest, 0 ); + PUT_UINT32( ctx->state[1], digest, 4 ); + PUT_UINT32( ctx->state[2], digest, 8 ); + PUT_UINT32( ctx->state[3], digest, 12 ); +} + + +/* Uses a static buffer, so beware of how it's used. */ +char *md5_asciistr(uint8 digest[16]) +{ + static char str[33]; + static char trans[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; + int x; + + for(x=0;x<16;x++) + { + str[x*2]=trans[digest[x]&0x0F]; + str[x*2+1]=trans[digest[x]>>4]; + } + return(str); +} diff --git a/branches/fceux-2.2.2/fceux-server/md5.h b/branches/fceux-2.2.2/fceux-server/md5.h new file mode 100644 index 00000000..10501e95 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/md5.h @@ -0,0 +1,37 @@ +/* FCE Ultra Network Play Server + * + * + * 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 _MD5_H +#define _MD5_H + +struct md5_context +{ + uint32 total[2]; + uint32 state[4]; + uint8 buffer[64]; +}; + +void md5_starts( struct md5_context *ctx ); +void md5_update( struct md5_context *ctx, uint8 *input, uint32 length ); +void md5_finish( struct md5_context *ctx, uint8 digest[16] ); + +/* Uses a static buffer, so beware of how it's used. */ +char *md5_asciistr(uint8 digest[16]); + +#endif /* md5.h */ diff --git a/branches/fceux-2.2.2/fceux-server/server.cpp b/branches/fceux-2.2.2/fceux-server/server.cpp new file mode 100644 index 00000000..116e8f49 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/server.cpp @@ -0,0 +1,915 @@ +/* FCE Ultra Network Play Server + * + * Copyright notice for this file: + * Copyright (C) 2004 Xodnizel + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "types.h" +#include "md5.h" +#include "throttle.h" + +#define VERSION "0.0.5" +#define DEFAULT_PORT 4046 +#define DEFAULT_MAX 100 +#define DEFAULT_TIMEOUT 5 +#define DEFAULT_FRAMEDIVISOR 1 +#define DEFAULT_CONFIG "/etc/fceux-server.conf" + +// MSG_NOSIGNAL and SOL_TCP have been depreciated on osx +#if defined (__APPLE__) || defined(BSD) +#define MSG_NOSIGNAL SO_NOSIGPIPE +#define SOL_TCP IPPROTO_TCP +#endif + +typedef struct { + uint32 id; /* mainly for faster referencing when pointed to from the Games + entries. + */ + char *nickname; + int TCPSocket; + void *game; /* Pointer to the game this player is in. */ + int localplayers; /* The number of local players, 1-4 */ + + time_t timeconnect; /* Time the client made the connection. */ + + /* Variables to handle non-blocking TCP reads. */ + uint8 *nbtcp; + uint32 nbtcphas, nbtcplen; + uint32 nbtcptype; +} ClientEntry; + +typedef struct +{ + uint8 id[16]; /* Unique 128-bit identifier for this game session. */ + uint8 joybuf[5]; /* 4 player data + 1 command byte */ + int MaxPlayers; /* Maximum players for this game */ + ClientEntry *Players[4]; /* Pointers to player data. */ + int IsUnique[4]; /* Set to 1 if player is unique client, 0 + if it's a duplicated entry to handle multiple players + per client. + */ + uint8 ExtraInfo[64]; /* Expansion information to be used in future versions + of FCE Ultra. + */ +} GameEntry; + +typedef struct +{ + unsigned int MaxClients; /* The maximum number of clients to allow. */ + /* You should expect each client to use + 65-70Kbps(not including save state loads) while + connected(and logged in), when using the default + FrameDivisor value of 1. + */ + unsigned int ConnectTimeout; /* How long to wait(in seconds) for the client to provide + login data before disconnecting the client. + */ + unsigned int FrameDivisor; /* The number of updates per second are divided + by this number. 1 = 60 updates/sec(approx), + 2 = 30 updates/sec, etc. */ + unsigned int Port; /* The port to listen on. */ + uint8 *Password; /* The server password. */ +} CONFIG; + +CONFIG ServerConfig; + +int LoadConfigFile(char *fn) +{ + FILE *fp; + ServerConfig.Port = ServerConfig.MaxClients = ServerConfig.ConnectTimeout = ServerConfig.FrameDivisor = ~0; + if(fp=fopen(fn,"rb")) + { + char buf[256]; + while(fgets(buf, 256, fp) > 0) + { + if(!strncasecmp(buf,"maxclients",strlen("maxclients"))) + sscanf(buf,"%*s %d",&ServerConfig.MaxClients); + else if(!strncasecmp(buf,"connecttimeout",strlen("connecttimeout"))) + sscanf(buf,"%*s %d",&ServerConfig.ConnectTimeout); + else if(!strncasecmp(buf,"framedivisor",strlen("framedivisor"))) + sscanf(buf,"%*s %d",&ServerConfig.FrameDivisor); + else if(!strncasecmp(buf,"port",strlen("port"))) + sscanf(buf,"%*s %d",&ServerConfig.Port); + else if(!strncasecmp(buf,"password",strlen("password"))) + { + char *pass = 0; + sscanf(buf,"%*s %as",&pass); + if(pass) + { + struct md5_context md5; + ServerConfig.Password = (uint8 *)malloc(16); + md5_starts(&md5); + md5_update(&md5,(uint8*)pass,strlen(pass)); + md5_finish(&md5,ServerConfig.Password); + puts("Password required to log in."); + } + } + } + } + + else + { + printf("Cannot load configuration file %s.\n", fn); + return(0); + } + + if(~0 == (ServerConfig.Port & ServerConfig.MaxClients & ServerConfig.ConnectTimeout & ServerConfig.FrameDivisor)) + { + puts("Incomplete configuration file"); + return(0); + } + //printf("%d,%d,%d\n",ServerConfig.MaxClients,ServerConfig.ConnectTimeout,ServerConfig.FrameDivisor); + printf("Using configuration file located at %s\n", fn); + return(1); +} + +static ClientEntry *Clients; +static GameEntry *Games; + +static void en32(uint8 *buf, uint32 morp) +{ + buf[0]=morp; + buf[1]=morp>>8; + buf[2]=morp>>16; + buf[3]=morp>>24; +} + +static uint32 de32(uint8 *morp) +{ + return(morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24)); +} + +static char *CleanNick(char *nick); +static int NickUnique(ClientEntry *client); +static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64]) throw(int); +static void SendToAll(GameEntry *game, int cmd, uint8 *data, uint32 len) throw(int); +static void BroadcastText(GameEntry *game, const char *fmt, ...) throw(int); +static void TextToClient(ClientEntry *client, const char *fmt, ...) throw(int); +static void KillClient(ClientEntry *client); + +#define NBTCP_LOGINLEN 0x100 +#define NBTCP_LOGIN 0x200 +#define NBTCP_COMMANDLEN 0x300 +#define NBTCP_COMMAND 0x400 + +#define NBTCP_UPDATEDATA 0x800 + +static void StartNBTCPReceive(ClientEntry *client, uint32 type, uint32 len) +{ + client->nbtcp = (uint8 *)malloc(len); + client->nbtcplen = len; + client->nbtcphas = 0; + client->nbtcptype = type; +} + +static void RedoNBTCPReceive(ClientEntry *client) +{ + client->nbtcphas = 0; +} + +static void EndNBTCPReceive(ClientEntry *client) +{ + free(client->nbtcp); + client->nbtcplen = client->localplayers; + client->nbtcphas = 0; + client->nbtcptype = 0; + client->nbtcp = 0; +} + +static uint8 *MakeMPS(ClientEntry *client) +{ + static uint8 buf[64]; + uint8 *bp = buf; + int x; + GameEntry *game = (GameEntry *)client->game; + + for(x=0;x<4;x++) + { + if(game->Players[x] == client) + { + *bp = '0' + x + 1; + bp++; + *bp = ','; + bp++; + } + } + if(*(bp-1) == ',') bp--; + + *bp = 0; + return(buf); +} + +/* Returns 1 if we are back to normal game mode, 0 if more data is yet to arrive. */ +static int CheckNBTCPReceive(ClientEntry *client) throw(int) +{ + if(!client->nbtcplen) + throw(1); /* Should not happen. */ + int l; + + while(l = recv(client->TCPSocket, client->nbtcp + client->nbtcphas, client->nbtcplen - client->nbtcphas, MSG_NOSIGNAL)) + { + if(l == -1) + { + if(errno == EAGAIN || errno == EWOULDBLOCK) + break; + throw(1); /* Die now. NOW. */ + } + client->nbtcphas += l; + + //printf("Read: %d, %04x, %d, %d\n",l,client->nbtcptype,client->nbtcphas, client->nbtcplen); + + /* We're all full. Yippie. */ + if(client->nbtcphas == client->nbtcplen) + { + uint32 len; + + switch(client->nbtcptype & 0xF00) + { + case NBTCP_UPDATEDATA: + { + GameEntry *game = (GameEntry *)client->game; + int x, wx; + if(client->nbtcp[0] == 0xFF) + { + EndNBTCPReceive(client); + StartNBTCPReceive(client, NBTCP_COMMANDLEN, 5); + return(1); + } + for(x=0,wx=0; x < 4; x++) + { + if(game->Players[x] == client) + { + game->joybuf[x] = client->nbtcp[wx]; + wx++; + } + } + RedoNBTCPReceive(client); + } + return(1); + case NBTCP_COMMANDLEN: + { + uint8 cmd = client->nbtcp[4]; + len = de32(client->nbtcp); + if(len > 200000) /* Sanity check. */ + throw(1); + + //printf("%02x, %d\n",cmd,len); + if(!len && !(cmd&0x80)) + { + SendToAll((GameEntry*)client->game, client->nbtcp[4], 0, 0); + EndNBTCPReceive(client); + StartNBTCPReceive(client,NBTCP_UPDATEDATA,client->localplayers); + } + else if(client->nbtcp[4]&0x80) + { + EndNBTCPReceive(client); + if(len) + StartNBTCPReceive(client,NBTCP_COMMAND | cmd,len); + else /* Woops. Client probably tried to send a text message of 0 length. Or maybe a 0-length cheat file? Better be safe! */ + StartNBTCPReceive(client,NBTCP_UPDATEDATA,client->localplayers); + } + else throw(1); + return(1); + } + case NBTCP_COMMAND: + { + len = client->nbtcplen; + uint32 tocmd = client->nbtcptype & 0xFF; + + if(tocmd == 0x90) /* Text */ + { + char *ma, *ma2; + + ma = (char *) malloc(len + 1); + memcpy(ma, client->nbtcp, len); + ma[len] = 0; + asprintf(&ma2, "<%s> %s",client->nickname,ma); + free(ma); + ma = ma2; + len=strlen(ma); + SendToAll((GameEntry*)client->game, tocmd, (uint8 *)ma, len); + free(ma); + } + else + SendToAll((GameEntry*)client->game, tocmd, client->nbtcp, len); + EndNBTCPReceive(client); + StartNBTCPReceive(client,NBTCP_UPDATEDATA,client->localplayers); + return(1); + } + case NBTCP_LOGINLEN:len = de32(client->nbtcp); + if(len > 1024 || len < (16 + 16 + 64 + 1)) + throw(1); + EndNBTCPReceive(client); + StartNBTCPReceive(client,NBTCP_LOGIN,len); + return(1); + case NBTCP_LOGIN: + { + uint32 len; + uint8 gameid[16]; + uint8 *sexybuf; + uint8 extra[64]; + + len = client->nbtcplen; + sexybuf = client->nbtcp; + + /* Game ID(MD5'd game MD5 and password on client side). */ + memcpy(gameid, sexybuf, 16); + sexybuf += 16; + len -= 16; + + if(ServerConfig.Password) + if(memcmp(ServerConfig.Password,sexybuf,16)) + { + TextToClient(client,"Invalid server password."); + throw(1); + } + sexybuf += 16; + len -= 16; + + memcpy(extra, sexybuf, 64); + sexybuf += 64; + len -= 64; + + client->localplayers = *sexybuf; + if(client->localplayers < 1 || client->localplayers > 4) + { + TextToClient(client,"Invalid number(%d) of local players!",client->localplayers); + throw(1); + } + sexybuf++; + len -= 1; + + AddClientToGame(client, gameid, extra); + /* Get the nickname */ + if(len) + { + client->nickname = (char *)malloc(len + 1); + memcpy(client->nickname, sexybuf, len); + client->nickname[len] = 0; + if((client->nickname = CleanNick(client->nickname))) + if(!NickUnique(client)) /* Nickname already exists */ + { + free(client->nickname); + client->nickname = 0; + } + } + uint8 *mps = MakeMPS(client); + + if(!client->nickname) + asprintf(&client->nickname,"*Player %s",mps); + + printf("Client %d assigned to game %d as player %s <%s>\n",client->id,(GameEntry*)client->game - Games,mps, client->nickname); + + int x; + GameEntry *tg=(GameEntry *)client->game; + + for(x=0; xMaxPlayers; x++) + if(tg->Players[x] && tg->IsUnique[x]) + { + if(tg->Players[x] != client) + { + try + { + TextToClient(tg->Players[x], "* Player %s has just connected as: %s",MakeMPS(client),client->nickname); + } catch(int i) + { + KillClient(tg->Players[x]); + } + TextToClient(client, "* Player %s is already connected as: %s",MakeMPS(tg->Players[x]),tg->Players[x]->nickname); + } + else + TextToClient(client, "* You(Player %s) have just connected as: %s",MakeMPS(client),client->nickname); + } + } + EndNBTCPReceive(client); + StartNBTCPReceive(client,NBTCP_UPDATEDATA,client->localplayers); + return(1); + } + } + } + return(0); +} + +int ListenSocket; + +static char *CleanNick(char *nick) +{ + int x; + + for(x=0; x' || nick[x] == '*' || (nick[x] < 0x20)) + nick[x] = 0; + if(!strlen(nick)) + { + free(nick); + nick = 0; + } + + return(nick); +} + +static int NickUnique(ClientEntry *client) +{ + int x; + GameEntry *game = (GameEntry *)client-> game; + + for(x=0; xMaxPlayers; x++) + if(game->Players[x] && client != game->Players[x]) + if(!strcasecmp(client->nickname, game->Players[x]->nickname)) + return(0); + return(1); +} + +static int MakeSendTCP(ClientEntry *client, uint8 *data, uint32 len) throw(int) +{ + if(send(client->TCPSocket, data, len, MSG_NOSIGNAL) != len) + throw(1); + return(1); +} + +static void SendToAll(GameEntry *game, int cmd, uint8 *data, uint32 len) throw(int) +{ + uint8 poo[5]; + int x; + + poo[4] = cmd; + + for(x=0;xMaxPlayers;x++) + { + if(!game->Players[x] || !game->IsUnique[x]) continue; + + try + { + if(cmd & 0x80) + en32(poo, len); + MakeSendTCP(game->Players[x],poo,5); + + if(cmd & 0x80) + { + MakeSendTCP(game->Players[x], data, len); + } + } + catch(int i) + { + KillClient(game->Players[x]); + } + + } +} + +static void TextToClient(ClientEntry *client, const char *fmt, ...) throw(int) +{ + char *moo; + va_list ap; + + va_start(ap,fmt); + vasprintf(&moo, fmt, ap); + va_end(ap); + + + uint8 poo[5]; + uint32 len; + + poo[4] = 0x90; + len = strlen(moo); + en32(poo, len); + + MakeSendTCP(client, poo, 5); + MakeSendTCP(client, (uint8*)moo, len); + free(moo); +} + +static void BroadcastText(GameEntry *game, const char *fmt, ...) throw(int) +{ + char *moo; + va_list ap; + + va_start(ap,fmt); + vasprintf(&moo, fmt, ap); + va_end(ap); + + SendToAll(game, 0x90,(uint8 *)moo,strlen(moo)); + free(moo); +} + +static void KillClient(ClientEntry *client) +{ + GameEntry *game; + uint8 *mps; + char *bmsg; + + game = (GameEntry *)client->game; + if(game) + { + int w; + int tc = 0; + + for(w=0;wMaxPlayers;w++) + if(game->Players[w]) tc++; + + for(w=0;wMaxPlayers;w++) + if(game->Players[w]) + if(game->Players[w] == client) + game->Players[w] = NULL; + + time_t curtime = time(0); + printf("Player <%s> disconnected from game %d on %s",client->nickname,game-Games,ctime(&curtime)); + asprintf(&bmsg, "* Player %s <%s> left.",MakeMPS(client),client->nickname); + if(tc == client->localplayers) /* If total players for this game = total local + players for this client, destroy the game. + */ + { + printf("Game %d destroyed.\n",game-Games); + memset(game, 0, sizeof(GameEntry)); + game = 0; + } + } + else + { + time_t curtime = time(0); + printf("Unassigned client %d disconnected on %s",client->id, ctime(&curtime)); + } + if(client->nbtcp) + free(client->nbtcp); + + if(client->nickname) + free(client->nickname); + + if(client->TCPSocket != -1) + close(client->TCPSocket); + memset(client, 0, sizeof(ClientEntry)); + client->TCPSocket = -1; + + if(game) + BroadcastText(game,"%s",bmsg); +} + +static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64]) throw(int) +{ + int wg; + GameEntry *game,*fegame; + + retry: + + game = NULL; + fegame = NULL; + + /* First, find an available game. */ + for(wg=0; wgMaxPlayers = 4; + memcpy(game->id, id, 16); + memcpy(game->ExtraInfo, extra, 64); + } + + + int n; + for(n = 0; n < game->MaxPlayers; n++) + if(game->Players[n]) + { + try + { + uint8 b[5]; + b[4] = 0x81; + MakeSendTCP(game->Players[n], b, 5); + break; + } + catch(int i) + { + KillClient(game->Players[n]); + /* All right, now the client we sent the request to is killed. I HOPE YOU'RE HAPPY! */ + /* Since killing a client can destroy a game, we'll need to see if the game was trashed. + If it was, then "goto retry", and try again. Ugly, yes. I LIKE UGLY. + */ + if(!game->MaxPlayers) + goto retry; + } + } + + int instancecount = client->localplayers; + + for(n=0; nMaxPlayers; n++) + if(!game->Players[n]) + { + game->Players[n] = client; + if(instancecount == client->localplayers) + game->IsUnique[n] = 1; + else + game->IsUnique[n] = 0; + instancecount --; + if(!instancecount) + break; + } + + /* Game is full. */ + if(n == game->MaxPlayers) + { + for(n=0; nMaxPlayers; n++) + if(game->Players[n] == client) + game->Players[n] = 0; + TextToClient(client, "Sorry, game is full. %d instance(s) tried, %d available.",client->localplayers,client->localplayers - instancecount); + throw(1); + } + + client->game = (void *)game; +} + + + + +int main(int argc, char *argv[]) +{ + + struct sockaddr_in sockin; + socklen_t sockin_len; + int i; + char* pass = 0; + /* If we can't load the default config file, use some defined values */ + if(!LoadConfigFile(DEFAULT_CONFIG)) { + ServerConfig.Port = DEFAULT_PORT; + ServerConfig.MaxClients = DEFAULT_MAX; + ServerConfig.ConnectTimeout = DEFAULT_TIMEOUT; + ServerConfig.FrameDivisor = DEFAULT_FRAMEDIVISOR; + } + char* configfile = 0; + + + for(i=1; ilocalplayers; + + while(CheckNBTCPReceive(client)) {}; + } // catch + catch(int i) + { + KillClient(Games[whichgame].Players[n]); + } + } // A games clients + + /* Now we send the data to all the clients. */ + for(n = 0; n < Games[whichgame].MaxPlayers; n++) + { + if(!Games[whichgame].Players[n] || !Games[whichgame].IsUnique[n]) continue; + try + { + MakeSendTCP(Games[whichgame].Players[n], Games[whichgame].joybuf, 5); + } + catch(int i) + { + KillClient(Games[whichgame].Players[n]); + } + } // A game's clients + } // Games + + SpeedThrottle(); + } // while(1) +} diff --git a/branches/fceux-2.2.2/fceux-server/throttle.cpp b/branches/fceux-2.2.2/fceux-server/throttle.cpp new file mode 100644 index 00000000..dedffe31 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/throttle.cpp @@ -0,0 +1,102 @@ +/* FCE Ultra Network Play Server + * + * Copyright notice for this file: + * Copyright (C) 2004 Xodnizel + * + * 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 +#include +#include "types.h" +#include "throttle.h" + +#ifdef TODO +THROTTLE *MakeThrottle(uint32 fps) +{ + + +} + +/* Returns 1 if it's time to run, 0 if it's not time yet. */ +int TestThrottle(THROTTLE *throt) +{ + +} + +/* Pass it a pointer to an array of THROTTLE structs */ +/* It will check */ +void DoAllThrottles(THROTTLE *throt) +{ + + +} + +void KillThrottle(THROTTLE *throt) +{ + +} + +#endif + +static uint64 tfreq; +static uint64 desiredfps; + +int32 FCEUI_GetDesiredFPS(void) +{ + //if(PAL) + // return(838977920); // ~50.007 + //else + return(1008307711); // ~60.1 +} + +void RefreshThrottleFPS(int divooder) +{ + desiredfps=(FCEUI_GetDesiredFPS() / divooder)>>8; + tfreq=1000000; + tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */ +} + +static uint64 GetCurTime(void) +{ + uint64 ret; + struct timeval tv; + + gettimeofday(&tv,0); + ret=(uint64)tv.tv_sec*1000000; + ret+=tv.tv_usec; + return(ret); +} + +void SpeedThrottle(void) +{ + static uint64 ttime,ltime; + + waiter: + ttime=GetCurTime(); + + if( (ttime-ltime) < (tfreq/desiredfps) ) + { + usleep(1000); + goto waiter; + } + if( (ttime-ltime) >= (tfreq*4/desiredfps)) + ltime=ttime; + else + ltime+=tfreq/desiredfps; +} + diff --git a/branches/fceux-2.2.2/fceux-server/throttle.h b/branches/fceux-2.2.2/fceux-server/throttle.h new file mode 100644 index 00000000..4434f86d --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/throttle.h @@ -0,0 +1,23 @@ +/* FCE Ultra Network Play Server + * + * Copyright notice for this file: + * Copyright (C) 2004 Xodnizel + * + * 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. + * */ + + +void RefreshThrottleFPS(int divooder); +void SpeedThrottle(void); diff --git a/branches/fceux-2.2.2/fceux-server/types.h b/branches/fceux-2.2.2/fceux-server/types.h new file mode 100644 index 00000000..4d1e35f4 --- /dev/null +++ b/branches/fceux-2.2.2/fceux-server/types.h @@ -0,0 +1,38 @@ +/* FCE Ultra Network Play Server + * + * Copyright notice for this file: + * Copyright (C) 2004 Xodnizel + * + * 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 __FCEU_TYPES +#define __FCEU_TYPES + +#include +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; + +typedef unsigned long long uint64; +typedef long long int64; +#define INLINE inline +#define GINLINE inline + +#endif diff --git a/branches/fceux-2.2.2/fceux.desktop b/branches/fceux-2.2.2/fceux.desktop new file mode 100644 index 00000000..60aecf2c --- /dev/null +++ b/branches/fceux-2.2.2/fceux.desktop @@ -0,0 +1,22 @@ +[Desktop Entry] +Type=Application +Version=1.0 +Name=Fceux +GenericName=NES/Famicom emulator +NoDisplay=false +Comment=Emulate NES ROMs +Exec=/usr/bin/fceux +Icon=/usr/share/pixmaps/fceux.png +Terminal=false +MimeType=application/x-nes-rom +Categories=Game;Emulator; +Encoding=UTF-8 +Actions=Fullscreen;DefaultConfig; +[Desktop Action Fullscreen] +Name=Open in Fullscreen +Exec=fceux -f 1 +OnlyShowIn=Unity +[Desktop Action DefaultConfig] +Name=Start With the Default Configuration +Exec=fceux --no-config 1 +OnlyShowIn=Unity diff --git a/branches/fceux-2.2.2/fceux.png b/branches/fceux-2.2.2/fceux.png new file mode 100644 index 00000000..1cf27b1f Binary files /dev/null and b/branches/fceux-2.2.2/fceux.png differ diff --git a/branches/fceux-2.2.2/getSDLKey/COPYING b/branches/fceux-2.2.2/getSDLKey/COPYING new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/branches/fceux-2.2.2/getSDLKey/COPYING @@ -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/branches/fceux-2.2.2/getSDLKey/Makefile b/branches/fceux-2.2.2/getSDLKey/Makefile new file mode 100644 index 00000000..2bb65883 --- /dev/null +++ b/branches/fceux-2.2.2/getSDLKey/Makefile @@ -0,0 +1,17 @@ +PREFIX = /usr +OUTFILE = getSDLKey + +CC = g++ +OBJS = getSDLKey.o +LIBS = $(shell sdl-config --cflags --libs) + +all: ${OBJS} + ${CC} -o ${OUTFILE} ${OBJS} ${LIBS} + +clean: + rm -f ${OUTFILE} ${OBJS} + +install: + install -m 755 -D getSDLKey ${PREFIX}/bin/getSDLKey + +getSDLKey.o = getSDLKey.cpp diff --git a/branches/fceux-2.2.2/getSDLKey/README b/branches/fceux-2.2.2/getSDLKey/README new file mode 100644 index 00000000..d300fe7d --- /dev/null +++ b/branches/fceux-2.2.2/getSDLKey/README @@ -0,0 +1,27 @@ +############################################# +# getSDLKey - Lukas Sabota - October, 2011 # +############################################# + +1. Dependencies: + gcc + make + libsdl + +2. Installing +Run "make" to compile to "getSDLKey". Run "make install" as root if you would like to install "getSDLKey" into a user-specified PREFIX. + +3. Running +Type "./getSDLKey" while in this directory to run. + +4. About this tool. +This is a tool to determine what the SDL keysym for a particular key on your keyboard is. This is especially useful when mapping hotkeys to FCEUX. Take a look at an excerpt of ~/.fceux/fceux.cfg: + + SDL.Hotkeys.SaveState = 286 + +Apparently, F5 on my system is SDL keysym 286. If you wanted to remap this to a different key, run ./getSDLKey and press the desired key to see what keysym you should modify your configuration with. + +5. Bugs +You can report any issues with this tool in the FCEUX SourceForge bugtracker. Alternatively, you can contact me directly at LTsmooth42 _at_ gmail _dot_ com. + +6. Future +I plan to implement a GUI for remapping these keys so you dont have to do this in the future, but were all very busy people, arent we? diff --git a/branches/fceux-2.2.2/getSDLKey/getSDLKey.cpp b/branches/fceux-2.2.2/getSDLKey/getSDLKey.cpp new file mode 100644 index 00000000..4f25fd8c --- /dev/null +++ b/branches/fceux-2.2.2/getSDLKey/getSDLKey.cpp @@ -0,0 +1,90 @@ +///////////////////////////////////////////////////////////////// +// getSDLKey.cpp +// Lukas Sabota - October, 2011 +// +// Prints the corresponding SDL keysym for a key pressed +// into a SDL window. Useful for remapping hotkeys in they +// ~/.fceux/fceux.cfg config file, but may be useful for other +// applications as well. +// +///////////////////////////////////////////////////////////////// + +#include + +void DisplayState(SDL_KeyboardEvent *key) +{ + if (key->type == SDL_KEYUP) + printf("RELEASED: "); + else + printf("PRESSED: "); + +} + +void DisplayModifiers(SDL_KeyboardEvent *key) +{ + SDLMod modifier = key->keysym.mod; + if( modifier & KMOD_NUM ) printf( "NUMLOCK " ); + if( modifier & KMOD_CAPS ) printf( "CAPSLOCK " ); + if( modifier & KMOD_MODE ) printf( "MODE " ); + if( modifier & KMOD_LCTRL ) printf( "LCTRL " ); + if( modifier & KMOD_RCTRL ) printf( "RCTRL " ); + if( modifier & KMOD_LSHIFT ) printf( "LSHIFT " ); + if( modifier & KMOD_RSHIFT ) printf( "RSHIFT " ); + if( modifier & KMOD_LALT ) printf( "LALT " ); + if( modifier & KMOD_RALT ) printf( "RALT " ); + if( modifier & KMOD_LMETA ) printf( "LMETA " ); + if( modifier & KMOD_RMETA ) printf( "RMETA " ); +} + +void DisplayKey(SDL_KeyboardEvent *key) +{ + printf( "%s\n", SDL_GetKeyName(key->keysym.sym)); +} + +void DisplayKeysym(SDL_KeyboardEvent *key) +{ + printf ("%d\n", key->keysym.sym); +} + + +int main(int argc, char** argv) +{ + SDL_Surface *screen; + + if (SDL_Init(SDL_INIT_VIDEO) != 0) + { + printf("Unable to initialize SDL: %s\n", SDL_GetError()); + return 1; + } + + atexit(SDL_Quit); + + screen = SDL_SetVideoMode(320, 240, 0, SDL_ANYFORMAT); + SDL_WM_SetCaption("Get SDL Keysyms! Now 50\% off!", NULL); + if (screen == NULL) + { + printf("Unable to set video mode: %s\n", SDL_GetError()); + return 1; + } + SDL_Event event; + int running = 1; + + while(running) { + while(SDL_PollEvent(&event)) { + switch(event.type){ + case SDL_KEYDOWN: + case SDL_KEYUP: + DisplayState(&event.key); + DisplayModifiers(&event.key); + DisplayKey(&event.key); + DisplayKeysym(&event.key); + break; + case SDL_QUIT: + running = 0; + break; + } + } + } + + return 0; +} diff --git a/branches/fceux-2.2.2/output/.gitignore b/branches/fceux-2.2.2/output/.gitignore new file mode 100644 index 00000000..907b4c9c --- /dev/null +++ b/branches/fceux-2.2.2/output/.gitignore @@ -0,0 +1,15 @@ +/7z.dll +/auxlib.lua +/cheats +/disksys.rom +/fceux.cfg +/fceux.chm +/fceux.chw +/fceux.exe +/fceux.exp +/fceux.lib +/fceux.pdb +/fcs +/movies +/sav +/snaps diff --git a/branches/fceux-2.2.2/output/fceux.chm b/branches/fceux-2.2.2/output/fceux.chm new file mode 100644 index 00000000..93fd80bc Binary files /dev/null and b/branches/fceux-2.2.2/output/fceux.chm differ diff --git a/branches/fceux-2.2.2/output/lua5.1.dll b/branches/fceux-2.2.2/output/lua5.1.dll new file mode 100644 index 00000000..b87f3b66 Binary files /dev/null and b/branches/fceux-2.2.2/output/lua5.1.dll differ diff --git a/branches/fceux-2.2.2/output/lua51.dll b/branches/fceux-2.2.2/output/lua51.dll new file mode 100644 index 00000000..27ab2654 Binary files /dev/null and b/branches/fceux-2.2.2/output/lua51.dll differ diff --git a/branches/fceux-2.2.2/output/luaScripts/AVI-HeadsUpDisplay.lua b/branches/fceux-2.2.2/output/luaScripts/AVI-HeadsUpDisplay.lua new file mode 100644 index 00000000..0a888949 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/AVI-HeadsUpDisplay.lua @@ -0,0 +1,121 @@ +-- Script by amaurea, andymac and feos for FCEUX 2.2.0 and earlier versions. +-- Allows customizable recording of Frame, Lag, Timer and Input display to AVI dump. +-- Drag and drop HUD items with mouse, use Numpad 1-6 to switch them on/off. + +print("Drag and drop HUD items with mouse, use Numpad 1-6 to switch them on/off.") + +screen = {w=256,h=231} +move = {object=nil,offx=0,offy=0} + +pads = { + {num=1,on=true, color="red", x=9, y=220,w=34,h=10,toggle="numpad1"}, + {num=2,on=true, color="yellow",x=54, y=220,w=34,h=10,toggle="numpad2"}, + {num=3,on=false,color="green", x=99, y=220,w=34,h=10,toggle="numpad3"}, + {num=4,on=false,color="orange",x=144,y=220,w=34,h=10,toggle="numpad4"} +} + +buttons = { + A = {x=30,y=5,w=3,h=3}, + B = {x=24,y=5,w=3,h=3}, + select = {x=18,y=7,w=3,h=1}, + start = {x=12,y=7,w=3,h=1}, + up = {x=4, y=1,w=2,h=2}, + down = {x=4, y=7,w=2,h=2}, + left = {x=1, y=4,w=2,h=2}, + right = {x=7, y=4,w=2,h=2} +} + +text = {on=true,x=1, y=9,w=30,h=16,toggle="numpad5"} +timer = {on=true,x=197,y=9,w=58,h= 7,toggle="numpad6"} + +function drawpad(pad) + gui.drawbox( pad.x, pad.y, pad.x+pad.w, pad.y+pad.h, "#3070ffb0" ) + gui.drawbox( pad.x+4, pad.y+4, pad.x+6, pad.y+6, "black" ) + controller = joypad.read(pad.num) + for name, b in pairs(buttons) do + gui.drawbox( pad.x + b.x, pad.y + b.y, pad.x + b.x + b.w, pad.y + b.y + b.h, + controller[name] and pad.color or "black" ) + end +end + +function mouseover(pad, margin) + return keys.xmouse >= pad.x-margin and keys.xmouse <= pad.x+pad.w+margin and + keys.ymouse >= pad.y-margin and keys.ymouse <= pad.y+pad.h+margin +end + +function inrange(upper, lower, testval) + if testval >= upper then return upper + elseif testval <= lower then return lower + else return testval + end +end + +function concat(tables) + local res = {} + for _, tab in ipairs(tables) do + for _, val in ipairs(tab) do + table.insert(res, val) + end + end + return res +end + +prev_keys = input.get() +objects = concat({pads, {text, timer}}) + +function everything() + keys = input.get() + + -- Are we moving anything around? + if move.object then + if keys["leftclick"] then + -- Do not go outside screen + local safex = inrange(screen.w - move.object.w, 0, keys.xmouse - move.offx) + local safey = inrange(screen.h - move.object.h, 8, keys.ymouse - move.offy) + move.object.x = safex + move.object.y = safey + else move.object = nil end + + -- Try to pick something up + elseif keys["leftclick"] then + for _,object in ipairs(objects) do + if mouseover(object,0) then + move.object = object + move.offx = keys.xmouse - object.x + move.offy = keys.ymouse - object.y + end + end + end + + -- Toggle displays + for _, object in ipairs(objects) do + if keys[object.toggle] and not prev_keys[object.toggle] then + object.on = not object.on + end + end + + -- Actually draw the stuff + if timer.on then + mins = math.floor(movie.framecount()/3600) + secs = movie.framecount()/60-mins*60 + gui.text( timer.x, timer.y, string.format("%s:%05.2f",os.date("!%H:%M",mins*60),secs), "white" ) + end + + if text.on then + local done = movie.mode() == "finished" or movie.mode() == nil + gui.text( text.x, text.y, movie.framecount(), done and "red" or "white" ) + gui.text( text.x, text.y + 9, FCEU.lagcount(), FCEU.lagged() and "red" or "green" ) + end + + for _, pad in ipairs(pads) do + if pad.on then drawpad(pad) end + end + + prev_keys = keys +end + +gui.register(everything) + +while (true) do + FCEU.frameadvance() +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/BoulderDash_AmoebaAI.lua b/branches/fceux-2.2.2/output/luaScripts/BoulderDash_AmoebaAI.lua new file mode 100644 index 00000000..adcbcb36 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/BoulderDash_AmoebaAI.lua @@ -0,0 +1,589 @@ +--------------------------------------------------------------------------- +-- Boulder Dash - Displaying Amoeba Pointer Movements +-- by AnS, 2012 +-- requested by CtrlAltDestroy +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * memory.registerexec() +--------------------------------------------------------------------------- +-- Usage: +-- Start playing any level of the BoulderDash that has the Amoeba enemy, +-- for example Level 2-3, Level 4-1 or Level 6-3. +-- Come close to the Amoeba enemy and see if you can find any regularities +-- in its movement. When you are convinced that its behavior is completely +-- erratic, run the script and unpause emulation. Now the script will draw +-- various arrows that show you the actual rules of the enemy AI. +-- +-- You can control the "playback slider" in the bottom of the screen (click +-- or drag it with mouse). Also you can pause and unpause this mini-playback +-- while the emulator is still paused. This is necessary because the Amoeba +-- makes a new set of moves every 8 frames, and this time span is not enough +-- for you to replay all the logged events. +--------------------------------------------------------------------------- +-- Explanations: +-- The Amoeba AI is defined by UpdateAmoeba() function (see the disassembly +-- code at the end of this script). +-- The UpdateAmoeba() makes many steps with the Amoeba Pointer (so the arrow +-- may move from tile to tile 100-200 times within the span of one frame! +-- This complexity makes it look unpredictable for player, even though the +-- rules of movement are very simple (move clockwise, rotate anticlockwise). +-- +-- This script allows you to see all steps of this Pointer, so you can grasp +-- the logic of Amoeba movement/multiplication. The script registers hooks +-- to all essential points of the UpdateAmoeba() code, and logs the whole +-- process of the function execution. Then it pauses emulation and replays +-- the log of events by drawing arrows over the game sprites. +-- The log auto-resets at the beginning of every new call of UpdateAmoeba(). +-- +-- Similar approach can be used for displaying complex AI in other games. +--------------------------------------------------------------------------- + +-- constants + +CELL_SIZE = 16; +CELL_HALFSIZE = CELL_SIZE / 2; +UPPER_BORDER_SIZE = 64; +LEFT_BORDER_SIZE = 32; +INTRO_DELAY = 1; +OUTRO_DELAY = 1; +MAX_ARROW_SIZE = 9; + +PAUSE_BUTTON_X = 2; +PAUSE_BUTTON_Y = 172; +PAUSE_BUTTON_WIDTH = 16; +PAUSE_BUTTON_HEIGHT = 16; + +TIMELINE_X = 20; +TIMELINE_LENGTH = 232; +TIMELINE_HEIGHT = 8; +TIMELINE_Y = 180; + +ColorStatuses = { "#00A000FF", "#00FF00FF", "#A0A0A0FF", "#00FFFFFF", "#FFFFFFFF", "#C0C000FF" }; +STATUS_NORMAL = 1; -- Green: Normal movements +STATUS_ROTATED = 2; -- Light-green: just rotated 90 degrees (anticlockwise) relative to current movement direction +STATUS_BUMPED = 3; -- Grey: bumped into obstacle +STATUS_SET = 4; -- Blue: Set amoeba +STATUS_REFUSED = 5; -- White: Refused to set amoeba +STATUS_END = 6; -- Yellow: RTS from UpdateAmoeba + +-- variables + +animation_timer = 0; +current_step = 0; +animation_speed = 0.5; +animation_paused = false; +mouse_held = false; +dragging_timeline = false; + +log_size = 0; +creation_frame = -1; + +-- arrays for storing the log data + +Amoeba_X = {}; +Amoeba_Y = {}; +AmoebaDirection = {}; +AmoebaPhase = {}; +AmoebaTimer = {}; +ColorStatus = {}; + +------------------------------------------------------------------------ +function reset_log() + log_size = 0; + animation_timer = 0; + creation_frame = movie.framecount(); + emu.pause(); +end + +function append_log_normal() + log_size = log_size + 1; + Amoeba_X[log_size] = memory.readbyte(0x0050); -- Temp_X + Amoeba_Y[log_size] = memory.readbyte(0x004F); -- Temp_Y + AmoebaDirection[log_size] = memory.readbyte(0x004E); -- Temp_AmoebaDirection + AmoebaPhase[log_size] = memory.readbyte(0x00B7); + AmoebaTimer[log_size] = memory.readbyte(0x00BD); + ColorStatus[log_size] = STATUS_NORMAL; -- Green: Normal movements +end + +function append_log_rotated() + log_size = log_size + 1; + Amoeba_X[log_size] = memory.readbyte(0x0050); -- Temp_X + Amoeba_Y[log_size] = memory.readbyte(0x004F); -- Temp_Y + AmoebaDirection[log_size] = memory.readbyte(0x004E); -- Temp_AmoebaDirection + AmoebaPhase[log_size] = memory.readbyte(0x00B7); + AmoebaTimer[log_size] = memory.readbyte(0x00BD); + ColorStatus[log_size] = STATUS_ROTATED; -- Light-green: just rotated 90 degrees (anticlockwise) relative to current movement direction +end + +function append_log_bumped() + log_size = log_size + 1; + Amoeba_X[log_size] = memory.readbyte(0x0050); -- Temp_X + Amoeba_Y[log_size] = memory.readbyte(0x004F); -- Temp_Y + AmoebaDirection[log_size] = memory.readbyte(0x004E); -- Temp_AmoebaDirection + AmoebaPhase[log_size] = memory.readbyte(0x00B7); + AmoebaTimer[log_size] = memory.readbyte(0x00BD); + ColorStatus[log_size] = STATUS_BUMPED; -- Grey: bumped into obstacle +end + +function append_log_set() + log_size = log_size + 1; + Amoeba_X[log_size] = memory.readbyte(0x0050); -- Temp_X + Amoeba_Y[log_size] = memory.readbyte(0x004F); -- Temp_Y + AmoebaDirection[log_size] = memory.readbyte(0x004E); -- Temp_AmoebaDirection + AmoebaPhase[log_size] = memory.readbyte(0x00B7); + AmoebaTimer[log_size] = memory.readbyte(0x00BD); + ColorStatus[log_size] = STATUS_SET; -- Blue: Set amoeba +end + +function append_log_refused() + log_size = log_size + 1; + Amoeba_X[log_size] = memory.readbyte(0x0050); -- Temp_X + Amoeba_Y[log_size] = memory.readbyte(0x004F); -- Temp_Y + AmoebaDirection[log_size] = memory.readbyte(0x004E); -- Temp_AmoebaDirection + AmoebaPhase[log_size] = memory.readbyte(0x00B7); + AmoebaTimer[log_size] = memory.readbyte(0x00BD); + ColorStatus[log_size] = STATUS_REFUSED; -- White: Refused to set amoeba +end + +function append_log_rts() + log_size = log_size + 1; + Amoeba_X[log_size] = memory.readbyte(0x00BC); + AmoebaDirectionAnd_Y = memory.readbyte(0x00BB); + Amoeba_Y[log_size] = AND(AmoebaDirectionAnd_Y, 0x3F); + AmoebaDirection[log_size] = AND(AmoebaDirectionAnd_Y, 0xC0); + AmoebaPhase[log_size] = memory.readbyte(0x00B7); + AmoebaTimer[log_size] = memory.readbyte(0x00BD); + ColorStatus[log_size] = STATUS_END; -- Yellow: RTS from UpdateAmoeba +end + +------------------------------------------------------------------------ +function DrawArrow(x, y, direction, size, color) + x = x + CELL_HALFSIZE; + y = y + CELL_HALFSIZE; + if (direction == 00) then + -- Left + gui.line(x, y - size, x - size, y, color); + gui.line(x - size, y, x, y + size, color); + gui.line(x, y + size, x, y - size, color); + end + if (direction == 0x40) then + -- up + gui.line(x - size, y, x, y - size, color); + gui.line(x, y - size, x + size, y, color); + gui.line(x + size, y, x - size, y, color); + end + if (direction == 0x80) then + -- Right + gui.line(x, y - size, x + size, y, color); + gui.line(x + size, y, x, y + size, color); + gui.line(x, y + size, x, y - size, color); + end + if (direction == 0xC0) then + -- Down + gui.line(x - size, y, x, y + size, color); + gui.line(x, y + size, x + size, y, color); + gui.line(x + size, y, x - size, y, color); + end +end +------------------------------------------------------------------------ +-- This function is called every frame when the emulator is unpaused, +-- and 20 times per second when the emulator is paused. + +function update() + AmoebaOrigin_X = memory.readbyte(0x00B9); + AmoebaOriginDirectionAnd_Y = memory.readbyte(0x00B8); + AmoebaOrigin_Y = AND(AmoebaOriginDirectionAnd_Y, 0x3F); + AmoebaOriginDirection = AND(AmoebaOriginDirectionAnd_Y, 0xC0); + + Camera_X_Lo = memory.readbyte(0x00BE); + Camera_X_Hi = memory.readbyte(0x00BF); + Camera_Y_Lo = memory.readbyte(0x00C0); + Camera_Y_Hi = memory.readbyte(0x00C1); + Camera_X = (256 * Camera_X_Hi + Camera_X_Lo) - UPPER_BORDER_SIZE; + Camera_Y = (256 * Camera_Y_Hi + Camera_Y_Lo) - LEFT_BORDER_SIZE; + + if (log_size > 0) then + + inp = input.get() + if (inp.leftclick) then + xm = inp.xmouse + ym = inp.ymouse + -- check click on the Pause/Resume button + if (not mouse_held) then + if (xm >= PAUSE_BUTTON_X and ym >= PAUSE_BUTTON_Y and xm < PAUSE_BUTTON_X + PAUSE_BUTTON_WIDTH and ym < PAUSE_BUTTON_Y + PAUSE_BUTTON_HEIGHT) then + animation_paused = not animation_paused; + end + end + -- check click on the timeline + if (dragging_timeline or (xm >= TIMELINE_X and ym >= TIMELINE_Y - TIMELINE_HEIGHT and xm < TIMELINE_X + TIMELINE_LENGTH and ym < TIMELINE_Y + TIMELINE_HEIGHT)) then + shift = xm - TIMELINE_X; + if (shift < 0) then + shift = 0; + else + if (shift > TIMELINE_LENGTH) then shift = TIMELINE_LENGTH; end + end + animation_timer = (INTRO_DELAY + log_size + OUTRO_DELAY) * shift / TIMELINE_LENGTH; + dragging_timeline = true; + end + mouse_held = true; + else + mouse_held = false; + dragging_timeline = false; + end + + if (not animation_paused and not mouse_held) then + -- animate + animation_timer = animation_timer + animation_speed; + if (animation_timer > INTRO_DELAY + log_size + OUTRO_DELAY) then + animation_timer = 0; + end + end + + current_step = math.floor(animation_timer - INTRO_DELAY); + if (current_step > log_size) then + current_step = log_size; + else + if (current_step < 1) then current_step = 1; end + end + + -- show info + if (ColorStatus[current_step] == STATUS_END) then + -- emphasize the phase change by yellow + gui.text(3, 11, "AmoebaPhase = " .. AND(AmoebaPhase[current_step], 3), "yellow"); + else + gui.text(3, 11, "AmoebaPhase = " .. AND(AmoebaPhase[current_step], 3)); + end + if ((ColorStatus[current_step] == STATUS_SET) or (ColorStatus[current_step] == STATUS_REFUSED)) then + -- emphasize the decrement by red + gui.text(3, 20, "AmoebaTimer = " .. AmoebaTimer[current_step], "red"); + else + gui.text(3, 20, "AmoebaTimer = " .. AmoebaTimer[current_step]); + end + + -- draw origin + DrawArrow(AmoebaOrigin_X * CELL_SIZE - Camera_X, AmoebaOrigin_Y * CELL_SIZE - Camera_Y, AmoebaOriginDirection, 5, "#00FFFFFF"); + + -- draw tail of pointers + for i = (MAX_ARROW_SIZE - 1), 0, -1 do + step = current_step - i; + if (step > 0) then + for s = 1, (MAX_ARROW_SIZE - i) do + -- draw previous position of pointer + DrawArrow(Amoeba_X[step] * CELL_SIZE - Camera_X, Amoeba_Y[step] * CELL_SIZE - Camera_Y, AmoebaDirection[step], s, ColorStatuses[ColorStatus[step]]); + end + end + end + -- draw black border around the last (current) pointer + DrawArrow(Amoeba_X[current_step] * CELL_SIZE - Camera_X, Amoeba_Y[current_step] * CELL_SIZE - Camera_Y, AmoebaDirection[current_step], MAX_ARROW_SIZE + 1, "black"); + + -- draw GUI + -- Pause/Resume button + gui.box(PAUSE_BUTTON_X, PAUSE_BUTTON_Y, PAUSE_BUTTON_X + PAUSE_BUTTON_WIDTH, PAUSE_BUTTON_Y + PAUSE_BUTTON_HEIGHT, "grey", "black"); + if (animation_paused) then + for s = 1, 6 do + DrawArrow(PAUSE_BUTTON_X - 2, PAUSE_BUTTON_Y, 0x80, s, "black"); + end + else + gui.box(PAUSE_BUTTON_X + (PAUSE_BUTTON_WIDTH / 2) - 3, PAUSE_BUTTON_Y + 3, PAUSE_BUTTON_X + (PAUSE_BUTTON_WIDTH / 2) - 1, PAUSE_BUTTON_Y + PAUSE_BUTTON_HEIGHT - 3, "black", "black"); + gui.box(PAUSE_BUTTON_X + (PAUSE_BUTTON_WIDTH / 2) + 3, PAUSE_BUTTON_Y + 3, PAUSE_BUTTON_X + (PAUSE_BUTTON_WIDTH / 2) + 1, PAUSE_BUTTON_Y + PAUSE_BUTTON_HEIGHT - 3, "black", "black"); + end + + -- line + gui.box(TIMELINE_X, TIMELINE_Y - TIMELINE_HEIGHT, TIMELINE_X + TIMELINE_LENGTH, TIMELINE_Y + TIMELINE_HEIGHT, "#00000040", "black"); + gui.box(TIMELINE_X, TIMELINE_Y - 1, TIMELINE_X + TIMELINE_LENGTH, TIMELINE_Y + 1, "white", "black"); + -- slider + shift = TIMELINE_LENGTH * animation_timer / (INTRO_DELAY + log_size + OUTRO_DELAY); + gui.box(TIMELINE_X + shift - 1, TIMELINE_Y - TIMELINE_HEIGHT, TIMELINE_X + shift + 1, TIMELINE_Y + TIMELINE_HEIGHT, "grey", "black"); + -- info + gui.text(TIMELINE_X + 80 + creation_frame % 3, TIMELINE_Y + TIMELINE_HEIGHT + 2, "Displaying " .. current_step .. " / " .. log_size); + gui.text(TIMELINE_X + 80 + creation_frame % 3, TIMELINE_Y + TIMELINE_HEIGHT + 11, "Created at frame " .. creation_frame); + end +end +------------------------------------------------------------------------ +gui.register(update); + +memory.registerexec(0xCE60, reset_log); -- ReallyUpdateAmoeba +--memory.registerexec(0xCE66, reset_log); -- RestartFromOrigin + +memory.registerexec(0xCE95, append_log_normal); -- TryMultiplying_Left +memory.registerexec(0xCEAE, append_log_normal); -- TryMultiplying_Up +memory.registerexec(0xCEC7, append_log_normal); -- TryMultiplying_Right +memory.registerexec(0xCEE0, append_log_normal); -- TryMultiplying_Down +memory.registerexec(0xCEF9, append_log_normal); -- TryMultiplying_Left2 +memory.registerexec(0xCF12, append_log_normal); -- TryMultiplying_Up2 +memory.registerexec(0xCF2B, append_log_normal); -- TryMultiplying_Right2 + +memory.registerexec(0xCEA3, append_log_rotated); -- Rotated from left to down +memory.registerexec(0xCEBC, append_log_rotated); -- Rotated from up to left +memory.registerexec(0xCED5, append_log_rotated); -- Rotated from right to up +memory.registerexec(0xCEEE, append_log_rotated); -- Rotated from down to right +memory.registerexec(0xCF07, append_log_rotated); -- Rotated from left to down +memory.registerexec(0xCF20, append_log_rotated); -- Rotated from up to left +memory.registerexec(0xCF39, append_log_rotated); -- Rotated from right to up + +memory.registerexec(0xCE9C, append_log_bumped); -- Bumped into obstacle +memory.registerexec(0xCEB5, append_log_bumped); -- Bumped into obstacle +memory.registerexec(0xCECE, append_log_bumped); -- Bumped into obstacle +memory.registerexec(0xCEE7, append_log_bumped); -- Bumped into obstacle +memory.registerexec(0xCF00, append_log_bumped); -- Bumped into obstacle +memory.registerexec(0xCF19, append_log_bumped); -- Bumped into obstacle +memory.registerexec(0xCF32, append_log_bumped); -- Bumped into obstacle + +memory.registerexec(0xCF97, append_log_normal); -- Jumped to another amoeba +memory.registerexec(0xCFA5, append_log_set); -- Set amoeba +memory.registerexec(0xCFA3, append_log_refused); -- Refused to set amoeba +memory.registerexec(0xCF5D, append_log_rts); -- RTS from UpdateAmoeba + +------------------------------------------------------------------------ +-- Disassembly of the BoulderDash code in question: +-- +-- UpdateAmoeba: +-- ; Called every frame, but works only once per 8 frames +-- >01:CE51:A5 B7 LDA AmoebaPhase = #$82 +-- 01:CE53:F0 0A BEQ ExitWithoutUpdate +-- 01:CE55:C9 FF CMP #$FF +-- 01:CE57:F0 06 BEQ ExitWithoutUpdate +-- 01:CE59:A5 FE LDA FrameCounter = #$6A +-- 01:CE5B:29 07 AND #$07 +-- 01:CE5D:F0 01 BEQ ReallyUpdateAmoeba +-- ExitWithoutUpdate: +-- 01:CE5F:60 RTS ----------------------------------------------------------- +-- ReallyUpdateAmoeba: +-- 01:CE60:A5 B7 LDA AmoebaPhase = #$82 +-- 01:CE62:29 03 AND #$03 +-- 01:CE64:D0 0C BNE PrepareForLoop25 +-- RestartFromOrigin: +-- ; Every time the amoeba multiplies or fails to multiply within 32 frames, it restarts to the original point +-- 01:CE66:A9 00 LDA #$00 +-- 01:CE68:85 B7 STA AmoebaPhase = #$82 +-- 01:CE6A:A5 B8 LDA AmoebaOriginDirectionAnd_Y = #$41 +-- 01:CE6C:85 BB STA AmoebaDirectionAnd_Y = #$41 +-- 01:CE6E:A5 B9 LDA AmoebaOrigin_X = #$14 +-- 01:CE70:85 BC STA Amoeba_X = #$18 +-- PrepareForLoop25: +-- 01:CE72:A9 19 LDA #$19 +-- 01:CE74:85 4D STA 25Tries = #$0A +-- ; Temp_X = Amoeba_X; Temp_Y = AmoebaDirectionAnd_Y & 00111111b; Temp_AmoebaDirection = AmoebaDirectionAnd_Y & 11000000b +-- 01:CE76:A5 BB LDA AmoebaDirectionAnd_Y = #$41 +-- 01:CE78:29 3F AND #$3F +-- 01:CE7A:A8 TAY +-- 01:CE7B:A5 BB LDA AmoebaDirectionAnd_Y = #$41 +-- 01:CE7D:29 C0 AND #$C0 +-- 01:CE7F:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CE81:A6 BC LDX Amoeba_X = #$18 +-- 01:CE83:84 4F STY Temp_Y = #$38 +-- 01:CE85:86 50 STX Temp_X = #$0A +-- Loop25Tries: +-- 01:CE87:A5 4E LDA Temp_AmoebaDirection = #$00 +-- 01:CE89:C9 40 CMP #$40 +-- 01:CE8B:F0 21 BEQ TryMultiplying_Up +-- 01:CE8D:C9 80 CMP #$80 +-- 01:CE8F:F0 36 BEQ TryMultiplying_Right +-- 01:CE91:C9 C0 CMP #$C0 +-- 01:CE93:F0 4B BEQ TryMultiplying_Down +-- TryMultiplying_Left: +-- 01:CE95:20 5E CF JSR CheckMultiplying_Left +-- 01:CE98:B0 05 BCS NextTimeTryDown +-- 01:CE9A:F0 0A BEQ OkSetAmoeba +-- 01:CE9C:4C AC CE JMP Restore_X +-- NextTimeTryDown: +-- ; Since we just moved the pointer to another amoeba, rotate direction anticlockwise +-- 01:CE9F:A9 C0 LDA #$C0 +-- 01:CEA1:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CEA3:4C 44 CF JMP DoUntilAll25TriesExpired +-- OkSetAmoeba: +-- 01:CEA6:20 99 CF JSR IntendToSetAmoebaToMap +-- 01:CEA9:90 01 BCC Restore_X +-- 01:CEAB:60 RTS ----------------------------------------------------------- +-- Restore_X: +-- 01:CEAC:E6 50 INC Temp_X = #$0A +-- TryMultiplying_Up: +-- 01:CEAE:20 6A CF JSR CheckMultiplying_Up +-- 01:CEB1:B0 05 BCS NextTimeTryLeft +-- 01:CEB3:F0 0A BEQ OkSetAmoeba +-- 01:CEB5:4C C5 CE JMP Restore_Y +-- NextTimeTryLeft: +-- ; Since we just moved the pointer to another amoeba, rotate direction anticlockwise +-- 01:CEB8:A9 00 LDA #$00 +-- 01:CEBA:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CEBC:4C 44 CF JMP DoUntilAll25TriesExpired +-- OkSetAmoeba: +-- 01:CEBF:20 99 CF JSR IntendToSetAmoebaToMap +-- 01:CEC2:90 01 BCC Restore_Y +-- 01:CEC4:60 RTS ----------------------------------------------------------- +-- Restore_Y: +-- 01:CEC5:E6 4F INC Temp_Y = #$38 +-- TryMultiplying_Right: +-- 01:CEC7:20 76 CF JSR CheckMultiplying_Right +-- 01:CECA:B0 05 BCS NextTimeTryUp +-- 01:CECC:F0 0A BEQ OkSetAmoeba +-- 01:CECE:4C DE CE JMP Restore_X +-- NextTimeTryUp: +-- ; Since we just moved the pointer to another amoeba, rotate direction anticlockwise +-- 01:CED1:A9 40 LDA #$40 +-- 01:CED3:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CED5:4C 44 CF JMP DoUntilAll25TriesExpired +-- OkSetAmoeba: +-- 01:CED8:20 99 CF JSR IntendToSetAmoebaToMap +-- 01:CEDB:90 01 BCC Restore_X +-- 01:CEDD:60 RTS ----------------------------------------------------------- +-- Restore_X: +-- 01:CEDE:C6 50 DEC Temp_X = #$0A +-- TryMultiplying_Down: +-- 01:CEE3:B0 05 BCS NextTimeTryRight +-- 01:CEE5:F0 0A BEQ OkSetAmoeba +-- 01:CEE7:4C F7 CE JMP Restore_X +-- NextTimeTryRight: +-- ; Since we just moved the pointer to another amoeba, rotate direction anticlockwise +-- 01:CEEA:A9 80 LDA #$80 +-- 01:CEEC:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CEEE:4C 44 CF JMP DoUntilAll25TriesExpired +-- OkSetAmoeba: +-- 01:CEF1:20 99 CF JSR IntendToSetAmoebaToMap +-- 01:CEF4:90 01 BCC Restore_X +-- 01:CEF6:60 RTS ----------------------------------------------------------- +-- Restore_X: +-- 01:CEF7:C6 4F DEC Temp_Y = #$38 +-- TryMultiplying_Left2: +-- 01:CEF9:20 5E CF JSR CheckMultiplying_Left +-- 01:CEFC:B0 05 BCS NextTimeTryDown2 +-- 01:CEFE:F0 0A BEQ OkSetAmoeba +-- 01:CF00:4C 10 CF JMP Restore_X +-- NextTimeTryDown2: +-- ; Since we just moved the pointer to another amoeba, rotate direction anticlockwise +-- 01:CF03:A9 C0 LDA #$C0 +-- 01:CF05:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CF07:4C 44 CF JMP DoUntilAll25TriesExpired +-- OkSetAmoeba: +-- 01:CF0A:20 99 CF JSR IntendToSetAmoebaToMap +-- 01:CF0D:90 01 BCC Restore_X +-- 01:CF0F:60 RTS ----------------------------------------------------------- +-- Restore_X: +-- 01:CF10:E6 50 INC Temp_X = #$0A +-- TryMultiplying_Up2: +-- 01:CF12:20 6A CF JSR CheckMultiplying_Up +-- 01:CF15:B0 05 BCS NextTimeTryLeft2 +-- 01:CF17:F0 0A BEQ OkSetAmoeba +-- 01:CF19:4C 29 CF JMP Restore_Y +-- NextTimeTryLeft2: +-- ; Since we just moved the pointer to another amoeba, rotate direction anticlockwise +-- 01:CF1C:A9 00 LDA #$00 +-- 01:CF1E:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CF20:4C 44 CF JMP DoUntilAll25TriesExpired +-- OkSetAmoeba: +-- 01:CF23:20 99 CF JSR IntendToSetAmoebaToMap +-- 01:CF26:90 01 BCC Restore_Y +-- 01:CF28:60 RTS ----------------------------------------------------------- +-- Restore_Y: +-- 01:CF29:E6 4F INC Temp_Y = #$38 +-- TryMultiplying_Right2: +-- 01:CF2B:20 76 CF JSR CheckMultiplying_Right +-- 01:CF2E:B0 05 BCS NextTimeTryUp2 +-- 01:CF30:F0 0A BEQ OkSetAmoeba +-- 01:CF32:4C 42 CF JMP Restore_X +-- NextTimeTryUp2: +-- ; Since we just moved the pointer to another amoeba, rotate direction anticlockwise +-- 01:CF35:A9 40 LDA #$40 +-- 01:CF37:85 4E STA Temp_AmoebaDirection = #$00 +-- 01:CF39:4C 44 CF JMP DoUntilAll25TriesExpired +-- OkSetAmoeba: +-- 01:CF3C:20 99 CF JSR IntendToSetAmoebaToMap +-- 01:CF3F:90 01 BCC Restore_X +-- 01:CF41:60 RTS ----------------------------------------------------------- +-- Restore_X: +-- 01:CF42:C6 50 DEC Temp_X = #$0A +-- DoUntilAll25TriesExpired: +-- 01:CF44:C6 4D DEC 25Tries = #$0A +-- 01:CF46:F0 03 BEQ All25TriesExpired +-- 01:CF48:4C 87 CE JMP Loop25Tries +-- All25TriesExpired: +-- ; Exits from UpdateAmoeba +-- 01:CF4B:A5 4F LDA Temp_Y = #$38 +-- 01:CF4D:05 4E ORA Temp_AmoebaDirection = #$00 +-- 01:CF4F:85 BB STA AmoebaDirectionAnd_Y = #$41 +-- 01:CF51:A5 50 LDA Temp_X = #$0A +-- 01:CF53:85 BC STA Amoeba_X = #$18 +-- 01:CF55:E6 B7 INC AmoebaPhase = #$82 +-- 01:CF57:A5 B7 LDA AmoebaPhase = #$82 +-- 01:CF59:29 83 AND #$83 +-- 01:CF5B:85 B7 STA AmoebaPhase = #$82 +-- 01:CF5D:60 RTS ----------------------------------------------------------- +-- +-- CheckMultiplying_Left: +-- ; Returns C=1 when the pointer is on another amoeba, Z=1 when can multiply +-- 01:CF5E:A4 4F LDY Temp_Y = #$38 +-- 01:CF60:C6 50 DEC Temp_X = #$0A +-- 01:CF62:A6 50 LDX Temp_X = #$0A +-- 01:CF64:20 7D CC JSR GetObjectFromMap +-- 01:CF67:4C 8B CF JMP CheckMultiplying +-- CheckMultiplying_Up: +-- ; Returns C=1 when the pointer is on another amoeba, Z=1 when can multiply +-- 01:CF6A:C6 4F DEC Temp_Y = #$38 +-- 01:CF6C:A4 4F LDY Temp_Y = #$38 +-- 01:CF6E:A6 50 LDX Temp_X = #$0A +-- 01:CF70:20 7D CC JSR GetObjectFromMap +-- 01:CF73:4C 8B CF JMP CheckMultiplying +-- CheckMultiplying_Right: +-- ; Returns C=1 when the pointer is on another amoeba, Z=1 when can multiply +-- 01:CF76:E6 50 INC Temp_X = #$0A +-- 01:CF78:A4 4F LDY Temp_Y = #$38 +-- 01:CF7A:A6 50 LDX Temp_X = #$0A +-- 01:CF7C:20 7D CC JSR GetObjectFromMap +-- 01:CF7F:4C 8B CF JMP CheckMultiplying +-- CheckMultiplying_Down: +-- ; Returns C=1 when the pointer is on another amoeba, Z=1 when can multiply +-- 01:CF82:E6 4F INC Temp_Y = #$38 +-- 01:CF84:A4 4F LDY Temp_Y = #$38 +-- 01:CF86:A6 50 LDX Temp_X = #$0A +-- 01:CF88:20 7D CC JSR GetObjectFromMap +-- CheckMultiplying: +-- ; Returns C=1 when the pointer is on another amoeba, Z=1 when can multiply +-- 01:CF8B:C9 D0 CMP #$D0 +-- 01:CF8D:F0 08 BEQ OccupiedByAmoeba +-- 01:CF8F:C9 00 CMP #$00 +-- 01:CF91:F0 02 BEQ $CF95 +-- 01:CF93:C9 20 CMP #$20 +-- ; Return result in Z flag: Z=1 when can multiply +-- 01:CF95:18 CLC +-- 01:CF96:60 RTS ----------------------------------------------------------- +-- OccupiedByAmoeba: +-- ; The place is occupied by another amoeba, so we can't multiply there +-- ; but instead we will move the pointer there! +-- 01:CF97:38 SEC +-- 01:CF98:60 RTS ----------------------------------------------------------- +-- +-- IntendToSetAmoebaToMap: +-- ; Uses Temp_X/Temp_Y, returns C=1 on success, and C=0 when --Countdown_BD != 0 +-- 01:CF99:A5 B7 LDA AmoebaPhase = #$82 +-- 01:CF9B:09 80 ORA #$80 +-- 01:CF9D:85 B7 STA AmoebaPhase = #$82 +-- 01:CF9F:C6 BD DEC Amoeba_Timer = #$1D +-- 01:CFA1:F0 02 BEQ ReallySetAmoebaToMap +-- DontWantToMultiply: +-- ; The IntendToSetAmoebaToMap() must be called many times, only then the multiplication will be made +-- 01:CFA3:18 CLC +-- 01:CFA4:60 RTS ----------------------------------------------------------- +-- ReallySetAmoebaToMap: +-- ; Uses Temp_X/Temp_Y, returns C=1 on success +-- 01:CFA5:A4 4F LDY Temp_Y = #$38 +-- 01:CFA7:A6 50 LDX Temp_X = #$0A +-- 01:CFA9:A9 D0 LDA #$D0 +-- 01:CFAB:20 77 D0 JSR SetObjectToMap +-- 01:CFAE:A4 4F LDY Temp_Y = #$38 +-- 01:CFB0:A6 50 LDX Temp_X = #$0A +-- 01:CFB2:A9 D0 LDA #$D0 +-- 01:CFB4:20 B7 D0 JSR AddObjectToBuffer +-- SheduleNextTimer: +-- ; Every time the waiting period decreases by 4 +-- 01:CFB7:A5 BA LDA AmoebaTimerResetValue = #$3F +-- 01:CFB9:38 SEC +-- 01:CFBA:E9 04 SBC #$04 +-- 01:CFBC:85 BA STA AmoebaTimerResetValue = #$3F +-- 01:CFBE:85 BD STA Amoeba_Timer = #$1D +-- ; Next update should reset the pointer to the origin +-- 01:CFC0:A9 80 LDA #$80 +-- 01:CFC2:85 B7 STA AmoebaPhase = #$82 +-- 01:CFC4:38 SEC +-- 01:CFC5:60 RTS ----------------------------------------------------------- +------------------------------------------------------------------------ + diff --git a/branches/fceux-2.2.2/output/luaScripts/BugsBunnyBirthdayBlowout.lua b/branches/fceux-2.2.2/output/luaScripts/BugsBunnyBirthdayBlowout.lua new file mode 100644 index 00000000..59cff15b --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/BugsBunnyBirthdayBlowout.lua @@ -0,0 +1,210 @@ +--Bugs Bunny Birthday Blowout +--Written by XKeeper +--Creates Lag and Sprite counters as well as Camera position + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function box(x1,y1,x2,y2,color) + if (x1 >= 0 and x1 <= 255 and x2 >= 0 and x2 <= 255 and y1 >= 0 and y1 <= 244 and y2 >= 0 and y2 <= 244) then + gui.drawbox(x1,y1,x2,y2,color); + end; +end; + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function filledbox(x1,y1,x2,y2,color) + for i = 0, math.abs(y1 - y2) do + line(x1,y1 + i,x2,y1 + i,color); + end; +end; + + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function lifebar(x, y, sx, sy, a1, a2, oncolor, offcolor, noborder) + -- this function will have the effect of drawing an HP bar + -- keep in mind xs and ys are 2px larger to account for borders + + x1 = x; + x2 = x + sx + 4; + y1 = y; + y2 = y + sy + 4; + w = math.floor(a1 / math.max(1, a1, a2) * sx); + if not a2 then w = 0 end; + + if (noborder) then + box(x1 + 1, y1 + 1, x2 - 1, y2 - 1, "#000000"); + else + box(x1 + 1, y1 + 1, x2 - 1, y2 - 1, "#ffffff"); + box(x1 , y1 , x2 , y2 , "#000000"); + end; + + if (w < sx) then + filledbox(x1 + w + 2, y1 + 2, x2 - 2, y2 - 2, offcolor); + end; + + if (w > 0) then + filledbox(x1 + 2, y1 + 2, x1 + 2 + w, y2 - 2, oncolor); + end; + +end; + + + + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function line(x1,y1,x2,y2,color) + if (x1 >= 0 and x1 <= 255 and x2 >= 0 and x2 <= 255 and y1 >= 0 and y1 <= 244 and y2 >= 0 and y2 <= 244) then + local success = pcall(function() gui.drawline(x1,y1,x2,y2,color) end); + if not success then + text(60, 224, "ERROR: ".. x1 ..",".. y1 .." ".. x2 ..",".. y2); + end; + end; +end; + +function text(x,y,str) + if (x >= 0 and x <= 255 and y >= 0 and y <= 240) then + gui.text(x,y,str); + end; +end; + +function pixel(x,y,color) + if (x >= 0 and x <= 255 and y >= 0 and y <= 240) then + gui.drawpixel(x,y,color); + end; +end; + + + +function drawpos(cx, cy, ex, ey, n) + sx = ex - cx; + sy = ey - cy; + + num = ""; + if n then + num = string.format("%02X", n); + end; + + if sx >= 0 and sx <= 255 and sy >= 0 and sy <= 244 then + line(sx, sy, sx + 16, sy + 0, "#ff0000"); + line(sx, sy, sx + 0, sy + 16, "#ff0000"); + text(sx, sy, num); + + elseif sx < 0 and sy >= 0 and sy <= 244 then + line(0, sy, 16, sy, "#ff0000"); + text(4, sy, num); + + elseif sx > 255 and sy >= 0 and sy <= 244 then + line(239, sy, 255, sy, "#ff0000"); + text(243, sy, num); + + elseif sy < 0 and sx >= 0 and sx <= 256 then + line(sx, 8, sx, 24, "#ff0000"); + text(sx, 8, num); + + elseif sy > 244 and sx >= 0 and sx <= 256 then + line(sx, 212, sx, 244, "#ff0000"); + text(sx, 216, num); + + end; + + +end; + + +lagdetectorold = 0; +timer = 0; +lagframes = 0; +lastlag = 0; + +while (true) do + + timer = timer + 1; + + lagdetector = memory.readbyte(0x00f5); +-- if lagdetector == lagdetectorold then + if AND(lagdetector, 0x20) == 0x20 then +-- if lagdetector == 0x0C then + lagframes = lagframes + 1; + else + if lagframes ~= 0 then + lastlag = lagframes; + end; + lagframes = 0; + lagdetectorold = lagdetector; + end; + memory.writebyte(0x00f5, OR(lagdetector, 0x20)); + + playerx = memory.readbyte(0x0432) + memory.readbyte(0x0433) * 0x100; + playery = memory.readbyte(0x0435) + memory.readbyte(0x0436) * 0x100; + + screenx = memory.readbyte(0x0456) + memory.readbyte(0x0457) * 0x100; + screeny = memory.readbyte(0x0458) + memory.readbyte(0x0459) * 0x100; + + text( 8, 8, string.format("%04X, %04X", playerx, playery)); + text( 8, 16, string.format("%04X, %04X", screenx, screeny)); + + drawpos(screenx, screeny, playerx, playery); + + + tmp = 0; + for i = 0, 0xb do + + offset = 0x7680 + i * 0x20; + + enemyt = memory.readbyte(offset); + enemyx = memory.readbyte(offset + 2) + memory.readbyte(offset + 3) * 0x100; + enemyy = memory.readbyte(offset + 4) + memory.readbyte(offset + 5) * 0x100; + + if enemyt ~= 0xff then +-- text(160, 8 + 8 * tmp, string.format("%02X: %02X <%04X, %04X>", i, enemyt, enemyx, enemyy)); + drawpos(screenx, screeny, enemyx, enemyy, i); + tmp = tmp + 1; + end + end; + + + text(142, 192, string.format("%02d lag frames", lastlag)); + text(142, 216, string.format("%02d active sprites", tmp)); + +-- box(2, 208, 2 + 8 * lastlag, 210, "#ff4444"); +-- box(2, 209, 2 + 8 * lastlag, 211, "#ff4444"); +-- box(2, 212, 2 + 8 * tmp, 213, "#4444ff"); +-- box(2, 214, 2 + 8 * tmp, 215, "#4444ff"); + + lifebar(144, 200, 100, 4, lastlag, 8, "#ffcc22", "#000000"); + lifebar(144, 208, 100, 4, tmp, 12, "#4488ff", "#000000"); + + FCEU.frameadvance(); + +end; + + + + + + + + + + + + + + + diff --git a/branches/fceux-2.2.2/output/luaScripts/ButtonCount.lua b/branches/fceux-2.2.2/output/luaScripts/ButtonCount.lua new file mode 100644 index 00000000..651c3293 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/ButtonCount.lua @@ -0,0 +1,156 @@ +--Written by Brandon Evans + +--You can change the number of controllers tracked here. +local controllers = 2 +--You can change the position of the text here. +local x = 0 +local y = 8 + +local players = {} +local states = {} +local pressed = 0 +local inputted = 0 + +function table.copy(t) + local t2 = {} + for k, v in pairs(t) do + t2[k] = v + end + return t2 +end + +function counts() + --Display the counts of the buttons pressed and inputted. + gui.text(x, y, 'Pressed: ' .. pressed) + gui.text(x, y + 8, 'Inputted: ' .. inputted) +end + +function load(slot) + --As Lua starts counting from 1, and there may be a slot 0, increment. + slot = slot + 1 + if not states[slot] or states[slot].inputted == nil then + gui.text(x, y + 16, 'No data loaded from slot ' .. tostring(slot - 1)) + counts() + return + end + --Load the data if there is any available for this slot. + players = table.copy(states[slot].players) + pressed = states[slot].pressed + inputted = states[slot].inputted + gui.text(x, y + 16, 'Data loaded from slot ' .. tostring(slot - 1)) + counts() +end + +function parse() + --If there is an open, read-only FM2 file, parse it for the initial data. + if not movie.active() then + return false + end + local fh = io.open(movie.name()) + if not fh or movie.mode() == 'record' or movie.name():match( + '.%.(%w+)$' + ) ~= 'fm2' then + return false + end + local frame = -1 + local last = {} + local match = { + 'right', 'left', 'down', 'up', 'start', 'select', 'B', 'A' + } + --Parse up until two frames before the current one. + while frame ~= emu.framecount() - 2 do + line = fh:read() + if not line then + break + end + --This is only a frame if it starts with a vertical bar. + if string.sub(line, 0, 1) == '|' then + frame = frame + 1 + players = {} + local player = -1 + --Split up the sections by a vertical bar. + for section in string.gmatch(line, '[^|]+') do + player = player + 1 + --Only deal with actual players. + if player ~= 0 then + local button = 0 + --Run through all the buttons. + for text in string.gmatch(section, '.') do + button = button + 1 + --Check if this button is pressed. + if text ~= ' ' and text ~= '.' then + inputted = inputted + 1 + --If the button was not previously pressed, + --increment. + if table.maxn(last) < player or not last[player][ + match[button] + ] then + pressed = pressed + 1 + end + if table.maxn(players) < player then + table.insert(players, {}) + end + --Mark this button as pressed. + players[player][match[button]] = true + end + end + end + end + --Save the players to compare with the next frame in the file. + last = players + end + end + return true +end + +function save(slot) + --As Lua starts counting from 1, and there may be a slot 0, increment. + slot = slot + 1 + while table.maxn(states) < slot do + table.insert(states, {}) + end + --Mark the current data as the data for this slot. + states[slot].players = table.copy(players) + states[slot].pressed = pressed + states[slot].inputted = inputted + gui.text(x, y + 16, 'Data saved to slot ' .. tostring(slot - 1)) + counts() +end + +if parse() then + gui.text(x, y + 16, 'Movie parsed for data') +else + gui.text(x, y + 16, 'No movie parsed for data') +end +if savestate.registerload then + savestate.registerload(load) + savestate.registersave(save) +end + +while true do + --If this is the first frame, reset the data. + if emu.framecount() == 0 then + players = {} + pressed = 0 + inputted = 0 + end + --Check players one and two. + for player = 1, controllers do + local buttons = joypad.getdown(player) + --Run through all of the pressed buttons. + for i, v in pairs(buttons) do + inputted = inputted + 1 + --If in the previous frame the button was not pressed, increment. + if table.maxn(players) >= player and not players[player][i] then + pressed = pressed + 1 + end + end + if table.maxn(players) < player then + table.insert(players, true) + end + --Mark these buttons as pressed. + players[player] = buttons + end + counts() + emu.frameadvance() +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/CustomLagIndicator_RvT.lua b/branches/fceux-2.2.2/output/luaScripts/CustomLagIndicator_RvT.lua new file mode 100644 index 00000000..50bdeded --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/CustomLagIndicator_RvT.lua @@ -0,0 +1,45 @@ +--------------------------------------------------------------------------- +-- Custom Lag Indicator for "RoboCop Vs The Terminator (U) (Prototype).nes" +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * emu.setlagflag() +--------------------------------------------------------------------------- +-- Usage: +-- The "RoboCop Vs The Terminator" game, as well as "Battle City" and some +-- other NES games, polls gamepads input every frame (in NMI), even when +-- it's lagging. So standard way of detecting lag (used by FCEUX and other +-- emulators) does not work for such games, and you have to determine lag +-- manually. +-- +-- In this game example we can detect lag by watching the RAM address 0x322. +-- This counter increases in non-lag frames only. +-- Debugger says the address increases by the instruction "INC $0322" which +-- is executed at ROM address 07:C6E9. So we should register a hook to this +-- instruction, and every time it's executed we can be sure that current +-- frame doesn't have lag ("no_lag = true"). +-- Then we should register another hook to the point where the game +-- polls Input (actually slightly after the point), so we can override +-- standard lag detection. +-- It's easy to find the code where the game polls input (reading from $4016). +-- Se we register a hook to an instruction following the input polling code. +-- In this case its ROM address 07:DE58. +--------------------------------------------------------------------------- + +no_lag = false; + +function set_nolag() + no_lag = true; +end +memory.registerexecute(0xC6E9, set_nolag); -- 07:C6E9 INC $0322 + +function determine_lagflag() + if (no_lag) then + emu.setlagflag(false); + no_lag = false; -- no_lag only affects once + else + emu.setlagflag(true); + end +end +memory.registerexecute(0xDE58, determine_lagflag); -- 07:DE58 The end of the cycle of reading from $4016-4017 (the point where FCEUX sets lagFlag to 0) + diff --git a/branches/fceux-2.2.2/output/luaScripts/Excitingbike-speedometeronly.lua b/branches/fceux-2.2.2/output/luaScripts/Excitingbike-speedometeronly.lua new file mode 100644 index 00000000..16d24b72 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Excitingbike-speedometeronly.lua @@ -0,0 +1,90 @@ +--Exciting Bike - Speedometer +--Written by XKeeper +--Shows the speedometer (obviously) + +require("x_functions"); + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(4); +end; + + + +function gameloop() + + + + +end; + + +gui.register(gameloop); + + +barcolors = {}; +barcolors[0] = "#000000"; +barcolors[1] = "#880000"; +barcolors[2] = "#ff0000"; +barcolors[3] = "#eeee00"; +barcolors[4] = "#00ff00"; +barcolors[5] = "#00ffff"; +barcolors[6] = "#0000ff"; +barcolors[7] = "#ff00ff"; +barcolors[8] = "#ffffff"; +barcolors[9] = "#123456"; + +lastvalue = {}; +justblinked = {}; +lastzero = {}; +timer = 0; +speed = 0; + +while (true) do + + timer = timer + 1; + lastvalue['speed'] = speed; + + + speed = memory.readbyte(0x0094) * 0x100 + memory.readbyte(0x0090); + positionx = memory.readbyte(0x0050) * 0x100 + memory.readbyte(0x0394); + timerspeed = 3 - memory.readbyte(0x004c); + timerslant = math.max(0, memory.readbyte(0x0026) - 1); + + if memory.readbyte(0x0303) ~= 0x8E then + text(255, 181, "Didn't advance this frame"); + end; + + speedadj1 = math.fmod(speed, 0x100); + speedadj2 = math.fmod(math.floor(speed / 0x100), #barcolors + 1); + speedadj3 = math.fmod(speedadj2 + 1, #barcolors + 1); + + lifebar( 61, 11, 100, 4, speedadj1, 0x100, barcolors[speedadj3], barcolors[speedadj2], "#000000", "#ffffff"); + + text( 0, 4 + 6, string.format("Speed: %4X", speed)); + text( 1, 4 + 14, string.format("S.Chg: %4d", speed - lastvalue['speed'])); + + text( 20, 222, " 2009 Xkeeper - http://jul.rustedlogic.net/ "); + line( 21, 231, 232, 231, "#000000"); + + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/Excitingbike.lua b/branches/fceux-2.2.2/output/luaScripts/Excitingbike.lua new file mode 100644 index 00000000..a6868ac9 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Excitingbike.lua @@ -0,0 +1,221 @@ +--Exicitebike +--Written by XKeeper +--Shows various stats including a RAM map & speed + +require("x_functions"); + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(4); +end; + + + +function gameloop() + + + + +end; + + +gui.register(gameloop); + + +barcolors = {}; +barcolors[0] = "#000000"; +barcolors[1] = "#880000"; +barcolors[2] = "#ff0000"; +barcolors[3] = "#eeee00"; +barcolors[4] = "#00ff00"; +barcolors[5] = "#00ffff"; +barcolors[6] = "#0000ff"; +barcolors[7] = "#ff00ff"; +barcolors[8] = "#ffffff"; +barcolors[9] = "#123456"; + +lastvalue = {}; +justblinked = {}; +lastzero = {}; +timer = 0; +speed = 0; + +while (true) do + + timer = timer + 1; + lastvalue['speed'] = speed; + + + speed = memory.readbyte(0x0094) * 0x100 + memory.readbyte(0x0090); + positionx = memory.readbyte(0x0050) * 0x100 + memory.readbyte(0x0394); + timerspeed = 3 - memory.readbyte(0x004c); + timerslant = math.max(0, memory.readbyte(0x0026) - 1); + + if memory.readbyte(0x0303) ~= 0x8E then + text(255, 181, "Didn't advance this frame"); + end; + + speedadj1 = math.fmod(speed, 0x100); + speedadj2 = math.fmod(math.floor(speed / 0x100), #barcolors + 1); + speedadj3 = math.fmod(speedadj2 + 1, #barcolors + 1); + + lifebar( 61, 11, 100, 4, speedadj1, 0x100, barcolors[speedadj3], barcolors[speedadj2], "#000000", "#ffffff"); + + text(198, 9, string.format("Speed %2d", timerspeed)); + text(196, 17, string.format(" Slant %2d", timerslant)); + box( 186, 10, 198, 18, "#000000"); + box( 186, 18, 198, 26, "#000000"); + + if timerspeed == 0 then + filledbox(187, 11, 197, 17, "#00ff00"); + if memory.readbyte(0x00B0) ~= 0 then + temp = "->"; + else + temp = "(B)"; + end; + text( 0, 50, string.format("Hold %s to maintain speed", temp)); + else + filledbox(187, 11, 197, 17, "#880000"); + end; + if timerslant <= 1 then + filledbox(187, 19, 197, 25, "#00ff00"); + text( 0, 58, string.format("Use < + > to modify angle")); + else + filledbox(187, 19, 197, 25, "#880000"); + end; + + + + text( 0, 4 + 6, string.format("Speed: %4X", speed)); + text( 1, 4 + 14, string.format("S.Chg: %4d", speed - lastvalue['speed'])); + + + + value = memory.readbyte(0x0064); + lifebar( 1, 1, 240, 6, value, 0xFF, "#ffffff", "#111144", false, "#000000"); + tp = math.floor(value / 255 * 240) + 4; + text(tp, 1, string.format("%02X", value)); + + + drawerpos = memory.readbyte(0x00e8); + screenpos = memory.readbyte(0x00eb); + + for x = 0, 0x3F do + for y = 0, 5 do + offset = y * 0x40 + x + 0x400; + value = memory.readbyte(offset); + color = string.format("#%02x%02x%02x", value, value, value); + x = math.fmod(x - screenpos, 0x40); + while (x < 0) do + x = x + 0x40; + end; + box(x * 3 + 8, y * 3 + 28, x * 3 + 9, y * 3 + 30, color); + box(x * 3 + 9, y * 3 + 28, x * 3 +10, y * 3 + 30, color); +-- pixel(x * 3 + 9, y * 3 + 28, color); + end; + end; + + drawerpos = drawerpos - screenpos; + while (drawerpos < 0) do + drawerpos = drawerpos + 0x40; + end; + + box(math.fmod(drawerpos, 0x40) * 3 + 7, 27, math.fmod(drawerpos, 0x40) * 3 + 11, 5 * 3 + 31, "#dd0000"); +-- box(math.fmod(screenpos, 0x40) * 3 + 7, 25, math.fmod(screenpos, 0x40) * 3 + 11, 5 * 3 + 31, "#00ff00"); + box(math.fmod(0, 0x40) * 3 + 7, 27, math.fmod(0, 0x40) * 3 + 11, 5 * 3 + 31, "#00ff00"); + + for i = 0, 5 do + offset = 0x00e8 + i; + if not lastzero[offset] then + lastzero[offset] = {}; + end; + + + value = memory.readbyte(offset); + + if lastvalue[offset] and lastvalue[offset] ~= value then + if not justblinked[offset] then + color = "#ffffff"; + else + color = "#dd0000"; + end; + justblinked[offset] = true; + else + color = "#dd0000"; + justblinked[offset] = false; + end; + + lifebar( 3, 190 + i * 8, 240, 6, value, 240, color, "#111144", false, "#000000"); + tp = math.floor(value / 240 * 240) + 4; + text(tp, 190 + i * 8, string.format("%02X", value)); + + if lastzero[offset]['time'] then + text(165, 190 + i * 8, string.format("%7sa %4df", string.format("%.2f", (lastzero[offset]['total'] / lastzero[offset]['samples'])), lastzero[offset]['time'])); + end; + if value == 0 and not lastzero[offset]['uhoh'] then + if lastzero[offset]['fr'] then + lastzero[offset]['time'] = timer - lastzero[offset]['fr']; + if lastzero[offset]['total'] then + lastzero[offset]['total'] = lastzero[offset]['total'] + lastzero[offset]['time']; + lastzero[offset]['samples'] = lastzero[offset]['samples'] + 1; + else + lastzero[offset]['total'] = lastzero[offset]['time']; + lastzero[offset]['samples'] = 1; + end; + end; + lastzero[offset]['fr'] = timer; + lastzero[offset]['uhoh'] = true; + elseif value ~= 0 then + lastzero[offset]['uhoh'] = false; + end; + + lastvalue[offset] = value; + + end; + + + +--[[ + startoffset = 0x5E0; + s = 0x120; + xs = 0x40; + ys = math.floor(s / xs); + for x = 0, xs - 1 do + for y = 0, ys - 1 do + offset = y * xs + x + startoffset; + value = memory.readbyte(offset); + if value == 0x40 then + color = "clear"; + else + value = math.fmod(value * 0x10, 0x100); + color = string.format("#%02x%02x%02x", value, value, value); + end; + + box(x * 3 + 8, y * 3 + 64, x * 3 + 10, y * 3 + 66, color); + pixel(x * 3 + 9, y * 3 + 65, color); + end; + end; + +]] + + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/FRKfunctions.lua b/branches/fceux-2.2.2/output/luaScripts/FRKfunctions.lua new file mode 100644 index 00000000..0dfaeb9b --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/FRKfunctions.lua @@ -0,0 +1,625 @@ +_FRK_Fn= {} +_FRK_Fn.version= 1 + +--FatRatKnight +-- Various little functions for use. + +-- Shortly, I will list out functions and keywords that the script provides +-- access to. But first, I feel a need to explain a few things... + +-- Option keywords are simply global variables that this auxillary script looks +-- for. If they are anything other than false or nil by the time your script +-- calls requrie("FRKfunctions"), this script will react accordingly. + +-- Reserved variable names are those the script uses, but allows access for +-- other scripts. Sorry about taking valuble names away from you, but I figure +-- you might want direct access to them. + +-- Functions are just that. Functions that do stuff, the whole point of this +-- auxillary script. I copied down their line numbers for your convenience. +-- If the quick description isn't enough, then perhaps the more detailed +-- comments and actual code might be. + +-- Options for individual functions can be changed by altering its number +-- after the require("FRKfunctions") line. + + + +--List of option keywords: + +-- _FRK_SkipRename Convenient names aren't used for these functions +-- _FRK_NoAutoReg Will not automatically fill registers + + +--List of reserved variable names: + +-- keys For checking current keys. +-- lastkeys For checking previous keys. + + +--List of functions: + +-- 82 UpdateKeys() Updates this script's key tables +-- 97 Press(button) Checks for a key hit +-- 109 PressRepeater(button) Like Press, but if held for long +-- 133 Release(button) Checks for when a key is released +-- 144 MouseMoved() Returns how far the mouse moved + +-- 166 FBoxOldFast(x1, y1, x2, y2, color) Faster at drawing, but stupid +-- 180 FBoxOld(x1, y1, x2, y2, color) Border-only box; corners fix +-- 210 FakeBox(x1, y1, x2, y2, Fill, Border) Fill-and-Border box; corners fix +-- 230 Draw[digit](Left,Top,color) Paints tiny digit on screen +-- 354 _FRK_Fn._DN_AnyBase(right, top, Number, color, bkgnd, div) + -- Paints a right-aligned number using any base from 2 to 16. +-- 405 DrawNum(right, top, Number, color, bkgnd) Paints a beautiful number +-- 413 DrawNumx(right, top, Number, color, bkgnd) Hexidecimal version + +-- 504 ProcessReg() Removes functions in registers and stores 'em +-- 521 ApplyReg() Sets registers +-- 534 AddReg(name, function) +-- 543 RemoveReg(name, pos) + +-- 564 limits(value,low,high) Returns value or specified limits +-- 575 within(value,low,high) Returns T/F; Is it within range? + + +--List of options for individual functions: + +_FRK_Fn.RepeaterDelay= 5 --How long should PressRepeater wait? + + + + + + + + + + +-- input.get family + +--***************************************************************************** +function _FRK_Fn.UpdateKeys() +--***************************************************************************** +-- Moves keys into lastkeys, then puts fresh keyboard input into keys. +-- Meant to simplify the process of registering keyhits. +-- Stick this thing at the beginning of a gui.register function or main loop. + + lastkeys= keys + keys= input.get() +end + +keys= input.get() -- Sanity. Want xmouse and ymouse to exist. +lastkeys= keys -- Otherwise, MouseMoved pings an error at me. + + +--***************************************************************************** +function _FRK_Fn.Press(button) -- Expects a key +--***************************************************************************** +-- Returns true or false. It's true at the moment the user hits the button. +-- Generally, if keys is pressed, the next loop around will set lastkeys, +-- and thus prevent returning true more than once if held. + + return (keys[button] and not lastkeys[button]) +end + + +local repeater= 0 +--***************************************************************************** +function _FRK_Fn.PressRepeater(button) -- Expects a key +--***************************************************************************** +--DarkKobold & FatRatKnight +-- Returns true or false. +-- Acts much like press if you don't hold the key down. Once held long enough, +-- it will repeatedly return true. +-- It works fine if there are multiple calls to different buttons. Not so fine +-- if there's multiple calls to the same button. Only one repeater variable... + + if keys[button] then + if not lastkeys[button] or repeater >= _FRK_Fn.RepeaterDelay then + return true + else + repeater = repeater + 1 + end + + elseif lastkeys[button] then -- To allow more calls for other buttons + repeater= 0 + end + return false +end + + +--***************************************************************************** +function _FRK_Fn.Release(button) -- Expects a key +--***************************************************************************** +-- Returns true or false. It's true at the moment the user releases the button. +-- Might be a good idea to know when the user ain't holding it anymore. +-- Eh, I don't see any obvious application, but may as well have it. + + return ((not keys[button]) and lastkeys[button]) +end + + +--***************************************************************************** +function _FRK_Fn.MouseMoved() +--***************************************************************************** +-- Returns two values: x,y +-- This function tells you how far the mouse moved since the last update. +-- It's simply the difference of what position it is now and what it once was. + + return (keys.xmouse - lastkeys.xmouse) , (keys.ymouse - lastkeys.ymouse) +end + + + + + + + + + + +-- Display family +-- For helping you see + +--***************************************************************************** +function _FRK_Fn.FBoxOldFast(x1, y1, x2, y2, color) +--***************************************************************************** +-- Gets around FCEUX's problem of double-painting the corners. +-- This particular function doesn't make sure the x and y are good. +-- Call this instead if you need processing speed and know its fine + + gui.line(x1 ,y1 ,x2-1,y1 ,color) -- top + gui.line(x2 ,y1 ,x2 ,y2-1,color) -- right + gui.line(x1+1,y2 ,x2 ,y2 ,color) -- bottom + gui.line(x1 ,y1+1,x1 ,y2 ,color) -- left +end + + +--***************************************************************************** +function _FRK_Fn.FBoxOld(x1, y1, x2, y2, color) +--***************************************************************************** +-- Gets around FCEUX's problem of double-painting the corners. +-- This has several sanity checks to ensure a properly drawn box. +-- It acts like the old-style border-only box. + + if (x1 == x2) and (y1 == y2) then -- Sanity: Is it a single dot? + gui.pixel(x1,y1,color) + + elseif (x1 == x2) or (y1 == y2) then -- Sanity: A straight line? + gui.line(x1,y1,x2,y2,color) + + else --(x1 ~= x2) and (y1 ~= y2) + local temp + if x1 > x2 then + temp= x1; x1= x2; x2= temp -- Sanity: Without these checks, + end -- This function may end up putting + if y1 > y2 then -- two or four out-of-place pixels + temp= y1; y1= y2; y2= temp -- near the corners. + end + + gui.line(x1 ,y1 ,x2-1,y1 ,color) -- top + gui.line(x2 ,y1 ,x2 ,y2-1,color) -- right + gui.line(x1+1,y2 ,x2 ,y2 ,color) -- bottom + gui.line(x1 ,y1+1,x1 ,y2 ,color) -- left + end +end + + +--***************************************************************************** +function _FRK_Fn.FakeBox(x1, y1, x2, y2, Fill, Border) +--***************************************************************************** +-- Gets around FCEUX's problem of double-painting the corners. +-- It acts like the new-style fill-and-border box. Not quite perfectly... +-- One "problem" is that, if you specify Fill only, it won't successfully +-- mimic the actual gui.box fill. + +if not Border then Border= Fill end + + gui.box(x1,y1,x2,y2,Fill,0) + FBoxOld(x1,y1,x2,y2,Border) +end + + +--### # ### ### # # ### ### ### ### ### # ## # ## ### ### +--# # ## # # # # # # # # # # # # # # # # # # # # # +--# # # ### ### ### ### ### ## ### ### # # ## # # # ## ## +--# # # # # # # # # # # # # ### # # # # # # # # +--### ### ### ### # ### ### # ### ### # # ## # ## ### # +--***************************************************************************** +_FRK_Fn.Draw= {} --Draw[button]( Left , Top , color ) +--***************************************************************************** +--Coordinates is the top-left pixel of the 3x5 digit. +--Used for drawing compact, colored numbers. + +local d= _FRK_Fn.Draw + +function d.D0(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+2,top ,left+2,top+4,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+4,color) +end + +function d.D1(left, top, color) + gui.line(left ,top+4,left+2,top+4,color) + gui.line(left+1,top ,left+1,top+3,color) + gui.pixel(left ,top+1,color) +end + +function d.D2(left, top, color) + gui.line(left ,top ,left+2,top ,color) + gui.line(left ,top+3,left+2,top+1,color) + gui.line(left ,top+4,left+2,top+4,color) + gui.pixel(left ,top+2,color) + gui.pixel(left+2,top+2,color) +end + +function d.D3(left, top, color) + gui.line(left ,top ,left+1,top ,color) + gui.line(left ,top+2,left+1,top+2,color) + gui.line(left ,top+4,left+1,top+4,color) + gui.line(left+2,top ,left+2,top+4,color) +end + +function d.D4(left, top, color) + gui.line(left ,top ,left ,top+2,color) + gui.line(left+2,top ,left+2,top+4,color) + gui.pixel(left+1,top+2,color) +end + +function d.D5(left, top, color) + gui.line(left ,top ,left+2,top ,color) + gui.line(left ,top+1,left+2,top+3,color) + gui.line(left ,top+4,left+2,top+4,color) + gui.pixel(left ,top+2,color) + gui.pixel(left+2,top+2,color) +end + +function d.D6(left, top, color) + gui.line(left ,top ,left+2,top ,color) + gui.line(left ,top+1,left ,top+4,color) + gui.line(left+2,top+2,left+2,top+4,color) + gui.pixel(left+1,top+2,color) + gui.pixel(left+1,top+4,color) +end + +function d.D7(left, top, color) + gui.line(left ,top ,left+1,top ,color) + gui.line(left+2,top ,left+1,top+4,color) +end + +function d.D8(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+2,top ,left+2,top+4,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+2,color) + gui.pixel(left+1,top+4,color) +end + +function d.D9(left, top, color) + gui.line(left ,top ,left ,top+2,color) + gui.line(left+2,top ,left+2,top+3,color) + gui.line(left ,top+4,left+2,top+4,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+2,color) +end + +function d.DA(left, top, color) + gui.line(left ,top+1,left ,top+4,color) + gui.line(left+2,top+1,left+2,top+4,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+3,color) +end + +function d.DB(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+1,top ,left+2,top+1,color) + gui.line(left+1,top+4,left+2,top+3,color) + gui.pixel(left+1,top+2,color) +end + +function d.DC(left, top, color) + gui.line(left ,top+1,left ,top+3,color) + gui.line(left+1,top ,left+2,top+1,color) + gui.line(left+1,top+4,left+2,top+3,color) +end + +function d.DD(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+2,top+1,left+2,top+3,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+4,color) +end + +function d.DE(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+1,top ,left+2,top ,color) + gui.line(left+1,top+4,left+2,top+4,color) + gui.pixel(left+1,top+2,color) +end + +function d.DF(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+1,top ,left+2,top ,color) + gui.pixel(left+1,top+2,color) +end + + +d[0],d[1],d[2],d[3],d[4]= d.D0, d.D1, d.D2, d.D3, d.D4 +d[5],d[6],d[7],d[8],d[9]= d.D5, d.D6, d.D7, d.D8, d.D9 +d[10],d[11],d[12],d[13],d[14],d[15]= d.DA, d.DB, d.DC, d.DD, d.DE, d.DF + +--***************************************************************************** +function _FRK_Fn._DN_AnyBase(right, top, Number, color, bkgnd, div) +--***************************************************************************** +-- Works with any base from 2 to 16. Paints the input number. +-- Returns the x position where it would paint another digit. +-- It only works with integers. Rounds fractions toward zero. + + if div < 2 then return end -- Prevents the function from never returning. + + local Digit= {} + local Negative= false + if Number < 0 then + Number= -Number + Negative= true + end + + Number= math.floor(Number) + if not color then color= "white" end + if not bkgnd then bkgnd= "clear" end + + local i= 0 + if Number < 1 then + Digit[1]= 0 + i= 1 + end + + while (Number >= 1) do + i= i+1 + Digit[i]= Number % div + Number= math.floor(Number/div) + end + + if Negative then i= i+1 end + local left= right - i*4 + FakeBox(left+1, top-1, right+1, top+5,bkgnd,bkgnd) + + i= 1 + while _FRK_Fn.Draw[Digit[i]] do + _FRK_Fn.Draw[Digit[i]](right-2,top,color) + right= right-4 + i=i+1 + end + + if Negative then + gui.line(right, top+2,right-2,top+2,color) + right= right-4 + end + return right +end + + +--***************************************************************************** +function _FRK_Fn.DrawNum(right, top, Number, color, bkgnd) +--***************************************************************************** +-- Paints the input number as right-aligned. Decimal version. + + return _FRK_Fn._DN_AnyBase(right, top, Number, color, bkgnd, 10) +end + +--***************************************************************************** +function _FRK_Fn.DrawNumx(right, top, Number, color, bkgnd) +--***************************************************************************** +-- Paints the input number as right-aligned. Hexadecimal version. + + return _FRK_Fn._DN_AnyBase(right, top, Number, color, bkgnd, 16) +end + + + + + + + + + + +-- Registry family +-- For overloading the usual registers with multiple separate functions. + +local RegNames= {"Before", "After", "Exit", "Gui", "Save", "Load"} + +_FRK_Fn.RegList= {} +_FRK_Fn.RegList.Before={} +_FRK_Fn.RegList.After= {} +_FRK_Fn.RegList.Exit= {} +_FRK_Fn.RegList.Gui= {} +_FRK_Fn.RegList.Save= {} +_FRK_Fn.RegList.Load= {} + +--***************************************************************************** +_FRK_Fn.RegFn= {} --RegFn[name]() For various registers +--***************************************************************************** + +function _FRK_Fn.RegFn.Before() + local i= 1 + while (_FRK_Fn.RegList.Before[i]) do + _FRK_Fn.RegList.Before[i]() + i= i+1 + end +end + +function _FRK_Fn.RegFn.After() + local i= 1 + while (_FRK_Fn.RegList.After[i]) do + _FRK_Fn.RegList.After[i]() + i= i+1 + end +end + +function _FRK_Fn.RegFn.Exit() + local i= 1 + while (_FRK_Fn.RegList.Exit[i]) do + _FRK_Fn.RegList.Exit[i]() + i= i+1 + end +end + +function _FRK_Fn.RegFn.Gui() + local i= 1 + while (_FRK_Fn.RegList.Gui[i]) do + _FRK_Fn.RegList.Gui[i]() + i= i+1 + end +end + +function _FRK_Fn.RegFn.Save() + local i= 1 + while (_FRK_Fn.RegList.Save[i]) do + _FRK_Fn.RegList.Save[i]() + i= i+1 + end +end + +function _FRK_Fn.RegFn.Load() + local i= 1 + while (_FRK_Fn.RegList.Load[i]) do + _FRK_Fn.RegList.Load[i]() + i= i+1 + end +end + + +local EmuRegisters={ + emu.registerbefore, + emu.registerafter, + emu.registerexit, + gui.register, + savestate.registersave, + savestate.registerload +} +--***************************************************************************** +function _FRK_Fn.ProcessRegisters() +--***************************************************************************** +-- Any functions in registers, such as those that might be inserted by +-- auxillary files, are removed from their registers and inserted into my +-- table of functions to execute. +-- All registers will be empty after excecution of this function. + + for i= 1, 6 do + local test= EmuRegisters[i]() +-- Make sure the function exists. Also, make sure it isn't ourselves... + if test and (test ~= _FRK_Fn.RegFn[ RegNames[i] ]) then + table.insert(_FRK_Fn.RegList[ RegNames[i] ],1,test) + end + end +end + +--***************************************************************************** +function _FRK_Fn.ApplyRegisters() +--***************************************************************************** +-- Fills the registers with functions that will excecute functions stored in +-- my tables. + + for i= 1, 6 do + if _FRK_Fn.RegList[ RegNames[i] ][ 1 ] then + EmuRegisters[i](_FRK_Fn.RegFn[ RegNames[i] ]) + end + end +end + +--***************************************************************************** +function _FRK_Fn.AddRegister(name, fn) +--***************************************************************************** +-- Name should be "Before", "After", "Exit", "Gui", "Save", or "Load". +-- Recommended for use if you plan to add functions to the register. + + table.insert(_FRK_Fn.RegList[name],fn) +end + +--***************************************************************************** +function _FRK_Fn.RemoveRegister(name, pos) +--***************************************************************************** +-- Name should be "Before", "After", "Exit", "Gui", "Save", or "Load". +-- You may omit pos. Doing so will remove and return the first function that's +-- been inserted into my table. + + return table.remove(_FRK_Fn.RegList[name],pos) +end + + + + + + + + + + +-- Miscellaneous family + +--***************************************************************************** +function _FRK_Fn.limits( value , low , high ) -- Expects numbers +--***************************************************************************** +-- Returns value, low, or high. high is returned if value exceeds high, +-- and low is returned if value is beneath low. +-- Sometimes, you'd rather crop the number to some specific limits. + + return math.max(math.min(value,high),low) +end + + +--***************************************************************************** +function _FRK_Fn.within( value , low , high ) -- Expects numbers +--***************************************************************************** +-- Returns true if value is between low and high, inclusive. False otherwise. +-- Sometimes, you just want to know if the number is within a certain range. + + return ( value >= low ) and ( value <= high ) +end + + + + + + + + + +--============================================================================= +if not _FRK_SkipRename then +--============================================================================= + UpdateKeys= _FRK_Fn.UpdateKeys + Press= _FRK_Fn.Press + PressRepeater= _FRK_Fn.PressRepeater + Release= _FRK_Fn.Release + MouseMoved= _FRK_Fn.MouseMoved + + FBoxOldFast= _FRK_Fn.FBoxOldFast + FBoxOld= _FRK_Fn.FBoxOld + FakeBox= _FRK_Fn.FakeBox + Draw= _FRK_Fn.Draw + DrawNum= _FRK_Fn.DrawNum + DrawNumx= _FRK_Fn.DrawNumx + + ProcessReg= _FRK_Fn.ProcessRegisters + ApplyReg= _FRK_Fn.ApplyRegisters + AddReg= _FRK_Fn.AddRegister + RemoveReg= _FRK_Fn.RemoveRegister + + limits= _FRK_Fn.limits + within= _FRK_Fn.within +end + +--============================================================================= +if not _FRK_NoAutoReg then +--============================================================================= + emu.registerbefore( _FRK_Fn.RegFn.Before) + emu.registerafter( _FRK_Fn.RegFn.After ) + emu.registerexit( _FRK_Fn.RegFn.Exit ) + gui.register( _FRK_Fn.RegFn.Gui ) + savestate.registersave(_FRK_Fn.RegFn.Save ) + savestate.registerload(_FRK_Fn.RegFn.Load ) +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/GUI-iup_button.lua b/branches/fceux-2.2.2/output/luaScripts/GUI-iup_button.lua new file mode 100644 index 00000000..f1028575 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/GUI-iup_button.lua @@ -0,0 +1,30 @@ +-- This script shows a simple button and click event + +-- Include our help script to load iup and take care of exit +require("auxlib"); + +function testiup() + -- Our callback function + function someAction(self, a) gui.text(10,10,"pressed me!"); end; + + -- Create a button + myButton = iup.button{title="Button Textwtf"}; + + -- Set the callback + myButton.action = someAction; + + -- Create the dialog + dialogs = dialogs + 1; + handles[dialogs] = iup.dialog{ myButton, title="IupDialog Title"; }; + + -- Show the dialog (the colon notation is equal + -- to calling handles[dialogs].show(handles[dialogs]); ) + handles[dialogs]:show(); + +end + +testiup(); + +while (true) do -- prevent script from exiting + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/GUI-iup_example.lua b/branches/fceux-2.2.2/output/luaScripts/GUI-iup_example.lua new file mode 100644 index 00000000..cb2c71cc --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/GUI-iup_example.lua @@ -0,0 +1,192 @@ +-- iup example +-- this shows a test window with all kinds of idle dialogs +-- docs: http://www.tecgraf.puc-rio.br/iup/ + +-- include our generic script (TAKES CARE OF CLOSING DIALOGS and includes the two iup systems) +require("auxlib"); + +-- Note that in the following example, parentheses are optional if you +-- are specifying tables with curly braces! Might look a little confusing. +function testiup() + + local img1 = + iup.image{ + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1}, + {1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1}, + {1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1}, + {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1}, + {1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1}, + {1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,3,2,3,2,3,2,2,3,2,2,2,3,3,3,2,2,2,3,3,2,3,2,2,3,3,3,2,2,2}, + {2,2,2,3,2,3,3,2,3,3,2,3,2,3,2,2,2,3,2,3,2,2,3,3,2,3,2,2,2,3,2,2}, + {2,2,2,3,2,3,2,2,3,2,2,3,2,2,2,2,2,3,2,3,2,2,2,3,2,3,2,2,2,3,2,2}, + {2,2,2,3,2,3,2,2,3,2,2,3,2,2,3,3,3,3,2,3,2,2,2,3,2,3,3,3,3,3,2,2}, + {2,2,2,3,2,3,2,2,3,2,2,3,2,3,2,2,2,3,2,3,2,2,2,3,2,3,2,2,2,2,2,2}, + {2,2,2,3,2,3,2,2,3,2,2,3,2,3,2,2,2,3,2,3,2,2,3,3,2,3,2,2,2,3,2,2}, + {2,2,2,3,2,3,2,2,3,2,2,3,2,2,3,3,3,3,2,2,3,3,2,3,2,2,3,3,3,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,2,2,2,3,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,2,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1}, + {1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; -- note that this ; is NOT the end of the command but a mere seperator, equivalent to a comma (,) + colors = + { + "BGCOLOR", -- 1 + "255 0 0", -- 2 + "0 0 0" -- 3 (changed because of Lua index starts at 1) + } + } + + local img2 = + iup.image{ + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,2,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,2,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,2,2,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, + {3,3,3,4,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, + {3,3,3,4,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, + {3,3,3,4,3,4,3,4,3,3,4,3,3,3,1,1,4,3,3,3,4,4,3,4,3,3,4,4,4,3,3,3}, + {3,3,3,4,3,4,4,3,4,4,3,4,3,4,1,1,3,4,3,4,3,3,4,4,3,4,3,3,3,4,3,3}, + {3,3,3,4,3,4,3,3,4,3,3,4,3,3,1,1,3,4,3,4,3,3,3,4,3,4,3,3,3,4,3,3}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {3,3,3,4,3,4,3,3,4,3,3,4,3,4,1,1,3,4,3,4,3,3,4,4,3,4,3,3,3,4,3,3}, + {3,3,3,4,3,4,3,3,4,3,3,4,3,3,1,1,4,4,3,3,4,4,3,4,3,3,4,4,4,3,3,3}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,4,3,3,3,3,3,3,3,3}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,4,3,3,3,4,3,3,3,3,3,3,3,3}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,4,4,4,3,3,3,3,3,3,3,3,3}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}, + {2,2,2,2,2,2,2,3,3,3,3,3,3,3,1,1,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,2,3,3,3,3,3,3,3,3,1,1,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, + {3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}; -- note that this ; is NOT the end of the command but a mere seperator, equivalent to a comma (,) + colors = + { + "0 255 0", -- 1 + "BGCOLOR", -- 2 + "255 0 0", -- 3 + "0 0 0" -- 4 + } + } + + mnu = iup.menu{ + iup.submenu{ + title="IupSubMenu 1", + iup.menu { + iup.item{title="IupItem 1 Checked",value="ON"}, + iup.separator{}, + iup.item{title="IupItem 2 Disabled",active="NO"} + } + }, + iup.item{title="IupItem 3"}, + iup.item{title="IupItem 4"} + } + + btn = iup.button{title="Press me!"}; + -- set the callback function, action + -- when the user clicks on the button, this function is executed + -- and in this case, it fires a silly popup message + btn.action = + function (self) + iup.Message("Why","Why oh why did you press me?"); + end + + dialogs = dialogs + 1; -- there is no ++ in Lua + handles[dialogs] = + iup.dialog{ + title="IupDialog Title", + menu=mnu, -- add the menu in the table + iup.vbox{ + iup.hbox{ + iup.frame{ + title="IupButton", + iup.vbox{ + btn, -- add the button + iup.button{title="",image=img1}, + iup.button{title="",image=img1,impress=img2} + } + }, + iup.frame{ + title="IupLabel", + iup.vbox{ + iup.label{title="Label Text"}, + iup.label{title="",separator="HORIZONTAL"}, + iup.label{title="",image=img1} + } + }, + iup.frame{ + title="IupToggle", + iup.vbox{ + iup.toggle{title="Toggle Text", value="ON"}, + iup.toggle{title="",image=img1,impress=img2}, + iup.frame{ + title="IupRadio", + iup.radio{ + iup.vbox{ + iup.toggle{title="Toggle Text"}, + iup.toggle{title="Toggle Text"} + } + } + } -- /frame + } -- /vbox + }, + iup.frame{ + title="IupText/IupMultiline", + iup.vbox{ + iup.text{size="80x",value="IupText Text"}, + iup.multiline{size="80x60", + expand="YES", + value="IupMultiline Text\nSecond Line\nThird Line"} + } + }, + iup.frame{ + title="IupList", + iup.vbox{ + iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; expand="YES",value="1"}, + iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; dropdown="YES",expand="YES",value="2"}, + iup.list{"Item 1 Text","Item 2 Text","Item 3 Text"; editbox="YES",expand="YES",value="3"} + } + } + }, -- /hbox + iup.canvas{bgcolor="128 255 0"}, + gap="5", + alignment="ARIGHT", + margin="5x5" + } -- /vbox + }; + + handles[dialogs]:show(); -- this actually shows you the dialog. Note that this is equivalent to calling handles[dialogs].show(handles[dialogs]); just shorter. + +end + +testiup(); -- note that this is not called from within the loop! + +-- once the loop quits, the script exits and all dialogs are automatically destroyed +while (true) do + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/Galaxian.lua b/branches/fceux-2.2.2/output/luaScripts/Galaxian.lua new file mode 100644 index 00000000..d832166e --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Galaxian.lua @@ -0,0 +1,186 @@ +--Galaxian +--Written by XKeeper +--Accesses the Music Player Easter Egg and displays the songs & information + +require "x_functions"; +require "x_interface"; + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu:5/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(6); +end; + +function musicplayer() + resets = memory.readbyte(0x0115); + song = memory.readbyte(0x0002); + songlua = math.max(1, math.floor(resets / 45)); + speed = memory.readbyte(0x0004); + speedde = memory.readbyte(0x0104); -- it's really an AND. But the only two values used are 0F and 07, so this modulous works. + pos = memory.readbyte(0x0000); + note = memory.readbyte(0x0001); + offsetb = song * 0x0100 + 0x4010 - 1; + offset = song * 0x0100 + pos - 1 + 0x4010; + note1 = 0x10 - math.floor(note / 0x10); + note2 = math.fmod(note, 0x10); + if note1 == 0x10 then note1 = 0 end; + + + text( 35, 42, string.format("Song Position: %02X%02X", song, pos)); + text( 40, 50, string.format("ROM Offset: %04X", offset)); + text( 43, 58, string.format("Song Speed: %02X", speed)); + text(105, 66, string.format(" %02X", math.fmod(speedde, speed))); + + lifebar(186, 21, 64, 4, note1, 15, "#8888ff", "#000066", false, "#ffffff"); + lifebar(186, 29, 64, 4, note2, 15, "#8888ff", "#000066", false, "#ffffff"); + text(178, 20, string.format("%X\n%X", note1, note2)); + + lifebar( 44, 67, 64, 4, math.fmod(speedde, speed), speed, "#8888ff", "#000066", false, "#ffffff"); + + if control.button(75, 90, 84, 1, "Toggle hex viewer") then + hexmap = not hexmap; + end; + + if hexmap then + songdata = {}; + songdata2 = {}; + for i = 0x00, 0xFF do + if i >= songs[songlua]['st'] and i <= songs[songlua]['en'] or true then + o = string.format("%02X", rom.readbyte(offsetb + i)); + else + o = ""; + end; + x = math.fmod(i, 0x10); + y = math.floor(i / 0x70); + if not songdata2[x] then + songdata2[x] = {}; + end; + if not songdata2[x][y] then + songdata2[x][y] = o; + -- songdata2[x][y] = string.format("%02X", y); + else + songdata2[x][y] = songdata2[x][y] .."\n".. o; + end; + end; + + for x = 0, 0x0F do + text(29 + x * 14, 100 + 8 * 0, songdata2[x][0]); + text(29 + x * 14, 100 + 8 * 7, songdata2[x][1]); + text(29 + x * 14, 100 + 8 * 14, songdata2[x][2]); + end; + + oboxx = 29 + math.fmod(pos, 0x10) * 14; + oboxy = 100 + 8 * math.floor(pos / 0x10); + c = "#ff0000"; + if math.fmod(timer, 4) < 2 then + c = "#FFFFFF"; + end; + box(oboxx, oboxy + 0, oboxx + 14, oboxy + 10, c); + end; + + if pos >= songs[songlua]['en'] then --and pos == 0xFE then + if not songs[songlua]['xx'] then + memory.writebyte(0x0104, 0xFF); +-- text(50, 50, "LOCK"); + else + memory.writebyte(0x0115, songs[songs[songlua]['xx']]['rv']); + memory.writebyte(0x0002, songs[songs[songlua]['xx']]['sv']); + memory.writebyte(0x0004, songs[songs[songlua]['xx']]['sp']); + memory.writebyte(0x0000, songs[songs[songlua]['xx']]['st']); + end; + end; + + for id, val in pairs(songs) do + if id == songlua then + c = "#8888ff"; + if math.fmod(timer, 4) < 2 then + c = "#FFFFFF"; + end; + else + c = nil; + end; + if control.button(195, 33 + 11 * id, 57, 1, string.format("Play song %d", id), c, true) then +-- resetrequired = true; +-- memory.register(0x0104, nil); + memory.writebyte(0x0115, val['rv']); + memory.writebyte(0x0002, val['sv']); + memory.writebyte(0x0004, val['sp']); + memory.writebyte(0x0000, val['st']); + end; + end; + + if resetrequired then + text(50, 85, "Please soft-reset game."); + if movie.framecount() == 0 then + resetrequired = false; + end; + end; +end; + + +songs = { + -- resets song `id` speed start end + { rv = 0x2E, sv = 0x1B, sp = 0x0F, st = 0x00, en = 0xC6 }, + { rv = 0x5A, sv = 0x18, sp = 0x07, st = 0x00, en = 0xC2 }, + { rv = 0x87, sv = 0x06, sp = 0x0F, st = 0x00, en = 0x7F }, + { rv = 0xB4, sv = 0x16, sp = 0x0F, st = 0x50, en = 0xAF }, + { rv = 0xE1, sv = 0x1A, sp = 0x0F, st = 0x80, en = 0xF8, xx = 0x01 }, + }; +timer = 0; +hexmap = true; + +while true do + + timer = timer + 1; + input.update(); + + if memory.readbyte(0x0101) == 1 then + musicplayer(); + + else + filledbox(23, 49, 233, 130, "#000000"); + text( 25, 50, "Normally you'd have to do something insane"); + text( 52, 58, "like push RESET 45 times and"); + text( 56, 66, "hold A+B on P2's controller."); + + text( 28, 82, "Lucky for you, though, we borrowed this."); + text( 73, 90, "Feel free to use it."); + + text( 73, 119, "(Yeah, we've got that)"); + + timer2 = math.fmod(timer, 60); + if timer2 >= 30 then timer2 = 60 - timer2; end; + timer2 = math.floor((timer2 / 30) * 255); + c = string.format("#%02X%02XFF", timer2, timer2); + + if control.button(110, 106, 37, 1, " EASY ", c, "#ffffff") then + memory.writebyte(0x0101, 0x01); + memory.writebyte(0x0115, songs[2]['rv']); + memory.writebyte(0x0002, songs[2]['sv']); + memory.writebyte(0x0004, songs[2]['sp']); + memory.writebyte(0x0000, songs[2]['st']); + FCEU.softreset(); +-- text(1, 1, 'woohoo'); + end; + end; + FCEU.frameadvance(); + +end; diff --git a/branches/fceux-2.2.2/output/luaScripts/Gradius-BulletHell.lua b/branches/fceux-2.2.2/output/luaScripts/Gradius-BulletHell.lua new file mode 100644 index 00000000..29fe3a85 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Gradius-BulletHell.lua @@ -0,0 +1,439 @@ +SCRIPT_TITLE = "Gradius - Bullet Hell" +SCRIPT_VERSION = "1.0" + +require "m_utils" +m_require("m_utils",0) + +--[[ +Gradius - Bullet Hell +version 1.0 by miau + +Visit http://morphcat.de/lua/ for the most recent version and other scripts. + + +Controls + Press select to fire a bomb that will destroy all enemy bullets and grant you + invincibility for a short period of time. + +Supported roms + Gradius (J), Gradius (U), Gradius (E) + +Known bugs + - dying from blue bullets doesn't trigger the death sound effect +-]] + +--configurable vars +local BOMBS_PER_LIFE = 5 +local HITBOX = {-2, 4, 9, 9} --vic viper's hit box for collision detection with blue bullets +-------------------------------------------------------------------------------------------- + + + +local MAX_EXSPR = 64 +local timer = 0 +local spr = {} +local exspr = {} +local exsprdata = {} +local deathtimer = 0 +local bombtimer = 0 +local paused = 0 +local bombs = BOMBS_PER_LIFE +local bulletimg = "" + + +function makebinstr(t) + local str = "" + for i,v in ipairs(t) do + str = str..string.char(v) + end + return str +end + +function initialize() + --Transparency doesn't seem to work for gd images, bummer! + bulletimg = makebinstr( { + 0xff, 0xfe, 0, 0x6, 0, 0x6, 0x1, 0xff, + 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0x2, 0x33, 0x6e, 0, + 0x2, 0x33, 0x6e, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0x2, 0x33, 0x6e, 0, 0x4d, 0xb6, 0xff, 0, + 0xdb, 0xff, 0xfc, 0, 0x2, 0x33, 0x6e, 0, + 0, 0, 0, 0, 0x2, 0x33, 0x6e, 0, + 0x4d, 0xb6, 0xff, 0, 0x4d, 0xb6, 0xff, 0, + 0xdb, 0xff, 0xfc, 0, 0xdb, 0xff, 0xfc, 0, + 0x2, 0x33, 0x6e, 0, 0x2, 0x33, 0x6e, 0, + 0xdb, 0xff, 0xfc, 0, 0xdb, 0xff, 0xfc, 0, + 0x4d, 0xb6, 0xff, 0, 0x4d, 0xb6, 0xff, 0, + 0x2, 0x33, 0x6e, 0, 0, 0, 0, 0, + 0x2, 0x33, 0x6e, 0, 0xdb, 0xff, 0xfc, 0, + 0x4d, 0xb6, 0xff, 0, 0x2, 0x33, 0x6e, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0x2, 0x33, 0x6e, 0, + 0x2, 0x33, 0x6e, 0, 0, 0, 0, 0, + 0, 0, 0 } ) + + for i=0,31 do + spr[i] = { + status=0, + id=0, + x=0, + y=0, + timer=-1, + } + end +end + + +function createexsprite(s) + for i=0,MAX_EXSPR-1 do + if(exspr[i]==nil) then + exspr[i]=s + if(exspr[i].id==nil) then + exspr[i].id=0 + end + if(exspr[i].x==nil) then + exspr[i].x=0 + end + if(exspr[i].y==nil) then + exspr[i].y=0 + end + if(exspr[i].vx==nil) then + exspr[i].vx=0 + end + if(exspr[i].vy==nil) then + exspr[i].vy=0 + end + if(exspr[i].timer==nil) then + exspr[i].timer=0 + end + if(exspr[i].ai==nil) then + exspr[i].ai="" + end + return exspr[i] + end + end + return nil +end + +function destroyallexsprites() + exspr = {} +end + +function destroyexsprite(i) + exspr[i] = nil +end + +function destroysprite(i) + memory.writebyte(0x100+i,0x00) + memory.writebyte(0x120+i,0x00) + memory.writebyte(0x300+i,0x00) +end + + +function drawexsprite(id,x,y) + gui.gdoverlay(x, y, bulletimg) +end + + +function getvicdistance(x,y) + return getdistance(vic.x+4,vic.y+8,x,y) +end + +function doexspriteai(s) + if(s.ai=="Stray") then + if(s.timer==0) then + s.vx = -3 + s.vy = AND(timer,0x0F) / 8 - 1 + end + elseif(s.ai=="AimOnce") then + if(s.timer==0) then + s.vx,s.vy = get_vdir(s,vic) + s.vx = s.vx * 2 + s.vy = s.vy * 2 + --s.vy = AND(timer,0x0F) / 8 - 1 + end + elseif(s.ai=="AimDelayed") then + if(s.timer>=30 and s.timer<=33) then + local x,y = get_vdir(s,vic) + s.vx = (x+s.vx) + s.vy = (y+s.vy) + end + elseif(s.ai=="AimRight") then + if(s.timer==0) then + s.vx,s.vy = get_vdir(s,vic) + s.vx = s.vx * 2.5 + s.vy = s.vy * 1.5 + end + elseif(s.ai=="AimLeft") then + if(s.timer==0) then + s.vx,s.vy = get_vdir(s,vic) + s.vx = s.vx * 1.5 + s.vy = s.vy * 2.5 + end + elseif(s.ai=="BossPattern1") then + if(s.timer==0) then + s.vx = math.random(-100,0)/50 + s.vy = math.random(-100,0)/70 + elseif(s.timer>=30 and s.timer <=35) then + s.vx=s.vx/1.1 + s.vy=s.vy/1.1 + elseif(s.timer==70) then + local x,y = get_vdir(s,vic) + s.vx = x*3 + s.vy = y*3 + end + elseif(s.ai=="LimitedLifeSpan") then + if(s.timer>120) then + s.x=999 --results in death + end + end + + if(s.timer>600) then --delete extended sprites after 10 seconds in case one gets stuck on screen + s.x=999 + end +end + +function doboss1ai(s) + if(s.timer>80 and s.timer<320 and AND(s.timer,63)==0) then + createexsprite({x=s.x,y=s.y,ai="BossPattern1"}) + createexsprite({x=s.x,y=s.y,ai="BossPattern1"}) + createexsprite({x=s.x,y=s.y,ai="BossPattern1"}) + createexsprite({x=s.x,y=s.y,ai="BossPattern1"}) + createexsprite({x=s.x,y=s.y,ai="BossPattern1"}) + createexsprite({x=s.x,y=s.y,ai="BossPattern1"}) + createexsprite({x=s.x,y=s.y,ai="BossPattern1"}) + end + if(s.timer>320 and s.timer<520) then --pattern2 a + if(math.mod(s.timer,27)<=9 and AND(s.timer,3)==3) then + createexsprite({x=s.x,y=s.y,vx=-0.2,ai="AimDelayed"}) + end + end + if(s.timer>320 and s.timer<520) then --pattern2 b + if(AND(s.timer,63)==0) then + createexsprite({x=s.x,y=s.y,vx=-0.7,vy=-1.6}) + createexsprite({x=s.x,y=s.y,vx=-1.1,vy=-0.8}) + createexsprite({x=s.x,y=s.y,vx=-1.2,vy=-0}) + createexsprite({x=s.x,y=s.y,vx=-1.1,vy=0.8}) + createexsprite({x=s.x,y=s.y,vx=-0.7,vy=1.6}) + end + elseif(s.timer>520) then + s.timer = 60 + end +end + + +function dospriteai(s) + if(s.id==0x85) then --Fan + if(s.timer==30) then + createexsprite({x=s.x,y=s.y,ai="Stray"}) + end + elseif(s.id==0x86) then --Jumper + if(AND(s.timer,127)==40) then + createexsprite({x=s.x,y=s.y,vx=-1.5,vy=-0.5}) + createexsprite({x=s.x,y=s.y,vx=-1,vy=-1.1}) + createexsprite({x=s.x,y=s.y,vx=0,vy=-1.4}) + createexsprite({x=s.x,y=s.y,vx=1,vy=-1.1}) + createexsprite({x=s.x,y=s.y,vx=1.5,vy=-0.5}) + end + elseif(s.id==0x88) then --Rugul + if(AND(s.timer,63)==30) then + createexsprite({x=s.x,y=s.y,ai="Stray"}) + end + elseif(s.id==0x84 or s.id==0x9C) then --Fose, Uska(?) + if(AND(s.timer,63)==30) then + createexsprite({x=s.x,y=s.y,vx=0,vy=-2}) + elseif(AND(s.timer,63)==60) then + createexsprite({x=s.x,y=s.y,vx=0,vy=2}) + end + elseif(s.id==0x89 or s.id==0x8C) then --Rush + if(AND(timer,63)==5) then + createexsprite({x=s.x,y=s.y,vx=-1,vy=-1}) + end + elseif(s.id==0x96) then --Moai + elseif(s.id==0x97) then --Mother and Child + if(AND(timer,7)==0) then + local t = s.timer/15 + createexsprite({x=s.x+16,y=s.y+16,vx=math.sin(t)-1,vy=math.cos(t),ai="LimitedLifeSpan"}) + end + elseif(s.id==0x8B) then --Zabu + if(s.timer==5) then + createexsprite({x=s.x,y=s.y,vx=0.5,ai="AimDelayed"}) + end + elseif(s.id==0x92 or s.id==0x93 or s.id==0x87 or s.id==0x91) then --Dee-01, Ducker + --if(s.timer==5) then + local t = AND(s.timer,127) + if(t>60 and t<79 and AND(s.timer,3)==3) then + --createexsprite({x=s.x,y=s.y,ai="AimOnce"}) + createexsprite({x=s.x,y=s.y,ai="AimOnce"}) + end + elseif(s.id==0x98) then --boss... + doboss1ai(s) + end +end + + +function updatevars() + paused = memory.readbyte(0x0015) + if(paused==1) then + return + end + --load original sprites from ram + for i=0,31 do + --if(i==0 or memory.readbyte(0x0300+i)~=0) then + if(memory.readbyte(0x0300+i)~=spr[i].id) then + spr[i].timer = 0 + end + spr[i].status=memory.readbyte(0x0100+i) --1=alive, 2=dead + spr[i].id=memory.readbyte(0x0300+i) + spr[i].x=memory.readbyte(0x0360+i) + spr[i].y=memory.readbyte(0x0320+i) + spr[i].timer=spr[i].timer+1 + if(spr[i].id==0) then + spr[i].timer = 0 + else + dospriteai(spr[i]) + end + + if(i>3 and bombtimer>0 and getvicdistance(spr[i].x+4,spr[i].y+4)<30) then + if(spr[i].id~=0x29 and spr[i].id~=0x01 and spr[i].id~=0x99 and spr[i].id~=0x98 and spr[i].id~=0x94 and spr[i].id~=0x97 and spr[i].id~=0x96 and spr[i].id~=0x1E) then + --excluded: hidden bonus (0x29), power ups and moai bullets (0x01), boss (0x99+0x98), tentacle (0x94), mother (0x97), moai (0x96), gate (0x1E) + destroysprite(i) + end + end + --end + end + vic = spr[0] + + + + + if(deathtimer>0) then + if(deathtimer==120) then + destroyallexsprites() + deathtimer = 0 + bombs = BOMBS_PER_LIFE + else + if(deathtimer==1) then + --this is part of what gradius does to kill vic viper... + --faster and without the annoying sound effect. who cares! + memory.writebyte(0x4C,0x78) + memory.writebyte(0x0100,0x02) --status = dead + memory.writebyte(0x0160,0x00) + memory.writebyte(0x0140,0x00) + memory.writebyte(0x1B,0xA0) + memory.writebyte(0x0120,0x2D) --chr?-- + end + deathtimer = deathtimer + 1 + end + end + + + local jp = joypad.get(1) + if(jp.select and jp.select~=last_select and bombs>0) then + bombtimer = 1 + bombs = bombs - 1 + destroyallexsprites() + --destroy bullets + for i=1,31 do + if(spr[i].id<4 and spr[i].id~=1) then + destroysprite(i) + end + end + end + last_select = jp.select + + + if(last_vic_status~=vic.status) then + if(vic.status==2) then --vic died in the original game, start death timer to destroy all extended sprites + deathtimer = 1 + end + end + last_vic_status = vic.status + + --calculations on extended sprites + for i=0,MAX_EXSPR-1 do + if(exspr[i]~=nil) then + if(bombtimer>0 and getvicdistance(exspr[i].x+4,exspr[i].y+4)<25) then + destroyexsprite(i) + else + doexspriteai(exspr[i]) + exspr[i].timer = exspr[i].timer + 1 + exspr[i].x=exspr[i].x+exspr[i].vx + exspr[i].y=exspr[i].y+exspr[i].vy + if(exspr[i].x>255 or exspr[i].x<0 or exspr[i].y>255 or exspr[i].y<0) then + --destroy exsprite + exspr[i]=nil + break + end + --collision check with vic viper + if(deathtimer==0 and vic.status==1 and exspr[i].x>=vic.x+HITBOX[1] and exspr[i].x<=vic.x+HITBOX[3] + and exspr[i].y>=vic.y+HITBOX[2] and exspr[i].y<=vic.y+HITBOX[4]) then + deathtimer = 1 + end + end + end + end + + +end + +function render() + --bcbox(vic.x-2, vic.y+4, vic.x+9, vic.y+9, "#ffffff") + + gui.text(0, 8, string.format("bombs %d",bombs)); + --gui.text(0, 8, string.format("Lives %d",memory.readbyte(0x0020))); + --gui.text(0, 28, string.format("bombtimer %d",bombtimer)); + + --[[for i=1,31 do + if(spr[i].id~=0) then + gui.text(spr[i].x, spr[i].y, string.format("%X",spr[i].id)); + end + end--]] + + for i=0,MAX_EXSPR-1 do + if(exspr[i]~=nil) then + drawexsprite(exspr[i].id,exspr[i].x,exspr[i].y) + end + end + + + if(bombtimer>0) then + if(bombtimer<12) then + memory.writebyte(0x11,0xFF) --monochrome screen + else + memory.writebyte(0x11,0x1E) + end + bombtimer = bombtimer + 1 + for i=0,64 do + local x = vic.x+4+math.sin(i)*bombtimer*4 + math.random(0,12) + local y = vic.y+8+math.cos(i)*bombtimer*4 + math.random(0,12) + local c = 255-bombtimer + local cs = string.format("#%02x%02x00",c,c) + bcpixel(x,y,cs) + bcpixel(x-1,y,cs) + bcpixel(x+1,y,cs) + bcpixel(x,y+1,cs) + bcpixel(x,y-1,cs) + + x = vic.x+4+math.sin(i)*(20+math.sin(bombtimer/5)) + y = vic.y+8+math.cos(i)*(20+math.sin(bombtimer/5)) + bcpixel(x,y,cs) + bcpixel(x-1,y,cs) + bcpixel(x,y-1,cs) + end + if(bombtimer==180) then + bombtimer=0 + end + end +end + + +initialize() +vic = spr[0] +while(true) do + updatevars() + render() + EMU.frameadvance() + timer = timer + 1 +end diff --git a/branches/fceux-2.2.2/output/luaScripts/JumpingFCEUXWindow.lua b/branches/fceux-2.2.2/output/luaScripts/JumpingFCEUXWindow.lua new file mode 100644 index 00000000..918e473a --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/JumpingFCEUXWindow.lua @@ -0,0 +1,33 @@ +require 'winapi' + +fceuxWindowDY = 0; +fceuxWindowDX = 0; +MIN_JUMP_POWER = -20; + +function jumpingWindow() + desktopWidth, desktopHeight = winapi.get_desktop_window():get_bounds(); + + fceuxWindow = winapi.find_window("FCEUXWindowClass", nil); + fceuxWindowX, fceuxWindowY = fceuxWindow:get_position(); + fceuxWindowWidth, fceuxWindowHeight = fceuxWindow:get_bounds(); + + fceuxWindowDY = fceuxWindowDY + 1; -- gravity + fceuxWindowY = fceuxWindowY + fceuxWindowDY; + if (fceuxWindowY + fceuxWindowHeight >= desktopHeight and fceuxWindowDY >= 0) then + fceuxWindowY = desktopHeight - fceuxWindowHeight - 1; + -- bounce from floor + fceuxWindowDY = (0 - fceuxWindowDY) * 0.9; + if (fceuxWindowDY > MIN_JUMP_POWER) then fceuxWindowDY = MIN_JUMP_POWER - math.random(10); end + fceuxWindowDX = math.random(-7, 7); + end + + fceuxWindowX = fceuxWindowX + fceuxWindowDX; + if ((fceuxWindowX < 0 and fceuxWindowDX < 0) or (fceuxWindowX + fceuxWindowWidth >= desktopWidth and fceuxWindowDX > 0)) then + -- bounce from sides + fceuxWindowDX = 0 - fceuxWindowDX; + end + + fceuxWindow:resize(fceuxWindowX, fceuxWindowY, fceuxWindowWidth, fceuxWindowHeight); +end + +emu.registerbefore(jumpingWindow); diff --git a/branches/fceux-2.2.2/output/luaScripts/Luabot.lua b/branches/fceux-2.2.2/output/luaScripts/Luabot.lua new file mode 100644 index 00000000..e20cd9f7 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Luabot.lua @@ -0,0 +1,249 @@ +-- BeeBee, LuaBot Frontend v1.07 +-- qFox, 2 August 2008 + +-- we need iup, so include it here (also takes care of cleaning up dialog when script exits) +require 'auxlib'; + +local botVersion = 1; -- check this version when saving/loading. this will change whenever the botsave-file changes. + +function createTextareaTab(reftable, tmptable, token, tab, fun, val) -- specific one, at that :) + reftable[token] = iup.multiline{title="Contents",expand="YES", border="YES" }; -- ,value=val}; + tmptable[token] = iup.vbox{iup.label{title="function "..fun.."()\n local result = no;"},reftable[token],iup.label{title=" return result;\nend;"}}; + tmptable[token].tabtitle = tab; +end; +function createTextareaTab2(reftable, tmptable, token, fun, arg) -- specific one, at that :) this one generates no return values + reftable[token] = iup.multiline{title="Contents",expand="YES", border="YES" }; --,value=fun}; + if (arg) then + tmptable[token] = iup.vbox{iup.label{title="function "..fun.."(wasOk) -- wasOk (boolean) is true when the attempt was ok\n"},reftable[token],iup.label{title="end;"}}; + else + tmptable[token] = iup.vbox{iup.label{title="function "..fun.."()\n"},reftable[token],iup.label{title="end;"}}; + end; + tmptable[token].tabtitle = fun; +end; + +function createGUI(n) + -- this table will keep the references for easy and fast lookup. + local reftable = {}; + -- this table we wont keep, it holds references to (mostly) cosmetic elements of the dialog + local tmptable = {}; + + -- ok, dont be intimidated by the next eight blocks of code. they basically all say the same! + -- every line creates an element for the gui and sets it up. every block is a tabbed pane and + -- they are all put into another tabbed pane themselves. all references are put into a table + -- paired with the tokens in the basicbot framework. this allows us to easily walk through + -- all the pairs of and replace them in the file, uppon writing. + + reftable.ROMNAME = iup.text{title="rom name", size="300x", value="something_or_the_other.rom"}; + tmptable.ROMNAME = iup.hbox{iup.label{title="Rom name: ", size="50x"}, reftable.ROMNAME, iup.fill{}}; + reftable.COMMENT = iup.text{title="comment", size="300x",value="a botscript for some game"}; + tmptable.COMMENT = iup.hbox{iup.label{title="Comment: ", size="50x"}, reftable.COMMENT, iup.fill{}}; + reftable.VERSION = iup.text{title="version", size="70x",value="1.00"}; + tmptable.VERSION = iup.hbox{iup.label{title="Version: ", size="50x"}, reftable.VERSION, iup.fill{}}; + tmptable.SAVE = iup.button{title="Save contents"}; + -- the callback is set after the dialog is created. we need the references to all controls for saving to work :) + tmptable.LOAD = iup.button{title="Load contents"}; + tmptable.WRITE = iup.button{title="Write bot script"}; + general = iup.vbox{tmptable.ROMNAME,tmptable.COMMENT,tmptable.VERSION,iup.fill{size="5x",},tmptable.SAVE,iup.fill{size="5x",},tmptable.LOAD,iup.fill{size="5x",},tmptable.WRITE,iup.fill{}}; + general.tabtitle = "General"; + + createTextareaTab(reftable, tmptable, "bA1", "A", "isPressedA1", "a1"); + createTextareaTab(reftable, tmptable, "bB1", "B", "isPressedB1", "b1"); + createTextareaTab(reftable, tmptable, "START1", "Start", "isPressedStart1", "start1"); + createTextareaTab(reftable, tmptable, "SELECT1","Select", "isPressedSelect1", "select1"); + createTextareaTab(reftable, tmptable, "UP1", "Up", "isPressedUp1", "up1"); + createTextareaTab(reftable, tmptable, "DOWN1", "Down", "isPressedDown1", "down1"); + createTextareaTab(reftable, tmptable, "LEFT1", "Left", "isPressedLeft1", "left1"); + createTextareaTab(reftable, tmptable, "RIGHT1", "Right", "isPressedRight1", "right1"); + tabs1 = iup.vbox{iup.tabs{tmptable.bA1,tmptable.bB1,tmptable.START1,tmptable.SELECT1,tmptable.UP1,tmptable.DOWN1,tmptable.LEFT1,tmptable.RIGHT1}}; + tabs1.tabtitle = "Player 1"; + + createTextareaTab(reftable, tmptable, "bA2", "A", "isPressedA2", "a2"); + createTextareaTab(reftable, tmptable, "bB2", "B", "isPressedB2", "b2"); + createTextareaTab(reftable, tmptable, "START2", "Start", "isPressedStart2", "start2"); + createTextareaTab(reftable, tmptable, "SELECT2","Select", "isPressedSelect2", "select2"); + createTextareaTab(reftable, tmptable, "UP2", "Up", "isPressedUp2", "up2"); + createTextareaTab(reftable, tmptable, "DOWN2", "Down", "isPressedDown2", "down2"); + createTextareaTab(reftable, tmptable, "LEFT2", "Left", "isPressedLeft2", "left2"); + createTextareaTab(reftable, tmptable, "RIGHT2", "Right", "isPressedRight2", "right2"); + tabs2 = iup.vbox{iup.tabs{tmptable.bA2,tmptable.bB2,tmptable.START2,tmptable.SELECT2,tmptable.UP2,tmptable.DOWN2,tmptable.LEFT2,tmptable.RIGHT2}}; + tabs2.tabtitle = "Player 2"; + + createTextareaTab(reftable, tmptable, "bA3", "A", "isPressedA3", "a3"); + createTextareaTab(reftable, tmptable, "bB3", "B", "isPressedB3", "b3"); + createTextareaTab(reftable, tmptable, "START3", "Start", "isPressedStart3", "start3"); + createTextareaTab(reftable, tmptable, "SELECT3","Select", "isPressedSelect3", "select3"); + createTextareaTab(reftable, tmptable, "UP3", "Up", "isPressedUp3", "up3"); + createTextareaTab(reftable, tmptable, "DOWN3", "Down", "isPressedDown3", "down3"); + createTextareaTab(reftable, tmptable, "LEFT3", "Left", "isPressedLeft3", "left3"); + createTextareaTab(reftable, tmptable, "RIGHT3", "Right", "isPressedRight3", "right3"); + tabs3 = iup.vbox{iup.tabs{tmptable.bA3,tmptable.bB3,tmptable.START3,tmptable.SELECT3,tmptable.UP3,tmptable.DOWN3,tmptable.LEFT3,tmptable.RIGHT3}}; + tabs3.tabtitle = "Player 3"; + + createTextareaTab(reftable, tmptable, "bA4", "A", "isPressedA4", "a4"); + createTextareaTab(reftable, tmptable, "bB4", "B", "isPressedB4", "b4"); + createTextareaTab(reftable, tmptable, "START4", "Start", "isPressedStart4", "start4"); + createTextareaTab(reftable, tmptable, "SELECT4","Select", "isPressedSelect4", "select4"); + createTextareaTab(reftable, tmptable, "UP4", "Up", "isPressedUp4", "up4"); + createTextareaTab(reftable, tmptable, "DOWN4", "Down", "isPressedDown4", "down4"); + createTextareaTab(reftable, tmptable, "LEFT4", "Left", "isPressedLeft4", "left4"); + createTextareaTab(reftable, tmptable, "RIGHT4", "Right", "isPressedRight4", "right4"); + tabs4 = iup.vbox{iup.tabs{tmptable.bA4,tmptable.bB4,tmptable.START4,tmptable.SELECT4,tmptable.UP4,tmptable.DOWN4,tmptable.LEFT4,tmptable.RIGHT4}}; + tabs4.tabtitle = "Player 4"; + + createTextareaTab2(reftable, tmptable, "ONSTART", "onStart", false); + createTextareaTab2(reftable, tmptable, "ONFINISH", "onFinish", false); + createTextareaTab2(reftable, tmptable, "ONSEGMENTSTART","onSegmentStart", false); + createTextareaTab2(reftable, tmptable, "ONSEGMENTEND", "onSegmentEnd", false); + createTextareaTab2(reftable, tmptable, "ONATTEMPTSTART","onAttemptStart", false); + createTextareaTab2(reftable, tmptable, "ONATTEMPTEND", "onAttemptEnd", true); + createTextareaTab2(reftable, tmptable, "ONINPUTSTART", "onInputStart", false); + createTextareaTab2(reftable, tmptable, "ONINPUTEND", "onInputEnd", false); + tabs5 = iup.vbox{iup.tabs{tmptable.ONSTART, tmptable.ONFINISH, tmptable.ONSEGMENTSTART, tmptable.ONSEGMENTEND, tmptable.ONATTEMPTSTART, tmptable.ONATTEMPTEND, tmptable.ONINPUTSTART, tmptable.ONINPUTEND}}; + tabs5.tabtitle = "Events"; + + createTextareaTab(reftable, tmptable, "SCORE", "score", "getScore", "score"); + createTextareaTab(reftable, tmptable, "TIE1", "tie1", "getTie1", "tie1"); + createTextareaTab(reftable, tmptable, "TIE2", "tie2", "getTie2", "tie2"); + createTextareaTab(reftable, tmptable, "TIE3", "tie3", "getTie3", "tie3"); + createTextareaTab(reftable, tmptable, "TIE4", "tie4", "getTie4", "tie4"); + tabs6 = iup.vbox{iup.tabs{tmptable.SCORE,tmptable.TIE1,tmptable.TIE2,tmptable.TIE3,tmptable.TIE4}}; + tabs6.tabtitle = "Score"; + + createTextareaTab(reftable, tmptable, "ISRUNEND", "isRunEnd", "isRunEnd", "isRunEnd"); + createTextareaTab(reftable, tmptable, "MUSTROLLBACK", "mustRollBack", "mustRollBack", "mustRollBack"); + createTextareaTab(reftable, tmptable, "ISSEGMENTEND", "isSegmentEnd", "isSegmentEnd", "isSegmentEnd"); + createTextareaTab(reftable, tmptable, "ISATTEMPTEND", "isAttemptEnd", "isAttemptEnd", "isAttemptEnd"); + createTextareaTab(reftable, tmptable, "ISATTEMPTOK", "isAttemptOk", "isAttemptOk", "isAttemptOk"); + tabs7 = iup.vbox{iup.tabs{tmptable.ISRUNEND,tmptable.MUSTROLLBACK,tmptable.ISSEGMENTEND,tmptable.ISATTEMPTEND,tmptable.ISATTEMPTOK}}; + tabs7.tabtitle = "Selection"; + + playertabs = iup.tabs{general,tabs1,tabs2,tabs3,tabs4,tabs5,tabs6,tabs7,title}; + handles[n] = iup.dialog{playertabs, title="BeeBee; BasicBot Frontend", size="450x200"} + handles[n]:showxy(iup.CENTER, iup.CENTER) + + -- now set the callback function for the save button. this will use all the references above. + -- these remain ok in the anonymous function by something called "closures". this means that + -- these variables, although local to the scope of the function, will remain their value in + -- the anonymous function. hence we can refer to them and fetch their contents, even though + -- you cant refer to them outside the context of the createGUI function. + tmptable.WRITE.action = + function(self, n) + local file = iup.filedlg{allownew="YES",dialogtype="SAVE",directory="./lua",showhidden="YES",title="Save botfile"}; + file:popup(iup.ANYWHERE,iup.ANYWHERE); + + if (file.value == "NULL") then + iup.Message("An error occurred trying to save your settings"); + return; + elseif (file.status == "-1") then + iup.Message("IupFileDlg","Operation canceled"); + return; + end + + -- ok, file selected, if an error occurred or user canceled, the function already returned, so lets write the bot! + + -- get the framework first. we need it to find the relevant tokens + local fh = assert(io.open("luabot_framework.lua","r")); + local framework = fh:read("*a"); + fh:close(); + + -- now replace all tokens by gui values + -- this is where the reftable comes in very handy :p + for token,obj in pairs(reftable) do + local st00pid = (reftable[token].value or ""); + framework = string.gsub(framework, "-- "..token, st00pid, 1); -- if nothing was entered, obj.value returns nil (not ""), so we have to make that translation + end; + + -- open the file, if old file, clear it + if (file.status == "1") then + fh = assert(io.open(file.value,"wb")); + else -- (file.status == "0") + fh = assert(io.open(file.value,"w+b")); -- clear file contents + end; + + -- write it + fh:write(framework); + + -- close it (automatically flushed) + fh:close(); + fh = nil; + + iup.Message ("Success", "Bot written to "..file.value.."!"); + end; + tmptable.SAVE.action = + function(self, n) + local file = iup.filedlg{allownew="YES",dialogtype="SAVE",directory="./lua",showhidden="YES",title="Save botfile",extfilter="BasicBot (*.bot)|*.bot|All files (*.*)|*.*|"}; + file:popup(iup.ANYWHERE,iup.ANYWHERE); + + if (file.status == 1) then -- cancel + return; + end; + + -- open the file, if old file, clear it + if (file.status == "1") then + fh = assert(io.open(file.value,"wb")); + else -- (file.status == "0") + fh = assert(io.open(file.value,"w+b")); -- clear file contents + end; + + -- allow us to detect the botfile version (warn the user if it's different?) + fh:write(botVersion.."\n"); + + -- now replace all tokens by gui values + -- this is where the reftable comes in very handy :p + for token,obj in pairs(reftable) do + print("------"); + print(token.." control -> "..tostring(obj)); + print(".value: "..tostring(obj.value)); + local st00pid = obj.value; + if (not st00pid) then st00pid = ""; end; + print(string.len(st00pid)); + fh:write(string.len(st00pid).."\n"); + if (string.len(st00pid) > 0) then fh:write(st00pid); end; + fh:write("\n"); + end; + + fh:close(); + iup.Message ("Success", "Settings saved!"); + end; + tmptable.LOAD.action = + function (self, n) + -- this function currently crashes fceux without notification + -- possibly because offsets are badly calculated, but serves as an example now + local file = iup.filedlg{allownew="NO",dialogtype="OPEN",directory="./lua",showhidden="YES",title="Save botfile",extfilter="BasicBot (*.bot)|*.bot|All files (*.*)|*.*|"}; + file:popup(iup.ANYWHERE,iup.ANYWHERE); + if (file.status == 1) then -- cancel + iup.Message ("Success", "Canceled by you..."); + return; + end; + local nellen = string.len("\n"); -- platform independent + fh = assert(io.open(file.value,"r")); + + fh:read("*n"); -- version + fh:read("*l"); -- return + + local len; + local data; + for token,crap in pairs(reftable) do + len = fh:read("*n"); -- read line (length) + if (not len) then + iup.Message ("Warning", "End of file reached too soon!"); + break; + end; -- no more data... (should we erase the rest?) + fh:read("*l"); -- return + data = fh:read(len); + if (not data) then + iup.Message ("Warning", "End of file reached too soon!"); + break; + end; -- no more data... (should we erase the rest?) + reftable[token].value = data; + fh:read("*l"); -- return + end; + iup.Message ("Success", "Settings loaded!"); + end; +end; + +dialogs = dialogs + 1; +createGUI(dialogs); +while (true) do + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/Machrider.lua b/branches/fceux-2.2.2/output/luaScripts/Machrider.lua new file mode 100644 index 00000000..53d56812 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Machrider.lua @@ -0,0 +1,266 @@ +--Machrider - Speedometer +--Written by XKeeper + +require("x_functions"); + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(4); +end; + + +function savereplay(filename, replaydata) + + stringout = ""; + + f = io.open(filename, "w"); + for k, v in pairs(replaydata) do + stringout = string.format("%d:%d:%d\n", k, v['speed'], v['gear']); + f:write(stringout); + end; + + f:close(); + + return true; + +end; + + + +olddist = 0; +lastcount = 0; +counter = 0; +altunittype = true; +waittimer = 0; +autoshift = true; -- auto-handle shifting? for the lazy people +speedgraph = {}; +timer = 0; +graphlen = 240; +graphheight = 100; +maxspeed = 500; +dorecording = false; + +while true do + + joydata = joypad.read(1); + if joydata['select'] and not joydatas then + altunittype = not altunittype; + joydatas = true; + + elseif joydata['up'] and joydata['B'] and not joydatas and dorecording then + savereplay("machriderspeed.xrp", speedgraph); + joydatas = true; + saved = true; + + elseif not joydata['select'] then + joydatas = false; + end; + + if saved and dorecording then + text(100, 140, "Saved data!"); + end; + + speedlow = memory.readbyte(0x0040); + speedhigh = memory.readbyte(0x0041); + speed = speedhigh * 0x100 + speedlow; + rpmlow = memory.readbyte(0x0042); + rpmhigh = memory.readbyte(0x0043); + rpm = rpmhigh * 0x100 + rpmlow; + gear = memory.readbyte(0x0032); + + + if autoshift and waittimer <= 0 then + if gear < 2 then + memory.writebyte(0x0032, 2); +-- waittimer = 6; + elseif speed <= 250 and gear > 2 then + memory.writebyte(0x0032, math.max(gear - 1, 2)); +-- waittimer = 6; + elseif speed >= 255 and gear < 3 then + memory.writebyte(0x0032, math.min(gear + 1, 3)); +-- waittimer = 6; + end; + end; + waittimer = waittimer - 1; + + if dorecording then + timer = timer + 1; + speedgraph[timer] = {speed = speed, gear = gear}; + if timer > graphlen then + temp = timer - graphlen - 1; + -- speedgraph[temp] = nil; + end; + + + for i = timer - graphlen, timer do + if speedgraph[i] then + xp = ((i + 3) - timer) + graphlen; + yp = graphheight - (speedgraph[i]['speed'] / maxspeed) * graphheight; + + if (speedgraph[i]['gear'] == 0) then + c = "blue"; + elseif (speedgraph[i]['gear'] == 1) then + c = "green"; + elseif (speedgraph[i]['gear'] == 2) then + c = "#cccc00"; + elseif (speedgraph[i]['gear'] == 3) then + c = "red"; + else + c = "gray"; + end; + + -- pixel(((i + 3) - timer) + 60, 50 - speedgraph[i], "#ffffff"); + line(xp, 10, xp, graphheight + 10, "#000000"); + line(xp, yp + 10, xp, graphheight + 10, c); + pixel(xp, yp + 10, "#ffffff"); + + -- pixel(((i + 3) - timer) + 60, 50 - speedgraph[i], "#ffffff"); + end; + end; + end; + +--[[ + dist = math.fmod(memory.readbyte(0x0062), 0x20); + text( 8, 15, string.format("%02X %4dfr/mv", dist, lastcount)); + if dist > olddist then + lastcount = counter; + counter = 0; + end; + olddist = dist; + counter = counter + 1; + + lifebar( 8, 8, 0x1F * 5, 3, dist, 0x1F, "#ffffff", "#0000FF", "#000000", "#ffffff"); +--]] + + barwidth = 100; + segmentwidth = 2; + pct = speed / maxspeed * 100; + + if altunittype then + speedadjust = (65535 / 60 / 60 / 60) * speed; -- rough approximation of km/h + text(barwidth * segmentwidth - 2, 221, string.format(" %3.1dkm/h", speedadjust)); + else + text(barwidth * segmentwidth - 2, 221, string.format(" %3d", speed)); + end; + + box(2, 221, barwidth * segmentwidth + 2, 230, "#000000"); + box(2, 222, barwidth * segmentwidth + 2, 229, "#000000"); + box(2, 223, barwidth * segmentwidth + 2, 228, "#000000"); + box(2, 224, barwidth * segmentwidth + 2, 227, "#000000"); + box(2, 225, barwidth * segmentwidth + 2, 226, "#000000"); + lastseg = false; + + if pct > 0 then + for bl = 1, math.min(maxspeed - 1, speed) do + + pct = bl / maxspeed; + segment = math.floor(pct * barwidth); + if segment ~= lastseg then + + if pct < 0.50 then + val = math.floor(pct * 2 * 0xFF); + segcolor = string.format("#%02XFF00", val); + + elseif pct < 0.90 then + val = math.floor(0xFF - (pct - 0.5) * 100/40 * 0xFF); + segcolor = string.format("#FF%02X00", val); + + elseif bl < maxspeed then + val = math.floor((pct - 0.90) * 10 * 0xFF); + segcolor = string.format("#FF%02X%02X", val, val); + + else + segcolor = "#ffffff"; + end; + + + yb = math.max(math.min(3, (pct * 100 - 50)), 0); + -- box(segment * segmentwidth + 3, 225 - yb, segment * segmentwidth + 3 + (segmentwidth - 2), 229, segcolor); + box(segment * segmentwidth + 3, 225 - yb, segment * segmentwidth + 3, 229, segcolor); + -- box(bl * 3 + 3, 218, bl * 3 + 4, 225, segcolor); + -- line(bl * 3 + 4, 218, bl * 3 + 4, 225, segcolor); + end; + lastseg = segment; + end; + end; + + + + maxrpm = 0x7F; + barwidth = 104; + segmentwidth = 1; + pct = rpmhigh / maxrpm * 100; + + line(2, 220, (barwidth + 2) * segmentwidth + 2, 220, "#000000"); + + if autoshift then + text( 2, 203, string.format("AUTO %1d", gear + 1)); + else + text( 2, 203, string.format("Manual %1d", gear + 1)); + end; + if altunittype then + text( 2, 211, string.format("%5dRPM", math.min(9999, rpm * .25))); + else + text( 2, 211, string.format("%5dRPM", rpm)); + end; + + rpmhigh = math.min(maxrpm + 10, rpmhigh); + lastseg = false; + + if pct > 0 then + for bl = 1, rpmhigh do + + pct = bl / maxrpm; + segment = math.floor(pct * barwidth); + if segment ~= lastseg then + if pct < 0.70 then + val = math.floor(pct * (100/70) * 0xFF); + segcolor = string.format("#%02XFF00", val); + + elseif pct < 0.90 then + val = math.floor(0xFF - (pct - 0.7) * 100/20 * 0xFF); + segcolor = string.format("#FF%02X00", val); + + elseif bl < maxrpm then + val = math.floor((pct - 0.90) * 10 * 0xFF); + segcolor = string.format("#FF%02X%02X", val, val); + + else + segcolor = "#ffffff"; + end; + + yb = math.floor(math.max(math.min(4, segment - 99), 0) / 2); + -- box(segment * segmentwidth + 3, 225 - yb, segment * segmentwidth + 3 + (segmentwidth - 2), 229, segcolor); + segment = math.min(segment, barwidth); + box(segment * segmentwidth + 3, 221, segment * segmentwidth + 3, 223 - yb, segcolor); + -- box(bl * 3 + 3, 218, bl * 3 + 4, 225, segcolor); + -- line(bl * 3 + 4, 218, bl * 3 + 4, 225, segcolor); + end; + lastseg = seg; + end; + end; + + + + + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/MegamanII-LaserEyes.lua b/branches/fceux-2.2.2/output/luaScripts/MegamanII-LaserEyes.lua new file mode 100644 index 00000000..33c202f9 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/MegamanII-LaserEyes.lua @@ -0,0 +1,730 @@ +SCRIPT_TITLE = "Mega Man 2 LASER EYES" +SCRIPT_VERSION = "1.0" + +require "m_utils" +m_require("m_utils",0) + +--[[ +Mega Man 2 LASER EYES +version 1.0 by miau + +Visit http://morphcat.de/lua/ for the most recent version and other scripts. + + +Controls + Press select to fire a laser from Mega Man's eyes aimed at the closest object. + Left-click to drag and drop objects. + Middle-clicking instantly moves Mega Man to the cursor position. + +Supported roms + Rockman 2 - Dr Wily no Nazo (J), Mega Man 2 (U), Mega Man 2 (E) + +Known bugs +- shooting lasers at bosses is glitchy, do it at your own risk +- eyes might turn black for a short period of time after screen transition +- some objects have duplicate IDs which will result in wrong names being shown for them + +-]] + +--configurable vars +local show_info = false --show sprite info on startup +local show_cursor = false --set this to true when recording a video + +--sound effects to use for various script events, nil to disable +local SFX_LASER = 0x25 +local SFX_EXPLOSION = 0x2B +local SFX_TARGET = nil --0x39 --0x21 +-------------------------------------------------------------------------------------------- +--List of sound effects +--0x21 press +--0x22 peeewwwwwww +--0x23 metal blade +--0x24 mega buster +--0x25 sniper armor shot? +--0x26 hit1 +--0x27 air shooter +--0x28 energy +--0x29 touch ground +--0x2A wily thing +--0x2B destroy1 +--0x2C ?? +--0x2D reflected shot +--0x2E ?? (metal blade-like noise channel usage, short) +--0x2F menu selector +--0x30 mega man appear +--0x31 leaf shield +--0x32 menu open +--0x33 ?? (short, low noise) +--0x34 gate open +--0x35 atomic fire charge 1 +--0x36 atomic fire charge 2 +--0x37 atomic fire charge 2 +--0x38 atomic fire shot ? +--0x39 prop-top leap +--0x3A mega man disappearing +--0x3B diving into water +--0x3C appearing platform +--0x3D wily stage lava drops +--0x3E wily stage lava drops +--0x3F ?? (similar to 0x27) +--0x40 ?? (short noise) +--0x41 death +--0x42 e-tank/1up +--0x43 ?? (short noise in fixed intervals) + + + + + + +local sprdb = {} --enemy names source: http://megaman.wikia.com +sprdb[0x00] = {name="Squirt"} +sprdb[0x01] = {name="Squirt"} --spawned by Lantern Fish +sprdb[0x04] = {name="M-445"} +sprdb[0x07] = {name="Snapper Controller",invincible=true} +sprdb[0x08] = {name="Snapper"} +sprdb[0x0A] = {name="Crabbot"} +sprdb[0x0C] = {name="Croaker"} +sprdb[0x0D] = {name="Croaker (tiny)"} +sprdb[0x0E] = {name="",invincible=true} --bubble...underwater mega man +sprdb[0x0F] = {name="Lantern Fish"} +sprdb[0x13] = {name="Platform"} +sprdb[0x15] = {name="Beam"} +sprdb[0x16] = {name="Bubble Bat"} +sprdb[0x17] = {name="Robo-Rabbit"} +sprdb[0x18] = {name="Carrot"} --or mega man being hit +sprdb[0x1D] = {name="Mecha Monkey"} +sprdb[0x1E] = {name="Atomic Chicken Controller",invincible=true} +sprdb[0x1F] = {name="Atomic Chicken"} +--sprdb[0x1B] = {name="Climbing Mega Man"} --or hot dog fire +--sprdb[0x1C] = {name=""} --or hot dog fire controller? +sprdb[0x21] = {name="Telly Spawn Point",invincible=true} +sprdb[0x22] = {name="Telly"} +sprdb[0x23] = {name="Hothead"} --or Mega Buster +sprdb[0x24] = {name="Tackle Fire"} +--sprdb[0x27] = {name="Light Control"} +--sprdb[0x28] = {name="Light Control"} +sprdb[0x29] = {name="Cogwheel"} +sprdb[0x2A] = {name="Pierobot"} +sprdb[0x2B] = {name="Prop-Top Controller",invincible=true} +sprdb[0x2C] = {name="Prop-Top"} +sprdb[0x2E] = {name="Hot Dog"} +sprdb[0x2F] = {name="Gate"} +sprdb[0x30] = {name="Press"} +sprdb[0x31] = {name="Blocky"} +sprdb[0x32] = {name="Big Fish Controller",invincible=true} +--sprdb[0x33] = {name=""} --Bubble Lead +sprdb[0x34] = {name="Neo Met"} +sprdb[0x35] = {name="Bullet"} --Sniper Armor/Sniper Joe +sprdb[0x36] = {name="Fan Fiend"} --or Metal Blade +sprdb[0x37] = {name="Pipi Controller",invincible=true} --or Flash weapon (Time Stopper) controller(?) +sprdb[0x38] = {name="Pipi"} +sprdb[0x3A] = {name="Pipi Egg"} --or Item-3(?) +sprdb[0x3B] = {name="Pipi Egg Shell"} +sprdb[0x3C] = {name="Child Pipi"} +sprdb[0x3D] = {name="Lightning Lord"} +sprdb[0x3E] = {name="Thunder Chariot"} +--sprdb[0x3F] = {name="Lightning Bolt"} --or "splash"... (mega man diving into water) +sprdb[0x3F] = {invincible=true} +sprdb[0x40] = {name="Air Tikki"} +sprdb[0x41] = sprdb[0x40] +sprdb[0x44] = {name="Air Tikki Horn"} +sprdb[0x45] = {name="Gremlin"} +sprdb[0x46] = {name="Spring Head"} +sprdb[0x47] = {name="Mole Controller",invincible=true} +sprdb[0x48] = {name="Mole (rising)"} +sprdb[0x49] = {name="Mole (falling)"} +sprdb[0x4B] = {name="Crazy Cannon"} +sprdb[0x4D] = {name="Bullet (Crazy Cannon)"} +sprdb[0x4E] = {name="Sniper Armor"} +sprdb[0x4F] = {name="Sniper Joe"} +sprdb[0x50] = {name="Squirm"} +sprdb[0x51] = {name="Squirm Pipe"} + +sprdb[0x5C] = {name="Metal Blade"} +sprdb[0x5D] = {name="Air Shooter"} +sprdb[0x5E] = {name="Crash Bomb"} + +--[[sprdb[0x60] = {name="Bubble Man"} +sprdb[0x61] = sprdb[0x60] +sprdb[0x62] = sprdb[0x60] +sprdb[0x63] = {name="Metal Man"} --or Falling Blocks (Dragon) (id2:80) +sprdb[0x64] = sprdb[0x63] --or Falling Blocks (Dragon).. Dragon Controller? (id2:80) +sprdb[0x65] = sprdb[0x63] --or Dragon Body (id2:8B) +sprdb[0x66] = {name="Air Man"} --or Dragon Bottom (id2:8B) +sprdb[0x67] = sprdb[0x66] +sprdb[0x68] = sprdb[0x66] +sprdb[0x69] = {name="Crash Man"} +sprdb[0x6A] = sprdb[0x69] --running or wily boss no.2 (id2:8B/CB/83/C3/80) +sprdb[0x6B] = sprdb[0x69] --jumping +sprdb[0x70] = {name="Dragon"} --(id2:8B) +sprdb[0x71] = {name="Big Fish"} --Wily Boss 3 (id2:83) +--]] + +sprdb[0x76] = {name="Large Life Energy",invincible=true} +sprdb[0x77] = {name="Small Life Energy",invincible=true} +sprdb[0x78] = {name="Large Weapon Energy",invincible=true} +sprdb[0x79] = {name="Small Weapon Energy",invincible=true} +sprdb[0x7A] = {name="E-Tank",invincible=true} +sprdb[0x7B] = {name="1UP",invincible=true} + + +local eyes = {} +eyes.open = { + {0,0,0,0,0,1,1,0,1,0,0,0,0}, + {0,0,0,0,0,1,1,0,1,0,0,0,0}, +} +eyes.running = { + {0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,1,1,0,1,0,0,0,0}, + {0,0,0,0,0,1,1,0,1,0,0,0,0}, +} +eyes.shooting = { + {0,0,0,0,0,0,0,0,0,1,1,0,1}, + {0,0,0,0,0,0,0,0,0,1,1,0,1}, +} +eyes.ladder = { + {0,0,0,0,0,0,0,1,1,0,0,0,0}, + {0,0,0,0,0,0,0,1,1,0,0,0,0}, +} +eyes.closed = { + {0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,1,1,1,1,0,1,1,0,0,0}, +} +eyes.none = {} + +local mmeyes = eyes.open +local timer = 0 +local spr = {} +local last_inp = {} +local inp = {} +local laser = {timer=0} +local last_laser = 0 + + + +--very limited and hacky particle engine following +local P_MAX = 150 +local particle = {p={}} + +function particle.laserai(pi) + local function checkcollision(px,py,rx,ry) + if(px>=rx-8 and px<=rx+8 and py>=ry-8 and py<=ry+8) then + return true + else + return false + end + end + + for i=1,31 do + if(spr[i].a and is_enemy(i)) then + local px = particle.p[pi].x + local py = particle.p[pi].y + local px2 = particle.p[pi].x+particle.p[pi].vx*6 + local py2 = particle.p[pi].y+particle.p[pi].vy*6 + local rx = spr[i].x+spr[i].hx*256 + local ry = spr[i].y + if(checkcollision(px,py,rx,ry) or checkcollision(px2,py2,rx,ry)) then + --if(spr[i].hp>5) then + -- memory.writebyte(0x06C0+i,spr[i].hp-5) + --else + memory.writebyte(0x06C0+i,1) + play_sfx(SFX_EXPLOSION) + particle.explosion(spr[i].x+spr[i].hx*256,spr[i].y) + destroy_sprite(i) + --end + end + end + end +end + + +function particle.create(new) + for i=0,P_MAX-1 do + if(particle.p[i]==nil) then + particle.p[i]=new + if(particle.p[i].x==nil) then + particle.p[i].x=0 + end + if(particle.p[i].y==nil) then + particle.p[i].y=0 + end + if(particle.p[i].vx==nil) then + particle.p[i].vx=0 + end + if(particle.p[i].vy==nil) then + particle.p[i].vy=0 + end + if(particle.p[i].timer==nil) then + particle.p[i].timer=0 + end + if(particle.p[i].lspan==nil) then + particle.p[i].lspan=60 + end + if(particle.p[i].color==nil) then + particle.p[i].color="#FFFFFF" + end + return i + end + end + return nil +end + +function particle.explosion(x,y) --faster than using particle.create + local j = 0 + for i=0,P_MAX-1 do + if(particle.p[i]==nil) then + local vx = math.random(-50,50)/30 + local vy = math.random(-50,50)/30 + local color = "#FF0000" + particle.p[i] = {} + particle.p[i].x = x + particle.p[i].y = y + particle.p[i].vx = vx + particle.p[i].vy = vy + particle.p[i].color = color + particle.p[i].lspan = math.random(20,40) + particle.p[i].timer=0 + if(j==40) then + return + end + j = j + 1 + end + end +end + +function particle.destroy(i) + particle.p[i] = nil +end + + +function particle.update() + for i=0,P_MAX-1 do + if(particle.p[i]) then + if(particle.p[i].timer >= particle.p[i].lspan) then + particle.destroy(i) + else + if(particle.p[i].aifunc) then + particle.p[i].aifunc(i) + end + if(particle.p[i]) then + particle.p[i].x = particle.p[i].x + particle.p[i].vx + particle.p[i].y = particle.p[i].y + particle.p[i].vy + particle.p[i].timer = particle.p[i].timer + 1 + end + end + end + end +end + +function particle.render(xdisp,ydisp) + local j=0 + for i=0,P_MAX-1 do + if(particle.p[i]) then + bcline2(particle.p[i].x-xdisp,particle.p[i].y-ydisp, particle.p[i].x-xdisp+particle.p[i].vx*6,particle.p[i].y+particle.p[i].vy*6-ydisp, particle.p[i].color) + if(particle.p[i].aifunc) then + bcline2(particle.p[i].x-xdisp,particle.p[i].y+1-ydisp, particle.p[i].x-xdisp+particle.p[i].vx*6,particle.p[i].y+particle.p[i].vy*6+1-ydisp, particle.p[i].color) + end + j = j + 1 + end + end +end + + + + +function initialize() + for i=0,31 do + spr[i] = { + a=0, + id=0, + id2=0, + x=0, + y=0, + hp=0, + --timer=-1, + } + end +end + + +function unselect_all() + for i=0,31 do + spr[i].selected=false + spr[i].moving = false + end +end + +function getx16(s) + return s.hx*256+s.x +end + +function get_target() + --closest target + local closest = nil + local dmin = 9999 + for i=1,31 do + if(spr[i].a and is_enemy(i) and spr[i].seltimer>=10 and + ( (spr[i].sx>=megaman.sx and megaman.dir==1) + or (spr[i].sx<=megaman.sx and megaman.dir==-1) + or megaman.dir==0)) then + local d = getdistance(megaman.sx,megaman.sy,spr[i].sx,spr[i].sy) + if(d=0x80) + if(spr[i].a==false) then + spr[i].seltimer=nil + end + + if(spr[i].a) then + if(inp.xmouse>=spr[i].sx-8 and inp.xmouse<=spr[i].sx+8 and inp.ymouse>=spr[i].sy-8 and inp.ymouse<=spr[i].sy+8) then + spr[i].hover = true + spr[i].clicked = inp.leftclick + if(inp.leftclick and last_inp.leftclick==nil) then + unselect_all() + spr[i].selected=true + end + else + spr[i].hover = false + if(inp.leftclick==nil) then + spr[i].clicked = false + end + end + + --auto-target + if(is_enemy(i)) then + if(spr[i].seltimer==nil) then + spr[i].seltimer=1 + else + spr[i].seltimer = spr[i].seltimer + 1 + end + end + + if(spr[i].selected) then + --[[if(inp.delete) then + destroy_sprite(i) + elseif(inp.pagedown) then + memory.writebyte(0x0400+i,spr[i].id-1) + elseif(inp.pageup) then + memory.writebyte(0x0400+i,spr[i].id+1) + end-]] + + if(spr[i].clicked) then + if(inp.xmouse~=last_inp.xmouse or inp.ymouse~=last_inp.ymouse) then + spr[i].moving = true + end + else + spr[i].moving = false + end + end + + if(spr[i].moving) then + local x = inp.xmouse+scroll_x + memory.writebyte(0x0460+i,inp.xmouse+scroll_x) + memory.writebyte(0x04A0+i,inp.ymouse) + memory.writebyte(0x0440+i,scroll_hx+math.floor(x/256)) + end + + end + --end + end + + megaman = spr[0] + if(megaman.id2==0x80) then + megaman.dir=-1 + else + megaman.dir=1 + end + if(megaman.id==0x1B) then + megaman.dir = 0 + end + + + if(inp.middleclick) then --change mega man's coordinates + local x = inp.xmouse+scroll_x + memory.writebyte(0x0460,x) + memory.writebyte(0x04A0,inp.ymouse) + memory.writebyte(0x0440,scroll_hx+math.floor(x/256)) + end + + --LASER!!! + jp = joypad.read(1) + if(jp.select and (last_jp.select==nil or timer-last_laser>22)) then + local t = get_target() + local vx,vy + play_sfx(SFX_LASER) + if(t) then + vx,vy = getvdir(megaman.sx,megaman.sy-3,spr[t].sx,spr[t].sy) + vx = vx * 10 + vy = vy * 10 + else + if(megaman.dir==0) then + vx = 0 + vy = -10 + else + vx = megaman.dir*10 + vy = 0 + end + end + last_laser = timer + + particle.create({x=getx16(megaman),y=megaman.y-3,vx=vx,vy=vy,color="#FF0000",aifunc=particle.laserai}) + end + + if(inp.xmouse<83 and inp.ymouse<18) then + if(inp.leftclick and last_inp.leftclick==nil) then + if(show_info) then + show_info = false + else + show_info = true + end + end + end + + last_jp = jp + last_inp = inp +end + +function render() + + if(show_info) then + gui.text(0,8,"Sprite Info: ON") + else + gui.text(0,8,"Sprite Info: OFF") + end + if(inp.xmouse<83 and inp.ymouse<18) then + if(show_info) then + gui.drawbox(0,9,77,17,"red") + else + gui.drawbox(0,9,83,17,"red") + end + end + + particle.render(scroll_x+scroll_hx*256,0) + + --LASER EYES!!! + --TODO: prevent play_sfx from playing sounds during title screen/stage select + if(memory.readbyte(0x580) == 0x0D) then --title screen tune is being played + megaman.sx=211 + megaman.sy=131 + megaman.dir = -1 + mmeyes = eyes.open + + --lasers during title screen + if(AND(timer,7)==0 and math.random(0,1)==0) then + --play_sfx(SFX_LASER) + local vx,vy=getvdir(megaman.sx,megaman.sy-3,0,math.random(30,220)) + vx=vx*10 + vy=vy*10 + particle.create({x=megaman.sx+6,y=megaman.sy-3,vx=vx,vy=vy,color="#FF0000",aifunc=LaserAI}) + mmeyes = eyes.none + end + elseif(megaman.a) then --sprite active + local f = memory.readbyte(0x06A0)*256 + memory.readbyte(0x0680) + local frame = memory.readbyte(0x06A0) + local ftimer = memory.readbyte(0x0680) + if(memory.readbyte(0x69)~=0x0E) then --menu opened or "stage intro" tune + mmeyes = eyes.none + elseif(megaman.id==0x00) then --BLINK! change occurs on next frame + if(f >= 0xA01) then + mmeyes = eyes.closed + elseif(f>=0x001) then + mmeyes = eyes.open + end + elseif(megaman.id==0x01 or megaman.id==0x03 or megaman.id==0x05 or megaman.id==0x07 or megaman.id==0x0B or megaman.id==0x11 or megaman.id==0x13) then + mmeyes = eyes.shooting + elseif(megaman.id==0x04 or megaman.id==0x0C or megaman.id==0x0D or megaman.id==0x10) then + mmeyes = eyes.open + elseif(megaman.id==0x08 or megaman.id==0x09 or megaman.id==0x14) then + if((f>=0x201 and f<=0x300) or (f>=0x001 and f<=0x100)) then + mmeyes = eyes.running + else + mmeyes = eyes.open + end + elseif(megaman.id==0x18) then --getting hurt + mmeyes = eyes.closed + elseif(megaman.id==0x1C or megaman.id==0x1E) then --mega buster, other weapons + mmeyes = eyes.ladder + else--if(megaman.id==0x1A or megaman.id==0x1B) then --respawning after death, climbing a ladder + mmeyes = eyes.none + end + + --if(megaman.hp==0) then + -- mmeyes = eyes.none + --end + else + mmeyes = eyes.none + end + + if(mmeyes ~= eyes.none) then + local eyecolor = "#FF0000" + if(timer-last_laser<5) then + eyecolor = "#FFFFFF" + end + if(megaman.dir==-1) then + for y=1,4 do + if(mmeyes[y]) then + for x=1,14 do + if(mmeyes[y][15-x]==1) then + bcpixel(megaman.sx-9+x,megaman.sy-5+y,eyecolor) + end + end + end + end + else + for y=1,4 do + if(mmeyes[y]) then + for x=1,14 do + if(mmeyes[y][x]==1) then + bcpixel(megaman.sx-5+x,megaman.sy-5+y,eyecolor) + end + end + end + end + end + end + + + for i=0,31 do + if(spr[i].a) then + local x,y + local boxcolor + if(spr[i].clicked) then + boxcolor="#AA5500" + elseif(spr[i].hover) then + boxcolor="#FFCCAA" + else + boxcolor=nil + end + x = spr[i].sx + y = spr[i].sy + if(boxcolor) then + bcbox(x-9,y-9,x+9,y+9,boxcolor) + end + + if(spr[i].seltimer) then + if(spr[i].seltimer<30) then + local b=30-spr[i].seltimer + local c = (30-spr[i].seltimer)*8 + bcbox(x-9-b,y-9-b,x+9+b,y+9+b,string.format("#CC%02X%02X",c,c)) + if(spr[i].seltimer==23) then + play_sfx(SFX_TARGET) + end + elseif(spr[i].seltimer>90 or AND(timer,7)>2) then + bcbox(x-9,y-9,x+9,y+9,"red") + end + end + + + if(show_info and (spr[i].hover or spr[i].clicked or spr[i].seltimer)) then + --bctext(AND(spr[i].x+255-scroll_x,255), spr[i].y, i); + if(i==0) then + bctext(x, y, "Blue Bomber") + bctext(x, y+8, "("..spr[i].sx..","..spr[i].sy..")") + bctext(x, y+16, "HP "..spr[i].hp) + elseif(i>4) then + if(sprdb[spr[i].id] and sprdb[spr[i].id].name --[[and i>4--]]) then + bctext(x, y, sprdb[spr[i].id].name) + else + bctext(x, y, "("..spr[i].id..")") + end + bctext(x, y+8, "("..spr[i].sx..","..spr[i].sy..")") + if(spr[i].hp~=0) then + bctext(x, y+16, "HP "..spr[i].hp) + end + end + end + end + end + + if(show_cursor) then + local col2 + if(inp.leftclick) then + col2 = "#FFAA00" + elseif(inp.rightclick) then + col2 = "#0099EE" + elseif(inp.middleclick) then + col2 = "#AACC00" + else + col2 = "white" + end + drawcursor(inp.xmouse,inp.ymouse,"black",col2) + end +end + + + +initialize() + +while(true) do + update_vars() + render() + EMU.frameadvance() + timer = timer + 1 +end + + diff --git a/branches/fceux-2.2.2/output/luaScripts/MemoryWatch.lua b/branches/fceux-2.2.2/output/luaScripts/MemoryWatch.lua new file mode 100644 index 00000000..41358502 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/MemoryWatch.lua @@ -0,0 +1,58 @@ +--Memory Watch +--Creates a Dialog box for monitoring a game's RAM values. + +--Version History +-- v0.01a (not yet done!) +-- include some iup stuff and take care of cleanup +require 'auxlib'; + +local function toHexStr(n) + return string.format("%X",n); +end; + + +local mat = iup.matrix {numcol=4, numlin=10,numcol_visible=4, numlin_visible=10, width1="40", width2="80", width3="30", width4="30", ALIGNMENT1="ARIGHT", ALIGNMENT2="ALEFT"}; +mat.resizematrix = "YES"; +mat:setcell(0,1,"Address"); -- index 0 (i or j) will set title +mat:setcell(0,2,"Title"); +mat:setcell(0,3,"Dec"); +mat:setcell(0,4,"Hex"); + +dialogs = dialogs + 1; +handles[dialogs] = + iup.dialog{ + iup.vbox{ + iup.label{ + title="Enter a number in the first column (can be hex)." + }, + iup.label{ + title="Third and fourth are values of that address." + }, + iup.fill{size="5"}, + mat, + iup.fill{}, + }, + title="St00pid memory watch", + size="215x160", + margin="10x10" + }; + +handles[dialogs]:showxy(iup.CENTER, iup.CENTER); + +while (true) do + local cols = tonumber(mat.numcol); + for i=1,cols do + local val = tonumber(mat:getcell(i,1)); + if ( + --mat["edit_mode1x"..i] ~= "YES" and -- who knows what you're editing in there + val and val >= 0 and val <= 0xFFFF -- check bounds + ) then + local mem = memory.readbyte(val); + mat:setcell(i,3,mem..""); + mat:setcell(i,4,toHexStr(mem)); + end; + end; + mat.redraw = "C3:4"; + + FCEU.frameadvance(); +end; diff --git a/branches/fceux-2.2.2/output/luaScripts/Multitrack.lua b/branches/fceux-2.2.2/output/luaScripts/Multitrack.lua new file mode 100644 index 00000000..baf67042 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Multitrack.lua @@ -0,0 +1,804 @@ +-- Multi-track rerecording for FCEUX 2.1.2 or later (script V2) +-- To make up for the lack of an internal multi-track rerecording in FCEUX. +-- It may get obsolete when TASEdit comes around. +--FatRatKnight +-- Rewind (by Antony Lavelle) added by DarkKobold + +-- Instructions: +-- The script has its own buttons, defined in the junk below. +-- If you're not sure what they do, experiment by pressing the button! +-- If you're still not sure, I'll give you some basic idea here. + +-- With the script buttons, defined by key down there, you can +-- toggle the input on or off for the next frame. Just push +-- the key button, and you'll see a light change. I don't +-- recommend HOLDing down the key button, especially if they +-- overlap with the actual controls you've set up on your +-- emulator. Especially there, since that's where problems begin. + +-- I also have options to determine whether the input from +-- the emulator should apply or whether the script should +-- bother. Hold space (default keys), and you can switch +-- individual buttons on or off. The script will decide +-- whether to ignore the script keys here or the input stored +-- away in its list, with the options that pop up. + +-- There's a player switch as well. Just hit the S key +-- (default keys) and it'll change to player 2. Or 3, or 4. +-- Or all players at once. This will make the script keys +-- start working on other players instead of just 1. + +-- Then there's the joypad input. home or end (default keys) +-- grants varying levels of control to the emulator joypad. +-- If you want to get rid of all control from the joypad setup +-- of the emulator, you can do that. The defaults are to allow +-- the controllers to toggle whatever input the script has. +-- I did not implement a way to give this decision to +-- individual joypad keys. + +-- That's the basics of controlling input with this script. +-- The script buttons let you decide input without a frame +-- advance, and the joypad keys are there if you're so used +-- to holding things down while pressing frame advance. + + +-- A few more advanced things are in here. I will briefly mention them: + -- Rewind: Back up a frame or two with a press of a button! + -- Seems to hog up CPU greatly. Disable if you want things run smoothly. + -- Insert/Delete: Found a time saver, yet want to keep later input? + -- This lets you slide a chunk of frames forward or back. + -- I display a number that says how many frames are buffered. + -- Immediate: Good if you want to change input while rewinding. + -- Okay, its use is quite rare, but it's there. + +-- Hopefully, this is enough to let you get started. Good luck! + + + +-- Stuff that you are encouraged to change to fit what you need. +--***************************************************************************** +-- Control scheme. Just experiment a little with the buttons. + +local selectplayer = "S" -- For selecting which player +local recordingtype= "space" -- For selecting how to record +local SetImmediate = "numpad5"--Toggle immediate option +local TrueSwitch = "home" -- Toggle whether joypad can turn off input +local FalseSwitch = "end" -- Toggle whether joypad can turn on input + +local show, hide = "pageup", "pagedown" -- Opacity adjuster +local scrlup, scrldown = "numpad8", "numpad2" -- Move the input display +local scrlleft, scrlright= "numpad4", "numpad6" -- Not a fast method, though. +local MorePast, LessPast = "numpad7", "numpad1" -- See more or less input! +local MoreFuture, LessFuture= "numpad3", "numpad9" -- Good use of screen space + +local add, remove = "insert", "delete" -- Moves input around +local rewind = "R" -- The button used to rewind things + +local key = {"right", "left", "down", "up", "L", "O", "J", "K"} +local btn = {"right", "left", "down", "up", "start", "select", "B", "A"} + +-- key links to the keyboard keys, so change those to fit your control needs. +-- btn links to joypad buttons. Don't change what's in there. +-- However, feel free to reorder the strings in btn! It will change the display! + + +--***************************************************************************** +-- Values to change. players, saveMax, and MsgDuration aren't changed in the +-- code. All others are simply default values which can dynamically change. + +local players= 2 -- You may tweak the number of players here. + +local saveMax= 1000 -- Max Rewind Power. Set to 0 to disable + +local opaque= 0 -- Default opacity. 0 is solid, 4 is invisible. + +local dispX, dispY= 10, 99 -- Default input display position. + +local Past, Future= -10, 10 -- Keep Past negative; Range of input display + +local immediate= false -- true: Changes apply to list upon happening + -- false: Changes only apply on frame advance +local JoyOn = "inv" -- true OR "inv" If true, disable turn-off +local JoyOff= nil -- false OR nil If false, disable turn-on + +local MsgDuration= 60 -- How long should messages stay? + + +--***************************************************************************** + +-- Stuff that really shouldn't be messed with, unless you plan to change the code significantly. +local optType= {"Both", "Keys", "List", "Off"} -- Names for option types +local keys, lastkeys= {}, {} -- To hold keyboard input +local Pin, thisInput= {}, {} -- Input manipulation array +local BufInput, BufLen= {},{}-- In case you want to insert or remove frames. +local option= {} -- Options for individual button input by script +local fc, lastfc= 0, 0 -- Frame counters +local FrameAdvance= false -- Frame advance detection +local pl= 1 -- Player selected +local plmin, plmax= 1, 1 -- For the all option +local repeater= 0 -- for holding a button +local rewinding= false -- For unpaused rewinding +local MsgTmr= 0 -- To time how long messages stay +local Message= "Activated Multitrack recording script. Have fun!" + + +--The stuff below is adapted from the original Rewinding script by Antony Lavelle + +local saveArray = {};--the Array in which the save states are stored +local saveCount = 0;--used for finding which array position to cycle through +local saver; -- the variable used for storing the save state +local rewindCount = 0;--this stops you looping back around the array if theres nothing at the end +local savePreventBuffer = 1;--Used for more control over when save states will be saved, not really used in this version much. + + +-- Initialize tables for each player. +for i= 1, players do + Pin[i] = {} + thisInput[i] = {} + option[i] = {} + BufInput[i] = {} + BufLen[i] = 0 + for j= 1, 8 do + option[i][btn[j]]= 1 + end +end + +-- Intention of options: +-- "Both" Script buttons and input list used +-- "Keys" Script buttons used +-- "List" Input list used +-- "Off" Script will not interfere with button + + +--***************************************************************************** +function press(button) +--***************************************************************************** +--FatRatKnight +-- Checks if a button is pressed. +-- The tables it accesses should be obvious in the next line. + + if keys[button] and not lastkeys[button] then + return true + end + + return false +end + + +--***************************************************************************** +function pressrepeater(button) +--***************************************************************************** +--DarkKobold; Changes by FatRatKnight. Description by FatRatKnight +-- Checks if a button is pressed. Will keep returning true if held long enough. +-- Accesses: keys[], lastkeys[], repeater + + if keys[button] then + if not lastkeys[button] or repeater >= 3 then + return true + else + repeater = repeater + 1; + end + + elseif lastkeys[button] then -- To allow more calls for other buttons + repeater= 0 + end; + return false +end + + +--***************************************************************************** +function NewMsg(text) +--***************************************************************************** +--FatRatKnight +-- Sets the message and resets the timer +-- Accesses: MsgTmr, Message + + MsgTmr= 0 + Message= text +end + + +--***************************************************************************** +function DispMsg() +--***************************************************************************** +--FatRatKnight +-- Merely displays whatever text happens to be in Message +-- Accesses: MsgTmr, Message, MsgDuration + + if MsgTmr < MsgDuration then + MsgTmr= MsgTmr + 1 + gui.text(0,20,Message) + end +end + + +--***************************************************************************** +function RewindThis() +--***************************************************************************** +--Added by DarkKobold; Made into function that returns T/F by FatRatKnight +-- Loads a state that was saved just the frame prior +-- Lets you know whether it was successful by returning true or false. +-- Accesses: rewindCount, saveArray, saveCount, saveMax + + if rewindCount<=0 then + return false -- Failed to rewind + else + savestate.load(saveArray[saveCount]); + saveCount = saveCount-1; + rewindCount = rewindCount-1; + if saveCount<=0 then + saveCount = saveMax; + end; + end; + return true -- Yay, rewind! +end + + +--***************************************************************************** +function GetNextInput(P) +--***************************************************************************** +--FatRatKnight +-- Gets the input from the input table. +-- Accesses: BufLen[], BufInput[], fc, Pin[] + + if BufLen[P] > 0 then + return BufInput[P][BufLen[P]] + end + return Pin[P][fc-BufLen[P]] +end + + +--***************************************************************************** +function LoadStoredInput(P) +--***************************************************************************** +--FatRatKnight +-- Loads up input into thisInput. +-- Found a good reason why it should be called in several spots. +-- Accesses: option[], thisInput[] + + local next= GetNextInput(P) + if next then + for i= 1, 8 do + local op= option[P][btn[i]] + if op == 1 or op == 3 then -- "Both" or "List" + thisInput[P][btn[i]]= next[btn[i]] + else + thisInput[P][btn[i]]= nil + end + end + else -- No input to load, so erase stuff. + for i= 1, 8 do + thisInput[P][btn[i]]= nil + end + end +end + + +--***************************************************************************** +function GetList(P,Offset) +--***************************************************************************** +--FatRatKnight +-- Fetches the input from the list relative to current framecount. +-- It takes into account insertions and deletions. +-- Accesses: thisInput[], Pin[], BufLen[], BufInput[] + + if Offset == 0 then + return thisInput[P] + elseif Offset < 0 then + return Pin[P][fc+Offset] + end + + if BufLen[P] > 0 and BufLen[P] > Offset then + return BufInput[P][BufLen[P]-Offset] + end + return Pin[P][fc+Offset-BufLen[P]] +end + + +--***************************************************************************** +function InputSnap(P) +--***************************************************************************** +--FatRatKnight +-- Will shove the input list over. +-- Might end up freezing for a moment if there's a few thousand frames to shift +-- Accesses: framed, BufLen, BufInput[], Pin[], players + + + if BufLen[P] < 0 then -- Squish! + local pointer= lastfc + while Pin[P][pointer] do + Pin[P][pointer]= Pin[P][pointer-BufLen[P]] + pointer= pointer+1 + end + end + + + if BufLen[P] > 0 then -- Foom! + local pointer= lastfc + while Pin[P][pointer] do + pointer= pointer+1 + end + -- pointer is now looking at a null frame. + -- Assume later frames are also null. + + while pointer > lastfc do + pointer= pointer-1 + Pin[P][pointer+BufLen[P]]= Pin[P][pointer] + end + -- pointer should now match lastfc. + -- Everything at lastfc and beyond should be moved over by BufLen. + + for i=0, BufLen[P]-1 do + Pin[P][lastfc +i]= BufInput[P][BufLen[P]-i] + end + end + + BufLen[P]= 0 -- If it ain't zero before, we did stuff to make us want it zero. +end + + +--***************************************************************************** +function NewFrame() +--***************************************************************************** +--FatRatKnight +-- Psuedo-detection of frame-advance or state load. +-- The lack of a function to otherwise detect state loads calls for this function +-- Accesses: fc, lastfc, FrameAdvance + + fc= movie.framecount() + + for P= 1, players do + InputSnap(P) + LoadStoredInput(P) + end +end + +savestate.registerload(NewFrame) + + +--***************************************************************************** +local Draw= {} --Draw[button]( Left , Top , color ) +--***************************************************************************** +--FatRatKnight +-- A set of functions for which to draw unique objects for each button. +-- The functions are in a table, so I can index them easy. +-- For use with DisplayInput() + +function Draw.right(x,y,color) -- ## + gui.line(x ,y ,x+1,y ,color) -- # + gui.line(x ,y+2,x+1,y+2,color) -- ## + gui.pixel(x+2,y+1,color) +end + +function Draw.left(x,y,color) -- ## + gui.line(x+1,y ,x+2,y ,color) -- # + gui.line(x+1,y+2,x+2,y+2,color) -- ## + gui.pixel(x ,y+1,color) +end + +function Draw.up(x,y,color) -- # + gui.line(x ,y+1,x ,y+2,color) -- # # + gui.line(x+2,y+1,x+2,y+2,color) -- # # + gui.pixel(x+1,y ,color) +end + +function Draw.down(x,y,color) -- # # + gui.line(x ,y ,x ,y+1,color) -- # # + gui.line(x+2,y ,x+2,y+1,color) -- # + gui.pixel(x+1,y+2,color) +end + +function Draw.start(x,y,color) -- # + gui.line(x+1,y ,x+1,y+2,color) -- ### + gui.line(x ,y+1,x+2,y+1,color) -- # +end + +function Draw.select(x,y,color) -- ### + gui.box(x ,y ,x+2,y+2,color) -- # # +end -- ### + +function Draw.A(x,y,color) -- ### + gui.box(x ,y ,x+2,y+1,color) -- ### + gui.pixel(x ,y+2,color) -- # # + gui.pixel(x+2,y+2,color) +end + +function Draw.B(x,y,color) -- # # + gui.line(x ,y ,x ,y+2,color) -- ## + gui.line(x+1,y+1,x+2,y+2,color) -- # # + gui.pixel(x+2,y ,color) +end + + +--***************************************************************************** +function DisplayInput() +--***************************************************************************** +--FatRatKnight; Changes by DarkKobold. +-- Shows the input stream that is stored in this script. +-- Converted into function form. There might be other ways of handling it. +-- Accesses: dispX, dispY, Pin[], thisInput[], players + +dispX= math.min(math.max(dispX,-2),219) +if pl > players then -- All players, man? + dispX= math.min(dispX,243-16*players) +end + +if (Future-Past) > 53 then + Past= math.max(Past, -53) + Future= Past + 53 +end +Past = math.min(Past ,0) +Future= math.max(Future,0) +dispY = math.min(math.max(dispY, 3-4*Past),217-4*Future) + + for i= Past, Future do + + local X,Y= dispX,dispY + if i < 0 then + Y= Y-3 + elseif i > 0 then + Y= Y+3 + end + + for P= plmin, plmax do + local temp= {} -- I may want to pick thisInput instead of the frame list. + temp= GetList(P,i) + + local color + for j= 1, 8 do + if not temp then + color= "white" + elseif temp[btn[j]] then + color= "green" + else + color= "red" + end + + if pl <= players then + Draw[btn[j]]( X +4*j , Y +4*i , color) + else -- all players + local bx= X+1 +j +2*players*(j-1) +2*P + gui.box(bx , Y+4*i , bx+1 , Y+4*i +2 ,color) + end + end + end + end + + local color= "white" -- immediate == true + if not immediate then + color= "blue" + for P= plmin, plmax do + local TI= GetNextInput(P) + for i=1, 8 do + if not TI or (TI[btn[i]] and not thisInput[P][btn[i]]) or (not TI[btn[i]] and thisInput[P][btn[i]])then + color= "green" + end + end + end + end + if pl <= players then + gui.box(dispX+2,dispY-2,dispX+36,dispY+4,color) + else + gui.box(dispX+2,dispY-2,dispX+12 +16*players,dispY+4,color) + end +end + + +-- Primary function. ... Why did I pick itisyourturn, anyway? +--***************************************************************************** +function itisyourturn() +--***************************************************************************** + keys= input.get() -- We need the keyboard and mouse! + fc= movie.framecount() -- We also need the Frame Count. + +-- State: Rewind + if saveMax > 0 then -- Disable Rewind if none exists + if pressrepeater(rewind) or rewinding then + rewinding= false + if RewindThis() then + NewFrame() + movie.rerecordcounting(true) + end + if rewindCount <= 0 then + emu.pause() + end + end + end + + if (fc == 0) and (lastfc ~= 0) then -- Hacky bit of script... + NewFrame() -- In case of resets that aren't + end -- considered stateloads. + +-- Selection: Players + if press(selectplayer) then + pl= pl + 1 + if (pl > players+1) or (players == 1) then + pl= 1 + end + +-- For standard player loops for allplayer option + if pl > players then + plmin= 1 + plmax= players + else + plmin= pl + plmax= pl + end + end + + +-- Input: Insert or delete frames + if press(add) then -- Part of the reason for + for P= plmin, plmax do -- speedy insertions and + BufLen[P]= BufLen[P]+1 -- deletions is due to the + if BufLen[P] > 0 then -- fact that I don't shift + BufInput[P][BufLen[P]]= {} -- frames immediately. + end + LoadStoredInput(P) + end + end -- I only shift once you + if press(remove) then -- begin rewind or load a + for P= plmin, plmax do -- state. At that point, + BufLen[P]= BufLen[P]-1 -- it may take a while if + LoadStoredInput(P) -- there's enough frames + end -- to shift around. + end + +-- Input: Should thisInput always instantly write to input table? + if press(SetImmediate) then + if not immediate then + immediate= true + else + immediate= false + end + end + +-- Input: Allow joypad to toggle input? + if press(TrueSwitch) then + if JoyOn == true then + JoyOn= "inv" + NewMsg("Joypad may now cancel input from the list") + else + JoyOn= true + NewMsg("Disabled joypad input cancellation") + end + end + if press(FalseSwitch) then + if JoyOff == false then + JoyOff= nil + NewMsg("Joypad may now write input into the list") + else + JoyOff= false + NewMsg("Disabled joypad input activation") + end + end + + +-- Option: Opacity + if press(hide) and opaque < 4 then + opaque= opaque+1 + end + if press(show) and opaque > 0 then + opaque= opaque-1 + end + gui.transparency(opaque) + +-- Option: Move input display by keyboard + if pressrepeater(scrlup) then + dispY= dispY - 1 + end + if pressrepeater(scrldown) then + dispY= dispY + 1 + end + if pressrepeater(scrlleft) then + dispX= dispX - 1 + end + if pressrepeater(scrlright) then + dispX= dispX + 1 + end + +-- Option: Move input display by mouse + if keys["leftclick"] and lastkeys["leftclick"] then + dispX= dispX + keys.xmouse - lastkeys.xmouse + dispY= dispY + keys.ymouse - lastkeys.ymouse + end + +-- Option: Adjust input display range + if pressrepeater(MorePast) then + Past= Past-1 -- Remember, Past is negative. + end -- Making it more negative would + if pressrepeater(LessPast) then -- let you see more of the past. + Past= Past+1 + end + if pressrepeater(MoreFuture) then -- On the other hand, I want to + Future= Future+1 -- make the Future positive. + end -- Don't we all want to be + if pressrepeater(LessFuture) then -- positive about the future? + Future= Future-1 + end + + +-- Begin start of frame change + if FrameAdvance then + for P= 1, players do + if not Pin[P][lastfc] then + InputSnap(P) -- If last frame was empty, kill the shift + end -- Don't track more than one buffer for loads + +-- Scroll the BufInput if there's anything in there. +-- This can potentially slow things if you insert enough frames. + if BufLen[P] > 0 then + for i= BufLen[P], 1, -1 do + BufInput[P][i]= BufInput[P][i-1] + end + BufInput[P][1]= Pin[P][lastfc] + end + +-- Store input + Pin[P][lastfc]= joypad.get(P) + + LoadStoredInput(P) + end -- Loop for each player + +-- Resets key input, so it counts as pressed again if held through frame advance. + for i= 1, 8 do + lastkeys[key[i]]= nil + end + + end +-- Done checking for a new frame + + +-- Begin checking key input +-- Are you setting button options? + if keys[recordingtype] then + gui.transparency(0) -- Override current opacity + for i= 1, 8 do -- key loop + +-- Set current options + for P= plmin, plmax do + if press(key[i]) then + option[P][btn[i]]= option[plmax][btn[i]]+1 + if option[P][btn[i]] > 4 then + option[P][btn[i]]= 1 + end + end + end + +-- Display current options + gui.text(20,20+12*i,btn[i]) + + if pl >= players + 1 then + local q= optType[option[1][btn[i]]] + for z= 2, players do + if q ~= optType[option[z][btn[i]]] then + q= "???" + break + end + end + gui.text(50,20+12*i,q) + else + gui.text(50,20+12*i,optType[option[pl][btn[i]]]) + end + + end -- key loop + +-- Are you setting actual input? + else + for i= 1, 8 do + +-- Toggle keyed input depending on options + for P= plmin, plmax do + op= option[P][btn[i]] + if op == 1 or op == 2 then -- "Both" or "Keys" + if press(key[i]) then + if thisInput[P][btn[i]] then + thisInput[P][btn[i]]= nil + else + thisInput[P][btn[i]]= true + end + end + end + end + + end -- key loop + +-- Done with input. +-- The next stuff is just displaying input table. +-- It's here to hide it when setting options. + if opaque < 4 then + DisplayInput() + end + end -- Done with "options" if + +-- Force copy of thisInput into the input table if immediate is on + if immediate then + for P= 1, players do + if not GetNextInput(P) then + Pin[P][fc-BufLen[P]]= {} + end -- Inserted frames always defined! Don't check for that + + if BufLen[P] > 0 then + for i= 1, 8 do + BufInput[P][BufLen[P]][btn[i]]= thisInput[P][btn[i]] + end + else + for i= 1, 8 do + Pin[P][fc-BufLen[P]][btn[i]]= thisInput[P][btn[i]] + end + end + end + end + +-- Display selected player. Or other odds and ends. + if pl <= players then + gui.text(30,10,pl) + gui.text(45,10,BufLen[pl]) + else + gui.text(30,10,"A") + end; + + DispMsg() -- Also display whatever message is in there. + +-- Change thisInput to conform to options + for P= 1, players do + for i= 1, 8 do + if thisInput[P][btn[i]] then + thisInput[P][btn[i]]= JoyOn -- Use the right kind of true + else + thisInput[P][btn[i]]= JoyOff -- And the right kind of false + end + end + end + +-- Feed the input to the emulation. + if movie.mode() ~= "playback" then + for P= 1, players do + joypad.set(P, thisInput[P]) + end + end + + lastfc= fc -- Standard "this happened last time" stuff + lastkeys= keys -- Don't want to keep registering key hits. + FrameAdvance= false + +end -- Yes, finally! The end of itisyourturn! +--***************************************************************************** + + +gui.register(itisyourturn) -- Need to call while in between frames + +emu.pause(); -- Immediate pause is nice + +--***************************************************************************** +while true do -- Main loop +--***************************************************************************** +-- Most of the stuff here by DarkKobold. Minor stuff by FatRatKnight +-- Rewinding feature originally by Antony Lavelle. +-- Keep in mind stuff here only happens on a frame advance or when unpaused. + + FrameAdvance= true + emu.frameadvance() + + if saveMax > 0 then -- Don't process if Rewind is disabled + if keys[rewind] and rewindCount > 0 then + rewinding= true + else + saveCount=saveCount+1; + rewindCount = math.min(rewindCount + 1,saveMax); + if saveCount==saveMax+1 then + saveCount = 1; + end + + if saveArray[saveCount] == nil then + saver = savestate.create(); + else + saver = saveArray[saveCount]; + end; + savestate.save(saver); + saveArray[saveCount] = saver; -- I'm pretty sure this line is unnecessary. + movie.rerecordcounting(false) + end + end + +end -- Main loop ends \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/Multitrack2.lua b/branches/fceux-2.2.2/output/luaScripts/Multitrack2.lua new file mode 100644 index 00000000..0913cb57 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Multitrack2.lua @@ -0,0 +1,1371 @@ +-- Multitrack v2 for FCEUX by FatRatKnight +-- Recent addition: Experimental save. Same format as in .fm2 +-- Did not include support to not have it trigger on script exit. Sorry... +-- Additionally, there's no *loading* mechanism in this script. Eh... + + +--*************** +local players= 2 -- You may tweak the number of players here. +--*************** + + +-- Rewind options +local saveMax= 50 -- How many save states to keep? Set to 0 to disable +local SaveBuf= 12 -- How many frames between saves? Don't use 0, ever. +local rewind= "numpad0" -- What key do you wish to hit for rewind? + +--Keep in mind: Higher saveMax, more savestates, more memory needed. + + +--Control +local PlayerSwitch= "home" -- For selecting other players +local opt= "end" -- For changing control options + +local BackupReadSwitch= "numpad-" -- Revert to backup copy +local BackupWriteSwitch= "numpad+" -- Copy input into backup + +local key = {"right", "left", "down", "up", "L", "O", "J", "K"} +local btn = {"right", "left", "down", "up", "start", "select", "B", "A"} + +--Try to avoid changing btn. You may reorder btn's stuff if you don't +--like the default order, however. Line up with key for good reasons. +--key is the actual keyboard control over the buttons. Change that! + + +--Insertions and deletions +local Insert= "insert" -- Inserts a frame at the frame you're at +local Delete= "delete" -- Eliminates current frame + + +--Display +local BackupDisplaySwitch= "numpad." -- Care to see the backup? + +local solid= "pageup" -- Make the display less +local clear= "pagedown" -- or more transparant. + +local DispN= "numpad8" +local DispS= "numpad2" -- For moving the +local DispE= "numpad6" -- display around. +local DispW= "numpad4" + +local MoreFutr= "numpad3" +local LessFutr= "numpad1" -- These will determine +local MorePast= "numpad7" -- how many frames you +local LessPast= "numpad9" -- want to display. +local ResetFP= "numpad5" + + +--Control options by keyboard +local OptUp= "numpad8" +local OptDn= "numpad2" -- Controls for changing +local OptRt= "numpad6" -- options by keyboard. +local OptLf= "numpad4" +local OptHit="numpad5" + + + +--Various colors I'm using. If you wish to bother, go ahead. +local shade= 0x00000080 +local white= "#FFFFFFFF" +local red= "#FF2000FF" +local green= 0x00FF00FF +local blue= 0x0040FFFF +local orange="#FFC000FF" +local yellow="#FFFF00FF" +local cyan= 0x00FFFFFF +local purple="#8020FFFF" + +--Default display stuff. Try to keep Past negative. +local DispX, DispY= 190, 70 --Position on screen to appear +local Past, Future= -12, 20 --How much input to see +local Opaque= 1 --0=unseen 1=visible Decimal in between works + + +local ListOfBtnClr= { -- Colors for individual buttons +--NotExist Off Ignored On + + white, red, orange, green, -- No backup to display + white, red, orange, green, -- Backup button is off + blue, blue, purple, cyan, -- Backup button is on + + white, red, orange, green, -- Same stuff as above. + white, red, orange, green, -- However, we're reading + blue, blue, purple, cyan, -- from backup here. + + white, red, orange, green, -- Likewise, but instead + white, red, orange, green, -- of read, we're writing + blue, blue, purple, cyan -- to the backup. Joy... +} + +local ListOfChangesClr= { -- Colors for backup-main comparisons +--NoMain NoMatch Equal + + white, green, blue, -- Backup just sits there... + white, orange, green, -- Reading from backup... + white, yellow, purple -- Writing to backup... +} + + + +local BackupFileLimit= 9 + + +--***************************************************************************** +--Please do not change the following, unless you plan to change the code: + +local plmin , plmax= 1 , 1 +local fc= movie.framecount() +local LastLoad= movie.framecount() +local saveCount= 0 +local saveArray= {} +local rewinding= false + +local BackupList= {} +local BackupOverride= {} +local DisplayBackup= true + +local InputList= {} +local ThisInput= {} +local BufInput= {} +local BufLen= {} +local TrueSwitch, FalseSwitch= {}, {} +local ReadList= {} +local ScriptEdit= {} + +for pl= 1, players do + InputList[pl]= {} + BackupList[pl]= {} + BackupOverride[pl]= false + ThisInput[pl]= {} + BufInput[pl]= {} + BufLen[pl]= 0 + + TrueSwitch[pl]= {} + FalseSwitch[pl]= {} + ReadList[pl]= {} + ScriptEdit[pl]= {} + for i= 1, 8 do + TrueSwitch[pl][i]= "inv" + FalseSwitch[pl][i]= nil + ReadList[pl][i]= true + ScriptEdit[pl][i]= false + end +end + +--***************************************************************************** +-- Just painting instructions here. + +print("Running Multitrack Script made by FatRatKnight.", + "\r\nIts primary use is to preserve input after a loadstate.", + "\r\nIt also gives precise control on changing this stored input.", + "\r\nEdit the script if you need to change stuff. All options are near the top.", + "\r\nThe script is currently set as follows:\r\n") + +print("Players:",players) +if players > 1 then + print("Player Switch key:",PlayerSwitch, + "\r\nThere is an All Players view as well, beyond the last player.\r\n") +else + print("With only one player, the PlayerSwitch button is disabled.\r\n") +end + +print("Maximum rewind states:",saveMax) +local CalcSeconds= math.floor(saveMax*SaveBuf*100/60)/100 +if saveMax > 0 then + print("Frames between saves:",SaveBuf, + "\r\nRewind key:",rewind, + "\r\nThis can go backwards up to about",CalcSeconds,"seconds.", + "\r\nRewind is a quick and easy way to back up just a few frames.", + "\r\nJust hit",rewind,"and back you go!\r\n") +else + print("Rewind function is disabled. Cheap on memory!\r\n") +end + +print("Hold >",opt,"< to view control options.", + "\r\nYou may use the mouse or keyboard to toggle options.", + "\r\nFor keyboard, use",OptUp,OptDn,OptRt,OptLf,"to choose an option and", + OptHit,"to toggle the option.", + "\r\nFor mouse, it's as simple at point and click.", + "\r\nIf viewing All Players, changing options will affect all players.\r\n") + +print("For the frame display, you can drag it around with the mouse.", + "\r\nTo move it by keyboard:",DispN,DispS,DispE,DispW, + "\r\nTo change frames to display:",MoreFutr,LessFutr,MorePast,LessPast, + "\r\nTo recenter display around current frame:",ResetFP, + "\r\nLastly, hide it with >",clear,"< and show it with >",solid,"<\r\n") + +print("Insert frame:",Insert, + "\r\nDelete frame:",Delete, + "\r\nThese keys allow you to shift frames around the current frame.", + "Perhaps you found an improvement to a segment and want to delete frames.", + "Or this small trick you wanted to add requires shifting a few frames forward.", + "These buttons let you shift frames around without forcing you to", + "modify each and every one of them individually.\r\n") + + +print("Script keys:", + "\r\nJoy - Keyboard", + "\r\n------------") +for i= 1, 8 do + print(btn[i],"-",key[i]) +end +print("By default, these are disabled. Enable them through the control options.", + "\r\nThey are a one-tap joypad switch for precision control.", + "\r\nIt will affect the currently displayed player, or all of them if", + "it's displaying All Players.\r\n") + +print("If you want to \"load\" an fm2 into this script, run the play file", + "while running this script. As the movie on read-only plays out, the", + "script will pick up its input. The script does not need to start from", + "frame 1 -- Load a state near the end of a movie if you so wish!", + "Once input is loaded, you may continue whatever you were doing.\r\n") + +print("Remember, edit the script if you don't like the current options. All", + "the options you should care about are near the top, clearly marked.", + "Change the control keys through there, as well as number of players or rewind limits.", + "\r\nThis script works with the joypad you actually set from FCEUX's config,", + "and they can even cancel input stored in this script.", + +"\r\n\r\nAnd have fun with this script. I hope your experiments with this script goes well.", +"\r\n\r\nLeeland Kirwan, the FatRatKnight.") + +print("Players:",players," - - ",CalcSeconds,"seconds of rewind.") + + + +--***************************************************************************** +function FBoxOld(x1, y1, x2, y2, color) +--***************************************************************************** +-- Gets around FCEUX's problem of double-painting the corners. +-- The double-paint is visible with non-opaque drawing. +-- It acts like the old-style border-only box. +-- Slightly messes up when x2 or y2 are less than their counterparts. + + if (x1 == x2) and (y1 == y2) then + gui.pixel(x1,y1,color) + + elseif (x1 == x2) or (y1 == y2) then + gui.line(x1,y1,x2,y2,color) + + else --(x1 ~= x2) and (y1 ~= y2) + gui.line(x1 ,y1 ,x2-1,y1 ,color) -- top + gui.line(x2 ,y1 ,x2 ,y2-1,color) -- right + gui.line(x1+1,y2 ,x2 ,y2 ,color) -- bottom + gui.line(x1 ,y1+1,x1 ,y2 ,color) -- left + end +end + + +--***************************************************************************** +function FakeBox(x1, y1, x2, y2, Fill, Border) +--***************************************************************************** +-- Gets around FCEUX's problem of double-painting the corners. +-- It acts like the new-style fill-and-border box. + +if not Border then Border= Fill end + + gui.box(x1,y1,x2,y2,Fill,0) + FBoxOld(x1,y1,x2,y2,Border) +end + + +--***************************************************************************** +local Draw= {} --Draw[button]( Left , Top , color ) +--***************************************************************************** + +function Draw.right(x,y,color) -- ## + gui.line(x ,y ,x+1,y ,color) -- # + gui.line(x ,y+2,x+1,y+2,color) -- ## + gui.pixel(x+2,y+1,color) +end + +function Draw.left(x,y,color) -- ## + gui.line(x+1,y ,x+2,y ,color) -- # + gui.line(x+1,y+2,x+2,y+2,color) -- ## + gui.pixel(x ,y+1,color) +end + +function Draw.up(x,y,color) -- # + gui.line(x ,y+1,x ,y+2,color) -- # # + gui.line(x+2,y+1,x+2,y+2,color) -- # # + gui.pixel(x+1,y ,color) +end + +function Draw.down(x,y,color) -- # # + gui.line(x ,y ,x ,y+1,color) -- # # + gui.line(x+2,y ,x+2,y+1,color) -- # + gui.pixel(x+1,y+2,color) +end + +function Draw.start(x,y,color) -- # + gui.line(x+1,y ,x+1,y+2,color) -- ### + gui.pixel(x ,y+1,color) -- # + gui.pixel(x+2,y+1,color) +end + +function Draw.select(x,y,color) -- ### + FBoxOld(x ,y ,x+2,y+2,color) -- # # +end -- ### + +function Draw.A(x,y,color) -- ### + FBoxOld(x ,y ,x+2,y+1,color) -- ### + gui.pixel(x ,y+2,color) -- # # + gui.pixel(x+2,y+2,color) +end + +function Draw.B(x,y,color) -- # # + gui.line(x ,y ,x ,y+2,color) -- ## + gui.line(x+1,y+1,x+2,y+2,color) -- # # + gui.pixel(x+2,y ,color) +end + + + +function Draw.D0(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+2,top ,left+2,top+4,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+4,color) +end + +function Draw.D1(left, top, color) + gui.line(left ,top+4,left+2,top+4,color) + gui.line(left+1,top ,left+1,top+3,color) + gui.pixel(left ,top+1,color) +end + +function Draw.D2(left, top, color) + gui.line(left ,top ,left+2,top ,color) + gui.line(left ,top+3,left+2,top+1,color) + gui.line(left ,top+4,left+2,top+4,color) + gui.pixel(left ,top+2,color) + gui.pixel(left+2,top+2,color) +end + +function Draw.D3(left, top, color) + gui.line(left ,top ,left+1,top ,color) + gui.line(left ,top+2,left+1,top+2,color) + gui.line(left ,top+4,left+1,top+4,color) + gui.line(left+2,top ,left+2,top+4,color) +end + +function Draw.D4(left, top, color) + gui.line(left ,top ,left ,top+2,color) + gui.line(left+2,top ,left+2,top+4,color) + gui.pixel(left+1,top+2,color) +end + +function Draw.D5(left, top, color) + gui.line(left ,top ,left+2,top ,color) + gui.line(left ,top+1,left+2,top+3,color) + gui.line(left ,top+4,left+2,top+4,color) + gui.pixel(left ,top+2,color) + gui.pixel(left+2,top+2,color) +end + +function Draw.D6(left, top, color) + gui.line(left ,top ,left+2,top ,color) + gui.line(left ,top+1,left ,top+4,color) + gui.line(left+2,top+2,left+2,top+4,color) + gui.pixel(left+1,top+2,color) + gui.pixel(left+1,top+4,color) +end + +function Draw.D7(left, top, color) + gui.line(left ,top ,left+1,top ,color) + gui.line(left+2,top ,left+1,top+4,color) +end + +function Draw.D8(left, top, color) + gui.line(left ,top ,left ,top+4,color) + gui.line(left+2,top ,left+2,top+4,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+2,color) + gui.pixel(left+1,top+4,color) +end + +function Draw.D9(left, top, color) + gui.line(left ,top ,left ,top+2,color) + gui.line(left+2,top ,left+2,top+3,color) + gui.line(left ,top+4,left+2,top+4,color) + gui.pixel(left+1,top ,color) + gui.pixel(left+1,top+2,color) +end + + +Draw[0],Draw[1],Draw[2],Draw[3],Draw[4]=Draw.D0,Draw.D1,Draw.D2,Draw.D3,Draw.D4 +Draw[5],Draw[6],Draw[7],Draw[8],Draw[9]=Draw.D5,Draw.D6,Draw.D7,Draw.D8,Draw.D9 +--***************************************************************************** +function DrawNum(right, top, Number, color, bkgnd) +--***************************************************************************** +-- Paints the input number as right-aligned. +-- Returns the x position where it would paint another digit. +-- It only works with integers. Rounds fractions toward zero. + + local Digit= {} + local Negative= false + if Number < 0 then + Number= -Number + Negative= true + end + + Number= math.floor(Number) + if not color then color= "white" end + if not bkgnd then bkgnd= "clear" end + + local i= 0 + if Number < 1 then + Digit[1]= 0 + i= 1 + end + + while (Number >= 1) do + i= i+1 + Digit[i]= Number % 10 + Number= math.floor(Number/10) + end + + if Negative then i= i+1 end + local left= right - i*4 + FakeBox(left+1, top-1, right+1, top+5,bkgnd,bkgnd) + + i= 1 + while Draw[Digit[i]] do + Draw[Digit[i]](right-2,top,color) + right= right-4 + i=i+1 + end + + if Negative then + gui.line(right, top+2,right-2,top+2,color) + right= right-4 + end + return right +end + + +--***************************************************************************** +function limits( value , low , high ) -- Expects numbers +--***************************************************************************** +-- Returns value, low, or high. high is returned if value exceeds high, +-- and low is returned if value is beneath low. + + return math.max(math.min(value,high),low) +end + +--***************************************************************************** +function within( value , low , high ) -- Expects numbers +--***************************************************************************** +-- Returns true if value is between low and high. False otherwise. + + return ( value >= low ) and ( value <= high ) +end + + +local keys, lastkeys= {}, {} +--***************************************************************************** +function press(button) -- Expects a key +--***************************************************************************** +-- Returns true or false. +-- Generally, if keys is pressed, the next loop around will set lastkeys, +-- and thus prevent returning true more than once if held. + + return (keys[button] and not lastkeys[button]) +end + +local repeater= 0 +--***************************************************************************** +function pressrepeater(button) -- Expects a key +--***************************************************************************** +--DarkKobold & FatRatKnight +-- Returns true or false. +-- Acts much like press if you don't hold the key down. Once held long enough, +-- it will repeatedly return true. +-- Try not to call this function more than once per main loop, since I've only +-- set one repeater variable. Inside a for loop is real bad. + + if keys[button] then + if not lastkeys[button] or repeater >= 3 then + return true + else + repeater = repeater + 1; + end + + elseif lastkeys[button] then -- To allow more calls for other buttons + repeater= 0 + end; + return false +end + + + +--***************************************************************************** +function JoyToNum(Joys) -- Expects a table containing joypad buttons +--***************************************************************************** +-- Returns a number from 0 to 255, representing button presses. +-- These numbers are the primary storage for this version of this script. + + local joynum= 0 + + for i= 1, 8 do + if Joys[btn[i]] then + joynum= bit.bor(joynum, bit.rshift(0x100,i)) + end + end + + return joynum +end + +--***************************************************************************** +function ReadJoynum(input, button) -- Expects... Certain numbers! +--***************************************************************************** +-- Returns true or false. True if the indicated button is pressed +-- according to the input. False otherwise. +-- Helper function + return ( bit.band(input , bit.rshift( 0x100,button )) ~= 0 ) +end + + +--***************************************************************************** +function RewindThis() +--***************************************************************************** +--DarkKobold & FatRatKnight; Original concept by Antony Lavelle + + if saveCount <= 0 then + return false -- Failed to rewind + else + savestate.load(saveArray[saveCount]); + saveCount = saveCount-1; + end; + return true -- Yay, rewind! +end + + +--***************************************************************************** +function ShowOnePlayer(x,y,color,button,pl) +--***************************************************************************** +-- Displays an individual button. +-- Helper function for DisplayInput. + + x= x + 4*button - 3 + Draw[btn[button]](x,y,color) +end + +--***************************************************************************** +function ShowManyPlayers(x,y,color,button,pl) +--***************************************************************************** +-- Displays an individual button. Uses 2x3 boxes instead of button graphics. +-- Helper function for DisplayInput. + + x= x + (2*players + 1)*(button - 1) + 2*pl - 1 + FBoxOld(x,y,x+1,y+2,color) +end + + +Future= limits(Future,Past,Past+53) --Idiot-proofing +--***************************************************************************** +function DisplayOptions(width) -- Expects width calculated by DisplayInput +--***************************************************************************** +-- Returns true if Opaque is 0, as a signal to don't bother painting. +-- Separated from DisplayInput to make it clear which half is doing what. + + +-- Change opacity? + if pressrepeater(solid) then Opaque= Opaque + 1/8 end + if pressrepeater(clear) then Opaque= Opaque - 1/8 end + Opaque= limits(Opaque,0,1) + + gui.opacity(Opaque) + if Opaque == 0 then return true end + -- Don't bother processing display if there's none to see. + +-- How many frames to show? + if pressrepeater(LessFutr) then + Future= Future-1 + if Future < Past then Past= Future end + end + if pressrepeater(MoreFutr) then + Future= Future+1 + if Future > Past+53 then Past= Future-53 end + end + if pressrepeater(MorePast) then + Past= Past-1 + if Past < Future-53 then Future= Past+53 end + end + if pressrepeater(LessPast) then + Past= Past+1 + if Past > Future then Future= Past end + end + + if press(ResetFP) then Past= -12; Future= 12 end + + +-- Move the display around? + if pressrepeater(DispS) then DispY= DispY+1 end + if pressrepeater(DispW) then DispX= DispX-1 end + if pressrepeater(DispE) then DispX= DispX+1 end + if pressrepeater(DispN) then DispY= DispY-1 end + + if keys["leftclick"] and lastkeys["leftclick"] then + DispX= DispX + keys.xmouse - lastkeys.xmouse + DispY= DispY + keys.ymouse - lastkeys.ymouse + end + +--Miscellaneous + if press(BackupDisplaySwitch) then DisplayBackup= not DisplayBackup end + DispX= limits(DispX,2,254-width) + DispY= limits(DispY,3-4*Past,218-4*Future) + + + return nil -- Signal to display the input +end + + +--***************************************************************************** +function DisplayInput() +--***************************************************************************** +-- Paints on the screen the current input stored within the script's list. + +--Are we showing all players or just one? + local HighlightButton= ShowOnePlayer + local width= 32 + if plmin ~= plmax then + HighlightButton= ShowManyPlayers + width= 16*players + 8 + end + +--For both setting options and asking if we should bother displaying ourselves + if DisplayOptions(width) then return end + +--Display frame offsets we're looking at. + local RtDigit= DispX + width + 22 + if RtDigit > 254 then RtDigit= DispX - 4 end + local TpDigit= DispY + 4*Past - 2 + DrawNum(RtDigit,TpDigit,Past,white,shade) + + if Future > Past+1 then + TpDigit= DispY + 4*Future + DrawNum(RtDigit,TpDigit,Future,white,shade) + end + +--Show cute little box around current frame + if Past <= 0 and Future >= 0 then + local color= blue + for pl= plmin, plmax do + local ThisFrame= InputList[pl][fc-BufLen[pl]] + if BufLen[pl] > 0 then ThisFrame= BufInput[pl][1] end + if ThisFrame ~= JoyToNum(ThisInput[pl]) then color= green end + end + FBoxOld(DispX-1,DispY-2,DispX+width+1,DispY+4,color) + end + +--Shade the proper regions efficiently + if Past < 0 then + local Y1= DispY + 4*Past -3 + local Y2= DispY - 3 + if Future < -1 then Y2= DispY + 4*Future +1 end + FakeBox(DispX,Y1,DispX+width,Y2,shade,shade) + end + if Future > 0 then + local Y1= DispY + 5 + local Y2= DispY + 4*Future+5 + if Past > 1 then Y1= DispY + 4*Past +1 end + FakeBox(DispX,Y1,DispX+width,Y2,shade,shade) + end + if Past <= 0 and Future >= 0 then + FakeBox(DispX,DispY-1,DispX+width,DispY+3,shade,shade) + end + +--Finally, we get to show the actual buttons! + for i= Past, Future do + local Y= DispY + 4*i + if i < 0 then Y=Y-2 + elseif i > 0 then Y=Y+2 end + + local BackupColor= nil -- For displaying a line for backup + for pl= plmin, plmax do + local scanz + if i < 0 then scanz= InputList[pl][fc+i] + elseif i == 0 then scanz= JoyToNum(ThisInput[pl]) + elseif i < BufLen[pl] then + scanz= BufInput[pl][i+1] + else scanz= InputList[pl][fc+i-BufLen[pl]] + end + for button= 1, 8 do + +-- Take a number, oh mighty color. There's too much of ya! + local color + if not scanz then + color= 1 --Does not exist + elseif ReadJoynum(scanz,button) then + if (i <= 0) or (ReadList[pl][button]) then + color= 4 --Button on + else + color= 3 --Button on, will be ignored + end + else + color= 2 --Button off + end + + if DisplayBackup then + if BackupList[pl][fc+i] then + if ReadJoynum(BackupList[pl][fc+i],button) then + color= color+8 + else + color= color+4 + end + end + if BackupOverride[pl] == "read" then + color= color+12 + elseif BackupOverride[pl] == "write" then + color= color+24 + end + end + + HighlightButton(DispX,Y,ListOfBtnClr[color],button,pl) + + end -- button loop + +-- Draw cute lines if we wish to see the backup + if DisplayBackup and BackupList[pl][fc+i] then + if not BackUpColor then + if not scanz then + BackupColor= 1 + elseif scanz == BackupList[pl][fc+i] then + BackupColor= 3 + else + BackupColor= 2 + end + if BackupOverride[pl] == "read" then + BackupColor= BackupColor+3 + elseif BackupOverride[pl] == "write" then + BackupColor= BackupColor+6 + end + + else -- Eh, we already have a BackupColor? + local CheckColor= (BackupColor-1)%3 + if not scanz then + BackupColor= BackupColor - CheckColor + elseif (scanz ~= BackupList[pl][fc+i]) and (CheckColor == 2) then + BackupColor= BackupColor - 1 + end + end + end + + end -- player loop + + if BackupColor then + gui.line(DispX-2,Y,DispX-2,Y+2,ListOfChangesClr[BackupColor]) + end + end -- loop from Past to Future +end --function + + +--***************************************************************************** +function SetInput() +--***************************************************************************** +-- Prepares ThisInput for joypad use. + + for pl= 1, players do + local temp + if BackupOverride[pl] == "read" then + temp= BackupList[pl][fc] + else + if BufLen[pl] > 0 then + temp= BufInput[pl][1] + else + temp= InputList[pl][fc-BufLen[pl]] + end + end + + for i= 1, 8 do + if temp and ReadJoynum(temp,i) and ReadList[pl][i] then + ThisInput[pl][btn[i]]= TrueSwitch[pl][i] + else + ThisInput[pl][btn[i]]= FalseSwitch[pl][i] + end + end + end +end + + +--***************************************************************************** +function ApplyInput() +--***************************************************************************** +-- Shoves ThisInput into the actual emulator joypads. + + if movie.mode() ~= "playback" then + for pl= 1, players do + joypad.set(pl, ThisInput[pl]) + end + end +end + + +--***************************************************************************** +function InputSnap() +--***************************************************************************** +-- Will shove the input list over. +-- Might end up freezing for a moment if there's a few thousand frames to shift + + for pl= 1, players do + + if BufLen[pl] < 0 then -- Squish! + local pointer= fc + while InputList[pl][pointer] do + InputList[pl][pointer]= InputList[pl][pointer-BufLen[pl]] + pointer= pointer+1 + end + end + + + if BufLen[pl] > 0 then -- Foom! + local pointer= fc + while InputList[pl][pointer] do + pointer= pointer+1 + end + -- pointer is now looking at a null frame. + -- Assume later frames are also null. + + while pointer > fc do + pointer= pointer-1 + InputList[pl][pointer+BufLen[pl]]= InputList[pl][pointer] + end + -- pointer should now match fc. + -- Everything at fc and beyond should be moved over by BufLen. + + for i=0, BufLen[pl]-1 do + InputList[pl][fc +i]= table.remove(BufInput[pl],1) + end + end + + BufLen[pl]= 0 -- If it ain't zero before, we want it zero now! + + end +end + + + + +local XStart, XDiff= 30, 25 +local YStart, YDiff= 12, 15 +local Status= { {},{},{},{} } +local TargA= {FalseSwitch,TrueSwitch,ReadList,ScriptEdit} +local TrueA= { nil , "inv" , true , true } +local FalsA= { false , true , false , false } +local BtnX, BtnY= 0, 0 + +local BasicText= { +"Activate: Lets the joypad activate input.", +"Remove: Allows the joypad to remove input.", +"List: Should the script remember button presses?", +"Keys: Allow the script-specific keys to work?"} + +local AdvText= { +{"With both joypad options on, you have full control.", + "Held buttons will toggle the script's stored input."}, -- 1 + +{"With this on-off set-up, auto-hold will not", + "accidentally cancel input, such as from load state."}, -- 2 + +{"With this off-on set, you can use auto-hold to", + "elegantly strip off unwanted input."}, -- 3 + +{"With both joypad options off, you ensure you can't", + "accidentally change what's stored in the script."}, -- 4 + +{"List on: Script will apply input stored within.", + "This is the whole point of the script, ya know."}, -- 5 + +{"List off: Stored input is ignored. A good idea if", + "you don't want the script interfering."}, -- 6 + +{"Keys on: Script keys will toggle the button press", + "for the current frame. Meant for precise edits."}, -- 7 + +{"Keys off: Script-specific keys are no longer a", + "factor. Long-term control is meant for joypad!"}, -- 8 + +{"Apparently, you've selected 'All players'", + "and they have different options set."}, -- 9 + +{"This is the 'All' button. Selecting this will set", + "all 'Yes' or all 'No' for this particular option."} --10 +} + +--***************************************************************************** +function ControlOptions() +--***************************************************************************** +-- Lets the user make adjustments on the various controls of this script. +-- The interface, apparently, is most of the work! + + +-- Button selection + if (keys.xmouse ~= lastkeys.xmouse) or (keys.ymouse ~= lastkeys.ymouse) then + BtnX= math.floor((keys.xmouse- XStart+4)/XDiff) + BtnY= math.floor((keys.ymouse- YStart-6)/YDiff) + else + if press(OptUp) then + BtnX= limits(BtnX ,1,4) + BtnY= limits(BtnY-1,1,9) + end + if press(OptDn) then + BtnX= limits(BtnX ,1,4) + BtnY= limits(BtnY+1,1,9) + end + if press(OptRt) then + BtnX= limits(BtnX+1,1,4) + BtnY= limits(BtnY ,1,9) + end + if press(OptLf) then + BtnX= limits(BtnX-1,1,4) + BtnY= limits(BtnY ,1,9) + end + end + + +--Did you punch something? + if press("leftclick") or press(OptHit) then + if within( BtnY , 1 , 9 ) then + if within( BtnX , 1 , 4 ) then + local LoopS, LoopF= 1, 8 + if BtnY ~= 9 then + LoopS, LoopF= BtnY, BtnY + end + + local Target, TstT, TstF= TargA[BtnX], TrueA[BtnX], FalsA[BtnX] + + for pl= plmin, plmax do + for Loop= LoopS, LoopF do + if Target[plmax][LoopF] == TstT then + Target[pl][Loop]= TstF + else + Target[pl][Loop]= TstT + end + end + end + + end + end + end + + +--Figure out the status + for i= 1, 4 do + for j= 1, 8 do + Status[i][j]= TargA[i][plmin][j] + local pl= plmin+1 + while (pl <= plmax) do + if Status[i][j] ~= TargA[i][pl][j] then + Status[i][j]= "???" + break + end + pl= pl+1 + end + if Status[i][j] == TrueA[i] then Status[i][j]= "Yes" + elseif Status[i][j] == FalsA[i] then Status[i][j]= "No" end + end + end + +--============================================================================= +--Begin drawing. Finally... + + +--Shade the whole freaking screen + FakeBox(0,0,255,223,shade,shade) + +-- Silly little graphics +-- Perhaps I shouldn't always assume that button right is a right arrow... + Draw.B( XStart + XDiff ,YStart,red) + Draw.right( XStart + XDiff + 5,YStart,white) + Draw.B( XStart + XDiff +10,YStart,green) + + Draw.B( XStart + XDiff*2 ,YStart,green) + Draw.right( XStart + XDiff*2+ 5,YStart,white) + Draw.B( XStart + XDiff*2+10,YStart,red) + + Draw[btn[1]](XStart + XDiff*3 ,YStart ,green) + Draw[btn[1]](XStart + XDiff*3 ,YStart+4,green) + Draw[btn[2]](XStart + XDiff*3+ 4,YStart ,green) + Draw[btn[2]](XStart + XDiff*3+ 4,YStart+4,red) + Draw[btn[3]](XStart + XDiff*3+ 8,YStart ,red) + Draw[btn[3]](XStart + XDiff*3+ 8,YStart+4,green) + Draw[btn[4]](XStart + XDiff*3+12,YStart ,red) + Draw[btn[4]](XStart + XDiff*3+12,YStart+4,red) + + gui.box(XStart+XDiff*4,YStart,XStart+XDiff*4+14,YStart+6,0,green) + Draw[btn[6]](XStart + XDiff*4+ 2,YStart+2,green) + Draw[btn[7]](XStart + XDiff*4+ 6,YStart+2,green) + Draw[btn[8]](XStart + XDiff*4+10,YStart+2,green) + + +--Highlight button + if within( BtnY , 1 , 9 ) then + if within( BtnX , 1 , 4 ) then + local LowX=BtnX*XDiff +XStart -4 + local LowY=BtnY*YDiff +YStart -3 + gui.box(LowX,LowY,LowX+XDiff-2,LowY+YDiff-2,blue,blue) + +--Handle text. Feels sort of hard-coded, however + gui.text(1,160,BasicText[BtnX]) + + local adv + if BtnY == 9 then + adv= 10 + elseif Status[BtnX][BtnY] == "???" then + adv= 9 + elseif within(BtnX,1,2) and ((Status[3-BtnX][BtnY] == "???")) then + adv= 9 + elseif within(BtnX,1,2) then + adv= 1 + if Status[2][BtnY] == "No" then + adv= adv + 1 + end + if Status[1][BtnY] == "No" then + adv= adv + 2 + end + else + adv= 5 + if BtnX == 4 then + adv= adv+2 + end + if Status[BtnX][BtnY] == "No" then + adv= adv+1 + end + end + gui.text(1,175,AdvText[adv][1]) + gui.text(1,183,AdvText[adv][2]) + end + end + + +--Lines! + for i= 1, 5 do + local Xpos= XStart + XDiff*i -5 + gui.line(Xpos,0,Xpos,YStart + YDiff*10-4,green) + end + + for j= 1, 9 do + local Ypos= YStart + YDiff*j -4 + gui.line( 0, Ypos, XStart + XDiff*5-5, Ypos, green) + end + gui.line(XStart+XDiff-4, YStart + YDiff*10-4, XStart + XDiff*5-5, YStart + YDiff*10-4, green) + + +--Button labels! + for j= 1, 8 do + local Ypos= YStart + YDiff*j + gui.text( 1, Ypos, btn[j]) + Draw[btn[j]](XStart + XDiff - 12, Ypos, green) + + for i= 1, 4 do + gui.text(XStart + XDiff*i, Ypos, Status[i][j]) + end + end + + for i= 1, 4 do + gui.text(XStart + XDiff*i, YStart + YDiff*9, "All") + end + +end + + +--***************************************************************************** +function CatchInput() +--***************************************************************************** +-- For use with registerbefore. It will get the input and paste it into +-- the input list. + + fc= movie.framecount() + for pl= 1, players do + if BufLen[pl] > 0 then + table.remove(BufInput[pl],1) + table.insert(BufInput[pl],InputList[pl][fc-1]) + end + local NewJoy= JoyToNum(joypad.get(pl)) + InputList[pl][fc-1]= NewJoy + if not BackupList[pl][fc-1] or (BackupOverride[pl] == "write") then + BackupList[pl][fc-1]= NewJoy + end + end + SetInput() +end +emu.registerbefore(CatchInput) + + +--***************************************************************************** +function OnLoad() +--***************************************************************************** +-- For use with registerload. It updates ThisInput so we're not stuck with +-- junk being carried over when we load something. +-- Also clears whatever rewind stuff is stored. + + InputSnap() + for pl= 1, players do --Assume user is done messing with backup on load + BackupOverride[pl]= false + end + + fc= movie.framecount() + LastLoad= fc + saveCount= 0 + SetInput() + ApplyInput() -- Sanity versus unpaused stateload +end +savestate.registerload(OnLoad) + + +--***************************************************************************** +function ItIsYourTurn() +--***************************************************************************** +-- For use with gui.register. I need to catch input while paused! +-- Needed for a half-decent interface. + +--Ensure things are nice, shall we? + local fc_= movie.framecount() + lastkeys= keys + keys= input.get() + + if fc ~= fc_ then -- Sanity versus unusual jump (Reset cycle?) + OnLoad() + end + +--Process Rewind + if saveMax > 0 then -- Don't process if Rewind is disabled + if pressrepeater(rewind) or rewinding then + rewinding= false + if RewindThis() then + InputSnap() + movie.rerecordcounting(true) + fc= movie.framecount() + SetInput() + if saveCount < 1 then emu.pause() end + end + end + end + +--Should we bother the backups today? + for pl= plmin, plmax do + if press(BackupReadSwitch) then + if BackupOverride[pl] ~= "read" then + BackupOverride[pl]= "read" + else + BackupOverride[pl]= false + end + end + if press(BackupWriteSwitch) then + if BackupOverride[pl] ~= "write" then + BackupOverride[pl]= "write" + else + BackupOverride[pl]= false + end + end + end + + if keys[BackupReadSwitch] and keys[BackupWriteSwitch] then + gui.text(30,1,"Hey, quit holding both buttons!") + elseif keys[BackupReadSwitch] then + gui.text(30,1,"This lets the script revert to the backup.") + elseif keys[BackupWriteSwitch] then + gui.text(30,1,"This stores input into the backup.") + end + +--Switch players on keypress + if press(PlayerSwitch) then + if plmin ~= plmax then + plmax= 1 + elseif plmin == players then + plmin= 1 + else + plmin= plmin+1 + plmax= plmax+1 + end + end + +--Display which player we're selecting. Upperleft corner seems good. + if plmin == plmax then + gui.text(1,2,plmin) + gui.text(11,2,BufLen[plmin]) + else + gui.text(1,2,"A") + end + +--Check if we want to see control options + if keys[opt] then + gui.opacity(1) + ControlOptions() + SetInput() + +--Otherwise, handle what we can see + else + +--Inserts and deletes. +--table functions don't work well on tables that don't connect from 1. + if pressrepeater(Insert) then + for pl= plmin, plmax do + BufLen[pl]= BufLen[pl] + 1 + if BufLen[pl] > 0 then + table.insert(BufInput[pl],1,0) + end + end + SetInput() + end + if pressrepeater(Delete) then + for pl= plmin, plmax do + if BufLen[pl] > 0 then + table.remove(BufInput[pl],1) + end + BufLen[pl]= BufLen[pl] - 1 + end + SetInput() + end + +--Script key handler + for pl= plmin, plmax do + for i= 1, 8 do + if press(key[i]) and ScriptEdit[pl][i] then + if ThisInput[pl][btn[i]] then + ThisInput[pl][btn[i]]= FalseSwitch[pl][i] + else + ThisInput[pl][btn[i]]= TrueSwitch[pl][i] + end + end + end + end + + DisplayInput() + end + +--Last bits of odds and ends + ApplyInput() + + collectgarbage("collect") +end +gui.register(ItIsYourTurn) + + +--***************************************************************************** +function Rewinder() +--***************************************************************************** +-- Contains the saving part of the Rewind engine. +-- Original by Antony Lavelle, added by DarkKobold, messed by FatRatKnight + if saveMax > 0 then -- Don't process if Rewind is disabled + if keys[rewind] and saveCount > 0 then + rewinding= true + + elseif (fc - LastLoad)%SaveBuf == 0 then + if saveCount >= saveMax then + table.remove(saveArray,1) + else + saveCount= saveCount+1 + end + + if saveArray[saveCount] == nil then + saveArray[saveCount]= savestate.create(); + end + + savestate.save(saveArray[saveCount]); + + movie.rerecordcounting(false) + end + end + +end + +--emu.registerafter(Rewinder) + + + + + + + + +local TestNumOfDoom= 0 +local TestFile= io.open("Backup" .. TestNumOfDoom .. ".txt" , "r") +while TestFile do + TestFile:close() + TestNumOfDoom= TestNumOfDoom+1 + if TestNumOfDoom >= BackupFileLimit then break end + TestFile= io.open("Backup" .. TestNumOfDoom .. ".txt" , "r") +end + + + + +local FCEUXbtn= {"right", "left", "down", "up", "start", "select", "B", "A"} +local FCEUXfrm= {"R","L","D","U","T","S","B","A"} +local FCEUXorder= {} + +for i= 1, 8 do + for j= 1, 8 do + if btn[i] == FCEUXbtn[j] then + FCEUXorder[j]= i + break + end + end +end + +--***************************************************************************** +function SaveToFile() +--***************************************************************************** +-- Creates a file that, effectively, stores whatever's in the script at the +-- time. +-- List of known glitches: +-- It only reads player 1 when deciding when to start or stop. + + InputSnap() + local LatestIndex= 0 + local EarliestIndex= math.huge + for Frame, Pads in pairs(InputList[1]) do + LatestIndex= math.max(LatestIndex,Frame) + EarliestIndex= math.min(EarliestIndex,Frame) + end + + + local BFile = io.open("Backup" .. TestNumOfDoom .. ".txt" , "w") + BFile:write("StartFrame: " .. EarliestIndex .. "\n") + + for Frame= EarliestIndex, LatestIndex do + BFile:write("|0") + for pl= 1, 4 do + BFile:write("|") + if InputList[pl] then + if InputList[pl][Frame] then + local Pads= InputList[pl][Frame] + for i= 1, 8 do + if ReadJoynum(Pads,FCEUXorder[i]) then + BFile:write(FCEUXfrm[i]) + else + BFile:write(".") + end + end + else + BFile:write(" ") + end + end + end + BFile:write("\n") + end + BFile:close() + +end + +emu.registerexit(SaveToFile) + + + + + + + + + + + +emu.pause() + +while true do + Rewinder() + + emu.frameadvance() +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/NightmareElmStreet-4Player.lua b/branches/fceux-2.2.2/output/luaScripts/NightmareElmStreet-4Player.lua new file mode 100644 index 00000000..fca98c45 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/NightmareElmStreet-4Player.lua @@ -0,0 +1,57 @@ +--Nightmare on Elm Street 4-Player TAS, lua script +--Displays important values on screen, including player positions, lag counter, and timers +--April 16th 2009 +--Written by adelikat + +local lag = 0; --Stores lag flag (00D6) value +local lagCounter = 0; --Stores lag change value (increments every time +local screenpos = 0; --Stores the screen position value - 00E8 +local ZZZ1 = 0; --Day/Night timers +local ZZZ2 = 0; +local ZZZ3 = 0; +local HP1 = 0; --Boss health +local HP2 = 0; --Boss health + +while (true) do + +--Counters and Lag flag + +--Get lag info +lag = memory.readbyte(0x00D6); +if (lag > 0) then + lag = 1; + lagCounter = lagCounter+1; +end + +--Get screen position +screenpos = memory.readbyte(0x00E8); + +--Get enemy HP values +HP1 = memory.readbyte(0x0113); +HP2 = memory.readbyte(0x0114); + +--Get Day/night timers +ZZZ1 = memory.readbyte(0x06C8); +ZZZ2 = memory.readbyte(0x06CC); +ZZZ3 = memory.readbyte(0x06D0); + +--dispay values +gui.text(191,8,"LagFlag:"); +gui.text(235,8,lag); + +gui.text(191,16,"LagCount:"); +gui.text(235,16,lagCounter); + +gui.text(191,24,"ScrnPos:"); +gui.text(235,24,screenpos); + +gui.text(1,8,"D/N:"..ZZZ1..","..ZZZ2..","..ZZZ3); + +--display enemy HP only if there is something to display TODO: display only the value that is useful +if ( (HP1 > 0 and HP1 < 255) or (HP2 > 0 and HP2 < 255) ) then + gui.text(1,16,"EnemyHPs:"..HP1..","..HP2); +end + + + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/PunchOutChallenge.lua b/branches/fceux-2.2.2/output/luaScripts/PunchOutChallenge.lua new file mode 100644 index 00000000..d978c05a --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/PunchOutChallenge.lua @@ -0,0 +1,334 @@ +--Mike Tyson's Punch Out!! +--Intended to Challenge the PROs! +--adelikat + +local NumStars = 0x0342 +local UntilStar = 0x0347 --Number of punches to land until Mac can get a star +local NumHearts = 0x0321 --Number of hearts, single digit +local NumHearts10 = 0x0322 --Number of hearts, 10's digit +local CurrentRoundA = 0x0006 --Address for which round we are in +local Round = 0 --Stores which round we are on +local OppMove = 0x0090 --What move the opponent is making + +local DizzyFlag = 0x00BA -- If Opponent will be insta-knocked down by any punch +local StarKOFlag = 0x03CB -- If OPponent will be insta-knocked down by a star +local KaiserKOFlag = 0x004B -- Setting this to 0 disables his ability to be stunned, thus you can't KO Star him + +local OppDodgeStar = 0x0348 -- Counter for how many unstunned stars before the opponent starts to dodge + +local OpponentIDA = 0x0031 +local OpponentID = 0 --Stores contents of OpponentIDA + +--Oppenent ID Table +--Round 1, R2, R3 + --36,47,64, 66 Glass Joe 47 = After round 1 Jump back begins + --114,116,118,120=R1 Von Kaiser + --220 Piston Honda I + --225 Don I + --52,62,66 King Hippo + --226,241 Great Tiger + --207 Bald Bull + --23 Piston Honda + --71,87,95 Soda Popinski + --111 Bald Bull II + --19 Don II + --231 Sandman + --105 Super Macho Man + --34 Mike Tyson (Mr. Dream) + + +local AltOppIDAddress = 0x0330 --Alternate flag for determining the opponent +--0 = Kaiser R2, PistonI R1 R2 R3 +--1 = Tiger R1 +--2 = Don I R2, Don I R3 +--3 = Don I R1 +--4 = Tyson R1 +--5 = Glass Joe R3, Von R1, Von R3, Soda R1 +--6 = Piston II R1 +--7 = Bull I R1, BullI R1, Sandman R1, Macho R1 +--9 = Glass R1, Glass R2, KHippo RI & Don II + + + + + + + + + +local OppIDAlt --stores the contents of 0x0330 + +local EHP = 0x0398 -- Enemy HP address +local EHPx= 178 +local EHPy= 14 +local EnemyHP = 0 +local lastEHP = 0 +local EMod = 0 --Amount that the opponents health will be modded by at the end of a frame + +local MHP = 0x0391 -- Mac HP address +local MHPx = 122 +local MHPy = 14 +local MacHP = 0 +local lastMHP = 0 + +local OppKnockedDown = 0x0005 -- Oppoenent is on the canvas flag +local OppDown -- Stores contents of 0x0005 +local OppDx = 130 +local OppDy = 70 +local OppWillGetUpWith = 0x039E -- Health that the oppoenent will get up with +local OppWillGet -- Stores contents of 0x039E + +local OppHitFlag = 0x03E0 +local OppHit +local OppHitTimer = 0 +local OppHitToDisplay = 0 +local OppJustHit = false + +local joy = {} +joy.select = 1 + +OHitValuex = 100 +OHitValuey = 100 + +--***************************************************************************** +function IsOppDown() +--***************************************************************************** + OppDown = memory.readbyte(OppKnockedDown) + if OppDown > 0 then + return true + end + return false +end + +--***************************************************************************** +function OppIsHit() +--***************************************************************************** + OppHit = memory.readbyte(OppHitFlag) + if OppHit > 0 then + return true + end + return false +end + + + +--***************************************************************************** +while true do +--***************************************************************************** + Timer1 = memory.readbyte(0x0302) --Keep track of the clock in the game + Timer2 = memory.readbyte(0x0304) + Timer3 = memory.readbyte(0x0305) + Timer4 = memory.readbyte(0x0306) + Timer5 = memory.readbyte(0x0307) + + EnemyHP = memory.readbyte(EHP) + gui.text(EHPx,EHPy,EnemyHP) + + MacHP = memory.readbyte(MHP) + gui.text(MHPx,MHPy,MacHP) + + OpponentID = memory.readbyte(OpponentIDA) + OppIDAlt = memory.readbyte(AltOppIDAddress) + OppWhichMove = memory.readbyte(OppMove) + + Round = memory.readbyte(CurrentRoundA) + + + + --*************************************** + --Display how much health the opponent will get up with + + if IsOppDown() then + OppWillGet = memory.readbyte(OppWillGetUpWith) + gui.text(OppDx, OppDy, OppWillGet) + gui.text(OppDx+16,OppDy, "Next health") + + --Unfair opponent health boosts! + --This will affect the oppenent both on his knock downs and Mac's :) + if OppWillGet >= 88 then + memory.writebyte(OppWillGetUpWith, 128) + end + if OppWillGet > 64 then + memory.writebyte(OppWillGetUpWith, 96) + end + if OppWillGet > 9 then + memory.writebyte(OppWillGetUpWith, 64) + end + + if OppWillGet and EnemyHP < 64 and EnemyHP > 0 then + memory.writebyte(OppWillGetUpWith, 64) + end + + if OppWillGet and EnemyHP < 9 and EnemyHP > 0 then + memory.writebyte(OppWillGetUpWith, 128) --Now that's just rude. + end + end + --*************************************** + + --*************************************** + --Get the amount Mac damaged the opponent + if OppIsHit() then + OppHitToDisplay = lastEHP - EnemyHP + OppHitTimer = 60 + OppJustHit = true + else OppJustHit = false + end + --*************************************** + + --*************************************** + --Display damage amount + if OppHitTimer > 0 then + gui.text(OHitValuex, OHitValuey, OppHitToDisplay) + end + + if OppHitTimer > 0 then + OppHitTimer = OppHitTimer - 1 + end + --*************************************** + + + --*************************************** + --Force the pressing of select between rounds! + x = memory.readbyte(0x0004) + if x == 1 then + joypad.set(1, joy) + end + --*************************************** + + +---------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- + + --*************************************** + --Glass Joe custom mods + --*************************************** + if OpponentID == 36 or OpponentID == 47 or OpponentID == 64 then + if OppJustHit and OppHitToDisplay < 5 and EnemyHP > 1 then + EMod = EnemyHP + 3 + end + + if OppWhichMove == 25 then + memory.writebyte(OppMove, 1) --Remove his jump back and replace with a regular punch + end + end + + --*************************************** + --Von Kaiser custom mods + --*************************************** + if OppIDAlt == 5 then + gui.text(10,10,"Von Kaiser") + memory.writebyte(KaiserKOFlag, 1) + if Timer1 == 0 and Timer2 == 0 and Round == 1 then + memory.writebyte(OppDodgeStar, 2) + end + end + + --*************************************** + --Piston Honda I custom mods + --*************************************** + if (OppIDAlt == 0 and (Timer3 > 0 or Timer2 > 0 or Timer1 > 0)) then + gui.text(10,10,"Piston Honda I") + if Timer1 == 0 and Timer2 == 0 and Round == 1 then + memory.writebyte(OppDodgeStar, 2) + end + + if OppWhichMove == 25 then + memory.writebyte(OppMove, 1) --Remove his jump back and replace with a regular punch + end + end + + --*************************************** + --Don Flamenco I custom mods + --*************************************** + if OppIDAlt == 3 then + gui.text(10,10,"Don Flamenco I") + if Timer1 == 0 and Timer2 == 0 and Round == 1 then + memory.writebyte(OppDodgeStar, 0) + end + end + + --*************************************** + --King Hippo custom mods + --*************************************** + if OpponentID == 52 then --Round 1 only + if Timer1 == 0 and Timer2 == 0 then + EMod = 128 + end + end + if OpponentID == 52 or OpponentID == 62 or OpponentID == 66 then --All rounds + gui.text(10,10,"King Hippo") + if OppJustHit and OppHitToDisplay < 4 and OppHitToDisplay > 0 and EnemyHP > 1 then + EMod = EnemyHP + 2 + end + end + + + --*************************************** + --Great Tiger custom mods + --*************************************** + if OppIDAlt == 3 then + gui.text(10,10,"Great Tiger") + end + if OpponentID == 230 then --Round 1 Tiger punch only + IsTigerDizzy = memory.readbyte(DizzyFlag) + if IsTigerDizzy > 0 then + memory.writebyte(DizzyFlag, 0) + end + end + + --*************************************** + --Bald Bull I Custom mods + --*************************************** + + --*************************************** + --Piston Honda II Custom mods + --*************************************** + + + --*************************************** + --Soda Popinski Custom mods + --*************************************** + if OpponentID == 71 or OpponentID == 87 or OpponentID == 95 then + gui.text(10,10,"Soda Popinski") + --Nullify the instant star knockdown, and punish mac for trying! + Soda = memory.readbyte(StarKOFlag) --TODO declare a variable instead of using 0x03CB (this is the soda instand knockdown flag) + if Soda > 0 then + + memory.writebyte(0x03CB, 0) --Return it back to 0 + memory.writebyte(NumStars, 0) --Mac loses his stars + memory.writebyte(UntilStar, 12) --Mac won't get a star, and can't get a star in the next 10 punches! + EMod = 128 --Ouch! + end + + end + + --*************************************** + --Bald Bull II Custom mods + --*************************************** + + --*************************************** + --Don Flamenco II Custom mods + --*************************************** + + --*************************************** + --Mr Sandman Custom mods + --*************************************** + + --*************************************** + --Super Macho Man Custom mods + --*************************************** + + --*************************************** + --Mike Tyson + --*************************************** + +---------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- + FCEU.frameadvance() + if EMod > 0 then + memory.writebyte(EHP, EMod) + EMod = 0 + end + lastEHP = EnemyHP + lastMHP = MacHP +end diff --git a/branches/fceux-2.2.2/output/luaScripts/PunchOutStats.lua b/branches/fceux-2.2.2/output/luaScripts/PunchOutStats.lua new file mode 100644 index 00000000..36971bd2 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/PunchOutStats.lua @@ -0,0 +1,91 @@ +--Mike Tyson's Punch Out!! +--Shows Oppoenent & Mac's Health and damage amounts. +--adelikat + + +local EHP = 0x0398 -- Enemy HP address +local EHPx= 178 +local EHPy= 14 +local EnemyHP = 0 +local lastEHP = 0 + +local MHP = 0x0391 -- Mac HP address +local MHPx = 122 +local MHPy = 14 +local MacHP = 0 +local lastMHP = 0 + +local OppKnockedDown = 0x0005 -- Oppoenent is on the canvas flag +local OppDown -- Stores contents of 0x0005 +local OppDx = 130 +local OppDy = 70 +local OppWillGetUpWith = 0x039E -- Health that the oppoenent will get up with +local OppWillGet -- Stores contents of 0x039E + +local OppHitFlag = 0x03E0 +local OppHit +local OppHitTimer = 0 +local OppHitToDisplay = 0 + +OHitValuex = 100 +OHitValuey = 100 + +--***************************************************************************** +function IsOppDown() +--***************************************************************************** + OppDown = memory.readbyte(OppKnockedDown) + if OppDown > 0 then + return true + end + return false +end + +--***************************************************************************** +function OppIsHit() +--***************************************************************************** + OppHit = memory.readbyte(OppHitFlag) + if OppHit > 0 then + return true + end + return false +end + + + +--***************************************************************************** +while true do +--***************************************************************************** + EnemyHP = memory.readbyte(EHP) + gui.text(EHPx,EHPy,EnemyHP) + + MacHP = memory.readbyte(MHP) + gui.text(MHPx,MHPy,MacHP) + + if IsOppDown() then + OppWillGet = memory.readbyte(OppWillGetUpWith) + gui.text(OppDx, OppDy, OppWillGet) + gui.text(OppDx+16,OppDy, "Next health") + end + + if OppIsHit() then + OppHitToDisplay = lastEHP - EnemyHP + OppHitTimer = 60 + + end + + if OppHitTimer > 0 then + gui.text(OHitValuex, OHitValuey, OppHitToDisplay) + end + + + if OppHitTimer > 0 then + OppHitTimer = OppHitTimer - 1 + end + --gui.text(10,180,"Timer: ") + --gui.text(10,200,OppHitTimer) --Debug + + + FCEU.frameadvance() + lastEHP = EnemyHP + lastMHP = MacHP +end diff --git a/branches/fceux-2.2.2/output/luaScripts/PunchOutTraining.lua b/branches/fceux-2.2.2/output/luaScripts/PunchOutTraining.lua new file mode 100644 index 00000000..07e626b0 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/PunchOutTraining.lua @@ -0,0 +1,155 @@ +-- Just something quick for Mike Tyson's Punch Out!! +-- Intended to help time hits in real time. +--FatRatKnight + + +local EHP= 0x0398 -- Enemy HP address +local TMR= 23 -- Frames in advance for your punches. +local BND= -8 -- KEEP NEGATIVE!! Frames after the golden zone. +local threshold= 15-- How many frames before the target timing does it allow? + +local DISPx= 180 +local DISPy= 180 +local DISPx2= DISPx+11 -- Right side of box. Adjust that plus to your need +local DisplayBar= true + +local timer= 0 +local held= 0 +local accuracy= 0 +local earlies= 0 +local lates= 0 + +local perfect= 0 + +local EnemyHP +local lastEHP +local LastHit=-50 +local HitTiming= BND-1 + +--***************************************************************************** +function Is_Hit() +--***************************************************************************** + if lastEHP then + if EnemyHP < lastEHP then + return true + end + end + return false +end + + +local LastButtons= {} +local Buttons= {} +--***************************************************************************** +function IsPress() +--***************************************************************************** + LastButtons["A"]= Buttons["A"] + LastButtons["B"]= Buttons["B"] + LastButtons["select"]= Buttons["select"] + + Buttons= joypad.get(1) + if (Buttons["A"] and not LastButtons["A"]) or (Buttons["B"] and not LastButtons["B"]) then + return true + end + return false +end + + +--***************************************************************************** +while true do +--***************************************************************************** + EnemyHP= memory.readbyte(EHP) + gui.text(144,22,EnemyHP) + + if IsPress() then + if LastHit <= threshold and LastHit >= BND then + HitTiming= LastHit + LastHit= BND-1 + timer= -18 + if HitTiming > 0 then + accuracy= accuracy + HitTiming + earlies= earlies + 1 + elseif HitTiming < 0 then + accuracy= accuracy - HitTiming + lates= lates + 1 + else + perfect= perfect + 1 + end + end + end + + if Buttons["A"] or Buttons["B"] then + held= held + 1 + else + if held == 1 then + timer= 0 + LastHit= HitTiming-1 + end + held= 0 + end + + if Is_Hit() then + LastHit= TMR + end + + + if DisplayBar then + for i= 1, TMR do + local color= "black" + if i == LastHit then + color= "green" + elseif i == HitTiming and timer < 0 then + color= "red" + gui.text(100,80,"early " .. i) + end + gui.drawbox(DISPx, DISPy-3 - 4*i,DISPx2, DISPy-1 - 4*i,color) + end + + if HitTiming == 0 and timer < 0 then + gui.text(128,80,"OK") + gui.drawbox(128,80,144,90,"green") + local color= "white" + if (timer % 3) == 0 then + color= "green" + elseif (timer % 3) == 1 then + color= "blue" + end + gui.drawbox(DISPx , DISPy , DISPx2, DISPy+2, color) + gui.drawbox(DISPx-2, DISPy-2, DISPx2+2, DISPy+4, color) + else + local color= "black" + if i == LastHit then + color= "green" + end + gui.drawbox(DISPx , DISPy ,DISPx2, DISPy+2,color) + gui.drawbox(DISPx-2, DISPy-2,DISPx2+2, DISPy+4,"white") + end + + for i= BND, -1 do + local color= "black" + if i == LastHit then + color= "green" + elseif i == HitTiming and timer < 0 then + color= "red" + gui.text(146,80,"late " .. -i) + end + gui.drawbox(DISPx, DISPy+3 - 4*i,DISPx2, DISPy+5 - 4*i,color) + end + end + + if Buttons["select"] and not LastButtons["select"] then + if DisplayBar then + DisplayBar= false + else + DisplayBar= true + end + end + gui.text(5,120,"Timing error: " .. accuracy) + gui.text(5,140,"Perfect hits: " .. perfect) + gui.text(5,160,"Early: " .. earlies) + gui.text(5,170,"Late: " .. lates) + LastHit= LastHit-1 + FCEU.frameadvance() + lastEHP= EnemyHP + timer= timer+1 +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/RBIBaseball.lua b/branches/fceux-2.2.2/output/luaScripts/RBIBaseball.lua new file mode 100644 index 00000000..799959b6 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/RBIBaseball.lua @@ -0,0 +1,178 @@ +--RBI Baseball script +--Written by adelikat +--Shows stats and information on screen and can even change a batter or pitcher's hand + +local PitchingScreenAddr = 0x001A; +local PitchingScreen; + +local p1PitchHealthAddr = 0x060D; +local p1PitchHealth; + +local p2PitchHealthAddr = 0x061D; +local p2PitchHealth; + +local p1OutsAddr = 0x0665; +local p1Outs; + +local pitchtypeAddr = 0x0112; +local pitchtype; + +local P1currHitterPowerAddr = 0x062B --2 byte +local P1currSpeedAddr = 0x062D +local P1currContactAddr = 0x062A + +local P2currHitterPowerAddr = 0x063B --2 byte +local P2currSpeedAddr = 0x063D +local P2currContactAddr = 0x063A + +local topinningAddr = 0x0115 + +--Extra Ram map notes +--0627 = P1 Batter Lefy or Righty (even or odd) +--0628 = P1 Bat average 150 + this address +--0629 = P1 # of Home Runs +--0638 = P2 Bat average 2 150 + this address +--0639 = P2 # of Home Runs +--0637 = P2 Batter Lefy or Righty (even or odd) + +--060x = P1 pitcher, 061x = P2 pitcher + +--0607 = +--Right digit = P1 Pitcher Lefty or Right (even or odd) +--Left digit = P1 Pitcher drop rating + +--0609 = P1 Sinker ball speed +--060A = P1 Regular ball Speed +--060B = P1 Fastball Speed +--060C = P1 Pitcher Curve rating left digit is curve left, right is curve right + +--0114 = Current Inning +--0115 = 10 if bottom of inning, 0 if on top, controls which player can control the batter + +--0728 & 0279 - In charge of inning music + +--TODO +--A hotkeys for boosting/lowering current pitcher (p1 or 2) health +--fix pitcher L/R switching to not kill the left digit (drop rating) in the process +--Do integer division on curve rating +--Outs display is wrong +--Music on/off toggle + +while true do + +memory.writebyte(0x0726, 0) --Turn of inning music +memory.writebyte(0x0727, 0) +memory.writebyte(0x0728, 0) +memory.writebyte(0x0729, 0) + +inningtb = memory.readbyte(topinningAddr); +i = input.get(); + +--Switch P1 batter hands +if (i.K == true) then + if (inningtb == 0x10) then + memory.writebyte(0x0607, 0) + end + if (inningtb == 0) then + memory.writebyte(0x0627, 0) + end +end + +if (i.L == true) then + if (inningtb == 0x10) then + memory.writebyte(0x0607, 1) + end + if (inningtb == 0) then + memory.writebyte(0x0627, 1) + end +end + +--Switch P2 batter hands +if (i.H == true) then + if (inningtb == 0x0) then + memory.writebyte(0x0617, 0) + end + if (inningtb == 0x10) then + memory.writebyte(0x0637, 0) + end +end + +if (i.J == true) then + if (inningtb == 0x0) then + memory.writebyte(0x0617, 1) + end + if (inningtb == 0x10) then + memory.writebyte(0x0637, 1) + end +end + +PitchingScreen = memory.readbyte(PitchingScreenAddr); + +------------------------------------------------------- +if (PitchingScreen == 0x003E) then +gui.text(186,24, "Toggle Hand\nH/J"); +gui.text(1,24, "Toggle Hand\nK/L"); + +pitchtype = memory.readbyte(pitchtypeAddr); + +--What the pitcher will pitch +if (pitchtype == 0) then + gui.text(100,1,"Sinker!!"); +end +if (pitchtype == 2) then + gui.text(100,1,"Fast Ball") +end +if (pitchtype == 1) then + gui.text(100,1,"Regular Pitch") +end + +--Top of Inning +if (inningtb == 0) then + gui.text(186,1,"Health " .. memory.readbyte(0x061D)) + gui.text(186,128,"Drop " .. memory.readbyte(0x0617) % 16) + gui.text(186,136,"CurveL " .. memory.readbyte(0x061C) / 16) + gui.text(186,144,"CurveR " .. memory.readbyte(0x061C) % 16) + gui.text(186,152,"Fast SP " .. memory.readbyte(0x061B)) + gui.text(186,160,"Reg SP " .. memory.readbyte(0x061A)) + gui.text(186,168,"Sink SP " .. memory.readbyte(0x0619)) + + P1currPower = memory.readbyte(P1currHitterPowerAddr) + (memory.readbyte(P1currHitterPowerAddr+1) * 256); + gui.text(1,176, "Power: " .. P1currPower); + P1currSpeed = memory.readbyte(P1currSpeedAddr); + gui.text(1,168, "Speed: " .. P1currSpeed); + P1currCt = memory.readbyte(P1currContactAddr); + gui.text(1,160, "Contact: " .. P1currCt); +end + +--Bottom of Inning +if (inningtb == 0x10) then + gui.text(1,1,"Health " .. memory.readbyte(0x060D)) + gui.text(1,128,"Drop " .. memory.readbyte(0x0607) % 16) + gui.text(1,136,"CurveL " .. memory.readbyte(0x060C) / 16) + gui.text(1,144,"CurveR " .. memory.readbyte(0x060C) % 16) + gui.text(1,152,"Fast SP " .. memory.readbyte(0x060B)) + gui.text(1,160,"Reg SP " .. memory.readbyte(0x060A)) + gui.text(1,168,"Sink SP " .. memory.readbyte(0x0609)) + + P2currPower = memory.readbyte(P2currHitterPowerAddr) + (memory.readbyte(P2currHitterPowerAddr+1) * 256); + gui.text(188,176, "Power: " .. P2currPower); + P2currSpeed = memory.readbyte(P2currSpeedAddr); + gui.text(188,168, "Speed: " .. P2currSpeed); + P2currCt = memory.readbyte(P2currContactAddr); + gui.text(188,160, "Contact: " .. P2currCt); +end + +end +------------------------------------------------------- + +if (PitchingScreen == 0x0036) then + +p1Outs = memory.readbyte(p1OutsAddr); +gui.text(1,1, "Outs " .. p1Outs); + +end +------------------------------------------------------- + +emu.frameadvance() + +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/Registerfind(CheatSearch).lua b/branches/fceux-2.2.2/output/luaScripts/Registerfind(CheatSearch).lua new file mode 100644 index 00000000..394e40e2 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Registerfind(CheatSearch).lua @@ -0,0 +1,217 @@ +--RegisterFind +--written by QFox +--Weeds out RAM addresses along the lines of Cheat Search and Ram Filter. Has some features not present in either of those 2 hardcoded dialogs. + +-- v0.1a (far from done!) +-- include some iup stuff and take care of cleanup +require 'auxlib'; + +local function toHexStr(n) + return string.format("%X",n); +end; + +local mems; +local memstart = 0; +local memend = 0x200; +local running = false; +local removetop = 0; + +local from = iup.text{value="0x0000"}; +local till = iup.text{value="0x0100"}; +local output = iup.multiline{ expand="YES" }; +local changecheck = iup.toggle{title="Remove changed addresses"}; +local equalcheck = iup.toggle{title="Remove unchanged addresses"}; +local init = iup.button{title="Init"}; +init.action = + function(self) + mems = {}; + memstart = math.min(0xFFFE, math.max(0, tonumber(from.value))); + memend = math.min(0xFFFF, math.max(1, tonumber(till.value))); + for i=(memstart+1),(memend+1) do + mems[i] = memory.readbyte(i-1); + end; + end; +local set = iup.button{title="Set"}; +set.action = + function(self) + if (mems) then + for i=(memstart+1),(memend+1) do + if (mems[i]) then + mems[i] = memory.readbyte(i); + end; + end; + step:action(); + end; + end; +local start = iup.button{title="Run"}; +start.action = + function(self) + if (not mems) then init:action(); end; -- same as pressing the init button + running = true; + end; +local stop = iup.button{title="Stop"}; +stop.action = + function(self) + running = false; + end; +local step = iup.button{title="Step"}; +step.action = + function(self) + if (not mems) then init:action(); end; + local s = ''; + local count = 0; + gui.text(50,50,"change: "..changecheck.value.." equal: "..equalcheck.value); + for i=(memstart+1),(memend+1) do + local nowval = memory.readbyte(i-1); + if ( + mems[i] and -- no memory, no need to print it + ( not running or -- always print (existing) values when the bot is not running + ( + (changecheck.value == "OFF" or mems[i] == nowval) and -- its ok, we're just removing unequal values + (equalcheck.value == "OFF" or mems[i] ~= nowval) -- its ok, we're just removing equal values + ) + ) + ) then + if (removetop > 0) then -- delete this (should be processed even while not running) + mems[i] = false; + removetop = removetop - 1; + else + count = count + 1; + s = s.."0x"..toHexStr(i-1)..": "..toHexStr(nowval).."\n"; + end; + elseif (mems[i] and (removetop > 0 or running)) then -- we're still deleting results + mems[i] = false; + if (removetop > 0) then removetop = removetop - 1; end; + end; + end; + output.value = "Have "..count.." addresses:\n"..s; + end; +local removetext = iup.text{}; +local remove = iup.button{title="del",size="30x"}; +remove.action = + function(self) + removetop = tonumber(removetext.value); + removetext.value = tonumber(removetext.value)..""; + end; +local fewertext = iup.text{}; +local fewer = iup.button{title="del",size="30x"}; +fewer.action = + function(self) + local than = tonumber(fewertext.value); + if (mems and than) then + for i=memstart,memend do + if (mems[i] and mems[i] < than) then + mems[i] = false; + end; + end; + end; + step:action(); + end; +local moretext = iup.text{}; +local more = iup.button{title="del",size="30x"}; +more.action = + function(self) + local than = tonumber(moretext.value); + if (mems and than) then + for i=memstart,memend do + if (mems[i] and mems[i] > than) then + mems[i] = false; + end; + end; + end; + step:action(); + end; +local sametext = iup.text{}; +local same = iup.button{title="del",size="30x"}; +same.action = + function(self) + local than = tonumber(sametext.value); + if (mems and than) then + for i=memstart,memend do + if (mems[i] and mems[i] == than) then + mems[i] = false; + end; + end; + end; + step:action(); + end; + +dialogs = dialogs + 1; +handles[dialogs] = + iup.dialog{ + iup.vbox{ + iup.fill{size="5"}, + iup.hbox{ + iup.label{title="Start offset",size="50x"}, + from + }, + iup.hbox{ + iup.label{title="End offset",size="50x"}, + till + }, + iup.fill{size="5"}, + iup.hbox{ + remove, + iup.fill{size="5"}, + iup.label{title="Remove top",size="50x"}, + iup.fill{size="5"}, + removetext, + iup.fill{size="5"}, + iup.label{title="(next step)"}, + removetop + }, + iup.fill{size="5"}, + iup.hbox{ + fewer, + iup.fill{size="5"}, + iup.label{title="When less than: ",size="70x"}, + fewertext + }, + iup.fill{size="5"}, + iup.hbox{ + more, + iup.fill{size="5"}, + iup.label{title="When more than: ",size="70x"}, + moretext + }, + iup.fill{size="5"}, + iup.hbox{ + same, + iup.fill{size="5"}, + iup.label{title="When equal to: ",size="70x"}, + sametext + }, + iup.fill{size="5"}, + iup.hbox{ + init, + iup.fill{size="5"}, + start, + iup.fill{size="5"}, + stop, + iup.fill{size="5"}, + step, + iup.fill{size="5"}, + set + }, + iup.fill{size="5"}, + iup.label{title="Filters below are automatically applied when you"}, + iup.label{title="press run or press the step button."}, + iup.fill{size="5"}, + changecheck, + equalcheck, + iup.fill{size="5"}, + iup.hbox{ + output + } + }, + title="Lua Register Finder", + size="200x300" + }; +handles[dialogs]:showxy(iup.CENTER, iup.CENTER); + + + +while (true) do + step:action(); -- same as pressing the step button + FCEU.frameadvance(); +end; diff --git a/branches/fceux-2.2.2/output/luaScripts/Rewinder.lua b/branches/fceux-2.2.2/output/luaScripts/Rewinder.lua new file mode 100644 index 00000000..c9257f20 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Rewinder.lua @@ -0,0 +1,71 @@ +-- NES Braidulator VERSION 1 +--(C) Antony Lavelle 2009 got_wot@hotmail.com http://www.the-exp.net +-- A Lua script that allows 'Braid' style time reversal for Nes games being run in FCEUX +--'Braid' is copyright Jonathan Blow, who is not affiliated with this script, but you should all buy his game because it's ace. +--This is my first ever time scripting in Lua, so if you can improve on this idea/code please by all means do and redistribute it, just please be nice and include original credits along with your own :) + + + +--Change these settings to adjust options + + +--Which key you would like to function as the "rewind key" + +local rewindKey = 'select' + + +--How much rewind power would you like? (The higher the number the further back in time you can go, but more computer memory is used up) +--Do not set to 0! + +local saveMax = 1000; + + + + +--The stuff below is for more advanced users, enter at your own peril! + + + +local saveArray = {};--the Array in which the save states are stored +local saveCount = 1;--used for finding which array position to cycle through +local save; -- the variable used for storing the save state +local rewindCount = 0;--this stops you looping back around the array if theres nothing at the end +local savePreventBuffer = 1;--Used for more control over when save states will be saved, not really used in this version much. +while (true) do + savePreventBuffer = savePreventBuffer-1; + if savePreventBuffer==0 then + savePreventBuffer = 1; + end; + joyput = joypad.read(1); + if joyput[rewindKey] then + savePreventBuffer = 5; + if rewindCount==0 then + --makes sure you can't go back too far could also include other things in here, left empty for now. + else + savestate.load(saveArray[saveCount]); + saveCount = saveCount-1; + rewindCount = rewindCount-1; + if saveCount==0 then + saveCount = saveMax-1; + end; + end; + end; + if savePreventBuffer==1 then + gui.text(80,15,""); + saveCount=saveCount+1; + if saveCount==saveMax then + saveCount = 1; + end + rewindCount = rewindCount+1; + if rewindCount==saveMax-1 then + rewindCount = saveMax-2; + end; + save = savestate.create(); + savestate.save(save); + saveArray[saveCount] = save; + end; + local HUDMATH = (math.ceil((100/saveMax)*rewindCount));--Making the rewind time a percentage. + local HUDTEXT = "REWIND POWER: ".. HUDMATH .."%"; + gui.text(80,5,HUDTEXT);--Displaying the time onscreen. + FCEU.frameadvance(); +end; diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB-AreaScrambler.lua b/branches/fceux-2.2.2/output/luaScripts/SMB-AreaScrambler.lua new file mode 100644 index 00000000..aaf82875 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB-AreaScrambler.lua @@ -0,0 +1,97 @@ +--SMB area scrambler +--Randomly changes the level contents. Doesn't garuantee a winnable level (nor does it guarantee it won't crash the game) +--Written by XKeeper + +require("x_functions"); + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(4); +end; + + + + + +function areascrambler() +end; + + +function gameloop() + + joyin = joypad.read(1); + if joyin['select'] then + memory.writebyte(0x00e7, math.random(0, 0xFF)); + memory.writebyte(0x00e8, math.random(0, 0xFF)); + memory.writebyte(0x00e9, math.random(0, 0xFF)); + memory.writebyte(0x00ea, math.random(0, 0xFF)); + memory.writebyte(0x0750, math.random(0, 0xFF)); + end; + + if joyin['up'] then + memory.writebyte(0x009F, -5); + memory.writebyte(0x07F8, 3); + memory.writebyte(0x0722, 0xFF) + end; + + screenpage = memory.readbyte(0x071a); + screenxpos = memory.readbyte(0x071c); + + arealow = memory.readbyte(0x00e7); + areahigh = memory.readbyte(0x00e8); + + enemylow = memory.readbyte(0x00e9); + enemyhigh = memory.readbyte(0x00ea); + + unknown = memory.readbyte(0x0750); + + + text( 6, 30, string.format("Position: %02X %02X", screenpage, screenxpos)); + text( 19, 38, string.format("Area: %02X %02X", areahigh, arealow)); + text( 13, 46, string.format("Enemy: %02X %02X", enemyhigh, enemylow)); + text( 13, 54, string.format("?: %02X", unknown)); +end; + + +function areascramble() + memory.writebyte(0x00e7, math.random(0, 0xFF)); + memory.writebyte(0x00e8, math.random(0, 0xFF)); +end; + +function enemyscramble() + memory.writebyte(0x00e9, math.random(0, 0xFF)); + memory.writebyte(0x00ea, math.random(0, 0xFF)); +end; + + +gui.register(gameloop); +memory.register(0x00e8, areascramble); +memory.register(0x00ea, enemyscramble); + + + +while (true) do + + memory.writebyte(0x079F, 2); + FCEU.frameadvance(); +end; + diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB-CompetitionRecorder.lua b/branches/fceux-2.2.2/output/luaScripts/SMB-CompetitionRecorder.lua new file mode 100644 index 00000000..bf70f19f --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB-CompetitionRecorder.lua @@ -0,0 +1,121 @@ +-- Super Mario Bros. script by ugetab. +-- 2010, April 20th. +-- Competition Recorder: +-- Start the script, then make a recording from Start. +-- Play until you get a score you'd like to keep, then end the movie. +-- A record of your best scores, and the filename you got it in, will be saved. +-- You can easily find your best score, because it will be sorted highest to lowest. +-- The last entry is always erased, but is also always the lowest score. + +-- The best score for your current movie file will be displayed above the coin counter. + +-- The reason this is good for competition is that you can't get away with cheating, +-- unless the game allows it. A movie file is a collection of button presses which +-- can be played back. If it doesn't play back the same for someone else, then there's +-- probably a problem with the game file, or with what the person recording did. + +function text(x,y,str) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.text(x,y,str); + end; +end; + +function bubbleSort(table) +--http://www.dreamincode.net/code/snippet3406.htm +--check to make sure the table has some items in it + if #table < 2 then + --print("Table does not have enough data in it") + return; + end; + + for i = 0, (#table / 2) -1 do --> array start to end. Arrays start at 1, not 0. + for j = 1, (#table / 2) -1 do + if tonumber(table[(j*2)+1]) > tonumber(table[(j*2)-1]) then -->switch + temp1 = table[(j*2) - 1]; + temp2 = table[(j*2)]; + table[(j*2) - 1] = table[(j*2) + 1]; + table[(j*2)] = table[(j*2) + 2]; + table[(j*2) + 1] = temp1; + table[(j*2) + 2] = temp2; + end; + end; + end; + return; +end; + +filesizefile = io.open("MaxScore_LUA.txt","r"); + +if filesizefile == nil then + filewritefile = io.open("MaxScore_LUA.txt","w"); + filewritefile:close(); + filesizefile = io.open("MaxScore_LUA.txt","r"); +end; + +filesize = filesizefile:seek("end"); +filesizefile:close(); +scores = {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"}; + +if filesize == nil then + filesize = 0; +end; + +if filesize < 20 then + fileinit = io.open("MaxScore_LUA.txt","w+") + for i = 1, #scores do + fileinit:write(scores[i]..'\n'); + end; + fileinit:close(); +end; + +activescoring = false; +moviename = ""; + +maxscoresave = -9999999; + +text(83,8,"-Inactive-"); + +while (true) do + if (movie.mode() == "record") then + if movie.ispoweron() then + maxscoretest = memory.readbyte(0x07d7)..memory.readbyte(0x07d8)..memory.readbyte(0x07d9)..memory.readbyte(0x07da)..memory.readbyte(0x07db)..memory.readbyte(0x07dc).."0"; + activescoring = true; + + --if (tonumber(maxscoretest) >= tonumber(maxscoresave)) then + if (tonumber(maxscoretest) <= 9999990) then + maxscoresave = maxscoretest; + moviename = movie.getname(); + end; + --end; + + text(83,8,maxscoresave); + end; + end; + if (movie.mode() == nil) then + if (activescoring == true) then + activescoring = false; + text(83,8,"-Inactive-"); + readfile = io.open("MaxScore_LUA.txt","r"); + linecount = 1 + for line in readfile:lines() do + if linecount <= 20 then + scores[linecount] = line; + end; + linecount = linecount + 1; + end; + readfile:close (); + + --if tonumber(maxscoresave) > tonumber(scores[19]) then + scores[19] = maxscoresave; + scores[20] = moviename; + bubbleSort(scores); + savefile = io.open("MaxScore_LUA.txt","w+") + for i = 1, #scores do + savefile:write(tostring(scores[i])); + savefile:write('\n'); + end; + savefile:close(); + --end; + end; + end; + FCEU.frameadvance(); +end; diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB-HitBoxes.lua b/branches/fceux-2.2.2/output/luaScripts/SMB-HitBoxes.lua new file mode 100644 index 00000000..1a973e16 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB-HitBoxes.lua @@ -0,0 +1,165 @@ +-- Super Mario Bros. hitbox script +-- Super Mario Bros (JU) (PRG0) [!].nes +-- Written by qFox +-- 28 july 2008 + +-- This script shows hitboxes of anything that has them +-- It also displays the found hitboxes in a output window with iup +-- Includes a toggle to automatically kill all enemies within 50px range of mario :p + +-- Include our help script to load iup and take care of exit +require("auxlib"); + +local running = true; +local restrainingorder = false; +local myoutput; +function createGUI(n) + local mybutton = iup.button{title="Close (exits the main loop)"}; + mybutton.action = function(self, x) + running = false; + --handles[n]:destroy(); + --handles[n] = false; + end; + myoutput = iup.multiline{size="200x200",expand="YES",value="Debug crap should be here"} + nottooclose = iup.toggle{title="Kill enemies that come too close", value="OFF"}; + nottooclose.action = function(self, v) restrainingorder = (v == 1); end; -- v is 0 or 1 + handles[n] = + iup.dialog{ + iup.frame + { + iup.vbox + { + mybutton, + nottooclose, + myoutput, + title="Lua tools are izi!" + } + } + }; + handles[n]:showxy(iup.CENTER, iup.CENTER) +end + +dialogs = dialogs + 1; +createGUI(dialogs); + +local outstr; +local function knifeEnemyIfTooClose(enemynumber) -- enemynumber starts at 1 + -- we add the suffix for x coords because the screen is 255 positions wide but smb has two pages + -- loaded at any given time. some enemy can be in page 2 while you are on page one. since a byte + -- can only hold 255 values, this would wrap around and make it seem like the enemy is on the same + -- page. hence we add the number of pages they are one, if they are equal, it all works out :) + local mx = memory.readbyte(0x0086)+(255*memory.readbyte(0x006D)); + local my = memory.readbyte(0x00CE); + local ex = memory.readbyte(0x0086+enemynumber)+(255*memory.readbyte(0x006D+enemynumber)); + local ey = memory.readbyte(0x00CE+enemynumber); + local d = math.sqrt(((mx-ex)^2)+((my-ey)^2)); -- pythagoras ;) + outstr = outstr .. d.." < 30.0 ?\n"; + if (d < 50.0 and restrainingorder and memory.readbyte(0x0015+enemynumber) ~= 40) then -- dont kill of horizontal moving platforms. we kinda need them. + -- KNIFE! + outstr = outstr .. "Knifing next enemy!\n"; + memory.writebyte(0x001D+enemynumber, 0xFF); -- this address denotes an enemy state. writing FF to it kills them as if hit by a star (so not flatten). + end; + return d; +end; + +-- draw a box and take care of coordinate checking +local function box(x1,y1,x2,y2,color) + -- gui.text(50,50,x1..","..y1.." "..x2..","..y2); + if (x1 > 0 and x1 < 255 and x2 > 0 and x2 < 255 and y1 > 0 and y1 < 224 and y2 > 0 and y2 < 224) then + gui.drawbox(x1,y1,x2,y2,color); + end; +end; + +-- hitbox coordinate offsets (x1,y1,x2,y2) +local mario_hb = 0x04AC; -- 1x4 +local enemy_hb = 0x04B0; -- 5x4 +local coin_hb = 0x04E0; -- 3x4 +local fiery_hb = 0x04C8; -- 2x4 +local hammer_hb= 0x04D0; -- 9x4 +local power_hb = 0x04C4; -- 1x4 + +-- addresses to check, to see whether the hitboxes should be drawn at all +local mario_ch = 0x000E; +local enemy_ch = 0x000F; +local coin_ch = 0x0030; +local fiery_ch = 0x0024; +local hammer_ch= 0x002A; +local power_ch = 0x0014; + +local a,b,c,d; +while (running) do + outstr = ''; + -- from 0x04AC are about 0x48 addresse that indicate a hitbox + -- different items use different addresses, some share + -- there can for instance only be one powerup on screen at any time (the star in 1.1 gets replaced by the flower, if you get it) + -- we cycle through the animation addresses for each type of hitbox, draw the corresponding hitbox if they are drawn + -- we draw: mario (1), enemies (5), coins (3), hammers (9), powerups (1). (bowser and (his) fireball are considered enemies) + + -- mario + if (memory.readbyte(mario_hb) > 0) then + a,b,c,d = memory.readbyte(mario_hb),memory.readbyte(mario_hb+1),memory.readbyte(mario_hb+2),memory.readbyte(mario_hb+3); + box(a,b,c,d, "green"); + outstr = outstr .. "Mario: <"..a..","..b..","..c..","..d..">\n"; + end; + + -- enemies + if (memory.readbyte(enemy_ch ) > 0) then + a,b,c,d = memory.readbyte(enemy_hb), memory.readbyte(enemy_hb+1), memory.readbyte(enemy_hb+2), memory.readbyte(enemy_hb+3); + box(a,b,c,d, "green"); + outstr = outstr .. "Enemy 1: <"..memory.readbyte(0x0016).."> <"..a..","..b..","..c..","..d.."> "..knifeEnemyIfTooClose(1).."\n"; + end; + if (memory.readbyte(enemy_ch+1) > 0) then + a,b,c,d = memory.readbyte(enemy_hb+4), memory.readbyte(enemy_hb+5), memory.readbyte(enemy_hb+6), memory.readbyte(enemy_hb+7); + box(a,b,c,d, "green"); + outstr = outstr .. "Enemy 2: <"..memory.readbyte(0x0017).."> <"..a..","..b..","..c..","..d.."> "..knifeEnemyIfTooClose(2).."\n"; + end; + if (memory.readbyte(enemy_ch+2) > 0) then + a,b,c,d = memory.readbyte(enemy_hb+8), memory.readbyte(enemy_hb+9), memory.readbyte(enemy_hb+10),memory.readbyte(enemy_hb+11); + box(a,b,c,d, "green"); + outstr = outstr .. "Enemy 3: <"..memory.readbyte(0x0018).."> <"..a..","..b..","..c..","..d.."> "..knifeEnemyIfTooClose(3).."\n"; + end; + if (memory.readbyte(enemy_ch+3) > 0) then + a,b,c,d = memory.readbyte(enemy_hb+12),memory.readbyte(enemy_hb+13),memory.readbyte(enemy_hb+14),memory.readbyte(enemy_hb+15); + box(a,b,c,d, "green"); + outstr = outstr .. "Enemy 4: <"..memory.readbyte(0x0019).."> <"..a..","..b..","..c..","..d.."> "..knifeEnemyIfTooClose(4).."\n"; + end; + if (memory.readbyte(enemy_ch+4) > 0) then + a,b,c,d = memory.readbyte(enemy_hb+16),memory.readbyte(enemy_hb+17),memory.readbyte(enemy_hb+18),memory.readbyte(enemy_hb+19) + box(a,b,c,d, "green"); + outstr = outstr .. "Enemy 5: <"..memory.readbyte(0x001A).."> <"..a..","..b..","..c..","..d.."> "..knifeEnemyIfTooClose(5).."\n"; + end; + + -- coins + if (memory.readbyte(coin_ch ) > 0) then box(memory.readbyte(coin_hb), memory.readbyte(coin_hb+1), memory.readbyte(coin_hb+2), memory.readbyte(coin_hb+3), "green"); end; + if (memory.readbyte(coin_ch+1) > 0) then box(memory.readbyte(coin_hb+4), memory.readbyte(coin_hb+5), memory.readbyte(coin_hb+6), memory.readbyte(coin_hb+7), "green"); end; + if (memory.readbyte(coin_ch+2) > 0) then box(memory.readbyte(coin_hb+8), memory.readbyte(coin_hb+9), memory.readbyte(coin_hb+10), memory.readbyte(coin_hb+11), "green"); end; + + -- (mario's) fireballs + if (memory.readbyte(fiery_ch ) > 0) then box(memory.readbyte(fiery_hb), memory.readbyte(fiery_hb+1), memory.readbyte(fiery_hb+2), memory.readbyte(fiery_hb+3), "green"); end; + if (memory.readbyte(fiery_ch+1) > 0) then box(memory.readbyte(fiery_hb+4), memory.readbyte(fiery_hb+5), memory.readbyte(fiery_hb+6),memory.readbyte(fiery_hb+7), "green"); end; + + -- hammers + if (memory.readbyte(hammer_ch ) > 0) then box(memory.readbyte(hammer_hb), memory.readbyte(hammer_hb+1), memory.readbyte(hammer_hb+2), memory.readbyte(hammer_hb+3), "green"); end; + if (memory.readbyte(hammer_ch+1) > 0) then box(memory.readbyte(hammer_hb+4), memory.readbyte(hammer_hb+5), memory.readbyte(hammer_hb+6), memory.readbyte(hammer_hb+7), "green"); end; + if (memory.readbyte(hammer_ch+2) > 0) then box(memory.readbyte(hammer_hb+8), memory.readbyte(hammer_hb+9), memory.readbyte(hammer_hb+10),memory.readbyte(hammer_hb+11), "green"); end; + if (memory.readbyte(hammer_ch+3) > 0) then box(memory.readbyte(hammer_hb+12),memory.readbyte(hammer_hb+13),memory.readbyte(hammer_hb+14),memory.readbyte(hammer_hb+15), "green"); end; + if (memory.readbyte(hammer_ch+4) > 0) then box(memory.readbyte(hammer_hb+16),memory.readbyte(hammer_hb+17),memory.readbyte(hammer_hb+18),memory.readbyte(hammer_hb+19), "green"); end; + if (memory.readbyte(hammer_ch+5) > 0) then box(memory.readbyte(hammer_hb+20),memory.readbyte(hammer_hb+21),memory.readbyte(hammer_hb+22),memory.readbyte(hammer_hb+23), "green"); end; + if (memory.readbyte(hammer_ch+6) > 0) then box(memory.readbyte(hammer_hb+24),memory.readbyte(hammer_hb+25),memory.readbyte(hammer_hb+26),memory.readbyte(hammer_hb+27), "green"); end; + if (memory.readbyte(hammer_ch+7) > 0) then box(memory.readbyte(hammer_hb+28),memory.readbyte(hammer_hb+29),memory.readbyte(hammer_hb+30),memory.readbyte(hammer_hb+31), "green"); end; + if (memory.readbyte(hammer_ch+8) > 0) then box(memory.readbyte(hammer_hb+32),memory.readbyte(hammer_hb+33),memory.readbyte(hammer_hb+34),memory.readbyte(hammer_hb+35), "green"); end; + + -- powerup + if (memory.readbyte(power_ch) > 0) then box(memory.readbyte(power_hb),memory.readbyte(power_hb+1),memory.readbyte(power_hb+2),memory.readbyte(power_hb+3), "green"); end; + + gui.text(5,32,"Green rectangles are hitboxes!"); + + if (myoutput) then + myoutput.value = outstr; + end; + + FCEU.frameadvance() +end + +gui.popup("script exited main loop"); + diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB-Jetpack.lua b/branches/fceux-2.2.2/output/luaScripts/SMB-Jetpack.lua new file mode 100644 index 00000000..b29c54f0 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB-Jetpack.lua @@ -0,0 +1,353 @@ +--Super Mario Bros. - Jetpack +--Written by XKeeper +--A fun script that gives mario a "Jetback" + +require("x_functions"); + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(4); +end; + + + +function doballs() + + count = 0; + for k, v in pairs(balls) do + + v['x'] = v['x'] + v['xs']; + v['y'] = v['y'] + v['ys']; + v['ys'] = v['ys'] - 0.1; + v['life'] = v['life'] - 1; + + if v['x'] < 0 or v['x'] > 254 or v['y'] < 0 or v['y'] > 243 or v['life'] < 0 then + balls[k] = nil; + else + balls[k] = v; +-- pixel(v['x'], v['y'], "#FFFFFF"); + colkey = math.ceil(255 * (5 - math.max(math.min(5, (v['life'] / 15)), 0)) / 5); + + if v['c'] >= 0 then + color = string.format("#%02X%02X%02X", v['c'], v['c'], v['c']); +-- color = string.format("#%02X%02X%02X", v['c'] * .8, v['c'] * .5, v['c'] * 0); + else + color = string.format("#%02X0000", v['c'] * -1 , 0, 0); + end; + + if v['life'] > 45 then + box(v['x'], v['y'], v['x'] + 1, v['y'] + 1, color); + else + pixel(v['x'], v['y'], color); + end; + count = count + 1; + end; + end; + +-- lifebar( 2, 140, 249, 10, spower, 400, "#ffffff", "#000044", "#bbbbff"); + return count; + +end; + + + +function nojumping() + memory.writebyte(0x000a, AND(memory.readbyte(0x000a), 0x7F)); + + return true; +end; + +function nomoving() + joyput = joypad.read(1); + if (joyput['left'] or joyput['right']) then + memory.writebyte(0x000c, 0); + end; + + return true; +end; + + +function areascrambler() + memory.writebyte(0x00e7, math.random(0, 0xFF)); + memory.writebyte(0x00e8, math.random(0, 0xFF)); +end; + +function enemyscrambler() + memory.writebyte(0x00e9, math.random(0, 0xFF)); + memory.writebyte(0x00ea, math.random(0, 0xFF)); +end; + + +--[[ +memory.register(0x00e8, areascrambler); +memory.register(0x00ea, enemyscrambler); +--]] + +-- gui.register(gameloop); +memory.register(0x000a, nojumping); +memory.register(0x000c, nomoving); + +testcount = 0; +balls = {}; +z = 0; +timer = 0; +jmax = 500; +jlife = 500; -- jmax; +refillrate = 0.020; +msgdisp = 300; +rechargerate = 0; +while (true) do + timer = timer + 1; + + + if timer < msgdisp then + yo = (((math.max(0, (timer + 60) - msgdisp))) ^ 2) / 50; + text(20, 50 - yo, "2009 Xkeeper - http://jul.rustedlogic.net/"); + text(49, 64 - yo, "A: Jetpack Left/Right: Move"); + text(53, 72 - yo, " B button: Turbo boost! "); + end; + + invincible = false; + if memory.readbyte(0x079F) >= 1 then + cyclepos = math.abs(15 - math.fmod(timer, 30)) / 15; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0xFF)); + barcolor = "#" .. warningboxcolor .. warningboxcolor .."ff"; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0x80) + 0x7F); + barcolor2 = "#0000" .. warningboxcolor; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0x40)); + barcolor3 = "#0000" .. warningboxcolor; +-- barcolor3 = "#000000"; + + jlife = math.min(jmax, jlife + (jmax - jlife) / 25 + 0.25); + rechargerate = -0.025; + invincible = true; + elseif jlife <= jmax * 0.25 then + cyclepos = math.abs(15 - math.fmod(timer, 30)) / 15; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0xFF)); + barcolor = "#ff" .. warningboxcolor .. warningboxcolor; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0x80) + 0x7F); + barcolor2 = "#" .. warningboxcolor .. "0000"; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0x40)); + barcolor3 = "#" .. warningboxcolor .. "0000"; +-- barcolor3 = "#000000"; + else + barcolor = "#ffffff"; + barcolor2 = "#ff4444"; + barcolor3 = "#000000"; + end; + lifebar(5, 8, 240, 2, jlife, jmax, barcolor, barcolor3, "#000000", barcolor2); + textx = math.max(4, math.min(math.floor(jlife/ jmax * 240) - 4, 229)); + if jlife == jmax then + textx = 223; + end; + text(textx, 13, string.format("%2.1d%%", math.min(jlife/ jmax * 100))); + +--[[ + bxp = math.sin(timer / 120) * 64 + 127; + byp = math.cos(timer / 120) * 64 + 127; + for i = 0, 0 do + balls[z] = {x = bxp + math.random(-100, 200) / 100, y = byp + math.random(-4, 4), xs = math.random(-100, 100) / 50, ys = math.random(-100, 100) / 100, life = math.random(60, 120), c = math.random(128, 255)}; + z = z + 1; + end; +]] + + + doballs(); + + + marioxspeed = memory.readbytesigned(0x0057); + marioyspeed = memory.readbytesigned(0x009F); + marioxpos = memory.readbyte(0x4AC); + marioypos = memory.readbyte(0x4AD); + +-- lifebar(5, 2, 240, 2, marioxspeed + 0x40, 0x80, "#8888ff", "#000000"); + + joyput = joypad.read(1); + if joyput['up'] then + memory.writebyte(0x07F8, 3); + end; + if joyput['A'] and jlife >= 3 then + + rechargerate = 0; + memory.writebyte(0x009F, math.max(-3, marioyspeed - 1)); +-- memory.writebyte(0x009F, -3); + if not invincible then jlife = math.max(0, jlife - 3); end; + for i = 0, 10 do + balls[z] = {x = marioxpos + 5, y = marioypos + 7, xs = math.random(-70, 70) / 100, ys = math.random(100, 300) / 100, life = math.random(30, 60), c = math.random(128, 255)}; + z = z + 1; + end; + end; + if (joyput['left'] or joyput['right']) then + + speedchange = 1; + speedmax = 0x28; + if joyput['B'] and jlife > 0 then + rechargerate = 0; + if not invincible then jlife = math.max(0, jlife - 1); end; + speedchange = 5; + speedmax = 0x40; + end; + + if joyput['left'] then + memory.writebyte(0x0033, 2); + memory.writebyte(0x0045, 2); + if marioxspeed > (speedmax * -1) then + memory.writebyte(0x0057, math.max(-0x40, marioxspeed - speedchange)); + end; + for i = 0, 10 do + balls[z] = {x = marioxpos + 7, y = marioypos + 7, xs = math.random(300, 400) / 100, ys = math.random(-10, 20) / 100, life = math.random(5, 5 + speedchange * 10), c = math.random(128, 255)}; + z = z + 1; + end; + else + + memory.writebyte(0x0033, 1); + memory.writebyte(0x0045, 1); + if marioxspeed < speedmax then + memory.writebyte(0x0057, math.min(0x40, marioxspeed + speedchange)); + end; + for i = 0, 10 do + balls[z] = {x = marioxpos + 7, y = marioypos + 7, xs = math.random(-400, -300) / 100, ys = math.random(-10, 20) / 100, life = math.random(5, 5 + speedchange * 10), c = math.random(128, 255)}; + z = z + 1; + end; + end; + end; + if not ((joyput['B'] and (joyput['left'] or joyput['right'])) or joyput['A']) then + + rechargerate = rechargerate + refillrate; + jlife = math.min(jmax, jlife + rechargerate); + + end; + + + + + + screenpage = memory.readbyte(0x071a); + screenxpos = memory.readbyte(0x071c); + + arealow = memory.readbyte(0x00e7); + areahigh = memory.readbyte(0x00e8); + + enemylow = memory.readbyte(0x00e9); + enemyhigh = memory.readbyte(0x00ea); + + +-- text( 10, 24, string.format("Screen position: %02X.%02X", screenpage, screenxpos)); +-- text(169, 24, string.format("Area: %02X %02X", areahigh, arealow)); +-- text(163, 32, string.format("Enemy: %02X %02X", enemyhigh, enemylow)); + + +--[[ + text( 4, 217, string.format("Memory writes: %04d", testcount)); + if testcount > 1500 or testcount < 200 then + cyclepos = math.abs(15 - math.fmod(timer, 30)) / 15; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0xFF)); + barcolor = "#ff" .. warningboxcolor .. warningboxcolor; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0x80) + 0x7F); + barcolor2 = "#" .. warningboxcolor .. "0000"; + warningboxcolor = string.format("%02X", math.floor(cyclepos * 0x40)); + barcolor3 = "#" .. warningboxcolor .. "0000"; +-- barcolor3 = "#000000"; + else + barcolor = "#ffffff"; + barcolor2 = "#ff4444"; + barcolor3 = "#000000"; + end; + lifebar(5, 226, 240, 2, testcount, 2500, barcolor, barcolor3, "#000000", barcolor2); + +--]] + +-- memory.writebyte(0x00e7, math.random(0, 0xFF)); +-- memory.writebyte(0x00e8, math.random(0, 0xFF)); +-- memory.writebyte(0x00e9, math.random(0, 0xFF)); +-- memory.writebyte(0x00ea, math.random(0, 0xFF)); + + testcount = 0; + +--[[ + marioxspeed2 = math.abs(marioxspeed); + + box(2, 217, 0x40 * 3 + 5, 226, "#000000"); + box(2, 218, 0x40 * 3 + 5, 225, "#000000"); + box(2, 219, 0x40 * 3 + 5, 224, "#000000"); + box(2, 220, 0x40 * 3 + 5, 223, "#000000"); + box(2, 221, 0x40 * 3 + 5, 222, "#000000"); + + if marioxspeed2 > 0 then + for bl = 0, marioxspeed2 do + + if bl < 0x20 then + segcolor = string.format("#%02XFF00", math.floor(bl / 0x20 * 0xFF)); + else + segcolor = string.format("#FF%02X00", math.max(0, math.floor((0x40 - bl) / 0x20 * 0xFF))); + end; + + box(bl * 3 + 3, 218, bl * 3 + 4, 225, segcolor); +-- line(bl * 3 + 4, 218, bl * 3 + 4, 225, segcolor); + end; + end; + + --]] + + maxspeed = 0x40; + marioxspeed = memory.readbytesigned(0x0057); + marioxspeed2 = math.abs(marioxspeed); + + + text(maxspeed * 3 + 2, 221, string.format(" %2d", marioxspeed2)); + + box(5, 221, maxspeed * 3 + 5, 230, "#000000"); + box(5, 222, maxspeed * 3 + 5, 229, "#000000"); + box(5, 223, maxspeed * 3 + 5, 228, "#000000"); + box(5, 224, maxspeed * 3 + 5, 227, "#000000"); + box(5, 225, maxspeed * 3 + 5, 226, "#000000"); + + if marioxspeed2 > 0 then + for bl = 1, marioxspeed2 do + + pct = bl / maxspeed; + if pct < 0.50 then + val = math.floor(pct * 2 * 0xFF); + segcolor = string.format("#%02XFF00", val); + + elseif pct < 0.90 then + val = math.floor(0xFF - (pct - 0.5) * 100/40 * 0xFF); + segcolor = string.format("#FF%02X00", val); + + elseif bl < maxspeed then + val = math.floor((pct - 0.90) * 10 * 0xFF); + segcolor = string.format("#FF%02X%02X", val, val); + + else + segcolor = "#ffffff"; + end; + + yb = math.max(math.min(3, (bl - 0x28)), 0); + box(bl * 3 + 3, 225 - yb, bl * 3 + 4, 229, segcolor); +-- box(bl * 3 + 3, 218, bl * 3 + 4, 225, segcolor); +-- line(bl * 3 + 4, 218, bl * 3 + 4, 225, segcolor); + end; + end; + + FCEU.frameadvance(); +end; + diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB-Lives&HPDisplay.lua b/branches/fceux-2.2.2/output/luaScripts/SMB-Lives&HPDisplay.lua new file mode 100644 index 00000000..4c99f77c --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB-Lives&HPDisplay.lua @@ -0,0 +1,60 @@ +-- Super Mario Bros. script by 4matsy. +-- 2008, September 11th. +--Displays the # of lives for Mario and a HP meter for Bowswer + +require("shapedefs"); + +function box(x1,y1,x2,y2,color) + if (x1 > 0 and x1 < 255 and x2 > 0 and x2 < 255 and y1 > 0 and y1 < 241 and y2 > 0 and y2 < 241) then + gui.drawbox(x1,y1,x2,y2,color); + end; +end; + +function line(x1,y1,x2,y2,color) + if (x1 > 0 and x1 < 255 and x2 > 0 and x2 < 255 and y1 > 0 and y1 < 241 and y2 > 0 and y2 < 241) then + gui.drawline(x1,y1,x2,y2,color); + end; +end; + +function text(x,y,str) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.text(x,y,str); + end; +end; + +function pixel(x,y,color) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.drawpixel(x,y,color); + end; +end; + + + +while (true) do + + -- print player's lives...I always thought this was a major omission of the status bar :p + text(63,13,"x"..memory.readbyte(0x075a)+1); + + -- check the enemy identifier buffer for presence of t3h b0ws3r (id #2d). if found, show his hp. + for i=0,5 do + if memory.readbyte((0x0016)+i) == 0x2d then -- aha, found you. YOU CANNOT HIDE FROM MY MAD SCRIPTZ0RING SKILLZ BWAHAHA + local bowsermaxhp = memory.readbyte(0xc56c); -- bowser's starting hp + local bowsercurhp = memory.readbyte(0x0483); -- bowser's current hp + local meterx = 104; -- x-origin of the meter + local metery = 228; -- y-origin of the meter + local spacingx = 8; -- how much x-space between each shape? + local spacingy = 0; -- how much y-space between each shape? + text((meterx-2),(metery-11),"Bowser:"); + for a=0,bowsermaxhp-1 do + drawshape((meterx+(spacingx*a)+0),(metery+(spacingy*a)+1),"heart_7x7","#000000"); + drawshape((meterx+(spacingx*a)+1),(metery+(spacingy*a)+0),"heart_7x7","#000000"); + drawshape((meterx+(spacingx*a)+1),(metery+(spacingy*a)+1),"heart_7x7","#000000"); + drawshape((meterx+(spacingx*a)+0),(metery+(spacingy*a)+0),"heart_7x7","#ffffff"); + if a < bowsercurhp then + drawshape((meterx+(spacingx*a)+1),(metery+(spacingy*a)+1),"heart_5x5","#ff0000"); + end; + end; + end; + end; + FCEU.frameadvance(); +end; diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB-Mouse.lua b/branches/fceux-2.2.2/output/luaScripts/SMB-Mouse.lua new file mode 100644 index 00000000..8cc31403 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB-Mouse.lua @@ -0,0 +1,573 @@ +--Super Mario Bros. - Drag and Drop +--Written by XKeeper +--Allows you to use the mouse to pick up enemies and movie them around! + +debugmodes = { + enabled = false; -- CHANGE THIS AT YOUR PERIL + showenemydata = false; + drawmouse = false; + locktimer = false; + invincible = false; + ver = "03/29 15:00:00"; + }; + +control = {}; -- must come first. + -- basically, will contain all the "interface" things, + -- buttons, menus, etc. + -- Easier to organize, I guess. + +require "x_functions"; +require "x_interface"; +if debugmodes['enabled'] and false then + require "x_smb1enemylist"; -- used for summoning and other things... not finished +end; + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu:5/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(6); +end; + + +-- **************************************************************************** +-- * drawmouse(xpos, ypos, click) +-- * Draws a crude mouse pointer at the location; mostly good for screenshots and debugging. +-- **************************************************************************** +function drawmouse(x, y, click) + + if click then + fill = "#cccccc"; + else + fill = "#ffffff"; + end; + + y = y + 1; + + for i = 0, 6 do + if i ~= 6 then + line(x + i, y + i, x + i, y + 8 - math.floor(i / 2), fill); + pixel(x + i, y + 8 - math.floor(i / 2), "#000000"); + end; + pixel(x + i, y + i - 1, "#000000"); + end; + pixel(x + 1, y + 0, "#000000"); + + line(x , y , x , y + 9, "#000000"); +-- line(x + 1, y + 1, x + 6 , y + 6, "#000000"); +-- line(x , y + 11, x + 7 , y + 7, "#000000"); + +end; + + +-- **************************************************************************** +-- * smbpx2ram( screen-x, screen-y ) +-- * Returns the offset that represents the tile under screenx/screeny. +-- **************************************************************************** +function smbpx2ram(px, py) + + local py = math.floor(py) - 0x20; + local px = math.floor(px); + if px < 0 or px > 400 or py < 0x00 or py > (240 - 0x20) then + return false; + end; + + local oy = math.floor(py / 0x10); + local ox = math.fmod(math.floor((px + smbdata['screenpos']) / 0x10), 0x20); + + offset = 0x500 + math.fmod(oy * 0x10 + math.floor(ox / 0x10) * 0xC0 + math.fmod(ox, 0xD0), 0x1A0); + return offset; + +end; + + +-- **************************************************************************** +-- * smbram2px( memory offset ) +-- * Gives the current top-left pixel of the tile the offset represents. +-- **************************************************************************** +function smbram2px(offset) + + offset = offset - 0x500; + if offset < 0 or offset >= 0x1A0 then + return false; + end; + + local px = (math.fmod(offset, 0x10) + math.floor(offset / 0xD0) * 0x10) * 0x10; + px = px - math.fmod(smbdata['screenpos'], 0x200); + if px < 0 then + px = px + 0x200; + end; + + local py = math.floor(math.fmod(offset, 0xD0) / 0x10); + returnval = {x = px, y = py}; + return returnval; + +end; + + +-- **************************************************************************** +-- * smbmoveenemy( Enemy number, xpos, ypos, x accell, y accell ) +-- * moves enemies to given point. auto-sets facing direction, as well +-- **************************************************************************** +function smbmoveenemy(n, x, y, ax, ay) + + local x1 = math.fmod(x, 0x100); + local x2 = math.floor(x / 0x100); + local y1 = math.fmod(y, 0x100); + local y2 = math.floor(y / 0x100); + local ax = math.max(-128, math.min(ax, 0x7F)); + local ay = math.max(-128, math.min(ay, 0x7F)); + + memory.writebyte(0x006D + n, x2); + memory.writebyte(0x0086 + n, x1); + memory.writebyte(0x00B5 + n, y2); + memory.writebyte(0x00CE + n, y1); + memory.writebyte(0x0057 + n, ax); + memory.writebyte(0x009F + n, ay); + + if ax > 0 then + memory.writebyte(0x0045 + n, 1); + elseif ax < 0 then + memory.writebyte(0x0045 + n, 2); + end; + +end; + + +-- **************************************************************************** +-- * inputaverage() +-- * Mouse movement averages (something unique to this...). +-- **************************************************************************** +function inputaverage() + + local tempx = 0; + local tempy = 0; + for temp = 1, 2 do + tempx = tempx + avgmove[temp]['xmouse']; + tempy = tempy + avgmove[temp]['ymouse']; + avgmove[temp] = avgmove[temp + 1]; + end; + avgmove[3]['xmouse'] = inpt['xmouse'] - last['xmouse']; + avgmove[3]['ymouse'] = inpt['ymouse'] - last['ymouse']; + avgmove['calc']['xmouse'] = (tempx + avgmove[3]['xmouse']) / 3; + avgmove['calc']['ymouse'] = (tempy + avgmove[3]['ymouse']) / 3; + +end; + + +-- **************************************************************************** +-- * tileview() +-- * This does all the "what tile is here" shit for you (me) +-- **************************************************************************** +function tileview () + local ramval = smbpx2ram(inpt['xmouse'], inpt['ymouse']); + if ramval then + local ret = smbram2px(ramval); + local c = "#ffffff"; + if math.fmod(timer, 4) < 2 then + c = "#cccccc"; + end; + if ret then + local tx1 = math.max(0, ret['x'] - 1); + local tx2 = math.min(0xFF, ret['x'] + 0x10); + local ty1 = math.max(ret['y'] * 0x10 + 0x1F, 0); + local ty2 = math.min(244, ret['y'] * 0x10 + 0x30); + box(tx1, ty1, tx2, ty2, c); + end; + + local textx = inpt['xmouse'] + 10; + local texty = inpt['ymouse'] - 4; + + if textx > 229 then + textx = textx - 42; + end; + texty = math.min(214, texty); + + text(textx, texty, string.format("%04X", ramval)); + text(textx, texty + 8, string.format(" %02X ", memory.readbyte(ramval))); + end; +end; + + +-- **************************************************************************** +-- * Generic test function, really. Does nothing of use. +-- * Incidentally, most of the times this shows up, it doesn't +-- **************************************************************************** +function test(arg) + + text(50, 100, "IT WORKS"); + +end; + + +-- **************************************************************************** +-- * spawnsetup(arg) +-- * Prepares spawning of an enemy. +-- * Perhaps should create a dialog box in the middle of the screen?.. +-- **************************************************************************** +function spawnsetup(args) + + if mode ~= 2 then + spawndata['lmode'] = mode; + mode = 2; + spawndata['enum'] = 0x00; + spawndata['ename'] = "Green Koopa"; + spawndata['etype'] = 0; + spawndata['exs'] = 16; + spawndata['eys'] = 24; + -- etype: + --- 0: normal enemy (one slot) + --- 1: big enemy (two slots, takes latter but fills both) + --- 2: powerup (takes slot 6) + end; +end; + + +-- **************************************************************************** +-- * spawnsetup(arg) +-- * Prepares spawning of an enemy. +-- * Perhaps should create a dialog box in the middle of the screen?.. +-- **************************************************************************** +function spawnenemy(args) + + local c = "#ffffff"; + if math.fmod(timer, 4) < 2 then + c = "#888888"; + end; + + local freespace = 0; + + if debugmodes['showenemydata'] then + for i = 1, 6 do + text(8, 8 + 8 * i, string.format("%d %02X", i, memory.readbyte(0x000E+i))); + end; + end; + for i = 1, 6 do + if ((spawndata['etype'] <= 1 and i <= 5) or (spawndata['etype'] == 2 and i == 6)) and memory.readbyte(0x000E+i) == 0 then + if debugmodes['showenemydata'] then + text(8, 8 + 8 * i, string.format("%d %02X *", i, memory.readbyte(0x000E+i))); + end; + if (spawndata['etype'] == 1 and memory.readbyte(0x000E + i - 1) == 0) or spawndata['etype'] ~= 1 then + freespace = i; + break; + end; + end; + end; + + if freespace > 0 then + box(inpt['xmouse'] - (spawndata['exs'] / 2), inpt['ymouse'] - (spawndata['eys'] / 2), inpt['xmouse'] + (spawndata['exs'] / 2), inpt['ymouse'] + (spawndata['eys'] / 2), c); + text(70, 31, string.format("Summon [%s]", spawndata['ename'])); + if debugmodes['showenemydata'] then + text(70, 39, string.format("Enemy slot [%X]", freespace)); + end; + local mx = smbdata['screenpos'] + inpt['xmouse']; + local my = 0x100 + inpt['ymouse']; + if inpt['leftclick'] and not last['leftclick'] then + memory.writebyte(0x000E + freespace, 1); + memory.writebyte(0x0015 + freespace, spawndata['enum']); + memory.writebyte(0x0499 + freespace, 3); + smbmoveenemy(freespace, mx - (spawndata['exs'] / 2), my - (spawndata['eys'] / 2), -1, 0); + mode = spawndata['lmode']; + end; + + else + text(70, 31, string.format("Can't summon (too many enemies)!")); + + end; + +end; + + +-- **************************************************************************** +-- * modechange(arg) +-- * changes current mode (used in menu). +-- * also changes menu text to reflect new mode. +-- **************************************************************************** +function modechange(args) + + mode = args[1]; + if args[1] == 0 then + mainmenu['menu']['m001_mode']['menu']['m001_tiles']['marked'] = 1; + mainmenu['menu']['m001_mode']['menu']['m002_enemy']['marked'] = 0; + else + mainmenu['menu']['m001_mode']['menu']['m001_tiles']['marked'] = 0; + mainmenu['menu']['m001_mode']['menu']['m002_enemy']['marked'] = 1; + end; +end; + + +-- **************************************************************************** +-- * debugmode(arg) +-- * changes debugmode flags +-- * useful for on-the-fly checking, I guess +-- **************************************************************************** +function debugmode(args) + + if debugmodes[args[2]] == false then + debugmodes[args[2]] = true; + mainmenu['menu']['m999_debug']['menu'][args[1]]['marked'] = 1; + else + debugmodes[args[2]] = false; + mainmenu['menu']['m999_debug']['menu'][args[1]]['marked'] = 0; + end; +end; + + + + + +mainmenu = { + test = 1; + life = 0; + width = 54; + menu = { + m001_mode = { + label = "Mode", + life = 0; + width = 50; + menu = { + m001_tiles = { + label = " Objects", + action = modechange, + args = {0}, + marked = 0; + }, + m002_enemy = { + label = " Sprites", + action = modechange, + args = {1}, + marked = 1; + }, + }, + }, + m002_summon = { + label = "Summon", + action = spawnsetup, + args = {1}, + }, + }, +}; + +if debugmodes['enabled'] then + mainmenu['menu']['m999_debug'] = { + label = "Debug", + life = 0; + width = 90; + menu = { + m000_showmouse = { + label = " Draw mouse", + action = debugmode, + marked = debugmodes['drawmouse'] and 1 or 0; + args = {"m000_showmouse", "drawmouse"}, + }, + m001_enemydata = { + label = " Show enemy data", + action = debugmode, + marked = debugmodes['showenemydata'] and 1 or 0; + args = {"m001_enemydata", "showenemydata"}, + }, + m002_locktimer = { + label = " Lock timer", + action = debugmode, + marked = debugmodes['locktimer'] and 1 or 0; + args = {"m002_locktimer", "locktimer"}, + }, + m003_invincible = { + label = " Invincibility", + action = debugmode, + marked = debugmodes['invincible'] and 1 or 0; + args = {"m003_invincible", "invincible"}, + }, + }, + }; +end; + + + + +smbdata = {screenpos = 0}; +mode = 1; +enemyhold = {}; +avgmove = { + { xmouse = 0, ymouse = 0 }, + { xmouse = 0, ymouse = 0 }, + { xmouse = 0, ymouse = 0 }, + calc = {} + }; +spawndata = {}; + +while (true) do + + + input.update(); -- updates mouse position + inputaverage(); -- average movement (for throwing) + + smbdata['screenposold'] = smbdata['screenpos']; + smbdata['screenpos'] = memory.readbyte(0x071a) * 0x100 + memory.readbyte(0x071c); + smbdata['screenposchg'] = smbdata['screenpos'] - smbdata['screenposold']; + smbdata['rendercol'] = memory.readbyte(0x06A0); + if smbdata['screenposchg'] < 0 then + smbdata['screenposchg'] = 0; + end; + timer = timer + 1; + + + if debugmodes['enabled'] then + if control.button( 234, 15, 19, 2, "SET\n999") then + memory.writebyte(0x07F8, 0x09); + memory.writebyte(0x07F9, 0x09); + memory.writebyte(0x07FA, 0x09); + end; + + if debugmodes['locktimer'] then + memory.writebyte(0x0787, 0x1F); + end; + + if debugmodes['invincible'] then + memory.writebyte(0x079E, 0x02); + end; + end; + + + if mode == 0 then + tileview(); + elseif mode == 2 then + + spawnenemy(); + + + else + if debugmodes['showenemydata'] then + text(0, 25 + 0, string.format("E# XPOS YPOS XREL YREL XA YA TY HB")); + end; + + for i=1,6 do + if (memory.readbyte(0x000E+i) ~= 0) then --and memory.readbyte(0x04AC+(i*4)) ~= 0xFF) and (memory.readbyte(0x0015 + i) ~= 0x30 and memory.readbyte(0x0015 + i) ~= 0x31) then + if not enemyhold[i] or not inpt['leftclick'] then + enemyhold[i] = nil; +-- text(8, 50 + i * 8, "-"); + elseif enemyhold[i] then +-- text(8, 50 + i * 8, string.format("HOLD %04X %04X", smbdata['screenpos'] + inpt['xmouse'] - enemyhold[i]['xmouse'], inpt['ymouse'] + 0x100 - enemyhold[i]['ymouse'])); + smbmoveenemy(i, smbdata['screenpos'] + inpt['xmouse'] - enemyhold[i]['x'], inpt['ymouse'] + 0x100 - enemyhold[i]['y'], (avgmove['calc']['xmouse']) * 8, avgmove['calc']['ymouse'] / 2.5); + end; + + e2x1 = memory.readbyte(0x04AC+(i*4)); + e2y1 = memory.readbyte(0x04AC+(i*4)+1); + e2x2 = memory.readbyte(0x04AC+(i*4)+2); + e2y2 = memory.readbyte(0x04AC+(i*4)+3); +-- text(e2x1 - 5, e2y1 - 13, string.format("%02X", memory.readbyte(0x001E + i))); + + + + enemyxpos = memory.readbytesigned(0x006D + i) * 0x0100 + memory.readbyte(0x0086 + i); + enemyypos = memory.readbytesigned(0x00B5 + i) * 0x100 + memory.readbyte(0x00CE + i); + enemyxacc = memory.readbytesigned(0x0057 + i); + enemyyacc = memory.readbytesigned(0x009f + i); + enemyxposa = enemyxpos - smbdata['screenpos']; + enemyyposa = enemyypos - 0x100; + enemyyposa2 = math.fmod(enemyyposa + 0x10000, 0x100); + enemytype = memory.readbyte(0x0015 + i); + enemyhitbox = memory.readbyte(0x0499 + i); + + dead = ""; + if enemyyposa <= -72 + 32 and enemyyacc < -3 then + dead = "UP"; + end; + if math.abs(enemyxacc) >= 0x60 then + dead = dead .. "SIDE"; + end; + if dead ~= "" then + dead = " ".. dead; + end; + + if debugmodes['showenemydata'] then + line(enemyxposa, enemyyposa2, enemyxposa + 16, enemyyposa2, "#ffffff"); + text(enemyxposa, enemyyposa2, memory.readbyte(0x0045 + i)); + text(1, 25 + 8 * i, string.format("E%X %04X %04X %04X %04X %02X %02X %02X %02X %s", i, + AND(enemyxpos, 0xFFFF), + AND(enemyypos, 0xFFFF), + AND(enemyxposa, 0xFFFF), + AND(enemyyposa, 0xFFFF), + AND(enemyxacc, 0xFF), + AND(enemyyacc, 0xFF), + AND(enemytype, 0xFF), + AND(enemyhitbox, 0xFF), + "")); -- dead)); + end; + + if hitbox(inpt['xmouse'], inpt['ymouse'], inpt['xmouse'], inpt['ymouse'], e2x1, e2y1, e2x2, e2y2, "#ffffff", "#0000ff") then +-- if hitbox(inpt['xmouse'], inpt['ymouse'], inpt['xmouse'], inpt['ymouse'], enemyxposa, enemyyposa, enemyxposa + 0xF, enemyyposa + 0x17) then + +-- text(e2x1 - 5, e2y1 - 13, string.format("#%d %02X", i, memory.readbyte(0x0015 + i))); + + + if inpt['leftclick'] then + + if not enemyhold[i] then + enemyhold[i] = { x = inpt['xmouse'] - enemyxposa, y = inpt['ymouse'] - enemyyposa }; + end; + + +-- memory.writebyte(0x001F + i, 0xFF); +-- memory.writebyte(0x04AC + i, 0xFF); +-- memory.writebyte(0x000E + i, 0x00); + end; + end; + else + enemyhold[i] = nil; + + end; + end; + end; + + --[[ + zap = zapper.read(); + + box(zap['xmouse'] - 5, zap['ymouse'] - 5, zap['xmouse'] + 5, zap['ymouse'] + 5, "#ffffff"); + if zap['click'] == 1 then + box(zap['xmouse'] - 7, zap['ymouse'] - 7, zap['xmouse'] + 7, zap['ymouse'] + 7, "#ff0000"); + end; + line(zap['xmouse'] - 0, zap['ymouse'] - 9, zap['xmouse'] + 0, zap['ymouse'] + 9, "#ffffff"); + line(zap['xmouse'] - 9, zap['ymouse'] - 0, zap['xmouse'] + 9, zap['ymouse'] + 0, "#ffffff"); + ]] + + + + -- almost always + if control.button(78, 14, 54, 1, "
") then + mainmenu['life'] = 70; + end; + control.showmenu(78, 25, mainmenu); + + text( 20, 222, " 2009 Xkeeper - http://jul.rustedlogic.net/ "); + line( 21, 231, 232, 231, "#000000"); + + if debugmodes['enabled'] then + text( 41, 214, " Debug version - ".. debugmodes['ver'] .." "); + end; + + + -- always on top + if debugmodes['drawmouse'] then + drawmouse(inpt['xmouse'], inpt['ymouse'], inpt['leftclick']); + end; + FCEU.frameadvance(); + +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB-Snow.lua b/branches/fceux-2.2.2/output/luaScripts/SMB-Snow.lua new file mode 100644 index 00000000..56841324 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB-Snow.lua @@ -0,0 +1,245 @@ +--Super Mario Bros. - It's Snowing! +--Written by XKeeper + + +require("x_functions"); + +if not x_requires then + -- Sanity check. If they require a newer version, let them know. + timer = 1; + while (true) do + timer = timer + 1; + for i = 0, 32 do + gui.drawbox( 6, 28 + i, 250, 92 - i, "#000000"); + end; + gui.text( 10, 32, string.format("This Lua script requires the x_functions library.")); + gui.text( 53, 42, string.format("It appears you do not have it.")); + gui.text( 39, 58, "Please get the x_functions library at"); + gui.text( 14, 69, "http://xkeeper.shacknet.nu/"); + gui.text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + gui.drawbox(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + +else + x_requires(4); +end; + + +function smbpx2ram(px, py) + + py = math.floor(py) - 0x20; + px = math.floor(px); + +-- text(90, 16, string.format("PX[%4d] PY[%4d]", px, py)); + if px < 0 or px > 400 or py < 0x00 or py > (240 - 0x20) then + return false; + end; + + oy = math.floor(py / 0x10); + ox = math.fmod(math.floor((px + smbdata['screenpos']) / 0x10), 0x20); + +-- text(90, 16, string.format("CX[%4X] CY[%4X]", ox, oy)); + + offset = 0x500 + math.fmod(oy * 0x10 + math.floor(ox / 0x10) * 0xC0 + math.fmod(ox, 0xD0), 0x1A0); + return offset; + +end; + +function smbram2px(offset) + + offset = offset - 0x500; + if offset < 0 or offset >= 0x1A0 then + return false; + end; + + + px = (math.fmod(offset, 0x10) + math.floor(offset / 0xD0) * 0x10) * 0x10; + px = px - math.fmod(smbdata['screenpos'], 0x200); +-- text(8, 8, string.format("PX[%4d] OF[%4X]", px, offset)); + if px < 0 then + px = px + 0x200; + end; + + py = math.floor(math.fmod(offset, 0xD0) / 0x10); + returnval = {x = px, y = py}; + return returnval; + +end; + + +function doballs() + + count = 0; + for k, v in pairs(balls) do + + v['x'] = v['x'] + v['xs'] - smbdata['screenposchg']; + v['y'] = v['y'] + v['ys']; +-- v['ys'] = v['ys'] - 0.1; + v['life'] = v['life'] - 1; + + offset = smbpx2ram(v['x'], v['y']); + temp = 0; + if offset then + temp = memory.readbyte(offset); + end; + + + -- 354 so we can spawn them offscreen + if v['x'] < 0 or v['x'] > 512 or v['y'] < 0 or v['y'] > 243 or v['life'] < 0 or (temp > 0) then + balls[k] = nil; + else + balls[k] = v; + colkey = math.ceil(255 * (5 - math.max(math.min(5, (v['life'] / 15)), 0)) / 5); + + if v['c'] >= 0 then + color = string.format("#%02X%02X%02X", v['c'], v['c'], 255); +-- color = string.format("#%02X%02X%02X", v['c'] * .8, v['c'] * .5, v['c'] * 0); + else + color = string.format("#%02X0000", v['c'] * -1 , 0, 0); + end; + + if v['life'] > 400 then + box(v['x'] - 1, v['y'] - 1, v['x'] + 1, v['y'] + 1, color); + pixel(v['x'], v['y'], color); + elseif v['life'] > 200 then + box(v['x'], v['y'], v['x'] + 1, v['y'] + 1, color); + else + pixel(v['x'], v['y'], color); + end; + count = count + 1; + end; + end; + + return count; + +end; + + +balls = {}; +z = 0; +timer = 0; +smbdata = {screenpos = 0}; +while (true) do + + if + memory.readbyte(0x0301) == 0x3F and + memory.readbyte(0x0302) == 0x10 and + memory.readbyte(0x0303) == 0x04 and + memory.readbyte(0x0304) == 0x22 + then + memory.writebyte(0x0304, 0x0F); + end; + + smbdata['screenposold'] = smbdata['screenpos']; + smbdata['screenpos'] = memory.readbyte(0x071a) * 0x100 + memory.readbyte(0x071c); + smbdata['screenposchg'] = smbdata['screenpos'] - smbdata['screenposold']; + smbdata['rendercol'] = memory.readbyte(0x06A0); + if smbdata['screenposchg'] < 0 then + smbdata['screenposchg'] = 0; + end; + timer = timer + 1; + + + ballcount = doballs(); + + + for i = 0, 2 do + balls[z] = {x = math.random(0, 512), y = 0, xs = math.random(-50, 00) / 100, ys = math.random(100, 150) / 100, life = math.random(400, 700), c = math.random(200, 255)}; + z = z + 1; + end; + +-- lifebar(8, 8, 240, 2, ballcount, 1000, "#ffffff", "clear"); +--]] + +--[[ + for x = 0x00, 0x0F do + for y = 0x00, 0x0C do + box(x * 0x10 + 0, y * 0x10 + 0x20, x * 0x10 + 0x01, y * 0x10 + 0x21, "#FFFFFF"); + value = memory.readbyte(smbpx2ram(x * 0x10, y * 0x10 + 0x20)); + if value > 0 then + text(x * 0x10 + 0, y * 0x10 + 0x20, string.format("%02X", value)); + end; + end; + end; +]] + +-- text(8, 8, string.format("0x06A0 [%4X]", smbdata['rendercol'])); +--[[ + for i = 0, 5 do + ret = smbram2px(0x500 + i * 0x10 + i); + if ret then +-- text(8, 16, string.format("PX[%4d] PY[%4d]", ret['x'], ret['y'])); + box(ret['x'] + 0, ret['y'] * 0x10 + 0x20, ret['x'] + 0x0F, ret['y'] * 0x10 + 0x2F, "#FFFFFF"); + end; + end; +--]] +--[[ + box(19, 19, 0x20 * 2 + 20, 46, "#0000ff"); + box(18, 18, 0x20 * 2 + 21, 47, "#0000ff"); + for x = 0, 0x1F do + for y = 0, 0x0C do + offset = 0x500 + y * 0x10 + math.floor(x / 0x10) * 0xD0 + math.fmod(x, 0x10); + c = memory.readbyte(offset); + box(x * 2 + 20, y * 2 + 20, x * 2 + 21, y * 2 + 21, string.format("#%02X%02X%02X", c, c, c)); + end; + end; + + if math.fmod(timer, 2) < 1 then + temp = math.floor(math.fmod(smbdata['screenpos'], 0x200) / 8); + if temp < 0x20 then + box(temp + 20, 19, temp + 0x10 * 2 + 20, 46, "#ffffff"); + else + box(temp + 20, 19, 0x20 * 2 + 20, 46, "#ffffff"); + box(19, 19, (temp - 0x20) + 20, 46, "#ffffff"); + end; + + line(smbdata['rendercol'] * 2 + 20, 19, smbdata['rendercol'] * 2 + 20, 46, "#00ff00"); + end; + +--]] +--[[ + x = 0; + y = 0; + px = math.sin(timer / 60) * 100 + 127; + py = math.cos(timer / 60) * 90 + 100 + 0x20; + offset = smbpx2ram(px, py); + if offset then + offset = offset - 0x500; + x = math.floor(offset / 0xD0) * 0x10 + math.fmod(offset, 0x10); + y = math.floor(math.fmod(offset, 0xD0) / 0x10); + + x2 = math.fmod(smbdata['screenpos'] + x * 0x10, 0x100); + box( x2, y * 0x10 + 0x20, x2 + 0x0F, y * 0x10 + 0x2F, "#ffffff"); +-- line( 0, y * 0x10, 255, y * 0x10, "#ffffff"); + + box (px - 3, py - 3, px + 3, py + 3, "#ffffff"); + line(px - 6, py , px + 6, py , "#ffffff"); + line(px , py - 6, px , py + 6, "#ffffff"); + text(90, 24, string.format("Offset[%04X]", offset + 0x500)); + text(90, 32, string.format("OX[%4X] OY[%4X]", x, y)); + text(90, 40, string.format("SX[%4X]", x2)); + else + text(90, 24, "Offset failed"); + end; + + if math.fmod(timer, 2) < 1 then + temp = math.floor(math.fmod(smbdata['screenpos'], 0x200) / 8) + 20; + line(temp, 18, temp, 47, "#ffffff"); + box(20 + x * 2, 20 + y * 2, 21 + x * 2, 21 + y * 2, "#ffffff"); + + end; + +--]] + + + text( 20, 222, " 2009 Xkeeper - http://jul.rustedlogic.net/ "); + line( 21, 231, 232, 231, "#000000"); + + FCEU.frameadvance(); + +end; + diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB2U.lua b/branches/fceux-2.2.2/output/luaScripts/SMB2U.lua new file mode 100644 index 00000000..4ebb2c39 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB2U.lua @@ -0,0 +1,173 @@ +-- Super Mario Bros. 2 USA - Grids & Contents (Unfinished) +-- Super Mario Bros. 2 (U) (PRG0) [!].nes +-- Written by QFox +-- 31 July 2008 + +-- shows (proper!) grid and contents. disable grid by setting variable to false +-- shows any non-air grid's tile-id +-- Slow! Will be heavy on lighter systems + + + +local angrybirdo = false; -- makes birdo freak, but can skew other creatures with timing :) +local drawgrid = true; -- draws a green grid + +local function box(x1,y1,x2,y2,color) + -- gui.text(50,50,x1..","..y1.." "..x2..","..y2); + if (x1 > 0 and x1 < 0xFF and x2 > 0 and x2 < 0xFF and y1 > 0 and y1 < 239 and y2 > 0 and y2 < 239) then + gui.drawbox(x1,y1,x2,y2,color); + end; +end; +local function text(x,y,str) + if (x > 0 and x < 0xFF and y > 0 and y < 240) then + gui.text(x,y,str); + end; +end; +local function toHexStr(n) + local meh = "%X"; + return meh:format(n); +end; + +while (true) do + if (angrybirdo and memory.readbyte(0x0010) > 0x81) then memory.writebyte(0x0010, 0x6D); end; -- birdo fires eggs constantly :p + + -- px = horzizontal page of current level + -- x = page x (relative to current page) + -- rx = real x (relative to whole level) + -- sx = screen x (relative to viewport) + local playerpx = memory.readbyte(0x0014); + local playerpy = memory.readbyte(0x001E); + local playerx = memory.readbyte(0x0028); + local playery = memory.readbyte(0x0032); + local playerrx = (playerpx*0xFF)+playerx; + local playerry = (playerpy*0xFF)+playery; + local playerstate = memory.readbyte(0x0050); + local screenoffsetx = memory.readbyte(0x04C0); + local screenoffsety = memory.readbyte(0x00CB); + + local playersx = (playerx - screenoffsetx); + if (playersx < 0) then playersx = playersx + 0xFF; end; + + local playersy = (playery - screenoffsety); + if (playersy < 0) then playersy = playersy + 0xFF; end; + + if (playerstate ~= 0x07) then + box(playersx, playersy, playersx+16, playersy+16, "green"); + end; + + if (memory.readbyte(0x00D8) == 0) then -- not scrolling vertically + -- show environment + -- i have playerrx, which is my real position in this level + -- i have the level, which is located at 0x6000 (the SRAM) + -- each tile (denoted by one byte) is 16x16 pixels + -- each screen is 15 tiles high and about 16 tiles wide + -- to get the right column, we add our playerrx/16 to 0x6000 + -- to be exact: + -- 0x6000 + (math.floor(playerrx/16) * 0xF0) + math.mod(playerx,0x0F) + + local levelstart = 0x6000; -- start of level layout in RAM + + -- ok, here we have two choices. either this is a horizontal level or + -- it is a vertical level. We have no real way of checking this, but + -- luckily levels are either horizontal or vertical :) + -- so there are three possibilities + -- 1: you're in 0:0, no worries + -- 2: you're in x:0, you're in a horizontal level + -- 3: you're in 0:y, you're in a vertical level + + + local addleftcrap = math.mod(screenoffsetx,16)*-1; -- works as padding to keep the grid aligned + local leftsplitrx = (memory.readbyte(0x04BE)*0x100) + (screenoffsetx + addleftcrap); -- column start left. add addleftcrap to iterative stuff to build up + local addtopcrap = math.mod(screenoffsety,15); -- works as padding to keep the grid aligned + local columns = math.floor(leftsplitrx/16); -- column x of the level is on the left side of the screen + + if (drawgrid) then -- print grid? + for i=0,15 do + -- text(addleftcrap+(i*16)-1, 37, toHexStr(columns+i)); -- print colnumber in each column + for j=0,17 do + box(addleftcrap+(i*16), addtopcrap+(j*16), addleftcrap+(i*16)+16, addtopcrap+(j*16)+16, "green"); -- draw green box for each cell + end; + end; + end; + + -- 42=mushroom if you go sub + -- 45=small + -- 44=big + -- 49=subspace + -- 6c=pow + -- 4e=cherry + + local topsplitry = (screenoffsety); + + -- starting page (might flow into next page). if the number of columns + -- is > 16, its a horizontal level, else its a vertical level. in either + -- case, the other will not up this value. + local levelpage = + levelstart + + ((math.floor(columns/16))*0xF0) + + (memory.readbyte(0x00CA)*0x100) + + topsplitry; + local levelcol = math.mod(columns,16); -- this is our starting column + + --text(10,150,toHexStr(topsplitry).." "..toHexStr(levelcol).." "..toHexStr(levelpage+levelcol).." "..toHexStr(leftsplitrx)); + + for j=0,15 do -- 16 columns + if (levelcol + j > 15) then -- go to next page + levelpage = levelpage + 0xF0; + levelcol = -j; + end; + for i=0,14 do -- 15 rows + local tile = memory.readbyte(levelpage+(levelcol+j)+(i*0x10)); + if (tile ~= 0x40) then + text(-2+addleftcrap+(j*16),5+(i*16),toHexStr(tile)); + end; + end; + end; + end; -- not scrolling if + + -- print some generic stats + text(2,10,"x:"..toHexStr(screenoffsetx)); + text(2,25,"y: "..toHexStr(screenoffsety)); + text(230,10,memory.readbyte(0x04C1)); + text(100,10,"Page: "..playerpx..","..playerpy); + text(playersx,playersy,playerrx.."\n"..playery); + + -- draw enemy info + local startpx = 0x0015; + local startpy = 0x001F; + local startx = 0x0029; + local starty = 0x0033; + local drawn = 0x0051; + local type = 0x0090; + for i=0,9 do + local estate = memory.readbyte(drawn+i); + if (estate ~= 0) then + local ex = memory.readbyte(startx+i); + local epx = memory.readbyte(startpx+i); + local ey = memory.readbyte(starty+i); + local epy = memory.readbyte(startpy+i); + local erx = (epx*0xFF)+ex; + local ery = (epy*0xFF)+ey; + local esx = (ex - screenoffsetx); + if (esx < 0) then esx = esx + 0xFF; end; + local esy = (ey - screenoffsety); + if (esy < 0) then esy = esy + 0xFF; end; + + --text(10, 20+(16*i), i..": "..esx.." "..erx); -- show enemy position list + + -- show enemy information + if ((erx > playerrx-127) and erx < (playerrx+120)) then + --text(esx,esy,erx); -- show level x pos above enemy + local wtf = "%X"; + text(esx,esy,wtf:format(memory.readbyte(type+i))); -- show enemy code + if (estate == 1 and i < 5) then + box(esx, esy, esx+16, esy+16, "red"); + else + box(esx, esy, esx+16, esy+16, "blue"); + end; + end; + end; + end; -- enemy info + + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/SMB3-RainbowRiding.lua b/branches/fceux-2.2.2/output/luaScripts/SMB3-RainbowRiding.lua new file mode 100644 index 00000000..493dea21 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SMB3-RainbowRiding.lua @@ -0,0 +1,638 @@ +SCRIPT_TITLE = "Super Mario Bros. 3 Rainbow Riding" +SCRIPT_VERSION = "0.1" + +require "m_utils" +m_require("m_utils",0) + +--[[ +Super Mario Bros. 3 Rainbow Riding +version 0.1 by miau + +Visit http://morphcat.de/lua/ for the most recent version and other scripts. + +This script turns smb3 into a new game very similar to Kirby's Canvas Curse. +It's still incomplete, messy and full of bugs, so don't expect too much. Next version +will fix most of that... hopefully. +Probably slow on old computers, you may want to turn down emulator speed anyway to +decrease difficulty. + +Controls + Left-click on mario - jump + Middle-click anywhere - run + Draw vertical lines to make mario change his walking direction + Draw horizontal lines to help mario move over obstacles + +Supported roms + Super Mario Bros 3 (J), Super Mario Bros 3 (U) (PRG 0), Super Mario Bros 3 (U) (PRG 1), + Super Mario Bros 3 (E) + +Known Bugs/TODO list + Too many to list em all, actually... + - game objects are occasionally catapulted out of screen - bad divisions!? + - mario falling through lines (clean up collision detection) + - long vertically scrolling levels won't work + - boss battles are glitchy + - disable auto move in mini games? + - option to disable auto move? + - make collision detection work with fire balls (fire mario or fire piranha plants) + - improve map screen check + - add easy mode: decrease mario's speed + - improve enemy hit boxes + - (add suicide button in case mario gets stuck) +-]] + +--configurable vars +local show_cursor = false +-------------------------------------------------------------------------------------------- + + + +local Z_LSPAN = 400 --240 +local Z_MAX = 128 --256 --maximum amount of lines on screen +local NUM_SPRITES = 20 + +local zbuf = {} +local zindex = 1 +local timer = 0 +local zprev = 0 +local last_inp={} +local spr = {} --game's original sprites +local mario = {} +local clickbox={x1=-4,y1=4,x2=18,y2=32} +local collx = 0 +local colly = 0 +--local coll = {} --debug +local paintmeter = 0 +local lastpaint = -100 +local jp = {} + + +--accepts two tables containing these elements [1]=x1, [2]=y1, [3]=x2, [4]=y2 +function get_line_intersection(a,b) + local Asx,Asy,Bsx,Bsy,s,t + local Ax1,Ay1,Ax2,Ay2 + local Bx1,By1,Bx2,By2 + Ax1 = a[1] + Ay1 = a[2] + Ax2 = a[3] + Ay2 = a[4] + Bx1 = b[1] + By1 = b[2] + Bx2 = b[3] + By2 = b[4] + Asx = Ax2 - Ax1 + Asy = Ay2 - Ay1 + Bsx = Bx2 - Bx1 + Bsy = By2 - By1 + + s = (-Asy * (Ax1 - Bx1) + Asx * (Ay1 - By1)) / (-Bsx*Asy + Asx*Bsy) + t = (Bsx * (Ay1 - By1) - Bsy * (Ax1 - Bx1)) / (-Bsx*Asy + Asx*Bsy) + if(s>=0 and s<=1 and t>=0 and t<=1) then + local Ix,Iy + Ix = Ax1 + t * Asx + Iy = Ay1 + t * Asy + return Ix,Iy + else + return nil + end +end + +function close_to_line(Px,Py,a,range) --a[4] line segment + local Ax=a[1] + local Ay=a[2] + local Bx=a[3] + local By=a[4] + local APx = Px - Ax + local APy = Py - Ay + local ABx = Bx - Ax + local ABy = By - Ay + local absq = ABx*ABx + ABy*ABy + local apab = APx*ABx + APy*ABy + local t = apab / absq + + if (t < 0.0) then + t = 0.0 + elseif (t > 1.0) then + t = 1.0 + end + local Cx,Cy + Cx = Ax + ABx * t + Cy = Ay + ABy * t + if(getdistance(Px,Py,Cx,Cy)<=range) then + return true + else + return false + end +end + +function ride_line(s,xoffs,yoffs) + + local function move(zx1,zy1,zx2,zy2) + local avx,avy,cvx,cvy + cvx,cvy = getvdir(zx1,zy1,zx2,zy2) + if(math.abs(spr[s].vx) Z_MAX) then + spr[s].riding = 1 + end + if(spr[s].riding==firstline) then + spr[s].riding=nil + return + end + domovemagic(x,y,firstline) + end + end + + if(spr[s].riding==nil) then + return + end + + local x = spr[s].x+xoffs + local y = spr[s].y+yoffs + domovemagic(x,y,spr[s].riding) +end + +function collisioncheck(s) + local c=false + local cvx,cvy + local avx,avy + + local function checkpixel(xoffs,yoffs,i,j) + local x = spr[s].x+xoffs + local y = spr[s].y+yoffs + local px2 = x+spr[s].vx + local py2 = y+spr[s].vy + local px1 = x + local py1 = y + local zx = zbuf[i].x + local zy = zbuf[i].y + local zx2 = zbuf[j].x + local zy2 = zbuf[j].y + if(spr[s].vx~=0 or spr[s].vy~=0) then + if(spr[s].vx>0) then --we need at least one pixel!!? + px2 = px2 + 2 + elseif(spr[s].vx<0) then + px2 = px2 - 2 + end + if(spr[s].vy>0) then + py2 = py2 + 2 + elseif(spr[s].vy<0) then + py2 = py2 - 2 + end + + local cx,cy = get_line_intersection({px1,py1,px2,py2},{zx,zy,zx2,zy2}) + if(cx~=nil) then + cx = math.floor(cx) + cy = math.floor(cy) + local avx,avy,cvx,cvy + + --coll = {--[[a={px1,py1,px2+spr[s].vx*64,py2+spr[s].vy*64},-]]b={zbuf[i].x,zbuf[i].y,zbuf[j].x,zbuf[j].y}} --debug + collx = cx + colly = cy + + avx,avy = getvdir(px1,py1,px2,py2) + cvx,cvy = getvdir(zbuf[j].x,zbuf[j].y,zbuf[i].x,zbuf[i].y) + + + local x,y + x = cx-xoffs + y = cy-yoffs + if(spr[s].x==x and spr[s].y==y) then + --FCEU.message("boo"..timer) + else + set_sprite_pos(s,x,y) + end + if(s==0) then --mario/luigi + if(math.abs(cvy)==1 and math.abs(cvx) < 0.5) then + change_sprite_dir(s) + set_sprite_velocity(s,-avx,nil) + else + spr[s].riding = i + set_sprite_velocity(s,0,0) + end + else --enemies, moving platforms + end + + + return true + end + else + if(close_to_line(x,y,{zx,zy,zx2,zy2},4)) then + if(s==0) then + spr[s].riding = i + set_sprite_velocity(s,0,0) + end + return true + else + spr[s].riding = nil + end + end + return false + end + + if(spr[s].riding) then + ride_line(s,8,30) + return + end + + for i=1,Z_MAX do + if(zbuf[i] and zbuf[i].connected) then + --if(zbuf[i].x >= spr[s].x+hitbox.x1 and zbuf[i].y >= spr[s].y+hitbox.y1 + -- and zbuf[i].x <= spr[s].x+hitbox.x2 and zbuf[i].y <= spr[s].y+hitbox.y2) then + --local px = spr[s].x-spr[s].vx + --local py = spr[s].y-spr[s].vy + local j + j = i - 1 + if(j < 1) then + j = Z_MAX + end + + if(zbuf[j]) then --check if line is still valid (if nil, node disappeared) + if(s==0) then --mario + if(checkpixel(8,30,i,j)) then + return + end + else + if(checkpixel(0,0,i,j) or checkpixel(8,8,i,j) + --[[or checkpixel(0,8,i,j) or checkpixel(8,0,i,j)-]]) then + destroy_sprite(s) + return + end + end + end + + --end + end + end + +end + + +function screen_to_game_pos(x,y) + return x+scroll_x,y+scroll_y +end + +function game_to_screen_pos(x,y) + return x-scroll_x,y-scroll_y +end + + +function destroy_sprite(s) + if(s<10) then + memory.writebyte(0x660+s,0x06) + --memory.writebyte(0x660+s,0x00) + --set_sprite_velocity(s,10,10) + else + memory.writebyte(0x6C7+s-10,0x01) + --set_sprite_pos(s,0,0) + end +end + +function set_sprite_velocity(s,vx,vy) + if(s<10) then + if(s==0) then + memory.writebyte(0xD8,1) --air flag? + end + if(vx) then + memory.writebyte(0xBD+s,vx*16) + spr[s].vx = vx + end + if(vy) then + memory.writebyte(0xCF+s,vy*16) + spr[s].vy = vy + end + end +end + +function set_sprite_pos(i,x,y) + memory.writebyte(0x90+i,AND(x,255)) + memory.writebyte(0x75+i,math.floor(x/256)) + memory.writebyte(0xA2+i,AND(y,255)) + memory.writebyte(0x87+i,math.floor(y/256)) + spr[i].x = x + spr[i].y = y + spr[i].sx,spr[i].sy = game_to_screen_pos(spr[i].x,spr[i].y) +end + +function change_sprite_dir(s) + if(spr[s].dir == 1) then + spr[s].dir = -1 + elseif(spr[s].dir == -1) then + spr[s].dir = 1 + end +end + + +function add_rainbow_coord(cx,cy,connected) + zbuf[zindex] = {t=timer,x=cx,y=cy,connected=connected} + zprev = zbuf[zindex] + zindex = zindex + 1 + if(zindex>Z_MAX) then + zindex = 1 + end +end + +function drawrainbow(x1,y1,x2,y2,coloffs) + local cx,cy + local vx,vy + local color = coloffs + vx,vy = getvdir(x1,y1,x2,y2) + cx = x1 + cy = y1 + + for i=1,200 do + if(cx>=0 and cy>=0 and cx<=253 and cy<=253) then + local rcolor = color/1.8+161 --165 + gui.drawpixel(cx,cy,rcolor) + gui.drawpixel(cx,cy+1,rcolor) + gui.drawpixel(cx+1,cy,rcolor) + gui.drawpixel(cx+1,cy+1,rcolor) + + gui.drawpixel(cx+2,cy,rcolor) + gui.drawpixel(cx,cy+2,rcolor) + gui.drawpixel(cx+2,cy+1,rcolor) + gui.drawpixel(cx+1,cy+2,rcolor) + gui.drawpixel(cx+2,cy+2,rcolor) + end + if((x2>x1 and cx>x2) or (x2y1 and cy>y2) or (y260) then + mario.lastposchange = timer + change_sprite_dir(0) + end + + --load game sprites from ram + for i=0,NUM_SPRITES-1 do + if(i<10) then + spr[i].x = memory.readbyte(0x90+i)+memory.readbyte(0x75+i)*256 + spr[i].y = memory.readbyte(0xA2+i)+memory.readbyte(0x87+i)*256 + spr[i].vx = memory.readbytesigned(0xBD+i)/16 + spr[i].vy = memory.readbytesigned(0xCF+i)/16 + spr[i].a = (memory.readbytesigned(0x660+i)~=0) + spr[i].id = memory.readbytesigned(0x670+i) + spr[i].sx,spr[i].sy = game_to_screen_pos(spr[i].x,spr[i].y) + else + --TODO: 0x5D3? + local xcomp = memory.readbyte(0xFD) + local ycomp = memory.readbyte(0xFC) + spr[i].x = memory.readbyte(0x5C9+i-10) + spr[i].y = memory.readbyte(0x5BF+i-10) + spr[i].a = true + spr[i].vx = 0 + spr[i].vy = 0 + spr[i].sx = AND(spr[i].x-xcomp+256,255) + spr[i].sy = AND(spr[i].y-ycomp+256,255) + spr[i].x = spr[i].sx + scroll_x + spr[i].y = spr[i].sy + scroll_y + end + if(spr[i].a) then + collisioncheck(i) + end + end + +end + +function update_vars() + --disabling input not possible anymore in FCEUX 2.1? + jp = {} + if(mario.riding==nil) then + if(mario.movetimer) then + jp.B = 1 + mario.movetimer = mario.movetimer - 1 + if(mario.movetimer == 0) then + mario.movetimer = nil + end + end + if(mario.dir==1) then + jp.right=1 + elseif(mario.dir==-1) then + jp.left=1 + end + --if(AND(timer,1)==0) then --automatically enter doors and pipes... not a very good idea actually :P + --jp.up=1 + --if(memory.readbyte(0xD8)==1) then --air flag set? try to stay in air as long as possible... makes it easier to rescue mario if collision detection screws up.. sucks in water levels + -- jp.A=1 + --end + --else + -- jp.down=1 --automatically enter pipes + --end + end + + inp = input.get() + + scroll_x = memory.readbyte(0xFD)+memory.readbyte(0x12)*256 + scroll_y = memory.readbyte(0xFC)--+memory.readbyte(0x13)*256 --not quite right, long vertical scrolling levels won't work + + --0xD8 = 0 -> touch ground, 1 -> air + + update_sprites() + + + if(inp.middleclick) then + mario.movetimer = 30 + end + + if(inp.leftclick==nil) then + mario.jumping=false + end + if(inp.leftclick and last_inp.leftclick==nil and + inp.xmouse>=mario.sx+clickbox.x1 and inp.xmouse<=mario.sx+clickbox.x2 and + inp.ymouse>=mario.sy+clickbox.y1 and inp.ymouse<=mario.sy+clickbox.y2) + then + jp.A = 1 + mario.jumping = true + elseif(inp.leftclick and mario.jumping) then + jp.A = 1 + elseif(inp.leftclick) then + if(paintmeter>0) then + local x,y=screen_to_game_pos(inp.xmouse,inp.ymouse) + if(last_inp.leftclick==nil) then + add_rainbow_coord(x,y,false) + outofpaint = nil + elseif(outofpaint==nil) then + if(zprev and getdistance(x,y,zprev.x,zprev.y)>8) then + add_rainbow_coord(x,y,true) + paintmeter = paintmeter - 2 + lastpaint = timer + end + end + else + outofpaint = true + end + end + + joypad.set(1,jp) + + last_mario = mario + last_inp = inp +end + +function render() + --bctext(0,20,string.format("Memory usage: %.2f KB",collectgarbage("count"))) + + + local j = 0 + for i=1,Z_MAX do + if(zbuf[i]) then + j = j + 1 + end + end + --bctext(0,20,"Lines: "..j) + --bctext(0,20,mario.x..","..mario.y) + --bctext(0,30,mario.sx..","..mario.sy) + --bctext(0,40,mario.vx..","..mario.vy) + --bctext(0,50,"D "..mario.dir) + + --bctext(0,70,"scroll_x: "..scroll_x) + --bctext(0,80,"scroll_y: "..scroll_y) + --bctext(0,90,AND(mario.x,255)) + --if(mario.riding) then + -- bctext(0,100,"R") + --end + bcbox(mario.sx+clickbox.x1,mario.sy+clickbox.y1,mario.sx+clickbox.x2,mario.sy+clickbox.y2,"white") + + local prev_x, prev_y, prev_connected + local i=zindex + local color = AND(timer/2,15) + for j=1,Z_MAX do + if(zbuf[i]) then + local ltime = timer-zbuf[i].t + if(ltime0) then + drawrainbow(pmx+paintmeter,pmy,pmx,pmy,timer/6) + end + bcbox(pmx-2,pmy-1,pmx+102,pmy+3,"white") + + if(timer-lastpaint>60) then + paintmeter = paintmeter + 1 + if(paintmeter>100) then + paintmeter=100 + end + end + + if(show_cursor) then + local col2 + if(inp.leftclick) then + col2 = "#FFAA00" + elseif(inp.rightclick) then + col2 = "#0099EE" + elseif(inp.middleclick) then + col2 = "#AACC00" + else + col2 = "white" + end + drawcursor(inp.xmouse,inp.ymouse,"black",col2) + end +end + + +function domagic() + if(memory.readbyte(0x73)==0x20) then --map screen(?) + update_vars() + render() + else + bcpixel(1,10,"clear") + end +end + +initialize() +gui.register(domagic) + +while(true) do + FCEU.frameadvance() + timer = timer + 1 +end diff --git a/branches/fceux-2.2.2/output/luaScripts/ShowPalette.lua b/branches/fceux-2.2.2/output/luaScripts/ShowPalette.lua new file mode 100644 index 00000000..1f2805c2 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/ShowPalette.lua @@ -0,0 +1,62 @@ +-- Show Palette +-- Click for other palette boxes +-- P00 - P3F are NES palette values. +-- P40 - P7F are LUA palette values. + +-- True or False +ShowTextLabels=true; + +function DecToHex(numberin) + if (numberin < 16) then + return string.format("0%X",numberin); + else + return string.format("%X",numberin); + end; +end; + +function text(x,y,str,text,back) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.text(x,y,str,text,back); + end; +end; + +local ButtonWasPressed; +local CurrentPaletteDisplay=0; + + + +while(true) do + +FCEU.frameadvance(); + +for i = 0, 7 do + gui.box(0 + (30*i),0,29 + (30*i),29,"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8))); + gui.box(0 + (30*i),30,29 + (30*i),59,"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8))); + gui.box(0 + (30*i),60,29 + (30*i),89,"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8))); + gui.box(0 + (30*i),90,29 + (30*i),119,"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8))); + if(ShowTextLabels == true) then + text(6 + (30*i),11,"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8))) + text(6 + (30*i),41,"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8))) + text(6 + (30*i),71,"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8))) + text(6 + (30*i),101,"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8))) + end; +end; + +mousestuff = input.get() + +if (not ButtonWasPressed) then + if (mousestuff.leftclick) then + ButtonWasPressed = 1; + CurrentPaletteDisplay=CurrentPaletteDisplay+1; + if (CurrentPaletteDisplay == 2) then + CurrentPaletteDisplay=8; + end; + if (CurrentPaletteDisplay == 10) then + CurrentPaletteDisplay=0; + end; + end; +end + +ButtonWasPressed = (mousestuff.leftclick); + +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/SoundDisplay.lua b/branches/fceux-2.2.2/output/luaScripts/SoundDisplay.lua new file mode 100644 index 00000000..c0fbccd6 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SoundDisplay.lua @@ -0,0 +1,213 @@ +--------------------------------------------------------------------------- +-- Display Sound Channels data +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * sound.get() +--------------------------------------------------------------------------- +-- Usage: +-- The script allows you to observe data of 5 sound channels. +-- Analysing such info you can notice some regularities in how +-- the data oscillates/changes when ingame music plays. +-- Then you can write scripts similar to \taseditor\TrackNoise.lua +-- to facilitate synchronous dances in TAS movies. +--------------------------------------------------------------------------- + +square1 = {x=1, y=8, on=true}; +square2 = {x=129, y=8, on=true}; +triangle = {x=1, y=67, on=true}; +noise = {x=129, y=67, on=true}; +dpcm = {x=1, y=118, on=true}; + +semitones = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"}; +duty_ratio = {"12.5%", "25%", "50%", "75%"}; +duty_color = {"purple", "magenta", "orange", "yellow"}; +key_color = {"#000000FF", "#202020FF", "#205050FF", "#008080FF", "#00C0C0FF", "#00FFFFFF", "#FFFFFFFF", "#FFFF00FF", "#FFFFFFFF", "#FFFF00FF", "#FFFFFFFF", "#FFFF00FF", "#FFFFFFFF", "#FFFF00FF", "#FFFFFFFF"}; +noise_color = {long="orange", short = "yellow"}; + +sample_names = { + -- Here you can specify custom names for DMC samples (to display name instead of just address) + -- For example, here are two samples for Contra(U) ROM + Sample_FC00 = {name="Kick", color="#C0C0C0FF"}, + Sample_FCC0 = {name="Snare", color="#80C0FFFF"}, +} + +function everyframe() + snd = sound.get(); + + if (square1.on) then + gui.text(square1.x, square1.y, "SQUARE 1:"); + + Volume = snd.rp2a03.square1.volume; + gui.text(square1.x, square1.y + 8, "Volume:"); + gui.box(square1.x + 32, square1.y + 7, square1.x + 32+15, square1.y + 15, "#006000FF", "black"); + gui.box(square1.x + 32, square1.y + 7, square1.x + 32 + Volume * 15, square1.y + 15, "green", "clear"); + gui.text(square1.x + 48, square1.y + 8, string.format("%g", Volume)); + + Frequency = snd.rp2a03.square1.frequency; + gui.text(square1.x, square1.y + 16, "Frequency: " .. string.format("%g", Frequency) .. "Hz"); + + Midikey = snd.rp2a03.square1.midikey; + gui.box(square1.x-1, square1.y + 23, square1.x + 127, square1.y + 31, "#008080FF", "black") + gui.box(square1.x-1, square1.y + 23, square1.x-1 + Midikey, square1.y + 31, "#00C0C0FF", "black") + Keycolor = key_color[math.floor(Volume * 15) + 1]; + gui.box(square1.x-1 + Midikey-1, square1.y + 23, square1.x-1 + Midikey+1, square1.y + 31, "white", Keycolor) + Note = math.floor((Midikey - 21) % 12); + Octave = math.floor((Midikey - 12) / 12); + Semitone = tostring(semitones[Note + 1]) .. Octave; + gui.text(square1.x, square1.y + 32, "Note: " .. Semitone .. " "); + gui.text(square1.x + 50, square1.y + 32, "(" .. string.format("%g", Midikey) .. ")"); + + Period = snd.rp2a03.square1.regs.frequency; + IndicatorColor = "#" .. string.format("%x", Period % 256) .. "0000FF"; + gui.text(square1.x, square1.y + 40, "Period:"); + gui.box(square1.x + 31, square1.y + 39, square1.x + 39, square1.y + 47, IndicatorColor, "black"); + gui.text(square1.x + 40, square1.y + 40, string.format("%g", Period)); + + Duty = snd.rp2a03.square1.duty; + gui.text(square1.x, square1.y + 48, "Duty #" .. Duty .. " (" .. duty_ratio[Duty + 1] .. ")", duty_color[Duty + 1]); + end + + if (square2.on) then + gui.text(square2.x, square2.y, "SQUARE 2:"); + + Volume = snd.rp2a03.square2.volume; + gui.text(square2.x, square2.y + 8, "Volume:"); + gui.box(square2.x + 32, square2.y + 7, square2.x + 32+15, square2.y + 15, "#006000FF", "black"); + gui.box(square2.x + 32, square2.y + 7, square2.x + 32 + Volume * 15, square2.y + 15, "green", "clear"); + gui.text(square2.x + 48, square2.y + 8, string.format("%g", Volume)); + + Frequency = snd.rp2a03.square2.frequency; + gui.text(square2.x, square2.y + 16, "Frequency: " .. string.format("%g", Frequency) .. "Hz"); + + Midikey = snd.rp2a03.square2.midikey; + gui.box(square2.x-1, square2.y + 23, square2.x + 127, square2.y + 31, "#008080FF", "black") + gui.box(square2.x-1, square2.y + 23, square2.x-1 + Midikey, square2.y + 31, "#00C0C0FF", "black") + Keycolor = key_color[math.floor(Volume * 15) + 1]; + gui.box(square2.x-1 + Midikey-1, square2.y + 23, square2.x-1 + Midikey+1, square2.y + 31, "white", Keycolor) + Note = math.floor((Midikey - 21) % 12); + Octave = math.floor((Midikey - 12) / 12); + Semitone = tostring(semitones[Note + 1]) .. Octave; + gui.text(square2.x, square2.y + 32, "Note: " .. Semitone .. " "); + gui.text(square2.x + 50, square2.y + 32, "(" .. string.format("%g", Midikey) .. ")"); + + Period = snd.rp2a03.square2.regs.frequency; + IndicatorColor = "#" .. string.format("%x", Period % 256) .. "0000FF"; + gui.text(square2.x, square2.y + 40, "Period:"); + gui.box(square2.x + 31, square2.y + 39, square2.x + 39, square2.y + 47, IndicatorColor, "black"); + gui.text(square2.x + 40, square2.y + 40, string.format("%g", Period)); + + Duty = snd.rp2a03.square2.duty; + gui.text(square2.x, square2.y + 48, "Duty #" .. Duty .. " (" .. duty_ratio[Duty + 1] .. ")", duty_color[Duty + 1]); + end + + if (triangle.on) then + gui.text(triangle.x, triangle.y, "TRIANGLE:"); + + Volume = snd.rp2a03.triangle.volume; + gui.text(triangle.x, triangle.y + 8, "Volume:"); + gui.box(triangle.x + 32, triangle.y + 7, triangle.x + 32+15, triangle.y + 15, "#006000FF", "black"); + gui.box(triangle.x + 32, triangle.y + 7, triangle.x + 32 + Volume * 15, triangle.y + 15, "#00A000FF", "clear"); + gui.text(triangle.x + 48, triangle.y + 8, string.format("%g", Volume)); + + Frequency = snd.rp2a03.triangle.frequency; + gui.text(triangle.x, triangle.y + 16, "Frequency: " .. string.format("%g", Frequency) .. "Hz"); + + Midikey = snd.rp2a03.triangle.midikey; + gui.box(triangle.x-1, triangle.y + 23, triangle.x + 127, triangle.y + 31, "#008080FF", "black") + gui.box(triangle.x-1, triangle.y + 23, triangle.x-1 + Midikey, triangle.y + 31, "#00C0C0FF", "black") + if (Volume ~= 0) then gui.box(triangle.x-1 + Midikey-1, triangle.y + 23, triangle.x-1 + Midikey+1, triangle.y + 31, "white", "black") end; + Note = math.floor((Midikey - 21) % 12); + Octave = math.floor((Midikey - 12) / 12); + Semitone = tostring(semitones[Note + 1]) .. Octave; + gui.text(triangle.x, triangle.y + 32, "Note: " .. Semitone .. " "); + gui.text(triangle.x + 50, triangle.y + 32, "(" .. string.format("%g", Midikey) .. ")"); + + Period = snd.rp2a03.triangle.regs.frequency; + IndicatorColor = "#" .. string.format("%x", Period % 256) .. "0000FF"; + gui.text(triangle.x, triangle.y + 40, "Period:"); + gui.box(triangle.x + 31, triangle.y + 39, triangle.x + 39, triangle.y + 47, IndicatorColor, "black"); + gui.text(triangle.x + 40, triangle.y + 40, string.format("%g", Period)); + end + + if (noise.on) then + gui.text(noise.x, noise.y, "NOISE:"); + + Volume = snd.rp2a03.noise.volume; + gui.text(noise.x, noise.y + 8, "Volume:"); + gui.box(noise.x + 32, noise.y + 7, noise.x + 32+15, noise.y + 15, "#006000FF", "black"); + gui.box(noise.x + 32, noise.y + 7, noise.x + 32 + Volume * 15, noise.y + 15, "green", "clear"); + gui.text(noise.x + 48, noise.y + 8, string.format("%g", Volume)); + + Frequency = snd.rp2a03.noise.frequency; + gui.text(noise.x, noise.y + 16, "Frequency: " .. string.format("%g", Frequency) .. "Hz"); + + Midikey = snd.rp2a03.noise.midikey; + gui.box(noise.x-1, noise.y + 23, noise.x + 127, noise.y + 31, "#008080FF", "black") + gui.box(noise.x-1, noise.y + 23, noise.x-1 + (Midikey/2), noise.y + 31, "#00C0C0FF", "black") + Keycolor = key_color[math.floor(Volume * 15) + 1]; + gui.box(noise.x-1 + (Midikey/2)-1, noise.y + 23, noise.x-1 + (Midikey/2)+1, noise.y + 31, "white", Keycolor) + Note = math.floor((Midikey - 21) % 12); + Octave = math.floor((Midikey - 12) / 12); + Semitone = tostring(semitones[Note + 1]) .. Octave; + gui.text(noise.x, noise.y + 32, "Note: " .. Semitone .. " "); + gui.text(noise.x + 58, noise.y + 32, "(" .. string.format("%g", Midikey) .. ")"); + + Period = snd.rp2a03.noise.regs.frequency; + IndicatorColor = "#" .. string.format("%X", Period % 256) .. "0000FF"; + gui.text(noise.x, noise.y + 40, "Period:"); + gui.box(noise.x + 31, noise.y + 39, noise.x + 39, noise.y + 47, IndicatorColor, "black"); + gui.text(noise.x + 40, noise.y + 40, string.format("%g", Period)); + + if (snd.rp2a03.noise.short) then + gui.text(noise.x, noise.y + 48, "Mode: short", noise_color.short); + else + gui.text(noise.x, noise.y + 48, "Mode: long", noise_color.long); + end + end + + if (dpcm.on) then + gui.text(dpcm.x, dpcm.y, "DPCM:"); + + Volume = snd.rp2a03.dpcm.volume; + gui.text(dpcm.x, dpcm.y + 8, "Volume:"); + gui.box(dpcm.x + 32, dpcm.y + 7, dpcm.x + 32+15, dpcm.y + 15, "#006000FF", "black"); + gui.box(dpcm.x + 32, dpcm.y + 7, dpcm.x + 32 + Volume * 15, dpcm.y + 15, "#00A000FF", "clear"); + gui.text(dpcm.x + 48, dpcm.y + 8, string.format("%g", Volume)); + + Frequency = snd.rp2a03.dpcm.frequency; + gui.text(dpcm.x, dpcm.y + 16, "Frequency: " .. string.format("%g", Frequency) .. "Hz"); + + Midikey = snd.rp2a03.dpcm.midikey; + gui.box(dpcm.x-1, dpcm.y + 23, dpcm.x + 127, dpcm.y + 31, "#008080FF", "black") + gui.box(dpcm.x-1, dpcm.y + 23, dpcm.x-1 + (Midikey/2), dpcm.y + 31, "#00C0C0FF", "black") + if (Volume ~= 0) then gui.box(dpcm.x-1 + (Midikey/2)-1, dpcm.y + 23, dpcm.x-1 + (Midikey/2)+1, dpcm.y + 31, "white", "black") end; + Note = math.floor((Midikey - 21) % 12); + Octave = math.floor((Midikey - 12) / 12); + Semitone = tostring(semitones[Note + 1]) .. Octave; + gui.text(dpcm.x, dpcm.y + 32, "Note: " .. Semitone .. " "); + gui.text(dpcm.x + 50, dpcm.y + 32, "(" .. string.format("%g", Midikey) .. ")"); + + Period = snd.rp2a03.dpcm.regs.frequency; + IndicatorColor = "#" .. string.format("%x", Period % 256) .. "0000FF"; + gui.text(dpcm.x, dpcm.y + 40, "Period:"); + gui.box(dpcm.x + 31, dpcm.y + 39, dpcm.x + 39, dpcm.y + 47, IndicatorColor, "black"); + gui.text(dpcm.x + 40, dpcm.y + 40, string.format("%g", Period)); + + if (snd.rp2a03.dpcm.dmcloop) then + gui.text(dpcm.x, dpcm.y + 48, "Sample: $" .. string.format("%X", snd.rp2a03.dpcm.dmcaddress) .. " (" .. snd.rp2a03.dpcm.dmcsize .. " bytes looped)", "orange"); + else + gui.text(dpcm.x, dpcm.y + 48, "Sample: $" .. string.format("%X", snd.rp2a03.dpcm.dmcaddress) .. " (" .. snd.rp2a03.dpcm.dmcsize .. " bytes)"); + end + + Sample_id = "Sample_" .. string.format("%X", snd.rp2a03.dpcm.dmcaddress); + if (sample_names[Sample_id] ~= nil) then + gui.text(dpcm.x + 170, dpcm.y + 48, sample_names[Sample_id].name, sample_names[Sample_id].color); + end + + gui.text(dpcm.x, dpcm.y + 56, "DMC seed: " .. string.format("%X", snd.rp2a03.dpcm.dmcseed)); + end +end + +emu.registerafter(everyframe); + diff --git a/branches/fceux-2.2.2/output/luaScripts/SoundDisplay2.lua b/branches/fceux-2.2.2/output/luaScripts/SoundDisplay2.lua new file mode 100644 index 00000000..6402ed76 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/SoundDisplay2.lua @@ -0,0 +1,312 @@ +-- feos, 2012 +-- gui.box frame simulates transparency + +print("Hi-hat and keys may glitch if you produce sound effects.") +print("Leftclick over the displays: channel names to hide the volumes, notes to hide the keyboard.") +print(" ") +print("And praise Gocha!") + +iterator = 15 +kb = {x=9, y=154, on=true} +prev_keys = input.get() +semitones = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"} + +volumes = { + S1V = {0}, S1C = {}, + S2V = {0}, S2C = {}, + TV = {0}, + NV = {0}, + DPCMV = {0} +} + +function Draw() + snd = sound.get() + keys = input.get() + + -- do only at the first frame + if #volumes.S1V == 1 then + channels = { + Square1 = {x=1, y=9, vol=volumes.S1V, color=volumes.S1C, duty=0, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}}, + Square2 = {x=1+45*1, y=9, vol=volumes.S2V, color=volumes.S2C, duty=0, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}}, + Triangle = {x=1+45*2, y=9, vol=volumes.TV, midi=0, semitone=0, octave=0, prev_semitone=0, float = {}}, + Noise = {x=1+45*3, y=9, vol=volumes.NV, midi=0, semitone=0, octave=0}, + DPCM = {x=1+45*4, y=9, vol=volumes.DPCMV} + } + end + + -- update the first indices for volume tables + -- shift the previous ones farther + table.insert(channels.Square1.vol, 1, snd.rp2a03.square1.volume*15) + table.insert(channels.Square2.vol, 1, snd.rp2a03.square2.volume*15) + table.insert(channels.Triangle.vol, 1, snd.rp2a03.triangle.volume*15) + table.insert(channels.Noise.vol, 1, snd.rp2a03.noise.volume*15) + table.insert(channels.DPCM.vol, 1, snd.rp2a03.dpcm.volume*15) + + -- get duty and midikey for proper channels + channels.Square1.duty = snd.rp2a03.square1.duty + channels.Square2.duty = snd.rp2a03.square2.duty + + channels.Square1.midi = snd.rp2a03.square1.midikey + channels.Square2.midi = snd.rp2a03.square2.midikey + channels.Triangle.midi = snd.rp2a03.triangle.midikey + channels.Noise.midi = snd.rp2a03.noise.midikey + + -- guess notes + for name, chan in pairs(channels) do + if name == "Square1" or name == "Square2" or name == "Triangle" or name == "Noise" then + if chan.vol[1] > 0 then + chan.octave = math.floor((chan.midi - 12) / 12) + chan.semitone = tostring(semitones[math.floor((chan.midi - 21) % 12) + 1]) + else chan.semitone = "--"; chan.octave = "-" + end + end + end + + -- notes display + gui.text(kb.x+203, kb.y, "S1: "..channels.Square1.semitone..channels.Square1.octave, "#ff0000ff", "#000000ff") + gui.text(kb.x+203, kb.y+9, "S2: "..channels.Square2.semitone..channels.Square2.octave, "#aa00ccff", "#000000ff") + gui.text(kb.x+204, kb.y+18, "Tr: "..channels.Triangle.semitone..channels.Triangle.octave, "#00aaffff", "#000000ff") + gui.text(kb.x+204, kb.y+27, "Ns: "..channels.Noise.semitone..channels.Noise.octave, "#ffffffff", "#000000ff") + +----------------- +-- Draw hi-hat -- +----------------- + + xhh1 = 227 + yhh1 = 18 + xhh2 = 227 + yhh2 = 18 + + if channels.Noise.vol[1] > 0 then + if channels.Noise.octave >= 9 and channels.Noise.octave <= 12 then + colorhh = "#ffaa00" + if channels.Noise.vol[2] - channels.Noise.vol[1] < 4 + and channels.Noise.vol[2] > 0 + then yhh1 = 15 + end + end + else colorhh = "#00000000" + end + + gui.line(xhh1-1, yhh1, xhh1+28, yhh1, "#00000088") + gui.line(xhh1-1, yhh1-1, xhh1+28, yhh1-1, "#00000088") + gui.line(xhh1-1, yhh1-2, xhh1+28, yhh1-2, "#00000088") + gui.line(xhh1+3, yhh1-3, xhh1+24, yhh1-3, "#00000088") + gui.line(xhh1+8, yhh1-4, xhh1+19, yhh1-4, "#00000088") + gui.line(xhh1+11, yhh1-5, xhh1+16, yhh1-5, "#00000088") + gui.line(xhh1+12, yhh1-6, xhh1+15, yhh1-6, "#00000088") + gui.line(xhh2-1, yhh2, xhh2+28, yhh2, "#00000088") + gui.line(xhh2-1, yhh2+1, xhh2+28, yhh2+1, "#00000088") + gui.line(xhh2-1, yhh2+2, xhh2+28, yhh2+2, "#00000088") + gui.line(xhh2+3, yhh2+3, xhh2+24, yhh2+3, "#00000088") + gui.line(xhh2+8, yhh2+4, xhh2+19, yhh2+4, "#00000088") + gui.line(xhh2+11, yhh2+5, xhh2+16, yhh2+5, "#00000088") + gui.line(xhh2+12, yhh2+6, xhh2+15, yhh2+6, "#00000088") + + gui.line(xhh1, yhh1-1, xhh1+27, yhh1-1, colorhh) + gui.line(xhh1+4, yhh1-2, xhh1+23, yhh1-2, colorhh) + gui.line(xhh1+9, yhh1-3, xhh1+18, yhh1-3, colorhh) + gui.line(xhh1+12, yhh1-4, xhh1+15, yhh1-4, colorhh) + gui.line(xhh1+13, yhh1-5, xhh1+14, yhh1-5, colorhh) + gui.line(xhh2, yhh2+1, xhh2+27, yhh2+1, colorhh) + gui.line(xhh2+4, yhh2+2, xhh2+23, yhh2+2, colorhh) + gui.line(xhh2+9, yhh2+3, xhh2+18, yhh2+3, colorhh) + gui.line(xhh2+12, yhh2+4, xhh2+15, yhh2+4, colorhh) + gui.line(xhh2+13, yhh2+5, xhh2+14, yhh2+5, colorhh) + +-------------------- +-- Keyboard stuff -- +-------------------- + + if (kb.on) then + -- capture leftclicks + if keys.xmouse <= 256 and keys.xmouse >= 205 and keys.ymouse >= 154 and keys.ymouse <= 181 then + if keys["leftclick"] and not prev_keys["leftclick"] then kb.on = false end + end + -- draw the kayboard + gui.box(kb.x-8, kb.y, kb.x+200, kb.y+16, "#ffffffff") -- white solid box + for a = -2, 49 do gui.box(kb.x+4*a, kb.y, kb.x+4*a, kb.y+16, "#00000000") end -- black lines + -- draw colored boxes as clean notes + for name, chan in pairs(channels) do + if name == "Square1" or name == "Square2" or name == "Triangle" then + if name == "Triangle" then color = "#00aaffff" + elseif name == "Square1" then color = "#ff0000ff" + else color = "#aa00ccff" + end + + if chan.semitone == "C" then gui.box(kb.x+1 +28*(chan.octave-1), kb.y, kb.x+3 +28*(chan.octave-1), kb.y+16, color) + elseif chan.semitone == "D" then gui.box(kb.x+5 +28*(chan.octave-1), kb.y, kb.x+7 +28*(chan.octave-1), kb.y+16, color) + elseif chan.semitone == "E" then gui.box(kb.x+9 +28*(chan.octave-1), kb.y, kb.x+11+28*(chan.octave-1), kb.y+16, color) + elseif chan.semitone == "F" then gui.box(kb.x+13+28*(chan.octave-1), kb.y, kb.x+15+28*(chan.octave-1), kb.y+16, color) + elseif chan.semitone == "G" then gui.box(kb.x+17+28*(chan.octave-1), kb.y, kb.x+19+28*(chan.octave-1), kb.y+16, color) + elseif chan.semitone == "A" then gui.box(kb.x+21+28*(chan.octave-1), kb.y, kb.x+23+28*(chan.octave-1), kb.y+16, color) + elseif chan.semitone == "B" then gui.box(kb.x+25+28*(chan.octave-1), kb.y, kb.x+27+28*(chan.octave-1), kb.y+16, color) + end + end + end + -- draw accidental keys + gui.box(kb.x-3, kb.y, kb.x-5, kb.y+10, "#00000000") + for oct = 0, 6 do + gui.box(kb.x+3+28*oct, kb.y, kb.x+5+28*oct, kb.y+10, "#00000000") + gui.box(kb.x+7+28*oct, kb.y, kb.x+9+28*oct, kb.y+10, "#00000000") + gui.box(kb.x+15+28*oct, kb.y, kb.x+17+28*oct, kb.y+10, "#00000000") + gui.box(kb.x+19+28*oct, kb.y, kb.x+21+28*oct, kb.y+10, "#00000000") + gui.box(kb.x+23+28*oct, kb.y, kb.x+25+28*oct, kb.y+10, "#00000000") + end + -- draw colored boxes over accidental keys + for name, chan in pairs(channels) do + if name == "Square1" or name == "Square2" or name == "Triangle" then + if name == "Triangle" then color = "#00aaffff" + elseif name == "Square1" then color = "#ff0000ff" + else color = "#aa00ccff" + end + + if chan.semitone == "C#" then gui.box(kb.x+3 +28*(chan.octave-1), kb.y, kb.x+5 +28*(chan.octave-1), kb.y+10, color) + elseif chan.semitone == "D#" then gui.box(kb.x+7 +28*(chan.octave-1), kb.y, kb.x+9 +28*(chan.octave-1), kb.y+10, color) + elseif chan.semitone == "F#" then gui.box(kb.x+15+28*(chan.octave-1), kb.y, kb.x+17+28*(chan.octave-1), kb.y+10, color) + elseif chan.semitone == "G#" then gui.box(kb.x+19+28*(chan.octave-1), kb.y, kb.x+21+28*(chan.octave-1), kb.y+10, color) + elseif chan.semitone == "A#" then gui.box(kb.x+23+28*(chan.octave-1), kb.y, kb.x+25+28*(chan.octave-1), kb.y+10, color) + end + end + end + + grey = "#aaaaaaaa" + for oct = 0, 6 do + gui.line(kb.x+3+28*oct, kb.y+10, kb.x+5+28*oct, kb.y+10, grey) + gui.line(kb.x+7+28*oct, kb.y+10, kb.x+9+28*oct, kb.y+10, grey) + gui.line(kb.x+15+28*oct, kb.y+10, kb.x+17+28*oct, kb.y+10, grey) + gui.line(kb.x+19+28*oct, kb.y+10, kb.x+21+28*oct, kb.y+10, grey) + gui.line(kb.x+23+28*oct, kb.y+10, kb.x+25+28*oct, kb.y+10, grey) + end + gui.line(kb.x-3, kb.y+10, kb.x-5, kb.y+10, grey) + gui.line(kb.x-8, kb.y, kb.x+200, kb.y, "#00000088") + gui.line(kb.x-8, kb.y+16, kb.x+200, kb.y+16, "#00000088") + gui.line(kb.x-8, kb.y, kb.x-8, kb.y+16, "#00000088") + gui.line(kb.x+200, kb.y, kb.x+200, kb.y+16, "#00000088") + else + -- capture leftclicks + if keys.xmouse <= 256 and keys.xmouse >= 205 and keys.ymouse >= 154 and keys.ymouse <= 181 then + if keys["leftclick"] and not prev_keys["leftclick"] then kb.on = true end + end + end + +-------------------- +-- Floating notes -- +-------------------- + + if (kb.on) then + for name, chan in pairs(channels) do + if name == "Square1" or name == "Square2" or name == "Triangle" then + + if chan.prev_semitone ~= chan.semitone then + if chan.semitone == "C" then table.insert(chan.float, 1, kb.x+1 +28*(chan.octave-1)) + elseif chan.semitone == "D" then table.insert(chan.float, 1, kb.x+5 +28*(chan.octave-1)) + elseif chan.semitone == "E" then table.insert(chan.float, 1, kb.x+9 +28*(chan.octave-1)) + elseif chan.semitone == "F" then table.insert(chan.float, 1, kb.x+13+28*(chan.octave-1)) + elseif chan.semitone == "G" then table.insert(chan.float, 1, kb.x+17+28*(chan.octave-1)) + elseif chan.semitone == "A" then table.insert(chan.float, 1, kb.x+21+28*(chan.octave-1)) + elseif chan.semitone == "B" then table.insert(chan.float, 1, kb.x+25+28*(chan.octave-1)) + elseif chan.semitone == "C#" then table.insert(chan.float, 1, kb.x+3 +28*(chan.octave-1)) + elseif chan.semitone == "D#" then table.insert(chan.float, 1, kb.x+7 +28*(chan.octave-1)) + elseif chan.semitone == "F#" then table.insert(chan.float, 1, kb.x+15+28*(chan.octave-1)) + elseif chan.semitone == "G#" then table.insert(chan.float, 1, kb.x+19+28*(chan.octave-1)) + elseif chan.semitone == "A#" then table.insert(chan.float, 1, kb.x+23+28*(chan.octave-1)) + end + end + + if name == "Triangle" then color = "#00aaffff" + elseif name == "Square1" then color = "#ff0000ff" + else color = "#aa00ccff" + end + + if #chan.float < 13 then + for i = 2, #chan.float do + if movie.framecount()%2 == 0 then gui.box(chan.float[i]-1, 161+i*5, chan.float[i]+3, 165+i*5, "#eedd2200") end + gui.box(chan.float[i], 162+i*5, chan.float[i]+2, 164+i*5, color) + end + else + for i = 2, 13 do + if movie.framecount()%2 == 0 then gui.box(chan.float[i]-1, 161+i*5, chan.float[i]+3, 165+i*5, "#eedd2200") end + gui.box(chan.float[i], 162+i*5, chan.float[i]+2, 164+i*5, color) + end + table.remove(chan.float, 14) + end + end + end + end + +--------------------- +-- Volumes display -- +--------------------- + + for name, chan in pairs(channels) do + if name == "Square1" or name == "Square2" then + -- set color for each duty value + if chan.duty == 0 then table.insert(chan.color,1,"#aaff00ff") + elseif chan.duty == 1 then table.insert(chan.color,1,"#00ff00ff") + elseif chan.duty == 2 then table.insert(chan.color,1,"#00bb00ff") + else table.insert(chan.color,1,"#008800ff") + end + end + -- capture leftclicks + if iterator == 15 then + if keys.ymouse <= 24 and keys.ymouse >= 0 then + if keys["leftclick"] and not prev_keys["leftclick"] then iterator = 1 end + end + else + if keys.ymouse <= 24 and keys.ymouse >= 0 then + if keys["leftclick"] and not prev_keys["leftclick"] then iterator = 15 end + end + end + -- draw volumes + gui.text(chan.x, 9, name, "#ffffffff", "#000000ff") + if iterator <=14 then + -- draw just first volume values + gui.text(chan.x, chan.y+9+1, chan.vol[1]) + if tonumber(chan.vol[1]) > 0 then + for j = 0, chan.vol[1]-1 do + gui.box(chan.x+13+j*2, chan.y+9, chan.x+15+j*2, chan.y+8+9, "#000000ff") + gui.line(chan.x+14+j*2, chan.y+1+9, chan.x+14+j*2, chan.y+7+9, "#00ff00ff") + if name == "Square1" or name == "Square2" then + -- color comes from duty + gui.text(chan.x+38, chan.y, chan.duty, chan.color[1], "#000000ff") + gui.line(chan.x+14+j*2, chan.y+1+9, chan.x+14+j*2, chan.y+7+9, chan.color[1]) + end + end + end + else + -- draw all 15 volume values + for i = 1, #chan.vol do + gui.text(chan.x, chan.y+i*9+1, chan.vol[i]) + if tonumber(chan.vol[i]) > 0 then + for j = 0, chan.vol[i]-1 do + gui.box(chan.x+13+j*2, chan.y+i*9, chan.x+15+j*2, chan.y+8+i*9, "#000000ff") + gui.line(chan.x+14+j*2, chan.y+1+i*9, chan.x+14+j*2, chan.y+7+i*9, "#00ff00ff") + if name == "Square1" or name == "Square2" then + -- color comes from duty + gui.text(chan.x+38, chan.y, chan.duty, chan.color[1], "#000000ff") + gui.line(chan.x+14+j*2, chan.y+1+i*9, chan.x+14+j*2, chan.y+7+i*9, chan.color[i]) + end + end + end + end + end + -- keep the table limited + table.remove(chan.vol, 15) + + -- highlight the first values + -- 30 Hz blinking, works properly if your monitor is set to 60 Hz + if chan.vol[1] > 0 and movie.framecount()%2 == 0 then + gui.box(chan.x+12, chan.y+8, chan.x+14+chan.vol[1]*2, chan.y+18, "#ffcc0000") + end + end + + for name, chan in pairs(channels) do + if name == "Square1" or name == "Square2" or name == "Triangle" then + chan.prev_semitone = chan.semitone + end + end + + prev_keys = keys +end +emu.registerafter(Draw); \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/Subtitler.lua b/branches/fceux-2.2.2/output/luaScripts/Subtitler.lua new file mode 100644 index 00000000..d0ab0773 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/Subtitler.lua @@ -0,0 +1,384 @@ +--FCEUX Subtitler Express v2, by FatRatKnight +-- I find the built-in subtitles for FCEUX's .fm2 is somewhat inconvenient. +-- This script should make the process smoother. + +-- Run the script. Type whatever you like. Letters and such will appear at the +-- top of the game display. The script can output a line of text that FCEUX +-- can understand and translates into the appropriate subtitle. It can ouput to +-- a file or to the display box + +-- Whatever the script outputs, you can copy that and paste it into the .fm2 +-- file in question, right before where all the actual frames begin. I suggest +-- WordPad to open the .fm2 file. + +-- If you're really that lazy, run a movie, subtitle it, then hit pageup twice. +-- The movie will be stopped, but this script will replace the old subtitles +-- with the new ones. It will actually create a new file appended with _S in +-- case the script royally screws up somehow. + +-- Let a frame pass, and the text becomes translucent. This is to signify that +-- the text will remain visible as an actual subtitle, but you can put in a new +-- subtitle here without destroying the old one. It will just override the old +-- subtitle when it's time for the new one to show up. + +-- Still, when it comes to translucent text, it's pretty dumb around loading +-- states. Don't try to worry too much about it. + +-- Beware of hotkeys you set in FCEUX, or even the defaults like I, P, shift+R, +-- shift+L, comma, and period. These can and will interfere with this script +-- if you don't disable them. + +-- Please don't try to type while emulation is unpaused. This script is not +-- smart enough to know how to handle unpaused typing. + +-- Don't let the warnings scare you. I hope the script makes subtitling easy. + + +local BypassFrameAdvanceKey= "backslash" --Set this to the frameadvance key. + +local SaveToThisFile= "ConvenientSubtitles.txt" --Location to save a file + +local SaveOnExit= true --Dost thou wish to save when the script exits? + + +-- List of commands: +local DelChar= "backspace" -- Delete a single character +local DelSub= "delete" -- Erase the whole subtitle for this frame +local ShoLine= "enter" -- Prints displayed line in .fm2 readable format +local SubCnt= "home" -- Counts current number of stored subtitles +local PntAll= "end" -- Prints all subtitles formatted for .fm2 +local SaveTxt= "pagedown" -- Saves subtitles to file +local T_AutoS= "insert" -- Toggles whether the script saves on exit +local SvToMov= "pageup" -- Saves subtitles to the movie file itself + + + +local WordyWords= {} +local CurrentStr= "" + +local KeyTable= { +a="a",b="b",c="c",d="d",e="e",f="f",g="g",h="h",i="i",j="j",k="k",l="l",m="m", +n="n",o="o",p="p",q="q",r="r",s="s",t="t",u="u",v="v",w="w",x="x",y="y",z="z", +tilde="`",minus="-",plus="=", +leftbracket="[",rightbracket="]",backslash="\\", +semicolon=";",quote="'", +comma=",",period=".",slash="/", + +A="A",B="B",C="C",D="D",E="E",F="F",G="G",H="H",I="I",J="J",K="K",L="L",M="M", +N="N",O="O",P="P",Q="Q",R="R",S="S",T="T",U="U",V="V",W="W",X="X",Y="Y",Z="Z", +TILDE="~",MINUS="_",PLUS="+", +LEFTBRACKET="{",RIGHTBRACKET="}",BACKSLASH="|", +SEMICOLON=":",QUOTE="\"", +COMMA="<",PERIOD=">",SLASH="?", + +numpad1="1",numpad2="2",numpad3="3",numpad4="4",numpad5="5", +numpad6="6",numpad7="7",numpad8="8",numpad9="9",numpad0="0", + +space= " ", SPACE= " "} + +KeyTable["1"]="!" +KeyTable["2"]="@" +KeyTable["3"]="#" +KeyTable["4"]="$" +KeyTable["5"]="%" +KeyTable["6"]="^" +KeyTable["7"]="&" +KeyTable["8"]="*" +KeyTable["9"]="(" +KeyTable["0"]=")" + +--LengthsTable= {} + +--for k,v in pairs(KeyTable) do +-- LengthsTable[v]= gui.text(0,0,v) +--end + + +local fc, lastfc= 0, 0 +--***************************************************************************** +local function UpdateFC() lastfc= fc; fc= movie.framecount() end +--***************************************************************************** +-- Quick function. I just want it to make use of movie.framecount convenient. + + +--***************************************************************************** +local function GetSortedSubs() +--***************************************************************************** +-- Returns a sorted array of frame numbers for every subtitle + + local ReturnTbl= {} + local count= 0 + for frame,text in pairs(WordyWords) do + count= count+1 + ReturnTbl[count]= frame + end + table.sort(ReturnTbl) + return ReturnTbl +end + + + +--***************************************************************************** +local function FixSubs() +--***************************************************************************** +-- Plants current subtitle into an array and fetches a new one. +-- Should be called every time the frame count changes. Every. Single. Time. +-- Can be called when the frame hasn't changed yet, if you need to. + + UpdateFC() + + if CurrentStr == "" then + WordyWords[lastfc]= nil + else + WordyWords[lastfc]= CurrentStr + end + + CurrentStr= WordyWords[fc] + if not CurrentStr then CurrentStr= "" end +end + +local LastSubfc= 0 +local LastSub= "" +--***************************************************************************** +local function GhostifySubs() +--***************************************************************************** +-- Displays subtitles. Needs a little support from emu.registerbefore to know +-- how to see an old subtitle after you decide to erase a new one. + + if CurrentStr ~= "" then + gui.text( 3, 9,CurrentStr) + elseif (fc < LastSubfc+300) and (fc > LastSubfc) then + gui.opacity(.5) + gui.text( 3, 9,LastSub) + end + gui.pixel(0,0,0) + gui.opacity(1) +end + + +--***************************************************************************** +local function SaveToFm2() +--***************************************************************************** +-- Saves to a copy of the currently playing .fm2. It will append _S to the new +-- filename, so run MySweetMovie.fm2, this script makes MySweetMovie_S.fm2 +-- By the way, this script tells FCEUX to stop "owning" the file as a way to +-- guarantee that this script can access it without interference. + + FixSubs() + + if not movie.active() then + print("Error: No movie!") + return false + end + + local OurMovie= movie.name() + + if string.match(OurMovie,".zip|") then + print("Error: File inside a zip!") + return false + end + + movie.close() + local MyFile, err= io.open(OurMovie,"r") + if not MyFile then + print("Error: Unable to open file for some strange reason.") + print(err) + return false + end + + local MovieData= MyFile:read("*a") + MyFile:close() + + local PreSub= string.find(MovieData,"\nsubtitle",1,true) + local PreData= string.find(MovieData,"\n|%d|") +-- local RemovedSubs= nil + if PreSub then +-- RemovedSubs= string.sub(MovieData,PreSub,PreData-1) + MovieData= (string.sub(MovieData,1,PreSub-1) + .. string.sub(MovieData,PreData)) + PreData= PreSub + end + + local S= GetSortedSubs() + local Write= "" + for i= 1, #S do + Write= Write .. "subtitle " .. S[i] .. " ".. WordyWords[S[i]] .. "\n" + end + + OurMovie= string.sub(OurMovie,1,-5) .. "_S" .. string.sub(OurMovie,-4) + + MyFile= io.open(OurMovie,"w") + MyFile:write(string.sub(MovieData,1,PreData) + .. Write + .. string.sub(MovieData,PreData+1)) + MyFile:close() + +-- print(RemovedSubs) + print("Success") + return true +end + + +--***************************************************************************** +local function SaveToTxt() +--***************************************************************************** + FixSubs() + local OutFile, Err= io.open(SaveToThisFile,"w") + if not OutFile then + print("File write fail") + print(Err) + return false + end + local Subs= GetSortedSubs() + for i= 1, #Subs do + OutFile:write("subtitle ".. Subs[i] .." ".. WordyWords[Subs[i]] .."\n") + end + OutFile:close() + print("Saved",#Subs,"lines to",SaveToThisFile) + + return true +end + + + +--***************************************************************************** +local KeyFunctions= {} +--***************************************************************************** +-- Greatly simplifies KeyReader for me. Also, faster processing should the list +-- get pretty large. +-- Various odds and ends that I want done shall be done here. + +function KeyFunctions._DelChar() --Remove a single character + if CurrentStr ~= "" then + CurrentStr= string.sub(CurrentStr,1,-2) + end +end +KeyFunctions[DelChar]= KeyFunctions._DelChar + + +function KeyFunctions._DelSub() --Remove the whole subtitle + CurrentStr= "" +end +KeyFunctions[DelSub]= KeyFunctions._DelSub + + +function KeyFunctions._ShoLine() --Dump the currently displayed line + print("subtitle",fc,CurrentStr) +end +KeyFunctions[ShoLine]= KeyFunctions._ShoLine + + +function KeyFunctions._SubCnt() --Count subtitles + local fr= GetSortedSubs() + print("Subtitle count:",#fr) +end +KeyFunctions[SubCnt]= KeyFunctions._SubCnt + + +function KeyFunctions._PntAll() --Dump all subtitles + FixSubs() + print("===========================") + local S= GetSortedSubs() + for i= 1, #S do + print("subtitle",S[i],WordyWords[S[i]]) + end +end +KeyFunctions[PntAll]= KeyFunctions._PntAll + + +function KeyFunctions._SaveTxt() --Save to a file + SaveToTxt() +end +KeyFunctions[SaveTxt]= KeyFunctions._SaveTxt + + +function KeyFunctions._T_AutoS() --Toggle Save-On-Exit + SaveOnExit= not SaveOnExit + if SaveOnExit then print("SaveOnExit activated!") + else print("Removed SaveOnExit.") end +end +KeyFunctions[T_AutoS]= KeyFunctions._T_AutoS + +local AmIClicked= false +function KeyFunctions._SvToMov() --Saves directly to the movie itself + if not movie.active() then + print("No movie detected. Doing nothing...") + return + end + + if not AmIClicked then + AmIClicked= true + print("Movie detected. Hit",SvToMov,"again to stop movie and", + "save subtitles directly into movie! Advance a frame to cancel.") + else + SaveToFm2() + end +end +KeyFunctions[SvToMov]= KeyFunctions._SvToMov + + +local lastkeys= input.get() +--***************************************************************************** +local function KeyReader() +--***************************************************************************** + if fc ~= movie.framecount() then --Egad, panic! New frame! Handle it!! + FixSubs() -- Whew. Problem solved. + + else -- Oh? Don't panic then + + local keys= input.get() + for k,v in pairs(keys) do + if not lastkeys[k] then + if k == BypassFrameAdvanceKey then + --... It's a bypass. Don't process. + elseif KeyFunctions[k] then + KeyFunctions[k]() + else + local ThisKey= k + if keys.shift then ThisKey= string.upper(ThisKey) + else ThisKey= string.lower(ThisKey) end + if KeyTable[ThisKey] then + CurrentStr= CurrentStr .. KeyTable[ThisKey] + end + end + end + end + GhostifySubs() + + lastkeys= keys + + end -- New frame test + +end + +--***************************************************************************** +local function Ex() +--***************************************************************************** + if SaveOnExit then + if not SaveToTxt() then + print("Dumping subtitles in message box instead!") + print("===========================") + local S= GetSortedSubs() + for i= 1, #fr do + print("subtitle",S[i],WordyWords[S[i]]) + end + end + end +end + +--***************************************************************************** +local function Bfr() +--***************************************************************************** + AmIClicked= false + + if CurrentStr ~= "" then + LastSubfc= fc + LastSub= CurrentStr + end + + FixSubs() +end + +gui.register(KeyReader) +emu.registerbefore(Bfr) +emu.registerexit(Ex) \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/TeenageMutantNinjaTurtles.lua b/branches/fceux-2.2.2/output/luaScripts/TeenageMutantNinjaTurtles.lua new file mode 100644 index 00000000..56463b78 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/TeenageMutantNinjaTurtles.lua @@ -0,0 +1,52 @@ +-- Teenage Mutant Ninja Turtles (U)[!].rom +-- Written by QFox +-- 31 july 2008 +-- Displays Hitboxes, Enemy HP, and various stats on screen + +local function box(x1,y1,x2,y2,color) + -- gui.text(50,50,x1..","..y1.." "..x2..","..y2); + if (x1 > 0 and x1 < 255 and x2 > 0 and x2 < 255 and y1 > 0 and y1 < 241 and y2 > 0 and y2 < 241) then + gui.drawbox(x1,y1,x2,y2,color); + end; +end; +local function text(x,y,str) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.text(x,y,str); + end; +end; +local function pixel(x,y,color) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.drawpixel(x,y,color); + end; +end; + +while (true) do + local stuff = 0x023C; -- start of tile data, 4 bytes each, y, ?, ?, x. every tile appears to be 10x10px + -- print boxes for all the tiles + -- invalid tiles are automatically hidden because their x/y coords are out of range, i guess + for i=0,0x30 do + x = memory.readbyte(stuff+3+(i*4)); + y = memory.readbyte(stuff+(i*4)); + box(x,y+1,x+7,y+16,"red"); + end; + + -- print player's health + local x = memory.readbyte(0x0480); + local y = memory.readbyte(0x0460); + local hp = memory.readbyte(0x0077+memory.readbyte(0x0067)); -- get health of current char, there are 4 chars and 4 healths + text(x-10,y-20,hp); + + -- print enemy hp + local startx = 0x0484; + local starty = 0x0464; + local starthp = 0x0564; + for i=0,11 do + x = memory.readbyte(startx+i); + y = memory.readbyte(starty+i); + hp = memory.readbyte(starthp+i); + --box(x-5,y-5,x+5,y+5,"green"); -- their 'center', or whatever it is. + text(x-5,y-20,hp); + end; + + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/UsingLuaBot-Documentation.txt b/branches/fceux-2.2.2/output/luaScripts/UsingLuaBot-Documentation.txt new file mode 100644 index 00000000..ed39731a --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/UsingLuaBot-Documentation.txt @@ -0,0 +1,140 @@ +LuaBot +Documentation +Written by Qfox + + +LuaBot is a trial and error script that exhausts the input-search-space by simply trying to push buttons. + +You can program it to limit this searchspace, as it can become exponentially large. Just do the math. You can press eight possible buttons at any frame. That makes up for 8! or 8*7*6*5*4*3*2*1 possible combinations for one single frame. There are 60 frames in one second, that's 60 to the power of (8!). + +Anyways, the bot has two parts. The frontend, which we'll call BeeBee, and the Lua part, which we call LuaBot. + +You start the bot by openening the luabot_front.lua script file. Make sure the luabot_backend.lua file is in the same directory. + +BeeBee + +BeeBee (who received it's name from BasicBot, its predecessor) just writes it's contents into the LuaBot framework and produces a big Lua script for you. +All you need to do is enter Lua code for the specific functions and the code will generate the script. + +You can also save and load the contents of the front-end. That way you can easily manage your bot scripts, without actually having to look into the LuaBot code. + +BeeBee is only a pasting mechanism. It does not compile Lua or warn for errors. + +LuaBot + +LuaBot is a generic trial-and-error script that serves as a bot framework. It will set inputs as you program them for a number of frames (called an attempt). When the isAttemptEnd() says the attempt ends, a new attempt is started. All the attempts fall under one segment. At the end of a segment (denoted by the isSegmentEnd() function), the best attempt is kept (judged by the score and tie functions) and the next segment is started. The bot is capable of rolling back if a segment runs into a dead end. This allows you to backtrack and restart a previous segment. + +The bot evaluates a true or false by checking to see whether the return value of a function is bigger then a certain value. It does this for EVERY function that returns something and every function that returns something must return a number (or Lua _will_ complain). For absolute true or false you can return "yes" and "no", "maxvalue" and "minvalue" or "pressed" and "released". Read variable info for more information. + +The script takes a number of variables and functions into account. Some variables become important to prevent desyncing over segments. + +- maxvalue +The maximum value (exclusive) of the random evaluation. If a value is higher than rand(minvalue, maxvalue), it evaluates as true, else false. By default this is set to 100. + +- minvalue +The lowest value (inclusive) of the random evaluation. If a value is lower than rand(minvalue, maxvalue), it evaluates to false, else true. By default this is set to 0. + +- yes / no +- pressed / released +These map to the minvalue/maxvalue. + +- loopcounter +The number of times a frameadvance has been called by the main botloop. + +- key1 key2 key3 key4 +The input table of players 1-4. The keys are: A B up down left right select start. Set any to 1 if you want them to be set and to nil if you don't want them set. +Note that these get cleared right before onInputStart is called. This variable is saved in a pseudo-movie table if the attempt is better then the previous one and used for playback when moving to the next segment. + +- lastkey1 lastkey2 lastkey3 lastkey4 +The inputs that were given to FCEU on the PREVIOUS frame. This holds for segments as well (at the beginning of a new segment, the lastkeys of the previous segment are set). This also goes for the start. If you use key1-4 in onStart, the first segment will have those keys as lastkey. + +- frame +The number of frames of the current attempt. Starts at 1. + +- attempt +The number of attempts in the current segment. Starts at 1. + +- segment +The segment the bot is currently running. Note that rolledback segments are deducted from this number. + +- okattempts +The number of attempts that have been deemed ok. This is a statistical variable. It might tell you how well your bot is doing (combined with the number of failed attempts). + +- failattempts +The number of attempts in the current segment that have been deemed bad. This is a statistical variable. It might tell you how well your bot is doing (combined with the number of approved attempts). + +- segments +This is the big table that holds everything together. Don't mess with it. + +- maxframes +You can set maxframes and check it in the isAttemptEnd function to simply limit a attempt by this many frames. You can also just ignore this and do something else instead. + +- maxattempts +Same as maxframes, except for attempts in a segment. + +- maxsegments +Same as maxframes, except for segments in a run. + +- playingbest +Will be set to true when the bot is playing back it's best attempt to advance to the next segment. Not really used by other functions. + +- keyrecording1-4 +A simple table with the pressed keys for playback. + +- X Y Z P Q +Some "static" variables. These allow you to easily set them onStart and use them in various functions to return the same number. Like a global variable. The P and Q numbers used to denote a random number between 0 and P or Q, but they don't right now. + +- vars +This is your variable table. It's contents is saved at the end of an attempt and will be loaded at the beginning of a segment. On rollback, this table is also kept. Put any variable you want to keep accross segments in this table. + + +Ok. That's it for the variables. Now for functions. There are basically three types of functions. The functions that determine whether a button is pressed (8 for each player), to determine whether an attempt/segment/run has ended or was ok and functions for certain events. This number is not evaluated by the random-eval function. + +- getScore +This returns how "well" the current attempt is. At the end of a segment, the best scoring good attempt will be used to continue to the next segment. In case of a tie, see the tie functions. This number is not evaluated by the random-eval function! + +- getTie1-4 +If the score ends in a tie, that is, two attempts score equally well (have an equal number of points for instance), you can use these functions to break that tie. Like, which attempt has the most health or is the fastest or whatever. This number is not evaluated by the random-eval function! + +- isRunEnd +Return whether the bot should stop running. If the returned number is bigger then the random number rand(minvalue-maxvalue), the bot will stop. + +- mustRollBack +Returns whether the bot should rollback the current attempt. In such case, the previous segment is loaded and the current segment is completely discarded. If the returned number is bigger then the random number rand(minvalue-maxvalue), the segment will rollback one segment. + +- isSegmentEnd +If the returned number is bigger then the random number rand(minvalue-maxvalue), the bot will stop the current segment, play back the best recorded attempt and start a new segment. Mostly done when a certain number of attempts is reached, but possibly you know when have the best possible attempt and can move on. + +- isAttemptEnd +If the returned number is bigger then the random number rand(minvalue-maxvalue), the attempt will stop and a new attempt will be started. Some examples when this function should return yes is when you reached a certain goal, a number of frames or when you died (in which case the bot should try again :). + +- isAttemptOk +If the returned number is bigger then the random number rand(minvalue-maxvalue), the current attempt (which has just ended) is deemed ok. Only attempts that are deemed ok are up for being saved. For instance, when the player died in the current attempt, you should return no. + +- pressKeyX (pressKeyA1, pressKeyStart4, etc...) +These functions determine whether a button should be pressed in the next frame. If the returned number is bigger then the random number rand(minvalue-maxvalue), the button is pressed, otherwise it is not. To absolutely press a button, simply return yes or no. To use some odds, return a number between minvalue and maxvalue. For instance, using the default settings, if you return 50, there is a 50% chance the button will be pressed. + +- onStart +Maybe a little misleading, but the onStart function is called BEFORE the main botloop starts. You can do some non-generic startup stuff here like press start at the title screen and get the game started. Returns nothing. + +- onFinish +The opposite to onStart, this function is called when the main botloop exits. You can cleanup, or write stuff or whatever. + +- onSegmentStart +When a new segment is started, this is called. After initializing variables and such, but before onAttemptStart is called. Returns nothing. + +- onSegmentEnd +When isSegmentEnd evaluates to true, this function is called. Returns nothing. + +- onAttemptStart +Called at the start of a new attempt, after onSegmentStart (in case of a new segment) but before onInputStart. Returns nothing. + +- onAttemptEnd(wasOk) +Called at the end of an attempt. The only function to have a parameter (note: case sensitive). The parameter wasOk will return (boolean) whether isAttemptOk evaluated to true or false. Returns nothing. + +- onInputStart +In a frame, this is the first place where the key1-4 variables are cleared. This is called before all the input (pressKeyX) functions are called. Returns nothing. + +- onInputEnd +This is called immediately after the input (pressKeyX) functions have been called. Returns nothing. + diff --git a/branches/fceux-2.2.2/output/luaScripts/UsingLuaScripting-Documentation.txt b/branches/fceux-2.2.2/output/luaScripts/UsingLuaScripting-Documentation.txt new file mode 100644 index 00000000..4ea1e75f --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/UsingLuaScripting-Documentation.txt @@ -0,0 +1,203 @@ +Learning to use Lua Sctripting for FCEUX +Written by QFox + +This is a document designed primarily to help someone use FCEUX specific commands with LUA, and tends to assume that you have some programming experience. It is best used for basic coding reference, and it is not comprehensive, in that there are a large number of things that LUA can do which aren't mentioned here. For a broad overview of the LUA language, check here: + +The Manual: (Good for learning LUA's basic capabilities, but you don't need to learn it all before using LUA) +http://www.lua.org/manual/ + +Programming in LUA: (Good for finding exact coding syntax, such as for LUA arrays, or to get coding examples) +http://www.lua.org/pil/ + +Other .lua files: +Don't be afraid to copy, look through, and break existing .lua scripts in order to make your own. Taking a piece of other people's code and learning how it works, modifying it, or outright duplicating it for your own project generally isn't frowned upon, as long as you know that what you release may eventually be used by others for their projects. + +Windows users - see also the Lua Scripting chapter for the FCEUX sHelp manual (fceux.chm) + +Ok. Lua. Let's see. + +Lua is a scripting language. It is used in games like Farcry and World of Warcraft (and many other games and applications!). Even though you can find all kinds of tutorials online, let me help you with the basics. + +I will asume you are at least somewhat familiar with the basics of programming. So basic stuff like arrays, variables, strings, loops and if-then-else and branching are not explained here. + +A hello world EmuLua program looks like this: + +while (true) do + gui.text(50,50,"Hello world!"); + FCEU.frameadvance(); +end; + +When you load the script, the emulator will sort of go into pause mode and hand controls over to Lua (you!). Hence you are responsible for frameadvancing the emulator. +IF YOU DO NOT CALL FCEU.frameadvance AT THE CYCLE OF THE MAIN LOOP YOU WILL FREEZE THE EMULATOR! There. You have been warned. Don't worry though, you'll make this mistake at least once. Just force-quit the application and try again :) + +Now then. Just like any other language, Lua has a few quirks you should be aware of. + +First of all, if's require a then and end. After a couple of days intensive Lua coding, I still make this mistake myself, but the Lua interpreter will prompt you of such errors on load, so don't worry too much about it. So: + +if (something) then + dostuff +end; + +Lua uses nil instead of null. + +There are only two values that evaluate to "false", these are "nil" and "false". ANYTHING else will evaluate to true, even 0 or the empty string. + +Comments are denoted by two consecutive dashes; --. Anything after it on the same line is a comment and ignored by Lua. There is no /* */ type of commenting in Lua. + +Variables have a local and global scope. You explicitly make a variable local by declaring it with the "local" keyword. + +somethingglobal; -- accessible by any function or flow +local something; -- only known to the same or deeper scope as where it was declared + +Note that variables declared in for loops (see below) are always considered local. + +Arrays are called tables in Lua. To be more precise, Lua uses associative arrays. + +Do not rely on the table.length() when your table can contain nil values, this function stops when it encounters a nil value, thus possibly cutting your table short. + +One experienced programmers will have to get used to is the table offset; tables start at index 1, not 0. That's just the way it is, deal with it. + +There are a few ways to create a table: + +local tbl1 = {}; -- empty table +local tbl2 = {"a","b","c","d"}; -- table with 5 strings +local tbl3 = {a=1,b=2,c=3}; -- associative table with 3 numbers +local tbl4 = {"a",b=2,c="x","d"=5}; -- associative table with mixed content + +Note that you can mix up the data in one table, as shown by tbl4. + +You can refer to table values in a few equivalent manners, using the examples above: + +tbl1[1] -- = nil because tbl1 is empty +tbl2[2] -- = "b" +tbl3["a"] -- = 1 +tbl4.b -- = 2 +tbl2.3 -- = "c" + +When the argument of a function is just a table, the parantheses "()" are optional. So for instance: + +processTable({a=2,b=3}); + +Is equivalent to + +processTable{a=2,b=3}; + +Another notation that's equivalent is + +filehandle.read(filehandle, 5); +filehandle:read(5); + +When using the colon notation ":" Lua will call the function adding the self-reference to the front of the parameterstack. + +Functions behave like objects and are declared in the follow manner: + +function doSomething(somevalue, anothervalue) + dostuffhere +end; + +So no curly braces "{}" ! + +Some flow control: + +for i=0,15 do + -- do stuff here, i runs from 0 to 15 (inclusive!) +end; + +for key,value in pairs(table) do + -- do stuff here. pairs will iterate through the table, splitting the keys and values +end; + +while (somethingistrue) do + +end; + +if (somethingistrue) then + +end; + +if (somethingistrue) then + +else + +end; + +if (somethingistrue) then + +elseif (somethingelseistrue) then + +end; + +For comparison, you only have to remember that the exclamationmark is not used. Not equal "!=" is written like tilde-equals "~=" and if (!something) then ... is written with "not " in front of it; if (not something) then... + +For easy reference to the standard libraries look on the bottom half of this page: http://www.lua.org/manual/5.1/ + + +Now then, let's get to the emulator specifics! + +To load a Lua script in FCEU first load a rom (Lua can only do things after each frame cycle so load a rom first). Go to file, at the bottom choose Run Lua Script and select and load the file. + +When Lua starts, the emulator pauses and hands control over to Lua. Lua (that's you!) decides when the next frame is processed. That's why it's very common to write an endless while loop, exiting the main loop of a script will exit the script and hand control back to the emulator. This also happens when a script unexpectingly crashes. + +A bare script looks like this: + +while (true) do + FCEU.frameadvance(); +end; + +And is about equal to not running Lua at all. The frameadvance function is the same called internally, so no loss of speed there! + +Bitwise operators: + +Lua does not have bitwise operators, so we supply some for you. These are common bitwise operators, nothing fancy. + +AND(a,b); +OR(a,b); +XOR(a,b); +BIT(n); -- returns a number with only bit n set (1) + +The emulator specific Lua is equal to the one of snes9x, with some platform specific changes (few buttons, for instance). +You can find the reference here: http://dehacked.2y.net/snes9x-lua.html +The following is a quick reference, you can go to the snes9x reference for more details. + +To paint stuff on screen, use the gui table. This contains a few predefined functions to manipulate the main window. For any coordinate, 0,0 is the top-left pixel of the window. You have to prevent out-of-bound errors yourself for now. If a color can be passed on, it is a string. HTML-syntax is supported ("#34053D"), as well as a FEW colors ("red", "green", "blue" ...). + +gui.text(x, y, str); -- Print a line to the window, you can use \n for a return but it will only work once +gui.drawpixel(x, y, color); -- plot a pixel at the given coordinate +gui.drawline(x1, y1, x2, y2, color); -- plot a line from x1,y1 to x2,y2 +gui.drawbox(x1, y1, x2, y2, color); -- draw a square from x1,y1 to x2,y2 +gui.popup(str); -- pops up a messagebox informing the user of something. Real handy when debugging! +gui.getpixel(x,y); -- return the values of the pixel at given position. Returns three numbers of the emulator image before paiting is applied. +gui.gdscreenshot(); -- Takes a screen shot of the image and returns it in the form of a string which can be imported by the gd library using the gd.createFromGdStr() function +(for more gd functions see DeHackED's reference: http://dehacked.2y.net/snes9x-lua.html) + +PAINTING IS ALWAYS ONE FRAME BEHIND! This is because the painting is done at the creation of the next frame, not while Lua is running. + +Emulator control: + +FCEU.frameadvance(); -- advances emulation ONE frame +FCEU.pause(); -- same as pressing the pause button +FCEU.speedmode(strMode); -- Supported are "normal","turbo","nothrottle","maximum". But know that except for "normal", all other modes will run as "turbo" for now. +FCEU.wait(); -- skips the emulation of the next frame, in case your script needs to wait for something + +Memory control: + +memory.readbyte(adr); -- read one byte from given address and return it. Besides decimal values Lua also allows the hex notation 0x00FA. In FCEUX reading is done BEFORE the cheats are applied! +memory.writebyte(adr, value); -- write one byte to the RAM of the NES. writing is done AFTER the hexeditor receives its values, so if you are freezing an address by Lua, it will not show in the hex editor (but it will in the game :) +memory.readbytesigned(adr); -- same as readbyte, except this returns a signed value, rather then an unsigned value. +memory.register(adr, function); -- binds a function to an address. The function will be called when an address changes. NOTE THAT THIS IS EXPENSIVE (eg.: slow)! Only one function allowed per address. + +Input control: + +You can read and write input by using the joypad table. A input table has the following (case sensitive) keys, where nil denotes they are not to be pressed: up down left right start select A B + +joypad.read(playern); -- get the input table for the player who's input you want to read (a number!) +joypad.write(playern, inputtable); -- set the input for player n. Note that this will overwrite any input from the user, and only when this is used. + +Savestates: + +You can load and save to the predefined savestates 1 ... 9 or create new "anonymous" savestates. You must first create a savestate object, which is your handle to a savestate. Then you can pass this handle on to savestate.load or save to do so. + +savestate.create(n); -- n is optional. When supplied, it will create a savestate for slot n, otherwise a new (anonymous) savestate object is created. Note that this does not yet save or load anything! +savestate.load(state); -- load the given savestate +savestate.save(state); -- save the given savestate + diff --git a/branches/fceux-2.2.2/output/luaScripts/UsingLuaScripting-ListofFunctions.txt b/branches/fceux-2.2.2/output/luaScripts/UsingLuaScripting-ListofFunctions.txt new file mode 100644 index 00000000..5583649b --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/UsingLuaScripting-ListofFunctions.txt @@ -0,0 +1,316 @@ +Library Listing of FCEUX Lua Functions +Written by adelikat/QFox + +FCEU library + +FCEU.poweron() + +Executes a power cycle. + +FCEU.softreset() + +Executes a (soft) reset. + +FCEU.speedmode(string mode) + +Set the emulator to given speed. The mode argument can be one of these: + - "normal" + - "nothrottle" (same as turbo on fceux) + - "turbo" + - "maximum" + +FCEU.frameadvance() + +Advance the emulator by one frame. It's like pressing the frame advance button once. + +Most scripts use this function in their main game loop to advance frames. Note that you can also register functions by various methods that run "dead", returning control to the emulator and letting the emulator advance the frame. For most people, using frame advance in an endless while loop is easier to comprehend so I suggest starting with that. This makes more sense when creating bots. Once you move to creating auxillary libraries, try the register() methods. + +FCEU.pause() + +Pauses the emulator. FCEUX will not unpause until you manually unpause it. + +FCEU.exec_count() + + + +FCEU.exec_time() + + + +FCEU.setrenderplanes(bool sprites, bool background) + +Toggles the drawing of the sprites and background planes. Set to false or nil to disable a pane, anything else will draw them. + +FCEU.message(string message) + +Displays given message on screen in the standard messages position. Use gui.text() when you need to position text. + +int FCEU.lagcount() + +Return the number of lag frames encountered. Lag frames are frames where the game did not poll for input because it missed the vblank. This happens when it has to compute too much within the frame boundary. This returns the number indicated on the lag counter. + +bool FCEU.lagged() + +Returns true if currently in a lagframe, false otherwise. + +bool FCEU.getreadonly() + +Returns whether the emulator is in read-only state. + +While this variable only applies to movies, it is stored as a global variable and can be modified even without a movie loaded. Hence, it is in the FCEU library rather than the movie library. + +FCEU.setreadonly(bool state) + +Sets the read-only status to read-only if argument is true and read+write if false. +Note: This might result in an error if the medium of the movie file is not writeable (such as in an archive file). + +While this variable only applies to movies, it is stored as a global variable and can be modified even without a movie loaded. Hence, it is in the FCEU library rather than the movie library. + + +ROM Library + +rom.readbyte(int address) + +Get an unsigned byte from the actual ROM file at the given address. + +This includes the header! It's the same as opening the file in a hex-editor. + +rom.readbytesigned(int address) + +Get a signed byte from the actual ROM faile at the given address. Returns a byte that is signed. + +This includes the header! It's the same as opening the file in a hex-editor. + + +Memory Library + +memory.readbyte(int address) + +Get an unsigned byte from the RAM at the given address. Returns a byte regardless of emulator. The byte will always be positive. + +memory.readbyterange(int address, int length) + +Get a length bytes starting at the given address and return it as a string. Convert to table to access the individual bytes. + +memory.readbytesigned(int address) + +Get a signed byte from the RAM at the given address. Returns a byte regardless of emulator. The most significant bit will serve as the sign. + +memory.writebyte(int address, int value) + +Write the value to the RAM at the given address. The value is modded with 256 before writing (so writing 257 will actually write 1). Negative values allowed. + +memory.register(int address, function func) + +Register an event listener to the given address. The function is called whenever write occurs to this address. One function per address. Can be triggered mid-frame. Set to nil to remove listener. Given function may not call frame advance or any of the savestate functions. Joypad reading/writing is undefined (so don't). + +Note: this is slow! + + +Joypad Library + +table joypad.read(int player) + +Returns a table containing the buttons pressed by the given player. This takes keyboard inputs, not Lua. The table keys look like this (case sensitive): + +up, down, left, right, A, B, start, select + +Where a Lua truthvalue true means that the button is set, false means the button is unset. Note that only "false" and "nil" are considered a false value by Lua. Anything else is true, even the number 0. + +joypad.set(int player, table input) + +Set the inputs for the given player. Table keys look like this (case sensitive): + +up, down, left, right, A, B, start, select + +There are 3 possible values, true, false, and nil. True will turn the button on, false will turn it off. Nil will leave it unchanged (allowing the user to control it). + +table joypad.get() + +A alias of joypad.read(). Left in for backwards compatibility with older versions of FCEU/FCEUX. + +joypad.write() + +A alias of joypad.set(). Left in for backwards compatibility with older versions of FCEU/FCEUX. + + +Zapper Library + +table zapper.read() + +Returns the mouse data (which is used to generate zapper input, as well as the arkanoid paddle). + +The return table consists of 3 values: xmouse, ymouse, and click. xmouse and ymouse are the x,y coordinates of the cursor in terms of pixels. click represents the mouse click. 0 = no click, 1 = left cick, 2 = right click. + +Currently, zapper data is ignored while a movie is playing. + +Note: The right-click isn't used in zapper data +Note: The zapper is always controller 2 on the NES so there is no player argument to this function. + + +Input Library + +table input.get() + +Reads input from keyboard and mouse. Returns pressed keys and the position of mouse in pixels on game screen. The function returns a table with at least two properties; table.xmouse and table.ymouse. Additionally any of these keys will be set to true if they were held at the time of executing this function: +leftclick, rightclick, middleclick, capslock, numlock, scrolllock, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24, backspace, tab, enter, shift, control, alt, pause, escape, space, pageup, pagedown, end, home, left, up, right, down, numpad0, numpad1, numpad2, numpad3, numpad4, numpad5, numpad6, numpad7, numpad8, numpad9, numpad*, insert, delete, numpad+, numpad-, numpad., numpad/, semicolon, plus, minus, comma, period, slash, backslash, tilde, quote, leftbracket, rightbracket. + +Savestate Library + +object savestate.create(int slot = nil) + +Create a new savestate object. Optionally you can save the current state to one of the predefined slots (0...9), otherwise you'll create an "anonymous" savestate. +Note that this does not actually save the current state! You need to create this value and pass it on to the load and save functions in order to save it. + +Anonymous savestates are temporary, memory only states. You can make them persistent by calling memory.persistent(state). Persistent anonymous states are deleted from disk once the script exits. + +savestate.save(object savestate) + +Save the current state object to the given savestate. The argument is the result of savestate.create(). You can load this state back up by calling savestate.load(savestate) on the same object. + +savestate.load(object savestate) + +Load the the given state. The argument is the result of savestate.create() and has been passed to savestate.save() at least once. + +If this savestate is not persistent and not one of the predefined states, the state will be deleted after loading. + +savestate.persist(object savestate) + +Set the given savestate to be persistent. It will not be deleted when you load this state but at the exit of this script instead, unless it's one of the predefined states. If it is one of the predefined savestates it will be saved as a file on disk. + + +Movie Library + +bool movie.active() + +Returns true if a movie is currently loaded and false otherwise. (This should be used to guard against Lua errors when attempting to retrieve movie information). + +int movie.framecount() + +Returns the framecount value. The frame counter runs without a movie running so this always returns a value. + +string movie.mode() + +Returns the current state of movie playback. Returns one of the following: + +- "record" +- "playback" +- nil + +movie.rerecordcounting(bool counting) + +Turn the rerecord counter on or off. Allows you to do some brute forcing without inflating the rerecord count. + +movie.stop() + +Stops movie playback. If no movie is loaded, it throws a Lua error. + +int movie.length() + +Returns the total number of frames of the current movie. Throws a Lua error if no movie is loaded. + +string movie.getname() + +Returns the filename of the current movie. Throws a Lua error if no movie is loaded. + +movie.rerecordcount() + +Returns the rerecord count of the current movie. Throws a Lua error if no movie is loaded. + +movie.playbeginning() + +Performs the Play from Beginning function. Movie mode is switched to read-only and the movie loaded will begin playback from frame 1. + +If no movie is loaded, no error is thrown and no message appears on screen. + + +GUI Library + +gui.drawpixel(int x, int y, type color) + +Draw one pixel of a given color at the given position on the screen. See drawing notes and color notes at the bottom of the page. + +gui.drawline(int x1, int y1, int x2, int y2, type color) + +Draws a line between the two points. See also drawing notes and color notes at the bottom of the page. + +gui.drawbox(int x1, int y1, int x2, int y2, type color) + +Draw a box with the two given opposite corners. +Also see drawing notes and color notes. + +gui.text(int x, int y, string str) + +Draws a given string at the given position. + +string gui.gdscreenshot() + +Takes a screen shot of the image and returns it in the form of a string which can be imported by the gd library using the gd.createFromGdStr() function. + +This function is provided so as to allow FCEUX to not carry a copy of the gd library itself. If you want raw RGB32 access, skip the first 11 bytes (header) and then read pixels as Alpha (always 0), Red, Green, Blue, left to right then top to bottom, range is 0-255 for all colors. + +Warning: Storing screen shots in memory is not recommended. Memory usage will blow up pretty quick. One screen shot string eats around 230 KB of RAM. + +gui.gdoverlay(int x = 0, int y = 0, string dgimage) + +Overlay the given image on the emulator. Transparency is absolute (any pixel not 100% transparent is completely opaque). The image must be gd file format version 1, true color. Image will be clipped to fit. + +gui.transparency(int strength) + +Set the transparency level for subsequent painting (including gdoverlay). Does not stack. +Values range from 0 to 4. Where 0 means completely opaque and 4 means completely transparent. + +function gui.register(function func) + +Register a function to be called between a frame being prepared for displaying on your screen and it actually happening. Used when that 1 frame delay for rendering is not acceptable. + +string gui.popup(string message, string type = "ok") + +Shows a popup. Default type is "ok". Can be one of these: + +- "ok" - "yesno" - "yesnocancel" +Returns "yes", "no" or "cancel" indicating the button clicked. + +Linux users might want to install xmessage to perform the work. Otherwise the dialog will appear on the shell and that's less noticeable. + + +Bitwise Operations + +int AND(int n1, int n2, ..., int nn) + +Binary logical AND of all the given integers. This function compensates for Lua's lack of it. + +int OR(int n1, int n2, ..., int nn) + +Binary logical OR of all the given integers. This function compensates for Lua's lack of it. + +int XOR(int n1, int n2, ..., int nn) + +Binary logical XOR of all the given integers. This function compensates for Lua's lack of it. + +int BIT(int n1, int n2, ..., int nn) + +Returns an integer with the given bits turned on. Parameters should be smaller than 31. + + +Appendix + +On drawing + +A general warning about drawing is that it is always one frame behind unless you use gui.register. This is because you tell the emulator to paint something but it will actually paint it when generating the image for the next frame. So you see your painting, except it will be on the image of the next frame. You can prevent this with gui.register because it gives you a quick chance to paint before blitting. + +Dimensions & color depths you can paint in: +320x239, 8bit color (confirm?) + +On colors + +Colors can be of a few types. +Int: use the a formula to compose the color as a number (depends on color depth) +String: Can either be a HTML color or simple colors. +HTML string: "#rrggbb" ("#228844") or #rrggbbaa if alpha is supported. +Simple colors: "clear", "red", "green", "blue", "white", "black", "gray", "grey", "orange", "yellow", "green", "teal", "cyan", "purple", "magenta". + +For transparancy use "clear", this is actually int 1. + + + diff --git a/branches/fceux-2.2.2/output/luaScripts/ZapperDisplay.lua b/branches/fceux-2.2.2/output/luaScripts/ZapperDisplay.lua new file mode 100644 index 00000000..51bc4aab --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/ZapperDisplay.lua @@ -0,0 +1,33 @@ +--Zapper display +--written by adelikat +--Purpose: To show the target of the zapper on screen +-- Primary use is for fullscreen where the mouse cursor is disabled + +local zap --get zapper.read() values +local color = "white" --color of outside bull's eye circles + +while true do + +zap = zapper.read() + +--Red if firing +if (zap.click == 1) then + color = "red" +else + color = "white" +end + +--gui.text(1,1,"X: " .. zap.x) +--gui.text(1,9,"Y: " .. zap.y) +--gui.text(1,17,"Click: " .. zap.fire) + +--Draw bull's eye +gui.box(zap.x-1,zap.y-1,zap.x+1,zap.y+1,"clear","red") +gui.box(zap.x-6,zap.y-6,zap.x+6,zap.y+6,"clear",color) +gui.box(zap.x-12,zap.y-12,zap.x+12,zap.y+12,"clear",color) +gui.line(zap.x-12,zap.y-12,zap.x+12,zap.y+12,color) +gui.line(zap.x+12,zap.y-12,zap.x-12,zap.y+12,color) +gui.pixel(zap.x,zap.y,"red") + +emu.frameadvance() +end \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/ZapperFun.lua b/branches/fceux-2.2.2/output/luaScripts/ZapperFun.lua new file mode 100644 index 00000000..ab3dc4ae --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/ZapperFun.lua @@ -0,0 +1,72 @@ +-- Zapper Fun +-- quick and dirty script that shows zapper position and fire button presses in FCEUX +-- Written by miau +-- http://morphcat.de/lua/ + +local Z_LSPAN = 20 --life span (in frames) of white box +local Z_LSPAN_CLICK = 30 --life span of red box +local Z_MAX = 60 --maximum amount of boxes on screen + +local zbuf = {} +local zindex = 1 +local timer = 0 +local lastclick = zapper.read().fire +local lastx = zapper.read().x +local lasty = zapper.read().y + +function zapper_addcoord(x,y,click) + zbuf[zindex] = {t=timer,x=x,y=y,click=click} + zindex = zindex + 1 + if(zindex>Z_MAX) then + zindex = 1 + end +end + +function box(x1,y1,x2,y2,color1,color2) + if(x1>=0 and y1>=0 and x2<=255 and y2<=255) then + gui.drawbox(x1, y1, x2, y2, color1, color2) + end +end + + + + while(true) do + local x = zapper.read().x + local y = zapper.read().y + local click = zapper.read().fire + --gui.text(0, 8, string.format("x=%d",x)); + --gui.text(0, 18, string.format("y=%d",y)); + --gui.text(0, 28, string.format("click=%d",click)); + if(click==1 and click~=lastclick) then + zapper_addcoord(x,y,1) + elseif(x~=lastx or y~=lasty) then + zapper_addcoord(x,y,0) + end + lastclick=click + lastx=x + lasty=y + box(x-3, y-3, x+3, y+3, "white", 0) + + for i=1,Z_MAX do + if(zbuf[i]) then + ltime = timer-zbuf[i].t + if(zbuf[i].click==0) then + if(ltime= maxvalue) then return true; end; + if (n > math.random(minvalue, maxvalue-1)) then return true; end; + return false; +end; + +local loopcounter = 0; -- counts the main loop +local key1 = {}; -- holds the to be pressed keys this frame for player 1 +local key2 = {}; -- holds the to be pressed keys this frame for player 2 +local key3 = {}; -- holds the to be pressed keys this frame for player 3 +local key4 = {}; -- holds the to be pressed keys this frame for player 4 +local lastkey1 = {}; -- keys pressed in previous frame for player 1 +local lastkey2 = {}; -- keys pressed in previous frame for player 2 +local lastkey3 = {}; -- keys pressed in previous frame for player 1 +local lastkey4 = {}; -- keys pressed in previous frame for player 2 +local frame = 0; -- number of frames (current value is current frame count, incremented at the start of a new frame) +local attempt = 1; -- number of attempts (current value is current attempt, incremented after the end of an attempt) +local segment = 1; -- number of segments (current value is current segment, incremented after the end of a segment) +local okattempts = 0; -- number of successfull attempts (including rollback) +local failattempts = 0; -- number of failed attempts (including rollback) + +local segments = {}; -- table that holds every segment, each segment is another table that consists of the score, ties, savestate (begin of segment), lastkeys, keys pressed, etc. +segments[1] = {}; -- initialize the first segment, we initialize the savestate right after the before code has ran + +-- these dont have to be used, but it makes it easier to control here +local maxframes = 400; +local maxattempts = 200; +local maxsegments = 100; + +local playingbest = false; -- when going to the next segment, we need to play the best segment to record, this indicates when we're doing so +local keyrecording1 = {}; -- every key pressed for player 1 is put in here +local keyrecording2 = {}; -- every key pressed for player 2 is put in here +local keyrecording3 = {}; -- every key pressed for player 3 is put in here +local keyrecording4 = {}; -- every key pressed for player 4 is put in here + +-- some constants/macro's/whatever to make source easier to read +local press = maxvalue; +local release = minvalue; +local yes = maxvalue; +local maybe = maxvalue/2; -- 50% +local no = minvalue; + +-- static constants, will be used by the frontend later +local X = 95; +local Y = 30; +local Z = 0; +local P = 0; +local Q = 0; + +local vars = {}; -- variable table. each cell holds a variable. variables are remembered accross segments + +-- user defined functions + +local function getScore() -- score of current attempt + local result = no; + -- SCORE + return result; +end; + +local function getTie1() -- tie breaker of current attempt in case score is equal + local result = no; + -- TIE1 + return result; +end; + +local function getTie2() -- second tie breaker + local result = no; + -- TIE2 + return result; +end; + +local function getTie3() -- third tie breaker + local result = no; + -- TIE3 + return result; +end; + +local function getTie4() -- fourth tie breaker + local result = no; + -- TIE4 + return result; +end; + +local function isRunEnd() -- gets called 3x! twice in the main loop (every frame). determines whether the bot should quit. + local result = no; + -- ISRUNEND + return result; +end; + +local function mustRollBack() -- drop back to previous segment? called at the end of a segment + local result = no; + -- MUSTROLLBACK + return result; +end; + +local function isSegmentEnd() -- end of current segment? (usually just x frames or being really stuck (to rollback)) + local result = no; + -- ISSEGMENTEND + return result; +end; + +local function isAttemptOk() -- is current run ok? like, did you die? (then the run is NOT ok... :). return no for no and yes for yes or be left by chance. + local result = yes; + -- ISATTEMPTOK + return result; +end; + +local function isAttemptEnd() -- end of current attempt? (like when you die or reach a goal) + local result = no; + -- ISATTEMPTEND + return result; +end; + +-- the next 2x8 functions determine whether a button should be pressed for player 1 and 2 +-- return yes or no for absolute values, return anything between minvalue and maxvalue +-- to set a chance of pressing that button. + +local function pressKeyA1() + local result = no; + -- bA1 + return result; +end; + +local function pressKeyB1() + local result = no; + -- bB1 + return result; +end; + +local function pressKeyStart1() + local result = no; + -- START1 + return result; +end; + +local function pressKeySelect1() + local result = no; + -- SELECT1 + return result; +end; + +local function pressKeyUp1() + local result = no; + -- UP1 + return result; +end; + +local function pressKeyDown1() + local result = no; + -- DOWN1 + return result; +end; + +local function pressKeyLeft1() + local result = no; + -- LEFT1 + return result; +end; + +local function pressKeyRight1() + local result = no; + -- RIGHT1 + return result; +end; + +local function pressKeyA2() + local result = no; + -- bA2 + return result; +end; + +local function pressKeyB2() + local result = no; + -- bB2 + return result; +end; + +local function pressKeyStart2() + local result = no; + -- START2 + return result; +end; + +local function pressKeySelect2() + local result = no; + -- SELECT2 + return result; +end; + +local function pressKeyUp2() + local result = no; + -- UP2 + return result; +end; + +local function pressKeyDown2() + local result = no; + -- DOWN2 + return result; +end; + +local function pressKeyLeft2() + local result = no; + -- LEFT2 + return result; +end; + +local function pressKeyRight2() + local result = no; + -- RIGHT2 + return result; +end; + +local function pressKeyA3() + local result = no; + -- bA3 + return result; +end; + +local function pressKeyB3() + local result = no; + -- bB3 + return result; +end; + +local function pressKeyStart3() + local result = no; + -- START3 + return result; +end; + +local function pressKeySelect3() + local result = no; + -- SELECT3 + return result; +end; + +local function pressKeyUp3() + local result = no; + -- UP3 + return result; +end; + +local function pressKeyDown3() + local result = no; + -- DOWN3 + return result; +end; + +local function pressKeyLeft3() + local result = no; + -- LEFT3 + return result; +end; + +local function pressKeyRight3() + local result = no; + -- RIGHT3 + return result; +end; + +local function pressKeyA4() + local result = no; + -- bA4 + return result; +end; + +local function pressKeyB4() + local result = no; + -- bB4 + return result; +end; + +local function pressKeyStart4() + local result = no; + -- START4 + return result; +end; + +local function pressKeySelect4() + local result = no; + -- SELECT4 + return result; +end; + +local function pressKeyUp4() + local result = no; + -- UP4 + return result; +end; + +local function pressKeyDown4() + local result = no; + -- DOWN4 + return result; +end; + +local function pressKeyLeft4() + local result = no; + -- LEFT4 + return result; +end; + +local function pressKeyRight4() + local result = no; + -- RIGHT4 + return result; +end; + +-- now follow the "events", one for the start and end of a frame, attempt, segment and whole bot. none of them need to return anything + +local function onStart() -- this code should run before the bot starts, for instance to start the game from power on and get setup the game + -- ONSTART +end; + +local function onFinish() -- code ran after the bot finishes + -- ONFINISH +end; + +local function onSegmentStart() -- code ran after initializing a new segment, before onAttemptStart(). framecount is always one fewer then actual frame! + -- ONSEGMENTSTART +end; + +local function onSegmentEnd() -- code ran after a segment finishes, before cleanup of segment vars + -- ONSEGMENTEND +end; + +local function onAttemptStart() -- code ran after initalizing a new attempt, before onInputStart(). not ran when playing back. framecount is always one fewer then actual frame! + -- ONATTEMPTSTART +end; + +local function onAttemptEnd(wasOk) -- code ran after an attempt ends before cleanup code, argument is boolean true when attempt was ok, boolean false otherwise. not ran when playing back + -- ONATTEMPTEND +end; + +local function onInputStart() -- code ran prior to getting input (keys are empty). not ran when playing back + -- ONINPUTSTART +end; + +local function onInputEnd() -- code ran after getting input (lastkey are still valid) (last function before frame ends, you can still manipulate the input here!). not ran when playing back + -- ONINPUTEND +end; + +-- the bot starts here.. (nothing is added from the user from this point onwards) + +onStart(); -- run this code first + +segments[segment].savestate = savestate.create(); -- create anonymous savestate obj for start of first segment +savestate.save(segments[segment].savestate); -- save current state to it, it will be reloaded at the start of each frame +local startkey1 = key1; -- save the last key pressed in the onStart. serves as an anchor for the first segment +local startkey2 = key2; +local startkey3 = key3; -- save the last key pressed in the onStart. serves as an anchor for the first segment +local startkey4 = key4; +local startvars = vars; -- save the vars array (it might have been used by the onStart) +lastkey1 = key1; -- to enter the loop... +lastkey2 = key2; +lastkey3 = key3; +lastkey4 = key4; +--FCEU.speedmode("maximum"); -- uncomment this line to make the bot run faster ("normal","turbo","maximum") + +onSegmentStart(); +onAttemptStart(); + +collectgarbage(); -- just in case... + +-- This will loops for each frame, at the end of the while +-- the frameadvance is called, causing it to advance +while (rand_if(isRunEnd())) do + loopcounter = loopcounter + 1; -- count the number of botloops + --gui.text(200,10,loopcounter); -- print it on the right side if you want to see the number of total frames + + if (not playingbest and rand_if(isAttemptEnd())) then -- load save state, continue with next attempt (disabled when playing back best) + -- record this attempt as the last attempt + if (not segments[segment].prev) then segments[segment].prev = {}; end; + segments[segment].prev.frames = frame; + segments[segment].prev.attempt = attempt; + segments[segment].prev.score = getScore(); + segments[segment].prev.tie1 = getTie1(); + segments[segment].prev.tie2 = getTie2(); + segments[segment].prev.tie3 = getTie3(); + segments[segment].prev.tie4 = getTie4(); + segments[segment].prev.ok = rand_if(isAttemptOk()); -- this is the check whether this attempt was valid or not. if not, it cannot become the best attempt. + -- update ok/failed attempt counters + if (segments[segment].prev.ok) then + okattempts = okattempts + 1; + onAttemptEnd(true); + else + failattempts = failattempts + 1; + onAttemptEnd(false); + end; + + -- if this attempt was better then the previous one, replace it + -- its a long IF, but all it checks (lazy eval) is whether the current + -- score is better then the previous one, or if its equal and the tie1 + -- is better then the previous tie1 or if the tie1 is equal to the prev + -- etc... for all four ties. Only tie4 actually needs to be better, tie1 + -- through tie3 can be equal as well, as long as the next tie breaks the + -- same tie of the previous attempt :) + if (segments[segment].prev.ok and (not segments[segment].best or (getScore() > segments[segment].best.score or (getScore() == segments[segment].best.score and (getTie1() > segments[segment].best.tie1 or (getTie1() == segments[segment].best.tie1 and (getTie1() > segments[segment].best.tie1 or (getTie1() == segments[segment].best.tie1 and (getTie1() > segments[segment].best.tie1 or (getTie1() == segments[segment].best.tie1 and getTie1() > segments[segment].best.tie1)))))))))) then + -- previous attempt was better then current best (or no current best + -- exists), so we (re)place it. + if (not segments[segment].best) then segments[segment].best = {}; end; + segments[segment].best.frames = segments[segment].prev.frames; + segments[segment].best.attempt = segments[segment].prev.attempt; + segments[segment].best.score = segments[segment].prev.score; + segments[segment].best.tie1 = segments[segment].prev.tie1; + segments[segment].best.tie2 = segments[segment].prev.tie2; + segments[segment].best.tie3 = segments[segment].prev.tie3; + segments[segment].best.tie4 = segments[segment].prev.tie4; + segments[segment].best.keys1 = keyrecording1; -- backup the recorded keys + segments[segment].best.keys2 = keyrecording2; -- backup the recorded keys player 2 + segments[segment].best.keys3 = keyrecording3; -- backup the recorded keys + segments[segment].best.keys4 = keyrecording4; -- backup the recorded keys player 2 + segments[segment].best.lastkey1 = lastkey1; -- backup the lastkey + segments[segment].best.lastkey2 = lastkey2; -- backup the lastkey + segments[segment].best.lastkey3 = lastkey3; -- backup the lastkey + segments[segment].best.lastkey4 = lastkey4; -- backup the lastkey + segments[segment].best.vars = vars; -- backup the vars table + end + + if (rand_if(isSegmentEnd())) then -- the current segment ends, replay the best attempt and continue from there onwards... + onSegmentEnd(); + if (rand_if(mustRollBack())) then -- rollback to previous segment + gui.text(50,50,"Rolling back to segment "..(segment-1)); + segments[segment] = nil; -- remove current segment data + attempt = 0; -- will be incremented in a few lines to be 1 + segment = segment - 1; + segments[segment].best = nil; + segments[segment].prev = nil; + collectgarbage(); -- collect the removed segment please + else + playingbest = true; -- this will start playing back the best attempt in this frame + end; + end; + + -- reset vars + attempt = attempt + 1; + frame = 0; + keyrecording1 = {}; -- reset the recordings :) + keyrecording2 = {}; + keyrecording3 = {}; + keyrecording4 = {}; + -- set lastkey to lastkey of previous segment (or start, if first segment) + -- also set the vars table to the table of the previous segment + if (segment == 1) then + lastkey1 = startkey1; + lastkey2 = startkey2; + lastkey3 = startkey3; + lastkey4 = startkey4; + vars = startvars; + else + lastkey1 = segments[segment-1].best.lastkey1; + lastkey2 = segments[segment-1].best.lastkey2; + lastkey3 = segments[segment-1].best.lastkey3; + lastkey4 = segments[segment-1].best.lastkey4; + vars = segments[segment-1].best.vars; + end; + -- load the segment savestate to go back to the start of this segment + if (segments[segment].savestate) then -- load segment savestate and try again :) + savestate.load(segments[segment].savestate); + else + fceu.crash(); -- this crashes because fceu is a nil table :) as long as gui.popup() doesnt work... we're crashing because no save state exists..? it should never happen. + end; + + if (rand_if(isRunEnd())) then break; end; -- if end of run, break out of main loop and run in end loop. + + if (not playingbest) then onAttemptStart(); end; -- only call this when not playing back best attempt. has decreased frame counter! + end; -- continues with (new) attempt + + -- increase framecounter _after_ processing attempt-end + frame = frame + 1; -- inrease the frame count (++frame?) + + if (playingbest and segments[segment].best) then -- press keys from memory (if there are any) + gui.text(10,150,"frame "..frame.." of "..segments[segment].best.frames); + if (frame >= segments[segment].best.frames) then -- end of playback, start new segment + playingbest = false; + lastkey1 = segments[segment].best.lastkey1; + lastkey2 = segments[segment].best.lastkey2; + lastkey3 = segments[segment].best.lastkey3; + lastkey4 = segments[segment].best.lastkey4; + vars = segments[segment].best.vars; + segment = segment + 1; + segments[segment] = {}; + -- create a new savestate for the start of this segment + segments[segment].savestate = savestate.create(); + savestate.save(segments[segment].savestate); + -- reset vars + frame = 0; -- onSegmentStart and onAttemptStart expect this to be one fewer... + attempt = 1; + + keyrecording1 = {}; -- reset recordings :) + keyrecording2 = {}; + keyrecording3 = {}; + keyrecording4 = {}; + -- after this, the next segment starts because playingbest is no longer true + onSegmentStart(); + onAttemptStart(); + frame = 1; -- now set it to 1 + else + key1 = segments[segment].best.keys1[frame]; -- fill keys with that of the best attempt + key2 = segments[segment].best.keys2[frame]; + key3 = segments[segment].best.keys3[frame]; + key4 = segments[segment].best.keys4[frame]; + gui.text(10,10,"Playback best of segment "..segment.."\nFrame: "..frame); + end; + end; + + if (rand_if(isRunEnd())) then break; end; -- if end of run, break out of main loop + -- note this is the middle, this is where an attempt or segment has ended if it would and started if it would! + -- now comes the input part for this frame + + if (not playingbest) then -- when playing best, the keys have been filled above. + -- press keys from bot + gui.text(10,10,"Attempt: "..attempt.." / "..maxattempts.."\nFrame: "..frame.." / "..maxframes); + if (segments[segment] and segments[segment].best and segments[segment].prev) then + gui.text(10,30,"Last score: "..segments[segment].prev.score.." ok="..okattempts..", fail="..failattempts.."\nBest score: "..segments[segment].best.score); + elseif (segments[segment] and segments[segment].prev) then + gui.text(10,30,"Last score: "..segments[segment].prev.score.."\nBest score: none, fails="..failattempts); + end; + gui.text(10,50,"Segment: "..segment); + + key1 = {}; + key2 = {}; + key3 = {}; + key4 = {}; + + onInputStart(); + + -- player 1 + if (rand_if(pressKeyUp1()) ) then key1.up = 1; end; + if (rand_if(pressKeyDown1())) then key1.down = 1; end; + if (rand_if(pressKeyLeft1())) then key1.left = 1; end; + if (rand_if(pressKeyRight1())) then key1.right = 1; end; + if (rand_if(pressKeyA1())) then key1.A = 1; end; + if (rand_if(pressKeyB1())) then key1.B = 1; end; + if (rand_if(pressKeySelect1())) then key1.select = 1; end; + if (rand_if(pressKeyStart1())) then key1.start = 1; end; + + -- player 2 + if (rand_if(pressKeyUp2()) ) then key2.up = 1; end; + if (rand_if(pressKeyDown2())) then key2.down = 1; end; + if (rand_if(pressKeyLeft2())) then key2.left = 1; end; + if (rand_if(pressKeyRight2())) then key2.right = 1; end; + if (rand_if(pressKeyA2())) then key2.A = 1; end; + if (rand_if(pressKeyB2())) then key2.B = 1; end; + if (rand_if(pressKeySelect2())) then key2.select = 1; end; + if (rand_if(pressKeyStart2())) then key2.start = 1; end; + + -- player 3 + if (rand_if(pressKeyUp3()) ) then key3.up = 1; end; + if (rand_if(pressKeyDown3())) then key3.down = 1; end; + if (rand_if(pressKeyLeft3())) then key3.left = 1; end; + if (rand_if(pressKeyRight3())) then key3.right = 1; end; + if (rand_if(pressKeyA3())) then key3.A = 1; end; + if (rand_if(pressKeyB3())) then key3.B = 1; end; + if (rand_if(pressKeySelect3())) then key3.select = 1; end; + if (rand_if(pressKeyStart3())) then key3.start = 1; end; + + -- player 2 + if (rand_if(pressKeyUp4()) ) then key4.up = 1; end; + if (rand_if(pressKeyDown4())) then key4.down = 1; end; + if (rand_if(pressKeyLeft4())) then key4.left = 1; end; + if (rand_if(pressKeyRight4())) then key4.right = 1; end; + if (rand_if(pressKeyA4())) then key4.A = 1; end; + if (rand_if(pressKeyB4())) then key4.B = 1; end; + if (rand_if(pressKeySelect4())) then key4.select = 1; end; + if (rand_if(pressKeyStart4())) then key4.start = 1; end; + + onInputEnd(); + + lastkey1 = key1; + lastkey2 = key2; + lastkey3 = key3; + lastkey4 = key4; + + keyrecording1[frame] = key1; -- record these keys + keyrecording2[frame] = key2; -- record these keys + keyrecording3[frame] = key3; -- record these keys + keyrecording4[frame] = key4; -- record these keys + end; + + -- actually set the keys here. + joypad.set(1, key1); + joypad.set(2, key2); + joypad.set(3, key3); + joypad.set(4, key4); + + -- next frame + FCEU.frameadvance(); +end; + +onFinish(); -- allow user cleanup before starting the final botloop + +-- now enter an endless loop displaying the results of this run. +while (true) do + if (segments[segment].best) then gui.text(30,100,"end: max attempt ["..segment.."] had score = "..segments[segment].best.score); + elseif (segment > 1 and segments[segment-1].best) then gui.text(30,100,"end: no best attempt ["..segment.."]\nPrevious best score: "..segments[segment-1].best.score); + else gui.text(30,100,"end: no best attempt ["..segment.."] ..."); end; + FCEU.frameadvance(); +end; + +-- i dont think it ever reaches this place... perhaps it should, or some event or whatever... +segments = nil; +collectgarbage(); -- collect the segment data... anything else is probably not worth it... diff --git a/branches/fceux-2.2.2/output/luaScripts/m_utils.lua b/branches/fceux-2.2.2/output/luaScripts/m_utils.lua new file mode 100644 index 00000000..eaf96dca --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/m_utils.lua @@ -0,0 +1,233 @@ +--Used for scripts written by Miau such as Gradius-BulletHell + +--[[ +A Compilation of general-purpose functions. + +-]] +M_UTILS_VERSION = 0 + +--initialization +if(FCEU) then + EMU = FCEU +elseif(snes9x) then + EMU = snes9x +elseif(gens) then + EMU = gens +end +if(EMU == nil) then + error("Unsupported environment. This script runs on Lua-capable emulators only - FCEUX, Snes9x or Gens.") +end + + + + +--[[ m_require + "require" with version checking + + Similar to the approach in Xk's x_functions.lua, but supports loading and automatic version checking of + "compatible" modules, too. A central version checking function does have its advantages. + +A compatible module looks like this: + if(REQUIRED_MODULE_VERSION==0) then --global variable = the second parameter of m_require + error("This module isn't backwards compatible to version 0.") + end + module("modulename") + MODULE_VERSION = 3 + function test() + end + return _M + +using it in your code: + m_require("modulefile.lua",3) --second parameter being > MODULE_VERSION would raise an error + modulename.test() +-]] +function m_require(module,requiredver) + if(module==nil or module=="m_utils") then + if(M_UTILS_VERSION>=requiredver) then + return true + else + error("\n\nThis script requires m_utils version "..requiredver..".\n".. + "Your m_utils.lua is version "..M_UTILS_VERSION.."\n".. + "Check http://morphcat.de/lua/ for a newer version.") + end + else + --give the module the possibility to be backwards compatible + --not very elegant, but there seems to be no other way using require + REQUIRED_MODULE_VERSION = requiredver + local ret = require(module) + if(requiredver==nil) then --got no version checking to do + return ret + elseif(ret==nil or ret==false) then + error("Could not load module "..module.." or module invalid.") + elseif(type(ret)~="table") then + error("Invalid module "..module..", doesn't return itself.") + elseif(ret.MODULE_VERSION==nil) then + error("Invalid module "..module..", missing version information.") + elseif(ret.MODULE_VERSION < requiredver) then + error("\n\nThis script requires "..module.." version "..requiredver..".\n".. + "Your "..module.." module is version "..ret.MODULE_VERSION..".\n".. + "If it's one of miau's Lua modules check\n".. + "http://morphcat.de/lua/ for a newer version.\n") + else + return ret + end + end +end + + +--drawing functions with bounds checking +function bcbox(x1,y1,x2,y2,color1) + if(x1>=0 and y1>=0 and x2<=255 and y2<=255) then + gui.drawbox(x1, y1, x2, y2, color1, 0) + end +end + +function bcpixel(x,y,color) + if(x>=0 and y>=0 and x<=255 and y<=255) then + gui.drawpixel(x,y,color) + end +end + +function bcline(x1,y1,x2,y2,color) + if(x1>=0 and y1>=0 and x2<=255 and y2<=255 + and x2>=0 and y2>=0 and x1<=255 and y1<=255) then + gui.drawline(x1, y1, x2, y2, color) + end +end + + +--bc + clipping, just make sure x2,y2 is the point that will most likely leave the screen first +function bcline2(x1,y1,x2,y2,color) + if(x1>=0 and y1>=0 and x1<=255 and y1<=255) then + if(x2>255 or y2>255 or x2<0 or y2<0) then + local vx,vy=getvdir(x1,y1,x2,y2) + --TODO: replace brute force-y method with line intersection formula + if(math.abs(vx)==1 or math.abs(vy)==1) then + local x=x1 + local y=y1 + while(x<254 and x>1 and y<254 and y>1) do + x = x + vx + y = y + vy + end + x = math.floor(x) + y = math.floor(y) + --logf(" ("..x1..","..y1..")-("..x..","..y..")\r\n") + gui.drawline(x1,y1,x,y,color) + end + else + gui.drawline(x1,y1,x2,y2,color) + end + end +end + +function bctext(x,y,text) + if(x>=0 and y>=0 and x<=255 and y<=255) then + --make sure the text is always visible or else... possible memory leaks(?) and crashes on FCEUX <= 2.0.3 + local len=string.len(text)*8+1 + if(x+len > 255) then + x = 255-len + end + if(x < 0) then + x = 0 + end + + if(y > 222) then --NTSC + y=222 + end + gui.text(x, y, text) + end +end + + +function getdistance(x1,y1,x2,y2) + return math.floor(math.sqrt((x1-x2)^2+(y1-y2)^2)) +end + +--returns direction vector of a line +function getvdir(srcx,srcy,destx,desty) + local x1 = srcx + local x2 = destx + local y1 = srcy + local y2 = desty + local xc = x2-x1 + local yc = y2-y1 + if(math.abs(xc)>math.abs(yc)) then + yc = yc/math.abs(xc) + xc = xc/math.abs(xc) + elseif(math.abs(yc)>math.abs(xc)) then + xc = xc/math.abs(yc) + yc = yc/math.abs(yc) + else + if(xc<0) then + xc=-1 + elseif(xc>0) then + xc=1 + else + xc=0 + end + if(yc<0) then + yc=-1 + elseif(yc>0) then + yc=1 + else + yc=0 + end + end + + return xc,yc +end + + +local m_cursor = { + {1,0,0,0,0,0,0,0}, + {1,1,0,0,0,0,0,0}, + {1,2,1,0,0,0,0,0}, + {1,2,2,1,0,0,0,0}, + {1,2,2,2,1,0,0,0}, + {1,2,2,2,2,1,0,0}, + {1,2,2,2,2,2,1,0}, + {1,2,1,1,1,1,1,1}, + {1,1,0,0,0,0,0,0}, + {1,0,0,0,0,0,0,0}, +} +function drawcursor(px,py,col1,col2) + if(px>0 and py>0 and px<256-8 and py<256-10) then + for y=1,10 do + if(m_cursor[y]) then + for x=1,8 do + if(m_cursor[y][x]==1) then + gui.drawpixel(px+x,py+y,col1) + elseif(m_cursor[y][x]==2) then + gui.drawpixel(px+x,py+y,col2) + end + end + end + end + end +end + +--debug functions +function logf(s) + local fo = io.open("E:/emu/nes/fceux-2.0.4.win32-unofficial/lua/log.txt", "ab") + if(fo~=nil) then + fo:write(s) + fo:close() + return true + end +end + +function logtable(a) + for i,v in pairs(a) do + if(type(v)=="table") then + printarrrec(v) + else + if(v==false) then + v="false" + elseif(v==true) then + v="true" + end + logf(i.." = "..v.."\r\n") + end + end +end + diff --git a/branches/fceux-2.2.2/output/luaScripts/shapedefs.lua b/branches/fceux-2.2.2/output/luaScripts/shapedefs.lua new file mode 100644 index 00000000..3aa1c666 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/shapedefs.lua @@ -0,0 +1,43 @@ +--shapedefs +--A Lua script with defined functions for shapes such as hearts. +--Needed for SM-Lives&HPDisplay-4Matsy.lua + +local function box(x1,y1,x2,y2,color) + if (x1 > 0 and x1 < 255 and x2 > 0 and x2 < 255 and y1 > 0 and y1 < 241 and y2 > 0 and y2 < 241) then + gui.drawbox(x1,y1,x2,y2,color); + end; +end; +local function text(x,y,str) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.text(x,y,str); + end; +end; +local function pixel(x,y,color) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.drawpixel(x,y,color); + end; +end; + +function drawshape (x,y,str,color) + if str == "heart_5x5" then + box(x+1,y+0,x+1,y+3,color); + box(x+3,y+0,x+3,y+3,color); + box(x+2,y+3,x+2,y+4,color); + box(x+0,y+1,x+4,y+2,color); + end; + if str == "heart_7x7" then + box(x+1,y+0,x+2,y+4,color); + box(x+4,y+0,x+5,y+4,color); + box(x+0,y+1,x+6,y+3,color); + box(x+3,y+2,x+3,y+6,color); + box(x+2,y+5,x+4,y+5,color); + end; + if str == "z2magicjar" then + box(x+0,y+5,x+4,y+6,color); + box(x+1,y+4,x+3,y+7,color); + box(x+1,y+0,x+3,y+0,color); + box(x+2,y+1,x+2,y+3,color); + box(x+3,y+2,x+3,y+2,color); + box(x+4,y+3,x+4,y+3,color); + end; +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/taseditor/InputDisplay_for_Selection.lua b/branches/fceux-2.2.2/output/luaScripts/taseditor/InputDisplay_for_Selection.lua new file mode 100644 index 00000000..50f44d5b --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/taseditor/InputDisplay_for_Selection.lua @@ -0,0 +1,64 @@ +--------------------------------------------------------------------------- +-- Display Input at Selection cursor +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * taseditor.getselection() +-- * taseditor.getinput() +--------------------------------------------------------------------------- +-- Usage: +-- Run the script, unpause emulation (or simply Frame Advance once). +-- Now you can see additional joypad icon at the bottom left corner of FCEUX screen. +-- This icon displays which buttons are held at the selected frame. +-- If you have several frames selected, the joypad icon will only display buttons +-- of the first selected frame. +-- By default the script only shows 1P joypad, but you can change "num=2, on=false" +-- to "num=2, on=true" to also display 2P joypad and so on. +--------------------------------------------------------------------------- + +pads = { + {num=1, on=true, color="red", x=50, y=200, w=34, h=10}, + {num=2, on=true, color="yellow", x=90, y=200, w=34, h=10}, + {num=3, on=false, color="green", x=130, y=200, w=34, h=10}, + {num=4, on=false, color="orange", x=170, y=200, w=34, h=10} +} + +buttons = { + A = {x=30, y=5, w=3, h=3, bitmask=1}, + B = {x=24, y=5, w=3, h=3, bitmask=2}, + select = {x=18, y=7, w=3, h=1, bitmask=4}, + start = {x=12, y=7, w=3, h=1, bitmask=8}, + up = {x=4, y=1, w=2, h=2, bitmask=16}, + down = {x=4, y=7, w=2, h=2, bitmask=32}, + left = {x=1, y=4, w=2, h=2, bitmask=64}, + right = {x=7, y=4, w=2, h=2, bitmask=128} +} + +function draw_joypads() + if (taseditor.engaged()) then + selection_table = taseditor.getselection(); + if (selection_table ~= nil) then + selection_start = selection_table[1]; + for _, pad in ipairs(pads) do + if pad.on then + gui.drawbox(pad.x, pad.y, pad.x+pad.w, pad.y+pad.h, "#3070ffb0") + gui.drawbox(pad.x+4, pad.y+4, pad.x+6, pad.y+6, "black") + controller = taseditor.getinput(selection_start, pad.num) + for name, btn in pairs(buttons) do + if (AND(controller, btn.bitmask) ~= 0) then + gui.drawbox(pad.x + btn.x, pad.y + btn.y, pad.x + btn.x + btn.w, pad.y + btn.y + btn.h, pad.color) + else + gui.drawbox(pad.x + btn.x, pad.y + btn.y, pad.x + btn.x + btn.w, pad.y + btn.y + btn.h, "black") + end + end + end + end + end + else + gui.text(1, 9, "TAS Editor is not engaged."); + end +end + +taseditor.registerauto(draw_joypads); + + diff --git a/branches/fceux-2.2.2/output/luaScripts/taseditor/InvertSelection.lua b/branches/fceux-2.2.2/output/luaScripts/taseditor/InvertSelection.lua new file mode 100644 index 00000000..342e9acb --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/taseditor/InvertSelection.lua @@ -0,0 +1,55 @@ +--------------------------------------------------------------------------- +-- Invert Selection +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * taseditor.getselection() +-- * taseditor.setselection() +--------------------------------------------------------------------------- +-- Usage: +-- Run the script, unpause emulation (or simply Frame Advance once). +-- Now you can press "Invert Selection" button to invert current Selection. +-- Previously selected frames become deselected, all other frames become selected. +--------------------------------------------------------------------------- + +function display_selection() + if (taseditor.engaged()) then + selection_table = taseditor.getselection(); + if (selection_table ~= nil) then + selection_size = #selection_table; + gui.text(0, 10, "Selection: " .. selection_size .. " rows"); + else + gui.text(0, 10, "Selection: no"); + end + else + gui.text(1, 9, "TAS Editor is not engaged."); + end +end + +function invert_selection() + old_sel = taseditor.getselection(); + new_sel = {}; + + -- Select all + movie_size = movie.length(); + for i = 0, movie_size do + new_sel[i + 1] = i; + end + + if (selection_table ~= nil) then + -- Substract old selection from new selection set + for i = #old_sel, 1, -1 do + selected_frame = old_sel[i]; + -- we're taking advantage of the fact that "old_sel" is sorted in ascending order + -- so we can safely use table.remove to remove indexes from the end to the beginning + table.remove(new_sel, selected_frame + 1); + end + end + + -- Apply new set to TAS Editor selection + taseditor.setselection(new_sel); +end + +taseditor.registerauto(display_selection); +taseditor.registermanual(invert_selection, "Invert Selection"); + diff --git a/branches/fceux-2.2.2/output/luaScripts/taseditor/RecordBackwards.lua b/branches/fceux-2.2.2/output/luaScripts/taseditor/RecordBackwards.lua new file mode 100644 index 00000000..8e30376e --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/taseditor/RecordBackwards.lua @@ -0,0 +1,99 @@ +--------------------------------------------------------------------------- +-- Recording Input while Rewinding Playback frame-by-frame +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * joypad.getimmediate() +-- * taseditor.getrecordermode() +-- * taseditor.getsuperimpose() +-- * taseditor.getinput() +-- * taseditor.setinput() +-- * taseditor.clearinputchanges() +-- * taseditor.applyinputchanges() +--------------------------------------------------------------------------- +-- Usage: +-- Run the script, unpause emulation (or simply Frame Advance once). +-- Now you can hold some joypad buttons and press "Rewind Frame" hotkey +-- to Record those buttons into PREVIOUS frame. +-- Try using this crazy method alongside with Frame Advance Recording. +-- This script supports multitracking and superimpose. Doesn't support Patterns. +--------------------------------------------------------------------------- + +-- This function reads joypad input table and converts it to single byte +function GetCurrentInputByte(player) + input_byte = 0; + input_table = joypad.getimmediate(player); + if (input_table ~= nil) then + -- A B select start up down left right + if (input_table.A) then input_byte = OR(input_byte, 1) end; + if (input_table.B) then input_byte = OR(input_byte, 2) end; + if (input_table.select) then input_byte = OR(input_byte, 4) end; + if (input_table.start) then input_byte = OR(input_byte, 8) end; + if (input_table.up) then input_byte = OR(input_byte, 16) end; + if (input_table.down) then input_byte = OR(input_byte, 32) end; + if (input_table.left) then input_byte = OR(input_byte, 64) end; + if (input_table.right) then input_byte = OR(input_byte, 128) end; + end + return input_byte; +end + +function reversed_recorder() + if taseditor.engaged() then + playback_position = movie.framecount(); + if (playback_position == (playback_last_position - 1)) then + -- Playback cursor moved up 1 frame, probably Rewind was used this frame + if (not movie.readonly()) then + -- Recording on + recording_mode = taseditor.getrecordermode(); + superimpose = taseditor.getsuperimpose(); + taseditor.clearinputchanges(); + name = "Record"; + if (recording_mode == "All") then + -- Recording all 4 joypads + for target_player = 1, 4 do + new_joypad_input = GetCurrentInputByte(target_player); + old_joypad_input = taseditor.getinput(playback_position, target_player); + -- Superimpose with old input if needed + if (superimpose == 1 or (superimpose == 2 and new_joypad_input == 0)) then + new_joypad_input = OR(new_joypad_input, old_joypad_input); + end + -- Add joypad info to name + if (new_joypad_input ~= old_joypad_input) then + name = name .. "(" .. target_player .. "P)"; + end + taseditor.submitinputchange(playback_position, target_player, new_joypad_input); + end + -- Write to movie data + taseditor.applyinputchanges(name); + else + -- Recording target_player using 1P keys + new_joypad_input = GetCurrentInputByte(1); + target_player = 1; + if (recording_mode == "2P") then target_player = 2 end; + if (recording_mode == "3P") then target_player = 3 end; + if (recording_mode == "4P") then target_player = 4 end; + old_joypad_input = taseditor.getinput(playback_position, target_player); + -- Superimpose with old input if needed + if (superimpose == 1 or (superimpose == 2 and new_joypad_input == 0)) then + new_joypad_input = OR(new_joypad_input, old_joypad_input); + end + -- Add joypad info to name + if (new_joypad_input ~= old_joypad_input) then + name = name .. "(" .. recording_mode .. ")"; + end + -- Write to movie data + taseditor.submitinputchange(playback_position, target_player, new_joypad_input); + taseditor.applyinputchanges(name); + end + end + end + playback_last_position = playback_position; + else + gui.text(1, 9, "TAS Editor is not engaged."); + end +end + +playback_last_position = movie.framecount(); +taseditor.registerauto(reversed_recorder); + + diff --git a/branches/fceux-2.2.2/output/luaScripts/taseditor/ShowNotes.lua b/branches/fceux-2.2.2/output/luaScripts/taseditor/ShowNotes.lua new file mode 100644 index 00000000..1fb61403 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/taseditor/ShowNotes.lua @@ -0,0 +1,64 @@ +--------------------------------------------------------------------------- +-- Showing Markers' Notes on screen +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * taseditor.getmarker() +-- * taseditor.getnote() +-- * taseditor.getselection() +--------------------------------------------------------------------------- +-- Usage: +-- Run the script, unpause emulation (or simply Frame Advance once). +-- Now you can observe Marker Notes not only in TAS Editor window, +-- but also in FCEUX main screen. +-- This script automatically divides long Notes into several lines of text +--------------------------------------------------------------------------- + +-- Custom function for word-wrapping long lines of text +function DisplayText(x, y, text, max_num_chars) + while string.len(text) >= max_num_chars do + -- Find last spacebar within first max_num_chars of text + last_spacebar = string.find(string.reverse(string.sub(text, 1, max_num_chars)), " "); + if (last_spacebar ~= nil) then + -- Output substring up to the spacebar + substring_len = max_num_chars - last_spacebar; + else + -- No spacebar found within first max_num_chars of the string + -- output substring up to the first spacebar (this substring will have length > max_num_chars) + substring_len = string.find(text, " "); + if (substring_len == nil) then + -- No spacebars found at all, output whole string + substring_len = string.len(text); + else + -- Don't output the spacebar + substring_len = substring_len - 1; + end + end + gui.text(x, y, string.sub(text, 1, substring_len)); + text = string.sub(text, substring_len + 2); + -- Next line + y = y + 8; + end + gui.text(x, y, text); +end + +function ShowNotes() + if taseditor.engaged() then + -- Take Marker near Playback cursor and display its Note in upper half of the screen + playback_position = movie.framecount(); + note = taseditor.getnote(taseditor.getmarker(playback_position)); + DisplayText(1, 9, note, 50); + -- Take Marker near Selection cursor and display its Note in lower half of the screen + current_selection = taseditor.getselection(); + if (current_selection ~= nil) then + selection_position = current_selection[1]; + note = taseditor.getnote(taseditor.getmarker(selection_position)); + DisplayText(1, 190, note, 50); + end + else + gui.text(1, 9, "TAS Editor is not engaged."); + end +end + +taseditor.registerauto(ShowNotes) + diff --git a/branches/fceux-2.2.2/output/luaScripts/taseditor/Swap1P2P.lua b/branches/fceux-2.2.2/output/luaScripts/taseditor/Swap1P2P.lua new file mode 100644 index 00000000..e69ac197 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/taseditor/Swap1P2P.lua @@ -0,0 +1,37 @@ +--------------------------------------------------------------------------- +-- Swap 1P and 2P buttons at Selected frames +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * taseditor.getselection() +-- * taseditor.clearinputchanges() +-- * taseditor.getinput() +-- * taseditor.submitinputchange() +-- * taseditor.applyinputchanges() +--------------------------------------------------------------------------- +-- Usage: +-- Use the script when you want to exchange recorded input between joypads. +-- Run the script, unpause emulation (or simply Frame Advance once). +-- Now you can select several frames of input data and then +-- press "Swap 1P/2P" button to swap Input of 1P and 2P in selected frames. +-- You can easily modify the script to swap any other joypads. +--------------------------------------------------------------------------- + +function swap() + selection_table = taseditor.getselection(); + if (selection_table ~= nil) then + taseditor.clearinputchanges(); + for i = 1, #selection_table do + selected_frame = selection_table[i]; + joypad1data = taseditor.getinput(selected_frame, 1); + joypad2data = taseditor.getinput(selected_frame, 2); + taseditor.submitinputchange(selected_frame, 1, joypad2data); + taseditor.submitinputchange(selected_frame, 2, joypad1data); + end + taseditor.applyinputchanges("Swap 1P/2P"); + end +end + +taseditor.registermanual(swap, "Swap 1P/2P"); + + diff --git a/branches/fceux-2.2.2/output/luaScripts/taseditor/TrackNoise.lua b/branches/fceux-2.2.2/output/luaScripts/taseditor/TrackNoise.lua new file mode 100644 index 00000000..1160f9c7 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/taseditor/TrackNoise.lua @@ -0,0 +1,82 @@ +--------------------------------------------------------------------------- +-- Tracking Noise channel volume peaks +-- by AnS, 2012 +--------------------------------------------------------------------------- +-- Showcases following functions: +-- * sound.get() +-- * taseditor.markedframe() +-- * taseditor.getmarker() +-- * taseditor.setmarker() +-- * taseditor.getnote() +-- * taseditor.setnote() +--------------------------------------------------------------------------- +-- Usage: +-- Run the script, unpause emulation. +-- When the "Auto function" checkbox is checked, the script will +-- automatically create Markers on various frames according to ingame music. +-- These Markers should help you see music patterns, +-- so you can adjust input precisely creating nice Tool-Assisted dances. +-- +-- This script uses Noise channel volume as an indicator for setting Markers, +-- but it's possible to use any other property of sound channels +-- as a factor to decide whether to set Marker on current frame. +-- +-- The script was tested on Super Mario Bros, Megaman and Duck Tales. +-- You may want to see it in slow-mo. Use -/= hotkeys to change emulation speed. +-- +-- To create customized script for your game, first use SoundDisplay.lua +-- to collect and analyse statistics about ingame music. Then choose +-- which channel you want to sync your input to. Finally, change this script +-- so that Markers will be created using new set of rules. +--------------------------------------------------------------------------- + +NOISE_VOL_THRESHOLD = 0.35; + +function track_changes() + if (taseditor.engaged()) then + current_frame = movie.framecount(); + if (last_frame ~= current_frame) then + -- Playback has moved + -- Get current value of indicator for current_frame + snd = sound.get(); + indicator = snd.rp2a03.noise.volume; + -- If Playback moved 1 frame forward, this was probably Frame Advance + if (last_frame == current_frame - 1) then + -- Looks like we advanced one frame from the last time + -- Decide whether to set Marker + if (indicator > NOISE_VOL_THRESHOLD and last_frame_indicator_value == 0) then + -- this was a peak in volume! ____/\____ + -- Set Marker and show frequency of noise+triangle in its Note + SetSoundMarker(current_frame - 1, "Sound: " .. (snd.rp2a03.noise.regs.frequency + snd.rp2a03.triangle.regs.frequency)); + end + end + last_frame = current_frame; + last_frame_indicator_value = indicator; + end + else + gui.text(1, 9, "TAS Editor is not engaged."); + end +end + +function SetSoundMarker(frame, new_note) + if (taseditor.markedframe(frame)) then + -- this frame is already marked + old_note = taseditor.getnote(taseditor.getmarker(frame)); + -- check if the Note of the Marker already contains new_note text + if (string.find(old_note, new_note) == nil) then + -- append new_note text to the Marker's Note + taseditor.setnote(taseditor.getmarker(frame), old_note .. " " .. new_note); + end + else + -- this frame isn't marked + -- create new Marker here + new_marker = taseditor.setmarker(frame); + taseditor.setnote(new_marker, new_note); + end +end + +last_frame = 0; +last_frame_indicator_value = 0; + +taseditor.registerauto(track_changes); + diff --git a/branches/fceux-2.2.2/output/luaScripts/tetris.lua b/branches/fceux-2.2.2/output/luaScripts/tetris.lua new file mode 100644 index 00000000..1ca1c72f --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/tetris.lua @@ -0,0 +1,141 @@ +-- Tetris - displays block stats and shows hitboxes +-- Written by QFox +-- http://www.datacrystal.org/wiki/Tetris:RAM_map +-- Tetris (U) [!].rom + +local function getPiece(n) -- returns table with information about this piece + -- every piece consists of 4 blocks + -- so piece will contain the information about these blocks + -- for every block is the offset compared to the x,y position of the piece + -- the x,y is written in a 4x4 plane of blocks, 1x1 being the topleft block + -- x,y is the position as given by tetris + local piece = {}; + if (n == 0) then -- T right + piece.pos = {{2,1},{1,2},{2,2},{3,2}}; + piece.rel = {{0,-1},{-1,0},{0,0},{1,0}}; + piece.anchor = {2,2}; + elseif (n == 1) then -- T up + piece.pos = {{1,1},{1,2},{2,2},{1,3}}; + piece.rel = {{0,-1},{0,0},{1,0},{0,1}}; + piece.anchor = {1,2}; + elseif (n == 2) then -- T down + piece.pos = {{1,1},{2,1},{3,1},{2,2}}; + piece.rel = {{-1,0},{0,0},{1,0},{0,1}}; + piece.anchor = {2,1}; + elseif (n == 3) then -- T left + piece.pos = {{2,1},{1,2},{2,2},{2,3}}; + piece.rel = {{0,-1},{-1,0},{0,0},{0,1}}; + piece.anchor = {2,2}; + elseif (n == 4) then -- J left + piece.pos = {{2,1},{2,2},{1,3},{2,3}}; + piece.rel = {{0,-1},{0,0},{-1,1},{0,1}}; + piece.anchor = {2,2}; + elseif (n == 5) then -- J up + piece.pos = {{1,1},{1,2},{2,2},{3,2}}; + piece.rel = {{-1,-1},{-1,0},{0,0},{1,0}}; + piece.anchor = {2,2}; + elseif (n == 6) then -- J right + piece.pos = {{1,1},{2,1},{1,2},{1,3}}; + piece.rel = {{0,-1},{1,-1},{0,0},{0,1}}; + piece.anchor = {1,2}; + elseif (n == 7) then -- J down + piece.pos = {{1,1},{2,1},{3,1},{3,2}}; + piece.rel = {{-1,0},{0,0},{1,0},{1,1}}; + piece.anchor = {2,1}; + elseif (n == 8) then -- Z horz + piece.pos = {{1,1},{2,1},{2,2},{3,2}}; + piece.rel = {{-1,0},{0,0},{0,1},{1,1}}; + piece.anchor = {2,1}; + elseif (n == 9) then -- Z vert + piece.pos = {{2,1},{1,2},{2,2},{1,3}}; + piece.rel = {{1,-1},{0,0},{1,0},{0,1}}; + piece.anchor = {1,2}; + elseif (n == 10) then -- O + piece.pos = {{1,1},{2,1},{1,2},{2,2}}; + piece.rel = {{-1,0},{0,0},{-1,1},{0,1}}; + piece.anchor = {2,1}; + elseif (n == 11) then -- S horz + piece.pos = {{2,1},{3,1},{1,2},{2,2}}; + piece.rel = {{0,0},{1,0},{-1,1},{0,1}}; + piece.anchor = {2,1}; + elseif (n == 12) then -- S vert + piece.pos = {{1,1},{1,2},{2,2},{2,3}}; + piece.rel = {{0,-1},{0,0},{1,0},{1,1}}; + piece.anchor = {1,2}; + elseif (n == 13) then -- L right + piece.pos = {{1,1},{1,2},{1,3},{2,3}}; + piece.rel = {{0,-1},{0,0},{0,1},{1,1}}; + piece.anchor = {1,2}; + elseif (n == 14) then -- L down + piece.pos = {{1,1},{2,1},{3,1},{1,2}}; + piece.rel = {{-1,0},{0,0},{1,0},{-1,1}}; + piece.anchor = {2,1}; + elseif (n == 15) then -- L left + piece.pos = {{1,1},{2,1},{2,2},{2,3}}; + piece.rel = {{-1,-1},{0,-1},{0,0},{0,1}}; + piece.anchor = {2,2}; + elseif (n == 16) then -- L up + piece.pos = {{3,1},{1,2},{2,2},{3,2}}; + piece.rel = {{1,-1},{-1,0},{0,0},{1,0}}; + piece.anchor = {2,2}; + elseif (n == 17) then -- I vert + piece.pos = {{1,1},{1,2},{1,3},{1,4}}; + piece.rel = {{0,-2},{0,-1},{0,0},{0,1}}; + piece.anchor = {1,3}; + elseif (n == 18) then -- I horz + piece.pos = {{1,1},{2,1},{3,1},{4,1}}; + piece.rel = {{-2,0},{-1,0},{0,0},{1,0}}; + piece.anchor = {3,1}; + else + return nil; + end; + piece.id = n; + return piece; +end; + + -- 0,0 - 10,20 + -- translated it's: <95,40> to <175,200> + -- x starts at 1, y starts at 0... + -- each block is 8x8 +local areax = 95; +local areay = 40; +local blocksize = 8; + +while (true) do + -- get position of current piece (now) + local x = (memory.readbyte(0x0060)*blocksize)+areax; + local y = (memory.readbyte(0x0061)*blocksize)+areay; + local now = getPiece(memory.readbyte(0x0062)); -- get piece info + -- draw a nice box around it + gui.drawbox(95,40,175,200,"red"); + gui.text(5,5,"xy: <"..x..", "..y..">"); + if (now and x > 0 and y > 0 and x < 250 and y < 200) then + gui.drawbox(x+(now.rel[1][1]*blocksize),y+(now.rel[1][2]*blocksize),x+(now.rel[1][1]*blocksize)+blocksize,y+(now.rel[1][2]*blocksize)+blocksize,"green"); + gui.drawbox(x+(now.rel[2][1]*blocksize),y+(now.rel[2][2]*blocksize),x+(now.rel[2][1]*blocksize)+blocksize,y+(now.rel[2][2]*blocksize)+blocksize,"green"); + gui.drawbox(x+(now.rel[3][1]*blocksize),y+(now.rel[3][2]*blocksize),x+(now.rel[3][1]*blocksize)+blocksize,y+(now.rel[3][2]*blocksize)+blocksize,"green"); + gui.drawbox(x+(now.rel[4][1]*blocksize),y+(now.rel[4][2]*blocksize),x+(now.rel[4][1]*blocksize)+blocksize,y+(now.rel[4][2]*blocksize)+blocksize,"green"); + end; + gui.text(5,15,"Now: "..memory.readbyte(0x0062).."\nNext: "..memory.readbyte(0x00BF)); + + -- draw the filled field and do some counting + local start = 0x0400; -- toprow + local height = -1; + local filled = 0; + for j=0,19 do + for i=0,9 do + if (memory.readbyte(start+(j*10)+i) ~= 0xEF) then + filled = filled + 1; + if (height == -1) then height = j; end; + gui.drawbox(areax+(i*blocksize),areay+(j*blocksize),areax+(i*blocksize)+blocksize,areay+(j*blocksize)+blocksize,"red"); + end; + end; + end; + if (height == -1) then height = 0; + else height = 20 - height; end; + gui.text(5,30,"Height: "..height.."\nFilled: "..filled.." ("..math.floor(filled/(height)*10).."%)"); + + + --local inp1 = joypad.read(1); + --joypad.set(1,{right=1}); + FCEU.frameadvance(); +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/vnb.lua b/branches/fceux-2.2.2/output/luaScripts/vnb.lua new file mode 100644 index 00000000..f7791b0d --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/vnb.lua @@ -0,0 +1,613 @@ + +-- Valkyrie no Bouken stuffs +-- This game sucks, don't play it +-- Lovingly based off of 4matsy's SMB code, and then mutilated and mamed as required +-- Xkeeper 2008, September 12th + + +require("x_functions"); +x_requires(4); + + + + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + + + +function mapdot(x,y,color) + if (x >= 1 and x <= 254 and y >= 1 and y <= 239) then + gui.drawline(x - 1, y , x + 1, y , color); + gui.drawline(x , y - 1, x , y + 2, color); + end; +end; + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function doexp() + + totalexp = vnbnumber(0x00d5, 5); + growth = memory.readbyte(0x0111); + level = memory.readbyte(0x00b9); + nextlv = memory.readbyte(0x00bb); + prevexp = -1; + + if level ~= 0 then + + if nextlv < 0x14 then + nextexp = exptable[nextlv + 1]; + else + prevexp = math.floor(totalexp / 10000) * 10000; + nextexp = math.floor(totalexp / 10000) * 10000 + 10000; + end; + + if growth < 3 and prevexp == -1 then +-- prevexp = exptable[leveltable[growth][level] + 1]; + + end; + + expval = {}; + expval["level"] = level; + expval["next"] = nextexp - totalexp; + expval["prev"] = prevexp; + expval["pct"] = math.floor((totalexp - prevexp) / (nextexp - prevexp) * 100); + expval["exp"] = totalexp; + + if prevexp == -1 then + expval["pct"] = -1; + end; + + else + + expval = {}; + expval["level"] = 0; + expval["next"] = 0; + expval["prev"] = 0; + expval["pct"] = 0; + expval["exp"] = 0; + + end; + + return expval; +end; + + + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function vnbnumber(offset, length) + val = 0; + + for i = 0, length do + inp = memory.readbyte(offset + (i)); + if (inp ~= 0x26) then val = val + inp * (10 ^ i); end; + end; + + return val; +end; + + + + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function worldmap() + + herox = memory.readbyte(0x0080) + memory.readbyte(0x0081) * 256; -- hero's X position + heroy = memory.readbyte(0x0082) + memory.readbyte(0x0083) * 256; -- hero's current MP + + if mapstyle == 1 then + mapx = 8; + mapy = 9; + mapw = 60; + maph = 37; + elseif mapstyle == 2 or mapstyle == 3 then + + mapx = 8; + mapy = 34; + mapw = 240; + maph = 147; + + else + return nil; + end; + + if gamemode == 0x05 or gamemode == 0x01 or gamemode == 0x06 or gamemode == 0x08 then + + maphx = math.ceil(herox / 3840 * mapw); + maphy = math.ceil(heroy / 2352 * maph); + + +-- filledbox(mapx - 1, mapy - 1, mapx + mapw + 1, mapy + maph, "#000000"); + box(mapx - 1, mapy - 1, mapx + mapw + 1, mapy + maph, "#ffffff"); + + if mapstyle == 3 then + for i = 0, 0xFF do + + mappx = math.ceil((3840 / 16) * math.fmod(i, 0x10) / 3840 * mapw); + mappy = math.ceil((2352 / 16) * math.floor(i / 0x10) / 2352 * maph); + mappx2 = math.ceil((3840 / 16) * (math.fmod(i, 0x10) + 1) / 3840 * mapw) - 1; + mappy2 = math.ceil((2352 / 16) * (math.floor(i / 0x10) + 1) / 2352 * maph) - 1; + tmp = memory.readbyte(0x81E5 + i) * 2; + filledbox(mapx + mappx, mapy + mappy, mapx + mappx2, mapy + mappy2, string.format("#%02x%02x%02x", tmp, tmp, tmp)); + + end; + end; + + if math.fmod(timer, 60) >= 30 then + color = "#888888"; + else + color = "#bbbbbb"; + end; + + +-- line(mapx, mapy + maphy, mapx + mapw, mapy + maphy, "#cccccc"); +-- line(mapx + maphx, mapy, mapx + maphx, mapy + maph, "#cccccc"); + + mapdist = 51; + for i = 1, mappoints do + mappx = math.ceil(mapdots[i]["x"] / 3840 * mapw); + mappy = math.ceil(mapdots[i]["y"] / 2352 * maph); + mapdot(mapx + mappx, mapy + mappy, mapdots[i]["color"]); + if mapdots[i]["name"] then + mapdotdist = math.abs(mapdots[i]["x"] - herox) + math.abs(mapdots[i]["y"] - heroy); + if mapdotdist < mapdist then + mapdist = mapdotdist; + mapdistn = mapdots[i]["name"]; + end; + end; + end; + + if mapdist <= 50 then + text(90, 17, mapdistn); + end; + filledbox(mapx + maphx - 0, mapy + maphy - 0, mapx + maphx + 0, mapy + maphy + 0, "#ffffff"); + box(mapx + maphx - 1, mapy + maphy - 1, mapx + maphx + 1, mapy + maphy + 1, color); + +-- text(mapx + 0, mapy + maph + 2, string.format("%04d, %04d", herox, heroy)); + + + end; +end; + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function gameloop() + + if gamemode == 0x01 and math.fmod(timer, 60) >= 30 then + text(105, 180, "< DEMO >"); + end; + + + herohp = memory.readbyte(0x00c0) + memory.readbyte(0x00c1) * 256; -- hero's current HP + heromp = memory.readbyte(0x00c2) + memory.readbyte(0x00c3) * 256; -- hero's current MP + heromaxhp = memory.readbyte(0x00c4) + memory.readbyte(0x00c5) * 256; -- hero's maximum HP + heromaxmp = memory.readbyte(0x00c6) + memory.readbyte(0x00c7) * 256; -- hero's maximum MP + money = vnbnumber(0x00d0, 4); + gametime = memory.readbyte(0x0031) * 0x3c + memory.readbyte(0x0030); -- game-time + gamehour = math.floor(gametime / 320); + gameminute = math.floor((gametime - 320 * gamehour) / 320 * 60); + expval = doexp(); + + worldmap(); + + filledbox(96, 194, 255, 244, "#000000"); + + text(191, 8, string.format("Time: %02d:%02d", gamehour, gameminute)); +-- text(188, 23, string.format("GameMode: %02x", gamemode)); + + text( 90, 194, string.format("HP %3d/%3d MP %3d/%3d", herohp, heromaxhp, heromp, heromaxmp)); + if expval["next"] > 0 then + text( 90, 218, string.format("Lv.%2d: %6d XP Next %6d", expval["level"], expval["exp"], expval["next"])); + else + text( 90, 218, string.format("Lv.%2d: %6d EXP", expval["level"], expval["exp"])); + end; + + + text(217, 202, string.format("ATK %2d", memory.readbyte(0x00e7))); + text(217, 210, string.format("$%5d", money)); + + + lifebar(191, 16, 60, 2, gamehour, 24, "#ffffff", "#777777", true); + lifebar(191, 20, 60, 0, gameminute, 60, "#cccccc", "#555555", true); + lifebar( 90, 202, 123, 4, herohp, heromaxhp, "#ffcc00", "#880000", true); + lifebar( 90, 208, 123, 3, heromp, heromaxmp, "#9999ff", "#0000dd", true); + + if expval["pct"] ~= -1 then + lifebar( 90, 226, 162, 2, expval["pct"], 100, "#ffffff", "#555555", true); + end; + + box(89, 194, 91, 244, "#000000"); + line(90, 194, 90, 244, "#000000"); + + + if not enemy then enemy = {} end; + + if gamemode == 0x05 or gamemode == 0x01 or gamemode == 0x06 then + for i = 0, 5 do + + offset = 0x500 + 0x10 * i; + + if not enemy[i] then + enemy[i] = {}; + end; + + if (memory.readbyte(offset) > 0) then + + if not enemy[i]["maxhp"] then enemy[i]["maxhp"] = 0 end; + + enemy[i]["t"] = memory.readbyte(offset); + enemy[i]["x"] = memory.readbyte(offset + 5); + enemy[i]["y"] = memory.readbyte(offset + 6); + enemy[i]["hp"] = memory.readbyte(offset + 15); + enemy[i]["maxhp"] = math.max(enemy[i]["maxhp"], enemy[i]["hp"]); + + enemy[i]["item"] = memory.readbyte(offset + 10); + + if enemy[i]["t"] > 1 then + text(enemy[i]["x"] - 9, enemy[i]["y"] - 16, enemy[i]["hp"] .."/".. enemy[i]["maxhp"]); + lifebar(enemy[i]["x"] - 5, enemy[i]["y"] - 8, 22, 0, enemy[i]["hp"], enemy[i]["maxhp"], "#ffcc00", "#dd0000", false); + else + if (enemy[i]["item"] == 0x1C) then + if enemy[i]["hp"] == 0 then enemy[i]["hp"] = 10 end; + if enemy[i]["hp"] == 9 then enemy[i]["hp"] = 99 end; + text(enemy[i]["x"] - 6 - math.min(math.floor(enemy[i]["hp"] / 10) * 2, 2), enemy[i]["y"] - 8, "$".. enemy[i]["hp"]); + else + box(enemy[i]["x"], enemy[i]["y"], enemy[i]["x"] + 15, enemy[i]["y"] + 15, "#ffffff"); + text(enemy[i]["x"] - string.len(itemlist[enemy[i]["item"]]) * 1.75 + 0, enemy[i]["y"] - 8, itemlist[enemy[i]["item"]]); + + end; + end; + + else + enemy[i] = {}; + + end; + end; + end; + + for i = 0, 7 do + offset = 0x0160 + 0x02 * i; + item = memory.readbyte(offset + 1); + uses = memory.readbyte(offset + 1); + xo = math.fmod(i, 4); + yo = math.floor(i / 4); + if (item > 0 and (uses > 0 and uses < 255)) then + text(xo * 12 + 8, 194 + yo * 16, uses); + end; + end; + + + + +--[[-- auto-regenerate HP + if (herohp < heromaxhp) and ((math.fmod(timer, 3) == 0) or true) then + herohp = herohp + 1; + memory.writebyte(0x00c0, math.fmod(herohp, 256)); + memory.writebyte(0x00c1, math.floor(herohp / 256)); + end; +--]]-- + + + +--[[ basically the Big Cheating Section. + + if not expbooster then expbooster = 0 end; + expbooster = expbooster + 1; + if expbooster >= 3 and gamemode == 0x06 then + expbooster = 0; + memory.writebyte(0x0d5, memory.readbyte(0x00d5) + 1); + + for i = 0,5 do + inp = memory.readbyte(0x00d5 + i); + if (inp == 0x0a) then + memory.writebyte(0x00d5 + (i + 1), memory.readbyte(0x00d5 + (i + 1)) + 1); + memory.writebyte(0x00d5 + i, 0); + + elseif (inp == 0x27) then + memory.writebyte(0x00d5 + i, 1); + + end; + end; + end; +]]-- +end; + + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function charaselect() + asign = memory.readbyte(0x0110); + btype = memory.readbyte(0x0111); + +-- line( 92, 30, 92, 130, "#ffffff"); + + + filledbox( 13, 48, 96, 64, "#000000"); -- cover JP text + filledbox( 13, 80, 96, 96, "#000000"); -- cover JP text + filledbox( 13, 112, 96, 128, "#000000"); -- cover JP text + filledbox(160, 48, 231, 64, "#000000"); -- cover JP text + + text( 74, 24, " Create your character "); + + text( 15, 51, "Astrological sign:"); + text(158, 51, string.format("%s", asigns[asign])); + + text( 41, 83, "Blood type:"); +-- text(164, 83, string.format("%s (%X)", btypes[btype], btype)); + + text( 26, 115, "Clothing color:"); + + + asign2 = math.fmod(asign, 4); + if asign2 == 0 then + shp = 64; + smp = 32; + elseif asign2 == 1 then + shp = 48; + smp = 48; + elseif asign2 == 2 then + shp = 32; + smp = 64; + elseif asign2 == 3 then + shp = 33; + smp = 63; + end; + + strength = 10 + math.floor(shp / 32); + + text( 8, 135, "Starting HP: "); + text( 8, 143, "Starting MP: "); + text(167, 135, " ".. shp); + text(167, 143, " ".. smp); + lifebar( 68, 136, 100, 4, shp, 64, "#ffcc00", "#880000"); + lifebar( 68, 144, 100, 4, smp, 64, "#9999ff", "#0000dd"); + + text(194, 136, "Strength: ".. strength); + text(194, 146, "Magic:"); + if smp >= 60 then + text(204, 162, "Fireball"); + end; + if smp >= 40 then + text(204, 154, "Heal"); + end; + + + + graphx = 17; + graphy = 160; + + text(graphx - 10, graphy + 63, "Lv."); + + for i = 1, 12 do + thispointx = i * 15 + graphx; + line(thispointx, graphy, thispointx, graphy + 63, "#000088"); + text(thispointx - 4 - (string.len(string.format("%d", i)) - 1) * 3, graphy + 63, string.format("%d", i)); + end; + + + for i = 0, 7 do + lg = i * 3; + thispointy = graphy + 63 - (lg) * 3; + line(graphx + 15, thispointy, graphx + 180, thispointy, "#000088"); + + if exptable[lg] then + temp = string.format("%d", exptable[lg]); + text(graphx - 17, thispointy - 4, string.format("%5d", exptable[lg])); + end; + + end; + + line(graphx + 15, graphy , graphx + 15, graphy + 63, "#9999ff"); + line(graphx + 15, graphy + 63, graphx + 180, graphy + 63, "#9999ff"); + +-- filledbox(graphx + 19, graphy + 1, graphx + 73, graphy + 8, "#666666"); + text(graphx + 16, graphy - 1, "EXP Growth"); + + if btype <= 2 then + + lastpointx = graphx; + lastpointy = graphy + 180; + for i = 1, 12 do + thispointx = i * 15 + graphx; + thispointy = graphy + 63 - (leveltable[btype][i] * 3); + line(lastpointx, lastpointy, thispointx, thispointy, "#ffffff"); + lastpointx = thispointx; + lastpointy = thispointy; + end; + + else + +-- filledbox(graphx + 75, graphy + 27, graphx + 119, graphy + 35, "#666666"); + text(graphx + 74, graphy + 26, " Random "); + + + end; + + line(194, 145, 254, 145, "#000000"); + line( 8, 153, 192, 153, "#000000"); + +end; + + + + + +-- ************************************************************************************ +-- ************************************************************************************ +-- ************************************************************************************ + +function keyintercept() + tmp = memory.readbyte(0x0026); + + if AND(tmp, 0x04) == 0x04 then + mapstyle = math.fmod(mapstyle + 1, 3) + end; + +-- memory.writebyte(0x0026, AND(tmp, 0xFB)); +end; + +memory.register(0x0026, keyintercept); + + + + + + + + +timer = 0; +mapstyle = 1; -- 0 = hidden, 1 = mini, 2 = bigmap +gamemode = 0; + +itemlist = {}; +itemlist[0x01] = "Lantrn"; +itemlist[0x02] = "Lantrn2"; +itemlist[0x03] = "Potion"; +itemlist[0x04] = "Potion2"; +itemlist[0x05] = "Antidt"; +itemlist[0x06] = "Antidt2"; +itemlist[0x07] = "Key"; +itemlist[0x08] = "GoldKey"; +itemlist[0x09] = "Ax"; +itemlist[0x0a] = "Ax2"; +itemlist[0x0b] = "Sword"; +itemlist[0x0c] = "Sword2"; +itemlist[0x0d] = "PwSword"; +itemlist[0x0e] = "PwSword2"; +itemlist[0x0f] = "MsSword"; +itemlist[0x10] = "SandraSl"; +itemlist[0x11] = "Mantle"; +itemlist[0x12] = "Mantle2"; +itemlist[0x13] = "Helmet"; +itemlist[0x14] = "Helmet2"; +itemlist[0x15] = "Tent"; +itemlist[0x16] = "Tent2"; +itemlist[0x17] = "Tiara"; +itemlist[0x18] = "Whale"; +itemlist[0x19] = "CureAll"; +itemlist[0x1a] = "TimeKey"; +itemlist[0x1b] = "Ship"; +itemlist[0x1c] = "Cash"; + +exptable = { + 0, + 20, + 50, + 90, + 150, + 230, + 350, + 510, + 750, + 1100, + 1600, + 2200, + 3200, + 4400, + 6400, + 9000, + 12000, + 15000, + 20000, + 30000, + 40000, + 50000, + }; + +leveltable = {}; +leveltable[0] = { 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x13, 0x14}; +leveltable[1] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x07, 0x0A, 0x0D, 0x10, 0x13, 0x14, 0x15}; +leveltable[2] = { 0x00, 0x03, 0x06, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13}; + +asigns = {}; +asigns[0x00] = "Aries"; +asigns[0x01] = "Taurus"; +asigns[0x02] = "Gemini"; +asigns[0x03] = "Cancer"; +asigns[0x04] = "Leo"; +asigns[0x05] = "Virgo"; +asigns[0x06] = "Libra"; +asigns[0x07] = "Scorpio"; +asigns[0x08] = "Sagittarius"; +asigns[0x09] = "Capricorn"; +asigns[0x0A] = "Aquarius"; +asigns[0x0B] = "Pisces"; + +btypes = {}; +btypes[0x00] = "A"; +btypes[0x01] = "B"; +btypes[0x02] = "O"; +btypes[0x03] = "AB"; + + +mapdots = {}; +mapdots[1] = {x = 996, y = 1888, color = "#4444ff"}; -- house +mapdots[2] = {x = 773, y = 989, color = "#4444ff"}; -- house + +mapdots[3] = {x = 266, y = 2263, color = "#00ff00"}; -- warp point +mapdots[4] = {x = 1800, y = 216, color = "#00ff00"}; -- warp point +mapdots[5] = {x = 776, y = 344, color = "#00ff00"}; -- warp point +mapdots[6] = {x = 2055, y = 2008, color = "#00ff00"}; -- warp point + +mapdots[7] = {x = 1863, y = 2045, color = "#dd0000", name = "South Pyramid"}; -- s.pyramid +mapdots[8] = {x = 1607, y = 381, color = "#dd0000", name = "North Pyramid"}; -- n.pyramid + + + +mappoints = table.maxn(mapdots); + +while (true) do + + + timer = timer +1; -- timer for script events + + gamemode = memory.readbyte(0x0029); -- game mode + + + if gamemode == 0x05 or gamemode == 0x01 or gamemode == 0x06 or gamemode == 0x08 then + gameloop(); + + elseif gamemode == 0x02 then + charaselect(); + else + +-- gametime = memory.readbyte(0x0031) * 0x3c + memory.readbyte(0x0030); -- game-time +-- gamehour = math.floor(gametime / 320); +-- gameminute = math.floor((gametime - 320 * gamehour) / 320 * 60); + + gametimer1 = memory.readbyte(0x0031); + gametimer2 = memory.readbyte(0x0030); + + text(190, 8, string.format("Timer: %02X %02X", gametimer1, gametimer2)); + text(189, 23, string.format("GameMode: %02x", gamemode)); + lifebar(191, 16, 60, 2, gametimer1, 0x80, "#ffffff", "#777777", true); + lifebar(191, 20, 60, 0, gametimer2, 0x3c, "#cccccc", "#555555", true); + end; + + FCEU.frameadvance(); + +end; diff --git a/branches/fceux-2.2.2/output/luaScripts/x_functions.lua b/branches/fceux-2.2.2/output/luaScripts/x_functions.lua new file mode 100644 index 00000000..a6d01c24 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/x_functions.lua @@ -0,0 +1,262 @@ + +x_func_version = 6; + +--[[ + Minor version history: + + v5 ----------- + - Added Bisqwit's 'clone table' function. + + v6 ----------- + - added pairs by keys + - added hitbox functions + + + +]] + + + + +-- Draws a line from x1,y1 to x2,y2 using color + +function line(x1,y1,x2,y2,color) + if (x1 >= 0 and x1 <= 255 and x2 >= 0 and x2 <= 255 and y1 >= 0 and y1 <= 244 and y2 >= 0 and y2 <= 244) then + local success = pcall(function() gui.drawline(x1,y1,x2,y2,color) end); + if not success then + text(60, 224, "ERROR: ".. x1 ..",".. y1 .." ".. x2 ..",".. y2); + end; + end; +end; + + +-- Puts text on-screen (duh) +function text(x,y,str) + if str == nil then + str = "nil"; + end; + if (x >= 0 and x <= 255 and y >= 0 and y <= 240) then + gui.text(x,y,str); + end; +end; + +-- Sets the pixel at x, y to color +function pixel(x,y,color) + if (x >= 0 and x <= 255 and y >= 0 and y <= 240) then + gui.drawpixel(x,y,color); + end; +end; + + +-- Draws a rectangle from x1,y1 to x2, y2 +function box(x1,y1,x2,y2,color) + if (x1 >= 0 and x1 <= 255 and x2 >= 0 and x2 <= 255 and y1 >= 0 and y1 <= 244 and y2 >= 0 and y2 <= 244) then +--[[ local success = pcall(function() gui.drawbox(x1,y1,x2,y2,color); end); + if not success then + text(60, 150, string.format("%3d %3d %3d %3d", x1, y1, x2, y2)); + FCEU.pause(); + end; +]] gui.drawbox(x1,y1,x2,y2,color); + end; +end; + + +-- Draws a filled box from x1, y1 to x2, y2 (warning: can be slow if drawing large boxes) +function filledbox(x1,y1,x2,y2,color) + for i = 0, math.abs(y1 - y2) do + line(x1,y1 + i,x2,y1 + i,color); + end; +end; + + + +-- Draws a life-bar. +-- x, y: position of top-right +-- sx, sy: width and height of ACTUAL BAR (0 is the smallest height (1px)) +-- a1, a2: Amounts (a1/a2*100 = % of bar filled) +-- oncolor, offcolor: "bar", "background" +-- noborder: set to "true" if you just want a black outline without the white + +function lifebar(x, y, sx, sy, a1, a2, oncolor, offcolor, outerborder, innerborder) + -- this function will have the effect of drawing an HP bar + -- keep in mind xs and ys are 2px larger to account for borders + + x1 = x; + x2 = x + sx + 4; + y1 = y; + y2 = y + sy + 4; + w = math.floor(a1 / math.max(1, a1, a2) * sx); + if not a2 then w = 0 end; + + outer = outerborder; + inner = innerborder; + + if (outer == true or outer == false) and (inner == nil) then + -- legacy + outer = nil; + inner = "#000000"; + + elseif outer == nil and inner == nil then + outer = "#000000"; + inner = "#ffffff"; + + elseif inner == nil then + inner = "#ffffff"; + end; + + if (inner) then + box(x1 + 1, y1 + 1, x2 - 1, y2 - 1, inner); + end; + if (outer) then + box(x1 , y1 , x2 , y2 , outer); + end; + + if (w < sx) then + filledbox(x1 + w + 2, y1 + 2, x2 - 2, y2 - 2, offcolor); + end; + + if (w > 0) then + filledbox(x1 + 2, y1 + 2, x1 + 2 + w, y2 - 2, oncolor); + end; + +end; + + + +function graph(x, y, sx, sy, minx, miny, maxx, maxy, xval, yval, color, border, filled) + + + if (filled ~= nil) then + filledbox(x + 1, y + 1, x+sx, y+sy, "#000000"); + end; + if (border ~= nil) then + box(x, y, x+sx+1, y+sy+1, color); + end; + + + xp = (xval - minx) / (maxx - minx) * sx; + yp = (yval - miny) / (maxy - miny) * sy; + + line(x + 1 , yp + y + 1, x + sx + 1, yp + y + 1, color); + line(xp + x + 1, y + 1 , xp + x + 1, y + sy + 1, color); + + return true; +end; + + +-- Bisqwit's clone table feature. +table.clone = function(table) + local res = {} + for k,v in pairs(table)do + res[k]=v + end + return res +end + +spairs = function (t, f) + local a = {} + for n in pairs(t) do table.insert(a, n) end + table.sort(a, f) + local i = 0 -- iterator variable + local iter = function () -- iterator function + i = i + 1 + if a[i] == nil then return nil + else return a[i], t[a[i]] + end + end + return iter +end + + +-- **************************************************************************** +-- * hitbox( coords1, coords2, con, coff ) +-- * Checks if any point of coords1 is within coords2. +-- * con/coff determine what colors of box to draw. +-- **************************************************************************** +function hitbox(b1x1, b1y1, b1x2, b1y2, b2x1, b2y1, b2x2, b2y2, con, coff) + + if not b1x1 then + text(0, 8, "ERROR!!!!"); + return; + end; + + local noboxes = false; + if con == nil and coff == nil then + noboxes = true; + else + if coff == nil then + coff = "#00ff00" + end; + + if con == nil then + con = "#dd0000"; + end; + if coff == nil then + coff = "#00ff00" + end; + end; + + boxes = {{ + x = {b1x1, b1x2}, + y = {b1y1, b1y2}, + }, { + x = {b2x1, b2x2}, + y = {b2y1, b2y2}, + }}; + + hit = false; + + for xc = 1, 2 do + for yc = 1, 2 do + + if (boxes[1]['x'][xc] >= boxes[2]['x'][1]) and + (boxes[1]['y'][yc] >= boxes[2]['y'][1]) and + (boxes[1]['x'][xc] <= boxes[2]['x'][2]) and + (boxes[1]['y'][yc] <= boxes[2]['y'][2]) then + + hit = true; + -- TODO: make this break out of the for loop? might not be worth it + end; + end; + end; + + if hit == true then + if not noboxes then box(b2x1, b2y1, b2x2, b2y2, con); end; + return true; + else + if not noboxes then box(b2x1, b2y1, b2x2, b2y2, coff); end; + return false; + end; + + return true; + +end; + + + +function x_requires(required) + -- Sanity check. If they require a newer version, let them know. + timer = 1; + if x_func_version < required then + + while (true) do + timer = timer + 1; + + for i = 0, 32 do + box( 6, 28 + i, 250, 92 - i, "#000000"); + end; + + text( 10, 32, string.format("This Lua script requires version %02d or greater.", required)); + text( 43, 42, string.format("Your x_functions.lua is version %02d.", x_func_version)); + text( 29, 58, "Please check for an updated version at"); + text( 14, 69, "http://xkeeper.shacknet.nu:5/"); + text(114, 78, "emu/nes/lua/x_functions.lua"); + + warningboxcolor = string.format("%02X", math.floor(math.abs(30 - math.fmod(timer, 60)) / 30 * 0xFF)); + box(7, 29, 249, 91, "#ff" .. warningboxcolor .. warningboxcolor); + + FCEU.frameadvance(); + end; + + end; +end; \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/luaScripts/x_interface.lua b/branches/fceux-2.2.2/output/luaScripts/x_interface.lua new file mode 100644 index 00000000..b2b333c9 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/x_interface.lua @@ -0,0 +1,116 @@ +-- **************************************************************************** +-- * +-- * FCEUX Lua GUI tools +-- * +-- **************************************************************************** + + +control = {}; + +last = {}; +inpt = { xmouse = 0, ymouse = 0 }; + +-- **************************************************************************** +-- * input.update() +-- * Updates input changes and calculates mouse movement averages. +-- **************************************************************************** +function input.update() + + last = table.clone(inpt); + inpt = input.get(); + +end; + + +-- **************************************************************************** +-- * control.button( xpos, ypos, width, height, t ) +-- * Draws a button that can have some effect. Not quite implemented yet! +-- * width/height are for the outline and more or less have to be set manually. +-- * since height is fixed, though, it's always a multiple. +-- * c disables hitbox checking and sets the outline to that color +-- **************************************************************************** +function control.button(x, y, w, h, t, c, sc) + local h = h * 8; + filledbox( x , y , x + w , y + h , "#000000"); + text(x - 1, y - 1, t); -- Yeah, for some reason... + + if c and not sc then + box( x - 1, y - 1, x + w + 1, y + h + 1, c); + elseif c then + return (hitbox(inpt['xmouse'], inpt['ymouse'], inpt['xmouse'], inpt['ymouse'], x - 1, y - 1, x + w + 1, y + h + 1, c, c) and (inpt['leftclick'] and not last['leftclick'])); + + elseif hitbox(inpt['xmouse'], inpt['ymouse'], inpt['xmouse'], inpt['ymouse'], x - 1, y - 1, x + w + 1, y + h + 1, "#6666ff", "#0000ff") and (inpt['leftclick'] and not last['leftclick']) then + box(x - 1, y - 1, x + w + 1, y + h + 1, "#ffffff"); -- for white-flash highlighting + return true; + end; + return false; + +end; + + + +-- **************************************************************************** +-- * control.showmenu( xpos, ypos, menutable ) +-- * Displays the given menu and takes action on it. Usually. +-- **************************************************************************** +function control.showmenu(x, y, menuinfo) + + + if menuinfo['life'] > 0 then + local temp = 0; + local i = 0; + local yscale = 11 - math.max(0, menuinfo['life'] - 60); +-- text(x, y - 11, string.format("Life: %3d", menuinfo['life'])); + + for k, v in spairs(menuinfo['menu']) do + + local buttoncolor = nil; + if v['menu'] and v['life'] > 0 then + buttoncolor = "#ffffff"; + end; + + buttonclicked = control.button(x, y + yscale * i, menuinfo['width'], 1, v['label'], buttoncolor, true); + if v['menu'] then + text(x + menuinfo['width'] - 6, y + yscale * i - 1, ">"); + end; + if v['marked'] == 1 then + text(x, y + yscale * i - 1, ">"); + end; + + -- is a selection, not a submenu + if buttonclicked and v['action'] then + v['action'](v['args']); + menuinfo['life'] = 0; + return -1; + + -- a submenu + elseif buttonclicked and v['menu'] then + v['life'] = 70; + end; + + if v['menu'] and v['life'] > 0 and temp >= 0 then + temp2 = control.showmenu(x + menuinfo['width'] + 3, y + yscale * i, v); + if temp2 >= 0 then + temp = math.max(temp, temp2); + else + temp = temp2; + end; + end; + + i = i + 1; + + end; + if temp >= 0 and hitbox(inpt['xmouse'], inpt['ymouse'], inpt['xmouse'], inpt['ymouse'], x, y, x + menuinfo['width'] + 2, y + i * yscale) then + menuinfo['life'] = math.max(menuinfo['life'] - 1, 60); + elseif temp == -1 or (menuinfo['life'] < 60 and inpt['leftclick'] and not last['leftclick']) then + menuinfo['life'] = 0; + return 0; + else + menuinfo['life'] = math.max(math.min(60, temp), menuinfo['life'] - 1); + end; + end; + + return menuinfo['life']; + +end; + diff --git a/branches/fceux-2.2.2/output/luaScripts/x_smb1enemylist.lua b/branches/fceux-2.2.2/output/luaScripts/x_smb1enemylist.lua new file mode 100644 index 00000000..661aa7e0 --- /dev/null +++ b/branches/fceux-2.2.2/output/luaScripts/x_smb1enemylist.lua @@ -0,0 +1,44 @@ +-- temporary file because this will be huge. + +handles = {}; + +handles[ 1] = { x1 = 0, y1 = 0, x2 = 16, y2 = 24 }; -- Green & Red Koopa +handles[ 2] = { x1 = 0, y1 = 8, x2 = 16, y2 = 24 }; -- Goomba +handles[ 3] = { x1 = 0, y1 = 0, x2 = 16, y2 = 16 }; -- generic 16x16 +handles[ 4] = { x1 = 0, y1 = 0, x2 = 8, y2 = 8 }; -- generic 8x 8 + + +enemylist = {}; + +-- type: +-- Default (0): selectable, standard +-- + 0x01: requires special handling +-- + 0x02: can't be selected (dupe, whatever) +-- + 0x10: requires two spaces to summon +-- + 0x20: powerup +--[[ +enemylist[] = { id = 0x00, name = "Green Koopa", handle = 1, hitbox = 0x03, type = 0x00 }; +enemylist[] = { id = 0x01, name = "Red Koopa", handle = 1, hitbox = 0x03, type = 0x01 }; -- Will jitter back and forth if moved into air + +enemylist[] = { id = 0x06, name = "Goomba", handle = 2, hitbox = 0x09, type = 0x00 }; +enemylist[] = { id = 0x07, name = "Blooper", handle = 1, hitbox = 0x09, type = 0x01 }; -- Uhh? It just vanishes out of nowhere... + +enemylist[] = { id = 0x0A, name = "Gray Cheep-Cheep", handle = 2, hitbox = 0x09, type = 0x00 }; +enemylist[] = { id = 0x0B, name = "Red Cheep-Cheep", handle = 2, hitbox = 0x09, type = 0x00 }; + +enemylist[] = { id = 0x0D, name = "Pirahna Plant", handle = 1, hitbox = 0x09, type = 0x01 }; -- x speed is really y speed, main position needs hacked +enemylist[] = { id = 0x0E, name = "Green Paratroopa", handle = 1, hitbox = 0x03, type = 0x00 }; + +enemylist[] = { id = 0x14, name = "Flying Cheepcheep", handle = 2, hitbox = 0x09, type = 0x00 }; + + +enemylist[] = { id = 0x2E, name = "Mushroom", handle = 3, hitbox = 0x03, type = 0x20, powerupval = 0x00 }; +enemylist[] = { id = 0x2E, name = "Flower", handle = 3, hitbox = 0x03, type = 0x20, powerupval = 0x01 }; +enemylist[] = { id = 0x2E, name = "Starman", handle = 3, hitbox = 0x03, type = 0x20, powerupval = 0x02 }; +enemylist[] = { id = 0x2E, name = "1-up Mushroom", handle = 3, hitbox = 0x03, type = 0x20, powerupval = 0x03 }; +enemylist[] = { id = 0x30, name = "Flagpole flag", handle = 3, hitbox = -1, type = 0x20 }; +enemylist[] = { id = 0x31, name = "Castle flag", handle = 3, hitbox = -1, type = 0x00 }; +enemylist[] = { id = 0x32, name = "Springboard", handle = 1, hitbox = -1, type = 0x00 }; + + +]] \ No newline at end of file diff --git a/branches/fceux-2.2.2/output/palettes/ASQ_realityA.pal b/branches/fceux-2.2.2/output/palettes/ASQ_realityA.pal new file mode 100644 index 00000000..8c935870 Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/ASQ_realityA.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/ASQ_realityB.pal b/branches/fceux-2.2.2/output/palettes/ASQ_realityB.pal new file mode 100644 index 00000000..1d36d597 Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/ASQ_realityB.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/BMF_final2.pal b/branches/fceux-2.2.2/output/palettes/BMF_final2.pal new file mode 100644 index 00000000..01fd7161 Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/BMF_final2.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/BMF_final3.pal b/branches/fceux-2.2.2/output/palettes/BMF_final3.pal new file mode 100644 index 00000000..d1560114 Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/BMF_final3.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/FCEU-13-default_nitsuja.pal b/branches/fceux-2.2.2/output/palettes/FCEU-13-default_nitsuja.pal new file mode 100644 index 00000000..9367073b Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/FCEU-13-default_nitsuja.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/FCEU-15-nitsuja_new.pal b/branches/fceux-2.2.2/output/palettes/FCEU-15-nitsuja_new.pal new file mode 100644 index 00000000..4765e546 Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/FCEU-15-nitsuja_new.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/FCEUX.pal b/branches/fceux-2.2.2/output/palettes/FCEUX.pal new file mode 100644 index 00000000..7bf9128f Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/FCEUX.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/nestopia_rgb.pal b/branches/fceux-2.2.2/output/palettes/nestopia_rgb.pal new file mode 100644 index 00000000..d2d3d923 Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/nestopia_rgb.pal differ diff --git a/branches/fceux-2.2.2/output/palettes/nestopia_yuv.pal b/branches/fceux-2.2.2/output/palettes/nestopia_yuv.pal new file mode 100644 index 00000000..4bb868ec Binary files /dev/null and b/branches/fceux-2.2.2/output/palettes/nestopia_yuv.pal differ diff --git a/branches/fceux-2.2.2/output/taseditor.chm b/branches/fceux-2.2.2/output/taseditor.chm new file mode 100644 index 00000000..c0318726 Binary files /dev/null and b/branches/fceux-2.2.2/output/taseditor.chm differ diff --git a/branches/fceux-2.2.2/output/tools/taseditor_patterns.txt b/branches/fceux-2.2.2/output/tools/taseditor_patterns.txt new file mode 100644 index 00000000..a584bd4b --- /dev/null +++ b/branches/fceux-2.2.2/output/tools/taseditor_patterns.txt @@ -0,0 +1,15 @@ +Alternating (1010...) +10 +Alternating at 30FPS (11001100...) +1100 +One Quarter (10001000...) +1000 +Tap'n'Hold (101111111...) +1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 +One-Two (1011010110...) +10110 + +FORMAT OF THIS FILE: 2 lines per every Pattern - first line is the name, second line is looped sequence of presses: 1 = press button, 0 = don't press button. + + + diff --git a/branches/fceux-2.2.2/src/.gitignore b/branches/fceux-2.2.2/src/.gitignore new file mode 100644 index 00000000..7061d616 --- /dev/null +++ b/branches/fceux-2.2.2/src/.gitignore @@ -0,0 +1 @@ +/fceu diff --git a/branches/fceux-2.2.2/src/SConscript b/branches/fceux-2.2.2/src/SConscript new file mode 100644 index 00000000..4713e155 --- /dev/null +++ b/branches/fceux-2.2.2/src/SConscript @@ -0,0 +1,42 @@ +import glob +file_list = glob.glob('*.cpp') +file_list.remove('lua-engine.cpp') # use logic below for this + +subdirs = Split(""" +boards +drivers/common +fir +input +utils +""") +#palettes + +Import('env') +Export('env') + +if env['LUA']: + file_list.append('lua-engine.cpp') + if env['SYSTEM_LUA'] == 0: + subdirs.append('lua') + +if env['CREATE_AVI']: + subdirs.append('drivers/videolog') + + + +for dir in subdirs: + subdir_files = SConscript('%s/SConscript' % dir) + file_list.append(subdir_files) +if env['PLATFORM'] == 'win32': + platform_files = SConscript('drivers/win/SConscript') +else: + platform_files = SConscript('drivers/sdl/SConscript') +file_list.append(platform_files) + +print env['LINKFLAGS'] + +if env['PLATFORM'] == 'win32': + fceux = env.Program('fceux.exe', file_list) +else: + fceux = env.Program('fceux', file_list) +Return('fceux') diff --git a/branches/fceux-2.2.2/src/asm.cpp b/branches/fceux-2.2.2/src/asm.cpp new file mode 100644 index 00000000..5131a14d --- /dev/null +++ b/branches/fceux-2.2.2/src/asm.cpp @@ -0,0 +1,522 @@ +/// \file +/// \brief 6502 assembler and disassembler + +#include "types.h" +#include "utils/xstring.h" +#include "debug.h" +#include "asm.h" +#include "x6502.h" + +#include +#include +#include +///assembles the string to an instruction located at addr, storing opcodes in output buffer +int Assemble(unsigned char *output, int addr, char *str) { + //unsigned char opcode[3] = { 0,0,0 }; + output[0] = output[1] = output[2] = 0; + char astr[128],ins[4]; + int len = strlen(str); + if ((!len) || (len > 0x127)) return 1; + + strcpy(astr,str); + str_ucase(astr); + sscanf(astr,"%3s",ins); //get instruction + if (strlen(ins) != 3) return 1; + strcpy(astr,strstr(astr,ins)+3); //heheh, this is probably a bad idea, but let's do it anyway! + if ((astr[0] != ' ') && (astr[0] != 0)) return 1; + + //remove all whitespace + str_strip(astr,STRIP_SP|STRIP_TAB|STRIP_CR|STRIP_LF); + + //repair syntax + chr_replace(astr,'[','('); //brackets + chr_replace(astr,']',')'); + chr_replace(astr,'{','('); + chr_replace(astr,'}',')'); + chr_replace(astr,';',0); //comments + str_replace(astr,"0X","$"); //miscellaneous + + //This does the following: + // 1) Sets opcode[0] on success, else returns 1. + // 2) Parses text in *astr to build the rest of the assembled + // data in 'opcode', else returns 1 on error. + + if (!strlen(astr)) { + //Implied instructions + if (!strcmp(ins,"BRK")) output[0] = 0x00; + else if (!strcmp(ins,"PHP")) output[0] = 0x08; + else if (!strcmp(ins,"ASL")) output[0] = 0x0A; + else if (!strcmp(ins,"CLC")) output[0] = 0x18; + else if (!strcmp(ins,"PLP")) output[0] = 0x28; + else if (!strcmp(ins,"ROL")) output[0] = 0x2A; + else if (!strcmp(ins,"SEC")) output[0] = 0x38; + else if (!strcmp(ins,"RTI")) output[0] = 0x40; + else if (!strcmp(ins,"PHA")) output[0] = 0x48; + else if (!strcmp(ins,"LSR")) output[0] = 0x4A; + else if (!strcmp(ins,"CLI")) output[0] = 0x58; + else if (!strcmp(ins,"RTS")) output[0] = 0x60; + else if (!strcmp(ins,"PLA")) output[0] = 0x68; + else if (!strcmp(ins,"ROR")) output[0] = 0x6A; + else if (!strcmp(ins,"SEI")) output[0] = 0x78; + else if (!strcmp(ins,"DEY")) output[0] = 0x88; + else if (!strcmp(ins,"TXA")) output[0] = 0x8A; + else if (!strcmp(ins,"TYA")) output[0] = 0x98; + else if (!strcmp(ins,"TXS")) output[0] = 0x9A; + else if (!strcmp(ins,"TAY")) output[0] = 0xA8; + else if (!strcmp(ins,"TAX")) output[0] = 0xAA; + else if (!strcmp(ins,"CLV")) output[0] = 0xB8; + else if (!strcmp(ins,"TSX")) output[0] = 0xBA; + else if (!strcmp(ins,"INY")) output[0] = 0xC8; + else if (!strcmp(ins,"DEX")) output[0] = 0xCA; + else if (!strcmp(ins,"CLD")) output[0] = 0xD8; + else if (!strcmp(ins,"INX")) output[0] = 0xE8; + else if (!strcmp(ins,"NOP")) output[0] = 0xEA; + else if (!strcmp(ins,"SED")) output[0] = 0xF8; + else return 1; + } + else { + //Instructions with Operands + if (!strcmp(ins,"ORA")) output[0] = 0x01; + else if (!strcmp(ins,"ASL")) output[0] = 0x06; + else if (!strcmp(ins,"BPL")) output[0] = 0x10; + else if (!strcmp(ins,"JSR")) output[0] = 0x20; + else if (!strcmp(ins,"AND")) output[0] = 0x21; + else if (!strcmp(ins,"BIT")) output[0] = 0x24; + else if (!strcmp(ins,"ROL")) output[0] = 0x26; + else if (!strcmp(ins,"BMI")) output[0] = 0x30; + else if (!strcmp(ins,"EOR")) output[0] = 0x41; + else if (!strcmp(ins,"LSR")) output[0] = 0x46; + else if (!strcmp(ins,"JMP")) output[0] = 0x4C; + else if (!strcmp(ins,"BVC")) output[0] = 0x50; + else if (!strcmp(ins,"ADC")) output[0] = 0x61; + else if (!strcmp(ins,"ROR")) output[0] = 0x66; + else if (!strcmp(ins,"BVS")) output[0] = 0x70; + else if (!strcmp(ins,"STA")) output[0] = 0x81; + else if (!strcmp(ins,"STY")) output[0] = 0x84; + else if (!strcmp(ins,"STX")) output[0] = 0x86; + else if (!strcmp(ins,"BCC")) output[0] = 0x90; + else if (!strcmp(ins,"LDY")) output[0] = 0xA0; + else if (!strcmp(ins,"LDA")) output[0] = 0xA1; + else if (!strcmp(ins,"LDX")) output[0] = 0xA2; + else if (!strcmp(ins,"BCS")) output[0] = 0xB0; + else if (!strcmp(ins,"CPY")) output[0] = 0xC0; + else if (!strcmp(ins,"CMP")) output[0] = 0xC1; + else if (!strcmp(ins,"DEC")) output[0] = 0xC6; + else if (!strcmp(ins,"BNE")) output[0] = 0xD0; + else if (!strcmp(ins,"CPX")) output[0] = 0xE0; + else if (!strcmp(ins,"SBC")) output[0] = 0xE1; + else if (!strcmp(ins,"INC")) output[0] = 0xE6; + else if (!strcmp(ins,"BEQ")) output[0] = 0xF0; + else return 1; + + { + //Parse Operands + // It's not the sexiest thing ever, but it works well enough! + + //TODO: + // Add branches. + // Fix certain instructions. (Setting bits is not 100% perfect.) + // Fix instruction/operand matching. (Instructions like "jmp ($94),Y" are no good!) + // Optimizations? + int tmpint; + char tmpchr,tmpstr[20]; + + if (sscanf(astr,"#$%2X%c",&tmpint,&tmpchr) == 1) { //#Immediate + switch (output[0]) { + case 0x20: case 0x4C: //Jumps + case 0x10: case 0x30: case 0x50: case 0x70: //Branches + case 0x90: case 0xB0: case 0xD0: case 0xF0: + case 0x06: case 0x24: case 0x26: case 0x46: //Other instructions incapable of #Immediate + case 0x66: case 0x81: case 0x84: case 0x86: + case 0xC6: case 0xE6: + return 1; + default: + //cheap hack for certain instructions + switch (output[0]) { + case 0xA0: case 0xA2: case 0xC0: case 0xE0: + break; + default: + output[0] |= 0x08; + break; + } + output[1] = tmpint; + break; + } + } + else if (sscanf(astr,"$%4X%c",&tmpint,&tmpchr) == 1) { //Absolute, Zero Page, Branch, or Jump + switch (output[0]) { + case 0x20: case 0x4C: //Jumps + output[1] = (tmpint & 0xFF); + output[2] = (tmpint >> 8); + break; + case 0x10: case 0x30: case 0x50: case 0x70: //Branches + case 0x90: case 0xB0: case 0xD0: case 0xF0: + tmpint -= (addr+2); + if ((tmpint < -128) || (tmpint > 127)) return 1; + output[1] = (tmpint & 0xFF); + break; + //return 1; //FIX ME + default: + if (tmpint > 0xFF) { //Absolute + output[0] |= 0x0C; + output[1] = (tmpint & 0xFF); + output[2] = (tmpint >> 8); + } + else { //Zero Page + output[0] |= 0x04; + output[1] = (tmpint & 0xFF); + } + break; + } + } + else if (sscanf(astr,"$%4X%s",&tmpint,tmpstr) == 2) { //Absolute,X, Zero Page,X, Absolute,Y or Zero Page,Y + if (!strcmp(tmpstr,",X")) { //Absolute,X or Zero Page,X + switch (output[0]) { + case 0x20: case 0x4C: //Jumps + case 0x10: case 0x30: case 0x50: case 0x70: //Branches + case 0x90: case 0xB0: case 0xD0: case 0xF0: + case 0x24: case 0x86: case 0xA2: case 0xC0: //Other instructions incapable of Absolute,X or Zero Page,X + case 0xE0: + return 1; + default: + if (tmpint > 0xFF) { //Absolute + if (output[0] == 0x84) return 1; //No STY Absolute,X! + output[0] |= 0x1C; + output[1] = (tmpint & 0xFF); + output[2] = (tmpint >> 8); + } + else { //Zero Page + output[0] |= 0x14; + output[1] = (tmpint & 0xFF); + } + break; + } + } + else if (!strcmp(tmpstr,",Y")) { //Absolute,Y or Zero Page,Y + switch (output[0]) { + case 0x20: case 0x4C: //Jumps + case 0x10: case 0x30: case 0x50: case 0x70: //Branches + case 0x90: case 0xB0: case 0xD0: case 0xF0: + case 0x06: case 0x24: case 0x26: case 0x46: //Other instructions incapable of Absolute,Y or Zero Page,Y + case 0x66: case 0x84: case 0x86: case 0xA0: + case 0xC0: case 0xC6: case 0xE0: case 0xE6: + return 1; + case 0xA2: //cheap hack for LDX + output[0] |= 0x04; + default: + if (tmpint > 0xFF) { //Absolute + if (output[0] == 0x86) return 1; //No STX Absolute,Y! + output[0] |= 0x18; + output[1] = (tmpint & 0xFF); + output[2] = (tmpint >> 8); + } + else { //Zero Page + if ((output[0] != 0x86) && (output[0] != 0xA2)) return 1; //only STX and LDX Absolute,Y! + output[0] |= 0x10; + output[1] = (tmpint & 0xFF); + } + break; + } + } + else return 1; + } + else if (sscanf(astr,"($%4X%s",&tmpint,tmpstr) == 2) { //Jump (Indirect), (Indirect,X) or (Indirect),Y + switch (output[0]) { + case 0x20: //Jumps + case 0x10: case 0x30: case 0x50: case 0x70: //Branches + case 0x90: case 0xB0: case 0xD0: case 0xF0: + case 0x06: case 0x24: case 0x26: case 0x46: //Other instructions incapable of Jump (Indirect), (Indirect,X) or (Indirect),Y + case 0x66: case 0x84: case 0x86: case 0xA0: + case 0xA2: case 0xC0: case 0xC6: case 0xE0: + case 0xE6: + return 1; + default: + if ((!strcmp(tmpstr,")")) && (output[0] == 0x4C)) { //Jump (Indirect) + output[0] = 0x6C; + output[1] = (tmpint & 0xFF); + output[2] = (tmpint >> 8); + } + else if ((!strcmp(tmpstr,",X)")) && (tmpint <= 0xFF) && (output[0] != 0x4C)) { //(Indirect,X) + output[1] = (tmpint & 0xFF); + } + else if ((!strcmp(tmpstr,"),Y")) && (tmpint <= 0xFF) && (output[0] != 0x4C)) { //(Indirect),Y + output[0] |= 0x10; + output[1] = (tmpint & 0xFF); + } + else return 1; + break; + } + } + else return 1; + } + } + + return 0; +} + +///disassembles the opcodes in the buffer assuming the provided address. Uses GetMem() and 6502 current registers to query referenced values. returns a static string buffer. +char *Disassemble(int addr, uint8 *opcode) { + static char str[64]={0},chr[5]={0}; + uint16 tmp,tmp2; + + //these may be replaced later with passed-in values to make a lighter-weight disassembly mode that may not query the referenced values + #define RX (X.X) + #define RY (X.Y) + + switch (opcode[0]) { + #define relative(a) { \ + if (((a)=opcode[1])&0x80) (a) = addr-(((a)-1)^0xFF); \ + else (a)+=addr; \ + } + #define absolute(a) { \ + (a) = opcode[1] | opcode[2]<<8; \ + } + #define zpIndex(a,i) { \ + (a) = opcode[1]+(i); \ + } + #define indirectX(a) { \ + (a) = (opcode[1]+RX)&0xFF; \ + (a) = GetMem((a)) | (GetMem((a)+1))<<8; \ + } + #define indirectY(a) { \ + (a) = GetMem(opcode[1]) | (GetMem(opcode[1]+1))<<8; \ + (a) += RY; \ + } + + + //odd, 1-byte opcodes + case 0x00: strcpy(str,"BRK"); break; + case 0x08: strcpy(str,"PHP"); break; + case 0x0A: strcpy(str,"ASL"); break; + case 0x18: strcpy(str,"CLC"); break; + case 0x28: strcpy(str,"PLP"); break; + case 0x2A: strcpy(str,"ROL"); break; + case 0x38: strcpy(str,"SEC"); break; + case 0x40: strcpy(str,"RTI"); break; + case 0x48: strcpy(str,"PHA"); break; + case 0x4A: strcpy(str,"LSR"); break; + case 0x58: strcpy(str,"CLI"); break; + case 0x60: strcpy(str,"RTS"); break; + case 0x68: strcpy(str,"PLA"); break; + case 0x6A: strcpy(str,"ROR"); break; + case 0x78: strcpy(str,"SEI"); break; + case 0x88: strcpy(str,"DEY"); break; + case 0x8A: strcpy(str,"TXA"); break; + case 0x98: strcpy(str,"TYA"); break; + case 0x9A: strcpy(str,"TXS"); break; + case 0xA8: strcpy(str,"TAY"); break; + case 0xAA: strcpy(str,"TAX"); break; + case 0xB8: strcpy(str,"CLV"); break; + case 0xBA: strcpy(str,"TSX"); break; + case 0xC8: strcpy(str,"INY"); break; + case 0xCA: strcpy(str,"DEX"); break; + case 0xD8: strcpy(str,"CLD"); break; + case 0xE8: strcpy(str,"INX"); break; + case 0xEA: strcpy(str,"NOP"); break; + case 0xF8: strcpy(str,"SED"); break; + + //(Indirect,X) + case 0x01: strcpy(chr,"ORA"); goto _indirectx; + case 0x21: strcpy(chr,"AND"); goto _indirectx; + case 0x41: strcpy(chr,"EOR"); goto _indirectx; + case 0x61: strcpy(chr,"ADC"); goto _indirectx; + case 0x81: strcpy(chr,"STA"); goto _indirectx; + case 0xA1: strcpy(chr,"LDA"); goto _indirectx; + case 0xC1: strcpy(chr,"CMP"); goto _indirectx; + case 0xE1: strcpy(chr,"SBC"); goto _indirectx; + _indirectx: + indirectX(tmp); + sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + break; + + //Zero Page + case 0x05: strcpy(chr,"ORA"); goto _zeropage; + case 0x06: strcpy(chr,"ASL"); goto _zeropage; + case 0x24: strcpy(chr,"BIT"); goto _zeropage; + case 0x25: strcpy(chr,"AND"); goto _zeropage; + case 0x26: strcpy(chr,"ROL"); goto _zeropage; + case 0x45: strcpy(chr,"EOR"); goto _zeropage; + case 0x46: strcpy(chr,"LSR"); goto _zeropage; + case 0x65: strcpy(chr,"ADC"); goto _zeropage; + case 0x66: strcpy(chr,"ROR"); goto _zeropage; + case 0x84: strcpy(chr,"STY"); goto _zeropage; + case 0x85: strcpy(chr,"STA"); goto _zeropage; + case 0x86: strcpy(chr,"STX"); goto _zeropage; + case 0xA4: strcpy(chr,"LDY"); goto _zeropage; + case 0xA5: strcpy(chr,"LDA"); goto _zeropage; + case 0xA6: strcpy(chr,"LDX"); goto _zeropage; + case 0xC4: strcpy(chr,"CPY"); goto _zeropage; + case 0xC5: strcpy(chr,"CMP"); goto _zeropage; + case 0xC6: strcpy(chr,"DEC"); goto _zeropage; + case 0xE4: strcpy(chr,"CPX"); goto _zeropage; + case 0xE5: strcpy(chr,"SBC"); goto _zeropage; + case 0xE6: strcpy(chr,"INC"); goto _zeropage; + _zeropage: + // ################################## Start of SP CODE ########################### + // Change width to %04X + sprintf(str,"%s $%04X = #$%02X", chr,opcode[1],GetMem(opcode[1])); + // ################################## End of SP CODE ########################### + break; + + //#Immediate + case 0x09: strcpy(chr,"ORA"); goto _immediate; + case 0x29: strcpy(chr,"AND"); goto _immediate; + case 0x49: strcpy(chr,"EOR"); goto _immediate; + case 0x69: strcpy(chr,"ADC"); goto _immediate; + //case 0x89: strcpy(chr,"STA"); goto _immediate; //baka, no STA #imm!! + case 0xA0: strcpy(chr,"LDY"); goto _immediate; + case 0xA2: strcpy(chr,"LDX"); goto _immediate; + case 0xA9: strcpy(chr,"LDA"); goto _immediate; + case 0xC0: strcpy(chr,"CPY"); goto _immediate; + case 0xC9: strcpy(chr,"CMP"); goto _immediate; + case 0xE0: strcpy(chr,"CPX"); goto _immediate; + case 0xE9: strcpy(chr,"SBC"); goto _immediate; + _immediate: + sprintf(str,"%s #$%02X", chr,opcode[1]); + break; + + //Absolute + case 0x0D: strcpy(chr,"ORA"); goto _absolute; + case 0x0E: strcpy(chr,"ASL"); goto _absolute; + case 0x2C: strcpy(chr,"BIT"); goto _absolute; + case 0x2D: strcpy(chr,"AND"); goto _absolute; + case 0x2E: strcpy(chr,"ROL"); goto _absolute; + case 0x4D: strcpy(chr,"EOR"); goto _absolute; + case 0x4E: strcpy(chr,"LSR"); goto _absolute; + case 0x6D: strcpy(chr,"ADC"); goto _absolute; + case 0x6E: strcpy(chr,"ROR"); goto _absolute; + case 0x8C: strcpy(chr,"STY"); goto _absolute; + case 0x8D: strcpy(chr,"STA"); goto _absolute; + case 0x8E: strcpy(chr,"STX"); goto _absolute; + case 0xAC: strcpy(chr,"LDY"); goto _absolute; + case 0xAD: strcpy(chr,"LDA"); goto _absolute; + case 0xAE: strcpy(chr,"LDX"); goto _absolute; + case 0xCC: strcpy(chr,"CPY"); goto _absolute; + case 0xCD: strcpy(chr,"CMP"); goto _absolute; + case 0xCE: strcpy(chr,"DEC"); goto _absolute; + case 0xEC: strcpy(chr,"CPX"); goto _absolute; + case 0xED: strcpy(chr,"SBC"); goto _absolute; + case 0xEE: strcpy(chr,"INC"); goto _absolute; + _absolute: + absolute(tmp); + sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp)); + break; + + //branches + case 0x10: strcpy(chr,"BPL"); goto _branch; + case 0x30: strcpy(chr,"BMI"); goto _branch; + case 0x50: strcpy(chr,"BVC"); goto _branch; + case 0x70: strcpy(chr,"BVS"); goto _branch; + case 0x90: strcpy(chr,"BCC"); goto _branch; + case 0xB0: strcpy(chr,"BCS"); goto _branch; + case 0xD0: strcpy(chr,"BNE"); goto _branch; + case 0xF0: strcpy(chr,"BEQ"); goto _branch; + _branch: + relative(tmp); + sprintf(str,"%s $%04X", chr,tmp); + break; + + //(Indirect),Y + case 0x11: strcpy(chr,"ORA"); goto _indirecty; + case 0x31: strcpy(chr,"AND"); goto _indirecty; + case 0x51: strcpy(chr,"EOR"); goto _indirecty; + case 0x71: strcpy(chr,"ADC"); goto _indirecty; + case 0x91: strcpy(chr,"STA"); goto _indirecty; + case 0xB1: strcpy(chr,"LDA"); goto _indirecty; + case 0xD1: strcpy(chr,"CMP"); goto _indirecty; + case 0xF1: strcpy(chr,"SBC"); goto _indirecty; + _indirecty: + indirectY(tmp); + sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + break; + + //Zero Page,X + case 0x15: strcpy(chr,"ORA"); goto _zeropagex; + case 0x16: strcpy(chr,"ASL"); goto _zeropagex; + case 0x35: strcpy(chr,"AND"); goto _zeropagex; + case 0x36: strcpy(chr,"ROL"); goto _zeropagex; + case 0x55: strcpy(chr,"EOR"); goto _zeropagex; + case 0x56: strcpy(chr,"LSR"); goto _zeropagex; + case 0x75: strcpy(chr,"ADC"); goto _zeropagex; + case 0x76: strcpy(chr,"ROR"); goto _zeropagex; + case 0x94: strcpy(chr,"STY"); goto _zeropagex; + case 0x95: strcpy(chr,"STA"); goto _zeropagex; + case 0xB4: strcpy(chr,"LDY"); goto _zeropagex; + case 0xB5: strcpy(chr,"LDA"); goto _zeropagex; + case 0xD5: strcpy(chr,"CMP"); goto _zeropagex; + case 0xD6: strcpy(chr,"DEC"); goto _zeropagex; + case 0xF5: strcpy(chr,"SBC"); goto _zeropagex; + case 0xF6: strcpy(chr,"INC"); goto _zeropagex; + _zeropagex: + zpIndex(tmp,RX); + // ################################## Start of SP CODE ########################### + // Change width to %04X + sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + // ################################## End of SP CODE ########################### + break; + + //Absolute,Y + case 0x19: strcpy(chr,"ORA"); goto _absolutey; + case 0x39: strcpy(chr,"AND"); goto _absolutey; + case 0x59: strcpy(chr,"EOR"); goto _absolutey; + case 0x79: strcpy(chr,"ADC"); goto _absolutey; + case 0x99: strcpy(chr,"STA"); goto _absolutey; + case 0xB9: strcpy(chr,"LDA"); goto _absolutey; + case 0xBE: strcpy(chr,"LDX"); goto _absolutey; + case 0xD9: strcpy(chr,"CMP"); goto _absolutey; + case 0xF9: strcpy(chr,"SBC"); goto _absolutey; + _absolutey: + absolute(tmp); + tmp2=(tmp+RY); + sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); + break; + + //Absolute,X + case 0x1D: strcpy(chr,"ORA"); goto _absolutex; + case 0x1E: strcpy(chr,"ASL"); goto _absolutex; + case 0x3D: strcpy(chr,"AND"); goto _absolutex; + case 0x3E: strcpy(chr,"ROL"); goto _absolutex; + case 0x5D: strcpy(chr,"EOR"); goto _absolutex; + case 0x5E: strcpy(chr,"LSR"); goto _absolutex; + case 0x7D: strcpy(chr,"ADC"); goto _absolutex; + case 0x7E: strcpy(chr,"ROR"); goto _absolutex; + case 0x9D: strcpy(chr,"STA"); goto _absolutex; + case 0xBC: strcpy(chr,"LDY"); goto _absolutex; + case 0xBD: strcpy(chr,"LDA"); goto _absolutex; + case 0xDD: strcpy(chr,"CMP"); goto _absolutex; + case 0xDE: strcpy(chr,"DEC"); goto _absolutex; + case 0xFD: strcpy(chr,"SBC"); goto _absolutex; + case 0xFE: strcpy(chr,"INC"); goto _absolutex; + _absolutex: + absolute(tmp); + tmp2=(tmp+RX); + sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2)); + break; + + //jumps + case 0x20: strcpy(chr,"JSR"); goto _jump; + case 0x4C: strcpy(chr,"JMP"); goto _jump; + case 0x6C: absolute(tmp); sprintf(str,"JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break; + _jump: + absolute(tmp); + sprintf(str,"%s $%04X", chr,tmp); + break; + + //Zero Page,Y + case 0x96: strcpy(chr,"STX"); goto _zeropagey; + case 0xB6: strcpy(chr,"LDX"); goto _zeropagey; + _zeropagey: + zpIndex(tmp,RY); + // ################################## Start of SP CODE ########################### + // Change width to %04X + sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp)); + // ################################## End of SP CODE ########################### + break; + + //UNDEFINED + default: strcpy(str,"ERROR"); break; + + } + + return str; +} diff --git a/branches/fceux-2.2.2/src/asm.h b/branches/fceux-2.2.2/src/asm.h new file mode 100644 index 00000000..5dff9f32 --- /dev/null +++ b/branches/fceux-2.2.2/src/asm.h @@ -0,0 +1,2 @@ +int Assemble(unsigned char *output, int addr, char *str); +char *Disassemble(int addr, uint8 *opcode); diff --git a/branches/fceux-2.2.2/src/attic/fceustr.cpp b/branches/fceux-2.2.2/src/attic/fceustr.cpp new file mode 100644 index 00000000..3904bb4c --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/fceustr.cpp @@ -0,0 +1,27 @@ +#include +#include + +#include "types.h" +#include "fceustr.h" + + +/* Creates a fceustr from a C-style string. */ +fceustr *fceustr_create(const char *str) +{ + fceustr *ret; + + ret=malloc(sizeof(fceustr)); + + ret->data=malloc(strlen(str)+1); + strcpy(ret->data,str); + + ret->len=strlen(str); + + return(ret); +} + +void fceustr_destroy(fceustr *str) +{ + if(str->data) free(str->data); + free(str); +} diff --git a/branches/fceux-2.2.2/src/attic/fceustr.h b/branches/fceux-2.2.2/src/attic/fceustr.h new file mode 100644 index 00000000..7033c3b0 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/fceustr.h @@ -0,0 +1,4 @@ +typedef struct { + uint8 *data; + uint32 len; /* Not including extra NULL character. */ +} fceustr; diff --git a/branches/fceux-2.2.2/src/attic/old fceultra docs.zip b/branches/fceux-2.2.2/src/attic/old fceultra docs.zip new file mode 100644 index 00000000..9d203c37 Binary files /dev/null and b/branches/fceux-2.2.2/src/attic/old fceultra docs.zip differ diff --git a/branches/fceux-2.2.2/src/attic/pc/dface.h b/branches/fceux-2.2.2/src/attic/pc/dface.h new file mode 100644 index 00000000..9981bd08 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dface.h @@ -0,0 +1,72 @@ +#ifdef __cplusplus +extern "C" { +#endif +#include "../common/args.h" +#include "../common/config.h" + +#include "input.h" + +extern FCEUGI *CurGame; + +extern CFGSTRUCT DriverConfig[]; +extern ARGPSTRUCT DriverArgs[]; +extern char *DriverUsage; + +void DoDriverArgs(void); +uint8 *GetBaseDirectory(void); + +int InitSound(FCEUGI *gi); +void WriteSound(int32 *Buffer, int Count); +int KillSound(void); +uint32 GetMaxSound(void); +uint32 GetWriteSound(void); + +void SilenceSound(int s); /* DOS and SDL */ + + +int InitMouse(void); +void KillMouse(void); +void GetMouseData(uint32 *MouseData); + +int InitJoysticks(void); +int KillJoysticks(void); +uint32 *GetJSOr(void); + +int InitKeyboard(void); +int UpdateKeyboard(void); +char *GetKeyboard(void); +void KillKeyboard(void); + +int InitVideo(FCEUGI *gi); +int KillVideo(void); +void BlitScreen(uint8 *XBuf); +void LockConsole(void); +void UnlockConsole(void); +void ToggleFS(); /* SDL */ + +int LoadGame(const char *path); +int CloseGame(void); +int GUI_Init(int argc, char **argv, int (*dofunc)(void)); +int GUI_Idle(void); +int GUI_Update(void); +void GUI_Hide(int); +void GUI_RequestExit(void); +int GUI_SetVideo(int fullscreen, int width, int height); +char *GUI_GetKeyboard(void); +void GUI_GetMouseState(uint32 *b, int *x, int *y); + +void UpdatePhysicalInput(void); +int DTestButton(ButtConfig *bc); +int DWaitButton(const uint8 *text, ButtConfig *bc, int wb); +int ButtonConfigBegin(void); +void ButtonConfigEnd(void); + +void Giggles(int); +void DoFun(void); + +int FCEUD_NetworkConnect(void); +#ifdef __cplusplus +} +#endif + + diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-joystick.c b/branches/fceux-2.2.2/src/attic/pc/dos-joystick.c new file mode 100644 index 00000000..05e18177 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-joystick.c @@ -0,0 +1,200 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "dos.h" +#include "dos-joystick.h" + +#define JOY_A 1 +#define JOY_B 2 +#define JOY_SELECT 4 +#define JOY_START 8 +#define JOY_UP 0x10 +#define JOY_DOWN 0x20 +#define JOY_LEFT 0x40 +#define JOY_RIGHT 0x80 + +int joy=0; +int joyBMap[6]; + +static int32 joybuttons=0; +static uint32 joyx=0; +static uint32 joyy=0; +static uint32 joyxcenter; +static uint32 joyycenter; + +static void ConfigJoystick(void); +volatile int soundjoyer=0; +volatile int soundjoyeron=0; + +/* Crude method to detect joystick. */ +static int DetectJoystick(void) +{ + uint8 b; + + outportb(0x201,0); + b=inportb(0x201); + sleep(1); + if((inportb(0x201)&3)==(b&3)) + return 0; + else + return 1; +} + +void UpdateJoyData(void) +{ + uint32 xc,yc; + + + joybuttons=((inportb(0x201)&0xF0)^0xF0)>>4; + + xc=yc=0; + + { + outportb(0x201,0); + + for(;;) + { + uint8 b; + + b=inportb(0x201); + if(!(b&3)) + break; + if(b&1) xc++; + if(b&2) yc++; + } + } + + joyx=xc; + joyy=yc; +} + +uint32 GetJSOr(void) +{ + int y; + unsigned long ret; + static int rtoggle=0; + ret=0; + + rtoggle^=1; + if(!soundo) + UpdateJoyData(); + for(y=0;y<6;y++) + if((y>=4 && rtoggle) || y<4) + if(joybuttons&joyBMap[y]) ret|=(1<=joyxcenter*1.75) ret|=JOY_RIGHT<<((joy-1)<<3); + if(joyy<=joyycenter*.25) ret|=JOY_UP<<((joy-1)<<3); + else if(joyy>=joyycenter*1.75) ret|=JOY_DOWN<<((joy-1)<<3); + + return ret; +} + +int InitJoysticks(void) +{ + if(!joy) return(0); + if(!DetectJoystick()) + { + printf("Joystick not detected!\n"); + joy=0; + return 0; + } + if(soundo) + { + soundjoyeron=1; + while(!soundjoyer); + } + else + UpdateJoyData(); + + joyxcenter=joyx; + joyycenter=joyy; + + if(!(joyBMap[0]|joyBMap[1]|joyBMap[2]|joyBMap[3])) + ConfigJoystick(); + return(1); +} + +static void BConfig(int b) +{ + int c=0; + uint32 st=time(0); + + while(time(0)< (st+4) ) + { + if(!soundo) + UpdateJoyData(); + if(joybuttons) c=joybuttons; + else if(c && !joybuttons) + { + joyBMap[b]=c; + break; + } + + } +} + +void KillJoysticks(void) +{ + +} + +static void ConfigJoystick(void) +{ + static char *genb="** Press button for "; + + printf("\n\n Joystick button configuration:\n\n"); + printf(" Push and release the button to map to the virtual joystick.\n"); + printf(" If you do not wish to assign a button, wait a few seconds\n"); + printf(" and the configuration will continue.\n\n"); + printf(" Press enter to continue...\n"); + getchar(); + + printf("%s\"Select\".\n",genb); + BConfig(2); + + printf("%s\"Start\".\n",genb); + BConfig(3); + + printf("%s\"B\".\n",genb); + BConfig(1); + + printf("%s\"A\".\n",genb); + BConfig(0); + + printf("%s\"Rapid fire B\".\n",genb); + BConfig(5); + + printf("%s\"Rapid fire A\".\n",genb); + BConfig(4); + +} + diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-joystick.h b/branches/fceux-2.2.2/src/attic/pc/dos-joystick.h new file mode 100644 index 00000000..8c50c6b2 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-joystick.h @@ -0,0 +1,27 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +void UpdateJoyData(void); +uint32 GetJSOr(void); +int InitJoysticks(void); + +/* Variables to save in config file. */ +extern int joy; +extern int joyBMap[6]; diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-keyboard.c b/branches/fceux-2.2.2/src/attic/pc/dos-keyboard.c new file mode 100644 index 00000000..b5926c3c --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-keyboard.c @@ -0,0 +1,131 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include "keyscan.h" + +static unsigned char lastsc; +static char keybuf[256]; +int newk; + +/* Read scan code from port $60 */ +/* Acknowledge interrupt( output $20 to port $20) */ + +static void ihandler(_go32_dpmi_registers *r) +{ + unsigned char scode=inp(0x60); /* Get scan code. */ + + + if(scode!=0xE0) + { + int offs=0; + + /* I'm only interested in preserving the independent status of the + right ALT and CONTROL keys. + */ + if(lastsc==0xE0) + if((scode&0x7F)==SCAN_LEFTALT || (scode&0x7F)==SCAN_LEFTCONTROL) + offs=0x80; + + + keybuf[(scode&0x7f)|offs]=((scode&0x80)^0x80); + newk++; + } + lastsc=scode; + + outp(0x20,0x20); /* Acknowledge interrupt. */ +} + +static _go32_dpmi_seginfo KBIBack,KBIBackRM; +static _go32_dpmi_seginfo KBI,KBIRM; +static _go32_dpmi_registers KBIRMRegs; +static int initdone=0; + +int InitKeyboard(void) +{ + /* I'll assume that the keyboard is in the correct scancode mode(translated + mode 2, I think). + */ + newk=0; + memset(keybuf,0,sizeof(keybuf)); + KBIRM.pm_offset=KBI.pm_offset=(int)ihandler; + KBIRM.pm_selector=KBI.pm_selector=_my_cs(); + + _go32_dpmi_get_real_mode_interrupt_vector(9,&KBIBackRM); + _go32_dpmi_allocate_real_mode_callback_iret(&KBIRM, &KBIRMRegs); + _go32_dpmi_set_real_mode_interrupt_vector(9,&KBIRM); + + _go32_dpmi_get_protected_mode_interrupt_vector(9,&KBIBack); + _go32_dpmi_allocate_iret_wrapper(&KBI); + _go32_dpmi_set_protected_mode_interrupt_vector(9,&KBI); + lastsc=0; + initdone=1; + return(1); +} + +void KillKeyboard(void) +{ + if(initdone) + { + _go32_dpmi_set_protected_mode_interrupt_vector(9,&KBIBack); + _go32_dpmi_free_iret_wrapper(&KBI); + + _go32_dpmi_set_real_mode_interrupt_vector(9,&KBIBackRM); + _go32_dpmi_free_real_mode_callback(&KBIRM); + initdone=0; + } +} + +/* In FCE Ultra, it doesn't matter if the key states change + in the middle of the keyboard handling code. If you want + to use this code elsewhere, you may want to memcpy() keybuf + to another buffer and return that when GetKeyboard() is + called. +*/ + +char *GetKeyboard(void) +{ + return keybuf; +} + +/* Returns 1 on new scan codes generated, 0 on no new scan codes. */ +int UpdateKeyboard(void) +{ + int t=newk; + + if(t) + { + asm volatile( + "subl %%eax,_newk\n\t" + : + : "a" (t) + ); + + if(keybuf[SCAN_LEFTCONTROL] && keybuf[SCAN_C]) + raise(SIGINT); + return(1); + } + return(0); +} diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-mouse.c b/branches/fceux-2.2.2/src/attic/pc/dos-mouse.c new file mode 100644 index 00000000..3e0d1142 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-mouse.c @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "dos.h" + +int InitMouse(void) +{ + __dpmi_regs regs; + + memset(®s,0,sizeof(regs)); + regs.x.ax=0; + __dpmi_int(0x33,®s); + if(regs.x.ax!=0xFFFF) + return(0); + + memset(®s,0,sizeof(regs)); + regs.x.ax=0x7; + regs.x.cx=0; // Min X + regs.x.dx=260; // Max X + __dpmi_int(0x33,®s); + + memset(®s,0,sizeof(regs)); + regs.x.ax=0x8; + regs.x.cx=0; // Min Y + regs.x.dx=260; // Max Y + __dpmi_int(0x33,®s); + + memset(®s,0,sizeof(regs)); + regs.x.ax=0xF; + regs.x.cx=8; // Mickey X + regs.x.dx=8; // Mickey Y + __dpmi_int(0x33,®s); + + memset(®s,0,sizeof(regs)); + regs.x.ax=0x2; + __dpmi_int(0x33,®s); + + return(1); +} + +uint32 GetMouseData(uint32 *x, uint32 *y) +{ + if(FCEUI_IsMovieActive()<0) + return; + + __dpmi_regs regs; + + memset(®s,0,sizeof(regs)); + regs.x.ax=0x3; + __dpmi_int(0x33,®s); + + *x=regs.x.cx; + *y=regs.x.dx; + return(regs.x.bx&3); +} + +void KillMouse(void) +{ + +} diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-sound.c b/branches/fceux-2.2.2/src/attic/pc/dos-sound.c new file mode 100644 index 00000000..e1a21fc1 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-sound.c @@ -0,0 +1,567 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dos.h" +#include "dos-sound.h" +#include "dos-joystick.h" + + +static void SBIRQHandler(_go32_dpmi_registers *r); +static uint32 LMBuffer; /* Address of low memory DMA playback buffer. */ +static int LMSelector; + +static uint8 *WaveBuffer; +static unsigned int IVector, SBIRQ, SBDMA, SBDMA16, SBPort; +static int DSPV,hsmode; +static int format; +static int frags, fragsize, fragtotal; +static volatile int WritePtr, ReadPtr; +static volatile int hbusy; +static volatile int whichbuf; + + +static uint8 PICMask; +/* Protected mode interrupt vector info. */ +static _go32_dpmi_seginfo SBIH,SBIHOld; + +/* Real mode interrupt vector info. */ +static _go32_dpmi_seginfo SBIHRM,SBIHRMOld; +static _go32_dpmi_registers SBIHRMRegs; + +static int WriteDSP(uint8 V) +{ + int x; + + for(x=65536;x;x--) + { + if(!(inportb(SBPort+0xC)&0x80)) + { + outportb(SBPort+0xC,V); + return(1); + } + } + return(0); +} + +static int ReadDSP(uint8 *V) +{ + int x; + + for(x=65536;x;x--) /* Should be more than enough time... */ + { + if(inportb(SBPort+0xE)&0x80) + { + *V=inportb(SBPort+0xA); + return(1); + } + } + return(0); +} + + +static int SetVectors(void) +{ + SBIH.pm_offset=SBIHRM.pm_offset=(int)SBIRQHandler; + SBIH.pm_selector=SBIHRM.pm_selector=_my_cs(); + + /* Get and set real mode interrupt vector. */ + _go32_dpmi_get_real_mode_interrupt_vector(IVector,&SBIHRMOld); + _go32_dpmi_allocate_real_mode_callback_iret(&SBIHRM, &SBIHRMRegs); + _go32_dpmi_set_real_mode_interrupt_vector(IVector,&SBIHRM); + + /* Get and set protected mode interrupt vector. */ + _go32_dpmi_get_protected_mode_interrupt_vector(IVector,&SBIHOld); + _go32_dpmi_allocate_iret_wrapper(&SBIH); + _go32_dpmi_set_protected_mode_interrupt_vector(IVector,&SBIH); + + return(1); +} + +static void ResetVectors(void) +{ + _go32_dpmi_set_protected_mode_interrupt_vector(IVector,&SBIHOld); + _go32_dpmi_free_iret_wrapper(&SBIH); + _go32_dpmi_set_real_mode_interrupt_vector(IVector,&SBIHRMOld); + _go32_dpmi_free_real_mode_callback(&SBIHRM); +} + +int GetBLASTER(void) +{ + int check=0; + char *s; + + if(!(s=getenv("BLASTER"))) + { + puts(" Error getting BLASTER environment variable."); + return(0); + } + + while(*s) + { + switch(toupper(*s)) + { + case 'A': check|=(sscanf(s+1,"%x",&SBPort)==1)?1:0;break; + case 'I': check|=(sscanf(s+1,"%d",&SBIRQ)==1)?2:0;break; + case 'D': check|=(sscanf(s+1,"%d",&SBDMA)==1)?4:0;break; + case 'H': check|=(sscanf(s+1,"%d",&SBDMA16)==1)?8:0;break; + } + s++; + } + + if((check^7)&7 || SBDMA>=4 || (SBDMA16<=4 && check&8) || SBIRQ>15) + { + puts(" Invalid or incomplete BLASTER environment variable."); + return(0); + } + if(!(check&8)) + format=0; + return(1); +} + +static int ResetDSP(void) +{ + uint8 b; + + outportb(SBPort+0x6,0x1); + delay(10); + outportb(SBPort+0x6,0x0); + delay(10); + + if(ReadDSP(&b)) + if(b==0xAA) + return(1); + return(0); +} + +static int GetDSPVersion(void) +{ + int ret; + uint8 t; + + if(!WriteDSP(0xE1)) + return(0); + if(!ReadDSP(&t)) + return(0); + ret=t<<8; + if(!ReadDSP(&t)) + return(0); + ret|=t; + + return(ret); +} + +static void KillDMABuffer(void) +{ + __dpmi_free_dos_memory(LMSelector); +} + +static int MakeDMABuffer(void) +{ + uint32 size; + int32 tmp; + + size=fragsize*2; /* Two buffers in the DMA buffer. */ + size<<=format; /* Twice the size for 16-bit than for 8-bit. */ + + size<<=1; /* Double the size in case the first 2 buffers + cross a 64KB or 128KB page boundary. + */ + size=(size+15)>>4; /* Convert to paragraphs */ + + if((tmp=__dpmi_allocate_dos_memory(size,&LMSelector))<0) + return(0); + + LMBuffer=tmp<<=4; + + if(format) /* Check for and fix 128KB page boundary crossing. */ + { + if((LMBuffer&0x20000) != ((LMBuffer+fragsize*2*2-1)&0x20000)) + LMBuffer+=fragsize*2*2; + } + else /* Check for and fix 64KB page boundary crossing. */ + { + if((LMBuffer&0x10000) != ((LMBuffer+fragsize*2-1)&0x10000)) + LMBuffer+=fragsize*2; + } + + DOSMemSet(LMBuffer, format?0:128, (fragsize*2)<>8); + + /* Page of buffer. */ + outportb(PPorts[format?SBDMA16:SBDMA],LMBuffer>>16); + + /* Offset of buffer within page. */ + if(format) + tmp=((SBDMA16&3)<<2)+0xc0; + else + tmp=SBDMA<<1; + + outportb(tmp,(LMBuffer>>format)); + outportb(tmp,(LMBuffer>>(8+format))); +} + +int InitSB(int Rate, int bittage) +{ + hsmode=hbusy=0; + whichbuf=1; + puts("Initializing Sound Blaster..."); + + format=bittage?1:0; + frags=8; + + if(Rate<=11025) + fragsize=1<<5; + else if(Rate<=22050) + fragsize=1<<6; + else + fragsize=1<<7; + + fragtotal=frags*fragsize; + WaveBuffer=malloc(fragtotal<65535)) + { + printf(" Unsupported playback rate: %d samples per second\n",Rate); + return(0); + } + + if(!GetBLASTER()) + return(0); + + /* Disable IRQ line in PIC0 or PIC1 */ + if(SBIRQ>7) + { + PICMask=inportb(0xA1); + outportb(0xA1,PICMask|(1<<(SBIRQ&7))); + } + else + { + PICMask=inportb(0x21); + outportb(0x21,PICMask|(1<>8,DSPV&0xFF); + if(DSPV<0x201) + { + printf(" DSP version number is too low.\n"); + return(0); + } + + if(DSPV<0x400) + format=0; + if(!MakeDMABuffer()) + { + puts(" Error creating low-memory DMA buffer."); + return(0); + } + + if(SBIRQ>7) IVector=SBIRQ+0x68; + else IVector=SBIRQ+0x8; + + if(!SetVectors()) + { + puts(" Error setting interrupt vectors."); + KillDMABuffer(); + return(0); + } + + /* Reenable IRQ line. */ + if(SBIRQ>7) + outportb(0xA1,PICMask&(~(1<<(SBIRQ&7)))); + else + outportb(0x21,PICMask&(~(1<=0x400) + { + WriteDSP(0x41); // Set sampling rate + WriteDSP(Rate>>8); // High byte + WriteDSP(Rate&0xFF); // Low byte + if(!format) + { + WriteDSP(0xC6); // 8-bit output + WriteDSP(0x00); // 8-bit mono unsigned PCM + } + else + { + WriteDSP(0xB6); // 16-bit output + WriteDSP(0x10); // 16-bit mono signed PCM + } + WriteDSP((fragsize-1)&0xFF);// Low byte of size + WriteDSP((fragsize-1)>>8); // High byte of size + } + else + { + int tc,command; + if(Rate>22050) + { + tc=(65536-(256000000/Rate))>>8; + Rate=256000000/(65536-(tc<<8)); + command=0x90; // High-speed auto-initialize DMA mode transfer + hsmode=1; + } + else + { + tc=256-(1000000/Rate); + Rate=1000000/(256-tc); + command=0x1c; // Auto-initialize DMA mode transfer + } + WriteDSP(0x40); // Set DSP time constant + WriteDSP(tc); // time constant + WriteDSP(0x48); // Set DSP block transfer size + WriteDSP((fragsize-1)&0xFF); + WriteDSP((fragsize-1)>>8); + + WriteDSP(command); + } + + /* Enable DMA */ + if(format) + outportb(0xd4,SBDMA16&3); + else + outportb(0xa,SBDMA); + + printf(" %d hz, %d-bit\n",Rate,8<=8) + outportb(0xA0,0x20); + whichbuf^=1; + return; + } + hbusy=1; + + { + /* This code seems to fail on many SB emulators. Bah. + SCREW SB EMULATORS. ^_^ */ + uint32 count; + uint32 block; + uint32 port; + + if(format) + port=((SBDMA16&3)*4)+0xc2; + else + port=(SBDMA*2)+1; + + count=inportb(port); + count|=inportb(port)<<8; + + if(count>=fragsize) + block=1; + else + block=0; + dest=LMBuffer+((block*fragsize)<>2;x;x--,dest+=4) + { + _farnspokel(dest,sby); + } + } + else + { + for(x=(fragsize<>2;x;x--,dest+=4,src++) + { + _farnspokel(dest,*src); + } + ReadPtr=(ReadPtr+fragsize)&(fragtotal-1); + } + + if(soundjoyeron) + { + static int coot=0; + if(!coot) + { + UpdateJoyData(); + soundjoyer=1; + } + coot=(coot+1)&3; + } + hbusy=0; + outportb(0x20,0x20); + if(SBIRQ>=8) + outportb(0xA0,0x20); +} + +void SilenceSound(int s) +{ + ssilence=s; +} + +void WriteSBSound(int32 *Buffer, int Count, int NoBlocking) +{ + int x; + + if(!format) + { + for(x=0;x>8)^128; + WritePtr=(WritePtr+1)&(fragtotal-1); + } + } + else // 16 bit + { + for(x=0;x7)?0xA1:0x21,PICMask|(1<<(SBIRQ&7))); + ResetVectors(); + outportb((SBIRQ>7)?0xA1:0x21,PICMask); + KillDMABuffer(); +} diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-sound.h b/branches/fceux-2.2.2/src/attic/pc/dos-sound.h new file mode 100644 index 00000000..c0e261b5 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-sound.h @@ -0,0 +1,26 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +int InitSB(int Rate, int bittage); +void KillSB(void); + +void WriteSBSound(int32 *Buffer, int Count, int NoBlocking); +void SilenceSound(int s); + diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-video.c b/branches/fceux-2.2.2/src/attic/pc/dos-video.c new file mode 100644 index 00000000..6c9a3682 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-video.c @@ -0,0 +1,246 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 \Firebug\ + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include + +#include "dos.h" +#include "dos-video.h" + +#define TEXT 3 +#define G320x200x256 0x13 + +static void vga_waitretrace(void) +{ + while(inp(0x3da)&0x8); + while(!(inp(0x3da)&0x8)); +} + +static void vga_setmode(int mode) +{ + __dpmi_regs regs; + + memset(®s,0,sizeof(regs)); + regs.x.ax=mode; + + __dpmi_int(0x10,®s); +} + +void vga_setpalette(int i, int r, int g, int b) +{ + outp(0x3c8,i); + outp(0x3c9,r); + outp(0x3c9,g); + outp(0x3c9,b); +} + +int FCEUDvmode=1; + +static int vidready=0; + +/* Part of the VGA low-level mass register setting code derived from + code by \Firebug\. +*/ + +#include "vgatweak.c" + +void SetBorder(void) +{ + inportb(0x3da); + outportb(0x3c0,(0x11|0x20)); + outportb(0x3c0,0x80); +} + +void TweakVGA(int VGAMode) +{ + int I; + + vga_waitretrace(); + + outportb(0x3C8,0x00); + for(I=0;I<768;I++) outportb(0x3C9,0x00); + + outportb(0x3D4,0x11); + I=inportb(0x3D5)&0x7F; + outportb(0x3D4,0x11); + outportb(0x3D5,I); + + switch(VGAMode) + { + case 1: for(I=0;I<25;I++) VGAPortSet(v256x240[I]);break; + case 2: for(I=0;I<25;I++) VGAPortSet(v256x256[I]);break; + case 3: for(I=0;I<25;I++) VGAPortSet(v256x256S[I]);break; + case 6: for(I=0;I<25;I++) VGAPortSet(v256x224S[I]);break; + case 8: for(I=0;I<25;I++) VGAPortSet(v256x224_103[I]);break; + default: break; + } + + outportb(0x3da,0); +} + + +static uint8 palettedbr[256],palettedbg[256],palettedbb[256]; + +static void FlushPalette(void) +{ + int x; + for(x=0;x<256;x++) + { + int z=x; + vga_setpalette(z,palettedbr[x]>>2,palettedbg[x]>>2,palettedbb[x]>>2); + } +} + +void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) +{ + palettedbr[index]=r; + palettedbg[index]=g; + palettedbb[index]=b; + if(vidready) + { + vga_setpalette(index,r>>2,g>>2,b>>2); + } +} + + +void FCEUD_GetPalette(uint8 i, uint8 *r, uint8 *g, uint8 *b) +{ + *r=palettedbr[i]; + *g=palettedbg[i]; + *b=palettedbb[i]; +} + +static uint32 ScreenLoc; + +int InitVideo(void) +{ + vidready=0; + switch(FCEUDvmode) + { + default: + case 1: + case 2: + case 3: + case 6: + case 8: + vga_setmode(G320x200x256); + vidready|=1; + ScreenLoc=0xa0000; + TweakVGA(FCEUDvmode); + SetBorder(); + DOSMemSet(ScreenLoc, 128, 256*256); + break; + } + vidready|=2; + FlushPalette(); + return 1; +} + +void KillVideo(void) +{ + if(vidready) + { + vga_setmode(TEXT); + vidready=0; + } +} +void LockConsole(void){} +void UnlockConsole(void){} +void BlitScreen(uint8 *XBuf) +{ + uint32 dest; + int tlines; + + if(eoptions&4 && !NoWaiting) + vga_waitretrace(); + + tlines=erendline-srendline+1; + + dest=ScreenLoc; + + switch(FCEUDvmode) + { + case 1:dest+=(((240-tlines)>>1)<<8);break; + case 2: + case 3:dest+=(((256-tlines)>>1)<<8);break; + case 4: + case 5:dest+=(((240-tlines)>>1)*640+((640-512)>>1));break; + case 8: + case 6:if(tlines>224) tlines=224;dest+=(((224-tlines)>>1)<<8);break; + } + + XBuf+=(srendline<<8)+(srendline<<4); + + _farsetsel(_dos_ds); + if(eoptions&DO_CLIPSIDES) + { + asm volatile( + "agoop1:\n\t" + "movl $30,%%eax\n\t" + "agoop2:\n\t" + "movl (%%esi),%%edx\n\t" + "movl 4(%%esi),%%ecx\n\t" + ".byte 0x64 \n\t" + "movl %%edx,(%%edi)\n\t" + ".byte 0x64 \n\t" + "movl %%ecx,4(%%edi)\n\t" + "addl $8,%%esi\n\t" + "addl $8,%%edi\n\t" + "decl %%eax\n\t" + "jne agoop2\n\t" + "addl $32,%%esi\n\t" + "addl $16,%%edi\n\t" + "decb %%bl\n\t" + "jne agoop1\n\t" + : + : "S" (XBuf+8), "D" (dest+8), "b" (tlines) + : "%eax","%cc","%edx","%ecx" ); + } + else + { + asm volatile( + "goop1:\n\t" + "movl $32,%%eax\n\t" + "goop2:\n\t" + "movl (%%esi),%%edx\n\t" + "movl 4(%%esi),%%ecx\n\t" + ".byte 0x64 \n\t" + "movl %%edx,(%%edi)\n\t" + ".byte 0x64 \n\t" + "movl %%ecx,4(%%edi)\n\t" + "addl $8,%%esi\n\t" + "addl $8,%%edi\n\t" + "decl %%eax\n\t" + "jne goop2\n\t" + "addl $16,%%esi\n\t" + "decb %%bl\n\t" + "jne goop1\n\t" + : + : "S" (XBuf), "D" (dest), "b" (tlines) + : "%eax","%cc","%edx","%ecx" ); + } +} + + diff --git a/branches/fceux-2.2.2/src/attic/pc/dos-video.h b/branches/fceux-2.2.2/src/attic/pc/dos-video.h new file mode 100644 index 00000000..75b1a1b8 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos-video.h @@ -0,0 +1,22 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +extern int FCEUDvmode; + diff --git a/branches/fceux-2.2.2/src/attic/pc/dos.c b/branches/fceux-2.2.2/src/attic/pc/dos.c new file mode 100644 index 00000000..bd34b058 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include +#include + +#include "dos.h" +#include "dos-joystick.h" +#include "dos-video.h" +#include "dos-sound.h" +#include "../common/args.h" +#include "../common/config.h" + +/* _CRT0_FLAG_LOCK_MEMORY might not always result in all memory being locked. + Bummer. I'll add code to explicitly lock the data touched by the sound + interrupt handler(and the handler itself), if necessary(though that might + be tricky...). I'll also to cover the data the keyboard + interrupt handler touches. +*/ + +int _crt0_startup_flags = _CRT0_FLAG_FILL_SBRK_MEMORY | _CRT0_FLAG_LOCK_MEMORY | _CRT0_FLAG_USE_DOS_SLASHES; + +static int f8bit=0; +int soundo=44100; +int doptions=0; + + +CFGSTRUCT DriverConfig[]={ + NAC("sound",soundo), + AC(doptions), + AC(f8bit), + AC(FCEUDvmode), + NACA("joybmap",joyBMap), + AC(joy), + ENDCFGSTRUCT +}; + +char *DriverUsage= +"-vmode x Select video mode(all are 8 bpp).\n\ + 1 = 256x240 6 = 256x224(with scanlines)\n\ + 2 = 256x256 8 = 256x224\n\ + 3 = 256x256(with scanlines)\n\ +-vsync x Wait for the screen's vertical retrace before updating the\n\ + screen. Refer to the documentation for caveats.\n\ + 0 = Disabled.\n\ + 1 = Enabled.\n\ +-sound x Sound.\n\ + 0 = Disabled.\n\ + Otherwise, x = playback rate.\n\ +-f8bit x Force 8-bit sound.\n\ + 0 = Disabled.\n\ + 1 = Enabled."; + +ARGPSTRUCT DriverArgs[]={ + {"-vmode",0,&FCEUDvmode,0}, + {"-sound",0,&soundo,0}, + {"-f8bit",0,&f8bit,0}, + {"-vsync",0,&doptions,DO_VSYNC}, + {0,0,0,0} +}; + +void DoDriverArgs(void) +{ + if(!joy) memset(joyBMap,0,sizeof(joyBMap)); +} + +int InitSound(void) +{ + if(soundo) + { + if(soundo==1) + soundo=44100; + soundo=InitSB(soundo,f8bit?0:1); + FCEUI_Sound(soundo); + } + return(soundo); +} + +void WriteSound(int32 *Buffer, int Count, int NoWaiting) +{ + WriteSBSound(Buffer,Count,NoWaiting); +} + +void KillSound(void) +{ + if(soundo) + KillSB(); +} + +void DOSMemSet(uint32 A, uint8 V, uint32 count) +{ + uint32 x; + + _farsetsel(_dos_ds); + for(x=0;x=0;x--) + { + if(arg0[x]=='/' || arg0[x]=='\\') + { + ret = malloc(x + 1); + strncpy(ret,arg0,x); + break; + } + } + + if(!ret) { x=0; ret = malloc(1); } + + BaseDirectory[x]=0; +} + +int main(int argc, char *argv[]) +{ + puts("\nStarting FCE Ultra "VERSION_STRING"...\n"); + arg0=argv[0]; + return(CLImain(argc,argv)); +} + diff --git a/branches/fceux-2.2.2/src/attic/pc/dos.h b/branches/fceux-2.2.2/src/attic/pc/dos.h new file mode 100644 index 00000000..b6814800 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/dos.h @@ -0,0 +1,27 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "main.h" +#include "dface.h" +#include "input.h" + +void DOSMemSet(uint32 A, uint8 V, uint32 count); +#define DO_VSYNC 1 + diff --git a/branches/fceux-2.2.2/src/attic/pc/input.c b/branches/fceux-2.2.2/src/attic/pc/input.c new file mode 100644 index 00000000..35fe0350 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/input.c @@ -0,0 +1,720 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "main.h" +#include "dface.h" +#include "input.h" + +#include "../common/cheat.h" + +/* UsrInputType[] is user-specified. InputType[] is current + (game loading can override user settings) +*/ +int UsrInputType[3]={SI_GAMEPAD,SI_GAMEPAD,SIFC_NONE}; +int InputType[3]={0,0,0}; +static int cspec=0; + +int gametype=0; + +/* Necessary for proper GUI functioning(configuring when a game isn't loaded). */ +void InputUserActiveFix(void) +{ + int x; + for(x=0;x<3;x++) InputType[x]=UsrInputType[x]; +} + +void ParseGIInput(FCEUGI *gi) +{ + gametype=gi->type; + + InputType[0]=UsrInputType[0]; + InputType[1]=UsrInputType[1]; + InputType[2]=UsrInputType[2]; + + if(gi->input[0]>=0) + InputType[0]=gi->input[0]; + if(gi->input[1]>=0) + InputType[1]=gi->input[1]; + if(gi->inputfc>=0) + InputType[2]=gi->inputfc; + cspec = gi->cspecial; + + #ifdef EXTGUI + Giggles(gi->cspecial); + #endif +} + + +static uint8 QuizKingData=0; +static uint8 HyperShotData=0; +static uint32 MahjongData=0; +static uint32 FTrainerData=0; +static uint8 TopRiderData=0; + +static uint8 BWorldData[1+13+1]; + +static void UpdateFKB(void); +static void UpdateGamepad(void); +static void UpdateQuizKing(void); +static void UpdateHyperShot(void); +static void UpdateMahjong(void); +static void UpdateFTrainer(void); +static void UpdateTopRider(void); + +static uint32 JSreturn=0; +int NoWaiting=1; + +#ifndef EXTGUI +static void DoCheatSeq(void) +{ + #if defined(DOS) || defined(SDL) + SilenceSound(1); + #endif + KillKeyboard(); + KillVideo(); + + DoConsoleCheatConfig(); + InitVideo(CurGame); + InitKeyboard(); + #if defined(DOS) || defined(SDL) + SilenceSound(0); + #endif +} +#endif + +#include "keyscan.h" +static char *keys=0; +static int DIPS=0; + +static uint8 keyonce[MKK_COUNT]; +#define KEY(__a) keys[MKK(__a)] + +static int _keyonly(int a) +{ + if(keys[a]) + { + if(!keyonce[a]) + { + keyonce[a]=1; + return(1); + } + } + else + keyonce[a]=0; + return(0); +} + +#define keyonly(__a) _keyonly(MKK(__a)) + +static int cidisabled=0; + +static void KeyboardCommands(void) +{ + int is_shift, is_alt; + + keys=GetKeyboard(); + + if(InputType[2]==SIFC_FKB) + { + if(keyonly(SCROLLLOCK)) + { + cidisabled^=1; + FCEUI_DispMessage("Family Keyboard %sabled.",cidisabled?"en":"dis"); + } + #ifdef SDL + SDL_WM_GrabInput(cidisabled?SDL_GRAB_ON:SDL_GRAB_OFF); + #endif + if(cidisabled) return; + } + + is_shift = KEY(LEFTSHIFT) | KEY(RIGHTSHIFT); + is_alt = KEY(LEFTALT) | KEY(RIGHTALT); + + if(keyonly(F4)) + { + if(is_shift) FCEUI_SetRenderDisable(-1, 2); + else FCEUI_SetRenderDisable(2, -1); + } + #ifdef SDL + if(keyonly(ENTER) && is_alt) ToggleFS(); + #endif + + NoWaiting&=~1; + if(KEY(GRAVE)) + NoWaiting|=1; + + if(gametype==GIT_FDS) + { + if(keyonly(F6)) FCEUI_FDSSelect(); + if(keyonly(F8)) FCEUI_FDSInsert(); + } + + if(keyonly(F9)) FCEUI_SaveSnapshot(); + if(gametype!=GIT_NSF) + { + #ifndef EXTGUI + if(keyonly(F2)) DoCheatSeq(); + #endif + if(keyonly(F5)) + { + if(is_shift) + FCEUI_SaveMovie(NULL,0,NULL); + else + FCEUI_SaveState(NULL); + } + if(keyonly(F7)) + { + if(is_shift) + FCEUI_LoadMovie(NULL,0); + else + FCEUI_LoadState(NULL); + } + } + + if(keyonly(F1)) FCEUI_ToggleTileView(); + + if(keyonly(MINUS)) DecreaseEmulationSpeed(); + if(keyonly(EQUAL)) IncreaseEmulationSpeed(); + if(keyonly(BACKSPACE)) FCEUI_MovieToggleFrameDisplay(); + if(keyonly(BACKSLASH)) FCEUI_ToggleEmulationPause(); + if(keyonly(RIGHTCONTROL)) FCEUI_FrameAdvance(); + + if(keyonly(F10)) FCEUI_ResetNES(); + if(keyonly(F11)) FCEUI_PowerNES(); + + #ifdef EXTGUI + if(keyonly(F3)) GUI_Hide(-1); + if(KEY(F12)) GUI_RequestExit(); + if(KEY(ESCAPE)) CloseGame(); + #else + if(KEY(F12) || KEY(ESCAPE)) CloseGame(); + #endif + + if(gametype==GIT_VSUNI) + { + if(keyonly(F8)) FCEUI_VSUniCoin(); + if(keyonly(F6)) + { + DIPS^=1; + FCEUI_VSUniToggleDIPView(); + } + if(!(DIPS&1)) goto DIPSless; + if(keyonly(1)) FCEUI_VSUniToggleDIP(0); + if(keyonly(2)) FCEUI_VSUniToggleDIP(1); + if(keyonly(3)) FCEUI_VSUniToggleDIP(2); + if(keyonly(4)) FCEUI_VSUniToggleDIP(3); + if(keyonly(5)) FCEUI_VSUniToggleDIP(4); + if(keyonly(6)) FCEUI_VSUniToggleDIP(5); + if(keyonly(7)) FCEUI_VSUniToggleDIP(6); + if(keyonly(8)) FCEUI_VSUniToggleDIP(7); + } + else + { + static uint8 bbuf[32]; + static int bbuft; + static int barcoder = 0; + + if(keyonly(H)) FCEUI_NTSCSELHUE(); + if(keyonly(T)) FCEUI_NTSCSELTINT(); + if(KEY(KP_MINUS) || KEY(MINUS)) FCEUI_NTSCDEC(); + if(KEY(KP_PLUS) || KEY(EQUAL)) FCEUI_NTSCINC(); + + if((InputType[2] == SIFC_BWORLD) || (cspec == SIS_DATACH)) + { + if(keyonly(F8)) + { + barcoder ^= 1; + if(!barcoder) + { + if(InputType[2] == SIFC_BWORLD) + { + strcpy(&BWorldData[1],bbuf); + BWorldData[0]=1; + } + else + FCEUI_DatachSet(bbuf); + FCEUI_DispMessage("Barcode Entered"); + } + else { bbuft = 0; FCEUI_DispMessage("Enter Barcode");} + } + } else barcoder = 0; + + #define SSM(x) \ + { if(barcoder) { if(bbuft < 13) {bbuf[bbuft++] = '0' + x; bbuf[bbuft] = 0;} FCEUI_DispMessage("Barcode: %s",bbuf);} \ + else { \ + if(is_shift) FCEUI_SelectMovie(x,1); \ + else FCEUI_SelectState(x,1); \ + } } + + DIPSless: + if(keyonly(0)) SSM(0); + if(keyonly(1)) SSM(1); + if(keyonly(2)) SSM(2); + if(keyonly(3)) SSM(3); + if(keyonly(4)) SSM(4); + if(keyonly(5)) SSM(5); + if(keyonly(6)) SSM(6); + if(keyonly(7)) SSM(7); + if(keyonly(8)) SSM(8); + if(keyonly(9)) SSM(9); + #undef SSM + } +} + +#define MK(x) {{BUTTC_KEYBOARD},{0},{MKK(x)},1} +#define MK2(x1,x2) {{BUTTC_KEYBOARD},{0},{MKK(x1),MKK(x2)},2} + +#define MKZ() {{0},{0},{0},0} + +#define GPZ() {MKZ(), MKZ(), MKZ(), MKZ()} + +ButtConfig GamePadConfig[4][10]={ + /* Gamepad 1 */ + { + MK(KP3), MK(KP2), MK(TAB), MK(ENTER), MK(W),MK(Z), + MK(A), MK(S), MKZ(), MKZ() + }, + + /* Gamepad 2 */ + GPZ(), + + /* Gamepad 3 */ + GPZ(), + + /* Gamepad 4 */ + GPZ() +}; + + +static void UpdateGamepad(void) +{ + if(FCEUI_IsMovieActive()<0) + return; + + static int rapid=0; + uint32 JS=0; + int x; + int wg; + + rapid^=1; + + for(wg=0;wg<4;wg++) + { + for(x=0;x<8;x++) + if(DTestButton(&GamePadConfig[wg][x])) + JS|=(1<ButtType[wc]==bc->ButtType[wc-1] && bc->DeviceNum[wc]==bc->DeviceNum[wc-1] && + bc->ButtonNum[wc]==bc->ButtonNum[wc-1]) + break; + } + bc->NumC=wc; +} + +void ConfigDevice(int which, int arg) +{ + uint8 buf[256]; + int x; + + ButtonConfigBegin(); + switch(which) + { + case FCFGD_QUIZKING: + for(x=0;x<6;x++) + { + sprintf(buf,"Quiz King Buzzer #%d", x+1); + subcon(buf,&QuizKingButtons[x]); + } + break; + case FCFGD_HYPERSHOT: + for(x=0;x<4;x++) + { + sprintf(buf,"Hyper Shot %d: %s",((x&2)>>1)+1,(x&1)?"JUMP":"RUN"); + subcon(buf,&HyperShotButtons[x]); + } + break; + case FCFGD_POWERPAD: + for(x=0;x<12;x++) + { + sprintf(buf,"PowerPad %d: %d", (arg&1)+1,x+11); + subcon(buf,&powerpadsc[arg&1][x]); + } + break; + + case FCFGD_GAMEPAD: + { + char *str[10]={"A","B","SELECT","START","UP","DOWN","LEFT","RIGHT","Rapid A","Rapid B"}; + for(x=0;x<10;x++) + { + sprintf(buf,"GamePad #%d: %s",arg+1,str[x]); + subcon(buf,&GamePadConfig[arg][x]); + } + } + break; + } + + ButtonConfigEnd(); +} + + +CFGSTRUCT InputConfig[]={ + ACA(UsrInputType), + AC(powerpadsc), + AC(QuizKingButtons), + AC(FTrainerButtons), + AC(HyperShotButtons), + AC(MahjongButtons), + AC(GamePadConfig), + AC(fkbmap), + ENDCFGSTRUCT +}; + + +static void InputCfg(char *text) +{ + if(!strncasecmp(text,"gamepad",strlen("gamepad"))) + { + ConfigDevice(FCFGD_GAMEPAD,(text[strlen("gamepad")]-'1')&3); + } + else if(!strncasecmp(text,"powerpad",strlen("powerpad"))) + { + ConfigDevice(FCFGD_POWERPAD,(text[strlen("powerpad")]-'1')&1); + } + else if(!strcasecmp(text,"hypershot")) + ConfigDevice(FCFGD_HYPERSHOT,0); + else if(!strcasecmp(text,"quizking")) + ConfigDevice(FCFGD_QUIZKING,0); +} + +static void FCExp(char *text) +{ + static char *fccortab[11]={"none","arkanoid","shadow","4player","fkb","hypershot", + "mahjong","quizking","ftrainera","ftrainerb","oekakids"}; + + static int fccortabi[11]={SIFC_NONE,SIFC_ARKANOID,SIFC_SHADOW, + SIFC_4PLAYER,SIFC_FKB,SIFC_HYPERSHOT,SIFC_MAHJONG,SIFC_QUIZKING, + SIFC_FTRAINERA,SIFC_FTRAINERB,SIFC_OEKAKIDS}; + int y; + for(y=0;y<11;y++) + if(!strcmp(fccortab[y],text)) + UsrInputType[2]=fccortabi[y]; +} + +static char *cortab[6]={"none","gamepad","zapper","powerpada","powerpadb","arkanoid"}; +static int cortabi[6]={SI_NONE,SI_GAMEPAD, + SI_ZAPPER,SI_POWERPADA,SI_POWERPADB,SI_ARKANOID}; + +static void Input1(char *text) +{ + int y; + + for(y=0;y<6;y++) + if(!strcmp(cortab[y],text)) + UsrInputType[0]=cortabi[y]; +} + +static void Input2(char *text) +{ + int y; + + for(y=0;y<6;y++) + if(!strcmp(cortab[y],text)) + UsrInputType[1]=cortabi[y]; +} + +ARGPSTRUCT InputArgs[]={ + {"-inputcfg",0,(void *)InputCfg,0x2000}, + {"-fcexp",0,(void *)FCExp,0x2000}, + {"-input1",0,(void *)Input1,0x2000}, + {"-input2",0,(void *)Input2,0x2000}, + {0,0,0,0} +}; diff --git a/branches/fceux-2.2.2/src/attic/pc/input.h b/branches/fceux-2.2.2/src/attic/pc/input.h new file mode 100644 index 00000000..f9fbf36e --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/input.h @@ -0,0 +1,38 @@ +#ifndef _aosdfjk02fmasf +#define _aosdfjk02fmasf +#define MAXBUTTCONFIG 4 +typedef struct { + uint8 ButtType[MAXBUTTCONFIG]; + uint8 DeviceNum[MAXBUTTCONFIG]; + uint16 ButtonNum[MAXBUTTCONFIG]; + uint32 NumC; + //uint64 DeviceID[MAXBUTTCONFIG]; /* TODO */ +} ButtConfig; + +extern CFGSTRUCT InputConfig[]; +extern ARGPSTRUCT InputArgs[]; +void ParseGIInput(FCEUGI *GI); + +#define BUTTC_KEYBOARD 0x00 +#define BUTTC_JOYSTICK 0x01 +#define BUTTC_MOUSE 0x02 + +#define FCFGD_GAMEPAD 1 +#define FCFGD_POWERPAD 2 +#define FCFGD_HYPERSHOT 3 +#define FCFGD_QUIZKING 4 + +void InitOtherInput(void); +void InputUserActiveFix(void); +#ifdef EXTGUI +extern ButtConfig GamePadConfig[4][10]; +extern ButtConfig powerpadsc[2][12]; +extern ButtConfig QuizKingButtons[6]; +extern ButtConfig FTrainerButtons[12]; +#endif + +void IncreaseEmulationSpeed(void); +void DecreaseEmulationSpeed(void); + +void FCEUD_UpdateInput(void); +#endif diff --git a/branches/fceux-2.2.2/src/attic/pc/keyscan.h b/branches/fceux-2.2.2/src/attic/pc/keyscan.h new file mode 100644 index 00000000..bec3af66 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/keyscan.h @@ -0,0 +1,161 @@ +#ifdef SDL +#include +#define SDLK_A SDLK_a +#define SDLK_B SDLK_b +#define SDLK_C SDLK_c +#define SDLK_D SDLK_d +#define SDLK_E SDLK_e +#define SDLK_F SDLK_f +#define SDLK_G SDLK_g +#define SDLK_H SDLK_h +#define SDLK_I SDLK_i +#define SDLK_J SDLK_j +#define SDLK_K SDLK_k +#define SDLK_L SDLK_l +#define SDLK_M SDLK_m +#define SDLK_N SDLK_n +#define SDLK_O SDLK_o +#define SDLK_P SDLK_p +#define SDLK_Q SDLK_q +#define SDLK_R SDLK_r +#define SDLK_S SDLK_s +#define SDLK_T SDLK_t +#define SDLK_U SDLK_u +#define SDLK_V SDLK_v +#define SDLK_W SDLK_w +#define SDLK_X SDLK_x +#define SDLK_Y SDLK_y +#define SDLK_Z SDLK_z +#define SDLK_LEFTCONTROL SDLK_LCTRL +#define SDLK_RIGHTCONTROL SDLK_RCTRL +#define SDLK_LEFTALT SDLK_LALT +#define SDLK_RIGHTALT SDLK_RALT +#define SDLK_LEFTSHIFT SDLK_LSHIFT +#define SDLK_RIGHTSHIFT SDLK_RSHIFT +#define SDLK_CURSORDOWN SDLK_DOWN +#define SDLK_CURSORUP SDLK_UP +#define SDLK_CURSORLEFT SDLK_LEFT +#define SDLK_CURSORRIGHT SDLK_RIGHT +#define SDLK_ENTER SDLK_RETURN +#define SDLK_EQUAL SDLK_EQUALS +#define SDLK_APOSTROPHE SDLK_QUOTE +#define SDLK_BRACKET_LEFT SDLK_LEFTBRACKET +#define SDLK_BRACKET_RIGHT SDLK_RIGHTBRACKET +#define SDLK_SCROLLLOCK SDLK_SCROLLOCK /* I guess the SDL people don't like lots of Ls... */ +#define SDLK_GRAVE SDLK_BACKQUOTE +#define MKK(k) SDLK_##k +#define MKK_COUNT (SDLK_LAST+1) + +#elif DOS + +#define SCAN_TILDE 0x29 +#define SCAN_1 0x02 +#define SCAN_2 0x03 +#define SCAN_3 0x04 +#define SCAN_4 0x05 +#define SCAN_5 0x06 +#define SCAN_6 0x07 +#define SCAN_7 0x08 +#define SCAN_8 0x09 +#define SCAN_9 0x0A +#define SCAN_0 0x0B +#define SCAN_MINUS 0x0C +#define SCAN_EQUAL 0x0D +#define SCAN_BACKSLASH 0x2B +#define SCAN_BACKSPACE 0x0E +#define SCAN_TAB 0x0F +#define SCAN_Q 0x10 +#define SCAN_W 0x11 +#define SCAN_E 0x12 +#define SCAN_R 0x13 +#define SCAN_T 0x14 +#define SCAN_Y 0x15 +#define SCAN_U 0x16 +#define SCAN_I 0x17 +#define SCAN_O 0x18 +#define SCAN_P 0x19 +#define SCAN_BRACKET_LEFT 0x1A +#define SCAN_BRACKET_RIGHT 0x1B +#define SCAN_LOWBACKSLASH 0x2B +#define SCAN_CAPSLOCK 0x3A +#define SCAN_A 0x1E +#define SCAN_S 0x1F +#define SCAN_D 0x20 +#define SCAN_F 0x21 +#define SCAN_G 0x22 +#define SCAN_H 0x23 +#define SCAN_J 0x24 +#define SCAN_K 0x25 +#define SCAN_L 0x26 +#define SCAN_SEMICOLON 0x27 +#define SCAN_APOSTROPHE 0x28 +#define SCAN_ENTER 0x1C +#define SCAN_LEFTSHIFT 0x2A +#define SCAN_Z 0x2C +#define SCAN_X 0x2D +#define SCAN_C 0x2E +#define SCAN_V 0x2F +#define SCAN_B 0x30 +#define SCAN_N 0x31 +#define SCAN_M 0x32 +#define SCAN_COMMA 0x33 +#define SCAN_PERIOD 0x34 +#define SCAN_SLASH 0x35 +#define SCAN_RIGHTSHIFT 0x36 +#define SCAN_LEFTCONTROL 0x1D +#define SCAN_LEFTALT 0x38 +#define SCAN_SPACE 0x39 + +/* Extended keys. */ +#define SCAN_RIGHTALT (0x38|0x80) +#define SCAN_RIGHTCONTROL (0x1D|0x80) +#define SCAN_BL_INSERT (0x52|0x80) +#define SCAN_BL_DELETE (0x53|0x80) +#define SCAN_BL_CURSORLEFT (0x4B|0x80) +#define SCAN_BL_HOME (0x47|0x80) +#define SCAN_BL_END (0x4F|0x80) +#define SCAN_BL_CURSORUP (0x48|0x80) +#define SCAN_BL_CURSORDOWN (0x50|0x80) +#define SCAN_BL_PAGEUP (0x49|0x80) +#define SCAN_BL_PAGEDOWN (0x51|0x80) +#define SCAN_BL_CURSORRIGHT (0x4D|0x80) + +#define SCAN_SCROLLLOCK 0x46 +/* Keys often found in the key pad area. */ +#define SCAN_NUMLOCK 0x45 +#define SCAN_HOME 0x47 +#define SCAN_CURSORLEFT 0x4B +#define SCAN_END 0x4F +#define SCAN_SLASH 0x35 +#define SCAN_CURSORUP 0x48 +#define SCAN_CENTER 0x4C +#define SCAN_CURSORDOWN 0x50 +#define SCAN_INSERT 0x52 +#define SCAN_PAUSE 0xC5 +#define SCAN_ASTERISK 0x37 +#define SCAN_PAGEUP 0x49 +#define SCAN_CURSORRIGHT 0x4D +#define SCAN_PAGEDOWN 0x51 +#define SCAN_DELETE 0x53 +#define SCAN_KP_MINUS 0x4A +#define SCAN_KP_PLUS 0x4E +#define SCAN_KP_ENTER 0x1C + +#define SCAN_ESCAPE 0x01 +#define SCAN_F1 0x3B +#define SCAN_F2 0x3C +#define SCAN_F3 0x3D +#define SCAN_F4 0x3E +#define SCAN_F5 0x3F +#define SCAN_F6 0x40 +#define SCAN_F7 0x41 +#define SCAN_F8 0x42 +#define SCAN_F9 0x43 +#define SCAN_F10 0x44 +#define SCAN_F11 0x57 +#define SCAN_F12 0x58 + +#define MK_COUNT 256 +#define MK(k) SCAN_##k + +#endif diff --git a/branches/fceux-2.2.2/src/attic/pc/main.c b/branches/fceux-2.2.2/src/attic/pc/main.c new file mode 100644 index 00000000..6bdd7ce7 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/main.c @@ -0,0 +1,553 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "main.h" +#include "throttle.h" + +#include "../common/cheat.h" + +#include "input.h" +#include "dface.h" + +extern int32 fps_scale; + +int CloseGame(void); + +static char *soundrecfn=0; /* File name of sound recording. */ + +static int ntsccol=0,ntschue=0,ntsctint=0; +int soundvol=100; +long soundq=0; +int _sound=1; +long soundrate=48000; +#ifdef WIN32 +long soundbufsize=52; +#else +long soundbufsize=24; +#endif + +#ifdef FRAMESKIP +static int frameskip=0; +#endif +static int inited=0; +static int isloaded=0; // Is game loaded? + +int srendlinev[2]={8,0}; +int erendlinev[2]={231,239}; + + +static uint8 *DrBaseDirectory; + +int eoptions=0; + +static void DriverKill(void); +static int DriverInitialize(FCEUGI *gi); +int gametype; + +FCEUGI *CurGame=NULL; + +static void ParseGI(FCEUGI *gi) +{ + ParseGIInput(gi); + gametype=gi->type; +} + +#ifndef EXTGUI +void FCEUD_PrintError(char *s) +{ + puts(s); +} + +void FCEUD_Message(char *s) +{ + fputs(s,stdout); +} +#endif + +static char *cpalette=0; +static void LoadCPalette(void) +{ + uint8 tmpp[192]; + FILE *fp; + + if(!(fp=FCEUD_UTF8fopen(cpalette,"rb"))) + { + printf(" Error loading custom palette from file: %s\n",cpalette); + return; + } + fread(tmpp,1,192,fp); + FCEUI_SetPaletteArray(tmpp); + fclose(fp); +} +#ifdef EXTGUI +extern CFGSTRUCT GUIConfig; +#endif +static CFGSTRUCT fceuconfig[]={ + AC(soundrate), + AC(soundq), + AC(_sound), + AC(soundvol), + AC(soundbufsize), + ACS(cpalette), + AC(ntsctint), + AC(ntschue), + AC(ntsccol), + AC(eoptions), + ACA(srendlinev), + ACA(erendlinev), + ADDCFGSTRUCT(InputConfig), + ADDCFGSTRUCT(DriverConfig), + #ifdef EXTGUI + ADDCFGSTRUCT(GUIConfig), + #endif + ENDCFGSTRUCT +}; + +static void SaveConfig(void) +{ + char tdir[2048]; + sprintf(tdir,"%s"PSS"fceu98.cfg",DrBaseDirectory); + FCEUI_GetNTSCTH(&ntsctint, &ntschue); + SaveFCEUConfig(tdir,fceuconfig); +} + +static void LoadConfig(void) +{ + char tdir[2048]; + sprintf(tdir,"%s"PSS"fceu98.cfg",DrBaseDirectory); + FCEUI_GetNTSCTH(&ntsctint, &ntschue); /* Get default settings for if + no config file exists. */ + LoadFCEUConfig(tdir,fceuconfig); + InputUserActiveFix(); +} + +static void CreateDirs(void) +{ + char *subs[7]={"fcs","fcm","snaps","gameinfo","sav","cheats","movie"}; + char tdir[2048]; + int x; + + #ifdef WIN32 + mkdir(DrBaseDirectory); + for(x=0;x<6;x++) + { + sprintf(tdir,"%s"PSS"%s",DrBaseDirectory,subs[x]); + mkdir(tdir); + } + #else + mkdir(DrBaseDirectory,S_IRWXU); + for(x=0;x<6;x++) + { + sprintf(tdir,"%s"PSS"%s",DrBaseDirectory,subs[x]); + mkdir(tdir,S_IRWXU); + } + #endif +} + +#ifndef WIN32 +static void SetSignals(void (*t)(int)) +{ + int sigs[11]={SIGINT,SIGTERM,SIGHUP,SIGPIPE,SIGSEGV,SIGFPE,SIGKILL,SIGALRM,SIGABRT,SIGUSR1,SIGUSR2}; + int x; + for(x=0;x<11;x++) + signal(sigs[x],t); +} + +static void CloseStuff(int signum) +{ + DriverKill(); + printf("\nSignal %d has been caught and dealt with...\n",signum); + switch(signum) + { + case SIGINT:printf("How DARE you interrupt me!\n");break; + case SIGTERM:printf("MUST TERMINATE ALL HUMANS\n");break; + case SIGHUP:printf("Reach out and hang-up on someone.\n");break; + case SIGPIPE:printf("The pipe has broken! Better watch out for floods...\n");break; + case SIGSEGV:printf("Iyeeeeeeeee!!! A segmentation fault has occurred. Have a fluffy day.\n");break; + /* So much SIGBUS evil. */ + #ifdef SIGBUS + #if(SIGBUS!=SIGSEGV) + case SIGBUS:printf("I told you to be nice to the driver.\n");break; + #endif + #endif + case SIGFPE:printf("Those darn floating points. Ne'er know when they'll bite!\n");break; + case SIGALRM:printf("Don't throw your clock at the meowing cats!\n");break; + case SIGABRT:printf("Abort, Retry, Ignore, Fail?\n");break; + case SIGUSR1: + case SIGUSR2:printf("Killing your processes is not nice.\n");break; + } + exit(1); +} +#endif + +static void DoArgs(int argc, char *argv[]) +{ + int x; + + static ARGPSTRUCT FCEUArgs[]={ + {"-soundbufsize",0,&soundbufsize,0}, + {"-soundrate",0,&soundrate,0}, + {"-soundq",0,&soundq,0}, +#ifdef FRAMESKIP + {"-frameskip",0,&frameskip,0}, +#endif + {"-sound",0,&_sound,0}, + {"-soundvol",0,&soundvol,0}, + {"-cpalette",0,&cpalette,0x4001}, + {"-soundrecord",0,&soundrecfn,0x4001}, + + {"-ntsccol",0,&ntsccol,0}, + {"-pal",0,&eoptions,0x8000|EO_PAL}, + + {"-lowpass",0,&eoptions,0x8000|EO_LOWPASS}, + {"-gg",0,&eoptions,0x8000|EO_GAMEGENIE}, + {"-no8lim",0,&eoptions,0x8001}, + {"-snapname",0,&eoptions,0x8000|EO_SNAPNAME}, + {"-nofs",0,&eoptions,0x8000|EO_NOFOURSCORE}, + {"-clipsides",0,&eoptions,0x8000|EO_CLIPSIDES}, + {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE}, + {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0}, + {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0}, + {0,(int *)InputArgs,0,0}, + {0,(int *)DriverArgs,0,0}, + {0,0,0,0} + }; + + ParseArguments(argc, argv, FCEUArgs); + if(cpalette) + { + if(cpalette[0]=='0') + if(cpalette[1]==0) + { + free(cpalette); + cpalette=0; + } + } + FCEUI_SetVidSystem((eoptions&EO_PAL)?1:0); + FCEUI_SetGameGenie((eoptions&EO_GAMEGENIE)?1:0); + FCEUI_SetLowPass((eoptions&EO_LOWPASS)?1:0); + + FCEUI_DisableSpriteLimitation(eoptions&1); + FCEUI_SetSnapName(eoptions&EO_SNAPNAME); + + for(x=0;x<2;x++) + { + if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0; + if(erendlinev[x]239) erendlinev[x]=239; + } + + FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); + DoDriverArgs(); +} + +#include "usage.h" + +/* Loads a game, given a full path/filename. The driver code must be + initialized after the game is loaded, because the emulator code + provides data necessary for the driver code(number of scanlines to + render, what virtual input devices to use, etc.). +*/ +int LoadGame(const char *path) +{ + FCEUGI *tmp; + + CloseGame(); + if(!(tmp=FCEUI_LoadGame(path,1))) + return 0; + CurGame=tmp; + ParseGI(tmp); + RefreshThrottleFPS(); + + if(!DriverInitialize(tmp)) + return(0); + if(soundrecfn) + { + if(!FCEUI_BeginWaveRecord(soundrecfn)) + { + free(soundrecfn); + soundrecfn=0; + } + } + isloaded=1; + #ifdef EXTGUI + if(eoptions&EO_AUTOHIDE) GUI_Hide(1); + #endif + + FCEUD_NetworkConnect(); + return 1; +} + +/* Closes a game. Frees memory, and deinitializes the drivers. */ +int CloseGame(void) +{ + if(!isloaded) return(0); + FCEUI_CloseGame(); + DriverKill(); + isloaded=0; + CurGame=0; + + if(soundrecfn) + FCEUI_EndWaveRecord(); + + #ifdef EXTGUI + GUI_Hide(0); + #endif + InputUserActiveFix(); + return(1); +} + +void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); + +void DoFun(void) +{ + uint8 *gfx; + int32 *sound; + int32 ssize; + static int fskipc=0; + static int opause=0; + + #ifdef FRAMESKIP + fskipc=(fskipc+1)%(frameskip+1); + #endif + + if(NoWaiting) {gfx=0;} + FCEUI_Emulate(&gfx, &sound, &ssize, fskipc); + FCEUD_Update(gfx, sound, ssize); + + if(opause!=FCEUI_EmulationPaused()) + { + opause=FCEUI_EmulationPaused(); + SilenceSound(opause); + } +} + +int CLImain(int argc, char *argv[]) +{ + int ret; + + if(!(ret=FCEUI_Initialize())) + return(0); + + DrBaseDirectory=GetBaseDirectory(); + FCEUI_SetBaseDirectory(DrBaseDirectory); + + CreateDirs(); + + #ifdef EXTGUI + if(argc==2 && !strcmp(argv[1],"-help")) // I hope no one has a game named "-help" :b + #else + if(argc<=1) + #endif + { + ShowUsage(argv[0]); + return(0); + } + + LoadConfig(); + DoArgs(argc-2,&argv[1]); + FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); + if(cpalette) + LoadCPalette(); + + /* All the config files and arguments are parsed now. */ + #ifdef EXTGUI + return(1); + + #else + if(!LoadGame(argv[argc-1])) + { + DriverKill(); + return(0); + } + + while(CurGame) + DoFun(); + + #if(0) + { + int x; + for(x=1;x= GetMaxSound() && fps_scale<=256) uflow=1; /* Go into massive underflow mode. */ + + if(can > Count) can=Count; + else uflow=0; + + WriteSound(Buffer,can); + + //if(uflow) puts("Underflow"); + tmpcan = GetWriteSound(); + // don't underflow when scaling fps + if(fps_scale>256 || ((tmpcan < Count*0.90) && !uflow)) + { + if(XBuf && (inited&4) && !(NoWaiting & 2)) + BlitScreen(XBuf); + Buffer+=can; + Count-=can; + if(Count) + { + if(NoWaiting) + { + can=GetWriteSound(); + if(Count>can) Count=can; + WriteSound(Buffer,Count); + } + else + { + while(Count>0) + { + WriteSound(Buffer,(Count= (Count * 1.8))) + { + if(Count > tmpcan) Count=tmpcan; + while(tmpcan > 0) + { +// printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan); + WriteSound(Buffer, (Count <= tmpcan)?Count : tmpcan); + tmpcan -= Count; + } + } + #endif + + } + else + { + if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) + SpeedThrottle(); + if(XBuf && (inited&4)) + { + BlitScreen(XBuf); + } + } + FCEUD_UpdateInput(); + //if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE)) + // SpeedThrottle(); + //if(XBuf && (inited&4)) + //{ + // BlitScreen(XBuf); + //} + //if(Count) + // WriteSound(Buffer,Count,NoWaiting); + //FCEUD_UpdateInput(); +} + + +/* Maybe ifndef WXWINDOWS would be better? ^_^ */ +#ifndef EXTGUI +FILE *FCEUD_UTF8fopen(const char *fn, const char *mode) +{ + return(fopen(fn,mode)); +} + + +#endif diff --git a/branches/fceux-2.2.2/src/attic/pc/main.h b/branches/fceux-2.2.2/src/attic/pc/main.h new file mode 100644 index 00000000..505eaf04 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/main.h @@ -0,0 +1,55 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../driver.h" +#include "../common/config.h" +#include "../common/args.h" + +extern int eoptions; +#define EO_NO8LIM 1 +#define EO_SUBASE 2 +#define EO_CLIPSIDES 8 +#define EO_SNAPNAME 16 +#define EO_NOFOURSCORE 32 +#define EO_NOTHROTTLE 64 +#define EO_GAMEGENIE 128 +#define EO_PAL 256 +#define EO_LOWPASS 512 +#define EO_AUTOHIDE 1024 + +extern int srendlinev[2],erendlinev[2]; +extern int NoWaiting; + +extern int soundvol; +extern long soundq; +extern int _sound; +extern long soundrate; +extern long soundbufsize; + +int CLImain(int argc, char *argv[]); + +#ifdef __cplusplus +} +#endif + diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-icon.h b/branches/fceux-2.2.2/src/attic/pc/sdl-icon.h new file mode 100644 index 00000000..3a563d0b --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-icon.h @@ -0,0 +1,134 @@ +static const struct { + unsigned int width; + unsigned int height; + unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ + uint8 pixel_data[32 * 32 * 3 + 1]; +} fceu_playicon = { + 32, 32, 3, + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\0\0\0\0\0\0\0\0\0\\\223\373\\\223\373\267\317\373" + "\246\304\373\260\312\373\222\267\373\246\304\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\267\317\373\246\304\373\260\312\373\210\261\373\246\304\373\\\223\373\\" + "\223\373\210\261\373\222\267\373\267\317\373\241\301\373\\\223\373\\\223" + "\373\0\0\0\0\0\0\\\223\373\\\223\373\227\272\373\227\272\373\227\272\373" + "\227\272\373\227\272\373\227\272\373\\\223\373\\\223\373z`sr\242\373\227" + "\272\373\227\272\373\\\223\373\\\223\373\\\223\373\\\223\373\213\261\373" + "z\247\373\213\261\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\" + "\223\373\\\223\373\313i=\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40" + "\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40" + "\315Z\40\315Z\40\315Z\40\315Z\40\315Z\40\257T*\\\223\373\\\223\373\\\223" + "\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223\373\315Z\40" + "\355\235\203\355\235\203\341\232\205\341\232\205\365\255\233\355\235\203" + "\355\235\203\350\250\232\365\255\233\355\235\203\307L\14\307L\14\307L\14" + "\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14\256B\12\\\223\373" + "\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373" + "\\\223\373\315Z\40\273zc\233l_\325\225\205\325\225\205\325\225\205\273\212" + "\201\325\225\205\237qd\325\225\205\317\231\216\307L\14\307L\14\307L\14\307" + "L\14\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14\256B\12\\\223\373\\" + "\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\" + "\223\373\315Z\40\344\232\203\301\215\201\344\232\203\273\212\201\325\225" + "\205\2114\10\344\232\203\350\250\232\325\225\205\333\230\205\307L\14\307" + "L\14\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14\256" + "B\12\\\223\373\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223" + "\373\\\223\373\\\223\373\315Z\40\2259\11}0\10\2259\11}0\10}0\10\307L\14\225" + "9\11d&\6}0\10}0\10\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14\307L\14" + "\307L\14\307L\14\307L\14\256B\12\\\223\373\\\223\373\\\223\373\\\223\373" + "\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223\373\315Z\40\355\235\203" + "\355\233\201\355\235\203\355\235\203\355\235\203\365\255\233\355\235\203" + "\341\232\205\355\235\203\355\235\203\307L\14\365\255\233\355\235\203\365" + "\255\233\355\235\203\355\235\203\355\235\203\355\235\203\355\235\203\307" + "L\14\256B\12\\\223\373\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373" + "\\\223\373\\\223\373\\\223\373\315Z\40\325\225\205\311\221\204\311\221\204" + "\325\225\205\311\221\204\325\225\205\311\221\204\325\225\205\325\225\205" + "\311\221\204\307L\14\325\225\205\311\221\204\325\225\205\311\221\204\325" + "\225\205\311\221\204\325\225\205\311\221\204\307L\14\256B\12\\\223\373\\" + "\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\" + "\223\373\315Z\40\325\225\205\325\225\205\325\225\205\325\225\205\325\225" + "\205\325\225\205\317\231\216\325\225\205\325\225\205\325\225\205\307L\14" + "\325\225\205\317\231\216\325\225\205\317\231\216\325\225\205\325\225\205" + "\273zc\241n_\307L\14\256B\12\\\223\373\\\223\373\\\223\373\\\223\373\0\0" + "\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223\373\315Z\40\325\225\205\325" + "\225\205\325\225\205\365\255\233\333\243\231\325\225\205\333\230\205\325" + "\225\205\325\225\205\325\225\205\307L\14\325\225\205\317\223\204\325\225" + "\205\333\230\205\325\225\205\325\225\205\333\230\205\317\223\204\307L\14" + "\256B\12\\\223\373\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\" + "\223\373\\\223\373\\\223\373\315Z\40\325\225\205\325\225\205\325\225\205" + "\325\225\205\311\221\204\325\225\205\325\225\205\325\225\205\344\232\203" + "\273\212\201\307L\14\325\225\205\273\212\201\325\225\205\325\225\205\344" + "\232\203\273\212\201\344\232\203\273\212\201\341\232\205\256B\12\\\223\373" + "\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373" + "\\\223\373\257T*d&\6d&\6d&\6d&\6d&\6d&\6d&\6d&\6}0\10d&\6\256B\12d&\6p+\7" + "d&\6d&\6}0\10d&\6}0\10d&\6d&\6\223@\26\\\223\373\\\223\373\\\223\373\\\223" + "\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\234\243" + "\335\213\237\344\237\244\333\251\247\326\237\244\333\\\223\373\267\252\317" + "\222\241\341\267\252\317\210\237\346\241\245\332\267\252\317\246\246\327" + "\246\246\327\\\223\373\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\0" + "\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\257hT\\\223\373\213\261\373\\\223" + "\373\241\301\373\210\261\373\246\304\373\222\267\373\241\301\373\260\312" + "\373\\\223\373\237\277\373\246\304\373\267\317\373\241\301\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\0\0\0\0\0\0\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\\\223\373\246\304\373\\\223\373\241" + "\301\373\210\261\373\246\304\373\222\267\373\241\301\373\260\312\373\\\223" + "\373\237\277\373\246\304\373\267\317\373\241\301\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\0\0\0\0\0\0\\\223\373" + "\\\223\373\\\223\373D\203\270D\203\270\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\0\0" + "\0\0\0\0\\\223\373\\\223\373(\211n\0\247\0\0n\0(\211n\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\0\0\0\0\0\0\\\223\373(\211n\0\247\0\0\247\0\0\247\0\0\247\0(\211n\\\223" + "\373\\\223\373\\\223\373\\\223\373\210\261\373\246\304\373\241\301\373z\247" + "\373\\\223\373\227\272\373\227\272\373\227\272\373\227\272\373\227\272\373" + "\227\272\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\0\0\0\0\0\0(\211n\0\247\0\0n\0\0\247\0\\\215\12fs\16" + "\0\247\0(\211n\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\" + "\223\373\\\223\373Z\231Z[\230SZ\231Z[\230SZ\231Z[\230S\\\223\373\0\0\0\0" + "\0\0\0\247\0\0\247\0\0\247\0\0\247\0vy\7p|\7\0\247\0\0\247\0(\211n\\\223" + "\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373" + "\\\223\373\\\223\373\\\223\373\\\223\373\\\223\373b\237L\200\317\20\200\317" + "\20\200\317\20\200\317\20\200\317\20\200\317\20[\223H\0\0\0\0\0\0\230P.\323" + "d0\230P.\323d0\221M&\313`%\230P.\323d0\230P.\323d0\230P.\323d0\230P.\323" + "d0\230P.\323d0\230P.\323d0\230P.\323d0\230P.\323d0\230P.\323d0\230P.\323" + "d0\230P.\323d0\230P.\323d0\0\0\0\0\0\0\0\0\0\237N(\225E\35\237N(\225E\35" + "\237N(\225E\35\237N(\225E\35\237N(\225E\35\237N(\225E\35\237N(\225E\35\237" + "N(\225E\35\237N(\225E\35\237N(\225E\35\237N(\225E\35\237N(\225E\35\237N(" + "\225E\35\237N(\225E\35\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", +}; + diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-joystick.c b/branches/fceux-2.2.2/src/attic/pc/sdl-joystick.c new file mode 100644 index 00000000..97f121f1 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-joystick.c @@ -0,0 +1,99 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * Copyright (C) 2002 Paul Kuliniewicz + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* PK: SDL joystick input stuff */ + +#include +#include +#include +#include + +#include "sdl.h" + +#define MAX_JOYSTICKS 32 +static SDL_Joystick *Joysticks[MAX_JOYSTICKS] = {NULL}; + +int DTestButtonJoy(ButtConfig *bc) +{ + int x; + + for(x=0;xNumC;x++) + { + if(bc->ButtonNum[x]&0x8000) /* Axis "button" */ + { + int pos; + pos = SDL_JoystickGetAxis(Joysticks[bc->DeviceNum[x]], bc->ButtonNum[x]&16383); + if ((bc->ButtonNum[x]&0x4000) && pos <= -16383) + return(1); + else if (!(bc->ButtonNum[x]&0x4000) && pos >= 16363) + return(1); + } + else if(bc->ButtonNum[x]&0x2000) /* Hat "button" */ + { + if( SDL_JoystickGetHat(Joysticks[bc->DeviceNum[x]],(bc->ButtonNum[x]>>8)&0x1F) & (bc->ButtonNum[x]&0xFF)) + return(1); + } + else + if(SDL_JoystickGetButton(Joysticks[bc->DeviceNum[x]], bc->ButtonNum[x] )) + return(1); + } + return(0); +} + +static int jinited=0; + +/* Cleanup opened joysticks. */ +int KillJoysticks (void) +{ + int n; /* joystick index */ + + if(!jinited) return(0); + for (n = 0; n < MAX_JOYSTICKS; n++) + { + if (Joysticks[n] != 0) + SDL_JoystickClose(Joysticks[n]); + Joysticks[n]=0; + } + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + return(1); +} + +/* Initialize joysticks. */ +int InitJoysticks (void) +{ + int n; /* joystick index */ + int total; + + SDL_InitSubSystem(SDL_INIT_JOYSTICK); + total=SDL_NumJoysticks(); + if(total>MAX_JOYSTICKS) total=MAX_JOYSTICKS; + + for (n = 0; n < total; n++) + { + /* Open the joystick under SDL. */ + Joysticks[n] = SDL_JoystickOpen(n); + //printf("Could not open joystick %d: %s.\n", + //joy[n] - 1, SDL_GetError()); + continue; + } + jinited=1; + return(1); +} diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-netplay.c b/branches/fceux-2.2.2/src/attic/pc/sdl-netplay.c new file mode 100644 index 00000000..83de4ba5 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-netplay.c @@ -0,0 +1,224 @@ +#include "sdl.h" +#include +#include "sdl-netplay.h" + +char *ServerHost; + +static int LocalPortTCP=0xFCE; +static int LocalPortUDP=0xFCE; +static int RemotePortTCP=0xFCE; + +static int RemotePortUDP; /* Not configurable, figured out during handshake. */ + +static TCPsocket Socket; +static UDPsocket UDPSocket; +static SDLNet_SocketSet set; + + +static void en32(uint8 *buf, uint32 morp) +{ + buf[0]=morp; + buf[1]=morp>>8; + buf[2]=morp>>16; + buf[3]=morp>>24; +} + +static uint32 de32(uint8 *morp) +{ + return(morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24)); +} + + + +int FCEUD_NetworkConnect(void) +{ + IPaddress rip; + + SDLNet_Init(); + + if(netplay==1) /* Be a server. */ + { + TCPsocket tmp; + Uint16 p=LocalPortUDP; + + SDLNet_ResolveHost(&rip,NULL,LocalPortTCP); + + UDPSocket=SDLNet_UDP_Open(&p); + + tmp=SDLNet_TCP_Open(&rip); + Socket=SDLNet_TCP_Accept(&tmp); + + memcpy(&rip,SDLNet_TCP_GetPeerAddress(Socket),sizeof(IPaddress)); + + { + uint8 buf[12]; + uint32 player=1; + + magic=SDL_GetTicks(); + + SDLNet_Write32(buf,uport); + SDLNet_Write32(buf+4,1); + SDLNet_Write32(buf+8,magic); + + SDLNet_TCP_Send(Socket, buf, 12); + + /* Get the UDP port the client is waiting for data on. */ + SDLNet_TCP_Recv(Socket, buf, 2); + RemotePortUDP=de32(buf); + } + } + else /* Be a client */ + { + SDLNet_ResolveHost(&rip,ServerHost,RemotePortTCP); + Socket=SDLNet_TCP_Open(&rip); + + { + Uint16 p=LocalPortUDP; + uint8 buf[12]; + + UDPSocket=SDLNet_UDP_Open(&p); + + /* Now, tell the server what local UDP port it should send to. */ + en32(buf,p); + SDLNet_TCP_Send(Socket, buf, 4); + + /* Get the UDP port from the server we should send data to. */ + SDLNet_TCP_Recv(Socket, buf, 12); + RemotePortUDP=de32(buf); + magic=de32(buf+8); + } + set=SDLNet_AllocSocketSet(1); + SDLNet_TCP_AddSocket(set,TCPSocket); + SDLNet_UDP_AddSocket(set,UDPSocket); + } // End client connect code. + + rip.port=RemotePortUDP; + SDLNet_UDP_Bind(UDPSocket, 0, &rip); +} + + + + +static int CheckUDP(uint8 *packet, int32 len, int32 alt) +{ + uint32 crc; + uint32 repcrc; + + crc=FCEUI_CRC32(0,packet+4,len+8); + repcrc=de32(packet); + + if(crc!=repcrc) return(0); /* CRC32 mismatch, bad packet. */ + packet+=4; + + if(de32(packet)!=magic) /* Magic number mismatch, bad or spoofed packet. */ + return(0); + + packet+=4; + if(alt) + { + if(de32(packet) +#include +#include +#else +#include +#include +#include +#endif +#include +#include + +#include "sdl.h" +#include "sdl-opengl.h" +#include "../common/vidblit.h" + +#ifndef APIENTRY +#define APIENTRY +#endif + +static GLuint textures[2]={0,0}; // Normal image, scanline overlay. + +static int left,right,top,bottom; // right and bottom are not inclusive. +static int scanlines; +static void *HiBuffer; + +void APIENTRY (*p_glBindTexture)(GLenum target,GLuint texture); +void APIENTRY (*p_glColorTableEXT)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +void APIENTRY (*p_glTexImage2D)( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); +void APIENTRY (*p_glBegin)(GLenum mode); +void APIENTRY (*p_glVertex2f)(GLfloat x, GLfloat y); +void APIENTRY (*p_glTexCoord2f)(GLfloat s, GLfloat t); +void APIENTRY (*p_glEnd)(void); +void APIENTRY (*p_glEnable)(GLenum cap); +void APIENTRY (*p_glBlendFunc)(GLenum sfactor, GLenum dfactor); +const GLubyte* APIENTRY (*p_glGetString)(GLenum name); +void APIENTRY (*p_glViewport)(GLint x, GLint y,GLsizei width, GLsizei height); +void APIENTRY (*p_glGenTextures)(GLsizei n, GLuint *textures); +void APIENTRY (*p_glDeleteTextures)(GLsizei n,const GLuint *textures); +void APIENTRY (*p_glTexParameteri)(GLenum target, GLenum pname, GLint param); +void APIENTRY (*p_glClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +void APIENTRY (*p_glLoadIdentity)(void); +void APIENTRY (*p_glClear)(GLbitfield mask); +void APIENTRY (*p_glMatrixMode)(GLenum mode); +void APIENTRY (*p_glDisable)(GLenum cap); + +void SetOpenGLPalette(uint8 *data) +{ + if(!HiBuffer) + { + p_glBindTexture(GL_TEXTURE_2D, textures[0]); + p_glColorTableEXT(GL_TEXTURE_2D,GL_RGB,256,GL_RGBA,GL_UNSIGNED_BYTE,data); + } + else + SetPaletteBlitToHigh((uint8*)data); +} + +void BlitOpenGL(uint8 *buf) +{ + p_glBindTexture(GL_TEXTURE_2D, textures[0]); + if(HiBuffer) + { + static int xo=0; + xo=(xo+1)&3; + Blit8ToHigh(buf,(uint8*)HiBuffer,256,240,256*4,1,1); + if(!xo) + p_glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,256,256, 0, GL_RGBA,GL_UNSIGNED_BYTE, + HiBuffer); + } + else + { + //glPixelStorei(GL_UNPACK_ROW_LENGTH, 256); + p_glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0, + GL_COLOR_INDEX,GL_UNSIGNED_BYTE,buf); + } + + p_glBegin(GL_QUADS); + p_glTexCoord2f(1.0f*left/256, 1.0f*bottom/256); // Bottom left of our picture. + p_glVertex2f(-1.0f, -1.0f); // Bottom left of target. + + p_glTexCoord2f(1.0f*right/256, 1.0f*bottom/256); // Bottom right of our picture. + p_glVertex2f( 1.0f, -1.0f); // Bottom right of target. + + p_glTexCoord2f(1.0f*right/256, 1.0f*top/256); // Top right of our picture. + p_glVertex2f( 1.0f, 1.0f); // Top right of target. + + p_glTexCoord2f(1.0f*left/256, 1.0f*top/256); // Top left of our picture. + p_glVertex2f(-1.0f, 1.0f); // Top left of target. + p_glEnd(); + + //glDisable(GL_BLEND); + if(scanlines) + { + p_glEnable(GL_BLEND); + + p_glBindTexture(GL_TEXTURE_2D, textures[1]); + p_glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA); + + p_glBegin(GL_QUADS); + + p_glTexCoord2f(1.0f*left/256, 1.0f*bottom/256); // Bottom left of our picture. + p_glVertex2f(-1.0f, -1.0f); // Bottom left of target. + + p_glTexCoord2f(1.0f*right/256, 1.0f*bottom/256); // Bottom right of our picture. + p_glVertex2f( 1.0f, -1.0f); // Bottom right of target. + + p_glTexCoord2f(1.0f*right/256, 1.0f*top/256); // Top right of our picture. + p_glVertex2f( 1.0f, 1.0f); // Top right of target. + + p_glTexCoord2f(1.0f*left/256, 1.0f*top/256); // Top left of our picture. + p_glVertex2f(-1.0f, 1.0f); // Top left of target. + + p_glEnd(); + p_glDisable(GL_BLEND); + } + SDL_GL_SwapBuffers(); +} + +void KillOpenGL(void) +{ + if(textures[0]) + p_glDeleteTextures(2, &textures[0]); + textures[0]=0; + if(HiBuffer) + { + free(HiBuffer); + HiBuffer=0; + } +} +/* Rectangle, left, right(not inclusive), top, bottom(not inclusive). */ + +int InitOpenGL(int l, int r, int t, int b, double xscale,double yscale, int efx, int ipolate, + int stretchx, int stretchy, SDL_Surface *screen) +{ + const char *extensions; + + #define LFG(x) if(!(p_##x = SDL_GL_GetProcAddress(#x))) return(0); + + #define LFGN(x) p_##x = SDL_GL_GetProcAddress(#x) + + LFG(glBindTexture); + LFGN(glColorTableEXT); + LFG(glTexImage2D); + LFG(glBegin); + LFG(glVertex2f); + LFG(glTexCoord2f); + LFG(glEnd); + LFG(glEnable); + LFG(glBlendFunc); + LFG(glGetString); + LFG(glViewport); + LFG(glGenTextures); + LFG(glDeleteTextures); + LFG(glTexParameteri); + LFG(glClearColor); + LFG(glLoadIdentity); + LFG(glClear); + LFG(glMatrixMode); + LFG(glDisable); + + left=l; + right=r; + top=t; + bottom=b; + + HiBuffer=0; + + extensions=(const char*)p_glGetString(GL_EXTENSIONS); + + if((efx&2) || !extensions || !p_glColorTableEXT || !strstr(extensions,"GL_EXT_paletted_texture")) + { + if(!(efx&2)) // Don't want to print out a warning message in this case... + FCEU_printf("Paletted texture extension not found. Using slower texture format..."); + HiBuffer=malloc(4*256*256); + memset(HiBuffer,0x00,4*256*256); + #ifndef LSB_FIRST + InitBlitToHigh(4,0xFF000000,0xFF0000,0xFF00,efx&2,0); + #else + InitBlitToHigh(4,0xFF,0xFF00,0xFF0000,efx&2,0); + #endif + } + + { + int rw=(r-l)*xscale; + int rh=(b-t)*yscale; + int sx=(screen->w-rw)/2; // Start x + int sy=(screen->h-rh)/2; // Start y + + if(stretchx) { sx=0; rw=screen->w; } + if(stretchy) { sy=0; rh=screen->h; } + p_glViewport(sx, sy, rw, rh); + } + p_glGenTextures(2, &textures[0]); + scanlines=0; + + if(efx&1) + { + uint8 *buf; + int x,y; + + scanlines=1; + + p_glBindTexture(GL_TEXTURE_2D, textures[1]); + p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST); + p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST); + + buf=(uint8*)malloc(256*(256*2)*4); + + for(y=0;y<(256*2);y++) + for(x=0;x<256;x++) + { + buf[y*256*4+x*4]=0; + buf[y*256*4+x*4+1]=0; + buf[y*256*4+x*4+2]=0; + buf[y*256*4+x*4+3]=(y&1)?0x00:0xFF; //?0xa0:0xFF; // <-- Pretty + //buf[y*256+x]=(y&1)?0x00:0xFF; + } + p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, (scanlines==2)?256*4:512, 0, + GL_RGBA,GL_UNSIGNED_BYTE,buf); + free(buf); + } + p_glBindTexture(GL_TEXTURE_2D, textures[0]); + + p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,ipolate?GL_LINEAR:GL_NEAREST); + p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,ipolate?GL_LINEAR:GL_NEAREST); + p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); + p_glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); + p_glEnable(GL_TEXTURE_2D); + p_glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Background color to black. + p_glMatrixMode(GL_MODELVIEW); + + p_glClear(GL_COLOR_BUFFER_BIT); + p_glLoadIdentity(); + + return(1); +} diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-opengl.h b/branches/fceux-2.2.2/src/attic/pc/sdl-opengl.h new file mode 100644 index 00000000..ca786f53 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-opengl.h @@ -0,0 +1,6 @@ +void SetOpenGLPalette(uint8 *data); +void BlitOpenGL(uint8 *buf); +void KillOpenGL(void); +int InitOpenGL(int l, int r, int t, int b, double xscale,double yscale, int efx, int ipolate, + int stretchx, int stretchy, SDL_Surface *screen); + diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-sound.c b/branches/fceux-2.2.2/src/attic/pc/sdl-sound.c new file mode 100644 index 00000000..f0b522c1 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-sound.c @@ -0,0 +1,373 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "sdl.h" + +#ifdef USE_SEXYAL + +#include "../sexyal/sexyal.h" + +static SexyAL *Interface; +static SexyAL_device *Output; +static SexyAL_format format; +static SexyAL_buffering buffering; + +uint32 GetMaxSound(void) +{ + return(buffering.totalsize); +} + +uint32 GetWriteSound(void) +{ + return(Output->CanWrite(Output)); +} + +void WriteSound(int32 *Buffer, int Count) +{ + //printf("%d\n",Output->CanWrite(Output)); + Output->Write(Output, Buffer, Count); +} + +int InitSound(FCEUGI *gi) +{ + if(!_sound) return(0); + + memset(&format,0,sizeof(format)); + memset(&buffering,0,sizeof(buffering)); + + FCEUI_SetSoundVolume(soundvol); + FCEUI_SetSoundQuality(soundq); + + Interface=SexyAL_Init(0); + + format.sampformat=SEXYAL_FMT_PCMS32S16; + format.channels=gi->soundchan?gi->soundchan:1; + format.rate=gi->soundrate?gi->soundrate:soundrate; + buffering.fragcount=buffering.fragsize=0; + buffering.ms=soundbufsize; + + FCEUI_printf("\nInitializing sound..."); + if(!(Output=Interface->Open(Interface,SEXYAL_ID_UNUSED,&format,&buffering))) + { + FCEUD_PrintError("Error opening a sound device."); + Interface->Destroy(Interface); + Interface=0; + return(0); + } + + if(soundq && format.rate!=48000 && format.rate!=44100 && format.rate!=96000) + { + FCEUD_PrintError("Set sound playback rate neither 44100, 48000, nor 96000, but needs to be when in high-quality sound mode."); + KillSound(); + return(0); + } + + if(format.rate<8192 || format.rate > 96000) + { + FCEUD_PrintError("Set rate is out of range [8192-96000]"); + KillSound(); + return(0); + } + FCEUI_printf("\n Bits: %u\n Rate: %u\n Channels: %u\n Byte order: CPU %s\n Buffer size: %u sample frames(%f ms)\n",(format.sampformat>>4)*8,format.rate,format.channels,format.byteorder?"Reversed":"Native",buffering.totalsize,(double)buffering.totalsize*1000/format.rate); + + format.sampformat=SEXYAL_FMT_PCMS32S16; + format.channels=gi->soundchan?gi->soundchan:1; + format.byteorder=0; + + //format.rate=gi->soundrate?gi->soundrate:soundrate; + + Output->SetConvert(Output,&format); + + FCEUI_Sound(format.rate); + return(1); +} + +void SilenceSound(int n) +{ + +} + +int KillSound(void) +{ + FCEUI_Sound(0); + if(Output) + Output->Close(Output); + if(Interface) + Interface->Destroy(Interface); + Interface=0; + if(!Output) return(0); + Output=0; + return(1); +} + +#elif USE_JACKACK /* Use JACK Audio Connection Kit */ + +#include +#include + +static jack_port_t *output_port = NULL; +static jack_client_t *client = NULL; +static jack_ringbuffer_t *tmpbuf = NULL; +static unsigned int BufferSize; + +static int process(jack_nframes_t nframes, void *arg) +{ + jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer(output_port, nframes); + size_t canread; + + canread = jack_ringbuffer_read_space(tmpbuf) / sizeof(jack_default_audio_sample_t); + + if(canread > nframes) + canread = nframes; + + jack_ringbuffer_read(tmpbuf, out,canread * sizeof(jack_default_audio_sample_t)); + nframes -= canread; + + if(nframes) /* Buffer underflow. Hmm. */ + { + + } + +} + +uint32 GetMaxSound(void) +{ + return(BufferSize); +} + +uint32 GetWriteSound(void) +{ + return(jack_readbuffer_write_space / sizeof(jack_default_audio_sample_t)); +} + + +static void DeadSound(void *arg) +{ + puts("AGH! Sound server hates us! Let's go on a rampage."); +} + +int InitSound(FCEUGI *gi) +{ + const char **ports; + + client = jack_client_new("FCE Ultra"); + + jack_set_process_callback(client, process, 0); + jack_on_shutdown(client, DeadSound, 0); + + printf("%ld\n",jack_get_sample_rate(client)); + + output_port = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + + BufferSize = soundbufsize * soundrate / 1000; + + tmpbuf = jack_ringbuffer_create(BufferSize * sizeof(jack_default_audio_sample_t)); + + jack_activate(client); + + + ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); + jack_connect(client, jack_port_name(output_port), ports[0]); + free(ports); +} + +void WriteSound(int32 *buf, int Count) +{ + jack_default_audio_sample_t jbuf[Count]; + int x; + + for(x=0;x>= 1; + + while(len) + { + int16 sample = 0; + if(BufferIn) + { + sample = Buffer[BufferRead]; + BufferRead = (BufferRead + 1) % BufferSize; + BufferIn--; + } + else sample = 0; + + *tmps = sample; + tmps++; + len--; + } +} + +int InitSound(FCEUGI *gi) +{ + SDL_AudioSpec spec; + if(!_sound) return(0); + + memset(&spec,0,sizeof(spec)); + if(SDL_InitSubSystem(SDL_INIT_AUDIO)<0) + { + puts(SDL_GetError()); + KillSound(); + return(0); + } + + spec.freq = soundrate; + spec.format = AUDIO_S16SYS; + spec.channels = 1; + spec.samples = 256; + spec.callback = fillaudio; + spec.userdata = 0; + + BufferSize = soundbufsize * soundrate / 1000; + + BufferSize -= spec.samples * 2; /* SDL uses at least double-buffering, so + multiply by 2. */ + + if(BufferSize < spec.samples) BufferSize = spec.samples; + + Buffer = malloc(sizeof(int) * BufferSize); + BufferRead = BufferWrite = BufferIn = 0; + + //printf("SDL Size: %d, Internal size: %d\n",spec.samples,BufferSize); + + if(SDL_OpenAudio(&spec,0)<0) + { + puts(SDL_GetError()); + KillSound(); + return(0); + } + SDL_PauseAudio(0); + FCEUI_Sound(soundrate); + return(1); +} + + +uint32 GetMaxSound(void) +{ + return(BufferSize); +} + +uint32 GetWriteSound(void) +{ + return(BufferSize - BufferIn); +} + +void WriteSound(int32 *buf, int Count) +{ + while(Count) + { + while(BufferIn == BufferSize) SDL_Delay(1); + Buffer[BufferWrite] = *buf; + Count--; + BufferWrite = (BufferWrite + 1) % BufferSize; + BufferIn++; + buf++; + } +} + +void SilenceSound(int n) +{ + SDL_PauseAudio(n); +} + +int KillSound(void) +{ + FCEUI_Sound(0); + SDL_CloseAudio(); + SDL_QuitSubSystem(SDL_INIT_AUDIO); + if(Buffer) + { + free(Buffer); + Buffer = 0; + } + return(0); +} + + +#endif + + +static int mute=0; +static int soundvolume=100; +void FCEUD_SoundVolumeAdjust(int n) +{ + switch(n) + { + case -1: soundvolume-=10; if(soundvolume<0) soundvolume=0; break; + case 0: soundvolume=100; break; + case 1: soundvolume+=10; if(soundvolume>150) soundvolume=150; break; + } + mute=0; + FCEUI_SetSoundVolume(soundvolume); + FCEU_DispMessage("Sound volume %d.", soundvolume); +} +void FCEUD_SoundToggle(void) +{ + if(mute) + { + mute=0; + FCEUI_SetSoundVolume(soundvolume); + FCEU_DispMessage("Sound mute off."); + } + else + { + mute=1; + FCEUI_SetSoundVolume(0); + FCEU_DispMessage("Sound mute on."); + } +} diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-throttle.c b/branches/fceux-2.2.2/src/attic/pc/sdl-throttle.c new file mode 100644 index 00000000..253ad885 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-throttle.c @@ -0,0 +1,86 @@ +#include "sdl.h" +#include "throttle.h" + +static uint64 tfreq; +static uint64 desiredfps; + +static int32 fps_scale_table[]= +{ 3, 3, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 2048 }; +int32 fps_scale = 256; + +#define fps_table_size (sizeof(fps_scale_table)/sizeof(fps_scale_table[0])) + +void RefreshThrottleFPS(void) +{ + desiredfps=FCEUI_GetDesiredFPS()>>8; + desiredfps=(desiredfps*fps_scale)>>8; + tfreq=10000000; + tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */ +} + +void SpeedThrottle(void) +{ + static uint64 ttime,ltime=0; + + waiter: + + ttime=SDL_GetTicks(); + ttime*=10000; + + if( (ttime-ltime) < (tfreq/desiredfps) ) + { + int64 delay; + delay=(tfreq/desiredfps)-(ttime-ltime); + if(delay>0) + SDL_Delay(delay/10000); + //printf("%d\n",(tfreq/desiredfps)-(ttime-ltime)); + //SDL_Delay((tfreq/desiredfps)-(ttime-ltime)); + goto waiter; + } + if( (ttime-ltime) >= (tfreq*4/desiredfps)) + ltime=ttime; + else + ltime+=tfreq/desiredfps; +} + +void IncreaseEmulationSpeed(void) +{ + int i; + for(i=1; fps_scale_table[i]>8); +} + +void DecreaseEmulationSpeed(void) +{ + int i; + for(i=1; fps_scale_table[i]>8); +} + +void FCEUD_SetEmulationSpeed(int cmd) +{ + switch(cmd) + { + case EMUSPEED_SLOWEST: fps_scale=fps_scale_table[0]; break; + case EMUSPEED_SLOWER: DecreaseEmulationSpeed(); break; + case EMUSPEED_NORMAL: fps_scale=256; break; + case EMUSPEED_FASTER: IncreaseEmulationSpeed(); break; + case EMUSPEED_FASTEST: fps_scale=fps_scale_table[fps_table_size-1]; break; + default: + return; + } + + RefreshThrottleFPS(); + + FCEU_DispMessage("emulation speed %d%%",(fps_scale*100)>>8); +} diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-video.c b/branches/fceux-2.2.2/src/attic/pc/sdl-video.c new file mode 100644 index 00000000..5886f0fb --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-video.c @@ -0,0 +1,432 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include "sdl.h" +#include "sdl-opengl.h" +#include "../common/vidblit.h" + +#include "sdl-icon.h" +#include "dface.h" + +SDL_Surface *screen; +SDL_Surface *BlitBuf; // Used as a buffer when using hardware-accelerated blits. +SDL_Surface *IconSurface=NULL; + +static int curbpp; +static int srendline,erendline; +static int tlines; +static int inited=0; + +#ifdef OPENGL +extern int sdlhaveogl; +static int usingogl; +static double exs,eys; +#else +static int exs,eys; +#endif +static int eefx; + +#define NWIDTH (256-((eoptions&EO_CLIPSIDES)?16:0)) +#define NOFFSET (eoptions&EO_CLIPSIDES?8:0) + + +static int paletterefresh; + +/* Return 1 if video was killed, 0 otherwise(video wasn't initialized). */ +int KillVideo(void) +{ + if(IconSurface) + { + SDL_FreeSurface(IconSurface); + IconSurface=0; + } + + if(inited&1) + { + #ifdef OPENGL + if(usingogl) + KillOpenGL(); + else + #endif + if(curbpp>8) + KillBlitToHigh(); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + inited&=~1; + return(1); + } + inited=0; + return(0); +} + +static int sponge; + +int InitVideo(FCEUGI *gi) +{ + const SDL_VideoInfo *vinf; + int flags=0; + + FCEUI_printf("Initializing video..."); + + FCEUI_GetCurrentVidSystem(&srendline,&erendline); + + if(_fullscreen) sponge=Settings.specialfs; + else sponge=Settings.special; + + + #ifdef OPENGL + usingogl=0; + if(_opengl && sdlhaveogl && !sponge) + { + flags=SDL_OPENGL; + usingogl=1; + } + #endif + + #ifdef EXTGUI + GUI_SetVideo(_fullscreen, 0, 0); + #endif + + if(!(SDL_WasInit(SDL_INIT_VIDEO)&SDL_INIT_VIDEO)) + if(SDL_InitSubSystem(SDL_INIT_VIDEO)==-1) + { + FCEUD_PrintError(SDL_GetError()); + return(0); + } + inited|=1; + + SDL_ShowCursor(0); + tlines=erendline-srendline+1; + + vinf=SDL_GetVideoInfo(); + + if(vinf->hw_available) + flags|=SDL_HWSURFACE; + + if(_fullscreen) + flags|=SDL_FULLSCREEN; + + flags|=SDL_HWPALETTE; + + //flags|=SDL_DOUBLEBUF; + #ifdef OPENGL + if(usingogl) + { + FCEU_printf("\n Initializing with OpenGL(Use \"-opengl 0\" to disable).\n"); + if(_doublebuf) + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + } + else + #endif + if(_doublebuf && (flags&SDL_HWSURFACE)) + flags|=SDL_DOUBLEBUF; + + if(_fullscreen) + { + int desbpp=_bpp; + + exs=_xscalefs; + eys=_yscalefs; + eefx=_efxfs; + + #ifdef OPENGL + if(!usingogl) {exs=(int)exs;eys=(int)eys;} + else desbpp=0; + + if(sponge) + { + exs=eys=2; + if(sponge == 3 || sponge == 4) exs = eys = 3; + eefx=0; + if(sponge == 1 || sponge == 3) desbpp = 32; + } + + + if( (usingogl && !_stretchx) || !usingogl) + #endif + if(_xres= 3) exs=eys=3; + eefx=0; + // SDL's 32bpp->16bpp code is slighty faster than mine, at least :/ + if(sponge == 1 || sponge == 3) desbpp=32; + } + + #ifdef OPENGL + if(!usingogl) {exs=(int)exs;eys=(int)eys;} + if(exs <= 0.01) + { + FCEUD_PrintError("xscale out of bounds."); + KillVideo(); + return(0); + } + if(eys <= 0.01) + { + FCEUD_PrintError("yscale out of bounds."); + KillVideo(); + return(0); + } + #endif + + #ifdef EXTGUI + GUI_SetVideo(_fullscreen, (NWIDTH*exs), tlines*eys); + #endif + + screen = SDL_SetVideoMode((NWIDTH*exs), tlines*eys, desbpp, flags); + } + curbpp=screen->format->BitsPerPixel; + if(!screen) + { + FCEUD_PrintError(SDL_GetError()); + KillVideo(); + return(0); + } + //BlitBuf=SDL_CreateRGBSurface(SDL_HWSURFACE,256,240,screen->format->BitsPerPixel,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0); + + inited=1; + + FCEU_printf(" Video Mode: %d x %d x %d bpp %s\n",screen->w,screen->h,screen->format->BitsPerPixel,_fullscreen?"full screen":""); + if(curbpp!=16 && curbpp!=24 && curbpp!=8 && curbpp!=32) + { + FCEU_printf(" Sorry, %dbpp modes are not supported by FCE Ultra. Supported bit depths are 8bpp, 16bpp, and 32bpp.\n",curbpp); + KillVideo(); + return(0); + } + + if(gi->name) + SDL_WM_SetCaption(gi->name,gi->name); + else + SDL_WM_SetCaption("FCE Ultra","FCE Ultra"); + + #ifdef LSB_FIRST + IconSurface=SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,32,32,24,32*3,0xFF,0xFF00,0xFF0000,0x00); + #else + IconSurface=SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,32,32,24,32*3,0xFF0000,0xFF00,0xFF,0x00); + #endif + + SDL_WM_SetIcon(IconSurface,0); + + paletterefresh=1; + + if(curbpp>8) + #ifdef OPENGL + if(!usingogl) + #endif + InitBlitToHigh(curbpp>>3,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,eefx,sponge); + #ifdef OPENGL + if(usingogl) + if(!InitOpenGL((eoptions&EO_CLIPSIDES)?8:0,256-((eoptions&EO_CLIPSIDES)?8:0),srendline,erendline+1,exs,eys,eefx,_openglip,_stretchx,_stretchy,screen)) + { + FCEUD_PrintError("Error initializing OpenGL."); + KillVideo(); + return(0); + } + #endif + return 1; +} + +void ToggleFS(void) +{ + extern FCEUGI *CurGame; + KillVideo(); + _fullscreen=!_fullscreen; + + if(!InitVideo(CurGame)) + { + _fullscreen=!_fullscreen; + InitVideo(CurGame); + } +} + +static SDL_Color psdl[256]; +void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b) +{ + psdl[index].r=r; + psdl[index].g=g; + psdl[index].b=b; + + paletterefresh=1; +} + +void FCEUD_GetPalette(uint8 index, uint8 *r, uint8 *g, uint8 *b) +{ + *r=psdl[index].r; + *g=psdl[index].g; + *b=psdl[index].b; +} + +static void RedoPalette(void) +{ + #ifdef OPENGL + if(usingogl) + SetOpenGLPalette((uint8*)psdl); + else + #endif + { + if(curbpp>8) + SetPaletteBlitToHigh((uint8*)psdl); + else + { + SDL_SetPalette(screen,SDL_PHYSPAL,psdl,0,256); + } + } +} + +void LockConsole(){} +void UnlockConsole(){} +void BlitScreen(uint8 *XBuf) +{ + SDL_Surface *TmpScreen; + uint8 *dest; + int xo=0,yo=0; + + if(!screen) return; + + if(paletterefresh) + { + RedoPalette(); + paletterefresh=0; + } + + #ifdef OPENGL + if(usingogl) + { + BlitOpenGL(XBuf); + return; + } + #endif + + XBuf+=srendline*256; + + if(BlitBuf) TmpScreen=BlitBuf; + else TmpScreen=screen; + + if(SDL_MUSTLOCK(TmpScreen)) + if(SDL_LockSurface(TmpScreen)) + { + return; + } + + dest=(uint8*)TmpScreen->pixels; + + if(_fullscreen) + { + xo=(((TmpScreen->w-NWIDTH*exs))/2); + dest+=xo*(curbpp>>3); + if(TmpScreen->h>(tlines*eys)) + { + yo=((TmpScreen->h-tlines*eys)/2); + dest+=yo*TmpScreen->pitch; + } + } + + if(curbpp>8) + { + if(BlitBuf) + Blit8ToHigh(XBuf+NOFFSET,dest, NWIDTH, tlines, TmpScreen->pitch,1,1); + else + Blit8ToHigh(XBuf+NOFFSET,dest, NWIDTH, tlines, TmpScreen->pitch,exs,eys); + } + else + { + if(BlitBuf) + Blit8To8(XBuf+NOFFSET,dest, NWIDTH, tlines, TmpScreen->pitch,1,1,0,sponge); + else + Blit8To8(XBuf+NOFFSET,dest, NWIDTH, tlines, TmpScreen->pitch,exs,eys,eefx,sponge); + } + if(SDL_MUSTLOCK(TmpScreen)) + SDL_UnlockSurface(TmpScreen); + + if(BlitBuf) + { + SDL_Rect srect; + SDL_Rect drect; + + srect.x=0; + srect.y=0; + srect.w=NWIDTH; + srect.h=tlines; + + drect.x=0; + drect.y=0; + drect.w=exs*NWIDTH; + drect.h=eys*tlines; + + SDL_BlitSurface(BlitBuf, &srect,screen,&drect); + } + + SDL_UpdateRect(screen, xo, yo, NWIDTH*exs, tlines*eys); + + if(screen->flags&SDL_DOUBLEBUF) + SDL_Flip(screen); +} + +uint32 PtoV(uint16 x, uint16 y) +{ + y=(double)y/eys; + x=(double)x/exs; + if(eoptions&EO_CLIPSIDES) + x+=8; + y+=srendline; + return(x|(y<<16)); +} diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl-video.h b/branches/fceux-2.2.2/src/attic/pc/sdl-video.h new file mode 100644 index 00000000..4a4f056d --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl-video.h @@ -0,0 +1 @@ +uint32 PtoV(uint16 x, uint16 y); diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl.c b/branches/fceux-2.2.2/src/attic/pc/sdl.c new file mode 100644 index 00000000..c2e939fc --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl.c @@ -0,0 +1,429 @@ +#include +#include +#include + +#include "sdl.h" +#include "sdl-video.h" +#ifdef NETWORK +#include "unix-netplay.h" +#endif + +DSETTINGS Settings; +CFGSTRUCT DriverConfig[]={ + #ifdef OPENGL + AC(_stretchx), + AC(_stretchy), + AC(_opengl), + AC(_openglip), + #endif + AC(Settings.special), + AC(Settings.specialfs), + AC(_doublebuf), + AC(_xscale), + AC(_yscale), + AC(_xscalefs), + AC(_yscalefs), + AC(_bpp), + AC(_efx), + AC(_efxfs), + AC(_fullscreen), + AC(_xres), + AC(_yres), + #ifdef NETWORK + ACS(netplaynick), + AC(netlocalplayers), + AC(tport), + ACS(netpassword), + ACS(netgamekey), + #endif + ENDCFGSTRUCT +}; + +//-fshack x Set the environment variable SDL_VIDEODRIVER to \"x\" when +// entering full screen mode and x is not \"0\". + +char *DriverUsage= +"-xres x Set horizontal resolution to x for full screen mode.\n\ +-yres x Set vertical resolution to x for full screen mode.\n\ +-xscale(fs) x Multiply width by x(Real numbers >0 with OpenGL, otherwise integers >0).\n\ +-yscale(fs) x Multiply height by x(Real numbers >0 with OpenGL, otherwise integers >0).\n\ +-bpp(fs) x Bits per pixel for SDL surface(and video mode in fs). 8, 16, 32.\n\ +-opengl x Enable OpenGL support if x is 1.\n\ +-openglip x Enable OpenGL linear interpolation if x is 1.\n\ +-doublebuf x \n\ +-special(fs) x Specify special scaling filter.\n\ +-stretch(x/y) x Stretch to fill surface on x or y axis(fullscreen, only with OpenGL).\n\ +-efx(fs) x Enable special effects. Logically OR the following together:\n\ + 1 = scanlines(for yscale>=2).\n\ + 2 = TV blur(for bpp of 16 or 32).\n\ +-fs x Select full screen mode if x is non zero.\n\ +-connect s Connect to server 's' for TCP/IP network play.\n\ +-netnick s Set the nickname to use in network play.\n\ +-netgamekey s Use key 's' to create a unique session for the game loaded.\n\ +-netpassword s Password to use for connecting to the server.\n\ +-netlocalplayers x Set the number of local players.\n\ +-netport x Use TCP/IP port x for network play."; + +ARGPSTRUCT DriverArgs[]={ + #ifdef OPENGL + {"-opengl",0,&_opengl,0}, + {"-openglip",0,&_openglip,0}, + {"-stretchx",0,&_stretchx,0}, + {"-stretchy",0,&_stretchy,0}, + #endif + {"-special",0,&Settings.special,0}, + {"-specialfs",0,&Settings.specialfs,0}, + {"-doublebuf",0,&_doublebuf,0}, + {"-bpp",0,&_bpp,0}, + {"-xscale",0,&_xscale,2}, + {"-yscale",0,&_yscale,2}, + {"-efx",0,&_efx,0}, + {"-xscalefs",0,&_xscalefs,2}, + {"-yscalefs",0,&_yscalefs,2}, + {"-efxfs",0,&_efxfs,0}, + {"-xres",0,&_xres,0}, + {"-yres",0,&_yres,0}, + {"-fs",0,&_fullscreen,0}, + //{"-fshack",0,&_fshack,0x4001}, + #ifdef NETWORK + {"-connect",0,&netplayhost,0x4001}, + {"-netport",0,&tport,0}, + {"-netlocalplayers",0,&netlocalplayers,0}, + {"-netnick",0,&netplaynick,0x4001}, + {"-netpassword",0,&netpassword,0x4001}, + #endif + {0,0,0,0} +}; + +static void SetDefaults(void) +{ + Settings.special=Settings.specialfs=0; + _bpp=8; + _xres=640; + _yres=480; + _fullscreen=0; + _xscale=2.50; + _yscale=2; + _xscalefs=_yscalefs=2; + _efx=_efxfs=0; + //_fshack=_fshacksave=0; +#ifdef OPENGL + _opengl=1; + _stretchx=1; + _stretchy=0; + _openglip=1; +#endif +} + +void DoDriverArgs(void) +{ + #ifdef BROKEN + if(_fshack) + { + if(_fshack[0]=='0') + if(_fshack[1]==0) + { + free(_fshack); + _fshack=0; + } + } + #endif +} + +int InitMouse(void) +{ + return(0); +} + +void KillMouse(void){} + +void GetMouseData(uint32 *d) +{ + if(FCEUI_IsMovieActive()<0) + return; + + int x,y; + uint32 t; + + t=SDL_GetMouseState(&x,&y); + #ifdef EXTGUI + GUI_GetMouseState(&t,&x,&y); + #endif + + d[2]=0; + if(t&SDL_BUTTON(1)) + d[2]|=1; + if(t&SDL_BUTTON(3)) + d[2]|=2; + t=PtoV(x,y); + d[0]=t&0xFFFF; + d[1]=(t>>16)&0xFFFF; +} + +int InitKeyboard(void) +{ + return(1); +} + +int UpdateKeyboard(void) +{ + return(1); +} + +void KillKeyboard(void) +{ + +} + + +void UpdatePhysicalInput(void) +{ + SDL_Event event; + + while(SDL_PollEvent(&event)) + { + switch(event.type) + { + //case SDL_SYSWMEVENT: puts("Nifty keen");break; + //case SDL_VIDEORESIZE: puts("Okie dokie");break; + case SDL_QUIT: CloseGame();puts("Quit");break; + } + //printf("Event: %d\n",event.type); + //fflush(stdout); + } + //SDL_PumpEvents(); +} + +static uint8 *KeyState=NULL; +char *GetKeyboard(void) +{ + KeyState=SDL_GetKeyState(0); + #ifdef EXTGUI + { char *tmp=GUI_GetKeyboard(); if(tmp) KeyState=tmp; } + #endif + return((char *)KeyState); +} + +#ifdef WIN32 +#include + + /* Stupid SDL */ + #ifdef main + #undef main + #endif +#endif + +#ifndef EXTGUI +uint8 *GetBaseDirectory(void) +{ + uint8 *ol; + uint8 *ret; + + ol=getenv("HOME"); + + if(ol) + { + ret=malloc(strlen(ol)+1+strlen("./fceultra")); + strcpy(ret,ol); + strcat(ret,"/.fceultra"); + } + else + { + #ifdef WIN32 + char *sa; + + ret=malloc(MAX_PATH+1); + GetModuleFileName(NULL,ret,MAX_PATH+1); + + sa=strrchr(ret,'\\'); + if(sa) + *sa = 0; + #else + ret=malloc(1); + ret[0]=0; + #endif + printf("%s\n",ret); + } + return(ret); +} +#endif + +#ifdef OPENGL +int sdlhaveogl; +#endif + + +int DTestButton(ButtConfig *bc) +{ + int x; + + for(x=0;xNumC;x++) + { + if(bc->ButtType[x]==BUTTC_KEYBOARD) + { + if(KeyState[bc->ButtonNum[x]]) + return(1); + } + else if(bc->ButtType[x]==BUTTC_JOYSTICK) + { + if(DTestButtonJoy(bc)) + return(1); + } + } + return(0); +} + +static int bcpv,bcpj; + +int ButtonConfigBegin(void) +{ + SDL_Surface *screen; + SDL_QuitSubSystem(SDL_INIT_VIDEO); + bcpv=KillVideo(); + bcpj=KillJoysticks(); + + if(!(SDL_WasInit(SDL_INIT_VIDEO)&SDL_INIT_VIDEO)) + if(SDL_InitSubSystem(SDL_INIT_VIDEO)==-1) + { + FCEUD_Message(SDL_GetError()); + return(0); + } + + screen = SDL_SetVideoMode(300, 1, 8, 0); + SDL_WM_SetCaption("Button Config",0); + InitJoysticks(); + + return(1); +} + +void ButtonConfigEnd(void) +{ + extern FCEUGI *CurGame; + KillJoysticks(); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + if(bcpv) InitVideo(CurGame); + if(bcpj) InitJoysticks(); +} + +int DWaitButton(const uint8 *text, ButtConfig *bc, int wb) +{ + SDL_Event event; + static int32 LastAx[64][64]; + int x,y; + + SDL_WM_SetCaption(text,0); + #ifndef EXTGUI + puts(text); + #endif + for(x=0;x<64;x++) + for(y=0;y<64;y++) + LastAx[x][y]=0x100000; + + while(SDL_WaitEvent(&event)) + { + switch(event.type) + { + case SDL_KEYDOWN:bc->ButtType[wb]=BUTTC_KEYBOARD; + bc->DeviceNum[wb]=0; + bc->ButtonNum[wb]=event.key.keysym.sym; + return(1); + case SDL_JOYBUTTONDOWN:bc->ButtType[wb]=BUTTC_JOYSTICK; + bc->DeviceNum[wb]=event.jbutton.which; + bc->ButtonNum[wb]=event.jbutton.button; + return(1); + case SDL_JOYHATMOTION:if(event.jhat.value != SDL_HAT_CENTERED) + { + bc->ButtType[wb]=BUTTC_JOYSTICK; + bc->DeviceNum[wb]=event.jhat.which; + bc->ButtonNum[wb]=0x2000|((event.jhat.hat&0x1F)<<8)|event.jhat.value; + return(1); + } + break; + case SDL_JOYAXISMOTION: + if(LastAx[event.jaxis.which][event.jaxis.axis]==0x100000) + { + if(abs(event.jaxis.value)<1000) + LastAx[event.jaxis.which][event.jaxis.axis]=event.jaxis.value; + } + else + { + if(abs(LastAx[event.jaxis.which][event.jaxis.axis]-event.jaxis.value)>=8192) + { + bc->ButtType[wb]=BUTTC_JOYSTICK; + bc->DeviceNum[wb]=event.jaxis.which; + bc->ButtonNum[wb]=0x8000|(event.jaxis.axis)|((event.jaxis.value<0)?0x4000:0); + return(1); + } + } + break; + } + } + + return(0); +} + +#ifdef EXTGUI +int FCEUSDLmain(int argc, char *argv[]) +#else +int main(int argc, char *argv[]) +#endif +{ + FCEUD_Message("\nStarting FCE Ultra "FCEU_VERSION"...\n"); + + #ifdef WIN32 + /* Taken from win32 sdl_main.c */ + SDL_SetModuleHandle(GetModuleHandle(NULL)); + #endif + + if(SDL_Init(SDL_INIT_VIDEO)) /* SDL_INIT_VIDEO Needed for (joystick config) event processing? */ + { + printf("Could not initialize SDL: %s.\n", SDL_GetError()); + return(-1); + } + + #ifdef OPENGL + #ifdef APPLEOPENGL + sdlhaveogl = 1; /* Stupid something... Hack. */ + #else + if(!SDL_GL_LoadLibrary(0)) sdlhaveogl=1; + else sdlhaveogl=0; + #endif + #endif + + SetDefaults(); + + { + int ret=CLImain(argc,argv); + SDL_Quit(); + return(ret?0:-1); + } +} + + +uint64 FCEUD_GetTime(void) +{ + return(SDL_GetTicks()); +} + +uint64 FCEUD_GetTimeFreq(void) +{ + return(1000); +} + +// dummy functions + +#define DUMMY(f) void f(void) {FCEU_DispMessage("Not implemented.");} +DUMMY(FCEUD_HideMenuToggle) +DUMMY(FCEUD_TurboOn) +DUMMY(FCEUD_TurboOff) +DUMMY(FCEUD_SaveStateAs) +DUMMY(FCEUD_LoadStateFrom) +DUMMY(FCEUD_MovieRecordTo) +DUMMY(FCEUD_MovieReplayFrom) +DUMMY(FCEUD_ToggleStatusIcon) +DUMMY(FCEUD_AviRecordTo) +DUMMY(FCEUD_AviStop) +void FCEUI_AviVideoUpdate(const unsigned char* buffer) {FCEU_DispMessage("Not implemented.");} +int FCEUD_ShowStatusIcon(void) {FCEU_DispMessage("Not implemented."); return 0; } +int FCEUI_AviIsRecording(void) {return 0;} + diff --git a/branches/fceux-2.2.2/src/attic/pc/sdl.h b/branches/fceux-2.2.2/src/attic/pc/sdl.h new file mode 100644 index 00000000..791316a8 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/sdl.h @@ -0,0 +1,50 @@ +#include +#include "main.h" +#include "dface.h" +#include "input.h" + +int DTestButtonJoy(ButtConfig *bc); + +typedef struct { + int xres; + int yres; + double xscale,yscale; + double xscalefs,yscalefs; + int efx,efxfs; + int bpp; + int fullscreen; + int doublebuf; + char *fshack; + char *fshacksave; + #ifdef OPENGL + int opengl; + int openglip; + int stretchx,stretchy; + #endif + int special,specialfs; +} DSETTINGS; + +extern DSETTINGS Settings; + +#define _doublebuf Settings.doublebuf +#define _bpp Settings.bpp +#define _xres Settings.xres +#define _yres Settings.yres +#define _fullscreen Settings.fullscreen +#define _xscale Settings.xscale +#define _yscale Settings.yscale +#define _xscalefs Settings.xscalefs +#define _yscalefs Settings.yscalefs +#define _efx Settings.efx +#define _efxfs Settings.efxfs +#define _ebufsize Settings.ebufsize +#define _fshack Settings.fshack +#define _fshacksave Settings.fshacksave + +#ifdef OPENGL +#define _opengl Settings.opengl +#define _openglip Settings.openglip +#define _stretchx Settings.stretchx +#define _stretchy Settings.stretchy +#endif + diff --git a/branches/fceux-2.2.2/src/attic/pc/throttle.c b/branches/fceux-2.2.2/src/attic/pc/throttle.c new file mode 100644 index 00000000..422dad79 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/throttle.c @@ -0,0 +1,41 @@ +#include +#include "main.h" +#include "throttle.h" + +static uint64 tfreq; +static uint64 desiredfps; + +void RefreshThrottleFPS(void) +{ + desiredfps=FCEUI_GetDesiredFPS()>>8; + tfreq=1000000; + tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */ +} + +static uint64 GetCurTime(void) +{ + uint64 ret; + struct timeval tv; + + gettimeofday(&tv,0); + ret=(uint64)tv.tv_sec*1000000; + ret+=tv.tv_usec; + return(ret); +} + +void SpeedThrottle(void) +{ + static uint64 ttime,ltime=0; + + waiter: + + ttime=GetCurTime(); + + if( (ttime-ltime) < (tfreq/desiredfps) ) + goto waiter; + if( (ttime-ltime) >= (tfreq*4/desiredfps)) + ltime=ttime; + else + ltime+=tfreq/desiredfps; +} + diff --git a/branches/fceux-2.2.2/src/attic/pc/throttle.h b/branches/fceux-2.2.2/src/attic/pc/throttle.h new file mode 100644 index 00000000..d6ca2aa8 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/throttle.h @@ -0,0 +1,2 @@ +void RefreshThrottleFPS(void); +void SpeedThrottle(void); diff --git a/branches/fceux-2.2.2/src/attic/pc/unix-netplay.c b/branches/fceux-2.2.2/src/attic/pc/unix-netplay.c new file mode 100644 index 00000000..5bef56e2 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/unix-netplay.c @@ -0,0 +1,292 @@ +#ifdef NETWORK +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "main.h" +#include "dface.h" +#include "unix-netplay.h" + +#include "../../md5.h" + +#ifndef socklen_t +#define socklen_t int +#endif + +#ifndef SOL_TCP +#define SOL_TCP IPPROTO_TCP +#endif + + +char *netplayhost=0; +char *netplaynick=0; +char *netgamekey = 0; +char *netpassword = 0; +int netlocalplayers = 1; + +int Port=0xFCE; +int FCEUDnetplay=0; + +int tport=0xFCE; + +static int Socket=-1; + +static void en32(uint8 *buf, uint32 morp) +{ + buf[0]=morp; + buf[1]=morp>>8; + buf[2]=morp>>16; + buf[3]=morp>>24; +} +/* +static uint32 de32(uint8 *morp) +{ + return(morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24)); +} +*/ +int FCEUD_NetworkConnect(void) +{ + struct sockaddr_in sockin; /* I want to play with fighting robots. */ + struct hostent *phostentb; + unsigned long hadr; + int TSocket; + int netdivisor; + + if(!netplayhost) return(0); + + if( (TSocket=socket(AF_INET,SOCK_STREAM,0))==-1) + { + puts("Error creating stream socket."); + FCEUD_NetworkClose(); + return(0); + } + + { + int tcpopt = 1; + #ifdef BEOS + if(setsockopt(TSocket, SOL_SOCKET, TCP_NODELAY, &tcpopt, sizeof(int))) + #else + if(setsockopt(TSocket, SOL_TCP, TCP_NODELAY, &tcpopt, sizeof(int))) + #endif + puts("Nodelay fail"); + } + + memset(&sockin,0,sizeof(sockin)); + sockin.sin_family=AF_INET; + + hadr=inet_addr(netplayhost); + + if(hadr!=INADDR_NONE) + sockin.sin_addr.s_addr=hadr; + else + { + puts("*** Looking up host name..."); + if(!(phostentb=gethostbyname((const char *)netplayhost))) + { + puts("Error getting host network information."); + close(TSocket); + FCEUD_NetworkClose(); + return(0); + } + memcpy(&sockin.sin_addr,phostentb->h_addr,phostentb->h_length); + } + + sockin.sin_port=htons(tport); + puts("*** Connecting to remote host..."); + if(connect(TSocket,(struct sockaddr *)&sockin,sizeof(sockin))==-1) + { + puts("Error connecting to remote host."); + close(TSocket); + FCEUD_NetworkClose(); + return(0); + } + Socket=TSocket; + puts("*** Sending initialization data to server..."); + { + uint8 *sendbuf; + uint8 buf[5]; + uint32 sblen; + + sblen = 4 + 16 + 16 + 64 + 1 + (netplaynick?strlen(netplaynick):0); + sendbuf = malloc(sblen); + memset(sendbuf, 0, sblen); + + en32(sendbuf, sblen - 4); + + if(netgamekey) + { + struct md5_context md5; + uint8 md5out[16]; + + md5_starts(&md5); + md5_update(&md5, CurGame->MD5, 16); + md5_update(&md5, netgamekey, strlen(netgamekey)); + md5_finish(&md5, md5out); + memcpy(sendbuf + 4, md5out, 16); + } + else + memcpy(sendbuf + 4, CurGame->MD5, 16); + + if(netpassword) + { + struct md5_context md5; + uint8 md5out[16]; + + md5_starts(&md5); + md5_update(&md5, netpassword, strlen(netpassword)); + md5_finish(&md5, md5out); + memcpy(sendbuf + 4 + 16, md5out, 16); + } + + memset(sendbuf + 4 + 16 + 16, 0, 64); + + sendbuf[4 + 16 + 16 + 64] = netlocalplayers; + + if(netplaynick) + memcpy(sendbuf + 4 + 16 + 16 + 64 + 1,netplaynick,strlen(netplaynick)); + + send(Socket, sendbuf, sblen, 0); + free(sendbuf); + + recv(Socket, buf, 1, MSG_WAITALL); + netdivisor = buf[0]; + } + + puts("*** Connection established."); + + FCEUDnetplay = 1; + FCEUI_NetplayStart(netlocalplayers, netdivisor); + return(1); +} + + +int FCEUD_SendData(void *data, uint32 len) +{ + int check; + if(!ioctl(fileno(stdin),FIONREAD,&check)) + if(check) + { + char buf[1024]; + char *f; + fgets(buf,1024,stdin); + if((f=strrchr(buf,'\n'))) + *f=0; + FCEUI_NetplayText(buf); + } + send(Socket, data, len ,0); + return(1); +} + +int FCEUD_RecvData(void *data, uint32 len) +{ + NoWaiting&=~2; + + for(;;) + { + fd_set funfun; + struct timeval popeye; + + popeye.tv_sec=0; + popeye.tv_usec=100000; + + FD_ZERO(&funfun); + FD_SET(Socket,&funfun); + + switch(select(Socket + 1,&funfun,0,0,&popeye)) + { + case 0: continue; + case -1:return(0); + } + + if(FD_ISSET(Socket,&funfun)) + { + if(recv(Socket,data,len,MSG_WAITALL) == len) + { + //unsigned long beefie; + + FD_ZERO(&funfun); + FD_SET(Socket, &funfun); + + popeye.tv_sec = popeye.tv_usec = 0; + if(select(Socket + 1, &funfun, 0, 0, &popeye) == 1) + //if(!ioctl(Socket,FIONREAD,&beefie)) + // if(beefie) + { + NoWaiting|=2; + //puts("Yaya"); + } + return(1); + } + else + return(0); + } + + } + return 0; +} + +void FCEUD_NetworkClose(void) +{ + if(Socket>0) + { + #ifdef BEOS + closesocket(Socket); + #else + close(Socket); + #endif + } + Socket=-1; + + if(FCEUDnetplay) + FCEUI_NetplayStop(); + FCEUDnetplay = 0; +} + + +void FCEUD_NetplayText(uint8 *text) +{ + char *tot = malloc(strlen(text) + 1); + char *tmp; + strcpy(tot, text); + tmp = tot; + + while(*tmp) + { + if(*tmp < 0x20) *tmp = ' '; + tmp++; + } + puts(tot); + free(tot); +} +#endif + diff --git a/branches/fceux-2.2.2/src/attic/pc/unix-netplay.h b/branches/fceux-2.2.2/src/attic/pc/unix-netplay.h new file mode 100644 index 00000000..dd6ed18a --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/unix-netplay.h @@ -0,0 +1,9 @@ +#ifdef NETWORK +extern char *netplaynick; +extern char *netplayhost; +extern char *netpassword; +extern char *netgamekey; +extern int tport; +extern int netlocalplayers; + +#endif diff --git a/branches/fceux-2.2.2/src/attic/pc/usage.h b/branches/fceux-2.2.2/src/attic/pc/usage.h new file mode 100644 index 00000000..b8833200 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/usage.h @@ -0,0 +1,60 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +void ShowUsage(char *prog) +{ +printf("\nUsage is as follows:\n%s filename\n\n",prog); +puts("Options:"); +puts(DriverUsage); +puts("-cpalette x Load a custom global palette from file x.\n\ +-ntsccol x Emulate an NTSC's TV's colors.\n\ + 0 = Disabled.\n\ + 1 = Enabled.\n\ +-pal x Emulate a PAL NES if x is 1.\n\ +-sound x Sound.\n\ + 0 = Disabled.\n\ + Otherwise, x = playback rate.\n\ +-soundvol x Sound volume. x is an integral percentage value.\n\ +-soundq x Sets sound quality.\n\ + 0 = Low quality.\n\ + 1 = High quality.\n\ +-inputx str Select device mapped to virtual input port x(1-2).\n\ + str may be: none, gamepad, zapper, powerpada, powerpadb,\n\ + arkanoid\n\ +-fcexp str Select Famicom expansion port device.\n\ + str may be: none, shadow, arkanoid, 4player, fkb\n\ +-inputcfg s Configure virtual input device \"s\".\n\ +-nofs x Disables Four-Score emulation if x is 1.\n\ +-gg x Enable Game Genie emulation if x is 1.\n\ +-no8lim x Disables the 8 sprites per scanline limitation.\n\ + 0 = Limitation enabled.\n\ + 1 = Limitation disabled.\n\ +-snapname x Selects what type of file name snapshots will have.\n\ + 0 = Numeric(0.png)\n\ + 1 = File base and numeric(mario-0.png)\n\ +-nothrottle x Disable artificial speed throttling if x is non-zero.\n\ +-clipsides x Clip leftmost and rightmost 8 columns of pixels of video output.\n\ + 0 = No clipping.\n\ + 1 = Clipping.\n\ +-slstart x Set the first drawn emulated scanline. Valid values for x are\n\ + 0 through 239.\n\ +-slend x Set the last drawn emulated scanline. Valid values for x are\n\ + 0 through 239."); +} diff --git a/branches/fceux-2.2.2/src/attic/pc/vgatweak.c b/branches/fceux-2.2.2/src/attic/pc/vgatweak.c new file mode 100644 index 00000000..a04cf94e --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/pc/vgatweak.c @@ -0,0 +1,168 @@ +/* This file is "#include"d from dos-video.c and svga-video.c */ + +typedef struct { + uint8 p; + uint8 i; + uint8 v; +} vgareg; + +vgareg v256x224_103[25] = +{ + { 0xc2, 0x0, 0xe7}, + { 0xd4, 0x0, 0x45}, + { 0xd4, 0x1, 0x3f}, + { 0xd4, 0x2, 0x40}, + { 0xd4, 0x3, 0x86}, + { 0xd4, 0x4, 0x3f}, + { 0xd4, 0x5, 0x10}, + { 0xd4, 0x6, 0xcd}, + { 0xd4, 0x7, 0x1f}, + { 0xd4, 0x8, 0x0}, + { 0xd4, 0x9, 0x41}, + { 0xd4, 0x10, 0xc0}, + { 0xd4, 0x11, 0xac}, + { 0xd4, 0x12, 0xbf}, + { 0xd4, 0x13, 0x20}, + { 0xd4, 0x14, 0x40}, // + { 0xd4, 0x15, 0xe7}, + { 0xd4, 0x16, 0x06}, // + { 0xd4, 0x17, 0xa3}, + { 0xc4, 0x1, 0x1}, + { 0xc4, 0x4, 0xe}, // + { 0xce, 0x5, 0x40}, + { 0xce, 0x6, 0x5}, + { 0xc0, 0x10, 0x41}, + { 0xc0, 0x13, 0x0}, +}; + +vgareg v256x240[25] = +{ + { 0xc2, 0x0, 0xe3}, + { 0xd4, 0x0, 0x4f}, + { 0xd4, 0x1, 0x3f}, + { 0xd4, 0x2, 0x40}, + { 0xd4, 0x3, 0x92}, + { 0xd4, 0x4, 0x44}, + { 0xd4, 0x5, 0x10}, + { 0xd4, 0x6, 0x0a}, + { 0xd4, 0x7, 0x3e}, + { 0xd4, 0x8, 0x00}, + { 0xd4, 0x9, 0x41}, + { 0xd4, 0x10, 0xea}, + { 0xd4, 0x11, 0xac}, + { 0xd4, 0x12, 0xdf}, + { 0xd4, 0x13, 0x20}, + { 0xd4, 0x14, 0x40}, + { 0xd4, 0x15, 0xe7}, + { 0xd4, 0x16, 0x06}, + { 0xd4, 0x17, 0xa3}, + { 0xc4, 0x1, 0x1}, + { 0xc4, 0x4, 0xe}, + { 0xce, 0x5, 0x40}, + { 0xce, 0x6, 0x5}, + { 0xc0, 0x10, 0x41}, + { 0xc0, 0x13, 0x0} +}; + +vgareg v256x224S[25] = +{ + { 0xc2, 0x0, 0xe3}, + { 0xd4, 0x0, 0x5f}, + { 0xd4, 0x1, 0x3f}, + { 0xd4, 0x2, 0x40}, + { 0xd4, 0x3, 0x82}, + { 0xd4, 0x4, 0x4e}, + { 0xd4, 0x5, 0x96}, + { 0xd4, 0x6, 0x5}, + { 0xd4, 0x7, 0x1}, + { 0xd4, 0x8, 0x0}, + { 0xd4, 0x9, 0x40}, + { 0xd4, 0x10, 0xea}, + { 0xd4, 0x11, 0xac}, + { 0xd4, 0x12, 0xdf}, + { 0xd4, 0x13, 0x20}, + { 0xd4, 0x14, 0x40}, + { 0xd4, 0x15, 0xe7}, + { 0xd4, 0x16, 0x0}, + { 0xd4, 0x17, 0xe3}, + { 0xc4, 0x1, 0x1}, + { 0xc4, 0x4, 0xe}, + { 0xce, 0x5, 0x40}, + { 0xce, 0x6, 0x5}, + { 0xc0, 0x10, 0x41}, + { 0xc0, 0x13, 0x0} +}; + +vgareg v256x256[25] = +{ + { 0xc2, 0x0, 0xe7}, + { 0xd4, 0x0, 0x5f}, + { 0xd4, 0x1, 0x3f}, + { 0xd4, 0x2, 0x40}, + { 0xd4, 0x3, 0x82}, + { 0xd4, 0x4, 0x4a}, + { 0xd4, 0x5, 0x9a}, + { 0xd4, 0x6, 0x23}, + { 0xd4, 0x7, 0xb2}, + { 0xd4, 0x8, 0x0}, + { 0xd4, 0x9, 0x61}, + { 0xd4, 0x10, 0xa}, + { 0xd4, 0x11, 0xac}, + { 0xd4, 0x12, 0xff}, + { 0xd4, 0x13, 0x20}, + { 0xd4, 0x14, 0x40}, + { 0xd4, 0x15, 0x7}, + { 0xd4, 0x16, 0x1a}, + { 0xd4, 0x17, 0xa3}, + { 0xc4, 0x1, 0x1}, + { 0xc4, 0x4, 0xe}, + { 0xce, 0x5, 0x40}, + { 0xce, 0x6, 0x5}, + { 0xc0, 0x10, 0x41}, + { 0xc0, 0x13, 0x0} +}; + +vgareg v256x256S[25] = +{ + { 0xc2, 0x00, 0xe7},{ 0xd4, 0x00, 0x5F},{ 0xd4, 0x01, 0x3f}, + { 0xd4, 0x02, 0x40},{ 0xd4, 0x03, 0x82},{ 0xd4, 0x04, 0x4a}, + { 0xd4, 0x05, 0x9a},{ 0xd4, 0x06, 0x25},{ 0xd4, 0x07, 0x15}, + { 0xd4, 0x08, 0x00},{ 0xd4, 0x09, 0x60},{ 0xd4, 0x10, 0x0a}, + { 0xd4, 0x11, 0xac},{ 0xd4, 0x12, 0xff},{ 0xd4, 0x13, 0x20}, + { 0xd4, 0x14, 0x40},{ 0xd4, 0x15, 0x07},{ 0xd4, 0x16, 0x1a}, + { 0xd4, 0x17, 0xa3},{ 0xc4, 0x01, 0x01},{ 0xc4, 0x04, 0x0e}, + { 0xce, 0x05, 0x40},{ 0xce, 0x06, 0x05},{ 0xc0, 0x10, 0x41}, + { 0xc0, 0x13, 0x00} +}; + +static void VGAPortSet(vgareg R) +{ + int p,i,v; + + p=0x300|R.p; + i=R.i; + v=R.v; + + switch(p) + { + case 0x3C0: inportb(0x3DA); + outportb(0x3C0,i); + outportb(0x3C0,v); + break; + case 0x3C2: + case 0x3C3: + default: outportb(p, v); + break; + case 0x3C4: if(i==1) + { + outportw(0x3c4,0x100); + outportw(0x3c4,(v<<8)|1); + outportw(0x3c4,0x300); + break; + } + case 0x3CE: + case 0x3D4: outportw(p,i|(v<<8)); + break; + } +} + diff --git a/branches/fceux-2.2.2/src/attic/sexyal/convert.c b/branches/fceux-2.2.2/src/attic/sexyal/convert.c new file mode 100644 index 00000000..8fc4d626 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/convert.c @@ -0,0 +1,14 @@ +#include "sexyal.h" +#include "convert.h" + +static inline uint16_t FLIP16(uint16_t b) +{ + return((b<<8)|((b>>8)&0xFF)); +} + +static inline uint32_t FLIP32(uint32_t b) +{ + return( (b<<24) | ((b>>8)&0xFF00) | ((b<<8)&0xFF0000) | ((b>>24)&0xFF) ); +} + +#include "convert.inc" diff --git a/branches/fceux-2.2.2/src/attic/sexyal/convert.h b/branches/fceux-2.2.2/src/attic/sexyal/convert.h new file mode 100644 index 00000000..ac364bb3 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/convert.h @@ -0,0 +1,2 @@ +void SexiALI_Convert(SexyAL_format *srcformat, SexyAL_format *destformat, void *vdest, void *vsrc, uint32_t frames); + diff --git a/branches/fceux-2.2.2/src/attic/sexyal/convert.inc b/branches/fceux-2.2.2/src/attic/sexyal/convert.inc new file mode 100644 index 00000000..2c895bf1 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/convert.inc @@ -0,0 +1,20387 @@ +void SexiALI_Convert(SexyAL_format *srcformat, SexyAL_format *destformat, void *vdest, void *vsrc, uint32_t frames) +{ +if(srcformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp2+=128; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp2+=128; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp2+=128; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp2+=128; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp2+=128; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp2+=128; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp2+=128; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp2+=128; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 8; + tmp2+=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=128; + tmp <<= 16; + tmp2+=128; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +if(srcformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp2-=128; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp2-=128; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp2-=128; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp2-=128; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp2-=128; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp2-=128; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp2-=128; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp2-=128; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 8; + tmp2-=128; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=128; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=128; + tmp <<= 16; + tmp2-=128; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 16; + tmp2 <<= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +if(srcformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp2+=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp2+=32768; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp2+=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp2+=32768; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp+=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +if(srcformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp >>= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp2-=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp2-=32768; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp2-=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp2-=32768; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 0; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp-=32768; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP16(tmp); + tmp <<= 8; +FLIP16(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP16(tmp); +tmp2=*src; + src++; +FLIP16(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP16(tmp); +FLIP16(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +if(srcformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp >>= 8; + tmp2+=32768; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 0; + tmp2+=32768; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp2+=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp2+=32768; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp2+=32768; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp2+=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp2+=32768; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=32768; + tmp <<= 8; + tmp2+=32768; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +if(srcformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp >>= 8; + tmp2-=32768; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 0; + tmp2-=32768; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 0; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 0; + tmp2 <<= 0; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp2-=32768; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp2-=32768; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp2-=32768; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp2-=32768; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp2-=32768; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=32768; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=32768; + tmp <<= 8; + tmp2-=32768; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp <<= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp <<= 8; + tmp2 <<= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +if(srcformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 16; + tmp2+=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp >>= 8; + tmp2+=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp+=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp+=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp2+=(1<<23); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp2+=(1<<23); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp2+=(1<<23); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp2+=(1<<23); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp2+=(1<<23); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp+=(1<<23); + tmp2+=(1<<23); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp2+=(1<<23); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp+=(1<<23); + tmp2+=(1<<23); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +if(srcformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* src=vsrc; +if(destformat->sampformat == SEXYAL_FMT_PCMS8) +{ +int8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 16; + tmp2-=(1<<23); + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU8) +{ +uint8_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 16; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 16; + tmp2 >>= 16; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS16) +{ +int16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU16) +{ +uint16_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S16) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp >>= 8; + tmp2-=(1<<23); + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U16) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp >>= 8; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp >>= 8; + tmp2 >>= 8; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMS32S24) +{ +int32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + tmp-=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + tmp-=(1<<23); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp2-=(1<<23); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp2-=(1<<23); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp2-=(1<<23); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp2-=(1<<23); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp2-=(1<<23); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + tmp-=(1<<23); + tmp2-=(1<<23); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp2-=(1<<23); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + tmp-=(1<<23); + tmp2-=(1<<23); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +if(destformat->sampformat == SEXYAL_FMT_PCMU32U24) +{ +uint32_t* dest=vdest; +if(srcformat->channels == 1) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +tmp=*src; + src++; +FLIP32(tmp); +FLIP32(tmp); + *dest=tmp; + dest++; + *dest=tmp; + dest++; +} +} +} +} +} +if(srcformat->channels == 2) +{ +if(destformat->channels == 1) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +tmp = (tmp+tmp2)>>1; + *dest=tmp; + dest++; +} +} +} +} +if(destformat->channels == 2) +{ +if(srcformat->byteorder == 0) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +tmp2=*src; + src++; +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +if(srcformat->byteorder == 1) +{ +if(destformat->byteorder == 0) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +if(destformat->byteorder == 1) +{ +while(frames--) +{ +int32_t tmp; +int32_t tmp2; +tmp=*src; + src++; +FLIP32(tmp); +tmp2=*src; + src++; +FLIP32(tmp2); +FLIP32(tmp); +FLIP32(tmp2); + *dest=tmp; + dest++; + *dest=tmp2; + dest++; +} +} +} +} +} +} +} +} diff --git a/branches/fceux-2.2.2/src/attic/sexyal/convertgen b/branches/fceux-2.2.2/src/attic/sexyal/convertgen new file mode 100644 index 00000000..d4420fda Binary files /dev/null and b/branches/fceux-2.2.2/src/attic/sexyal/convertgen differ diff --git a/branches/fceux-2.2.2/src/attic/sexyal/convertgen.c b/branches/fceux-2.2.2/src/attic/sexyal/convertgen.c new file mode 100644 index 00000000..83e59083 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/convertgen.c @@ -0,0 +1,155 @@ +#include + +char *check[]={"SEXYAL_FMT_PCMS8","SEXYAL_FMT_PCMU8","SEXYAL_FMT_PCMS16", +"SEXYAL_FMT_PCMU16","SEXYAL_FMT_PCMS32S16","SEXYAL_FMT_PCMU32U16","SEXYAL_FMT_PCMS32S24","SEXYAL_FMT_PCMU32U24"}; +char *str[]={"int8_t","uint8_t","int16_t","uint16_t","int32_t","uint32_t","int32_t","uint32_t"}; + +int bitss[]={8,8,16,16,16,16,24,24}; +int bitsreal[]={8,8,16,16,32,32,32,32}; + +void Fetch(int x,char *wt) +{ + //printf(" int32_t tmp%s=*src;\n",wt); + printf("tmp%s=*src;\n",wt); + printf(" src++;\n"); +} + +void BitConv(int src, int dest, char *wt) +{ + if((src^dest)&1) /* signed/unsigned change. */ + if(src&1) /* Source unsigned, dest signed. */ + { + if(src==1) printf(" tmp%s-=128;\n",wt); + else if(src==3) printf(" tmp%s-=32768;\n",wt); + else if(src==5) printf(" tmp%s-=32768;\n",wt); + else if(src==7) printf(" tmp%s-=(1<<23);\n",wt); + } + else /* Source signed, dest unsigned */ + { + if(src==0) printf(" tmp%s+=128;\n",wt); + else if(src==2) printf(" tmp%s+=32768;\n",wt); + else if(src==4) printf(" tmp%s+=32768;\n",wt); + else if(src==6) printf(" tmp%s+=(1<<23);\n",wt); + } + if((src>>1) != (dest>>1)) + { + int shifty=bitss[src]-bitss[dest]; + if(shifty>0) + printf(" tmp%s >>= %d;\n",wt,shifty); + else + printf(" tmp%s <<= %d;\n",wt,-shifty); + } +} + +void Save(int x, char *wt) +{ + printf(" *dest=tmp%s;\n",wt); + printf(" dest++;\n"); +} + +main() +{ + int srcbits,destbits,srcchannels,destchannels; + int srcbo,destbo; + + puts("void SexiALI_Convert(SexyAL_format *srcformat, SexyAL_format *destformat, void *vdest, void *vsrc, uint32_t frames)"); + puts("{"); + + for(srcbits=0;srcbits<8;srcbits++) + { + printf("if(srcformat->sampformat == %s)\n{\n",check[srcbits]); + + printf("%s* src=vsrc;\n",str[srcbits]); + + for(destbits=0;destbits<8;destbits++) + { + printf("if(destformat->sampformat == %s)\n{\n",check[destbits]); + + printf("%s* dest=vdest;\n",str[destbits]); + + for(srcchannels=0;srcchannels<2;srcchannels++) + { + printf("if(srcformat->channels == %c)\n{\n",'1'+srcchannels); + for(destchannels=0;destchannels<2;destchannels++) + { + printf("if(destformat->channels == %c)\n{\n",'1'+destchannels); + for(srcbo=0;srcbo<2;srcbo++) + { + printf("if(srcformat->byteorder == %d)\n{\n",srcbo); + for(destbo=0;destbo<2;destbo++) + { + printf("if(destformat->byteorder == %d)\n{\n",destbo); + //printf("if(srcformat->sampformat==%s && destformat->sameck[srcbits],check[destbits]); + printf("while(frames--)\n{\n"); + + puts("int32_t tmp;"); + if(srcchannels) + puts("int32_t tmp2;"); + + Fetch(srcbits,""); + + if(srcbo) + { + if(bitsreal[srcbits]==16) + puts("FLIP16(tmp);"); + else + puts("FLIP32(tmp);"); + } + + if(srcchannels) + { + Fetch(srcbits,"2"); + if(srcbo) + { + if(bitsreal[srcbits]==16) + puts("FLIP16(tmp2);"); + else + puts("FLIP32(tmp2);"); + } + } + + BitConv(srcbits,destbits,""); + + if(srcchannels) BitConv(srcbits,destbits,"2"); + + if(destbo) + { + if(bitsreal[srcbits]==16) + puts("FLIP16(tmp);"); + else + puts("FLIP32(tmp);"); + if(srcchannels && destchannels && destbo) + { + if(bitsreal[srcbits]==16) + puts("FLIP16(tmp2);"); + else + puts("FLIP32(tmp2);"); + } + } + + if(srcchannels && !destchannels) + printf("tmp = (tmp+tmp2)>>1;\n"); + + Save(destbits,""); + if(!srcchannels && destchannels) + Save(destbits,""); + + if(srcchannels && destchannels) + Save(destbits,"2"); + + puts("}"); + puts("}"); + } // destbo + puts("}"); + } // srcbo + puts("}"); + } + puts("}"); + } + puts("}"); + } + puts("}"); + } + + puts("}"); +} diff --git a/branches/fceux-2.2.2/src/attic/sexyal/drivers/dsound.c b/branches/fceux-2.2.2/src/attic/sexyal/drivers/dsound.c new file mode 100644 index 00000000..b6569ce6 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/drivers/dsound.c @@ -0,0 +1,276 @@ +#include +#include +#include + +#undef WINNT +#define NONAMELESSUNION + +#define DIRECTSOUND_VERSION 0x0300 + +#include +#include "../sexyal.h" + +typedef struct +{ + LPDIRECTSOUND ppDS; /* DirectSound interface object. */ + LPDIRECTSOUNDBUFFER ppbuf; /* Primary buffer. */ + LPDIRECTSOUNDBUFFER ppbufsec; /* Secondary buffer. */ + LPDIRECTSOUNDBUFFER ppbufw; /* Buffer to do writes to. */ + WAVEFORMATEX wf; /* Format of the primary and secondary buffers. */ + long DSBufferSize; /* The size of the buffer that we can write to, in bytes. */ + + long BufHowMuch; /* How many bytes we should try to buffer. */ + DWORD ToWritePos; /* Position which the next write to the buffer + should write to. + */ +} DSFobby; + +static void CheckStatus(DSFobby *tmp) +{ + DWORD status=0; + + IDirectSoundBuffer_GetStatus(tmp->ppbufw, &status); + if(status&DSBSTATUS_BUFFERLOST) + IDirectSoundBuffer_Restore(tmp->ppbufw); + + if(!(status&DSBSTATUS_PLAYING)) + { + tmp->ToWritePos=0; + IDirectSoundBuffer_SetCurrentPosition(tmp->ppbufsec,0); + IDirectSoundBuffer_SetFormat(tmp->ppbufw,&tmp->wf); + IDirectSoundBuffer_Play(tmp->ppbufw,0,0,DSBPLAY_LOOPING); + } +} + +SexyAL_device *SexyALI_DSound_Open(uint64_t id, SexyAL_format *format, SexyAL_buffering *buffering) +{ + SexyAL_device *dev; + DSFobby *fobby; + + DSBUFFERDESC DSBufferDesc; + DSCAPS dscaps; + DSBCAPS dsbcaps; + + dev=malloc(sizeof(SexyAL_device)); + fobby=malloc(sizeof(DSFobby)); + memset(fobby,0,sizeof(DSFobby)); + + memset(&fobby->wf,0,sizeof(WAVEFORMATEX)); + fobby->wf.wFormatTag = WAVE_FORMAT_PCM; + fobby->wf.nChannels = format->channels; + fobby->wf.nSamplesPerSec = format->rate; + + if(DirectSoundCreate(0,&fobby->ppDS,0) != DS_OK) + { + free(dev); + free(fobby); + return(0); + } + + { + //HWND hWnd = GetForegroundWindow(); // Ugly. + //if(!hWnd) + //{ hWnd=GetDesktopWindow(); exit(1); } + HWND hWnd; + hWnd=GetDesktopWindow(); + IDirectSound_SetCooperativeLevel(fobby->ppDS,hWnd,DSSCL_PRIORITY); + } + memset(&dscaps,0x00,sizeof(dscaps)); + dscaps.dwSize=sizeof(dscaps); + IDirectSound_GetCaps(fobby->ppDS,&dscaps); + IDirectSound_Compact(fobby->ppDS); + + /* Create primary buffer */ + memset(&DSBufferDesc,0x00,sizeof(DSBUFFERDESC)); + DSBufferDesc.dwSize=sizeof(DSBufferDesc); + DSBufferDesc.dwFlags=DSBCAPS_PRIMARYBUFFER; + + if(IDirectSound_CreateSoundBuffer(fobby->ppDS,&DSBufferDesc,&fobby->ppbuf,0) != DS_OK) + { + IDirectSound_Release(fobby->ppDS); + free(dev); + free(fobby); + return(0); + } + + /* Set primary buffer format. */ + if(format->sampformat == SEXYAL_FMT_PCMU8) + fobby->wf.wBitsPerSample=8; + else // if(format->sampformat == SEXYAL_FMT_PCMS16) + { + fobby->wf.wBitsPerSample=16; + format->sampformat=SEXYAL_FMT_PCMS16; + } + + fobby->wf.nBlockAlign=fobby->wf.wBitsPerSample>>3; + fobby->wf.nAvgBytesPerSec=fobby->wf.nSamplesPerSec*fobby->wf.nBlockAlign; + if(IDirectSoundBuffer_SetFormat(fobby->ppbuf,&fobby->wf) != DS_OK) + { + IDirectSound_Release(fobby->ppbuf); + IDirectSound_Release(fobby->ppDS); + free(dev); + free(fobby); + return(0); + } + + /* Create secondary sound buffer */ + IDirectSoundBuffer_GetFormat(fobby->ppbuf,&fobby->wf,sizeof(WAVEFORMATEX),0); + memset(&DSBufferDesc,0x00,sizeof(DSBUFFERDESC)); + DSBufferDesc.dwSize=sizeof(DSBufferDesc); + DSBufferDesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; + DSBufferDesc.dwFlags|=DSBCAPS_GLOBALFOCUS; + DSBufferDesc.dwBufferBytes=65536; + DSBufferDesc.lpwfxFormat=&fobby->wf; + if(IDirectSound_CreateSoundBuffer(fobby->ppDS, &DSBufferDesc, &fobby->ppbufsec, 0) != DS_OK) + { + IDirectSound_Release(fobby->ppbuf); + IDirectSound_Release(fobby->ppDS); + free(dev); + free(fobby); + return(0); + } + + fobby->DSBufferSize=65536; + IDirectSoundBuffer_SetCurrentPosition(fobby->ppbufsec,0); + fobby->ppbufw=fobby->ppbufsec; + + memcpy(&dev->format,format,sizeof(SexyAL_format)); + + if(!buffering->ms) + buffering->ms=53; + + buffering->totalsize=(int64_t)format->rate*buffering->ms/1000; + fobby->BufHowMuch=buffering->totalsize* format->channels * (format->sampformat>>4); + //printf("%d\n",fobby->BufHowMuch); + //fflush(stdout); + + dev->private=fobby; + timeBeginPeriod(1); + + return(dev); +} + +uint32_t SexyALI_DSound_RawCanWrite(SexyAL_device *device) +{ + DSFobby *tmp=device->private; + DWORD CurWritePos,CurPlayPos=0; + CheckStatus(tmp); + + CurWritePos=0; + + if(IDirectSoundBuffer_GetCurrentPosition(tmp->ppbufw,&CurPlayPos,&CurWritePos)==DS_OK) + { + //FCEU_DispMessage("%d",CurWritePos-CurPlayPos); + } + CurWritePos=(CurPlayPos+tmp->BufHowMuch)%tmp->DSBufferSize; + + /* If the current write pos is >= half the buffer size less than the to write pos, + assume DirectSound has wrapped around. + */ + + if(((int32_t)tmp->ToWritePos-(int32_t)CurWritePos) >= (tmp->DSBufferSize/2)) + { + CurWritePos+=tmp->DSBufferSize; + //printf("Fixit: %d,%d,%d\n",tmp->ToWritePos,CurWritePos,CurWritePos-tmp->DSBufferSize); + } + if(tmp->ToWritePosToWritePos; + if(howmuch > tmp->BufHowMuch) /* Oopsie. Severe buffer overflow... */ + { + tmp->ToWritePos=CurWritePos%tmp->DSBufferSize; + //IDirectSoundBuffer_Stop(tmp->ppbufsec); + //IDirectSoundBuffer_SetCurrentPosition(tmp->ppbufsec,tmp->ToWritePos); + //puts("Oops"); + //fflush(stdout); + //return(0); + } + return(CurWritePos-tmp->ToWritePos); + } + else + return(0); +} + +int SexyALI_DSound_RawWrite(SexyAL_device *device, void *data, uint32_t len) +{ + DSFobby *tmp=device->private; +// uint32_t cw; + + //printf("Pre: %d\n",SexyALI_DSound_RawCanWrite(device)); + //fflush(stdout); + + CheckStatus(tmp); + /* In this block, we write as much data as we can, then we write + the rest of it in >=1ms chunks. + */ + while(len) + { + VOID *LockPtr[2]={0,0}; + DWORD LockLen[2]={0,0}; + int32_t curlen; + + while(!(curlen=SexyALI_DSound_RawCanWrite(device))) + { + Sleep(1); + } + + if(curlen>len) curlen=len; + + if(DS_OK == IDirectSoundBuffer_Lock(tmp->ppbufw,tmp->ToWritePos,curlen,&LockPtr[0],&LockLen[0],&LockPtr[1],&LockLen[1],0)) + { + } + + if(LockPtr[1] != 0 && LockPtr[1] != LockPtr[0]) + { + memcpy(LockPtr[0],data,LockLen[0]); + memcpy(LockPtr[1],data+LockLen[0],len-LockLen[0]); + } + else if(LockPtr[0]) + { + memcpy(LockPtr[0],data,curlen); + } + IDirectSoundBuffer_Unlock(tmp->ppbufw,LockPtr[0],LockLen[0],LockPtr[1],LockLen[1]); + tmp->ToWritePos=(tmp->ToWritePos+curlen)%tmp->DSBufferSize; + + len-=curlen; + (uint8_t *) data+=curlen; + if(len) + Sleep(1); + } // end while(len) loop + + + return(1); +} + + + +int SexyALI_DSound_Close(SexyAL_device *device) +{ + if(device) + { + if(device->private) + { + DSFobby *tmp=device->private; + if(tmp->ppbufsec) + { + IDirectSoundBuffer_Stop(tmp->ppbufsec); + IDirectSoundBuffer_Release(tmp->ppbufsec); + } + if(tmp->ppbuf) + { + IDirectSoundBuffer_Stop(tmp->ppbuf); + IDirectSoundBuffer_Release(tmp->ppbuf); + } + if(tmp->ppDS) + { + IDirectSound_Release(tmp->ppDS); + } + free(device->private); + } + free(device); + timeEndPeriod(1); + return(1); + } + return(0); +} + diff --git a/branches/fceux-2.2.2/src/attic/sexyal/drivers/oss.c b/branches/fceux-2.2.2/src/attic/sexyal/drivers/oss.c new file mode 100644 index 00000000..68d9a8c8 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/drivers/oss.c @@ -0,0 +1,241 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../sexyal.h" +#include "../md5.h" +#include "../smallc.h" + +#include "oss.h" + +#define IDBASE 0x1000 + +void SexyALI_OSS_Enumerate(int (*func)(uint8_t *name, uint64_t id, void *udata), void *udata) +{ + struct stat buf; + char fn[64]; + unsigned int n; + + n=0; + + do + { + sal_strcpy(fn,"/dev/dsp"); + sal_strcat(fn,sal_uinttos(n)); + if(stat(fn,&buf)!=0) break; + } while(func(fn,n+IDBASE,udata)); +} + +static int FODevice(uint64_t id) +{ + char fn[64]; + + if(id==SEXYAL_ID_DEFAULT) + { + sal_strcpy(fn,"/dev/dsp"); + return(open(fn,O_WRONLY)); + } + else if(id==SEXYAL_ID_UNUSED) + { + int x=-1; + int dspfd; + do + { + sal_strcpy(fn,"/dev/dsp"); + if(x!=-1) + sal_strcat(fn,sal_uinttos(x)); + dspfd=open(fn,O_WRONLY|O_NONBLOCK); + if(dspfd!=-1) break; + x++; + } while(errno!=ENOENT); + if(dspfd==-1) return(0); + fcntl(dspfd,F_SETFL,fcntl(dspfd,F_GETFL)&~O_NONBLOCK); + return(dspfd); + } + else + { + sal_strcpy(fn,"/dev/dsp"); + sal_strcat(fn,sal_uinttos(id-IDBASE)); + return(open(fn,O_WRONLY)); + } +} + +unsigned int Log2(unsigned int value) +{ + int x=0; + + value>>=1; + while(value) + { + value>>=1; + x++; + } + return(x?x:1); +} + +SexyAL_device *SexyALI_OSS_Open(uint64_t id, SexyAL_format *format, SexyAL_buffering *buffering) +{ + SexyAL_device *device; + int fd; + unsigned int temp; + + if(!(fd=FODevice(id))) return(0); + + /* Set sample format. */ + /* TODO: Handle devices with byte order different from native byte order. */ + /* TODO: Fix fragment size calculation to work well with lower/higher playback rates, + as reported by OSS. + */ + + if(format->sampformat == SEXYAL_FMT_PCMU8) + temp=AFMT_U8; + else if(format->sampformat == SEXYAL_FMT_PCMS8) + temp=AFMT_S8; + else if(format->sampformat == SEXYAL_FMT_PCMU16) + temp=AFMT_U16_LE; + else + temp=AFMT_S16_NE; + + format->byteorder=0; + + ioctl(fd,SNDCTL_DSP_SETFMT,&temp); + switch(temp) + { + case AFMT_U8: format->sampformat = SEXYAL_FMT_PCMU8;break; + case AFMT_S8: format->sampformat = SEXYAL_FMT_PCMS8;break; + case AFMT_U16_LE: + #ifndef LSB_FIRST + format->byteorder=1; + #endif + format->sampformat = SEXYAL_FMT_PCMU16;break; + case AFMT_U16_BE: + #ifdef LSB_FIRST + format->byteorder=1; + #endif + format->sampformat = SEXYAL_FMT_PCMU16;break; + case AFMT_S16_LE: + #ifndef LSB_FIRST + format->byteorder=1; + #endif + format->sampformat = SEXYAL_FMT_PCMS16;break; + case AFMT_S16_BE: + #ifdef LSB_FIRST + format->byteorder=1; + #endif + format->sampformat = SEXYAL_FMT_PCMS16;break; + default: close(fd); return(0); + } + + /* Set number of channels. */ + temp=format->channels; + if(ioctl(fd,SNDCTL_DSP_CHANNELS,&temp)==-1) + { + close(fd); + return(0); + } + + if(temp<1 || temp>2) + { + close(fd); + return(0); + } + + format->channels=temp; + + /* Set frame rate. */ + temp=format->rate; + if(ioctl(fd,SNDCTL_DSP_SPEED,&temp)==-1) + { + close(fd); + return(0); + } + format->rate=temp; + device=malloc(sizeof(SexyAL_device)); + sal_memcpy(&device->format,format,sizeof(SexyAL_format)); + sal_memcpy(&device->buffering,buffering,sizeof(SexyAL_buffering)); + + if(buffering->fragcount == 0 || buffering->fragsize == 0) + { + buffering->fragcount=16; + buffering->fragsize=64; + } + else + { + if(buffering->fragsize<32) buffering->fragsize=32; + if(buffering->fragcount<2) buffering->fragcount=2; + } + + if(buffering->ms) + { + int64_t tc; + + //printf("%d\n",buffering->ms); + + /* 2*, >>1, |1 for crude rounding(it will always round 0.5 up, so it is a bit biased). */ + + tc=2*buffering->ms * format->rate / 1000 / buffering->fragsize; + //printf("%f\n",(double)buffering->ms * format->rate / 1000 / buffering->fragsize); + buffering->fragcount=(tc>>1)+(tc&1); //1<fragcount); + } + + temp=Log2(buffering->fragsize*(format->sampformat>>4)*format->channels); + temp|=buffering->fragcount<<16; + ioctl(fd,SNDCTL_DSP_SETFRAGMENT,&temp); + + { + audio_buf_info info; + ioctl(fd,SNDCTL_DSP_GETOSPACE,&info); + buffering->fragsize=info.fragsize/(format->sampformat>>4)/format->channels; + buffering->fragcount=info.fragments; + buffering->totalsize=buffering->fragsize*buffering->fragcount; + //printf("Actual: %d, %d\n",buffering->fragsize,buffering->fragcount); + } + device->private=malloc(sizeof(int)); + *(int*)device->private=fd; + return(device); +} + +int SexyALI_OSS_Close(SexyAL_device *device) +{ + if(device) + { + if(device->private) + { + close(*(int*)device->private); + free(device->private); + } + free(device); + return(1); + } + return(0); +} + +uint32_t SexyALI_OSS_RawWrite(SexyAL_device *device, void *data, uint32_t len) +{ + ssize_t bytes; + + bytes = write(*(int *)device->private,data,len); + if(bytes <= 0) return(0); /* FIXME: What to do on -1? */ + return(bytes); +} + +uint32_t SexyALI_OSS_RawCanWrite(SexyAL_device *device) +{ + struct audio_buf_info ai; + if(!ioctl(*(int *)device->private,SNDCTL_DSP_GETOSPACE,&ai)) + return(ai.bytes); + else + return(0); +} + diff --git a/branches/fceux-2.2.2/src/attic/sexyal/drivers/oss.h b/branches/fceux-2.2.2/src/attic/sexyal/drivers/oss.h new file mode 100644 index 00000000..b6927508 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/drivers/oss.h @@ -0,0 +1,6 @@ +void SexyALI_OSS_Enumerate(int (*func)(uint8_t *name, uint64_t id, void *udata), void *udata); +SexyAL_device *SexyALI_OSS_Open(uint64_t id, SexyAL_format *format, SexyAL_buffering *buffering); +int SexyALI_OSS_Close(SexyAL_device *device); +uint32_t SexyALI_OSS_RawWrite(SexyAL_device *device, void *data, uint32_t len); +uint32_t SexyALI_OSS_RawCanWrite(SexyAL_device *device); + diff --git a/branches/fceux-2.2.2/src/attic/sexyal/drivers/osxcoreaudio.c b/branches/fceux-2.2.2/src/attic/sexyal/drivers/osxcoreaudio.c new file mode 100644 index 00000000..b2c39a93 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/drivers/osxcoreaudio.c @@ -0,0 +1,5 @@ +#include +#include +#include + + diff --git a/branches/fceux-2.2.2/src/attic/sexyal/md5.c b/branches/fceux-2.2.2/src/attic/sexyal/md5.c new file mode 100644 index 00000000..50299f7f --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/md5.c @@ -0,0 +1,229 @@ +/* + * RFC 1321 compliant MD5 implementation, + * by Christophe Devine ; + * this program is licensed under the GPL. + */ + +/* Modified October 3, 2003, to remove testing code, and add + include of "types.h". + + -Xodnizel +*/ + +#include +#include "inttypes.h" +#include "md5.h" + +#define GET_UINT32(n,b,i) \ +{ \ + (n) = ( (uint32_t) (b)[(i) + 3] << 24 ) \ + | ( (uint32_t) (b)[(i) + 2] << 16 ) \ + | ( (uint32_t) (b)[(i) + 1] << 8 ) \ + | ( (uint32_t) (b)[(i) ] ); \ +} + +#define PUT_UINT32(n,b,i) \ +{ \ + (b)[(i) ] = (uint8_t) ( (n) ); \ + (b)[(i) + 1] = (uint8_t) ( (n) >> 8 ); \ + (b)[(i) + 2] = (uint8_t) ( (n) >> 16 ); \ + (b)[(i) + 3] = (uint8_t) ( (n) >> 24 ); \ +} + +void sal_md5_starts( struct sal_md5_context *ctx ) +{ + ctx->total[0] = 0; + ctx->total[1] = 0; + ctx->state[0] = 0x67452301; + ctx->state[1] = 0xEFCDAB89; + ctx->state[2] = 0x98BADCFE; + ctx->state[3] = 0x10325476; +} + +void sal_md5_process( struct sal_md5_context *ctx, uint8_t data[64] ) +{ + uint32_t A, B, C, D, X[16]; + + GET_UINT32( X[0], data, 0 ); + GET_UINT32( X[1], data, 4 ); + GET_UINT32( X[2], data, 8 ); + GET_UINT32( X[3], data, 12 ); + GET_UINT32( X[4], data, 16 ); + GET_UINT32( X[5], data, 20 ); + GET_UINT32( X[6], data, 24 ); + GET_UINT32( X[7], data, 28 ); + GET_UINT32( X[8], data, 32 ); + GET_UINT32( X[9], data, 36 ); + GET_UINT32( X[10], data, 40 ); + GET_UINT32( X[11], data, 44 ); + GET_UINT32( X[12], data, 48 ); + GET_UINT32( X[13], data, 52 ); + GET_UINT32( X[14], data, 56 ); + GET_UINT32( X[15], data, 60 ); + +#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) + +#define P(a,b,c,d,k,s,t) \ +{ \ + a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \ +} + + A = ctx->state[0]; + B = ctx->state[1]; + C = ctx->state[2]; + D = ctx->state[3]; + +#define F(x,y,z) (z ^ (x & (y ^ z))) + + P( A, B, C, D, 0, 7, 0xD76AA478 ); + P( D, A, B, C, 1, 12, 0xE8C7B756 ); + P( C, D, A, B, 2, 17, 0x242070DB ); + P( B, C, D, A, 3, 22, 0xC1BDCEEE ); + P( A, B, C, D, 4, 7, 0xF57C0FAF ); + P( D, A, B, C, 5, 12, 0x4787C62A ); + P( C, D, A, B, 6, 17, 0xA8304613 ); + P( B, C, D, A, 7, 22, 0xFD469501 ); + P( A, B, C, D, 8, 7, 0x698098D8 ); + P( D, A, B, C, 9, 12, 0x8B44F7AF ); + P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); + P( B, C, D, A, 11, 22, 0x895CD7BE ); + P( A, B, C, D, 12, 7, 0x6B901122 ); + P( D, A, B, C, 13, 12, 0xFD987193 ); + P( C, D, A, B, 14, 17, 0xA679438E ); + P( B, C, D, A, 15, 22, 0x49B40821 ); + +#undef F + +#define F(x,y,z) (y ^ (z & (x ^ y))) + + P( A, B, C, D, 1, 5, 0xF61E2562 ); + P( D, A, B, C, 6, 9, 0xC040B340 ); + P( C, D, A, B, 11, 14, 0x265E5A51 ); + P( B, C, D, A, 0, 20, 0xE9B6C7AA ); + P( A, B, C, D, 5, 5, 0xD62F105D ); + P( D, A, B, C, 10, 9, 0x02441453 ); + P( C, D, A, B, 15, 14, 0xD8A1E681 ); + P( B, C, D, A, 4, 20, 0xE7D3FBC8 ); + P( A, B, C, D, 9, 5, 0x21E1CDE6 ); + P( D, A, B, C, 14, 9, 0xC33707D6 ); + P( C, D, A, B, 3, 14, 0xF4D50D87 ); + P( B, C, D, A, 8, 20, 0x455A14ED ); + P( A, B, C, D, 13, 5, 0xA9E3E905 ); + P( D, A, B, C, 2, 9, 0xFCEFA3F8 ); + P( C, D, A, B, 7, 14, 0x676F02D9 ); + P( B, C, D, A, 12, 20, 0x8D2A4C8A ); + +#undef F + +#define F(x,y,z) (x ^ y ^ z) + + P( A, B, C, D, 5, 4, 0xFFFA3942 ); + P( D, A, B, C, 8, 11, 0x8771F681 ); + P( C, D, A, B, 11, 16, 0x6D9D6122 ); + P( B, C, D, A, 14, 23, 0xFDE5380C ); + P( A, B, C, D, 1, 4, 0xA4BEEA44 ); + P( D, A, B, C, 4, 11, 0x4BDECFA9 ); + P( C, D, A, B, 7, 16, 0xF6BB4B60 ); + P( B, C, D, A, 10, 23, 0xBEBFBC70 ); + P( A, B, C, D, 13, 4, 0x289B7EC6 ); + P( D, A, B, C, 0, 11, 0xEAA127FA ); + P( C, D, A, B, 3, 16, 0xD4EF3085 ); + P( B, C, D, A, 6, 23, 0x04881D05 ); + P( A, B, C, D, 9, 4, 0xD9D4D039 ); + P( D, A, B, C, 12, 11, 0xE6DB99E5 ); + P( C, D, A, B, 15, 16, 0x1FA27CF8 ); + P( B, C, D, A, 2, 23, 0xC4AC5665 ); + +#undef F + +#define F(x,y,z) (y ^ (x | ~z)) + + P( A, B, C, D, 0, 6, 0xF4292244 ); + P( D, A, B, C, 7, 10, 0x432AFF97 ); + P( C, D, A, B, 14, 15, 0xAB9423A7 ); + P( B, C, D, A, 5, 21, 0xFC93A039 ); + P( A, B, C, D, 12, 6, 0x655B59C3 ); + P( D, A, B, C, 3, 10, 0x8F0CCC92 ); + P( C, D, A, B, 10, 15, 0xFFEFF47D ); + P( B, C, D, A, 1, 21, 0x85845DD1 ); + P( A, B, C, D, 8, 6, 0x6FA87E4F ); + P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); + P( C, D, A, B, 6, 15, 0xA3014314 ); + P( B, C, D, A, 13, 21, 0x4E0811A1 ); + P( A, B, C, D, 4, 6, 0xF7537E82 ); + P( D, A, B, C, 11, 10, 0xBD3AF235 ); + P( C, D, A, B, 2, 15, 0x2AD7D2BB ); + P( B, C, D, A, 9, 21, 0xEB86D391 ); + +#undef F + + ctx->state[0] += A; + ctx->state[1] += B; + ctx->state[2] += C; + ctx->state[3] += D; +} + +void sal_md5_update( struct sal_md5_context *ctx, uint8_t *input, uint32_t length ) +{ + uint32_t left, fill; + + if( ! length ) return; + + left = ( ctx->total[0] >> 3 ) & 0x3F; + fill = 64 - left; + + ctx->total[0] += length << 3; + ctx->total[1] += length >> 29; + + ctx->total[0] &= 0xFFFFFFFF; + ctx->total[1] += ctx->total[0] < ( length << 3 ); + + if( left && length >= fill ) + { + memcpy( (void *) (ctx->buffer + left), (void *) input, fill ); + sal_md5_process( ctx, ctx->buffer ); + length -= fill; + input += fill; + left = 0; + } + + while( length >= 64 ) + { + sal_md5_process( ctx, input ); + length -= 64; + input += 64; + } + + if( length ) + { + memcpy( (void *) (ctx->buffer + left), (void *) input, length ); + } +} + +static uint8_t md5_padding[64] = +{ + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +void sal_md5_finish( struct sal_md5_context *ctx, uint8_t digest[16] ) +{ + uint32_t last, padn; + uint8_t msglen[8]; + + PUT_UINT32( ctx->total[0], msglen, 0 ); + PUT_UINT32( ctx->total[1], msglen, 4 ); + + last = ( ctx->total[0] >> 3 ) & 0x3F; + padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); + + sal_md5_update( ctx, md5_padding, padn ); + sal_md5_update( ctx, msglen, 8 ); + + PUT_UINT32( ctx->state[0], digest, 0 ); + PUT_UINT32( ctx->state[1], digest, 4 ); + PUT_UINT32( ctx->state[2], digest, 8 ); + PUT_UINT32( ctx->state[3], digest, 12 ); +} diff --git a/branches/fceux-2.2.2/src/attic/sexyal/md5.h b/branches/fceux-2.2.2/src/attic/sexyal/md5.h new file mode 100644 index 00000000..e06e356c --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/md5.h @@ -0,0 +1,15 @@ +#ifndef _MD5_H +#define _MD5_H + +struct sal_md5_context +{ + uint32_t total[2]; + uint32_t state[4]; + uint8_t buffer[64]; +}; + +void sal_md5_starts( struct sal_md5_context *ctx ); +void sal_md5_update( struct sal_md5_context *ctx, uint8_t *input, uint32_t length ); +void sal_md5_finish( struct sal_md5_context *ctx, uint8_t digest[16] ); + +#endif /* md5.h */ diff --git a/branches/fceux-2.2.2/src/attic/sexyal/sexyal.c b/branches/fceux-2.2.2/src/attic/sexyal/sexyal.c new file mode 100644 index 00000000..fc1594c3 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/sexyal.c @@ -0,0 +1,115 @@ +#include +#include +#include "sexyal.h" +#include "convert.h" + +#ifdef WIN32 + +#else +#include "drivers/oss.h" +#endif + +static uint32_t FtoB(const SexyAL_format *format, uint32_t frames) +{ + return(frames*format->channels*(format->sampformat>>4)); +} +/* +static uint32_t BtoF(const SexyAL_format *format, uint32_t bytes) +{ + return(bytes / (format->channels * (format->sampformat>>4))); +} +*/ +static uint32_t CanWrite(SexyAL_device *device) +{ + uint32_t bytes,frames; + + #ifdef WIN32 + bytes=SexyALI_DSound_RawCanWrite(device); + #else + bytes=SexyALI_OSS_RawCanWrite(device); + #endif + frames=bytes / device->format.channels / (device->format.sampformat>>4); + + return(frames); +} + +static uint32_t Write(SexyAL_device *device, void *data, uint32_t frames) +{ + uint8_t buffer[2048*4]; + + while(frames) + { + int32_t tmp; + + tmp=frames; + if(tmp>2048) + { + tmp=2048; + frames-=2048; + } + else frames-=tmp; + + SexiALI_Convert(&device->srcformat, &device->format, buffer, data, tmp); + //printf("%02x, %02x, %02x\n", device->srcformat.sampformat, device->srcformat.byteorder, device->srcformat.channels); + //printf("buffer: %d\n",buffer[0]); + /* FIXME: Return the actual number of frame written. It should always equal + the number of frames requested to be written, except in cases of sound device + failures. + */ + #ifdef WIN32 + SexyALI_DSound_RawWrite(device,buffer,FtoB(&device->format,tmp)); + #else + SexyALI_OSS_RawWrite(device,buffer,FtoB(&device->format,tmp)); + #endif + } + return(frames); +} + +static int Close(SexyAL_device *device) +{ + #ifdef WIN32 + return(SexyALI_DSound_Close(device)); + #else + return(SexyALI_OSS_Close(device)); + #endif +} + +int SetConvert(struct __SexyAL_device *device, SexyAL_format *format) +{ + memcpy(&device->srcformat,format,sizeof(SexyAL_format)); + return(1); +} + +static SexyAL_device *Open(SexyAL *iface, uint64_t id, SexyAL_format *format, SexyAL_buffering *buffering) +{ + SexyAL_device *ret; + + #ifdef WIN32 + if(!(ret=SexyALI_DSound_Open(id,format,buffering))) return(0); + #else + if(!(ret=SexyALI_OSS_Open(id,format,buffering))) return(0); + #endif + + ret->Write=Write; + ret->Close=Close; + ret->CanWrite=CanWrite; + ret->SetConvert=SetConvert; + return(ret); +} + +void Destroy(SexyAL *iface) +{ + free(iface); +} + +void *SexyAL_Init(int version) +{ + SexyAL *iface; + if(!version != 1) return(0); + + iface=malloc(sizeof(SexyAL)); + + iface->Open=Open; + iface->Destroy=Destroy; + return((void *)iface); +} diff --git a/branches/fceux-2.2.2/src/attic/sexyal/sexyal.h b/branches/fceux-2.2.2/src/attic/sexyal/sexyal.h new file mode 100644 index 00000000..c2e28884 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/sexyal.h @@ -0,0 +1,52 @@ +#include + +typedef struct +{ + uint32_t sampformat; + uint32_t channels; /* 1 = mono, 2 = stereo */ + uint32_t rate; /* Number of frames per second, 22050, 44100, etc. */ + uint32_t byteorder; /* 0 = Native(to CPU), 1 = Reversed. PDP can go to hell. */ +} SexyAL_format; + +typedef struct +{ + uint32_t fragcount; + uint32_t fragsize; + uint32_t totalsize; /* Shouldn't be filled in by application code. */ + uint32_t ms; /* Milliseconds of buffering, approximate. */ +} SexyAL_buffering; + +#define SEXYAL_ID_DEFAULT 0 +#define SEXYAL_ID_UNUSED 1 + +#define SEXYAL_FMT_PCMU8 0x10 +#define SEXYAL_FMT_PCMS8 0x11 + +#define SEXYAL_FMT_PCMU16 0x20 +#define SEXYAL_FMT_PCMS16 0x21 + +#define SEXYAL_FMT_PCMU32U24 0x40 +#define SEXYAL_FMT_PCMS32S24 0x41 + +#define SEXYAL_FMT_PCMU32U16 0x42 +#define SEXYAL_FMT_PCMS32S16 0x43 + +typedef struct __SexyAL_device { + int (*SetConvert)(struct __SexyAL_device *, SexyAL_format *); + uint32_t (*Write)(struct __SexyAL_device *, void *data, uint32_t frames); + uint32_t (*CanWrite)(struct __SexyAL_device *); + int (*Close)(struct __SexyAL_device *); + SexyAL_format format; + SexyAL_format srcformat; + SexyAL_buffering buffering; + void *private; +} SexyAL_device; + +typedef struct __SexyAL { + SexyAL_device * (*Open)(struct __SexyAL *, uint64_t id, SexyAL_format *, SexyAL_buffering *buffering); + void (*Enumerate)(struct __SexyAL *, int (*func)(uint8_t *name, uint64_t id, void *udata)); + void (*Destroy)(struct __SexyAL *); +} SexyAL; + +/* Initializes the library, requesting the interface of the version specified. */ +void *SexyAL_Init(int version); diff --git a/branches/fceux-2.2.2/src/attic/sexyal/smallc.c b/branches/fceux-2.2.2/src/attic/sexyal/smallc.c new file mode 100644 index 00000000..4aa95091 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/smallc.c @@ -0,0 +1,63 @@ +#include "smallc.h" + +void sal_memcpy(void *dest, const void *src, uint32_t n) +{ + while(n--) + { + *(uint8_t*)dest=*(uint8_t *)src; + (uint8_t*)dest++; + (uint8_t*)src++; + } +} + +uint32_t sal_strlen(const char *buf) +{ + uint32_t size=0; + + while(*buf++) size++; + + return(size); +} + +void sal_strcpy(char *dest, const char *src) +{ + while(*src) + *dest++ = *src++; + *dest=0; +} + +void sal_strcat(char *dest, const char *src) +{ + while(*dest) + dest++; + while(*src) + *dest++ = *src++; + *dest=0; +} + +const char *sal_uinttos(int value) +{ + static char buf[64],buf2[64]; + char *tmp; + int len=0; + + tmp=buf; + + while(value) + { + *tmp='0'+(value%10); + len++; + tmp++; + value/=10; + } + + tmp=buf2; + while(len-- >= 0) + { + *tmp=buf[len]; + tmp++; + } + + *tmp=0; + return(buf2); +} diff --git a/branches/fceux-2.2.2/src/attic/sexyal/smallc.h b/branches/fceux-2.2.2/src/attic/sexyal/smallc.h new file mode 100644 index 00000000..86856b1e --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/sexyal/smallc.h @@ -0,0 +1,7 @@ +#include + +void sal_memcpy(void *dest, const void *src, uint32_t n); +void sal_strcpy(char *dest, const char *src); +const char *sal_uinttos(int value); +void sal_strcat(char *dest, const char *src); + diff --git a/branches/fceux-2.2.2/src/attic/soundexp.cpp b/branches/fceux-2.2.2/src/attic/soundexp.cpp new file mode 100644 index 00000000..d59350f7 --- /dev/null +++ b/branches/fceux-2.2.2/src/attic/soundexp.cpp @@ -0,0 +1,42 @@ +#include + +#include + +#include "types.h" +#include "fceu.h" + +static OggVorbis_File cursong; + +void InstallSoundExp(void) +{ + FILE *fp=fopen("test.ogg","rb"); + + ov_open(fp,&cursong,NULL,0); + FCEUGameInfo->soundrate=44100; + FCEUGameInfo->soundchan=2; +} + +int cur=0; + +void UpdateSoundExp(int32 *buf, int32 len) +{ + int16 boo[8192]; + int32 offset=0; + int x; + int32 tlen=len; + + while(len) + { + int32 t=ov_read(&cursong,(char *)boo+offset*4,len*4,0,2,1,&cur)/4; + len-=t; + offset+=t; + } + +// printf("%d\n",inboo); + for(x=0;x> 2) & 1); + if (is172) + setchr8((((cmd ^ reg[2]) >> 3) & 2) | (((cmd ^ reg[2]) >> 5) & 1)); // 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to + // rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary + else + setchr8(reg[2] & 3); +} + +static DECLFW(UNL22211WriteLo) { +// FCEU_printf("bs %04x %02x\n",A,V); + reg[A & 3] = V; +} + +static DECLFW(UNL22211WriteHi) { +// FCEU_printf("bs %04x %02x\n",A,V); + cmd = V; + Sync(); +} + +static DECLFR(UNL22211ReadLo) { + return (reg[1] ^ reg[2]) | (is173 ? 0x01 : 0x40); +// if(reg[3]) +// return reg[2]; +// else +// return X.DB; +} + +static void UNL22211Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0x4100, 0x4100, UNL22211ReadLo); + SetWriteHandler(0x4100, 0x4103, UNL22211WriteLo); + SetWriteHandler(0x8000, 0xFFFF, UNL22211WriteHi); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNL22211_Init(CartInfo *info) { + is172 = 0; + is173 = 0; + info->Power = UNL22211Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper172_Init(CartInfo *info) { + is172 = 1; + is173 = 0; + info->Power = UNL22211Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper173_Init(CartInfo *info) { + is172 = 0; + is173 = 1; + info->Power = UNL22211Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/09-034a.cpp b/branches/fceux-2.2.2/src/boards/09-034a.cpp new file mode 100644 index 00000000..7847cd9d --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/09-034a.cpp @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * + * FDS Conversions + * + * Super Mario Bros 2j (Alt Full) is a BAD incomplete dump, should be mapper 43 + * + * Both Voleyball and Zanac by Whirlind Manu shares the same PCB, but with + * some differences: Voleyball has 8K CHR ROM and 8K ROM at 6000K, Zanac + * have 8K CHR RAM and banked 16K ROM mapper at 6000 as two 8K banks. +* + * Super Mario Bros 2j (Alt Small) uses additionally IRQ timer to drive framerate + * + * PCB for this mapper is "09-034A" + */ + +#include "mapinc.h" + +static uint8 prg; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { &prg, 1, "PRG" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(1, 0x6000, prg); + setprg32(0x8000, 0); + setchr8(0); +} + +static DECLFW(UNLSMB2JWrite1) { + prg = V & 1; + Sync(); +} + +static DECLFW(UNLSMB2JWrite2) { + IRQa = V & 1; + IRQCount = 0; + X6502_IRQEnd(FCEU_IQEXT); +} + +static DECLFR(UNLSMB2JRead) { + return 0xFF; +} + +static void UNLSMB2JPower(void) { + prg = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetReadHandler(0x4042, 0x4055, UNLSMB2JRead); + SetWriteHandler(0x4068, 0x4068, UNLSMB2JWrite2); + SetWriteHandler(0x4027, 0x4027, UNLSMB2JWrite1); +} + +static void UNLSMB2JIRQHook(int a) { + if (IRQa) + { + if (IRQCount < 5750) // completely by guess + IRQCount += a; + else { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLSMB2J_Init(CartInfo *info) { + info->Power = UNLSMB2JPower; + MapIRQHook = UNLSMB2JIRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/103.cpp b/branches/fceux-2.2.2/src/boards/103.cpp new file mode 100644 index 00000000..16a622c4 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/103.cpp @@ -0,0 +1,112 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg0, reg1, reg2; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®0, 1, "REG0" }, + { ®1, 1, "REG1" }, + { ®2, 1, "REG2" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8(0x8000, 0xc); + setprg8(0xe000, 0xf); + if (reg2 & 0x10) { + setprg8(0x6000, reg0); + setprg8(0xa000, 0xd); + setprg8(0xc000, 0xe); + } else { + setprg8r(0x10, 0x6000, 0); + setprg4(0xa000, (0xd << 1)); + setprg2(0xb000, (0xd << 2) + 2); + setprg2r(0x10, 0xb800, 4); + setprg2r(0x10, 0xc000, 5); + setprg2r(0x10, 0xc800, 6); + setprg2r(0x10, 0xd000, 7); + setprg2(0xd800, (0xe << 2) + 3); + } + setmirror(reg1 ^ 1); +} + +static DECLFW(M103RamWrite0) { + WRAM[A & 0x1FFF] = V; +} + +static DECLFW(M103RamWrite1) { + WRAM[0x2000 + ((A - 0xB800) & 0x1FFF)] = V; +} + +static DECLFW(M103Write0) { + reg0 = V & 0xf; + Sync(); +} + +static DECLFW(M103Write1) { + reg1 = (V >> 3) & 1; + Sync(); +} + +static DECLFW(M103Write2) { + reg2 = V; + Sync(); +} + +static void M103Power(void) { + reg0 = reg1 = 0; reg2 = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, M103RamWrite0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0xB800, 0xD7FF, M103RamWrite1); + SetWriteHandler(0x8000, 0x8FFF, M103Write0); + SetWriteHandler(0xE000, 0xEFFF, M103Write1); + SetWriteHandler(0xF000, 0xFFFF, M103Write2); +} + +static void M103Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper103_Init(CartInfo *info) { + info->Power = M103Power; + info->Close = M103Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 16384; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/106.cpp b/branches/fceux-2.2.2/src/boards/106.cpp new file mode 100644 index 00000000..e427d293 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/106.cpp @@ -0,0 +1,108 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg[16], IRQa; +static uint32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { reg, 16, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setchr1(0x0000, reg[0] & 0xfe); + setchr1(0x0400, reg[1] | 1); + setchr1(0x0800, reg[2] & 0xfe); + setchr1(0x0c00, reg[3] | 1); + setchr1(0x1000, reg[4]); + setchr1(0x1400, reg[5]); + setchr1(0x1800, reg[6]); + setchr1(0x1c00, reg[7]); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, (reg[0x8] & 0xf) | 0x10); + setprg8(0xA000, (reg[0x9] & 0x1f)); + setprg8(0xC000, (reg[0xa] & 0x1f)); + setprg8(0xE000, (reg[0xb] & 0xf) | 0x10); + setmirror((reg[0xc] & 1) ^ 1); +} + +static DECLFW(M106Write) { + A &= 0xF; + switch (A) { + case 0xD: IRQa = 0; IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xE: IRQCount = (IRQCount & 0xFF00) | V; break; + case 0xF: IRQCount = (IRQCount & 0x00FF) | (V << 8); IRQa = 1; break; + default: reg[A] = V; Sync(); break; + } +} + +static void M106Power(void) { + reg[8] = reg[9] = reg[0xa] = reg[0xb] = -1; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, M106Write); +} + +static void M106Reset(void) { +} + +static void M106Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void M106CpuHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount > 0x10000) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper106_Init(CartInfo *info) { + info->Reset = M106Reset; + info->Power = M106Power; + info->Close = M106Close; + MapIRQHook = M106CpuHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/108.cpp b/branches/fceux-2.2.2/src/boards/108.cpp new file mode 100644 index 00000000..4c463f96 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/108.cpp @@ -0,0 +1,58 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg32(0x8000, ~0); + setchr8(0); +} + +static DECLFW(M108Write) { + reg = V; + Sync(); +} + +static void M108Power(void) { + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x8FFF, M108Write); // regular 108 + SetWriteHandler(0xF000, 0xFFFF, M108Write); // simplified Kaiser BB Hack +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper108_Init(CartInfo *info) { + info->Power = M108Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/112.cpp b/branches/fceux-2.2.2/src/boards/112.cpp new file mode 100644 index 00000000..6c184b12 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/112.cpp @@ -0,0 +1,89 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * NTDEC, ASDER games + * + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, bank; +static uint8 *WRAM = NULL; + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { &mirror, 1, "MIRR" }, + { &bank, 1, "BANK" }, + { reg, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirror ^ 1); + setprg8(0x8000, reg[0]); + setprg8(0xA000, reg[1]); + setchr2(0x0000, (reg[2] >> 1)); + setchr2(0x0800, (reg[3] >> 1)); + setchr1(0x1000, ((bank & 0x10) << 4) | reg[4]); + setchr1(0x1400, ((bank & 0x20) << 3) | reg[5]); + setchr1(0x1800, ((bank & 0x40) << 2) | reg[6]); + setchr1(0x1C00, ((bank & 0x80) << 1) | reg[7]); +} + +static DECLFW(M112Write) { + switch (A) { + case 0xe000: mirror = V & 1; Sync();; break; + case 0x8000: cmd = V & 7; break; + case 0xa000: reg[cmd] = V; Sync(); break; + case 0xc000: bank = V; Sync(); break; + } +} + +static void M112Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void M112Power(void) { + bank = 0; + setprg16(0xC000, ~0); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M112Write); + SetWriteHandler(0x4020, 0x5FFF, M112Write); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper112_Init(CartInfo *info) { + info->Power = M112Power; + info->Close = M112Close; + GameStateRestore = StateRestore; + WRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartPRGMapping(0x10, WRAM, 8192, 1); + AddExState(WRAM, 8192, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/116.cpp b/branches/fceux-2.2.2/src/boards/116.cpp new file mode 100644 index 00000000..555f6c48 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/116.cpp @@ -0,0 +1,324 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 + * + * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) + * the same as 603-5052 board (TODO: add reading registers, merge) + * SL1632 2-in-1 protected board, similar to SL12 (TODO: find difference) + * + * Known PCB: + * + * Garou Densetsu Special (G0904.PCB, Huang-1, GAL dip: W conf.) + * Kart Fighter (008, Huang-1, GAL dip: W conf.) + * Somari (008, C5052-13, GAL dip: P conf., GK2-P/GK2-V maskroms) + * Somari (008, Huang-1, GAL dip: W conf., GK1-P/GK1-V maskroms) + * AV Mei Shao Nv Zhan Shi (aka AV Pretty Girl Fighting) (SL-12 PCB, Hunag-1, GAL dip: unk conf. SL-11A/SL-11B maskroms) + * Samurai Spirits (Full version) (Huang-1, GAL dip: unk conf. GS-2A/GS-4A maskroms) + * Contra Fighter (603-5052 PCB, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms) + * + */ + +#include "mapinc.h" + +static uint8 mode; +static uint8 vrc2_chr[8], vrc2_prg[2], vrc2_mirr; +static uint8 mmc3_regs[10], mmc3_ctrl, mmc3_mirr; +static uint8 IRQCount, IRQLatch, IRQa; +static uint8 IRQReload; +static uint8 mmc1_regs[4], mmc1_buffer, mmc1_shift; + +static SFORMAT StateRegs[] = +{ + { &mode, 1, "MODE" }, + { vrc2_chr, 8, "VRCC" }, + { vrc2_prg, 2, "VRCP" }, + { &vrc2_mirr, 1, "VRCM" }, + { mmc3_regs, 10, "M3RG" }, + { &mmc3_ctrl, 1, "M3CT" }, + { &mmc3_mirr, 1, "M3MR" }, + { &IRQReload, 1, "IRQR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQa, 1, "IRQA" }, + { mmc1_regs, 4, "M1RG" }, + { &mmc1_buffer, 1, "M1BF" }, + { &mmc1_shift, 1, "M1MR" }, + { 0 } +}; + +static void SyncPRG(void) { + switch (mode & 3) { + case 0: + setprg8(0x8000, vrc2_prg[0]); + setprg8(0xA000, vrc2_prg[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + break; + case 1: + { + uint32 swap = (mmc3_ctrl >> 5) & 2; + setprg8(0x8000, mmc3_regs[6 + swap]); + setprg8(0xA000, mmc3_regs[7]); + setprg8(0xC000, mmc3_regs[6 + (swap ^ 2)]); + setprg8(0xE000, mmc3_regs[9]); + break; + } + case 2: + case 3: + { + uint8 bank = mmc1_regs[3] & 0xF; + if (mmc1_regs[0] & 8) { + if (mmc1_regs[0] & 4) { + setprg16(0x8000, bank); + setprg16(0xC000, 0x0F); + } else { + setprg16(0x8000, 0); + setprg16(0xC000, bank); + } + } else + setprg32(0x8000, bank >> 1); + break; + } + } +} + +static void SyncCHR(void) { + uint32 base = (mode & 4) << 6; + switch (mode & 3) { + case 0: + setchr1(0x0000, base | vrc2_chr[0]); + setchr1(0x0400, base | vrc2_chr[1]); + setchr1(0x0800, base | vrc2_chr[2]); + setchr1(0x0c00, base | vrc2_chr[3]); + setchr1(0x1000, base | vrc2_chr[4]); + setchr1(0x1400, base | vrc2_chr[5]); + setchr1(0x1800, base | vrc2_chr[6]); + setchr1(0x1c00, base | vrc2_chr[7]); + break; + case 1: { + uint32 swap = (mmc3_ctrl & 0x80) << 5; + setchr1(0x0000 ^ swap, base | ((mmc3_regs[0]) & 0xFE)); + setchr1(0x0400 ^ swap, base | (mmc3_regs[0] | 1)); + setchr1(0x0800 ^ swap, base | ((mmc3_regs[1]) & 0xFE)); + setchr1(0x0c00 ^ swap, base | (mmc3_regs[1] | 1)); + setchr1(0x1000 ^ swap, base | mmc3_regs[2]); + setchr1(0x1400 ^ swap, base | mmc3_regs[3]); + setchr1(0x1800 ^ swap, base | mmc3_regs[4]); + setchr1(0x1c00 ^ swap, base | mmc3_regs[5]); + break; + } + case 2: + case 3: + if (mmc1_regs[0] & 0x10) { + setchr4(0x0000, mmc1_regs[1]); + setchr4(0x1000, mmc1_regs[2]); + } else + setchr8(mmc1_regs[1] >> 1); + break; + } +} + +static void SyncMIR(void) { + switch (mode & 3) { + case 0: { + setmirror((vrc2_mirr & 1) ^ 1); + break; + } + case 1: { + setmirror((mmc3_mirr & 1) ^ 1); + break; + } + case 2: + case 3: { + switch (mmc1_regs[0] & 3) { + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + } + break; + } + } +} + +static void Sync(void) { + SyncPRG(); + SyncCHR(); + SyncMIR(); +} + +static DECLFW(UNLSL12ModeWrite) { +// FCEU_printf("%04X:%02X\n",A,V); + if ((A & 0x4100) == 0x4100) { + mode = V; + if (A & 1) { // hacky hacky, there are two configuration modes on SOMARI HUANG-1 PCBs + // Solder pads with P1/P2 shorted called SOMARI P, + // Solder pads with W1/W2 shorted called SOMARI W + // Both identical 3-in-1 but W wanted MMC1 registers + // to be reset when switch to MMC1 mode P one - doesn't + // There is issue with W version of Somari at starting copyrights + mmc1_regs[0] = 0xc; + mmc1_regs[3] = 0; + mmc1_buffer = 0; + mmc1_shift = 0; + } + Sync(); + } +} + +static DECLFW(UNLSL12Write) { +// FCEU_printf("%04X:%02X\n",A,V); + switch (mode & 3) { + case 0: { + if ((A >= 0xB000) && (A <= 0xE003)) { + int32 ind = ((((A & 2) | (A >> 10)) >> 1) + 2) & 7; + int32 sar = ((A & 1) << 2); + vrc2_chr[ind] = (vrc2_chr[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + SyncCHR(); + } else + switch (A & 0xF000) { + case 0x8000: vrc2_prg[0] = V; SyncPRG(); break; + case 0xA000: vrc2_prg[1] = V; SyncPRG(); break; + case 0x9000: vrc2_mirr = V; SyncMIR(); break; + } + break; + } + case 1: { + switch (A & 0xE001) { + case 0x8000: { + uint8 old_ctrl = mmc3_ctrl; + mmc3_ctrl = V; + if ((old_ctrl & 0x40) != (mmc3_ctrl & 0x40)) + SyncPRG(); + if ((old_ctrl & 0x80) != (mmc3_ctrl & 0x80)) + SyncCHR(); + break; + } + case 0x8001: + mmc3_regs[mmc3_ctrl & 7] = V; + if ((mmc3_ctrl & 7) < 6) + SyncCHR(); + else + SyncPRG(); + break; + case 0xA000: + mmc3_mirr = V; + SyncMIR(); + break; + case 0xC000: + IRQLatch = V; + break; + case 0xC001: + IRQReload = 1; + break; + case 0xE000: + X6502_IRQEnd(FCEU_IQEXT); + IRQa = 0; + break; + case 0xE001: + IRQa = 1; + break; + } + break; + } + case 2: + case 3: { + if (V & 0x80) { + mmc1_regs[0] |= 0xc; + mmc1_buffer = mmc1_shift = 0; + SyncPRG(); + } else { + uint8 n = (A >> 13) - 4; + mmc1_buffer |= (V & 1) << (mmc1_shift++); + if (mmc1_shift == 5) { + mmc1_regs[n] = mmc1_buffer; + mmc1_buffer = mmc1_shift = 0; + switch (n) { + case 0: SyncMIR(); + case 2: SyncCHR(); + case 3: + case 1: SyncPRG(); + } + } + } + break; + } + } +} + +static void UNLSL12HBIRQ(void) { + if ((mode & 3) == 1) { + int32 count = IRQCount; + if (!count || IRQReload) { + IRQCount = IRQLatch; + IRQReload = 0; + } else + IRQCount--; + if (!IRQCount) { + if (IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +static void UNLSL12Power(void) { + mode = 0; + vrc2_chr[0] = ~0; + vrc2_chr[1] = ~0; + vrc2_chr[2] = ~0; + vrc2_chr[3] = ~0; // W conf. of Somari wanted CHR3 has to be set to BB bank (or similar), but doesn't do that directly + vrc2_chr[4] = 4; + vrc2_chr[5] = 5; + vrc2_chr[6] = 6; + vrc2_chr[7] = 7; + vrc2_prg[0] = 0; + vrc2_prg[1] = 1; + vrc2_mirr = 0; + mmc3_regs[0] = 0; + mmc3_regs[1] = 2; + mmc3_regs[2] = 4; + mmc3_regs[3] = 5; + mmc3_regs[4] = 6; + mmc3_regs[5] = 7; + mmc3_regs[6] = ~3; + mmc3_regs[7] = ~2; + mmc3_regs[8] = ~1; + mmc3_regs[9] = ~0; + mmc3_ctrl = mmc3_mirr = IRQCount = IRQLatch = IRQa = 0; + mmc1_regs[0] = 0xc; + mmc1_regs[1] = 0; + mmc1_regs[2] = 0; + mmc1_regs[3] = 0; + mmc1_buffer = 0; + mmc1_shift = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x7FFF, UNLSL12ModeWrite); + SetWriteHandler(0x8000, 0xFFFF, UNLSL12Write); +} + +void UNLSL12_Init(CartInfo *info) { + info->Power = UNLSL12Power; + GameHBIRQHook = UNLSL12HBIRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/117.cpp b/branches/fceux-2.2.2/src/boards/117.cpp new file mode 100644 index 00000000..3a50ce27 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/117.cpp @@ -0,0 +1,91 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 prgreg[4], chrreg[8], mirror; +static uint8 IRQa, IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { &IRQa, 1, "IRQA" }, + { &IRQCount, 1, "IRQC" }, + { &IRQLatch, 1, "IRQL" }, + { prgreg, 4, "PREG" }, + { chrreg, 8, "CREG" }, + { &mirror, 1, "MREG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, prgreg[0]); + setprg8(0xa000, prgreg[1]); + setprg8(0xc000, prgreg[2]); + setprg8(0xe000, prgreg[3]); + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chrreg[i]); + setmirror(mirror ^ 1); +} + +static DECLFW(M117Write) { + if (A < 0x8004) { + prgreg[A & 3] = V; + Sync(); + } else if ((A >= 0xA000) && (A <= 0xA007)) { + chrreg[A & 7] = V; + Sync(); + } else switch (A) { + case 0xc001: IRQLatch = V; break; + case 0xc003: IRQCount = IRQLatch; IRQa |= 2; break; + case 0xe000: IRQa &= ~1; IRQa |= V & 1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xc002: X6502_IRQEnd(FCEU_IQEXT); break; + case 0xd000: mirror = V & 1; + } +} + +static void M117Power(void) { + prgreg[0] = ~3; prgreg[1] = ~2; prgreg[2] = ~1; prgreg[3] = ~0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M117Write); +} + +static void M117IRQHook(void) { + if (IRQa == 3 && IRQCount) { + IRQCount--; + if (!IRQCount) { + IRQa &= 1; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper117_Init(CartInfo *info) { + info->Power = M117Power; + GameHBIRQHook = M117IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/120.cpp b/branches/fceux-2.2.2/src/boards/120.cpp new file mode 100644 index 00000000..aee1982a --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/120.cpp @@ -0,0 +1,59 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg32(0x8000, 2); + setchr8(0); +} + +static DECLFW(M120Write) { + if (A == 0x41FF) { + reg = V & 7; + Sync(); + } +} + +static void M120Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x5FFF, M120Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper120_Init(CartInfo *info) { + info->Power = M120Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/121.cpp b/branches/fceux-2.2.2/src/boards/121.cpp new file mode 100644 index 00000000..aa4e5c2c --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/121.cpp @@ -0,0 +1,129 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007-2008 Mad Dumper, CaH4e3 + * + * 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 + * + * Panda prince pirate. + * MK4, MK6, A9711/A9713 board + * 6035052 seems to be the same too, but with prot array in reverse + * A9746 seems to be the same too, check + * 187 seems to be the same too, check (A98402 board) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void Sync() { + switch (EXPREGS[5] & 0x3F) { + case 0x20: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x29: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x26: EXPREGS[7] = 0; EXPREGS[0] = EXPREGS[6]; break; + case 0x2B: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x2C: EXPREGS[7] = 1; if (EXPREGS[6]) EXPREGS[0] = EXPREGS[6]; break; + case 0x3C: + case 0x3F: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x28: EXPREGS[7] = 0; EXPREGS[1] = EXPREGS[6]; break; + case 0x2A: EXPREGS[7] = 0; EXPREGS[2] = EXPREGS[6]; break; + case 0x2F: break; + default: EXPREGS[5] = 0; break; + } +} + +static void M121CW(uint32 A, uint8 V) { + if (PRGsize[0] == CHRsize[0]) { // A9713 multigame extension hack! + setchr1(A, V | ((EXPREGS[3] & 0x80) << 1)); + } else { + if ((A & 0x1000) == ((MMC3_cmd & 0x80) << 5)) + setchr1(A, V | 0x100); + else + setchr1(A, V); + } +} + +static void M121PW(uint32 A, uint8 V) { + if (EXPREGS[5] & 0x3F) { +// FCEU_printf("prot banks: %02x %02x %02x %02x\n",V,EXPREGS[2],EXPREGS[1],EXPREGS[0]); + setprg8(A, (V & 0x1F) | ((EXPREGS[3] & 0x80) >> 2)); + setprg8(0xE000, (EXPREGS[0]) | ((EXPREGS[3] & 0x80) >> 2)); + setprg8(0xC000, (EXPREGS[1]) | ((EXPREGS[3] & 0x80) >> 2)); + setprg8(0xA000, (EXPREGS[2]) | ((EXPREGS[3] & 0x80) >> 2)); + } else { +// FCEU_printf("gen banks: %04x %02x\n",A,V); + setprg8(A, (V & 0x1F) | ((EXPREGS[3] & 0x80) >> 2)); + } +} + +static DECLFW(M121Write) { +// FCEU_printf("write: %04x:%04x\n",A&0xE003,V); + switch (A & 0xE003) { + case 0x8000: +// EXPREGS[5] = 0; +// FCEU_printf("gen: %02x\n",V); + MMC3_CMDWrite(A, V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8001: + EXPREGS[6] = ((V & 1) << 5) | ((V & 2) << 3) | ((V & 4) << 1) | ((V & 8) >> 1) | ((V & 0x10) >> 3) | ((V & 0x20) >> 5); +// FCEU_printf("bank: %02x (%02x)\n",V,EXPREGS[6]); + if (!EXPREGS[7]) Sync(); + MMC3_CMDWrite(A, V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8003: + EXPREGS[5] = V; +// EXPREGS[7] = 0; +// FCEU_printf("prot: %02x\n",EXPREGS[5]); + Sync(); + MMC3_CMDWrite(0x8000, V); + FixMMC3PRG(MMC3_cmd); + break; + } +} + +static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFW(M121LoWrite) { + EXPREGS[4] = prot_array[V & 3]; // 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter) + if ((A & 0x5180) == 0x5180) { // A9713 multigame extension + EXPREGS[3] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +// FCEU_printf("write: %04x:%04x\n",A,V); +} + +static DECLFR(M121Read) { +// FCEU_printf("read: %04x->\n",A,EXPREGS[0]); + return EXPREGS[4]; +} + +static void M121Power(void) { + EXPREGS[3] = 0x80; + EXPREGS[5] = 0; + GenMMC3Power(); + SetReadHandler(0x5000, 0x5FFF, M121Read); + SetWriteHandler(0x5000, 0x5FFF, M121LoWrite); + SetWriteHandler(0x8000, 0x9FFF, M121Write); +} + +void Mapper121_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 8, 0); + pwrap = M121PW; + cwrap = M121CW; + info->Power = M121Power; + AddExState(EXPREGS, 8, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/12in1.cpp b/branches/fceux-2.2.2/src/boards/12in1.cpp new file mode 100644 index 00000000..15f6c079 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/12in1.cpp @@ -0,0 +1,70 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 + * + * 7-in-1 Darkwing Duck, Snake, MagicBlock (PCB marked as "12 in 1") + */ + +#include "mapinc.h" + +static uint8 reg[4]; +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { 0 } +}; + +static void Sync(void) { + uint8 bank = (reg[3] & 3) << 3; + setchr4(0x0000, (reg[1] >> 3) | (bank << 2)); + setchr4(0x1000, (reg[2] >> 3) | (bank << 2)); + if (reg[3] & 8) { + setprg32(0x8000, ((reg[2] & 7) >> 1) | bank); + } else { + setprg16(0x8000, (reg[1] & 7) | bank); + setprg16(0xc000, 7 | bank); + } + setmirror(((reg[3] & 4) >> 2) ^ 1); +} + +static DECLFW(BMC12IN1Write) { + switch (A) { + case 0xafff: reg[0] = V; break; + case 0xbfff: reg[1] = V; break; + case 0xdfff: reg[2] = V; break; + case 0xefff: reg[3] = V; break; + } + Sync(); +} + +static void BMC12IN1Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BMC12IN1Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC12IN1_Init(CartInfo *info) { + info->Power = BMC12IN1Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/15.cpp b/branches/fceux-2.2.2/src/boards/15.cpp new file mode 100644 index 00000000..4aee608a --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/15.cpp @@ -0,0 +1,109 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 "mapinc.h" + +static uint16 latchea; +static uint8 latched; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static SFORMAT StateRegs[] = +{ + { &latchea, 2, "AREG" }, + { &latched, 1, "DREG" }, + { 0 } +}; + +static void Sync(void) { + int i; + setmirror(((latched >> 6) & 1) ^ 1); + switch (latchea) { + case 0x8000: + for (i = 0; i < 4; i++) + setprg8(0x8000 + (i << 13), (((latched & 0x7F) << 1) + i) ^ (latched >> 7)); + break; + case 0x8002: + for (i = 0; i < 4; i++) + setprg8(0x8000 + (i << 13), ((latched & 0x7F) << 1) + (latched >> 7)); + break; + case 0x8001: + case 0x8003: + for (i = 0; i < 4; i++) { + unsigned int b; + b = latched & 0x7F; + if (i >= 2 && !(latchea & 0x2)) + b = 0x7F; + setprg8(0x8000 + (i << 13), (i & 1) + ((b << 1) ^ (latched >> 7))); + } + break; + } +} + +static DECLFW(M15Write) { + latchea = A; + latched = V; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +static void M15Power(void) { + latchea = 0x8000; + latched = 0; + setchr8(0); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, M15Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + Sync(); +} + +static void M15Reset(void) { + latchea = 0x8000; + latched = 0; + Sync(); +} + +static void M15Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper15_Init(CartInfo *info) { + info->Power = M15Power; + info->Reset = M15Reset; + info->Close = M15Close; + GameStateRestore = StateRestore; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/151.cpp b/branches/fceux-2.2.2/src/boards/151.cpp new file mode 100644 index 00000000..2d9335f1 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/151.cpp @@ -0,0 +1,59 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 regs[8]; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[2]); + setprg8(0xC000, regs[4]); + setprg8(0xE000, ~0); + setchr4(0x0000, regs[6]); + setchr4(0x1000, regs[7]); +} + +static DECLFW(M151Write) { + regs[(A >> 12) & 7] = V; + Sync(); +} + +static void M151Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M151Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper151_Init(CartInfo *info) { + info->Power = M151Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/156.cpp b/branches/fceux-2.2.2/src/boards/156.cpp new file mode 100644 index 00000000..d682f305 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/156.cpp @@ -0,0 +1,113 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 chrlo[8], chrhi[8], prg, mirr, mirrisused = 0; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &prg, 1, "PREG" }, + { chrlo, 8, "CRGL" }, + { chrhi, 8, "CRGH" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + uint32 i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chrlo[i] | (chrhi[i] << 8)); + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, prg); + setprg16(0xC000, ~0); + if (mirrisused) + setmirror(mirr ^ 1); + else + setmirror(MI_0); +} + +static DECLFW(M156Write) { + switch (A) { + case 0xC000: + case 0xC001: + case 0xC002: + case 0xC003: chrlo[A & 3] = V; Sync(); break; + case 0xC004: + case 0xC005: + case 0xC006: + case 0xC007: chrhi[A & 3] = V; Sync(); break; + case 0xC008: + case 0xC009: + case 0xC00A: + case 0xC00B: chrlo[4 + (A & 3)] = V; Sync(); break; + case 0xC00C: + case 0xC00D: + case 0xC00E: + case 0xC00F: chrhi[4 + (A & 3)] = V; Sync(); break; + case 0xC010: prg = V; Sync(); break; + case 0xC014: mirr = V; mirrisused = 1; Sync(); break; + } +} + +static void M156Reset(void) { + uint32 i; + for (i = 0; i < 8; i++) { + chrlo[i] = 0; + chrhi[i] = 0; + } + prg = 0; + mirr = 0; + mirrisused = 0; +} + +static void M156Power(void) { + M156Reset(); + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0xC000, 0xCFFF, M156Write); +} + +static void M156Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper156_Init(CartInfo *info) { + info->Reset = M156Reset; + info->Power = M156Power; + info->Close = M156Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/164.cpp b/branches/fceux-2.2.2/src/boards/164.cpp new file mode 100644 index 00000000..7cde0a3a --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/164.cpp @@ -0,0 +1,229 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel 2006 CaH4e3 + * + * 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 + * + * It seems that 162/163/164 mappers are the same mapper with just different + * mapper modes enabled or disabled in software or hardware, need more nanjing + * carts + */ + +#include "mapinc.h" + +static uint8 laststrobe, trigger; +static uint8 reg[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static writefunc pcmwrite; + +static void (*WSync)(void); + +static SFORMAT StateRegs[] = +{ + { &laststrobe, 1, "STB" }, + { &trigger, 1, "TRG" }, + { reg, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, (reg[0] << 4) | (reg[1] & 0xF)); + setchr8(0); +} + +static void StateRestore(int version) { + WSync(); +} + +static DECLFR(ReadLow) { + switch (A & 0x7700) { + case 0x5100: return reg[2] | reg[0] | reg[1] | reg[3] ^ 0xff; break; + case 0x5500: + if (trigger) + return reg[2] | reg[1]; // Lei Dian Huang Bi Ka Qiu Chuan Shuo (NJ046) may broke other games + else + return 0; + } + return 4; +} + +static void M163HB(void) { + if (reg[1] & 0x80) { + if (scanline == 239) { + setchr4(0x0000, 0); + setchr4(0x1000, 0); + } else if (scanline == 127) { + setchr4(0x0000, 1); + setchr4(0x1000, 1); + } +/* + if(scanline>=127) // Hu Lu Jin Gang (NJ039) (Ch) [!] don't like it + { + setchr4(0x0000,1); + setchr4(0x1000,1); + } + else + { + setchr4(0x0000,0); + setchr4(0x1000,0); + } +*/ + } +} + +static DECLFW(Write) { + switch (A & 0x7300) { + case 0x5100: reg[0] = V; WSync(); break; + case 0x5000: reg[1] = V; WSync(); break; + case 0x5300: reg[2] = V; break; + case 0x5200: reg[3] = V; WSync(); break; + } +} + +static void Power(void) { + memset(reg, 0, 8); + reg[1] = 0xFF; + SetWriteHandler(0x5000, 0x5FFF, Write); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + WSync(); +} + +static void Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper164_Init(CartInfo *info) { + info->Power = Power; + info->Close = Close; + WSync = Sync; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +static DECLFW(Write2) { + if (A == 0x5101) { + if (laststrobe && !V) { + trigger ^= 1; + } + laststrobe = V; + } else if (A == 0x5100 && V == 6) //damn thoose protected games + setprg32(0x8000, 3); + else + switch (A & 0x7300) { + case 0x5200: reg[0] = V; WSync(); break; + case 0x5000: reg[1] = V; WSync(); if (!(reg[1] & 0x80) && (scanline < 128)) setchr8(0); /* setchr8(0); */ break; + case 0x5300: reg[2] = V; break; + case 0x5100: reg[3] = V; WSync(); break; + } +} + +static void Power2(void) { + memset(reg, 0, 8); + laststrobe = 1; + pcmwrite = GetWriteHandler(0x4011); + SetReadHandler(0x5000, 0x5FFF, ReadLow); + SetWriteHandler(0x5000, 0x5FFF, Write2); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + WSync(); +} + +void Mapper163_Init(CartInfo *info) { + info->Power = Power2; + info->Close = Close; + WSync = Sync; + GameHBIRQHook = M163HB; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +static void Sync3(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + switch (reg[3] & 7) { + case 0: + case 2: setprg32(0x8000, (reg[0] & 0xc) | (reg[1] & 2) | ((reg[2] & 0xf) << 4)); break; + case 1: + case 3: setprg32(0x8000, (reg[0] & 0xc) | (reg[2] & 0xf) << 4); break; + case 4: + case 6: setprg32(0x8000, (reg[0] & 0xe) | ((reg[1] >> 1) & 1) | ((reg[2] & 0xf) << 4)); break; + case 5: + case 7: setprg32(0x8000, (reg[0] & 0xf) | ((reg[2] & 0xf) << 4)); break; + } +} + +static DECLFW(Write3) { +// FCEU_printf("bs %04x %02x\n",A,V); + reg[(A >> 8) & 3] = V; + WSync(); +} + +static void Power3(void) { + reg[0] = 3; + reg[1] = 0; + reg[2] = 0; + reg[3] = 7; + SetWriteHandler(0x5000, 0x5FFF, Write3); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + WSync(); +} + +void UNLFS304_Init(CartInfo *info) { + info->Power = Power3; + info->Close = Close; + WSync = Sync3; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/168.cpp b/branches/fceux-2.2.2/src/boards/168.cpp new file mode 100644 index 00000000..5ec8e897 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/168.cpp @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setchr4r(0x10, 0x0000, 0); + setchr4r(0x10, 0x1000, reg & 0x0f); + setprg16(0x8000, reg >> 6); + setprg16(0xc000, ~0); +} + +static DECLFW(M168Write) { + reg = V; + Sync(); +} + +static DECLFW(M168Dummy) { +} + +static void M168Power(void) { + reg = 0; + Sync(); + SetWriteHandler(0x4020, 0x7fff, M168Dummy); + SetWriteHandler(0xB000, 0xB000, M168Write); + SetWriteHandler(0xF000, 0xF000, M168Dummy); + SetWriteHandler(0xF080, 0xF080, M168Dummy); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void MNNNClose(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper168_Init(CartInfo *info) { + info->Power = M168Power; + info->Close = MNNNClose; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); + + CHRRAMSIZE = 8192 * 8; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); +} diff --git a/branches/fceux-2.2.2/src/boards/170.cpp b/branches/fceux-2.2.2/src/boards/170.cpp new file mode 100644 index 00000000..9a8a8e50 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/170.cpp @@ -0,0 +1,62 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, 0); + setprg16(0xc000, ~0); + setchr8(0); +} + +static DECLFW(M170ProtW) { + reg = V << 1 & 0x80; +} + +static DECLFR(M170ProtR) { + return reg | (X.DB & 0x7F); +} + +static void M170Power(void) { + Sync(); + SetWriteHandler(0x6502, 0x6502, M170ProtW); + SetWriteHandler(0x7000, 0x7000, M170ProtW); + SetReadHandler(0x7001, 0x7001, M170ProtR); + SetReadHandler(0x7777, 0x7777, M170ProtR); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper170_Init(CartInfo *info) { + info->Power = M170Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/175.cpp b/branches/fceux-2.2.2/src/boards/175.cpp new file mode 100644 index 00000000..82786074 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/175.cpp @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg, delay, mirr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setchr8(reg); + if (!delay) { + setprg16(0x8000, reg); + setprg8(0xC000, reg << 1); + } + setprg8(0xE000, (reg << 1) + 1); + setmirror(((mirr & 4) >> 2) ^ 1); +} + +static DECLFW(M175Write1) { + mirr = V; + delay = 1; + Sync(); +} + +static DECLFW(M175Write2) { + reg = V & 0x0F; + delay = 1; + Sync(); +} + +static DECLFR(M175Read) { + if (A == 0xFFFC) { + delay = 0; + Sync(); + } + return CartBR(A); +} + +static void M175Power(void) { + reg = mirr = delay = 0; + SetReadHandler(0x8000, 0xFFFF, M175Read); + SetWriteHandler(0x8000, 0x8000, M175Write1); + SetWriteHandler(0xA000, 0xA000, M175Write2); + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper175_Init(CartInfo *info) { + info->Power = M175Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/176.cpp b/branches/fceux-2.2.2/src/boards/176.cpp new file mode 100644 index 00000000..37309eb3 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/176.cpp @@ -0,0 +1,158 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * Copyright (C) 2012 FCEUX team + * + * 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 "mapinc.h" + +extern uint32 ROM_size; + +static uint8 prg[4], chr, sbw, we_sram; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {prg, 4, "PRG"}, + {&chr, 1, "CHR"}, + {&sbw, 1, "SBW"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,0); + setprg8(0x8000,prg[0]); + setprg8(0xA000,prg[1]); + setprg8(0xC000,prg[2]); + setprg8(0xE000,prg[3]); + + setchr8(chr); +} + +static DECLFW(M176Write_5001) +{ + printf("%04X = $%02X\n",A,V); + if(sbw) + { + prg[0] = V*4; + prg[1] = V*4+1; + prg[2] = V*4+2; + prg[3] = V*4+3; + } + Sync(); +} + +static DECLFW(M176Write_5010) +{ + printf("%04X = $%02X\n",A,V); + if(V == 0x24) sbw = 1; + Sync(); +} + +static DECLFW(M176Write_5011) +{ + printf("%04X = $%02X\n",A,V); + V >>= 1; + if(sbw) + { + prg[0] = V*4; + prg[1] = V*4+1; + prg[2] = V*4+2; + prg[3] = V*4+3; + } + Sync(); +} + +static DECLFW(M176Write_5FF1) +{ + printf("%04X = $%02X\n",A,V); + V >>= 1; + prg[0] = V*4; + prg[1] = V*4+1; + prg[2] = V*4+2; + prg[3] = V*4+3; + Sync(); +} + +static DECLFW(M176Write_5FF2) +{ + printf("%04X = $%02X\n",A,V); + chr = V; + Sync(); +} + +static DECLFW(M176Write_A001) +{ + we_sram = V & 0x03; +} + +static DECLFW(M176Write_WriteSRAM) +{ +// if(we_sram) + CartBW(A,V); +} + +static void M176Power(void) +{ + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,M176Write_WriteSRAM); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0xA001,0xA001,M176Write_A001); + SetWriteHandler(0x5001,0x5001,M176Write_5001); + SetWriteHandler(0x5010,0x5010,M176Write_5010); + SetWriteHandler(0x5011,0x5011,M176Write_5011); + SetWriteHandler(0x5ff1,0x5ff1,M176Write_5FF1); + SetWriteHandler(0x5ff2,0x5ff2,M176Write_5FF2); + + we_sram = 0; + sbw = 0; + prg[0] = 0; + prg[1] = 1; + prg[2] = (ROM_size-2)&63; + prg[3] = (ROM_size-1)&63; + Sync(); +} + + +static void M176Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper176_Init(CartInfo *info) +{ + info->Power=M176Power; + info->Close=M176Close; + + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/177.cpp b/branches/fceux-2.2.2/src/boards/177.cpp new file mode 100644 index 00000000..04fd9c84 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/177.cpp @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, reg & 0x1f); + setmirror(((reg & 0x20) >> 5) ^ 1); +} + +static DECLFW(M177Write) { + reg = V; + Sync(); +} + +static void M177Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M177Write); +} + +static void M177Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper177_Init(CartInfo *info) { + info->Power = M177Power; + info->Close = M177Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/178.cpp b/branches/fceux-2.2.2/src/boards/178.cpp new file mode 100644 index 00000000..cfd0392d --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/178.cpp @@ -0,0 +1,176 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2013 CaH4e3 + * + * 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 + * + * DSOUNDV1/FL-TR8MA boards (32K WRAM, 8/16M), 178 mapper boards (8K WRAM, 4/8M) + * Various Education Cartridges + * + */ + +#include "mapinc.h" + +static uint8 reg[4]; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +// SND Registers +static uint8 pcm_enable = 0; +static int16 pcm_latch = 0x3F6, pcm_clock = 0x3F6; +static writefunc pcmwrite; + +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { 0 } +}; + +static int16 step_size[49] = { + 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, + 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, + 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, + 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, + 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552 +}; //49 items +static int32 step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 }; + +//decode stuff +static int32 jedi_table[16 * 49]; +static int32 acc = 0; //ADPCM accumulator, initial condition must be 0 +static int32 decstep = 0; //ADPCM decoding step, initial condition must be 0 + +static void jedi_table_init() { + int step, nib; + + for (step = 0; step < 49; step++) { + for (nib = 0; nib < 16; nib++) { + int value = (2 * (nib & 0x07) + 1) * step_size[step] / 8; + jedi_table[step * 16 + nib] = ((nib & 0x08) != 0) ? -value : value; + } + } +} + +static uint8 decode(uint8 code) { + acc += jedi_table[decstep + code]; + if ((acc & ~0x7ff) != 0) // acc is > 2047 + acc |= ~0xfff; + else acc &= 0xfff; + decstep += step_adj[code & 7] * 16; + if (decstep < 0) decstep = 0; + if (decstep > 48 * 16) decstep = 48 * 16; + return (acc >> 8) & 0xff; +} + +static void Sync(void) { + uint32 sbank = reg[1] & 0x7; + uint32 bbank = reg[2]; + setchr8(0); + setprg8r(0x10, 0x6000, reg[3] & 3); + if (reg[0] & 2) { // UNROM mode + setprg16(0x8000, (bbank << 3) | sbank); + if (reg[0] & 4) + setprg16(0xC000, (bbank << 3) | 6 | (reg[1] & 1)); + else + setprg16(0xC000, (bbank << 3) | 7); + } else { // NROM mode + uint32 bank = (bbank << 3) | sbank; + if (reg[0] & 4) { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } else + setprg32(0x8000, bank >> 1); + } + setmirror((reg[0] & 1) ^ 1); +} + +static DECLFW(M178Write) { + reg[A & 3] = V; +// FCEU_printf("cmd %04x:%02x\n", A, V); + Sync(); +} + +static DECLFW(M178WriteSnd) { + if (A == 0x5800) { + if (V & 0xF0) { + pcm_enable = 1; +// pcmwrite(0x4011, (V & 0xF) << 3); + pcmwrite(0x4011, decode(V & 0xf)); + } else + pcm_enable = 0; + } else + FCEU_printf("misc %04x:%02x\n", A, V); +} + +static DECLFR(M178ReadSnd) { + if (A == 0x5800) + return (X.DB & 0xBF) | ((pcm_enable ^ 1) << 6); + else + return X.DB; +} + +static void M178Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = 0; + Sync(); + pcmwrite = GetWriteHandler(0x4011); + SetWriteHandler(0x4800, 0x4fff, M178Write); + SetWriteHandler(0x5800, 0x5fff, M178WriteSnd); + SetReadHandler(0x5800, 0x5fff, M178ReadSnd); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xffff, CartBR); +} + +static void M178SndClk(int a) { + if (pcm_enable) { + pcm_latch -= a; + if (pcm_latch <= 0) { + pcm_latch += pcm_clock; + pcm_enable = 0; + } + } +} + +static void M178Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper178_Init(CartInfo *info) { + info->Power = M178Power; + info->Close = M178Close; + GameStateRestore = StateRestore; + MapIRQHook = M178SndClk; + + jedi_table_init(); + + WRAMSIZE = 32768; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/18.cpp b/branches/fceux-2.2.2/src/boards/18.cpp new file mode 100644 index 00000000..dcec0dc1 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/18.cpp @@ -0,0 +1,133 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 preg[4], creg[8]; +static uint8 IRQa, mirr; +static int32 IRQCount, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + int i; + for (i = 0; i < 8; i++) setchr1(i << 10, creg[i]); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + if (mirr & 2) + setmirror(MI_0); + else + setmirror(mirr & 1); +} + +static DECLFW(M18WriteIRQ) { + switch (A & 0xF003) { + case 0xE000: IRQLatch &= 0xFFF0; IRQLatch |= (V & 0x0f) << 0x0; break; + case 0xE001: IRQLatch &= 0xFF0F; IRQLatch |= (V & 0x0f) << 0x4; break; + case 0xE002: IRQLatch &= 0xF0FF; IRQLatch |= (V & 0x0f) << 0x8; break; + case 0xE003: IRQLatch &= 0x0FFF; IRQLatch |= (V & 0x0f) << 0xC; break; + case 0xF000: IRQCount = IRQLatch; break; + case 0xF001: IRQa = V & 1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF002: mirr = V & 3; Sync(); break; + } +} + +static DECLFW(M18WritePrg) { + uint32 i = ((A >> 1) & 1) | ((A - 0x8000) >> 11); + preg[i] &= (0xF0) >> ((A & 1) << 2); + preg[i] |= (V & 0xF) << ((A & 1) << 2); + Sync(); +} + +static DECLFW(M18WriteChr) { + uint32 i = ((A >> 1) & 1) | ((A - 0xA000) >> 11); + creg[i] &= (0xF0) >> ((A & 1) << 2); + creg[i] |= (V & 0xF) << ((A & 1) << 2); + Sync(); +} + +static void M18Power(void) { + IRQa = 0; + preg[0] = 0; + preg[1] = 1; + preg[2] = ~1; + preg[3] = ~0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0x9FFF, M18WritePrg); + SetWriteHandler(0xA000, 0xDFFF, M18WriteChr); + SetWriteHandler(0xE000, 0xFFFF, M18WriteIRQ); +} + +static void M18IRQHook(int a) { + if (IRQa && IRQCount) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = 0; + IRQa = 0; + } + } +} + +static void M18Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper18_Init(CartInfo *info) { + info->Power = M18Power; + info->Close = M18Close; + MapIRQHook = M18IRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/183.cpp b/branches/fceux-2.2.2/src/boards/183.cpp new file mode 100644 index 00000000..9ba8c2c4 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/183.cpp @@ -0,0 +1,111 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * Gimmick Bootleg (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 prg[4], chr[8], mirr; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[] = +{ + { prg, 4, "PRG" }, + { chr, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQPre, 1, "IRQP" }, + { &IRQa, 1, "IRQA" }, + { 0 } +}; + +static void SyncPrg(void) { + setprg8(0x6000, prg[3]); + setprg8(0x8000, prg[0]); + setprg8(0xA000, prg[1]); + setprg8(0xC000, prg[2]); + setprg8(0xE000, ~0); +} + +static void SyncMirr(void) { + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static void SyncChr(void) { + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); +} + +static void StateRestore(int version) { + SyncPrg(); + SyncChr(); + SyncMirr(); +} + +static DECLFW(M183Write) { + if ((A & 0xF800) == 0x6800) { + prg[3] = A & 0x3F; + SyncPrg(); + } else if (((A & 0xF80C) >= 0xB000) && ((A & 0xF80C) <= 0xE00C)) { + int index = (((A >> 11) - 6) | (A >> 3)) & 7; + chr[index] = (chr[index] & (0xF0 >> (A & 4))) | ((V & 0x0F) << (A & 4)); + SyncChr(); + } else switch (A & 0xF80C) { + case 0x8800: prg[0] = V; SyncPrg(); break; + case 0xA800: prg[1] = V; SyncPrg(); break; + case 0xA000: prg[2] = V; SyncPrg(); break; + case 0x9800: mirr = V & 3; SyncMirr(); break; + case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break; + case 0xF004: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break; + case 0xF008: IRQa = V; if (!V) IRQPre = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF00C: IRQPre = 16; break; + } +} + +static void M183IRQCounter(void) { + if (IRQa) { + IRQCount++; + if ((IRQCount - IRQPre) == 238) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void M183Power(void) { + IRQPre = IRQCount = IRQa = 0; + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, M183Write); + SyncPrg(); + SyncChr(); +} + +void Mapper183_Init(CartInfo *info) { + info->Power = M183Power; + GameHBIRQHook = M183IRQCounter; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/185.cpp b/branches/fceux-2.2.2/src/boards/185.cpp new file mode 100644 index 00000000..756864ee --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/185.cpp @@ -0,0 +1,107 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 *DummyCHR = NULL; +static uint8 datareg; +static void (*Sync)(void); + + +static SFORMAT StateRegs[] = +{ + { &datareg, 1, "DREG" }, + { 0 } +}; + +// on off +//1 0x0F, 0xF0 - Bird Week +//2 0x33, 0x00 - B-Wings +//3 0x11, 0x00 - Mighty Bomb Jack +//4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen +//5 0xFF, 0x00 - Sansuu 3 Nen +//6 0x21, 0x13 - Spy vs Spy +//7 0x20, 0x21 - Seicross + +static void Sync185(void) { + // little dirty eh? ;_) + if ((datareg & 3) && (datareg != 0x13)) // 1, 2, 3, 4, 5, 6 + setchr8(0); + else + setchr8r(0x10, 0); +} + +static void Sync181(void) { + if (!(datareg & 1)) // 7 + setchr8(0); + else + setchr8r(0x10, 0); +} + +static DECLFW(MWrite) { + datareg = V; + Sync(); +} + +static void MPower(void) { + datareg = 0; + Sync(); + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + SetWriteHandler(0x8000, 0xFFFF, MWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void MClose(void) { + if (DummyCHR) + FCEU_gfree(DummyCHR); + DummyCHR = NULL; +} + +static void MRestore(int version) { + Sync(); +} + +void Mapper185_Init(CartInfo *info) { + Sync = Sync185; + info->Power = MPower; + info->Close = MClose; + GameStateRestore = MRestore; + DummyCHR = (uint8*)FCEU_gmalloc(8192); + int x; + for (x = 0; x < 8192; x++) + DummyCHR[x] = 0xff; + SetupCartCHRMapping(0x10, DummyCHR, 8192, 0); + AddExState(StateRegs, ~0, 0, 0); +} + +void Mapper181_Init(CartInfo *info) { + Sync = Sync181; + info->Power = MPower; + info->Close = MClose; + GameStateRestore = MRestore; + DummyCHR = (uint8*)FCEU_gmalloc(8192); + int x; + for (x = 0; x < 8192; x++) + DummyCHR[x] = 0xff; + SetupCartCHRMapping(0x10, DummyCHR, 8192, 0); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/186.cpp b/branches/fceux-2.2.2/src/boards/186.cpp new file mode 100644 index 00000000..137beaa9 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/186.cpp @@ -0,0 +1,94 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * Family Study Box by Fukutake Shoten + */ + +#include "mapinc.h" + +static uint8 SWRAM[3072]; +static uint8 *WRAM = NULL; +static uint8 regs[4]; + +static SFORMAT StateRegs[] = +{ + { regs, 4, "DREG" }, + { SWRAM, 3072, "SWRM" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, regs[0] >> 6); + setprg16(0x8000, regs[1]); + setprg16(0xc000, 0); +} + +static DECLFW(M186Write) { + if (A & 0x4203) regs[A & 3] = V; + Sync(); +} + +static DECLFR(M186Read) { + switch (A) { + case 0x4200: return 0x00; break; + case 0x4201: return 0x00; break; + case 0x4202: return 0x40; break; + case 0x4203: return 0x00; break; + } + return 0xFF; +} + +static DECLFR(ASWRAM) { + return(SWRAM[A - 0x4400]); +} +static DECLFW(BSWRAM) { + SWRAM[A - 0x4400] = V; +} + +static void M186Power(void) { + setchr8(0); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, CartBW); + SetReadHandler(0x4200, 0x43FF, M186Read); + SetWriteHandler(0x4200, 0x43FF, M186Write); + SetReadHandler(0x4400, 0x4FFF, ASWRAM); + SetWriteHandler(0x4400, 0x4FFF, BSWRAM); + regs[0] = regs[1] = regs[2] = regs[3]; + Sync(); +} + +static void M186Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void M186Restore(int version) { + Sync(); +} + +void Mapper186_Init(CartInfo *info) { + info->Power = M186Power; + info->Close = M186Close; + GameStateRestore = M186Restore; + WRAM = (uint8*)FCEU_gmalloc(32768); + SetupCartPRGMapping(0x10, WRAM, 32768, 1); + AddExState(WRAM, 32768, 0, "WRAM"); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/187.cpp b/branches/fceux-2.2.2/src/boards/187.cpp new file mode 100644 index 00000000..6e5baa2e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/187.cpp @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static void M187CW(uint32 A, uint8 V) { + if ((A & 0x1000) == ((MMC3_cmd & 0x80) << 5)) + setchr1(A, V | 0x100); + else + setchr1(A, V); +} + +static void M187PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x80) { + uint8 bank = EXPREGS[0] & 0x1F; + if (EXPREGS[0] & 0x20) { + if (EXPREGS[0] & 0x40) + setprg32(0x8000, bank >> 2); + else + setprg32(0x8000, bank >> 1); // hacky hacky! two mappers in one! need real hw carts to test + } else { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else + setprg8(A, V & 0x3F); +} + +static DECLFW(M187Write8000) { + EXPREGS[1] = 1; + MMC3_CMDWrite(A, V); +} + +static DECLFW(M187Write8001) { + if (EXPREGS[1]) + MMC3_CMDWrite(A, V); +} + +static DECLFW(M187WriteLo) { + if ((A == 0x5000) || (A == 0x6000)) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + } +} + +static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFR(M187Read) { + return prot_data[EXPREGS[1] & 3]; +} + +static void M187Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); + SetReadHandler(0x5000, 0x5FFF, M187Read); + SetWriteHandler(0x5000, 0x6FFF, M187WriteLo); + SetWriteHandler(0x8000, 0x8000, M187Write8000); + SetWriteHandler(0x8001, 0x8001, M187Write8001); +} + +void Mapper187_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = M187PW; + cwrap = M187CW; + info->Power = M187Power; + AddExState(EXPREGS, 3, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/189.cpp b/branches/fceux-2.2.2/src/boards/189.cpp new file mode 100644 index 00000000..fb60b1b8 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/189.cpp @@ -0,0 +1,44 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static void M189PW(uint32 A, uint8 V) { + setprg32(0x8000, EXPREGS[0] & 7); +} + +static DECLFW(M189Write) { + EXPREGS[0] = V | (V >> 4); //actually, there is a two versions of 189 mapper with hi or lo bits bankswitching. + FixMMC3PRG(MMC3_cmd); +} + +static void M189Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); + SetWriteHandler(0x4120, 0x7FFF, M189Write); +} + +void Mapper189_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = M189PW; + info->Power = M189Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/193.cpp b/branches/fceux-2.2.2/src/boards/193.cpp new file mode 100644 index 00000000..12e96a16 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/193.cpp @@ -0,0 +1,71 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, bank; + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { &mirror, 1, "MIRR" }, + { &bank, 1, "BANK" }, + { reg, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirror ^ 1); + setprg8(0x8000, reg[3]); + setprg8(0xA000, 0xD); + setprg8(0xC000, 0xE); + setprg8(0xE000, 0xF); + setchr4(0x0000, reg[0] >> 2); + setchr2(0x1000, reg[1] >> 1); + setchr2(0x1800, reg[2] >> 1); +} + +static DECLFW(M193Write) { + reg[A & 3] = V; + Sync(); +} + +static void M193Power(void) { + bank = 0; + Sync(); + SetWriteHandler(0x6000, 0x6003, M193Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, CartBW); +} + +static void M193Reset(void) { +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper193_Init(CartInfo *info) { + info->Reset = M193Reset; + info->Power = M193Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/199.cpp b/branches/fceux-2.2.2/src/boards/199.cpp new file mode 100644 index 00000000..2a8ad051 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/199.cpp @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 + * + * Dragon Ball Z 2 - Gekishin Freeza! (C) + * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C) + * San Guo Zhi 2 (C) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static void M199PW(uint32 A, uint8 V) { + setprg8(A, V); + setprg8(0xC000, EXPREGS[0]); + setprg8(0xE000, EXPREGS[1]); +} + +static void M199CW(uint32 A, uint8 V) { + setchr1r((V < 8) ? 0x10 : 0x00, A, V); + setchr1r((DRegBuf[0] < 8) ? 0x10 : 0x00, 0x0000, DRegBuf[0]); + setchr1r((EXPREGS[2] < 8) ? 0x10 : 0x00, 0x0400, EXPREGS[2]); + setchr1r((DRegBuf[1] < 8) ? 0x10 : 0x00, 0x0800, DRegBuf[1]); + setchr1r((EXPREGS[3] < 8) ? 0x10 : 0x00, 0x0c00, EXPREGS[3]); +} + +static void M199MW(uint8 V) { +// FCEU_printf("%02x\n",V); + switch (V & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M199Write) { + if ((A == 0x8001) && (MMC3_cmd & 8)) { + EXPREGS[MMC3_cmd & 3] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else + if (A < 0xC000) + MMC3_CMDWrite(A, V); + else + MMC3_IRQWrite(A, V); +} + +static void M199Power(void) { + EXPREGS[0] = ~1; + EXPREGS[1] = ~0; + EXPREGS[2] = 1; + EXPREGS[3] = 3; + GenMMC3Power(); + SetWriteHandler(0x8000, 0xFFFF, M199Write); +} + +static void M199Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +void Mapper199_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M199CW; + pwrap = M199PW; + mwrap = M199MW; + info->Power = M199Power; + info->Close = M199Close; + + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); + + AddExState(EXPREGS, 4, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/206.cpp b/branches/fceux-2.2.2/src/boards/206.cpp new file mode 100644 index 00000000..d013a8f1 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/206.cpp @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 cmd; +static uint8 DRegs[8]; + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { DRegs, 8, "DREG" }, + { 0 } +}; + +static void Sync(void) { + setchr2(0x0000, DRegs[0]); + setchr2(0x0800, DRegs[1]); + int x; + for (x = 0; x < 4; x++) + setchr1(0x1000 + (x << 10), DRegs[2 + x]); + setprg8(0x8000, DRegs[6]); + setprg8(0xa000, DRegs[7]); + setprg8(0xc000, ~1); + setprg8(0xe000, ~0); +} + +static void StateRestore(int version) { + Sync(); +} + +static DECLFW(M206Write) { + switch (A & 0x8001) { + case 0x8000: cmd = V & 0x07; break; + case 0x8001: + if (cmd <= 0x05) + V &= 0x3F; + else + V &= 0x0F; + if (cmd <= 0x01) V >>= 1; + DRegs[cmd & 0x07] = V; + Sync(); + break; + } +} + +static void M206Power(void) { + cmd = 0; + DRegs[6] = 0; + DRegs[7] = 1; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M206Write); +} + + +void Mapper206_Init(CartInfo *info) { + info->Power = M206Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/208.cpp b/branches/fceux-2.2.2/src/boards/208.cpp new file mode 100644 index 00000000..d581b1e8 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/208.cpp @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static uint8 lut[256] = { + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +static void M208PW(uint32 A, uint8 V) { + setprg32(0x8000, EXPREGS[5]); +} + +static DECLFW(M208Write) { + EXPREGS[5] = (V & 0x1) | ((V >> 3) & 0x2); + FixMMC3PRG(MMC3_cmd); +} + +static DECLFW(M208ProtWrite) { + if (A <= 0x57FF) + EXPREGS[4] = V; + else + EXPREGS[(A & 0x03)] = V ^ lut[EXPREGS[4]]; +} + +static DECLFR(M208ProtRead) { + return(EXPREGS[(A & 0x3)]); +} + +static void M208Power(void) { + EXPREGS[5] = 3; + GenMMC3Power(); + SetWriteHandler(0x4800, 0x4fff, M208Write); + SetWriteHandler(0x6800, 0x6fff, M208Write); + SetWriteHandler(0x5000, 0x5fff, M208ProtWrite); + SetReadHandler(0x5800, 0x5fff, M208ProtRead); + SetReadHandler(0x8000, 0xffff, CartBR); +} + +void Mapper208_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + pwrap = M208PW; + info->Power = M208Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/222.cpp b/branches/fceux-2.2.2/src/boards/222.cpp new file mode 100644 index 00000000..0db78c7b --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/222.cpp @@ -0,0 +1,99 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * (VRC4 mapper) + * + */ + +#include "mapinc.h" + +static uint8 IRQCount; +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; +static uint8 mirr; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 1, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { prg_reg, 2, "PRG" }, + { chr_reg, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void M222IRQ(void) { + if (IRQa) { + IRQCount++; + if (IRQCount >= 238) { + X6502_IRQBegin(FCEU_IQEXT); +// IRQa=0; + } + } +} + +static void Sync(void) { + setprg8(0x8000, prg_reg[0]); + setprg8(0xA000, prg_reg[1]); + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chr_reg[i]); + setmirror(mirr ^ 1); +} + +static DECLFW(M222Write) { + switch (A & 0xF003) { + case 0x8000: prg_reg[0] = V; break; + case 0x9000: mirr = V & 1; break; + case 0xA000: prg_reg[1] = V; break; + case 0xB000: chr_reg[0] = V; break; + case 0xB002: chr_reg[1] = V; break; + case 0xC000: chr_reg[2] = V; break; + case 0xC002: chr_reg[3] = V; break; + case 0xD000: chr_reg[4] = V; break; + case 0xD002: chr_reg[5] = V; break; + case 0xE000: chr_reg[6] = V; break; + case 0xE002: chr_reg[7] = V; break; +// case 0xF000: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break; +// case 0xF001: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQCount=V; break; +// case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; +// case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; +// case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; + case 0xF000: IRQa = IRQCount = V; if (scanline < 240) IRQCount -= 8; else IRQCount += 4; X6502_IRQEnd(FCEU_IQEXT); break; + } + Sync(); +} + +static void M222Power(void) { + setprg16(0xC000, ~0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M222Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper222_Init(CartInfo *info) { + info->Power = M222Power; + GameHBIRQHook = M222IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/225.cpp b/branches/fceux-2.2.2/src/boards/225.cpp new file mode 100644 index 00000000..9df7d518 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/225.cpp @@ -0,0 +1,86 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 prot[4], prg, mode, chr, mirr; + +static SFORMAT StateRegs[] = +{ + { prot, 4, "PROT" }, + { &prg, 1, "PRG" }, + { &chr, 1, "CHR" }, + { &mode, 1, "MODE" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + if (mode) { + setprg16(0x8000, prg); + setprg16(0xC000, prg); + } else + setprg32(0x8000, prg >> 1); + setchr8(chr); + setmirror(mirr); +} + +static DECLFW(M225Write) { + uint32 bank = (A >> 14) & 1; + mirr = (A >> 13) & 1; + mode = (A >> 12) & 1; + chr = (A & 0x3f) | (bank << 6); + prg = ((A >> 6) & 0x3f) | (bank << 6); + Sync(); +} + +static DECLFW(M225LoWrite) { +} + +static DECLFR(M225LoRead) { + return 0; +} + +static void M225Power(void) { + prg = 0; + mode = 0; + Sync(); + SetReadHandler(0x5000, 0x5FFF, M225LoRead); + SetWriteHandler(0x5000, 0x5FFF, M225LoWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M225Write); +} + +static void M225Reset(void) { + prg = 0; + mode = 0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper225_Init(CartInfo *info) { + info->Reset = M225Reset; + info->Power = M225Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/228.cpp b/branches/fceux-2.2.2/src/boards/228.cpp new file mode 100644 index 00000000..e64c6ace --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/228.cpp @@ -0,0 +1,85 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 mram[4], vreg; +static uint16 areg; + +static SFORMAT StateRegs[] = +{ + { mram, 4, "MRAM" }, + { &areg, 2, "AREG" }, + { &vreg, 1, "VREG" }, + { 0 } +}; + +static void Sync(void) { + uint32 prgl, prgh, page = (areg >> 7) & 0x3F; + if ((page & 0x30) == 0x30) + page -= 0x10; + prgl = prgh = (page << 1) + (((areg >> 6) & 1) & ((areg >> 5) & 1)); + prgh += ((areg >> 5) & 1) ^ 1; + + setmirror(((areg >> 13) & 1) ^ 1); + setprg16(0x8000,prgl); + setprg16(0xc000,prgh); + setchr8(((vreg & 0x3) | ((areg & 0xF) << 2))); +} + +static DECLFW(M228RamWrite) { + mram[A & 3] = V & 0x0F; +} + +static DECLFR(M228RamRead) { + return mram[A & 3]; +} + +static DECLFW(M228Write) { + areg = A; + vreg = V; + Sync(); +} + +static void M228Reset(void) { + areg = 0x8000; + vreg = 0; + memset(mram, 0, sizeof(mram)); + Sync(); +} + +static void M228Power(void) { + M228Reset(); + SetReadHandler(0x5000,0x5FFF,M228RamRead); + SetWriteHandler(0x5000,0x5FFF,M228RamWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M228Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper228_Init(CartInfo *info) { + info->Reset = M228Reset; + info->Power = M228Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/230.cpp b/branches/fceux-2.2.2/src/boards/230.cpp new file mode 100644 index 00000000..0da975dd --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/230.cpp @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2009 qeed + * + * 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 + * + * 22 + Contra Reset based custom mapper... + * + */ + +#include "mapinc.h" + +static uint8 latche, reset; +static SFORMAT StateRegs[] = +{ + { &reset, 1, "RST" }, + { &latche, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + if(reset) { + setprg16(0x8000, latche & 7); + setprg16(0xC000, 7); + setmirror(MI_V); + } else { + uint32 bank = (latche & 0x1F) + 8; + if (latche & 0x20) { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } else + setprg32(0x8000, bank >> 1); + setmirror((latche >> 6) & 1); + } + setchr8(0); +} + +static DECLFW(M230Write) { + latche = V; + Sync(); +} + +static void M230Reset(void) { + reset ^= 1; + Sync(); +} + +static void M230Power(void) { + latche = reset = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M230Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper230_Init(CartInfo *info) { + info->Power = M230Power; + info->Reset = M230Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/232.cpp b/branches/fceux-2.2.2/src/boards/232.cpp new file mode 100644 index 00000000..86bb0d04 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/232.cpp @@ -0,0 +1,68 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 bank, preg; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { +// uint32 bbank = (bank & 0x18) >> 1; + uint32 bbank = ((bank & 0x10) >> 2) | (bank & 8); // some dumps have bbanks swapped, if swap commands, + // then all roms can be played, but with some swapped + // games in menu. if not, some dumps are unplayable + // make hard dump for both cart types to check + setprg16(0x8000, bbank | (preg & 3)); + setprg16(0xC000, bbank | 3); + setchr8(0); +} + +static DECLFW(M232WriteBank) { + bank = V; + Sync(); +} + +static DECLFW(M232WritePreg) { + preg = V; + Sync(); +} + +static void M232Power(void) { + bank = preg = 0; + Sync(); + SetWriteHandler(0x8000, 0xBFFF, M232WriteBank); + SetWriteHandler(0xC000, 0xFFFF, M232WritePreg); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper232_Init(CartInfo *info) { + info->Power = M232Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/234.cpp b/branches/fceux-2.2.2/src/boards/234.cpp new file mode 100644 index 00000000..ef471238 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/234.cpp @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 bank, preg; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { + if (bank & 0x40) { + setprg32(0x8000, (bank & 0xE) | (preg & 1)); + setchr8(((bank & 0xE) << 2) | ((preg >> 4) & 7)); + } else { + setprg32(0x8000, bank & 0xF); + setchr8(((bank & 0xF) << 2) | ((preg >> 4) & 3)); + } + setmirror((bank >> 7) ^ 1); +} + +DECLFR(M234ReadBank) { + uint8 r = CartBR(A); + if (!bank) { + bank = r; + Sync(); + } + return r; +} + +DECLFR(M234ReadPreg) { + uint8 r = CartBR(A); + preg = r; + Sync(); + return r; +} + +static void M234Reset(void) { + bank = preg = 0; + Sync(); +} + +static void M234Power(void) { + M234Reset(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0xFF80, 0xFF9F, M234ReadBank); + SetReadHandler(0xFFE8, 0xFFF7, M234ReadPreg); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper234_Init(CartInfo *info) { + info->Power = M234Power; + info->Reset = M234Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/235.cpp b/branches/fceux-2.2.2/src/boards/235.cpp new file mode 100644 index 00000000..98ce11bb --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/235.cpp @@ -0,0 +1,63 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" + +static uint16 cmdreg; +static SFORMAT StateRegs[] = +{ + { &cmdreg, 2, "CREG" }, + { 0 } +}; + +static void Sync(void) { + if (cmdreg & 0x400) + setmirror(MI_0); + else + setmirror(((cmdreg >> 13) & 1) ^ 1); + if (cmdreg & 0x800) { + setprg16(0x8000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); + setprg16(0xC000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); + } else + setprg32(0x8000, ((cmdreg & 0x300) >> 4) | (cmdreg & 0x1F)); +} + +static DECLFW(M235Write) { + cmdreg = A; + Sync(); +} + +static void M235Power(void) { + setchr8(0); + SetWriteHandler(0x8000, 0xFFFF, M235Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + cmdreg = 0; + Sync(); +} + +static void M235Restore(int version) { + Sync(); +} + +void Mapper235_Init(CartInfo *info) { + info->Power = M235Power; + GameStateRestore = M235Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/244.cpp b/branches/fceux-2.2.2/src/boards/244.cpp new file mode 100644 index 00000000..67c33694 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/244.cpp @@ -0,0 +1,77 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 preg, creg; +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &creg, 1, "CREG" }, + { 0 } +}; + +static uint8 prg_perm[4][4] = { + { 0, 1, 2, 3, }, + { 3, 2, 1, 0, }, + { 0, 2, 1, 3, }, + { 3, 1, 2, 0, }, +}; + +static uint8 chr_perm[8][8] = { + { 0, 1, 2, 3, 4, 5, 6, 7, }, + { 0, 2, 1, 3, 4, 6, 5, 7, }, + { 0, 1, 4, 5, 2, 3, 6, 7, }, + { 0, 4, 1, 5, 2, 6, 3, 7, }, + { 0, 4, 2, 6, 1, 5, 3, 7, }, + { 0, 2, 4, 6, 1, 3, 5, 7, }, + { 7, 6, 5, 4, 3, 2, 1, 0, }, + { 7, 6, 5, 4, 3, 2, 1, 0, }, +}; + +static void Sync(void) { + setprg32(0x8000, preg); + setchr8(creg); +} + +static DECLFW(M244Write) { + if (V & 8) + creg = chr_perm[(V >> 4) & 7][V & 7]; + else + preg = prg_perm[(V >> 4) & 3][V & 3]; + Sync(); +} + +static void M244Power(void) { + preg = creg = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M244Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper244_Init(CartInfo *info) { + info->Power = M244Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/246.cpp b/branches/fceux-2.2.2/src/boards/246.cpp new file mode 100644 index 00000000..2c46acc7 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/246.cpp @@ -0,0 +1,86 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 regs[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg2r(0x10, 0x6800, 0); + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[1]); + setprg8(0xC000, regs[2]); + setprg8(0xE000, regs[3]); + setchr2(0x0000, regs[4]); + setchr2(0x0800, regs[5]); + setchr2(0x1000, regs[6]); + setchr2(0x1800, regs[7]); +} + +static DECLFW(M246Write) { + regs[A & 7] = V; + Sync(); +} + +static void M246Power(void) { + regs[0] = regs[1] = regs[2] = regs[3] = ~0; + Sync(); + SetWriteHandler(0x6000, 0x67FF, M246Write); + SetReadHandler(0x6800, 0x6FFF, CartBR); + SetWriteHandler(0x6800, 0x6FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M246Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper246_Init(CartInfo *info) { + info->Power = M246Power; + info->Close = M246Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 2048; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/252.cpp b/branches/fceux-2.2.2/src/boards/252.cpp new file mode 100644 index 00000000..2c4b24b1 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/252.cpp @@ -0,0 +1,134 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 creg[8], preg[2]; +static int32 IRQa, IRQCount, IRQClock, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { creg, 8, "CREG" }, + { preg, 2, "PREG" }, + { &IRQa, 4, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { &IRQClock, 4, "IRQK" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, preg[0]); + setprg8(0xa000, preg[1]); + setprg8(0xc000, ~1); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) + if ((creg[i] == 6) || (creg[i] == 7)) + setchr1r(0x10, i << 10, creg[i] & 1); + else + setchr1(i << 10, creg[i]); +} + +static DECLFW(M252Write) { + if ((A >= 0xB000) && (A <= 0xEFFF)) { + uint8 ind = ((((A & 8) | (A >> 8)) >> 3) + 2) & 7; + uint8 sar = A & 4; + creg[ind] = (creg[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + Sync(); + } else + switch (A & 0xF00C) { + case 0x8000: + case 0x8004: + case 0x8008: + case 0x800C: preg[0] = V; Sync(); break; + case 0xA000: + case 0xA004: + case 0xA008: + case 0xA00C: preg[1] = V; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; + case 0xF004: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; + case 0xF008: X6502_IRQEnd(FCEU_IQEXT); IRQClock = 0; IRQCount = IRQLatch; IRQa = V & 2; break; + } +} + +static void M252Power(void) { + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M252Write); +} + +static void M252IRQ(int a) { + #define LCYCS 341 + if (IRQa) { + IRQClock += a * 3; + if (IRQClock >= LCYCS) { + while (IRQClock >= LCYCS) { + IRQClock -= LCYCS; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } + } +} + +static void M252Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + if (CHRRAM) + FCEU_gfree(CHRRAM); + WRAM = CHRRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper252_Init(CartInfo *info) { + info->Power = M252Power; + info->Close = M252Close; + MapIRQHook = M252IRQ; + + CHRRAMSIZE = 2048; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/253.cpp b/branches/fceux-2.2.2/src/boards/253.cpp new file mode 100644 index 00000000..e79662a7 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/253.cpp @@ -0,0 +1,151 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock; +static int32 IRQa, IRQCount, IRQLatch, IRQClock; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { chrlo, 8, "CHRL" }, + { chrhi, 8, "CHRH" }, + { prg, 2, "PRGR" }, + { &mirr, 1, "MIRR" }, + { &vlock, 1, "VLCK" }, + { &IRQa, 4, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { &IRQClock, 4, "IRQK" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, prg[0]); + setprg8(0xa000, prg[1]); + setprg8(0xc000, ~1); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) { + uint32 chr = chrlo[i] | (chrhi[i] << 8); + if (((chrlo[i] == 4) || (chrlo[i] == 5)) && !vlock) + setchr1r(0x10, i << 10, chr & 1); + else + setchr1(i << 10, chr); + } + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M253Write) { + if ((A >= 0xB000) && (A <= 0xE00C)) { + uint8 ind = ((((A & 8) | (A >> 8)) >> 3) + 2) & 7; + uint8 sar = A & 4; + uint8 clo = (chrlo[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + chrlo[ind] = clo; + if (ind == 0) { + if (clo == 0xc8) + vlock = 0; + else if (clo == 0x88) + vlock = 1; + } + if (sar) + chrhi[ind] = V >> 4; + Sync(); + } else + switch (A) { + case 0x8010: prg[0] = V; Sync(); break; + case 0xA010: prg[1] = V; Sync(); break; + case 0x9400: mirr = V & 3; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; + case 0xF004: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; + case 0xF008: X6502_IRQEnd(FCEU_IQEXT); IRQClock = 0; IRQCount = IRQLatch; IRQa = V & 2; break; + } +} + +static void M253Power(void) { + vlock = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M253Write); +} + +static void M253Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + if (CHRRAM) + FCEU_gfree(CHRRAM); + WRAM = CHRRAM = NULL; +} + +static void M253IRQ(int a) { + #define LCYCS 341 + if (IRQa) { + IRQClock += a * 3; + if (IRQClock >= LCYCS) { + while (IRQClock >= LCYCS) { + IRQClock -= LCYCS; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper253_Init(CartInfo *info) { + info->Power = M253Power; + info->Close = M253Close; + MapIRQHook = M253IRQ; + GameStateRestore = StateRestore; + + CHRRAMSIZE = 2048; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/28.cpp b/branches/fceux-2.2.2/src/boards/28.cpp new file mode 100644 index 00000000..c787b8c3 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/28.cpp @@ -0,0 +1,216 @@ +/* + Copyright (C) 2012 FCEUX team + + This file 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 file 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 the this software. If not, see . +*/ + +#include "mapinc.h" + +// http://wiki.nesdev.com/w/index.php/INES_Mapper_028 + +//config +static int prg_mask_16k; + +// state +uint8 reg; +uint8 chr; +uint8 prg; +uint8 mode; +uint8 outer; + +void SyncMirror() +{ + switch (mode & 3) + { + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + } +} + +void Mirror(uint8 value) +{ + if ((mode & 2) == 0) + { + mode &= 0xfe; + mode |= value >> 4 & 1; + } + SyncMirror(); +} + + +static void Sync() +{ + int prglo; + int prghi; + + int outb = outer << 1; + //this can probably be rolled up, but i have no motivation to do so + //until it's been tested + switch (mode & 0x3c) + { + //32K modes + case 0x00: + case 0x04: + prglo = outb; + prghi = outb | 1; + break; + case 0x10: + case 0x14: + prglo = outb & ~2 | prg << 1 & 2; + prghi = outb & ~2 | prg << 1 & 2 | 1; + break; + case 0x20: + case 0x24: + prglo = outb & ~6 | prg << 1 & 6; + prghi = outb & ~6 | prg << 1 & 6 | 1; + break; + case 0x30: + case 0x34: + prglo = outb & ~14 | prg << 1 & 14; + prghi = outb & ~14 | prg << 1 & 14 | 1; + break; + //bottom fixed modes + case 0x08: + prglo = outb; + prghi = outb | prg & 1; + break; + case 0x18: + prglo = outb; + prghi = outb & ~2 | prg & 3; + break; + case 0x28: + prglo = outb; + prghi = outb & ~6 | prg & 7; + break; + case 0x38: + prglo = outb; + prghi = outb & ~14 | prg & 15; + break; + //top fixed modes + case 0x0c: + prglo = outb | prg & 1; + prghi = outb | 1; + break; + case 0x1c: + prglo = outb & ~2 | prg & 3; + prghi = outb | 1; + break; + case 0x2c: + prglo = outb & ~6 | prg & 7; + prghi = outb | 1; + break; + case 0x3c: + prglo = outb & ~14 | prg & 15; + prghi = outb | 1; + break; + } + prglo &= prg_mask_16k; + prghi &= prg_mask_16k; + + setprg16(0x8000, prglo); + setprg16(0xC000, prghi); + setchr8(chr); +} + +static DECLFW(WriteEXP) +{ + uint32 addr = A; + uint8 value = V; + reg = value & 0x81; +} + +static DECLFW(WritePRG) +{ + uint32 addr = A; + uint8 value = V; + switch (reg) + { + case 0x00: + chr = value & 3; + Mirror(value); + break; + case 0x01: + prg = value & 15; + Mirror(value); + Sync(); + break; + case 0x80: + mode = value & 63; + SyncMirror(); + Sync(); + break; + case 0x81: + outer = value & 63; + Sync(); + break; + } +} + + + +static void M28Reset(void) +{ + outer = 63; + prg = 15; + Sync(); +} + + +static void M28Power(void) +{ + prg_mask_16k = PRGsize[0] - 1; + + //EXP + SetWriteHandler(0x5000,0x5FFF,WriteEXP); + + //PRG + SetWriteHandler(0x8000,0xFFFF,WritePRG); + SetReadHandler(0x8000,0xFFFF,CartBR); + + //WRAM + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + + M28Reset(); +} + +static void M28Close(void) +{ +} + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {&chr, 1, "CHR"}, + {&prg, 1, "PRG"}, + {&mode, 1, "MODE"}, + {&outer, 1, "OUTR"}, + {0} +}; + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper28_Init(CartInfo* info) +{ + info->Power=M28Power; + info->Reset=M28Reset; + info->Close=M28Close; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/32.cpp b/branches/fceux-2.2.2/src/boards/32.cpp new file mode 100644 index 00000000..0c34402e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/32.cpp @@ -0,0 +1,102 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 preg[2], creg[8], mirr; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + uint16 swap = ((mirr & 2) << 13); + setmirror((mirr & 1) ^ 1); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000 ^ swap, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000 ^ swap, ~1); + setprg8(0xE000, ~0); + uint8 i; + for (i = 0; i < 8; i++) + setchr1(i << 10, creg[i]); +} + +static DECLFW(M32Write0) { + preg[0] = V; + Sync(); +} + +static DECLFW(M32Write1) { + mirr = V; + Sync(); +} + +static DECLFW(M32Write2) { + preg[1] = V; + Sync(); +} + +static DECLFW(M32Write3) { + creg[A & 7] = V; + Sync(); +} + +static void M32Power(void) { + Sync(); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x8FFF, M32Write0); + SetWriteHandler(0x9000, 0x9FFF, M32Write1); + SetWriteHandler(0xA000, 0xAFFF, M32Write2); + SetWriteHandler(0xB000, 0xBFFF, M32Write3); +} + +static void M32Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper32_Init(CartInfo *info) { + info->Power = M32Power; + info->Close = M32Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/33.cpp b/branches/fceux-2.2.2/src/boards/33.cpp new file mode 100644 index 00000000..daa6a773 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/33.cpp @@ -0,0 +1,117 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 is48; +static uint8 regs[8], mirr; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "PREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirr); + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + setchr2(0x0000, regs[2]); + setchr2(0x0800, regs[3]); + setchr1(0x1000, regs[4]); + setchr1(0x1400, regs[5]); + setchr1(0x1800, regs[6]); + setchr1(0x1C00, regs[7]); +} + +static DECLFW(M33Write) { + A &= 0xF003; + switch(A) { + case 0x8000: regs[0] = V & 0x3F; if(!is48) mirr = ((V >> 6) & 1) ^ 1; Sync(); break; + case 0x8001: regs[1] = V & 0x3F; Sync(); break; + case 0x8002: regs[2] = V; Sync(); break; + case 0x8003: regs[3] = V; Sync(); break; + case 0xA000: regs[4] = V; Sync(); break; + case 0xA001: regs[5] = V; Sync(); break; + case 0xA002: regs[6] = V; Sync(); break; + case 0xA003: regs[7] = V; Sync(); break; + } +} + +static DECLFW(M48Write) { + switch (A & 0xF003) { + case 0xC000: IRQLatch = V; break; + case 0xC001: IRQCount = IRQLatch; break; + case 0xC003: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xC002: IRQa = 1; break; + case 0xE000: mirr = ((V >> 6) & 1) ^ 1; Sync(); break; + } +} + +static void M33Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M33Write); +} + +static void M48Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, M33Write); + SetWriteHandler(0xC000, 0xFFFF, M48Write); +} + +static void M48IRQ(void) { + if (IRQa) { + IRQCount++; + if (IRQCount == 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper33_Init(CartInfo *info) { + is48 = 0; + info->Power = M33Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper48_Init(CartInfo *info) { + is48 = 1; + info->Power = M48Power; + GameHBIRQHook = M48IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/34.cpp b/branches/fceux-2.2.2/src/boards/34.cpp new file mode 100644 index 00000000..71f1b300 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/34.cpp @@ -0,0 +1,92 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * Many-in-one hacked mapper crap. + * + * Original BNROM is actually AxROM variations without mirroring control, + * and haven't SRAM on-board, so it must be removed from here + * + * Difficult banking is what NINA board doing, most hacks for 34 mapper are + * NINA hacks, so this is actually 34 mapper + * + */ + +#include "mapinc.h" + +static uint8 regs[3]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 3, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, regs[0]); + setchr4(0x0000, regs[1]); + setchr4(0x1000, regs[2]); +} + +static DECLFW(M34Write) { + if (A >= 0x8000) + regs[0] = V; + else + switch (A) { + case 0x7ffd: regs[0] = V; break; + case 0x7ffe: regs[1] = V; break; + case 0x7fff: regs[2] = V; break; + } + Sync(); +} + +static void M34Power(void) { + regs[0] = regs[1] = 0; + regs[2] = 1; + Sync(); + SetReadHandler(0x6000, 0x7ffc, CartBR); + SetWriteHandler(0x6000, 0x7ffc, CartBW); + SetReadHandler(0x8000, 0xffff, CartBR); + SetWriteHandler(0x7ffd, 0xffff, M34Write); +} + +static void M34Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper34_Init(CartInfo *info) { + info->Power = M34Power; + info->Close = M34Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/36.cpp b/branches/fceux-2.2.2/src/boards/36.cpp new file mode 100644 index 00000000..209d777e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/36.cpp @@ -0,0 +1,63 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * TXC/Micro Genius simplified mapper + */ + +#include "mapinc.h" + +static uint8 latche; + +static SFORMAT StateRegs[] = +{ + { &latche, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, latche >> 4); + setchr8(latche & 0xf); +} + +static DECLFW(M36Write) { + latche = V; + Sync(); +} + +static DECLFR(M36Read) { + return latche; // Need by Strike Wolf, being simplified mapper, this cart still uses some TCX mapper features andrely on it +} + +static void M36Power(void) { + latche = 0; + Sync(); + SetReadHandler(0x4100, 0x4100, M36Read); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFE, M36Write); // Actually, BUS conflict there preventing from triggering the wrong banks +} + +static void M36Restore(int version) { + Sync(); +} + +void Mapper36_Init(CartInfo *info) { + info->Power = M36Power; + GameStateRestore = M36Restore; + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/3d-block.cpp b/branches/fceux-2.2.2/src/boards/3d-block.cpp new file mode 100644 index 00000000..2a8b62cb --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/3d-block.cpp @@ -0,0 +1,95 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg[4], IRQa; +static int16 IRQCount, IRQPause; + +static int16 Count = 0x0000; + +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, 0); + setchr8(0); +} + +//#define Count 0x1800 +#define Pause 0x010 + +static DECLFW(UNL3DBlockWrite) { + switch (A) { +//4800 32 +//4900 37 +//4a00 01 +//4e00 18 + case 0x4800: reg[0] = V; break; + case 0x4900: reg[1] = V; break; + case 0x4a00: reg[2] = V; break; + case 0x4e00: reg[3] = V; IRQCount = Count; IRQPause = Pause; IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void UNL3DBlockPower(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4800, 0x4E00, UNL3DBlockWrite); +} + +static void UNL3DBlockReset(void) { + Count += 0x10; + FCEU_printf("Count=%04x\n", Count); +} + +static void UNL3DBlockIRQHook(int a) { + if (IRQa) { + if (IRQCount > 0) { + IRQCount -= a; + } else { + if (IRQPause > 0) { + IRQPause -= a; + X6502_IRQBegin(FCEU_IQEXT); + } else { + IRQCount = Count; + IRQPause = Pause; + X6502_IRQEnd(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void UNL3DBlock_Init(CartInfo *info) { + info->Power = UNL3DBlockPower; + info->Reset = UNL3DBlockReset; + MapIRQHook = UNL3DBlockIRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/40.cpp b/branches/fceux-2.2.2/src/boards/40.cpp new file mode 100644 index 00000000..5cae497d --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/40.cpp @@ -0,0 +1,86 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, ~1); + setprg8(0x8000, ~3); + setprg8(0xa000, ~2); + setprg8(0xc000, reg); + setprg8(0xe000, ~0); + setchr8(0); +} + +static DECLFW(M40Write) { + switch (A & 0xe000) { + case 0x8000: IRQa = 0; IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xa000: IRQa = 1; break; + case 0xe000: reg = V & 7; Sync(); break; + } +} + +static void M40Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x8000, 0xffff, M40Write); +} + +static void M40Reset(void) { +} + +static void M40IRQHook(int a) { + if (IRQa) { + if (IRQCount < 4096) + IRQCount += a; + else{ + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper40_Init(CartInfo *info) { + info->Reset = M40Reset; + info->Power = M40Power; + MapIRQHook = M40IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/41.cpp b/branches/fceux-2.2.2/src/boards/41.cpp new file mode 100644 index 00000000..d0d90839 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/41.cpp @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 mainreg, chrreg, mirror; + +static SFORMAT StateRegs[] = +{ + { &mainreg, 1, "MREG" }, + { &chrreg, 1, "CREG" }, + { &mirror, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, mainreg & 7); + setchr8(chrreg); + setmirror(mirror); +} + +static DECLFW(M41Write0) { + mainreg = A & 0xFF; + mirror = ((A >> 5) & 1) ^ 1; + chrreg = (chrreg & 3) | ((A >> 1) & 0xC); + Sync(); +} + +static DECLFW(M41Write1) { + if (mainreg & 0x4) { + chrreg = (chrreg & 0xC) | (A & 3); + Sync(); + } +} + +static void M41Power(void) { + mainreg = chrreg = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x67FF, M41Write0); + SetWriteHandler(0x8000, 0xFFFF, M41Write1); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper41_Init(CartInfo *info) { + info->Power = M41Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/411120-c.cpp b/branches/fceux-2.2.2/src/boards/411120-c.cpp new file mode 100644 index 00000000..ccc490e8 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/411120-c.cpp @@ -0,0 +1,64 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * 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 + */ + +// actually cart ID is 811120-C, sorry ;) K-3094 - another ID + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0; + +static void BMC411120CCW(uint32 A, uint8 V) { + setchr1(A, V | ((EXPREGS[0] & 3) << 7)); +} + +static void BMC411120CPW(uint32 A, uint8 V) { + if (EXPREGS[0] & (8 | reset_flag)) + setprg32(0x8000, ((EXPREGS[0] >> 4) & 3) | (0x0C)); + else + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 3) << 4)); +} + +static DECLFW(BMC411120CLoWrite) { + EXPREGS[0] = A; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC411120CReset(void) { + EXPREGS[0] = 0; + reset_flag ^= 4; + MMC3RegReset(); +} + +static void BMC411120CPower(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, BMC411120CLoWrite); +} + +void BMC411120C_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap = BMC411120CPW; + cwrap = BMC411120CCW; + info->Power = BMC411120CPower; + info->Reset = BMC411120CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/42.cpp b/branches/fceux-2.2.2/src/boards/42.cpp new file mode 100644 index 00000000..87608574 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/42.cpp @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 preg, creg, mirr; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &creg, 1, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, preg); + setprg32(0x8000, ~0); + setchr8(creg); + setmirror(mirr); +} + +static DECLFW(M42Write) { + switch (A & 0xE003) { + case 0x8000: creg = V; Sync(); break; + case 0xE000: preg = V & 0x0F; Sync(); break; + case 0xE001: mirr = ((V >> 3) & 1 ) ^ 1; Sync(); break; + case 0xE002: IRQa = V & 2; if (!IRQa) IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void M42Power(void) { + preg = 0; + mirr = 1; // Ai Senshi Nicol actually has fixed mirroring, but mapper forcing it's default value now + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x6000, 0xffff, M42Write); +} + +static void M42IRQHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount >= 32768) IRQCount -= 32768; + if (IRQCount >= 24576) + X6502_IRQBegin(FCEU_IQEXT); + else + X6502_IRQEnd(FCEU_IQEXT); + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper42_Init(CartInfo *info) { + info->Power = M42Power; + MapIRQHook = M42IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/43.cpp b/branches/fceux-2.2.2/src/boards/43.cpp new file mode 100644 index 00000000..396f80e2 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/43.cpp @@ -0,0 +1,91 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, swap; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { ®, 1, "REG" }, + { &swap, 1, "SWAP" }, + { 0 } +}; + +static void Sync(void) { + setprg4(0x5000, 8 << 1); // Only YS-612 advanced version + setprg8(0x6000, swap?0:2); + setprg8(0x8000, 1); + setprg8(0xa000, 0); + setprg8(0xc000, reg); + setprg8(0xe000, swap?8:9); // hard dump for mr.Mary is 128K, + // bank 9 is the last 2K ok bank 8 repeated 4 times, then till the end of 128K + // instead used bank A, containing some CHR data, ines rom have unused banks removed, + // and bank A moved to the bank 9 place for compatibility with other crappy dumps + setchr8(0); +} + +static DECLFW(M43Write) { +// int transo[8]={4,3,4,4,4,7,5,6}; + int transo[8] = { 4, 3, 5, 3, 6, 3, 7, 3 }; // According to hardware tests + switch (A & 0xf1ff) { + case 0x4022: reg = transo[V & 7]; Sync(); break; + case 0x4120: swap = V & 1; Sync(); break; + case 0x8122: // hacked version + case 0x4122: IRQa = V & 1; X6502_IRQEnd(FCEU_IQEXT); IRQCount = 0; break; // original version + } +} + +static void M43Power(void) { + reg = swap = 0; + Sync(); + SetReadHandler(0x5000, 0xffff, CartBR); + SetWriteHandler(0x4020, 0xffff, M43Write); +} + +static void M43Reset(void) { +} + +static void M43IRQHook(int a) { + IRQCount += a; + if (IRQa) + if (IRQCount >= 4096) { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper43_Init(CartInfo *info) { + info->Reset = M43Reset; + info->Power = M43Power; + MapIRQHook = M43IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/46.cpp b/branches/fceux-2.2.2/src/boards/46.cpp new file mode 100644 index 00000000..04e03122 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/46.cpp @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg0, reg1; + +static SFORMAT StateRegs[] = +{ + { ®0, 1, "REG0" }, + { ®1, 1, "REG1" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, (reg1 & 1) + ((reg0 & 0xF) << 1)); + setchr8(((reg1 >> 4) & 7) + ((reg0 & 0xF0) >> 1)); +} + +static DECLFW(M46Write0) { + reg0 = V; + Sync(); +} + +static DECLFW(M46Write1) { + reg1 = V; + Sync(); +} + +static void M46Power(void) { + reg0 = reg1 = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, M46Write0); + SetWriteHandler(0x8000, 0xFFFF, M46Write1); +} + +static void M46Reset(void) { + reg0 = reg1 = 0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper46_Init(CartInfo *info) { + info->Power = M46Power; + info->Reset = M46Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/50.cpp b/branches/fceux-2.2.2/src/boards/50.cpp new file mode 100644 index 00000000..40a8e42a --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/50.cpp @@ -0,0 +1,85 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, 0xF); + setprg8(0x8000, 0x8); + setprg8(0xa000, 0x9); + setprg8(0xc000, reg); + setprg8(0xe000, 0xB); + setchr8(0); +} + +static DECLFW(M50Write) { + switch (A & 0xD160) { + case 0x4120: IRQa = V & 1; if (!IRQa) IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x4020: reg = ((V & 1) << 2) | ((V & 2) >> 1) | ((V & 4) >> 1) | (V & 8); Sync(); break; + } +} + +static void M50Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x4020, 0x5fff, M50Write); +} + +static void M50Reset(void) { +} + +static void M50IRQHook(int a) { + if (IRQa) { + if (IRQCount < 4096) + IRQCount += a; + else{ + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper50_Init(CartInfo *info) { + info->Reset = M50Reset; + info->Power = M50Power; + MapIRQHook = M50IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/51.cpp b/branches/fceux-2.2.2/src/boards/51.cpp new file mode 100644 index 00000000..02d693c3 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/51.cpp @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 bank, mode; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &mode, 1, "MODE" }, + { 0 } +}; + +static void Sync(void) { + if (mode & 2) { + setprg8(0x6000, ((bank & 7) << 2) | 0x23); + setprg16(0x8000, (bank << 1) | 0); + setprg16(0xC000, (bank << 1) | 1); + } else { + setprg8(0x6000, ((bank & 4) << 2) | 0x2F); + setprg16(0x8000, (bank << 1) | (mode >> 4)); + setprg16(0xC000, ((bank & 0xC) << 1) | 7); + } + if (mode == 0x12) + setmirror(MI_H); + else + setmirror(MI_V); + setchr8(0); +} + +static DECLFW(M51WriteMode) { + mode = V & 0x12; + Sync(); +} + +static DECLFW(M51WriteBank) { + bank = V & 0x0F; + if (A & 0x4000) + mode = (mode & 2) | (V & 0x10); + Sync(); +} + +static void M51Power(void) { + bank = 0; + mode = 2; + Sync(); + SetWriteHandler(0x6000, 0x7FFF, M51WriteMode); + SetWriteHandler(0x8000, 0xFFFF, M51WriteBank); + SetReadHandler(0x6000, 0xFFFF, CartBR); +} + +static void M51Reset(void) { + bank = 0; + mode = 2; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper51_Init(CartInfo *info) { + info->Power = M51Power; + info->Reset = M51Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/57.cpp b/branches/fceux-2.2.2/src/boards/57.cpp new file mode 100644 index 00000000..4d2b5105 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/57.cpp @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 prg_reg; +static uint8 chr_reg; +static uint8 hrd_flag; + +static SFORMAT StateRegs[] = +{ + { &hrd_flag, 1, "DPSW" }, + { &prg_reg, 1, "PRG" }, + { &chr_reg, 1, "CHR" }, + { 0 } +}; + +static void Sync(void) { + if (prg_reg & 0x80) + setprg32(0x8000, prg_reg >> 6); + else{ + setprg16(0x8000, (prg_reg >> 5) & 3); + setprg16(0xC000, (prg_reg >> 5) & 3); + } + setmirror((prg_reg & 8) >> 3); + setchr8((chr_reg & 3) | (prg_reg & 7) | ((prg_reg & 0x10) >> 1)); +} + +static DECLFR(M57Read) { + return hrd_flag; +} + +static DECLFW(M57Write) { + if ((A & 0x8800) == 0x8800) + prg_reg = V; + else + chr_reg = V; + Sync(); +} + +static void M57Power(void) { + prg_reg = 0; + chr_reg = 0; + hrd_flag = 0; + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M57Write); + SetReadHandler(0x6000, 0x6000, M57Read); + Sync(); +} + +static void M57Reset() { + hrd_flag++; + hrd_flag &= 3; + FCEU_printf("Select Register = %02x\n", hrd_flag); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper57_Init(CartInfo *info) { + info->Power = M57Power; + info->Reset = M57Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/603-5052.cpp b/branches/fceux-2.2.2/src/boards/603-5052.cpp new file mode 100644 index 00000000..cf13a449 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/603-5052.cpp @@ -0,0 +1,44 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static uint8 lut[4] = { 0x00, 0x02, 0x02, 0x03 }; + +static DECLFW(UNL6035052ProtWrite) { + EXPREGS[0] = lut[V & 3]; +} + +static DECLFR(UNL6035052ProtRead) { + return EXPREGS[0]; +} + +static void UNL6035052Power(void) { + GenMMC3Power(); + SetWriteHandler(0x4020, 0x7FFF, UNL6035052ProtWrite); + SetReadHandler(0x4020, 0x7FFF, UNL6035052ProtRead); +} + +void UNL6035052_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power = UNL6035052Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/62.cpp b/branches/fceux-2.2.2/src/boards/62.cpp new file mode 100644 index 00000000..0dc2a63d --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/62.cpp @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 bank; +static uint16 mode; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &mode, 2, "MODE" }, + { 0 } +}; + +static void Sync(void) { + setchr8(((mode & 0x1F) << 2) | (bank & 0x03)); + if (mode & 0x20) { + setprg16(0x8000, (mode & 0x40) | ((mode >> 8) & 0x3F)); + setprg16(0xc000, (mode & 0x40) | ((mode >> 8) & 0x3F)); + } else + setprg32(0x8000, ((mode & 0x40) | ((mode >> 8) & 0x3F)) >> 1); + setmirror(((mode >> 7) & 1) ^ 1); +} + +static DECLFW(M62Write) { + mode = A & 0x3FFF; + bank = V & 3; + Sync(); +} + +static void M62Power(void) { + bank = mode = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M62Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M62Reset(void) { + bank = mode = 0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper62_Init(CartInfo *info) { + info->Power = M62Power; + info->Reset = M62Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/65.cpp b/branches/fceux-2.2.2/src/boards/65.cpp new file mode 100644 index 00000000..fbfd6677 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/65.cpp @@ -0,0 +1,105 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 preg[3], creg[8], mirr; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { preg, 3, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirr); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + setchr1(0x0000, creg[0]); + setchr1(0x0400, creg[1]); + setchr1(0x0800, creg[2]); + setchr1(0x0C00, creg[3]); + setchr1(0x1000, creg[4]); + setchr1(0x1400, creg[5]); + setchr1(0x1800, creg[6]); + setchr1(0x1C00, creg[7]); + setmirror(mirr); +} + +static DECLFW(M65Write) { + switch (A) { + case 0x8000: preg[0] = V; Sync(); break; + case 0xA000: preg[1] = V; Sync(); break; + case 0xC000: preg[2] = V; Sync(); break; + case 0x9001: mirr = ((V >> 7) & 1) ^ 1; Sync(); break; + case 0x9003: IRQa = V & 0x80; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x9004: IRQCount = IRQLatch; break; + case 0x9005: IRQLatch &= 0x00FF; IRQLatch |= V << 8; break; + case 0x9006: IRQLatch &= 0xFF00; IRQLatch |= V; break; + case 0xB000: creg[0] = V; Sync(); break; + case 0xB001: creg[1] = V; Sync(); break; + case 0xB002: creg[2] = V; Sync(); break; + case 0xB003: creg[3] = V; Sync(); break; + case 0xB004: creg[4] = V; Sync(); break; + case 0xB005: creg[5] = V; Sync(); break; + case 0xB006: creg[6] = V; Sync(); break; + case 0xB007: creg[7] = V; Sync(); break; + } +} + +static void M65Power(void) { + preg[2] = ~1; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M65Write); +} + +void M65IRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount < -4) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = -1; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper65_Init(CartInfo *info) { + info->Power = M65Power; + MapIRQHook = M65IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/67.cpp b/branches/fceux-2.2.2/src/boards/67.cpp new file mode 100644 index 00000000..4e29edbf --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/67.cpp @@ -0,0 +1,106 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 preg, creg[4], mirr, suntoggle = 0; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &suntoggle, 1, "STOG" }, + { creg, 4, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirr); + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr2(0x0000, creg[0]); + setchr2(0x0800, creg[1]); + setchr2(0x1000, creg[2]); + setchr2(0x1800, creg[3]); + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M67Write) { + switch (A & 0xF800) { + case 0x8800: creg[0] = V; Sync(); break; + case 0x9800: creg[1] = V; Sync(); break; + case 0xA800: creg[2] = V; Sync(); break; + case 0xB800: creg[3] = V; Sync(); break; + case 0xC000: + case 0xC800: + IRQCount &= 0xFF << (suntoggle << 3); + IRQCount |= V << ((suntoggle ^ 1) << 3); + suntoggle ^= 1; + break; + case 0xD800: + suntoggle = 0; + IRQa = V & 0x10; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xE800: mirr = V & 3; Sync(); break; + case 0xF800: preg = V; Sync(); break; + } +} + +static void M67Power(void) { + suntoggle = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M67Write); +} + +void M67IRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = -1; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper67_Init(CartInfo *info) { + info->Power = M67Power; + MapIRQHook = M67IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/68.cpp b/branches/fceux-2.2.2/src/boards/68.cpp new file mode 100644 index 00000000..a38e567e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/68.cpp @@ -0,0 +1,163 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 chr_reg[4]; +static uint8 kogame, prg_reg, nt1, nt2, mirr; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE, count; + +static SFORMAT StateRegs[] = +{ + { &nt1, 1, "NT1" }, + { &nt2, 1, "NT2" }, + { &mirr, 1, "MIRR" }, + { &prg_reg, 1, "PRG" }, + { &kogame, 1, "KGME" }, + { &count, 4, "CNT" }, + { chr_reg, 4, "CHR" }, + { 0 } +}; + +static void M68NTfix(void) { + if ((!UNIFchrrama) && (mirr & 0x10)) { + PPUNTARAM = 0; + switch (mirr & 3) { + case 0: + vnapage[0] = vnapage[2] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); + vnapage[1] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); + break; + case 1: + vnapage[0] = vnapage[1] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); + vnapage[2] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); + break; + case 2: + vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); + break; + case 3: + vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); + break; + } + } else + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static void Sync(void) { + setchr2(0x0000, chr_reg[0]); + setchr2(0x0800, chr_reg[1]); + setchr2(0x1000, chr_reg[2]); + setchr2(0x1800, chr_reg[3]); + setprg8r(0x10, 0x6000, 0); + setprg16r((PRGptr[1]) ? kogame : 0, 0x8000, prg_reg); + setprg16(0xC000, ~0); +} + +static DECLFR(M68Read) { + if (!(kogame & 8)) { + count++; + if (count == 1784) + setprg16r(0, 0x8000, prg_reg); + } + return CartBR(A); +} + +static DECLFW(M68WriteLo) { + if (!V) { + count = 0; + setprg16r((PRGptr[1]) ? kogame : 0, 0x8000, prg_reg); + } + CartBW(A, V); +} + +static DECLFW(M68WriteCHR) { + chr_reg[(A >> 12) & 3] = V; + Sync(); +} + +static DECLFW(M68WriteNT1) { + nt1 = V; + M68NTfix(); +} + +static DECLFW(M68WriteNT2) { + nt2 = V; + M68NTfix(); +} + +static DECLFW(M68WriteMIR) { + mirr = V; + M68NTfix(); +} + +static DECLFW(M68WriteROM) { + prg_reg = V & 7; + kogame = ((V >> 3) & 1) ^ 1; + Sync(); +} + +static void M68Power(void) { + prg_reg = 0; + kogame = 0; + Sync(); + M68NTfix(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xBFFF, M68Read); + SetReadHandler(0xC000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, M68WriteCHR); + SetWriteHandler(0xC000, 0xCFFF, M68WriteNT1); + SetWriteHandler(0xD000, 0xDFFF, M68WriteNT2); + SetWriteHandler(0xE000, 0xEFFF, M68WriteMIR); + SetWriteHandler(0xF000, 0xFFFF, M68WriteROM); + SetWriteHandler(0x6000, 0x6000, M68WriteLo); + SetWriteHandler(0x6001, 0x7FFF, CartBW); +} + +static void M68Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); + M68NTfix(); +} + +void Mapper68_Init(CartInfo *info) { + info->Power = M68Power; + info->Close = M68Close; + GameStateRestore = StateRestore; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/69.cpp b/branches/fceux-2.2.2/src/boards/69.cpp new file mode 100644 index 00000000..c289c9df --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/69.cpp @@ -0,0 +1,278 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 cmdreg, preg[4], creg[8], mirr; +static uint8 IRQa; +static int32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &cmdreg, 1, "CMDR" }, + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + if ((preg[3] & 0xC0) == 0xC0) + setprg8r(0x10, 0x6000, 0); + else + setprg8(0x6000, preg[3] & 0x3F); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, creg[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M69WRAMWrite) { + if ((preg[3] & 0xC0) == 0xC0) + CartBW(A, V); +} + +static DECLFR(M69WRAMRead) { + if ((preg[3] & 0xC0) == 0x40) + return X.DB; + else + return CartBR(A); +} + +static DECLFW(M69Write0) { + cmdreg = V & 0xF; +} + +static DECLFW(M69Write1) { + switch (cmdreg) { + case 0x0: creg[0] = V; Sync(); break; + case 0x1: creg[1] = V; Sync(); break; + case 0x2: creg[2] = V; Sync(); break; + case 0x3: creg[3] = V; Sync(); break; + case 0x4: creg[4] = V; Sync(); break; + case 0x5: creg[5] = V; Sync(); break; + case 0x6: creg[6] = V; Sync(); break; + case 0x7: creg[7] = V; Sync(); break; + case 0x8: preg[3] = V; Sync(); break; + case 0x9: preg[0] = V; Sync(); break; + case 0xA: preg[1] = V; Sync(); break; + case 0xB: preg[2] = V; Sync(); break; + case 0xC: mirr = V & 3; Sync();break; + case 0xD: IRQa = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xE: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF: IRQCount &= 0x00FF; IRQCount |= V << 8; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +// SUNSOFT-5/FME-7 Sound + +static void AYSound(int Count); +static void AYSoundHQ(void); +static void DoAYSQ(int x); +static void DoAYSQHQ(int x); + +static uint8 sndcmd, sreg[14]; +static int32 vcount[3]; +static int32 dcount[3]; +static int CAYBC[3]; + +static SFORMAT SStateRegs[] = +{ + { &sndcmd, 1, "SCMD" }, + { sreg, 14, "SREG" }, + { 0 } +}; + +static DECLFW(M69SWrite0) { + sndcmd = V % 14; +} + +static DECLFW(M69SWrite1) { + int x; + GameExpSound.Fill = AYSound; + GameExpSound.HiFill = AYSoundHQ; + if (FSettings.SndRate) + switch (sndcmd) { + case 0: + case 1: + case 8: if (FSettings.soundq >= 1) DoAYSQHQ(0); else DoAYSQ(0); break; + case 2: + case 3: + case 9: if (FSettings.soundq >= 1) DoAYSQHQ(1); else DoAYSQ(1); break; + case 4: + case 5: + case 10: if (FSettings.soundq >= 1) DoAYSQHQ(2); else DoAYSQ(2); break; + case 7: + for (x = 0; x < 2; x++) + if (FSettings.soundq >= 1) DoAYSQHQ(x); else DoAYSQ(x); + break; + } + sreg[sndcmd] = V; +} + +static void DoAYSQ(int x) { + int32 freq = ((sreg[x << 1] | ((sreg[(x << 1) + 1] & 15) << 8)) + 1) << (4 + 17); + int32 amp = (sreg[0x8 + x] & 15) << 2; + int32 start, end; + int V; + + amp += amp >> 1; + + start = CAYBC[x]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + CAYBC[x] = end; + + if (amp && !(sreg[0x7] & (1 << x))) + for (V = start; V < end; V++) { + if (dcount[x]) + Wave[V >> 4] += amp; + vcount[x] -= nesincsize; + while (vcount[x] <= 0) { + dcount[x] ^= 1; + vcount[x] += freq; + } + } +} + +static void DoAYSQHQ(int x) { + uint32 V; + int32 freq = ((sreg[x << 1] | ((sreg[(x << 1) + 1] & 15) << 8)) + 1) << 4; + int32 amp = (sreg[0x8 + x] & 15) << 6; + + amp += amp >> 1; + + if (!(sreg[0x7] & (1 << x))) { + for (V = CAYBC[x]; V < SOUNDTS; V++) { + if (dcount[x]) + WaveHi[V] += amp; + vcount[x]--; + if (vcount[x] <= 0) { + dcount[x] ^= 1; + vcount[x] = freq; + } + } + } + CAYBC[x] = SOUNDTS; +} + +static void AYSound(int Count) { + int x; + DoAYSQ(0); + DoAYSQ(1); + DoAYSQ(2); + for (x = 0; x < 3; x++) + CAYBC[x] = Count; +} + +static void AYSoundHQ(void) { + DoAYSQHQ(0); + DoAYSQHQ(1); + DoAYSQHQ(2); +} + +static void AYHiSync(int32 ts) { + int x; + + for (x = 0; x < 3; x++) + CAYBC[x] = ts; +} + +void Mapper69_ESI(void) { + GameExpSound.RChange = Mapper69_ESI; + GameExpSound.HiSync = AYHiSync; + memset(dcount, 0, sizeof(dcount)); + memset(vcount, 0, sizeof(vcount)); + memset(CAYBC, 0, sizeof(CAYBC)); + AddExState(&SStateRegs, ~0, 0, 0); +} + +// SUNSOFT-5/FME-7 Sound + +static void M69Power(void) { + cmdreg = sndcmd = 0; + IRQCount = 0xFFFF; + IRQa = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, M69WRAMRead); + SetWriteHandler(0x6000, 0x7FFF, M69WRAMWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x9FFF, M69Write0); + SetWriteHandler(0xA000, 0xBFFF, M69Write1); + SetWriteHandler(0xC000, 0xDFFF, M69SWrite0); + SetWriteHandler(0xE000, 0xFFFF, M69SWrite1); +} + +static void M69Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void M69IRQHook(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); IRQa = 0; IRQCount = 0xFFFF; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper69_Init(CartInfo *info) { + info->Power = M69Power; + info->Close = M69Close; + MapIRQHook = M69IRQHook; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + Mapper69_ESI(); + AddExState(&StateRegs, ~0, 0, 0); +} + +void NSFAY_Init(void) { + sndcmd = 0; + SetWriteHandler(0xC000, 0xDFFF, M69SWrite0); + SetWriteHandler(0xE000, 0xFFFF, M69SWrite1); + Mapper69_ESI(); +} diff --git a/branches/fceux-2.2.2/src/boards/71.cpp b/branches/fceux-2.2.2/src/boards/71.cpp new file mode 100644 index 00000000..37c05aab --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/71.cpp @@ -0,0 +1,64 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 preg, mirr; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr8(0); + if(mirr) + setmirror(mirr); +} + +static DECLFW(M71Write) { + if ((A & 0xF000) == 0x9000) + mirr = MI_0 + ((V >> 4) & 1); // 2-in-1, some carts are normal hardwire V/H mirror, some uses mapper selectable 0/1 mirror + else + preg = V; + Sync(); +} + +static void M71Power(void) { + mirr = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M71Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper71_Init(CartInfo *info) { + info->Power = M71Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/72.cpp b/branches/fceux-2.2.2/src/boards/72.cpp new file mode 100644 index 00000000..de5ec91d --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/72.cpp @@ -0,0 +1,64 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * Moero!! Pro Tennis have ADPCM codec on-board, PROM isn't dumped, emulation isn't + * possible just now. + */ + +#include "mapinc.h" + +static uint8 preg, creg; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &creg, 1, "CREG" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr8(creg); +} + +static DECLFW(M72Write) { + if (V & 0x80) + preg = V & 0xF; + if (V & 0x40) + creg = V & 0xF; + Sync(); +} + +static void M72Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, M72Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper72_Init(CartInfo *info) { + info->Power = M72Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/77.cpp b/branches/fceux-2.2.2/src/boards/77.cpp new file mode 100644 index 00000000..bbba3e8f --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/77.cpp @@ -0,0 +1,75 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 latche; + +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &latche, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, latche & 7); + setchr2(0x0000, latche >> 4); + setchr2r(0x10, 0x0800, 2); + setchr4r(0x10, 0x1000, 0); +} + +static DECLFW(M77Write) { + latche = V; + Sync(); +} + +static void M77Power(void) { + latche = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M77Write); +} + +static void M77Close(void) +{ + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper77_Init(CartInfo *info) { + info->Power = M77Power; + info->Close = M77Close; + GameStateRestore = StateRestore; + + CHRRAMSIZE = 6 * 1024; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/79.cpp b/branches/fceux-2.2.2/src/boards/79.cpp new file mode 100644 index 00000000..14d9ac79 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/79.cpp @@ -0,0 +1,61 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 creg, preg; +static SFORMAT StateRegs[] = +{ + { &creg, 1, "CREG" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, preg); + setchr8(creg); +} + +static DECLFW(M79Write) { + if ((A < 0x8000) && ((A ^ 0x4100) == 0)) { + preg = (V >> 3) & 1; + } + creg = V & 7; + Sync(); +} + +static void M79Power(void) { + preg = ~0; + Sync(); + SetWriteHandler(0x4100, 0x5FFF, M79Write); + SetWriteHandler(0x8000, 0xFFFF, M79Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper79_Init(CartInfo *info) { + info->Power = M79Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/80.cpp b/branches/fceux-2.2.2/src/boards/80.cpp new file mode 100644 index 00000000..b99132c2 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/80.cpp @@ -0,0 +1,193 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 preg[3], creg[6], isExMirr; +static uint8 mirr, cmd, wram_enable, wram[256]; +static uint8 mcache[8]; +static uint32 lastppu; + +static SFORMAT StateRegs80[] = +{ + { preg, 3, "PREG" }, + { creg, 6, "CREG" }, + { wram, 256, "WRAM" }, + { &mirr, 1, "MIRR" }, + { &wram_enable, 1, "WRME" }, + { 0 } +}; + +static SFORMAT StateRegs95[] = +{ + { &cmd, 1, "CMDR" }, + { preg, 3, "PREG" }, + { creg, 6, "CREG" }, + { mcache, 8, "MCCH" }, + { &lastppu, 4, "LPPU" }, + { 0 } +}; + +static SFORMAT StateRegs207[] = +{ + { preg, 3, "PREG" }, + { creg, 6, "CREG" }, + { mcache, 8, "MCCH" }, + { &lastppu, 4, "LPPU" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + setchr2(0x0000, (creg[0] >> 1) & 0x3F); + setchr2(0x0800, (creg[1] >> 1) & 0x3F); + setchr1(0x1000, creg[2]); + setchr1(0x1400, creg[3]); + setchr1(0x1800, creg[4]); + setchr1(0x1C00, creg[5]); + if (isExMirr) { + setmirror(MI_0 + mcache[lastppu]); + } else + setmirror(mirr); +} + +static DECLFW(M80RamWrite) { + if(wram_enable == 0xA3) + wram[A & 0xFF] = V; +} + +static DECLFR(M80RamRead) { + if(wram_enable == 0xA3) + return wram[A & 0xFF]; + else + return 0xFF; +} + +static DECLFW(M80Write) { + switch (A) { + case 0x7EF0: creg[0] = V; mcache[0] = mcache[1] = V >> 7; Sync(); break; + case 0x7EF1: creg[1] = V; mcache[2] = mcache[3] = V >> 7; Sync(); break; + case 0x7EF2: creg[2] = V; mcache[4] = V >> 7; Sync(); break; + case 0x7EF3: creg[3] = V; mcache[5] = V >> 7; Sync(); break; + case 0x7EF4: creg[4] = V; mcache[6] = V >> 7; Sync(); break; + case 0x7EF5: creg[5] = V; mcache[7] = V >> 7; Sync(); break; + case 0x7EF6: mirr = V & 1; Sync(); break; + case 0x7EF8: wram_enable = V; break; + case 0x7EFA: + case 0x7EFB: preg[0] = V; Sync(); break; + case 0x7EFC: + case 0x7EFD: preg[1] = V; Sync(); break; + case 0x7EFE: + case 0x7EFF: preg[2] = V; Sync(); break; + } +} + +static DECLFW(M95Write) { + switch (A & 0xF001) { + case 0x8000: cmd = V; break; + case 0x8001: + switch (cmd & 0x07) { + case 0: creg[0] = V & 0x1F; mcache[0] = mcache[1] = (V >> 5) & 1; Sync(); break; + case 1: creg[1] = V & 0x1F; mcache[2] = mcache[3] = (V >> 5) & 1; Sync(); break; + case 2: creg[2] = V & 0x1F; mcache[4] = (V >> 5) & 1; Sync(); break; + case 3: creg[3] = V & 0x1F; mcache[5] = (V >> 5) & 1; Sync(); break; + case 4: creg[4] = V & 0x1F; mcache[6] = (V >> 5) & 1; Sync(); break; + case 5: creg[5] = V & 0x1F; mcache[7] = (V >> 5) & 1; Sync(); break; + case 6: preg[0] = V; Sync(); break; + case 7: preg[1] = V; Sync(); break; + } + Sync(); + } +} + +static void MExMirrPPU(uint32 A) { + static int8 lastmirr = -1, curmirr; + if (A < 0x2000) { + lastppu = A >> 10; + curmirr = mcache[lastppu]; + if (curmirr != lastmirr) { + setmirror(MI_0 + curmirr); + lastmirr = curmirr; + } + } +} + +static void M80Power(void) { + wram_enable = 0xFF; + Sync(); + SetReadHandler(0x7F00, 0x7FFF, M80RamRead); + SetWriteHandler(0x7F00, 0x7FFF, M80RamWrite); + SetWriteHandler(0x7EF0, 0x7EFF, M80Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M207Power(void) { + mcache[0] = mcache[1] = mcache[2] = mcache[3] = 0; + mcache[4] = mcache[5] = mcache[6] = mcache[7] = 0; + Sync(); + SetWriteHandler(0x7EF0, 0x7EFF, M80Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M95Power(void) { + preg[2] = ~1; + mcache[0] = mcache[1] = mcache[2] = mcache[3] = 0; + mcache[4] = mcache[5] = mcache[6] = mcache[7] = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M95Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper80_Init(CartInfo *info) { + isExMirr = 0; + info->Power = M80Power; + GameStateRestore = StateRestore; + + if (info->battery) { + info->SaveGame[0] = wram; + info->SaveGameLen[0] = 256; + } + + AddExState(&StateRegs80, ~0, 0, 0); +} + +void Mapper95_Init(CartInfo *info) { + isExMirr = 1; + info->Power = M95Power; + PPU_hook = MExMirrPPU; + GameStateRestore = StateRestore; + AddExState(&StateRegs95, ~0, 0, 0); +} + +void Mapper207_Init(CartInfo *info) { + isExMirr = 1; + info->Power = M207Power; + PPU_hook = MExMirrPPU; + GameStateRestore = StateRestore; + AddExState(&StateRegs207, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/8157.cpp b/branches/fceux-2.2.2/src/boards/8157.cpp new file mode 100644 index 00000000..287be082 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/8157.cpp @@ -0,0 +1,85 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * GG1 boards, similar to T-262, with no Data latch + * + */ + +#include "mapinc.h" + +static uint16 cmdreg; +static uint8 reset; +static SFORMAT StateRegs[] = +{ + { &reset, 1, "REST" }, + { &cmdreg, 2, "CREG" }, + { 0 } +}; + +static void Sync(void) { + uint32 base = ((cmdreg & 0x060) | ((cmdreg & 0x100) >> 1)) >> 2; + uint32 bank = (cmdreg & 0x01C) >> 2; + uint32 lbank = (cmdreg & 0x200) ? 7 : ((cmdreg & 0x80) ? bank : 0); + if (PRGptr[1]) { + setprg16r(base >> 3, 0x8000, bank); // for versions with split ROMs + setprg16r(base >> 3, 0xC000, lbank); + } else { + setprg16(0x8000, base | bank); + setprg16(0xC000, base | lbank); + } + setmirror(((cmdreg & 2) >> 1) ^ 1); +} + +static DECLFR(UNL8157Read) { + if ((cmdreg & 0x100) && (PRGsize[0] < (1024 * 1024))) { + A = (A & 0xFFF0) + reset; + } + return CartBR(A); +} + +static DECLFW(UNL8157Write) { + cmdreg = A; + Sync(); +} + +static void UNL8157Power(void) { + setchr8(0); + SetWriteHandler(0x8000, 0xFFFF, UNL8157Write); + SetReadHandler(0x8000, 0xFFFF, UNL8157Read); + cmdreg = reset = 0; + Sync(); +} + +static void UNL8157Reset(void) { + cmdreg = reset = 0; + reset++; + reset &= 0x1F; + Sync(); +} + +static void UNL8157Restore(int version) { + Sync(); +} + +void UNL8157_Init(CartInfo *info) { + info->Power = UNL8157Power; + info->Reset = UNL8157Reset; + GameStateRestore = UNL8157Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/82.cpp b/branches/fceux-2.2.2/src/boards/82.cpp new file mode 100644 index 00000000..033e6ff6 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/82.cpp @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * Taito X1-017 board, battery backed + * + */ + +#include "mapinc.h" + +static uint8 regs[9], ctrl; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 9, "REGS" }, + { &ctrl, 1, "CTRL" }, + { 0 } +}; + +static void Sync(void) { + uint32 swap = ((ctrl & 2) << 11); + setchr2(0x0000 ^ swap, regs[0] >> 1); + setchr2(0x0800 ^ swap, regs[1] >> 1); + setchr1(0x1000 ^ swap, regs[2]); + setchr1(0x1400 ^ swap, regs[3]); + setchr1(0x1800 ^ swap, regs[4]); + setchr1(0x1c00 ^ swap, regs[5]); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, regs[6]); + setprg8(0xA000, regs[7]); + setprg8(0xC000, regs[8]); + setprg8(0xE000, ~0); + setmirror(ctrl & 1); +} + +static DECLFW(M82Write) { + if (A <= 0x7ef5) + regs[A & 7] = V; + else + switch (A) { + case 0x7ef6: ctrl = V & 3; break; + case 0x7efa: regs[6] = V >> 2; break; + case 0x7efb: regs[7] = V >> 2; break; + case 0x7efc: regs[8] = V >> 2; break; + } + Sync(); +} + +static void M82Power(void) { + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetWriteHandler(0x7ef0, 0x7efc, M82Write); // external WRAM might end at $73FF +} + +static void M82Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper82_Init(CartInfo *info) { + info->Power = M82Power; + info->Close = M82Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/8237.cpp b/branches/fceux-2.2.2/src/boards/8237.cpp new file mode 100644 index 00000000..38077690 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/8237.cpp @@ -0,0 +1,173 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 + * + * Super Game (Sugar Softec) protected mapper + * Pocahontas 2 (Unl) [U][!], etc. + * TODO: 9in1 LION KING HANGS! + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 cmdin; + +static uint8 regperm[8][8] = +{ + { 0, 1, 2, 3, 4, 5, 6, 7 }, + { 0, 2, 6, 1, 7, 3, 4, 5 }, + { 0, 5, 4, 1, 7, 2, 6, 3 }, // unused + { 0, 6, 3, 7, 5, 2, 4, 1 }, + { 0, 2, 5, 3, 6, 1, 7, 4 }, + { 0, 1, 2, 3, 4, 5, 6, 7 }, // empty + { 0, 1, 2, 3, 4, 5, 6, 7 }, // empty + { 0, 1, 2, 3, 4, 5, 6, 7 }, // empty +}; + +static uint8 adrperm[8][8] = +{ + { 0, 1, 2, 3, 4, 5, 6, 7 }, + { 3, 2, 0, 4, 1, 5, 6, 7 }, + { 0, 1, 2, 3, 4, 5, 6, 7 }, // unused + { 5, 0, 1, 2, 3, 7, 6, 4 }, + { 3, 1, 0, 5, 2, 4, 6, 7 }, + { 0, 1, 2, 3, 4, 5, 6, 7 }, // empty + { 0, 1, 2, 3, 4, 5, 6, 7 }, // empty + { 0, 1, 2, 3, 4, 5, 6, 7 }, // empty +}; + +static void UNL8237CW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) + setchr1(A, ((EXPREGS[1] & 0xc) << 6) | (V & 0x7F) | ((EXPREGS[1] & 0x20) << 2)); + else + setchr1(A, ((EXPREGS[1] & 0xc) << 6) | V); +} + +static void UNL8237PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) { + uint8 sbank = (EXPREGS[1] & 0x10); + if (EXPREGS[0] & 0x80) { + uint8 bank = ((EXPREGS[1] & 3) << 4) | (EXPREGS[0] & 0x7) | (sbank >> 1); + if (EXPREGS[0] & 0x20) + setprg32(0x8000, bank >> 1); + else{ + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else + setprg8(A, ((EXPREGS[1] & 3) << 5) | (V & 0x0F) | sbank); + } else { + if (EXPREGS[0] & 0x80) { + uint8 bank = ((EXPREGS[1] & 3) << 4) | (EXPREGS[0] & 0xF); + if (EXPREGS[0] & 0x20) + setprg32(0x8000, bank >> 1); + else{ + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else + setprg8(A, ((EXPREGS[1] & 3) << 5) | (V & 0x1F)); + } +} + +static void UNL8237ACW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) + setchr1(A, ((EXPREGS[1] & 0xE) << 7) | (V & 0x7F) | ((EXPREGS[1] & 0x20) << 2)); + else + setchr1(A, ((EXPREGS[1] & 0xE) << 7) | V); +} + +static void UNL8237APW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) { + uint8 sbank = (EXPREGS[1] & 0x10); + if (EXPREGS[0] & 0x80) { + uint8 bank = ((EXPREGS[1] & 3) << 4) | ((EXPREGS[1] & 8) << 3) | (EXPREGS[0] & 0x7) | (sbank >> 1); + if (EXPREGS[0] & 0x20) { +// FCEU_printf("8000:%02X\n",bank>>1); + setprg32(0x8000, bank >> 1); + } else { +// FCEU_printf("8000-C000:%02X\n",bank); + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else { +// FCEU_printf("%04x:%02X\n",A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); + setprg8(A, ((EXPREGS[1] & 3) << 5) | ((EXPREGS[1] & 8) << 4) | (V & 0x0F) | sbank); + } + } else { + if (EXPREGS[0] & 0x80) { + uint8 bank = ((EXPREGS[1] & 3) << 4) | ((EXPREGS[1] & 8) << 3) | (EXPREGS[0] & 0xF); + if (EXPREGS[0] & 0x20) { +// FCEU_printf("8000:%02X\n",(bank>>1)&0x07); + setprg32(0x8000, bank >> 1); + } else { +// FCEU_printf("8000-C000:%02X\n",bank&0x0F); + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else { +// FCEU_printf("%04X:%02X\n",A,(((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F))&0x1F); + setprg8(A, ((EXPREGS[1] & 3) << 5) | ((EXPREGS[1] & 8) << 4) | (V & 0x1F)); + } + } +} +static DECLFW(UNL8237Write) { + uint8 dat = V; + uint8 adr = adrperm[EXPREGS[2]][((A >> 12) & 6) | (A & 1)]; + uint16 addr = (adr & 1) | ((adr & 6) << 12) | 0x8000; + if (adr < 4) { + if (!adr) + dat = (dat & 0xC0) | (regperm[EXPREGS[2]][dat & 7]); + MMC3_CMDWrite(addr, dat); + } else + MMC3_IRQWrite(addr, dat); +} + +static DECLFW(UNL8237ExWrite) { + switch (A) { + case 0x5000: EXPREGS[0] = V; FixMMC3PRG(MMC3_cmd); break; + case 0x5001: EXPREGS[1] = V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break; + case 0x5007: EXPREGS[2] = V; break; + } +} + +static void UNL8237Power(void) { + EXPREGS[0] = EXPREGS[2] = 0; + EXPREGS[1] = 3; + GenMMC3Power(); + SetWriteHandler(0x8000, 0xFFFF, UNL8237Write); + SetWriteHandler(0x5000, 0x7FFF, UNL8237ExWrite); +} + +void UNL8237_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap = UNL8237CW; + pwrap = UNL8237PW; + info->Power = UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDI"); +} + +void UNL8237A_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap = UNL8237ACW; + pwrap = UNL8237APW; + info->Power = UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDI"); +} diff --git a/branches/fceux-2.2.2/src/boards/830118C.cpp b/branches/fceux-2.2.2/src/boards/830118C.cpp new file mode 100644 index 00000000..f04d9dbf --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/830118C.cpp @@ -0,0 +1,68 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * 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 + */ + +// M-022 MMC3 based 830118C T-106 4M + 4M + +#include "mapinc.h" +#include "mmc3.h" + +static void BMC830118CCW(uint32 A, uint8 V) { + setchr1(A, (V & 0x7F) | ((EXPREGS[0] & 0x0c) << 5)); +} + +static void BMC830118CPW(uint32 A, uint8 V) { + if ((EXPREGS[0] & 0x0C) == 0x0C) { + if (A == 0x8000) { + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); + setprg8(0xC000, (V & 0x0F) | 0x32); + } else if (A == 0xA000) { + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); + setprg8(0xE000, (V & 0x0F) | 0x32); + } + } else { + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); + } +} + +static DECLFW(BMC830118CLoWrite) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC830118CReset(void) { + EXPREGS[0] = 0; + MMC3RegReset(); +} + +static void BMC830118CPower(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6800, 0x68FF, BMC830118CLoWrite); +} + +void BMC830118C_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap = BMC830118CPW; + cwrap = BMC830118CCW; + info->Power = BMC830118CPower; + info->Reset = BMC830118CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/88.cpp b/branches/fceux-2.2.2/src/boards/88.cpp new file mode 100644 index 00000000..7341f251 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/88.cpp @@ -0,0 +1,83 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, is154; + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { &mirror, 1, "MIRR" }, + { reg, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setchr2(0x0000, reg[0] >> 1); + setchr2(0x0800, reg[1] >> 1); + setchr1(0x1000, reg[2] | 0x40); + setchr1(0x1400, reg[3] | 0x40); + setchr1(0x1800, reg[4] | 0x40); + setchr1(0x1C00, reg[5] | 0x40); + setprg8(0x8000, reg[6]); + setprg8(0xA000, reg[7]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); +} + +static void MSync(void) { + if (is154) setmirror(MI_0 + (mirror & 1)); +} + +static DECLFW(M88Write) { + switch (A & 0x8001) { + case 0x8000: cmd = V & 7; mirror = V >> 6; MSync(); break; + case 0x8001: reg[cmd] = V; Sync(); break; + } +} + +static void M88Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0; + Sync(); + MSync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M88Write); +} + +static void StateRestore(int version) { + Sync(); + MSync(); +} + +void Mapper88_Init(CartInfo *info) { + is154 = 0; + info->Power = M88Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper154_Init(CartInfo *info) { + is154 = 1; + info->Power = M88Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/90.cpp b/branches/fceux-2.2.2/src/boards/90.cpp new file mode 100644 index 00000000..7c873d26 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/90.cpp @@ -0,0 +1,507 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +//#define DEBUG90 + +// Mapper 090 is simpliest mapper hardware and have not extended nametable control and latched chr banks in 4k mode +// Mapper 209 much compicated hardware with decribed above features disabled by default and switchable by command +// Mapper 211 the same mapper 209 but with forced nametable control + +static int is209; +static int is211; + +static uint8 IRQMode; // from $c001 +static uint8 IRQPre; // from $c004 +static uint8 IRQPreSize; // from $c007 +static uint8 IRQCount; // from $c005 +static uint8 IRQXOR; // Loaded from $C006 +static uint8 IRQa; // $c002, $c003, and $c000 + +static uint8 mul[2]; +static uint8 regie; + +static uint8 tkcom[4]; +static uint8 prgb[4]; +static uint8 chrlow[8]; +static uint8 chrhigh[8]; + +static uint8 chr[2]; + +static uint16 names[4]; +static uint8 tekker; + +static SFORMAT Tek_StateRegs[] = { + { &IRQMode, 1, "IRQM" }, + { &IRQPre, 1, "IRQP" }, + { &IRQPreSize, 1, "IRQR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQXOR, 1, "IRQX" }, + { &IRQa, 1, "IRQA" }, + { mul, 2, "MUL" }, + { ®ie, 1, "REGI" }, + { tkcom, 4, "TKCO" }, + { prgb, 4, "PRGB" }, + { chr, 2, "CLTC" }, + { chrlow, 4, "CHRL" }, + { chrhigh, 8, "CHRH" }, + { &names[0], 2 | FCEUSTATE_RLSB, "NMS0" }, + { &names[1], 2 | FCEUSTATE_RLSB, "NMS1" }, + { &names[2], 2 | FCEUSTATE_RLSB, "NMS2" }, + { &names[3], 2 | FCEUSTATE_RLSB, "NMS3" }, + { &tekker, 1, "TEKR" }, + { 0 } +}; + +static void mira(void) +{ + if((tkcom[0]&0x20&&is209)||is211) + { + int x; + if(tkcom[0]&0x40) // Name tables are ROM-only + { + for(x=0;x<4;x++) + setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x); + } + else // Name tables can be RAM or ROM. + { + for(x=0;x<4;x++) + { + if((tkcom[1]&0x80)==(names[x]&0x80)) // RAM selected. + setntamem(NTARAM+((names[x]&0x1)<<10),1,x); + else + setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x); + } + } + } + else + { + switch(tkcom[1]&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } + } +} + +static void tekprom(void) +{ + uint32 bankmode=((tkcom[3]&6)<<5); + switch(tkcom[0]&7) + { + case 00: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); + setprg32(0x8000,0x0F|((tkcom[3]&6)<<3)); + break; + case 01: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode); + setprg16(0x8000,(prgb[1]&0x1F)|((tkcom[3]&6)<<4)); + setprg16(0xC000,0x1F|((tkcom[3]&6)<<4)); + break; + case 03: // bit reversion + case 02: if(tkcom[0]&0x80) + setprg8(0x6000,(prgb[3]&0x3F)|bankmode); + setprg8(0x8000,(prgb[0]&0x3F)|bankmode); + setprg8(0xa000,(prgb[1]&0x3F)|bankmode); + setprg8(0xc000,(prgb[2]&0x3F)|bankmode); + setprg8(0xe000,0x3F|bankmode); + break; + case 04: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); + setprg32(0x8000,(prgb[3]&0x0F)|((tkcom[3]&6)<<3)); + break; + case 05: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode); + setprg16(0x8000,(prgb[1]&0x1F)|((tkcom[3]&6)<<4)); + setprg16(0xC000,(prgb[3]&0x1F)|((tkcom[3]&6)<<4)); + break; + case 07: // bit reversion + case 06: if(tkcom[0]&0x80) + setprg8(0x6000,(prgb[3]&0x3F)|bankmode); + setprg8(0x8000,(prgb[0]&0x3F)|bankmode); + setprg8(0xa000,(prgb[1]&0x3F)|bankmode); + setprg8(0xc000,(prgb[2]&0x3F)|bankmode); + setprg8(0xe000,(prgb[3]&0x3F)|bankmode); + break; + } +} + +static void tekvrom(void) +{ + int x, bank=0, mask=0xFFFF; + if(!(tkcom[3]&0x20)) + { + bank=(tkcom[3]&1)|((tkcom[3]&0x18)>>2); + switch (tkcom[0]&0x18) + { + case 0x00: bank<<=5; mask=0x1F; break; + case 0x08: bank<<=6; mask=0x3F; break; + case 0x10: bank<<=7; mask=0x7F; break; + case 0x18: bank<<=8; mask=0xFF; break; + } + } + switch(tkcom[0]&0x18) + { + case 0x00: // 8KB + setchr8(((chrlow[0]|(chrhigh[0]<<8))&mask)|bank); + break; + case 0x08: // 4KB +// for(x=0;x<8;x+=4) +// setchr4(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank); + setchr4(0x0000,((chrlow[chr[0]]|(chrhigh[chr[0]]<<8))&mask)|bank); + setchr4(0x1000,((chrlow[chr[1]]|(chrhigh[chr[1]]<<8))&mask)|bank); + break; + case 0x10: // 2KB + for(x=0;x<8;x+=2) + setchr2(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank); + break; + case 0x18: // 1KB + for(x=0;x<8;x++) + setchr1(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank); + break; + } +} + +static DECLFW(M90TekWrite) +{ + switch(A&0x5C03) + { + case 0x5800: mul[0]=V; break; + case 0x5801: mul[1]=V; break; + case 0x5803: regie=V; break; + } +} + +static DECLFR(M90TekRead) +{ + switch(A&0x5C03) + { + case 0x5800: return (mul[0]*mul[1]); + case 0x5801: return((mul[0]*mul[1])>>8); + case 0x5803: return (regie); + default: return tekker; + } + return(0xff); +} + +static DECLFW(M90PRGWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + prgb[A&3]=V; + tekprom(); +} + +static DECLFW(M90CHRlowWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + chrlow[A&7]=V; + tekvrom(); +} + +static DECLFW(M90CHRhiWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + chrhigh[A&7]=V; + tekvrom(); +} + +static DECLFW(M90NTWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + if(A&4) + { + names[A&3]&=0x00FF; + names[A&3]|=V<<8; + } + else + { + names[A&3]&=0xFF00; + names[A&3]|=V; + } + mira(); +} + +static DECLFW(M90IRQWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + switch(A&7) + { + case 00: //FCEU_printf("%s IRQ (C000)\n",V&1?"Enable":"Disable"); + IRQa=V&1;if(!(V&1)) X6502_IRQEnd(FCEU_IQEXT);break; + case 02: //FCEU_printf("Disable IRQ (C002) scanline=%d\n", scanline); + IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 03: //FCEU_printf("Enable IRQ (C003) scanline=%d\n", scanline); + IRQa=1;break; + case 01: IRQMode=V; + // FCEU_printf("IRQ Count method: "); + // switch (IRQMode&3) + // { + // case 00: FCEU_printf("M2 cycles\n");break; + // case 01: FCEU_printf("PPU A12 toggles\n");break; + // case 02: FCEU_printf("PPU reads\n");break; + // case 03: FCEU_printf("Writes to CPU space\n");break; + // } + // FCEU_printf("Counter prescaler size: %s\n",(IRQMode&4)?"3 bits":"8 bits"); + // FCEU_printf("Counter prescaler size adjust: %s\n",(IRQMode&8)?"Used C007":"Normal Operation"); + // if((IRQMode>>6)==2) FCEU_printf("Counter Down\n"); + // else if((IRQMode>>6)==1) FCEU_printf("Counter Up\n"); + // else FCEU_printf("Counter Stopped\n"); + break; + case 04: //FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); + IRQPre=V^IRQXOR;break; + case 05: //FCEU_printf("Main Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); + IRQCount=V^IRQXOR;break; + case 06: //FCEU_printf("Xor Value: %d\n",V); + IRQXOR=V;break; + case 07: //if(!(IRQMode&8)) FCEU_printf("C001 is clear, no effect applied\n"); + // else if(V==0xFF) FCEU_printf("Prescaler is changed for 12bits\n"); + // else FCEU_printf("Counter Stopped\n"); + IRQPreSize=V;break; + } +} + +static DECLFW(M90ModeWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + tkcom[A&3]=V; + tekprom(); + tekvrom(); + mira(); + +#ifdef DEBUG90 + switch (A&3) + { + case 00: FCEU_printf("Main Control Register:\n"); + FCEU_printf(" PGR Banking mode: %d\n",V&7); + FCEU_printf(" CHR Banking mode: %d\n",(V>>3)&3); + FCEU_printf(" 6000-7FFF addresses mapping: %s\n",(V&0x80)?"Yes":"No"); + FCEU_printf(" Nametable control: %s\n",(V&0x20)?"Enabled":"Disabled"); + if(V&0x20) + FCEU_printf(" Nametable can be: %s\n",(V&0x40)?"ROM Only":"RAM or ROM"); + break; + case 01: FCEU_printf("Mirroring mode: "); + switch (V&3) + { + case 0: FCEU_printf("Vertical\n");break; + case 1: FCEU_printf("Horizontal\n");break; + case 2: FCEU_printf("Nametable 0 only\n");break; + case 3: FCEU_printf("Nametable 1 only\n");break; + } + FCEU_printf("Mirroring flag: %s\n",(V&0x80)?"On":"Off"); + break; + case 02: if((((tkcom[0])>>5)&3)==1) + FCEU_printf("Nametable ROM/RAM select mode: %d\n",V>>7); + break; + case 03: + FCEU_printf("CHR Banking mode: %s\n",(V&0x20)?"Entire CHR ROM":"256Kb Switching mode"); + if(!(V&0x20)) FCEU_printf("256K CHR bank number: %02x\n",(V&1)|((V&0x18)>>2)); + FCEU_printf("512K PRG bank number: %d\n",(V&6)>>1); + FCEU_printf("CHR Bank mirroring: %s\n",(V&0x80)?"Swapped":"Normal operate"); + } +#endif +} + +static DECLFW(M90DummyWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); +} + +static void CCL(void) +{ + if((IRQMode>>6) == 1) // Count Up + { + IRQCount++; + if((IRQCount == 0) && IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } + else if((IRQMode>>6) == 2) // Count down + { + IRQCount--; + if((IRQCount == 0xFF) && IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void ClockCounter(void) +{ + uint8 premask; + + if(IRQMode & 0x4) + premask = 0x7; + else + premask = 0xFF; + if((IRQMode>>6) == 1) // Count up + { + IRQPre++; + if((IRQPre & premask) == 0) CCL(); + } + else if((IRQMode>>6) == 2) // Count down + { + IRQPre--; + if((IRQPre & premask) == premask) CCL(); + } +} + +void CPUWrap(int a) +{ + int x; + if((IRQMode&3)==0) for(x=0;x>8; + if(h<0x20&&((h&0x0F)==0xF)) + { + l=A&0xF0; + if(l==0xD0) + { + chr[(h&0x10)>>4]=((h&0x10)>>2); + tekvrom(); + } + else if(l==0xE0) + { + chr[(h&0x10)>>4]=((h&0x10)>>2)|2; + tekvrom(); + } + } + } + else + { + chr[0]=0; + chr[1]=4; + } +} + +static void togglie() +{ + tekker+=0x40; + tekker&=0xC0; + FCEU_printf("tekker=%02x\n",tekker); + memset(tkcom,0x00,sizeof(tkcom)); + memset(prgb,0xff,sizeof(prgb)); + tekprom(); + tekvrom(); +} + +static void M90Restore(int version) +{ + tekprom(); + tekvrom(); + mira(); +} + +static void M90Power(void) +{ + SetWriteHandler(0x5000,0x5fff,M90TekWrite); + SetWriteHandler(0x8000,0x8ff0,M90PRGWrite); + SetWriteHandler(0x9000,0x9fff,M90CHRlowWrite); + SetWriteHandler(0xA000,0xAfff,M90CHRhiWrite); + SetWriteHandler(0xB000,0xBfff,M90NTWrite); + SetWriteHandler(0xC000,0xCfff,M90IRQWrite); + SetWriteHandler(0xD000,0xD5ff,M90ModeWrite); + SetWriteHandler(0xE000,0xFfff,M90DummyWrite); + + + SetReadHandler(0x5000,0x5fff,M90TekRead); + SetReadHandler(0x6000,0xffff,CartBR); + + mul[0]=mul[1]=regie=0xFF; + + memset(tkcom,0x00,sizeof(tkcom)); + memset(prgb,0xff,sizeof(prgb)); + memset(chrlow,0xff,sizeof(chrlow)); + memset(chrhigh,0xff,sizeof(chrhigh)); + memset(names,0x00,sizeof(names)); + + if(is211) + tekker=0xC0; + else + tekker=0x00; + + tekprom(); + tekvrom(); +} + + +void Mapper90_Init(CartInfo *info) +{ + is211=0; + is209=0; + info->Reset=togglie; + info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; + GameHBIRQHook2=SLWrap; + GameStateRestore=M90Restore; + AddExState(Tek_StateRegs, ~0, 0, 0); +} + +void Mapper209_Init(CartInfo *info) +{ + is211=0; + is209=1; + info->Reset=togglie; + info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; + GameHBIRQHook2=SLWrap; + GameStateRestore=M90Restore; + AddExState(Tek_StateRegs, ~0, 0, 0); +} + +void Mapper211_Init(CartInfo *info) +{ + is211=1; + info->Reset=togglie; + info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; + GameHBIRQHook2=SLWrap; + GameStateRestore=M90Restore; + AddExState(Tek_StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/91.cpp b/branches/fceux-2.2.2/src/boards/91.cpp new file mode 100644 index 00000000..d1ed61b3 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/91.cpp @@ -0,0 +1,85 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 cregs[4], pregs[2]; +static uint8 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { cregs, 4, "CREG" }, + { pregs, 2, "PREG" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 1, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, pregs[0]); + setprg8(0xa000, pregs[1]); + setprg8(0xc000, ~1); + setprg8(0xe000, ~0); + setchr2(0x0000, cregs[0]); + setchr2(0x0800, cregs[1]); + setchr2(0x1000, cregs[2]); + setchr2(0x1800, cregs[3]); +} + +static DECLFW(M91Write0) { + cregs[A & 3] = V; + Sync(); +} + +static DECLFW(M91Write1) { + switch (A & 3) { + case 0: + case 1: pregs[A & 1] = V; Sync(); break; + case 2: IRQa = IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 3: IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void M91Power(void) { + Sync(); + SetWriteHandler(0x6000, 0x6fff, M91Write0); + SetWriteHandler(0x7000, 0x7fff, M91Write1); + SetReadHandler(0x8000, 0xffff, CartBR); +} + +static void M91IRQHook(void) { + if (IRQCount < 8 && IRQa) { + IRQCount++; + if (IRQCount >= 8) { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper91_Init(CartInfo *info) { + info->Power = M91Power; + GameHBIRQHook = M91IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/96.cpp b/branches/fceux-2.2.2/src/boards/96.cpp new file mode 100644 index 00000000..08c42d6b --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/96.cpp @@ -0,0 +1,70 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg, ppulatch; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &ppulatch, 1, "PPUL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(MI_0); + setprg32(0x8000, reg & 3); + setchr4(0x0000, (reg & 4) | ppulatch); + setchr4(0x1000, (reg & 4) | 3); +} + +static DECLFW(M96Write) { + reg = V; + Sync(); +} + +static void M96Hook(uint32 A) { + if ((A & 0x3000) == 0x2000) { + ppulatch = (A >> 8) & 3; + Sync(); + } +} + +static void M96Power(void) { + reg = ppulatch = 0; + Sync(); + SetReadHandler(0x8000, 0xffff, CartBR); + SetWriteHandler(0x8000, 0xffff, M96Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper96_Init(CartInfo *info) { + info->Power = M96Power; + PPU_hook = M96Hook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/branches/fceux-2.2.2/src/boards/99.cpp b/branches/fceux-2.2.2/src/boards/99.cpp new file mode 100644 index 00000000..caf5cff8 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/99.cpp @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 latch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static writefunc old4016; + +static SFORMAT StateRegs[] = +{ + { &latch, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setchr8((latch >> 2) & 1); + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, 0); + setprg8(0x8000, latch & 4); /* Special for VS Gumshoe */ +} + +static DECLFW(M99Write) { + latch = V; + Sync(); + old4016(A, V); +} + +static void M99Power(void) { + latch = 0; + Sync(); + old4016 = GetWriteHandler(0x4016); + SetWriteHandler(0x4016, 0x4016, M99Write); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); +} + +static void M99Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper99_Init(CartInfo *info) { + info->Power = M99Power; + info->Close = M99Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/SConscript b/branches/fceux-2.2.2/src/boards/SConscript new file mode 100644 index 00000000..f9afb2d5 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/SConscript @@ -0,0 +1,6 @@ +import glob +source_list = glob.glob('*.cpp')+glob.glob('*.c') + +for x in range(len(source_list)): + source_list[x] = 'boards/' + source_list[x] +Return('source_list') diff --git a/branches/fceux-2.2.2/src/boards/__dummy_mapper.cpp b/branches/fceux-2.2.2/src/boards/__dummy_mapper.cpp new file mode 100644 index 00000000..505f9169 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/__dummy_mapper.cpp @@ -0,0 +1,100 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2013 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg[8]; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; +/* +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; +*/ + +static SFORMAT StateRegs[] = +{ + { reg, 8, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { +} + +static DECLFW(MNNNWrite) { +} + +static void MNNNPower(void) { +// SetReadHandler(0x6000, 0x7fff, CartBR); +// SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, MNNNWrite); +} + +static void MNNNReset(void) { +} + +/* +static void MNNNClose(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + if (CHRRAM) + FCEU_gfree(CHRRAM); + WRAM = CHRRAM = NULL; +} +*/ + +static void MNNNIRQHook() { + X6502_IRQBegin(FCEU_IQEXT); +} + +static void StateRestore(int version) { + Sync(); +} + +void MapperNNN_Init(CartInfo *info) { + info->Reset = MNNNReset; + info->Power = MNNNPower; +// info->Close = MNNNClose; + GameHBIRQHook = MNNNIRQHook; + GameStateRestore = StateRestore; +/* + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); +*/ +/* + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } +*/ + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/a9746.cpp b/branches/fceux-2.2.2/src/boards/a9746.cpp new file mode 100644 index 00000000..321ac8aa --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/a9746.cpp @@ -0,0 +1,75 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static DECLFW(UNLA9746Write) { +// FCEU_printf("write raw %04x:%02x\n",A,V); + switch (A & 0xE003) { + case 0x8000: EXPREGS[1] = V; EXPREGS[0] = 0; break; + case 0x8002: EXPREGS[0] = V; EXPREGS[1] = 0; break; + case 0x8001: + { + uint8 bits_rev = ((V & 0x20) >> 5) | ((V & 0x10) >> 3) | ((V & 0x08) >> 1) | ((V & 0x04) << 1); + switch (EXPREGS[0]) { + case 0x26: setprg8(0x8000, bits_rev); break; + case 0x25: setprg8(0xA000, bits_rev); break; + case 0x24: setprg8(0xC000, bits_rev); break; + case 0x23: setprg8(0xE000, bits_rev); break; + } + switch (EXPREGS[1]) { + case 0x0a: + case 0x08: EXPREGS[2] = (V << 4); break; + case 0x09: setchr1(0x0000, EXPREGS[2] | (V >> 1)); break; + case 0x0b: setchr1(0x0400, EXPREGS[2] | (V >> 1) | 1); break; + case 0x0c: + case 0x0e: EXPREGS[2] = (V << 4); break; + case 0x0d: setchr1(0x0800, EXPREGS[2] | (V >> 1)); break; + case 0x0f: setchr1(0x0c00, EXPREGS[2] | (V >> 1) | 1); break; + case 0x10: + case 0x12: EXPREGS[2] = (V << 4); break; + case 0x11: setchr1(0x1000, EXPREGS[2] | (V >> 1)); break; + case 0x14: + case 0x16: EXPREGS[2] = (V << 4); break; + case 0x15: setchr1(0x1400, EXPREGS[2] | (V >> 1)); break; + case 0x18: + case 0x1a: EXPREGS[2] = (V << 4); break; + case 0x19: setchr1(0x1800, EXPREGS[2] | (V >> 1)); break; + case 0x1c: + case 0x1e: EXPREGS[2] = (V << 4); break; + case 0x1d: setchr1(0x1c00, EXPREGS[2] | (V >> 1)); break; + } + } + break; + } +} + +static void UNLA9746Power(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xbfff, UNLA9746Write); +} + +void UNLA9746_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power = UNLA9746Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} + diff --git a/branches/fceux-2.2.2/src/boards/ac-08.cpp b/branches/fceux-2.2.2/src/boards/ac-08.cpp new file mode 100644 index 00000000..2c32fda2 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ac-08.cpp @@ -0,0 +1,68 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg32r(1, 0x8000, 0); + setchr8(0); + setmirror(mirr); +} + +static DECLFW(AC08Mirr) { + mirr = ((V & 8) >> 3) ^ 1; + Sync(); +} + +static DECLFW(AC08Write) { + if (A == 0x8001) // Green Berret bank switching is only 100x xxxx xxxx xxx1 mask + reg = (V >> 1) & 0xf; + else + reg = V & 0xf; // Sad But True, 2-in-1 mapper, Green Berret need value shifted left one byte, Castlevania doesn't + Sync(); +} + +static void AC08Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x4025, 0x4025, AC08Mirr); + SetWriteHandler(0x8000, 0xFFFF, AC08Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void AC08_Init(CartInfo *info) { + info->Power = AC08Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/addrlatch.cpp b/branches/fceux-2.2.2/src/boards/addrlatch.cpp new file mode 100644 index 00000000..299f6e46 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/addrlatch.cpp @@ -0,0 +1,505 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 "mapinc.h" + +static uint16 latche, latcheinit; +static uint16 addrreg0, addrreg1; +static uint8 dipswitch; +static void (*WSync)(void); +static readfunc defread; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static DECLFW(LatchWrite) { + latche = A; + WSync(); +} + +static void LatchReset(void) { + latche = latcheinit; + WSync(); +} + +static void LatchPower(void) { + latche = latcheinit; + WSync(); + if (WRAM) { + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + } else + SetReadHandler(0x6000, 0xFFFF, defread); + SetWriteHandler(addrreg0, addrreg1, LatchWrite); +} + +static void LatchClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 linit, uint16 adr0, uint16 adr1, uint8 wram) { + latcheinit = linit; + addrreg0 = adr0; + addrreg1 = adr1; + WSync = proc; + if (func != NULL) + defread = func; + else + defread = CartBROB; + info->Power = LatchPower; + info->Reset = LatchReset; + info->Close = LatchClose; + if (wram) { + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + GameStateRestore = StateRestore; + AddExState(&latche, 2, 0, "LATC"); +} + +//------------------ BMCD1038 --------------------------- + +static void BMCD1038Sync(void) { + if (latche & 0x80) { + setprg16(0x8000, (latche & 0x70) >> 4); + setprg16(0xC000, (latche & 0x70) >> 4); + } else + setprg32(0x8000, (latche & 0x60) >> 5); + setchr8(latche & 7); + setmirror(((latche & 8) >> 3) ^ 1); +} + +static DECLFR(BMCD1038Read) { + if (latche & 0x100) + return dipswitch; + else + return CartBR(A); +} + +static void BMCD1038Reset(void) { + dipswitch++; + dipswitch &= 3; +} + +void BMCD1038_Init(CartInfo *info) { + Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0x0000, 0x8000, 0xFFFF, 0); + info->Reset = BMCD1038Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + +//------------------ UNL43272 --------------------------- +// mapper much complex, including 16K bankswitching +static void UNL43272Sync(void) { + if ((latche & 0x81) == 0x81) { + setprg32(0x8000, (latche & 0x38) >> 3); + } else + FCEU_printf("unrecognized command %04!\n", latche); + setchr8(0); + setmirror(0); +} + +static DECLFR(UNL43272Read) { + if (latche & 0x400) + return CartBR(A & 0xFE); + else + return CartBR(A); +} + +static void UNL43272Reset(void) { + latche = 0; + UNL43272Sync(); +} + +void UNL43272_Init(CartInfo *info) { + Latch_Init(info, UNL43272Sync, UNL43272Read, 0x0081, 0x8000, 0xFFFF, 0); + info->Reset = UNL43272Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + +//------------------ Map 058 --------------------------- + +static void BMCGK192Sync(void) { + if (latche & 0x40) { + setprg16(0x8000, latche & 7); + setprg16(0xC000, latche & 7); + } else + setprg32(0x8000, (latche >> 1) & 3); + setchr8((latche >> 3) & 7); + setmirror(((latche & 0x80) >> 7) ^ 1); +} + +void BMCGK192_Init(CartInfo *info) { + Latch_Init(info, BMCGK192Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 059 --------------------------- +// One more forgotten mapper +static void M59Sync(void) { + setprg32(0x8000, (latche >> 4) & 7); + setchr8(latche & 0x7); + setmirror((latche >> 3) & 1); +} + +static DECLFR(M59Read) { + if (latche & 0x100) + return 0; + else + return CartBR(A); +} + +void Mapper59_Init(CartInfo *info) { + Latch_Init(info, M59Sync, M59Read, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 061 --------------------------- +static void M61Sync(void) { + if (((latche & 0x10) << 1) ^ (latche & 0x20)) { + setprg16(0x8000, ((latche & 0xF) << 1) | (((latche & 0x20) >> 4))); + setprg16(0xC000, ((latche & 0xF) << 1) | (((latche & 0x20) >> 4))); + } else + setprg32(0x8000, latche & 0xF); + setchr8(0); + setmirror(((latche >> 7) & 1) ^ 1); +} + +void Mapper61_Init(CartInfo *info) { + Latch_Init(info, M61Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 092 --------------------------- +// Another two-in-one mapper, two Jaleco carts uses similar +// hardware, but with different wiring. +// Original code provided by LULU +// Additionally, PCB contains DSP extra sound chip, used for voice samples (unemulated) + +static void M92Sync(void) { + uint8 reg = latche & 0xF0; + setprg16(0x8000, 0); + if (latche >= 0x9000) { + switch (reg) { + case 0xD0: setprg16(0xc000, latche & 15); break; + case 0xE0: setchr8(latche & 15); break; + } + } else { + switch (reg) { + case 0xB0: setprg16(0xc000, latche & 15); break; + case 0x70: setchr8(latche & 15); break; + } + } +} + +void Mapper92_Init(CartInfo *info) { + Latch_Init(info, M92Sync, NULL, 0x80B0, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 200 --------------------------- + +static void M200Sync(void) { + setprg16(0x8000, latche & 7); + setprg16(0xC000, latche & 7); + setchr8(latche & 7); + setmirror((latche & 8) >> 3); +} + +void Mapper200_Init(CartInfo *info) { + Latch_Init(info, M200Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 201 --------------------------- + +static void M201Sync(void) { + if (latche & 8) { + setprg32(0x8000, latche & 3); + setchr8(latche & 3); + } else { + setprg32(0x8000, 0); + setchr8(0); + } +} + +void Mapper201_Init(CartInfo *info) { + Latch_Init(info, M201Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 202 --------------------------- + +static void M202Sync(void) { + // According to more carefull hardware tests and PCB study + int32 mirror = latche & 1; + int32 bank = (latche >> 1) & 0x7; + int32 select = (mirror & (bank >> 2)); + setprg16(0x8000, select ? (bank & 6) | 0 : bank); + setprg16(0xc000, select ? (bank & 6) | 1 : bank); + setmirror(mirror ^ 1); + setchr8(bank); +} + +void Mapper202_Init(CartInfo *info) { + Latch_Init(info, M202Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 204 --------------------------- + +static void M204Sync(void) { + int32 tmp2 = latche & 0x6; + int32 tmp1 = tmp2 + ((tmp2 == 0x6) ? 0 : (latche & 1)); + setprg16(0x8000, tmp1); + setprg16(0xc000, tmp2 + ((tmp2 == 0x6) ? 1 : (latche & 1))); + setchr8(tmp1); + setmirror(((latche >> 4) & 1) ^ 1); +} + +void Mapper204_Init(CartInfo *info) { + Latch_Init(info, M204Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 212 --------------------------- + +static DECLFR(M212Read) { + uint8 ret = CartBROB(A); + if ((A & 0xE010) == 0x6000) + ret |= 0x80; + return ret; +} + +static void M212Sync(void) { + if (latche & 0x4000) { + setprg32(0x8000, (latche >> 1) & 3); + } else { + setprg16(0x8000, latche & 7); + setprg16(0xC000, latche & 7); + } + setchr8(latche & 7); + setmirror(((latche >> 3) & 1) ^ 1); +} + +void Mapper212_Init(CartInfo *info) { + Latch_Init(info, M212Sync, M212Read, 0xFFFF, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 213 --------------------------- + +static void M213Sync(void) { + setprg32(0x8000, (latche >> 1) & 3); + setchr8((latche >> 3) & 7); +} + +void Mapper213_Init(CartInfo *info) { + Latch_Init(info, M213Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 214 --------------------------- + +static void M214Sync(void) { + setprg16(0x8000, (latche >> 2) & 3); + setprg16(0xC000, (latche >> 2) & 3); + setchr8(latche & 3); +} + +void Mapper214_Init(CartInfo *info) { + Latch_Init(info, M214Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 217 --------------------------- + +static void M217Sync(void) { + setprg32(0x8000, (latche >> 2) & 3); + setchr8(latche & 7); +} + +void Mapper217_Init(CartInfo *info) { + Latch_Init(info, M217Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 227 --------------------------- + +static void M227Sync(void) { + uint32 S = latche & 1; + uint32 p = ((latche >> 2) & 0x1F) + ((latche & 0x100) >> 3); + uint32 L = (latche >> 9) & 1; + + if ((latche >> 7) & 1) { + if (S) { + setprg32(0x8000, p >> 1); + } else { + setprg16(0x8000, p); + setprg16(0xC000, p); + } + } else { + if (S) { + if (L) { + setprg16(0x8000, p & 0x3E); + setprg16(0xC000, p | 7); + } else { + setprg16(0x8000, p & 0x3E); + setprg16(0xC000, p & 0x38); + } + } else { + if (L) { + setprg16(0x8000, p); + setprg16(0xC000, p | 7); + } else { + setprg16(0x8000, p); + setprg16(0xC000, p & 0x38); + } + } + } + + setmirror(((latche >> 1) & 1) ^ 1); + setchr8(0); + setprg8r(0x10, 0x6000, 0); +} + +void Mapper227_Init(CartInfo *info) { + Latch_Init(info, M227Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); +} + +//------------------ Map 229 --------------------------- + +static void M229Sync(void) { + setchr8(latche); + if (!(latche & 0x1e)) + setprg32(0x8000, 0); + else { + setprg16(0x8000, latche & 0x1F); + setprg16(0xC000, latche & 0x1F); + } + setmirror(((latche >> 5) & 1) ^ 1); +} + +void Mapper229_Init(CartInfo *info) { + Latch_Init(info, M229Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 231 --------------------------- + +static void M231Sync(void) { + setchr8(0); + if (latche & 0x20) + setprg32(0x8000, (latche >> 1) & 0x0F); + else { + setprg16(0x8000, latche & 0x1E); + setprg16(0xC000, latche & 0x1E); + } + setmirror(((latche >> 7) & 1) ^ 1); +} + +void Mapper231_Init(CartInfo *info) { + Latch_Init(info, M231Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//------------------ Map 242 --------------------------- + +static void M242Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, (latche >> 3) & 0xf); + setmirror(((latche >> 1) & 1) ^ 1); +} + +void Mapper242_Init(CartInfo *info) { + Latch_Init(info, M242Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); +} + +//------------------ 190in1 --------------------------- + +static void BMC190in1Sync(void) { + setprg16(0x8000, (latche >> 2) & 7); + setprg16(0xC000, (latche >> 2) & 7); + setchr8((latche >> 2) & 7); + setmirror((latche & 1) ^ 1); +} + +void BMC190in1_Init(CartInfo *info) { + Latch_Init(info, BMC190in1Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//-------------- BMC810544-C-A1 ------------------------ + +static void BMC810544CA1Sync(void) { + uint32 bank = latche >> 7; + if (latche & 0x40) + setprg32(0x8000, bank); + else { + setprg16(0x8000, (bank << 1) | ((latche >> 5) & 1)); + setprg16(0xC000, (bank << 1) | ((latche >> 5) & 1)); + } + setchr8(latche & 0x0f); + setmirror(((latche >> 4) & 1) ^ 1); +} + +void BMC810544CA1_Init(CartInfo *info) { + Latch_Init(info, BMC810544CA1Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//-------------- BMCNTD-03 ------------------------ + +static void BMCNTD03Sync(void) { + // 1PPP Pmcc spxx xccc + // 1000 0000 0000 0000 v + // 1001 1100 0000 0100 h + // 1011 1010 1100 0100 + uint32 prg = ((latche >> 10) & 0x1e); + uint32 chr = ((latche & 0x0300) >> 5) | (latche & 7); + if (latche & 0x80) { + setprg16(0x8000, prg | ((latche >> 6) & 1)); + setprg16(0xC000, prg | ((latche >> 6) & 1)); + } else + setprg32(0x8000, prg >> 1); + setchr8(chr); + setmirror(((latche >> 10) & 1) ^ 1); +} + +void BMCNTD03_Init(CartInfo *info) { + Latch_Init(info, BMCNTD03Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +//-------------- BMCG-146 ------------------------ + +static void BMCG146Sync(void) { + setchr8(0); + if (latche & 0x800) { // UNROM mode + setprg16(0x8000, (latche & 0x1F) | (latche & ((latche & 0x40) >> 6))); + setprg16(0xC000, (latche & 0x18) | 7); + } else { + if (latche & 0x40) { // 16K mode + setprg16(0x8000, latche & 0x1F); + setprg16(0xC000, latche & 0x1F); + } else { + setprg32(0x8000, (latche >> 1) & 0x0F); + } + } + setmirror(((latche & 0x80) >> 7) ^ 1); +} + +void BMCG146_Init(CartInfo *info) { + Latch_Init(info, BMCG146Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ax5705.cpp b/branches/fceux-2.2.2/src/boards/ax5705.cpp new file mode 100644 index 00000000..82a4824b --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ax5705.cpp @@ -0,0 +1,116 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * + * Super Bros. Pocker Mali (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 IRQCount; //, IRQPre; +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; +static uint8 mirr; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 1, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { prg_reg, 2, "PRG" }, + { chr_reg, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +/* +static void UNLAX5705IRQ(void) +{ + if(IRQa) + { + IRQCount++; + if(IRQCount>=238) + { + X6502_IRQBegin(FCEU_IQEXT); +// IRQa=0; + } + } +}*/ + +static void Sync(void) { + setprg8(0x8000, prg_reg[0]); + setprg8(0xA000, prg_reg[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chr_reg[i]); + setmirror(mirr ^ 1); +} + +static DECLFW(UNLAX5705Write) { +// if((A>=0xA008)&&(A<=0xE003)) +// { +// int ind=(((A>>11)-6)|(A&1))&7; +// int sar=((A&2)<<1); +// chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<> 2) | (V & 5); break; // EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed + case 0x8008: mirr = V & 1; break; + case 0xA000: prg_reg[1] = ((V & 2) << 2) | ((V & 8) >> 2) | (V & 5); break; + case 0xA008: chr_reg[0] = (chr_reg[0] & 0xF0) | (V & 0x0F); break; + case 0xA009: chr_reg[0] = (chr_reg[0] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xA00A: chr_reg[1] = (chr_reg[1] & 0xF0) | (V & 0x0F); break; + case 0xA00B: chr_reg[1] = (chr_reg[1] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC000: chr_reg[2] = (chr_reg[2] & 0xF0) | (V & 0x0F); break; + case 0xC001: chr_reg[2] = (chr_reg[2] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC002: chr_reg[3] = (chr_reg[3] & 0xF0) | (V & 0x0F); break; + case 0xC003: chr_reg[3] = (chr_reg[3] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC008: chr_reg[4] = (chr_reg[4] & 0xF0) | (V & 0x0F); break; + case 0xC009: chr_reg[4] = (chr_reg[4] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC00A: chr_reg[5] = (chr_reg[5] & 0xF0) | (V & 0x0F); break; + case 0xC00B: chr_reg[5] = (chr_reg[5] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xE000: chr_reg[6] = (chr_reg[6] & 0xF0) | (V & 0x0F); break; + case 0xE001: chr_reg[6] = (chr_reg[6] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xE002: chr_reg[7] = (chr_reg[7] & 0xF0) | (V & 0x0F); break; + case 0xE003: chr_reg[7] = (chr_reg[7] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; +// case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break; +// case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/ break; + } + Sync(); +} + +static void UNLAX5705Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLAX5705Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLAX5705_Init(CartInfo *info) { + info->Power = UNLAX5705Power; +// GameHBIRQHook=UNLAX5705IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/bandai.cpp b/branches/fceux-2.2.2/src/boards/bandai.cpp new file mode 100644 index 00000000..98f849c5 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bandai.cpp @@ -0,0 +1,464 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * Copyright (C) 2011 FCEUX team + * + * 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 + * + * Bandai mappers + * + */ + +#include "mapinc.h" + +static uint8 reg[16], is153, x24c02; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { reg, 16, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, // need for Famicom Jump II - Saikyou no 7 Nin (J) [!] + { 0 } +}; + +// x24C0x interface + +#define X24C0X_STANDBY 0 +#define X24C0X_ADDRESS 1 +#define X24C0X_WORD 2 +#define X24C0X_READ 3 +#define X24C0X_WRITE 4 + +static uint8 x24c0x_data[256], x24c0x_state; +static uint8 x24c0x_addr, x24c0x_word, x24c0x_latch, x24c0x_bitcount; +static uint8 x24c0x_sda, x24c0x_scl, x24c0x_out, x24c0x_oe; + +static SFORMAT x24c0xStateRegs[] = +{ + { &x24c0x_addr, 1, "ADDR" }, + { &x24c0x_word, 1, "WORD" }, + { &x24c0x_latch, 1, "LATC" }, + { &x24c0x_bitcount, 1, "BITC" }, + { &x24c0x_sda, 1, "SDA" }, + { &x24c0x_scl, 1, "SCL" }, + { &x24c0x_out, 1, "OUT" }, + { &x24c0x_oe, 1, "OE" }, + { &x24c0x_state, 1, "STAT" }, + { 0 } +}; + +static void x24c0x_init() { + x24c0x_addr = x24c0x_word = x24c0x_latch = x24c0x_bitcount = x24c0x_sda = x24c0x_scl = x24c0x_oe = 0; + x24c0x_state = X24C0X_STANDBY; +} + +static void x24c0x_write(uint8 data) { + uint8 sda = (data >> 6) & 1; + uint8 scl = (data >> 5) & 1; + x24c0x_oe = (data >> 7); + + if(x24c0x_scl && scl) { + if(x24c0x_sda && !sda) { // START + x24c0x_state = X24C0X_ADDRESS; + x24c0x_bitcount = 0; + x24c0x_addr = 0; + } else if(!x24c0x_sda && sda) { //STOP + x24c0x_state = X24C0X_STANDBY; + } + } else if(!x24c0x_scl && scl) { // RISING EDGE + switch(x24c0x_state) { + case X24C0X_ADDRESS: + if(x24c0x_bitcount < 7) { + x24c0x_addr <<= 1; + x24c0x_addr |= sda; + } else { + if(!x24c02) // X24C01 mode + x24c0x_word = x24c0x_addr; + if(sda) { // READ COMMAND + x24c0x_state = X24C0X_READ; + } else { // WRITE COMMAND + if(x24c02) // X24C02 mode + x24c0x_state = X24C0X_WORD; + else + x24c0x_state = X24C0X_WRITE; + } + } + x24c0x_bitcount++; + break; + case X24C0X_WORD: + if(x24c0x_bitcount == 8) { // ACK + x24c0x_word = 0; + x24c0x_out = 0; + } else { // WORD ADDRESS INPUT + x24c0x_word <<= 1; + x24c0x_word |= sda; + if(x24c0x_bitcount == 16) { // END OF ADDRESS INPUT + x24c0x_bitcount = 7; + x24c0x_state = X24C0X_WRITE; + } + } + x24c0x_bitcount++; + break; + case X24C0X_READ: + if (x24c0x_bitcount == 8) { // ACK + x24c0x_out = 0; + x24c0x_latch = x24c0x_data[x24c0x_word]; + x24c0x_bitcount = 0; + } else { // REAL OUTPUT + x24c0x_out = x24c0x_latch >> 7; + x24c0x_latch <<= 1; + x24c0x_bitcount++; + if(x24c0x_bitcount == 8) { + x24c0x_word++; + x24c0x_word &= 0xff; + } + } + break; + case X24C0X_WRITE: + if (x24c0x_bitcount == 8) { // ACK + x24c0x_out = 0; + x24c0x_latch = 0; + x24c0x_bitcount = 0; + } else { // REAL INPUT + x24c0x_latch <<= 1; + x24c0x_latch |= sda; + x24c0x_bitcount++; + if(x24c0x_bitcount == 8) { + x24c0x_data[x24c0x_word] = x24c0x_latch; + x24c0x_word++; + x24c0x_word &= 0xff; + } + } + break; + } + } + + x24c0x_sda = sda; + x24c0x_scl = scl; +} + +static uint8 x24c0x_read() { + return x24c0x_out << 4; +} + +// + +static void Sync(void) { + if (is153) { + int base = (reg[0] & 1) << 4; + setchr8(0); + setprg16(0x8000, (reg[8] & 0x0F) | base); + setprg16(0xC000, 0x0F | base); + } else { + int i; + for (i = 0; i < 8; i++) setchr1(i << 10, reg[i]); + setprg16(0x8000, reg[8]); + setprg16(0xC000, ~0); + } + switch (reg[9] & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(BandaiWrite) { + A &= 0x0F; + if (A < 0x0A) { + reg[A & 0x0F] = V; + Sync(); + } else + switch (A) { + case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa = V & 1; IRQCount = IRQLatch; break; + case 0x0B: IRQLatch &= 0xFF00; IRQLatch |= V; break; + case 0x0C: IRQLatch &= 0xFF; IRQLatch |= V << 8; break; + case 0x0D: x24c0x_write(V); break; + } +} + +static DECLFR(BandaiRead) { + return (X.DB & 0xEF) | x24c0x_read(); +} + +static void BandaiIRQHook(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount < 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = -1; + } + } +} + +static void BandaiPower(void) { + IRQa = 0; + x24c0x_init(); + Sync(); + SetReadHandler(0x6000, 0x7FFF, BandaiRead); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, BandaiWrite); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper16_Init(CartInfo *info) { + x24c02 = 1; + is153 = 0; + info->Power = BandaiPower; + MapIRQHook = BandaiIRQHook; + + info->battery = 1; + info->SaveGame[0] = x24c0x_data; + info->SaveGameLen[0] = 256; + AddExState(x24c0x_data, 256, 0, "DATA"); + + GameStateRestore = StateRestore; + AddExState(&x24c0xStateRegs, ~0, 0, 0); + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper159_Init(CartInfo *info) { + x24c02 = 0; + is153 = 0; + info->Power = BandaiPower; + MapIRQHook = BandaiIRQHook; + + info->battery = 1; + info->SaveGame[0] = x24c0x_data; + info->SaveGameLen[0] = 128; + AddExState(x24c0x_data, 128, 0, "DATA"); + + GameStateRestore = StateRestore; + AddExState(&x24c0xStateRegs, ~0, 0, 0); + AddExState(&StateRegs, ~0, 0, 0); +} + +// Famicom jump 2: +// 0-7: Lower bit of data selects which 256KB PRG block is in use. +// This seems to be a hack on the developers' part, so I'll make emulation +// of it a hack(I think the current PRG block would depend on whatever the +// lowest bit of the CHR bank switching register that corresponds to the +// last CHR address read). + +static void M153Power(void) { + Sync(); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BandaiWrite); +} + + +static void M153Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper153_Init(CartInfo *info) { + is153 = 1; + info->Power = M153Power; + info->Close = M153Close; + MapIRQHook = BandaiIRQHook; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +// Datach Barcode Battler + +static uint8 BarcodeData[256]; +static int BarcodeReadPos; +static int BarcodeCycleCount; +static uint32 BarcodeOut; + +int FCEUI_DatachSet(const uint8 *rcode) { + int prefix_parity_type[10][6] = { + { 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 1, 1 }, { 0, 0, 1, 1, 0, 1 }, { 0, 0, 1, 1, 1, 0 }, + { 0, 1, 0, 0, 1, 1 }, { 0, 1, 1, 0, 0, 1 }, { 0, 1, 1, 1, 0, 0 }, { 0, 1, 0, 1, 0, 1 }, + { 0, 1, 0, 1, 1, 0 }, { 0, 1, 1, 0, 1, 0 } + }; + int data_left_odd[10][7] = { + { 0, 0, 0, 1, 1, 0, 1 }, { 0, 0, 1, 1, 0, 0, 1 }, { 0, 0, 1, 0, 0, 1, 1 }, { 0, 1, 1, 1, 1, 0, 1 }, + { 0, 1, 0, 0, 0, 1, 1 }, { 0, 1, 1, 0, 0, 0, 1 }, { 0, 1, 0, 1, 1, 1, 1 }, { 0, 1, 1, 1, 0, 1, 1 }, + { 0, 1, 1, 0, 1, 1, 1 }, { 0, 0, 0, 1, 0, 1, 1 } + }; + int data_left_even[10][7] = { + { 0, 1, 0, 0, 1, 1, 1 }, { 0, 1, 1, 0, 0, 1, 1 }, { 0, 0, 1, 1, 0, 1, 1 }, { 0, 1, 0, 0, 0, 0, 1 }, + { 0, 0, 1, 1, 1, 0, 1 }, { 0, 1, 1, 1, 0, 0, 1 }, { 0, 0, 0, 0, 1, 0, 1 }, { 0, 0, 1, 0, 0, 0, 1 }, + { 0, 0, 0, 1, 0, 0, 1 }, { 0, 0, 1, 0, 1, 1, 1 } + }; + int data_right[10][7] = { + { 1, 1, 1, 0, 0, 1, 0 }, { 1, 1, 0, 0, 1, 1, 0 }, { 1, 1, 0, 1, 1, 0, 0 }, { 1, 0, 0, 0, 0, 1, 0 }, + { 1, 0, 1, 1, 1, 0, 0 }, { 1, 0, 0, 1, 1, 1, 0 }, { 1, 0, 1, 0, 0, 0, 0 }, { 1, 0, 0, 0, 1, 0, 0 }, + { 1, 0, 0, 1, 0, 0, 0 }, { 1, 1, 1, 0, 1, 0, 0 } + }; + uint8 code[13 + 1]; + uint32 tmp_p = 0; + int i, j; + int len; + + for (i = len = 0; i < 13; i++) { + if (!rcode[i]) break; + if ((code[i] = rcode[i] - '0') > 9) + return(0); + len++; + } + if (len != 13 && len != 12 && len != 8 && len != 7) return(0); + + #define BS(x) BarcodeData[tmp_p] = x; tmp_p++ + + for (j = 0; j < 32; j++) { + BS(0x00); + } + + /* Left guard bars */ + BS(1); BS(0); BS(1); + + if (len == 13 || len == 12) { + uint32 csum; + + for (i = 0; i < 6; i++) + if (prefix_parity_type[code[0]][i]) { + for (j = 0; j < 7; j++) { + BS(data_left_even[code[i + 1]][j]); + } + } else + for (j = 0; j < 7; j++) { + BS(data_left_odd[code[i + 1]][j]); + } + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for (i = 7; i < 12; i++) + for (j = 0; j < 7; j++) { + BS(data_right[code[i]][j]); + } + csum = 0; + for (i = 0; i < 12; i++) csum += code[i] * ((i & 1) ? 3 : 1); + csum = (10 - (csum % 10)) % 10; + for (j = 0; j < 7; j++) { + BS(data_right[csum][j]); + } + } else if (len == 8 || len == 7) { + uint32 csum = 0; + + for (i = 0; i < 7; i++) csum += (i & 1) ? code[i] : (code[i] * 3); + + csum = (10 - (csum % 10)) % 10; + + for (i = 0; i < 4; i++) + for (j = 0; j < 7; j++) { + BS(data_left_odd[code[i]][j]); + } + + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for (i = 4; i < 7; i++) + for (j = 0; j < 7; j++) { + BS(data_right[code[i]][j]); + } + + for (j = 0; j < 7; j++) { + BS(data_right[csum][j]); + } + } + + /* Right guard bars */ + BS(1); BS(0); BS(1); + + for (j = 0; j < 32; j++) { + BS(0x00); + } + + BS(0xFF); + + #undef BS + + BarcodeReadPos = 0; + BarcodeOut = 0x8; + BarcodeCycleCount = 0; + return(1); +} + +static void BarcodeIRQHook(int a) { + BandaiIRQHook(a); + + BarcodeCycleCount += a; + + if (BarcodeCycleCount >= 1000) { + BarcodeCycleCount -= 1000; + if (BarcodeData[BarcodeReadPos] == 0xFF) { + BarcodeOut = 0; + } else { + BarcodeOut = (BarcodeData[BarcodeReadPos] ^ 1) << 3; + BarcodeReadPos++; + } + } +} + +static DECLFR(BarcodeRead) { + return BarcodeOut; +} + +static void M157Power(void) { + IRQa = 0; + BarcodeData[0] = 0xFF; + BarcodeReadPos = 0; + BarcodeOut = 0; + BarcodeCycleCount = 0; + + Sync(); + + SetWriteHandler(0x6000, 0xFFFF, BandaiWrite); + SetReadHandler(0x6000, 0x7FFF, BarcodeRead); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +void Mapper157_Init(CartInfo *info) { + is153 = 1; + info->Power = M157Power; + MapIRQHook = BarcodeIRQHook; + + GameInfo->cspecial = SIS_DATACH; + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/bb.cpp b/branches/fceux-2.2.2/src/boards/bb.cpp new file mode 100644 index 00000000..cdea2c20 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bb.cpp @@ -0,0 +1,63 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg, chr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &chr, 1, "CHR" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg & 3); + setprg32(0x8000, ~0); + setchr8(chr & 3); +} + +static DECLFW(UNLBBWrite) { + if ((A & 0x9000) == 0x8000) + reg = chr = V; + else + chr = V & 1; // hacky hacky, ProWres simplified FDS conversion 2-in-1 mapper + Sync(); +} + +static void UNLBBPower(void) { + chr = 0; + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLBBWrite); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLBB_Init(CartInfo *info) { + info->Power = UNLBBPower; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/bmc13in1jy110.cpp b/branches/fceux-2.2.2/src/boards/bmc13in1jy110.cpp new file mode 100644 index 00000000..f4190451 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bmc13in1jy110.cpp @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * BMC 42-in-1 "reset switch" type + */ + +#include "mapinc.h" + +static uint8 bank_mode; +static uint8 bank_value; +static uint8 prgb[4]; +static SFORMAT StateRegs[] = +{ + { &bank_mode, 1, "BNM" }, + { &bank_value, 1, "BMV" }, + { prgb, 4, "PRGB" }, + { 0 } +}; + +static void Sync(void) { +// FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]); + switch (bank_mode & 7) { + case 0: + setprg32(0x8000, bank_value & 7); break; + case 1: + setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]); + setprg16(0xC000, (bank_value & 7) >> 1); + case 4: + setprg32(0x8000, 8 + (bank_value & 7)); break; + case 5: + setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]); + setprg16(0xC000, ((8 + (bank_value & 7)) >> 1) + prgb[3]); + case 2: + setprg8(0x8000, prgb[0] >> 2); + setprg8(0xa000, prgb[1]); + setprg8(0xc000, prgb[2]); + setprg8(0xe000, ~0); + break; + case 3: + setprg8(0x8000, prgb[0]); + setprg8(0xa000, prgb[1]); + setprg8(0xc000, prgb[2]); + setprg8(0xe000, prgb[3]); + break; + } +} + +static DECLFW(BMC13in1JY110Write) { +// FCEU_printf("%04x:%04x\n",A,V); + switch (A) { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: prgb[A & 3] = V; break; + case 0xD000: bank_mode = V; break; + case 0xD001: setmirror(V & 3); + case 0xD002: break; + case 0xD003: bank_value = V; break; + } + Sync(); +} + +static void BMC13in1JY110Power(void) { + prgb[0] = prgb[1] = prgb[2] = prgb[3] = 0; + bank_mode = 0; + bank_value = 0; + setprg32(0x8000, 0); + setchr8(0); + SetWriteHandler(0x8000, 0xFFFF, BMC13in1JY110Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC13in1JY110_Init(CartInfo *info) { + info->Power = BMC13in1JY110Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/bmc42in1r.cpp b/branches/fceux-2.2.2/src/boards/bmc42in1r.cpp new file mode 100644 index 00000000..06d851ae --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bmc42in1r.cpp @@ -0,0 +1,86 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2009 qeed + * + * 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 + * + * BMC 42-in-1 "reset switch" + "select switch" + * + */ + +#include "mapinc.h" + +static uint8 isresetbased = 0; +static uint8 latche[2], reset; +static SFORMAT StateRegs[] = +{ + { &reset, 1, "RST" }, + { latche, 2, "LATC" }, + { 0 } +}; + +static void Sync(void) { + uint8 bank; + if (isresetbased) + bank = (latche[0] & 0x1f) | (reset << 5) | ((latche[1] & 1) << 6); + else + bank = (latche[0] & 0x1f) | ((latche[0] & 0x80) >> 2) | ((latche[1] & 1) << 6); + if (!(latche[0] & 0x20)) + setprg32(0x8000, bank >> 1); + else{ + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + setmirror((latche[0] >> 6) & 1); + setchr8(0); +} + +static DECLFW(M226Write) { + latche[A & 1] = V; + Sync(); +} + +static void M226Power(void) { + latche[0] = latche[1] = reset = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M226Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper226_Init(CartInfo *info) { + isresetbased = 0; + info->Power = M226Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} + +static void M233Reset(void) { + reset ^= 1; + Sync(); +} + +void Mapper233_Init(CartInfo *info) { + isresetbased = 1; + info->Power = M226Power; + info->Reset = M233Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/bmc64in1nr.cpp b/branches/fceux-2.2.2/src/boards/bmc64in1nr.cpp new file mode 100644 index 00000000..11102a32 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bmc64in1nr.cpp @@ -0,0 +1,83 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * BMC 42-in-1 "reset switch" type + */ + +#include "mapinc.h" + +static uint8 regs[4]; + +static SFORMAT StateRegs[] = +{ + { regs, 4, "REGS" }, + { 0 } +}; + +static void Sync(void) { + if (regs[0] & 0x80) { + if (regs[1] & 0x80) + setprg32(0x8000, regs[1] & 0x1F); + else{ + int bank = ((regs[1] & 0x1f) << 1) | ((regs[1] >> 6) & 1); + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else { + int bank = ((regs[1] & 0x1f) << 1) | ((regs[1] >> 6) & 1); + setprg16(0xC000, bank); + } + if (regs[0] & 0x20) + setmirror(MI_H); + else + setmirror(MI_V); + setchr8((regs[2] << 2) | ((regs[0] >> 1) & 3)); +} + +static DECLFW(BMC64in1nrWriteLo) { + regs[A & 3] = V; + Sync(); +} + +static DECLFW(BMC64in1nrWriteHi) { + regs[3] = V; + Sync(); +} + +static void BMC64in1nrPower(void) { + regs[0] = 0x80; + regs[1] = 0x43; + regs[2] = regs[3] = 0; + Sync(); + SetWriteHandler(0x5000, 0x5003, BMC64in1nrWriteLo); + SetWriteHandler(0x8000, 0xFFFF, BMC64in1nrWriteHi); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC64in1nr_Init(CartInfo *info) { + info->Power = BMC64in1nrPower; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} + + diff --git a/branches/fceux-2.2.2/src/boards/bmc70in1.cpp b/branches/fceux-2.2.2/src/boards/bmc70in1.cpp new file mode 100644 index 00000000..95c34370 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bmc70in1.cpp @@ -0,0 +1,121 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 is_large_banks, hw_switch; +static uint8 large_bank; +static uint8 prg_bank; +static uint8 chr_bank; +static uint8 bank_mode; +static uint8 mirroring; +static SFORMAT StateRegs[] = +{ + { &large_bank, 1, "LB" }, + { &hw_switch, 1, "DPSW" }, + { &prg_bank, 1, "PRG" }, + { &chr_bank, 1, "CHR" }, + { &bank_mode, 1, "BM" }, + { &mirroring, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + switch (bank_mode) { + case 0x00: + case 0x10: + setprg16(0x8000, large_bank | prg_bank); + setprg16(0xC000, large_bank | 7); + break; + case 0x20: + setprg32(0x8000, (large_bank | prg_bank) >> 1); + break; + case 0x30: + setprg16(0x8000, large_bank | prg_bank); + setprg16(0xC000, large_bank | prg_bank); + break; + } + setmirror(mirroring); + if (!is_large_banks) + setchr8(chr_bank); +} + +static DECLFR(BMC70in1Read) { + if (bank_mode == 0x10) +// if(is_large_banks) + return CartBR((A & 0xFFF0) | hw_switch); +// else +// return CartBR((A&0xFFF0)|hw_switch); + else + return CartBR(A); +} + +static DECLFW(BMC70in1Write) { + if (A & 0x4000) { + bank_mode = A & 0x30; + prg_bank = A & 7; + } else { + mirroring = ((A & 0x20) >> 5) ^ 1; + if (is_large_banks) + large_bank = (A & 3) << 3; + else + chr_bank = A & 7; + } + Sync(); +} + +static void BMC70in1Reset(void) { + bank_mode = 0; + large_bank = 0; + Sync(); + hw_switch++; + hw_switch &= 0xf; +} + +static void BMC70in1Power(void) { + setchr8(0); + bank_mode = 0; + large_bank = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, BMC70in1Read); + SetWriteHandler(0x8000, 0xffff, BMC70in1Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC70in1_Init(CartInfo *info) { + is_large_banks = 0; + hw_switch = 0xd; + info->Power = BMC70in1Power; + info->Reset = BMC70in1Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void BMC70in1B_Init(CartInfo *info) { + is_large_banks = 1; + hw_switch = 0x6; + info->Power = BMC70in1Power; + info->Reset = BMC70in1Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/bonza.cpp b/branches/fceux-2.2.2/src/boards/bonza.cpp new file mode 100644 index 00000000..58f04f2e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bonza.cpp @@ -0,0 +1,133 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 CaH4e3 + * + * 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 "mapinc.h" + +#define CARD_EXTERNAL_INSERED 0x80 + +static uint8 prg_reg; +static uint8 chr_reg; +static SFORMAT StateRegs[] = +{ + { &prg_reg, 1, "PREG" }, + { &chr_reg, 1, "CREG" }, + { 0 } +}; + +/* + +cmd[0] = response on/off + 0x00 - on + 0x80 - off +cmd[1] = cmd + + +_GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62 + +_SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0 +_SELECT_FILE_2_0201: .BYTE 0,$A4, 2, 0, 2, 2, 1 +_SELECT_FILE_2_0203: .BYTE 0,$A4, 2, 0, 2, 2, 3 +_SELECT_FILE_2_0204: .BYTE 0,$A4, 2, 0, 2, 2, 4 +_SELECT_FILE_2_0205: .BYTE 0,$A4, 2, 0, 2, 2, 5 +_SELECT_FILE_2_3F04: .BYTE 0,$A4, 2, 0, 2,$3F, 4 +_SELECT_FILE_2_4F00: .BYTE 0,$A4, 2, 0, 2,$4F, 0 + +_READ_BINARY_5: .BYTE 0,$B0,$85, 0, 2 +_READ_BINARY_6: .BYTE 0,$B0,$86, 0, 4 +_READ_BINARY_6_0: .BYTE 0,$B0,$86, 0,$18 +_READ_BINARY_0: .BYTE 0,$B0, 0, 2, 3 +_READ_BINARY_0_0: .BYTE 0,$B0, 0, 0, 4 +_READ_BINARY_0_1: .BYTE 0,$B0, 0, 0, $C +_READ_BINARY_0_2: .BYTE 0,$B0, 0, 0,$10 + +_UPDATE_BINARY: .BYTE 0,$D6, 0, 0, 4 +_UPDATE_BINARY_0: .BYTE 0,$D6, 0, 0,$10 + +_GET_RESPONSE: .BYTE $80,$C0, 2,$A1, 8 +_GET_RESPONSE_0: .BYTE 0,$C0, 0, 0, 2 +_GET_RESPONSE_1: .BYTE 0,$C0, 0, 0, 6 +_GET_RESPONSE_2: .BYTE 0,$C0, 0, 0, 8 +_GET_RESPONSE_3: .BYTE 0,$C0, 0, 0, $C +_GET_RESPONSE_4: .BYTE 0,$C0, 0, 0,$10 + +byte_8C0B: .BYTE $80,$30, 0, 2, $A, 0, 1 +byte_8C48: .BYTE $80,$32, 0, 1, 4 +byte_8C89: .BYTE $80,$34, 0, 0, 8, 0, 0 +byte_8D01: .BYTE $80,$36, 0, 0, $C +byte_8CA7: .BYTE $80,$38, 0, 2, 4 +byte_8BEC: .BYTE $80,$3A, 0, 3, 0 + +byte_89A0: .BYTE 0,$48, 0, 0, 6 +byte_8808: .BYTE 0,$54, 0, 0,$1C +byte_89BF: .BYTE 0,$58, 0, 0,$1C + +_MANAGE_CHANNEL: .BYTE 0,$70, 0, 0, 8 +byte_8CE5: .BYTE 0,$74, 0, 0,$12 +byte_8C29: .BYTE 0,$76, 0, 0, 8 +byte_8CC6: .BYTE 0,$78, 0, 0,$12 +*/ + +static uint8 sim0reset[0x1F] = { + 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE, + 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53, + 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 +}; + +static void Sync(void) { + setprg32(0x8000, prg_reg); + setchr8(chr_reg); +} + +static void StateRestore(int version) { + Sync(); +} + +static DECLFW(M216WriteHi) { + prg_reg = A & 1; + chr_reg = (A & 0x0E) >> 1; + Sync(); +} + +static DECLFW(M216Write5000) { +// FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt); +} + +static DECLFR(M216Read5000) { +// FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit); + return 0; +} + +static void Power(void) { + prg_reg = 0; + chr_reg = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M216WriteHi); + SetWriteHandler(0x5000, 0x5000, M216Write5000); + SetReadHandler(0x5000, 0x5000, M216Read5000); +} + + +void Mapper216_Init(CartInfo *info) { + info->Power = Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/bs-5.cpp b/branches/fceux-2.2.2/src/boards/bs-5.cpp new file mode 100644 index 00000000..5e2ff1fe --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/bs-5.cpp @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg_prg[4]; +static uint8 reg_chr[4]; +static uint8 dip_switch; + +static SFORMAT StateRegs[] = +{ + { reg_prg, 4, "PREG" }, + { reg_chr, 4, "CREG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, reg_prg[0]); + setprg8(0xa000, reg_prg[1]); + setprg8(0xc000, reg_prg[2]); + setprg8(0xe000, reg_prg[3]); + setchr2(0x0000, reg_chr[0]); + setchr2(0x0800, reg_chr[1]); + setchr2(0x1000, reg_chr[2]); + setchr2(0x1800, reg_chr[3]); + setmirror(MI_V); +} + +static DECLFW(MBS5Write) { + int bank_sel = (A & 0xC00) >> 10; + switch (A & 0xF000) { + case 0x8000: + reg_chr[bank_sel] = A & 0x1F; + break; + case 0xA000: + if (A & (1 << (dip_switch + 4))) + reg_prg[bank_sel] = A & 0x0F; + break; + } + Sync(); +} + +static void MBS5Reset(void) { + dip_switch++; + dip_switch &= 3; + reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0; + Sync(); +} + +static void MBS5Power(void) { + dip_switch = 0; + reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, MBS5Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMCBS5_Init(CartInfo *info) { + info->Power = MBS5Power; + info->Reset = MBS5Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/cityfighter.cpp b/branches/fceux-2.2.2/src/boards/cityfighter.cpp new file mode 100644 index 00000000..32149596 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/cityfighter.cpp @@ -0,0 +1,124 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * + * City Fighter IV sith Sound VRC4 hacked + */ + +#include "mapinc.h" + +static int32 IRQCount; +static uint8 IRQa; +static uint8 prg_reg, prg_mode, mirr; +static uint8 chr_reg[8]; +static writefunc pcmwrite; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { &prg_reg, 1, "PREG" }, + { &prg_mode, 1, "PMOD" }, + { &mirr, 1, "MIRR" }, + { chr_reg, 8, "CREG" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, prg_reg >> 2); + if (!prg_mode) + setprg8(0xC000, prg_reg); + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chr_reg[i]); + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(UNLCITYFIGHTWrite) { + //FCEU_printf("%04x %02x",A,V); + switch (A & 0xF00C) { + case 0x9000: prg_reg = V & 0xC; mirr = V & 3; break; + case 0x9004: + case 0x9008: + case 0x900C: + if (A & 0x800) + pcmwrite(0x4011, (V & 0xf) << 3); + else + prg_reg = V & 0xC; + break; + case 0xC000: + case 0xC004: + case 0xC008: + case 0xC00C: prg_mode = V & 1; break; + case 0xD000: chr_reg[0] = (chr_reg[0] & 0xF0) | (V & 0x0F); break; + case 0xD004: chr_reg[0] = (chr_reg[0] & 0x0F) | (V << 4); break; + case 0xD008: chr_reg[1] = (chr_reg[1] & 0xF0) | (V & 0x0F); break; + case 0xD00C: chr_reg[1] = (chr_reg[1] & 0x0F) | (V << 4); break; + case 0xA000: chr_reg[2] = (chr_reg[2] & 0xF0) | (V & 0x0F); break; + case 0xA004: chr_reg[2] = (chr_reg[2] & 0x0F) | (V << 4); break; + case 0xA008: chr_reg[3] = (chr_reg[3] & 0xF0) | (V & 0x0F); break; + case 0xA00C: chr_reg[3] = (chr_reg[3] & 0x0F) | (V << 4); break; + case 0xB000: chr_reg[4] = (chr_reg[4] & 0xF0) | (V & 0x0F); break; + case 0xB004: chr_reg[4] = (chr_reg[4] & 0x0F) | (V << 4); break; + case 0xB008: chr_reg[5] = (chr_reg[5] & 0xF0) | (V & 0x0F); break; + case 0xB00C: chr_reg[5] = (chr_reg[5] & 0x0F) | (V << 4); break; + case 0xE000: chr_reg[6] = (chr_reg[6] & 0xF0) | (V & 0x0F); break; + case 0xE004: chr_reg[6] = (chr_reg[6] & 0x0F) | (V << 4); break; + case 0xE008: chr_reg[7] = (chr_reg[7] & 0xF0) | (V & 0x0F); break; + case 0xE00C: chr_reg[7] = (chr_reg[7] & 0x0F) | (V << 4); break; + case 0xF000: IRQCount = ((IRQCount & 0x1E0) | ((V & 0xF) << 1)); break; + case 0xF004: IRQCount = ((IRQCount & 0x1E) | ((V & 0xF) << 5)); break; + case 0xF008: IRQa = V & 2; X6502_IRQEnd(FCEU_IQEXT); break; + default: + break; + } + Sync(); +} + +static void UNLCITYFIGHTIRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLCITYFIGHTPower(void) { + prg_reg = 0; + Sync(); + pcmwrite = GetWriteHandler(0x4011); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLCITYFIGHTWrite); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLCITYFIGHT_Init(CartInfo *info) { + info->Power = UNLCITYFIGHTPower; + MapIRQHook = UNLCITYFIGHTIRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/dance2000.cpp b/branches/fceux-2.2.2/src/boards/dance2000.cpp new file mode 100644 index 00000000..eb1841d4 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/dance2000.cpp @@ -0,0 +1,109 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 prg, mode; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint32 lastnt = 0; + +static SFORMAT StateRegs[] = +{ + { &prg, 1, "REGS" }, + { &mode, 1, "MODE" }, + { &lastnt, 4, "LSNT" }, + { 0 } +}; + +static void Sync(void) { + setmirror((mode ^ 1) & 1); + setprg8r(0x10, 0x6000, 0); + setchr4(0x0000, lastnt); + setchr4(0x1000, 1); + if (mode & 4) + setprg32(0x8000, prg & 7); + else { + setprg16(0x8000, prg & 0x0f); + setprg16(0xC000, 0); + } +} + +static DECLFW(UNLD2000Write) { + switch (A) { + case 0x5000: prg = V; Sync(); break; + case 0x5200: mode = V; if (mode & 4) Sync(); break; + } +} + +static DECLFR(UNLD2000Read) { + if (prg & 0x40) + return X.DB; + else + return CartBR(A); +} + +static void UNLD2000Power(void) { + prg = mode = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, UNLD2000Read); + SetWriteHandler(0x5000, 0x5FFF, UNLD2000Write); +} + +static void UNL2000Hook(uint32 A) { + if (mode & 2) { + if ((A & 0x3000) == 0x2000) { + uint32 curnt = A & 0x800; + if (curnt != lastnt) { + setchr4(0x0000, curnt >> 11); + lastnt = curnt; + } + } + } else { + lastnt = 0; + setchr4(0x0000, 0); + } +} + +static void UNLD2000Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLD2000_Init(CartInfo *info) { + info->Power = UNLD2000Power; + info->Close = UNLD2000Close; + PPU_hook = UNL2000Hook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/datalatch.cpp b/branches/fceux-2.2.2/src/boards/datalatch.cpp new file mode 100644 index 00000000..4b0177fe --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/datalatch.cpp @@ -0,0 +1,484 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" +#include "../ines.h" + +static uint8 latche, latcheinit, bus_conflict; +static uint16 addrreg0, addrreg1; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static void (*WSync)(void); + +static DECLFW(LatchWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); + if (bus_conflict) + latche = (V == CartBR(A)) ? V : 0; + else + latche = V; + WSync(); +} + +static void LatchPower(void) { + latche = latcheinit; + WSync(); + if (WRAM) { + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + } else { + SetReadHandler(0x8000, 0xFFFF, CartBR); + } + SetWriteHandler(addrreg0, addrreg1, LatchWrite); +} + +static void LatchClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1, uint8 wram, uint8 busc) { + bus_conflict = busc; + latcheinit = init; + addrreg0 = adr0; + addrreg1 = adr1; + WSync = proc; + info->Power = LatchPower; + info->Close = LatchClose; + GameStateRestore = StateRestore; + if (wram) { + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + AddExState(&latche, 1, 0, "LATC"); + AddExState(&bus_conflict, 1, 0, "BUSC"); +} + +//------------------ Map 0 --------------------------- + +#ifdef DEBUG_MAPPER +static DECLFW(NROMWrite) { + FCEU_printf("bs %04x %02x\n", A, V); + CartBW(A, V); +} +#endif + +static void NROMPower(void) { + setprg8r(0x10, 0x6000, 0); // Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + setchr8(0); + + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + + #ifdef DEBUG_MAPPER + SetWriteHandler(0x4020, 0xFFFF, NROMWrite); + #endif +} + +void NROM_Init(CartInfo *info) { + info->Power = NROMPower; + info->Close = LatchClose; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); +} + +//------------------ Map 2 --------------------------- + +static void UNROMSync(void) { + static uint32 mirror_in_use = 0; + if (PRGsize[0] <= 128 * 1024) { + setprg16(0x8000, latche & 0x7); + if (latche & 8) mirror_in_use = 1; + if (mirror_in_use) + setmirror(((latche >> 3) & 1) ^ 1); // Higway Star Hacked mapper + } else + setprg16(0x8000, latche & 0xf); + setprg16(0xc000, ~0); + setchr8(0); +} + +void UNROM_Init(CartInfo *info) { + Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 0, 1); +} + +//------------------ Map 3 --------------------------- + +static void CNROMSync(void) { + setchr8(latche); + setprg32(0x8000, 0); + setprg8r(0x10, 0x6000, 0); // Hayauchy IGO uses 2Kb or RAM +} + +void CNROM_Init(CartInfo *info) { + Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, 1); +} + +//------------------ Map 7 --------------------------- + +static void ANROMSync() { + setprg32(0x8000, latche & 0xF); + setmirror(MI_0 + ((latche >> 4) & 1)); + setchr8(0); +} + +void ANROM_Init(CartInfo *info) { + Latch_Init(info, ANROMSync, 0, 0x4020, 0xFFFF, 0, 0); +} + +//------------------ Map 8 --------------------------- + +static void M8Sync() { + setprg16(0x8000, latche >> 3); + setprg16(0xc000, 1); + setchr8(latche & 3); +} + +void Mapper8_Init(CartInfo *info) { + Latch_Init(info, M8Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 11 --------------------------- + +static void M11Sync(void) { + setprg32(0x8000, latche & 0xF); + setchr8(latche >> 4); +} + +void Mapper11_Init(CartInfo *info) { + Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +void Mapper144_Init(CartInfo *info) { + Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF, 0, 0); +} + +//------------------ Map 13 --------------------------- + +static void CPROMSync(void) { + setchr4(0x0000, 0); + setchr4(0x1000, latche & 3); + setprg32(0x8000, 0); +} + +void CPROM_Init(CartInfo *info) { + Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 38 --------------------------- + +static void M38Sync(void) { + setprg32(0x8000, latche & 3); + setchr8(latche >> 2); +} + +void Mapper38_Init(CartInfo *info) { + Latch_Init(info, M38Sync, 0, 0x7000, 0x7FFF, 0, 0); +} + +//------------------ Map 66 --------------------------- + +static void MHROMSync(void) { + setprg32(0x8000, latche >> 4); + setchr8(latche & 0xF); +} + +void MHROM_Init(CartInfo *info) { + Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 70 --------------------------- + +static void M70Sync() { + setprg16(0x8000, latche >> 4); + setprg16(0xc000, ~0); + setchr8(latche & 0xf); +} + +void Mapper70_Init(CartInfo *info) { + Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 78 --------------------------- +/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ +static void M78Sync() { + setprg16(0x8000, (latche & 7)); + setprg16(0xc000, ~0); + setchr8(latche >> 4); + setmirror(MI_0 + ((latche >> 3) & 1)); +} + +void Mapper78_Init(CartInfo *info) { + Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 86 --------------------------- + +static void M86Sync(void) { + setprg32(0x8000, (latche >> 4) & 3); + setchr8((latche & 3) | ((latche >> 4) & 4)); +} + +void Mapper86_Init(CartInfo *info) { + Latch_Init(info, M86Sync, ~0, 0x6000, 0x6FFF, 0, 0); +} + +//------------------ Map 87 --------------------------- + +static void M87Sync(void) { + setprg32(0x8000, 0); + setchr8(((latche >> 1) & 1) | ((latche << 1) & 2)); +} + +void Mapper87_Init(CartInfo *info) { + Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0); +} + +//------------------ Map 89 --------------------------- + +static void M89Sync(void) { + setprg16(0x8000, (latche >> 4) & 7); + setprg16(0xc000, ~0); + setchr8((latche & 7) | ((latche >> 4) & 8)); + setmirror(MI_0 + ((latche >> 3) & 1)); +} + +void Mapper89_Init(CartInfo *info) { + Latch_Init(info, M89Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 93 --------------------------- + +static void SSUNROMSync(void) { + setprg16(0x8000, latche >> 4); + setprg16(0xc000, ~0); + setchr8(0); +} + +void SUNSOFT_UNROM_Init(CartInfo *info) { + Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 94 --------------------------- + +static void M94Sync(void) { + setprg16(0x8000, latche >> 2); + setprg16(0xc000, ~0); + setchr8(0); +} + +void Mapper94_Init(CartInfo *info) { + Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 97 --------------------------- + +static void M97Sync(void) { + setchr8(0); + setprg16(0x8000, ~0); + setprg16(0xc000, latche & 15); + switch (latche >> 6) { + case 0: break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_V); break; + case 3: break; + } + setchr8(((latche >> 1) & 1) | ((latche << 1) & 2)); +} + +void Mapper97_Init(CartInfo *info) { + Latch_Init(info, M97Sync, ~0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 101 --------------------------- + +static void M101Sync(void) { + setprg32(0x8000, 0); + setchr8(latche); +} + +void Mapper101_Init(CartInfo *info) { + Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF, 0, 0); +} + +//------------------ Map 107 --------------------------- + +static void M107Sync(void) { + setprg32(0x8000, (latche >> 1) & 3); + setchr8(latche & 7); +} + +void Mapper107_Init(CartInfo *info) { + Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 113 --------------------------- + +static void M113Sync(void) { + setprg32(0x8000, (latche >> 3) & 7); + setchr8(((latche >> 3) & 8) | (latche & 7)); +// setmirror(latche>>7); // only for HES 6in1 +} + +void Mapper113_Init(CartInfo *info) { + Latch_Init(info, M113Sync, 0, 0x4100, 0x7FFF, 0, 0); +} + +//------------------ Map 140 --------------------------- + +void Mapper140_Init(CartInfo *info) { + Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0); +} + +//------------------ Map 152 --------------------------- + +static void M152Sync() { + setprg16(0x8000, (latche >> 4) & 7); + setprg16(0xc000, ~0); + setchr8(latche & 0xf); + setmirror(MI_0 + ((latche >> 7) & 1)); /* Saint Seiya...hmm. */ +} + +void Mapper152_Init(CartInfo *info) { + Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 180 --------------------------- + +static void M180Sync(void) { + setprg16(0x8000, 0); + setprg16(0xc000, latche); + setchr8(0); +} + +void Mapper180_Init(CartInfo *info) { + Latch_Init(info, M180Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 184 --------------------------- + +static void M184Sync(void) { + setchr4(0x0000, latche); + setchr4(0x1000, latche >> 4); + setprg32(0x8000, 0); +} + +void Mapper184_Init(CartInfo *info) { + Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0); +} + +//------------------ Map 203 --------------------------- + +static void M203Sync(void) { + setprg16(0x8000, (latche >> 2) & 3); + setprg16(0xC000, (latche >> 2) & 3); + setchr8(latche & 3); +} + +void Mapper203_Init(CartInfo *info) { + Latch_Init(info, M203Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 240 --------------------------- + +static void M240Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, latche >> 4); + setchr8(latche & 0xF); +} + +void Mapper240_Init(CartInfo *info) { + Latch_Init(info, M240Sync, 0, 0x4020, 0x5FFF, 1, 0); +} + +//------------------ Map 241 --------------------------- +// Mapper 7 mostly, but with SRAM or maybe prot circuit +// figure out, which games do need 5xxx area reading + +static void M241Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + if (latche & 0x80) + setprg32(0x8000, latche | 8); // no 241 actually, but why not afterall? + else + setprg32(0x8000, latche); +} + +void Mapper241_Init(CartInfo *info) { + Latch_Init(info, M241Sync, 0, 0x8000, 0xFFFF, 1, 0); +} + +//------------------ A65AS --------------------------- + +// actually, there is two cart in one... First have extra mirroring +// mode (one screen) and 32K bankswitching, second one have only +// 16 bankswitching mode and normal mirroring... But there is no any +// correlations between modes and they can be used in one mapper code. + +static void BMCA65ASSync(void) { + if (latche & 0x40) + setprg32(0x8000, (latche >> 1) & 0x0F); + else { + setprg16(0x8000, ((latche & 0x30) >> 1) | (latche & 7)); + setprg16(0xC000, ((latche & 0x30) >> 1) | 7); + } + setchr8(0); + if (latche & 0x80) + setmirror(MI_0 + (((latche >> 5) & 1))); + else + setmirror(((latche >> 3) & 1) ^ 1); +} + +void BMCA65AS_Init(CartInfo *info) { + Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ BMC-11160 --------------------------- +// Simple BMC discrete mapper by TXC + +static void BMC11160Sync(void) { + uint32 bank = (latche >> 4) & 7; + setprg32(0x8000, bank); + setchr8((bank << 2) | (latche & 3)); + setmirror((latche >> 7) & 1); +} + +void BMC11160_Init(CartInfo *info) { + Latch_Init(info, BMC11160Sync, 0, 0x8000, 0xFFFF, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/dream.cpp b/branches/fceux-2.2.2/src/boards/dream.cpp new file mode 100644 index 00000000..c42fa0f9 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/dream.cpp @@ -0,0 +1,51 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 latche; + +static void Sync(void) { + setprg16(0x8000, latche); + setprg16(0xC000, 8); +} + +static DECLFW(DREAMWrite) { + latche = V & 7; + Sync(); +} + +static void DREAMPower(void) { + latche = 0; + Sync(); + setchr8(0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x5020, 0x5020, DREAMWrite); +} + +static void Restore(int version) { + Sync(); +} + +void DreamTech01_Init(CartInfo *info) { + GameStateRestore = Restore; + info->Power = DREAMPower; + AddExState(&latche, 1, 0, "LATC"); +} diff --git a/branches/fceux-2.2.2/src/boards/edu2000.cpp b/branches/fceux-2.2.2/src/boards/edu2000.cpp new file mode 100644 index 00000000..a8726391 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/edu2000.cpp @@ -0,0 +1,77 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 *WRAM = NULL; +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, (reg & 0xC0) >> 6); + setprg32(0x8000, reg & 0x1F); +// setmirror(((reg&0x20)>>5)); +} + +static DECLFW(UNLEDU2000HiWrite) { +// FCEU_printf("%04x:%02x\n",A,V); + reg = V; + Sync(); +} + +static void UNLEDU2000Power(void) { + setmirror(MI_0); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, UNLEDU2000HiWrite); + reg = 0; + Sync(); +} + +static void UNLEDU2000Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void UNLEDU2000Restore(int version) { + Sync(); +} + +void UNLEDU2000_Init(CartInfo *info) { + info->Power = UNLEDU2000Power; + info->Close = UNLEDU2000Close; + GameStateRestore = UNLEDU2000Restore; + WRAM = (uint8*)FCEU_gmalloc(32768); + SetupCartPRGMapping(0x10, WRAM, 32768, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = 32768; + } + AddExState(WRAM, 32768, 0, "WRAM"); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/emu2413.c b/branches/fceux-2.2.2/src/boards/emu2413.c new file mode 100644 index 00000000..240aeb00 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/emu2413.c @@ -0,0 +1,1078 @@ +/*********************************************************************************** + + emu2413.c -- YM2413 emulator written by Mitsutaka Okazaki 2001 + + 2001 01-08 : Version 0.10 -- 1st version. + 2001 01-15 : Version 0.20 -- semi-public version. + 2001 01-16 : Version 0.30 -- 1st public version. + 2001 01-17 : Version 0.31 -- Fixed bassdrum problem. + : Version 0.32 -- LPF implemented. + 2001 01-18 : Version 0.33 -- Fixed the drum problem, refine the mix-down method. + -- Fixed the LFO bug. + 2001 01-24 : Version 0.35 -- Fixed the drum problem, + support undocumented EG behavior. + 2001 02-02 : Version 0.38 -- Improved the performance. + Fixed the hi-hat and cymbal model. + Fixed the default percussive datas. + Noise reduction. + Fixed the feedback problem. + 2001 03-03 : Version 0.39 -- Fixed some drum bugs. + Improved the performance. + 2001 03-04 : Version 0.40 -- Improved the feedback. + Change the default table size. + Clock and Rate can be changed during play. + 2001 06-24 : Version 0.50 -- Improved the hi-hat and the cymbal tone. + Added VRC7 patch (OPLL_reset_patch is changed). + Fixed OPLL_reset() bug. + Added OPLL_setMask, OPLL_getMask and OPLL_toggleMask. + Added OPLL_writeIO. + 2001 09-28 : Version 0.51 -- Removed the noise table. + 2002 01-28 : Version 0.52 -- Added Stereo mode. + 2002 02-07 : Version 0.53 -- Fixed some drum bugs. + 2002 02-20 : Version 0.54 -- Added the best quality mode. + 2002 03-02 : Version 0.55 -- Removed OPLL_init & OPLL_close. + 2002 05-30 : Version 0.60 -- Fixed HH&CYM generator and all voice datas. + + 2004 01-24 : Modified by xodnizel to remove code not needed for the VRC7, among other things. + + References: + fmopl.c -- 1999,2000 written by Tatsuyuki Satoh (MAME development). + fmopl.c(fixed) -- (C) 2002 Jarek Burczynski. + s_opl.c -- 2001 written by Mamiya (NEZplug development). + fmgen.cpp -- 1999,2000 written by cisc. + fmpac.ill -- 2000 created by NARUTO. + MSX-Datapack + YMU757 data sheet + YM2143 data sheet + +**************************************************************************************/ +#include +#include +#include +#include +#include "emu2413.h" + +static const unsigned char default_inst[15][8] = { + /* VRC7 instruments, January 17, 2004 update -Xodnizel */ + { 0x03, 0x21, 0x04, 0x06, 0x8D, 0xF2, 0x42, 0x17 }, + { 0x13, 0x41, 0x05, 0x0E, 0x99, 0x96, 0x63, 0x12 }, + { 0x31, 0x11, 0x10, 0x0A, 0xF0, 0x9C, 0x32, 0x02 }, + { 0x21, 0x61, 0x1D, 0x07, 0x9F, 0x64, 0x20, 0x27 }, + { 0x22, 0x21, 0x1E, 0x06, 0xF0, 0x76, 0x08, 0x28 }, + { 0x02, 0x01, 0x06, 0x00, 0xF0, 0xF2, 0x03, 0x95 }, + { 0x21, 0x61, 0x1C, 0x07, 0x82, 0x81, 0x16, 0x07 }, + { 0x23, 0x21, 0x1A, 0x17, 0xEF, 0x82, 0x25, 0x15 }, + { 0x25, 0x11, 0x1F, 0x00, 0x86, 0x41, 0x20, 0x11 }, + { 0x85, 0x01, 0x1F, 0x0F, 0xE4, 0xA2, 0x11, 0x12 }, + { 0x07, 0xC1, 0x2B, 0x45, 0xB4, 0xF1, 0x24, 0xF4 }, + { 0x61, 0x23, 0x11, 0x06, 0x96, 0x96, 0x13, 0x16 }, + { 0x01, 0x02, 0xD3, 0x05, 0x82, 0xA2, 0x31, 0x51 }, + { 0x61, 0x22, 0x0D, 0x02, 0xC3, 0x7F, 0x24, 0x05 }, + { 0x21, 0x62, 0x0E, 0x00, 0xA1, 0xA0, 0x44, 0x17 }, +}; + +/* Size of Sintable ( 8 -- 18 can be used. 9 recommended.)*/ +#define PG_BITS 9 +#define PG_WIDTH (1 << PG_BITS) + +/* Phase increment counter */ +#define DP_BITS 18 +#define DP_WIDTH (1 << DP_BITS) +#define DP_BASE_BITS (DP_BITS - PG_BITS) + +/* Dynamic range (Accuracy of sin table) */ +#define DB_BITS 8 +#define DB_STEP (48.0 / (1 << DB_BITS)) +#define DB_MUTE (1 << DB_BITS) + +/* Dynamic range of envelope */ +#define EG_STEP 0.375 +#define EG_BITS 7 +#define EG_MUTE (1 << EG_BITS) + +/* Dynamic range of total level */ +#define TL_STEP 0.75 +#define TL_BITS 6 +#define TL_MUTE (1 << TL_BITS) + +/* Dynamic range of sustine level */ +#define SL_STEP 3.0 +#define SL_BITS 4 +#define SL_MUTE (1 << SL_BITS) + +#define EG2DB(d) ((d) * (int32)(EG_STEP / DB_STEP)) +#define TL2EG(d) ((d) * (int32)(TL_STEP / EG_STEP)) +#define SL2EG(d) ((d) * (int32)(SL_STEP / EG_STEP)) + +#define DB_POS(x) (uint32)((x) / DB_STEP) +#define DB_NEG(x) (uint32)(DB_MUTE + DB_MUTE + (x) / DB_STEP) + +/* Bits for liner value */ +#define DB2LIN_AMP_BITS 11 +#define SLOT_AMP_BITS (DB2LIN_AMP_BITS) + +/* Bits for envelope phase incremental counter */ +#define EG_DP_BITS 22 +#define EG_DP_WIDTH (1 << EG_DP_BITS) + +/* Bits for Pitch and Amp modulator */ +#define PM_PG_BITS 8 +#define PM_PG_WIDTH (1 << PM_PG_BITS) +#define PM_DP_BITS 16 +#define PM_DP_WIDTH (1 << PM_DP_BITS) +#define AM_PG_BITS 8 +#define AM_PG_WIDTH (1 << AM_PG_BITS) +#define AM_DP_BITS 16 +#define AM_DP_WIDTH (1 << AM_DP_BITS) + +/* PM table is calcurated by PM_AMP * pow(2,PM_DEPTH*sin(x)/1200) */ +#define PM_AMP_BITS 8 +#define PM_AMP (1 << PM_AMP_BITS) + +/* PM speed(Hz) and depth(cent) */ +#define PM_SPEED 6.4 +#define PM_DEPTH 13.75 + +/* AM speed(Hz) and depth(dB) */ +#define AM_SPEED 3.7 +//#define AM_DEPTH 4.8 +#define AM_DEPTH 2.4 + +/* Cut the lower b bit(s) off. */ +#define HIGHBITS(c, b) ((c) >> (b)) + +/* Leave the lower b bit(s). */ +#define LOWBITS(c, b) ((c) & ((1 << (b)) - 1)) + +/* Expand x which is s bits to d bits. */ +#define EXPAND_BITS(x, s, d) ((x) << ((d) - (s))) + +/* Expand x which is s bits to d bits and fill expanded bits '1' */ +#define EXPAND_BITS_X(x, s, d) (((x) << ((d) - (s))) | ((1 << ((d) - (s))) - 1)) + +/* Adjust envelope speed which depends on sampling rate. */ +#define rate_adjust(x) (rate == 49716 ? x : (uint32)((double)(x) * clk / 72 / rate + 0.5)) /* added 0.5 to round the value*/ + +#define MOD(o, x) (&(o)->slot[(x) << 1]) +#define CAR(o, x) (&(o)->slot[((x) << 1) | 1]) + +#define BIT(s, b) (((s) >> (b)) & 1) + +/* Input clock */ +static uint32 clk = 844451141; +/* Sampling rate */ +static uint32 rate = 3354932; + +/* WaveTable for each envelope amp */ +static uint16 fullsintable[PG_WIDTH]; +static uint16 halfsintable[PG_WIDTH]; + +static uint16 *waveform[2] = { fullsintable, halfsintable }; + +/* LFO Table */ +static int32 pmtable[PM_PG_WIDTH]; +static int32 amtable[AM_PG_WIDTH]; + +/* Phase delta for LFO */ +static uint32 pm_dphase; +static uint32 am_dphase; + +/* dB to Liner table */ +static int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2]; + +/* Liner to Log curve conversion table (for Attack rate). */ +static uint16 AR_ADJUST_TABLE[1 << EG_BITS]; + +/* Definition of envelope mode */ +enum +{ SETTLE, ATTACK, DECAY, SUSHOLD, SUSTINE, RELEASE, FINISH }; + +/* Phase incr table for Attack */ +static uint32 dphaseARTable[16][16]; +/* Phase incr table for Decay and Release */ +static uint32 dphaseDRTable[16][16]; + +/* KSL + TL Table */ +static uint32 tllTable[16][8][1 << TL_BITS][4]; +static int32 rksTable[2][8][2]; + +/* Phase incr table for PG */ +static uint32 dphaseTable[512][8][16]; + +/*************************************************** + + Create tables + +****************************************************/ +INLINE static int32 Min(int32 i, int32 j) { + if (i < j) + return i; + else + return j; +} + +/* Table for AR to LogCurve. */ +static void makeAdjustTable(void) { + int32 i; + + AR_ADJUST_TABLE[0] = (1 << EG_BITS); + for (i = 1; i < 128; i++) + AR_ADJUST_TABLE[i] = (uint16)((double)(1 << EG_BITS) - 1 - (1 << EG_BITS) * log(i) / log(128)); +} + + +/* Table for dB(0 -- (1<= DB_MUTE) DB2LIN_TABLE[i] = 0; + DB2LIN_TABLE[i + DB_MUTE + DB_MUTE] = (int16)(-DB2LIN_TABLE[i]); + } +} + +/* Liner(+0.0 - +1.0) to dB((1<> (20 - DP_BITS)); +} + +static void makeTllTable(void) { +#define dB2(x) ((x) * 2) + + static double kltable[16] = { + dB2(0.000), dB2(9.000), dB2(12.000), dB2(13.875), dB2(15.000), dB2(16.125), dB2(16.875), dB2(17.625), + dB2(18.000), dB2(18.750), dB2(19.125), dB2(19.500), dB2(19.875), dB2(20.250), dB2(20.625), dB2(21.000) + }; + + int32 tmp; + int32 fnum, block, TL, KL; + + for (fnum = 0; fnum < 16; fnum++) + for (block = 0; block < 8; block++) + for (TL = 0; TL < 64; TL++) + for (KL = 0; KL < 4; KL++) { + if (KL == 0) { + tllTable[fnum][block][TL][KL] = TL2EG(TL); + } else { + tmp = (int32)(kltable[fnum] - dB2(3.000) * (7 - block)); + if (tmp <= 0) + tllTable[fnum][block][TL][KL] = TL2EG(TL); + else + tllTable[fnum][block][TL][KL] = (uint32)((tmp >> (3 - KL)) / EG_STEP) + TL2EG(TL); + } + } +} + +/* Rate Table for Attack */ +static void makeDphaseARTable(void) { + int32 AR, Rks, RM, RL; + for (AR = 0; AR < 16; AR++) + for (Rks = 0; Rks < 16; Rks++) { + RM = AR + (Rks >> 2); + RL = Rks & 3; + if (RM > 15) + RM = 15; + switch (AR) { + case 0: + dphaseARTable[AR][Rks] = 0; + break; + case 15: + dphaseARTable[AR][Rks] = 0; /*EG_DP_WIDTH;*/ + break; + default: + dphaseARTable[AR][Rks] = rate_adjust(3 * (RL + 4) << (RM + 1)); + break; + } + } +} + +/* Rate Table for Decay and Release */ +static void makeDphaseDRTable(void) { + int32 DR, Rks, RM, RL; + + for (DR = 0; DR < 16; DR++) + for (Rks = 0; Rks < 16; Rks++) { + RM = DR + (Rks >> 2); + RL = Rks & 3; + if (RM > 15) + RM = 15; + switch (DR) { + case 0: + dphaseDRTable[DR][Rks] = 0; + break; + default: + dphaseDRTable[DR][Rks] = rate_adjust((RL + 4) << (RM - 1)); + break; + } + } +} + +static void makeRksTable(void) { + int32 fnum8, block, KR; + + for (fnum8 = 0; fnum8 < 2; fnum8++) + for (block = 0; block < 8; block++) + for (KR = 0; KR < 2; KR++) { + if (KR != 0) + rksTable[fnum8][block][KR] = (block << 1) + fnum8; + else + rksTable[fnum8][block][KR] = block >> 1; + } +} + +/************************************************************ + + Calc Parameters + +************************************************************/ + +INLINE static uint32 calc_eg_dphase(OPLL_SLOT * slot) { + switch (slot->eg_mode) { + case ATTACK: + return dphaseARTable[slot->patch.AR][slot->rks]; + + case DECAY: + return dphaseDRTable[slot->patch.DR][slot->rks]; + + case SUSHOLD: + return 0; + + case SUSTINE: + return dphaseDRTable[slot->patch.RR][slot->rks]; + + case RELEASE: + if (slot->sustine) + return dphaseDRTable[5][slot->rks]; + else if (slot->patch.EG) + return dphaseDRTable[slot->patch.RR][slot->rks]; + else + return dphaseDRTable[7][slot->rks]; + + case FINISH: + return 0; + + default: + return 0; + } +} + +/************************************************************* + + OPLL internal interfaces + +*************************************************************/ + +#define UPDATE_PG(S) (S)->dphase = dphaseTable[(S)->fnum][(S)->block][(S)->patch.ML] +#define UPDATE_TLL(S) \ + (((S)->type == 0) ? \ + ((S)->tll = tllTable[((S)->fnum) >> 5][(S)->block][(S)->patch.TL][(S)->patch.KL]) : \ + ((S)->tll = tllTable[((S)->fnum) >> 5][(S)->block][(S)->volume][(S)->patch.KL])) +#define UPDATE_RKS(S) (S)->rks = rksTable[((S)->fnum) >> 8][(S)->block][(S)->patch.KR] +#define UPDATE_WF(S) (S)->sintbl = waveform[(S)->patch.WF] +#define UPDATE_EG(S) (S)->eg_dphase = calc_eg_dphase(S) +#define UPDATE_ALL(S) \ + UPDATE_PG(S); \ + UPDATE_TLL(S); \ + UPDATE_RKS(S); \ + UPDATE_WF(S); \ + UPDATE_EG(S) /* EG should be updated last. */ + + +/* Slot key on */ +INLINE static void slotOn(OPLL_SLOT * slot) { + slot->eg_mode = ATTACK; + slot->eg_phase = 0; + slot->phase = 0; +} + +/* Slot key on without reseting the phase */ +INLINE static void slotOn2(OPLL_SLOT * slot) { + slot->eg_mode = ATTACK; + slot->eg_phase = 0; +} + +/* Slot key off */ +INLINE static void slotOff(OPLL_SLOT * slot) { + if (slot->eg_mode == ATTACK) + slot->eg_phase = EXPAND_BITS(AR_ADJUST_TABLE[HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS)], EG_BITS, EG_DP_BITS); + slot->eg_mode = RELEASE; +} + +/* Channel key on */ +INLINE static void keyOn(OPLL * opll, int32 i) { + if (!opll->slot_on_flag[i * 2]) + slotOn(MOD(opll, i)); + if (!opll->slot_on_flag[i * 2 + 1]) + slotOn(CAR(opll, i)); + opll->key_status[i] = 1; +} + +/* Channel key off */ +INLINE static void keyOff(OPLL * opll, int32 i) { + if (opll->slot_on_flag[i * 2 + 1]) + slotOff(CAR(opll, i)); + opll->key_status[i] = 0; +} + +/* Set sustine parameter */ +INLINE static void setSustine(OPLL * opll, int32 c, int32 sustine) { + CAR(opll, c)->sustine = sustine; + if (MOD(opll, c)->type) + MOD(opll, c)->sustine = sustine; +} + +/* Volume : 6bit ( Volume register << 2 ) */ +INLINE static void setVolume(OPLL * opll, int32 c, int32 volume) { + CAR(opll, c)->volume = volume; +} + +INLINE static void setSlotVolume(OPLL_SLOT * slot, int32 volume) { + slot->volume = volume; +} + +/* Set F-Number ( fnum : 9bit ) */ +INLINE static void setFnumber(OPLL * opll, int32 c, int32 fnum) { + CAR(opll, c)->fnum = fnum; + MOD(opll, c)->fnum = fnum; +} + +/* Set Block data (block : 3bit ) */ +INLINE static void setBlock(OPLL * opll, int32 c, int32 block) { + CAR(opll, c)->block = block; + MOD(opll, c)->block = block; +} + +INLINE static void update_key_status(OPLL * opll) { int ch; + + for (ch = 0; ch < 6; ch++) + opll->slot_on_flag[ch * 2] = opll->slot_on_flag[ch * 2 + 1] = (opll->HiFreq[ch]) & 0x10; +} + +/*********************************************************** + + Initializing + +***********************************************************/ + +static void OPLL_SLOT_reset(OPLL_SLOT * slot, int type) { + slot->type = type; + slot->sintbl = waveform[0]; + slot->phase = 0; + slot->dphase = 0; + slot->output[0] = 0; + slot->output[1] = 0; + slot->feedback = 0; + slot->eg_mode = SETTLE; + slot->eg_phase = EG_DP_WIDTH; + slot->eg_dphase = 0; + slot->rks = 0; + slot->tll = 0; + slot->sustine = 0; + slot->fnum = 0; + slot->block = 0; + slot->volume = 0; + slot->pgout = 0; + slot->egout = 0; +} + +static void internal_refresh(void) { + makeDphaseTable(); + makeDphaseARTable(); + makeDphaseDRTable(); + pm_dphase = (uint32)rate_adjust(PM_SPEED * PM_DP_WIDTH / (clk / 72)); + am_dphase = (uint32)rate_adjust(AM_SPEED * AM_DP_WIDTH / (clk / 72)); +} + +static void maketables(uint32 c, uint32 r) { + if (c != clk) { + clk = c; + makePmTable(); + makeAmTable(); + makeDB2LinTable(); + makeAdjustTable(); + makeTllTable(); + makeRksTable(); + makeSinTable(); + //makeDefaultPatch (); + } + + if (r != rate) { + rate = r; + internal_refresh(); + } +} + +OPLL *OPLL_new(uint32 clk, uint32 rate) { + OPLL *opll; + + maketables(clk, rate); + + opll = (OPLL*)calloc(sizeof(OPLL), 1); + if (opll == NULL) + return NULL; + + opll->mask = 0; + + OPLL_reset(opll); + + return opll; +} + + +void OPLL_delete(OPLL * opll) { + free(opll); +} + +/* Reset whole of OPLL except patch datas. */ +void OPLL_reset(OPLL * opll) { + int32 i; + + if (!opll) + return; + + opll->adr = 0; + opll->out = 0; + + opll->pm_phase = 0; + opll->am_phase = 0; + + opll->mask = 0; + + for (i = 0; i < 12; i++) + OPLL_SLOT_reset(&opll->slot[i], i % 2); + + for (i = 0; i < 6; i++) { + opll->key_status[i] = 0; + //setPatch (opll, i, 0); + } + + for (i = 0; i < 0x40; i++) + OPLL_writeReg(opll, i, 0); + + opll->realstep = (uint32)((1 << 31) / rate); + opll->opllstep = (uint32)((1 << 31) / (clk / 72)); + opll->oplltime = 0; +} + +/* Force Refresh (When external program changes some parameters). */ +void OPLL_forceRefresh(OPLL * opll) { + int32 i; + + if (opll == NULL) + return; + + for (i = 0; i < 12; i++) { + UPDATE_PG(&opll->slot[i]); + UPDATE_RKS(&opll->slot[i]); + UPDATE_TLL(&opll->slot[i]); + UPDATE_WF(&opll->slot[i]); + UPDATE_EG(&opll->slot[i]); + } +} + +void OPLL_set_rate(OPLL * opll, uint32 r) { + if (opll->quality) + rate = 49716; + else + rate = r; + internal_refresh(); + rate = r; +} + +void OPLL_set_quality(OPLL * opll, uint32 q) { + opll->quality = q; + OPLL_set_rate(opll, rate); +} + +/********************************************************* + + Generate wave data + +*********************************************************/ +/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 2PI). */ +#if (SLOT_AMP_BITS - PG_BITS) > 0 +#define wave2_2pi(e) ((e) >> (SLOT_AMP_BITS - PG_BITS)) +#else +#define wave2_2pi(e) ((e) << (PG_BITS - SLOT_AMP_BITS)) +#endif + +/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 4PI). */ +#if (SLOT_AMP_BITS - PG_BITS - 1) == 0 +#define wave2_4pi(e) (e) +#elif (SLOT_AMP_BITS - PG_BITS - 1) > 0 +#define wave2_4pi(e) ((e) >> (SLOT_AMP_BITS - PG_BITS - 1)) +#else +#define wave2_4pi(e) ((e) << (1 + PG_BITS - SLOT_AMP_BITS)) +#endif + +/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 8PI). */ +#if (SLOT_AMP_BITS - PG_BITS - 2) == 0 +#define wave2_8pi(e) (e) +#elif (SLOT_AMP_BITS - PG_BITS - 2) > 0 +#define wave2_8pi(e) ((e) >> (SLOT_AMP_BITS - PG_BITS - 2)) +#else +#define wave2_8pi(e) ((e) << (2 + PG_BITS - SLOT_AMP_BITS)) +#endif + + + +/* Update AM, PM unit */ +static void update_ampm(OPLL * opll) { + opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); + opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1); + opll->lfo_am = amtable[HIGHBITS(opll->am_phase, AM_DP_BITS - AM_PG_BITS)]; + opll->lfo_pm = pmtable[HIGHBITS(opll->pm_phase, PM_DP_BITS - PM_PG_BITS)]; +} + +/* PG */ +INLINE static void calc_phase(OPLL_SLOT * slot, int32 lfo) { + if (slot->patch.PM) + slot->phase += (slot->dphase * lfo) >> PM_AMP_BITS; + else + slot->phase += slot->dphase; + + slot->phase &= (DP_WIDTH - 1); + + slot->pgout = HIGHBITS(slot->phase, DP_BASE_BITS); +} + +/* EG */ +static void calc_envelope(OPLL_SLOT * slot, int32 lfo) { +#define S2E(x) (SL2EG((int32)(x / SL_STEP)) << (EG_DP_BITS - EG_BITS)) + + static uint32 SL[16] = { + S2E(0.0), S2E(3.0), S2E(6.0), S2E(9.0), S2E(12.0), S2E(15.0), S2E(18.0), S2E(21.0), + S2E(24.0), S2E(27.0), S2E(30.0), S2E(33.0), S2E(36.0), S2E(39.0), S2E(42.0), S2E(48.0) + }; + + uint32 egout; + + switch (slot->eg_mode) { + case ATTACK: + egout = AR_ADJUST_TABLE[HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS)]; + slot->eg_phase += slot->eg_dphase; + if ((EG_DP_WIDTH & slot->eg_phase) || (slot->patch.AR == 15)) { + egout = 0; + slot->eg_phase = 0; + slot->eg_mode = DECAY; + UPDATE_EG(slot); + } + break; + + case DECAY: + egout = HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS); + slot->eg_phase += slot->eg_dphase; + if (slot->eg_phase >= SL[slot->patch.SL]) { + if (slot->patch.EG) { + slot->eg_phase = SL[slot->patch.SL]; + slot->eg_mode = SUSHOLD; + UPDATE_EG(slot); + } else { + slot->eg_phase = SL[slot->patch.SL]; + slot->eg_mode = SUSTINE; + UPDATE_EG(slot); + } + } + break; + + case SUSHOLD: + egout = HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS); + if (slot->patch.EG == 0) { + slot->eg_mode = SUSTINE; + UPDATE_EG(slot); + } + break; + + case SUSTINE: + case RELEASE: + egout = HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS); + slot->eg_phase += slot->eg_dphase; + if (egout >= (1 << EG_BITS)) { + slot->eg_mode = FINISH; + egout = (1 << EG_BITS) - 1; + } + break; + + case FINISH: + egout = (1 << EG_BITS) - 1; + break; + + default: + egout = (1 << EG_BITS) - 1; + break; + } + + if (slot->patch.AM) + egout = EG2DB(egout + slot->tll) + lfo; + else + egout = EG2DB(egout + slot->tll); + + if (egout >= DB_MUTE) + egout = DB_MUTE - 1; + + slot->egout = egout; +} + +/* CARRIOR */ +INLINE static int32 calc_slot_car(OPLL_SLOT * slot, int32 fm) { + slot->output[1] = slot->output[0]; + + if (slot->egout >= (DB_MUTE - 1)) { + slot->output[0] = 0; + } else { + slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout + wave2_8pi(fm)) & (PG_WIDTH - 1)] + slot->egout]; + } + + return (slot->output[1] + slot->output[0]) >> 1; +} + +/* MODULATOR */ +INLINE static int32 calc_slot_mod(OPLL_SLOT * slot) { + int32 fm; + + slot->output[1] = slot->output[0]; + + if (slot->egout >= (DB_MUTE - 1)) { + slot->output[0] = 0; + } else if (slot->patch.FB != 0) { + fm = wave2_4pi(slot->feedback) >> (7 - slot->patch.FB); + slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout + fm) & (PG_WIDTH - 1)] + slot->egout]; + } else { + slot->output[0] = DB2LIN_TABLE[slot->sintbl[slot->pgout] + slot->egout]; + } + + slot->feedback = (slot->output[1] + slot->output[0]) >> 1; + + return slot->feedback; +} + +static INLINE int16 calc(OPLL * opll) { + int32 inst = 0, out = 0; + int32 i; + + update_ampm(opll); + + for (i = 0; i < 12; i++) { + calc_phase(&opll->slot[i], opll->lfo_pm); + calc_envelope(&opll->slot[i], opll->lfo_am); + } + + for (i = 0; i < 6; i++) + if (!(opll->mask & OPLL_MASK_CH(i)) && (CAR(opll, i)->eg_mode != FINISH)) + inst += calc_slot_car(CAR(opll, i), calc_slot_mod(MOD(opll, i))); + + out = inst; + return (int16)out; +} + +void OPLL_fillbuf(OPLL* opll, int32 *buf, int32 len, int shift) { + while (len > 0) { + *buf += (calc(opll) + 32768) << shift; + buf++; + len--; + } +} + +int16 OPLL_calc(OPLL * opll) { + if (!opll->quality) + return calc(opll); + + while (opll->realstep > opll->oplltime) { + opll->oplltime += opll->opllstep; + opll->prev = opll->next; + opll->next = calc(opll); + } + + opll->oplltime -= opll->realstep; + opll->out = (int16)(((double)opll->next * (opll->opllstep - opll->oplltime) + + (double)opll->prev * opll->oplltime) / opll->opllstep); + + return (int16)opll->out; +} + +uint32 OPLL_setMask(OPLL * opll, uint32 mask) { + uint32 ret; + + if (opll) { + ret = opll->mask; + opll->mask = mask; + return ret; + } else + return 0; +} + +uint32 OPLL_toggleMask(OPLL * opll, uint32 mask) { + uint32 ret; + + if (opll) { + ret = opll->mask; + opll->mask ^= mask; + return ret; + } else + return 0; +} + +/**************************************************** + + I/O Ctrl + +*****************************************************/ + +static void setInstrument(OPLL * opll, uint32 i, uint32 inst) { + const uint8 *src; + OPLL_PATCH *modp, *carp; + + opll->patch_number[i] = inst; + + if (inst) + src = default_inst[inst - 1]; + else + src = opll->CustInst; + + modp = &MOD(opll, i)->patch; + carp = &CAR(opll, i)->patch; + + modp->AM = (src[0] >> 7) & 1; + modp->PM = (src[0] >> 6) & 1; + modp->EG = (src[0] >> 5) & 1; + modp->KR = (src[0] >> 4) & 1; + modp->ML = (src[0] & 0xF); + + carp->AM = (src[1] >> 7) & 1; + carp->PM = (src[1] >> 6) & 1; + carp->EG = (src[1] >> 5) & 1; + carp->KR = (src[1] >> 4) & 1; + carp->ML = (src[1] & 0xF); + + modp->KL = (src[2] >> 6) & 3; + modp->TL = (src[2] & 0x3F); + + carp->KL = (src[3] >> 6) & 3; + carp->WF = (src[3] >> 4) & 1; + + modp->WF = (src[3] >> 3) & 1; + + modp->FB = (src[3]) & 7; + + modp->AR = (src[4] >> 4) & 0xF; + modp->DR = (src[4] & 0xF); + + carp->AR = (src[5] >> 4) & 0xF; + carp->DR = (src[5] & 0xF); + + modp->SL = (src[6] >> 4) & 0xF; + modp->RR = (src[6] & 0xF); + + carp->SL = (src[7] >> 4) & 0xF; + carp->RR = (src[7] & 0xF); +} + + +void OPLL_writeReg(OPLL * opll, uint32 reg, uint32 data) { + int32 i, v, ch; + + data = data & 0xff; + reg = reg & 0x3f; + + switch (reg) { + case 0x00: + opll->CustInst[0] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_PG(MOD(opll, i)); + UPDATE_RKS(MOD(opll, i)); + UPDATE_EG(MOD(opll, i)); + } + } + break; + + case 0x01: + opll->CustInst[1] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_PG(CAR(opll, i)); + UPDATE_RKS(CAR(opll, i)); + UPDATE_EG(CAR(opll, i)); + } + } + break; + + case 0x02: + opll->CustInst[2] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_TLL(MOD(opll, i)); + } + } + break; + + case 0x03: + opll->CustInst[3] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_WF(MOD(opll, i)); + UPDATE_WF(CAR(opll, i)); + } + } + break; + + case 0x04: + opll->CustInst[4] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(MOD(opll, i)); + } + } + break; + + case 0x05: + opll->CustInst[5] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(CAR(opll, i)); + } + } + break; + + case 0x06: + opll->CustInst[6] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(MOD(opll, i)); + } + } + break; + + case 0x07: + opll->CustInst[7] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(CAR(opll, i)); + } + } + break; + + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + ch = reg - 0x10; + opll->LowFreq[ch] = data; + setFnumber(opll, ch, data + ((opll->HiFreq[ch] & 1) << 8)); + UPDATE_ALL(MOD(opll, ch)); + UPDATE_ALL(CAR(opll, ch)); + break; + + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + ch = reg - 0x20; + opll->HiFreq[ch] = data; + + setFnumber(opll, ch, ((data & 1) << 8) + opll->LowFreq[ch]); + setBlock(opll, ch, (data >> 1) & 7); + setSustine(opll, ch, (data >> 5) & 1); + if (data & 0x10) + keyOn(opll, ch); + else + keyOff(opll, ch); + UPDATE_ALL(MOD(opll, ch)); + UPDATE_ALL(CAR(opll, ch)); + update_key_status(opll); + break; + + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + opll->InstVol[reg - 0x30] = data; + i = (data >> 4) & 15; + v = data & 15; + setInstrument(opll, reg - 0x30, i); + setVolume(opll, reg - 0x30, v << 2); + UPDATE_ALL(MOD(opll, reg - 0x30)); + UPDATE_ALL(CAR(opll, reg - 0x30)); + break; + + default: + break; + } +} + +void OPLL_writeIO(OPLL * opll, uint32 adr, uint32 val) { + if (adr & 1) + OPLL_writeReg(opll, opll->adr, val); + else + opll->adr = val; +} + diff --git a/branches/fceux-2.2.2/src/boards/emu2413.h b/branches/fceux-2.2.2/src/boards/emu2413.h new file mode 100644 index 00000000..c895f30f --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/emu2413.h @@ -0,0 +1,139 @@ +#ifndef _EMU2413_H_ +#define _EMU2413_H_ + +#ifndef INLINE +#if defined(_MSC_VER) +#define INLINE __forceinline +#elif defined(__GNUC__) +#define INLINE __inline__ +#elif defined(_MWERKS_) +#define INLINE inline +#else +#define INLINE +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned char uint8 ; +typedef signed char int8 ; + +typedef unsigned short uint16 ; +typedef signed short int16 ; + +typedef unsigned int uint32 ; +typedef signed int int32 ; + +#define PI 3.14159265358979323846 + +enum { OPLL_VRC7_TONE=0 }; + +/* voice data */ +typedef struct { + uint32 TL, FB, EG, ML, AR, DR, SL, RR, KR, KL, AM, PM, WF; +} OPLL_PATCH; + +/* slot */ +typedef struct { + OPLL_PATCH patch; + + int32 type; /* 0 : modulator 1 : carrier */ + + /* OUTPUT */ + int32 feedback; + int32 output[2]; /* Output value of slot */ + + /* for Phase Generator (PG) */ + uint16 *sintbl; /* Wavetable */ + uint32 phase; /* Phase */ + uint32 dphase; /* Phase increment amount */ + uint32 pgout; /* output */ + + /* for Envelope Generator (EG) */ + int32 fnum; /* F-Number */ + int32 block; /* Block */ + int32 volume; /* Current volume */ + int32 sustine; /* Sustine 1 = ON, 0 = OFF */ + uint32 tll; /* Total Level + Key scale level*/ + uint32 rks; /* Key scale offset (Rks) */ + int32 eg_mode; /* Current state */ + uint32 eg_phase; /* Phase */ + uint32 eg_dphase; /* Phase increment amount */ + uint32 egout; /* output */ +} OPLL_SLOT; + +/* Mask */ +#define OPLL_MASK_CH(x) (1 << (x)) + +/* opll */ +typedef struct { + uint32 adr; + int32 out; + + uint32 realstep; + uint32 oplltime; + uint32 opllstep; + int32 prev, next; + + /* Register */ + uint8 LowFreq[6]; + uint8 HiFreq[6]; + uint8 InstVol[6]; + + uint8 CustInst[8]; + + int32 slot_on_flag[6 * 2]; + + /* Pitch Modulator */ + uint32 pm_phase; + int32 lfo_pm; + + /* Amp Modulator */ + int32 am_phase; + int32 lfo_am; + + uint32 quality; + + /* Channel Data */ + int32 patch_number[6]; + int32 key_status[6]; + + /* Slot */ + OPLL_SLOT slot[6 * 2]; + + uint32 mask; +} OPLL; + +/* Create Object */ +OPLL *OPLL_new(uint32 clk, uint32 rate); +void OPLL_delete(OPLL *); + +/* Setup */ +void OPLL_reset(OPLL *); +void OPLL_set_rate(OPLL *opll, uint32 r); +void OPLL_set_quality(OPLL *opll, uint32 q); + +/* Port/Register access */ +void OPLL_writeIO(OPLL *, uint32 reg, uint32 val); +void OPLL_writeReg(OPLL *, uint32 reg, uint32 val); + +/* Synthsize */ +int16 OPLL_calc(OPLL *); + +/* Misc */ +void OPLL_forceRefresh(OPLL *); + +/* Channel Mask */ +uint32 OPLL_setMask(OPLL *, uint32 mask); +uint32 OPLL_toggleMask(OPLL *, uint32 mask); + + +void OPLL_fillbuf(OPLL* opll, int32 *buf, int32 len, int shift); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/branches/fceux-2.2.2/src/boards/famicombox.cpp b/branches/fceux-2.2.2/src/boards/famicombox.cpp new file mode 100644 index 00000000..05c6a629 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/famicombox.cpp @@ -0,0 +1,115 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 regs[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg2r(0x10, 0x0800, 0); + setprg2r(0x10, 0x1000, 1); + setprg2r(0x10, 0x1800, 2); + setprg8r(0x10, 0x6000, 1); + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + setchr8(0); +} + +//static DECLFW(SSSNROMWrite) +//{ +// CartBW(A,V); +//} + +static DECLFW(SSSNROMWrite) { +// FCEU_printf("write %04x %02x\n",A,V); +// regs[A&7] = V; +} + +static DECLFR(SSSNROMRead) { +// FCEU_printf("read %04x\n",A); + switch (A & 7) { + case 0: return regs[0] = 0xff; // clear all exceptions + case 2: return 0xc0; // DIP selftest + freeplay + case 3: return 0x00; // 0, 1 - attract + // 2 + // 4 - menu + // 8 - self check and game casette check + // 10 - lock? + // 20 - game title & count display + case 7: return 0x22; // TV type, key not turned, relay B + default: return 0; + } +} + +static void SSSNROMPower(void) { + regs[0] = regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = regs[6] = 0; + regs[7] = 0xff; + Sync(); + memset(WRAM, 0x00, WRAMSIZE); +// SetWriteHandler(0x0000,0x1FFF,SSSNROMRamWrite); + SetReadHandler(0x0800, 0x1FFF, CartBR); + SetWriteHandler(0x0800, 0x1FFF, CartBW); + SetReadHandler(0x5000, 0x5FFF, SSSNROMRead); + SetWriteHandler(0x5000, 0x5FFF, SSSNROMWrite); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void SSSNROMReset(void) { + regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = regs[6] = 0; +} + +static void SSSNROMClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void SSSNROMIRQHook(void) { +// X6502_IRQBegin(FCEU_IQEXT); +} + +static void StateRestore(int version) { + Sync(); +} + +void SSSNROM_Init(CartInfo *info) { + info->Reset = SSSNROMReset; + info->Power = SSSNROMPower; + info->Close = SSSNROMClose; + GameHBIRQHook = SSSNROMIRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 16384; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ffe.cpp b/branches/fceux-2.2.2/src/boards/ffe.cpp new file mode 100644 index 00000000..da354114 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ffe.cpp @@ -0,0 +1,153 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * FFE Copier Mappers + * + */ + +#include "mapinc.h" + +static uint8 preg[4], creg[8], latch, ffemode; +static uint8 IRQa, mirr; +static int32 IRQCount, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + if (ffemode) { + int i; + for (i = 0; i < 8; i++) setchr1(i << 10, creg[i]); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, preg[3]); + } else { + setchr8(latch & 3); + setprg16(0x8000, (latch >> 2) & 0x3F); + setprg16(0xc000, 0x7); + } + switch (mirr) { + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + } +} + +static DECLFW(FFEWriteMirr) { + mirr = ((A << 1) & 2) | ((V >> 4) & 1); + Sync(); +} + +static DECLFW(FFEWriteIRQ) { + switch (A) { + case 0x4501: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x4502: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x4503: IRQCount &= 0x00FF; IRQCount |= V << 8; IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static DECLFW(FFEWritePrg) { + preg[A & 3] = V; + Sync(); +} + +static DECLFW(FFEWriteChr) { + creg[A & 7] = V; + Sync(); +} + +static DECLFW(FFEWriteLatch) { + latch = V; + Sync(); +} + +static void FFEPower(void) { + preg[3] = ~0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x42FE, 0x42FF, FFEWriteMirr); + SetWriteHandler(0x4500, 0x4503, FFEWriteIRQ); + SetWriteHandler(0x4504, 0x4507, FFEWritePrg); + SetWriteHandler(0x4510, 0x4517, FFEWriteChr); + SetWriteHandler(0x4510, 0x4517, FFEWriteChr); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, FFEWriteLatch); +} + +static void FFEIRQHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount >= 0x10000) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0; + } + } +} + +static void FFEClose(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper6_Init(CartInfo *info) { + ffemode = 0; + mirr = ((info->mirror & 1) ^ 1) | 2; + + info->Power = FFEPower; + info->Close = FFEClose; + MapIRQHook = FFEIRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper17_Init(CartInfo *info) { + ffemode = 1; + Mapper6_Init(info); +} diff --git a/branches/fceux-2.2.2/src/boards/fk23c.cpp b/branches/fceux-2.2.2/src/boards/fk23c.cpp new file mode 100644 index 00000000..604d5160 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/fk23c.cpp @@ -0,0 +1,290 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" +#include "../ines.h" + +static bool is_BMCFK23CA; +static uint8 unromchr; +static uint32 dipswitch; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSize; + +static void BMCFK23CCW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr8(EXPREGS[2]|unromchr); + else if(EXPREGS[0]&0x20) { + setchr1r(0x10, A, V); + } + else + { + uint16 base=(EXPREGS[2]&0x7F)<<3; + if(EXPREGS[3]&2) + { + int cbase=(MMC3_cmd&0x80)<<5; + setchr1(A,V|base); + setchr1(0x0000^cbase,DRegBuf[0]|base); + setchr1(0x0400^cbase,EXPREGS[6]|base); + setchr1(0x0800^cbase,DRegBuf[1]|base); + setchr1(0x0c00^cbase,EXPREGS[7]|base); + } + else + setchr1(A,V|base); + } +} + +//some games are wired differently, and this will need to be changed. +//all the WXN games require prg_bonus = 1, and cah4e3's multicarts require prg_bonus = 0 +//we'll populate this from a game database +static int prg_bonus; +static int prg_mask; + +//prg_bonus = 0 +//4-in-1 (FK23C8021)[p1][!].nes +//4-in-1 (FK23C8033)[p1][!].nes +//4-in-1 (FK23C8043)[p1][!].nes +//4-in-1 (FK23Cxxxx, S-0210A PCB)[p1][!].nes + +//prg_bonus = 1 +//[m176]大富ç¿2-上海大亨.wxn.nes +//[m176]宠物翡翠.fix.nes +//[m176]格兰å¸äºš.wxn.nes +//[m176]梦幻之星.wxn.nes +//[m176]水浒神兽.fix.nes +//[m176]西楚霸王.fix.nes +//[m176]超级大富ç¿.wxn.nes +//[m176]雄霸天下.wxn.nes + +//works as-is under virtuanes m176 +//[m176]三侠五义.wxn.nes +//[m176]å£è¢‹é‡‘.fix.nes +//[m176]爆笑三国.fix.nes + +//needs other tweaks +//[m176]三国忠烈传.wxn.nes +//[m176]破釜沉舟.fix.nes + +//PRG wrapper +static void BMCFK23CPW(uint32 A, uint8 V) +{ + uint32 bank = (EXPREGS[1] & 0x1F); + uint32 hiblock = ((EXPREGS[0] & 8) << 4)|((EXPREGS[0] & 0x80) << 1)|(UNIFchrrama?((EXPREGS[2] & 0x40)<<3):0); + uint32 block = (EXPREGS[1] & 0x60) | hiblock; + uint32 extra = (EXPREGS[3] & 2); + + if((EXPREGS[0]&7)==4) + setprg32(0x8000,EXPREGS[1]>>1); + else if ((EXPREGS[0]&7)==3) + { + setprg16(0x8000,EXPREGS[1]); + setprg16(0xC000,EXPREGS[1]); + } + else + { + if(EXPREGS[0]&3) + { + uint32 blocksize = (6)-(EXPREGS[0]&3); + uint32 mask = (1<Power=BMCFK23CPower; + info->Reset=BMCFK23CReset; + AddExState(EXPREGS, 8, 0, "EXPR"); + AddExState(&unromchr, 1, 0, "UCHR"); + AddExState(&dipswitch, 1, 0, "DPSW"); + + prg_bonus = 1; + if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end()) + prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str()); + + prg_mask = 0x7F>>(prg_bonus); +} + +void BMCFK23CA_Init(CartInfo *info) +{ + is_BMCFK23CA = true; + + GenMMC3_Init(info, 512, 256, 8, 0); + cwrap=BMCFK23CCW; + pwrap=BMCFK23CPW; + info->Power=BMCFK23CAPower; + info->Reset=BMCFK23CReset; + info->Close=BMCFK23CAClose; + + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CRAM"); + + AddExState(EXPREGS, 8, 0, "EXPR"); + AddExState(&unromchr, 1, 0, "UCHR"); + AddExState(&dipswitch, 1, 0, "DPSW"); + + prg_bonus = 1; + if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end()) + prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str()); + prg_mask = 0x7F>>(prg_bonus); +} diff --git a/branches/fceux-2.2.2/src/boards/ghostbusters63in1.cpp b/branches/fceux-2.2.2/src/boards/ghostbusters63in1.cpp new file mode 100644 index 00000000..5e09d9be --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ghostbusters63in1.cpp @@ -0,0 +1,96 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * 63in1 ghostbusters + */ + +#include "mapinc.h" + +static uint8 reg[2], bank; +static uint8 banks[4] = { 0, 0, 1, 2 }; +static uint8 *CHRROM = NULL; +static uint32 CHRROMSIZE; + +static SFORMAT StateRegs[] = +{ + { reg, 2, "REGS" }, + { &bank, 1, "BANK" }, + { 0 } +}; + +static void Sync(void) { + if (reg[0] & 0x20) { + setprg16r(banks[bank], 0x8000, reg[0] & 0x1F); + setprg16r(banks[bank], 0xC000, reg[0] & 0x1F); + } else + setprg32r(banks[bank], 0x8000, (reg[0] >> 1) & 0x0F); + if (reg[1] & 2) + setchr8r(0x10, 0); + else + setchr8(0); + setmirror((reg[0] & 0x40) >> 6); +} + +static DECLFW(BMCGhostbusters63in1Write) { + reg[A & 1] = V; + bank = ((reg[0] & 0x80) >> 7) | ((reg[1] & 1) << 1); +// FCEU_printf("reg[0]=%02x, reg[1]=%02x, bank=%02x\n",reg[0],reg[1],bank); + Sync(); +} + +static DECLFR(BMCGhostbusters63in1Read) { + if (bank == 1) + return X.DB; + else + return CartBR(A); +} + +static void BMCGhostbusters63in1Power(void) { + reg[0] = reg[1] = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, BMCGhostbusters63in1Read); + SetWriteHandler(0x8000, 0xFFFF, BMCGhostbusters63in1Write); +} + +static void BMCGhostbusters63in1Reset(void) { + reg[0] = reg[1] = 0; +} + +static void StateRestore(int version) { + Sync(); +} + +static void BMCGhostbusters63in1Close(void) { + if (CHRROM) + FCEU_gfree(CHRROM); + CHRROM = NULL; +} + +void BMCGhostbusters63in1_Init(CartInfo *info) { + info->Reset = BMCGhostbusters63in1Reset; + info->Power = BMCGhostbusters63in1Power; + info->Close = BMCGhostbusters63in1Close; + + CHRROMSIZE = 8192; // dummy CHRROM, VRAM disable + CHRROM = (uint8*)FCEU_gmalloc(CHRROMSIZE); + SetupCartPRGMapping(0x10, CHRROM, CHRROMSIZE, 0); + AddExState(CHRROM, CHRROMSIZE, 0, "CROM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/gs-2004.cpp b/branches/fceux-2.2.2/src/boards/gs-2004.cpp new file mode 100644 index 00000000..43f70684 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/gs-2004.cpp @@ -0,0 +1,63 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(1, 0x6000, 0); + setprg32(0x8000, reg); + setchr8(0); +} + +static DECLFW(BMCGS2004Write) { + reg = V; + Sync(); +} + +static void BMCGS2004Power(void) { + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BMCGS2004Write); +} + +static void BMCGS2004Reset(void) { + reg = ~0; +} + +static void StateRestore(int version) { + Sync(); +} + +void BMCGS2004_Init(CartInfo *info) { + info->Reset = BMCGS2004Reset; + info->Power = BMCGS2004Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/gs-2013.cpp b/branches/fceux-2.2.2/src/boards/gs-2013.cpp new file mode 100644 index 00000000..704a8cf1 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/gs-2013.cpp @@ -0,0 +1,63 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0, 0x6000, ~0); + setprg32r((reg & 8) >> 3, 0x8000, reg); + setchr8(0); +} + +static DECLFW(BMCGS2013Write) { + reg = V; + Sync(); +} + +static void BMCGS2013Power(void) { + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BMCGS2013Write); +} + +static void BMCGS2013Reset(void) { + reg = ~0; +} + +static void StateRestore(int version) { + Sync(); +} + +void BMCGS2013_Init(CartInfo *info) { + info->Reset = BMCGS2013Reset; + info->Power = BMCGS2013Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/h2288.cpp b/branches/fceux-2.2.2/src/boards/h2288.cpp new file mode 100644 index 00000000..07ff76c1 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/h2288.cpp @@ -0,0 +1,70 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +extern uint8 m114_perm[8]; + +static void H2288PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) { + uint8 bank = (EXPREGS[0] & 5) | ((EXPREGS[0] & 8) >> 2) | ((EXPREGS[0] & 0x20) >> 2); + if (EXPREGS[0] & 2) + setprg32(0x8000, bank >> 1); + else{ + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else + setprg8(A, V & 0x3F); +} + +static DECLFW(H2288WriteHi) { + switch (A & 0x8001) { + case 0x8000: MMC3_CMDWrite(0x8000, (V & 0xC0) | (m114_perm[V & 7])); break; + case 0x8001: MMC3_CMDWrite(0x8001, V); break; + } +} + +static DECLFW(H2288WriteLo) { + if (A & 0x800) { + if (A & 1) + EXPREGS[1] = V; + else + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + } +} + +static void H2288Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); +// SetReadHandler(0x5000,0x5FFF,H2288Read); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x5000, 0x5FFF, H2288WriteLo); + SetWriteHandler(0x8000, 0x9FFF, H2288WriteHi); +} + +void UNLH2288_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = H2288PW; + info->Power = H2288Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/karaoke.cpp b/branches/fceux-2.2.2/src/boards/karaoke.cpp new file mode 100644 index 00000000..81d9dbc8 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/karaoke.cpp @@ -0,0 +1,63 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +extern uint32 ROM_size; +static uint8 latche; + +static void Sync(void) { + if (latche) { + if (latche & 0x10) + setprg16(0x8000, (latche & 7)); + else + setprg16(0x8000, (latche & 7) | 8); + } else + setprg16(0x8000, 7 + (ROM_size >> 4)); +} + +static DECLFW(M188Write) { + latche = V; + Sync(); +} + +static DECLFR(ExtDev) { + return(3); +} + +static void Power(void) { + latche = 0; + Sync(); + setchr8(0); + setprg16(0xc000, 0x7); + SetReadHandler(0x6000, 0x7FFF, ExtDev); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M188Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper188_Init(CartInfo *info) { + info->Power = Power; + GameStateRestore = StateRestore; + AddExState(&latche, 1, 0, "LATC"); +} diff --git a/branches/fceux-2.2.2/src/boards/kof97.cpp b/branches/fceux-2.2.2/src/boards/kof97.cpp new file mode 100644 index 00000000..4a7925ac --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/kof97.cpp @@ -0,0 +1,46 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static DECLFW(UNLKOF97CMDWrite) { + V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); //76143502 + if (A == 0x9000) A = 0x8001; + MMC3_CMDWrite(A, V); +} + +static DECLFW(UNLKOF97IRQWrite) { + V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); + if (A == 0xD000) A = 0xC001; + else if (A == 0xF000) A = 0xE001; + MMC3_IRQWrite(A, V); +} + +static void UNLKOF97Power(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xA000, UNLKOF97CMDWrite); + SetWriteHandler(0xC000, 0xF000, UNLKOF97IRQWrite); +} + +void UNLKOF97_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power = UNLKOF97Power; +} diff --git a/branches/fceux-2.2.2/src/boards/ks7012.cpp b/branches/fceux-2.2.2/src/boards/ks7012.cpp new file mode 100644 index 00000000..feaa7542 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7012.cpp @@ -0,0 +1,83 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, reg & 1); + setchr8(0); +} + +static DECLFW(UNLKS7012Write) { +// FCEU_printf("bs %04x %02x\n",A,V); + switch (A) { + case 0xE0A0: reg = 0; Sync(); break; + case 0xEE36: reg = 1; Sync(); break; + } +} + +static void UNLKS7012Power(void) { + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLKS7012Write); +} + +static void UNLKS7012Reset(void) { + reg = ~0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +static void UNLKS7012Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void UNLKS7012_Init(CartInfo *info) { + info->Power = UNLKS7012Power; + info->Reset = UNLKS7012Reset; + info->Close = UNLKS7012Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ks7013.cpp b/branches/fceux-2.2.2/src/boards/ks7013.cpp new file mode 100644 index 00000000..fe8349e9 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7013.cpp @@ -0,0 +1,77 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 + * + * Just another pirate cart with pirate mapper, instead of original MMC1 + * Kaiser Highway Star + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, reg); + setprg16(0xc000, ~0); + setmirror(mirr); + setchr8(0); +} + +static DECLFW(UNLKS7013BLoWrite) { + reg = V; + Sync(); +} + +static DECLFW(UNLKS7013BHiWrite) { + mirr = (V & 1) ^ 1; + Sync(); +} + +static void UNLKS7013BPower(void) { + reg = 0; + mirr = 0; + Sync(); + SetWriteHandler(0x6000, 0x7FFF, UNLKS7013BLoWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLKS7013BHiWrite); +} + +static void UNLKS7013BReset(void) { + reg = 0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7013B_Init(CartInfo *info) { + info->Power = UNLKS7013BPower; + info->Reset = UNLKS7013BReset; + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ks7017.cpp b/branches/fceux-2.2.2/src/boards/ks7017.cpp new file mode 100644 index 00000000..29c02037 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7017.cpp @@ -0,0 +1,114 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static int32 IRQa, IRQCount, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &mirr, 1, "MIRR" }, + { ®, 1, "REGS" }, + { &IRQa, 4, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, reg); + setprg16(0xC000, 2); + setmirror(mirr); +} + +static DECLFW(UNLKS7017Write) { +// FCEU_printf("bs %04x %02x\n",A,V); + if ((A & 0xFF00) == 0x4A00) { + reg = ((A >> 2) & 3) | ((A >> 4) & 4); + } else if ((A & 0xFF00) == 0x5100) { + Sync(); + } else if (A == 0x4020) { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount &= 0xFF00; + IRQCount |= V; + } else if (A == 0x4021) { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount &= 0xFF; + IRQCount |= V << 8; + IRQa = 1; + } else if (A == 0x4025) { + mirr = ((V & 8) >> 3) ^ 1; + } +} +static DECLFR(FDSRead4030) { + X6502_IRQEnd(FCEU_IQEXT); + return X.IRQlow & FCEU_IQEXT ? 1 : 0; +} + +static void UNL7017IRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7017Power(void) { + Sync(); + setchr8(0); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0x4030, 0x4030, FDSRead4030); + SetWriteHandler(0x4020, 0x5FFF, UNLKS7017Write); +} + +static void UNLKS7017Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7017_Init(CartInfo *info) { + info->Power = UNLKS7017Power; + info->Close = UNLKS7017Close; + MapIRQHook = UNL7017IRQ; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ks7030.cpp b/branches/fceux-2.2.2/src/boards/ks7030.cpp new file mode 100644 index 00000000..8e6a592e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7030.cpp @@ -0,0 +1,140 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * + * FDS Conversion + * + * Logical bank layot 32 K BANK 0, 64K BANK 1, 32K ~0 hardwired, 8K is missing + * need redump from MASKROM! + * probably need refix mapper after hard dump + * + */ + +#include "mapinc.h" + +static uint8 reg0, reg1; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®0, 1, "REG0" }, + { ®1, 1, "REG1" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg32(0x8000, ~0); + setprg4(0xb800, reg0); + setprg4(0xc800, 8 + reg1); +} + +// 6000 - 6BFF - RAM +// 6C00 - 6FFF - BANK 1K REG1 +// 7000 - 7FFF - BANK 4K REG0 + +static DECLFW(UNLKS7030RamWrite0) { + if ((A >= 0x6000) && A <= 0x6BFF) { + WRAM[A - 0x6000] = V; + } else if ((A >= 0x6C00) && A <= 0x6FFF) { + CartBW(0xC800 + (A - 0x6C00), V); + } else if ((A >= 0x7000) && A <= 0x7FFF) { + CartBW(0xB800 + (A - 0x7000), V); + } +} + +static DECLFR(UNLKS7030RamRead0) { + if ((A >= 0x6000) && A <= 0x6BFF) { + return WRAM[A - 0x6000]; + } else if ((A >= 0x6C00) && A <= 0x6FFF) { + return CartBR(0xC800 + (A - 0x6C00)); + } else if ((A >= 0x7000) && A <= 0x7FFF) { + return CartBR(0xB800 + (A - 0x7000)); + } + return 0; +} + +// B800 - BFFF - RAM +// C000 - CBFF - BANK 3K +// CC00 - D7FF - RAM + +static DECLFW(UNLKS7030RamWrite1) { + if ((A >= 0xB800) && A <= 0xBFFF) { + WRAM[0x0C00 + (A - 0xB800)] = V; + } else if ((A >= 0xC000) && A <= 0xCBFF) { + CartBW(0xCC00 + (A - 0xC000), V); + } else if ((A >= 0xCC00) && A <= 0xD7FF) { + WRAM[0x1400 + (A - 0xCC00)] = V; + } +} + +static DECLFR(UNLKS7030RamRead1) { + if ((A >= 0xB800) && A <= 0xBFFF) { + return WRAM[0x0C00 + (A - 0xB800)]; + } else if ((A >= 0xC000) && A <= 0xCBFF) { + return CartBR(0xCC00 + (A - 0xC000)); + } else if ((A >= 0xCC00) && A <= 0xD7FF) { + return WRAM[0x1400 + (A - 0xCC00)]; + } + return 0; +} + +static DECLFW(UNLKS7030Write0) { + reg0 = A & 7; + Sync(); +} + +static DECLFW(UNLKS7030Write1) { + reg1 = A & 15; + Sync(); +} + +static void UNLKS7030Power(void) { + reg0 = reg1 = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, UNLKS7030RamRead0); + SetWriteHandler(0x6000, 0x7FFF, UNLKS7030RamWrite0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x8FFF, UNLKS7030Write0); + SetWriteHandler(0x9000, 0x9FFF, UNLKS7030Write1); + SetReadHandler(0xB800, 0xD7FF, UNLKS7030RamRead1); + SetWriteHandler(0xB800, 0xD7FF, UNLKS7030RamWrite1); +} + +static void UNLKS7030Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7030_Init(CartInfo *info) { + info->Power = UNLKS7030Power; + info->Close = UNLKS7030Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ks7031.cpp b/branches/fceux-2.2.2/src/boards/ks7031.cpp new file mode 100644 index 00000000..f9944340 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7031.cpp @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[4]; + +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg2(0x6000, reg[0]); + setprg2(0x6800, reg[1]); + setprg2(0x7000, reg[2]); + setprg2(0x7800, reg[3]); + + setprg2(0x8000, 15); + setprg2(0x8800, 14); + setprg2(0x9000, 13); + setprg2(0x9800, 12); + setprg2(0xa000, 11); + setprg2(0xa800, 10); + setprg2(0xb000, 9); + setprg2(0xb800, 8); + + setprg2(0xc000, 7); + setprg2(0xc800, 6); + setprg2(0xd000, 5); + setprg2(0xd800, 4); + setprg2(0xe000, 3); + setprg2(0xe800, 2); + setprg2(0xf000, 1); + setprg2(0xf800, 0); + + setchr8(0); +} + +static DECLFW(UNLKS7031Write) { + reg[(A >> 11) & 3] = V; + Sync(); +} + +static void UNLKS7031Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xffff, UNLKS7031Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7031_Init(CartInfo *info) { + info->Power = UNLKS7031Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ks7032.cpp b/branches/fceux-2.2.2/src/boards/ks7032.cpp new file mode 100644 index 00000000..71d4c5f8 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7032.cpp @@ -0,0 +1,88 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg[8], cmd, IRQa = 0, isirqused = 0; +static int32 IRQCount; + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { reg, 8, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg[4]); + setprg8(0x8000, reg[1]); + setprg8(0xA000, reg[2]); + setprg8(0xC000, reg[3]); + setprg8(0xE000, ~0); + setchr8(0); +} + +static DECLFW(UNLKS7032Write) { +// FCEU_printf("bs %04x %02x\n",A,V); + switch (A & 0xF000) { +// case 0x8FFF: reg[4]=V; Sync(); break; + case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x000F) | (V & 0x0F); isirqused = 1; break; + case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x00F0) | ((V & 0x0F) << 4); isirqused = 1; break; + case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x0F00) | ((V & 0x0F) << 8); isirqused = 1; break; + case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0xF000) | (V << 12); isirqused = 1; break; + case 0xC000: if (isirqused) { + X6502_IRQEnd(FCEU_IQEXT); IRQa = 1; + } + break; + case 0xE000: cmd = V & 7; break; + case 0xF000: reg[cmd] = V; Sync(); break; + } +} + +static void UNLSMB2JIRQHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount >= 0xFFFF) { + IRQa = 0; + IRQCount = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7032Power(void) { + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4020, 0xFFFF, UNLKS7032Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7032_Init(CartInfo *info) { + info->Power = UNLKS7032Power; + MapIRQHook = UNLSMB2JIRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ks7037.cpp b/branches/fceux-2.2.2/src/boards/ks7037.cpp new file mode 100644 index 00000000..efe43f21 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7037.cpp @@ -0,0 +1,125 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], cmd; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static void (*WSync)(void); + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { reg, 8, "REGS" }, + { 0 } +}; + +static void SyncKS7037(void) { + setprg4r(0x10, 0x6000, 0); + setprg4(0x7000, 15); + setprg8(0x8000, reg[6]); + setprg4(0xA000, ~3); + setprg4r(0x10, 0xB000, 1); + setprg8(0xC000, reg[7]); + setprg8(0xE000, ~0); + setchr8(0); + setmirrorw(reg[2] & 1, reg[4] & 1, reg[3] & 1, reg[5] & 1); +} + +static void SyncLH10(void) { + setprg8(0x6000, ~1); + setprg8(0x8000, reg[6]); + setprg8(0xA000, reg[7]); + setprg8r(0x10, 0xC000, 0); + setprg8(0xE000, ~0); + setchr8(0); + setmirror(0); +} + +static DECLFW(UNLKS7037Write) { + switch (A & 0xE001) { + case 0x8000: cmd = V & 7; break; + case 0x8001: reg[cmd] = V; WSync(); break; + } +} + +static void UNLKS7037Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0; + WSync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0x9FFF, UNLKS7037Write); + SetWriteHandler(0xA000, 0xBFFF, CartBW); + SetWriteHandler(0xC000, 0xFFFF, UNLKS7037Write); +} + +static void LH10Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0; + WSync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, UNLKS7037Write); + SetWriteHandler(0xC000, 0xDFFF, CartBW); + SetWriteHandler(0xE000, 0xFFFF, UNLKS7037Write); +} + +static void Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + WSync(); +} + +void UNLKS7037_Init(CartInfo *info) { + info->Power = UNLKS7037Power; + info->Close = Close; + + WSync = SyncKS7037; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void LH10_Init(CartInfo *info) { + info->Power = LH10Power; + info->Close = Close; + + WSync = SyncLH10; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/ks7057.cpp b/branches/fceux-2.2.2/src/boards/ks7057.cpp new file mode 100644 index 00000000..a9c47968 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/ks7057.cpp @@ -0,0 +1,92 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], mirror; +static SFORMAT StateRegs[] = +{ + { reg, 8, "PRG" }, + { &mirror, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg2(0x6000, reg[4]); + setprg2(0x6800, reg[5]); + setprg2(0x7000, reg[6]); + setprg2(0x7800, reg[7]); + setprg2(0x8000, reg[0]); + setprg2(0x8800, reg[1]); + setprg2(0x9000, reg[2]); + setprg2(0x9800, reg[3]); + setprg8(0xA000, 0xd); + setprg16(0xC000, 7); + setchr8(0); + setmirror(mirror); +} + +static DECLFW(UNLKS7057Write) { + switch (A & 0xF003) { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: + case 0x9000: + case 0x9001: + case 0x9002: + case 0x9003: mirror = V & 1; Sync(); break; + case 0xB000: reg[0] = (reg[0] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB001: reg[0] = (reg[0] & 0x0F) | (V << 4); Sync(); break; + case 0xB002: reg[1] = (reg[1] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB003: reg[1] = (reg[1] & 0x0F) | (V << 4); Sync(); break; + case 0xC000: reg[2] = (reg[2] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC001: reg[2] = (reg[2] & 0x0F) | (V << 4); Sync(); break; + case 0xC002: reg[3] = (reg[3] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC003: reg[3] = (reg[3] & 0x0F) | (V << 4); Sync(); break; + case 0xD000: reg[4] = (reg[4] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD001: reg[4] = (reg[4] & 0x0F) | (V << 4); Sync(); break; + case 0xD002: reg[5] = (reg[5] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD003: reg[5] = (reg[5] & 0x0F) | (V << 4); Sync(); break; + case 0xE000: reg[6] = (reg[6] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE001: reg[6] = (reg[6] & 0x0F) | (V << 4); Sync(); break; + case 0xE002: reg[7] = (reg[7] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE003: reg[7] = (reg[7] & 0x0F) | (V << 4); Sync(); break; + } +} + +static void UNLKS7057Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLKS7057Write); +} + +static void UNLKS7057Reset(void) { + Sync(); +} + +void UNLKS7057_Init(CartInfo *info) { + info->Power = UNLKS7057Power; + info->Reset = UNLKS7057Reset; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/le05.cpp b/branches/fceux-2.2.2/src/boards/le05.cpp new file mode 100644 index 00000000..efbe13f6 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/le05.cpp @@ -0,0 +1,62 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 chr; +static SFORMAT StateRegs[] = +{ + { &chr, 1, "CHR" }, + { 0 } +}; + +static void Sync(void) { + setprg2r(0, 0xE000, 0); + setprg2r(0, 0xE800, 0); + setprg2r(0, 0xF000, 0); + setprg2r(0, 0xF800, 0); + + setprg8r(1, 0x6000, 3); + setprg8r(1, 0x8000, 0); + setprg8r(1, 0xA000, 1); + setprg8r(1, 0xC000, 2); + + setchr8(chr & 1); + setmirror(MI_V); +} + +static DECLFW(LE05Write) { + chr = V; + Sync(); +} + +static void LE05Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, LE05Write); +} + +void LE05_Init(CartInfo *info) { + info->Power = LE05Power; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/lh32.cpp b/branches/fceux-2.2.2/src/boards/lh32.cpp new file mode 100644 index 00000000..2150aee2 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/lh32.cpp @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg8(0x8000, ~3); + setprg8(0xa000, ~2); + setprg8r(0x10, 0xc000, 0); + setprg8(0xe000, ~0); + setchr8(0); +} + +static DECLFW(LH32Write) { + reg = V; + Sync(); +} + +static void LH32Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0xC000, 0xDFFF, CartBW); + SetWriteHandler(0x6000, 0x6000, LH32Write); +} + +static void LH32Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void LH32_Init(CartInfo *info) { + info->Power = LH32Power; + info->Close = LH32Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/lh53.cpp b/branches/fceux-2.2.2/src/boards/lh53.cpp new file mode 100644 index 00000000..7626dca5 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/lh53.cpp @@ -0,0 +1,107 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, IRQa; +static int32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8(0x6000, reg); + setprg8(0x8000, 0xc); + setprg4(0xa000, (0xd << 1)); + setprg2(0xb000, (0xd << 2) + 2); + setprg2r(0x10, 0xb800, 4); + setprg2r(0x10, 0xc000, 5); + setprg2r(0x10, 0xc800, 6); + setprg2r(0x10, 0xd000, 7); + setprg2(0xd800, (0xe << 2) + 3); + setprg8(0xe000, 0xf); +} + +static DECLFW(LH53RamWrite) { + WRAM[(A - 0xB800) & 0x1FFF] = V; +} + +static DECLFW(LH53Write) { + reg = V; + Sync(); +} + +static DECLFW(LH53IRQaWrite) { + IRQa = V & 2; + IRQCount = 0; + if (!IRQa) + X6502_IRQEnd(FCEU_IQEXT); +} + +static void LH53IRQ(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount > 7560) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void LH53Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0xB800, 0xD7FF, LH53RamWrite); + SetWriteHandler(0xE000, 0xEFFF, LH53IRQaWrite); + SetWriteHandler(0xF000, 0xFFFF, LH53Write); +} + +static void LH53Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void LH53_Init(CartInfo *info) { + info->Power = LH53Power; + info->Close = LH53Close; + MapIRQHook = LH53IRQ; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/malee.cpp b/branches/fceux-2.2.2/src/boards/malee.cpp new file mode 100644 index 00000000..ca369a75 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/malee.cpp @@ -0,0 +1,40 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 WRAM[2048]; + +static void MALEEPower(void) { + setprg2r(0x10, 0x7000, 0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0x6000, 0x67FF, CartBR); + SetReadHandler(0x7000, 0x77FF, CartBR); + SetWriteHandler(0x7000, 0x77FF, CartBW); + setprg2r(1, 0x6000, 0); + setprg32(0x8000, 0); + setchr8(0); +} + +void MALEE_Init(CartInfo *info) { + info->Power = MALEEPower; + SetupCartPRGMapping(0x10, WRAM, 2048, 1); + AddExState(WRAM, 2048, 0, "WRAM"); +} diff --git a/branches/fceux-2.2.2/src/boards/mapinc.h b/branches/fceux-2.2.2/src/boards/mapinc.h new file mode 100644 index 00000000..8fa46f42 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/mapinc.h @@ -0,0 +1,12 @@ +#include "../types.h" +#include "../utils/memory.h" +#include "../x6502.h" +#include "../fceu.h" +#include "../ppu.h" +#include "../sound.h" +#include "../state.h" +#include "../cart.h" +#include "../cheat.h" +#include "../unif.h" +#include +#include diff --git a/branches/fceux-2.2.2/src/boards/mihunche.cpp b/branches/fceux-2.2.2/src/boards/mihunche.cpp new file mode 100644 index 00000000..512aa0f2 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/mihunche.cpp @@ -0,0 +1,68 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2013 CaH4e3 + * + * 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 "mapinc.h" + +static uint16 latche; + +static SFORMAT StateRegs[] = +{ + { &latche, 2, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, 0); + if(CHRsize[0] == 8192) { + setchr4(0x0000, latche & 1); + setchr4(0x1000, latche & 1); + } else { + setchr8(latche & 1); // actually, my bad, overdumped roms, the real CHR size if 8K + } + setmirror(MI_0 + (latche & 1)); +} + +static DECLFW(UNLCC21Write1) { + latche = A; + Sync(); +} + +static DECLFW(UNLCC21Write2) { + latche = V; + Sync(); +} + +static void UNLCC21Power(void) { + latche = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8001, 0xFFFF, UNLCC21Write1); + SetWriteHandler(0x8000, 0x8000, UNLCC21Write2); // another one many-in-1 mapper, there is a lot of similar carts with little different wirings +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLCC21_Init(CartInfo *info) { + info->Power = UNLCC21Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/mmc1.cpp b/branches/fceux-2.2.2/src/boards/mmc1.cpp new file mode 100644 index 00000000..17fab418 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/mmc1.cpp @@ -0,0 +1,392 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static void GenMMC1Power(void); +static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery); + +static uint8 DRegs[4]; +static uint8 Buffer, BufferShift; + +static int mmc1opts; + +static void (*MMC1CHRHook4)(uint32 A, uint8 V); +static void (*MMC1PRGHook16)(uint32 A, uint8 V); + +static uint8 *WRAM = NULL; +static uint8 *CHRRAM = NULL; +static int is155, is171; + +static DECLFW(MBWRAM) { + if (!(DRegs[3] & 0x10) || is155) + Page[A >> 11][A] = V; // WRAM is enabled. +} + +static DECLFR(MAWRAM) { + if ((DRegs[3] & 0x10) && !is155) + return X.DB; // WRAM is disabled + return(Page[A >> 11][A]); +} + +static void MMC1CHR(void) { + if (mmc1opts & 4) { + if (DRegs[0] & 0x10) + setprg8r(0x10, 0x6000, (DRegs[1] >> 4) & 1); + else + setprg8r(0x10, 0x6000, (DRegs[1] >> 3) & 1); + } + + if (MMC1CHRHook4) { + if (DRegs[0] & 0x10) { + MMC1CHRHook4(0x0000, DRegs[1]); + MMC1CHRHook4(0x1000, DRegs[2]); + } else { + MMC1CHRHook4(0x0000, (DRegs[1] & 0xFE)); + MMC1CHRHook4(0x1000, DRegs[1] | 1); + } + } else { + if (DRegs[0] & 0x10) { + setchr4(0x0000, DRegs[1]); + setchr4(0x1000, DRegs[2]); + } else + setchr8(DRegs[1] >> 1); + } +} + +static void MMC1PRG(void) { + uint8 offs = DRegs[1] & 0x10; + if (MMC1PRGHook16) { + switch (DRegs[0] & 0xC) { + case 0xC: + MMC1PRGHook16(0x8000, (DRegs[3] + offs)); + MMC1PRGHook16(0xC000, 0xF + offs); + break; + case 0x8: + MMC1PRGHook16(0xC000, (DRegs[3] + offs)); + MMC1PRGHook16(0x8000, offs); + break; + case 0x0: + case 0x4: + MMC1PRGHook16(0x8000, ((DRegs[3] & ~1) + offs)); + MMC1PRGHook16(0xc000, ((DRegs[3] & ~1) + offs + 1)); + break; + } + } else { + switch (DRegs[0] & 0xC) { + case 0xC: + setprg16(0x8000, (DRegs[3] + offs)); + setprg16(0xC000, 0xF + offs); + break; + case 0x8: + setprg16(0xC000, (DRegs[3] + offs)); + setprg16(0x8000, offs); + break; + case 0x0: + case 0x4: + setprg16(0x8000, ((DRegs[3] & ~1) + offs)); + setprg16(0xc000, ((DRegs[3] & ~1) + offs + 1)); + break; + } + } +} + +static void MMC1MIRROR(void) { + if (!is171) + switch (DRegs[0] & 3) { + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + } +} + +static uint64 lreset; +static DECLFW(MMC1_write) { + int n = (A >> 13) - 4; + + /* The MMC1 is busy so ignore the write. */ + /* As of version FCE Ultra 0.81, the timestamp is only + increased before each instruction is executed(in other words + precision isn't that great), but this should still work to + deal with 2 writes in a row from a single RMW instruction. + */ + if ((timestampbase + timestamp) < (lreset + 2)) + return; +// FCEU_printf("Write %04x:%02x\n",A,V); + if (V & 0x80) { + DRegs[0] |= 0xC; + BufferShift = Buffer = 0; + MMC1PRG(); + lreset = timestampbase + timestamp; + return; + } + + Buffer |= (V & 1) << (BufferShift++); + + if (BufferShift == 5) { + DRegs[n] = Buffer; + BufferShift = Buffer = 0; + switch (n) { + case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break; + case 1: MMC1CHR(); MMC1PRG(); break; + case 2: MMC1CHR(); break; + case 3: MMC1PRG(); break; + } + } +} + +static void MMC1_Restore(int version) { + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); + lreset = 0; // timestamp(base) is not stored in save states. +} + +static void MMC1CMReset(void) { + int i; + + for (i = 0; i < 4; i++) + DRegs[i] = 0; + Buffer = BufferShift = 0; + DRegs[0] = 0x1F; + + DRegs[1] = 0; + DRegs[2] = 0; // Should this be something other than 0? + DRegs[3] = 0; + + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); +} + +static int DetectMMC1WRAMSize(uint32 crc32) { + switch (crc32) { + case 0xc6182024: // Romance of the 3 Kingdoms + case 0x2225c20f: // Genghis Khan + case 0x4642dda6: // Nobunaga's Ambition + case 0x29449ba9: // "" "" (J) + case 0x2b11e0b0: // "" "" (J) + case 0xb8747abf: // Best Play Pro Yakyuu Special (J) + case 0xc9556b36: // Final Fantasy I & II (J) [!] + FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(16); + break; + default: return(8); + } +} + +static uint32 NWCIRQCount; +static uint8 NWCRec; +#define NWCDIP 0xE + +static void NWCIRQHook(int a) { + if (!(NWCRec & 0x10)) { + NWCIRQCount += a; + if ((NWCIRQCount | (NWCDIP << 25)) >= 0x3e000000) { + NWCIRQCount = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void NWCCHRHook(uint32 A, uint8 V) { + if ((V & 0x10)) { // && !(NWCRec&0x10)) + NWCIRQCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + } + + NWCRec = V; + if (V & 0x08) + MMC1PRG(); + else + setprg32(0x8000, (V >> 1) & 3); +} + +static void NWCPRGHook(uint32 A, uint8 V) { + if (NWCRec & 0x8) + setprg16(A, 8 | (V & 0x7)); + else + setprg32(0x8000, (NWCRec >> 1) & 3); +} + +static void NWCPower(void) { + GenMMC1Power(); + setchr8r(0, 0); +} + +void Mapper105_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 8, 0); + MMC1CHRHook4 = NWCCHRHook; + MMC1PRGHook16 = NWCPRGHook; + MapIRQHook = NWCIRQHook; + info->Power = NWCPower; +} + +static void GenMMC1Power(void) { + lreset = 0; + if (mmc1opts & 1) { + FCEU_CheatAddRAM(8, 0x6000, WRAM); + if (mmc1opts & 4) + FCEU_dwmemset(WRAM, 0, 8192) + else if (!(mmc1opts & 2)) + FCEU_dwmemset(WRAM, 0, 8192); + } + SetWriteHandler(0x8000, 0xFFFF, MMC1_write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + + if (mmc1opts & 1) { + SetReadHandler(0x6000, 0x7FFF, MAWRAM); + SetWriteHandler(0x6000, 0x7FFF, MBWRAM); + setprg8r(0x10, 0x6000, 0); + } + + MMC1CMReset(); +} + +static void GenMMC1Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + if (WRAM) + FCEU_gfree(WRAM); + CHRRAM = WRAM = NULL; +} + +static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) { + is155 = 0; + + info->Close = GenMMC1Close; + MMC1PRGHook16 = MMC1CHRHook4 = 0; + mmc1opts = 0; + PRGmask16[0] &= (prg >> 14) - 1; + CHRmask4[0] &= (chr >> 12) - 1; + CHRmask8[0] &= (chr >> 13) - 1; + + if (wram) { + WRAM = (uint8*)FCEU_gmalloc(wram * 1024); + //mbg 17-jun-08 - this shouldve been cleared to re-initialize save ram + //ch4 10-dec-08 - nope, this souldn't + //mbg 29-mar-09 - no time to debate this, we need to keep from breaking some old stuff. + //we really need to make up a policy for how compatibility and accuracy can be resolved. + memset(WRAM, 0, wram * 1024); + mmc1opts |= 1; + if (wram > 8) mmc1opts |= 4; + SetupCartPRGMapping(0x10, WRAM, wram * 1024, 1); + AddExState(WRAM, wram * 1024, 0, "WRAM"); + if (battery) { + mmc1opts |= 2; + info->SaveGame[0] = WRAM + ((mmc1opts & 4) ? 8192 : 0); + info->SaveGameLen[0] = 8192; + } + } + if (!chr) { + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CHRR"); + } + AddExState(DRegs, 4, 0, "DREG"); + + info->Power = GenMMC1Power; + GameStateRestore = MMC1_Restore; + AddExState(&lreset, 8, 1, "LRST"); + AddExState(&Buffer, 1, 1, "BFFR"); + AddExState(&BufferShift, 1, 1, "BFRS"); +} + +void Mapper1_Init(CartInfo *info) { + int ws = DetectMMC1WRAMSize(info->CRC32); + GenMMC1Init(info, 512, 256, ws, info->battery); +} + +/* Same as mapper 1, without respect for WRAM enable bit. */ +void Mapper155_Init(CartInfo *info) { + GenMMC1Init(info, 512, 256, 8, info->battery); + is155 = 1; +} + +/* Same as mapper 1, with different (or without) mirroring control. */ +/* Kaiser KS7058 board, KS203 custom chip */ +void Mapper171_Init(CartInfo *info) { + GenMMC1Init(info, 32, 32, 0, 0); + is171 = 1; +} + +void SAROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 64, 8, info->battery); +} + +void SBROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 64, 0, 0); +} + +void SCROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 128, 0, 0); +} + +void SEROM_Init(CartInfo *info) { + GenMMC1Init(info, 32, 64, 0, 0); +} + +void SGROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 0, 0, 0); +} + +void SKROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 64, 8, info->battery); +} + +void SLROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 128, 0, 0); +} + +void SL1ROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 128, 0, 0); +} + +/* Begin unknown - may be wrong - perhaps they use different MMC1s from the + similarly functioning boards? +*/ + +void SL2ROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SFROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SHROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 0, 0); +} + +/* End unknown */ +/* */ +/* */ + +void SNROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 0, 8, info->battery); +} + +void SOROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 0, 16, info->battery); +} + + diff --git a/branches/fceux-2.2.2/src/boards/mmc2and4.cpp b/branches/fceux-2.2.2/src/boards/mmc2and4.cpp new file mode 100644 index 00000000..e2c3d7ea --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/mmc2and4.cpp @@ -0,0 +1,137 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 is10; +static uint8 creg[4], latch0, latch1, preg, mirr; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { creg, 4, "CREG" }, + { &preg, 1, "PREG" }, + { &mirr, 1, "MIRR" }, + { &latch0, 1, "LAT0" }, + { &latch1, 1, "LAT1" }, + { 0 } +}; + +static void Sync(void) { + if (is10) { + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + } else { + setprg8(0x8000, preg); + setprg8(0xA000, ~2); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + } + setchr4(0x0000, creg[latch0]); + setchr4(0x1000, creg[latch1 + 2]); + setmirror(mirr); +} + +DECLFW(MMC2and4Write) { + switch (A & 0xF000) { + case 0xA000: preg = V; Sync(); break; + case 0xB000: creg[0] = V; Sync(); break; + case 0xC000: creg[1] = V; Sync(); break; + case 0xD000: creg[2] = V; Sync(); break; + case 0xE000: creg[3] = V; Sync(); break; + case 0xF000: mirr = (V & 1) ^ 1; Sync(); break; + } +} + +static void MMC2and4PPUHook(uint32 A) { + uint8 l, h = A >> 8; + if (h >= 0x20 || ((h & 0xF) != 0xF)) + return; + l = A & 0xF0; + if (h < 0x10) { + if (l == 0xD0) { + latch0 = 0; + setchr4(0x0000, creg[0]); + } else if (l == 0xE0) { + latch0 = 1; + setchr4(0x0000, creg[1]); + } + } else { + if (l == 0xD0) { + latch1 = 0; + setchr4(0x1000, creg[2]); + } else if (l == 0xE0) { + latch1 = 1; + setchr4(0x1000, creg[3]); + } + } +} + +static void MMC2and4Power(void) { + preg = 0; + latch0 = latch1 = 1; + Sync(); + if (is10) { + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + } + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0xA000, 0xFFFF, MMC2and4Write); +} + +static void StateRestore(int version) { + Sync(); +} + +static void MMC2and4Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper9_Init(CartInfo *info) { + is10 = 0; + info->Power = MMC2and4Power; + PPU_hook = MMC2and4PPUHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper10_Init(CartInfo *info) { + is10 = 1; + info->Power = MMC2and4Power; + info->Close = MMC2and4Close; + PPU_hook = MMC2and4PPUHook; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/mmc3.cpp b/branches/fceux-2.2.2/src/boards/mmc3.cpp new file mode 100644 index 00000000..775a6766 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/mmc3.cpp @@ -0,0 +1,1328 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2003 Xodnizel + * Mapper 12 code Copyright (C) 2003 CaH4e3 + * + * 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 + */ + +/* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118, + 119,165,205,245,249,250,254 +*/ + +#include "mapinc.h" +#include "mmc3.h" + +uint8 MMC3_cmd; +uint8 *WRAM; +uint32 WRAMSIZE; +uint8 *CHRRAM; +uint32 CHRRAMSIZE; +uint8 DRegBuf[8]; +uint8 EXPREGS[8]; /* For bootleg games, mostly. */ +uint8 A000B, A001B; +uint8 mmc3opts = 0; + +#undef IRQCount +#undef IRQLatch +#undef IRQa +uint8 IRQCount, IRQLatch, IRQa; +uint8 IRQReload; + +static SFORMAT MMC3_StateRegs[] = +{ + { DRegBuf, 8, "REGS" }, + { &MMC3_cmd, 1, "CMD" }, + { &A000B, 1, "A000" }, + { &A001B, 1, "A001" }, + { &IRQReload, 1, "IRQR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQa, 1, "IRQA" }, + { 0 } +}; + +static int isRevB = 1; + +void (*pwrap)(uint32 A, uint8 V); +void (*cwrap)(uint32 A, uint8 V); +void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); + +// ---------------------------------------------------------------------- +// ------------------------- Generic MM3 Code --------------------------- +// ---------------------------------------------------------------------- + +void FixMMC3PRG(int V) { + if (V & 0x40) { + pwrap(0xC000, DRegBuf[6]); + pwrap(0x8000, ~1); + } else { + pwrap(0x8000, DRegBuf[6]); + pwrap(0xC000, ~1); + } + pwrap(0xA000, DRegBuf[7]); + pwrap(0xE000, ~0); +} + +void FixMMC3CHR(int V) { + int cbase = (V & 0x80) << 5; + + cwrap((cbase ^ 0x000), DRegBuf[0] & (~1)); + cwrap((cbase ^ 0x400), DRegBuf[0] | 1); + cwrap((cbase ^ 0x800), DRegBuf[1] & (~1)); + cwrap((cbase ^ 0xC00), DRegBuf[1] | 1); + + cwrap(cbase ^ 0x1000, DRegBuf[2]); + cwrap(cbase ^ 0x1400, DRegBuf[3]); + cwrap(cbase ^ 0x1800, DRegBuf[4]); + cwrap(cbase ^ 0x1c00, DRegBuf[5]); + + if (mwrap) mwrap(A000B); +} + +void MMC3RegReset(void) { + IRQCount = IRQLatch = IRQa = MMC3_cmd = 0; + + DRegBuf[0] = 0; + DRegBuf[1] = 2; + DRegBuf[2] = 4; + DRegBuf[3] = 5; + DRegBuf[4] = 6; + DRegBuf[5] = 7; + DRegBuf[6] = 0; + DRegBuf[7] = 1; + + FixMMC3PRG(0); + FixMMC3CHR(0); +} + +DECLFW(MMC3_CMDWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); + switch (A & 0xE001) { + case 0x8000: + if ((V & 0x40) != (MMC3_cmd & 0x40)) + FixMMC3PRG(V); + if ((V & 0x80) != (MMC3_cmd & 0x80)) + FixMMC3CHR(V); + MMC3_cmd = V; + break; + case 0x8001: + { + int cbase = (MMC3_cmd & 0x80) << 5; + DRegBuf[MMC3_cmd & 0x7] = V; + switch (MMC3_cmd & 0x07) { + case 0: + cwrap((cbase ^ 0x000), V & (~1)); + cwrap((cbase ^ 0x400), V | 1); + break; + case 1: + cwrap((cbase ^ 0x800), V & (~1)); + cwrap((cbase ^ 0xC00), V | 1); + break; + case 2: + cwrap(cbase ^ 0x1000, V); + break; + case 3: + cwrap(cbase ^ 0x1400, V); + break; + case 4: + cwrap(cbase ^ 0x1800, V); + break; + case 5: + cwrap(cbase ^ 0x1C00, V); + break; + case 6: + if (MMC3_cmd & 0x40) + pwrap(0xC000, V); + else + pwrap(0x8000, V); + break; + case 7: + pwrap(0xA000, V); + break; + } + break; + } + case 0xA000: + if (mwrap) mwrap(V); + break; + case 0xA001: + A001B = V; + break; + } +} + +DECLFW(MMC3_IRQWrite) { +// FCEU_printf("%04x:%04x\n",A,V); + switch (A & 0xE001) { + case 0xC000: IRQLatch = V; break; + case 0xC001: IRQReload = 1; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0xE001: IRQa = 1; break; + } +} + +static void ClockMMC3Counter(void) { + int count = IRQCount; + if (!count || IRQReload) { + IRQCount = IRQLatch; + IRQReload = 0; + } else + IRQCount--; + if ((count | isRevB) && !IRQCount) { + if (IRQa) { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void MMC3_hb(void) { + ClockMMC3Counter(); +} + +static void MMC3_hb_KickMasterHack(void) { + if (scanline == 238) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +static void MMC3_hb_PALStarWarsHack(void) { + if (scanline == 240) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +void GenMMC3Restore(int version) { + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void GENCWRAP(uint32 A, uint8 V) { + setchr1(A, V); // Business Wars NEEDS THIS for 8K CHR-RAM +} + +static void GENPWRAP(uint32 A, uint8 V) { + setprg8(A, V & 0x7F); // [NJ102] Mo Dao Jie (C) has 1024Mb MMC3 BOARD, maybe something other will be broken +} + +static void GENMWRAP(uint8 V) { + A000B = V; + setmirror((V & 1) ^ 1); +} + +static void GENNOMWRAP(uint8 V) { + A000B = V; +} + +static DECLFW(MBWRAMMMC6) { + WRAM[A & 0x3ff] = V; +} + +static DECLFR(MAWRAMMMC6) { + return(WRAM[A & 0x3ff]); +} + +void GenMMC3Power(void) { + if (UNIFchrrama) setchr8(0); + + SetWriteHandler(0x8000, 0xBFFF, MMC3_CMDWrite); + SetWriteHandler(0xC000, 0xFFFF, MMC3_IRQWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + A001B = A000B = 0; + setmirror(1); + if (mmc3opts & 1) { + if (WRAMSIZE == 1024) { + FCEU_CheatAddRAM(1, 0x7000, WRAM); + SetReadHandler(0x7000, 0x7FFF, MAWRAMMMC6); + SetWriteHandler(0x7000, 0x7FFF, MBWRAMMMC6); + } else { + FCEU_CheatAddRAM((WRAMSIZE & 0x1fff) >> 10, 0x6000, WRAM); + SetWriteHandler(0x6000, 0x6000 + ((WRAMSIZE - 1) & 0x1fff), CartBW); + SetReadHandler(0x6000, 0x6000 + ((WRAMSIZE - 1) & 0x1fff), CartBR); + setprg8r(0x10, 0x6000, 0); + } + if (!(mmc3opts & 2)) + FCEU_dwmemset(WRAM, 0, WRAMSIZE); + } + MMC3RegReset(); + if (CHRRAM) + FCEU_dwmemset(CHRRAM, 0, CHRRAMSIZE); +} + +static void GenMMC3Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + if (WRAM) + FCEU_gfree(WRAM); + CHRRAM = WRAM = NULL; +} + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) { + pwrap = GENPWRAP; + cwrap = GENCWRAP; + mwrap = GENMWRAP; + + WRAMSIZE = wram << 10; + + PRGmask8[0] &= (prg >> 13) - 1; + CHRmask1[0] &= (chr >> 10) - 1; + CHRmask2[0] &= (chr >> 11) - 1; + + if (wram) { + mmc3opts |= 1; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + + if (battery) { + mmc3opts |= 2; + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(MMC3_StateRegs, ~0, 0, 0); + + info->Power = GenMMC3Power; + info->Reset = MMC3RegReset; + info->Close = GenMMC3Close; + + if (info->CRC32 == 0x5104833e) // Kick Master + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if (info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20)// Shougi Meikan '92/'93 + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if (info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master. + GameHBIRQHook = MMC3_hb_PALStarWarsHack; + else + GameHBIRQHook = MMC3_hb; + GameStateRestore = GenMMC3Restore; +} + +// ---------------------------------------------------------------------- +// -------------------------- MMC3 Based Code --------------------------- +// ---------------------------------------------------------------------- + +// ---------------------------- Mapper 4 -------------------------------- + +static int hackm4 = 0; /* For Karnov, maybe others. BLAH. Stupid iNES format.*/ + +static void M4Power(void) { + GenMMC3Power(); + A000B = (hackm4 ^ 1) & 1; + setmirror(hackm4); +} + +void Mapper4_Init(CartInfo *info) { + int ws = 8; + + if ((info->CRC32 == 0x93991433 || info->CRC32 == 0xaf65aa84)) { + FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n"); + ws = 0; + } + GenMMC3_Init(info, 512, 256, ws, info->battery); + info->Power = M4Power; + hackm4 = info->mirror; +} + +// ---------------------------- Mapper 12 ------------------------------- + +static void M12CW(uint32 A, uint8 V) { + setchr1(A, (EXPREGS[(A & 0x1000) >> 12] << 8) + V); +} + +static DECLFW(M12Write) { + EXPREGS[0] = V & 0x01; + EXPREGS[1] = (V & 0x10) >> 4; +} + +static DECLFR(M12Read) { + return EXPREGS[2]; +} + +static void M12Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + EXPREGS[2] = 1; // chinese is default + GenMMC3Power(); + SetWriteHandler(0x4100, 0x5FFF, M12Write); + SetReadHandler(0x4100, 0x5FFF, M12Read); +} + +static void M12Reset(void) { + EXPREGS[0] = EXPREGS[1] = 0; + EXPREGS[2] ^= 1; + MMC3RegReset(); +} + +void Mapper12_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M12CW; + isRevB = 0; + + info->Power = M12Power; + info->Reset = M12Reset; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 37 ------------------------------- + +static void M37PW(uint32 A, uint8 V) { + if (EXPREGS[0] != 2) + V &= 0x7; + else + V &= 0xF; + V |= EXPREGS[0] << 3; + setprg8(A, V); +} + +static void M37CW(uint32 A, uint8 V) { + uint32 NV = V; + NV &= 0x7F; + NV |= EXPREGS[0] << 6; + setchr1(A, NV); +} + +static DECLFW(M37Write) { + EXPREGS[0] = (V & 6) >> 1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M37Reset(void) { + EXPREGS[0] = 0; + MMC3RegReset(); +} + +static void M37Power(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, M37Write); +} + +void Mapper37_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + pwrap = M37PW; + cwrap = M37CW; + info->Power = M37Power; + info->Reset = M37Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 44 ------------------------------- + +static void M44PW(uint32 A, uint8 V) { + uint32 NV = V; + if (EXPREGS[0] >= 6) NV &= 0x1F; + else NV &= 0x0F; + NV |= EXPREGS[0] << 4; + setprg8(A, NV); +} + +static void M44CW(uint32 A, uint8 V) { + uint32 NV = V; + if (EXPREGS[0] < 6) NV &= 0x7F; + NV |= EXPREGS[0] << 7; + setchr1(A, NV); +} + +static DECLFW(M44Write) { + if (A & 1) { + EXPREGS[0] = V & 7; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else + MMC3_CMDWrite(A, V); +} + +static void M44Power(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0xA000, 0xBFFF, M44Write); +} + +void Mapper44_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M44CW; + pwrap = M44PW; + info->Power = M44Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 45 ------------------------------- + +static void M45CW(uint32 A, uint8 V) { + if (!UNIFchrrama) { + uint32 NV = V; + if (EXPREGS[2] & 8) + NV &= (1 << ((EXPREGS[2] & 7) + 1)) - 1; + else + if (EXPREGS[2]) + NV &= 0; // hack ;( don't know exactly how it should be + NV |= EXPREGS[0] | ((EXPREGS[2] & 0xF0) << 4); + setchr1(A, NV); + } +} + +static void M45PW(uint32 A, uint8 V) { + V &= (EXPREGS[3] & 0x3F) ^ 0x3F; + V |= EXPREGS[1]; + setprg8(A, V); +} + +static DECLFW(M45Write) { + if (EXPREGS[3] & 0x40) { + WRAM[A - 0x6000] = V; + return; + } + EXPREGS[EXPREGS[4]] = V; + EXPREGS[4] = (EXPREGS[4] + 1) & 3; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(M45Read) { + uint32 addr = 1 << (EXPREGS[5] + 4); + if (A & (addr | (addr - 1))) + return X.DB | 1; + else + return X.DB; +} + +static void M45Reset(void) { + EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = EXPREGS[4] = 0; + EXPREGS[5]++; + EXPREGS[5] &= 7; + MMC3RegReset(); +} + +static void M45Power(void) { + setchr8(0); + GenMMC3Power(); + EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = EXPREGS[4] = EXPREGS[5] = 0; + SetWriteHandler(0x5000, 0x7FFF, M45Write); + SetReadHandler(0x5000, 0x5FFF, M45Read); +} + +void Mapper45_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M45CW; + pwrap = M45PW; + info->Reset = M45Reset; + info->Power = M45Power; + AddExState(EXPREGS, 5, 0, "EXPR"); +} + +// ---------------------------- Mapper 47 ------------------------------- + +static void M47PW(uint32 A, uint8 V) { + V &= 0xF; + V |= EXPREGS[0] << 4; + setprg8(A, V); +} + +static void M47CW(uint32 A, uint8 V) { + uint32 NV = V; + NV &= 0x7F; + NV |= EXPREGS[0] << 7; + setchr1(A, NV); +} + +static DECLFW(M47Write) { + EXPREGS[0] = V & 1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M47Power(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, M47Write); +// SetReadHandler(0x6000,0x7FFF,0); +} + +void Mapper47_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, 0); + pwrap = M47PW; + cwrap = M47CW; + info->Power = M47Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 49 ------------------------------- + +static void M49PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 1) { + V &= 0xF; + V |= (EXPREGS[0] & 0xC0) >> 2; + setprg8(A, V); + } else + setprg32(0x8000, (EXPREGS[0] >> 4) & 3); +} + +static void M49CW(uint32 A, uint8 V) { + uint32 NV = V; + NV &= 0x7F; + NV |= (EXPREGS[0] & 0xC0) << 1; + setchr1(A, NV); +} + +static DECLFW(M49Write) { + if (A001B & 0x80) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void M49Reset(void) { + EXPREGS[0] = 0; + MMC3RegReset(); +} + +static void M49Power(void) { + M49Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, M49Write); + SetReadHandler(0x6000, 0x7FFF, 0); +} + +void Mapper49_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 0, 0); + cwrap = M49CW; + pwrap = M49PW; + info->Reset = M49Reset; + info->Power = M49Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 52 ------------------------------- +static void M52PW(uint32 A, uint8 V) { + uint32 mask = 0x1F ^ ((EXPREGS[0] & 8) << 1); + uint32 bank = ((EXPREGS[0] & 6) | ((EXPREGS[0] >> 3) & EXPREGS[0] & 1)) << 4; + setprg8(A, bank | (V & mask)); +} + +static void M52CW(uint32 A, uint8 V) { + uint32 mask = 0xFF ^ ((EXPREGS[0] & 0x40) << 1); +// uint32 bank = (((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; + uint32 bank = (((EXPREGS[0] >> 4) & 2) | (EXPREGS[0] & 4) | ((EXPREGS[0] >> 6) & (EXPREGS[0] >> 4) & 1)) << 7; // actually 256K CHR banks index bits is inverted! + setchr1(A, bank | (V & mask)); +} + +static DECLFW(M52Write) { + if (EXPREGS[1]) { + WRAM[A - 0x6000] = V; + return; + } + EXPREGS[1] = V & 0x80; + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M52Reset(void) { + EXPREGS[0] = EXPREGS[1] = 0; + MMC3RegReset(); +} + +static void M52Power(void) { + M52Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, M52Write); +} + +void Mapper52_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 8, info->battery); + cwrap = M52CW; + pwrap = M52PW; + info->Reset = M52Reset; + info->Power = M52Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 76 ------------------------------- + +static void M76CW(uint32 A, uint8 V) { + if (A >= 0x1000) + setchr2((A & 0xC00) << 1, V); +} + +void Mapper76_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 0, 0); + cwrap = M76CW; +} + +// ---------------------------- Mapper 74 ------------------------------- + +static void M74CW(uint32 A, uint8 V) { + if ((V == 8) || (V == 9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes + setchr1r(0x10, A, V); + else + setchr1r(0, A, V); +} + +void Mapper74_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M74CW; + CHRRAMSIZE = 2048; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); +} + +// ---------------------------- Mapper 114 ------------------------------ + +static uint8 cmdin; +uint8 m114_perm[8] = { 0, 3, 1, 5, 6, 7, 2, 4 }; + +static void M114PWRAP(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x80) { +// FCEU_printf("8000-C000:%02X\n",EXPREGS[0]&0xF); + setprg16(0x8000, EXPREGS[0] & 0xF); + setprg16(0xC000, EXPREGS[0] & 0xF); + } else { +// FCEU_printf("%04X:%02X\n",A,V&0x3F); + setprg8(A, V & 0x3F); + } +} + +static DECLFW(M114Write) { + switch (A & 0xE001) { + case 0x8001: MMC3_CMDWrite(0xA000, V); break; + case 0xA000: MMC3_CMDWrite(0x8000, (V & 0xC0) | (m114_perm[V & 7])); cmdin = 1; break; + case 0xC000: if (!cmdin) break; MMC3_CMDWrite(0x8001, V); cmdin = 0; break; + case 0xA001: IRQLatch = V; break; + case 0xC001: IRQReload = 1; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0xE001: IRQa = 1; break; + } +} + +static DECLFW(M114ExWrite) { + if (A <= 0x7FFF) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + } +} + +static void M114Power(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xFFFF, M114Write); + SetWriteHandler(0x5000, 0x7FFF, M114ExWrite); +} + +static void M114Reset(void) { + EXPREGS[0] = 0; + MMC3RegReset(); +} + +void Mapper114_Init(CartInfo *info) { + isRevB = 0; + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = M114PWRAP; + info->Power = M114Power; + info->Reset = M114Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDI"); +} + +// ---------------------------- Mapper 115 KN-658 board ------------------------------ + +static void M115PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x80) { + if (EXPREGS[0] & 0x20) + setprg32(0x8000, (EXPREGS[0] & 0x0F) >> 1); // real hardware tests, info 100% now lol + else { + setprg16(0x8000, (EXPREGS[0] & 0x0F)); + setprg16(0xC000, (EXPREGS[0] & 0x0F)); + } + } else + setprg8(A, V); +} + +static void M115CW(uint32 A, uint8 V) { + setchr1(A, (uint32)V | ((EXPREGS[1] & 1) << 8)); +} + +static DECLFW(M115Write) { + if (A == 0x5080) + EXPREGS[2] = V; // Extra prot hardware 2-in-1 mode + else if (A == 0x6000) + EXPREGS[0] = V; + else if (A == 0x6001) + EXPREGS[1] = V; + FixMMC3PRG(MMC3_cmd); +} + +static DECLFR(M115Read) { + return EXPREGS[2]; +} + +static void M115Power(void) { + GenMMC3Power(); + SetWriteHandler(0x4100, 0x7FFF, M115Write); + SetReadHandler(0x5000, 0x5FFF, M115Read); +} + +void Mapper115_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 512, 0, 0); + cwrap = M115CW; + pwrap = M115PW; + info->Power = M115Power; + AddExState(EXPREGS, 3, 0, "EXPR"); +} + +// ---------------------------- Mapper 118 ------------------------------ + +static uint8 PPUCHRBus; +static uint8 TKSMIR[8]; + +static void TKSPPU(uint32 A) { + A &= 0x1FFF; + A >>= 10; + PPUCHRBus = A; + setmirror(MI_0 + TKSMIR[A]); +} + +static void TKSWRAP(uint32 A, uint8 V) { + TKSMIR[A >> 10] = V >> 7; + setchr1(A, V & 0x7F); + if (PPUCHRBus == (A >> 10)) + setmirror(MI_0 + (V >> 7)); +} + +// ---------------------------- Mapper 119 ------------------------------ + +static void TQWRAP(uint32 A, uint8 V) { + setchr1r((V & 0x40) >> 2, A, V & 0x3F); +} + +void Mapper119_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap = TQWRAP; + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); +} + +// ---------------------------- Mapper 134 ------------------------------ + +static void M134PW(uint32 A, uint8 V) { + setprg8(A, (V & 0x1F) | ((EXPREGS[0] & 2) << 4)); +} + +static void M134CW(uint32 A, uint8 V) { + setchr1(A, (V & 0xFF) | ((EXPREGS[0] & 0x20) << 3)); +} + +static DECLFW(M134Write) { + EXPREGS[0] = V; + FixMMC3CHR(MMC3_cmd); + FixMMC3PRG(MMC3_cmd); +} + +static void M134Power(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6001, 0x6001, M134Write); +} + +static void M134Reset(void) { + EXPREGS[0] = 0; + MMC3RegReset(); +} + +void Mapper134_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = M134PW; + cwrap = M134CW; + info->Power = M134Power; + info->Reset = M134Reset; + AddExState(EXPREGS, 4, 0, "EXPR"); +} + +// ---------------------------- Mapper 165 ------------------------------ + +static void M165CW(uint32 A, uint8 V) { + if (V == 0) + setchr4r(0x10, A, 0); + else + setchr4(A, V >> 2); +} + +static void M165PPUFD(void) { + if (EXPREGS[0] == 0xFD) { + M165CW(0x0000, DRegBuf[0]); + M165CW(0x1000, DRegBuf[2]); + } +} + +static void M165PPUFE(void) { + if (EXPREGS[0] == 0xFE) { + M165CW(0x0000, DRegBuf[1]); + M165CW(0x1000, DRegBuf[4]); + } +} + +static void M165CWM(uint32 A, uint8 V) { + if (((MMC3_cmd & 0x7) == 0) || ((MMC3_cmd & 0x7) == 2)) + M165PPUFD(); + if (((MMC3_cmd & 0x7) == 1) || ((MMC3_cmd & 0x7) == 4)) + M165PPUFE(); +} + +static void M165PPU(uint32 A) { + if ((A & 0x1FF0) == 0x1FD0) { + EXPREGS[0] = 0xFD; + M165PPUFD(); + } else if ((A & 0x1FF0) == 0x1FE0) { + EXPREGS[0] = 0xFE; + M165PPUFE(); + } +} + +static void M165Power(void) { + EXPREGS[0] = 0xFD; + GenMMC3Power(); +} + +void Mapper165_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 128, 8, info->battery); + cwrap = M165CWM; + PPU_hook = M165PPU; + info->Power = M165Power; + CHRRAMSIZE = 4096; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); + AddExState(EXPREGS, 4, 0, "EXPR"); +} + +// ---------------------------- Mapper 191 ------------------------------ + +static void M191CW(uint32 A, uint8 V) { + setchr1r((V & 0x80) >> 3, A, V); +} + +void Mapper191_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 8, info->battery); + cwrap = M191CW; + CHRRAMSIZE = 2048; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); +} + +// ---------------------------- Mapper 192 ------------------------------- + +static void M192CW(uint32 A, uint8 V) { + //Ying Lie Qun Xia Zhuan (Chinese), + //You Ling Xing Dong (China) (Unl) [this will be mistakenly headered as m074 sometimes] + if ((V == 8) || (V == 9) || (V == 0xA) || (V == 0xB)) + setchr1r(0x10, A, V); + else + setchr1r(0, A, V); +} + +void Mapper192_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M192CW; + CHRRAMSIZE = 4096; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); +} + +// ---------------------------- Mapper 194 ------------------------------- + +static void M194CW(uint32 A, uint8 V) { + if (V <= 1) //Dai-2-Ji - Super Robot Taisen (As).nes + setchr1r(0x10, A, V); + else + setchr1r(0, A, V); +} + +void Mapper194_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M194CW; + CHRRAMSIZE = 2048; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); +} + +// ---------------------------- Mapper 195 ------------------------------- +static void M195CW(uint32 A, uint8 V) { + if (V <= 3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C) + setchr1r(0x10, A, V); + else + setchr1r(0, A, V); +} + +static void M195Power(void) { + GenMMC3Power(); + setprg4r(0x10, 0x5000, 2); + SetWriteHandler(0x5000, 0x5fff, CartBW); + SetReadHandler(0x5000, 0x5fff, CartBR); +} + +void Mapper195_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 16, info->battery); + cwrap = M195CW; + info->Power = M195Power; + CHRRAMSIZE = 4096; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); +} + +// ---------------------------- Mapper 196 ------------------------------- +// MMC3 board with optional command address line connection, allows to +// make three-four different wirings to IRQ address lines and separately to +// CMD address line, Mali Boss additionally check if wiring are correct for +// game + +static void M196PW(uint32 A, uint8 V) { + if (EXPREGS[0]) + setprg32(0x8000, EXPREGS[1]); + else + setprg8(A, V); +} + +static DECLFW(Mapper196Write) { + if (A >= 0xC000) { + A = (A & 0xFFFE) | ((A >> 2) & 1) | ((A >> 3) & 1); + MMC3_IRQWrite(A, V); + } else { + A = (A & 0xFFFE) | ((A >> 2) & 1) | ((A >> 3) & 1) | ((A >> 1) & 1); + MMC3_CMDWrite(A, V); + } +} + +static DECLFW(Mapper196WriteLo) { + EXPREGS[0] = 1; + EXPREGS[1] = (V & 0xf) | (V >> 4); + FixMMC3PRG(MMC3_cmd); +} + +static void Mapper196Power(void) { + GenMMC3Power(); + EXPREGS[0] = EXPREGS[1] = 0; + SetWriteHandler(0x6000, 0x6FFF, Mapper196WriteLo); + SetWriteHandler(0x8000, 0xFFFF, Mapper196Write); +} + +void Mapper196_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 0, 0); + pwrap = M196PW; + info->Power = Mapper196Power; +} + +// ---------------------------- Mali Splash Bomb---------------------------- +// The same board as for 196 mapper games, but with additional data bit swap +// Also, it is impossible to work on the combined 196 mapper source with +// all data bits merged, because it's using one of them as 8000 reg... + +static void UNLMaliSBPW(uint32 A, uint8 V) { + setprg8(A, (V & 3) | ((V & 8) >> 1) | ((V & 4) << 1)); +} + +static void UNLMaliSBCW(uint32 A, uint8 V) { + setchr1(A, (V & 0xDD) | ((V & 0x20) >> 4) | ((V & 2) << 4)); +} + +static DECLFW(UNLMaliSBWrite) { + if (A >= 0xC000) { + A = (A & 0xFFFE) | ((A >> 2) & 1) | ((A >> 3) & 1); + MMC3_IRQWrite(A, V); + } else { + A = (A & 0xFFFE) | ((A >> 3) & 1); + MMC3_CMDWrite(A, V); + } +} + +static void UNLMaliSBPower(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xFFFF, UNLMaliSBWrite); +} + +void UNLMaliSB_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 0, 0); + pwrap = UNLMaliSBPW; + cwrap = UNLMaliSBCW; + info->Power = UNLMaliSBPower; +} + +// ---------------------------- Mapper 197 ------------------------------- + +static void M197CW(uint32 A, uint8 V) { + if (A == 0x0000) + setchr4(0x0000, V >> 1); + else if (A == 0x1000) + setchr2(0x1000, V); + else if (A == 0x1400) + setchr2(0x1800, V); +} + +void Mapper197_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 512, 8, 0); + cwrap = M197CW; +} + +// ---------------------------- Mapper 198 ------------------------------- + +static void M198PW(uint32 A, uint8 V) { + if (V >= 0x50) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes + setprg8(A, V & 0x4F); + else + setprg8(A, V); +} + +void Mapper198_Init(CartInfo *info) { + GenMMC3_Init(info, 1024, 0, 16, info->battery); + pwrap = M198PW; + info->Power = M195Power; +} + +// ---------------------------- Mapper 205 ------------------------------ +// GN-45 BOARD + +static void M205PW(uint32 A, uint8 V) { +// GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü 1F + àïïàðàòíûé ïåðåêëþ÷àòåëü íà øèíå àäðåñà + setprg8(A, (V & 0x0f) | EXPREGS[0]); +} + +static void M205CW(uint32 A, uint8 V) { +// GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü FF + setchr1(A, (V & 0x7F) | (EXPREGS[0] << 3)); +} + +static DECLFW(M205Write0) { + if (EXPREGS[2] == 0) { + EXPREGS[0] = A & 0x30; + EXPREGS[2] = A & 0x80; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else + CartBW(A, V); +} + +static DECLFW(M205Write1) { + if (EXPREGS[2] == 0) { + EXPREGS[0] = V & 0x30; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else + CartBW(A, V); +} + +static void M205Reset(void) { + EXPREGS[0] = EXPREGS[2] = 0; + MMC3RegReset(); +} + +static void M205Power(void) { + GenMMC3Power(); + SetWriteHandler(0x6000, 0x6fff, M205Write0); + SetWriteHandler(0x7000, 0x7fff, M205Write1); // OK-411 boards, the same logic, but data latched, 2-in-1 frankenstein +} + +void Mapper205_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap = M205PW; + cwrap = M205CW; + info->Power = M205Power; + info->Reset = M205Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 245 ------------------------------ + +static void M245CW(uint32 A, uint8 V) { + if (!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS for RAM cart + setchr1(A, V & 7); + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); +} + +static void M245PW(uint32 A, uint8 V) { + setprg8(A, (V & 0x3F) | ((EXPREGS[0] & 2) << 5)); +} + +static void M245Power(void) { + EXPREGS[0] = 0; + GenMMC3Power(); +} + +void Mapper245_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M245CW; + pwrap = M245PW; + info->Power = M245Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 249 ------------------------------ + +static void M249PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x2) { + if (V < 0x20) + V = (V & 1) | ((V >> 3) & 2) | ((V >> 1) & 4) | ((V << 2) & 8) | ((V << 2) & 0x10); + else { + V -= 0x20; + V = (V & 3) | ((V >> 1) & 4) | ((V >> 4) & 8) | ((V >> 2) & 0x10) | ((V << 3) & 0x20) | ((V << 2) & 0xC0); + } + } + setprg8(A, V); +} + +static void M249CW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x2) + V = (V & 3) | ((V >> 1) & 4) | ((V >> 4) & 8) | ((V >> 2) & 0x10) | ((V << 3) & 0x20) | ((V << 2) & 0xC0); + setchr1(A, V); +} + +static DECLFW(M249Write) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M249Power(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x5000, 0x5000, M249Write); +} + +void Mapper249_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M249CW; + pwrap = M249PW; + info->Power = M249Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 250 ------------------------------ + +static DECLFW(M250Write) { + MMC3_CMDWrite((A & 0xE000) | ((A & 0x400) >> 10), A & 0xFF); +} + +static DECLFW(M250IRQWrite) { + MMC3_IRQWrite((A & 0xE000) | ((A & 0x400) >> 10), A & 0xFF); +} + +static void M250_Power(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xBFFF, M250Write); + SetWriteHandler(0xC000, 0xFFFF, M250IRQWrite); +} + +void Mapper250_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + info->Power = M250_Power; +} + +// ---------------------------- Mapper 254 ------------------------------ + +static DECLFR(MR254WRAM) { + if (EXPREGS[0]) + return WRAM[A - 0x6000]; + else + return WRAM[A - 0x6000] ^ EXPREGS[1]; +} + +static DECLFW(M254Write) { + switch (A) { + case 0x8000: EXPREGS[0] = 0xff; break; + case 0xA001: EXPREGS[1] = V; break; + } + MMC3_CMDWrite(A, V); +} + +static void M254_Power(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xBFFF, M254Write); + SetReadHandler(0x6000, 0x7FFF, MR254WRAM); +} + +void Mapper254_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, info->battery); + info->Power = M254_Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- UNIF Boards ----------------------------- + +void TBROM_Init(CartInfo *info) { + GenMMC3_Init(info, 64, 64, 0, 0); +} + +void TEROM_Init(CartInfo *info) { + GenMMC3_Init(info, 32, 32, 0, 0); +} + +void TFROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 64, 0, 0); +} + +void TGROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 0, 0, 0); +} + +void TKROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); +} + +void TLROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 0, 0); +} + +void TSROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, 0); +} + +void TLSROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, 0); + cwrap = TKSWRAP; + mwrap = GENNOMWRAP; + PPU_hook = TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TKSROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = TKSWRAP; + mwrap = GENNOMWRAP; + PPU_hook = TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TQROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap = TQWRAP; + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); +} + +void HKROM_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 512, 1, info->battery); +} diff --git a/branches/fceux-2.2.2/src/boards/mmc3.h b/branches/fceux-2.2.2/src/boards/mmc3.h new file mode 100644 index 00000000..9dfbc920 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/mmc3.h @@ -0,0 +1,26 @@ +extern uint8 MMC3_cmd; +extern uint8 mmc3opts; +extern uint8 A000B; +extern uint8 A001B; +extern uint8 EXPREGS[8]; +extern uint8 DRegBuf[8]; + +#undef IRQCount +#undef IRQLatch +#undef IRQa +extern uint8 IRQCount,IRQLatch,IRQa; +extern uint8 IRQReload; + +extern void (*pwrap)(uint32 A, uint8 V); +extern void (*cwrap)(uint32 A, uint8 V); +extern void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void GenMMC3Restore(int version); +void MMC3RegReset(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); +DECLFW(MMC3_CMDWrite); +DECLFW(MMC3_IRQWrite); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); diff --git a/branches/fceux-2.2.2/src/boards/mmc5.cpp b/branches/fceux-2.2.2/src/boards/mmc5.cpp new file mode 100644 index 00000000..d7703f4e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/mmc5.cpp @@ -0,0 +1,874 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 + */ + +/* None of this code should use any of the iNES bank switching wrappers. */ + +#include "mapinc.h" + +static void (*sfun)(int P); +static void (*psfun)(void); + +void MMC5RunSound(int Count); +void MMC5RunSoundHQ(void); + +static INLINE void MMC5SPRVROM_BANK1(uint32 A, uint32 V) { + if (CHRptr[0]) { + V &= CHRmask1[0]; + MMC5SPRVPage[(A) >> 10] = &CHRptr[0][(V) << 10] - (A); + } +} + +static INLINE void MMC5BGVROM_BANK1(uint32 A, uint32 V) { + if (CHRptr[0]) { + V &= CHRmask1[0]; MMC5BGVPage[(A) >> 10] = &CHRptr[0][(V) << 10] - (A); + } +} + +static INLINE void MMC5SPRVROM_BANK2(uint32 A, uint32 V) { + if (CHRptr[0]) { + V &= CHRmask2[0]; MMC5SPRVPage[(A) >> 10] = MMC5SPRVPage[((A) >> 10) + 1] = &CHRptr[0][(V) << 11] - (A); + } +} +static INLINE void MMC5BGVROM_BANK2(uint32 A, uint32 V) { + if (CHRptr[0]) { + V &= CHRmask2[0]; MMC5BGVPage[(A) >> 10] = MMC5BGVPage[((A) >> 10) + 1] = &CHRptr[0][(V) << 11] - (A); + } +} + +static INLINE void MMC5SPRVROM_BANK4(uint32 A, uint32 V) { + if (CHRptr[0]) { + V &= CHRmask4[0]; MMC5SPRVPage[(A) >> 10] = MMC5SPRVPage[((A) >> 10) + 1] = MMC5SPRVPage[((A) >> 10) + 2] = MMC5SPRVPage[((A) >> 10) + 3] = &CHRptr[0][(V) << 12] - (A); + } +} +static INLINE void MMC5BGVROM_BANK4(uint32 A, uint32 V) { + if (CHRptr[0]) { + V &= CHRmask4[0]; MMC5BGVPage[(A) >> 10] = MMC5BGVPage[((A) >> 10) + 1] = MMC5BGVPage[((A) >> 10) + 2] = MMC5BGVPage[((A) >> 10) + 3] = &CHRptr[0][(V) << 12] - (A); + } +} + +static INLINE void MMC5SPRVROM_BANK8(uint32 V) { + if (CHRptr[0]) { + V &= CHRmask8[0]; MMC5SPRVPage[0] = MMC5SPRVPage[1] = MMC5SPRVPage[2] = MMC5SPRVPage[3] = MMC5SPRVPage[4] = MMC5SPRVPage[5] = MMC5SPRVPage[6] = MMC5SPRVPage[7] = &CHRptr[0][(V) << 13]; + } +} +static INLINE void MMC5BGVROM_BANK8(uint32 V) { + if (CHRptr[0]) { + V &= CHRmask8[0]; MMC5BGVPage[0] = MMC5BGVPage[1] = MMC5BGVPage[2] = MMC5BGVPage[3] = MMC5BGVPage[4] = MMC5BGVPage[5] = MMC5BGVPage[6] = MMC5BGVPage[7] = &CHRptr[0][(V) << 13]; + } +} + +static uint8 PRGBanks[4]; +static uint8 WRAMPage; +static uint16 CHRBanksA[8], CHRBanksB[4]; +static uint8 WRAMMaskEnable[2]; +uint8 mmc5ABMode; /* A=0, B=1 */ + +static uint8 IRQScanline, IRQEnable; +static uint8 CHRMode, NTAMirroring, NTFill, ATFill; + +static uint8 MMC5IRQR; +static uint8 MMC5LineCounter; +static uint8 mmc5psize, mmc5vsize; +static uint8 mul[2]; + +static uint8 *WRAM = NULL; +static uint8 *MMC5fill = NULL; +static uint8 *ExRAM = NULL; + +static uint8 MMC5WRAMsize; //configuration, not state +static uint8 MMC5WRAMIndex[8]; //configuration, not state + +static uint8 MMC5ROMWrProtect[4]; +static uint8 MMC5MemIn[5]; + +static void MMC5CHRA(void); +static void MMC5CHRB(void); + +typedef struct __cartdata { + uint32 crc32; + uint8 size; +} cartdata; + +#define Sprite16 (PPU[0]& 0x20) //Sprites 8x16/8x8 +//#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)] +static inline uint8 * MMC5BGVRAMADR(uint32 A) { + if (!Sprite16) { + if (mmc5ABMode == 0) + return &MMC5SPRVPage[(A) >> 10][(A)]; + else + return &MMC5BGVPage[(A) >> 10][(A)]; + } else return &MMC5BGVPage[(A) >> 10][(A)]; +} + +static void mmc5_PPUWrite(uint32 A, uint8 V) { + uint32 tmp = A; + extern uint8 PALRAM[0x20]; + + if (tmp >= 0x3F00) { + // hmmm.... + if (!(tmp & 0xf)) + PALRAM[0x00] = PALRAM[0x04] = PALRAM[0x08] = PALRAM[0x0C] = V & 0x3F; + else if (tmp & 3) PALRAM[(tmp & 0x1f)] = V & 0x3f; + } else if (tmp < 0x2000) { + if (PPUCHRRAM & (1 << (tmp >> 10))) + VPage[tmp >> 10][tmp] = V; + } else { + if (PPUNTARAM & (1 << ((tmp & 0xF00) >> 10))) + vnapage[((tmp & 0xF00) >> 10)][tmp & 0x3FF] = V; + } +} + +uint8 FASTCALL mmc5_PPURead(uint32 A) { + if (A < 0x2000) { + if (ppuphase == PPUPHASE_BG) + return *MMC5BGVRAMADR(A); + else return MMC5SPRVPage[(A) >> 10][(A)]; + } else { + return vnapage[(A >> 10) & 0x3][A & 0x3FF]; + } +} + +cartdata MMC5CartList[] = +{ + { 0x6f4e4312, 4 }, /* Aoki Ookami to Shiroki Mejika - Genchou Hishi */ + { 0x15fe6d0f, 2 }, /* Bandit Kings of Ancient China */ + { 0x671f23a8, 0 }, /* Castlevania III - Dracula's Curse (E) */ + { 0xcd4e7430, 0 }, /* Castlevania III - Dracula's Curse (KC) */ + { 0xed2465be, 0 }, /* Castlevania III - Dracula's Curse (U) */ + { 0xfe3488d1, 2 }, /* Daikoukai Jidai */ + { 0x0ec6c023, 1 }, /* Gemfire */ + { 0x0afb395e, 0 }, /* Gun Sight */ + { 0x1ced086f, 2 }, /* Ishin no Arashi */ + { 0x9cbadc25, 1 }, /* Just Breed */ + { 0x6396b988, 2 }, /* L'Empereur (J) */ + { 0x9c18762b, 2 }, /* L'Empereur (U) */ + { 0xb0480ae9, 0 }, /* Laser Invasion */ + { 0xb4735fac, 0 }, /* Metal Slader Glory */ + { 0xf540677b, 4 }, /* Nobunaga no Yabou - Bushou Fuuun Roku */ + { 0xeee9a682, 2 }, /* Nobunaga no Yabou - Sengoku Gunyuu Den (J) (PRG0) */ + { 0xf9b4240f, 2 }, /* Nobunaga no Yabou - Sengoku Gunyuu Den (J) (PRG1) */ + { 0x8ce478db, 2 }, /* Nobunaga's Ambition 2 */ + { 0xf011e490, 4 }, /* Romance of The Three Kingdoms II */ + { 0xbc80fb52, 1 }, /* Royal Blood */ + { 0x184c2124, 4 }, /* Sangokushi II (J) (PRG0) */ + { 0xee8e6553, 4 }, /* Sangokushi II (J) (PRG1) */ + { 0xd532e98f, 1 }, /* Shin 4 Nin Uchi Mahjong - Yakuman Tengoku */ + { 0x39f2ce4b, 2 }, /* Suikoden - Tenmei no Chikai */ + { 0xbb7f829a, 0 }, /* Uchuu Keibitai SDF */ + { 0xaca15643, 2 }, /* Uncharted Waters */ +}; + +#define MMC5_NOCARTS (sizeof(MMC5CartList) / sizeof(MMC5CartList[0])) +int DetectMMC5WRAMSize(uint32 crc32) { + int x; + for (x = 0; x < MMC5_NOCARTS; x++) { + if (crc32 == MMC5CartList[x].crc32) { + if(MMC5CartList[x].size > 1) + FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(MMC5CartList[x].size * 8); + } + } + return 64; +} + +static void BuildWRAMSizeTable(void) { + int x; + for (x = 0; x < 8; x++) { + switch (MMC5WRAMsize) { + case 0: MMC5WRAMIndex[x] = 255; break; //X,X,X,X,X,X,X,X + case 1: MMC5WRAMIndex[x] = (x > 3) ? 255 : 0; break; //0,0,0,0,X,X,X,X + case 2: MMC5WRAMIndex[x] = (x & 4) >> 2; break; //0,0,0,0,1,1,1,1 + case 4: MMC5WRAMIndex[x] = (x > 3) ? 255 : (x & 3); break; //0,1,2,3,X,X,X,X + case 8: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7 + } + } +} + +static void MMC5CHRA(void) { + int x; + switch (mmc5vsize & 3) { + case 0: + setchr8(CHRBanksA[7]); + MMC5SPRVROM_BANK8(CHRBanksA[7]); + break; + case 1: + setchr4(0x0000, CHRBanksA[3]); + setchr4(0x1000, CHRBanksA[7]); + MMC5SPRVROM_BANK4(0x0000, CHRBanksA[3]); + MMC5SPRVROM_BANK4(0x1000, CHRBanksA[7]); + break; + case 2: + setchr2(0x0000, CHRBanksA[1]); + setchr2(0x0800, CHRBanksA[3]); + setchr2(0x1000, CHRBanksA[5]); + setchr2(0x1800, CHRBanksA[7]); + MMC5SPRVROM_BANK2(0x0000, CHRBanksA[1]); + MMC5SPRVROM_BANK2(0x0800, CHRBanksA[3]); + MMC5SPRVROM_BANK2(0x1000, CHRBanksA[5]); + MMC5SPRVROM_BANK2(0x1800, CHRBanksA[7]); + break; + case 3: + for (x = 0; x < 8; x++) { + setchr1(x << 10, CHRBanksA[x]); + MMC5SPRVROM_BANK1(x << 10, CHRBanksA[x]); + } + break; + } +} + +static void MMC5CHRB(void) { + int x; + switch (mmc5vsize & 3) { + case 0: + setchr8(CHRBanksB[3]); + MMC5BGVROM_BANK8(CHRBanksB[3]); + break; + case 1: + setchr4(0x0000, CHRBanksB[3]); + setchr4(0x1000, CHRBanksB[3]); + MMC5BGVROM_BANK4(0x0000, CHRBanksB[3]); + MMC5BGVROM_BANK4(0x1000, CHRBanksB[3]); + break; + case 2: + setchr2(0x0000, CHRBanksB[1]); + setchr2(0x0800, CHRBanksB[3]); + setchr2(0x1000, CHRBanksB[1]); + setchr2(0x1800, CHRBanksB[3]); + MMC5BGVROM_BANK2(0x0000, CHRBanksB[1]); + MMC5BGVROM_BANK2(0x0800, CHRBanksB[3]); + MMC5BGVROM_BANK2(0x1000, CHRBanksB[1]); + MMC5BGVROM_BANK2(0x1800, CHRBanksB[3]); + break; + case 3: + for (x = 0; x < 8; x++) { + setchr1(x << 10, CHRBanksB[x & 3]); + MMC5BGVROM_BANK1(x << 10, CHRBanksB[x & 3]); + } + break; + } +} + +static void MMC5WRAM(uint32 A, uint32 V) { + V = MMC5WRAMIndex[V & 7]; + if (V != 255) { + setprg8r(0x10, A, V); + MMC5MemIn[(A - 0x6000) >> 13] = 1; + } else + MMC5MemIn[(A - 0x6000) >> 13] = 0; +} + +static void MMC5PRG(void) { + int x; + switch (mmc5psize & 3) { + case 0: + MMC5ROMWrProtect[0] = MMC5ROMWrProtect[1] = MMC5ROMWrProtect[2] = MMC5ROMWrProtect[3] = 1; + setprg32(0x8000, ((PRGBanks[1] & 0x7F) >> 2)); + for (x = 0; x < 4; x++) + MMC5MemIn[1 + x] = 1; + break; + case 1: + if (PRGBanks[1] & 0x80) { + MMC5ROMWrProtect[0] = MMC5ROMWrProtect[1] = 1; + setprg16(0x8000, (PRGBanks[1] >> 1)); + MMC5MemIn[1] = MMC5MemIn[2] = 1; + } else { + MMC5ROMWrProtect[0] = MMC5ROMWrProtect[1] = 0; + MMC5WRAM(0x8000, PRGBanks[1] & 7 & 0xFE); + MMC5WRAM(0xA000, (PRGBanks[1] & 7 & 0xFE) + 1); + } + MMC5MemIn[3] = MMC5MemIn[4] = 1; + MMC5ROMWrProtect[2] = MMC5ROMWrProtect[3] = 1; + setprg16(0xC000, (PRGBanks[3] & 0x7F) >> 1); + break; + case 2: + if (PRGBanks[1] & 0x80) { + MMC5MemIn[1] = MMC5MemIn[2] = 1; + MMC5ROMWrProtect[0] = MMC5ROMWrProtect[1] = 1; + setprg16(0x8000, (PRGBanks[1] & 0x7F) >> 1); + } else { + MMC5ROMWrProtect[0] = MMC5ROMWrProtect[1] = 0; + MMC5WRAM(0x8000, PRGBanks[1] & 7 & 0xFE); + MMC5WRAM(0xA000, (PRGBanks[1] & 7 & 0xFE) + 1); + } + if (PRGBanks[2] & 0x80) { + MMC5ROMWrProtect[2] = 1; + MMC5MemIn[3] = 1; + setprg8(0xC000, PRGBanks[2] & 0x7F); + } else { + MMC5ROMWrProtect[2] = 0; + MMC5WRAM(0xC000, PRGBanks[2] & 7); + } + MMC5MemIn[4] = 1; + MMC5ROMWrProtect[3] = 1; + setprg8(0xE000, PRGBanks[3] & 0x7F); + break; + case 3: + for (x = 0; x < 3; x++) + if (PRGBanks[x] & 0x80) { + MMC5ROMWrProtect[x] = 1; + setprg8(0x8000 + (x << 13), PRGBanks[x] & 0x7F); + MMC5MemIn[1 + x] = 1; + } else { + MMC5ROMWrProtect[x] = 0; + MMC5WRAM(0x8000 + (x << 13), PRGBanks[x] & 7); + } + MMC5MemIn[4] = 1; + MMC5ROMWrProtect[3] = 1; + setprg8(0xE000, PRGBanks[3] & 0x7F); + break; + } +} + +static DECLFW(Mapper5_write) { + switch (A) { + case 0x5100: + mmc5psize = V; + MMC5PRG(); + break; + case 0x5101: + mmc5vsize = V; + if (!mmc5ABMode) { + MMC5CHRB(); + MMC5CHRA(); + } else { + MMC5CHRA(); + MMC5CHRB(); + } + break; + case 0x5102: + WRAMMaskEnable[0] = V; + break; + case 0x5103: + WRAMMaskEnable[1] = V; + break; + case 0x5104: + CHRMode = V; + MMC5HackCHRMode = V & 3; + break; + case 0x5105: + { + int x; + for (x = 0; x < 4; x++) { + switch ((V >> (x << 1)) & 3) { + case 0: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM; break; + case 1: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM + 0x400; break; + case 2: PPUNTARAM |= 1 << x; vnapage[x] = ExRAM; break; + case 3: PPUNTARAM &= ~(1 << x); vnapage[x] = MMC5fill; break; + } + } + NTAMirroring = V; + break; + } + case 0x5106: + if (V != NTFill) + FCEU_dwmemset(MMC5fill, (V | (V << 8) | (V << 16) | (V << 24)), 0x3c0); + NTFill = V; + break; + case 0x5107: + if (V != ATFill) { + unsigned char moop = V | (V << 2) | (V << 4) | (V << 6); + FCEU_dwmemset(MMC5fill + 0x3c0, moop | (moop << 8) | (moop << 16) | (moop << 24), 0x40); + } + ATFill = V; + break; + case 0x5113: + WRAMPage = V; + MMC5WRAM(0x6000, V & 7); + break; + case 0x5114: + case 0x5115: + case 0x5116: + case 0x5117: + PRGBanks[A & 3] = V; + MMC5PRG(); + break; + case 0x5120: + case 0x5121: + case 0x5122: + case 0x5123: + case 0x5124: + case 0x5125: + case 0x5126: + case 0x5127: + mmc5ABMode = 0; + CHRBanksA[A & 7] = V | ((MMC50x5130 & 0x3) << 8); + MMC5CHRA(); + break; + case 0x5128: + case 0x5129: + case 0x512a: + case 0x512b: + mmc5ABMode = 1; + CHRBanksB[A & 3] = V | ((MMC50x5130 & 0x3) << 8); + MMC5CHRB(); + break; + case 0x5130: MMC50x5130 = V; break; + case 0x5200: MMC5HackSPMode = V; break; + case 0x5201: MMC5HackSPScroll = (V >> 3) & 0x1F; break; + case 0x5202: MMC5HackSPPage = V & 0x3F; break; + case 0x5203: X6502_IRQEnd(FCEU_IQEXT); IRQScanline = V; break; + case 0x5204: X6502_IRQEnd(FCEU_IQEXT); IRQEnable = V & 0x80; break; + case 0x5205: mul[0] = V; break; + case 0x5206: mul[1] = V; break; + } +} + +static DECLFR(MMC5_ReadROMRAM) { + if (MMC5MemIn[(A - 0x6000) >> 13]) + return Page[A >> 11][A]; + else + return X.DB; +} + +static DECLFW(MMC5_WriteROMRAM) { + if ((A >= 0x8000) && (MMC5ROMWrProtect[(A - 0x8000) >> 13])) + return; + if (MMC5MemIn[(A - 0x6000) >> 13]) + if (((WRAMMaskEnable[0] & 3) | ((WRAMMaskEnable[1] & 3) << 2)) == 6) + Page[A >> 11][A] = V; +} + +static DECLFW(MMC5_ExRAMWr) { + if (MMC5HackCHRMode != 3) + ExRAM[A & 0x3ff] = V; +} + +static DECLFR(MMC5_ExRAMRd) { + return ExRAM[A & 0x3ff]; +} + +static DECLFR(MMC5_read) { + switch (A) { + case 0x5204: { + uint8 x; + X6502_IRQEnd(FCEU_IQEXT); + x = MMC5IRQR; + #ifdef FCEUDEF_DEBUGGER + if (!fceuindbg) + #endif + MMC5IRQR &= 0x40; + return x; + } + case 0x5205: + return(mul[0] * mul[1]); + case 0x5206: + return((mul[0] * mul[1]) >> 8); + } + return(X.DB); +} + +void MMC5Synco(void) { + int x; + + MMC5PRG(); + for (x = 0; x < 4; x++) { + switch ((NTAMirroring >> (x << 1)) & 3) { + case 0: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM; break; + case 1: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM + 0x400; break; + case 2: PPUNTARAM |= 1 << x; vnapage[x] = ExRAM; break; + case 3: PPUNTARAM &= ~(1 << x); vnapage[x] = MMC5fill; break; + } + } + MMC5WRAM(0x6000, WRAMPage & 7); + if (!mmc5ABMode) { + MMC5CHRB(); + MMC5CHRA(); + } else { + MMC5CHRA(); + MMC5CHRB(); + } + + //in case the fill register changed, we need to overwrite the fill buffer + FCEU_dwmemset(MMC5fill, NTFill | (NTFill << 8) | (NTFill << 16) | (NTFill << 24), 0x3c0); + { + unsigned char moop = ATFill | (ATFill << 2) | (ATFill << 4) | (ATFill << 6); + FCEU_dwmemset(MMC5fill + 0x3c0, moop | (moop << 8) | (moop << 16) | (moop << 24), 0x40); + } + + MMC5HackCHRMode = CHRMode & 3; + + //zero 17-apr-2013 - why the heck should this happen here? anything in a `synco` should be depending on the state. + //im going to leave it commented out to see what happens + //X6502_IRQEnd(FCEU_IQEXT); +} + +void MMC5_hb(int scanline) { + if (scanline == 240) { + MMC5LineCounter = 0; + MMC5IRQR = 0x40; + return; + } + if (MMC5LineCounter < 240) { + if (MMC5LineCounter == IRQScanline) { + MMC5IRQR |= 0x80; + if (IRQEnable & 0x80) + X6502_IRQBegin(FCEU_IQEXT); + } + MMC5LineCounter++; + } + if (MMC5LineCounter == 240) + MMC5IRQR = 0; +} + +void MMC5_StateRestore(int version) { + MMC5Synco(); +} + +typedef struct { + uint16 wl[2]; + uint8 env[2]; + uint8 enable; + uint8 running; + uint8 raw; + uint8 rawcontrol; + int32 dcount[2]; + int32 BC[3]; + int32 vcount[2]; +} MMC5APU; + +static MMC5APU MMC5Sound; + + +static void Do5PCM() { + int32 V; + int32 start, end; + + start = MMC5Sound.BC[2]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + MMC5Sound.BC[2] = end; + + if (!(MMC5Sound.rawcontrol & 0x40) && MMC5Sound.raw) + for (V = start; V < end; V++) + Wave[V >> 4] += MMC5Sound.raw << 1; +} + +static void Do5PCMHQ() { + uint32 V; + if (!(MMC5Sound.rawcontrol & 0x40) && MMC5Sound.raw) + for (V = MMC5Sound.BC[2]; V < SOUNDTS; V++) + WaveHi[V] += MMC5Sound.raw << 5; + MMC5Sound.BC[2] = SOUNDTS; +} + + +static DECLFW(Mapper5_SW) { + A &= 0x1F; + + GameExpSound.Fill = MMC5RunSound; + GameExpSound.HiFill = MMC5RunSoundHQ; + + switch (A) { + case 0x10: if (psfun) psfun(); MMC5Sound.rawcontrol = V; break; + case 0x11: if (psfun) psfun(); MMC5Sound.raw = V; break; + + case 0x0: + case 0x4: + if (sfun) sfun(A >> 2); + MMC5Sound.env[A >> 2] = V; + break; + case 0x2: + case 0x6: + if (sfun) sfun(A >> 2); + MMC5Sound.wl[A >> 2] &= ~0x00FF; + MMC5Sound.wl[A >> 2] |= V & 0xFF; + break; + case 0x3: + case 0x7: + MMC5Sound.wl[A >> 2] &= ~0x0700; + MMC5Sound.wl[A >> 2] |= (V & 0x07) << 8; + MMC5Sound.running |= 1 << (A >> 2); + break; + case 0x15: + if (sfun) { + sfun(0); + sfun(1); + } + MMC5Sound.running &= V; + MMC5Sound.enable = V; + break; + } +} + +static void Do5SQ(int P) { + static int tal[4] = { 1, 2, 4, 6 }; + int32 V, amp, rthresh, wl; + int32 start, end; + + start = MMC5Sound.BC[P]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + MMC5Sound.BC[P] = end; + + wl = MMC5Sound.wl[P] + 1; + amp = (MMC5Sound.env[P] & 0xF) << 4; + rthresh = tal[(MMC5Sound.env[P] & 0xC0) >> 6]; + + if (wl >= 8 && (MMC5Sound.running & (P + 1))) { + int dc, vc; + + wl <<= 18; + dc = MMC5Sound.dcount[P]; + vc = MMC5Sound.vcount[P]; + + for (V = start; V < end; V++) { + if (dc < rthresh) + Wave[V >> 4] += amp; + vc -= nesincsize; + while (vc <= 0) { + vc += wl; + dc = (dc + 1) & 7; + } + } + MMC5Sound.dcount[P] = dc; + MMC5Sound.vcount[P] = vc; + } +} + +static void Do5SQHQ(int P) { + static int tal[4] = { 1, 2, 4, 6 }; + uint32 V; + int32 amp, rthresh, wl; + + wl = MMC5Sound.wl[P] + 1; + amp = ((MMC5Sound.env[P] & 0xF) << 8); + rthresh = tal[(MMC5Sound.env[P] & 0xC0) >> 6]; + + if (wl >= 8 && (MMC5Sound.running & (P + 1))) { + int dc, vc; + + wl <<= 1; + + dc = MMC5Sound.dcount[P]; + vc = MMC5Sound.vcount[P]; + for (V = MMC5Sound.BC[P]; V < SOUNDTS; V++) { + if (dc < rthresh) + WaveHi[V] += amp; + vc--; + if (vc <= 0) { /* Less than zero when first started. */ + vc = wl; + dc = (dc + 1) & 7; + } + } + MMC5Sound.dcount[P] = dc; + MMC5Sound.vcount[P] = vc; + } + MMC5Sound.BC[P] = SOUNDTS; +} + +void MMC5RunSoundHQ(void) { + Do5SQHQ(0); + Do5SQHQ(1); + Do5PCMHQ(); +} + +void MMC5HiSync(int32 ts) { + int x; + for (x = 0; x < 3; x++) + MMC5Sound.BC[x] = ts; +} + +void MMC5RunSound(int Count) { + int x; + Do5SQ(0); + Do5SQ(1); + Do5PCM(); + for (x = 0; x < 3; x++) + MMC5Sound.BC[x] = Count; +} + +void Mapper5_ESI(void) { + GameExpSound.RChange = Mapper5_ESI; + if (FSettings.SndRate) { + if (FSettings.soundq >= 1) { + sfun = Do5SQHQ; + psfun = Do5PCMHQ; + } else { + sfun = Do5SQ; + psfun = Do5PCM; + } + } else { + sfun = 0; + psfun = 0; + } + memset(MMC5Sound.BC, 0, sizeof(MMC5Sound.BC)); + memset(MMC5Sound.vcount, 0, sizeof(MMC5Sound.vcount)); + GameExpSound.HiSync = MMC5HiSync; +} + +void NSFMMC5_Init(void) { + memset(&MMC5Sound, 0, sizeof(MMC5Sound)); + mul[0] = mul[1] = 0; + ExRAM = (uint8*)FCEU_gmalloc(1024); + Mapper5_ESI(); + SetWriteHandler(0x5c00, 0x5fef, MMC5_ExRAMWr); + SetReadHandler(0x5c00, 0x5fef, MMC5_ExRAMRd); + MMC5HackCHRMode = 2; + SetWriteHandler(0x5000, 0x5015, Mapper5_SW); + SetWriteHandler(0x5205, 0x5206, Mapper5_write); + SetReadHandler(0x5205, 0x5206, MMC5_read); +} + +void NSFMMC5_Close(void) { + FCEU_gfree(ExRAM); + ExRAM = 0; +} + +static void GenMMC5Reset(void) { + int x; + + for (x = 0; x < 4; x++) PRGBanks[x] = ~0; + for (x = 0; x < 8; x++) CHRBanksA[x] = ~0; + for (x = 0; x < 4; x++) CHRBanksB[x] = ~0; + WRAMMaskEnable[0] = WRAMMaskEnable[1] = ~0; + + mmc5psize = mmc5vsize = 3; + CHRMode = 0; + + NTAMirroring = NTFill = ATFill = 0xFF; + + MMC5Synco(); + + SetWriteHandler(0x4020, 0x5bff, Mapper5_write); + SetReadHandler(0x4020, 0x5bff, MMC5_read); + + SetWriteHandler(0x5c00, 0x5fff, MMC5_ExRAMWr); + SetReadHandler(0x5c00, 0x5fff, MMC5_ExRAMRd); + + SetWriteHandler(0x6000, 0xFFFF, MMC5_WriteROMRAM); + SetReadHandler(0x6000, 0xFFFF, MMC5_ReadROMRAM); + + SetWriteHandler(0x5000, 0x5015, Mapper5_SW); + SetWriteHandler(0x5205, 0x5206, Mapper5_write); + SetReadHandler(0x5205, 0x5206, MMC5_read); + +// GameHBIRQHook=MMC5_hb; + FCEU_CheatAddRAM(8, 0x6000, WRAM); + FCEU_CheatAddRAM(1, 0x5c00, ExRAM); +} + +static SFORMAT MMC5_StateRegs[] = { + { PRGBanks, 4, "PRGB" }, + { CHRBanksA, 16, "CHRA" }, + { CHRBanksB, 8, "CHRB" }, + { &WRAMPage, 1, "WRMP" }, + { WRAMMaskEnable, 2, "WRME" }, + { &mmc5ABMode, 1, "ABMD" }, + { &IRQScanline, 1, "IRQS" }, + { &IRQEnable, 1, "IRQE" }, + { &CHRMode, 1, "CHRM" }, + { &NTAMirroring, 1, "NTAM" }, + { &NTFill, 1, "NTFL" }, + { &ATFill, 1, "ATFL" }, + + //zero 17-apr-2013 - added + { &MMC5IRQR, 1, "IRQR" }, + { &MMC5LineCounter, 1, "LCTR" }, + { &mmc5psize, 1, "PSIZ" }, + { &mmc5vsize, 1, "VSIZ" }, + { mul, 2, "MUL2" }, + { MMC5ROMWrProtect, 4, "WRPR" }, + { MMC5MemIn, 5, "MEMI" }, + + { &MMC5Sound.wl[0], 2 | FCEUSTATE_RLSB, "SDW0" }, + { &MMC5Sound.wl[1], 2 | FCEUSTATE_RLSB, "SDW1" }, + { MMC5Sound.env, 2, "SDEV" }, + { &MMC5Sound.enable, 1, "SDEN" }, + { &MMC5Sound.running, 1, "SDRU" }, + { &MMC5Sound.raw, 1, "SDRW" }, + { &MMC5Sound.rawcontrol, 1, "SDRC" }, + + //zero 17-apr-2013 - added + { &MMC5Sound.dcount[0], 4 | FCEUSTATE_RLSB, "DCT0" }, + { &MMC5Sound.dcount[1], 4 | FCEUSTATE_RLSB, "DCT1" }, + { &MMC5Sound.BC[0], 4 | FCEUSTATE_RLSB, "BC00" }, + { &MMC5Sound.BC[1], 4 | FCEUSTATE_RLSB, "BC01" }, + { &MMC5Sound.BC[2], 4 | FCEUSTATE_RLSB, "BC02" }, + { &MMC5Sound.vcount[0], 4 | FCEUSTATE_RLSB, "VCT0" }, + { &MMC5Sound.vcount[1], 4 | FCEUSTATE_RLSB, "VCT1" }, + { 0 } +}; + +static void GenMMC5_Init(CartInfo *info, int wsize, int battery) { + if (wsize) { + WRAM = (uint8*)FCEU_gmalloc(wsize * 1024); + SetupCartPRGMapping(0x10, WRAM, wsize * 1024, 1); + AddExState(WRAM, wsize * 1024, 0, "WRAM"); + } + + MMC5fill = (uint8*)FCEU_gmalloc(1024); + ExRAM = (uint8*)FCEU_gmalloc(1024); + + AddExState(ExRAM, 1024, 0, "ERAM"); + AddExState(&MMC5HackSPMode, 1, 0, "SPLM"); + AddExState(&MMC5HackSPScroll, 1, 0, "SPLS"); + AddExState(&MMC5HackSPPage, 1, 0, "SPLP"); + AddExState(&MMC50x5130, 1, 0, "5130"); + AddExState(MMC5_StateRegs, ~0, 0, 0); + + MMC5WRAMsize = wsize / 8; + BuildWRAMSizeTable(); + GameStateRestore = MMC5_StateRestore; + info->Power = GenMMC5Reset; + + if (battery) { + info->SaveGame[0] = WRAM; + if (wsize <= 16) + info->SaveGameLen[0] = 8192; + else + info->SaveGameLen[0] = 32768; + } + + MMC5HackVROMMask = CHRmask4[0]; + MMC5HackExNTARAMPtr = ExRAM; + MMC5Hack = 1; + MMC5HackVROMPTR = CHRptr[0]; + MMC5HackCHRMode = 0; + MMC5HackSPMode = MMC5HackSPScroll = MMC5HackSPPage = 0; + Mapper5_ESI(); + + FFCEUX_PPURead = mmc5_PPURead; + FFCEUX_PPUWrite = mmc5_PPUWrite; +} + +void Mapper5_Init(CartInfo *info) { + GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery); +} + +// ELROM seems to have 0KB of WRAM +// EKROM seems to have 8KB of WRAM, battery-backed +// ETROM seems to have 16KB of WRAM, battery-backed +// EWROM seems to have 32KB of WRAM, battery-backed + +void ELROM_Init(CartInfo *info) { + GenMMC5_Init(info, 0, 0); +} + +void EKROM_Init(CartInfo *info) { + GenMMC5_Init(info, 8, info->battery); +} + +void ETROM_Init(CartInfo *info) { + GenMMC5_Init(info, 16, info->battery); +} + +void EWROM_Init(CartInfo *info) { + GenMMC5_Init(info, 32, info->battery); +} diff --git a/branches/fceux-2.2.2/src/boards/n106.cpp b/branches/fceux-2.2.2/src/boards/n106.cpp new file mode 100644 index 00000000..71e189bf --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/n106.cpp @@ -0,0 +1,427 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint16 IRQCount; +static uint8 IRQa; + +static uint8 WRAM[8192]; +static uint8 IRAM[128]; + +static DECLFR(AWRAM) { + return(WRAM[A - 0x6000]); +} + +static DECLFW(BWRAM) { + WRAM[A - 0x6000] = V; +} + +void Mapper19_ESI(void); + +static uint8 NTAPage[4]; + +static uint8 dopol; +static uint8 gorfus; +static uint8 gorko; + +static void NamcoSound(int Count); +static void NamcoSoundHack(void); +static void DoNamcoSound(int32 *Wave, int Count); +static void DoNamcoSoundHQ(void); +static void SyncHQ(int32 ts); + +static int is210; /* Lesser mapper. */ + +static uint8 PRG[3]; +static uint8 CHR[8]; + +static SFORMAT N106_StateRegs[] = { + { PRG, 3, "PRG" }, + { CHR, 8, "CHR" }, + { NTAPage, 4, "NTA" }, + { 0 } +}; + +static void SyncPRG(void) { + setprg8(0x8000, PRG[0]); + setprg8(0xa000, PRG[1]); + setprg8(0xc000, PRG[2]); + setprg8(0xe000, 0x3F); +} + +static void NamcoIRQHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount >= 0x7FFF) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0x7FFF; //7FFF; + } + } +} + +static DECLFR(Namco_Read4800) { + uint8 ret = IRAM[dopol & 0x7f]; + /* Maybe I should call NamcoSoundHack() here? */ + #ifdef FCEUDEF_DEBUGGER + if (!fceuindbg) + #endif + if (dopol & 0x80) + dopol = (dopol & 0x80) | ((dopol + 1) & 0x7f); + return ret; +} + +static DECLFR(Namco_Read5000) { + return(IRQCount); +} + +static DECLFR(Namco_Read5800) { + return(IRQCount >> 8); +} + +static void DoNTARAMROM(int w, uint8 V) { + NTAPage[w] = V; + if (V >= 0xE0) + setntamem(NTARAM + ((V & 1) << 10), 1, w); + else{ + V &= CHRmask1[0]; + setntamem(CHRptr[0] + (V << 10), 0, w); + } +} + +static void FixNTAR(void) { + int x; + for (x = 0; x < 4; x++) + DoNTARAMROM(x, NTAPage[x]); +} + +static void DoCHRRAMROM(int x, uint8 V) { + CHR[x] = V; + if (!is210 && !((gorfus >> ((x >> 2) + 6)) & 1) && (V >= 0xE0)) { +// printf("BLAHAHA: %d, %02x\n",x,V); +// setchr1r(0x10,x<<10,V&7); + } else + setchr1(x << 10, V); +} + +static void FixCRR(void) { + int x; + for (x = 0; x < 8; x++) + DoCHRRAMROM(x, CHR[x]); +} + +static DECLFW(Mapper19C0D8_write) { + DoNTARAMROM((A - 0xC000) >> 11, V); +} + +static uint32 FreqCache[8]; +static uint32 EnvCache[8]; +static uint32 LengthCache[8]; + +static void FixCache(int a, int V) { + int w = (a >> 3) & 0x7; + switch (a & 0x07) { + case 0x00: FreqCache[w] &= ~0x000000FF; FreqCache[w] |= V; break; + case 0x02: FreqCache[w] &= ~0x0000FF00; FreqCache[w] |= V << 8; break; + case 0x04: + FreqCache[w] &= ~0x00030000; FreqCache[w] |= (V & 3) << 16; + LengthCache[w] = (8 - ((V >> 2) & 7)) << 2; + break; + case 0x07: EnvCache[w] = (double)(V & 0xF) * 576716; break; + } +} + +static DECLFW(Mapper19_write) { + A &= 0xF800; + if (A >= 0x8000 && A <= 0xb800) + DoCHRRAMROM((A - 0x8000) >> 11, V); + else + switch (A) { + case 0x4800: + if (dopol & 0x40) { + if (FSettings.SndRate) { + NamcoSoundHack(); + GameExpSound.Fill = NamcoSound; + GameExpSound.HiFill = DoNamcoSoundHQ; + GameExpSound.HiSync = SyncHQ; + } + FixCache(dopol, V); + } + IRAM[dopol & 0x7f] = V; + if (dopol & 0x80) + dopol = (dopol & 0x80) | ((dopol + 1) & 0x7f); + break; + case 0xf800: + dopol = V; break; + case 0x5000: + IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x5800: + IRQCount &= 0x00ff; IRQCount |= (V & 0x7F) << 8; + IRQa = V & 0x80; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xE000: + gorko = V & 0xC0; + PRG[0] = V & 0x3F; + SyncPRG(); + break; + case 0xE800: + gorfus = V & 0xC0; + FixCRR(); + PRG[1] = V & 0x3F; + SyncPRG(); + break; + case 0xF000: + PRG[2] = V & 0x3F; + SyncPRG(); + break; + } +} + +static int dwave = 0; + +static void NamcoSoundHack(void) { + int32 z, a; + if (FSettings.soundq >= 1) { + DoNamcoSoundHQ(); + return; + } + z = ((SOUNDTS << 16) / soundtsinc) >> 4; + a = z - dwave; + if (a) DoNamcoSound(&Wave[dwave], a); + dwave += a; +} + +static void NamcoSound(int Count) { + int32 z, a; + z = ((SOUNDTS << 16) / soundtsinc) >> 4; + a = z - dwave; + if (a) DoNamcoSound(&Wave[dwave], a); + dwave = 0; +} + +static uint32 PlayIndex[8]; +static int32 vcount[8]; +static int32 CVBC; + +#define TOINDEX (16 + 1) + +// 16:15 +static void SyncHQ(int32 ts) { + CVBC = ts; +} + + +/* Things to do: + 1 Read freq low + 2 Read freq mid + 3 Read freq high + 4 Read envelope + ...? +*/ + +static INLINE uint32 FetchDuff(uint32 P, uint32 envelope) { + uint32 duff; + duff = IRAM[((IRAM[0x46 + (P << 3)] + (PlayIndex[P] >> TOINDEX)) & 0xFF) >> 1]; + if ((IRAM[0x46 + (P << 3)] + (PlayIndex[P] >> TOINDEX)) & 1) + duff >>= 4; + duff &= 0xF; + duff = (duff * envelope) >> 16; + return(duff); +} + +static void DoNamcoSoundHQ(void) { + int32 P, V; + int32 cyclesuck = (((IRAM[0x7F] >> 4) & 7) + 1) * 15; + + for (P = 7; P >= (7 - ((IRAM[0x7F] >> 4) & 7)); P--) { + if ((IRAM[0x44 + (P << 3)] & 0xE0) && (IRAM[0x47 + (P << 3)] & 0xF)) { + uint32 freq; + int32 vco; + uint32 duff2, lengo, envelope; + + vco = vcount[P]; + freq = FreqCache[P]; + envelope = EnvCache[P]; + lengo = LengthCache[P]; + + duff2 = FetchDuff(P, envelope); + for (V = CVBC << 1; V < (int)SOUNDTS << 1; V++) { + WaveHi[V >> 1] += duff2; + if (!vco) { + PlayIndex[P] += freq; + while ((PlayIndex[P] >> TOINDEX) >= lengo) PlayIndex[P] -= lengo << TOINDEX; + duff2 = FetchDuff(P, envelope); + vco = cyclesuck; + } + vco--; + } + vcount[P] = vco; + } + } + CVBC = SOUNDTS; +} + + +static void DoNamcoSound(int32 *Wave, int Count) { + int P, V; + for (P = 7; P >= 7 - ((IRAM[0x7F] >> 4) & 7); P--) { + if ((IRAM[0x44 + (P << 3)] & 0xE0) && (IRAM[0x47 + (P << 3)] & 0xF)) { + int32 inc; + uint32 freq; + int32 vco; + uint32 duff, duff2, lengo, envelope; + + vco = vcount[P]; + freq = FreqCache[P]; + envelope = EnvCache[P]; + lengo = LengthCache[P]; + + if (!freq) { /*printf("Ack");*/ + continue; + } + + { + int c = ((IRAM[0x7F] >> 4) & 7) + 1; + inc = (long double)(FSettings.SndRate << 15) / ((long double)freq * 21477272 / ((long double)0x400000 * c * 45)); + } + + duff = IRAM[(((IRAM[0x46 + (P << 3)] + PlayIndex[P]) & 0xFF) >> 1)]; + if ((IRAM[0x46 + (P << 3)] + PlayIndex[P]) & 1) + duff >>= 4; + duff &= 0xF; + duff2 = (duff * envelope) >> 19; + for (V = 0; V < Count * 16; V++) { + if (vco >= inc) { + PlayIndex[P]++; + if (PlayIndex[P] >= lengo) + PlayIndex[P] = 0; + vco -= inc; + duff = IRAM[(((IRAM[0x46 + (P << 3)] + PlayIndex[P]) & 0xFF) >> 1)]; + if ((IRAM[0x46 + (P << 3)] + PlayIndex[P]) & 1) + duff >>= 4; + duff &= 0xF; + duff2 = (duff * envelope) >> 19; + } + Wave[V >> 4] += duff2; + vco += 0x8000; + } + vcount[P] = vco; + } + } +} + +static void Mapper19_StateRestore(int version) { + SyncPRG(); + FixNTAR(); + FixCRR(); + int x; + for (x = 0x40; x < 0x80; x++) + FixCache(x, IRAM[x]); +} + +static void M19SC(void) { + if (FSettings.SndRate) + Mapper19_ESI(); +} + +void Mapper19_ESI(void) { + GameExpSound.RChange = M19SC; + memset(vcount, 0, sizeof(vcount)); + memset(PlayIndex, 0, sizeof(PlayIndex)); + CVBC = 0; +} + +void NSFN106_Init(void) { + SetWriteHandler(0xf800, 0xffff, Mapper19_write); + SetWriteHandler(0x4800, 0x4fff, Mapper19_write); + SetReadHandler(0x4800, 0x4fff, Namco_Read4800); + Mapper19_ESI(); +} + +static int battery = 0; + +static void N106_Power(void) { + int x; + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xffff, Mapper19_write); + SetWriteHandler(0x4020, 0x5fff, Mapper19_write); + if (!is210) { + SetWriteHandler(0xc000, 0xdfff, Mapper19C0D8_write); + SetReadHandler(0x4800, 0x4fff, Namco_Read4800); + SetReadHandler(0x5000, 0x57ff, Namco_Read5000); + SetReadHandler(0x5800, 0x5fff, Namco_Read5800); + NTAPage[0] = NTAPage[1] = NTAPage[2] = NTAPage[3] = 0xFF; + FixNTAR(); + } + + SetReadHandler(0x6000, 0x7FFF, AWRAM); + SetWriteHandler(0x6000, 0x7FFF, BWRAM); + FCEU_CheatAddRAM(8, 0x6000, WRAM); + + gorfus = 0xFF; + SyncPRG(); + FixCRR(); + + if (!battery) { + FCEU_dwmemset(WRAM, 0, 8192); + FCEU_dwmemset(IRAM, 0, 128); + } + for (x = 0x40; x < 0x80; x++) + FixCache(x, IRAM[x]); +} + +void Mapper19_Init(CartInfo *info) { + is210 = 0; + battery = info->battery; + info->Power = N106_Power; + + MapIRQHook = NamcoIRQHook; + GameStateRestore = Mapper19_StateRestore; + GameExpSound.RChange = M19SC; + + if (FSettings.SndRate) + Mapper19_ESI(); + + AddExState(WRAM, 8192, 0, "WRAM"); + AddExState(IRAM, 128, 0, "IRAM"); + AddExState(N106_StateRegs, ~0, 0, 0); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = 8192; + info->SaveGame[1] = IRAM; + info->SaveGameLen[1] = 128; + } +} + +static void Mapper210_StateRestore(int version) { + SyncPRG(); + FixCRR(); +} + +void Mapper210_Init(CartInfo *info) { + is210 = 1; + GameStateRestore = Mapper210_StateRestore; + info->Power = N106_Power; + AddExState(WRAM, 8192, 0, "WRAM"); + AddExState(N106_StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/n625092.cpp b/branches/fceux-2.2.2/src/boards/n625092.cpp new file mode 100644 index 00000000..058cd3d8 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/n625092.cpp @@ -0,0 +1,95 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 + * + * 700in1 and 400in1 carts + * + */ + + +#include "mapinc.h" + +static uint16 cmd, bank; + +static SFORMAT StateRegs[] = +{ + { &cmd, 2, "CMD" }, + { &bank, 2, "BANK" }, + { 0 } +}; + +static void Sync(void) { + setmirror((cmd & 1) ^ 1); + setchr8(0); + if (cmd & 2) { + if (cmd & 0x100) { + setprg16(0x8000, ((cmd & 0xfc) >> 2) | bank); + setprg16(0xC000, ((cmd & 0xfc) >> 2) | 7); + } else { + setprg16(0x8000, ((cmd & 0xfc) >> 2) | (bank & 6)); + setprg16(0xC000, ((cmd & 0xfc) >> 2) | ((bank & 6) | 1)); + } + } else { + setprg16(0x8000, ((cmd & 0xfc) >> 2) | bank); + setprg16(0xC000, ((cmd & 0xfc) >> 2) | bank); + } +} + +static uint16 ass = 0; + +static DECLFW(UNLN625092WriteCommand) { + cmd = A; + if (A == 0x80F8) { + setprg16(0x8000, ass); + setprg16(0xC000, ass); + } else { + Sync(); + } +} + +static DECLFW(UNLN625092WriteBank) { + bank = A & 7; + Sync(); +} + +static void UNLN625092Power(void) { + cmd = 0; + bank = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, UNLN625092WriteCommand); + SetWriteHandler(0xC000, 0xFFFF, UNLN625092WriteBank); +} + +static void UNLN625092Reset(void) { + cmd = 0; + bank = 0; + ass++; + FCEU_printf("%04x\n", ass); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLN625092_Init(CartInfo *info) { + info->Reset = UNLN625092Reset; + info->Power = UNLN625092Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/novel.cpp b/branches/fceux-2.2.2/src/boards/novel.cpp new file mode 100644 index 00000000..c6dca068 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/novel.cpp @@ -0,0 +1,50 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 latch; + +static void DoNovel(void) { + setprg32(0x8000, latch & 3); + setchr8(latch & 7); +} + +static DECLFW(NovelWrite) { + latch = A & 0xFF; + DoNovel(); +} + +static void NovelReset(void) { + SetWriteHandler(0x8000, 0xFFFF, NovelWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + setprg32(0x8000, 0); + setchr8(0); +} + +static void NovelRestore(int version) { + DoNovel(); +} + +void Novel_Init(CartInfo *info) { + AddExState(&latch, 1, 0, "L1"); + info->Power = NovelReset; + GameStateRestore = NovelRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/onebus.cpp b/branches/fceux-2.2.2/src/boards/onebus.cpp new file mode 100644 index 00000000..96ce0265 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/onebus.cpp @@ -0,0 +1,292 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007-2010 CaH4e3 + * + * 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 + * + * VR02/VT03 Console and OneBus System + * + * Street Dance (Dance pad) (Unl) + * 101-in-1 Arcade Action II + * DreamGEAR 75-in-1, etc. + * + */ + +#include "mapinc.h" + +// General Purpose Registers +static uint8 cpu410x[16], ppu201x[16], apu40xx[64]; + +// IRQ Registers +static uint8 IRQCount, IRQa, IRQReload; +#define IRQLatch cpu410x[0x1] + +// MMC3 Registers +static uint8 inv_hack = 0; // some OneBus Systems have swapped PRG reg commans in MMC3 inplementation, + // trying to autodetect unusual behavior, due not to add a new mapper. +#define mmc3cmd cpu410x[0x5] +#define mirror cpu410x[0x6] + +// APU Registers +static uint8 pcm_enable = 0, pcm_irq = 0; +static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xF6; + +static writefunc defapuwrite[64]; +static readfunc defapuread[64]; + +static SFORMAT StateRegs[] = +{ + { cpu410x, 16, "REGC" }, + { ppu201x, 16, "REGS" }, + { apu40xx, 64, "REGA" }, + { &IRQReload, 1, "IRQR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { &pcm_enable, 1, "PCME" }, + { &pcm_irq, 1, "PCMI" }, + { &pcm_addr, 2, "PCMA" }, + { &pcm_size, 2, "PCMS" }, + { &pcm_latch, 2, "PCML" }, + { &pcm_clock, 2, "PCMC" }, + { 0 } +}; + +static void PSync(void) { + uint8 bankmode = cpu410x[0xb] & 7; + uint8 mask = (bankmode == 0x7) ? (0xff) : (0x3f >> bankmode); + uint32 block = ((cpu410x[0x0] & 0xf0) << 4) + (cpu410x[0xa] & (~mask)); + uint32 pswap = (mmc3cmd & 0x40) << 8; + +// uint8 bank0 = (cpu410x[0xb] & 0x40)?(~1):(cpu410x[0x7]); +// uint8 bank1 = cpu410x[0x8]; +// uint8 bank2 = (cpu410x[0xb] & 0x40)?(cpu410x[0x9]):(~1); +// uint8 bank3 = ~0; + uint8 bank0 = cpu410x[0x7 ^ inv_hack]; + uint8 bank1 = cpu410x[0x8 ^ inv_hack]; + uint8 bank2 = (cpu410x[0xb] & 0x40) ? (cpu410x[0x9]) : (~1); + uint8 bank3 = ~0; + +// FCEU_printf(" PRG: %04x [%02x]",0x8000^pswap,block | (bank0 & mask)); + setprg8(0x8000 ^ pswap, block | (bank0 & mask)); +// FCEU_printf(" %04x [%02x]",0xa000^pswap,block | (bank1 & mask)); + setprg8(0xa000, block | (bank1 & mask)); +// FCEU_printf(" %04x [%02x]",0xc000^pswap,block | (bank2 & mask)); + setprg8(0xc000 ^ pswap, block | (bank2 & mask)); +// FCEU_printf(" %04x [%02x]\n",0xe000^pswap,block | (bank3 & mask)); + setprg8(0xe000, block | (bank3 & mask)); +} + +static void CSync(void) { + static const uint8 midx[8] = { 0, 1, 2, 0, 3, 4, 5, 0 }; + uint8 mask = 0xff >> midx[ppu201x[0xa] & 7]; + uint32 block = ((cpu410x[0x0] & 0x0f) << 11) + ((ppu201x[0x8] & 0x70) << 4) + (ppu201x[0xa] & (~mask)); + uint32 cswap = (mmc3cmd & 0x80) << 5; + + uint8 bank0 = ppu201x[0x6] & (~1); + uint8 bank1 = ppu201x[0x6] | 1; + uint8 bank2 = ppu201x[0x7] & (~1); + uint8 bank3 = ppu201x[0x7] | 1; + uint8 bank4 = ppu201x[0x2]; + uint8 bank5 = ppu201x[0x3]; + uint8 bank6 = ppu201x[0x4]; + uint8 bank7 = ppu201x[0x5]; + + setchr1(0x0000 ^ cswap, block | (bank0 & mask)); + setchr1(0x0400 ^ cswap, block | (bank1 & mask)); + setchr1(0x0800 ^ cswap, block | (bank2 & mask)); + setchr1(0x0c00 ^ cswap, block | (bank3 & mask)); + setchr1(0x1000 ^ cswap, block | (bank4 & mask)); + setchr1(0x1400 ^ cswap, block | (bank5 & mask)); + setchr1(0x1800 ^ cswap, block | (bank6 & mask)); + setchr1(0x1c00 ^ cswap, block | (bank7 & mask)); + + setmirror((mirror & 1) ^ 1); +} + +static void Sync(void) { + PSync(); + CSync(); +} + +static DECLFW(UNLOneBusWriteCPU410X) { +// FCEU_printf("CPU %04x:%04x\n",A,V); + switch (A & 0xf) { + case 0x1: IRQLatch = V & 0xfe; break; + case 0x2: IRQReload = 1; break; + case 0x3: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0x4: IRQa = 1; break; + default: + cpu410x[A & 0xf] = V; + Sync(); + } +} + +static DECLFW(UNLOneBusWritePPU201X) { +// FCEU_printf("PPU %04x:%04x\n",A,V); + ppu201x[A & 0x0f] = V; + Sync(); +} + +static DECLFW(UNLOneBusWriteMMC3) { +// FCEU_printf("MMC %04x:%04x\n",A,V); + switch (A & 0xe001) { + case 0x8000: mmc3cmd = (mmc3cmd & 0x38) | (V & 0xc7); Sync(); break; + case 0x8001: + { + switch (mmc3cmd & 7) { + case 0: ppu201x[0x6] = V; CSync(); break; + case 1: ppu201x[0x7] = V; CSync(); break; + case 2: ppu201x[0x2] = V; CSync(); break; + case 3: ppu201x[0x3] = V; CSync(); break; + case 4: ppu201x[0x4] = V; CSync(); break; + case 5: ppu201x[0x5] = V; CSync(); break; + case 6: cpu410x[0x7] = V; PSync(); break; + case 7: cpu410x[0x8] = V; PSync(); break; + } + break; + } + case 0xa000: mirror = V; CSync(); break; + case 0xc000: IRQLatch = V & 0xfe; break; + case 0xc001: IRQReload = 1; break; + case 0xe000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0xe001: IRQa = 1; break; + } +} + +static void UNLOneBusIRQHook(void) { + uint32 count = IRQCount; + if (!count || IRQReload) { + IRQCount = IRQLatch; + IRQReload = 0; + } else + IRQCount--; + if (count && !IRQCount) { + if (IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static DECLFW(UNLOneBusWriteAPU40XX) { +// FCEU_printf("APU %04x:%04x\n",A,V); + apu40xx[A & 0x3f] = V; + switch (A & 0x3f) { + case 0x12: + if (apu40xx[0x30] & 0x10) { + pcm_addr = V << 6; + } + case 0x13: + if (apu40xx[0x30] & 0x10) { + pcm_size = (V << 4) + 1; + } + case 0x15: + if (apu40xx[0x30] & 0x10) { + pcm_enable = V & 0x10; + if (pcm_irq) { + X6502_IRQEnd(FCEU_IQEXT); + pcm_irq = 0; + } + if (pcm_enable) + pcm_latch = pcm_clock; + V &= 0xef; + } + } + defapuwrite[A & 0x3f](A, V); +} + +static DECLFR(UNLOneBusReadAPU40XX) { + uint8 result = defapuread[A & 0x3f](A); +// FCEU_printf("read %04x, %02x\n",A,result); + switch (A & 0x3f) { + case 0x15: + if (apu40xx[0x30] & 0x10) { + result = (result & 0x7f) | pcm_irq; + } + } + return result; +} + +static void UNLOneBusCpuHook(int a) { + if (pcm_enable) { + pcm_latch -= a; + if (pcm_latch <= 0) { + pcm_latch += pcm_clock; + pcm_size--; + if (pcm_size < 0) { + pcm_irq = 0x80; + pcm_enable = 0; + X6502_IRQBegin(FCEU_IQEXT); + } else { + uint8 raw_pcm = ARead[pcm_addr](pcm_addr) >> 1; + defapuwrite[0x11](0x4011, raw_pcm); + pcm_addr++; + pcm_addr &= 0x7FFF; + } + } + } +} + +static void UNLOneBusPower(void) { + uint32 i; + IRQReload = IRQCount = IRQa = 0; + + memset(cpu410x, 0x00, sizeof(cpu410x)); + memset(ppu201x, 0x00, sizeof(ppu201x)); + memset(apu40xx, 0x00, sizeof(apu40xx)); + + SetupCartCHRMapping(0, PRGptr[0], PRGsize[0], 0); + + for (i = 0; i < 64; i++) { + defapuread[i] = GetReadHandler(0x4000 | i); + defapuwrite[i] = GetWriteHandler(0x4000 | i); + } + SetReadHandler(0x4000, 0x403f, UNLOneBusReadAPU40XX); + SetWriteHandler(0x4000, 0x403f, UNLOneBusWriteAPU40XX); + + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x2010, 0x201f, UNLOneBusWritePPU201X); + SetWriteHandler(0x4100, 0x410f, UNLOneBusWriteCPU410X); + SetWriteHandler(0x8000, 0xffff, UNLOneBusWriteMMC3); + + Sync(); +} + +static void UNLOneBusReset(void) { + IRQReload = IRQCount = IRQa = 0; + + memset(cpu410x, 0x00, sizeof(cpu410x)); + memset(ppu201x, 0x00, sizeof(ppu201x)); + memset(apu40xx, 0x00, sizeof(apu40xx)); + + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLOneBus_Init(CartInfo *info) { + info->Power = UNLOneBusPower; + info->Reset = UNLOneBusReset; + + if (((*(uint32*)&(info->MD5)) == 0x305fcdc3) || // PowerJoy Supermax Carts + ((*(uint32*)&(info->MD5)) == 0x6abfce8e)) + inv_hack = 0xf; + + GameHBIRQHook = UNLOneBusIRQHook; + MapIRQHook = UNLOneBusCpuHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/pec-586.cpp b/branches/fceux-2.2.2/src/boards/pec-586.cpp new file mode 100644 index 00000000..6de80af7 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/pec-586.cpp @@ -0,0 +1,127 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 reg[8]; +static uint32 lastnt = 0; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { reg, 2, "REG" }, + { &lastnt, 4, "LNT" }, + { 0 } +}; + +static uint8 bs_tbl[128] = { + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, // 00 + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, // 10 + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, // 20 + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, // 30 + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, // 40 + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, // 50 + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30, // 60 + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, // 70 +}; + +static uint8 br_tbl[16] = { + 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, +}; + +static void Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + if(PRGsize[0] == 512 * 1024) { + if(reg[0] & 0x010) { + setprg32(0x8000, reg[0] & 7); + } else { + if(reg[0] & 0x40) + setprg8(0x8000, (reg[0] & 0x0F) | 0x20 | ((reg[0] & 0x20) >> 1)); + } + if((reg[0] & 0x18) == 0x18) + setmirror(MI_H); + else + setmirror(MI_V); + } else { + setprg16(0x8000, bs_tbl[reg[0] & 0x7f] >> 4); + setprg16(0xc000, bs_tbl[reg[0] & 0x7f] & 0xf); + setmirror(MI_V); + } +} + +static DECLFW(UNLPEC586Write) { + reg[(A & 0x700) >> 8] = V; + PEC586Hack = (reg[0] & 0x80) >> 7; +// FCEU_printf("bs %04x %02x\n", A, V); + Sync(); +} + +static DECLFR(UNLPEC586Read) { +// FCEU_printf("read %04x\n", A); + return (X.DB & 0xD8) | br_tbl[reg[4] >> 4]; +} + +static DECLFR(UNLPEC586ReadHi) { + if((reg[0] & 0x10) || ((reg[0] & 0x40) && (A < 0xA000))) + return CartBR(A); + else + return PRGptr[0][((0x0107 | ((A >> 7) & 0x0F8)) << 10) | (A & 0x3FF)]; +} + +static void UNLPEC586Power(void) { + if(PRGsize[0] == 512 * 1024) + reg[0] = 0x00; + else + reg[0] = 0x0E; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + if(PRGsize[0] == 512 * 1024) + SetReadHandler(0x8000, 0xFFFF, UNLPEC586ReadHi); + else + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x5000, 0x5fff, UNLPEC586Write); + SetReadHandler(0x5000, 0x5fff, UNLPEC586Read); +} + +static void UNLPEC586Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLPEC586Init(CartInfo *info) { + info->Power = UNLPEC586Power; + info->Close = UNLPEC586Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/sa-9602b.cpp b/branches/fceux-2.2.2/src/boards/sa-9602b.cpp new file mode 100644 index 00000000..a6a19bbe --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/sa-9602b.cpp @@ -0,0 +1,61 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static void SA9602BPW(uint32 A, uint8 V) { + setprg8r(EXPREGS[1], A, V & 0x3F); + if (MMC3_cmd & 0x40) + setprg8r(0, 0x8000, ~(1)); + else + setprg8r(0, 0xc000, ~(1)); + setprg8r(0, 0xe000, ~(0)); +} + +static DECLFW(SA9602BWrite) { + switch (A & 0xe001) { + case 0x8000: EXPREGS[0] = V; break; + case 0x8001: + if ((EXPREGS[0] & 7) < 6) { + EXPREGS[1] = V >> 6; + FixMMC3PRG(MMC3_cmd); + } + break; + } + MMC3_CMDWrite(A, V); +} + +static void SA9602BPower(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, SA9602BWrite); +} + +void SA9602B_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 0, 0, 0); + pwrap = SA9602BPW; + mmc3opts |= 2; + info->SaveGame[0] = UNIFchrrama; + info->SaveGameLen[0] = 32 * 1024; + info->Power = SA9602BPower; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/sachen.cpp b/branches/fceux-2.2.2/src/boards/sachen.cpp new file mode 100644 index 00000000..0f73e407 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/sachen.cpp @@ -0,0 +1,409 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 cmd, dip; +static uint8 latch[8]; + +static void S74LS374MSync(uint8 mirr) { + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirrorw(0, 1, 1, 1); break; + case 3: setmirror(MI_0); break; + } +} + +static void S74LS374NSynco(void) { + setprg32(0x8000, latch[0]); + setchr8(latch[1] | latch[3] | latch[4]); + S74LS374MSync(latch[2]); +} + +static DECLFW(S74LS374NWrite) { + A &= 0x4101; + if (A == 0x4100) + cmd = V & 7; + else{ + switch (cmd) { + case 2: latch[0] = V & 1; latch[3] = (V & 1) << 3; break; + case 4: latch[4] = (V & 1) << 2; break; + case 5: latch[0] = V & 7; break; + case 6: latch[1] = V & 3; break; + case 7: latch[2] = V >> 1; break; + } + S74LS374NSynco(); + } +} + +static DECLFR(S74LS374NRead) { + uint8 ret; + if ((A & 0x4100) == 0x4100) +// ret=(X.DB&0xC0)|((~cmd)&0x3F); + ret = ((~cmd) & 0x3F) ^ dip; + else + ret = X.DB; + return ret; +} + +static void S74LS374NPower(void) { + dip = 0; + latch[0] = latch[1] = latch[2] = latch[3] = latch[4] = 0; + S74LS374NSynco(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x7FFF, S74LS374NWrite); + SetReadHandler(0x4100, 0x5fff, S74LS374NRead); +} + +static void S74LS374NReset(void) { + dip ^= 1; + latch[0] = latch[1] = latch[2] = latch[3] = latch[4] = 0; + S74LS374NSynco(); +} + +static void S74LS374NRestore(int version) { + S74LS374NSynco(); +} + +void S74LS374N_Init(CartInfo *info) { + info->Power = S74LS374NPower; + info->Reset = S74LS374NReset; + GameStateRestore = S74LS374NRestore; + AddExState(latch, 5, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + AddExState(&dip, 1, 0, "DIP"); +} + +static void S74LS374NASynco(void) { + setprg32(0x8000, latch[0]); + setchr8(latch[1]); + S74LS374MSync(latch[2]); +} + +static DECLFW(S74LS374NAWrite) { + A &= 0x4101; + if (A == 0x4100) + cmd = V & 7; + else{ + switch (cmd) { + case 0: latch[0] = 0; latch[1] = 3; break; + case 2: latch[3] = (V & 1) << 3; break; + case 4: latch[1] = (latch[1] & 6) | (V & 3); break; + case 5: latch[0] = V & 1; break; + case 6: latch[1] = (latch[1] & 1) | latch[3] | ((V & 3) << 1); break; + case 7: latch[2] = V & 1; break; + } + S74LS374NASynco(); + } +} + +static void S74LS374NAPower(void) { + latch[0] = latch[2] = latch[3] = latch[4] = 0; + latch[1] = 3; + S74LS374NASynco(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x7FFF, S74LS374NAWrite); +} + +void S74LS374NA_Init(CartInfo *info) { + info->Power = S74LS374NAPower; + GameStateRestore = S74LS374NRestore; + AddExState(latch, 5, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); +} + +static int type; +static void S8259Synco(void) { + int x; + setprg32(0x8000, latch[5] & 7); + + if (!UNIFchrrama) { // No CHR RAM? Then BS'ing is ok. + for (x = 0; x < 4; x++) { + int bank; + if (latch[7] & 1) + bank = (latch[0] & 0x7) | ((latch[4] & 7) << 3); + else + bank = (latch[x] & 0x7) | ((latch[4] & 7) << 3); + switch (type) { + case 00: bank = (bank << 1) | (x & 1); setchr2(0x800 * x, bank); break; + case 01: setchr2(0x800 * x, bank); break; + case 02: bank = (bank << 2) | (x & 3); setchr2(0x800 * x, bank); break; + case 03: + bank = latch[x] & 7; + switch (x & 3) { + case 01: bank |= (latch[4] & 1) << 4; break; + case 02: bank |= (latch[4] & 2) << 3; break; + case 03: bank |= ((latch[4] & 4) << 2) | ((latch[6] & 1) << 3); break; + } + setchr1(0x400 * x, bank); + setchr4(0x1000, ~0); + break; + } + } + } + if (!(latch[7] & 1)) + S74LS374MSync(latch[7] >> 1); + else + setmirror(MI_V); +} + +static DECLFW(S8259Write) { + A &= 0x4101; + if (A == 0x4100) + cmd = V; + else{ + latch[cmd & 7] = V; + S8259Synco(); + } +} + +static void S8259Reset(void) { + int x; + cmd = 0; + + for (x = 0; x < 8; x++) latch[x] = 0; + setchr8(0); + + S8259Synco(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x7FFF, S8259Write); +} + +static void S8259Restore(int version) { + S8259Synco(); +} + +void S8259A_Init(CartInfo *info) { // Kevin's Horton 141 mapper + info->Power = S8259Reset; + GameStateRestore = S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type = 0; +} + +void S8259B_Init(CartInfo *info) { // Kevin's Horton 138 mapper + info->Power = S8259Reset; + GameStateRestore = S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type = 1; +} + +void S8259C_Init(CartInfo *info) { // Kevin's Horton 139 mapper + info->Power = S8259Reset; + GameStateRestore = S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type = 2; +} + +void S8259D_Init(CartInfo *info) { // Kevin's Horton 137 mapper + info->Power = S8259Reset; + GameStateRestore = S8259Restore; + AddExState(latch, 8, 0, "LATC"); + AddExState(&cmd, 1, 0, "CMD"); + type = 3; +} + +static void (*WSync)(void); + +static DECLFW(SAWrite) { + if (A & 0x100) { + latch[0] = V; + WSync(); + } +} + +static void SAPower(void) { + latch[0] = 0; + WSync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x5FFF, SAWrite); +} + +static void SARestore(int version) { + WSync(); +} + +static DECLFW(SADWrite) { + latch[0] = V; + WSync(); +} + +static void SADPower(void) { + latch[0] = 0; + WSync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, SADWrite); +} + +static void SA0161MSynco() { + setprg32(0x8000, (latch[0] >> 3) & 1); + setchr8(latch[0] & 7); +} + +static void SA72007Synco() { + setprg32(0x8000, 0); + setchr8(latch[0] >> 7); +} + +static void SA009Synco() { + setprg32(0x8000, 0); + setchr8(latch[0] & 1); +} + +static void SA72008Synco() { + setprg32(0x8000, (latch[0] >> 2) & 1); + setchr8(latch[0] & 3); +} + +void SA0161M_Init(CartInfo *info) { + WSync = SA0161MSynco; + GameStateRestore = SARestore; + info->Power = SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA72007_Init(CartInfo *info) { + WSync = SA72007Synco; + GameStateRestore = SARestore; + info->Power = SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA72008_Init(CartInfo *info) { + WSync = SA72008Synco; + GameStateRestore = SARestore; + info->Power = SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA009_Init(CartInfo *info) { + WSync = SA009Synco; + GameStateRestore = SARestore; + info->Power = SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA0036_Init(CartInfo *info) { + WSync = SA72007Synco; + GameStateRestore = SARestore; + info->Power = SADPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +void SA0037_Init(CartInfo *info) { + WSync = SA0161MSynco; + GameStateRestore = SARestore; + info->Power = SADPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + +// ----------------------------------------------- + +static void TCU01Synco() { + setprg32(0x8000, ((latch[0] & 0x80) >> 6) | ((latch[0] >> 2) & 1)); + setchr8((latch[0] >> 3) & 0xF); +} + +static DECLFW(TCU01Write) { + if ((A & 0x103) == 0x102) { + latch[0] = V; + TCU01Synco(); + } +} + +static void TCU01Power(void) { + latch[0] = 0; + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0xFFFF, TCU01Write); + TCU01Synco(); +} + +static void TCU01Restore(int version) { + TCU01Synco(); +} + +void TCU01_Init(CartInfo *info) { + GameStateRestore = TCU01Restore; + info->Power = TCU01Power; + AddExState(&latch[0], 1, 0, "LATC"); +} + +//----------------------------------------------- + +static void TCU02Synco() { + setprg32(0x8000, 0); + setchr8(latch[0] & 3); +} + +static DECLFW(TCU02Write) { + if ((A & 0x103) == 0x102) { + latch[0] = V + 3; + TCU02Synco(); + } +} + +static DECLFR(TCU02Read) { + return (latch[0] & 0x3F) | (X.DB & 0xC0); +} + +static void TCU02Power(void) { + latch[0] = 0; + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0x4100, 0x4100, TCU02Read); + SetWriteHandler(0x4100, 0xFFFF, TCU02Write); + TCU02Synco(); +} + +static void TCU02Restore(int version) { + TCU02Synco(); +} + +void TCU02_Init(CartInfo *info) { + GameStateRestore = TCU02Restore; + info->Power = TCU02Power; + AddExState(&latch[0], 1, 0, "LATC"); +} + +// --------------------------------------------- + +static DECLFR(TCA01Read) { + uint8 ret; + if ((A & 0x4100) == 0x4100) + ret = (X.DB & 0xC0) | ((~A) & 0x3F); + else + ret = X.DB; + return ret; +} + +static void TCA01Power(void) { + setprg16(0x8000, 0); + setprg16(0xC000, 1); + setchr8(0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0x4100, 0x5FFF, TCA01Read); +} + +void TCA01_Init(CartInfo *info) { + info->Power = TCA01Power; +} + diff --git a/branches/fceux-2.2.2/src/boards/sc-127.cpp b/branches/fceux-2.2.2/src/boards/sc-127.cpp new file mode 100644 index 00000000..ed466ca1 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/sc-127.cpp @@ -0,0 +1,114 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 + * + * Wario Land II (Kirby hack) + */ + +#include "mapinc.h" + +static uint8 reg[8], chr[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint16 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { reg, 8, "REGS" }, + { chr, 8, "CHRS" }, + { &IRQCount, 16, "IRQc" }, + { &IRQa, 16, "IRQa" }, + { 0 } +}; + +static void Sync(void) { + int i; + setprg8(0x8000, reg[0]); + setprg8(0xA000, reg[1]); + setprg8(0xC000, reg[2]); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + setmirror(reg[3] ^ 1); +} + +static DECLFW(UNLSC127Write) { + switch (A) { + case 0x8000: reg[0] = V; break; + case 0x8001: reg[1] = V; break; + case 0x8002: reg[2] = V; break; + case 0x9000: chr[0] = V; break; + case 0x9001: chr[1] = V; break; + case 0x9002: chr[2] = V; break; + case 0x9003: chr[3] = V; break; + case 0x9004: chr[4] = V; break; + case 0x9005: chr[5] = V; break; + case 0x9006: chr[6] = V; break; + case 0x9007: chr[7] = V; break; + case 0xC002: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xC005: IRQCount = V; break; + case 0xC003: IRQa = 1; break; + case 0xD001: reg[3] = V; break; + } + Sync(); +} + +static void UNLSC127Power(void) { + Sync(); + setprg8r(0x10, 0x6000, 0); + setprg8(0xE000, ~0); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLSC127Write); +} + +static void UNLSC127IRQ(void) { + if (IRQa) { + IRQCount--; + if (IRQCount == 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + } + } +} + +static void UNLSC127Reset(void) { +} + +static void UNLSC127Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLSC127_Init(CartInfo *info) { + info->Reset = UNLSC127Reset; + info->Power = UNLSC127Power; + info->Close = UNLSC127Close; + GameHBIRQHook = UNLSC127IRQ; + GameStateRestore = StateRestore; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/sheroes.cpp b/branches/fceux-2.2.2/src/boards/sheroes.cpp new file mode 100644 index 00000000..c536c1d5 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/sheroes.cpp @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM; +static uint8 tekker; + +static void MSHCW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) + setchr8r(0x10, 0); + else{ + if (A < 0x800) + setchr1(A, V | ((EXPREGS[0] & 8) << 5)); + else if (A < 0x1000) + setchr1(A, V | ((EXPREGS[0] & 4) << 6)); + else if (A < 0x1800) + setchr1(A, V | ((EXPREGS[0] & 1) << 8)); + else + setchr1(A, V | ((EXPREGS[0] & 2) << 7)); + } +} + +static DECLFW(MSHWrite) { + EXPREGS[0] = V; + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(MSHRead) { + return(tekker); +} + +static void MSHReset(void) { + MMC3RegReset(); + tekker ^= 0xFF; +} + +static void MSHPower(void) { + tekker = 0x00; + GenMMC3Power(); + SetWriteHandler(0x4100, 0x4100, MSHWrite); + SetReadHandler(0x4100, 0x4100, MSHRead); +} + +static void MSHClose(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +void UNLSHeroes_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 512, 0, 0); + cwrap = MSHCW; + info->Power = MSHPower; + info->Reset = MSHReset; + info->Close = MSHClose; + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(EXPREGS, 4, 0, "EXPR"); + AddExState(&tekker, 1, 0, "DIPSW"); +} diff --git a/branches/fceux-2.2.2/src/boards/sl1632.cpp b/branches/fceux-2.2.2/src/boards/sl1632.cpp new file mode 100644 index 00000000..80643c5f --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/sl1632.cpp @@ -0,0 +1,107 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap; +static SFORMAT StateRegs[] = +{ + { chrcmd, 8, "CHRC" }, + { &prg0, 1, "PRG0" }, + { &prg1, 1, "PRG1" }, + { &bbrk, 1, "BRK" }, + { &mirr, 1, "MIRR" }, + { &swap, 1, "SWAP" }, + { 0 } +}; + +static void Sync(void) { + int i; + setprg8(0x8000, prg0); + setprg8(0xA000, prg1); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chrcmd[i]); + setmirror(mirr ^ 1); +} + +static void UNLSL1632CW(uint32 A, uint8 V) { + int cbase = (MMC3_cmd & 0x80) << 5; + int page0 = (bbrk & 0x08) << 5; + int page1 = (bbrk & 0x20) << 3; + int page2 = (bbrk & 0x80) << 1; + setchr1(cbase ^ 0x0000, page0 | (DRegBuf[0] & (~1))); + setchr1(cbase ^ 0x0400, page0 | DRegBuf[0] | 1); + setchr1(cbase ^ 0x0800, page0 | (DRegBuf[1] & (~1))); + setchr1(cbase ^ 0x0C00, page0 | DRegBuf[1] | 1); + setchr1(cbase ^ 0x1000, page1 | DRegBuf[2]); + setchr1(cbase ^ 0x1400, page1 | DRegBuf[3]); + setchr1(cbase ^ 0x1800, page2 | DRegBuf[4]); + setchr1(cbase ^ 0x1c00, page2 | DRegBuf[5]); +} + +static DECLFW(UNLSL1632CMDWrite) { + if (A == 0xA131) { + bbrk = V; + } + if (bbrk & 2) { + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + if (A < 0xC000) + MMC3_CMDWrite(A, V); + else + MMC3_IRQWrite(A, V); + } else { + if ((A >= 0xB000) && (A <= 0xE003)) { + int ind = ((((A & 2) | (A >> 10)) >> 1) + 2) & 7; + int sar = ((A & 1) << 2); + chrcmd[ind] = (chrcmd[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + } else + switch (A & 0xF003) { + case 0x8000: prg0 = V; break; + case 0xA000: prg1 = V; break; + case 0x9000: mirr = V & 1; break; + } + Sync(); + } +} + +static void StateRestore(int version) { + if (bbrk & 2) { + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else + Sync(); +} + +static void UNLSL1632Power(void) { + GenMMC3Power(); + SetWriteHandler(0x4100, 0xFFFF, UNLSL1632CMDWrite); +} + +void UNLSL1632_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 512, 0, 0); + cwrap = UNLSL1632CW; + info->Power = UNLSL1632Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/subor.cpp b/branches/fceux-2.2.2/src/boards/subor.cpp new file mode 100644 index 00000000..00d9a997 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/subor.cpp @@ -0,0 +1,88 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 is167, regs[4]; + +static SFORMAT StateRegs[] = +{ + { regs, 4, "DREG" }, + { 0 } +}; + +static void Sync(void) { + int base, bank; + base = ((regs[0] ^ regs[1]) & 0x10) << 1; + bank = (regs[2] ^ regs[3]) & 0x1f; + + if (regs[1] & 0x08) { + bank &= 0xFE; + if (is167) { + setprg16(0x8000, base + bank + 1); + setprg16(0xC000, base + bank + 0); + } else { + setprg16(0x8000, base + bank + 0); + setprg16(0xC000, base + bank + 1); + } + } else { + if (regs[1] & 0x04) { + setprg16(0x8000, 0x1F); + setprg16(0xC000, base + bank); + } else { + setprg16(0x8000, base + bank); + if (is167) + setprg16(0xC000, 0x20); + else + setprg16(0xC000, 0x07); + } + } + setchr8(0); +} + +static DECLFW(M166Write) { + regs[(A >> 13) & 0x03] = V; + Sync(); +} + +static void M166Power(void) { + regs[0] = regs[1] = regs[2] = regs[3] = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M166Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper166_Init(CartInfo *info) { + is167 = 0; + info->Power = M166Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper167_Init(CartInfo *info) { + is167 = 1; + info->Power = M166Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/super24.cpp b/branches/fceux-2.2.2/src/boards/super24.cpp new file mode 100644 index 00000000..f62fbe85 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/super24.cpp @@ -0,0 +1,93 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM = NULL; +static int masko8[8] = { 63, 31, 15, 1, 3, 0, 0, 0 }; + +static void Super24PW(uint32 A, uint8 V) { + uint32 NV = V & masko8[EXPREGS[0] & 7]; + NV |= (EXPREGS[1] << 1); + setprg8r((NV >> 6) & 0xF, A, NV); +} + +static void Super24CW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x20) + setchr1r(0x10, A, V); + else{ + uint32 NV = V | (EXPREGS[2] << 3); + setchr1r((NV >> 9) & 0xF, A, NV); + } +} + +static DECLFW(Super24Write) { + switch (A) { + case 0x5FF0: + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + break; + case 0x5FF1: + EXPREGS[1] = V; + FixMMC3PRG(MMC3_cmd); + break; + case 0x5FF2: + EXPREGS[2] = V; + FixMMC3CHR(MMC3_cmd); + break; + } +} + +static void Super24Power(void) { + EXPREGS[0] = 0x24; + EXPREGS[1] = 159; + EXPREGS[2] = 0; + GenMMC3Power(); + SetWriteHandler(0x5000, 0x7FFF, Super24Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void Super24Reset(void) { + EXPREGS[0] = 0x24; + EXPREGS[1] = 159; + EXPREGS[2] = 0; + MMC3RegReset(); +} + +static void Super24Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +void Super24_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power = Super24Power; + info->Reset = Super24Reset; + info->Close = Super24Close; + cwrap = Super24CW; + pwrap = Super24PW; + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CHRR"); + AddExState(EXPREGS, 3, 0, "BIG2"); +} diff --git a/branches/fceux-2.2.2/src/boards/supervision.cpp b/branches/fceux-2.2.2/src/boards/supervision.cpp new file mode 100644 index 00000000..46be8ed2 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/supervision.cpp @@ -0,0 +1,87 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 cmd0, cmd1; +static SFORMAT StateRegs[] = +{ + { &cmd0, 1, "L1" }, + { &cmd1, 1, "L2" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + if (PRGptr[1]) + setprg8r((cmd0 & 0xC) >> 2, 0x6000, ((cmd0 & 0x3) << 4) | 0xF); + else + setprg8(0x6000, (((cmd0 & 0xF) << 4) | 0xF) + 4); + if (cmd0 & 0x10) { + if (PRGptr[1]) { + setprg16r((cmd0 & 0xC) >> 2, 0x8000, ((cmd0 & 0x3) << 3) | (cmd1 & 7)); + setprg16r((cmd0 & 0xC) >> 2, 0xc000, ((cmd0 & 0x3) << 3) | 7); + } else { + setprg16(0x8000, (((cmd0 & 0xF) << 3) | (cmd1 & 7)) + 2); + setprg16(0xc000, (((cmd0 & 0xF) << 3) | 7) + 2); + } + } else + if (PRGptr[4]) + setprg32r(4, 0x8000, 0); + else + setprg32(0x8000, 0); + setmirror(((cmd0 & 0x20) >> 5) ^ 1); +} + +static DECLFW(SuperWriteLo) { + if (!(cmd0 & 0x10)) { + cmd0 = V; + Sync(); + } +} + +static DECLFW(SuperWriteHi) { + cmd1 = V; + Sync(); +} + +static void SuperPower(void) { + SetWriteHandler(0x6000, 0x7FFF, SuperWriteLo); + SetWriteHandler(0x8000, 0xFFFF, SuperWriteHi); + SetReadHandler(0x6000, 0xFFFF, CartBR); + cmd0 = cmd1 = 0; + Sync(); +} + +static void SuperReset(void) { + cmd0 = cmd1 = 0; + Sync(); +} + +static void SuperRestore(int version) { + Sync(); +} + +void Supervision16_Init(CartInfo *info) { + info->Power = SuperPower; + info->Reset = SuperReset; + GameStateRestore = SuperRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/t-227-1.cpp b/branches/fceux-2.2.2/src/boards/t-227-1.cpp new file mode 100644 index 00000000..ca99b6f9 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/t-227-1.cpp @@ -0,0 +1,100 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * 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 + */ + +// T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0x07; + +static void BMCT2271CW(uint32 A, uint8 V) { + uint32 va = V; + if (EXPREGS[0] & 0x20) { + va |= 0x200; + va |= (EXPREGS[0] & 0x10) << 4; + } else { + va &= 0x7F; + va |= (EXPREGS[0] & 0x18) << 4; + } + setchr1(A, va); +} + +static void BMCT2271PW(uint32 A, uint8 V) { + uint32 va = V & 0x3F; + if (EXPREGS[0] & 0x20) { + va &= 0x1F; + va |= 0x40; + va |= (EXPREGS[0] & 0x10) << 1; + } else { + va &= 0x0F; + va |= (EXPREGS[0] & 0x18) << 1; + } + switch (EXPREGS[0] & 3) { + case 0x00: setprg8(A, va); break; + case 0x02: + { + va = (va & 0xFD) | ((EXPREGS[0] & 4) >> 1); + if (A < 0xC000) { + setprg16(0x8000, va >> 1); + setprg16(0xC000, va >> 1); + } + break; + } + case 0x01: + case 0x03: if (A < 0xC000) setprg32(0x8000, va >> 2); break; + } +} + +static DECLFW(BMCT2271LoWrite) { + if (!(EXPREGS[0] & 0x80)) + EXPREGS[0] = A & 0xFF; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(BMCT2271HiRead) { + uint32 av = A; + if (EXPREGS[0] & 0x40) av = (av & 0xFFF0) | reset_flag; + return CartBR(av); +} + +static void BMCT2271Reset(void) { + EXPREGS[0] = 0x00; + reset_flag++; + reset_flag &= 0x0F; + MMC3RegReset(); +} + +static void BMCT2271Power(void) { + EXPREGS[0] = 0x00; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, BMCT2271LoWrite); + SetReadHandler(0x8000, 0xFFFF, BMCT2271HiRead); +} + +void BMCT2271_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap = BMCT2271PW; + cwrap = BMCT2271CW; + info->Power = BMCT2271Power; + info->Reset = BMCT2271Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/branches/fceux-2.2.2/src/boards/t-262.cpp b/branches/fceux-2.2.2/src/boards/t-262.cpp new file mode 100644 index 00000000..01b873b3 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/t-262.cpp @@ -0,0 +1,73 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 bank, base, lock, mirr, mode; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &base, 1, "BASE" }, + { &lock, 1, "LOCK" }, + { &mirr, 1, "MIRR" }, + { &mode, 1, "MODE" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg16(0x8000, base | bank); + setprg16(0xC000, base | (mode ? bank : 7)); + setmirror(mirr); +} + +static DECLFW(BMCT262Write) { + if (!lock) { + base = ((A & 0x60) >> 2) | ((A & 0x100) >> 3); + mode = A & 0x80; + mirr = ((A & 2) >> 1) ^ 1; + lock = (A & 0x2000) >> 13; + } + bank = V & 7; + Sync(); +} + +static void BMCT262Power(void) { + lock = bank = base = mode = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, BMCT262Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void BMCT262Reset(void) { + lock = bank = base = mode = 0; + Sync(); +} + +static void BMCT262Restore(int version) { + Sync(); +} + +void BMCT262_Init(CartInfo *info) { + info->Power = BMCT262Power; + info->Reset = BMCT262Reset; + GameStateRestore = BMCT262Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/tengen.cpp b/branches/fceux-2.2.2/src/boards/tengen.cpp new file mode 100644 index 00000000..b47afff2 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/tengen.cpp @@ -0,0 +1,139 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "mapinc.h" + +static uint8 cmd, mirr, regs[11]; +static uint8 rmode, IRQmode, IRQCount, IRQa, IRQLatch; + +static SFORMAT StateRegs[] = { + { regs, 11, "REGS" }, + { &cmd, 1, "CMDR" }, + { &mirr, 1, "MIRR" }, + { &rmode, 1, "RMOD" }, + { &IRQmode, 1, "IRQM" }, + { &IRQCount, 1, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { &IRQLatch, 1, "IRQL" }, + { 0 } +}; + +static void M64IRQHook(int a) { + static int32 smallcount; + if (IRQmode) { + smallcount += a; + while (smallcount >= 4) { + smallcount -= 4; + IRQCount--; + if (IRQCount == 0xFF) + if (IRQa) X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void M64HBHook(void) { + if ((!IRQmode) && (scanline != 240)) { + rmode = 0; + IRQCount--; + if (IRQCount == 0xFF) { + if (IRQa) { + rmode = 1; + X6502_IRQBegin(FCEU_IQEXT); + } + } + } +} + +static void Sync(void) { + if (cmd & 0x20) { + setchr1(0x0000, regs[0]); + setchr1(0x0400, regs[8]); + setchr1(0x0800, regs[1]); + setchr1(0x0C00, regs[9]); + } else { + setchr2(0x0000, regs[0] >> 1); + setchr2(0x0800, regs[1] >> 1); + } + setchr1(0x1000, regs[2]); + setchr1(0x1400, regs[3]); + setchr1(0x1800, regs[4]); + setchr1(0x1C00, regs[5]); + setprg8(0x8000, regs[6]); + setprg8(0xA000, regs[7]); + setprg8(0xC000, regs[10]); + setprg8(0xE000, ~0); + setmirror(mirr); +} + +static DECLFW(M64Write) { + switch (A & 0xF001) { + case 0xA000: mirr = (V & 1) ^ 1; Sync(); break;\ + case 0x8000: cmd = V; break; + case 0x8001: + if ((cmd & 0xF) < 10) + regs[cmd & 0xF] = V; + else if ((cmd & 0xF) == 0xF) + regs[10] = V; + Sync(); + break; + case 0xC000: + IRQLatch = V; + if (rmode == 1) + IRQCount = IRQLatch; + break; + case 0xC001: + rmode = 1; + IRQCount = IRQLatch; + IRQmode = V & 1; + break; + case 0xE000: + IRQa = 0; + X6502_IRQEnd(FCEU_IQEXT); + if (rmode == 1) + IRQCount = IRQLatch; + break; + case 0xE001: + IRQa = 1; + if (rmode == 1) + IRQCount = IRQLatch; + break; + } +} + +static void M64Power(void) { + cmd = mirr = 0; + regs[0] = regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = ~0; + regs[6] = regs[7] = regs[8] = regs[9] = regs[10] = ~0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M64Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper64_Init(CartInfo *info) { + info->Power = M64Power; + GameHBIRQHook = M64HBHook; + MapIRQHook = M64IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/tf-1201.cpp b/branches/fceux-2.2.2/src/boards/tf-1201.cpp new file mode 100644 index 00000000..24e8a771 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/tf-1201.cpp @@ -0,0 +1,109 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * Lethal Weapon (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 prg0, prg1, mirr, swap; +static uint8 chr[8]; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[] = +{ + { &prg0, 1, "PRG0" }, + { &prg0, 1, "PRG1" }, + { &mirr, 1, "MIRR" }, + { &swap, 1, "SWAP" }, + { chr, 8, "CHR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQPre, 1, "IRQP" }, + { &IRQa, 1, "IRQA" }, + { 0 } +}; + +static void SyncPrg(void) { + if (swap & 3) { + setprg8(0x8000, ~1); + setprg8(0xC000, prg0); + } else { + setprg8(0x8000, prg0); + setprg8(0xC000, ~1); + } + setprg8(0xA000, prg1); + setprg8(0xE000, ~0); +} + +static void SyncChr(void) { + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + setmirror(mirr ^ 1); +} + +static void StateRestore(int version) { + SyncPrg(); + SyncChr(); +} + +static DECLFW(UNLTF1201Write) { + A = (A & 0xF003) | ((A & 0xC) >> 2); + if ((A >= 0xB000) && (A <= 0xE003)) { + int ind = (((A >> 11) - 6) | (A & 1)) & 7; + int sar = ((A & 2) << 1); + chr[ind] = (chr[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + SyncChr(); + } else switch (A & 0xF003) { + case 0x8000: prg0 = V; SyncPrg(); break; + case 0xA000: prg1 = V; SyncPrg(); break; + case 0x9000: mirr = V & 1; SyncChr(); break; + case 0x9001: swap = V & 3; SyncPrg(); break; + case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break; + case 0xF002: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break; + case 0xF001: + case 0xF003: IRQa = V & 2; X6502_IRQEnd(FCEU_IQEXT); if (scanline < 240) IRQCount -= 8; break; + } +} + +static void UNLTF1201IRQCounter(void) { + if (IRQa) { + IRQCount++; + if (IRQCount == 237) { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLTF1201Power(void) { + IRQPre = IRQCount = IRQa = 0; + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLTF1201Write); + SyncPrg(); + SyncChr(); +} + +void UNLTF1201_Init(CartInfo *info) { + info->Power = UNLTF1201Power; + GameHBIRQHook = UNLTF1201IRQCounter; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/transformer.cpp b/branches/fceux-2.2.2/src/boards/transformer.cpp new file mode 100644 index 00000000..0f9c4a60 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/transformer.cpp @@ -0,0 +1,96 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +unsigned int *GetKeyboard(void); // FIXME: 10/28 - now implemented in SDL as well. should we rename this to a FCEUI_* function? + +static unsigned int *TransformerKeys, oldkeys[256]; +static int TransformerCycleCount, TransformerChar = 0; + +static void TransformerIRQHook(int a) { + TransformerCycleCount += a; + if (TransformerCycleCount >= 1000) { + uint32 i; + TransformerCycleCount -= 1000; + TransformerKeys = GetKeyboard(); + + for (i = 0; i < 256; i++) { + if (oldkeys[i] != TransformerKeys[i]) { + if (oldkeys[i] == 0) + TransformerChar = i; + else + TransformerChar = i | 0x80; + X6502_IRQBegin(FCEU_IQEXT); + memcpy((void*)&oldkeys[0], (void*)TransformerKeys, sizeof(oldkeys)); + break; + } + } + } +} + +static DECLFR(TransformerRead) { + uint8 ret = 0; + switch (A & 3) { + case 0: ret = TransformerChar & 15; break; + case 1: ret = (TransformerChar >> 4); break; + case 2: break; + case 4: break; + } + X6502_IRQEnd(FCEU_IQEXT); + return ret; +} + +static void TransformerPower(void) { + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + setchr8(0); + + SetReadHandler(0x5000, 0x5004, TransformerRead); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + + MapIRQHook = TransformerIRQHook; +} + +static void TransformerClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Transformer_Init(CartInfo *info) { + info->Power = TransformerPower; + info->Close = TransformerClose; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); +} diff --git a/branches/fceux-2.2.2/src/boards/vrc1.cpp b/branches/fceux-2.2.2/src/boards/vrc1.cpp new file mode 100644 index 00000000..899bcfb5 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/vrc1.cpp @@ -0,0 +1,70 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * VRC-1 + * + */ + +#include "mapinc.h" + +static uint8 preg[3], creg[2], mode; +static SFORMAT StateRegs[] = +{ + { &mode, 1, "MODE" }, + { creg, 2, "CREG" }, + { preg, 3, "PREG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + setchr4(0x0000, creg[0] | ((mode & 2) << 3)); + setchr4(0x1000, creg[1] | ((mode & 4) << 2)); + setmirror((mode & 1) ^ 1); +} + +static DECLFW(M75Write) { + switch (A & 0xF000) { + case 0x8000: preg[0] = V; Sync(); break; + case 0x9000: mode = V; Sync(); break; + case 0xA000: preg[1] = V; Sync(); break; + case 0xC000: preg[2] = V; Sync(); break; + case 0xE000: creg[0] = V & 0xF; Sync(); break; + case 0xF000: creg[1] = V & 0xF; Sync(); break; + } +} + +static void M75Power(void) { + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M75Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper75_Init(CartInfo *info) { + info->Power = M75Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/vrc2and4.cpp b/branches/fceux-2.2.2/src/boards/vrc2and4.cpp new file mode 100644 index 00000000..58e6d868 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/vrc2and4.cpp @@ -0,0 +1,267 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 isPirate, is22; +static uint16 IRQCount; +static uint8 IRQLatch, IRQa; +static uint8 prgreg[2], chrreg[8]; +static uint16 chrhi[8]; +static uint8 regcmd, irqcmd, mirr, big_bank; +static uint16 acount = 0; +static uint16 weirdo = 0; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { prgreg, 2, "PREG" }, + { chrreg, 8, "CREG" }, + { chrhi, 16, "CRGH" }, + { ®cmd, 1, "CMDR" }, + { &irqcmd, 1, "CMDI" }, + { &mirr, 1, "MIRR" }, + { &big_bank, 1, "BIGB" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQa, 1, "IRQA" }, + { 0 } +}; + +static void Sync(void) { + if (regcmd & 2) { + setprg8(0xC000, prgreg[0] | big_bank); + setprg8(0x8000, ((~1) & 0x1F) | big_bank); + } else { + setprg8(0x8000, prgreg[0] | big_bank); + setprg8(0xC000, ((~1) & 0x1F) | big_bank); + } + setprg8(0xA000, prgreg[1] | big_bank); + setprg8(0xE000, ((~0) & 0x1F) | big_bank); + if (UNIFchrrama) + setchr8(0); + else{ + uint8 i; + if(!weirdo) + for (i = 0; i < 8; i++) + setchr1(i << 10, (chrhi[i] | chrreg[i]) >> is22); + else { + setchr1(0x0000, 0xFC); + setchr1(0x0400, 0xFD); + setchr1(0x0800, 0xFF); + weirdo--; + } + } + switch (mirr & 0x3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(VRC24Write) { + A &= 0xF003; + if ((A >= 0xB000) && (A <= 0xE003)) { + if (UNIFchrrama) + big_bank = (V & 8) << 2; // my personally many-in-one feature ;) just for support pirate cart 2-in-1 + else{ + uint16 i = ((A >> 1) & 1) | ((A - 0xB000) >> 11); + uint16 nibble = ((A & 1) << 2); + chrreg[i] = (chrreg[i] & (0xF0 >> nibble)) | ((V & 0xF) << nibble); + if(nibble) + chrhi[i] = (V & 0x10) << 4; // another one many in one feature from pirate carts + } + Sync(); + } else + switch (A & 0xF003) { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: + if (!isPirate) { + prgreg[0] = V & 0x1F; + Sync(); + } + break; + case 0xA000: + case 0xA001: + case 0xA002: + case 0xA003: + if (!isPirate) + prgreg[1] = V & 0x1F; + else{ + prgreg[0] = (V & 0x1F) << 1; + prgreg[1] = ((V & 0x1F) << 1) | 1; + } + Sync(); + break; + case 0x9000: + case 0x9001: if (V != 0xFF) mirr = V; Sync(); break; + case 0x9002: + case 0x9003: regcmd = V; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; + case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; + case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount = 0; IRQCount = IRQLatch; IRQa = V & 2; irqcmd = V & 1; break; + case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa = irqcmd; break; + } +} + +static DECLFW(M21Write) { + A = (A & 0xF000) | ((A >> 1) & 0x3); // Ganbare Goemon Gaiden 2 - Tenka no Zaihou (J) [!] isn't mapper 21 actually, + // it's mapper 23 by wirings + VRC24Write(A, V); +} + +static DECLFW(M22Write) { + if (A == 0xC007) { // Ganbare Goemon Gaiden does strange things!!! at the end credits + weirdo = 8; // quick dirty hack, seems there is no other games with such PCB, so + // we never know if it will not work for something else lol + } + A |= ((A >> 2) & 0x3); // It's just swapped lines from 21 mapper + // + VRC24Write((A & 0xF000) | ((A >> 1) & 1) | ((A << 1) & 2), V); +} + +static DECLFW(M23Write) { + A |= ((A >> 2) & 0x3) | ((A >> 4) & 0x3) | ((A >> 6) & 0x3);// actually there is many-in-one mapper source, some pirate or + // licensed games use various address bits for registers + VRC24Write(A, V); +} + +static void M21Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M21Write); +} + +static void M22Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M22Write); +} + +static void M23Power(void) { + big_bank = 0x20; + Sync(); + setprg8r(0x10, 0x6000, 0); // Only two Goemon games are have battery backed RAM, three more shooters + // (Parodius Da!, Gradius 2 and Crisis Force uses 2k or SRAM at 6000-67FF only + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M23Write); +} + +static void M25Power(void) { + big_bank = 0x20; + Sync(); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M22Write); +} + +void VRC24IRQHook(int a) { + #define LCYCS 341 + if (IRQa) { + acount += a * 3; + if (acount >= LCYCS) { + while (acount >= LCYCS) { + acount -= LCYCS; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +static void VRC24Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper21_Init(CartInfo *info) { + isPirate = 0; + is22 = 0; + info->Power = M21Power; + MapIRQHook = VRC24IRQHook; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper22_Init(CartInfo *info) { + isPirate = 0; + is22 = 1; + info->Power = M22Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} + +void VRC24_Init(CartInfo *info) { + info->Close = VRC24Close; + MapIRQHook = VRC24IRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if(info->battery) { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper23_Init(CartInfo *info) { + isPirate = 0; + is22 = 0; + info->Power = M23Power; + VRC24_Init(info); +} + +void Mapper25_Init(CartInfo *info) { + isPirate = 0; + is22 = 0; + info->Power = M25Power; + VRC24_Init(info); +} + +void UNLT230_Init(CartInfo *info) { + isPirate = 1; + is22 = 0; + info->Power = M23Power; + VRC24_Init(info); +} diff --git a/branches/fceux-2.2.2/src/boards/vrc3.cpp b/branches/fceux-2.2.2/src/boards/vrc3.cpp new file mode 100644 index 00000000..8369100e --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/vrc3.cpp @@ -0,0 +1,134 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 + * + * VRC-3 + * + */ + +#include "mapinc.h" + +static uint8 preg; +static uint8 IRQx; //autoenable +static uint8 IRQm; //mode +static uint8 IRQa; +static uint16 IRQReload, IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &IRQa, 1, "IRQA" }, + { &IRQx, 1, "IRQX" }, + { &IRQm, 1, "IRQM" }, + { &IRQReload, 2, "IRQR" }, + { &IRQCount, 2, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr8(0); +} + +static DECLFW(M73Write) { + switch (A & 0xF000) { + case 0x8000: IRQReload &= 0xFFF0; IRQReload |= (V & 0xF) << 0; break; + case 0x9000: IRQReload &= 0xFF0F; IRQReload |= (V & 0xF) << 4; break; + case 0xA000: IRQReload &= 0xF0FF; IRQReload |= (V & 0xF) << 8; break; + case 0xB000: IRQReload &= 0x0FFF; IRQReload |= (V & 0xF) << 12; break; + case 0xC000: + IRQm = V & 4; + IRQx = V & 1; + IRQa = V & 2; + if (IRQa) { + if (IRQm) { + IRQCount &= 0xFFFF; + IRQCount |= (IRQReload & 0xFF); + } else + IRQCount = IRQReload; + } + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xD000: X6502_IRQEnd(FCEU_IQEXT); IRQa = IRQx; break; + case 0xF000: preg = V; Sync(); break; + } +} + +static void M73IRQHook(int a) { + int32 i; + if (!IRQa) return; + for (i = 0; i < a; i++) { + if (IRQm) { + uint16 temp = IRQCount; + temp &= 0xFF; + IRQCount &= 0xFF00; + if (temp == 0xFF) { + IRQCount = IRQReload; + IRQCount |= (uint16)(IRQReload & 0xFF); + X6502_IRQBegin(FCEU_IQEXT); + } else { + temp++; + IRQCount |= temp; + } + } else { + //16 bit mode + if (IRQCount == 0xFFFF) { + IRQCount = IRQReload; + X6502_IRQBegin(FCEU_IQEXT); + } else + IRQCount++; + } + } +} + +static void M73Power(void) { + IRQReload = IRQm = IRQx = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, M73Write); +} + +static void M73Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper73_Init(CartInfo *info) { + info->Power = M73Power; + info->Close = M73Close; + MapIRQHook = M73IRQHook; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/branches/fceux-2.2.2/src/boards/vrc5.cpp b/branches/fceux-2.2.2/src/boards/vrc5.cpp new file mode 100644 index 00000000..0b439370 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/vrc5.cpp @@ -0,0 +1,225 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * 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 + * + * VRC-5 (CAI Shogakko no Sansu) + * + */ + +#include "mapinc.h" + +static uint8 QTAINTRAM[2048]; +static writefunc old2007wrap; + +static uint16 CHRSIZE = 8192; +static uint16 WRAMSIZE = 8192 + 4096; +static uint8 *CHRRAM = NULL; +static uint8 *WRAM = NULL; + +static uint8 IRQa, K4IRQ; +static uint32 IRQLatch, IRQCount; + +static uint8 regs[16]; +//static uint8 test[8]; +static SFORMAT StateRegs[] = +{ + { &IRQCount, 1, "IRQC" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQa, 1, "IRQA" }, + { &K4IRQ, 1, "KIRQ" }, + { regs, 16, "REGS" }, + { 0 } +}; + +static void chrSync(void) { + setchr4r(0x10, 0x0000, regs[5] & 1); + setchr4r(0x10, 0x1000, 0); +} + +static void Sync(void) { + chrSync(); +// if(regs[0xA]&0x10) +// { +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,0); + setchr1r(0x10,0x1400,1); + setchr1r(0x10,0x1800,2); + setchr1r(0x10,0x1c00,3);*/ +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1)^1)<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1)^1)<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1)^1)<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1)^1)<<2)+7); +*/ +// } +// else +// { +/* + setchr1r(0x10,0x0000,(((regs[5]&1)^1)<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1)^1)<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1)^1)<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1)^1)<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1))<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1))<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1))<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1))<<2)+7); +// } +//*/ +/* setchr1r(1,0x0000,test[0]); + setchr1r(1,0x0400,test[1]); + setchr1r(1,0x0800,test[2]); + setchr1r(1,0x0c00,test[3]); + setchr1r(1,0x1000,test[4]); + setchr1r(1,0x1400,test[5]); + setchr1r(1,0x1800,test[6]); + setchr1r(1,0x1c00,test[7]); +*/ + setprg4r(0x10, 0x6000, regs[0] & 1); + if (regs[2] >= 0x40) + setprg8r(1, 0x8000, (regs[2] - 0x40)); + else + setprg8r(0, 0x8000, (regs[2] & 0x3F)); + if (regs[3] >= 0x40) + setprg8r(1, 0xA000, (regs[3] - 0x40)); + else + setprg8r(0, 0xA000, (regs[3] & 0x3F)); + if (regs[4] >= 0x40) + setprg8r(1, 0xC000, (regs[4] - 0x40)); + else + setprg8r(0, 0xC000, (regs[4] & 0x3F)); + + setprg8r(1, 0xE000, ~0); + setmirror(MI_V); +} + +/*static DECLFW(TestWrite) +{ + test[A&7] = V; + Sync(); +}*/ + +static DECLFW(M190Write) { +// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp); + regs[(A & 0x0F00) >> 8] = V; + switch (A) { + case 0xd600: IRQLatch &= 0xFF00; IRQLatch |= V; break; + case 0xd700: IRQLatch &= 0x00FF; IRQLatch |= V << 8; break; + case 0xd900: IRQCount = IRQLatch; IRQa = V & 2; K4IRQ = V & 1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xd800: IRQa = K4IRQ; X6502_IRQEnd(FCEU_IQEXT); break; + } + Sync(); +} + +static DECLFR(M190Read) { +// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); + return regs[(A & 0x0F00) >> 8] + regs[0x0B]; +} +static void VRC5IRQ(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount & 0x10000) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } +} + +//static void Mapper190_PPU(uint32 A) +//{ +// if(A<0x2000) +// setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1); +// else +// chrSync(); +//} + +static DECLFW(M1902007Wrap) { + if (A >= 0x2000) { + if (regs[0xA] & 1) + QTAINTRAM[A & 0x1FFF] = V; + else + old2007wrap(A, V); + } +} + + +static void M190Power(void) { +/* test[0]=0; + test[1]=1; + test[2]=2; + test[3]=3; + test[4]=4; + test[5]=5; + test[6]=6; + test[7]=7; +*/ + setprg4r(0x10, 0x7000, 2); + + old2007wrap = GetWriteHandler(0x2007); + SetWriteHandler(0x2007, 0x2007, M1902007Wrap); + + SetReadHandler(0x6000, 0xFFFF, CartBR); +// SetWriteHandler(0x5000,0x5007,TestWrite); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, M190Write); + SetReadHandler(0xDC00, 0xDC00, M190Read); + SetReadHandler(0xDD00, 0xDD00, M190Read); + Sync(); +} + +static void M190Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper190_Init(CartInfo *info) { + info->Power = M190Power; + info->Close = M190Close; + GameStateRestore = StateRestore; + + MapIRQHook = VRC5IRQ; +// PPU_hook=Mapper190_PPU; + + CHRRAM = (uint8*)FCEU_gmalloc(CHRSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRSIZE, 1); + AddExState(CHRRAM, CHRSIZE, 0, "CRAM"); + + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE - 4096; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/vrc6.cpp b/branches/fceux-2.2.2/src/boards/vrc6.cpp new file mode 100644 index 00000000..66b45651 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/vrc6.cpp @@ -0,0 +1,377 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 + * + * VRC-6 + * + */ + +#include "mapinc.h" + +static uint8 is26; +static uint8 prg[2], chr[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static int32 IRQCount, CycleCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { prg, 2, "PRG" }, + { chr, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQd, 1, "IRQD" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQCount, 4, "IRQC" }, + { &CycleCount, 4, "CYCC" }, + { 0 } +}; + +static void(*sfun[3]) (void); +static uint8 vpsg1[8]; +static uint8 vpsg2[4]; +static int32 cvbc[3]; +static int32 vcount[3]; +static int32 dcount[2]; + +static SFORMAT SStateRegs[] = +{ + { vpsg1, 8, "PSG1" }, + { vpsg2, 4, "PSG2" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + if (is26) + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, prg[0]); + setprg8(0xc000, prg[1]); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(VRC6SW) { + A &= 0xF003; + if (A >= 0x9000 && A <= 0x9002) { + vpsg1[A & 3] = V; + if (sfun[0]) sfun[0](); + } else if (A >= 0xA000 && A <= 0xA002) { + vpsg1[4 | (A & 3)] = V; + if (sfun[1]) sfun[1](); + } else if (A >= 0xB000 && A <= 0xB002) { + vpsg2[A & 3] = V; + if (sfun[2]) sfun[2](); + } +} + +static DECLFW(VRC6Write) { + if (is26) + A = (A & 0xFFFC) | ((A >> 1) & 1) | ((A << 1) & 2); + if (A >= 0x9000 && A <= 0xB002) { + VRC6SW(A, V); + return; + } + switch (A & 0xF003) { + case 0x8000: prg[0] = V; Sync(); break; + case 0xB003: mirr = (V >> 2) & 3; Sync(); break; + case 0xC000: prg[1] = V; Sync(); break; + case 0xD000: chr[0] = V; Sync(); break; + case 0xD001: chr[1] = V; Sync(); break; + case 0xD002: chr[2] = V; Sync(); break; + case 0xD003: chr[3] = V; Sync(); break; + case 0xE000: chr[4] = V; Sync(); break; + case 0xE001: chr[5] = V; Sync(); break; + case 0xE002: chr[6] = V; Sync(); break; + case 0xE003: chr[7] = V; Sync(); break; + case 0xF000: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF001: + IRQa = V & 2; + IRQd = V & 1; + if (V & 2) + IRQCount = IRQLatch; + CycleCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF002: + IRQa = IRQd; + X6502_IRQEnd(FCEU_IQEXT); + } +} + +static void VRC6Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, VRC6Write); +} + +static void VRC6IRQHook(int a) { + if (IRQa) { + CycleCount += a * 3; + while(CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 0x100) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } + } + } +} + +static void VRC6Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +// VRC6 Sound + +static void DoSQV1(void); +static void DoSQV2(void); +static void DoSawV(void); + +static INLINE void DoSQV(int x) { + int32 V; + int32 amp = (((vpsg1[x << 2] & 15) << 8) * 6 / 8) >> 4; + int32 start, end; + + start = cvbc[x]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + cvbc[x] = end; + + if (vpsg1[(x << 2) | 0x2] & 0x80) { + if (vpsg1[x << 2] & 0x80) { + for (V = start; V < end; V++) + Wave[V >> 4] += amp; + } else { + int32 thresh = (vpsg1[x << 2] >> 4) & 7; + int32 freq = ((vpsg1[(x << 2) | 0x1] | ((vpsg1[(x << 2) | 0x2] & 15) << 8)) + 1) << 17; + for (V = start; V < end; V++) { + if (dcount[x] > thresh) + Wave[V >> 4] += amp; + vcount[x] -= nesincsize; + while (vcount[x] <= 0) { + vcount[x] += freq; + dcount[x] = (dcount[x] + 1) & 15; + } + } + } + } +} + +static void DoSQV1(void) { + DoSQV(0); +} + +static void DoSQV2(void) { + DoSQV(1); +} + +static void DoSawV(void) { + int V; + int32 start, end; + + start = cvbc[2]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + cvbc[2] = end; + + if (vpsg2[2] & 0x80) { + static int32 saw1phaseacc = 0; + uint32 freq3; + static uint8 b3 = 0; + static int32 phaseacc = 0; + static uint32 duff = 0; + + freq3 = (vpsg2[1] + ((vpsg2[2] & 15) << 8) + 1); + + for (V = start; V < end; V++) { + saw1phaseacc -= nesincsize; + if (saw1phaseacc <= 0) { + int32 t; + rea: + t = freq3; + t <<= 18; + saw1phaseacc += t; + phaseacc += vpsg2[0] & 0x3f; + b3++; + if (b3 == 7) { + b3 = 0; + phaseacc = 0; + } + if (saw1phaseacc <= 0) + goto rea; + duff = (((phaseacc >> 3) & 0x1f) << 4) * 6 / 8; + } + Wave[V >> 4] += duff; + } + } +} + +static INLINE void DoSQVHQ(int x) { + int32 V; + int32 amp = ((vpsg1[x << 2] & 15) << 8) * 6 / 8; + + if (vpsg1[(x << 2) | 0x2] & 0x80) { + if (vpsg1[x << 2] & 0x80) { + for (V = cvbc[x]; V < (int)SOUNDTS; V++) + WaveHi[V] += amp; + } else { + int32 thresh = (vpsg1[x << 2] >> 4) & 7; + for (V = cvbc[x]; V < (int)SOUNDTS; V++) { + if (dcount[x] > thresh) + WaveHi[V] += amp; + vcount[x]--; + if (vcount[x] <= 0) { + vcount[x] = (vpsg1[(x << 2) | 0x1] | ((vpsg1[(x << 2) | 0x2] & 15) << 8)) + 1; + dcount[x] = (dcount[x] + 1) & 15; + } + } + } + } + cvbc[x] = SOUNDTS; +} + +static void DoSQV1HQ(void) { + DoSQVHQ(0); +} + +static void DoSQV2HQ(void) { + DoSQVHQ(1); +} + +static void DoSawVHQ(void) { + static uint8 b3 = 0; + static int32 phaseacc = 0; + int32 V; + + if (vpsg2[2] & 0x80) { + for (V = cvbc[2]; V < (int)SOUNDTS; V++) { + WaveHi[V] += (((phaseacc >> 3) & 0x1f) << 8) * 6 / 8; + vcount[2]--; + if (vcount[2] <= 0) { + vcount[2] = (vpsg2[1] + ((vpsg2[2] & 15) << 8) + 1) << 1; + phaseacc += vpsg2[0] & 0x3f; + b3++; + if (b3 == 7) { + b3 = 0; + phaseacc = 0; + } + } + } + } + cvbc[2] = SOUNDTS; +} + + +void VRC6Sound(int Count) { + int x; + + DoSQV1(); + DoSQV2(); + DoSawV(); + for (x = 0; x < 3; x++) + cvbc[x] = Count; +} + +void VRC6SoundHQ(void) { + DoSQV1HQ(); + DoSQV2HQ(); + DoSawVHQ(); +} + +void VRC6SyncHQ(int32 ts) { + int x; + for (x = 0; x < 3; x++) cvbc[x] = ts; +} + +static void VRC6_ESI(void) { + GameExpSound.RChange = VRC6_ESI; + GameExpSound.Fill = VRC6Sound; + GameExpSound.HiFill = VRC6SoundHQ; + GameExpSound.HiSync = VRC6SyncHQ; + + memset(cvbc, 0, sizeof(cvbc)); + memset(vcount, 0, sizeof(vcount)); + memset(dcount, 0, sizeof(dcount)); + if (FSettings.SndRate) { + if (FSettings.soundq >= 1) { + sfun[0] = DoSQV1HQ; + sfun[1] = DoSQV2HQ; + sfun[2] = DoSawVHQ; + } else { + sfun[0] = DoSQV1; + sfun[1] = DoSQV2; + sfun[2] = DoSawV; + } + } else + memset(sfun, 0, sizeof(sfun)); + AddExState(&SStateRegs, ~0, 0, 0); +} + +// VRC6 Sound + +void Mapper24_Init(CartInfo *info) { + is26 = 0; + info->Power = VRC6Power; + MapIRQHook = VRC6IRQHook; + VRC6_ESI(); + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper26_Init(CartInfo *info) { + is26 = 1; + info->Power = VRC6Power; + info->Close = VRC6Close; + MapIRQHook = VRC6IRQHook; + VRC6_ESI(); + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + +void NSFVRC6_Init(void) { + VRC6_ESI(); + SetWriteHandler(0x8000, 0xbfff, VRC6SW); +} diff --git a/branches/fceux-2.2.2/src/boards/vrc7.cpp b/branches/fceux-2.2.2/src/boards/vrc7.cpp new file mode 100644 index 00000000..39154efa --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/vrc7.cpp @@ -0,0 +1,202 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * + * 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 "mapinc.h" + +static uint8 vrc7idx, preg[3], creg[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static int32 IRQCount, CycleCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &vrc7idx, 1, "VRCI" }, + { preg, 3, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQd, 1, "IRQD" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQCount, 4, "IRQC" }, + { &CycleCount, 4, "CYCC" }, + { 0 } +}; + +// VRC7 Sound + +#include "emu2413.h" + +static int32 dwave = 0; +static OPLL *VRC7Sound = NULL; + +void DoVRC7Sound(void) { + int32 z, a; + if (FSettings.soundq >= 1) + return; + z = ((SOUNDTS << 16) / soundtsinc) >> 4; + a = z - dwave; + OPLL_fillbuf(VRC7Sound, &Wave[dwave], a, 1); + dwave += a; +} + +void UpdateOPLNEO(int32 *Wave, int Count) { + OPLL_fillbuf(VRC7Sound, Wave, Count, 4); +} + +void UpdateOPL(int Count) { + int32 z, a; + z = ((SOUNDTS << 16) / soundtsinc) >> 4; + a = z - dwave; + if (VRC7Sound && a) + OPLL_fillbuf(VRC7Sound, &Wave[dwave], a, 1); + dwave = 0; +} + +static void VRC7SC(void) { + if (VRC7Sound) + OPLL_set_rate(VRC7Sound, FSettings.SndRate); +} + +static void VRC7SKill(void) { + if (VRC7Sound) + OPLL_delete(VRC7Sound); + VRC7Sound = NULL; +} + +static void VRC7_ESI(void) { + GameExpSound.RChange = VRC7SC; + GameExpSound.Kill = VRC7SKill; + VRC7Sound = OPLL_new(3579545, FSettings.SndRate ? FSettings.SndRate : 44100); + OPLL_reset(VRC7Sound); + OPLL_reset(VRC7Sound); +} + +// VRC7 Sound + +static void Sync(void) { + uint8 i; + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, creg[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(VRC7SW) { + if (FSettings.SndRate) { + OPLL_writeReg(VRC7Sound, vrc7idx, V); + GameExpSound.Fill = UpdateOPL; + GameExpSound.NeoFill = UpdateOPLNEO; + } +} + +static DECLFW(VRC7Write) { + A |= (A & 8) << 1; // another two-in-oooone + if (A >= 0xA000 && A <= 0xDFFF) { + A &= 0xF010; + creg[((A >> 4) & 1) | ((A - 0xA000) >> 11)] = V; + Sync(); + } else if (A == 0x9030) { + VRC7SW(A, V); + } else switch (A & 0xF010) { + case 0x8000: preg[0] = V; Sync(); break; + case 0x8010: preg[1] = V; Sync(); break; + case 0x9000: preg[2] = V; Sync(); break; + case 0x9010: vrc7idx = V; break; + case 0xE000: mirr = V & 3; Sync(); break; + case 0xE010: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF000: + IRQa = V & 2; + IRQd = V & 1; + if (V & 2) + IRQCount = IRQLatch; + CycleCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF010: + IRQa = IRQd; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void VRC7Power(void) { + Sync(); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, VRC7Write); +} + +static void VRC7Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void VRC7IRQHook(int a) { + if (IRQa) { + CycleCount += a * 3; + while(CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 0x100) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper85_Init(CartInfo *info) { + info->Power = VRC7Power; + info->Close = VRC7Close; + MapIRQHook = VRC7IRQHook; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + VRC7_ESI(); + AddExState(&StateRegs, ~0, 0, 0); +} + +void NSFVRC7_Init(void) { + SetWriteHandler(0x9010, 0x901F, VRC7Write); + SetWriteHandler(0x9030, 0x903F, VRC7Write); + VRC7_ESI(); +} diff --git a/branches/fceux-2.2.2/src/boards/vrc7p.cpp b/branches/fceux-2.2.2/src/boards/vrc7p.cpp new file mode 100644 index 00000000..5a886cb0 --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/vrc7p.cpp @@ -0,0 +1,120 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 CaH4e3 + * + * 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 + * + * YOKO Mortal Kombat V Pro, VRC7 pirate clone + */ + +#include "mapinc.h" + +static uint8 prg[3], chr[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static int32 IRQCount, CycleCount; + +static SFORMAT StateRegs[] = +{ + { prg, 3, "PRG" }, + { chr, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQd, 1, "IRQD" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQCount, 4, "IRQC" }, + { &CycleCount, 4, "CYCC" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + setprg8(0x8000, prg[0]); + setprg8(0xa000, prg[1]); + setprg8(0xc000, prg[2]); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(UNLVRC7Write) { + switch (A & 0xF008) { + case 0x8000: prg[0] = V; Sync(); break; + case 0x8008: prg[1] = V; Sync(); break; + case 0x9000: prg[2] = V; Sync(); break; + case 0xa000: chr[0] = V; Sync(); break; + case 0xa008: chr[1] = V; Sync(); break; + case 0xb000: chr[2] = V; Sync(); break; + case 0xb008: chr[3] = V; Sync(); break; + case 0xc000: chr[4] = V; Sync(); break; + case 0xc008: chr[5] = V; Sync(); break; + case 0xd000: chr[6] = V; Sync(); break; + case 0xd008: chr[7] = V; Sync(); break; + case 0xe000: mirr = V; Sync(); break; + case 0xe008: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xf000: + IRQa = V & 2; + IRQd = V & 1; + if (V & 2) + IRQCount = IRQLatch; + CycleCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf008: + if (IRQd) + IRQa = 1; + else + IRQa = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void UNLVRC7Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLVRC7Write); +} + +static void UNLVRC7IRQHook(int a) { + if (IRQa) { + CycleCount += a * 3; + while (CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 248) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLVRC7_Init(CartInfo *info) { + info->Power = UNLVRC7Power; + MapIRQHook = UNLVRC7IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/boards/yoko.cpp b/branches/fceux-2.2.2/src/boards/yoko.cpp new file mode 100644 index 00000000..d2b4e05b --- /dev/null +++ b/branches/fceux-2.2.2/src/boards/yoko.cpp @@ -0,0 +1,236 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * 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 + * + * YOKO mapper, almost the same as 83, TODO: figure out difference + * Mapper 83 - 30-in-1 mapper, two modes for single game carts, one mode for + * multigame Dragon Ball Z Party + * + * Mortal Kombat 2 YOKO + * N-CXX(M), XX - PRG+CHR, 12 - 128+256, 22 - 256+256, 14 - 128+512 + * + */ + +#include "mapinc.h" + +static uint8 mode, bank, reg[11], low[4], dip, IRQa; +static int32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static uint8 is2kbank, isnot2kbank; + +static SFORMAT StateRegs[] = +{ + { &mode, 1, "MODE" }, + { &bank, 1, "BANK" }, + { &IRQCount, 4, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { reg, 11, "REGS" }, + { low, 4, "LOWR" }, + { &is2kbank, 1, "IS2K" }, + { &isnot2kbank, 1, "NT2K" }, + { 0 } +}; + +static void UNLYOKOSync(void) { + setmirror((mode & 1) ^ 1); + setchr2(0x0000, reg[3]); + setchr2(0x0800, reg[4]); + setchr2(0x1000, reg[5]); + setchr2(0x1800, reg[6]); + if (mode & 0x10) { + uint32 base = (bank & 8) << 1; + setprg8(0x8000, (reg[0] & 0x0f) | base); + setprg8(0xA000, (reg[1] & 0x0f) | base); + setprg8(0xC000, (reg[2] & 0x0f) | base); + setprg8(0xE000, 0x0f | base); + } else { + if (mode & 8) + setprg32(0x8000, bank >> 1); + else{ + setprg16(0x8000, bank); + setprg16(0xC000, ~0); + } + } +} + +static void M83Sync(void) { + switch (mode & 3) { // check if it is truth + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } + if (is2kbank && !isnot2kbank) { + setchr2(0x0000, reg[0]); + setchr2(0x0800, reg[1]); + setchr2(0x1000, reg[6]); + setchr2(0x1800, reg[7]); + } else { + int x; + for (x = 0; x < 8; x++) + setchr1(x << 10, reg[x] | ((bank & 0x30) << 4)); + } + setprg8r(0x10, 0x6000, 0); + if (mode & 0x40) { + setprg16(0x8000, (bank & 0x3F)); // DBZ Party [p1] + setprg16(0xC000, (bank & 0x30) | 0xF); + } else { + setprg8(0x8000, reg[8]); + setprg8(0xA000, reg[9]); + setprg8(0xC000, reg[10]); + setprg8(0xE000, ~0); + } +} + +static DECLFW(UNLYOKOWrite) { + switch (A & 0x8C17) { + case 0x8000: bank = V; UNLYOKOSync(); break; + case 0x8400: mode = V; UNLYOKOSync(); break; + case 0x8800: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x8801: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break; + case 0x8c00: reg[0] = V; UNLYOKOSync(); break; + case 0x8c01: reg[1] = V; UNLYOKOSync(); break; + case 0x8c02: reg[2] = V; UNLYOKOSync(); break; + case 0x8c10: reg[3] = V; UNLYOKOSync(); break; + case 0x8c11: reg[4] = V; UNLYOKOSync(); break; + case 0x8c16: reg[5] = V; UNLYOKOSync(); break; + case 0x8c17: reg[6] = V; UNLYOKOSync(); break; + } +} + +static DECLFW(M83Write) { + switch (A) { + case 0x8000: is2kbank = 1; + case 0xB000: // Dragon Ball Z Party [p1] BMC + case 0xB0FF: // Dragon Ball Z Party [p1] BMC + case 0xB1FF: bank = V; mode |= 0x40; M83Sync(); break; // Dragon Ball Z Party [p1] BMC + case 0x8100: mode = V | (mode & 0x40); M83Sync(); break; + case 0x8200: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x8201: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break; + case 0x8300: reg[8] = V; mode &= 0xBF; M83Sync(); break; + case 0x8301: reg[9] = V; mode &= 0xBF; M83Sync(); break; + case 0x8302: reg[10] = V; mode &= 0xBF; M83Sync(); break; + case 0x8310: reg[0] = V; M83Sync(); break; + case 0x8311: reg[1] = V; M83Sync(); break; + case 0x8312: reg[2] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8313: reg[3] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8314: reg[4] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8315: reg[5] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8316: reg[6] = V; M83Sync(); break; + case 0x8317: reg[7] = V; M83Sync(); break; + } +} + +static DECLFR(UNLYOKOReadDip) { + return (X.DB & 0xFC) | dip; +} + +static DECLFR(UNLYOKOReadLow) { + return low[A & 3]; +} + +static DECLFW(UNLYOKOWriteLow) { + low[A & 3] = V; +} + +static void UNLYOKOPower(void) { + mode = bank = 0; + dip = 3; + UNLYOKOSync(); + SetReadHandler(0x5000, 0x53FF, UNLYOKOReadDip); + SetReadHandler(0x5400, 0x5FFF, UNLYOKOReadLow); + SetWriteHandler(0x5400, 0x5FFF, UNLYOKOWriteLow); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLYOKOWrite); +} + +static void M83Power(void) { + is2kbank = 0; + isnot2kbank = 0; + mode = bank = 0; + dip = 0; + M83Sync(); + SetReadHandler(0x5000, 0x5000, UNLYOKOReadDip); + SetReadHandler(0x5100, 0x5103, UNLYOKOReadLow); + SetWriteHandler(0x5100, 0x5103, UNLYOKOWriteLow); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); // Pirate Dragon Ball Z Party [p1] used if for saves instead of seraial EEPROM + SetReadHandler(0x8000, 0xffff, CartBR); + SetWriteHandler(0x8000, 0xffff, M83Write); +} + +static void UNLYOKOReset(void) { + dip = (dip + 1) & 3; + mode = bank = 0; + UNLYOKOSync(); +} + +static void M83Reset(void) { + dip ^= 1; + M83Sync(); +} + +static void M83Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void UNLYOKOIRQHook(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount < 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0xFFFF; + } + } +} + +static void UNLYOKOStateRestore(int version) { + UNLYOKOSync(); +} + +static void M83StateRestore(int version) { + M83Sync(); +} + +void UNLYOKO_Init(CartInfo *info) { + info->Power = UNLYOKOPower; + info->Reset = UNLYOKOReset; + MapIRQHook = UNLYOKOIRQHook; + GameStateRestore = UNLYOKOStateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper83_Init(CartInfo *info) { + info->Power = M83Power; + info->Reset = M83Reset; + info->Close = M83Close; + MapIRQHook = UNLYOKOIRQHook; + GameStateRestore = M83StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/branches/fceux-2.2.2/src/cart.cpp b/branches/fceux-2.2.2/src/cart.cpp new file mode 100644 index 00000000..baeaba65 --- /dev/null +++ b/branches/fceux-2.2.2/src/cart.cpp @@ -0,0 +1,573 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 + */ + +/// \file +/// \brief This file contains all code for coordinating the mapping in of the address space external to the NES. + +#include "types.h" +#include "fceu.h" +#include "ppu.h" +#include "driver.h" + +#include "cart.h" +#include "x6502.h" + +#include "file.h" +#include "utils/memory.h" + + +#include +#include +#include +#include + +uint8 *Page[32], *VPage[8]; +uint8 **VPageR = VPage; +uint8 *VPageG[8]; +uint8 *MMC5SPRVPage[8]; +uint8 *MMC5BGVPage[8]; + +static uint8 PRGIsRAM[32]; /* This page is/is not PRG RAM. */ + +/* 16 are (sort of) reserved for UNIF/iNES and 16 to map other stuff. */ +uint8 CHRram[32]; +uint8 PRGram[32]; + +uint8 *PRGptr[32]; +uint8 *CHRptr[32]; + +uint32 PRGsize[32]; +uint32 CHRsize[32]; + +uint32 PRGmask2[32]; +uint32 PRGmask4[32]; +uint32 PRGmask8[32]; +uint32 PRGmask16[32]; +uint32 PRGmask32[32]; + +uint32 CHRmask1[32]; +uint32 CHRmask2[32]; +uint32 CHRmask4[32]; +uint32 CHRmask8[32]; + +int geniestage = 0; + +int modcon; + +uint8 genieval[3]; +uint8 geniech[3]; + +uint32 genieaddr[3]; + +static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram) { + uint32 AB = A >> 11; + int x; + + if (p) + for (x = (s >> 1) - 1; x >= 0; x--) { + PRGIsRAM[AB + x] = ram; + Page[AB + x] = p - A; + } + else + for (x = (s >> 1) - 1; x >= 0; x--) { + PRGIsRAM[AB + x] = 0; + Page[AB + x] = 0; + } +} + +static uint8 nothing[8192]; +void ResetCartMapping(void) { + int x; + + PPU_ResetHooks(); + + for (x = 0; x < 32; x++) { + Page[x] = nothing - x * 2048; + PRGptr[x] = CHRptr[x] = 0; + PRGsize[x] = CHRsize[x] = 0; + } + for (x = 0; x < 8; x++) { + MMC5SPRVPage[x] = MMC5BGVPage[x] = VPageR[x] = nothing - 0x400 * x; + } +} + +void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram) { + PRGptr[chip] = p; + PRGsize[chip] = size; + + PRGmask2[chip] = (size >> 11) - 1; + PRGmask4[chip] = (size >> 12) - 1; + PRGmask8[chip] = (size >> 13) - 1; + PRGmask16[chip] = (size >> 14) - 1; + PRGmask32[chip] = (size >> 15) - 1; + + PRGram[chip] = ram ? 1 : 0; +} + +void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram) { + CHRptr[chip] = p; + CHRsize[chip] = size; + + CHRmask1[chip] = (size >> 10) - 1; + CHRmask2[chip] = (size >> 11) - 1; + CHRmask4[chip] = (size >> 12) - 1; + CHRmask8[chip] = (size >> 13) - 1; + + CHRram[chip] = ram; +} + +DECLFR(CartBR) { + return Page[A >> 11][A]; +} + +DECLFW(CartBW) { + //printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]); + if (PRGIsRAM[A >> 11] && Page[A >> 11]) + Page[A >> 11][A] = V; +} + +DECLFR(CartBROB) { + if (!Page[A >> 11]) + return(X.DB); + else + return Page[A >> 11][A]; +} + +void setprg2r(int r, uint32 A, uint32 V) { + V &= PRGmask2[r]; + setpageptr(2, A, PRGptr[r] ? (&PRGptr[r][V << 11]) : 0, PRGram[r]); +} + +void setprg2(uint32 A, uint32 V) { + setprg2r(0, A, V); +} + +void setprg4r(int r, uint32 A, uint32 V) { + V &= PRGmask4[r]; + setpageptr(4, A, PRGptr[r] ? (&PRGptr[r][V << 12]) : 0, PRGram[r]); +} + +void setprg4(uint32 A, uint32 V) { + setprg4r(0, A, V); +} + +void setprg8r(int r, uint32 A, uint32 V) { + if (PRGsize[r] >= 8192) { + V &= PRGmask8[r]; + setpageptr(8, A, PRGptr[r] ? (&PRGptr[r][V << 13]) : 0, PRGram[r]); + } else { + uint32 VA = V << 2; + int x; + for (x = 0; x < 4; x++) + setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]); + } +} + +void setprg8(uint32 A, uint32 V) { + setprg8r(0, A, V); +} + +void setprg16r(int r, uint32 A, uint32 V) { + if (PRGsize[r] >= 16384) { + V &= PRGmask16[r]; + setpageptr(16, A, PRGptr[r] ? (&PRGptr[r][V << 14]) : 0, PRGram[r]); + } else { + uint32 VA = V << 3; + int x; + + for (x = 0; x < 8; x++) + setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]); + } +} + +void setprg16(uint32 A, uint32 V) { + setprg16r(0, A, V); +} + +void setprg32r(int r, uint32 A, uint32 V) { + if (PRGsize[r] >= 32768) { + V &= PRGmask32[r]; + setpageptr(32, A, PRGptr[r] ? (&PRGptr[r][V << 15]) : 0, PRGram[r]); + } else { + uint32 VA = V << 4; + int x; + + for (x = 0; x < 16; x++) + setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]); + } +} + +void setprg32(uint32 A, uint32 V) { + setprg32r(0, A, V); +} + +void setchr1r(int r, uint32 A, uint32 V) { + if (!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V &= CHRmask1[r]; + if (CHRram[r]) + PPUCHRRAM |= (1 << (A >> 10)); + else + PPUCHRRAM &= ~(1 << (A >> 10)); + VPageR[(A) >> 10] = &CHRptr[r][(V) << 10] - (A); +} + +void setchr2r(int r, uint32 A, uint32 V) { + if (!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V &= CHRmask2[r]; + VPageR[(A) >> 10] = VPageR[((A) >> 10) + 1] = &CHRptr[r][(V) << 11] - (A); + if (CHRram[r]) + PPUCHRRAM |= (3 << (A >> 10)); + else + PPUCHRRAM &= ~(3 << (A >> 10)); +} + +void setchr4r(int r, unsigned int A, unsigned int V) { + if (!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V &= CHRmask4[r]; + VPageR[(A) >> 10] = VPageR[((A) >> 10) + 1] = + VPageR[((A) >> 10) + 2] = VPageR[((A) >> 10) + 3] = &CHRptr[r][(V) << 12] - (A); + if (CHRram[r]) + PPUCHRRAM |= (15 << (A >> 10)); + else + PPUCHRRAM &= ~(15 << (A >> 10)); +} + +void setchr8r(int r, uint32 V) { + int x; + + if (!CHRptr[r]) return; + FCEUPPU_LineUpdate(); + V &= CHRmask8[r]; + for (x = 7; x >= 0; x--) + VPageR[x] = &CHRptr[r][V << 13]; + if (CHRram[r]) + PPUCHRRAM |= (255); + else + PPUCHRRAM = 0; +} + +void setchr1(uint32 A, uint32 V) { + setchr1r(0, A, V); +} + +void setchr2(uint32 A, uint32 V) { + setchr2r(0, A, V); +} + +void setchr4(uint32 A, uint32 V) { + setchr4r(0, A, V); +} + +void setchr8(uint32 V) { + setchr8r(0, V); +} + +/* This function can be called without calling SetupCartMirroring(). */ + +void setntamem(uint8 *p, int ram, uint32 b) { + FCEUPPU_LineUpdate(); + vnapage[b] = p; + PPUNTARAM &= ~(1 << b); + if (ram) + PPUNTARAM |= 1 << b; +} + +static int mirrorhard = 0; +void setmirrorw(int a, int b, int c, int d) { + FCEUPPU_LineUpdate(); + vnapage[0] = NTARAM + a * 0x400; + vnapage[1] = NTARAM + b * 0x400; + vnapage[2] = NTARAM + c * 0x400; + vnapage[3] = NTARAM + d * 0x400; +} + +void setmirror(int t) { + FCEUPPU_LineUpdate(); + if (!mirrorhard) { + switch (t) { + case MI_H: + vnapage[0] = vnapage[1] = NTARAM; vnapage[2] = vnapage[3] = NTARAM + 0x400; + break; + case MI_V: + vnapage[0] = vnapage[2] = NTARAM; vnapage[1] = vnapage[3] = NTARAM + 0x400; + break; + case MI_0: + vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = NTARAM; + break; + case MI_1: + vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = NTARAM + 0x400; + break; + } + PPUNTARAM = 0xF; + } +} + +void SetupCartMirroring(int m, int hard, uint8 *extra) { + if (m < 4) { + mirrorhard = 0; + setmirror(m); + } else { + vnapage[0] = NTARAM; + vnapage[1] = NTARAM + 0x400; + vnapage[2] = extra; + vnapage[3] = extra + 0x400; + PPUNTARAM = 0xF; + } + mirrorhard = hard; +} + +static uint8 *GENIEROM = 0; + +void FixGenieMap(void); + +// Called when a game(file) is opened successfully. Returns TRUE on error. +bool FCEU_OpenGenie(void) +{ + FILE *fp; + int x; + + if (!GENIEROM) + { + char *fn; + + if (!(GENIEROM = (uint8*)FCEU_malloc(4096 + 1024))) + return true; + + fn = strdup(FCEU_MakeFName(FCEUMKF_GGROM, 0, 0).c_str()); + fp = FCEUD_UTF8fopen(fn, "rb"); + if (!fp) + { + FCEU_PrintError("Error opening Game Genie ROM image!\nIt should be named \"gg.rom\"!"); + free(GENIEROM); + GENIEROM = 0; + return true; + } + if (fread(GENIEROM, 1, 16, fp) != 16) + { + grerr: + FCEU_PrintError("Error reading from Game Genie ROM image!"); + free(GENIEROM); + GENIEROM = 0; + fclose(fp); + return true; + } + if (GENIEROM[0] == 0x4E) + { + /* iNES ROM image */ + if (fread(GENIEROM, 1, 4096, fp) != 4096) + goto grerr; + if (fseek(fp, 16384 - 4096, SEEK_CUR)) + goto grerr; + if (fread(GENIEROM + 4096, 1, 256, fp) != 256) + goto grerr; + } else + { + if (fread(GENIEROM + 16, 1, 4352 - 16, fp) != (4352 - 16)) + goto grerr; + } + fclose(fp); + + /* Workaround for the FCE Ultra CHR page size only being 1KB */ + for (x = 0; x < 4; x++) + { + memcpy(GENIEROM + 4096 + (x << 8), GENIEROM + 4096, 256); + } + } + + geniestage = 1; + return false; +} + +/* Called when a game is closed. */ +void FCEU_CloseGenie(void) { + /* No good reason to free() the Game Genie ROM image data. */ + geniestage = 0; + FlushGenieRW(); + VPageR = VPage; +} + +void FCEU_KillGenie(void) { + if (GENIEROM) { + free(GENIEROM); + GENIEROM = 0; + } +} + +static DECLFR(GenieRead) { + return GENIEROM[A & 4095]; +} + +static DECLFW(GenieWrite) { + switch (A) { + case 0x800c: + case 0x8008: + case 0x8004: genieval[((A - 4) & 0xF) >> 2] = V; break; + + case 0x800b: + case 0x8007: + case 0x8003: geniech[((A - 3) & 0xF) >> 2] = V; break; + + case 0x800a: + case 0x8006: + case 0x8002: genieaddr[((A - 2) & 0xF) >> 2] &= 0xFF00; genieaddr[((A - 2) & 0xF) >> 2] |= V; break; + + case 0x8009: + case 0x8005: + case 0x8001: genieaddr[((A - 1) & 0xF) >> 2] &= 0xFF; genieaddr[((A - 1) & 0xF) >> 2] |= (V | 0x80) << 8; break; + + case 0x8000: + if (!V) + FixGenieMap(); + else { + modcon = V ^ 0xFF; + if (V == 0x71) + modcon = 0; + } + break; + } +} + +static readfunc GenieBackup[3]; + +static DECLFR(GenieFix1) { + uint8 r = GenieBackup[0](A); + + if ((modcon >> 1) & 1) // No check + return genieval[0]; + else if (r == geniech[0]) + return genieval[0]; + + return r; +} + +static DECLFR(GenieFix2) { + uint8 r = GenieBackup[1](A); + + if ((modcon >> 2) & 1) // No check + return genieval[1]; + else if (r == geniech[1]) + return genieval[1]; + + return r; +} + +static DECLFR(GenieFix3) { + uint8 r = GenieBackup[2](A); + + if ((modcon >> 3) & 1) // No check + return genieval[2]; + else if (r == geniech[2]) + return genieval[2]; + + return r; +} + + +void FixGenieMap(void) { + int x; + + geniestage = 2; + + for (x = 0; x < 8; x++) + VPage[x] = VPageG[x]; + + VPageR = VPage; + FlushGenieRW(); + //printf("Rightyo\n"); + for (x = 0; x < 3; x++) + if ((modcon >> (4 + x)) & 1) { + readfunc tmp[3] = { GenieFix1, GenieFix2, GenieFix3 }; + GenieBackup[x] = GetReadHandler(genieaddr[x]); + SetReadHandler(genieaddr[x], genieaddr[x], tmp[x]); + } +} + +void FCEU_GeniePower(void) { + uint32 x; + + if (!geniestage) + return; + + geniestage = 1; + for (x = 0; x < 3; x++) { + genieval[x] = 0xFF; + geniech[x] = 0xFF; + genieaddr[x] = 0xFFFF; + } + modcon = 0; + + SetWriteHandler(0x8000, 0xFFFF, GenieWrite); + SetReadHandler(0x8000, 0xFFFF, GenieRead); + + for (x = 0; x < 8; x++) + VPage[x] = GENIEROM + 4096 - 0x400 * x; + + if (AllocGenieRW()) + VPageR = VPageG; + else + geniestage = 2; +} + + +void FCEU_SaveGameSave(CartInfo *LocalHWInfo) { + if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { + FILE *sp; + + std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); + if ((sp = FCEUD_UTF8fopen(soot, "wb")) == NULL) { + FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n", soot.c_str()); + } else { + for (int x = 0; x < 4; x++) + if (LocalHWInfo->SaveGame[x]) { + fwrite(LocalHWInfo->SaveGame[x], 1, + LocalHWInfo->SaveGameLen[x], sp); + } + } + } +} + +// hack, movie.cpp has to communicate with this function somehow +int disableBatteryLoading = 0; + +void FCEU_LoadGameSave(CartInfo *LocalHWInfo) { + if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading) { + FILE *sp; + + std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); + sp = FCEUD_UTF8fopen(soot, "rb"); + if (sp != NULL) { + for (int x = 0; x < 4; x++) + if (LocalHWInfo->SaveGame[x]) + fread(LocalHWInfo->SaveGame[x], 1, LocalHWInfo->SaveGameLen[x], sp); + } + } +} + +//clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though) +void FCEU_ClearGameSave(CartInfo *LocalHWInfo) { + if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { + for (int x = 0; x < 4; x++) + if (LocalHWInfo->SaveGame[x]) + memset(LocalHWInfo->SaveGame[x], 0, LocalHWInfo->SaveGameLen[x]); + } +} diff --git a/branches/fceux-2.2.2/src/cart.h b/branches/fceux-2.2.2/src/cart.h new file mode 100644 index 00000000..e5670c54 --- /dev/null +++ b/branches/fceux-2.2.2/src/cart.h @@ -0,0 +1,94 @@ +typedef struct { + // Set by mapper/board code: + void (*Power)(void); + void (*Reset)(void); + void (*Close)(void); + uint8 *SaveGame[4]; // Pointers to memory to save/load. + uint32 SaveGameLen[4]; // How much memory to save/load. + + // Set by iNES/UNIF loading code. + int mirror; // As set in the header or chunk. + // iNES/UNIF specific. Intended + // to help support games like "Karnov" + // that are not really MMC3 but are + // set to mapper 4. + int battery; // Presence of an actual battery. + uint8 MD5[16]; + uint32 CRC32; // Should be set by the iNES/UNIF loading + // code, used by mapper/board code, maybe + // other code in the future. +} CartInfo; + +void FCEU_SaveGameSave(CartInfo *LocalHWInfo); +void FCEU_LoadGameSave(CartInfo *LocalHWInfo); +void FCEU_ClearGameSave(CartInfo *LocalHWInfo); + +extern uint8 *Page[32], *VPage[8], *MMC5SPRVPage[8], *MMC5BGVPage[8]; + +void ResetCartMapping(void); +void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram); +void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram); +void SetupCartMirroring(int m, int hard, uint8 *extra); + +DECLFR(CartBROB); +DECLFR(CartBR); +DECLFW(CartBW); + +extern uint8 PRGram[32]; +extern uint8 CHRram[32]; + +extern uint8 *PRGptr[32]; +extern uint8 *CHRptr[32]; + +extern uint32 PRGsize[32]; +extern uint32 CHRsize[32]; + +extern uint32 PRGmask2[32]; +extern uint32 PRGmask4[32]; +extern uint32 PRGmask8[32]; +extern uint32 PRGmask16[32]; +extern uint32 PRGmask32[32]; + +extern uint32 CHRmask1[32]; +extern uint32 CHRmask2[32]; +extern uint32 CHRmask4[32]; +extern uint32 CHRmask8[32]; + +void setprg2(uint32 A, uint32 V); +void setprg4(uint32 A, uint32 V); +void setprg8(uint32 A, uint32 V); +void setprg16(uint32 A, uint32 V); +void setprg32(uint32 A, uint32 V); + +void setprg2r(int r, unsigned int A, unsigned int V); +void setprg4r(int r, unsigned int A, unsigned int V); +void setprg8r(int r, unsigned int A, unsigned int V); +void setprg16r(int r, unsigned int A, unsigned int V); +void setprg32r(int r, unsigned int A, unsigned int V); + +void setchr1r(int r, unsigned int A, unsigned int V); +void setchr2r(int r, unsigned int A, unsigned int V); +void setchr4r(int r, unsigned int A, unsigned int V); +void setchr8r(int r, unsigned int V); + +void setchr1(unsigned int A, unsigned int V); +void setchr2(unsigned int A, unsigned int V); +void setchr4(unsigned int A, unsigned int V); +void setchr8(unsigned int V); + +void setmirror(int t); +void setmirrorw(int a, int b, int c, int d); +void setntamem(uint8 *p, int ram, uint32 b); + +#define MI_H 0 +#define MI_V 1 +#define MI_0 2 +#define MI_1 3 + +extern int geniestage; + +void FCEU_GeniePower(void); + +bool FCEU_OpenGenie(void); +void FCEU_CloseGenie(void); +void FCEU_KillGenie(void); diff --git a/branches/fceux-2.2.2/src/cheat.cpp b/branches/fceux-2.2.2/src/cheat.cpp new file mode 100644 index 00000000..051ecb58 --- /dev/null +++ b/branches/fceux-2.2.2/src/cheat.cpp @@ -0,0 +1,964 @@ +/* FCE Ultra - NES/Famicom Emulator +* +* Copyright notice for this file: +* Copyright (C) 2002 Xodnizel +* +* 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 "types.h" +#include "x6502.h" +#include "cheat.h" +#include "fceu.h" +#include "file.h" +#include "cart.h" +#include "driver.h" +#include "utils/memory.h" + +#include +#include +#include +#include +#include + +using namespace std; + +static uint8 *CheatRPtrs[64]; + +vector FrozenAddresses; //List of addresses that are currently frozen +void UpdateFrozenList(void); //Function that populates the list of frozen addresses +unsigned int FrozenAddressCount=0; //Keeps up with the Frozen address count, necessary for using in other dialogs (such as hex editor) + +void FCEU_CheatResetRAM(void) +{ + int x; + + for(x=0;x<64;x++) + CheatRPtrs[x]=0; +} + +void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p) +{ + uint32 AB=A>>10; + int x; + + for(x=s-1;x>=0;x--) + CheatRPtrs[AB+x]=p-A; +} + + +struct CHEATF { + struct CHEATF *next; + char *name; + uint16 addr; + uint8 val; + int compare; /* -1 for no compare. */ + int type; /* 0 for replace, 1 for substitute(GG). */ + int status; +}; + +typedef struct { + uint16 addr; + uint8 val; + int compare; + readfunc PrevRead; +} CHEATF_SUBFAST; + + +static CHEATF_SUBFAST SubCheats[256]; +static int numsubcheats=0; +struct CHEATF *cheats=0,*cheatsl=0; + + +#define CHEATC_NONE 0x8000 +#define CHEATC_EXCLUDED 0x4000 +#define CHEATC_NOSHOW 0xC000 + +static uint16 *CheatComp = 0; +int savecheats = 0; + +static DECLFR(SubCheatsRead) +{ + CHEATF_SUBFAST *s=SubCheats; + int x=numsubcheats; + + do + { + if(s->addr==A) + { + if(s->compare>=0) + { + uint8 pv=s->PrevRead(A); + + if(pv==s->compare) + return(s->val); + else return(pv); + } + else return(s->val); + } + s++; + } while(--x); + return(0); /* We should never get here. */ +} + +void RebuildSubCheats(void) +{ + int x; + struct CHEATF *c=cheats; + for(x=0;xtype==1 && c->status) + { + if(GetReadHandler(c->addr)==SubCheatsRead) + { + /* Prevent a catastrophe by this check. */ + //FCEU_DispMessage("oops",0); + } + else + { + SubCheats[numsubcheats].PrevRead=GetReadHandler(c->addr); + SubCheats[numsubcheats].addr=c->addr; + SubCheats[numsubcheats].val=c->val; + SubCheats[numsubcheats].compare=c->compare; + SetReadHandler(c->addr,c->addr,SubCheatsRead); + numsubcheats++; + } + } + c=c->next; + } + FrozenAddressCount = numsubcheats; //Update the frozen address list + UpdateFrozenList(); + //FCEUI_DispMessage("Active Cheats: %d",0, FrozenAddresses.size()/*FrozenAddressCount*/); //Debug +} + +void FCEU_PowerCheats() +{ + numsubcheats=0; /* Quick hack to prevent setting of ancient read addresses. */ + RebuildSubCheats(); +} + +static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type); +static void CheatMemErr(void) +{ + FCEUD_PrintError("Error allocating memory for cheat data."); +} + +/* This function doesn't allocate any memory for "name" */ +static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type) +{ + struct CHEATF *temp; + if(!(temp=(struct CHEATF *)FCEU_dmalloc(sizeof(struct CHEATF)))) + { + CheatMemErr(); + return(0); + } + temp->name=name; + temp->addr=addr; + temp->val=val; + temp->status=status; + temp->compare=compare; + temp->type=type; + temp->next=0; + + if(cheats) + { + cheatsl->next=temp; + cheatsl=temp; + } + else + cheats=cheatsl=temp; + + return(1); +} + +void FCEU_LoadGameCheats(FILE *override) +{ + FILE *fp; + unsigned int addr; + unsigned int val; + unsigned int status; + unsigned int type; + unsigned int compare; + int x; + + char linebuf[2048]; + char *namebuf; + int tc=0; + char *fn; + + numsubcheats=savecheats=0; + + if(override) + fp = override; + else + { + fn=strdup(FCEU_MakeFName(FCEUMKF_CHEAT,0,0).c_str()); + fp=FCEUD_UTF8fopen(fn,"rb"); + free(fn); + if(!fp) return; + } + + FCEU_DispMessage("Cheats file loaded.",0); //Tells user a cheats file was loaded. + while(fgets(linebuf,2048,fp)>0) + { + char *tbuf=linebuf; + int doc=0; + + addr=val=compare=status=type=0; + + if(tbuf[0]=='S') + { + tbuf++; + type=1; + } + else type=0; + + if(tbuf[0]=='C') + { + tbuf++; + doc=1; + } + + if(tbuf[0]==':') + { + tbuf++; + status=0; + } + else status=1; + + if(doc) + { + char *neo=&tbuf[4+2+2+1+1+1]; + if(sscanf(tbuf,"%04x%*[:]%02x%*[:]%02x",&addr,&val,&compare)!=3) + continue; + if (!(namebuf=(char *)FCEU_dmalloc(strlen(neo)+1))) + return; + strcpy(namebuf,neo); + } + else + { + char *neo=&tbuf[4+2+1+1]; + if(sscanf(tbuf,"%04x%*[:]%02x",&addr,&val)!=2) + continue; + if (!(namebuf=(char *)FCEU_dmalloc(strlen(neo)+1))) + return; + strcpy(namebuf,neo); + } + + for(x=0;x<(int)strlen(namebuf);x++) + { + if(namebuf[x]==10 || namebuf[x]==13) + { + namebuf[x]=0; + break; + } + else if(namebuf[x] > 0x00 && namebuf[x] < 0x20) + namebuf[x]=0x20; + } + + AddCheatEntry(namebuf,addr,val,doc?compare:-1,status,type); + tc++; + } + RebuildSubCheats(); + if(!override) + fclose(fp); +} + +void FCEU_FlushGameCheats(FILE *override, int nosave) +{ + if(CheatComp) + { + free(CheatComp); + CheatComp=0; + } + if((!savecheats || nosave) && !override) /* Always save cheats if we're being overridden. */ + { + if(cheats) + { + struct CHEATF *next=cheats; + for(;;) + { + struct CHEATF *last=next; + next=next->next; + free(last->name); + free(last); + if(!next) break; + } + cheats=cheatsl=0; + } + } + else + { + char *fn = 0; + + if(!override) + fn = strdup(FCEU_MakeFName(FCEUMKF_CHEAT,0,0).c_str()); + + if(cheats) + { + struct CHEATF *next=cheats; + FILE *fp; + + if(override) + fp = override; + else + fp=FCEUD_UTF8fopen(fn,"wb"); + + if(fp) + { + for(;;) + { + struct CHEATF *t; + if(next->type) + fputc('S',fp); + if(next->compare>=0) + fputc('C',fp); + + if(!next->status) + fputc(':',fp); + + if(next->compare>=0) + fprintf(fp,"%04x:%02x:%02x:%s\n",next->addr,next->val,next->compare,next->name); + else + fprintf(fp,"%04x:%02x:%s\n",next->addr,next->val,next->name); + + free(next->name); + t=next; + next=next->next; + free(t); + if(!next) break; + } + if(!override) + fclose(fp); + } + else + FCEUD_PrintError("Error saving cheats."); + cheats=cheatsl=0; + } + else if(!override) + remove(fn); + if(!override) + free(fn); + } + + RebuildSubCheats(); /* Remove memory handlers. */ + +} + + +int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type) +{ + char *t; + + if(!(t=(char *)FCEU_dmalloc(strlen(name)+1))) + { + CheatMemErr(); + return(0); + } + strcpy(t,name); + if(!AddCheatEntry(t,addr,val,compare,1,type)) + { + free(t); + return(0); + } + savecheats=1; + RebuildSubCheats(); + + return(1); +} + +int FCEUI_DelCheat(uint32 which) +{ + struct CHEATF *prev; + struct CHEATF *cur; + uint32 x=0; + + for(prev=0,cur=cheats;;) + { + if(x==which) // Remove this cheat. + { + if(prev) // Update pointer to this cheat. + { + if(cur->next) // More cheats. + prev->next=cur->next; + else // No more. + { + prev->next=0; + cheatsl=prev; // Set the previous cheat as the last cheat. + } + } + else // This is the first cheat. + { + if(cur->next) // More cheats + cheats=cur->next; + else + cheats=cheatsl=0; // No (more) cheats. + } + free(cur->name); // Now that all references to this cheat are removed, + free(cur); // free the memory. + break; + } // *END REMOVE THIS CHEAT* + + + if(!cur->next) // No more cheats to go through(this shouldn't ever happen...) + return(0); + prev=cur; + cur=prev->next; + x++; + } + + savecheats=1; + RebuildSubCheats(); + return(1); +} + +void FCEU_ApplyPeriodicCheats(void) +{ + struct CHEATF *cur=cheats; + if(!cur) return; + + for(;;) + { + if(cur->status && !(cur->type)) + if(CheatRPtrs[cur->addr>>10]) + CheatRPtrs[cur->addr>>10][cur->addr]=cur->val; + if(cur->next) + cur=cur->next; + else + break; + } +} + + +void FCEUI_ListCheats(int (*callb)(char *name, uint32 a, uint8 v, int compare, int s, int type, void *data), void *data) +{ + struct CHEATF *next=cheats; + + while(next) + { + if(!callb(next->name,next->addr,next->val,next->compare,next->status,next->type,data)) break; + next=next->next; + } +} + +int FCEUI_GetCheat(uint32 which, char **name, uint32 *a, uint8 *v, int *compare, int *s, int *type) +{ + struct CHEATF *next=cheats; + uint32 x=0; + + while(next) + { + if(x==which) + { + if(name) + *name=next->name; + if(a) + *a=next->addr; + if(v) + *v=next->val; + if(s) + *s=next->status; + if(compare) + *compare=next->compare; + if(type) + *type=next->type; + return(1); + } + next=next->next; + x++; + } + return(0); +} + +static int GGtobin(char c) +{ + static char lets[16]={'A','P','Z','L','G','I','T','Y','E','O','X','U','K','S','V','N'}; + int x; + + for(x=0;x<16;x++) + if(lets[x] == toupper(c)) return(x); + return(0); +} + +/* Returns 1 on success, 0 on failure. Sets *a,*v,*c. */ +int FCEUI_DecodeGG(const char *str, int *a, int *v, int *c) +{ + uint16 A; + uint8 V,C; + uint8 t; + int s; + + A=0x8000; + V=0; + C=0; + + s=strlen(str); + if(s!=6 && s!=8) return(0); + + t=GGtobin(*str++); + V|=(t&0x07); + V|=(t&0x08)<<4; + + t=GGtobin(*str++); + V|=(t&0x07)<<4; + A|=(t&0x08)<<4; + + t=GGtobin(*str++); + A|=(t&0x07)<<4; + //if(t&0x08) return(0); /* 8-character code?! */ + + t=GGtobin(*str++); + A|=(t&0x07)<<12; + A|=(t&0x08); + + t=GGtobin(*str++); + A|=(t&0x07); + A|=(t&0x08)<<8; + + if(s==6) + { + t=GGtobin(*str++); + A|=(t&0x07)<<8; + V|=(t&0x08); + + *a=A; + *v=V; + *c=-1; + return(1); + } + else + { + t=GGtobin(*str++); + A|=(t&0x07)<<8; + C|=(t&0x08); + + t=GGtobin(*str++); + C|=(t&0x07); + C|=(t&0x08)<<4; + + t=GGtobin(*str++); + C|=(t&0x07)<<4; + V|=(t&0x08); + *a=A; + *v=V; + *c=C; + return(1); + } + return(0); +} + +int FCEUI_DecodePAR(const char *str, int *a, int *v, int *c, int *type) +{ + int boo[4]; + if(strlen(str)!=8) return(0); + + sscanf(str,"%02x%02x%02x%02x",boo,boo+1,boo+2,boo+3); + + *c=-1; + + if(1) + { + *a=(boo[3]<<8)|(boo[2]+0x7F); + *v=0; + } + else + { + *v=boo[3]; + *a=boo[2]|(boo[1]<<8); + } + /* Zero-page addressing modes don't go through the normal read/write handlers in FCEU, so + we must do the old hacky method of RAM cheats. + */ + if(*a<0x0100) + *type=0; + else + *type=1; + return(1); +} + +/* name can be NULL if the name isn't going to be changed. */ +/* same goes for a, v, and s(except the values of each one must be <0) */ + +int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int c, int s, int type) +{ + struct CHEATF *next=cheats; + uint32 x=0; + + while(next) + { + if(x==which) + { + if(name) + { + char *t; + if((t=(char *)realloc(next->name, strlen(name)+1))) + { + next->name=t; + strcpy(next->name,name); + } + else + return(0); + } + if(a>=0) + next->addr=a; + if(v>=0) + next->val=v; + if(s>=0) + next->status=s; + if(c>=-1) + next->compare=c; + next->type=type; + + savecheats=1; + RebuildSubCheats(); + + return(1); + } + next=next->next; + x++; + } + return(0); +} + +/* Convenience function. */ +int FCEUI_ToggleCheat(uint32 which) +{ + struct CHEATF *next=cheats; + uint32 x=0; + + while(next) + { + if(x==which) + { + next->status=!next->status; + savecheats=1; + RebuildSubCheats(); + return(next->status); + } + next=next->next; + x++; + } + + return(-1); +} + +static int InitCheatComp(void) +{ + uint32 x; + + CheatComp=(uint16*)FCEU_dmalloc(65536*sizeof(uint16)); + if(!CheatComp) + { + CheatMemErr(); + return(0); + } + for(x=0;x<65536;x++) + CheatComp[x]=CHEATC_NONE; + + return(1); +} + +void FCEUI_CheatSearchSetCurrentAsOriginal(void) +{ + uint32 x; + + if(!CheatComp) + { + if(InitCheatComp()) + { + CheatMemErr(); + return; + } + } + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CheatRPtrs[x>>10]) + CheatComp[x]=CheatRPtrs[x>>10][x]; + else + CheatComp[x]|=CHEATC_NONE; + } +} + +void FCEUI_CheatSearchShowExcluded(void) +{ + uint32 x; + + for(x=0x000;x<0x10000;x++) + CheatComp[x]&=~CHEATC_EXCLUDED; +} + + +int32 FCEUI_CheatSearchGetCount(void) +{ + uint32 x,c=0; + + if(CheatComp) + { + for(x=0x0000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10]) + c++; + } + + return c; +} +/* This function will give the initial value of the search and the current value at a location. */ + +void FCEUI_CheatSearchGet(int (*callb)(uint32 a, uint8 last, uint8 current, void *data),void *data) +{ + uint32 x; + + if(!CheatComp) + { + if(!InitCheatComp()) + CheatMemErr(); + return; + } + + for(x=0;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10]) + if(!callb(x,CheatComp[x],CheatRPtrs[x>>10][x],data)) + break; +} + +void FCEUI_CheatSearchGetRange(uint32 first, uint32 last, int (*callb)(uint32 a, uint8 last, uint8 current)) +{ + uint32 x; + uint32 in=0; + + if(!CheatComp) + { + if(!InitCheatComp()) + CheatMemErr(); + return; + } + + for(x=0;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10]) + { + if(in>=first) + if(!callb(x,CheatComp[x],CheatRPtrs[x>>10][x])) + break; + in++; + if(in>last) return; + } +} + +void FCEUI_CheatSearchBegin(void) +{ + uint32 x; + + if(!CheatComp) + { + if(!InitCheatComp()) + { + CheatMemErr(); + return; + } + } + for(x=0;x<0x10000;x++) + { + if(CheatRPtrs[x>>10]) + CheatComp[x]=CheatRPtrs[x>>10][x]; + else + CheatComp[x]=CHEATC_NONE; + } +} + + +static int INLINE CAbs(int x) +{ + if(x<0) + return(0-x); + return x; +} + +void FCEUI_CheatSearchEnd(int type, uint8 v1, uint8 v2) +{ + uint32 x; + + if(!CheatComp) + { + if(!InitCheatComp()) + { + CheatMemErr(); + return; + } + } + + + if(!type) // Change to a specific value. + { + for(x=0;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CheatComp[x]==v1 && CheatRPtrs[x>>10][x]==v2) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + } + else if(type==1) // Search for relative change(between values). + { + for(x=0;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CheatComp[x]==v1 && CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + } + else if(type==2) // Purely relative change. + { + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + } + else if(type==3) // Any change. + { + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CheatComp[x]!=CheatRPtrs[x>>10][x]) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + + } + else if(type==4) // new value = known + { + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CheatRPtrs[x>>10][x]==v1) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + + } + else if(type==5) // new value greater than + { + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CheatComp[x]>10][x]) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + + } + else if(type==6) // new value less than + { + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if(CheatComp[x]>CheatRPtrs[x>>10][x]) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + + } + else if(type==7) // new value greater than by known value + { + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if((CheatRPtrs[x>>10][x]-CheatComp[x])==v2) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + + } + else if(type==8) // new value less than by known value + { + for(x=0x000;x<0x10000;x++) + if(!(CheatComp[x]&CHEATC_NOSHOW)) + { + if((CheatComp[x]-CheatRPtrs[x>>10][x])==v2) + { + + } + else + CheatComp[x]|=CHEATC_EXCLUDED; + } + + } +} + +int FCEU_CheatGetByte(uint32 A) +{ + // if(CheatRPtrs[A>>10]) + // return CheatRPtrs[A>>10][A]; //adelikat-commenting this stuff out so that lua can see frozen addresses, I hope this doesn't bork stuff. + /*else*/ if(A < 0x10000) + return ARead[A](A); + else + return 0; +} + +void FCEU_CheatSetByte(uint32 A, uint8 V) +{ + if(CheatRPtrs[A>>10]) + CheatRPtrs[A>>10][A]=V; + else if(A < 0x10000) + BWrite[A](A, V); +} + +void UpdateFrozenList(void) +{ + //The purpose of this function is to keep an up to date list of addresses that are currently frozen + //and make these accessible to other dialogs that deal with memory addresses such as + //memwatch, hex editor, ramfilter, etc. + + int x; + FrozenAddresses.clear(); //Clear vector and repopulate + for(x=0;x Connect +* Connect -> Compare {('||' | '&&') Compare} +* Compare -> Sum {('==' | '!=' | '<=' | '>=' | '<' | '>') Sum} +* Sum -> Product {('+' | '-') Product} +* Product -> Primitive {('*' | '/') Primitive} +* Primitive -> Number | Address | Register | Flag | PC Bank | '(' Connect ')' +* Number -> '#' [1-9A-F]* +* Address -> '$' [1-9A-F]* | '$' '[' Connect ']' +* Register -> 'A' | 'X' | 'Y' | 'P' +* Flag -> 'N' | 'C' | 'Z' | 'I' | 'B' | 'V' +* PC Bank -> 'K' +* Data Bank -> 'T' +*/ + +#include "types.h" +#include "conddebug.h" +#include "utils/memory.h" + +#include +#include +#include +#include +#include + +// hack: this address is used by 'T' condition +uint16 addressOfTheLastAccessedData = 0; +// Next non-whitespace character in string +char next; + +int ishex(char c) +{ + return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} + +void scan(const char** str) +{ + do + { + next = **str; + (*str)++; + } while (isspace(next)); +} + +// Frees a condition and all of it's sub conditions +void freeTree(Condition* c) +{ + if (c->lhs) freeTree(c->lhs); + if (c->rhs) freeTree(c->rhs); + + free(c); +} + +// Generic function to handle all infix operators but the last one in the precedence hierarchy. : '(' E ')' +Condition* InfixOperator(const char** str, Condition(*nextPart(const char**)), int(*operators)(const char**)) +{ + Condition* t = nextPart(str); + Condition* t1; + Condition* mid; + int op; + + while ((op = operators(str))) + { + scan(str); + + t1 = nextPart(str); + + if (t1 == 0) + { + if(t) + freeTree(t); + return 0; + } + + mid = (Condition*)FCEU_dmalloc(sizeof(Condition)); + if (!mid) + return NULL; + memset(mid, 0, sizeof(Condition)); + + mid->lhs = t; + mid->rhs = t1; + mid->op = op; + + t = mid; + } + + return t; +} + +// Generic handler for two-character operators +int TwoCharOperator(const char** str, char c1, char c2, int op) +{ + if (next == c1 && **str == c2) + { + scan(str); + return op; + } + else + { + return 0; + } +} + +// Determines if a character is a flag +int isFlag(char c) +{ + return c == 'N' || c == 'I' || c == 'C' || c == 'V' || c == 'Z' || c == 'B' || c == 'U' || c == 'D'; +} + +// Determines if a character is a register +int isRegister(char c) +{ + return c == 'A' || c == 'X' || c == 'Y' || c == 'P'; +} + +// Determines if a character is for PC bank +int isPCBank(char c) +{ + return c == 'K'; +} + +// Determines if a character is for Data bank +int isDataBank(char c) +{ + return c == 'T'; +} + +// Reads a hexadecimal number from str +int getNumber(unsigned int* number, const char** str) +{ +// char buffer[5]; + + if (sscanf(*str, "%X", number) == EOF || *number > 0xFFFF) + { + return 0; + } + +// Older, inferior version which doesn't work with leading zeros +// sprintf(buffer, "%X", *number); +// *str += strlen(buffer); + while (ishex(**str)) (*str)++; + scan(str); + + return 1; +} + +Condition* Connect(const char** str); + +// Handles the following part of the grammar: '(' E ')' +Condition* Parentheses(const char** str, Condition* c, char openPar, char closePar) +{ + if (next == openPar) + { + scan(str); + + c->lhs = Connect(str); + + if (!c) return 0; + + if (next == closePar) + { + scan(str); + return c; + } + else + { + return 0; + } + } + + return 0; +} + +/* +* Check for primitives +* Flags, Registers, Numbers, Addresses and parentheses +*/ +Condition* Primitive(const char** str, Condition* c) +{ + if (isFlag(next)) /* Flags */ + { + if (c->type1 == TYPE_NO) + { + c->type1 = TYPE_FLAG; + c->value1 = next; + } + else + { + c->type2 = TYPE_FLAG; + c->value2 = next; + } + + scan(str); + + return c; + } + else if (isRegister(next)) /* Registers */ + { + if (c->type1 == TYPE_NO) + { + c->type1 = TYPE_REG; + c->value1 = next; + } + else + { + c->type2 = TYPE_REG; + c->value2 = next; + } + + scan(str); + + return c; + } + else if (isPCBank(next)) /* PC Bank */ + { + if (c->type1 == TYPE_NO) + { + c->type1 = TYPE_PC_BANK; + c->value1 = next; + } + else + { + c->type2 = TYPE_PC_BANK; + c->value2 = next; + } + + scan(str); + + return c; + } + else if (isDataBank(next)) /* Data Bank */ + { + if (c->type1 == TYPE_NO) + { + c->type1 = TYPE_DATA_BANK; + c->value1 = next; + } + else + { + c->type2 = TYPE_DATA_BANK; + c->value2 = next; + } + + scan(str); + + return c; + } + else if (next == '#') /* Numbers */ + { + unsigned int number = 0; + if (!getNumber(&number, str)) + { + return 0; + } + + if (c->type1 == TYPE_NO) + { + c->type1 = TYPE_NUM; + c->value1 = number; + } + else + { + c->type2 = TYPE_NUM; + c->value2 = number; + } + + return c; + } + else if (next == '$') /* Addresses */ + { + if ((**str >= '0' && **str <= '9') || (**str >= 'A' && **str <= 'F')) /* Constant addresses */ + { + unsigned int number = 0; + if (!getNumber(&number, str)) + { + return 0; + } + + if (c->type1 == TYPE_NO) + { + c->type1 = TYPE_ADDR; + c->value1 = number; + } + else + { + c->type2 = TYPE_ADDR; + c->value2 = number; + } + + return c; + } + else if (**str == '[') /* Dynamic addresses */ + { + scan(str); + Parentheses(str, c, '[', ']'); + + if (c->type1 == TYPE_NO) + { + c->type1 = TYPE_ADDR; + } + else + { + c->type2 = TYPE_ADDR; + } + + return c; + } + else + { + return 0; + } + } + else if (next == '(') + { + return Parentheses(str, c, '(', ')'); + } + + return 0; +} + +/* Handle * and / operators */ +Condition* Term(const char** str) +{ + Condition* t; + Condition* t1; + Condition* mid; + + t = (Condition*)FCEU_dmalloc(sizeof(Condition)); + if (!t) + return NULL; + + memset(t, 0, sizeof(Condition)); + + if (!Primitive(str, t)) + { + freeTree(t); + return 0; + } + + while (next == '*' || next == '/') + { + int op = next == '*' ? OP_MULT : OP_DIV; + + scan(str); + + if (!(t1 = (Condition*)FCEU_dmalloc(sizeof(Condition)))) + return NULL; + + memset(t1, 0, sizeof(Condition)); + + if (!Primitive(str, t1)) + { + freeTree(t); + freeTree(t1); + return 0; + } + + if (!(mid = (Condition*)FCEU_dmalloc(sizeof(Condition)))) + return NULL; + + memset(mid, 0, sizeof(Condition)); + + mid->lhs = t; + mid->rhs = t1; + mid->op = op; + + t = mid; + } + + return t; +} + +/* Check for + and - operators */ +int SumOperators(const char** str) +{ + switch (next) + { + case '+': return OP_PLUS; + case '-': return OP_MINUS; + default: return OP_NO; + } +} + +/* Handle + and - operators */ +Condition* Sum(const char** str) +{ + return InfixOperator(str, Term, SumOperators); +} + +/* Check for <=, =>, ==, !=, > and < operators */ +int CompareOperators(const char** str) +{ + int val = TwoCharOperator(str, '=', '=', OP_EQ); + if (val) return val; + + val = TwoCharOperator(str, '!', '=', OP_NE); + if (val) return val; + + val = TwoCharOperator(str, '>', '=', OP_GE); + if (val) return val; + + val = TwoCharOperator(str, '<', '=', OP_LE); + if (val) return val; + + val = next == '>' ? OP_G : 0; + if (val) return val; + + val = next == '<' ? OP_L : 0; + if (val) return val; + + return OP_NO; +} + +/* Handle <=, =>, ==, !=, > and < operators */ +Condition* Compare(const char** str) +{ + return InfixOperator(str, Sum, CompareOperators); +} + +/* Check for || or && operators */ +int ConnectOperators(const char** str) +{ + int val = TwoCharOperator(str, '|', '|', OP_OR); + if(val) return val; + + val = TwoCharOperator(str, '&', '&', OP_AND); + if(val) return val; + + return OP_NO; +} + +/* Handle || and && operators */ +Condition* Connect(const char** str) +{ + return InfixOperator(str, Compare, ConnectOperators); +} + +/* Root of the parser generator */ +Condition* generateCondition(const char* str) +{ + Condition* c; + + scan(&str); + c = Connect(&str); + + if (!c || next != 0) return 0; + else return c; +} diff --git a/branches/fceux-2.2.2/src/conddebug.h b/branches/fceux-2.2.2/src/conddebug.h new file mode 100644 index 00000000..92ea6334 --- /dev/null +++ b/branches/fceux-2.2.2/src/conddebug.h @@ -0,0 +1,65 @@ +/* FCEUXD SP - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 Sebastian Porst + * + * 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 CONDDEBUG_H +#define CONDDEBUG_H + +#define TYPE_NO 0 +#define TYPE_REG 1 +#define TYPE_FLAG 2 +#define TYPE_NUM 3 +#define TYPE_ADDR 4 +#define TYPE_PC_BANK 5 +#define TYPE_DATA_BANK 6 + +#define OP_NO 0 +#define OP_EQ 1 +#define OP_NE 2 +#define OP_GE 3 +#define OP_LE 4 +#define OP_G 5 +#define OP_L 6 +#define OP_PLUS 7 +#define OP_MINUS 8 +#define OP_MULT 9 +#define OP_DIV 10 +#define OP_OR 11 +#define OP_AND 12 + +extern uint16 addressOfTheLastAccessedData; +//mbg merge 7/18/06 turned into sane c++ +struct Condition +{ + Condition* lhs; + Condition* rhs; + + unsigned int type1; + unsigned int value1; + + unsigned int op; + + unsigned int type2; + unsigned int value2; +}; + +void freeTree(Condition* c); +Condition* generateCondition(const char* str); + +#endif diff --git a/branches/fceux-2.2.2/src/config.cpp b/branches/fceux-2.2.2/src/config.cpp new file mode 100644 index 00000000..de66a1ec --- /dev/null +++ b/branches/fceux-2.2.2/src/config.cpp @@ -0,0 +1,56 @@ +/// \file +/// \brief Contains methods related to the build configuration + +#include "types.h" +#include "version.h" +#include "fceu.h" +#include "driver.h" +#include "utils/memory.h" + +#include +#include +#include + +static char *aboutString = 0; + +// returns a string suitable for use in an aboutbox +char *FCEUI_GetAboutString() { + const char *aboutTemplate = + FCEU_NAME_AND_VERSION "\n\n" + "Administrators:\n" + "zeromus, adelikat, AnS\n\n" + "Current Contributors:\n" + "punkrockguy318 (Lukas Sabota)\n" + "CaH4e3, gocha, xhainingx, feos\n" + "\n" + "FCEUX 2.0:\n" + "mz, nitsujrehtona, SP, Ugly Joe,\n" + "Plombo, qeed, QFox, Shinydoofy\n" + "ugetab, Acmlm, DWEdit\n" + "\n" + "Previous versions:\n" + "FCE - Bero\n" + "FCEU - Xodnizel\n" + "FCEU XD - Bbitmaster & Parasyte\n" + "FCEU XD SP - Sebastian Porst\n" + "FCEU MM - CaH4e3\n" + "FCEU TAS - blip & nitsuja\n" + "FCEU TAS+ - Luke Gustafson\n" + "\n" + "FCEUX is dedicated to the fallen heroes\n" + "of NES emulation. In Memoriam --\n" + "ugetab\n" + "\n" + __TIME__ " " __DATE__ "\n"; + + if(aboutString) return aboutString; + + const char *compilerString = FCEUD_GetCompilerString(); + + //allocate the string and concatenate the template with the compiler string + if (!(aboutString = (char*)FCEU_dmalloc(strlen(aboutTemplate) + strlen(compilerString) + 1))) + return NULL; + + sprintf(aboutString,"%s%s",aboutTemplate,compilerString); + return aboutString; +} diff --git a/branches/fceux-2.2.2/src/config.h b/branches/fceux-2.2.2/src/config.h new file mode 100644 index 00000000..e69de29b diff --git a/branches/fceux-2.2.2/src/debug.cpp b/branches/fceux-2.2.2/src/debug.cpp new file mode 100644 index 00000000..c71274c4 --- /dev/null +++ b/branches/fceux-2.2.2/src/debug.cpp @@ -0,0 +1,800 @@ +/// \file +/// \brief Implements core debugging facilities +#include "types.h" +#include "x6502.h" +#include "fceu.h" +#include "cart.h" +#include "ines.h" +#include "debug.h" +#include "driver.h" +#include "ppu.h" + +#include "x6502abbrev.h" + +#include +#include + + +int vblankScanLines = 0; //Used to calculate scanlines 240-261 (vblank) +int vblankPixel = 0; //Used to calculate the pixels in vblank + +int offsetStringToInt(unsigned int type, const char* offsetBuffer) +{ + int offset = -1; + + if (sscanf(offsetBuffer,"%4X",&offset) == EOF) + { + return -1; + } + + if (type & BT_P) + { + return offset & 0x3FFF; + } + else if (type & BT_S) + { + return offset & 0x00FF; + } + else // BT_C + { + if (GameInfo->type == GIT_NSF) { //NSF Breakpoint keywords + if (strcmp(offsetBuffer,"LOAD") == 0) return (NSFHeader.LoadAddressLow | (NSFHeader.LoadAddressHigh<<8)); + if (strcmp(offsetBuffer,"INIT") == 0) return (NSFHeader.InitAddressLow | (NSFHeader.InitAddressHigh<<8)); + if (strcmp(offsetBuffer,"PLAY") == 0) return (NSFHeader.PlayAddressLow | (NSFHeader.PlayAddressHigh<<8)); + } + else if (GameInfo->type == GIT_FDS) { //FDS Breakpoint keywords + if (strcmp(offsetBuffer,"NMI1") == 0) return (GetMem(0xDFF6) | (GetMem(0xDFF7)<<8)); + if (strcmp(offsetBuffer,"NMI2") == 0) return (GetMem(0xDFF8) | (GetMem(0xDFF9)<<8)); + if (strcmp(offsetBuffer,"NMI3") == 0) return (GetMem(0xDFFA) | (GetMem(0xDFFB)<<8)); + if (strcmp(offsetBuffer,"RST") == 0) return (GetMem(0xDFFC) | (GetMem(0xDFFD)<<8)); + if ((strcmp(offsetBuffer,"IRQ") == 0) || (strcmp(offsetBuffer,"BRK") == 0)) return (GetMem(0xDFFE) | (GetMem(0xDFFF)<<8)); + } + else { //NES Breakpoint keywords + if ((strcmp(offsetBuffer,"NMI") == 0) || (strcmp(offsetBuffer,"VBL") == 0)) return (GetMem(0xFFFA) | (GetMem(0xFFFB)<<8)); + if (strcmp(offsetBuffer,"RST") == 0) return (GetMem(0xFFFC) | (GetMem(0xFFFD)<<8)); + if ((strcmp(offsetBuffer,"IRQ") == 0) || (strcmp(offsetBuffer,"BRK") == 0)) return (GetMem(0xFFFE) | (GetMem(0xFFFF)<<8)); + } + } + + return offset; +} + +// Returns the value of a given type or register + +int getValue(int type) +{ + switch (type) + { + case 'A': return _A; + case 'X': return _X; + case 'Y': return _Y; + case 'N': return _P & N_FLAG ? 1 : 0; + case 'V': return _P & V_FLAG ? 1 : 0; + case 'U': return _P & U_FLAG ? 1 : 0; + case 'B': return _P & B_FLAG ? 1 : 0; + case 'D': return _P & D_FLAG ? 1 : 0; + case 'I': return _P & I_FLAG ? 1 : 0; + case 'Z': return _P & Z_FLAG ? 1 : 0; + case 'C': return _P & C_FLAG ? 1 : 0; + case 'P': return _PC; + } + + return 0; +} + + +/** +* Checks whether a breakpoint condition is syntactically valid +* and creates a breakpoint condition object if everything's OK. +* +* @param condition Condition to parse +* @param num Number of the breakpoint in the BP list the condition belongs to +* @return 0 in case of an error; 2 if everything went fine +**/ +int checkCondition(const char* condition, int num) +{ + const char* b = condition; + + // Check if the condition isn't just all spaces. + + int onlySpaces = 1; + + while (*b) + { + if (*b != ' ') + { + onlySpaces = 0; + break; + } + + ++b; + } + + + // If there's an actual condition create the BP condition object now + + if (*condition && !onlySpaces) + { + Condition* c = generateCondition(condition); + + // Remove the old breakpoint condition before adding a new condition. + if (watchpoint[num].cond) + { + freeTree(watchpoint[num].cond); + free(watchpoint[num].condText); + watchpoint[num].cond = 0; + watchpoint[num].condText = 0; + } + + // If the creation of the BP condition object was succesful + // the condition is apparently valid. It can be added to the + // breakpoint now. + + if (c) + { + watchpoint[num].cond = c; + watchpoint[num].condText = (char*)malloc(strlen(condition) + 1); + if (!watchpoint[num].condText) + return 0; + strcpy(watchpoint[num].condText, condition); + } + else + { + watchpoint[num].cond = 0; + } + + return watchpoint[num].cond == 0 ? 2 : 0; + } + else + { + // Remove the old breakpoint condition + if (watchpoint[num].cond) + { + freeTree(watchpoint[num].cond); + free(watchpoint[num].condText); + watchpoint[num].cond = 0; + watchpoint[num].condText = 0; + } + return 0; + } +} + +/** +* Adds a new breakpoint. +* +* @param hwndDlg Handle of the debugger window +* @param num Number of the breakpoint +* @param +**/ +unsigned int NewBreak(const char* name, int start, int end, unsigned int type, const char* condition, unsigned int num, bool enable) +{ + // Finally add breakpoint to the list + watchpoint[num].address = start; + watchpoint[num].endaddress = 0; + + // Optional end address found + if (end != -1) + { + watchpoint[num].endaddress = end; + } + + // Get the breakpoint flags + watchpoint[num].flags = 0; + if (enable) watchpoint[num].flags|=WP_E; + if (type & WP_R) watchpoint[num].flags|=WP_R; + if (type & WP_F) watchpoint[num].flags|=WP_F; + if (type & WP_W) watchpoint[num].flags|=WP_W; + if (type & WP_X) watchpoint[num].flags|=WP_X; + if (type & BT_P) { + watchpoint[num].flags|=BT_P; + watchpoint[num].flags&=~WP_X; //disable execute flag! + } + if (type & BT_S) { + watchpoint[num].flags|=BT_S; + watchpoint[num].flags&=~WP_X; //disable execute flag! + } + + if (watchpoint[num].desc) + free(watchpoint[num].desc); + + watchpoint[num].desc = (char*)malloc(strlen(name) + 1); + strcpy(watchpoint[num].desc, name); + + return checkCondition(condition, num); +} + +int GetPRGAddress(int A){ + int result; + if(A > 0xFFFF) + return -1; + result = &Page[A>>11][A]-PRGptr[0]; + if((result > (int)PRGsize[0]) || (result < 0)) + return -1; + else + return result; +} + +/** +* Returns the bank for a given offset. +* Technically speaking this function does not calculate the actual bank +* where the offset resides but the 0x4000 bytes large chunk of the ROM of the offset. +* +* @param offs The offset +* @return The bank of that offset or -1 if the offset is not part of the ROM. +**/ +int getBank(int offs) +{ + //NSF data is easy to overflow the return on. + //Anything over FFFFF will kill it. + + //GetNesFileAddress doesn't work well with Unif files + int addr = GetNesFileAddress(offs)-16; + + if (GameInfo && GameInfo->type==GIT_NSF) + return addr != -1 ? addr / 0x1000 : -1; + return addr != -1 ? addr / 0x4000 : -1; +} + +int GetNesFileAddress(int A){ + int result; + if((A < 0x8000) || (A > 0xFFFF))return -1; + result = &Page[A>>11][A]-PRGptr[0]; + if((result > (int)(PRGsize[0])) || (result < 0))return -1; + else return result+16; //16 bytes for the header remember +} + +int GetRomAddress(int A){ + int i; + uint8 *p = GetNesPRGPointer(A-=16); + for(i = 16;i < 32;i++){ + if((&Page[i][i<<11] <= p) && (&Page[i][(i+1)<<11] > p))break; + } + if(i == 32)return -1; //not found + + return (i<<11) + (p-&Page[i][i<<11]); +} + +uint8 *GetNesPRGPointer(int A){ + return PRGptr[0]+A; +} + +uint8 *GetNesCHRPointer(int A){ + return CHRptr[0]+A; +} + +uint8 GetMem(uint16 A) { + if ((A >= 0x2000) && (A < 0x4000)) { + switch (A&7) { + case 0: return PPU[0]; + case 1: return PPU[1]; + case 2: return PPU[2]|(PPUGenLatch&0x1F); + case 3: return PPU[3]; + case 4: return SPRAM[PPU[3]]; + case 5: return XOffset; + case 6: return RefreshAddr&0xFF; + case 7: return VRAMBuffer; + } + } else if ((A >= 0x4000) && (A < 0x5000)) return 0xFF; // AnS: changed the range, so MMC5 ExRAM can be watched in the Hexeditor + if (GameInfo) return ARead[A](A); //adelikat: 11/17/09: Prevent crash if this is called with no game loaded. + else return 0; +} + +uint8 GetPPUMem(uint8 A) { + uint16 tmp=RefreshAddr&0x3FFF; + + if (tmp<0x2000) return VPage[tmp>>10][tmp]; + if (tmp>=0x3F00) return PALRAM[tmp&0x1F]; + return vnapage[(tmp>>10)&0x3][tmp&0x3FF]; +} + +//--------------------- + +// Evaluates a condition +int evaluate(Condition* c) +{ + int f = 0; + + int value1, value2; + + if (c->lhs) + { + value1 = evaluate(c->lhs); + } + else + { + switch(c->type1) + { + case TYPE_ADDR: // This is intended to not break, and use the TYPE_NUM code + case TYPE_NUM: value1 = c->value1; break; + default: value1 = getValue(c->value1); break; + } + } + + switch(c->type1) + { + case TYPE_ADDR: value1 = GetMem(value1); break; + case TYPE_PC_BANK: value1 = getBank(_PC); break; + case TYPE_DATA_BANK: value1 = getBank(addressOfTheLastAccessedData); break; + } + + f = value1; + + if (c->op) + { + if (c->rhs) + { + value2 = evaluate(c->rhs); + } + else + { + switch(c->type2) + { + case TYPE_ADDR: // This is intended to not break, and use the TYPE_NUM code + case TYPE_NUM: value2 = c->value2; break; + default: value2 = getValue(c->type2); break; + } + } + + switch(c->type2) + { + case TYPE_ADDR: value2 = GetMem(value2); break; + case TYPE_PC_BANK: value2 = getBank(_PC); break; + case TYPE_DATA_BANK: value2 = getBank(addressOfTheLastAccessedData); break; + } + + switch (c->op) + { + case OP_EQ: f = value1 == value2; break; + case OP_NE: f = value1 != value2; break; + case OP_GE: f = value1 >= value2; break; + case OP_LE: f = value1 <= value2; break; + case OP_G: f = value1 > value2; break; + case OP_L: f = value1 < value2; break; + case OP_MULT: f = value1 * value2; break; + case OP_DIV: f = value1 / value2; break; + case OP_PLUS: f = value1 + value2; break; + case OP_MINUS: f = value1 - value2; break; + case OP_OR: f = value1 || value2; break; + case OP_AND: f = value1 && value2; break; + } + } + + return f; +} + +int condition(watchpointinfo* wp) +{ + return wp->cond == 0 || evaluate(wp->cond); +} + + +//--------------------- + +volatile int codecount, datacount, undefinedcount; +unsigned char *cdloggerdata; +unsigned int cdloggerdataSize = 0; +static int indirectnext; + +int debug_loggingCD; + +//called by the cpu to perform logging if CDLogging is enabled +void LogCDVectors(int which){ + int j; + j = GetPRGAddress(which); + if(j == -1) return; + + if(!(cdloggerdata[j] & 2)){ + cdloggerdata[j] |= 0x0E; // we're in the last bank and recording it as data so 0x1110 or 0xE should be what we need + datacount++; + if(!(cdloggerdata[j] & 1))undefinedcount--; + } + j++; + + if(!(cdloggerdata[j] & 2)){ + cdloggerdata[j] |= 0x0E; + datacount++; + if(!(cdloggerdata[j] & 1))undefinedcount--; + } +} + +void LogCDData(uint8 *opcode, uint16 A, int size) { + int i, j; + uint8 memop = 0; + + if((j = GetPRGAddress(_PC)) != -1) + for (i = 0; i < size; i++) { + if(cdloggerdata[j+i] & 1)continue; //this has been logged so skip + cdloggerdata[j+i] |= 1; + cdloggerdata[j+i] |=((_PC+i)>>11)&0x0c; + if(indirectnext)cdloggerdata[j+i] |= 0x10; + codecount++; + if(!(cdloggerdata[j+i] & 2))undefinedcount--; + } + + //log instruction jumped to in an indirect jump + if(opcode[0] == 0x6c) + indirectnext = 1; + else + indirectnext = 0; + + switch (optype[opcode[0]]) { + case 1: + case 4: memop = 0x20; break; + } + + if((j = GetPRGAddress(A)) != -1) { + if(!(cdloggerdata[j] & 2)) { + cdloggerdata[j] |= 2; + cdloggerdata[j] |=(A>>11)&0x0c; + cdloggerdata[j] |= memop; + datacount++; + if(!(cdloggerdata[j] & 1))undefinedcount--; + } + } +} + +//-----------debugger stuff + +watchpointinfo watchpoint[65]; //64 watchpoints, + 1 reserved for step over +int iaPC; +uint32 iapoffset; //mbg merge 7/18/06 changed from int +int u; //deleteme +int skipdebug; //deleteme +int numWPs; + +bool break_asap = false; +// for CPU cycles and Instructions counters +uint64 total_cycles_base = 0; +uint64 delta_cycles_base = 0; +bool break_on_cycles = false; +uint64 break_cycles_limit = 0; +uint64 total_instructions = 0; +uint64 delta_instructions = 0; +bool break_on_instructions = false; +uint64 break_instructions_limit = 0; + +static DebuggerState dbgstate; + +DebuggerState &FCEUI_Debugger() { return dbgstate; } + +void ResetDebugStatisticsCounters() +{ + ResetCyclesCounter(); + ResetInstructionsCounter(); +} +void ResetCyclesCounter() +{ + total_cycles_base = delta_cycles_base = timestampbase + (uint64)timestamp; +} +void ResetInstructionsCounter() +{ + total_instructions = delta_instructions = 0; +} +void ResetDebugStatisticsDeltaCounters() +{ + delta_cycles_base = timestampbase + (uint64)timestamp; + delta_instructions = 0; +} +void IncrementInstructionsCounters() +{ + total_instructions++; + delta_instructions++; +} + +void BreakHit(int bp_num, bool force) +{ + if(!force) + { + //check to see whether we fall in any forbid zone + for (int i = 0; i < numWPs; i++) + { + watchpointinfo& wp = watchpoint[i]; + if(!(wp.flags & WP_F) || !(wp.flags & WP_E)) + continue; + + if (condition(&wp)) + { + if (wp.endaddress) { + if( (wp.address <= _PC) && (wp.endaddress >= _PC) ) + return; //forbid + } else { + if(wp.address == _PC) + return; //forbid + } + } + } + } + + FCEUI_SetEmulationPaused(EMULATIONPAUSED_PAUSED); //mbg merge 7/19/06 changed to use EmulationPaused() + +#ifdef WIN32 + FCEUD_DebugBreakpoint(bp_num); +#endif +} + +uint8 StackAddrBackup = X.S; +uint16 StackNextIgnorePC = 0xFFFF; + +///fires a breakpoint +static void breakpoint(uint8 *opcode, uint16 A, int size) { + int i, j; + uint8 brk_type; + uint8 stackop=0; + uint8 stackopstartaddr,stackopendaddr; + + if (break_asap) + { + break_asap = false; + BreakHit(BREAK_TYPE_LUA, true); + } + + if (break_on_cycles && ((timestampbase + (uint64)timestamp - total_cycles_base) > break_cycles_limit)) + BreakHit(BREAK_TYPE_CYCLES_EXCEED, true); + if (break_on_instructions && (total_instructions > break_instructions_limit)) + BreakHit(BREAK_TYPE_INSTRUCTIONS_EXCEED, true); + + //if the current instruction is bad, and we are breaking on bad opcodes, then hit the breakpoint + if(dbgstate.badopbreak && (size == 0)) + BreakHit(BREAK_TYPE_BADOP, true); + + //if we're stepping out, track the nest level + if (dbgstate.stepout) { + if (opcode[0] == 0x20) dbgstate.jsrcount++; + else if (opcode[0] == 0x60) { + if (dbgstate.jsrcount) + dbgstate.jsrcount--; + else { + dbgstate.stepout = false; + dbgstate.step = true; + return; + } + } + } + + //if we're stepping, then we'll always want to break + if (dbgstate.step) { + dbgstate.step = false; + BreakHit(BREAK_TYPE_STEP, true); + return; + } + + //if we're running for a scanline, we want to check if we've hit the cycle limit + if (dbgstate.runline) { + uint64 ts = timestampbase; + ts+=timestamp; + int diff = dbgstate.runline_end_time-ts; + if (diff<=0) + { + dbgstate.runline=false; + BreakHit(BREAK_TYPE_STEP, true); + return; + } + } + + //check the step over address and break if we've hit it + if ((watchpoint[64].address == _PC) && (watchpoint[64].flags)) { + watchpoint[64].address = 0; + watchpoint[64].flags = 0; + BreakHit(BREAK_TYPE_STEP, true); + return; + } + + brk_type = opbrktype[opcode[0]] | WP_X; + + switch (opcode[0]) { + //Push Ops + case 0x08: //Fall to next + case 0x48: stackopstartaddr=stackopendaddr=X.S-1; stackop=WP_W; StackAddrBackup = X.S; StackNextIgnorePC=_PC+1; break; + //Pull Ops + case 0x28: //Fall to next + case 0x68: stackopstartaddr=stackopendaddr=X.S+1; stackop=WP_R; StackAddrBackup = X.S; StackNextIgnorePC=_PC+1; break; + //JSR (Includes return address - 1) + case 0x20: stackopstartaddr=stackopendaddr=X.S-1; stackop=WP_W; StackAddrBackup = X.S; StackNextIgnorePC=(opcode[1]|opcode[2]<<8); break; + //RTI (Includes processor status, and exact return address) + case 0x40: stackopstartaddr=X.S+1; stackopendaddr=X.S+3; stackop=WP_R; StackAddrBackup = X.S; StackNextIgnorePC=(GetMem(X.S+2|0x0100)|GetMem(X.S+3|0x0100)<<8); break; + //RTS (Includes return address - 1) + case 0x60: stackopstartaddr=X.S+1; stackopendaddr=X.S+2; stackop=WP_R; StackAddrBackup = X.S; StackNextIgnorePC=(GetMem(stackopstartaddr|0x0100)|GetMem(stackopendaddr|0x0100)<<8)+1; break; + } + + for (i = 0; i < numWPs; i++) + { +// ################################## Start of SP CODE ########################### + if ((watchpoint[i].flags & WP_E) && condition(&watchpoint[i])) + { +// ################################## End of SP CODE ########################### + if (watchpoint[i].flags & BT_P) + { + // PPU Mem breaks + if ((watchpoint[i].flags & brk_type) && ((A >= 0x2000) && (A < 0x4000)) && ((A&7) == 7)) + { + if (watchpoint[i].endaddress) + { + if ((watchpoint[i].address <= RefreshAddr) && (watchpoint[i].endaddress >= RefreshAddr)) + BreakHit(i); + } else + { + if (watchpoint[i].address == RefreshAddr) + BreakHit(i); + } + } + } else if (watchpoint[i].flags & BT_S) + { + // Sprite Mem breaks + if ((watchpoint[i].flags & brk_type) && ((A >= 0x2000) && (A < 0x4000)) && ((A&7) == 4)) + { + if (watchpoint[i].endaddress) + { + if ((watchpoint[i].address <= PPU[3]) && (watchpoint[i].endaddress >= PPU[3])) + BreakHit(i); + } else + { + if (watchpoint[i].address == PPU[3]) + BreakHit(i); + } + } else if ((watchpoint[i].flags & WP_W) && (A == 0x4014)) + { + // Sprite DMA! :P + BreakHit(i); + } + } else + { + // CPU mem breaks + if ((watchpoint[i].flags & brk_type)) + { + if (watchpoint[i].endaddress) + { + if (((watchpoint[i].flags & (WP_R | WP_W)) && (watchpoint[i].address <= A) && (watchpoint[i].endaddress >= A)) || + ((watchpoint[i].flags & WP_X) && (watchpoint[i].address <= _PC) && (watchpoint[i].endaddress >= _PC))) + BreakHit(i); + } else + { + if (((watchpoint[i].flags & (WP_R | WP_W)) && (watchpoint[i].address == A)) || + ((watchpoint[i].flags & WP_X) && (watchpoint[i].address == _PC))) + BreakHit(i); + } + } else + { + // brk_type independant coding + if (stackop > 0) + { + // Announced stack mem breaks + // PHA, PLA, PHP, and PLP affect the stack data. + // TXS and TSX only deal with the pointer. + if (watchpoint[i].flags & stackop) + { + for (j = (stackopstartaddr|0x0100); j <= (stackopendaddr|0x0100); j++) + { + if (watchpoint[i].endaddress) + { + if ((watchpoint[i].address <= j) && (watchpoint[i].endaddress >= j)) + BreakHit(i); + } else + { + if (watchpoint[i].address == j) + BreakHit(i); + } + } + } + } + if (StackNextIgnorePC == _PC) + { + // Used to make it ignore the unannounced stack code one time + StackNextIgnorePC = 0xFFFF; + } else + { + if ((X.S < StackAddrBackup) && (stackop==0)) + { + // Unannounced stack mem breaks + // Pushes to stack + if (watchpoint[i].flags & WP_W) + { + for (j = (X.S|0x0100); j < (StackAddrBackup|0x0100); j++) + { + if (watchpoint[i].endaddress) + { + if ((watchpoint[i].address <= j) && (watchpoint[i].endaddress >= j)) + BreakHit(i); + } else + { + if (watchpoint[i].address == j) + BreakHit(i); + } + } + } + } else if ((StackAddrBackup < X.S) && (stackop==0)) + { + // Pulls from stack + if (watchpoint[i].flags & WP_R) + { + for (j = (StackAddrBackup|0x0100); j < (X.S|0x0100); j++) + { + if (watchpoint[i].endaddress) + { + if ((watchpoint[i].address <= j) && (watchpoint[i].endaddress >= j)) + BreakHit(i); + } else + { + if (watchpoint[i].address == j) + BreakHit(i); + } + } + } + } + } + + } + } +// ################################## Start of SP CODE ########################### + } +// ################################## End of SP CODE ########################### + } + + //Update the stack address with the current one, now that changes have registered. + StackAddrBackup = X.S; +} +//bbit edited: this is the end of the inserted code + +void DebugCycle() +{ + uint8 opcode[3] = {0}; + uint16 A = 0; + int size; + + if (scanline == 240) + { + vblankScanLines = (PAL?int((double)timestamp / ((double)341 / (double)3.2)):timestamp / 114); //114 approximates the number of timestamps per scanline during vblank. Approx 2508. NTSC: (341 / 3.0) PAL: (341 / 3.2). Uses (3.? * cpu_cycles) / 341.0, and assumes 1 cpu cycle. + if (vblankScanLines) vblankPixel = 341 / vblankScanLines; //341 pixels per scanline + //FCEUI_printf("vbPixel = %d",vblankPixel); //Debug + //FCEUI_printf("ts: %d line: %d\n", timestamp, vblankScanLines); //Debug + } + else + vblankScanLines = 0; + + if (GameInfo->type==GIT_NSF) + { + if ((_PC >= 0x3801) && (_PC <= 0x3824)) return; + } + + opcode[0] = GetMem(_PC); + size = opsize[opcode[0]]; + switch (size) + { + case 2: + opcode[1] = GetMem(_PC + 1); + break; + case 3: + opcode[1] = GetMem(_PC + 1); + opcode[2] = GetMem(_PC + 2); + break; + } + + switch (optype[opcode[0]]) + { + case 0: break; + case 1: + A = (opcode[1] + _X) & 0xFF; + A = GetMem(A) | (GetMem(A + 1) << 8); + break; + case 2: A = opcode[1]; break; + case 3: A = opcode[1] | (opcode[2] << 8); break; + case 4: A = (GetMem(opcode[1]) | (GetMem(opcode[1]+1) << 8)) + _Y; break; + case 5: A = opcode[1] + _X; break; + case 6: A = (opcode[1] | (opcode[2] << 8)) + _Y; break; + case 7: A = (opcode[1] | (opcode[2] << 8)) + _X; break; + case 8: A = opcode[1] + _Y; break; + } + addressOfTheLastAccessedData = A; + + if (numWPs || dbgstate.step || dbgstate.runline || dbgstate.stepout || watchpoint[64].flags || dbgstate.badopbreak || break_on_cycles || break_on_instructions || break_asap) + breakpoint(opcode, A, size); + + if(debug_loggingCD) + LogCDData(opcode, A, size); + +#ifdef WIN32 + //This needs to be windows only or else the linux build system will fail since logging is declared in a + //windows source file + FCEUD_TraceInstruction(opcode, size); +#endif + +} diff --git a/branches/fceux-2.2.2/src/debug.h b/branches/fceux-2.2.2/src/debug.h new file mode 100644 index 00000000..09c10177 --- /dev/null +++ b/branches/fceux-2.2.2/src/debug.h @@ -0,0 +1,164 @@ +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#include "conddebug.h" +#include "git.h" +#include "nsf.h" + +//watchpoint stuffs +#define WP_E 0x01 //watchpoint, enable +#define WP_W 0x02 //watchpoint, write +#define WP_R 0x04 //watchpoint, read +#define WP_X 0x08 //watchpoint, execute +#define WP_F 0x10 //watchpoint, forbid + +#define BT_C 0x00 //break type, cpu mem +#define BT_P 0x20 //break type, ppu mem +#define BT_S 0x40 //break type, sprite mem + +#define BREAK_TYPE_STEP -1 +#define BREAK_TYPE_BADOP -2 +#define BREAK_TYPE_CYCLES_EXCEED -3 +#define BREAK_TYPE_INSTRUCTIONS_EXCEED -4 +#define BREAK_TYPE_LUA -5 + +//opbrktype is used to grab the breakpoint type that each instruction will cause. +//WP_X is not used because ALL opcodes will have the execute bit set. +static const uint8 opbrktype[256] = { + /*0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F*/ +/*0x00*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, 0, 0, 0, 0, WP_R, WP_R|WP_W, 0, +/*0x10*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, +/*0x20*/ 0, WP_R, 0, 0, WP_R, WP_R, WP_R|WP_W, 0, 0, 0, 0, 0, WP_R, WP_R, WP_R|WP_W, 0, +/*0x30*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, +/*0x40*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, 0, 0, 0, 0, WP_R, WP_R|WP_W, 0, +/*0x50*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, +/*0x60*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, 0, 0, 0, WP_R, WP_R, WP_R|WP_W, 0, +/*0x70*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, +/*0x80*/ 0, WP_W, 0, 0, WP_W, WP_W, WP_W, 0, 0, 0, 0, 0, WP_W, WP_W, WP_W, 0, +/*0x90*/ 0, WP_W, 0, 0, WP_W, WP_W, WP_W, 0, 0, WP_W, 0, 0, 0, WP_W, 0, 0, +/*0xA0*/ 0, WP_R, 0, 0, WP_R, WP_R, WP_R, 0, 0, 0, 0, 0, WP_R, WP_R, WP_R, 0, +/*0xB0*/ 0, WP_R, 0, 0, WP_R, WP_R, WP_R, 0, 0, WP_R, 0, 0, WP_R, WP_R, WP_R, 0, +/*0xC0*/ 0, WP_R, 0, 0, WP_R, WP_R, WP_R|WP_W, 0, 0, 0, 0, 0, WP_R, WP_R, WP_R|WP_W, 0, +/*0xD0*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, +/*0xE0*/ 0, WP_R, 0, 0, WP_R, WP_R, WP_R|WP_W, 0, 0, 0, 0, 0, WP_R, WP_R, WP_R|WP_W, 0, +/*0xF0*/ 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0, 0, WP_R, 0, 0, 0, WP_R, WP_R|WP_W, 0 +}; + + +typedef struct { + uint16 address; + uint16 endaddress; + uint8 flags; +// ################################## Start of SP CODE ########################### + + Condition* cond; + char* condText; + char* desc; + +// ################################## End of SP CODE ########################### +} watchpointinfo; + +//mbg merge 7/18/06 had to make this extern +extern watchpointinfo watchpoint[65]; //64 watchpoints, + 1 reserved for step over + +int getBank(int offs); +int GetNesFileAddress(int A); +int GetPRGAddress(int A); +int GetRomAddress(int A); +//int GetEditHex(HWND hwndDlg, int id); +uint8 *GetNesPRGPointer(int A); +uint8 *GetNesCHRPointer(int A); +void KillDebugger(); +uint8 GetMem(uint16 A); +uint8 GetPPUMem(uint8 A); + +//---------CDLogger +void LogCDVectors(int which); +void LogCDData(uint8 *opcode, uint16 A, int size); +extern volatile int codecount, datacount, undefinedcount; +extern unsigned char *cdloggerdata; +extern unsigned int cdloggerdataSize; + +extern int debug_loggingCD; +static INLINE void FCEUI_SetLoggingCD(int val) { debug_loggingCD = val; } +static INLINE int FCEUI_GetLoggingCD() { return debug_loggingCD; } +//------- + +//-------tracing +//we're letting the win32 driver handle this ittself for now +//extern int debug_tracing; +//static INLINE void FCEUI_SetTracing(int val) { debug_tracing = val; } +//static INLINE int FCEUI_GetTracing() { return debug_tracing; } +//--------- + +//--------debugger +extern int iaPC; +extern uint32 iapoffset; //mbg merge 7/18/06 changed from int +void DebugCycle(); +void BreakHit(int bp_num, bool force = false); + +extern bool break_asap; +extern uint64 total_cycles_base; +extern uint64 delta_cycles_base; +extern bool break_on_cycles; +extern uint64 break_cycles_limit; +extern uint64 total_instructions; +extern uint64 delta_instructions; +extern bool break_on_instructions; +extern uint64 break_instructions_limit; +extern void ResetDebugStatisticsCounters(); +extern void ResetCyclesCounter(); +extern void ResetInstructionsCounter(); +extern void ResetDebugStatisticsDeltaCounters(); +extern void IncrementInstructionsCounters(); +//------------- + +//internal variables that debuggers will want access to +extern uint8 *vnapage[4],*VPage[8]; +extern uint8 PPU[4],PALRAM[0x20],SPRAM[0x100],VRAMBuffer,PPUGenLatch,XOffset; +extern uint32 RefreshAddr; + +extern int debug_loggingCD; +extern int numWPs; + +///encapsulates the operational state of the debugger core +class DebuggerState { +public: + ///indicates whether the debugger is stepping through a single instruction + bool step; + ///indicates whether the debugger is stepping out of a function call + bool stepout; + ///indicates whether the debugger is running one line + bool runline; + ///target timestamp for runline to stop at + uint64 runline_end_time; + ///indicates whether the debugger should break on bad opcodes + bool badopbreak; + ///counts the nest level of the call stack while stepping out + int jsrcount; + + ///resets the debugger state to an empty, non-debugging state + void reset() { + numWPs = 0; + step = false; + stepout = false; + jsrcount = 0; + } +}; + +extern NSF_HEADER NSFHeader; + +///retrieves the core's DebuggerState +DebuggerState &FCEUI_Debugger(); + +//#define CPU_BREAKPOINT 1 +//#define PPU_BREAKPOINT 2 +//#define SPRITE_BREAKPOINT 4 +//#define READ_BREAKPOINT 8 +//#define WRITE_BREAKPOINT 16 +//#define EXECUTE_BREAKPOINT 32 + +int offsetStringToInt(unsigned int type, const char* offsetBuffer); +unsigned int NewBreak(const char* name, int start, int end, unsigned int type, const char* condition, unsigned int num, bool enable); + +#endif diff --git a/branches/fceux-2.2.2/src/drawing.cpp b/branches/fceux-2.2.2/src/drawing.cpp new file mode 100644 index 00000000..2d64fd82 --- /dev/null +++ b/branches/fceux-2.2.2/src/drawing.cpp @@ -0,0 +1,525 @@ +#include "types.h" +#include "fceu.h" +#include "drawing.h" +#include "video.h" +#include "movie.h" +#include "driver.h" + +static uint8 Font6x7[792] = +{ + 6, 0, 0, 0, 0, 0, 0, 0, // 0x20 - Spacebar + 3, 64, 64, 64, 64, 64, 0, 64, + 5, 80, 80, 80, 0, 0, 0, 0, + 6, 80, 80,248, 80,248, 80, 80, + 6, 32,120,160,112, 40,240, 32, + 6, 64,168, 80, 32, 80,168, 16, + 6, 96,144,160, 64,168,144,104, + 3, 64, 64, 0, 0, 0, 0, 0, + 4, 32, 64, 64, 64, 64, 64, 32, + 4, 64, 32, 32, 32, 32, 32, 64, + 6, 0, 80, 32,248, 32, 80, 0, + 6, 0, 32, 32,248, 32, 32, 0, + 3, 0, 0, 0, 0, 0, 64,128, + 5, 0, 0, 0,240, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 64, + 5, 16, 16, 32, 32, 32, 64, 64, + 6,112,136,136,136,136,136,112, // 0x30 - 0 + 6, 32, 96, 32, 32, 32, 32, 32, + 6,112,136, 8, 48, 64,128,248, + 6,112,136, 8, 48, 8,136,112, + 6, 16, 48, 80,144,248, 16, 16, + 6,248,128,128,240, 8, 8,240, + 6, 48, 64,128,240,136,136,112, + 6,248, 8, 16, 16, 32, 32, 32, + 6,112,136,136,112,136,136,112, + 6,112,136,136,120, 8, 16, 96, + 3, 0, 0, 64, 0, 0, 64, 0, + 3, 0, 0, 64, 0, 0, 64,128, + 4, 0, 32, 64,128, 64, 32, 0, + 5, 0, 0,240, 0,240, 0, 0, + 4, 0,128, 64, 32, 64,128, 0, + 6,112,136, 8, 16, 32, 0, 32, // 0x3F - ? + 6,112,136,136,184,176,128,112, // 0x40 - @ + 6,112,136,136,248,136,136,136, // 0x41 - A + 6,240,136,136,240,136,136,240, + 6,112,136,128,128,128,136,112, + 6,224,144,136,136,136,144,224, + 6,248,128,128,240,128,128,248, + 6,248,128,128,240,128,128,128, + 6,112,136,128,184,136,136,120, + 6,136,136,136,248,136,136,136, + 4,224, 64, 64, 64, 64, 64,224, + 6, 8, 8, 8, 8, 8,136,112, + 6,136,144,160,192,160,144,136, + 6,128,128,128,128,128,128,248, + 6,136,216,168,168,136,136,136, + 6,136,136,200,168,152,136,136, + 7, 48, 72,132,132,132, 72, 48, + 6,240,136,136,240,128,128,128, + 6,112,136,136,136,168,144,104, + 6,240,136,136,240,144,136,136, + 6,112,136,128,112, 8,136,112, + 6,248, 32, 32, 32, 32, 32, 32, + 6,136,136,136,136,136,136,112, + 6,136,136,136, 80, 80, 32, 32, + 6,136,136,136,136,168,168, 80, + 6,136,136, 80, 32, 80,136,136, + 6,136,136, 80, 32, 32, 32, 32, + 6,248, 8, 16, 32, 64,128,248, + 3,192,128,128,128,128,128,192, + 5, 64, 64, 32, 32, 32, 16, 16, + 3,192, 64, 64, 64, 64, 64,192, + 4, 64,160, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 0, 0, 0,248, + 3,128, 64, 0, 0, 0, 0, 0, + 5, 0, 0, 96, 16,112,144,112, // 0x61 - a + 5,128,128,224,144,144,144,224, + 5, 0, 0,112,128,128,128,112, + 5, 16, 16,112,144,144,144,112, + 5, 0, 0, 96,144,240,128,112, + 5, 48, 64,224, 64, 64, 64, 64, + 5, 0,112,144,144,112, 16,224, + 5,128,128,224,144,144,144,144, + 2,128, 0,128,128,128,128,128, + 4, 32, 0, 32, 32, 32, 32,192, + 5,128,128,144,160,192,160,144, + 2,128,128,128,128,128,128,128, + 6, 0, 0,208,168,168,168,168, + 5, 0, 0,224,144,144,144,144, + 5, 0, 0, 96,144,144,144, 96, + 5, 0, 0,224,144,144,224,128, + 5, 0, 0,112,144,144,112, 16, + 5, 0, 0,176,192,128,128,128, + 5, 0, 0,112,128, 96, 16,224, + 4, 64, 64,224, 64, 64, 64, 32, + 5, 0, 0,144,144,144,144,112, + 5, 0, 0,144,144,144,160,192, + 6, 0, 0,136,136,168,168, 80, + 5, 0, 0,144,144, 96,144,144, + 5, 0,144,144,144,112, 16, 96, + 5, 0, 0,240, 32, 64,128,240, + 4, 32, 64, 64,128, 64, 64, 32, + 3, 64, 64, 64, 64, 64, 64, 64, + 4,128, 64, 64, 32, 64, 64,128, + 6, 0,104,176, 0, 0, 0, 0 +}; + +void DrawTextLineBG(uint8 *dest) +{ + int x,y; + static int otable[7]={81,49,30,17,8,3,0}; + //100,40,15,10,7,5,2}; + for(y=0;y<14;y++) + { + int offs; + + if(y>=7) offs=otable[13-y]; + else offs=otable[y]; + + for(x=offs;x<(256-offs);x++) + { + // Choose the dimmest set of colours and then dim that + dest[y*256+x]=(dest[y*256+x]&0x0F)|0xC0; + } + } +} + + +void DrawMessage(bool beforeMovie) +{ + if(guiMessage.howlong) + { + //don't display movie messages if we're not before the movie + if(beforeMovie && !guiMessage.isMovieMessage) + return; + + uint8 *t; + guiMessage.howlong--; + + if (guiMessage.linesFromBottom > 0) + t=XBuf+FCEU_TextScanlineOffsetFromBottom(guiMessage.linesFromBottom)+1; + else + t=XBuf+FCEU_TextScanlineOffsetFromBottom(20)+1; + + /* + FCEU palette: + $00: [8] unvpalette found in palettes/palettes.h + black, white, black, greyish, redish, bright green, bluish + $80: + nes palette + $C0: + dim version of nes palette + + */ + + if(t>=XBuf) + { + int color = 0x20; + if(guiMessage.howlong <= 40) color = 0x3C; + if(guiMessage.howlong <= 32) color = 0x31; + if(guiMessage.howlong <= 24) color = 0x21; + if(guiMessage.howlong <= 16) color = 0x51; + if(guiMessage.howlong <= 8) color = 0x41; + DrawTextTrans(ClipSidesOffset+t, 256, (uint8 *)guiMessage.errmsg, color+0x80); + } + } + + if(subtitleMessage.howlong) + { + //don't display movie messages if we're not before the movie + if(beforeMovie && !subtitleMessage.isMovieMessage) + return; + + uint8 *tt; + subtitleMessage.howlong--; + tt=XBuf+FCEU_TextScanlineOffsetFromBottom(216); + + if(tt>=XBuf) + { + int color = 0x20; + if(subtitleMessage.howlong == 39) color = 0x38; + if(subtitleMessage.howlong <= 30) color = 0x2C; + if(subtitleMessage.howlong <= 20) color = 0x1C; + if(subtitleMessage.howlong <= 10) color = 0x11; + if(subtitleMessage.howlong <= 5) color = 0x1; + DrawTextTrans(ClipSidesOffset+tt, 256, (uint8 *)subtitleMessage.errmsg, color+0x80); + } + } +} + + + + +static uint8 sstat[2541] = +{ + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83, + 0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x83,0x83,0x83, + 0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x80,0x83, + 0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81, + 0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x81,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, + 0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83, + 0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83, + 0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83, + 0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83, + 0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x83,0x80,0x80,0x81,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x80,0x83,0x83,0x81,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x81,0x81,0x81,0x83,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80 +}; + + + + + +static uint8 play_slines[]= +{ + 0, 0, 1, + 1, 0, 2, + 2, 0, 3, + 3, 0, 4, + 4, 0, 5, + 5, 0, 6, + 6, 0, 7, + 7, 0, 8, + 8, 0, 7, + 9, 0, 6, + 10, 0, 5, + 11, 0, 4, + 12, 0, 3, + 13, 0, 2, + 14, 0, 1, + 99, +}; + +static uint8 record_slines[]= +{ + 0, 5, 9, + 1, 3, 11, + 2, 2, 12, + 3, 1, 13, + 4, 1, 13, + 5, 0, 14, + 6, 0, 14, + 7, 0, 14, + 8, 0, 14, + 9, 0, 14, + 10, 1, 13, + 11, 1, 13, + 12, 2, 12, + 13, 3, 11, + 14, 5, 9, + 99, +}; + +static uint8 pause_slines[]= +{ + 0, 2, 6, + 1, 2, 6, + 2, 2, 6, + 3, 2, 6, + 4, 2, 6, + 5, 2, 6, + 6, 2, 6, + 7, 2, 6, + 8, 2, 6, + 9, 2, 6, + 10, 2, 6, + 11, 2, 6, + 12, 2, 6, + 13, 2, 6, + 14, 2, 6, + + 0, 9, 13, + 1, 9, 13, + 2, 9, 13, + 3, 9, 13, + 4, 9, 13, + 5, 9, 13, + 6, 9, 13, + 7, 9, 13, + 8, 9, 13, + 9, 9, 13, + 10, 9, 13, + 11, 9, 13, + 12, 9, 13, + 13, 9, 13, + 14, 9, 13, + 99, +}; + +static uint8 no_slines[]= +{ + 99 +}; + +static uint8* sline_icons[4]= +{ + no_slines, + play_slines, + record_slines, + pause_slines +}; + +static void drawstatus(uint8* XBuf, int n, int y, int xofs) +{ + uint8* slines=sline_icons[n]; + int i; + + + XBuf += FCEU_TextScanlineOffsetFromBottom(y) + 240 + 255 + xofs; + for(i=0; slines[i]!=99; i+=3) + { + int y=slines[i]; + uint8* dest=XBuf+(y*256); + int x; + for(x=slines[i+1]; x!=slines[i+2]; ++x) + dest[x]=0; + } + + XBuf -= 255; + for(i=0; slines[i]!=99; i+=3) + { + int y=slines[i]; + uint8* dest=XBuf+(y*256); + int x; + for(x=slines[i+1]; x!=slines[i+2]; ++x) + dest[x]=4; + } +} + +/// this draws the recording icon (play/pause/record) +void FCEU_DrawRecordingStatus(uint8* XBuf) +{ + if(FCEUD_ShowStatusIcon()) + { + bool hasPlayRecIcon = false; + if(FCEUMOV_Mode(MOVIEMODE_RECORD)) + { + drawstatus(XBuf-ClipSidesOffset,2,28,0); + hasPlayRecIcon = true; + } + else if(FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_FINISHED)) + { + drawstatus(XBuf-ClipSidesOffset,1,28,0); + hasPlayRecIcon = true; + } + + if(FCEUI_EmulationPaused()) + drawstatus(XBuf-ClipSidesOffset,3,28,hasPlayRecIcon?-16:0); + } +} + + +void FCEU_DrawNumberRow(uint8 *XBuf, int *nstatus, int cur) +{ + uint8 *XBaf; + int z,x,y; + + XBaf=XBuf - 4 + (FSettings.LastSLine-34)*256; + if(XBaf>=XBuf) + for(z=1;z<11;z++) + { + if(nstatus[z%10]) + { + for(y=0;y<13;y++) + for(x=0;x<21;x++) + XBaf[y*256+x+z*21+z]=sstat[y*21+x+(z-1)*21*12]^0x80; + } else { + for(y=0;y<13;y++) + for(x=0;x<21;x++) + if(sstat[y*21+x+(z-1)*21*12]!=0x83) + XBaf[y*256+x+z*21+z]=sstat[y*21+x+(z-1)*21*12]^0x80; + + else + XBaf[y*256+x+z*21+z]=(XBaf[y*256+x+z*21+z]&0xF)|0xC0; + } + if(cur==z%10) + { + for(x=0;x<21;x++) + XBaf[x+z*21+z*1]=4; + for(x=1;x<12;x++) + { + XBaf[256*x+z*21+z*1]= + XBaf[256*x+z*21+z*1+20]=4; + } + for(x=0;x<21;x++) + XBaf[12*256+x+z*21+z*1]=4; + } + } +} + +static int FixJoedChar(uint8 ch) +{ + int c = ch - 32; + return (c < 0 || c > 98) ? 0 : c; +} +static int JoedCharWidth(uint8 ch) +{ + return Font6x7[FixJoedChar(ch)*8]; +} + +char target[64][256]; + +void DrawTextTransWH(uint8 *dest, int width, uint8 *textmsg, uint8 fgcolor, int max_w, int max_h, int border) +{ + int beginx=2, x=beginx; + int y=2; + + memset(target, 0, 64 * 256); + + assert(width==256); + if (max_w > 256) max_w = 256; + if (max_h > 64) max_h = 64; + + int ch = 0, wid = 0, nx = 0, ny = 0, max_x = x, offs = 0; + int pixel_color; + for(; *textmsg; ++textmsg) + { + if(*textmsg == '\n') + { + // new line + x = beginx; + y += 8; + continue; + } + ch = FixJoedChar(*textmsg); + wid = Font6x7[ch * 8]; + + if ((x + wid) >= (int)width) + { + // wrap to new line + x = beginx; + y += 8; + } + + for(ny = 0; ny < 7; ++ny) + { + uint8 d = Font6x7[ch * 8 + 1 + ny]; + for(nx = 0; nx < wid; ++nx) + { + pixel_color = (d >> (7 - nx)) & 1; + if (pixel_color) + { + if (y + ny >= 62) + { + // Max border is 2, so the max safe y is 62 (since 64 is the max for the target array + goto textoverflow; + } + target[y + ny][x + nx] = 2; + } else + { + target[y + ny][x + nx] = 1; + } + } + } + // proceed to next char + x += wid; + if (max_x < x) + max_x = x; + + } +textoverflow: + + max_x += 2; + if (max_x > width) + max_x = width; + int max_y = y + ny + 2; + if (max_y > 62) + max_y = 62; + + // draw target buffer to screen buffer + for (y = 0; y < max_y; ++y) + { + for (x = 0; x < max_x; ++x) + { + offs = y * width + x; + pixel_color = target[y][x] * 100; + + if(border>=1) + { + x>=( 1) && (pixel_color += target[y][x-1]); + x<(width-1) && (pixel_color += target[y][x+1]); + y>=( 1) && (pixel_color += target[y-1][x]); + y<(16 -1) && (pixel_color += target[y+1][x]); + } + if(border>=2) + { + x>=( 1) && (pixel_color += target[y][x-1]*10); + x<(width-1) && (pixel_color += target[y][x+1]*10); + y>=( 1) && (pixel_color += target[y-1][x]*10); + y<(16 -1) && (pixel_color += target[y+1][x]*10); + + x>=( 1) && y>=( 1) && (pixel_color += target[y-1][x-1]); + x<(width-1) && y>=( 1) && (pixel_color += target[y-1][x+1]); + x>=( 1) && y<(16-1) && (pixel_color += target[y+1][x-1]); + x<(width-1) && y<(16-1) && (pixel_color += target[y+1][x+1]); + + x>=( 2) && (pixel_color += target[y][x-2]); + x<(width-2) && (pixel_color += target[y][x+2]); + y>=( 2) && (pixel_color += target[y-2][x]); + y<(16 -2) && (pixel_color += target[y+2][x]); + } + + if(pixel_color >= 200) + dest[offs] = fgcolor; + else if(pixel_color >= 10) + { + if(dest[offs] < 0xA0) + dest[offs] = 0xC1; + else + dest[offs] = 0xD1; + } + else if(pixel_color > 0) + { + dest[offs] = 0xCF; + } + } + } +} + +void DrawTextTrans(uint8 *dest, uint32 width, uint8 *textmsg, uint8 fgcolor) +{ + DrawTextTransWH(dest, width, textmsg, fgcolor, 256, 16, 2); +} diff --git a/branches/fceux-2.2.2/src/drawing.h b/branches/fceux-2.2.2/src/drawing.h new file mode 100644 index 00000000..9ec8e50e --- /dev/null +++ b/branches/fceux-2.2.2/src/drawing.h @@ -0,0 +1,6 @@ +void DrawTextLineBG(uint8 *dest); +void DrawMessage(bool beforeMovie); +void FCEU_DrawRecordingStatus(uint8* XBuf); +void FCEU_DrawNumberRow(uint8 *XBuf, int *nstatus, int cur); +void DrawTextTrans(uint8 *dest, uint32 width, uint8 *textmsg, uint8 fgcolor); +void DrawTextTransWH(uint8 *dest, int width, uint8 *textmsg, uint8 fgcolor, int max_w, int max_h, int border); diff --git a/branches/fceux-2.2.2/src/driver.h b/branches/fceux-2.2.2/src/driver.h new file mode 100644 index 00000000..d7474aa5 --- /dev/null +++ b/branches/fceux-2.2.2/src/driver.h @@ -0,0 +1,349 @@ +#ifndef __DRIVER_H_ +#define __DRIVER_H_ + +#include "types.h" +#include "git.h" +#include "file.h" + +#include +#include +#include + +FILE *FCEUD_UTF8fopen(const char *fn, const char *mode); +inline FILE *FCEUD_UTF8fopen(const std::string &n, const char *mode) { return FCEUD_UTF8fopen(n.c_str(),mode); } +EMUFILE_FILE* FCEUD_UTF8_fstream(const char *n, const char *m); +inline EMUFILE_FILE* FCEUD_UTF8_fstream(const std::string &n, const char *m) { return FCEUD_UTF8_fstream(n.c_str(),m); } +FCEUFILE* FCEUD_OpenArchiveIndex(ArchiveScanRecord& asr, std::string& fname, int innerIndex); +FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename); +ArchiveScanRecord FCEUD_ScanArchive(std::string fname); + +//mbg 7/23/06 +const char *FCEUD_GetCompilerString(); + +//This makes me feel dirty for some reason. +void FCEU_printf(char *format, ...); +#define FCEUI_printf FCEU_printf + +//Video interface +void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b); +void FCEUD_GetPalette(uint8 i,uint8 *r, uint8 *g, uint8 *b); + +//Displays an error. Can block or not. +void FCEUD_PrintError(const char *s); +void FCEUD_Message(const char *s); + +//Network interface + +//Call only when a game is loaded. +int FCEUI_NetplayStart(int nlocal, int divisor); + +// Call when network play needs to stop. +void FCEUI_NetplayStop(void); + +//Note: YOU MUST NOT CALL ANY FCEUI_* FUNCTIONS WHILE IN FCEUD_SendData() or FCEUD_RecvData(). + +//Return 0 on failure, 1 on success. +int FCEUD_SendData(void *data, uint32 len); +int FCEUD_RecvData(void *data, uint32 len); + +//Display text received over the network. +void FCEUD_NetplayText(uint8 *text); + +//Encode and send text over the network. +void FCEUI_NetplayText(uint8 *text); + +//Called when a fatal error occurred and network play can't continue. This function +//should call FCEUI_NetplayStop() after it has deinitialized the network on the driver +//side. +void FCEUD_NetworkClose(void); + +bool FCEUI_BeginWaveRecord(const char *fn); +int FCEUI_EndWaveRecord(void); + +void FCEUI_ResetNES(void); +void FCEUI_PowerNES(void); + +void FCEUI_NTSCSELHUE(void); +void FCEUI_NTSCSELTINT(void); +void FCEUI_NTSCDEC(void); +void FCEUI_NTSCINC(void); +void FCEUI_GetNTSCTH(int *tint, int *hue); +void FCEUI_SetNTSCTH(int n, int tint, int hue); + +void FCEUI_SetInput(int port, ESI type, void *ptr, int attrib); +void FCEUI_SetInputFC(ESIFC type, void *ptr, int attrib); + +//tells the emulator whether a fourscore is attached +void FCEUI_SetInputFourscore(bool attachFourscore); +//tells whether a fourscore is attached +bool FCEUI_GetInputFourscore(); +//tells whether the microphone is used +bool FCEUI_GetInputMicrophone(); + +void FCEUI_UseInputPreset(int preset); + + +//New interface functions + +//0 to order screen snapshots numerically(0.png), 1 to order them file base-numerically(smb3-0.png). +//this variable isn't used at all, snap is always name-based +//void FCEUI_SetSnapName(bool a); + +//0 to keep 8-sprites limitation, 1 to remove it +void FCEUI_DisableSpriteLimitation(int a); + +void FCEUI_SetRenderPlanes(bool sprites, bool bg); +void FCEUI_GetRenderPlanes(bool& sprites, bool& bg); + +//name=path and file to load. returns null if it failed +FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode, bool silent = false); + +//same as FCEUI_LoadGame, except that it can load from a tempfile. +//name is the logical path to open; archiveFilename is the archive which contains name +FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silent = false); + +//general purpose emulator initialization. returns true if successful +bool FCEUI_Initialize(); + +//Emulates a frame. +void FCEUI_Emulate(uint8 **, int32 **, int32 *, int); + +//Closes currently loaded game +void FCEUI_CloseGame(void); + +//Deallocates all allocated memory. Call after FCEUI_Emulate() returns. +void FCEUI_Kill(void); + +//Enable/Disable game genie. a=true->enabled +void FCEUI_SetGameGenie(bool a); + +//Set video system a=0 NTSC, a=1 PAL +void FCEUI_SetVidSystem(int a); + +//Convenience function; returns currently emulated video system(0=NTSC, 1=PAL). +int FCEUI_GetCurrentVidSystem(int *slstart, int *slend); + +#ifdef FRAMESKIP +/* Should be called from FCEUD_BlitScreen(). Specifies how many frames + to skip until FCEUD_BlitScreen() is called. FCEUD_BlitScreenDummy() + will be called instead of FCEUD_BlitScreen() when when a frame is skipped. +*/ +void FCEUI_FrameSkip(int x); +#endif + +//First and last scanlines to render, for ntsc and pal emulation. +void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); + +//Sets the base directory(save states, snapshots, etc. are saved in directories below this directory. +void FCEUI_SetBaseDirectory(std::string const & dir); + +//Tells FCE Ultra to copy the palette data pointed to by pal and use it. +//Data pointed to by pal needs to be 64*3 bytes in length. +void FCEUI_SetPaletteArray(uint8 *pal); + +//Sets up sound code to render sound at the specified rate, in samples +//per second. Only sample rates of 44100, 48000, and 96000 are currently supported. +//If "Rate" equals 0, sound is disabled. +void FCEUI_Sound(int Rate); +void FCEUI_SetSoundVolume(uint32 volume); +void FCEUI_SetTriangleVolume(uint32 volume); +void FCEUI_SetSquare1Volume(uint32 volume); +void FCEUI_SetSquare2Volume(uint32 volume); +void FCEUI_SetNoiseVolume(uint32 volume); +void FCEUI_SetPCMVolume(uint32 volume); + +void FCEUI_SetSoundQuality(int quality); + +void FCEUD_SoundToggle(void); +void FCEUD_SoundVolumeAdjust(int); + +int FCEUI_SelectState(int, int); +extern void FCEUI_SelectStateNext(int); + +//"fname" overrides the default save state filename code if non-NULL. +void FCEUI_SaveState(const char *fname, bool display_message=true); +void FCEUI_LoadState(const char *fname, bool display_message=true); + +void FCEUD_SaveStateAs(void); +void FCEUD_LoadStateFrom(void); + +//at the minimum, you should call FCEUI_SetInput, FCEUI_SetInputFC, and FCEUI_SetInputFourscore +//you may also need to maintain your own internal state +void FCEUD_SetInput(bool fourscore, bool microphone, ESI port0, ESI port1, ESIFC fcexp); + + +void FCEUD_MovieRecordTo(void); +void FCEUD_MovieReplayFrom(void); +void FCEUD_LuaRunFrom(void); + +int32 FCEUI_GetDesiredFPS(void); +void FCEUI_SaveSnapshot(void); +void FCEUI_SaveSnapshotAs(void); +void FCEU_DispMessage(char *format, int disppos, ...); +#define FCEUI_DispMessage FCEU_DispMessage + +int FCEUI_DecodePAR(const char *code, int *a, int *v, int *c, int *type); +int FCEUI_DecodeGG(const char *str, int *a, int *v, int *c); +int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type); +int FCEUI_DelCheat(uint32 which); +int FCEUI_ToggleCheat(uint32 which); + +int32 FCEUI_CheatSearchGetCount(void); +void FCEUI_CheatSearchGetRange(uint32 first, uint32 last, int (*callb)(uint32 a, uint8 last, uint8 current)); +void FCEUI_CheatSearchGet(int (*callb)(uint32 a, uint8 last, uint8 current, void *data), void *data); +void FCEUI_CheatSearchBegin(void); +void FCEUI_CheatSearchEnd(int type, uint8 v1, uint8 v2); +void FCEUI_ListCheats(int (*callb)(char *name, uint32 a, uint8 v, int compare, int s, int type, void *data), void *data); + +int FCEUI_GetCheat(uint32 which, char **name, uint32 *a, uint8 *v, int *compare, int *s, int *type); +int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int compare,int s, int type); + +void FCEUI_CheatSearchShowExcluded(void); +void FCEUI_CheatSearchSetCurrentAsOriginal(void); + +//.rom +#define FCEUIOD_ROMS 0 //Roms +#define FCEUIOD_NV 1 //NV = nonvolatile. save data. +#define FCEUIOD_STATES 2 //savestates +#define FCEUIOD_FDSROM 3 //disksys.rom +#define FCEUIOD_SNAPS 4 //screenshots +#define FCEUIOD_CHEATS 5 //cheats +#define FCEUIOD_MOVIES 6 //.fm2 files +#define FCEUIOD_MEMW 7 //memory watch fiels +#define FCEUIOD_BBOT 8 //basicbot, obsolete +#define FCEUIOD_MACRO 9 //macro files - old TASEdit v0.1 paradigm, not implemented, probably obsolete +#define FCEUIOD_INPUT 10 //input presets +#define FCEUIOD_LUA 11 //lua scripts +#define FCEUIOD_AVI 12 //default file for avi output +#define FCEUIOD__COUNT 13 //base directory override? + +void FCEUI_SetDirOverride(int which, char *n); + +void FCEUI_MemDump(uint16 a, int32 len, void (*callb)(uint16 a, uint8 v)); +uint8 FCEUI_MemSafePeek(uint16 A); +void FCEUI_MemPoke(uint16 a, uint8 v, int hl); +void FCEUI_NMI(void); +void FCEUI_IRQ(void); +uint16 FCEUI_Disassemble(void *XA, uint16 a, char *stringo); +void FCEUI_GetIVectors(uint16 *reset, uint16 *irq, uint16 *nmi); + +uint32 FCEUI_CRC32(uint32 crc, uint8 *buf, uint32 len); + +void FCEUI_SetLowPass(int q); + +void FCEUI_NSFSetVis(int mode); +int FCEUI_NSFChange(int amount); +int FCEUI_NSFGetInfo(uint8 *name, uint8 *artist, uint8 *copyright, int maxlen); + +void FCEUI_VSUniToggleDIPView(void); +void FCEUI_VSUniToggleDIP(int w); +uint8 FCEUI_VSUniGetDIPs(void); +void FCEUI_VSUniSetDIP(int w, int state); +void FCEUI_VSUniCoin(void); + +void FCEUI_FDSInsert(void); //mbg merge 7/17/06 changed to void fn(void) to make it an EMUCMDFN +//int FCEUI_FDSEject(void); +void FCEUI_FDSSelect(void); + +int FCEUI_DatachSet(const uint8 *rcode); + +///returns a flag indicating whether emulation is paused +int FCEUI_EmulationPaused(); +///returns a flag indicating whether a one frame step has been requested +int FCEUI_EmulationFrameStepped(); +///clears the framestepped flag. use it after youve stepped your one frame +void FCEUI_ClearEmulationFrameStepped(); +///sets the EmulationPaused flags +void FCEUI_SetEmulationPaused(int val); +///toggles the paused bit (bit0) for EmulationPaused. caused FCEUD_DebugUpdate() to fire if the emulation pauses +void FCEUI_ToggleEmulationPause(); + +//indicates whether input aids should be drawn (such as crosshairs, etc; usually in fullscreen mode) +bool FCEUD_ShouldDrawInputAids(); + +///called when the emulator closes a game +void FCEUD_OnCloseGame(void); + +void FCEUI_FrameAdvance(void); +void FCEUI_FrameAdvanceEnd(void); + +//AVI Output +int FCEUI_AviBegin(const char* fname); +void FCEUI_AviEnd(void); +void FCEUI_AviVideoUpdate(const unsigned char* buffer); +void FCEUI_AviSoundUpdate(void* soundData, int soundLen); +bool FCEUI_AviIsRecording(); +bool FCEUI_AviEnableHUDrecording(); +void FCEUI_SetAviEnableHUDrecording(bool enable); +bool FCEUI_AviDisableMovieMessages(); +void FCEUI_SetAviDisableMovieMessages(bool disable); + +void FCEUD_AviRecordTo(void); +void FCEUD_AviStop(void); + +///A callback that the emu core uses to poll the state of a given emulator command key +typedef int TestCommandState(int cmd); +///Signals the emu core to poll for emulator commands and take actions +void FCEUI_HandleEmuCommands(TestCommandState* testfn); + + +//Emulation speed +enum EMUSPEED_SET +{ + EMUSPEED_SLOWEST=0, + EMUSPEED_SLOWER, + EMUSPEED_NORMAL, + EMUSPEED_FASTER, + EMUSPEED_FASTEST +}; +void FCEUD_SetEmulationSpeed(int cmd); +void FCEUD_TurboOn(void); +void FCEUD_TurboOff(void); +void FCEUD_TurboToggle(void); + +int FCEUD_ShowStatusIcon(void); +void FCEUD_ToggleStatusIcon(void); +void FCEUD_HideMenuToggle(void); + +///signals the driver to perform a file open GUI operation +void FCEUD_CmdOpen(void); + +//new merge-era driver routines here: + +///signals that the cpu core hit a breakpoint. this function should not return until the core is ready for the next cycle +void FCEUD_DebugBreakpoint(int bp_num); + +///the driver should log the current instruction, if it wants (we should move the code in the win driver that does this to the shared area) +void FCEUD_TraceInstruction(uint8 *opcode, int size); + +///the driver might should update its NTView (only used if debugging support is compiled in) +void FCEUD_UpdateNTView(int scanline, bool drawall); + +///the driver might should update its PPUView (only used if debugging support is compiled in) +void FCEUD_UpdatePPUView(int scanline, int drawall); + +///I am dissatisfied with this method of getting an option from the driver to the core. but that is what we're using for now +bool FCEUD_PauseAfterPlayback(); + +///called when fceu changes something in the video system you might be interested in +void FCEUD_VideoChanged(); + +enum EFCEUI +{ + FCEUI_STOPAVI, FCEUI_QUICKSAVE, FCEUI_QUICKLOAD, FCEUI_SAVESTATE, FCEUI_LOADSTATE, + FCEUI_NEXTSAVESTATE,FCEUI_PREVIOUSSAVESTATE,FCEUI_VIEWSLOTS, + FCEUI_STOPMOVIE, FCEUI_RECORDMOVIE, FCEUI_PLAYMOVIE, + FCEUI_OPENGAME, FCEUI_CLOSEGAME, + FCEUI_TASEDITOR, + FCEUI_RESET, FCEUI_POWER, FCEUI_PLAYFROMBEGINNING, FCEUI_EJECT_DISK, FCEUI_SWITCH_DISK, FCEUI_INSERT_COIN +}; + +//checks whether an EFCEUI is valid right now +bool FCEU_IsValidUI(EFCEUI ui); + +#ifdef __cplusplus +extern "C" +#endif +FILE *FCEUI_UTF8fopen_C(const char *n, const char *m); + +#endif //__DRIVER_H_ diff --git a/branches/fceux-2.2.2/src/drivers/common/SConscript b/branches/fceux-2.2.2/src/drivers/common/SConscript new file mode 100644 index 00000000..3d39b224 --- /dev/null +++ b/branches/fceux-2.2.2/src/drivers/common/SConscript @@ -0,0 +1,6 @@ +import glob +source_list = glob.glob('*.cpp') + glob.glob('*.c') + +for x in range(len(source_list)): + source_list[x] = 'drivers/common/' + source_list[x] +Return('source_list') diff --git a/branches/fceux-2.2.2/src/drivers/common/args.cpp b/branches/fceux-2.2.2/src/drivers/common/args.cpp new file mode 100644 index 00000000..4167b8f5 --- /dev/null +++ b/branches/fceux-2.2.2/src/drivers/common/args.cpp @@ -0,0 +1,108 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 + */ + +/****************************************************************/ +/* FCE Ultra */ +/* */ +/* This file contains code for parsing command-line */ +/* options. */ +/* */ +/****************************************************************/ + +#include +#include +#include + +#include "../../types.h" +#include "args.h" + +int ParseEA(int x, int argc, char *argv[], ARGPSTRUCT *argsps) +{ + int y=0; + int ret=1; + + do + { + if(!argsps[y].name) + { + ParseEA(x,argc,argv,(ARGPSTRUCT*)argsps[y].var); + y++; + continue; + } + if(!strcmp(argv[x],argsps[y].name)) // A match. + { + //ret++; + if(argsps[y].subs) + { + if((x+1)>=argc) + break; + ret++; + if(argsps[y].substype&0x2000) + { + ((void (*)(char *))argsps[y].subs)(argv[x+1]); + } + else if(argsps[y].substype&0x8000) + { + *(int *)argsps[y].subs&=~(argsps[y].substype&(~0x8000)); + *(int *)argsps[y].subs|=atoi(argv[x+1])?(argsps[y].substype&(~0x8000)):0; + } + else + switch(argsps[y].substype&(~0x4000)) + { + case 0: // Integer + *(int *)argsps[y].subs=atoi(argv[x+1]); + break; + case 2: // Double float + *(double *)argsps[y].subs=atof(argv[x+1]); + break; + case 1: // String + if(argsps[y].substype&0x4000) + { + if(*(char **)argsps[y].subs) + free(*(char **)argsps[y].subs); + if(!( *(char **)argsps[y].subs=(char*)malloc(strlen(argv[x+1])+1) )) + break; + } + strcpy(*(char **)argsps[y].subs,argv[x+1]); + break; + } + } + if(argsps[y].var) + *argsps[y].var=1; + } + y++; + } while(argsps[y].var || argsps[y].subs); + return ret; +} + +int ParseArguments(int argc, char *argv[], ARGPSTRUCT *argsps) +{ + int x; + + for(x=0;x +#include +#include "../../driver.h" +#include "../../fceu.h" + +static void GetString(char *s, int max) +{ + int x; + fgets(s,max,stdin); + + for(x=0;x "); + fgets(buf,ARRAY_SIZE(buf),stdin); + if(buf[0]=='s' || buf[0]=='S') return(-1); + if(buf[0]=='\n') return(0); + if(!sscanf(buf,"%d",&num)) + return(0); + if(num<1) goto tryagain; + return(num); + } + else + { + int num=0; + + tryagain2: + printf(" <'Enter' to make no selection or enter a number.> "); + fgets(buf,ARRAY_SIZE(buf),stdin); + if(buf[0]=='\n') return(0); + if(!sscanf(buf,"%d",&num)) + return(0); + if(num<1) goto tryagain2; + return(num); + } +} + +int EndListShow(void) +{ + if(mordoe) + { + int r=ListChoice(1); + if(r>0 && r<=listcount) + listsel=listids[r-1]; + } + return(listsel); +} + +/* Returns 0 to stop listing, 1 to continue. */ +int AddToList(char *text, uint32 id) +{ + if(listcount==16) + { + int t=ListChoice(0); + mordoe=0; + if(t==-1) return(0); // Stop listing. + else if(t>0 && t<17) + { + listsel=listids[t-1]; + return(0); + } + listcount=0; + } + mordoe=1; + listids[listcount]=id; + printf("%2d) %s\n",listcount+1,text); + listcount++; + return(1); +} + +/* +** +** End list code. +**/ + +typedef struct MENU { + char *text; + void *action; + int type; // 0 for menu, 1 for function. +} MENU; + +static void SetOC(void) +{ + FCEUI_CheatSearchSetCurrentAsOriginal(); +} + +static void UnhideEx(void) +{ + FCEUI_CheatSearchShowExcluded(); +} + +static void ToggleCheat(int num) +{ + printf("Cheat %d %sabled.\n",1+num, + FCEUI_ToggleCheat(num)?"en":"dis"); +} + +static void ModifyCheat(int num) +{ + char *name; + char buf[256]; + uint32 A; + uint8 V; + int compare; + int type; + + int s; + int t; + + FCEUI_GetCheat(num, &name, &A, &V, &compare, &s, &type); + + printf("Name [%s]: ",name); + GetString(buf,256); + + /* This obviously doesn't allow for cheats with no names. Bah. Who wants + nameless cheats anyway... + */ + + if(buf[0]) + name=buf; // Change name when FCEUI_SetCheat() is called. + else + name=0; // Don't change name when FCEUI_SetCheat() is called. + + printf("Address [$%04x]: ",(unsigned int)A); + A=GetH16(A); + + printf("Value [%03d]: ",(unsigned int)V); + V=Get8(V); + + printf("Compare [%3d]: ",compare); + compare=GetI(compare); + + printf("Type(0=Old Style, 1=Read Substitute) [%1d]: ",type); + type=GetI(type)?1:0; + + printf("Enable [%s]: ",s?"Y":"N"); + t=getchar(); + if(t=='Y' || t=='y') s=1; + else if(t=='N' || t=='n') s=0; + + FCEUI_SetCheat(num,name,A,V,compare,s,type); +} + + +static void AddCheatGGPAR(int which) +{ + int A, V, C; + int type; + char name[256],code[256]; + + printf("Name: "); + GetString(name,256); + + printf("Code: "); + GetString(code,256); + + printf("Add cheat \"%s\" for code \"%s\"?",name,code); + if(GetYN(0)) + { + if(which) + { + if(!FCEUI_DecodePAR(code,&A,&V,&C,&type)) + { + puts("Invalid Game Genie code."); + return; + } + } + else + { + if(!FCEUI_DecodeGG(code,&A,&V,&C)) + { + puts("Invalid Game Genie code."); + return; + } + type=1; + } + + if(FCEUI_AddCheat(name,A,V,C,type)) + puts("Cheat added."); + else + puts("Error adding cheat."); + } +} + +static void AddCheatGG(void) +{ + AddCheatGGPAR(0); +} + +static void AddCheatPAR(void) +{ + AddCheatGGPAR(1); +} + +static void AddCheatParam(uint32 A, uint8 V) +{ + char name[256]; + + printf("Name: "); + GetString(name,256); + printf("Address [$%04x]: ",(unsigned int)A); + A=GetH16(A); + printf("Value [%03d]: ",(unsigned int)V); + V=Get8(V); + printf("Add cheat \"%s\" for address $%04x with value %03d?",name,(unsigned int)A,(unsigned int)V); + if(GetYN(0)) + { + if(FCEUI_AddCheat(name,A,V,-1,0)) + puts("Cheat added."); + else + puts("Error adding cheat."); + } +} + +static void AddCheat(void) +{ + AddCheatParam(0,0); +} + +static int lid; +static int clistcallb(char *name, uint32 a, uint8 v, int compare, int s, int type, void *data) +{ + char tmp[512]; + int ret; + + if(compare>=0) + sprintf(tmp,"%s $%04x:%03d:%03d - %s",s?"*":" ",(unsigned int)a,(unsigned int)v,compare,name); + else + sprintf(tmp,"%s $%04x:%03d - %s",s?"*":" ",(unsigned int)a,(unsigned int)v,name); + if(type==1) + tmp[2]='S'; + ret=AddToList(tmp,lid); + lid++; + return(ret); +} + +static void ListCheats(void) +{ + int which; + lid=0; + + BeginListShow(); + FCEUI_ListCheats(clistcallb,0); + which=EndListShow(); + if(which>=0) + { + char tmp[32]; + printf(" <(T)oggle status, (M)odify, or (D)elete this cheat.> "); + fgets(tmp,ARRAY_SIZE(tmp),stdin); + switch(tolower(tmp[0])) + { + case 't':ToggleCheat(which); + break; + case 'd':if(!FCEUI_DelCheat(which)) + puts("Error deleting cheat!"); + else + puts("Cheat has been deleted."); + break; + case 'm':ModifyCheat(which); + break; + } + } +} + +static void ResetSearch(void) +{ + FCEUI_CheatSearchBegin(); + puts("Done."); +} + +static int srescallb(uint32 a, uint8 last, uint8 current, void *data) +{ + char tmp[14]; + sprintf(tmp, "$%04x:%03d:%03d",(unsigned int)a,(unsigned int)last,(unsigned int)current); + return(AddToList(tmp,a)); +} + +static void ShowRes(void) +{ + int n=FCEUI_CheatSearchGetCount(); + printf(" %d results:\n",n); + if(n) + { + int which; + BeginListShow(); + FCEUI_CheatSearchGet(srescallb,0); + which=EndListShow(); + if(which>=0) + AddCheatParam(which,0); + } +} + +static int ShowShortList(char *moe[], int n, int def) +{ + int x,c; + int baa; //mbg merge 7/17/06 made to normal int + char tmp[256]; + + red: + for(x=0;x ",def+1); + fgets(tmp,ARRAY_SIZE(tmp),stdin); + if(tmp[0]=='\n') + return def; + c=tolower(tmp[0]); + baa=c-'1'; + + if(baaC)", + "Value increased by V2 (|C-O|==V2)", + "Value decreased by V2 (|O-C|==V2)"}; + int av[9]={ASK_V1|ASK_V2, + ASK_V1|ASK_V2, + ASK_V2, + ASK_NONE, + ASK_V1, + ASK_NONE, + ASK_NONE, + ASK_V2, + ASK_V2}; + + printf("\nSearch Filter:\n"); + + method=ShowShortList(m,9,method); + if(av[method]&ASK_V1) + { + printf("V1 [%03d]: ",v1); + v1=Get8(v1); + } + if(av[method]&ASK_V2) + { + printf("V2 [%03d]: ",v2); + v2=Get8(v2); + } + FCEUI_CheatSearchEnd(method,v1,v2); + puts("Search completed.\n"); +} + + +static MENU NewCheatsMenu[]={ + {"Add Cheat",(void *)AddCheat,1}, + {"Reset Search",(void *)ResetSearch,1}, + {"Do Search",(void *)DoSearch,1}, + {"Set Original to Current",(void *)SetOC,1}, + {"Unhide Excluded",(void *)UnhideEx,1}, + {"Show Results",(void *)ShowRes,1}, + {"Add Game Genie Cheat",(void *)AddCheatGG,1}, + {"Add PAR Cheat",(void *)AddCheatPAR,1}, + {0} +}; + +static MENU MainMenu[]={ + {"List Cheats",(void *)ListCheats,1}, + {"New Cheats...",(void *)NewCheatsMenu,0}, + {0} +}; + +static void DoMenu(MENU *men) +{ + int x=0; + + redisplay: + x=0; + puts(""); + while(men[x].text) + { + printf("%d) %s\n",x+1,men[x].text); + x++; + } + puts("D) Display Menu\nX) Return to Previous\n"); + { + char buf[32]; + int c; + + recommand: + printf("Command> "); + fgets(buf,ARRAY_SIZE(buf),stdin); + c=tolower(buf[0]); + if(c=='\n') + goto recommand; + else if(c=='d') + goto redisplay; + else if(c=='x') + { + return; + } + else if(sscanf(buf,"%d",&c)) + { + if(c>x) goto invalid; + if(men[c-1].type) + { + void (*func)(void)=(void(*)())men[c-1].action; + func(); + } + else + DoMenu((MENU*)men[c-1].action); /* Mmm...recursivey goodness. */ + goto redisplay; + } + else + { + invalid: + puts("Invalid command.\n"); + goto recommand; + } + + } +} + +void DoConsoleCheatConfig(void) +{ + MENU *curmenu=MainMenu; + + DoMenu(curmenu); +} diff --git a/branches/fceux-2.2.2/src/drivers/common/cheat.h b/branches/fceux-2.2.2/src/drivers/common/cheat.h new file mode 100644 index 00000000..77619fe3 --- /dev/null +++ b/branches/fceux-2.2.2/src/drivers/common/cheat.h @@ -0,0 +1,21 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 + */ + +void DoConsoleCheatConfig(void); diff --git a/branches/fceux-2.2.2/src/drivers/common/config.cpp b/branches/fceux-2.2.2/src/drivers/common/config.cpp new file mode 100644 index 00000000..ca610616 --- /dev/null +++ b/branches/fceux-2.2.2/src/drivers/common/config.cpp @@ -0,0 +1,374 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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. + *fs + * 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 + */ + +/****************************************************************/ +/* FCE Ultra */ +/* */ +/* This file contains routines for reading/writing the */ +/* configuration file. */ +/* */ +/****************************************************************/ + +#include +#include +#include + +#include "../../types.h" +#include "../../driver.h" +#include "../../utils/xstring.h" +#include "config.h" + +static int FReadString(FILE *fp, char *str, int n) +{ + int x=0,z; + for(;;) + { + z=fgetc(fp); + str[x]=z; + x++; + if(z<=0) break; + if(x>=n) return 0; + } + if(z<0) return 0; + return 1; +} + +#include +#include +typedef std::map CFGMAP; +static CFGMAP cfgmap; + +static void cfg_Parse(FILE *fp) +{ + //yes... it is a homebrewed key-value-pair parser + std::string key,value; + enum { + NEWLINE, KEY, SEPARATOR, VALUE, COMMENT + } state = NEWLINE; + bool bail = false; + for(;;) + { + int c = fgetc(fp); + bool iswhitespace, iscommentchar, isnewline; + if(c == -1) + goto bail; + iswhitespace = (c==' '||c=='\t'); + iscommentchar = (c=='#'); + isnewline = (c==10||c==13); + switch(state) + { + case NEWLINE: + if(iswhitespace) goto done; + if(iscommentchar) goto docomment; + if(isnewline) goto done; + key = ""; + value = ""; + goto dokey; + break; + case COMMENT: + docomment: + state = COMMENT; + if(isnewline) state = NEWLINE; + break; + case KEY: + dokey: //dookie + state = KEY; + if(iswhitespace) goto doseparator; + if(isnewline) goto commit; + key += c; + break; + case SEPARATOR: + doseparator: + state = SEPARATOR; + if(isnewline) goto commit; + if(!iswhitespace) goto dovalue; + break; + case VALUE: + dovalue: + state = VALUE; + if(isnewline) goto commit; + value += c; + } + goto done; + + bail: + bail = true; + if(state == VALUE) goto commit; + commit: + cfgmap[key] = value; + state = NEWLINE; + if(bail) break; + done: ; + } +} + +static void cfg_Save(FILE *fp) +{ + for(CFGMAP::iterator it(cfgmap.begin()); it != cfgmap.end(); it++) + { + if(it->first.size()>30 || it->second.size()>30) + { + int zzz=9; + } + fprintf(fp,"%s %s\n",it->first.c_str(),it->second.c_str()); + } +} + + +static void GetValueR(FILE *fp, char *str, void *v, int c) +{ + char buf[256]; + int s; + + while(FReadString(fp,buf,256)) + { + fread(&s,1,4,fp); + + if(!strcmp(str, buf)) + { + if(!c) // String, allocate some memory. + { + if(!(*(char **)v=(char*)malloc(s))) + goto gogl; + + fread(*(char **)v,1,s,fp); + continue; + } + else if(s>c || s +#include +#include +#include +#include +#include + +#include "../../types.h" +#include "configSys.h" + +std::string cfgFile = "fceux.cfg"; +/** + * Add a given option. The option is specified as a short command + * line (-f), long command line (--foo), option name (Foo), its type + * (integer or string). + */ +int +Config::_addOption(char shortArg, + const std::string &longArg, + const std::string &name, + int type) +{ + // make sure we have a valid type + if(type != INTEGER && type != STRING && + type != DOUBLE && type != FUNCTION) { + return -1; + } + + // check if the option already exists + if(_shortArgMap.find(shortArg) != _shortArgMap.end() || + _longArgMap.find(longArg) != _longArgMap.end() || + (type == INTEGER && _intOptMap.find(name) != _intOptMap.end()) || + (type == STRING && _strOptMap.find(name) != _strOptMap.end()) || + (type == DOUBLE && _dblOptMap.find(name) != _dblOptMap.end())) { + return -1; + } + + // add the option + switch(type) { + case(STRING): + _strOptMap[name] = ""; + break; + case(INTEGER): + _intOptMap[name] = 0; + break; + case(DOUBLE): + _dblOptMap[name] = 0.0; + break; + case(FUNCTION): + _fnOptMap[name] = NULL; + break; + default: + break; + } + _shortArgMap[shortArg] = name; + _longArgMap[longArg] = name; + + return 0; +} + +int +Config::_addOption(const std::string &longArg, + const std::string &name, + int type) +{ + // make sure we have a valid type + if(type != STRING && type != INTEGER && type != DOUBLE) { + return -1; + } + + // check if the option already exists + if(_longArgMap.find(longArg) != _longArgMap.end() || + (type == STRING && _strOptMap.find(name) != _strOptMap.end()) || + (type == INTEGER && _intOptMap.find(name) != _intOptMap.end()) || + (type == DOUBLE && _dblOptMap.find(name) != _dblOptMap.end())) { + return -1; + } + + // add the option + switch(type) { + case(STRING): + _strOptMap[name] = ""; + break; + case(INTEGER): + _intOptMap[name] = 0; + break; + case(DOUBLE): + _dblOptMap[name] = 0.0; + break; + default: + break; + } + _longArgMap[longArg] = name; + + return 0; +} + + +/** + * Add a given option and sets its default value. The option is + * specified as a short command line (-f), long command line (--foo), + * option name (Foo), its type (integer or string), and its default + * value. + */ +int +Config::addOption(char shortArg, + const std::string &longArg, + const std::string &name, + int defaultValue) +{ + int error; + + // add the option to the config system + error = _addOption(shortArg, longArg, name, INTEGER); + if(error) { + return error; + } + + // set the option to the default value + error = setOption(name, defaultValue); + if(error) { + return error; + } + + return 0; +} + +/** + * Add a given option and sets its default value. The option is + * specified as a short command line (-f), long command line (--foo), + * option name (Foo), its type (integer or string), and its default + * value. + */ +int +Config::addOption(char shortArg, + const std::string &longArg, + const std::string &name, + double defaultValue) +{ + int error; + + // add the option to the config system + error = _addOption(shortArg, longArg, name, DOUBLE); + if(error) { + return error; + } + + // set the option to the default value + error = setOption(name, defaultValue); + if(error) { + return error; + } + + return 0; +} + + +/** + * Add a given option and sets its default value. The option is + * specified as a short command line (-f), long command line (--foo), + * option name (Foo), its type (integer or string), and its default + * value. + */ +int +Config::addOption(char shortArg, + const std::string &longArg, + const std::string &name, + const std::string &defaultValue) +{ + int error; + + // add the option to the config system + error = _addOption(shortArg, longArg, name, STRING); + if(error) { + return error; + } + + // set the option to the default value + error = setOption(name, defaultValue); + if(error) { + return error; + } + + return 0; +} + +int +Config::addOption(char shortArg, + const std::string &longArg, + const std::string &name, + void (*defaultFn)(const std::string &)) +{ + int error; + + // add the option to the config system + error = _addOption(shortArg, longArg, name, FUNCTION); + if(error) { + return error; + } + + // set the option to the default value + error = setOption(name, defaultFn); + if(error) { + return error; + } + + return 0; +} + +int +Config::addOption(const std::string &longArg, + const std::string &name, + const std::string &defaultValue) +{ + int error; + + // add the option to the config system + error = _addOption(longArg, name, STRING); + if(error) { + return error; + } + + // set the option to the default value + error = setOption(name, defaultValue); + if(error) { + return error; + } + + return 0; +} + +int +Config::addOption(const std::string &longArg, + const std::string &name, + int defaultValue) +{ + int error; + + // add the option to the config system + error = _addOption(longArg, name, INTEGER); + if(error) { + return error; + } + + // set the option to the default value + error = setOption(name, defaultValue); + if(error) { + return error; + } + + return 0; +} + +int +Config::addOption(const std::string &longArg, + const std::string &name, + double defaultValue) +{ + int error; + + // add the option to the config system + error = _addOption(longArg, name, DOUBLE); + if(error) { + return error; + } + + // set the option to the default value + error = setOption(name, defaultValue); + if(error) { + return error; + } + + return 0; +} + +int +Config::addOption(const std::string &name, + const std::string &defaultValue) +{ + if(_strOptMap.find(name) != _strOptMap.end()) { + return -1; + } + + // add the option + _strOptMap[name] = defaultValue; + return 0; +} + +int +Config::addOption(const std::string &name, + int defaultValue) +{ + if(_intOptMap.find(name) != _intOptMap.end()) { + return -1; + } + + // add the option + _intOptMap[name] = defaultValue; + return 0; +} + +int +Config::addOption(const std::string &name, + double defaultValue) +{ + if(_dblOptMap.find(name) != _dblOptMap.end()) { + return -1; + } + + // add the option + _dblOptMap[name] = defaultValue; + return 0; +} + +/** + * Sets the specified option to the given integer value. + */ +int +Config::setOption(const std::string &name, + int value) +{ + std::map::iterator opt_i; + + // confirm that the option exists + opt_i = _intOptMap.find(name); + if(opt_i == _intOptMap.end()) { + return -1; + } + + // set the option + opt_i->second = value; + return 0; +} + +/** + * Sets the specified option to the given integer value. + */ +int +Config::setOption(const std::string &name, + double value) +{ + std::map::iterator opt_i; + + // confirm that the option exists + opt_i = _dblOptMap.find(name); + if(opt_i == _dblOptMap.end()) { + return -1; + } + + // set the option + opt_i->second = value; + return 0; +} + +/** + * Sets the specified option to the given string value. + */ +int +Config::setOption(const std::string &name, + const std::string &value) +{ + std::map::iterator opt_i; + + // confirm that the option exists + opt_i = _strOptMap.find(name); + if(opt_i == _strOptMap.end()) { + return -1; + } + + // set the option + opt_i->second = value; + return 0; +} + +/** + * Sets the specified option to the given function. + */ +int +Config::setOption(const std::string &name, + void (*value)(const std::string &)) +{ + std::map::iterator opt_i; + + // confirm that the option exists + opt_i = _fnOptMap.find(name); + if(opt_i == _fnOptMap.end()) { + return -1; + } + + // set the option + opt_i->second = value; + return 0; +} + + +int +Config::getOption(const std::string &name, + std::string *value) const +{ + std::map::const_iterator opt_i; + + // confirm that the option exists + opt_i = _strOptMap.find(name); + if(opt_i == _strOptMap.end()) { + return -1; + } + + // get the option + (*value) = opt_i->second; + return 0; +} + +int +Config::getOption(const std::string &name, + const char **value) const +{ + std::map::const_iterator opt_i; + + // confirm that the option exists + opt_i = _strOptMap.find(name); + if(opt_i == _strOptMap.end()) { + return -1; + } + + // get the option + (*value) = opt_i->second.c_str(); + return 0; +} + +int +Config::getOption(const std::string &name, + int *value) const +{ + std::map::const_iterator opt_i; + + // confirm that the option exists + opt_i = _intOptMap.find(name); + if(opt_i == _intOptMap.end()) { + return -1; + } + + // get the option + (*value) = opt_i->second; + return 0; +} + +int +Config::getOption(const std::string &name, + double *value) const +{ + std::map::const_iterator opt_i; + + // confirm that the option exists + opt_i = _dblOptMap.find(name); + if(opt_i == _dblOptMap.end()) { + return -1; + } + + // get the option + (*value) = opt_i->second; + return 0; +} + +/** + * Parses the command line arguments. Short args are of the form -f + * , long args are of the form --foo . Returns < 0 on error, + * or the index of the rom file in argv. + */ +int +Config::_parseArgs(int argc, + char **argv) +{ + int retval = 0; + std::map::iterator long_i, str_i; + std::map::iterator short_i; + std::map::iterator int_i; + std::map::iterator dbl_i; + std::map::iterator fn_i; + std::string arg, opt, value; + + for(int i = 1; i < argc; i++) { + arg = argv[i]; + if(arg[0] != '-') { + // must be a rom name? + retval = i; + continue; + } + + if(arg.size() < 2) { + // XXX invalid argument + return -1; + } + + // parse the argument and get the option name + if(arg[1] == '-') { + // long arg + long_i = _longArgMap.find(arg.substr(2)); + if(long_i == _longArgMap.end()) { + // XXX invalid argument + return -1; + } + + opt = long_i->second; + } else { + // short arg + short_i = _shortArgMap.find(arg[1]); + if(short_i == _shortArgMap.end()) { + // XXX invalid argument + return -1; + } + + opt = short_i->second; + } + + // make sure we've got a value + if(i + 1 >= argc) { + // XXX missing value + return -1; + } + i++; + + // now, find the appropriate option entry, and update it + str_i = _strOptMap.find(opt); + int_i = _intOptMap.find(opt); + dbl_i = _dblOptMap.find(opt); + fn_i = _fnOptMap.find(opt); + if(str_i != _strOptMap.end()) { + str_i->second = argv[i]; + } else if(int_i != _intOptMap.end()) { + int_i->second = atol(argv[i]); + } else if(dbl_i != _dblOptMap.end()) { + dbl_i->second = atof(argv[i]); + } else if(fn_i != _fnOptMap.end()) { + (*(fn_i->second))(argv[i]); + } else { + // XXX invalid option? shouldn't happen + return -1; + } + } + + // if we didn't get a rom-name, return error + return (retval) ? retval : -1; +} + + +/** + * Parses first the configuration file, and then overrides with any + * command-line options that were specified. + */ +int +Config::parse(int argc, + char **argv) +{ + int error; + + // read the config file + error = _load(); + if(error) { + return error; + } + + // try to read cfg.d/* + std::string cfgd_dir_name = _dir + "/" + "cfg.d/"; + DIR *d; + struct dirent *dir; + d = opendir(cfgd_dir_name.c_str()); + if (d) + { + while ((dir = readdir(d)) != NULL) + { + // dont load "." or ".." + if(strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) + { + continue; + } + + // TODO 0 = good -1 = bad + std::string fname = cfgd_dir_name + dir->d_name; + printf("Loading auxilary configuration file at %s...\n", fname.c_str()); + if (_loadFile(fname.c_str()) != 0) + { + printf("Failed to parse configuration at %s\n", fname.c_str()); + } + } + + closedir(d); + } + + // parse the arguments + return _parseArgs(argc, argv); +} + + +/** + * Read each line of the config file and put the variables into the + * config maps. Valid configuration lines are of the form: + * + *